2003-10-25 03:20:30 +04:00
|
|
|
/* Dialog box features module for the Midnight Commander
|
|
|
|
Copyright (C) 1994, 1995 Radek Doulik, Miguel de Icaza
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
This program 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-10-25 03:20:30 +04:00
|
|
|
*/
|
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file dialog.h
|
|
|
|
* \brief Header: dialog box features module
|
|
|
|
*/
|
|
|
|
|
2009-02-27 14:19:30 +03:00
|
|
|
#ifndef MC_DIALOG_H
|
|
|
|
#define MC_DIALOG_H
|
2004-12-03 22:17:46 +03:00
|
|
|
|
2010-04-18 14:23:06 +04:00
|
|
|
#include <sys/types.h> /* size_t */
|
|
|
|
|
2009-10-30 14:50:04 +03:00
|
|
|
#include "lib/global.h"
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/mouse.h"
|
2009-11-19 11:34:20 +03:00
|
|
|
#include "lib/util.h" /* Hook */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Common return values */
|
2010-04-18 14:23:06 +04:00
|
|
|
#define B_EXIT 0
|
|
|
|
#define B_CANCEL 1
|
|
|
|
#define B_ENTER 2
|
|
|
|
#define B_HELP 3
|
2003-10-25 03:20:30 +04:00
|
|
|
#define B_USER 100
|
|
|
|
|
2009-11-01 12:23:15 +03:00
|
|
|
typedef struct Widget Widget;
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
/* Widget messages */
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
WIDGET_INIT, /* Initialize widget */
|
|
|
|
WIDGET_FOCUS, /* Draw widget in focused state */
|
|
|
|
WIDGET_UNFOCUS, /* Draw widget in unfocused state */
|
|
|
|
WIDGET_DRAW, /* Sent to widget to draw themselves */
|
|
|
|
WIDGET_KEY, /* Sent to widgets on key press */
|
|
|
|
WIDGET_HOTKEY, /* Sent to widget to catch preprocess key */
|
|
|
|
WIDGET_COMMAND, /* Send to widget to handle command */
|
|
|
|
WIDGET_DESTROY, /* Sent to widget at destruction time */
|
|
|
|
WIDGET_CURSOR, /* Sent to widget to position the cursor */
|
|
|
|
WIDGET_IDLE, /* Sent to widgets with options & W_WANT_IDLE */
|
|
|
|
WIDGET_RESIZED /* Sent after a widget has been resized */
|
2003-10-25 03:20:30 +04:00
|
|
|
} widget_msg_t;
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
MSG_NOT_HANDLED = 0,
|
|
|
|
MSG_HANDLED = 1
|
2003-10-25 03:20:30 +04:00
|
|
|
} cb_ret_t;
|
|
|
|
|
|
|
|
/* Widgets are expected to answer to the following messages:
|
|
|
|
|
|
|
|
WIDGET_FOCUS: 1 if the accept the focus, 0 if they do not.
|
|
|
|
WIDGET_UNFOCUS: 1 if they accept to release the focus, 0 if they don't.
|
|
|
|
WIDGET_KEY: 1 if they actually used the key, 0 if not.
|
|
|
|
WIDGET_HOTKEY: 1 if they actually used the key, 0 if not.
|
2010-04-06 11:16:11 +04:00
|
|
|
*/
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Dialog messages */
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DLG_INIT = 0, /* Initialize dialog */
|
|
|
|
DLG_IDLE = 1, /* The idle state is active */
|
|
|
|
DLG_DRAW = 2, /* Draw dialog on screen */
|
|
|
|
DLG_FOCUS = 3, /* A widget has got focus */
|
|
|
|
DLG_UNFOCUS = 4, /* A widget has been unfocused */
|
|
|
|
DLG_RESIZE = 5, /* Window size has changed */
|
|
|
|
DLG_KEY = 6, /* Key before sending to widget */
|
|
|
|
DLG_HOTKEY_HANDLED = 7, /* A widget has got the hotkey */
|
|
|
|
DLG_POST_KEY = 8, /* The key has been handled */
|
|
|
|
DLG_UNHANDLED_KEY = 9, /* Key that no widget handled */
|
|
|
|
DLG_ACTION = 10, /* State of check- and radioboxes has changed
|
|
|
|
* and listbox current entry has changed */
|
|
|
|
DLG_VALIDATE = 11, /* Dialog is to be closed */
|
|
|
|
DLG_END = 12 /* Shut down dialog */
|
2003-10-25 03:20:30 +04:00
|
|
|
} dlg_msg_t;
|
|
|
|
|
2009-10-28 12:04:08 +03:00
|
|
|
/* Flags for create_dlg */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DLG_REVERSE = (1 << 5), /* Tab order is opposite to the add order */
|
|
|
|
DLG_WANT_TAB = (1 << 4), /* Should the tab key be sent to the dialog? */
|
|
|
|
DLG_WANT_IDLE = (1 << 3), /* Dialog wants idle events */
|
|
|
|
DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
|
|
|
|
DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
|
|
|
|
DLG_CENTER = (1 << 0), /* Center the dialog */
|
|
|
|
DLG_NONE = 0 /* No options */
|
|
|
|
} dlg_flags_t;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-03 15:19:09 +04:00
|
|
|
/* Dialog state */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DLG_ACTIVE = 0, /* Dialog is visible and active */
|
|
|
|
DLG_SUSPENDED = 1, /* Dialog is suspended */
|
|
|
|
DLG_CLOSED = 2 /* Dialog is closed */
|
|
|
|
} dlg_state_t;
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
/* Dialog callback */
|
2009-11-01 12:23:15 +03:00
|
|
|
typedef struct Dlg_head Dlg_head;
|
2010-04-18 14:23:06 +04:00
|
|
|
typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender,
|
2010-04-06 11:16:11 +04:00
|
|
|
dlg_msg_t msg, int parm, void *data);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2009-10-28 12:04:08 +03:00
|
|
|
/* menu command execution */
|
|
|
|
typedef cb_ret_t (*menu_exec_fn) (int command);
|
|
|
|
|
2009-10-24 12:58:02 +04:00
|
|
|
/* get string representation of shortcut assigned with command */
|
|
|
|
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
2009-10-24 12:58:02 +04:00
|
|
|
|
2010-04-18 14:23:06 +04:00
|
|
|
/* get dialog name to show in dialog list */
|
|
|
|
typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
|
|
|
|
|
2009-08-11 10:51:00 +04:00
|
|
|
/* Dialog color constants */
|
2010-04-06 11:16:11 +04:00
|
|
|
#define DLG_COLOR_NUM 4
|
|
|
|
#define DLG_NORMALC(h) ((h)->color[0])
|
|
|
|
#define DLG_FOCUSC(h) ((h)->color[1])
|
|
|
|
#define DLG_HOT_NORMALC(h) ((h)->color[2])
|
|
|
|
#define DLG_HOT_FOCUSC(h) ((h)->color[3])
|
2009-08-11 10:51:00 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
struct Dlg_head
|
|
|
|
{
|
2003-10-25 03:20:30 +04:00
|
|
|
/* Set by the user */
|
2009-11-19 11:34:20 +03:00
|
|
|
gboolean modal; /* type of dialog: modal or not */
|
2009-10-28 12:04:08 +03:00
|
|
|
dlg_flags_t flags; /* User flags */
|
2010-04-06 11:16:11 +04:00
|
|
|
const char *help_ctx; /* Name of the help entry */
|
|
|
|
int *color; /* Color set. Unused in viewer and editor */
|
2009-10-28 12:04:08 +03:00
|
|
|
char *title; /* Title of the dialog */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Set and received by the user */
|
2010-04-06 11:16:11 +04:00
|
|
|
int ret_value; /* Result of run_dlg() */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Geometry */
|
2010-04-06 11:16:11 +04:00
|
|
|
int x, y; /* Position relative to screen origin */
|
|
|
|
int cols, lines; /* Width and height of the window */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Internal flags */
|
2010-04-03 15:19:09 +04:00
|
|
|
dlg_state_t state;
|
|
|
|
gboolean fullscreen; /* Parents dialogs don't need refresh */
|
2010-04-06 11:16:11 +04:00
|
|
|
int mouse_status; /* For the autorepeat status of the mouse */
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Internal variables */
|
2010-04-05 20:59:21 +04:00
|
|
|
GList *widgets; /* widgets list */
|
|
|
|
GList *current; /* Curently active widget */
|
2010-04-06 11:16:11 +04:00
|
|
|
void *data; /* Data can be passed to dialog */
|
2010-04-18 14:23:06 +04:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
dlg_cb_fn callback;
|
2010-04-06 11:16:11 +04:00
|
|
|
dlg_shortcut_str get_shortcut; /* Shortcut string */
|
2010-04-18 14:23:06 +04:00
|
|
|
dlg_title_str get_title; /* useless for modal dialogs */
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
struct Dlg_head *parent; /* Parent dialog */
|
2009-11-01 12:23:15 +03:00
|
|
|
};
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2009-05-30 21:39:02 +04:00
|
|
|
/* Color styles for normal and error dialogs */
|
|
|
|
extern int dialog_colors[4];
|
|
|
|
extern int alarm_colors[4];
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Widget callback */
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2009-08-16 19:27:33 +04:00
|
|
|
/* widget options */
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
W_WANT_HOTKEY = (1 << 1),
|
|
|
|
W_WANT_CURSOR = (1 << 2),
|
|
|
|
W_WANT_IDLE = (1 << 3),
|
|
|
|
W_IS_INPUT = (1 << 4)
|
2009-08-16 19:27:33 +04:00
|
|
|
} widget_options_t;
|
|
|
|
|
|
|
|
/* Flags for widget repositioning on dialog resize */
|
2010-04-06 11:16:11 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
|
|
|
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
|
|
|
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
|
|
|
WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */
|
|
|
|
WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
|
|
|
|
WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
|
|
|
|
WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT
|
2009-08-16 19:27:33 +04:00
|
|
|
} widget_pos_flags_t;
|
|
|
|
|
2005-01-09 19:15:24 +03:00
|
|
|
/* Every Widget must have this as its first element */
|
2010-04-06 11:16:11 +04:00
|
|
|
struct Widget
|
|
|
|
{
|
2003-10-25 03:20:30 +04:00
|
|
|
int x, y;
|
|
|
|
int cols, lines;
|
2009-08-16 19:27:33 +04:00
|
|
|
widget_options_t options;
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_pos_flags_t pos_flags; /* repositioning flags */
|
2010-04-05 21:17:02 +04:00
|
|
|
unsigned int id; /* Number of the widget, starting with 0 */
|
2005-02-08 09:57:14 +03:00
|
|
|
callback_fn callback;
|
2003-10-25 03:20:30 +04:00
|
|
|
mouse_h mouse;
|
2010-04-05 21:17:02 +04:00
|
|
|
struct Dlg_head *owner;
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
/* draw box in window */
|
2010-04-06 11:16:11 +04:00
|
|
|
void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Creates a dialog head */
|
2009-11-19 11:34:20 +03:00
|
|
|
Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
|
2010-04-06 11:16:11 +04:00
|
|
|
const int *colors, dlg_cb_fn callback,
|
2009-10-28 12:04:08 +03:00
|
|
|
const char *help_ctx, const char *title, dlg_flags_t flags);
|
2009-05-30 21:39:02 +04:00
|
|
|
|
|
|
|
void dlg_set_default_colors (void);
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
int add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags);
|
|
|
|
int add_widget (Dlg_head * dest, void *w);
|
2009-08-16 19:27:33 +04:00
|
|
|
|
|
|
|
/* sets size of dialog, leaving positioning to automatic mehtods
|
2010-04-06 11:16:11 +04:00
|
|
|
according to dialog flags */
|
|
|
|
void dlg_set_size (Dlg_head * h, int lines, int cols);
|
2009-08-16 19:27:33 +04:00
|
|
|
/* this function allows to set dialog position */
|
2010-04-06 11:16:11 +04:00
|
|
|
void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-18 14:23:06 +04:00
|
|
|
void init_dlg (Dlg_head * h);
|
2010-04-06 11:16:11 +04:00
|
|
|
int run_dlg (Dlg_head * d);
|
2010-04-18 14:23:06 +04:00
|
|
|
void destroy_dlg (Dlg_head * h);
|
2004-12-03 22:17:46 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
void dlg_run_done (Dlg_head * h);
|
|
|
|
void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
|
2010-04-18 14:23:06 +04:00
|
|
|
|
|
|
|
char *dlg_get_title (const Dlg_head *h, size_t len);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* To activate/deactivate the idle message generation */
|
2010-04-06 11:16:11 +04:00
|
|
|
void set_idle_proc (Dlg_head * d, int enable);
|
2004-12-03 22:17:46 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
void dlg_redraw (Dlg_head * h);
|
2004-12-03 22:17:46 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
void widget_set_size (Widget * widget, int y, int x, int lines, int cols);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-05 20:59:21 +04:00
|
|
|
void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
void init_widget (Widget * w, int y, int x, int lines, int cols,
|
|
|
|
callback_fn callback, mouse_h mouse_handler);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Default callback for dialogs */
|
2010-04-06 11:16:11 +04:00
|
|
|
cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Default paint routine for dialogs */
|
|
|
|
void common_dialog_repaint (struct Dlg_head *h);
|
|
|
|
|
2009-05-11 16:13:58 +04:00
|
|
|
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
|
|
|
|
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-18 14:26:28 +04:00
|
|
|
extern GList *top_dlg;
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* A hook list for idle events */
|
|
|
|
extern Hook *idle_hook;
|
|
|
|
|
|
|
|
static inline cb_ret_t
|
2010-04-06 11:16:11 +04:00
|
|
|
send_message (Widget * w, widget_msg_t msg, int parm)
|
2003-10-25 03:20:30 +04:00
|
|
|
{
|
2010-04-05 20:59:21 +04:00
|
|
|
return w->callback (w, msg, parm);
|
2003-10-25 03:20:30 +04:00
|
|
|
}
|
|
|
|
|
2003-11-27 03:46:39 +03:00
|
|
|
/* Return 1 if the widget is active, 0 otherwise */
|
|
|
|
static inline int
|
|
|
|
dlg_widget_active (void *w)
|
|
|
|
{
|
|
|
|
Widget *w1 = (Widget *) w;
|
2010-04-05 21:17:02 +04:00
|
|
|
return ((Widget *) w1->owner->current->data == w1);
|
2010-04-05 20:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int
|
|
|
|
dlg_get_current_widget_id (const Dlg_head * h)
|
|
|
|
{
|
2010-04-05 21:17:02 +04:00
|
|
|
return ((Widget *) h->current->data)->id;
|
2003-11-27 03:46:39 +03:00
|
|
|
}
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
void dlg_replace_widget (Widget * old, Widget * new);
|
|
|
|
int dlg_overlap (Widget * a, Widget * b);
|
|
|
|
void widget_erase (Widget *);
|
|
|
|
void dlg_erase (Dlg_head * h);
|
|
|
|
void dlg_stop (Dlg_head * h);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Widget selection */
|
2010-04-06 11:16:11 +04:00
|
|
|
void dlg_select_widget (void *widget);
|
|
|
|
void dlg_one_up (Dlg_head * h);
|
|
|
|
void dlg_one_down (Dlg_head * h);
|
|
|
|
int dlg_focus (Dlg_head * h);
|
|
|
|
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
2010-04-05 20:59:21 +04:00
|
|
|
void dlg_select_by_id (const Dlg_head * h, unsigned int id);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
|
|
|
/* Redraw all dialogs */
|
1998-02-27 07:54:42 +03:00
|
|
|
void do_refresh (void);
|
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
/* Sets/clear the specified flag in the options field */
|
|
|
|
#define widget_option(w,f,i) \
|
|
|
|
w.options = ((i) ? (w.options | (f)) : (w.options & (~(f))))
|
|
|
|
|
|
|
|
#define widget_want_cursor(w,i) widget_option(w, W_WANT_CURSOR, i)
|
|
|
|
#define widget_want_hotkey(w,i) widget_option(w, W_WANT_HOTKEY, i)
|
|
|
|
|
|
|
|
/* Used in load_prompt() */
|
2010-04-06 11:16:11 +04:00
|
|
|
void update_cursor (Dlg_head * h);
|
2003-10-25 03:20:30 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
#endif /* MC_DIALOG_H */
|