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 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1280 RgnHandle rgn
= NewRgn() ;
1281 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1285 GetRegionBounds( rgn
, &content
) ;
1286 m_peer
->GetRect( &structure
) ;
1287 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1289 left
= content
.left
- structure
.left
;
1290 top
= content
.top
- structure
.top
;
1291 right
= structure
.right
- content
.right
;
1292 bottom
= structure
.bottom
- content
.bottom
;
1296 left
= top
= right
= bottom
= 0 ;
1301 wxSize wxWindowMac
::DoGetSizeFromClientSize( const wxSize
& size
) const
1303 wxSize sizeTotal
= size
;
1305 RgnHandle rgn
= NewRgn() ;
1307 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1311 GetRegionBounds( rgn
, &content
) ;
1313 m_peer
->GetRect( &structure
) ;
1314 // structure is in parent coordinates, but we only need width and height, so it's ok
1316 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1317 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1321 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1322 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1328 // Get size *available for subwindows* i.e. excluding menu bar etc.
1329 void wxWindowMac
::DoGetClientSize(int *x
, int *y
) const
1331 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1334 RgnHandle rgn
= NewRgn() ;
1336 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1338 GetRegionBounds( rgn
, &content
) ;
1342 m_peer
->GetRect( &content
) ;
1346 ww
= content
.right
- content
.left
;
1347 hh
= content
.bottom
- content
.top
;
1349 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1351 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1353 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1355 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1362 bool wxWindowMac
::SetCursor(const wxCursor
& cursor
)
1364 if (m_cursor
== cursor
)
1367 if (wxNullCursor
== cursor
)
1369 if ( ! wxWindowBase
::SetCursor( *wxSTANDARD_CURSOR
) )
1374 if ( ! wxWindowBase
::SetCursor( cursor
) )
1378 wxASSERT_MSG( m_cursor
.Ok(),
1379 wxT("cursor must be valid after call to the base version"));
1382 wxWindowMac
*mouseWin
= 0 ;
1384 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1385 WindowRef window
= (WindowRef
) ( tlw ? tlw
->MacGetWindowRef() : 0 ) ;
1387 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1389 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1390 // position, use it...
1394 ControlPartCode part
;
1395 ControlRef control
;
1396 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1398 mouseWin
= wxFindControlFromMacControl( control
) ;
1401 QDSwapPort( savePort
, NULL
) ;
1404 if ( mouseWin
== this && !wxIsBusy() )
1406 m_cursor
.MacInstall() ;
1413 bool wxWindowMac
::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1415 menu
->SetInvokingWindow(this);
1418 if ( x
== -1 && y
== -1 )
1420 wxPoint mouse
= wxGetMousePosition();
1421 x
= mouse
.x
; y
= mouse
.y
;
1425 ClientToScreen( &x
, &y
) ;
1428 menu
->MacBeforeDisplay( true ) ;
1429 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1430 if ( HiWord(menuResult
) != 0 )
1433 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1434 wxMenuItem
* item
= NULL
;
1436 item
= menu
->FindItem(id
, &realmenu
) ;
1437 if (item
->IsCheckable())
1439 item
->Check( !item
->IsChecked() ) ;
1441 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1443 menu
->MacAfterDisplay( true ) ;
1445 menu
->SetInvokingWindow(NULL
);
1451 // ----------------------------------------------------------------------------
1453 // ----------------------------------------------------------------------------
1457 void wxWindowMac
::DoSetToolTip(wxToolTip
*tooltip
)
1459 wxWindowBase
::DoSetToolTip(tooltip
);
1462 m_tooltip
->SetWindow(this);
1465 #endif // wxUSE_TOOLTIPS
1467 void wxWindowMac
::MacInvalidateBorders()
1469 if ( m_peer
== NULL
)
1472 bool vis
= MacIsReallyShown() ;
1476 int outerBorder
= MacGetLeftBorderSize() ;
1477 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1480 if ( outerBorder
== 0 )
1483 // now we know that we have something to do at all
1485 // as the borders are drawn on the parent we have to properly invalidate all these areas
1486 RgnHandle updateInner
= NewRgn() ,
1487 updateOuter
= NewRgn() ;
1489 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1491 m_peer
->GetRect( &rect
) ;
1492 RectRgn( updateInner
, &rect
) ;
1493 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1494 RectRgn( updateOuter
, &rect
) ;
1495 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1496 #ifdef __WXMAC_OSX__
1497 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1499 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1501 InvalWindowRgn( tlw
, updateOuter
) ;
1503 DisposeRgn(updateOuter
) ;
1504 DisposeRgn(updateInner
) ;
1506 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1507 RectRgn( updateInner , &rect ) ;
1508 InsetRect( &rect , -4 , -4 ) ;
1509 RectRgn( updateOuter , &rect ) ;
1510 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1511 wxPoint parent(0,0);
1512 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1513 parent -= GetParent()->GetClientAreaOrigin() ;
1514 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1515 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1516 DisposeRgn(updateOuter) ;
1517 DisposeRgn(updateInner) ;
1522 // deleting a window while it is shown invalidates the region occupied by border or
1525 if ( IsShown() && ( outerBorder > 0 ) )
1527 // as the borders are drawn on the parent we have to properly invalidate all these areas
1528 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1532 m_peer->GetRect( &rect ) ;
1533 RectRgn( updateInner , &rect ) ;
1534 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1535 RectRgn( updateOuter , &rect ) ;
1536 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1537 wxPoint parent(0,0);
1538 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1539 parent -= GetParent()->GetClientAreaOrigin() ;
1540 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1541 CopyRgn( updateOuter , updateTotal ) ;
1543 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1544 DisposeRgn(updateOuter) ;
1545 DisposeRgn(updateInner) ;
1546 DisposeRgn(updateTotal) ;
1551 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1553 int outerBorder
= MacGetLeftBorderSize() ;
1554 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1557 if ( vis
&& ( outerBorder
> 0 ) )
1559 // as the borders are drawn on the parent we have to properly invalidate all these areas
1560 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1564 m_peer
->GetRect( &rect
) ;
1565 RectRgn( updateInner
, &rect
) ;
1566 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1567 RectRgn( updateOuter
, &rect
) ;
1568 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1570 wxPoint parent(0,0);
1571 #if TARGET_API_MAC_OSX
1572 // no offsetting needed when compositing
1574 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1575 parent -= GetParent()->GetClientAreaOrigin() ;
1576 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1579 CopyRgn( updateOuter
, updateTotal
) ;
1582 RectRgn( updateInner
, &rect
) ;
1583 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1584 RectRgn( updateOuter
, &rect
) ;
1585 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1587 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1589 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1591 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1592 DisposeRgn(updateOuter
) ;
1593 DisposeRgn(updateInner
) ;
1594 DisposeRgn(updateTotal
) ;
1599 void wxWindowMac
::DoMoveWindow(int x
, int y
, int width
, int height
)
1601 // this is never called for a toplevel window, so we know we have a parent
1602 int former_x
, former_y
, former_w
, former_h
;
1604 // Get true coordinates of former position
1605 DoGetPosition( &former_x
, &former_y
) ;
1606 DoGetSize( &former_w
, &former_h
) ;
1608 wxWindow
*parent
= GetParent();
1611 wxPoint
pt(parent
->GetClientAreaOrigin());
1616 int actualWidth
= width
;
1617 int actualHeight
= height
;
1621 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1622 actualWidth
= m_minWidth
;
1623 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1624 actualHeight
= m_minHeight
;
1625 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1626 actualWidth
= m_maxWidth
;
1627 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1628 actualHeight
= m_maxHeight
;
1630 bool doMove
= false ;
1631 bool doResize
= false ;
1633 if ( actualX
!= former_x
|| actualY
!= former_y
)
1637 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1642 if ( doMove
|| doResize
)
1644 // as the borders are drawn outside the native control, we adjust now
1646 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1647 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1648 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1651 wxMacRectToNative( &bounds
, &r
) ;
1653 if ( !GetParent()->IsTopLevel() )
1655 wxMacWindowToNative( GetParent() , &r
) ;
1658 MacInvalidateBorders() ;
1660 m_peer
->SetRect( &r
) ;
1663 wxWindowMac
::MacSuperChangedPosition() ; // like this only children will be notified
1665 MacInvalidateBorders() ;
1667 MacRepositionScrollBars() ;
1670 wxPoint
point(actualX
,actualY
);
1671 wxMoveEvent
event(point
, m_windowId
);
1672 event
.SetEventObject(this);
1673 GetEventHandler()->ProcessEvent(event
) ;
1677 MacRepositionScrollBars() ;
1678 wxSize
size(actualWidth
, actualHeight
);
1679 wxSizeEvent
event(size
, m_windowId
);
1680 event
.SetEventObject(this);
1681 GetEventHandler()->ProcessEvent(event
);
1687 wxSize wxWindowMac
::DoGetBestSize() const
1689 if ( m_macIsUserPane
|| IsTopLevel() )
1690 return wxWindowBase
::DoGetBestSize() ;
1692 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1693 int bestWidth
, bestHeight
;
1694 m_peer
->GetBestRect( &bestsize
) ;
1696 if ( EmptyRect( &bestsize
) )
1698 bestsize
.left
= bestsize
.top
= 0 ;
1699 bestsize
.right
= 16 ;
1700 bestsize
.bottom
= 16 ;
1701 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1703 bestsize
.bottom
= 16 ;
1706 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1708 bestsize
.bottom
= 24 ;
1710 #endif // wxUSE_SPINBTN
1713 // return wxWindowBase::DoGetBestSize() ;
1717 bestWidth
= bestsize
.right
- bestsize
.left
;
1718 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1719 if ( bestHeight
< 10 )
1722 return wxSize(bestWidth
, bestHeight
);
1726 // set the size of the window: if the dimensions are positive, just use them,
1727 // but if any of them is equal to -1, it means that we must find the value for
1728 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1729 // which case -1 is a valid value for x and y)
1731 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1732 // the width/height to best suit our contents, otherwise we reuse the current
1734 void wxWindowMac
::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1736 // get the current size and position...
1737 int currentX
, currentY
;
1738 GetPosition(¤tX
, ¤tY
);
1740 int currentW
,currentH
;
1741 GetSize(¤tW
, ¤tH
);
1743 // ... and don't do anything (avoiding flicker) if it's already ok
1744 if ( x
== currentX
&& y
== currentY
&&
1745 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1748 MacRepositionScrollBars() ; // we might have a real position shift
1752 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1754 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1757 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1759 wxSize
size(-1, -1);
1762 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1764 size
= DoGetBestSize();
1769 // just take the current one
1776 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1780 size
= DoGetBestSize();
1782 //else: already called DoGetBestSize() above
1788 // just take the current one
1793 DoMoveWindow(x
, y
, width
, height
);
1797 wxPoint wxWindowMac
::GetClientAreaOrigin() const
1799 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1800 RgnHandle rgn
= NewRgn() ;
1802 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1803 GetRegionBounds( rgn
, &content
) ;
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 bool former
= MacIsReallyShown() ;
1842 if ( !wxWindowBase
::Show(show
) )
1845 // TODO use visibilityChanged Carbon Event for OSX
1848 m_peer
->SetVisibility( show
, true ) ;
1850 if ( former
!= MacIsReallyShown() )
1851 MacPropagateVisibilityChanged() ;
1855 bool wxWindowMac
::Enable(bool enable
)
1857 wxASSERT( m_peer
->Ok() ) ;
1858 bool former
= MacIsReallyEnabled() ;
1859 if ( !wxWindowBase
::Enable(enable
) )
1862 m_peer
->Enable( enable
) ;
1864 if ( former
!= MacIsReallyEnabled() )
1865 MacPropagateEnabledStateChanged() ;
1870 // status change propagations (will be not necessary for OSX later )
1873 void wxWindowMac
::MacPropagateVisibilityChanged()
1875 #if !TARGET_API_MAC_OSX
1876 MacVisibilityChanged() ;
1878 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
1881 wxWindowMac
*child
= node
->GetData();
1882 if ( child
->IsShown() )
1883 child
->MacPropagateVisibilityChanged( ) ;
1884 node
= node
->GetNext();
1889 void wxWindowMac
::MacPropagateEnabledStateChanged( )
1891 #if !TARGET_API_MAC_OSX
1892 MacEnabledStateChanged() ;
1894 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
1897 wxWindowMac
*child
= node
->GetData();
1898 if ( child
->IsEnabled() )
1899 child
->MacPropagateEnabledStateChanged() ;
1900 node
= node
->GetNext();
1905 void wxWindowMac
::MacPropagateHiliteChanged( )
1907 #if !TARGET_API_MAC_OSX
1908 MacHiliteChanged() ;
1910 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
1913 wxWindowMac
*child
= node
->GetData();
1914 // if ( child->IsEnabled() )
1915 child
->MacPropagateHiliteChanged() ;
1916 node
= node
->GetNext();
1922 // status change notifications
1925 void wxWindowMac
::MacVisibilityChanged()
1929 void wxWindowMac
::MacHiliteChanged()
1933 void wxWindowMac
::MacEnabledStateChanged()
1938 // status queries on the inherited window's state
1941 bool wxWindowMac
::MacIsReallyShown()
1943 // only under OSX the visibility of the TLW is taken into account
1944 if ( m_isBeingDeleted
)
1947 #if TARGET_API_MAC_OSX
1948 if ( m_peer
&& m_peer
->Ok() )
1949 return m_peer
->IsVisible();
1951 wxWindow
* win
= this ;
1952 while( win
->IsShown() )
1954 if ( win
->IsTopLevel() )
1957 win
= win
->GetParent() ;
1965 bool wxWindowMac
::MacIsReallyEnabled()
1967 return m_peer
->IsEnabled() ;
1970 bool wxWindowMac
::MacIsReallyHilited()
1972 return m_peer
->IsActive();
1975 void wxWindowMac
::MacFlashInvalidAreas()
1977 #if TARGET_API_MAC_OSX
1978 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1986 int wxWindowMac
::GetCharHeight() const
1988 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1989 return dc
.GetCharHeight() ;
1992 int wxWindowMac
::GetCharWidth() const
1994 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1995 return dc
.GetCharWidth() ;
1998 void wxWindowMac
::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1999 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2001 const wxFont
*fontToUse
= theFont
;
2003 fontToUse
= &m_font
;
2005 wxClientDC
dc( (wxWindowMac
*) this ) ;
2007 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2008 if ( externalLeading
)
2009 *externalLeading
= le
;
2019 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2020 * we always intersect with the entire window, not only with the client area
2023 void wxWindowMac
::Refresh(bool eraseBack
, const wxRect
*rect
)
2025 if ( m_peer
== NULL
)
2028 if ( !MacIsReallyShown() )
2034 wxMacRectToNative( rect
, &r
) ;
2035 m_peer
->SetNeedsDisplay( &r
) ;
2039 m_peer
->SetNeedsDisplay() ;
2043 void wxWindowMac
::Freeze()
2045 #if TARGET_API_MAC_OSX
2046 if ( !m_frozenness
++ )
2048 if ( m_peer
&& m_peer
->Ok() )
2049 m_peer
->SetDrawingEnabled( false ) ;
2055 void wxWindowMac
::Thaw()
2057 #if TARGET_API_MAC_OSX
2058 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2060 if ( !--m_frozenness
)
2062 if ( m_peer
&& m_peer
->Ok() )
2064 m_peer
->SetDrawingEnabled( true ) ;
2065 m_peer
->InvalidateWithChildren() ;
2071 wxWindowMac
*wxGetActiveWindow()
2073 // actually this is a windows-only concept
2077 // Coordinates relative to the window
2078 void wxWindowMac
::WarpPointer (int x_pos
, int y_pos
)
2080 // We really don't move the mouse programmatically under Mac.
2083 void wxWindowMac
::OnEraseBackground(wxEraseEvent
& event
)
2085 #if TARGET_API_MAC_OSX
2086 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2093 event
.GetDC()->Clear() ;
2097 void wxWindowMac
::OnNcPaint( wxNcPaintEvent
& event
)
2102 int wxWindowMac
::GetScrollPos(int orient
) const
2104 if ( orient
== wxHORIZONTAL
)
2107 return m_hScrollBar
->GetThumbPosition() ;
2112 return m_vScrollBar
->GetThumbPosition() ;
2117 // This now returns the whole range, not just the number
2118 // of positions that we can scroll.
2119 int wxWindowMac
::GetScrollRange(int orient
) const
2121 if ( orient
== wxHORIZONTAL
)
2124 return m_hScrollBar
->GetRange() ;
2129 return m_vScrollBar
->GetRange() ;
2134 int wxWindowMac
::GetScrollThumb(int orient
) const
2136 if ( orient
== wxHORIZONTAL
)
2139 return m_hScrollBar
->GetThumbSize() ;
2144 return m_vScrollBar
->GetThumbSize() ;
2149 void wxWindowMac
::SetScrollPos(int orient
, int pos
, bool refresh
)
2151 if ( orient
== wxHORIZONTAL
)
2154 m_hScrollBar
->SetThumbPosition( pos
) ;
2159 m_vScrollBar
->SetThumbPosition( pos
) ;
2164 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2165 // our own window origin is at leftOrigin/rightOrigin
2168 void wxWindowMac
::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2174 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2175 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2177 m_peer
->GetRect( &rect
) ;
2178 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2180 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2181 if ( UMAGetSystemVersion() >= 0x1030 )
2184 HIThemeFrameDrawInfo info
;
2185 memset( &info
, 0 , sizeof( info
) ) ;
2189 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2190 info
.isFocused
= hasFocus
;
2193 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2194 wxASSERT( cgContext
) ;
2196 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2199 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2200 InsetRect( &srect
, border
, border
);
2201 info
.kind
= kHIThemeFrameTextFieldSquare
;
2204 else if (HasFlag(wxSIMPLE_BORDER
))
2207 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2208 InsetRect( &srect
, border
, border
);
2209 info
.kind
= kHIThemeFrameListBox
;
2215 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2216 srect
.bottom
- srect
.top
) ;
2217 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2219 else if ( hasFocus
)
2222 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2223 srect
.bottom
- srect
.top
) ;
2224 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2227 m_peer
->GetRect( &rect
) ;
2228 if ( hasBothScrollbars
)
2231 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ?
16 : 12 ;
2232 CGRect cgrect
= CGRectMake( srect
.right
- size
, srect
.bottom
- size
, size
, size
) ;
2233 CGPoint cgpoint
= CGPointMake( srect
.right
- size
, srect
.bottom
- size
) ;
2234 HIThemeGrowBoxDrawInfo info
;
2235 memset( &info
, 0 , sizeof( info
) ) ;
2237 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2238 info
.kind
= kHIThemeGrowBoxKindNone
;
2239 info
.size
= kHIThemeGrowBoxSizeNormal
;
2240 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2241 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2247 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2251 wxMacControl
::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2252 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2255 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2259 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2260 InsetRect( &srect
, border
, border
);
2261 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2263 else if (HasFlag(wxSIMPLE_BORDER
))
2267 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2268 InsetRect( &srect
, border
, border
);
2269 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2275 DrawThemeFocusRect( &srect
, true ) ;
2277 if ( hasBothScrollbars
)
2279 // GetThemeStandaloneGrowBoxBounds
2280 //DrawThemeStandaloneNoGrowBox
2285 void wxWindowMac
::RemoveChild( wxWindowBase
*child
)
2287 if ( child
== m_hScrollBar
)
2288 m_hScrollBar
= NULL
;
2289 if ( child
== m_vScrollBar
)
2290 m_vScrollBar
= NULL
;
2292 wxWindowBase
::RemoveChild( child
) ;
2295 // New function that will replace some of the above.
2296 void wxWindowMac
::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2297 int range
, bool refresh
)
2299 if ( orient
== wxHORIZONTAL
)
2303 if ( range
== 0 || thumbVisible
>= range
)
2305 if ( m_hScrollBar
->IsShown() )
2306 m_hScrollBar
->Show(false) ;
2310 if ( !m_hScrollBar
->IsShown() )
2311 m_hScrollBar
->Show(true) ;
2313 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2320 if ( range
== 0 || thumbVisible
>= range
)
2322 if ( m_vScrollBar
->IsShown() )
2323 m_vScrollBar
->Show(false) ;
2327 if ( !m_vScrollBar
->IsShown() )
2328 m_vScrollBar
->Show(true) ;
2330 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2333 MacRepositionScrollBars() ;
2336 // Does a physical scroll
2337 void wxWindowMac
::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2339 if( dx
== 0 && dy
==0 )
2345 int width
, height
;
2346 GetClientSize( &width
, &height
) ;
2347 #if TARGET_API_MAC_OSX
2348 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2349 // area is scrolled, this does not occur if width and height are 2 pixels less,
2350 // TODO write optimal workaround
2351 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2354 scrollrect
.Intersect( *rect
) ;
2356 if ( m_peer
->GetNeedsDisplay() )
2358 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2359 // either immediate redraw or full invalidate
2361 // is the better overall solution, as it does not slow down scrolling
2362 m_peer
->SetNeedsDisplay() ;
2364 // this would be the preferred version for fast drawing controls
2365 if( UMAGetSystemVersion() < 0x1030 )
2368 HIViewRender(m_peer
->GetControlRef()) ;
2371 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2372 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2373 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2380 RgnHandle updateRgn
= NewRgn() ;
2383 wxClientDC
dc(this) ;
2384 wxMacPortSetter
helper(&dc
) ;
2386 m_peer
->GetRect( &scrollrect
) ;
2387 scrollrect
.top
+= MacGetTopBorderSize() ;
2388 scrollrect
.left
+= MacGetLeftBorderSize() ;
2389 scrollrect
.bottom
= scrollrect
.top
+ height
;
2390 scrollrect
.right
= scrollrect
.left
+ width
;
2394 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2395 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2396 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2398 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2400 // now scroll the former update region as well and add the new update region
2402 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2403 RgnHandle formerUpdateRgn
= NewRgn() ;
2404 RgnHandle scrollRgn
= NewRgn() ;
2405 RectRgn( scrollRgn
, &scrollrect
) ;
2406 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2408 LocalToGlobal( &pt
) ;
2409 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2410 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2411 if ( !EmptyRgn( formerUpdateRgn
) )
2413 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2414 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2415 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2417 InvalWindowRgn(rootWindow
, updateRgn
) ;
2418 DisposeRgn( updateRgn
) ;
2419 DisposeRgn( formerUpdateRgn
) ;
2420 DisposeRgn( scrollRgn
) ;
2425 for (wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2427 wxWindowMac
*child
= node
->GetData();
2428 if (child
== m_vScrollBar
) continue;
2429 if (child
== m_hScrollBar
) continue;
2430 if (child
->IsTopLevel()) continue;
2433 child
->GetPosition( &x
, &y
);
2435 child
->GetSize( &w
, &h
);
2439 if (rect
->Intersects(rc
))
2440 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2444 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2449 void wxWindowMac
::MacOnScroll(wxScrollEvent
&event
)
2451 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2453 wxScrollWinEvent wevent
;
2454 wevent
.SetPosition(event
.GetPosition());
2455 wevent
.SetOrientation(event
.GetOrientation());
2456 wevent
.SetEventObject(this);
2458 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2459 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2460 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2461 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2462 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2463 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2464 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2465 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2466 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2467 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2468 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2469 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2470 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2471 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2472 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2473 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2475 GetEventHandler()->ProcessEvent(wevent
);
2479 // Get the window with the focus
2480 wxWindowMac
*wxWindowBase
::DoFindFocus()
2482 ControlRef control
;
2483 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2484 return wxFindControlFromMacControl( control
) ;
2487 void wxWindowMac
::OnSetFocus(wxFocusEvent
& event
)
2489 // panel wants to track the window which was the last to have focus in it,
2490 // so we want to set ourselves as the window which last had focus
2492 // notice that it's also important to do it upwards the tree becaus
2493 // otherwise when the top level panel gets focus, it won't set it back to
2494 // us, but to some other sibling
2496 // CS:don't know if this is still needed:
2497 //wxChildFocusEvent eventFocus(this);
2498 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2500 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2502 #if !wxMAC_USE_CORE_GRAPHICS
2503 wxMacWindowStateSaver
sv( this ) ;
2505 m_peer
->GetRect( &rect
) ;
2506 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2508 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2512 wxMacControl
::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2514 rect
.right
+= pt
.x
;
2516 rect
.bottom
+= pt
.y
;
2519 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2520 DrawThemeFocusRect( &rect
, true ) ;
2523 DrawThemeFocusRect( &rect
, false ) ;
2525 // as this erases part of the frame we have to redraw borders
2526 // and because our z-ordering is not always correct (staticboxes)
2527 // we have to invalidate things, we cannot simple redraw
2528 MacInvalidateBorders() ;
2531 GetParent()->Refresh() ;
2538 void wxWindowMac
::OnInternalIdle()
2540 // This calls the UI-update mechanism (querying windows for
2541 // menu/toolbar/control state information)
2542 if (wxUpdateUIEvent
::CanUpdate(this))
2543 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2546 // Raise the window to the top of the Z order
2547 void wxWindowMac
::Raise()
2549 m_peer
->SetZOrder( true , NULL
) ;
2552 // Lower the window to the bottom of the Z order
2553 void wxWindowMac
::Lower()
2555 m_peer
->SetZOrder( false , NULL
) ;
2559 // static wxWindow *gs_lastWhich = NULL;
2561 bool wxWindowMac
::MacSetupCursor( const wxPoint
& pt
)
2563 // first trigger a set cursor event
2565 wxPoint clientorigin
= GetClientAreaOrigin() ;
2566 wxSize clientsize
= GetClientSize() ;
2568 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2570 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2572 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2573 if ( processedEvtSetCursor
&& event
.HasCursor() )
2575 cursor
= event
.GetCursor() ;
2580 // the test for processedEvtSetCursor is here to prevent using m_cursor
2581 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2582 // it - this is a way to say that our cursor shouldn't be used for this
2584 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2594 cursor
= *wxSTANDARD_CURSOR
;
2598 cursor
.MacInstall() ;
2600 return cursor
.Ok() ;
2603 wxString wxWindowMac
::MacGetToolTipString( wxPoint
&pt
)
2607 return m_tooltip
->GetTip() ;
2609 return wxEmptyString
;
2612 void wxWindowMac
::ClearBackground()
2618 void wxWindowMac
::Update()
2620 #if TARGET_API_MAC_OSX
2622 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2623 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2625 // for composited windows this also triggers a redraw of all
2626 // invalid views in the window
2627 if( UMAGetSystemVersion() >= 0x1030 )
2628 HIWindowFlush(window
) ;
2632 // the only way to trigger the redrawing on earlier systems is to call
2635 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2636 UInt32 currentEventClass
= 0 ;
2637 UInt32 currentEventKind
= 0 ;
2638 if ( currentEvent
!= NULL
)
2640 currentEventClass
= ::GetEventClass( currentEvent
) ;
2641 currentEventKind
= ::GetEventKind( currentEvent
) ;
2643 if ( currentEventClass
!= kEventClassMenu
)
2645 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2648 OSStatus status
= noErr
;
2649 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2652 m_peer
->SetNeedsDisplay() ;
2655 ::Draw1Control( m_peer
->GetControlRef() ) ;
2659 wxTopLevelWindowMac
* wxWindowMac
::MacGetTopLevelWindow() const
2661 wxTopLevelWindowMac
* win
= NULL
;
2662 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2665 win
= wxFindWinFromMacWindow( window
) ;
2669 wxRegion wxWindowMac
::MacGetVisibleRegion( bool includeOuterStructures
)
2671 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2672 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2673 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2674 // to add focus borders everywhere
2677 RgnHandle visRgn
= NewRgn() ;
2678 RgnHandle tempRgn
= NewRgn() ;
2679 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2681 m_peer
->GetRect( &r
) ;
2682 r
.left
-= MacGetLeftBorderSize() ;
2683 r
.top
-= MacGetTopBorderSize() ;
2684 r
.bottom
+= MacGetBottomBorderSize() ;
2685 r
.right
+= MacGetRightBorderSize() ;
2692 if ( includeOuterStructures
)
2693 InsetRect( &r
, -4 , -4 ) ;
2694 RectRgn( visRgn
, &r
) ;
2696 if ( !IsTopLevel() )
2698 wxWindow
* child
= this ;
2699 wxWindow
* parent
= child
->GetParent() ;
2704 // we have to find a better clipping algorithm here, in order not to clip things
2705 // positioned like status and toolbar
2706 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2708 size
= parent
->GetSize() ;
2713 size
= parent
->GetClientSize() ;
2714 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2718 parent
->MacWindowToRootWindow( &x
, &y
) ;
2719 MacRootWindowToWindow( &x
, &y
) ;
2721 if ( !includeOuterStructures
|| (
2722 parent
->MacClipChildren() ||
2723 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2726 SetRectRgn( tempRgn
,
2727 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2728 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2729 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2731 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2733 if ( parent
->IsTopLevel() )
2736 parent
= child
->GetParent() ;
2741 wxRegion vis
= visRgn
;
2742 DisposeRgn( visRgn
) ;
2743 DisposeRgn( tempRgn
) ;
2748 This function must not change the updatergn !
2750 bool wxWindowMac
::MacDoRedraw( WXHRGN updatergnr
, long time
)
2752 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2753 bool handled
= false ;
2755 GetRegionBounds( updatergn
, &updatebounds
) ;
2757 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2759 if ( !EmptyRgn(updatergn
) )
2761 RgnHandle newupdate
= NewRgn() ;
2762 wxSize point
= GetClientSize() ;
2763 wxPoint origin
= GetClientAreaOrigin() ;
2764 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2765 SectRgn( newupdate
, updatergn
, newupdate
) ;
2767 // first send an erase event to the entire update area
2769 // for the toplevel window this really is the entire area
2770 // for all the others only their client area, otherwise they
2771 // might be drawing with full alpha and eg put blue into
2772 // the grow-box area of a scrolled window (scroll sample)
2775 dc
= new wxWindowDC(this);
2777 dc
= new wxClientDC(this);
2778 dc
->SetClippingRegion(wxRegion(updatergn
));
2779 wxEraseEvent
eevent( GetId(), dc
);
2780 eevent
.SetEventObject( this );
2781 GetEventHandler()->ProcessEvent( eevent
);
2785 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2786 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2787 m_updateRegion
= newupdate
;
2788 DisposeRgn( newupdate
) ;
2790 if ( !m_updateRegion
.Empty() )
2792 // paint the window itself
2795 event
.SetTimestamp(time
);
2796 event
.SetEventObject(this);
2797 GetEventHandler()->ProcessEvent(event
);
2801 // now we cannot rely on having its borders drawn by a window itself, as it does not
2802 // get the updateRgn wide enough to always do so, so we do it from the parent
2803 // this would also be the place to draw any custom backgrounds for native controls
2804 // in Composited windowing
2805 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2807 for (wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2809 wxWindowMac
*child
= node
->GetData();
2810 if (child
== m_vScrollBar
) continue;
2811 if (child
== m_hScrollBar
) continue;
2812 if (child
->IsTopLevel()) continue;
2813 if (!child
->IsShown()) continue;
2815 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2818 child
->GetPosition( &x
, &y
);
2820 child
->GetSize( &w
, &h
);
2821 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2822 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2823 InsetRect( &childRect
, -10 , -10) ;
2825 if ( RectInRgn( &childRect
, updatergn
) )
2828 // paint custom borders
2829 wxNcPaintEvent
eventNc( child
->GetId() );
2830 eventNc
.SetEventObject( child
);
2831 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2833 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2834 if ( UMAGetSystemVersion() >= 0x1030 )
2836 child
->MacPaintBorders(0,0) ;
2841 wxWindowDC
dc(this) ;
2842 dc
.SetClippingRegion(wxRegion(updatergn
));
2843 wxMacPortSetter
helper(&dc
) ;
2844 child
->MacPaintBorders(0,0) ;
2854 WXWindow wxWindowMac
::MacGetTopLevelWindowRef() const
2856 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2860 if ( iter
->IsTopLevel() )
2861 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2863 iter
= iter
->GetParent() ;
2865 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2869 void wxWindowMac
::MacCreateScrollBars( long style
)
2871 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2873 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2875 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2876 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2877 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2878 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2880 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2881 variant
= wxWINDOW_VARIANT_SMALL
;
2884 int adjust
= hasBoth ? scrlsize
- 1: 0 ;
2886 GetClientSize( &width
, &height
) ;
2888 wxPoint
vPoint(width
-scrlsize
, 0) ;
2889 wxSize
vSize(scrlsize
, height
- adjust
) ;
2890 wxPoint
hPoint(0 , height
-scrlsize
) ;
2891 wxSize
hSize( width
- adjust
, scrlsize
) ;
2894 if ( style
& wxVSCROLL
)
2896 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2897 vSize
, wxVERTICAL
);
2900 if ( style
& wxHSCROLL
)
2902 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2903 hSize
, wxHORIZONTAL
);
2908 // because the create does not take into account the client area origin
2909 MacRepositionScrollBars() ; // we might have a real position shift
2912 void wxWindowMac
::MacRepositionScrollBars()
2914 if ( !m_hScrollBar
&& !m_vScrollBar
)
2917 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2918 int scrlsize
= m_hScrollBar ? m_hScrollBar
->GetSize().y
: ( m_vScrollBar ? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2919 int adjust
= hasBoth ? scrlsize
- 1 : 0 ;
2921 // get real client area
2925 GetSize( &width
, &height
) ;
2927 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2928 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2930 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2931 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2932 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2933 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2939 GetSize( &w , &h ) ;
2941 MacClientToRootWindow( &x , &y ) ;
2942 MacClientToRootWindow( &w , &h ) ;
2944 wxWindowMac *iter = (wxWindowMac*)this ;
2946 int totW = 10000 , totH = 10000;
2949 if ( iter->IsTopLevel() )
2951 iter->GetSize( &totW , &totH ) ;
2955 iter = iter->GetParent() ;
2983 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2987 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2991 bool wxWindowMac
::AcceptsFocus() const
2993 return MacCanFocus() && wxWindowBase
::AcceptsFocus();
2996 void wxWindowMac
::MacSuperChangedPosition()
2998 // only window-absolute structures have to be moved i.e. controls
3000 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
3003 wxWindowMac
*child
= node
->GetData();
3004 child
->MacSuperChangedPosition() ;
3005 node
= node
->GetNext();
3009 void wxWindowMac
::MacTopLevelWindowChangedPosition()
3011 // only screen-absolute structures have to be moved i.e. glcanvas
3013 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
3016 wxWindowMac
*child
= node
->GetData();
3017 child
->MacTopLevelWindowChangedPosition() ;
3018 node
= node
->GetNext();
3022 long wxWindowMac
::MacGetLeftBorderSize( ) const
3027 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3032 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3037 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3044 long wxWindowMac
::MacGetRightBorderSize( ) const
3046 // they are all symmetric in mac themes
3047 return MacGetLeftBorderSize() ;
3050 long wxWindowMac
::MacGetTopBorderSize( ) const
3052 // they are all symmetric in mac themes
3053 return MacGetLeftBorderSize() ;
3056 long wxWindowMac
::MacGetBottomBorderSize( ) const
3058 // they are all symmetric in mac themes
3059 return MacGetLeftBorderSize() ;
3062 long wxWindowMac
::MacRemoveBordersFromStyle( long style
)
3064 return style
& ~wxBORDER_MASK
;
3067 // Find the wxWindowMac at the current mouse position, returning the mouse
3069 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3071 pt
= wxGetMousePosition();
3072 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3076 // Get the current mouse position.
3077 wxPoint
wxGetMousePosition()
3080 wxGetMousePosition(& x
, & y
);
3081 return wxPoint(x
, y
);
3084 void wxWindowMac
::OnMouseEvent( wxMouseEvent
&event
)
3086 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3088 // copied from wxGTK : CS
3089 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3092 // (a) it's a command event and so is propagated to the parent
3093 // (b) under MSW it can be generated from kbd too
3094 // (c) it uses screen coords (because of (a))
3095 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3097 this->ClientToScreen(event
.GetPosition()));
3098 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3107 void wxWindowMac
::OnPaint( wxPaintEvent
& event
)
3109 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3111 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3115 void wxWindowMac
::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3119 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3123 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3124 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3128 wxInt32 wxWindowMac
::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3130 return eventNotHandledErr
;