Mercurial > pidgin.yaz
annotate finch/libgnt/gntcombobox.c @ 32165:47f7b8ca6149
conversation: O(1) purple_conv_chat_cb_find
I also deprecated what seems like a useless function. The
ui_data is to implement constant-time lookups for the room
list in Pidgin.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 20 Jun 2011 05:24:30 +0000 |
parents | e1b511df0d3e |
children |
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); | |
30673
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
153 gboolean showing = !!GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED); |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
154 |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
155 if (showing) { |
30671
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
156 if (text[1] == 0) { |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
157 switch (text[0]) { |
15818 | 158 case '\r': |
159 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
|
160 case '\n': |
15818 | 161 hide_popup(box, TRUE); |
162 return TRUE; | |
163 case 27: | |
164 hide_popup(box, FALSE); | |
165 return TRUE; | |
166 } | |
167 } | |
30671
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
168 } |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
169 |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
170 if (gnt_widget_key_pressed(box->dropdown, text)) { |
30673
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
171 if (!showing) |
30671
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
172 popup_dropdown(box); |
658e8b9522bc
Make the combobox a bit more friendly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30620
diff
changeset
|
173 return TRUE; |
15818 | 174 } |
175 | |
30673
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
176 { |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
177 #define SEARCH_IN_RANGE(start, end) do { \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
178 GntTreeRow *row; \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
179 for (row = start; row != end; \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
180 row = gnt_tree_row_get_next(tree, row)) { \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
181 gpointer key = gnt_tree_row_get_key(tree, row); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
182 GList *list = gnt_tree_get_row_text_list(tree, key); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
183 gboolean found = FALSE; \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
184 found = (list->data && g_ascii_strncasecmp(text, list->data, len) == 0); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
185 g_list_foreach(list, (GFunc)g_free, NULL); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
186 g_list_free(list); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
187 if (found) { \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
188 if (!showing) \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
189 popup_dropdown(box); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
190 gnt_tree_set_selected(tree, key); \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
191 return TRUE; \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
192 } \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
193 } \ |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
194 } while (0) |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
195 |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
196 int len = strlen(text); |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
197 GntTree *tree = GNT_TREE(box->dropdown); |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
198 GntTreeRow *current = tree->current; |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
199 |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
200 SEARCH_IN_RANGE(gnt_tree_row_get_next(tree, current), NULL); |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
201 SEARCH_IN_RANGE(tree->top, current); |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
202 |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
203 #undef SEARCH_IN_RANGE |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
204 } |
e1b511df0d3e
Make the combobox a tiny bit friendlier.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
30671
diff
changeset
|
205 |
15818 | 206 return FALSE; |
207 } | |
208 | |
209 static void | |
210 gnt_combo_box_destroy(GntWidget *widget) | |
211 { | |
212 gnt_widget_destroy(GNT_COMBO_BOX(widget)->dropdown->parent); | |
213 } | |
214 | |
215 static void | |
216 gnt_combo_box_lost_focus(GntWidget *widget) | |
217 { | |
218 GntComboBox *combo = GNT_COMBO_BOX(widget); | |
219 if (GNT_WIDGET_IS_FLAG_SET(combo->dropdown->parent, GNT_WIDGET_MAPPED)) | |
220 hide_popup(combo, FALSE); | |
221 widget_lost_focus(widget); | |
222 } | |
223 | |
224 static gboolean | |
225 gnt_combo_box_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
226 { | |
227 GntComboBox *box = GNT_COMBO_BOX(widget); | |
228 gboolean dshowing = GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED); | |
229 | |
230 if (event == GNT_MOUSE_SCROLL_UP) { | |
231 if (dshowing) | |
232 gnt_widget_key_pressed(box->dropdown, GNT_KEY_UP); | |
233 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
234 if (dshowing) | |
235 gnt_widget_key_pressed(box->dropdown, GNT_KEY_DOWN); | |
236 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
237 if (dshowing) { | |
238 hide_popup(box, TRUE); | |
239 } else { | |
240 popup_dropdown(GNT_COMBO_BOX(widget)); | |
241 } | |
242 } else | |
243 return FALSE; | |
244 return TRUE; | |
245 } | |
246 | |
247 static void | |
248 gnt_combo_box_size_changed(GntWidget *widget, int oldw, int oldh) | |
249 { | |
250 GntComboBox *box = GNT_COMBO_BOX(widget); | |
251 gnt_widget_set_size(box->dropdown, widget->priv.width - 1, box->dropdown->priv.height); | |
252 } | |
253 | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
254 static gboolean |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
255 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
|
256 { |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
257 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
|
258 return FALSE; |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
259 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
|
260 return TRUE; |
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 |
15818 | 263 static void |
264 gnt_combo_box_class_init(GntComboBoxClass *klass) | |
265 { | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
266 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
|
267 |
15818 | 268 parent_class = GNT_WIDGET_CLASS(klass); |
269 | |
270 parent_class->destroy = gnt_combo_box_destroy; | |
271 parent_class->draw = gnt_combo_box_draw; | |
272 parent_class->map = gnt_combo_box_map; | |
273 parent_class->size_request = gnt_combo_box_size_request; | |
274 parent_class->key_pressed = gnt_combo_box_key_pressed; | |
275 parent_class->clicked = gnt_combo_box_clicked; | |
276 parent_class->size_changed = gnt_combo_box_size_changed; | |
277 | |
278 widget_lost_focus = parent_class->lost_focus; | |
279 parent_class->lost_focus = gnt_combo_box_lost_focus; | |
280 | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
281 signals[SIG_SELECTION_CHANGED] = |
15818 | 282 g_signal_new("selection-changed", |
283 G_TYPE_FROM_CLASS(klass), | |
284 G_SIGNAL_RUN_LAST, | |
285 0, | |
286 NULL, NULL, | |
287 gnt_closure_marshal_VOID__POINTER_POINTER, | |
288 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
289 | |
30620
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
290 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
|
291 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
|
292 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
|
293 |
6943aec8cf61
Allow rebinding the key to show the dropdown menu for comboboxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
28984
diff
changeset
|
294 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
|
295 |
15818 | 296 GNTDEBUG; |
297 } | |
298 | |
299 static void | |
300 gnt_combo_box_init(GTypeInstance *instance, gpointer class) | |
301 { | |
302 GntWidget *box; | |
303 GntWidget *widget = GNT_WIDGET(instance); | |
304 GntComboBox *combo = GNT_COMBO_BOX(instance); | |
305 | |
306 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), | |
307 GNT_WIDGET_GROW_X | GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_NO_SHADOW); | |
308 combo->dropdown = gnt_tree_new(); | |
309 | |
310 box = gnt_box_new(FALSE, FALSE); | |
311 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | GNT_WIDGET_TRANSIENT); | |
312 gnt_box_set_pad(GNT_BOX(box), 0); | |
313 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
|
314 |
15818 | 315 widget->priv.minw = 4; |
316 widget->priv.minh = 3; | |
317 GNTDEBUG; | |
318 } | |
319 | |
320 /****************************************************************************** | |
321 * GntComboBox API | |
322 *****************************************************************************/ | |
323 GType | |
324 gnt_combo_box_get_gtype(void) | |
325 { | |
326 static GType type = 0; | |
327 | |
328 if(type == 0) | |
329 { | |
330 static const GTypeInfo info = { | |
331 sizeof(GntComboBoxClass), | |
332 NULL, /* base_init */ | |
333 NULL, /* base_finalize */ | |
334 (GClassInitFunc)gnt_combo_box_class_init, | |
335 NULL, /* class_finalize */ | |
336 NULL, /* class_data */ | |
337 sizeof(GntComboBox), | |
338 0, /* n_preallocs */ | |
339 gnt_combo_box_init, /* instance_init */ | |
340 NULL /* value_table */ | |
341 }; | |
342 | |
343 type = g_type_register_static(GNT_TYPE_WIDGET, | |
344 "GntComboBox", | |
345 &info, 0); | |
346 } | |
347 | |
348 return type; | |
349 } | |
350 | |
351 GntWidget *gnt_combo_box_new() | |
352 { | |
353 GntWidget *widget = g_object_new(GNT_TYPE_COMBO_BOX, NULL); | |
354 | |
355 return widget; | |
356 } | |
357 | |
358 void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text) | |
359 { | |
360 gnt_tree_add_row_last(GNT_TREE(box->dropdown), key, | |
361 gnt_tree_create_row(GNT_TREE(box->dropdown), text), NULL); | |
362 if (box->selected == NULL) | |
363 set_selection(box, key); | |
364 } | |
365 | |
366 gpointer gnt_combo_box_get_selected_data(GntComboBox *box) | |
367 { | |
368 return box->selected; | |
369 } | |
370 | |
371 void gnt_combo_box_set_selected(GntComboBox *box, gpointer key) | |
372 { | |
373 set_selection(box, key); | |
374 } | |
375 | |
376 void gnt_combo_box_remove(GntComboBox *box, gpointer key) | |
377 { | |
378 gnt_tree_remove(GNT_TREE(box->dropdown), key); | |
379 if (box->selected == key) | |
380 set_selection(box, NULL); | |
381 } | |
382 | |
383 void gnt_combo_box_remove_all(GntComboBox *box) | |
384 { | |
385 gnt_tree_remove_all(GNT_TREE(box->dropdown)); | |
386 set_selection(box, NULL); | |
387 } | |
388 |