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
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1836 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1839 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1841 wxSize size
= wxDefaultSize
;
1842 if ( width
== wxDefaultCoord
)
1844 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1846 size
= DoGetBestSize();
1851 // just take the current one
1856 if ( height
== wxDefaultCoord
)
1858 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1860 if ( size
.x
== wxDefaultCoord
)
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
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1899 int currentclientwidth
, currentclientheight
;
1900 int currentwidth
, currentheight
;
1902 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1903 GetSize( ¤twidth
, ¤theight
) ;
1905 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, 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 ( MacGetTopLevelWindow() == NULL
)
2174 #if TARGET_API_MAC_OSX
2175 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2182 event
.GetDC()->Clear() ;
2186 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2191 int wxWindowMac::GetScrollPos(int orient
) const
2193 if ( orient
== wxHORIZONTAL
)
2196 return m_hScrollBar
->GetThumbPosition() ;
2201 return m_vScrollBar
->GetThumbPosition() ;
2206 // This now returns the whole range, not just the number
2207 // of positions that we can scroll.
2208 int wxWindowMac::GetScrollRange(int orient
) const
2210 if ( orient
== wxHORIZONTAL
)
2213 return m_hScrollBar
->GetRange() ;
2218 return m_vScrollBar
->GetRange() ;
2223 int wxWindowMac::GetScrollThumb(int orient
) const
2225 if ( orient
== wxHORIZONTAL
)
2228 return m_hScrollBar
->GetThumbSize() ;
2233 return m_vScrollBar
->GetThumbSize() ;
2238 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2240 if ( orient
== wxHORIZONTAL
)
2243 m_hScrollBar
->SetThumbPosition( pos
) ;
2248 m_vScrollBar
->SetThumbPosition( pos
) ;
2253 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2254 // our own window origin is at leftOrigin/rightOrigin
2257 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2263 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2264 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2266 m_peer
->GetRect( &rect
) ;
2267 // back to the surrounding frame rectangle
2268 InsetRect( &rect
, -1 , -1 ) ;
2270 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2271 if ( UMAGetSystemVersion() >= 0x1030 )
2273 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2274 rect
.bottom
- rect
.top
) ;
2276 HIThemeFrameDrawInfo info
;
2277 memset( &info
, 0 , sizeof( info
) ) ;
2281 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2282 info
.isFocused
= hasFocus
;
2284 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2285 wxASSERT( cgContext
) ;
2287 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2289 info
.kind
= kHIThemeFrameTextFieldSquare
;
2290 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2292 else if (HasFlag(wxSIMPLE_BORDER
))
2294 info
.kind
= kHIThemeFrameListBox
;
2295 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2297 else if ( hasFocus
)
2299 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2302 m_peer
->GetRect( &rect
) ;
2303 if ( hasBothScrollbars
)
2305 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2306 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2307 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2308 HIThemeGrowBoxDrawInfo info
;
2309 memset( &info
, 0 , sizeof( info
) ) ;
2311 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2312 info
.kind
= kHIThemeGrowBoxKindNone
;
2313 info
.size
= kHIThemeGrowBoxSizeNormal
;
2314 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2315 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2321 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2325 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2326 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2329 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2331 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2333 else if (HasFlag(wxSIMPLE_BORDER
))
2335 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2340 DrawThemeFocusRect( &rect
, true ) ;
2343 if ( hasBothScrollbars
)
2345 // GetThemeStandaloneGrowBoxBounds
2346 //DrawThemeStandaloneNoGrowBox
2351 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2353 if ( child
== m_hScrollBar
)
2354 m_hScrollBar
= NULL
;
2355 if ( child
== m_vScrollBar
)
2356 m_vScrollBar
= NULL
;
2358 wxWindowBase::RemoveChild( child
) ;
2361 // New function that will replace some of the above.
2362 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2363 int range
, bool refresh
)
2365 if ( orient
== wxHORIZONTAL
)
2369 if ( range
== 0 || thumbVisible
>= range
)
2371 if ( m_hScrollBar
->IsShown() )
2372 m_hScrollBar
->Show(false) ;
2376 if ( !m_hScrollBar
->IsShown() )
2377 m_hScrollBar
->Show(true) ;
2379 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2386 if ( range
== 0 || thumbVisible
>= range
)
2388 if ( m_vScrollBar
->IsShown() )
2389 m_vScrollBar
->Show(false) ;
2393 if ( !m_vScrollBar
->IsShown() )
2394 m_vScrollBar
->Show(true) ;
2396 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2399 MacRepositionScrollBars() ;
2402 // Does a physical scroll
2403 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2405 if( dx
== 0 && dy
==0 )
2408 int width
, height
;
2409 GetClientSize( &width
, &height
) ;
2410 #if TARGET_API_MAC_OSX
2411 if ( 1 /* m_peer->IsCompositing() */ )
2413 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2414 // area is scrolled, this does not occur if width and height are 2 pixels less,
2415 // TODO write optimal workaround
2416 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2419 scrollrect
.Intersect( *rect
) ;
2421 if ( m_peer
->GetNeedsDisplay() )
2423 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2424 // either immediate redraw or full invalidate
2426 // is the better overall solution, as it does not slow down scrolling
2427 m_peer
->SetNeedsDisplay() ;
2429 // this would be the preferred version for fast drawing controls
2431 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2432 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2433 HIViewRender(m_peer
->GetControlRef()) ;
2439 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2440 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2441 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2443 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2444 // either immediate redraw or full invalidate
2446 // is the better overall solution, as it does not slow down scrolling
2447 m_peer
->SetNeedsDisplay() ;
2449 // this would be the preferred version for fast drawing controls
2451 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2452 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2453 HIViewRender(m_peer
->GetControlRef()) ;
2468 RgnHandle updateRgn
= NewRgn() ;
2471 wxClientDC
dc(this) ;
2472 wxMacPortSetter
helper(&dc
) ;
2474 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2475 //scrollrect.top += MacGetTopBorderSize() ;
2476 //scrollrect.left += MacGetLeftBorderSize() ;
2477 scrollrect
.bottom
= scrollrect
.top
+ height
;
2478 scrollrect
.right
= scrollrect
.left
+ width
;
2482 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2483 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2484 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2486 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2488 // now scroll the former update region as well and add the new update region
2490 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2491 RgnHandle formerUpdateRgn
= NewRgn() ;
2492 RgnHandle scrollRgn
= NewRgn() ;
2493 RectRgn( scrollRgn
, &scrollrect
) ;
2494 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2496 LocalToGlobal( &pt
) ;
2497 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2498 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2499 if ( !EmptyRgn( formerUpdateRgn
) )
2501 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2502 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2503 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2505 InvalWindowRgn(rootWindow
, updateRgn
) ;
2506 DisposeRgn( updateRgn
) ;
2507 DisposeRgn( formerUpdateRgn
) ;
2508 DisposeRgn( scrollRgn
) ;
2513 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2515 wxWindowMac
*child
= node
->GetData();
2516 if (child
== m_vScrollBar
) continue;
2517 if (child
== m_hScrollBar
) continue;
2518 if (child
->IsTopLevel()) continue;
2521 child
->GetPosition( &x
, &y
);
2523 child
->GetSize( &w
, &h
);
2527 if (rect
->Intersects(rc
))
2528 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2532 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2537 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2539 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2541 wxScrollWinEvent wevent
;
2542 wevent
.SetPosition(event
.GetPosition());
2543 wevent
.SetOrientation(event
.GetOrientation());
2544 wevent
.SetEventObject(this);
2546 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2547 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2548 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2549 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2550 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2551 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2552 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2553 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2554 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2555 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2556 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2557 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2558 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2559 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2560 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2561 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2563 GetEventHandler()->ProcessEvent(wevent
);
2567 // Get the window with the focus
2568 wxWindowMac
*wxWindowBase::DoFindFocus()
2570 ControlRef control
;
2571 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2572 return wxFindControlFromMacControl( control
) ;
2575 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2577 // panel wants to track the window which was the last to have focus in it,
2578 // so we want to set ourselves as the window which last had focus
2580 // notice that it's also important to do it upwards the tree becaus
2581 // otherwise when the top level panel gets focus, it won't set it back to
2582 // us, but to some other sibling
2584 // CS:don't know if this is still needed:
2585 //wxChildFocusEvent eventFocus(this);
2586 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2588 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2590 #if !wxMAC_USE_CORE_GRAPHICS
2591 wxMacWindowStateSaver
sv( this ) ;
2593 m_peer
->GetRect( &rect
) ;
2594 // auf den umgebenden Rahmen zur\9fck
2595 InsetRect( &rect
, -1 , -1 ) ;
2597 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2601 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2603 rect
.right
+= pt
.x
;
2605 rect
.bottom
+= pt
.y
;
2608 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2609 DrawThemeFocusRect( &rect
, true ) ;
2612 DrawThemeFocusRect( &rect
, false ) ;
2614 // as this erases part of the frame we have to redraw borders
2615 // and because our z-ordering is not always correct (staticboxes)
2616 // we have to invalidate things, we cannot simple redraw
2617 MacInvalidateBorders() ;
2620 GetParent()->Refresh() ;
2627 void wxWindowMac::OnInternalIdle()
2629 // This calls the UI-update mechanism (querying windows for
2630 // menu/toolbar/control state information)
2631 if (wxUpdateUIEvent::CanUpdate(this))
2632 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2635 // Raise the window to the top of the Z order
2636 void wxWindowMac::Raise()
2638 m_peer
->SetZOrder( true , NULL
) ;
2641 // Lower the window to the bottom of the Z order
2642 void wxWindowMac::Lower()
2644 m_peer
->SetZOrder( false , NULL
) ;
2648 // static wxWindow *gs_lastWhich = NULL;
2650 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2652 // first trigger a set cursor event
2654 wxPoint clientorigin
= GetClientAreaOrigin() ;
2655 wxSize clientsize
= GetClientSize() ;
2657 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2659 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2661 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2662 if ( processedEvtSetCursor
&& event
.HasCursor() )
2664 cursor
= event
.GetCursor() ;
2669 // the test for processedEvtSetCursor is here to prevent using m_cursor
2670 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2671 // it - this is a way to say that our cursor shouldn't be used for this
2673 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2683 cursor
= *wxSTANDARD_CURSOR
;
2687 cursor
.MacInstall() ;
2689 return cursor
.Ok() ;
2692 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2697 return m_tooltip
->GetTip() ;
2700 return wxEmptyString
;
2703 void wxWindowMac::ClearBackground()
2709 void wxWindowMac::Update()
2711 #if TARGET_API_MAC_OSX
2712 MacGetTopLevelWindow()->MacPerformUpdates() ;
2714 ::Draw1Control( m_peer
->GetControlRef() ) ;
2718 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2720 wxTopLevelWindowMac
* win
= NULL
;
2721 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2724 win
= wxFindWinFromMacWindow( window
) ;
2729 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2731 MacUpdateClippedRects() ;
2732 return m_cachedClippedClientRect
;
2735 const wxRect
& wxWindowMac::MacGetClippedRect() const
2737 MacUpdateClippedRects() ;
2738 return m_cachedClippedRect
;
2741 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2743 MacUpdateClippedRects() ;
2744 return m_cachedClippedRectWithOuterStructure
;
2747 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2749 static wxRegion emptyrgn
;
2750 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2752 MacUpdateClippedRects() ;
2753 if ( includeOuterStructures
)
2754 return m_cachedClippedRegionWithOuterStructure
;
2756 return m_cachedClippedRegion
;
2764 void wxWindowMac::MacUpdateClippedRects() const
2766 if ( m_cachedClippedRectValid
)
2769 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2770 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2771 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2772 // to add focus borders everywhere
2775 Rect rIncludingOuterStructures
;
2777 m_peer
->GetRect( &r
) ;
2778 r
.left
-= MacGetLeftBorderSize() ;
2779 r
.top
-= MacGetTopBorderSize() ;
2780 r
.bottom
+= MacGetBottomBorderSize() ;
2781 r
.right
+= MacGetRightBorderSize() ;
2788 rIncludingOuterStructures
= r
;
2789 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2791 wxRect cl
= GetClientRect() ;
2792 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2794 const wxWindow
* child
= this ;
2795 const wxWindow
* parent
= NULL
;
2796 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2801 if ( parent
->MacIsChildOfClientArea(child
) )
2803 size
= parent
->GetClientSize() ;
2804 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2810 // this will be true for scrollbars, toolbars etc.
2811 size
= parent
->GetSize() ;
2812 y
= parent
->MacGetTopBorderSize() ;
2813 x
= parent
->MacGetLeftBorderSize() ;
2814 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2815 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2818 parent
->MacWindowToRootWindow( &x
, &y
) ;
2819 MacRootWindowToWindow( &x
, &y
) ;
2821 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2823 // the wxwindow and client rects will always be clipped
2824 SectRect( &r
, &rparent
, &r
) ;
2825 SectRect( &rClient
, &rparent
, &rClient
) ;
2827 // the structure only at 'hard' borders
2828 if ( parent
->MacClipChildren() ||
2829 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2831 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2836 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2837 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2838 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2839 m_cachedClippedRectWithOuterStructure
= wxRect(
2840 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2841 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2842 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2844 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2845 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2846 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2848 m_cachedClippedRectValid
= true ;
2852 This function must not change the updatergn !
2854 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2856 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2857 bool handled
= false ;
2859 GetRegionBounds( updatergn
, &updatebounds
) ;
2861 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2863 if ( !EmptyRgn(updatergn
) )
2865 RgnHandle newupdate
= NewRgn() ;
2866 wxSize point
= GetClientSize() ;
2867 wxPoint origin
= GetClientAreaOrigin() ;
2868 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2869 SectRgn( newupdate
, updatergn
, newupdate
) ;
2871 // first send an erase event to the entire update area
2873 // for the toplevel window this really is the entire area
2874 // for all the others only their client area, otherwise they
2875 // might be drawing with full alpha and eg put blue into
2876 // the grow-box area of a scrolled window (scroll sample)
2877 wxDC
* dc
= new wxWindowDC(this);
2879 dc
->SetClippingRegion(wxRegion(updatergn
));
2881 dc
->SetClippingRegion(wxRegion(newupdate
));
2883 wxEraseEvent
eevent( GetId(), dc
);
2884 eevent
.SetEventObject( this );
2885 GetEventHandler()->ProcessEvent( eevent
);
2889 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2890 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2891 m_updateRegion
= newupdate
;
2892 DisposeRgn( newupdate
) ;
2894 if ( !m_updateRegion
.Empty() )
2896 // paint the window itself
2899 event
.SetTimestamp(time
);
2900 event
.SetEventObject(this);
2901 GetEventHandler()->ProcessEvent(event
);
2905 // now we cannot rely on having its borders drawn by a window itself, as it does not
2906 // get the updateRgn wide enough to always do so, so we do it from the parent
2907 // this would also be the place to draw any custom backgrounds for native controls
2908 // in Composited windowing
2909 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2911 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2913 wxWindowMac
*child
= node
->GetData();
2914 if (child
== m_vScrollBar
) continue;
2915 if (child
== m_hScrollBar
) continue;
2916 if (child
->IsTopLevel()) continue;
2917 if (!child
->IsShown()) continue;
2919 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2922 child
->GetPosition( &x
, &y
);
2924 child
->GetSize( &w
, &h
);
2925 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2926 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2927 InsetRect( &childRect
, -10 , -10) ;
2929 if ( RectInRgn( &childRect
, updatergn
) )
2932 // paint custom borders
2933 wxNcPaintEvent
eventNc( child
->GetId() );
2934 eventNc
.SetEventObject( child
);
2935 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2937 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2938 if ( UMAGetSystemVersion() >= 0x1030 )
2940 child
->MacPaintBorders(0,0) ;
2945 wxWindowDC
dc(this) ;
2946 dc
.SetClippingRegion(wxRegion(updatergn
));
2947 wxMacPortSetter
helper(&dc
) ;
2948 child
->MacPaintBorders(0,0) ;
2958 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2960 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2964 if ( iter
->IsTopLevel() )
2965 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2967 iter
= iter
->GetParent() ;
2969 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2973 void wxWindowMac::MacCreateScrollBars( long style
)
2975 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2977 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2979 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2980 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2981 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2982 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2984 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2985 variant
= wxWINDOW_VARIANT_SMALL
;
2988 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2990 GetClientSize( &width
, &height
) ;
2992 wxPoint
vPoint(width
-scrlsize
, 0) ;
2993 wxSize
vSize(scrlsize
, height
- adjust
) ;
2994 wxPoint
hPoint(0 , height
-scrlsize
) ;
2995 wxSize
hSize( width
- adjust
, scrlsize
) ;
2998 if ( style
& wxVSCROLL
)
3000 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3001 vSize
, wxVERTICAL
);
3004 if ( style
& wxHSCROLL
)
3006 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3007 hSize
, wxHORIZONTAL
);
3012 // because the create does not take into account the client area origin
3013 MacRepositionScrollBars() ; // we might have a real position shift
3016 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3018 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3024 void wxWindowMac::MacRepositionScrollBars()
3026 if ( !m_hScrollBar
&& !m_vScrollBar
)
3029 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3030 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3031 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3033 // get real client area
3037 GetSize( &width
, &height
) ;
3039 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3040 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3042 wxPoint
vPoint(width
-scrlsize
, 0) ;
3043 wxSize
vSize(scrlsize
, height
- adjust
) ;
3044 wxPoint
hPoint(0 , height
-scrlsize
) ;
3045 wxSize
hSize( width
- adjust
, scrlsize
) ;
3051 GetSize( &w , &h ) ;
3053 MacClientToRootWindow( &x , &y ) ;
3054 MacClientToRootWindow( &w , &h ) ;
3056 wxWindowMac *iter = (wxWindowMac*)this ;
3058 int totW = 10000 , totH = 10000;
3061 if ( iter->IsTopLevel() )
3063 iter->GetSize( &totW , &totH ) ;
3067 iter = iter->GetParent() ;
3095 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3099 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3103 bool wxWindowMac::AcceptsFocus() const
3105 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3108 void wxWindowMac::MacSuperChangedPosition()
3110 m_cachedClippedRectValid
= false ;
3111 // only window-absolute structures have to be moved i.e. controls
3113 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3116 wxWindowMac
*child
= node
->GetData();
3117 child
->MacSuperChangedPosition() ;
3118 node
= node
->GetNext();
3122 void wxWindowMac::MacTopLevelWindowChangedPosition()
3124 // only screen-absolute structures have to be moved i.e. glcanvas
3126 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3129 wxWindowMac
*child
= node
->GetData();
3130 child
->MacTopLevelWindowChangedPosition() ;
3131 node
= node
->GetNext();
3135 long wxWindowMac::MacGetLeftBorderSize( ) const
3142 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3144 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3145 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3147 else if (HasFlag(wxSIMPLE_BORDER
))
3149 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3150 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3155 long wxWindowMac::MacGetRightBorderSize( ) const
3157 // they are all symmetric in mac themes
3158 return MacGetLeftBorderSize() ;
3161 long wxWindowMac::MacGetTopBorderSize( ) const
3163 // they are all symmetric in mac themes
3164 return MacGetLeftBorderSize() ;
3167 long wxWindowMac::MacGetBottomBorderSize( ) const
3169 // they are all symmetric in mac themes
3170 return MacGetLeftBorderSize() ;
3173 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3175 return style
& ~wxBORDER_MASK
;
3178 // Find the wxWindowMac at the current mouse position, returning the mouse
3180 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3182 pt
= wxGetMousePosition();
3183 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3187 // Get the current mouse position.
3188 wxPoint
wxGetMousePosition()
3191 wxGetMousePosition(& x
, & y
);
3192 return wxPoint(x
, y
);
3195 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3197 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3199 // copied from wxGTK : CS
3200 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3203 // (a) it's a command event and so is propagated to the parent
3204 // (b) under MSW it can be generated from kbd too
3205 // (c) it uses screen coords (because of (a))
3206 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3208 this->ClientToScreen(event
.GetPosition()));
3209 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3218 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3220 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3222 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3226 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3230 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3234 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3235 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3239 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3241 return eventNotHandledErr
;
3244 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3246 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3248 if ( !wxWindowBase::Reparent(newParent
) )
3251 //copied from MacPostControlCreate
3252 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3253 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3254 ::EmbedControl( m_peer
->GetControlRef() , container
) ;