1 /* Dialog box features module for the Midnight Commander
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2007, 2009, 2010 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.
21 * \brief Source: dialog box features module
32 #include "lib/global.h"
34 #include "lib/tty/tty.h"
36 #include "lib/tty/mouse.h"
37 #include "lib/tty/key.h"
38 #include "lib/strutil.h"
40 #include "help.h" /* interactive_display() */
42 #include "execute.h" /* suspend_cmd() */
45 #include "main.h" /* fast_refresh */
46 #include "setup.h" /* mouse_close_dialog */
49 #include "dialog-switch.h"
51 /* Color styles for normal and error dialogs */
55 /* Primitive way to check if the the current dialog is our dialog */
56 /* This is needed by async routines like load_prompt */
57 GList
*top_dlg
= NULL
;
59 /* A hook list for idle events */
60 Hook
*idle_hook
= NULL
;
62 /* left click outside of dialog closes it */
63 int mouse_close_dialog
= 0;
65 static void dlg_broadcast_msg_to (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
, int flags
);
67 /* draw box in window */
69 draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
)
71 tty_draw_box (h
->y
+ y
, h
->x
+ x
, ys
, xs
, single
);
75 init_widget (Widget
* w
, int y
, int x
, int lines
, int cols
,
76 callback_fn callback
, mouse_h mouse_handler
)
82 w
->callback
= callback
;
83 w
->mouse
= mouse_handler
;
86 /* Almost all widgets want to put the cursor in a suitable place */
87 w
->options
= W_WANT_CURSOR
;
91 widget_set_size (Widget
* widget
, int y
, int x
, int lines
, int cols
)
96 widget
->lines
= lines
;
97 send_message (widget
, WIDGET_RESIZED
, 0 /* unused */ );
101 widget_erase (Widget
* w
)
104 tty_fill_region (w
->y
, w
->x
, w
->lines
, w
->cols
, ' ');
107 /* Clean the dialog area, draw the frame and the title */
109 common_dialog_repaint (Dlg_head
*h
)
113 if (h
->state
!= DLG_ACTIVE
)
116 space
= (h
->flags
& DLG_COMPACT
) ? 0 : 1;
118 tty_setcolor (DLG_NORMALC (h
));
120 draw_box (h
, space
, space
, h
->lines
- 2 * space
, h
->cols
- 2 * space
, FALSE
);
122 if (h
->title
!= NULL
)
124 tty_setcolor (DLG_HOT_NORMALC (h
));
125 dlg_move (h
, space
, (h
->cols
- str_term_width1 (h
->title
)) / 2);
126 tty_print_string (h
->title
);
130 /* this function allows to set dialog position */
132 dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
)
134 /* save old positions, will be used to reposition childs */
136 int shift_x
, shift_y
, scale_x
, scale_y
;
138 /* save old positions, will be used to reposition childs */
149 /* dialog is empty */
150 if (h
->widgets
== NULL
)
153 if (h
->current
== NULL
)
154 h
->current
= h
->widgets
;
156 /* values by which controls should be moved */
159 scale_x
= h
->cols
- oc
;
160 scale_y
= h
->lines
- ol
;
162 if ((shift_x
!= 0) || (shift_y
!= 0) || (scale_x
!= 0) || (scale_y
!= 0))
166 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
168 /* there are, mainly, 2 generally possible
171 1. control sticks to one side - it
174 2. control sticks to two sides of
175 one direction - it should be sized */
177 Widget
*c
= (Widget
*) w
->data
;
181 int lines
= c
->lines
;
183 if ((c
->pos_flags
& WPOS_KEEP_LEFT
) && (c
->pos_flags
& WPOS_KEEP_RIGHT
))
188 else if (c
->pos_flags
& WPOS_KEEP_LEFT
)
190 else if (c
->pos_flags
& WPOS_KEEP_RIGHT
)
191 x
+= shift_x
+ scale_x
;
193 if ((c
->pos_flags
& WPOS_KEEP_TOP
) && (c
->pos_flags
& WPOS_KEEP_BOTTOM
))
198 else if (c
->pos_flags
& WPOS_KEEP_TOP
)
200 else if (c
->pos_flags
& WPOS_KEEP_BOTTOM
)
201 y
+= shift_y
+ scale_y
;
203 widget_set_size (c
, y
, x
, lines
, cols
);
208 /* this function sets only size, leaving positioning to automatic methods */
210 dlg_set_size (Dlg_head
* h
, int lines
, int cols
)
215 if (h
->flags
& DLG_CENTER
)
217 y
= (LINES
- lines
) / 2;
218 x
= (COLS
- cols
) / 2;
221 if ((h
->flags
& DLG_TRYUP
) && (y
> 3))
224 dlg_set_position (h
, y
, x
, y
+ lines
, x
+ cols
);
227 /* Default dialog callback */
229 default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
238 if (h
->color
!= NULL
)
240 common_dialog_repaint (h
);
243 return MSG_NOT_HANDLED
;
246 dlg_broadcast_msg_to (h
, WIDGET_IDLE
, FALSE
, W_WANT_IDLE
);
250 /* this is default resizing mechanism */
251 /* the main idea of this code is to resize dialog
252 according to flags (if any of flags require automatic
253 resizing, like DLG_CENTER, end after that reposition
254 controls in dialog according to flags of widget) */
255 dlg_set_size (h
, h
->lines
, h
->cols
);
262 return MSG_NOT_HANDLED
;
266 create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
267 const int *colors
, dlg_cb_fn callback
, const char *help_ctx
,
268 const char *title
, dlg_flags_t flags
)
272 new_d
= g_new0 (Dlg_head
, 1);
273 new_d
->modal
= modal
;
276 new_d
->color
= g_new (int, DLG_COLOR_NUM
);
277 memmove (new_d
->color
, colors
, sizeof (int) * DLG_COLOR_NUM
);
279 new_d
->help_ctx
= help_ctx
;
280 new_d
->callback
= (callback
!= NULL
) ? callback
: default_dlg_callback
;
283 new_d
->flags
= flags
;
286 dlg_set_size (new_d
, lines
, cols
);
287 new_d
->fullscreen
= (new_d
->x
== 0 && new_d
->y
== 0
288 && new_d
->cols
== COLS
&& new_d
->lines
== LINES
);
290 new_d
->mouse_status
= MOU_NORMAL
;
292 /* Strip existing spaces, add one space before and after the title */
297 t
= g_strstrip (g_strdup (title
));
299 new_d
->title
= g_strdup_printf (" %s ", t
);
307 dlg_set_default_colors (void)
309 dialog_colors
[0] = COLOR_NORMAL
;
310 dialog_colors
[1] = COLOR_FOCUS
;
311 dialog_colors
[2] = COLOR_HOT_NORMAL
;
312 dialog_colors
[3] = COLOR_HOT_FOCUS
;
314 alarm_colors
[0] = ERROR_COLOR
;
315 alarm_colors
[1] = REVERSE_COLOR
;
316 alarm_colors
[2] = ERROR_HOT_NORMAL
;
317 alarm_colors
[3] = ERROR_HOT_FOCUS
;
321 dlg_erase (Dlg_head
* h
)
323 if ((h
!= NULL
) && (h
->state
== DLG_ACTIVE
))
324 tty_fill_region (h
->y
, h
->x
, h
->lines
, h
->cols
, ' ');
328 set_idle_proc (Dlg_head
* d
, int enable
)
331 d
->flags
|= DLG_WANT_IDLE
;
333 d
->flags
&= ~DLG_WANT_IDLE
;
337 * Insert widget to dialog before current widget. For dialogs populated
338 * from the bottom, make the widget current. Return widget number.
341 add_widget_autopos (Dlg_head
* h
, void *w
, widget_pos_flags_t pos_flags
)
343 Widget
*widget
= (Widget
*) w
;
345 /* Don't accept 0 widgets */
352 widget
->pos_flags
= pos_flags
;
353 widget
->id
= g_list_length (h
->widgets
);
355 if ((h
->flags
& DLG_REVERSE
) != 0)
356 h
->widgets
= g_list_prepend (h
->widgets
, widget
);
358 h
->widgets
= g_list_append (h
->widgets
, widget
);
360 h
->current
= h
->widgets
;
365 /* wrapper to simply add lefttop positioned controls */
367 add_widget (Dlg_head
* h
, void *w
)
369 return add_widget_autopos (h
, w
, WPOS_KEEP_LEFT
| WPOS_KEEP_TOP
);
379 if ((d
!= NULL
) && (d
->data
!= NULL
))
380 dlg_redraw ((Dlg_head
*) d
->data
);
384 /* Search first fullscreen dialog */
385 for (; d
!= NULL
; d
= g_list_next (d
))
386 if ((d
->data
!= NULL
) && ((Dlg_head
*) d
->data
)->fullscreen
)
388 /* back to top dialog */
389 for (; d
!= NULL
; d
= g_list_previous (d
))
391 dlg_redraw ((Dlg_head
*) d
->data
);
395 /* broadcast a message to all the widgets in a dialog that have
396 * the options set to flags. If flags is zero, the message is sent
400 dlg_broadcast_msg_to (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
, int flags
)
404 if (h
->widgets
== NULL
)
407 if (h
->current
== NULL
)
408 h
->current
= h
->widgets
;
412 p
= g_list_previous (h
->current
);
415 p
= g_list_last (h
->widgets
);
419 p
= g_list_next (h
->current
);
429 Widget
*w
= (Widget
*) p
->data
;
433 p
= g_list_previous (p
);
436 p
= g_list_last (h
->widgets
);
446 if ((flags
== 0) || ((flags
& w
->options
) != 0))
447 send_message (w
, message
, 0);
452 /* broadcast a message to all the widgets in a dialog */
454 dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t message
, gboolean reverse
)
456 dlg_broadcast_msg_to (h
, message
, reverse
, 0);
460 dlg_focus (Dlg_head
* h
)
462 /* cannot focus disabled widget ... */
464 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
466 Widget
*current
= (Widget
*) h
->current
->data
;
468 if (((current
->options
& W_DISABLED
) == 0)
469 && (send_message (current
, WIDGET_FOCUS
, 0) == MSG_HANDLED
))
471 h
->callback (h
, current
, DLG_FOCUS
, 0, NULL
);
480 dlg_unfocus (Dlg_head
* h
)
482 /* ... but can unfocus disabled widget */
484 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
486 Widget
*current
= (Widget
*) h
->current
->data
;
488 if (send_message (current
, WIDGET_UNFOCUS
, 0) == MSG_HANDLED
)
490 h
->callback (h
, current
, DLG_UNFOCUS
, 0, NULL
);
498 /* Return true if the windows overlap */
500 dlg_overlap (Widget
* a
, Widget
* b
)
502 return !((b
->x
>= a
->x
+ a
->cols
)
503 || (a
->x
>= b
->x
+ b
->cols
) || (b
->y
>= a
->y
+ a
->lines
) || (a
->y
>= b
->y
+ b
->lines
));
507 dlg_find_widget_callback (const void *a
, const void *b
)
509 const Widget
*w
= (const Widget
*) a
;
510 callback_fn f
= (callback_fn
) b
;
512 return (w
->callback
== f
) ? 0 : 1;
515 /* Find the widget with the given callback in the dialog h */
517 find_widget_type (const Dlg_head
* h
, callback_fn callback
)
521 w
= g_list_find_custom (h
->widgets
, callback
, dlg_find_widget_callback
);
523 return (w
== NULL
) ? NULL
: (Widget
*) w
->data
;
526 /* Find the widget with the given id */
528 dlg_find_by_id (const Dlg_head
* h
, unsigned int id
)
530 if (h
->widgets
!= NULL
)
534 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
535 if (((Widget
*) w
->data
)->id
== id
)
536 return (Widget
*) w
->data
;
542 /* Find the widget with the given id in the dialog h and select it */
544 dlg_select_by_id (const Dlg_head
* h
, unsigned int id
)
548 w
= dlg_find_by_id (h
, id
);
550 dlg_select_widget (w
);
553 /* What to do if the requested widget doesn't take focus */
556 SELECT_NEXT
, /* go the the next widget */
557 SELECT_PREV
, /* go the the previous widget */
558 SELECT_EXACT
/* use current widget */
562 * Try to select another widget. If forward is set, follow tab order.
563 * Otherwise go to the previous widget.
566 do_select_widget (Dlg_head
* h
, GList
* w
, select_dir_t dir
)
568 Widget
*w0
= (Widget
*) h
->current
->data
;
570 if (!dlg_unfocus (h
))
583 h
->current
= g_list_next (h
->current
);
584 if (h
->current
== NULL
)
585 h
->current
= h
->widgets
;
588 h
->current
= g_list_previous (h
->current
);
589 if (h
->current
== NULL
)
590 h
->current
= g_list_last (h
->widgets
);
593 h
->current
= g_list_find (h
->widgets
, w0
);
598 while (h
->current
!= w
/* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */);
600 if (dlg_overlap (w0
, (Widget
*) h
->current
->data
))
602 send_message ((Widget
*) h
->current
->data
, WIDGET_DRAW
, 0);
603 send_message ((Widget
*) h
->current
->data
, WIDGET_FOCUS
, 0);
608 * Try to select widget in the dialog.
611 dlg_select_widget (void *w
)
613 const Widget
*widget
= (Widget
*) w
;
614 Dlg_head
*h
= widget
->owner
;
616 do_select_widget (h
, g_list_find (h
->widgets
, widget
), SELECT_NEXT
);
619 /* Try to select previous widget in the tab order */
621 dlg_one_up (Dlg_head
* h
)
623 if (h
->widgets
!= NULL
)
627 prev
= g_list_previous (h
->current
);
629 prev
= g_list_last (h
->widgets
);
631 do_select_widget (h
, prev
, SELECT_PREV
);
635 /* Try to select next widget in the tab order */
637 dlg_one_down (Dlg_head
* h
)
639 if (h
->widgets
!= NULL
)
643 next
= g_list_next (h
->current
);
646 do_select_widget (h
, next
, SELECT_NEXT
);
651 update_cursor (Dlg_head
* h
)
653 GList
*p
= h
->current
;
655 if ((p
!= NULL
) && (h
->state
== DLG_ACTIVE
))
659 w
= (Widget
*) p
->data
;
661 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
662 send_message (w
, WIDGET_CURSOR
, 0);
673 w
= (Widget
*) p
->data
;
675 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
676 if (send_message (w
, WIDGET_CURSOR
, 0) == MSG_HANDLED
)
683 /* Redraw the widgets in reverse order, leaving the current widget
687 dlg_redraw (Dlg_head
* h
)
689 if (h
->state
!= DLG_ACTIVE
)
692 if (h
->winch_pending
)
694 h
->winch_pending
= FALSE
;
695 h
->callback (h
, NULL
, DLG_RESIZE
, 0, NULL
);
698 h
->callback (h
, NULL
, DLG_DRAW
, 0, NULL
);
699 dlg_broadcast_msg (h
, WIDGET_DRAW
, TRUE
);
704 dlg_stop (Dlg_head
* h
)
706 h
->state
= DLG_CLOSED
;
716 /* Use this if the refreshes fail */
719 #endif /* HAVE_SLANG */
723 dlg_execute_cmd (Dlg_head
* h
, unsigned long command
)
725 cb_ret_t ret
= MSG_HANDLED
;
729 h
->ret_value
= B_ENTER
;
732 case CK_DialogCancel
:
733 h
->ret_value
= B_CANCEL
;
737 case CK_DialogPrevItem
:
740 case CK_DialogNextItem
:
745 interactive_display (NULL
, h
->help_ctx
);
749 case CK_DialogSuspend
:
753 case CK_DialogRefresh
:
757 case CK_DialogListCmd
:
759 dialog_switch_list ();
761 ret
= MSG_NOT_HANDLED
;
763 case CK_DialogNextCmd
:
765 dialog_switch_next ();
767 ret
= MSG_NOT_HANDLED
;
769 case CK_DialogPrevCmd
:
771 dialog_switch_prev ();
773 ret
= MSG_NOT_HANDLED
;
777 ret
= MSG_NOT_HANDLED
;
784 dlg_handle_key (Dlg_head
* h
, int d_key
)
786 unsigned long command
;
787 command
= lookup_keymap_command (dialog_map
, d_key
);
788 if ((command
== CK_Ignore_Key
) || (dlg_execute_cmd (h
, command
) == MSG_NOT_HANDLED
))
789 return MSG_NOT_HANDLED
;
795 dlg_mouse_event (Dlg_head
* h
, Gpm_Event
* event
)
798 GList
*starting_widget
= h
->current
;
803 /* close the dialog by mouse click out of dialog area */
804 if (mouse_close_dialog
&& !h
->fullscreen
&& ((event
->buttons
& GPM_B_LEFT
) != 0) && ((event
->type
& GPM_DOWN
) != 0) /* left click */
805 && !((x
> h
->x
) && (x
<= h
->x
+ h
->cols
) && (y
> h
->y
) && (y
<= h
->y
+ h
->lines
)))
807 h
->ret_value
= B_CANCEL
;
812 item
= starting_widget
;
817 widget
= (Widget
*) item
->data
;
818 item
= g_list_next (item
);
822 if (((widget
->options
& W_DISABLED
) == 0)
823 && (x
> widget
->x
) && (x
<= widget
->x
+ widget
->cols
)
824 && (y
> widget
->y
) && (y
<= widget
->y
+ widget
->lines
))
827 new_event
.x
-= widget
->x
;
828 new_event
.y
-= widget
->y
;
830 if (widget
->mouse
!= NULL
)
831 return widget
->mouse (&new_event
, widget
);
834 while (item
!= starting_widget
);
840 dlg_try_hotkey (Dlg_head
* h
, int d_key
)
847 if (h
->widgets
== NULL
)
848 return MSG_NOT_HANDLED
;
850 if (h
->current
== NULL
)
851 h
->current
= h
->widgets
;
854 * Explanation: we don't send letter hotkeys to other widgets if
855 * the currently selected widget is an input line
858 current
= (Widget
*) h
->current
->data
;
860 if ((current
->options
& W_DISABLED
) != 0)
861 return MSG_NOT_HANDLED
;
863 if (current
->options
& W_IS_INPUT
)
865 /* skip ascii control characters, anything else can valid character in
867 if (d_key
>= 32 && d_key
< 256)
868 return MSG_NOT_HANDLED
;
871 /* If it's an alt key, send the message */
872 c
= d_key
& ~ALT (0);
873 if (d_key
& ALT (0) && g_ascii_isalpha (c
))
874 d_key
= g_ascii_tolower (c
);
876 handled
= MSG_NOT_HANDLED
;
877 if ((current
->options
& W_WANT_HOTKEY
) != 0)
878 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
880 /* If not used, send hotkey to other widgets */
881 if (handled
== MSG_HANDLED
)
884 hot_cur
= g_list_next (h
->current
);
886 hot_cur
= h
->widgets
;
888 /* send it to all widgets */
889 while (h
->current
!= hot_cur
&& handled
== MSG_NOT_HANDLED
)
891 current
= (Widget
*) hot_cur
->data
;
893 if ((current
->options
& W_WANT_HOTKEY
) != 0)
894 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
896 if (handled
== MSG_NOT_HANDLED
)
898 hot_cur
= g_list_next (hot_cur
);
900 hot_cur
= h
->widgets
;
904 if (handled
== MSG_HANDLED
)
905 do_select_widget (h
, hot_cur
, SELECT_EXACT
);
911 dlg_key_event (Dlg_head
* h
, int d_key
)
915 if (h
->widgets
== NULL
)
918 if (h
->current
== NULL
)
919 h
->current
= h
->widgets
;
921 /* TAB used to cycle */
922 if ((h
->flags
& DLG_WANT_TAB
) == 0)
929 else if (d_key
== KEY_BTAB
)
936 /* first can dlg_callback handle the key */
937 handled
= h
->callback (h
, NULL
, DLG_KEY
, d_key
, NULL
);
939 /* next try the hotkey */
940 if (handled
== MSG_NOT_HANDLED
)
941 handled
= dlg_try_hotkey (h
, d_key
);
943 if (handled
== MSG_HANDLED
)
944 h
->callback (h
, NULL
, DLG_HOTKEY_HANDLED
, 0, NULL
);
946 /* not used - then try widget_callback */
947 handled
= send_message ((Widget
*) h
->current
->data
, WIDGET_KEY
, d_key
);
949 /* not used- try to use the unhandled case */
950 if (handled
== MSG_NOT_HANDLED
)
951 handled
= h
->callback (h
, NULL
, DLG_UNHANDLED_KEY
, d_key
, NULL
);
953 if (handled
== MSG_NOT_HANDLED
)
954 handled
= dlg_handle_key (h
, d_key
);
956 h
->callback (h
, NULL
, DLG_POST_KEY
, d_key
, NULL
);
959 /* Init the process */
961 init_dlg (Dlg_head
* h
)
963 if ((top_dlg
!= NULL
) && ((Dlg_head
*) top_dlg
->data
)->modal
)
967 /* add dialog to the stack */
968 top_dlg
= g_list_prepend (top_dlg
, h
);
970 /* Initialize dialog manager and widgets */
971 if (h
->state
== DLG_ACTIVE
)
974 dialog_switch_add (h
);
976 h
->callback (h
, NULL
, DLG_INIT
, 0, NULL
);
977 dlg_broadcast_msg (h
, WIDGET_INIT
, FALSE
);
980 h
->state
= DLG_ACTIVE
;
984 /* Select the first widget that takes focus */
985 while (h
->current
!= NULL
&& !dlg_focus (h
))
987 h
->current
= g_list_next (h
->current
);
988 if (h
->current
== NULL
)
989 h
->current
= h
->widgets
;
996 dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
)
1000 if (tty_got_interrupt ())
1001 dlg_execute_cmd (h
, CK_DialogCancel
);
1006 if (key
== EV_MOUSE
)
1007 h
->mouse_status
= dlg_mouse_event (h
, event
);
1009 dlg_key_event (h
, key
);
1013 frontend_run_dlg (Dlg_head
* h
)
1020 /* close opened editors, viewers, etc */
1021 if (!h
->modal
&& midnight_shutdown
)
1023 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
1027 while (h
->state
== DLG_ACTIVE
)
1030 change_screen_size ();
1035 execute_hooks (idle_hook
);
1037 while ((h
->flags
& DLG_WANT_IDLE
) && is_idle ())
1038 h
->callback (h
, NULL
, DLG_IDLE
, 0, NULL
);
1040 /* Allow terminating the dialog from the idle handler */
1041 if (h
->state
!= DLG_ACTIVE
)
1047 /* Clear interrupt flag */
1048 tty_got_interrupt ();
1049 d_key
= tty_get_event (&event
, h
->mouse_status
== MOU_REPEAT
, TRUE
);
1051 dlg_process_event (h
, d_key
, &event
);
1053 if (h
->state
== DLG_CLOSED
)
1054 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
1058 /* Shutdown the run_dlg */
1060 dlg_run_done (Dlg_head
* h
)
1062 if (h
->state
== DLG_CLOSED
)
1064 h
->callback (h
, (Widget
*) h
->current
->data
, DLG_END
, 0, NULL
);
1066 dialog_switch_remove (h
);
1069 top_dlg
= g_list_remove (top_dlg
, h
);
1072 /* Standard run dialog routine
1073 * We have to keep this routine small so that we can duplicate it's
1074 * behavior on complex routines like the file routines, this way,
1075 * they can call the dlg_process_event without rewriting all the code
1078 run_dlg (Dlg_head
* h
)
1081 frontend_run_dlg (h
);
1083 return h
->ret_value
;
1087 destroy_dlg (Dlg_head
* h
)
1089 dlg_broadcast_msg (h
, WIDGET_DESTROY
, FALSE
);
1090 g_list_foreach (h
->widgets
, (GFunc
) g_free
, NULL
);
1091 g_list_free (h
->widgets
);
1100 dlg_get_title (const Dlg_head
*h
, size_t len
)
1107 if (h
->get_title
!= NULL
)
1108 t
= h
->get_title (h
, len
);
1115 /* Replace widget old_w for widget new_w in the dialog */
1117 dlg_replace_widget (Widget
* old_w
, Widget
* new_w
)
1119 Dlg_head
*h
= old_w
->owner
;
1120 gboolean should_focus
= FALSE
;
1122 if (h
->widgets
== NULL
)
1125 if (h
->current
== NULL
)
1126 h
->current
= h
->widgets
;
1128 if (old_w
== h
->current
->data
)
1129 should_focus
= TRUE
;
1132 new_w
->id
= old_w
->id
;
1135 h
->current
->data
= new_w
;
1137 g_list_find (h
->widgets
, old_w
)->data
= new_w
;
1139 send_message (old_w
, WIDGET_DESTROY
, 0);
1140 send_message (new_w
, WIDGET_INIT
, 0);
1143 dlg_select_widget (new_w
);
1145 send_message (new_w
, WIDGET_DRAW
, 0);