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 /* --------------------------------------------------------------------------------------------- */
85 dlg_widget_next (Dlg_head
*h
, GList
*l
)
89 next
= g_list_next (l
);
96 /* --------------------------------------------------------------------------------------------- */
99 dlg_widget_prev (Dlg_head
*h
, GList
*l
)
103 prev
= g_list_previous (l
);
105 prev
= g_list_last (h
->widgets
);
110 /* --------------------------------------------------------------------------------------------- */
112 * broadcast a message to all the widgets in a dialog that have
113 * the options set to flags. If flags is zero, the message is sent
118 dlg_broadcast_msg_to (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
, int flags
)
122 if (h
->widgets
== NULL
)
125 if (h
->current
== NULL
)
126 h
->current
= h
->widgets
;
129 p
= dlg_widget_prev (h
, h
->current
);
131 p
= dlg_widget_next (h
, h
->current
);
137 Widget
*w
= (Widget
*) p
->data
;
140 p
= dlg_widget_prev (h
, p
);
142 p
= dlg_widget_next (h
, p
);
144 if ((flags
== 0) || ((flags
& w
->options
) != 0))
145 send_message (w
, msg
, 0);
150 /* --------------------------------------------------------------------------------------------- */
153 dlg_unfocus (Dlg_head
* h
)
155 /* ... but can unfocus disabled widget */
157 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
159 Widget
*current
= (Widget
*) h
->current
->data
;
161 if (send_message (current
, WIDGET_UNFOCUS
, 0) == MSG_HANDLED
)
163 h
->callback (h
, current
, DLG_UNFOCUS
, 0, NULL
);
171 /* --------------------------------------------------------------------------------------------- */
174 dlg_find_widget_callback (const void *a
, const void *b
)
176 const Widget
*w
= (const Widget
*) a
;
177 callback_fn f
= (callback_fn
) b
;
179 return (w
->callback
== f
) ? 0 : 1;
182 /* --------------------------------------------------------------------------------------------- */
184 * Try to select another widget. If forward is set, follow tab order.
185 * Otherwise go to the previous widget.
189 do_select_widget (Dlg_head
* h
, GList
* w
, select_dir_t dir
)
191 Widget
*w0
= (Widget
*) h
->current
->data
;
193 if (!dlg_unfocus (h
))
206 h
->current
= g_list_find (h
->widgets
, w0
);
209 /* try find another widget that can take focus */
213 h
->current
= dlg_widget_next (h
, h
->current
);
216 h
->current
= dlg_widget_prev (h
, h
->current
);
220 while (h
->current
!= w
/* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */ );
222 if (dlg_overlap (w0
, (Widget
*) h
->current
->data
))
224 send_message ((Widget
*) h
->current
->data
, WIDGET_DRAW
, 0);
225 send_message ((Widget
*) h
->current
->data
, WIDGET_FOCUS
, 0);
229 /* --------------------------------------------------------------------------------------------- */
238 /* Use this if the refreshes fail */
241 #endif /* HAVE_SLANG */
244 /* --------------------------------------------------------------------------------------------- */
247 dlg_execute_cmd (Dlg_head
* h
, unsigned long command
)
249 cb_ret_t ret
= MSG_HANDLED
;
253 h
->ret_value
= B_ENTER
;
256 case CK_DialogCancel
:
257 h
->ret_value
= B_CANCEL
;
261 case CK_DialogPrevItem
:
264 case CK_DialogNextItem
:
269 interactive_display (NULL
, h
->help_ctx
);
273 case CK_DialogSuspend
:
277 case CK_DialogRefresh
:
281 case CK_DialogListCmd
:
283 dialog_switch_list ();
285 ret
= MSG_NOT_HANDLED
;
287 case CK_DialogNextCmd
:
289 dialog_switch_next ();
291 ret
= MSG_NOT_HANDLED
;
293 case CK_DialogPrevCmd
:
295 dialog_switch_prev ();
297 ret
= MSG_NOT_HANDLED
;
301 ret
= MSG_NOT_HANDLED
;
307 /* --------------------------------------------------------------------------------------------- */
310 dlg_handle_key (Dlg_head
* h
, int d_key
)
312 unsigned long command
;
313 command
= keybind_lookup_keymap_command (dialog_map
, d_key
);
314 if ((command
== CK_Ignore_Key
) || (dlg_execute_cmd (h
, command
) == MSG_NOT_HANDLED
))
315 return MSG_NOT_HANDLED
;
320 /* --------------------------------------------------------------------------------------------- */
323 dlg_mouse_event (Dlg_head
* h
, Gpm_Event
* event
)
326 GList
*starting_widget
= h
->current
;
331 /* close the dialog by mouse click out of dialog area */
332 if (mouse_close_dialog
&& !h
->fullscreen
&& ((event
->buttons
& GPM_B_LEFT
) != 0) && ((event
->type
& GPM_DOWN
) != 0) /* left click */
333 && !((x
> h
->x
) && (x
<= h
->x
+ h
->cols
) && (y
> h
->y
) && (y
<= h
->y
+ h
->lines
)))
335 h
->ret_value
= B_CANCEL
;
340 item
= starting_widget
;
345 widget
= (Widget
*) item
->data
;
346 item
= dlg_widget_next (h
, item
);
348 if (((widget
->options
& W_DISABLED
) == 0)
349 && (x
> widget
->x
) && (x
<= widget
->x
+ widget
->cols
)
350 && (y
> widget
->y
) && (y
<= widget
->y
+ widget
->lines
))
353 new_event
.x
-= widget
->x
;
354 new_event
.y
-= widget
->y
;
356 if (widget
->mouse
!= NULL
)
357 return widget
->mouse (&new_event
, widget
);
360 while (item
!= starting_widget
);
365 /* --------------------------------------------------------------------------------------------- */
368 dlg_try_hotkey (Dlg_head
* h
, int d_key
)
375 if (h
->widgets
== NULL
)
376 return MSG_NOT_HANDLED
;
378 if (h
->current
== NULL
)
379 h
->current
= h
->widgets
;
382 * Explanation: we don't send letter hotkeys to other widgets if
383 * the currently selected widget is an input line
386 current
= (Widget
*) h
->current
->data
;
388 if ((current
->options
& W_DISABLED
) != 0)
389 return MSG_NOT_HANDLED
;
391 if (current
->options
& W_IS_INPUT
)
393 /* skip ascii control characters, anything else can valid character in
395 if (d_key
>= 32 && d_key
< 256)
396 return MSG_NOT_HANDLED
;
399 /* If it's an alt key, send the message */
400 c
= d_key
& ~ALT (0);
401 if (d_key
& ALT (0) && g_ascii_isalpha (c
))
402 d_key
= g_ascii_tolower (c
);
404 handled
= MSG_NOT_HANDLED
;
405 if ((current
->options
& W_WANT_HOTKEY
) != 0)
406 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
408 /* If not used, send hotkey to other widgets */
409 if (handled
== MSG_HANDLED
)
412 hot_cur
= dlg_widget_next (h
, h
->current
);
414 /* send it to all widgets */
415 while (h
->current
!= hot_cur
&& handled
== MSG_NOT_HANDLED
)
417 current
= (Widget
*) hot_cur
->data
;
419 if ((current
->options
& W_WANT_HOTKEY
) != 0)
420 handled
= send_message (current
, WIDGET_HOTKEY
, d_key
);
422 if (handled
== MSG_NOT_HANDLED
)
423 hot_cur
= dlg_widget_next (h
, hot_cur
);
426 if (handled
== MSG_HANDLED
)
427 do_select_widget (h
, hot_cur
, SELECT_EXACT
);
432 /* --------------------------------------------------------------------------------------------- */
435 dlg_key_event (Dlg_head
* h
, int d_key
)
439 if (h
->widgets
== NULL
)
442 if (h
->current
== NULL
)
443 h
->current
= h
->widgets
;
445 /* TAB used to cycle */
446 if ((h
->flags
& DLG_WANT_TAB
) == 0)
453 else if (d_key
== KEY_BTAB
)
460 /* first can dlg_callback handle the key */
461 handled
= h
->callback (h
, NULL
, DLG_KEY
, d_key
, NULL
);
463 /* next try the hotkey */
464 if (handled
== MSG_NOT_HANDLED
)
465 handled
= dlg_try_hotkey (h
, d_key
);
467 if (handled
== MSG_HANDLED
)
468 h
->callback (h
, NULL
, DLG_HOTKEY_HANDLED
, 0, NULL
);
470 /* not used - then try widget_callback */
471 handled
= send_message ((Widget
*) h
->current
->data
, WIDGET_KEY
, d_key
);
473 /* not used- try to use the unhandled case */
474 if (handled
== MSG_NOT_HANDLED
)
475 handled
= h
->callback (h
, NULL
, DLG_UNHANDLED_KEY
, d_key
, NULL
);
477 if (handled
== MSG_NOT_HANDLED
)
478 handled
= dlg_handle_key (h
, d_key
);
480 h
->callback (h
, NULL
, DLG_POST_KEY
, d_key
, NULL
);
483 /* --------------------------------------------------------------------------------------------- */
486 frontend_run_dlg (Dlg_head
* h
)
493 /* close opened editors, viewers, etc */
494 if (!h
->modal
&& midnight_shutdown
)
496 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
500 while (h
->state
== DLG_ACTIVE
)
503 change_screen_size ();
508 execute_hooks (idle_hook
);
510 while ((h
->flags
& DLG_WANT_IDLE
) && is_idle ())
511 h
->callback (h
, NULL
, DLG_IDLE
, 0, NULL
);
513 /* Allow terminating the dialog from the idle handler */
514 if (h
->state
!= DLG_ACTIVE
)
520 /* Clear interrupt flag */
521 tty_got_interrupt ();
522 d_key
= tty_get_event (&event
, h
->mouse_status
== MOU_REPEAT
, TRUE
);
524 dlg_process_event (h
, d_key
, &event
);
526 if (h
->state
== DLG_CLOSED
)
527 h
->callback (h
, NULL
, DLG_VALIDATE
, 0, NULL
);
531 /* --------------------------------------------------------------------------------------------- */
534 dlg_find_widget_by_id (gconstpointer a
, gconstpointer b
)
536 Widget
*w
= (Widget
*) a
;
537 unsigned long id
= GPOINTER_TO_UINT (b
);
539 return w
->id
== id
? 0 : 1;
542 /* --------------------------------------------------------------------------------------------- */
543 /*** public functions ****************************************************************************/
544 /* --------------------------------------------------------------------------------------------- */
546 /** draw box in window */
548 draw_box (Dlg_head
* h
, int y
, int x
, int ys
, int xs
, gboolean single
)
550 tty_draw_box (h
->y
+ y
, h
->x
+ x
, ys
, xs
, single
);
553 /* --------------------------------------------------------------------------------------------- */
555 /** Clean the dialog area, draw the frame and the title */
557 common_dialog_repaint (Dlg_head
* h
)
561 if (h
->state
!= DLG_ACTIVE
)
564 space
= (h
->flags
& DLG_COMPACT
) ? 0 : 1;
566 tty_setcolor (h
->color
[DLG_COLOR_NORMAL
]);
568 draw_box (h
, space
, space
, h
->lines
- 2 * space
, h
->cols
- 2 * space
, FALSE
);
570 if (h
->title
!= NULL
)
572 tty_setcolor (h
->color
[DLG_COLOR_TITLE
]);
573 dlg_move (h
, space
, (h
->cols
- str_term_width1 (h
->title
)) / 2);
574 tty_print_string (h
->title
);
578 /* --------------------------------------------------------------------------------------------- */
579 /** this function allows to set dialog position */
582 dlg_set_position (Dlg_head
* h
, int y1
, int x1
, int y2
, int x2
)
584 /* save old positions, will be used to reposition childs */
586 int shift_x
, shift_y
, scale_x
, scale_y
;
588 /* save old positions, will be used to reposition childs */
599 /* dialog is empty */
600 if (h
->widgets
== NULL
)
603 if (h
->current
== NULL
)
604 h
->current
= h
->widgets
;
606 /* values by which controls should be moved */
609 scale_x
= h
->cols
- oc
;
610 scale_y
= h
->lines
- ol
;
612 if ((shift_x
!= 0) || (shift_y
!= 0) || (scale_x
!= 0) || (scale_y
!= 0))
616 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
618 /* there are, mainly, 2 generally possible
621 1. control sticks to one side - it
624 2. control sticks to two sides of
625 one direction - it should be sized */
627 Widget
*c
= (Widget
*) w
->data
;
631 int lines
= c
->lines
;
633 if ((c
->pos_flags
& WPOS_KEEP_LEFT
) && (c
->pos_flags
& WPOS_KEEP_RIGHT
))
638 else if (c
->pos_flags
& WPOS_KEEP_LEFT
)
640 else if (c
->pos_flags
& WPOS_KEEP_RIGHT
)
641 x
+= shift_x
+ scale_x
;
643 if ((c
->pos_flags
& WPOS_KEEP_TOP
) && (c
->pos_flags
& WPOS_KEEP_BOTTOM
))
648 else if (c
->pos_flags
& WPOS_KEEP_TOP
)
650 else if (c
->pos_flags
& WPOS_KEEP_BOTTOM
)
651 y
+= shift_y
+ scale_y
;
653 widget_set_size (c
, y
, x
, lines
, cols
);
658 /* --------------------------------------------------------------------------------------------- */
659 /** this function sets only size, leaving positioning to automatic methods */
662 dlg_set_size (Dlg_head
* h
, int lines
, int cols
)
667 if (h
->flags
& DLG_CENTER
)
669 y
= (LINES
- lines
) / 2;
670 x
= (COLS
- cols
) / 2;
673 if ((h
->flags
& DLG_TRYUP
) && (y
> 3))
676 dlg_set_position (h
, y
, x
, y
+ lines
, x
+ cols
);
679 /* --------------------------------------------------------------------------------------------- */
680 /** Default dialog callback */
683 default_dlg_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
692 if (h
->color
!= NULL
)
694 common_dialog_repaint (h
);
697 return MSG_NOT_HANDLED
;
700 dlg_broadcast_msg_to (h
, WIDGET_IDLE
, FALSE
, W_WANT_IDLE
);
704 /* this is default resizing mechanism */
705 /* the main idea of this code is to resize dialog
706 according to flags (if any of flags require automatic
707 resizing, like DLG_CENTER, end after that reposition
708 controls in dialog according to flags of widget) */
709 dlg_set_size (h
, h
->lines
, h
->cols
);
716 return MSG_NOT_HANDLED
;
719 /* --------------------------------------------------------------------------------------------- */
722 create_dlg (gboolean modal
, int y1
, int x1
, int lines
, int cols
,
723 const int *colors
, dlg_cb_fn callback
, const char *help_ctx
,
724 const char *title
, dlg_flags_t flags
)
728 new_d
= g_new0 (Dlg_head
, 1);
729 new_d
->modal
= modal
;
732 memmove (new_d
->color
, colors
, sizeof (dlg_colors_t
));
734 new_d
->help_ctx
= help_ctx
;
735 new_d
->callback
= (callback
!= NULL
) ? callback
: default_dlg_callback
;
738 new_d
->flags
= flags
;
741 dlg_set_size (new_d
, lines
, cols
);
742 new_d
->fullscreen
= (new_d
->x
== 0 && new_d
->y
== 0
743 && new_d
->cols
== COLS
&& new_d
->lines
== LINES
);
745 new_d
->mouse_status
= MOU_NORMAL
;
747 /* Strip existing spaces, add one space before and after the title */
752 t
= g_strstrip (g_strdup (title
));
754 new_d
->title
= g_strdup_printf (" %s ", t
);
761 /* --------------------------------------------------------------------------------------------- */
764 dlg_set_default_colors (void)
766 dialog_colors
[DLG_COLOR_NORMAL
] = COLOR_NORMAL
;
767 dialog_colors
[DLG_COLOR_FOCUS
] = COLOR_FOCUS
;
768 dialog_colors
[DLG_COLOR_HOT_NORMAL
] = COLOR_HOT_NORMAL
;
769 dialog_colors
[DLG_COLOR_HOT_FOCUS
] = COLOR_HOT_FOCUS
;
770 dialog_colors
[DLG_COLOR_TITLE
] = COLOR_TITLE
;
772 alarm_colors
[DLG_COLOR_NORMAL
] = ERROR_COLOR
;
773 alarm_colors
[DLG_COLOR_FOCUS
] = ERROR_FOCUS
;
774 alarm_colors
[DLG_COLOR_HOT_NORMAL
] = ERROR_HOT_NORMAL
;
775 alarm_colors
[DLG_COLOR_HOT_FOCUS
] = ERROR_HOT_FOCUS
;
776 alarm_colors
[DLG_COLOR_TITLE
] = ERROR_TITLE
;
779 /* --------------------------------------------------------------------------------------------- */
782 dlg_erase (Dlg_head
* h
)
784 if ((h
!= NULL
) && (h
->state
== DLG_ACTIVE
))
785 tty_fill_region (h
->y
, h
->x
, h
->lines
, h
->cols
, ' ');
788 /* --------------------------------------------------------------------------------------------- */
791 set_idle_proc (Dlg_head
* d
, int enable
)
794 d
->flags
|= DLG_WANT_IDLE
;
796 d
->flags
&= ~DLG_WANT_IDLE
;
799 /* --------------------------------------------------------------------------------------------- */
801 * Insert widget to dialog before current widget. For dialogs populated
802 * from the bottom, make the widget current. Return widget number.
806 add_widget_autopos (Dlg_head
* h
, void *w
, widget_pos_flags_t pos_flags
)
808 Widget
*widget
= (Widget
*) w
;
810 /* Don't accept 0 widgets */
817 widget
->pos_flags
= pos_flags
;
818 widget
->id
= g_list_length (h
->widgets
);
820 if ((h
->flags
& DLG_REVERSE
) != 0)
821 h
->widgets
= g_list_prepend (h
->widgets
, widget
);
823 h
->widgets
= g_list_append (h
->widgets
, widget
);
825 h
->current
= h
->widgets
;
830 /* --------------------------------------------------------------------------------------------- */
831 /** wrapper to simply add lefttop positioned controls */
834 add_widget (Dlg_head
* h
, void *w
)
836 return add_widget_autopos (h
, w
, WPOS_KEEP_LEFT
| WPOS_KEEP_TOP
);
839 /* --------------------------------------------------------------------------------------------- */
848 if ((d
!= NULL
) && (d
->data
!= NULL
))
849 dlg_redraw ((Dlg_head
*) d
->data
);
853 /* Search first fullscreen dialog */
854 for (; d
!= NULL
; d
= g_list_next (d
))
855 if ((d
->data
!= NULL
) && ((Dlg_head
*) d
->data
)->fullscreen
)
857 /* back to top dialog */
858 for (; d
!= NULL
; d
= g_list_previous (d
))
860 dlg_redraw ((Dlg_head
*) d
->data
);
864 /* --------------------------------------------------------------------------------------------- */
865 /** broadcast a message to all the widgets in a dialog */
868 dlg_broadcast_msg (Dlg_head
* h
, widget_msg_t msg
, gboolean reverse
)
870 dlg_broadcast_msg_to (h
, msg
, reverse
, 0);
873 /* --------------------------------------------------------------------------------------------- */
876 dlg_focus (Dlg_head
* h
)
878 /* cannot focus disabled widget ... */
880 if ((h
->current
!= NULL
) && (h
->state
== DLG_ACTIVE
))
882 Widget
*current
= (Widget
*) h
->current
->data
;
884 if (((current
->options
& W_DISABLED
) == 0)
885 && (send_message (current
, WIDGET_FOCUS
, 0) == MSG_HANDLED
))
887 h
->callback (h
, current
, DLG_FOCUS
, 0, NULL
);
895 /* --------------------------------------------------------------------------------------------- */
896 /** Return true if the windows overlap */
899 dlg_overlap (Widget
* a
, Widget
* b
)
901 return !((b
->x
>= a
->x
+ a
->cols
)
902 || (a
->x
>= b
->x
+ b
->cols
) || (b
->y
>= a
->y
+ a
->lines
) || (a
->y
>= b
->y
+ b
->lines
));
906 /* --------------------------------------------------------------------------------------------- */
907 /** Find the widget with the given callback in the dialog h */
910 find_widget_type (const Dlg_head
* h
, callback_fn callback
)
914 w
= g_list_find_custom (h
->widgets
, callback
, dlg_find_widget_callback
);
916 return (w
== NULL
) ? NULL
: (Widget
*) w
->data
;
919 /* --------------------------------------------------------------------------------------------- */
920 /** Find the widget with the given id */
923 dlg_find_by_id (const Dlg_head
* h
, unsigned int id
)
927 w
= g_list_find_custom (h
->widgets
, GUINT_TO_POINTER (id
), dlg_find_widget_by_id
);
928 return w
!= NULL
? (Widget
*) w
->data
: NULL
;
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
)
965 do_select_widget (h
, dlg_widget_prev (h
, h
->current
), SELECT_PREV
);
968 /* --------------------------------------------------------------------------------------------- */
969 /** Try to select next widget in the tab order */
972 dlg_one_down (Dlg_head
* h
)
974 if (h
->widgets
!= NULL
)
975 do_select_widget (h
, dlg_widget_next (h
, h
->current
), SELECT_NEXT
);
978 /* --------------------------------------------------------------------------------------------- */
981 update_cursor (Dlg_head
* h
)
983 GList
*p
= h
->current
;
985 if ((p
!= NULL
) && (h
->state
== DLG_ACTIVE
))
989 w
= (Widget
*) p
->data
;
991 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
992 send_message (w
, WIDGET_CURSOR
, 0);
996 p
= dlg_widget_next (h
, p
);
1000 w
= (Widget
*) p
->data
;
1002 if (((w
->options
& W_DISABLED
) == 0) && ((w
->options
& W_WANT_CURSOR
) != 0))
1003 if (send_message (w
, WIDGET_CURSOR
, 0) == MSG_HANDLED
)
1010 /* --------------------------------------------------------------------------------------------- */
1012 * Redraw the widgets in reverse order, leaving the current widget
1017 dlg_redraw (Dlg_head
* h
)
1019 if (h
->state
!= DLG_ACTIVE
)
1022 if (h
->winch_pending
)
1024 h
->winch_pending
= FALSE
;
1025 h
->callback (h
, NULL
, DLG_RESIZE
, 0, NULL
);
1028 h
->callback (h
, NULL
, DLG_DRAW
, 0, NULL
);
1029 dlg_broadcast_msg (h
, WIDGET_DRAW
, TRUE
);
1033 /* --------------------------------------------------------------------------------------------- */
1036 dlg_stop (Dlg_head
* h
)
1038 h
->state
= DLG_CLOSED
;
1041 /* --------------------------------------------------------------------------------------------- */
1042 /** Init the process */
1045 init_dlg (Dlg_head
* h
)
1047 if ((top_dlg
!= NULL
) && ((Dlg_head
*) top_dlg
->data
)->modal
)
1050 /* add dialog to the stack */
1051 top_dlg
= g_list_prepend (top_dlg
, h
);
1053 /* Initialize dialog manager and widgets */
1054 if (h
->state
== DLG_ACTIVE
)
1057 dialog_switch_add (h
);
1059 h
->callback (h
, NULL
, DLG_INIT
, 0, NULL
);
1060 dlg_broadcast_msg (h
, WIDGET_INIT
, FALSE
);
1063 h
->state
= DLG_ACTIVE
;
1067 /* Select the first widget that takes focus */
1068 while (h
->current
!= NULL
&& !dlg_focus (h
))
1069 h
->current
= dlg_widget_next (h
, h
->current
);
1074 /* --------------------------------------------------------------------------------------------- */
1077 dlg_process_event (Dlg_head
* h
, int key
, Gpm_Event
* event
)
1081 if (tty_got_interrupt ())
1082 if (h
->callback (h
, NULL
, DLG_ACTION
, CK_DialogCancel
, NULL
) != MSG_HANDLED
)
1083 dlg_execute_cmd (h
, CK_DialogCancel
);
1088 if (key
== EV_MOUSE
)
1089 h
->mouse_status
= dlg_mouse_event (h
, event
);
1091 dlg_key_event (h
, key
);
1094 /* --------------------------------------------------------------------------------------------- */
1095 /** Shutdown the run_dlg */
1098 dlg_run_done (Dlg_head
* h
)
1100 top_dlg
= g_list_remove (top_dlg
, h
);
1102 if (h
->state
== DLG_CLOSED
)
1104 h
->callback (h
, (Widget
*) h
->current
->data
, DLG_END
, 0, NULL
);
1106 dialog_switch_remove (h
);
1111 /* --------------------------------------------------------------------------------------------- */
1113 * Standard run dialog routine
1114 * We have to keep this routine small so that we can duplicate it's
1115 * behavior on complex routines like the file routines, this way,
1116 * they can call the dlg_process_event without rewriting all the code
1120 run_dlg (Dlg_head
* h
)
1123 frontend_run_dlg (h
);
1125 return h
->ret_value
;
1128 /* --------------------------------------------------------------------------------------------- */
1131 destroy_dlg (Dlg_head
* h
)
1133 dlg_broadcast_msg (h
, WIDGET_DESTROY
, FALSE
);
1134 g_list_foreach (h
->widgets
, (GFunc
) g_free
, NULL
);
1135 g_list_free (h
->widgets
);
1142 /* --------------------------------------------------------------------------------------------- */
1145 dlg_get_title (const Dlg_head
* h
, size_t len
)
1152 if (h
->get_title
!= NULL
)
1153 t
= h
->get_title (h
, len
);
1160 /* --------------------------------------------------------------------------------------------- */
1161 /** Replace widget old_w for widget new_w in the dialog */
1164 dlg_replace_widget (Widget
* old_w
, Widget
* new_w
)
1166 Dlg_head
*h
= old_w
->owner
;
1167 gboolean should_focus
= FALSE
;
1169 if (h
->widgets
== NULL
)
1172 if (h
->current
== NULL
)
1173 h
->current
= h
->widgets
;
1175 if (old_w
== h
->current
->data
)
1176 should_focus
= TRUE
;
1179 new_w
->id
= old_w
->id
;
1182 h
->current
->data
= new_w
;
1184 g_list_find (h
->widgets
, old_w
)->data
= new_w
;
1186 send_message (old_w
, WIDGET_DESTROY
, 0);
1187 send_message (new_w
, WIDGET_INIT
, 0);
1190 dlg_select_widget (new_w
);
1192 send_message (new_w
, WIDGET_DRAW
, 0);
1195 /* --------------------------------------------------------------------------------------------- */