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 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 #if TARGET_API_MAC_OSX
83 EVT_PAINT(wxWindowMac::OnPaint
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 1
97 // ---------------------------------------------------------------------------
98 // Utility Routines to move between different coordinate systems
99 // ---------------------------------------------------------------------------
102 * Right now we have the following setup :
103 * a border that is not part of the native control is always outside the
104 * control's border (otherwise we loose all native intelligence, future ways
105 * may be to have a second embedding control responsible for drawing borders
106 * and backgrounds eventually)
107 * so all this border calculations have to be taken into account when calling
108 * native methods or getting native oriented data
109 * so we have three coordinate systems here
110 * wx client coordinates
111 * wx window coordinates (including window frames)
116 // originating from native control
120 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
122 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
125 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
127 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
131 // directed towards native control
134 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
136 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
139 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
141 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
150 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
152 #if TARGET_API_MAC_OSX
154 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
156 kEventControlVisibilityChanged
= 157
162 static const EventTypeSpec eventList
[] =
164 { kEventClassControl
, kEventControlHit
} ,
165 #if TARGET_API_MAC_OSX
166 { kEventClassControl
, kEventControlDraw
} ,
167 { kEventClassControl
, kEventControlVisibilityChanged
} ,
168 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
169 { kEventClassControl
, kEventControlHiliteChanged
} ,
170 { kEventClassControl
, kEventControlSetFocusPart
} ,
172 { kEventClassService
, kEventServiceGetTypes
},
173 { kEventClassService
, kEventServiceCopy
},
174 { kEventClassService
, kEventServicePaste
},
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177 // { kEventClassControl , kEventControlBoundsChanged } ,
181 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
183 OSStatus result
= eventNotHandledErr
;
185 wxMacCarbonEvent
cEvent( event
) ;
187 ControlRef controlRef
;
188 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
190 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
192 switch( GetEventKind( event
) )
194 #if TARGET_API_MAC_OSX
195 case kEventControlDraw
:
197 RgnHandle updateRgn
= NULL
;
198 RgnHandle allocatedRgn
= NULL
;
199 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
201 if ( thisWindow
->GetPeer()->IsCompositing() == false )
203 if ( thisWindow
->GetPeer()->IsRootControl() == false )
205 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
209 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
213 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
215 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
219 if ( thisWindow
->GetPeer()->IsCompositing() == false )
221 allocatedRgn
= NewRgn() ;
222 CopyRgn( updateRgn
, allocatedRgn
) ;
223 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
224 // hide the given region by the new region that must be shifted
225 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
226 updateRgn
= allocatedRgn
;
230 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
232 // as this update region is in native window locals we must adapt it to wx window local
233 allocatedRgn
= NewRgn() ;
234 CopyRgn( updateRgn
, allocatedRgn
) ;
235 // hide the given region by the new region that must be shifted
236 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
237 updateRgn
= allocatedRgn
;
242 GetRegionBounds( updateRgn
, &rgnBounds
) ;
243 #if wxMAC_DEBUG_REDRAW
244 if ( thisWindow
->MacIsUserPane() )
246 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
247 static float color
= 0.5 ;
250 HIViewGetBounds( controlRef
, &bounds
);
251 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
252 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
253 CGContextFillRect( cgContext
, bounds
);
265 #if wxMAC_USE_CORE_GRAPHICS
266 bool created
= false ;
267 CGContextRef cgContext
= 0 ;
268 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
270 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
272 // this parameter is not provided on non-composited windows
274 // rest of the code expects this to be already transformed and clipped for local
275 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
277 GetPortBounds( port
, &bounds
) ;
278 CreateCGContextForPort( port
, &cgContext
) ;
280 wxMacWindowToNative( thisWindow
, updateRgn
) ;
281 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
282 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
283 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
284 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
286 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
287 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
289 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
292 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
293 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
294 controlBounds.right - controlBounds.left ,
295 controlBounds.bottom - controlBounds.top ) );
299 thisWindow
->MacSetCGContextRef( cgContext
) ;
301 wxMacCGContextStateSaver
sg( cgContext
) ;
303 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
305 #if wxMAC_USE_CORE_GRAPHICS
306 thisWindow
->MacSetCGContextRef( NULL
) ;
310 CGContextRelease( cgContext
) ;
315 DisposeRgn( allocatedRgn
) ;
318 case kEventControlVisibilityChanged
:
319 thisWindow
->MacVisibilityChanged() ;
321 case kEventControlEnabledStateChanged
:
322 thisWindow
->MacEnabledStateChanged() ;
324 case kEventControlHiliteChanged
:
325 thisWindow
->MacHiliteChanged() ;
328 // we emulate this event under Carbon CFM
329 case kEventControlSetFocusPart
:
331 Boolean focusEverything
= false ;
332 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
334 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
338 if ( controlPart
== kControlFocusNoPart
)
341 if ( thisWindow
->GetCaret() )
343 thisWindow
->GetCaret()->OnKillFocus();
345 #endif // wxUSE_CARET
346 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
347 event
.SetEventObject(thisWindow
);
348 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
352 // panel wants to track the window which was the last to have focus in it
353 wxChildFocusEvent
eventFocus(thisWindow
);
354 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
357 if ( thisWindow
->GetCaret() )
359 thisWindow
->GetCaret()->OnSetFocus();
361 #endif // wxUSE_CARET
363 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
364 event
.SetEventObject(thisWindow
);
365 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
367 if ( thisWindow
->MacIsUserPane() )
371 case kEventControlHit
:
373 result
= thisWindow
->MacControlHit( handler
, event
) ;
382 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
384 OSStatus result
= eventNotHandledErr
;
386 wxMacCarbonEvent
cEvent( event
) ;
388 ControlRef controlRef
;
389 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
390 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
391 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
393 switch( GetEventKind( event
) )
395 case kEventServiceGetTypes
:
399 textCtrl
->GetSelection( &from
, &to
) ;
401 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
403 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
404 if ( textCtrl
->IsEditable() )
405 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
407 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
408 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
410 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
414 CFArrayAppendValue (copyTypes
, typestring
) ;
416 CFArrayAppendValue (pasteTypes
, typestring
) ;
417 CFRelease( typestring
) ;
423 case kEventServiceCopy
:
427 textCtrl
->GetSelection( &from
, &to
) ;
428 wxString val
= textCtrl
->GetValue() ;
429 val
= val
.Mid( from
, to
- from
) ;
430 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
431 verify_noerr( ClearScrap( &scrapRef
) ) ;
432 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
436 case kEventServicePaste
:
439 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
440 Size textSize
, pastedSize
;
441 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
443 char *content
= new char[textSize
] ;
444 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
445 content
[textSize
-1] = 0 ;
447 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
449 textCtrl
->WriteText( wxString( content
) ) ;
460 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
462 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
463 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
464 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
465 OSStatus result
= eventNotHandledErr
;
467 switch ( GetEventClass( event
) )
469 case kEventClassControl
:
470 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
472 case kEventClassService
:
473 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
478 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
482 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
484 #if !TARGET_API_MAC_OSX
486 // ---------------------------------------------------------------------------
487 // UserPane events for non OSX builds
488 // ---------------------------------------------------------------------------
490 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
492 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
494 win
->MacControlUserPaneDrawProc(part
) ;
496 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
498 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
500 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
502 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
504 return kControlNoPart
;
506 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
508 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
510 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
512 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
514 return kControlNoPart
;
516 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
518 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
520 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
522 win
->MacControlUserPaneIdleProc() ;
524 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
526 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
528 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
530 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
532 return kControlNoPart
;
534 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
536 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
538 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
540 win
->MacControlUserPaneActivateProc(activating
) ;
542 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
544 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
546 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
548 return win
->MacControlUserPaneFocusProc(action
) ;
550 return kControlNoPart
;
552 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
554 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
556 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
558 win
->MacControlUserPaneBackgroundProc(info
) ;
560 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
562 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
564 RgnHandle rgn
= NewRgn() ;
567 MacWindowToRootWindow( &x
,&y
) ;
568 OffsetRgn( rgn
, -x
, -y
) ;
569 wxMacWindowStateSaver
sv( this ) ;
570 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
571 MacDoRedraw( rgn
, 0 ) ;
575 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
577 return kControlNoPart
;
580 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
582 return kControlNoPart
;
585 void wxWindowMac::MacControlUserPaneIdleProc()
589 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
591 return kControlNoPart
;
594 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
598 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
600 return kControlNoPart
;
603 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
609 // ---------------------------------------------------------------------------
610 // Scrollbar Tracking for all
611 // ---------------------------------------------------------------------------
613 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
614 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
618 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
621 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
625 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
627 // ===========================================================================
629 // ===========================================================================
631 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
633 static MacControlMap wxWinMacControlList
;
635 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
637 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
639 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
642 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
644 // adding NULL ControlRef is (first) surely a result of an error and
645 // (secondly) breaks native event processing
646 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
648 wxWinMacControlList
[inControl
] = control
;
651 void wxRemoveMacControlAssociation(wxWindow
*control
)
653 // iterate over all the elements in the class
654 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
655 // we should go on...
661 MacControlMap::iterator it
;
662 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
664 if ( it
->second
== control
)
666 wxWinMacControlList
.erase(it
);
674 // ----------------------------------------------------------------------------
675 // constructors and such
676 // ----------------------------------------------------------------------------
678 wxWindowMac::wxWindowMac()
683 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
688 const wxString
& name
)
691 Create(parent
, id
, pos
, size
, style
, name
);
694 void wxWindowMac::Init()
698 #if WXWIN_COMPATIBILITY_2_4
699 m_backgroundTransparent
= false;
702 // as all windows are created with WS_VISIBLE style...
705 m_hScrollBar
= NULL
;
706 m_vScrollBar
= NULL
;
707 m_macBackgroundBrush
= wxNullBrush
;
709 m_macIsUserPane
= true;
710 #if wxMAC_USE_CORE_GRAPHICS
711 m_cgContextRef
= NULL
;
713 m_clipChildren
= false ;
714 m_cachedClippedRectValid
= false ;
715 // we need a valid font for the encodings
716 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
720 wxWindowMac::~wxWindowMac()
724 m_isBeingDeleted
= true;
726 MacInvalidateBorders() ;
728 #ifndef __WXUNIVERSAL__
729 // VS: make sure there's no wxFrame with last focus set to us:
730 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
732 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
735 if ( frame
->GetLastFocus() == this )
737 frame
->SetLastFocus((wxWindow
*)NULL
);
742 #endif // __WXUNIVERSAL__
744 // destroy children before destroying this window itself
747 // wxRemoveMacControlAssociation( this ) ;
748 // If we delete an item, we should initialize the parent panel,
749 // because it could now be invalid.
750 wxWindow
*parent
= GetParent() ;
753 if (parent
->GetDefaultItem() == (wxButton
*) this)
754 parent
->SetDefaultItem(NULL
);
756 if ( m_peer
&& m_peer
->Ok() )
758 // in case the callback might be called during destruction
759 wxRemoveMacControlAssociation( this) ;
760 // we currently are not using this hook
761 // ::SetControlColorProc( *m_peer , NULL ) ;
765 if ( g_MacLastWindow
== this )
767 g_MacLastWindow
= NULL
;
770 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
773 if ( frame
->GetLastFocus() == this )
774 frame
->SetLastFocus( NULL
) ;
777 // delete our drop target if we've got one
778 #if wxUSE_DRAG_AND_DROP
779 if ( m_dropTarget
!= NULL
)
784 #endif // wxUSE_DRAG_AND_DROP
788 WXWidget
wxWindowMac::GetHandle() const
790 return (WXWidget
) m_peer
->GetControlRef() ;
794 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
796 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
797 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
798 GetEventTypeCount(eventList
), eventList
, this,
799 (EventHandlerRef
*)&m_macControlEventHandler
);
800 #if !TARGET_API_MAC_OSX
801 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
803 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
804 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
805 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
806 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
807 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
808 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
809 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
810 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
817 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
821 const wxString
& name
)
823 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
825 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
828 m_windowVariant
= parent
->GetWindowVariant() ;
830 if ( m_macIsUserPane
)
832 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
835 | kControlSupportsEmbedding
836 | kControlSupportsLiveFeedback
837 | kControlGetsFocusOnClick
838 // | kControlHasSpecialBackground
839 // | kControlSupportsCalcBestRect
840 | kControlHandlesTracking
841 | kControlSupportsFocus
842 | kControlWantsActivate
846 m_peer
= new wxMacControl(this) ;
847 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
850 MacPostControlCreate(pos
,size
) ;
852 #ifndef __WXUNIVERSAL__
853 // Don't give scrollbars to wxControls unless they ask for them
854 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
855 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
857 MacCreateScrollBars( style
) ;
861 wxWindowCreateEvent
event(this);
862 GetEventHandler()->AddPendingEvent(event
);
867 void wxWindowMac::MacChildAdded()
871 m_vScrollBar
->Raise() ;
875 m_hScrollBar
->Raise() ;
880 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
882 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
884 m_peer
->SetReference( (long) this ) ;
885 GetParent()->AddChild(this);
887 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
889 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
890 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
891 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
892 GetParent()->MacChildAdded() ;
894 // adjust font, controlsize etc
895 DoSetWindowVariant( m_windowVariant
) ;
897 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
899 if (!m_macIsUserPane
)
901 SetInitialBestSize(size
);
904 SetCursor( *wxSTANDARD_CURSOR
) ;
907 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
909 // Don't assert, in case we set the window variant before
910 // the window is created
911 // wxASSERT( m_peer->Ok() ) ;
913 m_windowVariant
= variant
;
915 if (m_peer
== NULL
|| !m_peer
->Ok())
919 ThemeFontID themeFont
= kThemeSystemFont
;
921 // we will get that from the settings later
922 // and make this NORMAL later, but first
923 // we have a few calculations that we must fix
927 case wxWINDOW_VARIANT_NORMAL
:
928 size
= kControlSizeNormal
;
929 themeFont
= kThemeSystemFont
;
931 case wxWINDOW_VARIANT_SMALL
:
932 size
= kControlSizeSmall
;
933 themeFont
= kThemeSmallSystemFont
;
935 case wxWINDOW_VARIANT_MINI
:
936 if (UMAGetSystemVersion() >= 0x1030 )
938 // not always defined in the headers
944 size
= kControlSizeSmall
;
945 themeFont
= kThemeSmallSystemFont
;
948 case wxWINDOW_VARIANT_LARGE
:
949 size
= kControlSizeLarge
;
950 themeFont
= kThemeSystemFont
;
953 wxFAIL_MSG(_T("unexpected window variant"));
956 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
959 font
.MacCreateThemeFont( themeFont
) ;
963 void wxWindowMac::MacUpdateControlFont()
965 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
969 bool wxWindowMac::SetFont(const wxFont
& font
)
971 bool retval
= wxWindowBase::SetFont( font
) ;
973 MacUpdateControlFont() ;
978 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
980 if ( !wxWindowBase::SetForegroundColour(col
) )
983 MacUpdateControlFont() ;
988 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
990 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
994 wxColour
newCol(GetBackgroundColour());
995 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
997 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
999 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1001 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1005 brush
.SetColour( newCol
) ;
1007 MacSetBackgroundBrush( brush
) ;
1009 MacUpdateControlFont() ;
1014 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1016 m_macBackgroundBrush
= brush
;
1017 m_peer
->SetBackground( brush
) ;
1020 bool wxWindowMac::MacCanFocus() const
1022 // there is currently no way to determine whether the window is running in full keyboard
1023 // access mode, therefore we cannot rely on these features, yet the only other way would be
1024 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1025 // in event handlers...
1026 UInt32 features
= 0 ;
1027 m_peer
->GetFeatures( & features
) ;
1028 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1032 void wxWindowMac::SetFocus()
1034 if ( AcceptsFocus() )
1037 wxWindow
* former
= FindFocus() ;
1038 if ( former
== this )
1041 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1042 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1043 // leave in case of an error
1044 if ( err
== errCouldntSetFocus
)
1047 #if !TARGET_API_MAC_OSX
1048 // emulate carbon events when running under carbonlib where they are not natively available
1051 EventRef evRef
= NULL
;
1052 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1055 wxMacCarbonEvent
cEvent( evRef
) ;
1056 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1057 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1059 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1060 ReleaseEvent(evRef
) ;
1062 // send new focus event
1064 EventRef evRef
= NULL
;
1065 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1068 wxMacCarbonEvent
cEvent( evRef
) ;
1069 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1070 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1072 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1073 ReleaseEvent(evRef
) ;
1080 void wxWindowMac::DoCaptureMouse()
1082 wxApp::s_captureWindow
= this ;
1085 wxWindow
* wxWindowBase::GetCapture()
1087 return wxApp::s_captureWindow
;
1090 void wxWindowMac::DoReleaseMouse()
1092 wxApp::s_captureWindow
= NULL
;
1095 #if wxUSE_DRAG_AND_DROP
1097 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1099 if ( m_dropTarget
!= 0 ) {
1100 delete m_dropTarget
;
1103 m_dropTarget
= pDropTarget
;
1104 if ( m_dropTarget
!= 0 )
1112 // Old style file-manager drag&drop
1113 void wxWindowMac::DragAcceptFiles(bool accept
)
1118 // Returns the size of the native control. In the case of the toplevel window
1119 // this is the content area root control
1121 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1122 int& w
, int& h
) const
1124 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1127 // From a wx position / size calculate the appropriate size of the native control
1129 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1132 int& w
, int& h
, bool adjustOrigin
) const
1134 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1136 // the desired size, minus the border pixels gives the correct size of the control
1140 // todo the default calls may be used as soon as PostCreateControl Is moved here
1141 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1142 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1144 if ( !isCompositing
)
1145 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1147 x
+= MacGetLeftBorderSize() ;
1148 y
+= MacGetTopBorderSize() ;
1149 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1150 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1153 AdjustForParentClientOrigin( x
, y
) ;
1155 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1156 if ( !GetParent()->IsTopLevel() )
1158 x
-= GetParent()->MacGetLeftBorderSize() ;
1159 y
-= GetParent()->MacGetTopBorderSize() ;
1165 // Get window size (not client size)
1166 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1169 m_peer
->GetRect( &bounds
) ;
1171 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1172 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1175 // get the position of the bounds of this window in client coordinates of its parent
1176 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1179 m_peer
->GetRect( &bounds
) ;
1181 int x1
= bounds
.left
;
1182 int y1
= bounds
.top
;
1184 // get the wx window position from the native one
1185 x1
-= MacGetLeftBorderSize() ;
1186 y1
-= MacGetTopBorderSize() ;
1188 if ( !IsTopLevel() )
1190 wxWindow
*parent
= GetParent();
1193 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1194 x1
+= parent
->MacGetLeftBorderSize() ;
1195 y1
+= parent
->MacGetTopBorderSize() ;
1196 // and now to client coordinates
1197 wxPoint
pt(parent
->GetClientAreaOrigin());
1206 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1208 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1210 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1213 Point localwhere
= {0,0} ;
1215 if(x
) localwhere
.h
= * x
;
1216 if(y
) localwhere
.v
= * y
;
1218 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1219 if(x
) *x
= localwhere
.h
;
1220 if(y
) *y
= localwhere
.v
;
1223 MacRootWindowToWindow( x
, y
) ;
1225 wxPoint origin
= GetClientAreaOrigin() ;
1226 if(x
) *x
-= origin
.x
;
1227 if(y
) *y
-= origin
.y
;
1230 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1232 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1233 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1235 wxPoint origin
= GetClientAreaOrigin() ;
1236 if(x
) *x
+= origin
.x
;
1237 if(y
) *y
+= origin
.y
;
1239 MacWindowToRootWindow( x
, y
) ;
1242 Point localwhere
= { 0,0 };
1243 if(x
) localwhere
.h
= * x
;
1244 if(y
) localwhere
.v
= * y
;
1245 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1246 if(x
) *x
= localwhere
.h
;
1247 if(y
) *y
= localwhere
.v
;
1251 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1253 wxPoint origin
= GetClientAreaOrigin() ;
1254 if(x
) *x
+= origin
.x
;
1255 if(y
) *y
+= origin
.y
;
1257 MacWindowToRootWindow( x
, y
) ;
1260 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1262 MacRootWindowToWindow( x
, y
) ;
1264 wxPoint origin
= GetClientAreaOrigin() ;
1265 if(x
) *x
-= origin
.x
;
1266 if(y
) *y
-= origin
.y
;
1269 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1272 if ( x
) pt
.x
= *x
;
1273 if ( y
) pt
.y
= *y
;
1275 if ( !IsTopLevel() )
1277 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1280 pt
.x
-= MacGetLeftBorderSize() ;
1281 pt
.y
-= MacGetTopBorderSize() ;
1282 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1286 if ( x
) *x
= (int) pt
.x
;
1287 if ( y
) *y
= (int) pt
.y
;
1290 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1295 MacWindowToRootWindow( &x1
, &y1
) ;
1300 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1303 if ( x
) pt
.x
= *x
;
1304 if ( y
) pt
.y
= *y
;
1306 if ( !IsTopLevel() )
1308 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1311 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1312 pt
.x
+= MacGetLeftBorderSize() ;
1313 pt
.y
+= MacGetTopBorderSize() ;
1317 if ( x
) *x
= (int) pt
.x
;
1318 if ( y
) *y
= (int) pt
.y
;
1321 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1326 MacRootWindowToWindow( &x1
, &y1
) ;
1331 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1333 RgnHandle rgn
= NewRgn() ;
1334 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1338 GetRegionBounds( rgn
, &content
) ;
1339 m_peer
->GetRect( &structure
) ;
1340 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1342 left
= content
.left
- structure
.left
;
1343 top
= content
.top
- structure
.top
;
1344 right
= structure
.right
- content
.right
;
1345 bottom
= structure
.bottom
- content
.bottom
;
1349 left
= top
= right
= bottom
= 0 ;
1354 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1356 wxSize sizeTotal
= size
;
1358 RgnHandle rgn
= NewRgn() ;
1360 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1364 GetRegionBounds( rgn
, &content
) ;
1366 m_peer
->GetRect( &structure
) ;
1367 // structure is in parent coordinates, but we only need width and height, so it's ok
1369 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1370 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1374 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1375 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1381 // Get size *available for subwindows* i.e. excluding menu bar etc.
1382 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1386 RgnHandle rgn
= NewRgn() ;
1388 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1390 GetRegionBounds( rgn
, &content
) ;
1394 m_peer
->GetRect( &content
) ;
1398 ww
= content
.right
- content
.left
;
1399 hh
= content
.bottom
- content
.top
;
1401 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1403 hh
-= m_hScrollBar
->GetSize().y
;
1405 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1407 ww
-= m_vScrollBar
->GetSize().x
;
1414 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1416 if (m_cursor
== cursor
)
1419 if (wxNullCursor
== cursor
)
1421 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1426 if ( ! wxWindowBase::SetCursor( cursor
) )
1430 wxASSERT_MSG( m_cursor
.Ok(),
1431 wxT("cursor must be valid after call to the base version"));
1434 wxWindowMac
*mouseWin
= 0 ;
1436 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1437 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1439 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1441 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1442 // position, use it...
1446 ControlPartCode part
;
1447 ControlRef control
;
1448 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1450 mouseWin
= wxFindControlFromMacControl( control
) ;
1453 QDSwapPort( savePort
, NULL
) ;
1456 if ( mouseWin
== this && !wxIsBusy() )
1458 m_cursor
.MacInstall() ;
1465 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1467 menu
->SetInvokingWindow(this);
1470 if ( x
== -1 && y
== -1 )
1472 wxPoint mouse
= wxGetMousePosition();
1473 x
= mouse
.x
; y
= mouse
.y
;
1477 ClientToScreen( &x
, &y
) ;
1480 menu
->MacBeforeDisplay( true ) ;
1481 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1482 if ( HiWord(menuResult
) != 0 )
1485 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1486 wxMenuItem
* item
= NULL
;
1488 item
= menu
->FindItem(id
, &realmenu
) ;
1489 if (item
->IsCheckable())
1491 item
->Check( !item
->IsChecked() ) ;
1493 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1495 menu
->MacAfterDisplay( true ) ;
1497 menu
->SetInvokingWindow(NULL
);
1503 // ----------------------------------------------------------------------------
1505 // ----------------------------------------------------------------------------
1509 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1511 wxWindowBase::DoSetToolTip(tooltip
);
1514 m_tooltip
->SetWindow(this);
1517 #endif // wxUSE_TOOLTIPS
1519 void wxWindowMac::MacInvalidateBorders()
1521 if ( m_peer
== NULL
)
1524 bool vis
= MacIsReallyShown() ;
1528 int outerBorder
= MacGetLeftBorderSize() ;
1529 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1532 if ( outerBorder
== 0 )
1535 // now we know that we have something to do at all
1537 // as the borders are drawn on the parent we have to properly invalidate all these areas
1538 RgnHandle updateInner
= NewRgn() ,
1539 updateOuter
= NewRgn() ;
1541 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1543 m_peer
->GetRect( &rect
) ;
1544 RectRgn( updateInner
, &rect
) ;
1545 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1546 RectRgn( updateOuter
, &rect
) ;
1547 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1548 #ifdef __WXMAC_OSX__
1549 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1551 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1553 InvalWindowRgn( tlw
, updateOuter
) ;
1555 DisposeRgn(updateOuter
) ;
1556 DisposeRgn(updateInner
) ;
1558 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1559 RectRgn( updateInner , &rect ) ;
1560 InsetRect( &rect , -4 , -4 ) ;
1561 RectRgn( updateOuter , &rect ) ;
1562 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1563 wxPoint parent(0,0);
1564 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1565 parent -= GetParent()->GetClientAreaOrigin() ;
1566 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1567 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1568 DisposeRgn(updateOuter) ;
1569 DisposeRgn(updateInner) ;
1574 // deleting a window while it is shown invalidates the region occupied by border or
1577 if ( IsShown() && ( outerBorder > 0 ) )
1579 // as the borders are drawn on the parent we have to properly invalidate all these areas
1580 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1584 m_peer->GetRect( &rect ) ;
1585 RectRgn( updateInner , &rect ) ;
1586 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1587 RectRgn( updateOuter , &rect ) ;
1588 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1589 wxPoint parent(0,0);
1590 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1591 parent -= GetParent()->GetClientAreaOrigin() ;
1592 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1593 CopyRgn( updateOuter , updateTotal ) ;
1595 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1596 DisposeRgn(updateOuter) ;
1597 DisposeRgn(updateInner) ;
1598 DisposeRgn(updateTotal) ;
1603 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1605 int outerBorder
= MacGetLeftBorderSize() ;
1606 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1609 if ( vis
&& ( outerBorder
> 0 ) )
1611 // as the borders are drawn on the parent we have to properly invalidate all these areas
1612 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1616 m_peer
->GetRect( &rect
) ;
1617 RectRgn( updateInner
, &rect
) ;
1618 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1619 RectRgn( updateOuter
, &rect
) ;
1620 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1622 wxPoint parent(0,0);
1623 #if TARGET_API_MAC_OSX
1624 // no offsetting needed when compositing
1626 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1627 parent -= GetParent()->GetClientAreaOrigin() ;
1628 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1631 CopyRgn( updateOuter
, updateTotal
) ;
1634 RectRgn( updateInner
, &rect
) ;
1635 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1636 RectRgn( updateOuter
, &rect
) ;
1637 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1639 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1641 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1643 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1644 DisposeRgn(updateOuter
) ;
1645 DisposeRgn(updateInner
) ;
1646 DisposeRgn(updateTotal
) ;
1651 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1653 // this is never called for a toplevel window, so we know we have a parent
1654 int former_x
, former_y
, former_w
, former_h
;
1656 // Get true coordinates of former position
1657 DoGetPosition( &former_x
, &former_y
) ;
1658 DoGetSize( &former_w
, &former_h
) ;
1660 wxWindow
*parent
= GetParent();
1663 wxPoint
pt(parent
->GetClientAreaOrigin());
1668 int actualWidth
= width
;
1669 int actualHeight
= height
;
1673 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1674 actualWidth
= m_minWidth
;
1675 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1676 actualHeight
= m_minHeight
;
1677 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1678 actualWidth
= m_maxWidth
;
1679 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1680 actualHeight
= m_maxHeight
;
1682 bool doMove
= false ;
1683 bool doResize
= false ;
1685 if ( actualX
!= former_x
|| actualY
!= former_y
)
1689 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1694 if ( doMove
|| doResize
)
1696 // as the borders are drawn outside the native control, we adjust now
1698 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1699 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1700 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1703 wxMacRectToNative( &bounds
, &r
) ;
1705 if ( !GetParent()->IsTopLevel() )
1707 wxMacWindowToNative( GetParent() , &r
) ;
1710 MacInvalidateBorders() ;
1712 m_cachedClippedRectValid
= false ;
1713 m_peer
->SetRect( &r
) ;
1715 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1717 MacInvalidateBorders() ;
1719 MacRepositionScrollBars() ;
1722 wxPoint
point(actualX
,actualY
);
1723 wxMoveEvent
event(point
, m_windowId
);
1724 event
.SetEventObject(this);
1725 GetEventHandler()->ProcessEvent(event
) ;
1729 MacRepositionScrollBars() ;
1730 wxSize
size(actualWidth
, actualHeight
);
1731 wxSizeEvent
event(size
, m_windowId
);
1732 event
.SetEventObject(this);
1733 GetEventHandler()->ProcessEvent(event
);
1739 wxSize
wxWindowMac::DoGetBestSize() const
1741 if ( m_macIsUserPane
|| IsTopLevel() )
1742 return wxWindowBase::DoGetBestSize() ;
1744 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1745 int bestWidth
, bestHeight
;
1746 m_peer
->GetBestRect( &bestsize
) ;
1748 if ( EmptyRect( &bestsize
) )
1750 bestsize
.left
= bestsize
.top
= 0 ;
1751 bestsize
.right
= 16 ;
1752 bestsize
.bottom
= 16 ;
1753 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1755 bestsize
.bottom
= 16 ;
1758 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1760 bestsize
.bottom
= 24 ;
1762 #endif // wxUSE_SPINBTN
1765 // return wxWindowBase::DoGetBestSize() ;
1769 bestWidth
= bestsize
.right
- bestsize
.left
;
1770 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1771 if ( bestHeight
< 10 )
1774 return wxSize(bestWidth
, bestHeight
);
1778 // set the size of the window: if the dimensions are positive, just use them,
1779 // but if any of them is equal to -1, it means that we must find the value for
1780 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1781 // which case -1 is a valid value for x and y)
1783 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1784 // the width/height to best suit our contents, otherwise we reuse the current
1786 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1788 // get the current size and position...
1789 int currentX
, currentY
;
1790 GetPosition(¤tX
, ¤tY
);
1792 int currentW
,currentH
;
1793 GetSize(¤tW
, ¤tH
);
1795 // ... and don't do anything (avoiding flicker) if it's already ok
1796 if ( x
== currentX
&& y
== currentY
&&
1797 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1800 MacRepositionScrollBars() ; // we might have a real position shift
1804 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1806 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1809 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1811 wxSize size
= wxDefaultSize
;
1812 if ( width
== wxDefaultCoord
)
1814 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1816 size
= DoGetBestSize();
1821 // just take the current one
1826 if ( height
== wxDefaultCoord
)
1828 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1830 if ( size
.x
== wxDefaultCoord
)
1832 size
= DoGetBestSize();
1834 //else: already called DoGetBestSize() above
1840 // just take the current one
1845 DoMoveWindow(x
, y
, width
, height
);
1849 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1851 RgnHandle rgn
= NewRgn() ;
1853 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1855 GetRegionBounds( rgn
, &content
) ;
1859 content
.left
= content
.top
= 0 ;
1862 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1865 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1867 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1869 int currentclientwidth
, currentclientheight
;
1870 int currentwidth
, currentheight
;
1872 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1873 GetSize( ¤twidth
, ¤theight
) ;
1875 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1876 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1880 void wxWindowMac::SetTitle(const wxString
& title
)
1882 m_label
= wxStripMenuCodes(title
) ;
1884 if ( m_peer
&& m_peer
->Ok() )
1886 m_peer
->SetTitle( m_label
) ;
1891 wxString
wxWindowMac::GetTitle() const
1896 bool wxWindowMac::Show(bool show
)
1898 bool former
= MacIsReallyShown() ;
1899 if ( !wxWindowBase::Show(show
) )
1902 // TODO use visibilityChanged Carbon Event for OSX
1905 m_peer
->SetVisibility( show
, true ) ;
1907 if ( former
!= MacIsReallyShown() )
1908 MacPropagateVisibilityChanged() ;
1912 bool wxWindowMac::Enable(bool enable
)
1914 wxASSERT( m_peer
->Ok() ) ;
1915 bool former
= MacIsReallyEnabled() ;
1916 if ( !wxWindowBase::Enable(enable
) )
1919 m_peer
->Enable( enable
) ;
1921 if ( former
!= MacIsReallyEnabled() )
1922 MacPropagateEnabledStateChanged() ;
1927 // status change propagations (will be not necessary for OSX later )
1930 void wxWindowMac::MacPropagateVisibilityChanged()
1932 #if !TARGET_API_MAC_OSX
1933 MacVisibilityChanged() ;
1935 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1938 wxWindowMac
*child
= node
->GetData();
1939 if ( child
->IsShown() )
1940 child
->MacPropagateVisibilityChanged( ) ;
1941 node
= node
->GetNext();
1946 void wxWindowMac::MacPropagateEnabledStateChanged( )
1948 #if !TARGET_API_MAC_OSX
1949 MacEnabledStateChanged() ;
1951 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1954 wxWindowMac
*child
= node
->GetData();
1955 if ( child
->IsEnabled() )
1956 child
->MacPropagateEnabledStateChanged() ;
1957 node
= node
->GetNext();
1962 void wxWindowMac::MacPropagateHiliteChanged( )
1964 #if !TARGET_API_MAC_OSX
1965 MacHiliteChanged() ;
1967 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1970 wxWindowMac
*child
= node
->GetData();
1971 // if ( child->IsEnabled() )
1972 child
->MacPropagateHiliteChanged() ;
1973 node
= node
->GetNext();
1979 // status change notifications
1982 void wxWindowMac::MacVisibilityChanged()
1986 void wxWindowMac::MacHiliteChanged()
1990 void wxWindowMac::MacEnabledStateChanged()
1995 // status queries on the inherited window's state
1998 bool wxWindowMac::MacIsReallyShown()
2000 // only under OSX the visibility of the TLW is taken into account
2001 if ( m_isBeingDeleted
)
2004 #if TARGET_API_MAC_OSX
2005 if ( m_peer
&& m_peer
->Ok() )
2006 return m_peer
->IsVisible();
2008 wxWindow
* win
= this ;
2009 while( win
->IsShown() )
2011 if ( win
->IsTopLevel() )
2014 win
= win
->GetParent() ;
2022 bool wxWindowMac::MacIsReallyEnabled()
2024 return m_peer
->IsEnabled() ;
2027 bool wxWindowMac::MacIsReallyHilited()
2029 return m_peer
->IsActive();
2032 void wxWindowMac::MacFlashInvalidAreas()
2034 #if TARGET_API_MAC_OSX
2035 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2043 int wxWindowMac::GetCharHeight() const
2045 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2046 return dc
.GetCharHeight() ;
2049 int wxWindowMac::GetCharWidth() const
2051 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2052 return dc
.GetCharWidth() ;
2055 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2056 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2058 const wxFont
*fontToUse
= theFont
;
2060 fontToUse
= &m_font
;
2062 wxClientDC
dc( (wxWindowMac
*) this ) ;
2064 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2065 if ( externalLeading
)
2066 *externalLeading
= le
;
2076 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2077 * we always intersect with the entire window, not only with the client area
2080 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2082 if ( m_peer
== NULL
)
2085 if ( !MacIsReallyShown() )
2091 wxMacRectToNative( rect
, &r
) ;
2092 m_peer
->SetNeedsDisplay( &r
) ;
2096 m_peer
->SetNeedsDisplay() ;
2100 void wxWindowMac::Freeze()
2102 #if TARGET_API_MAC_OSX
2103 if ( !m_frozenness
++ )
2105 if ( m_peer
&& m_peer
->Ok() )
2106 m_peer
->SetDrawingEnabled( false ) ;
2112 void wxWindowMac::Thaw()
2114 #if TARGET_API_MAC_OSX
2115 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2117 if ( !--m_frozenness
)
2119 if ( m_peer
&& m_peer
->Ok() )
2121 m_peer
->SetDrawingEnabled( true ) ;
2122 m_peer
->InvalidateWithChildren() ;
2128 wxWindowMac
*wxGetActiveWindow()
2130 // actually this is a windows-only concept
2134 // Coordinates relative to the window
2135 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2137 // We really don't move the mouse programmatically under Mac.
2140 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2142 if ( MacGetTopLevelWindow() == NULL
)
2144 #if TARGET_API_MAC_OSX
2145 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2152 event
.GetDC()->Clear() ;
2156 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2161 int wxWindowMac::GetScrollPos(int orient
) const
2163 if ( orient
== wxHORIZONTAL
)
2166 return m_hScrollBar
->GetThumbPosition() ;
2171 return m_vScrollBar
->GetThumbPosition() ;
2176 // This now returns the whole range, not just the number
2177 // of positions that we can scroll.
2178 int wxWindowMac::GetScrollRange(int orient
) const
2180 if ( orient
== wxHORIZONTAL
)
2183 return m_hScrollBar
->GetRange() ;
2188 return m_vScrollBar
->GetRange() ;
2193 int wxWindowMac::GetScrollThumb(int orient
) const
2195 if ( orient
== wxHORIZONTAL
)
2198 return m_hScrollBar
->GetThumbSize() ;
2203 return m_vScrollBar
->GetThumbSize() ;
2208 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2210 if ( orient
== wxHORIZONTAL
)
2213 m_hScrollBar
->SetThumbPosition( pos
) ;
2218 m_vScrollBar
->SetThumbPosition( pos
) ;
2223 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2224 // our own window origin is at leftOrigin/rightOrigin
2227 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2233 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2234 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2236 m_peer
->GetRect( &rect
) ;
2237 // back to the surrounding frame rectangle
2238 InsetRect( &rect
, -1 , -1 ) ;
2240 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2241 if ( UMAGetSystemVersion() >= 0x1030 )
2243 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2244 rect
.bottom
- rect
.top
) ;
2246 HIThemeFrameDrawInfo info
;
2247 memset( &info
, 0 , sizeof( info
) ) ;
2251 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2252 info
.isFocused
= hasFocus
;
2254 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2255 wxASSERT( cgContext
) ;
2257 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2259 info
.kind
= kHIThemeFrameTextFieldSquare
;
2260 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2262 else if (HasFlag(wxSIMPLE_BORDER
))
2264 info
.kind
= kHIThemeFrameListBox
;
2265 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2267 else if ( hasFocus
)
2269 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2272 m_peer
->GetRect( &rect
) ;
2273 if ( hasBothScrollbars
)
2275 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2276 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2277 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2278 HIThemeGrowBoxDrawInfo info
;
2279 memset( &info
, 0 , sizeof( info
) ) ;
2281 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2282 info
.kind
= kHIThemeGrowBoxKindNone
;
2283 info
.size
= kHIThemeGrowBoxSizeNormal
;
2284 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2285 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2291 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2295 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2296 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2299 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2301 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2303 else if (HasFlag(wxSIMPLE_BORDER
))
2305 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2310 DrawThemeFocusRect( &rect
, true ) ;
2313 if ( hasBothScrollbars
)
2315 // GetThemeStandaloneGrowBoxBounds
2316 //DrawThemeStandaloneNoGrowBox
2321 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2323 if ( child
== m_hScrollBar
)
2324 m_hScrollBar
= NULL
;
2325 if ( child
== m_vScrollBar
)
2326 m_vScrollBar
= NULL
;
2328 wxWindowBase::RemoveChild( child
) ;
2331 // New function that will replace some of the above.
2332 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2333 int range
, bool refresh
)
2335 if ( orient
== wxHORIZONTAL
)
2339 if ( range
== 0 || thumbVisible
>= range
)
2341 if ( m_hScrollBar
->IsShown() )
2342 m_hScrollBar
->Show(false) ;
2346 if ( !m_hScrollBar
->IsShown() )
2347 m_hScrollBar
->Show(true) ;
2349 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2356 if ( range
== 0 || thumbVisible
>= range
)
2358 if ( m_vScrollBar
->IsShown() )
2359 m_vScrollBar
->Show(false) ;
2363 if ( !m_vScrollBar
->IsShown() )
2364 m_vScrollBar
->Show(true) ;
2366 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2369 MacRepositionScrollBars() ;
2372 // Does a physical scroll
2373 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2375 if( dx
== 0 && dy
==0 )
2378 int width
, height
;
2379 GetClientSize( &width
, &height
) ;
2380 #if TARGET_API_MAC_OSX
2381 if ( 1 /* m_peer->IsCompositing() */ )
2383 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2384 // area is scrolled, this does not occur if width and height are 2 pixels less,
2385 // TODO write optimal workaround
2386 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2389 scrollrect
.Intersect( *rect
) ;
2391 if ( m_peer
->GetNeedsDisplay() )
2393 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2394 // either immediate redraw or full invalidate
2396 // is the better overall solution, as it does not slow down scrolling
2397 m_peer
->SetNeedsDisplay() ;
2399 // this would be the preferred version for fast drawing controls
2401 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2402 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2403 HIViewRender(m_peer
->GetControlRef()) ;
2409 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2410 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2411 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2413 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2414 // either immediate redraw or full invalidate
2416 // is the better overall solution, as it does not slow down scrolling
2417 m_peer
->SetNeedsDisplay() ;
2419 // this would be the preferred version for fast drawing controls
2421 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2422 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2423 HIViewRender(m_peer
->GetControlRef()) ;
2438 RgnHandle updateRgn
= NewRgn() ;
2441 wxClientDC
dc(this) ;
2442 wxMacPortSetter
helper(&dc
) ;
2444 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2445 //scrollrect.top += MacGetTopBorderSize() ;
2446 //scrollrect.left += MacGetLeftBorderSize() ;
2447 scrollrect
.bottom
= scrollrect
.top
+ height
;
2448 scrollrect
.right
= scrollrect
.left
+ width
;
2452 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2453 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2454 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2456 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2458 // now scroll the former update region as well and add the new update region
2460 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2461 RgnHandle formerUpdateRgn
= NewRgn() ;
2462 RgnHandle scrollRgn
= NewRgn() ;
2463 RectRgn( scrollRgn
, &scrollrect
) ;
2464 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2466 LocalToGlobal( &pt
) ;
2467 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2468 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2469 if ( !EmptyRgn( formerUpdateRgn
) )
2471 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2472 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2473 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2475 InvalWindowRgn(rootWindow
, updateRgn
) ;
2476 DisposeRgn( updateRgn
) ;
2477 DisposeRgn( formerUpdateRgn
) ;
2478 DisposeRgn( scrollRgn
) ;
2483 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2485 wxWindowMac
*child
= node
->GetData();
2486 if (child
== m_vScrollBar
) continue;
2487 if (child
== m_hScrollBar
) continue;
2488 if (child
->IsTopLevel()) continue;
2491 child
->GetPosition( &x
, &y
);
2493 child
->GetSize( &w
, &h
);
2497 if (rect
->Intersects(rc
))
2498 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2502 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2507 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2509 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2511 wxScrollWinEvent wevent
;
2512 wevent
.SetPosition(event
.GetPosition());
2513 wevent
.SetOrientation(event
.GetOrientation());
2514 wevent
.SetEventObject(this);
2516 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2517 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2518 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2519 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2520 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2521 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2522 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2523 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2524 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2525 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2526 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2527 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2528 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2529 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2530 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2531 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2533 GetEventHandler()->ProcessEvent(wevent
);
2537 // Get the window with the focus
2538 wxWindowMac
*wxWindowBase::DoFindFocus()
2540 ControlRef control
;
2541 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2542 return wxFindControlFromMacControl( control
) ;
2545 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2547 // panel wants to track the window which was the last to have focus in it,
2548 // so we want to set ourselves as the window which last had focus
2550 // notice that it's also important to do it upwards the tree becaus
2551 // otherwise when the top level panel gets focus, it won't set it back to
2552 // us, but to some other sibling
2554 // CS:don't know if this is still needed:
2555 //wxChildFocusEvent eventFocus(this);
2556 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2558 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2560 #if !wxMAC_USE_CORE_GRAPHICS
2561 wxMacWindowStateSaver
sv( this ) ;
2563 m_peer
->GetRect( &rect
) ;
2564 // auf den umgebenden Rahmen zur\9fck
2565 InsetRect( &rect
, -1 , -1 ) ;
2567 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2571 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2573 rect
.right
+= pt
.x
;
2575 rect
.bottom
+= pt
.y
;
2578 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2579 DrawThemeFocusRect( &rect
, true ) ;
2582 DrawThemeFocusRect( &rect
, false ) ;
2584 // as this erases part of the frame we have to redraw borders
2585 // and because our z-ordering is not always correct (staticboxes)
2586 // we have to invalidate things, we cannot simple redraw
2587 MacInvalidateBorders() ;
2590 GetParent()->Refresh() ;
2597 void wxWindowMac::OnInternalIdle()
2599 // This calls the UI-update mechanism (querying windows for
2600 // menu/toolbar/control state information)
2601 if (wxUpdateUIEvent::CanUpdate(this))
2602 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2605 // Raise the window to the top of the Z order
2606 void wxWindowMac::Raise()
2608 m_peer
->SetZOrder( true , NULL
) ;
2611 // Lower the window to the bottom of the Z order
2612 void wxWindowMac::Lower()
2614 m_peer
->SetZOrder( false , NULL
) ;
2618 // static wxWindow *gs_lastWhich = NULL;
2620 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2622 // first trigger a set cursor event
2624 wxPoint clientorigin
= GetClientAreaOrigin() ;
2625 wxSize clientsize
= GetClientSize() ;
2627 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2629 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2631 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2632 if ( processedEvtSetCursor
&& event
.HasCursor() )
2634 cursor
= event
.GetCursor() ;
2639 // the test for processedEvtSetCursor is here to prevent using m_cursor
2640 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2641 // it - this is a way to say that our cursor shouldn't be used for this
2643 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2653 cursor
= *wxSTANDARD_CURSOR
;
2657 cursor
.MacInstall() ;
2659 return cursor
.Ok() ;
2662 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2667 return m_tooltip
->GetTip() ;
2670 return wxEmptyString
;
2673 void wxWindowMac::ClearBackground()
2679 void wxWindowMac::Update()
2681 #if TARGET_API_MAC_OSX
2682 MacGetTopLevelWindow()->MacPerformUpdates() ;
2684 ::Draw1Control( m_peer
->GetControlRef() ) ;
2688 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2690 wxTopLevelWindowMac
* win
= NULL
;
2691 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2694 win
= wxFindWinFromMacWindow( window
) ;
2699 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2701 MacUpdateClippedRects() ;
2702 return m_cachedClippedClientRect
;
2705 const wxRect
& wxWindowMac::MacGetClippedRect() const
2707 MacUpdateClippedRects() ;
2708 return m_cachedClippedRect
;
2711 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2713 MacUpdateClippedRects() ;
2714 return m_cachedClippedRectWithOuterStructure
;
2717 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2719 static wxRegion emptyrgn
;
2720 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2722 MacUpdateClippedRects() ;
2723 if ( includeOuterStructures
)
2724 return m_cachedClippedRegionWithOuterStructure
;
2726 return m_cachedClippedRegion
;
2734 void wxWindowMac::MacUpdateClippedRects() const
2736 if ( m_cachedClippedRectValid
)
2739 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2740 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2741 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2742 // to add focus borders everywhere
2745 Rect rIncludingOuterStructures
;
2747 m_peer
->GetRect( &r
) ;
2748 r
.left
-= MacGetLeftBorderSize() ;
2749 r
.top
-= MacGetTopBorderSize() ;
2750 r
.bottom
+= MacGetBottomBorderSize() ;
2751 r
.right
+= MacGetRightBorderSize() ;
2758 rIncludingOuterStructures
= r
;
2759 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2761 wxRect cl
= GetClientRect() ;
2762 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2764 const wxWindow
* child
= this ;
2765 const wxWindow
* parent
= NULL
;
2766 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2771 if ( parent
->MacIsChildOfClientArea(child
) )
2773 size
= parent
->GetClientSize() ;
2774 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2780 // this will be true for scrollbars, toolbars etc.
2781 size
= parent
->GetSize() ;
2782 y
= parent
->MacGetTopBorderSize() ;
2783 x
= parent
->MacGetLeftBorderSize() ;
2784 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2785 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2788 parent
->MacWindowToRootWindow( &x
, &y
) ;
2789 MacRootWindowToWindow( &x
, &y
) ;
2791 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2793 // the wxwindow and client rects will always be clipped
2794 SectRect( &r
, &rparent
, &r
) ;
2795 SectRect( &rClient
, &rparent
, &rClient
) ;
2797 // the structure only at 'hard' borders
2798 if ( parent
->MacClipChildren() ||
2799 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2801 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2806 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2807 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2808 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2809 m_cachedClippedRectWithOuterStructure
= wxRect(
2810 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2811 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2812 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2814 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2815 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2816 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2818 m_cachedClippedRectValid
= true ;
2822 This function must not change the updatergn !
2824 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2826 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2827 bool handled
= false ;
2829 GetRegionBounds( updatergn
, &updatebounds
) ;
2831 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2833 if ( !EmptyRgn(updatergn
) )
2835 RgnHandle newupdate
= NewRgn() ;
2836 wxSize point
= GetClientSize() ;
2837 wxPoint origin
= GetClientAreaOrigin() ;
2838 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2839 SectRgn( newupdate
, updatergn
, newupdate
) ;
2841 // first send an erase event to the entire update area
2843 // for the toplevel window this really is the entire area
2844 // for all the others only their client area, otherwise they
2845 // might be drawing with full alpha and eg put blue into
2846 // the grow-box area of a scrolled window (scroll sample)
2847 wxDC
* dc
= new wxWindowDC(this);
2849 dc
->SetClippingRegion(wxRegion(updatergn
));
2851 dc
->SetClippingRegion(wxRegion(newupdate
));
2853 wxEraseEvent
eevent( GetId(), dc
);
2854 eevent
.SetEventObject( this );
2855 GetEventHandler()->ProcessEvent( eevent
);
2859 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2860 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2861 m_updateRegion
= newupdate
;
2862 DisposeRgn( newupdate
) ;
2864 if ( !m_updateRegion
.Empty() )
2866 // paint the window itself
2869 event
.SetTimestamp(time
);
2870 event
.SetEventObject(this);
2871 GetEventHandler()->ProcessEvent(event
);
2875 // now we cannot rely on having its borders drawn by a window itself, as it does not
2876 // get the updateRgn wide enough to always do so, so we do it from the parent
2877 // this would also be the place to draw any custom backgrounds for native controls
2878 // in Composited windowing
2879 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2881 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2883 wxWindowMac
*child
= node
->GetData();
2884 if (child
== m_vScrollBar
) continue;
2885 if (child
== m_hScrollBar
) continue;
2886 if (child
->IsTopLevel()) continue;
2887 if (!child
->IsShown()) continue;
2889 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2892 child
->GetPosition( &x
, &y
);
2894 child
->GetSize( &w
, &h
);
2895 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2896 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2897 InsetRect( &childRect
, -10 , -10) ;
2899 if ( RectInRgn( &childRect
, updatergn
) )
2902 // paint custom borders
2903 wxNcPaintEvent
eventNc( child
->GetId() );
2904 eventNc
.SetEventObject( child
);
2905 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2907 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2908 if ( UMAGetSystemVersion() >= 0x1030 )
2910 child
->MacPaintBorders(0,0) ;
2915 wxWindowDC
dc(this) ;
2916 dc
.SetClippingRegion(wxRegion(updatergn
));
2917 wxMacPortSetter
helper(&dc
) ;
2918 child
->MacPaintBorders(0,0) ;
2928 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2930 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2934 if ( iter
->IsTopLevel() )
2935 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2937 iter
= iter
->GetParent() ;
2939 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2943 void wxWindowMac::MacCreateScrollBars( long style
)
2945 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2947 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2949 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2950 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2951 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2952 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2954 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2955 variant
= wxWINDOW_VARIANT_SMALL
;
2958 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2960 GetClientSize( &width
, &height
) ;
2962 wxPoint
vPoint(width
-scrlsize
, 0) ;
2963 wxSize
vSize(scrlsize
, height
- adjust
) ;
2964 wxPoint
hPoint(0 , height
-scrlsize
) ;
2965 wxSize
hSize( width
- adjust
, scrlsize
) ;
2968 if ( style
& wxVSCROLL
)
2970 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2971 vSize
, wxVERTICAL
);
2974 if ( style
& wxHSCROLL
)
2976 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2977 hSize
, wxHORIZONTAL
);
2982 // because the create does not take into account the client area origin
2983 MacRepositionScrollBars() ; // we might have a real position shift
2986 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2988 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
2994 void wxWindowMac::MacRepositionScrollBars()
2996 if ( !m_hScrollBar
&& !m_vScrollBar
)
2999 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3000 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3001 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3003 // get real client area
3007 GetSize( &width
, &height
) ;
3009 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3010 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3012 wxPoint
vPoint(width
-scrlsize
, 0) ;
3013 wxSize
vSize(scrlsize
, height
- adjust
) ;
3014 wxPoint
hPoint(0 , height
-scrlsize
) ;
3015 wxSize
hSize( width
- adjust
, scrlsize
) ;
3021 GetSize( &w , &h ) ;
3023 MacClientToRootWindow( &x , &y ) ;
3024 MacClientToRootWindow( &w , &h ) ;
3026 wxWindowMac *iter = (wxWindowMac*)this ;
3028 int totW = 10000 , totH = 10000;
3031 if ( iter->IsTopLevel() )
3033 iter->GetSize( &totW , &totH ) ;
3037 iter = iter->GetParent() ;
3065 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3069 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3073 bool wxWindowMac::AcceptsFocus() const
3075 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3078 void wxWindowMac::MacSuperChangedPosition()
3080 m_cachedClippedRectValid
= false ;
3081 // only window-absolute structures have to be moved i.e. controls
3083 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3086 wxWindowMac
*child
= node
->GetData();
3087 child
->MacSuperChangedPosition() ;
3088 node
= node
->GetNext();
3092 void wxWindowMac::MacTopLevelWindowChangedPosition()
3094 // only screen-absolute structures have to be moved i.e. glcanvas
3096 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3099 wxWindowMac
*child
= node
->GetData();
3100 child
->MacTopLevelWindowChangedPosition() ;
3101 node
= node
->GetNext();
3105 long wxWindowMac::MacGetLeftBorderSize( ) const
3112 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3114 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3115 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3117 else if (HasFlag(wxSIMPLE_BORDER
))
3119 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3120 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3125 long wxWindowMac::MacGetRightBorderSize( ) const
3127 // they are all symmetric in mac themes
3128 return MacGetLeftBorderSize() ;
3131 long wxWindowMac::MacGetTopBorderSize( ) const
3133 // they are all symmetric in mac themes
3134 return MacGetLeftBorderSize() ;
3137 long wxWindowMac::MacGetBottomBorderSize( ) const
3139 // they are all symmetric in mac themes
3140 return MacGetLeftBorderSize() ;
3143 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3145 return style
& ~wxBORDER_MASK
;
3148 // Find the wxWindowMac at the current mouse position, returning the mouse
3150 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3152 pt
= wxGetMousePosition();
3153 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3157 // Get the current mouse position.
3158 wxPoint
wxGetMousePosition()
3161 wxGetMousePosition(& x
, & y
);
3162 return wxPoint(x
, y
);
3165 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3167 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3169 // copied from wxGTK : CS
3170 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3173 // (a) it's a command event and so is propagated to the parent
3174 // (b) under MSW it can be generated from kbd too
3175 // (c) it uses screen coords (because of (a))
3176 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3178 this->ClientToScreen(event
.GetPosition()));
3179 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3188 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3190 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3192 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3196 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3200 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3204 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3205 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3209 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3211 return eventNotHandledErr
;
3214 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3216 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3218 if ( !wxWindowBase::Reparent(newParent
) )
3221 //copied from MacPostControlCreate
3222 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3223 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3224 ::EmbedControl( m_peer
->GetControlRef() , container
) ;