1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: window.cpp 54981 2008-08-05 17:52:02Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
40 #include "wx/tooltip.h"
41 #include "wx/spinctrl.h"
42 #include "wx/geometry.h"
45 #include "wx/listctrl.h"
49 #include "wx/treectrl.h"
57 #include "wx/popupwin.h"
60 #if wxUSE_DRAG_AND_DROP
64 #include "wx/graphics.h"
67 #include "wx/osx/uma.h"
69 #include "wx/osx/private.h"
71 #include <Carbon/Carbon.h>
74 #define MAC_SCROLLBAR_SIZE 15
75 #define MAC_SMALL_SCROLLBAR_SIZE 11
79 #ifdef __WXUNIVERSAL__
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
82 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
85 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
86 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
87 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
88 EVT_PAINT(wxWindowMac::OnPaint
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 // ===========================================================================
99 // ===========================================================================
101 // ----------------------------------------------------------------------------
102 // constructors and such
103 // ----------------------------------------------------------------------------
105 wxWindowMac::wxWindowMac()
110 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
115 const wxString
& name
)
118 Create(parent
, id
, pos
, size
, style
, name
);
121 void wxWindowMac::Init()
125 m_cgContextRef
= NULL
;
127 // as all windows are created with WS_VISIBLE style...
130 m_hScrollBar
= NULL
;
131 m_vScrollBar
= NULL
;
132 m_hScrollBarAlwaysShown
= false;
133 m_vScrollBarAlwaysShown
= false;
135 m_macIsUserPane
= true;
136 m_clipChildren
= false ;
137 m_cachedClippedRectValid
= false ;
140 wxWindowMac::~wxWindowMac()
144 m_isBeingDeleted
= true;
146 MacInvalidateBorders() ;
148 #ifndef __WXUNIVERSAL__
149 // VS: make sure there's no wxFrame with last focus set to us:
150 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
152 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
155 if ( frame
->GetLastFocus() == this )
156 frame
->SetLastFocus((wxWindow
*)NULL
);
162 // destroy children before destroying this window itself
165 // wxRemoveMacControlAssociation( this ) ;
166 // If we delete an item, we should initialize the parent panel,
167 // because it could now be invalid.
168 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
171 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
172 tlw
->SetDefaultItem(NULL
);
175 if ( g_MacLastWindow
== this )
176 g_MacLastWindow
= NULL
;
178 #ifndef __WXUNIVERSAL__
179 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
182 if ( frame
->GetLastFocus() == this )
183 frame
->SetLastFocus( NULL
) ;
187 // delete our drop target if we've got one
188 #if wxUSE_DRAG_AND_DROP
189 if ( m_dropTarget
!= NULL
)
199 WXWidget
wxWindowMac::GetHandle() const
201 return (WXWidget
) m_peer
->GetWXWidget() ;
205 // TODO END move to window_osx.cpp
208 // ---------------------------------------------------------------------------
209 // Utility Routines to move between different coordinate systems
210 // ---------------------------------------------------------------------------
213 * Right now we have the following setup :
214 * a border that is not part of the native control is always outside the
215 * control's border (otherwise we loose all native intelligence, future ways
216 * may be to have a second embedding control responsible for drawing borders
217 * and backgrounds eventually)
218 * so all this border calculations have to be taken into account when calling
219 * native methods or getting native oriented data
220 * so we have three coordinate systems here
221 * wx client coordinates
222 * wx window coordinates (including window frames)
230 bool wxWindowMac::Create(wxWindowMac
*parent
,
235 const wxString
& name
)
237 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
239 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
242 m_windowVariant
= parent
->GetWindowVariant() ;
244 if ( m_macIsUserPane
)
246 m_peer
= wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() );
247 MacPostControlCreate(pos
, size
) ;
250 #ifndef __WXUNIVERSAL__
251 // Don't give scrollbars to wxControls unless they ask for them
252 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
253 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
255 MacCreateScrollBars( style
) ;
259 wxWindowCreateEvent
event((wxWindow
*)this);
260 GetEventHandler()->AddPendingEvent(event
);
265 void wxWindowMac::MacChildAdded()
268 m_vScrollBar
->Raise() ;
270 m_hScrollBar
->Raise() ;
273 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
), const wxSize
& size
)
275 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->IsOk() , wxT("No valid mac control") ) ;
278 m_peer
->SetReference( (URefCon
) this ) ;
281 GetParent()->AddChild( this );
284 m_peer
->InstallEventHandler();
286 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
287 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
288 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
290 GetParent()->MacChildAdded() ;
292 // adjust font, controlsize etc
293 DoSetWindowVariant( m_windowVariant
) ;
295 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
297 // for controls we want to use best size for wxDefaultSize params )
298 if ( !m_macIsUserPane
)
299 SetInitialSize(size
);
301 SetCursor( *wxSTANDARD_CURSOR
) ;
304 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
306 // Don't assert, in case we set the window variant before
307 // the window is created
308 // wxASSERT( m_peer->Ok() ) ;
310 m_windowVariant
= variant
;
312 if (m_peer
== NULL
|| !m_peer
->IsOk())
315 m_peer
->SetControlSize( variant
);
316 #if wxOSX_USE_COCOA_OR_CARBON
321 ThemeFontID themeFont
= kThemeSystemFont
;
323 // we will get that from the settings later
324 // and make this NORMAL later, but first
325 // we have a few calculations that we must fix
329 case wxWINDOW_VARIANT_NORMAL
:
330 size
= kControlSizeNormal
;
331 themeFont
= kThemeSystemFont
;
334 case wxWINDOW_VARIANT_SMALL
:
335 size
= kControlSizeSmall
;
336 themeFont
= kThemeSmallSystemFont
;
339 case wxWINDOW_VARIANT_MINI
:
340 // not always defined in the headers
345 case wxWINDOW_VARIANT_LARGE
:
346 size
= kControlSizeLarge
;
347 themeFont
= kThemeSystemFont
;
351 wxFAIL_MSG(_T("unexpected window variant"));
355 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
356 font
.MacCreateFromThemeFont( themeFont
) ;
358 CTFontUIFontType themeFont
= kCTFontSystemFontType
;
361 case wxWINDOW_VARIANT_NORMAL
:
362 themeFont
= kCTFontSystemFontType
;
365 case wxWINDOW_VARIANT_SMALL
:
366 themeFont
= kCTFontSmallSystemFontType
;
369 case wxWINDOW_VARIANT_MINI
:
370 themeFont
= kCTFontMiniSystemFontType
;
373 case wxWINDOW_VARIANT_LARGE
:
374 themeFont
= kCTFontSystemFontType
;
378 wxFAIL_MSG(_T("unexpected window variant"));
381 font
.MacCreateFromUIFont( themeFont
) ;
388 void wxWindowMac::MacUpdateControlFont()
391 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
393 // do not trigger refreshes upon invisible and possible partly created objects
394 if ( IsShownOnScreen() )
398 bool wxWindowMac::SetFont(const wxFont
& font
)
400 bool retval
= wxWindowBase::SetFont( font
);
402 MacUpdateControlFont() ;
407 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
409 bool retval
= wxWindowBase::SetForegroundColour( col
);
412 MacUpdateControlFont();
417 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
419 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
423 m_peer
->SetBackgroundColour( col
) ;
428 void wxWindowMac::SetFocus()
430 if ( !AcceptsFocus() )
433 wxWindow
* former
= FindFocus() ;
434 if ( former
== this )
440 void wxWindowMac::DoCaptureMouse()
442 wxApp::s_captureWindow
= (wxWindow
*) this ;
445 wxWindow
* wxWindowBase::GetCapture()
447 return wxApp::s_captureWindow
;
450 void wxWindowMac::DoReleaseMouse()
452 wxApp::s_captureWindow
= NULL
;
455 #if wxUSE_DRAG_AND_DROP
457 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
459 if ( m_dropTarget
!= NULL
)
462 m_dropTarget
= pDropTarget
;
463 if ( m_dropTarget
!= NULL
)
471 // Old-style File Manager Drag & Drop
472 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
477 // From a wx position / size calculate the appropriate size of the native control
479 bool wxWindowMac::MacGetBoundsForControl(
483 int& w
, int& h
, bool adjustOrigin
) const
485 // the desired size, minus the border pixels gives the correct size of the control
489 w
= WidthDefault( size
.x
);
490 h
= HeightDefault( size
.y
);
492 x
+= MacGetLeftBorderSize() ;
493 y
+= MacGetTopBorderSize() ;
494 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
495 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
498 AdjustForParentClientOrigin( x
, y
) ;
500 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
501 if ( GetParent() && !GetParent()->IsTopLevel() )
503 x
-= GetParent()->MacGetLeftBorderSize() ;
504 y
-= GetParent()->MacGetTopBorderSize() ;
510 // Get window size (not client size)
511 void wxWindowMac::DoGetSize(int *x
, int *y
) const
514 m_peer
->GetSize( width
, height
);
517 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
519 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
522 // get the position of the bounds of this window in client coordinates of its parent
523 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
527 m_peer
->GetPosition( x1
, y1
) ;
529 // get the wx window position from the native one
530 x1
-= MacGetLeftBorderSize() ;
531 y1
-= MacGetTopBorderSize() ;
535 wxWindow
*parent
= GetParent();
538 // we must first adjust it to be in window coordinates of the parent,
539 // as otherwise it gets lost by the ClientAreaOrigin fix
540 x1
+= parent
->MacGetLeftBorderSize() ;
541 y1
+= parent
->MacGetTopBorderSize() ;
543 // and now to client coordinates
544 wxPoint
pt(parent
->GetClientAreaOrigin());
556 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
558 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
559 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
560 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
561 MacRootWindowToWindow( x
, y
) ;
563 wxPoint origin
= GetClientAreaOrigin() ;
570 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
572 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
573 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
575 wxPoint origin
= GetClientAreaOrigin() ;
581 MacWindowToRootWindow( x
, y
) ;
582 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
585 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
587 wxPoint origin
= GetClientAreaOrigin() ;
593 MacWindowToRootWindow( x
, y
) ;
596 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
607 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
610 pt
.x
-= MacGetLeftBorderSize() ;
611 pt
.y
-= MacGetTopBorderSize() ;
612 wxWidgetImpl::Convert( &pt
, m_peer
, top
->m_peer
) ;
622 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
633 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
636 wxWidgetImpl::Convert( &pt
, top
->m_peer
, m_peer
) ;
637 pt
.x
+= MacGetLeftBorderSize() ;
638 pt
.y
+= MacGetTopBorderSize() ;
648 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
650 wxSize sizeTotal
= size
;
652 int innerwidth
, innerheight
;
654 int outerwidth
, outerheight
;
656 m_peer
->GetContentArea( left
, top
, innerwidth
, innerheight
);
657 m_peer
->GetSize( outerwidth
, outerheight
);
659 sizeTotal
.x
+= left
+ (outerwidth
-innerwidth
);
660 sizeTotal
.y
+= top
+ (outerheight
-innerheight
);
662 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
663 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
668 // Get size *available for subwindows* i.e. excluding menu bar etc.
669 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
675 m_peer
->GetContentArea( left
, top
, ww
, hh
);
677 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
678 hh
-= m_hScrollBar
->GetSize().y
;
680 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
681 ww
-= m_vScrollBar
->GetSize().x
;
689 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
691 if (m_cursor
.IsSameAs(cursor
))
696 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
701 if ( ! wxWindowBase::SetCursor( cursor
) )
705 wxASSERT_MSG( m_cursor
.Ok(),
706 wxT("cursor must be valid after call to the base version"));
708 wxWindowMac
*mouseWin
= 0 ;
711 wxNonOwnedWindow
*tlw
= MacGetTopLevelWindow() ;
712 WindowRef window
= (WindowRef
) ( tlw
? tlw
->GetWXWindow() : 0 ) ;
714 ControlPartCode part
;
717 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
719 HIGetMousePosition(kHICoordSpaceWindow
, window
, &hiPoint
);
723 GetGlobalMouse( &pt
);
726 ScreenToClient(&x
, &y
);
730 control
= FindControlUnderMouse( pt
, window
, &part
) ;
732 mouseWin
= wxFindWindowFromWXWidget( (WXWidget
) control
) ;
737 if ( mouseWin
== this && !wxIsBusy() )
738 m_cursor
.MacInstall() ;
744 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
746 #ifndef __WXUNIVERSAL__
747 menu
->SetInvokingWindow((wxWindow
*)this);
750 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
752 wxPoint mouse
= wxGetMousePosition();
758 ClientToScreen( &x
, &y
) ;
760 #ifdef __WXOSX_CARBON__
761 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
762 if ( HiWord(menuResult
) != 0 )
765 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
766 int id
= wxMacCommandToId( macid
);
767 wxMenuItem
* item
= NULL
;
769 item
= menu
->FindItem( id
, &realmenu
) ;
772 if (item
->IsCheckable())
773 item
->Check( !item
->IsChecked() ) ;
775 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
780 menu
->SetInvokingWindow( NULL
);
786 // actually this shouldn't be called, because universal is having its own implementation
792 // ----------------------------------------------------------------------------
794 // ----------------------------------------------------------------------------
798 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
800 wxWindowBase::DoSetToolTip(tooltip
);
803 m_tooltip
->SetWindow(this);
808 void wxWindowMac::MacInvalidateBorders()
810 if ( m_peer
== NULL
)
813 bool vis
= IsShownOnScreen() ;
817 int outerBorder
= MacGetLeftBorderSize() ;
819 if ( m_peer
->NeedsFocusRect() /* && m_peer->HasFocus() */ )
823 if ( outerBorder
== 0 )
826 // now we know that we have something to do at all
831 m_peer
->GetSize( tw
, th
);
832 m_peer
->GetPosition( tx
, ty
);
834 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
835 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
836 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
837 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
840 GetParent()->m_peer
->SetNeedsDisplay(&leftupdate
);
841 GetParent()->m_peer
->SetNeedsDisplay(&rightupdate
);
842 GetParent()->m_peer
->SetNeedsDisplay(&topupdate
);
843 GetParent()->m_peer
->SetNeedsDisplay(&bottomupdate
);
847 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
849 // this is never called for a toplevel window, so we know we have a parent
850 int former_x
, former_y
, former_w
, former_h
;
852 // Get true coordinates of former position
853 DoGetPosition( &former_x
, &former_y
) ;
854 DoGetSize( &former_w
, &former_h
) ;
856 wxWindow
*parent
= GetParent();
859 wxPoint
pt(parent
->GetClientAreaOrigin());
864 int actualWidth
= width
;
865 int actualHeight
= height
;
869 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
870 actualWidth
= m_minWidth
;
871 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
872 actualHeight
= m_minHeight
;
873 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
874 actualWidth
= m_maxWidth
;
875 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
876 actualHeight
= m_maxHeight
;
878 bool doMove
= false, doResize
= false ;
880 if ( actualX
!= former_x
|| actualY
!= former_y
)
883 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
886 if ( doMove
|| doResize
)
888 // as the borders are drawn outside the native control, we adjust now
890 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
891 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
892 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
894 if ( parent
&& !parent
->IsTopLevel() )
896 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
899 MacInvalidateBorders() ;
901 m_cachedClippedRectValid
= false ;
903 m_peer
->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
905 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
907 MacInvalidateBorders() ;
909 MacRepositionScrollBars() ;
912 wxPoint
point(actualX
, actualY
);
913 wxMoveEvent
event(point
, m_windowId
);
914 event
.SetEventObject(this);
915 HandleWindowEvent(event
) ;
920 MacRepositionScrollBars() ;
921 wxSize
size(actualWidth
, actualHeight
);
922 wxSizeEvent
event(size
, m_windowId
);
923 event
.SetEventObject(this);
924 HandleWindowEvent(event
);
929 wxSize
wxWindowMac::DoGetBestSize() const
931 if ( m_macIsUserPane
|| IsTopLevel() )
933 return wxWindowBase::DoGetBestSize() ;
939 m_peer
->GetBestRect(&r
);
941 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
948 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
953 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
960 // return wxWindowBase::DoGetBestSize() ;
964 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
965 MacGetRightBorderSize();
966 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
967 MacGetBottomBorderSize();
968 if ( bestHeight
< 10 )
971 return wxSize(bestWidth
, bestHeight
);
975 // set the size of the window: if the dimensions are positive, just use them,
976 // but if any of them is equal to -1, it means that we must find the value for
977 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
978 // which case -1 is a valid value for x and y)
980 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
981 // the width/height to best suit our contents, otherwise we reuse the current
983 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
985 // get the current size and position...
986 int currentX
, currentY
;
987 int currentW
, currentH
;
989 GetPosition(¤tX
, ¤tY
);
990 GetSize(¤tW
, ¤tH
);
992 // ... and don't do anything (avoiding flicker) if it's already ok
993 if ( x
== currentX
&& y
== currentY
&&
994 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
997 MacRepositionScrollBars() ; // we might have a real position shift
1002 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1004 if ( x
== wxDefaultCoord
)
1006 if ( y
== wxDefaultCoord
)
1010 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1012 wxSize size
= wxDefaultSize
;
1013 if ( width
== wxDefaultCoord
)
1015 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1017 size
= DoGetBestSize();
1022 // just take the current one
1027 if ( height
== wxDefaultCoord
)
1029 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1031 if ( size
.x
== wxDefaultCoord
)
1032 size
= DoGetBestSize();
1033 // else: already called DoGetBestSize() above
1039 // just take the current one
1044 DoMoveWindow( x
, y
, width
, height
);
1047 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1049 int left
,top
,width
,height
;
1050 m_peer
->GetContentArea( left
, top
, width
, height
);
1051 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1054 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1056 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1058 int currentclientwidth
, currentclientheight
;
1059 int currentwidth
, currentheight
;
1061 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1062 GetSize( ¤twidth
, ¤theight
) ;
1064 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1065 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1069 void wxWindowMac::SetLabel(const wxString
& title
)
1073 if ( m_peer
&& m_peer
->IsOk() )
1074 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1076 // do not trigger refreshes upon invisible and possible partly created objects
1077 if ( IsShownOnScreen() )
1081 wxString
wxWindowMac::GetLabel() const
1086 bool wxWindowMac::Show(bool show
)
1088 if ( !wxWindowBase::Show(show
) )
1092 m_peer
->SetVisibility( show
) ;
1097 void wxWindowMac::DoEnable(bool enable
)
1099 m_peer
->Enable( enable
) ;
1103 // status change notifications
1106 void wxWindowMac::MacVisibilityChanged()
1110 void wxWindowMac::MacHiliteChanged()
1114 void wxWindowMac::MacEnabledStateChanged()
1116 OnEnabled( m_peer
->IsEnabled() );
1120 // status queries on the inherited window's state
1123 bool wxWindowMac::MacIsReallyEnabled()
1125 return m_peer
->IsEnabled() ;
1128 bool wxWindowMac::MacIsReallyHilited()
1130 #if wxOSX_USE_CARBON
1131 return m_peer
->IsActive();
1133 return true; // TODO
1137 int wxWindowMac::GetCharHeight() const
1140 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1145 int wxWindowMac::GetCharWidth() const
1148 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1153 void wxWindowMac::GetTextExtent(const wxString
& str
, int *x
, int *y
,
1154 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1156 const wxFont
*fontToUse
= theFont
;
1160 tempFont
= GetFont();
1161 fontToUse
= &tempFont
;
1164 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1165 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1167 wxDouble h
, d
, e
, w
;
1168 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1172 if ( externalLeading
)
1173 *externalLeading
= (wxCoord
)(e
+0.5);
1175 *descent
= (wxCoord
)(d
+0.5);
1177 *x
= (wxCoord
)(w
+0.5);
1179 *y
= (wxCoord
)(h
+0.5);
1183 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1184 * we always intersect with the entire window, not only with the client area
1187 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1189 if ( m_peer
== NULL
)
1192 if ( !IsShownOnScreen() )
1195 m_peer
->SetNeedsDisplay( rect
) ;
1198 void wxWindowMac::DoFreeze()
1200 #if wxOSX_USE_CARBON
1201 if ( m_peer
&& m_peer
->IsOk() )
1202 m_peer
->SetDrawingEnabled( false ) ;
1206 void wxWindowMac::DoThaw()
1208 #if wxOSX_USE_CARBON
1209 if ( m_peer
&& m_peer
->IsOk() )
1211 m_peer
->SetDrawingEnabled( true ) ;
1212 m_peer
->InvalidateWithChildren() ;
1217 wxWindow
*wxGetActiveWindow()
1219 // actually this is a windows-only concept
1223 // Coordinates relative to the window
1224 void wxWindowMac::WarpPointer(int WXUNUSED(x_pos
), int WXUNUSED(y_pos
))
1226 // We really don't move the mouse programmatically under Mac.
1229 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1231 if ( MacGetTopLevelWindow() == NULL
)
1234 #if TARGET_API_MAC_OSX
1235 if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT )
1241 if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR
)
1243 event
.GetDC()->Clear() ;
1245 else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
1247 // don't skip the event here, custom background means that the app
1248 // is drawing it itself in its OnPaint(), so don't draw it at all
1249 // now to avoid flicker
1257 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1262 int wxWindowMac::GetScrollPos(int orient
) const
1264 if ( orient
== wxHORIZONTAL
)
1267 return m_hScrollBar
->GetThumbPosition() ;
1272 return m_vScrollBar
->GetThumbPosition() ;
1278 // This now returns the whole range, not just the number
1279 // of positions that we can scroll.
1280 int wxWindowMac::GetScrollRange(int orient
) const
1282 if ( orient
== wxHORIZONTAL
)
1285 return m_hScrollBar
->GetRange() ;
1290 return m_vScrollBar
->GetRange() ;
1296 int wxWindowMac::GetScrollThumb(int orient
) const
1298 if ( orient
== wxHORIZONTAL
)
1301 return m_hScrollBar
->GetThumbSize() ;
1306 return m_vScrollBar
->GetThumbSize() ;
1312 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1314 if ( orient
== wxHORIZONTAL
)
1317 m_hScrollBar
->SetThumbPosition( pos
) ;
1322 m_vScrollBar
->SetThumbPosition( pos
) ;
1327 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1329 bool needVisibilityUpdate
= false;
1331 if ( m_hScrollBarAlwaysShown
!= hflag
)
1333 m_hScrollBarAlwaysShown
= hflag
;
1334 needVisibilityUpdate
= true;
1337 if ( m_vScrollBarAlwaysShown
!= vflag
)
1339 m_vScrollBarAlwaysShown
= vflag
;
1340 needVisibilityUpdate
= true;
1343 if ( needVisibilityUpdate
)
1344 DoUpdateScrollbarVisibility();
1348 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1349 // our own window origin is at leftOrigin/rightOrigin
1352 void wxWindowMac::MacPaintGrowBox()
1357 if ( MacHasScrollBarCorner() )
1359 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1360 wxASSERT( cgContext
) ;
1364 m_peer
->GetSize( tw
, th
);
1365 m_peer
->GetPosition( tx
, ty
);
1367 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1370 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1371 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1372 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1373 CGContextSaveGState( cgContext
);
1375 if ( m_backgroundColour
.Ok() )
1377 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1381 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1383 CGContextFillRect( cgContext
, cgrect
);
1384 CGContextRestoreGState( cgContext
);
1388 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1393 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
1395 // back to the surrounding frame rectangle
1398 m_peer
->GetSize( tw
, th
);
1399 m_peer
->GetPosition( tx
, ty
);
1401 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1403 #if wxOSX_USE_COCOA_OR_CARBON
1405 InsetRect( &rect
, -1 , -1 ) ;
1408 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
1409 rect
.bottom
- rect
.top
) ;
1411 HIThemeFrameDrawInfo info
;
1412 memset( &info
, 0 , sizeof(info
) ) ;
1416 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1417 info
.isFocused
= hasFocus
;
1419 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1420 wxASSERT( cgContext
) ;
1422 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1424 info
.kind
= kHIThemeFrameTextFieldSquare
;
1425 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1427 else if ( HasFlag(wxSIMPLE_BORDER
) )
1429 info
.kind
= kHIThemeFrameListBox
;
1430 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1432 else if ( hasFocus
)
1434 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1436 #if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
1437 m_peer
->GetRect( &rect
) ;
1438 if ( MacHasScrollBarCorner() )
1440 int variant
= (m_hScrollBar
== NULL
? m_vScrollBar
: m_hScrollBar
) ->GetWindowVariant();
1441 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1442 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1443 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
1444 HIThemeGrowBoxDrawInfo info
;
1445 memset( &info
, 0, sizeof(info
) ) ;
1447 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1448 info
.kind
= kHIThemeGrowBoxKindNone
;
1449 // contrary to the docs ...SizeSmall does not work
1450 info
.size
= kHIThemeGrowBoxSizeNormal
;
1451 info
.direction
= 0 ;
1452 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1456 #endif // wxOSX_USE_COCOA_OR_CARBON
1459 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1461 if ( child
== m_hScrollBar
)
1462 m_hScrollBar
= NULL
;
1463 if ( child
== m_vScrollBar
)
1464 m_vScrollBar
= NULL
;
1466 wxWindowBase::RemoveChild( child
) ;
1469 void wxWindowMac::DoUpdateScrollbarVisibility()
1471 bool triggerSizeEvent
= false;
1475 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1477 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1479 m_hScrollBar
->Show( showHScrollBar
);
1480 triggerSizeEvent
= true;
1486 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1488 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1490 m_vScrollBar
->Show( showVScrollBar
) ;
1491 triggerSizeEvent
= true;
1495 MacRepositionScrollBars() ;
1496 if ( triggerSizeEvent
)
1498 wxSizeEvent
event(GetSize(), m_windowId
);
1499 event
.SetEventObject(this);
1500 HandleWindowEvent(event
);
1504 // New function that will replace some of the above.
1505 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1506 int range
, bool refresh
)
1508 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1509 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1510 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1511 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1513 DoUpdateScrollbarVisibility();
1516 // Does a physical scroll
1517 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1519 if ( dx
== 0 && dy
== 0 )
1522 int width
, height
;
1523 GetClientSize( &width
, &height
) ;
1526 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1528 scrollrect
.Intersect( *rect
) ;
1529 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1530 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1532 m_peer
->ScrollRect( &scrollrect
, dx
, dy
);
1537 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1539 child
= node
->GetData();
1542 if (child
== m_vScrollBar
)
1544 if (child
== m_hScrollBar
)
1546 if (child
->IsTopLevel())
1549 child
->GetPosition( &x
, &y
);
1550 child
->GetSize( &w
, &h
);
1553 wxRect
rc( x
, y
, w
, h
);
1554 if (rect
->Intersects( rc
))
1555 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1559 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1564 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1566 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1568 wxScrollWinEvent wevent
;
1569 wevent
.SetPosition(event
.GetPosition());
1570 wevent
.SetOrientation(event
.GetOrientation());
1571 wevent
.SetEventObject(this);
1573 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1574 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1575 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1576 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1577 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1578 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1579 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1580 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1581 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1582 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1583 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1584 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1585 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1586 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1587 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1588 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1590 HandleWindowEvent(wevent
);
1594 // Get the window with the focus
1595 wxWindow
*wxWindowBase::DoFindFocus()
1597 #if wxOSX_USE_CARBON
1598 ControlRef control
;
1599 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1600 return wxFindWindowFromWXWidget( (WXWidget
) control
) ;
1606 void wxWindowMac::OnInternalIdle()
1608 // This calls the UI-update mechanism (querying windows for
1609 // menu/toolbar/control state information)
1610 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1611 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1614 // Raise the window to the top of the Z order
1615 void wxWindowMac::Raise()
1620 // Lower the window to the bottom of the Z order
1621 void wxWindowMac::Lower()
1626 // static wxWindow *gs_lastWhich = NULL;
1628 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1630 // first trigger a set cursor event
1632 wxPoint clientorigin
= GetClientAreaOrigin() ;
1633 wxSize clientsize
= GetClientSize() ;
1635 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1637 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1639 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1640 if ( processedEvtSetCursor
&& event
.HasCursor() )
1642 cursor
= event
.GetCursor() ;
1646 // the test for processedEvtSetCursor is here to prevent using m_cursor
1647 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1648 // it - this is a way to say that our cursor shouldn't be used for this
1650 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
1653 if ( !wxIsBusy() && !GetParent() )
1654 cursor
= *wxSTANDARD_CURSOR
;
1658 cursor
.MacInstall() ;
1661 return cursor
.Ok() ;
1664 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1668 return m_tooltip
->GetTip() ;
1671 return wxEmptyString
;
1674 void wxWindowMac::ClearBackground()
1680 void wxWindowMac::Update()
1682 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1687 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1689 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1693 if ( iter
->IsTopLevel() )
1695 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1699 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1704 iter
= iter
->GetParent() ;
1710 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1712 MacUpdateClippedRects() ;
1714 return m_cachedClippedClientRect
;
1717 const wxRect
& wxWindowMac::MacGetClippedRect() const
1719 MacUpdateClippedRects() ;
1721 return m_cachedClippedRect
;
1724 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1726 MacUpdateClippedRects() ;
1728 return m_cachedClippedRectWithOuterStructure
;
1731 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1733 static wxRegion emptyrgn
;
1735 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1737 MacUpdateClippedRects() ;
1738 if ( includeOuterStructures
)
1739 return m_cachedClippedRegionWithOuterStructure
;
1741 return m_cachedClippedRegion
;
1749 void wxWindowMac::MacUpdateClippedRects() const
1751 #if wxOSX_USE_CARBON
1752 if ( m_cachedClippedRectValid
)
1755 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1756 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1757 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1758 // to add focus borders everywhere
1760 Rect rIncludingOuterStructures
;
1764 m_peer
->GetSize( tw
, th
);
1765 m_peer
->GetPosition( tx
, ty
);
1767 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1769 r
.left
-= MacGetLeftBorderSize() ;
1770 r
.top
-= MacGetTopBorderSize() ;
1771 r
.bottom
+= MacGetBottomBorderSize() ;
1772 r
.right
+= MacGetRightBorderSize() ;
1779 rIncludingOuterStructures
= r
;
1780 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1782 wxRect cl
= GetClientRect() ;
1783 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1787 const wxWindow
* child
= (wxWindow
*) this ;
1788 const wxWindow
* parent
= NULL
;
1790 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1792 if ( parent
->MacIsChildOfClientArea(child
) )
1794 size
= parent
->GetClientSize() ;
1795 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1801 // this will be true for scrollbars, toolbars etc.
1802 size
= parent
->GetSize() ;
1803 y
= parent
->MacGetTopBorderSize() ;
1804 x
= parent
->MacGetLeftBorderSize() ;
1805 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1806 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1809 parent
->MacWindowToRootWindow( &x
, &y
) ;
1810 MacRootWindowToWindow( &x
, &y
) ;
1812 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1814 // the wxwindow and client rects will always be clipped
1815 SectRect( &r
, &rparent
, &r
) ;
1816 SectRect( &rClient
, &rparent
, &rClient
) ;
1818 // the structure only at 'hard' borders
1819 if ( parent
->MacClipChildren() ||
1820 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1822 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1828 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1829 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1830 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1831 m_cachedClippedRectWithOuterStructure
= wxRect(
1832 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1833 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1834 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1836 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1837 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1838 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1840 m_cachedClippedRectValid
= true ;
1845 This function must not change the updatergn !
1847 bool wxWindowMac::MacDoRedraw( void* updatergnr
, long time
)
1849 bool handled
= false ;
1850 #if wxOSX_USE_CARBON
1852 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
1853 GetRegionBounds( updatergn
, &updatebounds
) ;
1855 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
1857 if ( !EmptyRgn(updatergn
) )
1859 RgnHandle newupdate
= NewRgn() ;
1860 wxSize point
= GetClientSize() ;
1861 wxPoint origin
= GetClientAreaOrigin() ;
1862 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
1863 SectRgn( newupdate
, updatergn
, newupdate
) ;
1865 // first send an erase event to the entire update area
1867 // for the toplevel window this really is the entire area
1868 // for all the others only their client area, otherwise they
1869 // might be drawing with full alpha and eg put blue into
1870 // the grow-box area of a scrolled window (scroll sample)
1871 wxDC
* dc
= new wxWindowDC(this);
1873 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn
)));
1875 dc
->SetDeviceClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate
)));
1877 wxEraseEvent
eevent( GetId(), dc
);
1878 eevent
.SetEventObject( this );
1879 HandleWindowEvent( eevent
);
1885 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1886 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
1887 m_updateRegion
= wxRegion(HIShapeCreateWithQDRgn(newupdate
)) ;
1888 DisposeRgn( newupdate
) ;
1890 if ( !m_updateRegion
.Empty() )
1892 // paint the window itself
1895 event
.SetTimestamp(time
);
1896 event
.SetEventObject(this);
1897 HandleWindowEvent(event
);
1901 // now we cannot rely on having its borders drawn by a window itself, as it does not
1902 // get the updateRgn wide enough to always do so, so we do it from the parent
1903 // this would also be the place to draw any custom backgrounds for native controls
1904 // in Composited windowing
1905 wxPoint clientOrigin
= GetClientAreaOrigin() ;
1909 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1911 child
= node
->GetData();
1914 if (child
== m_vScrollBar
)
1916 if (child
== m_hScrollBar
)
1918 if (child
->IsTopLevel())
1920 if (!child
->IsShown())
1923 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
1925 child
->GetPosition( &x
, &y
);
1926 child
->GetSize( &w
, &h
);
1927 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
1928 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
1929 InsetRect( &childRect
, -10 , -10) ;
1931 if ( RectInRgn( &childRect
, updatergn
) )
1933 // paint custom borders
1934 wxNcPaintEvent
eventNc( child
->GetId() );
1935 eventNc
.SetEventObject( child
);
1936 if ( !child
->HandleWindowEvent( eventNc
) )
1938 child
->MacPaintBorders(0, 0) ;
1948 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
1950 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
1951 return tlw
? tlw
->GetWXWindow() : NULL
;
1954 bool wxWindowMac::MacHasScrollBarCorner() const
1956 /* Returns whether the scroll bars in a wxScrolledWindow should be
1957 * shortened. Scroll bars should be shortened if either:
1959 * - both scroll bars are visible, or
1961 * - there is a resize box in the parent frame's corner and this
1962 * window shares the bottom and right edge with the parent
1966 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
1969 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
1970 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
1972 // Both scroll bars visible
1977 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
1979 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
1981 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
1984 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
1986 // Parent frame has resize handle
1987 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
1989 // Note: allow for some wiggle room here as wxMac's
1990 // window rect calculations seem to be imprecise
1991 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
1992 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
1994 // Parent frame has resize handle and shares
1995 // right bottom corner
2000 // Parent frame has resize handle but doesn't
2001 // share right bottom corner
2007 // Parent frame doesn't have resize handle
2013 // No parent frame found
2018 void wxWindowMac::MacCreateScrollBars( long style
)
2020 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2022 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2024 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2025 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2027 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2030 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2032 GetClientSize( &width
, &height
) ;
2034 wxPoint
vPoint(width
- scrlsize
, 0) ;
2035 wxSize
vSize(scrlsize
, height
- adjust
) ;
2036 wxPoint
hPoint(0, height
- scrlsize
) ;
2037 wxSize
hSize(width
- adjust
, scrlsize
) ;
2039 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2040 if ( style
& wxVSCROLL
)
2042 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2043 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2046 if ( style
& wxHSCROLL
)
2048 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2049 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2053 // because the create does not take into account the client area origin
2054 // we might have a real position shift
2055 MacRepositionScrollBars() ;
2058 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2060 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
2065 void wxWindowMac::MacRepositionScrollBars()
2067 if ( !m_hScrollBar
&& !m_vScrollBar
)
2070 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2071 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2073 // get real client area
2075 GetSize( &width
, &height
);
2077 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2078 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2080 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2081 wxSize
vSize( scrlsize
, height
- adjust
) ;
2082 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2083 wxSize
hSize( width
- adjust
, scrlsize
) ;
2086 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2088 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2091 bool wxWindowMac::AcceptsFocus() const
2093 return m_peer
->CanFocus() && wxWindowBase::AcceptsFocus();
2096 void wxWindowMac::MacSuperChangedPosition()
2098 // only window-absolute structures have to be moved i.e. controls
2100 m_cachedClippedRectValid
= false ;
2103 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2106 child
= node
->GetData();
2107 child
->MacSuperChangedPosition() ;
2109 node
= node
->GetNext();
2113 void wxWindowMac::MacTopLevelWindowChangedPosition()
2115 // only screen-absolute structures have to be moved i.e. glcanvas
2118 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2121 child
= node
->GetData();
2122 child
->MacTopLevelWindowChangedPosition() ;
2124 node
= node
->GetNext();
2128 long wxWindowMac::MacGetLeftBorderSize() const
2135 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2137 #if wxOSX_USE_COCOA_OR_CARBON
2138 // this metric is only the 'outset' outside the simple frame rect
2139 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2145 else if (HasFlag(wxSIMPLE_BORDER
))
2147 #if wxOSX_USE_COCOA_OR_CARBON
2148 // this metric is only the 'outset' outside the simple frame rect
2149 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2159 long wxWindowMac::MacGetRightBorderSize() const
2161 // they are all symmetric in mac themes
2162 return MacGetLeftBorderSize() ;
2165 long wxWindowMac::MacGetTopBorderSize() const
2167 // they are all symmetric in mac themes
2168 return MacGetLeftBorderSize() ;
2171 long wxWindowMac::MacGetBottomBorderSize() const
2173 // they are all symmetric in mac themes
2174 return MacGetLeftBorderSize() ;
2177 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2179 return style
& ~wxBORDER_MASK
;
2182 // Find the wxWindowMac at the current mouse position, returning the mouse
2184 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2186 pt
= wxGetMousePosition();
2187 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2189 return (wxWindow
*) found
;
2192 // Get the current mouse position.
2193 wxPoint
wxGetMousePosition()
2197 wxGetMousePosition( &x
, &y
);
2199 return wxPoint(x
, y
);
2202 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2204 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2206 // copied from wxGTK : CS
2207 // VZ: shouldn't we move this to base class then?
2209 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2212 // (a) it's a command event and so is propagated to the parent
2213 // (b) under MSW it can be generated from kbd too
2214 // (c) it uses screen coords (because of (a))
2215 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2217 this->ClientToScreen(event
.GetPosition()));
2218 evtCtx
.SetEventObject(this);
2219 if ( ! HandleWindowEvent(evtCtx
) )
2228 void wxWindowMac::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
2230 #if wxOSX_USE_COCOA_OR_CARBON
2231 // for native controls: call their native paint method
2232 if ( !MacIsUserPane() || ( IsTopLevel() && GetBackgroundStyle() == wxBG_STYLE_SYSTEM
) )
2234 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
2235 && GetBackgroundStyle() != wxBG_STYLE_TRANSPARENT
)
2236 CallNextEventHandler(
2237 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
2238 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2243 void wxWindowMac::MacHandleControlClick(WXWidget
WXUNUSED(control
),
2244 wxInt16
WXUNUSED(controlpart
),
2245 bool WXUNUSED(mouseStillDown
))
2249 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2253 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2254 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
2259 bool wxWindowMac::HandleClicked( double timestampsec
)
2264 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2266 #if wxOSX_USE_COCOA_OR_CARBON
2267 if ( HandleClicked( GetEventTime((EventRef
)event
) ) )
2270 return eventNotHandledErr
;
2276 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2278 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2279 if ( !wxWindowBase::Reparent(newParent
) )
2282 m_peer
->RemoveFromParent();
2283 m_peer
->Embed( GetParent()->GetPeer() );
2287 bool wxWindowMac::SetTransparent(wxByte alpha
)
2289 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2291 if ( alpha
!= m_macAlpha
)
2293 m_macAlpha
= alpha
;
2300 bool wxWindowMac::CanSetTransparent()
2305 wxByte
wxWindowMac::GetTransparent() const
2310 bool wxWindowMac::IsShownOnScreen() const
2312 if ( m_peer
&& m_peer
->IsOk() )
2314 bool peerVis
= m_peer
->IsVisible();
2315 bool wxVis
= wxWindowBase::IsShownOnScreen();
2316 if( peerVis
!= wxVis
)
2318 // CS : put a breakpoint here to investigate differences
2319 // between native an wx visibilities
2320 // the only place where I've encountered them until now
2321 // are the hiding/showing sequences where the vis-changed event is
2322 // first sent to the innermost control, while wx does things
2323 // from the outmost control
2324 wxVis
= wxWindowBase::IsShownOnScreen();
2328 return m_peer
->IsVisible();
2330 return wxWindowBase::IsShownOnScreen();
2337 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2339 static MacControlMap wxWinMacControlList
;
2341 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2343 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2345 return impl
->GetWXPeer();
2350 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2352 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2354 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2357 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2359 // adding NULL ControlRef is (first) surely a result of an error and
2360 // (secondly) breaks native event processing
2361 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2363 wxWinMacControlList
[inControl
] = impl
;
2366 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2368 // iterate over all the elements in the class
2369 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2370 // we should go on...
2376 MacControlMap::iterator it
;
2377 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2379 if ( it
->second
== impl
)
2381 wxWinMacControlList
.erase(it
);
2389 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2391 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
)
2394 m_isRootControl
= isRootControl
;
2398 wxWidgetImpl::wxWidgetImpl()
2403 wxWidgetImpl::~wxWidgetImpl()
2407 void wxWidgetImpl::Init()
2409 m_isRootControl
= false;
2411 m_needsFocusRect
= false;
2414 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2416 m_needsFocusRect
= needs
;
2419 bool wxWidgetImpl::NeedsFocusRect() const
2421 return m_needsFocusRect
;