]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/window.cpp
removed useless PM_USE_SESSION_APIS define (it must be defined in MacHeaders
[wxWidgets.git] / src / mac / window.cpp
index 644bf7e7372fb8bcd8980dd3ad44767986c7e034..edc7d866a8004aeafd795eb68bb2dced560eb4c8 100644 (file)
@@ -152,6 +152,20 @@ void wxWindow::Init()
 // Destructor
 wxWindow::~wxWindow()
 {
 // Destructor
 wxWindow::~wxWindow()
 {
+    // deleting a window while it is shown invalidates the region
+    if ( IsShown() ) {
+        wxWindow* iter = this ;
+        while( iter ) {
+            if ( iter->m_macWindowData )
+            {
+                Refresh() ;
+                break ;
+            }
+            iter = iter->GetParent() ;
+            
+        }
+    }
+    
     m_isBeingDeleted = TRUE;
 
        if ( s_lastMouseWindow == this )
     m_isBeingDeleted = TRUE;
 
        if ( s_lastMouseWindow == this )
@@ -282,6 +296,11 @@ void wxWindow::CaptureMouse()
     wxTheApp->s_captureWindow = this ;
 }
 
     wxTheApp->s_captureWindow = this ;
 }
 
+wxWindow* wxWindowBase::GetCapture()
+{
+    return wxTheApp->s_captureWindow ;
+}
+
 void wxWindow::ReleaseMouse()
 {
     wxTheApp->s_captureWindow = NULL ;
 void wxWindow::ReleaseMouse()
 {
     wxTheApp->s_captureWindow = NULL ;
@@ -413,11 +432,19 @@ void wxWindow::MacRootWindowToClient( int *x , int *y ) const
 
 bool wxWindow::SetCursor(const wxCursor& cursor)
 {
 
 bool wxWindow::SetCursor(const wxCursor& cursor)
 {
-   if ( !wxWindowBase::SetCursor(cursor) )
-   {
-       // no change
+    if (m_cursor == cursor)
        return FALSE;
        return FALSE;
-   }
+
+    if (wxNullCursor == cursor)
+    {
+       if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
+        return FALSE ;
+    }
+    else
+    {
+       if ( ! wxWindowBase::SetCursor( cursor ) )
+        return FALSE ;
+    }
 
   wxASSERT_MSG( m_cursor.Ok(),
                   wxT("cursor must be valid after call to the base version"));
 
   wxASSERT_MSG( m_cursor.Ok(),
                   wxT("cursor must be valid after call to the base version"));
@@ -432,7 +459,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor)
   {
        if ( mouseWin == this && !wxIsBusy() )
        {
   {
        if ( mouseWin == this && !wxIsBusy() )
        {
-               cursor.MacInstall() ;
+               m_cursor.MacInstall() ;
        }
   }
 
        }
   }
 
@@ -621,7 +648,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
                        if ( focus.Ok() )
                        {
                                Rect clientrect = { 0 , 0 , m_height , m_width } ;
                        if ( focus.Ok() )
                        {
                                Rect clientrect = { 0 , 0 , m_height , m_width } ;
-                               ClipRect( &clientrect ) ;
+                               // ClipRect( &clientrect ) ;
                        InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
                        }
                }
                        InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
                        }
                }
@@ -656,7 +683,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
                                if ( focus.Ok() )
                                {
                                        Rect clientrect = { 0 , 0 , m_height , m_width } ;
                                if ( focus.Ok() )
                                {
                                        Rect clientrect = { 0 , 0 , m_height , m_width } ;
-                                       ClipRect( &clientrect ) ;
+                                       // ClipRect( &clientrect ) ;
                                InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
                                }
                        }
                                InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
                                }
                        }
@@ -667,16 +694,18 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
                MacRepositionScrollBars() ;
                if ( doMove )
                {
                MacRepositionScrollBars() ;
                if ( doMove )
                {
-               wxMoveEvent event(wxPoint(m_x, m_y), m_windowId);
+               wxPoint point(m_x, m_y);
+               wxMoveEvent event(point, m_windowId);
                event.SetEventObject(this);
                GetEventHandler()->ProcessEvent(event) ;
        }
        if ( doResize )
        {
                event.SetEventObject(this);
                GetEventHandler()->ProcessEvent(event) ;
        }
        if ( doResize )
        {
-                       MacRepositionScrollBars() ;
-               wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
-               event.SetEventObject(this);
-               GetEventHandler()->ProcessEvent(event);
+           MacRepositionScrollBars() ;
+           wxSize size(m_width, m_height);
+           wxSizeEvent event(size, m_windowId);
+           event.SetEventObject(this);
+           GetEventHandler()->ProcessEvent(event);
        }
        }
 }
        }
        }
 }
