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
967 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
969 wxSizeEvent
event( wxSize(width
,height
), GetId() );
970 event
.SetEventObject( this );
971 HandleWindowEvent( event
);
977 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
979 if ( x
== wxDefaultCoord
)
981 if ( y
== wxDefaultCoord
)
985 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
987 wxSize size
= wxDefaultSize
;
988 if ( width
== wxDefaultCoord
)
990 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
992 size
= DoGetBestSize();
997 // just take the current one
1002 if ( height
== wxDefaultCoord
)
1004 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1006 if ( size
.x
== wxDefaultCoord
)
1007 size
= DoGetBestSize();
1008 // else: already called DoGetBestSize() above
1014 // just take the current one
1019 DoMoveWindow( x
, y
, width
, height
);
1022 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1024 int left
,top
,width
,height
;
1025 m_peer
->GetContentArea( left
, top
, width
, height
);
1026 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1029 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1031 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1033 int currentclientwidth
, currentclientheight
;
1034 int currentwidth
, currentheight
;
1036 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1037 GetSize( ¤twidth
, ¤theight
) ;
1039 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1040 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1044 void wxWindowMac::SetLabel(const wxString
& title
)
1048 if ( m_peer
&& m_peer
->IsOk() )
1049 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1051 // do not trigger refreshes upon invisible and possible partly created objects
1052 if ( IsShownOnScreen() )
1056 wxString
wxWindowMac::GetLabel() const
1061 bool wxWindowMac::Show(bool show
)
1063 if ( !wxWindowBase::Show(show
) )
1067 m_peer
->SetVisibility( show
) ;
1072 void wxWindowMac::DoEnable(bool enable
)
1074 m_peer
->Enable( enable
) ;
1078 // status change notifications
1081 void wxWindowMac::MacVisibilityChanged()
1085 void wxWindowMac::MacHiliteChanged()
1089 void wxWindowMac::MacEnabledStateChanged()
1091 OnEnabled( m_peer
->IsEnabled() );
1095 // status queries on the inherited window's state
1098 bool wxWindowMac::MacIsReallyEnabled()
1100 return m_peer
->IsEnabled() ;
1103 bool wxWindowMac::MacIsReallyHilited()
1105 #if wxOSX_USE_CARBON
1106 return m_peer
->IsActive();
1108 return true; // TODO
1112 int wxWindowMac::GetCharHeight() const
1115 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1120 int wxWindowMac::GetCharWidth() const
1123 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1128 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1129 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1131 const wxFont
*fontToUse
= theFont
;
1135 tempFont
= GetFont();
1136 fontToUse
= &tempFont
;
1139 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1140 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1142 wxDouble h
, d
, e
, w
;
1143 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1147 if ( externalLeading
)
1148 *externalLeading
= (wxCoord
)(e
+0.5);
1150 *descent
= (wxCoord
)(d
+0.5);
1152 *x
= (wxCoord
)(w
+0.5);
1154 *y
= (wxCoord
)(h
+0.5);
1158 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1159 * we always intersect with the entire window, not only with the client area
1162 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1164 if ( m_peer
== NULL
)
1167 if ( !IsShownOnScreen() )
1170 m_peer
->SetNeedsDisplay( rect
) ;
1173 void wxWindowMac::DoFreeze()
1175 #if wxOSX_USE_CARBON
1176 if ( m_peer
&& m_peer
->IsOk() )
1177 m_peer
->SetDrawingEnabled( false ) ;
1181 void wxWindowMac::DoThaw()
1183 #if wxOSX_USE_CARBON
1184 if ( m_peer
&& m_peer
->IsOk() )
1186 m_peer
->SetDrawingEnabled( true ) ;
1187 m_peer
->InvalidateWithChildren() ;
1192 wxWindow
*wxGetActiveWindow()
1194 // actually this is a windows-only concept
1198 // Coordinates relative to the window
1199 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1201 // We really don't move the mouse programmatically under Mac.
1204 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1206 if ( MacGetTopLevelWindow() == NULL
)
1209 #if TARGET_API_MAC_OSX
1210 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1216 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1218 event
.GetDC()->Clear() ;
1220 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1222 // don't skip the event here, custom background means that the app
1223 // is drawing it itself in its OnPaint(), so don't draw it at all
1224 // now to avoid flicker
1232 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1237 int wxWindowMac::GetScrollPos(int orient
) const
1239 if ( orient
== wxHORIZONTAL
)
1242 return m_hScrollBar
->GetThumbPosition() ;
1247 return m_vScrollBar
->GetThumbPosition() ;
1253 // This now returns the whole range, not just the number
1254 // of positions that we can scroll.
1255 int wxWindowMac::GetScrollRange(int orient
) const
1257 if ( orient
== wxHORIZONTAL
)
1260 return m_hScrollBar
->GetRange() ;
1265 return m_vScrollBar
->GetRange() ;
1271 int wxWindowMac::GetScrollThumb(int orient
) const
1273 if ( orient
== wxHORIZONTAL
)
1276 return m_hScrollBar
->GetThumbSize() ;
1281 return m_vScrollBar
->GetThumbSize() ;
1287 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1289 if ( orient
== wxHORIZONTAL
)
1292 m_hScrollBar
->SetThumbPosition( pos
) ;
1297 m_vScrollBar
->SetThumbPosition( pos
) ;
1302 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1304 bool needVisibilityUpdate
= false;
1306 if ( m_hScrollBarAlwaysShown
!= hflag
)
1308 m_hScrollBarAlwaysShown
= hflag
;
1309 needVisibilityUpdate
= true;
1312 if ( m_vScrollBarAlwaysShown
!= vflag
)
1314 m_vScrollBarAlwaysShown
= vflag
;
1315 needVisibilityUpdate
= true;
1318 if ( needVisibilityUpdate
)
1319 DoUpdateScrollbarVisibility();
1323 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1324 // our own window origin is at leftOrigin/rightOrigin
1327 void wxWindowMac::MacPaintGrowBox()
1332 if ( MacHasScrollBarCorner() )
1334 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1335 wxASSERT( cgContext
) ;
1339 m_peer
->GetSize( tw
, th
);
1340 m_peer
->GetPosition( tx
, ty
);
1342 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1345 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1346 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1347 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1348 CGContextSaveGState( cgContext
);
1350 if ( m_backgroundColour
.Ok() )
1352 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1356 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1358 CGContextFillRect( cgContext
, cgrect
);
1359 CGContextRestoreGState( cgContext
);
1363 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1368 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1370 // back to the surrounding frame rectangle
1373 m_peer
->GetSize( tw
, th
);
1374 m_peer
->GetPosition( tx
, ty
);
1376 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1378 #if wxOSX_USE_COCOA_OR_CARBON
1380 InsetRect( &rect
, -1 , -1 ) ;
1383 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1384 rect
.bottom
- rect
.top
) ;
1386 HIThemeFrameDrawInfo info
;
1387 memset( &info
, 0 , sizeof(info
) ) ;
1391 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1392 info
.isFocused
= hasFocus
;
1394 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1395 wxASSERT( cgContext
) ;
1397 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1399 info
.kind
= kHIThemeFrameTextFieldSquare
;
1400 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1402 else if ( HasFlag(wxSIMPLE_BORDER
) )
1404 info
.kind
= kHIThemeFrameListBox
;
1405 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1407 else if ( hasFocus
)
1409 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1411 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1412 m_peer
->GetRect( &rect
) ;
1413 if ( MacHasScrollBarCorner() )
1415 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1416 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1417 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1418 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1419 HIThemeGrowBoxDrawInfo info
;
1420 memset( &info
, 0, sizeof(info
) ) ;
1422 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1423 info
.kind
= kHIThemeGrowBoxKindNone
;
1424 // contrary to the docs ...SizeSmall does not work
1425 info
.size
= kHIThemeGrowBoxSizeNormal
;
1426 info
.direction
= 0 ;
1427 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1431 #endif // wxOSX_USE_COCOA_OR_CARBON
1434 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1436 if ( child
== m_hScrollBar
)
1437 m_hScrollBar
= NULL
;
1438 if ( child
== m_vScrollBar
)
1439 m_vScrollBar
= NULL
;
1441 wxWindowBase::RemoveChild( child
) ;
1444 void wxWindowMac::DoUpdateScrollbarVisibility()
1446 bool triggerSizeEvent
= false;
1450 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1452 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1454 m_hScrollBar
->Show( showHScrollBar
);
1455 triggerSizeEvent
= true;
1461 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1463 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1465 m_vScrollBar
->Show( showVScrollBar
) ;
1466 triggerSizeEvent
= true;
1470 MacRepositionScrollBars() ;
1471 if ( triggerSizeEvent
)
1473 wxSizeEvent
event(GetSize(), m_windowId
);
1474 event
.SetEventObject(this);
1475 HandleWindowEvent(event
);
1479 // New function that will replace some of the above.
1480 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1481 int range
, bool refresh
)
1483 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1484 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1485 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1486 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1488 DoUpdateScrollbarVisibility();
1491 // Does a physical scroll
1492 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1494 if ( dx
== 0 && dy
== 0 )
1497 int width
, height
;
1498 GetClientSize( &width
, &height
) ;
1501 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1503 scrollrect
.Intersect( *rect
) ;
1504 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1505 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1507 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1512 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1514 child
= node
->GetData();
1517 if (child
== m_vScrollBar
)
1519 if (child
== m_hScrollBar
)
1521 if (child
->IsTopLevel())
1524 child
->GetPosition( &x
, &y
);
1525 child
->GetSize( &w
, &h
);
1528 wxRect
rc( x
, y
, w
, h
);
1529 if (rect
->Intersects( rc
))
1530 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1534 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1539 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1541 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1543 wxScrollWinEvent wevent
;
1544 wevent
.SetPosition(event
.GetPosition());
1545 wevent
.SetOrientation(event
.GetOrientation());
1546 wevent
.SetEventObject(this);
1548 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1549 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1550 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1551 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1552 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1553 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1554 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1555 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1556 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1557 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1558 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1559 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1560 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1561 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1562 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1563 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1565 HandleWindowEvent(wevent
);
1569 // Get the window with the focus
1570 wxWindow
*wxWindowBase::DoFindFocus()
1572 #if wxOSX_USE_CARBON
1573 ControlRef control
;
1574 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1575 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1581 void wxWindowMac::OnInternalIdle()
1583 // This calls the UI-update mechanism (querying windows for
1584 // menu/toolbar/control state information)
1585 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1586 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1589 // Raise the window to the top of the Z order
1590 void wxWindowMac::Raise()
1595 // Lower the window to the bottom of the Z order
1596 void wxWindowMac::Lower()
1601 // static wxWindow *gs_lastWhich = NULL;
1603 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1605 // first trigger a set cursor event
1607 wxPoint clientorigin
= GetClientAreaOrigin() ;
1608 wxSize clientsize
= GetClientSize() ;
1610 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1612 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1614 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1615 if ( processedEvtSetCursor
&& event
.HasCursor() )
1617 cursor
= event
.GetCursor() ;
1621 // the test for processedEvtSetCursor is here to prevent using m_cursor
1622 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1623 // it - this is a way to say that our cursor shouldn't be used for this
1625 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1628 if ( !wxIsBusy() && !GetParent() )
1629 cursor
= *wxSTANDARD_CURSOR
;
1633 cursor
.MacInstall() ;
1636 return cursor
.Ok() ;
1639 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1643 return m_tooltip
->GetTip() ;
1646 return wxEmptyString
;
1649 void wxWindowMac::ClearBackground()
1655 void wxWindowMac::Update()
1657 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1662 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1664 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1668 if ( iter
->IsTopLevel() )
1670 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1674 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1679 iter
= iter
->GetParent() ;
1685 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1687 MacUpdateClippedRects() ;
1689 return m_cachedClippedClientRect
;
1692 const wxRect
& wxWindowMac::MacGetClippedRect() const
1694 MacUpdateClippedRects() ;
1696 return m_cachedClippedRect
;
1699 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1701 MacUpdateClippedRects() ;
1703 return m_cachedClippedRectWithOuterStructure
;
1706 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1708 static wxRegion emptyrgn
;
1710 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1712 MacUpdateClippedRects() ;
1713 if ( includeOuterStructures
)
1714 return m_cachedClippedRegionWithOuterStructure
;
1716 return m_cachedClippedRegion
;
1724 void wxWindowMac::MacUpdateClippedRects() const
1726 #if wxOSX_USE_CARBON
1727 if ( m_cachedClippedRectValid
)
1730 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1731 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1732 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1733 // to add focus borders everywhere
1735 Rect rIncludingOuterStructures
;
1739 m_peer
->GetSize( tw
, th
);
1740 m_peer
->GetPosition( tx
, ty
);
1742 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1744 r
.left
-= MacGetLeftBorderSize() ;
1745 r
.top
-= MacGetTopBorderSize() ;
1746 r
.bottom
+= MacGetBottomBorderSize() ;
1747 r
.right
+= MacGetRightBorderSize() ;
1754 rIncludingOuterStructures
= r
;
1755 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1757 wxRect cl
= GetClientRect() ;
1758 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1762 const wxWindow
* child
= (wxWindow
*) this ;
1763 const wxWindow
* parent
= NULL
;
1765 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1767 if ( parent
->MacIsChildOfClientArea(child
) )
1769 size
= parent
->GetClientSize() ;
1770 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1776 // this will be true for scrollbars, toolbars etc.
1777 size
= parent
->GetSize() ;
1778 y
= parent
->MacGetTopBorderSize() ;
1779 x
= parent
->MacGetLeftBorderSize() ;
1780 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1781 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1784 parent
->MacWindowToRootWindow( &x
, &y
) ;
1785 MacRootWindowToWindow( &x
, &y
) ;
1787 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1789 // the wxwindow and client rects will always be clipped
1790 SectRect( &r
, &rparent
, &r
) ;
1791 SectRect( &rClient
, &rparent
, &rClient
) ;
1793 // the structure only at 'hard' borders
1794 if ( parent
->MacClipChildren() ||
1795 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1797 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1803 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1804 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1805 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1806 m_cachedClippedRectWithOuterStructure
= wxRect(
1807 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1808 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1809 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1811 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1812 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1813 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1815 m_cachedClippedRectValid
= true ;
1820 This function must not change the updatergn !
1822 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1824 bool handled
= false ;
1825 #if wxOSX_USE_CARBON
1827 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1828 GetRegionBounds( updatergn
, &updatebounds
) ;
1830 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1832 if ( !EmptyRgn(updatergn
) )
1834 RgnHandle newupdate
= NewRgn() ;
1835 wxSize point
= GetClientSize() ;
1836 wxPoint origin
= GetClientAreaOrigin() ;
1837 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1838 SectRgn( newupdate
, updatergn
, newupdate
) ;
1840 // first send an erase event to the entire update area
1842 // for the toplevel window this really is the entire area
1843 // for all the others only their client area, otherwise they
1844 // might be drawing with full alpha and eg put blue into
1845 // the grow-box area of a scrolled window (scroll sample)
1846 wxDC
* dc
= new wxWindowDC(this);
1848 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1850 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1852 wxEraseEvent
eevent( GetId(), dc
);
1853 eevent
.SetEventObject( this );
1854 HandleWindowEvent( eevent
);
1860 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1861 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1862 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1863 DisposeRgn( newupdate
) ;
1865 if ( !m_updateRegion
.Empty() )
1867 // paint the window itself
1870 event
.SetTimestamp(time
);
1871 event
.SetEventObject(this);
1872 HandleWindowEvent(event
);
1876 // now we cannot rely on having its borders drawn by a window itself, as it does not
1877 // get the updateRgn wide enough to always do so, so we do it from the parent
1878 // this would also be the place to draw any custom backgrounds for native controls
1879 // in Composited windowing
1880 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1884 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1886 child
= node
->GetData();
1889 if (child
== m_vScrollBar
)
1891 if (child
== m_hScrollBar
)
1893 if (child
->IsTopLevel())
1895 if (!child
->IsShown())
1898 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1900 child
->GetPosition( &x
, &y
);
1901 child
->GetSize( &w
, &h
);
1902 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1903 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1904 InsetRect( &childRect
, -10 , -10) ;
1906 if ( RectInRgn( &childRect
, updatergn
) )
1908 // paint custom borders
1909 wxNcPaintEvent
eventNc( child
->GetId() );
1910 eventNc
.SetEventObject( child
);
1911 if ( !child
->HandleWindowEvent( eventNc
) )
1913 child
->MacPaintBorders(0, 0) ;
1923 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1925 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1926 return tlw
? tlw
->GetWXWindow() : NULL
;
1929 bool wxWindowMac::MacHasScrollBarCorner() const
1931 /* Returns whether the scroll bars in a wxScrolledWindow should be
1932 * shortened. Scroll bars should be shortened if either:
1934 * - both scroll bars are visible, or
1936 * - there is a resize box in the parent frame's corner and this
1937 * window shares the bottom and right edge with the parent
1941 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1944 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1945 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1947 // Both scroll bars visible
1952 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1954 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1956 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1959 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1961 // Parent frame has resize handle
1962 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1964 // Note: allow for some wiggle room here as wxMac's
1965 // window rect calculations seem to be imprecise
1966 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1967 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1969 // Parent frame has resize handle and shares
1970 // right bottom corner
1975 // Parent frame has resize handle but doesn't
1976 // share right bottom corner
1982 // Parent frame doesn't have resize handle
1988 // No parent frame found
1993 void wxWindowMac::MacCreateScrollBars( long style
)
1995 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
1997 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
1999 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2000 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2002 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2005 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2007 GetClientSize( &width
, &height
) ;
2009 wxPoint
vPoint(width
- scrlsize
, 0) ;
2010 wxSize
vSize(scrlsize
, height
- adjust
) ;
2011 wxPoint
hPoint(0, height
- scrlsize
) ;
2012 wxSize
hSize(width
- adjust
, scrlsize
) ;
2014 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2015 if ( style
& wxVSCROLL
)
2017 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2018 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2021 if ( style
& wxHSCROLL
)
2023 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2024 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2028 // because the create does not take into account the client area origin
2029 // we might have a real position shift
2030 MacRepositionScrollBars() ;
2033 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2035 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2040 void wxWindowMac::MacRepositionScrollBars()
2042 if ( !m_hScrollBar
&& !m_vScrollBar
)
2045 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2046 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2048 // get real client area
2050 GetSize( &width
, &height
);
2052 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2053 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2055 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2056 wxSize
vSize( scrlsize
, height
- adjust
) ;
2057 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2058 wxSize
hSize( width
- adjust
, scrlsize
) ;
2061 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2063 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2066 bool wxWindowMac::AcceptsFocus() const
2068 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2071 void wxWindowMac::MacSuperChangedPosition()
2073 // only window-absolute structures have to be moved i.e. controls
2075 m_cachedClippedRectValid
= false ;
2078 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2081 child
= node
->GetData();
2082 child
->MacSuperChangedPosition() ;
2084 node
= node
->GetNext();
2088 void wxWindowMac::MacTopLevelWindowChangedPosition()
2090 // only screen-absolute structures have to be moved i.e. glcanvas
2093 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2096 child
= node
->GetData();
2097 child
->MacTopLevelWindowChangedPosition() ;
2099 node
= node
->GetNext();
2103 long wxWindowMac::MacGetLeftBorderSize() const
2110 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2112 #if wxOSX_USE_COCOA_OR_CARBON
2113 // this metric is only the 'outset' outside the simple frame rect
2114 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2120 else if (HasFlag(wxSIMPLE_BORDER
))
2122 #if wxOSX_USE_COCOA_OR_CARBON
2123 // this metric is only the 'outset' outside the simple frame rect
2124 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2134 long wxWindowMac::MacGetRightBorderSize() const
2136 // they are all symmetric in mac themes
2137 return MacGetLeftBorderSize() ;
2140 long wxWindowMac::MacGetTopBorderSize() const
2142 // they are all symmetric in mac themes
2143 return MacGetLeftBorderSize() ;
2146 long wxWindowMac::MacGetBottomBorderSize() const
2148 // they are all symmetric in mac themes
2149 return MacGetLeftBorderSize() ;
2152 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2154 return style
& ~wxBORDER_MASK
;
2157 // Find the wxWindowMac at the current mouse position, returning the mouse
2159 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2161 pt
= wxGetMousePosition();
2162 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2164 return (wxWindow
*) found
;
2167 // Get the current mouse position.
2168 wxPoint
wxGetMousePosition()
2172 wxGetMousePosition( &x
, &y
);
2174 return wxPoint(x
, y
);
2177 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2179 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2181 // copied from wxGTK : CS
2182 // VZ: shouldn't we move this to base class then?
2184 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2187 // (a) it's a command event and so is propagated to the parent
2188 // (b) under MSW it can be generated from kbd too
2189 // (c) it uses screen coords (because of (a))
2190 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2192 this->ClientToScreen(event
.GetPosition()));
2193 evtCtx
.SetEventObject(this);
2194 if ( ! HandleWindowEvent(evtCtx
) )
2203 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2205 #if wxOSX_USE_COCOA_OR_CARBON
2206 // for native controls: call their native paint method
2207 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2209 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2210 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2211 CallNextEventHandler(
2212 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2213 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2218 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2222 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2226 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2227 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2232 bool wxWindowMac::OSXHandleClicked( double timestampsec
)
2237 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2239 #if wxOSX_USE_COCOA_OR_CARBON
2240 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2243 return eventNotHandledErr
;
2249 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2251 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2252 if ( !wxWindowBase::Reparent(newParent
) )
2255 m_peer
->RemoveFromParent();
2256 m_peer
->Embed( GetParent()->GetPeer() );
2260 bool wxWindowMac::SetTransparent(wxByte alpha
)
2262 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2264 if ( alpha
!= m_macAlpha
)
2266 m_macAlpha
= alpha
;
2273 bool wxWindowMac::CanSetTransparent()
2278 wxByte
wxWindowMac::GetTransparent() const
2283 bool wxWindowMac::IsShownOnScreen() const
2285 if ( m_peer
&& m_peer
->IsOk() )
2287 bool peerVis
= m_peer
->IsVisible();
2288 bool wxVis
= wxWindowBase::IsShownOnScreen();
2289 if( peerVis
!= wxVis
)
2291 // CS : put a breakpoint here to investigate differences
2292 // between native an wx visibilities
2293 // the only place where I've encountered them until now
2294 // are the hiding/showing sequences where the vis-changed event is
2295 // first sent to the innermost control, while wx does things
2296 // from the outmost control
2297 wxVis
= wxWindowBase::IsShownOnScreen();
2301 return m_peer
->IsVisible();
2303 return wxWindowBase::IsShownOnScreen();
2306 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2308 bool handled
= HandleWindowEvent( event
) ;
2309 if ( handled
&& event
.GetSkipped() )
2313 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2315 wxWindow
*ancestor
= this;
2318 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2321 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2323 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2324 handled
= handler
->ProcessEvent( command_event
);
2328 // accelerators can also be used with buttons, try them too
2329 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2330 handled
= handler
->ProcessEvent( command_event
);
2336 if (ancestor
->IsTopLevel())
2339 ancestor
= ancestor
->GetParent();
2342 #endif // wxUSE_ACCEL
2351 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2353 static MacControlMap wxWinMacControlList
;
2355 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2357 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2359 return impl
->GetWXPeer();
2364 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2366 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2368 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2371 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2373 // adding NULL ControlRef is (first) surely a result of an error and
2374 // (secondly) breaks native event processing
2375 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2377 wxWinMacControlList
[inControl
] = impl
;
2380 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2382 // iterate over all the elements in the class
2383 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2384 // we should go on...
2390 MacControlMap::iterator it
;
2391 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2393 if ( it
->second
== impl
)
2395 wxWinMacControlList
.erase(it
);
2403 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2405 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2408 m_isRootControl
= isRootControl
;
2412 wxWidgetImpl::wxWidgetImpl()
2417 wxWidgetImpl::~wxWidgetImpl()
2421 void wxWidgetImpl::Init()
2423 m_isRootControl
= false;
2425 m_needsFocusRect
= false;
2428 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2430 m_needsFocusRect
= needs
;
2433 bool wxWidgetImpl::NeedsFocusRect() const
2435 return m_needsFocusRect
;