]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/window.cpp
added WXK_WINDOWS_XXX key constants
[wxWidgets.git] / src / mac / window.cpp
index 2515e88ca54ab28664cb9e03f6d5a70b6c16cee7..1c05505709b7fb38ec16ba83b41de34ed083af7d 100644 (file)
@@ -133,6 +133,8 @@ void wxWindowMac::Init()
 // Destructor
 wxWindowMac::~wxWindowMac()
 {
+    SendDestroyEvent();
+
     // deleting a window while it is shown invalidates the region
     if ( IsShown() ) {
         wxWindowMac* iter = this ;
@@ -169,7 +171,7 @@ wxWindowMac::~wxWindowMac()
     {
         s_lastMouseWindow = NULL ;
     }
-    
+
     wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
     if ( frame )
     {
@@ -197,6 +199,17 @@ bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
 {
     wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
 
+#if wxUSE_STATBOX
+    // wxGTK doesn't allow to create controls with static box as the parent so
+    // this will result in a crash when the program is ported to wxGTK - warn
+    // about it
+    //
+    // the correct solution is to create the controls as siblings of the
+    // static box
+    wxASSERT_MSG( !wxDynamicCast(parent, wxStaticBox),
+                  _T("wxStaticBox can't be used as a window parent!") );
+#endif // wxUSE_STATBOX
+
     if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
         return FALSE;
 
@@ -227,24 +240,32 @@ void wxWindowMac::SetFocus()
     {
         if (gFocusWindow )
         {
-            #if wxUSE_CARET
+#if wxUSE_CARET
                 // Deal with caret
                 if ( gFocusWindow->m_caret )
                 {
                       gFocusWindow->m_caret->OnKillFocus();
                 }
-            #endif // wxUSE_CARET
-      #ifndef __WXUNIVERSAL__
+#endif // wxUSE_CARET
+#ifndef __WXUNIVERSAL__
             wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
             if ( control && control->GetMacControl() )
             {
                 UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl()  , kControlFocusNoPart ) ;
                 control->MacRedrawControl() ;
             }
-            #endif
-            wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
-            event.SetEventObject(gFocusWindow);
-            gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
+#endif
+            // Without testing the window id, for some reason
+            // a kill focus event can still be sent to
+            // the control just being focussed.
+            int thisId = this->m_windowId;
+            int gFocusWindowId = gFocusWindow->m_windowId;
+            if (gFocusWindowId != thisId)
+            {
+                wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
+                event.SetEventObject(gFocusWindow);
+                gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
+            }
         }
         gFocusWindow = this ;
         {
@@ -609,7 +630,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
 
         if ( HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
         {
-            wxPoint oldPos( m_x , m_y ) ; 
+            wxPoint oldPos( m_x , m_y ) ;
             wxPoint newPos( actualX , actualY ) ;
             MacWindowToRootWindow( &oldPos.x , &oldPos.y ) ;
             MacWindowToRootWindow( &newPos.x , &newPos.y ) ;
@@ -1245,7 +1266,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
         if (child == m_vScrollBar) continue;
         if (child == m_hScrollBar) continue;
         if (child->IsTopLevel()) continue;
-        
+
         int x,y;
         child->GetPosition( &x, &y );
         int w,h;
@@ -1480,15 +1501,15 @@ bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMa
 
 static wxWindow *gs_lastWhich = NULL;
 
-bool wxWindowMac::MacSetupCursor( const wxPoint& pt) 
+bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
 {
     // first trigger a set cursor event
-    
+
     wxPoint clientorigin = GetClientAreaOrigin() ;
     wxSize clientsize = GetClientSize() ;
     wxCursor cursor ;
     if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
-    {  
+    {
         wxSetCursorEvent event( pt.x , pt.y );
 
         bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
@@ -1498,7 +1519,7 @@ bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
         }
         else
         {
-            
+
             // the test for processedEvtSetCursor is here to prevent using m_cursor
             // if the user code caught EVT_SET_CURSOR() and returned nothing from
             // it - this is a way to say that our cursor shouldn't be used for this
@@ -1663,9 +1684,9 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling
       parent->MacWindowToRootWindow( &x, &y ) ;
       MacRootWindowToWindow( &x , &y ) ;
 
-      SetRectRgn( tempRgn , 
-       x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() , 
-       x + size.x - parent->MacGetRightBorderSize(), 
+      SetRectRgn( tempRgn ,
+       x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
+       x + size.x - parent->MacGetRightBorderSize(),
        y + size.y - parent->MacGetBottomBorderSize()) ;
 
       SectRgn( visRgn , tempRgn , visRgn ) ;
@@ -1765,7 +1786,8 @@ void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
         if ( erase && !EmptyRgn(ownUpdateRgn) )
         {
           wxWindowDC dc(this);
-          dc.SetClippingRegion(wxRegion(ownUpdateRgn));
+          if (!EmptyRgn(ownUpdateRgn))
+              dc.SetClippingRegion(wxRegion(ownUpdateRgn));
           wxEraseEvent eevent( GetId(), &dc );
           eevent.SetEventObject( this );
           GetEventHandler()->ProcessEvent( eevent );