2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Dialog box features module for the Midnight Commander
|
|
|
|
|
2017-01-01 17:33:11 +03:00
|
|
|
Copyright (C) 1994-2017
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-10-15 14:56:47 +04:00
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of the License,
|
|
|
|
or (at your option) any later version.
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
1998-02-27 07:54:42 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-10-25 03:20:30 +04:00
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file dialog.c
|
|
|
|
* \brief Source: dialog box features module
|
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
#include <ctype.h>
|
2011-05-02 13:44:47 +04:00
|
|
|
#include <errno.h>
|
2009-02-27 14:54:26 +03:00
|
|
|
#include <stdlib.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-05-02 13:44:47 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/tty.h"
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/skin.h"
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/key.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2011-05-02 13:44:47 +04:00
|
|
|
#include "lib/fileloc.h" /* MC_HISTORY_FILE */
|
2011-02-17 15:02:31 +03:00
|
|
|
#include "lib/event.h" /* mc_event_raise() */
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2016-03-06 09:44:16 +03:00
|
|
|
#include "lib/widget.h"
|
|
|
|
#include "lib/widget/mouse.h"
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
2009-05-30 21:39:02 +04:00
|
|
|
/* Color styles for normal and error dialogs */
|
2010-10-12 13:33:09 +04:00
|
|
|
dlg_colors_t dialog_colors;
|
|
|
|
dlg_colors_t alarm_colors;
|
2014-02-08 19:37:11 +04:00
|
|
|
dlg_colors_t listbox_colors;
|
2009-05-30 21:39:02 +04:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
/* Primitive way to check if the the current dialog is our dialog */
|
|
|
|
/* This is needed by async routines like load_prompt */
|
2010-04-18 14:26:28 +04:00
|
|
|
GList *top_dlg = NULL;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* A hook list for idle events */
|
2010-11-09 11:08:20 +03:00
|
|
|
hook_t *idle_hook = NULL;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-22 14:45:18 +03:00
|
|
|
/* If set then dialogs just clean the screen when refreshing, else */
|
|
|
|
/* they do a complete refresh, refreshing all the parts of the program */
|
2016-11-25 10:39:08 +03:00
|
|
|
gboolean fast_refresh = FALSE;
|
2010-11-22 14:45:18 +03:00
|
|
|
|
2009-04-03 19:29:20 +04:00
|
|
|
/* left click outside of dialog closes it */
|
2016-11-25 10:39:08 +03:00
|
|
|
gboolean mouse_close_dialog = FALSE;
|
2009-04-03 19:29:20 +04:00
|
|
|
|
2011-07-14 21:34:55 +04:00
|
|
|
const global_keymap_t *dialog_map = NULL;
|
2011-02-16 18:19:48 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2016-06-10 15:53:07 +03:00
|
|
|
/* Control widget positions in dialog */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int shift_x;
|
|
|
|
int scale_x;
|
|
|
|
int shift_y;
|
|
|
|
int scale_y;
|
|
|
|
} widget_shift_scale_t;
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2010-09-01 14:28:10 +04:00
|
|
|
|
2016-06-18 20:29:46 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
2011-07-18 13:27:01 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static GList *
|
2016-06-18 20:29:46 +03:00
|
|
|
dlg_get_next_or_prev_of (const GList * list, gboolean next)
|
2011-07-18 13:27:01 +04:00
|
|
|
{
|
2016-06-18 20:29:46 +03:00
|
|
|
GList *l = NULL;
|
2011-07-18 13:27:01 +04:00
|
|
|
|
2016-06-18 20:29:46 +03:00
|
|
|
if (list != NULL && list->data != NULL)
|
|
|
|
{
|
|
|
|
const WDialog *owner = CONST_WIDGET (list->data)->owner;
|
2011-07-18 13:27:01 +04:00
|
|
|
|
2016-06-18 20:29:46 +03:00
|
|
|
if (owner != NULL)
|
|
|
|
{
|
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
l = g_list_next (list);
|
|
|
|
if (l == NULL)
|
|
|
|
l = owner->widgets;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
l = g_list_previous (list);
|
|
|
|
if (l == NULL)
|
|
|
|
l = g_list_last (owner->widgets);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return l;
|
2011-07-18 13:27:01 +04:00
|
|
|
}
|
|
|
|
|
2016-07-16 21:00:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
dlg_select_next_or_prev (WDialog * h, gboolean next)
|
|
|
|
{
|
|
|
|
if (h->widgets != NULL && h->current != NULL)
|
|
|
|
{
|
|
|
|
GList *l = h->current;
|
|
|
|
Widget *w;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
l = dlg_get_next_or_prev_of (l, next);
|
|
|
|
w = WIDGET (l->data);
|
|
|
|
}
|
|
|
|
while ((widget_get_state (w, WST_DISABLED) || !widget_get_options (w, WOP_SELECTABLE))
|
|
|
|
&& l != h->current);
|
|
|
|
|
|
|
|
widget_select (l->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* broadcast a message to all the widgets in a dialog that have
|
|
|
|
* the options set to flags. If flags is zero, the message is sent
|
|
|
|
* to all widgets.
|
|
|
|
*/
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
static void
|
2016-04-10 12:35:43 +03:00
|
|
|
dlg_broadcast_msg_to (WDialog * h, widget_msg_t msg, gboolean reverse, widget_options_t flags)
|
2009-08-16 19:27:33 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
GList *p, *first;
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-04-05 20:59:21 +04:00
|
|
|
if (h->widgets == NULL)
|
2010-04-03 15:19:09 +04:00
|
|
|
return;
|
|
|
|
|
2010-04-05 20:59:21 +04:00
|
|
|
if (h->current == NULL)
|
|
|
|
h->current = h->widgets;
|
|
|
|
|
2016-06-18 20:29:46 +03:00
|
|
|
p = dlg_get_next_or_prev_of (h->current, !reverse);
|
2010-11-10 14:09:42 +03:00
|
|
|
first = p;
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
do
|
|
|
|
{
|
2012-06-20 15:09:44 +04:00
|
|
|
Widget *w = WIDGET (p->data);
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2016-06-18 20:29:46 +03:00
|
|
|
p = dlg_get_next_or_prev_of (p, !reverse);
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((flags == 0) || ((flags & w->options) != 0))
|
2012-06-26 11:52:21 +04:00
|
|
|
send_message (w, NULL, msg, 0, NULL);
|
2009-08-16 19:27:33 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
while (first != p);
|
2009-08-16 19:27:33 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-05-03 17:24:56 +04:00
|
|
|
/**
|
|
|
|
* Read histories from the ${XDG_CACHE_HOME}/mc/history file
|
|
|
|
*/
|
|
|
|
static void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_read_history (WDialog * h)
|
2011-05-03 17:24:56 +04:00
|
|
|
{
|
|
|
|
char *profile;
|
|
|
|
ev_history_load_save_t event_data;
|
|
|
|
|
|
|
|
if (num_history_items_recorded == 0) /* this is how to disable */
|
|
|
|
return;
|
|
|
|
|
2011-11-24 02:28:07 +04:00
|
|
|
profile = mc_config_get_full_path (MC_HISTORY_FILE);
|
2012-07-28 14:19:27 +04:00
|
|
|
event_data.cfg = mc_config_init (profile, TRUE);
|
2011-05-03 17:24:56 +04:00
|
|
|
event_data.receiver = NULL;
|
|
|
|
|
|
|
|
/* create all histories in dialog */
|
|
|
|
mc_event_raise (h->event_group, MCEVENT_HISTORY_LOAD, &event_data);
|
|
|
|
|
|
|
|
mc_config_deinit (event_data.cfg);
|
|
|
|
g_free (profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
static int
|
|
|
|
dlg_find_widget_callback (const void *a, const void *b)
|
|
|
|
{
|
2016-02-20 17:29:21 +03:00
|
|
|
const Widget *w = CONST_WIDGET (a);
|
2016-02-20 18:09:10 +03:00
|
|
|
const widget_cb_fn f = b;
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return (w->callback == f) ? 0 : 1;
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2016-06-28 15:39:03 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
static void
|
|
|
|
refresh_cmd (void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SLANG
|
|
|
|
tty_touch_screen ();
|
|
|
|
mc_refresh ();
|
|
|
|
#else
|
|
|
|
/* Use this if the refreshes fail */
|
|
|
|
clr_scr ();
|
|
|
|
repaint_screen ();
|
|
|
|
#endif /* HAVE_SLANG */
|
2009-05-30 21:39:02 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static cb_ret_t
|
2015-11-21 18:15:11 +03:00
|
|
|
dlg_execute_cmd (WDialog * h, long command)
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
cb_ret_t ret = MSG_HANDLED;
|
|
|
|
switch (command)
|
|
|
|
{
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Ok:
|
2010-11-10 14:09:42 +03:00
|
|
|
h->ret_value = B_ENTER;
|
|
|
|
dlg_stop (h);
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Cancel:
|
2010-11-10 14:09:42 +03:00
|
|
|
h->ret_value = B_CANCEL;
|
|
|
|
dlg_stop (h);
|
|
|
|
break;
|
|
|
|
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Up:
|
|
|
|
case CK_Left:
|
2016-07-16 16:16:23 +03:00
|
|
|
dlg_select_prev_widget (h);
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Down:
|
|
|
|
case CK_Right:
|
2016-07-16 16:16:23 +03:00
|
|
|
dlg_select_next_widget (h);
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
|
|
|
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Help:
|
2011-02-17 15:02:31 +03:00
|
|
|
{
|
|
|
|
ev_help_t event_data = { NULL, h->help_ctx };
|
|
|
|
mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
|
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
|
|
|
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Suspend:
|
2011-02-18 15:13:44 +03:00
|
|
|
mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
refresh_cmd ();
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Refresh:
|
2010-11-10 14:09:42 +03:00
|
|
|
refresh_cmd ();
|
|
|
|
break;
|
|
|
|
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_ScreenList:
|
2016-04-16 11:12:49 +03:00
|
|
|
if (!widget_get_state (WIDGET (h), WST_MODAL))
|
2010-11-10 14:09:42 +03:00
|
|
|
dialog_switch_list ();
|
|
|
|
else
|
|
|
|
ret = MSG_NOT_HANDLED;
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_ScreenNext:
|
2016-04-16 11:12:49 +03:00
|
|
|
if (!widget_get_state (WIDGET (h), WST_MODAL))
|
2010-11-10 14:09:42 +03:00
|
|
|
dialog_switch_next ();
|
|
|
|
else
|
|
|
|
ret = MSG_NOT_HANDLED;
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_ScreenPrev:
|
2016-04-16 11:12:49 +03:00
|
|
|
if (!widget_get_state (WIDGET (h), WST_MODAL))
|
2010-11-10 14:09:42 +03:00
|
|
|
dialog_switch_prev ();
|
|
|
|
else
|
|
|
|
ret = MSG_NOT_HANDLED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = MSG_NOT_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static cb_ret_t
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_handle_key (WDialog * h, int d_key)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2015-11-21 18:15:11 +03:00
|
|
|
long command;
|
2011-10-27 14:58:54 +04:00
|
|
|
|
2010-11-18 11:43:23 +03:00
|
|
|
command = keybind_lookup_keymap_command (dialog_map, d_key);
|
2011-10-27 14:58:54 +04:00
|
|
|
|
|
|
|
if (command == CK_IgnoreKey)
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_NOT_HANDLED;
|
2011-10-27 14:58:54 +04:00
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
if (send_message (h, NULL, MSG_ACTION, command, NULL) == MSG_HANDLED
|
2011-10-27 14:58:54 +04:00
|
|
|
|| dlg_execute_cmd (h, command) == MSG_HANDLED)
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_HANDLED;
|
2011-10-27 14:58:54 +04:00
|
|
|
|
|
|
|
return MSG_NOT_HANDLED;
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2016-03-06 09:44:16 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* This is the low-level mouse handler.
|
|
|
|
* It receives a Gpm_Event event and translates it into a higher level protocol.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
dlg_mouse_translator (Gpm_Event * event, Widget * w)
|
|
|
|
{
|
|
|
|
mouse_event_t me;
|
|
|
|
|
2016-03-23 19:17:05 +03:00
|
|
|
me = mouse_translate_event (w, event);
|
2016-03-06 09:44:16 +03:00
|
|
|
|
2016-03-23 19:17:05 +03:00
|
|
|
return mouse_process_event (w, &me);
|
2016-03-06 09:44:16 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_mouse_event (WDialog * h, Gpm_Event * event)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2012-06-20 12:05:13 +04:00
|
|
|
Widget *wh = WIDGET (h);
|
|
|
|
|
2016-02-23 09:49:58 +03:00
|
|
|
GList *p;
|
2013-06-23 17:30:03 +04:00
|
|
|
|
|
|
|
/* close the dialog by mouse left click out of dialog area */
|
2016-05-08 21:10:05 +03:00
|
|
|
if (mouse_close_dialog && (wh->pos_flags & WPOS_FULLSCREEN) == 0
|
|
|
|
&& ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0)
|
|
|
|
&& !mouse_global_in_widget (event, wh))
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
|
|
|
h->ret_value = B_CANCEL;
|
|
|
|
dlg_stop (h);
|
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2016-03-06 09:44:16 +03:00
|
|
|
if (wh->mouse_callback != NULL)
|
2012-05-28 16:59:20 +04:00
|
|
|
{
|
|
|
|
int mou;
|
|
|
|
|
2016-03-06 09:44:16 +03:00
|
|
|
mou = dlg_mouse_translator (event, wh);
|
2012-05-28 16:59:20 +04:00
|
|
|
if (mou != MOU_UNHANDLED)
|
|
|
|
return mou;
|
|
|
|
}
|
|
|
|
|
2016-02-23 09:49:58 +03:00
|
|
|
/* send the event to widgets in reverse Z-order */
|
|
|
|
p = g_list_last (h->widgets);
|
2010-11-10 14:09:42 +03:00
|
|
|
do
|
|
|
|
{
|
2013-06-23 17:30:03 +04:00
|
|
|
Widget *w = WIDGET (p->data);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2016-04-10 12:26:48 +03:00
|
|
|
if (!widget_get_state (w, WST_DISABLED) && w->mouse_callback != NULL)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2011-03-21 16:43:56 +03:00
|
|
|
/* put global cursor position to the widget */
|
|
|
|
int ret;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2016-03-06 09:44:16 +03:00
|
|
|
ret = dlg_mouse_translator (event, w);
|
2011-03-21 16:43:56 +03:00
|
|
|
if (ret != MOU_UNHANDLED)
|
|
|
|
return ret;
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2016-02-23 09:49:58 +03:00
|
|
|
|
|
|
|
p = g_list_previous (p);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2016-02-23 09:49:58 +03:00
|
|
|
while (p != NULL);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2011-03-21 16:43:56 +03:00
|
|
|
return MOU_UNHANDLED;
|
2009-08-16 19:27:33 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static cb_ret_t
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_try_hotkey (WDialog * h, int d_key)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
GList *hot_cur;
|
|
|
|
Widget *current;
|
|
|
|
cb_ret_t handled;
|
|
|
|
int c;
|
1999-01-01 05:04:59 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (h->widgets == NULL)
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
|
|
if (h->current == NULL)
|
|
|
|
h->current = h->widgets;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Explanation: we don't send letter hotkeys to other widgets if
|
|
|
|
* the currently selected widget is an input line
|
|
|
|
*/
|
|
|
|
|
2012-06-20 15:09:44 +04:00
|
|
|
current = WIDGET (h->current->data);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2016-04-10 12:26:48 +03:00
|
|
|
if (widget_get_state (current, WST_DISABLED))
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
2016-04-10 10:49:31 +03:00
|
|
|
if (widget_get_options (current, WOP_IS_INPUT))
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
/* skip ascii control characters, anything else can valid character in
|
|
|
|
* some encoding */
|
|
|
|
if (d_key >= 32 && d_key < 256)
|
|
|
|
return MSG_NOT_HANDLED;
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* If it's an alt key, send the message */
|
|
|
|
c = d_key & ~ALT (0);
|
|
|
|
if (d_key & ALT (0) && g_ascii_isalpha (c))
|
|
|
|
d_key = g_ascii_tolower (c);
|
|
|
|
|
|
|
|
handled = MSG_NOT_HANDLED;
|
2016-04-10 10:49:31 +03:00
|
|
|
if (widget_get_options (current, WOP_WANT_HOTKEY))
|
2012-09-28 15:05:43 +04:00
|
|
|
handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* If not used, send hotkey to other widgets */
|
|
|
|
if (handled == MSG_HANDLED)
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2016-06-18 20:29:46 +03:00
|
|
|
hot_cur = dlg_get_widget_next_of (h->current);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* send it to all widgets */
|
|
|
|
while (h->current != hot_cur && handled == MSG_NOT_HANDLED)
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2012-06-20 15:09:44 +04:00
|
|
|
current = WIDGET (hot_cur->data);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2016-04-10 10:49:31 +03:00
|
|
|
if (widget_get_options (current, WOP_WANT_HOTKEY)
|
2016-04-10 12:26:48 +03:00
|
|
|
&& !widget_get_state (current, WST_DISABLED))
|
2012-09-28 15:05:43 +04:00
|
|
|
handled = send_message (current, NULL, MSG_HOTKEY, d_key, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
if (handled == MSG_NOT_HANDLED)
|
2016-06-18 20:29:46 +03:00
|
|
|
hot_cur = dlg_get_widget_next_of (hot_cur);
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
if (handled == MSG_HANDLED)
|
2016-07-16 21:00:28 +03:00
|
|
|
widget_select (WIDGET (hot_cur->data));
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
return handled;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
static void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_key_event (WDialog * h, int d_key)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
cb_ret_t handled;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-05 20:59:21 +04:00
|
|
|
if (h->widgets == NULL)
|
2010-04-06 11:16:11 +04:00
|
|
|
return;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-05 20:59:21 +04:00
|
|
|
if (h->current == NULL)
|
|
|
|
h->current = h->widgets;
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* TAB used to cycle */
|
2016-05-08 20:25:29 +03:00
|
|
|
if (!widget_get_options (WIDGET (h), WOP_WANT_TAB))
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if (d_key == '\t')
|
|
|
|
{
|
2016-07-16 16:16:23 +03:00
|
|
|
dlg_select_next_widget (h);
|
2010-11-10 14:09:42 +03:00
|
|
|
return;
|
|
|
|
}
|
Handle newline and tab with shift/ctrl modifiers correctly.
MC already has its own half-ready trick: when pasting with Shift-Insert,
using the X11 extension, the newline ("Enter" as mc calls it) with the
Shift modifier pressed gets converted to a "Return", and in the editor
the Return character inserts a non-indenting newline. This makes pasting
better in terminals not supporting bracketed paste, however, it has some
problems that this commit addresses:
* Shift+newline gets this special treatment, but Ctrl+newline gets
dropped. Hence e.g. when pasting in Gnome-terminal with Ctrl+Shift+V
all the newlines will be missing. This commit adds the same
non-indenting newline behavior to Ctrl+Newline and Ctrl+Shift+Newline.
* The code forgets about Tab that also needs special treatment:
- Most terminals send \e[Z on Shift+Tab, this is not handled by MC
at all, moreover it causes a hang for about a second. This commit
teaches this sequence to MC. This is especially useful when no X11
is available, because there Ctrl+Tab is identical to Tab, so the
backwards tab feature is not available. With this commit Shift+Tab
becomes a backwards tab too on all terminals that emit \e[Z.
- When pasting to the editor, Shift+Tab, Ctrl+Tab and Ctrl+Shift+Tab
should all insert a tab for the same reason mentioned at the newline.
- It would look inconsistent in the keymap files to have logical code
such as "backtab" instead of "shift-tab" and friends, hence get rid
of KEY_BTAB and use KEY_M_SHIFT | '\t' instead.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2013-10-01 14:09:14 +04:00
|
|
|
else if ((d_key & ~(KEY_M_SHIFT | KEY_M_CTRL)) == '\t')
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2016-07-16 16:16:23 +03:00
|
|
|
dlg_select_prev_widget (h);
|
2010-11-10 14:09:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-04-05 20:59:21 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* first can dlg_callback handle the key */
|
2012-09-28 15:05:43 +04:00
|
|
|
handled = send_message (h, NULL, MSG_KEY, d_key, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* next try the hotkey */
|
|
|
|
if (handled == MSG_NOT_HANDLED)
|
|
|
|
handled = dlg_try_hotkey (h, d_key);
|
|
|
|
|
|
|
|
if (handled == MSG_HANDLED)
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_HOTKEY_HANDLED, 0, NULL);
|
2003-10-25 03:20:30 +04:00
|
|
|
else
|
2010-11-10 14:09:42 +03:00
|
|
|
/* not used - then try widget_callback */
|
2012-09-28 15:05:43 +04:00
|
|
|
handled = send_message (h->current->data, NULL, MSG_KEY, d_key, NULL);
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* not used- try to use the unhandled case */
|
|
|
|
if (handled == MSG_NOT_HANDLED)
|
2012-09-28 15:05:43 +04:00
|
|
|
handled = send_message (h, NULL, MSG_UNHANDLED_KEY, d_key, NULL);
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (handled == MSG_NOT_HANDLED)
|
|
|
|
handled = dlg_handle_key (h, d_key);
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2013-10-10 16:21:26 +04:00
|
|
|
(void) handled;
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_POST_KEY, d_key, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2013-06-24 11:40:53 +04:00
|
|
|
frontend_dlg_run (WDialog * h)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2016-04-10 20:02:59 +03:00
|
|
|
Widget *wh = WIDGET (h);
|
2010-11-10 14:09:42 +03:00
|
|
|
Gpm_Event event;
|
|
|
|
|
|
|
|
event.x = -1;
|
|
|
|
|
|
|
|
/* close opened editors, viewers, etc */
|
2016-04-16 11:12:49 +03:00
|
|
|
if (!widget_get_state (wh, WST_MODAL) && mc_global.midnight_shutdown)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_VALIDATE, 0, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
while (widget_get_state (wh, WST_ACTIVE))
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2013-10-15 10:34:04 +04:00
|
|
|
int d_key;
|
|
|
|
|
2012-10-31 10:48:56 +04:00
|
|
|
if (mc_global.tty.winch_flag != 0)
|
2011-02-18 14:30:15 +03:00
|
|
|
dialog_change_screen_size ();
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (is_idle ())
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if (idle_hook)
|
|
|
|
execute_hooks (idle_hook);
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
while (widget_get_state (wh, WST_IDLE) && is_idle ())
|
|
|
|
send_message (wh, NULL, MSG_IDLE, 0, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* Allow terminating the dialog from the idle handler */
|
2016-04-10 20:02:59 +03:00
|
|
|
if (!widget_get_state (wh, WST_ACTIVE))
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
2010-04-05 20:59:21 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
update_cursor (h);
|
|
|
|
|
|
|
|
/* Clear interrupt flag */
|
|
|
|
tty_got_interrupt ();
|
|
|
|
d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE);
|
|
|
|
|
|
|
|
dlg_process_event (h, d_key, &event);
|
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
if (widget_get_state (wh, WST_CLOSED))
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_VALIDATE, 0, NULL);
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2011-08-07 18:36:28 +04:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int
|
|
|
|
dlg_find_widget_by_id (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
2016-02-20 17:29:21 +03:00
|
|
|
const Widget *w = CONST_WIDGET (a);
|
2011-08-07 18:36:28 +04:00
|
|
|
unsigned long id = GPOINTER_TO_UINT (b);
|
|
|
|
|
|
|
|
return w->id == id ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2016-06-10 15:53:07 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
static void
|
|
|
|
dlg_widget_set_position (gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
/* there are, mainly, 2 generally possible situations:
|
|
|
|
* 1. control sticks to one side - it should be moved
|
|
|
|
* 2. control sticks to two sides of one direction - it should be sized
|
|
|
|
*/
|
|
|
|
|
|
|
|
Widget *c = WIDGET (data);
|
|
|
|
Widget *wh = WIDGET (c->owner);
|
|
|
|
const widget_shift_scale_t *wss = (const widget_shift_scale_t *) user_data;
|
|
|
|
int x = c->x;
|
|
|
|
int y = c->y;
|
|
|
|
int cols = c->cols;
|
|
|
|
int lines = c->lines;
|
|
|
|
|
|
|
|
if ((c->pos_flags & WPOS_CENTER_HORZ) != 0)
|
|
|
|
x = wh->x + (wh->cols - c->cols) / 2;
|
|
|
|
else if ((c->pos_flags & WPOS_KEEP_LEFT) != 0 && (c->pos_flags & WPOS_KEEP_RIGHT) != 0)
|
|
|
|
{
|
|
|
|
x += wss->shift_x;
|
|
|
|
cols += wss->scale_x;
|
|
|
|
}
|
|
|
|
else if ((c->pos_flags & WPOS_KEEP_LEFT) != 0)
|
|
|
|
x += wss->shift_x;
|
|
|
|
else if ((c->pos_flags & WPOS_KEEP_RIGHT) != 0)
|
|
|
|
x += wss->shift_x + wss->scale_x;
|
|
|
|
|
|
|
|
if ((c->pos_flags & WPOS_CENTER_VERT) != 0)
|
|
|
|
y = wh->y + (wh->lines - c->lines) / 2;
|
|
|
|
else if ((c->pos_flags & WPOS_KEEP_TOP) != 0 && (c->pos_flags & WPOS_KEEP_BOTTOM) != 0)
|
|
|
|
{
|
|
|
|
y += wss->shift_y;
|
|
|
|
lines += wss->scale_y;
|
|
|
|
}
|
|
|
|
else if ((c->pos_flags & WPOS_KEEP_TOP) != 0)
|
|
|
|
y += wss->shift_y;
|
|
|
|
else if ((c->pos_flags & WPOS_KEEP_BOTTOM) != 0)
|
|
|
|
y += wss->shift_y + wss->scale_y;
|
|
|
|
|
|
|
|
widget_set_size (c, y, x, lines, cols);
|
|
|
|
}
|
|
|
|
|
2016-06-10 15:39:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2016-08-09 10:04:46 +03:00
|
|
|
dlg_adjust_position (widget_pos_flags_t pos_flags, int *y, int *x, int *lines, int *cols)
|
2016-06-10 15:39:28 +03:00
|
|
|
{
|
2016-08-09 10:04:46 +03:00
|
|
|
if ((pos_flags & WPOS_FULLSCREEN) != 0)
|
2016-06-10 15:39:28 +03:00
|
|
|
{
|
|
|
|
*y = 0;
|
|
|
|
*x = 0;
|
|
|
|
*lines = LINES;
|
|
|
|
*cols = COLS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-09 10:04:46 +03:00
|
|
|
if ((pos_flags & WPOS_CENTER_HORZ) != 0)
|
2016-06-10 15:39:28 +03:00
|
|
|
*x = (COLS - *cols) / 2;
|
|
|
|
|
2016-08-09 10:04:46 +03:00
|
|
|
if ((pos_flags & WPOS_CENTER_VERT) != 0)
|
2016-06-10 15:39:28 +03:00
|
|
|
*y = (LINES - *lines) / 2;
|
|
|
|
|
2016-08-09 10:04:46 +03:00
|
|
|
if ((pos_flags & WPOS_TRYUP) != 0)
|
2016-06-10 15:39:28 +03:00
|
|
|
{
|
|
|
|
if (*y > 3)
|
|
|
|
*y -= 2;
|
|
|
|
else if (*y == 3)
|
|
|
|
*y = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** Clean the dialog area, draw the frame and the title */
|
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_default_repaint (WDialog * h)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2012-06-20 12:05:13 +04:00
|
|
|
Widget *wh = WIDGET (h);
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
int space;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
if (!widget_get_state (wh, WST_ACTIVE))
|
2010-11-10 14:09:42 +03:00
|
|
|
return;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2016-05-08 21:10:05 +03:00
|
|
|
space = h->compact ? 0 : 1;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
|
|
|
|
dlg_erase (h);
|
2013-04-23 14:10:20 +04:00
|
|
|
tty_draw_box (wh->y + space, wh->x + space, wh->lines - 2 * space, wh->cols - 2 * space, FALSE);
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (h->title != NULL)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
tty_setcolor (h->color[DLG_COLOR_TITLE]);
|
2012-06-20 12:05:13 +04:00
|
|
|
widget_move (h, space, (wh->cols - str_term_width1 (h->title)) / 2);
|
2010-11-10 14:09:42 +03:00
|
|
|
tty_print_string (h->title);
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** this function allows to set dialog position */
|
2003-11-27 03:17:43 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
void
|
2016-06-02 16:12:24 +03:00
|
|
|
dlg_set_position (WDialog * h, int y, int x, int lines, int cols)
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2012-06-20 12:05:13 +04:00
|
|
|
Widget *wh = WIDGET (h);
|
2016-06-10 15:53:07 +03:00
|
|
|
widget_shift_scale_t wss;
|
2012-06-20 12:05:13 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* save old positions, will be used to reposition childs */
|
|
|
|
int ox, oy, oc, ol;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* save old positions, will be used to reposition childs */
|
2012-06-20 12:05:13 +04:00
|
|
|
ox = wh->x;
|
|
|
|
oy = wh->y;
|
|
|
|
oc = wh->cols;
|
|
|
|
ol = wh->lines;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2016-06-02 16:12:24 +03:00
|
|
|
wh->x = x;
|
|
|
|
wh->y = y;
|
|
|
|
wh->lines = lines;
|
|
|
|
wh->cols = cols;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* dialog is empty */
|
|
|
|
if (h->widgets == NULL)
|
|
|
|
return;
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (h->current == NULL)
|
|
|
|
h->current = h->widgets;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* values by which controls should be moved */
|
2016-06-10 15:53:07 +03:00
|
|
|
wss.shift_x = wh->x - ox;
|
|
|
|
wss.scale_x = wh->cols - oc;
|
|
|
|
wss.shift_y = wh->y - oy;
|
|
|
|
wss.scale_y = wh->lines - ol;
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2016-06-10 15:53:07 +03:00
|
|
|
if (wss.shift_x != 0 || wss.shift_y != 0 || wss.scale_x != 0 || wss.scale_y != 0)
|
|
|
|
g_list_foreach (h->widgets, dlg_widget_set_position, &wss);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2014-02-22 15:07:20 +04:00
|
|
|
/** Set dialog size and position */
|
2003-11-27 11:59:54 +03:00
|
|
|
|
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_set_size (WDialog * h, int lines, int cols)
|
2003-11-27 11:59:54 +03:00
|
|
|
{
|
2016-06-10 15:39:28 +03:00
|
|
|
int x = 0, y = 0;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2016-08-09 10:04:46 +03:00
|
|
|
dlg_adjust_position (WIDGET (h)->pos_flags, &y, &x, &lines, &cols);
|
2016-06-02 16:12:24 +03:00
|
|
|
dlg_set_position (h, y, x, lines, cols);
|
2003-11-27 11:59:54 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Default dialog callback */
|
|
|
|
|
|
|
|
cb_ret_t
|
2012-09-28 15:05:43 +04:00
|
|
|
dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
2003-11-27 11:59:54 +03:00
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
WDialog *h = DIALOG (w);
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
(void) sender;
|
|
|
|
(void) parm;
|
|
|
|
(void) data;
|
|
|
|
|
|
|
|
switch (msg)
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_DRAW:
|
2010-11-10 14:09:42 +03:00
|
|
|
if (h->color != NULL)
|
|
|
|
{
|
2012-09-28 11:05:23 +04:00
|
|
|
dlg_default_repaint (h);
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
return MSG_NOT_HANDLED;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_IDLE:
|
2016-04-10 12:35:43 +03:00
|
|
|
/* we don't want endless loop */
|
|
|
|
widget_idle (w, FALSE);
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
case MSG_RESIZE:
|
2010-11-10 14:09:42 +03:00
|
|
|
/* this is default resizing mechanism */
|
|
|
|
/* the main idea of this code is to resize dialog
|
|
|
|
according to flags (if any of flags require automatic
|
2016-05-08 21:10:05 +03:00
|
|
|
resizing, like WPOS_CENTER, end after that reposition
|
2010-11-10 14:09:42 +03:00
|
|
|
controls in dialog according to flags of widget) */
|
2013-06-23 17:24:14 +04:00
|
|
|
dlg_set_size (h, w->lines, w->cols);
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-04-05 20:59:21 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
return MSG_NOT_HANDLED;
|
2003-11-27 11:59:54 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2012-09-28 11:18:45 +04:00
|
|
|
WDialog *
|
2016-05-08 21:10:05 +03:00
|
|
|
dlg_create (gboolean modal, int y1, int x1, int lines, int cols, widget_pos_flags_t pos_flags,
|
|
|
|
gboolean compact, const int *colors, widget_cb_fn callback,
|
|
|
|
widget_mouse_cb_fn mouse_callback, const char *help_ctx, const char *title)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2012-09-28 11:18:45 +04:00
|
|
|
WDialog *new_d;
|
2012-06-20 12:05:13 +04:00
|
|
|
Widget *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2012-09-28 11:18:45 +04:00
|
|
|
new_d = g_new0 (WDialog, 1);
|
2012-06-20 12:05:13 +04:00
|
|
|
w = WIDGET (new_d);
|
2016-08-09 10:04:46 +03:00
|
|
|
dlg_adjust_position (pos_flags, &y1, &x1, &lines, &cols);
|
2013-06-24 11:40:53 +04:00
|
|
|
widget_init (w, y1, x1, lines, cols, (callback != NULL) ? callback : dlg_default_callback,
|
2016-03-06 09:44:16 +03:00
|
|
|
mouse_callback);
|
2016-08-09 10:04:46 +03:00
|
|
|
w->pos_flags = pos_flags;
|
2016-06-07 15:03:20 +03:00
|
|
|
w->options |= WOP_SELECTABLE | WOP_TOP_SELECT;
|
2016-04-16 11:12:49 +03:00
|
|
|
|
2016-06-12 18:15:02 +03:00
|
|
|
w->state |= WST_CONSTRUCT | WST_FOCUSED;
|
2016-04-16 11:12:49 +03:00
|
|
|
if (modal)
|
|
|
|
w->state |= WST_MODAL;
|
2012-06-20 12:05:13 +04:00
|
|
|
|
2014-02-08 19:37:11 +04:00
|
|
|
new_d->color = colors;
|
2010-11-10 14:09:42 +03:00
|
|
|
new_d->help_ctx = help_ctx;
|
2016-05-08 21:10:05 +03:00
|
|
|
new_d->compact = compact;
|
2010-11-10 14:09:42 +03:00
|
|
|
new_d->data = NULL;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2011-03-21 16:43:56 +03:00
|
|
|
new_d->mouse_status = MOU_UNHANDLED;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* Strip existing spaces, add one space before and after the title */
|
2012-09-20 12:48:14 +04:00
|
|
|
if (title != NULL && *title != '\0')
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
|
|
|
char *t;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
t = g_strstrip (g_strdup (title));
|
|
|
|
if (*t != '\0')
|
|
|
|
new_d->title = g_strdup_printf (" %s ", t);
|
|
|
|
g_free (t);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2013-08-13 10:58:10 +04:00
|
|
|
/* unique name of event group for this dialog */
|
2011-05-01 15:42:17 +04:00
|
|
|
new_d->event_group = g_strdup_printf ("%s_%p", MCEVENT_GROUP_DIALOG, (void *) new_d);
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return new_d;
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-11-08 12:43:37 +03:00
|
|
|
void
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_set_default_colors (void)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
dialog_colors[DLG_COLOR_NORMAL] = COLOR_NORMAL;
|
|
|
|
dialog_colors[DLG_COLOR_FOCUS] = COLOR_FOCUS;
|
|
|
|
dialog_colors[DLG_COLOR_HOT_NORMAL] = COLOR_HOT_NORMAL;
|
|
|
|
dialog_colors[DLG_COLOR_HOT_FOCUS] = COLOR_HOT_FOCUS;
|
|
|
|
dialog_colors[DLG_COLOR_TITLE] = COLOR_TITLE;
|
2010-06-05 18:48:06 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
alarm_colors[DLG_COLOR_NORMAL] = ERROR_COLOR;
|
|
|
|
alarm_colors[DLG_COLOR_FOCUS] = ERROR_FOCUS;
|
|
|
|
alarm_colors[DLG_COLOR_HOT_NORMAL] = ERROR_HOT_NORMAL;
|
|
|
|
alarm_colors[DLG_COLOR_HOT_FOCUS] = ERROR_HOT_FOCUS;
|
|
|
|
alarm_colors[DLG_COLOR_TITLE] = ERROR_TITLE;
|
2014-02-08 19:37:11 +04:00
|
|
|
|
|
|
|
listbox_colors[DLG_COLOR_NORMAL] = PMENU_ENTRY_COLOR;
|
|
|
|
listbox_colors[DLG_COLOR_FOCUS] = PMENU_SELECTED_COLOR;
|
|
|
|
listbox_colors[DLG_COLOR_HOT_NORMAL] = PMENU_ENTRY_COLOR;
|
|
|
|
listbox_colors[DLG_COLOR_HOT_FOCUS] = PMENU_SELECTED_COLOR;
|
|
|
|
listbox_colors[DLG_COLOR_TITLE] = PMENU_TITLE_COLOR;
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-11-08 12:43:37 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_erase (WDialog * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2016-04-10 20:02:59 +03:00
|
|
|
Widget *wh = WIDGET (h);
|
2012-06-20 12:05:13 +04:00
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
if (wh != NULL && widget_get_state (wh, WST_ACTIVE))
|
2012-06-20 12:05:13 +04:00
|
|
|
tty_fill_region (wh->y, wh->x, wh->lines, wh->cols, ' ');
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
2011-04-17 14:21:17 +04:00
|
|
|
* Insert widget to dialog before requested widget. Make the widget current. Return widget ID.
|
2010-11-10 14:09:42 +03:00
|
|
|
*/
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2011-04-17 14:21:17 +04:00
|
|
|
unsigned long
|
2012-09-28 11:18:45 +04:00
|
|
|
add_widget_autopos (WDialog * h, void *w, widget_pos_flags_t pos_flags, const void *before)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2012-09-26 15:16:24 +04:00
|
|
|
Widget *wh = WIDGET (h);
|
2012-11-28 11:19:02 +04:00
|
|
|
Widget *widget;
|
2017-01-30 22:06:13 +03:00
|
|
|
GList *new_current;
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* Don't accept 0 widgets */
|
|
|
|
if (w == NULL)
|
|
|
|
abort ();
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2012-11-28 11:19:02 +04:00
|
|
|
widget = WIDGET (w);
|
|
|
|
|
2012-09-26 15:16:24 +04:00
|
|
|
if ((pos_flags & WPOS_CENTER_HORZ) != 0)
|
|
|
|
widget->x = (wh->cols - widget->cols) / 2;
|
|
|
|
widget->x += wh->x;
|
|
|
|
|
|
|
|
if ((pos_flags & WPOS_CENTER_VERT) != 0)
|
|
|
|
widget->y = (wh->lines - widget->lines) / 2;
|
|
|
|
widget->y += wh->y;
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
widget->owner = h;
|
|
|
|
widget->pos_flags = pos_flags;
|
2011-04-17 14:12:07 +04:00
|
|
|
widget->id = h->widget_id++;
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2012-09-24 14:22:33 +04:00
|
|
|
if (h->widgets == NULL || before == NULL)
|
2011-04-17 14:21:17 +04:00
|
|
|
{
|
2012-09-24 14:22:33 +04:00
|
|
|
h->widgets = g_list_append (h->widgets, widget);
|
2017-01-30 22:06:13 +03:00
|
|
|
new_current = g_list_last (h->widgets);
|
2011-04-17 14:21:17 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
else
|
2011-04-17 14:21:17 +04:00
|
|
|
{
|
2012-09-24 14:22:33 +04:00
|
|
|
GList *b;
|
2011-04-17 14:21:17 +04:00
|
|
|
|
2012-09-24 14:22:33 +04:00
|
|
|
b = g_list_find (h->widgets, before);
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2012-09-24 14:22:33 +04:00
|
|
|
/* don't accept widget not from dialog. This shouldn't happen */
|
|
|
|
if (b == NULL)
|
|
|
|
abort ();
|
2011-04-17 14:21:17 +04:00
|
|
|
|
2012-09-24 14:22:33 +04:00
|
|
|
b = g_list_next (b);
|
|
|
|
h->widgets = g_list_insert_before (h->widgets, b, widget);
|
|
|
|
if (b != NULL)
|
2017-01-30 22:06:13 +03:00
|
|
|
new_current = g_list_previous (b);
|
2012-09-24 14:22:33 +04:00
|
|
|
else
|
2017-01-30 22:06:13 +03:00
|
|
|
new_current = g_list_last (h->widgets);
|
2011-04-17 14:21:17 +04:00
|
|
|
}
|
|
|
|
|
2017-01-30 22:06:13 +03:00
|
|
|
/* widget has been added at runtime */
|
2016-04-10 20:02:59 +03:00
|
|
|
if (widget_get_state (wh, WST_ACTIVE))
|
2011-04-17 14:21:17 +04:00
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (widget, NULL, MSG_INIT, 0, NULL);
|
2017-01-30 22:06:13 +03:00
|
|
|
widget_select (widget);
|
2011-04-17 14:21:17 +04:00
|
|
|
}
|
2017-01-30 22:06:13 +03:00
|
|
|
else
|
|
|
|
h->current = new_current;
|
2010-05-06 23:19:02 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return widget->id;
|
2010-05-06 23:19:02 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** wrapper to simply add lefttop positioned controls */
|
|
|
|
|
2011-04-17 14:21:17 +04:00
|
|
|
unsigned long
|
2012-09-28 11:18:45 +04:00
|
|
|
add_widget (WDialog * h, void *w)
|
2010-05-06 23:19:02 +04:00
|
|
|
{
|
2012-09-26 15:16:24 +04:00
|
|
|
return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT,
|
2011-04-17 14:21:17 +04:00
|
|
|
h->current != NULL ? h->current->data : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
unsigned long
|
2012-09-28 11:18:45 +04:00
|
|
|
add_widget_before (WDialog * h, void *w, void *before)
|
2011-04-17 14:21:17 +04:00
|
|
|
{
|
2012-09-26 15:16:24 +04:00
|
|
|
return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, before);
|
2011-04-17 14:21:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** delete widget from dialog */
|
|
|
|
void
|
|
|
|
del_widget (void *w)
|
|
|
|
{
|
2012-11-28 11:19:02 +04:00
|
|
|
WDialog *h;
|
2011-04-17 14:21:17 +04:00
|
|
|
GList *d;
|
|
|
|
|
|
|
|
/* Don't accept NULL widget. This shouldn't happen */
|
|
|
|
if (w == NULL)
|
|
|
|
abort ();
|
|
|
|
|
2012-11-28 11:19:02 +04:00
|
|
|
h = WIDGET (w)->owner;
|
|
|
|
|
2011-04-17 14:21:17 +04:00
|
|
|
d = g_list_find (h->widgets, w);
|
|
|
|
if (d == h->current)
|
2016-06-18 20:29:46 +03:00
|
|
|
dlg_set_current_widget_next (h);
|
2011-04-17 14:21:17 +04:00
|
|
|
|
|
|
|
h->widgets = g_list_remove_link (h->widgets, d);
|
2016-07-16 21:00:28 +03:00
|
|
|
if (h->widgets == NULL)
|
|
|
|
h->current = NULL;
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (d->data, NULL, MSG_DESTROY, 0, NULL);
|
2012-12-13 14:40:07 +04:00
|
|
|
g_free (d->data);
|
2011-04-17 14:21:17 +04:00
|
|
|
g_list_free_1 (d);
|
|
|
|
|
|
|
|
/* widget has been deleted in runtime */
|
2016-04-10 20:02:59 +03:00
|
|
|
if (widget_get_state (WIDGET (h), WST_ACTIVE))
|
2011-04-17 14:21:17 +04:00
|
|
|
{
|
|
|
|
dlg_redraw (h);
|
2016-07-16 21:00:28 +03:00
|
|
|
dlg_select_current_widget (h);
|
2011-04-17 14:21:17 +04:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
do_refresh (void)
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
GList *d = top_dlg;
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (fast_refresh)
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((d != NULL) && (d->data != NULL))
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_redraw (DIALOG (d->data));
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
else
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
/* Search first fullscreen dialog */
|
|
|
|
for (; d != NULL; d = g_list_next (d))
|
2016-05-08 21:10:05 +03:00
|
|
|
if (d->data != NULL && (WIDGET (d->data)->pos_flags & WPOS_FULLSCREEN) != 0)
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
|
|
|
/* back to top dialog */
|
|
|
|
for (; d != NULL; d = g_list_previous (d))
|
|
|
|
if (d->data != NULL)
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_redraw (DIALOG (d->data));
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
|
|
|
}
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** broadcast a message to all the widgets in a dialog */
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_broadcast_msg (WDialog * h, widget_msg_t msg)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2012-09-24 14:22:33 +04:00
|
|
|
dlg_broadcast_msg_to (h, msg, FALSE, 0);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Find the widget with the given callback in the dialog h */
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
Widget *
|
2012-09-28 11:18:45 +04:00
|
|
|
find_widget_type (const WDialog * h, widget_cb_fn callback)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
|
|
|
GList *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2016-03-15 22:03:19 +03:00
|
|
|
w = g_list_find_custom (h->widgets, (gconstpointer) callback, dlg_find_widget_callback);
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2012-06-20 15:09:44 +04:00
|
|
|
return (w == NULL) ? NULL : WIDGET (w->data);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2016-07-16 21:00:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
GList *
|
|
|
|
dlg_find (const WDialog * h, const Widget * w)
|
|
|
|
{
|
|
|
|
return (w->owner == NULL || w->owner != h) ? NULL : g_list_find (h->widgets, w);
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Find the widget with the given id */
|
|
|
|
|
|
|
|
Widget *
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_find_by_id (const WDialog * h, unsigned long id)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2011-08-07 18:36:28 +04:00
|
|
|
GList *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2011-08-07 18:36:28 +04:00
|
|
|
w = g_list_find_custom (h->widgets, GUINT_TO_POINTER (id), dlg_find_widget_by_id);
|
2012-06-20 15:09:44 +04:00
|
|
|
return w != NULL ? WIDGET (w->data) : NULL;
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Find the widget with the given id in the dialog h and select it */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_select_by_id (const WDialog * h, unsigned long id)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
|
|
|
Widget *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
w = dlg_find_by_id (h, id);
|
|
|
|
if (w != NULL)
|
2016-08-09 09:35:27 +03:00
|
|
|
widget_select (w);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Try to select previous widget in the tab order */
|
|
|
|
|
|
|
|
void
|
2016-07-16 16:16:23 +03:00
|
|
|
dlg_select_prev_widget (WDialog * h)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2016-07-16 21:00:28 +03:00
|
|
|
dlg_select_next_or_prev (h, FALSE);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Try to select next widget in the tab order */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
void
|
2016-07-16 16:16:23 +03:00
|
|
|
dlg_select_next_widget (WDialog * h)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2016-07-16 21:00:28 +03:00
|
|
|
dlg_select_next_or_prev (h, TRUE);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
update_cursor (WDialog * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
GList *p = h->current;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
if (p != NULL && widget_get_state (WIDGET (h), WST_ACTIVE))
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
|
|
|
Widget *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2012-06-20 15:09:44 +04:00
|
|
|
w = WIDGET (p->data);
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2016-04-10 12:26:48 +03:00
|
|
|
if (!widget_get_state (w, WST_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR))
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (w, NULL, MSG_CURSOR, 0, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
else
|
|
|
|
do
|
|
|
|
{
|
2016-06-18 20:29:46 +03:00
|
|
|
p = dlg_get_widget_next_of (p);
|
2010-11-10 14:09:42 +03:00
|
|
|
if (p == h->current)
|
|
|
|
break;
|
|
|
|
|
2012-06-20 15:09:44 +04:00
|
|
|
w = WIDGET (p->data);
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2016-04-10 12:26:48 +03:00
|
|
|
if (!widget_get_state (w, WST_DISABLED) && widget_get_options (w, WOP_WANT_CURSOR)
|
2016-04-10 10:49:31 +03:00
|
|
|
&& send_message (w, NULL, MSG_CURSOR, 0, NULL) == MSG_HANDLED)
|
|
|
|
break;
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
|
|
|
while (TRUE);
|
2003-10-25 04:22:13 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Redraw the widgets in reverse order, leaving the current widget
|
|
|
|
* as the last one
|
|
|
|
*/
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_redraw (WDialog * h)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2016-04-10 20:02:59 +03:00
|
|
|
if (!widget_get_state (WIDGET (h), WST_ACTIVE))
|
2010-11-10 14:09:42 +03:00
|
|
|
return;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (h->winch_pending)
|
|
|
|
{
|
|
|
|
h->winch_pending = FALSE;
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_RESIZE, 0, NULL);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_DRAW, 0, NULL);
|
|
|
|
dlg_broadcast_msg (h, MSG_DRAW);
|
2010-11-10 14:09:42 +03:00
|
|
|
update_cursor (h);
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_stop (WDialog * h)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2016-04-10 20:02:59 +03:00
|
|
|
widget_set_state (WIDGET (h), WST_CLOSED, TRUE);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Init the process */
|
|
|
|
|
2009-11-08 12:43:37 +03:00
|
|
|
void
|
2013-06-24 11:40:53 +04:00
|
|
|
dlg_init (WDialog * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2016-04-10 20:02:59 +03:00
|
|
|
Widget *wh = WIDGET (h);
|
|
|
|
|
2016-04-16 11:12:49 +03:00
|
|
|
if (top_dlg != NULL && widget_get_state (WIDGET (top_dlg->data), WST_MODAL))
|
|
|
|
widget_set_state (wh, WST_MODAL, TRUE);
|
2009-11-19 11:34:20 +03:00
|
|
|
|
2009-10-30 14:50:04 +03:00
|
|
|
/* add dialog to the stack */
|
2010-04-18 14:26:28 +04:00
|
|
|
top_dlg = g_list_prepend (top_dlg, h);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2009-10-30 14:50:04 +03:00
|
|
|
/* Initialize dialog manager and widgets */
|
2016-04-10 20:02:59 +03:00
|
|
|
if (widget_get_state (wh, WST_CONSTRUCT))
|
2010-04-18 14:58:18 +04:00
|
|
|
{
|
2016-04-16 11:12:49 +03:00
|
|
|
if (!widget_get_state (wh, WST_MODAL))
|
2010-04-18 14:58:18 +04:00
|
|
|
dialog_switch_add (h);
|
|
|
|
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, NULL, MSG_INIT, 0, NULL);
|
|
|
|
dlg_broadcast_msg (h, MSG_INIT);
|
2011-05-03 17:24:56 +04:00
|
|
|
dlg_read_history (h);
|
2010-04-18 14:58:18 +04:00
|
|
|
}
|
|
|
|
|
2016-07-16 21:00:28 +03:00
|
|
|
/* Select the first widget that takes focus */
|
|
|
|
while (h->current != NULL && !widget_get_options (WIDGET (h->current->data), WOP_SELECTABLE)
|
|
|
|
&& !widget_get_state (WIDGET (h->current->data), WST_DISABLED))
|
|
|
|
dlg_set_current_widget_next (h);
|
2012-04-08 16:29:46 +04:00
|
|
|
|
2016-07-16 21:00:28 +03:00
|
|
|
widget_set_state (wh, WST_ACTIVE, TRUE);
|
2013-09-28 21:36:37 +04:00
|
|
|
dlg_redraw (h);
|
2016-07-16 21:00:28 +03:00
|
|
|
/* focus found widget */
|
|
|
|
widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE);
|
2011-04-17 14:21:17 +04:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
h->ret_value = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-11-08 12:43:37 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_process_event (WDialog * h, int key, Gpm_Event * event)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
|
|
|
if (key == EV_NONE)
|
|
|
|
{
|
|
|
|
if (tty_got_interrupt ())
|
2012-09-28 15:05:43 +04:00
|
|
|
if (send_message (h, NULL, MSG_ACTION, CK_Cancel, NULL) != MSG_HANDLED)
|
2011-03-28 16:45:50 +04:00
|
|
|
dlg_execute_cmd (h, CK_Cancel);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
2016-03-06 09:44:16 +03:00
|
|
|
else if (key == EV_MOUSE)
|
2010-04-06 11:16:11 +04:00
|
|
|
h->mouse_status = dlg_mouse_event (h, event);
|
2003-10-25 03:20:30 +04:00
|
|
|
else
|
2010-04-06 11:16:11 +04:00
|
|
|
dlg_key_event (h, key);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2013-06-24 11:40:53 +04:00
|
|
|
/** Shutdown the dlg_run */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2009-10-30 14:50:04 +03:00
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_run_done (WDialog * h)
|
2009-10-30 14:50:04 +03:00
|
|
|
{
|
2010-09-20 13:58:17 +04:00
|
|
|
top_dlg = g_list_remove (top_dlg, h);
|
|
|
|
|
2016-04-10 20:02:59 +03:00
|
|
|
if (widget_get_state (WIDGET (h), WST_CLOSED))
|
2010-04-18 14:58:18 +04:00
|
|
|
{
|
2012-09-28 15:05:43 +04:00
|
|
|
send_message (h, h->current->data, MSG_END, 0, NULL);
|
2016-04-16 11:12:49 +03:00
|
|
|
if (!widget_get_state (WIDGET (h), WST_MODAL))
|
2010-04-18 14:58:18 +04:00
|
|
|
dialog_switch_remove (h);
|
|
|
|
}
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Standard run dialog routine
|
2003-10-25 03:20:30 +04:00
|
|
|
* We have to keep this routine small so that we can duplicate it's
|
|
|
|
* behavior on complex routines like the file routines, this way,
|
|
|
|
* they can call the dlg_process_event without rewriting all the code
|
|
|
|
*/
|
2010-11-10 14:09:42 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
int
|
2013-06-24 11:40:53 +04:00
|
|
|
dlg_run (WDialog * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2013-06-24 11:40:53 +04:00
|
|
|
dlg_init (h);
|
|
|
|
frontend_dlg_run (h);
|
2003-10-25 03:20:30 +04:00
|
|
|
dlg_run_done (h);
|
|
|
|
return h->ret_value;
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
void
|
2013-06-24 11:40:53 +04:00
|
|
|
dlg_destroy (WDialog * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2011-05-02 13:44:47 +04:00
|
|
|
/* if some widgets have history, save all history at one moment here */
|
|
|
|
dlg_save_history (h);
|
2012-09-28 15:05:43 +04:00
|
|
|
dlg_broadcast_msg (h, MSG_DESTROY);
|
2013-11-04 12:09:13 +04:00
|
|
|
g_list_free_full (h->widgets, g_free);
|
2011-05-01 15:42:17 +04:00
|
|
|
mc_event_group_del (h->event_group);
|
|
|
|
g_free (h->event_group);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (h->title);
|
|
|
|
g_free (h);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
do_refresh ();
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-05-02 13:44:47 +04:00
|
|
|
/**
|
|
|
|
* Write history to the ${XDG_CACHE_HOME}/mc/history file
|
|
|
|
*/
|
|
|
|
void
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_save_history (WDialog * h)
|
2011-05-02 13:44:47 +04:00
|
|
|
{
|
|
|
|
char *profile;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (num_history_items_recorded == 0) /* this is how to disable */
|
|
|
|
return;
|
|
|
|
|
2011-11-24 02:28:07 +04:00
|
|
|
profile = mc_config_get_full_path (MC_HISTORY_FILE);
|
2011-05-02 13:44:47 +04:00
|
|
|
i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
|
|
|
|
if (i != -1)
|
|
|
|
close (i);
|
|
|
|
|
|
|
|
/* Make sure the history is only readable by the user */
|
|
|
|
if (chmod (profile, S_IRUSR | S_IWUSR) != -1 || errno == ENOENT)
|
|
|
|
{
|
|
|
|
ev_history_load_save_t event_data;
|
|
|
|
|
2012-07-28 14:19:27 +04:00
|
|
|
event_data.cfg = mc_config_init (profile, FALSE);
|
2011-05-02 13:44:47 +04:00
|
|
|
event_data.receiver = NULL;
|
|
|
|
|
|
|
|
/* get all histories in dialog */
|
|
|
|
mc_event_raise (h->event_group, MCEVENT_HISTORY_SAVE, &event_data);
|
|
|
|
|
|
|
|
mc_config_save_file (event_data.cfg, NULL);
|
|
|
|
mc_config_deinit (event_data.cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (profile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2010-04-18 14:23:06 +04:00
|
|
|
char *
|
2012-09-28 11:18:45 +04:00
|
|
|
dlg_get_title (const WDialog * h, size_t len)
|
2010-04-18 14:23:06 +04:00
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
if (h == NULL)
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
if (h->get_title != NULL)
|
|
|
|
t = h->get_title (h, len);
|
|
|
|
else
|
|
|
|
t = g_strdup ("");
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2016-06-18 20:29:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch current widget to widget after current in dialog.
|
|
|
|
*
|
|
|
|
* @param h WDialog widget
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
dlg_set_current_widget_next (WDialog * h)
|
|
|
|
{
|
|
|
|
h->current = dlg_get_next_or_prev_of (h->current, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch current widget to widget before current in dialog.
|
|
|
|
*
|
|
|
|
* @param h WDialog widget
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
dlg_set_current_widget_prev (WDialog * h)
|
|
|
|
{
|
|
|
|
h->current = dlg_get_next_or_prev_of (h->current, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get widget that is after specified widget in dialog.
|
|
|
|
*
|
|
|
|
* @param w widget holder
|
|
|
|
*
|
|
|
|
* @return widget that is after "w" or NULL if "w" is NULL or widget doesn't have owner
|
|
|
|
*/
|
|
|
|
|
|
|
|
GList *
|
|
|
|
dlg_get_widget_next_of (GList * w)
|
|
|
|
{
|
|
|
|
return dlg_get_next_or_prev_of (w, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get widget that is before specified widget in dialog.
|
|
|
|
*
|
|
|
|
* @param w widget holder
|
|
|
|
*
|
|
|
|
* @return widget that is before "w" or NULL if "w" is NULL or widget doesn't have owner
|
|
|
|
*/
|
|
|
|
|
|
|
|
GList *
|
|
|
|
dlg_get_widget_prev_of (GList * w)
|
|
|
|
{
|
|
|
|
return dlg_get_next_or_prev_of (w, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|