4 Copyright (C) 1994-2016
5 Free Software Foundation, Inc.
8 Andrew Borodin <aborodin@vmail.ru>, 2012, 2013, 2016
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software: you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation, either version 3 of the License,
15 or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 * \brief Source: pulldown menu code
35 #include <sys/types.h>
37 #include "lib/global.h"
39 #include "lib/tty/tty.h"
41 #include "lib/tty/key.h" /* key macros */
42 #include "lib/strutil.h"
43 #include "lib/widget.h"
44 #include "lib/event.h" /* mc_event_raise() */
46 /*** global variables ****************************************************************************/
48 /*** file scope macro definitions ****************************************************************/
50 #define MENUENTRY(x) ((menu_entry_t *)(x))
51 #define MENU(x) ((menu_t *)(x))
53 /*** file scope type declarations ****************************************************************/
57 unsigned char first_letter
;
65 int start_x
; /* position relative to menubar start */
68 size_t max_entry_len
; /* cached max length of entry texts (text + shortcut) */
69 size_t max_hotkey_len
; /* cached max length of shortcuts */
70 unsigned int selected
; /* pointer to current menu entry */
74 /*** file scope variables ************************************************************************/
76 /*** file scope functions ************************************************************************/
77 /* --------------------------------------------------------------------------------------------- */
80 menu_arrange (menu_t
* menu
, dlg_shortcut_str get_shortcut
)
85 size_t max_shortcut_len
= 0;
87 menu
->max_entry_len
= 1;
88 menu
->max_hotkey_len
= 1;
90 for (i
= menu
->entries
; i
!= NULL
; i
= g_list_next (i
))
92 menu_entry_t
*entry
= MENUENTRY (i
->data
);
98 len
= (size_t) hotkey_width (entry
->text
);
99 menu
->max_hotkey_len
= max (menu
->max_hotkey_len
, len
);
101 if (get_shortcut
!= NULL
)
102 entry
->shortcut
= get_shortcut (entry
->command
);
104 if (entry
->shortcut
!= NULL
)
106 len
= (size_t) str_term_width1 (entry
->shortcut
);
107 max_shortcut_len
= max (max_shortcut_len
, len
);
112 menu
->max_entry_len
= menu
->max_hotkey_len
+ max_shortcut_len
;
116 /* --------------------------------------------------------------------------------------------- */
119 menubar_paint_idx (WMenuBar
* menubar
, unsigned int idx
, int color
)
121 Widget
*w
= WIDGET (menubar
);
122 const menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
123 const menu_entry_t
*entry
= MENUENTRY (g_list_nth_data (menu
->entries
, idx
));
124 const int y
= 2 + idx
;
125 int x
= menu
->start_x
;
127 if (x
+ menu
->max_entry_len
+ 4 > (gsize
) w
->cols
)
128 x
= w
->cols
- menu
->max_entry_len
- 4;
133 tty_setcolor (MENU_ENTRY_COLOR
);
135 widget_move (w
, y
, x
- 1);
136 tty_print_alt_char (ACS_LTEE
, FALSE
);
137 tty_draw_hline (w
->y
+ y
, w
->x
+ x
, ACS_HLINE
, menu
->max_entry_len
+ 3);
138 widget_move (w
, y
, x
+ menu
->max_entry_len
+ 3);
139 tty_print_alt_char (ACS_RTEE
, FALSE
);
146 tty_setcolor (color
);
147 widget_move (w
, y
, x
);
148 tty_print_char ((unsigned char) entry
->first_letter
);
149 tty_getyx (&yt
, &xt
);
150 tty_draw_hline (yt
, xt
, ' ', menu
->max_entry_len
+ 2); /* clear line */
151 tty_print_string (entry
->text
.start
);
153 if (entry
->text
.hotkey
!= NULL
)
155 tty_setcolor (color
== MENU_SELECTED_COLOR
? MENU_HOTSEL_COLOR
: MENU_HOT_COLOR
);
156 tty_print_string (entry
->text
.hotkey
);
157 tty_setcolor (color
);
160 if (entry
->text
.end
!= NULL
)
161 tty_print_string (entry
->text
.end
);
163 if (entry
->shortcut
!= NULL
)
165 widget_move (w
, y
, x
+ menu
->max_hotkey_len
+ 3);
166 tty_print_string (entry
->shortcut
);
169 /* move cursor to the start of entry text */
170 widget_move (w
, y
, x
+ 1);
174 /* --------------------------------------------------------------------------------------------- */
177 menubar_draw_drop (WMenuBar
* menubar
)
179 Widget
*w
= WIDGET (menubar
);
180 const menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
181 const unsigned int count
= g_list_length (menu
->entries
);
182 int column
= menu
->start_x
- 1;
185 if (column
+ menu
->max_entry_len
+ 5 > (gsize
) w
->cols
)
186 column
= w
->cols
- menu
->max_entry_len
- 5;
188 tty_setcolor (MENU_ENTRY_COLOR
);
189 tty_draw_box (w
->y
+ 1, w
->x
+ column
, count
+ 2, menu
->max_entry_len
+ 5, FALSE
);
191 for (i
= 0; i
< count
; i
++)
192 menubar_paint_idx (menubar
, i
,
193 i
== menu
->selected
? MENU_SELECTED_COLOR
: MENU_ENTRY_COLOR
);
196 /* --------------------------------------------------------------------------------------------- */
199 menubar_set_color (WMenuBar
* menubar
, gboolean current
, gboolean hotkey
)
201 if (!menubar
->is_active
)
202 tty_setcolor (MENU_INACTIVE_COLOR
);
204 tty_setcolor (hotkey
? MENU_HOTSEL_COLOR
: MENU_SELECTED_COLOR
);
206 tty_setcolor (hotkey
? MENU_HOT_COLOR
: MENU_ENTRY_COLOR
);
209 /* --------------------------------------------------------------------------------------------- */
212 menubar_draw (WMenuBar
* menubar
)
214 Widget
*w
= WIDGET (menubar
);
217 /* First draw the complete menubar */
218 tty_setcolor (menubar
->is_active
? MENU_ENTRY_COLOR
: MENU_INACTIVE_COLOR
);
219 tty_draw_hline (w
->y
, w
->x
, ' ', w
->cols
);
221 /* Now each one of the entries */
222 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
224 menu_t
*menu
= MENU (i
->data
);
225 gboolean is_selected
= (menubar
->selected
== (gsize
) g_list_position (menubar
->menu
, i
));
227 menubar_set_color (menubar
, is_selected
, FALSE
);
228 widget_move (w
, 0, menu
->start_x
);
230 tty_print_char (' ');
231 tty_print_string (menu
->text
.start
);
233 if (menu
->text
.hotkey
!= NULL
)
235 menubar_set_color (menubar
, is_selected
, TRUE
);
236 tty_print_string (menu
->text
.hotkey
);
237 menubar_set_color (menubar
, is_selected
, FALSE
);
240 if (menu
->text
.end
!= NULL
)
241 tty_print_string (menu
->text
.end
);
243 tty_print_char (' ');
246 if (menubar
->is_dropped
)
247 menubar_draw_drop (menubar
);
249 widget_move (w
, 0, MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
))->start_x
);
252 /* --------------------------------------------------------------------------------------------- */
255 menubar_remove (WMenuBar
* menubar
)
259 if (!menubar
->is_dropped
)
262 /* HACK: before refresh the dialog, change the current widget to keep the order
263 of overlapped widgets. This is useful in multi-window editor.
264 In general, menubar should be a special object, not an ordinary widget
265 in the current dialog. */
266 h
= WIDGET (menubar
)->owner
;
267 h
->current
= g_list_find (h
->widgets
, dlg_find_by_id (h
, menubar
->previous_widget
));
269 menubar
->is_dropped
= FALSE
;
271 menubar
->is_dropped
= TRUE
;
273 /* restore current widget */
274 h
->current
= g_list_find (h
->widgets
, menubar
);
277 /* --------------------------------------------------------------------------------------------- */
280 menubar_left (WMenuBar
* menubar
)
282 menubar_remove (menubar
);
283 if (menubar
->selected
== 0)
284 menubar
->selected
= g_list_length (menubar
->menu
) - 1;
287 menubar_draw (menubar
);
290 /* --------------------------------------------------------------------------------------------- */
293 menubar_right (WMenuBar
* menubar
)
295 menubar_remove (menubar
);
296 menubar
->selected
= (menubar
->selected
+ 1) % g_list_length (menubar
->menu
);
297 menubar_draw (menubar
);
300 /* --------------------------------------------------------------------------------------------- */
303 menubar_finish (WMenuBar
* menubar
)
305 Widget
*w
= WIDGET (menubar
);
307 menubar
->is_dropped
= FALSE
;
308 menubar
->is_active
= FALSE
;
310 widget_want_hotkey (w
, 0);
312 /* Move the menubar to the bottom so that widgets displayed on top of
313 * an "invisible" menubar get the first chance to respond to mouse events. */
314 dlg_set_bottom_widget (w
);
316 dlg_select_by_id (w
->owner
, menubar
->previous_widget
);
320 /* --------------------------------------------------------------------------------------------- */
323 menubar_drop (WMenuBar
* menubar
, unsigned int selected
)
325 menubar
->is_dropped
= TRUE
;
326 menubar
->selected
= selected
;
327 menubar_draw (menubar
);
330 /* --------------------------------------------------------------------------------------------- */
333 menubar_execute (WMenuBar
* menubar
)
335 const menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
336 const menu_entry_t
*entry
= MENUENTRY (g_list_nth_data (menu
->entries
, menu
->selected
));
338 if ((entry
!= NULL
) && (entry
->command
!= CK_IgnoreKey
))
340 Widget
*w
= WIDGET (menubar
);
342 mc_global
.widget
.is_right
= (menubar
->selected
!= 0);
343 menubar_finish (menubar
);
344 send_message (w
->owner
, w
, MSG_ACTION
, entry
->command
, NULL
);
349 /* --------------------------------------------------------------------------------------------- */
352 menubar_down (WMenuBar
* menubar
)
354 menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
355 const unsigned int len
= g_list_length (menu
->entries
);
358 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
362 menu
->selected
= (menu
->selected
+ 1) % len
;
363 entry
= MENUENTRY (g_list_nth_data (menu
->entries
, menu
->selected
));
365 while ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
));
367 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
370 /* --------------------------------------------------------------------------------------------- */
373 menubar_up (WMenuBar
* menubar
)
375 menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
376 const unsigned int len
= g_list_length (menu
->entries
);
379 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
383 if (menu
->selected
== 0)
384 menu
->selected
= len
- 1;
387 entry
= MENUENTRY (g_list_nth_data (menu
->entries
, menu
->selected
));
389 while ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
));
391 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
394 /* --------------------------------------------------------------------------------------------- */
397 menubar_first (WMenuBar
* menubar
)
399 menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
401 if (menu
->selected
== 0)
404 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
412 entry
= MENUENTRY (g_list_nth_data (menu
->entries
, menu
->selected
));
414 if ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
))
420 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
423 /* --------------------------------------------------------------------------------------------- */
426 menubar_last (WMenuBar
* menubar
)
428 menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
429 const unsigned int len
= g_list_length (menu
->entries
);
432 if (menu
->selected
== len
- 1)
435 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
437 menu
->selected
= len
;
442 entry
= MENUENTRY (g_list_nth_data (menu
->entries
, menu
->selected
));
444 while ((entry
== NULL
) || (entry
->command
== CK_IgnoreKey
));
446 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
449 /* --------------------------------------------------------------------------------------------- */
452 menubar_handle_key (WMenuBar
* menubar
, int key
)
456 key
= g_ascii_tolower (key
);
458 if (is_abort_char (key
))
460 menubar_finish (menubar
);
464 /* menubar help or menubar navigation */
469 ev_help_t event_data
= { NULL
, NULL
};
471 if (menubar
->is_dropped
)
473 MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
))->help_node
;
475 event_data
.node
= "[Menu Bar]";
477 mc_event_raise (MCEVENT_GROUP_CORE
, "help", &event_data
);
478 menubar_draw (menubar
);
484 menubar_left (menubar
);
489 menubar_right (menubar
);
496 if (!menubar
->is_dropped
)
500 /* drop menu by hotkey */
501 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
503 menu_t
*menu
= MENU (i
->data
);
505 if ((menu
->text
.hotkey
!= NULL
) && (key
== g_ascii_tolower (menu
->text
.hotkey
[0])))
507 menubar_drop (menubar
, g_list_position (menubar
->menu
, i
));
512 /* drop menu by Enter or Dowwn key */
513 if (key
== KEY_ENTER
|| key
== XCTRL ('n') || key
== KEY_DOWN
|| key
== '\n')
514 menubar_drop (menubar
, menubar
->selected
);
520 menu_t
*menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
523 /* execute menu command by hotkey */
524 for (i
= menu
->entries
; i
!= NULL
; i
= g_list_next (i
))
526 const menu_entry_t
*entry
= MENUENTRY (i
->data
);
528 if ((entry
!= NULL
) && (entry
->command
!= CK_IgnoreKey
)
529 && (entry
->text
.hotkey
!= NULL
) && (key
== g_ascii_tolower (entry
->text
.hotkey
[0])))
531 menu
->selected
= g_list_position (menu
->entries
, i
);
532 menubar_execute (menubar
);
537 /* menu execute by Enter or menu navigation */
542 menubar_execute (menubar
);
547 menubar_first (menubar
);
552 menubar_last (menubar
);
557 menubar_down (menubar
);
562 menubar_up (menubar
);
573 /* --------------------------------------------------------------------------------------------- */
576 menubar_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
578 WMenuBar
*menubar
= MENUBAR (w
);
582 /* We do not want the focus unless we have been activated */
584 if (!menubar
->is_active
)
585 return MSG_NOT_HANDLED
;
587 /* Trick to get all the mouse events */
590 /* Trick to get all of the hotkeys */
591 widget_want_hotkey (w
, 1);
592 menubar_draw (menubar
);
595 /* We don't want the buttonbar to activate while using the menubar */
598 if (menubar
->is_active
)
600 menubar_handle_key (menubar
, parm
);
603 return MSG_NOT_HANDLED
;
606 /* Put the cursor in a suitable place */
607 return MSG_NOT_HANDLED
;
610 return menubar
->is_active
? MSG_NOT_HANDLED
: MSG_HANDLED
;
613 if (menubar
->is_visible
)
615 menubar_draw (menubar
);
621 /* try show menu after screen resize */
622 send_message (w
, sender
, MSG_FOCUS
, 0, data
);
627 menubar_set_menu (menubar
, NULL
);
631 return widget_default_callback (w
, sender
, msg
, parm
, data
);
635 /* --------------------------------------------------------------------------------------------- */
638 menubar_get_menu_by_x_coord (const WMenuBar
* menubar
, int x
)
643 for (i
= 0, menu
= menubar
->menu
;
644 menu
!= NULL
&& x
> MENU (menu
->data
)->start_x
; i
++, menu
= g_list_next (menu
))
647 /* Don't set the invalid value -1 */
654 /* --------------------------------------------------------------------------------------------- */
657 menubar_mouse_on_menu (const WMenuBar
* menubar
, int y
, int x
)
659 Widget
*w
= WIDGET (menubar
);
661 int left_x
, right_x
, bottom_y
;
663 if (!menubar
->is_dropped
)
666 menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
667 left_x
= menu
->start_x
;
668 right_x
= left_x
+ menu
->max_entry_len
+ 3;
669 if (right_x
> w
->cols
)
671 left_x
= w
->cols
- (menu
->max_entry_len
+ 3);
675 bottom_y
= g_list_length (menu
->entries
) + 2; /* skip bar and top frame */
677 return (x
>= left_x
&& x
< right_x
&& y
> 1 && y
< bottom_y
);
680 /* --------------------------------------------------------------------------------------------- */
683 menubar_change_selected_item (WMenuBar
* menubar
, int y
)
688 y
-= 2; /* skip bar and top frame */
689 menu
= MENU (g_list_nth_data (menubar
->menu
, menubar
->selected
));
690 entry
= MENUENTRY (g_list_nth_data (menu
->entries
, y
));
692 if (entry
!= NULL
&& entry
->command
!= CK_IgnoreKey
)
694 menubar_paint_idx (menubar
, menu
->selected
, MENU_ENTRY_COLOR
);
696 menubar_paint_idx (menubar
, menu
->selected
, MENU_SELECTED_COLOR
);
700 /* --------------------------------------------------------------------------------------------- */
703 menubar_mouse_callback (Widget
* w
, mouse_msg_t msg
, mouse_event_t
* event
)
705 static gboolean was_drag
= FALSE
;
707 WMenuBar
*menubar
= MENUBAR (w
);
708 gboolean mouse_on_drop
;
710 mouse_on_drop
= menubar_mouse_on_menu (menubar
, event
->y
, event
->x
);
719 /* events on menubar */
720 unsigned int selected
;
722 selected
= menubar_get_menu_by_x_coord (menubar
, event
->x
);
723 menubar_activate (menubar
, TRUE
, selected
);
724 menubar_remove (menubar
); /* if already shown */
725 menubar_drop (menubar
, selected
);
727 else if (mouse_on_drop
)
728 menubar_change_selected_item (menubar
, event
->y
);
731 /* mouse click outside menubar or dropdown -- close menu */
732 menubar_finish (menubar
);
737 * Unless we clear the 'capture' flag, we'll receive MSG_MOUSE_DRAG
738 * events belonging to this click (in case the user drags the mouse,
741 * For the time being, we mark this with FIXME as this flag should
742 * preferably be regarded as "implementation detail" and not be
743 * touched by us. We should think of some other way of communicating
744 * this to the system.
746 w
->mouse
.capture
= FALSE
;
751 if (was_drag
&& mouse_on_drop
)
752 menubar_execute (menubar
);
756 case MSG_MOUSE_CLICK
:
759 if ((event
->buttons
& GPM_B_MIDDLE
) != 0 && event
->y
> 0 && menubar
->is_dropped
)
761 /* middle click -- everywhere */
762 menubar_execute (menubar
);
764 else if (mouse_on_drop
)
765 menubar_execute (menubar
);
766 else if (event
->y
> 0)
767 /* releasing the mouse button outside the menu -- close menu */
768 menubar_finish (menubar
);
774 menubar_remove (menubar
);
775 menubar_drop (menubar
, menubar_get_menu_by_x_coord (menubar
, event
->x
));
777 else if (mouse_on_drop
)
778 menubar_change_selected_item (menubar
, event
->y
);
783 case MSG_MOUSE_SCROLL_UP
:
784 case MSG_MOUSE_SCROLL_DOWN
:
787 if (menubar
->is_active
)
791 /* menubar: left/right */
792 if (msg
== MSG_MOUSE_SCROLL_UP
)
793 menubar_left (menubar
);
795 menubar_right (menubar
);
797 else if (mouse_on_drop
)
799 /* drop-down menu: up/down */
800 if (msg
== MSG_MOUSE_SCROLL_UP
)
801 menubar_up (menubar
);
803 menubar_down (menubar
);
814 /* --------------------------------------------------------------------------------------------- */
815 /*** public functions ****************************************************************************/
816 /* --------------------------------------------------------------------------------------------- */
819 menu_entry_create (const char *name
, long command
)
823 entry
= g_new (menu_entry_t
, 1);
824 entry
->first_letter
= ' ';
825 entry
->text
= parse_hotkey (name
);
826 entry
->command
= command
;
827 entry
->shortcut
= NULL
;
832 /* --------------------------------------------------------------------------------------------- */
835 menu_entry_free (menu_entry_t
* entry
)
839 release_hotkey (entry
->text
);
840 g_free (entry
->shortcut
);
845 /* --------------------------------------------------------------------------------------------- */
848 create_menu (const char *name
, GList
* entries
, const char *help_node
)
852 menu
= g_new (menu_t
, 1);
854 menu
->text
= parse_hotkey (name
);
855 menu
->entries
= entries
;
856 menu
->max_entry_len
= 1;
857 menu
->max_hotkey_len
= 0;
859 menu
->help_node
= g_strdup (help_node
);
864 /* --------------------------------------------------------------------------------------------- */
867 menu_set_name (menu_t
* menu
, const char *name
)
869 release_hotkey (menu
->text
);
870 menu
->text
= parse_hotkey (name
);
873 /* --------------------------------------------------------------------------------------------- */
876 destroy_menu (menu_t
* menu
)
878 release_hotkey (menu
->text
);
879 g_list_free_full (menu
->entries
, (GDestroyNotify
) menu_entry_free
);
880 g_free (menu
->help_node
);
884 /* --------------------------------------------------------------------------------------------- */
887 menubar_new (int y
, int x
, int cols
, GList
* menu
, gboolean visible
)
892 menubar
= g_new0 (WMenuBar
, 1);
893 w
= WIDGET (menubar
);
894 widget_init (w
, y
, x
, 1, cols
, menubar_callback
, menubar_mouse_callback
);
896 menubar
->is_visible
= visible
;
897 widget_want_cursor (w
, FALSE
);
898 menubar_set_menu (menubar
, menu
);
903 /* --------------------------------------------------------------------------------------------- */
906 menubar_set_menu (WMenuBar
* menubar
, GList
* menu
)
908 /* delete previous menu */
909 if (menubar
->menu
!= NULL
)
910 g_list_free_full (menubar
->menu
, (GDestroyNotify
) destroy_menu
);
913 menubar
->is_active
= FALSE
;
914 menubar
->is_dropped
= FALSE
;
915 menubar
->menu
= menu
;
916 menubar
->selected
= 0;
917 menubar_arrange (menubar
);
920 /* --------------------------------------------------------------------------------------------- */
923 menubar_add_menu (WMenuBar
* menubar
, menu_t
* menu
)
927 menu_arrange (menu
, WIDGET (menubar
)->owner
->get_shortcut
);
928 menubar
->menu
= g_list_append (menubar
->menu
, menu
);
931 menubar_arrange (menubar
);
934 /* --------------------------------------------------------------------------------------------- */
936 * Properly space menubar items. Should be called when menubar is created
937 * and also when widget width is changed (i.e. upon xterm resize).
941 menubar_arrange (WMenuBar
* menubar
)
947 if (menubar
->menu
== NULL
)
950 gap
= WIDGET (menubar
)->cols
- 2;
952 /* First, calculate gap between items... */
953 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
955 menu_t
*menu
= MENU (i
->data
);
957 /* preserve length here, to be used below */
958 menu
->start_x
= hotkey_width (menu
->text
) + 2;
959 gap
-= menu
->start_x
;
962 if (g_list_next (menubar
->menu
) == NULL
)
965 gap
/= (g_list_length (menubar
->menu
) - 1);
969 /* We are out of luck - window is too narrow... */
975 /* ...and now fix start positions of menubar items */
976 for (i
= menubar
->menu
; i
!= NULL
; i
= g_list_next (i
))
978 menu_t
*menu
= MENU (i
->data
);
979 int len
= menu
->start_x
;
981 menu
->start_x
= start_x
;
982 start_x
+= len
+ gap
;
986 /* --------------------------------------------------------------------------------------------- */
987 /** Find MenuBar widget in the dialog */
990 find_menubar (const WDialog
* h
)
992 return MENUBAR (find_widget_type (h
, menubar_callback
));
995 /* --------------------------------------------------------------------------------------------- */
1000 * @param menubar menu bar object
1001 * @param dropped whether dropdown menus should be drooped or not
1002 * @which number of active dropdown menu
1005 menubar_activate (WMenuBar
* menubar
, gboolean dropped
, int which
)
1007 Widget
*w
= WIDGET (menubar
);
1009 if (!menubar
->is_active
)
1011 menubar
->is_active
= TRUE
;
1012 menubar
->is_dropped
= dropped
;
1014 menubar
->selected
= (guint
) which
;
1016 menubar
->previous_widget
= dlg_get_current_widget_id (w
->owner
);
1018 /* Bring it to the top so it receives all mouse events before any other widget.
1019 * See also comment in menubar_finish(). */
1020 dlg_set_top_widget (w
);
1024 /* --------------------------------------------------------------------------------------------- */