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() && !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
);
838 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
839 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
840 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
841 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
845 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
847 // this is never called for a toplevel window, so we know we have a parent
848 int former_x
, former_y
, former_w
, former_h
;
850 // Get true coordinates of former position
851 DoGetPosition( &former_x
, &former_y
) ;
852 DoGetSize( &former_w
, &former_h
) ;
854 wxWindow
*parent
= GetParent();
857 wxPoint
pt(parent
->GetClientAreaOrigin());
862 int actualWidth
= width
;
863 int actualHeight
= height
;
867 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
868 actualWidth
= m_minWidth
;
869 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
870 actualHeight
= m_minHeight
;
871 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
872 actualWidth
= m_maxWidth
;
873 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
874 actualHeight
= m_maxHeight
;
876 bool doMove
= false, doResize
= false ;
878 if ( actualX
!= former_x
|| actualY
!= former_y
)
881 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
884 if ( doMove
|| doResize
)
886 // as the borders are drawn outside the native control, we adjust now
888 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
889 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
890 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
892 if ( parent
&& !parent
->IsTopLevel() )
894 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
897 MacInvalidateBorders() ;
899 m_cachedClippedRectValid
= false ;
901 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
903 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
905 MacInvalidateBorders() ;
907 MacRepositionScrollBars() ;
910 wxPoint
point(actualX
, actualY
);
911 wxMoveEvent
event(point
, m_windowId
);
912 event
.SetEventObject(this);
913 HandleWindowEvent(event
) ;
918 MacRepositionScrollBars() ;
919 wxSize
size(actualWidth
, actualHeight
);
920 wxSizeEvent
event(size
, m_windowId
);
921 event
.SetEventObject(this);
922 HandleWindowEvent(event
);
927 wxSize
wxWindowMac::DoGetBestSize() const
929 if ( m_macIsUserPane
|| IsTopLevel() )
931 return wxWindowBase::DoGetBestSize() ;
937 m_peer
->GetBestRect(&r
);
939 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
946 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
951 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
958 // return wxWindowBase::DoGetBestSize() ;
962 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
963 MacGetRightBorderSize();
964 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
965 MacGetBottomBorderSize();
966 if ( bestHeight
< 10 )
969 return wxSize(bestWidth
, bestHeight
);
973 // set the size of the window: if the dimensions are positive, just use them,
974 // but if any of them is equal to -1, it means that we must find the value for
975 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
976 // which case -1 is a valid value for x and y)
978 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
979 // the width/height to best suit our contents, otherwise we reuse the current
981 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
983 // get the current size and position...
984 int currentX
, currentY
;
985 int currentW
, currentH
;
987 GetPosition(¤tX
, ¤tY
);
988 GetSize(¤tW
, ¤tH
);
990 // ... and don't do anything (avoiding flicker) if it's already ok
991 if ( x
== currentX
&& y
== currentY
&&
992 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
995 MacRepositionScrollBars() ; // we might have a real position shift
1000 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1002 if ( x
== wxDefaultCoord
)
1004 if ( y
== wxDefaultCoord
)
1008 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1010 wxSize size
= wxDefaultSize
;
1011 if ( width
== wxDefaultCoord
)
1013 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1015 size
= DoGetBestSize();
1020 // just take the current one
1025 if ( height
== wxDefaultCoord
)
1027 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1029 if ( size
.x
== wxDefaultCoord
)
1030 size
= DoGetBestSize();
1031 // else: already called DoGetBestSize() above
1037 // just take the current one
1042 DoMoveWindow( x
, y
, width
, height
);
1045 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1047 int left
,top
,width
,height
;
1048 m_peer
->GetContentArea( left
, top
, width
, height
);
1049 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1052 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1054 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1056 int currentclientwidth
, currentclientheight
;
1057 int currentwidth
, currentheight
;
1059 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1060 GetSize( ¤twidth
, ¤theight
) ;
1062 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1063 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1067 void wxWindowMac::SetLabel(const wxString
& title
)
1071 if ( m_peer
&& m_peer
->IsOk() )
1072 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1074 // do not trigger refreshes upon invisible and possible partly created objects
1075 if ( IsShownOnScreen() )
1079 wxString
wxWindowMac::GetLabel() const
1084 bool wxWindowMac::Show(bool show
)
1086 if ( !wxWindowBase::Show(show
) )
1090 m_peer
->SetVisibility( show
) ;
1095 void wxWindowMac::DoEnable(bool enable
)
1097 m_peer
->Enable( enable
) ;
1101 // status change notifications
1104 void wxWindowMac::MacVisibilityChanged()
1108 void wxWindowMac::MacHiliteChanged()
1112 void wxWindowMac::MacEnabledStateChanged()
1114 OnEnabled( m_peer
->IsEnabled() );
1118 // status queries on the inherited window's state
1121 bool wxWindowMac::MacIsReallyEnabled()
1123 return m_peer
->IsEnabled() ;
1126 bool wxWindowMac::MacIsReallyHilited()
1128 #if wxOSX_USE_CARBON
1129 return m_peer
->IsActive();
1131 return true; // TODO
1135 int wxWindowMac::GetCharHeight() const
1137 wxClientDC
dc( (wxWindow
*)this ) ;
1139 return dc
.GetCharHeight() ;
1142 int wxWindowMac::GetCharWidth() const
1144 wxClientDC
dc( (wxWindow
*)this ) ;
1146 return dc
.GetCharWidth() ;
1149 void wxWindowMac::GetTextExtent(const wxString
& string
, 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 wxClientDC
dc( (wxWindow
*) this ) ;
1161 wxCoord lx
,ly
,ld
,le
;
1162 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1163 if ( externalLeading
)
1164 *externalLeading
= le
;
1174 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1175 * we always intersect with the entire window, not only with the client area
1178 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1180 if ( m_peer
== NULL
)
1183 if ( !IsShownOnScreen() )
1186 m_peer
->SetNeedsDisplay( rect
) ;
1189 void wxWindowMac::DoFreeze()
1191 #if wxOSX_USE_CARBON
1192 if ( m_peer
&& m_peer
->IsOk() )
1193 m_peer
->SetDrawingEnabled( false ) ;
1197 void wxWindowMac::DoThaw()
1199 #if wxOSX_USE_CARBON
1200 if ( m_peer
&& m_peer
->IsOk() )
1202 m_peer
->SetDrawingEnabled( true ) ;
1203 m_peer
->InvalidateWithChildren() ;
1208 wxWindow
*wxGetActiveWindow()
1210 // actually this is a windows-only concept
1214 // Coordinates relative to the window
1215 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1217 // We really don't move the mouse programmatically under Mac.
1220 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1222 if ( MacGetTopLevelWindow() == NULL
)
1225 #if TARGET_API_MAC_OSX
1226 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1232 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1234 event
.GetDC()->Clear() ;
1236 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1238 // don't skip the event here, custom background means that the app
1239 // is drawing it itself in its OnPaint(), so don't draw it at all
1240 // now to avoid flicker
1248 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1253 int wxWindowMac::GetScrollPos(int orient
) const
1255 if ( orient
== wxHORIZONTAL
)
1258 return m_hScrollBar
->GetThumbPosition() ;
1263 return m_vScrollBar
->GetThumbPosition() ;
1269 // This now returns the whole range, not just the number
1270 // of positions that we can scroll.
1271 int wxWindowMac::GetScrollRange(int orient
) const
1273 if ( orient
== wxHORIZONTAL
)
1276 return m_hScrollBar
->GetRange() ;
1281 return m_vScrollBar
->GetRange() ;
1287 int wxWindowMac::GetScrollThumb(int orient
) const
1289 if ( orient
== wxHORIZONTAL
)
1292 return m_hScrollBar
->GetThumbSize() ;
1297 return m_vScrollBar
->GetThumbSize() ;
1303 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1305 if ( orient
== wxHORIZONTAL
)
1308 m_hScrollBar
->SetThumbPosition( pos
) ;
1313 m_vScrollBar
->SetThumbPosition( pos
) ;
1318 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1320 bool needVisibilityUpdate
= false;
1322 if ( m_hScrollBarAlwaysShown
!= hflag
)
1324 m_hScrollBarAlwaysShown
= hflag
;
1325 needVisibilityUpdate
= true;
1328 if ( m_vScrollBarAlwaysShown
!= vflag
)
1330 m_vScrollBarAlwaysShown
= vflag
;
1331 needVisibilityUpdate
= true;
1334 if ( needVisibilityUpdate
)
1335 DoUpdateScrollbarVisibility();
1339 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1340 // our own window origin is at leftOrigin/rightOrigin
1343 void wxWindowMac::MacPaintGrowBox()
1348 if ( MacHasScrollBarCorner() )
1350 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1351 wxASSERT( cgContext
) ;
1355 m_peer
->GetSize( tw
, th
);
1356 m_peer
->GetPosition( tx
, ty
);
1358 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1361 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1362 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1363 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1364 CGContextSaveGState( cgContext
);
1366 if ( m_backgroundColour
.Ok() )
1368 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1372 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1374 CGContextFillRect( cgContext
, cgrect
);
1375 CGContextRestoreGState( cgContext
);
1379 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1384 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1386 // back to the surrounding frame rectangle
1389 m_peer
->GetSize( tw
, th
);
1390 m_peer
->GetPosition( tx
, ty
);
1392 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1394 #if wxOSX_USE_COCOA_OR_CARBON
1396 InsetRect( &rect
, -1 , -1 ) ;
1399 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1400 rect
.bottom
- rect
.top
) ;
1402 HIThemeFrameDrawInfo info
;
1403 memset( &info
, 0 , sizeof(info
) ) ;
1407 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1408 info
.isFocused
= hasFocus
;
1410 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1411 wxASSERT( cgContext
) ;
1413 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1415 info
.kind
= kHIThemeFrameTextFieldSquare
;
1416 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1418 else if ( HasFlag(wxSIMPLE_BORDER
) )
1420 info
.kind
= kHIThemeFrameListBox
;
1421 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1423 else if ( hasFocus
)
1425 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1427 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1428 m_peer
->GetRect( &rect
) ;
1429 if ( MacHasScrollBarCorner() )
1431 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1432 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1433 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1434 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1435 HIThemeGrowBoxDrawInfo info
;
1436 memset( &info
, 0, sizeof(info
) ) ;
1438 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1439 info
.kind
= kHIThemeGrowBoxKindNone
;
1440 // contrary to the docs ...SizeSmall does not work
1441 info
.size
= kHIThemeGrowBoxSizeNormal
;
1442 info
.direction
= 0 ;
1443 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1447 #endif // wxOSX_USE_COCOA_OR_CARBON
1450 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1452 if ( child
== m_hScrollBar
)
1453 m_hScrollBar
= NULL
;
1454 if ( child
== m_vScrollBar
)
1455 m_vScrollBar
= NULL
;
1457 wxWindowBase::RemoveChild( child
) ;
1460 void wxWindowMac::DoUpdateScrollbarVisibility()
1462 bool triggerSizeEvent
= false;
1466 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1468 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1470 m_hScrollBar
->Show( showHScrollBar
);
1471 triggerSizeEvent
= true;
1477 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1479 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1481 m_vScrollBar
->Show( showVScrollBar
) ;
1482 triggerSizeEvent
= true;
1486 MacRepositionScrollBars() ;
1487 if ( triggerSizeEvent
)
1489 wxSizeEvent
event(GetSize(), m_windowId
);
1490 event
.SetEventObject(this);
1491 HandleWindowEvent(event
);
1495 // New function that will replace some of the above.
1496 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1497 int range
, bool refresh
)
1499 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1500 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1501 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1502 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1504 DoUpdateScrollbarVisibility();
1507 // Does a physical scroll
1508 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1510 if ( dx
== 0 && dy
== 0 )
1513 int width
, height
;
1514 GetClientSize( &width
, &height
) ;
1517 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1519 scrollrect
.Intersect( *rect
) ;
1520 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1521 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1523 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1528 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1530 child
= node
->GetData();
1533 if (child
== m_vScrollBar
)
1535 if (child
== m_hScrollBar
)
1537 if (child
->IsTopLevel())
1540 child
->GetPosition( &x
, &y
);
1541 child
->GetSize( &w
, &h
);
1544 wxRect
rc( x
, y
, w
, h
);
1545 if (rect
->Intersects( rc
))
1546 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1550 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1555 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1557 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1559 wxScrollWinEvent wevent
;
1560 wevent
.SetPosition(event
.GetPosition());
1561 wevent
.SetOrientation(event
.GetOrientation());
1562 wevent
.SetEventObject(this);
1564 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1565 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1566 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1567 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1568 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1569 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1570 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1571 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1572 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1573 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1574 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1575 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1576 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1577 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1578 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1579 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1581 HandleWindowEvent(wevent
);
1585 // Get the window with the focus
1586 wxWindow
*wxWindowBase::DoFindFocus()
1588 #if wxOSX_USE_CARBON
1589 ControlRef control
;
1590 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1591 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1597 void wxWindowMac::OnInternalIdle()
1599 // This calls the UI-update mechanism (querying windows for
1600 // menu/toolbar/control state information)
1601 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1602 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1605 // Raise the window to the top of the Z order
1606 void wxWindowMac::Raise()
1611 // Lower the window to the bottom of the Z order
1612 void wxWindowMac::Lower()
1617 // static wxWindow *gs_lastWhich = NULL;
1619 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1621 // first trigger a set cursor event
1623 wxPoint clientorigin
= GetClientAreaOrigin() ;
1624 wxSize clientsize
= GetClientSize() ;
1626 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1628 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1630 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1631 if ( processedEvtSetCursor
&& event
.HasCursor() )
1633 cursor
= event
.GetCursor() ;
1637 // the test for processedEvtSetCursor is here to prevent using m_cursor
1638 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1639 // it - this is a way to say that our cursor shouldn't be used for this
1641 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1644 if ( !wxIsBusy() && !GetParent() )
1645 cursor
= *wxSTANDARD_CURSOR
;
1649 cursor
.MacInstall() ;
1652 return cursor
.Ok() ;
1655 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1659 return m_tooltip
->GetTip() ;
1662 return wxEmptyString
;
1665 void wxWindowMac::ClearBackground()
1671 void wxWindowMac::Update()
1673 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1678 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1680 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1684 if ( iter
->IsTopLevel() )
1686 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1690 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1695 iter
= iter
->GetParent() ;
1701 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1703 MacUpdateClippedRects() ;
1705 return m_cachedClippedClientRect
;
1708 const wxRect
& wxWindowMac::MacGetClippedRect() const
1710 MacUpdateClippedRects() ;
1712 return m_cachedClippedRect
;
1715 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1717 MacUpdateClippedRects() ;
1719 return m_cachedClippedRectWithOuterStructure
;
1722 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1724 static wxRegion emptyrgn
;
1726 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1728 MacUpdateClippedRects() ;
1729 if ( includeOuterStructures
)
1730 return m_cachedClippedRegionWithOuterStructure
;
1732 return m_cachedClippedRegion
;
1740 void wxWindowMac::MacUpdateClippedRects() const
1742 #if wxOSX_USE_CARBON
1743 if ( m_cachedClippedRectValid
)
1746 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1747 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1748 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1749 // to add focus borders everywhere
1751 Rect rIncludingOuterStructures
;
1755 m_peer
->GetSize( tw
, th
);
1756 m_peer
->GetPosition( tx
, ty
);
1758 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1760 r
.left
-= MacGetLeftBorderSize() ;
1761 r
.top
-= MacGetTopBorderSize() ;
1762 r
.bottom
+= MacGetBottomBorderSize() ;
1763 r
.right
+= MacGetRightBorderSize() ;
1770 rIncludingOuterStructures
= r
;
1771 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1773 wxRect cl
= GetClientRect() ;
1774 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1778 const wxWindow
* child
= (wxWindow
*) this ;
1779 const wxWindow
* parent
= NULL
;
1781 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1783 if ( parent
->MacIsChildOfClientArea(child
) )
1785 size
= parent
->GetClientSize() ;
1786 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1792 // this will be true for scrollbars, toolbars etc.
1793 size
= parent
->GetSize() ;
1794 y
= parent
->MacGetTopBorderSize() ;
1795 x
= parent
->MacGetLeftBorderSize() ;
1796 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1797 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1800 parent
->MacWindowToRootWindow( &x
, &y
) ;
1801 MacRootWindowToWindow( &x
, &y
) ;
1803 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1805 // the wxwindow and client rects will always be clipped
1806 SectRect( &r
, &rparent
, &r
) ;
1807 SectRect( &rClient
, &rparent
, &rClient
) ;
1809 // the structure only at 'hard' borders
1810 if ( parent
->MacClipChildren() ||
1811 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1813 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1819 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1820 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1821 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1822 m_cachedClippedRectWithOuterStructure
= wxRect(
1823 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1824 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1825 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1827 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1828 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1829 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1831 m_cachedClippedRectValid
= true ;
1836 This function must not change the updatergn !
1838 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1840 bool handled
= false ;
1841 #if wxOSX_USE_CARBON
1843 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1844 GetRegionBounds( updatergn
, &updatebounds
) ;
1846 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1848 if ( !EmptyRgn(updatergn
) )
1850 RgnHandle newupdate
= NewRgn() ;
1851 wxSize point
= GetClientSize() ;
1852 wxPoint origin
= GetClientAreaOrigin() ;
1853 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1854 SectRgn( newupdate
, updatergn
, newupdate
) ;
1856 // first send an erase event to the entire update area
1858 // for the toplevel window this really is the entire area
1859 // for all the others only their client area, otherwise they
1860 // might be drawing with full alpha and eg put blue into
1861 // the grow-box area of a scrolled window (scroll sample)
1862 wxDC
* dc
= new wxWindowDC(this);
1864 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1866 dc
->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1868 wxEraseEvent
eevent( GetId(), dc
);
1869 eevent
.SetEventObject( this );
1870 HandleWindowEvent( eevent
);
1876 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1877 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1878 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1879 DisposeRgn( newupdate
) ;
1881 if ( !m_updateRegion
.Empty() )
1883 // paint the window itself
1886 event
.SetTimestamp(time
);
1887 event
.SetEventObject(this);
1888 HandleWindowEvent(event
);
1892 // now we cannot rely on having its borders drawn by a window itself, as it does not
1893 // get the updateRgn wide enough to always do so, so we do it from the parent
1894 // this would also be the place to draw any custom backgrounds for native controls
1895 // in Composited windowing
1896 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1900 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1902 child
= node
->GetData();
1905 if (child
== m_vScrollBar
)
1907 if (child
== m_hScrollBar
)
1909 if (child
->IsTopLevel())
1911 if (!child
->IsShown())
1914 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1916 child
->GetPosition( &x
, &y
);
1917 child
->GetSize( &w
, &h
);
1918 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1919 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1920 InsetRect( &childRect
, -10 , -10) ;
1922 if ( RectInRgn( &childRect
, updatergn
) )
1924 // paint custom borders
1925 wxNcPaintEvent
eventNc( child
->GetId() );
1926 eventNc
.SetEventObject( child
);
1927 if ( !child
->HandleWindowEvent( eventNc
) )
1929 child
->MacPaintBorders(0, 0) ;
1939 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1941 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1942 return tlw
? tlw
->GetWXWindow() : NULL
;
1945 bool wxWindowMac::MacHasScrollBarCorner() const
1947 /* Returns whether the scroll bars in a wxScrolledWindow should be
1948 * shortened. Scroll bars should be shortened if either:
1950 * - both scroll bars are visible, or
1952 * - there is a resize box in the parent frame's corner and this
1953 * window shares the bottom and right edge with the parent
1957 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1960 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1961 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1963 // Both scroll bars visible
1968 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1970 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1972 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1975 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1977 // Parent frame has resize handle
1978 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1980 // Note: allow for some wiggle room here as wxMac's
1981 // window rect calculations seem to be imprecise
1982 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1983 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1985 // Parent frame has resize handle and shares
1986 // right bottom corner
1991 // Parent frame has resize handle but doesn't
1992 // share right bottom corner
1998 // Parent frame doesn't have resize handle
2004 // No parent frame found
2009 void wxWindowMac::MacCreateScrollBars( long style
)
2011 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2013 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2015 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2016 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2018 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2021 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2023 GetClientSize( &width
, &height
) ;
2025 wxPoint
vPoint(width
- scrlsize
, 0) ;
2026 wxSize
vSize(scrlsize
, height
- adjust
) ;
2027 wxPoint
hPoint(0, height
- scrlsize
) ;
2028 wxSize
hSize(width
- adjust
, scrlsize
) ;
2030 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2031 if ( style
& wxVSCROLL
)
2033 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2034 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2037 if ( style
& wxHSCROLL
)
2039 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2040 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2044 // because the create does not take into account the client area origin
2045 // we might have a real position shift
2046 MacRepositionScrollBars() ;
2049 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2051 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2056 void wxWindowMac::MacRepositionScrollBars()
2058 if ( !m_hScrollBar
&& !m_vScrollBar
)
2061 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2062 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2064 // get real client area
2066 GetSize( &width
, &height
);
2068 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2069 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2071 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2072 wxSize
vSize( scrlsize
, height
- adjust
) ;
2073 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2074 wxSize
hSize( width
- adjust
, scrlsize
) ;
2077 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2079 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2082 bool wxWindowMac::AcceptsFocus() const
2084 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2087 void wxWindowMac::MacSuperChangedPosition()
2089 // only window-absolute structures have to be moved i.e. controls
2091 m_cachedClippedRectValid
= false ;
2094 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2097 child
= node
->GetData();
2098 child
->MacSuperChangedPosition() ;
2100 node
= node
->GetNext();
2104 void wxWindowMac::MacTopLevelWindowChangedPosition()
2106 // only screen-absolute structures have to be moved i.e. glcanvas
2109 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2112 child
= node
->GetData();
2113 child
->MacTopLevelWindowChangedPosition() ;
2115 node
= node
->GetNext();
2119 long wxWindowMac::MacGetLeftBorderSize() const
2126 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2128 #if wxOSX_USE_COCOA_OR_CARBON
2129 // this metric is only the 'outset' outside the simple frame rect
2130 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2136 else if (HasFlag(wxSIMPLE_BORDER
))
2138 #if wxOSX_USE_COCOA_OR_CARBON
2139 // this metric is only the 'outset' outside the simple frame rect
2140 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2150 long wxWindowMac::MacGetRightBorderSize() const
2152 // they are all symmetric in mac themes
2153 return MacGetLeftBorderSize() ;
2156 long wxWindowMac::MacGetTopBorderSize() const
2158 // they are all symmetric in mac themes
2159 return MacGetLeftBorderSize() ;
2162 long wxWindowMac::MacGetBottomBorderSize() const
2164 // they are all symmetric in mac themes
2165 return MacGetLeftBorderSize() ;
2168 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2170 return style
& ~wxBORDER_MASK
;
2173 // Find the wxWindowMac at the current mouse position, returning the mouse
2175 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2177 pt
= wxGetMousePosition();
2178 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2180 return (wxWindow
*) found
;
2183 // Get the current mouse position.
2184 wxPoint
wxGetMousePosition()
2188 wxGetMousePosition( &x
, &y
);
2190 return wxPoint(x
, y
);
2193 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2195 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2197 // copied from wxGTK : CS
2198 // VZ: shouldn't we move this to base class then?
2200 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2203 // (a) it's a command event and so is propagated to the parent
2204 // (b) under MSW it can be generated from kbd too
2205 // (c) it uses screen coords (because of (a))
2206 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2208 this->ClientToScreen(event
.GetPosition()));
2209 evtCtx
.SetEventObject(this);
2210 if ( ! HandleWindowEvent(evtCtx
) )
2219 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2221 #if wxOSX_USE_COCOA_OR_CARBON
2222 // for native controls: call their native paint method
2223 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2225 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2226 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2227 CallNextEventHandler(
2228 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2229 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2234 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2235 wxInt16
WXUNUSED(controlpart
),
2236 bool WXUNUSED(mouseStillDown
))
2240 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2244 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2245 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2250 bool wxWindowMac::HandleClicked( double timestampsec
)
2255 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2257 #if wxOSX_USE_COCOA_OR_CARBON
2258 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2261 return eventNotHandledErr
;
2267 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2269 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2270 if ( !wxWindowBase::Reparent(newParent
) )
2273 m_peer
->RemoveFromParent();
2274 m_peer
->Embed( GetParent()->GetPeer() );
2278 bool wxWindowMac::SetTransparent(wxByte alpha
)
2280 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2282 if ( alpha
!= m_macAlpha
)
2284 m_macAlpha
= alpha
;
2291 bool wxWindowMac::CanSetTransparent()
2296 wxByte
wxWindowMac::GetTransparent() const
2301 bool wxWindowMac::IsShownOnScreen() const
2303 if ( m_peer
&& m_peer
->IsOk() )
2305 bool peerVis
= m_peer
->IsVisible();
2306 bool wxVis
= wxWindowBase::IsShownOnScreen();
2307 if( peerVis
!= wxVis
)
2309 // CS : put a breakpoint here to investigate differences
2310 // between native an wx visibilities
2311 // the only place where I've encountered them until now
2312 // are the hiding/showing sequences where the vis-changed event is
2313 // first sent to the innermost control, while wx does things
2314 // from the outmost control
2315 wxVis
= wxWindowBase::IsShownOnScreen();
2319 return m_peer
->IsVisible();
2321 return wxWindowBase::IsShownOnScreen();
2328 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2330 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2333 m_isRootControl
= isRootControl
;
2337 wxWidgetImpl::wxWidgetImpl()
2342 wxWidgetImpl::~wxWidgetImpl()
2346 void wxWidgetImpl::Init()
2348 m_isRootControl
= false;
2350 m_needsFocusRect
= false;
2353 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2355 m_needsFocusRect
= needs
;
2358 bool wxWidgetImpl::NeedsFocusRect() const
2360 return m_needsFocusRect
;