]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/window.cpp
added generic color dialog to setup
[wxWidgets.git] / src / mac / window.cpp
index 382b71024f1d48411f461dc841eba2c322d464b7..62f65318ea5e38ce450fa140d9805abe153bafbc 100644 (file)
@@ -108,11 +108,15 @@ void wxRemoveMacWindowAssociation(wxWindow *win)
 // constructors and such
 // ----------------------------------------------------------------------------
 
 // constructors and such
 // ----------------------------------------------------------------------------
 
+WindowRef wxWindow::s_macWindowInUpdate = NULL;
+
 void wxWindow::Init()
 {
     // generic
     InitBase();
 
 void wxWindow::Init()
 {
     // generic
     InitBase();
 
+    m_macEraseOnRedraw = true ;
+
     // MSW specific
     m_doubleClickAllowed = 0;
     m_winCaptured = FALSE;
     // MSW specific
     m_doubleClickAllowed = 0;
     m_winCaptured = FALSE;
@@ -130,6 +134,7 @@ void wxWindow::Init()
     m_isShown = TRUE;
 
        m_macWindowData = NULL ;
     m_isShown = TRUE;
 
        m_macWindowData = NULL ;
+       m_macEraseOnRedraw = true ;
 
        m_x = 0;
        m_y = 0 ;       
 
        m_x = 0;
        m_y = 0 ;       
@@ -147,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 )
@@ -277,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 ;
@@ -408,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"));
@@ -427,7 +459,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor)
   {
        if ( mouseWin == this && !wxIsBusy() )
        {
   {
        if ( mouseWin == this && !wxIsBusy() )
        {
-               cursor.MacInstall() ;
+               m_cursor.MacInstall() ;
        }
   }
 
        }
   }
 
@@ -616,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 ) ;
                        }
                }
@@ -651,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 ) ;
                                }
                        }
@@ -662,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);
        }
        }
 }
        }
        }
 }
@@ -730,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);
          }
@@ -741,8 +776,6 @@ bool wxWindow::Show(bool show)
        }
        MacSuperShown( show ) ;
        Refresh() ;
        }
        MacSuperShown( show ) ;
        Refresh() ;
-       if(m_macWindowData)
-               MacUpdateImmediately() ;
 
     return TRUE;
 }
 
     return TRUE;
 }
