[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24851] trunk/blender/source/blender/ windowmanager: Extend handler return values to distinguish between events that have been handled and passed through and those that haven 't been handled at all.

Martin Poirier theeth at yahoo.com
Tue Nov 24 06:03:44 CET 2009


Revision: 24851
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24851
Author:   theeth
Date:     2009-11-24 06:03:44 +0100 (Tue, 24 Nov 2009)

Log Message:
-----------
Extend handler return values to distinguish between events that have been handled and passed through and those that haven't been handled at all.

This also solves a bug with Click event (not visible with keymaps that use Click in default)

Modified Paths:
--------------
    trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c
    trunk/blender/source/blender/windowmanager/wm_event_system.h

Modified: trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2009-11-24 04:59:52 UTC (rev 24850)
+++ trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2009-11-24 05:03:44 UTC (rev 24851)
@@ -937,6 +937,10 @@
 			retval= wm_operator_invoke(C, ot, event, properties, NULL);
 	}
 
+	/* Finished and pass through flag as handled */
+	if(retval == (OPERATOR_FINISHED|OPERATOR_PASS_THROUGH))
+		return WM_HANDLER_HANDLED;
+
 	if(retval & OPERATOR_PASS_THROUGH)
 		return WM_HANDLER_CONTINUE;
 
@@ -1110,7 +1114,7 @@
 		
 			/* modal+blocking handler */
 			if(handler->flag & WM_HANDLER_BLOCKING)
-				action= WM_HANDLER_BREAK;
+				action |= WM_HANDLER_BREAK;
 
 			if(handler->keymap) {
 				wmKeyMap *keymap= WM_keymap_active(wm, handler->keymap);
@@ -1122,28 +1126,28 @@
 							
 							event->keymap_idname= kmi->idname;	/* weak, but allows interactive callback to not use rawkey */
 							
-							action= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr);
-							if(action==WM_HANDLER_BREAK)  /* not always_pass here, it denotes removed handler */
+							action |= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr);
+							if(action & WM_HANDLER_BREAK)  /* not always_pass here, it denotes removed handler */
 								break;
 						}
 					}
 				}
 			}
 			else if(handler->ui_handle) {
-				action= wm_handler_ui_call(C, handler, event);
+				action |= wm_handler_ui_call(C, handler, event);
 			}
 			else if(handler->type==WM_HANDLER_FILESELECT) {
 				/* screen context changes here */
-				action= wm_handler_fileselect_call(C, handlers, handler, event);
+				action |= wm_handler_fileselect_call(C, handlers, handler, event);
 			}
 			else {
 				/* modal, swallows all */
-				action= wm_handler_operator_call(C, handlers, handler, event, NULL);
+				action |= wm_handler_operator_call(C, handlers, handler, event, NULL);
 			}
 
