]> git.draconx.ca Git - gob-dx.git/blob - examples/gtk-button-count.gob
9061c5cd63fdaddc9e1f6170db169e65da82b566
[gob-dx.git] / examples / gtk-button-count.gob
1 /*
2  * This is an example button widget which counts the number of clicks
3  *
4  * It is also showing how you can use inline gtk-doc like documentation
5  * which will be correctly translated and put into the resulting source
6  * file
7  */
8 class Gtk:Button:Count from Gtk:Button {
9         public int count;
10
11         argument INT count
12         get {
13                 ARG = self->count;
14         }
15         set {
16                 self->count = ARG;
17         };
18
19         init(self)
20         {
21                 self->count = 0;
22         }
23
24         /**
25          * new:
26          *
27          * Makes a new #GtkButtonCount widget
28          *
29          * Returns: a new widget
30          **/
31         public
32         GtkWidget *
33         new(void)
34         {
35                 /* It's ok to use a normal cast here, as we are sure that we
36                  * have gotten the right type */
37                 return (GtkWidget *)GET_NEW;
38         }
39
40         /**
41          * new_with_label:
42          * @label: the label text
43          *
44          * Makes a new #GtkButtonCount widget with a label
45          *
46          * Returns: a new widget
47          **/
48         public
49         GtkWidget *
50         new_with_label(char *label (check null)) onerror NULL
51         {
52                 /* It's ok to use a normal cast here, as we are sure that we
53                  * have gotten the right type */
54                 GtkWidget *widget = (GtkWidget *)GET_NEW;
55                 GtkWidget *label_widget = gtk_label_new(label);
56                 gtk_container_add(GTK_CONTAINER(widget), label_widget);
57                 gtk_widget_show(label_widget);
58                 return widget;
59         }
60
61         override (Gtk:Button)
62         void
63         clicked(Gtk:Button *self (check null type))
64         {
65                 GtkButtonCount *bc = GTK_BUTTON_COUNT(self);
66                 bc->count++;
67                 PARENT_HANDLER(self);
68         }
69 }