2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Dialog box features module for the Midnight Commander
|
|
|
|
|
2007-09-26 14:22:25 +04:00
|
|
|
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
2011-10-15 14:56:47 +04:00
|
|
|
2005, 2007, 2009, 2010, 2011
|
|
|
|
The Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
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>
|
|
|
|
#include <fcntl.h> /* open() */
|
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/mouse.h"
|
|
|
|
#include "lib/tty/key.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2010-11-12 11:03:57 +03:00
|
|
|
#include "lib/widget.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
|
|
|
|
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;
|
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 */
|
|
|
|
int fast_refresh = 0;
|
|
|
|
|
2009-04-03 19:29:20 +04:00
|
|
|
/* left click outside of dialog closes it */
|
|
|
|
int mouse_close_dialog = 0;
|
|
|
|
|
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
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/** What to do if the requested widget doesn't take focus */
|
|
|
|
typedef enum
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
SELECT_NEXT, /* go the the next widget */
|
|
|
|
SELECT_PREV, /* go the the previous widget */
|
|
|
|
SELECT_EXACT /* use current widget */
|
|
|
|
} select_dir_t;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2010-09-01 14:28:10 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
2011-07-18 13:27:01 +04:00
|
|
|
|
|
|
|
static GList *
|
2011-10-15 14:56:47 +04:00
|
|
|
dlg_widget_next (Dlg_head * h, GList * l)
|
2011-07-18 13:27:01 +04:00
|
|
|
{
|
|
|
|
GList *next;
|
|
|
|
|
|
|
|
next = g_list_next (l);
|
|
|
|
if (next == NULL)
|
|
|
|
next = h->widgets;
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static GList *
|
2011-10-15 14:56:47 +04:00
|
|
|
dlg_widget_prev (Dlg_head * h, GList * l)
|
2011-07-18 13:27:01 +04:00
|
|
|
{
|
|
|
|
GList *prev;
|
|
|
|
|
|
|
|
prev = g_list_previous (l);
|
|
|
|
if (prev == NULL)
|
|
|
|
prev = g_list_last (h->widgets);
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
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
|
2010-11-12 11:03:57 +03:00
|
|
|
dlg_broadcast_msg_to (Dlg_head * h, widget_msg_t msg, gboolean reverse, int 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;
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (reverse)
|
2011-07-18 13:27:01 +04:00
|
|
|
p = dlg_widget_prev (h, h->current);
|
2010-11-10 14:09:42 +03:00
|
|
|
else
|
2011-07-18 13:27:01 +04:00
|
|
|
p = dlg_widget_next (h, h->current);
|
2010-04-06 11:16:11 +04:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
Widget *w = (Widget *) p->data;
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (reverse)
|
2011-07-18 13:27:01 +04:00
|
|
|
p = dlg_widget_prev (h, p);
|
2010-11-10 14:09:42 +03:00
|
|
|
else
|
2011-07-18 13:27:01 +04:00
|
|
|
p = dlg_widget_next (h, p);
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((flags == 0) || ((flags & w->options) != 0))
|
2010-11-12 11:03:57 +03:00
|
|
|
send_message (w, msg, 0);
|
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
|
|
|
|
dlg_read_history (Dlg_head * h)
|
|
|
|
{
|
|
|
|
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);
|
2011-05-03 17:24:56 +04:00
|
|
|
event_data.cfg = mc_config_init (profile);
|
|
|
|
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_unfocus (Dlg_head * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
/* ... but can unfocus disabled widget */
|
2005-02-08 21:25:31 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((h->current != NULL) && (h->state == DLG_ACTIVE))
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
Widget *current = (Widget *) h->current->data;
|
|
|
|
|
|
|
|
if (send_message (current, WIDGET_UNFOCUS, 0) == MSG_HANDLED)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
h->callback (h, current, DLG_UNFOCUS, 0, NULL);
|
|
|
|
return 1;
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
static int
|
|
|
|
dlg_find_widget_callback (const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const Widget *w = (const Widget *) a;
|
|
|
|
callback_fn f = (callback_fn) 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
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Try to select another widget. If forward is set, follow tab order.
|
|
|
|
* Otherwise go to the previous widget.
|
|
|
|
*/
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
static void
|
|
|
|
do_select_widget (Dlg_head * h, GList * w, select_dir_t dir)
|
|
|
|
{
|
|
|
|
Widget *w0 = (Widget *) h->current->data;
|
2009-08-16 19:27:33 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (!dlg_unfocus (h))
|
|
|
|
return;
|
2010-04-03 15:19:09 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
h->current = w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
do
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if (dlg_focus (h))
|
|
|
|
break;
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
switch (dir)
|
|
|
|
{
|
2011-05-04 17:07:25 +04:00
|
|
|
case SELECT_EXACT:
|
|
|
|
h->current = g_list_find (h->widgets, w0);
|
|
|
|
if (dlg_focus (h))
|
|
|
|
return;
|
|
|
|
/* try find another widget that can take focus */
|
|
|
|
dir = SELECT_NEXT;
|
|
|
|
/* fallthrough */
|
2010-11-10 14:09:42 +03:00
|
|
|
case SELECT_NEXT:
|
2011-07-18 13:27:01 +04:00
|
|
|
h->current = dlg_widget_next (h, h->current);
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
|
|
|
case SELECT_PREV:
|
2011-07-18 13:27:01 +04:00
|
|
|
h->current = dlg_widget_prev (h, h->current);
|
2010-11-10 14:09:42 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
while (h->current != w /* && (((Widget *) h->current->data)->options & W_DISABLED) == 0 */ );
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (dlg_overlap (w0, (Widget *) h->current->data))
|
|
|
|
{
|
|
|
|
send_message ((Widget *) h->current->data, WIDGET_DRAW, 0);
|
|
|
|
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-10-12 13:33:09 +04: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
|
|
|
|
dlg_execute_cmd (Dlg_head * h, unsigned 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:
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_one_up (h);
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_Down:
|
|
|
|
case CK_Right:
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_one_down (h);
|
|
|
|
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:
|
2010-11-10 14:09:42 +03:00
|
|
|
if (!h->modal)
|
|
|
|
dialog_switch_list ();
|
|
|
|
else
|
|
|
|
ret = MSG_NOT_HANDLED;
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_ScreenNext:
|
2010-11-10 14:09:42 +03:00
|
|
|
if (!h->modal)
|
|
|
|
dialog_switch_next ();
|
|
|
|
else
|
|
|
|
ret = MSG_NOT_HANDLED;
|
|
|
|
break;
|
2011-01-21 11:47:27 +03:00
|
|
|
case CK_ScreenPrev:
|
2010-11-10 14:09:42 +03:00
|
|
|
if (!h->modal)
|
|
|
|
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
|
|
|
|
dlg_handle_key (Dlg_head * h, int d_key)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
unsigned long command;
|
2010-11-18 11:43:23 +03:00
|
|
|
command = keybind_lookup_keymap_command (dialog_map, d_key);
|
2011-02-20 18:23:32 +03:00
|
|
|
if ((command == CK_IgnoreKey) || (dlg_execute_cmd (h, command) == MSG_NOT_HANDLED))
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_NOT_HANDLED;
|
2003-10-25 03:20:30 +04:00
|
|
|
else
|
2010-11-10 14:09:42 +03:00
|
|
|
return MSG_HANDLED;
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int
|
|
|
|
dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
GList *item;
|
|
|
|
GList *starting_widget = h->current;
|
|
|
|
Gpm_Event new_event;
|
|
|
|
int x = event->x;
|
|
|
|
int y = event->y;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* close the dialog by mouse click out of dialog area */
|
|
|
|
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
|
|
|
|
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
|
|
|
|
{
|
|
|
|
h->ret_value = B_CANCEL;
|
|
|
|
dlg_stop (h);
|
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
item = starting_widget;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Widget *widget;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
widget = (Widget *) item->data;
|
2011-07-18 13:27:01 +04:00
|
|
|
item = dlg_widget_next (h, item);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (((widget->options & W_DISABLED) == 0)
|
|
|
|
&& (x > widget->x) && (x <= widget->x + widget->cols)
|
|
|
|
&& (y > widget->y) && (y <= widget->y + widget->lines))
|
|
|
|
{
|
|
|
|
new_event = *event;
|
|
|
|
new_event.x -= widget->x;
|
|
|
|
new_event.y -= widget->y;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (widget->mouse != NULL)
|
|
|
|
return widget->mouse (&new_event, widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (item != starting_widget);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return MOU_NORMAL;
|
2009-08-16 19:27:33 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static cb_ret_t
|
|
|
|
dlg_try_hotkey (Dlg_head * 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
current = (Widget *) h->current->data;
|
|
|
|
|
|
|
|
if ((current->options & W_DISABLED) != 0)
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
|
|
if (current->options & W_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;
|
|
|
|
if ((current->options & W_WANT_HOTKEY) != 0)
|
|
|
|
handled = send_message (current, WIDGET_HOTKEY, d_key);
|
|
|
|
|
|
|
|
/* If not used, send hotkey to other widgets */
|
|
|
|
if (handled == MSG_HANDLED)
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2011-07-18 13:27:01 +04:00
|
|
|
hot_cur = dlg_widget_next (h, 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
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
current = (Widget *) hot_cur->data;
|
|
|
|
|
|
|
|
if ((current->options & W_WANT_HOTKEY) != 0)
|
|
|
|
handled = send_message (current, WIDGET_HOTKEY, d_key);
|
|
|
|
|
|
|
|
if (handled == MSG_NOT_HANDLED)
|
2011-07-18 13:27:01 +04:00
|
|
|
hot_cur = dlg_widget_next (h, hot_cur);
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
if (handled == MSG_HANDLED)
|
|
|
|
do_select_widget (h, hot_cur, SELECT_EXACT);
|
|
|
|
|
|
|
|
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
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_key_event (Dlg_head * 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 */
|
|
|
|
if ((h->flags & DLG_WANT_TAB) == 0)
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if (d_key == '\t')
|
|
|
|
{
|
|
|
|
dlg_one_down (h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (d_key == KEY_BTAB)
|
|
|
|
{
|
|
|
|
dlg_one_up (h);
|
|
|
|
return;
|
|
|
|
}
|
2010-04-05 20:59:21 +04:00
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* first can dlg_callback handle the key */
|
|
|
|
handled = h->callback (h, NULL, DLG_KEY, d_key, NULL);
|
|
|
|
|
|
|
|
/* next try the hotkey */
|
|
|
|
if (handled == MSG_NOT_HANDLED)
|
|
|
|
handled = dlg_try_hotkey (h, d_key);
|
|
|
|
|
|
|
|
if (handled == MSG_HANDLED)
|
|
|
|
h->callback (h, NULL, DLG_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 */
|
|
|
|
handled = send_message ((Widget *) h->current->data, WIDGET_KEY, d_key);
|
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)
|
|
|
|
handled = h->callback (h, NULL, DLG_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
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
h->callback (h, NULL, DLG_POST_KEY, d_key, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
frontend_run_dlg (Dlg_head * h)
|
|
|
|
{
|
|
|
|
int d_key;
|
|
|
|
Gpm_Event event;
|
|
|
|
|
|
|
|
event.x = -1;
|
|
|
|
|
|
|
|
/* close opened editors, viewers, etc */
|
2011-02-10 18:02:54 +03:00
|
|
|
if (!h->modal && mc_global.widget.midnight_shutdown)
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
h->callback (h, NULL, DLG_VALIDATE, 0, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
while (h->state == DLG_ACTIVE)
|
|
|
|
{
|
2011-02-10 18:02:54 +03:00
|
|
|
if (mc_global.tty.winch_flag)
|
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
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
while ((h->flags & DLG_WANT_IDLE) && is_idle ())
|
|
|
|
h->callback (h, NULL, DLG_IDLE, 0, NULL);
|
|
|
|
|
|
|
|
/* Allow terminating the dialog from the idle handler */
|
|
|
|
if (h->state != DLG_ACTIVE)
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (h->state == DLG_CLOSED)
|
|
|
|
h->callback (h, NULL, DLG_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)
|
|
|
|
{
|
|
|
|
Widget *w = (Widget *) a;
|
|
|
|
unsigned long id = GPOINTER_TO_UINT (b);
|
|
|
|
|
|
|
|
return w->id == id ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** draw box in window */
|
|
|
|
void
|
|
|
|
draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single)
|
|
|
|
{
|
|
|
|
tty_draw_box (h->y + y, h->x + x, ys, xs, single);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/** Clean the dialog area, draw the frame and the title */
|
|
|
|
void
|
|
|
|
common_dialog_repaint (Dlg_head * h)
|
|
|
|
{
|
|
|
|
int space;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (h->state != DLG_ACTIVE)
|
|
|
|
return;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
space = (h->flags & DLG_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);
|
|
|
|
draw_box (h, space, space, h->lines - 2 * space, h->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]);
|
|
|
|
dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2);
|
|
|
|
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
|
|
|
|
dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2)
|
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 */
|
|
|
|
int ox, oy, oc, ol;
|
|
|
|
int shift_x, shift_y, scale_x, scale_y;
|
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 */
|
|
|
|
ox = h->x;
|
|
|
|
oy = h->y;
|
|
|
|
oc = h->cols;
|
|
|
|
ol = h->lines;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
h->x = x1;
|
|
|
|
h->y = y1;
|
|
|
|
h->lines = y2 - y1;
|
|
|
|
h->cols = x2 - x1;
|
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 */
|
|
|
|
shift_x = h->x - ox;
|
|
|
|
shift_y = h->y - oy;
|
|
|
|
scale_x = h->cols - oc;
|
|
|
|
scale_y = h->lines - ol;
|
|
|
|
|
|
|
|
if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0))
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2010-06-30 14:51:57 +04:00
|
|
|
GList *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-06-30 14:51:57 +04:00
|
|
|
for (w = h->widgets; w != NULL; w = g_list_next (w))
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
|
|
|
/* there are, mainly, 2 generally possible
|
|
|
|
situations:
|
2003-11-27 11:59:54 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
1. control sticks to one side - it
|
|
|
|
should be moved
|
2003-11-27 11:59:54 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
2. control sticks to two sides of
|
|
|
|
one direction - it should be sized */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
Widget *c = (Widget *) w->data;
|
|
|
|
int x = c->x;
|
|
|
|
int y = c->y;
|
|
|
|
int cols = c->cols;
|
|
|
|
int lines = c->lines;
|
2003-11-27 11:59:54 +03:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT))
|
|
|
|
{
|
|
|
|
x += shift_x;
|
|
|
|
cols += scale_x;
|
|
|
|
}
|
|
|
|
else if (c->pos_flags & WPOS_KEEP_LEFT)
|
|
|
|
x += shift_x;
|
|
|
|
else if (c->pos_flags & WPOS_KEEP_RIGHT)
|
|
|
|
x += shift_x + scale_x;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM))
|
|
|
|
{
|
|
|
|
y += shift_y;
|
|
|
|
lines += scale_y;
|
|
|
|
}
|
|
|
|
else if (c->pos_flags & WPOS_KEEP_TOP)
|
|
|
|
y += shift_y;
|
|
|
|
else if (c->pos_flags & WPOS_KEEP_BOTTOM)
|
|
|
|
y += shift_y + scale_y;
|
2010-04-06 11:16:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
widget_set_size (c, y, x, lines, cols);
|
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 sets only size, leaving positioning to automatic methods */
|
2003-11-27 11:59:54 +03:00
|
|
|
|
|
|
|
void
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_set_size (Dlg_head * h, int lines, int cols)
|
2003-11-27 11:59:54 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
int x = h->x;
|
|
|
|
int y = h->y;
|
|
|
|
|
|
|
|
if (h->flags & DLG_CENTER)
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
y = (LINES - lines) / 2;
|
|
|
|
x = (COLS - cols) / 2;
|
|
|
|
}
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((h->flags & DLG_TRYUP) && (y > 3))
|
|
|
|
y -= 2;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_set_position (h, y, x, y + lines, x + cols);
|
2003-11-27 11:59:54 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Default dialog callback */
|
|
|
|
|
|
|
|
cb_ret_t
|
|
|
|
default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
2003-11-27 11:59:54 +03:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
(void) sender;
|
|
|
|
(void) parm;
|
|
|
|
(void) data;
|
|
|
|
|
|
|
|
switch (msg)
|
2010-04-05 20:59:21 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
case DLG_DRAW:
|
|
|
|
if (h->color != NULL)
|
|
|
|
{
|
|
|
|
common_dialog_repaint (h);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
return MSG_NOT_HANDLED;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
case DLG_IDLE:
|
|
|
|
dlg_broadcast_msg_to (h, WIDGET_IDLE, FALSE, W_WANT_IDLE);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
case DLG_RESIZE:
|
|
|
|
/* this is default resizing mechanism */
|
|
|
|
/* the main idea of this code is to resize dialog
|
|
|
|
according to flags (if any of flags require automatic
|
|
|
|
resizing, like DLG_CENTER, end after that reposition
|
|
|
|
controls in dialog according to flags of widget) */
|
|
|
|
dlg_set_size (h, h->lines, h->cols);
|
|
|
|
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
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
Dlg_head *
|
|
|
|
create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
|
|
|
|
const int *colors, dlg_cb_fn callback, const char *help_ctx,
|
|
|
|
const char *title, dlg_flags_t flags)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
Dlg_head *new_d;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
new_d = g_new0 (Dlg_head, 1);
|
|
|
|
new_d->modal = modal;
|
|
|
|
if (colors != NULL)
|
|
|
|
memmove (new_d->color, colors, sizeof (dlg_colors_t));
|
|
|
|
new_d->help_ctx = help_ctx;
|
|
|
|
new_d->callback = (callback != NULL) ? callback : default_dlg_callback;
|
|
|
|
new_d->x = x1;
|
|
|
|
new_d->y = y1;
|
|
|
|
new_d->flags = flags;
|
|
|
|
new_d->data = NULL;
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_set_size (new_d, lines, cols);
|
|
|
|
new_d->fullscreen = (new_d->x == 0 && new_d->y == 0
|
|
|
|
&& new_d->cols == COLS && new_d->lines == LINES);
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
new_d->mouse_status = MOU_NORMAL;
|
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 */
|
|
|
|
if (title != NULL)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2011-05-01 15:42:17 +04:00
|
|
|
/* unique name got event group for this dialog */
|
|
|
|
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;
|
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_erase (Dlg_head * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((h != NULL) && (h->state == DLG_ACTIVE))
|
|
|
|
tty_fill_region (h->y, h->x, h->lines, h->cols, ' ');
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
set_idle_proc (Dlg_head * d, int enable)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
if (enable)
|
|
|
|
d->flags |= DLG_WANT_IDLE;
|
|
|
|
else
|
|
|
|
d->flags &= ~DLG_WANT_IDLE;
|
2010-05-06 23:19:02 +04:00
|
|
|
}
|
2009-05-18 20:21:11 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Insert widget to dialog before current widget. For dialogs populated
|
|
|
|
* from the bottom, make the widget current. Return widget number.
|
|
|
|
*/
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
int
|
|
|
|
add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags)
|
|
|
|
{
|
|
|
|
Widget *widget = (Widget *) w;
|
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
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
widget->x += h->x;
|
|
|
|
widget->y += h->y;
|
|
|
|
widget->owner = h;
|
|
|
|
widget->pos_flags = pos_flags;
|
|
|
|
widget->id = g_list_length (h->widgets);
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((h->flags & DLG_REVERSE) != 0)
|
|
|
|
h->widgets = g_list_prepend (h->widgets, widget);
|
|
|
|
else
|
|
|
|
h->widgets = g_list_append (h->widgets, widget);
|
2010-04-18 14:58:18 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
h->current = h->widgets;
|
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 */
|
|
|
|
|
|
|
|
int
|
|
|
|
add_widget (Dlg_head * h, void *w)
|
2010-05-06 23:19:02 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP);
|
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))
|
2011-07-09 20:32:26 +04:00
|
|
|
dlg_redraw ((Dlg_head *) 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))
|
|
|
|
if ((d->data != NULL) && ((Dlg_head *) d->data)->fullscreen)
|
|
|
|
break;
|
|
|
|
/* back to top dialog */
|
|
|
|
for (; d != NULL; d = g_list_previous (d))
|
|
|
|
if (d->data != NULL)
|
|
|
|
dlg_redraw ((Dlg_head *) d->data);
|
|
|
|
}
|
|
|
|
}
|
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
|
2010-11-12 11:03:57 +03:00
|
|
|
dlg_broadcast_msg (Dlg_head * h, widget_msg_t msg, gboolean reverse)
|
2010-11-10 14:09:42 +03:00
|
|
|
{
|
2010-11-12 11:03:57 +03:00
|
|
|
dlg_broadcast_msg_to (h, msg, reverse, 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
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
dlg_focus (Dlg_head * h)
|
|
|
|
{
|
|
|
|
/* cannot focus disabled widget ... */
|
|
|
|
|
|
|
|
if ((h->current != NULL) && (h->state == DLG_ACTIVE))
|
|
|
|
{
|
|
|
|
Widget *current = (Widget *) h->current->data;
|
|
|
|
|
|
|
|
if (((current->options & W_DISABLED) == 0)
|
|
|
|
&& (send_message (current, WIDGET_FOCUS, 0) == MSG_HANDLED))
|
|
|
|
{
|
|
|
|
h->callback (h, current, DLG_FOCUS, 0, NULL);
|
|
|
|
return 1;
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return 0;
|
2009-10-30 14:50:04 +03:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Return true if the windows overlap */
|
|
|
|
|
|
|
|
int
|
|
|
|
dlg_overlap (Widget * a, Widget * b)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-11-10 14:09:42 +03:00
|
|
|
return !((b->x >= a->x + a->cols)
|
|
|
|
|| (a->x >= b->x + b->cols) || (b->y >= a->y + a->lines) || (a->y >= b->y + b->lines));
|
|
|
|
}
|
2003-10-25 03:20:30 +04: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 *
|
|
|
|
find_widget_type (const Dlg_head * h, callback_fn callback)
|
|
|
|
{
|
|
|
|
GList *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
w = g_list_find_custom (h->widgets, callback, dlg_find_widget_callback);
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
return (w == NULL) ? NULL : (Widget *) w->data;
|
|
|
|
}
|
2010-06-29 11:20:48 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Find the widget with the given id */
|
|
|
|
|
|
|
|
Widget *
|
|
|
|
dlg_find_by_id (const Dlg_head * h, unsigned int id)
|
|
|
|
{
|
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);
|
|
|
|
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
|
|
|
|
dlg_select_by_id (const Dlg_head * h, unsigned int id)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
dlg_select_widget (w);
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*
|
|
|
|
* Try to select widget in the dialog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
dlg_select_widget (void *w)
|
|
|
|
{
|
|
|
|
const Widget *widget = (Widget *) w;
|
|
|
|
Dlg_head *h = widget->owner;
|
|
|
|
|
2011-01-07 11:52:47 +03:00
|
|
|
do_select_widget (h, g_list_find (h->widgets, widget), SELECT_EXACT);
|
2010-11-10 14:09:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Try to select previous widget in the tab order */
|
|
|
|
|
|
|
|
void
|
|
|
|
dlg_one_up (Dlg_head * h)
|
|
|
|
{
|
|
|
|
if (h->widgets != NULL)
|
2011-07-18 13:27:01 +04:00
|
|
|
do_select_widget (h, dlg_widget_prev (h, h->current), SELECT_PREV);
|
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
|
|
|
|
dlg_one_down (Dlg_head * h)
|
|
|
|
{
|
|
|
|
if (h->widgets != NULL)
|
2011-07-18 13:27:01 +04:00
|
|
|
do_select_widget (h, dlg_widget_next (h, h->current), SELECT_NEXT);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
update_cursor (Dlg_head * 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
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if ((p != NULL) && (h->state == DLG_ACTIVE))
|
|
|
|
{
|
|
|
|
Widget *w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
w = (Widget *) p->data;
|
2010-04-05 20:59:21 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
if (((w->options & W_DISABLED) == 0) && ((w->options & W_WANT_CURSOR) != 0))
|
|
|
|
send_message (w, WIDGET_CURSOR, 0);
|
|
|
|
else
|
|
|
|
do
|
|
|
|
{
|
2011-07-18 13:27:01 +04:00
|
|
|
p = dlg_widget_next (h, p);
|
2010-11-10 14:09:42 +03:00
|
|
|
if (p == h->current)
|
|
|
|
break;
|
|
|
|
|
|
|
|
w = (Widget *) p->data;
|
|
|
|
|
|
|
|
if (((w->options & W_DISABLED) == 0) && ((w->options & W_WANT_CURSOR) != 0))
|
|
|
|
if (send_message (w, WIDGET_CURSOR, 0) == MSG_HANDLED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
dlg_redraw (Dlg_head * h)
|
|
|
|
{
|
|
|
|
if (h->state != DLG_ACTIVE)
|
|
|
|
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;
|
|
|
|
h->callback (h, NULL, DLG_RESIZE, 0, NULL);
|
|
|
|
}
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-11-10 14:09:42 +03:00
|
|
|
h->callback (h, NULL, DLG_DRAW, 0, NULL);
|
|
|
|
dlg_broadcast_msg (h, WIDGET_DRAW, TRUE);
|
|
|
|
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
|
|
|
|
dlg_stop (Dlg_head * h)
|
|
|
|
{
|
|
|
|
h->state = DLG_CLOSED;
|
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
|
2010-04-06 11:16:11 +04:00
|
|
|
init_dlg (Dlg_head * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2009-11-19 11:34:20 +03:00
|
|
|
if ((top_dlg != NULL) && ((Dlg_head *) top_dlg->data)->modal)
|
|
|
|
h->modal = TRUE;
|
|
|
|
|
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 */
|
2010-04-18 14:58:18 +04:00
|
|
|
if (h->state == DLG_ACTIVE)
|
|
|
|
{
|
|
|
|
if (!h->modal)
|
|
|
|
dialog_switch_add (h);
|
|
|
|
|
|
|
|
h->callback (h, NULL, DLG_INIT, 0, NULL);
|
|
|
|
dlg_broadcast_msg (h, WIDGET_INIT, FALSE);
|
2011-05-03 17:24:56 +04:00
|
|
|
dlg_read_history (h);
|
2010-04-18 14:58:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
h->state = DLG_ACTIVE;
|
2009-10-30 14:50:04 +03:00
|
|
|
|
2009-11-12 11:54:00 +03:00
|
|
|
dlg_redraw (h);
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
/* Select the first widget that takes focus */
|
2009-10-30 14:50:04 +03:00
|
|
|
while (h->current != NULL && !dlg_focus (h))
|
2011-07-18 13:27:01 +04:00
|
|
|
h->current = dlg_widget_next (h, h->current);
|
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
|
2010-04-06 11:16:11 +04:00
|
|
|
dlg_process_event (Dlg_head * h, int key, Gpm_Event * event)
|
|
|
|
{
|
|
|
|
if (key == EV_NONE)
|
|
|
|
{
|
|
|
|
if (tty_got_interrupt ())
|
2011-03-28 16:45:50 +04:00
|
|
|
if (h->callback (h, NULL, DLG_ACTION, CK_Cancel, NULL) != MSG_HANDLED)
|
|
|
|
dlg_execute_cmd (h, CK_Cancel);
|
2010-05-06 23:19:02 +04:00
|
|
|
|
|
|
|
return;
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Shutdown the run_dlg */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2009-10-30 14:50:04 +03:00
|
|
|
void
|
|
|
|
dlg_run_done (Dlg_head * h)
|
|
|
|
{
|
2010-09-20 13:58:17 +04:00
|
|
|
top_dlg = g_list_remove (top_dlg, h);
|
|
|
|
|
2010-04-18 14:58:18 +04:00
|
|
|
if (h->state == DLG_CLOSED)
|
|
|
|
{
|
2010-04-05 20:59:21 +04:00
|
|
|
h->callback (h, (Widget *) h->current->data, DLG_END, 0, NULL);
|
2010-04-18 14:58:18 +04:00
|
|
|
if (!h->modal)
|
|
|
|
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
|
|
|
|
run_dlg (Dlg_head * h)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
|
|
|
init_dlg (h);
|
|
|
|
frontend_run_dlg (h);
|
|
|
|
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
|
2010-04-06 11:16:11 +04:00
|
|
|
destroy_dlg (Dlg_head * 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);
|
2010-04-05 20:59:21 +04:00
|
|
|
dlg_broadcast_msg (h, WIDGET_DESTROY, FALSE);
|
|
|
|
g_list_foreach (h->widgets, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (h->widgets);
|
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
|
|
|
|
dlg_save_history (Dlg_head * h)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
event_data.cfg = mc_config_init (profile);
|
|
|
|
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 *
|
2010-11-10 14:09:42 +03:00
|
|
|
dlg_get_title (const Dlg_head * 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
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Replace widget old_w for widget new_w in the dialog */
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
void
|
2010-04-06 11:16:11 +04:00
|
|
|
dlg_replace_widget (Widget * old_w, Widget * new_w)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-04-05 21:17:02 +04:00
|
|
|
Dlg_head *h = old_w->owner;
|
2010-04-05 20:59:21 +04:00
|
|
|
gboolean should_focus = FALSE;
|
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;
|
|
|
|
|
|
|
|
if (old_w == h->current->data)
|
|
|
|
should_focus = TRUE;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-05 21:17:02 +04:00
|
|
|
new_w->owner = h;
|
|
|
|
new_w->id = old_w->id;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
if (should_focus)
|
2010-04-05 20:59:21 +04:00
|
|
|
h->current->data = new_w;
|
|
|
|
else
|
|
|
|
g_list_find (h->widgets, old_w)->data = new_w;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
send_message (old_w, WIDGET_DESTROY, 0);
|
|
|
|
send_message (new_w, WIDGET_INIT, 0);
|
|
|
|
|
2003-11-27 03:17:43 +03:00
|
|
|
if (should_focus)
|
2010-04-06 11:16:11 +04:00
|
|
|
dlg_select_widget (new_w);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
send_message (new_w, WIDGET_DRAW, 0);
|
|
|
|
}
|
2010-11-10 14:09:42 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|