+ if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
+ {
+#if TARGET_API_MAC_CARBON
+ Update() ;
+#else
+ wxClientDC dc(this) ;
+ wxMacPortSetter helper(&dc) ;
+ wxMacWindowClipper clipper(this) ;
+ wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
+ UMADrawControl( (ControlRef) m_macControl ) ;
+#endif
+ }
+*/
+}
+
+/* TODO
+void wxWindowMac::OnPaint(wxPaintEvent& event)
+{
+ // why don't we skip that here ?
+}
+*/
+
+wxWindowMac *wxGetActiveWindow()
+{
+ // actually this is a windows-only concept
+ return NULL;
+}
+
+// Coordinates relative to the window
+void wxWindowMac::WarpPointer (int x_pos, int y_pos)
+{
+ // We really don't move the mouse programmatically under Mac.
+}
+
+void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
+{
+ if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
+ {
+ event.Skip() ;
+ }
+ else
+ event.GetDC()->Clear() ;
+}
+
+void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
+{
+ wxWindowDC dc(this) ;
+ wxMacPortSetter helper(&dc) ;
+
+ MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
+}
+
+int wxWindowMac::GetScrollPos(int orient) const
+{
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ return m_hScrollBar->GetThumbPosition() ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ return m_vScrollBar->GetThumbPosition() ;
+ }
+ return 0;
+}
+
+// This now returns the whole range, not just the number
+// of positions that we can scroll.
+int wxWindowMac::GetScrollRange(int orient) const
+{
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ return m_hScrollBar->GetRange() ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ return m_vScrollBar->GetRange() ;
+ }
+ return 0;
+}
+
+int wxWindowMac::GetScrollThumb(int orient) const
+{
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ return m_hScrollBar->GetThumbSize() ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ return m_vScrollBar->GetThumbSize() ;
+ }
+ return 0;
+}
+
+void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
+{
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ m_hScrollBar->SetThumbPosition( pos ) ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ m_vScrollBar->SetThumbPosition( pos ) ;
+ }
+}
+
+void wxWindowMac::MacPaintBorders( int left , int top )
+{
+ if( IsTopLevel() )
+ return ;
+
+ 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:
+ if (major >= 10)
+ {
+ darkShadow.red = 0x8E8E;
+ darkShadow.green = 0x8E8E;
+ darkShadow.blue = 0x8E8E;
+ lightShadow.red = 0xBDBD;
+ lightShadow.green = 0xBDBD;
+ lightShadow.blue = 0xBDBD;
+ }
+
+ PenNormal() ;
+
+ int w , h ;
+ GetSize( &w , &h ) ;
+ if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
+ {
+#if wxMAC_USE_THEME_BORDER
+ Rect rect = { top , left , m_height + top , m_width + left } ;
+ SInt32 border = 0 ;
+ /*
+ GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
+ InsetRect( &rect , border , border );
+ DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+ */
+
+ DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+#else
+ bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
+ RGBForeColor( &face );
+ MoveTo( left + 0 , top + h - 2 );
+ LineTo( left + 0 , top + 0 );
+ LineTo( left + w - 2 , top + 0 );
+
+ MoveTo( left + 2 , top + h - 3 );
+ LineTo( left + w - 3 , top + h - 3 );
+ LineTo( left + w - 3 , top + 2 );
+
+ RGBForeColor( sunken ? &face : &darkShadow );
+ MoveTo( left + 0 , top + h - 1 );
+ LineTo( left + w - 1 , top + h - 1 );
+ LineTo( left + w - 1 , top + 0 );
+
+ RGBForeColor( sunken ? &lightShadow : &white );
+ MoveTo( left + 1 , top + h - 3 );
+ LineTo( left + 1, top + 1 );
+ LineTo( left + w - 3 , top + 1 );
+
+ RGBForeColor( sunken ? &white : &lightShadow );
+ MoveTo( left + 1 , top + h - 2 );
+ LineTo( left + w - 2 , top + h - 2 );
+ LineTo( left + w - 2 , top + 1 );
+
+ RGBForeColor( sunken ? &darkShadow : &face );
+ MoveTo( left + 2 , top + h - 4 );
+ LineTo( left + 2 , top + 2 );
+ LineTo( left + w - 4 , top + 2 );
+#endif
+ }
+ else if (HasFlag(wxSIMPLE_BORDER))
+ {
+ Rect rect = { top , left , h + top , w + left } ;
+ RGBForeColor( &darkShadow ) ;
+ FrameRect( &rect ) ;
+ }
+}
+
+void wxWindowMac::RemoveChild( wxWindowBase *child )
+{
+ if ( child == m_hScrollBar )
+ m_hScrollBar = NULL ;
+ if ( child == m_vScrollBar )
+ m_vScrollBar = NULL ;
+
+ wxWindowBase::RemoveChild( child ) ;
+}
+
+// New function that will replace some of the above.
+void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
+ int range, bool refresh)
+{
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ {
+ if ( range == 0 || thumbVisible >= range )
+ {
+ if ( m_hScrollBar->IsShown() )
+ m_hScrollBar->Show(false) ;
+ }
+ else
+ {
+ if ( !m_hScrollBar->IsShown() )
+ m_hScrollBar->Show(true) ;
+ m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
+ }
+ }
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ {
+ if ( range == 0 || thumbVisible >= range )
+ {
+ if ( m_vScrollBar->IsShown() )
+ m_vScrollBar->Show(false) ;
+ }
+ else
+ {
+ if ( !m_vScrollBar->IsShown() )
+ m_vScrollBar->Show(true) ;
+ m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
+ }
+ }
+ }
+ MacRepositionScrollBars() ;
+}
+
+// Does a physical scroll
+void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
+{
+ if( dx == 0 && dy ==0 )
+ return ;
+
+
+ {
+ wxClientDC dc(this) ;
+ wxMacPortSetter helper(&dc) ;
+
+ int width , height ;
+ GetClientSize( &width , &height ) ;
+
+
+ wxPoint pos;
+ pos.x = pos.y = 0;
+
+ Rect scrollrect;
+ // TODO take out the boundaries
+ GetControlBounds( (ControlRef) m_macControl, &scrollrect);
+
+ RgnHandle updateRgn = NewRgn() ;
+ if ( rect )
+ {
+ Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
+ dc.XLOG2DEVMAC(rect->x + rect->width) } ;
+ SectRect( &scrollrect , &r , &scrollrect ) ;
+ }
+ ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
+#if TARGET_CARBON
+ //KO: The docs say ScrollRect creates an update region, which thus calls an update event
+ // but it seems the update only refreshes the background of the control, rather than calling
+ // kEventControlDraw, so we need to force a proper update here. There has to be a better
+ // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
+ Update();
+#endif
+ // we also have to scroll the update rgn in this rectangle
+ // in order not to loose updates
+#if !TARGET_CARBON
+ WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
+ RgnHandle formerUpdateRgn = NewRgn() ;
+ RgnHandle scrollRgn = NewRgn() ;
+ RectRgn( scrollRgn , &scrollrect ) ;
+ GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
+ Point pt = {0,0} ;
+ LocalToGlobal( &pt ) ;
+ OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
+ SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
+ if ( !EmptyRgn( formerUpdateRgn ) )
+ {
+ MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
+ SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
+ InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
+ }
+ InvalWindowRgn(rootWindow , updateRgn ) ;
+ DisposeRgn( updateRgn ) ;
+ DisposeRgn( formerUpdateRgn ) ;
+ DisposeRgn( scrollRgn ) ;
+#endif
+ }
+
+ for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
+ {
+ wxWindowMac *child = 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;
+ child->GetSize( &w, &h );
+ if (rect)
+ {
+ wxRect rc(x,y,w,h);
+ if (rect->Intersects(rc))
+ child->SetSize( x+dx, y+dy, w, h );
+ }
+ else
+ {
+ child->SetSize( x+dx, y+dy, w, h );
+ }
+ }
+
+// TODO remove, was moved higher up Update() ;