Skip to content

Commit

Permalink
Remove INativeWindow::SetWindowMode, put it in INativeController::Cre…
Browse files Browse the repository at this point in the history
…ateNativeWindow
  • Loading branch information
vczh committed Jul 26, 2021
1 parent f0be5f3 commit 8e4d943
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 43 deletions.
19 changes: 11 additions & 8 deletions Import/GacUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -4283,10 +4291,6 @@ GuiWindow
void GuiWindow::OnNativeWindowChanged()
{
SyncNativeWindowProperties();
if (auto window = GetNativeWindow())
{
window->SetWindowMode(windowMode);
}
GuiControlHost::OnNativeWindowChanged();
}

Expand All @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions Import/GacUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2035,11 +2035,6 @@ Native Window
/// </summary>
/// <returns>The window mode.</summary>
virtual WindowMode GetWindowMode() = 0;
/// <summary>
/// Set the window mode
/// </summary>
/// <param name="mode">The window mode.</param>
virtual void SetWindowMode(WindowMode mode) = 0;

/// <summary>
/// Enable the window customized frame mode.
Expand Down Expand Up @@ -2791,7 +2786,8 @@ Native Window Services
/// Create a window.
/// </summary>
/// <returns>The created window.</returns>
virtual INativeWindow* CreateNativeWindow() = 0;
/// <param name="windowMode">The window mode.</param>
virtual INativeWindow* CreateNativeWindow(INativeWindow::WindowMode windowMode) = 0;
/// <summary>
/// Destroy a window.
/// </summary>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -11243,7 +11240,8 @@ Control Host
public:
/// <summary>Create a control with a specified default theme.</summary>
/// <param name="themeName">The theme name for retriving a default control template.</param>
GuiControlHost(theme::ThemeName themeName);
/// <param name="mode">The window mode.</param>
GuiControlHost(theme::ThemeName themeName, INativeWindow::WindowMode mode);
~GuiControlHost();

/// <summary>Window got focus event.</summary>
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Import/GacUIReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 19 additions & 25 deletions Import/GacUIWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8897,7 +8897,7 @@ WindowsForm
NativePoint caretPoint;
WindowsForm* parentWindow = nullptr;
List<WindowsForm*> childWindows;
WindowMode windowMode = Normal;
WindowMode windowMode;
List<INativeWindowListener*> listeners;
vint mouseLastX = -1;
vint mouseLastY = -1;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 8e4d943

Please sign in to comment.