@@ -735,7 +764,8 @@ bool wxWindow::Show(bool show)
                UMASelectWindow( m_macWindowData->m_macWindow ) ;
                // no need to generate events here, they will get them triggered by macos
                // actually they should be , but apparently they are not
                UMASelectWindow( m_macWindowData->m_macWindow ) ;
                // no need to generate events here, they will get them triggered by macos
                // actually they should be , but apparently they are not
-           wxSizeEvent event(wxSize(m_width, m_height), m_windowId);
+           wxSize size(m_width, m_height);
+           wxSizeEvent event(size, m_windowId);
            event.SetEventObject(this);
            GetEventHandler()->ProcessEvent(event);
          }
            event.SetEventObject(this);
            GetEventHandler()->ProcessEvent(event);
          }
@@ -745,9 +775,17 @@ bool wxWindow::Show(bool show)
          }
        }
        MacSuperShown( show ) ;
          }
        }
        MacSuperShown( show ) ;
-       Refresh() ;
-       if(m_macWindowData)
-               MacUpdateImmediately() ;
+       if ( !show )
+       {
+           WindowRef window = GetMacRootWindow() ;
+           wxWindow* win = wxFindWinFromMacWindow( window ) ;
+           if ( !win->m_isBeingDeleted )
+               Refresh() ;     
+       }
+       else
+       {
+       Refresh() ;     
+       }
 
     return TRUE;
 }
 
     return TRUE;
 }
@@ -889,11 +927,14 @@ void wxWindow::MacEraseBackground( Rect *rect )
 
 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
 {
 
 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
 {
+//    if ( !IsShown() )
+//        return ;
+        
        wxMacDrawingHelper focus( this ) ;
        if ( focus.Ok() )
        {
                Rect clientrect = { 0 , 0 , m_height , m_width } ;
        wxMacDrawingHelper focus( this ) ;
        if ( focus.Ok() )
        {
                Rect clientrect = { 0 , 0 , m_height , m_width } ;
-               ClipRect( &clientrect ) ;
+               // ClipRect( &clientrect ) ;
 
        if ( rect )
        {
 
        if ( rect )
        {
@@ -1133,6 +1174,7 @@ void  wxWindow::MacCreateRealWindow( const wxString& title,
        UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
 
        m_macWindowData->m_macFocus = NULL ;
        UMACreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
 
        m_macWindowData->m_macFocus = NULL ;
+       m_macWindowData->m_macHasReceivedFirstActivate = true ;
 }
 
 void wxWindow::MacPaint( wxPaintEvent &event ) 
 }
 
 void wxWindow::MacPaint( wxPaintEvent &event ) 
@@ -1269,7 +1311,7 @@ void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
                                {
                                        if ( !m_hScrollBar->IsShown() )
                                                m_hScrollBar->Show(true) ;
                                {
                                        if ( !m_hScrollBar->IsShown() )
                                                m_hScrollBar->Show(true) ;
-                                       m_hScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
+                                       m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
                                }
                        }
                }
                                }
                        }
                }
@@ -1286,7 +1328,7 @@ void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
                                {
                                        if ( !m_vScrollBar->IsShown() )
                                                m_vScrollBar->Show(true) ;
                                {
                                        if ( !m_vScrollBar->IsShown() )
                                                m_vScrollBar->Show(true) ;
-                                       m_vScrollBar->SetScrollbar( pos , thumbVisible , range , refresh ) ;
+                                       m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
                                }
                        }
                }
                                }
                        }
                }
@@ -1491,13 +1533,19 @@ void wxWindow::OnIdle(wxIdleEvent& event)
 // Raise the window to the top of the Z order
 void wxWindow::Raise()
 {
 // Raise the window to the top of the Z order
 void wxWindow::Raise()
 {
-    // TODO
+    if ( m_macWindowData )
+    {
+        UMABringToFront( m_macWindowData->m_macWindow ) ;
+    }
 }
 
 // Lower the window to the bottom of the Z order
 void wxWindow::Lower()
 {
 }
 
 // Lower the window to the bottom of the Z order
 void wxWindow::Lower()
 {
-    // TODO
+    if ( m_macWindowData )
+    {
+        UMASendBehind( m_macWindowData->m_macWindow , NULL ) ;
+    }
 }
 
 void wxWindow::DoSetClientSize(int width, int height)
 }
 
 void wxWindow::DoSetClientSize(int width, int height)
