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 void wxWindowMac::DontCreatePeer()
306 m_peer
= kOSXNoWidgetImpl
;
309 void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl
* wrapper
)
311 wxOSXWidgetImpl
* inner
= GetPeer();
312 wxASSERT_MSG( inner
!= NULL
&& inner
->IsOk(), "missing or incomplete inner peer" );
313 wxASSERT_MSG( wrapper
!= NULL
&& wrapper
->IsOk(), "missing or incomplete wrapper" );
315 if ( !(inner
!= NULL
&& inner
->IsOk() && wrapper
!= NULL
&& wrapper
->IsOk()) )
318 inner
->RemoveFromParent();
319 wrapper
->InstallEventHandler();
320 wrapper
->Embed(inner
);
324 void wxWindowMac::SetPeer(wxOSXWidgetImpl
* peer
)
328 if ( !GetPeer()->IsRootControl() )
329 GetPeer()->RemoveFromParent();
335 if ( GetPeer() && !GetPeer()->IsRootControl())
337 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
339 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
340 GetParent()->AddChild( this );
342 GetPeer()->InstallEventHandler();
343 GetPeer()->Embed(GetParent()->GetPeer());
345 GetParent()->MacChildAdded() ;
347 // adjust font, controlsize etc
348 DoSetWindowVariant( m_windowVariant
) ;
350 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
352 // for controls we want to use best size for wxDefaultSize params )
353 if ( !GetPeer()->IsUserPane() )
354 SetInitialSize(GetMinSize());
356 SetCursor( *wxSTANDARD_CURSOR
) ;
360 #if WXWIN_COMPATIBILITY_2_8
362 bool wxWindowMac::MacIsUserPane()
364 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
369 bool wxWindowMac::MacIsUserPane() const
371 return GetPeer() == NULL
|| GetPeer()->IsUserPane();
374 // ---------------------------------------------------------------------------
375 // Utility Routines to move between different coordinate systems
376 // ---------------------------------------------------------------------------
379 * Right now we have the following setup :
380 * a border that is not part of the native control is always outside the
381 * control's border (otherwise we loose all native intelligence, future ways
382 * may be to have a second embedding control responsible for drawing borders
383 * and backgrounds eventually)
384 * so all this border calculations have to be taken into account when calling
385 * native methods or getting native oriented data
386 * so we have three coordinate systems here
387 * wx client coordinates
388 * wx window coordinates (including window frames)
396 bool wxWindowMac::Create(wxWindowMac
*parent
,
401 const wxString
& name
)
403 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
405 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
408 m_windowVariant
= parent
->GetWindowVariant() ;
410 if ( m_peer
!= kOSXNoWidgetImpl
)
412 SetPeer(wxWidgetImpl::CreateUserPane( this, parent
, id
, pos
, size
, style
, GetExtraStyle() ));
413 MacPostControlCreate(pos
, size
) ;
416 #ifndef __WXUNIVERSAL__
417 // Don't give scrollbars to wxControls unless they ask for them
418 if ( (! IsKindOf(CLASSINFO(wxControl
))
420 && ! IsKindOf(CLASSINFO(wxStatusBar
))
423 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
425 MacCreateScrollBars( style
) ;
429 wxWindowCreateEvent
event((wxWindow
*)this);
430 GetEventHandler()->AddPendingEvent(event
);
435 void wxWindowMac::MacChildAdded()
439 m_vScrollBar
->Raise() ;
441 m_hScrollBar
->Raise() ;
447 void wxWindowMac::MacPostControlCreate(const wxPoint
& WXUNUSED(pos
),
448 const wxSize
& WXUNUSED(size
))
450 // todo remove if refactoring works correctly
452 wxASSERT_MSG( GetPeer() != NULL
&& GetPeer()->IsOk() , wxT("No valid mac control") ) ;
454 if (!GetParent()->GetChildren().Find((wxWindow
*)this))
455 GetParent()->AddChild( this );
457 GetPeer()->InstallEventHandler();
458 GetPeer()->Embed(GetParent()->GetPeer());
460 GetParent()->MacChildAdded() ;
462 // adjust font, controlsize etc
463 DoSetWindowVariant( m_windowVariant
) ;
465 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
467 // for controls we want to use best size for wxDefaultSize params )
468 if ( !GetPeer()->IsUserPane() )
469 SetInitialSize(size
);
471 SetCursor( *wxSTANDARD_CURSOR
) ;
475 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
477 // Don't assert, in case we set the window variant before
478 // the window is created
479 // wxASSERT( GetPeer()->IsOk() ) ;
481 m_windowVariant
= variant
;
483 if (GetPeer() == NULL
|| !GetPeer()->IsOk())
486 GetPeer()->SetControlSize( variant
);
490 case wxWINDOW_VARIANT_NORMAL
:
491 static wxFont
sysNormal(wxOSX_SYSTEM_FONT_NORMAL
);
495 case wxWINDOW_VARIANT_SMALL
:
496 static wxFont
sysSmall(wxOSX_SYSTEM_FONT_SMALL
);
500 case wxWINDOW_VARIANT_MINI
:
501 static wxFont
sysMini(wxOSX_SYSTEM_FONT_MINI
);
505 case wxWINDOW_VARIANT_LARGE
:
506 static wxFont
sysLarge(wxOSX_SYSTEM_FONT_NORMAL
);
511 wxFAIL_MSG(wxT("unexpected window variant"));
516 void wxWindowMac::MacUpdateControlFont()
519 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
521 // do not trigger refreshes upon invisible and possible partly created objects
522 if ( IsShownOnScreen() )
526 bool wxWindowMac::SetFont(const wxFont
& font
)
528 bool retval
= wxWindowBase::SetFont( font
);
530 MacUpdateControlFont() ;
535 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
537 bool retval
= wxWindowBase::SetForegroundColour( col
);
540 MacUpdateControlFont();
545 bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style
)
547 if ( !wxWindowBase::SetBackgroundStyle(style
) )
551 GetPeer()->SetBackgroundStyle(style
);
555 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
559 if ( m_backgroundColour
.IsOk() )
560 m_growBox
->SetBackgroundColour(m_backgroundColour
);
562 m_growBox
->SetBackgroundColour(*wxWHITE
);
565 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
569 GetPeer()->SetBackgroundColour( col
) ;
574 static bool wxIsWindowOrParentDisabled(wxWindow
* w
)
576 while (w
&& !w
->IsTopLevel())
585 void wxWindowMac::SetFocus()
587 if ( !AcceptsFocus() )
590 if (wxIsWindowOrParentDisabled((wxWindow
*) this))
593 wxWindow
* former
= FindFocus() ;
594 if ( former
== this )
597 GetPeer()->SetFocus() ;
600 void wxWindowMac::DoCaptureMouse()
602 wxApp::s_captureWindow
= (wxWindow
*) this ;
603 GetPeer()->CaptureMouse() ;
606 wxWindow
* wxWindowBase::GetCapture()
608 return wxApp::s_captureWindow
;
611 void wxWindowMac::DoReleaseMouse()
613 wxApp::s_captureWindow
= NULL
;
615 GetPeer()->ReleaseMouse() ;
618 #if wxUSE_DRAG_AND_DROP
620 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
624 m_dropTarget
= pDropTarget
;
626 GetPeer()->SetDropTarget(m_dropTarget
) ;
631 // Old-style File Manager Drag & Drop
632 void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept
))
637 // From a wx position / size calculate the appropriate size of the native control
639 bool wxWindowMac::MacGetBoundsForControl(
643 int& w
, int& h
, bool adjustOrigin
) const
645 // the desired size, minus the border pixels gives the correct size of the control
649 w
= WidthDefault( size
.x
);
650 h
= HeightDefault( size
.y
);
652 x
+= MacGetLeftBorderSize() ;
653 y
+= MacGetTopBorderSize() ;
654 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
655 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
658 AdjustForParentClientOrigin( x
, y
) ;
660 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
661 if ( GetParent() && !GetParent()->IsTopLevel() )
663 x
-= GetParent()->MacGetLeftBorderSize() ;
664 y
-= GetParent()->MacGetTopBorderSize() ;
670 // Get window size (not client size)
671 void wxWindowMac::DoGetSize(int *x
, int *y
) const
674 GetPeer()->GetSize( width
, height
);
677 *x
= width
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
679 *y
= height
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
682 // get the position of the bounds of this window in client coordinates of its parent
683 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
687 GetPeer()->GetPosition( x1
, y1
) ;
689 // get the wx window position from the native one
690 x1
-= MacGetLeftBorderSize() ;
691 y1
-= MacGetTopBorderSize() ;
695 wxWindow
*parent
= GetParent();
698 // we must first adjust it to be in window coordinates of the parent,
699 // as otherwise it gets lost by the ClientAreaOrigin fix
700 x1
+= parent
->MacGetLeftBorderSize() ;
701 y1
+= parent
->MacGetTopBorderSize() ;
703 // and now to client coordinates
704 wxPoint
pt(parent
->GetClientAreaOrigin());
716 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
718 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
719 wxCHECK_RET( tlw
, wxT("TopLevel Window missing") ) ;
720 tlw
->GetNonOwnedPeer()->ScreenToWindow( x
, y
);
721 MacRootWindowToWindow( x
, y
) ;
723 wxPoint origin
= GetClientAreaOrigin() ;
730 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
732 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow() ;
733 wxCHECK_RET( tlw
, wxT("TopLevel window missing") ) ;
735 wxPoint origin
= GetClientAreaOrigin() ;
741 MacWindowToRootWindow( x
, y
) ;
742 tlw
->GetNonOwnedPeer()->WindowToScreen( x
, y
);
745 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
747 wxPoint origin
= GetClientAreaOrigin() ;
753 MacWindowToRootWindow( x
, y
) ;
756 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
767 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
770 pt
.x
-= MacGetLeftBorderSize() ;
771 pt
.y
-= MacGetTopBorderSize() ;
772 wxWidgetImpl::Convert( &pt
, GetPeer() , top
->GetPeer() ) ;
782 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
793 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
796 wxWidgetImpl::Convert( &pt
, top
->GetPeer() , GetPeer() ) ;
797 pt
.x
+= MacGetLeftBorderSize() ;
798 pt
.y
+= MacGetTopBorderSize() ;
808 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
810 wxSize sizeTotal
= size
;
812 int innerwidth
, innerheight
;
814 int outerwidth
, outerheight
;
816 GetPeer()->GetContentArea( left
, top
, innerwidth
, innerheight
);
817 GetPeer()->GetSize( outerwidth
, outerheight
);
819 sizeTotal
.x
+= outerwidth
-innerwidth
;
820 sizeTotal
.y
+= outerheight
-innerheight
;
822 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
823 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
828 // Get size *available for subwindows* i.e. excluding menu bar etc.
829 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
835 GetPeer()->GetContentArea( left
, top
, ww
, hh
);
837 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
838 hh
-= m_hScrollBar
->GetSize().y
;
840 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
841 ww
-= m_vScrollBar
->GetSize().x
;
850 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
852 if (m_cursor
.IsSameAs(cursor
))
857 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
862 if ( ! wxWindowBase::SetCursor( cursor
) )
866 wxASSERT_MSG( m_cursor
.IsOk(),
867 wxT("cursor must be valid after call to the base version"));
869 if ( GetPeer() != NULL
)
870 GetPeer()->SetCursor( m_cursor
);
876 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
878 #ifndef __WXUNIVERSAL__
881 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
883 wxPoint mouse
= wxGetMousePosition();
889 ClientToScreen( &x
, &y
) ;
891 menu
->GetPeer()->PopUp(this, x
, y
);
894 // actually this shouldn't be called, because universal is having its own implementation
900 // ----------------------------------------------------------------------------
902 // ----------------------------------------------------------------------------
906 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
908 wxWindowBase::DoSetToolTip(tooltip
);
911 m_tooltip
->SetWindow(this);
914 GetPeer()->SetToolTip(tooltip
);
919 void wxWindowMac::MacInvalidateBorders()
921 if ( GetPeer() == NULL
)
924 bool vis
= IsShownOnScreen() ;
928 int outerBorder
= MacGetLeftBorderSize() ;
930 if ( GetPeer()->NeedsFocusRect() )
933 if ( outerBorder
== 0 )
936 // now we know that we have something to do at all
940 GetPeer()->GetSize( tw
, th
);
941 GetPeer()->GetPosition( tx
, ty
);
943 wxRect
leftupdate( tx
-outerBorder
,ty
,outerBorder
,th
);
944 wxRect
rightupdate( tx
+tw
, ty
, outerBorder
, th
);
945 wxRect
topupdate( tx
-outerBorder
, ty
-outerBorder
, tw
+ 2 * outerBorder
, outerBorder
);
946 wxRect
bottomupdate( tx
-outerBorder
, ty
+ th
, tw
+ 2 * outerBorder
, outerBorder
);
949 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate
);
950 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate
);
951 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate
);
952 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate
);
956 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
958 // this is never called for a toplevel window, so we know we have a parent
959 int former_x
, former_y
, former_w
, former_h
;
961 // Get true coordinates of former position
962 DoGetPosition( &former_x
, &former_y
) ;
963 DoGetSize( &former_w
, &former_h
) ;
965 wxWindow
*parent
= GetParent();
968 wxPoint
pt(parent
->GetClientAreaOrigin());
973 int actualWidth
= width
;
974 int actualHeight
= height
;
979 // min and max sizes are only for sizers, not for explicit size setting
980 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
981 actualWidth
= m_minWidth
;
982 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
983 actualHeight
= m_minHeight
;
984 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
985 actualWidth
= m_maxWidth
;
986 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
987 actualHeight
= m_maxHeight
;
990 bool doMove
= false, doResize
= false ;
992 if ( actualX
!= former_x
|| actualY
!= former_y
)
995 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
998 if ( doMove
|| doResize
)
1000 // as the borders are drawn outside the native control, we adjust now
1002 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1003 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1004 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1006 if ( parent
&& !parent
->IsTopLevel() )
1008 bounds
.Offset( -parent
->MacGetLeftBorderSize(), -parent
->MacGetTopBorderSize() );
1011 MacInvalidateBorders() ;
1013 m_cachedClippedRectValid
= false ;
1015 GetPeer()->Move( bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1017 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1019 MacInvalidateBorders() ;
1021 MacRepositionScrollBars() ;
1024 wxPoint
point(actualX
, actualY
);
1025 wxMoveEvent
event(point
, m_windowId
);
1026 event
.SetEventObject(this);
1027 HandleWindowEvent(event
) ;
1032 MacRepositionScrollBars() ;
1033 MacOnInternalSize();
1034 wxSize
size(actualWidth
, actualHeight
);
1035 wxSizeEvent
event(size
, m_windowId
);
1036 event
.SetEventObject(this);
1037 HandleWindowEvent(event
);
1042 wxSize
wxWindowMac::DoGetBestSize() const
1044 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() || IsTopLevel() )
1046 return wxWindowBase::DoGetBestSize() ;
1052 GetPeer()->GetBestRect(&r
);
1054 if ( r
.GetWidth() == 0 && r
.GetHeight() == 0 )
1062 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1069 if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1076 // return wxWindowBase::DoGetBestSize() ;
1080 int bestWidth
= r
.width
+ MacGetLeftBorderSize() +
1081 MacGetRightBorderSize();
1082 int bestHeight
= r
.height
+ MacGetTopBorderSize() +
1083 MacGetBottomBorderSize();
1084 if ( bestHeight
< 10 )
1087 return wxSize(bestWidth
, bestHeight
);
1091 // set the size of the window: if the dimensions are positive, just use them,
1092 // but if any of them is equal to -1, it means that we must find the value for
1093 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1094 // which case -1 is a valid value for x and y)
1096 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1097 // the width/height to best suit our contents, otherwise we reuse the current
1099 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1101 // get the current size and position...
1102 int currentX
, currentY
;
1103 int currentW
, currentH
;
1105 GetPosition(¤tX
, ¤tY
);
1106 GetSize(¤tW
, ¤tH
);
1108 // ... and don't do anything (avoiding flicker) if it's already ok
1109 if ( x
== currentX
&& y
== currentY
&&
1110 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1113 MacRepositionScrollBars() ; // we might have a real position shift
1115 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1117 MacOnInternalSize();
1118 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1119 event
.SetEventObject( this );
1120 HandleWindowEvent( event
);
1126 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1128 if ( x
== wxDefaultCoord
)
1130 if ( y
== wxDefaultCoord
)
1134 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1136 wxSize size
= wxDefaultSize
;
1137 if ( width
== wxDefaultCoord
)
1139 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1141 size
= DoGetBestSize();
1146 // just take the current one
1151 if ( height
== wxDefaultCoord
)
1153 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1155 if ( size
.x
== wxDefaultCoord
)
1156 size
= DoGetBestSize();
1157 // else: already called DoGetBestSize() above
1163 // just take the current one
1168 DoMoveWindow( x
, y
, width
, height
);
1171 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1173 int left
,top
,width
,height
;
1174 GetPeer()->GetContentArea( left
, top
, width
, height
);
1175 return wxPoint( left
+ MacGetLeftBorderSize() , top
+ MacGetTopBorderSize() );
1178 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1180 if ( clientwidth
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1182 int currentclientwidth
, currentclientheight
;
1183 int currentwidth
, currentheight
;
1185 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1186 GetSize( ¤twidth
, ¤theight
) ;
1188 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1189 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1193 float wxWindowMac::GetContentScaleFactor() const
1195 return GetPeer()->GetContentScaleFactor();
1198 void wxWindowMac::SetLabel(const wxString
& title
)
1200 if ( title
== m_label
)
1205 InvalidateBestSize();
1207 if ( GetPeer() && GetPeer()->IsOk() )
1208 GetPeer()->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
), GetFont().GetEncoding() ) ;
1210 // do not trigger refreshes upon invisible and possible partly created objects
1211 if ( IsShownOnScreen() )
1215 wxString
wxWindowMac::GetLabel() const
1220 bool wxWindowMac::Show(bool show
)
1223 MacInvalidateBorders();
1225 if ( !wxWindowBase::Show(show
) )
1229 GetPeer()->SetVisibility( show
) ;
1232 MacInvalidateBorders();
1234 #ifdef __WXOSX_IPHONE__
1235 // only when there's no native event support
1236 if ( !IsTopLevel() )
1239 wxShowEvent
eventShow(GetId(), show
);
1240 eventShow
.SetEventObject(this);
1242 HandleWindowEvent(eventShow
);
1248 bool wxWindowMac::OSXShowWithEffect(bool show
,
1249 wxShowEffect effect
,
1252 if ( effect
== wxSHOW_EFFECT_NONE
||
1253 !GetPeer() || !GetPeer()->ShowWithEffect(show
, effect
, timeout
) )
1259 void wxWindowMac::DoEnable(bool enable
)
1261 GetPeer()->Enable( enable
) ;
1262 MacInvalidateBorders();
1266 // status change notifications
1269 void wxWindowMac::MacVisibilityChanged()
1273 void wxWindowMac::MacHiliteChanged()
1277 void wxWindowMac::MacEnabledStateChanged()
1279 OnEnabled( GetPeer()->IsEnabled() );
1283 // status queries on the inherited window's state
1286 bool wxWindowMac::MacIsReallyEnabled()
1288 return GetPeer()->IsEnabled() ;
1291 bool wxWindowMac::MacIsReallyHilited()
1293 #if wxOSX_USE_CARBON
1294 return GetPeer()->IsActive();
1296 return true; // TODO
1300 int wxWindowMac::GetCharHeight() const
1303 GetTextExtent( wxT("g") , NULL
, &height
, NULL
, NULL
, NULL
);
1308 int wxWindowMac::GetCharWidth() const
1311 GetTextExtent( wxT("g") , &width
, NULL
, NULL
, NULL
, NULL
);
1316 void wxWindowMac::DoGetTextExtent(const wxString
& str
,
1319 int *externalLeading
,
1320 const wxFont
*theFont
) const
1322 const wxFont
*fontToUse
= theFont
;
1326 tempFont
= GetFont();
1327 fontToUse
= &tempFont
;
1330 wxGraphicsContext
* ctx
= wxGraphicsContext::Create();
1331 ctx
->SetFont( *fontToUse
, *wxBLACK
);
1333 wxDouble h
, d
, e
, w
;
1334 ctx
->GetTextExtent( str
, &w
, &h
, &d
, &e
);
1338 if ( externalLeading
)
1339 *externalLeading
= (wxCoord
)(e
+0.5);
1341 *descent
= (wxCoord
)(d
+0.5);
1343 *x
= (wxCoord
)(w
+0.5);
1345 *y
= (wxCoord
)(h
+0.5);
1349 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1350 * we always intersect with the entire window, not only with the client area
1353 void wxWindowMac::Refresh(bool WXUNUSED(eraseBack
), const wxRect
*rect
)
1355 if ( GetPeer() == NULL
)
1358 if ( !IsShownOnScreen() )
1361 GetPeer()->SetNeedsDisplay( rect
) ;
1364 void wxWindowMac::DoFreeze()
1366 #if wxOSX_USE_CARBON
1367 if ( GetPeer() && GetPeer()->IsOk() )
1368 GetPeer()->SetDrawingEnabled( false ) ;
1372 void wxWindowMac::DoThaw()
1374 #if wxOSX_USE_CARBON
1375 if ( GetPeer() && GetPeer()->IsOk() )
1377 GetPeer()->SetDrawingEnabled( true ) ;
1378 GetPeer()->InvalidateWithChildren() ;
1383 wxWindow
*wxGetActiveWindow()
1385 // actually this is a windows-only concept
1389 // Coordinates relative to the window
1390 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
1392 #if wxOSX_USE_COCOA_OR_CARBON
1395 DoClientToScreen(&x
, &y
);
1396 CGPoint cgpoint
= CGPointMake( x
, y
);
1397 CGWarpMouseCursorPosition( cgpoint
);
1399 // At least GTK sends a mouse moved event after WarpMouse
1400 wxMouseEvent
event(wxEVT_MOTION
);
1403 wxMouseState mState
= ::wxGetMouseState();
1405 event
.m_altDown
= mState
.AltDown();
1406 event
.m_controlDown
= mState
.ControlDown();
1407 event
.m_leftDown
= mState
.LeftIsDown();
1408 event
.m_middleDown
= mState
.MiddleIsDown();
1409 event
.m_rightDown
= mState
.RightIsDown();
1410 event
.m_metaDown
= mState
.MetaDown();
1411 event
.m_shiftDown
= mState
.ShiftDown();
1412 event
.SetId(GetId());
1413 event
.SetEventObject(this);
1414 GetEventHandler()->ProcessEvent(event
);
1418 int wxWindowMac::GetScrollPos(int orient
) const
1421 if ( orient
== wxHORIZONTAL
)
1424 return m_hScrollBar
->GetThumbPosition() ;
1429 return m_vScrollBar
->GetThumbPosition() ;
1435 // This now returns the whole range, not just the number
1436 // of positions that we can scroll.
1437 int wxWindowMac::GetScrollRange(int orient
) const
1440 if ( orient
== wxHORIZONTAL
)
1443 return m_hScrollBar
->GetRange() ;
1448 return m_vScrollBar
->GetRange() ;
1454 int wxWindowMac::GetScrollThumb(int orient
) const
1457 if ( orient
== wxHORIZONTAL
)
1460 return m_hScrollBar
->GetThumbSize() ;
1465 return m_vScrollBar
->GetThumbSize() ;
1471 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1474 if ( orient
== wxHORIZONTAL
)
1477 m_hScrollBar
->SetThumbPosition( pos
) ;
1482 m_vScrollBar
->SetThumbPosition( pos
) ;
1488 wxWindowMac::AlwaysShowScrollbars(bool hflag
, bool vflag
)
1490 bool needVisibilityUpdate
= false;
1492 if ( m_hScrollBarAlwaysShown
!= hflag
)
1494 m_hScrollBarAlwaysShown
= hflag
;
1495 needVisibilityUpdate
= true;
1498 if ( m_vScrollBarAlwaysShown
!= vflag
)
1500 m_vScrollBarAlwaysShown
= vflag
;
1501 needVisibilityUpdate
= true;
1504 if ( needVisibilityUpdate
)
1505 DoUpdateScrollbarVisibility();
1509 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1510 // our own window origin is at leftOrigin/rightOrigin
1513 void wxWindowMac::MacPaintGrowBox()
1519 if ( MacHasScrollBarCorner() )
1522 CGContextRef cgContext
= (CGContextRef
) MacGetCGContextRef() ;
1523 wxASSERT( cgContext
) ;
1527 GetPeer()->GetSize( tw
, th
);
1528 GetPeer()->GetPosition( tx
, ty
);
1530 Rect rect
= { ty
,tx
, ty
+th
, tx
+tw
};
1533 int size
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
1534 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
1535 CGContextSaveGState( cgContext
);
1537 if ( m_backgroundColour
.IsOk() )
1539 CGContextSetFillColorWithColor( cgContext
, m_backgroundColour
.GetCGColor() );
1543 CGContextSetRGBFillColor( cgContext
, (CGFloat
) 1.0, (CGFloat
)1.0 ,(CGFloat
) 1.0 , (CGFloat
)1.0 );
1545 CGContextFillRect( cgContext
, cgrect
);
1546 CGContextRestoreGState( cgContext
);
1550 if ( m_backgroundColour
.IsOk() )
1551 m_growBox
->SetBackgroundColour(m_backgroundColour
);
1553 m_growBox
->SetBackgroundColour(*wxWHITE
);
1561 void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin
) , int WXUNUSED(rightOrigin
) )
1566 bool hasFocus
= GetPeer()->NeedsFocusRect() && HasFocus();
1568 // back to the surrounding frame rectangle
1571 GetPeer()->GetSize( tw
, th
);
1572 GetPeer()->GetPosition( tx
, ty
);
1574 #if wxOSX_USE_COCOA_OR_CARBON
1577 CGRect cgrect
= CGRectMake( tx
-1 , ty
-1 , tw
+2 ,
1580 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
1581 wxASSERT( cgContext
) ;
1583 if ( GetPeer()->NeedsFrame() )
1585 HIThemeFrameDrawInfo info
;
1586 memset( &info
, 0 , sizeof(info
) ) ;
1590 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
1591 info
.isFocused
= hasFocus
;
1593 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1595 info
.kind
= kHIThemeFrameTextFieldSquare
;
1596 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1598 else if ( HasFlag(wxSIMPLE_BORDER
) )
1600 info
.kind
= kHIThemeFrameListBox
;
1601 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
1607 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
1610 #endif // wxOSX_USE_COCOA_OR_CARBON
1613 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1616 if ( child
== m_hScrollBar
)
1617 m_hScrollBar
= NULL
;
1618 if ( child
== m_vScrollBar
)
1619 m_vScrollBar
= NULL
;
1620 if ( child
== m_growBox
)
1623 wxWindowBase::RemoveChild( child
) ;
1626 void wxWindowMac::DoUpdateScrollbarVisibility()
1629 bool triggerSizeEvent
= false;
1633 bool showHScrollBar
= m_hScrollBarAlwaysShown
|| m_hScrollBar
->IsNeeded();
1635 if ( m_hScrollBar
->IsShown() != showHScrollBar
)
1637 m_hScrollBar
->Show( showHScrollBar
);
1638 triggerSizeEvent
= true;
1644 bool showVScrollBar
= m_vScrollBarAlwaysShown
|| m_vScrollBar
->IsNeeded();
1646 if ( m_vScrollBar
->IsShown() != showVScrollBar
)
1648 m_vScrollBar
->Show( showVScrollBar
) ;
1649 triggerSizeEvent
= true;
1653 MacRepositionScrollBars() ;
1654 if ( triggerSizeEvent
)
1656 MacOnInternalSize();
1657 wxSizeEvent
event(GetSize(), m_windowId
);
1658 event
.SetEventObject(this);
1659 HandleWindowEvent(event
);
1664 // New function that will replace some of the above.
1665 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumb
,
1666 int range
, bool refresh
)
1669 // Updating scrollbars when window is being deleted is useless and
1670 // currently results in asserts in client-to-screen coordinates conversion
1671 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1672 if ( m_isBeingDeleted
)
1675 if ( orient
== wxHORIZONTAL
&& m_hScrollBar
)
1676 m_hScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1677 else if ( orient
== wxVERTICAL
&& m_vScrollBar
)
1678 m_vScrollBar
->SetScrollbar(pos
, thumb
, range
, thumb
, refresh
);
1680 DoUpdateScrollbarVisibility();
1684 // Does a physical scroll
1685 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1687 if ( dx
== 0 && dy
== 0 )
1690 int width
, height
;
1691 GetClientSize( &width
, &height
) ;
1694 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
1696 scrollrect
.Intersect( *rect
) ;
1697 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1698 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1700 GetPeer()->ScrollRect( &scrollrect
, dx
, dy
);
1705 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1707 child
= node
->GetData();
1711 if (child
->IsTopLevel())
1714 if ( !IsClientAreaChild(child
) )
1717 child
->GetPosition( &x
, &y
);
1718 child
->GetSize( &w
, &h
);
1721 wxRect
rc( x
, y
, w
, h
);
1722 if (rect
->Intersects( rc
))
1723 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1727 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
, wxSIZE_AUTO
|wxSIZE_ALLOW_MINUS_ONE
);
1732 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
1735 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
1737 wxScrollWinEvent wevent
;
1738 wevent
.SetPosition(event
.GetPosition());
1739 wevent
.SetOrientation(event
.GetOrientation());
1740 wevent
.SetEventObject(this);
1742 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
1743 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
1744 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
1745 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
1746 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
1747 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
1748 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
1749 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
1750 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
1751 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
1752 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
1753 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
1754 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
1755 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
1756 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
1757 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
1759 HandleWindowEvent(wevent
);
1764 wxWindow
*wxWindowBase::DoFindFocus()
1766 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
1769 // Raise the window to the top of the Z order
1770 void wxWindowMac::Raise()
1775 // Lower the window to the bottom of the Z order
1776 void wxWindowMac::Lower()
1781 // static wxWindow *gs_lastWhich = NULL;
1783 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
1785 // first trigger a set cursor event
1787 wxPoint clientorigin
= GetClientAreaOrigin() ;
1788 wxSize clientsize
= GetClientSize() ;
1790 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
1792 wxSetCursorEvent
event( pt
.x
, pt
.y
);
1794 bool processedEvtSetCursor
= HandleWindowEvent(event
);
1795 if ( processedEvtSetCursor
&& event
.HasCursor() )
1797 cursor
= event
.GetCursor() ;
1801 // the test for processedEvtSetCursor is here to prevent using m_cursor
1802 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1803 // it - this is a way to say that our cursor shouldn't be used for this
1805 if ( !processedEvtSetCursor
&& m_cursor
.IsOk() )
1808 if ( !wxIsBusy() && !GetParent() )
1809 cursor
= *wxSTANDARD_CURSOR
;
1812 if ( cursor
.IsOk() )
1813 cursor
.MacInstall() ;
1816 return cursor
.IsOk() ;
1819 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&WXUNUSED(pt
) )
1823 return m_tooltip
->GetTip() ;
1826 return wxEmptyString
;
1829 void wxWindowMac::ClearBackground()
1835 void wxWindowMac::Update()
1837 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
1842 wxNonOwnedWindow
* wxWindowMac::MacGetTopLevelWindow() const
1844 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1848 if ( iter
->IsTopLevel() )
1850 wxTopLevelWindow
* toplevel
= wxDynamicCast(iter
,wxTopLevelWindow
);
1854 wxPopupWindow
* popupwin
= wxDynamicCast(iter
,wxPopupWindow
);
1859 iter
= iter
->GetParent() ;
1865 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
1867 MacUpdateClippedRects() ;
1869 return m_cachedClippedClientRect
;
1872 const wxRect
& wxWindowMac::MacGetClippedRect() const
1874 MacUpdateClippedRects() ;
1876 return m_cachedClippedRect
;
1879 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1881 MacUpdateClippedRects() ;
1883 return m_cachedClippedRectWithOuterStructure
;
1886 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
1888 static wxRegion emptyrgn
;
1890 if ( !m_isBeingDeleted
&& IsShownOnScreen() )
1892 MacUpdateClippedRects() ;
1893 if ( includeOuterStructures
)
1894 return m_cachedClippedRegionWithOuterStructure
;
1896 return m_cachedClippedRegion
;
1904 void wxWindowMac::MacUpdateClippedRects() const
1906 #if wxOSX_USE_CARBON
1907 if ( m_cachedClippedRectValid
)
1910 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1911 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1912 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1913 // to add focus borders everywhere
1915 Rect rIncludingOuterStructures
;
1919 GetPeer()->GetSize( tw
, th
);
1920 GetPeer()->GetPosition( tx
, ty
);
1922 Rect r
= { ty
,tx
, ty
+th
, tx
+tw
};
1924 r
.left
-= MacGetLeftBorderSize() ;
1925 r
.top
-= MacGetTopBorderSize() ;
1926 r
.bottom
+= MacGetBottomBorderSize() ;
1927 r
.right
+= MacGetRightBorderSize() ;
1934 rIncludingOuterStructures
= r
;
1935 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
1937 wxRect cl
= GetClientRect() ;
1938 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
1942 const wxWindow
* child
= (wxWindow
*) this ;
1943 const wxWindow
* parent
= NULL
;
1945 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
1947 if ( parent
->MacIsChildOfClientArea(child
) )
1949 size
= parent
->GetClientSize() ;
1950 wxPoint origin
= parent
->GetClientAreaOrigin() ;
1956 // this will be true for scrollbars, toolbars etc.
1957 size
= parent
->GetSize() ;
1958 y
= parent
->MacGetTopBorderSize() ;
1959 x
= parent
->MacGetLeftBorderSize() ;
1960 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
1961 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
1964 parent
->MacWindowToRootWindow( &x
, &y
) ;
1965 MacRootWindowToWindow( &x
, &y
) ;
1967 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
1969 // the wxwindow and client rects will always be clipped
1970 SectRect( &r
, &rparent
, &r
) ;
1971 SectRect( &rClient
, &rparent
, &rClient
) ;
1973 // the structure only at 'hard' borders
1974 if ( parent
->MacClipChildren() ||
1975 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
1977 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
1983 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
1984 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
1985 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
1986 m_cachedClippedRectWithOuterStructure
= wxRect(
1987 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
1988 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
1989 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
1991 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
1992 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
1993 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
1995 m_cachedClippedRectValid
= true ;
2000 This function must not change the updatergn !
2002 bool wxWindowMac::MacDoRedraw( long time
)
2004 bool handled
= false ;
2006 wxRegion formerUpdateRgn
= m_updateRegion
;
2007 wxRegion clientUpdateRgn
= formerUpdateRgn
;
2009 const wxRect clientRect
= GetClientRect();
2011 clientUpdateRgn
.Intersect(clientRect
);
2013 // first send an erase event to the entire update area
2014 const wxBackgroundStyle bgStyle
= GetBackgroundStyle();
2017 case wxBG_STYLE_ERASE
:
2018 case wxBG_STYLE_SYSTEM
:
2019 case wxBG_STYLE_COLOUR
:
2021 // for the toplevel window this really is the entire area for
2022 // all the others only their client area, otherwise they might
2023 // be drawing with full alpha and eg put blue into the grow-box
2024 // area of a scrolled window (scroll sample)
2025 wxWindowDC
dc(this);
2027 dc
.SetDeviceClippingRegion(formerUpdateRgn
);
2029 dc
.SetDeviceClippingRegion(clientUpdateRgn
);
2031 if ( bgStyle
== wxBG_STYLE_ERASE
)
2033 wxEraseEvent
eevent( GetId(), &dc
);
2034 eevent
.SetEventObject( this );
2035 if ( ProcessWindowEvent( eevent
) )
2041 dc
.SetBackground(GetBackgroundColour());
2047 case wxBG_STYLE_PAINT
:
2048 case wxBG_STYLE_TRANSPARENT
:
2049 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2050 // entire window client area
2054 wxFAIL_MSG( "unsupported background style" );
2057 // as this is a full window, shouldn't be necessary anymore
2058 // MacPaintGrowBox();
2060 // calculate a client-origin version of the update rgn and set
2061 // m_updateRegion to that
2062 clientUpdateRgn
.Offset(-clientRect
.GetPosition());
2063 m_updateRegion
= clientUpdateRgn
;
2065 if ( !m_updateRegion
.Empty() )
2067 // paint the window itself
2069 wxPaintEvent
event(GetId());
2070 event
.SetTimestamp(time
);
2071 event
.SetEventObject(this);
2072 handled
= HandleWindowEvent(event
);
2075 m_updateRegion
= formerUpdateRgn
;
2077 wxNonOwnedWindow
* top
= MacGetTopLevelWindow();
2079 top
->WindowWasPainted() ;
2084 void wxWindowMac::MacPaintChildrenBorders()
2086 // now we cannot rely on having its borders drawn by a window itself, as it does not
2087 // get the updateRgn wide enough to always do so, so we do it from the parent
2088 // this would also be the place to draw any custom backgrounds for native controls
2089 // in Composited windowing
2090 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2094 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2096 child
= node
->GetData();
2100 if (child
== m_vScrollBar
)
2102 if (child
== m_hScrollBar
)
2104 if (child
== m_growBox
)
2107 if (child
->IsTopLevel())
2109 if (!child
->IsShown())
2112 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2114 child
->GetPosition( &x
, &y
);
2115 child
->GetSize( &w
, &h
);
2117 if ( m_updateRegion
.Contains(clientOrigin
.x
+x
-10, clientOrigin
.y
+y
-10, w
+20, h
+20) )
2119 // paint custom borders
2120 wxNcPaintEvent
eventNc( child
->GetId() );
2121 eventNc
.SetEventObject( child
);
2122 if ( !child
->HandleWindowEvent( eventNc
) )
2124 child
->MacPaintBorders(0, 0) ;
2131 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2133 wxNonOwnedWindow
* tlw
= MacGetTopLevelWindow();
2134 return tlw
? tlw
->GetWXWindow() : NULL
;
2137 bool wxWindowMac::MacHasScrollBarCorner() const
2140 /* Returns whether the scroll bars in a wxScrolledWindow should be
2141 * shortened. Scroll bars should be shortened if either:
2143 * - both scroll bars are visible, or
2145 * - there is a resize box in the parent frame's corner and this
2146 * window shares the bottom and right edge with the parent
2150 if ( m_hScrollBar
== NULL
&& m_vScrollBar
== NULL
)
2153 if ( ( m_hScrollBar
&& m_hScrollBar
->IsShown() )
2154 && ( m_vScrollBar
&& m_vScrollBar
->IsShown() ) )
2156 // Both scroll bars visible
2161 wxPoint thisWindowBottomRight
= GetScreenRect().GetBottomRight();
2163 for ( const wxWindow
*win
= (wxWindow
*)this; win
; win
= win
->GetParent() )
2165 const wxFrame
*frame
= wxDynamicCast( win
, wxFrame
) ;
2168 if ( frame
->GetWindowStyleFlag() & wxRESIZE_BORDER
)
2170 // Parent frame has resize handle
2171 wxPoint frameBottomRight
= frame
->GetScreenRect().GetBottomRight();
2173 // Note: allow for some wiggle room here as wxMac's
2174 // window rect calculations seem to be imprecise
2175 if ( abs( thisWindowBottomRight
.x
- frameBottomRight
.x
) <= 2
2176 && abs( thisWindowBottomRight
.y
- frameBottomRight
.y
) <= 2 )
2178 // Parent frame has resize handle and shares
2179 // right bottom corner
2184 // Parent frame has resize handle but doesn't
2185 // share right bottom corner
2191 // Parent frame doesn't have resize handle
2197 // No parent frame found
2205 void wxWindowMac::MacCreateScrollBars( long style
)
2208 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2210 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2212 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2213 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2215 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2218 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1: 0 ;
2220 GetClientSize( &width
, &height
) ;
2222 wxPoint
vPoint(width
- scrlsize
, 0) ;
2223 wxSize
vSize(scrlsize
, height
- adjust
) ;
2224 wxPoint
hPoint(0, height
- scrlsize
) ;
2225 wxSize
hSize(width
- adjust
, scrlsize
) ;
2227 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2228 if ( style
& wxVSCROLL
)
2230 m_vScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
2231 m_vScrollBar
->SetMinSize( wxDefaultSize
);
2234 if ( style
& wxHSCROLL
)
2236 m_hScrollBar
= new wxScrollBar((wxWindow
*)this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
2237 m_hScrollBar
->SetMinSize( wxDefaultSize
);
2240 wxPoint
gPoint(width
- scrlsize
, height
- scrlsize
);
2241 wxSize
gSize(scrlsize
, scrlsize
);
2242 m_growBox
= new wxBlindPlateWindow((wxWindow
*)this, wxID_ANY
, gPoint
, gSize
, 0);
2245 // because the create does not take into account the client area origin
2246 // we might have a real position shift
2247 MacRepositionScrollBars() ;
2251 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2253 bool result
= ((child
== NULL
)
2255 || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
) && (child
!= m_growBox
))
2262 void wxWindowMac::MacRepositionScrollBars()
2265 if ( !m_hScrollBar
&& !m_vScrollBar
)
2268 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2269 int adjust
= MacHasScrollBarCorner() ? scrlsize
- 1 : 0 ;
2271 // get real client area
2273 GetSize( &width
, &height
);
2275 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2276 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2278 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
2279 wxSize
vSize( scrlsize
, height
- adjust
) ;
2280 wxPoint
hPoint( 0 , height
- scrlsize
) ;
2281 wxSize
hSize( width
- adjust
, scrlsize
) ;
2284 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2286 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2289 if ( MacHasScrollBarCorner() )
2291 m_growBox
->SetSize( width
- scrlsize
, height
- scrlsize
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_USE_EXISTING
);
2292 if ( !m_growBox
->IsShown() )
2297 if ( m_growBox
->IsShown() )
2304 bool wxWindowMac::AcceptsFocus() const
2306 if ( GetPeer() == NULL
|| GetPeer()->IsUserPane() )
2307 return wxWindowBase::AcceptsFocus();
2309 return GetPeer()->CanFocus();
2312 void wxWindowMac::MacSuperChangedPosition()
2314 // only window-absolute structures have to be moved i.e. controls
2316 m_cachedClippedRectValid
= false ;
2319 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2322 child
= node
->GetData();
2323 child
->MacSuperChangedPosition() ;
2325 node
= node
->GetNext();
2329 void wxWindowMac::MacTopLevelWindowChangedPosition()
2331 // only screen-absolute structures have to be moved i.e. glcanvas
2334 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2337 child
= node
->GetData();
2338 child
->MacTopLevelWindowChangedPosition() ;
2340 node
= node
->GetNext();
2344 long wxWindowMac::MacGetWXBorderSize() const
2351 if ( GetPeer() && GetPeer()->NeedsFrame() )
2353 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
2355 #if wxOSX_USE_COCOA_OR_CARBON
2356 // this metric is only the 'outset' outside the simple frame rect
2357 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2363 else if (HasFlag(wxSIMPLE_BORDER
))
2365 #if wxOSX_USE_COCOA_OR_CARBON
2366 // this metric is only the 'outset' outside the simple frame rect
2367 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2378 long wxWindowMac::MacGetLeftBorderSize() const
2380 // the wx borders are all symmetric in mac themes
2381 long border
= MacGetWXBorderSize() ;
2385 int left
, top
, right
, bottom
;
2386 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2394 long wxWindowMac::MacGetRightBorderSize() const
2396 // the wx borders are all symmetric in mac themes
2397 long border
= MacGetWXBorderSize() ;
2401 int left
, top
, right
, bottom
;
2402 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2409 long wxWindowMac::MacGetTopBorderSize() const
2411 // the wx borders are all symmetric in mac themes
2412 long border
= MacGetWXBorderSize() ;
2416 int left
, top
, right
, bottom
;
2417 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2424 long wxWindowMac::MacGetBottomBorderSize() const
2426 // the wx borders are all symmetric in mac themes
2427 long border
= MacGetWXBorderSize() ;
2431 int left
, top
, right
, bottom
;
2432 GetPeer()->GetLayoutInset( left
, top
, right
, bottom
);
2439 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2441 return style
& ~wxBORDER_MASK
;
2444 // Find the wxWindowMac at the current mouse position, returning the mouse
2446 wxWindow
* wxFindWindowAtPointer( wxPoint
& pt
)
2448 pt
= wxGetMousePosition();
2449 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2451 return (wxWindow
*) found
;
2454 // Get the current mouse position.
2455 wxPoint
wxGetMousePosition()
2459 wxGetMousePosition( &x
, &y
);
2461 return wxPoint(x
, y
);
2464 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2466 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2468 // copied from wxGTK : CS
2469 // VZ: shouldn't we move this to base class then?
2471 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2474 // (a) it's a command event and so is propagated to the parent
2475 // (b) under MSW it can be generated from kbd too
2476 // (c) it uses screen coords (because of (a))
2477 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2479 this->ClientToScreen(event
.GetPosition()));
2480 evtCtx
.SetEventObject(this);
2481 if ( ! HandleWindowEvent(evtCtx
) )
2490 void wxWindowMac::TriggerScrollEvent( wxEventType
WXUNUSED(scrollEvent
) )
2494 Rect
wxMacGetBoundsForControl( wxWindowMac
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2498 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2499 Rect bounds
= { static_cast<short>(y
), static_cast<short>(x
), static_cast<short>(y
+ h
), static_cast<short>(x
+ w
) };
2504 bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec
) )
2509 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF event
)
2511 #if wxOSX_USE_COCOA_OR_CARBON
2512 if ( OSXHandleClicked( GetEventTime((EventRef
)event
) ) )
2515 return eventNotHandledErr
;
2521 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
2523 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
2524 if ( !wxWindowBase::Reparent(newParent
) )
2527 GetPeer()->RemoveFromParent();
2528 GetPeer()->Embed( GetParent()->GetPeer() );
2534 bool wxWindowMac::SetTransparent(wxByte alpha
)
2536 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT
);
2538 if ( alpha
!= m_macAlpha
)
2540 m_macAlpha
= alpha
;
2547 bool wxWindowMac::CanSetTransparent()
2552 wxByte
wxWindowMac::GetTransparent() const
2557 bool wxWindowMac::IsShownOnScreen() const
2559 if ( GetPeer() && GetPeer()->IsOk() )
2561 bool peerVis
= GetPeer()->IsVisible();
2562 bool wxVis
= wxWindowBase::IsShownOnScreen();
2563 if( peerVis
!= wxVis
)
2565 // CS : put a breakpoint here to investigate differences
2566 // between native an wx visibilities
2567 // the only place where I've encountered them until now
2568 // are the hiding/showing sequences where the vis-changed event is
2569 // first sent to the innermost control, while wx does things
2570 // from the outmost control
2571 wxVis
= wxWindowBase::IsShownOnScreen();
2575 return GetPeer()->IsVisible();
2577 return wxWindowBase::IsShownOnScreen();
2580 #if wxUSE_HOTKEY && wxOSX_USE_COCOA_OR_CARBON
2583 wxHotKeyHandler(EventHandlerCallRef
WXUNUSED(nextHandler
),
2585 void* WXUNUSED(userData
))
2587 EventHotKeyID hotKeyId
;
2589 GetEventParameter( event
, kEventParamDirectObject
, typeEventHotKeyID
, NULL
, sizeof(hotKeyId
), NULL
, &hotKeyId
);
2591 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2593 if ( s_hotkeys
[i
].keyId
== static_cast<int>(hotKeyId
.id
) )
2595 unsigned char charCode
;
2598 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
2600 GetEventParameter( event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
2601 GetEventParameter( event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
2602 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
2604 UInt32 keymessage
= (keyCode
<< 8) + charCode
;
2606 wxKeyEvent
wxevent(wxEVT_HOTKEY
);
2607 wxevent
.SetId(hotKeyId
.id
);
2608 wxTheApp
->MacCreateKeyEvent( wxevent
, s_hotkeys
[i
].window
, keymessage
,
2609 modifiers
, when
, 0 ) ;
2611 s_hotkeys
[i
].window
->HandleWindowEvent(wxevent
);
2618 bool wxWindowMac::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
2620 for ( unsigned i
= 0; i
< s_hotkeys
.size(); ++i
)
2622 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2624 wxLogLastError(wxT("hotkeyId already registered"));
2630 static bool installed
= false;
2633 EventTypeSpec eventType
;
2634 eventType
.eventClass
=kEventClassKeyboard
;
2635 eventType
.eventKind
=kEventHotKeyPressed
;
2637 InstallApplicationEventHandler(&wxHotKeyHandler
, 1, &eventType
, NULL
, NULL
);
2641 UInt32 mac_modifiers
=0;
2642 if ( modifiers
& wxMOD_ALT
)
2643 mac_modifiers
|= optionKey
;
2644 if ( modifiers
& wxMOD_SHIFT
)
2645 mac_modifiers
|= shiftKey
;
2646 if ( modifiers
& wxMOD_RAW_CONTROL
)
2647 mac_modifiers
|= controlKey
;
2648 if ( modifiers
& wxMOD_CONTROL
)
2649 mac_modifiers
|= cmdKey
;
2651 EventHotKeyRef hotKeyRef
;
2652 EventHotKeyID hotKeyIDmac
;
2654 hotKeyIDmac
.signature
= 'WXMC';
2655 hotKeyIDmac
.id
= hotkeyId
;
2657 if ( RegisterEventHotKey(wxCharCodeWXToOSX((wxKeyCode
)keycode
), mac_modifiers
, hotKeyIDmac
,
2658 GetApplicationEventTarget(), 0, &hotKeyRef
) != noErr
)
2660 wxLogLastError(wxT("RegisterHotKey"));
2671 s_hotkeys
.push_back(v
);
2677 bool wxWindowMac::UnregisterHotKey(int hotkeyId
)
2679 for ( int i
= ((int)s_hotkeys
.size())-1; i
>=0; -- i
)
2681 if ( s_hotkeys
[i
].keyId
== hotkeyId
)
2683 EventHotKeyRef ref
= s_hotkeys
[i
].ref
;
2684 s_hotkeys
.erase(s_hotkeys
.begin() + i
);
2685 if ( UnregisterEventHotKey(ref
) != noErr
)
2687 wxLogLastError(wxT("UnregisterHotKey"));
2699 #endif // wxUSE_HOTKEY
2701 bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent
& event
)
2703 bool handled
= false;
2705 // moved the ordinary key event sending AFTER the accel evaluation
2708 if ( !handled
&& event
.GetEventType() == wxEVT_KEY_DOWN
)
2710 wxWindow
*ancestor
= this;
2713 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
2716 wxEvtHandler
* const handler
= ancestor
->GetEventHandler();
2718 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
2719 handled
= handler
->ProcessEvent( command_event
);
2723 // accelerators can also be used with buttons, try them too
2724 command_event
.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED
);
2725 handled
= handler
->ProcessEvent( command_event
);
2731 if (ancestor
->IsTopLevel())
2734 ancestor
= ancestor
->GetParent();
2737 #endif // wxUSE_ACCEL
2741 handled
= HandleWindowEvent( event
) ;
2742 if ( handled
&& event
.GetSkipped() )
2753 WX_DECLARE_HASH_MAP(WXWidget
, wxWidgetImpl
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
2755 static MacControlMap wxWinMacControlList
;
2757 wxWindowMac
*wxFindWindowFromWXWidget(WXWidget inControl
)
2759 wxWidgetImpl
* impl
= wxWidgetImpl::FindFromWXWidget( inControl
);
2761 return impl
->GetWXPeer();
2766 wxWidgetImpl
*wxWidgetImpl::FindFromWXWidget(WXWidget inControl
)
2768 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
2770 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
2773 void wxWidgetImpl::Associate(WXWidget inControl
, wxWidgetImpl
*impl
)
2775 // adding NULL ControlRef is (first) surely a result of an error and
2776 // (secondly) breaks native event processing
2777 wxCHECK_RET( inControl
!= (WXWidget
) NULL
, wxT("attempt to add a NULL WXWidget to control map") );
2779 wxWinMacControlList
[inControl
] = impl
;
2782 void wxWidgetImpl::RemoveAssociations(wxWidgetImpl
* impl
)
2784 // iterate over all the elements in the class
2785 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2786 // we should go on...
2792 MacControlMap::iterator it
;
2793 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
2795 if ( it
->second
== impl
)
2797 wxWinMacControlList
.erase(it
);
2805 IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl
, wxObject
)
2807 wxWidgetImpl::wxWidgetImpl( wxWindowMac
* peer
, bool isRootControl
, bool isUserPane
)
2810 m_isRootControl
= isRootControl
;
2811 m_isUserPane
= isUserPane
;
2813 m_shouldSendEvents
= true;
2816 wxWidgetImpl::wxWidgetImpl()
2821 wxWidgetImpl::~wxWidgetImpl()
2825 void wxWidgetImpl::Init()
2827 m_isRootControl
= false;
2829 m_needsFocusRect
= false;
2830 m_needsFrame
= true;
2833 void wxWidgetImpl::SetNeedsFocusRect( bool needs
)
2835 m_needsFocusRect
= needs
;
2838 bool wxWidgetImpl::NeedsFocusRect() const
2840 return m_needsFocusRect
;
2843 void wxWidgetImpl::SetNeedsFrame( bool needs
)
2845 m_needsFrame
= needs
;
2848 bool wxWidgetImpl::NeedsFrame() const
2850 return m_needsFrame
;