1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
71 #include <Carbon/Carbon.h>
74 #define MAC_SCROLLBAR_SIZE 15
75 #define MAC_SMALL_SCROLLBAR_SIZE 11
79 #ifdef __WXUNIVERSAL__
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
82 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
85 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
86 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
87 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
88 EVT_PAINT(wxWindowMac::OnPaint
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 // ===========================================================================
99 // ===========================================================================
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 wxWindowMac::wxWindowMac()
110 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
115 const wxString
& name
)
118 Create(parent
, id
, pos
, size
, style
, name
);
121 void wxWindowMac::Init()
125 m_cgContextRef
= NULL
;
127 // as all windows are created with WS_VISIBLE style...
130 m_hScrollBar
= NULL
;
131 m_vScrollBar
= NULL
;
132 m_hScrollBarAlwaysShown
= false;
133 m_vScrollBarAlwaysShown
= false;
135 m_macIsUserPane
= true;
136 m_clipChildren
= false ;
137 m_cachedClippedRectValid
= false ;
140 wxWindowMac::~wxWindowMac()
144 m_isBeingDeleted
= true;
146 MacInvalidateBorders() ;
148 #ifndef __WXUNIVERSAL__
149 // VS: make sure there's no wxFrame with last focus set to us:
150 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
152 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
155 if ( frame
->GetLastFocus() == this )
156 frame
->SetLastFocus((wxWindow
*)NULL
);
162 // destroy children before destroying this window itself
165 // wxRemoveMacControlAssociation( this ) ;
166 // If we delete an item, we should initialize the parent panel,
167 // because it could now be invalid.
168 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
171 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
172 tlw
->SetDefaultItem(NULL
);
175 if ( g_MacLastWindow
== this )
176 g_MacLastWindow
= NULL
;
178 #ifndef __WXUNIVERSAL__
179 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
182 if ( frame
->GetLastFocus() == this )
183 frame
->SetLastFocus( NULL
) ;
187 // delete our drop target if we've got one
188 #if wxUSE_DRAG_AND_DROP
189 if ( m_dropTarget
!= NULL
)
199 WXWidget
wxWindowMac::GetHandle() const
201 return (WXWidget
) m_peer
->GetWXWidget() ;
205 // TODO END move to window_osx.cpp
208 // ---------------------------------------------------------------------------
209 // Utility Routines to move between different coordinate systems
210 // ---------------------------------------------------------------------------
213 * Right now we have the following setup :
214 * a border that is not part of the native control is always outside the
215 * control's border (otherwise we loose all native intelligence, future ways
216 * may be to have a second embedding control responsible for drawing borders
217 * and backgrounds eventually)
218 * so all this border calculations have to be taken into account when calling
219 * native methods or getting native oriented data
220 * so we have three coordinate systems here
221 * wx client coordinates
222 * wx window coordinates (including window frames)
230 bool wxWindowMac::Create(wxWindowMac
*parent
,
235 const wxString
& name
)
237 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
239 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
242 m_windowVariant
= parent
->GetWindowVariant() ;
244 if ( m_macIsUserPane
)
246 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
247 MacPostControlCreate(pos
, size
) ;
250 #ifndef __WXUNIVERSAL__
251 // Don't give scrollbars to wxControls unless they ask for them
252 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
253 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
255 MacCreateScrollBars( style
) ;
259 wxWindowCreateEvent
event((wxWindow
*)this);
260 GetEventHandler()->AddPendingEvent(event
);
265 void wxWindowMac::MacChildAdded()
268 m_vScrollBar
->Raise() ;
270 m_hScrollBar
->Raise() ;
273 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
275 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
277 GetParent()->AddChild( this );
279 m_peer
->InstallEventHandler();
280 m_peer
->Embed(GetParent()->GetPeer());
282 GetParent()->MacChildAdded() ;
284 // adjust font, controlsize etc
285 DoSetWindowVariant( m_windowVariant
) ;
287 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
289 // for controls we want to use best size for wxDefaultSize params )
290 if ( !m_macIsUserPane
)
291 SetInitialSize(size
);
293 SetCursor( *wxSTANDARD_CURSOR
) ;
296 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
298 // Don't assert, in case we set the window variant before
299 // the window is created
300 // wxASSERT( m_peer->Ok() ) ;
302 m_windowVariant
= variant
;
304 if (m_peer
== NULL
|| !m_peer
->IsOk())
307 m_peer
->SetControlSize( variant
);
311 // we will get that from the settings later
312 // and make this NORMAL later, but first
313 // we have a few calculations that we must fix
317 case wxWINDOW_VARIANT_NORMAL
:
318 size
= kControlSizeNormal
;
321 case wxWINDOW_VARIANT_SMALL
:
322 size
= kControlSizeSmall
;
325 case wxWINDOW_VARIANT_MINI
:
326 // not always defined in the headers
330 case wxWINDOW_VARIANT_LARGE
:
331 size
= kControlSizeLarge
;
335 wxFAIL_MSG(_T("unexpected window variant"));
338 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
341 #if wxOSX_USE_COCOA_OR_CARBON
344 #if wxOSX_USE_ATSU_TEXT
345 ThemeFontID themeFont
= kThemeSystemFont
;
347 // we will get that from the settings later
348 // and make this NORMAL later, but first
349 // we have a few calculations that we must fix
353 case wxWINDOW_VARIANT_NORMAL
:
354 themeFont
= kThemeSystemFont
;
357 case wxWINDOW_VARIANT_SMALL
:
358 themeFont
= kThemeSmallSystemFont
;
361 case wxWINDOW_VARIANT_MINI
:
362 // not always defined in the headers
366 case wxWINDOW_VARIANT_LARGE
:
367 themeFont
= kThemeSystemFont
;
371 wxFAIL_MSG(_T("unexpected window variant"));
375 font
.MacCreateFromThemeFont( themeFont
) ;
377 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
380 case wxWINDOW_VARIANT_NORMAL
:
381 themeFont
= kCTFontSystemFontType
;
384 case wxWINDOW_VARIANT_SMALL
:
385 themeFont
= kCTFontSmallSystemFontType
;
388 case wxWINDOW_VARIANT_MINI
:
389 themeFont
= kCTFontMiniSystemFontType
;
392 case wxWINDOW_VARIANT_LARGE
:
393 themeFont
= kCTFontSystemFontType
;
397 wxFAIL_MSG(_T("unexpected window variant"));
400 font
.MacCreateFromUIFont( themeFont
) ;
407 void wxWindowMac::MacUpdateControlFont()
410 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
412 // do not trigger refreshes upon invisible and possible partly created objects
413 if ( IsShownOnScreen() )
417 bool wxWindowMac::SetFont(const wxFont
& font
)
419 bool retval
= wxWindowBase::SetFont( font
);
421 MacUpdateControlFont() ;
426 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
428 bool retval
= wxWindowBase::SetForegroundColour( col
);
431 MacUpdateControlFont();
436 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
438 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
442 m_peer
->SetBackgroundColour( col
) ;
447 void wxWindowMac::SetFocus()
449 if ( !AcceptsFocus() )
452 wxWindow
* former
= FindFocus() ;
453 if ( former
== this )
459 void wxWindowMac::DoCaptureMouse()
461 wxApp::s_captureWindow
= (wxWindow
*) this ;
464 wxWindow
* wxWindowBase::GetCapture()
466 return wxApp::s_captureWindow
;
469 void wxWindowMac::DoReleaseMouse()
471 wxApp::s_captureWindow
= NULL
;
474 #if wxUSE_DRAG_AND_DROP
476 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
480 m_dropTarget
= pDropTarget
;
481 if ( m_dropTarget
!= NULL
)
489 // Old-style File Manager Drag & Drop
490 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
495 // From a wx position / size calculate the appropriate size of the native control
497 bool wxWindowMac::MacGetBoundsForControl(
501 int& w
, int& h
, bool adjustOrigin
) const
503 // the desired size, minus the border pixels gives the correct size of the control
507 w
= WidthDefault( size
.x
);
508 h
= HeightDefault( size
.y
);
510 x
+= MacGetLeftBorderSize() ;
511 y
+= MacGetTopBorderSize() ;
512 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
513 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
516 AdjustForParentClientOrigin( x
, y
) ;
518 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
519 if ( GetParent() && !GetParent()->IsTopLevel() )
521 x
-= GetParent()->MacGetLeftBorderSize() ;
522 y
-= GetParent()->MacGetTopBorderSize() ;
528 // Get window size (not client size)
529 void wxWindowMac::DoGetSize(int *x
, int *y
) const
532 m_peer
->GetSize( width
, height
);
535 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
537 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
540 // get the position of the bounds of this window in client coordinates of its parent
541 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
545 m_peer
->GetPosition( x1
, y1
) ;
547 // get the wx window position from the native one
548 x1
-= MacGetLeftBorderSize() ;
549 y1
-= MacGetTopBorderSize() ;
553 wxWindow
*parent
= GetParent();
556 // we must first adjust it to be in window coordinates of the parent,
557 // as otherwise it gets lost by the ClientAreaOrigin fix
558 x1
+= parent
->MacGetLeftBorderSize() ;
559 y1
+= parent
->MacGetTopBorderSize() ;
561 // and now to client coordinates
562 wxPoint
pt(parent
->GetClientAreaOrigin());
574 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
576 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
577 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
578 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
579 MacRootWindowToWindow( x
, y
) ;
581 wxPoint origin
= GetClientAreaOrigin() ;
588 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
590 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
591 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
593 wxPoint origin
= GetClientAreaOrigin() ;
599 MacWindowToRootWindow( x
, y
) ;
600 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
603 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
605 wxPoint origin
= GetClientAreaOrigin() ;
611 MacWindowToRootWindow( x
, y
) ;
614 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
625 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
628 pt
.x
-= MacGetLeftBorderSize() ;
629 pt
.y
-= MacGetTopBorderSize() ;
630 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
640 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
651 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
654 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
655 pt
.x
+= MacGetLeftBorderSize() ;
656 pt
.y
+= MacGetTopBorderSize() ;
666 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
668 wxSize sizeTotal
= size
;
670 int innerwidth
, innerheight
;
672 int outerwidth
, outerheight
;
674 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
675 m_peer
->GetSize( outerwidth
, outerheight
);
677 sizeTotal
.x
+= outerwidth
-innerwidth
;
678 sizeTotal
.y
+= outerheight
-innerheight
;
680 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
681 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
686 // Get size *available for subwindows* i.e. excluding menu bar etc.
687 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
693 m_peer
->GetContentArea( left
, top
, ww
, hh
);
695 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
696 hh
-= m_hScrollBar
->GetSize().y
;
698 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
699 ww
-= m_vScrollBar
->GetSize().x
;
707 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
709 if (m_cursor
.IsSameAs(cursor
))
714 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
719 if ( ! wxWindowBase::SetCursor( cursor
) )
723 wxASSERT_MSG( m_cursor
.Ok(),
724 wxT("cursor must be valid after call to the base version"));
726 wxWindowMac
*mouseWin
= 0 ;
729 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
730 WindowRef window
= (WindowRef
) ( tlw
? tlw
->GetWXWindow() : 0 ) ;
732 ControlPartCode part
;
735 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
737 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
741 GetGlobalMouse( &pt
);
744 ScreenToClient(&x
, &y
);
748 control
= FindControlUnderMouse( pt
, window
, &part
) ;
750 mouseWin
= wxFindWindowFromWXWidget( (WXWidget
) control
) ;
755 if ( mouseWin
== this && !wxIsBusy() )
756 m_cursor
.MacInstall() ;
762 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
764 #ifndef __WXUNIVERSAL__
765 menu
->SetInvokingWindow((wxWindow
*)this);
768 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
770 wxPoint mouse
= wxGetMousePosition();
776 ClientToScreen( &x
, &y
) ;
778 menu
->GetPeer()->PopUp(this, x
, y
);
779 menu
->SetInvokingWindow( NULL
);
782 // actually this shouldn't be called, because universal is having its own implementation
788 // ----------------------------------------------------------------------------
790 // ----------------------------------------------------------------------------
794 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
796 wxWindowBase::DoSetToolTip(tooltip
);
799 m_tooltip
->SetWindow(this);
804 void wxWindowMac::MacInvalidateBorders()
806 if ( m_peer
== NULL
)
809 bool vis
= IsShownOnScreen() ;
813 int outerBorder
= MacGetLeftBorderSize() ;
815 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
819 if ( outerBorder
== 0 )
822 // now we know that we have something to do at all
827 m_peer
->GetSize( tw
, th
);
828 m_peer
->GetPosition( tx
, ty
);
830 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
831 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
832 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
833 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
836 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
837 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
838 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
839 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
843 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
845 // this is never called for a toplevel window, so we know we have a parent
846 int former_x
, former_y
, former_w
, former_h
;
848 // Get true coordinates of former position
849 DoGetPosition( &former_x
, &former_y
) ;
850 DoGetSize( &former_w
, &former_h
) ;
852 wxWindow
*parent
= GetParent();
855 wxPoint
pt(parent
->GetClientAreaOrigin());
860 int actualWidth
= width
;
861 int actualHeight
= height
;
865 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
866 actualWidth
= m_minWidth
;
867 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
868 actualHeight
= m_minHeight
;
869 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
870 actualWidth
= m_maxWidth
;
871 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
872 actualHeight
= m_maxHeight
;
874 bool doMove
= false, doResize
= false ;
876 if ( actualX
!= former_x
|| actualY
!= former_y
)
879 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
882 if ( doMove
|| doResize
)
884 // as the borders are drawn outside the native control, we adjust now
886 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
887 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
888 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
890 if ( parent
&& !parent
->IsTopLevel() )
892 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
895 MacInvalidateBorders() ;
897 m_cachedClippedRectValid
= false ;
899 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
901 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
903 MacInvalidateBorders() ;
905 MacRepositionScrollBars() ;
908 wxPoint
point(actualX
, actualY
);
909 wxMoveEvent
event(point
, m_windowId
);
910 event
.SetEventObject(this);
911 HandleWindowEvent(event
) ;
916 MacRepositionScrollBars() ;
917 wxSize
size(actualWidth
, actualHeight
);
918 wxSizeEvent
event(size
, m_windowId
);
919 event
.SetEventObject(this);
920 HandleWindowEvent(event
);
925 wxSize
wxWindowMac::DoGetBestSize() const
927 if ( m_macIsUserPane
|| IsTopLevel() )
929 return wxWindowBase::DoGetBestSize() ;
935 m_peer
->GetBestRect(&r
);
937 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
944 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
949 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
956 // return wxWindowBase::DoGetBestSize() ;
960 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
961 MacGetRightBorderSize();
962 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
963 MacGetBottomBorderSize();
964 if ( bestHeight
< 10 )
967 return wxSize(bestWidth
, bestHeight
);
971 // set the size of the window: if the dimensions are positive, just use them,
972 // but if any of them is equal to -1, it means that we must find the value for
973 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
974 // which case -1 is a valid value for x and y)
976 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
977 // the width/height to best suit our contents, otherwise we reuse the current
979 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
981 // get the current size and position...
982 int currentX
, currentY
;
983 int currentW
, currentH
;
985 GetPosition(¤tX
, ¤tY
);
986 GetSize(¤tW
, ¤tH
);
988 // ... and don't do anything (avoiding flicker) if it's already ok
989 if ( x
== currentX
&& y
== currentY
&&
990 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
993 MacRepositionScrollBars() ; // we might have a real position shift
998 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1000 if ( x
== wxDefaultCoord
)
1002 if ( y
== wxDefaultCoord
)
1006 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1008 wxSize size
= wxDefaultSize
;
1009 if ( width
== wxDefaultCoord
)
1011 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1013 size
= DoGetBestSize();
1018 // just take the current one
1023 if ( height
== wxDefaultCoord
)
1025 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1027 if ( size
.x
== wxDefaultCoord
)
1028 size
= DoGetBestSize();
1029 // else: already called DoGetBestSize() above
1035 // just take the current one
1040 DoMoveWindow( x
, y
, width
, height
);
1043 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1045 int left
,top
,width
,height
;
1046 m_peer
->GetContentArea( left
, top
, width
, height
);
1047 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1050 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1052 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1054 int currentclientwidth
, currentclientheight
;
1055 int currentwidth
, currentheight
;
1057 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1058 GetSize( ¤twidth
, ¤theight
) ;
1060 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1061 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1065 void wxWindowMac::SetLabel(const wxString
& title
)
1069 if ( m_peer
&& m_peer
->IsOk() )
1070 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1072 // do not trigger refreshes upon invisible and possible partly created objects
1073 if ( IsShownOnScreen() )
1077 wxString
wxWindowMac::GetLabel() const
1082 bool wxWindowMac::Show(bool show
)
1084 if ( !wxWindowBase::Show(show
) )
1088 m_peer
->SetVisibility( show
) ;
1093 void wxWindowMac::DoEnable(bool enable
)
1095 m_peer
->Enable( enable
) ;
1099 // status change notifications
1102 void wxWindowMac::MacVisibilityChanged()
1106 void wxWindowMac::MacHiliteChanged()
1110 void wxWindowMac::MacEnabledStateChanged()
1112 OnEnabled( m_peer
->IsEnabled() );
1116 // status queries on the inherited window's state
1119 bool wxWindowMac::MacIsReallyEnabled()
1121 return m_peer
->IsEnabled() ;
1124 bool wxWindowMac::MacIsReallyHilited()
1126 #if wxOSX_USE_CARBON
1127 return m_peer
->IsActive();
1129 return true; // TODO
1133 int wxWindowMac::GetCharHeight() const
1136 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1141 int wxWindowMac::GetCharWidth() const
1144 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1149 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1150 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1152 const wxFont
*fontToUse
= theFont
;
1156 tempFont
= GetFont();
1157 fontToUse
= &tempFont
;
1160 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1161 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1163 wxDouble h
, d
, e
, w
;
1164 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1168 if ( externalLeading
)
1169 *externalLeading
= (wxCoord
)(e
+0.5);
1171 *descent
= (wxCoord
)(d
+0.5);
1173 *x
= (wxCoord
)(w
+0.5);
1175 *y
= (wxCoord
)(h
+0.5);
1179 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1180 * we always intersect with the entire window, not only with the client area
1183 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1185 if ( m_peer
== NULL
)
1188 if ( !IsShownOnScreen() )
1191 m_peer
->SetNeedsDisplay( rect
) ;
1194 void wxWindowMac::DoFreeze()
1196 #if wxOSX_USE_CARBON
1197 if ( m_peer
&& m_peer
->IsOk() )
1198 m_peer
->SetDrawingEnabled( false ) ;
1202 void wxWindowMac::DoThaw()
1204 #if wxOSX_USE_CARBON
1205 if ( m_peer
&& m_peer
->IsOk() )
1207 m_peer
->SetDrawingEnabled( true ) ;
1208 m_peer
->InvalidateWithChildren() ;
1213 wxWindow
*wxGetActiveWindow()
1215 // actually this is a windows-only concept
1219 // Coordinates relative to the window
1220 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1222 // We really don't move the mouse programmatically under Mac.
1225 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1227 if ( MacGetTopLevelWindow() == NULL
)
1230 #if TARGET_API_MAC_OSX
1231 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1237 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1239 event
.GetDC()->Clear() ;
1241 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1243 // don't skip the event here, custom background means that the app
1244 // is drawing it itself in its OnPaint(), so don't draw it at all
1245 // now to avoid flicker
1253 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1258 int wxWindowMac::GetScrollPos(int orient
) const
1260 if ( orient
== wxHORIZONTAL
)
1263 return m_hScrollBar
->GetThumbPosition() ;
1268 return m_vScrollBar
->GetThumbPosition() ;
1274 // This now returns the whole range, not just the number
1275 // of positions that we can scroll.
1276 int wxWindowMac::GetScrollRange(int orient
) const
1278 if ( orient
== wxHORIZONTAL
)
1281 return m_hScrollBar
->GetRange() ;
1286 return m_vScrollBar
->GetRange() ;
1292 int wxWindowMac::GetScrollThumb(int orient
) const
1294 if ( orient
== wxHORIZONTAL
)
1297 return m_hScrollBar
->GetThumbSize() ;
1302 return m_vScrollBar
->GetThumbSize() ;
1308 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1310 if ( orient
== wxHORIZONTAL
)
1313 m_hScrollBar
->SetThumbPosition( pos
) ;
1318 m_vScrollBar
->SetThumbPosition( pos
) ;
1323 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1325 bool needVisibilityUpdate
= false;
1327 if ( m_hScrollBarAlwaysShown
!= hflag
)
1329 m_hScrollBarAlwaysShown
= hflag
;
1330 needVisibilityUpdate
= true;
1333 if ( m_vScrollBarAlwaysShown
!= vflag
)
1335 m_vScrollBarAlwaysShown
= vflag
;
1336 needVisibilityUpdate
= true;
1339 if ( needVisibilityUpdate
)
1340 DoUpdateScrollbarVisibility();
1344 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1345 // our own window origin is at leftOrigin/rightOrigin
1348 void wxWindowMac::MacPaintGrowBox()
1353 if ( MacHasScrollBarCorner() )
1355 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1356 wxASSERT( cgContext
) ;
1360 m_peer
->GetSize( tw
, th
);
1361 m_peer
->GetPosition( tx
, ty
);
1363 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1366 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1367 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1368 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1369 CGContextSaveGState( cgContext
);
1371 if ( m_backgroundColour
.Ok() )
1373 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1377 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1379 CGContextFillRect( cgContext
, cgrect
);
1380 CGContextRestoreGState( cgContext
);
1384 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1389 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1391 // back to the surrounding frame rectangle
1394 m_peer
->GetSize( tw
, th
);
1395 m_peer
->GetPosition( tx
, ty
);
1397 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1399 #if wxOSX_USE_COCOA_OR_CARBON
1401 InsetRect( &rect
, -1 , -1 ) ;
1404 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1405 rect
.bottom
- rect
.top
) ;
1407 HIThemeFrameDrawInfo info
;
1408 memset( &info
, 0 , sizeof(info
) ) ;
1412 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1413 info
.isFocused
= hasFocus
;
1415 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1416 wxASSERT( cgContext
) ;
1418 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1420 info
.kind
= kHIThemeFrameTextFieldSquare
;
1421 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1423 else if ( HasFlag(wxSIMPLE_BORDER
) )
1425 info
.kind
= kHIThemeFrameListBox
;
1426 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1428 else if ( hasFocus
)
1430 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1432 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1433 m_peer
->GetRect( &rect
) ;
1434 if ( MacHasScrollBarCorner() )
1436 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1437 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1438 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1439 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1440 HIThemeGrowBoxDrawInfo info
;
1441 memset( &info
, 0, sizeof(info
) ) ;
1443 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1444 info
.kind
= kHIThemeGrowBoxKindNone
;
1445 // contrary to the docs ...SizeSmall does not work
1446 info
.size
= kHIThemeGrowBoxSizeNormal
;
1447 info
.direction
= 0 ;
1448 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1452 #endif // wxOSX_USE_COCOA_OR_CARBON
1455 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1457 if ( child
== m_hScrollBar
)
1458 m_hScrollBar
= NULL
;
1459 if ( child
== m_vScrollBar
)
1460 m_vScrollBar
= NULL
;
1462 wxWindowBase::RemoveChild( child
) ;
1465 void wxWindowMac::DoUpdateScrollbarVisibility()
1467 bool triggerSizeEvent
= false;
1471 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1473 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1475 m_hScrollBar
->Show( showHScrollBar
);
1476 triggerSizeEvent
= true;
1482 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1484 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1486 m_vScrollBar
->Show( showVScrollBar
) ;
1487 triggerSizeEvent
= true;
1491 MacRepositionScrollBars() ;
1492 if ( triggerSizeEvent
)
1494 wxSizeEvent
event(GetSize(), m_windowId
);
1495 event
.SetEventObject(this);
1496 HandleWindowEvent(event
);
1500 // New function that will replace some of the above.
1501 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1502 int range
, bool refresh
)
1504 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1505 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1506 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1507 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1509 DoUpdateScrollbarVisibility();
1512 // Does a physical scroll
1513 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1515 if ( dx
== 0 && dy
== 0 )
1518 int width
, height
;
1519 GetClientSize( &width
, &height
) ;
1522 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1524 scrollrect
.Intersect( *rect
) ;
1525 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1526 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1528 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1533 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1535 child
= node
->GetData();
1538 if (child
== m_vScrollBar
)
1540 if (child
== m_hScrollBar
)
1542 if (child
->IsTopLevel())
1545 child
->GetPosition( &x
, &y
);
1546 child
->GetSize( &w
, &h
);
1549 wxRect
rc( x
, y
, w
, h
);
1550 if (rect
->Intersects( rc
))
1551 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1555 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1560 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1562 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1564 wxScrollWinEvent wevent
;
1565 wevent
.SetPosition(event
.GetPosition());
1566 wevent
.SetOrientation(event
.GetOrientation());
1567 wevent
.SetEventObject(this);
1569 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1570 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1571 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1572 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1573 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1574 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1575 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1576 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1577 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1578 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1579 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1580 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1581 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1582 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1583 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1584 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1586 HandleWindowEvent(wevent
);
1590 // Get the window with the focus
1591 wxWindow
*wxWindowBase::DoFindFocus()
1593 #if wxOSX_USE_CARBON
1594 ControlRef control
;
1595 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1596 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1602 void wxWindowMac::OnInternalIdle()
1604 // This calls the UI-update mechanism (querying windows for
1605 // menu/toolbar/control state information)
1606 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1607 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1610 // Raise the window to the top of the Z order
1611 void wxWindowMac::Raise()
1616 // Lower the window to the bottom of the Z order
1617 void wxWindowMac::Lower()
1622 // static wxWindow *gs_lastWhich = NULL;
1624 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1626 // first trigger a set cursor event
1628 wxPoint clientorigin
= GetClientAreaOrigin() ;
1629 wxSize clientsize
= GetClientSize() ;
1631 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1633 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1635 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1636 if ( processedEvtSetCursor
&& event
.HasCursor() )
1638 cursor
= event
.GetCursor() ;
1642 // the test for processedEvtSetCursor is here to prevent using m_cursor
1643 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1644 // it - this is a way to say that our cursor shouldn't be used for this
1646 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1649 if ( !wxIsBusy() && !GetParent() )
1650 cursor
= *wxSTANDARD_CURSOR
;
1654 cursor
.MacInstall() ;
1657 return cursor
.Ok() ;
1660 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1664 return m_tooltip
->GetTip() ;
1667 return wxEmptyString
;
1670 void wxWindowMac::ClearBackground()
1676 void wxWindowMac::Update()
1678 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1683 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1685 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1689 if ( iter
->IsTopLevel() )
1691 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1695 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1700 iter
= iter
->GetParent() ;
1706 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1708 MacUpdateClippedRects() ;
1710 return m_cachedClippedClientRect
;
1713 const wxRect
& wxWindowMac::MacGetClippedRect() const
1715 MacUpdateClippedRects() ;
1717 return m_cachedClippedRect
;
1720 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1722 MacUpdateClippedRects() ;
1724 return m_cachedClippedRectWithOuterStructure
;
1727 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1729 static wxRegion emptyrgn
;
1731 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1733 MacUpdateClippedRects() ;
1734 if ( includeOuterStructures
)
1735 return m_cachedClippedRegionWithOuterStructure
;
1737 return m_cachedClippedRegion
;
1745 void wxWindowMac::MacUpdateClippedRects() const
1747 #if wxOSX_USE_CARBON
1748 if ( m_cachedClippedRectValid
)
1751 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1752 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1753 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1754 // to add focus borders everywhere
1756 Rect rIncludingOuterStructures
;
1760 m_peer
->GetSize( tw
, th
);
1761 m_peer
->GetPosition( tx
, ty
);
1763 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1765 r
.left
-= MacGetLeftBorderSize() ;
1766 r
.top
-= MacGetTopBorderSize() ;
1767 r
.bottom
+= MacGetBottomBorderSize() ;
1768 r
.right
+= MacGetRightBorderSize() ;
1775 rIncludingOuterStructures
= r
;
1776 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1778 wxRect cl
= GetClientRect() ;
1779 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1783 const wxWindow
* child
= (wxWindow
*) this ;
1784 const wxWindow
* parent
= NULL
;
1786 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1788 if ( parent
->MacIsChildOfClientArea(child
) )
1790 size
= parent
->GetClientSize() ;
1791 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1797 // this will be true for scrollbars, toolbars etc.
1798 size
= parent
->GetSize() ;
1799 y
= parent
->MacGetTopBorderSize() ;
1800 x
= parent
->MacGetLeftBorderSize() ;
1801 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1802 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1805 parent
->MacWindowToRootWindow( &x
, &y
) ;
1806 MacRootWindowToWindow( &x
, &y
) ;
1808 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1810 // the wxwindow and client rects will always be clipped
1811 SectRect( &r
, &rparent
, &r
) ;
1812 SectRect( &rClient
, &rparent
, &rClient
) ;
1814 // the structure only at 'hard' borders
1815 if ( parent
->MacClipChildren() ||
1816 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1818 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1824 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1825 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1826 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1827 m_cachedClippedRectWithOuterStructure
= wxRect(
1828 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1829 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1830 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1832 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1833 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1834 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1836 m_cachedClippedRectValid
= true ;
1841 This function must not change the updatergn !
1843 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1845 bool handled
= false ;
1846 #if wxOSX_USE_CARBON
1848 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1849 GetRegionBounds( updatergn
, &updatebounds
) ;
1851 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1853 if ( !EmptyRgn(updatergn
) )
1855 RgnHandle newupdate
= NewRgn() ;
1856 wxSize point
= GetClientSize() ;
1857 wxPoint origin
= GetClientAreaOrigin() ;
1858 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1859 SectRgn( newupdate
, updatergn
, newupdate
) ;
1861 // first send an erase event to the entire update area
1863 // for the toplevel window this really is the entire area
1864 // for all the others only their client area, otherwise they
1865 // might be drawing with full alpha and eg put blue into
1866 // the grow-box area of a scrolled window (scroll sample)
1867 wxDC
* dc
= new wxWindowDC(this);
1869 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1871 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1873 wxEraseEvent
eevent( GetId(), dc
);
1874 eevent
.SetEventObject( this );
1875 HandleWindowEvent( eevent
);
1881 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1882 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1883 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1884 DisposeRgn( newupdate
) ;
1886 if ( !m_updateRegion
.Empty() )
1888 // paint the window itself
1891 event
.SetTimestamp(time
);
1892 event
.SetEventObject(this);
1893 HandleWindowEvent(event
);
1897 // now we cannot rely on having its borders drawn by a window itself, as it does not
1898 // get the updateRgn wide enough to always do so, so we do it from the parent
1899 // this would also be the place to draw any custom backgrounds for native controls
1900 // in Composited windowing
1901 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1905 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1907 child
= node
->GetData();
1910 if (child
== m_vScrollBar
)
1912 if (child
== m_hScrollBar
)
1914 if (child
->IsTopLevel())
1916 if (!child
->IsShown())
1919 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1921 child
->GetPosition( &x
, &y
);
1922 child
->GetSize( &w
, &h
);
1923 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1924 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1925 InsetRect( &childRect
, -10 , -10) ;
1927 if ( RectInRgn( &childRect
, updatergn
) )
1929 // paint custom borders
1930 wxNcPaintEvent
eventNc( child
->GetId() );
1931 eventNc
.SetEventObject( child
);
1932 if ( !child
->HandleWindowEvent( eventNc
) )
1934 child
->MacPaintBorders(0, 0) ;
1944 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1946 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1947 return tlw
? tlw
->GetWXWindow() : NULL
;
1950 bool wxWindowMac::MacHasScrollBarCorner() const
1952 /* Returns whether the scroll bars in a wxScrolledWindow should be
1953 * shortened. Scroll bars should be shortened if either:
1955 * - both scroll bars are visible, or
1957 * - there is a resize box in the parent frame's corner and this
1958 * window shares the bottom and right edge with the parent
1962 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1965 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1966 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1968 // Both scroll bars visible
1973 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1975 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1977 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1980 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1982 // Parent frame has resize handle
1983 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1985 // Note: allow for some wiggle room here as wxMac's
1986 // window rect calculations seem to be imprecise
1987 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1988 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1990 // Parent frame has resize handle and shares
1991 // right bottom corner
1996 // Parent frame has resize handle but doesn't
1997 // share right bottom corner
2003 // Parent frame doesn't have resize handle
2009 // No parent frame found
2014 void wxWindowMac::MacCreateScrollBars( long style
)
2016 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2018 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2020 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2021 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2023 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2026 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2028 GetClientSize( &width
, &height
) ;
2030 wxPoint
vPoint(width
- scrlsize
, 0) ;
2031 wxSize
vSize(scrlsize
, height
- adjust
) ;
2032 wxPoint
hPoint(0, height
- scrlsize
) ;
2033 wxSize
hSize(width
- adjust
, scrlsize
) ;
2035 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2036 if ( style
& wxVSCROLL
)
2038 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2039 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2042 if ( style
& wxHSCROLL
)
2044 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2045 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2049 // because the create does not take into account the client area origin
2050 // we might have a real position shift
2051 MacRepositionScrollBars() ;
2054 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2056 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2061 void wxWindowMac::MacRepositionScrollBars()
2063 if ( !m_hScrollBar
&& !m_vScrollBar
)
2066 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2067 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2069 // get real client area
2071 GetSize( &width
, &height
);
2073 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2074 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2076 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2077 wxSize
vSize( scrlsize
, height
- adjust
) ;
2078 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2079 wxSize
hSize( width
- adjust
, scrlsize
) ;
2082 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2084 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2087 bool wxWindowMac::AcceptsFocus() const
2089 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2092 void wxWindowMac::MacSuperChangedPosition()
2094 // only window-absolute structures have to be moved i.e. controls
2096 m_cachedClippedRectValid
= false ;
2099 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2102 child
= node
->GetData();
2103 child
->MacSuperChangedPosition() ;
2105 node
= node
->GetNext();
2109 void wxWindowMac::MacTopLevelWindowChangedPosition()
2111 // only screen-absolute structures have to be moved i.e. glcanvas
2114 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2117 child
= node
->GetData();
2118 child
->MacTopLevelWindowChangedPosition() ;
2120 node
= node
->GetNext();
2124 long wxWindowMac::MacGetLeftBorderSize() const
2131 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2133 #if wxOSX_USE_COCOA_OR_CARBON
2134 // this metric is only the 'outset' outside the simple frame rect
2135 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2141 else if (HasFlag(wxSIMPLE_BORDER
))
2143 #if wxOSX_USE_COCOA_OR_CARBON
2144 // this metric is only the 'outset' outside the simple frame rect
2145 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2155 long wxWindowMac::MacGetRightBorderSize() const
2157 // they are all symmetric in mac themes
2158 return MacGetLeftBorderSize() ;
2161 long wxWindowMac::MacGetTopBorderSize() const
2163 // they are all symmetric in mac themes
2164 return MacGetLeftBorderSize() ;
2167 long wxWindowMac::MacGetBottomBorderSize() const
2169 // they are all symmetric in mac themes
2170 return MacGetLeftBorderSize() ;
2173 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2175 return style
& ~wxBORDER_MASK
;
2178 // Find the wxWindowMac at the current mouse position, returning the mouse
2180 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2182 pt
= wxGetMousePosition();
2183 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2185 return (wxWindow
*) found
;
2188 // Get the current mouse position.
2189 wxPoint
wxGetMousePosition()
2193 wxGetMousePosition( &x
, &y
);
2195 return wxPoint(x
, y
);
2198 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2200 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2202 // copied from wxGTK : CS
2203 // VZ: shouldn't we move this to base class then?
2205 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2208 // (a) it's a command event and so is propagated to the parent
2209 // (b) under MSW it can be generated from kbd too
2210 // (c) it uses screen coords (because of (a))
2211 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2213 this->ClientToScreen(event
.GetPosition()));
2214 evtCtx
.SetEventObject(this);
2215 if ( ! HandleWindowEvent(evtCtx
) )
2224 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2226 #if wxOSX_USE_COCOA_OR_CARBON
2227 // for native controls: call their native paint method
2228 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2230 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2231 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2232 CallNextEventHandler(
2233 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2234 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2239 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2240 wxInt16
WXUNUSED(controlpart
),
2241 bool WXUNUSED(mouseStillDown
))
2245 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2249 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2250 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2255 bool wxWindowMac::HandleClicked( double timestampsec
)
2260 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2262 #if wxOSX_USE_COCOA_OR_CARBON
2263 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2266 return eventNotHandledErr
;
2272 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2274 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2275 if ( !wxWindowBase::Reparent(newParent
) )
2278 m_peer
->RemoveFromParent();
2279 m_peer
->Embed( GetParent()->GetPeer() );
2283 bool wxWindowMac::SetTransparent(wxByte alpha
)
2285 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2287 if ( alpha
!= m_macAlpha
)
2289 m_macAlpha
= alpha
;
2296 bool wxWindowMac::CanSetTransparent()
2301 wxByte
wxWindowMac::GetTransparent() const
2306 bool wxWindowMac::IsShownOnScreen() const
2308 if ( m_peer
&& m_peer
->IsOk() )
2310 bool peerVis
= m_peer
->IsVisible();
2311 bool wxVis
= wxWindowBase::IsShownOnScreen();
2312 if( peerVis
!= wxVis
)
2314 // CS : put a breakpoint here to investigate differences
2315 // between native an wx visibilities
2316 // the only place where I've encountered them until now
2317 // are the hiding/showing sequences where the vis-changed event is
2318 // first sent to the innermost control, while wx does things
2319 // from the outmost control
2320 wxVis
= wxWindowBase::IsShownOnScreen();
2324 return m_peer
->IsVisible();
2326 return wxWindowBase::IsShownOnScreen();
2333 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2335 static MacControlMap wxWinMacControlList
;
2337 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2339 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2341 return impl
->GetWXPeer();
2346 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2348 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2350 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2353 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2355 // adding NULL ControlRef is (first) surely a result of an error and
2356 // (secondly) breaks native event processing
2357 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2359 wxWinMacControlList
[inControl
] = impl
;
2362 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2364 // iterate over all the elements in the class
2365 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2366 // we should go on...
2372 MacControlMap::iterator it
;
2373 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2375 if ( it
->second
== impl
)
2377 wxWinMacControlList
.erase(it
);
2385 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2387 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2390 m_isRootControl
= isRootControl
;
2394 wxWidgetImpl::wxWidgetImpl()
2399 wxWidgetImpl::~wxWidgetImpl()
2403 void wxWidgetImpl::Init()
2405 m_isRootControl
= false;
2407 m_needsFocusRect
= false;
2410 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2412 m_needsFocusRect
= needs
;
2415 bool wxWidgetImpl::NeedsFocusRect() const
2417 return m_needsFocusRect
;