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(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
);
311 // we will get that from the settings later
312 // and make this NORMAL later, but first
313 // we have a few calculations that we must fix
317 case wxWINDOW_VARIANT_NORMAL
:
318 size
= kControlSizeNormal
;
321 case wxWINDOW_VARIANT_SMALL
:
322 size
= kControlSizeSmall
;
325 case wxWINDOW_VARIANT_MINI
:
326 // not always defined in the headers
330 case wxWINDOW_VARIANT_LARGE
:
331 size
= kControlSizeLarge
;
335 wxFAIL_MSG(_T("unexpected window variant"));
338 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
341 #if wxOSX_USE_COCOA_OR_CARBON
344 #if wxOSX_USE_ATSU_TEXT
345 ThemeFontID themeFont
= kThemeSystemFont
;
347 // we will get that from the settings later
348 // and make this NORMAL later, but first
349 // we have a few calculations that we must fix
353 case wxWINDOW_VARIANT_NORMAL
:
354 themeFont
= kThemeSystemFont
;
357 case wxWINDOW_VARIANT_SMALL
:
358 themeFont
= kThemeSmallSystemFont
;
361 case wxWINDOW_VARIANT_MINI
:
362 // not always defined in the headers
366 case wxWINDOW_VARIANT_LARGE
:
367 themeFont
= kThemeSystemFont
;
371 wxFAIL_MSG(_T("unexpected window variant"));
375 font
.MacCreateFromThemeFont( themeFont
) ;
377 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
380 case wxWINDOW_VARIANT_NORMAL
:
381 themeFont
= kCTFontSystemFontType
;
384 case wxWINDOW_VARIANT_SMALL
:
385 themeFont
= kCTFontSmallSystemFontType
;
388 case wxWINDOW_VARIANT_MINI
:
389 themeFont
= kCTFontMiniSystemFontType
;
392 case wxWINDOW_VARIANT_LARGE
:
393 themeFont
= kCTFontSystemFontType
;
397 wxFAIL_MSG(_T("unexpected window variant"));
400 font
.MacCreateFromUIFont( themeFont
) ;
407 void wxWindowMac
::MacUpdateControlFont()
410 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
412 // do not trigger refreshes upon invisible and possible partly created objects
413 if ( IsShownOnScreen() )
417 bool wxWindowMac
::SetFont(const wxFont
& font
)
419 bool retval
= wxWindowBase
::SetFont( font
);
421 MacUpdateControlFont() ;
426 bool wxWindowMac
::SetForegroundColour(const wxColour
& col
)
428 bool retval
= wxWindowBase
::SetForegroundColour( col
);
431 MacUpdateControlFont();
436 bool wxWindowMac
::SetBackgroundColour(const wxColour
& col
)
438 if ( !wxWindowBase
::SetBackgroundColour(col
) && m_hasBgCol
)
442 m_peer
->SetBackgroundColour( col
) ;
447 void wxWindowMac
::SetFocus()
449 if ( !AcceptsFocus() )
452 wxWindow
* former
= FindFocus() ;
453 if ( former
== this )
459 void wxWindowMac
::DoCaptureMouse()
461 wxApp
::s_captureWindow
= (wxWindow
*) this ;
462 m_peer
->CaptureMouse() ;
465 wxWindow
* wxWindowBase
::GetCapture()
467 return wxApp
::s_captureWindow
;
470 void wxWindowMac
::DoReleaseMouse()
472 wxApp
::s_captureWindow
= NULL
;
474 m_peer
->ReleaseMouse() ;
477 #if wxUSE_DRAG_AND_DROP
479 void wxWindowMac
::SetDropTarget(wxDropTarget
*pDropTarget
)
483 m_dropTarget
= pDropTarget
;
484 if ( m_dropTarget
!= NULL
)
492 // Old-style File Manager Drag & Drop
493 void wxWindowMac
::DragAcceptFiles(bool WXUNUSED(accept
))
498 // From a wx position / size calculate the appropriate size of the native control
500 bool wxWindowMac
::MacGetBoundsForControl(
504 int& w
, int& h
, bool adjustOrigin
) const
506 // the desired size, minus the border pixels gives the correct size of the control
510 w
= WidthDefault( size
.x
);
511 h
= HeightDefault( size
.y
);
513 x
+= MacGetLeftBorderSize() ;
514 y
+= MacGetTopBorderSize() ;
515 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
516 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
519 AdjustForParentClientOrigin( x
, y
) ;
521 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
522 if ( GetParent() && !GetParent()->IsTopLevel() )
524 x
-= GetParent()->MacGetLeftBorderSize() ;
525 y
-= GetParent()->MacGetTopBorderSize() ;
531 // Get window size (not client size)
532 void wxWindowMac
::DoGetSize(int *x
, int *y
) const
535 m_peer
->GetSize( width
, height
);
538 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
540 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
543 // get the position of the bounds of this window in client coordinates of its parent
544 void wxWindowMac
::DoGetPosition(int *x
, int *y
) const
548 m_peer
->GetPosition( x1
, y1
) ;
550 // get the wx window position from the native one
551 x1
-= MacGetLeftBorderSize() ;
552 y1
-= MacGetTopBorderSize() ;
556 wxWindow
*parent
= GetParent();
559 // we must first adjust it to be in window coordinates of the parent,
560 // as otherwise it gets lost by the ClientAreaOrigin fix
561 x1
+= parent
->MacGetLeftBorderSize() ;
562 y1
+= parent
->MacGetTopBorderSize() ;
564 // and now to client coordinates
565 wxPoint
pt(parent
->GetClientAreaOrigin());
577 void wxWindowMac
::DoScreenToClient(int *x
, int *y
) const
579 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
580 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
581 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
582 MacRootWindowToWindow( x
, y
) ;
584 wxPoint origin
= GetClientAreaOrigin() ;
591 void wxWindowMac
::DoClientToScreen(int *x
, int *y
) const
593 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
594 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
596 wxPoint origin
= GetClientAreaOrigin() ;
602 MacWindowToRootWindow( x
, y
) ;
603 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
606 void wxWindowMac
::MacClientToRootWindow( int *x
, int *y
) const
608 wxPoint origin
= GetClientAreaOrigin() ;
614 MacWindowToRootWindow( x
, y
) ;
617 void wxWindowMac
::MacWindowToRootWindow( int *x
, int *y
) const
628 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
631 pt
.x
-= MacGetLeftBorderSize() ;
632 pt
.y
-= MacGetTopBorderSize() ;
633 wxWidgetImpl
::Convert( &pt
, m_peer
, top
->m_peer
) ;
643 void wxWindowMac
::MacRootWindowToWindow( int *x
, int *y
) const
654 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
657 wxWidgetImpl
::Convert( &pt
, top
->m_peer
, m_peer
) ;
658 pt
.x
+= MacGetLeftBorderSize() ;
659 pt
.y
+= MacGetTopBorderSize() ;
669 wxSize wxWindowMac
::DoGetSizeFromClientSize( const wxSize
& size
) const
671 wxSize sizeTotal
= size
;
673 int innerwidth
, innerheight
;
675 int outerwidth
, outerheight
;
677 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
678 m_peer
->GetSize( outerwidth
, outerheight
);
680 sizeTotal
.x
+= outerwidth
-innerwidth
;
681 sizeTotal
.y
+= outerheight
-innerheight
;
683 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
684 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
689 // Get size *available for subwindows* i.e. excluding menu bar etc.
690 void wxWindowMac
::DoGetClientSize( int *x
, int *y
) const
696 m_peer
->GetContentArea( left
, top
, ww
, hh
);
698 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
699 hh
-= m_hScrollBar
->GetSize().y
;
701 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
702 ww
-= m_vScrollBar
->GetSize().x
;
710 bool wxWindowMac
::SetCursor(const wxCursor
& cursor
)
712 if (m_cursor
.IsSameAs(cursor
))
717 if ( ! wxWindowBase
::SetCursor( *wxSTANDARD_CURSOR
) )
722 if ( ! wxWindowBase
::SetCursor( cursor
) )
726 wxASSERT_MSG( m_cursor
.Ok(),
727 wxT("cursor must be valid after call to the base version"));
729 if ( GetPeer() != NULL
)
730 GetPeer()->SetCursor( m_cursor
);
736 bool wxWindowMac
::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
738 #ifndef __WXUNIVERSAL__
739 menu
->SetInvokingWindow((wxWindow
*)this);
742 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
744 wxPoint mouse
= wxGetMousePosition();
750 ClientToScreen( &x
, &y
) ;
752 menu
->GetPeer()->PopUp(this, x
, y
);
753 menu
->SetInvokingWindow( NULL
);
756 // actually this shouldn't be called, because universal is having its own implementation
762 // ----------------------------------------------------------------------------
764 // ----------------------------------------------------------------------------
768 void wxWindowMac
::DoSetToolTip(wxToolTip
*tooltip
)
770 wxWindowBase
::DoSetToolTip(tooltip
);
773 m_tooltip
->SetWindow(this);
778 void wxWindowMac
::MacInvalidateBorders()
780 if ( m_peer
== NULL
)
783 bool vis
= IsShownOnScreen() ;
787 int outerBorder
= MacGetLeftBorderSize() ;
789 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
793 if ( outerBorder
== 0 )
796 // now we know that we have something to do at all
801 m_peer
->GetSize( tw
, th
);
802 m_peer
->GetPosition( tx
, ty
);
804 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
805 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
806 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
807 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
810 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
811 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
812 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
813 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
817 void wxWindowMac
::DoMoveWindow(int x
, int y
, int width
, int height
)
819 // this is never called for a toplevel window, so we know we have a parent
820 int former_x
, former_y
, former_w
, former_h
;
822 // Get true coordinates of former position
823 DoGetPosition( &former_x
, &former_y
) ;
824 DoGetSize( &former_w
, &former_h
) ;
826 wxWindow
*parent
= GetParent();
829 wxPoint
pt(parent
->GetClientAreaOrigin());
834 int actualWidth
= width
;
835 int actualHeight
= height
;
839 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
840 actualWidth
= m_minWidth
;
841 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
842 actualHeight
= m_minHeight
;
843 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
844 actualWidth
= m_maxWidth
;
845 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
846 actualHeight
= m_maxHeight
;
848 bool doMove
= false, doResize
= false ;
850 if ( actualX
!= former_x
|| actualY
!= former_y
)
853 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
856 if ( doMove
|| doResize
)
858 // as the borders are drawn outside the native control, we adjust now
860 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
861 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
862 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
864 if ( parent
&& !parent
->IsTopLevel() )
866 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
869 MacInvalidateBorders() ;
871 m_cachedClippedRectValid
= false ;
873 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
875 wxWindowMac
::MacSuperChangedPosition() ; // like this only children will be notified
877 MacInvalidateBorders() ;
879 MacRepositionScrollBars() ;
882 wxPoint
point(actualX
, actualY
);
883 wxMoveEvent
event(point
, m_windowId
);
884 event
.SetEventObject(this);
885 HandleWindowEvent(event
) ;
890 MacRepositionScrollBars() ;
891 wxSize
size(actualWidth
, actualHeight
);
892 wxSizeEvent
event(size
, m_windowId
);
893 event
.SetEventObject(this);
894 HandleWindowEvent(event
);
899 wxSize wxWindowMac
::DoGetBestSize() const
901 if ( m_macIsUserPane
|| IsTopLevel() )
903 return wxWindowBase
::DoGetBestSize() ;
909 m_peer
->GetBestRect(&r
);
911 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
918 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
923 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
930 // return wxWindowBase::DoGetBestSize() ;
934 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
935 MacGetRightBorderSize();
936 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
937 MacGetBottomBorderSize();
938 if ( bestHeight
< 10 )
941 return wxSize(bestWidth
, bestHeight
);
945 // set the size of the window: if the dimensions are positive, just use them,
946 // but if any of them is equal to -1, it means that we must find the value for
947 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
948 // which case -1 is a valid value for x and y)
950 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
951 // the width/height to best suit our contents, otherwise we reuse the current
953 void wxWindowMac
::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
955 // get the current size and position...
956 int currentX
, currentY
;
957 int currentW
, currentH
;
959 GetPosition(¤tX
, ¤tY
);
960 GetSize(¤tW
, ¤tH
);
962 // ... and don't do anything (avoiding flicker) if it's already ok
963 if ( x
== currentX
&& y
== currentY
&&
964 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
967 MacRepositionScrollBars() ; // we might have a real position shift
972 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
974 if ( x
== wxDefaultCoord
)
976 if ( y
== wxDefaultCoord
)
980 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
982 wxSize size
= wxDefaultSize
;
983 if ( width
== wxDefaultCoord
)
985 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
987 size
= DoGetBestSize();
992 // just take the current one
997 if ( height
== wxDefaultCoord
)
999 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1001 if ( size
.x
== wxDefaultCoord
)
1002 size
= DoGetBestSize();
1003 // else: already called DoGetBestSize() above
1009 // just take the current one
1014 DoMoveWindow( x
, y
, width
, height
);
1017 wxPoint wxWindowMac
::GetClientAreaOrigin() const
1019 int left
,top
,width
,height
;
1020 m_peer
->GetContentArea( left
, top
, width
, height
);
1021 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1024 void wxWindowMac
::DoSetClientSize(int clientwidth
, int clientheight
)
1026 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1028 int currentclientwidth
, currentclientheight
;
1029 int currentwidth
, currentheight
;
1031 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1032 GetSize( ¤twidth
, ¤theight
) ;
1034 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1035 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1039 void wxWindowMac
::SetLabel(const wxString
& title
)
1043 if ( m_peer
&& m_peer
->IsOk() )
1044 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1046 // do not trigger refreshes upon invisible and possible partly created objects
1047 if ( IsShownOnScreen() )
1051 wxString wxWindowMac
::GetLabel() const
1056 bool wxWindowMac
::Show(bool show
)
1058 if ( !wxWindowBase
::Show(show
) )
1062 m_peer
->SetVisibility( show
) ;
1067 void wxWindowMac
::DoEnable(bool enable
)
1069 m_peer
->Enable( enable
) ;
1073 // status change notifications
1076 void wxWindowMac
::MacVisibilityChanged()
1080 void wxWindowMac
::MacHiliteChanged()
1084 void wxWindowMac
::MacEnabledStateChanged()
1086 OnEnabled( m_peer
->IsEnabled() );
1090 // status queries on the inherited window's state
1093 bool wxWindowMac
::MacIsReallyEnabled()
1095 return m_peer
->IsEnabled() ;
1098 bool wxWindowMac
::MacIsReallyHilited()
1100 #if wxOSX_USE_CARBON
1101 return m_peer
->IsActive();
1103 return true; // TODO
1107 int wxWindowMac
::GetCharHeight() const
1110 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1115 int wxWindowMac
::GetCharWidth() const
1118 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1123 void wxWindowMac
::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1124 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1126 const wxFont
*fontToUse
= theFont
;
1130 tempFont
= GetFont();
1131 fontToUse
= &tempFont
;
1134 wxGraphicsContext
* ctx
= wxGraphicsContext
::Create();
1135 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1137 wxDouble h
, d
, e
, w
;
1138 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1142 if ( externalLeading
)
1143 *externalLeading
= (wxCoord
)(e
+0.5);
1145 *descent
= (wxCoord
)(d
+0.5);
1147 *x
= (wxCoord
)(w
+0.5);
1149 *y
= (wxCoord
)(h
+0.5);
1153 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1154 * we always intersect with the entire window, not only with the client area
1157 void wxWindowMac
::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1159 if ( m_peer
== NULL
)
1162 if ( !IsShownOnScreen() )
1165 m_peer
->SetNeedsDisplay( rect
) ;
1168 void wxWindowMac
::DoFreeze()
1170 #if wxOSX_USE_CARBON
1171 if ( m_peer
&& m_peer
->IsOk() )
1172 m_peer
->SetDrawingEnabled( false ) ;
1176 void wxWindowMac
::DoThaw()
1178 #if wxOSX_USE_CARBON
1179 if ( m_peer
&& m_peer
->IsOk() )
1181 m_peer
->SetDrawingEnabled( true ) ;
1182 m_peer
->InvalidateWithChildren() ;
1187 wxWindow
*wxGetActiveWindow()
1189 // actually this is a windows-only concept
1193 // Coordinates relative to the window
1194 void wxWindowMac
::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1196 // We really don't move the mouse programmatically under Mac.
1199 void wxWindowMac
::OnEraseBackground(wxEraseEvent
& event
)
1201 if ( MacGetTopLevelWindow() == NULL
)
1204 #if TARGET_API_MAC_OSX
1205 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1211 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1213 event
.GetDC()->Clear() ;
1215 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1217 // don't skip the event here, custom background means that the app
1218 // is drawing it itself in its OnPaint(), so don't draw it at all
1219 // now to avoid flicker
1227 void wxWindowMac
::OnNcPaint( wxNcPaintEvent
& event
)
1232 int wxWindowMac
::GetScrollPos(int orient
) const
1234 if ( orient
== wxHORIZONTAL
)
1237 return m_hScrollBar
->GetThumbPosition() ;
1242 return m_vScrollBar
->GetThumbPosition() ;
1248 // This now returns the whole range, not just the number
1249 // of positions that we can scroll.
1250 int wxWindowMac
::GetScrollRange(int orient
) const
1252 if ( orient
== wxHORIZONTAL
)
1255 return m_hScrollBar
->GetRange() ;
1260 return m_vScrollBar
->GetRange() ;
1266 int wxWindowMac
::GetScrollThumb(int orient
) const
1268 if ( orient
== wxHORIZONTAL
)
1271 return m_hScrollBar
->GetThumbSize() ;
1276 return m_vScrollBar
->GetThumbSize() ;
1282 void wxWindowMac
::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1284 if ( orient
== wxHORIZONTAL
)
1287 m_hScrollBar
->SetThumbPosition( pos
) ;
1292 m_vScrollBar
->SetThumbPosition( pos
) ;
1297 wxWindowMac
::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1299 bool needVisibilityUpdate
= false;
1301 if ( m_hScrollBarAlwaysShown
!= hflag
)
1303 m_hScrollBarAlwaysShown
= hflag
;
1304 needVisibilityUpdate
= true;
1307 if ( m_vScrollBarAlwaysShown
!= vflag
)
1309 m_vScrollBarAlwaysShown
= vflag
;
1310 needVisibilityUpdate
= true;
1313 if ( needVisibilityUpdate
)
1314 DoUpdateScrollbarVisibility();
1318 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1319 // our own window origin is at leftOrigin/rightOrigin
1322 void wxWindowMac
::MacPaintGrowBox()
1327 if ( MacHasScrollBarCorner() )
1329 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1330 wxASSERT( cgContext
) ;
1334 m_peer
->GetSize( tw
, th
);
1335 m_peer
->GetPosition( tx
, ty
);
1337 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1340 int size
= m_hScrollBar ? m_hScrollBar
->GetSize().y
: ( m_vScrollBar ? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1341 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1342 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1343 CGContextSaveGState( cgContext
);
1345 if ( m_backgroundColour
.Ok() )
1347 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1351 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1353 CGContextFillRect( cgContext
, cgrect
);
1354 CGContextRestoreGState( cgContext
);
1358 void wxWindowMac
::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1363 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1365 // back to the surrounding frame rectangle
1368 m_peer
->GetSize( tw
, th
);
1369 m_peer
->GetPosition( tx
, ty
);
1371 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1373 #if wxOSX_USE_COCOA_OR_CARBON
1375 InsetRect( &rect
, -1 , -1 ) ;
1378 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1379 rect
.bottom
- rect
.top
) ;
1381 HIThemeFrameDrawInfo info
;
1382 memset( &info
, 0 , sizeof(info
) ) ;
1386 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1387 info
.isFocused
= hasFocus
;
1389 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1390 wxASSERT( cgContext
) ;
1392 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1394 info
.kind
= kHIThemeFrameTextFieldSquare
;
1395 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1397 else if ( HasFlag(wxSIMPLE_BORDER
) )
1399 info
.kind
= kHIThemeFrameListBox
;
1400 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1402 else if ( hasFocus
)
1404 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1406 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1407 m_peer
->GetRect( &rect
) ;
1408 if ( MacHasScrollBarCorner() )
1410 int variant
= (m_hScrollBar
== NULL ? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1411 int size
= m_hScrollBar ? m_hScrollBar
->GetSize().y
: ( m_vScrollBar ? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1412 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1413 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1414 HIThemeGrowBoxDrawInfo info
;
1415 memset( &info
, 0, sizeof(info
) ) ;
1417 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1418 info
.kind
= kHIThemeGrowBoxKindNone
;
1419 // contrary to the docs ...SizeSmall does not work
1420 info
.size
= kHIThemeGrowBoxSizeNormal
;
1421 info
.direction
= 0 ;
1422 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1426 #endif // wxOSX_USE_COCOA_OR_CARBON
1429 void wxWindowMac
::RemoveChild( wxWindowBase
*child
)
1431 if ( child
== m_hScrollBar
)
1432 m_hScrollBar
= NULL
;
1433 if ( child
== m_vScrollBar
)
1434 m_vScrollBar
= NULL
;
1436 wxWindowBase
::RemoveChild( child
) ;
1439 void wxWindowMac
::DoUpdateScrollbarVisibility()
1441 bool triggerSizeEvent
= false;
1445 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1447 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1449 m_hScrollBar
->Show( showHScrollBar
);
1450 triggerSizeEvent
= true;
1456 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1458 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1460 m_vScrollBar
->Show( showVScrollBar
) ;
1461 triggerSizeEvent
= true;
1465 MacRepositionScrollBars() ;
1466 if ( triggerSizeEvent
)
1468 wxSizeEvent
event(GetSize(), m_windowId
);
1469 event
.SetEventObject(this);
1470 HandleWindowEvent(event
);
1474 // New function that will replace some of the above.
1475 void wxWindowMac
::SetScrollbar(int orient
, int pos
, int thumb
,
1476 int range
, bool refresh
)
1478 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1479 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1480 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1481 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1483 DoUpdateScrollbarVisibility();
1486 // Does a physical scroll
1487 void wxWindowMac
::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1489 if ( dx
== 0 && dy
== 0 )
1492 int width
, height
;
1493 GetClientSize( &width
, &height
) ;
1496 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1498 scrollrect
.Intersect( *rect
) ;
1499 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1500 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1502 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1507 for (wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1509 child
= node
->GetData();
1512 if (child
== m_vScrollBar
)
1514 if (child
== m_hScrollBar
)
1516 if (child
->IsTopLevel())
1519 child
->GetPosition( &x
, &y
);
1520 child
->GetSize( &w
, &h
);
1523 wxRect
rc( x
, y
, w
, h
);
1524 if (rect
->Intersects( rc
))
1525 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1529 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1534 void wxWindowMac
::MacOnScroll( wxScrollEvent
&event
)
1536 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1538 wxScrollWinEvent wevent
;
1539 wevent
.SetPosition(event
.GetPosition());
1540 wevent
.SetOrientation(event
.GetOrientation());
1541 wevent
.SetEventObject(this);
1543 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1544 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1545 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1546 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1547 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1548 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1549 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1550 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1551 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1552 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1553 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1554 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1555 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1556 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1557 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1558 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1560 HandleWindowEvent(wevent
);
1564 // Get the window with the focus
1565 wxWindow
*wxWindowBase
::DoFindFocus()
1567 #if wxOSX_USE_CARBON
1568 ControlRef control
;
1569 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1570 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1576 void wxWindowMac
::OnInternalIdle()
1578 // This calls the UI-update mechanism (querying windows for
1579 // menu/toolbar/control state information)
1580 if (wxUpdateUIEvent
::CanUpdate(this) && IsShownOnScreen())
1581 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1584 // Raise the window to the top of the Z order
1585 void wxWindowMac
::Raise()
1590 // Lower the window to the bottom of the Z order
1591 void wxWindowMac
::Lower()
1596 // static wxWindow *gs_lastWhich = NULL;
1598 bool wxWindowMac
::MacSetupCursor( const wxPoint
& pt
)
1600 // first trigger a set cursor event
1602 wxPoint clientorigin
= GetClientAreaOrigin() ;
1603 wxSize clientsize
= GetClientSize() ;
1605 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1607 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1609 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1610 if ( processedEvtSetCursor
&& event
.HasCursor() )
1612 cursor
= event
.GetCursor() ;
1616 // the test for processedEvtSetCursor is here to prevent using m_cursor
1617 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1618 // it - this is a way to say that our cursor shouldn't be used for this
1620 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1623 if ( !wxIsBusy() && !GetParent() )
1624 cursor
= *wxSTANDARD_CURSOR
;
1628 cursor
.MacInstall() ;
1631 return cursor
.Ok() ;
1634 wxString wxWindowMac
::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1638 return m_tooltip
->GetTip() ;
1641 return wxEmptyString
;
1644 void wxWindowMac
::ClearBackground()
1650 void wxWindowMac
::Update()
1652 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1657 wxNonOwnedWindow
* wxWindowMac
::MacGetTopLevelWindow() const
1659 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1663 if ( iter
->IsTopLevel() )
1665 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1669 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1674 iter
= iter
->GetParent() ;
1680 const wxRect
& wxWindowMac
::MacGetClippedClientRect() const
1682 MacUpdateClippedRects() ;
1684 return m_cachedClippedClientRect
;
1687 const wxRect
& wxWindowMac
::MacGetClippedRect() const
1689 MacUpdateClippedRects() ;
1691 return m_cachedClippedRect
;
1694 const wxRect
&wxWindowMac
:: MacGetClippedRectWithOuterStructure() const
1696 MacUpdateClippedRects() ;
1698 return m_cachedClippedRectWithOuterStructure
;
1701 const wxRegion
& wxWindowMac
::MacGetVisibleRegion( bool includeOuterStructures
)
1703 static wxRegion emptyrgn
;
1705 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1707 MacUpdateClippedRects() ;
1708 if ( includeOuterStructures
)
1709 return m_cachedClippedRegionWithOuterStructure
;
1711 return m_cachedClippedRegion
;
1719 void wxWindowMac
::MacUpdateClippedRects() const
1721 #if wxOSX_USE_CARBON
1722 if ( m_cachedClippedRectValid
)
1725 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1726 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1727 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1728 // to add focus borders everywhere
1730 Rect rIncludingOuterStructures
;
1734 m_peer
->GetSize( tw
, th
);
1735 m_peer
->GetPosition( tx
, ty
);
1737 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1739 r
.left
-= MacGetLeftBorderSize() ;
1740 r
.top
-= MacGetTopBorderSize() ;
1741 r
.bottom
+= MacGetBottomBorderSize() ;
1742 r
.right
+= MacGetRightBorderSize() ;
1749 rIncludingOuterStructures
= r
;
1750 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1752 wxRect cl
= GetClientRect() ;
1753 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1757 const wxWindow
* child
= (wxWindow
*) this ;
1758 const wxWindow
* parent
= NULL
;
1760 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1762 if ( parent
->MacIsChildOfClientArea(child
) )
1764 size
= parent
->GetClientSize() ;
1765 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1771 // this will be true for scrollbars, toolbars etc.
1772 size
= parent
->GetSize() ;
1773 y
= parent
->MacGetTopBorderSize() ;
1774 x
= parent
->MacGetLeftBorderSize() ;
1775 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1776 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1779 parent
->MacWindowToRootWindow( &x
, &y
) ;
1780 MacRootWindowToWindow( &x
, &y
) ;
1782 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1784 // the wxwindow and client rects will always be clipped
1785 SectRect( &r
, &rparent
, &r
) ;
1786 SectRect( &rClient
, &rparent
, &rClient
) ;
1788 // the structure only at 'hard' borders
1789 if ( parent
->MacClipChildren() ||
1790 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1792 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1798 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1799 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1800 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1801 m_cachedClippedRectWithOuterStructure
= wxRect(
1802 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1803 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1804 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1806 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1807 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1808 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1810 m_cachedClippedRectValid
= true ;
1815 This function must not change the updatergn !
1817 bool wxWindowMac
::MacDoRedraw( void* updatergnr
, long time
)
1819 bool handled
= false ;
1820 #if wxOSX_USE_CARBON
1822 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1823 GetRegionBounds( updatergn
, &updatebounds
) ;
1825 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1827 if ( !EmptyRgn(updatergn
) )
1829 RgnHandle newupdate
= NewRgn() ;
1830 wxSize point
= GetClientSize() ;
1831 wxPoint origin
= GetClientAreaOrigin() ;
1832 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1833 SectRgn( newupdate
, updatergn
, newupdate
) ;
1835 // first send an erase event to the entire update area
1837 // for the toplevel window this really is the entire area
1838 // for all the others only their client area, otherwise they
1839 // might be drawing with full alpha and eg put blue into
1840 // the grow-box area of a scrolled window (scroll sample)
1841 wxDC
* dc
= new wxWindowDC(this);
1843 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1845 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1847 wxEraseEvent
eevent( GetId(), dc
);
1848 eevent
.SetEventObject( this );
1849 HandleWindowEvent( eevent
);
1855 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1856 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1857 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1858 DisposeRgn( newupdate
) ;
1860 if ( !m_updateRegion
.Empty() )
1862 // paint the window itself
1865 event
.SetTimestamp(time
);
1866 event
.SetEventObject(this);
1867 HandleWindowEvent(event
);
1871 // now we cannot rely on having its borders drawn by a window itself, as it does not
1872 // get the updateRgn wide enough to always do so, so we do it from the parent
1873 // this would also be the place to draw any custom backgrounds for native controls
1874 // in Composited windowing
1875 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1879 for (wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1881 child
= node
->GetData();
1884 if (child
== m_vScrollBar
)
1886 if (child
== m_hScrollBar
)
1888 if (child
->IsTopLevel())
1890 if (!child
->IsShown())
1893 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1895 child
->GetPosition( &x
, &y
);
1896 child
->GetSize( &w
, &h
);
1897 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1898 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1899 InsetRect( &childRect
, -10 , -10) ;
1901 if ( RectInRgn( &childRect
, updatergn
) )
1903 // paint custom borders
1904 wxNcPaintEvent
eventNc( child
->GetId() );
1905 eventNc
.SetEventObject( child
);
1906 if ( !child
->HandleWindowEvent( eventNc
) )
1908 child
->MacPaintBorders(0, 0) ;
1918 WXWindow wxWindowMac
::MacGetTopLevelWindowRef() const
1920 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1921 return tlw ? tlw
->GetWXWindow() : NULL
;
1924 bool wxWindowMac
::MacHasScrollBarCorner() const
1926 /* Returns whether the scroll bars in a wxScrolledWindow should be
1927 * shortened. Scroll bars should be shortened if either:
1929 * - both scroll bars are visible, or
1931 * - there is a resize box in the parent frame's corner and this
1932 * window shares the bottom and right edge with the parent
1936 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1939 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1940 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1942 // Both scroll bars visible
1947 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1949 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1951 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1954 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1956 // Parent frame has resize handle
1957 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1959 // Note: allow for some wiggle room here as wxMac's
1960 // window rect calculations seem to be imprecise
1961 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1962 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1964 // Parent frame has resize handle and shares
1965 // right bottom corner
1970 // Parent frame has resize handle but doesn't
1971 // share right bottom corner
1977 // Parent frame doesn't have resize handle
1983 // No parent frame found
1988 void wxWindowMac
::MacCreateScrollBars( long style
)
1990 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1992 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1994 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1995 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1997 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2000 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2002 GetClientSize( &width
, &height
) ;
2004 wxPoint
vPoint(width
- scrlsize
, 0) ;
2005 wxSize
vSize(scrlsize
, height
- adjust
) ;
2006 wxPoint
hPoint(0, height
- scrlsize
) ;
2007 wxSize
hSize(width
- adjust
, scrlsize
) ;
2009 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2010 if ( style
& wxVSCROLL
)
2012 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2013 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2016 if ( style
& wxHSCROLL
)
2018 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2019 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2023 // because the create does not take into account the client area origin
2024 // we might have a real position shift
2025 MacRepositionScrollBars() ;
2028 bool wxWindowMac
::MacIsChildOfClientArea( const wxWindow
* child
) const
2030 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2035 void wxWindowMac
::MacRepositionScrollBars()
2037 if ( !m_hScrollBar
&& !m_vScrollBar
)
2040 int scrlsize
= m_hScrollBar ? m_hScrollBar
->GetSize().y
: ( m_vScrollBar ? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2041 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2043 // get real client area
2045 GetSize( &width
, &height
);
2047 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2048 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2050 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2051 wxSize
vSize( scrlsize
, height
- adjust
) ;
2052 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2053 wxSize
hSize( width
- adjust
, scrlsize
) ;
2056 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2058 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2061 bool wxWindowMac
::AcceptsFocus() const
2063 return m_peer
->CanFocus() && wxWindowBase
::AcceptsFocus();
2066 void wxWindowMac
::MacSuperChangedPosition()
2068 // only window-absolute structures have to be moved i.e. controls
2070 m_cachedClippedRectValid
= false ;
2073 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2076 child
= node
->GetData();
2077 child
->MacSuperChangedPosition() ;
2079 node
= node
->GetNext();
2083 void wxWindowMac
::MacTopLevelWindowChangedPosition()
2085 // only screen-absolute structures have to be moved i.e. glcanvas
2088 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2091 child
= node
->GetData();
2092 child
->MacTopLevelWindowChangedPosition() ;
2094 node
= node
->GetNext();
2098 long wxWindowMac
::MacGetLeftBorderSize() const
2105 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2107 #if wxOSX_USE_COCOA_OR_CARBON
2108 // this metric is only the 'outset' outside the simple frame rect
2109 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2115 else if (HasFlag(wxSIMPLE_BORDER
))
2117 #if wxOSX_USE_COCOA_OR_CARBON
2118 // this metric is only the 'outset' outside the simple frame rect
2119 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2129 long wxWindowMac
::MacGetRightBorderSize() const
2131 // they are all symmetric in mac themes
2132 return MacGetLeftBorderSize() ;
2135 long wxWindowMac
::MacGetTopBorderSize() const
2137 // they are all symmetric in mac themes
2138 return MacGetLeftBorderSize() ;
2141 long wxWindowMac
::MacGetBottomBorderSize() const
2143 // they are all symmetric in mac themes
2144 return MacGetLeftBorderSize() ;
2147 long wxWindowMac
::MacRemoveBordersFromStyle( long style
)
2149 return style
& ~wxBORDER_MASK
;
2152 // Find the wxWindowMac at the current mouse position, returning the mouse
2154 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2156 pt
= wxGetMousePosition();
2157 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2159 return (wxWindow
*) found
;
2162 // Get the current mouse position.
2163 wxPoint
wxGetMousePosition()
2167 wxGetMousePosition( &x
, &y
);
2169 return wxPoint(x
, y
);
2172 void wxWindowMac
::OnMouseEvent( wxMouseEvent
&event
)
2174 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2176 // copied from wxGTK : CS
2177 // VZ: shouldn't we move this to base class then?
2179 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2182 // (a) it's a command event and so is propagated to the parent
2183 // (b) under MSW it can be generated from kbd too
2184 // (c) it uses screen coords (because of (a))
2185 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2187 this->ClientToScreen(event
.GetPosition()));
2188 evtCtx
.SetEventObject(this);
2189 if ( ! HandleWindowEvent(evtCtx
) )
2198 void wxWindowMac
::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2200 #if wxOSX_USE_COCOA_OR_CARBON
2201 // for native controls: call their native paint method
2202 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2204 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2205 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2206 CallNextEventHandler(
2207 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2208 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2213 void wxWindowMac
::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2217 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2221 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2222 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2227 bool wxWindowMac
::HandleClicked( double timestampsec
)
2232 wxInt32 wxWindowMac
::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2234 #if wxOSX_USE_COCOA_OR_CARBON
2235 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2238 return eventNotHandledErr
;
2244 bool wxWindowMac
::Reparent(wxWindowBase
*newParentBase
)
2246 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2247 if ( !wxWindowBase
::Reparent(newParent
) )
2250 m_peer
->RemoveFromParent();
2251 m_peer
->Embed( GetParent()->GetPeer() );
2255 bool wxWindowMac
::SetTransparent(wxByte alpha
)
2257 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2259 if ( alpha
!= m_macAlpha
)
2261 m_macAlpha
= alpha
;
2268 bool wxWindowMac
::CanSetTransparent()
2273 wxByte wxWindowMac
::GetTransparent() const
2278 bool wxWindowMac
::IsShownOnScreen() const
2280 if ( m_peer
&& m_peer
->IsOk() )
2282 bool peerVis
= m_peer
->IsVisible();
2283 bool wxVis
= wxWindowBase
::IsShownOnScreen();
2284 if( peerVis
!= wxVis
)
2286 // CS : put a breakpoint here to investigate differences
2287 // between native an wx visibilities
2288 // the only place where I've encountered them until now
2289 // are the hiding/showing sequences where the vis-changed event is
2290 // first sent to the innermost control, while wx does things
2291 // from the outmost control
2292 wxVis
= wxWindowBase
::IsShownOnScreen();
2296 return m_peer
->IsVisible();
2298 return wxWindowBase
::IsShownOnScreen();
2301 bool wxWindowMac
::HandleKeyEvent( wxKeyEvent
& event
)
2303 bool handled
= HandleWindowEvent( event
) ;
2304 if ( handled
&& event
.GetSkipped() )
2308 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2310 wxWindow
*ancestor
= this;
2313 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2316 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2318 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2319 handled
= handler
->ProcessEvent( command_event
);
2323 // accelerators can also be used with buttons, try them too
2324 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2325 handled
= handler
->ProcessEvent( command_event
);
2331 if (ancestor
->IsTopLevel())
2334 ancestor
= ancestor
->GetParent();
2337 #endif // wxUSE_ACCEL
2346 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2348 static MacControlMap wxWinMacControlList
;
2350 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2352 wxWidgetImpl
* impl
= wxWidgetImpl
::FindFromWXWidget( inControl
);
2354 return impl
->GetWXPeer();
2359 wxWidgetImpl
*wxWidgetImpl
::FindFromWXWidget(WXWidget inControl
)
2361 MacControlMap
::iterator node
= wxWinMacControlList
.find(inControl
);
2363 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2366 void wxWidgetImpl
::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2368 // adding NULL ControlRef is (first) surely a result of an error and
2369 // (secondly) breaks native event processing
2370 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2372 wxWinMacControlList
[inControl
] = impl
;
2375 void wxWidgetImpl
::RemoveAssociations(wxWidgetImpl
* impl
)
2377 // iterate over all the elements in the class
2378 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2379 // we should go on...
2385 MacControlMap
::iterator it
;
2386 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2388 if ( it
->second
== impl
)
2390 wxWinMacControlList
.erase(it
);
2398 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2400 wxWidgetImpl
::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2403 m_isRootControl
= isRootControl
;
2407 wxWidgetImpl
::wxWidgetImpl()
2412 wxWidgetImpl
::~wxWidgetImpl()
2416 void wxWidgetImpl
::Init()
2418 m_isRootControl
= false;
2420 m_needsFocusRect
= false;
2423 void wxWidgetImpl
::SetNeedsFocusRect( bool needs
)
2425 m_needsFocusRect
= needs
;
2428 bool wxWidgetImpl
::NeedsFocusRect() const
2430 return m_needsFocusRect
;