1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
16 #include "wx/wxprec.h"
19 #include "wx/window.h"
21 #include "wx/dcclient.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
41 #include "wx/toolbar.h"
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 #if TARGET_API_MAC_OSX
83 EVT_PAINT(wxWindowMac::OnPaint
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 1
97 // ---------------------------------------------------------------------------
98 // Utility Routines to move between different coordinate systems
99 // ---------------------------------------------------------------------------
102 * Right now we have the following setup :
103 * a border that is not part of the native control is always outside the
104 * control's border (otherwise we loose all native intelligence, future ways
105 * may be to have a second embedding control responsible for drawing borders
106 * and backgrounds eventually)
107 * so all this border calculations have to be taken into account when calling
108 * native methods or getting native oriented data
109 * so we have three coordinate systems here
110 * wx client coordinates
111 * wx window coordinates (including window frames)
116 // originating from native control
120 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
122 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
125 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
127 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
131 // directed towards native control
134 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
136 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
139 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
141 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
150 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
152 #if TARGET_API_MAC_OSX
154 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
156 kEventControlVisibilityChanged
= 157
162 static const EventTypeSpec eventList
[] =
164 { kEventClassControl
, kEventControlHit
} ,
165 #if TARGET_API_MAC_OSX
166 { kEventClassControl
, kEventControlDraw
} ,
167 { kEventClassControl
, kEventControlVisibilityChanged
} ,
168 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
169 { kEventClassControl
, kEventControlHiliteChanged
} ,
170 { kEventClassControl
, kEventControlSetFocusPart
} ,
172 { kEventClassService
, kEventServiceGetTypes
},
173 { kEventClassService
, kEventServiceCopy
},
174 { kEventClassService
, kEventServicePaste
},
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177 // { kEventClassControl , kEventControlBoundsChanged } ,
181 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
183 OSStatus result
= eventNotHandledErr
;
185 wxMacCarbonEvent
cEvent( event
) ;
187 ControlRef controlRef
;
188 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
190 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
192 switch( GetEventKind( event
) )
194 #if TARGET_API_MAC_OSX
195 case kEventControlDraw
:
197 RgnHandle updateRgn
= NULL
;
198 RgnHandle allocatedRgn
= NULL
;
199 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
201 if ( thisWindow
->GetPeer()->IsCompositing() == false )
203 if ( thisWindow
->GetPeer()->IsRootControl() == false )
205 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
209 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
213 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
215 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
219 if ( thisWindow
->GetPeer()->IsCompositing() == false )
221 allocatedRgn
= NewRgn() ;
222 CopyRgn( updateRgn
, allocatedRgn
) ;
223 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
224 // hide the given region by the new region that must be shifted
225 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
226 updateRgn
= allocatedRgn
;
230 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
232 // as this update region is in native window locals we must adapt it to wx window local
233 allocatedRgn
= NewRgn() ;
234 CopyRgn( updateRgn
, allocatedRgn
) ;
235 // hide the given region by the new region that must be shifted
236 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
237 updateRgn
= allocatedRgn
;
242 GetRegionBounds( updateRgn
, &rgnBounds
) ;
243 #if wxMAC_DEBUG_REDRAW
244 if ( thisWindow
->MacIsUserPane() )
246 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
247 static float color
= 0.5 ;
250 HIViewGetBounds( controlRef
, &bounds
);
251 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
252 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
253 CGContextFillRect( cgContext
, bounds
);
265 #if wxMAC_USE_CORE_GRAPHICS
266 bool created
= false ;
267 CGContextRef cgContext
= 0 ;
268 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
270 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
272 // this parameter is not provided on non-composited windows
274 // rest of the code expects this to be already transformed and clipped for local
275 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
277 GetPortBounds( port
, &bounds
) ;
278 CreateCGContextForPort( port
, &cgContext
) ;
280 wxMacWindowToNative( thisWindow
, updateRgn
) ;
281 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
282 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
283 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
284 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
286 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
287 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
289 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
292 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
293 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
294 controlBounds.right - controlBounds.left ,
295 controlBounds.bottom - controlBounds.top ) );
299 thisWindow
->MacSetCGContextRef( cgContext
) ;
301 wxMacCGContextStateSaver
sg( cgContext
) ;
303 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
305 #if wxMAC_USE_CORE_GRAPHICS
306 thisWindow
->MacSetCGContextRef( NULL
) ;
310 CGContextRelease( cgContext
) ;
315 DisposeRgn( allocatedRgn
) ;
318 case kEventControlVisibilityChanged
:
319 thisWindow
->MacVisibilityChanged() ;
321 case kEventControlEnabledStateChanged
:
322 thisWindow
->MacEnabledStateChanged() ;
324 case kEventControlHiliteChanged
:
325 thisWindow
->MacHiliteChanged() ;
328 // we emulate this event under Carbon CFM
329 case kEventControlSetFocusPart
:
331 Boolean focusEverything
= false ;
332 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
334 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
338 if ( controlPart
== kControlFocusNoPart
)
341 if ( thisWindow
->GetCaret() )
343 thisWindow
->GetCaret()->OnKillFocus();
345 #endif // wxUSE_CARET
346 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
347 event
.SetEventObject(thisWindow
);
348 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
352 // panel wants to track the window which was the last to have focus in it
353 wxChildFocusEvent
eventFocus(thisWindow
);
354 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
357 if ( thisWindow
->GetCaret() )
359 thisWindow
->GetCaret()->OnSetFocus();
361 #endif // wxUSE_CARET
363 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
364 event
.SetEventObject(thisWindow
);
365 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
367 if ( thisWindow
->MacIsUserPane() )
371 case kEventControlHit
:
373 result
= thisWindow
->MacControlHit( handler
, event
) ;
382 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
384 OSStatus result
= eventNotHandledErr
;
386 wxMacCarbonEvent
cEvent( event
) ;
388 ControlRef controlRef
;
389 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
390 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
391 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
393 switch( GetEventKind( event
) )
395 case kEventServiceGetTypes
:
399 textCtrl
->GetSelection( &from
, &to
) ;
401 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
403 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
404 if ( textCtrl
->IsEditable() )
405 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
407 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
408 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
410 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
414 CFArrayAppendValue (copyTypes
, typestring
) ;
416 CFArrayAppendValue (pasteTypes
, typestring
) ;
417 CFRelease( typestring
) ;
423 case kEventServiceCopy
:
427 textCtrl
->GetSelection( &from
, &to
) ;
428 wxString val
= textCtrl
->GetValue() ;
429 val
= val
.Mid( from
, to
- from
) ;
430 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
431 verify_noerr( ClearScrap( &scrapRef
) ) ;
432 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
436 case kEventServicePaste
:
439 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
440 Size textSize
, pastedSize
;
441 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
443 char *content
= new char[textSize
] ;
444 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
445 content
[textSize
-1] = 0 ;
447 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
449 textCtrl
->WriteText( wxString( content
) ) ;
460 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
462 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
463 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
464 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
465 OSStatus result
= eventNotHandledErr
;
467 switch ( GetEventClass( event
) )
469 case kEventClassControl
:
470 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
472 case kEventClassService
:
473 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
478 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
482 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
484 #if !TARGET_API_MAC_OSX
486 // ---------------------------------------------------------------------------
487 // UserPane events for non OSX builds
488 // ---------------------------------------------------------------------------
490 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
492 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
494 win
->MacControlUserPaneDrawProc(part
) ;
496 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
498 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
500 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
502 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
504 return kControlNoPart
;
506 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
508 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
510 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
512 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
514 return kControlNoPart
;
516 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
518 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
520 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
522 win
->MacControlUserPaneIdleProc() ;
524 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
526 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
528 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
530 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
532 return kControlNoPart
;
534 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
536 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
538 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
540 win
->MacControlUserPaneActivateProc(activating
) ;
542 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
544 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
546 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
548 return win
->MacControlUserPaneFocusProc(action
) ;
550 return kControlNoPart
;
552 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
554 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
556 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
558 win
->MacControlUserPaneBackgroundProc(info
) ;
560 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
562 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
564 RgnHandle rgn
= NewRgn() ;
567 MacWindowToRootWindow( &x
,&y
) ;
568 OffsetRgn( rgn
, -x
, -y
) ;
569 wxMacWindowStateSaver
sv( this ) ;
570 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
571 MacDoRedraw( rgn
, 0 ) ;
575 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
577 return kControlNoPart
;
580 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
582 return kControlNoPart
;
585 void wxWindowMac::MacControlUserPaneIdleProc()
589 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
591 return kControlNoPart
;
594 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
598 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
600 return kControlNoPart
;
603 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
609 // ---------------------------------------------------------------------------
610 // Scrollbar Tracking for all
611 // ---------------------------------------------------------------------------
613 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
614 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
618 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
621 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
625 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
627 // ===========================================================================
629 // ===========================================================================
631 #if KEY_wxList_DEPRECATED
632 wxList
wxWinMacControlList(wxKEY_INTEGER
);
634 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
636 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
639 return (wxControl
*)node
->GetData();
642 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
644 // adding NULL ControlRef is (first) surely a result of an error and
645 // (secondly) breaks native event processing
646 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
648 if ( !wxWinMacControlList
.Find((long)inControl
) )
649 wxWinMacControlList
.Append((long)inControl
, control
);
652 void wxRemoveMacControlAssociation(wxWindow
*control
)
654 // remove all associations pointing to us
655 while ( wxWinMacControlList
.DeleteObject(control
) )
660 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
662 static MacControlMap wxWinMacControlList
;
664 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
666 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
668 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
671 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
673 // adding NULL ControlRef is (first) surely a result of an error and
674 // (secondly) breaks native event processing
675 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
677 wxWinMacControlList
[inControl
] = control
;
680 void wxRemoveMacControlAssociation(wxWindow
*control
)
682 // iterate over all the elements in the class
683 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
684 // we should go on...
690 MacControlMap::iterator it
;
691 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
693 if ( it
->second
== control
)
695 wxWinMacControlList
.erase(it
);
702 #endif // deprecated wxList
704 // ----------------------------------------------------------------------------
705 // constructors and such
706 // ----------------------------------------------------------------------------
708 wxWindowMac::wxWindowMac()
713 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
718 const wxString
& name
)
721 Create(parent
, id
, pos
, size
, style
, name
);
724 void wxWindowMac::Init()
728 #if WXWIN_COMPATIBILITY_2_4
729 m_backgroundTransparent
= false;
732 // as all windows are created with WS_VISIBLE style...
735 m_hScrollBar
= NULL
;
736 m_vScrollBar
= NULL
;
737 m_macBackgroundBrush
= wxNullBrush
;
739 m_macIsUserPane
= true;
740 #if wxMAC_USE_CORE_GRAPHICS
741 m_cgContextRef
= NULL
;
743 m_clipChildren
= false ;
744 m_cachedClippedRectValid
= false ;
745 // we need a valid font for the encodings
746 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
750 wxWindowMac::~wxWindowMac()
754 m_isBeingDeleted
= true;
756 MacInvalidateBorders() ;
758 #ifndef __WXUNIVERSAL__
759 // VS: make sure there's no wxFrame with last focus set to us:
760 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
762 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
765 if ( frame
->GetLastFocus() == this )
767 frame
->SetLastFocus((wxWindow
*)NULL
);
772 #endif // __WXUNIVERSAL__
774 // destroy children before destroying this window itself
777 // wxRemoveMacControlAssociation( this ) ;
778 // If we delete an item, we should initialize the parent panel,
779 // because it could now be invalid.
780 wxWindow
*parent
= GetParent() ;
783 if (parent
->GetDefaultItem() == (wxButton
*) this)
784 parent
->SetDefaultItem(NULL
);
786 if ( m_peer
&& m_peer
->Ok() )
788 // in case the callback might be called during destruction
789 wxRemoveMacControlAssociation( this) ;
790 // we currently are not using this hook
791 // ::SetControlColorProc( *m_peer , NULL ) ;
795 if ( g_MacLastWindow
== this )
797 g_MacLastWindow
= NULL
;
800 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
803 if ( frame
->GetLastFocus() == this )
804 frame
->SetLastFocus( NULL
) ;
807 // delete our drop target if we've got one
808 #if wxUSE_DRAG_AND_DROP
809 if ( m_dropTarget
!= NULL
)
814 #endif // wxUSE_DRAG_AND_DROP
818 WXWidget
wxWindowMac::GetHandle() const
820 return (WXWidget
) m_peer
->GetControlRef() ;
824 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
826 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
827 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
828 GetEventTypeCount(eventList
), eventList
, this,
829 (EventHandlerRef
*)&m_macControlEventHandler
);
830 #if !TARGET_API_MAC_OSX
831 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
833 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
834 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
835 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
836 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
837 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
838 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
839 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
840 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
847 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
851 const wxString
& name
)
853 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
855 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
858 m_windowVariant
= parent
->GetWindowVariant() ;
860 if ( m_macIsUserPane
)
862 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
865 | kControlSupportsEmbedding
866 | kControlSupportsLiveFeedback
867 | kControlGetsFocusOnClick
868 // | kControlHasSpecialBackground
869 // | kControlSupportsCalcBestRect
870 | kControlHandlesTracking
871 | kControlSupportsFocus
872 | kControlWantsActivate
876 m_peer
= new wxMacControl(this) ;
877 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
880 MacPostControlCreate(pos
,size
) ;
882 #ifndef __WXUNIVERSAL__
883 // Don't give scrollbars to wxControls unless they ask for them
884 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
885 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
887 MacCreateScrollBars( style
) ;
891 wxWindowCreateEvent
event(this);
892 GetEventHandler()->AddPendingEvent(event
);
897 void wxWindowMac::MacChildAdded()
901 m_vScrollBar
->Raise() ;
905 m_hScrollBar
->Raise() ;
910 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
912 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
914 m_peer
->SetReference( (long) this ) ;
915 GetParent()->AddChild(this);
917 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
919 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
920 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
921 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
922 GetParent()->MacChildAdded() ;
924 // adjust font, controlsize etc
925 DoSetWindowVariant( m_windowVariant
) ;
927 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
929 if (!m_macIsUserPane
)
931 SetInitialBestSize(size
);
934 SetCursor( *wxSTANDARD_CURSOR
) ;
937 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
939 // Don't assert, in case we set the window variant before
940 // the window is created
941 // wxASSERT( m_peer->Ok() ) ;
943 m_windowVariant
= variant
;
945 if (m_peer
== NULL
|| !m_peer
->Ok())
949 ThemeFontID themeFont
= kThemeSystemFont
;
951 // we will get that from the settings later
952 // and make this NORMAL later, but first
953 // we have a few calculations that we must fix
957 case wxWINDOW_VARIANT_NORMAL
:
958 size
= kControlSizeNormal
;
959 themeFont
= kThemeSystemFont
;
961 case wxWINDOW_VARIANT_SMALL
:
962 size
= kControlSizeSmall
;
963 themeFont
= kThemeSmallSystemFont
;
965 case wxWINDOW_VARIANT_MINI
:
966 if (UMAGetSystemVersion() >= 0x1030 )
968 // not always defined in the headers
974 size
= kControlSizeSmall
;
975 themeFont
= kThemeSmallSystemFont
;
978 case wxWINDOW_VARIANT_LARGE
:
979 size
= kControlSizeLarge
;
980 themeFont
= kThemeSystemFont
;
983 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 if ( !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
) )
1027 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1029 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1031 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1035 brush
.SetColour( newCol
) ;
1037 MacSetBackgroundBrush( brush
) ;
1039 MacUpdateControlFont() ;
1044 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1046 m_macBackgroundBrush
= brush
;
1047 m_peer
->SetBackground( brush
) ;
1050 bool wxWindowMac::MacCanFocus() const
1052 // there is currently no way to determine whether the window is running in full keyboard
1053 // access mode, therefore we cannot rely on these features, yet the only other way would be
1054 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1055 // in event handlers...
1056 UInt32 features
= 0 ;
1057 m_peer
->GetFeatures( & features
) ;
1058 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1062 void wxWindowMac::SetFocus()
1064 if ( AcceptsFocus() )
1067 wxWindow
* former
= FindFocus() ;
1068 if ( former
== this )
1071 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1072 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1073 // leave in case of an error
1074 if ( err
== errCouldntSetFocus
)
1077 #if !TARGET_API_MAC_OSX
1078 // emulate carbon events when running under carbonlib where they are not natively available
1081 EventRef evRef
= NULL
;
1082 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1085 wxMacCarbonEvent
cEvent( evRef
) ;
1086 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1087 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1089 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1090 ReleaseEvent(evRef
) ;
1092 // send new focus event
1094 EventRef evRef
= NULL
;
1095 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1098 wxMacCarbonEvent
cEvent( evRef
) ;
1099 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1100 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1102 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1103 ReleaseEvent(evRef
) ;
1110 void wxWindowMac::DoCaptureMouse()
1112 wxApp::s_captureWindow
= this ;
1115 wxWindow
* wxWindowBase::GetCapture()
1117 return wxApp::s_captureWindow
;
1120 void wxWindowMac::DoReleaseMouse()
1122 wxApp::s_captureWindow
= NULL
;
1125 #if wxUSE_DRAG_AND_DROP
1127 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1129 if ( m_dropTarget
!= 0 ) {
1130 delete m_dropTarget
;
1133 m_dropTarget
= pDropTarget
;
1134 if ( m_dropTarget
!= 0 )
1142 // Old style file-manager drag&drop
1143 void wxWindowMac::DragAcceptFiles(bool accept
)
1148 // Returns the size of the native control. In the case of the toplevel window
1149 // this is the content area root control
1151 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1152 int& w
, int& h
) const
1154 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1157 // From a wx position / size calculate the appropriate size of the native control
1159 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1162 int& w
, int& h
, bool adjustOrigin
) const
1164 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1166 // the desired size, minus the border pixels gives the correct size of the control
1170 // todo the default calls may be used as soon as PostCreateControl Is moved here
1171 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1172 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1174 if ( !isCompositing
)
1175 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1177 x
+= MacGetLeftBorderSize() ;
1178 y
+= MacGetTopBorderSize() ;
1179 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1180 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1183 AdjustForParentClientOrigin( x
, y
) ;
1185 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1186 if ( !GetParent()->IsTopLevel() )
1188 x
-= GetParent()->MacGetLeftBorderSize() ;
1189 y
-= GetParent()->MacGetTopBorderSize() ;
1195 // Get window size (not client size)
1196 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1199 m_peer
->GetRect( &bounds
) ;
1201 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1202 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1205 // get the position of the bounds of this window in client coordinates of its parent
1206 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1209 m_peer
->GetRect( &bounds
) ;
1211 int x1
= bounds
.left
;
1212 int y1
= bounds
.top
;
1214 // get the wx window position from the native one
1215 x1
-= MacGetLeftBorderSize() ;
1216 y1
-= MacGetTopBorderSize() ;
1218 if ( !IsTopLevel() )
1220 wxWindow
*parent
= GetParent();
1223 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1224 x1
+= parent
->MacGetLeftBorderSize() ;
1225 y1
+= parent
->MacGetTopBorderSize() ;
1226 // and now to client coordinates
1227 wxPoint
pt(parent
->GetClientAreaOrigin());
1236 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1238 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1240 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1243 Point localwhere
= {0,0} ;
1245 if(x
) localwhere
.h
= * x
;
1246 if(y
) localwhere
.v
= * y
;
1248 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1249 if(x
) *x
= localwhere
.h
;
1250 if(y
) *y
= localwhere
.v
;
1253 MacRootWindowToWindow( x
, y
) ;
1255 wxPoint origin
= GetClientAreaOrigin() ;
1256 if(x
) *x
-= origin
.x
;
1257 if(y
) *y
-= origin
.y
;
1260 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1262 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1263 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1265 wxPoint origin
= GetClientAreaOrigin() ;
1266 if(x
) *x
+= origin
.x
;
1267 if(y
) *y
+= origin
.y
;
1269 MacWindowToRootWindow( x
, y
) ;
1272 Point localwhere
= { 0,0 };
1273 if(x
) localwhere
.h
= * x
;
1274 if(y
) localwhere
.v
= * y
;
1275 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1276 if(x
) *x
= localwhere
.h
;
1277 if(y
) *y
= localwhere
.v
;
1281 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1283 wxPoint origin
= GetClientAreaOrigin() ;
1284 if(x
) *x
+= origin
.x
;
1285 if(y
) *y
+= origin
.y
;
1287 MacWindowToRootWindow( x
, y
) ;
1290 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1292 MacRootWindowToWindow( x
, y
) ;
1294 wxPoint origin
= GetClientAreaOrigin() ;
1295 if(x
) *x
-= origin
.x
;
1296 if(y
) *y
-= origin
.y
;
1299 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1302 if ( x
) pt
.x
= *x
;
1303 if ( y
) pt
.y
= *y
;
1305 if ( !IsTopLevel() )
1307 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1310 pt
.x
-= MacGetLeftBorderSize() ;
1311 pt
.y
-= MacGetTopBorderSize() ;
1312 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1316 if ( x
) *x
= (int) pt
.x
;
1317 if ( y
) *y
= (int) pt
.y
;
1320 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1325 MacWindowToRootWindow( &x1
, &y1
) ;
1330 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1333 if ( x
) pt
.x
= *x
;
1334 if ( y
) pt
.y
= *y
;
1336 if ( !IsTopLevel() )
1338 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1341 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1342 pt
.x
+= MacGetLeftBorderSize() ;
1343 pt
.y
+= MacGetTopBorderSize() ;
1347 if ( x
) *x
= (int) pt
.x
;
1348 if ( y
) *y
= (int) pt
.y
;
1351 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1356 MacRootWindowToWindow( &x1
, &y1
) ;
1361 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1363 RgnHandle rgn
= NewRgn() ;
1364 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1368 GetRegionBounds( rgn
, &content
) ;
1369 m_peer
->GetRect( &structure
) ;
1370 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1372 left
= content
.left
- structure
.left
;
1373 top
= content
.top
- structure
.top
;
1374 right
= structure
.right
- content
.right
;
1375 bottom
= structure
.bottom
- content
.bottom
;
1379 left
= top
= right
= bottom
= 0 ;
1384 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1386 wxSize sizeTotal
= size
;
1388 RgnHandle rgn
= NewRgn() ;
1390 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1394 GetRegionBounds( rgn
, &content
) ;
1396 m_peer
->GetRect( &structure
) ;
1397 // structure is in parent coordinates, but we only need width and height, so it's ok
1399 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1400 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1404 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1405 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1411 // Get size *available for subwindows* i.e. excluding menu bar etc.
1412 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1416 RgnHandle rgn
= NewRgn() ;
1418 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1420 GetRegionBounds( rgn
, &content
) ;
1424 m_peer
->GetRect( &content
) ;
1428 ww
= content
.right
- content
.left
;
1429 hh
= content
.bottom
- content
.top
;
1431 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1433 hh
-= m_hScrollBar
->GetSize().y
;
1435 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1437 ww
-= m_vScrollBar
->GetSize().x
;
1444 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1446 if (m_cursor
== cursor
)
1449 if (wxNullCursor
== cursor
)
1451 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1456 if ( ! wxWindowBase::SetCursor( cursor
) )
1460 wxASSERT_MSG( m_cursor
.Ok(),
1461 wxT("cursor must be valid after call to the base version"));
1464 wxWindowMac
*mouseWin
= 0 ;
1466 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1467 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1469 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1471 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1472 // position, use it...
1476 ControlPartCode part
;
1477 ControlRef control
;
1478 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1480 mouseWin
= wxFindControlFromMacControl( control
) ;
1483 QDSwapPort( savePort
, NULL
) ;
1486 if ( mouseWin
== this && !wxIsBusy() )
1488 m_cursor
.MacInstall() ;
1495 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1497 menu
->SetInvokingWindow(this);
1500 if ( x
== -1 && y
== -1 )
1502 wxPoint mouse
= wxGetMousePosition();
1503 x
= mouse
.x
; y
= mouse
.y
;
1507 ClientToScreen( &x
, &y
) ;
1510 menu
->MacBeforeDisplay( true ) ;
1511 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1512 if ( HiWord(menuResult
) != 0 )
1515 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1516 wxMenuItem
* item
= NULL
;
1518 item
= menu
->FindItem(id
, &realmenu
) ;
1519 if (item
->IsCheckable())
1521 item
->Check( !item
->IsChecked() ) ;
1523 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1525 menu
->MacAfterDisplay( true ) ;
1527 menu
->SetInvokingWindow(NULL
);
1533 // ----------------------------------------------------------------------------
1535 // ----------------------------------------------------------------------------
1539 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1541 wxWindowBase::DoSetToolTip(tooltip
);
1544 m_tooltip
->SetWindow(this);
1547 #endif // wxUSE_TOOLTIPS
1549 void wxWindowMac::MacInvalidateBorders()
1551 if ( m_peer
== NULL
)
1554 bool vis
= MacIsReallyShown() ;
1558 int outerBorder
= MacGetLeftBorderSize() ;
1559 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1562 if ( outerBorder
== 0 )
1565 // now we know that we have something to do at all
1567 // as the borders are drawn on the parent we have to properly invalidate all these areas
1568 RgnHandle updateInner
= NewRgn() ,
1569 updateOuter
= NewRgn() ;
1571 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1573 m_peer
->GetRect( &rect
) ;
1574 RectRgn( updateInner
, &rect
) ;
1575 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1576 RectRgn( updateOuter
, &rect
) ;
1577 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1578 #ifdef __WXMAC_OSX__
1579 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1581 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1583 InvalWindowRgn( tlw
, updateOuter
) ;
1585 DisposeRgn(updateOuter
) ;
1586 DisposeRgn(updateInner
) ;
1588 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1589 RectRgn( updateInner , &rect ) ;
1590 InsetRect( &rect , -4 , -4 ) ;
1591 RectRgn( updateOuter , &rect ) ;
1592 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1593 wxPoint parent(0,0);
1594 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1595 parent -= GetParent()->GetClientAreaOrigin() ;
1596 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1597 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1598 DisposeRgn(updateOuter) ;
1599 DisposeRgn(updateInner) ;
1604 // deleting a window while it is shown invalidates the region occupied by border or
1607 if ( IsShown() && ( outerBorder > 0 ) )
1609 // as the borders are drawn on the parent we have to properly invalidate all these areas
1610 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1614 m_peer->GetRect( &rect ) ;
1615 RectRgn( updateInner , &rect ) ;
1616 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1617 RectRgn( updateOuter , &rect ) ;
1618 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1619 wxPoint parent(0,0);
1620 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1621 parent -= GetParent()->GetClientAreaOrigin() ;
1622 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1623 CopyRgn( updateOuter , updateTotal ) ;
1625 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1626 DisposeRgn(updateOuter) ;
1627 DisposeRgn(updateInner) ;
1628 DisposeRgn(updateTotal) ;
1633 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1635 int outerBorder
= MacGetLeftBorderSize() ;
1636 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1639 if ( vis
&& ( outerBorder
> 0 ) )
1641 // as the borders are drawn on the parent we have to properly invalidate all these areas
1642 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1646 m_peer
->GetRect( &rect
) ;
1647 RectRgn( updateInner
, &rect
) ;
1648 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1649 RectRgn( updateOuter
, &rect
) ;
1650 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1652 wxPoint parent(0,0);
1653 #if TARGET_API_MAC_OSX
1654 // no offsetting needed when compositing
1656 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1657 parent -= GetParent()->GetClientAreaOrigin() ;
1658 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1661 CopyRgn( updateOuter
, updateTotal
) ;
1664 RectRgn( updateInner
, &rect
) ;
1665 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1666 RectRgn( updateOuter
, &rect
) ;
1667 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1669 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1671 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1673 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1674 DisposeRgn(updateOuter
) ;
1675 DisposeRgn(updateInner
) ;
1676 DisposeRgn(updateTotal
) ;
1681 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1683 // this is never called for a toplevel window, so we know we have a parent
1684 int former_x
, former_y
, former_w
, former_h
;
1686 // Get true coordinates of former position
1687 DoGetPosition( &former_x
, &former_y
) ;
1688 DoGetSize( &former_w
, &former_h
) ;
1690 wxWindow
*parent
= GetParent();
1693 wxPoint
pt(parent
->GetClientAreaOrigin());
1698 int actualWidth
= width
;
1699 int actualHeight
= height
;
1703 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1704 actualWidth
= m_minWidth
;
1705 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1706 actualHeight
= m_minHeight
;
1707 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1708 actualWidth
= m_maxWidth
;
1709 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1710 actualHeight
= m_maxHeight
;
1712 bool doMove
= false ;
1713 bool doResize
= false ;
1715 if ( actualX
!= former_x
|| actualY
!= former_y
)
1719 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1724 if ( doMove
|| doResize
)
1726 // as the borders are drawn outside the native control, we adjust now
1728 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1729 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1730 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1733 wxMacRectToNative( &bounds
, &r
) ;
1735 if ( !GetParent()->IsTopLevel() )
1737 wxMacWindowToNative( GetParent() , &r
) ;
1740 MacInvalidateBorders() ;
1742 m_cachedClippedRectValid
= false ;
1743 m_peer
->SetRect( &r
) ;
1745 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1747 MacInvalidateBorders() ;
1749 MacRepositionScrollBars() ;
1752 wxPoint
point(actualX
,actualY
);
1753 wxMoveEvent
event(point
, m_windowId
);
1754 event
.SetEventObject(this);
1755 GetEventHandler()->ProcessEvent(event
) ;
1759 MacRepositionScrollBars() ;
1760 wxSize
size(actualWidth
, actualHeight
);
1761 wxSizeEvent
event(size
, m_windowId
);
1762 event
.SetEventObject(this);
1763 GetEventHandler()->ProcessEvent(event
);
1769 wxSize
wxWindowMac::DoGetBestSize() const
1771 if ( m_macIsUserPane
|| IsTopLevel() )
1772 return wxWindowBase::DoGetBestSize() ;
1774 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1775 int bestWidth
, bestHeight
;
1776 m_peer
->GetBestRect( &bestsize
) ;
1778 if ( EmptyRect( &bestsize
) )
1780 bestsize
.left
= bestsize
.top
= 0 ;
1781 bestsize
.right
= 16 ;
1782 bestsize
.bottom
= 16 ;
1783 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1785 bestsize
.bottom
= 16 ;
1788 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1790 bestsize
.bottom
= 24 ;
1792 #endif // wxUSE_SPINBTN
1795 // return wxWindowBase::DoGetBestSize() ;
1799 bestWidth
= bestsize
.right
- bestsize
.left
;
1800 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1801 if ( bestHeight
< 10 )
1804 return wxSize(bestWidth
, bestHeight
);
1808 // set the size of the window: if the dimensions are positive, just use them,
1809 // but if any of them is equal to -1, it means that we must find the value for
1810 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1811 // which case -1 is a valid value for x and y)
1813 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1814 // the width/height to best suit our contents, otherwise we reuse the current
1816 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1818 // get the current size and position...
1819 int currentX
, currentY
;
1820 GetPosition(¤tX
, ¤tY
);
1822 int currentW
,currentH
;
1823 GetSize(¤tW
, ¤tH
);
1825 // ... and don't do anything (avoiding flicker) if it's already ok
1826 if ( x
== currentX
&& y
== currentY
&&
1827 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1830 MacRepositionScrollBars() ; // we might have a real position shift
1834 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1836 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1839 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1841 wxSize
size(-1, -1);
1844 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1846 size
= DoGetBestSize();
1851 // just take the current one
1858 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1862 size
= DoGetBestSize();
1864 //else: already called DoGetBestSize() above
1870 // just take the current one
1875 DoMoveWindow(x
, y
, width
, height
);
1879 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1881 RgnHandle rgn
= NewRgn() ;
1883 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1885 GetRegionBounds( rgn
, &content
) ;
1889 content
.left
= content
.top
= 0 ;
1892 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1895 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1897 if ( clientheight
!= -1 || clientheight
!= -1 )
1899 int currentclientwidth
, currentclientheight
;
1900 int currentwidth
, currentheight
;
1902 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1903 GetSize( ¤twidth
, ¤theight
) ;
1905 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1906 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1910 void wxWindowMac::SetTitle(const wxString
& title
)
1912 m_label
= wxStripMenuCodes(title
) ;
1914 if ( m_peer
&& m_peer
->Ok() )
1916 m_peer
->SetTitle( m_label
) ;
1921 wxString
wxWindowMac::GetTitle() const
1926 bool wxWindowMac::Show(bool show
)
1928 bool former
= MacIsReallyShown() ;
1929 if ( !wxWindowBase::Show(show
) )
1932 // TODO use visibilityChanged Carbon Event for OSX
1935 m_peer
->SetVisibility( show
, true ) ;
1937 if ( former
!= MacIsReallyShown() )
1938 MacPropagateVisibilityChanged() ;
1942 bool wxWindowMac::Enable(bool enable
)
1944 wxASSERT( m_peer
->Ok() ) ;
1945 bool former
= MacIsReallyEnabled() ;
1946 if ( !wxWindowBase::Enable(enable
) )
1949 m_peer
->Enable( enable
) ;
1951 if ( former
!= MacIsReallyEnabled() )
1952 MacPropagateEnabledStateChanged() ;
1957 // status change propagations (will be not necessary for OSX later )
1960 void wxWindowMac::MacPropagateVisibilityChanged()
1962 #if !TARGET_API_MAC_OSX
1963 MacVisibilityChanged() ;
1965 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1968 wxWindowMac
*child
= node
->GetData();
1969 if ( child
->IsShown() )
1970 child
->MacPropagateVisibilityChanged( ) ;
1971 node
= node
->GetNext();
1976 void wxWindowMac::MacPropagateEnabledStateChanged( )
1978 #if !TARGET_API_MAC_OSX
1979 MacEnabledStateChanged() ;
1981 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1984 wxWindowMac
*child
= node
->GetData();
1985 if ( child
->IsEnabled() )
1986 child
->MacPropagateEnabledStateChanged() ;
1987 node
= node
->GetNext();
1992 void wxWindowMac::MacPropagateHiliteChanged( )
1994 #if !TARGET_API_MAC_OSX
1995 MacHiliteChanged() ;
1997 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2000 wxWindowMac
*child
= node
->GetData();
2001 // if ( child->IsEnabled() )
2002 child
->MacPropagateHiliteChanged() ;
2003 node
= node
->GetNext();
2009 // status change notifications
2012 void wxWindowMac::MacVisibilityChanged()
2016 void wxWindowMac::MacHiliteChanged()
2020 void wxWindowMac::MacEnabledStateChanged()
2025 // status queries on the inherited window's state
2028 bool wxWindowMac::MacIsReallyShown()
2030 // only under OSX the visibility of the TLW is taken into account
2031 if ( m_isBeingDeleted
)
2034 #if TARGET_API_MAC_OSX
2035 if ( m_peer
&& m_peer
->Ok() )
2036 return m_peer
->IsVisible();
2038 wxWindow
* win
= this ;
2039 while( win
->IsShown() )
2041 if ( win
->IsTopLevel() )
2044 win
= win
->GetParent() ;
2052 bool wxWindowMac::MacIsReallyEnabled()
2054 return m_peer
->IsEnabled() ;
2057 bool wxWindowMac::MacIsReallyHilited()
2059 return m_peer
->IsActive();
2062 void wxWindowMac::MacFlashInvalidAreas()
2064 #if TARGET_API_MAC_OSX
2065 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2073 int wxWindowMac::GetCharHeight() const
2075 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2076 return dc
.GetCharHeight() ;
2079 int wxWindowMac::GetCharWidth() const
2081 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2082 return dc
.GetCharWidth() ;
2085 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2086 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2088 const wxFont
*fontToUse
= theFont
;
2090 fontToUse
= &m_font
;
2092 wxClientDC
dc( (wxWindowMac
*) this ) ;
2094 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2095 if ( externalLeading
)
2096 *externalLeading
= le
;
2106 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2107 * we always intersect with the entire window, not only with the client area
2110 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2112 if ( m_peer
== NULL
)
2115 if ( !MacIsReallyShown() )
2121 wxMacRectToNative( rect
, &r
) ;
2122 m_peer
->SetNeedsDisplay( &r
) ;
2126 m_peer
->SetNeedsDisplay() ;
2130 void wxWindowMac::Freeze()
2132 #if TARGET_API_MAC_OSX
2133 if ( !m_frozenness
++ )
2135 if ( m_peer
&& m_peer
->Ok() )
2136 m_peer
->SetDrawingEnabled( false ) ;
2142 void wxWindowMac::Thaw()
2144 #if TARGET_API_MAC_OSX
2145 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2147 if ( !--m_frozenness
)
2149 if ( m_peer
&& m_peer
->Ok() )
2151 m_peer
->SetDrawingEnabled( true ) ;
2152 m_peer
->InvalidateWithChildren() ;
2158 wxWindowMac
*wxGetActiveWindow()
2160 // actually this is a windows-only concept
2164 // Coordinates relative to the window
2165 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2167 // We really don't move the mouse programmatically under Mac.
2170 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2172 #if TARGET_API_MAC_OSX
2173 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2180 event
.GetDC()->Clear() ;
2184 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2189 int wxWindowMac::GetScrollPos(int orient
) const
2191 if ( orient
== wxHORIZONTAL
)
2194 return m_hScrollBar
->GetThumbPosition() ;
2199 return m_vScrollBar
->GetThumbPosition() ;
2204 // This now returns the whole range, not just the number
2205 // of positions that we can scroll.
2206 int wxWindowMac::GetScrollRange(int orient
) const
2208 if ( orient
== wxHORIZONTAL
)
2211 return m_hScrollBar
->GetRange() ;
2216 return m_vScrollBar
->GetRange() ;
2221 int wxWindowMac::GetScrollThumb(int orient
) const
2223 if ( orient
== wxHORIZONTAL
)
2226 return m_hScrollBar
->GetThumbSize() ;
2231 return m_vScrollBar
->GetThumbSize() ;
2236 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2238 if ( orient
== wxHORIZONTAL
)
2241 m_hScrollBar
->SetThumbPosition( pos
) ;
2246 m_vScrollBar
->SetThumbPosition( pos
) ;
2251 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2252 // our own window origin is at leftOrigin/rightOrigin
2255 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2261 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2262 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2264 m_peer
->GetRect( &rect
) ;
2265 // back to the surrounding frame rectangle
2266 InsetRect( &rect
, -1 , -1 ) ;
2268 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2269 if ( UMAGetSystemVersion() >= 0x1030 )
2271 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2272 rect
.bottom
- rect
.top
) ;
2274 HIThemeFrameDrawInfo info
;
2275 memset( &info
, 0 , sizeof( info
) ) ;
2279 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2280 info
.isFocused
= hasFocus
;
2282 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2283 wxASSERT( cgContext
) ;
2285 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2287 info
.kind
= kHIThemeFrameTextFieldSquare
;
2288 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2290 else if (HasFlag(wxSIMPLE_BORDER
))
2292 info
.kind
= kHIThemeFrameListBox
;
2293 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2295 else if ( hasFocus
)
2297 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2300 m_peer
->GetRect( &rect
) ;
2301 if ( hasBothScrollbars
)
2303 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2304 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2305 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2306 HIThemeGrowBoxDrawInfo info
;
2307 memset( &info
, 0 , sizeof( info
) ) ;
2309 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2310 info
.kind
= kHIThemeGrowBoxKindNone
;
2311 info
.size
= kHIThemeGrowBoxSizeNormal
;
2312 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2313 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2319 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2323 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2324 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2327 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2329 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2331 else if (HasFlag(wxSIMPLE_BORDER
))
2333 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2338 DrawThemeFocusRect( &rect
, true ) ;
2341 if ( hasBothScrollbars
)
2343 // GetThemeStandaloneGrowBoxBounds
2344 //DrawThemeStandaloneNoGrowBox
2349 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2351 if ( child
== m_hScrollBar
)
2352 m_hScrollBar
= NULL
;
2353 if ( child
== m_vScrollBar
)
2354 m_vScrollBar
= NULL
;
2356 wxWindowBase::RemoveChild( child
) ;
2359 // New function that will replace some of the above.
2360 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2361 int range
, bool refresh
)
2363 if ( orient
== wxHORIZONTAL
)
2367 if ( range
== 0 || thumbVisible
>= range
)
2369 if ( m_hScrollBar
->IsShown() )
2370 m_hScrollBar
->Show(false) ;
2374 if ( !m_hScrollBar
->IsShown() )
2375 m_hScrollBar
->Show(true) ;
2377 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2384 if ( range
== 0 || thumbVisible
>= range
)
2386 if ( m_vScrollBar
->IsShown() )
2387 m_vScrollBar
->Show(false) ;
2391 if ( !m_vScrollBar
->IsShown() )
2392 m_vScrollBar
->Show(true) ;
2394 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2397 MacRepositionScrollBars() ;
2400 // Does a physical scroll
2401 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2403 if( dx
== 0 && dy
==0 )
2406 int width
, height
;
2407 GetClientSize( &width
, &height
) ;
2408 #if TARGET_API_MAC_OSX
2409 if ( 1 /* m_peer->IsCompositing() */ )
2411 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2412 // area is scrolled, this does not occur if width and height are 2 pixels less,
2413 // TODO write optimal workaround
2414 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2417 scrollrect
.Intersect( *rect
) ;
2419 if ( m_peer
->GetNeedsDisplay() )
2421 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2422 // either immediate redraw or full invalidate
2424 // is the better overall solution, as it does not slow down scrolling
2425 m_peer
->SetNeedsDisplay() ;
2427 // this would be the preferred version for fast drawing controls
2429 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2430 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2431 HIViewRender(m_peer
->GetControlRef()) ;
2437 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2438 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2439 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2441 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2442 // either immediate redraw or full invalidate
2444 // is the better overall solution, as it does not slow down scrolling
2445 m_peer
->SetNeedsDisplay() ;
2447 // this would be the preferred version for fast drawing controls
2449 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2450 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2451 HIViewRender(m_peer
->GetControlRef()) ;
2466 RgnHandle updateRgn
= NewRgn() ;
2469 wxClientDC
dc(this) ;
2470 wxMacPortSetter
helper(&dc
) ;
2472 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2473 //scrollrect.top += MacGetTopBorderSize() ;
2474 //scrollrect.left += MacGetLeftBorderSize() ;
2475 scrollrect
.bottom
= scrollrect
.top
+ height
;
2476 scrollrect
.right
= scrollrect
.left
+ width
;
2480 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2481 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2482 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2484 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2486 // now scroll the former update region as well and add the new update region
2488 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2489 RgnHandle formerUpdateRgn
= NewRgn() ;
2490 RgnHandle scrollRgn
= NewRgn() ;
2491 RectRgn( scrollRgn
, &scrollrect
) ;
2492 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2494 LocalToGlobal( &pt
) ;
2495 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2496 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2497 if ( !EmptyRgn( formerUpdateRgn
) )
2499 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2500 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2501 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2503 InvalWindowRgn(rootWindow
, updateRgn
) ;
2504 DisposeRgn( updateRgn
) ;
2505 DisposeRgn( formerUpdateRgn
) ;
2506 DisposeRgn( scrollRgn
) ;
2511 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2513 wxWindowMac
*child
= node
->GetData();
2514 if (child
== m_vScrollBar
) continue;
2515 if (child
== m_hScrollBar
) continue;
2516 if (child
->IsTopLevel()) continue;
2519 child
->GetPosition( &x
, &y
);
2521 child
->GetSize( &w
, &h
);
2525 if (rect
->Intersects(rc
))
2526 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2530 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2535 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2537 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2539 wxScrollWinEvent wevent
;
2540 wevent
.SetPosition(event
.GetPosition());
2541 wevent
.SetOrientation(event
.GetOrientation());
2542 wevent
.SetEventObject(this);
2544 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2545 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2546 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2547 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2548 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2549 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2550 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2551 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2552 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2553 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2554 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2555 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2556 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2557 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2558 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2559 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2561 GetEventHandler()->ProcessEvent(wevent
);
2565 // Get the window with the focus
2566 wxWindowMac
*wxWindowBase::DoFindFocus()
2568 ControlRef control
;
2569 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2570 return wxFindControlFromMacControl( control
) ;
2573 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2575 // panel wants to track the window which was the last to have focus in it,
2576 // so we want to set ourselves as the window which last had focus
2578 // notice that it's also important to do it upwards the tree becaus
2579 // otherwise when the top level panel gets focus, it won't set it back to
2580 // us, but to some other sibling
2582 // CS:don't know if this is still needed:
2583 //wxChildFocusEvent eventFocus(this);
2584 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2586 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2588 #if !wxMAC_USE_CORE_GRAPHICS
2589 wxMacWindowStateSaver
sv( this ) ;
2591 m_peer
->GetRect( &rect
) ;
2592 // auf den umgebenden Rahmen zur\9fck
2593 InsetRect( &rect
, -1 , -1 ) ;
2595 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2599 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2601 rect
.right
+= pt
.x
;
2603 rect
.bottom
+= pt
.y
;
2606 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2607 DrawThemeFocusRect( &rect
, true ) ;
2610 DrawThemeFocusRect( &rect
, false ) ;
2612 // as this erases part of the frame we have to redraw borders
2613 // and because our z-ordering is not always correct (staticboxes)
2614 // we have to invalidate things, we cannot simple redraw
2615 MacInvalidateBorders() ;
2618 GetParent()->Refresh() ;
2625 void wxWindowMac::OnInternalIdle()
2627 // This calls the UI-update mechanism (querying windows for
2628 // menu/toolbar/control state information)
2629 if (wxUpdateUIEvent::CanUpdate(this))
2630 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2633 // Raise the window to the top of the Z order
2634 void wxWindowMac::Raise()
2636 m_peer
->SetZOrder( true , NULL
) ;
2639 // Lower the window to the bottom of the Z order
2640 void wxWindowMac::Lower()
2642 m_peer
->SetZOrder( false , NULL
) ;
2646 // static wxWindow *gs_lastWhich = NULL;
2648 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2650 // first trigger a set cursor event
2652 wxPoint clientorigin
= GetClientAreaOrigin() ;
2653 wxSize clientsize
= GetClientSize() ;
2655 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2657 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2659 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2660 if ( processedEvtSetCursor
&& event
.HasCursor() )
2662 cursor
= event
.GetCursor() ;
2667 // the test for processedEvtSetCursor is here to prevent using m_cursor
2668 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2669 // it - this is a way to say that our cursor shouldn't be used for this
2671 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2681 cursor
= *wxSTANDARD_CURSOR
;
2685 cursor
.MacInstall() ;
2687 return cursor
.Ok() ;
2690 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2695 return m_tooltip
->GetTip() ;
2698 return wxEmptyString
;
2701 void wxWindowMac::ClearBackground()
2707 void wxWindowMac::Update()
2709 #if TARGET_API_MAC_OSX
2710 MacGetTopLevelWindow()->MacPerformUpdates() ;
2712 ::Draw1Control( m_peer
->GetControlRef() ) ;
2716 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2718 wxTopLevelWindowMac
* win
= NULL
;
2719 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2722 win
= wxFindWinFromMacWindow( window
) ;
2727 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2729 MacUpdateClippedRects() ;
2730 return m_cachedClippedClientRect
;
2733 const wxRect
& wxWindowMac::MacGetClippedRect() const
2735 MacUpdateClippedRects() ;
2736 return m_cachedClippedRect
;
2739 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2741 MacUpdateClippedRects() ;
2742 return m_cachedClippedRectWithOuterStructure
;
2745 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2747 static wxRegion emptyrgn
;
2748 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2750 MacUpdateClippedRects() ;
2751 if ( includeOuterStructures
)
2752 return m_cachedClippedRegionWithOuterStructure
;
2754 return m_cachedClippedRegion
;
2762 void wxWindowMac::MacUpdateClippedRects() const
2764 if ( m_cachedClippedRectValid
)
2767 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2768 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2769 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2770 // to add focus borders everywhere
2773 Rect rIncludingOuterStructures
;
2775 m_peer
->GetRect( &r
) ;
2776 r
.left
-= MacGetLeftBorderSize() ;
2777 r
.top
-= MacGetTopBorderSize() ;
2778 r
.bottom
+= MacGetBottomBorderSize() ;
2779 r
.right
+= MacGetRightBorderSize() ;
2786 rIncludingOuterStructures
= r
;
2787 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2789 wxRect cl
= GetClientRect() ;
2790 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2792 const wxWindow
* child
= this ;
2793 const wxWindow
* parent
= NULL
;
2794 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2799 if ( parent
->MacIsChildOfClientArea(child
) )
2801 size
= parent
->GetClientSize() ;
2802 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2808 // this will be true for scrollbars, toolbars etc.
2809 size
= parent
->GetSize() ;
2810 y
= parent
->MacGetTopBorderSize() ;
2811 x
= parent
->MacGetLeftBorderSize() ;
2812 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2813 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2816 parent
->MacWindowToRootWindow( &x
, &y
) ;
2817 MacRootWindowToWindow( &x
, &y
) ;
2819 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2821 // the wxwindow and client rects will always be clipped
2822 SectRect( &r
, &rparent
, &r
) ;
2823 SectRect( &rClient
, &rparent
, &rClient
) ;
2825 // the structure only at 'hard' borders
2826 if ( parent
->MacClipChildren() ||
2827 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2829 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2834 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2835 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2836 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2837 m_cachedClippedRectWithOuterStructure
= wxRect(
2838 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2839 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2840 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2842 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2843 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2844 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2846 m_cachedClippedRectValid
= true ;
2850 This function must not change the updatergn !
2852 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2854 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2855 bool handled
= false ;
2857 GetRegionBounds( updatergn
, &updatebounds
) ;
2859 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2861 if ( !EmptyRgn(updatergn
) )
2863 RgnHandle newupdate
= NewRgn() ;
2864 wxSize point
= GetClientSize() ;
2865 wxPoint origin
= GetClientAreaOrigin() ;
2866 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2867 SectRgn( newupdate
, updatergn
, newupdate
) ;
2869 // first send an erase event to the entire update area
2871 // for the toplevel window this really is the entire area
2872 // for all the others only their client area, otherwise they
2873 // might be drawing with full alpha and eg put blue into
2874 // the grow-box area of a scrolled window (scroll sample)
2875 wxDC
* dc
= new wxWindowDC(this);
2877 dc
->SetClippingRegion(wxRegion(updatergn
));
2879 dc
->SetClippingRegion(wxRegion(newupdate
));
2881 wxEraseEvent
eevent( GetId(), dc
);
2882 eevent
.SetEventObject( this );
2883 GetEventHandler()->ProcessEvent( eevent
);
2887 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2888 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2889 m_updateRegion
= newupdate
;
2890 DisposeRgn( newupdate
) ;
2892 if ( !m_updateRegion
.Empty() )
2894 // paint the window itself
2897 event
.SetTimestamp(time
);
2898 event
.SetEventObject(this);
2899 GetEventHandler()->ProcessEvent(event
);
2903 // now we cannot rely on having its borders drawn by a window itself, as it does not
2904 // get the updateRgn wide enough to always do so, so we do it from the parent
2905 // this would also be the place to draw any custom backgrounds for native controls
2906 // in Composited windowing
2907 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2909 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2911 wxWindowMac
*child
= node
->GetData();
2912 if (child
== m_vScrollBar
) continue;
2913 if (child
== m_hScrollBar
) continue;
2914 if (child
->IsTopLevel()) continue;
2915 if (!child
->IsShown()) continue;
2917 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2920 child
->GetPosition( &x
, &y
);
2922 child
->GetSize( &w
, &h
);
2923 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2924 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2925 InsetRect( &childRect
, -10 , -10) ;
2927 if ( RectInRgn( &childRect
, updatergn
) )
2930 // paint custom borders
2931 wxNcPaintEvent
eventNc( child
->GetId() );
2932 eventNc
.SetEventObject( child
);
2933 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2935 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2936 if ( UMAGetSystemVersion() >= 0x1030 )
2938 child
->MacPaintBorders(0,0) ;
2943 wxWindowDC
dc(this) ;
2944 dc
.SetClippingRegion(wxRegion(updatergn
));
2945 wxMacPortSetter
helper(&dc
) ;
2946 child
->MacPaintBorders(0,0) ;
2956 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2958 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2962 if ( iter
->IsTopLevel() )
2963 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2965 iter
= iter
->GetParent() ;
2967 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2971 void wxWindowMac::MacCreateScrollBars( long style
)
2973 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2975 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2977 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2978 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2979 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2980 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2982 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2983 variant
= wxWINDOW_VARIANT_SMALL
;
2986 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2988 GetClientSize( &width
, &height
) ;
2990 wxPoint
vPoint(width
-scrlsize
, 0) ;
2991 wxSize
vSize(scrlsize
, height
- adjust
) ;
2992 wxPoint
hPoint(0 , height
-scrlsize
) ;
2993 wxSize
hSize( width
- adjust
, scrlsize
) ;
2996 if ( style
& wxVSCROLL
)
2998 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2999 vSize
, wxVERTICAL
);
3002 if ( style
& wxHSCROLL
)
3004 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3005 hSize
, wxHORIZONTAL
);
3010 // because the create does not take into account the client area origin
3011 MacRepositionScrollBars() ; // we might have a real position shift
3014 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3016 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3022 void wxWindowMac::MacRepositionScrollBars()
3024 if ( !m_hScrollBar
&& !m_vScrollBar
)
3027 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3028 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3029 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3031 // get real client area
3035 GetSize( &width
, &height
) ;
3037 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3038 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3040 wxPoint
vPoint(width
-scrlsize
, 0) ;
3041 wxSize
vSize(scrlsize
, height
- adjust
) ;
3042 wxPoint
hPoint(0 , height
-scrlsize
) ;
3043 wxSize
hSize( width
- adjust
, scrlsize
) ;
3049 GetSize( &w , &h ) ;
3051 MacClientToRootWindow( &x , &y ) ;
3052 MacClientToRootWindow( &w , &h ) ;
3054 wxWindowMac *iter = (wxWindowMac*)this ;
3056 int totW = 10000 , totH = 10000;
3059 if ( iter->IsTopLevel() )
3061 iter->GetSize( &totW , &totH ) ;
3065 iter = iter->GetParent() ;
3093 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3097 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3101 bool wxWindowMac::AcceptsFocus() const
3103 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3106 void wxWindowMac::MacSuperChangedPosition()
3108 m_cachedClippedRectValid
= false ;
3109 // only window-absolute structures have to be moved i.e. controls
3111 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3114 wxWindowMac
*child
= node
->GetData();
3115 child
->MacSuperChangedPosition() ;
3116 node
= node
->GetNext();
3120 void wxWindowMac::MacTopLevelWindowChangedPosition()
3122 // only screen-absolute structures have to be moved i.e. glcanvas
3124 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3127 wxWindowMac
*child
= node
->GetData();
3128 child
->MacTopLevelWindowChangedPosition() ;
3129 node
= node
->GetNext();
3133 long wxWindowMac::MacGetLeftBorderSize( ) const
3140 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3142 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3143 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3145 else if (HasFlag(wxSIMPLE_BORDER
))
3147 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3148 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3153 long wxWindowMac::MacGetRightBorderSize( ) const
3155 // they are all symmetric in mac themes
3156 return MacGetLeftBorderSize() ;
3159 long wxWindowMac::MacGetTopBorderSize( ) const
3161 // they are all symmetric in mac themes
3162 return MacGetLeftBorderSize() ;
3165 long wxWindowMac::MacGetBottomBorderSize( ) const
3167 // they are all symmetric in mac themes
3168 return MacGetLeftBorderSize() ;
3171 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3173 return style
& ~wxBORDER_MASK
;
3176 // Find the wxWindowMac at the current mouse position, returning the mouse
3178 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3180 pt
= wxGetMousePosition();
3181 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3185 // Get the current mouse position.
3186 wxPoint
wxGetMousePosition()
3189 wxGetMousePosition(& x
, & y
);
3190 return wxPoint(x
, y
);
3193 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3195 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3197 // copied from wxGTK : CS
3198 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3201 // (a) it's a command event and so is propagated to the parent
3202 // (b) under MSW it can be generated from kbd too
3203 // (c) it uses screen coords (because of (a))
3204 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3206 this->ClientToScreen(event
.GetPosition()));
3207 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3216 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3218 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3220 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3224 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3228 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3232 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3233 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3237 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3239 return eventNotHandledErr
;