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
65 #include "wx/osx/uma.h"
67 #include "wx/osx/private.h"
69 #include <Carbon/Carbon.h>
72 #define MAC_SCROLLBAR_SIZE 15
73 #define MAC_SMALL_SCROLLBAR_SIZE 11
77 #ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
80 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
85 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
86 EVT_PAINT(wxWindowMac::OnPaint
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 // ===========================================================================
97 // ===========================================================================
99 // ----------------------------------------------------------------------------
100 // constructors and such
101 // ----------------------------------------------------------------------------
103 wxWindowMac::wxWindowMac()
108 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
113 const wxString
& name
)
116 Create(parent
, id
, pos
, size
, style
, name
);
119 void wxWindowMac::Init()
123 m_cgContextRef
= NULL
;
125 // as all windows are created with WS_VISIBLE style...
128 m_hScrollBar
= NULL
;
129 m_vScrollBar
= NULL
;
130 m_hScrollBarAlwaysShown
= false;
131 m_vScrollBarAlwaysShown
= false;
133 m_macIsUserPane
= true;
134 m_clipChildren
= false ;
135 m_cachedClippedRectValid
= false ;
138 wxWindowMac::~wxWindowMac()
142 m_isBeingDeleted
= true;
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((wxWindow
*)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") ) ;
276 m_peer
->SetReference( (URefCon
) this ) ;
279 GetParent()->AddChild( this );
282 m_peer
->InstallEventHandler();
284 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
285 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
286 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
288 GetParent()->MacChildAdded() ;
290 // adjust font, controlsize etc
291 DoSetWindowVariant( m_windowVariant
) ;
293 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
295 if (!m_macIsUserPane
)
296 SetInitialSize(size
);
298 SetCursor( *wxSTANDARD_CURSOR
) ;
301 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
303 // Don't assert, in case we set the window variant before
304 // the window is created
305 // wxASSERT( m_peer->Ok() ) ;
307 m_windowVariant
= variant
;
309 if (m_peer
== NULL
|| !m_peer
->IsOk())
312 m_peer
->SetControlSize( variant
);
313 #if wxOSX_USE_COCOA_OR_CARBON
318 ThemeFontID themeFont
= kThemeSystemFont
;
320 // we will get that from the settings later
321 // and make this NORMAL later, but first
322 // we have a few calculations that we must fix
326 case wxWINDOW_VARIANT_NORMAL
:
327 size
= kControlSizeNormal
;
328 themeFont
= kThemeSystemFont
;
331 case wxWINDOW_VARIANT_SMALL
:
332 size
= kControlSizeSmall
;
333 themeFont
= kThemeSmallSystemFont
;
336 case wxWINDOW_VARIANT_MINI
:
337 // not always defined in the headers
342 case wxWINDOW_VARIANT_LARGE
:
343 size
= kControlSizeLarge
;
344 themeFont
= kThemeSystemFont
;
348 wxFAIL_MSG(_T("unexpected window variant"));
352 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
353 font
.MacCreateFromThemeFont( themeFont
) ;
355 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
358 case wxWINDOW_VARIANT_NORMAL
:
359 themeFont
= kCTFontSystemFontType
;
362 case wxWINDOW_VARIANT_SMALL
:
363 themeFont
= kCTFontSmallSystemFontType
;
366 case wxWINDOW_VARIANT_MINI
:
367 themeFont
= kCTFontMiniSystemFontType
;
370 case wxWINDOW_VARIANT_LARGE
:
371 themeFont
= kCTFontSystemFontType
;
375 wxFAIL_MSG(_T("unexpected window variant"));
378 font
.MacCreateFromUIFont( themeFont
) ;
385 void wxWindowMac::MacUpdateControlFont()
388 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
390 // do not trigger refreshes upon invisible and possible partly created objects
391 if ( IsShownOnScreen() )
395 bool wxWindowMac::SetFont(const wxFont
& font
)
397 bool retval
= wxWindowBase::SetFont( font
);
399 MacUpdateControlFont() ;
404 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
406 bool retval
= wxWindowBase::SetForegroundColour( col
);
409 MacUpdateControlFont();
414 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
416 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
420 m_peer
->SetBackgroundColour( col
) ;
425 void wxWindowMac::SetFocus()
427 if ( !AcceptsFocus() )
430 wxWindow
* former
= FindFocus() ;
431 if ( former
== this )
437 void wxWindowMac::DoCaptureMouse()
439 wxApp::s_captureWindow
= (wxWindow
*) this ;
442 wxWindow
* wxWindowBase::GetCapture()
444 return wxApp::s_captureWindow
;
447 void wxWindowMac::DoReleaseMouse()
449 wxApp::s_captureWindow
= NULL
;
452 #if wxUSE_DRAG_AND_DROP
454 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
456 if ( m_dropTarget
!= NULL
)
459 m_dropTarget
= pDropTarget
;
460 if ( m_dropTarget
!= NULL
)
468 // Old-style File Manager Drag & Drop
469 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
474 // From a wx position / size calculate the appropriate size of the native control
476 bool wxWindowMac::MacGetBoundsForControl(
480 int& w
, int& h
, bool adjustOrigin
) const
482 // the desired size, minus the border pixels gives the correct size of the control
486 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
487 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
488 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
490 x
+= MacGetLeftBorderSize() ;
491 y
+= MacGetTopBorderSize() ;
492 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
493 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
496 AdjustForParentClientOrigin( x
, y
) ;
498 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
499 if ( !GetParent()->IsTopLevel() )
501 x
-= GetParent()->MacGetLeftBorderSize() ;
502 y
-= GetParent()->MacGetTopBorderSize() ;
508 // Get window size (not client size)
509 void wxWindowMac::DoGetSize(int *x
, int *y
) const
512 m_peer
->GetSize( width
, height
);
515 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
517 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
520 // get the position of the bounds of this window in client coordinates of its parent
521 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
525 m_peer
->GetPosition( x1
, y1
) ;
527 // get the wx window position from the native one
528 x1
-= MacGetLeftBorderSize() ;
529 y1
-= MacGetTopBorderSize() ;
533 wxWindow
*parent
= GetParent();
536 // we must first adjust it to be in window coordinates of the parent,
537 // as otherwise it gets lost by the ClientAreaOrigin fix
538 x1
+= parent
->MacGetLeftBorderSize() ;
539 y1
+= parent
->MacGetTopBorderSize() ;
541 // and now to client coordinates
542 wxPoint
pt(parent
->GetClientAreaOrigin());
554 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
556 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
557 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
558 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
559 MacRootWindowToWindow( x
, y
) ;
561 wxPoint origin
= GetClientAreaOrigin() ;
568 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
570 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
571 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
573 wxPoint origin
= GetClientAreaOrigin() ;
579 MacWindowToRootWindow( x
, y
) ;
580 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
583 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
585 wxPoint origin
= GetClientAreaOrigin() ;
591 MacWindowToRootWindow( x
, y
) ;
594 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
605 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
608 pt
.x
-= MacGetLeftBorderSize() ;
609 pt
.y
-= MacGetTopBorderSize() ;
610 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
620 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
631 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
634 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
635 pt
.x
+= MacGetLeftBorderSize() ;
636 pt
.y
+= MacGetTopBorderSize() ;
646 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
648 wxSize sizeTotal
= size
;
650 int innerwidth
, innerheight
;
652 int outerwidth
, outerheight
;
654 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
655 m_peer
->GetSize( outerwidth
, outerheight
);
657 sizeTotal
.x
+= left
+ (outerwidth
-innerwidth
);
658 sizeTotal
.y
+= top
+ (outerheight
-innerheight
);
660 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
661 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
666 // Get size *available for subwindows* i.e. excluding menu bar etc.
667 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
673 m_peer
->GetContentArea( left
, top
, ww
, hh
);
675 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
676 hh
-= m_hScrollBar
->GetSize().y
;
678 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
679 ww
-= m_vScrollBar
->GetSize().x
;
687 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
689 if (m_cursor
.IsSameAs(cursor
))
694 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
699 if ( ! wxWindowBase::SetCursor( cursor
) )
703 wxASSERT_MSG( m_cursor
.Ok(),
704 wxT("cursor must be valid after call to the base version"));
706 wxWindowMac
*mouseWin
= 0 ;
709 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
710 WindowRef window
= (WindowRef
) ( tlw
? tlw
->GetWXWindow() : 0 ) ;
712 ControlPartCode part
;
715 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
717 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
721 GetGlobalMouse( &pt
);
724 ScreenToClient(&x
, &y
);
728 control
= FindControlUnderMouse( pt
, window
, &part
) ;
730 mouseWin
= wxFindWindowFromWXWidget( (WXWidget
) control
) ;
735 if ( mouseWin
== this && !wxIsBusy() )
736 m_cursor
.MacInstall() ;
742 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
744 #ifndef __WXUNIVERSAL__
745 menu
->SetInvokingWindow((wxWindow
*)this);
748 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
750 wxPoint mouse
= wxGetMousePosition();
756 ClientToScreen( &x
, &y
) ;
758 #ifdef __WXOSX_CARBON__
759 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
760 if ( HiWord(menuResult
) != 0 )
763 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
764 int id
= wxMacCommandToId( macid
);
765 wxMenuItem
* item
= NULL
;
767 item
= menu
->FindItem( id
, &realmenu
) ;
770 if (item
->IsCheckable())
771 item
->Check( !item
->IsChecked() ) ;
773 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
778 menu
->SetInvokingWindow( NULL
);
784 // actually this shouldn't be called, because universal is having its own implementation
790 // ----------------------------------------------------------------------------
792 // ----------------------------------------------------------------------------
796 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
798 wxWindowBase::DoSetToolTip(tooltip
);
801 m_tooltip
->SetWindow(this);
806 void wxWindowMac::MacInvalidateBorders()
808 if ( m_peer
== NULL
)
811 bool vis
= IsShownOnScreen() ;
815 int outerBorder
= MacGetLeftBorderSize() ;
817 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
821 if ( outerBorder
== 0 )
824 // now we know that we have something to do at all
829 m_peer
->GetSize( tw
, th
);
830 m_peer
->GetPosition( tx
, ty
);
832 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
833 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
834 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
835 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
837 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
838 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
839 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
840 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 ( !GetParent()->IsTopLevel() )
892 bounds
.Offset( -GetParent()->MacGetLeftBorderSize(), -GetParent()->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
1135 wxClientDC
dc( (wxWindow
*)this ) ;
1137 return dc
.GetCharHeight() ;
1140 int wxWindowMac::GetCharWidth() const
1142 wxClientDC
dc( (wxWindow
*)this ) ;
1144 return dc
.GetCharWidth() ;
1147 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1148 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1150 const wxFont
*fontToUse
= theFont
;
1154 tempFont
= GetFont();
1155 fontToUse
= &tempFont
;
1158 wxClientDC
dc( (wxWindow
*) this ) ;
1159 wxCoord lx
,ly
,ld
,le
;
1160 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1161 if ( externalLeading
)
1162 *externalLeading
= le
;
1172 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1173 * we always intersect with the entire window, not only with the client area
1176 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1178 if ( m_peer
== NULL
)
1181 if ( !IsShownOnScreen() )
1184 m_peer
->SetNeedsDisplay( rect
) ;
1187 void wxWindowMac::DoFreeze()
1189 #if wxOSX_USE_CARBON
1190 if ( m_peer
&& m_peer
->IsOk() )
1191 m_peer
->SetDrawingEnabled( false ) ;
1195 void wxWindowMac::DoThaw()
1197 #if wxOSX_USE_CARBON
1198 if ( m_peer
&& m_peer
->IsOk() )
1200 m_peer
->SetDrawingEnabled( true ) ;
1201 m_peer
->InvalidateWithChildren() ;
1206 wxWindow
*wxGetActiveWindow()
1208 // actually this is a windows-only concept
1212 // Coordinates relative to the window
1213 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1215 // We really don't move the mouse programmatically under Mac.
1218 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1220 if ( MacGetTopLevelWindow() == NULL
)
1223 #if TARGET_API_MAC_OSX
1224 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1230 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1232 event
.GetDC()->Clear() ;
1234 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1236 // don't skip the event here, custom background means that the app
1237 // is drawing it itself in its OnPaint(), so don't draw it at all
1238 // now to avoid flicker
1246 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1251 int wxWindowMac::GetScrollPos(int orient
) const
1253 if ( orient
== wxHORIZONTAL
)
1256 return m_hScrollBar
->GetThumbPosition() ;
1261 return m_vScrollBar
->GetThumbPosition() ;
1267 // This now returns the whole range, not just the number
1268 // of positions that we can scroll.
1269 int wxWindowMac::GetScrollRange(int orient
) const
1271 if ( orient
== wxHORIZONTAL
)
1274 return m_hScrollBar
->GetRange() ;
1279 return m_vScrollBar
->GetRange() ;
1285 int wxWindowMac::GetScrollThumb(int orient
) const
1287 if ( orient
== wxHORIZONTAL
)
1290 return m_hScrollBar
->GetThumbSize() ;
1295 return m_vScrollBar
->GetThumbSize() ;
1301 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1303 if ( orient
== wxHORIZONTAL
)
1306 m_hScrollBar
->SetThumbPosition( pos
) ;
1311 m_vScrollBar
->SetThumbPosition( pos
) ;
1316 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1318 bool needVisibilityUpdate
= false;
1320 if ( m_hScrollBarAlwaysShown
!= hflag
)
1322 m_hScrollBarAlwaysShown
= hflag
;
1323 needVisibilityUpdate
= true;
1326 if ( m_vScrollBarAlwaysShown
!= vflag
)
1328 m_vScrollBarAlwaysShown
= vflag
;
1329 needVisibilityUpdate
= true;
1332 if ( needVisibilityUpdate
)
1333 DoUpdateScrollbarVisibility();
1337 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1338 // our own window origin is at leftOrigin/rightOrigin
1341 void wxWindowMac::MacPaintGrowBox()
1346 if ( MacHasScrollBarCorner() )
1348 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1349 wxASSERT( cgContext
) ;
1353 m_peer
->GetSize( tw
, th
);
1354 m_peer
->GetPosition( tx
, ty
);
1356 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1359 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1360 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1361 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1362 CGContextSaveGState( cgContext
);
1364 if ( m_backgroundColour
.Ok() )
1366 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1370 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1372 CGContextFillRect( cgContext
, cgrect
);
1373 CGContextRestoreGState( cgContext
);
1377 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1382 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1384 // back to the surrounding frame rectangle
1387 m_peer
->GetSize( tw
, th
);
1388 m_peer
->GetPosition( tx
, ty
);
1390 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1392 #if wxOSX_USE_COCOA_OR_CARBON
1394 InsetRect( &rect
, -1 , -1 ) ;
1397 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1398 rect
.bottom
- rect
.top
) ;
1400 HIThemeFrameDrawInfo info
;
1401 memset( &info
, 0 , sizeof(info
) ) ;
1405 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1406 info
.isFocused
= hasFocus
;
1408 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1409 wxASSERT( cgContext
) ;
1411 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1413 info
.kind
= kHIThemeFrameTextFieldSquare
;
1414 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1416 else if ( HasFlag(wxSIMPLE_BORDER
) )
1418 info
.kind
= kHIThemeFrameListBox
;
1419 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1421 else if ( hasFocus
)
1423 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1425 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1426 m_peer
->GetRect( &rect
) ;
1427 if ( MacHasScrollBarCorner() )
1429 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1430 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1431 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1432 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1433 HIThemeGrowBoxDrawInfo info
;
1434 memset( &info
, 0, sizeof(info
) ) ;
1436 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1437 info
.kind
= kHIThemeGrowBoxKindNone
;
1438 // contrary to the docs ...SizeSmall does not work
1439 info
.size
= kHIThemeGrowBoxSizeNormal
;
1440 info
.direction
= 0 ;
1441 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1445 #endif // wxOSX_USE_COCOA_OR_CARBON
1448 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1450 if ( child
== m_hScrollBar
)
1451 m_hScrollBar
= NULL
;
1452 if ( child
== m_vScrollBar
)
1453 m_vScrollBar
= NULL
;
1455 wxWindowBase::RemoveChild( child
) ;
1458 void wxWindowMac::DoUpdateScrollbarVisibility()
1460 bool triggerSizeEvent
= false;
1464 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1466 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1468 m_hScrollBar
->Show( showHScrollBar
);
1469 triggerSizeEvent
= true;
1475 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1477 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1479 m_vScrollBar
->Show( showVScrollBar
) ;
1480 triggerSizeEvent
= true;
1484 MacRepositionScrollBars() ;
1485 if ( triggerSizeEvent
)
1487 wxSizeEvent
event(GetSize(), m_windowId
);
1488 event
.SetEventObject(this);
1489 HandleWindowEvent(event
);
1493 // New function that will replace some of the above.
1494 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1495 int range
, bool refresh
)
1497 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1498 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1499 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1500 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1502 DoUpdateScrollbarVisibility();
1505 // Does a physical scroll
1506 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1508 if ( dx
== 0 && dy
== 0 )
1511 int width
, height
;
1512 GetClientSize( &width
, &height
) ;
1515 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1517 scrollrect
.Intersect( *rect
) ;
1518 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1519 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1521 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1526 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1528 child
= node
->GetData();
1531 if (child
== m_vScrollBar
)
1533 if (child
== m_hScrollBar
)
1535 if (child
->IsTopLevel())
1538 child
->GetPosition( &x
, &y
);
1539 child
->GetSize( &w
, &h
);
1542 wxRect
rc( x
, y
, w
, h
);
1543 if (rect
->Intersects( rc
))
1544 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1548 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1553 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1555 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1557 wxScrollWinEvent wevent
;
1558 wevent
.SetPosition(event
.GetPosition());
1559 wevent
.SetOrientation(event
.GetOrientation());
1560 wevent
.SetEventObject(this);
1562 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1563 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1564 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1565 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1566 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1567 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1568 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1569 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1570 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1571 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1572 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1573 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1574 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1575 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1576 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1577 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1579 HandleWindowEvent(wevent
);
1583 // Get the window with the focus
1584 wxWindow
*wxWindowBase::DoFindFocus()
1586 #if wxOSX_USE_CARBON
1587 ControlRef control
;
1588 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1589 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1595 void wxWindowMac::OnInternalIdle()
1597 // This calls the UI-update mechanism (querying windows for
1598 // menu/toolbar/control state information)
1599 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1600 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1603 // Raise the window to the top of the Z order
1604 void wxWindowMac::Raise()
1609 // Lower the window to the bottom of the Z order
1610 void wxWindowMac::Lower()
1615 // static wxWindow *gs_lastWhich = NULL;
1617 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1619 // first trigger a set cursor event
1621 wxPoint clientorigin
= GetClientAreaOrigin() ;
1622 wxSize clientsize
= GetClientSize() ;
1624 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1626 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1628 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1629 if ( processedEvtSetCursor
&& event
.HasCursor() )
1631 cursor
= event
.GetCursor() ;
1635 // the test for processedEvtSetCursor is here to prevent using m_cursor
1636 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1637 // it - this is a way to say that our cursor shouldn't be used for this
1639 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1642 if ( !wxIsBusy() && !GetParent() )
1643 cursor
= *wxSTANDARD_CURSOR
;
1647 cursor
.MacInstall() ;
1650 return cursor
.Ok() ;
1653 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1657 return m_tooltip
->GetTip() ;
1660 return wxEmptyString
;
1663 void wxWindowMac::ClearBackground()
1669 void wxWindowMac::Update()
1671 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1676 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1678 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1682 if ( iter
->IsTopLevel() )
1684 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1688 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1693 iter
= iter
->GetParent() ;
1699 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1701 MacUpdateClippedRects() ;
1703 return m_cachedClippedClientRect
;
1706 const wxRect
& wxWindowMac::MacGetClippedRect() const
1708 MacUpdateClippedRects() ;
1710 return m_cachedClippedRect
;
1713 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1715 MacUpdateClippedRects() ;
1717 return m_cachedClippedRectWithOuterStructure
;
1720 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1722 static wxRegion emptyrgn
;
1724 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1726 MacUpdateClippedRects() ;
1727 if ( includeOuterStructures
)
1728 return m_cachedClippedRegionWithOuterStructure
;
1730 return m_cachedClippedRegion
;
1738 void wxWindowMac::MacUpdateClippedRects() const
1740 #if wxOSX_USE_CARBON
1741 if ( m_cachedClippedRectValid
)
1744 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1745 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1746 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1747 // to add focus borders everywhere
1749 Rect rIncludingOuterStructures
;
1753 m_peer
->GetSize( tw
, th
);
1754 m_peer
->GetPosition( tx
, ty
);
1756 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1758 r
.left
-= MacGetLeftBorderSize() ;
1759 r
.top
-= MacGetTopBorderSize() ;
1760 r
.bottom
+= MacGetBottomBorderSize() ;
1761 r
.right
+= MacGetRightBorderSize() ;
1768 rIncludingOuterStructures
= r
;
1769 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1771 wxRect cl
= GetClientRect() ;
1772 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1776 const wxWindow
* child
= (wxWindow
*) this ;
1777 const wxWindow
* parent
= NULL
;
1779 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1781 if ( parent
->MacIsChildOfClientArea(child
) )
1783 size
= parent
->GetClientSize() ;
1784 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1790 // this will be true for scrollbars, toolbars etc.
1791 size
= parent
->GetSize() ;
1792 y
= parent
->MacGetTopBorderSize() ;
1793 x
= parent
->MacGetLeftBorderSize() ;
1794 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1795 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1798 parent
->MacWindowToRootWindow( &x
, &y
) ;
1799 MacRootWindowToWindow( &x
, &y
) ;
1801 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1803 // the wxwindow and client rects will always be clipped
1804 SectRect( &r
, &rparent
, &r
) ;
1805 SectRect( &rClient
, &rparent
, &rClient
) ;
1807 // the structure only at 'hard' borders
1808 if ( parent
->MacClipChildren() ||
1809 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1811 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1817 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1818 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1819 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1820 m_cachedClippedRectWithOuterStructure
= wxRect(
1821 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1822 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1823 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1825 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1826 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1827 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1829 m_cachedClippedRectValid
= true ;
1834 This function must not change the updatergn !
1836 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1838 bool handled
= false ;
1839 #if wxOSX_USE_CARBON
1841 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1842 GetRegionBounds( updatergn
, &updatebounds
) ;
1844 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1846 if ( !EmptyRgn(updatergn
) )
1848 RgnHandle newupdate
= NewRgn() ;
1849 wxSize point
= GetClientSize() ;
1850 wxPoint origin
= GetClientAreaOrigin() ;
1851 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1852 SectRgn( newupdate
, updatergn
, newupdate
) ;
1854 // first send an erase event to the entire update area
1856 // for the toplevel window this really is the entire area
1857 // for all the others only their client area, otherwise they
1858 // might be drawing with full alpha and eg put blue into
1859 // the grow-box area of a scrolled window (scroll sample)
1860 wxDC
* dc
= new wxWindowDC(this);
1862 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1864 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1866 wxEraseEvent
eevent( GetId(), dc
);
1867 eevent
.SetEventObject( this );
1868 HandleWindowEvent( eevent
);
1874 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1875 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1876 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1877 DisposeRgn( newupdate
) ;
1879 if ( !m_updateRegion
.Empty() )
1881 // paint the window itself
1884 event
.SetTimestamp(time
);
1885 event
.SetEventObject(this);
1886 HandleWindowEvent(event
);
1890 // now we cannot rely on having its borders drawn by a window itself, as it does not
1891 // get the updateRgn wide enough to always do so, so we do it from the parent
1892 // this would also be the place to draw any custom backgrounds for native controls
1893 // in Composited windowing
1894 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1898 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1900 child
= node
->GetData();
1903 if (child
== m_vScrollBar
)
1905 if (child
== m_hScrollBar
)
1907 if (child
->IsTopLevel())
1909 if (!child
->IsShown())
1912 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1914 child
->GetPosition( &x
, &y
);
1915 child
->GetSize( &w
, &h
);
1916 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1917 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1918 InsetRect( &childRect
, -10 , -10) ;
1920 if ( RectInRgn( &childRect
, updatergn
) )
1922 // paint custom borders
1923 wxNcPaintEvent
eventNc( child
->GetId() );
1924 eventNc
.SetEventObject( child
);
1925 if ( !child
->HandleWindowEvent( eventNc
) )
1927 child
->MacPaintBorders(0, 0) ;
1937 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1939 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1940 return tlw
? tlw
->GetWXWindow() : NULL
;
1943 bool wxWindowMac::MacHasScrollBarCorner() const
1945 /* Returns whether the scroll bars in a wxScrolledWindow should be
1946 * shortened. Scroll bars should be shortened if either:
1948 * - both scroll bars are visible, or
1950 * - there is a resize box in the parent frame's corner and this
1951 * window shares the bottom and right edge with the parent
1955 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1958 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1959 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1961 // Both scroll bars visible
1966 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1968 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1970 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1973 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1975 // Parent frame has resize handle
1976 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1978 // Note: allow for some wiggle room here as wxMac's
1979 // window rect calculations seem to be imprecise
1980 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1981 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1983 // Parent frame has resize handle and shares
1984 // right bottom corner
1989 // Parent frame has resize handle but doesn't
1990 // share right bottom corner
1996 // Parent frame doesn't have resize handle
2002 // No parent frame found
2007 void wxWindowMac::MacCreateScrollBars( long style
)
2009 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2011 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2013 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2014 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2016 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2019 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2021 GetClientSize( &width
, &height
) ;
2023 wxPoint
vPoint(width
- scrlsize
, 0) ;
2024 wxSize
vSize(scrlsize
, height
- adjust
) ;
2025 wxPoint
hPoint(0, height
- scrlsize
) ;
2026 wxSize
hSize(width
- adjust
, scrlsize
) ;
2028 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2029 if ( style
& wxVSCROLL
)
2031 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2032 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2035 if ( style
& wxHSCROLL
)
2037 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2038 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2042 // because the create does not take into account the client area origin
2043 // we might have a real position shift
2044 MacRepositionScrollBars() ;
2047 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2049 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2054 void wxWindowMac::MacRepositionScrollBars()
2056 if ( !m_hScrollBar
&& !m_vScrollBar
)
2059 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2060 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2062 // get real client area
2064 GetSize( &width
, &height
);
2066 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2067 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2069 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2070 wxSize
vSize( scrlsize
, height
- adjust
) ;
2071 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2072 wxSize
hSize( width
- adjust
, scrlsize
) ;
2075 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2077 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2080 bool wxWindowMac::AcceptsFocus() const
2082 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2085 void wxWindowMac::MacSuperChangedPosition()
2087 // only window-absolute structures have to be moved i.e. controls
2089 m_cachedClippedRectValid
= false ;
2092 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2095 child
= node
->GetData();
2096 child
->MacSuperChangedPosition() ;
2098 node
= node
->GetNext();
2102 void wxWindowMac::MacTopLevelWindowChangedPosition()
2104 // only screen-absolute structures have to be moved i.e. glcanvas
2107 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2110 child
= node
->GetData();
2111 child
->MacTopLevelWindowChangedPosition() ;
2113 node
= node
->GetNext();
2117 long wxWindowMac::MacGetLeftBorderSize() const
2124 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2126 #if wxOSX_USE_COCOA_OR_CARBON
2127 // this metric is only the 'outset' outside the simple frame rect
2128 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2134 else if (HasFlag(wxSIMPLE_BORDER
))
2136 #if wxOSX_USE_COCOA_OR_CARBON
2137 // this metric is only the 'outset' outside the simple frame rect
2138 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2148 long wxWindowMac::MacGetRightBorderSize() const
2150 // they are all symmetric in mac themes
2151 return MacGetLeftBorderSize() ;
2154 long wxWindowMac::MacGetTopBorderSize() const
2156 // they are all symmetric in mac themes
2157 return MacGetLeftBorderSize() ;
2160 long wxWindowMac::MacGetBottomBorderSize() const
2162 // they are all symmetric in mac themes
2163 return MacGetLeftBorderSize() ;
2166 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2168 return style
& ~wxBORDER_MASK
;
2171 // Find the wxWindowMac at the current mouse position, returning the mouse
2173 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2175 pt
= wxGetMousePosition();
2176 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2178 return (wxWindow
*) found
;
2181 // Get the current mouse position.
2182 wxPoint
wxGetMousePosition()
2186 wxGetMousePosition( &x
, &y
);
2188 return wxPoint(x
, y
);
2191 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2193 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2195 // copied from wxGTK : CS
2196 // VZ: shouldn't we move this to base class then?
2198 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2201 // (a) it's a command event and so is propagated to the parent
2202 // (b) under MSW it can be generated from kbd too
2203 // (c) it uses screen coords (because of (a))
2204 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2206 this->ClientToScreen(event
.GetPosition()));
2207 evtCtx
.SetEventObject(this);
2208 if ( ! HandleWindowEvent(evtCtx
) )
2217 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2219 #if wxOSX_USE_COCOA_OR_CARBON
2220 // for native controls: call their native paint method
2221 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2223 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2224 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2225 CallNextEventHandler(
2226 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2227 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2232 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2233 wxInt16
WXUNUSED(controlpart
),
2234 bool WXUNUSED(mouseStillDown
))
2238 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2242 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2243 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2248 bool wxWindowMac::HandleClicked( double timestampsec
)
2253 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2255 #if wxOSX_USE_COCOA_OR_CARBON
2256 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2259 return eventNotHandledErr
;
2265 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2267 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2268 if ( !wxWindowBase::Reparent(newParent
) )
2271 m_peer
->RemoveFromParent();
2272 m_peer
->Embed( GetParent()->GetPeer() );
2276 bool wxWindowMac::SetTransparent(wxByte alpha
)
2278 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2280 if ( alpha
!= m_macAlpha
)
2282 m_macAlpha
= alpha
;
2289 bool wxWindowMac::CanSetTransparent()
2294 wxByte
wxWindowMac::GetTransparent() const
2299 bool wxWindowMac::IsShownOnScreen() const
2301 if ( m_peer
&& m_peer
->IsOk() )
2303 bool peerVis
= m_peer
->IsVisible();
2304 bool wxVis
= wxWindowBase::IsShownOnScreen();
2305 if( peerVis
!= wxVis
)
2307 // CS : put a breakpoint here to investigate differences
2308 // between native an wx visibilities
2309 // the only place where I've encountered them until now
2310 // are the hiding/showing sequences where the vis-changed event is
2311 // first sent to the innermost control, while wx does things
2312 // from the outmost control
2313 wxVis
= wxWindowBase::IsShownOnScreen();
2317 return m_peer
->IsVisible();
2319 return wxWindowBase::IsShownOnScreen();
2326 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2328 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2331 m_isRootControl
= isRootControl
;
2335 wxWidgetImpl::wxWidgetImpl()
2340 wxWidgetImpl::~wxWidgetImpl()
2344 void wxWidgetImpl::Init()
2346 m_isRootControl
= false;
2348 m_needsFocusRect
= false;
2351 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2353 m_needsFocusRect
= needs
;
2356 bool wxWidgetImpl::NeedsFocusRect() const
2358 return m_needsFocusRect
;