]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/window.cpp
invalidate m_selection in DoRemovePage(), not in DeletePage() (replaces patch 998984)
[wxWidgets.git] / src / mac / carbon / window.cpp
index b793d62377058ddea8d0c845d065b76e74e53147..04eeaf07b07c2cd4fe13dd66cd34834474e21580 100644 (file)
@@ -82,8 +82,6 @@ BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
     EVT_NC_PAINT(wxWindowMac::OnNcPaint)
     EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
 // TODO    EVT_PAINT(wxWindowMac::OnPaint)
-    EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
-    EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
     EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
     EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
     EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
@@ -151,13 +149,21 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
         case kEventControlDraw :
             {
                 RgnHandle updateRgn = NULL ;
-
+                RgnHandle allocatedRgn = NULL ;
                 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
                 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr ) 
                 {
                     updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
                 }
-                // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
+                else
+                {
+                    if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
+                    {
+                        allocatedRgn = NewRgn() ;
+                        CopyRgn( updateRgn , allocatedRgn ) ;
+                        OffsetRgn( updateRgn , thisWindow->MacGetLeftBorderSize() , thisWindow->MacGetTopBorderSize() ) ;
+                    }
+                }
 
 #if 0 
               // in case we would need a coregraphics compliant background erase first
@@ -184,6 +190,8 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl
 #endif
                 if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
                     result = noErr ;
+                if ( allocatedRgn )
+                    DisposeRgn( allocatedRgn ) ;
             }
             break ;
         case kEventControlVisibilityChanged :
@@ -505,14 +513,10 @@ pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessa
                 wxWindow*  wx = (wxWindow*) wxFindControlFromMacControl( iControl ) ;
                 if ( wx != NULL )
                 {
-                    /*
                     const wxBrush &brush = wx->MacGetBackgroundBrush() ;
                     if  ( brush.Ok() )
                     {
-                        
                         wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
-                        */
-                        // this clipping is only needed for non HIView
                         
                         RgnHandle clip = NewRgn() ;
                         int x = 0 , y = 0;
@@ -524,7 +528,6 @@ pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessa
                         DisposeRgn( clip ) ;
 
                         status = noErr ;
-                        /*
                     }
                     else if ( wx->MacIsUserPane() )
                     {
@@ -532,7 +535,6 @@ pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessa
                         // setup of our parent ourselves
                         status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
                     }
-                    */
                 }
             }
             break ;
@@ -781,7 +783,7 @@ void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
 #if !TARGET_API_MAC_OSX
     // eventually we can fix some clipping issues be reactivating this hook 
     //if ( m_macIsUserPane )
-    // SetControlColorProc( *m_peer , wxMacSetupControlBackgroundUPP ) ;
+    // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
 #endif
     m_peer->SetTitle( wxStripMenuCodes(m_label) ) ;
 
@@ -895,11 +897,14 @@ bool wxWindowMac::SetBackgroundColour(const wxColour& col )
     }
     MacSetBackgroundBrush( brush ) ;
         
-    MacUpdateControlFont() ;
-    
     return true ;
 }
 
+void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
+{
+    m_macBackgroundBrush = brush ;
+    m_peer->SetBackground( brush ) ;
+}
 
 bool wxWindowMac::MacCanFocus() const
 {
@@ -997,6 +1002,9 @@ void wxWindowMac::DragAcceptFiles(bool accept)
     // TODO
 }
 
+// Returns the size of the native control. In the case of the toplevel window
+// this is the content area root control
+
 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
                                            int& w, int& h) const 
 {
@@ -1019,6 +1027,8 @@ void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
     }
 }
 
+// From a wx position / size calculate the appropriate size of the native control
 bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
                                        const wxSize& size,
                                        int& x, int& y,
@@ -1200,8 +1210,8 @@ void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
     {
         Rect bounds ;
         m_peer->GetRect( &bounds ) ;   
-        if(x)   *x += bounds.left ;
-        if(y)   *y += bounds.top ;
+        if(x)   *x += bounds.left - MacGetLeftBorderSize() ;
+        if(y)   *y += bounds.top - MacGetTopBorderSize() ;
     }
 #endif
 }
@@ -1237,8 +1247,8 @@ void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
     {
         Rect bounds ;
         m_peer->GetRect( &bounds ) ;   
-        if(x)   *x -= bounds.left ;
-        if(y)   *y -= bounds.top ;
+        if(x)   *x -= bounds.left + MacGetLeftBorderSize() ;
+        if(y)   *y -= bounds.top + MacGetTopBorderSize() ;
     }
 #endif
 }
@@ -1333,10 +1343,10 @@ void wxWindowMac::DoGetClientSize(int *x, int *y) const
 #endif 
     ww = content.right - content.left ;
     hh = content.bottom - content.top ;
