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_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 // ===========================================================================
98 // ===========================================================================
100 // ----------------------------------------------------------------------------
101 // constructors and such
102 // ----------------------------------------------------------------------------
104 wxWindowMac::wxWindowMac()
109 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
114 const wxString
& name
)
117 Create(parent
, id
, pos
, size
, style
, name
);
120 void wxWindowMac::Init()
124 m_cgContextRef
= NULL
;
126 // as all windows are created with WS_VISIBLE style...
129 m_hScrollBar
= NULL
;
130 m_vScrollBar
= NULL
;
131 m_hScrollBarAlwaysShown
= false;
132 m_vScrollBarAlwaysShown
= false;
134 m_macIsUserPane
= true;
135 m_clipChildren
= false ;
136 m_cachedClippedRectValid
= false ;
139 wxWindowMac::~wxWindowMac()
143 MacInvalidateBorders() ;
145 #ifndef __WXUNIVERSAL__
146 // VS: make sure there's no wxFrame with last focus set to us:
147 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
149 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
152 if ( frame
->GetLastFocus() == this )
153 frame
->SetLastFocus(NULL
);
159 // destroy children before destroying this window itself
162 // wxRemoveMacControlAssociation( this ) ;
163 // If we delete an item, we should initialize the parent panel,
164 // because it could now be invalid.
165 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
168 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
169 tlw
->SetDefaultItem(NULL
);
172 if ( g_MacLastWindow
== this )
173 g_MacLastWindow
= NULL
;
175 #ifndef __WXUNIVERSAL__
176 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
179 if ( frame
->GetLastFocus() == this )
180 frame
->SetLastFocus( NULL
) ;
184 // delete our drop target if we've got one
185 #if wxUSE_DRAG_AND_DROP
186 if ( m_dropTarget
!= NULL
)
196 WXWidget
wxWindowMac::GetHandle() const
198 return (WXWidget
) m_peer
->GetWXWidget() ;
202 // TODO END move to window_osx.cpp
205 // ---------------------------------------------------------------------------
206 // Utility Routines to move between different coordinate systems
207 // ---------------------------------------------------------------------------
210 * Right now we have the following setup :
211 * a border that is not part of the native control is always outside the
212 * control's border (otherwise we loose all native intelligence, future ways
213 * may be to have a second embedding control responsible for drawing borders
214 * and backgrounds eventually)
215 * so all this border calculations have to be taken into account when calling
216 * native methods or getting native oriented data
217 * so we have three coordinate systems here
218 * wx client coordinates
219 * wx window coordinates (including window frames)
227 bool wxWindowMac::Create(wxWindowMac
*parent
,
232 const wxString
& name
)
234 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
236 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
239 m_windowVariant
= parent
->GetWindowVariant() ;
241 if ( m_macIsUserPane
)
243 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
244 MacPostControlCreate(pos
, size
) ;
247 #ifndef __WXUNIVERSAL__
248 // Don't give scrollbars to wxControls unless they ask for them
249 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
250 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
252 MacCreateScrollBars( style
) ;
256 wxWindowCreateEvent
event((wxWindow
*)this);
257 GetEventHandler()->AddPendingEvent(event
);
262 void wxWindowMac::MacChildAdded()
265 m_vScrollBar
->Raise() ;
267 m_hScrollBar
->Raise() ;
270 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
272 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
274 GetParent()->AddChild( this );
276 m_peer
->InstallEventHandler();
277 m_peer
->Embed(GetParent()->GetPeer());
279 GetParent()->MacChildAdded() ;
281 // adjust font, controlsize etc
282 DoSetWindowVariant( m_windowVariant
) ;
284 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
286 // for controls we want to use best size for wxDefaultSize params )
287 if ( !m_macIsUserPane
)
288 SetInitialSize(size
);
290 SetCursor( *wxSTANDARD_CURSOR
) ;
293 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
295 // Don't assert, in case we set the window variant before
296 // the window is created
297 // wxASSERT( m_peer->Ok() ) ;
299 m_windowVariant
= variant
;
301 if (m_peer
== NULL
|| !m_peer
->IsOk())
304 m_peer
->SetControlSize( variant
);
308 // we will get that from the settings later
309 // and make this NORMAL later, but first
310 // we have a few calculations that we must fix
314 case wxWINDOW_VARIANT_NORMAL
:
315 size
= kControlSizeNormal
;
318 case wxWINDOW_VARIANT_SMALL
:
319 size
= kControlSizeSmall
;
322 case wxWINDOW_VARIANT_MINI
:
323 // not always defined in the headers
327 case wxWINDOW_VARIANT_LARGE
:
328 size
= kControlSizeLarge
;
332 wxFAIL_MSG(_T("unexpected window variant"));
335 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
338 #if wxOSX_USE_COCOA_OR_CARBON
341 #if wxOSX_USE_ATSU_TEXT
342 ThemeFontID themeFont
= kThemeSystemFont
;
344 // we will get that from the settings later
345 // and make this NORMAL later, but first
346 // we have a few calculations that we must fix
350 case wxWINDOW_VARIANT_NORMAL
:
351 themeFont
= kThemeSystemFont
;
354 case wxWINDOW_VARIANT_SMALL
:
355 themeFont
= kThemeSmallSystemFont
;
358 case wxWINDOW_VARIANT_MINI
:
359 // not always defined in the headers
363 case wxWINDOW_VARIANT_LARGE
:
364 themeFont
= kThemeSystemFont
;
368 wxFAIL_MSG(_T("unexpected window variant"));
372 font
.MacCreateFromThemeFont( themeFont
) ;
374 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
377 case wxWINDOW_VARIANT_NORMAL
:
378 themeFont
= kCTFontSystemFontType
;
381 case wxWINDOW_VARIANT_SMALL
:
382 themeFont
= kCTFontSmallSystemFontType
;
385 case wxWINDOW_VARIANT_MINI
:
386 themeFont
= kCTFontMiniSystemFontType
;
389 case wxWINDOW_VARIANT_LARGE
:
390 themeFont
= kCTFontSystemFontType
;
394 wxFAIL_MSG(_T("unexpected window variant"));
397 font
.MacCreateFromUIFont( themeFont
) ;
404 void wxWindowMac::MacUpdateControlFont()
407 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
409 // do not trigger refreshes upon invisible and possible partly created objects
410 if ( IsShownOnScreen() )
414 bool wxWindowMac::SetFont(const wxFont
& font
)
416 bool retval
= wxWindowBase::SetFont( font
);
418 MacUpdateControlFont() ;
423 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
425 bool retval
= wxWindowBase::SetForegroundColour( col
);
428 MacUpdateControlFont();
433 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
435 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
439 m_peer
->SetBackgroundColour( col
) ;
444 void wxWindowMac::SetFocus()
446 if ( !AcceptsFocus() )
449 wxWindow
* former
= FindFocus() ;
450 if ( former
== this )
456 void wxWindowMac::DoCaptureMouse()
458 wxApp::s_captureWindow
= (wxWindow
*) this ;
459 m_peer
->CaptureMouse() ;
462 wxWindow
* wxWindowBase::GetCapture()
464 return wxApp::s_captureWindow
;
467 void wxWindowMac::DoReleaseMouse()
469 wxApp::s_captureWindow
= NULL
;
471 m_peer
->ReleaseMouse() ;
474 #if wxUSE_DRAG_AND_DROP
476 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
480 m_dropTarget
= pDropTarget
;
481 if ( m_dropTarget
!= NULL
)
489 // Old-style File Manager Drag & Drop
490 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
495 // From a wx position / size calculate the appropriate size of the native control
497 bool wxWindowMac::MacGetBoundsForControl(
501 int& w
, int& h
, bool adjustOrigin
) const
503 // the desired size, minus the border pixels gives the correct size of the control
507 w
= WidthDefault( size
.x
);
508 h
= HeightDefault( size
.y
);
510 x
+= MacGetLeftBorderSize() ;
511 y
+= MacGetTopBorderSize() ;
512 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
513 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
516 AdjustForParentClientOrigin( x
, y
) ;
518 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
519 if ( GetParent() && !GetParent()->IsTopLevel() )
521 x
-= GetParent()->MacGetLeftBorderSize() ;
522 y
-= GetParent()->MacGetTopBorderSize() ;
528 // Get window size (not client size)
529 void wxWindowMac::DoGetSize(int *x
, int *y
) const
532 m_peer
->GetSize( width
, height
);
535 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
537 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
540 // get the position of the bounds of this window in client coordinates of its parent
541 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
545 m_peer
->GetPosition( x1
, y1
) ;
547 // get the wx window position from the native one
548 x1
-= MacGetLeftBorderSize() ;
549 y1
-= MacGetTopBorderSize() ;
553 wxWindow
*parent
= GetParent();
556 // we must first adjust it to be in window coordinates of the parent,
557 // as otherwise it gets lost by the ClientAreaOrigin fix
558 x1
+= parent
->MacGetLeftBorderSize() ;
559 y1
+= parent
->MacGetTopBorderSize() ;
561 // and now to client coordinates
562 wxPoint
pt(parent
->GetClientAreaOrigin());
574 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
576 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
577 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
578 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
579 MacRootWindowToWindow( x
, y
) ;
581 wxPoint origin
= GetClientAreaOrigin() ;
588 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
590 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
591 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
593 wxPoint origin
= GetClientAreaOrigin() ;
599 MacWindowToRootWindow( x
, y
) ;
600 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
603 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
605 wxPoint origin
= GetClientAreaOrigin() ;
611 MacWindowToRootWindow( x
, y
) ;
614 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
625 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
628 pt
.x
-= MacGetLeftBorderSize() ;
629 pt
.y
-= MacGetTopBorderSize() ;
630 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
640 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
651 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
654 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
655 pt
.x
+= MacGetLeftBorderSize() ;
656 pt
.y
+= MacGetTopBorderSize() ;
666 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
668 wxSize sizeTotal
= size
;
670 int innerwidth
, innerheight
;
672 int outerwidth
, outerheight
;
674 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
675 m_peer
->GetSize( outerwidth
, outerheight
);
677 sizeTotal
.x
+= outerwidth
-innerwidth
;
678 sizeTotal
.y
+= outerheight
-innerheight
;
680 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
681 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
686 // Get size *available for subwindows* i.e. excluding menu bar etc.
687 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
693 m_peer
->GetContentArea( left
, top
, ww
, hh
);
695 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
696 hh
-= m_hScrollBar
->GetSize().y
;
698 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
699 ww
-= m_vScrollBar
->GetSize().x
;
707 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
709 if (m_cursor
.IsSameAs(cursor
))
714 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
719 if ( ! wxWindowBase::SetCursor( cursor
) )
723 wxASSERT_MSG( m_cursor
.Ok(),
724 wxT("cursor must be valid after call to the base version"));
726 if ( GetPeer() != NULL
)
727 GetPeer()->SetCursor( m_cursor
);
733 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
735 #ifndef __WXUNIVERSAL__
736 menu
->SetInvokingWindow((wxWindow
*)this);
739 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
741 wxPoint mouse
= wxGetMousePosition();
747 ClientToScreen( &x
, &y
) ;
749 menu
->GetPeer()->PopUp(this, x
, y
);
750 menu
->SetInvokingWindow( NULL
);
753 // actually this shouldn't be called, because universal is having its own implementation
759 // ----------------------------------------------------------------------------
761 // ----------------------------------------------------------------------------
765 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
767 wxWindowBase::DoSetToolTip(tooltip
);
770 m_tooltip
->SetWindow(this);
775 void wxWindowMac::MacInvalidateBorders()
777 if ( m_peer
== NULL
)
780 bool vis
= IsShownOnScreen() ;
784 int outerBorder
= MacGetLeftBorderSize() ;
786 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
790 if ( outerBorder
== 0 )
793 // now we know that we have something to do at all
798 m_peer
->GetSize( tw
, th
);
799 m_peer
->GetPosition( tx
, ty
);
801 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
802 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
803 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
804 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
807 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
808 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
809 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
810 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
814 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
816 // this is never called for a toplevel window, so we know we have a parent
817 int former_x
, former_y
, former_w
, former_h
;
819 // Get true coordinates of former position
820 DoGetPosition( &former_x
, &former_y
) ;
821 DoGetSize( &former_w
, &former_h
) ;
823 wxWindow
*parent
= GetParent();
826 wxPoint
pt(parent
->GetClientAreaOrigin());
831 int actualWidth
= width
;
832 int actualHeight
= height
;
836 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
837 actualWidth
= m_minWidth
;
838 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
839 actualHeight
= m_minHeight
;
840 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
841 actualWidth
= m_maxWidth
;
842 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
843 actualHeight
= m_maxHeight
;
845 bool doMove
= false, doResize
= false ;
847 if ( actualX
!= former_x
|| actualY
!= former_y
)
850 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
853 if ( doMove
|| doResize
)
855 // as the borders are drawn outside the native control, we adjust now
857 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
858 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
859 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
861 if ( parent
&& !parent
->IsTopLevel() )
863 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
866 MacInvalidateBorders() ;
868 m_cachedClippedRectValid
= false ;
870 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
872 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
874 MacInvalidateBorders() ;
876 MacRepositionScrollBars() ;
879 wxPoint
point(actualX
, actualY
);
880 wxMoveEvent
event(point
, m_windowId
);
881 event
.SetEventObject(this);
882 HandleWindowEvent(event
) ;
887 MacRepositionScrollBars() ;
888 wxSize
size(actualWidth
, actualHeight
);
889 wxSizeEvent
event(size
, m_windowId
);
890 event
.SetEventObject(this);
891 HandleWindowEvent(event
);
896 wxSize
wxWindowMac::DoGetBestSize() const
898 if ( m_macIsUserPane
|| IsTopLevel() )
900 return wxWindowBase::DoGetBestSize() ;
906 m_peer
->GetBestRect(&r
);
908 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
915 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
920 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
927 // return wxWindowBase::DoGetBestSize() ;
931 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
932 MacGetRightBorderSize();
933 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
934 MacGetBottomBorderSize();
935 if ( bestHeight
< 10 )
938 return wxSize(bestWidth
, bestHeight
);
942 // set the size of the window: if the dimensions are positive, just use them,
943 // but if any of them is equal to -1, it means that we must find the value for
944 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
945 // which case -1 is a valid value for x and y)
947 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
948 // the width/height to best suit our contents, otherwise we reuse the current
950 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
952 // get the current size and position...
953 int currentX
, currentY
;
954 int currentW
, currentH
;
956 GetPosition(¤tX
, ¤tY
);
957 GetSize(¤tW
, ¤tH
);
959 // ... and don't do anything (avoiding flicker) if it's already ok
960 if ( x
== currentX
&& y
== currentY
&&
961 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
964 MacRepositionScrollBars() ; // we might have a real position shift
966 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
968 wxSizeEvent
event( wxSize(width
,height
), GetId() );
969 event
.SetEventObject( this );
970 HandleWindowEvent( event
);
976 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
978 if ( x
== wxDefaultCoord
)
980 if ( y
== wxDefaultCoord
)
984 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
986 wxSize size
= wxDefaultSize
;
987 if ( width
== wxDefaultCoord
)
989 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
991 size
= DoGetBestSize();
996 // just take the current one
1001 if ( height
== wxDefaultCoord
)
1003 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1005 if ( size
.x
== wxDefaultCoord
)
1006 size
= DoGetBestSize();
1007 // else: already called DoGetBestSize() above
1013 // just take the current one
1018 DoMoveWindow( x
, y
, width
, height
);
1021 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1023 int left
,top
,width
,height
;
1024 m_peer
->GetContentArea( left
, top
, width
, height
);
1025 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1028 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1030 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1032 int currentclientwidth
, currentclientheight
;
1033 int currentwidth
, currentheight
;
1035 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1036 GetSize( ¤twidth
, ¤theight
) ;
1038 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1039 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1043 void wxWindowMac::SetLabel(const wxString
& title
)
1047 if ( m_peer
&& m_peer
->IsOk() )
1048 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1050 // do not trigger refreshes upon invisible and possible partly created objects
1051 if ( IsShownOnScreen() )
1055 wxString
wxWindowMac::GetLabel() const
1060 bool wxWindowMac::Show(bool show
)
1062 if ( !wxWindowBase::Show(show
) )
1066 m_peer
->SetVisibility( show
) ;
1071 void wxWindowMac::DoEnable(bool enable
)
1073 m_peer
->Enable( enable
) ;
1077 // status change notifications
1080 void wxWindowMac::MacVisibilityChanged()
1084 void wxWindowMac::MacHiliteChanged()
1088 void wxWindowMac::MacEnabledStateChanged()
1090 OnEnabled( m_peer
->IsEnabled() );
1094 // status queries on the inherited window's state
1097 bool wxWindowMac::MacIsReallyEnabled()
1099 return m_peer
->IsEnabled() ;
1102 bool wxWindowMac::MacIsReallyHilited()
1104 #if wxOSX_USE_CARBON
1105 return m_peer
->IsActive();
1107 return true; // TODO
1111 int wxWindowMac::GetCharHeight() const
1114 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1119 int wxWindowMac::GetCharWidth() const
1122 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1127 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1128 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1130 const wxFont
*fontToUse
= theFont
;
1134 tempFont
= GetFont();
1135 fontToUse
= &tempFont
;
1138 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1139 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1141 wxDouble h
, d
, e
, w
;
1142 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1146 if ( externalLeading
)
1147 *externalLeading
= (wxCoord
)(e
+0.5);
1149 *descent
= (wxCoord
)(d
+0.5);
1151 *x
= (wxCoord
)(w
+0.5);
1153 *y
= (wxCoord
)(h
+0.5);
1157 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1158 * we always intersect with the entire window, not only with the client area
1161 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1163 if ( m_peer
== NULL
)
1166 if ( !IsShownOnScreen() )
1169 m_peer
->SetNeedsDisplay( rect
) ;
1172 void wxWindowMac::DoFreeze()
1174 #if wxOSX_USE_CARBON
1175 if ( m_peer
&& m_peer
->IsOk() )
1176 m_peer
->SetDrawingEnabled( false ) ;
1180 void wxWindowMac::DoThaw()
1182 #if wxOSX_USE_CARBON
1183 if ( m_peer
&& m_peer
->IsOk() )
1185 m_peer
->SetDrawingEnabled( true ) ;
1186 m_peer
->InvalidateWithChildren() ;
1191 wxWindow
*wxGetActiveWindow()
1193 // actually this is a windows-only concept
1197 // Coordinates relative to the window
1198 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1200 // We really don't move the mouse programmatically under Mac.
1203 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1205 if ( MacGetTopLevelWindow() == NULL
)
1208 #if TARGET_API_MAC_OSX
1209 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1215 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1217 event
.GetDC()->Clear() ;
1219 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1221 // don't skip the event here, custom background means that the app
1222 // is drawing it itself in its OnPaint(), so don't draw it at all
1223 // now to avoid flicker
1231 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1236 int wxWindowMac::GetScrollPos(int orient
) const
1238 if ( orient
== wxHORIZONTAL
)
1241 return m_hScrollBar
->GetThumbPosition() ;
1246 return m_vScrollBar
->GetThumbPosition() ;
1252 // This now returns the whole range, not just the number
1253 // of positions that we can scroll.
1254 int wxWindowMac::GetScrollRange(int orient
) const
1256 if ( orient
== wxHORIZONTAL
)
1259 return m_hScrollBar
->GetRange() ;
1264 return m_vScrollBar
->GetRange() ;
1270 int wxWindowMac::GetScrollThumb(int orient
) const
1272 if ( orient
== wxHORIZONTAL
)
1275 return m_hScrollBar
->GetThumbSize() ;
1280 return m_vScrollBar
->GetThumbSize() ;
1286 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1288 if ( orient
== wxHORIZONTAL
)
1291 m_hScrollBar
->SetThumbPosition( pos
) ;
1296 m_vScrollBar
->SetThumbPosition( pos
) ;
1301 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1303 bool needVisibilityUpdate
= false;
1305 if ( m_hScrollBarAlwaysShown
!= hflag
)
1307 m_hScrollBarAlwaysShown
= hflag
;
1308 needVisibilityUpdate
= true;
1311 if ( m_vScrollBarAlwaysShown
!= vflag
)
1313 m_vScrollBarAlwaysShown
= vflag
;
1314 needVisibilityUpdate
= true;
1317 if ( needVisibilityUpdate
)
1318 DoUpdateScrollbarVisibility();
1322 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1323 // our own window origin is at leftOrigin/rightOrigin
1326 void wxWindowMac::MacPaintGrowBox()
1331 if ( MacHasScrollBarCorner() )
1333 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1334 wxASSERT( cgContext
) ;
1338 m_peer
->GetSize( tw
, th
);
1339 m_peer
->GetPosition( tx
, ty
);
1341 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1344 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1345 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1346 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1347 CGContextSaveGState( cgContext
);
1349 if ( m_backgroundColour
.Ok() )
1351 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1355 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1357 CGContextFillRect( cgContext
, cgrect
);
1358 CGContextRestoreGState( cgContext
);
1362 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1367 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1369 // back to the surrounding frame rectangle
1372 m_peer
->GetSize( tw
, th
);
1373 m_peer
->GetPosition( tx
, ty
);
1375 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1377 #if wxOSX_USE_COCOA_OR_CARBON
1379 InsetRect( &rect
, -1 , -1 ) ;
1382 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1383 rect
.bottom
- rect
.top
) ;
1385 HIThemeFrameDrawInfo info
;
1386 memset( &info
, 0 , sizeof(info
) ) ;
1390 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1391 info
.isFocused
= hasFocus
;
1393 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1394 wxASSERT( cgContext
) ;
1396 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1398 info
.kind
= kHIThemeFrameTextFieldSquare
;
1399 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1401 else if ( HasFlag(wxSIMPLE_BORDER
) )
1403 info
.kind
= kHIThemeFrameListBox
;
1404 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1406 else if ( hasFocus
)
1408 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1410 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1411 m_peer
->GetRect( &rect
) ;
1412 if ( MacHasScrollBarCorner() )
1414 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1415 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1416 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1417 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1418 HIThemeGrowBoxDrawInfo info
;
1419 memset( &info
, 0, sizeof(info
) ) ;
1421 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1422 info
.kind
= kHIThemeGrowBoxKindNone
;
1423 // contrary to the docs ...SizeSmall does not work
1424 info
.size
= kHIThemeGrowBoxSizeNormal
;
1425 info
.direction
= 0 ;
1426 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1430 #endif // wxOSX_USE_COCOA_OR_CARBON
1433 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1435 if ( child
== m_hScrollBar
)
1436 m_hScrollBar
= NULL
;
1437 if ( child
== m_vScrollBar
)
1438 m_vScrollBar
= NULL
;
1440 wxWindowBase::RemoveChild( child
) ;
1443 void wxWindowMac::DoUpdateScrollbarVisibility()
1445 bool triggerSizeEvent
= false;
1449 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1451 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1453 m_hScrollBar
->Show( showHScrollBar
);
1454 triggerSizeEvent
= true;
1460 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1462 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1464 m_vScrollBar
->Show( showVScrollBar
) ;
1465 triggerSizeEvent
= true;
1469 MacRepositionScrollBars() ;
1470 if ( triggerSizeEvent
)
1472 wxSizeEvent
event(GetSize(), m_windowId
);
1473 event
.SetEventObject(this);
1474 HandleWindowEvent(event
);
1478 // New function that will replace some of the above.
1479 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1480 int range
, bool refresh
)
1482 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1483 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1484 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1485 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1487 DoUpdateScrollbarVisibility();
1490 // Does a physical scroll
1491 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1493 if ( dx
== 0 && dy
== 0 )
1496 int width
, height
;
1497 GetClientSize( &width
, &height
) ;
1500 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1502 scrollrect
.Intersect( *rect
) ;
1503 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1504 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1506 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1511 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1513 child
= node
->GetData();
1516 if (child
== m_vScrollBar
)
1518 if (child
== m_hScrollBar
)
1520 if (child
->IsTopLevel())
1523 child
->GetPosition( &x
, &y
);
1524 child
->GetSize( &w
, &h
);
1527 wxRect
rc( x
, y
, w
, h
);
1528 if (rect
->Intersects( rc
))
1529 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1533 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1538 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1540 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1542 wxScrollWinEvent wevent
;
1543 wevent
.SetPosition(event
.GetPosition());
1544 wevent
.SetOrientation(event
.GetOrientation());
1545 wevent
.SetEventObject(this);
1547 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1548 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1549 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1550 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1551 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1552 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1553 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1554 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1555 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1556 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1557 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1558 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1559 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1560 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1561 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1562 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1564 HandleWindowEvent(wevent
);
1568 // Get the window with the focus
1569 wxWindow
*wxWindowBase::DoFindFocus()
1571 #if wxOSX_USE_CARBON
1572 ControlRef control
;
1573 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1574 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1580 void wxWindowMac::OnInternalIdle()
1582 // This calls the UI-update mechanism (querying windows for
1583 // menu/toolbar/control state information)
1584 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1585 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1588 // Raise the window to the top of the Z order
1589 void wxWindowMac::Raise()
1594 // Lower the window to the bottom of the Z order
1595 void wxWindowMac::Lower()
1600 // static wxWindow *gs_lastWhich = NULL;
1602 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1604 // first trigger a set cursor event
1606 wxPoint clientorigin
= GetClientAreaOrigin() ;
1607 wxSize clientsize
= GetClientSize() ;
1609 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1611 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1613 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1614 if ( processedEvtSetCursor
&& event
.HasCursor() )
1616 cursor
= event
.GetCursor() ;
1620 // the test for processedEvtSetCursor is here to prevent using m_cursor
1621 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1622 // it - this is a way to say that our cursor shouldn't be used for this
1624 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1627 if ( !wxIsBusy() && !GetParent() )
1628 cursor
= *wxSTANDARD_CURSOR
;
1632 cursor
.MacInstall() ;
1635 return cursor
.Ok() ;
1638 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1642 return m_tooltip
->GetTip() ;
1645 return wxEmptyString
;
1648 void wxWindowMac::ClearBackground()
1654 void wxWindowMac::Update()
1656 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1661 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1663 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1667 if ( iter
->IsTopLevel() )
1669 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1673 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1678 iter
= iter
->GetParent() ;
1684 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1686 MacUpdateClippedRects() ;
1688 return m_cachedClippedClientRect
;
1691 const wxRect
& wxWindowMac::MacGetClippedRect() const
1693 MacUpdateClippedRects() ;
1695 return m_cachedClippedRect
;
1698 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1700 MacUpdateClippedRects() ;
1702 return m_cachedClippedRectWithOuterStructure
;
1705 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1707 static wxRegion emptyrgn
;
1709 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1711 MacUpdateClippedRects() ;
1712 if ( includeOuterStructures
)
1713 return m_cachedClippedRegionWithOuterStructure
;
1715 return m_cachedClippedRegion
;
1723 void wxWindowMac::MacUpdateClippedRects() const
1725 #if wxOSX_USE_CARBON
1726 if ( m_cachedClippedRectValid
)
1729 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1730 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1731 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1732 // to add focus borders everywhere
1734 Rect rIncludingOuterStructures
;
1738 m_peer
->GetSize( tw
, th
);
1739 m_peer
->GetPosition( tx
, ty
);
1741 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1743 r
.left
-= MacGetLeftBorderSize() ;
1744 r
.top
-= MacGetTopBorderSize() ;
1745 r
.bottom
+= MacGetBottomBorderSize() ;
1746 r
.right
+= MacGetRightBorderSize() ;
1753 rIncludingOuterStructures
= r
;
1754 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1756 wxRect cl
= GetClientRect() ;
1757 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1761 const wxWindow
* child
= (wxWindow
*) this ;
1762 const wxWindow
* parent
= NULL
;
1764 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1766 if ( parent
->MacIsChildOfClientArea(child
) )
1768 size
= parent
->GetClientSize() ;
1769 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1775 // this will be true for scrollbars, toolbars etc.
1776 size
= parent
->GetSize() ;
1777 y
= parent
->MacGetTopBorderSize() ;
1778 x
= parent
->MacGetLeftBorderSize() ;
1779 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1780 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1783 parent
->MacWindowToRootWindow( &x
, &y
) ;
1784 MacRootWindowToWindow( &x
, &y
) ;
1786 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1788 // the wxwindow and client rects will always be clipped
1789 SectRect( &r
, &rparent
, &r
) ;
1790 SectRect( &rClient
, &rparent
, &rClient
) ;
1792 // the structure only at 'hard' borders
1793 if ( parent
->MacClipChildren() ||
1794 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1796 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1802 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1803 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1804 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1805 m_cachedClippedRectWithOuterStructure
= wxRect(
1806 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1807 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1808 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1810 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1811 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1812 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1814 m_cachedClippedRectValid
= true ;
1819 This function must not change the updatergn !
1821 bool wxWindowMac::MacDoRedraw( long time
)
1823 bool handled
= false ;
1825 wxRegion formerUpdateRgn
= m_updateRegion
;
1826 wxRegion clientUpdateRgn
= formerUpdateRgn
;
1828 wxSize sz
= GetClientSize() ;
1829 wxPoint origin
= GetClientAreaOrigin() ;
1831 clientUpdateRgn
.Intersect(origin
.x
, origin
.y
, origin
.x
+ sz
.x
, origin
.y
+ sz
.y
);
1833 // first send an erase event to the entire update area
1835 // for the toplevel window this really is the entire area
1836 // for all the others only their client area, otherwise they
1837 // might be drawing with full alpha and eg put blue into
1838 // the grow-box area of a scrolled window (scroll sample)
1839 wxDC
* dc
= new wxWindowDC(this);
1841 dc
->SetDeviceClippingRegion(formerUpdateRgn
);
1843 dc
->SetDeviceClippingRegion(clientUpdateRgn
);
1845 wxEraseEvent
eevent( GetId(), dc
);
1846 eevent
.SetEventObject( this );
1847 HandleWindowEvent( eevent
);
1853 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1854 clientUpdateRgn
.Offset( -origin
.x
, -origin
.y
);
1855 m_updateRegion
= clientUpdateRgn
;
1857 if ( !m_updateRegion
.Empty() )
1859 // paint the window itself
1861 wxPaintEvent
event(GetId());
1862 event
.SetTimestamp(time
);
1863 event
.SetEventObject(this);
1864 handled
= HandleWindowEvent(event
);
1867 m_updateRegion
= formerUpdateRgn
;
1871 void wxWindowMac::MacPaintChildrenBorders()
1873 // now we cannot rely on having its borders drawn by a window itself, as it does not
1874 // get the updateRgn wide enough to always do so, so we do it from the parent
1875 // this would also be the place to draw any custom backgrounds for native controls
1876 // in Composited windowing
1877 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1881 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1883 child
= node
->GetData();
1886 if (child
== m_vScrollBar
)
1888 if (child
== m_hScrollBar
)
1890 if (child
->IsTopLevel())
1892 if (!child
->IsShown())
1895 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1897 child
->GetPosition( &x
, &y
);
1898 child
->GetSize( &w
, &h
);
1900 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
1902 // paint custom borders
1903 wxNcPaintEvent
eventNc( child
->GetId() );
1904 eventNc
.SetEventObject( child
);
1905 if ( !child
->HandleWindowEvent( eventNc
) )
1907 child
->MacPaintBorders(0, 0) ;
1914 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1916 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1917 return tlw
? tlw
->GetWXWindow() : NULL
;
1920 bool wxWindowMac::MacHasScrollBarCorner() const
1922 /* Returns whether the scroll bars in a wxScrolledWindow should be
1923 * shortened. Scroll bars should be shortened if either:
1925 * - both scroll bars are visible, or
1927 * - there is a resize box in the parent frame's corner and this
1928 * window shares the bottom and right edge with the parent
1932 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1935 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1936 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1938 // Both scroll bars visible
1943 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1945 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1947 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1950 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1952 // Parent frame has resize handle
1953 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1955 // Note: allow for some wiggle room here as wxMac's
1956 // window rect calculations seem to be imprecise
1957 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1958 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1960 // Parent frame has resize handle and shares
1961 // right bottom corner
1966 // Parent frame has resize handle but doesn't
1967 // share right bottom corner
1973 // Parent frame doesn't have resize handle
1979 // No parent frame found
1984 void wxWindowMac::MacCreateScrollBars( long style
)
1986 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1988 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1990 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1991 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1993 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1996 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
1998 GetClientSize( &width
, &height
) ;
2000 wxPoint
vPoint(width
- scrlsize
, 0) ;
2001 wxSize
vSize(scrlsize
, height
- adjust
) ;
2002 wxPoint
hPoint(0, height
- scrlsize
) ;
2003 wxSize
hSize(width
- adjust
, scrlsize
) ;
2005 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2006 if ( style
& wxVSCROLL
)
2008 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2009 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2012 if ( style
& wxHSCROLL
)
2014 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2015 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2019 // because the create does not take into account the client area origin
2020 // we might have a real position shift
2021 MacRepositionScrollBars() ;
2024 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2026 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2031 void wxWindowMac::MacRepositionScrollBars()
2033 if ( !m_hScrollBar
&& !m_vScrollBar
)
2036 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2037 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2039 // get real client area
2041 GetSize( &width
, &height
);
2043 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2044 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2046 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2047 wxSize
vSize( scrlsize
, height
- adjust
) ;
2048 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2049 wxSize
hSize( width
- adjust
, scrlsize
) ;
2052 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2054 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2057 bool wxWindowMac::AcceptsFocus() const
2059 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2062 void wxWindowMac::MacSuperChangedPosition()
2064 // only window-absolute structures have to be moved i.e. controls
2066 m_cachedClippedRectValid
= false ;
2069 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2072 child
= node
->GetData();
2073 child
->MacSuperChangedPosition() ;
2075 node
= node
->GetNext();
2079 void wxWindowMac::MacTopLevelWindowChangedPosition()
2081 // only screen-absolute structures have to be moved i.e. glcanvas
2084 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2087 child
= node
->GetData();
2088 child
->MacTopLevelWindowChangedPosition() ;
2090 node
= node
->GetNext();
2094 long wxWindowMac::MacGetLeftBorderSize() const
2101 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2103 #if wxOSX_USE_COCOA_OR_CARBON
2104 // this metric is only the 'outset' outside the simple frame rect
2105 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2111 else if (HasFlag(wxSIMPLE_BORDER
))
2113 #if wxOSX_USE_COCOA_OR_CARBON
2114 // this metric is only the 'outset' outside the simple frame rect
2115 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2125 long wxWindowMac::MacGetRightBorderSize() const
2127 // they are all symmetric in mac themes
2128 return MacGetLeftBorderSize() ;
2131 long wxWindowMac::MacGetTopBorderSize() const
2133 // they are all symmetric in mac themes
2134 return MacGetLeftBorderSize() ;
2137 long wxWindowMac::MacGetBottomBorderSize() const
2139 // they are all symmetric in mac themes
2140 return MacGetLeftBorderSize() ;
2143 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2145 return style
& ~wxBORDER_MASK
;
2148 // Find the wxWindowMac at the current mouse position, returning the mouse
2150 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2152 pt
= wxGetMousePosition();
2153 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2155 return (wxWindow
*) found
;
2158 // Get the current mouse position.
2159 wxPoint
wxGetMousePosition()
2163 wxGetMousePosition( &x
, &y
);
2165 return wxPoint(x
, y
);
2168 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2170 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2172 // copied from wxGTK : CS
2173 // VZ: shouldn't we move this to base class then?
2175 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2178 // (a) it's a command event and so is propagated to the parent
2179 // (b) under MSW it can be generated from kbd too
2180 // (c) it uses screen coords (because of (a))
2181 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2183 this->ClientToScreen(event
.GetPosition()));
2184 evtCtx
.SetEventObject(this);
2185 if ( ! HandleWindowEvent(evtCtx
) )
2194 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2198 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2202 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2203 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2208 bool wxWindowMac::OSXHandleClicked( double timestampsec
)
2213 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2215 #if wxOSX_USE_COCOA_OR_CARBON
2216 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2219 return eventNotHandledErr
;
2225 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2227 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2228 if ( !wxWindowBase::Reparent(newParent
) )
2231 m_peer
->RemoveFromParent();
2232 m_peer
->Embed( GetParent()->GetPeer() );
2236 bool wxWindowMac::SetTransparent(wxByte alpha
)
2238 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2240 if ( alpha
!= m_macAlpha
)
2242 m_macAlpha
= alpha
;
2249 bool wxWindowMac::CanSetTransparent()
2254 wxByte
wxWindowMac::GetTransparent() const
2259 bool wxWindowMac::IsShownOnScreen() const
2261 if ( m_peer
&& m_peer
->IsOk() )
2263 bool peerVis
= m_peer
->IsVisible();
2264 bool wxVis
= wxWindowBase::IsShownOnScreen();
2265 if( peerVis
!= wxVis
)
2267 // CS : put a breakpoint here to investigate differences
2268 // between native an wx visibilities
2269 // the only place where I've encountered them until now
2270 // are the hiding/showing sequences where the vis-changed event is
2271 // first sent to the innermost control, while wx does things
2272 // from the outmost control
2273 wxVis
= wxWindowBase::IsShownOnScreen();
2277 return m_peer
->IsVisible();
2279 return wxWindowBase::IsShownOnScreen();
2282 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2284 bool handled
= HandleWindowEvent( event
) ;
2285 if ( handled
&& event
.GetSkipped() )
2289 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2291 wxWindow
*ancestor
= this;
2294 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2297 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2299 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2300 handled
= handler
->ProcessEvent( command_event
);
2304 // accelerators can also be used with buttons, try them too
2305 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2306 handled
= handler
->ProcessEvent( command_event
);
2312 if (ancestor
->IsTopLevel())
2315 ancestor
= ancestor
->GetParent();
2318 #endif // wxUSE_ACCEL
2327 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2329 static MacControlMap wxWinMacControlList
;
2331 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2333 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2335 return impl
->GetWXPeer();
2340 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2342 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2344 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2347 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2349 // adding NULL ControlRef is (first) surely a result of an error and
2350 // (secondly) breaks native event processing
2351 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2353 wxWinMacControlList
[inControl
] = impl
;
2356 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2358 // iterate over all the elements in the class
2359 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2360 // we should go on...
2366 MacControlMap::iterator it
;
2367 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2369 if ( it
->second
== impl
)
2371 wxWinMacControlList
.erase(it
);
2379 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2381 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2384 m_isRootControl
= isRootControl
;
2388 wxWidgetImpl::wxWidgetImpl()
2393 wxWidgetImpl::~wxWidgetImpl()
2397 void wxWidgetImpl::Init()
2399 m_isRootControl
= false;
2401 m_needsFocusRect
= false;
2404 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2406 m_needsFocusRect
= needs
;
2409 bool wxWidgetImpl::NeedsFocusRect() const
2411 return m_needsFocusRect
;