Reorder fields in mc_global struct and change type for some of them.
[midnight-commander.git] / lib / widget / menu.c
blobcadf03b3cd84a9fd4586cb9b8396dace2dbdedf4
1 /*
2 Pulldown menu code
4 Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5 2007, 2009, 2011
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** \file menu.c
25 * \brief Source: pulldown menu code
28 #include <config.h>
30 #include <ctype.h>
31 #include <stdarg.h>
32 #include <string.h>
33 #include <sys/types.h>
35 #include "lib/global.h"
37 #include "lib/tty/tty.h"
38 #include "lib/skin.h"
39 #include "lib/tty/mouse.h"
40 #include "lib/tty/key.h" /* key macros */
41 #include "lib/strutil.h"
42 #include "lib/widget.h"
43 #include "lib/event.h" /* mc_event_raise() */
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
51 /*** file scope variables ************************************************************************/
53 static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm);
55 /*** file scope functions ************************************************************************/
56 /* --------------------------------------------------------------------------------------------- */
58 static void
59 menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
61 if (menu != NULL)
63 GList *i;
64 size_t max_shortcut_len = 0;
66 menu->max_entry_len = 1;
67 menu->max_hotkey_len = 1;
69 for (i = menu->entries; i != NULL; i = g_list_next (i))
71 menu_entry_t *entry = i->data;
73 if (entry != NULL)
75 size_t len;
77 len = (size_t) hotkey_width (entry->text);
78 menu->max_hotkey_len = max (menu->max_hotkey_len, len);
80 if (get_shortcut != NULL)
81 entry->shortcut = get_shortcut (entry->command);
83 if (entry->shortcut != NULL)
85 len = (size_t) str_term_width1 (entry->shortcut);
86 max_shortcut_len = max (max_shortcut_len, len);
91 menu->max_entry_len = menu->max_hotkey_len + max_shortcut_len;
95 /* --------------------------------------------------------------------------------------------- */
97 static void
98 menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
100 const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
101 const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
102 const int y = 2 + idx;
103 int x = menu->start_x;
105 if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
106 x = menubar->widget.cols - menu->max_entry_len - 4;
108 if (entry == NULL)
110 /* menu separator */
111 tty_setcolor (MENU_ENTRY_COLOR);
113 widget_move (&menubar->widget, y, x - 1);
114 tty_print_alt_char (ACS_LTEE, FALSE);
116 tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
117 ACS_HLINE, menu->max_entry_len + 3);
119 widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
120 tty_print_alt_char (ACS_RTEE, FALSE);
122 else
124 /* menu text */
125 tty_setcolor (color);
126 widget_move (&menubar->widget, y, x);
127 tty_print_char ((unsigned char) entry->first_letter);
128 tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */
129 tty_print_string (entry->text.start);
131 if (entry->text.hotkey != NULL)
133 tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
134 tty_print_string (entry->text.hotkey);
135 tty_setcolor (color);
138 if (entry->text.end != NULL)
139 tty_print_string (entry->text.end);
141 if (entry->shortcut != NULL)
143 widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
144 tty_print_string (entry->shortcut);
147 /* move cursor to the start of entry text */
148 widget_move (&menubar->widget, y, x + 1);
152 /* --------------------------------------------------------------------------------------------- */
154 static void
155 menubar_draw_drop (WMenuBar * menubar)
157 const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
158 const unsigned int count = g_list_length (menu->entries);
159 int column = menu->start_x - 1;
160 unsigned int i;
162 if (column + menu->max_entry_len + 5 > (gsize) menubar->widget.cols)
163 column = menubar->widget.cols - menu->max_entry_len - 5;
165 tty_setcolor (MENU_ENTRY_COLOR);
166 draw_box (menubar->widget.owner,
167 menubar->widget.y + 1, menubar->widget.x + column,
168 count + 2, menu->max_entry_len + 5, FALSE);
170 for (i = 0; i < count; i++)
171 menubar_paint_idx (menubar, i,
172 i == menu->selected ? MENU_SELECTED_COLOR : MENU_ENTRY_COLOR);
175 /* --------------------------------------------------------------------------------------------- */
177 static void
178 menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
180 if (!menubar->is_active)
181 tty_setcolor (MENU_INACTIVE_COLOR);
182 else if (current)
183 tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR);
184 else
185 tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR);
188 /* --------------------------------------------------------------------------------------------- */
190 static void
191 menubar_draw (WMenuBar * menubar)
193 GList *i;
195 /* First draw the complete menubar */
196 tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR);
197 tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
199 /* Now each one of the entries */
200 for (i = menubar->menu; i != NULL; i = g_list_next (i))
202 Menu *menu = i->data;
203 gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i));
205 menubar_set_color (menubar, is_selected, FALSE);
206 widget_move (&menubar->widget, 0, menu->start_x);
208 tty_print_char (' ');
209 tty_print_string (menu->text.start);
211 if (menu->text.hotkey != NULL)
213 menubar_set_color (menubar, is_selected, TRUE);
214 tty_print_string (menu->text.hotkey);
215 menubar_set_color (menubar, is_selected, FALSE);
218 if (menu->text.end != NULL)
219 tty_print_string (menu->text.end);
221 tty_print_char (' ');
224 if (menubar->is_dropped)
225 menubar_draw_drop (menubar);
226 else
227 widget_move (&menubar->widget, 0,
228 ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x);
231 /* --------------------------------------------------------------------------------------------- */
233 static void
234 menubar_remove (WMenuBar * menubar)
236 if (menubar->is_dropped)
238 menubar->is_dropped = FALSE;
239 do_refresh ();
240 menubar->is_dropped = TRUE;
244 /* --------------------------------------------------------------------------------------------- */
246 static void
247 menubar_left (WMenuBar * menubar)
249 menubar_remove (menubar);
250 if (menubar->selected == 0)
251 menubar->selected = g_list_length (menubar->menu) - 1;
252 else
253 menubar->selected--;
254 menubar_draw (menubar);
257 /* --------------------------------------------------------------------------------------------- */
259 static void
260 menubar_right (WMenuBar * menubar)
262 menubar_remove (menubar);
263 menubar->selected = (menubar->selected + 1) % g_list_length (menubar->menu);
264 menubar_draw (menubar);
267 /* --------------------------------------------------------------------------------------------- */
269 static void
270 menubar_finish (WMenuBar * menubar)
272 menubar->is_dropped = FALSE;
273 menubar->is_active = FALSE;
274 menubar->widget.lines = 1;
275 widget_want_hotkey (menubar->widget, 0);
277 dlg_select_by_id (menubar->widget.owner, menubar->previous_widget);
278 do_refresh ();
281 /* --------------------------------------------------------------------------------------------- */
283 static void
284 menubar_drop (WMenuBar * menubar, unsigned int selected)
286 menubar->is_dropped = TRUE;
287 menubar->selected = selected;
288 menubar_draw (menubar);
291 /* --------------------------------------------------------------------------------------------- */
293 static void
294 menubar_execute (WMenuBar * menubar)
296 const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
297 const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected);
299 if ((entry != NULL) && (entry->command != CK_IgnoreKey))
301 mc_global.widget.is_right = (menubar->selected != 0);
302 menubar_finish (menubar);
303 menubar->widget.owner->callback (menubar->widget.owner, &menubar->widget,
304 DLG_ACTION, entry->command, NULL);
305 do_refresh ();
309 /* --------------------------------------------------------------------------------------------- */
311 static void
312 menubar_down (WMenuBar * menubar)
314 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
315 const unsigned int len = g_list_length (menu->entries);
316 menu_entry_t *entry;
318 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
322 menu->selected = (menu->selected + 1) % len;
323 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
325 while ((entry == NULL) || (entry->command == CK_IgnoreKey));
327 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
330 /* --------------------------------------------------------------------------------------------- */
332 static void
333 menubar_up (WMenuBar * menubar)
335 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
336 const unsigned int len = g_list_length (menu->entries);
337 menu_entry_t *entry;
339 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
343 if (menu->selected == 0)
344 menu->selected = len - 1;
345 else
346 menu->selected--;
347 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
349 while ((entry == NULL) || (entry->command == CK_IgnoreKey));
351 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
354 /* --------------------------------------------------------------------------------------------- */
356 static void
357 menubar_first (WMenuBar * menubar)
359 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
360 menu_entry_t *entry;
362 if (menu->selected == 0)
363 return;
365 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
367 menu->selected = 0;
369 while (TRUE)
371 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
373 if ((entry == NULL) || (entry->command == CK_IgnoreKey))
374 menu->selected++;
375 else
376 break;
379 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
382 /* --------------------------------------------------------------------------------------------- */
384 static void
385 menubar_last (WMenuBar * menubar)
387 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
388 const unsigned int len = g_list_length (menu->entries);
389 menu_entry_t *entry;
391 if (menu->selected == len - 1)
392 return;
394 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
396 menu->selected = len;
400 menu->selected--;
401 entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
403 while ((entry == NULL) || (entry->command == CK_IgnoreKey));
405 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
408 /* --------------------------------------------------------------------------------------------- */
410 static int
411 menubar_handle_key (WMenuBar * menubar, int key)
413 /* Lowercase */
414 if (isascii (key))
415 key = g_ascii_tolower (key);
417 if (is_abort_char (key))
419 menubar_finish (menubar);
420 return 1;
423 /* menubar help or menubar navigation */
424 switch (key)
426 case KEY_F (1):
428 ev_help_t event_data = { NULL, NULL };
430 if (menubar->is_dropped)
431 event_data.node =
432 ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->help_node;
433 else
434 event_data.node = "[Menu Bar]";
436 mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
437 menubar_draw (menubar);
438 return 1;
440 case KEY_LEFT:
441 case XCTRL ('b'):
442 menubar_left (menubar);
443 return 1;
445 case KEY_RIGHT:
446 case XCTRL ('f'):
447 menubar_right (menubar);
448 return 1;
451 if (!menubar->is_dropped)
453 GList *i;
455 /* drop menu by hotkey */
456 for (i = menubar->menu; i != NULL; i = g_list_next (i))
458 Menu *menu = i->data;
460 if ((menu->text.hotkey != NULL) && (key == g_ascii_tolower (menu->text.hotkey[0])))
462 menubar_drop (menubar, g_list_position (menubar->menu, i));
463 return 1;
467 /* drop menu by Enter or Dowwn key */
468 if (key == KEY_ENTER || key == XCTRL ('n') || key == KEY_DOWN || key == '\n')
469 menubar_drop (menubar, menubar->selected);
471 return 1;
475 Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
476 GList *i;
478 /* execute menu command by hotkey */
479 for (i = menu->entries; i != NULL; i = g_list_next (i))
481 const menu_entry_t *entry = i->data;
483 if ((entry != NULL) && (entry->command != CK_IgnoreKey)
484 && (entry->text.hotkey != NULL) && (key == g_ascii_tolower (entry->text.hotkey[0])))
486 menu->selected = g_list_position (menu->entries, i);
487 menubar_execute (menubar);
488 return 1;
492 /* menu execute by Enter or menu navigation */
493 switch (key)
495 case KEY_ENTER:
496 case '\n':
497 menubar_execute (menubar);
498 return 1;
500 case KEY_HOME:
501 case ALT ('<'):
502 menubar_first (menubar);
503 break;
505 case KEY_END:
506 case ALT ('>'):
507 menubar_last (menubar);
508 break;
510 case KEY_DOWN:
511 case XCTRL ('n'):
512 menubar_down (menubar);
513 break;
515 case KEY_UP:
516 case XCTRL ('p'):
517 menubar_up (menubar);
518 break;
522 return 0;
525 /* --------------------------------------------------------------------------------------------- */
527 static cb_ret_t
528 menubar_callback (Widget * w, widget_msg_t msg, int parm)
530 WMenuBar *menubar = (WMenuBar *) w;
532 switch (msg)
534 /* We do not want the focus unless we have been activated */
535 case WIDGET_FOCUS:
536 if (!menubar->is_active)
537 return MSG_NOT_HANDLED;
539 /* Trick to get all the mouse events */
540 menubar->widget.lines = LINES;
542 /* Trick to get all of the hotkeys */
543 widget_want_hotkey (menubar->widget, 1);
544 menubar_draw (menubar);
545 return MSG_HANDLED;
547 /* We don't want the buttonbar to activate while using the menubar */
548 case WIDGET_HOTKEY:
549 case WIDGET_KEY:
550 if (menubar->is_active)
552 menubar_handle_key (menubar, parm);
553 return MSG_HANDLED;
555 return MSG_NOT_HANDLED;
557 case WIDGET_CURSOR:
558 /* Put the cursor in a suitable place */
559 return MSG_NOT_HANDLED;
561 case WIDGET_UNFOCUS:
562 return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED;
564 case WIDGET_DRAW:
565 if (menubar->is_visible)
567 menubar_draw (menubar);
568 return MSG_HANDLED;
570 /* fall through */
572 case WIDGET_RESIZED:
573 /* try show menu after screen resize */
574 send_message (w, WIDGET_FOCUS, 0);
575 return MSG_HANDLED;
578 case WIDGET_DESTROY:
579 menubar_set_menu (menubar, NULL);
580 return MSG_HANDLED;
582 default:
583 return default_proc (msg, parm);
587 /* --------------------------------------------------------------------------------------------- */
589 static int
590 menubar_event (Gpm_Event * event, void *data)
592 WMenuBar *menubar = data;
593 gboolean was_active = TRUE;
594 int left_x, right_x, bottom_y;
595 Menu *menu;
597 /* ignore unsupported events */
598 if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0)
599 return MOU_NORMAL;
601 /* ignore wheel events if menu is inactive */
602 if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
603 return MOU_NORMAL;
605 if (!menubar->is_dropped)
607 menubar->previous_widget = dlg_get_current_widget_id (menubar->widget.owner);
608 menubar->is_active = TRUE;
609 menubar->is_dropped = TRUE;
610 was_active = FALSE;
613 /* Mouse operations on the menubar */
614 if (event->y == 1 || !was_active)
616 if ((event->type & GPM_UP) != 0)
617 return MOU_NORMAL;
619 /* wheel events on menubar */
620 if (event->buttons & GPM_B_UP)
621 menubar_left (menubar);
622 else if (event->buttons & GPM_B_DOWN)
623 menubar_right (menubar);
624 else
626 const unsigned int len = g_list_length (menubar->menu);
627 unsigned int new_selection = 0;
629 while ((new_selection < len)
630 && (event->x > ((Menu *) g_list_nth_data (menubar->menu,
631 new_selection))->start_x))
632 new_selection++;
634 if (new_selection != 0) /* Don't set the invalid value -1 */
635 new_selection--;
637 if (!was_active)
639 menubar->selected = new_selection;
640 dlg_select_widget (menubar);
642 else
644 menubar_remove (menubar);
645 menubar->selected = new_selection;
647 menubar_draw (menubar);
649 return MOU_NORMAL;
652 if (!menubar->is_dropped || (event->y < 2))
653 return MOU_NORMAL;
655 /* middle click -- everywhere */
656 if (((event->buttons & GPM_B_MIDDLE) != 0) && ((event->type & GPM_DOWN) != 0))
658 menubar_execute (menubar);
659 return MOU_NORMAL;
662 /* the mouse operation is on the menus or it is not */
663 menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected);
664 left_x = menu->start_x;
665 right_x = left_x + menu->max_entry_len + 3;
666 if (right_x > menubar->widget.cols)
668 left_x = menubar->widget.cols - menu->max_entry_len - 3;
669 right_x = menubar->widget.cols;
672 bottom_y = g_list_length (menu->entries) + 3;
674 if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y))
676 int pos = event->y - 3;
677 const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
679 /* mouse wheel */
680 if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
682 menubar_up (menubar);
683 return MOU_NORMAL;
685 if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
687 menubar_down (menubar);
688 return MOU_NORMAL;
691 /* ignore events above and below dropped down menu */
692 if ((pos < 0) || (pos >= bottom_y - 3))
693 return MOU_NORMAL;
695 if ((entry != NULL) && (entry->command != CK_IgnoreKey))
697 menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
698 menu->selected = pos;
699 menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
701 if ((event->type & GPM_UP) != 0)
702 menubar_execute (menubar);
705 else
706 /* use click not wheel to close menu */
707 if (((event->type & GPM_DOWN) != 0) && ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
708 menubar_finish (menubar);
710 return MOU_NORMAL;
713 /* --------------------------------------------------------------------------------------------- */
714 /*** public functions ****************************************************************************/
715 /* --------------------------------------------------------------------------------------------- */
717 menu_entry_t *
718 menu_entry_create (const char *name, unsigned long command)
720 menu_entry_t *entry;
722 entry = g_new (menu_entry_t, 1);
723 entry->first_letter = ' ';
724 entry->text = parse_hotkey (name);
725 entry->command = command;
726 entry->shortcut = NULL;
728 return entry;
731 /* --------------------------------------------------------------------------------------------- */
733 void
734 menu_entry_free (menu_entry_t * entry)
736 if (entry != NULL)
738 release_hotkey (entry->text);
739 g_free (entry->shortcut);
740 g_free (entry);
744 /* --------------------------------------------------------------------------------------------- */
746 Menu *
747 create_menu (const char *name, GList * entries, const char *help_node)
749 Menu *menu;
751 menu = g_new (Menu, 1);
752 menu->start_x = 0;
753 menu->text = parse_hotkey (name);
754 menu->entries = entries;
755 menu->max_entry_len = 1;
756 menu->max_hotkey_len = 0;
757 menu->selected = 0;
758 menu->help_node = g_strdup (help_node);
760 return menu;
763 /* --------------------------------------------------------------------------------------------- */
765 void
766 menu_set_name (Menu * menu, const char *name)
768 release_hotkey (menu->text);
769 menu->text = parse_hotkey (name);
772 /* --------------------------------------------------------------------------------------------- */
774 void
775 destroy_menu (Menu * menu)
777 release_hotkey (menu->text);
778 g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
779 g_list_free (menu->entries);
780 g_free (menu->help_node);
781 g_free (menu);
784 /* --------------------------------------------------------------------------------------------- */
786 WMenuBar *
787 menubar_new (int y, int x, int cols, GList * menu)
789 WMenuBar *menubar;
791 menubar = g_new0 (WMenuBar, 1);
792 init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event);
793 widget_want_cursor (menubar->widget, FALSE);
794 menubar->is_visible = TRUE; /* by default */
795 menubar_set_menu (menubar, menu);
797 return menubar;
800 /* --------------------------------------------------------------------------------------------- */
802 void
803 menubar_set_menu (WMenuBar * menubar, GList * menu)
805 /* delete previous menu */
806 if (menubar->menu != NULL)
808 g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
809 g_list_free (menubar->menu);
811 /* add new menu */
812 menubar->is_active = FALSE;
813 menubar->is_dropped = FALSE;
814 menubar->menu = menu;
815 menubar->selected = 0;
816 menubar_arrange (menubar);
819 /* --------------------------------------------------------------------------------------------- */
821 void
822 menubar_add_menu (WMenuBar * menubar, Menu * menu)
824 if (menu != NULL)
826 menu_arrange (menu, menubar->widget.owner->get_shortcut);
827 menubar->menu = g_list_append (menubar->menu, menu);
830 menubar_arrange (menubar);
833 /* --------------------------------------------------------------------------------------------- */
835 * Properly space menubar items. Should be called when menubar is created
836 * and also when widget width is changed (i.e. upon xterm resize).
839 void
840 menubar_arrange (WMenuBar * menubar)
842 int start_x = 1;
843 GList *i;
844 int gap;
846 if (menubar->menu == NULL)
847 return;
849 #ifndef RESIZABLE_MENUBAR
850 gap = 3;
852 for (i = menubar->menu; i != NULL; i = g_list_next (i))
854 Menu *menu = i->data;
855 int len = hotkey_width (menu->text) + 2;
857 menu->start_x = start_x;
858 start_x += len + gap;
860 #else /* RESIZABLE_MENUBAR */
861 gap = menubar->widget.cols - 2;
863 /* First, calculate gap between items... */
864 for (i = menubar->menu; i != NULL; i = g_list_next (i))
866 Menu *menu = i->data;
867 /* preserve length here, to be used below */
868 menu->start_x = hotkey_width (menu->text) + 2;
869 gap -= menu->start_x;
872 gap /= (menubar->menu->len - 1);
874 if (gap <= 0)
876 /* We are out of luck - window is too narrow... */
877 gap = 1;
880 /* ...and now fix start positions of menubar items */
881 for (i = menubar->menu; i != NULL; i = g_list_next (i))
883 Menu *menu = i->data;
884 int len = menu->start_x;
886 menu->start_x = start_x;
887 start_x += len + gap;
889 #endif /* RESIZABLE_MENUBAR */
892 /* --------------------------------------------------------------------------------------------- */
893 /** Find MenuBar widget in the dialog */
895 WMenuBar *
896 find_menubar (const Dlg_head * h)
898 return (WMenuBar *) find_widget_type (h, menubar_callback);
901 /* --------------------------------------------------------------------------------------------- */