BooleanAttribute.h
Go to the documentation of this file.00001 #ifndef BOOLEANATTRIBUTE_H_
00002 #define BOOLEANATTRIBUTE_H_
00003
00007 class BooleanAttribute: public EntityAttribute
00008 {
00009 std::string m_classname;
00010
00011 std::string m_key;
00012
00013 GtkCheckButton* m_check;
00014
00015
00016
00017
00018 static gboolean toggled (GtkWidget *widget, BooleanAttribute* self)
00019 {
00020 self->apply();
00021 return FALSE;
00022 }
00023 public:
00024
00025 BooleanAttribute (const std::string& classname, const std::string& key) :
00026 m_classname(classname), m_key(key), m_check(0)
00027 {
00028 GtkCheckButton* check = GTK_CHECK_BUTTON(gtk_check_button_new());
00029
00030
00031 gtk_widget_show(GTK_WIDGET(check));
00032
00033 m_check = check;
00034
00035
00036 guint handler = g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(toggled), this);
00037 g_object_set_data(G_OBJECT(check), "handler", gint_to_pointer(handler));
00038
00039
00040 update();
00041 }
00042
00043 GtkWidget* getWidget () const
00044 {
00045 return GTK_WIDGET(m_check);
00046 }
00047
00048
00049 void apply (void)
00050 {
00051 std::string value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_check)) ? "1" : "0";
00052
00053 entitySetValue(m_classname, m_key, value);
00054 }
00055
00056
00057 void update (void)
00058 {
00059 const std::string value = entityGetValueForKey(m_key);
00060
00061 if (value.length() > 0) {
00062 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(m_check), string::toInt(value) != 0);
00063 } else {
00064
00065 toggle_button_set_active_no_signal(GTK_TOGGLE_BUTTON(m_check), false);
00066 }
00067 }
00068 };
00069
00070 #endif