diff 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
line wrap: on
line diff
--- a/console/libgnt/gntmain.c	Sat Sep 23 19:04:03 2006 +0000
+++ b/console/libgnt/gntmain.c	Sun Sep 24 07:14:26 2006 +0000
@@ -8,6 +8,7 @@
 #include "gntbox.h"
 #include "gntcolors.h"
 #include "gntkeys.h"
+#include "gntmenu.h"
 #include "gntstyle.h"
 #include "gnttree.h"
 #include "gntutils.h"
@@ -34,6 +35,14 @@
  * 	Need to wattrset for colors to use with PDCurses.
  */
 
+/**
+ * There can be at most one menu at a time on the screen.
+ * If there is a menu being displayed, then all the keystrokes will be sent to
+ * the menu until it is closed, either when the user activates a menuitem, or
+ * presses Escape to cancel the menu.
+ */
+static GntMenu *menu;
+
 static int lock_focus_list;
 static GList *focus_list;
 static GList *ordered;
@@ -120,6 +129,15 @@
 static gboolean
 update_screen(gpointer null)
 {
+	if (menu) {
+		GntMenu *top = menu;
+		while (top) {
+			GntNode *node = g_hash_table_lookup(nodes, top);
+			if (node)
+				top_panel(node->panel);
+			top = top->submenu;
+		}
+	}
 	update_panels();
 	doupdate();
 	return TRUE;
@@ -685,7 +703,7 @@
 static int
 reverse_char(WINDOW *d, int y, int x, gboolean set)
 {
-#define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE))
+#define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE))
 
 #ifdef NO_WIDECHAR
 	chtype ch;
@@ -777,8 +795,9 @@
 
 	if (mode == GNT_KP_MODE_NORMAL)
 	{
-		if (ordered)
-		{
+		if (menu) {
+			ret = gnt_widget_key_pressed(GNT_WIDGET(menu), buffer);
+		} else if (ordered) {
 			ret = gnt_widget_key_pressed(ordered->data, buffer);
 		}
 
@@ -1209,8 +1228,8 @@
 	
 	while (widget->parent)
 		widget = widget->parent;
-	
-	gnt_box_sync_children(GNT_BOX(widget));
+	if (!GNT_IS_MENU(widget))
+		gnt_box_sync_children(GNT_BOX(widget));
 	node = g_hash_table_lookup(nodes, widget);
 	if (node && !node->panel)
 	{
@@ -1244,6 +1263,9 @@
 	GntWidget *w;
 	if (!widget)
 		return FALSE;
+	
+	if (GNT_IS_MENU(widget))
+		return TRUE;
 
 	w = widget;
 
@@ -1416,3 +1438,25 @@
 	lock_focus_list = 0;
 }
 
+static void
+reset_menu(GntWidget *widget, gpointer null)
+{
+	menu = NULL;
+}
+
+gboolean gnt_screen_menu_show(gpointer newmenu)
+{
+	if (menu) {
+		/* For now, if a menu is being displayed, then another menu
+		 * can NOT take over. */
+		return FALSE;
+	}
+
+	menu = newmenu;
+	gnt_widget_draw(GNT_WIDGET(menu));
+
+	g_signal_connect(G_OBJECT(menu), "hide", G_CALLBACK(reset_menu), NULL);
+
+	return TRUE;
+}
+