mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2025-01-26 11:21:08 +00:00
experimental string converter class
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@91 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
parent
5fbe19c4a6
commit
c7987cc0be
1 changed files with 19 additions and 6 deletions
|
@ -170,18 +170,31 @@ void IntRadioExport(GtkRadioButton& widget, const IntImportCallback& importCallb
|
||||||
}
|
}
|
||||||
typedef ImportExport<GtkRadioButton, int, IntRadioImport, IntRadioExport> IntRadioImportExport;
|
typedef ImportExport<GtkRadioButton, int, IntRadioImport, IntRadioExport> IntRadioImportExport;
|
||||||
|
|
||||||
|
template<typename Type, typename Formatter>
|
||||||
|
class StringFromType
|
||||||
|
{
|
||||||
|
StringOutputStream value;
|
||||||
|
public:
|
||||||
|
StringFromType(const Type& type)
|
||||||
|
{
|
||||||
|
value << Formatter(type);
|
||||||
|
}
|
||||||
|
operator const char*() const
|
||||||
|
{
|
||||||
|
return value.c_str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef StringFromType<const char*, ConvertLocaleToUTF8> LocaleToUTF8;
|
||||||
|
typedef StringFromType<const char*, ConvertUTF8ToLocale> UTF8ToLocale;
|
||||||
|
|
||||||
void TextEntryImport(GtkEntry& widget, const char* text)
|
void TextEntryImport(GtkEntry& widget, const char* text)
|
||||||
{
|
{
|
||||||
StringOutputStream value(64);
|
gtk_entry_set_text(&widget, LocaleToUTF8(text));
|
||||||
value << ConvertLocaleToUTF8(text);
|
|
||||||
gtk_entry_set_text(&widget, value.c_str());
|
|
||||||
}
|
}
|
||||||
void TextEntryExport(GtkEntry& widget, const StringImportCallback& importCallback)
|
void TextEntryExport(GtkEntry& widget, const StringImportCallback& importCallback)
|
||||||
{
|
{
|
||||||
StringOutputStream value(64);
|
importCallback(UTF8ToLocale(gtk_entry_get_text(&widget)));
|
||||||
value << ConvertUTF8ToLocale(gtk_entry_get_text(&widget));
|
|
||||||
importCallback(value.c_str());
|
|
||||||
}
|
}
|
||||||
typedef ImportExport<GtkEntry, const char*, TextEntryImport, TextEntryExport> TextEntryImportExport;
|
typedef ImportExport<GtkEntry, const char*, TextEntryImport, TextEntryExport> TextEntryImportExport;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue