1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/scrolwin.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
40 #include "wx/laywin.h"
41 #include "wx/splitter.h"
43 #include "wx/toolbar.h"
50 #define wxWINDOW_HSCROLL 5998
51 #define wxWINDOW_VSCROLL 5997
53 #define MAC_SCROLLBAR_SIZE 15
54 #define MAC_SMALL_SCROLLBAR_SIZE 11
56 #include "wx/mac/uma.h"
59 #include <ToolUtils.h>
61 #include <MacTextEditor.h>
64 #if TARGET_API_MAC_OSX
66 #include <HIToolbox/HIView.h>
70 #if wxUSE_DRAG_AND_DROP
76 extern wxList wxPendingDelete
;
78 #ifdef __WXUNIVERSAL__
79 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
81 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
82 #endif // __WXUNIVERSAL__/__WXMAC__
84 #if !USE_SHARED_LIBRARY
86 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
87 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
88 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
89 // TODO EVT_PAINT(wxWindowMac::OnPaint)
90 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
91 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
92 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
97 #define wxMAC_DEBUG_REDRAW 0
98 #ifndef wxMAC_DEBUG_REDRAW
99 #define wxMAC_DEBUG_REDRAW 0
102 #define wxMAC_USE_THEME_BORDER 1
104 // ---------------------------------------------------------------------------
105 // Utility Routines to move between different coordinate systems
106 // ---------------------------------------------------------------------------
109 * Right now we have the following setup :
110 * a border that is not part of the native control is always outside the
111 * control's border (otherwise we loose all native intelligence, future ways
112 * may be to have a second embedding control responsible for drawing borders
113 * and backgrounds eventually)
114 * so all this border calculations have to be taken into account when calling
115 * native methods or getting native oriented data
116 * so we have three coordinate systems here
117 * wx client coordinates
118 * wx window coordinates (including window frames)
123 // originating from native control
127 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
129 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
132 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
134 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
138 // directed towards native control
141 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
143 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
146 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
148 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
152 // ---------------------------------------------------------------------------
154 // ---------------------------------------------------------------------------
156 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
157 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
159 #if TARGET_API_MAC_OSX
161 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
163 kEventControlVisibilityChanged
= 157
169 static const EventTypeSpec eventList
[] =
171 { kEventClassControl
, kEventControlHit
} ,
172 #if TARGET_API_MAC_OSX
173 { kEventClassControl
, kEventControlDraw
} ,
174 { kEventClassControl
, kEventControlVisibilityChanged
} ,
175 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
176 { kEventClassControl
, kEventControlHiliteChanged
} ,
177 { kEventClassControl
, kEventControlSetFocusPart
} ,
179 { kEventClassService
, kEventServiceGetTypes
},
180 { kEventClassService
, kEventServiceCopy
},
181 { kEventClassService
, kEventServicePaste
},
183 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
184 // { kEventClassControl , kEventControlBoundsChanged } ,
188 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
190 OSStatus result
= eventNotHandledErr
;
192 wxMacCarbonEvent
cEvent( event
) ;
194 ControlRef controlRef
;
195 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
197 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
199 switch( GetEventKind( event
) )
201 #if TARGET_API_MAC_OSX
202 case kEventControlDraw
:
204 RgnHandle updateRgn
= NULL
;
205 RgnHandle allocatedRgn
= NULL
;
206 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
207 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
209 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
213 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
215 allocatedRgn
= NewRgn() ;
216 CopyRgn( updateRgn
, allocatedRgn
) ;
217 // hide the given region by the new region that must be shifted
218 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
219 updateRgn
= allocatedRgn
;
224 // in case we would need a coregraphics compliant background erase first
225 // now usable to track redraws
226 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
227 if ( thisWindow
->MacIsUserPane() )
229 static float color
= 0.5 ;
232 HIViewGetBounds( controlRef
, &bounds
);
233 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
234 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
235 CGContextFillRect( cgContext
, bounds
);
246 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
249 DisposeRgn( allocatedRgn
) ;
252 case kEventControlVisibilityChanged
:
253 thisWindow
->MacVisibilityChanged() ;
255 case kEventControlEnabledStateChanged
:
256 thisWindow
->MacEnabledStateChanged() ;
258 case kEventControlHiliteChanged
:
259 thisWindow
->MacHiliteChanged() ;
261 case kEventControlSetFocusPart
:
263 Boolean focusEverything
= false ;
264 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
265 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
268 if ( controlPart
== kControlFocusNoPart
)
271 if ( thisWindow
->GetCaret() )
273 thisWindow
->GetCaret()->OnKillFocus();
275 #endif // wxUSE_CARET
276 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
277 event
.SetEventObject(thisWindow
);
278 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
282 // panel wants to track the window which was the last to have focus in it
283 wxChildFocusEvent
eventFocus(thisWindow
);
284 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
287 if ( thisWindow
->GetCaret() )
289 thisWindow
->GetCaret()->OnSetFocus();
291 #endif // wxUSE_CARET
293 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
294 event
.SetEventObject(thisWindow
);
295 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
297 if ( thisWindow
->MacIsUserPane() )
302 case kEventControlHit
:
304 result
= thisWindow
->MacControlHit( handler
, event
) ;
313 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
315 OSStatus result
= eventNotHandledErr
;
317 wxMacCarbonEvent
cEvent( event
) ;
319 ControlRef controlRef
;
320 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
321 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
322 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
324 switch( GetEventKind( event
) )
326 case kEventServiceGetTypes
:
330 textCtrl
->GetSelection( &from
, &to
) ;
332 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
334 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
335 if ( textCtrl
->IsEditable() )
336 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
338 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
339 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
341 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
345 CFArrayAppendValue (copyTypes
, typestring
) ;
347 CFArrayAppendValue (pasteTypes
, typestring
) ;
348 CFRelease( typestring
) ;
354 case kEventServiceCopy
:
358 textCtrl
->GetSelection( &from
, &to
) ;
359 wxString val
= textCtrl
->GetValue() ;
360 val
= val
.Mid( from
, to
- from
) ;
361 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
362 verify_noerr( ClearScrap( &scrapRef
) ) ;
363 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
367 case kEventServicePaste
:
370 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
371 Size textSize
, pastedSize
;
372 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
374 char *content
= new char[textSize
] ;
375 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
376 content
[textSize
-1] = 0 ;
378 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
380 textCtrl
->WriteText( wxString( content
) ) ;
391 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
393 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
394 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
395 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
396 OSStatus result
= eventNotHandledErr
;
398 switch ( GetEventClass( event
) )
400 case kEventClassControl
:
401 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
403 case kEventClassService
:
404 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
408 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
412 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
414 // ---------------------------------------------------------------------------
415 // UserPane events for non OSX builds
416 // ---------------------------------------------------------------------------
418 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
420 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
421 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
422 win
->MacControlUserPaneDrawProc(part
) ;
425 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
427 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
428 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
429 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
432 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
434 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
435 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
436 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
439 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
441 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
442 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
443 win
->MacControlUserPaneIdleProc() ;
446 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
448 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
449 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
450 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
453 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
455 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
456 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
457 win
->MacControlUserPaneActivateProc(activating
) ;
460 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
462 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
463 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
464 return win
->MacControlUserPaneFocusProc(action
) ;
467 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
469 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
470 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
471 win
->MacControlUserPaneBackgroundProc(info
) ;
474 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
476 RgnHandle rgn
= NewRgn() ;
478 wxMacWindowStateSaver
sv( this ) ;
479 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
480 MacDoRedraw( rgn
, 0 ) ;
484 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
486 return kControlNoPart
;
489 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
491 return kControlNoPart
;
494 void wxWindowMac::MacControlUserPaneIdleProc()
498 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
500 return kControlNoPart
;
503 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
507 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
509 return kControlNoPart
;
512 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
516 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
517 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
518 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
519 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
520 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
521 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
522 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
523 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
525 // ===========================================================================
527 // ===========================================================================
529 wxList
wxWinMacControlList(wxKEY_INTEGER
);
531 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
533 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
536 return (wxControl
*)node
->GetData();
539 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
541 // adding NULL ControlRef is (first) surely a result of an error and
542 // (secondly) breaks native event processing
543 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
545 if ( !wxWinMacControlList
.Find((long)inControl
) )
546 wxWinMacControlList
.Append((long)inControl
, control
);
549 void wxRemoveMacControlAssociation(wxWindow
*control
)
551 wxWinMacControlList
.DeleteObject(control
);
555 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
557 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
559 // we have to setup the brush in the current port and return noErr
560 // or return an error code so that the control manager walks further up the
561 // hierarchy to find a correct background
563 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
565 OSStatus status
= paramErr
;
568 case kControlMsgApplyTextColor
:
570 case kControlMsgSetUpBackground
:
572 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
576 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
579 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
581 // this clipping is only needed for non HIView
583 RgnHandle clip
= NewRgn() ;
586 wx
->MacWindowToRootWindow( &x
,&y
) ;
587 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
588 OffsetRgn( clip
, x
, y
) ;
595 else if ( wx->MacIsUserPane() )
597 // if we don't have a valid brush for such a control, we have to call the
598 // setup of our parent ourselves
599 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
612 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
613 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
617 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
620 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
625 // ----------------------------------------------------------------------------
626 // constructors and such
627 // ----------------------------------------------------------------------------
629 wxWindowMac::wxWindowMac()
634 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
639 const wxString
& name
)
642 Create(parent
, id
, pos
, size
, style
, name
);
645 void wxWindowMac::Init()
649 #if WXWIN_COMPATIBILITY_2_4
650 m_backgroundTransparent
= FALSE
;
653 // as all windows are created with WS_VISIBLE style...
656 m_hScrollBar
= NULL
;
657 m_vScrollBar
= NULL
;
658 m_macBackgroundBrush
= wxNullBrush
;
660 m_macIsUserPane
= TRUE
;
662 // make sure all proc ptrs are available
664 if ( gControlUserPaneDrawUPP
== NULL
)
666 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
667 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
668 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
669 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
670 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
671 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
672 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
673 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
675 if ( wxMacLiveScrollbarActionUPP
== NULL
)
677 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
680 if ( wxMacSetupControlBackgroundUPP
== NULL
)
682 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
685 // we need a valid font for the encodings
686 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
690 wxWindowMac::~wxWindowMac()
694 m_isBeingDeleted
= TRUE
;
696 #ifndef __WXUNIVERSAL__
697 // VS: make sure there's no wxFrame with last focus set to us:
698 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
700 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
703 if ( frame
->GetLastFocus() == this )
705 frame
->SetLastFocus((wxWindow
*)NULL
);
710 #endif // __WXUNIVERSAL__
712 // wxRemoveMacControlAssociation( this ) ;
713 // If we delete an item, we should initialize the parent panel,
714 // because it could now be invalid.
715 wxWindow
*parent
= GetParent() ;
718 if (parent
->GetDefaultItem() == (wxButton
*) this)
719 parent
->SetDefaultItem(NULL
);
721 if ( m_peer
&& m_peer
->Ok() )
723 // in case the callback might be called during destruction
724 wxRemoveMacControlAssociation( this) ;
725 // we currently are not using this hook
726 // ::SetControlColorProc( *m_peer , NULL ) ;
730 if ( g_MacLastWindow
== this )
732 g_MacLastWindow
= NULL
;
735 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
738 if ( frame
->GetLastFocus() == this )
739 frame
->SetLastFocus( NULL
) ;
744 // delete our drop target if we've got one
745 #if wxUSE_DRAG_AND_DROP
746 if ( m_dropTarget
!= NULL
)
751 #endif // wxUSE_DRAG_AND_DROP
755 WXWidget
wxWindowMac::GetHandle() const
757 return (WXWidget
) m_peer
->GetControlRef() ;
761 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
763 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
764 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
765 GetEventTypeCount(eventList
), eventList
, this,
766 (EventHandlerRef
*)&m_macControlEventHandler
);
771 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
775 const wxString
& name
)
777 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
779 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
782 parent
->AddChild(this);
784 m_windowVariant
= parent
->GetWindowVariant() ;
786 if ( m_macIsUserPane
)
788 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
791 | kControlSupportsEmbedding
792 // | kControlSupportsLiveFeedback
793 // | kControlHasSpecialBackground
794 // | kControlSupportsCalcBestRect
795 // | kControlHandlesTracking
796 | kControlSupportsFocus
797 // | kControlWantsActivate
798 // | kControlWantsIdle
801 m_peer
= new wxMacControl() ;
802 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
805 MacPostControlCreate(pos
,size
) ;
806 #if !TARGET_API_MAC_OSX
807 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
808 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
809 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
810 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
811 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
812 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
813 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
814 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
817 #ifndef __WXUNIVERSAL__
818 // Don't give scrollbars to wxControls unless they ask for them
819 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
820 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
822 MacCreateScrollBars( style
) ;
826 wxWindowCreateEvent
event(this);
827 GetEventHandler()->AddPendingEvent(event
);
832 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
834 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
836 m_peer
->SetReference( (long) this ) ;
838 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
840 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
841 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
842 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
844 // adjust font, controlsize etc
845 DoSetWindowVariant( m_windowVariant
) ;
847 #if !TARGET_API_MAC_OSX
848 // eventually we can fix some clipping issues be reactivating this hook
849 //if ( m_macIsUserPane )
850 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
852 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
854 if (!m_macIsUserPane
)
856 SetInitialBestSize(size
);
859 SetCursor( *wxSTANDARD_CURSOR
) ;
862 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
864 // Don't assert, in case we set the window variant before
865 // the window is created
866 // wxASSERT( m_peer->Ok() ) ;
868 m_windowVariant
= variant
;
870 if (m_peer
== NULL
|| !m_peer
->Ok())
874 ThemeFontID themeFont
= kThemeSystemFont
;
876 // we will get that from the settings later
877 // and make this NORMAL later, but first
878 // we have a few calculations that we must fix
882 case wxWINDOW_VARIANT_NORMAL
:
883 size
= kControlSizeNormal
;
884 themeFont
= kThemeSystemFont
;
886 case wxWINDOW_VARIANT_SMALL
:
887 size
= kControlSizeSmall
;
888 themeFont
= kThemeSmallSystemFont
;
890 case wxWINDOW_VARIANT_MINI
:
891 if (UMAGetSystemVersion() >= 0x1030 )
893 // not always defined in the headers
899 size
= kControlSizeSmall
;
900 themeFont
= kThemeSmallSystemFont
;
903 case wxWINDOW_VARIANT_LARGE
:
904 size
= kControlSizeLarge
;
905 themeFont
= kThemeSystemFont
;
908 wxFAIL_MSG(_T("unexpected window variant"));
911 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
914 font
.MacCreateThemeFont( themeFont
) ;
918 void wxWindowMac::MacUpdateControlFont()
920 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
924 bool wxWindowMac::SetFont(const wxFont
& font
)
926 bool retval
= !wxWindowBase::SetFont( font
) ;
928 MacUpdateControlFont() ;
933 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
935 if ( !wxWindowBase::SetForegroundColour(col
) )
938 MacUpdateControlFont() ;
943 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
945 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
949 wxColour
newCol(GetBackgroundColour());
950 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
952 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
954 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
956 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
960 brush
.SetColour( newCol
) ;
962 MacSetBackgroundBrush( brush
) ;
964 MacUpdateControlFont() ;
969 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
971 m_macBackgroundBrush
= brush
;
972 m_peer
->SetBackground( brush
) ;
975 bool wxWindowMac::MacCanFocus() const
977 // there is currently no way to determine whether the window is running in full keyboard
978 // access mode, therefore we cannot rely on these features, yet the only other way would be
979 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
980 // in event handlers...
981 UInt32 features
= 0 ;
982 m_peer
->GetFeatures( & features
) ;
983 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
987 void wxWindowMac::SetFocus()
989 if ( AcceptsFocus() )
991 #if !TARGET_API_MAC_OSX
992 wxWindow
* former
= FindFocus() ;
994 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
995 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
996 // leave in case of an error
997 if ( err
== errCouldntSetFocus
)
1000 #if !TARGET_API_MAC_OSX
1001 // emulate carbon events when running under carbonlib where they are not natively available
1004 EventRef evRef
= NULL
;
1005 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1008 wxMacCarbonEvent
cEvent( evRef
) ;
1009 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1010 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1012 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1013 ReleaseEvent(evRef
) ;
1015 // send new focus event
1017 EventRef evRef
= NULL
;
1018 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1021 wxMacCarbonEvent
cEvent( evRef
) ;
1022 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1023 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1025 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1026 ReleaseEvent(evRef
) ;
1033 void wxWindowMac::DoCaptureMouse()
1035 wxTheApp
->s_captureWindow
= this ;
1038 wxWindow
* wxWindowBase::GetCapture()
1040 return wxTheApp
->s_captureWindow
;
1043 void wxWindowMac::DoReleaseMouse()
1045 wxTheApp
->s_captureWindow
= NULL
;
1048 #if wxUSE_DRAG_AND_DROP
1050 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1052 if ( m_dropTarget
!= 0 ) {
1053 delete m_dropTarget
;
1056 m_dropTarget
= pDropTarget
;
1057 if ( m_dropTarget
!= 0 )
1065 // Old style file-manager drag&drop
1066 void wxWindowMac::DragAcceptFiles(bool accept
)
1071 // Returns the size of the native control. In the case of the toplevel window
1072 // this is the content area root control
1074 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1075 int& w
, int& h
) const
1078 m_peer
->GetRect( &bounds
) ;
1083 w
= bounds
.right
- bounds
.left
;
1084 h
= bounds
.bottom
- bounds
.top
;
1087 // From a wx position / size calculate the appropriate size of the native control
1089 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1092 int& w
, int& h
, bool adjustOrigin
) const
1094 // the desired size, minus the border pixels gives the correct size of the control
1098 // todo the default calls may be used as soon as PostCreateControl Is moved here
1099 w
= size
.x
; // WidthDefault( size.x );
1100 h
= size
.y
; // HeightDefault( size.y ) ;
1101 #if !TARGET_API_MAC_OSX
1102 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1105 x
+= MacGetLeftBorderSize() ;
1106 y
+= MacGetTopBorderSize() ;
1107 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1108 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1111 AdjustForParentClientOrigin( x
, y
) ;
1115 // Get window size (not client size)
1116 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1118 // take the size of the control and add the borders that have to be drawn outside
1119 int x1
, y1
, w1
, h1
;
1121 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1123 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1124 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1130 // get the position of the bounds of this window in client coordinates of its parent
1131 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1133 int x1
, y1
, w1
,h1
;
1134 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1135 x1
-= MacGetLeftBorderSize() ;
1136 y1
-= MacGetTopBorderSize() ;
1138 #if !TARGET_API_MAC_OSX
1139 if ( !GetParent()->IsTopLevel() )
1142 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1147 if ( !IsTopLevel() )
1149 wxWindow
*parent
= GetParent();
1152 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1153 x1
+= parent
->MacGetLeftBorderSize() ;
1154 y1
+= parent
->MacGetTopBorderSize() ;
1155 // and now to client coordinates
1156 wxPoint
pt(parent
->GetClientAreaOrigin());
1165 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1167 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1169 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1172 Point localwhere
= {0,0} ;
1174 if(x
) localwhere
.h
= * x
;
1175 if(y
) localwhere
.v
= * y
;
1177 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1178 if(x
) *x
= localwhere
.h
;
1179 if(y
) *y
= localwhere
.v
;
1182 MacRootWindowToWindow( x
, y
) ;
1184 wxPoint origin
= GetClientAreaOrigin() ;
1185 if(x
) *x
-= origin
.x
;
1186 if(y
) *y
-= origin
.y
;
1189 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1191 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1192 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1194 wxPoint origin
= GetClientAreaOrigin() ;
1195 if(x
) *x
+= origin
.x
;
1196 if(y
) *y
+= origin
.y
;
1198 MacWindowToRootWindow( x
, y
) ;
1201 Point localwhere
= { 0,0 };
1202 if(x
) localwhere
.h
= * x
;
1203 if(y
) localwhere
.v
= * y
;
1204 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1205 if(x
) *x
= localwhere
.h
;
1206 if(y
) *y
= localwhere
.v
;
1210 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1212 wxPoint origin
= GetClientAreaOrigin() ;
1213 if(x
) *x
+= origin
.x
;
1214 if(y
) *y
+= origin
.y
;
1216 MacWindowToRootWindow( x
, y
) ;
1219 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1221 MacRootWindowToWindow( x
, y
) ;
1223 wxPoint origin
= GetClientAreaOrigin() ;
1224 if(x
) *x
-= origin
.x
;
1225 if(y
) *y
-= origin
.y
;
1228 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1230 #if TARGET_API_MAC_OSX
1232 if ( x
) pt
.x
= *x
;
1233 if ( y
) pt
.y
= *y
;
1235 if ( !IsTopLevel() )
1237 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1240 pt
.x
-= MacGetLeftBorderSize() ;
1241 pt
.y
-= MacGetTopBorderSize() ;
1242 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1246 if ( x
) *x
= (int) pt
.x
;
1247 if ( y
) *y
= (int) pt
.y
;
1249 if ( !IsTopLevel() )
1252 m_peer
->GetRect( &bounds
) ;
1253 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1254 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1259 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1264 MacWindowToRootWindow( &x1
, &y1
) ;
1269 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1271 #if TARGET_API_MAC_OSX
1273 if ( x
) pt
.x
= *x
;
1274 if ( y
) pt
.y
= *y
;
1276 if ( !IsTopLevel() )
1278 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1279 pt
.x
+= MacGetLeftBorderSize() ;
1280 pt
.y
+= MacGetTopBorderSize() ;
1283 if ( x
) *x
= (int) pt
.x
;
1284 if ( y
) *y
= (int) pt
.y
;
1286 if ( !IsTopLevel() )
1289 m_peer
->GetRect( &bounds
) ;
1290 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1291 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1296 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1301 MacRootWindowToWindow( &x1
, &y1
) ;
1306 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1308 RgnHandle rgn
= NewRgn() ;
1310 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1312 GetRegionBounds( rgn
, &content
) ;
1317 m_peer
->GetRect( &content
) ;
1320 m_peer
->GetRect( &structure
) ;
1321 #if !TARGET_API_MAC_OSX
1322 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1324 left
= content
.left
- structure
.left
;
1325 top
= content
.top
- structure
.top
;
1326 right
= structure
.right
- content
.right
;
1327 bottom
= structure
.bottom
- content
.bottom
;
1330 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1332 wxSize sizeTotal
= size
;
1334 RgnHandle rgn
= NewRgn() ;
1338 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1340 GetRegionBounds( rgn
, &content
) ;
1345 m_peer
->GetRect( &content
) ;
1348 m_peer
->GetRect( &structure
) ;
1349 #if !TARGET_API_MAC_OSX
1350 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1353 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1354 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1356 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1357 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1363 // Get size *available for subwindows* i.e. excluding menu bar etc.
1364 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1368 RgnHandle rgn
= NewRgn() ;
1370 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1372 GetRegionBounds( rgn
, &content
) ;
1377 m_peer
->GetRect( &content
) ;
1379 #if !TARGET_API_MAC_OSX
1381 m_peer
->GetRect( &structure
) ;
1382 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1384 ww
= content
.right
- content
.left
;
1385 hh
= content
.bottom
- content
.top
;
1387 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1388 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1391 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1397 GetSize( &w , &h ) ;
1399 MacClientToRootWindow( &x1 , &y1 ) ;
1400 MacClientToRootWindow( &w , &h ) ;
1402 wxWindowMac *iter = (wxWindowMac*)this ;
1404 int totW = 10000 , totH = 10000;
1407 if ( iter->IsTopLevel() )
1409 iter->GetSize( &totW , &totH ) ;
1413 iter = iter->GetParent() ;
1416 if (m_hScrollBar && m_hScrollBar->IsShown() )
1418 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1424 if (m_vScrollBar && m_vScrollBar->IsShown() )
1426 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1434 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1436 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1438 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1440 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1447 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1449 if (m_cursor
== cursor
)
1452 if (wxNullCursor
== cursor
)
1454 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1459 if ( ! wxWindowBase::SetCursor( cursor
) )
1463 wxASSERT_MSG( m_cursor
.Ok(),
1464 wxT("cursor must be valid after call to the base version"));
1467 wxWindowMac
*mouseWin
= 0 ;
1469 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1471 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1473 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1474 // position, use it...
1478 ControlPartCode part
;
1479 ControlRef control
;
1480 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1482 mouseWin
= wxFindControlFromMacControl( control
) ;
1485 QDSwapPort( savePort
, NULL
) ;
1488 if ( mouseWin
== this && !wxIsBusy() )
1490 m_cursor
.MacInstall() ;
1497 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1499 menu
->SetInvokingWindow(this);
1502 if ( x
== -1 && y
== -1 )
1504 wxPoint mouse
= wxGetMousePosition();
1505 x
= mouse
.x
; y
= mouse
.y
;
1509 ClientToScreen( &x
, &y
) ;
1512 menu
->MacBeforeDisplay( true ) ;
1513 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1514 if ( HiWord(menuResult
) != 0 )
1517 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1518 wxMenuItem
* item
= NULL
;
1520 item
= menu
->FindItem(id
, &realmenu
) ;
1521 if (item
->IsCheckable())
1523 item
->Check( !item
->IsChecked() ) ;
1525 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1527 menu
->MacAfterDisplay( true ) ;
1529 menu
->SetInvokingWindow(NULL
);
1535 // ----------------------------------------------------------------------------
1537 // ----------------------------------------------------------------------------
1541 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1543 wxWindowBase::DoSetToolTip(tooltip
);
1546 m_tooltip
->SetWindow(this);
1549 #endif // wxUSE_TOOLTIPS
1551 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1553 // this is never called for a toplevel window, so we know we have a parent
1554 int former_x
, former_y
, former_w
, former_h
;
1556 // Get true coordinates of former position
1557 DoGetPosition( &former_x
, &former_y
) ;
1558 DoGetSize( &former_w
, &former_h
) ;
1560 wxWindow
*parent
= GetParent();
1563 wxPoint
pt(parent
->GetClientAreaOrigin());
1568 int actualWidth
= width
;
1569 int actualHeight
= height
;
1573 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1574 actualWidth
= m_minWidth
;
1575 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1576 actualHeight
= m_minHeight
;
1577 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1578 actualWidth
= m_maxWidth
;
1579 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1580 actualHeight
= m_maxHeight
;
1582 bool doMove
= false ;
1583 bool doResize
= false ;
1585 if ( actualX
!= former_x
|| actualY
!= former_y
)
1589 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1594 if ( doMove
|| doResize
)
1596 // we don't adjust twice for the origin
1597 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1598 #if TARGET_API_MAC_OSX
1599 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1600 if ( ! GetParent()->IsTopLevel() )
1602 r
.left
-= GetParent()->MacGetLeftBorderSize() ;
1603 r
.top
-= GetParent()->MacGetTopBorderSize() ;
1604 r
.right
-= GetParent()->MacGetLeftBorderSize() ;
1605 r
.bottom
-= GetParent()->MacGetTopBorderSize() ;
1608 bool vis
= m_peer
->IsVisible();
1610 int outerBorder
= MacGetLeftBorderSize() ;
1611 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1614 if ( vis
&& ( outerBorder
> 0 ) )
1616 // as the borders are drawn on the parent we have to properly invalidate all these areas
1617 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1621 m_peer
->GetRect( &rect
) ;
1622 RectRgn( updateInner
, &rect
) ;
1623 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1624 RectRgn( updateOuter
, &rect
) ;
1625 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1626 wxPoint
parent(0,0);
1627 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1628 parent
-= GetParent()->GetClientAreaOrigin() ;
1629 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1630 CopyRgn( updateOuter
, updateTotal
) ;
1633 RectRgn( updateInner
, &rect
) ;
1634 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1635 RectRgn( updateOuter
, &rect
) ;
1636 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1637 wxPoint
parentorig(0,0);
1638 GetParent()->MacWindowToRootWindow( &parentorig
.x
, &parentorig
.y
) ;
1639 parent
-= GetParent()->GetClientAreaOrigin() ;
1640 OffsetRgn( updateOuter
, -parentorig
.x
, -parentorig
.y
) ;
1641 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1643 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1644 DisposeRgn(updateOuter
) ;
1645 DisposeRgn(updateInner
) ;
1646 DisposeRgn(updateTotal
) ;
1649 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1651 m_peer
->SetVisibility( false , true ) ;
1653 m_peer
->SetRect( &r
) ;
1655 m_peer
->SetVisibility( true , true ) ;
1657 MacRepositionScrollBars() ;
1660 wxPoint
point(actualX
,actualY
);
1661 wxMoveEvent
event(point
, m_windowId
);
1662 event
.SetEventObject(this);
1663 GetEventHandler()->ProcessEvent(event
) ;
1667 MacRepositionScrollBars() ;
1668 wxSize
size(actualWidth
, actualHeight
);
1669 wxSizeEvent
event(size
, m_windowId
);
1670 event
.SetEventObject(this);
1671 GetEventHandler()->ProcessEvent(event
);
1677 wxSize
wxWindowMac::DoGetBestSize() const
1679 if ( m_macIsUserPane
|| IsTopLevel() )
1680 return wxWindowBase::DoGetBestSize() ;
1682 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1683 int bestWidth
, bestHeight
;
1684 m_peer
->GetBestRect( &bestsize
) ;
1686 if ( EmptyRect( &bestsize
) )
1688 bestsize
.left
= bestsize
.top
= 0 ;
1689 bestsize
.right
= 16 ;
1690 bestsize
.bottom
= 16 ;
1691 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1693 bestsize
.bottom
= 16 ;
1695 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1697 bestsize
.bottom
= 24 ;
1701 // return wxWindowBase::DoGetBestSize() ;
1705 bestWidth
= bestsize
.right
- bestsize
.left
;
1706 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1707 if ( bestHeight
< 10 )
1710 return wxSize(bestWidth
, bestHeight
);
1714 // set the size of the window: if the dimensions are positive, just use them,
1715 // but if any of them is equal to -1, it means that we must find the value for
1716 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1717 // which case -1 is a valid value for x and y)
1719 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1720 // the width/height to best suit our contents, otherwise we reuse the current
1722 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1724 // get the current size and position...
1725 int currentX
, currentY
;
1726 GetPosition(¤tX
, ¤tY
);
1728 int currentW
,currentH
;
1729 GetSize(¤tW
, ¤tH
);
1731 // ... and don't do anything (avoiding flicker) if it's already ok
1732 if ( x
== currentX
&& y
== currentY
&&
1733 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1736 MacRepositionScrollBars() ; // we might have a real position shift
1740 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1742 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1745 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1747 wxSize
size(-1, -1);
1750 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1752 size
= DoGetBestSize();
1757 // just take the current one
1764 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1768 size
= DoGetBestSize();
1770 //else: already called DoGetBestSize() above
1776 // just take the current one
1781 DoMoveWindow(x
, y
, width
, height
);
1785 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1787 RgnHandle rgn
= NewRgn() ;
1789 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1790 GetRegionBounds( rgn
, &content
) ;
1792 #if !TARGET_API_MAC_OSX
1793 // if the content rgn is empty / not supported
1794 // don't attempt to correct the coordinates to wxWindow relative ones
1795 if (!::EmptyRect( &content
) )
1798 m_peer
->GetRect( &structure
) ;
1799 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1803 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1806 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1808 if ( clientheight
!= -1 || clientheight
!= -1 )
1810 int currentclientwidth
, currentclientheight
;
1811 int currentwidth
, currentheight
;
1813 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1814 GetSize( ¤twidth
, ¤theight
) ;
1816 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1817 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1821 void wxWindowMac::SetTitle(const wxString
& title
)
1823 m_label
= wxStripMenuCodes(title
) ;
1825 if ( m_peer
&& m_peer
->Ok() )
1827 m_peer
->SetTitle( m_label
) ;
1832 wxString
wxWindowMac::GetTitle() const
1837 bool wxWindowMac::Show(bool show
)
1839 if ( !wxWindowBase::Show(show
) )
1842 // TODO use visibilityChanged Carbon Event for OSX
1843 bool former
= MacIsReallyShown() ;
1845 m_peer
->SetVisibility( show
, true ) ;
1846 if ( former
!= MacIsReallyShown() )
1847 MacPropagateVisibilityChanged() ;
1851 bool wxWindowMac::Enable(bool enable
)
1853 wxASSERT( m_peer
->Ok() ) ;
1854 if ( !wxWindowBase::Enable(enable
) )
1857 bool former
= MacIsReallyEnabled() ;
1858 m_peer
->Enable( enable
) ;
1860 if ( former
!= MacIsReallyEnabled() )
1861 MacPropagateEnabledStateChanged() ;
1866 // status change propagations (will be not necessary for OSX later )
1869 void wxWindowMac::MacPropagateVisibilityChanged()
1871 #if !TARGET_API_MAC_OSX
1872 MacVisibilityChanged() ;
1874 wxWindowListNode
*node
= GetChildren().GetFirst();
1877 wxWindowMac
*child
= node
->GetData();
1878 if ( child
->IsShown() )
1879 child
->MacPropagateVisibilityChanged( ) ;
1880 node
= node
->GetNext();
1885 void wxWindowMac::MacPropagateEnabledStateChanged( )
1887 #if !TARGET_API_MAC_OSX
1888 MacEnabledStateChanged() ;
1890 wxWindowListNode
*node
= GetChildren().GetFirst();
1893 wxWindowMac
*child
= node
->GetData();
1894 if ( child
->IsEnabled() )
1895 child
->MacPropagateEnabledStateChanged() ;
1896 node
= node
->GetNext();
1901 void wxWindowMac::MacPropagateHiliteChanged( )
1903 #if !TARGET_API_MAC_OSX
1904 MacHiliteChanged() ;
1906 wxWindowListNode
*node
= GetChildren().GetFirst();
1909 wxWindowMac
*child
= node
->GetData();
1910 // if ( child->IsEnabled() )
1911 child
->MacPropagateHiliteChanged() ;
1912 node
= node
->GetNext();
1918 // status change notifications
1921 void wxWindowMac::MacVisibilityChanged()
1925 void wxWindowMac::MacHiliteChanged()
1929 void wxWindowMac::MacEnabledStateChanged()
1934 // status queries on the inherited window's state
1937 bool wxWindowMac::MacIsReallyShown()
1939 // only under OSX the visibility of the TLW is taken into account
1940 #if TARGET_API_MAC_OSX
1941 if ( m_peer
&& m_peer
->Ok() )
1942 return m_peer
->IsVisible();
1944 wxWindow
* win
= this ;
1945 while( win
->IsShown() )
1947 if ( win
->IsTopLevel() )
1950 win
= win
->GetParent() ;
1958 bool wxWindowMac::MacIsReallyEnabled()
1960 return m_peer
->IsEnabled() ;
1963 bool wxWindowMac::MacIsReallyHilited()
1965 return m_peer
->IsActive();
1968 void wxWindowMac::MacFlashInvalidAreas()
1970 #if TARGET_API_MAC_OSX
1971 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1979 int wxWindowMac::GetCharHeight() const
1981 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1982 return dc
.GetCharHeight() ;
1985 int wxWindowMac::GetCharWidth() const
1987 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1988 return dc
.GetCharWidth() ;
1991 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1992 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1994 const wxFont
*fontToUse
= theFont
;
1996 fontToUse
= &m_font
;
1998 wxClientDC
dc( (wxWindowMac
*) this ) ;
2000 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2001 if ( externalLeading
)
2002 *externalLeading
= le
;
2012 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2013 * we always intersect with the entire window, not only with the client area
2016 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2018 if ( m_peer
== NULL
)
2021 #if TARGET_API_MAC_OSX
2023 m_peer
->SetNeedsDisplay( true ) ;
2026 RgnHandle update
= NewRgn() ;
2027 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2028 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2029 wxPoint origin
= GetClientAreaOrigin() ;
2030 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2031 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2033 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2034 m_peer
->SetNeedsDisplay( true , update
) ;
2035 DisposeRgn( update
) ;
2039 RgnHandle updateRgn = NewRgn() ;
2042 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2046 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2047 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2049 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2050 DisposeRgn(updateRgn) ;
2052 if ( m_peer
->IsVisible())
2054 m_peer
->SetVisibility( false , false ) ;
2055 m_peer
->SetVisibility( true , true ) ;
2058 if ( MacGetTopLevelWindow() == NULL )
2061 if ( !m_peer->IsVisible())
2064 wxPoint client = GetClientAreaOrigin();
2067 int x2 = m_width - client.x;
2068 int y2 = m_height - client.y;
2070 if (IsKindOf( CLASSINFO(wxButton)))
2072 // buttons have an "aura"
2079 Rect clientrect = { y1, x1, y2, x2 };
2083 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2084 SectRect( &clientrect , &r , &clientrect ) ;
2087 if ( !EmptyRect( &clientrect ) )
2089 int top = 0 , left = 0 ;
2091 MacClientToRootWindow( &left , &top ) ;
2092 OffsetRect( &clientrect , left , top ) ;
2094 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2100 void wxWindowMac::Freeze()
2102 #if TARGET_API_MAC_OSX
2103 if ( !m_frozenness
++ )
2105 m_peer
->SetDrawingEnabled( false ) ;
2111 void wxWindowMac::Thaw()
2113 #if TARGET_API_MAC_OSX
2114 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2116 if ( !--m_frozenness
)
2118 m_peer
->SetDrawingEnabled( true ) ;
2119 m_peer
->InvalidateWithChildren() ;
2124 void wxWindowMac::MacRedrawControl()
2127 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2129 #if TARGET_API_MAC_CARBON
2132 wxClientDC dc(this) ;
2133 wxMacPortSetter helper(&dc) ;
2134 wxMacWindowClipper clipper(this) ;
2135 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2136 UMADrawControl( *m_peer ) ;
2143 void wxWindowMac::OnPaint(wxPaintEvent& event)
2145 // why don't we skip that here ?
2149 wxWindowMac
*wxGetActiveWindow()
2151 // actually this is a windows-only concept
2155 // Coordinates relative to the window
2156 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2158 // We really don't move the mouse programmatically under Mac.
2161 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2163 #if TARGET_API_MAC_OSX
2164 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2170 event
.GetDC()->Clear() ;
2173 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2178 int wxWindowMac::GetScrollPos(int orient
) const
2180 if ( orient
== wxHORIZONTAL
)
2183 return m_hScrollBar
->GetThumbPosition() ;
2188 return m_vScrollBar
->GetThumbPosition() ;
2193 // This now returns the whole range, not just the number
2194 // of positions that we can scroll.
2195 int wxWindowMac::GetScrollRange(int orient
) const
2197 if ( orient
== wxHORIZONTAL
)
2200 return m_hScrollBar
->GetRange() ;
2205 return m_vScrollBar
->GetRange() ;
2210 int wxWindowMac::GetScrollThumb(int orient
) const
2212 if ( orient
== wxHORIZONTAL
)
2215 return m_hScrollBar
->GetThumbSize() ;
2220 return m_vScrollBar
->GetThumbSize() ;
2225 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2227 if ( orient
== wxHORIZONTAL
)
2230 m_hScrollBar
->SetThumbPosition( pos
) ;
2235 m_vScrollBar
->SetThumbPosition( pos
) ;
2239 void wxWindowMac::MacPaintBorders( int left
, int top
)
2245 m_peer
->GetRect( &rect
) ;
2246 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2248 if ( !IsTopLevel() )
2250 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2254 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2256 rect
.right
+= pt
.x
;
2258 rect
.bottom
+= pt
.y
;
2262 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2266 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2267 InsetRect( &srect
, border
, border
);
2268 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2270 else if (HasFlag(wxSIMPLE_BORDER
))
2274 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2275 InsetRect( &srect
, border
, border
);
2276 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2280 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2282 if ( child
== m_hScrollBar
)
2283 m_hScrollBar
= NULL
;
2284 if ( child
== m_vScrollBar
)
2285 m_vScrollBar
= NULL
;
2287 wxWindowBase::RemoveChild( child
) ;
2290 // New function that will replace some of the above.
2291 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2292 int range
, bool refresh
)
2294 if ( orient
== wxHORIZONTAL
)
2298 if ( range
== 0 || thumbVisible
>= range
)
2300 if ( m_hScrollBar
->IsShown() )
2301 m_hScrollBar
->Show(false) ;
2305 if ( !m_hScrollBar
->IsShown() )
2306 m_hScrollBar
->Show(true) ;
2307 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2315 if ( range
== 0 || thumbVisible
>= range
)
2317 if ( m_vScrollBar
->IsShown() )
2318 m_vScrollBar
->Show(false) ;
2322 if ( !m_vScrollBar
->IsShown() )
2323 m_vScrollBar
->Show(true) ;
2324 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2328 MacRepositionScrollBars() ;
2331 // Does a physical scroll
2332 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2334 if( dx
== 0 && dy
==0 )
2340 int width
, height
;
2341 GetClientSize( &width
, &height
) ;
2342 #if TARGET_API_MAC_OSX
2343 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2344 // area is scrolled, this does not occur if width and height are 2 pixels less,
2345 // TODO write optimal workaround
2346 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2349 scrollrect
.Intersect( *rect
) ;
2351 if ( m_peer
->GetNeedsDisplay() )
2353 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2354 // either immediate redraw or full invalidate
2356 // is the better overall solution, as it does not slow down scrolling
2357 m_peer
->SetNeedsDisplay( true ) ;
2359 // this would be the preferred version for fast drawing controls
2360 if( UMAGetSystemVersion() < 0x1030 )
2363 HIViewRender(m_peer
->GetControlRef()) ;
2366 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2367 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2368 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2375 RgnHandle updateRgn
= NewRgn() ;
2378 wxClientDC
dc(this) ;
2379 wxMacPortSetter
helper(&dc
) ;
2381 m_peer
->GetRect( &scrollrect
) ;
2382 scrollrect
.top
+= MacGetTopBorderSize() ;
2383 scrollrect
.left
+= MacGetLeftBorderSize() ;
2384 scrollrect
.bottom
= scrollrect
.top
+ height
;
2385 scrollrect
.right
= scrollrect
.left
+ width
;
2389 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2390 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2391 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2393 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2395 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2399 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2401 wxWindowMac
*child
= node
->GetData();
2402 if (child
== m_vScrollBar
) continue;
2403 if (child
== m_hScrollBar
) continue;
2404 if (child
->IsTopLevel()) continue;
2407 child
->GetPosition( &x
, &y
);
2409 child
->GetSize( &w
, &h
);
2413 if (rect
->Intersects(rc
))
2414 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2418 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2423 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2425 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2427 wxScrollWinEvent wevent
;
2428 wevent
.SetPosition(event
.GetPosition());
2429 wevent
.SetOrientation(event
.GetOrientation());
2430 wevent
.m_eventObject
= this;
2432 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2433 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2434 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2435 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2436 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2437 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2438 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2439 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2440 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2441 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2442 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2443 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2444 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2445 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2446 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2447 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2449 GetEventHandler()->ProcessEvent(wevent
);
2453 // Get the window with the focus
2454 wxWindowMac
*wxWindowBase::FindFocus()
2456 ControlRef control
;
2457 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2458 return wxFindControlFromMacControl( control
) ;
2461 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2463 // panel wants to track the window which was the last to have focus in it,
2464 // so we want to set ourselves as the window which last had focus
2466 // notice that it's also important to do it upwards the tree becaus
2467 // otherwise when the top level panel gets focus, it won't set it back to
2468 // us, but to some other sibling
2470 // CS:don't know if this is still needed:
2471 //wxChildFocusEvent eventFocus(this);
2472 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2474 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2476 wxMacWindowStateSaver
sv( this ) ;
2481 MacWindowToRootWindow( &x
, &y
) ;
2482 GetSize( &w
, &h
) ;
2483 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2485 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2486 DrawThemeFocusRect( &rect
, true ) ;
2489 DrawThemeFocusRect( &rect
, false ) ;
2491 // as this erases part of the frame we have to redraw borders
2492 // and because our z-ordering is not always correct (staticboxes)
2493 // we have to invalidate things, we cannot simple redraw
2494 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2495 RectRgn( updateInner
, &rect
) ;
2496 InsetRect( &rect
, -4 , -4 ) ;
2497 RectRgn( updateOuter
, &rect
) ;
2498 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2499 wxPoint
parent(0,0);
2500 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2501 parent
-= GetParent()->GetClientAreaOrigin() ;
2502 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2503 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2504 DisposeRgn(updateOuter
) ;
2505 DisposeRgn(updateInner
) ;
2512 void wxWindowMac::OnInternalIdle()
2514 // This calls the UI-update mechanism (querying windows for
2515 // menu/toolbar/control state information)
2516 if (wxUpdateUIEvent::CanUpdate(this))
2517 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2520 // Raise the window to the top of the Z order
2521 void wxWindowMac::Raise()
2523 m_peer
->SetZOrder( true , NULL
) ;
2526 // Lower the window to the bottom of the Z order
2527 void wxWindowMac::Lower()
2529 m_peer
->SetZOrder( false , NULL
) ;
2533 // static wxWindow *gs_lastWhich = NULL;
2535 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2537 // first trigger a set cursor event
2539 wxPoint clientorigin
= GetClientAreaOrigin() ;
2540 wxSize clientsize
= GetClientSize() ;
2542 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2544 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2546 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2547 if ( processedEvtSetCursor
&& event
.HasCursor() )
2549 cursor
= event
.GetCursor() ;
2554 // the test for processedEvtSetCursor is here to prevent using m_cursor
2555 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2556 // it - this is a way to say that our cursor shouldn't be used for this
2558 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2568 cursor
= *wxSTANDARD_CURSOR
;
2572 cursor
.MacInstall() ;
2574 return cursor
.Ok() ;
2577 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2581 return m_tooltip
->GetTip() ;
2583 return wxEmptyString
;
2586 void wxWindowMac::Update()
2588 #if TARGET_API_MAC_OSX
2589 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2590 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2591 // for composited windows this also triggers a redraw of all
2592 // invalid views in the window
2593 if( UMAGetSystemVersion() >= 0x1030 )
2594 HIWindowFlush(window
) ;
2598 // the only way to trigger the redrawing on earlier systems is to call
2601 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2602 UInt32 currentEventClass
= 0 ;
2603 UInt32 currentEventKind
= 0 ;
2604 if ( currentEvent
!= NULL
)
2606 currentEventClass
= ::GetEventClass( currentEvent
) ;
2607 currentEventKind
= ::GetEventKind( currentEvent
) ;
2609 if ( currentEventClass
!= kEventClassMenu
)
2611 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2614 OSStatus status
= noErr
;
2615 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2618 m_peer
->SetNeedsDisplay( true ) ;
2621 ::Draw1Control( m_peer
->GetControlRef() ) ;
2625 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2627 wxTopLevelWindowMac
* win
= NULL
;
2628 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2631 win
= wxFindWinFromMacWindow( window
) ;
2635 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2637 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2638 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2639 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2640 // to add focus borders everywhere
2643 RgnHandle visRgn
= NewRgn() ;
2644 RgnHandle tempRgn
= NewRgn() ;
2645 if ( m_peer
->IsVisible())
2647 m_peer
->GetRect( &r
) ;
2648 r
.left
-= MacGetLeftBorderSize() ;
2649 r
.top
-= MacGetTopBorderSize() ;
2650 r
.bottom
+= MacGetBottomBorderSize() ;
2651 r
.right
+= MacGetRightBorderSize() ;
2653 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2655 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2656 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2665 if ( includeOuterStructures
)
2666 InsetRect( &r
, -4 , -4 ) ;
2667 RectRgn( visRgn
, &r
) ;
2669 if ( !IsTopLevel() )
2671 wxWindow
* child
= this ;
2672 wxWindow
* parent
= child
->GetParent() ;
2677 // we have to find a better clipping algorithm here, in order not to clip things
2678 // positioned like status and toolbar
2679 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2681 size
= parent
->GetSize() ;
2686 size
= parent
->GetClientSize() ;
2687 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2691 parent
->MacWindowToRootWindow( &x
, &y
) ;
2692 MacRootWindowToWindow( &x
, &y
) ;
2694 if ( !includeOuterStructures
|| (
2695 parent
->IsKindOf( CLASSINFO( wxScrolledWindow
) ) ||
2696 parent
->IsKindOf( CLASSINFO( wxSashLayoutWindow
) ) ||
2697 ( parent
->GetParent() && parent
->GetParent()->IsKindOf( CLASSINFO( wxSplitterWindow
) ) )
2700 SetRectRgn( tempRgn
,
2701 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2702 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2703 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2705 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2707 if ( parent
->IsTopLevel() )
2710 parent
= child
->GetParent() ;
2715 wxRegion vis
= visRgn
;
2716 DisposeRgn( visRgn
) ;
2717 DisposeRgn( tempRgn
) ;
2722 This function must not change the updatergn !
2724 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2726 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2727 bool handled
= false ;
2729 GetRegionBounds( updatergn
, &updatebounds
) ;
2730 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2731 if ( !EmptyRgn(updatergn
) )
2733 RgnHandle newupdate
= NewRgn() ;
2734 wxSize point
= GetClientSize() ;
2735 wxPoint origin
= GetClientAreaOrigin() ;
2736 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2737 SectRgn( newupdate
, updatergn
, newupdate
) ;
2739 // first send an erase event to the entire update area
2741 wxWindowDC
dc(this);
2742 dc
.SetClippingRegion(wxRegion(updatergn
));
2743 wxEraseEvent
eevent( GetId(), &dc
);
2744 eevent
.SetEventObject( this );
2745 GetEventHandler()->ProcessEvent( eevent
);
2748 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2749 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2750 m_updateRegion
= newupdate
;
2751 DisposeRgn( newupdate
) ;
2753 if ( !m_updateRegion
.Empty() )
2755 // paint the window itself
2757 event
.m_timeStamp
= time
;
2758 event
.SetEventObject(this);
2759 handled
= GetEventHandler()->ProcessEvent(event
);
2761 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2764 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2766 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2773 // now we cannot rely on having its borders drawn by a window itself, as it does not
2774 // get the updateRgn wide enough to always do so, so we do it from the parent
2775 // this would also be the place to draw any custom backgrounds for native controls
2776 // in Composited windowing
2777 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2779 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2781 wxWindowMac
*child
= node
->GetData();
2782 if (child
== m_vScrollBar
) continue;
2783 if (child
== m_hScrollBar
) continue;
2784 if (child
->IsTopLevel()) continue;
2785 if (!child
->IsShown()) continue;
2788 child
->GetPosition( &x
, &y
);
2790 child
->GetSize( &w
, &h
);
2791 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2792 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2793 if ( child
->MacGetTopBorderSize() )
2795 if ( RectInRgn( &childRect
, updatergn
) )
2797 // paint custom borders
2798 wxNcPaintEvent
eventNc( child
->GetId() );
2799 eventNc
.SetEventObject( child
);
2800 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2802 wxWindowDC
dc(this) ;
2803 dc
.SetClippingRegion(wxRegion(updatergn
));
2804 wxMacPortSetter
helper(&dc
) ;
2805 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2809 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2811 wxWindowDC
dc(this) ;
2812 dc
.SetClippingRegion(wxRegion(updatergn
));
2813 wxMacPortSetter
helper(&dc
) ;
2814 OffsetRect( &childRect
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2815 DrawThemeFocusRect( &childRect
, true ) ;
2822 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2824 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2825 // updatergn is always already clipped to our boundaries
2826 // if we are in compositing mode then it is in relative to the upper left of the control
2827 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2828 // of the toplevel window
2829 // it is in window coordinates, not in client coordinates
2831 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2832 RgnHandle ownUpdateRgn
= NewRgn() ;
2833 CopyRgn( updatergn
, ownUpdateRgn
) ;
2835 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2838 m_peer
->GetRectInWindowCoords( &bounds
);
2839 RgnHandle controlRgn
= NewRgn();
2840 RectRgn( controlRgn
, &bounds
);
2841 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2842 // the window update region
2843 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2844 DisposeRgn( controlRgn
);
2846 //KO: convert ownUpdateRgn to local coordinates
2847 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2850 MacDoRedraw( ownUpdateRgn
, time
) ;
2851 DisposeRgn( ownUpdateRgn
) ;
2855 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2857 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2861 if ( iter
->IsTopLevel() )
2862 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2864 iter
= iter
->GetParent() ;
2866 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2870 void wxWindowMac::MacCreateScrollBars( long style
)
2872 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2874 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2876 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2877 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2878 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2879 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2881 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2882 variant
= wxWINDOW_VARIANT_SMALL
;
2885 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2887 GetClientSize( &width
, &height
) ;
2889 wxPoint
vPoint(width
-scrlsize
, 0) ;
2890 wxSize
vSize(scrlsize
, height
- adjust
) ;
2891 wxPoint
hPoint(0 , height
-scrlsize
) ;
2892 wxSize
hSize( width
- adjust
, scrlsize
) ;
2895 if ( style
& wxVSCROLL
)
2897 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2898 vSize
, wxVERTICAL
);
2901 if ( style
& wxHSCROLL
)
2903 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2904 hSize
, wxHORIZONTAL
);
2909 // because the create does not take into account the client area origin
2910 MacRepositionScrollBars() ; // we might have a real position shift
2913 void wxWindowMac::MacRepositionScrollBars()
2915 if ( !m_hScrollBar
&& !m_vScrollBar
)
2918 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2919 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2920 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2922 // get real client area
2926 GetSize( &width
, &height
) ;
2928 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2929 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2931 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2932 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2933 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2934 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2940 GetSize( &w , &h ) ;
2942 MacClientToRootWindow( &x , &y ) ;
2943 MacClientToRootWindow( &w , &h ) ;
2945 wxWindowMac *iter = (wxWindowMac*)this ;
2947 int totW = 10000 , totH = 10000;
2950 if ( iter->IsTopLevel() )
2952 iter->GetSize( &totW , &totH ) ;
2956 iter = iter->GetParent() ;
2984 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2988 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2992 bool wxWindowMac::AcceptsFocus() const
2994 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2997 void wxWindowMac::MacSuperChangedPosition()
2999 // only window-absolute structures have to be moved i.e. controls
3001 wxWindowListNode
*node
= GetChildren().GetFirst();
3004 wxWindowMac
*child
= node
->GetData();
3005 child
->MacSuperChangedPosition() ;
3006 node
= node
->GetNext();
3010 void wxWindowMac::MacTopLevelWindowChangedPosition()
3012 // only screen-absolute structures have to be moved i.e. glcanvas
3014 wxWindowListNode
*node
= GetChildren().GetFirst();
3017 wxWindowMac
*child
= node
->GetData();
3018 child
->MacTopLevelWindowChangedPosition() ;
3019 node
= node
->GetNext();
3023 long wxWindowMac::MacGetLeftBorderSize( ) const
3028 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3033 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3038 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3045 long wxWindowMac::MacGetRightBorderSize( ) const
3047 // they are all symmetric in mac themes
3048 return MacGetLeftBorderSize() ;
3051 long wxWindowMac::MacGetTopBorderSize( ) const
3053 // they are all symmetric in mac themes
3054 return MacGetLeftBorderSize() ;
3057 long wxWindowMac::MacGetBottomBorderSize( ) const
3059 // they are all symmetric in mac themes
3060 return MacGetLeftBorderSize() ;
3063 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3065 return style
& ~wxBORDER_MASK
;
3068 // Find the wxWindowMac at the current mouse position, returning the mouse
3070 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3072 pt
= wxGetMousePosition();
3073 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3077 // Get the current mouse position.
3078 wxPoint
wxGetMousePosition()
3081 wxGetMousePosition(& x
, & y
);
3082 return wxPoint(x
, y
);
3085 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3087 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3089 // copied from wxGTK : CS
3090 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3093 // (a) it's a command event and so is propagated to the parent
3094 // (b) under MSW it can be generated from kbd too
3095 // (c) it uses screen coords (because of (a))
3096 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3098 this->ClientToScreen(event
.GetPosition()));
3099 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3108 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3112 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3116 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3117 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3121 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3123 return eventNotHandledErr
;