-			if(action==WM_HANDLER_BREAK) {
+			if(action & WM_HANDLER_BREAK) {
 				if(always_pass)
-					action= WM_HANDLER_CONTINUE;
+					action &= ~WM_HANDLER_BREAK;
 				else
 					break;
 			}
@@ -1160,10 +1164,10 @@
 
 		if (win && win->last_type == event->type && win->last_val == KM_PRESS) {
 			event->val = KM_CLICK;
-			action = wm_handlers_do(C, event, handlers);
+			action |= wm_handlers_do(C, event, handlers);
 
 			/* revert value if not handled */
-			if (action == WM_HANDLER_CONTINUE) {
+			if ((action & WM_HANDLER_BREAK) == 0) {
 				event->val = KM_RELEASE;
 			}
 		}
@@ -1261,12 +1265,12 @@
 
 	for(win= CTX_wm_manager(C)->windows.first; win; win= win->next) {
 		wmEvent *event;
+		int action = WM_HANDLER_CONTINUE;
 		
 		if( win->screen==NULL )
 			wm_event_free_all(win);
 		
 		while( (event= win->queue.first) ) {
-			int action;
 
 			CTX_wm_window_set(C, win);
 			
@@ -1278,7 +1282,7 @@
 			wm_window_make_drawable(C, win);
 			
 			/* first we do priority handlers, modal + some limited keymaps */
-			action= wm_handlers_do(C, event, &win->modalhandlers);
+			action |= wm_handlers_do(C, event, &win->modalhandlers);
 			
 			/* fileread case */
 			if(CTX_wm_window(C)==NULL)
@@ -1287,7 +1291,7 @@
 			/* builtin tweak, if action is break it removes tweak */
 			wm_tweakevent_test(C, event, action);
 
-			if(action==WM_HANDLER_CONTINUE) {
+			if((action & WM_HANDLER_BREAK) == 0) {
 				ScrArea *sa;
 				ARegion *ar;
 				int doit= 0;
@@ -1304,15 +1308,15 @@
 					if(wm_event_inside_i(event, &sa->totrct)) {
 						CTX_wm_area_set(C, sa);
 
-						if(action==WM_HANDLER_CONTINUE) {
+						if((action & WM_HANDLER_BREAK) == 0) {
 							for(ar=sa->regionbase.first; ar; ar= ar->next) {
 								if(wm_event_inside_i(event, &ar->winrct)) {
 									CTX_wm_region_set(C, ar);
-									action= wm_handlers_do(C, event, &ar->handlers);
+									action |= wm_handlers_do(C, event, &ar->handlers);
 
 									doit |= (BLI_in_rcti(&ar->winrct, event->x, event->y));
 									
-									if(action==WM_HANDLER_BREAK)
+									if(action & WM_HANDLER_BREAK)
 										break;
 								}
 							}
@@ -1320,8 +1324,8 @@
 
 						CTX_wm_region_set(C, NULL);
 
-						if(action==WM_HANDLER_CONTINUE)
-							action= wm_handlers_do(C, event, &sa->handlers);
+						if((action & WM_HANDLER_BREAK) == 0)
+							action |= wm_handlers_do(C, event, &sa->handlers);
 
 						CTX_wm_area_set(C, NULL);
 
@@ -1329,12 +1333,12 @@
 					}
 				}
 				
-				if(action==WM_HANDLER_CONTINUE) {
+				if((action & WM_HANDLER_BREAK) == 0) {
 					/* also some non-modal handlers need active area/region */
 					CTX_wm_area_set(C, area_event_inside(C, event->x, event->y));
 					CTX_wm_region_set(C, region_event_inside(C, event->x, event->y));
 
-					action= wm_handlers_do(C, event, &win->handlers);
+					action |= wm_handlers_do(C, event, &win->handlers);
 
 					/* fileread case */
 					if(CTX_wm_window(C)==NULL)
@@ -1350,8 +1354,13 @@
 			}
 			
 			/* store last event for this window */
-			win->last_type = event->type;
-			win->last_val = event->val;
+			if (action == WM_HANDLER_CONTINUE) {
+				win->last_type = event->type;
+				win->last_val = event->val;
+			} else {
+				win->last_type = -1;
+				win->last_val = 0;
+			}
 
 			/* unlink and free here, blender-quit then frees all */
 			BLI_remlink(&win->queue, event);

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2009-11-24 04:59:52 UTC (rev 24850)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2009-11-24 05:03:44 UTC (rev 24851)
@@ -2037,7 +2037,7 @@
 		}
 	}
 	else {
-		if(action==WM_HANDLER_BREAK) {
+		if(action & WM_HANDLER_BREAK) {
 			WM_gesture_end(C, win->tweak);
 			win->tweak= NULL;
 		}

Modified: trunk/blender/source/blender/windowmanager/wm_event_system.h
===================================================================
--- trunk/blender/source/blender/windowmanager/wm_event_system.h	2009-11-24 04:59:52 UTC (rev 24850)
+++ trunk/blender/source/blender/windowmanager/wm_event_system.h	2009-11-24 05:03:44 UTC (rev 24851)
@@ -31,6 +31,7 @@
 /* return value of handler-operator call */
 #define WM_HANDLER_CONTINUE	0
 #define WM_HANDLER_BREAK	1
+#define WM_HANDLER_HANDLED	2
 
 struct ScrArea;
 struct ARegion;





More information about the Bf-blender-cvs mailing list