瀏覽代碼

Properly send FocusLost event to windows (and in turn, to GUIElements)

Marko Pintera 12 年之前
父節點
當前提交
d7fcf5dc94

+ 16 - 0
BansheeEngine/Source/BsGUIManager.cpp

@@ -1193,6 +1193,22 @@ namespace BansheeEngine
 			if(getWidgetWindow(*widget) == &win)
 				widget->ownerWindowFocusChanged();
 		}
+
+		mNewElementsInFocus.clear();
+		for(auto& focusedElement : mElementsInFocus)
+		{
+			if(getWidgetWindow(*focusedElement.widget) == &win)
+			{
+				mCommandEvent = GUICommandEvent();
+				mCommandEvent.setType(GUICommandEventType::FocusLost);
+
+				sendCommandEvent(focusedElement.widget, focusedElement.element, mCommandEvent);
+			}
+			else
+				mNewElementsInFocus.push_back(focusedElement);
+		}
+
+		mElementsInFocus.swap(mNewElementsInFocus);
 	}
 
 	// We stop getting mouse move events once it leaves the window, so make sure

+ 7 - 0
CamelotClient/Source/BsGUITreeViewEditBox.cpp

@@ -60,6 +60,13 @@ namespace BansheeEditor
 
 			return true;
 		}
+		else if(ev.getType() == GUICommandEventType::FocusLost)
+		{
+			if(!onInputCanceled.empty())
+				onInputCanceled();
+
+			return true;
+		}
 
 		return processed;
 	}

+ 13 - 9
CamelotCore/Source/CmPlatformWndProc.cpp

@@ -29,17 +29,21 @@ namespace CamelotFramework
 			{
 				bool active = (LOWORD(wParam) != WA_INACTIVE);
 				if( active )
-				{
 					win->setActive(true);
 
-					if(!win->hasFocus())
-						windowFocusReceived(win);
-				}
-				else
-				{
-					if(win->hasFocus())
-						windowFocusLost(win);
-				}
+				break;
+			}
+		case WM_SETFOCUS:
+			{
+				if(!win->hasFocus())
+					windowFocusReceived(win);
+
+				break;
+			}
+		case WM_KILLFOCUS:
+			{
+				if(win->hasFocus())
+					windowFocusLost(win);
 
 				break;
 			}

+ 3 - 0
CamelotCore/Source/CmRenderWindowManager.cpp

@@ -51,6 +51,9 @@ namespace CamelotFramework
 	void RenderWindowManager::windowFocusLost(RenderWindow* window)
 	{
 		window->_windowFocusLost();
+
+		CM_LOCK_MUTEX(mWindowMutex);
+		mNewWindowInFocus = nullptr;
 	}
 
 	void RenderWindowManager::windowMovedOrResized(RenderWindow* window)

+ 1 - 0
CamelotCore/Source/Win32/CmPlatformImpl.cpp

@@ -474,6 +474,7 @@ namespace CamelotFramework
 			if(mRequiresStartUp)
 			{
 				OleInitialize(nullptr);
+
 				mRequiresStartUp = false;
 			}
 		}