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"
39 #include "lib/widget.h"
41 /* TODO: these includes should be removed! */
42 #include "src/help.h" /* interactive_display() */
43 #include "src/filemanager/layout.h"
44 #include "src/execute.h" /* suspend_cmd() */
45 #include "src/keybind-defaults.h"
47 /*** global variables ****************************************************************************/
49 /* Color styles for normal and error dialogs */
50 dlg_colors_t dialog_colors
;
51 dlg_colors_t alarm_colors
;
53 /* Primitive way to check if the the current dialog is our dialog */
54 /* This is needed by async routines like load_prompt */
55 GList
*top_dlg
= NULL
;
57 /* A hook list for idle events */
58 hook_t
*idle_hook
= NULL
;
60 /* If set then dialogs just clean the screen when refreshing, else */
61 /* they do a complete refresh, refreshing all the parts of the program */
64 /* left click outside of dialog closes it */
65 int mouse_close_dialog
= 0;
67 /*** file scope macro definitions ****************************************************************/
69 /*** file scope type declarations ****************************************************************/
71 /** What to do if the requested widget doesn't take focus */
74 SELECT_NEXT
, /* go the the next widget */
75 SELECT_PREV
, /* go the the previous widget */
76 SELECT_EXACT
/* use current widget */
79 /*** file scope variables ************************************************************************/
81 /*** file scope functions ************************************************************************/
83 /* --------------------------------------------------------------------------------------------- */
85 * broadcast a message to all the widgets in a dialog that have
86 * the options set to flags. If flags is zero, the message is sent
91 dlg_broadcast_msg_to (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
, int flags
)
95 if (h
->widgets
== NULL
)
98 if (h
->current
== NULL
)
99 h
->current
= h
->widgets
;
103 p
= g_list_previous (h
->current
);
106 p
= g_list_last (h
->widgets
);
110 p
= g_list_next (h
->current
);
120 Widget
*w
= (Widget
*) p
->data
;
124 p
= g_list_previous (p
);
127 p
= g_list_last (h
->widgets
);
137 if ((flags
== 0) || ((flags
& w
->options
) != 0))
138 send_message (w
, msg
, 0);
143 /* --------------------------------------------------------------------------------------------- */
146 dlg_unfocus (Dlg_head
* h
)
148 /* ... but can unfocus disabled widget */
150 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
152 Widget
*current
= (Widget
*) h
->current
->data
;
154 if (send_message (current
, WIDGET_UNFOCUS
, 0) == MSG_HANDLED
)
156 h
->callback (h
, current
, DLG_UNFOCUS
, 0, NULL
);
164 /* --------------------------------------------------------------------------------------------- */
167 dlg_find_widget_callback (const void *a
, const void *b
)
169 const Widget
*w
= (const Widget
*) a
;
170 callback_fn f
= (callback_fn
) b
;
172 return (w
->callback
== f
) ? 0 : 1;
175 /* --------------------------------------------------------------------------------------------- */
177 * Try to select another widget. If forward is set, follow tab order.
178 * Otherwise go to the previous widget.
182 do_select_widget (Dlg_head
* h
, GList
* w
, select_dir_t dir
)
184 Widget
*w0
= (Widget
*) h
->current
->data
;
186 if (!dlg_unfocus (h
))
199 h
->current
= g_list_next (h
->current
);
200 if (h
->current
== NULL
)
201 h
->current
= h
->widgets
;
204 h
->current
= g_list_previous (h
->current
);
205 if (h
->current
== NULL
)
206 h
->current
= g_list_last (h
->widgets
);
209 h
->current
= g_list_find (h
->widgets
, w0
);
214 while (h
->current
!= w
/* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */ );
216 if (dlg_overlap (w0
, (Widget
*) h
->current
->data
))
218 send_message ((Widget
*) h
->current
->data
, WIDGET_DRAW
, 0);
219 send_message ((Widget
*) h
->current
->data
, WIDGET_FOCUS
, 0);
223 /* --------------------------------------------------------------------------------------------- */
232 /* Use this if the refreshes fail */
235 #endif /* HAVE_SLANG */
238 /* --------------------------------------------------------------------------------------------- */
241 dlg_execute_cmd (Dlg_head
* h
, unsigned long command
)
243 cb_ret_t ret
= MSG_HANDLED
;
247 h
->ret_value
= B_ENTER
;
250 case CK_DialogCancel
:
251 h
->ret_value
= B_CANCEL
;
255 case CK_DialogPrevItem
:
258 case CK_DialogNextItem
:
263 interactive_display (NULL
, h
->help_ctx
);
267 case CK_DialogSuspend
:
271 case CK_DialogRefresh
:
275 case CK_DialogListCmd
:
277 dialog_switch_list ();
279 ret
= MSG_NOT_HANDLED
;
281 case CK_DialogNextCmd
:
283 dialog_switch_next ();
285 ret
= MSG_NOT_HANDLED
;
287 case CK_DialogPrevCmd
:
289 dialog_switch_prev ();
291 ret
= MSG_NOT_HANDLED
;
295 ret
= MSG_NOT_HANDLED
;
301 /* --------------------------------------------------------------------------------------------- */
304 dlg_handle_key (Dlg_head
* h
, int d_key
)
306 unsigned long command
;
307 command
= keybind_lookup_keymap_command (dialog_map
, d_key
);
308 if ((command
== CK_Ignore_Key
) || (dlg_execute_cmd (h
, command
) == MSG_NOT_HANDLED
))
309 return MSG_NOT_HANDLED
;
314 /* --------------------------------------------------------------------------------------------- */
317 dlg_mouse_event (Dlg_head
* h
, Gpm_Event
* event
)
320 GList
*starting_widget
= h
->current
;
325 /* close the dialog by mouse click out of dialog area */
326 if (mouse_close_dialog
&& !h
->fullscreen
&& ((event
->buttons
& GPM_B_LEFT
) != 0) && ((event
->type
& GPM_DOWN
) != 0) /* left click */
327 && !((x
> h
->x
) && (x
<= h
->x
+ h
->cols
) && (y
> h
->y
) && (y
<= h
->y
+ h
->lines
)))
329 h
->ret_value
= B_CANCEL
;
334 item
= starting_widget
;
339 widget
= (Widget
*) item
->data
;
340 item
= g_list_next (item
);
344 if (((widget
->options
& W_DISABLED
) == 0)
345 && (x
> widget
->x
) && (x
<= widget
->x
+ widget
->cols
)
346 && (y
> widget
->y
) && (y
<= widget
->y
+ widget
->lines
))
349 new_event
.x
-= widget
->x
;
350 new_event
.y
-= widget
->y
;
352 if (widget
->mouse
!= NULL
)
353 return widget
->mouse (&new_event
, widget
);
356 while (item
!= starting_widget
);
361 /* --------------------------------------------------------------------------------------------- */
364 dlg_try_hotkey (Dlg_head
* h
, int d_key
)
371 if (h
->widgets
== NULL
)
372 return MSG_NOT_HANDLED
;
374 if (h
->current
== NULL
)
375 h
->current
= h
->widgets
;
378 * Explanation: we don't send letter hotkeys to other widgets if
379 * the currently selected widget is an input line
382 current
= (Widget
*) h
->current
->data
;
384 if ((current
->options
& W_DISABLED
) != 0)
385 return MSG_NOT_HANDLED
;
387 if (current
->options
& W_IS_INPUT
)
389 /* skip ascii control characters, anything else can valid character in
391 if (d_key
>= 32 && d_key
< 256)
392 return MSG_NOT_HANDLED
;
395 /* If it's an alt key, send the message */
396 c
= d_key
& ~ALT (0);
397 if (d_key
& ALT (0) && g_ascii_isalpha (c
))
398 d_key
= g_ascii_tolower (c
);
400 handled
= MSG_NOT_HANDLED
;
401 if ((current
->options
& W_WANT_HOTKEY
) != 0)
402 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
404 /* If not used, send hotkey to other widgets */
405 if (handled
== MSG_HANDLED
)
408 hot_cur
= g_list_next (h
->current
);
410 hot_cur
= h
->widgets
;
412 /* send it to all widgets */
413 while (h
->current
!= hot_cur
&& handled
== MSG_NOT_HANDLED
)
415 current
= (Widget
*) hot_cur
->data
;
417 if ((current
->options
& W_WANT_HOTKEY
) != 0)
418 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
420 if (handled
== MSG_NOT_HANDLED
)
422 hot_cur
= g_list_next (hot_cur
);
424 hot_cur
= h
->widgets
;
428 if (handled
== MSG_HANDLED
)
429 do_select_widget (h
, hot_cur
, SELECT_EXACT
);
434 /* --------------------------------------------------------------------------------------------- */
437 dlg_key_event (Dlg_head
* h
, int d_key
)
441 if (h
->widgets
== NULL
)
444 if (h
->current
== NULL
)
445 h
->current
= h
->widgets
;
447 /* TAB used to cycle */
448 if ((h
->flags
& DLG_WANT_TAB
) == 0)
455 else if (d_key
== KEY_BTAB
)
462 /* first can dlg_callback handle the key */
463 handled
= h
->callback (h
, NULL
, DLG_KEY
, d_key
, NULL
);
465 /* next try the hotkey */
466 if (handled
== MSG_NOT_HANDLED
)
467 handled
= dlg_try_hotkey (h
, d_key
);
469 if (handled
== MSG_HANDLED
)
470 h
->callback (h
, NULL
, DLG_HOTKEY_HANDLED
, 0, NULL
);
472 /* not used - then try widget_callback */
473 handled
= send_message ((Widget
*) h
->current
->data
, WIDGET_KEY
, d_key
);
475 /* not used- try to use the unhandled case */
476 if (handled
== MSG_NOT_HANDLED
)
477 handled
= h
->callback (h
, NULL
, DLG_UNHANDLED_KEY
, d_key
, NULL
);
479 if (handled
== MSG_NOT_HANDLED
)
480 handled
= dlg_handle_key (h
, d_key
);
482 h
->callback (h
, NULL
, DLG_POST_KEY
, d_key
, NULL
);
485 /* --------------------------------------------------------------------------------------------- */
488 frontend_run_dlg (Dlg_head
* h
)
495 /* close opened editors, viewers, etc */
496 if (!h
->modal
&& midnight_shutdown
)
498 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
502 while (h
->state
== DLG_ACTIVE
)
505 change_screen_size ();
510 execute_hooks (idle_hook
);
512 while ((h
->flags
& DLG_WANT_IDLE
) && is_idle ())
513 h
->callback (h
, NULL
, DLG_IDLE
, 0, NULL
);
515 /* Allow terminating the dialog from the idle handler */
516 if (h
->state
!= DLG_ACTIVE
)
522 /* Clear interrupt flag */
523 tty_got_interrupt ();
524 d_key
= tty_get_event (&event
, h
->mouse_status
== MOU_REPEAT
, TRUE
);
526 dlg_process_event (h
, d_key
, &event
);
528 if (h
->state
== DLG_CLOSED
)
529 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
533 /* --------------------------------------------------------------------------------------------- */
534 /*** public functions ****************************************************************************/
535 /* --------------------------------------------------------------------------------------------- */
537 /** draw box in window */
539 draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
)
541 tty_draw_box (h
->y
+ y
, h
->x
+ x
, ys
, xs
, single
);
544 /* --------------------------------------------------------------------------------------------- */
546 /** Clean the dialog area, draw the frame and the title */
548 common_dialog_repaint (Dlg_head
* h
)
552 if (h
->state
!= DLG_ACTIVE
)
555 space
= (h
->flags
& DLG_COMPACT
) ? 0 : 1;
557 tty_setcolor (h
->color
[DLG_COLOR_NORMAL
]);
559 draw_box (h
, space
, space
, h
->lines
- 2 * space
, h
->cols
- 2 * space
, FALSE
);
561 if (h
->title
!= NULL
)
563 tty_setcolor (h
->color
[DLG_COLOR_TITLE
]);
564 dlg_move (h
, space
, (h
->cols
- str_term_width1 (h
->title
)) / 2);
565 tty_print_string (h
->title
);
569 /* --------------------------------------------------------------------------------------------- */
570 /** this function allows to set dialog position */
573 dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
)
575 /* save old positions, will be used to reposition childs */
577 int shift_x
, shift_y
, scale_x
, scale_y
;
579 /* save old positions, will be used to reposition childs */
590 /* dialog is empty */
591 if (h
->widgets
== NULL
)
594 if (h
->current
== NULL
)
595 h
->current
= h
->widgets
;
597 /* values by which controls should be moved */
600 scale_x
= h
->cols
- oc
;
601 scale_y
= h
->lines
- ol
;
603 if ((shift_x
!= 0) || (shift_y
!= 0) || (scale_x
!= 0) || (scale_y
!= 0))
607 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
609 /* there are, mainly, 2 generally possible
612 1. control sticks to one side - it
615 2. control sticks to two sides of
616 one direction - it should be sized */
618 Widget
*c
= (Widget
*) w
->data
;
622 int lines
= c
->lines
;
624 if ((c
->pos_flags
& WPOS_KEEP_LEFT
) && (c
->pos_flags
& WPOS_KEEP_RIGHT
))
629 else if (c
->pos_flags
& WPOS_KEEP_LEFT
)
631 else if (c
->pos_flags
& WPOS_KEEP_RIGHT
)
632 x
+= shift_x
+ scale_x
;
634 if ((c
->pos_flags
& WPOS_KEEP_TOP
) && (c
->pos_flags
& WPOS_KEEP_BOTTOM
))
639 else if (c
->pos_flags
& WPOS_KEEP_TOP
)
641 else if (c
->pos_flags
& WPOS_KEEP_BOTTOM
)
642 y
+= shift_y
+ scale_y
;
644 widget_set_size (c
, y
, x
, lines
, cols
);
649 /* --------------------------------------------------------------------------------------------- */
650 /** this function sets only size, leaving positioning to automatic methods */
653 dlg_set_size (Dlg_head
* h
, int lines
, int cols
)
658 if (h
->flags
& DLG_CENTER
)
660 y
= (LINES
- lines
) / 2;
661 x
= (COLS
- cols
) / 2;
664 if ((h
->flags
& DLG_TRYUP
) && (y
> 3))
667 dlg_set_position (h
, y
, x
, y
+ lines
, x
+ cols
);
670 /* --------------------------------------------------------------------------------------------- */
671 /** Default dialog callback */
674 default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
683 if (h
->color
!= NULL
)
685 common_dialog_repaint (h
);
688 return MSG_NOT_HANDLED
;
691 dlg_broadcast_msg_to (h
, WIDGET_IDLE
, FALSE
, W_WANT_IDLE
);
695 /* this is default resizing mechanism */
696 /* the main idea of this code is to resize dialog
697 according to flags (if any of flags require automatic
698 resizing, like DLG_CENTER, end after that reposition
699 controls in dialog according to flags of widget) */
700 dlg_set_size (h
, h
->lines
, h
->cols
);
707 return MSG_NOT_HANDLED
;
710 /* --------------------------------------------------------------------------------------------- */
713 create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
714 const int *colors
, dlg_cb_fn callback
, const char *help_ctx
,
715 const char *title
, dlg_flags_t flags
)
719 new_d
= g_new0 (Dlg_head
, 1);
720 new_d
->modal
= modal
;
723 memmove (new_d
->color
, colors
, sizeof (dlg_colors_t
));
725 new_d
->help_ctx
= help_ctx
;
726 new_d
->callback
= (callback
!= NULL
) ? callback
: default_dlg_callback
;
729 new_d
->flags
= flags
;
732 dlg_set_size (new_d
, lines
, cols
);
733 new_d
->fullscreen
= (new_d
->x
== 0 && new_d
->y
== 0
734 && new_d
->cols
== COLS
&& new_d
->lines
== LINES
);
736 new_d
->mouse_status
= MOU_NORMAL
;
738 /* Strip existing spaces, add one space before and after the title */
743 t
= g_strstrip (g_strdup (title
));
745 new_d
->title
= g_strdup_printf (" %s ", t
);
752 /* --------------------------------------------------------------------------------------------- */
755 dlg_set_default_colors (void)
757 dialog_colors
[DLG_COLOR_NORMAL
] = COLOR_NORMAL
;
758 dialog_colors
[DLG_COLOR_FOCUS
] = COLOR_FOCUS
;
759 dialog_colors
[DLG_COLOR_HOT_NORMAL
] = COLOR_HOT_NORMAL
;
760 dialog_colors
[DLG_COLOR_HOT_FOCUS
] = COLOR_HOT_FOCUS
;
761 dialog_colors
[DLG_COLOR_TITLE
] = COLOR_TITLE
;
763 alarm_colors
[DLG_COLOR_NORMAL
] = ERROR_COLOR
;
764 alarm_colors
[DLG_COLOR_FOCUS
] = ERROR_FOCUS
;
765 alarm_colors
[DLG_COLOR_HOT_NORMAL
] = ERROR_HOT_NORMAL
;
766 alarm_colors
[DLG_COLOR_HOT_FOCUS
] = ERROR_HOT_FOCUS
;
767 alarm_colors
[DLG_COLOR_TITLE
] = ERROR_TITLE
;
770 /* --------------------------------------------------------------------------------------------- */
773 dlg_erase (Dlg_head
* h
)
775 if ((h
!= NULL
) && (h
->state
== DLG_ACTIVE
))
776 tty_fill_region (h
->y
, h
->x
, h
->lines
, h
->cols
, ' ');
779 /* --------------------------------------------------------------------------------------------- */
782 set_idle_proc (Dlg_head
* d
, int enable
)
785 d
->flags
|= DLG_WANT_IDLE
;
787 d
->flags
&= ~DLG_WANT_IDLE
;
790 /* --------------------------------------------------------------------------------------------- */
792 * Insert widget to dialog before current widget. For dialogs populated
793 * from the bottom, make the widget current. Return widget number.
797 add_widget_autopos (Dlg_head
* h
, void *w
, widget_pos_flags_t pos_flags
)
799 Widget
*widget
= (Widget
*) w
;
801 /* Don't accept 0 widgets */
808 widget
->pos_flags
= pos_flags
;
809 widget
->id
= g_list_length (h
->widgets
);
811 if ((h
->flags
& DLG_REVERSE
) != 0)
812 h
->widgets
= g_list_prepend (h
->widgets
, widget
);
814 h
->widgets
= g_list_append (h
->widgets
, widget
);
816 h
->current
= h
->widgets
;
821 /* --------------------------------------------------------------------------------------------- */
822 /** wrapper to simply add lefttop positioned controls */
825 add_widget (Dlg_head
* h
, void *w
)
827 return add_widget_autopos (h
, w
, WPOS_KEEP_LEFT
| WPOS_KEEP_TOP
);
830 /* --------------------------------------------------------------------------------------------- */
839 if ((d
!= NULL
) && (d
->data
!= NULL
))
840 dlg_redraw ((Dlg_head
*) d
->data
);
844 /* Search first fullscreen dialog */
845 for (; d
!= NULL
; d
= g_list_next (d
))
846 if ((d
->data
!= NULL
) && ((Dlg_head
*) d
->data
)->fullscreen
)
848 /* back to top dialog */
849 for (; d
!= NULL
; d
= g_list_previous (d
))
851 dlg_redraw ((Dlg_head
*) d
->data
);
855 /* --------------------------------------------------------------------------------------------- */
856 /** broadcast a message to all the widgets in a dialog */
859 dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
)
861 dlg_broadcast_msg_to (h
, msg
, reverse
, 0);
864 /* --------------------------------------------------------------------------------------------- */
867 dlg_focus (Dlg_head
* h
)
869 /* cannot focus disabled widget ... */
871 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
873 Widget
*current
= (Widget
*) h
->current
->data
;
875 if (((current
->options
& W_DISABLED
) == 0)
876 && (send_message (current
, WIDGET_FOCUS
, 0) == MSG_HANDLED
))
878 h
->callback (h
, current
, DLG_FOCUS
, 0, NULL
);
886 /* --------------------------------------------------------------------------------------------- */
887 /** Return true if the windows overlap */
890 dlg_overlap (Widget
* a
, Widget
* b
)
892 return !((b
->x
>= a
->x
+ a
->cols
)
893 || (a
->x
>= b
->x
+ b
->cols
) || (b
->y
>= a
->y
+ a
->lines
) || (a
->y
>= b
->y
+ b
->lines
));
897 /* --------------------------------------------------------------------------------------------- */
898 /** Find the widget with the given callback in the dialog h */
901 find_widget_type (const Dlg_head
* h
, callback_fn callback
)
905 w
= g_list_find_custom (h
->widgets
, callback
, dlg_find_widget_callback
);
907 return (w
== NULL
) ? NULL
: (Widget
*) w
->data
;
910 /* --------------------------------------------------------------------------------------------- */
911 /** Find the widget with the given id */
914 dlg_find_by_id (const Dlg_head
* h
, unsigned int id
)
916 if (h
->widgets
!= NULL
)
920 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
921 if (((Widget
*) w
->data
)->id
== id
)
922 return (Widget
*) w
->data
;
928 /* --------------------------------------------------------------------------------------------- */
929 /** Find the widget with the given id in the dialog h and select it */
932 dlg_select_by_id (const Dlg_head
* h
, unsigned int id
)
936 w
= dlg_find_by_id (h
, id
);
938 dlg_select_widget (w
);
941 /* --------------------------------------------------------------------------------------------- */
943 * Try to select widget in the dialog.
947 dlg_select_widget (void *w
)
949 const Widget
*widget
= (Widget
*) w
;
950 Dlg_head
*h
= widget
->owner
;
952 do_select_widget (h
, g_list_find (h
->widgets
, widget
), SELECT_EXACT
);
955 /* --------------------------------------------------------------------------------------------- */
956 /** Try to select previous widget in the tab order */
959 dlg_one_up (Dlg_head
* h
)
961 if (h
->widgets
!= NULL
)
965 prev
= g_list_previous (h
->current
);
967 prev
= g_list_last (h
->widgets
);
969 do_select_widget (h
, prev
, SELECT_PREV
);
973 /* --------------------------------------------------------------------------------------------- */
974 /** Try to select next widget in the tab order */
977 dlg_one_down (Dlg_head
* h
)
979 if (h
->widgets
!= NULL
)
983 next
= g_list_next (h
->current
);
986 do_select_widget (h
, next
, SELECT_NEXT
);
990 /* --------------------------------------------------------------------------------------------- */
993 update_cursor (Dlg_head
* h
)
995 GList
*p
= h
->current
;
997 if ((p
!= NULL
) && (h
->state
== DLG_ACTIVE
))
1001 w
= (Widget
*) p
->data
;
1003 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
1004 send_message (w
, WIDGET_CURSOR
, 0);
1008 p
= g_list_next (p
);
1012 if (p
== h
->current
)
1015 w
= (Widget
*) p
->data
;
1017 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
1018 if (send_message (w
, WIDGET_CURSOR
, 0) == MSG_HANDLED
)
1025 /* --------------------------------------------------------------------------------------------- */
1027 * Redraw the widgets in reverse order, leaving the current widget
1032 dlg_redraw (Dlg_head
* h
)
1034 if (h
->state
!= DLG_ACTIVE
)
1037 if (h
->winch_pending
)
1039 h
->winch_pending
= FALSE
;
1040 h
->callback (h
, NULL
, DLG_RESIZE
, 0, NULL
);
1043 h
->callback (h
, NULL
, DLG_DRAW
, 0, NULL
);
1044 dlg_broadcast_msg (h
, WIDGET_DRAW
, TRUE
);
1048 /* --------------------------------------------------------------------------------------------- */
1051 dlg_stop (Dlg_head
* h
)
1053 h
->state
= DLG_CLOSED
;
1056 /* --------------------------------------------------------------------------------------------- */
1057 /** Init the process */
1060 init_dlg (Dlg_head
* h
)
1062 if ((top_dlg
!= NULL
) && ((Dlg_head
*) top_dlg
->data
)->modal
)
1065 /* add dialog to the stack */
1066 top_dlg
= g_list_prepend (top_dlg
, h
);
1068 /* Initialize dialog manager and widgets */
1069 if (h
->state
== DLG_ACTIVE
)
1072 dialog_switch_add (h
);
1074 h
->callback (h
, NULL
, DLG_INIT
, 0, NULL
);
1075 dlg_broadcast_msg (h
, WIDGET_INIT
, FALSE
);
1078 h
->state
= DLG_ACTIVE
;
1082 /* Select the first widget that takes focus */
1083 while (h
->current
!= NULL
&& !dlg_focus (h
))
1085 h
->current
= g_list_next (h
->current
);
1086 if (h
->current
== NULL
)
1087 h
->current
= h
->widgets
;
1093 /* --------------------------------------------------------------------------------------------- */
1096 dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
)
1100 if (tty_got_interrupt ())
1101 if (h
->callback (h
, NULL
, DLG_ACTION
, CK_DialogCancel
, NULL
) != MSG_HANDLED
)
1102 dlg_execute_cmd (h
, CK_DialogCancel
);
1107 if (key
== EV_MOUSE
)
1108 h
->mouse_status
= dlg_mouse_event (h
, event
);
1110 dlg_key_event (h
, key
);
1113 /* --------------------------------------------------------------------------------------------- */
1114 /** Shutdown the run_dlg */
1117 dlg_run_done (Dlg_head
* h
)
1119 top_dlg
= g_list_remove (top_dlg
, h
);
1121 if (h
->state
== DLG_CLOSED
)
1123 h
->callback (h
, (Widget
*) h
->current
->data
, DLG_END
, 0, NULL
);
1125 dialog_switch_remove (h
);
1130 /* --------------------------------------------------------------------------------------------- */
1132 * Standard run dialog routine
1133 * We have to keep this routine small so that we can duplicate it's
1134 * behavior on complex routines like the file routines, this way,
1135 * they can call the dlg_process_event without rewriting all the code
1139 run_dlg (Dlg_head
* h
)
1142 frontend_run_dlg (h
);
1144 return h
->ret_value
;
1147 /* --------------------------------------------------------------------------------------------- */
1150 destroy_dlg (Dlg_head
* h
)
1152 dlg_broadcast_msg (h
, WIDGET_DESTROY
, FALSE
);
1153 g_list_foreach (h
->widgets
, (GFunc
) g_free
, NULL
);
1154 g_list_free (h
->widgets
);
1161 /* --------------------------------------------------------------------------------------------- */
1164 dlg_get_title (const Dlg_head
* h
, size_t len
)
1171 if (h
->get_title
!= NULL
)
1172 t
= h
->get_title (h
, len
);
1179 /* --------------------------------------------------------------------------------------------- */
1180 /** Replace widget old_w for widget new_w in the dialog */
1183 dlg_replace_widget (Widget
* old_w
, Widget
* new_w
)
1185 Dlg_head
*h
= old_w
->owner
;
1186 gboolean should_focus
= FALSE
;
1188 if (h
->widgets
== NULL
)
1191 if (h
->current
== NULL
)
1192 h
->current
= h
->widgets
;
1194 if (old_w
== h
->current
->data
)
1195 should_focus
= TRUE
;
1198 new_w
->id
= old_w
->id
;
1201 h
->current
->data
= new_w
;
1203 g_list_find (h
->widgets
, old_w
)->data
= new_w
;
1205 send_message (old_w
, WIDGET_DESTROY
, 0);
1206 send_message (new_w
, WIDGET_INIT
, 0);
1209 dlg_select_widget (new_w
);
1211 send_message (new_w
, WIDGET_DRAW
, 0);
1214 /* --------------------------------------------------------------------------------------------- */