1 /* 2 * menu.h 3 * 4 * Copyright 2012 Dimitar Toshkov Zhekov <dimitar.zhekov@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef MENU_H 21 22 struct _MenuItem 23 { 24 const char *name; 25 void (*callback)(const MenuItem *menu_item); 26 guint state; 27 GtkWidget *widget; /* automatic */ 28 gpointer gdata; 29 }; 30 31 typedef struct _MenuInfo 32 { 33 MenuItem *items; 34 guint (*extra_state)(void); 35 guint last_state; /* must be 0 */ 36 } MenuInfo; 37 38 const MenuItem *menu_item_find(const MenuItem *menu_items, const char *name); 39 gboolean menu_item_matches_state(const MenuItem *menu_item, guint state); 40 void menu_item_execute(const MenuInfo *menu_info, const MenuItem *menu_item, gboolean beep); 41 void menu_item_set_active(const MenuItem *menu_item, gboolean active); /* block execute */ 42 43 gboolean menu_insert_delete(const GdkEventKey *event, const MenuInfo *menu_info, 44 const char *insert_name, const char *delete_name); 45 void menu_shift_button_release(GtkWidget *widget, GdkEventButton *event, GtkWidget *menu, 46 void (action)(const MenuItem *menu_item)); 47 48 GtkWidget *menu_connect(const char *name, MenuInfo *menu_info, GtkWidget *widget); 49 GtkWidget *menu_select(const char *name, MenuInfo *menu_info, GtkTreeSelection *selection); 50 51 enum 52 { 53 COLUMN_NAME, 54 COLUMN_DISPLAY, 55 COLUMN_VALUE, 56 COLUMN_HB_MODE, 57 COLUMN_MR_MODE 58 }; 59 60 #define MENU_HBIT_ITEM(prefix, mode, MODE) \ 61 { (#prefix"_hb_"mode), (on_##prefix##_hbit_update), DS_REPARSABLE, NULL, \ 62 GINT_TO_POINTER(MODE) } 63 64 /* note: N references to prefix */ 65 #define MENU_HBIT_ITEMS(prefix) \ 66 { (#prefix"_hb_mode"), (on_##prefix##_hbit_display), DS_REPARSABLE, NULL, NULL }, \ 67 MENU_HBIT_ITEM(prefix, "default", HB_DEFAULT), \ 68 MENU_HBIT_ITEM(prefix, "7bit", HB_7BIT), \ 69 MENU_HBIT_ITEM(prefix, "locale", HB_LOCALE), \ 70 MENU_HBIT_ITEM(prefix, "utf8", HB_UTF8) 71 72 void menu_mode_display(GtkTreeSelection *selection, const MenuItem *menu_item, gint column); 73 void menu_mode_update(GtkTreeSelection *selection, gint new_mode, gboolean hbit); 74 #define menu_hbit_display(selection, menu_item) menu_mode_display((selection), (menu_item), \ 75 COLUMN_HB_MODE) 76 #define menu_hbit_update(selection, menu_item) menu_mode_update((selection), \ 77 GPOINTER_TO_INT((menu_item)->gdata), TRUE) 78 79 void menu_mber_display(GtkTreeSelection *selection, const MenuItem *menu_item); 80 void menu_mber_update(GtkTreeSelection *selection, const MenuItem *menu_item); 81 void menu_mber_button_release(GtkTreeSelection *selection, GtkWidget *item, 82 GdkEventButton *event, GtkWidget *menu); 83 84 void menu_copy(GtkTreeSelection *selection, const MenuItem *menu_item); 85 void menu_modify(GtkTreeSelection *selection, const MenuItem *menu_item); 86 void menu_inspect(GtkTreeSelection *selection); 87 88 void on_menu_display_booleans(const MenuItem *menu_item); 89 void on_menu_update_boolean(const MenuItem *menu_item); 90 void on_menu_evaluate_value(GArray *nodes); 91 92 typedef struct _MenuKey 93 { 94 const char *name; 95 const gchar *label; 96 } MenuKey; 97 98 void menu_set_popup_keybindings(GeanyKeyGroup *scope_key_group, guint item); 99 void menu_clear(void); 100 void menu_update_state(DebugState state); 101 102 void menu_init(void); 103 void menu_finalize(void); 104 105 #define MENU_H 1 106 #endif 107