1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
16 #include "wx/wxprec.h"
19 #include "wx/window.h"
21 #include "wx/dcclient.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
41 #include "wx/toolbar.h"
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 #if TARGET_API_MAC_OSX
83 EVT_PAINT(wxWindowMac::OnPaint
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 1
97 // ---------------------------------------------------------------------------
98 // Utility Routines to move between different coordinate systems
99 // ---------------------------------------------------------------------------
102 * Right now we have the following setup :
103 * a border that is not part of the native control is always outside the
104 * control's border (otherwise we loose all native intelligence, future ways
105 * may be to have a second embedding control responsible for drawing borders
106 * and backgrounds eventually)
107 * so all this border calculations have to be taken into account when calling
108 * native methods or getting native oriented data
109 * so we have three coordinate systems here
110 * wx client coordinates
111 * wx window coordinates (including window frames)
116 // originating from native control
120 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
122 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
125 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
127 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
131 // directed towards native control
134 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
136 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
139 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
141 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
150 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
152 #if TARGET_API_MAC_OSX
154 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
156 kEventControlVisibilityChanged
= 157
162 static const EventTypeSpec eventList
[] =
164 { kEventClassControl
, kEventControlHit
} ,
165 #if TARGET_API_MAC_OSX
166 { kEventClassControl
, kEventControlDraw
} ,
167 { kEventClassControl
, kEventControlVisibilityChanged
} ,
168 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
169 { kEventClassControl
, kEventControlHiliteChanged
} ,
170 { kEventClassControl
, kEventControlSetFocusPart
} ,
172 { kEventClassService
, kEventServiceGetTypes
},
173 { kEventClassService
, kEventServiceCopy
},
174 { kEventClassService
, kEventServicePaste
},
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177 // { kEventClassControl , kEventControlBoundsChanged } ,
181 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
183 OSStatus result
= eventNotHandledErr
;
185 wxMacCarbonEvent
cEvent( event
) ;
187 ControlRef controlRef
;
188 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
190 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
192 switch( GetEventKind( event
) )
194 #if TARGET_API_MAC_OSX
195 case kEventControlDraw
:
197 RgnHandle updateRgn
= NULL
;
198 RgnHandle allocatedRgn
= NULL
;
199 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
201 if ( thisWindow
->GetPeer()->IsCompositing() == false )
203 if ( thisWindow
->GetPeer()->IsRootControl() == false )
205 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
209 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
213 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
215 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
219 if ( thisWindow
->GetPeer()->IsCompositing() == false )
221 allocatedRgn
= NewRgn() ;
222 CopyRgn( updateRgn
, allocatedRgn
) ;
223 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
224 // hide the given region by the new region that must be shifted
225 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
226 updateRgn
= allocatedRgn
;
230 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
232 // as this update region is in native window locals we must adapt it to wx window local
233 allocatedRgn
= NewRgn() ;
234 CopyRgn( updateRgn
, allocatedRgn
) ;
235 // hide the given region by the new region that must be shifted
236 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
237 updateRgn
= allocatedRgn
;
242 GetRegionBounds( updateRgn
, &rgnBounds
) ;
243 #if wxMAC_DEBUG_REDRAW
244 if ( thisWindow
->MacIsUserPane() )
246 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
247 static float color
= 0.5 ;
250 HIViewGetBounds( controlRef
, &bounds
);
251 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
252 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
253 CGContextFillRect( cgContext
, bounds
);
265 #if wxMAC_USE_CORE_GRAPHICS
266 bool created
= false ;
267 CGContextRef cgContext
= 0 ;
268 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
270 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
272 // this parameter is not provided on non-composited windows
274 // rest of the code expects this to be already transformed and clipped for local
275 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
277 GetPortBounds( port
, &bounds
) ;
278 CreateCGContextForPort( port
, &cgContext
) ;
280 wxMacWindowToNative( thisWindow
, updateRgn
) ;
281 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
282 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
283 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
284 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
286 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
287 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
289 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
292 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
293 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
294 controlBounds.right - controlBounds.left ,
295 controlBounds.bottom - controlBounds.top ) );
299 thisWindow
->MacSetCGContextRef( cgContext
) ;
301 wxMacCGContextStateSaver
sg( cgContext
) ;
303 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
305 #if wxMAC_USE_CORE_GRAPHICS
306 thisWindow
->MacSetCGContextRef( NULL
) ;
310 CGContextRelease( cgContext
) ;
315 DisposeRgn( allocatedRgn
) ;
318 case kEventControlVisibilityChanged
:
319 thisWindow
->MacVisibilityChanged() ;
321 case kEventControlEnabledStateChanged
:
322 thisWindow
->MacEnabledStateChanged() ;
324 case kEventControlHiliteChanged
:
325 thisWindow
->MacHiliteChanged() ;
328 // we emulate this event under Carbon CFM
329 case kEventControlSetFocusPart
:
331 Boolean focusEverything
= false ;
332 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
334 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
338 if ( controlPart
== kControlFocusNoPart
)
341 if ( thisWindow
->GetCaret() )
343 thisWindow
->GetCaret()->OnKillFocus();
345 #endif // wxUSE_CARET
346 static bool inKillFocusEvent
= false ;
347 if ( !inKillFocusEvent
)
349 inKillFocusEvent
= true ;
350 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
351 event
.SetEventObject(thisWindow
);
352 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
353 inKillFocusEvent
= false ;
358 // panel wants to track the window which was the last to have focus in it
359 wxChildFocusEvent
eventFocus(thisWindow
);
360 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
363 if ( thisWindow
->GetCaret() )
365 thisWindow
->GetCaret()->OnSetFocus();
367 #endif // wxUSE_CARET
369 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
370 event
.SetEventObject(thisWindow
);
371 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
373 if ( thisWindow
->MacIsUserPane() )
377 case kEventControlHit
:
379 result
= thisWindow
->MacControlHit( handler
, event
) ;
388 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
390 OSStatus result
= eventNotHandledErr
;
392 wxMacCarbonEvent
cEvent( event
) ;
394 ControlRef controlRef
;
395 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
396 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
397 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
399 switch( GetEventKind( event
) )
401 case kEventServiceGetTypes
:
405 textCtrl
->GetSelection( &from
, &to
) ;
407 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
409 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
410 if ( textCtrl
->IsEditable() )
411 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
413 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
414 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
416 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
420 CFArrayAppendValue (copyTypes
, typestring
) ;
422 CFArrayAppendValue (pasteTypes
, typestring
) ;
423 CFRelease( typestring
) ;
429 case kEventServiceCopy
:
433 textCtrl
->GetSelection( &from
, &to
) ;
434 wxString val
= textCtrl
->GetValue() ;
435 val
= val
.Mid( from
, to
- from
) ;
436 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
437 verify_noerr( ClearScrap( &scrapRef
) ) ;
438 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
442 case kEventServicePaste
:
445 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
446 Size textSize
, pastedSize
;
447 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
449 char *content
= new char[textSize
] ;
450 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
451 content
[textSize
-1] = 0 ;
453 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
455 textCtrl
->WriteText( wxString( content
) ) ;
466 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
468 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
469 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
470 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
471 OSStatus result
= eventNotHandledErr
;
473 switch ( GetEventClass( event
) )
475 case kEventClassControl
:
476 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
478 case kEventClassService
:
479 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
484 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
488 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
490 #if !TARGET_API_MAC_OSX
492 // ---------------------------------------------------------------------------
493 // UserPane events for non OSX builds
494 // ---------------------------------------------------------------------------
496 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
498 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
500 win
->MacControlUserPaneDrawProc(part
) ;
502 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
504 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
506 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
508 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
510 return kControlNoPart
;
512 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
514 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
516 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
518 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
520 return kControlNoPart
;
522 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
524 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
526 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
528 win
->MacControlUserPaneIdleProc() ;
530 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
532 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
534 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
536 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
538 return kControlNoPart
;
540 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
542 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
544 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
546 win
->MacControlUserPaneActivateProc(activating
) ;
548 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
550 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
552 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
554 return win
->MacControlUserPaneFocusProc(action
) ;
556 return kControlNoPart
;
558 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
560 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
562 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
564 win
->MacControlUserPaneBackgroundProc(info
) ;
566 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
568 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
570 RgnHandle rgn
= NewRgn() ;
573 MacWindowToRootWindow( &x
,&y
) ;
574 OffsetRgn( rgn
, -x
, -y
) ;
575 wxMacWindowStateSaver
sv( this ) ;
576 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
577 MacDoRedraw( rgn
, 0 ) ;
581 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
583 return kControlNoPart
;
586 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
588 return kControlNoPart
;
591 void wxWindowMac::MacControlUserPaneIdleProc()
595 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
597 return kControlNoPart
;
600 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
604 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
606 return kControlNoPart
;
609 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
615 // ---------------------------------------------------------------------------
616 // Scrollbar Tracking for all
617 // ---------------------------------------------------------------------------
619 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
620 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
624 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
627 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
631 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
633 // ===========================================================================
635 // ===========================================================================
637 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
639 static MacControlMap wxWinMacControlList
;
641 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
643 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
645 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
648 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
650 // adding NULL ControlRef is (first) surely a result of an error and
651 // (secondly) breaks native event processing
652 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
654 wxWinMacControlList
[inControl
] = control
;
657 void wxRemoveMacControlAssociation(wxWindow
*control
)
659 // iterate over all the elements in the class
660 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
661 // we should go on...
667 MacControlMap::iterator it
;
668 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
670 if ( it
->second
== control
)
672 wxWinMacControlList
.erase(it
);
680 // ----------------------------------------------------------------------------
681 // constructors and such
682 // ----------------------------------------------------------------------------
684 wxWindowMac::wxWindowMac()
689 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
694 const wxString
& name
)
697 Create(parent
, id
, pos
, size
, style
, name
);
700 void wxWindowMac::Init()
704 #if WXWIN_COMPATIBILITY_2_4
705 m_backgroundTransparent
= false;
708 // as all windows are created with WS_VISIBLE style...
711 m_hScrollBar
= NULL
;
712 m_vScrollBar
= NULL
;
713 m_macBackgroundBrush
= wxNullBrush
;
715 m_macIsUserPane
= true;
716 #if wxMAC_USE_CORE_GRAPHICS
717 m_cgContextRef
= NULL
;
719 m_clipChildren
= false ;
720 m_cachedClippedRectValid
= false ;
721 // we need a valid font for the encodings
722 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
726 wxWindowMac::~wxWindowMac()
730 m_isBeingDeleted
= true;
732 MacInvalidateBorders() ;
734 #ifndef __WXUNIVERSAL__
735 // VS: make sure there's no wxFrame with last focus set to us:
736 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
738 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
741 if ( frame
->GetLastFocus() == this )
743 frame
->SetLastFocus((wxWindow
*)NULL
);
748 #endif // __WXUNIVERSAL__
750 // destroy children before destroying this window itself
753 // wxRemoveMacControlAssociation( this ) ;
754 // If we delete an item, we should initialize the parent panel,
755 // because it could now be invalid.
756 wxWindow
*parent
= GetParent() ;
759 if (parent
->GetDefaultItem() == (wxButton
*) this)
760 parent
->SetDefaultItem(NULL
);
762 if ( m_peer
&& m_peer
->Ok() )
764 // in case the callback might be called during destruction
765 wxRemoveMacControlAssociation( this) ;
766 // we currently are not using this hook
767 // ::SetControlColorProc( *m_peer , NULL ) ;
771 if ( g_MacLastWindow
== this )
773 g_MacLastWindow
= NULL
;
776 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
779 if ( frame
->GetLastFocus() == this )
780 frame
->SetLastFocus( NULL
) ;
783 // delete our drop target if we've got one
784 #if wxUSE_DRAG_AND_DROP
785 if ( m_dropTarget
!= NULL
)
790 #endif // wxUSE_DRAG_AND_DROP
794 WXWidget
wxWindowMac::GetHandle() const
796 return (WXWidget
) m_peer
->GetControlRef() ;
800 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
802 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
803 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
804 GetEventTypeCount(eventList
), eventList
, this,
805 (EventHandlerRef
*)&m_macControlEventHandler
);
806 #if !TARGET_API_MAC_OSX
807 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
809 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
810 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
811 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
812 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
813 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
814 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
815 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
816 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
823 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
827 const wxString
& name
)
829 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
831 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
834 m_windowVariant
= parent
->GetWindowVariant() ;
836 if ( m_macIsUserPane
)
838 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
841 | kControlSupportsEmbedding
842 | kControlSupportsLiveFeedback
843 | kControlGetsFocusOnClick
844 // | kControlHasSpecialBackground
845 // | kControlSupportsCalcBestRect
846 | kControlHandlesTracking
847 | kControlSupportsFocus
848 | kControlWantsActivate
852 m_peer
= new wxMacControl(this) ;
853 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
856 MacPostControlCreate(pos
,size
) ;
858 #ifndef __WXUNIVERSAL__
859 // Don't give scrollbars to wxControls unless they ask for them
860 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
861 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
863 MacCreateScrollBars( style
) ;
867 wxWindowCreateEvent
event(this);
868 GetEventHandler()->AddPendingEvent(event
);
873 void wxWindowMac::MacChildAdded()
877 m_vScrollBar
->Raise() ;
881 m_hScrollBar
->Raise() ;
886 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
888 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
890 m_peer
->SetReference( (long) this ) ;
891 GetParent()->AddChild(this);
893 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
895 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
896 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
897 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
898 GetParent()->MacChildAdded() ;
900 // adjust font, controlsize etc
901 DoSetWindowVariant( m_windowVariant
) ;
903 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
905 if (!m_macIsUserPane
)
907 SetInitialBestSize(size
);
910 SetCursor( *wxSTANDARD_CURSOR
) ;
913 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
915 // Don't assert, in case we set the window variant before
916 // the window is created
917 // wxASSERT( m_peer->Ok() ) ;
919 m_windowVariant
= variant
;
921 if (m_peer
== NULL
|| !m_peer
->Ok())
925 ThemeFontID themeFont
= kThemeSystemFont
;
927 // we will get that from the settings later
928 // and make this NORMAL later, but first
929 // we have a few calculations that we must fix
933 case wxWINDOW_VARIANT_NORMAL
:
934 size
= kControlSizeNormal
;
935 themeFont
= kThemeSystemFont
;
937 case wxWINDOW_VARIANT_SMALL
:
938 size
= kControlSizeSmall
;
939 themeFont
= kThemeSmallSystemFont
;
941 case wxWINDOW_VARIANT_MINI
:
942 if (UMAGetSystemVersion() >= 0x1030 )
944 // not always defined in the headers
950 size
= kControlSizeSmall
;
951 themeFont
= kThemeSmallSystemFont
;
954 case wxWINDOW_VARIANT_LARGE
:
955 size
= kControlSizeLarge
;
956 themeFont
= kThemeSystemFont
;
959 wxFAIL_MSG(_T("unexpected window variant"));
962 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
965 font
.MacCreateThemeFont( themeFont
) ;
969 void wxWindowMac::MacUpdateControlFont()
971 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
975 bool wxWindowMac::SetFont(const wxFont
& font
)
977 bool retval
= wxWindowBase::SetFont( font
) ;
979 MacUpdateControlFont() ;
984 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
986 if ( !wxWindowBase::SetForegroundColour(col
) )
989 MacUpdateControlFont() ;
994 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
996 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1000 wxColour
newCol(GetBackgroundColour());
1001 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1003 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1005 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1007 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1011 brush
.SetColour( newCol
) ;
1013 MacSetBackgroundBrush( brush
) ;
1015 MacUpdateControlFont() ;
1020 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1022 m_macBackgroundBrush
= brush
;
1023 m_peer
->SetBackground( brush
) ;
1026 bool wxWindowMac::MacCanFocus() const
1028 // there is currently no way to determine whether the window is running in full keyboard
1029 // access mode, therefore we cannot rely on these features, yet the only other way would be
1030 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1031 // in event handlers...
1032 UInt32 features
= 0 ;
1033 m_peer
->GetFeatures( & features
) ;
1034 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1038 void wxWindowMac::SetFocus()
1040 if ( AcceptsFocus() )
1043 wxWindow
* former
= FindFocus() ;
1044 if ( former
== this )
1047 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1048 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1049 // leave in case of an error
1050 if ( err
== errCouldntSetFocus
)
1053 #if !TARGET_API_MAC_OSX
1054 // emulate carbon events when running under carbonlib where they are not natively available
1057 EventRef evRef
= NULL
;
1058 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1061 wxMacCarbonEvent
cEvent( evRef
) ;
1062 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1063 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1065 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1066 ReleaseEvent(evRef
) ;
1068 // send new focus event
1070 EventRef evRef
= NULL
;
1071 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1074 wxMacCarbonEvent
cEvent( evRef
) ;
1075 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1076 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1078 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1079 ReleaseEvent(evRef
) ;
1086 void wxWindowMac::DoCaptureMouse()
1088 wxApp::s_captureWindow
= this ;
1091 wxWindow
* wxWindowBase::GetCapture()
1093 return wxApp::s_captureWindow
;
1096 void wxWindowMac::DoReleaseMouse()
1098 wxApp::s_captureWindow
= NULL
;
1101 #if wxUSE_DRAG_AND_DROP
1103 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1105 if ( m_dropTarget
!= 0 ) {
1106 delete m_dropTarget
;
1109 m_dropTarget
= pDropTarget
;
1110 if ( m_dropTarget
!= 0 )
1118 // Old style file-manager drag&drop
1119 void wxWindowMac::DragAcceptFiles(bool accept
)
1124 // Returns the size of the native control. In the case of the toplevel window
1125 // this is the content area root control
1127 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1128 int& w
, int& h
) const
1130 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1133 // From a wx position / size calculate the appropriate size of the native control
1135 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1138 int& w
, int& h
, bool adjustOrigin
) const
1140 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1142 // the desired size, minus the border pixels gives the correct size of the control
1146 // todo the default calls may be used as soon as PostCreateControl Is moved here
1147 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1148 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1150 if ( !isCompositing
)
1151 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1153 x
+= MacGetLeftBorderSize() ;
1154 y
+= MacGetTopBorderSize() ;
1155 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1156 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1159 AdjustForParentClientOrigin( x
, y
) ;
1161 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1162 if ( !GetParent()->IsTopLevel() )
1164 x
-= GetParent()->MacGetLeftBorderSize() ;
1165 y
-= GetParent()->MacGetTopBorderSize() ;
1171 // Get window size (not client size)
1172 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1175 m_peer
->GetRect( &bounds
) ;
1177 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1178 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1181 // get the position of the bounds of this window in client coordinates of its parent
1182 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1185 m_peer
->GetRect( &bounds
) ;
1187 int x1
= bounds
.left
;
1188 int y1
= bounds
.top
;
1190 // get the wx window position from the native one
1191 x1
-= MacGetLeftBorderSize() ;
1192 y1
-= MacGetTopBorderSize() ;
1194 if ( !IsTopLevel() )
1196 wxWindow
*parent
= GetParent();
1199 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1200 x1
+= parent
->MacGetLeftBorderSize() ;
1201 y1
+= parent
->MacGetTopBorderSize() ;
1202 // and now to client coordinates
1203 wxPoint
pt(parent
->GetClientAreaOrigin());
1212 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1214 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1216 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1219 Point localwhere
= {0,0} ;
1221 if(x
) localwhere
.h
= * x
;
1222 if(y
) localwhere
.v
= * y
;
1224 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1225 if(x
) *x
= localwhere
.h
;
1226 if(y
) *y
= localwhere
.v
;
1229 MacRootWindowToWindow( x
, y
) ;
1231 wxPoint origin
= GetClientAreaOrigin() ;
1232 if(x
) *x
-= origin
.x
;
1233 if(y
) *y
-= origin
.y
;
1236 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1238 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1239 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1241 wxPoint origin
= GetClientAreaOrigin() ;
1242 if(x
) *x
+= origin
.x
;
1243 if(y
) *y
+= origin
.y
;
1245 MacWindowToRootWindow( x
, y
) ;
1248 Point localwhere
= { 0,0 };
1249 if(x
) localwhere
.h
= * x
;
1250 if(y
) localwhere
.v
= * y
;
1251 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1252 if(x
) *x
= localwhere
.h
;
1253 if(y
) *y
= localwhere
.v
;
1257 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1259 wxPoint origin
= GetClientAreaOrigin() ;
1260 if(x
) *x
+= origin
.x
;
1261 if(y
) *y
+= origin
.y
;
1263 MacWindowToRootWindow( x
, y
) ;
1266 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1268 MacRootWindowToWindow( x
, y
) ;
1270 wxPoint origin
= GetClientAreaOrigin() ;
1271 if(x
) *x
-= origin
.x
;
1272 if(y
) *y
-= origin
.y
;
1275 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1278 if ( x
) pt
.x
= *x
;
1279 if ( y
) pt
.y
= *y
;
1281 if ( !IsTopLevel() )
1283 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1286 pt
.x
-= MacGetLeftBorderSize() ;
1287 pt
.y
-= MacGetTopBorderSize() ;
1288 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1292 if ( x
) *x
= (int) pt
.x
;
1293 if ( y
) *y
= (int) pt
.y
;
1296 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1301 MacWindowToRootWindow( &x1
, &y1
) ;
1306 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1309 if ( x
) pt
.x
= *x
;
1310 if ( y
) pt
.y
= *y
;
1312 if ( !IsTopLevel() )
1314 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1317 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1318 pt
.x
+= MacGetLeftBorderSize() ;
1319 pt
.y
+= MacGetTopBorderSize() ;
1323 if ( x
) *x
= (int) pt
.x
;
1324 if ( y
) *y
= (int) pt
.y
;
1327 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1332 MacRootWindowToWindow( &x1
, &y1
) ;
1337 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1339 RgnHandle rgn
= NewRgn() ;
1340 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1344 GetRegionBounds( rgn
, &content
) ;
1345 m_peer
->GetRect( &structure
) ;
1346 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1348 left
= content
.left
- structure
.left
;
1349 top
= content
.top
- structure
.top
;
1350 right
= structure
.right
- content
.right
;
1351 bottom
= structure
.bottom
- content
.bottom
;
1355 left
= top
= right
= bottom
= 0 ;
1360 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1362 wxSize sizeTotal
= size
;
1364 RgnHandle rgn
= NewRgn() ;
1366 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1370 GetRegionBounds( rgn
, &content
) ;
1372 m_peer
->GetRect( &structure
) ;
1373 // structure is in parent coordinates, but we only need width and height, so it's ok
1375 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1376 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1380 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1381 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1387 // Get size *available for subwindows* i.e. excluding menu bar etc.
1388 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1392 RgnHandle rgn
= NewRgn() ;
1394 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1396 GetRegionBounds( rgn
, &content
) ;
1400 m_peer
->GetRect( &content
) ;
1404 ww
= content
.right
- content
.left
;
1405 hh
= content
.bottom
- content
.top
;
1407 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1409 hh
-= m_hScrollBar
->GetSize().y
;
1411 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1413 ww
-= m_vScrollBar
->GetSize().x
;
1420 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1422 if (m_cursor
== cursor
)
1425 if (wxNullCursor
== cursor
)
1427 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1432 if ( ! wxWindowBase::SetCursor( cursor
) )
1436 wxASSERT_MSG( m_cursor
.Ok(),
1437 wxT("cursor must be valid after call to the base version"));
1440 wxWindowMac
*mouseWin
= 0 ;
1442 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1443 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1445 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1447 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1448 // position, use it...
1452 ControlPartCode part
;
1453 ControlRef control
;
1454 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1456 mouseWin
= wxFindControlFromMacControl( control
) ;
1459 QDSwapPort( savePort
, NULL
) ;
1462 if ( mouseWin
== this && !wxIsBusy() )
1464 m_cursor
.MacInstall() ;
1471 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1473 menu
->SetInvokingWindow(this);
1476 if ( x
== -1 && y
== -1 )
1478 wxPoint mouse
= wxGetMousePosition();
1479 x
= mouse
.x
; y
= mouse
.y
;
1483 ClientToScreen( &x
, &y
) ;
1486 menu
->MacBeforeDisplay( true ) ;
1487 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1488 if ( HiWord(menuResult
) != 0 )
1491 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1492 wxMenuItem
* item
= NULL
;
1494 item
= menu
->FindItem(id
, &realmenu
) ;
1495 if (item
->IsCheckable())
1497 item
->Check( !item
->IsChecked() ) ;
1499 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1501 menu
->MacAfterDisplay( true ) ;
1503 menu
->SetInvokingWindow(NULL
);
1509 // ----------------------------------------------------------------------------
1511 // ----------------------------------------------------------------------------
1515 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1517 wxWindowBase::DoSetToolTip(tooltip
);
1520 m_tooltip
->SetWindow(this);
1523 #endif // wxUSE_TOOLTIPS
1525 void wxWindowMac::MacInvalidateBorders()
1527 if ( m_peer
== NULL
)
1530 bool vis
= MacIsReallyShown() ;
1534 int outerBorder
= MacGetLeftBorderSize() ;
1535 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1538 if ( outerBorder
== 0 )
1541 // now we know that we have something to do at all
1543 // as the borders are drawn on the parent we have to properly invalidate all these areas
1544 RgnHandle updateInner
= NewRgn() ,
1545 updateOuter
= NewRgn() ;
1547 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1549 m_peer
->GetRect( &rect
) ;
1550 RectRgn( updateInner
, &rect
) ;
1551 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1552 RectRgn( updateOuter
, &rect
) ;
1553 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1554 #ifdef __WXMAC_OSX__
1555 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1557 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1559 InvalWindowRgn( tlw
, updateOuter
) ;
1561 DisposeRgn(updateOuter
) ;
1562 DisposeRgn(updateInner
) ;
1564 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1565 RectRgn( updateInner , &rect ) ;
1566 InsetRect( &rect , -4 , -4 ) ;
1567 RectRgn( updateOuter , &rect ) ;
1568 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1569 wxPoint parent(0,0);
1570 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1571 parent -= GetParent()->GetClientAreaOrigin() ;
1572 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1573 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1574 DisposeRgn(updateOuter) ;
1575 DisposeRgn(updateInner) ;
1580 // deleting a window while it is shown invalidates the region occupied by border or
1583 if ( IsShown() && ( outerBorder > 0 ) )
1585 // as the borders are drawn on the parent we have to properly invalidate all these areas
1586 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1590 m_peer->GetRect( &rect ) ;
1591 RectRgn( updateInner , &rect ) ;
1592 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1593 RectRgn( updateOuter , &rect ) ;
1594 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1595 wxPoint parent(0,0);
1596 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1597 parent -= GetParent()->GetClientAreaOrigin() ;
1598 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1599 CopyRgn( updateOuter , updateTotal ) ;
1601 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1602 DisposeRgn(updateOuter) ;
1603 DisposeRgn(updateInner) ;
1604 DisposeRgn(updateTotal) ;
1609 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1611 int outerBorder
= MacGetLeftBorderSize() ;
1612 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1615 if ( vis
&& ( outerBorder
> 0 ) )
1617 // as the borders are drawn on the parent we have to properly invalidate all these areas
1618 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1622 m_peer
->GetRect( &rect
) ;
1623 RectRgn( updateInner
, &rect
) ;
1624 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1625 RectRgn( updateOuter
, &rect
) ;
1626 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1628 wxPoint parent(0,0);
1629 #if TARGET_API_MAC_OSX
1630 // no offsetting needed when compositing
1632 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1633 parent -= GetParent()->GetClientAreaOrigin() ;
1634 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1637 CopyRgn( updateOuter
, updateTotal
) ;
1640 RectRgn( updateInner
, &rect
) ;
1641 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1642 RectRgn( updateOuter
, &rect
) ;
1643 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1645 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1647 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1649 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1650 DisposeRgn(updateOuter
) ;
1651 DisposeRgn(updateInner
) ;
1652 DisposeRgn(updateTotal
) ;
1657 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1659 // this is never called for a toplevel window, so we know we have a parent
1660 int former_x
, former_y
, former_w
, former_h
;
1662 // Get true coordinates of former position
1663 DoGetPosition( &former_x
, &former_y
) ;
1664 DoGetSize( &former_w
, &former_h
) ;
1666 wxWindow
*parent
= GetParent();
1669 wxPoint
pt(parent
->GetClientAreaOrigin());
1674 int actualWidth
= width
;
1675 int actualHeight
= height
;
1679 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1680 actualWidth
= m_minWidth
;
1681 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1682 actualHeight
= m_minHeight
;
1683 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1684 actualWidth
= m_maxWidth
;
1685 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1686 actualHeight
= m_maxHeight
;
1688 bool doMove
= false ;
1689 bool doResize
= false ;
1691 if ( actualX
!= former_x
|| actualY
!= former_y
)
1695 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1700 if ( doMove
|| doResize
)
1702 // as the borders are drawn outside the native control, we adjust now
1704 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1705 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1706 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1709 wxMacRectToNative( &bounds
, &r
) ;
1711 if ( !GetParent()->IsTopLevel() )
1713 wxMacWindowToNative( GetParent() , &r
) ;
1716 MacInvalidateBorders() ;
1718 m_cachedClippedRectValid
= false ;
1719 m_peer
->SetRect( &r
) ;
1721 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1723 MacInvalidateBorders() ;
1725 MacRepositionScrollBars() ;
1728 wxPoint
point(actualX
,actualY
);
1729 wxMoveEvent
event(point
, m_windowId
);
1730 event
.SetEventObject(this);
1731 GetEventHandler()->ProcessEvent(event
) ;
1735 MacRepositionScrollBars() ;
1736 wxSize
size(actualWidth
, actualHeight
);
1737 wxSizeEvent
event(size
, m_windowId
);
1738 event
.SetEventObject(this);
1739 GetEventHandler()->ProcessEvent(event
);
1745 wxSize
wxWindowMac::DoGetBestSize() const
1747 if ( m_macIsUserPane
|| IsTopLevel() )
1748 return wxWindowBase::DoGetBestSize() ;
1750 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1751 int bestWidth
, bestHeight
;
1752 m_peer
->GetBestRect( &bestsize
) ;
1754 if ( EmptyRect( &bestsize
) )
1756 bestsize
.left
= bestsize
.top
= 0 ;
1757 bestsize
.right
= 16 ;
1758 bestsize
.bottom
= 16 ;
1759 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1761 bestsize
.bottom
= 16 ;
1764 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1766 bestsize
.bottom
= 24 ;
1768 #endif // wxUSE_SPINBTN
1771 // return wxWindowBase::DoGetBestSize() ;
1775 bestWidth
= bestsize
.right
- bestsize
.left
;
1776 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1777 if ( bestHeight
< 10 )
1780 return wxSize(bestWidth
, bestHeight
);
1784 // set the size of the window: if the dimensions are positive, just use them,
1785 // but if any of them is equal to -1, it means that we must find the value for
1786 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1787 // which case -1 is a valid value for x and y)
1789 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1790 // the width/height to best suit our contents, otherwise we reuse the current
1792 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1794 // get the current size and position...
1795 int currentX
, currentY
;
1796 GetPosition(¤tX
, ¤tY
);
1798 int currentW
,currentH
;
1799 GetSize(¤tW
, ¤tH
);
1801 // ... and don't do anything (avoiding flicker) if it's already ok
1802 if ( x
== currentX
&& y
== currentY
&&
1803 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1806 MacRepositionScrollBars() ; // we might have a real position shift
1810 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1812 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1815 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1817 wxSize size
= wxDefaultSize
;
1818 if ( width
== wxDefaultCoord
)
1820 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1822 size
= DoGetBestSize();
1827 // just take the current one
1832 if ( height
== wxDefaultCoord
)
1834 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1836 if ( size
.x
== wxDefaultCoord
)
1838 size
= DoGetBestSize();
1840 //else: already called DoGetBestSize() above
1846 // just take the current one
1851 DoMoveWindow(x
, y
, width
, height
);
1855 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1857 RgnHandle rgn
= NewRgn() ;
1859 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1861 GetRegionBounds( rgn
, &content
) ;
1865 content
.left
= content
.top
= 0 ;
1868 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1871 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1873 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1875 int currentclientwidth
, currentclientheight
;
1876 int currentwidth
, currentheight
;
1878 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1879 GetSize( ¤twidth
, ¤theight
) ;
1881 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1882 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1886 void wxWindowMac::SetTitle(const wxString
& title
)
1888 m_label
= wxStripMenuCodes(title
) ;
1890 if ( m_peer
&& m_peer
->Ok() )
1892 m_peer
->SetTitle( m_label
) ;
1897 wxString
wxWindowMac::GetTitle() const
1902 bool wxWindowMac::Show(bool show
)
1904 bool former
= MacIsReallyShown() ;
1905 if ( !wxWindowBase::Show(show
) )
1908 // TODO use visibilityChanged Carbon Event for OSX
1911 m_peer
->SetVisibility( show
, true ) ;
1913 if ( former
!= MacIsReallyShown() )
1914 MacPropagateVisibilityChanged() ;
1918 bool wxWindowMac::Enable(bool enable
)
1920 wxASSERT( m_peer
->Ok() ) ;
1921 bool former
= MacIsReallyEnabled() ;
1922 if ( !wxWindowBase::Enable(enable
) )
1925 m_peer
->Enable( enable
) ;
1927 if ( former
!= MacIsReallyEnabled() )
1928 MacPropagateEnabledStateChanged() ;
1933 // status change propagations (will be not necessary for OSX later )
1936 void wxWindowMac::MacPropagateVisibilityChanged()
1938 #if !TARGET_API_MAC_OSX
1939 MacVisibilityChanged() ;
1941 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1944 wxWindowMac
*child
= node
->GetData();
1945 if ( child
->IsShown() )
1946 child
->MacPropagateVisibilityChanged( ) ;
1947 node
= node
->GetNext();
1952 void wxWindowMac::MacPropagateEnabledStateChanged( )
1954 #if !TARGET_API_MAC_OSX
1955 MacEnabledStateChanged() ;
1957 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1960 wxWindowMac
*child
= node
->GetData();
1961 if ( child
->IsEnabled() )
1962 child
->MacPropagateEnabledStateChanged() ;
1963 node
= node
->GetNext();
1968 void wxWindowMac::MacPropagateHiliteChanged( )
1970 #if !TARGET_API_MAC_OSX
1971 MacHiliteChanged() ;
1973 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1976 wxWindowMac
*child
= node
->GetData();
1977 // if ( child->IsEnabled() )
1978 child
->MacPropagateHiliteChanged() ;
1979 node
= node
->GetNext();
1985 // status change notifications
1988 void wxWindowMac::MacVisibilityChanged()
1992 void wxWindowMac::MacHiliteChanged()
1996 void wxWindowMac::MacEnabledStateChanged()
2001 // status queries on the inherited window's state
2004 bool wxWindowMac::MacIsReallyShown()
2006 // only under OSX the visibility of the TLW is taken into account
2007 if ( m_isBeingDeleted
)
2010 #if TARGET_API_MAC_OSX
2011 if ( m_peer
&& m_peer
->Ok() )
2012 return m_peer
->IsVisible();
2014 wxWindow
* win
= this ;
2015 while( win
->IsShown() )
2017 if ( win
->IsTopLevel() )
2020 win
= win
->GetParent() ;
2028 bool wxWindowMac::MacIsReallyEnabled()
2030 return m_peer
->IsEnabled() ;
2033 bool wxWindowMac::MacIsReallyHilited()
2035 return m_peer
->IsActive();
2038 void wxWindowMac::MacFlashInvalidAreas()
2040 #if TARGET_API_MAC_OSX
2041 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2049 int wxWindowMac::GetCharHeight() const
2051 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2052 return dc
.GetCharHeight() ;
2055 int wxWindowMac::GetCharWidth() const
2057 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2058 return dc
.GetCharWidth() ;
2061 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2062 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2064 const wxFont
*fontToUse
= theFont
;
2066 fontToUse
= &m_font
;
2068 wxClientDC
dc( (wxWindowMac
*) this ) ;
2070 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2071 if ( externalLeading
)
2072 *externalLeading
= le
;
2082 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2083 * we always intersect with the entire window, not only with the client area
2086 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2088 if ( m_peer
== NULL
)
2091 if ( !MacIsReallyShown() )
2097 wxMacRectToNative( rect
, &r
) ;
2098 m_peer
->SetNeedsDisplay( &r
) ;
2102 m_peer
->SetNeedsDisplay() ;
2106 void wxWindowMac::Freeze()
2108 #if TARGET_API_MAC_OSX
2109 if ( !m_frozenness
++ )
2111 if ( m_peer
&& m_peer
->Ok() )
2112 m_peer
->SetDrawingEnabled( false ) ;
2118 void wxWindowMac::Thaw()
2120 #if TARGET_API_MAC_OSX
2121 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2123 if ( !--m_frozenness
)
2125 if ( m_peer
&& m_peer
->Ok() )
2127 m_peer
->SetDrawingEnabled( true ) ;
2128 m_peer
->InvalidateWithChildren() ;
2134 wxWindowMac
*wxGetActiveWindow()
2136 // actually this is a windows-only concept
2140 // Coordinates relative to the window
2141 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2143 // We really don't move the mouse programmatically under Mac.
2146 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2148 if ( MacGetTopLevelWindow() == NULL
)
2150 #if TARGET_API_MAC_OSX
2151 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2158 event
.GetDC()->Clear() ;
2162 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2167 int wxWindowMac::GetScrollPos(int orient
) const
2169 if ( orient
== wxHORIZONTAL
)
2172 return m_hScrollBar
->GetThumbPosition() ;
2177 return m_vScrollBar
->GetThumbPosition() ;
2182 // This now returns the whole range, not just the number
2183 // of positions that we can scroll.
2184 int wxWindowMac::GetScrollRange(int orient
) const
2186 if ( orient
== wxHORIZONTAL
)
2189 return m_hScrollBar
->GetRange() ;
2194 return m_vScrollBar
->GetRange() ;
2199 int wxWindowMac::GetScrollThumb(int orient
) const
2201 if ( orient
== wxHORIZONTAL
)
2204 return m_hScrollBar
->GetThumbSize() ;
2209 return m_vScrollBar
->GetThumbSize() ;
2214 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2216 if ( orient
== wxHORIZONTAL
)
2219 m_hScrollBar
->SetThumbPosition( pos
) ;
2224 m_vScrollBar
->SetThumbPosition( pos
) ;
2229 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2230 // our own window origin is at leftOrigin/rightOrigin
2233 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2239 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2240 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2242 m_peer
->GetRect( &rect
) ;
2243 // back to the surrounding frame rectangle
2244 InsetRect( &rect
, -1 , -1 ) ;
2246 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2247 if ( UMAGetSystemVersion() >= 0x1030 )
2249 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2250 rect
.bottom
- rect
.top
) ;
2252 HIThemeFrameDrawInfo info
;
2253 memset( &info
, 0 , sizeof( info
) ) ;
2257 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2258 info
.isFocused
= hasFocus
;
2260 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2261 wxASSERT( cgContext
) ;
2263 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2265 info
.kind
= kHIThemeFrameTextFieldSquare
;
2266 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2268 else if (HasFlag(wxSIMPLE_BORDER
))
2270 info
.kind
= kHIThemeFrameListBox
;
2271 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2273 else if ( hasFocus
)
2275 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2278 m_peer
->GetRect( &rect
) ;
2279 if ( hasBothScrollbars
)
2281 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2282 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2283 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2284 HIThemeGrowBoxDrawInfo info
;
2285 memset( &info
, 0 , sizeof( info
) ) ;
2287 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2288 info
.kind
= kHIThemeGrowBoxKindNone
;
2289 info
.size
= kHIThemeGrowBoxSizeNormal
;
2290 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2291 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2297 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2301 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2302 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2305 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2307 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2309 else if (HasFlag(wxSIMPLE_BORDER
))
2311 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2316 DrawThemeFocusRect( &rect
, true ) ;
2319 if ( hasBothScrollbars
)
2321 // GetThemeStandaloneGrowBoxBounds
2322 //DrawThemeStandaloneNoGrowBox
2327 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2329 if ( child
== m_hScrollBar
)
2330 m_hScrollBar
= NULL
;
2331 if ( child
== m_vScrollBar
)
2332 m_vScrollBar
= NULL
;
2334 wxWindowBase::RemoveChild( child
) ;
2337 // New function that will replace some of the above.
2338 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2339 int range
, bool refresh
)
2341 if ( orient
== wxHORIZONTAL
)
2345 if ( range
== 0 || thumbVisible
>= range
)
2347 if ( m_hScrollBar
->IsShown() )
2348 m_hScrollBar
->Show(false) ;
2352 if ( !m_hScrollBar
->IsShown() )
2353 m_hScrollBar
->Show(true) ;
2355 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2362 if ( range
== 0 || thumbVisible
>= range
)
2364 if ( m_vScrollBar
->IsShown() )
2365 m_vScrollBar
->Show(false) ;
2369 if ( !m_vScrollBar
->IsShown() )
2370 m_vScrollBar
->Show(true) ;
2372 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2375 MacRepositionScrollBars() ;
2378 // Does a physical scroll
2379 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2381 if( dx
== 0 && dy
==0 )
2384 int width
, height
;
2385 GetClientSize( &width
, &height
) ;
2386 #if TARGET_API_MAC_OSX
2387 if ( 1 /* m_peer->IsCompositing() */ )
2389 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2390 // area is scrolled, this does not occur if width and height are 2 pixels less,
2391 // TODO write optimal workaround
2392 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2395 scrollrect
.Intersect( *rect
) ;
2397 if ( m_peer
->GetNeedsDisplay() )
2399 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2400 // either immediate redraw or full invalidate
2402 // is the better overall solution, as it does not slow down scrolling
2403 m_peer
->SetNeedsDisplay() ;
2405 // this would be the preferred version for fast drawing controls
2407 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2408 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2409 HIViewRender(m_peer
->GetControlRef()) ;
2415 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2416 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2417 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2419 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2420 // either immediate redraw or full invalidate
2422 // is the better overall solution, as it does not slow down scrolling
2423 m_peer
->SetNeedsDisplay() ;
2425 // this would be the preferred version for fast drawing controls
2427 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2428 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2429 HIViewRender(m_peer
->GetControlRef()) ;
2444 RgnHandle updateRgn
= NewRgn() ;
2447 wxClientDC
dc(this) ;
2448 wxMacPortSetter
helper(&dc
) ;
2450 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2451 //scrollrect.top += MacGetTopBorderSize() ;
2452 //scrollrect.left += MacGetLeftBorderSize() ;
2453 scrollrect
.bottom
= scrollrect
.top
+ height
;
2454 scrollrect
.right
= scrollrect
.left
+ width
;
2458 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2459 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2460 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2462 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2464 // now scroll the former update region as well and add the new update region
2466 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2467 RgnHandle formerUpdateRgn
= NewRgn() ;
2468 RgnHandle scrollRgn
= NewRgn() ;
2469 RectRgn( scrollRgn
, &scrollrect
) ;
2470 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2472 LocalToGlobal( &pt
) ;
2473 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2474 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2475 if ( !EmptyRgn( formerUpdateRgn
) )
2477 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2478 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2479 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2481 InvalWindowRgn(rootWindow
, updateRgn
) ;
2482 DisposeRgn( updateRgn
) ;
2483 DisposeRgn( formerUpdateRgn
) ;
2484 DisposeRgn( scrollRgn
) ;
2489 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2491 wxWindowMac
*child
= node
->GetData();
2492 if (child
== m_vScrollBar
) continue;
2493 if (child
== m_hScrollBar
) continue;
2494 if (child
->IsTopLevel()) continue;
2497 child
->GetPosition( &x
, &y
);
2499 child
->GetSize( &w
, &h
);
2503 if (rect
->Intersects(rc
))
2504 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2508 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2513 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2515 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2517 wxScrollWinEvent wevent
;
2518 wevent
.SetPosition(event
.GetPosition());
2519 wevent
.SetOrientation(event
.GetOrientation());
2520 wevent
.SetEventObject(this);
2522 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2523 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2524 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2525 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2526 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2527 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2528 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2529 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2530 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2531 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2532 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2533 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2534 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2535 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2536 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2537 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2539 GetEventHandler()->ProcessEvent(wevent
);
2543 // Get the window with the focus
2544 wxWindowMac
*wxWindowBase::DoFindFocus()
2546 ControlRef control
;
2547 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2548 return wxFindControlFromMacControl( control
) ;
2551 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2553 // panel wants to track the window which was the last to have focus in it,
2554 // so we want to set ourselves as the window which last had focus
2556 // notice that it's also important to do it upwards the tree becaus
2557 // otherwise when the top level panel gets focus, it won't set it back to
2558 // us, but to some other sibling
2560 // CS:don't know if this is still needed:
2561 //wxChildFocusEvent eventFocus(this);
2562 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2564 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2566 #if !wxMAC_USE_CORE_GRAPHICS
2567 wxMacWindowStateSaver
sv( this ) ;
2569 m_peer
->GetRect( &rect
) ;
2570 // auf den umgebenden Rahmen zur\9fck
2571 InsetRect( &rect
, -1 , -1 ) ;
2573 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2577 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2579 rect
.right
+= pt
.x
;
2581 rect
.bottom
+= pt
.y
;
2584 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2585 DrawThemeFocusRect( &rect
, true ) ;
2588 DrawThemeFocusRect( &rect
, false ) ;
2590 // as this erases part of the frame we have to redraw borders
2591 // and because our z-ordering is not always correct (staticboxes)
2592 // we have to invalidate things, we cannot simple redraw
2593 MacInvalidateBorders() ;
2596 GetParent()->Refresh() ;
2603 void wxWindowMac::OnInternalIdle()
2605 // This calls the UI-update mechanism (querying windows for
2606 // menu/toolbar/control state information)
2607 if (wxUpdateUIEvent::CanUpdate(this))
2608 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2611 // Raise the window to the top of the Z order
2612 void wxWindowMac::Raise()
2614 m_peer
->SetZOrder( true , NULL
) ;
2617 // Lower the window to the bottom of the Z order
2618 void wxWindowMac::Lower()
2620 m_peer
->SetZOrder( false , NULL
) ;
2624 // static wxWindow *gs_lastWhich = NULL;
2626 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2628 // first trigger a set cursor event
2630 wxPoint clientorigin
= GetClientAreaOrigin() ;
2631 wxSize clientsize
= GetClientSize() ;
2633 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2635 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2637 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2638 if ( processedEvtSetCursor
&& event
.HasCursor() )
2640 cursor
= event
.GetCursor() ;
2645 // the test for processedEvtSetCursor is here to prevent using m_cursor
2646 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2647 // it - this is a way to say that our cursor shouldn't be used for this
2649 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2659 cursor
= *wxSTANDARD_CURSOR
;
2663 cursor
.MacInstall() ;
2665 return cursor
.Ok() ;
2668 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2673 return m_tooltip
->GetTip() ;
2676 return wxEmptyString
;
2679 void wxWindowMac::ClearBackground()
2685 void wxWindowMac::Update()
2687 #if TARGET_API_MAC_OSX
2688 MacGetTopLevelWindow()->MacPerformUpdates() ;
2690 ::Draw1Control( m_peer
->GetControlRef() ) ;
2694 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2696 wxTopLevelWindowMac
* win
= NULL
;
2697 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2700 win
= wxFindWinFromMacWindow( window
) ;
2705 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2707 MacUpdateClippedRects() ;
2708 return m_cachedClippedClientRect
;
2711 const wxRect
& wxWindowMac::MacGetClippedRect() const
2713 MacUpdateClippedRects() ;
2714 return m_cachedClippedRect
;
2717 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2719 MacUpdateClippedRects() ;
2720 return m_cachedClippedRectWithOuterStructure
;
2723 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2725 static wxRegion emptyrgn
;
2726 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2728 MacUpdateClippedRects() ;
2729 if ( includeOuterStructures
)
2730 return m_cachedClippedRegionWithOuterStructure
;
2732 return m_cachedClippedRegion
;
2740 void wxWindowMac::MacUpdateClippedRects() const
2742 if ( m_cachedClippedRectValid
)
2745 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2746 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2747 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2748 // to add focus borders everywhere
2751 Rect rIncludingOuterStructures
;
2753 m_peer
->GetRect( &r
) ;
2754 r
.left
-= MacGetLeftBorderSize() ;
2755 r
.top
-= MacGetTopBorderSize() ;
2756 r
.bottom
+= MacGetBottomBorderSize() ;
2757 r
.right
+= MacGetRightBorderSize() ;
2764 rIncludingOuterStructures
= r
;
2765 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2767 wxRect cl
= GetClientRect() ;
2768 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2770 const wxWindow
* child
= this ;
2771 const wxWindow
* parent
= NULL
;
2772 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2777 if ( parent
->MacIsChildOfClientArea(child
) )
2779 size
= parent
->GetClientSize() ;
2780 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2786 // this will be true for scrollbars, toolbars etc.
2787 size
= parent
->GetSize() ;
2788 y
= parent
->MacGetTopBorderSize() ;
2789 x
= parent
->MacGetLeftBorderSize() ;
2790 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2791 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2794 parent
->MacWindowToRootWindow( &x
, &y
) ;
2795 MacRootWindowToWindow( &x
, &y
) ;
2797 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2799 // the wxwindow and client rects will always be clipped
2800 SectRect( &r
, &rparent
, &r
) ;
2801 SectRect( &rClient
, &rparent
, &rClient
) ;
2803 // the structure only at 'hard' borders
2804 if ( parent
->MacClipChildren() ||
2805 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2807 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2812 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2813 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2814 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2815 m_cachedClippedRectWithOuterStructure
= wxRect(
2816 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2817 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2818 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2820 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2821 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2822 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2824 m_cachedClippedRectValid
= true ;
2828 This function must not change the updatergn !
2830 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2832 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2833 bool handled
= false ;
2835 GetRegionBounds( updatergn
, &updatebounds
) ;
2837 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2839 if ( !EmptyRgn(updatergn
) )
2841 RgnHandle newupdate
= NewRgn() ;
2842 wxSize point
= GetClientSize() ;
2843 wxPoint origin
= GetClientAreaOrigin() ;
2844 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2845 SectRgn( newupdate
, updatergn
, newupdate
) ;
2847 // first send an erase event to the entire update area
2849 // for the toplevel window this really is the entire area
2850 // for all the others only their client area, otherwise they
2851 // might be drawing with full alpha and eg put blue into
2852 // the grow-box area of a scrolled window (scroll sample)
2853 wxDC
* dc
= new wxWindowDC(this);
2855 dc
->SetClippingRegion(wxRegion(updatergn
));
2857 dc
->SetClippingRegion(wxRegion(newupdate
));
2859 wxEraseEvent
eevent( GetId(), dc
);
2860 eevent
.SetEventObject( this );
2861 GetEventHandler()->ProcessEvent( eevent
);
2865 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2866 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2867 m_updateRegion
= newupdate
;
2868 DisposeRgn( newupdate
) ;
2870 if ( !m_updateRegion
.Empty() )
2872 // paint the window itself
2875 event
.SetTimestamp(time
);
2876 event
.SetEventObject(this);
2877 GetEventHandler()->ProcessEvent(event
);
2881 // now we cannot rely on having its borders drawn by a window itself, as it does not
2882 // get the updateRgn wide enough to always do so, so we do it from the parent
2883 // this would also be the place to draw any custom backgrounds for native controls
2884 // in Composited windowing
2885 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2887 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2889 wxWindowMac
*child
= node
->GetData();
2890 if (child
== m_vScrollBar
) continue;
2891 if (child
== m_hScrollBar
) continue;
2892 if (child
->IsTopLevel()) continue;
2893 if (!child
->IsShown()) continue;
2895 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2898 child
->GetPosition( &x
, &y
);
2900 child
->GetSize( &w
, &h
);
2901 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2902 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2903 InsetRect( &childRect
, -10 , -10) ;
2905 if ( RectInRgn( &childRect
, updatergn
) )
2908 // paint custom borders
2909 wxNcPaintEvent
eventNc( child
->GetId() );
2910 eventNc
.SetEventObject( child
);
2911 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2913 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2914 if ( UMAGetSystemVersion() >= 0x1030 )
2916 child
->MacPaintBorders(0,0) ;
2921 wxWindowDC
dc(this) ;
2922 dc
.SetClippingRegion(wxRegion(updatergn
));
2923 wxMacPortSetter
helper(&dc
) ;
2924 child
->MacPaintBorders(0,0) ;
2934 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2936 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2940 if ( iter
->IsTopLevel() )
2941 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2943 iter
= iter
->GetParent() ;
2945 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2949 void wxWindowMac::MacCreateScrollBars( long style
)
2951 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2953 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2955 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2956 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2957 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2958 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2960 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2961 variant
= wxWINDOW_VARIANT_SMALL
;
2964 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2966 GetClientSize( &width
, &height
) ;
2968 wxPoint
vPoint(width
-scrlsize
, 0) ;
2969 wxSize
vSize(scrlsize
, height
- adjust
) ;
2970 wxPoint
hPoint(0 , height
-scrlsize
) ;
2971 wxSize
hSize( width
- adjust
, scrlsize
) ;
2974 if ( style
& wxVSCROLL
)
2976 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2977 vSize
, wxVERTICAL
);
2980 if ( style
& wxHSCROLL
)
2982 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2983 hSize
, wxHORIZONTAL
);
2988 // because the create does not take into account the client area origin
2989 MacRepositionScrollBars() ; // we might have a real position shift
2992 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
2994 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3000 void wxWindowMac::MacRepositionScrollBars()
3002 if ( !m_hScrollBar
&& !m_vScrollBar
)
3005 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3006 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3007 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3009 // get real client area
3013 GetSize( &width
, &height
) ;
3015 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3016 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3018 wxPoint
vPoint(width
-scrlsize
, 0) ;
3019 wxSize
vSize(scrlsize
, height
- adjust
) ;
3020 wxPoint
hPoint(0 , height
-scrlsize
) ;
3021 wxSize
hSize( width
- adjust
, scrlsize
) ;
3027 GetSize( &w , &h ) ;
3029 MacClientToRootWindow( &x , &y ) ;
3030 MacClientToRootWindow( &w , &h ) ;
3032 wxWindowMac *iter = (wxWindowMac*)this ;
3034 int totW = 10000 , totH = 10000;
3037 if ( iter->IsTopLevel() )
3039 iter->GetSize( &totW , &totH ) ;
3043 iter = iter->GetParent() ;
3071 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3075 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3079 bool wxWindowMac::AcceptsFocus() const
3081 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3084 void wxWindowMac::MacSuperChangedPosition()
3086 m_cachedClippedRectValid
= false ;
3087 // only window-absolute structures have to be moved i.e. controls
3089 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3092 wxWindowMac
*child
= node
->GetData();
3093 child
->MacSuperChangedPosition() ;
3094 node
= node
->GetNext();
3098 void wxWindowMac::MacTopLevelWindowChangedPosition()
3100 // only screen-absolute structures have to be moved i.e. glcanvas
3102 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3105 wxWindowMac
*child
= node
->GetData();
3106 child
->MacTopLevelWindowChangedPosition() ;
3107 node
= node
->GetNext();
3111 long wxWindowMac::MacGetLeftBorderSize( ) const
3118 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3120 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3121 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3123 else if (HasFlag(wxSIMPLE_BORDER
))
3125 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3126 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3131 long wxWindowMac::MacGetRightBorderSize( ) const
3133 // they are all symmetric in mac themes
3134 return MacGetLeftBorderSize() ;
3137 long wxWindowMac::MacGetTopBorderSize( ) const
3139 // they are all symmetric in mac themes
3140 return MacGetLeftBorderSize() ;
3143 long wxWindowMac::MacGetBottomBorderSize( ) const
3145 // they are all symmetric in mac themes
3146 return MacGetLeftBorderSize() ;
3149 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3151 return style
& ~wxBORDER_MASK
;
3154 // Find the wxWindowMac at the current mouse position, returning the mouse
3156 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3158 pt
= wxGetMousePosition();
3159 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3163 // Get the current mouse position.
3164 wxPoint
wxGetMousePosition()
3167 wxGetMousePosition(& x
, & y
);
3168 return wxPoint(x
, y
);
3171 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3173 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3175 // copied from wxGTK : CS
3176 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3179 // (a) it's a command event and so is propagated to the parent
3180 // (b) under MSW it can be generated from kbd too
3181 // (c) it uses screen coords (because of (a))
3182 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3184 this->ClientToScreen(event
.GetPosition()));
3185 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3194 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3196 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3198 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3202 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3206 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3210 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3211 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3215 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3217 return eventNotHandledErr
;
3220 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3222 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3224 if ( !wxWindowBase::Reparent(newParent
) )
3227 //copied from MacPostControlCreate
3228 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3229 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3230 ::EmbedControl( m_peer
->GetControlRef() , container
) ;