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 MacInvalidateBorders() ;
146 #ifndef __WXUNIVERSAL__
147 // VS: make sure there's no wxFrame with last focus set to us:
148 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
150 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
153 if ( frame
->GetLastFocus() == this )
154 frame
->SetLastFocus(NULL
);
160 // destroy children before destroying this window itself
163 // wxRemoveMacControlAssociation( this ) ;
164 // If we delete an item, we should initialize the parent panel,
165 // because it could now be invalid.
166 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
169 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
170 tlw
->SetDefaultItem(NULL
);
173 if ( g_MacLastWindow
== this )
174 g_MacLastWindow
= NULL
;
176 #ifndef __WXUNIVERSAL__
177 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
180 if ( frame
->GetLastFocus() == this )
181 frame
->SetLastFocus( NULL
) ;
185 // delete our drop target if we've got one
186 #if wxUSE_DRAG_AND_DROP
187 if ( m_dropTarget
!= NULL
)
197 WXWidget
wxWindowMac::GetHandle() const
199 return (WXWidget
) m_peer
->GetWXWidget() ;
203 // TODO END move to window_osx.cpp
206 // ---------------------------------------------------------------------------
207 // Utility Routines to move between different coordinate systems
208 // ---------------------------------------------------------------------------
211 * Right now we have the following setup :
212 * a border that is not part of the native control is always outside the
213 * control's border (otherwise we loose all native intelligence, future ways
214 * may be to have a second embedding control responsible for drawing borders
215 * and backgrounds eventually)
216 * so all this border calculations have to be taken into account when calling
217 * native methods or getting native oriented data
218 * so we have three coordinate systems here
219 * wx client coordinates
220 * wx window coordinates (including window frames)
228 bool wxWindowMac::Create(wxWindowMac
*parent
,
233 const wxString
& name
)
235 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
237 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
240 m_windowVariant
= parent
->GetWindowVariant() ;
242 if ( m_macIsUserPane
)
244 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
245 MacPostControlCreate(pos
, size
) ;
248 #ifndef __WXUNIVERSAL__
249 // Don't give scrollbars to wxControls unless they ask for them
250 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
251 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
253 MacCreateScrollBars( style
) ;
257 wxWindowCreateEvent
event((wxWindow
*)this);
258 GetEventHandler()->AddPendingEvent(event
);
263 void wxWindowMac::MacChildAdded()
266 m_vScrollBar
->Raise() ;
268 m_hScrollBar
->Raise() ;
271 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
273 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
275 GetParent()->AddChild( this );
277 m_peer
->InstallEventHandler();
278 m_peer
->Embed(GetParent()->GetPeer());
280 GetParent()->MacChildAdded() ;
282 // adjust font, controlsize etc
283 DoSetWindowVariant( m_windowVariant
) ;
285 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
287 // for controls we want to use best size for wxDefaultSize params )
288 if ( !m_macIsUserPane
)
289 SetInitialSize(size
);
291 SetCursor( *wxSTANDARD_CURSOR
) ;
294 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
296 // Don't assert, in case we set the window variant before
297 // the window is created
298 // wxASSERT( m_peer->Ok() ) ;
300 m_windowVariant
= variant
;
302 if (m_peer
== NULL
|| !m_peer
->IsOk())
305 m_peer
->SetControlSize( variant
);
309 // we will get that from the settings later
310 // and make this NORMAL later, but first
311 // we have a few calculations that we must fix
315 case wxWINDOW_VARIANT_NORMAL
:
316 size
= kControlSizeNormal
;
319 case wxWINDOW_VARIANT_SMALL
:
320 size
= kControlSizeSmall
;
323 case wxWINDOW_VARIANT_MINI
:
324 // not always defined in the headers
328 case wxWINDOW_VARIANT_LARGE
:
329 size
= kControlSizeLarge
;
333 wxFAIL_MSG(_T("unexpected window variant"));
336 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
339 #if wxOSX_USE_COCOA_OR_CARBON
342 #if wxOSX_USE_ATSU_TEXT
343 ThemeFontID themeFont
= kThemeSystemFont
;
345 // we will get that from the settings later
346 // and make this NORMAL later, but first
347 // we have a few calculations that we must fix
351 case wxWINDOW_VARIANT_NORMAL
:
352 themeFont
= kThemeSystemFont
;
355 case wxWINDOW_VARIANT_SMALL
:
356 themeFont
= kThemeSmallSystemFont
;
359 case wxWINDOW_VARIANT_MINI
:
360 // not always defined in the headers
364 case wxWINDOW_VARIANT_LARGE
:
365 themeFont
= kThemeSystemFont
;
369 wxFAIL_MSG(_T("unexpected window variant"));
373 font
.MacCreateFromThemeFont( themeFont
) ;
375 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
378 case wxWINDOW_VARIANT_NORMAL
:
379 themeFont
= kCTFontSystemFontType
;
382 case wxWINDOW_VARIANT_SMALL
:
383 themeFont
= kCTFontSmallSystemFontType
;
386 case wxWINDOW_VARIANT_MINI
:
387 themeFont
= kCTFontMiniSystemFontType
;
390 case wxWINDOW_VARIANT_LARGE
:
391 themeFont
= kCTFontSystemFontType
;
395 wxFAIL_MSG(_T("unexpected window variant"));
398 font
.MacCreateFromUIFont( themeFont
) ;
405 void wxWindowMac::MacUpdateControlFont()
408 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
410 // do not trigger refreshes upon invisible and possible partly created objects
411 if ( IsShownOnScreen() )
415 bool wxWindowMac::SetFont(const wxFont
& font
)
417 bool retval
= wxWindowBase::SetFont( font
);
419 MacUpdateControlFont() ;
424 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
426 bool retval
= wxWindowBase::SetForegroundColour( col
);
429 MacUpdateControlFont();
434 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
436 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
440 m_peer
->SetBackgroundColour( col
) ;
445 void wxWindowMac::SetFocus()
447 if ( !AcceptsFocus() )
450 wxWindow
* former
= FindFocus() ;
451 if ( former
== this )
457 void wxWindowMac::DoCaptureMouse()
459 wxApp::s_captureWindow
= (wxWindow
*) this ;
460 m_peer
->CaptureMouse() ;
463 wxWindow
* wxWindowBase::GetCapture()
465 return wxApp::s_captureWindow
;
468 void wxWindowMac::DoReleaseMouse()
470 wxApp::s_captureWindow
= NULL
;
472 m_peer
->ReleaseMouse() ;
475 #if wxUSE_DRAG_AND_DROP
477 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
481 m_dropTarget
= pDropTarget
;
482 if ( m_dropTarget
!= NULL
)
490 // Old-style File Manager Drag & Drop
491 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
496 // From a wx position / size calculate the appropriate size of the native control
498 bool wxWindowMac::MacGetBoundsForControl(
502 int& w
, int& h
, bool adjustOrigin
) const
504 // the desired size, minus the border pixels gives the correct size of the control
508 w
= WidthDefault( size
.x
);
509 h
= HeightDefault( size
.y
);
511 x
+= MacGetLeftBorderSize() ;
512 y
+= MacGetTopBorderSize() ;
513 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
514 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
517 AdjustForParentClientOrigin( x
, y
) ;
519 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
520 if ( GetParent() && !GetParent()->IsTopLevel() )
522 x
-= GetParent()->MacGetLeftBorderSize() ;
523 y
-= GetParent()->MacGetTopBorderSize() ;
529 // Get window size (not client size)
530 void wxWindowMac::DoGetSize(int *x
, int *y
) const
533 m_peer
->GetSize( width
, height
);
536 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
538 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
541 // get the position of the bounds of this window in client coordinates of its parent
542 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
546 m_peer
->GetPosition( x1
, y1
) ;
548 // get the wx window position from the native one
549 x1
-= MacGetLeftBorderSize() ;
550 y1
-= MacGetTopBorderSize() ;
554 wxWindow
*parent
= GetParent();
557 // we must first adjust it to be in window coordinates of the parent,
558 // as otherwise it gets lost by the ClientAreaOrigin fix
559 x1
+= parent
->MacGetLeftBorderSize() ;
560 y1
+= parent
->MacGetTopBorderSize() ;
562 // and now to client coordinates
563 wxPoint
pt(parent
->GetClientAreaOrigin());
575 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
577 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
578 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
579 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
580 MacRootWindowToWindow( x
, y
) ;
582 wxPoint origin
= GetClientAreaOrigin() ;
589 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
591 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
592 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
594 wxPoint origin
= GetClientAreaOrigin() ;
600 MacWindowToRootWindow( x
, y
) ;
601 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
604 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
606 wxPoint origin
= GetClientAreaOrigin() ;
612 MacWindowToRootWindow( x
, y
) ;
615 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
626 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
629 pt
.x
-= MacGetLeftBorderSize() ;
630 pt
.y
-= MacGetTopBorderSize() ;
631 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
641 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
652 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
655 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
656 pt
.x
+= MacGetLeftBorderSize() ;
657 pt
.y
+= MacGetTopBorderSize() ;
667 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
669 wxSize sizeTotal
= size
;
671 int innerwidth
, innerheight
;
673 int outerwidth
, outerheight
;
675 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
676 m_peer
->GetSize( outerwidth
, outerheight
);
678 sizeTotal
.x
+= outerwidth
-innerwidth
;
679 sizeTotal
.y
+= outerheight
-innerheight
;
681 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
682 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
687 // Get size *available for subwindows* i.e. excluding menu bar etc.
688 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
694 m_peer
->GetContentArea( left
, top
, ww
, hh
);
696 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
697 hh
-= m_hScrollBar
->GetSize().y
;
699 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
700 ww
-= m_vScrollBar
->GetSize().x
;
708 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
710 if (m_cursor
.IsSameAs(cursor
))
715 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
720 if ( ! wxWindowBase::SetCursor( cursor
) )
724 wxASSERT_MSG( m_cursor
.Ok(),
725 wxT("cursor must be valid after call to the base version"));
727 if ( GetPeer() != NULL
)
728 GetPeer()->SetCursor( m_cursor
);
734 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
736 #ifndef __WXUNIVERSAL__
737 menu
->SetInvokingWindow((wxWindow
*)this);
740 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
742 wxPoint mouse
= wxGetMousePosition();
748 ClientToScreen( &x
, &y
) ;
750 menu
->GetPeer()->PopUp(this, x
, y
);
751 menu
->SetInvokingWindow( NULL
);
754 // actually this shouldn't be called, because universal is having its own implementation
760 // ----------------------------------------------------------------------------
762 // ----------------------------------------------------------------------------
766 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
768 wxWindowBase::DoSetToolTip(tooltip
);
771 m_tooltip
->SetWindow(this);
776 void wxWindowMac::MacInvalidateBorders()
778 if ( m_peer
== NULL
)
781 bool vis
= IsShownOnScreen() ;
785 int outerBorder
= MacGetLeftBorderSize() ;
787 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
791 if ( outerBorder
== 0 )
794 // now we know that we have something to do at all
799 m_peer
->GetSize( tw
, th
);
800 m_peer
->GetPosition( tx
, ty
);
802 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
803 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
804 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
805 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
808 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
809 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
810 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
811 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
815 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
817 // this is never called for a toplevel window, so we know we have a parent
818 int former_x
, former_y
, former_w
, former_h
;
820 // Get true coordinates of former position
821 DoGetPosition( &former_x
, &former_y
) ;
822 DoGetSize( &former_w
, &former_h
) ;
824 wxWindow
*parent
= GetParent();
827 wxPoint
pt(parent
->GetClientAreaOrigin());
832 int actualWidth
= width
;
833 int actualHeight
= height
;
837 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
838 actualWidth
= m_minWidth
;
839 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
840 actualHeight
= m_minHeight
;
841 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
842 actualWidth
= m_maxWidth
;
843 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
844 actualHeight
= m_maxHeight
;
846 bool doMove
= false, doResize
= false ;
848 if ( actualX
!= former_x
|| actualY
!= former_y
)
851 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
854 if ( doMove
|| doResize
)
856 // as the borders are drawn outside the native control, we adjust now
858 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
859 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
860 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
862 if ( parent
&& !parent
->IsTopLevel() )
864 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
867 MacInvalidateBorders() ;
869 m_cachedClippedRectValid
= false ;
871 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
873 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
875 MacInvalidateBorders() ;
877 MacRepositionScrollBars() ;
880 wxPoint
point(actualX
, actualY
);
881 wxMoveEvent
event(point
, m_windowId
);
882 event
.SetEventObject(this);
883 HandleWindowEvent(event
) ;
888 MacRepositionScrollBars() ;
889 wxSize
size(actualWidth
, actualHeight
);
890 wxSizeEvent
event(size
, m_windowId
);
891 event
.SetEventObject(this);
892 HandleWindowEvent(event
);
897 wxSize
wxWindowMac::DoGetBestSize() const
899 if ( m_macIsUserPane
|| IsTopLevel() )
901 return wxWindowBase::DoGetBestSize() ;
907 m_peer
->GetBestRect(&r
);
909 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
916 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
921 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
928 // return wxWindowBase::DoGetBestSize() ;
932 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
933 MacGetRightBorderSize();
934 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
935 MacGetBottomBorderSize();
936 if ( bestHeight
< 10 )
939 return wxSize(bestWidth
, bestHeight
);
943 // set the size of the window: if the dimensions are positive, just use them,
944 // but if any of them is equal to -1, it means that we must find the value for
945 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
946 // which case -1 is a valid value for x and y)
948 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
949 // the width/height to best suit our contents, otherwise we reuse the current
951 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
953 // get the current size and position...
954 int currentX
, currentY
;
955 int currentW
, currentH
;
957 GetPosition(¤tX
, ¤tY
);
958 GetSize(¤tW
, ¤tH
);
960 // ... and don't do anything (avoiding flicker) if it's already ok
961 if ( x
== currentX
&& y
== currentY
&&
962 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
965 MacRepositionScrollBars() ; // we might have a real position shift
970 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
972 if ( x
== wxDefaultCoord
)
974 if ( y
== wxDefaultCoord
)
978 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
980 wxSize size
= wxDefaultSize
;
981 if ( width
== wxDefaultCoord
)
983 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
985 size
= DoGetBestSize();
990 // just take the current one
995 if ( height
== wxDefaultCoord
)
997 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
999 if ( size
.x
== wxDefaultCoord
)
1000 size
= DoGetBestSize();
1001 // else: already called DoGetBestSize() above
1007 // just take the current one
1012 DoMoveWindow( x
, y
, width
, height
);
1015 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1017 int left
,top
,width
,height
;
1018 m_peer
->GetContentArea( left
, top
, width
, height
);
1019 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1022 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1024 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1026 int currentclientwidth
, currentclientheight
;
1027 int currentwidth
, currentheight
;
1029 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1030 GetSize( ¤twidth
, ¤theight
) ;
1032 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1033 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1037 void wxWindowMac::SetLabel(const wxString
& title
)
1041 if ( m_peer
&& m_peer
->IsOk() )
1042 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1044 // do not trigger refreshes upon invisible and possible partly created objects
1045 if ( IsShownOnScreen() )
1049 wxString
wxWindowMac::GetLabel() const
1054 bool wxWindowMac::Show(bool show
)
1056 if ( !wxWindowBase::Show(show
) )
1060 m_peer
->SetVisibility( show
) ;
1065 void wxWindowMac::DoEnable(bool enable
)
1067 m_peer
->Enable( enable
) ;
1071 // status change notifications
1074 void wxWindowMac::MacVisibilityChanged()
1078 void wxWindowMac::MacHiliteChanged()
1082 void wxWindowMac::MacEnabledStateChanged()
1084 OnEnabled( m_peer
->IsEnabled() );
1088 // status queries on the inherited window's state
1091 bool wxWindowMac::MacIsReallyEnabled()
1093 return m_peer
->IsEnabled() ;
1096 bool wxWindowMac::MacIsReallyHilited()
1098 #if wxOSX_USE_CARBON
1099 return m_peer
->IsActive();
1101 return true; // TODO
1105 int wxWindowMac::GetCharHeight() const
1108 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1113 int wxWindowMac::GetCharWidth() const
1116 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1121 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1122 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1124 const wxFont
*fontToUse
= theFont
;
1128 tempFont
= GetFont();
1129 fontToUse
= &tempFont
;
1132 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1133 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1135 wxDouble h
, d
, e
, w
;
1136 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1140 if ( externalLeading
)
1141 *externalLeading
= (wxCoord
)(e
+0.5);
1143 *descent
= (wxCoord
)(d
+0.5);
1145 *x
= (wxCoord
)(w
+0.5);
1147 *y
= (wxCoord
)(h
+0.5);
1151 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1152 * we always intersect with the entire window, not only with the client area
1155 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1157 if ( m_peer
== NULL
)
1160 if ( !IsShownOnScreen() )
1163 m_peer
->SetNeedsDisplay( rect
) ;
1166 void wxWindowMac::DoFreeze()
1168 #if wxOSX_USE_CARBON
1169 if ( m_peer
&& m_peer
->IsOk() )
1170 m_peer
->SetDrawingEnabled( false ) ;
1174 void wxWindowMac::DoThaw()
1176 #if wxOSX_USE_CARBON
1177 if ( m_peer
&& m_peer
->IsOk() )
1179 m_peer
->SetDrawingEnabled( true ) ;
1180 m_peer
->InvalidateWithChildren() ;
1185 wxWindow
*wxGetActiveWindow()
1187 // actually this is a windows-only concept
1191 // Coordinates relative to the window
1192 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1194 // We really don't move the mouse programmatically under Mac.
1197 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1199 if ( MacGetTopLevelWindow() == NULL
)
1202 #if TARGET_API_MAC_OSX
1203 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1209 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1211 event
.GetDC()->Clear() ;
1213 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1215 // don't skip the event here, custom background means that the app
1216 // is drawing it itself in its OnPaint(), so don't draw it at all
1217 // now to avoid flicker
1225 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1230 int wxWindowMac::GetScrollPos(int orient
) const
1232 if ( orient
== wxHORIZONTAL
)
1235 return m_hScrollBar
->GetThumbPosition() ;
1240 return m_vScrollBar
->GetThumbPosition() ;
1246 // This now returns the whole range, not just the number
1247 // of positions that we can scroll.
1248 int wxWindowMac::GetScrollRange(int orient
) const
1250 if ( orient
== wxHORIZONTAL
)
1253 return m_hScrollBar
->GetRange() ;
1258 return m_vScrollBar
->GetRange() ;
1264 int wxWindowMac::GetScrollThumb(int orient
) const
1266 if ( orient
== wxHORIZONTAL
)
1269 return m_hScrollBar
->GetThumbSize() ;
1274 return m_vScrollBar
->GetThumbSize() ;
1280 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1282 if ( orient
== wxHORIZONTAL
)
1285 m_hScrollBar
->SetThumbPosition( pos
) ;
1290 m_vScrollBar
->SetThumbPosition( pos
) ;
1295 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1297 bool needVisibilityUpdate
= false;
1299 if ( m_hScrollBarAlwaysShown
!= hflag
)
1301 m_hScrollBarAlwaysShown
= hflag
;
1302 needVisibilityUpdate
= true;
1305 if ( m_vScrollBarAlwaysShown
!= vflag
)
1307 m_vScrollBarAlwaysShown
= vflag
;
1308 needVisibilityUpdate
= true;
1311 if ( needVisibilityUpdate
)
1312 DoUpdateScrollbarVisibility();
1316 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1317 // our own window origin is at leftOrigin/rightOrigin
1320 void wxWindowMac::MacPaintGrowBox()
1325 if ( MacHasScrollBarCorner() )
1327 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1328 wxASSERT( cgContext
) ;
1332 m_peer
->GetSize( tw
, th
);
1333 m_peer
->GetPosition( tx
, ty
);
1335 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1338 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1339 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1340 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1341 CGContextSaveGState( cgContext
);
1343 if ( m_backgroundColour
.Ok() )
1345 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1349 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1351 CGContextFillRect( cgContext
, cgrect
);
1352 CGContextRestoreGState( cgContext
);
1356 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1361 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1363 // back to the surrounding frame rectangle
1366 m_peer
->GetSize( tw
, th
);
1367 m_peer
->GetPosition( tx
, ty
);
1369 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1371 #if wxOSX_USE_COCOA_OR_CARBON
1373 InsetRect( &rect
, -1 , -1 ) ;
1376 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1377 rect
.bottom
- rect
.top
) ;
1379 HIThemeFrameDrawInfo info
;
1380 memset( &info
, 0 , sizeof(info
) ) ;
1384 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1385 info
.isFocused
= hasFocus
;
1387 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1388 wxASSERT( cgContext
) ;
1390 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1392 info
.kind
= kHIThemeFrameTextFieldSquare
;
1393 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1395 else if ( HasFlag(wxSIMPLE_BORDER
) )
1397 info
.kind
= kHIThemeFrameListBox
;
1398 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1400 else if ( hasFocus
)
1402 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1404 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1405 m_peer
->GetRect( &rect
) ;
1406 if ( MacHasScrollBarCorner() )
1408 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1409 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1410 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1411 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1412 HIThemeGrowBoxDrawInfo info
;
1413 memset( &info
, 0, sizeof(info
) ) ;
1415 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1416 info
.kind
= kHIThemeGrowBoxKindNone
;
1417 // contrary to the docs ...SizeSmall does not work
1418 info
.size
= kHIThemeGrowBoxSizeNormal
;
1419 info
.direction
= 0 ;
1420 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1424 #endif // wxOSX_USE_COCOA_OR_CARBON
1427 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1429 if ( child
== m_hScrollBar
)
1430 m_hScrollBar
= NULL
;
1431 if ( child
== m_vScrollBar
)
1432 m_vScrollBar
= NULL
;
1434 wxWindowBase::RemoveChild( child
) ;
1437 void wxWindowMac::DoUpdateScrollbarVisibility()
1439 bool triggerSizeEvent
= false;
1443 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1445 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1447 m_hScrollBar
->Show( showHScrollBar
);
1448 triggerSizeEvent
= true;
1454 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1456 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1458 m_vScrollBar
->Show( showVScrollBar
) ;
1459 triggerSizeEvent
= true;
1463 MacRepositionScrollBars() ;
1464 if ( triggerSizeEvent
)
1466 wxSizeEvent
event(GetSize(), m_windowId
);
1467 event
.SetEventObject(this);
1468 HandleWindowEvent(event
);
1472 // New function that will replace some of the above.
1473 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1474 int range
, bool refresh
)
1476 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1477 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1478 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1479 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1481 DoUpdateScrollbarVisibility();
1484 // Does a physical scroll
1485 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1487 if ( dx
== 0 && dy
== 0 )
1490 int width
, height
;
1491 GetClientSize( &width
, &height
) ;
1494 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1496 scrollrect
.Intersect( *rect
) ;
1497 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1498 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1500 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1505 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1507 child
= node
->GetData();
1510 if (child
== m_vScrollBar
)
1512 if (child
== m_hScrollBar
)
1514 if (child
->IsTopLevel())
1517 child
->GetPosition( &x
, &y
);
1518 child
->GetSize( &w
, &h
);
1521 wxRect
rc( x
, y
, w
, h
);
1522 if (rect
->Intersects( rc
))
1523 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1527 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1532 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1534 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1536 wxScrollWinEvent wevent
;
1537 wevent
.SetPosition(event
.GetPosition());
1538 wevent
.SetOrientation(event
.GetOrientation());
1539 wevent
.SetEventObject(this);
1541 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1542 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1543 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1544 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1545 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1546 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1547 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1548 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1549 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1550 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1551 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1552 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1553 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1554 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1555 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1556 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1558 HandleWindowEvent(wevent
);
1562 // Get the window with the focus
1563 wxWindow
*wxWindowBase::DoFindFocus()
1565 #if wxOSX_USE_CARBON
1566 ControlRef control
;
1567 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1568 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1574 void wxWindowMac::OnInternalIdle()
1576 // This calls the UI-update mechanism (querying windows for
1577 // menu/toolbar/control state information)
1578 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1579 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1582 // Raise the window to the top of the Z order
1583 void wxWindowMac::Raise()
1588 // Lower the window to the bottom of the Z order
1589 void wxWindowMac::Lower()
1594 // static wxWindow *gs_lastWhich = NULL;
1596 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1598 // first trigger a set cursor event
1600 wxPoint clientorigin
= GetClientAreaOrigin() ;
1601 wxSize clientsize
= GetClientSize() ;
1603 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1605 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1607 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1608 if ( processedEvtSetCursor
&& event
.HasCursor() )
1610 cursor
= event
.GetCursor() ;
1614 // the test for processedEvtSetCursor is here to prevent using m_cursor
1615 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1616 // it - this is a way to say that our cursor shouldn't be used for this
1618 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1621 if ( !wxIsBusy() && !GetParent() )
1622 cursor
= *wxSTANDARD_CURSOR
;
1626 cursor
.MacInstall() ;
1629 return cursor
.Ok() ;
1632 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1636 return m_tooltip
->GetTip() ;
1639 return wxEmptyString
;
1642 void wxWindowMac::ClearBackground()
1648 void wxWindowMac::Update()
1650 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1655 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1657 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1661 if ( iter
->IsTopLevel() )
1663 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1667 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1672 iter
= iter
->GetParent() ;
1678 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1680 MacUpdateClippedRects() ;
1682 return m_cachedClippedClientRect
;
1685 const wxRect
& wxWindowMac::MacGetClippedRect() const
1687 MacUpdateClippedRects() ;
1689 return m_cachedClippedRect
;
1692 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1694 MacUpdateClippedRects() ;
1696 return m_cachedClippedRectWithOuterStructure
;
1699 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1701 static wxRegion emptyrgn
;
1703 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1705 MacUpdateClippedRects() ;
1706 if ( includeOuterStructures
)
1707 return m_cachedClippedRegionWithOuterStructure
;
1709 return m_cachedClippedRegion
;
1717 void wxWindowMac::MacUpdateClippedRects() const
1719 #if wxOSX_USE_CARBON
1720 if ( m_cachedClippedRectValid
)
1723 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1724 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1725 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1726 // to add focus borders everywhere
1728 Rect rIncludingOuterStructures
;
1732 m_peer
->GetSize( tw
, th
);
1733 m_peer
->GetPosition( tx
, ty
);
1735 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1737 r
.left
-= MacGetLeftBorderSize() ;
1738 r
.top
-= MacGetTopBorderSize() ;
1739 r
.bottom
+= MacGetBottomBorderSize() ;
1740 r
.right
+= MacGetRightBorderSize() ;
1747 rIncludingOuterStructures
= r
;
1748 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1750 wxRect cl
= GetClientRect() ;
1751 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1755 const wxWindow
* child
= (wxWindow
*) this ;
1756 const wxWindow
* parent
= NULL
;
1758 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1760 if ( parent
->MacIsChildOfClientArea(child
) )
1762 size
= parent
->GetClientSize() ;
1763 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1769 // this will be true for scrollbars, toolbars etc.
1770 size
= parent
->GetSize() ;
1771 y
= parent
->MacGetTopBorderSize() ;
1772 x
= parent
->MacGetLeftBorderSize() ;
1773 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1774 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1777 parent
->MacWindowToRootWindow( &x
, &y
) ;
1778 MacRootWindowToWindow( &x
, &y
) ;
1780 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1782 // the wxwindow and client rects will always be clipped
1783 SectRect( &r
, &rparent
, &r
) ;
1784 SectRect( &rClient
, &rparent
, &rClient
) ;
1786 // the structure only at 'hard' borders
1787 if ( parent
->MacClipChildren() ||
1788 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1790 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1796 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1797 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1798 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1799 m_cachedClippedRectWithOuterStructure
= wxRect(
1800 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1801 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1802 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1804 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1805 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1806 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1808 m_cachedClippedRectValid
= true ;
1813 This function must not change the updatergn !
1815 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1817 bool handled
= false ;
1818 #if wxOSX_USE_CARBON
1820 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1821 GetRegionBounds( updatergn
, &updatebounds
) ;
1823 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1825 if ( !EmptyRgn(updatergn
) )
1827 RgnHandle newupdate
= NewRgn() ;
1828 wxSize point
= GetClientSize() ;
1829 wxPoint origin
= GetClientAreaOrigin() ;
1830 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1831 SectRgn( newupdate
, updatergn
, newupdate
) ;
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(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1843 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
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 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1855 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1856 DisposeRgn( newupdate
) ;
1858 if ( !m_updateRegion
.Empty() )
1860 // paint the window itself
1863 event
.SetTimestamp(time
);
1864 event
.SetEventObject(this);
1865 HandleWindowEvent(event
);
1869 // now we cannot rely on having its borders drawn by a window itself, as it does not
1870 // get the updateRgn wide enough to always do so, so we do it from the parent
1871 // this would also be the place to draw any custom backgrounds for native controls
1872 // in Composited windowing
1873 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1877 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1879 child
= node
->GetData();
1882 if (child
== m_vScrollBar
)
1884 if (child
== m_hScrollBar
)
1886 if (child
->IsTopLevel())
1888 if (!child
->IsShown())
1891 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1893 child
->GetPosition( &x
, &y
);
1894 child
->GetSize( &w
, &h
);
1895 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1896 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1897 InsetRect( &childRect
, -10 , -10) ;
1899 if ( RectInRgn( &childRect
, updatergn
) )
1901 // paint custom borders
1902 wxNcPaintEvent
eventNc( child
->GetId() );
1903 eventNc
.SetEventObject( child
);
1904 if ( !child
->HandleWindowEvent( eventNc
) )
1906 child
->MacPaintBorders(0, 0) ;
1916 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1918 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1919 return tlw
? tlw
->GetWXWindow() : NULL
;
1922 bool wxWindowMac::MacHasScrollBarCorner() const
1924 /* Returns whether the scroll bars in a wxScrolledWindow should be
1925 * shortened. Scroll bars should be shortened if either:
1927 * - both scroll bars are visible, or
1929 * - there is a resize box in the parent frame's corner and this
1930 * window shares the bottom and right edge with the parent
1934 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1937 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1938 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1940 // Both scroll bars visible
1945 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1947 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1949 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1952 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1954 // Parent frame has resize handle
1955 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1957 // Note: allow for some wiggle room here as wxMac's
1958 // window rect calculations seem to be imprecise
1959 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1960 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1962 // Parent frame has resize handle and shares
1963 // right bottom corner
1968 // Parent frame has resize handle but doesn't
1969 // share right bottom corner
1975 // Parent frame doesn't have resize handle
1981 // No parent frame found
1986 void wxWindowMac::MacCreateScrollBars( long style
)
1988 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1990 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1992 int scrlsize
= MAC_SCROLLBAR_SIZE
;
1993 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
1995 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
1998 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2000 GetClientSize( &width
, &height
) ;
2002 wxPoint
vPoint(width
- scrlsize
, 0) ;
2003 wxSize
vSize(scrlsize
, height
- adjust
) ;
2004 wxPoint
hPoint(0, height
- scrlsize
) ;
2005 wxSize
hSize(width
- adjust
, scrlsize
) ;
2007 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2008 if ( style
& wxVSCROLL
)
2010 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2011 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2014 if ( style
& wxHSCROLL
)
2016 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2017 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2021 // because the create does not take into account the client area origin
2022 // we might have a real position shift
2023 MacRepositionScrollBars() ;
2026 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2028 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2033 void wxWindowMac::MacRepositionScrollBars()
2035 if ( !m_hScrollBar
&& !m_vScrollBar
)
2038 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2039 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2041 // get real client area
2043 GetSize( &width
, &height
);
2045 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2046 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2048 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2049 wxSize
vSize( scrlsize
, height
- adjust
) ;
2050 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2051 wxSize
hSize( width
- adjust
, scrlsize
) ;
2054 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2056 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2059 bool wxWindowMac::AcceptsFocus() const
2061 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2064 void wxWindowMac::MacSuperChangedPosition()
2066 // only window-absolute structures have to be moved i.e. controls
2068 m_cachedClippedRectValid
= false ;
2071 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2074 child
= node
->GetData();
2075 child
->MacSuperChangedPosition() ;
2077 node
= node
->GetNext();
2081 void wxWindowMac::MacTopLevelWindowChangedPosition()
2083 // only screen-absolute structures have to be moved i.e. glcanvas
2086 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2089 child
= node
->GetData();
2090 child
->MacTopLevelWindowChangedPosition() ;
2092 node
= node
->GetNext();
2096 long wxWindowMac::MacGetLeftBorderSize() const
2103 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2105 #if wxOSX_USE_COCOA_OR_CARBON
2106 // this metric is only the 'outset' outside the simple frame rect
2107 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2113 else if (HasFlag(wxSIMPLE_BORDER
))
2115 #if wxOSX_USE_COCOA_OR_CARBON
2116 // this metric is only the 'outset' outside the simple frame rect
2117 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2127 long wxWindowMac::MacGetRightBorderSize() const
2129 // they are all symmetric in mac themes
2130 return MacGetLeftBorderSize() ;
2133 long wxWindowMac::MacGetTopBorderSize() const
2135 // they are all symmetric in mac themes
2136 return MacGetLeftBorderSize() ;
2139 long wxWindowMac::MacGetBottomBorderSize() const
2141 // they are all symmetric in mac themes
2142 return MacGetLeftBorderSize() ;
2145 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2147 return style
& ~wxBORDER_MASK
;
2150 // Find the wxWindowMac at the current mouse position, returning the mouse
2152 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2154 pt
= wxGetMousePosition();
2155 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2157 return (wxWindow
*) found
;
2160 // Get the current mouse position.
2161 wxPoint
wxGetMousePosition()
2165 wxGetMousePosition( &x
, &y
);
2167 return wxPoint(x
, y
);
2170 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2172 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2174 // copied from wxGTK : CS
2175 // VZ: shouldn't we move this to base class then?
2177 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2180 // (a) it's a command event and so is propagated to the parent
2181 // (b) under MSW it can be generated from kbd too
2182 // (c) it uses screen coords (because of (a))
2183 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2185 this->ClientToScreen(event
.GetPosition()));
2186 evtCtx
.SetEventObject(this);
2187 if ( ! HandleWindowEvent(evtCtx
) )
2196 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2198 #if wxOSX_USE_COCOA_OR_CARBON
2199 // for native controls: call their native paint method
2200 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2202 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2203 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2204 CallNextEventHandler(
2205 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2206 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2211 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2215 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2219 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2220 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2225 bool wxWindowMac::OSXHandleClicked( double timestampsec
)
2230 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2232 #if wxOSX_USE_COCOA_OR_CARBON
2233 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2236 return eventNotHandledErr
;
2242 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2244 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2245 if ( !wxWindowBase::Reparent(newParent
) )
2248 m_peer
->RemoveFromParent();
2249 m_peer
->Embed( GetParent()->GetPeer() );
2253 bool wxWindowMac::SetTransparent(wxByte alpha
)
2255 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2257 if ( alpha
!= m_macAlpha
)
2259 m_macAlpha
= alpha
;
2266 bool wxWindowMac::CanSetTransparent()
2271 wxByte
wxWindowMac::GetTransparent() const
2276 bool wxWindowMac::IsShownOnScreen() const
2278 if ( m_peer
&& m_peer
->IsOk() )
2280 bool peerVis
= m_peer
->IsVisible();
2281 bool wxVis
= wxWindowBase::IsShownOnScreen();
2282 if( peerVis
!= wxVis
)
2284 // CS : put a breakpoint here to investigate differences
2285 // between native an wx visibilities
2286 // the only place where I've encountered them until now
2287 // are the hiding/showing sequences where the vis-changed event is
2288 // first sent to the innermost control, while wx does things
2289 // from the outmost control
2290 wxVis
= wxWindowBase::IsShownOnScreen();
2294 return m_peer
->IsVisible();
2296 return wxWindowBase::IsShownOnScreen();
2299 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2301 bool handled
= HandleWindowEvent( event
) ;
2302 if ( handled
&& event
.GetSkipped() )
2306 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2308 wxWindow
*ancestor
= this;
2311 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2314 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2316 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2317 handled
= handler
->ProcessEvent( command_event
);
2321 // accelerators can also be used with buttons, try them too
2322 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2323 handled
= handler
->ProcessEvent( command_event
);
2329 if (ancestor
->IsTopLevel())
2332 ancestor
= ancestor
->GetParent();
2335 #endif // wxUSE_ACCEL
2344 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2346 static MacControlMap wxWinMacControlList
;
2348 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2350 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2352 return impl
->GetWXPeer();
2357 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2359 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2361 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2364 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2366 // adding NULL ControlRef is (first) surely a result of an error and
2367 // (secondly) breaks native event processing
2368 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2370 wxWinMacControlList
[inControl
] = impl
;
2373 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2375 // iterate over all the elements in the class
2376 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2377 // we should go on...
2383 MacControlMap::iterator it
;
2384 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2386 if ( it
->second
== impl
)
2388 wxWinMacControlList
.erase(it
);
2396 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2398 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2401 m_isRootControl
= isRootControl
;
2405 wxWidgetImpl::wxWidgetImpl()
2410 wxWidgetImpl::~wxWidgetImpl()
2414 void wxWidgetImpl::Init()
2416 m_isRootControl
= false;
2418 m_needsFocusRect
= false;
2421 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2423 m_needsFocusRect
= needs
;
2426 bool wxWidgetImpl::NeedsFocusRect() const
2428 return m_needsFocusRect
;