- if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
- {
- Rect structure, content ;
-
- GetRegionBounds( rgn , &content ) ;
- m_peer->GetRect( &structure ) ;
- OffsetRect( &structure, -structure.left , -structure.top ) ;
-
- left = content.left - structure.left ;
- top = content.top - structure.top ;
- right = structure.right - content.right ;
- bottom = structure.bottom - content.bottom ;
- }
- else
- {
- left = top = right = bottom = 0 ;
- }
-
- DisposeRgn( rgn ) ;
-}
-
-wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
-{
- wxSize sizeTotal = size;
-
- RgnHandle rgn = NewRgn() ;
- if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
- {
- Rect content, structure ;
- GetRegionBounds( rgn , &content ) ;
- m_peer->GetRect( &structure ) ;
-
- // structure is in parent coordinates, but we only need width and height, so it's ok
-
- sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
- sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top) ;
- }
-
- DisposeRgn( rgn ) ;
-
- sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
- sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
-
- return sizeTotal;
-}
-
-// Get size *available for subwindows* i.e. excluding menu bar etc.
-void wxWindowMac::DoGetClientSize( int *x, int *y ) const
-{
- int ww, hh;
-
- RgnHandle rgn = NewRgn() ;
- Rect content ;
- if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
- GetRegionBounds( rgn , &content ) ;
- else
- m_peer->GetRect( &content ) ;
- DisposeRgn( rgn ) ;
-
- ww = content.right - content.left ;
- hh = content.bottom - content.top ;
-
- if (m_hScrollBar && m_hScrollBar->IsShown() )
- hh -= m_hScrollBar->GetSize().y ;
-
- if (m_vScrollBar && m_vScrollBar->IsShown() )
- ww -= m_vScrollBar->GetSize().x ;
-
- if (x)
- *x = ww;
- if (y)
- *y = hh;
-}
-
-bool wxWindowMac::SetCursor(const wxCursor& cursor)
-{
- if (m_cursor.IsSameAs(cursor))
- return false;
-
- if (!cursor.IsOk())
- {
- 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"));
-
- wxWindowMac *mouseWin = 0 ;
- {
- wxNonOwnedWindow *tlw = MacGetTopLevelWindow() ;
- WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ;
-
- ControlPartCode part ;
- ControlRef control ;
- Point pt ;
- #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
- HIPoint hiPoint ;
- HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint);
- pt.h = hiPoint.x;
- pt.v = hiPoint.y;
- #else
- GetGlobalMouse( &pt );
- int x = pt.h;
- int y = pt.v;
- ScreenToClient(&x, &y);
- pt.h = x;
- pt.v = y;
-#endif
- control = FindControlUnderMouse( pt , window , &part ) ;
- if ( control )
- mouseWin = wxFindControlFromMacControl( control ) ;
-
- }
-
- if ( mouseWin == this && !wxIsBusy() )
- m_cursor.MacInstall() ;
-
- return true ;
-}
-
-#if wxUSE_MENUS
-bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
-{
-#ifndef __WXUNIVERSAL__
- menu->SetInvokingWindow((wxWindow*)this);
- menu->UpdateUI();
-
- if ( x == wxDefaultCoord && y == wxDefaultCoord )
- {
- wxPoint mouse = wxGetMousePosition();
- x = mouse.x;
- y = mouse.y;
- }
- else
- {
- ClientToScreen( &x , &y ) ;
- }
-
- menu->MacBeforeDisplay( true ) ;
- long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ;
- if ( HiWord(menuResult) != 0 )
- {
- MenuCommand macid;
- GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid );
- int id = wxMacCommandToId( macid );
- wxMenuItem* item = NULL ;
- wxMenu* realmenu ;
- item = menu->FindItem( id, &realmenu ) ;
- if ( item )
- {
- if (item->IsCheckable())
- item->Check( !item->IsChecked() ) ;
-
- menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
- }
- }
-
- menu->MacAfterDisplay( true ) ;
- menu->SetInvokingWindow( NULL );
-
- return true;
-#else
- // actually this shouldn't be called, because universal is having its own implementation
- return false;
-#endif
-}
-#endif
-
-// ----------------------------------------------------------------------------
-// tooltips
-// ----------------------------------------------------------------------------
-
-#if wxUSE_TOOLTIPS
-
-void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
-{
- wxWindowBase::DoSetToolTip(tooltip);
-
- if ( m_tooltip )
- m_tooltip->SetWindow(this);
-}
-
-#endif
-
-void wxWindowMac::MacInvalidateBorders()
-{
- if ( m_peer == NULL )
- return ;
-
- bool vis = IsShownOnScreen() ;
- if ( !vis )
- return ;
-
- int outerBorder = MacGetLeftBorderSize() ;
- if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ )
- outerBorder += 4 ;
-
- if ( outerBorder == 0 )
- return ;
-
- // now we know that we have something to do at all
-
- // as the borders are drawn on the parent we have to properly invalidate all these areas
- RgnHandle updateInner , updateOuter;
- Rect rect ;
-
- // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
- updateInner = NewRgn() ;
- updateOuter = NewRgn() ;
-
- m_peer->GetRect( &rect ) ;
- RectRgn( updateInner, &rect ) ;
- InsetRect( &rect , -outerBorder , -outerBorder ) ;
- RectRgn( updateOuter, &rect ) ;
- DiffRgn( updateOuter, updateInner , updateOuter ) ;
-
- GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ;
-
- DisposeRgn( updateOuter ) ;
- DisposeRgn( updateInner ) ;
-}
-
-void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
-{
- // this is never called for a toplevel window, so we know we have a parent
- int former_x , former_y , former_w, former_h ;
-
- // Get true coordinates of former position
- DoGetPosition( &former_x , &former_y ) ;
- DoGetSize( &former_w , &former_h ) ;
-
- wxWindow *parent = GetParent();
- if ( parent )
- {
- wxPoint pt(parent->GetClientAreaOrigin());
- former_x += pt.x ;
- former_y += pt.y ;
- }
-
- int actualWidth = width ;
- int actualHeight = height ;
- int actualX = x;
- int actualY = y;
-
- if ((m_minWidth != -1) && (actualWidth < m_minWidth))
- actualWidth = m_minWidth;
- if ((m_minHeight != -1) && (actualHeight < m_minHeight))
- actualHeight = m_minHeight;
- if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
- actualWidth = m_maxWidth;
- if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
- actualHeight = m_maxHeight;
-
- bool doMove = false, doResize = false ;
-
- if ( actualX != former_x || actualY != former_y )
- doMove = true ;
-
- if ( actualWidth != former_w || actualHeight != former_h )
- doResize = true ;
-
- if ( doMove || doResize )
- {
- // as the borders are drawn outside the native control, we adjust now
-
- wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
- wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
- actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
-
- Rect r ;
- wxMacRectToNative( &bounds , &r ) ;
-
- if ( !GetParent()->IsTopLevel() )
- wxMacWindowToNative( GetParent() , &r ) ;
-
- MacInvalidateBorders() ;
-
- m_cachedClippedRectValid = false ;
- m_peer->SetRect( &r ) ;
-
- wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
-
- MacInvalidateBorders() ;
-
- MacRepositionScrollBars() ;
- if ( doMove )
- {
- wxPoint point(actualX, actualY);
- wxMoveEvent event(point, m_windowId);
- event.SetEventObject(this);
- HandleWindowEvent(event) ;
- }
-
- if ( doResize )
- {
- MacRepositionScrollBars() ;
- wxSize size(actualWidth, actualHeight);
- wxSizeEvent event(size, m_windowId);
- event.SetEventObject(this);
- HandleWindowEvent(event);
- }
- }
-}
-
-wxSize wxWindowMac::DoGetBestSize() const
-{
- if ( m_macIsUserPane || IsTopLevel() )
- {
- return wxWindowBase::DoGetBestSize() ;
- }
- else
- {
- Rect bestsize = { 0 , 0 , 0 , 0 } ;
- int bestWidth, bestHeight ;
-
- m_peer->GetBestRect( &bestsize ) ;
- if ( EmptyRect( &bestsize ) )
- {
- bestsize.left =
- bestsize.top = 0 ;
- bestsize.right =
- bestsize.bottom = 16 ;
-
- if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
- {
- bestsize.bottom = 16 ;
- }
- #if wxUSE_SPINBTN
- else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
- {
- bestsize.bottom = 24 ;
- }
- #endif
- else
- {
- // return wxWindowBase::DoGetBestSize() ;
- }
- }
-
- bestWidth = bestsize.right - bestsize.left + MacGetLeftBorderSize() +
- MacGetRightBorderSize();
- bestHeight = bestsize.bottom - bestsize.top + MacGetTopBorderSize() +
- MacGetBottomBorderSize();
- if ( bestHeight < 10 )
- bestHeight = 13 ;
-
- return wxSize(bestWidth, bestHeight);
- }
-}
-
-// set the size of the window: if the dimensions are positive, just use them,
-// but if any of them is equal to -1, it means that we must find the value for
-// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
-// which case -1 is a valid value for x and y)
-//
-// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
-// the width/height to best suit our contents, otherwise we reuse the current
-// width/height
-void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
-{
- // get the current size and position...
- int currentX, currentY;
- int currentW, currentH;
-
- GetPosition(¤tX, ¤tY);
- GetSize(¤tW, ¤tH);
-
- // ... and don't do anything (avoiding flicker) if it's already ok
- if ( x == currentX && y == currentY &&
- width == currentW && height == currentH && ( height != -1 && width != -1 ) )
- {
- // TODO: REMOVE
- MacRepositionScrollBars() ; // we might have a real position shift
-
- return;
- }
-
- if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
- {
- if ( x == wxDefaultCoord )
- x = currentX;
- if ( y == wxDefaultCoord )
- y = currentY;
- }
-
- AdjustForParentClientOrigin( x, y, sizeFlags );
-
- wxSize size = wxDefaultSize;
- if ( width == wxDefaultCoord )
- {
- if ( sizeFlags & wxSIZE_AUTO_WIDTH )
- {
- size = DoGetBestSize();
- width = size.x;
- }
- else
- {
- // just take the current one
- width = currentW;
- }
- }
-
- if ( height == wxDefaultCoord )
- {
- if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
- {
- if ( size.x == wxDefaultCoord )
- size = DoGetBestSize();
- // else: already called DoGetBestSize() above
-
- height = size.y;
- }
- else
- {
- // just take the current one
- height = currentH;
- }
- }
-
- DoMoveWindow( x, y, width, height );
-}
-
-wxPoint wxWindowMac::GetClientAreaOrigin() const
-{
- RgnHandle rgn = NewRgn() ;
- Rect content ;
- if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
- {
- GetRegionBounds( rgn , &content ) ;
- }
- else
- {
- content.left =
- content.top = 0 ;
- }
-
- DisposeRgn( rgn ) ;
-
- return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() );
-}
-
-void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
-{
- if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord )
- {
- int currentclientwidth , currentclientheight ;
- int currentwidth , currentheight ;
-
- GetClientSize( ¤tclientwidth , ¤tclientheight ) ;
- GetSize( ¤twidth , ¤theight ) ;
-
- DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
- currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
- }
-}
-
-void wxWindowMac::SetLabel(const wxString& title)
-{
- m_label = title ;
-
- if ( m_peer && m_peer->Ok() )
- m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ;
-
- // do not trigger refreshes upon invisible and possible partly created objects
- if ( IsShownOnScreen() )
- Refresh() ;
-}
-
-wxString wxWindowMac::GetLabel() const
-{
- return m_label ;
-}
-
-bool wxWindowMac::Show(bool show)
-{
- if ( !wxWindowBase::Show(show) )
- return false;
-
- if ( m_peer )
- m_peer->SetVisibility( show , true ) ;
-
- return true;
-}
-
-void wxWindowMac::DoEnable(bool enable)
-{
- m_peer->Enable( enable ) ;
-}
-
-//
-// status change notifications
-//
-
-void wxWindowMac::MacVisibilityChanged()
-{
-}
-
-void wxWindowMac::MacHiliteChanged()
-{
-}
-
-void wxWindowMac::MacEnabledStateChanged()
-{
- OnEnabled( m_peer->IsEnabled() );
-}
-
-//
-// status queries on the inherited window's state
-//
-
-bool wxWindowMac::MacIsReallyEnabled()
-{
- return m_peer->IsEnabled() ;
-}
-
-bool wxWindowMac::MacIsReallyHilited()
-{
- return m_peer->IsActive();
-}
-
-void wxWindowMac::MacFlashInvalidAreas()
-{
-#if TARGET_API_MAC_OSX
- HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
-#endif
-}
-
-int wxWindowMac::GetCharHeight() const
-{
- wxClientDC dc( (wxWindowMac*)this ) ;
-
- return dc.GetCharHeight() ;
-}
-
-int wxWindowMac::GetCharWidth() const
-{
- wxClientDC dc( (wxWindowMac*)this ) ;
-
- return dc.GetCharWidth() ;
-}
-
-void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
- int *descent, int *externalLeading, const wxFont *theFont ) const
-{
- const wxFont *fontToUse = theFont;
- wxFont tempFont;
- if ( !fontToUse )
- {
- tempFont = GetFont();
- fontToUse = &tempFont;
- }
-
- wxClientDC dc( (wxWindowMac*) this ) ;
- wxCoord lx,ly,ld,le ;
- dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
- if ( externalLeading )
- *externalLeading = le ;
- if ( descent )
- *descent = ld ;
- if ( x )
- *x = lx ;
- if ( y )
- *y = ly ;
-}
-
-/*
- * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
- * we always intersect with the entire window, not only with the client area
- */
-
-void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect)
-{
- if ( m_peer == NULL )
- return ;
-
- if ( !IsShownOnScreen() )
- return ;
-
- if ( rect )
- {
- Rect r ;
-
- wxMacRectToNative( rect , &r ) ;
- m_peer->SetNeedsDisplay( &r ) ;
- }
- else
- {
- m_peer->SetNeedsDisplay() ;
- }
-}
-
-void wxWindowMac::DoFreeze()
-{
-#if TARGET_API_MAC_OSX
- if ( m_peer && m_peer->Ok() )
- m_peer->SetDrawingEnabled( false ) ;
-#endif
-}
-
-void wxWindowMac::DoThaw()
-{
-#if TARGET_API_MAC_OSX
- if ( m_peer && m_peer->Ok() )
- {
- m_peer->SetDrawingEnabled( true ) ;
- m_peer->InvalidateWithChildren() ;
- }
-#endif
-}
-
-wxWindowMac *wxGetActiveWindow()
-{
- // actually this is a windows-only concept
- return NULL;
-}
-
-// Coordinates relative to the window
-void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos))
-{
- // We really don't move the mouse programmatically under Mac.
-}
-
-void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
-{
- if ( MacGetTopLevelWindow() == NULL )
- return ;
-/*
-#if TARGET_API_MAC_OSX
- if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
- {
- }
- else
-#endif
-*/
- if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR )
- {
- event.GetDC()->Clear() ;
- }
- else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM )
- {
- // don't skip the event here, custom background means that the app
- // is drawing it itself in its OnPaint(), so don't draw it at all
- // now to avoid flicker
- }
- else
- {
- event.Skip() ;
- }
-}
-
-void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
-{
- event.Skip() ;
-}
-
-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 WXUNUSED(refresh))
-{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- m_hScrollBar->SetThumbPosition( pos ) ;
- }
- else
- {
- if ( m_vScrollBar )
- m_vScrollBar->SetThumbPosition( pos ) ;
- }
-}
-
-void
-wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag)
-{
- bool needVisibilityUpdate = false;
-
- if ( m_hScrollBarAlwaysShown != hflag )
- {
- m_hScrollBarAlwaysShown = hflag;
- needVisibilityUpdate = true;
- }
-
- if ( m_vScrollBarAlwaysShown != vflag )
- {
- m_vScrollBarAlwaysShown = vflag;
- needVisibilityUpdate = true;
- }
-
- if ( needVisibilityUpdate )
- DoUpdateScrollbarVisibility();
-}
-
-//
-// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
-// our own window origin is at leftOrigin/rightOrigin
-//
-
-void wxWindowMac::MacPaintGrowBox()
-{
- if ( IsTopLevel() )
- return ;
-
- if ( MacHasScrollBarCorner() )
- {
- Rect rect ;
-
- CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
- wxASSERT( cgContext ) ;
-
- m_peer->GetRect( &rect ) ;
-
- int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
- CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
- CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
- CGContextSaveGState( cgContext );
-
- if ( m_backgroundColour.Ok() )
- {
- CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() );
- }
- else
- {
- CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 );
- }
- CGContextFillRect( cgContext, cgrect );
- CGContextRestoreGState( cgContext );
- }
-}
-
-void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
-{
- if ( IsTopLevel() )
- return ;
-
- Rect rect ;
- bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
-
- // back to the surrounding frame rectangle
- m_peer->GetRect( &rect ) ;
- InsetRect( &rect, -1 , -1 ) ;
-
- {
- CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
- rect.bottom - rect.top ) ;
-
- HIThemeFrameDrawInfo info ;
- memset( &info, 0 , sizeof(info) ) ;
-
- info.version = 0 ;
- info.kind = 0 ;
- info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
- info.isFocused = hasFocus ;
-
- CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
- wxASSERT( cgContext ) ;
-
- if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
- {
- info.kind = kHIThemeFrameTextFieldSquare ;
- HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
- }
- else if ( HasFlag(wxSIMPLE_BORDER) )
- {
- info.kind = kHIThemeFrameListBox ;
- HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
- }
- else if ( hasFocus )
- {
- HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
- }
-#if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
- m_peer->GetRect( &rect ) ;
- if ( MacHasScrollBarCorner() )
- {
- int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant();
- int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
- CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
- CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
- HIThemeGrowBoxDrawInfo info ;
- memset( &info, 0, sizeof(info) ) ;
- info.version = 0 ;
- info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
- info.kind = kHIThemeGrowBoxKindNone ;
- // contrary to the docs ...SizeSmall does not work
- info.size = kHIThemeGrowBoxSizeNormal ;
- info.direction = 0 ;
- HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
- }
-#endif
- }
-}
-
-void wxWindowMac::RemoveChild( wxWindowBase *child )
-{
- if ( child == m_hScrollBar )
- m_hScrollBar = NULL ;
- if ( child == m_vScrollBar )
- m_vScrollBar = NULL ;
-
- wxWindowBase::RemoveChild( child ) ;
-}
-
-void wxWindowMac::DoUpdateScrollbarVisibility()
-{
- bool triggerSizeEvent = false;
-
- if ( m_hScrollBar )
- {
- bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded();
-
- if ( m_hScrollBar->IsShown() != showHScrollBar )
- {
- m_hScrollBar->Show( showHScrollBar );
- triggerSizeEvent = true;
- }
- }
-
- if ( m_vScrollBar)
- {
- bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded();
-
- if ( m_vScrollBar->IsShown() != showVScrollBar )
- {
- m_vScrollBar->Show( showVScrollBar ) ;
- triggerSizeEvent = true;
- }
- }
-
- MacRepositionScrollBars() ;
- if ( triggerSizeEvent )
- {
- wxSizeEvent event(GetSize(), m_windowId);
- event.SetEventObject(this);
- HandleWindowEvent(event);
- }
-}
-
-// New function that will replace some of the above.
-void wxWindowMac::SetScrollbar(int orient, int pos, int thumb,
- int range, bool refresh)
-{
- if ( orient == wxHORIZONTAL && m_hScrollBar )
- m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
- else if ( orient == wxVERTICAL && m_vScrollBar )
- m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
-
- DoUpdateScrollbarVisibility();
-}
-
-// Does a physical scroll
-void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
-{
- if ( dx == 0 && dy == 0 )
- return ;
-
- int width , height ;
- GetClientSize( &width , &height ) ;
-
- {
- // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
- // area is scrolled, this does not occur if width and height are 2 pixels less,
- // TODO: write optimal workaround
- wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
- if ( rect )
- scrollrect.Intersect( *rect ) ;
-
- if ( m_peer->GetNeedsDisplay() )
- {
- // because HIViewScrollRect does not scroll the already invalidated area we have two options:
- // in case there is already a pending redraw on that area
- // either immediate redraw or full invalidate
-#if 1
- // is the better overall solution, as it does not slow down scrolling
- m_peer->SetNeedsDisplay() ;
-#else
- // this would be the preferred version for fast drawing controls
- HIViewRender(m_peer->GetControlRef()) ;
-#endif
- }
-
- // as the native control might be not a 0/0 wx window coordinates, we have to offset
- scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
- m_peer->ScrollRect( &scrollrect , dx , dy ) ;
-
-#if 0
- // this would be the preferred version for fast drawing controls
- HIViewRender(m_peer->GetControlRef()) ;
-#endif
- }
-
- wxWindowMac *child;
- int x, y, w, h;
- for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
- {
- child = node->GetData();
- if (child == NULL)
- continue;
- if (child == m_vScrollBar)
- continue;
- if (child == m_hScrollBar)
- continue;
- if (child->IsTopLevel())
- continue;
-
- child->GetPosition( &x, &y );
- child->GetSize( &w, &h );
- if (rect)
- {
- wxRect rc( x, y, w, h );
- if (rect->Intersects( rc ))
- child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
- }
- else
- {
- child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
- }
- }
-}
-
-void wxWindowMac::MacOnScroll( wxScrollEvent &event )
-{
- if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
- {
- wxScrollWinEvent wevent;
- wevent.SetPosition(event.GetPosition());
- wevent.SetOrientation(event.GetOrientation());
- wevent.SetEventObject(this);
-
- if (event.GetEventType() == wxEVT_SCROLL_TOP)
- wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
- else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
- wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
- else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
- wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
- else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
- wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
- else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
- wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
- else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
- wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
- else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
- wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
- else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
- wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
-
- HandleWindowEvent(wevent);
- }
-}
-
-// Get the window with the focus
-wxWindowMac *wxWindowBase::DoFindFocus()
-{
- ControlRef control ;
- GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
- return wxFindControlFromMacControl( control ) ;
-}
-
-void wxWindowMac::OnInternalIdle()