1 #ifndef MENUTREE_H
2 #define MENUTREE_H
3 /*
4     roxterm - VTE/GTK terminal emulator with tabs
5     Copyright (C) 2004-2015 Tony Houghton <h@realh.co.uk>
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21 
22 
23 /* Handles the menu tree */
24 
25 #include "options.h"
26 
27 /* These are upper case because they could be replaced with string macros if
28  * we were to build menus from some external definition */
29 
30 typedef enum {
31     MENUTREE_NULL_ID = -1,
32 
33     MENUTREE_SSH_HOST,
34     MENUTREE_OPEN_IN_BROWSER,
35     MENUTREE_OPEN_IN_MAILER,
36     MENUTREE_OPEN_IN_FILER,
37     MENUTREE_VOIP_CALL,
38     MENUTREE_COPY_URI,
39     MENUTREE_URI_SEPARATOR,
40 
41     MENUTREE_FILE,
42     MENUTREE_EDIT,
43     MENUTREE_VIEW,
44     MENUTREE_SEARCH,
45     MENUTREE_PREFERENCES,
46     MENUTREE_TABS,
47     MENUTREE_HELP,
48 
49     MENUTREE_FILE_NEW_WINDOW,
50     MENUTREE_FILE_NEW_TAB,
51     MENUTREE_FILE_NEW_WINDOW_WITH_PROFILE,
52     MENUTREE_FILE_NEW_WINDOW_WITH_PROFILE_HEADER,
53     MENUTREE_FILE_NEW_TAB_WITH_PROFILE,
54     MENUTREE_FILE_NEW_TAB_WITH_PROFILE_HEADER,
55     MENUTREE_FILE_CLOSE_TAB,
56     MENUTREE_FILE_CLOSE_WINDOW,
57     MENUTREE_FILE_SAVE_SESSION,
58 
59     MENUTREE_EDIT_SELECT_ALL,
60     MENUTREE_EDIT_COPY,
61     MENUTREE_EDIT_PASTE,
62     MENUTREE_EDIT_COPY_AND_PASTE,
63     MENUTREE_EDIT_SET_WINDOW_TITLE,
64     MENUTREE_EDIT_RESET,
65     MENUTREE_EDIT_RESET_AND_CLEAR,
66     MENUTREE_EDIT_RESPAWN,
67 
68     MENUTREE_VIEW_SHOW_MENUBAR,
69     MENUTREE_VIEW_SHOW_TAB_BAR,
70     MENUTREE_VIEW_FULLSCREEN,
71     MENUTREE_VIEW_BORDERLESS,
72     MENUTREE_VIEW_ZOOM_IN,
73     MENUTREE_VIEW_ZOOM_OUT,
74     MENUTREE_VIEW_ZOOM_NORM,
75     MENUTREE_VIEW_SCROLL_UP,
76     MENUTREE_VIEW_SCROLL_DOWN,
77     MENUTREE_VIEW_SCROLL_PAGE_UP,
78     MENUTREE_VIEW_SCROLL_PAGE_DOWN,
79     MENUTREE_VIEW_SCROLL_HALF_PAGE_UP,
80     MENUTREE_VIEW_SCROLL_HALF_PAGE_DOWN,
81     MENUTREE_VIEW_SCROLL_TO_TOP,
82     MENUTREE_VIEW_SCROLL_TO_BOTTOM,
83 
84     MENUTREE_SEARCH_FIND,
85     MENUTREE_SEARCH_FIND_NEXT,
86     MENUTREE_SEARCH_FIND_PREVIOUS,
87 
88     MENUTREE_PREFERENCES_PROFILES,
89     MENUTREE_PREFERENCES_SELECT_PROFILE,
90     MENUTREE_PREFERENCES_SELECT_COLOUR_SCHEME,
91     MENUTREE_PREFERENCES_SELECT_SHORTCUTS,
92     MENUTREE_PREFERENCES_EDIT_CURRENT_PROFILE,
93     MENUTREE_PREFERENCES_EDIT_CURRENT_COLOUR_SCHEME,
94     MENUTREE_PREFERENCES_EDIT_CURRENT_SHORTCUTS_SCHEME,
95     MENUTREE_PREFERENCES_CONFIG_MANAGER,
96 
97     MENUTREE_TABS_DETACH_TAB,
98     MENUTREE_TABS_CLOSE_TAB,
99     MENUTREE_TABS_CLOSE_OTHER_TABS,
100     MENUTREE_TABS_NAME_TAB,
101     MENUTREE_TABS_PREVIOUS_TAB,
102     MENUTREE_TABS_NEXT_TAB,
103     MENUTREE_TABS_MOVE_TAB_LEFT,
104     MENUTREE_TABS_MOVE_TAB_RIGHT,
105 
106     MENUTREE_HELP_SHOW_MANUAL,
107     MENUTREE_HELP_ABOUT,
108 
109 
110     MENUTREE_NUM_IDS,
111 
112     MENUTREE_TABS_FIRST_FIXED = MENUTREE_TABS_DETACH_TAB,
113     MENUTREE_TABS_LAST_FIXED = MENUTREE_TABS_MOVE_TAB_RIGHT + 1,
114                                 /* +1 for separator */
115     MENUTREE_TABS_FIRST_DYNAMIC =
116     MENUTREE_TABS_LAST_FIXED - MENUTREE_TABS_FIRST_FIXED + 3
117     /* +3 because there are 3 separators in total */
118 } MenuTreeID;
119 
120 typedef struct MenuTree MenuTree;
121 struct MenuTree {
122     GtkWidget *top_level;
123     gboolean being_deleted;
124     void (*deleted_handler) (MenuTree *, gpointer);
125     gpointer deleted_data;
126     GtkWidget *item_widgets[MENUTREE_NUM_IDS];
127     gpointer user_data;
128     GtkAccelGroup *accel_group;
129     GList *tabs;    /* List of GtkMenuItem widgets */
130     int ntabs;
131     Options *shortcuts;
132     gboolean disable_shortcuts;
133     gboolean disable_tab_shortcuts;
134     GtkWidget *new_win_profiles_menu;
135     GtkWidget *new_tab_profiles_menu;
136 };
137 
138 /* Builds a menu tree. The GType should either be GTK_TYPE_MENU_BAR or
139  * GTK_TYPE_MENU.
140  */
141 MenuTree *menutree_new(Options *shortcuts, GtkAccelGroup * accel_group,
142     GType menu_type, gboolean disable_shortcuts,
143     gboolean disable_tab_shortcuts, gpointer user_data);
144 
145 /* Creates the short version of the popup menu, used as the context menu when
146  * the menu bar is enabled.
147  * Must not be called before menutree_new has been called for first time.
148  */
149 MenuTree *menutree_new_short_popup(Options *shortcuts,
150         GtkAccelGroup *accel_group, gboolean disable_shortcuts,
151         gpointer user_data);
152 
153 void menutree_delete(MenuTree *);
154 
155 /* Gets the widget at the top-level (menu bar or popup menu) */
menutree_get_top_level_widget(MenuTree * tree)156 inline static GtkWidget *menutree_get_top_level_widget(MenuTree * tree)
157 {
158     return tree->top_level;
159 }
160 
menutree_get_widget_for_id(MenuTree * tree,MenuTreeID id)161 inline static GtkWidget *menutree_get_widget_for_id(MenuTree *tree,
162     MenuTreeID id)
163 {
164     return tree->item_widgets[id];
165 }
166 
167 GtkMenu *menutree_submenu_from_id(MenuTree *mtree, MenuTreeID id);
168 
169 inline static void
menutree_shade(MenuTree * tree,MenuTreeID id,gboolean shade)170 menutree_shade(MenuTree * tree, MenuTreeID id, gboolean shade)
171 {
172     gtk_widget_set_sensitive(tree->item_widgets[id], !shade);
173 }
174 
175 /* Supply a function to be called when a menutree is destroyed */
176 void
177 menutree_connect_destroyed(MenuTree * tree,
178     GCallback callback, gpointer user_data);
179 
180 /* Adds a tab to the tabs menu. Returns the GtkMenuItem widget. Caller's
181  * responsibility to connect a signal handler to it; position starts at 0
182  * for first tab, not actual position in menu (due to Next/Previous Tab and
183  * separator), or -1 to append. */
184 GtkWidget *menutree_add_tab_at_position(MenuTree * tree, const char *title,
185         int position);
186 
menutree_add_tab(MenuTree * tree,const char * title)187 inline static GtkWidget *menutree_add_tab(MenuTree * tree, const char *title)
188 {
189     return menutree_add_tab_at_position(tree, title, -1);
190 }
191 
192 GtkWidget *menutree_change_tab_title(MenuTree * tree,
193     GtkWidget *widget, const char *title);
194 
195 
196 void menutree_set_show_menu_bar_active(MenuTree * tree, gboolean active);
197 void menutree_set_show_tab_bar_active(MenuTree *tree, gboolean active);
198 void menutree_set_fullscreen_active(MenuTree *tree, gboolean active);
199 void menutree_set_borderless_active(MenuTree *tree, gboolean active);
200 
201 gulong menutree_named_signal_connect_data(MenuTree * tree, MenuTreeID id,
202     const char *signame, GCallback handler, gpointer user_data,
203     GConnectFlags flags);
204 
menutree_named_signal_connect(MenuTree * tree,MenuTreeID id,const char * signame,GCallback handler,gpointer user_data)205 inline static gulong menutree_named_signal_connect(MenuTree *tree,
206     MenuTreeID id, const char *signame, GCallback handler, gpointer user_data)
207 {
208     return menutree_named_signal_connect_data(tree, id, signame, handler,
209             user_data, 0);
210 }
211 
menutree_named_signal_connect_swapped(MenuTree * tree,MenuTreeID id,const char * signame,GCallback handler,gpointer user_data)212 inline static gulong menutree_named_signal_connect_swapped(MenuTree *tree,
213     MenuTreeID id, const char *signame, GCallback handler, gpointer user_data)
214 {
215     return menutree_named_signal_connect_data(tree, id, signame, handler,
216             user_data, G_CONNECT_SWAPPED);
217 }
218 
219 /* Connects a handler for an item's "activate" signal */
menutree_signal_connect_data(MenuTree * tree,MenuTreeID id,GCallback handler,gpointer user_data,GConnectFlags flags)220 inline static gulong menutree_signal_connect_data(MenuTree *tree, MenuTreeID id,
221     GCallback handler, gpointer user_data, GConnectFlags flags)
222 {
223     return menutree_named_signal_connect_data(tree, id, "activate", handler,
224             user_data, flags);
225 }
226 
227 inline static gulong
menutree_signal_connect(MenuTree * tree,MenuTreeID id,GCallback handler,gpointer user_data)228 menutree_signal_connect(MenuTree * tree, MenuTreeID id,
229     GCallback handler, gpointer user_data)
230 {
231     return menutree_signal_connect_data(tree, id, handler, user_data, 0);
232 }
233 
234 inline static gulong
menutree_signal_connect_swapped(MenuTree * tree,MenuTreeID id,GCallback handler,gpointer user_data)235 menutree_signal_connect_swapped(MenuTree * tree, MenuTreeID id,
236     GCallback handler, gpointer user_data)
237 {
238     return menutree_signal_connect_data(tree, id, handler, user_data,
239         G_CONNECT_SWAPPED);
240 }
241 
242 void menutree_set_show_item(MenuTree * tree, MenuTreeID id, gboolean show);
243 
244 void menutree_apply_shortcuts(MenuTree *tree, Options *shortcuts);
245 
246 /* Use with gtk_container_foreach to find the group of the last radio menu
247  * item in a menu. data must point to a GSList * where the group is stored */
248 void menutree_find_radio_group(GtkWidget *widget, gpointer data);
249 
250 /* Remove an item from the tabs menu; menu_item is the widget returned by
251  * menutree_add_tab */
252 void menutree_remove_tab(MenuTree * tree, GtkWidget * menu_item);
253 
menutree_select_tab(MenuTree * tree,GtkWidget * menu_item)254 inline static void menutree_select_tab(MenuTree * tree, GtkWidget * menu_item)
255 {
256     (void) tree;
257     gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_item), TRUE);
258 }
259 
260 void menutree_disable_shortcuts(MenuTree *tree, gboolean disable);
261 
262 void menutree_disable_tab_shortcuts(MenuTree *tree, gboolean disable);
263 
264 /* Change left/right to up/down */
265 void menutree_change_move_tab_labels(MenuTree *tree);
266 
267 #endif /* MENUTREE_H */
268 
269 /* vi:set sw=4 ts=4 et cindent cino= */
270