From 8e4d94350277af43344ae73402893dbb737f9db2 Mon Sep 17 00:00:00 2001 From: Zihan Chen Date: Sun, 25 Jul 2021 22:14:27 -0700 Subject: [PATCH] Remove INativeWindow::SetWindowMode, put it in INativeController::CreateNativeWindow --- Import/GacUI.cpp | 19 +++++++++------- Import/GacUI.h | 13 +++++------ Import/GacUIReflection.cpp | 4 ++-- Import/GacUIWindows.cpp | 44 ++++++++++++++++---------------------- 4 files changed, 37 insertions(+), 43 deletions(-) diff --git a/Import/GacUI.cpp b/Import/GacUI.cpp index 46fe83cb..968fc35e 100644 --- a/Import/GacUI.cpp +++ b/Import/GacUI.cpp @@ -3785,8 +3785,9 @@ GuiControlHost } } - GuiControlHost::GuiControlHost(theme::ThemeName themeName) + GuiControlHost::GuiControlHost(theme::ThemeName themeName, INativeWindow::WindowMode mode) :GuiControl(themeName) + , windowMode(mode) { boundsComposition->SetAlignmentToParent(Margin(0, 0, 0, 0)); @@ -3845,6 +3846,13 @@ GuiControlHost { host->GetNativeWindow()->UninstallListener(this); } + if (window) + { + if (windowMode != window->GetWindowMode()) + { + CHECK_FAIL(L"GuiControlHost::SetNativeWindow(INativeWindow*)#Window mode does not match."); + } + } host->SetNativeWindow(window); if(host->GetNativeWindow()) { @@ -4283,10 +4291,6 @@ GuiWindow void GuiWindow::OnNativeWindowChanged() { SyncNativeWindowProperties(); - if (auto window = GetNativeWindow()) - { - window->SetWindowMode(windowMode); - } GuiControlHost::OnNativeWindowChanged(); } @@ -4312,13 +4316,12 @@ GuiWindow } GuiWindow::GuiWindow(theme::ThemeName themeName, INativeWindow::WindowMode mode) - :GuiControlHost(themeName) - , windowMode(mode) + :GuiControlHost(themeName, mode) { SetAltComposition(boundsComposition); SetAltControl(this, true); - INativeWindow* window = GetCurrentController()->WindowService()->CreateNativeWindow(); + INativeWindow* window = GetCurrentController()->WindowService()->CreateNativeWindow(windowMode); SetNativeWindow(window); GetApplication()->RegisterWindow(this); ClipboardUpdated.SetAssociatedComposition(boundsComposition); diff --git a/Import/GacUI.h b/Import/GacUI.h index cf9f5798..0b444e3a 100644 --- a/Import/GacUI.h +++ b/Import/GacUI.h @@ -2035,11 +2035,6 @@ Native Window /// /// The window mode. virtual WindowMode GetWindowMode() = 0; - /// - /// Set the window mode - /// - /// The window mode. - virtual void SetWindowMode(WindowMode mode) = 0; /// /// Enable the window customized frame mode. @@ -2791,7 +2786,8 @@ Native Window Services /// Create a window. /// /// The created window. - virtual INativeWindow* CreateNativeWindow() = 0; + /// The window mode. + virtual INativeWindow* CreateNativeWindow(INativeWindow::WindowMode windowMode) = 0; /// /// Destroy a window. /// @@ -11207,6 +11203,7 @@ Control Host friend class compositions::GuiGraphicsHost; protected: compositions::GuiGraphicsHost* host; + INativeWindow::WindowMode windowMode = INativeWindow::Normal; virtual void OnNativeWindowChanged(); virtual void OnVisualStatusChanged(); @@ -11243,7 +11240,8 @@ Control Host public: /// Create a control with a specified default theme. /// The theme name for retriving a default control template. - GuiControlHost(theme::ThemeName themeName); + /// The window mode. + GuiControlHost(theme::ThemeName themeName, INativeWindow::WindowMode mode); ~GuiControlHost(); /// Window got focus event. @@ -11404,7 +11402,6 @@ Window GUI_SPECIFY_CONTROL_TEMPLATE_TYPE(WindowTemplate, GuiControlHost) friend class GuiApplication; protected: - INativeWindow::WindowMode windowMode = INativeWindow::Normal; compositions::IGuiAltActionHost* previousAltHost = nullptr; bool hasMaximizedBox = true; bool hasMinimizedBox = true; diff --git a/Import/GacUIReflection.cpp b/Import/GacUIReflection.cpp index 4c13483d..5969a559 100644 --- a/Import/GacUIReflection.cpp +++ b/Import/GacUIReflection.cpp @@ -373,7 +373,7 @@ Type Declaration CLASS_MEMBER_PROPERTY_FAST(WindowCursor) CLASS_MEMBER_PROPERTY_FAST(CaretPoint) CLASS_MEMBER_PROPERTY_FAST(Parent) - CLASS_MEMBER_PROPERTY_FAST(WindowMode) + CLASS_MEMBER_PROPERTY_READONLY_FAST(WindowMode) CLASS_MEMBER_PROPERTY_READONLY_FAST(CustomFramePadding) CLASS_MEMBER_PROPERTY_FAST(Icon) CLASS_MEMBER_PROPERTY_READONLY_FAST(SizeState) @@ -2252,7 +2252,7 @@ Type Declaration (Class) BEGIN_CLASS_MEMBER(GuiControlHost) CLASS_MEMBER_BASE(GuiControl) CLASS_MEMBER_BASE(GuiInstanceRootObject) - CONTROL_CONSTRUCTOR_CONTROLT_TEMPLATE_INHERITANCE(GuiControlHost) + CONTROL_CONSTRUCTOR_CONTROLT_TEMPLATE_INHERITANCE_2(GuiControlHost, INativeWindow::WindowMode, mode) CLASS_MEMBER_GUIEVENT(WindowGotFocus) CLASS_MEMBER_GUIEVENT(WindowLostFocus) diff --git a/Import/GacUIWindows.cpp b/Import/GacUIWindows.cpp index 8705acb2..c5984a1d 100644 --- a/Import/GacUIWindows.cpp +++ b/Import/GacUIWindows.cpp @@ -8897,7 +8897,7 @@ WindowsForm NativePoint caretPoint; WindowsForm* parentWindow = nullptr; List childWindows; - WindowMode windowMode = Normal; + WindowMode windowMode; List listeners; vint mouseLastX = -1; vint mouseLastY = -1; @@ -8925,12 +8925,23 @@ WindowsForm customFramePadding = NativeMargin(padding, padding, padding, padding); } public: - WindowsForm(HWND parent, WString className, HINSTANCE hInstance) + WindowsForm(HWND parent, WString className, HINSTANCE hInstance, INativeWindow::WindowMode _windowMode) + :windowMode(_windowMode) { - // use WS_POPUP in CreateWindowEx, because CW_USERDEFAULT is interpreted as 0, unlike WS_OVERLAPPED - DWORD exStyle = WS_EX_APPWINDOW | WS_EX_CONTROLPARENT; - DWORD style = WS_BORDER | WS_CAPTION | WS_SIZEBOX | WS_SYSMENU | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; - handle = CreateWindowEx(exStyle, className.Buffer(), L"", style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, hInstance, NULL); + { + DWORD exStyle = WS_EX_APPWINDOW | WS_EX_CONTROLPARENT; + DWORD style = WS_BORDER | WS_CAPTION | WS_SIZEBOX | WS_SYSMENU | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; + handle = CreateWindowEx(exStyle, className.Buffer(), L"", style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, hInstance, NULL); + } + if (windowMode == INativeWindow::Normal) + { + // use WS_POPUP in CreateWindowEx, because CW_USERDEFAULT is interpreted as 0, unlike WS_OVERLAPPED + // if this is not a popup window, replace WS_POPUP with WS_OVERLAPPED + auto style = InternalGetStyle(); + style = TurnOnStyle(style, WS_OVERLAPPED); + style = TurnOffStyle(style, WS_POPUP); + InternalSetStyle(style); + } UpdateDpiAwaredFields(true); } @@ -9196,23 +9207,6 @@ WindowsForm return windowMode; } - void SetWindowMode(WindowMode mode)override - { - windowMode = mode; - auto style = InternalGetStyle(); - if (mode == Normal) - { - style = TurnOnStyle(style, WS_OVERLAPPED); - style = TurnOffStyle(style, WS_POPUP); - } - else - { - style = TurnOffStyle(style, WS_OVERLAPPED); - style = TurnOnStyle(style, WS_POPUP); - } - InternalSetStyle(style); - } - void EnableCustomFrameMode()override { customFrameMode=true; @@ -9800,9 +9794,9 @@ WindowsController //======================================================================= - INativeWindow* CreateNativeWindow()override + INativeWindow* CreateNativeWindow(INativeWindow::WindowMode windowMode)override { - WindowsForm* window=new WindowsForm(godWindow, windowClass.GetName(), hInstance); + WindowsForm* window=new WindowsForm(godWindow, windowClass.GetName(), hInstance, windowMode); windows.Add(window->GetWindowHandle(), window); callbackService.InvokeNativeWindowCreated(window); window->SetWindowCursor(resourceService.GetDefaultSystemCursor());