* dlg.h: Use cb_ret_t and widget_msg_t in widget callbacks.

Massive adjustment for the above.
This commit is contained in:
Pavel Roskin 2003-09-10 22:48:54 +00:00
parent 683c686159
commit e355e25b56
13 changed files with 341 additions and 340 deletions

View File

@ -34,7 +34,7 @@ struct WMenu *edit_menubar;
int column_highlighting = 0;
static int edit_callback (WEdit *edit, int msg, int par);
static cb_ret_t edit_callback (WEdit *edit, widget_msg_t msg, int parm);
static int
edit_event (WEdit * edit, Gpm_Event * event, int *result)
@ -317,36 +317,49 @@ void edit_update_screen (WEdit * e)
edit_render_keypress (e);
}
static int edit_callback (WEdit *e, int msg, int par)
static cb_ret_t
edit_callback (WEdit *e, widget_msg_t msg, int parm)
{
switch (msg) {
case WIDGET_INIT:
e->force |= REDRAW_COMPLETELY;
edit_labels (e);
break;
return MSG_HANDLED;
case WIDGET_DRAW:
e->force |= REDRAW_COMPLETELY;
e->num_widget_lines = LINES - 2;
e->num_widget_columns = COLS;
/* fallthrough */
case WIDGET_FOCUS:
edit_update_screen (e);
return 1;
case WIDGET_KEY:{
return MSG_HANDLED;
case WIDGET_KEY:
{
int cmd, ch;
if (edit_drop_hotkey_menu (e, par)) /* first check alt-f, alt-e, alt-s, etc for drop menus */
return 1;
if (!edit_translate_key (e, par, &cmd, &ch))
return 0;
/* first check alt-f, alt-e, alt-s, etc for drop menus */
if (edit_drop_hotkey_menu (e, parm))
return MSG_HANDLED;
if (!edit_translate_key (e, parm, &cmd, &ch))
return MSG_NOT_HANDLED;
edit_execute_key_command (e, cmd, ch);
edit_update_screen (e);
}
return 1;
return MSG_HANDLED;
case WIDGET_CURSOR:
widget_move (&e->widget, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET, e->curs_col + e->start_col);
return 1;
widget_move (&e->widget, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET,
e->curs_col + e->start_col);
return MSG_HANDLED;
case WIDGET_DESTROY:
edit_clean (e);
return 1;
return MSG_HANDLED;
default:
return default_proc (msg, parm);
}
return default_proc (msg, par);
}

View File

@ -1,5 +1,8 @@
2003-09-10 Pavel Roskin <proski@gnu.org>
* dlg.h: Use cb_ret_t and widget_msg_t in widget callbacks.
Massive adjustment for the above.
* chmod.c (chmod_toggle_select): Get id as argument.
* dlg.h: Remove restroy callback. Widgets should use

View File

@ -249,8 +249,8 @@ enter (WInput *cmdline)
return MSG_HANDLED;
}
static int
command_callback (WInput *cmd, int msg, int par)
static cb_ret_t
command_callback (WInput *cmd, widget_msg_t msg, int parm)
{
switch (msg) {
case WIDGET_FOCUS:
@ -259,11 +259,14 @@ command_callback (WInput *cmd, int msg, int par)
case WIDGET_KEY:
/* Special case: we handle the enter key */
if (par == '\n') {
if (parm == '\n') {
return enter (cmd);
}
/* fall through */
default:
return input_callback (cmd, msg, parm);
}
return input_callback (cmd, msg, par);
}
WInput *

View File

@ -133,40 +133,22 @@ init_widget (Widget *w, int y, int x, int lines, int cols,
}
/* Default callback for widgets */
int default_proc (int Msg, int Par)
cb_ret_t
default_proc (widget_msg_t msg, int parm)
{
switch (Msg){
case WIDGET_HOTKEY: /* Didn't use the key */
return 0;
case WIDGET_INIT: /* We could tell if something went wrong */
return 1;
case WIDGET_KEY:
return 0; /* Didn't use the key */
case WIDGET_FOCUS: /* We accept FOCUSes */
return 1;
case WIDGET_UNFOCUS: /* We accept loose FOCUSes */
return 1;
switch (msg) {
case WIDGET_INIT:
case WIDGET_FOCUS:
case WIDGET_UNFOCUS:
case WIDGET_DRAW:
return 1;
case WIDGET_DESTROY:
return 1;
case WIDGET_CURSOR:
/* Move the cursor to the default widget position */
return 1;
case WIDGET_IDLE:
return 1;
return MSG_HANDLED;
default:
return MSG_NOT_HANDLED;
}
printf ("Internal error: unhandled message: %d\n", Msg);
return 1;
}
/* Clean the dialog area, draw the frame and the title */

View File

@ -93,18 +93,20 @@ typedef struct Dlg_head {
} Dlg_head;
typedef struct Widget Widget;
/* Widget callback */
typedef int (*callback_fn)(void *widget, int Msg, int Par);
typedef cb_ret_t (*callback_fn) (Widget *widget, widget_msg_t msg, int parm);
/* Every Widget must have this as it's first element */
typedef struct Widget {
struct Widget {
int x, y;
int cols, lines;
int options;
callback_fn callback; /* The callback function */
mouse_h mouse;
struct Dlg_head *parent;
} Widget;
};
/* The options for the widgets */
#define W_WANT_HOTKEY 2
@ -168,7 +170,7 @@ void init_widget (Widget *w, int y, int x, int lines, int cols,
cb_ret_t default_dlg_callback (Dlg_head *h, dlg_msg_t msg, int parm);
/* Default callback for widgets */
int default_proc (int Msg, int Par);
cb_ret_t default_proc (widget_msg_t msg, int parm);
/* Default paint routine for dialogs */
void common_dialog_repaint (struct Dlg_head *h);

View File

@ -582,10 +582,10 @@ static void prev_node_cmd (Dlg_head *h)
help_callback (h, DLG_DRAW, 0);
}
static int
md_callback (Widget *w, int msg, int par)
static cb_ret_t
md_callback (Widget *w, widget_msg_t msg, int parm)
{
return default_proc (msg, par);
return default_proc (msg, parm);
}
static Widget *

View File

@ -217,29 +217,30 @@ static void info_hook (void *data)
info_show_info (info);
}
static int
info_callback (WInfo *info, int msg, int par)
static cb_ret_t
info_callback (WInfo *info, widget_msg_t msg, int parm)
{
switch (msg) {
case WIDGET_INIT:
add_hook (&select_file_hook, info_hook, info);
info->ready = 0;
return 1;
return MSG_HANDLED;
case WIDGET_DRAW:
info_hook (info);
info_show_info (info);
return 1;
return MSG_HANDLED;
case WIDGET_FOCUS:
return 0;
return MSG_NOT_HANDLED;
case WIDGET_DESTROY:
delete_hook (&select_file_hook, info_hook);
return MSG_HANDLED;
default:
return default_proc (msg, par);
return default_proc (msg, parm);
}
}

View File

@ -336,52 +336,56 @@ static int menubar_handle_key (WMenu *menubar, int key)
return 0;
}
static int menubar_callback (WMenu *menubar, int msg, int par)
static cb_ret_t
menubar_callback (WMenu *menubar, widget_msg_t msg, int parm)
{
switch (msg){
switch (msg) {
/* We do not want the focus unless we have been activated */
case WIDGET_FOCUS:
if (menubar->active){
widget_want_cursor (menubar->widget, 1);
if (!menubar->active)
return MSG_NOT_HANDLED;
/* Trick to get all the mouse events */
menubar->widget.lines = LINES;
widget_want_cursor (menubar->widget, 1);
/* Trick to get all of the hotkeys */
widget_want_hotkey (menubar->widget, 1);
menubar->subsel = 0;
menubar_drop_compute (menubar);
menubar_draw (menubar);
return 1;
} else
return 0;
/* Trick to get all the mouse events */
menubar->widget.lines = LINES;
/* Trick to get all of the hotkeys */
widget_want_hotkey (menubar->widget, 1);
menubar->subsel = 0;
menubar_drop_compute (menubar);
menubar_draw (menubar);
return MSG_HANDLED;
/* We don't want the buttonbar to activate while using the menubar */
case WIDGET_HOTKEY:
case WIDGET_KEY:
if (menubar->active){
menubar_handle_key (menubar, par);
return 1;
if (menubar->active) {
menubar_handle_key (menubar, parm);
return MSG_HANDLED;
} else
return 0;
return MSG_NOT_HANDLED;
case WIDGET_CURSOR:
/* Put the cursor in a suitable place */
return 0;
return MSG_NOT_HANDLED;
case WIDGET_UNFOCUS:
if (menubar->active)
return 0;
return MSG_NOT_HANDLED;
else {
widget_want_cursor (menubar->widget, 0);
return 1;
return MSG_HANDLED;
}
case WIDGET_DRAW:
if (menubar_visible)
menubar_draw (menubar);
return MSG_HANDLED;
default:
return default_proc (msg, parm);
}
return default_proc (msg, par);
}
static int

View File

@ -102,7 +102,7 @@ int filetype_mode = 1;
/* The hook list for the select file function */
Hook *select_file_hook = 0;
static int panel_callback (WPanel *p, int Msg, int Par);
static cb_ret_t panel_callback (WPanel *p, widget_msg_t msg, int parm);
static int panel_event (Gpm_Event *event, WPanel *panel);
static void paint_frame (WPanel *panel);
static char *panel_format (WPanel *panel);
@ -1635,12 +1635,12 @@ move_selection (WPanel *panel, int lines)
select_item (panel);
}
static int
static cb_ret_t
move_left (WPanel *panel, int c_code)
{
if (panel->split) {
move_selection (panel, -llines (panel));
return 1;
return MSG_HANDLED;
} else
return maybe_cd (c_code, 0);
}
@ -1650,7 +1650,7 @@ move_right (WPanel *panel, int c_code)
{
if (panel->split) {
move_selection (panel, llines (panel));
return 1;
return MSG_HANDLED;
} else
return maybe_cd (c_code, 1);
}
@ -2117,7 +2117,7 @@ static const key_map panel_keymap [] = {
{ 0, 0 }
};
static inline int
static inline cb_ret_t
panel_key (WPanel *panel, int key)
{
int i;
@ -2133,12 +2133,12 @@ panel_key (WPanel *panel, int key)
if (panel->searching != old_searching)
display_mini_info (panel);
return 1;
return MSG_HANDLED;
}
}
if (torben_fj_mode && key == ALT ('h')) {
goto_middle_file (panel);
return 1;
return MSG_HANDLED;
}
/* We do not want to take a key press if nothing can be done with it */
@ -2152,39 +2152,39 @@ panel_key (WPanel *panel, int key)
if (is_abort_char (key)) {
panel->searching = 0;
display_mini_info (panel);
return 1;
return MSG_HANDLED;
}
/* Do not eat characters not meant for the panel below ' ' (e.g. C-l). */
if ((key >= ' ' && key <= 255) || key == KEY_BACKSPACE) {
if (panel->searching) {
do_search (panel, key);
return 1;
return MSG_HANDLED;
}
if (!command_prompt) {
start_search (panel);
do_search (panel, key);
return 1;
return MSG_HANDLED;
}
}
return 0;
return MSG_NOT_HANDLED;
}
void user_file_menu_cmd (void) {
user_menu_cmd (NULL);
}
static int
panel_callback (WPanel *panel, int msg, int par)
static cb_ret_t
panel_callback (WPanel *panel, widget_msg_t msg, int parm)
{
Dlg_head *h = panel->widget.parent;
switch (msg){
switch (msg) {
case WIDGET_DRAW:
paint_panel (panel);
return 1;
return MSG_HANDLED;
case WIDGET_FOCUS:
current_panel = panel;
@ -2208,10 +2208,7 @@ panel_callback (WPanel *panel, int msg, int par)
define_label (h, 7, _("Mkdir"), mkdir_cmd);
define_label (h, 8, _("Delete"), delete_cmd);
redraw_labels (h);
/* Chain behavior */
default_proc (WIDGET_FOCUS, par);
return 1;
return MSG_HANDLED;
case WIDGET_UNFOCUS:
/* Janne: look at this for the multiple panel options */
@ -2222,17 +2219,17 @@ panel_callback (WPanel *panel, int msg, int par)
panel->active = 0;
show_dir (panel);
unselect_item (panel);
return 1;
return MSG_HANDLED;
case WIDGET_KEY:
return panel_key (panel, par);
return panel_key (panel, parm);
case WIDGET_DESTROY:
panel_destroy (panel);
return 1;
return MSG_HANDLED;
default:
return default_proc (msg, par);
return default_proc (msg, parm);
}
}

View File

@ -71,7 +71,6 @@ struct WTree {
/* Forwards */
static void save_tree (WTree *tree);
static void tree_rescan_cmd (WTree *tree);
static int tree_callback (WTree *tree, int msg, int par);
static tree_entry *back_ptr (tree_entry *ptr, int *count)
{
@ -943,7 +942,7 @@ static const key_map tree_keymap [] = {
{ 0, 0 }
};
static inline int
static inline cb_ret_t
tree_key (WTree *tree, int key)
{
int i;
@ -954,7 +953,7 @@ tree_key (WTree *tree, int key)
tree->searching = 0;
(*tree_keymap [i].fn)(tree);
show_tree (tree);
return 1;
return MSG_HANDLED;
}
}
@ -970,10 +969,11 @@ tree_key (WTree *tree, int key)
if (tree->is_panel) {
tree->searching = 0;
show_tree (tree);
return 1; /* eat abort char */
return MSG_HANDLED; /* eat abort char */
}
return 0; /* modal tree dialog: let upper layer see the
abort character and close the dialog */
/* modal tree dialog: let upper layer see the
abort character and close the dialog */
return MSG_NOT_HANDLED;
}
/* Do not eat characters not meant for the tree below ' ' (e.g. C-l). */
@ -981,18 +981,18 @@ tree_key (WTree *tree, int key)
if (tree->searching){
tree_do_search (tree, key);
show_tree (tree);
return 1;
return MSG_HANDLED;
}
if (!command_prompt) {
tree_start_search (tree);
tree_do_search (tree, key);
return 1;
return MSG_HANDLED;
}
return tree->is_panel;
}
return 0;
return MSG_NOT_HANDLED;
}
static void
@ -1011,8 +1011,8 @@ tree_frame (Dlg_head *h, WTree *tree)
}
static int
tree_callback (WTree *tree, int msg, int par)
static cb_ret_t
tree_callback (WTree *tree, widget_msg_t msg, int parm)
{
Dlg_head *h = tree->widget.parent;
@ -1020,10 +1020,10 @@ tree_callback (WTree *tree, int msg, int par)
case WIDGET_DRAW:
tree_frame (h, tree);
show_tree (tree);
return 1;
return MSG_HANDLED;
case WIDGET_KEY:
return tree_key (tree, par);
return tree_key (tree, parm);
case WIDGET_FOCUS:
tree->active = 1;
@ -1052,7 +1052,7 @@ tree_callback (WTree *tree, int msg, int par)
/* FIXME: Should find a better way of only displaying the
currently selected item */
show_tree (tree);
return 1;
return MSG_HANDLED;
/* FIXME: Should find a better way of changing the color of the
selected item */
@ -1060,14 +1060,14 @@ tree_callback (WTree *tree, int msg, int par)
case WIDGET_UNFOCUS:
tree->active = 0;
show_tree (tree);
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
tree_destroy (tree);
return 1;
return MSG_HANDLED;
default:
return default_proc (msg, par);
return default_proc (msg, parm);
}
}

