Added locale setting before calling dpkg to fix "link to" parsing on non-C locales
[midnight-commander.git] / lib / widget / menu.c
blob1595cd18fd16f943b252a0c9dd0b79ff7ce0535a
1 /* Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2 2007, 2009 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /** \file menu.c
19 * \brief Source: pulldown menu code
22 #include <config.h>
24 #include <ctype.h>
25 #include <stdarg.h>
26 #include <string.h>
27 #include <sys/types.h>
29 #include "lib/global.h"
31 #include "lib/tty/tty.h"
32 #include "lib/skin.h"
33 #include "lib/tty/mouse.h"
34 #include "lib/tty/key.h" /* key macros */
35 #include "lib/strutil.h"
36 #include "lib/widget.h"
37 #include "lib/event.h" /* mc_event_raise() */
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
43 /*** file scope type declarations ****************************************************************/
45 /*** file scope variables ************************************************************************/
47 static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm);
49 /*** file scope functions ************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
52 static void
53 menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
55 if (menu != NULL)
57 GList *i;
58 size_t max_shortcut_len = 0;
60 menu->max_entry_len = 1;
61 menu->max_hotkey_len = 1;
63 for (i = menu->entries; i != NULL; i = g_list_next (i))
65 menu_entry_t *entry = i->data;
67 if (entry != NULL)
69 size_t len;
71 len = (size_t) hotkey_width (entry->text);
72 menu->max_hotkey_len = max (menu->max_hotkey_len, len);
74 if (get_shortcut != NULL)
75 entry->shortcut = get_shortcut (entry->command);
77 if (entry->shortcut != NULL)
79 len = (size_t) str_term_width1 (entry->shortcut);
80 max_shortcut_len = max (max_shortcut_len, len);
85 menu->max_entry_len = menu->max_hotkey_len + max_shortcut_len;
89 /* --------------------------------------------------------------------------------------------- */
91 static void
92 menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
94 const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
95 const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
96 const int y = 2 + idx;
97 int x = menu->start_x;
99 if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
100 x = menubar->widget.cols - menu->max_entry_len - 4;
102 if (entry == NULL)
104 /* menu separator */
105 tty_setcolor (MENU_ENTRY_COLOR);
107 widget_move (&menubar->widget, y, x - 1);
108 tty_print_alt_char (ACS_LTEE, FALSE);
110 tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
111 ACS_HLINE, menu->max_entry_len + 3);
113 widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
114 tty_print_alt_char (ACS_RTEE, FALSE);
116 else
118 /* menu text */
119 tty_setcolor (color);
120 widget_move (&menubar->widget, y, x);
121 tty_print_char ((unsigned char) entry->first_letter);
122 tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */
123 tty_print_string (entry->text.start);
125 if (entry->text.hotkey != NULL)
127 tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
128 tty_print_string (entry->text.hotkey);
129 tty_setcolor (color);
132 if (entry->text.end != NULL)
133 tty_print_string (entry->text.end);
135 if (entry->shortcut != NULL)
137 widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
138 tty_print_string (entry->shortcut);
141 /* move cursor to the start of entry text */
142 widget_move (&menubar->widget, y, x + 1);
146 /* --------------------------------------------------------------------------------------------- */
148 static void
149 menubar_draw_drop (WMenuBar * menubar)
151 const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
152 const unsigned int count = g_list_length (menu->entries);
153 int column = menu->start_x - 1;
154 unsigned int i;
156 if (column + menu->max_entry_len + 5 > (gsize) menubar->widget.cols)
157 column = menubar->widget.cols - menu->max_entry_len - 5;
159 tty_setcolor (MENU_ENTRY_COLOR);
160 draw_box (menubar->widget.owner,
161 menubar->widget.y + 1, menubar->widget.x + column,
162 count + 2, menu->max_entry_len + 5, FALSE);
164 for (i = 0; i < count; i++)
165 menubar_paint_idx (menubar, i,
166 i == menu->selected ? MENU_SELECTED_COLOR : MENU_ENTRY_COLOR);
169 /* --------------------------------------------------------------------------------------------- */
171 static void
172 menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
174 if (!menubar->is_active)
175 tty_setcolor (MENU_INACTIVE_COLOR);
176 else if (current)
177 tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR);
178 else
179 tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR);
182 /* --------------------------------------------------------------------------------------------- */
184 static void
185 menubar_draw (WMenuBar * menubar)
187 GList *i;
189 /* First draw the complete menubar */
190 tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR);
191 tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
193 /* Now each one of the entries */
194 for (i = menubar->menu; i != NULL; i = g_list_next (i))
196 Menu *menu = i->data;
197 gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i));
199 menubar_set_color (menubar, is_selected, FALSE);
200 widget_move (&menubar->widget, 0, menu->start_x);
202 tty_print_char (' ');
203 tty_print_string (menu->text.start);
205 if (menu->text.hotkey != NULL)
207 menubar_set_color (menubar, is_selected, TRUE);
208 tty_print_string (menu->text.hotkey);
209 menubar_set_color (menubar, is_selected, FALSE);
212 if (menu->text.end != NULL)
213 tty_print_string (menu->text.end);
215 tty_print_char (' ');
218 if (menubar->is_dropped)
219 menubar_draw_drop (menubar);
220 else
221 widget_move (&menubar->widget, 0,
222 ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x);
225 /* --------------------------------------------------------------------------------------------- */
227 static void
228 menubar_remove (WMenuBar * menubar)
230 if (menubar->is_dropped)
232 menubar->is_dropped = FALSE;
233 do_refresh ();
234 menubar->is_dropped = TRUE;
238 /* --------------------------------------------------------------------------------------------- */
240 static void
241 menubar_left (WMenuBar * menubar)
243 menubar_remove (menubar);
244 if (menubar->selected == 0)
245 menubar->selected = g_list_length (menubar->menu) - 1;
246 else
247 menubar->selected--;
248 menubar_draw (menubar);
251 /* --------------------------------------------------------------------------------------------- */
253 static void
254 menubar_right (WMenuBar * menubar)
256 menubar_remove (menubar);
257 menubar->selected = (menubar->selected + 1) % g_list_length (menubar->menu);
258 menubar_draw (menubar);
261 /* --------------------------------------------------------------------------------------------- */
263 static void
264 menubar_finish (WMenuBar * menubar)
266 menubar->is_dropped = FALSE;
267 menubar->is_active = FALSE;
268 menubar->widget.lines = 1;
269 widget_want_hotkey (menubar->widget, 0);
271 dlg_select_by_id (menubar->widget.owner, menubar->previous_widget);
272 do_refresh ();
275 /* --------------------------------------------------------------------------------------------- */
277 static void
278 menubar_drop (WMenuBar * menubar, unsigned int selected)
280 menubar->is_dropped = TRUE;
281 menubar->selected = selected;
282 menubar_draw (menubar);
285 /* --------------------------------------------------------------------------------------------- */
287 static void
288 menubar_execute (WMenuBar * menubar)
290 const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
291 const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected);
293 if ((entry != NULL) && (entry->command != CK_IgnoreKey))
295 mc_global.is_right = (menubar->selected != 0);
296 menubar_finish (menubar);
297 menubar->widget.owner->callback (menubar->widget.owner, &menubar->widget,
298 DLG_ACTION, entry->command, NULL);
299 do_refresh ();
303 /* --------------------------------------------------------------------------------------------- */
305 static void
306 menubar_down (WMenuBar * menubar)
308 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
309 const unsigned int len = g_list_length (menu->entries);
310 menu_entry_t *entry;
312 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
316 menu->selected = (menu->selected + 1) % len;
317 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
319 while ((entry == NULL) || (entry->command == CK_IgnoreKey));
321 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
324 /* --------------------------------------------------------------------------------------------- */
326 static void
327 menubar_up (WMenuBar * menubar)
329 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
330 const unsigned int len = g_list_length (menu->entries);
331 menu_entry_t *entry;
333 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
337 if (menu->selected == 0)
338 menu->selected = len - 1;
339 else
340 menu->selected--;
341 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
343 while ((entry == NULL) || (entry->command == CK_IgnoreKey));
345 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
348 /* --------------------------------------------------------------------------------------------- */
350 static void
351 menubar_first (WMenuBar * menubar)
353 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
354 menu_entry_t *entry;
356 if (menu->selected == 0)
357 return;
359 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
361 menu->selected = 0;
363 while (TRUE)
365 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
367 if ((entry == NULL) || (entry->command == CK_IgnoreKey))
368 menu->selected++;
369 else
370 break;
373 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
376 /* --------------------------------------------------------------------------------------------- */
378 static void
379 menubar_last (WMenuBar * menubar)
381 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
382 const unsigned int len = g_list_length (menu->entries);
383 menu_entry_t *entry;
385 if (menu->selected == len - 1)
386 return;
388 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
390 menu->selected = len;
394 menu->selected--;
395 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
397 while ((entry == NULL) || (entry->command == CK_IgnoreKey));
399 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
402 /* --------------------------------------------------------------------------------------------- */
404 static int
405 menubar_handle_key (WMenuBar * menubar, int key)
407 /* Lowercase */
408 if (isascii (key))
409 key = g_ascii_tolower (key);
411 if (is_abort_char (key))
413 menubar_finish (menubar);
414 return 1;
417 /* menubar help or menubar navigation */
418 switch (key)
420 case KEY_F (1):
422 ev_help_t event_data = { NULL, NULL };
424 if (menubar->is_dropped)
425 event_data.node =
426 ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->help_node;
427 else
428 event_data.node = "[Menu Bar]";
430 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
431 menubar_draw (menubar);
432 return 1;
434 case KEY_LEFT:
435 case XCTRL ('b'):
436 menubar_left (menubar);
437 return 1;
439 case KEY_RIGHT:
440 case XCTRL ('f'):
441 menubar_right (menubar);
442 return 1;
445 if (!menubar->is_dropped)
447 GList *i;
449 /* drop menu by hotkey */
450 for (i = menubar->menu; i != NULL; i = g_list_next (i))
452 Menu *menu = i->data;
454 if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0])))
456 menubar_drop (menubar, g_list_position (menubar->menu, i));
457 return 1;
461 /* drop menu by Enter or Dowwn key */
462 if (key == KEY_ENTER || key == XCTRL ('n') || key == KEY_DOWN || key == '\n')
463 menubar_drop (menubar, menubar->selected);
465 return 1;
469 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
470 GList *i;
472 /* execute menu command by hotkey */
473 for (i = menu->entries; i != NULL; i = g_list_next (i))
475 const menu_entry_t *entry = i->data;
477 if ((entry != NULL) && (entry->command != CK_IgnoreKey)
478 && (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0])))
480 menu->selected = g_list_position (menu->entries, i);
481 menubar_execute (menubar);
482 return 1;
486 /* menu execute by Enter or menu navigation */
487 switch (key)
489 case KEY_ENTER:
490 case '\n':
491 menubar_execute (menubar);
492 return 1;
494 case KEY_HOME:
495 case ALT ('<'):
496 menubar_first (menubar);
497 break;
499 case KEY_END:
500 case ALT ('>'):
501 menubar_last (menubar);
502 break;
504 case KEY_DOWN:
505 case XCTRL ('n'):
506 menubar_down (menubar);
507 break;
509 case KEY_UP:
510 case XCTRL ('p'):
511 menubar_up (menubar);
512 break;
516 return 0;
519 /* --------------------------------------------------------------------------------------------- */
521 static cb_ret_t
522 menubar_callback (Widget * w, widget_msg_t msg, int parm)
524 WMenuBar *menubar = (WMenuBar *) w;
526 switch (msg)
528 /* We do not want the focus unless we have been activated */
529 case WIDGET_FOCUS:
530 if (!menubar->is_active)
531 return MSG_NOT_HANDLED;
533 /* Trick to get all the mouse events */
534 menubar->widget.lines = LINES;
536 /* Trick to get all of the hotkeys */
537 widget_want_hotkey (menubar->widget, 1);
538 menubar_draw (menubar);
539 return MSG_HANDLED;
541 /* We don't want the buttonbar to activate while using the menubar */
542 case WIDGET_HOTKEY:
543 case WIDGET_KEY:
544 if (menubar->is_active)
546 menubar_handle_key (menubar, parm);
547 return MSG_HANDLED;
549 return MSG_NOT_HANDLED;
551 case WIDGET_CURSOR:
552 /* Put the cursor in a suitable place */
553 return MSG_NOT_HANDLED;
555 case WIDGET_UNFOCUS:
556 return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED;
558 case WIDGET_DRAW:
559 if (menubar->is_visible)
561 menubar_draw (menubar);
562 return MSG_HANDLED;
564 /* fall through */
566 case WIDGET_RESIZED:
567 /* try show menu after screen resize */
568 send_message (w, WIDGET_FOCUS, 0);
569 return MSG_HANDLED;
572 case WIDGET_DESTROY:
573 menubar_set_menu (menubar, NULL);
574 return MSG_HANDLED;
576 default:
577 return default_proc (msg, parm);
581 /* --------------------------------------------------------------------------------------------- */
583 static int
584 menubar_event (Gpm_Event * event, void *data)
586 WMenuBar *menubar = data;
587 gboolean was_active = TRUE;
588 int left_x, right_x, bottom_y;
589 Menu *menu;
591 /* ignore unsupported events */
592 if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0)
593 return MOU_NORMAL;
595 /* ignore wheel events if menu is inactive */
596 if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
597 return MOU_NORMAL;
599 if (!menubar->is_dropped)
601 menubar->previous_widget = dlg_get_current_widget_id (menubar->widget.owner);
602 menubar->is_active = TRUE;
603 menubar->is_dropped = TRUE;
604 was_active = FALSE;
607 /* Mouse operations on the menubar */
608 if (event->y == 1 || !was_active)
610 if ((event->type & GPM_UP) != 0)
611 return MOU_NORMAL;
613 /* wheel events on menubar */
614 if (event->buttons & GPM_B_UP)
615 menubar_left (menubar);
616 else if (event->buttons & GPM_B_DOWN)
617 menubar_right (menubar);
618 else
620 const unsigned int len = g_list_length (menubar->menu);
621 unsigned int new_selection = 0;
623 while ((new_selection < len)
624 && (event->x > ((Menu *) g_list_nth_data (menubar->menu,
625 new_selection))->start_x))
626 new_selection++;
628 if (new_selection != 0) /* Don't set the invalid value -1 */
629 new_selection--;
631 if (!was_active)
633 menubar->selected = new_selection;
634 dlg_select_widget (menubar);
636 else
638 menubar_remove (menubar);
639 menubar->selected = new_selection;
641 menubar_draw (menubar);
643 return MOU_NORMAL;
646 if (!menubar->is_dropped || (event->y < 2))
647 return MOU_NORMAL;
649 /* middle click -- everywhere */
650 if (((event->buttons & GPM_B_MIDDLE) != 0) && ((event->type & GPM_DOWN) != 0))
652 menubar_execute (menubar);
653 return MOU_NORMAL;
656 /* the mouse operation is on the menus or it is not */
657 menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected);
658 left_x = menu->start_x;
659 right_x = left_x + menu->max_entry_len + 3;
660 if (right_x > menubar->widget.cols)
662 left_x = menubar->widget.cols - menu->max_entry_len - 3;
663 right_x = menubar->widget.cols;
666 bottom_y = g_list_length (menu->entries) + 3;
668 if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y))
670 int pos = event->y - 3;
671 const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
673 /* mouse wheel */
674 if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
676 menubar_up (menubar);
677 return MOU_NORMAL;
679 if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
681 menubar_down (menubar);
682 return MOU_NORMAL;
685 /* ignore events above and below dropped down menu */
686 if ((pos < 0) || (pos >= bottom_y - 3))
687 return MOU_NORMAL;
689 if ((entry != NULL) && (entry->command != CK_IgnoreKey))
691 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
692 menu->selected = pos;
693 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
695 if ((event->type & GPM_UP) != 0)
696 menubar_execute (menubar);
699 else
700 /* use click not wheel to close menu */
701 if (((event->type & GPM_DOWN) != 0) && ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
702 menubar_finish (menubar);
704 return MOU_NORMAL;
707 /* --------------------------------------------------------------------------------------------- */
708 /*** public functions ****************************************************************************/
709 /* --------------------------------------------------------------------------------------------- */
711 menu_entry_t *
712 menu_entry_create (const char *name, unsigned long command)
714 menu_entry_t *entry;
716 entry = g_new (menu_entry_t, 1);
717 entry->first_letter = ' ';
718 entry->text = parse_hotkey (name);
719 entry->command = command;
720 entry->shortcut = NULL;
722 return entry;
725 /* --------------------------------------------------------------------------------------------- */
727 void
728 menu_entry_free (menu_entry_t * entry)
730 if (entry != NULL)
732 release_hotkey (entry->text);
733 g_free (entry->shortcut);
734 g_free (entry);
738 /* --------------------------------------------------------------------------------------------- */
740 Menu *
741 create_menu (const char *name, GList * entries, const char *help_node)
743 Menu *menu;
745 menu = g_new (Menu, 1);
746 menu->start_x = 0;
747 menu->text = parse_hotkey (name);
748 menu->entries = entries;
749 menu->max_entry_len = 1;
750 menu->max_hotkey_len = 0;
751 menu->selected = 0;
752 menu->help_node = g_strdup (help_node);
754 return menu;
757 /* --------------------------------------------------------------------------------------------- */
759 void
760 menu_set_name (Menu * menu, const char *name)
762 release_hotkey (menu->text);
763 menu->text = parse_hotkey (name);
766 /* --------------------------------------------------------------------------------------------- */
768 void
769 destroy_menu (Menu * menu)
771 release_hotkey (menu->text);
772 g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
773 g_list_free (menu->entries);
774 g_free (menu->help_node);
775 g_free (menu);
778 /* --------------------------------------------------------------------------------------------- */
780 WMenuBar *
781 menubar_new (int y, int x, int cols, GList * menu)
783 WMenuBar *menubar;
785 menubar = g_new0 (WMenuBar, 1);
786 init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event);
787 widget_want_cursor (menubar->widget, FALSE);
788 menubar->is_visible = TRUE; /* by default */
789 menubar_set_menu (menubar, menu);
791 return menubar;
794 /* --------------------------------------------------------------------------------------------- */
796 void
797 menubar_set_menu (WMenuBar * menubar, GList * menu)
799 /* delete previous menu */
800 if (menubar->menu != NULL)
802 g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
803 g_list_free (menubar->menu);
805 /* add new menu */
806 menubar->is_active = FALSE;
807 menubar->is_dropped = FALSE;
808 menubar->menu = menu;
809 menubar->selected = 0;
810 menubar_arrange (menubar);
813 /* --------------------------------------------------------------------------------------------- */
815 void
816 menubar_add_menu (WMenuBar * menubar, Menu * menu)
818 if (menu != NULL)
820 menu_arrange (menu, menubar->widget.owner->get_shortcut);
821 menubar->menu = g_list_append (menubar->menu, menu);
824 menubar_arrange (menubar);
827 /* --------------------------------------------------------------------------------------------- */
829 * Properly space menubar items. Should be called when menubar is created
830 * and also when widget width is changed (i.e. upon xterm resize).
833 void
834 menubar_arrange (WMenuBar * menubar)
836 int start_x = 1;
837 GList *i;
838 int gap;
840 if (menubar->menu == NULL)
841 return;
843 #ifndef RESIZABLE_MENUBAR
844 gap = 3;
846 for (i = menubar->menu; i != NULL; i = g_list_next (i))
848 Menu *menu = i->data;
849 int len = hotkey_width (menu->text) + 2;
851 menu->start_x = start_x;
852 start_x += len + gap;
854 #else /* RESIZABLE_MENUBAR */
855 gap = menubar->widget.cols - 2;
857 /* First, calculate gap between items... */
858 for (i = menubar->menu; i != NULL; i = g_list_nwxt (i))
860 Menu *menu = i->data;
861 /* preserve length here, to be used below */
862 menu->start_x = hotkey_width (menu->text) + 2;
863 gap -= menu->start_x;
866 gap /= (menubar->menu->len - 1);
868 if (gap <= 0)
870 /* We are out of luck - window is too narrow... */
871 gap = 1;
874 /* ...and now fix start positions of menubar items */
875 for (i = menubar->menu; i != NULL; i = g_list_nwxt (i))
877 Menu *menu = i->data;
878 int len = menu->start_x;
880 menu->start_x = start_x;
881 start_x += len + gap;
883 #endif /* RESIZABLE_MENUBAR */
886 /* --------------------------------------------------------------------------------------------- */
887 /** Find MenuBar widget in the dialog */
889 WMenuBar *
890 find_menubar (const Dlg_head * h)
892 return (WMenuBar *) find_widget_type (h, menubar_callback);
895 /* --------------------------------------------------------------------------------------------- */