Mercurial > pidgin.yaz
annotate finch/libgnt/gntmenu.c @ 29368:746bf7d8b34e
Combine the CurrentMedia and MsnUserPhoneInfo structs. This makes
MsnUser smaller by the size of one pointer.
Since both of these structs are used only rarely, this ends up saving
memory for most people.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 05 Feb 2010 02:19:22 +0000 |
parents | a18f421696dc |
children |
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 |
28984
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24041
diff
changeset
|
23 #include "gntinternal.h" |
15818 | 24 #include "gntmenu.h" |
25 #include "gntmenuitemcheck.h" | |
26 | |
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
|
27 #include <ctype.h> |
15818 | 28 #include <string.h> |
29 | |
30 enum | |
31 { | |
32 SIGS = 1, | |
33 }; | |
34 | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
35 enum |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
36 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
37 ITEM_TEXT = 0, |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
38 ITEM_TRIGGER, |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
39 ITEM_SUBMENU, |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
40 NUM_COLUMNS |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
41 }; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
42 |
15818 | 43 static GntTreeClass *parent_class = NULL; |
44 | |
45 static void (*org_draw)(GntWidget *wid); | |
46 static void (*org_destroy)(GntWidget *wid); | |
47 static void (*org_map)(GntWidget *wid); | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
48 static void (*org_size_request)(GntWidget *wid); |
15818 | 49 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
|
50 static gboolean (*org_clicked)(GntWidget *w, GntMouseEvent event, int x, int y); |
15818 | 51 |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
52 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
|
53 |
15818 | 54 static void |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
55 menu_hide_all(GntMenu *menu) |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
56 { |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
57 while (menu->parentmenu) |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
58 menu = menu->parentmenu; |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
59 gnt_widget_hide(GNT_WIDGET(menu)); |
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 |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
62 static void |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
63 show_submenu(GntMenu *menu) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
64 { |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
65 GntMenuItem *item; |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
66 |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
67 if (menu->type != GNT_MENU_TOPLEVEL) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
68 return; |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
69 |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
70 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
|
71 if (!item || !item->submenu) |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
72 return; |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
73 menuitem_activate(menu, item); |
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 |
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
76 static void |
15818 | 77 gnt_menu_draw(GntWidget *widget) |
78 { | |
79 GntMenu *menu = GNT_MENU(widget); | |
80 GList *iter; | |
81 chtype type; | |
82 int i; | |
83 | |
84 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
|
85 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
15818 | 86 werase(widget->window); |
87 | |
88 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
|
89 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
|
90 type = ' ' | gnt_color_pair(GNT_COLOR_HIGHLIGHT); |
15818 | 91 if (i == menu->selected) |
92 type |= A_REVERSE; | |
93 item->priv.x = getcurx(widget->window) + widget->priv.x; | |
94 item->priv.y = getcury(widget->window) + widget->priv.y + 1; | |
95 wbkgdset(widget->window, type); | |
28984
a18f421696dc
Fix showing umlauts etc. on non-utf8 locales.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24041
diff
changeset
|
96 wprintw(widget->window, " %s ", C_(item->text)); |
15818 | 97 } |
98 } else { | |
99 org_draw(widget); | |
100 } | |
101 | |
102 GNTDEBUG; | |
103 } | |
104 | |
105 static void | |
106 gnt_menu_size_request(GntWidget *widget) | |
107 { | |
108 GntMenu *menu = GNT_MENU(widget); | |
109 | |
110 if (menu->type == GNT_MENU_TOPLEVEL) { | |
111 widget->priv.height = 1; | |
112 widget->priv.width = getmaxx(stdscr); | |
113 } else { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
114 org_size_request(widget); |
15818 | 115 widget->priv.height = g_list_length(menu->list) + 2; |
116 } | |
117 } | |
118 | |
119 static void | |
120 menu_tree_add(GntMenu *menu, GntMenuItem *item, GntMenuItem *parent) | |
121 { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
122 char trigger[4] = "\0 )\0"; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
123 |
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
|
124 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
|
125 trigger[0] = '('; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
126 |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
127 if (GNT_IS_MENU_ITEM_CHECK(item)) { |
15818 | 128 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
|
129 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
|
130 gnt_tree_set_choice(GNT_TREE(menu), item, gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); |
15818 | 131 } else |
132 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
|
133 gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, item->submenu ? ">" : " "), parent); |
15818 | 134 |
135 if (0 && item->submenu) { | |
136 GntMenu *sub = GNT_MENU(item->submenu); | |
137 GList *iter; | |
138 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
|
139 GntMenuItem *it = GNT_MENU_ITEM(iter->data); |
15818 | 140 menu_tree_add(menu, it, item); |
141 } | |
142 } | |
143 } | |
144 | |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
145 #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
|
146 |
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 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
|
148 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
|
149 { |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
150 GList *iter; |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
151 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
|
152 |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
153 memset(bools, 0, sizeof(bools)); |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
154 bools[36] = 1; |
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
155 |
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
|
156 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
|
157 GntMenuItem *item = iter->data; |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 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
|
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 |
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 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 } |
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 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
|
179 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
|
180 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
|
181 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
|
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 } |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
184 |
15818 | 185 static void |
186 gnt_menu_map(GntWidget *widget) | |
187 { | |
188 GntMenu *menu = GNT_MENU(widget); | |
189 | |
190 if (menu->type == GNT_MENU_TOPLEVEL) { | |
191 gnt_widget_size_request(widget); | |
192 } else { | |
193 /* Populate the tree */ | |
194 GList *iter; | |
195 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
|
196 /* 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
|
197 assign_triggers(menu); |
15818 | 198 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
|
199 GntMenuItem *item = GNT_MENU_ITEM(iter->data); |
15818 | 200 menu_tree_add(menu, item, NULL); |
201 } | |
202 org_map(widget); | |
203 gnt_tree_adjust_columns(GNT_TREE(widget)); | |
204 } | |
205 GNTDEBUG; | |
206 } | |
207 | |
208 static void | |
209 menuitem_activate(GntMenu *menu, GntMenuItem *item) | |
210 { | |
21256
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
211 if (!item) |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
212 return; |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
213 |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
214 if (gnt_menuitem_activate(item)) { |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
215 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
|
216 } else { |
15818 | 217 if (item->submenu) { |
218 GntMenu *sub = GNT_MENU(item->submenu); | |
219 menu->submenu = sub; | |
220 sub->type = GNT_MENU_POPUP; /* Submenus are *never* toplevel */ | |
221 sub->parentmenu = menu; | |
222 if (menu->type != GNT_MENU_TOPLEVEL) { | |
223 GntWidget *widget = GNT_WIDGET(menu); | |
224 item->priv.x = widget->priv.x + widget->priv.width - 1; | |
225 item->priv.y = widget->priv.y + gnt_tree_get_selection_visible_line(GNT_TREE(menu)); | |
226 } | |
227 gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y); | |
228 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE); | |
229 gnt_widget_draw(GNT_WIDGET(sub)); | |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
230 } else { |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
231 menu_hide_all(menu); |
15818 | 232 } |
233 } | |
234 } | |
235 | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
236 static GList* |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
237 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
|
238 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
239 GList *iter; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
240 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
|
241 if (gnt_menuitem_get_trigger(iter->data) == trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
242 return iter; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
243 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
244 return NULL; |
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 |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
247 static gboolean |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
248 check_for_trigger(GntMenu *menu, char trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
249 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
250 /* check for a trigger key */ |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
251 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
|
252 GList *find; |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
253 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
|
254 |
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 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
|
256 return FALSE; |
21454
d78e440584e0
Add maximize flags for windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21260
diff
changeset
|
257 |
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
|
258 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
|
259 if (!find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
260 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
|
261 if (!find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
262 return FALSE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
263 if (find != nth) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
264 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
|
265 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
|
266 if (iter != NULL && iter != find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
267 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
268 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
|
269 if (iter != NULL && iter != find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
270 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
271 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
272 gnt_widget_activate(GNT_WIDGET(menu)); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
273 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
274 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
275 |
15818 | 276 static gboolean |
277 gnt_menu_key_pressed(GntWidget *widget, const char *text) | |
278 { | |
279 GntMenu *menu = GNT_MENU(widget); | |
280 int current = menu->selected; | |
281 | |
282 if (menu->submenu) { | |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
283 GntMenu *sub = menu; |
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
284 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
|
285 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
|
286 return TRUE; |
23345
9a7520e489f8
Fix some key-press issues on nested popup menus where pressing up/down
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22871
diff
changeset
|
287 if (menu->type != GNT_MENU_TOPLEVEL) |
9a7520e489f8
Fix some key-press issues on nested popup menus where pressing up/down
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22871
diff
changeset
|
288 return FALSE; |
15818 | 289 } |
290 | |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
291 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
|
292 (menu->type != GNT_MENU_TOPLEVEL && strcmp(text, GNT_KEY_LEFT) == 0)) { |
15818 | 293 /* Escape closes menu */ |
294 GntMenu *par = menu->parentmenu; | |
295 if (par != NULL) { | |
296 par->submenu = NULL; | |
297 gnt_widget_hide(widget); | |
298 } else | |
299 gnt_widget_hide(widget); | |
21625
e5606c720791
Improve the 'menu experience' a little bit.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21483
diff
changeset
|
300 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
|
301 gnt_menu_key_pressed(GNT_WIDGET(par), text); |
15818 | 302 return TRUE; |
303 } | |
304 | |
305 if (menu->type == GNT_MENU_TOPLEVEL) { | |
306 if (strcmp(text, GNT_KEY_LEFT) == 0) { | |
307 menu->selected--; | |
308 if (menu->selected < 0) | |
309 menu->selected = g_list_length(menu->list) - 1; | |
310 } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { | |
311 menu->selected++; | |
312 if (menu->selected >= g_list_length(menu->list)) | |
313 menu->selected = 0; | |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
314 } 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
|
315 strcmp(text, GNT_KEY_DOWN) == 0) { |
15818 | 316 gnt_widget_activate(widget); |
317 } | |
318 | |
319 if (current != menu->selected) { | |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
320 GntMenu *sub = menu->submenu; |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
321 if (sub) |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
322 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
|
323 show_submenu(menu); |
15818 | 324 gnt_widget_draw(widget); |
325 return TRUE; | |
326 } | |
327 } else { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
328 if (text[1] == '\0') { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
329 if (check_for_trigger(menu, text[0])) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
330 return TRUE; |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
331 } 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
|
332 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
|
333 if (item && item->submenu) { |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
334 menuitem_activate(menu, item); |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
335 return TRUE; |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
336 } |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
337 } |
23345
9a7520e489f8
Fix some key-press issues on nested popup menus where pressing up/down
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22871
diff
changeset
|
338 if (gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text)) |
9a7520e489f8
Fix some key-press issues on nested popup menus where pressing up/down
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22871
diff
changeset
|
339 return TRUE; |
15818 | 340 return org_key_pressed(widget, text); |
341 } | |
342 | |
23345
9a7520e489f8
Fix some key-press issues on nested popup menus where pressing up/down
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22871
diff
changeset
|
343 return gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text); |
15818 | 344 } |
345 | |
346 static void | |
347 gnt_menu_destroy(GntWidget *widget) | |
348 { | |
349 GntMenu *menu = GNT_MENU(widget); | |
350 g_list_foreach(menu->list, (GFunc)g_object_unref, NULL); | |
351 g_list_free(menu->list); | |
352 org_destroy(widget); | |
353 } | |
354 | |
355 static void | |
356 gnt_menu_toggled(GntTree *tree, gpointer key) | |
357 { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
358 GntMenuItem *item = GNT_MENU_ITEM(key); |
15818 | 359 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
|
360 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
|
361 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
|
362 gnt_menuitem_activate(item); |
15818 | 363 while (menu) { |
364 gnt_widget_hide(GNT_WIDGET(menu)); | |
365 menu = menu->parentmenu; | |
366 } | |
367 } | |
368 | |
369 static void | |
370 gnt_menu_activate(GntWidget *widget) | |
371 { | |
372 GntMenu *menu = GNT_MENU(widget); | |
373 GntMenuItem *item; | |
374 | |
375 if (menu->type == GNT_MENU_TOPLEVEL) { | |
376 item = g_list_nth_data(menu->list, menu->selected); | |
377 } else { | |
378 item = gnt_tree_get_selection_data(GNT_TREE(menu)); | |
379 } | |
380 | |
381 if (item) { | |
15931
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
382 if (GNT_IS_MENU_ITEM_CHECK(item)) |
15818 | 383 gnt_menu_toggled(GNT_TREE(widget), item); |
384 else | |
385 menuitem_activate(menu, item); | |
386 } | |
387 } | |
388 | |
389 static void | |
390 gnt_menu_hide(GntWidget *widget) | |
391 { | |
16731
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
392 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
|
393 |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15931
diff
changeset
|
394 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
|
395 gnt_widget_hide(GNT_WIDGET(sub)); |
15818 | 396 if (menu->parentmenu) |
397 menu->parentmenu->submenu = NULL; | |
398 } | |
399 | |
22309
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
400 static gboolean |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
401 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
|
402 { |
24041
fe2d4fc77b05
Fix handling mouse events with menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23345
diff
changeset
|
403 if (GNT_MENU(widget)->type != GNT_MENU_POPUP) |
fe2d4fc77b05
Fix handling mouse events with menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23345
diff
changeset
|
404 return FALSE; |
fe2d4fc77b05
Fix handling mouse events with menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23345
diff
changeset
|
405 |
fe2d4fc77b05
Fix handling mouse events with menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23345
diff
changeset
|
406 if (org_clicked && org_clicked(widget, event, x, y)) |
fe2d4fc77b05
Fix handling mouse events with menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23345
diff
changeset
|
407 return TRUE; |
22309
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
408 gnt_widget_activate(widget); |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
409 return TRUE; |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
410 } |
07073da46dd5
Single clicking a menuitem should activate it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21625
diff
changeset
|
411 |
15818 | 412 static void |
413 gnt_menu_class_init(GntMenuClass *klass) | |
414 { | |
415 GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass); | |
416 parent_class = GNT_TREE_CLASS(klass); | |
417 | |
418 org_destroy = wid_class->destroy; | |
419 org_map = wid_class->map; | |
420 org_draw = wid_class->draw; | |
421 org_key_pressed = wid_class->key_pressed; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
422 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
|
423 org_clicked = wid_class->clicked; |
15818 | 424 |
425 wid_class->destroy = gnt_menu_destroy; | |
426 wid_class->draw = gnt_menu_draw; | |
427 wid_class->map = gnt_menu_map; | |
428 wid_class->size_request = gnt_menu_size_request; | |
429 wid_class->key_pressed = gnt_menu_key_pressed; | |
430 wid_class->activate = gnt_menu_activate; | |
431 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
|
432 wid_class->clicked = gnt_menu_clicked; |
15818 | 433 |
434 parent_class->toggled = gnt_menu_toggled; | |
435 | |
436 GNTDEBUG; | |
437 } | |
438 | |
439 static void | |
440 gnt_menu_init(GTypeInstance *instance, gpointer class) | |
441 { | |
442 GntWidget *widget = GNT_WIDGET(instance); | |
443 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | | |
23345
9a7520e489f8
Fix some key-press issues on nested popup menus where pressing up/down
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22871
diff
changeset
|
444 GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_TRANSIENT | GNT_WIDGET_DISABLE_ACTIONS); |
15818 | 445 GNTDEBUG; |
446 } | |
447 | |
448 /****************************************************************************** | |
449 * GntMenu API | |
450 *****************************************************************************/ | |
451 GType | |
452 gnt_menu_get_gtype(void) | |
453 { | |
454 static GType type = 0; | |
455 | |
456 if(type == 0) | |
457 { | |
458 static const GTypeInfo info = { | |
459 sizeof(GntMenuClass), | |
460 NULL, /* base_init */ | |
461 NULL, /* base_finalize */ | |
462 (GClassInitFunc)gnt_menu_class_init, | |
463 NULL, /* class_finalize */ | |
464 NULL, /* class_data */ | |
465 sizeof(GntMenu), | |
466 0, /* n_preallocs */ | |
467 gnt_menu_init, /* instance_init */ | |
468 NULL /* value_table */ | |
469 }; | |
470 | |
471 type = g_type_register_static(GNT_TYPE_TREE, | |
472 "GntMenu", | |
473 &info, 0); | |
474 } | |
475 | |
476 return type; | |
477 } | |
478 | |
479 GntWidget *gnt_menu_new(GntMenuType type) | |
480 { | |
481 GntWidget *widget = g_object_new(GNT_TYPE_MENU, NULL); | |
482 GntMenu *menu = GNT_MENU(widget); | |
483 menu->list = NULL; | |
484 menu->selected = 0; | |
485 menu->type = type; | |
486 | |
487 if (type == GNT_MENU_TOPLEVEL) { | |
488 widget->priv.x = 0; | |
489 widget->priv.y = 0; | |
490 } else { | |
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 gnt_tree_set_column_resizable(GNT_TREE(widget), ITEM_SUBMENU, FALSE); |
15818 | 497 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
498 } | |
499 | |
500 return widget; | |
501 } | |
502 | |
503 void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item) | |
504 { | |
505 menu->list = g_list_append(menu->list, item); | |
506 } | |
507 | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
508 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
|
509 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
510 GntMenuItem *item = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
511 GList *iter = menu->list; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
512 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
513 if (!id || !*id) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
514 return NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
515 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
516 for (; iter; iter = iter->next) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
517 GntMenu *sub; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
518 item = iter->data; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
519 sub = gnt_menuitem_get_submenu(item); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
520 if (sub) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
521 item = gnt_menu_get_item(sub, id); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
522 if (item) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
523 break; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
524 } else { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
525 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
|
526 if (itid && strcmp(itid, id) == 0) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
527 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
|
528 /* 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
|
529 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
530 item = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
531 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
532 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
533 return item; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
534 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
535 |