comparison console/libgnt/gntbox.c @ 13930:3dbcbc5e57e1

[gaim-migrate @ 16457] Enable resizing (Alt+r, then the arrow keys, then enter/escape to end). It 'works', but needs fine-tuning. But I am going to put it off for a later date. Some other minor decoration tweaks. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 08 Jul 2006 02:11:11 +0000
parents 9309d27d780c
children 917a71dd02eb
comparison
equal deleted inserted replaced
13929:59af3aecf580 13930:3dbcbc5e57e1
37 gnt_box_sync_children(box); 37 gnt_box_sync_children(box);
38 38
39 if (box->title) 39 if (box->title)
40 { 40 {
41 gchar *title = g_strdup(box->title); 41 gchar *title = g_strdup(box->title);
42 int pos = g_utf8_strlen(title, -1); 42 int pos = g_utf8_strlen(title, -1), right;
43 43
44 if (pos >= widget->priv.width - 2) 44 if (pos >= widget->priv.width - 4)
45 { 45 {
46 g_utf8_strncpy(title, box->title, widget->priv.width - 2); 46 g_utf8_strncpy(title, box->title, widget->priv.width - 4);
47 pos = 1; 47 pos = 2;
48 right = pos + g_utf8_strlen(title, -1);
48 } 49 }
49 else 50 else
50 { 51 {
51 /* XXX: Position of the title might be configurable */ 52 /* XXX: Position of the title might be configurable */
53 right = pos;
52 pos = (widget->priv.width - pos) / 2; 54 pos = (widget->priv.width - pos) / 2;
55 right += pos;
53 } 56 }
54 57
55 if (gnt_widget_has_focus(widget)) 58 if (gnt_widget_has_focus(widget))
56 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_TITLE)); 59 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_TITLE));
57 else 60 else
58 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_TITLE_D)); 61 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_TITLE_D));
62 mvwaddch(widget->window, 0, pos-1, ACS_RTEE | COLOR_PAIR(GNT_COLOR_NORMAL));
59 mvwprintw(widget->window, 0, pos, title); 63 mvwprintw(widget->window, 0, pos, title);
64 mvwaddch(widget->window, 0, right, ACS_LTEE | COLOR_PAIR(GNT_COLOR_NORMAL));
60 g_free(title); 65 g_free(title);
61 } 66 }
62 67
63 DEBUG; 68 DEBUG;
64 } 69 }
269 { 274 {
270 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x); 275 WINDOW *win = newwin(height, width, widget->priv.y + y, widget->priv.x + x);
271 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE); 276 copywin(widget->window, win, y, x, 0, 0, height - 1, width - 1, FALSE);
272 wrefresh(win); 277 wrefresh(win);
273 delwin(win); 278 delwin(win);
279 }
280
281 static gboolean
282 gnt_box_confirm_size(GntWidget *widget, int width, int height)
283 {
284 GList *iter;
285 GntBox *box = GNT_BOX(widget);
286 int wchange, hchange;
287 int wc = 0, hc = 0;
288
289 wchange = widget->priv.width - width;
290 hchange = widget->priv.height - height;
291
292 /* XXX: Right now, I am trying to just apply all the changes to
293 * just one widget. It should be possible to distribute the
294 * changes to all the widgets in the box. */
295 for (iter = box->list; iter; iter = iter->next)
296 {
297 GntWidget *wid = iter->data;
298 int w, h;
299
300 gnt_widget_get_size(wid, &w, &h);
301
302 if (gnt_widget_set_size(wid, w - wchange, h - hchange))
303 return TRUE;
304 }
305
306 return FALSE;
274 } 307 }
275 308
276 static void 309 static void
277 gnt_box_class_init(GntBoxClass *klass) 310 gnt_box_class_init(GntBoxClass *klass)
278 { 311 {
284 parent_class->size_request = gnt_box_size_request; 317 parent_class->size_request = gnt_box_size_request;
285 parent_class->set_position = gnt_box_set_position; 318 parent_class->set_position = gnt_box_set_position;
286 parent_class->key_pressed = gnt_box_key_pressed; 319 parent_class->key_pressed = gnt_box_key_pressed;
287 parent_class->lost_focus = gnt_box_lost_focus; 320 parent_class->lost_focus = gnt_box_lost_focus;
288 parent_class->gained_focus = gnt_box_gained_focus; 321 parent_class->gained_focus = gnt_box_gained_focus;
322 parent_class->confirm_size = gnt_box_confirm_size;
289 323
290 DEBUG; 324 DEBUG;
291 } 325 }
292 326
293 static void 327 static void
294 gnt_box_init(GTypeInstance *instance, gpointer class) 328 gnt_box_init(GTypeInstance *instance, gpointer class)
295 { 329 {
330 /* Initially make both the height and width resizable.
331 * Update the flags as necessary when widgets are added to it. */
332 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(instance), GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y);
296 DEBUG; 333 DEBUG;
297 } 334 }
298 335
299 /****************************************************************************** 336 /******************************************************************************
300 * GntBox API 337 * GntBox API
342 379
343 void gnt_box_add_widget(GntBox *b, GntWidget *widget) 380 void gnt_box_add_widget(GntBox *b, GntWidget *widget)
344 { 381 {
345 b->list = g_list_append(b->list, widget); 382 b->list = g_list_append(b->list, widget);
346 widget->parent = GNT_WIDGET(b); 383 widget->parent = GNT_WIDGET(b);
384
385 if (b->vertical)
386 {
387 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_X))
388 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(b), GNT_WIDGET_GROW_X);
389 }
390 else
391 {
392 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_GROW_Y))
393 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(b), GNT_WIDGET_GROW_Y);
394 }
347 } 395 }
348 396
349 void gnt_box_set_title(GntBox *b, const char *title) 397 void gnt_box_set_title(GntBox *b, const char *title)
350 { 398 {
351 g_free(b->title); 399 g_free(b->title);