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
) );
301 thisWindow
->MacSetCGContextRef( cgContext
) ;
304 wxMacCGContextStateSaver
sg( cgContext
) ;
306 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
309 #if wxMAC_USE_CORE_GRAPHICS
310 thisWindow
->MacSetCGContextRef( NULL
) ;
314 CGContextRelease( cgContext
) ;
319 DisposeRgn( allocatedRgn
) ;
323 case kEventControlVisibilityChanged
:
324 thisWindow
->MacVisibilityChanged() ;
327 case kEventControlEnabledStateChanged
:
328 thisWindow
->MacEnabledStateChanged() ;
331 case kEventControlHiliteChanged
:
332 thisWindow
->MacHiliteChanged() ;
336 // we emulate this event under Carbon CFM
337 case kEventControlSetFocusPart
:
339 Boolean focusEverything
= false ;
340 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
343 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
348 if ( controlPart
== kControlFocusNoPart
)
351 if ( thisWindow
->GetCaret() )
352 thisWindow
->GetCaret()->OnKillFocus();
355 static bool inKillFocusEvent
= false ;
357 if ( !inKillFocusEvent
)
359 inKillFocusEvent
= true ;
360 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
361 event
.SetEventObject(thisWindow
);
362 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
363 inKillFocusEvent
= false ;
368 // panel wants to track the window which was the last to have focus in it
369 wxChildFocusEvent
eventFocus(thisWindow
);
370 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
373 if ( thisWindow
->GetCaret() )
374 thisWindow
->GetCaret()->OnSetFocus();
377 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
378 event
.SetEventObject(thisWindow
);
379 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
382 if ( thisWindow
->MacIsUserPane() )
387 case kEventControlHit
:
388 result
= thisWindow
->MacControlHit( handler
, event
) ;
398 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
400 OSStatus result
= eventNotHandledErr
;
402 wxMacCarbonEvent
cEvent( event
) ;
404 ControlRef controlRef
;
405 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
406 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
407 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
409 switch ( GetEventKind( event
) )
411 case kEventServiceGetTypes
:
415 textCtrl
->GetSelection( &from
, &to
) ;
417 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
419 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
420 if ( textCtrl
->IsEditable() )
421 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
423 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
424 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
426 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
430 CFArrayAppendValue(copyTypes
, typestring
) ;
432 CFArrayAppendValue(pasteTypes
, typestring
) ;
434 CFRelease( typestring
) ;
442 case kEventServiceCopy
:
447 textCtrl
->GetSelection( &from
, &to
) ;
448 wxString val
= textCtrl
->GetValue() ;
449 val
= val
.Mid( from
, to
- from
) ;
450 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
451 verify_noerr( ClearScrap( &scrapRef
) ) ;
452 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
457 case kEventServicePaste
:
460 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
461 Size textSize
, pastedSize
;
462 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
464 char *content
= new char[textSize
] ;
465 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
466 content
[textSize
- 1] = 0 ;
469 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
471 textCtrl
->WriteText( wxString( content
) ) ;
486 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
488 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
489 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
490 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
491 OSStatus result
= eventNotHandledErr
;
493 switch ( GetEventClass( event
) )
495 case kEventClassControl
:
496 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
499 case kEventClassService
:
500 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
507 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
512 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
514 #if !TARGET_API_MAC_OSX
516 // ---------------------------------------------------------------------------
517 // UserPane events for non OSX builds
518 // ---------------------------------------------------------------------------
520 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
522 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
524 win
->MacControlUserPaneDrawProc(part
) ;
526 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
528 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
530 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
532 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
534 return kControlNoPart
;
536 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
538 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
540 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
542 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
544 return kControlNoPart
;
546 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
548 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
550 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
552 win
->MacControlUserPaneIdleProc() ;
554 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
556 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
558 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
560 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
562 return kControlNoPart
;
564 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
566 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
568 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
570 win
->MacControlUserPaneActivateProc(activating
) ;
572 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
574 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
576 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
578 return win
->MacControlUserPaneFocusProc(action
) ;
580 return kControlNoPart
;
582 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
584 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
586 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
588 win
->MacControlUserPaneBackgroundProc(info
) ;
590 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
592 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
595 RgnHandle rgn
= NewRgn() ;
597 MacWindowToRootWindow( &x
,&y
) ;
598 OffsetRgn( rgn
, -x
, -y
) ;
599 wxMacWindowStateSaver
sv( this ) ;
600 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
601 MacDoRedraw( rgn
, 0 ) ;
605 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
607 return kControlNoPart
;
610 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
612 return kControlNoPart
;
615 void wxWindowMac::MacControlUserPaneIdleProc()
619 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
621 return kControlNoPart
;
624 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
628 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
630 if ( AcceptsFocus() )
633 return kControlNoPart
;
636 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
642 // ---------------------------------------------------------------------------
643 // Scrollbar Tracking for all
644 // ---------------------------------------------------------------------------
646 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
647 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
651 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
653 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
656 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
658 // ===========================================================================
660 // ===========================================================================
662 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
664 static MacControlMap wxWinMacControlList
;
666 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
668 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
670 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
673 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
675 // adding NULL ControlRef is (first) surely a result of an error and
676 // (secondly) breaks native event processing
677 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
679 wxWinMacControlList
[inControl
] = control
;
682 void wxRemoveMacControlAssociation(wxWindow
*control
)
684 // iterate over all the elements in the class
685 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
686 // we should go on...
692 MacControlMap::iterator it
;
693 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
695 if ( it
->second
== control
)
697 wxWinMacControlList
.erase(it
);
705 // ----------------------------------------------------------------------------
706 // constructors and such
707 // ----------------------------------------------------------------------------
709 wxWindowMac::wxWindowMac()
714 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
719 const wxString
& name
)
722 Create(parent
, id
, pos
, size
, style
, name
);
725 void wxWindowMac::Init()
730 #if WXWIN_COMPATIBILITY_2_4
731 m_backgroundTransparent
= false;
734 #if wxMAC_USE_CORE_GRAPHICS
735 m_cgContextRef
= NULL
;
738 // as all windows are created with WS_VISIBLE style...
741 m_hScrollBar
= NULL
;
742 m_vScrollBar
= NULL
;
743 m_macBackgroundBrush
= wxNullBrush
;
745 m_macIsUserPane
= true;
746 m_clipChildren
= false ;
747 m_cachedClippedRectValid
= false ;
749 // we need a valid font for the encodings
750 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
754 wxWindowMac::~wxWindowMac()
758 m_isBeingDeleted
= true;
760 MacInvalidateBorders() ;
762 #ifndef __WXUNIVERSAL__
763 // VS: make sure there's no wxFrame with last focus set to us:
764 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
766 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
769 if ( frame
->GetLastFocus() == this )
770 frame
->SetLastFocus((wxWindow
*)NULL
);
774 #endif // __WXUNIVERSAL__
776 // destroy children before destroying this window itself
779 // wxRemoveMacControlAssociation( this ) ;
780 // If we delete an item, we should initialize the parent panel,
781 // because it could now be invalid.
782 wxWindow
*parent
= GetParent() ;
785 if (parent
->GetDefaultItem() == (wxButton
*) this)
786 parent
->SetDefaultItem(NULL
);
789 if ( m_peer
&& m_peer
->Ok() )
791 // in case the callback might be called during destruction
792 wxRemoveMacControlAssociation( this) ;
793 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
794 // we currently are not using this hook
795 // ::SetControlColorProc( *m_peer , NULL ) ;
799 if ( g_MacLastWindow
== this )
800 g_MacLastWindow
= NULL
;
802 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
805 if ( frame
->GetLastFocus() == this )
806 frame
->SetLastFocus( NULL
) ;
809 // delete our drop target if we've got one
810 #if wxUSE_DRAG_AND_DROP
811 if ( m_dropTarget
!= NULL
)
821 WXWidget
wxWindowMac::GetHandle() const
823 return (WXWidget
) m_peer
->GetControlRef() ;
826 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
828 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
829 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
830 GetEventTypeCount(eventList
), eventList
, this,
831 (EventHandlerRef
*)&m_macControlEventHandler
);
833 #if !TARGET_API_MAC_OSX
834 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
836 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
837 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
838 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
839 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
840 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
841 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
842 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
843 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
849 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
853 const wxString
& name
)
855 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
857 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
860 m_windowVariant
= parent
->GetWindowVariant() ;
862 if ( m_macIsUserPane
)
864 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
867 | kControlSupportsEmbedding
868 | kControlSupportsLiveFeedback
869 | kControlGetsFocusOnClick
870 // | kControlHasSpecialBackground
871 // | kControlSupportsCalcBestRect
872 | kControlHandlesTracking
873 | kControlSupportsFocus
874 | kControlWantsActivate
878 m_peer
= new wxMacControl(this) ;
879 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
881 MacPostControlCreate(pos
, size
) ;
884 #ifndef __WXUNIVERSAL__
885 // Don't give scrollbars to wxControls unless they ask for them
886 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
887 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
889 MacCreateScrollBars( style
) ;
893 wxWindowCreateEvent
event(this);
894 GetEventHandler()->AddPendingEvent(event
);
899 void wxWindowMac::MacChildAdded()
902 m_vScrollBar
->Raise() ;
904 m_hScrollBar
->Raise() ;
907 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
909 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
911 m_peer
->SetReference( (long) this ) ;
912 GetParent()->AddChild(this);
914 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
916 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
917 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
918 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
919 GetParent()->MacChildAdded() ;
921 // adjust font, controlsize etc
922 DoSetWindowVariant( m_windowVariant
) ;
924 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
926 if (!m_macIsUserPane
)
927 SetInitialBestSize(size
);
929 SetCursor( *wxSTANDARD_CURSOR
) ;
932 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
934 // Don't assert, in case we set the window variant before
935 // the window is created
936 // wxASSERT( m_peer->Ok() ) ;
938 m_windowVariant
= variant
;
940 if (m_peer
== NULL
|| !m_peer
->Ok())
944 ThemeFontID themeFont
= kThemeSystemFont
;
946 // we will get that from the settings later
947 // and make this NORMAL later, but first
948 // we have a few calculations that we must fix
952 case wxWINDOW_VARIANT_NORMAL
:
953 size
= kControlSizeNormal
;
954 themeFont
= kThemeSystemFont
;
957 case wxWINDOW_VARIANT_SMALL
:
958 size
= kControlSizeSmall
;
959 themeFont
= kThemeSmallSystemFont
;
962 case wxWINDOW_VARIANT_MINI
:
963 if (UMAGetSystemVersion() >= 0x1030 )
965 // not always defined in the headers
971 size
= kControlSizeSmall
;
972 themeFont
= kThemeSmallSystemFont
;
976 case wxWINDOW_VARIANT_LARGE
:
977 size
= kControlSizeLarge
;
978 themeFont
= kThemeSystemFont
;
982 wxFAIL_MSG(_T("unexpected window variant"));
986 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
989 font
.MacCreateThemeFont( themeFont
) ;
993 void wxWindowMac::MacUpdateControlFont()
995 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
999 bool wxWindowMac::SetFont(const wxFont
& font
)
1001 bool retval
= wxWindowBase::SetFont( font
) ;
1003 MacUpdateControlFont() ;
1008 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1010 bool retval
= wxWindowBase::SetForegroundColour(col
);
1013 MacUpdateControlFont() ;
1018 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1020 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1024 wxColour
newCol(GetBackgroundColour());
1025 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1026 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1027 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1028 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1030 brush
.SetColour( newCol
) ;
1032 MacSetBackgroundBrush( brush
) ;
1034 MacUpdateControlFont() ;
1039 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1041 m_macBackgroundBrush
= brush
;
1042 m_peer
->SetBackground( brush
) ;
1045 bool wxWindowMac::MacCanFocus() const
1047 // there is currently no way to determine whether the window is running in full keyboard
1048 // access mode, therefore we cannot rely on these features, yet the only other way would be
1049 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1050 // in event handlers...
1051 UInt32 features
= 0 ;
1052 m_peer
->GetFeatures( &features
) ;
1054 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1057 void wxWindowMac::SetFocus()
1059 if ( !AcceptsFocus() )
1062 wxWindow
* former
= FindFocus() ;
1063 if ( former
== this )
1066 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1067 // we can only leave in case of an error
1068 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1069 if ( err
== errCouldntSetFocus
)
1072 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1074 #if !TARGET_API_MAC_OSX
1075 // emulate carbon events when running under CarbonLib where they are not natively available
1078 EventRef evRef
= NULL
;
1079 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1082 wxMacCarbonEvent
cEvent( evRef
) ;
1083 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1084 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1086 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1087 ReleaseEvent(evRef
) ;
1090 // send new focus event
1092 EventRef evRef
= NULL
;
1093 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1096 wxMacCarbonEvent
cEvent( evRef
) ;
1097 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1098 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1100 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1101 ReleaseEvent(evRef
) ;
1106 void wxWindowMac::DoCaptureMouse()
1108 wxApp::s_captureWindow
= this ;
1111 wxWindow
* wxWindowBase::GetCapture()
1113 return wxApp::s_captureWindow
;
1116 void wxWindowMac::DoReleaseMouse()
1118 wxApp::s_captureWindow
= NULL
;
1121 #if wxUSE_DRAG_AND_DROP
1123 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1125 if ( m_dropTarget
!= NULL
)
1126 delete m_dropTarget
;
1128 m_dropTarget
= pDropTarget
;
1129 if ( m_dropTarget
!= NULL
)
1137 // Old style file-manager drag&drop
1138 void wxWindowMac::DragAcceptFiles(bool accept
)
1143 // Returns the size of the native control. In the case of the toplevel window
1144 // this is the content area root control
1146 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1147 int& w
, int& h
) const
1149 wxFAIL_MSG( wxT("Not currently supported") ) ;
1152 // From a wx position / size calculate the appropriate size of the native control
1154 bool wxWindowMac::MacGetBoundsForControl(
1158 int& w
, int& h
, bool adjustOrigin
) const
1160 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1162 // the desired size, minus the border pixels gives the correct size of the control
1166 // todo the default calls may be used as soon as PostCreateControl Is moved here
1167 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1168 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1170 if ( !isCompositing
)
1171 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1173 x
+= MacGetLeftBorderSize() ;
1174 y
+= MacGetTopBorderSize() ;
1175 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1176 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1179 AdjustForParentClientOrigin( x
, y
) ;
1181 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1182 if ( !GetParent()->IsTopLevel() )
1184 x
-= GetParent()->MacGetLeftBorderSize() ;
1185 y
-= GetParent()->MacGetTopBorderSize() ;
1191 // Get window size (not client size)
1192 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1195 m_peer
->GetRect( &bounds
) ;
1198 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1200 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1203 // get the position of the bounds of this window in client coordinates of its parent
1204 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1207 m_peer
->GetRect( &bounds
) ;
1209 int x1
= bounds
.left
;
1210 int y1
= bounds
.top
;
1212 // get the wx window position from the native one
1213 x1
-= MacGetLeftBorderSize() ;
1214 y1
-= MacGetTopBorderSize() ;
1216 if ( !IsTopLevel() )
1218 wxWindow
*parent
= GetParent();
1221 // we must first adjust it to be in window coordinates of the parent,
1222 // as otherwise it gets lost by the ClientAreaOrigin fix
1223 x1
+= parent
->MacGetLeftBorderSize() ;
1224 y1
+= parent
->MacGetTopBorderSize() ;
1226 // and now to client coordinates
1227 wxPoint
pt(parent
->GetClientAreaOrigin());
1239 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1241 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1243 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1246 Point localwhere
= {0, 0} ;
1253 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1261 MacRootWindowToWindow( x
, y
) ;
1263 wxPoint origin
= GetClientAreaOrigin() ;
1270 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1272 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1273 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1275 wxPoint origin
= GetClientAreaOrigin() ;
1281 MacWindowToRootWindow( x
, y
) ;
1284 Point localwhere
= { 0,0 };
1286 localwhere
.h
= * x
;
1288 localwhere
.v
= * y
;
1290 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1299 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1301 wxPoint origin
= GetClientAreaOrigin() ;
1307 MacWindowToRootWindow( x
, y
) ;
1310 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1312 MacRootWindowToWindow( x
, y
) ;
1314 wxPoint origin
= GetClientAreaOrigin() ;
1321 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1329 if ( !IsTopLevel() )
1331 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1334 pt
.x
-= MacGetLeftBorderSize() ;
1335 pt
.y
-= MacGetTopBorderSize() ;
1336 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1346 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1355 MacWindowToRootWindow( &x1
, &y1
) ;
1363 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1372 if ( !IsTopLevel() )
1374 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1377 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1378 pt
.x
+= MacGetLeftBorderSize() ;
1379 pt
.y
+= MacGetTopBorderSize() ;
1389 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1398 MacRootWindowToWindow( &x1
, &y1
) ;
1406 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1408 RgnHandle rgn
= NewRgn() ;
1410 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1412 Rect structure
, content
;
1414 GetRegionBounds( rgn
, &content
) ;
1415 m_peer
->GetRect( &structure
) ;
1416 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1418 left
= content
.left
- structure
.left
;
1419 top
= content
.top
- structure
.top
;
1420 right
= structure
.right
- content
.right
;
1421 bottom
= structure
.bottom
- content
.bottom
;
1425 left
= top
= right
= bottom
= 0 ;
1431 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1433 wxSize sizeTotal
= size
;
1435 RgnHandle rgn
= NewRgn() ;
1436 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1438 Rect content
, structure
;
1439 GetRegionBounds( rgn
, &content
) ;
1440 m_peer
->GetRect( &structure
) ;
1442 // structure is in parent coordinates, but we only need width and height, so it's ok
1444 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1445 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1450 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1451 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1456 // Get size *available for subwindows* i.e. excluding menu bar etc.
1457 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1461 RgnHandle rgn
= NewRgn() ;
1463 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1464 GetRegionBounds( rgn
, &content
) ;
1466 m_peer
->GetRect( &content
) ;
1469 ww
= content
.right
- content
.left
;
1470 hh
= content
.bottom
- content
.top
;
1472 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1473 hh
-= m_hScrollBar
->GetSize().y
;
1475 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1476 ww
-= m_vScrollBar
->GetSize().x
;
1484 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1486 if (m_cursor
== cursor
)
1489 if (wxNullCursor
== cursor
)
1491 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1496 if ( ! wxWindowBase::SetCursor( cursor
) )
1500 wxASSERT_MSG( m_cursor
.Ok(),
1501 wxT("cursor must be valid after call to the base version"));
1503 wxWindowMac
*mouseWin
= 0 ;
1505 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1506 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1508 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1510 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1511 // position, use it...
1515 ControlPartCode part
;
1516 ControlRef control
;
1517 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1519 mouseWin
= wxFindControlFromMacControl( control
) ;
1522 QDSwapPort( savePort
, NULL
) ;
1525 if ( mouseWin
== this && !wxIsBusy() )
1526 m_cursor
.MacInstall() ;
1532 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1534 menu
->SetInvokingWindow(this);
1537 if ( x
== -1 && y
== -1 )
1539 wxPoint mouse
= wxGetMousePosition();
1545 ClientToScreen( &x
, &y
) ;
1548 menu
->MacBeforeDisplay( true ) ;
1549 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1550 if ( HiWord(menuResult
) != 0 )
1553 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1554 wxMenuItem
* item
= NULL
;
1556 item
= menu
->FindItem(id
, &realmenu
) ;
1557 if (item
->IsCheckable())
1558 item
->Check( !item
->IsChecked() ) ;
1560 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1563 menu
->MacAfterDisplay( true ) ;
1564 menu
->SetInvokingWindow(NULL
);
1570 // ----------------------------------------------------------------------------
1572 // ----------------------------------------------------------------------------
1576 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1578 wxWindowBase::DoSetToolTip(tooltip
);
1581 m_tooltip
->SetWindow(this);
1586 void wxWindowMac::MacInvalidateBorders()
1588 if ( m_peer
== NULL
)
1591 bool vis
= MacIsReallyShown() ;
1595 int outerBorder
= MacGetLeftBorderSize() ;
1596 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1599 if ( outerBorder
== 0 )
1602 // now we know that we have something to do at all
1604 // as the borders are drawn on the parent we have to properly invalidate all these areas
1605 RgnHandle updateInner
= NewRgn() ,
1606 updateOuter
= NewRgn() ;
1608 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1610 m_peer
->GetRect( &rect
) ;
1611 RectRgn( updateInner
, &rect
) ;
1612 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1613 RectRgn( updateOuter
, &rect
) ;
1614 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1616 #ifdef __WXMAC_OSX__
1617 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1619 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1621 InvalWindowRgn( tlw
, updateOuter
) ;
1624 DisposeRgn(updateOuter
) ;
1625 DisposeRgn(updateInner
) ;
1628 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
1629 RectRgn( updateInner
, &rect
) ;
1630 InsetRect( &rect
, -4 , -4 ) ;
1631 RectRgn( updateOuter
, &rect
) ;
1632 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1633 wxPoint
parent(0, 0);
1634 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1635 parent
-= GetParent()->GetClientAreaOrigin() ;
1636 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1637 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
1638 DisposeRgn(updateOuter
) ;
1639 DisposeRgn(updateInner
) ;
1645 // deleting a window while it is shown invalidates
1646 // the region occupied by border or focus
1648 if ( IsShown() && ( outerBorder
> 0 ) )
1650 // as the borders are drawn on the parent we have to properly invalidate all these areas
1651 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1655 m_peer
->GetRect( &rect
) ;
1656 RectRgn( updateInner
, &rect
) ;
1657 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1658 RectRgn( updateOuter
, &rect
) ;
1659 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1660 wxPoint
parent(0, 0);
1661 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1662 parent
-= GetParent()->GetClientAreaOrigin() ;
1663 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1664 CopyRgn( updateOuter
, updateTotal
) ;
1666 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1667 DisposeRgn(updateOuter
) ;
1668 DisposeRgn(updateInner
) ;
1669 DisposeRgn(updateTotal
) ;
1675 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1677 int outerBorder
= MacGetLeftBorderSize() ;
1678 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1681 if ( vis
&& ( outerBorder
> 0 ) )
1683 // as the borders are drawn on the parent we have to properly invalidate all these areas
1684 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1688 m_peer
->GetRect( &rect
) ;
1689 RectRgn( updateInner
, &rect
) ;
1690 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1691 RectRgn( updateOuter
, &rect
) ;
1692 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1695 wxPoint parent(0, 0);
1696 #if TARGET_API_MAC_OSX
1697 // no offsetting needed when compositing
1699 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1700 parent -= GetParent()->GetClientAreaOrigin() ;
1701 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1705 CopyRgn( updateOuter
, updateTotal
) ;
1708 RectRgn( updateInner
, &rect
) ;
1709 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1710 RectRgn( updateOuter
, &rect
) ;
1711 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1714 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1717 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1719 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1720 DisposeRgn(updateOuter
) ;
1721 DisposeRgn(updateInner
) ;
1722 DisposeRgn(updateTotal
) ;
1727 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1729 // this is never called for a toplevel window, so we know we have a parent
1730 int former_x
, former_y
, former_w
, former_h
;
1732 // Get true coordinates of former position
1733 DoGetPosition( &former_x
, &former_y
) ;
1734 DoGetSize( &former_w
, &former_h
) ;
1736 wxWindow
*parent
= GetParent();
1739 wxPoint
pt(parent
->GetClientAreaOrigin());
1744 int actualWidth
= width
;
1745 int actualHeight
= height
;
1749 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1750 actualWidth
= m_minWidth
;
1751 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1752 actualHeight
= m_minHeight
;
1753 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1754 actualWidth
= m_maxWidth
;
1755 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1756 actualHeight
= m_maxHeight
;
1758 bool doMove
= false, doResize
= false ;
1760 if ( actualX
!= former_x
|| actualY
!= former_y
)
1763 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1766 if ( doMove
|| doResize
)
1768 // as the borders are drawn outside the native control, we adjust now
1770 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1771 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1772 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1775 wxMacRectToNative( &bounds
, &r
) ;
1777 if ( !GetParent()->IsTopLevel() )
1778 wxMacWindowToNative( GetParent() , &r
) ;
1780 MacInvalidateBorders() ;
1782 m_cachedClippedRectValid
= false ;
1783 m_peer
->SetRect( &r
) ;
1785 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1787 MacInvalidateBorders() ;
1789 MacRepositionScrollBars() ;
1792 wxPoint
point(actualX
, actualY
);
1793 wxMoveEvent
event(point
, m_windowId
);
1794 event
.SetEventObject(this);
1795 GetEventHandler()->ProcessEvent(event
) ;
1800 MacRepositionScrollBars() ;
1801 wxSize
size(actualWidth
, actualHeight
);
1802 wxSizeEvent
event(size
, m_windowId
);
1803 event
.SetEventObject(this);
1804 GetEventHandler()->ProcessEvent(event
);
1809 wxSize
wxWindowMac::DoGetBestSize() const
1811 if ( m_macIsUserPane
|| IsTopLevel() )
1812 return wxWindowBase::DoGetBestSize() ;
1814 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1815 int bestWidth
, bestHeight
;
1817 m_peer
->GetBestRect( &bestsize
) ;
1818 if ( EmptyRect( &bestsize
) )
1823 bestsize
.bottom
= 16 ;
1825 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1827 bestsize
.bottom
= 16 ;
1830 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1832 bestsize
.bottom
= 24 ;
1837 // return wxWindowBase::DoGetBestSize() ;
1841 bestWidth
= bestsize
.right
- bestsize
.left
;
1842 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1843 if ( bestHeight
< 10 )
1846 return wxSize(bestWidth
, bestHeight
);
1849 // set the size of the window: if the dimensions are positive, just use them,
1850 // but if any of them is equal to -1, it means that we must find the value for
1851 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1852 // which case -1 is a valid value for x and y)
1854 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1855 // the width/height to best suit our contents, otherwise we reuse the current
1857 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1859 // get the current size and position...
1860 int currentX
, currentY
;
1861 int currentW
, currentH
;
1863 GetPosition(¤tX
, ¤tY
);
1864 GetSize(¤tW
, ¤tH
);
1866 // ... and don't do anything (avoiding flicker) if it's already ok
1867 if ( x
== currentX
&& y
== currentY
&&
1868 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1871 MacRepositionScrollBars() ; // we might have a real position shift
1876 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1878 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1881 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1883 wxSize size
= wxDefaultSize
;
1884 if ( width
== wxDefaultCoord
)
1886 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1888 size
= DoGetBestSize();
1893 // just take the current one
1898 if ( height
== wxDefaultCoord
)
1900 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1902 if ( size
.x
== wxDefaultCoord
)
1903 size
= DoGetBestSize();
1904 // else: already called DoGetBestSize() above
1910 // just take the current one
1915 DoMoveWindow(x
, y
, width
, height
);
1918 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1920 RgnHandle rgn
= NewRgn() ;
1922 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1924 GetRegionBounds( rgn
, &content
) ;
1934 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
1937 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1939 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1941 int currentclientwidth
, currentclientheight
;
1942 int currentwidth
, currentheight
;
1944 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1945 GetSize( ¤twidth
, ¤theight
) ;
1947 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1948 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1952 void wxWindowMac::SetLabel(const wxString
& title
)
1954 m_label
= wxStripMenuCodes(title
) ;
1956 if ( m_peer
&& m_peer
->Ok() )
1957 m_peer
->SetLabel( m_label
) ;
1962 wxString
wxWindowMac::GetLabel() const
1967 bool wxWindowMac::Show(bool show
)
1969 bool former
= MacIsReallyShown() ;
1970 if ( !wxWindowBase::Show(show
) )
1973 // TODO use visibilityChanged Carbon Event for OSX
1975 m_peer
->SetVisibility( show
, true ) ;
1977 if ( former
!= MacIsReallyShown() )
1978 MacPropagateVisibilityChanged() ;
1981 // patch from Sailesh Agrawal
1982 wxShowEvent
eventShow(GetId(), show
);
1983 eventShow
.SetEventObject(this);
1984 GetEventHandler()->ProcessEvent(eventShow
);
1990 bool wxWindowMac::Enable(bool enable
)
1992 wxASSERT( m_peer
->Ok() ) ;
1993 bool former
= MacIsReallyEnabled() ;
1994 if ( !wxWindowBase::Enable(enable
) )
1997 m_peer
->Enable( enable
) ;
1999 if ( former
!= MacIsReallyEnabled() )
2000 MacPropagateEnabledStateChanged() ;
2006 // status change propagations (will be not necessary for OSX later )
2009 void wxWindowMac::MacPropagateVisibilityChanged()
2011 #if !TARGET_API_MAC_OSX
2012 MacVisibilityChanged() ;
2015 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2018 child
= node
->GetData();
2019 if ( child
->IsShown() )
2020 child
->MacPropagateVisibilityChanged() ;
2022 node
= node
->GetNext();
2027 void wxWindowMac::MacPropagateEnabledStateChanged()
2029 #if !TARGET_API_MAC_OSX
2030 MacEnabledStateChanged() ;
2033 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2036 child
= node
->GetData();
2037 if ( child
->IsEnabled() )
2038 child
->MacPropagateEnabledStateChanged() ;
2040 node
= node
->GetNext();
2045 void wxWindowMac::MacPropagateHiliteChanged()
2047 #if !TARGET_API_MAC_OSX
2048 MacHiliteChanged() ;
2051 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2054 child
= node
->GetData();
2055 if (child
/* && child->IsEnabled() */)
2056 child
->MacPropagateHiliteChanged() ;
2058 node
= node
->GetNext();
2064 // status change notifications
2067 void wxWindowMac::MacVisibilityChanged()
2071 void wxWindowMac::MacHiliteChanged()
2075 void wxWindowMac::MacEnabledStateChanged()
2080 // status queries on the inherited window's state
2083 bool wxWindowMac::MacIsReallyShown()
2085 // only under OSX the visibility of the TLW is taken into account
2086 if ( m_isBeingDeleted
)
2089 #if TARGET_API_MAC_OSX
2090 if ( m_peer
&& m_peer
->Ok() )
2091 return m_peer
->IsVisible();
2094 wxWindow
* win
= this ;
2095 while ( win
->IsShown() )
2097 if ( win
->IsTopLevel() )
2100 win
= win
->GetParent() ;
2108 bool wxWindowMac::MacIsReallyEnabled()
2110 return m_peer
->IsEnabled() ;
2113 bool wxWindowMac::MacIsReallyHilited()
2115 return m_peer
->IsActive();
2118 void wxWindowMac::MacFlashInvalidAreas()
2120 #if TARGET_API_MAC_OSX
2121 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2125 int wxWindowMac::GetCharHeight() const
2127 wxClientDC
dc( (wxWindowMac
*)this ) ;
2129 return dc
.GetCharHeight() ;
2132 int wxWindowMac::GetCharWidth() const
2134 wxClientDC
dc( (wxWindowMac
*)this ) ;
2136 return dc
.GetCharWidth() ;
2139 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2140 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2142 const wxFont
*fontToUse
= theFont
;
2144 fontToUse
= &m_font
;
2146 wxClientDC
dc( (wxWindowMac
*) this ) ;
2148 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2149 if ( externalLeading
)
2150 *externalLeading
= le
;
2160 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2161 * we always intersect with the entire window, not only with the client area
2164 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2166 if ( m_peer
== NULL
)
2169 if ( !MacIsReallyShown() )
2176 wxMacRectToNative( rect
, &r
) ;
2177 m_peer
->SetNeedsDisplay( &r
) ;
2181 m_peer
->SetNeedsDisplay() ;
2185 void wxWindowMac::Freeze()
2187 #if TARGET_API_MAC_OSX
2188 if ( !m_frozenness
++ )
2190 if ( m_peer
&& m_peer
->Ok() )
2191 m_peer
->SetDrawingEnabled( false ) ;
2196 void wxWindowMac::Thaw()
2198 #if TARGET_API_MAC_OSX
2199 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2201 if ( !--m_frozenness
)
2203 if ( m_peer
&& m_peer
->Ok() )
2205 m_peer
->SetDrawingEnabled( true ) ;
2206 m_peer
->InvalidateWithChildren() ;
2212 wxWindowMac
*wxGetActiveWindow()
2214 // actually this is a windows-only concept
2218 // Coordinates relative to the window
2219 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2221 // We really don't move the mouse programmatically under Mac.
2224 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2226 if ( MacGetTopLevelWindow() == NULL
)
2229 #if TARGET_API_MAC_OSX
2230 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2237 event
.GetDC()->Clear() ;
2241 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2246 int wxWindowMac::GetScrollPos(int orient
) const
2248 if ( orient
== wxHORIZONTAL
)
2251 return m_hScrollBar
->GetThumbPosition() ;
2256 return m_vScrollBar
->GetThumbPosition() ;
2262 // This now returns the whole range, not just the number
2263 // of positions that we can scroll.
2264 int wxWindowMac::GetScrollRange(int orient
) const
2266 if ( orient
== wxHORIZONTAL
)
2269 return m_hScrollBar
->GetRange() ;
2274 return m_vScrollBar
->GetRange() ;
2280 int wxWindowMac::GetScrollThumb(int orient
) const
2282 if ( orient
== wxHORIZONTAL
)
2285 return m_hScrollBar
->GetThumbSize() ;
2290 return m_vScrollBar
->GetThumbSize() ;
2296 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2298 if ( orient
== wxHORIZONTAL
)
2301 m_hScrollBar
->SetThumbPosition( pos
) ;
2306 m_vScrollBar
->SetThumbPosition( pos
) ;
2311 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2312 // our own window origin is at leftOrigin/rightOrigin
2315 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2321 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2322 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2324 m_peer
->GetRect( &rect
) ;
2325 // back to the surrounding frame rectangle
2326 InsetRect( &rect
, -1 , -1 ) ;
2328 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2329 if ( UMAGetSystemVersion() >= 0x1030 )
2331 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2332 rect
.bottom
- rect
.top
) ;
2334 HIThemeFrameDrawInfo info
;
2335 memset( &info
, 0 , sizeof( info
) ) ;
2339 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2340 info
.isFocused
= hasFocus
;
2342 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2343 wxASSERT( cgContext
) ;
2345 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2347 info
.kind
= kHIThemeFrameTextFieldSquare
;
2348 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2350 else if ( HasFlag(wxSIMPLE_BORDER
) )
2352 info
.kind
= kHIThemeFrameListBox
;
2353 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2355 else if ( hasFocus
)
2357 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2360 m_peer
->GetRect( &rect
) ;
2361 if ( hasBothScrollbars
)
2363 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2364 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2365 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2366 HIThemeGrowBoxDrawInfo info
;
2367 memset( &info
, 0, sizeof(info
) ) ;
2369 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2370 info
.kind
= kHIThemeGrowBoxKindNone
;
2371 info
.size
= kHIThemeGrowBoxSizeNormal
;
2372 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2373 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2379 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2383 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2384 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2387 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2388 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2389 else if ( HasFlag(wxSIMPLE_BORDER
) )
2390 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2393 DrawThemeFocusRect( &rect
, true ) ;
2395 if ( hasBothScrollbars
)
2397 // GetThemeStandaloneGrowBoxBounds
2398 // DrawThemeStandaloneNoGrowBox
2403 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2405 if ( child
== m_hScrollBar
)
2406 m_hScrollBar
= NULL
;
2407 if ( child
== m_vScrollBar
)
2408 m_vScrollBar
= NULL
;
2410 wxWindowBase::RemoveChild( child
) ;
2413 // New function that will replace some of the above.
2414 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2415 int range
, bool refresh
)
2417 if ( orient
== wxHORIZONTAL
)
2421 if ( range
== 0 || thumbVisible
>= range
)
2423 if ( m_hScrollBar
->IsShown() )
2424 m_hScrollBar
->Show(false) ;
2428 if ( !m_hScrollBar
->IsShown() )
2429 m_hScrollBar
->Show(true) ;
2432 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2439 if ( range
== 0 || thumbVisible
>= range
)
2441 if ( m_vScrollBar
->IsShown() )
2442 m_vScrollBar
->Show(false) ;
2446 if ( !m_vScrollBar
->IsShown() )
2447 m_vScrollBar
->Show(true) ;
2450 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2454 MacRepositionScrollBars() ;
2457 // Does a physical scroll
2458 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2460 if ( dx
== 0 && dy
== 0 )
2463 int width
, height
;
2464 GetClientSize( &width
, &height
) ;
2466 #if TARGET_API_MAC_OSX
2467 if ( true /* m_peer->IsCompositing() */ )
2469 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2470 // area is scrolled, this does not occur if width and height are 2 pixels less,
2471 // TODO write optimal workaround
2472 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2474 scrollrect
.Intersect( *rect
) ;
2476 if ( m_peer
->GetNeedsDisplay() )
2478 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2479 // either immediate redraw or full invalidate
2481 // is the better overall solution, as it does not slow down scrolling
2482 m_peer
->SetNeedsDisplay() ;
2484 // this would be the preferred version for fast drawing controls
2486 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2487 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2488 HIViewRender(m_peer
->GetControlRef()) ;
2495 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2496 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2497 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2499 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2500 // either immediate redraw or full invalidate
2502 // is the better overall solution, as it does not slow down scrolling
2503 m_peer
->SetNeedsDisplay() ;
2505 // this would be the preferred version for fast drawing controls
2507 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2508 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2509 HIViewRender(m_peer
->GetControlRef()) ;
2523 RgnHandle updateRgn
= NewRgn() ;
2526 wxClientDC
dc(this) ;
2527 wxMacPortSetter
helper(&dc
) ;
2529 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2530 //scrollrect.top += MacGetTopBorderSize() ;
2531 //scrollrect.left += MacGetLeftBorderSize() ;
2532 scrollrect
.bottom
= scrollrect
.top
+ height
;
2533 scrollrect
.right
= scrollrect
.left
+ width
;
2537 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2538 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2539 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2542 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2544 // now scroll the former update region as well and add the new update region
2545 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2546 RgnHandle formerUpdateRgn
= NewRgn() ;
2547 RgnHandle scrollRgn
= NewRgn() ;
2548 RectRgn( scrollRgn
, &scrollrect
) ;
2549 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2551 LocalToGlobal( &pt
) ;
2552 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2553 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2555 if ( !EmptyRgn( formerUpdateRgn
) )
2557 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2558 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2559 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2562 InvalWindowRgn(rootWindow
, updateRgn
) ;
2563 DisposeRgn( updateRgn
) ;
2564 DisposeRgn( formerUpdateRgn
) ;
2565 DisposeRgn( scrollRgn
) ;
2573 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2575 child
= node
->GetData();
2578 if (child
== m_vScrollBar
)
2580 if (child
== m_hScrollBar
)
2582 if (child
->IsTopLevel())
2585 child
->GetPosition( &x
, &y
);
2586 child
->GetSize( &w
, &h
);
2589 wxRect
rc( x
, y
, w
, h
);
2590 if (rect
->Intersects( rc
))
2591 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2595 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2600 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2602 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2604 wxScrollWinEvent wevent
;
2605 wevent
.SetPosition(event
.GetPosition());
2606 wevent
.SetOrientation(event
.GetOrientation());
2607 wevent
.SetEventObject(this);
2609 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2610 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2611 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2612 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2613 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2614 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2615 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2616 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2617 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2618 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2619 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2620 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2621 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2622 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2623 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2624 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2626 GetEventHandler()->ProcessEvent(wevent
);
2630 // Get the window with the focus
2631 wxWindowMac
*wxWindowBase::DoFindFocus()
2633 ControlRef control
;
2634 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2635 return wxFindControlFromMacControl( control
) ;
2638 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2640 // panel wants to track the window which was the last to have focus in it,
2641 // so we want to set ourselves as the window which last had focus
2643 // notice that it's also important to do it upwards the tree because
2644 // otherwise when the top level panel gets focus, it won't set it back to
2645 // us, but to some other sibling
2647 // CS: don't know if this is still needed:
2648 //wxChildFocusEvent eventFocus(this);
2649 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2651 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2653 #if wxMAC_USE_CORE_GRAPHICS
2654 GetParent()->Refresh() ;
2656 wxMacWindowStateSaver
sv( this ) ;
2659 m_peer
->GetRect( &rect
) ;
2660 // auf den umgebenden Rahmen zur\9fck
2661 InsetRect( &rect
, -1 , -1 ) ;
2663 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2667 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2669 rect
.right
+= pt
.x
;
2671 rect
.bottom
+= pt
.y
;
2674 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2675 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2676 if ( !bIsFocusEvent
)
2678 // as this erases part of the frame we have to redraw borders
2679 // and because our z-ordering is not always correct (staticboxes)
2680 // we have to invalidate things, we cannot simple redraw
2681 MacInvalidateBorders() ;
2689 void wxWindowMac::OnInternalIdle()
2691 // This calls the UI-update mechanism (querying windows for
2692 // menu/toolbar/control state information)
2693 if (wxUpdateUIEvent::CanUpdate(this))
2694 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2697 // Raise the window to the top of the Z order
2698 void wxWindowMac::Raise()
2700 m_peer
->SetZOrder( true , NULL
) ;
2703 // Lower the window to the bottom of the Z order
2704 void wxWindowMac::Lower()
2706 m_peer
->SetZOrder( false , NULL
) ;
2709 // static wxWindow *gs_lastWhich = NULL;
2711 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2713 // first trigger a set cursor event
2715 wxPoint clientorigin
= GetClientAreaOrigin() ;
2716 wxSize clientsize
= GetClientSize() ;
2718 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2720 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2722 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2723 if ( processedEvtSetCursor
&& event
.HasCursor() )
2725 cursor
= event
.GetCursor() ;
2729 // the test for processedEvtSetCursor is here to prevent using m_cursor
2730 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2731 // it - this is a way to say that our cursor shouldn't be used for this
2733 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2736 if ( !wxIsBusy() && !GetParent() )
2737 cursor
= *wxSTANDARD_CURSOR
;
2741 cursor
.MacInstall() ;
2744 return cursor
.Ok() ;
2747 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2751 return m_tooltip
->GetTip() ;
2754 return wxEmptyString
;
2757 void wxWindowMac::ClearBackground()
2763 void wxWindowMac::Update()
2765 #if TARGET_API_MAC_OSX
2766 MacGetTopLevelWindow()->MacPerformUpdates() ;
2768 ::Draw1Control( m_peer
->GetControlRef() ) ;
2772 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2774 wxTopLevelWindowMac
* win
= NULL
;
2775 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2777 win
= wxFindWinFromMacWindow( window
) ;
2782 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2784 MacUpdateClippedRects() ;
2786 return m_cachedClippedClientRect
;
2789 const wxRect
& wxWindowMac::MacGetClippedRect() const
2791 MacUpdateClippedRects() ;
2793 return m_cachedClippedRect
;
2796 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2798 MacUpdateClippedRects() ;
2800 return m_cachedClippedRectWithOuterStructure
;
2803 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2805 static wxRegion emptyrgn
;
2807 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2809 MacUpdateClippedRects() ;
2810 if ( includeOuterStructures
)
2811 return m_cachedClippedRegionWithOuterStructure
;
2813 return m_cachedClippedRegion
;
2821 void wxWindowMac::MacUpdateClippedRects() const
2823 if ( m_cachedClippedRectValid
)
2826 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2827 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2828 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2829 // to add focus borders everywhere
2831 Rect r
, rIncludingOuterStructures
;
2833 m_peer
->GetRect( &r
) ;
2834 r
.left
-= MacGetLeftBorderSize() ;
2835 r
.top
-= MacGetTopBorderSize() ;
2836 r
.bottom
+= MacGetBottomBorderSize() ;
2837 r
.right
+= MacGetRightBorderSize() ;
2844 rIncludingOuterStructures
= r
;
2845 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2847 wxRect cl
= GetClientRect() ;
2848 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2852 const wxWindow
* child
= this ;
2853 const wxWindow
* parent
= NULL
;
2855 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2857 if ( parent
->MacIsChildOfClientArea(child
) )
2859 size
= parent
->GetClientSize() ;
2860 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2866 // this will be true for scrollbars, toolbars etc.
2867 size
= parent
->GetSize() ;
2868 y
= parent
->MacGetTopBorderSize() ;
2869 x
= parent
->MacGetLeftBorderSize() ;
2870 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2871 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2874 parent
->MacWindowToRootWindow( &x
, &y
) ;
2875 MacRootWindowToWindow( &x
, &y
) ;
2877 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2879 // the wxwindow and client rects will always be clipped
2880 SectRect( &r
, &rparent
, &r
) ;
2881 SectRect( &rClient
, &rparent
, &rClient
) ;
2883 // the structure only at 'hard' borders
2884 if ( parent
->MacClipChildren() ||
2885 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2887 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2893 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2894 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2895 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2896 m_cachedClippedRectWithOuterStructure
= wxRect(
2897 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2898 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2899 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2901 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2902 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2903 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2905 m_cachedClippedRectValid
= true ;
2909 This function must not change the updatergn !
2911 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2913 bool handled
= false ;
2915 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2916 GetRegionBounds( updatergn
, &updatebounds
) ;
2918 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2920 if ( !EmptyRgn(updatergn
) )
2922 RgnHandle newupdate
= NewRgn() ;
2923 wxSize point
= GetClientSize() ;
2924 wxPoint origin
= GetClientAreaOrigin() ;
2925 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2926 SectRgn( newupdate
, updatergn
, newupdate
) ;
2928 // first send an erase event to the entire update area
2930 // for the toplevel window this really is the entire area
2931 // for all the others only their client area, otherwise they
2932 // might be drawing with full alpha and eg put blue into
2933 // the grow-box area of a scrolled window (scroll sample)
2934 wxDC
* dc
= new wxWindowDC(this);
2936 dc
->SetClippingRegion(wxRegion(updatergn
));
2938 dc
->SetClippingRegion(wxRegion(newupdate
));
2940 wxEraseEvent
eevent( GetId(), dc
);
2941 eevent
.SetEventObject( this );
2942 GetEventHandler()->ProcessEvent( eevent
);
2946 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2947 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2948 m_updateRegion
= newupdate
;
2949 DisposeRgn( newupdate
) ;
2951 if ( !m_updateRegion
.Empty() )
2953 // paint the window itself
2956 event
.SetTimestamp(time
);
2957 event
.SetEventObject(this);
2958 GetEventHandler()->ProcessEvent(event
);
2962 // now we cannot rely on having its borders drawn by a window itself, as it does not
2963 // get the updateRgn wide enough to always do so, so we do it from the parent
2964 // this would also be the place to draw any custom backgrounds for native controls
2965 // in Composited windowing
2966 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2970 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2972 child
= node
->GetData();
2975 if (child
== m_vScrollBar
)
2977 if (child
== m_hScrollBar
)
2979 if (child
->IsTopLevel())
2981 if (!child
->IsShown())
2984 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2986 child
->GetPosition( &x
, &y
);
2987 child
->GetSize( &w
, &h
);
2988 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2989 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2990 InsetRect( &childRect
, -10 , -10) ;
2992 if ( RectInRgn( &childRect
, updatergn
) )
2994 // paint custom borders
2995 wxNcPaintEvent
eventNc( child
->GetId() );
2996 eventNc
.SetEventObject( child
);
2997 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2999 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3000 if ( UMAGetSystemVersion() >= 0x1030 )
3002 child
->MacPaintBorders(0, 0) ;
3007 wxWindowDC
dc(this) ;
3008 dc
.SetClippingRegion(wxRegion(updatergn
));
3009 wxMacPortSetter
helper(&dc
) ;
3010 child
->MacPaintBorders(0, 0) ;
3021 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3023 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3027 if ( iter
->IsTopLevel() )
3028 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3030 iter
= iter
->GetParent() ;
3033 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3038 void wxWindowMac::MacCreateScrollBars( long style
)
3040 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3042 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3044 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3045 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3046 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3047 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3049 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3050 variant
= wxWINDOW_VARIANT_SMALL
;
3053 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3055 GetClientSize( &width
, &height
) ;
3057 wxPoint
vPoint(width
- scrlsize
, 0) ;
3058 wxSize
vSize(scrlsize
, height
- adjust
) ;
3059 wxPoint
hPoint(0, height
- scrlsize
) ;
3060 wxSize
hSize(width
- adjust
, scrlsize
) ;
3062 if ( style
& wxVSCROLL
)
3063 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3065 if ( style
& wxHSCROLL
)
3066 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3069 // because the create does not take into account the client area origin
3070 // we might have a real position shift
3071 MacRepositionScrollBars() ;
3074 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3076 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3081 void wxWindowMac::MacRepositionScrollBars()
3083 if ( !m_hScrollBar
&& !m_vScrollBar
)
3086 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3087 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3088 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3090 // get real client area
3092 GetSize( &width
, &height
);
3094 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3095 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3097 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3098 wxSize
vSize( scrlsize
, height
- adjust
) ;
3099 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3100 wxSize
hSize( width
- adjust
, scrlsize
) ;
3103 int x
= 0, y
= 0, w
, h
;
3104 GetSize( &w
, &h
) ;
3106 MacClientToRootWindow( &x
, &y
) ;
3107 MacClientToRootWindow( &w
, &h
) ;
3109 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3111 int totW
= 10000 , totH
= 10000;
3114 if ( iter
->IsTopLevel() )
3116 iter
->GetSize( &totW
, &totH
) ;
3120 iter
= iter
->GetParent() ;
3134 if ( w
- x
>= totW
)
3139 if ( h
- y
>= totH
)
3147 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3149 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3152 bool wxWindowMac::AcceptsFocus() const
3154 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3157 void wxWindowMac::MacSuperChangedPosition()
3159 // only window-absolute structures have to be moved i.e. controls
3161 m_cachedClippedRectValid
= false ;
3164 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3167 child
= node
->GetData();
3168 child
->MacSuperChangedPosition() ;
3170 node
= node
->GetNext();
3174 void wxWindowMac::MacTopLevelWindowChangedPosition()
3176 // only screen-absolute structures have to be moved i.e. glcanvas
3179 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3182 child
= node
->GetData();
3183 child
->MacTopLevelWindowChangedPosition() ;
3185 node
= node
->GetNext();
3189 long wxWindowMac::MacGetLeftBorderSize() const
3196 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3198 // this metric is only the 'outset' outside the simple frame rect
3199 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3202 else if (HasFlag(wxSIMPLE_BORDER
))
3204 // this metric is only the 'outset' outside the simple frame rect
3205 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3212 long wxWindowMac::MacGetRightBorderSize() const
3214 // they are all symmetric in mac themes
3215 return MacGetLeftBorderSize() ;
3218 long wxWindowMac::MacGetTopBorderSize() const
3220 // they are all symmetric in mac themes
3221 return MacGetLeftBorderSize() ;
3224 long wxWindowMac::MacGetBottomBorderSize() const
3226 // they are all symmetric in mac themes
3227 return MacGetLeftBorderSize() ;
3230 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3232 return style
& ~wxBORDER_MASK
;
3235 // Find the wxWindowMac at the current mouse position, returning the mouse
3237 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3239 pt
= wxGetMousePosition();
3240 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3245 // Get the current mouse position.
3246 wxPoint
wxGetMousePosition()
3250 wxGetMousePosition( &x
, &y
);
3252 return wxPoint(x
, y
);
3255 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3257 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3259 // copied from wxGTK : CS
3260 // VZ: shouldn't we move this to base class then?
3262 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3265 // (a) it's a command event and so is propagated to the parent
3266 // (b) under MSW it can be generated from kbd too
3267 // (c) it uses screen coords (because of (a))
3268 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3270 this->ClientToScreen(event
.GetPosition()));
3271 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3280 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3282 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3283 CallNextEventHandler(
3284 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3285 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3288 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3292 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3296 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3297 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3302 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3304 return eventNotHandledErr
;
3307 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3309 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3311 if ( !wxWindowBase::Reparent(newParent
) )
3314 // copied from MacPostControlCreate
3315 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3317 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3319 ::EmbedControl( m_peer
->GetControlRef() , container
) ;