Update release

This commit is contained in:
Zihan Chen
2018-07-10 00:04:57 -07:00
parent 167547854c
commit 4ac5de559b
5 changed files with 120 additions and 76 deletions
+41 -12
View File
@@ -6411,7 +6411,7 @@ GuiControlHost
control=control->GetParent(); control=control->GetParent();
} }
} }
return 0; return nullptr;
} }
void GuiControlHost::MoveIntoTooltipControl(GuiControl* tooltipControl, Point location) void GuiControlHost::MoveIntoTooltipControl(GuiControl* tooltipControl, Point location)
@@ -6547,7 +6547,15 @@ GuiControlHost
void GuiControlHost::Destroying() void GuiControlHost::Destroying()
{ {
WindowDestroying.Execute(GetNotifyEventArguments()); WindowDestroying.Execute(GetNotifyEventArguments());
SetNativeWindow(0); calledDestroyed = true;
if (deleteWhenDestroyed)
{
GetApplication()->InvokeInMainThread(this, [=]()
{
delete this;
});
}
SetNativeWindow(nullptr);
} }
void GuiControlHost::UpdateClientSizeAfterRendering(Size clientSize) void GuiControlHost::UpdateClientSizeAfterRendering(Size clientSize)
@@ -6580,6 +6588,20 @@ GuiControlHost
delete host; delete host;
} }
void GuiControlHost::DeleteAfterProcessingAllEvents()
{
auto window = host->GetNativeWindow();
if (calledDestroyed || !window)
{
delete this;
}
else
{
deleteWhenDestroyed = true;
GetCurrentController()->WindowService()->DestroyNativeWindow(window);
}
}
compositions::GuiGraphicsHost* GuiControlHost::GetGraphicsHost() compositions::GuiGraphicsHost* GuiControlHost::GetGraphicsHost()
{ {
return host; return host;
@@ -6902,17 +6924,17 @@ GuiControlHost
void GuiControlHost::Close() void GuiControlHost::Close()
{ {
INativeWindow* window=host->GetNativeWindow(); if (auto window = host->GetNativeWindow())
if(window)
{ {
if(GetCurrentController()->WindowService()->GetMainWindow()!=window) auto mainWindow = GetCurrentController()->WindowService()->GetMainWindow();
if (mainWindow == window)
{ {
window->Hide(false); SetNativeWindow(nullptr);
GetCurrentController()->WindowService()->DestroyNativeWindow(window);
} }
else else
{ {
SetNativeWindow(0); window->Hide(false);
GetCurrentController()->WindowService()->DestroyNativeWindow(window);
} }
} }
} }
@@ -7054,7 +7076,7 @@ GuiWindow
INativeWindow* window=host->GetNativeWindow(); INativeWindow* window=host->GetNativeWindow();
if(window) if(window)
{ {
SetNativeWindow(0); SetNativeWindow(nullptr);
GetCurrentController()->WindowService()->DestroyNativeWindow(window); GetCurrentController()->WindowService()->DestroyNativeWindow(window);
} }
} }
@@ -7153,7 +7175,7 @@ GuiWindow
ShowModal(owner, [=]() ShowModal(owner, [=]()
{ {
callback(); callback();
delete this; DeleteAfterProcessingAllEvents();
}); });
} }
@@ -8599,8 +8621,15 @@ Helper Functions
void SafeDeleteControl(controls::GuiControl* value) void SafeDeleteControl(controls::GuiControl* value)
{ {
NotifyFinalizeInstance(value); if (auto controlHost = dynamic_cast<controls::GuiControlHost*>(value))
SafeDeleteControlInternal(value); {
controlHost->DeleteAfterProcessingAllEvents();
}
else
{
NotifyFinalizeInstance(value);
SafeDeleteControlInternal(value);
}
} }
void SafeDeleteComposition(GuiGraphicsComposition* value) void SafeDeleteComposition(GuiGraphicsComposition* value)
+14 -8
View File
@@ -2218,28 +2218,28 @@ Native Window Services
/// Create a window. /// Create a window.
/// </summary> /// </summary>
/// <returns>The created window.</returns> /// <returns>The created window.</returns>
virtual INativeWindow* CreateNativeWindow()=0; virtual INativeWindow* CreateNativeWindow() = 0;
/// <summary> /// <summary>
/// Destroy a window. /// Destroy a window.
/// </summary> /// </summary>
/// <param name="window">The window to destroy.</param> /// <param name="window">The window to destroy.</param>
virtual void DestroyNativeWindow(INativeWindow* window)=0; virtual void DestroyNativeWindow(INativeWindow* window) = 0;
/// <summary> /// <summary>
/// Get the main window. /// Get the main window.
/// </summary> /// </summary>
/// <returns>The main window.</returns> /// <returns>The main window.</returns>
virtual INativeWindow* GetMainWindow()=0; virtual INativeWindow* GetMainWindow() = 0;
/// <summary> /// <summary>
/// Get the window that under a specified position in screen space. /// Get the window that under a specified position in screen space.
/// </summary> /// </summary>
/// <returns>The window that under a specified position in screen space.</returns> /// <returns>The window that under a specified position in screen space.</returns>
/// <param name="location">The specified position in screen space.</param> /// <param name="location">The specified position in screen space.</param>
virtual INativeWindow* GetWindow(Point location)=0; virtual INativeWindow* GetWindow(Point location) = 0;
/// <summary> /// <summary>
/// Make the specified window a main window, show that window, and wait until the windows is closed. /// Make the specified window a main window, show that window, and wait until the windows is closed.
/// </summary> /// </summary>
/// <param name="window">The specified window.</param> /// <param name="window">The specified window.</param>
virtual void Run(INativeWindow* window)=0; virtual void Run(INativeWindow* window) = 0;
}; };
/// <summary> /// <summary>
@@ -11002,14 +11002,17 @@ Control Host
virtual void OnNativeWindowChanged(); virtual void OnNativeWindowChanged();
virtual void OnVisualStatusChanged(); virtual void OnVisualStatusChanged();
protected: protected:
static const vint TooltipDelayOpenTime=500; static const vint TooltipDelayOpenTime = 500;
static const vint TooltipDelayCloseTime=500; static const vint TooltipDelayCloseTime = 500;
static const vint TooltipDelayLifeTime=5000; static const vint TooltipDelayLifeTime = 5000;
Ptr<INativeDelay> tooltipOpenDelay; Ptr<INativeDelay> tooltipOpenDelay;
Ptr<INativeDelay> tooltipCloseDelay; Ptr<INativeDelay> tooltipCloseDelay;
Point tooltipLocation; Point tooltipLocation;
bool calledDestroyed = false;
bool deleteWhenDestroyed = false;
controls::GuiControlHost* GetControlHostForInstance()override; controls::GuiControlHost* GetControlHostForInstance()override;
GuiControl* GetTooltipOwner(Point location); GuiControl* GetTooltipOwner(Point location);
void MoveIntoTooltipControl(GuiControl* tooltipControl, Point location); void MoveIntoTooltipControl(GuiControl* tooltipControl, Point location);
@@ -11051,6 +11054,9 @@ Control Host
/// <summary>Window destroying event.</summary> /// <summary>Window destroying event.</summary>
compositions::GuiNotifyEvent WindowDestroying; compositions::GuiNotifyEvent WindowDestroying;
/// <summary>Delete this control host after processing all events.</summary>
void DeleteAfterProcessingAllEvents();
/// <summary>Get the internal <see cref="compositions::GuiGraphicsHost"/> object to host the window content.</summary> /// <summary>Get the internal <see cref="compositions::GuiGraphicsHost"/> object to host the window content.</summary>
/// <returns>The internal <see cref="compositions::GuiGraphicsHost"/> object to host the window content.</returns> /// <returns>The internal <see cref="compositions::GuiGraphicsHost"/> object to host the window content.</returns>
compositions::GuiGraphicsHost* GetGraphicsHost(); compositions::GuiGraphicsHost* GetGraphicsHost();
+1
View File
@@ -2166,6 +2166,7 @@ Type Declaration (Class)
CLASS_MEMBER_PROPERTY_FAST(ShortcutKeyManager) CLASS_MEMBER_PROPERTY_FAST(ShortcutKeyManager)
CLASS_MEMBER_PROPERTY_READONLY_FAST(RelatedScreen) CLASS_MEMBER_PROPERTY_READONLY_FAST(RelatedScreen)
CLASS_MEMBER_METHOD(DeleteAfterProcessingAllEvents, NO_PARAMETER)
CLASS_MEMBER_METHOD(ForceCalculateSizeImmediately, NO_PARAMETER) CLASS_MEMBER_METHOD(ForceCalculateSizeImmediately, NO_PARAMETER)
CLASS_MEMBER_METHOD(GetFocused, NO_PARAMETER) CLASS_MEMBER_METHOD(GetFocused, NO_PARAMETER)
CLASS_MEMBER_METHOD(SetFocused, NO_PARAMETER) CLASS_MEMBER_METHOD(SetFocused, NO_PARAMETER)
+63 -55
View File
@@ -13301,30 +13301,22 @@ WindowsForm
protected: protected:
HWND handle; HWND handle;
WString title; WString title;
WindowsCursor* cursor; WindowsCursor* cursor = nullptr;
Point caretPoint; Point caretPoint;
WindowsForm* parentWindow; WindowsForm* parentWindow = nullptr;
bool alwaysPassFocusToParent; bool alwaysPassFocusToParent = false;
List<INativeWindowListener*> listeners; List<INativeWindowListener*> listeners;
vint mouseLastX; vint mouseLastX = -1;
vint mouseLastY; vint mouseLastY = -1;
vint mouseHoving; bool mouseHoving = false;
Interface* graphicsHandler; Interface* graphicsHandler = nullptr;
bool customFrameMode; bool customFrameMode = false;
List<Ptr<INativeMessageHandler>> messageHandlers; List<Ptr<INativeMessageHandler>> messageHandlers;
bool supressingAlt; bool supressingAlt = false;
Ptr<bool> flagDisposed = new bool(false);
public: public:
WindowsForm(HWND parent, WString className, HINSTANCE hInstance) WindowsForm(HWND parent, WString className, HINSTANCE hInstance)
:cursor(0)
,parentWindow(0)
,alwaysPassFocusToParent(false)
,mouseLastX(-1)
,mouseLastY(-1)
,mouseHoving(false)
,graphicsHandler(0)
,customFrameMode(false)
,supressingAlt(false)
{ {
DWORD exStyle = WS_EX_APPWINDOW | WS_EX_CONTROLPARENT; 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; DWORD style = WS_BORDER | WS_CAPTION | WS_SIZEBOX | WS_SYSMENU | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
@@ -13333,12 +13325,13 @@ WindowsForm
~WindowsForm() ~WindowsForm()
{ {
*flagDisposed.Obj() = true;
List<INativeWindowListener*> copiedListeners; List<INativeWindowListener*> copiedListeners;
CopyFrom(copiedListeners, listeners); CopyFrom(copiedListeners, listeners);
for(vint i=0;i<copiedListeners.Count();i++) for (vint i = 0; i < copiedListeners.Count(); i++)
{ {
INativeWindowListener* listener=copiedListeners[i]; INativeWindowListener* listener = copiedListeners[i];
if(listeners.Contains(listener)) if (listeners.Contains(listener))
{ {
listener->Destroyed(); listener->Destroyed();
} }
@@ -13356,11 +13349,14 @@ WindowsForm
bool HandleMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& result) bool HandleMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& result)
{ {
#define CHECK_DISPOSED if (*flag.Obj()) return skip
auto flag = flagDisposed;
bool skip = false; bool skip = false;
{ {
FOREACH(Ptr<INativeMessageHandler>, handler, messageHandlers) FOREACH(Ptr<INativeMessageHandler>, handler, messageHandlers)
{ {
handler->BeforeHandle(hwnd, uMsg, wParam, lParam, skip); handler->BeforeHandle(hwnd, uMsg, wParam, lParam, skip);
CHECK_DISPOSED;
} }
if (skip) if (skip)
{ {
@@ -13368,14 +13364,17 @@ WindowsForm
} }
} }
skip = HandleMessageInternal(hwnd, uMsg, wParam, lParam, result); skip = HandleMessageInternal(hwnd, uMsg, wParam, lParam, result);
CHECK_DISPOSED;
if (GetWindowsFormFromHandle(hwnd)) if (GetWindowsFormFromHandle(hwnd))
{ {
FOREACH(Ptr<INativeMessageHandler>, handler, messageHandlers) FOREACH(Ptr<INativeMessageHandler>, handler, messageHandlers)
{ {
handler->AfterHandle(hwnd, uMsg, wParam, lParam, skip, result); handler->AfterHandle(hwnd, uMsg, wParam, lParam, skip, result);
CHECK_DISPOSED;
} }
} }
return skip; return skip;
#undef CHECK_DISPOSED
} }
HWND GetWindowHandle()override HWND GetWindowHandle()override
@@ -13824,6 +13823,7 @@ WindowsController
Dictionary<HWND, WindowsForm*> windows; Dictionary<HWND, WindowsForm*> windows;
INativeWindow* mainWindow; INativeWindow* mainWindow;
HWND mainWindowHandle; HWND mainWindowHandle;
vint handleMessageLevelCounter = 0;
WindowsCallbackService callbackService; WindowsCallbackService callbackService;
WindowsResourceService resourceService; WindowsResourceService resourceService;
@@ -13868,51 +13868,59 @@ WindowsController
bool HandleMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& result) bool HandleMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& result)
{ {
bool skipDefaultProcedure=false; bool skipDefaultProcedure=false;
vint index=windows.Keys().IndexOf(hwnd); handleMessageLevelCounter++;
if(index!=-1)
{ {
WindowsForm* window=windows.Values().Get(index); vint index = windows.Keys().IndexOf(hwnd);
skipDefaultProcedure=window->HandleMessage(hwnd, uMsg, wParam, lParam, result); if (index != -1)
switch(uMsg)
{ {
case WM_CLOSE: WindowsForm* window = windows.Values().Get(index);
if(!skipDefaultProcedure) skipDefaultProcedure = window->HandleMessage(hwnd, uMsg, wParam, lParam, result);
switch (uMsg)
{ {
ShowWindow(window->GetWindowHandle(), SW_HIDE); case WM_CLOSE:
if(window!=mainWindow) if (!skipDefaultProcedure)
{ {
skipDefaultProcedure=true; ShowWindow(window->GetWindowHandle(), SW_HIDE);
if (window != mainWindow)
{
skipDefaultProcedure = true;
}
}
break;
case WM_DESTROY:
DestroyNativeWindow(window);
break;
}
}
}
{
if (hwnd == mainWindowHandle && uMsg == WM_DESTROY)
{
for (vint i = 0; i < windows.Count(); i++)
{
if (windows.Values().Get(i)->IsVisible())
{
windows.Values().Get(i)->Hide(true);
} }
} }
break; while (windows.Count())
case WM_DESTROY:
DestroyNativeWindow(window);
break;
}
}
if(hwnd==mainWindowHandle && uMsg==WM_DESTROY)
{
for(vint i=0;i<windows.Count();i++)
{
if(windows.Values().Get(i)->IsVisible())
{ {
windows.Values().Get(i)->Hide(true); DestroyNativeWindow(windows.Values().Get(0));
} }
PostQuitMessage(0);
} }
while(windows.Count())
{
DestroyNativeWindow(windows.Values().Get(0));
}
PostQuitMessage(0);
} }
asyncService.ExecuteAsyncTasks(); handleMessageLevelCounter--;
if (handleMessageLevelCounter == 0)
{
asyncService.ExecuteAsyncTasks();
}
return skipDefaultProcedure; return skipDefaultProcedure;
} }
//======================================================================= //=======================================================================
INativeWindow* CreateNativeWindow() INativeWindow* CreateNativeWindow()override
{ {
WindowsForm* window=new WindowsForm(godWindow, windowClass.GetName(), hInstance); WindowsForm* window=new WindowsForm(godWindow, windowClass.GetName(), hInstance);
windows.Add(window->GetWindowHandle(), window); windows.Add(window->GetWindowHandle(), window);
@@ -13921,7 +13929,7 @@ WindowsController
return window; return window;
} }
void DestroyNativeWindow(INativeWindow* window) void DestroyNativeWindow(INativeWindow* window)override
{ {
WindowsForm* windowsForm=dynamic_cast<WindowsForm*>(window); WindowsForm* windowsForm=dynamic_cast<WindowsForm*>(window);
windowsForm->InvokeDestroying(); windowsForm->InvokeDestroying();
@@ -13933,12 +13941,12 @@ WindowsController
} }
} }
INativeWindow* GetMainWindow() INativeWindow* GetMainWindow()override
{ {
return mainWindow; return mainWindow;
} }
void Run(INativeWindow* window) void Run(INativeWindow* window)override
{ {
mainWindow=window; mainWindow=window;
mainWindowHandle=GetWindowsForm(window)->GetWindowHandle(); mainWindowHandle=GetWindowsForm(window)->GetWindowHandle();
@@ -13952,7 +13960,7 @@ WindowsController
} }
} }
INativeWindow* GetWindow(Point location) INativeWindow* GetWindow(Point location)override
{ {
POINT p; POINT p;
p.x=(int)location.x; p.x=(int)location.x;
@@ -305,7 +305,7 @@
<![CDATA[ <![CDATA[
prop FolderName : string = "" {} prop FolderName : string = "" {}
var Ready : bool = true; var Ready : bool = false;
]]> ]]>
</ref.Members> </ref.Members>
<Window ref.Name="self" Text="New Folder" ClientSize="x:240 y:120" MaximizedBox="false" MinimizedBox="false" SizeBox="false"> <Window ref.Name="self" Text="New Folder" ClientSize="x:240 y:120" MaximizedBox="false" MinimizedBox="false" SizeBox="false">