]> git.draconx.ca Git - gob-dx.git/blob - examples/gtk-button-count.gob
Release 2.0.0
[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 requires 2.0.0
9
10 class Gtk:Button:Count from Gtk:Button {
11         public int count = 0;
12         property INT count
13                 (nick = _("Count of clicks"),
14                  blurb = _("How many times was the button clicked"),
15                  minimum = 0,
16                  maximum = INT_MAX,
17                  /* initially set to 0, even though we have already
18                   * set the default above */
19                  default_value = 0,
20                  /* links the count property to the count data member */
21                  link);
22
23         init (self)
24         {
25                 /* Although we have specified the default in two places
26                  * already, this is an example of where else you can put
27                  * initialization */
28                 self->count = 0;
29         }
30
31         /**
32          * new:
33          *
34          * Makes a new #GtkButtonCount widget
35          *
36          * Returns: a new widget
37          **/
38         public
39         GtkWidget *
40         new (void)
41         {
42                 /* It's ok to use a normal cast here, as we are sure that we
43                  * have gotten the right type */
44                 return (GtkWidget *)GET_NEW;
45         }
46
47         /**
48          * new_with_label:
49          * @label: the label text
50          *
51          * Makes a new #GtkButtonCount widget with a label
52          *
53          * Returns: a new widget
54          **/
55         public
56         GtkWidget *
57         new_with_label (char *label (check null)) onerror NULL
58         {
59                 /* It's ok to use a normal cast here, as we are sure that we
60                  * have gotten the right type */
61                 GtkWidget *widget = (GtkWidget *)GET_NEW;
62                 GtkWidget *label_widget = gtk_label_new (label);
63                 gtk_container_add (GTK_CONTAINER (widget), label_widget);
64                 gtk_widget_show (label_widget);
65                 return widget;
66         }
67
68         override (Gtk:Button)
69         void
70         clicked (Gtk:Button *self (check null type))
71         {
72                 GtkButtonCount *bc = GTK_BUTTON_COUNT (self);
73                 /* increase count */
74                 bc->count++;
75                 /* runt he parent class handler for clicked */
76                 PARENT_HANDLER (self);
77         }
78 }