Moved dir $(srcdir)/vfs into $(srcdir)/lib/vfs/mc-vfs
[midnight-commander.git] / src / dialog.c
blob1231d40c9a84ad5fad5cef252ad87701cca882fd
1 /* Dialog box features module for the Midnight Commander
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /** \file dialog.c
21 * \brief Source: dialog box features module
24 #include <config.h>
26 #include <ctype.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
32 #include "global.h"
34 #include "../src/tty/tty.h"
35 #include "../src/skin/skin.h"
36 #include "../src/tty/mouse.h"
37 #include "../src/tty/key.h"
39 #include "help.h" /* interactive_display() */
40 #include "dialog.h"
41 #include "layout.h"
42 #include "execute.h" /* suspend_cmd() */
43 #include "main.h" /* fast_refresh */
44 #include "strutil.h"
45 #include "setup.h" /* mouse_close_dialog */
47 /* Color styles for normal and error dialogs */
48 int dialog_colors [4];
49 int alarm_colors [4];
51 /* Primitive way to check if the the current dialog is our dialog */
52 /* This is needed by async routines like load_prompt */
53 Dlg_head *current_dlg = 0;
55 /* A hook list for idle events */
56 Hook *idle_hook = 0;
58 /* left click outside of dialog closes it */
59 int mouse_close_dialog = 0;
61 static void dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message,
62 int reverse, int flags);
64 /* draw box in window */
65 void
66 draw_box (Dlg_head *h, int y, int x, int ys, int xs)
68 tty_draw_box (h->y + y, h->x + x, ys, xs);
71 void
72 widget_erase (Widget *w)
74 tty_fill_region (w->y, w->x, w->lines, w->cols, ' ');
77 void
78 dlg_erase (Dlg_head *h)
80 if (h != NULL)
81 tty_fill_region (h->y, h->x, h->lines, h->cols, ' ');
84 void
85 init_widget (Widget *w, int y, int x, int lines, int cols,
86 callback_fn callback, mouse_h mouse_handler)
88 w->x = x;
89 w->y = y;
90 w->cols = cols;
91 w->lines = lines;
92 w->callback = callback;
93 w->mouse = mouse_handler;
94 w->parent = 0;
96 /* Almost all widgets want to put the cursor in a suitable place */
97 w->options = W_WANT_CURSOR;
100 /* Clean the dialog area, draw the frame and the title */
101 void
102 common_dialog_repaint (struct Dlg_head *h)
104 int space;
106 space = (h->flags & DLG_COMPACT) ? 0 : 1;
108 tty_setcolor (DLG_NORMALC (h));
109 dlg_erase (h);
110 draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space);
112 if (h->title) {
113 tty_setcolor (DLG_HOT_NORMALC (h));
114 dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2);
115 tty_print_string (h->title);
119 /* this function allows to set dialog position */
120 void
121 dlg_set_position (Dlg_head *h, int y1, int x1, int y2, int x2)
123 /* save old positions, will be used to reposition childs */
124 int ox, oy, oc, ol;
125 int shift_x, shift_y, scale_x, scale_y;
127 /* save old positions, will be used to reposition childs */
128 ox = h->x;
129 oy = h->y;
130 oc = h->cols;
131 ol = h->lines;
133 h->x = x1;
134 h->y = y1;
135 h->lines = y2 - y1;
136 h->cols = x2 - x1;
138 /* values by which controls should be moved */
139 shift_x = h->x - ox;
140 shift_y = h->y - oy;
141 scale_x = h->cols - oc;
142 scale_y = h->lines - ol;
144 if (h->current == NULL)
145 return;
147 if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0)) {
148 Widget *c = h->current;
150 do {
151 /* there are, mainly, 2 generally possible
152 situations:
154 1. control sticks to one side - it
155 should be moved
157 2. control sticks to two sides of
158 one direction - it should be sized */
160 int x = c->x;
161 int y = c->y;
162 int cols = c->cols;
163 int lines = c->lines;
165 if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT)) {
166 x += shift_x;
167 cols += scale_x;
168 } else if (c->pos_flags & WPOS_KEEP_LEFT)
169 x += shift_x;
170 else if (c->pos_flags & WPOS_KEEP_RIGHT)
171 x += shift_x + scale_x;
173 if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM)) {
174 y += shift_y;
175 lines += scale_y;
176 } else if (c->pos_flags & WPOS_KEEP_TOP)
177 y += shift_y;
178 else if (c->pos_flags & WPOS_KEEP_BOTTOM)
179 y += shift_y + scale_y;
181 widget_set_size (c, y, x, lines, cols);
183 c = c->next;
184 } while (h->current != c);
188 /* this function sets only size, leaving positioning to automatic methods */
189 void
190 dlg_set_size (Dlg_head *h, int lines, int cols)
192 int x = h->x;
193 int y = h->y;
195 if (h->flags & DLG_CENTER) {
196 y = (LINES - lines) / 2;
197 x = (COLS - cols) / 2;
200 if ((h->flags & DLG_TRYUP) && (y > 3))
201 y -= 2;
203 dlg_set_position (h, y, x, y + lines, x + cols);
206 /* Default dialog callback */
207 cb_ret_t
208 default_dlg_callback (Dlg_head *h, Widget *sender,
209 dlg_msg_t msg, int parm, void *data)
211 (void) sender;
212 (void) parm;
213 (void) data;
215 switch (msg) {
216 case DLG_DRAW:
217 if (h->color != NULL) {
218 common_dialog_repaint (h);
219 return MSG_HANDLED;
221 return MSG_NOT_HANDLED;
223 case DLG_IDLE:
224 dlg_broadcast_msg_to (h, WIDGET_IDLE, 0, W_WANT_IDLE);
225 return MSG_HANDLED;
227 case DLG_RESIZE:
228 /* this is default resizing mechanism */
229 /* the main idea of this code is to resize dialog
230 according to flags (if any of flags require automatic
231 resizing, like DLG_CENTER, end after that reposition
232 controls in dialog according to flags of widget) */
233 dlg_set_size (h, h->lines, h->cols);
234 return MSG_HANDLED;
236 default:
237 break;
240 return MSG_NOT_HANDLED;
243 Dlg_head *
244 create_dlg (int y1, int x1, int lines, int cols, const int *color_set,
245 dlg_cb_fn callback, const char *help_ctx, const char *title,
246 int flags)
248 Dlg_head *new_d;
250 new_d = g_new0 (Dlg_head, 1);
251 if (color_set != NULL) {
252 new_d->color = g_new (int, DLG_COLOR_NUM);
253 memmove (new_d->color, color_set, sizeof (int) * DLG_COLOR_NUM);
255 new_d->help_ctx = help_ctx;
256 new_d->callback = (callback != NULL) ? callback : default_dlg_callback;
257 new_d->x = x1;
258 new_d->y = y1;
259 new_d->flags = flags;
260 new_d->data = NULL;
262 dlg_set_size (new_d, lines, cols);
264 /* Strip existing spaces, add one space before and after the title */
265 if (title) {
266 char *t;
268 t = g_strstrip (g_strdup (title));
269 if (*t != '\0')
270 new_d->title = g_strdup_printf (" %s ", t);
271 g_free (t);
274 return new_d;
277 void
278 dlg_set_default_colors (void)
280 dialog_colors [0] = COLOR_NORMAL;
281 dialog_colors [1] = COLOR_FOCUS;
282 dialog_colors [2] = COLOR_HOT_NORMAL;
283 dialog_colors [3] = COLOR_HOT_FOCUS;
285 alarm_colors [0] = ERROR_COLOR;
286 alarm_colors [1] = REVERSE_COLOR;
287 alarm_colors [2] = ERROR_HOT_NORMAL;
288 alarm_colors [3] = ERROR_HOT_FOCUS;
291 void
292 set_idle_proc (Dlg_head *d, int enable)
294 if (enable)
295 d->flags |= DLG_WANT_IDLE;
296 else
297 d->flags &= ~DLG_WANT_IDLE;
301 * Insert widget to dialog before current widget. For dialogs populated
302 * from the bottom, make the widget current. Return widget number.
305 add_widget_autopos (Dlg_head *h, void *w, widget_pos_flags_t pos_flags)
307 Widget *widget = (Widget *) w;
309 /* Don't accept 0 widgets, and running dialogs */
310 if (!widget || h->running)
311 abort ();
313 widget->x += h->x;
314 widget->y += h->y;
315 widget->parent = h;
316 widget->dlg_id = h->count++;
317 widget->pos_flags = pos_flags;
319 if (h->current) {
320 widget->next = h->current;
321 widget->prev = h->current->prev;
322 h->current->prev->next = widget;
323 h->current->prev = widget;
324 } else {
325 widget->prev = widget;
326 widget->next = widget;
329 if ((h->flags & DLG_REVERSE) || !h->current)
330 h->current = widget;
332 return widget->dlg_id;
335 /* wrapper to simply add lefttop positioned controls */
337 add_widget (Dlg_head *h, void *w)
339 return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP);
342 static void
343 do_complete_refresh (Dlg_head *dlg)
345 if (!dlg->fullscreen && dlg->parent)
346 do_complete_refresh (dlg->parent);
348 dlg_redraw (dlg);
351 void
352 do_refresh (void)
354 if (!current_dlg)
355 return;
357 if (fast_refresh)
358 dlg_redraw (current_dlg);
359 else {
360 do_complete_refresh (current_dlg);
364 /* broadcast a message to all the widgets in a dialog that have
365 * the options set to flags. If flags is zero, the message is sent
366 * to all widgets.
368 static void
369 dlg_broadcast_msg_to (Dlg_head *h, widget_msg_t message, int reverse,
370 int flags)
372 Widget *p, *first, *wi;
374 if (!h->current)
375 return;
377 if (reverse)
378 first = p = h->current->prev;
379 else
380 first = p = h->current->next;
382 do {
383 wi = p;
384 if (reverse)
385 p = p->prev;
386 else
387 p = p->next;
388 if (flags == 0 || (flags & wi->options))
389 send_message (wi, message, 0);
390 } while (first != p);
393 /* broadcast a message to all the widgets in a dialog */
394 void
395 dlg_broadcast_msg (Dlg_head *h, widget_msg_t message, int reverse)
397 dlg_broadcast_msg_to (h, message, reverse, 0);
401 dlg_focus (Dlg_head *h)
403 if ((h->current != NULL)
404 && (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED)) {
405 h->callback (h, h->current, DLG_FOCUS, 0, NULL);
406 return 1;
408 return 0;
411 static int
412 dlg_unfocus (Dlg_head *h)
414 if ((h->current != NULL)
415 && (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED)) {
416 h->callback (h, h->current, DLG_UNFOCUS, 0, NULL);
417 return 1;
419 return 0;
423 /* Return true if the windows overlap */
424 int dlg_overlap (Widget *a, Widget *b)
426 if ((b->x >= a->x + a->cols)
427 || (a->x >= b->x + b->cols)
428 || (b->y >= a->y + a->lines)
429 || (a->y >= b->y + b->lines))
430 return 0;
431 return 1;
435 /* Find the widget with the given callback in the dialog h */
436 Widget *
437 find_widget_type (const Dlg_head *h, callback_fn callback)
439 Widget *w = NULL;
441 if ((h != NULL) && (h->current != NULL)) {
442 int i;
443 Widget *item;
445 for (i = 0, item = h->current; i < h->count; i++, item = item->next) {
446 if (item->callback == callback) {
447 w = item;
448 break;
453 return w;
456 /* Find the widget with the given dialog id in the dialog h and select it */
457 void
458 dlg_select_by_id (const Dlg_head *h, int id)
460 Widget *w, *w_found;
462 if (!h->current)
463 return;
465 w = h->current;
466 w_found = NULL;
468 do {
469 if (w->dlg_id == id) {
470 w_found = w;
471 break;
473 w = w->next;
474 } while (w != h->current);
476 if (w_found)
477 dlg_select_widget(w_found);
481 /* What to do if the requested widget doesn't take focus */
482 typedef enum {
483 SELECT_NEXT, /* go the the next widget */
484 SELECT_PREV, /* go the the previous widget */
485 SELECT_EXACT /* use current widget */
486 } select_dir_t;
489 * Try to select another widget. If forward is set, follow tab order.
490 * Otherwise go to the previous widget.
492 static void
493 do_select_widget (Dlg_head *h, Widget *w, select_dir_t dir)
495 Widget *w0 = h->current;
497 if (!dlg_unfocus (h))
498 return;
500 h->current = w;
501 do {
502 if (dlg_focus (h))
503 break;
505 switch (dir) {
506 case SELECT_NEXT:
507 h->current = h->current->next;
508 break;
509 case SELECT_PREV:
510 h->current = h->current->prev;
511 break;
512 case SELECT_EXACT:
513 h->current = w0;
514 dlg_focus (h);
515 return;
517 } while (h->current != w);
519 if (dlg_overlap (w0, h->current)) {
520 send_message (h->current, WIDGET_DRAW, 0);
521 send_message (h->current, WIDGET_FOCUS, 0);
527 * Try to select widget in the dialog.
529 void
530 dlg_select_widget (void *w)
532 do_select_widget (((Widget *) w)->parent, w, SELECT_NEXT);
536 /* Try to select previous widget in the tab order */
537 void
538 dlg_one_up (Dlg_head *h)
540 if (h->current)
541 do_select_widget (h, h->current->prev, SELECT_PREV);
545 /* Try to select next widget in the tab order */
546 void
547 dlg_one_down (Dlg_head *h)
549 if (h->current)
550 do_select_widget (h, h->current->next, SELECT_NEXT);
554 void update_cursor (Dlg_head *h)
556 Widget *p = h->current;
558 if (p != NULL) {
559 if (p->options & W_WANT_CURSOR)
560 send_message (p, WIDGET_CURSOR, 0);
561 else
562 while ((p = p->next) != h->current)
563 if (p->options & W_WANT_CURSOR)
564 if (send_message (p, WIDGET_CURSOR, 0) == MSG_HANDLED)
565 break;
569 /* Redraw the widgets in reverse order, leaving the current widget
570 * as the last one
572 void
573 dlg_redraw (Dlg_head *h)
575 h->callback (h, NULL, DLG_DRAW, 0, NULL);
576 dlg_broadcast_msg (h, WIDGET_DRAW, 1);
577 update_cursor (h);
580 void
581 dlg_stop (Dlg_head *h)
583 h->running = 0;
586 static void
587 dialog_handle_key (Dlg_head *h, int d_key)
589 if (is_abort_char (d_key)) {
590 h->ret_value = B_CANCEL;
591 dlg_stop (h);
592 return;
595 switch (d_key) {
596 case '\n':
597 case KEY_ENTER:
598 h->ret_value = B_ENTER;
599 dlg_stop (h);
600 break;
602 case KEY_LEFT:
603 case KEY_UP:
604 dlg_one_up (h);
605 break;
607 case KEY_RIGHT:
608 case KEY_DOWN:
609 dlg_one_down (h);
610 break;
612 case KEY_F(1):
613 interactive_display (NULL, h->help_ctx);
614 do_refresh ();
615 break;
617 case XCTRL('z'):
618 suspend_cmd ();
619 /* Fall through */
621 case XCTRL('l'):
622 #ifdef HAVE_SLANG
623 tty_touch_screen ();
624 mc_refresh ();
625 #else
626 /* Use this if the refreshes fail */
627 clr_scr ();
628 repaint_screen ();
629 #endif /* HAVE_SLANG */
630 break;
632 default:
633 break;
637 static cb_ret_t
638 dlg_try_hotkey (Dlg_head *h, int d_key)
640 Widget *hot_cur;
641 cb_ret_t handled;
642 int c;
644 if (h->current == NULL)
645 return MSG_NOT_HANDLED;
648 * Explanation: we don't send letter hotkeys to other widgets if
649 * the currently selected widget is an input line
652 if (h->current->options & W_IS_INPUT) {
653 /* skip ascii control characters, anything else can valid character in
654 * some encoding */
655 if (d_key >= 32 && d_key < 256)
656 return MSG_NOT_HANDLED;
659 /* If it's an alt key, send the message */
660 c = d_key & ~ALT (0);
661 if (d_key & ALT (0) && g_ascii_isalpha (c))
662 d_key = g_ascii_tolower (c);
664 handled = MSG_NOT_HANDLED;
665 if (h->current->options & W_WANT_HOTKEY)
666 handled = send_message (h->current, WIDGET_HOTKEY, d_key);
668 /* If not used, send hotkey to other widgets */
669 if (handled == MSG_HANDLED)
670 return MSG_HANDLED;
672 hot_cur = h->current->next;
674 /* send it to all widgets */
675 while (h->current != hot_cur && handled == MSG_NOT_HANDLED) {
676 if (hot_cur->options & W_WANT_HOTKEY)
677 handled = send_message (hot_cur, WIDGET_HOTKEY, d_key);
679 if (handled == MSG_NOT_HANDLED)
680 hot_cur = hot_cur->next;
683 if (handled == MSG_HANDLED)
684 do_select_widget (h, hot_cur, SELECT_EXACT);
686 return handled;
689 static void
690 dlg_key_event (Dlg_head *h, int d_key)
692 cb_ret_t handled;
694 if (h->current == NULL)
695 return;
697 /* TAB used to cycle */
698 if (!(h->flags & DLG_WANT_TAB)) {
699 if (d_key == '\t') {
700 dlg_one_down (h);
701 return;
702 } else if (d_key == KEY_BTAB) {
703 dlg_one_up (h);
704 return;
708 /* first can dlg_callback handle the key */
709 handled = h->callback (h, NULL, DLG_KEY, d_key, NULL);
711 /* next try the hotkey */
712 if (handled == MSG_NOT_HANDLED)
713 handled = dlg_try_hotkey (h, d_key);
715 if (handled == MSG_HANDLED)
716 h->callback (h, NULL, DLG_HOTKEY_HANDLED, 0, NULL);
717 else
718 /* not used - then try widget_callback */
719 handled = send_message (h->current, WIDGET_KEY, d_key);
721 /* not used- try to use the unhandled case */
722 if (handled == MSG_NOT_HANDLED)
723 handled = h->callback (h, NULL, DLG_UNHANDLED_KEY, d_key, NULL);
725 if (handled == MSG_NOT_HANDLED)
726 dialog_handle_key (h, d_key);
728 h->callback (h, NULL, DLG_POST_KEY, d_key, NULL);
731 static int
732 dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
734 Widget *item;
735 Widget *starting_widget = h->current;
736 Gpm_Event new_event;
737 int x = event->x;
738 int y = event->y;
740 /* close the dialog by mouse click out of dialog area */
741 if (mouse_close_dialog && !h->fullscreen
742 && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
743 && !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines))) {
744 h->ret_value = B_CANCEL;
745 dlg_stop (h);
746 return MOU_NORMAL;
749 item = starting_widget;
750 do {
751 Widget *widget;
753 widget = item;
754 item = item->next;
756 if ((x > widget->x) && (x <= widget->x + widget->cols)
757 && (y > widget->y) && (y <= widget->y + widget->lines)) {
758 new_event = *event;
759 new_event.x -= widget->x;
760 new_event.y -= widget->y;
762 if (widget->mouse != NULL)
763 return widget->mouse (&new_event, widget);
765 } while (item != starting_widget);
767 return MOU_NORMAL;
770 /* Run dialog routines */
772 /* Init the process */
773 void
774 init_dlg (Dlg_head *h)
776 /* Initialize dialog manager and widgets */
777 h->callback (h, NULL, DLG_INIT, 0, NULL);
778 dlg_broadcast_msg (h, WIDGET_INIT, 0);
780 if (h->x == 0 && h->y == 0 && h->cols == COLS && h->lines == LINES)
781 h->fullscreen = 1;
783 h->parent = current_dlg;
784 current_dlg = h;
786 /* Initialize the mouse status */
787 h->mouse_status = MOU_NORMAL;
789 /* Select the first widget that takes focus */
790 while (!dlg_focus (h) && h->current)
791 h->current = h->current->next;
793 /* Redraw the screen */
794 dlg_redraw (h);
796 h->ret_value = 0;
797 h->running = 1;
800 /* Shutdown the run_dlg */
801 void
802 dlg_run_done (Dlg_head *h)
804 if (h->current != NULL)
805 h->callback (h, h->current, DLG_END, 0, NULL);
807 current_dlg = h->parent;
810 void
811 dlg_process_event (Dlg_head *h, int key, Gpm_Event *event)
813 if (key == EV_NONE){
814 if (tty_got_interrupt ())
815 key = XCTRL('g');
816 else
817 return;
820 if (key == EV_MOUSE)
821 h->mouse_status = dlg_mouse_event (h, event);
822 else
823 dlg_key_event (h, key);
826 static void
827 frontend_run_dlg (Dlg_head *h)
829 int d_key;
830 Gpm_Event event;
832 event.x = -1;
833 while (h->running) {
834 if (winch_flag)
835 change_screen_size ();
837 if (is_idle ()) {
838 if (idle_hook)
839 execute_hooks (idle_hook);
841 while ((h->flags & DLG_WANT_IDLE) && is_idle ())
842 h->callback (h, NULL, DLG_IDLE, 0, NULL);
844 /* Allow terminating the dialog from the idle handler */
845 if (!h->running)
846 break;
849 update_cursor (h);
851 /* Clear interrupt flag */
852 tty_got_interrupt ();
853 d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE);
855 dlg_process_event (h, d_key, &event);
857 if (!h->running)
858 h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
862 /* Standard run dialog routine
863 * We have to keep this routine small so that we can duplicate it's
864 * behavior on complex routines like the file routines, this way,
865 * they can call the dlg_process_event without rewriting all the code
867 int run_dlg (Dlg_head *h)
869 init_dlg (h);
870 frontend_run_dlg (h);
871 dlg_run_done (h);
872 return h->ret_value;
875 void
876 destroy_dlg (Dlg_head *h)
878 int i;
879 Widget *c;
881 dlg_broadcast_msg (h, WIDGET_DESTROY, 0);
882 c = h->current;
883 for (i = 0; i < h->count; i++) {
884 c = c->next;
885 g_free (h->current);
886 h->current = c;
888 g_free (h->color);
889 g_free (h->title);
890 g_free (h);
892 do_refresh ();
895 void widget_set_size (Widget *widget, int y, int x, int lines, int cols)
897 widget->x = x;
898 widget->y = y;
899 widget->cols = cols;
900 widget->lines = lines;
901 send_message (widget, WIDGET_RESIZED, 0 /* unused */);
904 /* Replace widget old_w for widget new_w in the dialog */
905 void
906 dlg_replace_widget (Widget *old_w, Widget *new_w)
908 Dlg_head *h = old_w->parent;
909 int should_focus = 0;
911 if (!h->current)
912 return;
914 if (old_w == h->current)
915 should_focus = 1;
917 new_w->parent = h;
918 new_w->dlg_id = old_w->dlg_id;
920 if (old_w == old_w->next) {
921 /* just one widget */
922 new_w->prev = new_w;
923 new_w->next = new_w;
924 } else {
925 new_w->prev = old_w->prev;
926 new_w->next = old_w->next;
927 old_w->prev->next = new_w;
928 old_w->next->prev = new_w;
931 if (should_focus)
932 h->current = new_w;
934 send_message (old_w, WIDGET_DESTROY, 0);
935 send_message (new_w, WIDGET_INIT, 0);
937 if (should_focus)
938 dlg_select_widget (new_w);
940 send_message (new_w, WIDGET_DRAW, 0);