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 #include <stdbool.h>
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     /** \brief  menu item callback function
69      *
70      * The return value determines whether or not the keypress was 'consumed'
71      * by the UI. Normally you'd return TRUE here.
72      *
73      * If `NULL`, there is no callback (for separators or placeholders for
74      * not yet implemented items)
75      */
76     gboolean (*callback)(GtkWidget *widget, gpointer user_data);
77 
78     /** \brief  Callback data (optional)
79      *
80      *  - UI_MENU_TYPE_ITEM_ACTION:  scalar
81      *  - UI_MENU_TYPE_SUBMENU: array of submenu items
82      *  - UI_MENU_TYPE_ITEM_CHECK: resource name
83      *  - UI_MENU_TYPE_SEPARATOR: ignored
84      */
85     void *data;
86 
87     /** accelerator key, without modifier
88      * (see /usr/include/gtk-3.0/gdk/gdkkeysyms.h)
89      */
90     guint keysym;
91 
92     /** modifier (ie Alt) */
93     GdkModifierType modifier;
94 
95     /** whether the callback should be called while holding the vice mainlock */
96     bool unlocked;
97 
98 } ui_menu_item_t;
99 
100 
101 /** \brief  Terminator of a menu items list
102  */
103 #define UI_MENU_TERMINATOR { NULL, UI_MENU_TYPE_GUARD, NULL, NULL, NULL, 0, 0 }
104 
105 
106 /** \brief  Menu items separator
107  */
108 #define UI_MENU_SEPARATOR { "---", UI_MENU_TYPE_SEPARATOR, NULL, NULL, NULL, 0, 0 }
109 
110 
111 /** \brief  Platform-dependent accelerator key defines
112  */
113 #ifdef MACOSX_SUPPORT
114   /* Mac Command key (Windows key on PC keyboards) */
115   #define VICE_MOD_MASK GDK_META_MASK
116 #else
117   /* Alt key (Option key on Mac keyboards) */
118   #define VICE_MOD_MASK GDK_MOD1_MASK
119 #endif
120 
121 
122 /*
123  * Public functions
124  */
125 
126 GtkWidget *ui_menu_submenu_create(GtkWidget *bar, const char *label);
127 
128 GtkWidget *ui_menu_add(GtkWidget *menu, ui_menu_item_t *items);
129 
130 /* FIXME: is this still even used? */
131 void ui_menu_init_accelerators(GtkWidget *window);
132 
133 #endif
134