1 /** \file   uimenu.h
2  * \brief   Native GTK3 menu handling - header
3  *
4  * \author  Bas Wassink <b.wassink@ziggo.nl>
5  * \author  Marcus Sutton <loggedoubt@gmail.com>
6  */
7 
8 /*
9  * This file is part of VICE, the Versatile Commodore Emulator.
10  * See README for copyright notice.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program 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.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25  *  02111-1307  USA.
26  *
27  */
28 
29 #ifndef VICE_UIMENU_H
30 #define VICE_UIMENU_H
31 
32 #include "vice.h"
33 #include <gtk/gtk.h>
34 
35 
36 /** \brief  Menu item types
37  *
38  * The submenu types needs special handling, no more callbacks to create the
39  * menu so we won't have to deal with the `ui_update_checmarks` crap of Gtk2.
40  *
41  * The 'layer' between VICE and Gtk3 should be as thin as possible, so no
42  * UI_CREATE_TOGGLE_BUTTON() stuff.
43  */
44 typedef enum ui_menu_item_type_e {
45     UI_MENU_TYPE_GUARD = -1,    /**< list terminator */
46     UI_MENU_TYPE_ITEM_ACTION,   /**< standard list item: activate dialog */
47     UI_MENU_TYPE_ITEM_CHECK,    /**< menu item with checkmark */
48     UI_MENU_TYPE_SUBMENU,       /**< submenu */
49     UI_MENU_TYPE_SEPARATOR      /**< items separator */
50 } ui_menu_item_type_t;
51 
52 
53 
54 /** \brief  Menu item object
55  *
56  * Contains information on a menu item
57  */
58 typedef struct ui_menu_item_s {
59     char *              label;  /**< menu item label */
60     ui_menu_item_type_t type;   /**< menu item type, \see ui_menu_item_type_t */
61 
62     /* callbacks, accelerators and other things, again light on the CPP/layer
63      * stuff to keep things clean and maintainable. */
64 
65     /** GAction name (must be unique or NULL for no action) */
66     char *action_name;
67 
68     /** menu item callback function (NULL == no callback) */
69     void (*callback)(GtkWidget *widget, gpointer user_data);
70 
71     /** callback data, or a pointer to an array of submenu items if the menu
72      *  type is UI_MENU_TYPE_SUBMENU, or a resource name in case of
73      *  UI_MENU_ITEM_TYPE_CHECK */
74     void *data;
75 
76     /** accelerator key, without modifier
77      * (see /usr/include/gtk-3.0/gdk/gdkkeysyms.h)
78      */
79     guint keysym;
80 
81     /** modifier (ie Alt) */
82     GdkModifierType modifier;
83 
84 } ui_menu_item_t;
85 
86 
87 /** \brief  Terminator of a menu items list
88  */
89 #define UI_MENU_TERMINATOR { NULL, UI_MENU_TYPE_GUARD, NULL, NULL, NULL, 0, 0 }
90 
91 
92 /** \brief  Menu items separator
93  */
94 #define UI_MENU_SEPARATOR { "---", UI_MENU_TYPE_SEPARATOR, NULL, NULL, NULL, 0, 0 }
95 
96 
97 /** \brief  Platform-dependent accelerator key defines
98  */
99 #ifdef MACOSX_SUPPORT
100   /* Mac Command key (Windows key on PC keyboards) */
101   #define VICE_MOD_MASK GDK_META_MASK
102 #else
103   /* Alt key (Option key on Mac keyboards) */
104   #define VICE_MOD_MASK GDK_MOD1_MASK
105 #endif
106 
107 
108 /*
109  * Public functions
110  */
111 
112 GtkWidget *ui_menu_submenu_create(GtkWidget *bar, const char *label);
113 
114 GtkWidget *ui_menu_add(GtkWidget *menu, ui_menu_item_t *items);
115 
116 /* FIXME: is this still even used? */
117 void ui_menu_init_accelerators(GtkWidget *window);
118 
119 #endif
120