1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/window.h"
17 #include "wx/dcclient.h"
21 #include "wx/layout.h"
22 #include "wx/dialog.h"
23 #include "wx/scrolbar.h"
24 #include "wx/statbox.h"
25 #include "wx/button.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
29 #include "wx/tooltip.h"
30 #include "wx/statusbr.h"
31 #include "wx/menuitem.h"
32 #include "wx/spinctrl.h"
34 #include "wx/geometry.h"
35 #include "wx/textctrl.h"
37 #include "wx/toolbar.h"
44 #define MAC_SCROLLBAR_SIZE 15
45 #define MAC_SMALL_SCROLLBAR_SIZE 11
47 #include "wx/mac/uma.h"
51 #include <ToolUtils.h>
53 #include <MacTextEditor.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
76 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
77 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
78 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
79 #if TARGET_API_MAC_OSX
80 EVT_PAINT(wxWindowMac::OnPaint
)
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 #define wxMAC_USE_THEME_BORDER 1
94 // ---------------------------------------------------------------------------
95 // Utility Routines to move between different coordinate systems
96 // ---------------------------------------------------------------------------
99 * Right now we have the following setup :
100 * a border that is not part of the native control is always outside the
101 * control's border (otherwise we loose all native intelligence, future ways
102 * may be to have a second embedding control responsible for drawing borders
103 * and backgrounds eventually)
104 * so all this border calculations have to be taken into account when calling
105 * native methods or getting native oriented data
106 * so we have three coordinate systems here
107 * wx client coordinates
108 * wx window coordinates (including window frames)
113 // originating from native control
117 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
119 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
122 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
124 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
128 // directed towards native control
131 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
133 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
136 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
138 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
146 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
148 #if TARGET_API_MAC_OSX
150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
153 kEventControlVisibilityChanged
= 157
159 static const EventTypeSpec eventList
[] =
161 { kEventClassControl
, kEventControlHit
} ,
163 #if TARGET_API_MAC_OSX
164 { kEventClassControl
, kEventControlDraw
} ,
165 { kEventClassControl
, kEventControlVisibilityChanged
} ,
166 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
167 { kEventClassControl
, kEventControlHiliteChanged
} ,
168 { kEventClassControl
, kEventControlSetFocusPart
} ,
170 { kEventClassService
, kEventServiceGetTypes
},
171 { kEventClassService
, kEventServiceCopy
},
172 { kEventClassService
, kEventServicePaste
},
174 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
175 // { kEventClassControl , kEventControlBoundsChanged } ,
179 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
181 OSStatus result
= eventNotHandledErr
;
183 wxMacCarbonEvent
cEvent( event
) ;
185 ControlRef controlRef
;
186 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
188 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
190 switch ( GetEventKind( event
) )
192 #if TARGET_API_MAC_OSX
193 case kEventControlDraw
:
195 RgnHandle updateRgn
= NULL
;
196 RgnHandle allocatedRgn
= NULL
;
197 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
200 if ( ! thisWindow
->GetPeer()->IsCompositing() )
202 if ( thisWindow
->GetPeer()->IsRootControl() )
203 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
205 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
208 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
210 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
214 if ( ! thisWindow
->GetPeer()->IsCompositing() )
216 allocatedRgn
= NewRgn() ;
217 CopyRgn( updateRgn
, allocatedRgn
) ;
218 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
220 // hide the given region by the new region that must be shifted
221 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
222 updateRgn
= allocatedRgn
;
226 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
228 // as this update region is in native window locals we must adapt it to wx window local
229 allocatedRgn
= NewRgn() ;
230 CopyRgn( updateRgn
, allocatedRgn
) ;
232 // hide the given region by the new region that must be shifted
233 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
234 updateRgn
= allocatedRgn
;
240 GetRegionBounds( updateRgn
, &rgnBounds
) ;
242 #if wxMAC_DEBUG_REDRAW
243 if ( thisWindow
->MacIsUserPane() )
245 static float color
= 0.5 ;
248 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
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
);
266 #if wxMAC_USE_CORE_GRAPHICS
267 bool created
= false ;
268 CGContextRef cgContext
= 0 ;
269 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
271 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
273 // this parameter is not provided on non-composited windows
276 // rest of the code expects this to be already transformed and clipped for local
277 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
279 GetPortBounds( port
, &bounds
) ;
280 CreateCGContextForPort( port
, &cgContext
) ;
282 wxMacWindowToNative( thisWindow
, updateRgn
) ;
283 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
284 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
285 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
286 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
288 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
289 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
291 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
294 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
295 CGContextFillRect(cgContext
, CGRectMake( 0 , 0 ,
296 controlBounds
.right
- controlBounds
.left
,
297 controlBounds
.bottom
- controlBounds
.top
) );
302 thisWindow
->MacSetCGContextRef( cgContext
) ;
305 wxMacCGContextStateSaver
sg( cgContext
) ;
307 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
310 #if wxMAC_USE_CORE_GRAPHICS
311 thisWindow
->MacSetCGContextRef( NULL
) ;
315 CGContextRelease( cgContext
) ;
320 DisposeRgn( allocatedRgn
) ;
324 case kEventControlVisibilityChanged
:
325 thisWindow
->MacVisibilityChanged() ;
328 case kEventControlEnabledStateChanged
:
329 thisWindow
->MacEnabledStateChanged() ;
332 case kEventControlHiliteChanged
:
333 thisWindow
->MacHiliteChanged() ;
337 // we emulate this event under Carbon CFM
338 case kEventControlSetFocusPart
:
340 Boolean focusEverything
= false ;
341 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
344 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
349 if ( controlPart
== kControlFocusNoPart
)
352 if ( thisWindow
->GetCaret() )
353 thisWindow
->GetCaret()->OnKillFocus();
356 static bool inKillFocusEvent
= false ;
358 if ( !inKillFocusEvent
)
360 inKillFocusEvent
= true ;
361 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
362 event
.SetEventObject(thisWindow
);
363 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
364 inKillFocusEvent
= false ;
369 // panel wants to track the window which was the last to have focus in it
370 wxChildFocusEvent
eventFocus(thisWindow
);
371 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
374 if ( thisWindow
->GetCaret() )
375 thisWindow
->GetCaret()->OnSetFocus();
378 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
379 event
.SetEventObject(thisWindow
);
380 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
383 if ( thisWindow
->MacIsUserPane() )
388 case kEventControlHit
:
389 result
= thisWindow
->MacControlHit( handler
, event
) ;
399 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
401 OSStatus result
= eventNotHandledErr
;
403 wxMacCarbonEvent
cEvent( event
) ;
405 ControlRef controlRef
;
406 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
407 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
408 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
410 switch ( GetEventKind( event
) )
412 case kEventServiceGetTypes
:
416 textCtrl
->GetSelection( &from
, &to
) ;
418 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
420 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
421 if ( textCtrl
->IsEditable() )
422 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
424 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
425 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
427 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
431 CFArrayAppendValue(copyTypes
, typestring
) ;
433 CFArrayAppendValue(pasteTypes
, typestring
) ;
435 CFRelease( typestring
) ;
443 case kEventServiceCopy
:
448 textCtrl
->GetSelection( &from
, &to
) ;
449 wxString val
= textCtrl
->GetValue() ;
450 val
= val
.Mid( from
, to
- from
) ;
451 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
452 verify_noerr( ClearScrap( &scrapRef
) ) ;
453 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
458 case kEventServicePaste
:
461 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
462 Size textSize
, pastedSize
;
463 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
465 char *content
= new char[textSize
] ;
466 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
467 content
[textSize
- 1] = 0 ;
470 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
472 textCtrl
->WriteText( wxString( content
) ) ;
487 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
489 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
490 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
491 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
492 OSStatus result
= eventNotHandledErr
;
494 switch ( GetEventClass( event
) )
496 case kEventClassControl
:
497 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
500 case kEventClassService
:
501 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
508 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
513 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
515 #if !TARGET_API_MAC_OSX
517 // ---------------------------------------------------------------------------
518 // UserPane events for non OSX builds
519 // ---------------------------------------------------------------------------
521 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
523 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
525 win
->MacControlUserPaneDrawProc(part
) ;
527 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
529 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
531 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
533 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
535 return kControlNoPart
;
537 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
539 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
541 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
543 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
545 return kControlNoPart
;
547 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
549 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
551 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
553 win
->MacControlUserPaneIdleProc() ;
555 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
557 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
559 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
561 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
563 return kControlNoPart
;
565 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
567 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
569 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
571 win
->MacControlUserPaneActivateProc(activating
) ;
573 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
575 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
577 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
579 return win
->MacControlUserPaneFocusProc(action
) ;
581 return kControlNoPart
;
583 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
585 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
587 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
589 win
->MacControlUserPaneBackgroundProc(info
) ;
591 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
593 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
596 RgnHandle rgn
= NewRgn() ;
598 MacWindowToRootWindow( &x
,&y
) ;
599 OffsetRgn( rgn
, -x
, -y
) ;
600 wxMacWindowStateSaver
sv( this ) ;
601 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
602 MacDoRedraw( rgn
, 0 ) ;
606 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
608 return kControlNoPart
;
611 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
613 return kControlNoPart
;
616 void wxWindowMac::MacControlUserPaneIdleProc()
620 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
622 return kControlNoPart
;
625 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
629 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
631 if ( AcceptsFocus() )
634 return kControlNoPart
;
637 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
643 // ---------------------------------------------------------------------------
644 // Scrollbar Tracking for all
645 // ---------------------------------------------------------------------------
647 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
648 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
652 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
654 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
657 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
659 // ===========================================================================
661 // ===========================================================================
663 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
665 static MacControlMap wxWinMacControlList
;
667 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
669 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
671 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
674 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
676 // adding NULL ControlRef is (first) surely a result of an error and
677 // (secondly) breaks native event processing
678 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
680 wxWinMacControlList
[inControl
] = control
;
683 void wxRemoveMacControlAssociation(wxWindow
*control
)
685 // iterate over all the elements in the class
686 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
687 // we should go on...
693 MacControlMap::iterator it
;
694 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
696 if ( it
->second
== control
)
698 wxWinMacControlList
.erase(it
);
706 // ----------------------------------------------------------------------------
707 // constructors and such
708 // ----------------------------------------------------------------------------
710 wxWindowMac::wxWindowMac()
715 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
720 const wxString
& name
)
723 Create(parent
, id
, pos
, size
, style
, name
);
726 void wxWindowMac::Init()
731 #if WXWIN_COMPATIBILITY_2_4
732 m_backgroundTransparent
= false;
735 #if wxMAC_USE_CORE_GRAPHICS
736 m_cgContextRef
= NULL
;
739 // as all windows are created with WS_VISIBLE style...
742 m_hScrollBar
= NULL
;
743 m_vScrollBar
= NULL
;
744 m_macBackgroundBrush
= wxNullBrush
;
746 m_macIsUserPane
= true;
747 m_clipChildren
= false ;
748 m_cachedClippedRectValid
= false ;
750 // we need a valid font for the encodings
751 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
755 wxWindowMac::~wxWindowMac()
759 m_isBeingDeleted
= true;
761 MacInvalidateBorders() ;
763 #ifndef __WXUNIVERSAL__
764 // VS: make sure there's no wxFrame with last focus set to us:
765 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
767 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
770 if ( frame
->GetLastFocus() == this )
771 frame
->SetLastFocus((wxWindow
*)NULL
);
775 #endif // __WXUNIVERSAL__
777 // destroy children before destroying this window itself
780 // wxRemoveMacControlAssociation( this ) ;
781 // If we delete an item, we should initialize the parent panel,
782 // because it could now be invalid.
783 wxWindow
*parent
= GetParent() ;
786 if (parent
->GetDefaultItem() == (wxButton
*) this)
787 parent
->SetDefaultItem(NULL
);
790 if ( m_peer
&& m_peer
->Ok() )
792 // in case the callback might be called during destruction
793 wxRemoveMacControlAssociation( this) ;
794 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
795 // we currently are not using this hook
796 // ::SetControlColorProc( *m_peer , NULL ) ;
800 if ( g_MacLastWindow
== this )
801 g_MacLastWindow
= NULL
;
803 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
806 if ( frame
->GetLastFocus() == this )
807 frame
->SetLastFocus( NULL
) ;
810 // delete our drop target if we've got one
811 #if wxUSE_DRAG_AND_DROP
812 if ( m_dropTarget
!= NULL
)
822 WXWidget
wxWindowMac::GetHandle() const
824 return (WXWidget
) m_peer
->GetControlRef() ;
827 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
829 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
830 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
831 GetEventTypeCount(eventList
), eventList
, this,
832 (EventHandlerRef
*)&m_macControlEventHandler
);
834 #if !TARGET_API_MAC_OSX
835 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
837 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
838 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
839 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
840 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
841 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
842 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
843 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
844 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
850 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
854 const wxString
& name
)
856 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
858 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
861 m_windowVariant
= parent
->GetWindowVariant() ;
863 if ( m_macIsUserPane
)
865 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
868 | kControlSupportsEmbedding
869 | kControlSupportsLiveFeedback
870 | kControlGetsFocusOnClick
871 // | kControlHasSpecialBackground
872 // | kControlSupportsCalcBestRect
873 | kControlHandlesTracking
874 | kControlSupportsFocus
875 | kControlWantsActivate
879 m_peer
= new wxMacControl(this) ;
880 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
882 MacPostControlCreate(pos
, size
) ;
885 #ifndef __WXUNIVERSAL__
886 // Don't give scrollbars to wxControls unless they ask for them
887 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
888 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
890 MacCreateScrollBars( style
) ;
894 wxWindowCreateEvent
event(this);
895 GetEventHandler()->AddPendingEvent(event
);
900 void wxWindowMac::MacChildAdded()
903 m_vScrollBar
->Raise() ;
905 m_hScrollBar
->Raise() ;
908 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
910 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
912 m_peer
->SetReference( (long) this ) ;
913 GetParent()->AddChild(this);
915 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
917 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
918 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
919 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
920 GetParent()->MacChildAdded() ;
922 // adjust font, controlsize etc
923 DoSetWindowVariant( m_windowVariant
) ;
925 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
927 if (!m_macIsUserPane
)
928 SetInitialBestSize(size
);
930 SetCursor( *wxSTANDARD_CURSOR
) ;
933 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
935 // Don't assert, in case we set the window variant before
936 // the window is created
937 // wxASSERT( m_peer->Ok() ) ;
939 m_windowVariant
= variant
;
941 if (m_peer
== NULL
|| !m_peer
->Ok())
945 ThemeFontID themeFont
= kThemeSystemFont
;
947 // we will get that from the settings later
948 // and make this NORMAL later, but first
949 // we have a few calculations that we must fix
953 case wxWINDOW_VARIANT_NORMAL
:
954 size
= kControlSizeNormal
;
955 themeFont
= kThemeSystemFont
;
958 case wxWINDOW_VARIANT_SMALL
:
959 size
= kControlSizeSmall
;
960 themeFont
= kThemeSmallSystemFont
;
963 case wxWINDOW_VARIANT_MINI
:
964 if (UMAGetSystemVersion() >= 0x1030 )
966 // not always defined in the headers
972 size
= kControlSizeSmall
;
973 themeFont
= kThemeSmallSystemFont
;
977 case wxWINDOW_VARIANT_LARGE
:
978 size
= kControlSizeLarge
;
979 themeFont
= kThemeSystemFont
;
983 wxFAIL_MSG(_T("unexpected window variant"));
987 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
990 font
.MacCreateThemeFont( themeFont
) ;
994 void wxWindowMac::MacUpdateControlFont()
996 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1000 bool wxWindowMac::SetFont(const wxFont
& font
)
1002 bool retval
= wxWindowBase::SetFont( font
) ;
1004 MacUpdateControlFont() ;
1009 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1011 bool retval
= wxWindowBase::SetForegroundColour(col
);
1014 MacUpdateControlFont() ;
1019 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1021 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1025 wxColour
newCol(GetBackgroundColour());
1026 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1027 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1028 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1029 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1031 brush
.SetColour( newCol
) ;
1033 MacSetBackgroundBrush( brush
) ;
1035 MacUpdateControlFont() ;
1040 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1042 m_macBackgroundBrush
= brush
;
1043 m_peer
->SetBackground( brush
) ;
1046 bool wxWindowMac::MacCanFocus() const
1048 // there is currently no way to determine whether the window is running in full keyboard
1049 // access mode, therefore we cannot rely on these features, yet the only other way would be
1050 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1051 // in event handlers...
1052 UInt32 features
= 0 ;
1053 m_peer
->GetFeatures( &features
) ;
1055 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1058 void wxWindowMac::SetFocus()
1060 if ( !AcceptsFocus() )
1063 wxWindow
* former
= FindFocus() ;
1064 if ( former
== this )
1067 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1068 // we can only leave in case of an error
1069 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1070 if ( err
== errCouldntSetFocus
)
1073 // enable for patch 1376506 - perhaps? (Stefan's version)
1075 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1078 #if !TARGET_API_MAC_OSX
1079 // emulate carbon events when running under CarbonLib where they are not natively available
1082 EventRef evRef
= NULL
;
1083 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1086 wxMacCarbonEvent
cEvent( evRef
) ;
1087 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1088 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1090 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1091 ReleaseEvent(evRef
) ;
1094 // send new focus event
1096 EventRef evRef
= NULL
;
1097 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1100 wxMacCarbonEvent
cEvent( evRef
) ;
1101 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1102 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1104 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1105 ReleaseEvent(evRef
) ;
1110 void wxWindowMac::DoCaptureMouse()
1112 wxApp::s_captureWindow
= this ;
1115 wxWindow
* wxWindowBase::GetCapture()
1117 return wxApp::s_captureWindow
;
1120 void wxWindowMac::DoReleaseMouse()
1122 wxApp::s_captureWindow
= NULL
;
1125 #if wxUSE_DRAG_AND_DROP
1127 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1129 if ( m_dropTarget
!= NULL
)
1130 delete m_dropTarget
;
1132 m_dropTarget
= pDropTarget
;
1133 if ( m_dropTarget
!= NULL
)
1141 // Old style file-manager drag&drop
1142 void wxWindowMac::DragAcceptFiles(bool accept
)
1147 // Returns the size of the native control. In the case of the toplevel window
1148 // this is the content area root control
1150 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1151 int& w
, int& h
) const
1153 wxFAIL_MSG( wxT("Not currently supported") ) ;
1156 // From a wx position / size calculate the appropriate size of the native control
1158 bool wxWindowMac::MacGetBoundsForControl(
1162 int& w
, int& h
, bool adjustOrigin
) const
1164 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1166 // the desired size, minus the border pixels gives the correct size of the control
1170 // todo the default calls may be used as soon as PostCreateControl Is moved here
1171 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1172 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1174 if ( !isCompositing
)
1175 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1177 x
+= MacGetLeftBorderSize() ;
1178 y
+= MacGetTopBorderSize() ;
1179 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1180 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1183 AdjustForParentClientOrigin( x
, y
) ;
1185 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1186 if ( !GetParent()->IsTopLevel() )
1188 x
-= GetParent()->MacGetLeftBorderSize() ;
1189 y
-= GetParent()->MacGetTopBorderSize() ;
1195 // Get window size (not client size)
1196 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1199 m_peer
->GetRect( &bounds
) ;
1202 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1204 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1207 // get the position of the bounds of this window in client coordinates of its parent
1208 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1211 m_peer
->GetRect( &bounds
) ;
1213 int x1
= bounds
.left
;
1214 int y1
= bounds
.top
;
1216 // get the wx window position from the native one
1217 x1
-= MacGetLeftBorderSize() ;
1218 y1
-= MacGetTopBorderSize() ;
1220 if ( !IsTopLevel() )
1222 wxWindow
*parent
= GetParent();
1225 // we must first adjust it to be in window coordinates of the parent,
1226 // as otherwise it gets lost by the ClientAreaOrigin fix
1227 x1
+= parent
->MacGetLeftBorderSize() ;
1228 y1
+= parent
->MacGetTopBorderSize() ;
1230 // and now to client coordinates
1231 wxPoint
pt(parent
->GetClientAreaOrigin());
1243 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1245 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1247 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1250 Point localwhere
= {0, 0} ;
1257 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1265 MacRootWindowToWindow( x
, y
) ;
1267 wxPoint origin
= GetClientAreaOrigin() ;
1274 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1276 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1277 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1279 wxPoint origin
= GetClientAreaOrigin() ;
1285 MacWindowToRootWindow( x
, y
) ;
1288 Point localwhere
= { 0,0 };
1290 localwhere
.h
= * x
;
1292 localwhere
.v
= * y
;
1294 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1303 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1305 wxPoint origin
= GetClientAreaOrigin() ;
1311 MacWindowToRootWindow( x
, y
) ;
1314 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1316 MacRootWindowToWindow( x
, y
) ;
1318 wxPoint origin
= GetClientAreaOrigin() ;
1325 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1333 if ( !IsTopLevel() )
1335 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1338 pt
.x
-= MacGetLeftBorderSize() ;
1339 pt
.y
-= MacGetTopBorderSize() ;
1340 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1350 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1359 MacWindowToRootWindow( &x1
, &y1
) ;
1367 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1376 if ( !IsTopLevel() )
1378 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1381 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1382 pt
.x
+= MacGetLeftBorderSize() ;
1383 pt
.y
+= MacGetTopBorderSize() ;
1393 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1402 MacRootWindowToWindow( &x1
, &y1
) ;
1410 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1412 RgnHandle rgn
= NewRgn() ;
1414 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1416 Rect structure
, content
;
1418 GetRegionBounds( rgn
, &content
) ;
1419 m_peer
->GetRect( &structure
) ;
1420 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1422 left
= content
.left
- structure
.left
;
1423 top
= content
.top
- structure
.top
;
1424 right
= structure
.right
- content
.right
;
1425 bottom
= structure
.bottom
- content
.bottom
;
1429 left
= top
= right
= bottom
= 0 ;
1435 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1437 wxSize sizeTotal
= size
;
1439 RgnHandle rgn
= NewRgn() ;
1440 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1442 Rect content
, structure
;
1443 GetRegionBounds( rgn
, &content
) ;
1444 m_peer
->GetRect( &structure
) ;
1446 // structure is in parent coordinates, but we only need width and height, so it's ok
1448 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1449 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1454 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1455 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1460 // Get size *available for subwindows* i.e. excluding menu bar etc.
1461 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1465 RgnHandle rgn
= NewRgn() ;
1467 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1468 GetRegionBounds( rgn
, &content
) ;
1470 m_peer
->GetRect( &content
) ;
1473 ww
= content
.right
- content
.left
;
1474 hh
= content
.bottom
- content
.top
;
1476 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1477 hh
-= m_hScrollBar
->GetSize().y
;
1479 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1480 ww
-= m_vScrollBar
->GetSize().x
;
1488 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1490 if (m_cursor
== cursor
)
1493 if (wxNullCursor
== cursor
)
1495 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1500 if ( ! wxWindowBase::SetCursor( cursor
) )
1504 wxASSERT_MSG( m_cursor
.Ok(),
1505 wxT("cursor must be valid after call to the base version"));
1507 wxWindowMac
*mouseWin
= 0 ;
1509 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1510 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1512 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1514 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1515 // position, use it...
1519 ControlPartCode part
;
1520 ControlRef control
;
1521 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1523 mouseWin
= wxFindControlFromMacControl( control
) ;
1526 QDSwapPort( savePort
, NULL
) ;
1529 if ( mouseWin
== this && !wxIsBusy() )
1530 m_cursor
.MacInstall() ;
1536 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1538 menu
->SetInvokingWindow(this);
1541 if ( x
== -1 && y
== -1 )
1543 wxPoint mouse
= wxGetMousePosition();
1549 ClientToScreen( &x
, &y
) ;
1552 menu
->MacBeforeDisplay( true ) ;
1553 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1554 if ( HiWord(menuResult
) != 0 )
1557 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1558 wxMenuItem
* item
= NULL
;
1560 item
= menu
->FindItem(id
, &realmenu
) ;
1561 if (item
->IsCheckable())
1562 item
->Check( !item
->IsChecked() ) ;
1564 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1567 menu
->MacAfterDisplay( true ) ;
1568 menu
->SetInvokingWindow(NULL
);
1574 // ----------------------------------------------------------------------------
1576 // ----------------------------------------------------------------------------
1580 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1582 wxWindowBase::DoSetToolTip(tooltip
);
1585 m_tooltip
->SetWindow(this);
1590 void wxWindowMac::MacInvalidateBorders()
1592 if ( m_peer
== NULL
)
1595 bool vis
= MacIsReallyShown() ;
1599 int outerBorder
= MacGetLeftBorderSize() ;
1600 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1603 if ( outerBorder
== 0 )
1606 // now we know that we have something to do at all
1608 // as the borders are drawn on the parent we have to properly invalidate all these areas
1609 RgnHandle updateInner
= NewRgn() ,
1610 updateOuter
= NewRgn() ;
1612 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1614 m_peer
->GetRect( &rect
) ;
1615 RectRgn( updateInner
, &rect
) ;
1616 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1617 RectRgn( updateOuter
, &rect
) ;
1618 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1620 #ifdef __WXMAC_OSX__
1621 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1623 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1625 InvalWindowRgn( tlw
, updateOuter
) ;
1628 DisposeRgn(updateOuter
) ;
1629 DisposeRgn(updateInner
) ;
1632 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
1633 RectRgn( updateInner
, &rect
) ;
1634 InsetRect( &rect
, -4 , -4 ) ;
1635 RectRgn( updateOuter
, &rect
) ;
1636 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1637 wxPoint
parent(0, 0);
1638 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1639 parent
-= GetParent()->GetClientAreaOrigin() ;
1640 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1641 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
1642 DisposeRgn(updateOuter
) ;
1643 DisposeRgn(updateInner
) ;
1649 // deleting a window while it is shown invalidates the region occupied by border or
1652 if ( IsShown() && ( outerBorder
> 0 ) )
1654 // as the borders are drawn on the parent we have to properly invalidate all these areas
1655 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1659 m_peer
->GetRect( &rect
) ;
1660 RectRgn( updateInner
, &rect
) ;
1661 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1662 RectRgn( updateOuter
, &rect
) ;
1663 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1664 wxPoint
parent(0, 0);
1665 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1666 parent
-= GetParent()->GetClientAreaOrigin() ;
1667 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1668 CopyRgn( updateOuter
, updateTotal
) ;
1670 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1671 DisposeRgn(updateOuter
) ;
1672 DisposeRgn(updateInner
) ;
1673 DisposeRgn(updateTotal
) ;
1679 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1681 int outerBorder
= MacGetLeftBorderSize() ;
1682 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1685 if ( vis
&& ( outerBorder
> 0 ) )
1687 // as the borders are drawn on the parent we have to properly invalidate all these areas
1688 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1692 m_peer
->GetRect( &rect
) ;
1693 RectRgn( updateInner
, &rect
) ;
1694 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1695 RectRgn( updateOuter
, &rect
) ;
1696 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1699 wxPoint parent(0, 0);
1700 #if TARGET_API_MAC_OSX
1701 // no offsetting needed when compositing
1703 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1704 parent -= GetParent()->GetClientAreaOrigin() ;
1705 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1708 CopyRgn( updateOuter
, updateTotal
) ;
1711 RectRgn( updateInner
, &rect
) ;
1712 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1713 RectRgn( updateOuter
, &rect
) ;
1714 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1716 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1718 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1720 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1721 DisposeRgn(updateOuter
) ;
1722 DisposeRgn(updateInner
) ;
1723 DisposeRgn(updateTotal
) ;
1728 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1730 // this is never called for a toplevel window, so we know we have a parent
1731 int former_x
, former_y
, former_w
, former_h
;
1733 // Get true coordinates of former position
1734 DoGetPosition( &former_x
, &former_y
) ;
1735 DoGetSize( &former_w
, &former_h
) ;
1737 wxWindow
*parent
= GetParent();
1740 wxPoint
pt(parent
->GetClientAreaOrigin());
1745 int actualWidth
= width
;
1746 int actualHeight
= height
;
1750 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1751 actualWidth
= m_minWidth
;
1752 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1753 actualHeight
= m_minHeight
;
1754 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1755 actualWidth
= m_maxWidth
;
1756 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1757 actualHeight
= m_maxHeight
;
1759 bool doMove
= false, doResize
= false ;
1761 if ( actualX
!= former_x
|| actualY
!= former_y
)
1764 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1767 if ( doMove
|| doResize
)
1769 // as the borders are drawn outside the native control, we adjust now
1771 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1772 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1773 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1776 wxMacRectToNative( &bounds
, &r
) ;
1778 if ( !GetParent()->IsTopLevel() )
1779 wxMacWindowToNative( GetParent() , &r
) ;
1781 MacInvalidateBorders() ;
1783 m_cachedClippedRectValid
= false ;
1784 m_peer
->SetRect( &r
) ;
1786 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1788 MacInvalidateBorders() ;
1790 MacRepositionScrollBars() ;
1793 wxPoint
point(actualX
, actualY
);
1794 wxMoveEvent
event(point
, m_windowId
);
1795 event
.SetEventObject(this);
1796 GetEventHandler()->ProcessEvent(event
) ;
1801 MacRepositionScrollBars() ;
1802 wxSize
size(actualWidth
, actualHeight
);
1803 wxSizeEvent
event(size
, m_windowId
);
1804 event
.SetEventObject(this);
1805 GetEventHandler()->ProcessEvent(event
);
1810 wxSize
wxWindowMac::DoGetBestSize() const
1812 if ( m_macIsUserPane
|| IsTopLevel() )
1813 return wxWindowBase::DoGetBestSize() ;
1815 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1816 int bestWidth
, bestHeight
;
1818 m_peer
->GetBestRect( &bestsize
) ;
1819 if ( EmptyRect( &bestsize
) )
1824 bestsize
.bottom
= 16 ;
1826 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1828 bestsize
.bottom
= 16 ;
1831 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1833 bestsize
.bottom
= 24 ;
1838 // return wxWindowBase::DoGetBestSize() ;
1842 bestWidth
= bestsize
.right
- bestsize
.left
;
1843 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1844 if ( bestHeight
< 10 )
1847 return wxSize(bestWidth
, bestHeight
);
1850 // set the size of the window: if the dimensions are positive, just use them,
1851 // but if any of them is equal to -1, it means that we must find the value for
1852 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1853 // which case -1 is a valid value for x and y)
1855 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1856 // the width/height to best suit our contents, otherwise we reuse the current
1858 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1860 // get the current size and position...
1861 int currentX
, currentY
;
1862 int currentW
, currentH
;
1864 GetPosition(¤tX
, ¤tY
);
1865 GetSize(¤tW
, ¤tH
);
1867 // ... and don't do anything (avoiding flicker) if it's already ok
1868 if ( x
== currentX
&& y
== currentY
&&
1869 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1872 MacRepositionScrollBars() ; // we might have a real position shift
1877 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1879 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1882 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1884 wxSize size
= wxDefaultSize
;
1885 if ( width
== wxDefaultCoord
)
1887 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1889 size
= DoGetBestSize();
1894 // just take the current one
1899 if ( height
== wxDefaultCoord
)
1901 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1903 if ( size
.x
== wxDefaultCoord
)
1904 size
= DoGetBestSize();
1905 // else: already called DoGetBestSize() above
1911 // just take the current one
1916 DoMoveWindow(x
, y
, width
, height
);
1919 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1921 RgnHandle rgn
= NewRgn() ;
1923 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1925 GetRegionBounds( rgn
, &content
) ;
1935 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
1938 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1940 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1942 int currentclientwidth
, currentclientheight
;
1943 int currentwidth
, currentheight
;
1945 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1946 GetSize( ¤twidth
, ¤theight
) ;
1948 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1949 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1953 void wxWindowMac::SetLabel(const wxString
& title
)
1955 m_label
= wxStripMenuCodes(title
) ;
1957 if ( m_peer
&& m_peer
->Ok() )
1958 m_peer
->SetLabel( m_label
) ;
1963 wxString
wxWindowMac::GetLabel() const
1968 bool wxWindowMac::Show(bool show
)
1970 bool former
= MacIsReallyShown() ;
1971 if ( !wxWindowBase::Show(show
) )
1974 // TODO use visibilityChanged Carbon Event for OSX
1976 m_peer
->SetVisibility( show
, true ) ;
1978 if ( former
!= MacIsReallyShown() )
1979 MacPropagateVisibilityChanged() ;
1982 // patch from Sailesh Agrawal
1983 wxShowEvent
eventShow(GetId(), show
);
1984 eventShow
.SetEventObject(this);
1985 GetEventHandler()->ProcessEvent(eventShow
);
1991 bool wxWindowMac::Enable(bool enable
)
1993 wxASSERT( m_peer
->Ok() ) ;
1994 bool former
= MacIsReallyEnabled() ;
1995 if ( !wxWindowBase::Enable(enable
) )
1998 m_peer
->Enable( enable
) ;
2000 if ( former
!= MacIsReallyEnabled() )
2001 MacPropagateEnabledStateChanged() ;
2007 // status change propagations (will be not necessary for OSX later )
2010 void wxWindowMac::MacPropagateVisibilityChanged()
2012 #if !TARGET_API_MAC_OSX
2013 MacVisibilityChanged() ;
2016 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2019 child
= node
->GetData();
2020 if ( child
->IsShown() )
2021 child
->MacPropagateVisibilityChanged() ;
2023 node
= node
->GetNext();
2028 void wxWindowMac::MacPropagateEnabledStateChanged()
2030 #if !TARGET_API_MAC_OSX
2031 MacEnabledStateChanged() ;
2034 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2037 child
= node
->GetData();
2038 if ( child
->IsEnabled() )
2039 child
->MacPropagateEnabledStateChanged() ;
2041 node
= node
->GetNext();
2046 void wxWindowMac::MacPropagateHiliteChanged()
2048 #if !TARGET_API_MAC_OSX
2049 MacHiliteChanged() ;
2052 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2055 child
= node
->GetData();
2056 if (child
/* && child->IsEnabled() */)
2057 child
->MacPropagateHiliteChanged() ;
2059 node
= node
->GetNext();
2065 // status change notifications
2068 void wxWindowMac::MacVisibilityChanged()
2072 void wxWindowMac::MacHiliteChanged()
2076 void wxWindowMac::MacEnabledStateChanged()
2081 // status queries on the inherited window's state
2084 bool wxWindowMac::MacIsReallyShown()
2086 // only under OSX the visibility of the TLW is taken into account
2087 if ( m_isBeingDeleted
)
2090 #if TARGET_API_MAC_OSX
2091 if ( m_peer
&& m_peer
->Ok() )
2092 return m_peer
->IsVisible();
2095 wxWindow
* win
= this ;
2096 while ( win
->IsShown() )
2098 if ( win
->IsTopLevel() )
2101 win
= win
->GetParent() ;
2109 bool wxWindowMac::MacIsReallyEnabled()
2111 return m_peer
->IsEnabled() ;
2114 bool wxWindowMac::MacIsReallyHilited()
2116 return m_peer
->IsActive();
2119 void wxWindowMac::MacFlashInvalidAreas()
2121 #if TARGET_API_MAC_OSX
2122 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2126 int wxWindowMac::GetCharHeight() const
2128 wxClientDC
dc( (wxWindowMac
*)this ) ;
2130 return dc
.GetCharHeight() ;
2133 int wxWindowMac::GetCharWidth() const
2135 wxClientDC
dc( (wxWindowMac
*)this ) ;
2137 return dc
.GetCharWidth() ;
2140 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2141 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2143 const wxFont
*fontToUse
= theFont
;
2145 fontToUse
= &m_font
;
2147 wxClientDC
dc( (wxWindowMac
*) this ) ;
2149 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2150 if ( externalLeading
)
2151 *externalLeading
= le
;
2161 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2162 * we always intersect with the entire window, not only with the client area
2165 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2167 if ( m_peer
== NULL
)
2170 if ( !MacIsReallyShown() )
2177 wxMacRectToNative( rect
, &r
) ;
2178 m_peer
->SetNeedsDisplay( &r
) ;
2182 m_peer
->SetNeedsDisplay() ;
2186 void wxWindowMac::Freeze()
2188 #if TARGET_API_MAC_OSX
2189 if ( !m_frozenness
++ )
2191 if ( m_peer
&& m_peer
->Ok() )
2192 m_peer
->SetDrawingEnabled( false ) ;
2197 void wxWindowMac::Thaw()
2199 #if TARGET_API_MAC_OSX
2200 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2202 if ( !--m_frozenness
)
2204 if ( m_peer
&& m_peer
->Ok() )
2206 m_peer
->SetDrawingEnabled( true ) ;
2207 m_peer
->InvalidateWithChildren() ;
2213 wxWindowMac
*wxGetActiveWindow()
2215 // actually this is a windows-only concept
2219 // Coordinates relative to the window
2220 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2222 // We really don't move the mouse programmatically under Mac.
2225 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2227 if ( MacGetTopLevelWindow() == NULL
)
2230 #if TARGET_API_MAC_OSX
2231 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2238 event
.GetDC()->Clear() ;
2242 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2247 int wxWindowMac::GetScrollPos(int orient
) const
2249 if ( orient
== wxHORIZONTAL
)
2252 return m_hScrollBar
->GetThumbPosition() ;
2257 return m_vScrollBar
->GetThumbPosition() ;
2263 // This now returns the whole range, not just the number
2264 // of positions that we can scroll.
2265 int wxWindowMac::GetScrollRange(int orient
) const
2267 if ( orient
== wxHORIZONTAL
)
2270 return m_hScrollBar
->GetRange() ;
2275 return m_vScrollBar
->GetRange() ;
2281 int wxWindowMac::GetScrollThumb(int orient
) const
2283 if ( orient
== wxHORIZONTAL
)
2286 return m_hScrollBar
->GetThumbSize() ;
2291 return m_vScrollBar
->GetThumbSize() ;
2297 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2299 if ( orient
== wxHORIZONTAL
)
2302 m_hScrollBar
->SetThumbPosition( pos
) ;
2307 m_vScrollBar
->SetThumbPosition( pos
) ;
2312 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2313 // our own window origin is at leftOrigin/rightOrigin
2316 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2322 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2323 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2325 m_peer
->GetRect( &rect
) ;
2326 // back to the surrounding frame rectangle
2327 InsetRect( &rect
, -1 , -1 ) ;
2329 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2330 if ( UMAGetSystemVersion() >= 0x1030 )
2332 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2333 rect
.bottom
- rect
.top
) ;
2335 HIThemeFrameDrawInfo info
;
2336 memset( &info
, 0 , sizeof( info
) ) ;
2340 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2341 info
.isFocused
= hasFocus
;
2343 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2344 wxASSERT( cgContext
) ;
2346 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2348 info
.kind
= kHIThemeFrameTextFieldSquare
;
2349 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2351 else if ( HasFlag(wxSIMPLE_BORDER
) )
2353 info
.kind
= kHIThemeFrameListBox
;
2354 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2356 else if ( hasFocus
)
2358 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2361 m_peer
->GetRect( &rect
) ;
2362 if ( hasBothScrollbars
)
2364 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2365 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2366 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2367 HIThemeGrowBoxDrawInfo info
;
2368 memset( &info
, 0, sizeof(info
) ) ;
2370 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2371 info
.kind
= kHIThemeGrowBoxKindNone
;
2372 info
.size
= kHIThemeGrowBoxSizeNormal
;
2373 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2374 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2380 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2384 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2385 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2388 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2389 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2390 else if ( HasFlag(wxSIMPLE_BORDER
) )
2391 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2394 DrawThemeFocusRect( &rect
, true ) ;
2396 if ( hasBothScrollbars
)
2398 // GetThemeStandaloneGrowBoxBounds
2399 // DrawThemeStandaloneNoGrowBox
2404 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2406 if ( child
== m_hScrollBar
)
2407 m_hScrollBar
= NULL
;
2408 if ( child
== m_vScrollBar
)
2409 m_vScrollBar
= NULL
;
2411 wxWindowBase::RemoveChild( child
) ;
2414 // New function that will replace some of the above.
2415 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2416 int range
, bool refresh
)
2418 if ( orient
== wxHORIZONTAL
)
2422 if ( range
== 0 || thumbVisible
>= range
)
2424 if ( m_hScrollBar
->IsShown() )
2425 m_hScrollBar
->Show(false) ;
2429 if ( !m_hScrollBar
->IsShown() )
2430 m_hScrollBar
->Show(true) ;
2433 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2440 if ( range
== 0 || thumbVisible
>= range
)
2442 if ( m_vScrollBar
->IsShown() )
2443 m_vScrollBar
->Show(false) ;
2447 if ( !m_vScrollBar
->IsShown() )
2448 m_vScrollBar
->Show(true) ;
2451 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2455 MacRepositionScrollBars() ;
2458 // Does a physical scroll
2459 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2461 if ( dx
== 0 && dy
== 0 )
2464 int width
, height
;
2465 GetClientSize( &width
, &height
) ;
2467 #if TARGET_API_MAC_OSX
2468 if ( true /* m_peer->IsCompositing() */ )
2470 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2471 // area is scrolled, this does not occur if width and height are 2 pixels less,
2472 // TODO write optimal workaround
2473 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2475 scrollrect
.Intersect( *rect
) ;
2477 if ( m_peer
->GetNeedsDisplay() )
2479 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2480 // either immediate redraw or full invalidate
2482 // is the better overall solution, as it does not slow down scrolling
2483 m_peer
->SetNeedsDisplay() ;
2485 // this would be the preferred version for fast drawing controls
2487 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2488 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2489 HIViewRender(m_peer
->GetControlRef()) ;
2496 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2497 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2498 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2500 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2501 // either immediate redraw or full invalidate
2503 // is the better overall solution, as it does not slow down scrolling
2504 m_peer
->SetNeedsDisplay() ;
2506 // this would be the preferred version for fast drawing controls
2508 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2509 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2510 HIViewRender(m_peer
->GetControlRef()) ;
2524 RgnHandle updateRgn
= NewRgn() ;
2527 wxClientDC
dc(this) ;
2528 wxMacPortSetter
helper(&dc
) ;
2530 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2531 //scrollrect.top += MacGetTopBorderSize() ;
2532 //scrollrect.left += MacGetLeftBorderSize() ;
2533 scrollrect
.bottom
= scrollrect
.top
+ height
;
2534 scrollrect
.right
= scrollrect
.left
+ width
;
2538 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2539 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2540 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2543 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2545 // now scroll the former update region as well and add the new update region
2546 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2547 RgnHandle formerUpdateRgn
= NewRgn() ;
2548 RgnHandle scrollRgn
= NewRgn() ;
2549 RectRgn( scrollRgn
, &scrollrect
) ;
2550 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2552 LocalToGlobal( &pt
) ;
2553 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2554 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2556 if ( !EmptyRgn( formerUpdateRgn
) )
2558 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2559 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2560 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2563 InvalWindowRgn(rootWindow
, updateRgn
) ;
2564 DisposeRgn( updateRgn
) ;
2565 DisposeRgn( formerUpdateRgn
) ;
2566 DisposeRgn( scrollRgn
) ;
2574 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2576 child
= node
->GetData();
2579 if (child
== m_vScrollBar
)
2581 if (child
== m_hScrollBar
)
2583 if (child
->IsTopLevel())
2586 child
->GetPosition( &x
, &y
);
2587 child
->GetSize( &w
, &h
);
2590 wxRect
rc( x
, y
, w
, h
);
2591 if (rect
->Intersects( rc
))
2592 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2596 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2601 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2603 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2605 wxScrollWinEvent wevent
;
2606 wevent
.SetPosition(event
.GetPosition());
2607 wevent
.SetOrientation(event
.GetOrientation());
2608 wevent
.SetEventObject(this);
2610 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2611 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2612 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2613 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2614 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2615 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2616 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2617 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2618 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2619 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2620 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2621 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2622 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2623 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2624 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2625 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2627 GetEventHandler()->ProcessEvent(wevent
);
2631 // Get the window with the focus
2632 wxWindowMac
*wxWindowBase::DoFindFocus()
2634 ControlRef control
;
2635 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2636 return wxFindControlFromMacControl( control
) ;
2639 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2641 // panel wants to track the window which was the last to have focus in it,
2642 // so we want to set ourselves as the window which last had focus
2644 // notice that it's also important to do it upwards the tree because
2645 // otherwise when the top level panel gets focus, it won't set it back to
2646 // us, but to some other sibling
2648 // CS: don't know if this is still needed:
2649 //wxChildFocusEvent eventFocus(this);
2650 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2652 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2654 // enable for patch 1376506 - perhaps?
2656 if ( bIsFocusEvent
)
2657 SetUserFocusWindow( GetControlOwner( GetPeer()->GetControlRef() ) );
2659 SetUserFocusWindow( kUserFocusAuto
);
2662 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2664 #if wxMAC_USE_CORE_GRAPHICS
2665 GetParent()->Refresh() ;
2667 wxMacWindowStateSaver
sv( this ) ;
2670 m_peer
->GetRect( &rect
) ;
2671 // auf den umgebenden Rahmen zur\9fck
2672 InsetRect( &rect
, -1 , -1 ) ;
2674 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2678 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2680 rect
.right
+= pt
.x
;
2682 rect
.bottom
+= pt
.y
;
2685 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2686 if ( !bIsFocusEvent
)
2688 // as this erases part of the frame we have to redraw borders
2689 // and because our z-ordering is not always correct (staticboxes)
2690 // we have to invalidate things, we cannot simple redraw
2691 MacInvalidateBorders() ;
2699 void wxWindowMac::OnInternalIdle()
2701 // This calls the UI-update mechanism (querying windows for
2702 // menu/toolbar/control state information)
2703 if (wxUpdateUIEvent::CanUpdate(this))
2704 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2707 // Raise the window to the top of the Z order
2708 void wxWindowMac::Raise()
2710 m_peer
->SetZOrder( true , NULL
) ;
2713 // Lower the window to the bottom of the Z order
2714 void wxWindowMac::Lower()
2716 m_peer
->SetZOrder( false , NULL
) ;
2719 // static wxWindow *gs_lastWhich = NULL;
2721 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2723 // first trigger a set cursor event
2725 wxPoint clientorigin
= GetClientAreaOrigin() ;
2726 wxSize clientsize
= GetClientSize() ;
2728 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2730 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2732 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2733 if ( processedEvtSetCursor
&& event
.HasCursor() )
2735 cursor
= event
.GetCursor() ;
2739 // the test for processedEvtSetCursor is here to prevent using m_cursor
2740 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2741 // it - this is a way to say that our cursor shouldn't be used for this
2743 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2746 if ( !wxIsBusy() && !GetParent() )
2747 cursor
= *wxSTANDARD_CURSOR
;
2751 cursor
.MacInstall() ;
2754 return cursor
.Ok() ;
2757 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2761 return m_tooltip
->GetTip() ;
2764 return wxEmptyString
;
2767 void wxWindowMac::ClearBackground()
2773 void wxWindowMac::Update()
2775 #if TARGET_API_MAC_OSX
2776 MacGetTopLevelWindow()->MacPerformUpdates() ;
2778 ::Draw1Control( m_peer
->GetControlRef() ) ;
2782 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2784 wxTopLevelWindowMac
* win
= NULL
;
2785 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2787 win
= wxFindWinFromMacWindow( window
) ;
2792 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2794 MacUpdateClippedRects() ;
2796 return m_cachedClippedClientRect
;
2799 const wxRect
& wxWindowMac::MacGetClippedRect() const
2801 MacUpdateClippedRects() ;
2803 return m_cachedClippedRect
;
2806 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2808 MacUpdateClippedRects() ;
2810 return m_cachedClippedRectWithOuterStructure
;
2813 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2815 static wxRegion emptyrgn
;
2817 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2819 MacUpdateClippedRects() ;
2820 if ( includeOuterStructures
)
2821 return m_cachedClippedRegionWithOuterStructure
;
2823 return m_cachedClippedRegion
;
2831 void wxWindowMac::MacUpdateClippedRects() const
2833 if ( m_cachedClippedRectValid
)
2836 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2837 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2838 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2839 // to add focus borders everywhere
2841 Rect r
, rIncludingOuterStructures
;
2843 m_peer
->GetRect( &r
) ;
2844 r
.left
-= MacGetLeftBorderSize() ;
2845 r
.top
-= MacGetTopBorderSize() ;
2846 r
.bottom
+= MacGetBottomBorderSize() ;
2847 r
.right
+= MacGetRightBorderSize() ;
2854 rIncludingOuterStructures
= r
;
2855 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2857 wxRect cl
= GetClientRect() ;
2858 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2862 const wxWindow
* child
= this ;
2863 const wxWindow
* parent
= NULL
;
2865 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2867 if ( parent
->MacIsChildOfClientArea(child
) )
2869 size
= parent
->GetClientSize() ;
2870 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2876 // this will be true for scrollbars, toolbars etc.
2877 size
= parent
->GetSize() ;
2878 y
= parent
->MacGetTopBorderSize() ;
2879 x
= parent
->MacGetLeftBorderSize() ;
2880 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2881 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2884 parent
->MacWindowToRootWindow( &x
, &y
) ;
2885 MacRootWindowToWindow( &x
, &y
) ;
2887 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2889 // the wxwindow and client rects will always be clipped
2890 SectRect( &r
, &rparent
, &r
) ;
2891 SectRect( &rClient
, &rparent
, &rClient
) ;
2893 // the structure only at 'hard' borders
2894 if ( parent
->MacClipChildren() ||
2895 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2897 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2903 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2904 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2905 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2906 m_cachedClippedRectWithOuterStructure
= wxRect(
2907 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2908 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2909 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2911 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2912 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2913 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2915 m_cachedClippedRectValid
= true ;
2919 This function must not change the updatergn !
2921 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2923 bool handled
= false ;
2925 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2926 GetRegionBounds( updatergn
, &updatebounds
) ;
2928 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2930 if ( !EmptyRgn(updatergn
) )
2932 RgnHandle newupdate
= NewRgn() ;
2933 wxSize point
= GetClientSize() ;
2934 wxPoint origin
= GetClientAreaOrigin() ;
2935 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2936 SectRgn( newupdate
, updatergn
, newupdate
) ;
2938 // first send an erase event to the entire update area
2940 // for the toplevel window this really is the entire area
2941 // for all the others only their client area, otherwise they
2942 // might be drawing with full alpha and eg put blue into
2943 // the grow-box area of a scrolled window (scroll sample)
2944 wxDC
* dc
= new wxWindowDC(this);
2946 dc
->SetClippingRegion(wxRegion(updatergn
));
2948 dc
->SetClippingRegion(wxRegion(newupdate
));
2950 wxEraseEvent
eevent( GetId(), dc
);
2951 eevent
.SetEventObject( this );
2952 GetEventHandler()->ProcessEvent( eevent
);
2956 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2957 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2958 m_updateRegion
= newupdate
;
2959 DisposeRgn( newupdate
) ;
2961 if ( !m_updateRegion
.Empty() )
2963 // paint the window itself
2966 event
.SetTimestamp(time
);
2967 event
.SetEventObject(this);
2968 GetEventHandler()->ProcessEvent(event
);
2972 // now we cannot rely on having its borders drawn by a window itself, as it does not
2973 // get the updateRgn wide enough to always do so, so we do it from the parent
2974 // this would also be the place to draw any custom backgrounds for native controls
2975 // in Composited windowing
2976 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2980 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2982 child
= node
->GetData();
2985 if (child
== m_vScrollBar
)
2987 if (child
== m_hScrollBar
)
2989 if (child
->IsTopLevel())
2991 if (!child
->IsShown())
2994 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2996 child
->GetPosition( &x
, &y
);
2997 child
->GetSize( &w
, &h
);
2998 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2999 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3000 InsetRect( &childRect
, -10 , -10) ;
3002 if ( RectInRgn( &childRect
, updatergn
) )
3004 // paint custom borders
3005 wxNcPaintEvent
eventNc( child
->GetId() );
3006 eventNc
.SetEventObject( child
);
3007 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3009 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3010 if ( UMAGetSystemVersion() >= 0x1030 )
3012 child
->MacPaintBorders(0, 0) ;
3017 wxWindowDC
dc(this) ;
3018 dc
.SetClippingRegion(wxRegion(updatergn
));
3019 wxMacPortSetter
helper(&dc
) ;
3020 child
->MacPaintBorders(0, 0) ;
3031 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3033 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3037 if ( iter
->IsTopLevel() )
3038 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3040 iter
= iter
->GetParent() ;
3043 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3048 void wxWindowMac::MacCreateScrollBars( long style
)
3050 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3052 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3054 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3055 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3056 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3057 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3059 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3060 variant
= wxWINDOW_VARIANT_SMALL
;
3063 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3065 GetClientSize( &width
, &height
) ;
3067 wxPoint
vPoint(width
- scrlsize
, 0) ;
3068 wxSize
vSize(scrlsize
, height
- adjust
) ;
3069 wxPoint
hPoint(0 , height
- scrlsize
) ;
3070 wxSize
hSize( width
- adjust
, scrlsize
) ;
3072 if ( style
& wxVSCROLL
)
3073 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3075 if ( style
& wxHSCROLL
)
3076 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3079 // because the create does not take into account the client area origin
3080 // we might have a real position shift
3081 MacRepositionScrollBars() ;
3084 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3086 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3092 void wxWindowMac::MacRepositionScrollBars()
3094 if ( !m_hScrollBar
&& !m_vScrollBar
)
3097 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3098 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3099 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3101 // get real client area
3103 GetSize( &width
, &height
);
3105 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3106 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3108 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3109 wxSize
vSize( scrlsize
, height
- adjust
) ;
3110 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3111 wxSize
hSize( width
- adjust
, scrlsize
) ;
3114 int x
= 0, y
= 0, w
, h
;
3115 GetSize( &w
, &h
) ;
3117 MacClientToRootWindow( &x
, &y
) ;
3118 MacClientToRootWindow( &w
, &h
) ;
3120 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3122 int totW
= 10000 , totH
= 10000;
3125 if ( iter
->IsTopLevel() )
3127 iter
->GetSize( &totW
, &totH
) ;
3131 iter
= iter
->GetParent() ;
3145 if ( w
- x
>= totW
)
3150 if ( h
- y
>= totH
)
3158 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3160 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3163 bool wxWindowMac::AcceptsFocus() const
3165 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3168 void wxWindowMac::MacSuperChangedPosition()
3170 // only window-absolute structures have to be moved i.e. controls
3172 m_cachedClippedRectValid
= false ;
3175 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3178 child
= node
->GetData();
3179 child
->MacSuperChangedPosition() ;
3181 node
= node
->GetNext();
3185 void wxWindowMac::MacTopLevelWindowChangedPosition()
3187 // only screen-absolute structures have to be moved i.e. glcanvas
3190 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3193 child
= node
->GetData();
3194 child
->MacTopLevelWindowChangedPosition() ;
3196 node
= node
->GetNext();
3200 long wxWindowMac::MacGetLeftBorderSize() const
3207 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3209 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3210 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3212 else if (HasFlag(wxSIMPLE_BORDER
))
3214 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3215 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3221 long wxWindowMac::MacGetRightBorderSize() const
3223 // they are all symmetric in mac themes
3224 return MacGetLeftBorderSize() ;
3227 long wxWindowMac::MacGetTopBorderSize() const
3229 // they are all symmetric in mac themes
3230 return MacGetLeftBorderSize() ;
3233 long wxWindowMac::MacGetBottomBorderSize() const
3235 // they are all symmetric in mac themes
3236 return MacGetLeftBorderSize() ;
3239 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3241 return style
& ~wxBORDER_MASK
;
3244 // Find the wxWindowMac at the current mouse position, returning the mouse
3246 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3248 pt
= wxGetMousePosition();
3249 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3254 // Get the current mouse position.
3255 wxPoint
wxGetMousePosition()
3259 wxGetMousePosition( &x
, &y
);
3261 return wxPoint(x
, y
);
3264 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3266 long evtType
= event
.GetEventType();
3267 // if ((evtType == ewxEVT_RIGHT_DOWN) || (evtType == wxEVT_CONTEXT_MENU))
3268 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3270 // copied from wxGTK : CS
3271 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3274 // (a) it's a command event and so is propagated to the parent
3275 // (b) under MSW it can be generated from kbd too
3276 // (c) it uses screen coords (because of (a))
3277 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3279 this->ClientToScreen(event
.GetPosition()));
3280 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3289 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3291 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3292 CallNextEventHandler(
3293 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3294 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3297 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3301 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3305 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3306 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3311 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3313 return eventNotHandledErr
;
3316 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3318 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3320 if ( !wxWindowBase::Reparent(newParent
) )
3323 // copied from MacPostControlCreate
3324 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3326 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3328 ::EmbedControl( m_peer
->GetControlRef() , container
) ;