1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/window_osx.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
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"
72 #define MAC_SCROLLBAR_SIZE 15
73 #define MAC_SMALL_SCROLLBAR_SIZE 11
77 #ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
85 #define wxMAC_DEBUG_REDRAW 0
86 #ifndef wxMAC_DEBUG_REDRAW
87 #define wxMAC_DEBUG_REDRAW 0
90 wxWidgetImplType
* kOSXNoWidgetImpl
= (wxWidgetImplType
*) -1L;
92 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
100 wxVector
<wxHotKeyRec
> s_hotkeys
;
104 // ===========================================================================
106 // ===========================================================================
108 // the grow box has to be implemented as an inactive window, so that nothing can direct
111 class WXDLLIMPEXP_CORE wxBlindPlateWindow
: public wxWindow
114 wxBlindPlateWindow() { Init(); }
116 // Old-style constructor (no default values for coordinates to avoid
117 // ambiguity with the new one)
118 wxBlindPlateWindow(wxWindow
*parent
,
119 int x
, int y
, int width
, int height
,
120 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
121 const wxString
& name
= wxPanelNameStr
)
125 Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), style
, name
);
129 wxBlindPlateWindow(wxWindow
*parent
,
130 wxWindowID winid
= wxID_ANY
,
131 const wxPoint
& pos
= wxDefaultPosition
,
132 const wxSize
& size
= wxDefaultSize
,
133 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
134 const wxString
& name
= wxPanelNameStr
)
138 Create(parent
, winid
, pos
, size
, style
, name
);
142 bool Create(wxWindow
*parent
,
143 wxWindowID winid
= wxID_ANY
,
144 const wxPoint
& pos
= wxDefaultPosition
,
145 const wxSize
& size
= wxDefaultSize
,
146 long style
= wxTAB_TRAVERSAL
| wxNO_BORDER
,
147 const wxString
& name
= wxPanelNameStr
)
149 if ( !wxWindow::Create(parent
, winid
, pos
, size
, style
, name
) )
152 // so that non-solid background renders correctly under GTK+:
153 SetThemeEnabled(true);
157 virtual ~wxBlindPlateWindow();
159 virtual bool AcceptsFocus() const
165 // common part of all ctors
170 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow
)
171 DECLARE_EVENT_TABLE()
174 wxBlindPlateWindow::~wxBlindPlateWindow()
178 IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow
, wxWindow
)
180 BEGIN_EVENT_TABLE(wxBlindPlateWindow
, wxWindow
)
184 // ----------------------------------------------------------------------------
185 // constructors and such
186 // ----------------------------------------------------------------------------
188 wxWindowMac::wxWindowMac()
193 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
198 const wxString
& name
)
201 Create(parent
, id
, pos
, size
, style
, name
);
204 void wxWindowMac::Init()
208 m_cgContextRef
= NULL
;
210 // as all windows are created with WS_VISIBLE style...
213 m_hScrollBar
= NULL
;
214 m_vScrollBar
= NULL
;
215 m_hScrollBarAlwaysShown
= false;
216 m_vScrollBarAlwaysShown
= false;
219 m_clipChildren
= false ;
220 m_cachedClippedRectValid
= false ;
221 m_isNativeWindowWrapper
= false;
224 wxWindowMac::~wxWindowMac()
228 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
229 for ( int i
= s_hotkeys
.size()-1; i
>=0; -- i
)
231 if ( s_hotkeys
[i
].window
== this )
233 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
234 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
235 if ( UnregisterEventHotKey(ref
) != noErr
)
237 wxLogLastError(wxT("UnregisterHotKey"));
243 MacInvalidateBorders() ;
245 #ifndef __WXUNIVERSAL__
246 // VS: make sure there's no wxFrame with last focus set to us:
247 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
249 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
252 if ( frame
->GetLastFocus() == this )
253 frame
->SetLastFocus(NULL
);
259 // destroy children before destroying this window itself
262 // wxRemoveMacControlAssociation( this ) ;
263 // If we delete an item, we should initialize the parent panel,
264 // because it could now be invalid.
265 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this), wxTopLevelWindow
);
268 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
269 tlw
->SetDefaultItem(NULL
);
272 if ( g_MacLastWindow
== this )
273 g_MacLastWindow
= NULL
;
275 #ifndef __WXUNIVERSAL__
276 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( (wxWindow
*)this ) , wxFrame
) ;
279 if ( frame
->GetLastFocus() == this )
280 frame
->SetLastFocus( NULL
) ;
284 // delete our drop target if we've got one
285 #if wxUSE_DRAG_AND_DROP
286 wxDELETE(m_dropTarget
);
292 WXWidget
wxWindowMac::GetHandle() const
295 return (WXWidget
) GetPeer()->GetWXWidget() ;
299 wxOSXWidgetImpl
* wxWindowMac::GetPeer() const
301 return m_peer
== kOSXNoWidgetImpl
? NULL
: m_peer
;
304 bool wxWindowMac::ShouldCreatePeer() const
306 return m_peer
!= kOSXNoWidgetImpl
;
309 void wxWindowMac::DontCreatePeer()
311 m_peer
= kOSXNoWidgetImpl
;
314 void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl
* wrapper
)
316 wxOSXWidgetImpl
* inner
= GetPeer();
317 wxASSERT_MSG( inner
!= NULL
&& inner
->IsOk(), "missing or incomplete inner peer" );
318 wxASSERT_MSG( wrapper
!= NULL
&& wrapper
->IsOk(), "missing or incomplete wrapper" );
320 if ( !(inner
!= NULL
&& inner
->IsOk() && wrapper
!= NULL
&& wrapper
->IsOk()) )
323 inner
->RemoveFromParent();
324 wrapper
->InstallEventHandler();
325 wrapper
->Embed(inner
);
329 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
333 if ( !GetPeer()->IsRootControl() )
334 GetPeer()->RemoveFromParent();
340 if ( GetPeer() && !GetPeer()->IsRootControl())
342 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
344 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
345 GetParent()->AddChild( this );
347 GetPeer()->InstallEventHandler();
348 GetPeer()->Embed(GetParent()->GetPeer());
350 GetParent()->MacChildAdded() ;
352 // adjust font, controlsize etc
353 GetPeer()->SetControlSize( m_windowVariant
);
355 // in case nothing has been set, use the variant default fonts
357 DoSetWindowVariant( m_windowVariant
);
359 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
361 // for controls we want to use best size for wxDefaultSize params )
362 if ( !GetPeer()->IsUserPane() )
363 SetInitialSize(GetMinSize());
365 SetCursor( *wxSTANDARD_CURSOR
) ;
369 #if WXWIN_COMPATIBILITY_2_8
371 bool wxWindowMac::MacIsUserPane()
373 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
378 bool wxWindowMac::MacIsUserPane() const
380 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
383 // ---------------------------------------------------------------------------
384 // Utility Routines to move between different coordinate systems
385 // ---------------------------------------------------------------------------
388 * Right now we have the following setup :
389 * a border that is not part of the native control is always outside the
390 * control's border (otherwise we lose all native intelligence, future ways
391 * may be to have a second embedding control responsible for drawing borders
392 * and backgrounds eventually)
393 * so all this border calculations have to be taken into account when calling
394 * native methods or getting native oriented data
395 * so we have three coordinate systems here
396 * wx client coordinates
397 * wx window coordinates (including window frames)
405 bool wxWindowMac::Create(wxWindowMac
*parent
,
410 const wxString
& name
)
412 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
414 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
417 m_windowVariant
= parent
->GetWindowVariant() ;
419 if ( m_peer
!= kOSXNoWidgetImpl
)
421 SetPeer(wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
422 MacPostControlCreate(pos
, size
) ;
425 #ifndef __WXUNIVERSAL__
426 // Don't give scrollbars to wxControls unless they ask for them
427 if ( (! IsKindOf(CLASSINFO(wxControl
))
429 && ! IsKindOf(CLASSINFO(wxStatusBar
))
432 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
434 MacCreateScrollBars( style
) ;
438 wxWindowCreateEvent
event((wxWindow
*)this);
439 GetEventHandler()->AddPendingEvent(event
);
444 void wxWindowMac::MacChildAdded()
448 m_vScrollBar
->Raise() ;
450 m_hScrollBar
->Raise() ;
456 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
),
457 const wxSize
& WXUNUSED(size
))
459 // todo remove if refactoring works correctly
461 wxASSERT_MSG( GetPeer() != NULL
&& GetPeer()->IsOk() , wxT("No valid mac control") ) ;
463 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
464 GetParent()->AddChild( this );
466 GetPeer()->InstallEventHandler();
467 GetPeer()->Embed(GetParent()->GetPeer());
469 GetParent()->MacChildAdded() ;
471 // adjust font, controlsize etc
472 DoSetWindowVariant( m_windowVariant
) ;
474 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
476 // for controls we want to use best size for wxDefaultSize params )
477 if ( !GetPeer()->IsUserPane() )
478 SetInitialSize(size
);
480 SetCursor( *wxSTANDARD_CURSOR
) ;
484 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
486 // Don't assert, in case we set the window variant before
487 // the window is created
488 // wxASSERT( GetPeer()->IsOk() ) ;
490 m_windowVariant
= variant
;
492 if (GetPeer() == NULL
|| !GetPeer()->IsOk())
495 GetPeer()->SetControlSize( variant
);
499 case wxWINDOW_VARIANT_NORMAL
:
500 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
504 case wxWINDOW_VARIANT_SMALL
:
505 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
509 case wxWINDOW_VARIANT_MINI
:
510 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
514 case wxWINDOW_VARIANT_LARGE
:
515 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
520 wxFAIL_MSG(wxT("unexpected window variant"));
525 void wxWindowMac::MacUpdateControlFont()
528 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
530 // do not trigger refreshes upon invisible and possible partly created objects
531 if ( IsShownOnScreen() )
535 bool wxWindowMac::SetFont(const wxFont
& font
)
537 bool retval
= wxWindowBase::SetFont( font
);
539 MacUpdateControlFont() ;
544 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
546 bool retval
= wxWindowBase::SetForegroundColour( col
);
549 MacUpdateControlFont();
554 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
556 if ( !wxWindowBase::SetBackgroundStyle(style
) )
560 GetPeer()->SetBackgroundStyle(style
);
564 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
568 if ( m_backgroundColour
.IsOk() )
569 m_growBox
->SetBackgroundColour(m_backgroundColour
);
571 m_growBox
->SetBackgroundColour(*wxWHITE
);
574 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
578 GetPeer()->SetBackgroundColour( col
) ;
583 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
585 while (w
&& !w
->IsTopLevel())
594 void wxWindowMac::SetFocus()
596 if ( !AcceptsFocus() )
599 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
602 wxWindow
* former
= FindFocus() ;
603 if ( former
== this )
606 GetPeer()->SetFocus() ;
609 void wxWindowMac::OSXSimulateFocusEvents()
611 wxWindow
* former
= FindFocus() ;
612 if ( former
!= NULL
&& former
!= this )
615 wxFocusEvent
event( wxEVT_KILL_FOCUS
, former
->GetId());
616 event
.SetEventObject(former
);
617 event
.SetWindow(this);
618 former
->HandleWindowEvent(event
) ;
622 wxFocusEvent
event(wxEVT_SET_FOCUS
, former
->GetId());
623 event
.SetEventObject(former
);
624 event
.SetWindow(this);
625 former
->HandleWindowEvent(event
);
630 void wxWindowMac::DoCaptureMouse()
632 wxApp::s_captureWindow
= (wxWindow
*) this ;
633 GetPeer()->CaptureMouse() ;
636 wxWindow
* wxWindowBase::GetCapture()
638 return wxApp::s_captureWindow
;
641 void wxWindowMac::DoReleaseMouse()
643 wxApp::s_captureWindow
= NULL
;
645 GetPeer()->ReleaseMouse() ;
648 #if wxUSE_DRAG_AND_DROP
650 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
654 m_dropTarget
= pDropTarget
;
656 GetPeer()->SetDropTarget(m_dropTarget
) ;
661 // Old-style File Manager Drag & Drop
662 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
667 // From a wx position / size calculate the appropriate size of the native control
669 bool wxWindowMac::MacGetBoundsForControl(
673 int& w
, int& h
, bool adjustOrigin
) const
675 // the desired size, minus the border pixels gives the correct size of the control
679 w
= WidthDefault( size
.x
);
680 h
= HeightDefault( size
.y
);
682 x
+= MacGetLeftBorderSize() ;
683 y
+= MacGetTopBorderSize() ;
684 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
685 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
688 AdjustForParentClientOrigin( x
, y
) ;
690 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
691 if ( GetParent() && !GetParent()->IsTopLevel() )
693 x
-= GetParent()->MacGetLeftBorderSize() ;
694 y
-= GetParent()->MacGetTopBorderSize() ;
700 // Get window size (not client size)
701 void wxWindowMac::DoGetSize(int *x
, int *y
) const
704 GetPeer()->GetSize( width
, height
);
707 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
709 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
712 // get the position of the bounds of this window in client coordinates of its parent
713 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
717 GetPeer()->GetPosition( x1
, y1
) ;
719 // get the wx window position from the native one
720 x1
-= MacGetLeftBorderSize() ;
721 y1
-= MacGetTopBorderSize() ;
725 wxWindow
*parent
= GetParent();
728 // we must first adjust it to be in window coordinates of the parent,
729 // as otherwise it gets lost by the ClientAreaOrigin fix
730 x1
+= parent
->MacGetLeftBorderSize() ;
731 y1
+= parent
->MacGetTopBorderSize() ;
733 // and now to client coordinates
734 wxPoint
pt(parent
->GetClientAreaOrigin());
746 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
748 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
749 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
750 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
751 MacRootWindowToWindow( x
, y
) ;
753 wxPoint origin
= GetClientAreaOrigin() ;
760 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
762 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
763 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
765 wxPoint origin
= GetClientAreaOrigin() ;
771 MacWindowToRootWindow( x
, y
) ;
772 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
775 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
777 wxPoint origin
= GetClientAreaOrigin() ;
783 MacWindowToRootWindow( x
, y
) ;
786 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
797 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
800 pt
.x
-= MacGetLeftBorderSize() ;
801 pt
.y
-= MacGetTopBorderSize() ;
802 wxWidgetImpl::Convert( &pt
, GetPeer() , top
->GetPeer() ) ;
812 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
823 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
826 wxWidgetImpl::Convert( &pt
, top
->GetPeer() , GetPeer() ) ;
827 pt
.x
+= MacGetLeftBorderSize() ;
828 pt
.y
+= MacGetTopBorderSize() ;
838 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
840 wxSize sizeTotal
= size
;
842 int innerwidth
, innerheight
;
844 int outerwidth
, outerheight
;
846 GetPeer()->GetContentArea( left
, top
, innerwidth
, innerheight
);
847 GetPeer()->GetSize( outerwidth
, outerheight
);
849 sizeTotal
.x
+= outerwidth
-innerwidth
;
850 sizeTotal
.y
+= outerheight
-innerheight
;
852 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
853 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
858 // Get size *available for subwindows* i.e. excluding menu bar etc.
859 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
865 GetPeer()->GetContentArea( left
, top
, ww
, hh
);
867 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
868 hh
-= m_hScrollBar
->GetSize().y
;
870 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
871 ww
-= m_vScrollBar
->GetSize().x
;
880 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
882 if (m_cursor
.IsSameAs(cursor
))
887 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
892 if ( ! wxWindowBase::SetCursor( cursor
) )
896 wxASSERT_MSG( m_cursor
.IsOk(),
897 wxT("cursor must be valid after call to the base version"));
899 if ( GetPeer() != NULL
)
900 GetPeer()->SetCursor( m_cursor
);
906 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
908 #ifndef __WXUNIVERSAL__
911 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
913 wxPoint mouse
= wxGetMousePosition();
919 ClientToScreen( &x
, &y
) ;
921 menu
->GetPeer()->PopUp(this, x
, y
);
924 // actually this shouldn't be called, because universal is having its own implementation
930 // ----------------------------------------------------------------------------
932 // ----------------------------------------------------------------------------
936 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
938 wxWindowBase::DoSetToolTip(tooltip
);
941 m_tooltip
->SetWindow(this);
944 GetPeer()->SetToolTip(tooltip
);
949 void wxWindowMac::MacInvalidateBorders()
951 if ( GetPeer() == NULL
)
954 bool vis
= IsShownOnScreen() ;
958 int outerBorder
= MacGetLeftBorderSize() ;
960 if ( GetPeer()->NeedsFocusRect() )
963 if ( outerBorder
== 0 )
966 // now we know that we have something to do at all
970 GetPeer()->GetSize( tw
, th
);
971 GetPeer()->GetPosition( tx
, ty
);
973 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
974 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
975 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
976 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
979 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate
);
980 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate
);
981 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate
);
982 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate
);
986 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
988 // this is never called for a toplevel window, so we know we have a parent
989 int former_x
, former_y
, former_w
, former_h
;
991 // Get true coordinates of former position
992 DoGetPosition( &former_x
, &former_y
) ;
993 DoGetSize( &former_w
, &former_h
) ;
995 wxWindow
*parent
= GetParent();
998 wxPoint
pt(parent
->GetClientAreaOrigin());
1003 int actualWidth
= width
;
1004 int actualHeight
= height
;
1009 // min and max sizes are only for sizers, not for explicit size setting
1010 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1011 actualWidth
= m_minWidth
;
1012 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1013 actualHeight
= m_minHeight
;
1014 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1015 actualWidth
= m_maxWidth
;
1016 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1017 actualHeight
= m_maxHeight
;
1020 bool doMove
= false, doResize
= false ;
1022 if ( actualX
!= former_x
|| actualY
!= former_y
)
1025 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1028 if ( doMove
|| doResize
)
1030 // as the borders are drawn outside the native control, we adjust now
1032 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1033 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1034 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1036 if ( parent
&& !parent
->IsTopLevel() )
1038 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
1041 MacInvalidateBorders() ;
1043 m_cachedClippedRectValid
= false ;
1045 GetPeer()->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1047 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1049 MacInvalidateBorders() ;
1051 MacRepositionScrollBars() ;
1054 wxPoint
point(actualX
, actualY
);
1055 wxMoveEvent
event(point
, m_windowId
);
1056 event
.SetEventObject(this);
1057 HandleWindowEvent(event
) ;
1062 MacRepositionScrollBars() ;
1063 MacOnInternalSize();
1064 wxSize
size(actualWidth
, actualHeight
);
1065 wxSizeEvent
event(size
, m_windowId
);
1066 event
.SetEventObject(this);
1067 HandleWindowEvent(event
);
1072 wxSize
wxWindowMac::DoGetBestSize() const
1074 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() || IsTopLevel() )
1076 return wxWindowBase::DoGetBestSize() ;
1082 GetPeer()->GetBestRect(&r
);
1084 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
1092 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1099 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1106 // return wxWindowBase::DoGetBestSize() ;
1110 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1111 MacGetRightBorderSize();
1112 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1113 MacGetBottomBorderSize();
1114 if ( bestHeight
< 10 )
1117 return wxSize(bestWidth
, bestHeight
);
1121 // set the size of the window: if the dimensions are positive, just use them,
1122 // but if any of them is equal to -1, it means that we must find the value for
1123 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1124 // which case -1 is a valid value for x and y)
1126 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1127 // the width/height to best suit our contents, otherwise we reuse the current
1129 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1131 // get the current size and position...
1132 int currentX
, currentY
;
1133 int currentW
, currentH
;
1135 GetPosition(¤tX
, ¤tY
);
1136 GetSize(¤tW
, ¤tH
);
1138 // ... and don't do anything (avoiding flicker) if it's already ok
1139 if ( x
== currentX
&& y
== currentY
&&
1140 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1143 MacRepositionScrollBars() ; // we might have a real position shift
1145 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1147 MacOnInternalSize();
1148 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1149 event
.SetEventObject( this );
1150 HandleWindowEvent( event
);
1156 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1158 if ( x
== wxDefaultCoord
)
1160 if ( y
== wxDefaultCoord
)
1164 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1166 wxSize size
= wxDefaultSize
;
1167 if ( width
== wxDefaultCoord
)
1169 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1171 size
= DoGetBestSize();
1176 // just take the current one
1181 if ( height
== wxDefaultCoord
)
1183 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1185 if ( size
.x
== wxDefaultCoord
)
1186 size
= DoGetBestSize();
1187 // else: already called DoGetBestSize() above
1193 // just take the current one
1198 DoMoveWindow( x
, y
, width
, height
);
1201 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1203 int left
,top
,width
,height
;
1204 GetPeer()->GetContentArea( left
, top
, width
, height
);
1205 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1208 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1210 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1212 int currentclientwidth
, currentclientheight
;
1213 int currentwidth
, currentheight
;
1215 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1216 GetSize( ¤twidth
, ¤theight
) ;
1218 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1219 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1223 float wxWindowMac::GetContentScaleFactor() const
1225 return GetPeer()->GetContentScaleFactor();
1228 void wxWindowMac::SetLabel(const wxString
& title
)
1230 if ( title
== m_label
)
1235 InvalidateBestSize();
1237 if ( GetPeer() && GetPeer()->IsOk() )
1238 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1240 // do not trigger refreshes upon invisible and possible partly created objects
1241 if ( IsShownOnScreen() )
1245 wxString
wxWindowMac::GetLabel() const
1250 bool wxWindowMac::Show(bool show
)
1253 MacInvalidateBorders();
1255 if ( !wxWindowBase::Show(show
) )
1259 GetPeer()->SetVisibility( show
) ;
1262 MacInvalidateBorders();
1264 #ifdef __WXOSX_IPHONE__
1265 // only when there's no native event support
1266 if ( !IsTopLevel() )
1269 wxShowEvent
eventShow(GetId(), show
);
1270 eventShow
.SetEventObject(this);
1272 HandleWindowEvent(eventShow
);
1278 bool wxWindowMac::OSXShowWithEffect(bool show
,
1279 wxShowEffect effect
,
1282 if ( effect
== wxSHOW_EFFECT_NONE
||
1283 !GetPeer() || !GetPeer()->ShowWithEffect(show
, effect
, timeout
) )
1289 void wxWindowMac::DoEnable(bool enable
)
1291 GetPeer()->Enable( enable
) ;
1292 MacInvalidateBorders();
1296 // status change notifications
1299 void wxWindowMac::MacVisibilityChanged()
1303 void wxWindowMac::MacHiliteChanged()
1307 void wxWindowMac::MacEnabledStateChanged()
1312 // status queries on the inherited window's state
1315 bool wxWindowMac::MacIsReallyEnabled()
1317 return GetPeer()->IsEnabled() ;
1320 bool wxWindowMac::MacIsReallyHilited()
1322 #if wxOSX_USE_CARBON
1323 return GetPeer()->IsActive();
1325 return true; // TODO
1329 int wxWindowMac::GetCharHeight() const
1332 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1337 int wxWindowMac::GetCharWidth() const
1340 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1345 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1348 int *externalLeading
,
1349 const wxFont
*theFont
) const
1351 const wxFont
*fontToUse
= theFont
;
1355 tempFont
= GetFont();
1356 fontToUse
= &tempFont
;
1359 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1360 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1362 wxDouble h
, d
, e
, w
;
1363 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1367 if ( externalLeading
)
1368 *externalLeading
= (wxCoord
)(e
+0.5);
1370 *descent
= (wxCoord
)(d
+0.5);
1372 *x
= (wxCoord
)(w
+0.5);
1374 *y
= (wxCoord
)(h
+0.5);
1378 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1379 * we always intersect with the entire window, not only with the client area
1382 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1384 if ( GetPeer() == NULL
)
1387 if ( !IsShownOnScreen() )
1393 GetPeer()->SetNeedsDisplay( rect
) ;
1396 void wxWindowMac::DoFreeze()
1398 if ( GetPeer() && GetPeer()->IsOk() )
1399 GetPeer()->SetDrawingEnabled( false ) ;
1402 void wxWindowMac::DoThaw()
1404 if ( GetPeer() && GetPeer()->IsOk() )
1405 GetPeer()->SetDrawingEnabled( true ) ;
1408 wxWindow
*wxGetActiveWindow()
1410 // actually this is a windows-only concept
1414 // Coordinates relative to the window
1415 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1417 #if wxOSX_USE_COCOA_OR_CARBON
1420 DoClientToScreen(&x
, &y
);
1421 CGPoint cgpoint
= CGPointMake( x
, y
);
1422 CGWarpMouseCursorPosition( cgpoint
);
1424 // At least GTK sends a mouse moved event after WarpMouse
1425 wxMouseEvent
event(wxEVT_MOTION
);
1428 wxMouseState mState
= ::wxGetMouseState();
1430 event
.m_altDown
= mState
.AltDown();
1431 event
.m_controlDown
= mState
.ControlDown();
1432 event
.m_leftDown
= mState
.LeftIsDown();
1433 event
.m_middleDown
= mState
.MiddleIsDown();
1434 event
.m_rightDown
= mState
.RightIsDown();
1435 event
.m_metaDown
= mState
.MetaDown();
1436 event
.m_shiftDown
= mState
.ShiftDown();
1437 event
.SetId(GetId());
1438 event
.SetEventObject(this);
1439 GetEventHandler()->ProcessEvent(event
);
1443 int wxWindowMac::GetScrollPos(int orient
) const
1446 if ( orient
== wxHORIZONTAL
)
1449 return m_hScrollBar
->GetThumbPosition() ;
1454 return m_vScrollBar
->GetThumbPosition() ;
1460 // This now returns the whole range, not just the number
1461 // of positions that we can scroll.
1462 int wxWindowMac::GetScrollRange(int orient
) const
1465 if ( orient
== wxHORIZONTAL
)
1468 return m_hScrollBar
->GetRange() ;
1473 return m_vScrollBar
->GetRange() ;
1479 int wxWindowMac::GetScrollThumb(int orient
) const
1482 if ( orient
== wxHORIZONTAL
)
1485 return m_hScrollBar
->GetThumbSize() ;
1490 return m_vScrollBar
->GetThumbSize() ;
1496 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1499 if ( orient
== wxHORIZONTAL
)
1502 m_hScrollBar
->SetThumbPosition( pos
) ;
1507 m_vScrollBar
->SetThumbPosition( pos
) ;
1513 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1515 bool needVisibilityUpdate
= false;
1517 if ( m_hScrollBarAlwaysShown
!= hflag
)
1519 m_hScrollBarAlwaysShown
= hflag
;
1520 needVisibilityUpdate
= true;
1523 if ( m_vScrollBarAlwaysShown
!= vflag
)
1525 m_vScrollBarAlwaysShown
= vflag
;
1526 needVisibilityUpdate
= true;
1529 if ( needVisibilityUpdate
)
1530 DoUpdateScrollbarVisibility();
1534 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1535 // our own window origin is at leftOrigin/rightOrigin
1538 void wxWindowMac::MacPaintGrowBox()
1544 if ( MacHasScrollBarCorner() )
1547 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1548 wxASSERT( cgContext
) ;
1552 GetPeer()->GetSize( tw
, th
);
1553 GetPeer()->GetPosition( tx
, ty
);
1555 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1558 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1559 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1560 CGContextSaveGState( cgContext
);
1562 if ( m_backgroundColour
.IsOk() )
1564 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1568 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1570 CGContextFillRect( cgContext
, cgrect
);
1571 CGContextRestoreGState( cgContext
);
1575 if ( m_backgroundColour
.IsOk() )
1576 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1578 m_growBox
->SetBackgroundColour(*wxWHITE
);
1586 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1591 bool hasFocus
= GetPeer()->NeedsFocusRect() && HasFocus();
1593 // back to the surrounding frame rectangle
1596 GetPeer()->GetSize( tw
, th
);
1597 GetPeer()->GetPosition( tx
, ty
);
1599 #if wxOSX_USE_COCOA_OR_CARBON
1602 CGRect cgrect
= CGRectMake( tx
-1 , ty
-1 , tw
+2 ,
1605 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1606 wxASSERT( cgContext
) ;
1608 if ( GetPeer()->NeedsFrame() )
1610 HIThemeFrameDrawInfo info
;
1611 memset( &info
, 0 , sizeof(info
) ) ;
1615 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1616 info
.isFocused
= hasFocus
;
1618 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1620 info
.kind
= kHIThemeFrameTextFieldSquare
;
1621 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1623 else if ( HasFlag(wxSIMPLE_BORDER
) )
1625 info
.kind
= kHIThemeFrameListBox
;
1626 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1632 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1635 #endif // wxOSX_USE_COCOA_OR_CARBON
1638 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1641 if ( child
== m_hScrollBar
)
1642 m_hScrollBar
= NULL
;
1643 if ( child
== m_vScrollBar
)
1644 m_vScrollBar
= NULL
;
1645 if ( child
== m_growBox
)
1648 wxWindowBase::RemoveChild( child
) ;
1651 void wxWindowMac::DoUpdateScrollbarVisibility()
1654 bool triggerSizeEvent
= false;
1658 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1660 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1662 m_hScrollBar
->Show( showHScrollBar
);
1663 triggerSizeEvent
= true;
1669 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1671 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1673 m_vScrollBar
->Show( showVScrollBar
) ;
1674 triggerSizeEvent
= true;
1678 MacRepositionScrollBars() ;
1679 if ( triggerSizeEvent
)
1681 MacOnInternalSize();
1682 wxSizeEvent
event(GetSize(), m_windowId
);
1683 event
.SetEventObject(this);
1684 HandleWindowEvent(event
);
1689 // New function that will replace some of the above.
1690 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1691 int range
, bool refresh
)
1694 // Updating scrollbars when window is being deleted is useless and
1695 // currently results in asserts in client-to-screen coordinates conversion
1696 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1697 if ( m_isBeingDeleted
)
1700 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1701 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1702 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1703 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1705 DoUpdateScrollbarVisibility();
1709 // Does a physical scroll
1710 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1712 if ( dx
== 0 && dy
== 0 )
1715 int width
, height
;
1716 GetClientSize( &width
, &height
) ;
1719 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1721 scrollrect
.Intersect( *rect
) ;
1722 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1723 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1725 GetPeer()->ScrollRect( &scrollrect
, dx
, dy
);
1730 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1732 child
= node
->GetData();
1736 if (child
->IsTopLevel())
1739 if ( !IsClientAreaChild(child
) )
1742 child
->GetPosition( &x
, &y
);
1743 child
->GetSize( &w
, &h
);
1746 wxRect
rc( x
, y
, w
, h
);
1747 if (rect
->Intersects( rc
))
1748 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1752 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1757 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1760 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1762 wxScrollWinEvent wevent
;
1763 wevent
.SetPosition(event
.GetPosition());
1764 wevent
.SetOrientation(event
.GetOrientation());
1765 wevent
.SetEventObject(this);
1767 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1768 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1769 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1770 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1771 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1772 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1773 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1774 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1775 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1776 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1777 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1778 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1779 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1780 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1781 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1782 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1784 HandleWindowEvent(wevent
);
1789 wxWindow
*wxWindowBase::DoFindFocus()
1791 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1794 // Raise the window to the top of the Z order
1795 void wxWindowMac::Raise()
1800 // Lower the window to the bottom of the Z order
1801 void wxWindowMac::Lower()
1806 // static wxWindow *gs_lastWhich = NULL;
1808 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1810 // first trigger a set cursor event
1812 wxPoint clientorigin
= GetClientAreaOrigin() ;
1813 wxSize clientsize
= GetClientSize() ;
1815 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1817 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1818 event
.SetId(GetId());
1819 event
.SetEventObject(this);
1821 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1822 if ( processedEvtSetCursor
&& event
.HasCursor() )
1824 cursor
= event
.GetCursor() ;
1828 // the test for processedEvtSetCursor is here to prevent using m_cursor
1829 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1830 // it - this is a way to say that our cursor shouldn't be used for this
1832 if ( !processedEvtSetCursor
&& m_cursor
.IsOk() )
1835 if ( !wxIsBusy() && !GetParent() )
1836 cursor
= *wxSTANDARD_CURSOR
;
1839 if ( cursor
.IsOk() )
1840 cursor
.MacInstall() ;
1843 return cursor
.IsOk() ;
1846 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1850 return m_tooltip
->GetTip() ;
1853 return wxEmptyString
;
1856 void wxWindowMac::ClearBackground()
1862 void wxWindowMac::Update()
1864 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1869 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1871 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1875 if ( iter
->IsTopLevel() )
1877 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1881 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1886 iter
= iter
->GetParent() ;
1892 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1894 MacUpdateClippedRects() ;
1896 return m_cachedClippedClientRect
;
1899 const wxRect
& wxWindowMac::MacGetClippedRect() const
1901 MacUpdateClippedRects() ;
1903 return m_cachedClippedRect
;
1906 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1908 MacUpdateClippedRects() ;
1910 return m_cachedClippedRectWithOuterStructure
;
1913 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1915 static wxRegion emptyrgn
;
1917 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1919 MacUpdateClippedRects() ;
1920 if ( includeOuterStructures
)
1921 return m_cachedClippedRegionWithOuterStructure
;
1923 return m_cachedClippedRegion
;
1931 void wxWindowMac::MacUpdateClippedRects() const
1933 #if wxOSX_USE_CARBON
1934 if ( m_cachedClippedRectValid
)
1937 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1938 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1939 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1940 // to add focus borders everywhere
1942 Rect rIncludingOuterStructures
;
1946 GetPeer()->GetSize( tw
, th
);
1947 GetPeer()->GetPosition( tx
, ty
);
1949 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1951 r
.left
-= MacGetLeftBorderSize() ;
1952 r
.top
-= MacGetTopBorderSize() ;
1953 r
.bottom
+= MacGetBottomBorderSize() ;
1954 r
.right
+= MacGetRightBorderSize() ;
1961 rIncludingOuterStructures
= r
;
1962 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1964 wxRect cl
= GetClientRect() ;
1965 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1969 const wxWindow
* child
= (wxWindow
*) this ;
1970 const wxWindow
* parent
= NULL
;
1972 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1974 if ( parent
->MacIsChildOfClientArea(child
) )
1976 size
= parent
->GetClientSize() ;
1977 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1983 // this will be true for scrollbars, toolbars etc.
1984 size
= parent
->GetSize() ;
1985 y
= parent
->MacGetTopBorderSize() ;
1986 x
= parent
->MacGetLeftBorderSize() ;
1987 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1988 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1991 parent
->MacWindowToRootWindow( &x
, &y
) ;
1992 MacRootWindowToWindow( &x
, &y
) ;
1994 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1996 // the wxwindow and client rects will always be clipped
1997 SectRect( &r
, &rparent
, &r
) ;
1998 SectRect( &rClient
, &rparent
, &rClient
) ;
2000 // the structure only at 'hard' borders
2001 if ( parent
->MacClipChildren() ||
2002 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2004 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2010 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2011 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2012 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2013 m_cachedClippedRectWithOuterStructure
= wxRect(
2014 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2015 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2016 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2018 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2019 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2020 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2022 m_cachedClippedRectValid
= true ;
2027 This function must not change the updatergn !
2029 bool wxWindowMac::MacDoRedraw( long time
)
2031 bool handled
= false ;
2033 wxRegion formerUpdateRgn
= m_updateRegion
;
2034 wxRegion clientUpdateRgn
= formerUpdateRgn
;
2036 const wxRect clientRect
= GetClientRect();
2038 clientUpdateRgn
.Intersect(clientRect
);
2040 // first send an erase event to the entire update area
2041 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
2044 case wxBG_STYLE_ERASE
:
2045 case wxBG_STYLE_SYSTEM
:
2046 case wxBG_STYLE_COLOUR
:
2048 // for the toplevel window this really is the entire area for
2049 // all the others only their client area, otherwise they might
2050 // be drawing with full alpha and eg put blue into the grow-box
2051 // area of a scrolled window (scroll sample)
2052 wxWindowDC
dc(this);
2054 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
2056 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
2058 if ( bgStyle
== wxBG_STYLE_ERASE
)
2060 wxEraseEvent
eevent( GetId(), &dc
);
2061 eevent
.SetEventObject( this );
2062 if ( ProcessWindowEvent( eevent
) )
2068 dc
.SetBackground(GetBackgroundColour());
2074 case wxBG_STYLE_PAINT
:
2075 case wxBG_STYLE_TRANSPARENT
:
2076 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2077 // entire window client area
2081 wxFAIL_MSG( "unsupported background style" );
2084 // as this is a full window, shouldn't be necessary anymore
2085 // MacPaintGrowBox();
2087 // calculate a client-origin version of the update rgn and set
2088 // m_updateRegion to that
2089 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
2090 m_updateRegion
= clientUpdateRgn
;
2092 if ( !m_updateRegion
.Empty() )
2094 // paint the window itself
2096 wxPaintEvent
event(GetId());
2097 event
.SetTimestamp(time
);
2098 event
.SetEventObject(this);
2099 handled
= HandleWindowEvent(event
);
2102 m_updateRegion
= formerUpdateRgn
;
2104 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2106 top
->WindowWasPainted() ;
2111 void wxWindowMac::MacPaintChildrenBorders()
2113 // now we cannot rely on having its borders drawn by a window itself, as it does not
2114 // get the updateRgn wide enough to always do so, so we do it from the parent
2115 // this would also be the place to draw any custom backgrounds for native controls
2116 // in Composited windowing
2117 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2121 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2123 child
= node
->GetData();
2127 if (child
== m_vScrollBar
)
2129 if (child
== m_hScrollBar
)
2131 if (child
== m_growBox
)
2134 if (child
->IsTopLevel())
2136 if (!child
->IsShown())
2139 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2141 child
->GetPosition( &x
, &y
);
2142 child
->GetSize( &w
, &h
);
2144 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2146 // paint custom borders
2147 wxNcPaintEvent
eventNc( child
->GetId() );
2148 eventNc
.SetEventObject( child
);
2149 if ( !child
->HandleWindowEvent( eventNc
) )
2151 child
->MacPaintBorders(0, 0) ;
2158 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2160 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2161 return tlw
? tlw
->GetWXWindow() : NULL
;
2164 bool wxWindowMac::MacHasScrollBarCorner() const
2167 /* Returns whether the scroll bars in a wxScrolledWindow should be
2168 * shortened. Scroll bars should be shortened if either:
2170 * - both scroll bars are visible, or
2172 * - there is a resize box in the parent frame's corner and this
2173 * window shares the bottom and right edge with the parent
2177 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2180 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2181 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2183 // Both scroll bars visible
2188 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2190 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2192 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2195 // starting from 10.7 there are no resize indicators anymore
2196 if ( (frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
) && UMAGetSystemVersion() < 0x1070)
2198 // Parent frame has resize handle
2199 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2201 // Note: allow for some wiggle room here as wxMac's
2202 // window rect calculations seem to be imprecise
2203 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2204 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2206 // Parent frame has resize handle and shares
2207 // right bottom corner
2212 // Parent frame has resize handle but doesn't
2213 // share right bottom corner
2219 // Parent frame doesn't have resize handle
2225 // No parent frame found
2233 void wxWindowMac::MacCreateScrollBars( long style
)
2236 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2238 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2240 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2241 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2243 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2246 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2248 GetClientSize( &width
, &height
) ;
2250 wxPoint
vPoint(width
- scrlsize
, 0) ;
2251 wxSize
vSize(scrlsize
, height
- adjust
) ;
2252 wxPoint
hPoint(0, height
- scrlsize
) ;
2253 wxSize
hSize(width
- adjust
, scrlsize
) ;
2255 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2256 if ( style
& wxVSCROLL
)
2258 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2259 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2262 if ( style
& wxHSCROLL
)
2264 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2265 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2268 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2269 wxSize
gSize(scrlsize
, scrlsize
);
2270 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2273 // because the create does not take into account the client area origin
2274 // we might have a real position shift
2275 MacRepositionScrollBars() ;
2279 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2281 bool result
= ((child
== NULL
)
2283 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2290 void wxWindowMac::MacRepositionScrollBars()
2293 if ( !m_hScrollBar
&& !m_vScrollBar
)
2296 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2297 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2299 // get real client area
2301 GetSize( &width
, &height
);
2303 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2304 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2306 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2307 wxSize
vSize( scrlsize
, height
- adjust
) ;
2308 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2309 wxSize
hSize( width
- adjust
, scrlsize
) ;
2312 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2314 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2317 if ( MacHasScrollBarCorner() )
2319 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2320 if ( !m_growBox
->IsShown() )
2325 if ( m_growBox
->IsShown() )
2332 bool wxWindowMac::AcceptsFocus() const
2334 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() )
2335 return wxWindowBase::AcceptsFocus();
2337 return GetPeer()->CanFocus();
2340 void wxWindowMac::MacSuperChangedPosition()
2342 // only window-absolute structures have to be moved i.e. controls
2344 m_cachedClippedRectValid
= false ;
2347 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2350 child
= node
->GetData();
2351 child
->MacSuperChangedPosition() ;
2353 node
= node
->GetNext();
2357 void wxWindowMac::MacTopLevelWindowChangedPosition()
2359 // only screen-absolute structures have to be moved i.e. glcanvas
2362 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2365 child
= node
->GetData();
2366 child
->MacTopLevelWindowChangedPosition() ;
2368 node
= node
->GetNext();
2372 long wxWindowMac::MacGetWXBorderSize() const
2379 if ( GetPeer() && GetPeer()->NeedsFrame() )
2381 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2383 #if wxOSX_USE_COCOA_OR_CARBON
2384 // this metric is only the 'outset' outside the simple frame rect
2385 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2391 else if (HasFlag(wxSIMPLE_BORDER
))
2393 #if wxOSX_USE_COCOA_OR_CARBON
2394 // this metric is only the 'outset' outside the simple frame rect
2395 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2406 long wxWindowMac::MacGetLeftBorderSize() const
2408 // the wx borders are all symmetric in mac themes
2409 long border
= MacGetWXBorderSize() ;
2413 int left
, top
, right
, bottom
;
2414 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2422 long wxWindowMac::MacGetRightBorderSize() const
2424 // the wx borders are all symmetric in mac themes
2425 long border
= MacGetWXBorderSize() ;
2429 int left
, top
, right
, bottom
;
2430 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2437 long wxWindowMac::MacGetTopBorderSize() const
2439 // the wx borders are all symmetric in mac themes
2440 long border
= MacGetWXBorderSize() ;
2444 int left
, top
, right
, bottom
;
2445 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2452 long wxWindowMac::MacGetBottomBorderSize() const
2454 // the wx borders are all symmetric in mac themes
2455 long border
= MacGetWXBorderSize() ;
2459 int left
, top
, right
, bottom
;
2460 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2467 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2469 return style
& ~wxBORDER_MASK
;
2472 // Find the wxWindowMac at the current mouse position, returning the mouse
2474 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2476 pt
= wxGetMousePosition();
2477 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2479 return (wxWindow
*) found
;
2482 // Get the current mouse position.
2483 wxPoint
wxGetMousePosition()
2487 wxGetMousePosition( &x
, &y
);
2489 return wxPoint(x
, y
);
2492 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2494 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2496 // copied from wxGTK : CS
2497 // VZ: shouldn't we move this to base class then?
2499 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2502 // (a) it's a command event and so is propagated to the parent
2503 // (b) under MSW it can be generated from kbd too
2504 // (c) it uses screen coords (because of (a))
2505 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2507 this->ClientToScreen(event
.GetPosition()));
2508 evtCtx
.SetEventObject(this);
2509 if ( ! HandleWindowEvent(evtCtx
) )
2518 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2522 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2526 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2527 Rect bounds
= { static_cast<short>(y
), static_cast<short>(x
), static_cast<short>(y
+ h
), static_cast<short>(x
+ w
) };
2532 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2537 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2539 #if wxOSX_USE_COCOA_OR_CARBON
2540 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2543 return eventNotHandledErr
;
2549 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2551 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2552 if ( !wxWindowBase::Reparent(newParent
) )
2555 GetPeer()->RemoveFromParent();
2556 GetPeer()->Embed( GetParent()->GetPeer() );
2562 bool wxWindowMac::SetTransparent(wxByte alpha
)
2564 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2566 if ( alpha
!= m_macAlpha
)
2568 m_macAlpha
= alpha
;
2575 bool wxWindowMac::CanSetTransparent()
2580 wxByte
wxWindowMac::GetTransparent() const
2585 bool wxWindowMac::IsShownOnScreen() const
2587 if ( GetPeer() && GetPeer()->IsOk() )
2589 bool peerVis
= GetPeer()->IsVisible();
2590 bool wxVis
= wxWindowBase::IsShownOnScreen();
2591 if( peerVis
!= wxVis
)
2593 // CS : put a breakpoint here to investigate differences
2594 // between native an wx visibilities
2595 // the only place where I've encountered them until now
2596 // are the hiding/showing sequences where the vis-changed event is
2597 // first sent to the innermost control, while wx does things
2598 // from the outmost control
2599 wxVis
= wxWindowBase::IsShownOnScreen();
2603 return GetPeer()->IsVisible();
2605 return wxWindowBase::IsShownOnScreen();
2608 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2611 wxHotKeyHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
2613 void* WXUNUSED(userData
))
2615 EventHotKeyID hotKeyId
;
2617 GetEventParameter( event
, kEventParamDirectObject
, typeEventHotKeyID
, NULL
, sizeof(hotKeyId
), NULL
, &hotKeyId
);
2619 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2621 if ( s_hotkeys
[i
].keyId
== static_cast<int>(hotKeyId
.id
) )
2623 unsigned char charCode
;
2626 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
2628 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
2629 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
2630 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
2632 UInt32 keymessage
= (keyCode
<< 8) + charCode
;
2634 wxKeyEvent
wxevent(wxEVT_HOTKEY
);
2635 wxevent
.SetId(hotKeyId
.id
);
2636 wxTheApp
->MacCreateKeyEvent( wxevent
, s_hotkeys
[i
].window
, keymessage
,
2637 modifiers
, when
, 0 ) ;
2639 s_hotkeys
[i
].window
->HandleWindowEvent(wxevent
);
2646 bool wxWindowMac::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
2648 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2650 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2652 wxLogLastError(wxT("hotkeyId already registered"));
2658 static bool installed
= false;
2661 EventTypeSpec eventType
;
2662 eventType
.eventClass
=kEventClassKeyboard
;
2663 eventType
.eventKind
=kEventHotKeyPressed
;
2665 InstallApplicationEventHandler(&wxHotKeyHandler
, 1, &eventType
, NULL
, NULL
);
2669 UInt32 mac_modifiers
=0;
2670 if ( modifiers
& wxMOD_ALT
)
2671 mac_modifiers
|= optionKey
;
2672 if ( modifiers
& wxMOD_SHIFT
)
2673 mac_modifiers
|= shiftKey
;
2674 if ( modifiers
& wxMOD_RAW_CONTROL
)
2675 mac_modifiers
|= controlKey
;
2676 if ( modifiers
& wxMOD_CONTROL
)
2677 mac_modifiers
|= cmdKey
;
2679 EventHotKeyRef hotKeyRef
;
2680 EventHotKeyID hotKeyIDmac
;
2682 hotKeyIDmac
.signature
= 'WXMC';
2683 hotKeyIDmac
.id
= hotkeyId
;
2685 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode
)keycode
), mac_modifiers
, hotKeyIDmac
,
2686 GetApplicationEventTarget(), 0, &hotKeyRef
) != noErr
)
2688 wxLogLastError(wxT("RegisterHotKey"));
2699 s_hotkeys
.push_back(v
);
2705 bool wxWindowMac::UnregisterHotKey(int hotkeyId
)
2707 for ( int i
= ((int)s_hotkeys
.size())-1; i
>=0; -- i
)
2709 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2711 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
2712 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
2713 if ( UnregisterEventHotKey(ref
) != noErr
)
2715 wxLogLastError(wxT("UnregisterHotKey"));
2727 #endif // wxUSE_HOTKEY
2729 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2731 bool handled
= false;
2733 // moved the ordinary key event sending AFTER the accel evaluation
2736 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2738 wxWindow
*ancestor
= this;
2741 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2744 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2746 wxCommandEvent
command_event( wxEVT_MENU
, command
);
2747 handled
= handler
->ProcessEvent( command_event
);
2751 // accelerators can also be used with buttons, try them too
2752 command_event
.SetEventType(wxEVT_BUTTON
);
2753 handled
= handler
->ProcessEvent( command_event
);
2759 if (ancestor
->IsTopLevel())
2762 ancestor
= ancestor
->GetParent();
2765 #endif // wxUSE_ACCEL
2769 handled
= HandleWindowEvent( event
) ;
2770 if ( handled
&& event
.GetSkipped() )
2781 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2783 static MacControlMap wxWinMacControlList
;
2785 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2787 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2789 return impl
->GetWXPeer();
2794 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2796 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2798 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2801 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2803 // adding NULL ControlRef is (first) surely a result of an error and
2804 // (secondly) breaks native event processing
2805 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2807 wxWinMacControlList
[inControl
] = impl
;
2810 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2812 // iterate over all the elements in the class
2813 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2814 // we should go on...
2820 MacControlMap::iterator it
;
2821 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2823 if ( it
->second
== impl
)
2825 wxWinMacControlList
.erase(it
);
2833 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2835 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2838 m_isRootControl
= isRootControl
;
2839 m_isUserPane
= isUserPane
;
2841 m_shouldSendEvents
= true;
2844 wxWidgetImpl::wxWidgetImpl()
2849 wxWidgetImpl::~wxWidgetImpl()
2853 void wxWidgetImpl::Init()
2855 m_isRootControl
= false;
2857 m_needsFocusRect
= false;
2858 m_needsFrame
= true;
2861 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2863 m_needsFocusRect
= needs
;
2866 bool wxWidgetImpl::NeedsFocusRect() const
2868 return m_needsFocusRect
;
2871 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2873 m_needsFrame
= needs
;
2876 bool wxWidgetImpl::NeedsFrame() const
2878 return m_needsFrame
;
2881 void wxWidgetImpl::SetDrawingEnabled(bool WXUNUSED(enabled
))