Mercurial > pidgin
comparison console/libgnt/gntbox.c @ 13855:5b288502a382
[gaim-migrate @ 16314]
New widget GntEntry. It's mostly functional.
Some minor improvements to the box-packing code.
Minor improvements to the skeleton code for gnt, and completely change the name from my initial choice of GN (Glib and Ncurses) to GNT (Gaim Ncurses Toolkit).
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 23 Jun 2006 06:24:25 +0000 |
parents | a4c30c1d9de8 |
children | c1e3f7c75c3f |
comparison
equal
deleted
inserted
replaced
13854:a4c30c1d9de8 | 13855:5b288502a382 |
---|---|
51 int w, h, curx, cury, max; | 51 int w, h, curx, cury, max; |
52 gboolean has_border = FALSE; | 52 gboolean has_border = FALSE; |
53 | 53 |
54 w = h = 0; | 54 w = h = 0; |
55 max = -1; | 55 max = -1; |
56 curx = widget->priv.x + 1; | 56 curx = widget->priv.x; |
57 cury = widget->priv.y + 1; | 57 cury = widget->priv.y; |
58 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) | 58 if (!(GNT_WIDGET_FLAGS(widget) & GNT_WIDGET_NO_BORDER)) |
59 { | 59 { |
60 has_border = TRUE; | 60 has_border = TRUE; |
61 curx += box->pad; | 61 curx += 1; |
62 cury += box->pad; | 62 cury += 1; |
63 if (!box->vertical) | |
64 curx++; | |
65 } | 63 } |
66 | 64 |
67 for (iter = box->list; iter; iter = iter->next) | 65 for (iter = box->list; iter; iter = iter->next) |
68 { | 66 { |
69 gnt_widget_set_position(GNT_WIDGET(iter->data), curx, cury); | 67 gnt_widget_set_position(GNT_WIDGET(iter->data), curx, cury); |
82 } | 80 } |
83 } | 81 } |
84 | 82 |
85 if (has_border) | 83 if (has_border) |
86 { | 84 { |
87 curx += 2; | 85 curx += 1; |
88 cury += 1; | 86 cury += 1; |
89 max += 2; | 87 max += 2; |
90 } | 88 } |
91 | 89 |
92 if (box->vertical) | 90 if (box->vertical) |
144 if (widget->priv.width == 0 || widget->priv.height == 0) | 142 if (widget->priv.width == 0 || widget->priv.height == 0) |
145 gnt_widget_size_request(widget); | 143 gnt_widget_size_request(widget); |
146 DEBUG; | 144 DEBUG; |
147 } | 145 } |
148 | 146 |
147 /* Ensures that the current widget can take focus */ | |
148 static void | |
149 ensure_active(GntBox *box) | |
150 { | |
151 int investigated = 0; | |
152 int total; | |
153 | |
154 if (box->active == NULL) | |
155 box->active = box->list; | |
156 | |
157 total = g_list_length(box->list); | |
158 | |
159 while (box->active && !GNT_WIDGET_IS_FLAG_SET(box->active->data, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
160 { | |
161 box->active = box->active->next; | |
162 investigated++; | |
163 } | |
164 | |
165 /* Rotate if necessary */ | |
166 if (!box->active && investigated < total) | |
167 { | |
168 box->active = box->list; | |
169 while (investigated < total && !GNT_WIDGET_IS_FLAG_SET(box->active->data, GNT_WIDGET_CAN_TAKE_FOCUS)) | |
170 { | |
171 box->active = box->active->next; | |
172 investigated++; | |
173 } | |
174 } | |
175 } | |
176 | |
149 static gboolean | 177 static gboolean |
150 gnt_box_key_pressed(GntWidget *widget, const char *text) | 178 gnt_box_key_pressed(GntWidget *widget, const char *text) |
151 { | 179 { |
152 GntBox *box = GNT_BOX(widget); | 180 GntBox *box = GNT_BOX(widget); |
153 | 181 |
154 /*if (box->list == NULL)*/ | 182 ensure_active(box); |
155 /*return FALSE;*/ | |
156 | |
157 if (box->active == NULL) | 183 if (box->active == NULL) |
158 box->active = box->list; | 184 return FALSE; |
159 | 185 |
160 if (gnt_widget_key_pressed(box->active->data, text)) | 186 if (gnt_widget_key_pressed(box->active->data, text)) |
161 return TRUE; | 187 return TRUE; |
162 | 188 |
163 if (text[0] == 27) | 189 if (text[0] == 27) |