2009-05-04 20:11:51 +04:00
|
|
|
/* Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
|
|
|
2007, 2009 Free Software Foundation, Inc.
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2009-05-04 20:11:51 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file menu.c
|
|
|
|
* \brief Source: pulldown menu code
|
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdarg.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <string.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <sys/types.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
#include "global.h"
|
2009-05-09 19:17:57 +04:00
|
|
|
|
2009-05-08 14:01:05 +04:00
|
|
|
#include "../src/tty/tty.h"
|
2009-09-04 18:22:49 +04:00
|
|
|
#include "../src/skin/skin.h"
|
2009-05-09 19:17:57 +04:00
|
|
|
#include "../src/tty/mouse.h"
|
2009-05-26 19:01:58 +04:00
|
|
|
#include "../src/tty/key.h" /* key macros */
|
2009-05-09 19:17:57 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "menu.h"
|
2001-08-07 02:22:04 +04:00
|
|
|
#include "help.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "dialog.h"
|
2009-08-16 12:11:59 +04:00
|
|
|
#include "widget.h"
|
2009-07-12 14:22:41 +04:00
|
|
|
#include "main.h" /* is_right */
|
2008-12-29 01:57:59 +03:00
|
|
|
#include "strutil.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
int menubar_visible = 1; /* This is the new default */
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
menu_entry_t *
|
2009-10-01 22:23:50 +04:00
|
|
|
menu_entry_create (const char *name, int command)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
menu_entry_t *entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
entry = g_new (menu_entry_t, 1);
|
|
|
|
entry->first_letter = ' ';
|
|
|
|
entry->text = parse_hotkey (name);
|
2009-10-01 22:23:50 +04:00
|
|
|
entry->command = command;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
void
|
|
|
|
menu_entry_free (menu_entry_t *entry)
|
|
|
|
{
|
|
|
|
if (entry != NULL) {
|
|
|
|
release_hotkey (entry->text);
|
|
|
|
g_free (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-25 13:08:18 +04:00
|
|
|
menu_arrange (Menu *menu)
|
2009-05-04 20:11:51 +04:00
|
|
|
{
|
|
|
|
if (menu != NULL) {
|
2009-08-25 13:08:18 +04:00
|
|
|
GList *i;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
for (i = menu->entries; i != NULL; i = g_list_next (i)) {
|
|
|
|
menu_entry_t *entry = i->data;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
if (entry != NULL) {
|
2009-08-25 13:08:18 +04:00
|
|
|
const size_t len = (size_t) hotkey_width (entry->text);
|
2009-05-04 20:11:51 +04:00
|
|
|
menu->max_entry_len = max (menu->max_entry_len, len);
|
1999-08-01 15:37:25 +04:00
|
|
|
}
|
Fri Apr 3 05:23:20 1998 Alex Tkachenko <alex@bcs.zp.ua>
* configure.in: ALL_LINGUAS test added, to allow specify list
of languages to be installed by setting env variable before
configure. If it is empty, it defaults to full list.
* src/menu.h menu_entry.{hot_pos, is_dupped} dropped
* src/menu.c: consistency fixes: pull-down menu items are now
accessible either with arrow keys or with hotkeys, denoted with &
(and highlighted). (key combinations, placed to the right of items
intended to be used from outside the menus). Freeing menu entries
removed as it no longer needed
* src/main.c, edit/editmenu.c: menubar init code is changed to conform
above fixes.
* edit/edit.h: use of "Cancel" in error_dialogs replaced with
"Dismiss", to avoid collisions in translation of "Cancel" in other
places with this case.
* src/boxes.c: select_format() and it's support removed, as it is
obsoleted by input line history feature. display_init()/display_callback
fixed to suite i18n changes. sort_box() - alike.
* src/option.c: pause_options added &'s and gettext calls to expand
statically assigned values.
* src/widget.c: (radio_callback) hotkey recognition is changed to
&-notation, rather than simple uppercase.
* src/dlg.c: (dlg_try_hotkey) plain symbol comparison replaced with
call to isalpha(), this fixes errorneous exit from input line, when
button hotkey is 8-bit NLS char.
1998-04-04 00:00:00 +04:00
|
|
|
}
|
1999-08-01 15:37:25 +04:00
|
|
|
}
|
2009-05-04 20:11:51 +04:00
|
|
|
}
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
Menu *
|
2009-08-25 13:08:18 +04:00
|
|
|
create_menu (const char *name, GList *entries, const char *help_node)
|
2009-05-04 20:11:51 +04:00
|
|
|
{
|
|
|
|
Menu *menu;
|
|
|
|
|
|
|
|
menu = g_new (Menu, 1);
|
1998-06-08 04:33:31 +04:00
|
|
|
menu->start_x = 0;
|
2009-05-04 20:11:51 +04:00
|
|
|
menu->text = parse_hotkey (name);
|
|
|
|
menu->entries = entries;
|
|
|
|
menu->max_entry_len = 1;
|
|
|
|
menu->selected = 0;
|
2009-02-06 01:40:32 +03:00
|
|
|
menu->help_node = g_strdup (help_node);
|
2009-05-04 20:11:51 +04:00
|
|
|
menu_arrange (menu);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
void
|
|
|
|
destroy_menu (Menu *menu)
|
|
|
|
{
|
|
|
|
release_hotkey (menu->text);
|
2009-08-25 13:08:18 +04:00
|
|
|
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
|
|
|
g_list_free (menu->entries);
|
2009-05-04 20:11:51 +04:00
|
|
|
g_free (menu->help_node);
|
|
|
|
g_free (menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
|
|
|
const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
|
1998-02-27 07:54:42 +03:00
|
|
|
const int y = 2 + idx;
|
2008-12-29 01:57:59 +03:00
|
|
|
int x = menu->start_x;
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (x + menu->max_entry_len + 3 > menubar->widget.cols)
|
|
|
|
x = menubar->widget.cols - menu->max_entry_len - 3;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (entry == NULL) {
|
|
|
|
/* menu separator */
|
|
|
|
tty_setcolor (MENU_ENTRY_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
widget_move (&menubar->widget, y, x - 1);
|
|
|
|
tty_print_alt_char (ACS_LTEE);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
|
|
|
|
ACS_HLINE, menu->max_entry_len + 2);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
widget_move (&menubar->widget, y, x + menu->max_entry_len + 2);
|
|
|
|
tty_print_alt_char (ACS_RTEE);
|
2009-04-26 18:22:53 +04:00
|
|
|
} else {
|
2009-05-04 20:11:51 +04:00
|
|
|
/* menu text */
|
|
|
|
tty_setcolor (color);
|
|
|
|
widget_move (&menubar->widget, y, x);
|
|
|
|
tty_print_char ((unsigned char) entry->first_letter);
|
|
|
|
tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 1); /* clear line */
|
|
|
|
tty_print_string (entry->text.start);
|
|
|
|
|
|
|
|
if (entry->text.hotkey != NULL) {
|
|
|
|
tty_setcolor (color == MENU_SELECTED_COLOR ?
|
|
|
|
MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
|
|
|
|
tty_print_string (entry->text.hotkey);
|
|
|
|
tty_setcolor (color);
|
|
|
|
}
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (entry->text.end != NULL)
|
|
|
|
tty_print_string (entry->text.end);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
/* move cursor to the start of entry text */
|
|
|
|
widget_move (&menubar->widget, y, x + 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_draw_drop (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
|
|
|
const unsigned int count = g_list_length (menu->entries);
|
2009-05-04 20:11:51 +04:00
|
|
|
int column = menu->start_x - 1;
|
|
|
|
unsigned int i;
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (column + menu->max_entry_len + 4 > menubar->widget.cols)
|
|
|
|
column = menubar->widget.cols - menu->max_entry_len - 4;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-08-26 13:19:44 +04:00
|
|
|
tty_setcolor (MENU_ENTRY_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
draw_box (menubar->widget.parent,
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->widget.y + 1, menubar->widget.x + column,
|
|
|
|
count + 2, menu->max_entry_len + 4);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
|
|
|
/* draw items except selected */
|
|
|
|
for (i = 0; i < count; i++)
|
2009-05-04 20:11:51 +04:00
|
|
|
if (i != menu->selected)
|
|
|
|
menubar_paint_idx (menubar, i, MENU_ENTRY_COLOR);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
/* draw selected item at last to move cursor to the nice location */
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_set_color (WMenuBar *menubar, gboolean current, gboolean hotkey)
|
2009-08-26 13:19:44 +04:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
if (!menubar->is_active)
|
2009-08-26 13:19:44 +04:00
|
|
|
tty_setcolor (hotkey ? COLOR_HOT_FOCUS : SELECTED_COLOR);
|
2009-08-25 13:08:18 +04:00
|
|
|
else if (current)
|
2009-08-26 13:19:44 +04:00
|
|
|
tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR);
|
|
|
|
else
|
|
|
|
tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR);
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_draw (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
GList *i;
|
2009-04-26 18:22:53 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* First draw the complete menubar */
|
2009-05-04 20:11:51 +04:00
|
|
|
tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : SELECTED_COLOR);
|
2009-06-03 23:07:06 +04:00
|
|
|
tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Now each one of the entries */
|
2009-08-25 13:08:18 +04:00
|
|
|
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
|
|
|
|
Menu *menu = i->data;
|
|
|
|
gboolean is_selected = (menubar->selected == g_list_position (menubar->menu, i));
|
2009-05-04 20:11:51 +04:00
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_set_color (menubar, is_selected, FALSE);
|
2009-05-04 20:11:51 +04:00
|
|
|
widget_move (&menubar->widget, 0, menu->start_x);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
tty_print_string (menu->text.start);
|
2009-04-26 18:22:53 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (menu->text.hotkey != NULL) {
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_set_color (menubar, is_selected, TRUE);
|
2009-05-04 20:11:51 +04:00
|
|
|
tty_print_string (menu->text.hotkey);
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_set_color (menubar, is_selected, FALSE);
|
2009-05-04 20:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (menu->text.end != NULL)
|
|
|
|
tty_print_string (menu->text.end);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (menubar->is_dropped)
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_draw_drop (menubar);
|
2009-04-26 18:22:53 +04:00
|
|
|
else
|
|
|
|
widget_move (&menubar->widget, 0,
|
2009-08-25 13:08:18 +04:00
|
|
|
((Menu *) g_list_nth_data (menubar->menu,
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->selected))->start_x);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_remove (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
if (menubar->is_dropped) {
|
|
|
|
menubar->is_dropped = FALSE;
|
1998-02-27 07:54:42 +03:00
|
|
|
do_refresh ();
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->is_dropped = TRUE;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_left (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_remove (menubar);
|
|
|
|
if (menubar->selected == 0)
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar->selected = g_list_length (menubar->menu) - 1;
|
2009-05-04 20:11:51 +04:00
|
|
|
else
|
|
|
|
menubar->selected--;
|
|
|
|
menubar_draw (menubar);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_right (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_remove (menubar);
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar->selected = (menubar->selected + 1) % g_list_length (menubar->menu);
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_draw (menubar);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2003-09-13 02:45:51 +04:00
|
|
|
static void
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_finish (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->is_dropped = FALSE;
|
|
|
|
menubar->is_active = FALSE;
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar->widget.lines = 1;
|
|
|
|
widget_want_hotkey (menubar->widget, 0);
|
2003-09-13 11:43:20 +04:00
|
|
|
|
|
|
|
dlg_select_by_id (menubar->widget.parent, menubar->previous_widget);
|
1998-02-27 07:54:42 +03:00
|
|
|
do_refresh ();
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_drop (WMenuBar *menubar, unsigned int selected)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->is_dropped = TRUE;
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar->selected = selected;
|
|
|
|
menubar_draw (menubar);
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
2009-09-19 14:45:40 +04:00
|
|
|
menubar_execute (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
2009-09-19 14:45:40 +04:00
|
|
|
const menu_entry_t *entry = g_list_nth_data (menu->entries, menu->selected);
|
2009-05-04 20:11:51 +04:00
|
|
|
|
2009-10-01 22:23:50 +04:00
|
|
|
if ((entry != NULL) && (entry->command != 0)) {
|
|
|
|
is_right = (menubar->selected != 0);
|
|
|
|
menubar_finish (menubar);
|
|
|
|
menubar->widget.parent->menu_executor (entry->command);
|
|
|
|
do_refresh ();
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_down (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
|
|
|
const unsigned int len = g_list_length (menu->entries);
|
2009-05-04 20:11:51 +04:00
|
|
|
menu_entry_t *entry;
|
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
do {
|
2009-08-25 13:08:18 +04:00
|
|
|
menu->selected = (menu->selected + 1) % len;
|
|
|
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
2009-10-01 22:23:50 +04:00
|
|
|
} while ((entry == NULL) || (entry->command == 0));
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static void
|
|
|
|
menubar_up (WMenuBar *menubar)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
|
|
|
const unsigned int len = g_list_length (menu->entries);
|
2009-05-04 20:11:51 +04:00
|
|
|
menu_entry_t *entry;
|
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
do {
|
|
|
|
if (menu->selected == 0)
|
2009-08-25 13:08:18 +04:00
|
|
|
menu->selected = len - 1;
|
2009-05-04 20:11:51 +04:00
|
|
|
else
|
|
|
|
menu->selected--;
|
2009-08-25 13:08:18 +04:00
|
|
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
2009-10-01 22:23:50 +04:00
|
|
|
} while ((entry == NULL) || (entry->command == 0));
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:03 +04:00
|
|
|
static void
|
|
|
|
menubar_first (WMenuBar *menubar)
|
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
2009-07-19 13:21:03 +04:00
|
|
|
menu_entry_t *entry;
|
|
|
|
|
|
|
|
if (menu->selected == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
|
|
|
|
|
|
|
menu->selected = 0;
|
|
|
|
|
|
|
|
while (TRUE) {
|
2009-08-25 13:08:18 +04:00
|
|
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
2009-07-19 13:21:03 +04:00
|
|
|
|
2009-10-01 22:23:50 +04:00
|
|
|
if ((entry == NULL) || (entry->command == 0))
|
2009-07-19 13:21:03 +04:00
|
|
|
menu->selected++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menubar_last (WMenuBar *menubar)
|
|
|
|
{
|
2009-08-25 13:08:18 +04:00
|
|
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
|
|
|
const unsigned int len = g_list_length (menu->entries);
|
2009-07-19 13:21:03 +04:00
|
|
|
menu_entry_t *entry;
|
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
if (menu->selected == len - 1)
|
2009-07-19 13:21:03 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
menu->selected = len;
|
2009-07-19 13:21:03 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
menu->selected--;
|
2009-08-25 13:08:18 +04:00
|
|
|
entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
|
2009-10-01 22:23:50 +04:00
|
|
|
} while ((entry == NULL) || (entry->command == 0));
|
2009-07-19 13:21:03 +04:00
|
|
|
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
static int
|
|
|
|
menubar_handle_key (WMenuBar *menubar, int key)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Lowercase */
|
2009-05-04 20:11:51 +04:00
|
|
|
if (isascii (key))
|
|
|
|
key = g_ascii_tolower (key);
|
|
|
|
|
|
|
|
if (is_abort_char (key)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_finish (menubar);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
/* menubar help or menubar navigation */
|
|
|
|
switch (key) {
|
|
|
|
case KEY_F(1):
|
|
|
|
if (menubar->is_dropped)
|
2002-08-21 01:30:06 +04:00
|
|
|
interactive_display (NULL,
|
2009-08-25 13:08:18 +04:00
|
|
|
((Menu *) g_list_nth_data (menubar->menu,
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->selected))->help_node);
|
|
|
|
else
|
2001-08-07 02:22:04 +04:00
|
|
|
interactive_display (NULL, "[Menu Bar]");
|
|
|
|
menubar_draw (menubar);
|
|
|
|
return 1;
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
case KEY_LEFT:
|
|
|
|
case XCTRL('b'):
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_left (menubar);
|
|
|
|
return 1;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case XCTRL ('f'):
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_right (menubar);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (!menubar->is_dropped) {
|
2009-08-25 13:08:18 +04:00
|
|
|
GList *i;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
/* drop menu by hotkey */
|
2009-08-25 13:08:18 +04:00
|
|
|
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
|
|
|
|
Menu *menu = i->data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if ((menu->text.hotkey != NULL)
|
|
|
|
&& (key == g_ascii_tolower (menu->text.hotkey[0]))) {
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_drop (menubar, g_list_position (menubar->menu, i));
|
2009-05-04 20:11:51 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
2009-09-07 14:28:07 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
/* drop menu by Enter or Dowwn key */
|
|
|
|
if (key == KEY_ENTER || key == XCTRL ('n')
|
|
|
|
|| key == KEY_DOWN || key == '\n')
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_drop (menubar, menubar->selected);
|
2009-05-04 20:11:51 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
2009-05-04 20:11:51 +04:00
|
|
|
}
|
2009-09-07 14:28:07 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
{
|
2009-09-19 14:45:40 +04:00
|
|
|
Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
|
2009-08-25 13:08:18 +04:00
|
|
|
GList *i;
|
2009-09-07 14:28:07 +04:00
|
|
|
|
2009-10-01 22:23:50 +04:00
|
|
|
/* execute menu command by hotkey */
|
2009-09-19 14:45:40 +04:00
|
|
|
for (i = menu->entries; i != NULL; i = g_list_next (i)) {
|
2009-08-25 13:08:18 +04:00
|
|
|
const menu_entry_t *entry = i->data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-10-01 22:23:50 +04:00
|
|
|
if ((entry != NULL) && (entry->command != 0)
|
2009-05-04 20:11:51 +04:00
|
|
|
&& (entry->text.hotkey != NULL)
|
|
|
|
&& (key == g_ascii_tolower (entry->text.hotkey[0]))) {
|
2009-09-19 14:45:40 +04:00
|
|
|
menu->selected = g_list_position (menu->entries, i);
|
|
|
|
menubar_execute (menubar);
|
2009-05-04 20:11:51 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* menu execute by Enter or menu navigation */
|
|
|
|
switch (key) {
|
|
|
|
case KEY_ENTER:
|
|
|
|
case '\n':
|
2009-09-19 14:45:40 +04:00
|
|
|
menubar_execute (menubar);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
2009-07-19 13:21:03 +04:00
|
|
|
case KEY_HOME:
|
|
|
|
case ALT ('<'):
|
|
|
|
menubar_first (menubar);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_END:
|
|
|
|
case ALT ('>'):
|
|
|
|
menubar_last (menubar);
|
|
|
|
break;
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
case KEY_DOWN:
|
|
|
|
case XCTRL ('n'):
|
|
|
|
menubar_down (menubar);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_UP:
|
|
|
|
case XCTRL ('p'):
|
|
|
|
menubar_up (menubar);
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
2009-05-04 20:11:51 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
static cb_ret_t
|
2005-05-23 20:39:52 +04:00
|
|
|
menubar_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
WMenuBar *menubar = (WMenuBar *) w;
|
2005-05-23 20:39:52 +04:00
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
/* We do not want the focus unless we have been activated */
|
|
|
|
case WIDGET_FOCUS:
|
2009-05-04 20:11:51 +04:00
|
|
|
if (!menubar->is_active)
|
2003-09-11 02:48:54 +04:00
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
widget_want_cursor (menubar->widget, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
/* Trick to get all the mouse events */
|
|
|
|
menubar->widget.lines = LINES;
|
|
|
|
|
|
|
|
/* Trick to get all of the hotkeys */
|
|
|
|
widget_want_hotkey (menubar->widget, 1);
|
|
|
|
menubar_draw (menubar);
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* We don't want the buttonbar to activate while using the menubar */
|
|
|
|
case WIDGET_HOTKEY:
|
|
|
|
case WIDGET_KEY:
|
2009-05-04 20:11:51 +04:00
|
|
|
if (menubar->is_active) {
|
2003-09-11 02:48:54 +04:00
|
|
|
menubar_handle_key (menubar, parm);
|
|
|
|
return MSG_HANDLED;
|
2009-05-04 20:11:51 +04:00
|
|
|
}
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case WIDGET_CURSOR:
|
|
|
|
/* Put the cursor in a suitable place */
|
2003-09-11 02:48:54 +04:00
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case WIDGET_UNFOCUS:
|
2009-05-04 20:11:51 +04:00
|
|
|
if (menubar->is_active)
|
2003-09-11 02:48:54 +04:00
|
|
|
return MSG_NOT_HANDLED;
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
widget_want_cursor (menubar->widget, 0);
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case WIDGET_DRAW:
|
2009-08-09 19:25:40 +04:00
|
|
|
if (menubar_visible) {
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_draw (menubar);
|
2009-08-09 19:25:40 +04:00
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2003-09-11 02:48:54 +04:00
|
|
|
|
2009-08-09 19:25:40 +04:00
|
|
|
case WIDGET_RESIZED:
|
|
|
|
/* try show menu after screen resize */
|
|
|
|
send_message (w, WIDGET_FOCUS, 0);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
menubar_set_menu (menubar, NULL);
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
default:
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-13 00:01:50 +03:00
|
|
|
static int
|
2009-08-26 22:31:54 +04:00
|
|
|
menubar_event (Gpm_Event *event, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
WMenuBar *menubar = data;
|
|
|
|
gboolean was_active = TRUE;
|
1998-02-27 07:54:42 +03:00
|
|
|
int left_x, right_x, bottom_y;
|
2009-05-04 20:11:51 +04:00
|
|
|
Menu *menu;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-22 16:11:37 +04:00
|
|
|
/* ignore unsupported events */
|
2009-09-07 14:28:07 +04:00
|
|
|
if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
return MOU_NORMAL;
|
2009-08-26 22:31:54 +04:00
|
|
|
|
2009-08-28 22:08:08 +04:00
|
|
|
/* ignore wheel events if menu is inactive */
|
2009-05-04 20:11:51 +04:00
|
|
|
if (!menubar->is_active
|
|
|
|
&& ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
|
2009-08-28 22:08:08 +04:00
|
|
|
return MOU_NORMAL;
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (!menubar->is_dropped) {
|
2003-09-13 11:43:20 +04:00
|
|
|
menubar->previous_widget = menubar->widget.parent->current->dlg_id;
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar->is_active = TRUE;
|
|
|
|
menubar->is_dropped = TRUE;
|
|
|
|
was_active = FALSE;
|
2009-09-22 16:11:37 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Mouse operations on the menubar */
|
2009-05-04 20:11:51 +04:00
|
|
|
if (event->y == 1 || !was_active) {
|
|
|
|
if ((event->type & GPM_UP) != 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
return MOU_NORMAL;
|
2009-08-26 22:31:54 +04:00
|
|
|
|
2009-09-22 16:11:37 +04:00
|
|
|
/* wheel events on menubar */
|
2009-08-26 22:31:54 +04:00
|
|
|
if (event->buttons & GPM_B_UP)
|
|
|
|
menubar_left (menubar);
|
|
|
|
else if (event->buttons & GPM_B_DOWN)
|
|
|
|
menubar_right (menubar);
|
|
|
|
else {
|
2009-08-25 13:08:18 +04:00
|
|
|
const unsigned int len = g_list_length (menubar->menu);
|
2009-09-07 14:28:07 +04:00
|
|
|
int new_selection = 0;
|
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
while ((new_selection < len)
|
|
|
|
&& (event->x > ((Menu *) g_list_nth_data (menubar->menu,
|
2009-05-04 20:11:51 +04:00
|
|
|
new_selection))->start_x))
|
1998-03-31 00:59:37 +04:00
|
|
|
new_selection++;
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (new_selection != 0) /* Don't set the invalid value -1 */
|
|
|
|
new_selection--;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-07 14:28:07 +04:00
|
|
|
if (!was_active) {
|
2009-08-26 22:31:54 +04:00
|
|
|
menubar->selected = new_selection;
|
|
|
|
dlg_select_widget (menubar);
|
2009-09-07 14:28:07 +04:00
|
|
|
} else {
|
|
|
|
menubar_remove (menubar);
|
|
|
|
menubar->selected = new_selection;
|
2009-08-26 22:31:54 +04:00
|
|
|
}
|
2009-09-22 16:11:37 +04:00
|
|
|
menubar_draw (menubar);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (!menubar->is_dropped || (event->y < 2))
|
1998-02-27 07:54:42 +03:00
|
|
|
return MOU_NORMAL;
|
2009-08-26 22:31:54 +04:00
|
|
|
|
2009-09-07 14:28:07 +04:00
|
|
|
/* middle click -- everywhere */
|
2009-05-04 20:11:51 +04:00
|
|
|
if (((event->buttons & GPM_B_MIDDLE) != 0)
|
|
|
|
&& ((event->type & GPM_DOWN) != 0)) {
|
2009-09-19 14:45:40 +04:00
|
|
|
menubar_execute (menubar);
|
1998-02-27 07:54:42 +03:00
|
|
|
return MOU_NORMAL;
|
2009-09-07 14:28:07 +04:00
|
|
|
}
|
2009-08-26 22:31:54 +04:00
|
|
|
|
2009-09-07 14:28:07 +04:00
|
|
|
/* the mouse operation is on the menus or it is not */
|
2009-08-25 13:08:18 +04:00
|
|
|
menu = (Menu *) g_list_nth_data (menubar->menu, menubar->selected);
|
2009-09-22 16:11:37 +04:00
|
|
|
left_x = menu->start_x;
|
2009-05-04 20:11:51 +04:00
|
|
|
right_x = left_x + menu->max_entry_len + 3;
|
2009-09-07 14:28:07 +04:00
|
|
|
if (right_x > menubar->widget.cols) {
|
2009-05-04 20:11:51 +04:00
|
|
|
left_x = menubar->widget.cols - menu->max_entry_len - 3;
|
2009-09-07 14:28:07 +04:00
|
|
|
right_x = menubar->widget.cols;
|
|
|
|
}
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
bottom_y = g_list_length (menu->entries) + 3;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-09-07 14:28:07 +04:00
|
|
|
if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y)){
|
1998-02-27 07:54:42 +03:00
|
|
|
int pos = event->y - 3;
|
2009-08-25 13:08:18 +04:00
|
|
|
const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-08-26 22:31:54 +04:00
|
|
|
/* mouse wheel */
|
|
|
|
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) {
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_up (menubar);
|
2009-08-26 22:31:54 +04:00
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
|
|
|
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) {
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_down (menubar);
|
2009-08-26 22:31:54 +04:00
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
|
|
|
|
2009-09-22 16:11:37 +04:00
|
|
|
/* ignore events above and below dropped down menu */
|
2009-08-25 13:08:18 +04:00
|
|
|
if ((pos < 0) || (pos >= bottom_y - 3))
|
2009-09-22 16:11:37 +04:00
|
|
|
return MOU_NORMAL;
|
|
|
|
|
2009-10-01 22:23:50 +04:00
|
|
|
if ((entry != NULL) && (entry->command != 0)) {
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
|
|
|
|
menu->selected = pos;
|
|
|
|
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if ((event->type & GPM_UP) != 0)
|
2009-09-19 14:45:40 +04:00
|
|
|
menubar_execute (menubar);
|
2009-09-07 14:28:07 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
} else
|
2009-08-27 21:29:09 +04:00
|
|
|
/* use click not wheel to close menu */
|
2009-05-04 20:11:51 +04:00
|
|
|
if (((event->type & GPM_DOWN) != 0)
|
|
|
|
&& ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
|
1998-02-27 07:54:42 +03:00
|
|
|
menubar_finish (menubar);
|
2009-08-26 22:31:54 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
WMenuBar *
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_new (int y, int x, int cols, GList *menu)
|
2009-05-04 20:11:51 +04:00
|
|
|
{
|
|
|
|
WMenuBar *menubar = g_new0 (WMenuBar, 1);
|
|
|
|
|
|
|
|
init_widget (&menubar->widget, y, x, 1, cols,
|
|
|
|
menubar_callback, menubar_event);
|
|
|
|
widget_want_cursor (menubar->widget, 0);
|
|
|
|
menubar_set_menu (menubar, menu);
|
|
|
|
return menubar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar_set_menu (WMenuBar *menubar, GList *menu)
|
2009-05-04 20:11:51 +04:00
|
|
|
{
|
|
|
|
/* delete previous menu */
|
|
|
|
if (menubar->menu != NULL) {
|
2009-08-25 13:08:18 +04:00
|
|
|
g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
|
|
|
|
g_list_free (menubar->menu);
|
2009-05-04 20:11:51 +04:00
|
|
|
}
|
|
|
|
/* add new menu */
|
|
|
|
menubar->is_active = FALSE;
|
|
|
|
menubar->is_dropped = FALSE;
|
|
|
|
menubar->menu = menu;
|
|
|
|
menubar->selected = 0;
|
|
|
|
menubar_arrange (menubar);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
menubar_add_menu (WMenuBar *menubar, Menu *menu)
|
|
|
|
{
|
|
|
|
if (menu != NULL)
|
2009-08-25 13:08:18 +04:00
|
|
|
menubar->menu = g_list_append (menubar->menu, menu);
|
2009-05-04 20:11:51 +04:00
|
|
|
|
|
|
|
menubar_arrange (menubar);
|
|
|
|
}
|
|
|
|
|
1998-03-31 00:59:37 +04:00
|
|
|
/*
|
|
|
|
* Properly space menubar items. Should be called when menubar is created
|
|
|
|
* and also when widget width is changed (i.e. upon xterm resize).
|
|
|
|
*/
|
|
|
|
void
|
2009-05-04 20:11:51 +04:00
|
|
|
menubar_arrange (WMenuBar* menubar)
|
1998-03-31 00:59:37 +04:00
|
|
|
{
|
2009-05-04 20:11:51 +04:00
|
|
|
int start_x = 1;
|
2009-08-25 13:08:18 +04:00
|
|
|
GList *i;
|
2009-05-04 20:11:51 +04:00
|
|
|
int gap;
|
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
if (menubar->menu == NULL)
|
2009-05-04 20:11:51 +04:00
|
|
|
return;
|
1998-05-08 06:25:00 +04:00
|
|
|
|
|
|
|
#ifndef RESIZABLE_MENUBAR
|
2009-05-04 20:11:51 +04:00
|
|
|
gap = 3;
|
1998-05-08 06:25:00 +04:00
|
|
|
|
2009-08-25 13:08:18 +04:00
|
|
|
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
|
|
|
|
Menu *menu = i->data;
|
2009-05-04 20:11:51 +04:00
|
|
|
int len = hotkey_width (menu->text);
|
1998-05-08 06:25:00 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
menu->start_x = start_x;
|
|
|
|
start_x += len + gap;
|
|
|
|
}
|
1998-05-08 06:25:00 +04:00
|
|
|
#else /* RESIZABLE_MENUBAR */
|
2009-05-04 20:11:51 +04:00
|
|
|
gap = menubar->widget.cols - 2;
|
|
|
|
|
|
|
|
/* First, calculate gap between items... */
|
2009-08-25 13:08:18 +04:00
|
|
|
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) {
|
|
|
|
Menu *menu = i->data;
|
2009-05-04 20:11:51 +04:00
|
|
|
/* preserve length here, to be used below */
|
|
|
|
menu->start_x = hotkey_width (menu->text);
|
|
|
|
gap -= menu->start_x;
|
2008-12-29 01:57:59 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
gap /= (menubar->menu->len - 1);
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
if (gap <= 0) {
|
|
|
|
/* We are out of luck - window is too narrow... */
|
|
|
|
gap = 1;
|
|
|
|
}
|
2003-09-01 03:29:49 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
/* ...and now fix start positions of menubar items */
|
2009-08-25 13:08:18 +04:00
|
|
|
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) {
|
|
|
|
Menu *menu = i->data;
|
2009-05-04 20:11:51 +04:00
|
|
|
int len = menu->start_x;
|
1998-03-31 00:59:37 +04:00
|
|
|
|
2009-05-04 20:11:51 +04:00
|
|
|
menu->start_x = start_x;
|
|
|
|
start_x += len + gap;
|
|
|
|
}
|
|
|
|
#endif /* RESIZABLE_MENUBAR */
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|