1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/window.h"
17 #include "wx/dcclient.h"
21 #include "wx/layout.h"
22 #include "wx/dialog.h"
23 #include "wx/scrolbar.h"
24 #include "wx/statbox.h"
25 #include "wx/button.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
29 #include "wx/tooltip.h"
30 #include "wx/statusbr.h"
31 #include "wx/menuitem.h"
32 #include "wx/spinctrl.h"
34 #include "wx/geometry.h"
35 #include "wx/textctrl.h"
37 #include "wx/toolbar.h"
44 #define MAC_SCROLLBAR_SIZE 15
45 #define MAC_SMALL_SCROLLBAR_SIZE 11
47 #include "wx/mac/uma.h"
50 #include <ToolUtils.h>
52 #include <MacTextEditor.h>
55 #if TARGET_API_MAC_OSX
57 #include <HIToolbox/HIView.h>
61 #if wxUSE_DRAG_AND_DROP
67 extern wxList wxPendingDelete
;
69 #ifdef __WXUNIVERSAL__
70 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
72 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
73 #endif // __WXUNIVERSAL__/__WXMAC__
75 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
76 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
77 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
78 #if TARGET_API_MAC_OSX
79 EVT_PAINT(wxWindowMac::OnPaint
)
81 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
82 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
86 #define wxMAC_DEBUG_REDRAW 0
87 #ifndef wxMAC_DEBUG_REDRAW
88 #define wxMAC_DEBUG_REDRAW 0
91 #define wxMAC_USE_THEME_BORDER 1
93 // ---------------------------------------------------------------------------
94 // Utility Routines to move between different coordinate systems
95 // ---------------------------------------------------------------------------
98 * Right now we have the following setup :
99 * a border that is not part of the native control is always outside the
100 * control's border (otherwise we loose all native intelligence, future ways
101 * may be to have a second embedding control responsible for drawing borders
102 * and backgrounds eventually)
103 * so all this border calculations have to be taken into account when calling
104 * native methods or getting native oriented data
105 * so we have three coordinate systems here
106 * wx client coordinates
107 * wx window coordinates (including window frames)
112 // originating from native control
116 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
118 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
121 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
123 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
127 // directed towards native control
130 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
132 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
135 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
137 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
140 // ---------------------------------------------------------------------------
142 // ---------------------------------------------------------------------------
144 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
145 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
147 #if TARGET_API_MAC_OSX
149 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
151 kEventControlVisibilityChanged
= 157
157 static const EventTypeSpec eventList
[] =
159 { kEventClassControl
, kEventControlHit
} ,
160 #if TARGET_API_MAC_OSX
161 { kEventClassControl
, kEventControlDraw
} ,
162 { kEventClassControl
, kEventControlVisibilityChanged
} ,
163 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
164 { kEventClassControl
, kEventControlHiliteChanged
} ,
165 { kEventClassControl
, kEventControlSetFocusPart
} ,
167 { kEventClassService
, kEventServiceGetTypes
},
168 { kEventClassService
, kEventServiceCopy
},
169 { kEventClassService
, kEventServicePaste
},
171 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
172 // { kEventClassControl , kEventControlBoundsChanged } ,
176 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
178 OSStatus result
= eventNotHandledErr
;
180 wxMacCarbonEvent
cEvent( event
) ;
182 ControlRef controlRef
;
183 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
185 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
187 switch( GetEventKind( event
) )
189 #if TARGET_API_MAC_OSX
190 case kEventControlDraw
:
192 RgnHandle updateRgn
= NULL
;
193 RgnHandle allocatedRgn
= NULL
;
194 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
196 if ( thisWindow
->GetPeer()->IsCompositing() == false )
198 if ( thisWindow
->GetPeer()->IsRootControl() == false )
199 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
201 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->GetPeer()->IsCompositing() == false )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
215 // hide the given region by the new region that must be shifted
216 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
217 updateRgn
= allocatedRgn
;
221 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
223 // as this update region is in native window locals we must adapt it to wx window local
224 allocatedRgn
= NewRgn() ;
225 CopyRgn( updateRgn
, allocatedRgn
) ;
226 // hide the given region by the new region that must be shifted
227 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
228 updateRgn
= allocatedRgn
;
234 GetRegionBounds( updateRgn
, &rgnBounds
) ;
235 #if wxMAC_DEBUG_REDRAW
236 if ( thisWindow
->MacIsUserPane() )
238 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
239 static float color
= 0.5 ;
242 HIViewGetBounds( controlRef
, &bounds
);
243 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
244 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
245 CGContextFillRect( cgContext
, bounds
);
257 #if wxMAC_USE_CORE_GRAPHICS
258 bool created
= false ;
259 CGContextRef cgContext
= 0 ;
260 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
262 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
264 // this parameter is not provided on non-composited windows
266 // rest of the code expects this to be already transformed and clipped for local
267 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
269 GetPortBounds( port
, &bounds
) ;
270 CreateCGContextForPort( port
, &cgContext
) ;
272 wxMacWindowToNative( thisWindow
, updateRgn
) ;
273 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
274 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
275 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
276 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
278 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
279 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
281 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
284 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
285 CGContextFillRect(cgContext
, CGRectMake( 0 , 0 ,
286 controlBounds
.right
- controlBounds
.left
,
287 controlBounds
.bottom
- controlBounds
.top
) );
291 thisWindow
->MacSetCGContextRef( cgContext
) ;
293 wxMacCGContextStateSaver
sg( cgContext
) ;
295 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
297 #if wxMAC_USE_CORE_GRAPHICS
298 thisWindow
->MacSetCGContextRef( NULL
) ;
301 CGContextRelease( cgContext
) ;
306 DisposeRgn( allocatedRgn
) ;
310 case kEventControlVisibilityChanged
:
311 thisWindow
->MacVisibilityChanged() ;
314 case kEventControlEnabledStateChanged
:
315 thisWindow
->MacEnabledStateChanged() ;
318 case kEventControlHiliteChanged
:
319 thisWindow
->MacHiliteChanged() ;
323 // we emulate this event under Carbon CFM
324 case kEventControlSetFocusPart
:
326 Boolean focusEverything
= false ;
327 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
329 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
334 if ( controlPart
== kControlFocusNoPart
)
337 if ( thisWindow
->GetCaret() )
338 thisWindow
->GetCaret()->OnKillFocus();
341 static bool inKillFocusEvent
= false ;
342 if ( !inKillFocusEvent
)
344 inKillFocusEvent
= true ;
345 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
346 event
.SetEventObject(thisWindow
);
347 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
348 inKillFocusEvent
= false ;
353 // panel wants to track the window which was the last to have focus in it
354 wxChildFocusEvent
eventFocus(thisWindow
);
355 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
358 if ( thisWindow
->GetCaret() )
359 thisWindow
->GetCaret()->OnSetFocus();
362 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
363 event
.SetEventObject(thisWindow
);
364 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
367 if ( thisWindow
->MacIsUserPane() )
372 case kEventControlHit
:
373 result
= thisWindow
->MacControlHit( handler
, event
) ;
383 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
385 OSStatus result
= eventNotHandledErr
;
387 wxMacCarbonEvent
cEvent( event
) ;
389 ControlRef controlRef
;
390 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
391 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
392 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
394 switch ( GetEventKind( event
) )
396 case kEventServiceGetTypes
:
400 textCtrl
->GetSelection( &from
, &to
) ;
402 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
404 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
405 if ( textCtrl
->IsEditable() )
406 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
408 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
409 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
411 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
415 CFArrayAppendValue (copyTypes
, typestring
) ;
417 CFArrayAppendValue (pasteTypes
, typestring
) ;
419 CFRelease( typestring
) ;
427 case kEventServiceCopy
:
432 textCtrl
->GetSelection( &from
, &to
) ;
433 wxString val
= textCtrl
->GetValue() ;
434 val
= val
.Mid( from
, to
- from
) ;
435 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
436 verify_noerr( ClearScrap( &scrapRef
) ) ;
437 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
442 case kEventServicePaste
:
445 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
446 Size textSize
, pastedSize
;
447 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
449 char *content
= new char[textSize
] ;
450 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
451 content
[textSize
-1] = 0 ;
454 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
456 textCtrl
->WriteText( wxString( content
) ) ;
471 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
473 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
474 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
475 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
476 OSStatus result
= eventNotHandledErr
;
478 switch ( GetEventClass( event
) )
480 case kEventClassControl
:
481 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
484 case kEventClassService
:
485 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
492 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
497 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
499 #if !TARGET_API_MAC_OSX
501 // ---------------------------------------------------------------------------
502 // UserPane events for non OSX builds
503 // ---------------------------------------------------------------------------
505 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
507 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
509 win
->MacControlUserPaneDrawProc(part
) ;
511 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
513 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
515 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
517 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
519 return kControlNoPart
;
521 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
523 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
525 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
527 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
529 return kControlNoPart
;
531 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
533 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
535 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
537 win
->MacControlUserPaneIdleProc() ;
539 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
541 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
543 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
545 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
547 return kControlNoPart
;
549 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
551 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
553 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
555 win
->MacControlUserPaneActivateProc(activating
) ;
557 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
559 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
561 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
563 return win
->MacControlUserPaneFocusProc(action
) ;
565 return kControlNoPart
;
567 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
569 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
571 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
573 win
->MacControlUserPaneBackgroundProc(info
) ;
575 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
577 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
580 RgnHandle rgn
= NewRgn() ;
582 MacWindowToRootWindow( &x
,&y
) ;
583 OffsetRgn( rgn
, -x
, -y
) ;
584 wxMacWindowStateSaver
sv( this ) ;
585 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
586 MacDoRedraw( rgn
, 0 ) ;
590 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
592 return kControlNoPart
;
595 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
597 return kControlNoPart
;
600 void wxWindowMac::MacControlUserPaneIdleProc()
604 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
606 return kControlNoPart
;
609 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
613 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
615 if ( AcceptsFocus() )
618 return kControlNoPart
;
621 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
627 // ---------------------------------------------------------------------------
628 // Scrollbar Tracking for all
629 // ---------------------------------------------------------------------------
631 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
632 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
636 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
638 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
641 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
643 // ===========================================================================
645 // ===========================================================================
647 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
649 static MacControlMap wxWinMacControlList
;
651 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
653 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
655 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
658 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
660 // adding NULL ControlRef is (first) surely a result of an error and
661 // (secondly) breaks native event processing
662 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
664 wxWinMacControlList
[inControl
] = control
;
667 void wxRemoveMacControlAssociation(wxWindow
*control
)
669 // iterate over all the elements in the class
670 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
671 // we should go on...
677 MacControlMap::iterator it
;
678 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
680 if ( it
->second
== control
)
682 wxWinMacControlList
.erase(it
);
690 // ----------------------------------------------------------------------------
691 // constructors and such
692 // ----------------------------------------------------------------------------
694 wxWindowMac::wxWindowMac()
699 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
704 const wxString
& name
)
707 Create(parent
, id
, pos
, size
, style
, name
);
710 void wxWindowMac::Init()
714 #if WXWIN_COMPATIBILITY_2_4
715 m_backgroundTransparent
= false;
718 #if wxMAC_USE_CORE_GRAPHICS
719 m_cgContextRef
= NULL
;
722 // as all windows are created with WS_VISIBLE style...
725 m_hScrollBar
= NULL
;
726 m_vScrollBar
= NULL
;
727 m_macBackgroundBrush
= wxNullBrush
;
729 m_macIsUserPane
= true;
730 m_clipChildren
= false ;
731 m_cachedClippedRectValid
= false ;
733 // we need a valid font for the encodings
734 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
738 wxWindowMac::~wxWindowMac()
742 m_isBeingDeleted
= true;
744 MacInvalidateBorders() ;
746 #ifndef __WXUNIVERSAL__
747 // VS: make sure there's no wxFrame with last focus set to us:
748 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
750 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
753 if ( frame
->GetLastFocus() == this )
754 frame
->SetLastFocus((wxWindow
*)NULL
);
758 #endif // __WXUNIVERSAL__
760 // destroy children before destroying this window itself
763 // wxRemoveMacControlAssociation( this ) ;
764 // If we delete an item, we should initialize the parent panel,
765 // because it could now be invalid.
766 wxWindow
*parent
= GetParent() ;
769 if (parent
->GetDefaultItem() == (wxButton
*) this)
770 parent
->SetDefaultItem(NULL
);
773 if ( m_peer
&& m_peer
->Ok() )
775 // in case the callback might be called during destruction
776 wxRemoveMacControlAssociation( this) ;
777 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
778 // we currently are not using this hook
779 // ::SetControlColorProc( *m_peer , NULL ) ;
783 if ( g_MacLastWindow
== this )
784 g_MacLastWindow
= NULL
;
786 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
789 if ( frame
->GetLastFocus() == this )
790 frame
->SetLastFocus( NULL
) ;
793 // delete our drop target if we've got one
794 #if wxUSE_DRAG_AND_DROP
795 if ( m_dropTarget
!= NULL
)
805 WXWidget
wxWindowMac::GetHandle() const
807 return (WXWidget
) m_peer
->GetControlRef() ;
811 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
813 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
814 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
815 GetEventTypeCount(eventList
), eventList
, this,
816 (EventHandlerRef
*)&m_macControlEventHandler
);
818 #if !TARGET_API_MAC_OSX
819 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
821 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
822 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
823 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
824 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
825 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
826 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
827 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
828 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
834 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
838 const wxString
& name
)
840 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
842 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
845 m_windowVariant
= parent
->GetWindowVariant() ;
847 if ( m_macIsUserPane
)
849 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
852 | kControlSupportsEmbedding
853 | kControlSupportsLiveFeedback
854 | kControlGetsFocusOnClick
855 // | kControlHasSpecialBackground
856 // | kControlSupportsCalcBestRect
857 | kControlHandlesTracking
858 | kControlSupportsFocus
859 | kControlWantsActivate
863 m_peer
= new wxMacControl(this) ;
864 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
867 MacPostControlCreate(pos
,size
) ;
869 #ifndef __WXUNIVERSAL__
870 // Don't give scrollbars to wxControls unless they ask for them
871 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
872 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
874 MacCreateScrollBars( style
) ;
878 wxWindowCreateEvent
event(this);
879 GetEventHandler()->AddPendingEvent(event
);
884 void wxWindowMac::MacChildAdded()
887 m_vScrollBar
->Raise() ;
889 m_hScrollBar
->Raise() ;
892 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
894 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
896 m_peer
->SetReference( (long) this ) ;
897 GetParent()->AddChild(this);
899 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
901 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
902 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
903 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
904 GetParent()->MacChildAdded() ;
906 // adjust font, controlsize etc
907 DoSetWindowVariant( m_windowVariant
) ;
909 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
911 if (!m_macIsUserPane
)
912 SetInitialBestSize(size
);
914 SetCursor( *wxSTANDARD_CURSOR
) ;
917 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
919 // Don't assert, in case we set the window variant before
920 // the window is created
921 // wxASSERT( m_peer->Ok() ) ;
923 m_windowVariant
= variant
;
925 if (m_peer
== NULL
|| !m_peer
->Ok())
929 ThemeFontID themeFont
= kThemeSystemFont
;
931 // we will get that from the settings later
932 // and make this NORMAL later, but first
933 // we have a few calculations that we must fix
937 case wxWINDOW_VARIANT_NORMAL
:
938 size
= kControlSizeNormal
;
939 themeFont
= kThemeSystemFont
;
942 case wxWINDOW_VARIANT_SMALL
:
943 size
= kControlSizeSmall
;
944 themeFont
= kThemeSmallSystemFont
;
947 case wxWINDOW_VARIANT_MINI
:
948 if (UMAGetSystemVersion() >= 0x1030 )
950 // not always defined in the headers
956 size
= kControlSizeSmall
;
957 themeFont
= kThemeSmallSystemFont
;
961 case wxWINDOW_VARIANT_LARGE
:
962 size
= kControlSizeLarge
;
963 themeFont
= kThemeSystemFont
;
967 wxFAIL_MSG(_T("unexpected window variant"));
971 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
974 font
.MacCreateThemeFont( themeFont
) ;
978 void wxWindowMac::MacUpdateControlFont()
980 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
984 bool wxWindowMac::SetFont(const wxFont
& font
)
986 bool retval
= wxWindowBase::SetFont( font
) ;
988 MacUpdateControlFont() ;
993 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
995 if ( !wxWindowBase::SetForegroundColour(col
) )
998 MacUpdateControlFont() ;
1003 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1005 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1009 wxColour
newCol(GetBackgroundColour());
1010 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1011 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1012 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1013 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1015 brush
.SetColour( newCol
) ;
1017 MacSetBackgroundBrush( brush
) ;
1019 MacUpdateControlFont() ;
1024 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1026 m_macBackgroundBrush
= brush
;
1027 m_peer
->SetBackground( brush
) ;
1030 bool wxWindowMac::MacCanFocus() const
1032 // there is currently no way to determine whether the window is running in full keyboard
1033 // access mode, therefore we cannot rely on these features, yet the only other way would be
1034 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1035 // in event handlers...
1036 UInt32 features
= 0 ;
1037 m_peer
->GetFeatures( & features
) ;
1039 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1042 void wxWindowMac::SetFocus()
1044 if ( !AcceptsFocus() )
1047 wxWindow
* former
= FindFocus() ;
1048 if ( former
== this )
1051 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1052 // we can only leave in case of an error
1053 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1054 if ( err
== errCouldntSetFocus
)
1057 // enable for patch 1376506 - perhaps? (Stefan's version)
1059 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1062 #if !TARGET_API_MAC_OSX
1063 // emulate carbon events when running under CarbonLib where they are not natively available
1066 EventRef evRef
= NULL
;
1067 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1070 wxMacCarbonEvent
cEvent( evRef
) ;
1071 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1072 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1074 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1075 ReleaseEvent(evRef
) ;
1078 // send new focus event
1080 EventRef evRef
= NULL
;
1081 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1084 wxMacCarbonEvent
cEvent( evRef
) ;
1085 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1086 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1088 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1089 ReleaseEvent(evRef
) ;
1094 void wxWindowMac::DoCaptureMouse()
1096 wxApp::s_captureWindow
= this ;
1099 wxWindow
* wxWindowBase::GetCapture()
1101 return wxApp::s_captureWindow
;
1104 void wxWindowMac::DoReleaseMouse()
1106 wxApp::s_captureWindow
= NULL
;
1109 #if wxUSE_DRAG_AND_DROP
1111 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1113 if ( m_dropTarget
!= NULL
)
1114 delete m_dropTarget
;
1116 m_dropTarget
= pDropTarget
;
1117 if ( m_dropTarget
!= NULL
)
1125 // Old style file-manager drag&drop
1126 void wxWindowMac::DragAcceptFiles(bool accept
)
1131 // Returns the size of the native control. In the case of the toplevel window
1132 // this is the content area root control
1134 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1135 int& w
, int& h
) const
1137 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1140 // From a wx position / size calculate the appropriate size of the native control
1142 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1145 int& w
, int& h
, bool adjustOrigin
) const
1147 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1149 // the desired size, minus the border pixels gives the correct size of the control
1153 // todo the default calls may be used as soon as PostCreateControl Is moved here
1154 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1155 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1157 if ( !isCompositing
)
1158 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1160 x
+= MacGetLeftBorderSize() ;
1161 y
+= MacGetTopBorderSize() ;
1162 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1163 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1166 AdjustForParentClientOrigin( x
, y
) ;
1168 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1169 if ( !GetParent()->IsTopLevel() )
1171 x
-= GetParent()->MacGetLeftBorderSize() ;
1172 y
-= GetParent()->MacGetTopBorderSize() ;
1178 // Get window size (not client size)
1179 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1182 m_peer
->GetRect( &bounds
) ;
1185 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1187 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1190 // get the position of the bounds of this window in client coordinates of its parent
1191 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1194 m_peer
->GetRect( &bounds
) ;
1196 int x1
= bounds
.left
;
1197 int y1
= bounds
.top
;
1199 // get the wx window position from the native one
1200 x1
-= MacGetLeftBorderSize() ;
1201 y1
-= MacGetTopBorderSize() ;
1203 if ( !IsTopLevel() )
1205 wxWindow
*parent
= GetParent();
1208 // we must first adjust it to be in window coordinates of the parent,
1209 // as otherwise it gets lost by the ClientAreaOrigin fix
1210 x1
+= parent
->MacGetLeftBorderSize() ;
1211 y1
+= parent
->MacGetTopBorderSize() ;
1213 // and now to client coordinates
1214 wxPoint
pt(parent
->GetClientAreaOrigin());
1226 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1228 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1230 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1233 Point localwhere
= {0, 0} ;
1240 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1248 MacRootWindowToWindow( x
, y
) ;
1250 wxPoint origin
= GetClientAreaOrigin() ;
1257 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1259 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1260 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1262 wxPoint origin
= GetClientAreaOrigin() ;
1268 MacWindowToRootWindow( x
, y
) ;
1271 Point localwhere
= { 0,0 };
1273 localwhere
.h
= * x
;
1275 localwhere
.v
= * y
;
1277 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1286 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1288 wxPoint origin
= GetClientAreaOrigin() ;
1294 MacWindowToRootWindow( x
, y
) ;
1297 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1299 MacRootWindowToWindow( x
, y
) ;
1301 wxPoint origin
= GetClientAreaOrigin() ;
1308 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1316 if ( !IsTopLevel() )
1318 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1321 pt
.x
-= MacGetLeftBorderSize() ;
1322 pt
.y
-= MacGetTopBorderSize() ;
1323 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1333 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1342 MacWindowToRootWindow( &x1
, &y1
) ;
1350 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1359 if ( !IsTopLevel() )
1361 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1364 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1365 pt
.x
+= MacGetLeftBorderSize() ;
1366 pt
.y
+= MacGetTopBorderSize() ;
1376 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1385 MacRootWindowToWindow( &x1
, &y1
) ;
1393 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1395 RgnHandle rgn
= NewRgn() ;
1396 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1400 GetRegionBounds( rgn
, &content
) ;
1401 m_peer
->GetRect( &structure
) ;
1402 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1404 left
= content
.left
- structure
.left
;
1405 top
= content
.top
- structure
.top
;
1406 right
= structure
.right
- content
.right
;
1407 bottom
= structure
.bottom
- content
.bottom
;
1411 left
= top
= right
= bottom
= 0 ;
1416 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1418 wxSize sizeTotal
= size
;
1420 RgnHandle rgn
= NewRgn() ;
1421 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1425 GetRegionBounds( rgn
, &content
) ;
1427 m_peer
->GetRect( &structure
) ;
1428 // structure is in parent coordinates, but we only need width and height, so it's ok
1430 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1431 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1435 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1436 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1441 // Get size *available for subwindows* i.e. excluding menu bar etc.
1442 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1446 RgnHandle rgn
= NewRgn() ;
1448 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1449 GetRegionBounds( rgn
, &content
) ;
1451 m_peer
->GetRect( &content
) ;
1454 ww
= content
.right
- content
.left
;
1455 hh
= content
.bottom
- content
.top
;
1457 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1458 hh
-= m_hScrollBar
->GetSize().y
;
1460 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1461 ww
-= m_vScrollBar
->GetSize().x
;
1470 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1472 if (m_cursor
== cursor
)
1475 if (wxNullCursor
== cursor
)
1477 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1482 if ( ! wxWindowBase::SetCursor( cursor
) )
1486 wxASSERT_MSG( m_cursor
.Ok(),
1487 wxT("cursor must be valid after call to the base version"));
1489 wxWindowMac
*mouseWin
= 0 ;
1491 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1492 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1494 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1496 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1497 // position, use it...
1501 ControlPartCode part
;
1502 ControlRef control
;
1503 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1505 mouseWin
= wxFindControlFromMacControl( control
) ;
1508 QDSwapPort( savePort
, NULL
) ;
1511 if ( mouseWin
== this && !wxIsBusy() )
1512 m_cursor
.MacInstall() ;
1518 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1520 menu
->SetInvokingWindow(this);
1523 if ( x
== -1 && y
== -1 )
1525 wxPoint mouse
= wxGetMousePosition();
1526 x
= mouse
.x
; y
= mouse
.y
;
1530 ClientToScreen( &x
, &y
) ;
1533 menu
->MacBeforeDisplay( true ) ;
1534 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1535 if ( HiWord(menuResult
) != 0 )
1538 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1539 wxMenuItem
* item
= NULL
;
1541 item
= menu
->FindItem(id
, &realmenu
) ;
1542 if (item
->IsCheckable())
1543 item
->Check( !item
->IsChecked() ) ;
1545 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1547 menu
->MacAfterDisplay( true ) ;
1549 menu
->SetInvokingWindow(NULL
);
1555 // ----------------------------------------------------------------------------
1557 // ----------------------------------------------------------------------------
1561 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1563 wxWindowBase::DoSetToolTip(tooltip
);
1566 m_tooltip
->SetWindow(this);
1569 #endif // wxUSE_TOOLTIPS
1571 void wxWindowMac::MacInvalidateBorders()
1573 if ( m_peer
== NULL
)
1576 bool vis
= MacIsReallyShown() ;
1580 int outerBorder
= MacGetLeftBorderSize() ;
1581 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1584 if ( outerBorder
== 0 )
1587 // now we know that we have something to do at all
1589 // as the borders are drawn on the parent we have to properly invalidate all these areas
1590 RgnHandle updateInner
= NewRgn() ,
1591 updateOuter
= NewRgn() ;
1593 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1595 m_peer
->GetRect( &rect
) ;
1596 RectRgn( updateInner
, &rect
) ;
1597 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1598 RectRgn( updateOuter
, &rect
) ;
1599 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1601 #ifdef __WXMAC_OSX__
1602 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1604 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1606 InvalWindowRgn( tlw
, updateOuter
) ;
1609 DisposeRgn(updateOuter
) ;
1610 DisposeRgn(updateInner
) ;
1613 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
1614 RectRgn( updateInner
, &rect
) ;
1615 InsetRect( &rect
, -4 , -4 ) ;
1616 RectRgn( updateOuter
, &rect
) ;
1617 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1618 wxPoint
parent(0,0);
1619 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1620 parent
-= GetParent()->GetClientAreaOrigin() ;
1621 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1622 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
1623 DisposeRgn(updateOuter
) ;
1624 DisposeRgn(updateInner
) ;
1630 // deleting a window while it is shown invalidates the region occupied by border or
1633 if ( IsShown() && ( outerBorder
> 0 ) )
1635 // as the borders are drawn on the parent we have to properly invalidate all these areas
1636 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1640 m_peer
->GetRect( &rect
) ;
1641 RectRgn( updateInner
, &rect
) ;
1642 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1643 RectRgn( updateOuter
, &rect
) ;
1644 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1645 wxPoint
parent(0,0);
1646 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1647 parent
-= GetParent()->GetClientAreaOrigin() ;
1648 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1649 CopyRgn( updateOuter
, updateTotal
) ;
1651 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1652 DisposeRgn(updateOuter
) ;
1653 DisposeRgn(updateInner
) ;
1654 DisposeRgn(updateTotal
) ;
1660 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1662 int outerBorder
= MacGetLeftBorderSize() ;
1663 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1666 if ( vis
&& ( outerBorder
> 0 ) )
1668 // as the borders are drawn on the parent we have to properly invalidate all these areas
1669 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1673 m_peer
->GetRect( &rect
) ;
1674 RectRgn( updateInner
, &rect
) ;
1675 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1676 RectRgn( updateOuter
, &rect
) ;
1677 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1679 wxPoint parent(0,0);
1680 #if TARGET_API_MAC_OSX
1681 // no offsetting needed when compositing
1683 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1684 parent -= GetParent()->GetClientAreaOrigin() ;
1685 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1688 CopyRgn( updateOuter
, updateTotal
) ;
1691 RectRgn( updateInner
, &rect
) ;
1692 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1693 RectRgn( updateOuter
, &rect
) ;
1694 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1696 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1698 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1700 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1701 DisposeRgn(updateOuter
) ;
1702 DisposeRgn(updateInner
) ;
1703 DisposeRgn(updateTotal
) ;
1708 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1710 // this is never called for a toplevel window, so we know we have a parent
1711 int former_x
, former_y
, former_w
, former_h
;
1713 // Get true coordinates of former position
1714 DoGetPosition( &former_x
, &former_y
) ;
1715 DoGetSize( &former_w
, &former_h
) ;
1717 wxWindow
*parent
= GetParent();
1720 wxPoint
pt(parent
->GetClientAreaOrigin());
1725 int actualWidth
= width
;
1726 int actualHeight
= height
;
1730 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1731 actualWidth
= m_minWidth
;
1732 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1733 actualHeight
= m_minHeight
;
1734 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1735 actualWidth
= m_maxWidth
;
1736 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1737 actualHeight
= m_maxHeight
;
1739 bool doMove
= false ;
1740 bool doResize
= false ;
1742 if ( actualX
!= former_x
|| actualY
!= former_y
)
1745 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1748 if ( doMove
|| doResize
)
1750 // as the borders are drawn outside the native control, we adjust now
1752 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1753 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1754 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1757 wxMacRectToNative( &bounds
, &r
) ;
1759 if ( !GetParent()->IsTopLevel() )
1760 wxMacWindowToNative( GetParent() , &r
) ;
1762 MacInvalidateBorders() ;
1764 m_cachedClippedRectValid
= false ;
1765 m_peer
->SetRect( &r
) ;
1767 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1769 MacInvalidateBorders() ;
1771 MacRepositionScrollBars() ;
1774 wxPoint
point(actualX
,actualY
);
1775 wxMoveEvent
event(point
, m_windowId
);
1776 event
.SetEventObject(this);
1777 GetEventHandler()->ProcessEvent(event
) ;
1782 MacRepositionScrollBars() ;
1783 wxSize
size(actualWidth
, actualHeight
);
1784 wxSizeEvent
event(size
, m_windowId
);
1785 event
.SetEventObject(this);
1786 GetEventHandler()->ProcessEvent(event
);
1791 wxSize
wxWindowMac::DoGetBestSize() const
1793 if ( m_macIsUserPane
|| IsTopLevel() )
1794 return wxWindowBase::DoGetBestSize() ;
1796 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1797 int bestWidth
, bestHeight
;
1798 m_peer
->GetBestRect( &bestsize
) ;
1800 if ( EmptyRect( &bestsize
) )
1802 bestsize
.left
= bestsize
.top
= 0 ;
1803 bestsize
.right
= 16 ;
1804 bestsize
.bottom
= 16 ;
1805 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1807 bestsize
.bottom
= 16 ;
1810 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1812 bestsize
.bottom
= 24 ;
1814 #endif // wxUSE_SPINBTN
1817 // return wxWindowBase::DoGetBestSize() ;
1821 bestWidth
= bestsize
.right
- bestsize
.left
;
1822 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1823 if ( bestHeight
< 10 )
1826 return wxSize(bestWidth
, bestHeight
);
1829 // set the size of the window: if the dimensions are positive, just use them,
1830 // but if any of them is equal to -1, it means that we must find the value for
1831 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1832 // which case -1 is a valid value for x and y)
1834 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1835 // the width/height to best suit our contents, otherwise we reuse the current
1837 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1839 // get the current size and position...
1840 int currentX
, currentY
;
1841 GetPosition(¤tX
, ¤tY
);
1843 int currentW
,currentH
;
1844 GetSize(¤tW
, ¤tH
);
1846 // ... and don't do anything (avoiding flicker) if it's already ok
1847 if ( x
== currentX
&& y
== currentY
&&
1848 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1851 MacRepositionScrollBars() ; // we might have a real position shift
1855 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1857 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1860 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1862 wxSize size
= wxDefaultSize
;
1863 if ( width
== wxDefaultCoord
)
1865 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1867 size
= DoGetBestSize();
1872 // just take the current one
1877 if ( height
== wxDefaultCoord
)
1879 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1881 if ( size
.x
== wxDefaultCoord
)
1883 size
= DoGetBestSize();
1885 //else: already called DoGetBestSize() above
1891 // just take the current one
1896 DoMoveWindow(x
, y
, width
, height
);
1899 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1901 RgnHandle rgn
= NewRgn() ;
1903 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1905 GetRegionBounds( rgn
, &content
) ;
1909 content
.left
= content
.top
= 0 ;
1913 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
1916 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1918 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1920 int currentclientwidth
, currentclientheight
;
1921 int currentwidth
, currentheight
;
1923 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1924 GetSize( ¤twidth
, ¤theight
) ;
1926 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1927 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1931 void wxWindowMac::SetLabel(const wxString
& title
)
1933 m_label
= wxStripMenuCodes(title
) ;
1935 if ( m_peer
&& m_peer
->Ok() )
1936 m_peer
->SetLabel( m_label
) ;
1941 wxString
wxWindowMac::GetLabel() const
1946 bool wxWindowMac::Show(bool show
)
1948 bool former
= MacIsReallyShown() ;
1949 if ( !wxWindowBase::Show(show
) )
1952 // TODO use visibilityChanged Carbon Event for OSX
1954 m_peer
->SetVisibility( show
, true ) ;
1956 if ( former
!= MacIsReallyShown() )
1957 MacPropagateVisibilityChanged() ;
1961 bool wxWindowMac::Enable(bool enable
)
1963 wxASSERT( m_peer
->Ok() ) ;
1964 bool former
= MacIsReallyEnabled() ;
1965 if ( !wxWindowBase::Enable(enable
) )
1968 m_peer
->Enable( enable
) ;
1970 if ( former
!= MacIsReallyEnabled() )
1971 MacPropagateEnabledStateChanged() ;
1977 // status change propagations (will be not necessary for OSX later )
1980 void wxWindowMac::MacPropagateVisibilityChanged()
1982 #if !TARGET_API_MAC_OSX
1983 MacVisibilityChanged() ;
1986 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1989 child
= node
->GetData();
1990 if ( child
->IsShown() )
1991 child
->MacPropagateVisibilityChanged() ;
1993 node
= node
->GetNext();
1998 void wxWindowMac::MacPropagateEnabledStateChanged()
2000 #if !TARGET_API_MAC_OSX
2001 MacEnabledStateChanged() ;
2004 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2007 child
= node
->GetData();
2008 if ( child
->IsEnabled() )
2009 child
->MacPropagateEnabledStateChanged() ;
2011 node
= node
->GetNext();
2016 void wxWindowMac::MacPropagateHiliteChanged()
2018 #if !TARGET_API_MAC_OSX
2019 MacHiliteChanged() ;
2022 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2025 child
= node
->GetData();
2026 // if ( child->IsEnabled() )
2027 child
->MacPropagateHiliteChanged() ;
2029 node
= node
->GetNext();
2035 // status change notifications
2038 void wxWindowMac::MacVisibilityChanged()
2042 void wxWindowMac::MacHiliteChanged()
2046 void wxWindowMac::MacEnabledStateChanged()
2051 // status queries on the inherited window's state
2054 bool wxWindowMac::MacIsReallyShown()
2056 // only under OSX the visibility of the TLW is taken into account
2057 if ( m_isBeingDeleted
)
2060 #if TARGET_API_MAC_OSX
2061 if ( m_peer
&& m_peer
->Ok() )
2062 return m_peer
->IsVisible();
2065 wxWindow
* win
= this ;
2066 while ( win
->IsShown() )
2068 if ( win
->IsTopLevel() )
2071 win
= win
->GetParent() ;
2079 bool wxWindowMac::MacIsReallyEnabled()
2081 return m_peer
->IsEnabled() ;
2084 bool wxWindowMac::MacIsReallyHilited()
2086 return m_peer
->IsActive();
2089 void wxWindowMac::MacFlashInvalidAreas()
2091 #if TARGET_API_MAC_OSX
2092 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2096 int wxWindowMac::GetCharHeight() const
2098 wxClientDC
dc( (wxWindowMac
*)this ) ;
2100 return dc
.GetCharHeight() ;
2103 int wxWindowMac::GetCharWidth() const
2105 wxClientDC
dc( (wxWindowMac
*)this ) ;
2107 return dc
.GetCharWidth() ;
2110 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2111 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2113 const wxFont
*fontToUse
= theFont
;
2115 fontToUse
= &m_font
;
2117 wxClientDC
dc( (wxWindowMac
*) this ) ;
2119 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2120 if ( externalLeading
)
2121 *externalLeading
= le
;
2131 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2132 * we always intersect with the entire window, not only with the client area
2135 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2137 if ( m_peer
== NULL
)
2140 if ( !MacIsReallyShown() )
2146 wxMacRectToNative( rect
, &r
) ;
2147 m_peer
->SetNeedsDisplay( &r
) ;
2151 m_peer
->SetNeedsDisplay() ;
2155 void wxWindowMac::Freeze()
2157 #if TARGET_API_MAC_OSX
2158 if ( !m_frozenness
++ )
2160 if ( m_peer
&& m_peer
->Ok() )
2161 m_peer
->SetDrawingEnabled( false ) ;
2166 void wxWindowMac::Thaw()
2168 #if TARGET_API_MAC_OSX
2169 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2171 if ( !--m_frozenness
)
2173 if ( m_peer
&& m_peer
->Ok() )
2175 m_peer
->SetDrawingEnabled( true ) ;
2176 m_peer
->InvalidateWithChildren() ;
2182 wxWindowMac
*wxGetActiveWindow()
2184 // actually this is a windows-only concept
2188 // Coordinates relative to the window
2189 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2191 // We really don't move the mouse programmatically under Mac.
2194 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2196 if ( MacGetTopLevelWindow() == NULL
)
2198 #if TARGET_API_MAC_OSX
2199 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2206 event
.GetDC()->Clear() ;
2210 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2215 int wxWindowMac::GetScrollPos(int orient
) const
2217 if ( orient
== wxHORIZONTAL
)
2220 return m_hScrollBar
->GetThumbPosition() ;
2225 return m_vScrollBar
->GetThumbPosition() ;
2231 // This now returns the whole range, not just the number
2232 // of positions that we can scroll.
2233 int wxWindowMac::GetScrollRange(int orient
) const
2235 if ( orient
== wxHORIZONTAL
)
2238 return m_hScrollBar
->GetRange() ;
2243 return m_vScrollBar
->GetRange() ;
2249 int wxWindowMac::GetScrollThumb(int orient
) const
2251 if ( orient
== wxHORIZONTAL
)
2254 return m_hScrollBar
->GetThumbSize() ;
2259 return m_vScrollBar
->GetThumbSize() ;
2265 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2267 if ( orient
== wxHORIZONTAL
)
2270 m_hScrollBar
->SetThumbPosition( pos
) ;
2275 m_vScrollBar
->SetThumbPosition( pos
) ;
2280 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2281 // our own window origin is at leftOrigin/rightOrigin
2284 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2290 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2291 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2293 m_peer
->GetRect( &rect
) ;
2294 // back to the surrounding frame rectangle
2295 InsetRect( &rect
, -1 , -1 ) ;
2297 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2298 if ( UMAGetSystemVersion() >= 0x1030 )
2300 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2301 rect
.bottom
- rect
.top
) ;
2303 HIThemeFrameDrawInfo info
;
2304 memset( &info
, 0 , sizeof( info
) ) ;
2308 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2309 info
.isFocused
= hasFocus
;
2311 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2312 wxASSERT( cgContext
) ;
2314 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2316 info
.kind
= kHIThemeFrameTextFieldSquare
;
2317 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2319 else if ( HasFlag(wxSIMPLE_BORDER
) )
2321 info
.kind
= kHIThemeFrameListBox
;
2322 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2324 else if ( hasFocus
)
2326 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2329 m_peer
->GetRect( &rect
) ;
2330 if ( hasBothScrollbars
)
2332 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2333 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2334 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2335 HIThemeGrowBoxDrawInfo info
;
2336 memset( &info
, 0, sizeof(info
) ) ;
2338 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2339 info
.kind
= kHIThemeGrowBoxKindNone
;
2340 info
.size
= kHIThemeGrowBoxSizeNormal
;
2341 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2342 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2348 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2352 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2353 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2356 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2357 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2358 else if ( HasFlag(wxSIMPLE_BORDER
) )
2359 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2362 DrawThemeFocusRect( &rect
, true ) ;
2364 if ( hasBothScrollbars
)
2366 // GetThemeStandaloneGrowBoxBounds
2367 // DrawThemeStandaloneNoGrowBox
2372 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2374 if ( child
== m_hScrollBar
)
2375 m_hScrollBar
= NULL
;
2376 if ( child
== m_vScrollBar
)
2377 m_vScrollBar
= NULL
;
2379 wxWindowBase::RemoveChild( child
) ;
2382 // New function that will replace some of the above.
2383 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2384 int range
, bool refresh
)
2386 if ( orient
== wxHORIZONTAL
)
2390 if ( range
== 0 || thumbVisible
>= range
)
2392 if ( m_hScrollBar
->IsShown() )
2393 m_hScrollBar
->Show(false) ;
2397 if ( !m_hScrollBar
->IsShown() )
2398 m_hScrollBar
->Show(true) ;
2401 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2408 if ( range
== 0 || thumbVisible
>= range
)
2410 if ( m_vScrollBar
->IsShown() )
2411 m_vScrollBar
->Show(false) ;
2415 if ( !m_vScrollBar
->IsShown() )
2416 m_vScrollBar
->Show(true) ;
2419 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2423 MacRepositionScrollBars() ;
2426 // Does a physical scroll
2427 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2429 if ( dx
== 0 && dy
==0 )
2432 int width
, height
;
2433 GetClientSize( &width
, &height
) ;
2435 #if TARGET_API_MAC_OSX
2436 if ( true /* m_peer->IsCompositing() */ )
2438 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2439 // area is scrolled, this does not occur if width and height are 2 pixels less,
2440 // TODO write optimal workaround
2441 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2443 scrollrect
.Intersect( *rect
) ;
2445 if ( m_peer
->GetNeedsDisplay() )
2447 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2448 // either immediate redraw or full invalidate
2450 // is the better overall solution, as it does not slow down scrolling
2451 m_peer
->SetNeedsDisplay() ;
2453 // this would be the preferred version for fast drawing controls
2455 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2456 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2457 HIViewRender(m_peer
->GetControlRef()) ;
2464 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2465 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2466 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2468 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2469 // either immediate redraw or full invalidate
2471 // is the better overall solution, as it does not slow down scrolling
2472 m_peer
->SetNeedsDisplay() ;
2474 // this would be the preferred version for fast drawing controls
2476 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2477 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2478 HIViewRender(m_peer
->GetControlRef()) ;
2493 RgnHandle updateRgn
= NewRgn() ;
2496 wxClientDC
dc(this) ;
2497 wxMacPortSetter
helper(&dc
) ;
2499 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2500 //scrollrect.top += MacGetTopBorderSize() ;
2501 //scrollrect.left += MacGetLeftBorderSize() ;
2502 scrollrect
.bottom
= scrollrect
.top
+ height
;
2503 scrollrect
.right
= scrollrect
.left
+ width
;
2507 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2508 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2509 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2512 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2514 // now scroll the former update region as well and add the new update region
2515 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2516 RgnHandle formerUpdateRgn
= NewRgn() ;
2517 RgnHandle scrollRgn
= NewRgn() ;
2518 RectRgn( scrollRgn
, &scrollrect
) ;
2519 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2521 LocalToGlobal( &pt
) ;
2522 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2523 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2525 if ( !EmptyRgn( formerUpdateRgn
) )
2527 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2528 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2529 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2532 InvalWindowRgn(rootWindow
, updateRgn
) ;
2533 DisposeRgn( updateRgn
) ;
2534 DisposeRgn( formerUpdateRgn
) ;
2535 DisposeRgn( scrollRgn
) ;
2543 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2545 child
= node
->GetData();
2548 if (child
== m_vScrollBar
)
2550 if (child
== m_hScrollBar
)
2552 if (child
->IsTopLevel())
2555 child
->GetPosition( &x
, &y
);
2556 child
->GetSize( &w
, &h
);
2559 wxRect
rc( x
, y
, w
, h
);
2560 if (rect
->Intersects( rc
))
2561 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2565 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2570 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2572 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2574 wxScrollWinEvent wevent
;
2575 wevent
.SetPosition(event
.GetPosition());
2576 wevent
.SetOrientation(event
.GetOrientation());
2577 wevent
.SetEventObject(this);
2579 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2580 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2581 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2582 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2583 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2584 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2585 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2586 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2587 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2588 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2589 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2590 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2591 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2592 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2593 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2594 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2596 GetEventHandler()->ProcessEvent(wevent
);
2600 // Get the window with the focus
2601 wxWindowMac
*wxWindowBase::DoFindFocus()
2603 ControlRef control
;
2604 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2605 return wxFindControlFromMacControl( control
) ;
2608 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2610 // panel wants to track the window which was the last to have focus in it,
2611 // so we want to set ourselves as the window which last had focus
2613 // notice that it's also important to do it upwards the tree because
2614 // otherwise when the top level panel gets focus, it won't set it back to
2615 // us, but to some other sibling
2617 // CS: don't know if this is still needed:
2618 //wxChildFocusEvent eventFocus(this);
2619 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2621 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2623 // enable for patch 1376506 - perhaps?
2625 if ( bIsFocusEvent
)
2626 SetUserFocusWindow( GetControlOwner( GetPeer()->GetControlRef() ) );
2628 SetUserFocusWindow( kUserFocusAuto
);
2631 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2633 #if wxMAC_USE_CORE_GRAPHICS
2634 GetParent()->Refresh() ;
2636 wxMacWindowStateSaver
sv( this ) ;
2639 m_peer
->GetRect( &rect
) ;
2640 // auf den umgebenden Rahmen zur\9fck
2641 InsetRect( &rect
, -1 , -1 ) ;
2643 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2647 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2649 rect
.right
+= pt
.x
;
2651 rect
.bottom
+= pt
.y
;
2654 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2655 if ( !bIsFocusEvent
)
2657 // as this erases part of the frame we have to redraw borders
2658 // and because our z-ordering is not always correct (staticboxes)
2659 // we have to invalidate things, we cannot simple redraw
2660 MacInvalidateBorders() ;
2668 void wxWindowMac::OnInternalIdle()
2670 // This calls the UI-update mechanism (querying windows for
2671 // menu/toolbar/control state information)
2672 if (wxUpdateUIEvent::CanUpdate(this))
2673 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2676 // Raise the window to the top of the Z order
2677 void wxWindowMac::Raise()
2679 m_peer
->SetZOrder( true , NULL
) ;
2682 // Lower the window to the bottom of the Z order
2683 void wxWindowMac::Lower()
2685 m_peer
->SetZOrder( false , NULL
) ;
2688 // static wxWindow *gs_lastWhich = NULL;
2690 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2692 // first trigger a set cursor event
2694 wxPoint clientorigin
= GetClientAreaOrigin() ;
2695 wxSize clientsize
= GetClientSize() ;
2697 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2699 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2701 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2702 if ( processedEvtSetCursor
&& event
.HasCursor() )
2704 cursor
= event
.GetCursor() ;
2708 // the test for processedEvtSetCursor is here to prevent using m_cursor
2709 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2710 // it - this is a way to say that our cursor shouldn't be used for this
2712 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2715 if ( !wxIsBusy() && !GetParent() )
2716 cursor
= *wxSTANDARD_CURSOR
;
2720 cursor
.MacInstall() ;
2723 return cursor
.Ok() ;
2726 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2730 return m_tooltip
->GetTip() ;
2733 return wxEmptyString
;
2736 void wxWindowMac::ClearBackground()
2742 void wxWindowMac::Update()
2744 #if TARGET_API_MAC_OSX
2745 MacGetTopLevelWindow()->MacPerformUpdates() ;
2747 ::Draw1Control( m_peer
->GetControlRef() ) ;
2751 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2753 wxTopLevelWindowMac
* win
= NULL
;
2754 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2756 win
= wxFindWinFromMacWindow( window
) ;
2761 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2763 MacUpdateClippedRects() ;
2765 return m_cachedClippedClientRect
;
2768 const wxRect
& wxWindowMac::MacGetClippedRect() const
2770 MacUpdateClippedRects() ;
2772 return m_cachedClippedRect
;
2775 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2777 MacUpdateClippedRects() ;
2779 return m_cachedClippedRectWithOuterStructure
;
2782 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2784 static wxRegion emptyrgn
;
2785 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2787 MacUpdateClippedRects() ;
2788 if ( includeOuterStructures
)
2789 return m_cachedClippedRegionWithOuterStructure
;
2791 return m_cachedClippedRegion
;
2799 void wxWindowMac::MacUpdateClippedRects() const
2801 if ( m_cachedClippedRectValid
)
2804 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2805 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2806 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2807 // to add focus borders everywhere
2809 Rect r
, rIncludingOuterStructures
;
2811 m_peer
->GetRect( &r
) ;
2812 r
.left
-= MacGetLeftBorderSize() ;
2813 r
.top
-= MacGetTopBorderSize() ;
2814 r
.bottom
+= MacGetBottomBorderSize() ;
2815 r
.right
+= MacGetRightBorderSize() ;
2822 rIncludingOuterStructures
= r
;
2823 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2825 wxRect cl
= GetClientRect() ;
2826 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2830 const wxWindow
* child
= this ;
2831 const wxWindow
* parent
= NULL
;
2832 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2834 if ( parent
->MacIsChildOfClientArea(child
) )
2836 size
= parent
->GetClientSize() ;
2837 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2843 // this will be true for scrollbars, toolbars etc.
2844 size
= parent
->GetSize() ;
2845 y
= parent
->MacGetTopBorderSize() ;
2846 x
= parent
->MacGetLeftBorderSize() ;
2847 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2848 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2851 parent
->MacWindowToRootWindow( &x
, &y
) ;
2852 MacRootWindowToWindow( &x
, &y
) ;
2854 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2856 // the wxwindow and client rects will always be clipped
2857 SectRect( &r
, &rparent
, &r
) ;
2858 SectRect( &rClient
, &rparent
, &rClient
) ;
2860 // the structure only at 'hard' borders
2861 if ( parent
->MacClipChildren() ||
2862 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2864 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2870 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2871 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2872 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2873 m_cachedClippedRectWithOuterStructure
= wxRect(
2874 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2875 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2876 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2878 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2879 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2880 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2882 m_cachedClippedRectValid
= true ;
2886 This function must not change the updatergn !
2888 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2890 bool handled
= false ;
2892 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2893 GetRegionBounds( updatergn
, &updatebounds
) ;
2895 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2897 if ( !EmptyRgn(updatergn
) )
2899 RgnHandle newupdate
= NewRgn() ;
2900 wxSize point
= GetClientSize() ;
2901 wxPoint origin
= GetClientAreaOrigin() ;
2902 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2903 SectRgn( newupdate
, updatergn
, newupdate
) ;
2905 // first send an erase event to the entire update area
2907 // for the toplevel window this really is the entire area
2908 // for all the others only their client area, otherwise they
2909 // might be drawing with full alpha and eg put blue into
2910 // the grow-box area of a scrolled window (scroll sample)
2911 wxDC
* dc
= new wxWindowDC(this);
2913 dc
->SetClippingRegion(wxRegion(updatergn
));
2915 dc
->SetClippingRegion(wxRegion(newupdate
));
2917 wxEraseEvent
eevent( GetId(), dc
);
2918 eevent
.SetEventObject( this );
2919 GetEventHandler()->ProcessEvent( eevent
);
2923 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2924 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2925 m_updateRegion
= newupdate
;
2926 DisposeRgn( newupdate
) ;
2928 if ( !m_updateRegion
.Empty() )
2930 // paint the window itself
2933 event
.SetTimestamp(time
);
2934 event
.SetEventObject(this);
2935 GetEventHandler()->ProcessEvent(event
);
2939 // now we cannot rely on having its borders drawn by a window itself, as it does not
2940 // get the updateRgn wide enough to always do so, so we do it from the parent
2941 // this would also be the place to draw any custom backgrounds for native controls
2942 // in Composited windowing
2943 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2947 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2949 child
= node
->GetData();
2952 if (child
== m_vScrollBar
)
2954 if (child
== m_hScrollBar
)
2956 if (child
->IsTopLevel())
2958 if (!child
->IsShown())
2961 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2963 child
->GetPosition( &x
, &y
);
2964 child
->GetSize( &w
, &h
);
2965 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2966 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2967 InsetRect( &childRect
, -10 , -10) ;
2969 if ( RectInRgn( &childRect
, updatergn
) )
2971 // paint custom borders
2972 wxNcPaintEvent
eventNc( child
->GetId() );
2973 eventNc
.SetEventObject( child
);
2974 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2976 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2977 if ( UMAGetSystemVersion() >= 0x1030 )
2979 child
->MacPaintBorders(0, 0) ;
2984 wxWindowDC
dc(this) ;
2985 dc
.SetClippingRegion(wxRegion(updatergn
));
2986 wxMacPortSetter
helper(&dc
) ;
2987 child
->MacPaintBorders(0, 0) ;
2998 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3000 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3004 if ( iter
->IsTopLevel() )
3005 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3007 iter
= iter
->GetParent() ;
3010 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3015 void wxWindowMac::MacCreateScrollBars( long style
)
3017 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3019 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3021 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3022 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3023 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3024 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3026 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3027 variant
= wxWINDOW_VARIANT_SMALL
;
3030 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3032 GetClientSize( &width
, &height
) ;
3034 wxPoint
vPoint(width
-scrlsize
, 0) ;
3035 wxSize
vSize(scrlsize
, height
- adjust
) ;
3036 wxPoint
hPoint(0 , height
-scrlsize
) ;
3037 wxSize
hSize( width
- adjust
, scrlsize
) ;
3039 if ( style
& wxVSCROLL
)
3040 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3042 if ( style
& wxHSCROLL
)
3043 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3046 // because the create does not take into account the client area origin
3047 // we might have a real position shift
3048 MacRepositionScrollBars() ;
3051 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3053 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3059 void wxWindowMac::MacRepositionScrollBars()
3061 if ( !m_hScrollBar
&& !m_vScrollBar
)
3064 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3065 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3066 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3068 // get real client area
3070 GetSize( &width
, &height
);
3072 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3073 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3075 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3076 wxSize
vSize( scrlsize
, height
- adjust
) ;
3077 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3078 wxSize
hSize( width
- adjust
, scrlsize
) ;
3081 int x
= 0, y
= 0, w
, h
;
3082 GetSize( &w
, &h
) ;
3084 MacClientToRootWindow( &x
, &y
) ;
3085 MacClientToRootWindow( &w
, &h
) ;
3087 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3089 int totW
= 10000 , totH
= 10000;
3092 if ( iter
->IsTopLevel() )
3094 iter
->GetSize( &totW
, &totH
) ;
3098 iter
= iter
->GetParent() ;
3112 if ( w
- x
>= totW
)
3117 if ( h
- y
>= totH
)
3125 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3127 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3130 bool wxWindowMac::AcceptsFocus() const
3132 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3135 void wxWindowMac::MacSuperChangedPosition()
3137 // only window-absolute structures have to be moved i.e. controls
3139 m_cachedClippedRectValid
= false ;
3142 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3145 child
= node
->GetData();
3146 child
->MacSuperChangedPosition() ;
3148 node
= node
->GetNext();
3152 void wxWindowMac::MacTopLevelWindowChangedPosition()
3154 // only screen-absolute structures have to be moved i.e. glcanvas
3157 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3160 child
= node
->GetData();
3161 child
->MacTopLevelWindowChangedPosition() ;
3163 node
= node
->GetNext();
3167 long wxWindowMac::MacGetLeftBorderSize() const
3174 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3176 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3177 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3179 else if (HasFlag(wxSIMPLE_BORDER
))
3181 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3182 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3188 long wxWindowMac::MacGetRightBorderSize() const
3190 // they are all symmetric in mac themes
3191 return MacGetLeftBorderSize() ;
3194 long wxWindowMac::MacGetTopBorderSize() const
3196 // they are all symmetric in mac themes
3197 return MacGetLeftBorderSize() ;
3200 long wxWindowMac::MacGetBottomBorderSize() const
3202 // they are all symmetric in mac themes
3203 return MacGetLeftBorderSize() ;
3206 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3208 return style
& ~wxBORDER_MASK
;
3211 // Find the wxWindowMac at the current mouse position, returning the mouse
3213 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3215 pt
= wxGetMousePosition();
3216 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3221 // Get the current mouse position.
3222 wxPoint
wxGetMousePosition()
3226 wxGetMousePosition( &x
, &y
);
3228 return wxPoint(x
, y
);
3231 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3233 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3235 // copied from wxGTK : CS
3236 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3239 // (a) it's a command event and so is propagated to the parent
3240 // (b) under MSW it can be generated from kbd too
3241 // (c) it uses screen coords (because of (a))
3242 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3244 this->ClientToScreen(event
.GetPosition()));
3245 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3254 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3256 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3257 CallNextEventHandler(
3258 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3259 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3262 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3266 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3270 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3271 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3276 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3278 return eventNotHandledErr
;
3281 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3283 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3285 if ( !wxWindowBase::Reparent(newParent
) )
3288 // copied from MacPostControlCreate
3289 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3291 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3293 ::EmbedControl( m_peer
->GetControlRef() , container
) ;