annotate finch/libgnt/gntmenu.c @ 21699:760a8e024142

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