static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm) { WMenuBar *menubar = (WMenuBar *) w; switch (msg) { /* We do not want the focus unless we have been activated */ case WIDGET_FOCUS: if (!menubar->is_active) return MSG_NOT_HANDLED; /* 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_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->is_active) { menubar_handle_key (menubar, parm); return MSG_HANDLED; } return MSG_NOT_HANDLED; case WIDGET_CURSOR: /* Put the cursor in a suitable place */ return MSG_NOT_HANDLED; case WIDGET_UNFOCUS: return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED; case WIDGET_DRAW: if (menubar->is_visible) { menubar_draw (menubar); return MSG_HANDLED; } /* fall through */ case WIDGET_RESIZED: /* try show menu after screen resize */ send_message (w, WIDGET_FOCUS, 0); return MSG_HANDLED; case WIDGET_DESTROY: menubar_set_menu (menubar, NULL); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t tree_callback (Widget *w, widget_msg_t msg, int parm) { WTree *tree = (WTree *) w; Dlg_head *h = tree->widget.parent; switch (msg) { case WIDGET_DRAW: tree_frame (h, tree); show_tree (tree); return MSG_HANDLED; case WIDGET_KEY: return tree_key (tree, parm); case WIDGET_FOCUS: tree->active = 1; buttonbar_set_label (h, 1, _("Help"), tree_help_cmd); buttonbar_set_label_data (h, 2, _("Rescan"), tree_rescan_command, tree); buttonbar_set_label_data (h, 3, _("Forget"), tree_forget_cmd, tree); buttonbar_set_label_data (h, 5, _("Copy"), tree_copy_cmd, tree); buttonbar_set_label_data (h, 6, _("RenMov"), tree_move_cmd, tree); #if 0 /* FIXME: mkdir is currently defunct */ buttonbar_set_label_data (h, 7, _("Mkdir"), tree_mkdir_cmd, tree); #else buttonbar_clear_label (h, 7); #endif buttonbar_set_label_data (h, 8, _("Rmdir"), tree_rmdir_command, tree); set_navig_label (tree); buttonbar_redraw (h); /* FIXME: Should find a better way of only displaying the currently selected item */ show_tree (tree); return MSG_HANDLED; /* FIXME: Should find a better way of changing the color of the selected item */ case WIDGET_UNFOCUS: tree->active = 0; show_tree (tree); return MSG_HANDLED; case WIDGET_DESTROY: tree_destroy (tree); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t buttonbar_callback (Widget * w, widget_msg_t msg, int parm) { WButtonBar *bb = (WButtonBar *) w; int i; const char *text; switch (msg) { case WIDGET_FOCUS: return MSG_NOT_HANDLED; case WIDGET_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: if (bb->visible) { buttonbar_init_button_positions (bb); widget_move (&bb->widget, 0, 0); tty_setcolor (DEFAULT_COLOR); tty_printf ("%-*s", bb->widget.cols, ""); widget_move (&bb->widget, 0, 0); for (i = 0; i < BUTTONBAR_LABELS_NUM; i++) { int width; width = buttonbar_get_button_width (bb, i); if (width <= 0) break; tty_setcolor (BUTTONBAR_HOTKEY_COLOR); tty_printf ("%2d", i + 1); tty_setcolor (BUTTONBAR_BUTTON_COLOR); text = (bb->labels[i].text != NULL) ? bb->labels[i].text : ""; tty_print_string (str_fit_to_term (text, width - 2, J_LEFT_FIT)); } } return MSG_HANDLED; case WIDGET_DESTROY: for (i = 0; i < BUTTONBAR_LABELS_NUM; i++) g_free (bb->labels[i].text); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm) { WEdit *e = (WEdit *) w; switch (msg) { case WIDGET_DRAW: e->force |= REDRAW_COMPLETELY; /* fallthrough */ case WIDGET_FOCUS: edit_update_screen (e); return MSG_HANDLED; case WIDGET_KEY: { int cmd, ch; cb_ret_t ret = MSG_NOT_HANDLED; /* The user may override the access-keys for the menu bar. */ if (macro_index == -1 && edit_execute_macro (e, parm)) ret = MSG_HANDLED; else if (edit_translate_key (e, parm, &cmd, &ch)) { edit_execute_key_command (e, cmd, ch); edit_update_screen (e); ret = MSG_HANDLED; } else if (edit_drop_hotkey_menu (e, parm)) ret = MSG_HANDLED; return ret; } case WIDGET_COMMAND: /* command from menubar or buttonbar */ return edit_command_execute (e, parm); case WIDGET_CURSOR: widget_move (w, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET, e->curs_col + e->start_col + e->over_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width); return MSG_HANDLED; case WIDGET_DESTROY: edit_clean (e); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t check_callback (Widget * w, widget_msg_t msg, int parm) { WCheck *c = (WCheck *) w; Dlg_head *h = c->widget.owner; switch (msg) { case WIDGET_HOTKEY: if (c->text.hotkey != NULL) { if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm) { check_callback (w, WIDGET_KEY, ' '); /* make action */ return MSG_HANDLED; } } return MSG_NOT_HANDLED; case WIDGET_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, ' '); return MSG_HANDLED; case WIDGET_CURSOR: widget_move (&c->widget, 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); tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] "); hotkey_draw (w, c->text, msg == WIDGET_FOCUS); return MSG_HANDLED; case WIDGET_DESTROY: release_hotkey (c->text); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t hline_callback (Widget * w, widget_msg_t msg, int parm) { WHLine *l = (WHLine *) w; Dlg_head *h = l->widget.owner; switch (msg) { case WIDGET_INIT: case WIDGET_RESIZED: if (l->auto_adjust_cols) { if (((w->owner->flags & DLG_COMPACT) != 0)) { w->x = w->owner->x; w->cols = w->owner->cols; } else { w->x = w->owner->x + 1; w->cols = w->owner->cols - 2; } } case WIDGET_FOCUS: /* We don't want to get the focus */ return MSG_NOT_HANDLED; case WIDGET_DRAW: if (l->transparent) tty_setcolor (DEFAULT_COLOR); else tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2); if (l->auto_adjust_cols) { widget_move (w, 0, 0); tty_print_alt_char (ACS_LTEE, FALSE); widget_move (w, 0, w->cols - 1); tty_print_alt_char (ACS_RTEE, FALSE); } return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t view_callback (Widget *w, widget_msg_t msg, int parm) { cb_ret_t i; WDiff *view = (WDiff *)w; Dlg_head *h = view->widget.parent; switch (msg) { case WIDGET_INIT: view_labels(view); return MSG_HANDLED; case WIDGET_DRAW: view->new_frame = 1; view_update(view); return MSG_HANDLED; case WIDGET_CURSOR: return MSG_HANDLED; case WIDGET_KEY: i = view_handle_key((WDiff *)view, parm); if (view->view_quit) dlg_stop(h); else { view_update(view); } return i; case WIDGET_IDLE: return MSG_HANDLED; case WIDGET_FOCUS: view_labels(view); return MSG_HANDLED; case WIDGET_DESTROY: return MSG_HANDLED; default: return default_proc(msg, parm); } }
static cb_ret_t groupbox_callback (Widget * w, widget_msg_t msg, int parm) { WGroupbox *g = (WGroupbox *) w; switch (msg) { case WIDGET_INIT: return MSG_HANDLED; case WIDGET_FOCUS: return MSG_NOT_HANDLED; case WIDGET_DRAW: { 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); 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); tty_print_string (g->title); } return MSG_HANDLED; } case WIDGET_DESTROY: g_free (g->title); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t button_callback (Widget * w, widget_msg_t msg, int parm) { WButton *b = (WButton *) w; int stop = 0; int off = 0; Dlg_head *h = b->widget.owner; switch (msg) { case WIDGET_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) { button_callback (w, WIDGET_KEY, ' '); return MSG_HANDLED; } if (parm == '\n' && b->flags == DEFPUSH_BUTTON) { button_callback (w, WIDGET_KEY, ' '); return MSG_HANDLED; } if (b->text.hotkey != NULL && g_ascii_tolower ((gchar) b->text.hotkey[0]) == parm) { button_callback (w, WIDGET_KEY, ' '); return MSG_HANDLED; } return MSG_NOT_HANDLED; case WIDGET_KEY: if (parm != ' ' && parm != '\n') return MSG_NOT_HANDLED; if (b->callback != NULL) stop = b->callback (b, b->action); if (b->callback == NULL || stop != 0) { h->ret_value = b->action; dlg_stop (h); } return MSG_HANDLED; case WIDGET_CURSOR: switch (b->flags) { case DEFPUSH_BUTTON: off = 3; break; case NORMAL_BUTTON: off = 2; break; case NARROW_BUTTON: off = 1; break; case HIDDEN_BUTTON: default: off = 0; break; } widget_move (&b->widget, 0, b->hotpos + off); return MSG_HANDLED; case WIDGET_UNFOCUS: case WIDGET_FOCUS: case WIDGET_DRAW: if (msg == WIDGET_UNFOCUS) b->selected = FALSE; else if (msg == WIDGET_FOCUS) b->selected = TRUE; widget_selectcolor (w, b->selected, FALSE); widget_move (w, 0, 0); switch (b->flags) { case DEFPUSH_BUTTON: tty_print_string ("[< "); break; case NORMAL_BUTTON: tty_print_string ("[ "); break; case NARROW_BUTTON: tty_print_string ("["); break; case HIDDEN_BUTTON: default: return MSG_HANDLED; } hotkey_draw (w, b->text, b->selected); switch (b->flags) { case DEFPUSH_BUTTON: tty_print_string (" >]"); break; case NORMAL_BUTTON: tty_print_string (" ]"); break; case NARROW_BUTTON: tty_print_string ("]"); break; default: break; } return MSG_HANDLED; case WIDGET_DESTROY: release_hotkey (b->text); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t tree_callback (Widget * w, widget_msg_t msg, int parm) { WTree *tree = (WTree *) w; Dlg_head *h = tree->widget.owner; WButtonBar *b = find_buttonbar (h); switch (msg) { case WIDGET_DRAW: tree_frame (h, tree); show_tree (tree); return MSG_HANDLED; case WIDGET_FOCUS: tree->active = 1; buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), tree_map, (Widget *) tree); buttonbar_set_label (b, 2, Q_ ("ButtonBar|Rescan"), tree_map, (Widget *) tree); buttonbar_set_label (b, 3, Q_ ("ButtonBar|Forget"), tree_map, (Widget *) tree); buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static") : Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree); buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), tree_map, (Widget *) tree); buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), tree_map, (Widget *) tree); #if 0 /* FIXME: mkdir is currently defunct */ buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, (Widget *) tree); #else buttonbar_clear_label (b, 7, (Widget *) tree); #endif buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, (Widget *) tree); buttonbar_redraw (b); /* FIXME: Should find a better way of only displaying the currently selected item */ show_tree (tree); return MSG_HANDLED; /* FIXME: Should find a better way of changing the color of the selected item */ case WIDGET_UNFOCUS: tree->active = 0; tree->searching = 0; show_tree (tree); return MSG_HANDLED; case WIDGET_KEY: return tree_key (tree, parm); case WIDGET_COMMAND: /* command from buttonbar */ return tree_execute_cmd (tree, parm); case WIDGET_DESTROY: tree_destroy (tree); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm) { WEdit *e = (WEdit *) w; switch (msg) { case WIDGET_FOCUS: edit_set_buttonbar (e, find_buttonbar (e->widget.owner)); /* fall through */ case WIDGET_DRAW: e->force |= REDRAW_COMPLETELY; edit_update_screen (e); return MSG_HANDLED; case WIDGET_UNFOCUS: /* redraw frame and status */ edit_status (e, FALSE); return MSG_HANDLED; case WIDGET_KEY: { int cmd, ch; cb_ret_t ret = MSG_NOT_HANDLED; /* The user may override the access-keys for the menu bar. */ if (macro_index == -1 && edit_execute_macro (e, parm)) { edit_update_screen (e); ret = MSG_HANDLED; } else if (edit_translate_key (e, parm, &cmd, &ch)) { edit_execute_key_command (e, cmd, ch); edit_update_screen (e); ret = MSG_HANDLED; } return ret; } case WIDGET_COMMAND: /* command from menubar or buttonbar */ edit_execute_key_command (e, parm, -1); edit_update_screen (e); return MSG_HANDLED; case WIDGET_CURSOR: { int y, x; y = (e->fullscreen ? 0 : 1) + EDIT_TEXT_VERTICAL_OFFSET + e->curs_row; x = (e->fullscreen ? 0 : 1) + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width + e->curs_col + e->start_col + e->over_col; widget_move (w, y, x); return MSG_HANDLED; } case WIDGET_DESTROY: edit_clean (e); return MSG_HANDLED; default: return default_proc (msg, parm); } }
static cb_ret_t gauge_callback (Widget * w, widget_msg_t msg, int parm) { WGauge *g = (WGauge *) w; Dlg_head *h = g->widget.owner; if (msg == WIDGET_INIT) return MSG_HANDLED; /* We don't want to get the focus */ if (msg == WIDGET_FOCUS) return MSG_NOT_HANDLED; if (msg == WIDGET_DRAW) { widget_move (&g->widget, 0, 0); tty_setcolor (h->color[DLG_COLOR_NORMAL]); if (!g->shown) tty_printf ("%*s", gauge_len, ""); else { int percentage, columns; long total = g->max; long done = g->current; if (total <= 0 || done < 0) { done = 0; total = 100; } if (done > total) done = total; while (total > 65535) { total /= 256; done /= 256; } percentage = (200 * done / total + 1) / 2; columns = (2 * (gauge_len - 7) * done / total + 1) / 2; tty_print_char ('['); if (g->from_left_to_right) { tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", (int) columns, ""); tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s] %3d%%", (int) (gauge_len - 7 - columns), "", (int) percentage); } else { tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("%*s", gauge_len - columns - 7, ""); tty_setcolor (GAUGE_COLOR); tty_printf ("%*s", columns, ""); tty_setcolor (h->color[DLG_COLOR_NORMAL]); tty_printf ("] %3d%%", 100 * columns / (gauge_len - 7), percentage); } } return MSG_HANDLED; } return default_proc (msg, parm); }
static cb_ret_t label_callback (Widget * w, widget_msg_t msg, int parm) { WLabel *l = (WLabel *) w; Dlg_head *h = l->widget.owner; switch (msg) { case WIDGET_INIT: return MSG_HANDLED; /* We don't want to get the focus */ case WIDGET_FOCUS: return MSG_NOT_HANDLED; case WIDGET_DRAW: { char *p = l->text; int y = 0; gboolean disabled = (w->options & W_DISABLED) != 0; if (l->text == NULL) return MSG_HANDLED; if (l->transparent) tty_setcolor (disabled ? DISABLED_COLOR : DEFAULT_COLOR); else tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]); while (TRUE) { char *q; char c = '\0'; q = strchr (p, '\n'); if (q != NULL) { c = q[0]; q[0] = '\0'; } widget_move (&l->widget, y, 0); tty_print_string (str_fit_to_term (p, l->widget.cols, J_LEFT)); if (q == NULL) break; q[0] = c; p = q + 1; y++; } return MSG_HANDLED; } case WIDGET_DESTROY: g_free (l->text); return MSG_HANDLED; default: return default_proc (msg, parm); } }