StringAttribute.h
Go to the documentation of this file.00001 #ifndef STRINGATTRIBUTE_H_
00002 #define STRINGATTRIBUTE_H_
00003
00004 #include "gtkutil/widget.h"
00005
00009 class StringAttribute: public EntityAttribute
00010 {
00011 std::string m_classname;
00012
00013 std::string m_key;
00014 GtkEntry* m_entry;
00015 NonModalEntry m_nonModal;
00016 public:
00017
00018 StringAttribute (const std::string& classname, const std::string& key) :
00019 m_classname(classname), m_key(key), m_entry(0), m_nonModal(ApplyCaller(*this), UpdateCaller(*this))
00020 {
00021 GtkEntry* entry = GTK_ENTRY(gtk_entry_new());
00022 gtk_widget_show(GTK_WIDGET(entry));
00023 widget_set_size(GTK_WIDGET(entry), 50, 0);
00024
00025 m_entry = entry;
00026 m_nonModal.connect(m_entry);
00027 }
00028 GtkWidget* getWidget () const
00029 {
00030 return GTK_WIDGET(m_entry);
00031 }
00032 GtkEntry* getEntry () const
00033 {
00034 return m_entry;
00035 }
00036
00037 void apply (void)
00038 {
00039 StringOutputStream value(64);
00040 value << ConvertUTF8ToLocale(gtk_entry_get_text(m_entry));
00041 entitySetValue(m_classname, m_key, value.c_str());
00042 }
00043 typedef MemberCaller<StringAttribute, &StringAttribute::apply> ApplyCaller;
00044
00045 void update (void)
00046 {
00047 const std::string& value = entityGetValueForKey(m_key);
00048 gtk_entry_set_text(m_entry, value.c_str());
00049 }
00050 typedef MemberCaller<StringAttribute, &StringAttribute::update> UpdateCaller;
00051 };
00052
00053 #endif