@@ -1684,8 +1732,12 @@ void wxWindow::MacFireMouseEvent( EventRecord *ev )
                                else
                                        event.SetEventType(wxEVT_LEFT_DCLICK ) ;
                        }
                                else
                                        event.SetEventType(wxEVT_LEFT_DCLICK ) ;
                        }
+                   lastWhen = 0 ;
+               }
+               else
+               {
+                   lastWhen = ev->when ;
                }
                }
-               lastWhen = ev->when ;
                lastWhere = localwhere ;
        }
 
                lastWhere = localwhere ;
        }
 
@@ -1758,13 +1810,18 @@ void wxWindow::MacMouseMoved( EventRecord *ev , short part)
 }
 void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
 {
 }
 void wxWindow::MacActivate( EventRecord *ev , bool inIsActivating )
 {
+    if ( !m_macWindowData->m_macHasReceivedFirstActivate )
+        m_macWindowData->m_macHasReceivedFirstActivate = true ;
+    
        wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
        event.m_timeStamp = ev->when ;
        event.SetEventObject(this);
        
        GetEventHandler()->ProcessEvent(event);
        
        wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
        event.m_timeStamp = ev->when ;
        event.SetEventObject(this);
        
        GetEventHandler()->ProcessEvent(event);
        
+    Refresh(false) ;
        UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
        UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
+//     MacUpdateImmediately() ;
 }
 
 void wxWindow::MacRedraw( RgnHandle updatergn , long time)
 }
 
 void wxWindow::MacRedraw( RgnHandle updatergn , long time)
@@ -1839,7 +1896,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
                                RGBBackColor( &m_backgroundColour.GetPixel()) ;
                        }
             // subtract all non transparent children from updatergn
                                RGBBackColor( &m_backgroundColour.GetPixel()) ;
                        }
             // subtract all non transparent children from updatergn
-
+            
            RgnHandle childarea = NewRgn() ;
                for (wxNode *node = GetChildren().First(); node; node = node->Next())
                {
            RgnHandle childarea = NewRgn() ;
                for (wxNode *node = GetChildren().First(); node; node = node->Next())
                {
@@ -1847,7 +1904,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
                        // eventually test for transparent windows
                        if ( child->GetMacRootWindow() == window && child->IsShown() )
                        {
                        // eventually test for transparent windows
                        if ( child->GetMacRootWindow() == window && child->IsShown() )
                        {
-                           if ( !child->IsKindOf( CLASSINFO( wxNotebook ) ) && !child->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
+                           if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() )
                            {
                                SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;
                                DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ;
                            {
                                SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;
                                DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ;
@@ -1858,7 +1915,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
 
                        if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
                                eraseBackground = true ;
 
                        if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
                                eraseBackground = true ;
-                       SetClip( updatergn ) ;
+                       SetClip( ownUpdateRgn ) ;
                        if ( m_macEraseOnRedraw ) {
                        if ( eraseBackground  )
                        {
                        if ( m_macEraseOnRedraw ) {
                        if ( eraseBackground  )
                        {
@@ -1930,7 +1987,7 @@ void wxWindow::MacUpdateImmediately()
                    GetPortVisibleRegion( GetWindowPort( window ), region );
 
                                // if windowshade gives incompatibility , take the follwing out
                    GetPortVisibleRegion( GetWindowPort( window ), region );
 
                                // if windowshade gives incompatibility , take the follwing out
-                   if ( !EmptyRgn( region ) )
+                   if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
                    {
                                        win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
                    }
                    {
                                        win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
                    }
@@ -1961,7 +2018,7 @@ void wxWindow::MacUpdate( EventRecord *ev )
             GetPortVisibleRegion( GetWindowPort( window ), region );
 
                        // if windowshade gives incompatibility , take the follwing out
             GetPortVisibleRegion( GetWindowPort( window ), region );
 
                        // if windowshade gives incompatibility , take the follwing out
-            if ( !EmptyRgn( region ) )
+            if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
             {
                                MacRedraw( region , ev->when ) ;
             }
             {
                                MacRedraw( region , ev->when ) ;
             }