Mercurial > pidgin.yaz
annotate finch/libgnt/gntcombobox.c @ 30671:658e8b9522bc
Make the combobox a bit more friendly.
While the dropdown in the combobox is not shown, and some key is pressed
that triggers an action in the dropdown (e.g. home, end keys etc.), popup
the dropdown.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 05 Jul 2010 04:44:52 +0000 |
parents | 6943aec8cf61 |
children | e1b511df0d3e |
rev | line source |
---|---|
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18443
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15818
diff
changeset
|
22 |
28984
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26521
diff
changeset
|
23 #include "gntinternal.h" |
15818 | 24 #include "gntbox.h" |
25 #include "gntcombobox.h" | |
26 #include "gnttree.h" | |
27 #include "gntmarshal.h" | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
28 #include "gntstyle.h" |
15818 | 29 #include "gntutils.h" |
30 | |
31 #include <string.h> | |
32 | |
33 enum | |
34 { | |
35 SIG_SELECTION_CHANGED, | |
36 SIGS, | |
37 }; | |
38 | |
39 static GntWidgetClass *parent_class = NULL; | |
40 static guint signals[SIGS] = { 0 }; | |
41 static void (*widget_lost_focus)(GntWidget *widget); | |
42 | |
43 static void | |
44 set_selection(GntComboBox *box, gpointer key) | |
45 { | |
46 if (box->selected != key) | |
47 { | |
48 /* XXX: make sure the key actually does exist */ | |
49 gpointer old = box->selected; | |
50 box->selected = key; | |
51 if (GNT_WIDGET(box)->window) | |
52 gnt_widget_draw(GNT_WIDGET(box)); | |
53 if (box->dropdown) | |
54 gnt_tree_set_selected(GNT_TREE(box->dropdown), key); | |
55 g_signal_emit(box, signals[SIG_SELECTION_CHANGED], 0, old, key); | |
56 } | |
57 } | |
58 | |
59 static void | |
60 hide_popup(GntComboBox *box, gboolean set) | |
61 { | |
62 gnt_widget_set_size(box->dropdown, | |
63 box->dropdown->priv.width - 1, box->dropdown->priv.height); | |
64 if (set) | |
65 set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); | |
66 else | |
67 gnt_tree_set_selected(GNT_TREE(box->dropdown), box->selected); | |
68 gnt_widget_hide(box->dropdown->parent); | |
69 } | |
70 | |
71 static void | |
72 gnt_combo_box_draw(GntWidget *widget) | |
73 { | |
74 GntComboBox *box = GNT_COMBO_BOX(widget); | |
75 char *text = NULL, *s; | |
76 GntColorType type; | |
77 int len; | |
26521
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22289
diff
changeset
|
78 |
15818 | 79 if (box->dropdown && box->selected) |
80 text = gnt_tree_get_selection_text(GNT_TREE(box->dropdown)); | |
81 | |
82 if (text == NULL) | |
83 text = g_strdup(""); | |
84 | |
85 if (gnt_widget_has_focus(widget)) | |
86 type = GNT_COLOR_HIGHLIGHT; | |
87 else | |
88 type = GNT_COLOR_NORMAL; | |
89 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
90 wbkgdset(widget->window, '\0' | gnt_color_pair(type)); |
15818 | 91 |
92 s = (char*)gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, &len); | |
93 *s = '\0'; | |
94 | |
28984
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26521
diff
changeset
|
95 mvwaddstr(widget->window, 1, 1, C_(text)); |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
96 whline(widget->window, ' ' | gnt_color_pair(type), widget->priv.width - 4 - len); |
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
97 mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL)); |
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
98 mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | gnt_color_pair(GNT_COLOR_NORMAL)); |
26521
c67d43408daa
Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22289
diff
changeset
|
99 wmove(widget->window, 1, 1); |
15818 | 100 |
101 g_free(text); | |
102 GNTDEBUG; | |
103 } | |
104 | |
105 static void | |
106 gnt_combo_box_size_request(GntWidget *widget) | |
107 { | |
108 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) | |
109 { | |
110 GntWidget *dd = GNT_COMBO_BOX(widget)->dropdown; | |
111 gnt_widget_size_request(dd); | |
112 widget->priv.height = 3; /* For now, a combobox will have border */ | |
18443
92f845cd977c
Fix the initial size of a combobox.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17718
diff
changeset
|
113 widget->priv.width = MAX(10, dd->priv.width + 2); |
15818 | 114 } |
115 } | |
116 | |
117 static void | |
118 gnt_combo_box_map(GntWidget *widget) | |
119 { | |
120 if (widget->priv.width == 0 || widget->priv.height == 0) | |
121 gnt_widget_size_request(widget); | |
122 GNTDEBUG; | |
123 } | |
124 | |
125 static void | |
126 popup_dropdown(GntComboBox *box) | |
127 { | |
128 GntWidget *widget = GNT_WIDGET(box); | |
129 GntWidget *parent = box->dropdown->parent; | |
130 int height = g_list_length(GNT_TREE(box->dropdown)->list); | |
131 int y = widget->priv.y + widget->priv.height - 1; | |
132 gnt_widget_set_size(box->dropdown, widget->priv.width, height + 2); | |
133 | |
134 if (y + height + 2 >= getmaxy(stdscr)) | |
135 y = widget->priv.y - height - 1; | |
136 gnt_widget_set_position(parent, widget->priv.x, y); | |
137 if (parent->window) | |
138 { | |
139 mvwin(parent->window, y, widget->priv.x); | |
140 wresize(parent->window, height+2, widget->priv.width); | |
141 } | |
142 parent->priv.width = widget->priv.width; | |
143 parent->priv.height = height + 2; | |
144 | |
145 GNT_WIDGET_UNSET_FLAGS(parent, GNT_WIDGET_INVISIBLE); | |
146 gnt_widget_draw(parent); | |
147 } | |
148 | |
149 static gboolean | |
150 gnt_combo_box_key_pressed(GntWidget *widget, const char *text) | |
151 { | |
152 GntComboBox *box = GNT_COMBO_BOX(widget); | |
30671
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
153 if (GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED)) { |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
154 if (text[1] == 0) { |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
155 switch (text[0]) { |
15818 | 156 case '\r': |
157 case '\t': | |
22289
0ba0f2804299
'\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
158 case '\n': |
15818 | 159 hide_popup(box, TRUE); |
160 return TRUE; | |
161 case 27: | |
162 hide_popup(box, FALSE); | |
163 return TRUE; | |
164 } | |
165 } | |
30671
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
166 } |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
167 |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
168 if (gnt_widget_key_pressed(box->dropdown, text)) { |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
169 if (!GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED)) |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
170 popup_dropdown(box); |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
171 return TRUE; |
15818 | 172 } |
173 | |
174 return FALSE; | |
175 } | |
176 | |
177 static void | |
178 gnt_combo_box_destroy(GntWidget *widget) | |
179 { | |
180 gnt_widget_destroy(GNT_COMBO_BOX(widget)->dropdown->parent); | |
181 } | |
182 | |
183 static void | |
184 gnt_combo_box_lost_focus(GntWidget *widget) | |
185 { | |
186 GntComboBox *combo = GNT_COMBO_BOX(widget); | |
187 if (GNT_WIDGET_IS_FLAG_SET(combo->dropdown->parent, GNT_WIDGET_MAPPED)) | |
188 hide_popup(combo, FALSE); | |
189 widget_lost_focus(widget); | |
190 } | |
191 | |
192 static gboolean | |
193 gnt_combo_box_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
194 { | |
195 GntComboBox *box = GNT_COMBO_BOX(widget); | |
196 gboolean dshowing = GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED); | |
197 | |
198 if (event == GNT_MOUSE_SCROLL_UP) { | |
199 if (dshowing) | |
200 gnt_widget_key_pressed(box->dropdown, GNT_KEY_UP); | |
201 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
202 if (dshowing) | |
203 gnt_widget_key_pressed(box->dropdown, GNT_KEY_DOWN); | |
204 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
205 if (dshowing) { | |
206 hide_popup(box, TRUE); | |
207 } else { | |
208 popup_dropdown(GNT_COMBO_BOX(widget)); | |
209 } | |
210 } else | |
211 return FALSE; | |
212 return TRUE; | |
213 } | |
214 | |
215 static void | |
216 gnt_combo_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
217 { | |
218 GntComboBox *box = GNT_COMBO_BOX(widget); | |
219 gnt_widget_set_size(box->dropdown, widget->priv.width - 1, box->dropdown->priv.height); | |
220 } | |
221 | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
222 static gboolean |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
223 dropdown_menu(GntBindable *b, GList *null) |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
224 { |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
225 if (GNT_WIDGET_IS_FLAG_SET(GNT_COMBO_BOX(b)->dropdown->parent, GNT_WIDGET_MAPPED)) |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
226 return FALSE; |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
227 popup_dropdown(GNT_COMBO_BOX(b)); |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
228 return TRUE; |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
229 } |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
230 |
15818 | 231 static void |
232 gnt_combo_box_class_init(GntComboBoxClass *klass) | |
233 { | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
234 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
235 |
15818 | 236 parent_class = GNT_WIDGET_CLASS(klass); |
237 | |
238 parent_class->destroy = gnt_combo_box_destroy; | |
239 parent_class->draw = gnt_combo_box_draw; | |
240 parent_class->map = gnt_combo_box_map; | |
241 parent_class->size_request = gnt_combo_box_size_request; | |
242 parent_class->key_pressed = gnt_combo_box_key_pressed; | |
243 parent_class->clicked = gnt_combo_box_clicked; | |
244 parent_class->size_changed = gnt_combo_box_size_changed; | |
245 | |
246 widget_lost_focus = parent_class->lost_focus; | |
247 parent_class->lost_focus = gnt_combo_box_lost_focus; | |
248 | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
249 signals[SIG_SELECTION_CHANGED] = |
15818 | 250 g_signal_new("selection-changed", |
251 G_TYPE_FROM_CLASS(klass), | |
252 G_SIGNAL_RUN_LAST, | |
253 0, | |
254 NULL, NULL, | |
255 gnt_closure_marshal_VOID__POINTER_POINTER, | |
256 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
257 | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
258 gnt_bindable_class_register_action(bindable, "dropdown", dropdown_menu, |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
259 GNT_KEY_DOWN, NULL); |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
260 gnt_bindable_register_binding(bindable, "dropdown", GNT_KEY_UP, NULL); |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
261 |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
262 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), bindable); |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
263 |
15818 | 264 GNTDEBUG; |
265 } | |
266 | |
267 static void | |
268 gnt_combo_box_init(GTypeInstance *instance, gpointer class) | |
269 { | |
270 GntWidget *box; | |
271 GntWidget *widget = GNT_WIDGET(instance); | |
272 GntComboBox *combo = GNT_COMBO_BOX(instance); | |
273 | |
274 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), | |
275 GNT_WIDGET_GROW_X | GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW); | |
276 combo->dropdown = gnt_tree_new(); | |
277 | |
278 box = gnt_box_new(FALSE, FALSE); | |
279 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT); | |
280 gnt_box_set_pad(GNT_BOX(box), 0); | |
281 gnt_box_add_widget(GNT_BOX(box), combo->dropdown); | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
282 |
15818 | 283 widget->priv.minw = 4; |
284 widget->priv.minh = 3; | |
285 GNTDEBUG; | |
286 } | |
287 | |
288 /****************************************************************************** | |
289 * GntComboBox API | |
290 *****************************************************************************/ | |
291 GType | |
292 gnt_combo_box_get_gtype(void) | |
293 { | |
294 static GType type = 0; | |
295 | |
296 if(type == 0) | |
297 { | |
298 static const GTypeInfo info = { | |
299 sizeof(GntComboBoxClass), | |
300 NULL, /* base_init */ | |
301 NULL, /* base_finalize */ | |
302 (GClassInitFunc)gnt_combo_box_class_init, | |
303 NULL, /* class_finalize */ | |
304 NULL, /* class_data */ | |
305 sizeof(GntComboBox), | |
306 0, /* n_preallocs */ | |
307 gnt_combo_box_init, /* instance_init */ | |
308 NULL /* value_table */ | |
309 }; | |
310 | |
311 type = g_type_register_static(GNT_TYPE_WIDGET, | |
312 "GntComboBox", | |
313 &info, 0); | |
314 } | |
315 | |
316 return type; | |
317 } | |
318 | |
319 GntWidget *gnt_combo_box_new() | |
320 { | |
321 GntWidget *widget = g_object_new(GNT_TYPE_COMBO_BOX, NULL); | |
322 | |
323 return widget; | |
324 } | |
325 | |
326 void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text) | |
327 { | |
328 gnt_tree_add_row_last(GNT_TREE(box->dropdown), key, | |
329 gnt_tree_create_row(GNT_TREE(box->dropdown), text), NULL); | |
330 if (box->selected == NULL) | |
331 set_selection(box, key); | |
332 } | |
333 | |
334 gpointer gnt_combo_box_get_selected_data(GntComboBox *box) | |
335 { | |
336 return box->selected; | |
337 } | |
338 | |
339 void gnt_combo_box_set_selected(GntComboBox *box, gpointer key) | |
340 { | |
341 set_selection(box, key); | |
342 } | |
343 | |
344 void gnt_combo_box_remove(GntComboBox *box, gpointer key) | |
345 { | |
346 gnt_tree_remove(GNT_TREE(box->dropdown), key); | |
347 if (box->selected == key) | |
348 set_selection(box, NULL); | |
349 } | |
350 | |
351 void gnt_combo_box_remove_all(GntComboBox *box) | |
352 { | |
353 gnt_tree_remove_all(GNT_TREE(box->dropdown)); | |
354 set_selection(box, NULL); | |
355 } | |
356 |