Applied MC indentation policy.
[midnight-commander.git] / src / dialog.c
blob313f7929addbc20aa37f99e00f5a43f2285c56e3
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 "lib/global.h"
34 #include "lib/tty/tty.h"
35 #include "lib/skin.h"
36 #include "lib/tty/mouse.h"
37 #include "lib/tty/key.h"
38 #include "lib/strutil.h"
40 #include "help.h" /* interactive_display() */
41 #include "dialog.h"
42 #include "layout.h"
43 #include "execute.h" /* suspend_cmd() */
44 #include "main.h" /* fast_refresh */
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, int reverse, int flags);
63 /* draw box in window */
64 void
65 draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single)
67 tty_draw_box (h->y + y, h->x + x, ys, xs, single);
70 void
71 widget_erase (Widget * w)
73 tty_fill_region (w->y, w->x, w->lines, w->cols, ' ');
76 void
77 dlg_erase (Dlg_head * h)
79 if (h != NULL)
80 tty_fill_region (h->y, h->x, h->lines, h->cols, ' ');
83 void
84 init_widget (Widget * w, int y, int x, int lines, int cols,
85 callback_fn callback, mouse_h mouse_handler)
87 w->x = x;
88 w->y = y;
89 w->cols = cols;
90 w->lines = lines;
91 w->callback = callback;
92 w->mouse = mouse_handler;
93 w->parent = 0;
95 /* Almost all widgets want to put the cursor in a suitable place */
96 w->options = W_WANT_CURSOR;
99 /* Clean the dialog area, draw the frame and the title */
100 void
101 common_dialog_repaint (struct Dlg_head *h)
103 int space;
105 space = (h->flags & DLG_COMPACT) ? 0 : 1;
107 tty_setcolor (DLG_NORMALC (h));
108 dlg_erase (h);
109 draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space, FALSE);
111 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))
149 Widget *c = h->current;
153 /* there are, mainly, 2 generally possible
154 situations:
156 1. control sticks to one side - it
157 should be moved
159 2. control sticks to two sides of
160 one direction - it should be sized */
162 int x = c->x;
163 int y = c->y;
164 int cols = c->cols;
165 int lines = c->lines;
167 if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT))
169 x += shift_x;
170 cols += scale_x;
172 else if (c->pos_flags & WPOS_KEEP_LEFT)
173 x += shift_x;
174 else if (c->pos_flags & WPOS_KEEP_RIGHT)
175 x += shift_x + scale_x;
177 if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM))
179 y += shift_y;
180 lines += scale_y;
182 else if (c->pos_flags & WPOS_KEEP_TOP)
183 y += shift_y;
184 else if (c->pos_flags & WPOS_KEEP_BOTTOM)
185 y += shift_y + scale_y;
187 widget_set_size (c, y, x, lines, cols);
189 c = c->next;
191 while (h->current != c);
195 /* this function sets only size, leaving positioning to automatic methods */
196 void
197 dlg_set_size (Dlg_head * h, int lines, int cols)
199 int x = h->x;
200 int y = h->y;
202 if (h->flags & DLG_CENTER)
204 y = (LINES - lines) / 2;
205 x = (COLS - cols) / 2;
208 if ((h->flags & DLG_TRYUP) && (y > 3))
209 y -= 2;
211 dlg_set_position (h, y, x, y + lines, x + cols);
214 /* Default dialog callback */
215 cb_ret_t
216 default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
218 (void) sender;
219 (void) parm;
220 (void) data;
222 switch (msg)
224 case DLG_DRAW:
225 if (h->color != NULL)
227 common_dialog_repaint (h);
228 return MSG_HANDLED;
230 return MSG_NOT_HANDLED;
232 case DLG_IDLE:
233 dlg_broadcast_msg_to (h, WIDGET_IDLE, 0, W_WANT_IDLE);
234 return MSG_HANDLED;
236 case DLG_RESIZE:
237 /* this is default resizing mechanism */
238 /* the main idea of this code is to resize dialog
239 according to flags (if any of flags require automatic
240 resizing, like DLG_CENTER, end after that reposition
241 controls in dialog according to flags of widget) */
242 dlg_set_size (h, h->lines, h->cols);
243 return MSG_HANDLED;
245 default:
246 break;
249 return MSG_NOT_HANDLED;
252 Dlg_head *
253 create_dlg (int y1, int x1, int lines, int cols, const int *colors,
254 dlg_cb_fn callback, const char *help_ctx, const char *title, int flags)
256 Dlg_head *new_d;
258 new_d = g_new0 (Dlg_head, 1);
259 if (colors != NULL)
261 new_d->color = g_new (int, DLG_COLOR_NUM);
262 memmove (new_d->color, colors, sizeof (int) * DLG_COLOR_NUM);
264 new_d->help_ctx = help_ctx;
265 new_d->callback = (callback != NULL) ? callback : default_dlg_callback;
266 new_d->x = x1;
267 new_d->y = y1;
268 new_d->flags = flags;
269 new_d->data = NULL;
271 dlg_set_size (new_d, lines, cols);
273 /* Strip existing spaces, add one space before and after the title */
274 if (title)
276 char *t;
278 t = g_strstrip (g_strdup (title));
279 if (*t != '\0')
280 new_d->title = g_strdup_printf (" %s ", t);
281 g_free (t);
284 return new_d;
287 void
288 dlg_set_default_colors (void)
290 dialog_colors[0] = COLOR_NORMAL;
291 dialog_colors[1] = COLOR_FOCUS;
292 dialog_colors[2] = COLOR_HOT_NORMAL;
293 dialog_colors[3] = COLOR_HOT_FOCUS;
295 alarm_colors[0] = ERROR_COLOR;
296 alarm_colors[1] = REVERSE_COLOR;
297 alarm_colors[2] = ERROR_HOT_NORMAL;
298 alarm_colors[3] = ERROR_HOT_FOCUS;
301 void
302 set_idle_proc (Dlg_head * d, int enable)
304 if (enable)
305 d->flags |= DLG_WANT_IDLE;
306 else
307 d->flags &= ~DLG_WANT_IDLE;
311 * Insert widget to dialog before current widget. For dialogs populated
312 * from the bottom, make the widget current. Return widget number.
315 add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags)
317 Widget *widget = (Widget *) w;
319 /* Don't accept 0 widgets, and running dialogs */
320 if (!widget || h->running)
321 abort ();
323 widget->x += h->x;
324 widget->y += h->y;
325 widget->parent = h;
326 widget->dlg_id = h->count++;
327 widget->pos_flags = pos_flags;
329 if (h->current)
331 widget->next = h->current;
332 widget->prev = h->current->prev;
333 h->current->prev->next = widget;
334 h->current->prev = widget;
336 else
338 widget->prev = widget;
339 widget->next = widget;
342 if ((h->flags & DLG_REVERSE) || !h->current)
343 h->current = widget;
345 return widget->dlg_id;
348 /* wrapper to simply add lefttop positioned controls */
350 add_widget (Dlg_head * h, void *w)
352 return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP);
355 static void
356 do_complete_refresh (Dlg_head * dlg)
358 if (!dlg->fullscreen && dlg->parent)
359 do_complete_refresh (dlg->parent);
361 dlg_redraw (dlg);
364 void
365 do_refresh (void)
367 if (!current_dlg)
368 return;
370 if (fast_refresh)
371 dlg_redraw (current_dlg);
372 else
373 do_complete_refresh (current_dlg);
376 /* broadcast a message to all the widgets in a dialog that have
377 * the options set to flags. If flags is zero, the message is sent
378 * to all widgets.
380 static void
381 dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t message, int reverse, int flags)
383 Widget *p, *first, *wi;
385 if (!h->current)
386 return;
388 if (reverse)
389 first = p = h->current->prev;
390 else
391 first = p = h->current->next;
395 wi = p;
396 if (reverse)
397 p = p->prev;
398 else
399 p = p->next;
400 if (flags == 0 || (flags & wi->options))
401 send_message (wi, message, 0);
403 while (first != p);
406 /* broadcast a message to all the widgets in a dialog */
407 void
408 dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, int reverse)
410 dlg_broadcast_msg_to (h, message, reverse, 0);
414 dlg_focus (Dlg_head * h)
416 if ((h->current != NULL) && (send_message (h->current, WIDGET_FOCUS, 0) == MSG_HANDLED))
418 h->callback (h, h->current, DLG_FOCUS, 0, NULL);
419 return 1;
421 return 0;
424 static int
425 dlg_unfocus (Dlg_head * h)
427 if ((h->current != NULL) && (send_message (h->current, WIDGET_UNFOCUS, 0) == MSG_HANDLED))
429 h->callback (h, h->current, DLG_UNFOCUS, 0, NULL);
430 return 1;
432 return 0;
436 /* Return true if the windows overlap */
438 dlg_overlap (Widget * a, Widget * b)
440 if ((b->x >= a->x + a->cols)
441 || (a->x >= b->x + b->cols) || (b->y >= a->y + a->lines) || (a->y >= b->y + b->lines))
442 return 0;
443 return 1;
447 /* Find the widget with the given callback in the dialog h */
448 Widget *
449 find_widget_type (const Dlg_head * h, callback_fn callback)
451 Widget *w = NULL;
453 if ((h != NULL) && (h->current != NULL))
455 int i;
456 Widget *item;
458 for (i = 0, item = h->current; i < h->count; i++, item = item->next)
460 if (item->callback == callback)
462 w = item;
463 break;
468 return w;
471 /* Find the widget with the given dialog id in the dialog h and select it */
472 void
473 dlg_select_by_id (const Dlg_head * h, int id)
475 Widget *w, *w_found;
477 if (!h->current)
478 return;
480 w = h->current;
481 w_found = NULL;
485 if (w->dlg_id == id)
487 w_found = w;
488 break;
490 w = w->next;
492 while (w != h->current);
494 if (w_found)
495 dlg_select_widget (w_found);
499 /* What to do if the requested widget doesn't take focus */
500 typedef enum
502 SELECT_NEXT, /* go the the next widget */
503 SELECT_PREV, /* go the the previous widget */
504 SELECT_EXACT /* use current widget */
505 } select_dir_t;
508 * Try to select another widget. If forward is set, follow tab order.
509 * Otherwise go to the previous widget.
511 static void
512 do_select_widget (Dlg_head * h, Widget * w, select_dir_t dir)
514 Widget *w0 = h->current;
516 if (!dlg_unfocus (h))
517 return;
519 h->current = w;
522 if (dlg_focus (h))
523 break;
525 switch (dir)
527 case SELECT_NEXT:
528 h->current = h->current->next;
529 break;
530 case SELECT_PREV:
531 h->current = h->current->prev;
532 break;
533 case SELECT_EXACT:
534 h->current = w0;
535 dlg_focus (h);
536 return;
539 while (h->current != w);
541 if (dlg_overlap (w0, h->current))
543 send_message (h->current, WIDGET_DRAW, 0);
544 send_message (h->current, WIDGET_FOCUS, 0);
550 * Try to select widget in the dialog.
552 void
553 dlg_select_widget (void *w)
555 do_select_widget (((Widget *) w)->parent, w, SELECT_NEXT);
559 /* Try to select previous widget in the tab order */
560 void
561 dlg_one_up (Dlg_head * h)
563 if (h->current)
564 do_select_widget (h, h->current->prev, SELECT_PREV);
568 /* Try to select next widget in the tab order */
569 void
570 dlg_one_down (Dlg_head * h)
572 if (h->current)
573 do_select_widget (h, h->current->next, SELECT_NEXT);
577 void
578 update_cursor (Dlg_head * h)
580 Widget *p = h->current;
582 if (p != NULL)
584 if (p->options & W_WANT_CURSOR)
585 send_message (p, WIDGET_CURSOR, 0);
586 else
587 while ((p = p->next) != h->current)
588 if (p->options & W_WANT_CURSOR)
589 if (send_message (p, WIDGET_CURSOR, 0) == MSG_HANDLED)
590 break;
594 /* Redraw the widgets in reverse order, leaving the current widget
595 * as the last one
597 void
598 dlg_redraw (Dlg_head * h)
600 h->callback (h, NULL, DLG_DRAW, 0, NULL);
601 dlg_broadcast_msg (h, WIDGET_DRAW, 1);
602 update_cursor (h);
605 void
606 dlg_stop (Dlg_head * h)
608 h->running = 0;
611 static void
612 dialog_handle_key (Dlg_head * h, int d_key)
614 if (is_abort_char (d_key))
616 h->ret_value = B_CANCEL;
617 dlg_stop (h);
618 return;
621 switch (d_key)
623 case '\n':
624 case KEY_ENTER:
625 h->ret_value = B_ENTER;
626 dlg_stop (h);
627 break;
629 case KEY_LEFT:
630 case KEY_UP:
631 dlg_one_up (h);
632 break;
634 case KEY_RIGHT:
635 case KEY_DOWN:
636 dlg_one_down (h);
637 break;
639 case KEY_F (1):
640 interactive_display (NULL, h->help_ctx);
641 do_refresh ();
642 break;
644 case XCTRL ('z'):
645 suspend_cmd ();
646 /* Fall through */
648 case XCTRL ('l'):
649 #ifdef HAVE_SLANG
650 tty_touch_screen ();
651 mc_refresh ();
652 #else
653 /* Use this if the refreshes fail */
654 clr_scr ();
655 repaint_screen ();
656 #endif /* HAVE_SLANG */
657 break;
659 default:
660 break;
664 static cb_ret_t
665 dlg_try_hotkey (Dlg_head * h, int d_key)
667 Widget *hot_cur;
668 cb_ret_t handled;
669 int c;
671 if (h->current == NULL)
672 return MSG_NOT_HANDLED;
675 * Explanation: we don't send letter hotkeys to other widgets if
676 * the currently selected widget is an input line
679 if (h->current->options & W_IS_INPUT)
681 /* skip ascii control characters, anything else can valid character in
682 * some encoding */
683 if (d_key >= 32 && d_key < 256)
684 return MSG_NOT_HANDLED;
687 /* If it's an alt key, send the message */
688 c = d_key & ~ALT (0);
689 if (d_key & ALT (0) && g_ascii_isalpha (c))
690 d_key = g_ascii_tolower (c);
692 handled = MSG_NOT_HANDLED;
693 if (h->current->options & W_WANT_HOTKEY)
694 handled = send_message (h->current, WIDGET_HOTKEY, d_key);
696 /* If not used, send hotkey to other widgets */
697 if (handled == MSG_HANDLED)
698 return MSG_HANDLED;
700 hot_cur = h->current->next;
702 /* send it to all widgets */
703 while (h->current != hot_cur && handled == MSG_NOT_HANDLED)
705 if (hot_cur->options & W_WANT_HOTKEY)
706 handled = send_message (hot_cur, WIDGET_HOTKEY, d_key);
708 if (handled == MSG_NOT_HANDLED)
709 hot_cur = hot_cur->next;
712 if (handled == MSG_HANDLED)
713 do_select_widget (h, hot_cur, SELECT_EXACT);
715 return handled;
718 static void
719 dlg_key_event (Dlg_head * h, int d_key)
721 cb_ret_t handled;
723 if (h->current == NULL)
724 return;
726 /* TAB used to cycle */
727 if (!(h->flags & DLG_WANT_TAB))
729 if (d_key == '\t')
731 dlg_one_down (h);
732 return;
734 else if (d_key == KEY_BTAB)
736 dlg_one_up (h);
737 return;
741 /* first can dlg_callback handle the key */
742 handled = h->callback (h, NULL, DLG_KEY, d_key, NULL);
744 /* next try the hotkey */
745 if (handled == MSG_NOT_HANDLED)
746 handled = dlg_try_hotkey (h, d_key);
748 if (handled == MSG_HANDLED)
749 h->callback (h, NULL, DLG_HOTKEY_HANDLED, 0, NULL);
750 else
751 /* not used - then try widget_callback */
752 handled = send_message (h->current, WIDGET_KEY, d_key);
754 /* not used- try to use the unhandled case */
755 if (handled == MSG_NOT_HANDLED)
756 handled = h->callback (h, NULL, DLG_UNHANDLED_KEY, d_key, NULL);
758 if (handled == MSG_NOT_HANDLED)
759 dialog_handle_key (h, d_key);
761 h->callback (h, NULL, DLG_POST_KEY, d_key, NULL);
764 static int
765 dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
767 Widget *item;
768 Widget *starting_widget = h->current;
769 Gpm_Event new_event;
770 int x = event->x;
771 int y = event->y;
773 /* close the dialog by mouse click out of dialog area */
774 if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
775 && !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
777 h->ret_value = B_CANCEL;
778 dlg_stop (h);
779 return MOU_NORMAL;
782 item = starting_widget;
785 Widget *widget;
787 widget = item;
788 item = item->next;
790 if ((x > widget->x) && (x <= widget->x + widget->cols)
791 && (y > widget->y) && (y <= widget->y + widget->lines))
793 new_event = *event;
794 new_event.x -= widget->x;
795 new_event.y -= widget->y;
797 if (widget->mouse != NULL)
798 return widget->mouse (&new_event, widget);
801 while (item != starting_widget);
803 return MOU_NORMAL;
806 /* Run dialog routines */
808 /* Init the process */
809 void
810 init_dlg (Dlg_head * h)
812 /* Initialize dialog manager and widgets */
813 h->callback (h, NULL, DLG_INIT, 0, NULL);
814 dlg_broadcast_msg (h, WIDGET_INIT, 0);
816 if (h->x == 0 && h->y == 0 && h->cols == COLS && h->lines == LINES)
817 h->fullscreen = 1;
819 h->parent = current_dlg;
820 current_dlg = h;
822 /* Initialize the mouse status */
823 h->mouse_status = MOU_NORMAL;
825 /* Select the first widget that takes focus */
826 while (!dlg_focus (h) && h->current)
827 h->current = h->current->next;
829 /* Redraw the screen */
830 dlg_redraw (h);
832 h->ret_value = 0;
833 h->running = 1;
836 /* Shutdown the run_dlg */
837 void
838 dlg_run_done (Dlg_head * h)
840 if (h->current != NULL)
841 h->callback (h, h->current, DLG_END, 0, NULL);
843 current_dlg = h->parent;
846 void
847 dlg_process_event (Dlg_head * h, int key, Gpm_Event * event)
849 if (key == EV_NONE)
851 if (tty_got_interrupt ())
852 key = XCTRL ('g');
853 else
854 return;
857 if (key == EV_MOUSE)
858 h->mouse_status = dlg_mouse_event (h, event);
859 else
860 dlg_key_event (h, key);
863 static void
864 frontend_run_dlg (Dlg_head * h)
866 int d_key;
867 Gpm_Event event;
869 event.x = -1;
870 while (h->running)
872 if (winch_flag)
873 change_screen_size ();
875 if (is_idle ())
877 if (idle_hook)
878 execute_hooks (idle_hook);
880 while ((h->flags & DLG_WANT_IDLE) && is_idle ())
881 h->callback (h, NULL, DLG_IDLE, 0, NULL);
883 /* Allow terminating the dialog from the idle handler */
884 if (!h->running)
885 break;
888 update_cursor (h);
890 /* Clear interrupt flag */
891 tty_got_interrupt ();
892 d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE);
894 dlg_process_event (h, d_key, &event);
896 if (!h->running)
897 h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
901 /* Standard run dialog routine
902 * We have to keep this routine small so that we can duplicate it's
903 * behavior on complex routines like the file routines, this way,
904 * they can call the dlg_process_event without rewriting all the code
907 run_dlg (Dlg_head * h)
909 init_dlg (h);
910 frontend_run_dlg (h);
911 dlg_run_done (h);
912 return h->ret_value;
915 void
916 destroy_dlg (Dlg_head * h)
918 int i;
919 Widget *c;
921 dlg_broadcast_msg (h, WIDGET_DESTROY, 0);
922 c = h->current;
923 for (i = 0; i < h->count; i++)
925 c = c->next;
926 g_free (h->current);
927 h->current = c;
929 g_free (h->color);
930 g_free (h->title);
931 g_free (h);
933 do_refresh ();
936 void
937 widget_set_size (Widget * widget, int y, int x, int lines, int cols)
939 widget->x = x;
940 widget->y = y;
941 widget->cols = cols;
942 widget->lines = lines;
943 send_message (widget, WIDGET_RESIZED, 0 /* unused */ );
946 /* Replace widget old_w for widget new_w in the dialog */
947 void
948 dlg_replace_widget (Widget * old_w, Widget * new_w)
950 Dlg_head *h = old_w->parent;
951 int should_focus = 0;
953 if (!h->current)
954 return;
956 if (old_w == h->current)
957 should_focus = 1;
959 new_w->parent = h;
960 new_w->dlg_id = old_w->dlg_id;
962 if (old_w == old_w->next)
964 /* just one widget */
965 new_w->prev = new_w;
966 new_w->next = new_w;
968 else
970 new_w->prev = old_w->prev;
971 new_w->next = old_w->next;
972 old_w->prev->next = new_w;
973 old_w->next->prev = new_w;
976 if (should_focus)
977 h->current = new_w;
979 send_message (old_w, WIDGET_DESTROY, 0);
980 send_message (new_w, WIDGET_INIT, 0);
982 if (should_focus)
983 dlg_select_widget (new_w);
985 send_message (new_w, WIDGET_DRAW, 0);