Mercurial > pidgin
annotate finch/libgnt/gntmenu.c @ 21426:8ffb65f3c0e9
Clarify PURPLE_CONNECTION_ERROR_INVALID_USERNAME slightly.
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Sun, 11 Nov 2007 21:56:58 +0000 |
parents | 084c5d5472ad |
children | d78e440584e0 |
rev | line source |
---|---|
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
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:
15928
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:
15928
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
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:
15928
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:
15928
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:
15928
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
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:
15928
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
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:
15928
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19681
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19662
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
17928
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
15928
diff
changeset
|
22 |
15817 | 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> |
15817 | 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 |
15817 | 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); |
15817 | 48 static gboolean (*org_key_pressed)(GntWidget *w, const char *t); |
49 | |
50 static void | |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
51 menu_hide_all(GntMenu *menu) |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
52 { |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
53 while (menu->parentmenu) |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
54 menu = menu->parentmenu; |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
55 gnt_widget_hide(GNT_WIDGET(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 |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
58 static void |
15817 | 59 gnt_menu_draw(GntWidget *widget) |
60 { | |
61 GntMenu *menu = GNT_MENU(widget); | |
62 GList *iter; | |
63 chtype type; | |
64 int i; | |
65 | |
66 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
|
67 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT)); |
15817 | 68 werase(widget->window); |
69 | |
70 for (i = 0, iter = menu->list; iter; iter = iter->next, i++) { | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
71 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
|
72 type = ' ' | gnt_color_pair(GNT_COLOR_HIGHLIGHT); |
15817 | 73 if (i == menu->selected) |
74 type |= A_REVERSE; | |
75 item->priv.x = getcurx(widget->window) + widget->priv.x; | |
76 item->priv.y = getcury(widget->window) + widget->priv.y + 1; | |
77 wbkgdset(widget->window, type); | |
78 wprintw(widget->window, " %s ", item->text); | |
79 } | |
80 } else { | |
81 org_draw(widget); | |
82 } | |
83 | |
84 GNTDEBUG; | |
85 } | |
86 | |
87 static void | |
88 gnt_menu_size_request(GntWidget *widget) | |
89 { | |
90 GntMenu *menu = GNT_MENU(widget); | |
91 | |
92 if (menu->type == GNT_MENU_TOPLEVEL) { | |
93 widget->priv.height = 1; | |
94 widget->priv.width = getmaxx(stdscr); | |
95 } else { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
96 org_size_request(widget); |
15817 | 97 widget->priv.height = g_list_length(menu->list) + 2; |
98 } | |
99 } | |
100 | |
101 static void | |
102 menu_tree_add(GntMenu *menu, GntMenuItem *item, GntMenuItem *parent) | |
103 { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
104 char trigger[4] = "\0 )\0"; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
105 |
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
|
106 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
|
107 trigger[0] = '('; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
108 |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
109 if (GNT_IS_MENU_ITEM_CHECK(item)) { |
15817 | 110 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
|
111 gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, " "), parent, NULL); |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
112 gnt_tree_set_choice(GNT_TREE(menu), item, gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); |
15817 | 113 } else |
114 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
|
115 gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, item->submenu ? ">" : " "), parent); |
15817 | 116 |
117 if (0 && item->submenu) { | |
118 GntMenu *sub = GNT_MENU(item->submenu); | |
119 GList *iter; | |
120 for (iter = sub->list; iter; iter = iter->next) { | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
121 GntMenuItem *it = GNT_MENU_ITEM(iter->data); |
15817 | 122 menu_tree_add(menu, it, item); |
123 } | |
124 } | |
125 } | |
126 | |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
127 #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
|
128 |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
129 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
|
130 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
|
131 { |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
132 GList *iter; |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
133 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
|
134 |
daf41b214ffb
Try to automatically assign some hotkeys for the menuitems. Do we like this?
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18440
diff
changeset
|
135 memset(bools, 0, sizeof(bools)); |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
136 bools[36] = 1; |
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
137 |
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
|
138 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
|
139 GntMenuItem *item = iter->data; |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 } |
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 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 char ch = tolower(*text++); |
18447
8fc91e437981
Possible crash fix.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18444
diff
changeset
|
154 if (ch == ' ' || bools[(int)GET_VAL(ch)]) |
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 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
|
156 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
|
157 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
|
158 } |
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) |
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 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
|
161 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
|
162 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
|
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 } |
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 |
15817 | 166 static void |
167 gnt_menu_map(GntWidget *widget) | |
168 { | |
169 GntMenu *menu = GNT_MENU(widget); | |
170 | |
171 if (menu->type == GNT_MENU_TOPLEVEL) { | |
172 gnt_widget_size_request(widget); | |
173 } else { | |
174 /* Populate the tree */ | |
175 GList *iter; | |
176 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
|
177 /* 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
|
178 assign_triggers(menu); |
15817 | 179 for (iter = menu->list; iter; iter = iter->next) { |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
180 GntMenuItem *item = GNT_MENU_ITEM(iter->data); |
15817 | 181 menu_tree_add(menu, item, NULL); |
182 } | |
183 org_map(widget); | |
184 gnt_tree_adjust_columns(GNT_TREE(widget)); | |
185 } | |
186 GNTDEBUG; | |
187 } | |
188 | |
189 static void | |
190 menuitem_activate(GntMenu *menu, GntMenuItem *item) | |
191 { | |
21256
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
192 if (!item) |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
193 return; |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
194 |
e8b0f224483f
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21250
diff
changeset
|
195 if (gnt_menuitem_activate(item)) { |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
196 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
|
197 } else { |
15817 | 198 if (item->submenu) { |
199 GntMenu *sub = GNT_MENU(item->submenu); | |
200 menu->submenu = sub; | |
201 sub->type = GNT_MENU_POPUP; /* Submenus are *never* toplevel */ | |
202 sub->parentmenu = menu; | |
203 if (menu->type != GNT_MENU_TOPLEVEL) { | |
204 GntWidget *widget = GNT_WIDGET(menu); | |
205 item->priv.x = widget->priv.x + widget->priv.width - 1; | |
206 item->priv.y = widget->priv.y + gnt_tree_get_selection_visible_line(GNT_TREE(menu)); | |
207 } | |
208 gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y); | |
209 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE); | |
210 gnt_widget_draw(GNT_WIDGET(sub)); | |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
211 } else { |
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
212 menu_hide_all(menu); |
15817 | 213 } |
214 } | |
215 } | |
216 | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
217 static GList* |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
218 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
|
219 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
220 GList *iter; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
221 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
|
222 if (gnt_menuitem_get_trigger(iter->data) == trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
223 return iter; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
224 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
225 return NULL; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
226 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
227 |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
228 static gboolean |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
229 check_for_trigger(GntMenu *menu, char trigger) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
230 { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
231 /* check for a trigger key */ |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
232 GList *iter; |
19652
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
|
233 GList *find; |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
234 GList *nth = g_list_find(menu->list, gnt_tree_get_selection_data(GNT_TREE(menu))); |
19652
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
|
235 |
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
|
236 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
|
237 return FALSE; |
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
|
238 |
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
|
239 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
|
240 if (!find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
241 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
|
242 if (!find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
243 return FALSE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
244 if (find != nth) { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
245 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
|
246 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
|
247 if (iter != NULL && iter != find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
248 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
249 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
|
250 if (iter != NULL && iter != find) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
251 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
252 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
253 gnt_widget_activate(GNT_WIDGET(menu)); |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
254 return TRUE; |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
255 } |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
256 |
15817 | 257 static gboolean |
258 gnt_menu_key_pressed(GntWidget *widget, const char *text) | |
259 { | |
260 GntMenu *menu = GNT_MENU(widget); | |
261 int current = menu->selected; | |
262 | |
263 if (menu->submenu) { | |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
264 GntMenu *sub = menu; |
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
265 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
|
266 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
|
267 return TRUE; |
15817 | 268 } |
269 | |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
270 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
|
271 (menu->type != GNT_MENU_TOPLEVEL && strcmp(text, GNT_KEY_LEFT) == 0)) { |
15817 | 272 /* Escape closes menu */ |
273 GntMenu *par = menu->parentmenu; | |
274 if (par != NULL) { | |
275 par->submenu = NULL; | |
276 gnt_widget_hide(widget); | |
277 } else | |
278 gnt_widget_hide(widget); | |
279 return TRUE; | |
280 } | |
281 | |
282 if (menu->type == GNT_MENU_TOPLEVEL) { | |
283 if (strcmp(text, GNT_KEY_LEFT) == 0) { | |
284 menu->selected--; | |
285 if (menu->selected < 0) | |
286 menu->selected = g_list_length(menu->list) - 1; | |
287 } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { | |
288 menu->selected++; | |
289 if (menu->selected >= g_list_length(menu->list)) | |
290 menu->selected = 0; | |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
291 } 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
|
292 strcmp(text, GNT_KEY_DOWN) == 0) { |
15817 | 293 gnt_widget_activate(widget); |
294 } | |
295 | |
296 if (current != menu->selected) { | |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
297 GntMenu *sub = menu->submenu; |
21260
084c5d5472ad
Fix menu hiding.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21256
diff
changeset
|
298 if (sub) |
18875
6a911f06aa46
Some more navigation improvement for the menus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18874
diff
changeset
|
299 gnt_widget_hide(GNT_WIDGET(sub)); |
15817 | 300 gnt_widget_draw(widget); |
301 return TRUE; | |
302 } | |
303 } else { | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
304 if (text[1] == '\0') { |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
305 if (check_for_trigger(menu, text[0])) |
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
306 return TRUE; |
18874
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
307 } 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
|
308 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
|
309 if (item && item->submenu) { |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
310 menuitem_activate(menu, item); |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
311 return TRUE; |
5dd1cfc53666
Make the menus a little more usable.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18531
diff
changeset
|
312 } |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
313 } |
15817 | 314 return org_key_pressed(widget, text); |
315 } | |
316 | |
317 return FALSE; | |
318 } | |
319 | |
320 static void | |
321 gnt_menu_destroy(GntWidget *widget) | |
322 { | |
323 GntMenu *menu = GNT_MENU(widget); | |
324 g_list_foreach(menu->list, (GFunc)g_object_unref, NULL); | |
325 g_list_free(menu->list); | |
326 org_destroy(widget); | |
327 } | |
328 | |
329 static void | |
330 gnt_menu_toggled(GntTree *tree, gpointer key) | |
331 { | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
332 GntMenuItem *item = GNT_MENU_ITEM(key); |
15817 | 333 GntMenu *menu = GNT_MENU(tree); |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
334 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:
15817
diff
changeset
|
335 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
|
336 gnt_menuitem_activate(item); |
15817 | 337 while (menu) { |
338 gnt_widget_hide(GNT_WIDGET(menu)); | |
339 menu = menu->parentmenu; | |
340 } | |
341 } | |
342 | |
343 static void | |
344 gnt_menu_activate(GntWidget *widget) | |
345 { | |
346 GntMenu *menu = GNT_MENU(widget); | |
347 GntMenuItem *item; | |
348 | |
349 if (menu->type == GNT_MENU_TOPLEVEL) { | |
350 item = g_list_nth_data(menu->list, menu->selected); | |
351 } else { | |
352 item = gnt_tree_get_selection_data(GNT_TREE(menu)); | |
353 } | |
354 | |
355 if (item) { | |
15928
f00f2e283ffb
Some define changes. This helps in generating the python bindings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
356 if (GNT_IS_MENU_ITEM_CHECK(item)) |
15817 | 357 gnt_menu_toggled(GNT_TREE(widget), item); |
358 else | |
359 menuitem_activate(menu, item); | |
360 } | |
361 } | |
362 | |
363 static void | |
364 gnt_menu_hide(GntWidget *widget) | |
365 { | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
366 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:
15928
diff
changeset
|
367 |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
368 while ((sub = menu->submenu)) |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
15928
diff
changeset
|
369 gnt_widget_hide(GNT_WIDGET(sub)); |
15817 | 370 if (menu->parentmenu) |
371 menu->parentmenu->submenu = NULL; | |
372 } | |
373 | |
374 static void | |
375 gnt_menu_class_init(GntMenuClass *klass) | |
376 { | |
377 GntWidgetClass *wid_class = GNT_WIDGET_CLASS(klass); | |
378 parent_class = GNT_TREE_CLASS(klass); | |
379 | |
380 org_destroy = wid_class->destroy; | |
381 org_map = wid_class->map; | |
382 org_draw = wid_class->draw; | |
383 org_key_pressed = wid_class->key_pressed; | |
18440
be10fc22d649
Allow trigger keys for menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18404
diff
changeset
|
384 org_size_request = wid_class->size_request; |
15817 | 385 |
386 wid_class->destroy = gnt_menu_destroy; | |
387 wid_class->draw = gnt_menu_draw; | |
388 wid_class->map = gnt_menu_map; | |
389 wid_class->size_request = gnt_menu_size_request; | |
390 wid_class->key_pressed = gnt_menu_key_pressed; | |
391 wid_class->activate = gnt_menu_activate; | |
392 wid_class->hide = gnt_menu_hide; | |
393 | |
394 parent_class->toggled = gnt_menu_toggled; | |
395 | |
396 GNTDEBUG; | |
397 } | |
398 | |
399 static void | |
400 gnt_menu_init(GTypeInstance *instance, gpointer class) | |
401 { | |
402 GntWidget *widget = GNT_WIDGET(instance); | |
403 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW | GNT_WIDGET_NO_BORDER | | |
404 GNT_WIDGET_CAN_TAKE_FOCUS | GNT_WIDGET_TRANSIENT); | |
405 GNTDEBUG; | |
406 } | |
407 | |
408 /****************************************************************************** | |
409 * GntMenu API | |
410 *****************************************************************************/ | |
411 GType | |
412 gnt_menu_get_gtype(void) | |
413 { | |
414 static GType type = 0; | |
415 | |
416 if(type == 0) | |
417 { | |
418 static const GTypeInfo info = { | |
419 sizeof(GntMenuClass), | |
420 NULL, /* base_init */ | |
421 NULL, /* base_finalize */ | |
422 (GClassInitFunc)gnt_menu_class_init, | |
423 NULL, /* class_finalize */ | |
424 NULL, /* class_data */ | |
425 sizeof(GntMenu), | |
426 0, /* n_preallocs */ | |
427 gnt_menu_init, /* instance_init */ | |
428 NULL /* value_table */ | |
429 }; | |
430 | |
431 type = g_type_register_static(GNT_TYPE_TREE, | |
432 "GntMenu", | |
433 &info, 0); | |
434 } | |
435 | |
436 return type; | |
437 } | |
438 | |
439 GntWidget *gnt_menu_new(GntMenuType type) | |
440 { | |
441 GntWidget *widget = g_object_new(GNT_TYPE_MENU, NULL); | |
442 GntMenu *menu = GNT_MENU(widget); | |
443 menu->list = NULL; | |
444 menu->selected = 0; | |
445 menu->type = type; | |
446 | |
447 if (type == GNT_MENU_TOPLEVEL) { | |
448 widget->priv.x = 0; | |
449 widget->priv.y = 0; | |
450 } else { | |
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 gnt_tree_set_column_resizable(GNT_TREE(widget), ITEM_SUBMENU, FALSE); |
15817 | 457 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_NO_BORDER); |
458 } | |
459 | |
460 return widget; | |
461 } | |
462 | |
463 void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item) | |
464 { | |
465 menu->list = g_list_append(menu->list, item); | |
466 } | |
467 | |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
468 GntMenuItem *gnt_menu_get_item(GntMenu *menu, const char *id) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
469 { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
470 GntMenuItem *item = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
471 GList *iter = menu->list; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
472 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
473 if (!id || !*id) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
474 return NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
475 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
476 for (; iter; iter = iter->next) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
477 GntMenu *sub; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
478 item = iter->data; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
479 sub = gnt_menuitem_get_submenu(item); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
480 if (sub) { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
481 item = gnt_menu_get_item(sub, id); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
482 if (item) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
483 break; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
484 } else { |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
485 const char *itid = gnt_menuitem_get_id(item); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
486 if (itid && strcmp(itid, id) == 0) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
487 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
|
488 /* XXX: Perhaps look at the menu-label as well? */ |
21212
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
489 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
490 item = NULL; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
491 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
492 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
493 if (item) |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
494 menuitem_activate(menu, item); |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
495 |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
496 return item; |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
497 } |
b65f1bff6412
Allow binding key-shortcuts to menuitems.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19681
diff
changeset
|
498 |