comparison console/libgnt/gntcombobox.c @ 14344:ed771d01239b

[gaim-migrate @ 17046] Fine-tuning the mouse-event handling in the combobox. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 26 Aug 2006 13:53:10 +0000
parents 0387a167f342
children c4a32405af68
comparison
equal deleted inserted replaced
14343:0387a167f342 14344:ed771d01239b
1 #include "gntbox.h" 1 #include "gntbox.h"
2 #include "gntcombobox.h" 2 #include "gntcombobox.h"
3 #include "gnttree.h" 3 #include "gnttree.h"
4 #include "gntmarshal.h" 4 #include "gntmarshal.h"
5 #include "gntutils.h"
5 6
6 #include <string.h> 7 #include <string.h>
7 8
8 enum 9 enum
9 { 10 {
37 GntComboBox *box = GNT_COMBO_BOX(widget); 38 GntComboBox *box = GNT_COMBO_BOX(widget);
38 char *text = NULL; 39 char *text = NULL;
39 GntColorType type; 40 GntColorType type;
40 int len; 41 int len;
41 42
42 if (box->dropdown) 43 if (box->dropdown && box->selected)
43 {
44 text = gnt_tree_get_selection_text(GNT_TREE(box->dropdown)); 44 text = gnt_tree_get_selection_text(GNT_TREE(box->dropdown));
45 box->selected = gnt_tree_get_selection_data(GNT_TREE(box->dropdown));
46 }
47 45
48 if (text == NULL) 46 if (text == NULL)
49 text = g_strdup(text); 47 text = g_strdup("");
50 48
51 if (gnt_widget_has_focus(widget)) 49 if (gnt_widget_has_focus(widget))
52 type = GNT_COLOR_HIGHLIGHT; 50 type = GNT_COLOR_HIGHLIGHT;
53 else 51 else
54 type = GNT_COLOR_NORMAL; 52 type = GNT_COLOR_NORMAL;
55 53
56 wbkgdset(widget->window, '\0' | COLOR_PAIR(type)); 54 wbkgdset(widget->window, '\0' | COLOR_PAIR(type));
57 55
58 if ((len = g_utf8_strlen(text, -1)) > widget->priv.width - 4) 56 if ((len = g_utf8_strlen(text, -1)) > widget->priv.width - 4)
59 { 57 {
60 char *s = g_utf8_offset_to_pointer(text, widget->priv.width - 4); 58 char *s = gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, NULL);
61 *s = '\0'; 59 *s = '\0';
62 len = widget->priv.width - 4; 60 len = widget->priv.width - 4;
63 } 61 }
64 62
65 mvwprintw(widget->window, 1, 1, text); 63 mvwprintw(widget->window, 1, 1, text);
104 y = widget->priv.y - height - 1; 102 y = widget->priv.y - height - 1;
105 gnt_widget_set_position(parent, widget->priv.x, y); 103 gnt_widget_set_position(parent, widget->priv.x, y);
106 if (parent->window) 104 if (parent->window)
107 { 105 {
108 mvwin(parent->window, y, widget->priv.x); 106 mvwin(parent->window, y, widget->priv.x);
107 wresize(parent->window, height+2, widget->priv.width);
109 } 108 }
110 109
111 gnt_widget_draw(parent); 110 gnt_widget_draw(parent);
112 } 111 }
113 112
178 if (dshowing) 177 if (dshowing)
179 gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_DOWN); 178 gnt_widget_key_pressed(box->dropdown, "\033" GNT_KEY_DOWN);
180 } else if (event == GNT_LEFT_MOUSE_DOWN) { 179 } else if (event == GNT_LEFT_MOUSE_DOWN) {
181 if (dshowing) { 180 if (dshowing) {
182 set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); 181 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); 182 gnt_widget_hide(box->dropdown->parent);
185 } else { 183 } else {
186 popup_dropdown(GNT_COMBO_BOX(widget)); 184 popup_dropdown(GNT_COMBO_BOX(widget));
187 return TRUE;
188 } 185 }
189 } else 186 } else
190 return FALSE; 187 return FALSE;
191 return TRUE; 188 return TRUE;
192 } 189 }