Mercurial > pidgin.yaz
annotate finch/libgnt/gntmenu.c @ 23268:9f34726fe141
Whoops, I should have inverted this logic.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 02 Jun 2008 09:00:11 +0000 |
parents | 24dfef623410 |
children | 9a7520e489f8 |
rev | line source |
---|---|
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19661
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15931
diff
changeset
|
22 |
15818 | 23 #include "gntmenu.h" |
24 #include "gntmenuitemcheck.h" | |
25 | |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
26 #include <ctype.h> |
15818 | 27 #include <string.h> |
28 | |
29 enum | |
30 { | |
31 SIGS = 1, | |
32 }; | |
33 | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
34 enum |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
35 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
36 ITEM_TEXT = 0, |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
37 ITEM_TRIGGER, |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
38 ITEM_SUBMENU, |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
39 NUM_COLUMNS |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
40 }; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
41 |
15818 | 42 static GntTreeClass *parent_class = NULL; |
43 | |
44 static void (*org_draw)(GntWidget *wid); | |
45 static void (*org_destroy)(GntWidget *wid); | |
46 static void (*org_map)(GntWidget *wid); | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
47 static void (*org_size_request)(GntWidget *wid); |
15818 | 48 static gboolean (*org_key_pressed)(GntWidget *w, const char *t); |
22309
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
49 static gboolean (*org_clicked)(GntWidget *w, GntMouseEvent event, int x, int y); |
15818 | 50 |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
51 static void menuitem_activate(GntMenu *menu, GntMenuItem *item); |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
52 |
15818 | 53 static void |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
54 menu_hide_all(GntMenu *menu) |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
55 { |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
56 while (menu->parentmenu) |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
57 menu = menu->parentmenu; |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
58 gnt_widget_hide(GNT_WIDGET(menu)); |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
59 } |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
60 |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
61 static void |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
62 show_submenu(GntMenu *menu) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
63 { |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
64 GntMenuItem *item; |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
65 |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
66 if (menu->type != GNT_MENU_TOPLEVEL) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
67 return; |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
68 |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
69 item = g_list_nth_data(menu->list, menu->selected); |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
70 if (!item || !item->submenu) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
71 return; |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
72 menuitem_activate(menu, item); |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
73 } |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
74 |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
75 static void |
15818 | 76 gnt_menu_draw(GntWidget *widget) |
77 { | |
78 GntMenu *menu = GNT_MENU(widget); | |
79 GList *iter; | |
80 chtype type; | |
81 int i; | |
82 | |
83 if (menu->type == GNT_MENU_TOPLEVEL) { | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21215
diff
changeset
|
84 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
15818 | 85 werase(widget->window); |
86 | |
87 for (i = 0, iter = menu->list; iter; iter = iter->next, i++) { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
88 GntMenuItem *item = GNT_MENU_ITEM(iter->data); |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21215
diff
changeset
|
89 type = ' ' | gnt_color_pair(GNT_COLOR_HIGHLIGHT); |
15818 | 90 if (i == menu->selected) |
91 type |= A_REVERSE; | |
92 item->priv.x = getcurx(widget->window) + widget->priv.x; | |
93 item->priv.y = getcury(widget->window) + widget->priv.y + 1; | |
94 wbkgdset(widget->window, type); | |
95 wprintw(widget->window, " %s ", item->text); | |
96 } | |
97 } else { | |
98 org_draw(widget); | |
99 } | |
100 | |
101 GNTDEBUG; | |
102 } | |
103 | |
104 static void | |
105 gnt_menu_size_request(GntWidget *widget) | |
106 { | |
107 GntMenu *menu = GNT_MENU(widget); | |
108 | |
109 if (menu->type == GNT_MENU_TOPLEVEL) { | |
110 widget->priv.height = 1; | |
111 widget->priv.width = getmaxx(stdscr); | |
112 } else { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
113 org_size_request(widget); |
15818 | 114 widget->priv.height = g_list_length(menu->list) + 2; |
115 } | |
116 } | |
117 | |
118 static void | |
119 menu_tree_add(GntMenu *menu, GntMenuItem *item, GntMenuItem *parent) | |
120 { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
121 char trigger[4] = "\0 )\0"; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
122 |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
123 if ((trigger[1] = gnt_menuitem_get_trigger(item)) && trigger[1] != ' ') |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
124 trigger[0] = '('; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
125 |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
126 if (GNT_IS_MENU_ITEM_CHECK(item)) { |
15818 | 127 gnt_tree_add_choice(GNT_TREE(menu), item, |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
128 gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, " "), parent, NULL); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
129 gnt_tree_set_choice(GNT_TREE(menu), item, gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); |
15818 | 130 } else |
131 gnt_tree_add_row_last(GNT_TREE(menu), item, | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
132 gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, item->submenu ? ">" : " "), parent); |
15818 | 133 |
134 if (0 && item->submenu) { | |
135 GntMenu *sub = GNT_MENU(item->submenu); | |
136 GList *iter; | |
137 for (iter = sub->list; iter; iter = iter->next) { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
138 GntMenuItem *it = GNT_MENU_ITEM(iter->data); |
15818 | 139 menu_tree_add(menu, it, item); |
140 } | |
141 } | |
142 } | |
143 | |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
144 #define GET_VAL(ch) ((ch >= '0' && ch <= '9') ? (ch - '0') : (ch >= 'a' && ch <= 'z') ? (10 + ch - 'a') : 36) |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
145 |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
146 static void |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
147 assign_triggers(GntMenu *menu) |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
148 { |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
149 GList *iter; |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
150 gboolean bools[37]; |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
151 |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
152 memset(bools, 0, sizeof(bools)); |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
153 bools[36] = 1; |
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
154 |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
155 for (iter = menu->list; iter; iter = iter->next) { |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
156 GntMenuItem *item = iter->data; |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
157 char trigger = tolower(gnt_menuitem_get_trigger(item)); |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
158 if (trigger == '\0' || trigger == ' ') |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
159 continue; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
160 bools[(int)GET_VAL(trigger)] = 1; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
161 } |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
162 |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
163 for (iter = menu->list; iter; iter = iter->next) { |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
164 GntMenuItem *item = iter->data; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
165 char trigger = gnt_menuitem_get_trigger(item); |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
166 const char *text = item->text; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
167 if (trigger != '\0') |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
168 continue; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
169 while (*text) { |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
170 char ch = tolower(*text++); |
22871
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22309
diff
changeset
|
171 char t[2] = {ch, '\0'}; |
24dfef623410
Check if a key is already bound before assigning a menu trigger
Richard Nelson <wabz@pidgin.im>
parents:
22309
diff
changeset
|
172 if (ch == ' ' || bools[(int)GET_VAL(ch)] || gnt_bindable_check_key(GNT_BINDABLE(menu), t)) |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
173 continue; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
174 trigger = ch; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
175 break; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
176 } |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
177 if (trigger == 0) |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
178 trigger = item->text[0]; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
179 gnt_menuitem_set_trigger(item, trigger); |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
180 bools[(int)GET_VAL(trigger)] = 1; |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
181 } |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
182 } |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
183 |
15818 | 184 static void |
185 gnt_menu_map(GntWidget *widget) | |
186 { | |
187 GntMenu *menu = GNT_MENU(widget); | |
188 | |
189 if (menu->type == GNT_MENU_TOPLEVEL) { | |
190 gnt_widget_size_request(widget); | |
191 } else { | |
192 /* Populate the tree */ | |
193 GList *iter; | |
194 gnt_tree_remove_all(GNT_TREE(widget)); | |
18444
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
195 /* Try to assign some trigger for the items */ |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
196 assign_triggers(menu); |
15818 | 197 for (iter = menu->list; iter; iter = iter->next) { |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
198 GntMenuItem *item = GNT_MENU_ITEM(iter->data); |
15818 | 199 menu_tree_add(menu, item, NULL); |
200 } | |
201 org_map(widget); | |
202 gnt_tree_adjust_columns(GNT_TREE(widget)); | |
203 } | |
204 GNTDEBUG; | |
205 } | |
206 | |
207 static void | |
208 menuitem_activate(GntMenu *menu, GntMenuItem *item) | |
209 { | |
21256
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
210 if (!item) |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
211 return; |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
212 |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
213 if (gnt_menuitem_activate(item)) { |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
214 menu_hide_all(menu); |
21256
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
215 } else { |
15818 | 216 if (item->submenu) { |
217 GntMenu *sub = GNT_MENU(item->submenu); | |
218 menu->submenu = sub; | |
219 sub->type = GNT_MENU_POPUP; /* Submenus are *never* toplevel */ | |
220 sub->parentmenu = menu; | |
221 if (menu->type != GNT_MENU_TOPLEVEL) { | |
222 GntWidget *widget = GNT_WIDGET(menu); | |
223 item->priv.x = widget->priv.x + widget->priv.width - 1; | |
224 item->priv.y = widget->priv.y + gnt_tree_get_selection_visible_line(GNT_TREE(menu)); | |
225 } | |
226 gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y); | |
227 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE); | |
228 gnt_widget_draw(GNT_WIDGET(sub)); | |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
229 } else { |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
230 menu_hide_all(menu); |
15818 | 231 } |
232 } | |
233 } | |
234 | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
235 static GList* |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
236 find_item_with_trigger(GList *start, GList *end, char trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
237 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
238 GList *iter; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
239 for (iter = start; iter != (end ? end : NULL); iter = iter->next) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
240 if (gnt_menuitem_get_trigger(iter->data) == trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
241 return iter; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
242 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
243 return NULL; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
244 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
245 |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
246 static gboolean |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
247 check_for_trigger(GntMenu *menu, char trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
248 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
249 /* check for a trigger key */ |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
250 GList *iter; |
19651
21e67147f9f0
Do not crash when pressing a key in an empty menu. Thanks to CmdrChalupa in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18875
diff
changeset
|
251 GList *find; |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
252 GList *nth = g_list_find(menu->list, gnt_tree_get_selection_data(GNT_TREE(menu))); |
19651
21e67147f9f0
Do not crash when pressing a key in an empty menu. Thanks to CmdrChalupa in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18875
diff
changeset
|
253 |
21e67147f9f0
Do not crash when pressing a key in an empty menu. Thanks to CmdrChalupa in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18875
diff
changeset
|
254 if (nth == NULL) |
21e67147f9f0
Do not crash when pressing a key in an empty menu. Thanks to CmdrChalupa in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18875
diff
changeset
|
255 return FALSE; |
21454
d78e440584e0
Add maximize flags for windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21260
diff
changeset
|
256 |
19651
21e67147f9f0
Do not crash when pressing a key in an empty menu. Thanks to CmdrChalupa in
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18875
diff
changeset
|
257 find = find_item_with_trigger(nth->next, NULL, trigger); |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
258 if (!find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
259 find = find_item_with_trigger(menu->list, nth->next, trigger); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
260 if (!find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
261 return FALSE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
262 if (find != nth) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
263 gnt_tree_set_selected(GNT_TREE(menu), find->data); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
264 iter = find_item_with_trigger(find->next, NULL, trigger); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
265 if (iter != NULL && iter != find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
266 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
267 iter = find_item_with_trigger(menu->list, nth, trigger); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
268 if (iter != NULL && iter != find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
269 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
270 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
271 gnt_widget_activate(GNT_WIDGET(menu)); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
272 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
273 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
274 |
15818 | 275 static gboolean |
276 gnt_menu_key_pressed(GntWidget *widget, const char *text) | |
277 { | |
278 GntMenu *menu = GNT_MENU(widget); | |
279 int current = menu->selected; | |
280 | |
281 if (menu->submenu) { | |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
282 GntMenu *sub = menu; |
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
283 do sub = sub->submenu; while (sub->submenu); |
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
284 if (gnt_widget_key_pressed(GNT_WIDGET(sub), text)) |
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
285 return TRUE; |
15818 | 286 } |
287 | |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
288 if ((text[0] == 27 && text[1] == 0) || |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
289 (menu->type != GNT_MENU_TOPLEVEL && strcmp(text, GNT_KEY_LEFT) == 0)) { |
15818 | 290 /* Escape closes menu */ |
291 GntMenu *par = menu->parentmenu; | |
292 if (par != NULL) { | |
293 par->submenu = NULL; | |
294 gnt_widget_hide(widget); | |
295 } else | |
296 gnt_widget_hide(widget); | |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
297 if (par && par->type == GNT_MENU_TOPLEVEL) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
298 gnt_menu_key_pressed(GNT_WIDGET(par), text); |
15818 | 299 return TRUE; |
300 } | |
301 | |
302 if (menu->type == GNT_MENU_TOPLEVEL) { | |
303 if (strcmp(text, GNT_KEY_LEFT) == 0) { | |
304 menu->selected--; | |
305 if (menu->selected < 0) | |
306 menu->selected = g_list_length(menu->list) - 1; | |
307 } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { | |
308 menu->selected++; | |
309 if (menu->selected >= g_list_length(menu->list)) | |
310 menu->selected = 0; | |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
311 } else if (strcmp(text, GNT_KEY_ENTER) == 0 || |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
312 strcmp(text, GNT_KEY_DOWN) == 0) { |
15818 | 313 gnt_widget_activate(widget); |
314 } | |
315 | |
316 if (current != menu->selected) { | |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
317 GntMenu *sub = menu->submenu; |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
318 if (sub) |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
319 gnt_widget_hide(GNT_WIDGET(sub)); |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
320 show_submenu(menu); |
15818 | 321 gnt_widget_draw(widget); |
322 return TRUE; | |
323 } | |
324 } else { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
325 if (text[1] == '\0') { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
326 if (check_for_trigger(menu, text[0])) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
327 return TRUE; |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
328 } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
329 GntMenuItem *item = gnt_tree_get_selection_data(GNT_TREE(menu)); |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
330 if (item && item->submenu) { |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
331 menuitem_activate(menu, item); |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
332 return TRUE; |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
333 } |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
334 } |
15818 | 335 return org_key_pressed(widget, text); |
336 } | |
337 | |
338 return FALSE; | |
339 } | |
340 | |
341 static void | |
342 gnt_menu_destroy(GntWidget *widget) | |
343 { | |
344 GntMenu *menu = GNT_MENU(widget); | |
345 g_list_foreach(menu->list, (GFunc)g_object_unref, NULL); | |
346 g_list_free(menu->list); | |
347 org_destroy(widget); | |
348 } | |
349 | |
350 static void | |
351 gnt_menu_toggled(GntTree *tree, gpointer key) | |
352 { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
353 GntMenuItem *item = GNT_MENU_ITEM(key); |
15818 | 354 GntMenu *menu = GNT_MENU(tree); |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
355 gboolean check = gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item)); |
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
356 gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), !check); |
21256
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
357 gnt_menuitem_activate(item); |
15818 | 358 while (menu) { |
359 gnt_widget_hide(GNT_WIDGET(menu)); | |
360 menu = menu->parentmenu; | |
361 } | |
362 } | |
363 | |
364 static void | |
365 gnt_menu_activate(GntWidget *widget) | |
366 { | |
367 GntMenu *menu = GNT_MENU(widget); | |
368 GntMenuItem *item; | |
369 | |
370 if (menu->type == GNT_MENU_TOPLEVEL) { | |
371 item = g_list_nth_data(menu->list, menu->selected); | |
372 } else { | |
373 item = gnt_tree_get_selection_data(GNT_TREE(menu)); | |
374 } | |
375 | |
376 if (item) { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
377 if (GNT_IS_MENU_ITEM_CHECK(item)) |
15818 | 378 gnt_menu_toggled(GNT_TREE(widget), item); |
379 else | |
380 menuitem_activate(menu, item); | |
381 } | |
382 } | |
383 | |
384 static void | |
385 gnt_menu_hide(GntWidget *widget) | |
386 { | |
16731
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
387 GntMenu *sub, *menu = GNT_MENU(widget); |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
388 |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
389 while ((sub = menu->submenu)) |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
390 gnt_widget_hide(GNT_WIDGET(sub)); |
15818 | 391 if (menu->parentmenu) |
392 menu->parentmenu->submenu = NULL; | |
393 } | |
394 | |
22309
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
395 static gboolean |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
396 gnt_menu_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
397 { |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
398 if (!org_clicked || !org_clicked(widget, event, x, y) || |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
399 !GNT_MENU(widget)->type == GNT_MENU_TOPLEVEL) |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
400 return FALSE; |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
401 gnt_widget_activate(widget); |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
402 return TRUE; |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
403 } |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
404 |
15818 | 405 static void |
406 gnt_menu_class_init(GntMenuClass *klass) | |
407 { | |
408 GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass); | |
409 parent_class = GNT_TREE_CLASS(klass); | |
410 | |
411 org_destroy = wid_class->destroy; | |
412 org_map = wid_class->map; | |
413 org_draw = wid_class->draw; | |
414 org_key_pressed = wid_class->key_pressed; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
415 org_size_request = wid_class->size_request; |
22309
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
416 org_clicked = wid_class->clicked; |
15818 | 417 |
418 wid_class->destroy = gnt_menu_destroy; | |
419 wid_class->draw = gnt_menu_draw; | |
420 wid_class->map = gnt_menu_map; | |
421 wid_class->size_request = gnt_menu_size_request; | |
422 wid_class->key_pressed = gnt_menu_key_pressed; | |
423 wid_class->activate = gnt_menu_activate; | |
424 wid_class->hide = gnt_menu_hide; | |
22309
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
425 wid_class->clicked = gnt_menu_clicked; |
15818 | 426 |
427 parent_class->toggled = gnt_menu_toggled; | |
428 | |
429 GNTDEBUG; | |
430 } | |
431 | |
432 static void | |
433 gnt_menu_init(GTypeInstance *instance, gpointer class) | |
434 { | |
435 GntWidget *widget = GNT_WIDGET(instance); | |
436 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | | |
437 GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_TRANSIENT); | |
438 GNTDEBUG; | |
439 } | |
440 | |
441 /****************************************************************************** | |
442 * GntMenu API | |
443 *****************************************************************************/ | |
444 GType | |
445 gnt_menu_get_gtype(void) | |
446 { | |
447 static GType type = 0; | |
448 | |
449 if(type == 0) | |
450 { | |
451 static const GTypeInfo info = { | |
452 sizeof(GntMenuClass), | |
453 NULL, /* base_init */ | |
454 NULL, /* base_finalize */ | |
455 (GClassInitFunc)gnt_menu_class_init, | |
456 NULL, /* class_finalize */ | |
457 NULL, /* class_data */ | |
458 sizeof(GntMenu), | |
459 0, /* n_preallocs */ | |
460 gnt_menu_init, /* instance_init */ | |
461 NULL /* value_table */ | |
462 }; | |
463 | |
464 type = g_type_register_static(GNT_TYPE_TREE, | |
465 "GntMenu", | |
466 &info, 0); | |
467 } | |
468 | |
469 return type; | |
470 } | |
471 | |
472 GntWidget *gnt_menu_new(GntMenuType type) | |
473 { | |
474 GntWidget *widget = g_object_new(GNT_TYPE_MENU, NULL); | |
475 GntMenu *menu = GNT_MENU(widget); | |
476 menu->list = NULL; | |
477 menu->selected = 0; | |
478 menu->type = type; | |
479 | |
480 if (type == GNT_MENU_TOPLEVEL) { | |
481 widget->priv.x = 0; | |
482 widget->priv.y = 0; | |
483 } else { | |
484 GNT_TREE(widget)->show_separator = FALSE; | |
18531
da550279d390
Use gobject properties instead of hacks when creating columns in a tree.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18447
diff
changeset
|
485 g_object_set(G_OBJECT(widget), "columns", NUM_COLUMNS, NULL); |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
486 gnt_tree_set_col_width(GNT_TREE(widget), ITEM_TRIGGER, 3); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
487 gnt_tree_set_column_resizable(GNT_TREE(widget), ITEM_TRIGGER, FALSE); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
488 gnt_tree_set_col_width(GNT_TREE(widget), ITEM_SUBMENU, 1); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
489 gnt_tree_set_column_resizable(GNT_TREE(widget), ITEM_SUBMENU, FALSE); |
15818 | 490 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
491 } | |
492 | |
493 return widget; | |
494 } | |
495 | |
496 void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item) | |
497 { | |
498 menu->list = g_list_append(menu->list, item); | |
499 } | |
500 | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
501 GntMenuItem *gnt_menu_get_item(GntMenu *menu, const char *id) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
502 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
503 GntMenuItem *item = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
504 GList *iter = menu->list; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
505 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
506 if (!id || !*id) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
507 return NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
508 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
509 for (; iter; iter = iter->next) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
510 GntMenu *sub; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
511 item = iter->data; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
512 sub = gnt_menuitem_get_submenu(item); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
513 if (sub) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
514 item = gnt_menu_get_item(sub, id); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
515 if (item) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
516 break; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
517 } else { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
518 const char *itid = gnt_menuitem_get_id(item); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
519 if (itid && strcmp(itid, id) == 0) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
520 break; |
21215
4c7604b4841c
Add a note: Perhaps look at menu-labels if it doesn't have an ID when processing an accelerator key.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21212
diff
changeset
|
521 /* XXX: Perhaps look at the menu-label as well? */ |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
522 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
523 item = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
524 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
525 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
526 return item; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
527 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
528 |