Mercurial > pidgin.yaz
comparison console/libgnt/gntcombobox.c @ 14343:0387a167f342
[gaim-migrate @ 17044]
A WM can now act on keystrokes. As an example, the sample WM will toggle
the buddylist on pressing Alt+b.
Mouse clicking and scrolling is now supported in most/all widgets.
To use a WM, you need to add "wm=/path/to/wm.so" under [general] in ~/.gntrc.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 26 Aug 2006 12:54:39 +0000 |
parents | 2c85b0f97dd0 |
children | ed771d01239b |
comparison
equal
deleted
inserted
replaced
14342:12156328fb4f | 14343:0387a167f342 |
---|---|
87 gnt_combo_box_map(GntWidget *widget) | 87 gnt_combo_box_map(GntWidget *widget) |
88 { | 88 { |
89 if (widget->priv.width == 0 || widget->priv.height == 0) | 89 if (widget->priv.width == 0 || widget->priv.height == 0) |
90 gnt_widget_size_request(widget); | 90 gnt_widget_size_request(widget); |
91 DEBUG; | 91 DEBUG; |
92 } | |
93 | |
94 static void | |
95 popup_dropdown(GntComboBox *box) | |
96 { | |
97 GntWidget *widget = GNT_WIDGET(box); | |
98 GntWidget *parent = box->dropdown->parent; | |
99 int height = g_list_length(GNT_TREE(box->dropdown)->list); | |
100 int y = widget->priv.y + widget->priv.height - 1; | |
101 gnt_widget_set_size(box->dropdown, widget->priv.width, height + 2); | |
102 | |
103 if (y + height + 2 >= getmaxy(stdscr)) | |
104 y = widget->priv.y - height - 1; | |
105 gnt_widget_set_position(parent, widget->priv.x, y); | |
106 if (parent->window) | |
107 { | |
108 mvwin(parent->window, y, widget->priv.x); | |
109 } | |
110 | |
111 gnt_widget_draw(parent); | |
92 } | 112 } |
93 | 113 |
94 static gboolean | 114 static gboolean |
95 gnt_combo_box_key_pressed(GntWidget *widget, const char *text) | 115 gnt_combo_box_key_pressed(GntWidget *widget, const char *text) |
96 { | 116 { |
119 if (text[0] == 27) | 139 if (text[0] == 27) |
120 { | 140 { |
121 if (strcmp(text + 1, GNT_KEY_UP) == 0 || | 141 if (strcmp(text + 1, GNT_KEY_UP) == 0 || |
122 strcmp(text + 1, GNT_KEY_DOWN) == 0) | 142 strcmp(text + 1, GNT_KEY_DOWN) == 0) |
123 { | 143 { |
124 GntWidget *parent = box->dropdown->parent; | 144 popup_dropdown(box); |
125 int height = g_list_length(GNT_TREE(box->dropdown)->list); | |
126 int y = widget->priv.y + widget->priv.height - 1; | |
127 gnt_widget_set_size(box->dropdown, widget->priv.width, height + 2); | |
128 | |
129 if (y + height + 2 >= getmaxy(stdscr)) | |
130 y = widget->priv.y - height - 1; | |
131 gnt_widget_set_position(parent, widget->priv.x, y); | |
132 if (parent->window) | |
133 { | |
134 mvwin(parent->window, y, widget->priv.x); | |
135 } | |
136 | |
137 gnt_widget_draw(parent); | |
138 return TRUE; | 145 return TRUE; |
139 } | 146 } |
140 } | 147 } |
141 } | 148 } |
142 | 149 |
154 { | 161 { |
155 GntComboBox *combo = GNT_COMBO_BOX(widget); | 162 GntComboBox *combo = GNT_COMBO_BOX(widget); |
156 if (GNT_WIDGET_IS_FLAG_SET(combo->dropdown->parent, GNT_WIDGET_MAPPED)) | 163 if (GNT_WIDGET_IS_FLAG_SET(combo->dropdown->parent, GNT_WIDGET_MAPPED)) |
157 gnt_widget_hide(GNT_COMBO_BOX(widget)->dropdown->parent); | 164 gnt_widget_hide(GNT_COMBO_BOX(widget)->dropdown->parent); |
158 widget_lost_focus(widget); | 165 widget_lost_focus(widget); |
166 } | |
167 | |
168 static gboolean | |
169 gnt_combo_box_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) | |
170 { | |
171 GntComboBox *box = GNT_COMBO_BOX(widget); | |
172 gboolean dshowing = GNT_WIDGET_IS_FLAG_SET(box->dropdown->parent, GNT_WIDGET_MAPPED); | |
173 | |
174 if (event == GNT_MOUSE_SCROLL_UP) { | |
175 if (dshowing) | |
176 gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_UP); | |
177 } else if (event == GNT_MOUSE_SCROLL_DOWN) { | |
178 if (dshowing) | |
179 gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_DOWN); | |
180 } else if (event == GNT_LEFT_MOUSE_DOWN) { | |
181 if (dshowing) { | |
182 set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); | |
183 gnt_tree_set_selected(GNT_TREE(box->dropdown), box->selected); | |
184 gnt_widget_hide(box->dropdown->parent); | |
185 } else { | |
186 popup_dropdown(GNT_COMBO_BOX(widget)); | |
187 return TRUE; | |
188 } | |
189 } else | |
190 return FALSE; | |
191 return TRUE; | |
159 } | 192 } |
160 | 193 |
161 static void | 194 static void |
162 gnt_combo_box_class_init(GntComboBoxClass *klass) | 195 gnt_combo_box_class_init(GntComboBoxClass *klass) |
163 { | 196 { |
166 parent_class->destroy = gnt_combo_box_destroy; | 199 parent_class->destroy = gnt_combo_box_destroy; |
167 parent_class->draw = gnt_combo_box_draw; | 200 parent_class->draw = gnt_combo_box_draw; |
168 parent_class->map = gnt_combo_box_map; | 201 parent_class->map = gnt_combo_box_map; |
169 parent_class->size_request = gnt_combo_box_size_request; | 202 parent_class->size_request = gnt_combo_box_size_request; |
170 parent_class->key_pressed = gnt_combo_box_key_pressed; | 203 parent_class->key_pressed = gnt_combo_box_key_pressed; |
204 parent_class->clicked = gnt_combo_box_clicked; | |
171 | 205 |
172 widget_lost_focus = parent_class->lost_focus; | 206 widget_lost_focus = parent_class->lost_focus; |
173 parent_class->lost_focus = gnt_combo_box_lost_focus; | 207 parent_class->lost_focus = gnt_combo_box_lost_focus; |
174 | 208 |
175 signals[SIG_SELECTION_CHANGED] = | 209 signals[SIG_SELECTION_CHANGED] = |