]> git.saurik.com Git - wxWidgets.git/commitdiff
Added a mechanism allowing a toplevel window to delay its deactivation
authorDavid Elliott <dfe@tgwbd.org>
Thu, 13 Nov 2003 15:13:55 +0000 (15:13 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 13 Nov 2003 15:13:55 +0000 (15:13 +0000)
event.  This will come in handy for MDI among other things.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24545 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/toplevel.h
src/cocoa/app.mm
src/cocoa/toplevel.mm

index ae5e610a111f1213583f6b33e4ecc617cfb6fb13..8276028e6761e9a3827b77d2924649a81ee00e2a 100644 (file)
@@ -4,9 +4,9 @@
 // Author:      David Elliott
 // Modified by:
 // Created:     2002/12/08
-// RCS-ID:      $Id
+// RCS-ID:      $Id$
 // Copyright:   (c) 2002 David Elliott
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 #ifndef __WX_COCOA_TOPLEVEL_H__
@@ -68,6 +68,7 @@ public:
     virtual void CocoaDelegate_windowDidBecomeMain(void);
     virtual void CocoaDelegate_windowDidResignMain(void);
     virtual wxMenuBar* GetAppMenuBar(wxCocoaNSWindow *win);
+    static void DeactivatePendingWindow();
 protected:
     void SetNSWindow(WX_NSWindow cocoaNSWindow);
     WX_NSWindow m_cocoaNSWindow;
@@ -75,10 +76,12 @@ protected:
     virtual void CocoaReplaceView(WX_NSView oldView, WX_NSView newView);
     static unsigned int NSWindowStyleForWxStyle(long style);
 
+    static wxTopLevelWindowCocoa *sm_cocoaDeactivateWindow;
 // ------------------------------------------------------------------------
 // Implementation
 // ------------------------------------------------------------------------
 public:
+    virtual bool Destroy();
     // Pure virtuals
     virtual void Maximize(bool maximize = true);
     virtual bool IsMaximized() const;
index d1676de387cba9a4505013c577f50bf06c30cfcb..4ef6974b2f2e35d669e9d4938c522237d9ca8a1e 100644 (file)
@@ -261,6 +261,7 @@ void wxApp::CocoaDelegate_applicationDidBecomeActive()
 
 void wxApp::CocoaDelegate_applicationWillResignActive()
 {
+    wxTopLevelWindowCocoa::DeactivatePendingWindow();
 }
 
 void wxApp::CocoaDelegate_applicationDidResignActive()
index c1ef688bda803a6dfd3082e0edda3ad09c14107d..7a7c11cbb0700e26cb0f93dcabb974ea53f6f0e1 100644 (file)
@@ -45,6 +45,8 @@ wxWindowList       wxModelessWindows;
 // wxTopLevelWindowCocoa implementation
 // ============================================================================
 
+wxTopLevelWindowCocoa *wxTopLevelWindowCocoa::sm_cocoaDeactivateWindow = NULL;
+
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowCocoa creation
 // ----------------------------------------------------------------------------
@@ -135,11 +137,22 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
 
 wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa()
 {
+    wxASSERT(sm_cocoaDeactivateWindow!=this);
     wxAutoNSAutoreleasePool pool;
     DestroyChildren();
     SetNSWindow(NULL);
 }
 
+bool wxTopLevelWindowCocoa::Destroy()
+{
+    if(sm_cocoaDeactivateWindow==this)
+    {
+        sm_cocoaDeactivateWindow = NULL;
+        wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey();
+    }
+    return wxTopLevelWindowBase::Destroy();
+}
+
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowCocoa Cocoa Specifics
 // ----------------------------------------------------------------------------
@@ -174,8 +187,16 @@ void wxTopLevelWindowCocoa::CocoaReplaceView(WX_NSView oldView, WX_NSView newVie
         [m_cocoaNSWindow setContentView:newView];
 }
 
+/*static*/ void wxTopLevelWindowCocoa::DeactivatePendingWindow()
+{
+    if(sm_cocoaDeactivateWindow)
+        sm_cocoaDeactivateWindow->wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey();
+    sm_cocoaDeactivateWindow = NULL;
+}
+
 void wxTopLevelWindowCocoa::CocoaDelegate_windowDidBecomeKey(void)
 {
+    DeactivatePendingWindow();
     wxLogDebug("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidBecomeKey",this);
     wxActivateEvent event(wxEVT_ACTIVATE, TRUE, GetId());
     event.SetEventObject(this);