View File

@ -197,8 +197,8 @@ int altered_nroff_flag = 0;
static const char hex_char[] = "0123456789ABCDEF";
/* Our callback */
static int view_callback (WView *view, int msg, int par);
/* Our widget callback */
static cb_ret_t view_callback (WView *view, widget_msg_t msg, int parm);
static int regexp_view_search (WView * view, char *pattern, char *string,
int match_type);
@ -2313,7 +2313,7 @@ continue_search (WView *view)
}
/* Both views */
static int
static cb_ret_t
view_handle_key (WView *view, int c)
{
int prev_monitor = view->monitor;
@ -2327,26 +2327,26 @@ view_handle_key (WView *view, int c)
case 0x09: /* Tab key */
view->view_side = 1 - view->view_side;
view->dirty++;
return 1;
return MSG_HANDLED;
case XCTRL ('a'): /* Beginning of line */
view->edit_cursor -= view->edit_cursor % view->bytes_per_line;
view->dirty++;
return 1;
return MSG_HANDLED;
case XCTRL ('b'): /* Character back */
move_left (view);
return 1;
return MSG_HANDLED;
case XCTRL ('e'): /* End of line */
view->edit_cursor -= view->edit_cursor % view->bytes_per_line;
view->edit_cursor += view->bytes_per_line - 1;
view->dirty++;
return 1;
return MSG_HANDLED;
case XCTRL ('f'): /* Character forward */
move_right (view);
return 1;
return MSG_HANDLED;
}
/* Trap 0-9,A-F,a-f for left side data entry (hex editing) */
@ -2355,7 +2355,7 @@ view_handle_key (WView *view, int c)
(c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
put_editkey (view, c);
return 1;
return MSG_HANDLED;
}
}
@ -2364,36 +2364,36 @@ view_handle_key (WView *view, int c)
if (view->view_side == view_side_right) {
if (c < 256 && (is_printable (c) || (c == '\n'))) {
put_editkey (view, c);
return 1;
return MSG_HANDLED;
}
}
}
if (check_left_right_keys (view, c))
return 1;
return MSG_HANDLED;
if (check_movement_keys
(c, 1, vheight, view, (movefn) view_move_backward,
(movefn) view_move_forward, (movefn) move_to_top,
(movefn) move_to_bottom)) {
return 1;
return MSG_HANDLED;
}
switch (c) {
case '?':
regexp_search (view, -1);
return 1;
return MSG_HANDLED;
case '/':
regexp_search (view, 1);
return 1;
return MSG_HANDLED;
/* Continue search */
case XCTRL ('s'):
case 'n':
case KEY_F (17):
continue_search (view);
return 1;
return MSG_HANDLED;
case XCTRL ('r'):
if (view->last_search) {
@ -2401,7 +2401,7 @@ view_handle_key (WView *view, int c)
} else {
normal_search (view, -1);
}
return 1;
return MSG_HANDLED;
/* toggle ruler */
case ALT ('r'):
@ -2417,73 +2417,73 @@ view_handle_key (WView *view, int c)
break;
}
view->dirty++;
return 1;
return MSG_HANDLED;
case 'h':
move_left (view);
return 1;
return MSG_HANDLED;
case 'j':
case '\n':
case 'e':
view_move_forward (view, 1);
return 1;
return MSG_HANDLED;
case 'd':
view_move_forward (view, vheight / 2);
return 1;
return MSG_HANDLED;
case 'u':
view_move_backward (view, vheight / 2);
return 1;
return MSG_HANDLED;
case 'k':
case 'y':
view_move_backward (view, 1);
return 1;
return MSG_HANDLED;
case 'l':
move_right (view);
return 1;
return MSG_HANDLED;
case ' ':
case 'f':
view_move_forward (view, vheight - 1);
return 1;
return MSG_HANDLED;
case XCTRL ('o'):
view_other_cmd ();
return 1;
return MSG_HANDLED;
/* Unlike Ctrl-O, run a new shell if the subshell is not running. */
case '!':
exec_shell ();
return 1;
return MSG_HANDLED;
case 'F':
set_monitor (view, on);
return 1;
return MSG_HANDLED;
case 'b':
view_move_backward (view, vheight - 1);
return 1;
return MSG_HANDLED;
case KEY_IC:
view_move_backward (view, 2);
return 1;
return MSG_HANDLED;
case KEY_DC:
view_move_forward (view, 2);
return 1;
return MSG_HANDLED;
case 'm':
view->marks[view->marker] = view->start_display;
return 1;
return MSG_HANDLED;
case 'r':
view->start_display = view->marks[view->marker];
view->dirty++;
return 1;
return MSG_HANDLED;
/* Use to indicate parent that we want to see the next/previous file */
/* Only works on full screen mode */
@ -2498,14 +2498,14 @@ view_handle_key (WView *view, int c)
case ESC_CHAR:
if (view_ok_to_quit (view))
view->view_quit = 1;
return 1;
return MSG_HANDLED;
#ifdef HAVE_CHARSET
case XCTRL ('t'):
do_select_codepage ();
view->dirty++;
view_update (view, TRUE);
return 1;
return MSG_HANDLED;
#endif /* HAVE_CHARSET */
}
@ -2516,7 +2516,7 @@ view_handle_key (WView *view, int c)
set_monitor (view, prev_monitor);
/* Key not used */
return 0;
return MSG_NOT_HANDLED;
}
/* Both views */
@ -2680,10 +2680,10 @@ view_hook (void *v)
view_status (view, TRUE);
}
static int
view_callback (WView *view, int msg, int par)
static cb_ret_t
view_callback (WView *view, widget_msg_t msg, int parm)
{
int i;
cb_ret_t i;
Dlg_head *h = view->widget.parent;
switch (msg) {
@ -2693,20 +2693,20 @@ view_callback (WView *view, int msg, int par)
add_hook (&select_file_hook, view_hook, view);
else
view_labels (view);
return 1;
return MSG_HANDLED;
case WIDGET_DRAW:
display (view);
view_status (view, TRUE);
return 1;
return MSG_HANDLED;
case WIDGET_CURSOR:
if (view->hex_mode)
view_place_cursor (view);
return 1;
return MSG_HANDLED;
case WIDGET_KEY:
i = view_handle_key ((WView *) view, par);
i = view_handle_key ((WView *) view, parm);
if (view->view_quit)
dlg_stop (h);
else {
@ -2721,20 +2721,20 @@ view_callback (WView *view, int msg, int par)
display (view);
view_status (view, TRUE);
sleep (1);
return 1;
return MSG_HANDLED;
case WIDGET_FOCUS:
view_labels (view);
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
view_done (view);
if (view->have_frame)
delete_hook (&select_file_hook, view_hook);
return 1;
return MSG_HANDLED;
default:
return default_proc (msg, par);
return default_proc (msg, parm);
}
}

View File

@ -47,15 +47,15 @@ static int button_event (Gpm_Event *event, WButton *b);
int quote = 0;
static int
button_callback (WButton *b, int Msg, int Par)
static cb_ret_t
button_callback (WButton *b, widget_msg_t msg, int parm)
{
char buf[BUF_SMALL];
int stop = 0;
int off = 0;
Dlg_head *h = b->widget.parent;
switch (Msg) {
switch (msg) {
case WIDGET_HOTKEY:
/*
* Don't let the default button steal Enter from the current
@ -63,26 +63,26 @@ button_callback (WButton *b, int Msg, int Par)
* when hotkeys are sent to all widgets before the key is
* handled by the current widget.
*/
if (Par == '\n' && h->current->widget == &b->widget) {
if (parm == '\n' && h->current->widget == &b->widget) {
button_callback (b, WIDGET_KEY, ' ');
return 1;
return MSG_HANDLED;
}
if (Par == '\n' && b->flags == DEFPUSH_BUTTON) {
if (parm == '\n' && b->flags == DEFPUSH_BUTTON) {
button_callback (b, WIDGET_KEY, ' ');
return 1;
return MSG_HANDLED;
}
if (b->hotkey == Par || toupper (b->hotkey) == Par) {
if (b->hotkey == parm || toupper (b->hotkey) == parm) {
button_callback (b, WIDGET_KEY, ' ');
return 1;
return MSG_HANDLED;
}
return 0;
return MSG_NOT_HANDLED;
case WIDGET_KEY:
if (Par != ' ' && Par != '\n')
return 0;
if (parm != ' ' && parm != '\n')
return MSG_NOT_HANDLED;
if (b->callback)
stop = (*b->callback) (b->action);
@ -90,7 +90,7 @@ button_callback (WButton *b, int Msg, int Par)
h->ret_value = b->action;
dlg_stop (h);
}
return 1;
return MSG_HANDLED;
case WIDGET_CURSOR:
switch (b->flags) {
@ -109,14 +109,14 @@ button_callback (WButton *b, int Msg, int Par)
break;
}
widget_move (&b->widget, 0, b->hotpos + off);
return 1;
return MSG_HANDLED;
case WIDGET_UNFOCUS:
case WIDGET_FOCUS:
case WIDGET_DRAW:
if (Msg == WIDGET_UNFOCUS)
if (msg == WIDGET_UNFOCUS)
b->selected = 0;
else if (Msg == WIDGET_FOCUS)
else if (msg == WIDGET_FOCUS)
b->selected = 1;
switch (b->flags) {
@ -149,14 +149,14 @@ button_callback (WButton *b, int Msg, int Par)
widget_move (&b->widget, 0, b->hotpos + off);
addch ((unsigned char) b->text[b->hotpos]);
}
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
g_free (b->text);
return 1;
return MSG_HANDLED;
default:
return default_proc (Msg, Par);
return default_proc (msg, parm);
}
}
@ -249,93 +249,92 @@ button_set_text (WButton *b, char *text)
/* Radio button widget */
static int radio_event (Gpm_Event *event, WRadio *r);
static int
radio_callback (WRadio *r, int Msg, int Par)
static cb_ret_t
radio_callback (WRadio *r, int msg, int parm)
{
int i;
Dlg_head *h = r->widget.parent;
switch (Msg) {
case WIDGET_INIT:
return 1;
switch (msg) {
case WIDGET_HOTKEY:
{
int i, lp = tolower(Par);
int i, lp = tolower (parm);
char *cp;
for (i = 0; i < r->count; i++){
cp = strchr (r->texts [i], '&');
if (cp != NULL && cp[1] != '\0'){
int c = tolower (cp [1]);
for (i = 0; i < r->count; i++) {
cp = strchr (r->texts[i], '&');
if (cp != NULL && cp[1] != '\0') {
int c = tolower (cp[1]);
if (c != lp)
continue;
r->pos = i;
radio_callback (r, WIDGET_KEY, ' '); /* Take action */
return 1;
/* Take action */
radio_callback (r, WIDGET_KEY, ' ');
return MSG_HANDLED;
}
}
}
return 0;
return MSG_NOT_HANDLED;
case WIDGET_KEY:
switch (Par){
switch (parm) {
case ' ':
r->sel = r->pos;
(*h->callback) (h, DLG_ACTION, 0);
(*h->callback) (h, DLG_ACTION, 0);
radio_callback (r, WIDGET_FOCUS, ' ');
return 1;
return MSG_HANDLED;
case KEY_UP:
case KEY_LEFT:
if (r->pos > 0){
if (r->pos > 0) {
r->pos--;
return 1;
return MSG_HANDLED;
}
return 0;
return MSG_NOT_HANDLED;
case KEY_DOWN:
case KEY_RIGHT:
if (r->count - 1 > r->pos) {
r->pos++;
return 1;
return MSG_HANDLED;
}
}
return 0;
return MSG_NOT_HANDLED;
case WIDGET_CURSOR:
(*h->callback) (h, DLG_ACTION, 0);
radio_callback (r, WIDGET_FOCUS, ' ');
widget_move (&r->widget, r->pos, 1);
break;
return MSG_HANDLED;
case WIDGET_UNFOCUS:
case WIDGET_FOCUS:
case WIDGET_DRAW:
for (i = 0; i < r->count; i++){
register unsigned char* cp;
attrset ((i==r->pos && Msg==WIDGET_FOCUS) ? FOCUSC :NORMALC);
for (i = 0; i < r->count; i++) {
register unsigned char *cp;
attrset ((i == r->pos
&& msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
widget_move (&r->widget, i, 0);
printw("(%c) ", (r->sel == i) ? '*' : ' ');
for (cp = r->texts[i]; *cp; cp++)
{
if (*cp == '&')
{
attrset ((i==r->pos && Msg==WIDGET_FOCUS)
? HOT_FOCUSC : HOT_NORMALC);
addch(*++cp);
attrset ((i==r->pos && Msg==WIDGET_FOCUS) ? FOCUSC : NORMALC);
}
else
addch(*cp);
}
printw ("(%c) ", (r->sel == i) ? '*' : ' ');
for (cp = r->texts[i]; *cp; cp++) {
if (*cp == '&') {
attrset ((i == r->pos && msg == WIDGET_FOCUS)
? HOT_FOCUSC : HOT_NORMALC);
addch (*++cp);
attrset ((i == r->pos
&& msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
} else
addch (*cp);
}
}
return 1;
break;
return MSG_HANDLED;
default:
return default_proc (msg, parm);
}
return default_proc (Msg, Par);
}
static int
@ -388,57 +387,54 @@ radio_new (int y, int x, int count, char **texts, int use_hotkey)
static int check_event (Gpm_Event *event, WCheck *b);
static int
check_callback (WCheck *c, int Msg, int Par)
static cb_ret_t
check_callback (WCheck *c, widget_msg_t msg, int parm)
{
Dlg_head *h = c->widget.parent;
switch (Msg) {
case WIDGET_INIT:
return 1;
switch (msg) {
case WIDGET_HOTKEY:
if (c->hotkey == Par
if (c->hotkey == parm
|| (c->hotkey >= 'a' && c->hotkey <= 'z'
&& c->hotkey - 32 == Par)) {
&& c->hotkey - 32 == parm)) {
check_callback (c, WIDGET_KEY, ' '); /* make action */
return 1;
return MSG_HANDLED;
}
return 0;
return MSG_NOT_HANDLED;
case WIDGET_KEY:
if (Par != ' ')
return 0;
if (parm != ' ')
return MSG_NOT_HANDLED;
c->state ^= C_BOOL;
c->state ^= C_CHANGE;
(*h->callback) (h, DLG_ACTION, 0);
check_callback (c, WIDGET_FOCUS, ' ');
return 1;
return MSG_HANDLED;
case WIDGET_CURSOR:
widget_move (&c->widget, 0, 1);
return 1;
return MSG_HANDLED;
case WIDGET_FOCUS:
case WIDGET_UNFOCUS:
case WIDGET_DRAW:
attrset ((Msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
attrset ((msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
widget_move (&c->widget, 0, 0);
printw ("[%c] %s", (c->state & C_BOOL) ? 'x' : ' ', c->text);
if (c->hotpos >= 0) {
attrset ((Msg == WIDGET_FOCUS) ? HOT_FOCUSC : HOT_NORMALC);
attrset ((msg == WIDGET_FOCUS) ? HOT_FOCUSC : HOT_NORMALC);
widget_move (&c->widget, 0, +c->hotpos + 4);
addch ((unsigned char) c->text[c->hotpos]);
}
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
g_free (c->text);
return 1;
return MSG_HANDLED;
default:
return default_proc (Msg, Par);
return default_proc (msg, parm);
}
}
@ -495,17 +491,17 @@ check_new (int y, int x, int state, char *text)
/* Label widget */
static int
label_callback (WLabel *l, int Msg, int Par)
label_callback (WLabel *l, int msg, int parm)
{
Dlg_head *h = l->widget.parent;
switch (Msg) {
switch (msg) {
case WIDGET_INIT:
return 1;
return MSG_HANDLED;
/* We don't want to get the focus */
case WIDGET_FOCUS:
return 0;
return MSG_NOT_HANDLED;
case WIDGET_DRAW:
{
@ -513,7 +509,7 @@ label_callback (WLabel *l, int Msg, int Par)
int y = 0;
if (!l->text)
return 1;
return MSG_HANDLED;
if (l->transparent)
attrset (DEFAULT_COLOR);
@ -538,15 +534,15 @@ label_callback (WLabel *l, int Msg, int Par)
p = q + 1;
y++;
}
return 1;
return MSG_HANDLED;
}
case WIDGET_DESTROY:
g_free (l->text);
return 1;
return MSG_HANDLED;
default:
return default_proc (Msg, Par);
return default_proc (msg, parm);
}
}
@ -606,18 +602,18 @@ label_new (int y, int x, const char *text)
#define gauge_len 47
static int
gauge_callback (WGauge *g, int Msg, int Par)
gauge_callback (WGauge *g, int msg, int parm)
{
Dlg_head *h = g->widget.parent;
if (Msg == WIDGET_INIT)
return 1;
if (msg == WIDGET_INIT)
return MSG_HANDLED;
/* We don't want to get the focus */
if (Msg == WIDGET_FOCUS)
return 0;
if (msg == WIDGET_FOCUS)
return MSG_NOT_HANDLED;
if (Msg == WIDGET_DRAW){
if (msg == WIDGET_DRAW){
widget_move (&g->widget, 0, 0);
attrset (NORMALC);
if (!g->shown)
@ -644,9 +640,9 @@ gauge_callback (WGauge *g, int Msg, int Par)
attrset (NORMALC);
printw ("%*s] %3d%%", gauge_len - 7 - columns, "", percentage);
}
return 1;
return MSG_HANDLED;
}
return default_proc (Msg, Par);
return default_proc (msg, parm);
}
void
@ -819,11 +815,11 @@ history_get (char *input_name)
hist = NULL;
if (!num_history_items_recorded) /* this is how to disable */
return 0;
return NULL;
if (!input_name)
return 0;
return NULL;
if (!*input_name)
return 0;
return NULL;
profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
for (i = 0;; i++) {
char key_name[BUF_TINY];
@ -916,7 +912,7 @@ i18n_htitle (void)
return history_title;
}
static inline int listbox_fwd (WListbox *l);
static inline cb_ret_t listbox_fwd (WListbox *l);
char *
show_hist (GList *history, int widget_x, int widget_y)
@ -930,7 +926,7 @@ show_hist (GList *history, int widget_x, int widget_y)
z = history;
if (!z)
return 0;
return NULL;
z = g_list_first (history);
hi = z;
@ -1112,13 +1108,13 @@ new_input (WInput *in)
update_input (in, 0);
}
static int
static cb_ret_t
insert_char (WInput *in, int c_code)
{
int i;
if (c_code == -1)
return 0;
return MSG_NOT_HANDLED;
in->need_push = 1;
if (strlen (in->buffer)+1 == in->current_max_len){
@ -1140,7 +1136,7 @@ insert_char (WInput *in, int c_code)
in->buffer [in->point] = c_code;
in->point++;
}
return 1;
return MSG_HANDLED;
}
static void
@ -1473,7 +1469,7 @@ port_region_marked_for_delete (WInput *in)
in->first = 0;
}
int
cb_ret_t
handle_char (WInput *in, int c_code)
{
int i;
@ -1500,7 +1496,7 @@ handle_char (WInput *in, int c_code)
}
if (!input_map [i].fn){
if (c_code > 255 || !is_printable (c_code))
return 0;
return MSG_NOT_HANDLED;
if (in->first){
port_region_marked_for_delete (in);
}
@ -1536,58 +1532,58 @@ input_set_point (WInput *in, int pos)
update_input (in, 1);
}
int
input_callback (WInput *in, int Msg, int Par)
cb_ret_t
input_callback (WInput *in, widget_msg_t msg, int parm)
{
int v;
Dlg_head *h = in->widget.parent;
switch (Msg) {
switch (msg) {
case WIDGET_INIT:
return 1;
return MSG_HANDLED;
case WIDGET_KEY:
if (Par == XCTRL ('q')) {
if (parm == XCTRL ('q')) {
quote = 1;
v = handle_char (in, mi_getch ());
quote = 0;
return v;
}
if (Par == KEY_UP || Par == KEY_DOWN || Par == ESC_CHAR
|| Par == KEY_F (10) || Par == XCTRL ('g'))
return 0; /* We don't handle up/down */
if (parm == KEY_UP || parm == KEY_DOWN || parm == ESC_CHAR
|| parm == KEY_F (10) || parm == XCTRL ('g'))
return MSG_NOT_HANDLED; /* We don't handle up/down */
if (Par == '\n') {
if (parm == '\n') {
dlg_one_down (h);
return 1;
return MSG_HANDLED;
}
/* When pasting multiline text, insert literal Enter */
if ((Par & ~KEY_M_MASK) == '\n') {
if ((parm & ~KEY_M_MASK) == '\n') {
quote = 1;
v = handle_char (in, '\n');
quote = 0;
return v;
}
return handle_char (in, Par);
return handle_char (in, parm);
case WIDGET_FOCUS:
case WIDGET_UNFOCUS:
case WIDGET_DRAW:
update_input (in, 0);
return default_proc (Msg, Par);
return default_proc (msg, parm);
case WIDGET_CURSOR:
widget_move (&in->widget, 0, in->point - in->first_shown);
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
input_destroy (in);
return 1;
return MSG_HANDLED;
default:
return default_proc (Msg, Par);
return default_proc (msg, parm);
}
}
@ -1770,21 +1766,21 @@ listbox_check_hotkey (WListbox *l, int key)
{
int i;
WLEntry *e;
i = 0;
e = l->list;
if (!e)
return 0;
while (1){
return NULL;
while (1) {
/* If we didn't find anything, return */
if (i && e == l->list)
return 0;
return NULL;
if (e->hotkey == key)
return e;
i++;
e = e->next;
}
@ -1909,35 +1905,35 @@ listbox_select_pos (WListbox *l, WLEntry *base, int pos)
return base;
}
static inline int
static inline cb_ret_t
listbox_back (WListbox *l)
{
if (l->pos){
listbox_select_entry (l, listbox_select_pos (l, l->list, l->pos-1));
return 1;
return MSG_HANDLED;
}
return 0;
return MSG_NOT_HANDLED;
}
static inline int
static inline cb_ret_t
listbox_fwd (WListbox *l)
{
if (l->current != l->list->prev){
listbox_select_entry (l, listbox_select_pos (l, l->list, l->pos+1));
return 1;
return MSG_HANDLED;
}
return 0;
return MSG_NOT_HANDLED;
}
/* Returns 1 if we want a redraw */
static int
/* Return MSG_HANDLED if we want a redraw */
static cb_ret_t
listbox_key (WListbox *l, int key)
{
int i;
int j = 0;
if (!l->list)
return 0;
return MSG_NOT_HANDLED;
switch (key){
case KEY_HOME:
@ -1945,7 +1941,7 @@ listbox_key (WListbox *l, int key)
case ALT ('<'):
l->current = l->top = l->list;
l->pos = 0;
return 1;
return MSG_HANDLED;
case KEY_END:
case KEY_C1:
@ -1954,17 +1950,17 @@ listbox_key (WListbox *l, int key)
for (i = min (l->height - 1, l->count - 1); i; i--)
l->top = l->top->prev;
l->pos = l->count - 1;
return 1;
return MSG_HANDLED;
case XCTRL('p'):
case KEY_UP:
listbox_back (l);
return 1;
return MSG_HANDLED;
case XCTRL('n'):
case KEY_DOWN:
listbox_fwd (l);
return 1;
return MSG_HANDLED;
case KEY_NPAGE:
case XCTRL('v'):
@ -1978,7 +1974,7 @@ listbox_key (WListbox *l, int key)
j |= listbox_back (l);
return j > 0;
}
return 0;
return MSG_NOT_HANDLED;
}
static void
@ -1996,7 +1992,7 @@ listbox_destroy (WListbox *l)
}
static int
listbox_callback (WListbox *l, int msg, int par)
listbox_callback (WListbox *l, int msg, int parm)
{
int ret_code;
WLEntry *e;
@ -2004,10 +2000,10 @@ listbox_callback (WListbox *l, int msg, int par)
switch (msg) {
case WIDGET_INIT:
return 1;
return MSG_HANDLED;
case WIDGET_HOTKEY:
if ((e = listbox_check_hotkey (l, par)) != NULL) {
if ((e = listbox_check_hotkey (l, parm)) != NULL) {
int action;
listbox_select_entry (l, e);
@ -2021,31 +2017,31 @@ listbox_callback (WListbox *l, int msg, int par)
h->ret_value = B_ENTER;
dlg_stop (h);
}
return 1;
return MSG_HANDLED;
} else
return 0;
return MSG_NOT_HANDLED;
case WIDGET_KEY:
if ((ret_code = listbox_key (l, par)))
if ((ret_code = listbox_key (l, parm)))
listbox_draw (l, 1);
return ret_code;
case WIDGET_CURSOR:
widget_move (&l->widget, l->cursor_y, 0);
return 1;
return MSG_HANDLED;
case WIDGET_FOCUS:
case WIDGET_UNFOCUS:
case WIDGET_DRAW:
listbox_draw (l, msg != WIDGET_UNFOCUS);
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
listbox_destroy (l);
return 1;
return MSG_HANDLED;
default:
return default_proc (msg, par);
return default_proc (msg, parm);
}
}
@ -2180,11 +2176,11 @@ listbox_add_item (WListbox *l, enum append_pos pos, int hotkey, char *text,
WLEntry *entry;
if (!l)
return 0;
return NULL;
if (!l->allow_duplicates)
if (listbox_search_text (l, text))
return 0;
return NULL;
entry = g_new (WLEntry, 1);
entry->text = g_strdup (text);
@ -2237,26 +2233,26 @@ listbox_get_current (WListbox *l, char **string, char **extra)
static int
buttonbar_callback (WButtonBar *bb, int msg, int par)
buttonbar_callback (WButtonBar *bb, int msg, int parm)
{
int i;
switch (msg) {
case WIDGET_FOCUS:
return 0;
return MSG_NOT_HANDLED;
case WIDGET_HOTKEY:
for (i = 0; i < 10; i++) {
if (par == KEY_F (i + 1) && bb->labels[i].function) {
if (parm == KEY_F (i + 1) && bb->labels[i].function) {
(*bb->labels[i].function) (bb->labels[i].data);
return 1;
return MSG_HANDLED;
}
}
return 0;
return MSG_NOT_HANDLED;
case WIDGET_DRAW:
if (!bb->visible)
return 1;
return MSG_HANDLED;
widget_move (&bb->widget, 0, 0);
attrset (DEFAULT_COLOR);
printw ("%-*s", bb->widget.cols, "");
@ -2270,15 +2266,15 @@ buttonbar_callback (WButtonBar *bb, int msg, int par)
attrset (DEFAULT_COLOR);
}
attrset (SELECTED_COLOR);
return 1;
return MSG_HANDLED;
case WIDGET_DESTROY:
for (i = 0; i < 10; i++)
g_free (bb->labels[i].text);
return 1;
return MSG_HANDLED;
default:
return default_proc (msg, par);
return default_proc (msg, parm);
}
}
@ -2369,8 +2365,8 @@ redraw_labels (Dlg_head *h)
send_message ((Widget *) bb, WIDGET_DRAW, 0);
}
static int
groupbox_callback (WGroupbox *g, int msg, int parm)
static cb_ret_t
groupbox_callback (WGroupbox *g, widget_msg_t msg, int parm)
{
switch (msg) {
case WIDGET_INIT:

View File

@ -149,7 +149,7 @@ WGroupbox *groupbox_new (int x, int y, int width, int height, char *title);
/* Input lines */
void winput_set_origin (WInput *i, int x, int field_len);
int handle_char (WInput *in, int c_code);
cb_ret_t handle_char (WInput *in, int c_code);
int is_in_input_map (WInput *in, int c_code);
void update_input (WInput *in, int clear_first);
void new_input (WInput *in);
@ -161,7 +161,7 @@ void input_enable_update (WInput *in);
void input_set_point (WInput *in, int pos);
void input_show_cursor (WInput *in);
void assign_text (WInput *in, char *text);
int input_callback (WInput *in, int Msg, int Par);
cb_ret_t input_callback (WInput *in, widget_msg_t msg, int parm);
/* Labels */
void label_set_text (WLabel *label, char *text);