| |
1 #include "gntbutton.h" |
| |
2 |
| |
3 enum |
| |
4 { |
| |
5 SIGS = 1, |
| |
6 }; |
| |
7 |
| |
8 static GntWidgetClass *parent_class = NULL; |
| |
9 static guint signals[SIGS] = { 0 }; |
| |
10 |
| |
11 static void |
| |
12 gnt_button_draw(GntWidget *widget) |
| |
13 { |
| |
14 GntButton *button = GNT_BUTTON(widget); |
| |
15 GntColorType type; |
| |
16 |
| |
17 if (GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_HAS_FOCUS) |
| |
18 type = GNT_COLOR_HIGHLIGHT; |
| |
19 else |
| |
20 type = GNT_COLOR_NORMAL; |
| |
21 wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); |
| |
22 mvwprintw(widget->window, 1, 1, button->priv->text); |
| |
23 |
| |
24 wrefresh(widget->window); |
| |
25 |
| |
26 DEBUG; |
| |
27 } |
| |
28 |
| |
29 static void |
| |
30 gnt_button_size_request(GntWidget *widget) |
| |
31 { |
| |
32 GntButton *button = GNT_BUTTON(widget); |
| |
33 widget->priv.width = g_utf8_strlen(button->priv->text, -1) + 2; |
| |
34 widget->priv.height = 3; |
| |
35 } |
| |
36 |
| |
37 static void |
| |
38 gnt_button_map(GntWidget *widget) |
| |
39 { |
| |
40 if (widget->priv.width == 0 || widget->priv.height == 0) |
| |
41 gnt_widget_size_request(widget); |
| |
42 DEBUG; |
| |
43 } |
| |
44 |
| |
45 static gboolean |
| |
46 gnt_button_key_pressed(GntWidget *widget, const char *key) |
| |
47 { |
| |
48 if (strcmp(key, GNT_KEY_ENTER) == 0) |
| |
49 { |
| |
50 gnt_widget_activate(widget); |
| |
51 return TRUE; |
| |
52 } |
| |
53 return FALSE; |
| |
54 } |
| |
55 |
| |
56 static void |
| |
57 gnt_button_class_init(GntWidgetClass *klass) |
| |
58 { |
| |
59 GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
| |
60 |
| |
61 parent_class = GNT_WIDGET_CLASS(klass); |
| |
62 parent_class->draw = gnt_button_draw; |
| |
63 parent_class->map = gnt_button_map; |
| |
64 parent_class->size_request = gnt_button_size_request; |
| |
65 parent_class->key_pressed = gnt_button_key_pressed; |
| |
66 |
| |
67 DEBUG; |
| |
68 } |
| |
69 |
| |
70 static void |
| |
71 gnt_button_init(GTypeInstance *instance, gpointer class) |
| |
72 { |
| |
73 GntButton *button = GNT_BUTTON(instance); |
| |
74 button->priv = g_new0(GntButtonPriv, 1); |
| |
75 DEBUG; |
| |
76 } |
| |
77 |
| |
78 /****************************************************************************** |
| |
79 * GntButton API |
| |
80 *****************************************************************************/ |
| |
81 GType |
| |
82 gnt_button_get_gtype(void) { |
| |
83 static GType type = 0; |
| |
84 |
| |
85 if(type == 0) { |
| |
86 static const GTypeInfo info = { |
| |
87 sizeof(GntButtonClass), |
| |
88 NULL, /* base_init */ |
| |
89 NULL, /* base_finalize */ |
| |
90 (GClassInitFunc)gnt_button_class_init, |
| |
91 NULL, /* class_finalize */ |
| |
92 NULL, /* class_data */ |
| |
93 sizeof(GntButton), |
| |
94 0, /* n_preallocs */ |
| |
95 gnt_button_init, /* instance_init */ |
| |
96 }; |
| |
97 |
| |
98 type = g_type_register_static(GNT_TYPE_WIDGET, |
| |
99 "GntButton", |
| |
100 &info, 0); |
| |
101 } |
| |
102 |
| |
103 return type; |
| |
104 } |
| |
105 |
| |
106 GntWidget *gnt_button_new(const char *text) |
| |
107 { |
| |
108 GntWidget *widget = g_object_new(GNT_TYPE_BUTTON, NULL); |
| |
109 GntButton *button = GNT_BUTTON(widget); |
| |
110 |
| |
111 button->priv->text = g_strdup(text); |
| |
112 gnt_widget_set_take_focus(widget, TRUE); |
| |
113 |
| |
114 return widget; |
| |
115 } |
| |
116 |