X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/1656cfade4879af0cb003e3847e58264caa5781f..69c350c69e70bddb040dfc5d90b0368376a6389e:/examples/gtk-button-count.gob diff --git a/examples/gtk-button-count.gob b/examples/gtk-button-count.gob index 1982146..2eee5f2 100644 --- a/examples/gtk-button-count.gob +++ b/examples/gtk-button-count.gob @@ -5,20 +5,27 @@ * which will be correctly translated and put into the resulting source * file */ -class Gtk:Button:Count from Gtk:Button { - public int count; +requires 2.0.0 - argument INT count - get { - ARG = self->count; - } - set { - self->count = ARG; - }; +class Gtk:Button:Count from Gtk:Button { + public int count = 0; + property INT count + (nick = _("Count of clicks"), + blurb = _("How many times was the button clicked"), + minimum = 0, + maximum = INT_MAX, + /* initially set to 0, even though we have already + * set the default above */ + default_value = 0, + /* links the count property to the count data member */ + link); - init(button) + init (self) { - button->count = 0; + /* Although we have specified the default in two places + * already, this is an example of where else you can put + * initialization */ + self->count = 0; } /** @@ -30,9 +37,11 @@ class Gtk:Button:Count from Gtk:Button { **/ public GtkWidget * - new(void) + new (void) { - return GTK_WIDGET(GET_NEW); + /* It's ok to use a normal cast here, as we are sure that we + * have gotten the right type */ + return (GtkWidget *)GET_NEW; } /** @@ -45,17 +54,25 @@ class Gtk:Button:Count from Gtk:Button { **/ public GtkWidget * - new_with_label(char *label (check null)) onerror NULL + new_with_label (char *label (check null)) onerror NULL { - return GTK_WIDGET(GET_NEW); + /* It's ok to use a normal cast here, as we are sure that we + * have gotten the right type */ + GtkWidget *widget = (GtkWidget *)GET_NEW; + GtkWidget *label_widget = gtk_label_new (label); + gtk_container_add (GTK_CONTAINER (widget), label_widget); + gtk_widget_show (label_widget); + return widget; } override (Gtk:Button) void - clicked(Gtk:Button *self (check null type)) + clicked (Gtk:Button *self (check null type)) { - GtkButtonCount *bc = GTK_BUTTON_COUNT(self); + GtkButtonCount *bc = GTK_BUTTON_COUNT (self); + /* increase count */ bc->count++; - PARENT_HANDLER(self); + /* runt he parent class handler for clicked */ + PARENT_HANDLER (self); } }