1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
71 #include <Carbon/Carbon.h>
74 #define MAC_SCROLLBAR_SIZE 15
75 #define MAC_SMALL_SCROLLBAR_SIZE 11
79 #ifdef __WXUNIVERSAL__
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
82 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
85 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
86 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
87 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
88 EVT_PAINT(wxWindowMac::OnPaint
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 // ===========================================================================
99 // ===========================================================================
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 wxWindowMac::wxWindowMac()
110 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
115 const wxString
& name
)
118 Create(parent
, id
, pos
, size
, style
, name
);
121 void wxWindowMac::Init()
125 m_cgContextRef
= NULL
;
127 // as all windows are created with WS_VISIBLE style...
130 m_hScrollBar
= NULL
;
131 m_vScrollBar
= NULL
;
132 m_hScrollBarAlwaysShown
= false;
133 m_vScrollBarAlwaysShown
= false;
135 m_macIsUserPane
= true;
136 m_clipChildren
= false ;
137 m_cachedClippedRectValid
= false ;
140 wxWindowMac::~wxWindowMac()
144 m_isBeingDeleted
= true;
146 MacInvalidateBorders() ;
148 #ifndef __WXUNIVERSAL__
149 // VS: make sure there's no wxFrame with last focus set to us:
150 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
152 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
155 if ( frame
->GetLastFocus() == this )
156 frame
->SetLastFocus((wxWindow
*)NULL
);
162 // destroy children before destroying this window itself
165 // wxRemoveMacControlAssociation( this ) ;
166 // If we delete an item, we should initialize the parent panel,
167 // because it could now be invalid.
168 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
171 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
172 tlw
->SetDefaultItem(NULL
);
175 if ( g_MacLastWindow
== this )
176 g_MacLastWindow
= NULL
;
178 #ifndef __WXUNIVERSAL__
179 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
182 if ( frame
->GetLastFocus() == this )
183 frame
->SetLastFocus( NULL
) ;
187 // delete our drop target if we've got one
188 #if wxUSE_DRAG_AND_DROP
189 if ( m_dropTarget
!= NULL
)
199 WXWidget
wxWindowMac::GetHandle() const
201 return (WXWidget
) m_peer
->GetWXWidget() ;
205 // TODO END move to window_osx.cpp
208 // ---------------------------------------------------------------------------
209 // Utility Routines to move between different coordinate systems
210 // ---------------------------------------------------------------------------
213 * Right now we have the following setup :
214 * a border that is not part of the native control is always outside the
215 * control's border (otherwise we loose all native intelligence, future ways
216 * may be to have a second embedding control responsible for drawing borders
217 * and backgrounds eventually)
218 * so all this border calculations have to be taken into account when calling
219 * native methods or getting native oriented data
220 * so we have three coordinate systems here
221 * wx client coordinates
222 * wx window coordinates (including window frames)
230 bool wxWindowMac::Create(wxWindowMac
*parent
,
235 const wxString
& name
)
237 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
239 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
242 m_windowVariant
= parent
->GetWindowVariant() ;
244 if ( m_macIsUserPane
)
246 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
247 MacPostControlCreate(pos
, size
) ;
250 #ifndef __WXUNIVERSAL__
251 // Don't give scrollbars to wxControls unless they ask for them
252 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
253 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
255 MacCreateScrollBars( style
) ;
259 wxWindowCreateEvent
event((wxWindow
*)this);
260 GetEventHandler()->AddPendingEvent(event
);
265 void wxWindowMac::MacChildAdded()
268 m_vScrollBar
->Raise() ;
270 m_hScrollBar
->Raise() ;
273 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
275 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
277 GetParent()->AddChild( this );
279 m_peer
->InstallEventHandler();
280 m_peer
->Embed(GetParent()->GetPeer());
282 GetParent()->MacChildAdded() ;
284 // adjust font, controlsize etc
285 DoSetWindowVariant( m_windowVariant
) ;
287 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
289 // for controls we want to use best size for wxDefaultSize params )
290 if ( !m_macIsUserPane
)
291 SetInitialSize(size
);
293 SetCursor( *wxSTANDARD_CURSOR
) ;
296 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
298 // Don't assert, in case we set the window variant before
299 // the window is created
300 // wxASSERT( m_peer->Ok() ) ;
302 m_windowVariant
= variant
;
304 if (m_peer
== NULL
|| !m_peer
->IsOk())
307 m_peer
->SetControlSize( variant
);
308 #if wxOSX_USE_COCOA_OR_CARBON
313 ThemeFontID themeFont
= kThemeSystemFont
;
315 // we will get that from the settings later
316 // and make this NORMAL later, but first
317 // we have a few calculations that we must fix
321 case wxWINDOW_VARIANT_NORMAL
:
322 size
= kControlSizeNormal
;
323 themeFont
= kThemeSystemFont
;
326 case wxWINDOW_VARIANT_SMALL
:
327 size
= kControlSizeSmall
;
328 themeFont
= kThemeSmallSystemFont
;
331 case wxWINDOW_VARIANT_MINI
:
332 // not always defined in the headers
337 case wxWINDOW_VARIANT_LARGE
:
338 size
= kControlSizeLarge
;
339 themeFont
= kThemeSystemFont
;
343 wxFAIL_MSG(_T("unexpected window variant"));
347 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
348 font
.MacCreateFromThemeFont( themeFont
) ;
350 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
353 case wxWINDOW_VARIANT_NORMAL
:
354 themeFont
= kCTFontSystemFontType
;
357 case wxWINDOW_VARIANT_SMALL
:
358 themeFont
= kCTFontSmallSystemFontType
;
361 case wxWINDOW_VARIANT_MINI
:
362 themeFont
= kCTFontMiniSystemFontType
;
365 case wxWINDOW_VARIANT_LARGE
:
366 themeFont
= kCTFontSystemFontType
;
370 wxFAIL_MSG(_T("unexpected window variant"));
373 font
.MacCreateFromUIFont( themeFont
) ;
380 void wxWindowMac::MacUpdateControlFont()
383 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
385 // do not trigger refreshes upon invisible and possible partly created objects
386 if ( IsShownOnScreen() )
390 bool wxWindowMac::SetFont(const wxFont
& font
)
392 bool retval
= wxWindowBase::SetFont( font
);
394 MacUpdateControlFont() ;
399 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
401 bool retval
= wxWindowBase::SetForegroundColour( col
);
404 MacUpdateControlFont();
409 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
411 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
415 m_peer
->SetBackgroundColour( col
) ;
420 void wxWindowMac::SetFocus()
422 if ( !AcceptsFocus() )
425 wxWindow
* former
= FindFocus() ;
426 if ( former
== this )
432 void wxWindowMac::DoCaptureMouse()
434 wxApp::s_captureWindow
= (wxWindow
*) this ;
437 wxWindow
* wxWindowBase::GetCapture()
439 return wxApp::s_captureWindow
;
442 void wxWindowMac::DoReleaseMouse()
444 wxApp::s_captureWindow
= NULL
;
447 #if wxUSE_DRAG_AND_DROP
449 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
453 m_dropTarget
= pDropTarget
;
454 if ( m_dropTarget
!= NULL
)
462 // Old-style File Manager Drag & Drop
463 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
468 // From a wx position / size calculate the appropriate size of the native control
470 bool wxWindowMac::MacGetBoundsForControl(
474 int& w
, int& h
, bool adjustOrigin
) const
476 // the desired size, minus the border pixels gives the correct size of the control
480 w
= WidthDefault( size
.x
);
481 h
= HeightDefault( size
.y
);
483 x
+= MacGetLeftBorderSize() ;
484 y
+= MacGetTopBorderSize() ;
485 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
486 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
489 AdjustForParentClientOrigin( x
, y
) ;
491 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
492 if ( GetParent() && !GetParent()->IsTopLevel() )
494 x
-= GetParent()->MacGetLeftBorderSize() ;
495 y
-= GetParent()->MacGetTopBorderSize() ;
501 // Get window size (not client size)
502 void wxWindowMac::DoGetSize(int *x
, int *y
) const
505 m_peer
->GetSize( width
, height
);
508 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
510 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
513 // get the position of the bounds of this window in client coordinates of its parent
514 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
518 m_peer
->GetPosition( x1
, y1
) ;
520 // get the wx window position from the native one
521 x1
-= MacGetLeftBorderSize() ;
522 y1
-= MacGetTopBorderSize() ;
526 wxWindow
*parent
= GetParent();
529 // we must first adjust it to be in window coordinates of the parent,
530 // as otherwise it gets lost by the ClientAreaOrigin fix
531 x1
+= parent
->MacGetLeftBorderSize() ;
532 y1
+= parent
->MacGetTopBorderSize() ;
534 // and now to client coordinates
535 wxPoint
pt(parent
->GetClientAreaOrigin());
547 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
549 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
550 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
551 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
552 MacRootWindowToWindow( x
, y
) ;
554 wxPoint origin
= GetClientAreaOrigin() ;
561 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
563 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
564 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
566 wxPoint origin
= GetClientAreaOrigin() ;
572 MacWindowToRootWindow( x
, y
) ;
573 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
576 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
578 wxPoint origin
= GetClientAreaOrigin() ;
584 MacWindowToRootWindow( x
, y
) ;
587 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
598 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
601 pt
.x
-= MacGetLeftBorderSize() ;
602 pt
.y
-= MacGetTopBorderSize() ;
603 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
613 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
624 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
627 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
628 pt
.x
+= MacGetLeftBorderSize() ;
629 pt
.y
+= MacGetTopBorderSize() ;
639 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
641 wxSize sizeTotal
= size
;
643 int innerwidth
, innerheight
;
645 int outerwidth
, outerheight
;
647 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
648 m_peer
->GetSize( outerwidth
, outerheight
);
650 sizeTotal
.x
+= left
+ (outerwidth
-innerwidth
);
651 sizeTotal
.y
+= top
+ (outerheight
-innerheight
);
653 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
654 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
659 // Get size *available for subwindows* i.e. excluding menu bar etc.
660 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
666 m_peer
->GetContentArea( left
, top
, ww
, hh
);
668 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
669 hh
-= m_hScrollBar
->GetSize().y
;
671 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
672 ww
-= m_vScrollBar
->GetSize().x
;
680 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
682 if (m_cursor
.IsSameAs(cursor
))
687 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
692 if ( ! wxWindowBase::SetCursor( cursor
) )
696 wxASSERT_MSG( m_cursor
.Ok(),
697 wxT("cursor must be valid after call to the base version"));
699 wxWindowMac
*mouseWin
= 0 ;
702 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
703 WindowRef window
= (WindowRef
) ( tlw
? tlw
->GetWXWindow() : 0 ) ;
705 ControlPartCode part
;
708 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
710 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
714 GetGlobalMouse( &pt
);
717 ScreenToClient(&x
, &y
);
721 control
= FindControlUnderMouse( pt
, window
, &part
) ;
723 mouseWin
= wxFindWindowFromWXWidget( (WXWidget
) control
) ;
728 if ( mouseWin
== this && !wxIsBusy() )
729 m_cursor
.MacInstall() ;
735 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
737 #ifndef __WXUNIVERSAL__
738 menu
->SetInvokingWindow((wxWindow
*)this);
741 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
743 wxPoint mouse
= wxGetMousePosition();
749 ClientToScreen( &x
, &y
) ;
751 menu
->GetPeer()->PopUp(this, x
, y
);
752 menu
->SetInvokingWindow( NULL
);
755 // actually this shouldn't be called, because universal is having its own implementation
761 // ----------------------------------------------------------------------------
763 // ----------------------------------------------------------------------------
767 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
769 wxWindowBase::DoSetToolTip(tooltip
);
772 m_tooltip
->SetWindow(this);
777 void wxWindowMac::MacInvalidateBorders()
779 if ( m_peer
== NULL
)
782 bool vis
= IsShownOnScreen() ;
786 int outerBorder
= MacGetLeftBorderSize() ;
788 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
792 if ( outerBorder
== 0 )
795 // now we know that we have something to do at all
800 m_peer
->GetSize( tw
, th
);
801 m_peer
->GetPosition( tx
, ty
);
803 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
804 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
805 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
806 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
809 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
810 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
811 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
812 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
816 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
818 // this is never called for a toplevel window, so we know we have a parent
819 int former_x
, former_y
, former_w
, former_h
;
821 // Get true coordinates of former position
822 DoGetPosition( &former_x
, &former_y
) ;
823 DoGetSize( &former_w
, &former_h
) ;
825 wxWindow
*parent
= GetParent();
828 wxPoint
pt(parent
->GetClientAreaOrigin());
833 int actualWidth
= width
;
834 int actualHeight
= height
;
838 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
839 actualWidth
= m_minWidth
;
840 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
841 actualHeight
= m_minHeight
;
842 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
843 actualWidth
= m_maxWidth
;
844 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
845 actualHeight
= m_maxHeight
;
847 bool doMove
= false, doResize
= false ;
849 if ( actualX
!= former_x
|| actualY
!= former_y
)
852 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
855 if ( doMove
|| doResize
)
857 // as the borders are drawn outside the native control, we adjust now
859 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
860 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
861 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
863 if ( parent
&& !parent
->IsTopLevel() )
865 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
868 MacInvalidateBorders() ;
870 m_cachedClippedRectValid
= false ;
872 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
874 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
876 MacInvalidateBorders() ;
878 MacRepositionScrollBars() ;
881 wxPoint
point(actualX
, actualY
);
882 wxMoveEvent
event(point
, m_windowId
);
883 event
.SetEventObject(this);
884 HandleWindowEvent(event
) ;
889 MacRepositionScrollBars() ;
890 wxSize
size(actualWidth
, actualHeight
);
891 wxSizeEvent
event(size
, m_windowId
);
892 event
.SetEventObject(this);
893 HandleWindowEvent(event
);
898 wxSize
wxWindowMac::DoGetBestSize() const
900 if ( m_macIsUserPane
|| IsTopLevel() )
902 return wxWindowBase::DoGetBestSize() ;
908 m_peer
->GetBestRect(&r
);
910 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
917 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
922 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
929 // return wxWindowBase::DoGetBestSize() ;
933 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
934 MacGetRightBorderSize();
935 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
936 MacGetBottomBorderSize();
937 if ( bestHeight
< 10 )
940 return wxSize(bestWidth
, bestHeight
);
944 // set the size of the window: if the dimensions are positive, just use them,
945 // but if any of them is equal to -1, it means that we must find the value for
946 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
947 // which case -1 is a valid value for x and y)
949 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
950 // the width/height to best suit our contents, otherwise we reuse the current
952 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
954 // get the current size and position...
955 int currentX
, currentY
;
956 int currentW
, currentH
;
958 GetPosition(¤tX
, ¤tY
);
959 GetSize(¤tW
, ¤tH
);
961 // ... and don't do anything (avoiding flicker) if it's already ok
962 if ( x
== currentX
&& y
== currentY
&&
963 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
966 MacRepositionScrollBars() ; // we might have a real position shift
971 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
973 if ( x
== wxDefaultCoord
)
975 if ( y
== wxDefaultCoord
)
979 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
981 wxSize size
= wxDefaultSize
;
982 if ( width
== wxDefaultCoord
)
984 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
986 size
= DoGetBestSize();
991 // just take the current one
996 if ( height
== wxDefaultCoord
)
998 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1000 if ( size
.x
== wxDefaultCoord
)
1001 size
= DoGetBestSize();
1002 // else: already called DoGetBestSize() above
1008 // just take the current one
1013 DoMoveWindow( x
, y
, width
, height
);
1016 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1018 int left
,top
,width
,height
;
1019 m_peer
->GetContentArea( left
, top
, width
, height
);
1020 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1023 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1025 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1027 int currentclientwidth
, currentclientheight
;
1028 int currentwidth
, currentheight
;
1030 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1031 GetSize( ¤twidth
, ¤theight
) ;
1033 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1034 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1038 void wxWindowMac::SetLabel(const wxString
& title
)
1042 if ( m_peer
&& m_peer
->IsOk() )
1043 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1045 // do not trigger refreshes upon invisible and possible partly created objects
1046 if ( IsShownOnScreen() )
1050 wxString
wxWindowMac::GetLabel() const
1055 bool wxWindowMac::Show(bool show
)
1057 if ( !wxWindowBase::Show(show
) )
1061 m_peer
->SetVisibility( show
) ;
1066 void wxWindowMac::DoEnable(bool enable
)
1068 m_peer
->Enable( enable
) ;
1072 // status change notifications
1075 void wxWindowMac::MacVisibilityChanged()
1079 void wxWindowMac::MacHiliteChanged()
1083 void wxWindowMac::MacEnabledStateChanged()
1085 OnEnabled( m_peer
->IsEnabled() );
1089 // status queries on the inherited window's state
1092 bool wxWindowMac::MacIsReallyEnabled()
1094 return m_peer
->IsEnabled() ;
1097 bool wxWindowMac::MacIsReallyHilited()
1099 #if wxOSX_USE_CARBON
1100 return m_peer
->IsActive();
1102 return true; // TODO
1106 int wxWindowMac::GetCharHeight() const
1109 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1114 int wxWindowMac::GetCharWidth() const
1117 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1122 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1123 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1125 const wxFont
*fontToUse
= theFont
;
1129 tempFont
= GetFont();
1130 fontToUse
= &tempFont
;
1133 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1134 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1136 wxDouble h
, d
, e
, w
;
1137 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1141 if ( externalLeading
)
1142 *externalLeading
= (wxCoord
)(e
+0.5);
1144 *descent
= (wxCoord
)(d
+0.5);
1146 *x
= (wxCoord
)(w
+0.5);
1148 *y
= (wxCoord
)(h
+0.5);
1152 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1153 * we always intersect with the entire window, not only with the client area
1156 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1158 if ( m_peer
== NULL
)
1161 if ( !IsShownOnScreen() )
1164 m_peer
->SetNeedsDisplay( rect
) ;
1167 void wxWindowMac::DoFreeze()
1169 #if wxOSX_USE_CARBON
1170 if ( m_peer
&& m_peer
->IsOk() )
1171 m_peer
->SetDrawingEnabled( false ) ;
1175 void wxWindowMac::DoThaw()
1177 #if wxOSX_USE_CARBON
1178 if ( m_peer
&& m_peer
->IsOk() )
1180 m_peer
->SetDrawingEnabled( true ) ;
1181 m_peer
->InvalidateWithChildren() ;
1186 wxWindow
*wxGetActiveWindow()
1188 // actually this is a windows-only concept
1192 // Coordinates relative to the window
1193 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1195 // We really don't move the mouse programmatically under Mac.
1198 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1200 if ( MacGetTopLevelWindow() == NULL
)
1203 #if TARGET_API_MAC_OSX
1204 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1210 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1212 event
.GetDC()->Clear() ;
1214 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1216 // don't skip the event here, custom background means that the app
1217 // is drawing it itself in its OnPaint(), so don't draw it at all
1218 // now to avoid flicker
1226 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1231 int wxWindowMac::GetScrollPos(int orient
) const
1233 if ( orient
== wxHORIZONTAL
)
1236 return m_hScrollBar
->GetThumbPosition() ;
1241 return m_vScrollBar
->GetThumbPosition() ;
1247 // This now returns the whole range, not just the number
1248 // of positions that we can scroll.
1249 int wxWindowMac::GetScrollRange(int orient
) const
1251 if ( orient
== wxHORIZONTAL
)
1254 return m_hScrollBar
->GetRange() ;
1259 return m_vScrollBar
->GetRange() ;
1265 int wxWindowMac::GetScrollThumb(int orient
) const
1267 if ( orient
== wxHORIZONTAL
)
1270 return m_hScrollBar
->GetThumbSize() ;
1275 return m_vScrollBar
->GetThumbSize() ;
1281 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1283 if ( orient
== wxHORIZONTAL
)
1286 m_hScrollBar
->SetThumbPosition( pos
) ;
1291 m_vScrollBar
->SetThumbPosition( pos
) ;
1296 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1298 bool needVisibilityUpdate
= false;
1300 if ( m_hScrollBarAlwaysShown
!= hflag
)
1302 m_hScrollBarAlwaysShown
= hflag
;
1303 needVisibilityUpdate
= true;
1306 if ( m_vScrollBarAlwaysShown
!= vflag
)
1308 m_vScrollBarAlwaysShown
= vflag
;
1309 needVisibilityUpdate
= true;
1312 if ( needVisibilityUpdate
)
1313 DoUpdateScrollbarVisibility();
1317 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1318 // our own window origin is at leftOrigin/rightOrigin
1321 void wxWindowMac::MacPaintGrowBox()
1326 if ( MacHasScrollBarCorner() )
1328 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1329 wxASSERT( cgContext
) ;
1333 m_peer
->GetSize( tw
, th
);
1334 m_peer
->GetPosition( tx
, ty
);
1336 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1339 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1340 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1341 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1342 CGContextSaveGState( cgContext
);
1344 if ( m_backgroundColour
.Ok() )
1346 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1350 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1352 CGContextFillRect( cgContext
, cgrect
);
1353 CGContextRestoreGState( cgContext
);
1357 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1362 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1364 // back to the surrounding frame rectangle
1367 m_peer
->GetSize( tw
, th
);
1368 m_peer
->GetPosition( tx
, ty
);
1370 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1372 #if wxOSX_USE_COCOA_OR_CARBON
1374 InsetRect( &rect
, -1 , -1 ) ;
1377 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1378 rect
.bottom
- rect
.top
) ;
1380 HIThemeFrameDrawInfo info
;
1381 memset( &info
, 0 , sizeof(info
) ) ;
1385 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1386 info
.isFocused
= hasFocus
;
1388 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1389 wxASSERT( cgContext
) ;
1391 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1393 info
.kind
= kHIThemeFrameTextFieldSquare
;
1394 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1396 else if ( HasFlag(wxSIMPLE_BORDER
) )
1398 info
.kind
= kHIThemeFrameListBox
;
1399 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1401 else if ( hasFocus
)
1403 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1405 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1406 m_peer
->GetRect( &rect
) ;
1407 if ( MacHasScrollBarCorner() )
1409 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1410 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1411 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1412 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1413 HIThemeGrowBoxDrawInfo info
;
1414 memset( &info
, 0, sizeof(info
) ) ;
1416 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1417 info
.kind
= kHIThemeGrowBoxKindNone
;
1418 // contrary to the docs ...SizeSmall does not work
1419 info
.size
= kHIThemeGrowBoxSizeNormal
;
1420 info
.direction
= 0 ;
1421 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1425 #endif // wxOSX_USE_COCOA_OR_CARBON
1428 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1430 if ( child
== m_hScrollBar
)
1431 m_hScrollBar
= NULL
;
1432 if ( child
== m_vScrollBar
)
1433 m_vScrollBar
= NULL
;
1435 wxWindowBase::RemoveChild( child
) ;
1438 void wxWindowMac::DoUpdateScrollbarVisibility()
1440 bool triggerSizeEvent
= false;
1444 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1446 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1448 m_hScrollBar
->Show( showHScrollBar
);
1449 triggerSizeEvent
= true;
1455 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1457 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1459 m_vScrollBar
->Show( showVScrollBar
) ;
1460 triggerSizeEvent
= true;
1464 MacRepositionScrollBars() ;
1465 if ( triggerSizeEvent
)
1467 wxSizeEvent
event(GetSize(), m_windowId
);
1468 event
.SetEventObject(this);
1469 HandleWindowEvent(event
);
1473 // New function that will replace some of the above.
1474 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1475 int range
, bool refresh
)
1477 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1478 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1479 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1480 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1482 DoUpdateScrollbarVisibility();
1485 // Does a physical scroll
1486 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1488 if ( dx
== 0 && dy
== 0 )
1491 int width
, height
;
1492 GetClientSize( &width
, &height
) ;
1495 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1497 scrollrect
.Intersect( *rect
) ;
1498 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1499 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1501 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1506 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1508 child
= node
->GetData();
1511 if (child
== m_vScrollBar
)
1513 if (child
== m_hScrollBar
)
1515 if (child
->IsTopLevel())
1518 child
->GetPosition( &x
, &y
);
1519 child
->GetSize( &w
, &h
);
1522 wxRect
rc( x
, y
, w
, h
);
1523 if (rect
->Intersects( rc
))
1524 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1528 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1533 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1535 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1537 wxScrollWinEvent wevent
;
1538 wevent
.SetPosition(event
.GetPosition());
1539 wevent
.SetOrientation(event
.GetOrientation());
1540 wevent
.SetEventObject(this);
1542 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1543 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1544 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1545 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1546 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1547 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1548 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1549 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1550 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1551 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1552 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1553 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1554 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1555 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1556 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1557 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1559 HandleWindowEvent(wevent
);
1563 // Get the window with the focus
1564 wxWindow
*wxWindowBase::DoFindFocus()
1566 #if wxOSX_USE_CARBON
1567 ControlRef control
;
1568 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1569 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1575 void wxWindowMac::OnInternalIdle()
1577 // This calls the UI-update mechanism (querying windows for
1578 // menu/toolbar/control state information)
1579 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1580 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1583 // Raise the window to the top of the Z order
1584 void wxWindowMac::Raise()
1589 // Lower the window to the bottom of the Z order
1590 void wxWindowMac::Lower()
1595 // static wxWindow *gs_lastWhich = NULL;
1597 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1599 // first trigger a set cursor event
1601 wxPoint clientorigin
= GetClientAreaOrigin() ;
1602 wxSize clientsize
= GetClientSize() ;
1604 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1606 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1608 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1609 if ( processedEvtSetCursor
&& event
.HasCursor() )
1611 cursor
= event
.GetCursor() ;
1615 // the test for processedEvtSetCursor is here to prevent using m_cursor
1616 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1617 // it - this is a way to say that our cursor shouldn't be used for this
1619 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1622 if ( !wxIsBusy() && !GetParent() )
1623 cursor
= *wxSTANDARD_CURSOR
;
1627 cursor
.MacInstall() ;
1630 return cursor
.Ok() ;
1633 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1637 return m_tooltip
->GetTip() ;
1640 return wxEmptyString
;
1643 void wxWindowMac::ClearBackground()
1649 void wxWindowMac::Update()
1651 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1656 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1658 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1662 if ( iter
->IsTopLevel() )
1664 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1668 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1673 iter
= iter
->GetParent() ;
1679 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1681 MacUpdateClippedRects() ;
1683 return m_cachedClippedClientRect
;
1686 const wxRect
& wxWindowMac::MacGetClippedRect() const
1688 MacUpdateClippedRects() ;
1690 return m_cachedClippedRect
;
1693 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1695 MacUpdateClippedRects() ;
1697 return m_cachedClippedRectWithOuterStructure
;
1700 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1702 static wxRegion emptyrgn
;
1704 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1706 MacUpdateClippedRects() ;
1707 if ( includeOuterStructures
)
1708 return m_cachedClippedRegionWithOuterStructure
;
1710 return m_cachedClippedRegion
;
1718 void wxWindowMac::MacUpdateClippedRects() const
1720 #if wxOSX_USE_CARBON
1721 if ( m_cachedClippedRectValid
)
1724 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1725 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1726 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1727 // to add focus borders everywhere
1729 Rect rIncludingOuterStructures
;
1733 m_peer
->GetSize( tw
, th
);
1734 m_peer
->GetPosition( tx
, ty
);
1736 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1738 r
.left
-= MacGetLeftBorderSize() ;
1739 r
.top
-= MacGetTopBorderSize() ;
1740 r
.bottom
+= MacGetBottomBorderSize() ;
1741 r
.right
+= MacGetRightBorderSize() ;
1748 rIncludingOuterStructures
= r
;
1749 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1751 wxRect cl
= GetClientRect() ;
1752 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1756 const wxWindow
* child
= (wxWindow
*) this ;
1757 const wxWindow
* parent
= NULL
;
1759 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1761 if ( parent
->MacIsChildOfClientArea(child
) )
1763 size
= parent
->GetClientSize() ;
1764 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1770 // this will be true for scrollbars, toolbars etc.
1771 size
= parent
->GetSize() ;
1772 y
= parent
->MacGetTopBorderSize() ;
1773 x
= parent
->MacGetLeftBorderSize() ;
1774 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1775 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1778 parent
->MacWindowToRootWindow( &x
, &y
) ;
1779 MacRootWindowToWindow( &x
, &y
) ;
1781 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1783 // the wxwindow and client rects will always be clipped
1784 SectRect( &r
, &rparent
, &r
) ;
1785 SectRect( &rClient
, &rparent
, &rClient
) ;
1787 // the structure only at 'hard' borders
1788 if ( parent
->MacClipChildren() ||
1789 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1791 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1797 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1798 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1799 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1800 m_cachedClippedRectWithOuterStructure
= wxRect(
1801 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1802 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1803 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1805 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1806 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1807 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1809 m_cachedClippedRectValid
= true ;
1814 This function must not change the updatergn !
1816 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1818 bool handled
= false ;
1819 #if wxOSX_USE_CARBON
1821 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1822 GetRegionBounds( updatergn
, &updatebounds
) ;
1824 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1826 if ( !EmptyRgn(updatergn
) )
1828 RgnHandle newupdate
= NewRgn() ;
1829 wxSize point
= GetClientSize() ;
1830 wxPoint origin
= GetClientAreaOrigin() ;
1831 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1832 SectRgn( newupdate
, updatergn
, newupdate
) ;
1834 // first send an erase event to the entire update area
1836 // for the toplevel window this really is the entire area
1837 // for all the others only their client area, otherwise they
1838 // might be drawing with full alpha and eg put blue into
1839 // the grow-box area of a scrolled window (scroll sample)
1840 wxDC
* dc
= new wxWindowDC(this);
1842 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1844 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1846 wxEraseEvent
eevent( GetId(), dc
);
1847 eevent
.SetEventObject( this );
1848 HandleWindowEvent( eevent
);
1854 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1855 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1856 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1857 DisposeRgn( newupdate
) ;
1859 if ( !m_updateRegion
.Empty() )
1861 // paint the window itself
1864 event
.SetTimestamp(time
);
1865 event
.SetEventObject(this);
1866 HandleWindowEvent(event
);
1870 // now we cannot rely on having its borders drawn by a window itself, as it does not
1871 // get the updateRgn wide enough to always do so, so we do it from the parent
1872 // this would also be the place to draw any custom backgrounds for native controls
1873 // in Composited windowing
1874 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1878 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1880 child
= node
->GetData();
1883 if (child
== m_vScrollBar
)
1885 if (child
== m_hScrollBar
)
1887 if (child
->IsTopLevel())
1889 if (!child
->IsShown())
1892 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1894 child
->GetPosition( &x
, &y
);
1895 child
->GetSize( &w
, &h
);
1896 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1897 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1898 InsetRect( &childRect
, -10 , -10) ;
1900 if ( RectInRgn( &childRect
, updatergn
) )
1902 // paint custom borders
1903 wxNcPaintEvent
eventNc( child
->GetId() );
1904 eventNc
.SetEventObject( child
);
1905 if ( !child
->HandleWindowEvent( eventNc
) )
1907 child
->MacPaintBorders(0, 0) ;
1917 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1919 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1920 return tlw
? tlw
->GetWXWindow() : NULL
;
1923 bool wxWindowMac::MacHasScrollBarCorner() const
1925 /* Returns whether the scroll bars in a wxScrolledWindow should be
1926 * shortened. Scroll bars should be shortened if either:
1928 * - both scroll bars are visible, or
1930 * - there is a resize box in the parent frame's corner and this
1931 * window shares the bottom and right edge with the parent
1935 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1938 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1939 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1941 // Both scroll bars visible
1946 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1948 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1950 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1953 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1955 // Parent frame has resize handle
1956 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1958 // Note: allow for some wiggle room here as wxMac's
1959 // window rect calculations seem to be imprecise
1960 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1961 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1963 // Parent frame has resize handle and shares
1964 // right bottom corner
1969 // Parent frame has resize handle but doesn't
1970 // share right bottom corner
1976 // Parent frame doesn't have resize handle
1982 // No parent frame found
1987 void wxWindowMac::MacCreateScrollBars( long style
)
1989 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1991 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1993 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1994 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1996 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1999 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2001 GetClientSize( &width
, &height
) ;
2003 wxPoint
vPoint(width
- scrlsize
, 0) ;
2004 wxSize
vSize(scrlsize
, height
- adjust
) ;
2005 wxPoint
hPoint(0, height
- scrlsize
) ;
2006 wxSize
hSize(width
- adjust
, scrlsize
) ;
2008 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2009 if ( style
& wxVSCROLL
)
2011 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2012 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2015 if ( style
& wxHSCROLL
)
2017 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2018 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2022 // because the create does not take into account the client area origin
2023 // we might have a real position shift
2024 MacRepositionScrollBars() ;
2027 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2029 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2034 void wxWindowMac::MacRepositionScrollBars()
2036 if ( !m_hScrollBar
&& !m_vScrollBar
)
2039 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2040 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2042 // get real client area
2044 GetSize( &width
, &height
);
2046 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2047 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2049 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2050 wxSize
vSize( scrlsize
, height
- adjust
) ;
2051 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2052 wxSize
hSize( width
- adjust
, scrlsize
) ;
2055 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2057 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2060 bool wxWindowMac::AcceptsFocus() const
2062 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2065 void wxWindowMac::MacSuperChangedPosition()
2067 // only window-absolute structures have to be moved i.e. controls
2069 m_cachedClippedRectValid
= false ;
2072 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2075 child
= node
->GetData();
2076 child
->MacSuperChangedPosition() ;
2078 node
= node
->GetNext();
2082 void wxWindowMac::MacTopLevelWindowChangedPosition()
2084 // only screen-absolute structures have to be moved i.e. glcanvas
2087 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2090 child
= node
->GetData();
2091 child
->MacTopLevelWindowChangedPosition() ;
2093 node
= node
->GetNext();
2097 long wxWindowMac::MacGetLeftBorderSize() const
2104 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2106 #if wxOSX_USE_COCOA_OR_CARBON
2107 // this metric is only the 'outset' outside the simple frame rect
2108 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2114 else if (HasFlag(wxSIMPLE_BORDER
))
2116 #if wxOSX_USE_COCOA_OR_CARBON
2117 // this metric is only the 'outset' outside the simple frame rect
2118 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2128 long wxWindowMac::MacGetRightBorderSize() const
2130 // they are all symmetric in mac themes
2131 return MacGetLeftBorderSize() ;
2134 long wxWindowMac::MacGetTopBorderSize() const
2136 // they are all symmetric in mac themes
2137 return MacGetLeftBorderSize() ;
2140 long wxWindowMac::MacGetBottomBorderSize() const
2142 // they are all symmetric in mac themes
2143 return MacGetLeftBorderSize() ;
2146 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2148 return style
& ~wxBORDER_MASK
;
2151 // Find the wxWindowMac at the current mouse position, returning the mouse
2153 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2155 pt
= wxGetMousePosition();
2156 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2158 return (wxWindow
*) found
;
2161 // Get the current mouse position.
2162 wxPoint
wxGetMousePosition()
2166 wxGetMousePosition( &x
, &y
);
2168 return wxPoint(x
, y
);
2171 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2173 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2175 // copied from wxGTK : CS
2176 // VZ: shouldn't we move this to base class then?
2178 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2181 // (a) it's a command event and so is propagated to the parent
2182 // (b) under MSW it can be generated from kbd too
2183 // (c) it uses screen coords (because of (a))
2184 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2186 this->ClientToScreen(event
.GetPosition()));
2187 evtCtx
.SetEventObject(this);
2188 if ( ! HandleWindowEvent(evtCtx
) )
2197 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2199 #if wxOSX_USE_COCOA_OR_CARBON
2200 // for native controls: call their native paint method
2201 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2203 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2204 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2205 CallNextEventHandler(
2206 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2207 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2212 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2213 wxInt16
WXUNUSED(controlpart
),
2214 bool WXUNUSED(mouseStillDown
))
2218 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2222 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2223 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2228 bool wxWindowMac::HandleClicked( double timestampsec
)
2233 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2235 #if wxOSX_USE_COCOA_OR_CARBON
2236 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2239 return eventNotHandledErr
;
2245 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2247 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2248 if ( !wxWindowBase::Reparent(newParent
) )
2251 m_peer
->RemoveFromParent();
2252 m_peer
->Embed( GetParent()->GetPeer() );
2256 bool wxWindowMac::SetTransparent(wxByte alpha
)
2258 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2260 if ( alpha
!= m_macAlpha
)
2262 m_macAlpha
= alpha
;
2269 bool wxWindowMac::CanSetTransparent()
2274 wxByte
wxWindowMac::GetTransparent() const
2279 bool wxWindowMac::IsShownOnScreen() const
2281 if ( m_peer
&& m_peer
->IsOk() )
2283 bool peerVis
= m_peer
->IsVisible();
2284 bool wxVis
= wxWindowBase::IsShownOnScreen();
2285 if( peerVis
!= wxVis
)
2287 // CS : put a breakpoint here to investigate differences
2288 // between native an wx visibilities
2289 // the only place where I've encountered them until now
2290 // are the hiding/showing sequences where the vis-changed event is
2291 // first sent to the innermost control, while wx does things
2292 // from the outmost control
2293 wxVis
= wxWindowBase::IsShownOnScreen();
2297 return m_peer
->IsVisible();
2299 return wxWindowBase::IsShownOnScreen();
2306 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2308 static MacControlMap wxWinMacControlList
;
2310 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2312 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2314 return impl
->GetWXPeer();
2319 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2321 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2323 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2326 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2328 // adding NULL ControlRef is (first) surely a result of an error and
2329 // (secondly) breaks native event processing
2330 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2332 wxWinMacControlList
[inControl
] = impl
;
2335 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2337 // iterate over all the elements in the class
2338 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2339 // we should go on...
2345 MacControlMap::iterator it
;
2346 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2348 if ( it
->second
== impl
)
2350 wxWinMacControlList
.erase(it
);
2358 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2360 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2363 m_isRootControl
= isRootControl
;
2367 wxWidgetImpl::wxWidgetImpl()
2372 wxWidgetImpl::~wxWidgetImpl()
2376 void wxWidgetImpl::Init()
2378 m_isRootControl
= false;
2380 m_needsFocusRect
= false;
2383 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2385 m_needsFocusRect
= needs
;
2388 bool wxWidgetImpl::NeedsFocusRect() const
2390 return m_needsFocusRect
;