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; }
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; }
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; }
void menubar_arrange (WMenuBar * menubar) { int start_x = 1; GList *i; int gap; if (menubar->menu == NULL) return; gap = WIDGET (menubar)->cols - 2; /* First, calculate gap between items... */ for (i = menubar->menu; i != NULL; i = g_list_next (i)) { 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; } if (g_list_next (menubar->menu) == NULL) gap = 1; else gap /= (g_list_length (menubar->menu) - 1); if (gap <= 0) { /* We are out of luck - window is too narrow... */ gap = 1; } else if (gap >= 3) gap = 3; /* ...and now fix start positions of menubar items */ for (i = menubar->menu; i != NULL; i = g_list_next (i)) { menu_t *menu = MENU (i->data); int len = menu->start_x; menu->start_x = start_x; start_x += len + gap; } }
int button_get_len (const WButton * b) { int ret = hotkey_width (b->text); switch (b->flags) { case DEFPUSH_BUTTON: ret += 6; break; case NORMAL_BUTTON: ret += 4; break; case NARROW_BUTTON: ret += 2; break; case HIDDEN_BUTTON: default: return 0; } return ret; }
static void menu_arrange (menu_t * menu, dlg_shortcut_str get_shortcut) { if (menu != NULL) { GList *i; size_t max_shortcut_len = 0; menu->max_entry_len = 1; menu->max_hotkey_len = 1; for (i = menu->entries; i != NULL; i = g_list_next (i)) { menu_entry_t *entry = MENUENTRY (i->data); if (entry != NULL) { size_t len; len = (size_t) hotkey_width (entry->text); menu->max_hotkey_len = max (menu->max_hotkey_len, len); if (get_shortcut != NULL) entry->shortcut = get_shortcut (entry->command); if (entry->shortcut != NULL) { len = (size_t) str_term_width1 (entry->shortcut); max_shortcut_len = max (max_shortcut_len, len); } } } menu->max_entry_len = menu->max_hotkey_len + max_shortcut_len; } }