]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/window.cpp
added WXK_WINDOWS_XXX key constants
[wxWidgets.git] / src / mac / window.cpp
index 70ffe076e7c3596ad914eee9a2214f3a4f174dba..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 ) ;
@@ -786,13 +807,13 @@ bool wxWindowMac::Show(bool show)
 
 void wxWindowMac::MacSuperShown( bool show )
 {
-    wxNode *node = GetChildren().First();
+    wxWindowListNode *node = GetChildren().GetFirst();
     while ( node )
     {
-        wxWindowMac *child = (wxWindowMac *)node->Data();
+        wxWindowMac *child = (wxWindowMac *)node->GetData();
         if ( child->m_isShown )
             child->MacSuperShown( show ) ;
-        node = node->Next();
+        node = node->GetNext();
     }
 }
 
@@ -804,13 +825,13 @@ void wxWindowMac::MacSuperEnabled( bool enabled )
       // because unter MacOSX the frames are drawn with an addXXX mode)
       // the borders area
     }
-    wxNode *node = GetChildren().First();
+    wxWindowListNode *node = GetChildren().GetFirst();
     while ( node )
     {
-        wxWindowMac *child = (wxWindowMac *)node->Data();
+        wxWindowMac *child = (wxWindowMac *)node->GetData();
         if ( child->m_isShown )
             child->MacSuperEnabled( enabled ) ;
-        node = node->Next();
+        node = node->GetNext();
     }
 }
 
@@ -1239,13 +1260,13 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
         DisposeRgn( updateRgn ) ;
     }
 
-    for (wxNode *node = GetChildren().First(); node; node = node->Next())
+    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
     {
-        wxWindowMac *child = (wxWindowMac*)node->Data();
+        wxWindowMac *child = (wxWindowMac*)node->GetData();
         if (child == m_vScrollBar) continue;
         if (child == m_hScrollBar) continue;
         if (child->IsTopLevel()) continue;
-        
+
         int x,y;
         child->GetPosition( &x, &y );
         int w,h;
@@ -1313,13 +1334,13 @@ void wxWindowMac::OnCommand(wxWindowMac& win, wxCommandEvent& event)
 wxObject* wxWindowMac::GetChild(int number) const
 {
     // Return a pointer to the Nth object in the Panel
-    wxNode *node = GetChildren().First();
+    wxNode *node = GetChildren().GetFirst();
     int n = number;
     while (node && n--)
-        node = node->Next();
+        node = node->GetNext();
     if ( node )
     {
-        wxObject *obj = (wxObject *)node->Data();
+        wxObject *obj = (wxObject *)node->GetData();
         return(obj);
     }
     else
@@ -1435,9 +1456,9 @@ bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac**
       newPoint.y -= m_y;
     }
 
-    for (wxNode *node = GetChildren().First(); node; node = node->Next())
+    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
     {
-        wxWindowMac *child = (wxWindowMac*)node->Data();
+        wxWindowMac *child = (wxWindowMac*)node->GetData();
         // added the m_isShown test --dmazzoni
         if ( child->MacGetRootWindow() == window && child->m_isShown )
         {
@@ -1478,18 +1499,17 @@ bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMa
     return FALSE ;
 }
 
-extern int wxBusyCursorCount ;
 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);
@@ -1499,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
@@ -1541,9 +1561,9 @@ bool wxWindowMac::MacDispatchMouseEvent(wxMouseEvent& event)
     int x = event.m_x ;
     int y = event.m_y ;
 
-    for (wxNode *node = GetChildren().First(); node; node = node->Next())
+    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
     {
-        wxWindowMac *child = (wxWindowMac*)node->Data();
+        wxWindowMac *child = (wxWindowMac*)node->GetData();
         if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
         {
             if (child->MacDispatchMouseEvent(event))
@@ -1664,10 +1684,10 @@ 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->MacGetLeftBorderSize() - parent->MacGetRightBorderSize(), 
-       y + size.y - parent->MacGetTopBorderSize() - parent->MacGetBottomBorderSize()) ;
+      SetRectRgn( tempRgn ,
+       x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
+       x + size.x - parent->MacGetRightBorderSize(),
+       y + size.y - parent->MacGetBottomBorderSize()) ;
 
       SectRgn( visRgn , tempRgn , visRgn ) ;
       if ( parent->IsTopLevel() )
@@ -1679,9 +1699,9 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling
   {
       if ( GetWindowStyle() & wxCLIP_CHILDREN )
       {
-        for (wxNode *node = GetChildren().First(); node; node = node->Next())
+        for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
         {
-            wxWindowMac *child = (wxWindowMac*)node->Data();
+            wxWindowMac *child = (wxWindowMac*)node->GetData();
 
             if ( !child->IsTopLevel() && child->IsShown() )
             {
@@ -1702,9 +1722,9 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool respectChildrenAndSibling
       if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )
       {
         bool thisWindowThrough = false ;
-        for (wxNode *node = GetParent()->GetChildren().First(); node; node = node->Next())
+        for (wxWindowListNode *node = GetParent()->GetChildren().GetFirst(); node; node = node->GetNext())
         {
-            wxWindowMac *sibling = (wxWindowMac*)node->Data();
+            wxWindowMac *sibling = (wxWindowMac*)node->GetData();
             if ( sibling == this )
             {
               thisWindowThrough = true ;
@@ -1766,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 );
@@ -1788,11 +1809,11 @@ void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
     // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
 
     RgnHandle childupdate = NewRgn() ;
-    for (wxNode *node = GetChildren().First(); node; node = node->Next())
+    for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
     {
         // calculate the update region for the child windows by intersecting the window rectangle with our own
         // passed in update region and then offset it to be client-wise window coordinates again
-        wxWindowMac *child = (wxWindowMac*)node->Data();
+        wxWindowMac *child = (wxWindowMac*)node->GetData();
         SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;
         SectRgn( childupdate , updatergn , childupdate ) ;
         OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
@@ -1949,12 +1970,12 @@ void wxWindowMac::MacSuperChangedPosition()
 {
     // only window-absolute structures have to be moved i.e. controls
 
-    wxNode *node = GetChildren().First();
+    wxWindowListNode *node = GetChildren().GetFirst();
     while ( node )
     {
-        wxWindowMac *child = (wxWindowMac *)node->Data();
+        wxWindowMac *child = (wxWindowMac *)node->GetData();
         child->MacSuperChangedPosition() ;
-        node = node->Next();
+        node = node->GetNext();
     }
 }
 
@@ -1962,12 +1983,12 @@ void wxWindowMac::MacTopLevelWindowChangedPosition()
 {
     // only screen-absolute structures have to be moved i.e. glcanvas
 
-    wxNode *node = GetChildren().First();
+    wxWindowListNode *node = GetChildren().GetFirst();
     while ( node )
     {
-        wxWindowMac *child = (wxWindowMac *)node->Data();
+        wxWindowMac *child = (wxWindowMac *)node->GetData();
         child->MacTopLevelWindowChangedPosition() ;
-        node = node->Next();
+        node = node->GetNext();
     }
 }
 long wxWindowMac::MacGetLeftBorderSize( ) const