@@ -811,6 +844,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
 
 void wxWindow::MacEraseBackground( Rect *rect )
 {
 
 void wxWindow::MacEraseBackground( Rect *rect )
 {
+/*
        WindowRef window = GetMacRootWindow() ;
        if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
        {
        WindowRef window = GetMacRootWindow() ;
        if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
        {
@@ -878,15 +912,19 @@ 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 )
        {
@@ -895,6 +933,10 @@ void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
        }
        InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
        }
        }
        InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
        }
+       if ( !eraseBack )
+               m_macEraseOnRedraw = false ;
+       else
+               m_macEraseOnRedraw = true ;
 }
 
 // Responds to colour changes: passes event on to children.
 }
 
 // Responds to colour changes: passes event on to children.
@@ -1122,6 +1164,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 ) 
@@ -1258,7 +1301,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 ) ;
                                }
                        }
                }
                                }
                        }
                }
@@ -1275,7 +1318,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 ) ;
                                }
                        }
                }
                                }
                        }
                }
@@ -1480,13 +1523,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)
@@ -1673,8 +1722,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 ;
        }
 
@@ -1747,19 +1800,27 @@ 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)
 {
        // updatergn is always already clipped to our boundaries
        WindowRef window = GetMacRootWindow() ;
 }
 
 void wxWindow::MacRedraw( RgnHandle updatergn , long time)
 {
        // updatergn is always already clipped to our boundaries
        WindowRef window = GetMacRootWindow() ;
+       // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
+       RgnHandle ownUpdateRgn = NewRgn() ;
+       CopyRgn( updatergn , ownUpdateRgn ) ;
        wxWindow* win = wxFindWinFromMacWindow( window ) ;
        {
                wxMacDrawingHelper focus( this ) ; // was client
        wxWindow* win = wxFindWinFromMacWindow( window ) ;
        {
                wxMacDrawingHelper focus( this ) ; // was client
@@ -1824,23 +1885,45 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
                        {
                                RGBBackColor( &m_backgroundColour.GetPixel()) ;
                        }
                        {
                                RGBBackColor( &m_backgroundColour.GetPixel()) ;
                        }
+            // subtract all non transparent children from updatergn
+            
+           RgnHandle childarea = NewRgn() ;
+               for (wxNode *node = GetChildren().First(); node; node = node->Next())
+               {
+                       wxWindow *child = (wxWindow*)node->Data();
+                       // eventually test for transparent windows
+                       if ( child->GetMacRootWindow() == window && child->IsShown() )
+                       {
+                           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 ) ;
+                           }
+                       }
+               }               
+               DisposeRgn( childarea ) ;
+
                        if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
                                eraseBackground = true ;
                        if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
                                eraseBackground = true ;
-                       SetClip( updatergn ) ;
-                       if ( eraseBackground )
-                       {
-                               EraseRgn( updatergn ) ; 
-                       }
+                       SetClip( ownUpdateRgn ) ;
+                       if ( m_macEraseOnRedraw ) {
+                       if ( eraseBackground  )
+                       {
+                               EraseRgn( ownUpdateRgn ) ;      
+                       }
+               }
+               else {
+                   m_macEraseOnRedraw = true ;
+               }
                }
 
                }
 
-               m_macUpdateRgn = updatergn ;
                {
                        RgnHandle newupdate = NewRgn() ;
                        wxSize point = GetClientSize() ;
                        wxPoint origin = GetClientAreaOrigin() ;
 
                        SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
                {
                        RgnHandle newupdate = NewRgn() ;
                        wxSize point = GetClientSize() ;
                        wxPoint origin = GetClientAreaOrigin() ;
 
                        SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
-                       SectRgn( newupdate , m_macUpdateRgn , newupdate ) ;
+                       SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
                        OffsetRgn( newupdate , -origin.x , -origin.y ) ;
                        m_updateRegion = newupdate ;
                        DisposeRgn( newupdate ) ;
                        OffsetRgn( newupdate , -origin.x , -origin.y ) ;
                        m_updateRegion = newupdate ;
                        DisposeRgn( newupdate ) ;
@@ -1860,7 +1943,7 @@ void wxWindow::MacRedraw( RgnHandle updatergn , long time)
        {
                wxWindow *child = (wxWindow*)node->Data();
                SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;
        {
                wxWindow *child = (wxWindow*)node->Data();
                SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width ,  child->m_y + child->m_height ) ;
-               SectRgn( childupdate , m_macUpdateRgn , childupdate ) ;
+               SectRgn( childupdate , updatergn , childupdate ) ;
                OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
                if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
                {
                OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
                if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
                {
@@ -1894,7 +1977,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 ) ;
                    }
@@ -1925,7 +2008,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 ) ;
             }
@@ -2310,37 +2393,7 @@ long wxWindow::MacRemoveBordersFromStyle( long style )
 {
        return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
 }
 {
        return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
 }
-/*
-wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) 
-{
-       m_ok = false ;
-       Point localOrigin ;
-       Rect clipRect ;
-       WindowRef window ;
-       wxWindow *rootwin ;
-       m_currentPort = NULL ;
-       GetPort( &m_formerPort ) ;
-       if ( theWindow )
-       {
-       
-               theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
-               m_currentPort = UMAGetWindowPort( window ) ;
-               theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; 
-               m_ok = true ;
-       }
-}
-       
-wxMacFocusHelper::~wxMacFocusHelper() 
-{
-       if ( m_ok )
-       {
-               SetPort( m_currentPort ) ;
-               SetOrigin( 0 , 0 ) ;
-       }
-       if ( m_formerPort != m_currentPort )
-               SetPort( m_formerPort ) ;
-}
-*/
+
 
 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) 
 {
 
 wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) 
 {
@@ -2374,7 +2427,6 @@ wxMacDrawingHelper::~wxMacDrawingHelper()
                Rect portRect ;
                GetPortBounds( m_currentPort , &portRect ) ;
                ClipRect( &portRect ) ;
                Rect portRect ;
                GetPortBounds( m_currentPort , &portRect ) ;
                ClipRect( &portRect ) ;
-               wxDC::MacInvalidateSetup() ;    
        }
                
        if ( m_formerPort != m_currentPort )
        }
                
        if ( m_formerPort != m_currentPort )