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 width; r->texts[i] = parse_hotkey (texts[i]); width = hotkey_width (r->texts[i]); wmax = max (width, wmax); } widget_init (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 (w, TRUE); return r; }
static cb_ret_t menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WMenuBar *menubar = MENUBAR (w); switch (msg) { /* We do not want the focus unless we have been activated */ case MSG_FOCUS: if (!menubar->is_active) return MSG_NOT_HANDLED; /* Trick to get all the mouse events */ w->lines = LINES; /* Trick to get all of the hotkeys */ widget_want_hotkey (w, 1); menubar_draw (menubar); return MSG_HANDLED; /* We don't want the buttonbar to activate while using the menubar */ case MSG_HOTKEY: case MSG_KEY: if (menubar->is_active) { menubar_handle_key (menubar, parm); return MSG_HANDLED; } return MSG_NOT_HANDLED; case MSG_CURSOR: /* Put the cursor in a suitable place */ return MSG_NOT_HANDLED; case MSG_UNFOCUS: return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED; case MSG_DRAW: if (menubar->is_visible) { menubar_draw (menubar); return MSG_HANDLED; } /* fall through */ case MSG_RESIZE: /* try show menu after screen resize */ send_message (w, sender, MSG_FOCUS, 0, data); return MSG_HANDLED; case MSG_DESTROY: menubar_set_menu (menubar, NULL); return MSG_HANDLED; default: return widget_default_callback (w, sender, msg, parm, data); } }
static void menubar_finish (WMenuBar * menubar) { menubar->is_dropped = FALSE; menubar->is_active = FALSE; menubar->widget.lines = 1; widget_want_hotkey (menubar->widget, 0); dlg_select_by_id (menubar->widget.owner, menubar->previous_widget); do_refresh (); }
static void menubar_finish (WMenuBar * menubar) { Widget *w = WIDGET (menubar); menubar->is_dropped = FALSE; menubar->is_active = FALSE; w->lines = 1; widget_want_hotkey (w, 0); dlg_select_by_id (w->owner, menubar->previous_widget); do_refresh (); }
WCheck * check_new (int y, int x, int state, const char *text) { WCheck *c; c = g_new (WCheck, 1); c->text = parse_hotkey (text); init_widget (&c->widget, 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); return c; }
WButtonBar * buttonbar_new (gboolean visible) { WButtonBar *bb; bb = g_new0 (WButtonBar, 1); init_widget (&bb->widget, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event); bb->widget.pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM; bb->visible = visible; widget_want_hotkey (bb->widget, 1); widget_want_cursor (bb->widget, 0); return bb; }
WHLine * hline_new (int y, int x, int width) { WHLine *l; int lines = 1; l = g_new (WHLine, 1); init_widget (&l->widget, y, x, lines, 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); return l; }
WButtonBar * buttonbar_new (gboolean visible) { WButtonBar *bb; Widget *w; bb = g_new0 (WButtonBar, 1); w = WIDGET (bb); widget_init (w, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event); w->pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM; bb->visible = visible; widget_want_hotkey (w, TRUE); widget_want_cursor (w, FALSE); return bb; }
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); /* 4 is width of "[X] " */ widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_mouse_callback); c->state = state ? C_BOOL : 0; widget_want_cursor (w, TRUE); widget_want_hotkey (w, TRUE); return c; }
WHLine * hline_new (int y, int x, int width) { WHLine *l; Widget *w; int lines = 1; l = g_new (WHLine, 1); w = WIDGET (l); widget_init (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL); l->text = NULL; l->auto_adjust_cols = (width < 0); l->transparent = FALSE; widget_want_cursor (w, FALSE); widget_want_hotkey (w, FALSE); return l; }
WGroupbox * groupbox_new (int y, int x, int height, int width, const char *title) { WGroupbox *g; Widget *w; g = g_new (WGroupbox, 1); w = WIDGET (g); widget_init (w, y, x, height, width, groupbox_callback, NULL); widget_want_cursor (w, FALSE); widget_want_hotkey (w, FALSE); g->title = NULL; groupbox_set_title (g, title); return g; }
WButton * button_new (int y, int x, int action, button_flags_t flags, const char *text, bcback_fn callback) { WButton *b; b = g_new (WButton, 1); 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); b->selected = FALSE; b->callback = callback; widget_want_hotkey (b->widget, TRUE); b->hotpos = (b->text.hotkey != NULL) ? str_term_width1 (b->text.start) : -1; return b; }
WLabel * label_new (int y, int x, const char *text) { WLabel *l; int cols = 1; int lines = 1; if (text != NULL) str_msg_term_size (text, &lines, &cols); l = g_new (WLabel, 1); init_widget (&l->widget, 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); return l; }
WGauge * gauge_new (int y, int x, gboolean shown, int max, int current) { WGauge *g; g = g_new (WGauge, 1); init_widget (&g->widget, y, x, 1, gauge_len, gauge_callback, NULL); g->shown = shown; if (max == 0) max = 1; /* I do not like division by zero :) */ g->max = max; g->current = current; g->from_left_to_right = TRUE; widget_want_cursor (g->widget, FALSE); widget_want_hotkey (g->widget, FALSE); return g; }
WGauge * gauge_new (int y, int x, int cols, gboolean shown, int max, int current) { WGauge *g; Widget *w; g = g_new (WGauge, 1); w = WIDGET (g); widget_init (w, y, x, 1, cols, gauge_callback, NULL); widget_want_cursor (w, FALSE); widget_want_hotkey (w, FALSE); g->shown = shown; if (max == 0) max = 1; /* I do not like division by zero :) */ g->max = max; g->current = current; g->from_left_to_right = TRUE; return g; }
WGroupbox * groupbox_new (int y, int x, int height, int width, const char *title) { WGroupbox *g; g = g_new (WGroupbox, 1); init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL); widget_want_cursor (g->widget, FALSE); widget_want_hotkey (g->widget, FALSE); /* Strip existing spaces, add one space before and after the title */ if (title != NULL) { char *t; t = g_strstrip (g_strdup (title)); g->title = g_strconcat (" ", t, " ", (char *) NULL); g_free (t); } return g; }
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); w = WIDGET (l); widget_init (w, y, x, height, width, listbox_callback, listbox_event); l->list = NULL; l->top = l->pos = 0; l->deletable = deletable; l->callback = callback; l->allow_duplicates = TRUE; l->scrollbar = !mc_global.tty.slow_terminal; widget_want_hotkey (w, TRUE); widget_want_cursor (w, FALSE); return l; }