Misc warning fixes by ABX
[wxWidgets.git] / src / mac / toplevel.cpp
index 7e109340963f558aaeed76ef66e09c890476f133..d8f5c9563cf7c1ff13d9af92f4aedc60b21adf67 100644 (file)
@@ -126,7 +126,7 @@ static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , Even
     {
         case kEventTextInputUnicodeForKeyEvent :
             // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not
-            // get its own kEventTextInputUnicodeForKeyEvent, so we route back the 
+            // get its own kEventTextInputUnicodeForKeyEvent, so we route back the
             wxControl* control = wxDynamicCast( focus , wxControl ) ;
             if ( control )
             {
@@ -341,13 +341,13 @@ static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRe
 
                 GetEventParameter( event, kEventParamCurrentBounds, typeQDRectangle, NULL,
                     sizeof( newContentRect ), NULL, &newContentRect );
-                    
+
                 wxRect contentRect(newContentRect.left , newContentRect.top ,
                     newContentRect.right - newContentRect.left ,
                     newContentRect.bottom - newContentRect.top) ;
-                    
+
                 bool handled = false ;
-                if ((attributes & kWindowBoundsChangeSizeChanged) != 0) 
+                if ((attributes & kWindowBoundsChangeSizeChanged) != 0)
                 {
                     wxSizeEvent event(contentRect , toplevelWindow->GetId());
                     event.SetEventObject(toplevelWindow);
@@ -439,6 +439,7 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
 // ----------------------------------------------------------------------------
 
 WXHWND wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
+wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
 
 void wxTopLevelWindowMac::Init()
 {
@@ -563,6 +564,7 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
            long style,
            const wxString& name )
 {
+    OSStatus err = noErr ;
     SetName(name);
     m_windowStyle = style;
     m_isShown = FALSE;
@@ -622,7 +624,7 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
     else
     {
         if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||
-            HasFlag( wxSYSTEM_MENU ) )
+            HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )
         {
             wclass = kDocumentWindowClass ;
         }
@@ -636,16 +638,19 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
         }
     }
 
-    if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
+    if ( HasFlag( wxMINIMIZE_BOX ) )
     {
-        attr |= kWindowFullZoomAttribute ;
         attr |= kWindowCollapseBoxAttribute ;
     }
+    if ( HasFlag( wxMAXIMIZE_BOX ) )
+    {
+        attr |= kWindowFullZoomAttribute ;
+    }
     if ( HasFlag( wxRESIZE_BORDER ) )
     {
         attr |= kWindowResizableAttribute ;
     }
-    if ( HasFlag( wxSYSTEM_MENU ) )
+    if ( HasFlag( wxCLOSE_BOX) )
     {
         attr |= kWindowCloseBoxAttribute ;
     }
@@ -664,23 +669,24 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
         customWindowDefSpec.defType = kWindowDefProcPtr;
         customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);
 
-        ::CreateCustomWindow( &customWindowDefSpec, wclass,
+        err = ::CreateCustomWindow( &customWindowDefSpec, wclass,
                               attr, &theBoundsRect,
                               (WindowRef*) &m_macWindow);
     }
     else
 #endif
     {
-        ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
+        err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;
     }
 
+    wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );
     wxAssociateWinWithMacWindow( m_macWindow , this ) ;
     UMASetWTitle( (WindowRef)m_macWindow , title ) ;
     ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;
 #if TARGET_CARBON
     InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;
     InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(),
-        GetEventTypeCount(eventList), eventList, this, &((EventHandlerRef)m_macEventHandler));
+        GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler);
 #endif
     m_macFocus = NULL ;
 
@@ -707,9 +713,9 @@ void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR cli
     *rootwin = this ;
 }
 
-void wxTopLevelWindowMac::Clear()
+void wxTopLevelWindowMac::ClearBackground()
 {
-    wxWindow::Clear() ;
+    wxWindow::ClearBackground() ;
 }
 
 WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding()
@@ -760,7 +766,7 @@ void wxTopLevelWindowMac::MacUpdate( long timestamp)
         DisposeRgn( diffRgn );
     if ( visRgn )
         DisposeRgn( visRgn ) ;
-        
+
     EndUpdate( (WindowRef)m_macWindow ) ;
     SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;
     m_macNeedsErasing = false ;
@@ -916,8 +922,21 @@ void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part)
 
 #endif
 
+void wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp)
+{
+    if(s_macDeactivateWindow)
+    {
+        wxLogDebug("Doing delayed deactivation of %p",s_macDeactivateWindow);
+        s_macDeactivateWindow->MacActivate(timestamp, false);
+    }
+}
+
 void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
 {
+    wxLogDebug("TopLevel=%p::MacActivate",this);
+    if(s_macDeactivateWindow==this)
+        s_macDeactivateWindow=NULL;
+    MacDelayedDeactivation(timestamp);
     wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
     event.m_timeStamp = timestamp ;
     event.SetEventObject(this);