1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
16 #include "wx/wxprec.h"
19 #include "wx/window.h"
21 #include "wx/dcclient.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.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"
41 #include "wx/toolbar.h"
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 #if TARGET_API_MAC_OSX
85 EVT_PAINT(wxWindowMac::OnPaint
)
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
120 // originating from native control
124 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
126 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
131 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
135 // directed towards native control
138 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
140 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
143 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
145 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
154 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
156 #if TARGET_API_MAC_OSX
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
160 kEventControlVisibilityChanged
= 157
166 static const EventTypeSpec eventList
[] =
168 { kEventClassControl
, kEventControlHit
} ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl
, kEventControlDraw
} ,
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
174 { kEventClassControl
, kEventControlSetFocusPart
} ,
176 { kEventClassService
, kEventServiceGetTypes
},
177 { kEventClassService
, kEventServiceCopy
},
178 { kEventClassService
, kEventServicePaste
},
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 // as this update region is in native window locals we must adapt it to wx window local
213 allocatedRgn
= NewRgn() ;
214 CopyRgn( updateRgn
, allocatedRgn
) ;
215 // hide the given region by the new region that must be shifted
216 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
217 updateRgn
= allocatedRgn
;
221 #if wxMAC_DEBUG_REDRAW
222 if ( thisWindow
->MacIsUserPane() )
224 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
225 static float color
= 0.5 ;
228 HIViewGetBounds( controlRef
, &bounds
);
229 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
230 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
231 CGContextFillRect( cgContext
, bounds
);
243 #if wxMAC_USE_CORE_GRAPHICS
244 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
245 thisWindow
->MacSetCGContextRef( cgContext
) ;
246 wxMacCGContextStateSaver
sg( cgContext
) ;
248 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
250 #if wxMAC_USE_CORE_GRAPHICS
251 thisWindow
->MacSetCGContextRef( NULL
) ;
255 DisposeRgn( allocatedRgn
) ;
258 case kEventControlVisibilityChanged
:
259 thisWindow
->MacVisibilityChanged() ;
261 case kEventControlEnabledStateChanged
:
262 thisWindow
->MacEnabledStateChanged() ;
264 case kEventControlHiliteChanged
:
265 thisWindow
->MacHiliteChanged() ;
268 // we emulate this event under Carbon CFM
269 case kEventControlSetFocusPart
:
271 Boolean focusEverything
= false ;
272 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
274 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
278 if ( controlPart
== kControlFocusNoPart
)
281 if ( thisWindow
->GetCaret() )
283 thisWindow
->GetCaret()->OnKillFocus();
285 #endif // wxUSE_CARET
286 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
287 event
.SetEventObject(thisWindow
);
288 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
292 // panel wants to track the window which was the last to have focus in it
293 wxChildFocusEvent
eventFocus(thisWindow
);
294 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
297 if ( thisWindow
->GetCaret() )
299 thisWindow
->GetCaret()->OnSetFocus();
301 #endif // wxUSE_CARET
303 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
304 event
.SetEventObject(thisWindow
);
305 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
307 if ( thisWindow
->MacIsUserPane() )
311 case kEventControlHit
:
313 result
= thisWindow
->MacControlHit( handler
, event
) ;
322 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
324 OSStatus result
= eventNotHandledErr
;
326 wxMacCarbonEvent
cEvent( event
) ;
328 ControlRef controlRef
;
329 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
330 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
331 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
333 switch( GetEventKind( event
) )
335 case kEventServiceGetTypes
:
339 textCtrl
->GetSelection( &from
, &to
) ;
341 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
343 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
344 if ( textCtrl
->IsEditable() )
345 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
347 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
348 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
350 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
354 CFArrayAppendValue (copyTypes
, typestring
) ;
356 CFArrayAppendValue (pasteTypes
, typestring
) ;
357 CFRelease( typestring
) ;
363 case kEventServiceCopy
:
367 textCtrl
->GetSelection( &from
, &to
) ;
368 wxString val
= textCtrl
->GetValue() ;
369 val
= val
.Mid( from
, to
- from
) ;
370 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
371 verify_noerr( ClearScrap( &scrapRef
) ) ;
372 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
376 case kEventServicePaste
:
379 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
380 Size textSize
, pastedSize
;
381 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
383 char *content
= new char[textSize
] ;
384 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
385 content
[textSize
-1] = 0 ;
387 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
389 textCtrl
->WriteText( wxString( content
) ) ;
400 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
402 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
403 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
404 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
405 OSStatus result
= eventNotHandledErr
;
407 switch ( GetEventClass( event
) )
409 case kEventClassControl
:
410 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
412 case kEventClassService
:
413 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
417 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
421 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
423 #if !TARGET_API_MAC_OSX
425 // ---------------------------------------------------------------------------
426 // UserPane events for non OSX builds
427 // ---------------------------------------------------------------------------
429 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
431 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
433 win
->MacControlUserPaneDrawProc(part
) ;
435 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
437 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
439 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
441 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
443 return kControlNoPart
;
445 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
447 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
449 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
451 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
453 return kControlNoPart
;
455 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
457 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
459 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
461 win
->MacControlUserPaneIdleProc() ;
463 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
465 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
467 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
469 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
471 return kControlNoPart
;
473 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
475 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
477 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
479 win
->MacControlUserPaneActivateProc(activating
) ;
481 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
483 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
485 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
487 return win
->MacControlUserPaneFocusProc(action
) ;
489 return kControlNoPart
;
491 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
493 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
495 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
497 win
->MacControlUserPaneBackgroundProc(info
) ;
499 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
501 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
503 RgnHandle rgn
= NewRgn() ;
505 wxMacWindowStateSaver
sv( this ) ;
506 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
507 MacDoRedraw( rgn
, 0 ) ;
511 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
513 return kControlNoPart
;
516 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
518 return kControlNoPart
;
521 void wxWindowMac::MacControlUserPaneIdleProc()
525 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
527 return kControlNoPart
;
530 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
534 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
536 return kControlNoPart
;
539 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
545 // ---------------------------------------------------------------------------
546 // Scrollbar Tracking for all
547 // ---------------------------------------------------------------------------
549 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
550 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
554 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
557 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
561 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
563 // ===========================================================================
565 // ===========================================================================
567 #if KEY_wxList_DEPRECATED
568 wxList
wxWinMacControlList(wxKEY_INTEGER
);
570 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
572 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
575 return (wxControl
*)node
->GetData();
578 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
580 // adding NULL ControlRef is (first) surely a result of an error and
581 // (secondly) breaks native event processing
582 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
584 if ( !wxWinMacControlList
.Find((long)inControl
) )
585 wxWinMacControlList
.Append((long)inControl
, control
);
588 void wxRemoveMacControlAssociation(wxWindow
*control
)
590 wxWinMacControlList
.DeleteObject(control
);
594 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
596 static MacControlMap wxWinMacControlList
;
598 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
600 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
602 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
605 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
607 // adding NULL ControlRef is (first) surely a result of an error and
608 // (secondly) breaks native event processing
609 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
611 wxWinMacControlList
[inControl
] = control
;
614 void wxRemoveMacControlAssociation(wxWindow
*control
)
616 // iterate over all the elements in the class
617 MacControlMap::iterator it
;
618 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
620 if ( it
->second
== control
)
622 wxWinMacControlList
.erase(it
);
627 #endif // deprecated wxList
629 // ----------------------------------------------------------------------------
630 // constructors and such
631 // ----------------------------------------------------------------------------
633 wxWindowMac::wxWindowMac()
638 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
643 const wxString
& name
)
646 Create(parent
, id
, pos
, size
, style
, name
);
649 void wxWindowMac::Init()
653 #if WXWIN_COMPATIBILITY_2_4
654 m_backgroundTransparent
= FALSE
;
657 // as all windows are created with WS_VISIBLE style...
660 m_hScrollBar
= NULL
;
661 m_vScrollBar
= NULL
;
662 m_macBackgroundBrush
= wxNullBrush
;
664 m_macIsUserPane
= TRUE
;
665 #if wxMAC_USE_CORE_GRAPHICS
666 m_cgContextRef
= NULL
;
668 // we need a valid font for the encodings
669 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
673 wxWindowMac::~wxWindowMac()
677 m_isBeingDeleted
= TRUE
;
679 MacInvalidateBorders() ;
681 #ifndef __WXUNIVERSAL__
682 // VS: make sure there's no wxFrame with last focus set to us:
683 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
685 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
688 if ( frame
->GetLastFocus() == this )
690 frame
->SetLastFocus((wxWindow
*)NULL
);
695 #endif // __WXUNIVERSAL__
697 // destroy children before destroying this window itself
700 // wxRemoveMacControlAssociation( this ) ;
701 // If we delete an item, we should initialize the parent panel,
702 // because it could now be invalid.
703 wxWindow
*parent
= GetParent() ;
706 if (parent
->GetDefaultItem() == (wxButton
*) this)
707 parent
->SetDefaultItem(NULL
);
709 if ( m_peer
&& m_peer
->Ok() )
711 // in case the callback might be called during destruction
712 wxRemoveMacControlAssociation( this) ;
713 // we currently are not using this hook
714 // ::SetControlColorProc( *m_peer , NULL ) ;
718 if ( g_MacLastWindow
== this )
720 g_MacLastWindow
= NULL
;
723 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
726 if ( frame
->GetLastFocus() == this )
727 frame
->SetLastFocus( NULL
) ;
730 // delete our drop target if we've got one
731 #if wxUSE_DRAG_AND_DROP
732 if ( m_dropTarget
!= NULL
)
737 #endif // wxUSE_DRAG_AND_DROP
741 WXWidget
wxWindowMac::GetHandle() const
743 return (WXWidget
) m_peer
->GetControlRef() ;
747 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
749 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
750 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
751 GetEventTypeCount(eventList
), eventList
, this,
752 (EventHandlerRef
*)&m_macControlEventHandler
);
753 #if !TARGET_API_MAC_OSX
754 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
756 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
757 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
758 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
759 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
760 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
761 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
762 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
763 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
770 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
774 const wxString
& name
)
776 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
778 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
781 m_windowVariant
= parent
->GetWindowVariant() ;
783 if ( m_macIsUserPane
)
785 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
788 | kControlSupportsEmbedding
789 | kControlSupportsLiveFeedback
790 | kControlGetsFocusOnClick
791 // | kControlHasSpecialBackground
792 // | kControlSupportsCalcBestRect
793 | kControlHandlesTracking
794 | kControlSupportsFocus
795 | kControlWantsActivate
799 m_peer
= new wxMacControl(this) ;
800 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
803 MacPostControlCreate(pos
,size
) ;
805 #ifndef __WXUNIVERSAL__
806 // Don't give scrollbars to wxControls unless they ask for them
807 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
808 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
810 MacCreateScrollBars( style
) ;
814 wxWindowCreateEvent
event(this);
815 GetEventHandler()->AddPendingEvent(event
);
820 void wxWindowMac::MacChildAdded()
824 m_vScrollBar
->Raise() ;
828 m_hScrollBar
->Raise() ;
833 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
835 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
837 m_peer
->SetReference( (long) this ) ;
838 GetParent()->AddChild(this);
840 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
842 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
843 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
844 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
845 GetParent()->MacChildAdded() ;
847 // adjust font, controlsize etc
848 DoSetWindowVariant( m_windowVariant
) ;
850 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
852 if (!m_macIsUserPane
)
854 SetInitialBestSize(size
);
857 SetCursor( *wxSTANDARD_CURSOR
) ;
860 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
862 // Don't assert, in case we set the window variant before
863 // the window is created
864 // wxASSERT( m_peer->Ok() ) ;
866 m_windowVariant
= variant
;
868 if (m_peer
== NULL
|| !m_peer
->Ok())
872 ThemeFontID themeFont
= kThemeSystemFont
;
874 // we will get that from the settings later
875 // and make this NORMAL later, but first
876 // we have a few calculations that we must fix
880 case wxWINDOW_VARIANT_NORMAL
:
881 size
= kControlSizeNormal
;
882 themeFont
= kThemeSystemFont
;
884 case wxWINDOW_VARIANT_SMALL
:
885 size
= kControlSizeSmall
;
886 themeFont
= kThemeSmallSystemFont
;
888 case wxWINDOW_VARIANT_MINI
:
889 if (UMAGetSystemVersion() >= 0x1030 )
891 // not always defined in the headers
897 size
= kControlSizeSmall
;
898 themeFont
= kThemeSmallSystemFont
;
901 case wxWINDOW_VARIANT_LARGE
:
902 size
= kControlSizeLarge
;
903 themeFont
= kThemeSystemFont
;
906 wxFAIL_MSG(_T("unexpected window variant"));
909 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
912 font
.MacCreateThemeFont( themeFont
) ;
916 void wxWindowMac::MacUpdateControlFont()
918 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
922 bool wxWindowMac::SetFont(const wxFont
& font
)
924 bool retval
= wxWindowBase::SetFont( font
) ;
926 MacUpdateControlFont() ;
931 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
933 if ( !wxWindowBase::SetForegroundColour(col
) )
936 MacUpdateControlFont() ;
941 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
943 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
947 wxColour
newCol(GetBackgroundColour());
948 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
950 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
952 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
954 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
958 brush
.SetColour( newCol
) ;
960 MacSetBackgroundBrush( brush
) ;
962 MacUpdateControlFont() ;
967 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
969 m_macBackgroundBrush
= brush
;
970 m_peer
->SetBackground( brush
) ;
973 bool wxWindowMac::MacCanFocus() const
975 // there is currently no way to determine whether the window is running in full keyboard
976 // access mode, therefore we cannot rely on these features, yet the only other way would be
977 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
978 // in event handlers...
979 UInt32 features
= 0 ;
980 m_peer
->GetFeatures( & features
) ;
981 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
985 void wxWindowMac::SetFocus()
987 if ( AcceptsFocus() )
990 wxWindow
* former
= FindFocus() ;
991 if ( former
== this )
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
1077 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1080 // From a wx position / size calculate the appropriate size of the native control
1082 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1085 int& w
, int& h
, bool adjustOrigin
) const
1087 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1089 // the desired size, minus the border pixels gives the correct size of the control
1093 // todo the default calls may be used as soon as PostCreateControl Is moved here
1094 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1095 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1097 if ( !isCompositing
)
1098 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1100 x
+= MacGetLeftBorderSize() ;
1101 y
+= MacGetTopBorderSize() ;
1102 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1103 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1106 AdjustForParentClientOrigin( x
, y
) ;
1108 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1109 if ( !GetParent()->IsTopLevel() )
1111 x
-= GetParent()->MacGetLeftBorderSize() ;
1112 y
-= GetParent()->MacGetTopBorderSize() ;
1118 // Get window size (not client size)
1119 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1122 m_peer
->GetRect( &bounds
) ;
1124 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1125 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1128 // get the position of the bounds of this window in client coordinates of its parent
1129 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1132 m_peer
->GetRect( &bounds
) ;
1134 int x1
= bounds
.left
;
1135 int y1
= bounds
.top
;
1137 if ( !IsTopLevel() )
1139 wxWindow
*parent
= GetParent();
1142 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1143 x1
+= parent
->MacGetLeftBorderSize() ;
1144 y1
+= parent
->MacGetTopBorderSize() ;
1145 // and now to client coordinates
1146 wxPoint
pt(parent
->GetClientAreaOrigin());
1155 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1157 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1159 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1162 Point localwhere
= {0,0} ;
1164 if(x
) localwhere
.h
= * x
;
1165 if(y
) localwhere
.v
= * y
;
1167 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1168 if(x
) *x
= localwhere
.h
;
1169 if(y
) *y
= localwhere
.v
;
1172 MacRootWindowToWindow( x
, y
) ;
1174 wxPoint origin
= GetClientAreaOrigin() ;
1175 if(x
) *x
-= origin
.x
;
1176 if(y
) *y
-= origin
.y
;
1179 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1181 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1182 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1184 wxPoint origin
= GetClientAreaOrigin() ;
1185 if(x
) *x
+= origin
.x
;
1186 if(y
) *y
+= origin
.y
;
1188 MacWindowToRootWindow( x
, y
) ;
1191 Point localwhere
= { 0,0 };
1192 if(x
) localwhere
.h
= * x
;
1193 if(y
) localwhere
.v
= * y
;
1194 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1195 if(x
) *x
= localwhere
.h
;
1196 if(y
) *y
= localwhere
.v
;
1200 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1202 wxPoint origin
= GetClientAreaOrigin() ;
1203 if(x
) *x
+= origin
.x
;
1204 if(y
) *y
+= origin
.y
;
1206 MacWindowToRootWindow( x
, y
) ;
1209 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1211 MacRootWindowToWindow( x
, y
) ;
1213 wxPoint origin
= GetClientAreaOrigin() ;
1214 if(x
) *x
-= origin
.x
;
1215 if(y
) *y
-= origin
.y
;
1218 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1221 if ( x
) pt
.x
= *x
;
1222 if ( y
) pt
.y
= *y
;
1224 if ( !IsTopLevel() )
1226 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1229 pt
.x
-= MacGetLeftBorderSize() ;
1230 pt
.y
-= MacGetTopBorderSize() ;
1231 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1235 if ( x
) *x
= (int) pt
.x
;
1236 if ( y
) *y
= (int) pt
.y
;
1239 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1244 MacWindowToRootWindow( &x1
, &y1
) ;
1249 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1252 if ( x
) pt
.x
= *x
;
1253 if ( y
) pt
.y
= *y
;
1255 if ( !IsTopLevel() )
1257 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1258 pt
.x
+= MacGetLeftBorderSize() ;
1259 pt
.y
+= MacGetTopBorderSize() ;
1262 if ( x
) *x
= (int) pt
.x
;
1263 if ( y
) *y
= (int) pt
.y
;
1266 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1271 MacRootWindowToWindow( &x1
, &y1
) ;
1276 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1278 RgnHandle rgn
= NewRgn() ;
1279 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1283 GetRegionBounds( rgn
, &content
) ;
1284 m_peer
->GetRect( &structure
) ;
1285 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1287 left
= content
.left
- structure
.left
;
1288 top
= content
.top
- structure
.top
;
1289 right
= structure
.right
- content
.right
;
1290 bottom
= structure
.bottom
- content
.bottom
;
1294 left
= top
= right
= bottom
= 0 ;
1299 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1301 wxSize sizeTotal
= size
;
1303 RgnHandle rgn
= NewRgn() ;
1305 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1309 GetRegionBounds( rgn
, &content
) ;
1311 m_peer
->GetRect( &structure
) ;
1312 // structure is in parent coordinates, but we only need width and height, so it's ok
1314 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1315 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1319 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1320 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1326 // Get size *available for subwindows* i.e. excluding menu bar etc.
1327 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1331 RgnHandle rgn
= NewRgn() ;
1333 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1335 GetRegionBounds( rgn
, &content
) ;
1339 m_peer
->GetRect( &content
) ;
1343 ww
= content
.right
- content
.left
;
1344 hh
= content
.bottom
- content
.top
;
1346 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1348 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1350 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1352 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1359 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1361 if (m_cursor
== cursor
)
1364 if (wxNullCursor
== cursor
)
1366 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1371 if ( ! wxWindowBase::SetCursor( cursor
) )
1375 wxASSERT_MSG( m_cursor
.Ok(),
1376 wxT("cursor must be valid after call to the base version"));
1379 wxWindowMac
*mouseWin
= 0 ;
1381 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1382 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1384 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1386 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1387 // position, use it...
1391 ControlPartCode part
;
1392 ControlRef control
;
1393 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1395 mouseWin
= wxFindControlFromMacControl( control
) ;
1398 QDSwapPort( savePort
, NULL
) ;
1401 if ( mouseWin
== this && !wxIsBusy() )
1403 m_cursor
.MacInstall() ;
1410 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1412 menu
->SetInvokingWindow(this);
1415 if ( x
== -1 && y
== -1 )
1417 wxPoint mouse
= wxGetMousePosition();
1418 x
= mouse
.x
; y
= mouse
.y
;
1422 ClientToScreen( &x
, &y
) ;
1425 menu
->MacBeforeDisplay( true ) ;
1426 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1427 if ( HiWord(menuResult
) != 0 )
1430 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1431 wxMenuItem
* item
= NULL
;
1433 item
= menu
->FindItem(id
, &realmenu
) ;
1434 if (item
->IsCheckable())
1436 item
->Check( !item
->IsChecked() ) ;
1438 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1440 menu
->MacAfterDisplay( true ) ;
1442 menu
->SetInvokingWindow(NULL
);
1448 // ----------------------------------------------------------------------------
1450 // ----------------------------------------------------------------------------
1454 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1456 wxWindowBase::DoSetToolTip(tooltip
);
1459 m_tooltip
->SetWindow(this);
1462 #endif // wxUSE_TOOLTIPS
1464 void wxWindowMac::MacInvalidateBorders()
1466 if ( m_peer
== NULL
)
1469 bool vis
= MacIsReallyShown() ;
1473 int outerBorder
= MacGetLeftBorderSize() ;
1474 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1477 if ( outerBorder
== 0 )
1480 // now we know that we have something to do at all
1482 // as the borders are drawn on the parent we have to properly invalidate all these areas
1483 RgnHandle updateInner
= NewRgn() ,
1484 updateOuter
= NewRgn() ;
1486 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1488 m_peer
->GetRect( &rect
) ;
1489 RectRgn( updateInner
, &rect
) ;
1490 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1491 RectRgn( updateOuter
, &rect
) ;
1492 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1493 #ifdef __WXMAC_OSX__
1494 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1496 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1498 InvalWindowRgn( tlw
, updateOuter
) ;
1500 DisposeRgn(updateOuter
) ;
1501 DisposeRgn(updateInner
) ;
1503 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1504 RectRgn( updateInner , &rect ) ;
1505 InsetRect( &rect , -4 , -4 ) ;
1506 RectRgn( updateOuter , &rect ) ;
1507 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1508 wxPoint parent(0,0);
1509 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1510 parent -= GetParent()->GetClientAreaOrigin() ;
1511 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1512 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1513 DisposeRgn(updateOuter) ;
1514 DisposeRgn(updateInner) ;
1519 // deleting a window while it is shown invalidates the region occupied by border or
1522 if ( IsShown() && ( outerBorder > 0 ) )
1524 // as the borders are drawn on the parent we have to properly invalidate all these areas
1525 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1529 m_peer->GetRect( &rect ) ;
1530 RectRgn( updateInner , &rect ) ;
1531 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1532 RectRgn( updateOuter , &rect ) ;
1533 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1534 wxPoint parent(0,0);
1535 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1536 parent -= GetParent()->GetClientAreaOrigin() ;
1537 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1538 CopyRgn( updateOuter , updateTotal ) ;
1540 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1541 DisposeRgn(updateOuter) ;
1542 DisposeRgn(updateInner) ;
1543 DisposeRgn(updateTotal) ;
1548 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1550 int outerBorder
= MacGetLeftBorderSize() ;
1551 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1554 if ( vis
&& ( outerBorder
> 0 ) )
1556 // as the borders are drawn on the parent we have to properly invalidate all these areas
1557 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1561 m_peer
->GetRect( &rect
) ;
1562 RectRgn( updateInner
, &rect
) ;
1563 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1564 RectRgn( updateOuter
, &rect
) ;
1565 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1567 wxPoint parent(0,0);
1568 #if TARGET_API_MAC_OSX
1569 // no offsetting needed when compositing
1571 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1572 parent -= GetParent()->GetClientAreaOrigin() ;
1573 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1576 CopyRgn( updateOuter
, updateTotal
) ;
1579 RectRgn( updateInner
, &rect
) ;
1580 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1581 RectRgn( updateOuter
, &rect
) ;
1582 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1584 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1586 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1588 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1589 DisposeRgn(updateOuter
) ;
1590 DisposeRgn(updateInner
) ;
1591 DisposeRgn(updateTotal
) ;
1596 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1598 // this is never called for a toplevel window, so we know we have a parent
1599 int former_x
, former_y
, former_w
, former_h
;
1601 // Get true coordinates of former position
1602 DoGetPosition( &former_x
, &former_y
) ;
1603 DoGetSize( &former_w
, &former_h
) ;
1605 wxWindow
*parent
= GetParent();
1608 wxPoint
pt(parent
->GetClientAreaOrigin());
1613 int actualWidth
= width
;
1614 int actualHeight
= height
;
1618 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1619 actualWidth
= m_minWidth
;
1620 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1621 actualHeight
= m_minHeight
;
1622 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1623 actualWidth
= m_maxWidth
;
1624 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1625 actualHeight
= m_maxHeight
;
1627 bool doMove
= false ;
1628 bool doResize
= false ;
1630 if ( actualX
!= former_x
|| actualY
!= former_y
)
1634 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1639 if ( doMove
|| doResize
)
1641 // as the borders are drawn outside the native control, we adjust now
1643 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1644 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1645 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1648 wxMacRectToNative( &bounds
, &r
) ;
1650 if ( !GetParent()->IsTopLevel() )
1652 wxMacWindowToNative( GetParent() , &r
) ;
1655 MacInvalidateBorders() ;
1657 m_peer
->SetRect( &r
) ;
1660 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1662 MacInvalidateBorders() ;
1664 MacRepositionScrollBars() ;
1667 wxPoint
point(actualX
,actualY
);
1668 wxMoveEvent
event(point
, m_windowId
);
1669 event
.SetEventObject(this);
1670 GetEventHandler()->ProcessEvent(event
) ;
1674 MacRepositionScrollBars() ;
1675 wxSize
size(actualWidth
, actualHeight
);
1676 wxSizeEvent
event(size
, m_windowId
);
1677 event
.SetEventObject(this);
1678 GetEventHandler()->ProcessEvent(event
);
1684 wxSize
wxWindowMac::DoGetBestSize() const
1686 if ( m_macIsUserPane
|| IsTopLevel() )
1687 return wxWindowBase::DoGetBestSize() ;
1689 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1690 int bestWidth
, bestHeight
;
1691 m_peer
->GetBestRect( &bestsize
) ;
1693 if ( EmptyRect( &bestsize
) )
1695 bestsize
.left
= bestsize
.top
= 0 ;
1696 bestsize
.right
= 16 ;
1697 bestsize
.bottom
= 16 ;
1698 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1700 bestsize
.bottom
= 16 ;
1703 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1705 bestsize
.bottom
= 24 ;
1707 #endif // wxUSE_SPINBTN
1710 // return wxWindowBase::DoGetBestSize() ;
1714 bestWidth
= bestsize
.right
- bestsize
.left
;
1715 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1716 if ( bestHeight
< 10 )
1719 return wxSize(bestWidth
, bestHeight
);
1723 // set the size of the window: if the dimensions are positive, just use them,
1724 // but if any of them is equal to -1, it means that we must find the value for
1725 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1726 // which case -1 is a valid value for x and y)
1728 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1729 // the width/height to best suit our contents, otherwise we reuse the current
1731 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1733 // get the current size and position...
1734 int currentX
, currentY
;
1735 GetPosition(¤tX
, ¤tY
);
1737 int currentW
,currentH
;
1738 GetSize(¤tW
, ¤tH
);
1740 // ... and don't do anything (avoiding flicker) if it's already ok
1741 if ( x
== currentX
&& y
== currentY
&&
1742 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1745 MacRepositionScrollBars() ; // we might have a real position shift
1749 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1751 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1754 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1756 wxSize
size(-1, -1);
1759 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1761 size
= DoGetBestSize();
1766 // just take the current one
1773 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1777 size
= DoGetBestSize();
1779 //else: already called DoGetBestSize() above
1785 // just take the current one
1790 DoMoveWindow(x
, y
, width
, height
);
1794 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1796 RgnHandle rgn
= NewRgn() ;
1798 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1800 GetRegionBounds( rgn
, &content
) ;
1804 content
.left
= content
.top
= 0 ;
1807 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1810 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1812 if ( clientheight
!= -1 || clientheight
!= -1 )
1814 int currentclientwidth
, currentclientheight
;
1815 int currentwidth
, currentheight
;
1817 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1818 GetSize( ¤twidth
, ¤theight
) ;
1820 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1821 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1825 void wxWindowMac::SetTitle(const wxString
& title
)
1827 m_label
= wxStripMenuCodes(title
) ;
1829 if ( m_peer
&& m_peer
->Ok() )
1831 m_peer
->SetTitle( m_label
) ;
1836 wxString
wxWindowMac::GetTitle() const
1841 bool wxWindowMac::Show(bool show
)
1843 bool former
= MacIsReallyShown() ;
1844 if ( !wxWindowBase::Show(show
) )
1847 // TODO use visibilityChanged Carbon Event for OSX
1850 m_peer
->SetVisibility( show
, true ) ;
1852 if ( former
!= MacIsReallyShown() )
1853 MacPropagateVisibilityChanged() ;
1857 bool wxWindowMac::Enable(bool enable
)
1859 wxASSERT( m_peer
->Ok() ) ;
1860 bool former
= MacIsReallyEnabled() ;
1861 if ( !wxWindowBase::Enable(enable
) )
1864 m_peer
->Enable( enable
) ;
1866 if ( former
!= MacIsReallyEnabled() )
1867 MacPropagateEnabledStateChanged() ;
1872 // status change propagations (will be not necessary for OSX later )
1875 void wxWindowMac::MacPropagateVisibilityChanged()
1877 #if !TARGET_API_MAC_OSX
1878 MacVisibilityChanged() ;
1880 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1883 wxWindowMac
*child
= node
->GetData();
1884 if ( child
->IsShown() )
1885 child
->MacPropagateVisibilityChanged( ) ;
1886 node
= node
->GetNext();
1891 void wxWindowMac::MacPropagateEnabledStateChanged( )
1893 #if !TARGET_API_MAC_OSX
1894 MacEnabledStateChanged() ;
1896 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1899 wxWindowMac
*child
= node
->GetData();
1900 if ( child
->IsEnabled() )
1901 child
->MacPropagateEnabledStateChanged() ;
1902 node
= node
->GetNext();
1907 void wxWindowMac::MacPropagateHiliteChanged( )
1909 #if !TARGET_API_MAC_OSX
1910 MacHiliteChanged() ;
1912 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1915 wxWindowMac
*child
= node
->GetData();
1916 // if ( child->IsEnabled() )
1917 child
->MacPropagateHiliteChanged() ;
1918 node
= node
->GetNext();
1924 // status change notifications
1927 void wxWindowMac::MacVisibilityChanged()
1931 void wxWindowMac::MacHiliteChanged()
1935 void wxWindowMac::MacEnabledStateChanged()
1940 // status queries on the inherited window's state
1943 bool wxWindowMac::MacIsReallyShown()
1945 // only under OSX the visibility of the TLW is taken into account
1946 if ( m_isBeingDeleted
)
1949 #if TARGET_API_MAC_OSX
1950 if ( m_peer
&& m_peer
->Ok() )
1951 return m_peer
->IsVisible();
1953 wxWindow
* win
= this ;
1954 while( win
->IsShown() )
1956 if ( win
->IsTopLevel() )
1959 win
= win
->GetParent() ;
1967 bool wxWindowMac::MacIsReallyEnabled()
1969 return m_peer
->IsEnabled() ;
1972 bool wxWindowMac::MacIsReallyHilited()
1974 return m_peer
->IsActive();
1977 void wxWindowMac::MacFlashInvalidAreas()
1979 #if TARGET_API_MAC_OSX
1980 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1988 int wxWindowMac::GetCharHeight() const
1990 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1991 return dc
.GetCharHeight() ;
1994 int wxWindowMac::GetCharWidth() const
1996 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1997 return dc
.GetCharWidth() ;
2000 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2001 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2003 const wxFont
*fontToUse
= theFont
;
2005 fontToUse
= &m_font
;
2007 wxClientDC
dc( (wxWindowMac
*) this ) ;
2009 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2010 if ( externalLeading
)
2011 *externalLeading
= le
;
2021 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2022 * we always intersect with the entire window, not only with the client area
2025 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2027 if ( m_peer
== NULL
)
2030 if ( !MacIsReallyShown() )
2036 wxMacRectToNative( rect
, &r
) ;
2037 m_peer
->SetNeedsDisplay( &r
) ;
2041 m_peer
->SetNeedsDisplay() ;
2045 void wxWindowMac::Freeze()
2047 #if TARGET_API_MAC_OSX
2048 if ( !m_frozenness
++ )
2050 if ( m_peer
&& m_peer
->Ok() )
2051 m_peer
->SetDrawingEnabled( false ) ;
2057 void wxWindowMac::Thaw()
2059 #if TARGET_API_MAC_OSX
2060 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2062 if ( !--m_frozenness
)
2064 if ( m_peer
&& m_peer
->Ok() )
2066 m_peer
->SetDrawingEnabled( true ) ;
2067 m_peer
->InvalidateWithChildren() ;
2073 wxWindowMac
*wxGetActiveWindow()
2075 // actually this is a windows-only concept
2079 // Coordinates relative to the window
2080 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2082 // We really don't move the mouse programmatically under Mac.
2085 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2087 #if TARGET_API_MAC_OSX
2088 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2095 event
.GetDC()->Clear() ;
2099 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2104 int wxWindowMac::GetScrollPos(int orient
) const
2106 if ( orient
== wxHORIZONTAL
)
2109 return m_hScrollBar
->GetThumbPosition() ;
2114 return m_vScrollBar
->GetThumbPosition() ;
2119 // This now returns the whole range, not just the number
2120 // of positions that we can scroll.
2121 int wxWindowMac::GetScrollRange(int orient
) const
2123 if ( orient
== wxHORIZONTAL
)
2126 return m_hScrollBar
->GetRange() ;
2131 return m_vScrollBar
->GetRange() ;
2136 int wxWindowMac::GetScrollThumb(int orient
) const
2138 if ( orient
== wxHORIZONTAL
)
2141 return m_hScrollBar
->GetThumbSize() ;
2146 return m_vScrollBar
->GetThumbSize() ;
2151 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2153 if ( orient
== wxHORIZONTAL
)
2156 m_hScrollBar
->SetThumbPosition( pos
) ;
2161 m_vScrollBar
->SetThumbPosition( pos
) ;
2166 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2167 // our own window origin is at leftOrigin/rightOrigin
2170 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2176 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2177 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2179 m_peer
->GetRect( &rect
) ;
2180 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2182 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2183 if ( UMAGetSystemVersion() >= 0x1030 )
2186 HIThemeFrameDrawInfo info
;
2187 memset( &info
, 0 , sizeof( info
) ) ;
2191 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2192 info
.isFocused
= hasFocus
;
2195 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2196 wxASSERT( cgContext
) ;
2198 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2201 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2202 InsetRect( &srect
, border
, border
);
2203 info
.kind
= kHIThemeFrameTextFieldSquare
;
2206 else if (HasFlag(wxSIMPLE_BORDER
))
2209 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2210 InsetRect( &srect
, border
, border
);
2211 info
.kind
= kHIThemeFrameListBox
;
2217 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2218 srect
.bottom
- srect
.top
) ;
2219 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2221 else if ( hasFocus
)
2224 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2225 srect
.bottom
- srect
.top
) ;
2226 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2229 m_peer
->GetRect( &rect
) ;
2230 if ( hasBothScrollbars
)
2233 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2234 CGRect cgrect
= CGRectMake( srect
.right
- size
, srect
.bottom
- size
, size
, size
) ;
2235 CGPoint cgpoint
= CGPointMake( srect
.right
- size
, srect
.bottom
- size
) ;
2236 HIThemeGrowBoxDrawInfo info
;
2237 memset( &info
, 0 , sizeof( info
) ) ;
2239 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2240 info
.kind
= kHIThemeGrowBoxKindNone
;
2241 info
.size
= kHIThemeGrowBoxSizeNormal
;
2242 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2243 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2249 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2253 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2254 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2257 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2261 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2262 InsetRect( &srect
, border
, border
);
2263 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2265 else if (HasFlag(wxSIMPLE_BORDER
))
2269 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2270 InsetRect( &srect
, border
, border
);
2271 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2277 DrawThemeFocusRect( &srect
, true ) ;
2279 if ( hasBothScrollbars
)
2281 // GetThemeStandaloneGrowBoxBounds
2282 //DrawThemeStandaloneNoGrowBox
2287 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2289 if ( child
== m_hScrollBar
)
2290 m_hScrollBar
= NULL
;
2291 if ( child
== m_vScrollBar
)
2292 m_vScrollBar
= NULL
;
2294 wxWindowBase::RemoveChild( child
) ;
2297 // New function that will replace some of the above.
2298 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2299 int range
, bool refresh
)
2301 if ( orient
== wxHORIZONTAL
)
2305 if ( range
== 0 || thumbVisible
>= range
)
2307 if ( m_hScrollBar
->IsShown() )
2308 m_hScrollBar
->Show(false) ;
2312 if ( !m_hScrollBar
->IsShown() )
2313 m_hScrollBar
->Show(true) ;
2315 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2322 if ( range
== 0 || thumbVisible
>= range
)
2324 if ( m_vScrollBar
->IsShown() )
2325 m_vScrollBar
->Show(false) ;
2329 if ( !m_vScrollBar
->IsShown() )
2330 m_vScrollBar
->Show(true) ;
2332 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2335 MacRepositionScrollBars() ;
2338 // Does a physical scroll
2339 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2341 if( dx
== 0 && dy
==0 )
2347 int width
, height
;
2348 GetClientSize( &width
, &height
) ;
2349 #if TARGET_API_MAC_OSX
2350 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2351 // area is scrolled, this does not occur if width and height are 2 pixels less,
2352 // TODO write optimal workaround
2353 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2356 scrollrect
.Intersect( *rect
) ;
2358 if ( m_peer
->GetNeedsDisplay() )
2360 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2361 // either immediate redraw or full invalidate
2363 // is the better overall solution, as it does not slow down scrolling
2364 m_peer
->SetNeedsDisplay() ;
2366 // this would be the preferred version for fast drawing controls
2367 if( UMAGetSystemVersion() < 0x1030 )
2370 HIViewRender(m_peer
->GetControlRef()) ;
2373 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2374 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2375 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2382 RgnHandle updateRgn
= NewRgn() ;
2385 wxClientDC
dc(this) ;
2386 wxMacPortSetter
helper(&dc
) ;
2388 m_peer
->GetRect( &scrollrect
) ;
2389 scrollrect
.top
+= MacGetTopBorderSize() ;
2390 scrollrect
.left
+= MacGetLeftBorderSize() ;
2391 scrollrect
.bottom
= scrollrect
.top
+ height
;
2392 scrollrect
.right
= scrollrect
.left
+ width
;
2396 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2397 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2398 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2400 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2402 // now scroll the former update region as well and add the new update region
2404 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2405 RgnHandle formerUpdateRgn
= NewRgn() ;
2406 RgnHandle scrollRgn
= NewRgn() ;
2407 RectRgn( scrollRgn
, &scrollrect
) ;
2408 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2410 LocalToGlobal( &pt
) ;
2411 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2412 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2413 if ( !EmptyRgn( formerUpdateRgn
) )
2415 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2416 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2417 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2419 InvalWindowRgn(rootWindow
, updateRgn
) ;
2420 DisposeRgn( updateRgn
) ;
2421 DisposeRgn( formerUpdateRgn
) ;
2422 DisposeRgn( scrollRgn
) ;
2427 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2429 wxWindowMac
*child
= node
->GetData();
2430 if (child
== m_vScrollBar
) continue;
2431 if (child
== m_hScrollBar
) continue;
2432 if (child
->IsTopLevel()) continue;
2435 child
->GetPosition( &x
, &y
);
2437 child
->GetSize( &w
, &h
);
2441 if (rect
->Intersects(rc
))
2442 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2446 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2451 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2453 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2455 wxScrollWinEvent wevent
;
2456 wevent
.SetPosition(event
.GetPosition());
2457 wevent
.SetOrientation(event
.GetOrientation());
2458 wevent
.SetEventObject(this);
2460 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2461 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2462 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2463 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2464 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2465 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2466 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2467 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2468 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2469 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2470 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2471 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2472 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2473 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2474 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2475 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2477 GetEventHandler()->ProcessEvent(wevent
);
2481 // Get the window with the focus
2482 wxWindowMac
*wxWindowBase::DoFindFocus()
2484 ControlRef control
;
2485 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2486 return wxFindControlFromMacControl( control
) ;
2489 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2491 // panel wants to track the window which was the last to have focus in it,
2492 // so we want to set ourselves as the window which last had focus
2494 // notice that it's also important to do it upwards the tree becaus
2495 // otherwise when the top level panel gets focus, it won't set it back to
2496 // us, but to some other sibling
2498 // CS:don't know if this is still needed:
2499 //wxChildFocusEvent eventFocus(this);
2500 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2502 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2504 #if !wxMAC_USE_CORE_GRAPHICS
2505 wxMacWindowStateSaver
sv( this ) ;
2507 m_peer
->GetRect( &rect
) ;
2508 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2510 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2514 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2516 rect
.right
+= pt
.x
;
2518 rect
.bottom
+= pt
.y
;
2521 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2522 DrawThemeFocusRect( &rect
, true ) ;
2525 DrawThemeFocusRect( &rect
, false ) ;
2527 // as this erases part of the frame we have to redraw borders
2528 // and because our z-ordering is not always correct (staticboxes)
2529 // we have to invalidate things, we cannot simple redraw
2530 MacInvalidateBorders() ;
2533 GetParent()->Refresh() ;
2540 void wxWindowMac::OnInternalIdle()
2542 // This calls the UI-update mechanism (querying windows for
2543 // menu/toolbar/control state information)
2544 if (wxUpdateUIEvent::CanUpdate(this))
2545 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2548 // Raise the window to the top of the Z order
2549 void wxWindowMac::Raise()
2551 m_peer
->SetZOrder( true , NULL
) ;
2554 // Lower the window to the bottom of the Z order
2555 void wxWindowMac::Lower()
2557 m_peer
->SetZOrder( false , NULL
) ;
2561 // static wxWindow *gs_lastWhich = NULL;
2563 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2565 // first trigger a set cursor event
2567 wxPoint clientorigin
= GetClientAreaOrigin() ;
2568 wxSize clientsize
= GetClientSize() ;
2570 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2572 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2574 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2575 if ( processedEvtSetCursor
&& event
.HasCursor() )
2577 cursor
= event
.GetCursor() ;
2582 // the test for processedEvtSetCursor is here to prevent using m_cursor
2583 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2584 // it - this is a way to say that our cursor shouldn't be used for this
2586 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2596 cursor
= *wxSTANDARD_CURSOR
;
2600 cursor
.MacInstall() ;
2602 return cursor
.Ok() ;
2605 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2609 return m_tooltip
->GetTip() ;
2611 return wxEmptyString
;
2614 void wxWindowMac::ClearBackground()
2620 void wxWindowMac::Update()
2622 #if TARGET_API_MAC_OSX
2624 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2625 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2627 // for composited windows this also triggers a redraw of all
2628 // invalid views in the window
2629 if( UMAGetSystemVersion() >= 0x1030 )
2630 HIWindowFlush(window
) ;
2634 // the only way to trigger the redrawing on earlier systems is to call
2637 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2638 UInt32 currentEventClass
= 0 ;
2639 UInt32 currentEventKind
= 0 ;
2640 if ( currentEvent
!= NULL
)
2642 currentEventClass
= ::GetEventClass( currentEvent
) ;
2643 currentEventKind
= ::GetEventKind( currentEvent
) ;
2645 if ( currentEventClass
!= kEventClassMenu
)
2647 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2650 OSStatus status
= noErr
;
2651 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2654 m_peer
->SetNeedsDisplay() ;
2657 ::Draw1Control( m_peer
->GetControlRef() ) ;
2661 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2663 wxTopLevelWindowMac
* win
= NULL
;
2664 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2667 win
= wxFindWinFromMacWindow( window
) ;
2671 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2673 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2674 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2675 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2676 // to add focus borders everywhere
2679 RgnHandle visRgn
= NewRgn() ;
2680 RgnHandle tempRgn
= NewRgn() ;
2681 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2683 m_peer
->GetRect( &r
) ;
2684 r
.left
-= MacGetLeftBorderSize() ;
2685 r
.top
-= MacGetTopBorderSize() ;
2686 r
.bottom
+= MacGetBottomBorderSize() ;
2687 r
.right
+= MacGetRightBorderSize() ;
2694 if ( includeOuterStructures
)
2695 InsetRect( &r
, -4 , -4 ) ;
2696 RectRgn( visRgn
, &r
) ;
2698 if ( !IsTopLevel() )
2700 wxWindow
* child
= this ;
2701 wxWindow
* parent
= child
->GetParent() ;
2706 // we have to find a better clipping algorithm here, in order not to clip things
2707 // positioned like status and toolbar
2708 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2710 size
= parent
->GetSize() ;
2715 size
= parent
->GetClientSize() ;
2716 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2720 parent
->MacWindowToRootWindow( &x
, &y
) ;
2721 MacRootWindowToWindow( &x
, &y
) ;
2723 if ( !includeOuterStructures
|| (
2724 parent
->MacClipChildren() ||
2725 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2728 SetRectRgn( tempRgn
,
2729 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2730 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2731 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2733 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2735 if ( parent
->IsTopLevel() )
2738 parent
= child
->GetParent() ;
2743 wxRegion vis
= visRgn
;
2744 DisposeRgn( visRgn
) ;
2745 DisposeRgn( tempRgn
) ;
2750 This function must not change the updatergn !
2752 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2754 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2755 bool handled
= false ;
2757 GetRegionBounds( updatergn
, &updatebounds
) ;
2759 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2761 if ( !EmptyRgn(updatergn
) )
2763 RgnHandle newupdate
= NewRgn() ;
2764 wxSize point
= GetClientSize() ;
2765 wxPoint origin
= GetClientAreaOrigin() ;
2766 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2767 SectRgn( newupdate
, updatergn
, newupdate
) ;
2769 // first send an erase event to the entire update area
2771 // for the toplevel window this really is the entire area
2772 // for all the others only their client area, otherwise they
2773 // might be drawing with full alpha and eg put blue into
2774 // the grow-box area of a scrolled window (scroll sample)
2777 dc
= new wxWindowDC(this);
2779 dc
= new wxClientDC(this);
2780 dc
->SetClippingRegion(wxRegion(updatergn
));
2781 wxEraseEvent
eevent( GetId(), dc
);
2782 eevent
.SetEventObject( this );
2783 GetEventHandler()->ProcessEvent( eevent
);
2787 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2788 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2789 m_updateRegion
= newupdate
;
2790 DisposeRgn( newupdate
) ;
2792 if ( !m_updateRegion
.Empty() )
2794 // paint the window itself
2797 event
.SetTimestamp(time
);
2798 event
.SetEventObject(this);
2799 GetEventHandler()->ProcessEvent(event
);
2803 // now we cannot rely on having its borders drawn by a window itself, as it does not
2804 // get the updateRgn wide enough to always do so, so we do it from the parent
2805 // this would also be the place to draw any custom backgrounds for native controls
2806 // in Composited windowing
2807 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2809 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2811 wxWindowMac
*child
= node
->GetData();
2812 if (child
== m_vScrollBar
) continue;
2813 if (child
== m_hScrollBar
) continue;
2814 if (child
->IsTopLevel()) continue;
2815 if (!child
->IsShown()) continue;
2817 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2820 child
->GetPosition( &x
, &y
);
2822 child
->GetSize( &w
, &h
);
2823 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2824 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2825 InsetRect( &childRect
, -10 , -10) ;
2827 if ( RectInRgn( &childRect
, updatergn
) )
2830 // paint custom borders
2831 wxNcPaintEvent
eventNc( child
->GetId() );
2832 eventNc
.SetEventObject( child
);
2833 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2835 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2836 if ( UMAGetSystemVersion() >= 0x1030 )
2838 child
->MacPaintBorders(0,0) ;
2843 wxWindowDC
dc(this) ;
2844 dc
.SetClippingRegion(wxRegion(updatergn
));
2845 wxMacPortSetter
helper(&dc
) ;
2846 child
->MacPaintBorders(0,0) ;
2856 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2858 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2862 if ( iter
->IsTopLevel() )
2863 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2865 iter
= iter
->GetParent() ;
2867 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2871 void wxWindowMac::MacCreateScrollBars( long style
)
2873 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2875 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2877 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2878 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2879 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2880 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2882 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2883 variant
= wxWINDOW_VARIANT_SMALL
;
2886 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2888 GetClientSize( &width
, &height
) ;
2890 wxPoint
vPoint(width
-scrlsize
, 0) ;
2891 wxSize
vSize(scrlsize
, height
- adjust
) ;
2892 wxPoint
hPoint(0 , height
-scrlsize
) ;
2893 wxSize
hSize( width
- adjust
, scrlsize
) ;
2896 if ( style
& wxVSCROLL
)
2898 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2899 vSize
, wxVERTICAL
);
2902 if ( style
& wxHSCROLL
)
2904 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2905 hSize
, wxHORIZONTAL
);
2910 // because the create does not take into account the client area origin
2911 MacRepositionScrollBars() ; // we might have a real position shift
2914 void wxWindowMac::MacRepositionScrollBars()
2916 if ( !m_hScrollBar
&& !m_vScrollBar
)
2919 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2920 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2921 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2923 // get real client area
2927 GetSize( &width
, &height
) ;
2929 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2930 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2932 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2933 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2934 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2935 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2941 GetSize( &w , &h ) ;
2943 MacClientToRootWindow( &x , &y ) ;
2944 MacClientToRootWindow( &w , &h ) ;
2946 wxWindowMac *iter = (wxWindowMac*)this ;
2948 int totW = 10000 , totH = 10000;
2951 if ( iter->IsTopLevel() )
2953 iter->GetSize( &totW , &totH ) ;
2957 iter = iter->GetParent() ;
2985 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2989 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2993 bool wxWindowMac::AcceptsFocus() const
2995 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2998 void wxWindowMac::MacSuperChangedPosition()
3000 // only window-absolute structures have to be moved i.e. controls
3002 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3005 wxWindowMac
*child
= node
->GetData();
3006 child
->MacSuperChangedPosition() ;
3007 node
= node
->GetNext();
3011 void wxWindowMac::MacTopLevelWindowChangedPosition()
3013 // only screen-absolute structures have to be moved i.e. glcanvas
3015 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3018 wxWindowMac
*child
= node
->GetData();
3019 child
->MacTopLevelWindowChangedPosition() ;
3020 node
= node
->GetNext();
3024 long wxWindowMac::MacGetLeftBorderSize( ) const
3029 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3034 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3039 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3046 long wxWindowMac::MacGetRightBorderSize( ) const
3048 // they are all symmetric in mac themes
3049 return MacGetLeftBorderSize() ;
3052 long wxWindowMac::MacGetTopBorderSize( ) const
3054 // they are all symmetric in mac themes
3055 return MacGetLeftBorderSize() ;
3058 long wxWindowMac::MacGetBottomBorderSize( ) const
3060 // they are all symmetric in mac themes
3061 return MacGetLeftBorderSize() ;
3064 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3066 return style
& ~wxBORDER_MASK
;
3069 // Find the wxWindowMac at the current mouse position, returning the mouse
3071 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3073 pt
= wxGetMousePosition();
3074 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3078 // Get the current mouse position.
3079 wxPoint
wxGetMousePosition()
3082 wxGetMousePosition(& x
, & y
);
3083 return wxPoint(x
, y
);
3086 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3088 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3090 // copied from wxGTK : CS
3091 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3094 // (a) it's a command event and so is propagated to the parent
3095 // (b) under MSW it can be generated from kbd too
3096 // (c) it uses screen coords (because of (a))
3097 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3099 this->ClientToScreen(event
.GetPosition()));
3100 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3109 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3111 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3113 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3117 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3121 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3125 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3126 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3130 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3132 return eventNotHandledErr
;