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() )
992 wxWindow
* former
= FindFocus() ;
993 if ( former
== this )
996 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
997 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
998 // leave in case of an error
999 if ( err
== errCouldntSetFocus
)
1002 #if !TARGET_API_MAC_OSX
1003 // emulate carbon events when running under carbonlib where they are not natively available
1006 EventRef evRef
= NULL
;
1007 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1010 wxMacCarbonEvent
cEvent( evRef
) ;
1011 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1012 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1014 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1015 ReleaseEvent(evRef
) ;
1017 // send new focus event
1019 EventRef evRef
= NULL
;
1020 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1023 wxMacCarbonEvent
cEvent( evRef
) ;
1024 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1025 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1027 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1028 ReleaseEvent(evRef
) ;
1035 void wxWindowMac::DoCaptureMouse()
1037 wxTheApp
->s_captureWindow
= this ;
1040 wxWindow
* wxWindowBase::GetCapture()
1042 return wxTheApp
->s_captureWindow
;
1045 void wxWindowMac::DoReleaseMouse()
1047 wxTheApp
->s_captureWindow
= NULL
;
1050 #if wxUSE_DRAG_AND_DROP
1052 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1054 if ( m_dropTarget
!= 0 ) {
1055 delete m_dropTarget
;
1058 m_dropTarget
= pDropTarget
;
1059 if ( m_dropTarget
!= 0 )
1067 // Old style file-manager drag&drop
1068 void wxWindowMac::DragAcceptFiles(bool accept
)
1073 // Returns the size of the native control. In the case of the toplevel window
1074 // this is the content area root control
1076 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1077 int& w
, int& h
) const
1080 m_peer
->GetRect( &bounds
) ;
1085 w
= bounds
.right
- bounds
.left
;
1086 h
= bounds
.bottom
- bounds
.top
;
1089 // From a wx position / size calculate the appropriate size of the native control
1091 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1094 int& w
, int& h
, bool adjustOrigin
) const
1096 // the desired size, minus the border pixels gives the correct size of the control
1100 // todo the default calls may be used as soon as PostCreateControl Is moved here
1101 w
= size
.x
; // WidthDefault( size.x );
1102 h
= size
.y
; // HeightDefault( size.y ) ;
1103 #if !TARGET_API_MAC_OSX
1104 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1107 x
+= MacGetLeftBorderSize() ;
1108 y
+= MacGetTopBorderSize() ;
1109 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1110 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1113 AdjustForParentClientOrigin( x
, y
) ;
1117 // Get window size (not client size)
1118 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1120 // take the size of the control and add the borders that have to be drawn outside
1121 int x1
, y1
, w1
, h1
;
1123 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1125 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1126 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1132 // get the position of the bounds of this window in client coordinates of its parent
1133 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1135 int x1
, y1
, w1
,h1
;
1136 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1137 x1
-= MacGetLeftBorderSize() ;
1138 y1
-= MacGetTopBorderSize() ;
1140 #if !TARGET_API_MAC_OSX
1141 if ( !GetParent()->IsTopLevel() )
1144 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1149 if ( !IsTopLevel() )
1151 wxWindow
*parent
= GetParent();
1154 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1155 x1
+= parent
->MacGetLeftBorderSize() ;
1156 y1
+= parent
->MacGetTopBorderSize() ;
1157 // and now to client coordinates
1158 wxPoint
pt(parent
->GetClientAreaOrigin());
1167 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1169 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1171 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1174 Point localwhere
= {0,0} ;
1176 if(x
) localwhere
.h
= * x
;
1177 if(y
) localwhere
.v
= * y
;
1179 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1180 if(x
) *x
= localwhere
.h
;
1181 if(y
) *y
= localwhere
.v
;
1184 MacRootWindowToWindow( x
, y
) ;
1186 wxPoint origin
= GetClientAreaOrigin() ;
1187 if(x
) *x
-= origin
.x
;
1188 if(y
) *y
-= origin
.y
;
1191 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1193 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1194 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1196 wxPoint origin
= GetClientAreaOrigin() ;
1197 if(x
) *x
+= origin
.x
;
1198 if(y
) *y
+= origin
.y
;
1200 MacWindowToRootWindow( x
, y
) ;
1203 Point localwhere
= { 0,0 };
1204 if(x
) localwhere
.h
= * x
;
1205 if(y
) localwhere
.v
= * y
;
1206 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1207 if(x
) *x
= localwhere
.h
;
1208 if(y
) *y
= localwhere
.v
;
1212 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1214 wxPoint origin
= GetClientAreaOrigin() ;
1215 if(x
) *x
+= origin
.x
;
1216 if(y
) *y
+= origin
.y
;
1218 MacWindowToRootWindow( x
, y
) ;
1221 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1223 MacRootWindowToWindow( x
, y
) ;
1225 wxPoint origin
= GetClientAreaOrigin() ;
1226 if(x
) *x
-= origin
.x
;
1227 if(y
) *y
-= origin
.y
;
1230 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1232 #if TARGET_API_MAC_OSX
1234 if ( x
) pt
.x
= *x
;
1235 if ( y
) pt
.y
= *y
;
1237 if ( !IsTopLevel() )
1239 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1242 pt
.x
-= MacGetLeftBorderSize() ;
1243 pt
.y
-= MacGetTopBorderSize() ;
1244 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1248 if ( x
) *x
= (int) pt
.x
;
1249 if ( y
) *y
= (int) pt
.y
;
1251 if ( !IsTopLevel() )
1254 m_peer
->GetRect( &bounds
) ;
1255 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1256 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1261 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1266 MacWindowToRootWindow( &x1
, &y1
) ;
1271 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1273 #if TARGET_API_MAC_OSX
1275 if ( x
) pt
.x
= *x
;
1276 if ( y
) pt
.y
= *y
;
1278 if ( !IsTopLevel() )
1280 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1281 pt
.x
+= MacGetLeftBorderSize() ;
1282 pt
.y
+= MacGetTopBorderSize() ;
1285 if ( x
) *x
= (int) pt
.x
;
1286 if ( y
) *y
= (int) pt
.y
;
1288 if ( !IsTopLevel() )
1291 m_peer
->GetRect( &bounds
) ;
1292 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1293 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1298 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1303 MacRootWindowToWindow( &x1
, &y1
) ;
1308 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1310 RgnHandle rgn
= NewRgn() ;
1312 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1314 GetRegionBounds( rgn
, &content
) ;
1319 m_peer
->GetRect( &content
) ;
1322 m_peer
->GetRect( &structure
) ;
1323 #if !TARGET_API_MAC_OSX
1324 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1326 left
= content
.left
- structure
.left
;
1327 top
= content
.top
- structure
.top
;
1328 right
= structure
.right
- content
.right
;
1329 bottom
= structure
.bottom
- content
.bottom
;
1332 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1334 wxSize sizeTotal
= size
;
1336 RgnHandle rgn
= NewRgn() ;
1340 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1342 GetRegionBounds( rgn
, &content
) ;
1347 m_peer
->GetRect( &content
) ;
1350 m_peer
->GetRect( &structure
) ;
1351 #if !TARGET_API_MAC_OSX
1352 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1355 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1356 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1358 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1359 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1365 // Get size *available for subwindows* i.e. excluding menu bar etc.
1366 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1370 RgnHandle rgn
= NewRgn() ;
1372 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1374 GetRegionBounds( rgn
, &content
) ;
1379 m_peer
->GetRect( &content
) ;
1381 #if !TARGET_API_MAC_OSX
1383 m_peer
->GetRect( &structure
) ;
1384 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1386 ww
= content
.right
- content
.left
;
1387 hh
= content
.bottom
- content
.top
;
1389 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1390 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1393 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1399 GetSize( &w , &h ) ;
1401 MacClientToRootWindow( &x1 , &y1 ) ;
1402 MacClientToRootWindow( &w , &h ) ;
1404 wxWindowMac *iter = (wxWindowMac*)this ;
1406 int totW = 10000 , totH = 10000;
1409 if ( iter->IsTopLevel() )
1411 iter->GetSize( &totW , &totH ) ;
1415 iter = iter->GetParent() ;
1418 if (m_hScrollBar && m_hScrollBar->IsShown() )
1420 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1426 if (m_vScrollBar && m_vScrollBar->IsShown() )
1428 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1436 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1438 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1440 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1442 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1449 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1451 if (m_cursor
== cursor
)
1454 if (wxNullCursor
== cursor
)
1456 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1461 if ( ! wxWindowBase::SetCursor( cursor
) )
1465 wxASSERT_MSG( m_cursor
.Ok(),
1466 wxT("cursor must be valid after call to the base version"));
1469 wxWindowMac
*mouseWin
= 0 ;
1471 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1473 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1475 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1476 // position, use it...
1480 ControlPartCode part
;
1481 ControlRef control
;
1482 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1484 mouseWin
= wxFindControlFromMacControl( control
) ;
1487 QDSwapPort( savePort
, NULL
) ;
1490 if ( mouseWin
== this && !wxIsBusy() )
1492 m_cursor
.MacInstall() ;
1499 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1501 menu
->SetInvokingWindow(this);
1504 if ( x
== -1 && y
== -1 )
1506 wxPoint mouse
= wxGetMousePosition();
1507 x
= mouse
.x
; y
= mouse
.y
;
1511 ClientToScreen( &x
, &y
) ;
1514 menu
->MacBeforeDisplay( true ) ;
1515 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1516 if ( HiWord(menuResult
) != 0 )
1519 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1520 wxMenuItem
* item
= NULL
;
1522 item
= menu
->FindItem(id
, &realmenu
) ;
1523 if (item
->IsCheckable())
1525 item
->Check( !item
->IsChecked() ) ;
1527 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1529 menu
->MacAfterDisplay( true ) ;
1531 menu
->SetInvokingWindow(NULL
);
1537 // ----------------------------------------------------------------------------
1539 // ----------------------------------------------------------------------------
1543 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1545 wxWindowBase::DoSetToolTip(tooltip
);
1548 m_tooltip
->SetWindow(this);
1551 #endif // wxUSE_TOOLTIPS
1553 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1555 // this is never called for a toplevel window, so we know we have a parent
1556 int former_x
, former_y
, former_w
, former_h
;
1558 // Get true coordinates of former position
1559 DoGetPosition( &former_x
, &former_y
) ;
1560 DoGetSize( &former_w
, &former_h
) ;
1562 wxWindow
*parent
= GetParent();
1565 wxPoint
pt(parent
->GetClientAreaOrigin());
1570 int actualWidth
= width
;
1571 int actualHeight
= height
;
1575 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1576 actualWidth
= m_minWidth
;
1577 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1578 actualHeight
= m_minHeight
;
1579 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1580 actualWidth
= m_maxWidth
;
1581 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1582 actualHeight
= m_maxHeight
;
1584 bool doMove
= false ;
1585 bool doResize
= false ;
1587 if ( actualX
!= former_x
|| actualY
!= former_y
)
1591 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1596 if ( doMove
|| doResize
)
1598 // we don't adjust twice for the origin
1599 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1600 #if TARGET_API_MAC_OSX
1601 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1602 if ( ! GetParent()->IsTopLevel() )
1604 r
.left
-= GetParent()->MacGetLeftBorderSize() ;
1605 r
.top
-= GetParent()->MacGetTopBorderSize() ;
1606 r
.right
-= GetParent()->MacGetLeftBorderSize() ;
1607 r
.bottom
-= GetParent()->MacGetTopBorderSize() ;
1610 bool vis
= m_peer
->IsVisible();
1612 int outerBorder
= MacGetLeftBorderSize() ;
1613 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1616 if ( vis
&& ( outerBorder
> 0 ) )
1618 // as the borders are drawn on the parent we have to properly invalidate all these areas
1619 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1623 m_peer
->GetRect( &rect
) ;
1624 RectRgn( updateInner
, &rect
) ;
1625 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1626 RectRgn( updateOuter
, &rect
) ;
1627 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1628 wxPoint
parent(0,0);
1629 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1630 parent
-= GetParent()->GetClientAreaOrigin() ;
1631 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1632 CopyRgn( updateOuter
, updateTotal
) ;
1635 RectRgn( updateInner
, &rect
) ;
1636 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1637 RectRgn( updateOuter
, &rect
) ;
1638 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1639 wxPoint
parentorig(0,0);
1640 GetParent()->MacWindowToRootWindow( &parentorig
.x
, &parentorig
.y
) ;
1641 parent
-= GetParent()->GetClientAreaOrigin() ;
1642 OffsetRgn( updateOuter
, -parentorig
.x
, -parentorig
.y
) ;
1643 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1645 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1646 DisposeRgn(updateOuter
) ;
1647 DisposeRgn(updateInner
) ;
1648 DisposeRgn(updateTotal
) ;
1651 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1653 m_peer
->SetVisibility( false , true ) ;
1655 m_peer
->SetRect( &r
) ;
1657 m_peer
->SetVisibility( true , true ) ;
1659 MacRepositionScrollBars() ;
1662 wxPoint
point(actualX
,actualY
);
1663 wxMoveEvent
event(point
, m_windowId
);
1664 event
.SetEventObject(this);
1665 GetEventHandler()->ProcessEvent(event
) ;
1669 MacRepositionScrollBars() ;
1670 wxSize
size(actualWidth
, actualHeight
);
1671 wxSizeEvent
event(size
, m_windowId
);
1672 event
.SetEventObject(this);
1673 GetEventHandler()->ProcessEvent(event
);
1679 wxSize
wxWindowMac::DoGetBestSize() const
1681 if ( m_macIsUserPane
|| IsTopLevel() )
1682 return wxWindowBase::DoGetBestSize() ;
1684 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1685 int bestWidth
, bestHeight
;
1686 m_peer
->GetBestRect( &bestsize
) ;
1688 if ( EmptyRect( &bestsize
) )
1690 bestsize
.left
= bestsize
.top
= 0 ;
1691 bestsize
.right
= 16 ;
1692 bestsize
.bottom
= 16 ;
1693 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1695 bestsize
.bottom
= 16 ;
1697 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1699 bestsize
.bottom
= 24 ;
1703 // return wxWindowBase::DoGetBestSize() ;
1707 bestWidth
= bestsize
.right
- bestsize
.left
;
1708 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1709 if ( bestHeight
< 10 )
1712 return wxSize(bestWidth
, bestHeight
);
1716 // set the size of the window: if the dimensions are positive, just use them,
1717 // but if any of them is equal to -1, it means that we must find the value for
1718 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1719 // which case -1 is a valid value for x and y)
1721 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1722 // the width/height to best suit our contents, otherwise we reuse the current
1724 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1726 // get the current size and position...
1727 int currentX
, currentY
;
1728 GetPosition(¤tX
, ¤tY
);
1730 int currentW
,currentH
;
1731 GetSize(¤tW
, ¤tH
);
1733 // ... and don't do anything (avoiding flicker) if it's already ok
1734 if ( x
== currentX
&& y
== currentY
&&
1735 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1738 MacRepositionScrollBars() ; // we might have a real position shift
1742 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1744 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1747 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1749 wxSize
size(-1, -1);
1752 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1754 size
= DoGetBestSize();
1759 // just take the current one
1766 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1770 size
= DoGetBestSize();
1772 //else: already called DoGetBestSize() above
1778 // just take the current one
1783 DoMoveWindow(x
, y
, width
, height
);
1787 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1789 RgnHandle rgn
= NewRgn() ;
1791 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1792 GetRegionBounds( rgn
, &content
) ;
1794 #if !TARGET_API_MAC_OSX
1795 // if the content rgn is empty / not supported
1796 // don't attempt to correct the coordinates to wxWindow relative ones
1797 if (!::EmptyRect( &content
) )
1800 m_peer
->GetRect( &structure
) ;
1801 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1805 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1808 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1810 if ( clientheight
!= -1 || clientheight
!= -1 )
1812 int currentclientwidth
, currentclientheight
;
1813 int currentwidth
, currentheight
;
1815 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1816 GetSize( ¤twidth
, ¤theight
) ;
1818 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1819 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1823 void wxWindowMac::SetTitle(const wxString
& title
)
1825 m_label
= wxStripMenuCodes(title
) ;
1827 if ( m_peer
&& m_peer
->Ok() )
1829 m_peer
->SetTitle( m_label
) ;
1834 wxString
wxWindowMac::GetTitle() const
1839 bool wxWindowMac::Show(bool show
)
1841 if ( !wxWindowBase::Show(show
) )
1844 // TODO use visibilityChanged Carbon Event for OSX
1845 bool former
= MacIsReallyShown() ;
1847 m_peer
->SetVisibility( show
, true ) ;
1848 if ( former
!= MacIsReallyShown() )
1849 MacPropagateVisibilityChanged() ;
1853 bool wxWindowMac::Enable(bool enable
)
1855 wxASSERT( m_peer
->Ok() ) ;
1856 if ( !wxWindowBase::Enable(enable
) )
1859 bool former
= MacIsReallyEnabled() ;
1860 m_peer
->Enable( enable
) ;
1862 if ( former
!= MacIsReallyEnabled() )
1863 MacPropagateEnabledStateChanged() ;
1868 // status change propagations (will be not necessary for OSX later )
1871 void wxWindowMac::MacPropagateVisibilityChanged()
1873 #if !TARGET_API_MAC_OSX
1874 MacVisibilityChanged() ;
1876 wxWindowListNode
*node
= GetChildren().GetFirst();
1879 wxWindowMac
*child
= node
->GetData();
1880 if ( child
->IsShown() )
1881 child
->MacPropagateVisibilityChanged( ) ;
1882 node
= node
->GetNext();
1887 void wxWindowMac::MacPropagateEnabledStateChanged( )
1889 #if !TARGET_API_MAC_OSX
1890 MacEnabledStateChanged() ;
1892 wxWindowListNode
*node
= GetChildren().GetFirst();
1895 wxWindowMac
*child
= node
->GetData();
1896 if ( child
->IsEnabled() )
1897 child
->MacPropagateEnabledStateChanged() ;
1898 node
= node
->GetNext();
1903 void wxWindowMac::MacPropagateHiliteChanged( )
1905 #if !TARGET_API_MAC_OSX
1906 MacHiliteChanged() ;
1908 wxWindowListNode
*node
= GetChildren().GetFirst();
1911 wxWindowMac
*child
= node
->GetData();
1912 // if ( child->IsEnabled() )
1913 child
->MacPropagateHiliteChanged() ;
1914 node
= node
->GetNext();
1920 // status change notifications
1923 void wxWindowMac::MacVisibilityChanged()
1927 void wxWindowMac::MacHiliteChanged()
1931 void wxWindowMac::MacEnabledStateChanged()
1936 // status queries on the inherited window's state
1939 bool wxWindowMac::MacIsReallyShown()
1941 // only under OSX the visibility of the TLW is taken into account
1942 #if TARGET_API_MAC_OSX
1943 if ( m_peer
&& m_peer
->Ok() )
1944 return m_peer
->IsVisible();
1946 wxWindow
* win
= this ;
1947 while( win
->IsShown() )
1949 if ( win
->IsTopLevel() )
1952 win
= win
->GetParent() ;
1960 bool wxWindowMac::MacIsReallyEnabled()
1962 return m_peer
->IsEnabled() ;
1965 bool wxWindowMac::MacIsReallyHilited()
1967 return m_peer
->IsActive();
1970 void wxWindowMac::MacFlashInvalidAreas()
1972 #if TARGET_API_MAC_OSX
1973 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1981 int wxWindowMac::GetCharHeight() const
1983 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1984 return dc
.GetCharHeight() ;
1987 int wxWindowMac::GetCharWidth() const
1989 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1990 return dc
.GetCharWidth() ;
1993 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1994 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1996 const wxFont
*fontToUse
= theFont
;
1998 fontToUse
= &m_font
;
2000 wxClientDC
dc( (wxWindowMac
*) this ) ;
2002 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2003 if ( externalLeading
)
2004 *externalLeading
= le
;
2014 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2015 * we always intersect with the entire window, not only with the client area
2018 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2020 if ( m_peer
== NULL
)
2023 #if TARGET_API_MAC_OSX
2025 m_peer
->SetNeedsDisplay( true ) ;
2028 RgnHandle update
= NewRgn() ;
2029 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2030 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2031 wxPoint origin
= GetClientAreaOrigin() ;
2032 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2033 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2035 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2036 m_peer
->SetNeedsDisplay( true , update
) ;
2037 DisposeRgn( update
) ;
2041 RgnHandle updateRgn = NewRgn() ;
2044 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2048 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2049 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2051 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2052 DisposeRgn(updateRgn) ;
2054 if ( m_peer
->IsVisible())
2056 m_peer
->SetVisibility( false , false ) ;
2057 m_peer
->SetVisibility( true , true ) ;
2060 if ( MacGetTopLevelWindow() == NULL )
2063 if ( !m_peer->IsVisible())
2066 wxPoint client = GetClientAreaOrigin();
2069 int x2 = m_width - client.x;
2070 int y2 = m_height - client.y;
2072 if (IsKindOf( CLASSINFO(wxButton)))
2074 // buttons have an "aura"
2081 Rect clientrect = { y1, x1, y2, x2 };
2085 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2086 SectRect( &clientrect , &r , &clientrect ) ;
2089 if ( !EmptyRect( &clientrect ) )
2091 int top = 0 , left = 0 ;
2093 MacClientToRootWindow( &left , &top ) ;
2094 OffsetRect( &clientrect , left , top ) ;
2096 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2102 void wxWindowMac::Freeze()
2104 #if TARGET_API_MAC_OSX
2105 if ( !m_frozenness
++ )
2107 m_peer
->SetDrawingEnabled( false ) ;
2113 void wxWindowMac::Thaw()
2115 #if TARGET_API_MAC_OSX
2116 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2118 if ( !--m_frozenness
)
2120 m_peer
->SetDrawingEnabled( true ) ;
2121 m_peer
->InvalidateWithChildren() ;
2126 void wxWindowMac::MacRedrawControl()
2129 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2131 #if TARGET_API_MAC_CARBON
2134 wxClientDC dc(this) ;
2135 wxMacPortSetter helper(&dc) ;
2136 wxMacWindowClipper clipper(this) ;
2137 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2138 UMADrawControl( *m_peer ) ;
2145 void wxWindowMac::OnPaint(wxPaintEvent& event)
2147 // why don't we skip that here ?
2151 wxWindowMac
*wxGetActiveWindow()
2153 // actually this is a windows-only concept
2157 // Coordinates relative to the window
2158 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2160 // We really don't move the mouse programmatically under Mac.
2163 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2165 #if TARGET_API_MAC_OSX
2166 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2172 event
.GetDC()->Clear() ;
2175 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2180 int wxWindowMac::GetScrollPos(int orient
) const
2182 if ( orient
== wxHORIZONTAL
)
2185 return m_hScrollBar
->GetThumbPosition() ;
2190 return m_vScrollBar
->GetThumbPosition() ;
2195 // This now returns the whole range, not just the number
2196 // of positions that we can scroll.
2197 int wxWindowMac::GetScrollRange(int orient
) const
2199 if ( orient
== wxHORIZONTAL
)
2202 return m_hScrollBar
->GetRange() ;
2207 return m_vScrollBar
->GetRange() ;
2212 int wxWindowMac::GetScrollThumb(int orient
) const
2214 if ( orient
== wxHORIZONTAL
)
2217 return m_hScrollBar
->GetThumbSize() ;
2222 return m_vScrollBar
->GetThumbSize() ;
2227 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2229 if ( orient
== wxHORIZONTAL
)
2232 m_hScrollBar
->SetThumbPosition( pos
) ;
2237 m_vScrollBar
->SetThumbPosition( pos
) ;
2241 void wxWindowMac::MacPaintBorders( int left
, int top
)
2247 m_peer
->GetRect( &rect
) ;
2248 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2250 if ( !IsTopLevel() )
2252 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2256 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2258 rect
.right
+= pt
.x
;
2260 rect
.bottom
+= pt
.y
;
2264 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2268 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2269 InsetRect( &srect
, border
, border
);
2270 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2272 else if (HasFlag(wxSIMPLE_BORDER
))
2276 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2277 InsetRect( &srect
, border
, border
);
2278 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2282 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2284 if ( child
== m_hScrollBar
)
2285 m_hScrollBar
= NULL
;
2286 if ( child
== m_vScrollBar
)
2287 m_vScrollBar
= NULL
;
2289 wxWindowBase::RemoveChild( child
) ;
2292 // New function that will replace some of the above.
2293 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2294 int range
, bool refresh
)
2296 if ( orient
== wxHORIZONTAL
)
2300 if ( range
== 0 || thumbVisible
>= range
)
2302 if ( m_hScrollBar
->IsShown() )
2303 m_hScrollBar
->Show(false) ;
2307 if ( !m_hScrollBar
->IsShown() )
2308 m_hScrollBar
->Show(true) ;
2309 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2317 if ( range
== 0 || thumbVisible
>= range
)
2319 if ( m_vScrollBar
->IsShown() )
2320 m_vScrollBar
->Show(false) ;
2324 if ( !m_vScrollBar
->IsShown() )
2325 m_vScrollBar
->Show(true) ;
2326 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2330 MacRepositionScrollBars() ;
2333 // Does a physical scroll
2334 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2336 if( dx
== 0 && dy
==0 )
2342 int width
, height
;
2343 GetClientSize( &width
, &height
) ;
2344 #if TARGET_API_MAC_OSX
2345 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2346 // area is scrolled, this does not occur if width and height are 2 pixels less,
2347 // TODO write optimal workaround
2348 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2351 scrollrect
.Intersect( *rect
) ;
2353 if ( m_peer
->GetNeedsDisplay() )
2355 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2356 // either immediate redraw or full invalidate
2358 // is the better overall solution, as it does not slow down scrolling
2359 m_peer
->SetNeedsDisplay( true ) ;
2361 // this would be the preferred version for fast drawing controls
2362 if( UMAGetSystemVersion() < 0x1030 )
2365 HIViewRender(m_peer
->GetControlRef()) ;
2368 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2369 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2370 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2377 RgnHandle updateRgn
= NewRgn() ;
2380 wxClientDC
dc(this) ;
2381 wxMacPortSetter
helper(&dc
) ;
2383 m_peer
->GetRect( &scrollrect
) ;
2384 scrollrect
.top
+= MacGetTopBorderSize() ;
2385 scrollrect
.left
+= MacGetLeftBorderSize() ;
2386 scrollrect
.bottom
= scrollrect
.top
+ height
;
2387 scrollrect
.right
= scrollrect
.left
+ width
;
2391 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2392 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2393 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2395 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2397 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2401 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2403 wxWindowMac
*child
= node
->GetData();
2404 if (child
== m_vScrollBar
) continue;
2405 if (child
== m_hScrollBar
) continue;
2406 if (child
->IsTopLevel()) continue;
2409 child
->GetPosition( &x
, &y
);
2411 child
->GetSize( &w
, &h
);
2415 if (rect
->Intersects(rc
))
2416 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2420 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2425 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2427 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2429 wxScrollWinEvent wevent
;
2430 wevent
.SetPosition(event
.GetPosition());
2431 wevent
.SetOrientation(event
.GetOrientation());
2432 wevent
.m_eventObject
= this;
2434 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2435 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2436 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2437 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2438 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2439 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2440 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2441 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2442 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2443 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2444 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2445 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2446 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2447 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2448 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2449 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2451 GetEventHandler()->ProcessEvent(wevent
);
2455 // Get the window with the focus
2456 wxWindowMac
*wxWindowBase::FindFocus()
2458 ControlRef control
;
2459 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2460 return wxFindControlFromMacControl( control
) ;
2463 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2465 // panel wants to track the window which was the last to have focus in it,
2466 // so we want to set ourselves as the window which last had focus
2468 // notice that it's also important to do it upwards the tree becaus
2469 // otherwise when the top level panel gets focus, it won't set it back to
2470 // us, but to some other sibling
2472 // CS:don't know if this is still needed:
2473 //wxChildFocusEvent eventFocus(this);
2474 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2476 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2478 wxMacWindowStateSaver
sv( this ) ;
2483 MacWindowToRootWindow( &x
, &y
) ;
2484 GetSize( &w
, &h
) ;
2485 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2487 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2488 DrawThemeFocusRect( &rect
, true ) ;
2491 DrawThemeFocusRect( &rect
, false ) ;
2493 // as this erases part of the frame we have to redraw borders
2494 // and because our z-ordering is not always correct (staticboxes)
2495 // we have to invalidate things, we cannot simple redraw
2496 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2497 RectRgn( updateInner
, &rect
) ;
2498 InsetRect( &rect
, -4 , -4 ) ;
2499 RectRgn( updateOuter
, &rect
) ;
2500 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2501 wxPoint
parent(0,0);
2502 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2503 parent
-= GetParent()->GetClientAreaOrigin() ;
2504 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2505 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2506 DisposeRgn(updateOuter
) ;
2507 DisposeRgn(updateInner
) ;
2514 void wxWindowMac::OnInternalIdle()
2516 // This calls the UI-update mechanism (querying windows for
2517 // menu/toolbar/control state information)
2518 if (wxUpdateUIEvent::CanUpdate(this))
2519 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2522 // Raise the window to the top of the Z order
2523 void wxWindowMac::Raise()
2525 m_peer
->SetZOrder( true , NULL
) ;
2528 // Lower the window to the bottom of the Z order
2529 void wxWindowMac::Lower()
2531 m_peer
->SetZOrder( false , NULL
) ;
2535 // static wxWindow *gs_lastWhich = NULL;
2537 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2539 // first trigger a set cursor event
2541 wxPoint clientorigin
= GetClientAreaOrigin() ;
2542 wxSize clientsize
= GetClientSize() ;
2544 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2546 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2548 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2549 if ( processedEvtSetCursor
&& event
.HasCursor() )
2551 cursor
= event
.GetCursor() ;
2556 // the test for processedEvtSetCursor is here to prevent using m_cursor
2557 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2558 // it - this is a way to say that our cursor shouldn't be used for this
2560 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2570 cursor
= *wxSTANDARD_CURSOR
;
2574 cursor
.MacInstall() ;
2576 return cursor
.Ok() ;
2579 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2583 return m_tooltip
->GetTip() ;
2585 return wxEmptyString
;
2588 void wxWindowMac::Update()
2590 #if TARGET_API_MAC_OSX
2591 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2592 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2593 // for composited windows this also triggers a redraw of all
2594 // invalid views in the window
2595 if( UMAGetSystemVersion() >= 0x1030 )
2596 HIWindowFlush(window
) ;
2600 // the only way to trigger the redrawing on earlier systems is to call
2603 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2604 UInt32 currentEventClass
= 0 ;
2605 UInt32 currentEventKind
= 0 ;
2606 if ( currentEvent
!= NULL
)
2608 currentEventClass
= ::GetEventClass( currentEvent
) ;
2609 currentEventKind
= ::GetEventKind( currentEvent
) ;
2611 if ( currentEventClass
!= kEventClassMenu
)
2613 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2616 OSStatus status
= noErr
;
2617 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2620 m_peer
->SetNeedsDisplay( true ) ;
2623 ::Draw1Control( m_peer
->GetControlRef() ) ;
2627 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2629 wxTopLevelWindowMac
* win
= NULL
;
2630 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2633 win
= wxFindWinFromMacWindow( window
) ;
2637 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2639 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2640 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2641 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2642 // to add focus borders everywhere
2645 RgnHandle visRgn
= NewRgn() ;
2646 RgnHandle tempRgn
= NewRgn() ;
2647 if ( m_peer
->IsVisible())
2649 m_peer
->GetRect( &r
) ;
2650 r
.left
-= MacGetLeftBorderSize() ;
2651 r
.top
-= MacGetTopBorderSize() ;
2652 r
.bottom
+= MacGetBottomBorderSize() ;
2653 r
.right
+= MacGetRightBorderSize() ;
2655 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2657 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2658 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2667 if ( includeOuterStructures
)
2668 InsetRect( &r
, -4 , -4 ) ;
2669 RectRgn( visRgn
, &r
) ;
2671 if ( !IsTopLevel() )
2673 wxWindow
* child
= this ;
2674 wxWindow
* parent
= child
->GetParent() ;
2679 // we have to find a better clipping algorithm here, in order not to clip things
2680 // positioned like status and toolbar
2681 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2683 size
= parent
->GetSize() ;
2688 size
= parent
->GetClientSize() ;
2689 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2693 parent
->MacWindowToRootWindow( &x
, &y
) ;
2694 MacRootWindowToWindow( &x
, &y
) ;
2696 if ( !includeOuterStructures
|| (
2697 parent
->IsKindOf( CLASSINFO( wxScrolledWindow
) ) ||
2698 parent
->IsKindOf( CLASSINFO( wxSashLayoutWindow
) ) ||
2699 ( parent
->GetParent() && parent
->GetParent()->IsKindOf( CLASSINFO( wxSplitterWindow
) ) )
2702 SetRectRgn( tempRgn
,
2703 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2704 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2705 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2707 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2709 if ( parent
->IsTopLevel() )
2712 parent
= child
->GetParent() ;
2717 wxRegion vis
= visRgn
;
2718 DisposeRgn( visRgn
) ;
2719 DisposeRgn( tempRgn
) ;
2724 This function must not change the updatergn !
2726 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2728 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2729 bool handled
= false ;
2731 GetRegionBounds( updatergn
, &updatebounds
) ;
2732 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2733 if ( !EmptyRgn(updatergn
) )
2735 RgnHandle newupdate
= NewRgn() ;
2736 wxSize point
= GetClientSize() ;
2737 wxPoint origin
= GetClientAreaOrigin() ;
2738 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2739 SectRgn( newupdate
, updatergn
, newupdate
) ;
2741 // first send an erase event to the entire update area
2743 wxWindowDC
dc(this);
2744 dc
.SetClippingRegion(wxRegion(updatergn
));
2745 wxEraseEvent
eevent( GetId(), &dc
);
2746 eevent
.SetEventObject( this );
2747 GetEventHandler()->ProcessEvent( eevent
);
2750 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2751 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2752 m_updateRegion
= newupdate
;
2753 DisposeRgn( newupdate
) ;
2755 if ( !m_updateRegion
.Empty() )
2757 // paint the window itself
2759 event
.m_timeStamp
= time
;
2760 event
.SetEventObject(this);
2761 handled
= GetEventHandler()->ProcessEvent(event
);
2763 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2766 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2768 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2775 // now we cannot rely on having its borders drawn by a window itself, as it does not
2776 // get the updateRgn wide enough to always do so, so we do it from the parent
2777 // this would also be the place to draw any custom backgrounds for native controls
2778 // in Composited windowing
2779 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2781 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2783 wxWindowMac
*child
= node
->GetData();
2784 if (child
== m_vScrollBar
) continue;
2785 if (child
== m_hScrollBar
) continue;
2786 if (child
->IsTopLevel()) continue;
2787 if (!child
->IsShown()) continue;
2790 child
->GetPosition( &x
, &y
);
2792 child
->GetSize( &w
, &h
);
2793 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2794 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2795 if ( child
->MacGetTopBorderSize() )
2797 if ( RectInRgn( &childRect
, updatergn
) )
2799 // paint custom borders
2800 wxNcPaintEvent
eventNc( child
->GetId() );
2801 eventNc
.SetEventObject( child
);
2802 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2804 wxWindowDC
dc(this) ;
2805 dc
.SetClippingRegion(wxRegion(updatergn
));
2806 wxMacPortSetter
helper(&dc
) ;
2807 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2811 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2813 wxWindowDC
dc(this) ;
2814 dc
.SetClippingRegion(wxRegion(updatergn
));
2815 wxMacPortSetter
helper(&dc
) ;
2816 OffsetRect( &childRect
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2817 DrawThemeFocusRect( &childRect
, true ) ;
2824 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2826 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2827 // updatergn is always already clipped to our boundaries
2828 // if we are in compositing mode then it is in relative to the upper left of the control
2829 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2830 // of the toplevel window
2831 // it is in window coordinates, not in client coordinates
2833 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2834 RgnHandle ownUpdateRgn
= NewRgn() ;
2835 CopyRgn( updatergn
, ownUpdateRgn
) ;
2837 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2840 m_peer
->GetRectInWindowCoords( &bounds
);
2841 RgnHandle controlRgn
= NewRgn();
2842 RectRgn( controlRgn
, &bounds
);
2843 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2844 // the window update region
2845 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2846 DisposeRgn( controlRgn
);
2848 //KO: convert ownUpdateRgn to local coordinates
2849 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2852 MacDoRedraw( ownUpdateRgn
, time
) ;
2853 DisposeRgn( ownUpdateRgn
) ;
2857 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2859 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2863 if ( iter
->IsTopLevel() )
2864 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2866 iter
= iter
->GetParent() ;
2868 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2872 void wxWindowMac::MacCreateScrollBars( long style
)
2874 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2876 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2878 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2879 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2880 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2881 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2883 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2884 variant
= wxWINDOW_VARIANT_SMALL
;
2887 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2889 GetClientSize( &width
, &height
) ;
2891 wxPoint
vPoint(width
-scrlsize
, 0) ;
2892 wxSize
vSize(scrlsize
, height
- adjust
) ;
2893 wxPoint
hPoint(0 , height
-scrlsize
) ;
2894 wxSize
hSize( width
- adjust
, scrlsize
) ;
2897 if ( style
& wxVSCROLL
)
2899 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2900 vSize
, wxVERTICAL
);
2903 if ( style
& wxHSCROLL
)
2905 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2906 hSize
, wxHORIZONTAL
);
2911 // because the create does not take into account the client area origin
2912 MacRepositionScrollBars() ; // we might have a real position shift
2915 void wxWindowMac::MacRepositionScrollBars()
2917 if ( !m_hScrollBar
&& !m_vScrollBar
)
2920 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2921 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2922 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2924 // get real client area
2928 GetSize( &width
, &height
) ;
2930 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2931 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2933 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2934 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2935 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2936 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2942 GetSize( &w , &h ) ;
2944 MacClientToRootWindow( &x , &y ) ;
2945 MacClientToRootWindow( &w , &h ) ;
2947 wxWindowMac *iter = (wxWindowMac*)this ;
2949 int totW = 10000 , totH = 10000;
2952 if ( iter->IsTopLevel() )
2954 iter->GetSize( &totW , &totH ) ;
2958 iter = iter->GetParent() ;
2986 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2990 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2994 bool wxWindowMac::AcceptsFocus() const
2996 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2999 void wxWindowMac::MacSuperChangedPosition()
3001 // only window-absolute structures have to be moved i.e. controls
3003 wxWindowListNode
*node
= GetChildren().GetFirst();
3006 wxWindowMac
*child
= node
->GetData();
3007 child
->MacSuperChangedPosition() ;
3008 node
= node
->GetNext();
3012 void wxWindowMac::MacTopLevelWindowChangedPosition()
3014 // only screen-absolute structures have to be moved i.e. glcanvas
3016 wxWindowListNode
*node
= GetChildren().GetFirst();
3019 wxWindowMac
*child
= node
->GetData();
3020 child
->MacTopLevelWindowChangedPosition() ;
3021 node
= node
->GetNext();
3025 long wxWindowMac::MacGetLeftBorderSize( ) const
3030 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3035 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3040 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3047 long wxWindowMac::MacGetRightBorderSize( ) const
3049 // they are all symmetric in mac themes
3050 return MacGetLeftBorderSize() ;
3053 long wxWindowMac::MacGetTopBorderSize( ) const
3055 // they are all symmetric in mac themes
3056 return MacGetLeftBorderSize() ;
3059 long wxWindowMac::MacGetBottomBorderSize( ) const
3061 // they are all symmetric in mac themes
3062 return MacGetLeftBorderSize() ;
3065 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3067 return style
& ~wxBORDER_MASK
;
3070 // Find the wxWindowMac at the current mouse position, returning the mouse
3072 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3074 pt
= wxGetMousePosition();
3075 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3079 // Get the current mouse position.
3080 wxPoint
wxGetMousePosition()
3083 wxGetMousePosition(& x
, & y
);
3084 return wxPoint(x
, y
);
3087 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3089 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3091 // copied from wxGTK : CS
3092 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3095 // (a) it's a command event and so is propagated to the parent
3096 // (b) under MSW it can be generated from kbd too
3097 // (c) it uses screen coords (because of (a))
3098 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3100 this->ClientToScreen(event
.GetPosition()));
3101 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3110 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3114 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3118 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3119 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3123 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3125 return eventNotHandledErr
;