-    
+    /*
     ww -= MacGetLeftBorderSize(  )  + MacGetRightBorderSize(  ) ;
     hh -= MacGetTopBorderSize(  ) + MacGetBottomBorderSize( );
-
+    */
     if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar  && m_hScrollBar->IsShown()) )
     {
         int x1 = 0 ;
@@ -1825,8 +1835,9 @@ bool wxWindowMac::MacIsReallyShown()
 {
     // only under OSX the visibility of the TLW is taken into account
 #if TARGET_API_MAC_OSX
-    return m_peer->IsVisible();
-#else
+    if ( m_peer && m_peer->Ok() )
+        return m_peer->IsVisible();
+#endif
     wxWindow* win = this ;
     while( win->IsShown()  )
     {
@@ -1839,7 +1850,6 @@ bool wxWindowMac::MacIsReallyShown()
             
     } ;
     return false ;
-#endif
 }
 
 bool wxWindowMac::MacIsReallyEnabled() 
@@ -1902,6 +1912,9 @@ void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
 
 void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
 {
+    if ( m_peer == NULL )
+        return ;
+        
 #if TARGET_API_MAC_OSX
     if ( rect == NULL )
         m_peer->SetNeedsDisplay( true ) ; 
@@ -2040,11 +2053,13 @@ void wxWindowMac::WarpPointer (int x_pos, int y_pos)
 
 void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
 {
+#if TARGET_API_MAC_OSX
     if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
     {
         event.Skip() ;
     }
     else
+#endif
         event.GetDC()->Clear() ;
 }
 
@@ -2125,9 +2140,6 @@ void wxWindowMac::MacPaintBorders( int left , int top )
     int major,minor;
     wxGetOsVersion( &major, &minor );
 
-    RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
-    RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
-    
     RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
     RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
     // OS X has lighter border edges than classic:
@@ -2154,6 +2166,9 @@ void wxWindowMac::MacPaintBorders( int left , int top )
         InsetRect( &rect , border , border );
         DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
 #else
+        RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
+        RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
+    
         bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
         RGBForeColor( &face );
         MoveTo( left + 0 , top + h - 2 );
@@ -2388,8 +2403,6 @@ void wxWindowMac::OnSetFocus(wxFocusEvent& event)
     if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
     {
         wxMacWindowStateSaver sv( this ) ;
-//        wxWindowDC dc(this) ;
-//        wxMacPortSetter helper(&dc) ;
 
         int w , h ;
         int x , y ;
@@ -2703,6 +2716,8 @@ void wxWindowMac::MacCreateScrollBars( long style )
 {
     wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
 
+#if 0
+
     bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
     int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
     int width, height ;
@@ -2733,6 +2748,34 @@ void wxWindowMac::MacCreateScrollBars( long style )
     {
         m_hScrollBar->Show(false) ;
     }
+#else  
+    if ( style & ( wxVSCROLL | wxHSCROLL ) )
+    {
+        bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
+        int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
+        int width, height ;
+        GetClientSize( &width , &height ) ;
+
+        wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
+        wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
+        wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
+        wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
+
+
+        if ( style & wxVSCROLL )
+        {
+            m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
+                vSize , wxVERTICAL);
+        }
+
+        if ( style  & wxHSCROLL )
+        {
+            m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
+                hSize , wxHORIZONTAL);
+        }
+    }
+#endif
+
 
     // because the create does not take into account the client area origin
     MacRepositionScrollBars() ; // we might have a real position shift
@@ -2740,6 +2783,9 @@ void wxWindowMac::MacCreateScrollBars( long style )
 
 void wxWindowMac::MacRepositionScrollBars()
 {
+    if ( !m_hScrollBar && !m_vScrollBar )
+        return ;
+    
     bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
     int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
 
@@ -2852,17 +2898,11 @@ long wxWindowMac::MacGetLeftBorderSize( ) const
     if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
     {
         SInt32 border = 3 ;
-#if 0 // wxMAC_USE_THEME_BORDER
-          GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
-#endif
           return border ;
     }
     else if (  m_windowStyle &wxDOUBLE_BORDER)
     {
           SInt32 border = 3 ;
-#if 0 // wxMAC_USE_THEME_BORDER
-          GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
-#endif
           return border ;
     }
     else if (m_windowStyle &wxSIMPLE_BORDER)
@@ -2892,7 +2932,7 @@ long wxWindowMac::MacGetBottomBorderSize( ) const
 
 long wxWindowMac::MacRemoveBordersFromStyle( long style )
 {
-    return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
+    return style & ~wxBORDER_MASK ;
 }
 
 // Find the wxWindowMac at the current mouse position, returning the mouse