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 ************************************************************************/
82 /* --------------------------------------------------------------------------------------------- */
84 static void dlg_broadcast_msg_to (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
, int flags
);
86 /* --------------------------------------------------------------------------------------------- */
88 * broadcast a message to all the widgets in a dialog that have
89 * the options set to flags. If flags is zero, the message is sent
94 dlg_broadcast_msg_to (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
, int flags
)
98 if (h
->widgets
== NULL
)
101 if (h
->current
== NULL
)
102 h
->current
= h
->widgets
;
106 p
= g_list_previous (h
->current
);
109 p
= g_list_last (h
->widgets
);
113 p
= g_list_next (h
->current
);
123 Widget
*w
= (Widget
*) p
->data
;
127 p
= g_list_previous (p
);
130 p
= g_list_last (h
->widgets
);
140 if ((flags
== 0) || ((flags
& w
->options
) != 0))
141 send_message (w
, msg
, 0);
146 /* --------------------------------------------------------------------------------------------- */
149 dlg_unfocus (Dlg_head
* h
)
151 /* ... but can unfocus disabled widget */
153 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
155 Widget
*current
= (Widget
*) h
->current
->data
;
157 if (send_message (current
, WIDGET_UNFOCUS
, 0) == MSG_HANDLED
)
159 h
->callback (h
, current
, DLG_UNFOCUS
, 0, NULL
);
167 /* --------------------------------------------------------------------------------------------- */
170 dlg_find_widget_callback (const void *a
, const void *b
)
172 const Widget
*w
= (const Widget
*) a
;
173 callback_fn f
= (callback_fn
) b
;
175 return (w
->callback
== f
) ? 0 : 1;
178 /* --------------------------------------------------------------------------------------------- */
180 * Try to select another widget. If forward is set, follow tab order.
181 * Otherwise go to the previous widget.
185 do_select_widget (Dlg_head
* h
, GList
* w
, select_dir_t dir
)
187 Widget
*w0
= (Widget
*) h
->current
->data
;
189 if (!dlg_unfocus (h
))
202 h
->current
= g_list_next (h
->current
);
203 if (h
->current
== NULL
)
204 h
->current
= h
->widgets
;
207 h
->current
= g_list_previous (h
->current
);
208 if (h
->current
== NULL
)
209 h
->current
= g_list_last (h
->widgets
);
212 h
->current
= g_list_find (h
->widgets
, w0
);
217 while (h
->current
!= w
/* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */ );
219 if (dlg_overlap (w0
, (Widget
*) h
->current
->data
))
221 send_message ((Widget
*) h
->current
->data
, WIDGET_DRAW
, 0);
222 send_message ((Widget
*) h
->current
->data
, WIDGET_FOCUS
, 0);
226 /* --------------------------------------------------------------------------------------------- */
235 /* Use this if the refreshes fail */
238 #endif /* HAVE_SLANG */
241 /* --------------------------------------------------------------------------------------------- */
244 dlg_execute_cmd (Dlg_head
* h
, unsigned long command
)
246 cb_ret_t ret
= MSG_HANDLED
;
250 h
->ret_value
= B_ENTER
;
253 case CK_DialogCancel
:
254 h
->ret_value
= B_CANCEL
;
258 case CK_DialogPrevItem
:
261 case CK_DialogNextItem
:
266 interactive_display (NULL
, h
->help_ctx
);
270 case CK_DialogSuspend
:
274 case CK_DialogRefresh
:
278 case CK_DialogListCmd
:
280 dialog_switch_list ();
282 ret
= MSG_NOT_HANDLED
;
284 case CK_DialogNextCmd
:
286 dialog_switch_next ();
288 ret
= MSG_NOT_HANDLED
;
290 case CK_DialogPrevCmd
:
292 dialog_switch_prev ();
294 ret
= MSG_NOT_HANDLED
;
298 ret
= MSG_NOT_HANDLED
;
304 /* --------------------------------------------------------------------------------------------- */
307 dlg_handle_key (Dlg_head
* h
, int d_key
)
309 unsigned long command
;
310 command
= keybind_lookup_keymap_command (dialog_map
, d_key
);
311 if ((command
== CK_Ignore_Key
) || (dlg_execute_cmd (h
, command
) == MSG_NOT_HANDLED
))
312 return MSG_NOT_HANDLED
;
317 /* --------------------------------------------------------------------------------------------- */
320 dlg_mouse_event (Dlg_head
* h
, Gpm_Event
* event
)
323 GList
*starting_widget
= h
->current
;
328 /* close the dialog by mouse click out of dialog area */
329 if (mouse_close_dialog
&& !h
->fullscreen
&& ((event
->buttons
& GPM_B_LEFT
) != 0) && ((event
->type
& GPM_DOWN
) != 0) /* left click */
330 && !((x
> h
->x
) && (x
<= h
->x
+ h
->cols
) && (y
> h
->y
) && (y
<= h
->y
+ h
->lines
)))
332 h
->ret_value
= B_CANCEL
;
337 item
= starting_widget
;
342 widget
= (Widget
*) item
->data
;
343 item
= g_list_next (item
);
347 if (((widget
->options
& W_DISABLED
) == 0)
348 && (x
> widget
->x
) && (x
<= widget
->x
+ widget
->cols
)
349 && (y
> widget
->y
) && (y
<= widget
->y
+ widget
->lines
))
352 new_event
.x
-= widget
->x
;
353 new_event
.y
-= widget
->y
;
355 if (widget
->mouse
!= NULL
)
356 return widget
->mouse (&new_event
, widget
);
359 while (item
!= starting_widget
);
364 /* --------------------------------------------------------------------------------------------- */
367 dlg_try_hotkey (Dlg_head
* h
, int d_key
)
374 if (h
->widgets
== NULL
)
375 return MSG_NOT_HANDLED
;
377 if (h
->current
== NULL
)
378 h
->current
= h
->widgets
;
381 * Explanation: we don't send letter hotkeys to other widgets if
382 * the currently selected widget is an input line
385 current
= (Widget
*) h
->current
->data
;
387 if ((current
->options
& W_DISABLED
) != 0)
388 return MSG_NOT_HANDLED
;
390 if (current
->options
& W_IS_INPUT
)
392 /* skip ascii control characters, anything else can valid character in
394 if (d_key
>= 32 && d_key
< 256)
395 return MSG_NOT_HANDLED
;
398 /* If it's an alt key, send the message */
399 c
= d_key
& ~ALT (0);
400 if (d_key
& ALT (0) && g_ascii_isalpha (c
))
401 d_key
= g_ascii_tolower (c
);
403 handled
= MSG_NOT_HANDLED
;
404 if ((current
->options
& W_WANT_HOTKEY
) != 0)
405 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
407 /* If not used, send hotkey to other widgets */
408 if (handled
== MSG_HANDLED
)
411 hot_cur
= g_list_next (h
->current
);
413 hot_cur
= h
->widgets
;
415 /* send it to all widgets */
416 while (h
->current
!= hot_cur
&& handled
== MSG_NOT_HANDLED
)
418 current
= (Widget
*) hot_cur
->data
;
420 if ((current
->options
& W_WANT_HOTKEY
) != 0)
421 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
423 if (handled
== MSG_NOT_HANDLED
)
425 hot_cur
= g_list_next (hot_cur
);
427 hot_cur
= h
->widgets
;
431 if (handled
== MSG_HANDLED
)
432 do_select_widget (h
, hot_cur
, SELECT_EXACT
);
437 /* --------------------------------------------------------------------------------------------- */
440 dlg_key_event (Dlg_head
* h
, int d_key
)
444 if (h
->widgets
== NULL
)
447 if (h
->current
== NULL
)
448 h
->current
= h
->widgets
;
450 /* TAB used to cycle */
451 if ((h
->flags
& DLG_WANT_TAB
) == 0)
458 else if (d_key
== KEY_BTAB
)
465 /* first can dlg_callback handle the key */
466 handled
= h
->callback (h
, NULL
, DLG_KEY
, d_key
, NULL
);
468 /* next try the hotkey */
469 if (handled
== MSG_NOT_HANDLED
)
470 handled
= dlg_try_hotkey (h
, d_key
);
472 if (handled
== MSG_HANDLED
)
473 h
->callback (h
, NULL
, DLG_HOTKEY_HANDLED
, 0, NULL
);
475 /* not used - then try widget_callback */
476 handled
= send_message ((Widget
*) h
->current
->data
, WIDGET_KEY
, d_key
);
478 /* not used- try to use the unhandled case */
479 if (handled
== MSG_NOT_HANDLED
)
480 handled
= h
->callback (h
, NULL
, DLG_UNHANDLED_KEY
, d_key
, NULL
);
482 if (handled
== MSG_NOT_HANDLED
)
483 handled
= dlg_handle_key (h
, d_key
);
485 h
->callback (h
, NULL
, DLG_POST_KEY
, d_key
, NULL
);
488 /* --------------------------------------------------------------------------------------------- */
491 frontend_run_dlg (Dlg_head
* h
)
498 /* close opened editors, viewers, etc */
499 if (!h
->modal
&& midnight_shutdown
)
501 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
505 while (h
->state
== DLG_ACTIVE
)
508 change_screen_size ();
513 execute_hooks (idle_hook
);
515 while ((h
->flags
& DLG_WANT_IDLE
) && is_idle ())
516 h
->callback (h
, NULL
, DLG_IDLE
, 0, NULL
);
518 /* Allow terminating the dialog from the idle handler */
519 if (h
->state
!= DLG_ACTIVE
)
525 /* Clear interrupt flag */
526 tty_got_interrupt ();
527 d_key
= tty_get_event (&event
, h
->mouse_status
== MOU_REPEAT
, TRUE
);
529 dlg_process_event (h
, d_key
, &event
);
531 if (h
->state
== DLG_CLOSED
)
532 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
536 /* --------------------------------------------------------------------------------------------- */
537 /*** public functions ****************************************************************************/
538 /* --------------------------------------------------------------------------------------------- */
540 /** draw box in window */
542 draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
)
544 tty_draw_box (h
->y
+ y
, h
->x
+ x
, ys
, xs
, single
);
547 /* --------------------------------------------------------------------------------------------- */
549 /** Clean the dialog area, draw the frame and the title */
551 common_dialog_repaint (Dlg_head
* h
)
555 if (h
->state
!= DLG_ACTIVE
)
558 space
= (h
->flags
& DLG_COMPACT
) ? 0 : 1;
560 tty_setcolor (h
->color
[DLG_COLOR_NORMAL
]);
562 draw_box (h
, space
, space
, h
->lines
- 2 * space
, h
->cols
- 2 * space
, FALSE
);
564 if (h
->title
!= NULL
)
566 tty_setcolor (h
->color
[DLG_COLOR_TITLE
]);
567 dlg_move (h
, space
, (h
->cols
- str_term_width1 (h
->title
)) / 2);
568 tty_print_string (h
->title
);
572 /* --------------------------------------------------------------------------------------------- */
573 /** this function allows to set dialog position */
576 dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
)
578 /* save old positions, will be used to reposition childs */
580 int shift_x
, shift_y
, scale_x
, scale_y
;
582 /* save old positions, will be used to reposition childs */
593 /* dialog is empty */
594 if (h
->widgets
== NULL
)
597 if (h
->current
== NULL
)
598 h
->current
= h
->widgets
;
600 /* values by which controls should be moved */
603 scale_x
= h
->cols
- oc
;
604 scale_y
= h
->lines
- ol
;
606 if ((shift_x
!= 0) || (shift_y
!= 0) || (scale_x
!= 0) || (scale_y
!= 0))
610 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
612 /* there are, mainly, 2 generally possible
615 1. control sticks to one side - it
618 2. control sticks to two sides of
619 one direction - it should be sized */
621 Widget
*c
= (Widget
*) w
->data
;
625 int lines
= c
->lines
;
627 if ((c
->pos_flags
& WPOS_KEEP_LEFT
) && (c
->pos_flags
& WPOS_KEEP_RIGHT
))
632 else if (c
->pos_flags
& WPOS_KEEP_LEFT
)
634 else if (c
->pos_flags
& WPOS_KEEP_RIGHT
)
635 x
+= shift_x
+ scale_x
;
637 if ((c
->pos_flags
& WPOS_KEEP_TOP
) && (c
->pos_flags
& WPOS_KEEP_BOTTOM
))
642 else if (c
->pos_flags
& WPOS_KEEP_TOP
)
644 else if (c
->pos_flags
& WPOS_KEEP_BOTTOM
)
645 y
+= shift_y
+ scale_y
;
647 widget_set_size (c
, y
, x
, lines
, cols
);
652 /* --------------------------------------------------------------------------------------------- */
653 /** this function sets only size, leaving positioning to automatic methods */
656 dlg_set_size (Dlg_head
* h
, int lines
, int cols
)
661 if (h
->flags
& DLG_CENTER
)
663 y
= (LINES
- lines
) / 2;
664 x
= (COLS
- cols
) / 2;
667 if ((h
->flags
& DLG_TRYUP
) && (y
> 3))
670 dlg_set_position (h
, y
, x
, y
+ lines
, x
+ cols
);
673 /* --------------------------------------------------------------------------------------------- */
674 /** Default dialog callback */
677 default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
686 if (h
->color
!= NULL
)
688 common_dialog_repaint (h
);
691 return MSG_NOT_HANDLED
;
694 dlg_broadcast_msg_to (h
, WIDGET_IDLE
, FALSE
, W_WANT_IDLE
);
698 /* this is default resizing mechanism */
699 /* the main idea of this code is to resize dialog
700 according to flags (if any of flags require automatic
701 resizing, like DLG_CENTER, end after that reposition
702 controls in dialog according to flags of widget) */
703 dlg_set_size (h
, h
->lines
, h
->cols
);
710 return MSG_NOT_HANDLED
;
713 /* --------------------------------------------------------------------------------------------- */
716 create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
717 const int *colors
, dlg_cb_fn callback
, const char *help_ctx
,
718 const char *title
, dlg_flags_t flags
)
722 new_d
= g_new0 (Dlg_head
, 1);
723 new_d
->modal
= modal
;
726 memmove (new_d
->color
, colors
, sizeof (dlg_colors_t
));
728 new_d
->help_ctx
= help_ctx
;
729 new_d
->callback
= (callback
!= NULL
) ? callback
: default_dlg_callback
;
732 new_d
->flags
= flags
;
735 dlg_set_size (new_d
, lines
, cols
);
736 new_d
->fullscreen
= (new_d
->x
== 0 && new_d
->y
== 0
737 && new_d
->cols
== COLS
&& new_d
->lines
== LINES
);
739 new_d
->mouse_status
= MOU_NORMAL
;
741 /* Strip existing spaces, add one space before and after the title */
746 t
= g_strstrip (g_strdup (title
));
748 new_d
->title
= g_strdup_printf (" %s ", t
);
755 /* --------------------------------------------------------------------------------------------- */
758 dlg_set_default_colors (void)
760 dialog_colors
[DLG_COLOR_NORMAL
] = COLOR_NORMAL
;
761 dialog_colors
[DLG_COLOR_FOCUS
] = COLOR_FOCUS
;
762 dialog_colors
[DLG_COLOR_HOT_NORMAL
] = COLOR_HOT_NORMAL
;
763 dialog_colors
[DLG_COLOR_HOT_FOCUS
] = COLOR_HOT_FOCUS
;
764 dialog_colors
[DLG_COLOR_TITLE
] = COLOR_TITLE
;
766 alarm_colors
[DLG_COLOR_NORMAL
] = ERROR_COLOR
;
767 alarm_colors
[DLG_COLOR_FOCUS
] = ERROR_FOCUS
;
768 alarm_colors
[DLG_COLOR_HOT_NORMAL
] = ERROR_HOT_NORMAL
;
769 alarm_colors
[DLG_COLOR_HOT_FOCUS
] = ERROR_HOT_FOCUS
;
770 alarm_colors
[DLG_COLOR_TITLE
] = ERROR_TITLE
;
773 /* --------------------------------------------------------------------------------------------- */
776 dlg_erase (Dlg_head
* h
)
778 if ((h
!= NULL
) && (h
->state
== DLG_ACTIVE
))
779 tty_fill_region (h
->y
, h
->x
, h
->lines
, h
->cols
, ' ');
782 /* --------------------------------------------------------------------------------------------- */
785 set_idle_proc (Dlg_head
* d
, int enable
)
788 d
->flags
|= DLG_WANT_IDLE
;
790 d
->flags
&= ~DLG_WANT_IDLE
;
793 /* --------------------------------------------------------------------------------------------- */
795 * Insert widget to dialog before current widget. For dialogs populated
796 * from the bottom, make the widget current. Return widget number.
800 add_widget_autopos (Dlg_head
* h
, void *w
, widget_pos_flags_t pos_flags
)
802 Widget
*widget
= (Widget
*) w
;
804 /* Don't accept 0 widgets */
811 widget
->pos_flags
= pos_flags
;
812 widget
->id
= g_list_length (h
->widgets
);
814 if ((h
->flags
& DLG_REVERSE
) != 0)
815 h
->widgets
= g_list_prepend (h
->widgets
, widget
);
817 h
->widgets
= g_list_append (h
->widgets
, widget
);
819 h
->current
= h
->widgets
;
824 /* --------------------------------------------------------------------------------------------- */
825 /** wrapper to simply add lefttop positioned controls */
828 add_widget (Dlg_head
* h
, void *w
)
830 return add_widget_autopos (h
, w
, WPOS_KEEP_LEFT
| WPOS_KEEP_TOP
);
833 /* --------------------------------------------------------------------------------------------- */
842 if ((d
!= NULL
) && (d
->data
!= NULL
))
843 dlg_redraw ((Dlg_head
*) d
->data
);
847 /* Search first fullscreen dialog */
848 for (; d
!= NULL
; d
= g_list_next (d
))
849 if ((d
->data
!= NULL
) && ((Dlg_head
*) d
->data
)->fullscreen
)
851 /* back to top dialog */
852 for (; d
!= NULL
; d
= g_list_previous (d
))
854 dlg_redraw ((Dlg_head
*) d
->data
);
858 /* --------------------------------------------------------------------------------------------- */
859 /** broadcast a message to all the widgets in a dialog */
862 dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
)
864 dlg_broadcast_msg_to (h
, msg
, reverse
, 0);
867 /* --------------------------------------------------------------------------------------------- */
870 dlg_focus (Dlg_head
* h
)
872 /* cannot focus disabled widget ... */
874 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
876 Widget
*current
= (Widget
*) h
->current
->data
;
878 if (((current
->options
& W_DISABLED
) == 0)
879 && (send_message (current
, WIDGET_FOCUS
, 0) == MSG_HANDLED
))
881 h
->callback (h
, current
, DLG_FOCUS
, 0, NULL
);
889 /* --------------------------------------------------------------------------------------------- */
890 /** Return true if the windows overlap */
893 dlg_overlap (Widget
* a
, Widget
* b
)
895 return !((b
->x
>= a
->x
+ a
->cols
)
896 || (a
->x
>= b
->x
+ b
->cols
) || (b
->y
>= a
->y
+ a
->lines
) || (a
->y
>= b
->y
+ b
->lines
));
900 /* --------------------------------------------------------------------------------------------- */
901 /** Find the widget with the given callback in the dialog h */
904 find_widget_type (const Dlg_head
* h
, callback_fn callback
)
908 w
= g_list_find_custom (h
->widgets
, callback
, dlg_find_widget_callback
);
910 return (w
== NULL
) ? NULL
: (Widget
*) w
->data
;
913 /* --------------------------------------------------------------------------------------------- */
914 /** Find the widget with the given id */
917 dlg_find_by_id (const Dlg_head
* h
, unsigned int id
)
919 if (h
->widgets
!= NULL
)
923 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
924 if (((Widget
*) w
->data
)->id
== id
)
925 return (Widget
*) w
->data
;
931 /* --------------------------------------------------------------------------------------------- */
932 /** Find the widget with the given id in the dialog h and select it */
935 dlg_select_by_id (const Dlg_head
* h
, unsigned int id
)
939 w
= dlg_find_by_id (h
, id
);
941 dlg_select_widget (w
);
944 /* --------------------------------------------------------------------------------------------- */
946 * Try to select widget in the dialog.
950 dlg_select_widget (void *w
)
952 const Widget
*widget
= (Widget
*) w
;
953 Dlg_head
*h
= widget
->owner
;
955 do_select_widget (h
, g_list_find (h
->widgets
, widget
), SELECT_EXACT
);
958 /* --------------------------------------------------------------------------------------------- */
959 /** Try to select previous widget in the tab order */
962 dlg_one_up (Dlg_head
* h
)
964 if (h
->widgets
!= NULL
)
968 prev
= g_list_previous (h
->current
);
970 prev
= g_list_last (h
->widgets
);
972 do_select_widget (h
, prev
, SELECT_PREV
);
976 /* --------------------------------------------------------------------------------------------- */
977 /** Try to select next widget in the tab order */
980 dlg_one_down (Dlg_head
* h
)
982 if (h
->widgets
!= NULL
)
986 next
= g_list_next (h
->current
);
989 do_select_widget (h
, next
, SELECT_NEXT
);
993 /* --------------------------------------------------------------------------------------------- */
996 update_cursor (Dlg_head
* h
)
998 GList
*p
= h
->current
;
1000 if ((p
!= NULL
) && (h
->state
== DLG_ACTIVE
))
1004 w
= (Widget
*) p
->data
;
1006 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
1007 send_message (w
, WIDGET_CURSOR
, 0);
1011 p
= g_list_next (p
);
1015 if (p
== h
->current
)
1018 w
= (Widget
*) p
->data
;
1020 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
1021 if (send_message (w
, WIDGET_CURSOR
, 0) == MSG_HANDLED
)
1028 /* --------------------------------------------------------------------------------------------- */
1030 * Redraw the widgets in reverse order, leaving the current widget
1035 dlg_redraw (Dlg_head
* h
)
1037 if (h
->state
!= DLG_ACTIVE
)
1040 if (h
->winch_pending
)
1042 h
->winch_pending
= FALSE
;
1043 h
->callback (h
, NULL
, DLG_RESIZE
, 0, NULL
);
1046 h
->callback (h
, NULL
, DLG_DRAW
, 0, NULL
);
1047 dlg_broadcast_msg (h
, WIDGET_DRAW
, TRUE
);
1051 /* --------------------------------------------------------------------------------------------- */
1054 dlg_stop (Dlg_head
* h
)
1056 h
->state
= DLG_CLOSED
;
1059 /* --------------------------------------------------------------------------------------------- */
1060 /** Init the process */
1063 init_dlg (Dlg_head
* h
)
1065 if ((top_dlg
!= NULL
) && ((Dlg_head
*) top_dlg
->data
)->modal
)
1069 /* add dialog to the stack */
1070 top_dlg
= g_list_prepend (top_dlg
, h
);
1072 /* Initialize dialog manager and widgets */
1073 if (h
->state
== DLG_ACTIVE
)
1076 dialog_switch_add (h
);
1078 h
->callback (h
, NULL
, DLG_INIT
, 0, NULL
);
1079 dlg_broadcast_msg (h
, WIDGET_INIT
, FALSE
);
1082 h
->state
= DLG_ACTIVE
;
1086 /* Select the first widget that takes focus */
1087 while (h
->current
!= NULL
&& !dlg_focus (h
))
1089 h
->current
= g_list_next (h
->current
);
1090 if (h
->current
== NULL
)
1091 h
->current
= h
->widgets
;
1097 /* --------------------------------------------------------------------------------------------- */
1100 dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
)
1104 if (tty_got_interrupt ())
1105 dlg_execute_cmd (h
, CK_DialogCancel
);
1110 if (key
== EV_MOUSE
)
1111 h
->mouse_status
= dlg_mouse_event (h
, event
);
1113 dlg_key_event (h
, key
);
1116 /* --------------------------------------------------------------------------------------------- */
1117 /** Shutdown the run_dlg */
1120 dlg_run_done (Dlg_head
* h
)
1122 top_dlg
= g_list_remove (top_dlg
, h
);
1124 if (h
->state
== DLG_CLOSED
)
1126 h
->callback (h
, (Widget
*) h
->current
->data
, DLG_END
, 0, NULL
);
1128 dialog_switch_remove (h
);
1133 /* --------------------------------------------------------------------------------------------- */
1135 * Standard run dialog routine
1136 * We have to keep this routine small so that we can duplicate it's
1137 * behavior on complex routines like the file routines, this way,
1138 * they can call the dlg_process_event without rewriting all the code
1142 run_dlg (Dlg_head
* h
)
1145 frontend_run_dlg (h
);
1147 return h
->ret_value
;
1150 /* --------------------------------------------------------------------------------------------- */
1153 destroy_dlg (Dlg_head
* h
)
1155 dlg_broadcast_msg (h
, WIDGET_DESTROY
, FALSE
);
1156 g_list_foreach (h
->widgets
, (GFunc
) g_free
, NULL
);
1157 g_list_free (h
->widgets
);
1164 /* --------------------------------------------------------------------------------------------- */
1167 dlg_get_title (const Dlg_head
* h
, size_t len
)
1174 if (h
->get_title
!= NULL
)
1175 t
= h
->get_title (h
, len
);
1182 /* --------------------------------------------------------------------------------------------- */
1183 /** Replace widget old_w for widget new_w in the dialog */
1186 dlg_replace_widget (Widget
* old_w
, Widget
* new_w
)
1188 Dlg_head
*h
= old_w
->owner
;
1189 gboolean should_focus
= FALSE
;
1191 if (h
->widgets
== NULL
)
1194 if (h
->current
== NULL
)
1195 h
->current
= h
->widgets
;
1197 if (old_w
== h
->current
->data
)
1198 should_focus
= TRUE
;
1201 new_w
->id
= old_w
->id
;
1204 h
->current
->data
= new_w
;
1206 g_list_find (h
->widgets
, old_w
)->data
= new_w
;
1208 send_message (old_w
, WIDGET_DESTROY
, 0);
1209 send_message (new_w
, WIDGET_INIT
, 0);
1212 dlg_select_widget (new_w
);
1214 send_message (new_w
, WIDGET_DRAW
, 0);
1217 /* --------------------------------------------------------------------------------------------- */