[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50808] trunk/blender/source/blender/ editors: Enable predictable menu key-chaining as with r50501.

Campbell Barton ideasman42 at gmail.com
Sat Sep 22 09:38:17 CEST 2012


Revision: 50808
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50808
Author:   campbellbarton
Date:     2012-09-22 07:38:16 +0000 (Sat, 22 Sep 2012)
Log Message:
-----------
Enable predictable menu key-chaining as with r50501.

The way it works now, navigation keys (up/down, number, a-z) - won't apply to a submenu if there are no active buttons in that menu, instead the parent menu gets the event.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50501

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/UI_interface.h
    trunk/blender/source/blender/editors/interface/interface_handlers.c

Modified: trunk/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_interface.h	2012-09-22 07:22:42 UTC (rev 50807)
+++ trunk/blender/source/blender/editors/include/UI_interface.h	2012-09-22 07:38:16 UTC (rev 50808)
@@ -120,11 +120,12 @@
 #define UI_BLOCK_CLIP_EVENTS    8192    /* stop handling mouse events */
 
 /* uiPopupBlockHandle->menuretval */
-#define UI_RETURN_CANCEL    1       /* cancel all menus cascading */
-#define UI_RETURN_OK        2       /* choice made */
-#define UI_RETURN_OUT       4       /* left the menu */
-#define UI_RETURN_UPDATE    8       /* update the button that opened */
-#define UI_RETURN_POPUP_OK  16      /* popup is ok to be handled */
+#define UI_RETURN_CANCEL     1       /* cancel all menus cascading */
+#define UI_RETURN_OK         2       /* choice made */
+#define UI_RETURN_OUT        4       /* left the menu */
+#define UI_RETURN_OUT_PARENT 8       /* let the parent handle this event */
+#define UI_RETURN_UPDATE     16      /* update the button that opened */
+#define UI_RETURN_POPUP_OK   32      /* popup is ok to be handled */
 
 /* block->flag bits 12-15 are identical to but->flag bits */
 

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-09-22 07:22:42 UTC (rev 50807)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-09-22 07:38:16 UTC (rev 50808)
@@ -6219,7 +6219,7 @@
 	return 0;
 }
 
-static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle *menu, int UNUSED(topmenu))
+static int ui_handle_menu_event(bContext *C, wmEvent *event, uiPopupBlockHandle *menu, int level)
 {
 	ARegion *ar;
 	uiBlock *block;
@@ -6264,10 +6264,22 @@
 		}
 		
 		/* first block own event func */
-		if (block->block_event_func && block->block_event_func(C, block, event)) ;
-		/* events not for active search menu button */
+		if (block->block_event_func && block->block_event_func(C, block, event)) {
+			/* pass */
+		}   /* events not for active search menu button */
 		else if (but == NULL || but->type != SEARCH_MENU) {
 			switch (event->type) {
+
+
+			/* let the parent menu get the event */
+#define     PASS_EVENT_TO_PARENT_IF_NONACTIVE                                 \
+				if ((level != 0) && (but == NULL)) {                          \
+					menu->menuretval = UI_RETURN_OUT | UI_RETURN_OUT_PARENT;  \
+					BLI_assert(retval == WM_UI_HANDLER_CONTINUE);             \
+					break;                                                    \
+				} (void)0
+
+
 				/* closing sublevels of pulldowns */
 				case LEFTARROWKEY:
 					if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP))
@@ -6280,6 +6292,9 @@
 				/* opening sublevels of pulldowns */
 				case RIGHTARROWKEY:	
 					if (event->val == KM_PRESS && (block->flag & UI_BLOCK_LOOP)) {
+
+						PASS_EVENT_TO_PARENT_IF_NONACTIVE;
+
 						but = ui_but_find_activated(ar);
 
 						if (!but) {
@@ -6305,6 +6320,9 @@
 					}
 					else if (inside || (block->flag & UI_BLOCK_LOOP)) {
 						if (event->val == KM_PRESS) {
+
+							PASS_EVENT_TO_PARENT_IF_NONACTIVE;
+
 							but = ui_but_find_activated(ar);
 							if (but) {
 								/* is there a situation where UI_LEFT or UI_RIGHT would also change navigation direction? */
@@ -6384,6 +6402,9 @@
 					if (act == 0) act = 10;
 
 					if ((block->flag & UI_BLOCK_NUMSELECT) && event->val == KM_PRESS) {
+
+						PASS_EVENT_TO_PARENT_IF_NONACTIVE;
+
 						if (event->alt) act += 10;
 
 						count = 0;
@@ -6461,6 +6482,8 @@
 					    (event->ctrl  == FALSE) &&
 					    (event->oskey == FALSE))
 					{
+						PASS_EVENT_TO_PARENT_IF_NONACTIVE;
+
 						for (but = block->buttons.first; but; but = but->next) {
 
 							if (but->menu_key == event->type) {
@@ -6550,6 +6573,10 @@
 						retval = WM_UI_HANDLER_BREAK;
 				}
 			}
+
+			/* end switch */
+#undef PASS_EVENT_TO_PARENT_IF_NONACTIVE
+
 		}
 	}
 
@@ -6638,7 +6665,7 @@
 		return WM_UI_HANDLER_BREAK;
 }
 
-static int ui_handle_menus_recursive(bContext *C, wmEvent *event, uiPopupBlockHandle *menu)
+static int ui_handle_menus_recursive(bContext *C, wmEvent *event, uiPopupBlockHandle *menu, int level)
 {
 	uiBut *but;
 	uiHandleButtonData *data;
@@ -6651,14 +6678,20 @@
 	submenu = (data) ? data->menu : NULL;
 
 	if (submenu)
-		retval = ui_handle_menus_recursive(C, event, submenu);
+		retval = ui_handle_menus_recursive(C, event, submenu, level + 1);
 
 	/* now handle events for our own menu */
 	if (retval == WM_UI_HANDLER_CONTINUE || event->type == TIMER) {
-		if (submenu && submenu->menuretval)
+		if (submenu && submenu->menuretval) {
 			retval = ui_handle_menu_return_submenu(C, event, menu);
-		else
-			retval = ui_handle_menu_event(C, event, menu, (submenu == NULL));
+			/* we may wan't to quit the submenu and handle the even in this menu */
+			if ((retval == WM_UI_HANDLER_BREAK) && (submenu->menuretval & UI_RETURN_OUT_PARENT)) {
+				retval = ui_handle_menu_event(C, event, menu, level);
+			}
+		}
+		else {
+			retval = ui_handle_menu_event(C, event, menu, level);  /* same as above */
+		}
 	}
 
 	return retval;
@@ -6746,7 +6779,7 @@
 		if (data->state == BUTTON_STATE_MENU_OPEN) {
 			/* handle events for menus and their buttons recursively,
 			 * this will handle events from the top to the bottom menu */
-			retval = ui_handle_menus_recursive(C, event, data->menu);
+			retval = ui_handle_menus_recursive(C, event, data->menu, 0);
 
 			/* handle events for the activated button */
 			if (retval == WM_UI_HANDLER_CONTINUE || event->type == TIMER) {
@@ -6790,7 +6823,7 @@
 		retval = WM_UI_HANDLER_CONTINUE;
 	}
 
-	ui_handle_menus_recursive(C, event, menu);
+	ui_handle_menus_recursive(C, event, menu, 0);
 
 	/* free if done, does not free handle itself */
 	if (menu->menuretval) {




More information about the Bf-blender-cvs mailing list