comparison console/libgnt/gntmain.c @ 14613:62bb53609a36

[gaim-migrate @ 17341] Menus and windows. I have added a test-app test/menu.c to show how to use it. Pressing Ctrl+o brings up the menu for the window (if it has one). It should now be possible to add menus for account-actions and all that stuff. Patches are very welcome. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 24 Sep 2006 07:14:26 +0000
parents d1f9b05c3f58
children d1935057d82c
comparison
equal deleted inserted replaced
14612:1f46715c08d9 14613:62bb53609a36
6 6
7 #include "gnt.h" 7 #include "gnt.h"
8 #include "gntbox.h" 8 #include "gntbox.h"
9 #include "gntcolors.h" 9 #include "gntcolors.h"
10 #include "gntkeys.h" 10 #include "gntkeys.h"
11 #include "gntmenu.h"
11 #include "gntstyle.h" 12 #include "gntstyle.h"
12 #include "gnttree.h" 13 #include "gnttree.h"
13 #include "gntutils.h" 14 #include "gntutils.h"
14 #include "gntwm.h" 15 #include "gntwm.h"
15 16
31 * Notes: Interesting functions to look at: 32 * Notes: Interesting functions to look at:
32 * scr_dump, scr_init, scr_restore: for workspaces 33 * scr_dump, scr_init, scr_restore: for workspaces
33 * 34 *
34 * Need to wattrset for colors to use with PDCurses. 35 * Need to wattrset for colors to use with PDCurses.
35 */ 36 */
37
38 /**
39 * There can be at most one menu at a time on the screen.
40 * If there is a menu being displayed, then all the keystrokes will be sent to
41 * the menu until it is closed, either when the user activates a menuitem, or
42 * presses Escape to cancel the menu.
43 */
44 static GntMenu *menu;
36 45
37 static int lock_focus_list; 46 static int lock_focus_list;
38 static GList *focus_list; 47 static GList *focus_list;
39 static GList *ordered; 48 static GList *ordered;
40 49
118 } 127 }
119 128
120 static gboolean 129 static gboolean
121 update_screen(gpointer null) 130 update_screen(gpointer null)
122 { 131 {
132 if (menu) {
133 GntMenu *top = menu;
134 while (top) {
135 GntNode *node = g_hash_table_lookup(nodes, top);
136 if (node)
137 top_panel(node->panel);
138 top = top->submenu;
139 }
140 }
123 update_panels(); 141 update_panels();
124 doupdate(); 142 doupdate();
125 return TRUE; 143 return TRUE;
126 } 144 }
127 145
683 701
684 /* Returns the onscreen width of the character at the position */ 702 /* Returns the onscreen width of the character at the position */
685 static int 703 static int
686 reverse_char(WINDOW *d, int y, int x, gboolean set) 704 reverse_char(WINDOW *d, int y, int x, gboolean set)
687 { 705 {
688 #define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE)) 706 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE))
689 707
690 #ifdef NO_WIDECHAR 708 #ifdef NO_WIDECHAR
691 chtype ch; 709 chtype ch;
692 ch = mvwinch(d, y, x); 710 ch = mvwinch(d, y, x);
693 mvwaddch(d, y, x, DECIDE(ch)); 711 mvwaddch(d, y, x, DECIDE(ch));
775 } else 793 } else
776 buffer = keys; 794 buffer = keys;
777 795
778 if (mode == GNT_KP_MODE_NORMAL) 796 if (mode == GNT_KP_MODE_NORMAL)
779 { 797 {
780 if (ordered) 798 if (menu) {
781 { 799 ret = gnt_widget_key_pressed(GNT_WIDGET(menu), buffer);
800 } else if (ordered) {
782 ret = gnt_widget_key_pressed(ordered->data, buffer); 801 ret = gnt_widget_key_pressed(ordered->data, buffer);
783 } 802 }
784 803
785 if (!ret) 804 if (!ret)
786 { 805 {
1207 { 1226 {
1208 GntNode *node; 1227 GntNode *node;
1209 1228
1210 while (widget->parent) 1229 while (widget->parent)
1211 widget = widget->parent; 1230 widget = widget->parent;
1212 1231 if (!GNT_IS_MENU(widget))
1213 gnt_box_sync_children(GNT_BOX(widget)); 1232 gnt_box_sync_children(GNT_BOX(widget));
1214 node = g_hash_table_lookup(nodes, widget); 1233 node = g_hash_table_lookup(nodes, widget);
1215 if (node && !node->panel) 1234 if (node && !node->panel)
1216 { 1235 {
1217 if (wm.new_window && node->me != _list.window) 1236 if (wm.new_window && node->me != _list.window)
1218 node->panel = wm.new_window(node->me); 1237 node->panel = wm.new_window(node->me);
1242 gboolean gnt_widget_has_focus(GntWidget *widget) 1261 gboolean gnt_widget_has_focus(GntWidget *widget)
1243 { 1262 {
1244 GntWidget *w; 1263 GntWidget *w;
1245 if (!widget) 1264 if (!widget)
1246 return FALSE; 1265 return FALSE;
1266
1267 if (GNT_IS_MENU(widget))
1268 return TRUE;
1247 1269
1248 w = widget; 1270 w = widget;
1249 1271
1250 while (widget->parent) 1272 while (widget->parent)
1251 widget = widget->parent; 1273 widget = widget->parent;
1414 lock_focus_list = 1; 1436 lock_focus_list = 1;
1415 gnt_widget_show(win); 1437 gnt_widget_show(win);
1416 lock_focus_list = 0; 1438 lock_focus_list = 0;
1417 } 1439 }
1418 1440
1441 static void
1442 reset_menu(GntWidget *widget, gpointer null)
1443 {
1444 menu = NULL;
1445 }
1446
1447 gboolean gnt_screen_menu_show(gpointer newmenu)
1448 {
1449 if (menu) {
1450 /* For now, if a menu is being displayed, then another menu
1451 * can NOT take over. */
1452 return FALSE;
1453 }
1454
1455 menu = newmenu;
1456 gnt_widget_draw(GNT_WIDGET(menu));
1457
1458 g_signal_connect(G_OBJECT(menu), "hide", G_CALLBACK(reset_menu), NULL);
1459
1460 return TRUE;
1461 }
1462