Merge branch '2919_dlg_as_widget'
* 2919_dlg_as_widget: (57 commits) Update po/*.po and po/mc.pot files. Internal menu structures are opaque now. Add useful macros for widget type cast. Unify widget and dialog message handling. Remove DLG_WANT_IDLE. Use W_WANT_IDLE instead. Rename Dlg_head to WDialog. Rename default callbacks of widget and dialog. Unify some hotkeys. (editcmd_dialog_raw_key_query): adjust sizes and look'n'feel. (real_query_recursive): refactoring of dialog. "Directory scanning" dialog: adjust look'n'feel. Center text in query owerwrite and delete dialogs. (query_dialog): center label horizontally. Horizontal centering of multi-line label: center each line independently. (file_mask_dialog): adjust width calculation. (query_dialog): add horizontal line. Remove DLG_REVERSE flag. Build file operation dialogs in normal order. Build find file dialogs in normal order. Build "Background jobs" dialog in normal order. ...
Этот коммит содержится в:
Коммит
47fc9f669f
@ -9,8 +9,8 @@
|
||||
/* main forward declarations */
|
||||
struct Widget;
|
||||
typedef struct Widget Widget;
|
||||
struct Dlg_head;
|
||||
typedef struct Dlg_head Dlg_head;
|
||||
struct WDialog;
|
||||
typedef struct WDialog WDialog;
|
||||
|
||||
/* Please note that the first element in all the widgets is a */
|
||||
/* widget variable of type Widget. We abuse this fact everywhere */
|
||||
|
@ -55,42 +55,42 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
button_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
button_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WButton *b = (WButton *) w;
|
||||
WButton *b = BUTTON (w);
|
||||
WDialog *h = w->owner;
|
||||
int stop = 0;
|
||||
int off = 0;
|
||||
Dlg_head *h = b->widget.owner;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_HOTKEY:
|
||||
case MSG_HOTKEY:
|
||||
/*
|
||||
* Don't let the default button steal Enter from the current
|
||||
* button. This is a workaround for the flawed event model
|
||||
* when hotkeys are sent to all widgets before the key is
|
||||
* handled by the current widget.
|
||||
*/
|
||||
if (parm == '\n' && (Widget *) h->current->data == &b->widget)
|
||||
if (parm == '\n' && WIDGET (h->current->data) == WIDGET (b))
|
||||
{
|
||||
button_callback (w, WIDGET_KEY, ' ');
|
||||
send_message (w, sender, MSG_KEY, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
if (parm == '\n' && b->flags == DEFPUSH_BUTTON)
|
||||
{
|
||||
button_callback (w, WIDGET_KEY, ' ');
|
||||
send_message (w, sender, MSG_KEY, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
if (b->text.hotkey != NULL && g_ascii_tolower ((gchar) b->text.hotkey[0]) == parm)
|
||||
{
|
||||
button_callback (w, WIDGET_KEY, ' ');
|
||||
send_message (w, sender, MSG_KEY, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
if (parm != ' ' && parm != '\n')
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
@ -103,7 +103,7 @@ button_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
case MSG_CURSOR:
|
||||
switch (b->flags)
|
||||
{
|
||||
case DEFPUSH_BUTTON:
|
||||
@ -120,15 +120,15 @@ button_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
off = 0;
|
||||
break;
|
||||
}
|
||||
widget_move (&b->widget, 0, b->hotpos + off);
|
||||
widget_move (w, 0, b->hotpos + off);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_UNFOCUS:
|
||||
case WIDGET_FOCUS:
|
||||
case WIDGET_DRAW:
|
||||
if (msg == WIDGET_UNFOCUS)
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_FOCUS:
|
||||
case MSG_DRAW:
|
||||
if (msg == MSG_UNFOCUS)
|
||||
b->selected = FALSE;
|
||||
else if (msg == WIDGET_FOCUS)
|
||||
else if (msg == MSG_FOCUS)
|
||||
b->selected = TRUE;
|
||||
|
||||
widget_selectcolor (w, b->selected, FALSE);
|
||||
@ -168,12 +168,12 @@ button_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
release_hotkey (b->text);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ button_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
static int
|
||||
button_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Widget *w = (Widget *) data;
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
return MOU_UNHANDLED;
|
||||
@ -192,8 +192,8 @@ button_event (Gpm_Event * event, void *data)
|
||||
dlg_select_widget (w);
|
||||
if ((event->type & GPM_UP) != 0)
|
||||
{
|
||||
button_callback (w, WIDGET_KEY, ' ');
|
||||
w->owner->callback (w->owner, w, DLG_POST_KEY, ' ', NULL);
|
||||
send_message (w, NULL, MSG_KEY, ' ', NULL);
|
||||
send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,17 +208,18 @@ WButton *
|
||||
button_new (int y, int x, int action, button_flags_t flags, const char *text, bcback_fn callback)
|
||||
{
|
||||
WButton *b;
|
||||
Widget *w;
|
||||
|
||||
b = g_new (WButton, 1);
|
||||
w = WIDGET (b);
|
||||
|
||||
b->action = action;
|
||||
b->flags = flags;
|
||||
b->text = parse_hotkey (text);
|
||||
|
||||
init_widget (&b->widget, y, x, 1, button_get_len (b), button_callback, button_event);
|
||||
|
||||
init_widget (w, y, x, 1, button_get_len (b), button_callback, button_event);
|
||||
b->selected = FALSE;
|
||||
b->callback = callback;
|
||||
widget_want_hotkey (b->widget, TRUE);
|
||||
widget_want_hotkey (w, TRUE);
|
||||
b->hotpos = (b->text.hotkey != NULL) ? str_term_width1 (b->text.start) : -1;
|
||||
|
||||
return b;
|
||||
@ -239,10 +240,13 @@ button_get_text (const WButton * b)
|
||||
void
|
||||
button_set_text (WButton * b, const char *text)
|
||||
{
|
||||
Widget *w = WIDGET (b);
|
||||
|
||||
release_hotkey (b->text);
|
||||
b->text = parse_hotkey (text);
|
||||
b->widget.cols = button_get_len (b);
|
||||
dlg_redraw (b->widget.owner);
|
||||
w->cols = button_get_len (b);
|
||||
if (w->owner != NULL)
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define BUTTON(x) ((WButton *)(x))
|
||||
|
||||
struct WButton;
|
||||
|
||||
|
@ -148,42 +148,41 @@ static gboolean
|
||||
buttonbar_call (WButtonBar * bb, int i)
|
||||
{
|
||||
cb_ret_t ret = MSG_NOT_HANDLED;
|
||||
Widget *w = WIDGET (bb);
|
||||
|
||||
if ((bb != NULL) && (bb->labels[i].command != CK_IgnoreKey))
|
||||
ret = bb->widget.owner->callback (bb->widget.owner,
|
||||
(Widget *) bb, DLG_ACTION,
|
||||
bb->labels[i].command, bb->labels[i].receiver);
|
||||
ret = send_message (w->owner, w, MSG_ACTION, bb->labels[i].command, bb->labels[i].receiver);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
buttonbar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
buttonbar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WButtonBar *bb = (WButtonBar *) w;
|
||||
WButtonBar *bb = BUTTONBAR (w);
|
||||
int i;
|
||||
const char *text;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_FOCUS:
|
||||
case MSG_FOCUS:
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_HOTKEY:
|
||||
case MSG_HOTKEY:
|
||||
for (i = 0; i < BUTTONBAR_LABELS_NUM; i++)
|
||||
if (parm == KEY_F (i + 1) && buttonbar_call (bb, i))
|
||||
return MSG_HANDLED;
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
if (bb->visible)
|
||||
{
|
||||
buttonbar_init_button_positions (bb);
|
||||
widget_move (&bb->widget, 0, 0);
|
||||
widget_move (w, 0, 0);
|
||||
tty_setcolor (DEFAULT_COLOR);
|
||||
tty_printf ("%-*s", bb->widget.cols, "");
|
||||
widget_move (&bb->widget, 0, 0);
|
||||
tty_printf ("%-*s", w->cols, "");
|
||||
widget_move (w, 0, 0);
|
||||
|
||||
for (i = 0; i < BUTTONBAR_LABELS_NUM; i++)
|
||||
{
|
||||
@ -203,13 +202,13 @@ buttonbar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
for (i = 0; i < BUTTONBAR_LABELS_NUM; i++)
|
||||
g_free (bb->labels[i].text);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,14 +217,14 @@ buttonbar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
static int
|
||||
buttonbar_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Widget *w = (Widget *) data;
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
return MOU_UNHANDLED;
|
||||
|
||||
if ((event->type & GPM_UP) != 0)
|
||||
{
|
||||
WButtonBar *bb = (WButtonBar *) data;
|
||||
WButtonBar *bb = BUTTONBAR (data);
|
||||
Gpm_Event local;
|
||||
int button;
|
||||
|
||||
@ -246,14 +245,16 @@ WButtonBar *
|
||||
buttonbar_new (gboolean visible)
|
||||
{
|
||||
WButtonBar *bb;
|
||||
Widget *w;
|
||||
|
||||
bb = g_new0 (WButtonBar, 1);
|
||||
w = WIDGET (bb);
|
||||
init_widget (w, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event);
|
||||
|
||||
init_widget (&bb->widget, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event);
|
||||
bb->widget.pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM;
|
||||
w->pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM;
|
||||
bb->visible = visible;
|
||||
widget_want_hotkey (bb->widget, 1);
|
||||
widget_want_cursor (bb->widget, 0);
|
||||
widget_want_hotkey (w, TRUE);
|
||||
widget_want_cursor (w, FALSE);
|
||||
|
||||
return bb;
|
||||
}
|
||||
@ -277,7 +278,7 @@ buttonbar_set_label (WButtonBar * bb, int idx, const char *text,
|
||||
set_label_text (bb, idx, text);
|
||||
|
||||
bb->labels[idx - 1].command = command;
|
||||
bb->labels[idx - 1].receiver = (Widget *) receiver;
|
||||
bb->labels[idx - 1].receiver = WIDGET (receiver);
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +286,7 @@ buttonbar_set_label (WButtonBar * bb, int idx, const char *text,
|
||||
|
||||
/* Find ButtonBar widget in the dialog */
|
||||
WButtonBar *
|
||||
find_buttonbar (const Dlg_head * h)
|
||||
find_buttonbar (const WDialog * h)
|
||||
{
|
||||
return (WButtonBar *) find_widget_type (h, buttonbar_callback);
|
||||
return BUTTONBAR (find_widget_type (h, buttonbar_callback));
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define BUTTONBAR(x) ((WButtonBar *)(x))
|
||||
|
||||
/* number of bttons in buttonbar */
|
||||
#define BUTTONBAR_LABELS_NUM 10
|
||||
|
||||
@ -41,7 +43,7 @@ struct global_keymap_t;
|
||||
WButtonBar *buttonbar_new (gboolean visible);
|
||||
void buttonbar_set_label (WButtonBar * bb, int idx, const char *text,
|
||||
const struct global_keymap_t *keymap, const Widget * receiver);
|
||||
WButtonBar *find_buttonbar (const Dlg_head * h);
|
||||
WButtonBar *find_buttonbar (const WDialog * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
@ -49,7 +51,7 @@ static inline void
|
||||
buttonbar_redraw (WButtonBar * bb)
|
||||
{
|
||||
if (bb != NULL)
|
||||
send_message ((Widget *) bb, WIDGET_DRAW, 0);
|
||||
send_message (bb, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -54,52 +54,52 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
check_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
check_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WCheck *c = (WCheck *) w;
|
||||
Dlg_head *h = c->widget.owner;
|
||||
WCheck *c = CHECK (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_HOTKEY:
|
||||
case MSG_HOTKEY:
|
||||
if (c->text.hotkey != NULL)
|
||||
{
|
||||
if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
|
||||
{
|
||||
check_callback (w, WIDGET_KEY, ' '); /* make action */
|
||||
/* make action */
|
||||
send_message (w, sender, MSG_KEY, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
if (parm != ' ')
|
||||
return MSG_NOT_HANDLED;
|
||||
c->state ^= C_BOOL;
|
||||
c->state ^= C_CHANGE;
|
||||
h->callback (h, w, DLG_ACTION, 0, NULL);
|
||||
check_callback (w, WIDGET_FOCUS, ' ');
|
||||
send_message (WIDGET (w)->owner, w, MSG_ACTION, 0, NULL);
|
||||
send_message (w, sender, MSG_FOCUS, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
widget_move (&c->widget, 0, 1);
|
||||
case MSG_CURSOR:
|
||||
widget_move (c, 0, 1);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_FOCUS:
|
||||
case WIDGET_UNFOCUS:
|
||||
case WIDGET_DRAW:
|
||||
widget_selectcolor (w, msg == WIDGET_FOCUS, FALSE);
|
||||
widget_move (&c->widget, 0, 0);
|
||||
case MSG_FOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_DRAW:
|
||||
widget_selectcolor (w, msg == MSG_FOCUS, FALSE);
|
||||
widget_move (c, 0, 0);
|
||||
tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] ");
|
||||
hotkey_draw (w, c->text, msg == WIDGET_FOCUS);
|
||||
hotkey_draw (w, c->text, msg == MSG_FOCUS);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
release_hotkey (c->text);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ check_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
static int
|
||||
check_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Widget *w = (Widget *) data;
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
return MOU_UNHANDLED;
|
||||
@ -118,9 +118,9 @@ check_event (Gpm_Event * event, void *data)
|
||||
dlg_select_widget (w);
|
||||
if ((event->type & GPM_UP) != 0)
|
||||
{
|
||||
check_callback (w, WIDGET_KEY, ' ');
|
||||
check_callback (w, WIDGET_FOCUS, 0);
|
||||
w->owner->callback (w->owner, w, DLG_POST_KEY, ' ', NULL);
|
||||
send_message (w, NULL, MSG_KEY, ' ', NULL);
|
||||
send_message (w, NULL, MSG_FOCUS, 0, NULL);
|
||||
send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,13 +135,17 @@ WCheck *
|
||||
check_new (int y, int x, int state, const char *text)
|
||||
{
|
||||
WCheck *c;
|
||||
Widget *w;
|
||||
|
||||
c = g_new (WCheck, 1);
|
||||
w = WIDGET (c);
|
||||
c->text = parse_hotkey (text);
|
||||
init_widget (&c->widget, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_event);
|
||||
init_widget (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_event);
|
||||
/* 4 is width of "[X] " */
|
||||
c->state = state ? C_BOOL : 0;
|
||||
widget_want_hotkey (c->widget, TRUE);
|
||||
widget_want_hotkey (w, TRUE);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define CHECK(x) ((WCheck *)(x))
|
||||
|
||||
#define C_BOOL 0x0001
|
||||
#define C_CHANGE 0x0002
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
Dlg_head *midnight_dlg = NULL;
|
||||
WDialog *midnight_dlg = NULL;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
@ -75,7 +75,7 @@ dialog_switch_suspend (void *data, void *user_data)
|
||||
(void) user_data;
|
||||
|
||||
if (data != mc_current->data)
|
||||
((Dlg_head *) data)->state = DLG_SUSPENDED;
|
||||
DIALOG (data)->state = DLG_SUSPENDED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -85,7 +85,7 @@ dialog_switch_goto (GList * dlg)
|
||||
{
|
||||
if (mc_current != dlg)
|
||||
{
|
||||
Dlg_head *old = (Dlg_head *) mc_current->data;
|
||||
WDialog *old = DIALOG (mc_current->data);
|
||||
|
||||
mc_current = dlg;
|
||||
|
||||
@ -100,7 +100,7 @@ dialog_switch_goto (GList * dlg)
|
||||
/* switch from editor, viewer, etc to another dialog */
|
||||
old->state = DLG_SUSPENDED;
|
||||
|
||||
if ((Dlg_head *) dlg->data != midnight_dlg)
|
||||
if (DIALOG (dlg->data) != midnight_dlg)
|
||||
/* switch to another editor, viewer, etc */
|
||||
/* return to panels before run the required dialog */
|
||||
dialog_switch_pending = TRUE;
|
||||
@ -119,11 +119,11 @@ dialog_switch_goto (GList * dlg)
|
||||
static void
|
||||
dlg_resize_cb (void *data, void *user_data)
|
||||
{
|
||||
Dlg_head *d = data;
|
||||
WDialog *d = data;
|
||||
|
||||
(void) user_data;
|
||||
if (d->state == DLG_ACTIVE)
|
||||
d->callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
send_message (d, NULL, MSG_RESIZE, 0, NULL);
|
||||
else
|
||||
d->winch_pending = TRUE;
|
||||
}
|
||||
@ -133,7 +133,7 @@ dlg_resize_cb (void *data, void *user_data)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_add (Dlg_head * h)
|
||||
dialog_switch_add (WDialog * h)
|
||||
{
|
||||
GList *dlg;
|
||||
|
||||
@ -154,11 +154,11 @@ dialog_switch_add (Dlg_head * h)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_remove (Dlg_head * h)
|
||||
dialog_switch_remove (WDialog * h)
|
||||
{
|
||||
GList *this;
|
||||
|
||||
if ((Dlg_head *) mc_current->data == h)
|
||||
if (DIALOG (mc_current->data) == h)
|
||||
this = mc_current;
|
||||
else
|
||||
this = g_list_find (mc_dialogs, h);
|
||||
@ -167,13 +167,13 @@ dialog_switch_remove (Dlg_head * h)
|
||||
|
||||
/* adjust current dialog */
|
||||
if (top_dlg != NULL)
|
||||
mc_current = g_list_find (mc_dialogs, (Dlg_head *) top_dlg->data);
|
||||
mc_current = g_list_find (mc_dialogs, DIALOG (top_dlg->data));
|
||||
else
|
||||
mc_current = mc_dialogs;
|
||||
|
||||
/* resume forced the current screen */
|
||||
if (mc_current != NULL)
|
||||
((Dlg_head *) mc_current->data)->state = DLG_ACTIVE;
|
||||
DIALOG (mc_current->data)->state = DLG_ACTIVE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -240,13 +240,13 @@ dialog_switch_list (void)
|
||||
|
||||
for (h = mc_dialogs; h != NULL; h = g_list_next (h))
|
||||
{
|
||||
Dlg_head *dlg;
|
||||
WDialog *dlg;
|
||||
char *title;
|
||||
|
||||
dlg = (Dlg_head *) h->data;
|
||||
dlg = DIALOG (h->data);
|
||||
|
||||
if ((dlg != NULL) && (dlg->get_title != NULL))
|
||||
title = dlg->get_title (dlg, listbox->list->widget.cols - 2); /* FIXME! */
|
||||
title = dlg->get_title (dlg, WIDGET (listbox->list)->cols - 2);
|
||||
else
|
||||
title = g_strdup ("");
|
||||
|
||||
@ -274,7 +274,7 @@ dialog_switch_process_pending (void)
|
||||
|
||||
while (dialog_switch_pending)
|
||||
{
|
||||
Dlg_head *h = (Dlg_head *) mc_current->data;
|
||||
WDialog *h = DIALOG (mc_current->data);
|
||||
|
||||
dialog_switch_pending = FALSE;
|
||||
h->state = DLG_SUSPENDED;
|
||||
@ -306,7 +306,7 @@ dialog_switch_got_winch (void)
|
||||
|
||||
for (dlg = mc_dialogs; dlg != NULL; dlg = g_list_next (dlg))
|
||||
if (dlg != mc_current)
|
||||
((Dlg_head *) dlg->data)->winch_pending = TRUE;
|
||||
DIALOG (dlg->data)->winch_pending = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -316,7 +316,7 @@ dialog_switch_shutdown (void)
|
||||
{
|
||||
while (mc_dialogs != NULL)
|
||||
{
|
||||
Dlg_head *dlg = (Dlg_head *) mc_dialogs->data;
|
||||
WDialog *dlg = DIALOG (mc_dialogs->data);
|
||||
|
||||
run_dlg (dlg);
|
||||
destroy_dlg (dlg);
|
||||
|
@ -12,12 +12,12 @@
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern Dlg_head *midnight_dlg;
|
||||
extern WDialog *midnight_dlg;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void dialog_switch_add (struct Dlg_head *h);
|
||||
void dialog_switch_remove (struct Dlg_head *h);
|
||||
void dialog_switch_add (struct WDialog *h);
|
||||
void dialog_switch_remove (struct WDialog *h);
|
||||
size_t dialog_switch_num (void);
|
||||
|
||||
void dialog_switch_next (void);
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -16,7 +16,9 @@
|
||||
#include "lib/keybind.h" /* global_keymap_t */
|
||||
#include "lib/tty/mouse.h" /* mouse_h */
|
||||
|
||||
/*** defined constants ***************************************************************************/
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define DIALOG(x) ((WDialog *)(x))
|
||||
|
||||
/* Common return values */
|
||||
#define B_EXIT 0
|
||||
@ -25,39 +27,16 @@
|
||||
#define B_HELP 3
|
||||
#define B_USER 100
|
||||
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + (_y), ((Dlg_head *)(h))->x + (_x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* Dialog messages */
|
||||
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 */
|
||||
} dlg_msg_t;
|
||||
|
||||
/* 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_NONE = 0, /* No options */
|
||||
DLG_CENTER = (1 << 0), /* Center the dialog */
|
||||
DLG_NONE = 0 /* No options */
|
||||
DLG_TRYUP = (1 << 1), /* Try to move two lines up the dialog */
|
||||
DLG_COMPACT = (1 << 2), /* Suppress spaces around the frame */
|
||||
DLG_WANT_TAB = (1 << 3) /* Should the tab key be sent to the dialog? */
|
||||
} dlg_flags_t;
|
||||
|
||||
/* Dialog state */
|
||||
@ -87,20 +66,19 @@ typedef enum
|
||||
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
||||
|
||||
/* get dialog name to show in dialog list */
|
||||
typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
|
||||
typedef char *(*dlg_title_str) (const WDialog * h, size_t len);
|
||||
|
||||
typedef int dlg_colors_t[DLG_COLOR_COUNT];
|
||||
|
||||
/* Dialog callback */
|
||||
typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* menu command execution */
|
||||
typedef cb_ret_t (*menu_exec_fn) (int command);
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct Dlg_head
|
||||
struct WDialog
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
/* Set by the user */
|
||||
gboolean modal; /* type of dialog: modal or not */
|
||||
dlg_flags_t flags; /* User flags */
|
||||
@ -111,10 +89,6 @@ struct Dlg_head
|
||||
/* Set and received by the user */
|
||||
int ret_value; /* Result of run_dlg() */
|
||||
|
||||
/* Geometry */
|
||||
int x, y; /* Position relative to screen origin */
|
||||
int cols, lines; /* Width and height of the window */
|
||||
|
||||
/* Internal flags */
|
||||
dlg_state_t state;
|
||||
gboolean fullscreen; /* Parents dialogs don't need refresh */
|
||||
@ -128,8 +102,6 @@ struct Dlg_head
|
||||
void *data; /* Data can be passed to dialog */
|
||||
char *event_group; /* Name of event group for this dialog */
|
||||
|
||||
dlg_cb_fn callback;
|
||||
mouse_h mouse;
|
||||
dlg_shortcut_str get_shortcut; /* Shortcut string */
|
||||
dlg_title_str get_title; /* useless for modal dialogs */
|
||||
};
|
||||
@ -153,70 +125,67 @@ extern const global_keymap_t *dialog_map;
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* draw box in window */
|
||||
void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
|
||||
void draw_box (const WDialog * h, int y, int x, int ys, int xs, gboolean single);
|
||||
|
||||
/* Creates a dialog head */
|
||||
Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
|
||||
const int *colors, dlg_cb_fn callback, mouse_h mouse_handler,
|
||||
const char *help_ctx, const char *title, dlg_flags_t flags);
|
||||
WDialog *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
|
||||
const int *colors, widget_cb_fn callback, mouse_h mouse_handler,
|
||||
const char *help_ctx, const char *title, dlg_flags_t flags);
|
||||
|
||||
void dlg_set_default_colors (void);
|
||||
|
||||
unsigned long add_widget_autopos (Dlg_head * dest, void *w, widget_pos_flags_t pos_flags,
|
||||
unsigned long add_widget_autopos (WDialog * dest, void *w, widget_pos_flags_t pos_flags,
|
||||
const void *before);
|
||||
unsigned long add_widget (Dlg_head * dest, void *w);
|
||||
unsigned long add_widget_before (Dlg_head * h, void *w, void *before);
|
||||
unsigned long add_widget (WDialog * dest, void *w);
|
||||
unsigned long add_widget_before (WDialog * h, void *w, void *before);
|
||||
void del_widget (void *w);
|
||||
|
||||
/* sets size of dialog, leaving positioning to automatic mehtods
|
||||
according to dialog flags */
|
||||
void dlg_set_size (Dlg_head * h, int lines, int cols);
|
||||
void dlg_set_size (WDialog * h, int lines, int cols);
|
||||
/* this function allows to set dialog position */
|
||||
void dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2);
|
||||
void dlg_set_position (WDialog * h, int y1, int x1, int y2, int x2);
|
||||
|
||||
void init_dlg (Dlg_head * h);
|
||||
int run_dlg (Dlg_head * d);
|
||||
void destroy_dlg (Dlg_head * h);
|
||||
void init_dlg (WDialog * h);
|
||||
int run_dlg (WDialog * d);
|
||||
void destroy_dlg (WDialog * h);
|
||||
|
||||
void dlg_run_done (Dlg_head * h);
|
||||
void dlg_save_history (Dlg_head * h);
|
||||
void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event);
|
||||
void dlg_run_done (WDialog * h);
|
||||
void dlg_save_history (WDialog * h);
|
||||
void dlg_process_event (WDialog * h, int key, Gpm_Event * event);
|
||||
|
||||
char *dlg_get_title (const Dlg_head * h, size_t len);
|
||||
char *dlg_get_title (const WDialog * h, size_t len);
|
||||
|
||||
/* To activate/deactivate the idle message generation */
|
||||
void set_idle_proc (Dlg_head * d, int enable);
|
||||
void dlg_redraw (WDialog * h);
|
||||
|
||||
void dlg_redraw (Dlg_head * h);
|
||||
|
||||
void dlg_broadcast_msg (Dlg_head * h, widget_msg_t message, gboolean reverse);
|
||||
void dlg_broadcast_msg (WDialog * h, widget_msg_t message);
|
||||
|
||||
/* Default callback for dialogs */
|
||||
cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
cb_ret_t dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
|
||||
|
||||
/* Default paint routine for dialogs */
|
||||
void common_dialog_repaint (Dlg_head * h);
|
||||
void dlg_default_repaint (WDialog * h);
|
||||
|
||||
void dlg_replace_widget (Widget * old, Widget * new);
|
||||
int dlg_overlap (Widget * a, Widget * b);
|
||||
void dlg_erase (Dlg_head * h);
|
||||
void dlg_stop (Dlg_head * h);
|
||||
void dlg_erase (WDialog * h);
|
||||
void dlg_stop (WDialog * h);
|
||||
|
||||
/* Widget selection */
|
||||
void dlg_select_widget (void *w);
|
||||
void dlg_set_top_widget (void *w);
|
||||
void dlg_one_up (Dlg_head * h);
|
||||
void dlg_one_down (Dlg_head * h);
|
||||
gboolean dlg_focus (Dlg_head * h);
|
||||
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
||||
Widget *dlg_find_by_id (const Dlg_head * h, unsigned long id);
|
||||
void dlg_select_by_id (const Dlg_head * h, unsigned long id);
|
||||
void dlg_one_up (WDialog * h);
|
||||
void dlg_one_down (WDialog * h);
|
||||
gboolean dlg_focus (WDialog * h);
|
||||
Widget *find_widget_type (const WDialog * h, widget_cb_fn callback);
|
||||
Widget *dlg_find_by_id (const WDialog * h, unsigned long id);
|
||||
void dlg_select_by_id (const WDialog * h, unsigned long id);
|
||||
|
||||
/* Redraw all dialogs */
|
||||
void do_refresh (void);
|
||||
|
||||
/* Used in load_prompt() */
|
||||
void update_cursor (Dlg_head * h);
|
||||
void update_cursor (WDialog * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
@ -224,16 +193,15 @@ void update_cursor (Dlg_head * h);
|
||||
static inline gboolean
|
||||
dlg_widget_active (void *w)
|
||||
{
|
||||
Widget *w1 = (Widget *) w;
|
||||
return ((Widget *) w1->owner->current->data == w1);
|
||||
return (w == WIDGET (w)->owner->current->data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline unsigned long
|
||||
dlg_get_current_widget_id (const struct Dlg_head *h)
|
||||
dlg_get_current_widget_id (const struct WDialog *h)
|
||||
{
|
||||
return ((Widget *) h->current->data)->id;
|
||||
return WIDGET (h->current->data)->id;
|
||||
}
|
||||
|
||||
#endif /* MC__DIALOG_H */
|
||||
|
@ -59,21 +59,21 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
gauge_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WGauge *g = (WGauge *) w;
|
||||
Dlg_head *h = g->widget.owner;
|
||||
WGauge *g = GAUGE (w);
|
||||
WDialog *h = w->owner;
|
||||
|
||||
if (msg == WIDGET_INIT)
|
||||
if (msg == MSG_INIT)
|
||||
return MSG_HANDLED;
|
||||
|
||||
/* We don't want to get the focus */
|
||||
if (msg == WIDGET_FOCUS)
|
||||
if (msg == MSG_FOCUS)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
if (msg == WIDGET_DRAW)
|
||||
if (msg == MSG_DRAW)
|
||||
{
|
||||
widget_move (&g->widget, 0, 0);
|
||||
widget_move (w, 0, 0);
|
||||
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
|
||||
if (!g->shown)
|
||||
tty_printf ("%*s", gauge_len, "");
|
||||
@ -118,7 +118,7 @@ gauge_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -129,9 +129,11 @@ WGauge *
|
||||
gauge_new (int y, int x, gboolean shown, int max, int current)
|
||||
{
|
||||
WGauge *g;
|
||||
Widget *w;
|
||||
|
||||
g = g_new (WGauge, 1);
|
||||
init_widget (&g->widget, y, x, 1, gauge_len, gauge_callback, NULL);
|
||||
w = WIDGET (g);
|
||||
init_widget (w, y, x, 1, gauge_len, gauge_callback, NULL);
|
||||
|
||||
g->shown = shown;
|
||||
if (max == 0)
|
||||
@ -140,8 +142,8 @@ gauge_new (int y, int x, gboolean shown, int max, int current)
|
||||
g->current = current;
|
||||
g->from_left_to_right = TRUE;
|
||||
|
||||
widget_want_cursor (g->widget, FALSE);
|
||||
widget_want_hotkey (g->widget, FALSE);
|
||||
widget_want_cursor (w, FALSE);
|
||||
widget_want_hotkey (w, FALSE);
|
||||
|
||||
return g;
|
||||
}
|
||||
@ -158,7 +160,7 @@ gauge_set_value (WGauge * g, int max, int current)
|
||||
max = 1; /* I do not like division by zero :) */
|
||||
g->current = current;
|
||||
g->max = max;
|
||||
gauge_callback ((Widget *) g, WIDGET_DRAW, 0);
|
||||
gauge_callback (WIDGET (g), NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -169,7 +171,7 @@ gauge_show (WGauge * g, gboolean shown)
|
||||
if (g->shown != shown)
|
||||
{
|
||||
g->shown = shown;
|
||||
gauge_callback ((Widget *) g, WIDGET_DRAW, 0);
|
||||
gauge_callback (WIDGET (g), NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define GAUGE(x) ((WGauge *)(x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
@ -53,41 +53,41 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
groupbox_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WGroupbox *g = (WGroupbox *) w;
|
||||
WGroupbox *g = GROUPBOX (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case MSG_INIT:
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_FOCUS:
|
||||
case MSG_FOCUS:
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
{
|
||||
Widget *wo = WIDGET (w->owner);
|
||||
|
||||
gboolean disabled = (w->options & W_DISABLED) != 0;
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL);
|
||||
draw_box (g->widget.owner, g->widget.y - g->widget.owner->y,
|
||||
g->widget.x - g->widget.owner->x, g->widget.lines, g->widget.cols, TRUE);
|
||||
draw_box (w->owner, w->y - wo->y, w->x - wo->x, w->lines, w->cols, TRUE);
|
||||
|
||||
if (g->title != NULL)
|
||||
{
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE);
|
||||
dlg_move (g->widget.owner, g->widget.y - g->widget.owner->y,
|
||||
g->widget.x - g->widget.owner->x + 1);
|
||||
widget_move (w->owner, w->y - wo->y, w->x - wo->x + 1);
|
||||
tty_print_string (g->title);
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
g_free (g->title);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,15 +99,33 @@ WGroupbox *
|
||||
groupbox_new (int y, int x, int height, int width, const char *title)
|
||||
{
|
||||
WGroupbox *g;
|
||||
Widget *w;
|
||||
|
||||
g = g_new (WGroupbox, 1);
|
||||
init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL);
|
||||
w = WIDGET (g);
|
||||
init_widget (w, y, x, height, width, groupbox_callback, NULL);
|
||||
|
||||
widget_want_cursor (g->widget, FALSE);
|
||||
widget_want_hotkey (g->widget, FALSE);
|
||||
widget_want_cursor (w, FALSE);
|
||||
widget_want_hotkey (w, FALSE);
|
||||
|
||||
g->title = NULL;
|
||||
groupbox_set_title (g, title);
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
groupbox_set_title (WGroupbox *g, const char *title)
|
||||
{
|
||||
Widget *w = WIDGET (g);
|
||||
|
||||
g_free (g->title);
|
||||
g->title = NULL;
|
||||
|
||||
/* Strip existing spaces, add one space before and after the title */
|
||||
if (title != NULL)
|
||||
if (title != NULL && *title != '\0')
|
||||
{
|
||||
char *t;
|
||||
|
||||
@ -116,7 +134,8 @@ groupbox_new (int y, int x, int height, int width, const char *title)
|
||||
g_free (t);
|
||||
}
|
||||
|
||||
return g;
|
||||
if (w->owner != NULL)
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define GROUPBOX(x) ((WGroupbox *)(x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
@ -23,6 +25,7 @@ typedef struct WGroupbox
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WGroupbox *groupbox_new (int y, int x, int height, int width, const char *title);
|
||||
void groupbox_set_title (WGroupbox *g, const char *title);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -73,7 +73,7 @@ typedef struct
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
history_dlg_reposition (Dlg_head * dlg_head)
|
||||
history_dlg_reposition (WDialog * dlg_head)
|
||||
{
|
||||
history_dlg_data *data;
|
||||
int x = 0, y, he, wi;
|
||||
@ -117,15 +117,15 @@ history_dlg_reposition (Dlg_head * dlg_head)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
history_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
history_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_RESIZE:
|
||||
return history_dlg_reposition (h);
|
||||
case MSG_RESIZE:
|
||||
return history_dlg_reposition (DIALOG (w));
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ history_show (GList ** history, Widget * widget, int current)
|
||||
GList *z, *hlist = NULL, *hi;
|
||||
size_t maxlen, i, count = 0;
|
||||
char *r = NULL;
|
||||
Dlg_head *query_dlg;
|
||||
WDialog *query_dlg;
|
||||
WListbox *query_list;
|
||||
history_dlg_data hist_data;
|
||||
|
||||
@ -336,9 +336,9 @@ history_show (GList ** history, Widget * widget, int current)
|
||||
The main idea - create 4x4 dialog and add 2x2 list in
|
||||
center of it, and let dialog function resize it to needed
|
||||
size. */
|
||||
history_dlg_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);
|
||||
send_message (query_dlg, NULL, MSG_RESIZE, 0, NULL);
|
||||
|
||||
if (query_dlg->y < widget->y)
|
||||
if (WIDGET (query_dlg)->y < widget->y)
|
||||
{
|
||||
/* draw list entries from bottom upto top */
|
||||
listbox_set_list (query_list, hlist);
|
||||
@ -369,16 +369,15 @@ history_show (GList ** history, Widget * widget, int current)
|
||||
z = NULL;
|
||||
for (hi = query_list->list; hi != NULL; hi = g_list_next (hi))
|
||||
{
|
||||
WLEntry *entry;
|
||||
WLEntry *entry = LENTRY (hi->data);
|
||||
|
||||
entry = (WLEntry *) hi->data;
|
||||
/* history is being reverted here again */
|
||||
z = g_list_prepend (z, entry->text);
|
||||
entry->text = NULL;
|
||||
}
|
||||
|
||||
/* restore history direction */
|
||||
if (query_dlg->y < widget->y)
|
||||
if (WIDGET (query_dlg)->y < widget->y)
|
||||
z = g_list_reverse (z);
|
||||
|
||||
destroy_dlg (query_dlg);
|
||||
|
@ -54,34 +54,36 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
hline_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WHLine *l = (WHLine *) w;
|
||||
Dlg_head *h = l->widget.owner;
|
||||
WHLine *l = HLINE (w);
|
||||
WDialog *h = w->owner;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case WIDGET_RESIZED:
|
||||
case MSG_INIT:
|
||||
case MSG_RESIZE:
|
||||
if (l->auto_adjust_cols)
|
||||
{
|
||||
if (((w->owner->flags & DLG_COMPACT) != 0))
|
||||
Widget *wo = WIDGET (h);
|
||||
|
||||
if (((h->flags & DLG_COMPACT) != 0))
|
||||
{
|
||||
w->x = w->owner->x;
|
||||
w->cols = w->owner->cols;
|
||||
w->x = wo->x;
|
||||
w->cols = wo->cols;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->x = w->owner->x + 1;
|
||||
w->cols = w->owner->cols - 2;
|
||||
w->x = wo->x + 1;
|
||||
w->cols = wo->cols - 2;
|
||||
}
|
||||
}
|
||||
|
||||
case WIDGET_FOCUS:
|
||||
case MSG_FOCUS:
|
||||
/* We don't want to get the focus */
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
if (l->transparent)
|
||||
tty_setcolor (DEFAULT_COLOR);
|
||||
else
|
||||
@ -99,7 +101,7 @@ hline_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,14 +113,16 @@ WHLine *
|
||||
hline_new (int y, int x, int width)
|
||||
{
|
||||
WHLine *l;
|
||||
Widget *w;
|
||||
int lines = 1;
|
||||
|
||||
l = g_new (WHLine, 1);
|
||||
init_widget (&l->widget, y, x, lines, width, hline_callback, NULL);
|
||||
w = WIDGET (l);
|
||||
init_widget (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL);
|
||||
l->auto_adjust_cols = (width < 0);
|
||||
l->transparent = FALSE;
|
||||
widget_want_cursor (l->widget, FALSE);
|
||||
widget_want_hotkey (l->widget, FALSE);
|
||||
widget_want_cursor (w, FALSE);
|
||||
widget_want_hotkey (w, FALSE);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define HLINE(x) ((WHLine *)(x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
@ -73,7 +73,7 @@ const global_keymap_t *input_map = NULL;
|
||||
|
||||
#define should_show_history_button(in) \
|
||||
(in->history != NULL && in->field_width > HISTORY_BUTTON_WIDTH * 2 + 1 \
|
||||
&& in->widget.owner != NULL)
|
||||
&& WIDGET (in)->owner != NULL)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
@ -103,7 +103,7 @@ static void
|
||||
draw_history_button (WInput * in)
|
||||
{
|
||||
char c;
|
||||
gboolean disabled = (((Widget *) in)->options & W_DISABLED) != 0;
|
||||
gboolean disabled = (WIDGET (in)->options & W_DISABLED) != 0;
|
||||
|
||||
if (g_list_next (in->history_current) == NULL)
|
||||
c = '^';
|
||||
@ -112,12 +112,12 @@ draw_history_button (WInput * in)
|
||||
else
|
||||
c = '|';
|
||||
|
||||
widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH);
|
||||
widget_move (in, 0, in->field_width - HISTORY_BUTTON_WIDTH);
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : in->color[WINPUTC_HISTORY]);
|
||||
|
||||
#ifdef LARGE_HISTORY_BUTTON
|
||||
tty_print_string ("[ ]");
|
||||
widget_move (&in->widget, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1);
|
||||
widget_move (in, 0, in->field_width - HISTORY_BUTTON_WIDTH + 1);
|
||||
#endif
|
||||
|
||||
tty_print_char (c);
|
||||
@ -195,8 +195,7 @@ do_show_hist (WInput * in)
|
||||
|
||||
len = get_history_length (in->history);
|
||||
|
||||
r = history_show (&in->history, &in->widget,
|
||||
g_list_position (in->history_current, in->history));
|
||||
r = history_show (&in->history, WIDGET (in), g_list_position (in->history_current, in->history));
|
||||
if (r != NULL)
|
||||
{
|
||||
input_assign_text (in, r);
|
||||
@ -832,7 +831,7 @@ static gboolean
|
||||
input_load_history (const gchar * event_group_name, const gchar * event_name,
|
||||
gpointer init_data, gpointer data)
|
||||
{
|
||||
WInput *in = (WInput *) init_data;
|
||||
WInput *in = INPUT (init_data);
|
||||
ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
|
||||
const char *def_text;
|
||||
size_t buffer_len;
|
||||
@ -875,12 +874,12 @@ static gboolean
|
||||
input_save_history (const gchar * event_group_name, const gchar * event_name,
|
||||
gpointer init_data, gpointer data)
|
||||
{
|
||||
WInput *in = (WInput *) init_data;
|
||||
WInput *in = INPUT (init_data);
|
||||
|
||||
(void) event_group_name;
|
||||
(void) event_name;
|
||||
|
||||
if (!in->is_password && (((Widget *) in)->owner->ret_value != B_CANCEL))
|
||||
if (!in->is_password && (WIDGET (in)->owner->ret_value != B_CANCEL))
|
||||
{
|
||||
ev_history_load_save_t *ev = (ev_history_load_save_t *) data;
|
||||
|
||||
@ -929,8 +928,8 @@ input_destroy (WInput * in)
|
||||
static int
|
||||
input_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
WInput *in = (WInput *) data;
|
||||
Widget *w = (Widget *) data;
|
||||
WInput *in = INPUT (data);
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
return MOU_UNHANDLED;
|
||||
@ -972,6 +971,25 @@ input_event (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Callback for applying new options to input widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param options options set
|
||||
* @param enable TRUE if specified options should be added, FALSE if options should be removed
|
||||
*/
|
||||
static void
|
||||
input_set_options_callback (Widget * w, widget_options_t options, gboolean enable)
|
||||
{
|
||||
WInput *in = INPUT (w);
|
||||
|
||||
widget_default_set_options_callback (w, options, enable);
|
||||
if (in->label != NULL)
|
||||
widget_set_options (WIDGET (in->label), options, enable);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -991,10 +1009,13 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex
|
||||
const char *histname, input_complete_t completion_flags)
|
||||
{
|
||||
WInput *in;
|
||||
Widget *w;
|
||||
|
||||
in = g_new (WInput, 1);
|
||||
init_widget (&in->widget, y, x, 1, width, input_callback, input_event);
|
||||
in->widget.options |= W_IS_INPUT;
|
||||
w = WIDGET (in);
|
||||
init_widget (w, y, x, 1, width, input_callback, input_event);
|
||||
w->options |= W_IS_INPUT;
|
||||
w->set_options = input_set_options_callback;
|
||||
|
||||
memmove (in->color, input_colors, sizeof (input_colors_t));
|
||||
|
||||
@ -1026,30 +1047,31 @@ input_new (int y, int x, const int *input_colors, int width, const char *def_tex
|
||||
in->history_name = NULL;
|
||||
if ((histname != NULL) && (*histname != '\0'))
|
||||
in->history_name = g_strdup (histname);
|
||||
|
||||
/* history will be loaded later */
|
||||
|
||||
in->label = NULL;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
cb_ret_t
|
||||
input_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WInput *in = (WInput *) w;
|
||||
WInput *in = INPUT (w);
|
||||
cb_ret_t v;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case MSG_INIT:
|
||||
/* subscribe to "history_load" event */
|
||||
mc_event_add (w->owner->event_group, MCEVENT_HISTORY_LOAD, input_load_history, w, NULL);
|
||||
/* subscribe to "history_save" event */
|
||||
mc_event_add (w->owner->event_group, MCEVENT_HISTORY_SAVE, input_save_history, w, NULL);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
if (parm == XCTRL ('q'))
|
||||
{
|
||||
quote = 1;
|
||||
@ -1074,21 +1096,21 @@ input_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
|
||||
return input_handle_char (in, parm);
|
||||
|
||||
case WIDGET_COMMAND:
|
||||
case MSG_ACTION:
|
||||
return input_execute_cmd (in, parm);
|
||||
|
||||
case WIDGET_FOCUS:
|
||||
case WIDGET_UNFOCUS:
|
||||
case WIDGET_DRAW:
|
||||
case MSG_FOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_DRAW:
|
||||
case MSG_RESIZE:
|
||||
input_update (in, FALSE);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
widget_move (&in->widget, 0, str_term_width2 (in->buffer, in->point)
|
||||
- in->term_first_shown);
|
||||
case MSG_CURSOR:
|
||||
widget_move (in, 0, str_term_width2 (in->buffer, in->point) - in->term_first_shown);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
/* unsubscribe from "history_load" event */
|
||||
mc_event_del (w->owner->event_group, MCEVENT_HISTORY_LOAD, input_load_history, w);
|
||||
/* unsubscribe from "history_save" event */
|
||||
@ -1097,7 +1119,7 @@ input_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1124,8 +1146,8 @@ input_get_default_colors (void)
|
||||
void
|
||||
input_set_origin (WInput * in, int x, int field_width)
|
||||
{
|
||||
in->widget.x = x;
|
||||
in->field_width = in->widget.cols = field_width;
|
||||
WIDGET (in)->x = x;
|
||||
in->field_width = WIDGET (in)->cols = field_width;
|
||||
input_update (in, FALSE);
|
||||
}
|
||||
|
||||
@ -1268,17 +1290,21 @@ input_update (WInput * in, gboolean clear_first)
|
||||
/* Adjust the mark */
|
||||
in->mark = min (in->mark, buf_len);
|
||||
|
||||
/* don't draw widget not put into dialog */
|
||||
if (WIDGET(in)->owner == NULL)
|
||||
return;
|
||||
|
||||
if (has_history != 0)
|
||||
draw_history_button (in);
|
||||
|
||||
if ((((Widget *) in)->options & W_DISABLED) != 0)
|
||||
if ((WIDGET (in)->options & W_DISABLED) != 0)
|
||||
tty_setcolor (DISABLED_COLOR);
|
||||
else if (in->first)
|
||||
tty_setcolor (in->color[WINPUTC_UNCHANGED]);
|
||||
else
|
||||
tty_setcolor (in->color[WINPUTC_MAIN]);
|
||||
|
||||
widget_move (&in->widget, 0, 0);
|
||||
widget_move (in, 0, 0);
|
||||
|
||||
if (!in->is_password)
|
||||
{
|
||||
@ -1298,7 +1324,7 @@ input_update (WInput * in, gboolean clear_first)
|
||||
tty_setcolor (in->color[WINPUTC_MARK]);
|
||||
if (m1 < in->term_first_shown)
|
||||
{
|
||||
widget_move (&in->widget, 0, 0);
|
||||
widget_move (in, 0, 0);
|
||||
tty_print_string (str_term_substring
|
||||
(in->buffer, in->term_first_shown,
|
||||
m2 - in->term_first_shown));
|
||||
@ -1307,7 +1333,7 @@ input_update (WInput * in, gboolean clear_first)
|
||||
{
|
||||
int sel_width;
|
||||
|
||||
widget_move (&in->widget, 0, m1 - in->term_first_shown);
|
||||
widget_move (in, 0, m1 - in->term_first_shown);
|
||||
sel_width =
|
||||
min (m2 - m1,
|
||||
(in->field_width - has_history) - (str_term_width2 (in->buffer, m1) -
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define INPUT(x) ((WInput *)(x))
|
||||
|
||||
/* For history load-save functions */
|
||||
#define INPUT_LAST_TEXT ((char *) 2)
|
||||
|
||||
@ -68,6 +70,7 @@ typedef struct
|
||||
input_complete_t completion_flags;
|
||||
char charbuf[MB_LEN_MAX]; /* buffer for multibytes characters */
|
||||
size_t charpoint; /* point to end of mulibyte sequence in charbuf */
|
||||
WLabel *label; /* label associated with this input line*/
|
||||
} WInput;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
@ -82,7 +85,7 @@ WInput *input_new (int y, int x, const int *input_colors,
|
||||
int len, const char *text, const char *histname,
|
||||
input_complete_t completion_flags);
|
||||
/* callbac is public; needed for command line */
|
||||
cb_ret_t input_callback (Widget * w, widget_msg_t msg, int parm);
|
||||
cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
|
||||
const int *input_get_default_colors (void);
|
||||
void input_set_origin (WInput * i, int x, int field_width);
|
||||
cb_ret_t input_handle_char (WInput * in, int key);
|
||||
|
@ -1048,14 +1048,16 @@ insert_text (WInput * in, char *text, ssize_t size)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
static char buff[MB_LEN_MAX] = "";
|
||||
static int bl = 0;
|
||||
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_KEY:
|
||||
case MSG_KEY:
|
||||
switch (parm)
|
||||
{
|
||||
case KEY_LEFT:
|
||||
@ -1090,17 +1092,17 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da
|
||||
|
||||
new_end = str_get_prev_char (&input->buffer[end]) - input->buffer;
|
||||
|
||||
for (i = 0, e = ((WListbox *) h->current->data)->list;
|
||||
for (i = 0, e = LISTBOX (h->current->data)->list;
|
||||
e != NULL; i++, e = g_list_next (e))
|
||||
{
|
||||
WLEntry *le = (WLEntry *) e->data;
|
||||
WLEntry *le = LENTRY (e->data);
|
||||
|
||||
if (strncmp (input->buffer + start, le->text, new_end - start) == 0)
|
||||
{
|
||||
listbox_select_entry ((WListbox *) h->current->data, i);
|
||||
listbox_select_entry (LISTBOX (h->current->data), i);
|
||||
end = new_end;
|
||||
input_handle_char (input, parm);
|
||||
send_message ((Widget *) h->current->data, WIDGET_DRAW, 0);
|
||||
send_message (h->current->data, NULL, MSG_DRAW, 0, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1141,10 +1143,10 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
for (i = 0, e = ((WListbox *) h->current->data)->list;
|
||||
for (i = 0, e = LISTBOX (h->current->data)->list;
|
||||
e != NULL; i++, e = g_list_next (e))
|
||||
{
|
||||
WLEntry *le = (WLEntry *) e->data;
|
||||
WLEntry *le = LENTRY (e->data);
|
||||
|
||||
if (strncmp (input->buffer + start, le->text, end - start) == 0
|
||||
&& strncmp (&le->text[end - start], buff, bl) == 0)
|
||||
@ -1152,7 +1154,7 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da
|
||||
if (need_redraw == 0)
|
||||
{
|
||||
need_redraw = 1;
|
||||
listbox_select_entry ((WListbox *) h->current->data, i);
|
||||
listbox_select_entry (LISTBOX (h->current->data), i);
|
||||
last_text = le->text;
|
||||
}
|
||||
else
|
||||
@ -1203,7 +1205,7 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da
|
||||
if (need_redraw == 2)
|
||||
{
|
||||
insert_text (input, last_text, low);
|
||||
send_message ((Widget *) h->current->data, WIDGET_DRAW, 0);
|
||||
send_message (h->current->data, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
else if (need_redraw == 1)
|
||||
{
|
||||
@ -1217,7 +1219,7 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da
|
||||
break;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1281,7 +1283,7 @@ complete_engine (WInput * in, int what_to_do)
|
||||
int x, y, w, h;
|
||||
int start_x, start_y;
|
||||
char **p, *q;
|
||||
Dlg_head *query_dlg;
|
||||
WDialog *query_dlg;
|
||||
WListbox *query_list;
|
||||
|
||||
for (p = in->completions + 1; *p != NULL; count++, p++)
|
||||
@ -1290,8 +1292,8 @@ complete_engine (WInput * in, int what_to_do)
|
||||
if (i > maxlen)
|
||||
maxlen = i;
|
||||
}
|
||||
start_x = in->widget.x;
|
||||
start_y = in->widget.y;
|
||||
start_x = WIDGET (in)->x;
|
||||
start_y = WIDGET (in)->y;
|
||||
if (start_y - 2 >= count)
|
||||
{
|
||||
y = start_y - 2 - count;
|
||||
|
@ -57,39 +57,45 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
label_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
label_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WLabel *l = (WLabel *) w;
|
||||
Dlg_head *h = l->widget.owner;
|
||||
WLabel *l = LABEL (w);
|
||||
WDialog *h = w->owner;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case MSG_INIT:
|
||||
return MSG_HANDLED;
|
||||
|
||||
/* We don't want to get the focus */
|
||||
case WIDGET_FOCUS:
|
||||
case MSG_FOCUS:
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
{
|
||||
char *p = l->text;
|
||||
int y = 0;
|
||||
gboolean disabled = (w->options & W_DISABLED) != 0;
|
||||
gboolean disabled;
|
||||
align_crt_t align;
|
||||
|
||||
if (l->text == NULL)
|
||||
return MSG_HANDLED;
|
||||
|
||||
disabled = (w->options & W_DISABLED) != 0;
|
||||
|
||||
if (l->transparent)
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : DEFAULT_COLOR);
|
||||
else
|
||||
tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]);
|
||||
|
||||
align = (w->pos_flags & WPOS_CENTER_HORZ) != 0 ? J_CENTER_LEFT : J_LEFT;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
char *q;
|
||||
char c = '\0';
|
||||
|
||||
|
||||
q = strchr (p, '\n');
|
||||
if (q != NULL)
|
||||
{
|
||||
@ -97,8 +103,8 @@ label_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
q[0] = '\0';
|
||||
}
|
||||
|
||||
widget_move (&l->widget, y, 0);
|
||||
tty_print_string (str_fit_to_term (p, l->widget.cols, J_LEFT));
|
||||
widget_move (w, y, 0);
|
||||
tty_print_string (str_fit_to_term (p, w->cols, align));
|
||||
|
||||
if (q == NULL)
|
||||
break;
|
||||
@ -110,12 +116,12 @@ label_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
g_free (l->text);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,6 +133,7 @@ WLabel *
|
||||
label_new (int y, int x, const char *text)
|
||||
{
|
||||
WLabel *l;
|
||||
Widget *w;
|
||||
int cols = 1;
|
||||
int lines = 1;
|
||||
|
||||
@ -134,12 +141,14 @@ label_new (int y, int x, const char *text)
|
||||
str_msg_term_size (text, &lines, &cols);
|
||||
|
||||
l = g_new (WLabel, 1);
|
||||
init_widget (&l->widget, y, x, lines, cols, label_callback, NULL);
|
||||
w = WIDGET (l);
|
||||
init_widget (w, y, x, lines, cols, label_callback, NULL);
|
||||
|
||||
l->text = g_strdup (text);
|
||||
l->auto_adjust_cols = TRUE;
|
||||
l->transparent = FALSE;
|
||||
widget_want_cursor (l->widget, FALSE);
|
||||
widget_want_hotkey (l->widget, FALSE);
|
||||
widget_want_cursor (w, FALSE);
|
||||
widget_want_hotkey (w, FALSE);
|
||||
|
||||
return l;
|
||||
}
|
||||
@ -149,7 +158,8 @@ label_new (int y, int x, const char *text)
|
||||
void
|
||||
label_set_text (WLabel * label, const char *text)
|
||||
{
|
||||
int newcols = label->widget.cols;
|
||||
Widget *w = WIDGET (label);
|
||||
int newcols = w->cols;
|
||||
int newlines;
|
||||
|
||||
if (label->text != NULL && text != NULL && strcmp (label->text, text) == 0)
|
||||
@ -165,18 +175,18 @@ label_set_text (WLabel * label, const char *text)
|
||||
if (label->auto_adjust_cols)
|
||||
{
|
||||
str_msg_term_size (text, &newlines, &newcols);
|
||||
if (newcols > label->widget.cols)
|
||||
label->widget.cols = newcols;
|
||||
if (newlines > label->widget.lines)
|
||||
label->widget.lines = newlines;
|
||||
if (newcols > w->cols)
|
||||
w->cols = newcols;
|
||||
if (newlines > w->lines)
|
||||
w->lines = newlines;
|
||||
}
|
||||
}
|
||||
|
||||
if (label->widget.owner != NULL)
|
||||
label_callback ((Widget *) label, WIDGET_DRAW, 0);
|
||||
if (w->owner != NULL)
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
|
||||
if (newcols < label->widget.cols)
|
||||
label->widget.cols = newcols;
|
||||
if (newcols < w->cols)
|
||||
w->cols = newcols;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define LABEL(x) ((WLabel *)(x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
@ -113,7 +113,7 @@ create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
|
||||
listbox->dlg =
|
||||
create_dlg (TRUE, ypos, xpos, lines + space, cols + space,
|
||||
listbox_colors, NULL, NULL, help, title, DLG_REVERSE | DLG_TRYUP);
|
||||
listbox_colors, NULL, NULL, help, title, DLG_TRYUP);
|
||||
|
||||
listbox->list = listbox_new (2, 2, lines, cols, FALSE, NULL);
|
||||
add_widget (listbox->dlg, listbox->list);
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct Dlg_head *dlg;
|
||||
struct WDialog *dlg;
|
||||
struct WListbox *list;
|
||||
} Listbox;
|
||||
|
||||
|
@ -83,31 +83,32 @@ listbox_entry_free (void *data)
|
||||
static void
|
||||
listbox_drawscroll (WListbox * l)
|
||||
{
|
||||
const int max_line = l->widget.lines - 1;
|
||||
Widget *w = WIDGET (l);
|
||||
int max_line = w->lines - 1;
|
||||
int line = 0;
|
||||
int i;
|
||||
|
||||
/* Are we at the top? */
|
||||
widget_move (&l->widget, 0, l->widget.cols);
|
||||
widget_move (w, 0, w->cols);
|
||||
if (l->top == 0)
|
||||
tty_print_one_vline (TRUE);
|
||||
else
|
||||
tty_print_char ('^');
|
||||
|
||||
/* Are we at the bottom? */
|
||||
widget_move (&l->widget, max_line, l->widget.cols);
|
||||
if ((l->top + l->widget.lines == l->count) || (l->widget.lines >= l->count))
|
||||
widget_move (w, max_line, w->cols);
|
||||
if ((l->top + w->lines == l->count) || (w->lines >= l->count))
|
||||
tty_print_one_vline (TRUE);
|
||||
else
|
||||
tty_print_char ('v');
|
||||
|
||||
/* Now draw the nice relative pointer */
|
||||
if (l->count != 0)
|
||||
line = 1 + ((l->pos * (l->widget.lines - 2)) / l->count);
|
||||
line = 1 + ((l->pos * (w->lines - 2)) / l->count);
|
||||
|
||||
for (i = 1; i < max_line; i++)
|
||||
{
|
||||
widget_move (&l->widget, i, l->widget.cols);
|
||||
widget_move (w, i, w->cols);
|
||||
if (i != line)
|
||||
tty_print_one_vline (TRUE);
|
||||
else
|
||||
@ -120,8 +121,9 @@ listbox_drawscroll (WListbox * l)
|
||||
static void
|
||||
listbox_draw (WListbox * l, gboolean focused)
|
||||
{
|
||||
const Dlg_head *h = l->widget.owner;
|
||||
const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0;
|
||||
Widget *w = WIDGET (l);
|
||||
const WDialog *h = w->owner;
|
||||
const gboolean disabled = (w->options & W_DISABLED) != 0;
|
||||
const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL];
|
||||
/* *INDENT-OFF* */
|
||||
int selc = disabled
|
||||
@ -140,7 +142,7 @@ listbox_draw (WListbox * l, gboolean focused)
|
||||
/* pos = (le == NULL) ? 0 : g_list_position (l->list, le); */
|
||||
pos = (le == NULL) ? 0 : l->top;
|
||||
|
||||
for (i = 0; i < l->widget.lines; i++)
|
||||
for (i = 0; i < w->lines; i++)
|
||||
{
|
||||
const char *text;
|
||||
|
||||
@ -153,24 +155,25 @@ listbox_draw (WListbox * l, gboolean focused)
|
||||
else
|
||||
tty_setcolor (normalc);
|
||||
|
||||
widget_move (&l->widget, i, 1);
|
||||
widget_move (l, i, 1);
|
||||
|
||||
if ((i > 0 && pos >= l->count) || (l->list == NULL) || (le == NULL))
|
||||
text = "";
|
||||
else
|
||||
{
|
||||
WLEntry *e = (WLEntry *) le->data;
|
||||
WLEntry *e = LENTRY (le->data);
|
||||
|
||||
text = e->text;
|
||||
le = g_list_next (le);
|
||||
pos++;
|
||||
}
|
||||
|
||||
tty_print_string (str_fit_to_term (text, l->widget.cols - 2, J_LEFT_FIT));
|
||||
tty_print_string (str_fit_to_term (text, w->cols - 2, J_LEFT_FIT));
|
||||
}
|
||||
|
||||
l->cursor_y = sel_line;
|
||||
|
||||
if (l->scrollbar && (l->count > l->widget.lines))
|
||||
if (l->scrollbar && (l->count > w->lines))
|
||||
{
|
||||
tty_setcolor (normalc);
|
||||
listbox_drawscroll (l);
|
||||
@ -187,7 +190,7 @@ listbox_check_hotkey (WListbox * l, int key)
|
||||
|
||||
for (i = 0, le = l->list; le != NULL; i++, le = g_list_next (le))
|
||||
{
|
||||
WLEntry *e = (WLEntry *) le->data;
|
||||
WLEntry *e = LENTRY (le->data);
|
||||
|
||||
if (e->hotkey == key)
|
||||
return i;
|
||||
@ -239,6 +242,7 @@ listbox_execute_cmd (WListbox * l, unsigned long command)
|
||||
{
|
||||
cb_ret_t ret = MSG_HANDLED;
|
||||
int i;
|
||||
Widget *w = WIDGET (l);
|
||||
|
||||
switch (command)
|
||||
{
|
||||
@ -255,18 +259,18 @@ listbox_execute_cmd (WListbox * l, unsigned long command)
|
||||
listbox_select_last (l);
|
||||
break;
|
||||
case CK_PageUp:
|
||||
for (i = 0; (i < l->widget.lines - 1) && (l->pos > 0); i++)
|
||||
for (i = 0; (i < w->lines - 1) && (l->pos > 0); i++)
|
||||
listbox_back (l);
|
||||
break;
|
||||
case CK_PageDown:
|
||||
for (i = 0; (i < l->widget.lines - 1) && (l->pos < l->count - 1); i++)
|
||||
for (i = 0; (i < w->lines - 1) && (l->pos < l->count - 1); i++)
|
||||
listbox_fwd (l);
|
||||
break;
|
||||
case CK_Delete:
|
||||
if (l->deletable)
|
||||
{
|
||||
gboolean is_last = (l->pos + 1 >= l->count);
|
||||
gboolean is_more = (l->top + l->widget.lines >= l->count);
|
||||
gboolean is_more = (l->top + w->lines >= l->count);
|
||||
|
||||
listbox_remove_current (l);
|
||||
if ((l->top > 0) && (is_last || is_more))
|
||||
@ -306,7 +310,7 @@ listbox_key (WListbox * l, int key)
|
||||
listbox_select_entry (l, key - '0');
|
||||
|
||||
/* need scroll to item? */
|
||||
if (abs (oldpos - l->pos) > l->widget.lines)
|
||||
if (abs (oldpos - l->pos) > WIDGET (l)->lines)
|
||||
l->top = l->pos;
|
||||
|
||||
return MSG_HANDLED;
|
||||
@ -362,18 +366,18 @@ listbox_destroy (WListbox * l)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
listbox_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WListbox *l = (WListbox *) w;
|
||||
Dlg_head *h = l->widget.owner;
|
||||
WListbox *l = LISTBOX (w);
|
||||
WDialog *h = w->owner;
|
||||
cb_ret_t ret_code;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case MSG_INIT:
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_HOTKEY:
|
||||
case MSG_HOTKEY:
|
||||
{
|
||||
int pos, action;
|
||||
|
||||
@ -382,7 +386,7 @@ listbox_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
listbox_select_entry (l, pos);
|
||||
h->callback (h, w, DLG_ACTION, l->pos, NULL);
|
||||
send_message (h, w, MSG_ACTION, l->pos, NULL);
|
||||
|
||||
if (l->callback != NULL)
|
||||
action = l->callback (l);
|
||||
@ -398,38 +402,38 @@ listbox_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
ret_code = listbox_key (l, parm);
|
||||
if (ret_code != MSG_NOT_HANDLED)
|
||||
{
|
||||
listbox_draw (l, TRUE);
|
||||
h->callback (h, w, DLG_ACTION, l->pos, NULL);
|
||||
send_message (h, w, MSG_ACTION, l->pos, NULL);
|
||||
}
|
||||
return ret_code;
|
||||
|
||||
case WIDGET_COMMAND:
|
||||
case MSG_ACTION:
|
||||
return listbox_execute_cmd (l, parm);
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
widget_move (&l->widget, l->cursor_y, 0);
|
||||
h->callback (h, w, DLG_ACTION, l->pos, NULL);
|
||||
case MSG_CURSOR:
|
||||
widget_move (l, l->cursor_y, 0);
|
||||
send_message (h, w, MSG_ACTION, l->pos, NULL);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_FOCUS:
|
||||
case WIDGET_UNFOCUS:
|
||||
case WIDGET_DRAW:
|
||||
listbox_draw (l, msg != WIDGET_UNFOCUS);
|
||||
case MSG_FOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_DRAW:
|
||||
listbox_draw (l, msg != MSG_UNFOCUS);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
listbox_destroy (l);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_RESIZED:
|
||||
case MSG_RESIZE:
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,8 +442,8 @@ listbox_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
static int
|
||||
listbox_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
WListbox *l = (WListbox *) data;
|
||||
Widget *w = (Widget *) data;
|
||||
WListbox *l = LISTBOX (data);
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
return MOU_UNHANDLED;
|
||||
@ -516,12 +520,14 @@ WListbox *
|
||||
listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback)
|
||||
{
|
||||
WListbox *l;
|
||||
Widget *w;
|
||||
|
||||
if (height <= 0)
|
||||
height = 1;
|
||||
|
||||
l = g_new (WListbox, 1);
|
||||
init_widget (&l->widget, y, x, height, width, listbox_callback, listbox_event);
|
||||
w = WIDGET (l);
|
||||
init_widget (w, y, x, height, width, listbox_callback, listbox_event);
|
||||
|
||||
l->list = NULL;
|
||||
l->top = l->pos = 0;
|
||||
@ -530,8 +536,8 @@ listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn
|
||||
l->callback = callback;
|
||||
l->allow_duplicates = TRUE;
|
||||
l->scrollbar = !mc_global.tty.slow_terminal;
|
||||
widget_want_hotkey (l->widget, TRUE);
|
||||
widget_want_cursor (l->widget, FALSE);
|
||||
widget_want_hotkey (w, TRUE);
|
||||
widget_want_cursor (w, FALSE);
|
||||
|
||||
return l;
|
||||
}
|
||||
@ -548,7 +554,7 @@ listbox_search_text (WListbox * l, const char *text)
|
||||
|
||||
for (i = 0, le = l->list; le != NULL; i++, le = g_list_next (le))
|
||||
{
|
||||
WLEntry *e = (WLEntry *) le->data;
|
||||
WLEntry *e = LENTRY (le->data);
|
||||
|
||||
if (strcmp (e->text, text) == 0)
|
||||
return i;
|
||||
@ -573,8 +579,10 @@ listbox_select_first (WListbox * l)
|
||||
void
|
||||
listbox_select_last (WListbox * l)
|
||||
{
|
||||
int lines = WIDGET (l)->lines;
|
||||
|
||||
l->pos = l->count - 1;
|
||||
l->top = l->count > l->widget.lines ? l->count - l->widget.lines : 0;
|
||||
l->top = l->count > lines ? l->count - lines : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -600,8 +608,13 @@ listbox_select_entry (WListbox * l, int dest)
|
||||
l->pos = dest;
|
||||
if (!top_seen)
|
||||
l->top = l->pos;
|
||||
else if (l->pos - l->top >= l->widget.lines)
|
||||
l->top = l->pos - l->widget.lines + 1;
|
||||
else
|
||||
{
|
||||
int lines = WIDGET (l)->lines;
|
||||
|
||||
if (l->pos - l->top >= lines)
|
||||
l->top = l->pos - lines + 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -620,7 +633,7 @@ listbox_get_current (WListbox * l, char **string, void **extra)
|
||||
gboolean ok;
|
||||
|
||||
if (l != NULL)
|
||||
e = (WLEntry *) g_list_nth_data (l->list, l->pos);
|
||||
e = LENTRY (g_list_nth_data (l->list, l->pos));
|
||||
|
||||
ok = (e != NULL);
|
||||
|
||||
@ -642,7 +655,7 @@ listbox_remove_current (WListbox * l)
|
||||
|
||||
current = g_list_nth (l->list, l->pos);
|
||||
l->list = g_list_remove_link (l->list, current);
|
||||
listbox_entry_free ((WLEntry *) current->data);
|
||||
listbox_entry_free (LENTRY (current->data));
|
||||
g_list_free_1 (current);
|
||||
l->count--;
|
||||
|
||||
|
@ -10,6 +10,9 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define LISTBOX(x) ((WListbox *)(x))
|
||||
#define LENTRY(x) ((WLEntry *)(x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* callback should return one of the following values */
|
||||
|
@ -49,17 +49,37 @@
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define MENUENTRY(x) ((menu_entry_t *)(x))
|
||||
#define MENU(x) ((menu_t *)(x))
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
struct menu_entry_t
|
||||
{
|
||||
unsigned char first_letter;
|
||||
hotkey_t text;
|
||||
unsigned long command;
|
||||
char *shortcut;
|
||||
};
|
||||
|
||||
static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm);
|
||||
struct menu_t
|
||||
{
|
||||
int start_x; /* position relative to menubar start */
|
||||
hotkey_t text;
|
||||
GList *entries;
|
||||
size_t max_entry_len; /* cached max length of entry texts (text + shortcut) */
|
||||
size_t max_hotkey_len; /* cached max length of shortcuts */
|
||||
unsigned int selected; /* pointer to current menu entry */
|
||||
char *help_node;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
menu_arrange (menu_t * menu, dlg_shortcut_str get_shortcut)
|
||||
{
|
||||
if (menu != NULL)
|
||||
{
|
||||
@ -71,7 +91,7 @@ menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
|
||||
for (i = menu->entries; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
menu_entry_t *entry = i->data;
|
||||
menu_entry_t *entry = MENUENTRY (i->data);
|
||||
|
||||
if (entry != NULL)
|
||||
{
|
||||
@ -100,26 +120,24 @@ menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
static void
|
||||
menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
{
|
||||
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
|
||||
Widget *w = WIDGET (menubar);
|
||||
const menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
const menu_entry_t *entry = MENUENTRY (g_list_nth_data (menu->entries, idx));
|
||||
const int y = 2 + idx;
|
||||
int x = menu->start_x;
|
||||
|
||||
if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
|
||||
x = menubar->widget.cols - menu->max_entry_len - 4;
|
||||
if (x + menu->max_entry_len + 4 > (gsize) w->cols)
|
||||
x = w->cols - menu->max_entry_len - 4;
|
||||
|
||||
if (entry == NULL)
|
||||
{
|
||||
/* menu separator */
|
||||
tty_setcolor (MENU_ENTRY_COLOR);
|
||||
|
||||
widget_move (&menubar->widget, y, x - 1);
|
||||
widget_move (w, y, x - 1);
|
||||
tty_print_alt_char (ACS_LTEE, FALSE);
|
||||
|
||||
tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
|
||||
ACS_HLINE, menu->max_entry_len + 3);
|
||||
|
||||
widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
|
||||
tty_draw_hline (w->y + y, w->x + x, ACS_HLINE, menu->max_entry_len + 3);
|
||||
widget_move (w, y, x + menu->max_entry_len + 3);
|
||||
tty_print_alt_char (ACS_RTEE, FALSE);
|
||||
}
|
||||
else
|
||||
@ -128,7 +146,7 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
|
||||
/* menu text */
|
||||
tty_setcolor (color);
|
||||
widget_move (&menubar->widget, y, x);
|
||||
widget_move (w, y, x);
|
||||
tty_print_char ((unsigned char) entry->first_letter);
|
||||
tty_getyx (&yt, &xt);
|
||||
tty_draw_hline (yt, xt, ' ', menu->max_entry_len + 2); /* clear line */
|
||||
@ -146,12 +164,12 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
|
||||
if (entry->shortcut != NULL)
|
||||
{
|
||||
widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
|
||||
widget_move (w, y, x + menu->max_hotkey_len + 3);
|
||||
tty_print_string (entry->shortcut);
|
||||
}
|
||||
|
||||
/* move cursor to the start of entry text */
|
||||
widget_move (&menubar->widget, y, x + 1);
|
||||
widget_move (w, y, x + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -160,18 +178,17 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
static void
|
||||
menubar_draw_drop (WMenuBar * menubar)
|
||||
{
|
||||
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
Widget *w = WIDGET (menubar);
|
||||
const menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
const unsigned int count = g_list_length (menu->entries);
|
||||
int column = menu->start_x - 1;
|
||||
unsigned int i;
|
||||
|
||||
if (column + menu->max_entry_len + 5 > (gsize) menubar->widget.cols)
|
||||
column = menubar->widget.cols - menu->max_entry_len - 5;
|
||||
if (column + menu->max_entry_len + 5 > (gsize) w->cols)
|
||||
column = w->cols - menu->max_entry_len - 5;
|
||||
|
||||
tty_setcolor (MENU_ENTRY_COLOR);
|
||||
draw_box (menubar->widget.owner,
|
||||
menubar->widget.y + 1, menubar->widget.x + column,
|
||||
count + 2, menu->max_entry_len + 5, FALSE);
|
||||
draw_box (w->owner, w->y + 1, w->x + column, count + 2, menu->max_entry_len + 5, FALSE);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
menubar_paint_idx (menubar, i,
|
||||
@ -196,20 +213,21 @@ menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
|
||||
static void
|
||||
menubar_draw (WMenuBar * menubar)
|
||||
{
|
||||
Widget *w = WIDGET (menubar);
|
||||
GList *i;
|
||||
|
||||
/* First draw the complete menubar */
|
||||
tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR);
|
||||
tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
|
||||
tty_draw_hline (w->y, w->x, ' ', w->cols);
|
||||
|
||||
/* Now each one of the entries */
|
||||
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
Menu *menu = i->data;
|
||||
menu_t *menu = MENU (i->data);
|
||||
gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i));
|
||||
|
||||
menubar_set_color (menubar, is_selected, FALSE);
|
||||
widget_move (&menubar->widget, 0, menu->start_x);
|
||||
widget_move (w, 0, menu->start_x);
|
||||
|
||||
tty_print_char (' ');
|
||||
tty_print_string (menu->text.start);
|
||||
@ -230,8 +248,8 @@ menubar_draw (WMenuBar * menubar)
|
||||
if (menubar->is_dropped)
|
||||
menubar_draw_drop (menubar);
|
||||
else
|
||||
widget_move (&menubar->widget, 0,
|
||||
((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x);
|
||||
widget_move (w, 0,
|
||||
MENU (g_list_nth_data (menubar->menu, menubar->selected))->start_x);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -239,7 +257,7 @@ menubar_draw (WMenuBar * menubar)
|
||||
static void
|
||||
menubar_remove (WMenuBar * menubar)
|
||||
{
|
||||
Dlg_head *h;
|
||||
WDialog *h;
|
||||
|
||||
if (!menubar->is_dropped)
|
||||
return;
|
||||
@ -248,7 +266,7 @@ menubar_remove (WMenuBar * menubar)
|
||||
of overlapped widgets. This is useful in multi-window editor.
|
||||
In general, menubar should be a special object, not an ordinary widget
|
||||
in the current dialog. */
|
||||
h = menubar->widget.owner;
|
||||
h = WIDGET (menubar)->owner;
|
||||
h->current = g_list_find (h->widgets, dlg_find_by_id (h, menubar->previous_widget));
|
||||
|
||||
menubar->is_dropped = FALSE;
|
||||
@ -287,12 +305,14 @@ menubar_right (WMenuBar * menubar)
|
||||
static void
|
||||
menubar_finish (WMenuBar * menubar)
|
||||
{
|
||||
Widget *w = WIDGET (menubar);
|
||||
|
||||
menubar->is_dropped = FALSE;
|
||||
menubar->is_active = FALSE;
|
||||
menubar->widget.lines = 1;
|
||||
widget_want_hotkey (menubar->widget, 0);
|
||||
w->lines = 1;
|
||||
widget_want_hotkey (w, 0);
|
||||
|
||||
dlg_select_by_id (menubar->widget.owner, menubar->previous_widget);
|
||||
dlg_select_by_id (w->owner, menubar->previous_widget);
|
||||
do_refresh ();
|
||||
}
|
||||
|
||||
@ -311,15 +331,16 @@ menubar_drop (WMenuBar * menubar, unsigned int selected)
|
||||
static void
|
||||
menubar_execute (WMenuBar * menubar)
|
||||
{
|
||||
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected);
|
||||
const menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
const menu_entry_t *entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));
|
||||
|
||||
if ((entry != NULL) && (entry->command != CK_IgnoreKey))
|
||||
{
|
||||
Widget *w = WIDGET (menubar);
|
||||
|
||||
mc_global.widget.is_right = (menubar->selected != 0);
|
||||
menubar_finish (menubar);
|
||||
menubar->widget.owner->callback (menubar->widget.owner, &menubar->widget,
|
||||
DLG_ACTION, entry->command, NULL);
|
||||
send_message (w->owner, w, MSG_ACTION, entry->command, NULL);
|
||||
do_refresh ();
|
||||
}
|
||||
}
|
||||
@ -329,7 +350,7 @@ menubar_execute (WMenuBar * menubar)
|
||||
static void
|
||||
menubar_down (WMenuBar * menubar)
|
||||
{
|
||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
const unsigned int len = g_list_length (menu->entries);
|
||||
menu_entry_t *entry;
|
||||
|
||||
@ -338,7 +359,7 @@ menubar_down (WMenuBar * menubar)
|
||||
do
|
||||
{
|
||||
menu->selected = (menu->selected + 1) % len;
|
||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||
entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));
|
||||
}
|
||||
while ((entry == NULL) || (entry->command == CK_IgnoreKey));
|
||||
|
||||
@ -350,7 +371,7 @@ menubar_down (WMenuBar * menubar)
|
||||
static void
|
||||
menubar_up (WMenuBar * menubar)
|
||||
{
|
||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
const unsigned int len = g_list_length (menu->entries);
|
||||
menu_entry_t *entry;
|
||||
|
||||
@ -362,7 +383,7 @@ menubar_up (WMenuBar * menubar)
|
||||
menu->selected = len - 1;
|
||||
else
|
||||
menu->selected--;
|
||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||
entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));
|
||||
}
|
||||
while ((entry == NULL) || (entry->command == CK_IgnoreKey));
|
||||
|
||||
@ -374,7 +395,7 @@ menubar_up (WMenuBar * menubar)
|
||||
static void
|
||||
menubar_first (WMenuBar * menubar)
|
||||
{
|
||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
menu_entry_t *entry;
|
||||
|
||||
if (menu->selected == 0)
|
||||
@ -386,7 +407,7 @@ menubar_first (WMenuBar * menubar)
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||
entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));
|
||||
|
||||
if ((entry == NULL) || (entry->command == CK_IgnoreKey))
|
||||
menu->selected++;
|
||||
@ -402,7 +423,7 @@ menubar_first (WMenuBar * menubar)
|
||||
static void
|
||||
menubar_last (WMenuBar * menubar)
|
||||
{
|
||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
const unsigned int len = g_list_length (menu->entries);
|
||||
menu_entry_t *entry;
|
||||
|
||||
@ -416,7 +437,7 @@ menubar_last (WMenuBar * menubar)
|
||||
do
|
||||
{
|
||||
menu->selected--;
|
||||
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
||||
entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));
|
||||
}
|
||||
while ((entry == NULL) || (entry->command == CK_IgnoreKey));
|
||||
|
||||
@ -447,7 +468,7 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
|
||||
if (menubar->is_dropped)
|
||||
event_data.node =
|
||||
((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->help_node;
|
||||
MENU (g_list_nth_data (menubar->menu, menubar->selected))->help_node;
|
||||
else
|
||||
event_data.node = "[Menu Bar]";
|
||||
|
||||
@ -473,7 +494,7 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
/* drop menu by hotkey */
|
||||
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
Menu *menu = i->data;
|
||||
menu_t *menu = MENU (i->data);
|
||||
|
||||
if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0])))
|
||||
{
|
||||
@ -490,13 +511,13 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
}
|
||||
|
||||
{
|
||||
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
||||
menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
GList *i;
|
||||
|
||||
/* execute menu command by hotkey */
|
||||
for (i = menu->entries; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
const menu_entry_t *entry = i->data;
|
||||
const menu_entry_t *entry = MENUENTRY (i->data);
|
||||
|
||||
if ((entry != NULL) && (entry->command != CK_IgnoreKey)
|
||||
&& (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0])))
|
||||
@ -543,28 +564,28 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WMenuBar *menubar = (WMenuBar *) w;
|
||||
WMenuBar *menubar = MENUBAR (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
/* We do not want the focus unless we have been activated */
|
||||
case WIDGET_FOCUS:
|
||||
case MSG_FOCUS:
|
||||
if (!menubar->is_active)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
/* Trick to get all the mouse events */
|
||||
menubar->widget.lines = LINES;
|
||||
w->lines = LINES;
|
||||
|
||||
/* Trick to get all of the hotkeys */
|
||||
widget_want_hotkey (menubar->widget, 1);
|
||||
widget_want_hotkey (w, 1);
|
||||
menubar_draw (menubar);
|
||||
return MSG_HANDLED;
|
||||
|
||||
/* We don't want the buttonbar to activate while using the menubar */
|
||||
case WIDGET_HOTKEY:
|
||||
case WIDGET_KEY:
|
||||
case MSG_HOTKEY:
|
||||
case MSG_KEY:
|
||||
if (menubar->is_active)
|
||||
{
|
||||
menubar_handle_key (menubar, parm);
|
||||
@ -572,14 +593,14 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
case MSG_CURSOR:
|
||||
/* Put the cursor in a suitable place */
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_UNFOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
if (menubar->is_visible)
|
||||
{
|
||||
menubar_draw (menubar);
|
||||
@ -587,18 +608,18 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
/* fall through */
|
||||
|
||||
case WIDGET_RESIZED:
|
||||
case MSG_RESIZE:
|
||||
/* try show menu after screen resize */
|
||||
send_message (w, WIDGET_FOCUS, 0);
|
||||
send_message (w, sender, MSG_FOCUS, 0, data);
|
||||
return MSG_HANDLED;
|
||||
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
menubar_set_menu (menubar, NULL);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -607,11 +628,11 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
static int
|
||||
menubar_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
WMenuBar *menubar = (WMenuBar *) data;
|
||||
Widget *w = (Widget *) data;
|
||||
WMenuBar *menubar = MENUBAR (data);
|
||||
Widget *w = WIDGET (data);
|
||||
gboolean was_active = TRUE;
|
||||
int left_x, right_x, bottom_y;
|
||||
Menu *menu;
|
||||
menu_t *menu;
|
||||
Gpm_Event local;
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
@ -652,8 +673,7 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
unsigned int new_selection = 0;
|
||||
|
||||
while ((new_selection < len)
|
||||
&& (local.x > ((Menu *) g_list_nth_data (menubar->menu,
|
||||
new_selection))->start_x))
|
||||
&& (local.x > MENU (g_list_nth_data (menubar->menu, new_selection))->start_x))
|
||||
new_selection++;
|
||||
|
||||
if (new_selection != 0) /* Don't set the invalid value -1 */
|
||||
@ -685,13 +705,13 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
}
|
||||
|
||||
/* the mouse operation is on the menus or it is not */
|
||||
menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected);
|
||||
menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
|
||||
left_x = menu->start_x;
|
||||
right_x = left_x + menu->max_entry_len + 3;
|
||||
if (right_x > menubar->widget.cols)
|
||||
if (right_x > w->cols)
|
||||
{
|
||||
left_x = menubar->widget.cols - menu->max_entry_len - 3;
|
||||
right_x = menubar->widget.cols;
|
||||
left_x = w->cols - menu->max_entry_len - 3;
|
||||
right_x = w->cols;
|
||||
}
|
||||
|
||||
bottom_y = g_list_length (menu->entries) + 3;
|
||||
@ -699,7 +719,7 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
if ((local.x >= left_x) && (local.x <= right_x) && (local.y <= bottom_y))
|
||||
{
|
||||
int pos = local.y - 3;
|
||||
const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
|
||||
const menu_entry_t *entry = MENUENTRY (g_list_nth_data (menu->entries, pos));
|
||||
|
||||
/* mouse wheel */
|
||||
if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
|
||||
@ -769,12 +789,12 @@ menu_entry_free (menu_entry_t * entry)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Menu *
|
||||
menu_t *
|
||||
create_menu (const char *name, GList * entries, const char *help_node)
|
||||
{
|
||||
Menu *menu;
|
||||
menu_t *menu;
|
||||
|
||||
menu = g_new (Menu, 1);
|
||||
menu = g_new (menu_t, 1);
|
||||
menu->start_x = 0;
|
||||
menu->text = parse_hotkey (name);
|
||||
menu->entries = entries;
|
||||
@ -789,7 +809,7 @@ create_menu (const char *name, GList * entries, const char *help_node)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menu_set_name (Menu * menu, const char *name)
|
||||
menu_set_name (menu_t * menu, const char *name)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
menu->text = parse_hotkey (name);
|
||||
@ -798,7 +818,7 @@ menu_set_name (Menu * menu, const char *name)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
destroy_menu (Menu * menu)
|
||||
destroy_menu (menu_t * menu)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
||||
@ -813,11 +833,14 @@ WMenuBar *
|
||||
menubar_new (int y, int x, int cols, GList * menu)
|
||||
{
|
||||
WMenuBar *menubar;
|
||||
Widget *w;
|
||||
|
||||
menubar = g_new0 (WMenuBar, 1);
|
||||
init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event);
|
||||
widget_want_cursor (menubar->widget, FALSE);
|
||||
w = WIDGET (menubar);
|
||||
init_widget (w, y, x, 1, cols, menubar_callback, menubar_event);
|
||||
|
||||
menubar->is_visible = TRUE; /* by default */
|
||||
widget_want_cursor (w, FALSE);
|
||||
menubar_set_menu (menubar, menu);
|
||||
|
||||
return menubar;
|
||||
@ -845,11 +868,11 @@ menubar_set_menu (WMenuBar * menubar, GList * menu)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menubar_add_menu (WMenuBar * menubar, Menu * menu)
|
||||
menubar_add_menu (WMenuBar * menubar, menu_t * menu)
|
||||
{
|
||||
if (menu != NULL)
|
||||
{
|
||||
menu_arrange (menu, menubar->widget.owner->get_shortcut);
|
||||
menu_arrange (menu, WIDGET (menubar)->owner->get_shortcut);
|
||||
menubar->menu = g_list_append (menubar->menu, menu);
|
||||
}
|
||||
|
||||
@ -872,12 +895,13 @@ menubar_arrange (WMenuBar * menubar)
|
||||
if (menubar->menu == NULL)
|
||||
return;
|
||||
|
||||
gap = menubar->widget.cols - 2;
|
||||
gap = WIDGET (menubar)->cols - 2;
|
||||
|
||||
/* First, calculate gap between items... */
|
||||
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
Menu *menu = (Menu *) i->data;
|
||||
menu_t *menu = MENU (i->data);
|
||||
|
||||
/* preserve length here, to be used below */
|
||||
menu->start_x = hotkey_width (menu->text) + 2;
|
||||
gap -= menu->start_x;
|
||||
@ -899,7 +923,7 @@ menubar_arrange (WMenuBar * menubar)
|
||||
/* ...and now fix start positions of menubar items */
|
||||
for (i = menubar->menu; i != NULL; i = g_list_next (i))
|
||||
{
|
||||
Menu *menu = (Menu *) i->data;
|
||||
menu_t *menu = MENU (i->data);
|
||||
int len = menu->start_x;
|
||||
|
||||
menu->start_x = start_x;
|
||||
@ -911,9 +935,9 @@ menubar_arrange (WMenuBar * menubar)
|
||||
/** Find MenuBar widget in the dialog */
|
||||
|
||||
WMenuBar *
|
||||
find_menubar (const Dlg_head * h)
|
||||
find_menubar (const WDialog * h)
|
||||
{
|
||||
return (WMenuBar *) find_widget_type (h, menubar_callback);
|
||||
return MENUBAR (find_widget_type (h, menubar_callback));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -11,30 +11,19 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define MENUBAR(x) ((WMenuBar *)(x))
|
||||
|
||||
#define menu_separator_create() NULL
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct menu_entry_t
|
||||
{
|
||||
unsigned char first_letter;
|
||||
hotkey_t text;
|
||||
unsigned long command;
|
||||
char *shortcut;
|
||||
} menu_entry_t;
|
||||
struct menu_entry_t;
|
||||
typedef struct menu_entry_t menu_entry_t;
|
||||
|
||||
typedef struct Menu
|
||||
{
|
||||
int start_x; /* position relative to menubar start */
|
||||
hotkey_t text;
|
||||
GList *entries;
|
||||
size_t max_entry_len; /* cached max length of entry texts (text + shortcut) */
|
||||
size_t max_hotkey_len; /* cached max length of shortcuts */
|
||||
unsigned int selected; /* pointer to current menu entry */
|
||||
char *help_node;
|
||||
} Menu;
|
||||
struct menu_t;
|
||||
typedef struct menu_t menu_t;
|
||||
|
||||
/* The button bar menu */
|
||||
typedef struct WMenuBar
|
||||
@ -56,16 +45,16 @@ typedef struct WMenuBar
|
||||
menu_entry_t *menu_entry_create (const char *name, unsigned long command);
|
||||
void menu_entry_free (menu_entry_t * me);
|
||||
|
||||
Menu *create_menu (const char *name, GList * entries, const char *help_node);
|
||||
void menu_set_name (Menu * menu, const char *name);
|
||||
void destroy_menu (Menu * menu);
|
||||
menu_t *create_menu (const char *name, GList * entries, const char *help_node);
|
||||
void menu_set_name (menu_t * menu, const char *name);
|
||||
void destroy_menu (menu_t * menu);
|
||||
|
||||
WMenuBar *menubar_new (int y, int x, int cols, GList * menu);
|
||||
void menubar_set_menu (WMenuBar * menubar, GList * menu);
|
||||
void menubar_add_menu (WMenuBar * menubar, Menu * menu);
|
||||
void menubar_add_menu (WMenuBar * menubar, menu_t * menu);
|
||||
void menubar_arrange (WMenuBar * menubar);
|
||||
|
||||
WMenuBar *find_menubar (const Dlg_head * h);
|
||||
WMenuBar *find_menubar (const WDialog * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
Widget based utility functions.
|
||||
|
||||
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Authors:
|
||||
@ -10,7 +10,7 @@
|
||||
Radek Doulik, 1994, 1995
|
||||
Jakub Jelinek, 1995
|
||||
Andrej Borsenkow, 1995
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2011, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
#include <stdio.h> /* fprintf() */
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/strutil.h" /* str_term_width1() */
|
||||
#include "lib/util.h" /* tilde_expand() */
|
||||
#include "lib/widget.h"
|
||||
|
||||
@ -45,119 +46,520 @@
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
#define I18N(x) (x = x != NULL && *x != '\0' ? _(x) : x)
|
||||
#else
|
||||
#define I18N(x) (x = x)
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Widget *widget;
|
||||
quick_widget_t *quick_widget;
|
||||
} quick_widget_item_t;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static WInput *
|
||||
quick_create_input (int y, int x, const quick_widget_t * qw)
|
||||
{
|
||||
WInput *in;
|
||||
|
||||
in = input_new (y, x, input_get_default_colors (), 8, qw->u.input.text, qw->u.input.histname,
|
||||
INPUT_COMPLETE_DEFAULT);
|
||||
in->is_password = (qw->u.input.flags == 1);
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
in->completion_flags |= INPUT_COMPLETE_CD;
|
||||
if ((qw->u.input.flags & 4) != 0)
|
||||
in->strip_password = TRUE;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
quick_create_labeled_input (GArray * widgets, int *y, int x, quick_widget_t * quick_widget,
|
||||
int *width)
|
||||
{
|
||||
quick_widget_item_t in, label;
|
||||
|
||||
label.quick_widget = g_new0 (quick_widget_t, 1);
|
||||
label.quick_widget->widget_type = quick_label;
|
||||
label.quick_widget->options = quick_widget->options;
|
||||
/* FIXME: this should be turned in depend of label_location */
|
||||
label.quick_widget->pos_flags = quick_widget->pos_flags;
|
||||
|
||||
switch (quick_widget->u.input.label_location)
|
||||
{
|
||||
case input_label_above:
|
||||
label.widget = WIDGET (label_new (*y, x, I18N (quick_widget->u.input.label_text)));
|
||||
*y += label.widget->lines - 1;
|
||||
g_array_append_val (widgets, label);
|
||||
|
||||
in.widget = WIDGET (quick_create_input (++(*y), x, quick_widget));
|
||||
in.quick_widget = quick_widget;
|
||||
g_array_append_val (widgets, in);
|
||||
|
||||
*width = max (label.widget->cols, in.widget->cols);
|
||||
break;
|
||||
|
||||
case input_label_left:
|
||||
label.widget = WIDGET (label_new (*y, x, I18N (quick_widget->u.input.label_text)));
|
||||
g_array_append_val (widgets, label);
|
||||
|
||||
in.widget = WIDGET (quick_create_input (*y, x + label.widget->cols + 1, quick_widget));
|
||||
in.quick_widget = quick_widget;
|
||||
g_array_append_val (widgets, in);
|
||||
|
||||
*width = label.widget->cols + in.widget->cols + 1;
|
||||
break;
|
||||
|
||||
case input_label_right:
|
||||
in.widget = WIDGET (quick_create_input (*y, x, quick_widget));
|
||||
in.quick_widget = quick_widget;
|
||||
g_array_append_val (widgets, in);
|
||||
|
||||
label.widget =
|
||||
WIDGET (label_new
|
||||
(*y, x + in.widget->cols + 1, I18N (quick_widget->u.input.label_text)));
|
||||
g_array_append_val (widgets, label);
|
||||
|
||||
*width = label.widget->cols + in.widget->cols + 1;
|
||||
break;
|
||||
|
||||
case input_label_below:
|
||||
in.widget = WIDGET (quick_create_input (*y, x, quick_widget));
|
||||
in.quick_widget = quick_widget;
|
||||
g_array_append_val (widgets, in);
|
||||
|
||||
label.widget = WIDGET (label_new (++(*y), x, I18N (quick_widget->u.input.label_text)));
|
||||
*y += label.widget->lines - 1;
|
||||
g_array_append_val (widgets, label);
|
||||
|
||||
*width = max (label.widget->cols, in.widget->cols);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
INPUT (in.widget)->label = LABEL (label.widget);
|
||||
/* cross references */
|
||||
label.quick_widget->u.label.input = in.quick_widget;
|
||||
in.quick_widget->u.input.label = label.quick_widget;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
#define I18N(x) (x = !qd->i18n && x != NULL && *x != '\0' ? _(x): x)
|
||||
#else
|
||||
#define I18N(x) (x = x)
|
||||
#endif
|
||||
Dlg_head *dd;
|
||||
QuickWidget *qw;
|
||||
WInput *in;
|
||||
WRadio *r;
|
||||
int len;
|
||||
int blen = 0;
|
||||
int x, y; /* current positions */
|
||||
int y1 = 0; /* bottom of 1st column in case of two columns */
|
||||
int y2 = -1; /* start of two columns */
|
||||
int width1 = 0; /* width of single column */
|
||||
int width2 = 0; /* width of each of two columns*/
|
||||
gboolean have_groupbox = FALSE;
|
||||
gboolean two_columns = FALSE;
|
||||
gboolean put_buttons = FALSE;
|
||||
|
||||
/* x position of 1st column is 3 */
|
||||
const int x1 = 3;
|
||||
/* x position of 2nd column is 4 and it will be fixed later, after creation of all widgets */
|
||||
int x2 = 4;
|
||||
|
||||
GArray *widgets;
|
||||
size_t i;
|
||||
quick_widget_t *quick_widget;
|
||||
WGroupbox *g = NULL;
|
||||
WDialog *dd;
|
||||
int return_val;
|
||||
|
||||
I18N (qd->title);
|
||||
len = str_term_width1 (I18N (quick_dlg->title)) + 6;
|
||||
quick_dlg->cols = max (quick_dlg->cols, len);
|
||||
|
||||
if ((qd->xpos == -1) || (qd->ypos == -1))
|
||||
dd = create_dlg (TRUE, 0, 0, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->mouse, qd->help, qd->title,
|
||||
DLG_CENTER | DLG_TRYUP | DLG_REVERSE);
|
||||
else
|
||||
dd = create_dlg (TRUE, qd->ypos, qd->xpos, qd->ylen, qd->xlen,
|
||||
dialog_colors, qd->callback, qd->mouse, qd->help, qd->title, DLG_REVERSE);
|
||||
y = 1;
|
||||
x = x1;
|
||||
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
/* create widgets */
|
||||
widgets = g_array_sized_new (FALSE, FALSE, sizeof (quick_widget_item_t), 8);
|
||||
|
||||
for (quick_widget = quick_dlg->widgets; quick_widget->widget_type != quick_end; quick_widget++)
|
||||
{
|
||||
int xpos;
|
||||
int ypos;
|
||||
quick_widget_item_t item = { NULL, quick_widget };
|
||||
int width = 0;
|
||||
|
||||
xpos = (qd->xlen * qw->relative_x) / qw->x_divisions;
|
||||
ypos = (qd->ylen * qw->relative_y) / qw->y_divisions;
|
||||
|
||||
switch (qw->widget_type)
|
||||
switch (quick_widget->widget_type)
|
||||
{
|
||||
case quick_checkbox:
|
||||
qw->widget =
|
||||
(Widget *) check_new (ypos, xpos, *qw->u.checkbox.state,
|
||||
I18N (qw->u.checkbox.text));
|
||||
item.widget =
|
||||
WIDGET (check_new
|
||||
(++y, x, *quick_widget->u.checkbox.state,
|
||||
I18N (quick_widget->u.checkbox.text)));
|
||||
g_array_append_val (widgets, item);
|
||||
width = item.widget->cols;
|
||||
if (g != NULL)
|
||||
width += 2;
|
||||
if (two_columns)
|
||||
width2 = max (width2, width);
|
||||
else
|
||||
width1 = max (width1, width);
|
||||
break;
|
||||
|
||||
case quick_button:
|
||||
qw->widget = (Widget *) button_new (ypos, xpos, qw->u.button.action,
|
||||
(qw->u.button.action ==
|
||||
B_ENTER) ? DEFPUSH_BUTTON : NORMAL_BUTTON,
|
||||
I18N (qw->u.button.text), qw->u.button.callback);
|
||||
/* single button */
|
||||
item.widget = WIDGET (button_new (++y, x, quick_widget->u.button.action,
|
||||
quick_widget->u.button.action == B_ENTER ?
|
||||
DEFPUSH_BUTTON : NORMAL_BUTTON,
|
||||
I18N (quick_widget->u.button.text),
|
||||
quick_widget->u.button.callback));
|
||||
g_array_append_val (widgets, item);
|
||||
width = item.widget->cols;
|
||||
if (g != NULL)
|
||||
width += 2;
|
||||
if (two_columns)
|
||||
width2 = max (width2, width);
|
||||
else
|
||||
width1 = max (width1, width);
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
in = input_new (ypos, xpos, input_get_default_colors (),
|
||||
qw->u.input.len, qw->u.input.text, qw->u.input.histname,
|
||||
INPUT_COMPLETE_DEFAULT);
|
||||
in->is_password = (qw->u.input.flags == 1);
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
in->completion_flags |= INPUT_COMPLETE_CD;
|
||||
if ((qw->u.input.flags & 4) != 0)
|
||||
in->strip_password = TRUE;
|
||||
qw->widget = (Widget *) in;
|
||||
*qw->u.input.result = NULL;
|
||||
*quick_widget->u.input.result = NULL;
|
||||
y++;
|
||||
if (quick_widget->u.input.label_location != input_label_none)
|
||||
quick_create_labeled_input (widgets, &y, x, quick_widget, &width);
|
||||
else
|
||||
{
|
||||
item.widget = WIDGET (quick_create_input (y, x, quick_widget));
|
||||
g_array_append_val (widgets, item);
|
||||
width = item.widget->cols;
|
||||
}
|
||||
if (g != NULL)
|
||||
width += 2;
|
||||
if (two_columns)
|
||||
width2 = max (width2, width);
|
||||
else
|
||||
width1 = max (width1, width);
|
||||
break;
|
||||
|
||||
case quick_label:
|
||||
qw->widget = (Widget *) label_new (ypos, xpos, I18N (qw->u.label.text));
|
||||
break;
|
||||
|
||||
case quick_groupbox:
|
||||
qw->widget = (Widget *) groupbox_new (ypos, xpos,
|
||||
qw->u.groupbox.height,
|
||||
qw->u.groupbox.width,
|
||||
I18N (qw->u.groupbox.title));
|
||||
item.widget = WIDGET (label_new (++y, x, I18N (quick_widget->u.label.text)));
|
||||
g_array_append_val (widgets, item);
|
||||
y += item.widget->lines - 1;
|
||||
width = item.widget->cols;
|
||||
if (g != NULL)
|
||||
width += 2;
|
||||
if (two_columns)
|
||||
width2 = max (width2, width);
|
||||
else
|
||||
width1 = max (width1, width);
|
||||
break;
|
||||
|
||||
case quick_radio:
|
||||
{
|
||||
int i;
|
||||
WRadio *r;
|
||||
char **items = NULL;
|
||||
|
||||
/* create the copy of radio_items to avoid mwmory leak */
|
||||
items = g_new0 (char *, qw->u.radio.count + 1);
|
||||
items = g_new (char *, quick_widget->u.radio.count + 1);
|
||||
for (i = 0; i < (size_t) quick_widget->u.radio.count; i++)
|
||||
items[i] = g_strdup (_(quick_widget->u.radio.items[i]));
|
||||
items[i] = NULL;
|
||||
|
||||
if (!qd->i18n)
|
||||
for (i = 0; i < qw->u.radio.count; i++)
|
||||
items[i] = g_strdup (_(qw->u.radio.items[i]));
|
||||
else
|
||||
for (i = 0; i < qw->u.radio.count; i++)
|
||||
items[i] = g_strdup (qw->u.radio.items[i]);
|
||||
|
||||
r = radio_new (ypos, xpos, qw->u.radio.count, (const char **) items);
|
||||
r->pos = r->sel = *qw->u.radio.value;
|
||||
qw->widget = (Widget *) r;
|
||||
r = radio_new (++y, x, quick_widget->u.radio.count, (const char **) items);
|
||||
r->pos = r->sel = *quick_widget->u.radio.value;
|
||||
g_strfreev (items);
|
||||
break;
|
||||
item.widget = WIDGET (r);
|
||||
g_array_append_val (widgets, item);
|
||||
y += item.widget->lines - 1;
|
||||
width = item.widget->cols;
|
||||
if (g != NULL)
|
||||
width += 2;
|
||||
if (two_columns)
|
||||
width2 = max (width2, width);
|
||||
else
|
||||
width1 = max (width1, width);
|
||||
}
|
||||
break;
|
||||
|
||||
case quick_start_groupbox:
|
||||
I18N (quick_widget->u.groupbox.title);
|
||||
len = str_term_width1 (quick_widget->u.groupbox.title);
|
||||
g = groupbox_new (++y, x, 1, len + 4, quick_widget->u.groupbox.title);
|
||||
item.widget = WIDGET (g);
|
||||
g_array_append_val (widgets, item);
|
||||
have_groupbox = TRUE;
|
||||
break;
|
||||
|
||||
case quick_stop_groupbox:
|
||||
if (g != NULL)
|
||||
{
|
||||
Widget *w = WIDGET (g);
|
||||
|
||||
y++;
|
||||
w->lines = y + 1 - w->y;
|
||||
g = NULL;
|
||||
|
||||
g_array_append_val (widgets, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case quick_separator:
|
||||
y++;
|
||||
if (quick_widget->u.separator.line)
|
||||
{
|
||||
item.widget = WIDGET (hline_new (y, x, 1));
|
||||
g_array_append_val (widgets, item);
|
||||
}
|
||||
break;
|
||||
|
||||
case quick_start_columns:
|
||||
y2 = y;
|
||||
g_array_append_val (widgets, item);
|
||||
two_columns = TRUE;
|
||||
break;
|
||||
|
||||
case quick_next_column:
|
||||
x = x2;
|
||||
y1 = y;
|
||||
y = y2;
|
||||
break;
|
||||
|
||||
case quick_stop_columns:
|
||||
x = x1;
|
||||
y = max (y1, y);
|
||||
g_array_append_val (widgets, item);
|
||||
two_columns = FALSE;
|
||||
break;
|
||||
|
||||
case quick_buttons:
|
||||
/* start put several buttons in bottom line */
|
||||
if (quick_widget->u.separator.space)
|
||||
{
|
||||
y++;
|
||||
|
||||
if (quick_widget->u.separator.line)
|
||||
item.widget = WIDGET (hline_new (y, 1, -1));
|
||||
}
|
||||
|
||||
g_array_append_val (widgets, item);
|
||||
|
||||
/* several buttons in bottom line */
|
||||
y++;
|
||||
quick_widget++;
|
||||
for (; quick_widget->widget_type == quick_button; quick_widget++)
|
||||
{
|
||||
item.widget = WIDGET (button_new (y, x++, quick_widget->u.button.action,
|
||||
quick_widget->u.button.action == B_ENTER ?
|
||||
DEFPUSH_BUTTON : NORMAL_BUTTON,
|
||||
I18N (quick_widget->u.button.text),
|
||||
quick_widget->u.button.callback));
|
||||
item.quick_widget = quick_widget;
|
||||
g_array_append_val (widgets, item);
|
||||
blen += item.widget->cols + 1;
|
||||
}
|
||||
|
||||
/* stop dialog build here */
|
||||
blen--;
|
||||
quick_widget->widget_type = quick_end;
|
||||
quick_widget--;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* adjust dialog width */
|
||||
quick_dlg->cols = max (quick_dlg->cols, blen + 6);
|
||||
if (have_groupbox)
|
||||
{
|
||||
if (width1 != 0)
|
||||
width1 += 2;
|
||||
if (width2 != 0)
|
||||
width2 += 2;
|
||||
}
|
||||
if (width2 == 0)
|
||||
len = width1 + 6;
|
||||
else
|
||||
{
|
||||
len = width2 * 2 + 7;
|
||||
if (width1 != 0)
|
||||
len = max (len, width1 + 6);
|
||||
}
|
||||
|
||||
quick_dlg->cols = max (quick_dlg->cols, len);
|
||||
width1 = quick_dlg->cols - 6;
|
||||
width2 = (quick_dlg->cols - 7) / 2;
|
||||
|
||||
if (quick_dlg->x == -1 || quick_dlg->y == -1)
|
||||
dd = create_dlg (TRUE, 0, 0, y + 3, quick_dlg->cols,
|
||||
dialog_colors, quick_dlg->callback, quick_dlg->mouse, quick_dlg->help,
|
||||
quick_dlg->title, DLG_CENTER | DLG_TRYUP);
|
||||
else
|
||||
dd = create_dlg (TRUE, quick_dlg->y, quick_dlg->x, y + 3, quick_dlg->cols,
|
||||
dialog_colors, quick_dlg->callback, quick_dlg->mouse, quick_dlg->help,
|
||||
quick_dlg->title, DLG_NONE);
|
||||
|
||||
/* add widgets into the dialog */
|
||||
x2 = x1 + width2 + 1;
|
||||
g = NULL;
|
||||
two_columns = FALSE;
|
||||
x = (WIDGET (dd)->cols - blen) / 2;
|
||||
|
||||
for (i = 0; i < widgets->len; i++)
|
||||
{
|
||||
quick_widget_item_t *item;
|
||||
int column_width;
|
||||
|
||||
item = &g_array_index (widgets, quick_widget_item_t, i);
|
||||
column_width = two_columns ? width2 : width1;
|
||||
|
||||
/* adjust widget width and x position */
|
||||
switch (item->quick_widget->widget_type)
|
||||
{
|
||||
case quick_label:
|
||||
{
|
||||
quick_widget_t *input = item->quick_widget->u.label.input;
|
||||
|
||||
if (input != NULL && input->u.input.label_location == input_label_right)
|
||||
{
|
||||
/* location of this label will be adjusted later */
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* fall through */
|
||||
case quick_checkbox:
|
||||
case quick_radio:
|
||||
if (item->widget->x != x1)
|
||||
item->widget->x = x2;
|
||||
if (g != NULL)
|
||||
item->widget->x += 2;
|
||||
break;
|
||||
|
||||
case quick_button:
|
||||
if (!put_buttons)
|
||||
{
|
||||
if (item->widget->x != x1)
|
||||
item->widget->x = x2;
|
||||
if (g != NULL)
|
||||
item->widget->x += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
item->widget->x = x;
|
||||
x += item->widget->cols + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
{
|
||||
Widget *label = WIDGET (INPUT (item->widget)->label);
|
||||
int width = column_width;
|
||||
|
||||
if (g != NULL)
|
||||
width -= 4;
|
||||
|
||||
switch (item->quick_widget->u.input.label_location)
|
||||
{
|
||||
case input_label_left:
|
||||
/* label was adjusted before; adjust input line */
|
||||
item->widget->x = label->x + label->cols + 1 - WIDGET (label->owner)->x;
|
||||
item->widget->cols = width - label->cols - 1;
|
||||
break;
|
||||
|
||||
case input_label_right:
|
||||
label->x =
|
||||
item->widget->x + item->widget->cols + 1 - WIDGET (item->widget->owner)->x;
|
||||
item->widget->cols = width - label->cols - 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (item->widget->x != x1)
|
||||
item->widget->x = x2;
|
||||
if (g != NULL)
|
||||
item->widget->x += 2;
|
||||
item->widget->cols = width;
|
||||
break;
|
||||
}
|
||||
|
||||
/* forced update internal variables of inpuit line */
|
||||
input_set_origin (INPUT (item->widget), item->widget->x, item->widget->cols);
|
||||
}
|
||||
break;
|
||||
|
||||
case quick_start_groupbox:
|
||||
g = GROUPBOX (item->widget);
|
||||
if (item->widget->x != x1)
|
||||
item->widget->x = x2;
|
||||
item->widget->cols = column_width;
|
||||
break;
|
||||
|
||||
case quick_stop_groupbox:
|
||||
g = NULL;
|
||||
break;
|
||||
|
||||
case quick_separator:
|
||||
if (item->widget != NULL)
|
||||
{
|
||||
if (g != NULL)
|
||||
{
|
||||
Widget *wg = WIDGET (g);
|
||||
|
||||
HLINE (item->widget)->auto_adjust_cols = FALSE;
|
||||
item->widget->x = wg->x + 1 - WIDGET (wg->owner)->x;
|
||||
item->widget->cols = wg->cols;
|
||||
}
|
||||
else if (two_columns)
|
||||
{
|
||||
HLINE (item->widget)->auto_adjust_cols = FALSE;
|
||||
if (item->widget->x != x1)
|
||||
item->widget->x = x2;
|
||||
item->widget->x--;
|
||||
item->widget->cols = column_width + 2;
|
||||
}
|
||||
else
|
||||
HLINE (item->widget)->auto_adjust_cols = TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case quick_start_columns:
|
||||
two_columns = TRUE;
|
||||
break;
|
||||
|
||||
case quick_stop_columns:
|
||||
two_columns = FALSE;
|
||||
break;
|
||||
|
||||
case quick_buttons:
|
||||
/* several buttons in bottom line */
|
||||
put_buttons = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
qw->widget = NULL;
|
||||
fprintf (stderr, "QuickWidget: unknown widget type\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (qw->widget != NULL)
|
||||
if (item->widget != NULL)
|
||||
{
|
||||
qw->widget->options |= qw->options; /* FIXME: cannot reset flags, setup only */
|
||||
add_widget (dd, qw->widget);
|
||||
unsigned long id;
|
||||
|
||||
/* add widget into dialog */
|
||||
item->widget->options |= item->quick_widget->options; /* FIXME: cannot reset flags, setup only */
|
||||
id = add_widget_autopos (dd, item->widget, item->quick_widget->pos_flags, NULL);
|
||||
if (item->quick_widget->id != NULL)
|
||||
*item->quick_widget->id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,36 +574,50 @@ quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
|
||||
/* Get the data if we found something interesting */
|
||||
if (return_val != B_CANCEL)
|
||||
{
|
||||
for (qw = qd->widgets; qw->widget_type != quick_end; qw++)
|
||||
for (i = 0; i < widgets->len; i++)
|
||||
{
|
||||
switch (qw->widget_type)
|
||||
quick_widget_item_t *item;
|
||||
|
||||
item = &g_array_index (widgets, quick_widget_item_t, i);
|
||||
|
||||
switch (item->quick_widget->widget_type)
|
||||
{
|
||||
case quick_checkbox:
|
||||
*qw->u.checkbox.state = ((WCheck *) qw->widget)->state & C_BOOL;
|
||||
*item->quick_widget->u.checkbox.state = CHECK (item->widget)->state & C_BOOL;
|
||||
break;
|
||||
|
||||
case quick_input:
|
||||
if ((qw->u.input.flags & 2) != 0)
|
||||
*qw->u.input.result = tilde_expand (((WInput *) qw->widget)->buffer);
|
||||
if ((quick_widget->u.input.flags & 2) != 0)
|
||||
*item->quick_widget->u.input.result =
|
||||
tilde_expand (INPUT (item->widget)->buffer);
|
||||
else
|
||||
*qw->u.input.result = g_strdup (((WInput *) qw->widget)->buffer);
|
||||
*item->quick_widget->u.input.result = g_strdup (INPUT (item->widget)->buffer);
|
||||
break;
|
||||
|
||||
case quick_radio:
|
||||
*qw->u.radio.value = ((WRadio *) qw->widget)->sel;
|
||||
*item->quick_widget->u.radio.value = RADIO (item->widget)->sel;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroy_dlg (dd);
|
||||
|
||||
/* destroy input labels created before */
|
||||
for (i = 0; i < widgets->len; i++)
|
||||
{
|
||||
quick_widget_item_t *item;
|
||||
|
||||
item = &g_array_index (widgets, quick_widget_item_t, i);
|
||||
if (item->quick_widget->widget_type == quick_input)
|
||||
g_free (item->quick_widget->u.input.label);
|
||||
}
|
||||
|
||||
g_array_free (widgets, TRUE);
|
||||
|
||||
return return_val;
|
||||
#undef I18N
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -9,131 +9,226 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
|
||||
{ \
|
||||
.widget_type = quick_checkbox, \
|
||||
.relative_x = x, \
|
||||
.x_divisions = xdiv, \
|
||||
.relative_y = y, \
|
||||
.y_divisions = ydiv, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.checkbox = { \
|
||||
.text = txt, \
|
||||
.state = st \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_CHECKBOX(txt, st, id_) \
|
||||
{ \
|
||||
.widget_type = quick_checkbox, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = id_, \
|
||||
.u = { \
|
||||
.checkbox = { \
|
||||
.text = txt, \
|
||||
.state = st \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_BUTTON(x, xdiv, y, ydiv, txt, act, cb) \
|
||||
{ \
|
||||
.widget_type = quick_button, \
|
||||
.relative_x = x, \
|
||||
.x_divisions = xdiv, \
|
||||
.relative_y = y, \
|
||||
.y_divisions = ydiv, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.button = { \
|
||||
.text = txt, \
|
||||
.action = act, \
|
||||
.callback = cb \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_BUTTON(txt, act, cb, id_) \
|
||||
{ \
|
||||
.widget_type = quick_button, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = id_, \
|
||||
.u = { \
|
||||
.button = { \
|
||||
.text = txt, \
|
||||
.action = act, \
|
||||
.callback = cb \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_INPUT(x, xdiv, y, ydiv, txt, len_, flags_, hname, res) \
|
||||
{ \
|
||||
.widget_type = quick_input, \
|
||||
.relative_x = x, \
|
||||
.x_divisions = xdiv, \
|
||||
.relative_y = y, \
|
||||
.y_divisions = ydiv, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = txt, \
|
||||
.len = len_, \
|
||||
.flags = flags_, \
|
||||
.histname = hname, \
|
||||
.result = res \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_INPUT(txt, flags_, hname, res, id_) \
|
||||
{ \
|
||||
.widget_type = quick_input, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = id_, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.label_text = NULL, \
|
||||
.label_location = input_label_none, \
|
||||
.label = NULL, \
|
||||
.text = txt, \
|
||||
.flags = flags_, \
|
||||
.histname = hname, \
|
||||
.result = res \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_LABEL(x, xdiv, y, ydiv, txt) \
|
||||
{ \
|
||||
.widget_type = quick_label, \
|
||||
.relative_x = x, \
|
||||
.x_divisions = xdiv, \
|
||||
.relative_y = y, \
|
||||
.y_divisions = ydiv, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.label = { \
|
||||
.text = txt \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_LABELED_INPUT(label_, label_loc, txt, flags_, hname, res, id_) \
|
||||
{ \
|
||||
.widget_type = quick_input, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = id_, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.label_text = label_, \
|
||||
.label_location = label_loc, \
|
||||
.label = NULL, \
|
||||
.text = txt, \
|
||||
.flags = flags_, \
|
||||
.histname = hname, \
|
||||
.result = res \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_RADIO(x, xdiv, y, ydiv, cnt, items_, val) \
|
||||
{ \
|
||||
.widget_type = quick_radio, \
|
||||
.relative_x = x, \
|
||||
.x_divisions = xdiv, \
|
||||
.relative_y = y, \
|
||||
.y_divisions = ydiv, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.radio = { \
|
||||
.count = cnt, \
|
||||
.items = items_, \
|
||||
.value = val \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_LABEL(txt, id_) \
|
||||
{ \
|
||||
.widget_type = quick_label, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = id_, \
|
||||
.u = { \
|
||||
.label = { \
|
||||
.text = txt, \
|
||||
.input = NULL \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_GROUPBOX(x, xdiv, y, ydiv, w, h, t) \
|
||||
{ \
|
||||
.widget_type = quick_groupbox, \
|
||||
.relative_x = x, \
|
||||
.x_divisions = xdiv, \
|
||||
.relative_y = y, \
|
||||
.y_divisions = ydiv, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.groupbox = { \
|
||||
.width = w, \
|
||||
.height = h, \
|
||||
.title = t \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_RADIO(cnt, items_, val, id_) \
|
||||
{ \
|
||||
.widget_type = quick_radio, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = id_, \
|
||||
.u = { \
|
||||
.radio = { \
|
||||
.count = cnt, \
|
||||
.items = items_, \
|
||||
.value = val \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_END \
|
||||
{ \
|
||||
.widget_type = quick_end, \
|
||||
.relative_x = 0, \
|
||||
.x_divisions = 0, \
|
||||
.relative_y = 0, \
|
||||
.y_divisions = 0, \
|
||||
.widget = NULL, \
|
||||
.options = 0, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = NULL, \
|
||||
.len = 0, \
|
||||
.flags = 0, \
|
||||
.histname = NULL, \
|
||||
.result = NULL \
|
||||
} \
|
||||
} \
|
||||
#define QUICK_START_GROUPBOX(t) \
|
||||
{ \
|
||||
.widget_type = quick_start_groupbox, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.groupbox = { \
|
||||
.title = t \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_STOP_GROUPBOX \
|
||||
{ \
|
||||
.widget_type = quick_stop_groupbox, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = NULL, \
|
||||
.flags = 0, \
|
||||
.histname = NULL, \
|
||||
.result = NULL \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_SEPARATOR(line_) \
|
||||
{ \
|
||||
.widget_type = quick_separator, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.separator = { \
|
||||
.space = TRUE, \
|
||||
.line = line_ \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_START_COLUMNS \
|
||||
{ \
|
||||
.widget_type = quick_start_columns, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = NULL, \
|
||||
.flags = 0, \
|
||||
.histname = NULL, \
|
||||
.result = NULL \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_NEXT_COLUMN \
|
||||
{ \
|
||||
.widget_type = quick_next_column, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = NULL, \
|
||||
.flags = 0, \
|
||||
.histname = NULL, \
|
||||
.result = NULL \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_STOP_COLUMNS \
|
||||
{ \
|
||||
.widget_type = quick_stop_columns, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = NULL, \
|
||||
.flags = 0, \
|
||||
.histname = NULL, \
|
||||
.result = NULL \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_START_BUTTONS(space_, line_) \
|
||||
{ \
|
||||
.widget_type = quick_buttons, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.separator = { \
|
||||
.space = space_, \
|
||||
.line = line_ \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define QUICK_BUTTONS_OK_CANCEL \
|
||||
QUICK_START_BUTTONS (TRUE, TRUE), \
|
||||
QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL), \
|
||||
QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL)
|
||||
|
||||
#define QUICK_END \
|
||||
{ \
|
||||
.widget_type = quick_end, \
|
||||
.options = 0, \
|
||||
.pos_flags = WPOS_KEEP_DEFAULT, \
|
||||
.id = NULL, \
|
||||
.u = { \
|
||||
.input = { \
|
||||
.text = NULL, \
|
||||
.flags = 0, \
|
||||
.histname = NULL, \
|
||||
.result = NULL \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
@ -147,23 +242,36 @@ typedef enum
|
||||
quick_input = 3,
|
||||
quick_label = 4,
|
||||
quick_radio = 5,
|
||||
quick_groupbox = 6
|
||||
quick_start_groupbox = 6,
|
||||
quick_stop_groupbox = 7,
|
||||
quick_separator = 8,
|
||||
quick_start_columns = 9,
|
||||
quick_next_column = 10,
|
||||
quick_stop_columns = 11,
|
||||
quick_buttons = 12
|
||||
} quick_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
input_label_none = 0,
|
||||
input_label_above = 1,
|
||||
input_label_left = 2,
|
||||
input_label_right = 3,
|
||||
input_label_below = 4
|
||||
} quick_input_label_location_t;
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* The widget is placed on relative_?/divisions_? of the parent widget */
|
||||
typedef struct
|
||||
typedef struct quick_widget_t quick_widget_t;
|
||||
|
||||
struct quick_widget_t
|
||||
{
|
||||
quick_t widget_type;
|
||||
|
||||
int relative_x;
|
||||
int x_divisions;
|
||||
int relative_y;
|
||||
int y_divisions;
|
||||
|
||||
Widget *widget;
|
||||
widget_options_t options;
|
||||
widget_pos_flags_t pos_flags;
|
||||
unsigned long *id;
|
||||
|
||||
/* widget parameters */
|
||||
union
|
||||
@ -183,8 +291,10 @@ typedef struct
|
||||
|
||||
struct
|
||||
{
|
||||
const char *label_text;
|
||||
quick_input_label_location_t label_location;
|
||||
quick_widget_t *label;
|
||||
const char *text;
|
||||
int len;
|
||||
int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
|
||||
const char *histname;
|
||||
char **result;
|
||||
@ -194,6 +304,7 @@ typedef struct
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
quick_widget_t *input;
|
||||
} label;
|
||||
|
||||
struct
|
||||
@ -205,37 +316,40 @@ typedef struct
|
||||
|
||||
struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
const char *title;
|
||||
} groupbox;
|
||||
|
||||
struct
|
||||
{
|
||||
gboolean space;
|
||||
gboolean line;
|
||||
} separator;
|
||||
} u;
|
||||
} QuickWidget;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int xlen, ylen;
|
||||
int xpos, ypos; /* if -1, then center the dialog */
|
||||
int y, x; /* if -1, then center the dialog */
|
||||
int cols; /* heigth is calculated automatically */
|
||||
const char *title;
|
||||
const char *help;
|
||||
QuickWidget *widgets;
|
||||
dlg_cb_fn callback;
|
||||
quick_widget_t *widgets;
|
||||
widget_cb_fn callback;
|
||||
mouse_h mouse;
|
||||
gboolean i18n; /* If true, internationalization has happened */
|
||||
} QuickDialog;
|
||||
} quick_dialog_t;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int quick_dialog_skip (QuickDialog * qd, int nskip);
|
||||
int quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline int
|
||||
quick_dialog (QuickDialog * qd)
|
||||
quick_dialog (quick_dialog_t * quick_dlg)
|
||||
{
|
||||
return quick_dialog_skip (qd, 0);
|
||||
return quick_dialog_skip (quick_dlg, 1);
|
||||
}
|
||||
|
||||
#endif /* MC__QUICK_H */
|
||||
|
@ -54,15 +54,14 @@
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t
|
||||
radio_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WRadio *r = (WRadio *) w;
|
||||
WRadio *r = RADIO (w);
|
||||
int i;
|
||||
Dlg_head *h = r->widget.owner;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_HOTKEY:
|
||||
case MSG_HOTKEY:
|
||||
{
|
||||
for (i = 0; i < r->count; i++)
|
||||
{
|
||||
@ -75,20 +74,20 @@ radio_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
r->pos = i;
|
||||
|
||||
/* Take action */
|
||||
radio_callback (w, WIDGET_KEY, ' ');
|
||||
send_message (w, sender, MSG_KEY, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
switch (parm)
|
||||
{
|
||||
case ' ':
|
||||
r->sel = r->pos;
|
||||
h->callback (h, w, DLG_ACTION, 0, NULL);
|
||||
radio_callback (w, WIDGET_FOCUS, ' ');
|
||||
send_message (w->owner, w, MSG_ACTION, 0, NULL);
|
||||
send_message (w, sender, MSG_FOCUS, ' ', data);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case KEY_UP:
|
||||
@ -110,35 +109,35 @@ radio_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
h->callback (h, w, DLG_ACTION, 0, NULL);
|
||||
radio_callback (w, WIDGET_FOCUS, ' ');
|
||||
widget_move (&r->widget, r->pos, 1);
|
||||
case MSG_CURSOR:
|
||||
send_message (w->owner, w, MSG_ACTION, 0, NULL);
|
||||
send_message (w, sender, MSG_FOCUS, ' ', data);
|
||||
widget_move (r, r->pos, 1);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_UNFOCUS:
|
||||
case WIDGET_FOCUS:
|
||||
case WIDGET_DRAW:
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_FOCUS:
|
||||
case MSG_DRAW:
|
||||
for (i = 0; i < r->count; i++)
|
||||
{
|
||||
const gboolean focused = (i == r->pos && msg == WIDGET_FOCUS);
|
||||
const gboolean focused = (i == r->pos && msg == MSG_FOCUS);
|
||||
|
||||
widget_selectcolor (w, focused, FALSE);
|
||||
widget_move (&r->widget, i, 0);
|
||||
tty_draw_hline (r->widget.y + i, r->widget.x, ' ', r->widget.cols);
|
||||
widget_move (r, i, 0);
|
||||
tty_draw_hline (w->y + i, w->x, ' ', w->cols);
|
||||
tty_print_string ((r->sel == i) ? "(*) " : "( ) ");
|
||||
hotkey_draw (w, r->texts[i], focused);
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
for (i = 0; i < r->count; i++)
|
||||
release_hotkey (r->texts[i]);
|
||||
g_free (r->texts);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,14 +146,14 @@ radio_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
static int
|
||||
radio_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Widget *w = (Widget *) data;
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
return MOU_UNHANDLED;
|
||||
|
||||
if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
|
||||
{
|
||||
WRadio *r = (WRadio *) data;
|
||||
WRadio *r = RADIO (data);
|
||||
Gpm_Event local;
|
||||
|
||||
local = mouse_get_local (event, w);
|
||||
@ -163,8 +162,8 @@ radio_event (Gpm_Event * event, void *data)
|
||||
dlg_select_widget (w);
|
||||
if ((event->type & GPM_UP) != 0)
|
||||
{
|
||||
radio_callback (w, WIDGET_KEY, ' ');
|
||||
w->owner->callback (w->owner, w, DLG_POST_KEY, ' ', NULL);
|
||||
radio_callback (w, NULL, MSG_KEY, ' ', NULL);
|
||||
send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,28 +178,31 @@ WRadio *
|
||||
radio_new (int y, int x, int count, const char **texts)
|
||||
{
|
||||
WRadio *r;
|
||||
Widget *w;
|
||||
int i, wmax = 0;
|
||||
|
||||
r = g_new (WRadio, 1);
|
||||
w = WIDGET (r);
|
||||
|
||||
/* Compute the longest string */
|
||||
r->texts = g_new (hotkey_t, count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
int w;
|
||||
int width;
|
||||
|
||||
r->texts[i] = parse_hotkey (texts[i]);
|
||||
w = hotkey_width (r->texts[i]);
|
||||
wmax = max (w, wmax);
|
||||
width = hotkey_width (r->texts[i]);
|
||||
wmax = max (width, wmax);
|
||||
}
|
||||
|
||||
init_widget (&r->widget, y, x, count, 4 + wmax, radio_callback, radio_event);
|
||||
init_widget (w, y, x, count, 4 + wmax, radio_callback, radio_event);
|
||||
/* 4 is width of "(*) " */
|
||||
r->state = 1;
|
||||
r->pos = 0;
|
||||
r->sel = 0;
|
||||
r->count = count;
|
||||
widget_want_hotkey (r->widget, TRUE);
|
||||
widget_want_hotkey (w, TRUE);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define RADIO(x) ((WRadio *)(x))
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
@ -139,7 +139,7 @@ hotkey_draw (Widget * w, const hotkey_t hotkey, gboolean focused)
|
||||
|
||||
void
|
||||
init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||
callback_fn callback, mouse_h mouse_handler)
|
||||
widget_cb_fn callback, mouse_h mouse_handler)
|
||||
{
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
@ -147,6 +147,7 @@ init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||
w->lines = lines;
|
||||
w->callback = callback;
|
||||
w->mouse = mouse_handler;
|
||||
w->set_options = widget_default_set_options_callback;
|
||||
w->owner = NULL;
|
||||
|
||||
/* Almost all widgets want to put the cursor in a suitable place */
|
||||
@ -157,19 +158,22 @@ init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||
|
||||
/* Default callback for widgets */
|
||||
cb_ret_t
|
||||
default_proc (widget_msg_t msg, int parm)
|
||||
widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
(void) w;
|
||||
(void) sender;
|
||||
(void) parm;
|
||||
(void) data;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case WIDGET_FOCUS:
|
||||
case WIDGET_UNFOCUS:
|
||||
case WIDGET_DRAW:
|
||||
case WIDGET_DESTROY:
|
||||
case WIDGET_CURSOR:
|
||||
case WIDGET_IDLE:
|
||||
case MSG_INIT:
|
||||
case MSG_FOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
case MSG_DRAW:
|
||||
case MSG_DESTROY:
|
||||
case MSG_CURSOR:
|
||||
case MSG_IDLE:
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
@ -179,6 +183,42 @@ default_proc (widget_msg_t msg, int parm)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Callback for applying new options to widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param options options set
|
||||
* @param enable TRUE if specified options should be added, FALSE if options should be removed
|
||||
*/
|
||||
void
|
||||
widget_default_set_options_callback (Widget *w, widget_options_t options, gboolean enable)
|
||||
{
|
||||
if (enable)
|
||||
w->options |= options;
|
||||
else
|
||||
w->options &= ~options;
|
||||
|
||||
if (w->owner != NULL && (options & W_DISABLED) != 0)
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Apply new options to widget.
|
||||
*
|
||||
* @param w widget
|
||||
* @param options options set
|
||||
* @param enable TRUE if specified options should be added, FALSE if options should be removed
|
||||
*/
|
||||
void
|
||||
widget_set_options (Widget *w, widget_options_t options, gboolean enable)
|
||||
{
|
||||
w->set_options (w, options, enable);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
widget_set_size (Widget * widget, int y, int x, int lines, int cols)
|
||||
{
|
||||
@ -186,7 +226,7 @@ widget_set_size (Widget * widget, int y, int x, int lines, int cols)
|
||||
widget->y = y;
|
||||
widget->cols = cols;
|
||||
widget->lines = lines;
|
||||
send_message (widget, WIDGET_RESIZED, 0 /* unused */ );
|
||||
send_message (widget, NULL, MSG_RESIZE, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -194,7 +234,7 @@ widget_set_size (Widget * widget, int y, int x, int lines, int cols)
|
||||
void
|
||||
widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey)
|
||||
{
|
||||
Dlg_head *h = w->owner;
|
||||
WDialog *h = w->owner;
|
||||
int color;
|
||||
|
||||
if ((w->options & W_DISABLED) != 0)
|
||||
|
@ -10,38 +10,45 @@
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + (_y), ((Widget *)(w))->x + (_x))
|
||||
#define WIDGET(x) ((Widget *)(x))
|
||||
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (WIDGET(w)->y + (_y), WIDGET(w)->x + (_x))
|
||||
/* 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))
|
||||
#define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
|
||||
#define widget_want_cursor(w,i) widget_set_options(w, W_WANT_CURSOR, i)
|
||||
#define widget_want_hotkey(w,i) widget_set_options(w, W_WANT_HOTKEY, i)
|
||||
#define widget_want_idle(w,i) widget_set_options(w, W_WANT_IDLE, i)
|
||||
#define widget_disable(w,i) widget_set_options(w, W_DISABLED, i)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* Widget messages */
|
||||
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 */
|
||||
MSG_INIT = 0, /* Initialize widget */
|
||||
MSG_FOCUS, /* Draw widget in focused state or widget has got focus */
|
||||
MSG_UNFOCUS, /* Draw widget in unfocused state or widget has been unfocused */
|
||||
MSG_DRAW, /* Draw widget on screen */
|
||||
MSG_KEY, /* Sent to widgets on key press */
|
||||
MSG_HOTKEY, /* Sent to widget to catch preprocess key */
|
||||
MSG_HOTKEY_HANDLED, /* A widget has got the hotkey */
|
||||
MSG_UNHANDLED_KEY, /* Key that no widget handled */
|
||||
MSG_POST_KEY, /* The key has been handled */
|
||||
MSG_ACTION, /* Send to widget to handle command or
|
||||
* state of check- and radiobuttons has changed
|
||||
* and listbox current entry has changed */
|
||||
MSG_CURSOR, /* Sent to widget to position the cursor */
|
||||
MSG_IDLE, /* The idle state is active */
|
||||
MSG_RESIZE, /* Screen size has changed */
|
||||
MSG_VALIDATE, /* Dialog is to be closed */
|
||||
MSG_END, /* Shut down dialog */
|
||||
MSG_DESTROY /* Sent to widget at destruction time */
|
||||
} widget_msg_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.
|
||||
MSG_FOCUS: MSG_HANDLED if the accept the focus, MSG_NOT_HANDLED if they do not.
|
||||
MSG_UNFOCUS: MSG_HANDLED if they accept to release the focus, MSG_NOT_HANDLED if they don't.
|
||||
MSG_KEY: MSG_HANDLED if they actually used the key, MSG_NOT_HANDLED if not.
|
||||
MSG_HOTKEY: MSG_HANDLED if they actually used the key, MSG_NOT_HANDLED if not.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
@ -63,19 +70,28 @@ typedef enum
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
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_CENTER_HORZ = (1 << 0), /* center widget in horizontal */
|
||||
WPOS_CENTER_VERT = (1 << 1), /* center widget in vertical */
|
||||
WPOS_KEEP_LEFT = (1 << 2), /* keep widget distance to left border of dialog */
|
||||
WPOS_KEEP_RIGHT = (1 << 3), /* keep widget distance to right border of dialog */
|
||||
WPOS_KEEP_TOP = (1 << 4), /* keep widget distance to top border of dialog */
|
||||
WPOS_KEEP_BOTTOM = (1 << 5), /* 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
|
||||
WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT,
|
||||
WPOS_KEEP_DEFAULT = WPOS_KEEP_LEFT | WPOS_KEEP_TOP
|
||||
} widget_pos_flags_t;
|
||||
/* NOTE: if WPOS_CENTER_HORZ flag is used, other horizontal flags (WPOS_KEEP_LEFT, WPOS_KEEP_RIGHT,
|
||||
* and WPOS_KEEP_HORZ are ignored).
|
||||
* If WPOS_CENTER_VERT flag is used, other horizontal flags (WPOS_KEEP_TOP, WPOS_KEEP_BOTTOM,
|
||||
* and WPOS_KEEP_VERT are ignored).
|
||||
*/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* Widget callback */
|
||||
typedef cb_ret_t (*callback_fn) (struct Widget * widget, widget_msg_t msg, int parm);
|
||||
typedef cb_ret_t (*widget_cb_fn) (Widget * widget, Widget * sender, widget_msg_t msg, int parm,
|
||||
void *data);
|
||||
|
||||
/* Every Widget must have this as its first element */
|
||||
struct Widget
|
||||
@ -85,9 +101,10 @@ struct Widget
|
||||
widget_options_t options;
|
||||
widget_pos_flags_t pos_flags; /* repositioning flags */
|
||||
unsigned int id; /* Number of the widget, starting with 0 */
|
||||
callback_fn callback;
|
||||
widget_cb_fn callback;
|
||||
mouse_h mouse;
|
||||
struct Dlg_head *owner;
|
||||
void (*set_options) (Widget *w, widget_options_t options, gboolean enable);
|
||||
struct WDialog *owner;
|
||||
};
|
||||
|
||||
/* structure for label (caption) with hotkey, if original text does not contain
|
||||
@ -112,16 +129,18 @@ void release_hotkey (const hotkey_t hotkey);
|
||||
/* return width on terminal of hotkey */
|
||||
int hotkey_width (const hotkey_t hotkey);
|
||||
/* draw hotkey of widget */
|
||||
void hotkey_draw (struct Widget *w, const hotkey_t hotkey, gboolean focused);
|
||||
void hotkey_draw (Widget *w, const hotkey_t hotkey, gboolean focused);
|
||||
|
||||
/* widget initialization */
|
||||
void init_widget (Widget * w, int y, int x, int lines, int cols,
|
||||
callback_fn callback, mouse_h mouse_handler);
|
||||
widget_cb_fn callback, mouse_h mouse_handler);
|
||||
/* Default callback for widgets */
|
||||
cb_ret_t default_proc (widget_msg_t msg, int parm);
|
||||
cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
|
||||
void widget_default_set_options_callback (Widget *w, widget_options_t options, gboolean enable);
|
||||
void widget_set_options (Widget *w, widget_options_t options, gboolean enable);
|
||||
void widget_set_size (Widget * widget, int y, int x, int lines, int cols);
|
||||
/* select color for widget in dependance of state */
|
||||
void widget_selectcolor (struct Widget *w, gboolean focused, gboolean hotkey);
|
||||
void widget_selectcolor (Widget *w, gboolean focused, gboolean hotkey);
|
||||
void widget_erase (Widget * w);
|
||||
|
||||
/* get mouse pointer location within widget */
|
||||
@ -131,9 +150,9 @@ gboolean mouse_global_in_widget (const Gpm_Event * event, const Widget * w);
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline cb_ret_t
|
||||
send_message (Widget * w, widget_msg_t msg, int parm)
|
||||
send_message (void *w, void *sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
return w->callback (w, msg, parm);
|
||||
return WIDGET (w)->callback (WIDGET (w), WIDGET (sender), msg, parm, data);
|
||||
}
|
||||
|
||||
#endif /* MC__WIDGET_INTERNAL_H */
|
||||
|
@ -2,7 +2,7 @@
|
||||
Widget based utility functions.
|
||||
|
||||
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011
|
||||
2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Authors:
|
||||
@ -10,7 +10,7 @@
|
||||
Radek Doulik, 1994, 1995
|
||||
Jakub Jelinek, 1995
|
||||
Andrej Borsenkow, 1995
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2009, 2010, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static Dlg_head *last_query_dlg;
|
||||
static WDialog *last_query_dlg;
|
||||
|
||||
static int sel_pos = 0;
|
||||
|
||||
@ -63,21 +63,23 @@ static int sel_pos = 0;
|
||||
/** default query callback, used to reposition query */
|
||||
|
||||
static cb_ret_t
|
||||
default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
query_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_RESIZE:
|
||||
case MSG_RESIZE:
|
||||
if ((h->flags & DLG_CENTER) == 0)
|
||||
{
|
||||
Dlg_head *prev_dlg = NULL;
|
||||
WDialog *prev_dlg = NULL;
|
||||
int ypos, xpos;
|
||||
|
||||
/* get dialog under h */
|
||||
if (top_dlg != NULL)
|
||||
{
|
||||
if (top_dlg->data != (void *) h)
|
||||
prev_dlg = (Dlg_head *) top_dlg->data;
|
||||
prev_dlg = DIALOG (top_dlg->data);
|
||||
else
|
||||
{
|
||||
GList *p;
|
||||
@ -86,38 +88,38 @@ default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
Get previous dialog in stack */
|
||||
p = g_list_next (top_dlg);
|
||||
if (p != NULL)
|
||||
prev_dlg = (Dlg_head *) p->data;
|
||||
prev_dlg = DIALOG (p->data);
|
||||
}
|
||||
}
|
||||
|
||||
/* if previous dialog is not fullscreen'd -- overlap it */
|
||||
if (prev_dlg == NULL || prev_dlg->fullscreen)
|
||||
ypos = LINES / 3 - (h->lines - 3) / 2;
|
||||
ypos = LINES / 3 - (w->lines - 3) / 2;
|
||||
else
|
||||
ypos = prev_dlg->y + 2;
|
||||
ypos = WIDGET (prev_dlg)->y + 2;
|
||||
|
||||
xpos = COLS / 2 - h->cols / 2;
|
||||
xpos = COLS / 2 - w->cols / 2;
|
||||
|
||||
/* set position */
|
||||
dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols);
|
||||
dlg_set_position (h, ypos, xpos, ypos + w->lines, xpos + w->cols);
|
||||
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
/* fallthrough */
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Create message dialog */
|
||||
|
||||
static struct Dlg_head *
|
||||
static struct WDialog *
|
||||
do_create_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
char *p;
|
||||
Dlg_head *d;
|
||||
WDialog *d;
|
||||
|
||||
/* Add empty lines before and after the message */
|
||||
p = g_strconcat ("\n", text, "\n", (char *) NULL);
|
||||
@ -125,7 +127,7 @@ do_create_message (int flags, const char *title, const char *text)
|
||||
d = last_query_dlg;
|
||||
|
||||
/* do resize before initing and running */
|
||||
default_query_callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
send_message (d, NULL, MSG_RESIZE, 0, NULL);
|
||||
|
||||
init_dlg (d);
|
||||
g_free (p);
|
||||
@ -142,7 +144,7 @@ do_create_message (int flags, const char *title, const char *text)
|
||||
static void
|
||||
fg_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
Dlg_head *d;
|
||||
WDialog *d;
|
||||
|
||||
d = do_create_message (flags, title, text);
|
||||
tty_getch ();
|
||||
@ -182,84 +184,44 @@ static char *
|
||||
fg_input_dialog_help (const char *header, const char *text, const char *help,
|
||||
const char *history_name, const char *def_text, gboolean strip_password)
|
||||
{
|
||||
char *my_str;
|
||||
int flags = (strip_password) ? 4 : 0;
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 64, 1, 0, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (3, 64, 1, 0, N_("&OK"), B_ENTER, NULL),
|
||||
/* 2 */ QUICK_INPUT (3, 64, 0, 0, def_text, 58, flags, NULL, &my_str),
|
||||
/* 3 */ QUICK_LABEL (3, 64, 2, 0, ""),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
int b0_len, b1_len, b_len, gap;
|
||||
char histname[64] = "inp|";
|
||||
int lines, cols;
|
||||
int len;
|
||||
int i;
|
||||
char *p_text;
|
||||
char histname[64] = "inp|";
|
||||
int flags = strip_password ? 4 : 0;
|
||||
char *my_str;
|
||||
int ret;
|
||||
|
||||
/* buttons */
|
||||
#ifdef ENABLE_NLS
|
||||
quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text);
|
||||
quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text);
|
||||
#endif /* ENABLE_NLS */
|
||||
/* label text */
|
||||
p_text = g_strstrip (g_strdup (text));
|
||||
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */
|
||||
b_len = b0_len + b1_len + 2; /* including gap */
|
||||
|
||||
/* input line */
|
||||
/* input history */
|
||||
if (history_name != NULL && *history_name != '\0')
|
||||
{
|
||||
g_strlcpy (histname + 3, history_name, sizeof (histname) - 3);
|
||||
quick_widgets[2].u.input.histname = histname;
|
||||
}
|
||||
|
||||
/* The special value of def_text is used to identify password boxes
|
||||
and hide characters with "*". Don't save passwords in history! */
|
||||
if (def_text == INPUT_PASSWORD)
|
||||
{
|
||||
quick_widgets[2].u.input.flags = 1;
|
||||
flags = 1;
|
||||
histname[3] = '\0';
|
||||
quick_widgets[2].u.input.text = "";
|
||||
def_text = "";
|
||||
}
|
||||
|
||||
/* text */
|
||||
p_text = g_strstrip (g_strdup (text));
|
||||
str_msg_term_size (p_text, &lines, &cols);
|
||||
quick_widgets[3].u.label.text = p_text;
|
||||
|
||||
/* dialog width */
|
||||
len = str_term_width1 (header);
|
||||
len = max (max (len, cols) + 4, 64);
|
||||
len = min (max (len, b_len + 6), COLS);
|
||||
|
||||
/* button locations */
|
||||
gap = (len - 8 - b_len) / 3;
|
||||
quick_widgets[1].relative_x = 3 + gap;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + gap + 2;
|
||||
|
||||
{
|
||||
QuickDialog Quick_input = {
|
||||
len, lines + 6, -1, -1, header,
|
||||
help, quick_widgets, NULL, NULL, TRUE
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABELED_INPUT (p_text, input_label_above, def_text, flags, histname, &my_str,
|
||||
NULL),
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
quick_widgets[i].x_divisions = Quick_input.xlen;
|
||||
quick_widgets[i].y_divisions = Quick_input.ylen;
|
||||
}
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, COLS / 2, header,
|
||||
help, quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
quick_widgets[i].relative_y += 2 + lines;
|
||||
|
||||
/* input line length */
|
||||
quick_widgets[2].u.input.len = Quick_input.xlen - 6;
|
||||
|
||||
ret = quick_dialog (&Quick_input);
|
||||
ret = quick_dialog (&qdlg);
|
||||
}
|
||||
|
||||
g_free (p_text);
|
||||
@ -309,7 +271,7 @@ int
|
||||
query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
{
|
||||
va_list ap;
|
||||
Dlg_head *query_dlg;
|
||||
WDialog *query_dlg;
|
||||
WButton *button;
|
||||
WButton *defbutton = NULL;
|
||||
int win_len = 0;
|
||||
@ -343,11 +305,16 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
|
||||
/* prepare dialog */
|
||||
query_dlg =
|
||||
create_dlg (TRUE, 0, 0, lines, cols, query_colors, default_query_callback, NULL,
|
||||
create_dlg (TRUE, 0, 0, lines, cols, query_colors, query_default_callback, NULL,
|
||||
"[QueryBox]", header, dlg_flags);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
add_widget_autopos (query_dlg, label_new (2, 3, text), WPOS_KEEP_TOP | WPOS_CENTER_HORZ,
|
||||
NULL);
|
||||
|
||||
add_widget (query_dlg, hline_new (lines - 4, -1, -1));
|
||||
|
||||
cols = (cols - win_len - 2) / 2 + 2;
|
||||
va_start (ap, count);
|
||||
for (i = 0; i < count; i++)
|
||||
@ -359,7 +326,7 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
if (strchr (cur_name, '&') != NULL)
|
||||
xpos--;
|
||||
|
||||
button = button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON, cur_name, 0);
|
||||
button = button_new (lines - 3, cols, B_USER + i, NORMAL_BUTTON, cur_name, NULL);
|
||||
add_widget (query_dlg, button);
|
||||
cols += xpos;
|
||||
if (i == sel_pos)
|
||||
@ -367,12 +334,10 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
}
|
||||
va_end (ap);
|
||||
|
||||
add_widget (query_dlg, label_new (2, 3, text));
|
||||
|
||||
/* do resize before running and selecting any widget */
|
||||
default_query_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);
|
||||
send_message (query_dlg, NULL, MSG_RESIZE, 0, NULL);
|
||||
|
||||
if (defbutton)
|
||||
if (defbutton != NULL)
|
||||
dlg_select_widget (defbutton);
|
||||
|
||||
/* run dialog and make result */
|
||||
@ -389,8 +354,9 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
}
|
||||
else
|
||||
{
|
||||
add_widget (query_dlg, label_new (2, 3, text));
|
||||
add_widget (query_dlg, button_new (0, 0, 0, HIDDEN_BUTTON, "-", 0));
|
||||
add_widget_autopos (query_dlg, label_new (2, 3, text), WPOS_KEEP_TOP | WPOS_CENTER_HORZ,
|
||||
NULL);
|
||||
add_widget (query_dlg, button_new (0, 0, 0, HIDDEN_BUTTON, "-", NULL));
|
||||
last_query_dlg = query_dlg;
|
||||
}
|
||||
sel_pos = 0;
|
||||
@ -411,11 +377,11 @@ query_set_sel (int new_sel)
|
||||
* destroy_dlg() to dismiss it. Not safe to call from background.
|
||||
*/
|
||||
|
||||
struct Dlg_head *
|
||||
struct WDialog *
|
||||
create_message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
va_list args;
|
||||
Dlg_head *d;
|
||||
WDialog *d;
|
||||
char *p;
|
||||
|
||||
va_start (args, text);
|
||||
|
@ -41,8 +41,8 @@ int query_dialog (const char *header, const char *text, int flags, int count, ..
|
||||
void query_set_sel (int new_sel);
|
||||
|
||||
/* Create message box but don't dismiss it yet, not background safe */
|
||||
struct Dlg_head *create_message (int flags, const char *title,
|
||||
const char *text, ...) __attribute__ ((format (__printf__, 3, 4)));
|
||||
struct WDialog *create_message (int flags, const char *title,
|
||||
const char *text, ...) __attribute__ ((format (__printf__, 3, 4)));
|
||||
|
||||
/* Show message box, background safe */
|
||||
void message (int flags, const char *title, const char *text, ...)
|
||||
|
2467
po/az.po
2467
po/az.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2827
po/be.po
2827
po/be.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2490
po/bg.po
2490
po/bg.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2522
po/ca.po
2522
po/ca.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2786
po/cs.po
2786
po/cs.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2786
po/da.po
2786
po/da.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2795
po/de.po
2795
po/de.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2281
po/de_CH.po
2281
po/de_CH.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2696
po/el.po
2696
po/el.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2886
po/eo.po
2886
po/eo.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2886
po/es.po
2886
po/es.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1195
po/et.po
1195
po/et.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2845
po/eu.po
2845
po/eu.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2376
po/fi.po
2376
po/fi.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2308
po/fi_FI.po
2308
po/fi_FI.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2618
po/fr.po
2618
po/fr.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2851
po/gl.po
2851
po/gl.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2869
po/hu.po
2869
po/hu.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2450
po/ia.po
2450
po/ia.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2306
po/id.po
2306
po/id.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1118
po/it.po
1118
po/it.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1198
po/it_IT.po
1198
po/it_IT.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2502
po/ja.po
2502
po/ja.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2288
po/ka.po
2288
po/ka.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2498
po/ko.po
2498
po/ko.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2503
po/lt.po
2503
po/lt.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2476
po/lv.po
2476
po/lv.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2971
po/mc.pot
2971
po/mc.pot
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2468
po/mn.po
2468
po/mn.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2464
po/nb.po
2464
po/nb.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2816
po/nl.po
2816
po/nl.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2896
po/pl.po
2896
po/pl.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2530
po/pt.po
2530
po/pt.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2721
po/pt_BR.po
2721
po/pt_BR.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2468
po/ro.po
2468
po/ro.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2811
po/ru.po
2811
po/ru.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2520
po/sk.po
2520
po/sk.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2490
po/sl.po
2490
po/sl.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2474
po/sr.po
2474
po/sr.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2467
po/sv.po
2467
po/sv.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1198
po/sv_SE.po
1198
po/sv_SE.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2281
po/ta.po
2281
po/ta.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2469
po/tr.po
2469
po/tr.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2892
po/uk.po
2892
po/uk.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2482
po/vi.po
2482
po/vi.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2426
po/wa.po
2426
po/wa.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2828
po/zh_CN.po
2828
po/zh_CN.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2463
po/zh_TW.po
2463
po/zh_TW.po
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,11 +1,12 @@
|
||||
/*
|
||||
Search functions for diffviewer.
|
||||
|
||||
Copyright (C) 2010, 2011
|
||||
Copyright (C) 2010, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Slava Zanko <slavazanko@gmail.com>, 2010.
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -43,9 +44,6 @@
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define SEARCH_DLG_WIDTH 58
|
||||
#define SEARCH_DLG_HEIGHT 13
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef struct mcdiffview_search_options_struct
|
||||
@ -67,85 +65,53 @@ static mcdiffview_search_options_t mcdiffview_search_options = {
|
||||
.all_codepages = FALSE,
|
||||
};
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#define DLG_BTN1_text N_("&Cancel")
|
||||
#define DLG_BTN2_text N_("&OK")
|
||||
|
||||
static void
|
||||
mcdiffview_dialog_fix_buttons_positions (QuickDialog * dlg)
|
||||
{
|
||||
size_t str_cancel_len, str_ok_len;
|
||||
size_t first_start_position;
|
||||
|
||||
str_cancel_len = str_term_width1 (_(DLG_BTN1_text)) + 4;
|
||||
str_ok_len = str_term_width1 (_(DLG_BTN2_text)) + 6;
|
||||
|
||||
first_start_position = (SEARCH_DLG_WIDTH - str_cancel_len - str_ok_len - 1) / 2;
|
||||
dlg->widgets[1].relative_x = first_start_position;
|
||||
dlg->widgets[0].relative_x = first_start_position + str_ok_len + 1;
|
||||
}
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
mcdiffview_dialog_search (WDiff * dview)
|
||||
{
|
||||
char *exp = NULL;
|
||||
|
||||
int qd_result;
|
||||
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
gchar **list_of_types;
|
||||
|
||||
QuickWidget search_widgets[] = {
|
||||
/* 0 */
|
||||
QUICK_BUTTON (3, SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, DLG_BTN1_text,
|
||||
B_CANCEL, NULL),
|
||||
/* 1 */
|
||||
QUICK_BUTTON (3, SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT - 3, SEARCH_DLG_HEIGHT, DLG_BTN2_text,
|
||||
B_ENTER, NULL),
|
||||
/* 2 */
|
||||
list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
|
||||
{
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above,
|
||||
INPUT_LAST_TEXT, 0, MC_HISTORY_SHARED_SEARCH, &exp, NULL),
|
||||
QUICK_SEPARATOR (TRUE),
|
||||
QUICK_START_COLUMNS,
|
||||
QUICK_RADIO (num_of_types, (const char **) list_of_types,
|
||||
(int *) &mcdiffview_search_options.type, NULL),
|
||||
QUICK_NEXT_COLUMN,
|
||||
QUICK_CHECKBOX (N_("Cas&e sensitive"), &mcdiffview_search_options.case_sens, NULL),
|
||||
QUICK_CHECKBOX (N_("&Backwards"), &mcdiffview_search_options.backwards, NULL),
|
||||
QUICK_CHECKBOX (N_("&Whole words"), &mcdiffview_search_options.whole_words, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&All charsets"),
|
||||
&mcdiffview_search_options.all_codepages),
|
||||
QUICK_CHECKBOX (N_("&All charsets"), &mcdiffview_search_options.all_codepages, NULL),
|
||||
#endif
|
||||
QUICK_STOP_COLUMNS,
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("&Whole words"),
|
||||
&mcdiffview_search_options.whole_words),
|
||||
/* 3 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
|
||||
&mcdiffview_search_options.backwards),
|
||||
/* 4 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("Cas&e sensitive"),
|
||||
&mcdiffview_search_options.case_sens),
|
||||
/* 5 */
|
||||
QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &mcdiffview_search_options.type),
|
||||
/* 6 */
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH,
|
||||
&exp),
|
||||
/* 7 */
|
||||
QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")),
|
||||
QUICK_END
|
||||
};
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 58,
|
||||
N_("Search"), "[Input Line Keys]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
QuickDialog search_input = {
|
||||
SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1,
|
||||
N_("Search"), "[Input Line Keys]",
|
||||
search_widgets, NULL, NULL, FALSE
|
||||
};
|
||||
qd_result = quick_dialog (&qdlg);
|
||||
}
|
||||
|
||||
mcdiffview_dialog_fix_buttons_positions (&search_input);
|
||||
|
||||
qd_result = quick_dialog (&search_input);
|
||||
g_strfreev (list_of_types);
|
||||
|
||||
|
||||
if ((qd_result == B_CANCEL) || (exp == NULL) || (exp[0] == '\0'))
|
||||
{
|
||||
g_free (exp);
|
||||
@ -154,9 +120,10 @@ mcdiffview_dialog_search (WDiff * dview)
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
{
|
||||
GString *tmp = str_convert_to_input (exp);
|
||||
GString *tmp;
|
||||
|
||||
if (tmp)
|
||||
tmp = str_convert_to_input (exp);
|
||||
if (tmp != NULL)
|
||||
{
|
||||
g_free (exp);
|
||||
exp = g_string_free (tmp, FALSE);
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
Copyright (C) 2007, 2010, 2011
|
||||
Copyright (C) 2007, 2010, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Daniel Borca <dborca@yahoo.com>, 2007
|
||||
Slava Zanko <slavazanko@gmail.com>, 2010
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2010
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2010, 2012
|
||||
Ilia Maslakov <il.smind@gmail.com>, 2010
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
@ -81,9 +81,6 @@ do { \
|
||||
#define FILE_READ_BUF 4096
|
||||
#define FILE_FLAG_TEMP (1 << 0)
|
||||
|
||||
#define OPTX 56
|
||||
#define OPTY 17
|
||||
|
||||
#define ADD_CH '+'
|
||||
#define DEL_CH '-'
|
||||
#define CHG_CH '*'
|
||||
@ -2353,35 +2350,31 @@ dview_diff_options (WDiff * dview)
|
||||
N_("&Minimal (Find a smaller set of change)")
|
||||
};
|
||||
|
||||
QuickWidget diffopt_widgets[] = {
|
||||
QUICK_BUTTON (6, 10, 14, OPTY, N_("&Cancel"), B_CANCEL, NULL),
|
||||
QUICK_BUTTON (2, 10, 14, OPTY, N_("&OK"), B_ENTER, NULL),
|
||||
|
||||
QUICK_CHECKBOX (3, OPTX, 12, OPTY,
|
||||
N_("Strip &trailing carriage return"), &dview->opt.strip_trailing_cr),
|
||||
QUICK_CHECKBOX (3, OPTX, 11, OPTY,
|
||||
N_("Ignore all &whitespace"), &dview->opt.ignore_all_space),
|
||||
QUICK_CHECKBOX (3, OPTX, 10, OPTY,
|
||||
N_("Ignore &space change"), &dview->opt.ignore_space_change),
|
||||
QUICK_CHECKBOX (3, OPTX, 9, OPTY,
|
||||
N_("Ignore tab &expansion"), &dview->opt.ignore_tab_expansion),
|
||||
QUICK_CHECKBOX (3, OPTX, 8, OPTY,
|
||||
N_("&Ignore case"), &dview->opt.ignore_case),
|
||||
QUICK_LABEL (3, OPTX, 7, OPTY, N_("Diff extra options")),
|
||||
QUICK_RADIO (3, OPTX, 3, OPTY,
|
||||
3, (const char **) quality_str, (int *) &dview->opt.quality),
|
||||
QUICK_LABEL (3, OPTX, 2, OPTY, N_("Diff algorithm")),
|
||||
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_START_GROUPBOX (N_("Diff algorithm")),
|
||||
QUICK_RADIO (3, (const char **) quality_str, (int *) &dview->opt.quality, NULL),
|
||||
QUICK_STOP_GROUPBOX,
|
||||
QUICK_START_GROUPBOX (N_("Diff extra options")),
|
||||
QUICK_CHECKBOX (N_("&Ignore case"), &dview->opt.ignore_case, NULL),
|
||||
QUICK_CHECKBOX (N_("Ignore tab &expansion"), &dview->opt.ignore_tab_expansion, NULL),
|
||||
QUICK_CHECKBOX (N_("Ignore &space change"), &dview->opt.ignore_space_change, NULL),
|
||||
QUICK_CHECKBOX (N_("Ignore all &whitespace"), &dview->opt.ignore_all_space, NULL),
|
||||
QUICK_CHECKBOX (N_("Strip &trailing carriage return"), &dview->opt.strip_trailing_cr,
|
||||
NULL),
|
||||
QUICK_STOP_GROUPBOX,
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
QuickDialog diffopt = {
|
||||
OPTX, OPTY, -1, -1,
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 56,
|
||||
N_("Diff Options"), "[Diff Options]",
|
||||
diffopt_widgets, NULL, NULL, FALSE
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&diffopt) != B_CANCEL)
|
||||
if (quick_dialog (&qdlg) != B_CANCEL)
|
||||
dview_reread (dview);
|
||||
}
|
||||
|
||||
@ -2445,7 +2438,7 @@ dview_init (WDiff * dview, const char *args, const char *file1, const char *file
|
||||
ndiff = redo_diff (dview);
|
||||
if (ndiff < 0)
|
||||
{
|
||||
/* goto WIDGET_DESTROY stage: dview_fini() */
|
||||
/* goto MSG_DESTROY stage: dview_fini() */
|
||||
f_close (f[DIFF_LEFT]);
|
||||
f_close (f[DIFF_RIGHT]);
|
||||
return -1;
|
||||
@ -2867,7 +2860,7 @@ dview_update (WDiff * dview)
|
||||
static void
|
||||
dview_edit (WDiff * dview, diff_place_t ord)
|
||||
{
|
||||
Dlg_head *h;
|
||||
WDialog *h;
|
||||
gboolean h_modal;
|
||||
int linenum, lineofs;
|
||||
|
||||
@ -2877,7 +2870,7 @@ dview_edit (WDiff * dview, diff_place_t ord)
|
||||
return;
|
||||
}
|
||||
|
||||
h = ((Widget *) dview)->owner;
|
||||
h = WIDGET (dview)->owner;
|
||||
h_modal = h->modal;
|
||||
|
||||
get_line_numbers (dview->a[ord], dview->skip_rows, &linenum, &lineofs);
|
||||
@ -2943,19 +2936,21 @@ dview_goto_cmd (WDiff * dview, diff_place_t ord)
|
||||
static void
|
||||
dview_labels (WDiff * dview)
|
||||
{
|
||||
Dlg_head *h;
|
||||
Widget *d;
|
||||
WDialog *h;
|
||||
WButtonBar *b;
|
||||
|
||||
h = dview->widget.owner;
|
||||
d = WIDGET (dview);
|
||||
h = d->owner;
|
||||
b = find_buttonbar (h);
|
||||
|
||||
buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 2, Q_ ("ButtonBar|Save"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 5, Q_ ("ButtonBar|Merge"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 9, Q_ ("ButtonBar|Options"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), diff_map, (Widget *) dview);
|
||||
buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), diff_map, d);
|
||||
buttonbar_set_label (b, 2, Q_ ("ButtonBar|Save"), diff_map, d);
|
||||
buttonbar_set_label (b, 4, Q_ ("ButtonBar|Edit"), diff_map, d);
|
||||
buttonbar_set_label (b, 5, Q_ ("ButtonBar|Merge"), diff_map, d);
|
||||
buttonbar_set_label (b, 7, Q_ ("ButtonBar|Search"), diff_map, d);
|
||||
buttonbar_set_label (b, 9, Q_ ("ButtonBar|Options"), diff_map, d);
|
||||
buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), diff_map, d);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -3309,26 +3304,26 @@ dview_handle_key (WDiff * dview, int key)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
dview_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
dview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WDiff *dview = (WDiff *) w;
|
||||
Dlg_head *h = dview->widget.owner;
|
||||
WDialog *h = w->owner;
|
||||
cb_ret_t i;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_INIT:
|
||||
case MSG_INIT:
|
||||
dview_labels (dview);
|
||||
dview_load_options (dview);
|
||||
dview_update (dview);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
dview->new_frame = 1;
|
||||
dview_update (dview);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
i = dview_handle_key (dview, parm);
|
||||
if (dview->view_quit)
|
||||
dlg_stop (h);
|
||||
@ -3336,7 +3331,7 @@ dview_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
dview_update (dview);
|
||||
return i;
|
||||
|
||||
case WIDGET_COMMAND:
|
||||
case MSG_ACTION:
|
||||
i = dview_execute_cmd (dview, parm);
|
||||
if (dview->view_quit)
|
||||
dlg_stop (h);
|
||||
@ -3344,20 +3339,20 @@ dview_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
dview_update (dview);
|
||||
return i;
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
dview_save_options (dview);
|
||||
dview_fini (dview);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
dview_adjust_size (Dlg_head * h)
|
||||
dview_adjust_size (WDialog * h)
|
||||
{
|
||||
WDiff *dview;
|
||||
WButtonBar *bar;
|
||||
@ -3365,8 +3360,8 @@ dview_adjust_size (Dlg_head * h)
|
||||
/* Look up the viewer and the buttonbar, we assume only two widgets here */
|
||||
dview = (WDiff *) find_widget_type (h, dview_callback);
|
||||
bar = find_buttonbar (h);
|
||||
widget_set_size (&dview->widget, 0, 0, LINES - 1, COLS);
|
||||
widget_set_size ((Widget *) bar, LINES - 1, 0, 1, COLS);
|
||||
widget_set_size (WIDGET (dview), 0, 0, LINES - 1, COLS);
|
||||
widget_set_size (WIDGET (bar), LINES - 1, 0, 1, COLS);
|
||||
|
||||
dview_compute_areas (dview);
|
||||
}
|
||||
@ -3374,32 +3369,33 @@ dview_adjust_size (Dlg_head * h)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
dview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
dview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WDiff *dview = (WDiff *) data;
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_RESIZE:
|
||||
case MSG_RESIZE:
|
||||
dview_adjust_size (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_ACTION:
|
||||
case MSG_ACTION:
|
||||
/* shortcut */
|
||||
if (sender == NULL)
|
||||
return dview_execute_cmd (NULL, parm);
|
||||
/* message from buttonbar */
|
||||
if (sender == (Widget *) find_buttonbar (h))
|
||||
if (sender == WIDGET (find_buttonbar (h)))
|
||||
{
|
||||
if (data != NULL)
|
||||
return send_message ((Widget *) data, WIDGET_COMMAND, parm);
|
||||
return send_message (data, NULL, MSG_ACTION, parm, NULL);
|
||||
|
||||
dview = (WDiff *) find_widget_type (h, dview_callback);
|
||||
return dview_execute_cmd (dview, parm);
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case DLG_VALIDATE:
|
||||
case MSG_VALIDATE:
|
||||
dview = (WDiff *) find_widget_type (h, dview_callback);
|
||||
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
|
||||
if (dview_ok_to_exit (dview))
|
||||
@ -3407,14 +3403,14 @@ dview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, v
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
dview_get_title (const Dlg_head * h, size_t len)
|
||||
dview_get_title (const WDialog * h, size_t len)
|
||||
{
|
||||
const WDiff *dview;
|
||||
const char *modified = " (*) ";
|
||||
@ -3443,7 +3439,8 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
|
||||
{
|
||||
int error;
|
||||
WDiff *dview;
|
||||
Dlg_head *dview_dlg;
|
||||
Widget *w;
|
||||
WDialog *dview_dlg;
|
||||
|
||||
/* Create dialog and widgets, put them on the dialog */
|
||||
dview_dlg =
|
||||
@ -3451,11 +3448,9 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
|
||||
"[Diff Viewer]", NULL, DLG_WANT_TAB);
|
||||
|
||||
dview = g_new0 (WDiff, 1);
|
||||
|
||||
init_widget (&dview->widget, 0, 0, LINES - 1, COLS,
|
||||
(callback_fn) dview_callback, (mouse_h) dview_event);
|
||||
|
||||
widget_want_cursor (dview->widget, 0);
|
||||
w = WIDGET (dview);
|
||||
init_widget (w, 0, 0, LINES - 1, COLS, dview_callback, dview_event);
|
||||
widget_want_cursor (w, FALSE);
|
||||
|
||||
add_widget (dview_dlg, dview);
|
||||
add_widget (dview_dlg, buttonbar_new (TRUE));
|
||||
|
@ -172,12 +172,12 @@ extern char *edit_window_close_char;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
gboolean edit_add_window (Dlg_head * h, int y, int x, int lines, int cols,
|
||||
gboolean edit_add_window (WDialog * h, int y, int x, int lines, int cols,
|
||||
const vfs_path_t * f, long fline);
|
||||
WEdit *find_editor (const Dlg_head * h);
|
||||
WEdit *find_editor (const WDialog * h);
|
||||
gboolean edit_widget_is_editor (const Widget * w);
|
||||
gboolean edit_drop_hotkey_menu (Dlg_head * h, int key);
|
||||
void edit_menu_cmd (Dlg_head * h);
|
||||
gboolean edit_drop_hotkey_menu (WDialog * h, int key);
|
||||
void edit_menu_cmd (WDialog * h);
|
||||
void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
|
||||
void edit_init_menu (struct WMenuBar *menubar);
|
||||
void edit_save_mode_cmd (void);
|
||||
@ -228,9 +228,9 @@ WEdit *edit_init (WEdit * edit, int y, int x, int lines, int cols,
|
||||
const vfs_path_t * filename_vpath, long line);
|
||||
gboolean edit_clean (WEdit * edit);
|
||||
gboolean edit_ok_to_exit (WEdit * edit);
|
||||
gboolean edit_load_cmd (Dlg_head * h);
|
||||
gboolean edit_load_syntax_file (Dlg_head * h);
|
||||
gboolean edit_load_menu_file (Dlg_head * h);
|
||||
gboolean edit_load_cmd (WDialog * h);
|
||||
gboolean edit_load_syntax_file (WDialog * h);
|
||||
gboolean edit_load_menu_file (WDialog * h);
|
||||
gboolean edit_close_cmd (WEdit * edit);
|
||||
void edit_mark_cmd (WEdit * edit, gboolean unmark);
|
||||
void edit_mark_current_word_cmd (WEdit * edit);
|
||||
@ -265,10 +265,10 @@ gboolean edit_load_back_cmd (WEdit * edit);
|
||||
gboolean edit_load_forward_cmd (WEdit * edit);
|
||||
void edit_block_process_cmd (WEdit * edit, int macro_number);
|
||||
void edit_refresh_cmd (void);
|
||||
void edit_syntax_onoff_cmd (Dlg_head * h);
|
||||
void edit_show_tabs_tws_cmd (Dlg_head * h);
|
||||
void edit_show_margin_cmd (Dlg_head * h);
|
||||
void edit_show_numbers_cmd (Dlg_head * h);
|
||||
void edit_syntax_onoff_cmd (WDialog * h);
|
||||
void edit_show_tabs_tws_cmd (WDialog * h);
|
||||
void edit_show_margin_cmd (WDialog * h);
|
||||
void edit_show_numbers_cmd (WDialog * h);
|
||||
void edit_date_cmd (WEdit * edit);
|
||||
void edit_goto_cmd (WEdit * edit);
|
||||
int eval_marks (WEdit * edit, off_t * start_mark, off_t * end_mark);
|
||||
@ -321,7 +321,7 @@ gboolean edit_line_is_blank (WEdit * edit, long line);
|
||||
gboolean is_break_char (char c);
|
||||
long edit_indent_width (const WEdit * edit, off_t p);
|
||||
void edit_insert_indent (WEdit * edit, int indent);
|
||||
void edit_options_dialog (Dlg_head * h);
|
||||
void edit_options_dialog (WDialog * h);
|
||||
void edit_syntax_dialog (WEdit * edit);
|
||||
void edit_mail_dialog (WEdit * edit);
|
||||
void format_paragraph (WEdit * edit, int force);
|
||||
|
@ -515,7 +515,7 @@ edit_load_position (WEdit * edit)
|
||||
book_mark_restore (edit, BOOK_MARK_COLOR);
|
||||
|
||||
edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1));
|
||||
edit_move_display (edit, line - (edit->widget.lines / 2));
|
||||
edit_move_display (edit, line - (WIDGET (edit)->lines / 2));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -906,7 +906,7 @@ static void
|
||||
edit_end_page (WEdit * edit)
|
||||
{
|
||||
edit_update_curs_row (edit);
|
||||
edit_move_down (edit, edit->widget.lines - edit->curs_row - 1, 0);
|
||||
edit_move_down (edit, WIDGET (edit)->lines - edit->curs_row - 1, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -938,7 +938,7 @@ edit_move_to_bottom (WEdit * edit)
|
||||
edit_move_down (edit, edit->total_lines - edit->curs_row, 0);
|
||||
edit->start_display = edit->last_byte;
|
||||
edit->start_line = edit->total_lines;
|
||||
edit_scroll_upward (edit, edit->widget.lines - 1);
|
||||
edit_scroll_upward (edit, WIDGET (edit)->lines - 1);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
}
|
||||
}
|
||||
@ -1624,7 +1624,7 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack
|
||||
break;
|
||||
/* count lines if searching downward */
|
||||
if (inc > 0 && a == '\n')
|
||||
if (n++ >= edit->widget.lines - edit->curs_row) /* out of screen */
|
||||
if (n++ >= WIDGET (edit)->lines - edit->curs_row) /* out of screen */
|
||||
break;
|
||||
}
|
||||
/* count bracket depth */
|
||||
@ -1807,7 +1807,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
|
||||
|
||||
edit_cursor_move (edit, curs - edit->curs1);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
send_message ((Widget *) edit, WIDGET_DRAW, 0);
|
||||
send_message (edit, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -2187,6 +2187,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
|
||||
long line)
|
||||
{
|
||||
gboolean to_free = FALSE;
|
||||
Widget *w;
|
||||
|
||||
option_auto_syntax = 1; /* Resetting to auto on every invokation */
|
||||
option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0;
|
||||
@ -2226,13 +2227,11 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
|
||||
to_free = TRUE;
|
||||
}
|
||||
|
||||
edit->drag_state = MCEDIT_DRAG_NORMAL;
|
||||
edit->widget.y = y;
|
||||
edit->widget.x = x;
|
||||
edit->widget.lines = lines;
|
||||
edit->widget.cols = cols;
|
||||
w = WIDGET (edit);
|
||||
init_widget (w, y, x, lines, cols, NULL, NULL);
|
||||
edit_save_size (edit);
|
||||
edit->fullscreen = TRUE;
|
||||
edit->drag_state = MCEDIT_DRAG_NORMAL;
|
||||
|
||||
edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
edit->stat1.st_uid = getuid ();
|
||||
@ -2352,14 +2351,16 @@ edit_clean (WEdit * edit)
|
||||
gboolean
|
||||
edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
WEdit *e;
|
||||
int y = edit->widget.y;
|
||||
int x = edit->widget.x;
|
||||
int lines = edit->widget.lines;
|
||||
int columns = edit->widget.cols;
|
||||
|
||||
int y = w->y;
|
||||
int x = w->x;
|
||||
int lines = w->lines;
|
||||
int columns = w->cols;
|
||||
|
||||
e = g_malloc0 (sizeof (WEdit));
|
||||
e->widget = edit->widget;
|
||||
*WIDGET (e) = *w;
|
||||
|
||||
if (edit_init (e, y, x, lines, columns, filename_vpath, line) == NULL)
|
||||
{
|
||||
@ -3154,7 +3155,7 @@ edit_scroll_downward (WEdit * edit, long i)
|
||||
{
|
||||
long lines_below;
|
||||
|
||||
lines_below = edit->total_lines - edit->start_line - (edit->widget.lines - 1);
|
||||
lines_below = edit->total_lines - edit->start_line - (WIDGET (edit)->lines - 1);
|
||||
if (lines_below > 0)
|
||||
{
|
||||
if (i > lines_below)
|
||||
@ -3471,7 +3472,7 @@ edit_find_bracket (WEdit * edit)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* This executes a command as though the user initiated it through a key
|
||||
* press. Callback with WIDGET_KEY as a message calls this after
|
||||
* press. Callback with MSG_KEY as a message calls this after
|
||||
* translating the key press. This function can be used to pass any
|
||||
* command to the editor. Note that the screen wouldn't update
|
||||
* automatically. Either of command or char_for_insertion must be
|
||||
@ -3531,6 +3532,8 @@ edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_inse
|
||||
void
|
||||
edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
|
||||
if (command == CK_WindowFullscreen)
|
||||
{
|
||||
edit_toggle_fullscreen (edit);
|
||||
@ -3817,13 +3820,13 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
edit->column_highlight = 1;
|
||||
case CK_PageUp:
|
||||
case CK_MarkPageUp:
|
||||
edit_move_up (edit, edit->widget.lines - 1, 1);
|
||||
edit_move_up (edit, w->lines - 1, 1);
|
||||
break;
|
||||
case CK_MarkColumnPageDown:
|
||||
edit->column_highlight = 1;
|
||||
case CK_PageDown:
|
||||
case CK_MarkPageDown:
|
||||
edit_move_down (edit, edit->widget.lines - 1, 1);
|
||||
edit_move_down (edit, w->lines - 1, 1);
|
||||
break;
|
||||
case CK_MarkColumnLeft:
|
||||
edit->column_highlight = 1;
|
||||
@ -4000,8 +4003,8 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
if (p->next != NULL)
|
||||
{
|
||||
p = p->next;
|
||||
if (p->line >= edit->start_line + edit->widget.lines || p->line < edit->start_line)
|
||||
edit_move_display (edit, p->line - edit->widget.lines / 2);
|
||||
if (p->line >= edit->start_line + w->lines || p->line < edit->start_line)
|
||||
edit_move_display (edit, p->line - w->lines / 2);
|
||||
edit_move_to_line (edit, p->line);
|
||||
}
|
||||
}
|
||||
@ -4017,8 +4020,8 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
|
||||
p = p->prev;
|
||||
if (p->line >= 0)
|
||||
{
|
||||
if (p->line >= edit->start_line + edit->widget.lines || p->line < edit->start_line)
|
||||
edit_move_display (edit, p->line - edit->widget.lines / 2);
|
||||
if (p->line >= edit->start_line + w->lines || p->line < edit->start_line)
|
||||
edit_move_display (edit, p->line - w->lines / 2);
|
||||
edit_move_to_line (edit, p->line);
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
Written by:
|
||||
Paul Sheer, 1996, 1997
|
||||
Andrew Borodin <aborodin@vmail.ru> 2012
|
||||
Ilia Maslakov <il.smind@gmail.com> 2012
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2012
|
||||
Ilia Maslakov <il.smind@gmail.com>, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -105,17 +105,42 @@ int edit_confirm_save = 1;
|
||||
|
||||
#define is_digit(x) ((x) >= '0' && (x) <= '9')
|
||||
|
||||
#define MAIL_DLG_HEIGHT 12
|
||||
|
||||
#define MAX_WORD_COMPLETIONS 100 /* in listbox */
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static unsigned long edit_save_mode_radio_id, edit_save_mode_input_id;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
edit_save_mode_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case MSG_ACTION:
|
||||
if (sender != NULL && sender->id == edit_save_mode_radio_id)
|
||||
{
|
||||
Widget *ww;
|
||||
|
||||
ww = dlg_find_by_id (DIALOG (w), edit_save_mode_input_id);
|
||||
widget_disable (ww, RADIO (sender)->sel != 2);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
default:
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* If 0 (quick save) then a) create/truncate <filename> file,
|
||||
b) save to <filename>;
|
||||
if 1 (safe save) then a) save to <tempnam>,
|
||||
@ -420,13 +445,10 @@ edit_check_newline (WEdit * edit)
|
||||
static vfs_path_t *
|
||||
edit_get_save_file_as (WEdit * edit)
|
||||
{
|
||||
#define DLG_WIDTH 64
|
||||
#define DLG_HEIGHT 14
|
||||
|
||||
static LineBreaks cur_lb = LB_ASIS;
|
||||
|
||||
char *filename = vfs_path_to_str (edit->filename_vpath);
|
||||
char *filename;
|
||||
char *filename_res;
|
||||
vfs_path_t *ret_vpath = NULL;
|
||||
|
||||
const char *lb_names[LB_NAMES] = {
|
||||
N_("&Do not change"),
|
||||
@ -435,41 +457,42 @@ edit_get_save_file_as (WEdit * edit)
|
||||
N_("&Macintosh format (CR)")
|
||||
};
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
QUICK_BUTTON (6, 10, DLG_HEIGHT - 3, DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
QUICK_BUTTON (2, 10, DLG_HEIGHT - 3, DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
QUICK_RADIO (5, DLG_WIDTH, DLG_HEIGHT - 8, DLG_HEIGHT, LB_NAMES, lb_names, (int *) &cur_lb),
|
||||
QUICK_LABEL (3, DLG_WIDTH, DLG_HEIGHT - 9, DLG_HEIGHT, N_("Change line breaks to:")),
|
||||
QUICK_INPUT (3, DLG_WIDTH, DLG_HEIGHT - 11, DLG_HEIGHT, filename, DLG_WIDTH - 6, 0,
|
||||
"save-as", &filename_res),
|
||||
QUICK_LABEL (3, DLG_WIDTH, DLG_HEIGHT - 12, DLG_HEIGHT, N_("Enter file name:")),
|
||||
QUICK_END
|
||||
};
|
||||
filename = vfs_path_to_str (edit->filename_vpath);
|
||||
|
||||
QuickDialog Quick_options = {
|
||||
DLG_WIDTH, DLG_HEIGHT, -1, -1,
|
||||
N_("Save As"), "[Save File As]",
|
||||
quick_widgets, NULL, NULL, FALSE
|
||||
};
|
||||
|
||||
if (quick_dialog (&Quick_options) != B_CANCEL)
|
||||
{
|
||||
char *fname;
|
||||
vfs_path_t *ret_vpath;
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABELED_INPUT (N_("Enter file name:"), input_label_above, filename, 0, "save-as",
|
||||
&filename_res, NULL),
|
||||
QUICK_SEPARATOR (TRUE),
|
||||
QUICK_LABEL (N_("Change line breaks to:"), NULL),
|
||||
QUICK_RADIO (LB_NAMES, lb_names, (int *) &cur_lb, NULL),
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
edit->lb = cur_lb;
|
||||
fname = tilde_expand (filename_res);
|
||||
g_free (filename_res);
|
||||
ret_vpath = vfs_path_from_str (fname);
|
||||
g_free (fname);
|
||||
return ret_vpath;
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 64,
|
||||
N_("Save As"), "[Save File As]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&qdlg) != B_CANCEL)
|
||||
{
|
||||
char *fname;
|
||||
|
||||
edit->lb = cur_lb;
|
||||
fname = tilde_expand (filename_res);
|
||||
g_free (filename_res);
|
||||
ret_vpath = vfs_path_from_str (fname);
|
||||
g_free (fname);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
|
||||
return NULL;
|
||||
|
||||
#undef DLG_WIDTH
|
||||
#undef DLG_HEIGHT
|
||||
return ret_vpath;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -512,9 +535,11 @@ edit_save_cmd (WEdit * edit)
|
||||
*/
|
||||
|
||||
static inline gboolean
|
||||
edit_load_file_from_filename (Dlg_head * h, const vfs_path_t * vpath)
|
||||
edit_load_file_from_filename (WDialog * h, const vfs_path_t * vpath)
|
||||
{
|
||||
return edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, vpath, 0);
|
||||
Widget *w = WIDGET (h);
|
||||
|
||||
return edit_add_window (h, w->y + 1, w->x, w->lines - 2, w->cols, vpath, 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1496,7 +1521,7 @@ edit_refresh_cmd (void)
|
||||
*/
|
||||
|
||||
void
|
||||
edit_syntax_onoff_cmd (Dlg_head * h)
|
||||
edit_syntax_onoff_cmd (WDialog * h)
|
||||
{
|
||||
option_syntax_highlighting = !option_syntax_highlighting;
|
||||
g_list_foreach (h->widgets, edit_syntax_onoff_cb, NULL);
|
||||
@ -1511,7 +1536,7 @@ edit_syntax_onoff_cmd (Dlg_head * h)
|
||||
*/
|
||||
|
||||
void
|
||||
edit_show_tabs_tws_cmd (Dlg_head * h)
|
||||
edit_show_tabs_tws_cmd (WDialog * h)
|
||||
{
|
||||
enable_show_tabs_tws = !enable_show_tabs_tws;
|
||||
g_list_foreach (h->widgets, edit_redraw_page_cb, NULL);
|
||||
@ -1526,7 +1551,7 @@ edit_show_tabs_tws_cmd (Dlg_head * h)
|
||||
*/
|
||||
|
||||
void
|
||||
edit_show_margin_cmd (Dlg_head * h)
|
||||
edit_show_margin_cmd (WDialog * h)
|
||||
{
|
||||
show_right_margin = !show_right_margin;
|
||||
g_list_foreach (h->widgets, edit_redraw_page_cb, NULL);
|
||||
@ -1541,7 +1566,7 @@ edit_show_margin_cmd (Dlg_head * h)
|
||||
*/
|
||||
|
||||
void
|
||||
edit_show_numbers_cmd (Dlg_head * h)
|
||||
edit_show_numbers_cmd (WDialog * h)
|
||||
{
|
||||
option_line_state = !option_line_state;
|
||||
option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0;
|
||||
@ -1554,10 +1579,6 @@ edit_show_numbers_cmd (Dlg_head * h)
|
||||
void
|
||||
edit_save_mode_cmd (void)
|
||||
{
|
||||
/* diaog sizes */
|
||||
const int DLG_X = 38;
|
||||
const int DLG_Y = 13;
|
||||
|
||||
char *str_result;
|
||||
|
||||
const char *str[] = {
|
||||
@ -1566,64 +1587,41 @@ edit_save_mode_cmd (void)
|
||||
N_("&Do backups with following extension:")
|
||||
};
|
||||
|
||||
QuickWidget widgets[] = {
|
||||
/* 0 */
|
||||
QUICK_BUTTON (18, DLG_X, DLG_Y - 3, DLG_Y, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */
|
||||
QUICK_BUTTON (6, DLG_X, DLG_Y - 3, DLG_Y, N_("&OK"), B_ENTER, NULL),
|
||||
/* 2 */
|
||||
QUICK_CHECKBOX (4, DLG_X, 8, DLG_Y, N_("Check &POSIX new line"), &option_check_nl_at_eof),
|
||||
/* 3 */
|
||||
QUICK_INPUT (8, DLG_X, 6, DLG_Y, option_backup_ext, 9, 0, "edit-backup-ext", &str_result),
|
||||
/* 4 */
|
||||
QUICK_RADIO (4, DLG_X, 3, DLG_Y, 3, str, &option_save_mode),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
QuickDialog dialog = {
|
||||
DLG_X, DLG_Y, -1, -1, N_("Edit Save Mode"),
|
||||
"[Edit Save Mode]", widgets, NULL, NULL, FALSE
|
||||
};
|
||||
|
||||
size_t i;
|
||||
size_t maxlen = 0;
|
||||
size_t w0, w1, b_len, w3;
|
||||
|
||||
#ifdef HAVE_ASSERT_H
|
||||
assert (option_backup_ext != NULL);
|
||||
#endif
|
||||
|
||||
/* OK/Cancel buttons */
|
||||
w0 = str_term_width1 (_(widgets[0].u.button.text)) + 3;
|
||||
w1 = str_term_width1 (_(widgets[1].u.button.text)) + 5; /* default button */
|
||||
b_len = w0 + w1 + 3;
|
||||
|
||||
maxlen = max (b_len, (size_t) str_term_width1 (_(dialog.title)) + 2);
|
||||
|
||||
w3 = 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
str[i] = _(str[i]);
|
||||
#endif
|
||||
w3 = max (w3, (size_t) str_term_width1 (str[i]));
|
||||
}
|
||||
|
||||
maxlen = max (maxlen, w3 + 4);
|
||||
|
||||
dialog.xlen = min ((size_t) COLS, maxlen + 8);
|
||||
|
||||
widgets[3].u.input.len = w3;
|
||||
widgets[1].relative_x = (dialog.xlen - b_len) / 2;
|
||||
widgets[0].relative_x = widgets[1].relative_x + w0 + 2;
|
||||
|
||||
for (i = 0; i < sizeof (widgets) / sizeof (widgets[0]); i++)
|
||||
widgets[i].x_divisions = dialog.xlen;
|
||||
|
||||
if (quick_dialog (&dialog) != B_CANCEL)
|
||||
{
|
||||
g_free (option_backup_ext);
|
||||
option_backup_ext = str_result;
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_RADIO (3, str, &option_save_mode, &edit_save_mode_radio_id),
|
||||
QUICK_INPUT (option_backup_ext, 0, "edit-backup-ext", &str_result,
|
||||
&edit_save_mode_input_id),
|
||||
QUICK_SEPARATOR (TRUE),
|
||||
QUICK_CHECKBOX (N_("Check &POSIX new line"), &option_check_nl_at_eof, NULL),
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 38,
|
||||
N_("Edit Save Mode"), "[Edit Save Mode]",
|
||||
quick_widgets, edit_save_mode_callback, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&qdlg) != B_CANCEL)
|
||||
{
|
||||
g_free (option_backup_ext);
|
||||
option_backup_ext = str_result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2059,7 +2057,7 @@ edit_save_confirm_cmd (WEdit * edit)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_load_cmd (Dlg_head * h)
|
||||
edit_load_cmd (WDialog * h)
|
||||
{
|
||||
char *exp;
|
||||
gboolean ret = TRUE; /* possible cancel */
|
||||
@ -2089,7 +2087,7 @@ edit_load_cmd (Dlg_head * h)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_load_syntax_file (Dlg_head * h)
|
||||
edit_load_syntax_file (WDialog * h)
|
||||
{
|
||||
vfs_path_t *extdir_vpath;
|
||||
int dir = 0;
|
||||
@ -2134,7 +2132,7 @@ edit_load_syntax_file (Dlg_head * h)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_load_menu_file (Dlg_head * h)
|
||||
edit_load_menu_file (WDialog * h)
|
||||
{
|
||||
vfs_path_t *buffer_vpath;
|
||||
vfs_path_t *menufile_vpath;
|
||||
@ -2204,14 +2202,14 @@ edit_close_cmd (WEdit * edit)
|
||||
|
||||
if (ret)
|
||||
{
|
||||
Dlg_head *h = ((Widget *) edit)->owner;
|
||||
WDialog *h = WIDGET (edit)->owner;
|
||||
|
||||
if (edit->locked != 0)
|
||||
unlock_file (edit->filename_vpath);
|
||||
|
||||
del_widget (edit);
|
||||
|
||||
if (edit_widget_is_editor ((Widget *) h->current->data))
|
||||
if (edit_widget_is_editor (WIDGET (h->current->data)))
|
||||
edit = (WEdit *) h->current->data;
|
||||
else
|
||||
{
|
||||
@ -2665,7 +2663,7 @@ edit_replace_cmd (WEdit * edit, int again)
|
||||
long l;
|
||||
int prompt;
|
||||
|
||||
l = (long) (edit->curs_row - edit->widget.lines / 3);
|
||||
l = edit->curs_row - WIDGET (edit)->lines / 3;
|
||||
if (l > 0)
|
||||
edit_scroll_downward (edit, l);
|
||||
if (l < 0)
|
||||
@ -3070,7 +3068,7 @@ edit_goto_cmd (WEdit * edit)
|
||||
line = l;
|
||||
if (l < 0)
|
||||
l = edit->total_lines + l + 2;
|
||||
edit_move_display (edit, l - edit->widget.lines / 2 - 1);
|
||||
edit_move_display (edit, l - WIDGET (edit)->lines / 2 - 1);
|
||||
edit_move_to_line (edit, l - 1);
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
g_free (f);
|
||||
@ -3295,30 +3293,31 @@ edit_mail_dialog (WEdit * edit)
|
||||
static char *mail_subject_last = 0;
|
||||
static char *mail_to_last = 0;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 10, 9, MAIL_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (2, 10, 9, MAIL_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
/* 2 */ QUICK_INPUT (3, 50, 8, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input", &tmail_cc),
|
||||
/* 3 */ QUICK_LABEL (3, 50, 7, MAIL_DLG_HEIGHT, N_("Copies to")),
|
||||
/* 4 */ QUICK_INPUT (3, 50, 6, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input-2",
|
||||
&tmail_subject),
|
||||
/* 5 */ QUICK_LABEL (3, 50, 5, MAIL_DLG_HEIGHT, N_("Subject")),
|
||||
/* 6 */ QUICK_INPUT (3, 50, 4, MAIL_DLG_HEIGHT, "", 44, 0, "mail-dlg-input-3", &tmail_to),
|
||||
/* 7 */ QUICK_LABEL (3, 50, 3, MAIL_DLG_HEIGHT, N_("To")),
|
||||
/* 8 */ QUICK_LABEL (3, 50, 2, MAIL_DLG_HEIGHT, N_("mail -s <subject> -c <cc> <to>")),
|
||||
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABEL (N_("mail -s <subject> -c <cc> <to>"), NULL),
|
||||
QUICK_LABELED_INPUT (N_("To"), input_label_above,
|
||||
mail_to_last != NULL ? mail_to_last : "", 0,
|
||||
"mail-dlg-input-3", &tmail_to, NULL),
|
||||
QUICK_LABELED_INPUT (N_("Subject"), input_label_above,
|
||||
mail_subject_last != NULL ? mail_subject_last : "", 0,
|
||||
"mail-dlg-input-2", &tmail_subject, NULL),
|
||||
QUICK_LABELED_INPUT (N_("Copies to"), input_label_above,
|
||||
mail_cc_last != NULL ? mail_cc_last : "", 0,
|
||||
"mail-dlg-input", &tmail_cc, NULL),
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
QuickDialog Quick_input = {
|
||||
50, MAIL_DLG_HEIGHT, -1, -1, N_("Mail"),
|
||||
"[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 50,
|
||||
N_("Mail"), "[Input Line Keys]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
quick_widgets[2].u.input.text = mail_cc_last ? mail_cc_last : "";
|
||||
quick_widgets[4].u.input.text = mail_subject_last ? mail_subject_last : "";
|
||||
quick_widgets[6].u.input.text = mail_to_last ? mail_to_last : "";
|
||||
|
||||
if (quick_dialog (&Quick_input) != B_CANCEL)
|
||||
if (quick_dialog (&qdlg) != B_CANCEL)
|
||||
{
|
||||
g_free (mail_cc_last);
|
||||
g_free (mail_subject_last);
|
||||
@ -3330,12 +3329,12 @@ edit_mail_dialog (WEdit * edit)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/*******************/
|
||||
/* Word Completion */
|
||||
/*******************/
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Complete current word using regular expression search
|
||||
* backwards beginning at the current cursor position.
|
||||
@ -3407,7 +3406,7 @@ edit_select_codepage_cmd (WEdit * edit)
|
||||
edit_set_codeset (edit);
|
||||
|
||||
edit->force = REDRAW_PAGE;
|
||||
send_message ((Widget *) edit, WIDGET_DRAW, 0);
|
||||
send_message (edit, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
/*
|
||||
Editor dialogs for high level editing commands
|
||||
|
||||
Copyright (C) 2009, 2011
|
||||
Copyright (C) 2009, 2011, 2012
|
||||
The Free Software Foundation, Inc.
|
||||
|
||||
Written by:
|
||||
Slava Zanko <slavazanko@gmail.com>, 2009.
|
||||
Andrew Borodin, <aborodin@vmail.ru>, 2012.
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -59,14 +60,6 @@ edit_search_options_t edit_search_options = {
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define SEARCH_DLG_WIDTH 58
|
||||
#define SEARCH_DLG_MIN_HEIGHT 13
|
||||
#define SEARCH_DLG_HEIGHT_SUPPLY 3
|
||||
|
||||
#define REPLACE_DLG_WIDTH 58
|
||||
#define REPLACE_DLG_MIN_HEIGHT 17
|
||||
#define REPLACE_DLG_HEIGHT_SUPPLY 5
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
@ -75,17 +68,18 @@ edit_search_options_t edit_search_options = {
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
editcmd_dialog_raw_key_query_cb (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_KEY:
|
||||
case MSG_KEY:
|
||||
h->ret_value = parm;
|
||||
dlg_stop (h);
|
||||
return MSG_HANDLED;
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,205 +87,51 @@ editcmd_dialog_raw_key_query_cb (struct Dlg_head *h, Widget * sender,
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
|
||||
/*@out@ */ char **search_text, /*@out@ */ char **replace_text)
|
||||
{
|
||||
if ((search_default == NULL) || (*search_default == '\0'))
|
||||
search_default = INPUT_LAST_TEXT;
|
||||
|
||||
{
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int REPLACE_DLG_HEIGHT = REPLACE_DLG_MIN_HEIGHT + num_of_types - REPLACE_DLG_HEIGHT_SUPPLY;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 10, 13, REPLACE_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (2, 10, 13, REPLACE_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
/* 2 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 11, REPLACE_DLG_HEIGHT,
|
||||
N_("&All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
#endif
|
||||
/* 3 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 10, REPLACE_DLG_HEIGHT,
|
||||
N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 4 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 9, REPLACE_DLG_HEIGHT,
|
||||
N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 5 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 8, REPLACE_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 6 */ QUICK_CHECKBOX (33, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
|
||||
N_("Cas&e sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 7 */ QUICK_RADIO (3, REPLACE_DLG_WIDTH, 7, REPLACE_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 8 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 4, REPLACE_DLG_HEIGHT,
|
||||
N_("Enter replacement string:")),
|
||||
/* 9 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 5, REPLACE_DLG_HEIGHT,
|
||||
replace_default, REPLACE_DLG_WIDTH - 6, 0, "replace",
|
||||
replace_text),
|
||||
/* 10 */ QUICK_LABEL (3, REPLACE_DLG_WIDTH, 2, REPLACE_DLG_HEIGHT,
|
||||
N_("Enter search string:")),
|
||||
/* 11 */ QUICK_INPUT (3, REPLACE_DLG_WIDTH, 3, REPLACE_DLG_HEIGHT,
|
||||
search_default, REPLACE_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH, search_text),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
QuickDialog Quick_input = {
|
||||
REPLACE_DLG_WIDTH, REPLACE_DLG_HEIGHT, -1, -1, N_("Replace"),
|
||||
"[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
|
||||
};
|
||||
|
||||
if (quick_dialog (&Quick_input) != B_CANCEL)
|
||||
{
|
||||
edit->replace_mode = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
*replace_text = NULL;
|
||||
*search_text = NULL;
|
||||
}
|
||||
|
||||
g_strfreev (list_of_types);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
editcmd_dialog_search_show (WEdit * edit)
|
||||
{
|
||||
char *search_text;
|
||||
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
int SEARCH_DLG_HEIGHT = SEARCH_DLG_MIN_HEIGHT + num_of_types - SEARCH_DLG_HEIGHT_SUPPLY;
|
||||
size_t i;
|
||||
|
||||
gchar **list_of_types;
|
||||
int dialog_result;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */
|
||||
QUICK_BUTTON (6, 10, 11, SEARCH_DLG_HEIGHT, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */
|
||||
QUICK_BUTTON (4, 10, 11, SEARCH_DLG_HEIGHT, N_("&Find all"), B_USER, NULL),
|
||||
/* 2 */
|
||||
QUICK_BUTTON (2, 10, 11, SEARCH_DLG_HEIGHT, N_("&OK"), B_ENTER, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
/* 3 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 9, SEARCH_DLG_HEIGHT, N_("&All charsets"),
|
||||
&edit_search_options.all_codepages),
|
||||
#endif
|
||||
/* 4 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 8, SEARCH_DLG_HEIGHT, N_("&Whole words"),
|
||||
&edit_search_options.whole_words),
|
||||
/* 5 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 7, SEARCH_DLG_HEIGHT, N_("In se&lection"),
|
||||
&edit_search_options.only_in_selection),
|
||||
/* 6 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 6, SEARCH_DLG_HEIGHT, N_("&Backwards"),
|
||||
&edit_search_options.backwards),
|
||||
/* 7 */
|
||||
QUICK_CHECKBOX (33, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT, N_("Cas&e sensitive"),
|
||||
&edit_search_options.case_sens),
|
||||
/* 8 */
|
||||
QUICK_RADIO (3, SEARCH_DLG_WIDTH, 5, SEARCH_DLG_HEIGHT,
|
||||
num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type),
|
||||
/* 9 */
|
||||
QUICK_INPUT (3, SEARCH_DLG_WIDTH, 3, SEARCH_DLG_HEIGHT,
|
||||
INPUT_LAST_TEXT, SEARCH_DLG_WIDTH - 6, 0,
|
||||
MC_HISTORY_SHARED_SEARCH, &search_text),
|
||||
/* 10 */
|
||||
QUICK_LABEL (3, SEARCH_DLG_WIDTH, 2, SEARCH_DLG_HEIGHT, N_("Enter search string:")),
|
||||
QUICK_END
|
||||
};
|
||||
list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
size_t last_checkbox = 7;
|
||||
#else
|
||||
size_t last_checkbox = 6;
|
||||
#endif
|
||||
|
||||
QuickDialog Quick_input = {
|
||||
SEARCH_DLG_WIDTH, SEARCH_DLG_HEIGHT, -1, -1, N_("Search"),
|
||||
"[Input Line Keys]", quick_widgets, NULL, NULL, TRUE
|
||||
};
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
char **list_of_types_nls;
|
||||
|
||||
/* header title */
|
||||
Quick_input.title = _(Quick_input.title);
|
||||
/* buttons */
|
||||
for (i = 0; i < 3; i++)
|
||||
quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
|
||||
/* checkboxes */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
|
||||
/* label */
|
||||
quick_widgets[10].u.label.text = _(quick_widgets[10].u.label.text);
|
||||
|
||||
/* radiobuttons */
|
||||
/* create copy of radio items to avoid memory leak */
|
||||
list_of_types_nls = g_new0 (char *, num_of_types + 1);
|
||||
for (i = 0; i < num_of_types; i++)
|
||||
list_of_types_nls[i] = g_strdup (_(list_of_types[i]));
|
||||
g_strfreev (list_of_types);
|
||||
list_of_types = list_of_types_nls;
|
||||
quick_widgets[last_checkbox + 1].u.radio.items = (const char **) list_of_types;
|
||||
#endif
|
||||
|
||||
/* calculate widget coordinates */
|
||||
{
|
||||
int len = 0;
|
||||
int dlg_width;
|
||||
gchar **radio = list_of_types;
|
||||
int b0_len, b1_len, b2_len;
|
||||
const int button_gap = 2;
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above,
|
||||
INPUT_LAST_TEXT, 0, MC_HISTORY_SHARED_SEARCH, &search_text, NULL),
|
||||
QUICK_SEPARATOR (TRUE),
|
||||
QUICK_START_COLUMNS,
|
||||
QUICK_RADIO (num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type, NULL),
|
||||
QUICK_NEXT_COLUMN,
|
||||
QUICK_CHECKBOX (N_("Cas&e sensitive"), &edit_search_options.case_sens, NULL),
|
||||
QUICK_CHECKBOX (N_("&Backwards"), &edit_search_options.backwards, NULL),
|
||||
QUICK_CHECKBOX (N_("In se&lection"), &edit_search_options.only_in_selection, NULL),
|
||||
QUICK_CHECKBOX (N_("&Whole words"), &edit_search_options.whole_words, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
QUICK_CHECKBOX (N_("&All charsets"), &edit_search_options.all_codepages, NULL),
|
||||
#endif
|
||||
QUICK_STOP_COLUMNS,
|
||||
QUICK_START_BUTTONS (TRUE, TRUE),
|
||||
QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
|
||||
QUICK_BUTTON (N_("&Find all"), B_USER, NULL, NULL),
|
||||
QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
/* length of radiobuttons */
|
||||
while (*radio != NULL)
|
||||
{
|
||||
len = max (len, str_term_width1 (*radio));
|
||||
radio++;
|
||||
}
|
||||
/* length of checkboxes */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
len = max (len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 58,
|
||||
N_("Search"), "[Input Line Keys]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
/* preliminary dialog width */
|
||||
dlg_width = max (len * 2, str_term_width1 (Quick_input.title)) + 4;
|
||||
|
||||
/* length of buttons */
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
|
||||
b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5; /* default button */
|
||||
len = b0_len + b1_len + b2_len + button_gap * 2;
|
||||
|
||||
/* dialog width */
|
||||
Quick_input.xlen = max (SEARCH_DLG_WIDTH, max (dlg_width, len + 6));
|
||||
|
||||
/* correct widget coordinates */
|
||||
for (i = 0; i < sizeof (quick_widgets) / sizeof (quick_widgets[0]); i++)
|
||||
quick_widgets[i].x_divisions = Quick_input.xlen;
|
||||
|
||||
/* checkbox positions */
|
||||
for (i = 3; i <= last_checkbox; i++)
|
||||
quick_widgets[i].relative_x = Quick_input.xlen / 2 + 2;
|
||||
/* input length */
|
||||
quick_widgets[last_checkbox + 2].u.input.len = Quick_input.xlen - 6;
|
||||
/* button positions */
|
||||
quick_widgets[2].relative_x = Quick_input.xlen / 2 - len / 2;
|
||||
quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + button_gap;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap;
|
||||
dialog_result = quick_dialog (&qdlg);
|
||||
}
|
||||
|
||||
dialog_result = quick_dialog (&Quick_input);
|
||||
|
||||
g_strfreev (list_of_types);
|
||||
|
||||
if ((dialog_result == B_CANCEL) || (search_text == NULL) || (search_text[0] == '\0'))
|
||||
@ -333,6 +173,122 @@ editcmd_dialog_search_show (WEdit * edit)
|
||||
return (edit->search != NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
editcmd_dialog_replace_show (WEdit * edit, const char *search_default, const char *replace_default,
|
||||
/*@out@ */ char **search_text, /*@out@ */ char **replace_text)
|
||||
{
|
||||
size_t num_of_types;
|
||||
gchar **list_of_types;
|
||||
|
||||
if ((search_default == NULL) || (*search_default == '\0'))
|
||||
search_default = INPUT_LAST_TEXT;
|
||||
|
||||
list_of_types = mc_search_get_types_strings_array (&num_of_types);
|
||||
|
||||
{
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above,
|
||||
search_default, 0, MC_HISTORY_SHARED_SEARCH, search_text, NULL),
|
||||
QUICK_LABELED_INPUT (N_("Enter replacement string:"), input_label_above,
|
||||
replace_default, 0, "replace", replace_text, NULL),
|
||||
QUICK_SEPARATOR (TRUE),
|
||||
QUICK_START_COLUMNS,
|
||||
QUICK_RADIO (num_of_types, (const char **) list_of_types,
|
||||
(int *) &edit_search_options.type, NULL),
|
||||
QUICK_NEXT_COLUMN,
|
||||
QUICK_CHECKBOX (N_("Cas&e sensitive"), &edit_search_options.case_sens, NULL),
|
||||
QUICK_CHECKBOX (N_("&Backwards"), &edit_search_options.backwards, NULL),
|
||||
QUICK_CHECKBOX (N_("In se&lection"), &edit_search_options.only_in_selection, NULL),
|
||||
QUICK_CHECKBOX (N_("&Whole words"), &edit_search_options.whole_words, NULL),
|
||||
#ifdef HAVE_CHARSET
|
||||
QUICK_CHECKBOX (N_("&All charsets"), &edit_search_options.all_codepages, NULL),
|
||||
#endif
|
||||
QUICK_STOP_COLUMNS,
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 58,
|
||||
N_("Replace"), "[Input Line Keys]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&qdlg) != B_CANCEL)
|
||||
edit->replace_mode = 0;
|
||||
else
|
||||
{
|
||||
*replace_text = NULL;
|
||||
*search_text = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (list_of_types);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos,
|
||||
int ypos)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
|
||||
/* dialog size */
|
||||
int dlg_height = 10;
|
||||
|
||||
char tmp[BUF_MEDIUM];
|
||||
char *repl_from, *repl_to;
|
||||
int retval;
|
||||
|
||||
if (xpos == -1)
|
||||
xpos = w->x + option_line_state_width + 1;
|
||||
if (ypos == -1)
|
||||
ypos = w->y + w->lines / 2;
|
||||
/* Sometimes menu can hide replaced text. I don't like it */
|
||||
if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
|
||||
ypos -= dlg_height;
|
||||
|
||||
g_snprintf (tmp, sizeof (tmp), "\"%s\"", from_text);
|
||||
repl_from = g_strdup (str_trunc (tmp, - 7));
|
||||
|
||||
g_snprintf (tmp, sizeof (tmp), "\"%s\"", to_text);
|
||||
repl_to = g_strdup (str_trunc (tmp, - 7));
|
||||
|
||||
{
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABEL (repl_from, NULL),
|
||||
QUICK_LABEL (N_("Replace with:"), NULL),
|
||||
QUICK_LABEL (repl_to, NULL),
|
||||
QUICK_START_BUTTONS (TRUE, TRUE),
|
||||
QUICK_BUTTON (N_("&Replace"), B_ENTER, NULL, NULL),
|
||||
QUICK_BUTTON (N_("A&ll"), B_REPLACE_ALL, NULL, NULL),
|
||||
QUICK_BUTTON (N_("&Skip"), B_SKIP_REPLACE, NULL, NULL),
|
||||
QUICK_BUTTON (N_("&Cancel"), B_CANCEL, NULL, NULL),
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
quick_dialog_t qdlg = {
|
||||
ypos, xpos, -1,
|
||||
N_("Confirm replace"), NULL,
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
retval = quick_dialog (&qdlg);
|
||||
}
|
||||
|
||||
g_free (repl_from);
|
||||
g_free (repl_to);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* gets a raw key from the keyboard. Passing cancel = 1 draws
|
||||
a cancel button thus allowing c-c etc. Alternatively, cancel = 0
|
||||
@ -342,19 +298,29 @@ editcmd_dialog_search_show (WEdit * edit)
|
||||
int
|
||||
editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel)
|
||||
{
|
||||
int w;
|
||||
struct Dlg_head *raw_dlg;
|
||||
int w, wq;
|
||||
int y = 2;
|
||||
WDialog *raw_dlg;
|
||||
|
||||
w = str_term_width1 (query) + 7;
|
||||
w = str_term_width1 (heading) + 6;
|
||||
wq = str_term_width1 (query);
|
||||
w = max (w, wq + 3 * 2 + 1 + 2);
|
||||
|
||||
raw_dlg =
|
||||
create_dlg (TRUE, 0, 0, 7, w, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL,
|
||||
NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
|
||||
add_widget (raw_dlg, input_new (3 - cancel, w - 5, input_get_default_colors (),
|
||||
2, "", 0, INPUT_COMPLETE_DEFAULT));
|
||||
add_widget (raw_dlg, label_new (3 - cancel, 2, query));
|
||||
create_dlg (TRUE, 0, 0, cancel ? 7 : 5, w, dialog_colors, editcmd_dialog_raw_key_query_cb,
|
||||
NULL, NULL, heading, DLG_CENTER | DLG_TRYUP | DLG_WANT_TAB);
|
||||
|
||||
add_widget (raw_dlg, label_new (y, 3, query));
|
||||
add_widget (raw_dlg, input_new (y++, 3 + wq + 1, input_get_default_colors (),
|
||||
w - (6 + wq + 1), "", 0, INPUT_COMPLETE_DEFAULT));
|
||||
if (cancel)
|
||||
add_widget (raw_dlg, button_new (4, w / 2 - 5, B_CANCEL, NORMAL_BUTTON, _("Cancel"), 0));
|
||||
{
|
||||
add_widget (raw_dlg, hline_new (y++, -1, -1));
|
||||
/* Button w/o hotkey to allow use any key as raw or macro one */
|
||||
add_widget_autopos (raw_dlg, button_new (y, 1, B_CANCEL, NORMAL_BUTTON, _("Cancel"), NULL),
|
||||
WPOS_KEEP_TOP | WPOS_CENTER_HORZ, NULL);
|
||||
}
|
||||
|
||||
w = run_dlg (raw_dlg);
|
||||
destroy_dlg (raw_dlg);
|
||||
|
||||
@ -371,7 +337,7 @@ editcmd_dialog_completion_show (WEdit * edit, int max_len, int word_len,
|
||||
|
||||
int start_x, start_y, offset, i;
|
||||
char *curr = NULL;
|
||||
Dlg_head *compl_dlg;
|
||||
WDialog *compl_dlg;
|
||||
WListbox *compl_list;
|
||||
int compl_dlg_h; /* completion dialog height */
|
||||
int compl_dlg_w; /* completion dialog width */
|
||||
@ -458,7 +424,7 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
int start_x, start_y, offset, i;
|
||||
char *curr = NULL;
|
||||
etags_hash_t *curr_def = NULL;
|
||||
Dlg_head *def_dlg;
|
||||
WDialog *def_dlg;
|
||||
WListbox *def_list;
|
||||
int def_dlg_h; /* dialog height */
|
||||
int def_dlg_w; /* dialog width */
|
||||
@ -569,89 +535,3 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
editcmd_dialog_replace_prompt_show (WEdit * edit, char *from_text, char *to_text, int xpos,
|
||||
int ypos)
|
||||
{
|
||||
/* dialog sizes */
|
||||
int dlg_height = 9;
|
||||
int dlg_width = 8;
|
||||
|
||||
int retval;
|
||||
int i;
|
||||
int btn_pos;
|
||||
|
||||
char *repl_from, *repl_to;
|
||||
char tmp[BUF_MEDIUM];
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (44, dlg_width, 6, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (29, dlg_width, 6, dlg_height, N_("&Skip"), B_SKIP_REPLACE, NULL),
|
||||
/* 2 */ QUICK_BUTTON (21, dlg_width, 6, dlg_height, N_("A&ll"), B_REPLACE_ALL, NULL),
|
||||
/* 3 */ QUICK_BUTTON (4, dlg_width, 6, dlg_height, N_("&Replace"), B_ENTER, NULL),
|
||||
/* 4 */ QUICK_LABEL (3, dlg_width, 2, dlg_height, NULL),
|
||||
/* 5 */ QUICK_LABEL (3, dlg_width, 3, dlg_height, N_("Replace with:")),
|
||||
/* 6 */ QUICK_LABEL (3, dlg_width, 4, dlg_height, NULL),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
for (i = 0; i < 4; i++)
|
||||
quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
|
||||
#endif
|
||||
|
||||
/* calculate button positions */
|
||||
btn_pos = 4;
|
||||
|
||||
for (i = 3; i > -1; i--)
|
||||
{
|
||||
quick_widgets[i].relative_x = btn_pos;
|
||||
btn_pos += str_term_width1 (quick_widgets[i].u.button.text) + 5;
|
||||
if (i == 3) /* default button */
|
||||
btn_pos += 2;
|
||||
}
|
||||
|
||||
dlg_width = btn_pos + 2;
|
||||
|
||||
/* correct widget coordinates */
|
||||
for (i = 0; i < 7; i++)
|
||||
quick_widgets[i].x_divisions = dlg_width;
|
||||
|
||||
g_snprintf (tmp, sizeof (tmp), "\"%s\"", from_text);
|
||||
repl_from = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
|
||||
|
||||
g_snprintf (tmp, sizeof (tmp), "\"%s\"", to_text);
|
||||
repl_to = g_strdup (str_fit_to_term (tmp, dlg_width - 7, J_LEFT));
|
||||
|
||||
quick_widgets[4].u.label.text = repl_from;
|
||||
quick_widgets[6].u.label.text = repl_to;
|
||||
|
||||
if (xpos == -1)
|
||||
xpos = (edit->widget.cols - dlg_width) / 2;
|
||||
|
||||
if (ypos == -1)
|
||||
ypos = edit->widget.lines * 2 / 3;
|
||||
|
||||
{
|
||||
QuickDialog Quick_input = {
|
||||
dlg_width, dlg_height, 0, 0, N_("Confirm replace"),
|
||||
"[Input Line Keys]", quick_widgets, NULL, NULL, FALSE
|
||||
};
|
||||
|
||||
/* Sometimes menu can hide replaced text. I don't like it */
|
||||
if ((edit->curs_row >= ypos - 1) && (edit->curs_row <= ypos + dlg_height - 1))
|
||||
ypos -= dlg_height;
|
||||
|
||||
Quick_input.ypos = ypos;
|
||||
Quick_input.xpos = xpos;
|
||||
|
||||
retval = quick_dialog (&Quick_input);
|
||||
g_free (repl_from);
|
||||
g_free (repl_to);
|
||||
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -193,7 +193,8 @@ status_string (WEdit * edit, char *s, int w)
|
||||
static inline void
|
||||
edit_status_fullscreen (WEdit * edit, int color)
|
||||
{
|
||||
const int w = edit->widget.owner->cols;
|
||||
Widget *h = WIDGET (WIDGET (edit)->owner);
|
||||
const int w = h->cols;
|
||||
const size_t status_size = w + 1;
|
||||
char *const status = g_malloc (status_size);
|
||||
int status_len;
|
||||
@ -222,7 +223,7 @@ edit_status_fullscreen (WEdit * edit, int color)
|
||||
fname = str_trunc (fname, fname_len);
|
||||
}
|
||||
|
||||
dlg_move (edit->widget.owner, 0, 0);
|
||||
widget_move (h, 0, 0);
|
||||
tty_setcolor (color);
|
||||
printwstr (fname, fname_len + gap);
|
||||
printwstr (status, w - (fname_len + gap));
|
||||
@ -233,7 +234,7 @@ edit_status_fullscreen (WEdit * edit, int color)
|
||||
|
||||
if (edit->total_lines + 1 != 0)
|
||||
percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
|
||||
dlg_move (edit->widget.owner, 0, w - 6 - 6);
|
||||
widget_move (h, 0, w - 6 - 6);
|
||||
tty_printf (" %3d%%", percent);
|
||||
}
|
||||
|
||||
@ -250,8 +251,9 @@ edit_status_fullscreen (WEdit * edit, int color)
|
||||
static inline void
|
||||
edit_status_window (WEdit * edit)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
int y, x;
|
||||
int cols = edit->widget.cols;
|
||||
int cols = w->cols;
|
||||
|
||||
tty_setcolor (STATUSBAR_COLOR);
|
||||
|
||||
@ -271,12 +273,12 @@ edit_status_window (WEdit * edit)
|
||||
#endif
|
||||
|
||||
edit_move (2, 0);
|
||||
tty_printf ("[%s]", str_term_trim (fname, edit->widget.cols - 8 - 6));
|
||||
tty_printf ("[%s]", str_term_trim (fname, w->cols - 8 - 6));
|
||||
g_free (full_fname);
|
||||
}
|
||||
|
||||
tty_getyx (&y, &x);
|
||||
x -= edit->widget.x;
|
||||
x -= w->x;
|
||||
x += 4;
|
||||
if (x + 6 <= cols - 2 - 6)
|
||||
{
|
||||
@ -289,7 +291,7 @@ edit_status_window (WEdit * edit)
|
||||
|
||||
if (cols > 30)
|
||||
{
|
||||
edit_move (2, edit->widget.lines - 1);
|
||||
edit_move (2, w->lines - 1);
|
||||
tty_printf ("%3ld %5ld/%ld %6ld/%ld",
|
||||
edit->curs_col + edit->over_col,
|
||||
edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte);
|
||||
@ -302,7 +304,7 @@ edit_status_window (WEdit * edit)
|
||||
*/
|
||||
if (cols > 46)
|
||||
{
|
||||
edit_move (32, edit->widget.lines - 1);
|
||||
edit_move (32, w->lines - 1);
|
||||
if (edit->curs1 >= edit->last_byte)
|
||||
tty_print_string ("[<EOF> ]");
|
||||
#ifdef HAVE_CHARSET
|
||||
@ -365,14 +367,14 @@ edit_draw_frame (const WEdit * edit, int color, gboolean active)
|
||||
static inline void
|
||||
edit_draw_window_icons (const WEdit * edit, int color)
|
||||
{
|
||||
const Widget *w = (const Widget *) edit;
|
||||
const Widget *w = WIDGET (edit);
|
||||
char tmp[17];
|
||||
|
||||
tty_setcolor (color);
|
||||
if (edit->fullscreen)
|
||||
dlg_move (w->owner, 0, w->owner->cols - 6);
|
||||
widget_move (w->owner, 0, WIDGET (w->owner)->cols - 6);
|
||||
else
|
||||
widget_move (w, 0, edit->widget.cols - 8);
|
||||
widget_move (w, 0, w->cols - 8);
|
||||
g_snprintf (tmp, sizeof (tmp), "[%s][%s]", edit_window_state_char, edit_window_close_char);
|
||||
tty_print_string (tmp);
|
||||
}
|
||||
@ -383,6 +385,8 @@ static inline void
|
||||
print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
|
||||
long end_col, struct line_s line[], char *status, int bookmarked)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
|
||||
struct line_s *p;
|
||||
|
||||
int x = start_col_real;
|
||||
@ -406,25 +410,25 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
|
||||
len = end_col + 1 - start_col;
|
||||
wrap_start = option_word_wrap_line_length + edit->start_col;
|
||||
|
||||
if (len > 0 && edit->widget.y + y >= 0)
|
||||
if (len > 0 && w->y + y >= 0)
|
||||
{
|
||||
if (!show_right_margin || wrap_start > end_col)
|
||||
tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
|
||||
tty_draw_hline (w->y + y, w->x + x1, ' ', len);
|
||||
else if (wrap_start < 0)
|
||||
{
|
||||
tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
|
||||
tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
|
||||
tty_draw_hline (w->y + y, w->x + x1, ' ', len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wrap_start > 0)
|
||||
tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start);
|
||||
tty_draw_hline (w->y + y, w->x + x1, ' ', wrap_start);
|
||||
|
||||
len -= wrap_start;
|
||||
if (len > 0)
|
||||
{
|
||||
tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
|
||||
tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len);
|
||||
tty_draw_hline (w->y + y, w->x + x1 + wrap_start, ' ', len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -499,6 +503,8 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
|
||||
static void
|
||||
edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
|
||||
struct line_s line[MAX_LINE_LEN];
|
||||
struct line_s *p = line;
|
||||
|
||||
@ -513,7 +519,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
||||
int book_mark = 0;
|
||||
char line_stat[LINE_STATE_WIDTH + 1] = "\0";
|
||||
|
||||
if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1))
|
||||
if (row > w->lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1))
|
||||
return;
|
||||
|
||||
if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
|
||||
@ -529,10 +535,8 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
|
||||
end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
if (!edit->fullscreen)
|
||||
{
|
||||
const Widget *w = (const Widget *) edit;
|
||||
|
||||
end_col--;
|
||||
if (w->x + w->cols <= w->owner->cols)
|
||||
if (w->x + w->cols <= WIDGET (w->owner)->cols)
|
||||
end_col--;
|
||||
}
|
||||
|
||||
@ -841,8 +845,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
||||
static long prev_curs_row = 0;
|
||||
static off_t prev_curs = 0;
|
||||
|
||||
Widget *w = (Widget *) edit;
|
||||
Dlg_head *h = w->owner;
|
||||
Widget *w = WIDGET (edit);
|
||||
Widget *wh = WIDGET (w->owner);
|
||||
|
||||
long row = 0, curs_row;
|
||||
int force = edit->force;
|
||||
@ -854,24 +858,24 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
||||
|
||||
/* draw only visible region */
|
||||
|
||||
last_line = h->y + h->lines - 1;
|
||||
last_line = wh->y + wh->lines - 1;
|
||||
|
||||
y1 = w->y;
|
||||
if (y1 > last_line - 1 /* buttonbar */ )
|
||||
return;
|
||||
|
||||
last_column = h->x + h->cols - 1;
|
||||
last_column = wh->x + wh->cols - 1;
|
||||
|
||||
x1 = w->x;
|
||||
if (x1 > last_column)
|
||||
return;
|
||||
|
||||
y2 = w->y + w->lines - 1;
|
||||
if (y2 < h->y + 1 /* menubar */ )
|
||||
if (y2 < wh->y + 1 /* menubar */ )
|
||||
return;
|
||||
|
||||
x2 = w->x + w->cols - 1;
|
||||
if (x2 < h->x)
|
||||
if (x2 < wh->x)
|
||||
return;
|
||||
|
||||
if ((force & REDRAW_IN_BOUNDS) == 0)
|
||||
@ -881,17 +885,17 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
||||
|
||||
if (y2 <= last_line - 1 /* buttonbar */ )
|
||||
end_row = w->lines - 1;
|
||||
else if (y1 >= h->y + 1 /* menubar */ )
|
||||
end_row = h->lines - 1 - y1 - 1;
|
||||
else if (y1 >= wh->y + 1 /* menubar */ )
|
||||
end_row = wh->lines - 1 - y1 - 1;
|
||||
else
|
||||
end_row = start_row + h->lines - 1 - 1;
|
||||
end_row = start_row + wh->lines - 1 - 1;
|
||||
|
||||
if (x2 <= last_column)
|
||||
end_column = w->cols - 1;
|
||||
else if (x1 >= h->x)
|
||||
end_column = h->cols - 1 - x1;
|
||||
else if (x1 >= wh->x)
|
||||
end_column = wh->cols - 1 - x1;
|
||||
else
|
||||
end_column = start_column + h->cols - 1;
|
||||
end_column = start_column + wh->cols - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -967,7 +971,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
|
||||
}
|
||||
}
|
||||
|
||||
if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1)
|
||||
if ((force & REDRAW_LINE_BELOW) != 0 && row < w->lines - 1)
|
||||
{
|
||||
row = curs_row + 1;
|
||||
b = edit_bol (edit, edit->curs1);
|
||||
@ -1049,22 +1053,24 @@ edit_status (WEdit * edit, gboolean active)
|
||||
void
|
||||
edit_scroll_screen_over_cursor (WEdit * edit)
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
|
||||
long p;
|
||||
long outby;
|
||||
int b_extreme, t_extreme, l_extreme, r_extreme;
|
||||
|
||||
if (edit->widget.lines <= 0 || edit->widget.cols <= 0)
|
||||
if (w->lines <= 0 || w->cols <= 0)
|
||||
return;
|
||||
|
||||
edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET;
|
||||
edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
w->lines -= EDIT_TEXT_VERTICAL_OFFSET;
|
||||
w->cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
|
||||
if (!edit->fullscreen)
|
||||
{
|
||||
edit->widget.x++;
|
||||
edit->widget.cols -= 2;
|
||||
edit->widget.y++;
|
||||
edit->widget.lines -= 2;
|
||||
w->x++;
|
||||
w->cols -= 2;
|
||||
w->y++;
|
||||
w->lines -= 2;
|
||||
}
|
||||
|
||||
r_extreme = EDIT_RIGHT_EXTREME;
|
||||
@ -1073,39 +1079,39 @@ edit_scroll_screen_over_cursor (WEdit * edit)
|
||||
t_extreme = EDIT_TOP_EXTREME;
|
||||
if (edit->found_len != 0)
|
||||
{
|
||||
b_extreme = max (edit->widget.lines / 4, b_extreme);
|
||||
t_extreme = max (edit->widget.lines / 4, t_extreme);
|
||||
b_extreme = max (w->lines / 4, b_extreme);
|
||||
t_extreme = max (w->lines / 4, t_extreme);
|
||||
}
|
||||
if (b_extreme + t_extreme + 1 > edit->widget.lines)
|
||||
if (b_extreme + t_extreme + 1 > w->lines)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = b_extreme + t_extreme;
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
b_extreme = (b_extreme * (edit->widget.lines - 1)) / n;
|
||||
t_extreme = (t_extreme * (edit->widget.lines - 1)) / n;
|
||||
b_extreme = (b_extreme * (w->lines - 1)) / n;
|
||||
t_extreme = (t_extreme * (w->lines - 1)) / n;
|
||||
}
|
||||
if (l_extreme + r_extreme + 1 > edit->widget.cols)
|
||||
if (l_extreme + r_extreme + 1 > w->cols)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = l_extreme + t_extreme;
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
l_extreme = (l_extreme * (edit->widget.cols - 1)) / n;
|
||||
r_extreme = (r_extreme * (edit->widget.cols - 1)) / n;
|
||||
l_extreme = (l_extreme * (w->cols - 1)) / n;
|
||||
r_extreme = (r_extreme * (w->cols - 1)) / n;
|
||||
}
|
||||
p = edit_get_col (edit) + edit->over_col;
|
||||
edit_update_curs_row (edit);
|
||||
outby = p + edit->start_col - edit->widget.cols + 1 + (r_extreme + edit->found_len);
|
||||
outby = p + edit->start_col - w->cols + 1 + (r_extreme + edit->found_len);
|
||||
if (outby > 0)
|
||||
edit_scroll_right (edit, outby);
|
||||
outby = l_extreme - p - edit->start_col;
|
||||
if (outby > 0)
|
||||
edit_scroll_left (edit, outby);
|
||||
p = edit->curs_row;
|
||||
outby = p - edit->widget.lines + 1 + b_extreme;
|
||||
outby = p - w->lines + 1 + b_extreme;
|
||||
if (outby > 0)
|
||||
edit_scroll_downward (edit, outby);
|
||||
outby = t_extreme - p;
|
||||
@ -1113,14 +1119,14 @@ edit_scroll_screen_over_cursor (WEdit * edit)
|
||||
edit_scroll_upward (edit, outby);
|
||||
edit_update_curs_row (edit);
|
||||
|
||||
edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET;
|
||||
edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
w->lines += EDIT_TEXT_VERTICAL_OFFSET;
|
||||
w->cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
|
||||
if (!edit->fullscreen)
|
||||
{
|
||||
edit->widget.x--;
|
||||
edit->widget.cols += 2;
|
||||
edit->widget.y--;
|
||||
edit->widget.lines += 2;
|
||||
w->x--;
|
||||
w->cols += 2;
|
||||
w->y--;
|
||||
w->lines += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ create_options_menu (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_drop_menu_cmd (Dlg_head * h, int which)
|
||||
edit_drop_menu_cmd (WDialog * h, int which)
|
||||
{
|
||||
WMenuBar *menubar;
|
||||
|
||||
@ -306,7 +306,7 @@ edit_init_menu (struct WMenuBar *menubar)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
edit_menu_cmd (Dlg_head * h)
|
||||
edit_menu_cmd (WDialog * h)
|
||||
{
|
||||
edit_drop_menu_cmd (h, -1);
|
||||
}
|
||||
@ -314,7 +314,7 @@ edit_menu_cmd (Dlg_head * h)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
edit_drop_hotkey_menu (Dlg_head * h, int key)
|
||||
edit_drop_hotkey_menu (WDialog * h, int key)
|
||||
{
|
||||
int m = 0;
|
||||
switch (key)
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
Written by:
|
||||
Paul Sheer, 1996, 1997
|
||||
Andrew Borodin <aborodin@vmail.ru> 2012
|
||||
Andrew Borodin <aborodin@vmail.ru>, 2012
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
@ -46,17 +46,14 @@
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define OPT_DLG_H 17
|
||||
#define OPT_DLG_W 74
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static const char *wrap_str[] = {
|
||||
N_("None"),
|
||||
N_("Dynamic paragraphing"),
|
||||
N_("Type writer wrap"),
|
||||
N_("&None"),
|
||||
N_("&Dynamic paragraphing"),
|
||||
N_("Type &writer wrap"),
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -106,7 +103,7 @@ edit_reload_syntax (void *data, void *user_data)
|
||||
{
|
||||
(void) user_data;
|
||||
|
||||
if (edit_widget_is_editor ((Widget *) data))
|
||||
if (edit_widget_is_editor (WIDGET (data)))
|
||||
{
|
||||
WEdit *edit = (WEdit *) data;
|
||||
edit_load_syntax (edit, NULL, edit->syntax_type);
|
||||
@ -118,56 +115,13 @@ edit_reload_syntax (void *data, void *user_data)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
edit_options_dialog (Dlg_head * h)
|
||||
edit_options_dialog (WDialog * h)
|
||||
{
|
||||
char wrap_length[16], tab_spacing[16], *p, *q;
|
||||
char wrap_length[16], tab_spacing[16];
|
||||
char *p, *q;
|
||||
int wrap_mode = 0;
|
||||
int old_syntax_hl;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), B_ENTER, NULL),
|
||||
/* 2 */ QUICK_LABEL (OPT_DLG_W / 2 + 1, OPT_DLG_W, 12, OPT_DLG_H,
|
||||
N_("Word wrap line length:")),
|
||||
/* 3 */ QUICK_INPUT (OPT_DLG_W / 2 + 25, OPT_DLG_W, 12, OPT_DLG_H,
|
||||
wrap_length, OPT_DLG_W / 2 - 4 - 24, 0, "edit-word-wrap", &p),
|
||||
/* 4 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 11, OPT_DLG_H,
|
||||
N_("&Group undo"), &option_group_undo),
|
||||
/* 5 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 10, OPT_DLG_H,
|
||||
N_("Cursor beyond end of line"), &option_cursor_beyond_eol),
|
||||
/* 6 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 9, OPT_DLG_H,
|
||||
N_("Pers&istent selection"), &option_persistent_selections),
|
||||
/* 7 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 8, OPT_DLG_H,
|
||||
N_("Synta&x highlighting"), &option_syntax_highlighting),
|
||||
/* 8 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 7, OPT_DLG_H,
|
||||
N_("Visible tabs"), &visible_tabs),
|
||||
/* 9 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 6, OPT_DLG_H,
|
||||
N_("Visible trailing spaces"), &visible_tws),
|
||||
/* 10 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 5, OPT_DLG_H,
|
||||
N_("Save file &position"), &option_save_position),
|
||||
/* 11 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 4, OPT_DLG_H,
|
||||
N_("Confir&m before saving"), &edit_confirm_save),
|
||||
/* 12 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 3, OPT_DLG_H,
|
||||
N_("&Return does autoindent"), &option_return_does_auto_indent),
|
||||
/* 13 */ QUICK_LABEL (3, OPT_DLG_W, 11, OPT_DLG_H, N_("Tab spacing:")),
|
||||
/* 14 */ QUICK_INPUT (3 + 24, OPT_DLG_W, 11, OPT_DLG_H,
|
||||
tab_spacing, OPT_DLG_W / 2 - 4 - 24, 0, "edit-tab-spacing", &q),
|
||||
/* 15 */ QUICK_CHECKBOX (3, OPT_DLG_W, 10, OPT_DLG_H,
|
||||
N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces),
|
||||
/* 16 */ QUICK_CHECKBOX (3, OPT_DLG_W, 9, OPT_DLG_H,
|
||||
N_("&Backspace through tabs"), &option_backspace_through_tabs),
|
||||
/* 17 */ QUICK_CHECKBOX (3, OPT_DLG_W, 8, OPT_DLG_H,
|
||||
N_("&Fake half tabs"), &option_fake_half_tabs),
|
||||
/* 18 */ QUICK_RADIO (4, OPT_DLG_W, 4, OPT_DLG_H, 3, wrap_str, &wrap_mode),
|
||||
/* 19 */ QUICK_LABEL (3, OPT_DLG_W, 3, OPT_DLG_H, N_("Wrap mode")),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
QuickDialog Quick_options = {
|
||||
OPT_DLG_W, OPT_DLG_H, -1, -1, N_("Editor options"),
|
||||
"[Editor options]", quick_widgets, NULL, NULL, FALSE
|
||||
};
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static gboolean i18n_flag = FALSE;
|
||||
|
||||
@ -188,8 +142,55 @@ edit_options_dialog (Dlg_head * h)
|
||||
else
|
||||
wrap_mode = 0;
|
||||
|
||||
if (quick_dialog (&Quick_options) == B_CANCEL)
|
||||
return;
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
quick_widget_t quick_widgets[] = {
|
||||
QUICK_START_COLUMNS,
|
||||
QUICK_START_GROUPBOX (N_("Wrap mode")),
|
||||
QUICK_RADIO (3, wrap_str, &wrap_mode, NULL),
|
||||
QUICK_STOP_GROUPBOX,
|
||||
QUICK_SEPARATOR (FALSE),
|
||||
QUICK_START_GROUPBOX (N_("Tabulation")),
|
||||
QUICK_CHECKBOX (N_("&Fake half tabs"), &option_fake_half_tabs, NULL),
|
||||
QUICK_CHECKBOX (N_("&Backspace through tabs"), &option_backspace_through_tabs,
|
||||
NULL),
|
||||
QUICK_CHECKBOX (N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces,
|
||||
NULL),
|
||||
QUICK_LABELED_INPUT (N_("Tab spacing:"), input_label_left, tab_spacing, 0,
|
||||
"edit-tab-spacing", &q, NULL),
|
||||
QUICK_STOP_GROUPBOX,
|
||||
QUICK_NEXT_COLUMN,
|
||||
QUICK_START_GROUPBOX (N_("Other options")),
|
||||
QUICK_CHECKBOX (N_("&Return does autoindent"), &option_return_does_auto_indent,
|
||||
NULL),
|
||||
QUICK_CHECKBOX (N_("Confir&m before saving"), &edit_confirm_save, NULL),
|
||||
QUICK_CHECKBOX (N_("Save file &position"), &option_save_position, NULL),
|
||||
QUICK_CHECKBOX (N_("&Visible trailing spaces"), &visible_tws, NULL),
|
||||
QUICK_CHECKBOX (N_("Visible &tabs"), &visible_tabs, NULL),
|
||||
QUICK_CHECKBOX (N_("Synta&x highlighting"), &option_syntax_highlighting, NULL),
|
||||
QUICK_CHECKBOX (N_("Pers&istent selection"), &option_persistent_selections,
|
||||
NULL),
|
||||
QUICK_CHECKBOX (N_("Cursor be&yond end of line"), &option_cursor_beyond_eol,
|
||||
NULL),
|
||||
QUICK_CHECKBOX (N_("&Group undo"), &option_group_undo, NULL),
|
||||
QUICK_LABELED_INPUT (N_("Word wrap line length:"), input_label_left,
|
||||
wrap_length, 0, "edit-word-wrap", &p, NULL),
|
||||
QUICK_STOP_GROUPBOX,
|
||||
QUICK_STOP_COLUMNS,
|
||||
QUICK_BUTTONS_OK_CANCEL,
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 74,
|
||||
N_("Editor options"), "[Editor options]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
if (quick_dialog (&qdlg) == B_CANCEL)
|
||||
return;
|
||||
}
|
||||
|
||||
old_syntax_hl = option_syntax_highlighting;
|
||||
|
||||
|
@ -84,8 +84,7 @@ static unsigned int edit_dlg_init_refcounter = 0;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm);
|
||||
static cb_ret_t edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
static cb_ret_t edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
|
||||
void *data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -139,49 +138,31 @@ edit_dlg_deinit (void)
|
||||
static void
|
||||
edit_about (void)
|
||||
{
|
||||
const char *header = N_("About");
|
||||
const char *button_name = N_("&OK");
|
||||
const char *const version = "MCEdit " VERSION;
|
||||
char text[BUF_LARGE];
|
||||
quick_widget_t quick_widgets[] = {
|
||||
/* *INDENT-OFF* */
|
||||
QUICK_LABEL ("MCEdit " VERSION, NULL),
|
||||
QUICK_SEPARATOR (TRUE),
|
||||
QUICK_LABEL (N_("A user friendly text editor\n"
|
||||
"written for the Midnight Commander."), NULL),
|
||||
QUICK_SEPARATOR (FALSE),
|
||||
QUICK_LABEL (N_("Copyright (C) 1996-2012 the Free Software Foundation"), NULL),
|
||||
QUICK_START_BUTTONS (TRUE, TRUE),
|
||||
QUICK_BUTTON (N_("&OK"), B_ENTER, NULL, NULL),
|
||||
QUICK_END
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
int win_len, version_len, button_len;
|
||||
int cols, lines;
|
||||
quick_dialog_t qdlg = {
|
||||
-1, -1, 40,
|
||||
N_("About"), "[Internal File Editor]",
|
||||
quick_widgets, NULL, NULL
|
||||
};
|
||||
|
||||
Dlg_head *about_dlg;
|
||||
quick_widgets[0].pos_flags = WPOS_KEEP_TOP | WPOS_CENTER_HORZ;
|
||||
quick_widgets[2].pos_flags = WPOS_KEEP_TOP | WPOS_CENTER_HORZ;
|
||||
quick_widgets[4].pos_flags = WPOS_KEEP_TOP | WPOS_CENTER_HORZ;
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
header = _(header);
|
||||
button_name = _(button_name);
|
||||
#endif
|
||||
|
||||
button_len = str_term_width1 (button_name) + 5;
|
||||
version_len = str_term_width1 (version);
|
||||
|
||||
g_snprintf (text, sizeof (text),
|
||||
_("Copyright (C) 1996-2012 the Free Software Foundation\n\n"
|
||||
" A user friendly text editor\n"
|
||||
" written for the Midnight Commander"));
|
||||
|
||||
win_len = str_term_width1 (header);
|
||||
win_len = max (win_len, version_len);
|
||||
win_len = max (win_len, button_len);
|
||||
|
||||
/* count width and height of text */
|
||||
str_msg_term_size (text, &lines, &cols);
|
||||
lines += 9;
|
||||
cols = max (win_len, cols) + 6;
|
||||
|
||||
/* dialog */
|
||||
about_dlg = create_dlg (TRUE, 0, 0, lines, cols, dialog_colors, NULL, NULL,
|
||||
"[Internal File Editor]", header, DLG_CENTER | DLG_TRYUP);
|
||||
|
||||
add_widget (about_dlg, label_new (3, (cols - version_len) / 2, version));
|
||||
add_widget (about_dlg, label_new (5, 3, text));
|
||||
add_widget (about_dlg, button_new (lines - 3, (cols - button_len) / 2,
|
||||
B_ENTER, NORMAL_BUTTON, button_name, NULL));
|
||||
|
||||
run_dlg (about_dlg);
|
||||
destroy_dlg (about_dlg);
|
||||
(void) quick_dialog (&qdlg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -208,16 +189,16 @@ edit_help (void)
|
||||
static void
|
||||
edit_dialog_resize_cb (void *data, void *user_data)
|
||||
{
|
||||
Widget *w = (Widget *) data;
|
||||
Widget *w = WIDGET (data);
|
||||
|
||||
(void) user_data;
|
||||
|
||||
if (edit_widget_is_editor (w) && ((WEdit *) w)->fullscreen)
|
||||
{
|
||||
Dlg_head *h = w->owner;
|
||||
Widget *wh = WIDGET (w->owner);
|
||||
|
||||
w->lines = h->lines - 2;
|
||||
w->cols = h->cols;
|
||||
w->lines = wh->lines - 2;
|
||||
w->cols = wh->cols;
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,9 +213,8 @@ static void
|
||||
edit_restore_size (WEdit * edit)
|
||||
{
|
||||
edit->drag_state = MCEDIT_DRAG_NORMAL;
|
||||
widget_set_size ((Widget *) edit, edit->y_prev, edit->x_prev,
|
||||
edit->lines_prev, edit->cols_prev);
|
||||
dlg_redraw (((Widget *) edit)->owner);
|
||||
widget_set_size (WIDGET (edit), edit->y_prev, edit->x_prev, edit->lines_prev, edit->cols_prev);
|
||||
dlg_redraw (WIDGET (edit)->owner);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -248,25 +228,25 @@ edit_restore_size (WEdit * edit)
|
||||
static void
|
||||
edit_window_move (WEdit * edit, unsigned long command)
|
||||
{
|
||||
Widget *w = (Widget *) edit;
|
||||
Dlg_head *h = w->owner;
|
||||
Widget *w = WIDGET (edit);
|
||||
Widget *wh = WIDGET (w->owner);
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case CK_Up:
|
||||
if (w->y > h->y + 1) /* menubar */
|
||||
if (w->y > wh->y + 1) /* menubar */
|
||||
w->y--;
|
||||
break;
|
||||
case CK_Down:
|
||||
if (w->y < h->y + h->lines - 2) /* buttonbar */
|
||||
if (w->y < wh->y + wh->lines - 2) /* buttonbar */
|
||||
w->y++;
|
||||
break;
|
||||
case CK_Left:
|
||||
if (w->x + w->cols > h->x)
|
||||
if (w->x + w->cols > wh->x)
|
||||
w->x--;
|
||||
break;
|
||||
case CK_Right:
|
||||
if (w->x < h->x + h->cols)
|
||||
if (w->x < wh->x + wh->cols)
|
||||
w->x++;
|
||||
break;
|
||||
default:
|
||||
@ -274,7 +254,7 @@ edit_window_move (WEdit * edit, unsigned long command)
|
||||
}
|
||||
|
||||
edit->force |= REDRAW_PAGE;
|
||||
dlg_redraw (h);
|
||||
dlg_redraw (w->owner);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -288,8 +268,8 @@ edit_window_move (WEdit * edit, unsigned long command)
|
||||
static void
|
||||
edit_window_resize (WEdit * edit, unsigned long command)
|
||||
{
|
||||
Widget *w = (Widget *) edit;
|
||||
Dlg_head *h = w->owner;
|
||||
Widget *w = WIDGET (edit);
|
||||
Widget *wh = WIDGET (w->owner);
|
||||
|
||||
switch (command)
|
||||
{
|
||||
@ -298,7 +278,7 @@ edit_window_resize (WEdit * edit, unsigned long command)
|
||||
w->lines--;
|
||||
break;
|
||||
case CK_Down:
|
||||
if (w->y + w->lines < h->y + h->lines - 1) /* buttonbar */
|
||||
if (w->y + w->lines < wh->y + wh->lines - 1) /* buttonbar */
|
||||
w->lines++;
|
||||
break;
|
||||
case CK_Left:
|
||||
@ -306,7 +286,7 @@ edit_window_resize (WEdit * edit, unsigned long command)
|
||||
w->cols--;
|
||||
break;
|
||||
case CK_Right:
|
||||
if (w->x + w->cols < h->x + h->cols)
|
||||
if (w->x + w->cols < wh->x + wh->cols)
|
||||
w->cols++;
|
||||
break;
|
||||
default:
|
||||
@ -314,7 +294,7 @@ edit_window_resize (WEdit * edit, unsigned long command)
|
||||
}
|
||||
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
dlg_redraw (h);
|
||||
dlg_redraw (w->owner);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -334,7 +314,7 @@ get_hotkey (int n)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edit_window_list (const Dlg_head * h)
|
||||
edit_window_list (const WDialog * h)
|
||||
{
|
||||
const size_t offset = 2; /* skip menu and buttonbar */
|
||||
const size_t dlg_num = g_list_length (h->widgets) - offset;
|
||||
@ -350,7 +330,7 @@ edit_window_list (const Dlg_head * h)
|
||||
listbox = create_listbox_window (lines, cols, _("Open files"), "[Open files]");
|
||||
|
||||
for (w = h->widgets; w != NULL; w = g_list_next (w))
|
||||
if (edit_widget_is_editor ((Widget *) w->data))
|
||||
if (edit_widget_is_editor (WIDGET (w->data)))
|
||||
{
|
||||
WEdit *e = (WEdit *) w->data;
|
||||
char *fname;
|
||||
@ -367,7 +347,7 @@ edit_window_list (const Dlg_head * h)
|
||||
}
|
||||
|
||||
listbox_add_item (listbox->list, LISTBOX_APPEND_AT_END, get_hotkey (i++),
|
||||
str_term_trim (fname, listbox->list->widget.cols - 2), NULL);
|
||||
str_term_trim (fname, WIDGET (listbox->list)->cols - 2), NULL);
|
||||
g_free (fname);
|
||||
}
|
||||
|
||||
@ -405,7 +385,7 @@ edit_get_shortcut (unsigned long command)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
edit_get_title (const Dlg_head * h, size_t len)
|
||||
edit_get_title (const WDialog * h, size_t len)
|
||||
{
|
||||
const WEdit *edit = find_editor (h);
|
||||
const char *modified = edit->modified ? "(*) " : " ";
|
||||
@ -436,7 +416,7 @@ static int
|
||||
edit_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
WEdit *edit = (WEdit *) data;
|
||||
Widget *w = (Widget *) data;
|
||||
Widget *w = WIDGET (data);
|
||||
Gpm_Event local;
|
||||
|
||||
if (!mouse_global_in_widget (event, w))
|
||||
@ -460,13 +440,13 @@ edit_event (Gpm_Event * event, void *data)
|
||||
/* click on the top line (move) */
|
||||
int dx = edit->fullscreen ? 0 : 2;
|
||||
|
||||
if (local.x == edit->widget.cols - dx - 1)
|
||||
if (local.x == w->cols - dx - 1)
|
||||
{
|
||||
edit_dialog_callback (w->owner, NULL, DLG_ACTION, CK_Close, NULL);
|
||||
send_message (w->owner, NULL, MSG_ACTION, CK_Close, NULL);
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
if (local.x == edit->widget.cols - dx - 4)
|
||||
if (local.x == w->cols - dx - 4)
|
||||
{
|
||||
edit_toggle_fullscreen (edit);
|
||||
return MOU_NORMAL;
|
||||
@ -628,7 +608,7 @@ edit_event (Gpm_Event * event, void *data)
|
||||
}
|
||||
else if (!edit->fullscreen)
|
||||
{
|
||||
Dlg_head *h = w->owner;
|
||||
Widget *h = WIDGET (w->owner);
|
||||
|
||||
if (edit->drag_state == MCEDIT_DRAG_MOVE)
|
||||
{
|
||||
@ -655,7 +635,7 @@ edit_event (Gpm_Event * event, void *data)
|
||||
edit->force |= REDRAW_COMPLETELY;
|
||||
}
|
||||
|
||||
dlg_redraw (h);
|
||||
dlg_redraw (w->owner);
|
||||
}
|
||||
}
|
||||
|
||||
@ -674,13 +654,14 @@ edit_event (Gpm_Event * event, void *data)
|
||||
static int
|
||||
edit_dialog_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
Dlg_head *h = (Dlg_head *) data;
|
||||
WDialog *h = DIALOG (data);
|
||||
Widget *w;
|
||||
Widget *wh = WIDGET (h);
|
||||
int ret = MOU_UNHANDLED;
|
||||
|
||||
w = (Widget *) find_menubar (h);
|
||||
w = WIDGET (find_menubar (h));
|
||||
|
||||
if (event->y == h->y + 1 && (event->type & GPM_DOWN) != 0 && !((WMenuBar *) w)->is_active)
|
||||
if (event->y == wh->y + 1 && (event->type & GPM_DOWN) != 0 && !MENUBAR (w)->is_active)
|
||||
{
|
||||
/* menubar */
|
||||
|
||||
@ -690,11 +671,11 @@ edit_dialog_event (Gpm_Event * event, void *data)
|
||||
|
||||
/* Try find top fullscreen window */
|
||||
for (l = h->widgets; l != NULL; l = g_list_next (l))
|
||||
if (edit_widget_is_editor ((Widget *) l->data) && ((WEdit *) l->data)->fullscreen)
|
||||
if (edit_widget_is_editor (WIDGET (l->data)) && ((WEdit *) l->data)->fullscreen)
|
||||
top = l;
|
||||
|
||||
/* Handle fullscreen/close buttons in the top line */
|
||||
x = h->x + h->cols + 1 - 6;
|
||||
x = wh->x + wh->cols + 1 - 6;
|
||||
|
||||
if (top != NULL && event->x >= x)
|
||||
{
|
||||
@ -713,7 +694,7 @@ edit_dialog_event (Gpm_Event * event, void *data)
|
||||
if (x <= 2)
|
||||
edit_toggle_fullscreen (e);
|
||||
else
|
||||
edit_dialog_callback (h, NULL, DLG_ACTION, CK_Close, NULL);
|
||||
send_message (h, NULL, MSG_ACTION, CK_Close, NULL);
|
||||
|
||||
ret = MOU_NORMAL;
|
||||
}
|
||||
@ -728,14 +709,15 @@ edit_dialog_event (Gpm_Event * event, void *data)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
edit_dialog_command_execute (Dlg_head * h, unsigned long command)
|
||||
edit_dialog_command_execute (WDialog * h, unsigned long command)
|
||||
{
|
||||
Widget *wh = WIDGET (h);
|
||||
gboolean ret = MSG_HANDLED;
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case CK_EditNew:
|
||||
edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, NULL, 0);
|
||||
edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0);
|
||||
break;
|
||||
case CK_EditFile:
|
||||
edit_load_cmd (h);
|
||||
@ -748,7 +730,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
|
||||
break;
|
||||
case CK_Close:
|
||||
/* if there are no opened files anymore, close MC editor */
|
||||
if (edit_widget_is_editor ((Widget *) h->current->data) &&
|
||||
if (edit_widget_is_editor (WIDGET (h->current->data)) &&
|
||||
edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL)
|
||||
dlg_stop (h);
|
||||
break;
|
||||
@ -762,7 +744,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
|
||||
case CK_Quit:
|
||||
case CK_Cancel:
|
||||
{
|
||||
Widget *w = (Widget *) h->current->data;
|
||||
Widget *w = WIDGET (h->current->data);
|
||||
|
||||
if (!edit_widget_is_editor (w) || ((WEdit *) w)->drag_state == MCEDIT_DRAG_NORMAL)
|
||||
dlg_stop (h);
|
||||
@ -796,7 +778,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
|
||||
break;
|
||||
case CK_WindowMove:
|
||||
case CK_WindowResize:
|
||||
if (edit_widget_is_editor ((Widget *) h->current->data))
|
||||
if (edit_widget_is_editor (WIDGET (h->current->data)))
|
||||
edit_handle_move_resize ((WEdit *) h->current->data, command);
|
||||
break;
|
||||
case CK_WindowList:
|
||||
@ -830,7 +812,7 @@ edit_dialog_command_execute (Dlg_head * h, unsigned long command)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
edit_quit (Dlg_head * h)
|
||||
edit_quit (WDialog * h)
|
||||
{
|
||||
GList *l;
|
||||
WEdit *e = NULL;
|
||||
@ -838,7 +820,7 @@ edit_quit (Dlg_head * h)
|
||||
h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */
|
||||
|
||||
for (l = h->widgets; l != NULL; l = g_list_next (l))
|
||||
if (edit_widget_is_editor ((Widget *) l->data))
|
||||
if (edit_widget_is_editor (WIDGET (l->data)))
|
||||
{
|
||||
e = (WEdit *) l->data;
|
||||
|
||||
@ -868,13 +850,13 @@ static inline void
|
||||
edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
|
||||
{
|
||||
buttonbar_set_label (bb, 1, Q_ ("ButtonBar|Help"), editor_map, NULL);
|
||||
buttonbar_set_label (bb, 2, Q_ ("ButtonBar|Save"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 3, Q_ ("ButtonBar|Mark"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 4, Q_ ("ButtonBar|Replac"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 5, Q_ ("ButtonBar|Copy"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 6, Q_ ("ButtonBar|Move"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, (Widget *) edit);
|
||||
buttonbar_set_label (bb, 2, Q_ ("ButtonBar|Save"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 3, Q_ ("ButtonBar|Mark"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 4, Q_ ("ButtonBar|Replac"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 5, Q_ ("ButtonBar|Copy"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 6, Q_ ("ButtonBar|Move"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 7, Q_ ("ButtonBar|Search"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 8, Q_ ("ButtonBar|Delete"), editor_map, WIDGET (edit));
|
||||
buttonbar_set_label (bb, 9, Q_ ("ButtonBar|PullDn"), editor_map, NULL);
|
||||
buttonbar_set_label (bb, 10, Q_ ("ButtonBar|Quit"), editor_map, NULL);
|
||||
}
|
||||
@ -883,66 +865,67 @@ edit_set_buttonbar (WEdit * edit, WButtonBar * bb)
|
||||
/** Callback for the edit dialog */
|
||||
|
||||
static cb_ret_t
|
||||
edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
edit_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WMenuBar *menubar;
|
||||
WButtonBar *buttonbar;
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_INIT:
|
||||
case MSG_INIT:
|
||||
edit_dlg_init ();
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_DRAW:
|
||||
/* don't use common_dialog_repaint() -- we don't need a frame */
|
||||
case MSG_DRAW:
|
||||
/* don't use dlg_default_repaint() -- we don't need a frame */
|
||||
tty_setcolor (EDITOR_BACKGROUND);
|
||||
dlg_erase (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_RESIZE:
|
||||
case MSG_RESIZE:
|
||||
menubar = find_menubar (h);
|
||||
buttonbar = find_buttonbar (h);
|
||||
/* dlg_set_size() is surplus for this case */
|
||||
h->lines = LINES;
|
||||
h->cols = COLS;
|
||||
widget_set_size (&buttonbar->widget, h->lines - 1, h->x, 1, h->cols);
|
||||
widget_set_size (&menubar->widget, h->y, h->x, 1, h->cols);
|
||||
w->lines = LINES;
|
||||
w->cols = COLS;
|
||||
widget_set_size (WIDGET (buttonbar), w->lines - 1, w->x, 1, w->cols);
|
||||
widget_set_size (WIDGET (menubar), w->y, w->x, 1, w->cols);
|
||||
menubar_arrange (menubar);
|
||||
g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_ACTION:
|
||||
case MSG_ACTION:
|
||||
/* shortcut */
|
||||
if (sender == NULL)
|
||||
return edit_dialog_command_execute (h, parm);
|
||||
/* message from menu */
|
||||
menubar = find_menubar (h);
|
||||
if (sender == (Widget *) menubar)
|
||||
if (sender == WIDGET (menubar))
|
||||
{
|
||||
if (edit_dialog_command_execute (h, parm) == MSG_HANDLED)
|
||||
return MSG_HANDLED;
|
||||
/* try send command to the current window */
|
||||
return send_message ((Widget *) h->current->data, WIDGET_COMMAND, parm);
|
||||
return send_message (h->current->data, NULL, MSG_ACTION, parm, NULL);
|
||||
}
|
||||
/* message from buttonbar */
|
||||
buttonbar = find_buttonbar (h);
|
||||
if (sender == (Widget *) buttonbar)
|
||||
if (sender == WIDGET (buttonbar))
|
||||
{
|
||||
if (data != NULL)
|
||||
return send_message ((Widget *) data, WIDGET_COMMAND, parm);
|
||||
return send_message (data, NULL, MSG_ACTION, parm, NULL);
|
||||
return edit_dialog_command_execute (h, parm);
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case DLG_KEY:
|
||||
case MSG_KEY:
|
||||
{
|
||||
Widget *w = h->current->data;
|
||||
Widget *we = WIDGET (h->current->data);
|
||||
cb_ret_t ret = MSG_NOT_HANDLED;
|
||||
|
||||
if (edit_widget_is_editor (w))
|
||||
if (edit_widget_is_editor (we))
|
||||
{
|
||||
WEdit *e = (WEdit *) w;
|
||||
WEdit *e = (WEdit *) we;
|
||||
unsigned long command;
|
||||
|
||||
if (!e->extmod)
|
||||
@ -961,46 +944,46 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
|
||||
}
|
||||
|
||||
/* hardcoded menu hotkeys (see edit_drop_hotkey_menu) */
|
||||
case DLG_UNHANDLED_KEY:
|
||||
case MSG_UNHANDLED_KEY:
|
||||
return edit_drop_hotkey_menu (h, parm) ? MSG_HANDLED : MSG_NOT_HANDLED;
|
||||
|
||||
case DLG_VALIDATE:
|
||||
case MSG_VALIDATE:
|
||||
edit_quit (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_END:
|
||||
case MSG_END:
|
||||
edit_dlg_deinit ();
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
edit_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
WEdit *e = (WEdit *) w;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WIDGET_FOCUS:
|
||||
edit_set_buttonbar (e, find_buttonbar (e->widget.owner));
|
||||
case MSG_FOCUS:
|
||||
edit_set_buttonbar (e, find_buttonbar (w->owner));
|
||||
/* fall through */
|
||||
|
||||
case WIDGET_DRAW:
|
||||
case MSG_DRAW:
|
||||
e->force |= REDRAW_COMPLETELY;
|
||||
edit_update_screen (e);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_UNFOCUS:
|
||||
case MSG_UNFOCUS:
|
||||
/* redraw frame and status */
|
||||
edit_status (e, FALSE);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_KEY:
|
||||
case MSG_KEY:
|
||||
{
|
||||
int cmd, ch;
|
||||
cb_ret_t ret = MSG_NOT_HANDLED;
|
||||
@ -1021,13 +1004,13 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return ret;
|
||||
}
|
||||
|
||||
case WIDGET_COMMAND:
|
||||
case MSG_ACTION:
|
||||
/* command from menubar or buttonbar */
|
||||
edit_execute_key_command (e, parm, -1);
|
||||
edit_update_screen (e);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case WIDGET_CURSOR:
|
||||
case MSG_CURSOR:
|
||||
{
|
||||
int y, x;
|
||||
|
||||
@ -1039,12 +1022,12 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
case WIDGET_DESTROY:
|
||||
case MSG_DESTROY:
|
||||
edit_clean (e);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_proc (msg, parm);
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1079,7 +1062,7 @@ gboolean
|
||||
edit_files (const GList * files)
|
||||
{
|
||||
static gboolean made_directory = FALSE;
|
||||
Dlg_head *edit_dlg;
|
||||
WDialog *edit_dlg;
|
||||
WMenuBar *menubar;
|
||||
const GList *file;
|
||||
gboolean ok = FALSE;
|
||||
@ -1117,11 +1100,12 @@ edit_files (const GList * files)
|
||||
|
||||
for (file = files; file != NULL; file = g_list_next (file))
|
||||
{
|
||||
Widget *w = WIDGET (edit_dlg);
|
||||
mcedit_arg_t *f = (mcedit_arg_t *) file->data;
|
||||
gboolean f_ok;
|
||||
|
||||
f_ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x,
|
||||
edit_dlg->lines - 2, edit_dlg->cols, f->file_vpath, f->line_number);
|
||||
f_ok = edit_add_window (edit_dlg, w->y + 1, w->x, w->lines - 2, w->cols, f->file_vpath,
|
||||
f->line_number);
|
||||
/* at least one file has been opened succefully */
|
||||
ok = ok || f_ok;
|
||||
}
|
||||
@ -1146,9 +1130,9 @@ edit_get_file_name (const WEdit * edit)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WEdit *
|
||||
find_editor (const Dlg_head * h)
|
||||
find_editor (const WDialog * h)
|
||||
{
|
||||
if (edit_widget_is_editor ((Widget *) h->current->data))
|
||||
if (edit_widget_is_editor (WIDGET (h->current->data)))
|
||||
return (WEdit *) h->current->data;
|
||||
return (WEdit *) find_widget_type (h, edit_callback);
|
||||
}
|
||||
@ -1172,11 +1156,12 @@ edit_widget_is_editor (const Widget * w)
|
||||
void
|
||||
edit_update_screen (WEdit * e)
|
||||
{
|
||||
WDialog *h = WIDGET (e)->owner;
|
||||
|
||||
edit_scroll_screen_over_cursor (e);
|
||||
edit_update_curs_col (e);
|
||||
|
||||
edit_status (e, (e->force & REDRAW_COMPLETELY) != 0 &&
|
||||
(void *) e == ((Widget *) e)->owner->current->data);
|
||||
edit_status (e, (e->force & REDRAW_COMPLETELY) != 0 && (void *) e == h->current->data);
|
||||
|
||||
/* pop all events for this window for internal handling */
|
||||
if (!is_idle ())
|
||||
@ -1188,7 +1173,7 @@ edit_update_screen (WEdit * e)
|
||||
edit_render_keypress (e);
|
||||
}
|
||||
|
||||
buttonbar_redraw (find_buttonbar (((Widget *) e)->owner));
|
||||
buttonbar_redraw (find_buttonbar (h));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1201,10 +1186,12 @@ edit_update_screen (WEdit * e)
|
||||
void
|
||||
edit_save_size (WEdit * edit)
|
||||
{
|
||||
edit->y_prev = edit->widget.y;
|
||||
edit->x_prev = edit->widget.x;
|
||||
edit->lines_prev = edit->widget.lines;
|
||||
edit->cols_prev = edit->widget.cols;
|
||||
Widget *w = WIDGET (edit);
|
||||
|
||||
edit->y_prev = w->y;
|
||||
edit->x_prev = w->x;
|
||||
edit->lines_prev = w->lines;
|
||||
edit->cols_prev = w->cols;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -1223,7 +1210,7 @@ edit_save_size (WEdit * edit)
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path_t * f, long fline)
|
||||
edit_add_window (WDialog * h, int y, int x, int lines, int cols, const vfs_path_t * f, long fline)
|
||||
{
|
||||
WEdit *edit;
|
||||
Widget *w;
|
||||
@ -1232,10 +1219,9 @@ edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path
|
||||
if (edit == NULL)
|
||||
return FALSE;
|
||||
|
||||
w = (Widget *) edit;
|
||||
w = WIDGET (edit);
|
||||
w->callback = edit_callback;
|
||||
w->mouse = edit_event;
|
||||
widget_want_cursor (*w, TRUE);
|
||||
|
||||
add_widget (h, w);
|
||||
dlg_redraw (h);
|
||||
@ -1348,8 +1334,6 @@ edit_handle_move_resize (WEdit * edit, unsigned long command)
|
||||
void
|
||||
edit_toggle_fullscreen (WEdit * edit)
|
||||
{
|
||||
Dlg_head *h = ((Widget *) edit)->owner;
|
||||
|
||||
edit->fullscreen = !edit->fullscreen;
|
||||
edit->force = REDRAW_COMPLETELY;
|
||||
|
||||
@ -1357,8 +1341,11 @@ edit_toggle_fullscreen (WEdit * edit)
|
||||
edit_restore_size (edit);
|
||||
else
|
||||
{
|
||||
Widget *w = WIDGET (edit);
|
||||
Widget *h = WIDGET (w->owner);
|
||||
|
||||
edit_save_size (edit);
|
||||
widget_set_size ((Widget *) edit, h->y + 1, h->x, h->lines - 2, h->cols);
|
||||
widget_set_size (w, h->y + 1, h->x, h->lines - 2, h->cols);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
edit_update_screen (edit);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
|
||||
unsigned int i;
|
||||
int res;
|
||||
char *curr = NULL;
|
||||
Dlg_head *sug_dlg;
|
||||
WDialog *sug_dlg;
|
||||
WListbox *sug_list;
|
||||
int max_btn_len = 0;
|
||||
int add_len;
|
||||
@ -109,9 +109,15 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
|
||||
|
||||
sug_dlg_w += max_btn_len;
|
||||
sug_dlg_w = max (sug_dlg_w, word_label_len) + 1;
|
||||
|
||||
sug_dlg = create_dlg (TRUE, ypos, xpos, sug_dlg_h, sug_dlg_w,
|
||||
dialog_colors, NULL, NULL, "[ASpell]", _("Check word"), DLG_COMPACT);
|
||||
|
||||
add_widget (sug_dlg, label_new (1, 2, lang_label));
|
||||
add_widget (sug_dlg, label_new (3, 2, word_label));
|
||||
|
||||
add_widget (sug_dlg, groupbox_new (4, 2, sug_dlg_h - 5, 25, _("Suggest")));
|
||||
|
||||
sug_list = listbox_new (5, 2, sug_dlg_h - 7, 24, FALSE, NULL);
|
||||
for (i = 0; i < suggest->len; i++)
|
||||
listbox_add_item (sug_list, LISTBOX_APPEND_AT_END, 0, g_array_index (suggest, char *, i),
|
||||
@ -123,10 +129,6 @@ spell_dialog_spell_suggest_show (WEdit * edit, const char *word, char **new_word
|
||||
add_widget (sug_dlg, skip_btn);
|
||||
add_widget (sug_dlg, cancel_button);
|
||||
|
||||
add_widget (sug_dlg, label_new (1, 2, lang_label));
|
||||
add_widget (sug_dlg, label_new (3, 2, word_label));
|
||||
add_widget (sug_dlg, groupbox_new (4, 2, sug_dlg_h - 5, 25, _("Suggest")));
|
||||
|
||||
res = run_dlg (sug_dlg);
|
||||
if (res == B_ENTER)
|
||||
{
|
||||
|
@ -58,16 +58,13 @@
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define BX 5
|
||||
#define BY 6
|
||||
|
||||
#define TX 50
|
||||
#define TY 2
|
||||
#define BY 5
|
||||
|
||||
#define BUTTONS 9
|
||||
#define BUTTONS_PERM 5
|
||||
|
||||
#define B_SETALL B_USER
|
||||
#define B_SKIP (B_USER + 1)
|
||||
|
||||
#define B_OWN (B_USER + 3)
|
||||
#define B_GRP (B_USER + 4)
|
||||
#define B_OTH (B_USER + 5)
|
||||
@ -78,43 +75,47 @@
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct Dlg_head *ch_dlg;
|
||||
static struct WDialog *ch_dlg;
|
||||
|
||||
static struct
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
unsigned long id;
|
||||
int ret_cmd, flags, x, len;
|
||||
const char *text;
|
||||
} chown_advanced_but[BUTTONS] =
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
{ B_CANCEL, NORMAL_BUTTON, 4, 53, N_("&Cancel") },
|
||||
{ B_ENTER, DEFPUSH_BUTTON,4, 40, N_("&Set") },
|
||||
{ B_SKIP, NORMAL_BUTTON, 4, 23, N_("S&kip") },
|
||||
{ B_SETALL, NORMAL_BUTTON, 4, 0, N_("Set &all")},
|
||||
{ B_ENTER, NARROW_BUTTON, 0, 47, ""},
|
||||
{ B_ENTER, NARROW_BUTTON, 0, 29, ""},
|
||||
{ B_ENTER, NARROW_BUTTON, 0, 19, " "},
|
||||
{ B_ENTER, NARROW_BUTTON, 0, 11, " "},
|
||||
{ B_ENTER, NARROW_BUTTON, 0, 3, " "}
|
||||
{ 0, B_ENTER, NARROW_BUTTON, 3, 0, " "},
|
||||
{ 0, B_ENTER, NARROW_BUTTON, 11, 0, " "},
|
||||
{ 0, B_ENTER, NARROW_BUTTON, 19, 0, " "},
|
||||
{ 0, B_ENTER, NARROW_BUTTON, 29, 0, ""},
|
||||
{ 0, B_ENTER, NARROW_BUTTON, 47, 0, ""},
|
||||
|
||||
{ 0, B_SETALL, NORMAL_BUTTON, 0, 0, N_("Set &all")},
|
||||
{ 0, B_SKIP, NORMAL_BUTTON, 0, 0, N_("S&kip") },
|
||||
{ 0, B_ENTER, DEFPUSH_BUTTON, 0, 0, N_("&Set") },
|
||||
{ 0, B_CANCEL, NORMAL_BUTTON, 0, 0, N_("&Cancel") }
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
static WButton *b_att[3]; /* permission */
|
||||
static WButton *b_user, *b_group; /* owner */
|
||||
static WLabel *l_filename;
|
||||
static WLabel *l_mode;
|
||||
|
||||
static int files_on_begin; /* Number of files at startup */
|
||||
static int flag_pos;
|
||||
static int x_toggle;
|
||||
static char ch_flags[11];
|
||||
static const char ch_perm[] = "rwx";
|
||||
static mode_t ch_cmode;
|
||||
static struct stat *sf_stat;
|
||||
static int need_update;
|
||||
static int end_chown;
|
||||
static gboolean need_update = FALSE;
|
||||
static gboolean end_chown = FALSE;
|
||||
static int current_file;
|
||||
static int single_set;
|
||||
static gboolean single_set = FALSE;
|
||||
static char *fname;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
@ -136,7 +137,7 @@ inc_flag_pos (int f_pos)
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
flag_pos++;
|
||||
if (!(flag_pos % 3) || f_pos > 2)
|
||||
if ((flag_pos % 3) == 0 || f_pos > 2)
|
||||
return MSG_NOT_HANDLED;
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
@ -146,13 +147,13 @@ inc_flag_pos (int f_pos)
|
||||
static cb_ret_t
|
||||
dec_flag_pos (int f_pos)
|
||||
{
|
||||
if (!flag_pos)
|
||||
if (flag_pos == 0)
|
||||
{
|
||||
flag_pos = 10;
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
flag_pos--;
|
||||
if (!((flag_pos + 1) % 3) || f_pos > 2)
|
||||
if (((flag_pos + 1) % 3) == 0 || f_pos > 2)
|
||||
return MSG_NOT_HANDLED;
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
@ -230,19 +231,19 @@ print_flags (void)
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
dlg_move (ch_dlg, BY + 1, 9 + i);
|
||||
widget_move (ch_dlg, BY + 1, 9 + i);
|
||||
tty_print_char (ch_flags[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
dlg_move (ch_dlg, BY + 1, 17 + i);
|
||||
widget_move (ch_dlg, BY + 1, 17 + i);
|
||||
tty_print_char (ch_flags[i + 3]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
dlg_move (ch_dlg, BY + 1, 25 + i);
|
||||
widget_move (ch_dlg, BY + 1, 25 + i);
|
||||
tty_print_char (ch_flags[i + 6]);
|
||||
}
|
||||
|
||||
@ -250,12 +251,12 @@ print_flags (void)
|
||||
|
||||
for (i = 0; i < 15; i++)
|
||||
{
|
||||
dlg_move (ch_dlg, BY + 1, 35 + i);
|
||||
widget_move (ch_dlg, BY + 1, 35 + i);
|
||||
tty_print_char (ch_flags[9]);
|
||||
}
|
||||
for (i = 0; i < 15; i++)
|
||||
{
|
||||
dlg_move (ch_dlg, BY + 1, 53 + i);
|
||||
widget_move (ch_dlg, BY + 1, 53 + i);
|
||||
tty_print_char (ch_flags[10]);
|
||||
}
|
||||
}
|
||||
@ -263,49 +264,67 @@ print_flags (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
update_mode (Dlg_head * h)
|
||||
chown_info_update (void)
|
||||
{
|
||||
char buffer[BUF_SMALL];
|
||||
|
||||
/* mode */
|
||||
g_snprintf (buffer, sizeof (buffer), "Permissions (octal): %o", get_mode ());
|
||||
label_set_text (l_mode, buffer);
|
||||
|
||||
/* permissions */
|
||||
update_permissions ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
update_mode (WDialog * h)
|
||||
{
|
||||
print_flags ();
|
||||
tty_setcolor (COLOR_NORMAL);
|
||||
dlg_move (h, BY + 2, 9);
|
||||
tty_printf ("%12o", get_mode ());
|
||||
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
|
||||
chown_info_update ();
|
||||
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
chl_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
chl_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_KEY:
|
||||
case MSG_KEY:
|
||||
switch (parm)
|
||||
{
|
||||
case KEY_LEFT:
|
||||
case KEY_RIGHT:
|
||||
h->ret_value = parm;
|
||||
dlg_stop (h);
|
||||
{
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
h->ret_value = parm;
|
||||
dlg_stop (h);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_enter_key (Dlg_head * h, int f_pos)
|
||||
do_enter_key (WDialog * h, int f_pos)
|
||||
{
|
||||
Dlg_head *chl_dlg;
|
||||
WDialog *chl_dlg;
|
||||
WListbox *chl_list;
|
||||
struct passwd *chl_pass;
|
||||
struct group *chl_grp;
|
||||
int fe;
|
||||
int lxx, lyy, chl_end, b_pos;
|
||||
int is_owner;
|
||||
int lxx, lyy, b_pos;
|
||||
gboolean chl_end, is_owner;
|
||||
const char *title;
|
||||
int result;
|
||||
|
||||
do
|
||||
{
|
||||
@ -314,25 +333,21 @@ do_enter_key (Dlg_head * h, int f_pos)
|
||||
|
||||
lxx = (COLS - 74) / 2 + (is_owner ? 35 : 53);
|
||||
lyy = (LINES - 13) / 2;
|
||||
chl_end = 0;
|
||||
chl_end = FALSE;
|
||||
|
||||
chl_dlg =
|
||||
create_dlg (TRUE, lyy, lxx, 13, 17, dialog_colors, chl_callback, NULL,
|
||||
"[Advanced Chown]", title, DLG_COMPACT | DLG_REVERSE);
|
||||
"[Advanced Chown]", title, DLG_COMPACT);
|
||||
|
||||
/* get new listboxes */
|
||||
chl_list = listbox_new (1, 1, 11, 15, FALSE, NULL);
|
||||
|
||||
listbox_add_item (chl_list, LISTBOX_APPEND_AT_END, 0, "<Unknown>", NULL);
|
||||
|
||||
if (is_owner)
|
||||
{
|
||||
/* get and put user names in the listbox */
|
||||
setpwent ();
|
||||
while ((chl_pass = getpwent ()))
|
||||
{
|
||||
while ((chl_pass = getpwent ()) != NULL)
|
||||
listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_pass->pw_name, NULL);
|
||||
}
|
||||
endpwent ();
|
||||
fe = listbox_search_text (chl_list, get_owner (sf_stat->st_uid));
|
||||
}
|
||||
@ -340,10 +355,8 @@ do_enter_key (Dlg_head * h, int f_pos)
|
||||
{
|
||||
/* get and put group names in the listbox */
|
||||
setgrent ();
|
||||
while ((chl_grp = getgrent ()))
|
||||
{
|
||||
while ((chl_grp = getgrent ()) != NULL)
|
||||
listbox_add_item (chl_list, LISTBOX_APPEND_SORTED, 0, chl_grp->gr_name, NULL);
|
||||
}
|
||||
endgrent ();
|
||||
fe = listbox_search_text (chl_list, get_group (sf_stat->st_gid));
|
||||
}
|
||||
@ -353,30 +366,30 @@ do_enter_key (Dlg_head * h, int f_pos)
|
||||
b_pos = chl_list->pos;
|
||||
add_widget (chl_dlg, chl_list);
|
||||
|
||||
run_dlg (chl_dlg);
|
||||
result = run_dlg (chl_dlg);
|
||||
|
||||
if (b_pos != chl_list->pos)
|
||||
{
|
||||
int ok = 0;
|
||||
gboolean ok = FALSE;
|
||||
char *text;
|
||||
|
||||
listbox_get_current (chl_list, &text, NULL);
|
||||
if (is_owner)
|
||||
{
|
||||
chl_pass = getpwnam (text);
|
||||
if (chl_pass)
|
||||
if (chl_pass != NULL)
|
||||
{
|
||||
ok = 1;
|
||||
ok = TRUE;
|
||||
sf_stat->st_uid = chl_pass->pw_uid;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chl_grp = getgrnam (text);
|
||||
if (chl_grp)
|
||||
if (chl_grp != NULL)
|
||||
{
|
||||
sf_stat->st_gid = chl_grp->gr_gid;
|
||||
ok = 1;
|
||||
ok = TRUE;
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
@ -388,17 +401,17 @@ do_enter_key (Dlg_head * h, int f_pos)
|
||||
if (ok)
|
||||
print_flags ();
|
||||
}
|
||||
if (chl_dlg->ret_value == KEY_LEFT)
|
||||
if (result == KEY_LEFT)
|
||||
{
|
||||
if (!is_owner)
|
||||
chl_end = 1;
|
||||
chl_end = TRUE;
|
||||
dlg_one_up (ch_dlg);
|
||||
f_pos--;
|
||||
}
|
||||
else if (chl_dlg->ret_value == KEY_RIGHT)
|
||||
else if (result == KEY_RIGHT)
|
||||
{
|
||||
if (is_owner)
|
||||
chl_end = 1;
|
||||
chl_end = TRUE;
|
||||
dlg_one_down (ch_dlg);
|
||||
f_pos++;
|
||||
}
|
||||
@ -413,58 +426,30 @@ do_enter_key (Dlg_head * h, int f_pos)
|
||||
static void
|
||||
chown_refresh (void)
|
||||
{
|
||||
common_dialog_repaint (ch_dlg);
|
||||
dlg_default_repaint (ch_dlg);
|
||||
|
||||
tty_setcolor (COLOR_NORMAL);
|
||||
|
||||
dlg_move (ch_dlg, BY - 1, 8);
|
||||
widget_move (ch_dlg, BY - 1, 8);
|
||||
tty_print_string (_("owner"));
|
||||
dlg_move (ch_dlg, BY - 1, 16);
|
||||
widget_move (ch_dlg, BY - 1, 16);
|
||||
tty_print_string (_("group"));
|
||||
dlg_move (ch_dlg, BY - 1, 24);
|
||||
widget_move (ch_dlg, BY - 1, 24);
|
||||
tty_print_string (_("other"));
|
||||
|
||||
dlg_move (ch_dlg, BY - 1, 35);
|
||||
widget_move (ch_dlg, BY - 1, 35);
|
||||
tty_print_string (_("owner"));
|
||||
dlg_move (ch_dlg, BY - 1, 53);
|
||||
widget_move (ch_dlg, BY - 1, 53);
|
||||
tty_print_string (_("group"));
|
||||
|
||||
dlg_move (ch_dlg, 3, 4);
|
||||
tty_print_string (_("On"));
|
||||
dlg_move (ch_dlg, BY + 1, 4);
|
||||
widget_move (ch_dlg, BY + 1, 3);
|
||||
tty_print_string (_("Flag"));
|
||||
dlg_move (ch_dlg, BY + 2, 4);
|
||||
tty_print_string (_("Mode"));
|
||||
|
||||
if (!single_set)
|
||||
{
|
||||
dlg_move (ch_dlg, 3, 54);
|
||||
tty_printf (_("%6d of %d"), files_on_begin - (current_panel->marked) + 1, files_on_begin);
|
||||
}
|
||||
|
||||
print_flags ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
chown_info_update (void)
|
||||
{
|
||||
/* display file info */
|
||||
tty_setcolor (COLOR_NORMAL);
|
||||
|
||||
/* name && mode */
|
||||
dlg_move (ch_dlg, 3, 8);
|
||||
tty_print_string (str_fit_to_term (fname, 45, J_LEFT_FIT));
|
||||
dlg_move (ch_dlg, BY + 2, 9);
|
||||
tty_printf ("%12o", get_mode ());
|
||||
|
||||
/* permissions */
|
||||
update_permissions ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
b_setpos (int f_pos)
|
||||
{
|
||||
@ -477,46 +462,57 @@ b_setpos (int f_pos)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
int i = 0, f_pos = BUTTONS - dlg_get_current_widget_id (h) - single_set - 1;
|
||||
WDialog *h = DIALOG (w);
|
||||
int i;
|
||||
int f_pos;
|
||||
unsigned int id;
|
||||
|
||||
id = dlg_get_current_widget_id (h);
|
||||
|
||||
for (i = 0; i < BUTTONS_PERM; i++)
|
||||
if (chown_advanced_but[i].id == id)
|
||||
break;
|
||||
|
||||
f_pos = i;
|
||||
i = 0;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_DRAW:
|
||||
case MSG_DRAW:
|
||||
chown_refresh ();
|
||||
chown_info_update ();
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_POST_KEY:
|
||||
case MSG_POST_KEY:
|
||||
if (f_pos < 3)
|
||||
b_setpos (f_pos);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_FOCUS:
|
||||
case MSG_FOCUS:
|
||||
if (f_pos < 3)
|
||||
{
|
||||
if ((flag_pos / 3) != f_pos)
|
||||
flag_pos = f_pos * 3;
|
||||
b_setpos (f_pos);
|
||||
}
|
||||
else if (f_pos < 5)
|
||||
else if (f_pos < BUTTONS_PERM)
|
||||
flag_pos = f_pos + 6;
|
||||
return MSG_HANDLED;
|
||||
|
||||
case DLG_KEY:
|
||||
case MSG_KEY:
|
||||
switch (parm)
|
||||
{
|
||||
|
||||
case XCTRL ('b'):
|
||||
case KEY_LEFT:
|
||||
if (f_pos < 5)
|
||||
if (f_pos < BUTTONS_PERM)
|
||||
return (dec_flag_pos (f_pos));
|
||||
break;
|
||||
|
||||
case XCTRL ('f'):
|
||||
case KEY_RIGHT:
|
||||
if (f_pos < 5)
|
||||
if (f_pos < BUTTONS_PERM)
|
||||
return (inc_flag_pos (f_pos));
|
||||
break;
|
||||
|
||||
@ -527,7 +523,7 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
|
||||
case '\n':
|
||||
case KEY_ENTER:
|
||||
if (f_pos <= 2 || f_pos >= 5)
|
||||
if (f_pos <= 2 || f_pos >= BUTTONS_PERM)
|
||||
break;
|
||||
do_enter_key (h, f_pos);
|
||||
return MSG_HANDLED;
|
||||
@ -544,8 +540,8 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
ch_flags[i * 3 + parm - 3] = (x_toggle & (1 << parm)) ? '-' : '+';
|
||||
x_toggle ^= (1 << parm);
|
||||
update_mode (h);
|
||||
dlg_broadcast_msg (h, WIDGET_DRAW, FALSE);
|
||||
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
|
||||
dlg_broadcast_msg (h, MSG_DRAW);
|
||||
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
|
||||
break;
|
||||
|
||||
case XCTRL ('x'):
|
||||
@ -560,8 +556,8 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
ch_flags[i * 3 + parm] = (x_toggle & (1 << parm)) ? '-' : '+';
|
||||
x_toggle ^= (1 << parm);
|
||||
update_mode (h);
|
||||
dlg_broadcast_msg (h, WIDGET_DRAW, FALSE);
|
||||
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
|
||||
dlg_broadcast_msg (h, MSG_DRAW);
|
||||
send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
@ -574,7 +570,7 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
if (f_pos > 2)
|
||||
break;
|
||||
flag_pos = f_pos * 3 + i; /* (strchr(ch_perm,parm)-ch_perm); */
|
||||
if (((WButton *) h->current->data)->text.start[(flag_pos % 3)] == '-')
|
||||
if (BUTTON (h->current->data)->text.start[(flag_pos % 3)] == '-')
|
||||
ch_flags[flag_pos] = '+';
|
||||
else
|
||||
ch_flags[flag_pos] = '-';
|
||||
@ -588,11 +584,12 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
i++;
|
||||
|
||||
case '1':
|
||||
if (f_pos > 2)
|
||||
break;
|
||||
flag_pos = i + f_pos * 3;
|
||||
ch_flags[flag_pos] = '=';
|
||||
update_mode (h);
|
||||
if (f_pos <= 2)
|
||||
{
|
||||
flag_pos = i + f_pos * 3;
|
||||
ch_flags[flag_pos] = '=';
|
||||
update_mode (h);
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
@ -609,8 +606,8 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
{
|
||||
ch_flags[flag_pos] = parm;
|
||||
update_mode (h);
|
||||
advanced_chown_callback (h, sender, DLG_KEY, KEY_RIGHT, NULL);
|
||||
if (flag_pos > 8 || !(flag_pos % 3))
|
||||
send_message (h, sender, MSG_KEY, KEY_RIGHT, NULL);
|
||||
if (flag_pos > 8 || (flag_pos % 3) == 0)
|
||||
dlg_one_down (h);
|
||||
}
|
||||
break;
|
||||
@ -618,7 +615,7 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -628,63 +625,107 @@ static void
|
||||
init_chown_advanced (void)
|
||||
{
|
||||
int i;
|
||||
enum
|
||||
{ dlg_h = 13, dlg_w = 74, n_elem = 4 };
|
||||
#ifdef ENABLE_NLS
|
||||
static int i18n_len = 0;
|
||||
int dlg_h = 12;
|
||||
int dlg_w = 74;
|
||||
int y;
|
||||
|
||||
if (i18n_len == 0)
|
||||
static gboolean i18n = FALSE;
|
||||
|
||||
if (!i18n)
|
||||
{
|
||||
int dx, cx;
|
||||
for (i = 0; i < n_elem; i++)
|
||||
for (i = BUTTONS_PERM; i < BUTTONS; i++)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
chown_advanced_but[i].text = _(chown_advanced_but[i].text);
|
||||
i18n_len += str_term_width1 (chown_advanced_but[i].text) + 3;
|
||||
if (DEFPUSH_BUTTON == chown_advanced_but[i].flags)
|
||||
i18n_len += 2; /* "<>" */
|
||||
}
|
||||
cx = dx = (dlg_w - i18n_len - 2) / (n_elem + 1);
|
||||
|
||||
/* Reversed order */
|
||||
for (i = n_elem - 1; i >= 0; i--)
|
||||
{
|
||||
chown_advanced_but[i].x = cx;
|
||||
cx += str_term_width1 (chown_advanced_but[i].text) + 3 + dx;
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
sf_stat = g_new (struct stat, 1);
|
||||
chown_advanced_but[i].len = str_term_width1 (chown_advanced_but[i].text) + 3;
|
||||
if (chown_advanced_but[i].flags == DEFPUSH_BUTTON)
|
||||
chown_advanced_but[i].len += 2; /* "<>" */
|
||||
}
|
||||
|
||||
i18n = TRUE;
|
||||
}
|
||||
|
||||
do_refresh ();
|
||||
end_chown = need_update = current_file = 0;
|
||||
single_set = (current_panel->marked < 2) ? 2 : 0;
|
||||
|
||||
sf_stat = g_new (struct stat, 1);
|
||||
current_file = 0;
|
||||
end_chown = need_update = FALSE;
|
||||
single_set = (current_panel->marked < 2);
|
||||
memset (ch_flags, '=', 11);
|
||||
flag_pos = 0;
|
||||
x_toggle = 070;
|
||||
|
||||
if (!single_set)
|
||||
dlg_h += 2;
|
||||
|
||||
ch_dlg =
|
||||
create_dlg (TRUE, 0, 0, dlg_h, dlg_w, dialog_colors, advanced_chown_callback, NULL,
|
||||
"[Advanced Chown]", _("Chown advanced command"), DLG_CENTER | DLG_REVERSE);
|
||||
"[Advanced Chown]", _("Chown advanced command"), DLG_CENTER);
|
||||
|
||||
#define XTRACT(i) BY+chown_advanced_but[i].y, BX+chown_advanced_but[i].x, \
|
||||
|
||||
l_filename = label_new (2, 3, "");
|
||||
add_widget (ch_dlg, l_filename);
|
||||
|
||||
add_widget (ch_dlg, hline_new (3, -1, -1));
|
||||
|
||||
#define XTRACT(i,y) y, BX+chown_advanced_but[i].x, \
|
||||
chown_advanced_but[i].ret_cmd, chown_advanced_but[i].flags, \
|
||||
(chown_advanced_but[i].text), 0
|
||||
(chown_advanced_but[i].text), NULL
|
||||
b_att[0] = button_new (XTRACT (0, BY));
|
||||
chown_advanced_but[0].id = add_widget (ch_dlg, b_att[0]);
|
||||
b_att[1] = button_new (XTRACT (1, BY));
|
||||
chown_advanced_but[1].id = add_widget (ch_dlg, b_att[1]);
|
||||
b_att[2] = button_new (XTRACT (2, BY));
|
||||
chown_advanced_but[2].id = add_widget (ch_dlg, b_att[2]);
|
||||
b_user = button_new (XTRACT (3, BY));
|
||||
chown_advanced_but[3].id = add_widget (ch_dlg, b_user);
|
||||
b_group = button_new (XTRACT (4, BY));
|
||||
chown_advanced_but[4].id = add_widget (ch_dlg, b_group);
|
||||
#undef XTRACT
|
||||
|
||||
for (i = 0; i < BUTTONS - 5; i++)
|
||||
if (!single_set || i < 2)
|
||||
add_widget (ch_dlg, button_new (XTRACT (i)));
|
||||
l_mode = label_new (BY + 2, 3, "");
|
||||
add_widget (ch_dlg, l_mode);
|
||||
|
||||
b_att[0] = button_new (XTRACT (8));
|
||||
b_att[1] = button_new (XTRACT (7));
|
||||
b_att[2] = button_new (XTRACT (6));
|
||||
b_user = button_new (XTRACT (5));
|
||||
b_group = button_new (XTRACT (4));
|
||||
y = BY + 3;
|
||||
if (!single_set)
|
||||
{
|
||||
i = BUTTONS_PERM;
|
||||
add_widget (ch_dlg, hline_new (y++, -1, -1));
|
||||
chown_advanced_but[i].id = add_widget (ch_dlg,
|
||||
button_new (y,
|
||||
WIDGET (ch_dlg)->cols / 2 -
|
||||
chown_advanced_but[i].len,
|
||||
chown_advanced_but[i].ret_cmd,
|
||||
chown_advanced_but[i].flags,
|
||||
chown_advanced_but[i].text, NULL));
|
||||
i++;
|
||||
chown_advanced_but[i].id = add_widget (ch_dlg,
|
||||
button_new (y, WIDGET (ch_dlg)->cols / 2 + 1,
|
||||
chown_advanced_but[i].ret_cmd,
|
||||
chown_advanced_but[i].flags,
|
||||
chown_advanced_but[i].text, NULL));
|
||||
y++;
|
||||
}
|
||||
|
||||
add_widget (ch_dlg, b_group);
|
||||
add_widget (ch_dlg, b_user);
|
||||
add_widget (ch_dlg, b_att[2]);
|
||||
add_widget (ch_dlg, b_att[1]);
|
||||
add_widget (ch_dlg, b_att[0]);
|
||||
i = BUTTONS_PERM + 2;
|
||||
add_widget (ch_dlg, hline_new (y++, -1, -1));
|
||||
chown_advanced_but[i].id = add_widget (ch_dlg,
|
||||
button_new (y,
|
||||
WIDGET (ch_dlg)->cols / 2 -
|
||||
chown_advanced_but[i].len,
|
||||
chown_advanced_but[i].ret_cmd,
|
||||
chown_advanced_but[i].flags,
|
||||
chown_advanced_but[i].text, NULL));
|
||||
i++;
|
||||
chown_advanced_but[i].id = add_widget (ch_dlg,
|
||||
button_new (y, WIDGET (ch_dlg)->cols / 2 + 1,
|
||||
chown_advanced_but[i].ret_cmd,
|
||||
chown_advanced_but[i].flags,
|
||||
chown_advanced_but[i].text, NULL));
|
||||
|
||||
dlg_select_widget (b_att[0]);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -732,7 +773,7 @@ apply_advanced_chowns (struct stat *sf)
|
||||
|
||||
lc_fname = current_panel->dir.list[current_file].fname;
|
||||
vpath = vfs_path_from_str (lc_fname);
|
||||
need_update = end_chown = 1;
|
||||
need_update = end_chown = TRUE;
|
||||
if (mc_chmod (vpath, get_mode ()) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
|
||||
lc_fname, unix_error_string (errno));
|
||||
@ -754,7 +795,9 @@ apply_advanced_chowns (struct stat *sf)
|
||||
vfs_path_free (vpath);
|
||||
break;
|
||||
}
|
||||
|
||||
ch_cmode = sf->st_mode;
|
||||
|
||||
if (mc_chmod (vpath, get_mode ()) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
|
||||
lc_fname, unix_error_string (errno));
|
||||
@ -767,7 +810,7 @@ apply_advanced_chowns (struct stat *sf)
|
||||
do_file_mark (current_panel, current_file, 0);
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
while (current_panel->marked);
|
||||
while (current_panel->marked != 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -777,11 +820,18 @@ apply_advanced_chowns (struct stat *sf)
|
||||
void
|
||||
chown_advanced_cmd (void)
|
||||
{
|
||||
files_on_begin = current_panel->marked;
|
||||
/* Number of files at startup */
|
||||
int files_on_begin;
|
||||
|
||||
files_on_begin = max (1, current_panel->marked);
|
||||
|
||||
do
|
||||
{ /* do while any files remaining */
|
||||
int file_idx;
|
||||
char buffer[BUF_MEDIUM];
|
||||
vfs_path_t *vpath;
|
||||
int result;
|
||||
|
||||
init_chown_advanced ();
|
||||
|
||||
if (current_panel->marked)
|
||||
@ -796,56 +846,53 @@ chown_advanced_cmd (void)
|
||||
vfs_path_free (vpath);
|
||||
break;
|
||||
}
|
||||
|
||||
ch_cmode = sf_stat->st_mode;
|
||||
|
||||
file_idx = files_on_begin == 1 ? 1 : (files_on_begin - current_panel->marked + 1);
|
||||
g_snprintf (buffer, sizeof (buffer), "%s (%d/%d)",
|
||||
str_fit_to_term (fname, WIDGET(ch_dlg)->cols - 20, J_LEFT_FIT),
|
||||
file_idx, files_on_begin);
|
||||
label_set_text (l_filename, buffer);
|
||||
chown_refresh ();
|
||||
|
||||
update_ownership ();
|
||||
|
||||
/* game can begin */
|
||||
run_dlg (ch_dlg);
|
||||
result = run_dlg (ch_dlg);
|
||||
|
||||
switch (ch_dlg->ret_value)
|
||||
switch (result)
|
||||
{
|
||||
case B_CANCEL:
|
||||
end_chown = 1;
|
||||
end_chown = TRUE;
|
||||
break;
|
||||
|
||||
case B_ENTER:
|
||||
{
|
||||
vfs_path_t *fname_vpath;
|
||||
|
||||
fname_vpath = vfs_path_from_str (fname);
|
||||
need_update = 1;
|
||||
if (mc_chmod (fname_vpath, get_mode ()) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
|
||||
fname, unix_error_string (errno));
|
||||
/* call mc_chown only, if mc_chmod didn't fail */
|
||||
else if (mc_chown
|
||||
(fname_vpath, (ch_flags[9] == '+') ? sf_stat->st_uid : (uid_t) - 1,
|
||||
(ch_flags[10] == '+') ? sf_stat->st_gid : (gid_t) - 1) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"), fname,
|
||||
unix_error_string (errno));
|
||||
vfs_path_free (fname_vpath);
|
||||
}
|
||||
need_update = TRUE;
|
||||
if (mc_chmod (vpath, get_mode ()) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
|
||||
fname, unix_error_string (errno));
|
||||
/* call mc_chown only, if mc_chmod didn't fail */
|
||||
else if (mc_chown
|
||||
(vpath, (ch_flags[9] == '+') ? sf_stat->st_uid : (uid_t) - 1,
|
||||
(ch_flags[10] == '+') ? sf_stat->st_gid : (gid_t) - 1) == -1)
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"), fname,
|
||||
unix_error_string (errno));
|
||||
break;
|
||||
|
||||
case B_SETALL:
|
||||
apply_advanced_chowns (sf_stat);
|
||||
break;
|
||||
|
||||
case B_SKIP:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (current_panel->marked && ch_dlg->ret_value != B_CANCEL)
|
||||
if (current_panel->marked && result != B_CANCEL)
|
||||
{
|
||||
do_file_mark (current_panel, current_file, 0);
|
||||
need_update = 1;
|
||||
need_update = TRUE;
|
||||
}
|
||||
destroy_dlg (ch_dlg);
|
||||
vfs_path_free (vpath);
|
||||
|
||||
}
|
||||
while (current_panel->marked && !end_chown);
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -18,7 +18,7 @@
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int display_box (WPanel * p, char **user, char **mini, int *use_msformat, int num);
|
||||
int panel_listing_box (WPanel * p, char **user, char **mini, int *use_msformat, int num);
|
||||
const panel_field_t *sort_box (panel_sort_info_t * info);
|
||||
void confirm_box (void);
|
||||
void display_bits_box (void);
|
||||
|
@ -80,18 +80,18 @@ static struct
|
||||
} check_perm[] =
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
{ S_IXOTH, N_("execute/search by others"), FALSE, NULL },
|
||||
{ S_IWOTH, N_("write by others"), FALSE, NULL },
|
||||
{ S_IROTH, N_("read by others"), FALSE, NULL },
|
||||
{ S_IXGRP, N_("execute/search by group"), FALSE, NULL },
|
||||
{ S_IWGRP, N_("write by group"), FALSE, NULL },
|
||||
{ S_IRGRP, N_("read by group"), FALSE, NULL },
|
||||
{ S_IXUSR, N_("execute/search by owner"), FALSE, NULL },
|
||||
{ S_IWUSR, N_("write by owner"), FALSE, NULL },
|
||||
{ S_IRUSR, N_("read by owner"), FALSE, NULL },
|
||||
{ S_ISVTX, N_("sticky bit"), FALSE, NULL },
|
||||
{ S_ISGID, N_("set group ID on execution"), FALSE, NULL },
|
||||
{ S_ISUID, N_("set user ID on execution"), FALSE, NULL }
|
||||
{ S_ISUID, N_("set &user ID on execution"), FALSE, NULL },
|
||||
{ S_ISGID, N_("set &group ID on execution"), FALSE, NULL },
|
||||
{ S_ISVTX, N_("stick&y bit"), FALSE, NULL },
|
||||
{ S_IRUSR, N_("&read by owner"), FALSE, NULL },
|
||||
{ S_IWUSR, N_("&write by owner"), FALSE, NULL },
|
||||
{ S_IXUSR, N_("e&xecute/search by owner"), FALSE, NULL },
|
||||
{ S_IRGRP, N_("rea&d by group"), FALSE, NULL },
|
||||
{ S_IWGRP, N_("write by grou&p"), FALSE, NULL },
|
||||
{ S_IXGRP, N_("execu&te/search by group"), FALSE, NULL },
|
||||
{ S_IROTH, N_("read &by others"), FALSE, NULL },
|
||||
{ S_IWOTH, N_("wr&ite by others"), FALSE, NULL },
|
||||
{ S_IXOTH, N_("execute/searc&h by others"), FALSE, NULL }
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
@ -118,17 +118,18 @@ static struct
|
||||
} chmod_but[] =
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
{ B_CANCEL, NORMAL_BUTTON, 3, 0, N_("&Cancel") },
|
||||
{ B_ENTER, DEFPUSH_BUTTON, 3, 0, N_("&Set") },
|
||||
{ B_CLRMRK, NORMAL_BUTTON, 5, 0, N_("C&lear marked") },
|
||||
{ B_SETMRK, NORMAL_BUTTON, 5, 0, N_("S&et marked") },
|
||||
{ B_ALL, NORMAL_BUTTON, 6, 0, N_("Set &all") },
|
||||
{ B_MARKED, NORMAL_BUTTON, 6, 0, N_("&Marked all") },
|
||||
{ B_ALL, NORMAL_BUTTON, 6, 0, N_("Set &all") }
|
||||
{ B_SETMRK, NORMAL_BUTTON, 5, 0, N_("S&et marked") },
|
||||
{ B_CLRMRK, NORMAL_BUTTON, 5, 0, N_("C&lear marked") },
|
||||
{ B_ENTER, DEFPUSH_BUTTON, 3, 0, N_("&Set") },
|
||||
{ B_CANCEL, NORMAL_BUTTON, 3, 0, N_("&Cancel") }
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
static const unsigned int chmod_but_num = G_N_ELEMENTS (chmod_but);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
@ -180,25 +181,25 @@ chmod_i18n (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
chmod_toggle_select (Dlg_head * h, int Id)
|
||||
chmod_toggle_select (WDialog * h, int Id)
|
||||
{
|
||||
tty_setcolor (COLOR_NORMAL);
|
||||
check_perm[Id].selected = !check_perm[Id].selected;
|
||||
|
||||
dlg_move (h, PY + check_perm_num - Id, PX + 1);
|
||||
widget_move (h, PY + Id + 1, PX + 1);
|
||||
tty_print_char (check_perm[Id].selected ? '*' : ' ');
|
||||
dlg_move (h, PY + check_perm_num - Id, PX + 3);
|
||||
widget_move (h, PY + Id + 1, PX + 3);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
chmod_refresh (Dlg_head * h)
|
||||
chmod_refresh (WDialog * h)
|
||||
{
|
||||
int y = file_gb->widget.y + 1;
|
||||
int x = file_gb->widget.x + 2;
|
||||
int y = WIDGET (file_gb)->y + 1;
|
||||
int x = WIDGET (file_gb)->x + 2;
|
||||
|
||||
common_dialog_repaint (h);
|
||||
dlg_default_repaint (h);
|
||||
|
||||
tty_setcolor (COLOR_NORMAL);
|
||||
|
||||
@ -215,40 +216,34 @@ chmod_refresh (Dlg_head * h)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
chmod_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
int id;
|
||||
|
||||
id = dlg_get_current_widget_id (h) - (chmod_but_num - (single_set ? 4 : 0)) - 1;
|
||||
WDialog *h = DIALOG (w);
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_ACTION:
|
||||
/* close dialog due to SIGINT (ctrl-g) */
|
||||
if (sender == NULL && parm == CK_Cancel)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
/* handle checkboxes */
|
||||
if (id >= 0)
|
||||
case MSG_ACTION:
|
||||
{
|
||||
gboolean sender_is_checkbox = FALSE;
|
||||
/* handle checkboxes */
|
||||
unsigned int i;
|
||||
|
||||
/* close dialog due to SIGINT (ctrl-g) */
|
||||
if (sender == NULL && parm == CK_Cancel)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
/* whether action was sent by checkbox? */
|
||||
for (i = 0; i < check_perm_num; i++)
|
||||
if (sender == (Widget *) check_perm[i].check)
|
||||
{
|
||||
sender_is_checkbox = TRUE;
|
||||
if (sender == WIDGET (check_perm[i].check))
|
||||
break;
|
||||
}
|
||||
|
||||
if (sender_is_checkbox)
|
||||
if (i < check_perm_num)
|
||||
{
|
||||
c_stat ^= check_perm[id].mode;
|
||||
char buffer[BUF_TINY];
|
||||
|
||||
c_stat ^= check_perm[i].mode;
|
||||
g_snprintf (buffer, sizeof (buffer), "%o", (unsigned int) c_stat);
|
||||
label_set_text (statl, buffer);
|
||||
chmod_toggle_select (h, id);
|
||||
chmod_toggle_select (h, i);
|
||||
mode_change = TRUE;
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
@ -256,32 +251,44 @@ chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da
|
||||
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case DLG_KEY:
|
||||
if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0)
|
||||
case MSG_KEY:
|
||||
if (parm == 'T' || parm == 't' || parm == KEY_IC)
|
||||
{
|
||||
chmod_toggle_select (h, id);
|
||||
if (parm == KEY_IC)
|
||||
dlg_one_down (h);
|
||||
return MSG_HANDLED;
|
||||
unsigned int i;
|
||||
unsigned long id;
|
||||
|
||||
id = dlg_get_current_widget_id (h);
|
||||
for (i = 0; i < check_perm_num; i++)
|
||||
if (id == WIDGET (check_perm[i].check)->id)
|
||||
break;
|
||||
|
||||
if (i < check_perm_num)
|
||||
{
|
||||
chmod_toggle_select (h, i);
|
||||
if (parm == KEY_IC)
|
||||
dlg_one_down (h);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
}
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case DLG_DRAW:
|
||||
case MSG_DRAW:
|
||||
chmod_refresh (h);
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Dlg_head *
|
||||
static WDialog *
|
||||
init_chmod (const char *fname, const struct stat *sf_stat)
|
||||
{
|
||||
Dlg_head *ch_dlg;
|
||||
WDialog *ch_dlg;
|
||||
int lines, cols;
|
||||
int y;
|
||||
int perm_gb_len;
|
||||
int file_gb_len;
|
||||
unsigned int i;
|
||||
@ -306,50 +313,66 @@ init_chmod (const char *fname, const struct stat *sf_stat)
|
||||
|
||||
ch_dlg =
|
||||
create_dlg (TRUE, 0, 0, lines, cols, dialog_colors,
|
||||
chmod_callback, NULL, "[Chmod]", _("Chmod command"), DLG_CENTER | DLG_REVERSE);
|
||||
chmod_callback, NULL, "[Chmod]", _("Chmod command"), DLG_CENTER);
|
||||
|
||||
for (i = 0; i < chmod_but_num; i++)
|
||||
{
|
||||
add_widget (ch_dlg,
|
||||
button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 + 1,
|
||||
chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));
|
||||
|
||||
i++;
|
||||
|
||||
add_widget (ch_dlg,
|
||||
button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 - chmod_but[i].len,
|
||||
chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));
|
||||
|
||||
if (single_set)
|
||||
break;
|
||||
}
|
||||
|
||||
file_gb = groupbox_new (PY, PX + perm_gb_len + 1, check_perm_num + 2, file_gb_len, _("File"));
|
||||
add_widget (ch_dlg, file_gb);
|
||||
add_widget (ch_dlg, groupbox_new (PY, PX, check_perm_num + 2, perm_gb_len, _("Permission")));
|
||||
|
||||
for (i = 0; i < check_perm_num; i++)
|
||||
{
|
||||
check_perm[i].check = check_new (PY + (check_perm_num - i), PX + 2,
|
||||
check_perm[i].check = check_new (PY + i + 1, PX + 2,
|
||||
(c_stat & check_perm[i].mode) != 0 ? 1 : 0,
|
||||
check_perm[i].text);
|
||||
add_widget (ch_dlg, check_perm[i].check);
|
||||
}
|
||||
|
||||
add_widget (ch_dlg, groupbox_new (PY, PX, check_perm_num + 2, perm_gb_len, _("Permission")));
|
||||
file_gb = groupbox_new (PY, PX + perm_gb_len + 1, check_perm_num + 2, file_gb_len, _("File"));
|
||||
add_widget (ch_dlg, file_gb);
|
||||
|
||||
/* Set the labels */
|
||||
/* Do this at end to have a widget id in a simple way */
|
||||
lines = PY + 2;
|
||||
y = PY + 2;
|
||||
cols = PX + perm_gb_len + 3;
|
||||
c_fname = str_trunc (fname, file_gb_len - 3);
|
||||
add_widget (ch_dlg, label_new (lines, cols, c_fname));
|
||||
c_fown = str_trunc (get_owner (sf_stat->st_uid), file_gb_len - 3);
|
||||
add_widget (ch_dlg, label_new (lines + 4, cols, c_fown));
|
||||
c_fgrp = str_trunc (get_group (sf_stat->st_gid), file_gb_len - 3);
|
||||
add_widget (ch_dlg, label_new (lines + 6, cols, c_fgrp));
|
||||
add_widget (ch_dlg, label_new (y, cols, c_fname));
|
||||
g_snprintf (buffer, sizeof (buffer), "%o", (unsigned int) c_stat);
|
||||
statl = label_new (lines + 2, cols, buffer);
|
||||
statl = label_new (y + 2, cols, buffer);
|
||||
add_widget (ch_dlg, statl);
|
||||
c_fown = str_trunc (get_owner (sf_stat->st_uid), file_gb_len - 3);
|
||||
add_widget (ch_dlg, label_new (y + 4, cols, c_fown));
|
||||
c_fgrp = str_trunc (get_group (sf_stat->st_gid), file_gb_len - 3);
|
||||
add_widget (ch_dlg, label_new (y + 6, cols, c_fgrp));
|
||||
|
||||
if (!single_set)
|
||||
{
|
||||
i = 0;
|
||||
add_widget (ch_dlg, hline_new (lines - chmod_but[i].y - 1, -1, -1));
|
||||
for (; i < chmod_but_num - 2; i++)
|
||||
{
|
||||
y = lines - chmod_but[i].y;
|
||||
add_widget (ch_dlg,
|
||||
button_new (y, WIDGET (ch_dlg)->cols / 2 - chmod_but[i].len,
|
||||
chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text,
|
||||
NULL));
|
||||
i++;
|
||||
add_widget (ch_dlg,
|
||||
button_new (y, WIDGET (ch_dlg)->cols / 2 + 1,
|
||||
chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text,
|
||||
NULL));
|
||||
}
|
||||
}
|
||||
|
||||
i = chmod_but_num - 2;
|
||||
y = lines - chmod_but[i].y;
|
||||
add_widget (ch_dlg, hline_new (y - 1, -1, -1));
|
||||
add_widget (ch_dlg,
|
||||
button_new (y, WIDGET (ch_dlg)->cols / 2 - chmod_but[i].len, chmod_but[i].ret_cmd,
|
||||
chmod_but[i].flags, chmod_but[i].text, NULL));
|
||||
i++;
|
||||
add_widget (ch_dlg,
|
||||
button_new (y, WIDGET (ch_dlg)->cols / 2 + 1, chmod_but[i].ret_cmd,
|
||||
chmod_but[i].flags, chmod_but[i].text, NULL));
|
||||
|
||||
/* select first checkbox */
|
||||
dlg_select_widget (check_perm[0].check);
|
||||
|
||||
return ch_dlg;
|
||||
}
|
||||
@ -435,7 +458,7 @@ chmod_cmd (void)
|
||||
do
|
||||
{ /* do while any files remaining */
|
||||
vfs_path_t *vpath;
|
||||
Dlg_head *ch_dlg;
|
||||
WDialog *ch_dlg;
|
||||
struct stat sf_stat;
|
||||
char *fname;
|
||||
int result;
|
||||
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
x
Ссылка в новой задаче
Block a user