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
) ;
477 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
481 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
483 #if !TARGET_API_MAC_OSX
485 // ---------------------------------------------------------------------------
486 // UserPane events for non OSX builds
487 // ---------------------------------------------------------------------------
489 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
491 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
493 win
->MacControlUserPaneDrawProc(part
) ;
495 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
497 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
499 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
501 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
503 return kControlNoPart
;
505 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
507 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
509 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
511 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
513 return kControlNoPart
;
515 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
517 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
519 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
521 win
->MacControlUserPaneIdleProc() ;
523 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
525 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
527 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
529 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
531 return kControlNoPart
;
533 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
535 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
537 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
539 win
->MacControlUserPaneActivateProc(activating
) ;
541 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
543 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
545 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
547 return win
->MacControlUserPaneFocusProc(action
) ;
549 return kControlNoPart
;
551 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
553 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
555 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
557 win
->MacControlUserPaneBackgroundProc(info
) ;
559 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
561 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
563 RgnHandle rgn
= NewRgn() ;
566 MacWindowToRootWindow( &x
,&y
) ;
567 OffsetRgn( rgn
, -x
, -y
) ;
568 wxMacWindowStateSaver
sv( this ) ;
569 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
570 MacDoRedraw( rgn
, 0 ) ;
574 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
576 return kControlNoPart
;
579 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
581 return kControlNoPart
;
584 void wxWindowMac::MacControlUserPaneIdleProc()
588 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
590 return kControlNoPart
;
593 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
597 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
599 return kControlNoPart
;
602 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
608 // ---------------------------------------------------------------------------
609 // Scrollbar Tracking for all
610 // ---------------------------------------------------------------------------
612 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
613 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
617 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
620 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
624 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
626 // ===========================================================================
628 // ===========================================================================
630 #if KEY_wxList_DEPRECATED
631 wxList
wxWinMacControlList(wxKEY_INTEGER
);
633 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
635 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
638 return (wxControl
*)node
->GetData();
641 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
643 // adding NULL ControlRef is (first) surely a result of an error and
644 // (secondly) breaks native event processing
645 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
647 if ( !wxWinMacControlList
.Find((long)inControl
) )
648 wxWinMacControlList
.Append((long)inControl
, control
);
651 void wxRemoveMacControlAssociation(wxWindow
*control
)
653 // remove all associations pointing to us
654 while ( wxWinMacControlList
.DeleteObject(control
) )
659 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
661 static MacControlMap wxWinMacControlList
;
663 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
665 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
667 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
670 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
672 // adding NULL ControlRef is (first) surely a result of an error and
673 // (secondly) breaks native event processing
674 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
676 wxWinMacControlList
[inControl
] = control
;
679 void wxRemoveMacControlAssociation(wxWindow
*control
)
681 // iterate over all the elements in the class
682 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
683 // we should go on...
689 MacControlMap::iterator it
;
690 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
692 if ( it
->second
== control
)
694 wxWinMacControlList
.erase(it
);
701 #endif // deprecated wxList
703 // ----------------------------------------------------------------------------
704 // constructors and such
705 // ----------------------------------------------------------------------------
707 wxWindowMac::wxWindowMac()
712 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
717 const wxString
& name
)
720 Create(parent
, id
, pos
, size
, style
, name
);
723 void wxWindowMac::Init()
727 #if WXWIN_COMPATIBILITY_2_4
728 m_backgroundTransparent
= FALSE
;
731 // as all windows are created with WS_VISIBLE style...
734 m_hScrollBar
= NULL
;
735 m_vScrollBar
= NULL
;
736 m_macBackgroundBrush
= wxNullBrush
;
738 m_macIsUserPane
= TRUE
;
739 #if wxMAC_USE_CORE_GRAPHICS
740 m_cgContextRef
= NULL
;
742 m_clipChildren
= false ;
743 m_cachedClippedRectValid
= false ;
744 // we need a valid font for the encodings
745 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
749 wxWindowMac::~wxWindowMac()
753 m_isBeingDeleted
= TRUE
;
755 MacInvalidateBorders() ;
757 #ifndef __WXUNIVERSAL__
758 // VS: make sure there's no wxFrame with last focus set to us:
759 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
761 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
764 if ( frame
->GetLastFocus() == this )
766 frame
->SetLastFocus((wxWindow
*)NULL
);
771 #endif // __WXUNIVERSAL__
773 // destroy children before destroying this window itself
776 // wxRemoveMacControlAssociation( this ) ;
777 // If we delete an item, we should initialize the parent panel,
778 // because it could now be invalid.
779 wxWindow
*parent
= GetParent() ;
782 if (parent
->GetDefaultItem() == (wxButton
*) this)
783 parent
->SetDefaultItem(NULL
);
785 if ( m_peer
&& m_peer
->Ok() )
787 // in case the callback might be called during destruction
788 wxRemoveMacControlAssociation( this) ;
789 // we currently are not using this hook
790 // ::SetControlColorProc( *m_peer , NULL ) ;
794 if ( g_MacLastWindow
== this )
796 g_MacLastWindow
= NULL
;
799 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
802 if ( frame
->GetLastFocus() == this )
803 frame
->SetLastFocus( NULL
) ;
806 // delete our drop target if we've got one
807 #if wxUSE_DRAG_AND_DROP
808 if ( m_dropTarget
!= NULL
)
813 #endif // wxUSE_DRAG_AND_DROP
817 WXWidget
wxWindowMac::GetHandle() const
819 return (WXWidget
) m_peer
->GetControlRef() ;
823 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
825 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
826 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
827 GetEventTypeCount(eventList
), eventList
, this,
828 (EventHandlerRef
*)&m_macControlEventHandler
);
829 #if !TARGET_API_MAC_OSX
830 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
832 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
833 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
834 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
835 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
836 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
837 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
838 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
839 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
846 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
850 const wxString
& name
)
852 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
854 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
857 m_windowVariant
= parent
->GetWindowVariant() ;
859 if ( m_macIsUserPane
)
861 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
864 | kControlSupportsEmbedding
865 | kControlSupportsLiveFeedback
866 | kControlGetsFocusOnClick
867 // | kControlHasSpecialBackground
868 // | kControlSupportsCalcBestRect
869 | kControlHandlesTracking
870 | kControlSupportsFocus
871 | kControlWantsActivate
875 m_peer
= new wxMacControl(this) ;
876 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
879 MacPostControlCreate(pos
,size
) ;
881 #ifndef __WXUNIVERSAL__
882 // Don't give scrollbars to wxControls unless they ask for them
883 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
884 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
886 MacCreateScrollBars( style
) ;
890 wxWindowCreateEvent
event(this);
891 GetEventHandler()->AddPendingEvent(event
);
896 void wxWindowMac::MacChildAdded()
900 m_vScrollBar
->Raise() ;
904 m_hScrollBar
->Raise() ;
909 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
911 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
913 m_peer
->SetReference( (long) this ) ;
914 GetParent()->AddChild(this);
916 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
918 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
919 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
920 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
921 GetParent()->MacChildAdded() ;
923 // adjust font, controlsize etc
924 DoSetWindowVariant( m_windowVariant
) ;
926 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
928 if (!m_macIsUserPane
)
930 SetInitialBestSize(size
);
933 SetCursor( *wxSTANDARD_CURSOR
) ;
936 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
938 // Don't assert, in case we set the window variant before
939 // the window is created
940 // wxASSERT( m_peer->Ok() ) ;
942 m_windowVariant
= variant
;
944 if (m_peer
== NULL
|| !m_peer
->Ok())
948 ThemeFontID themeFont
= kThemeSystemFont
;
950 // we will get that from the settings later
951 // and make this NORMAL later, but first
952 // we have a few calculations that we must fix
956 case wxWINDOW_VARIANT_NORMAL
:
957 size
= kControlSizeNormal
;
958 themeFont
= kThemeSystemFont
;
960 case wxWINDOW_VARIANT_SMALL
:
961 size
= kControlSizeSmall
;
962 themeFont
= kThemeSmallSystemFont
;
964 case wxWINDOW_VARIANT_MINI
:
965 if (UMAGetSystemVersion() >= 0x1030 )
967 // not always defined in the headers
973 size
= kControlSizeSmall
;
974 themeFont
= kThemeSmallSystemFont
;
977 case wxWINDOW_VARIANT_LARGE
:
978 size
= kControlSizeLarge
;
979 themeFont
= kThemeSystemFont
;
982 wxFAIL_MSG(_T("unexpected window variant"));
985 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
988 font
.MacCreateThemeFont( themeFont
) ;
992 void wxWindowMac::MacUpdateControlFont()
994 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
998 bool wxWindowMac::SetFont(const wxFont
& font
)
1000 bool retval
= wxWindowBase::SetFont( font
) ;
1002 MacUpdateControlFont() ;
1007 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1009 if ( !wxWindowBase::SetForegroundColour(col
) )
1012 MacUpdateControlFont() ;
1017 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1019 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1023 wxColour
newCol(GetBackgroundColour());
1024 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1026 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1028 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1030 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1034 brush
.SetColour( newCol
) ;
1036 MacSetBackgroundBrush( brush
) ;
1038 MacUpdateControlFont() ;
1043 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1045 m_macBackgroundBrush
= brush
;
1046 m_peer
->SetBackground( brush
) ;
1049 bool wxWindowMac::MacCanFocus() const
1051 // there is currently no way to determine whether the window is running in full keyboard
1052 // access mode, therefore we cannot rely on these features, yet the only other way would be
1053 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1054 // in event handlers...
1055 UInt32 features
= 0 ;
1056 m_peer
->GetFeatures( & features
) ;
1057 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1061 void wxWindowMac::SetFocus()
1063 if ( AcceptsFocus() )
1066 wxWindow
* former
= FindFocus() ;
1067 if ( former
== this )
1070 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1071 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1072 // leave in case of an error
1073 if ( err
== errCouldntSetFocus
)
1076 #if !TARGET_API_MAC_OSX
1077 // emulate carbon events when running under carbonlib where they are not natively available
1080 EventRef evRef
= NULL
;
1081 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1084 wxMacCarbonEvent
cEvent( evRef
) ;
1085 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1086 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1088 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1089 ReleaseEvent(evRef
) ;
1091 // send new focus event
1093 EventRef evRef
= NULL
;
1094 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1097 wxMacCarbonEvent
cEvent( evRef
) ;
1098 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1099 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1101 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1102 ReleaseEvent(evRef
) ;
1109 void wxWindowMac::DoCaptureMouse()
1111 wxApp::s_captureWindow
= this ;
1114 wxWindow
* wxWindowBase::GetCapture()
1116 return wxApp::s_captureWindow
;
1119 void wxWindowMac::DoReleaseMouse()
1121 wxApp::s_captureWindow
= NULL
;
1124 #if wxUSE_DRAG_AND_DROP
1126 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1128 if ( m_dropTarget
!= 0 ) {
1129 delete m_dropTarget
;
1132 m_dropTarget
= pDropTarget
;
1133 if ( m_dropTarget
!= 0 )
1141 // Old style file-manager drag&drop
1142 void wxWindowMac::DragAcceptFiles(bool accept
)
1147 // Returns the size of the native control. In the case of the toplevel window
1148 // this is the content area root control
1150 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1151 int& w
, int& h
) const
1153 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1156 // From a wx position / size calculate the appropriate size of the native control
1158 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1161 int& w
, int& h
, bool adjustOrigin
) const
1163 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1165 // the desired size, minus the border pixels gives the correct size of the control
1169 // todo the default calls may be used as soon as PostCreateControl Is moved here
1170 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1171 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1173 if ( !isCompositing
)
1174 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1176 x
+= MacGetLeftBorderSize() ;
1177 y
+= MacGetTopBorderSize() ;
1178 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1179 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1182 AdjustForParentClientOrigin( x
, y
) ;
1184 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1185 if ( !GetParent()->IsTopLevel() )
1187 x
-= GetParent()->MacGetLeftBorderSize() ;
1188 y
-= GetParent()->MacGetTopBorderSize() ;
1194 // Get window size (not client size)
1195 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1198 m_peer
->GetRect( &bounds
) ;
1200 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1201 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1204 // get the position of the bounds of this window in client coordinates of its parent
1205 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1208 m_peer
->GetRect( &bounds
) ;
1210 int x1
= bounds
.left
;
1211 int y1
= bounds
.top
;
1213 // get the wx window position from the native one
1214 x1
-= MacGetLeftBorderSize() ;
1215 y1
-= MacGetTopBorderSize() ;
1217 if ( !IsTopLevel() )
1219 wxWindow
*parent
= GetParent();
1222 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1223 x1
+= parent
->MacGetLeftBorderSize() ;
1224 y1
+= parent
->MacGetTopBorderSize() ;
1225 // and now to client coordinates
1226 wxPoint
pt(parent
->GetClientAreaOrigin());
1235 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1237 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1239 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1242 Point localwhere
= {0,0} ;
1244 if(x
) localwhere
.h
= * x
;
1245 if(y
) localwhere
.v
= * y
;
1247 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1248 if(x
) *x
= localwhere
.h
;
1249 if(y
) *y
= localwhere
.v
;
1252 MacRootWindowToWindow( x
, y
) ;
1254 wxPoint origin
= GetClientAreaOrigin() ;
1255 if(x
) *x
-= origin
.x
;
1256 if(y
) *y
-= origin
.y
;
1259 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1261 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1262 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1264 wxPoint origin
= GetClientAreaOrigin() ;
1265 if(x
) *x
+= origin
.x
;
1266 if(y
) *y
+= origin
.y
;
1268 MacWindowToRootWindow( x
, y
) ;
1271 Point localwhere
= { 0,0 };
1272 if(x
) localwhere
.h
= * x
;
1273 if(y
) localwhere
.v
= * y
;
1274 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1275 if(x
) *x
= localwhere
.h
;
1276 if(y
) *y
= localwhere
.v
;
1280 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1282 wxPoint origin
= GetClientAreaOrigin() ;
1283 if(x
) *x
+= origin
.x
;
1284 if(y
) *y
+= origin
.y
;
1286 MacWindowToRootWindow( x
, y
) ;
1289 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1291 MacRootWindowToWindow( x
, y
) ;
1293 wxPoint origin
= GetClientAreaOrigin() ;
1294 if(x
) *x
-= origin
.x
;
1295 if(y
) *y
-= origin
.y
;
1298 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1301 if ( x
) pt
.x
= *x
;
1302 if ( y
) pt
.y
= *y
;
1304 if ( !IsTopLevel() )
1306 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1309 pt
.x
-= MacGetLeftBorderSize() ;
1310 pt
.y
-= MacGetTopBorderSize() ;
1311 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1315 if ( x
) *x
= (int) pt
.x
;
1316 if ( y
) *y
= (int) pt
.y
;
1319 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1324 MacWindowToRootWindow( &x1
, &y1
) ;
1329 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1332 if ( x
) pt
.x
= *x
;
1333 if ( y
) pt
.y
= *y
;
1335 if ( !IsTopLevel() )
1337 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1340 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1341 pt
.x
+= MacGetLeftBorderSize() ;
1342 pt
.y
+= MacGetTopBorderSize() ;
1346 if ( x
) *x
= (int) pt
.x
;
1347 if ( y
) *y
= (int) pt
.y
;
1350 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1355 MacRootWindowToWindow( &x1
, &y1
) ;
1360 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1362 RgnHandle rgn
= NewRgn() ;
1363 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1367 GetRegionBounds( rgn
, &content
) ;
1368 m_peer
->GetRect( &structure
) ;
1369 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1371 left
= content
.left
- structure
.left
;
1372 top
= content
.top
- structure
.top
;
1373 right
= structure
.right
- content
.right
;
1374 bottom
= structure
.bottom
- content
.bottom
;
1378 left
= top
= right
= bottom
= 0 ;
1383 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1385 wxSize sizeTotal
= size
;
1387 RgnHandle rgn
= NewRgn() ;
1389 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1393 GetRegionBounds( rgn
, &content
) ;
1395 m_peer
->GetRect( &structure
) ;
1396 // structure is in parent coordinates, but we only need width and height, so it's ok
1398 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1399 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1403 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1404 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1410 // Get size *available for subwindows* i.e. excluding menu bar etc.
1411 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1415 RgnHandle rgn
= NewRgn() ;
1417 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1419 GetRegionBounds( rgn
, &content
) ;
1423 m_peer
->GetRect( &content
) ;
1427 ww
= content
.right
- content
.left
;
1428 hh
= content
.bottom
- content
.top
;
1430 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1432 hh
-= m_hScrollBar
->GetSize().y
;
1434 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1436 ww
-= m_vScrollBar
->GetSize().x
;
1443 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1445 if (m_cursor
== cursor
)
1448 if (wxNullCursor
== cursor
)
1450 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1455 if ( ! wxWindowBase::SetCursor( cursor
) )
1459 wxASSERT_MSG( m_cursor
.Ok(),
1460 wxT("cursor must be valid after call to the base version"));
1463 wxWindowMac
*mouseWin
= 0 ;
1465 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1466 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1468 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1470 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1471 // position, use it...
1475 ControlPartCode part
;
1476 ControlRef control
;
1477 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1479 mouseWin
= wxFindControlFromMacControl( control
) ;
1482 QDSwapPort( savePort
, NULL
) ;
1485 if ( mouseWin
== this && !wxIsBusy() )
1487 m_cursor
.MacInstall() ;
1494 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1496 menu
->SetInvokingWindow(this);
1499 if ( x
== -1 && y
== -1 )
1501 wxPoint mouse
= wxGetMousePosition();
1502 x
= mouse
.x
; y
= mouse
.y
;
1506 ClientToScreen( &x
, &y
) ;
1509 menu
->MacBeforeDisplay( true ) ;
1510 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1511 if ( HiWord(menuResult
) != 0 )
1514 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1515 wxMenuItem
* item
= NULL
;
1517 item
= menu
->FindItem(id
, &realmenu
) ;
1518 if (item
->IsCheckable())
1520 item
->Check( !item
->IsChecked() ) ;
1522 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1524 menu
->MacAfterDisplay( true ) ;
1526 menu
->SetInvokingWindow(NULL
);
1532 // ----------------------------------------------------------------------------
1534 // ----------------------------------------------------------------------------
1538 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1540 wxWindowBase::DoSetToolTip(tooltip
);
1543 m_tooltip
->SetWindow(this);
1546 #endif // wxUSE_TOOLTIPS
1548 void wxWindowMac::MacInvalidateBorders()
1550 if ( m_peer
== NULL
)
1553 bool vis
= MacIsReallyShown() ;
1557 int outerBorder
= MacGetLeftBorderSize() ;
1558 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1561 if ( outerBorder
== 0 )
1564 // now we know that we have something to do at all
1566 // as the borders are drawn on the parent we have to properly invalidate all these areas
1567 RgnHandle updateInner
= NewRgn() ,
1568 updateOuter
= NewRgn() ;
1570 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1572 m_peer
->GetRect( &rect
) ;
1573 RectRgn( updateInner
, &rect
) ;
1574 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1575 RectRgn( updateOuter
, &rect
) ;
1576 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1577 #ifdef __WXMAC_OSX__
1578 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1580 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1582 InvalWindowRgn( tlw
, updateOuter
) ;
1584 DisposeRgn(updateOuter
) ;
1585 DisposeRgn(updateInner
) ;
1587 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1588 RectRgn( updateInner , &rect ) ;
1589 InsetRect( &rect , -4 , -4 ) ;
1590 RectRgn( updateOuter , &rect ) ;
1591 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1592 wxPoint parent(0,0);
1593 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1594 parent -= GetParent()->GetClientAreaOrigin() ;
1595 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1596 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1597 DisposeRgn(updateOuter) ;
1598 DisposeRgn(updateInner) ;
1603 // deleting a window while it is shown invalidates the region occupied by border or
1606 if ( IsShown() && ( outerBorder > 0 ) )
1608 // as the borders are drawn on the parent we have to properly invalidate all these areas
1609 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1613 m_peer->GetRect( &rect ) ;
1614 RectRgn( updateInner , &rect ) ;
1615 InsetRect( &rect , -outerBorder , -outerBorder ) ;
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 CopyRgn( updateOuter , updateTotal ) ;
1624 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1625 DisposeRgn(updateOuter) ;
1626 DisposeRgn(updateInner) ;
1627 DisposeRgn(updateTotal) ;
1632 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1634 int outerBorder
= MacGetLeftBorderSize() ;
1635 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1638 if ( vis
&& ( outerBorder
> 0 ) )
1640 // as the borders are drawn on the parent we have to properly invalidate all these areas
1641 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1645 m_peer
->GetRect( &rect
) ;
1646 RectRgn( updateInner
, &rect
) ;
1647 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1648 RectRgn( updateOuter
, &rect
) ;
1649 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1651 wxPoint parent(0,0);
1652 #if TARGET_API_MAC_OSX
1653 // no offsetting needed when compositing
1655 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1656 parent -= GetParent()->GetClientAreaOrigin() ;
1657 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1660 CopyRgn( updateOuter
, updateTotal
) ;
1663 RectRgn( updateInner
, &rect
) ;
1664 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1665 RectRgn( updateOuter
, &rect
) ;
1666 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1668 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1670 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1672 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1673 DisposeRgn(updateOuter
) ;
1674 DisposeRgn(updateInner
) ;
1675 DisposeRgn(updateTotal
) ;
1680 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1682 // this is never called for a toplevel window, so we know we have a parent
1683 int former_x
, former_y
, former_w
, former_h
;
1685 // Get true coordinates of former position
1686 DoGetPosition( &former_x
, &former_y
) ;
1687 DoGetSize( &former_w
, &former_h
) ;
1689 wxWindow
*parent
= GetParent();
1692 wxPoint
pt(parent
->GetClientAreaOrigin());
1697 int actualWidth
= width
;
1698 int actualHeight
= height
;
1702 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1703 actualWidth
= m_minWidth
;
1704 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1705 actualHeight
= m_minHeight
;
1706 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1707 actualWidth
= m_maxWidth
;
1708 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1709 actualHeight
= m_maxHeight
;
1711 bool doMove
= false ;
1712 bool doResize
= false ;
1714 if ( actualX
!= former_x
|| actualY
!= former_y
)
1718 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1723 if ( doMove
|| doResize
)
1725 // as the borders are drawn outside the native control, we adjust now
1727 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1728 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1729 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1732 wxMacRectToNative( &bounds
, &r
) ;
1734 if ( !GetParent()->IsTopLevel() )
1736 wxMacWindowToNative( GetParent() , &r
) ;
1739 MacInvalidateBorders() ;
1741 m_cachedClippedRectValid
= false ;
1742 m_peer
->SetRect( &r
) ;
1744 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1746 MacInvalidateBorders() ;
1748 MacRepositionScrollBars() ;
1751 wxPoint
point(actualX
,actualY
);
1752 wxMoveEvent
event(point
, m_windowId
);
1753 event
.SetEventObject(this);
1754 GetEventHandler()->ProcessEvent(event
) ;
1758 MacRepositionScrollBars() ;
1759 wxSize
size(actualWidth
, actualHeight
);
1760 wxSizeEvent
event(size
, m_windowId
);
1761 event
.SetEventObject(this);
1762 GetEventHandler()->ProcessEvent(event
);
1768 wxSize
wxWindowMac::DoGetBestSize() const
1770 if ( m_macIsUserPane
|| IsTopLevel() )
1771 return wxWindowBase::DoGetBestSize() ;
1773 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1774 int bestWidth
, bestHeight
;
1775 m_peer
->GetBestRect( &bestsize
) ;
1777 if ( EmptyRect( &bestsize
) )
1779 bestsize
.left
= bestsize
.top
= 0 ;
1780 bestsize
.right
= 16 ;
1781 bestsize
.bottom
= 16 ;
1782 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1784 bestsize
.bottom
= 16 ;
1787 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1789 bestsize
.bottom
= 24 ;
1791 #endif // wxUSE_SPINBTN
1794 // return wxWindowBase::DoGetBestSize() ;
1798 bestWidth
= bestsize
.right
- bestsize
.left
;
1799 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1800 if ( bestHeight
< 10 )
1803 return wxSize(bestWidth
, bestHeight
);
1807 // set the size of the window: if the dimensions are positive, just use them,
1808 // but if any of them is equal to -1, it means that we must find the value for
1809 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1810 // which case -1 is a valid value for x and y)
1812 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1813 // the width/height to best suit our contents, otherwise we reuse the current
1815 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1817 // get the current size and position...
1818 int currentX
, currentY
;
1819 GetPosition(¤tX
, ¤tY
);
1821 int currentW
,currentH
;
1822 GetSize(¤tW
, ¤tH
);
1824 // ... and don't do anything (avoiding flicker) if it's already ok
1825 if ( x
== currentX
&& y
== currentY
&&
1826 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1829 MacRepositionScrollBars() ; // we might have a real position shift
1833 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1835 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1838 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1840 wxSize
size(-1, -1);
1843 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1845 size
= DoGetBestSize();
1850 // just take the current one
1857 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1861 size
= DoGetBestSize();
1863 //else: already called DoGetBestSize() above
1869 // just take the current one
1874 DoMoveWindow(x
, y
, width
, height
);
1878 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1880 RgnHandle rgn
= NewRgn() ;
1882 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1884 GetRegionBounds( rgn
, &content
) ;
1888 content
.left
= content
.top
= 0 ;
1891 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1894 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1896 if ( clientheight
!= -1 || clientheight
!= -1 )
1898 int currentclientwidth
, currentclientheight
;
1899 int currentwidth
, currentheight
;
1901 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1902 GetSize( ¤twidth
, ¤theight
) ;
1904 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1905 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1909 void wxWindowMac::SetTitle(const wxString
& title
)
1911 m_label
= wxStripMenuCodes(title
) ;
1913 if ( m_peer
&& m_peer
->Ok() )
1915 m_peer
->SetTitle( m_label
) ;
1920 wxString
wxWindowMac::GetTitle() const
1925 bool wxWindowMac::Show(bool show
)
1927 bool former
= MacIsReallyShown() ;
1928 if ( !wxWindowBase::Show(show
) )
1931 // TODO use visibilityChanged Carbon Event for OSX
1934 m_peer
->SetVisibility( show
, true ) ;
1936 if ( former
!= MacIsReallyShown() )
1937 MacPropagateVisibilityChanged() ;
1941 bool wxWindowMac::Enable(bool enable
)
1943 wxASSERT( m_peer
->Ok() ) ;
1944 bool former
= MacIsReallyEnabled() ;
1945 if ( !wxWindowBase::Enable(enable
) )
1948 m_peer
->Enable( enable
) ;
1950 if ( former
!= MacIsReallyEnabled() )
1951 MacPropagateEnabledStateChanged() ;
1956 // status change propagations (will be not necessary for OSX later )
1959 void wxWindowMac::MacPropagateVisibilityChanged()
1961 #if !TARGET_API_MAC_OSX
1962 MacVisibilityChanged() ;
1964 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1967 wxWindowMac
*child
= node
->GetData();
1968 if ( child
->IsShown() )
1969 child
->MacPropagateVisibilityChanged( ) ;
1970 node
= node
->GetNext();
1975 void wxWindowMac::MacPropagateEnabledStateChanged( )
1977 #if !TARGET_API_MAC_OSX
1978 MacEnabledStateChanged() ;
1980 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1983 wxWindowMac
*child
= node
->GetData();
1984 if ( child
->IsEnabled() )
1985 child
->MacPropagateEnabledStateChanged() ;
1986 node
= node
->GetNext();
1991 void wxWindowMac::MacPropagateHiliteChanged( )
1993 #if !TARGET_API_MAC_OSX
1994 MacHiliteChanged() ;
1996 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1999 wxWindowMac
*child
= node
->GetData();
2000 // if ( child->IsEnabled() )
2001 child
->MacPropagateHiliteChanged() ;
2002 node
= node
->GetNext();
2008 // status change notifications
2011 void wxWindowMac::MacVisibilityChanged()
2015 void wxWindowMac::MacHiliteChanged()
2019 void wxWindowMac::MacEnabledStateChanged()
2024 // status queries on the inherited window's state
2027 bool wxWindowMac::MacIsReallyShown()
2029 // only under OSX the visibility of the TLW is taken into account
2030 if ( m_isBeingDeleted
)
2033 #if TARGET_API_MAC_OSX
2034 if ( m_peer
&& m_peer
->Ok() )
2035 return m_peer
->IsVisible();
2037 wxWindow
* win
= this ;
2038 while( win
->IsShown() )
2040 if ( win
->IsTopLevel() )
2043 win
= win
->GetParent() ;
2051 bool wxWindowMac::MacIsReallyEnabled()
2053 return m_peer
->IsEnabled() ;
2056 bool wxWindowMac::MacIsReallyHilited()
2058 return m_peer
->IsActive();
2061 void wxWindowMac::MacFlashInvalidAreas()
2063 #if TARGET_API_MAC_OSX
2064 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2072 int wxWindowMac::GetCharHeight() const
2074 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2075 return dc
.GetCharHeight() ;
2078 int wxWindowMac::GetCharWidth() const
2080 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2081 return dc
.GetCharWidth() ;
2084 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2085 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2087 const wxFont
*fontToUse
= theFont
;
2089 fontToUse
= &m_font
;
2091 wxClientDC
dc( (wxWindowMac
*) this ) ;
2093 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2094 if ( externalLeading
)
2095 *externalLeading
= le
;
2105 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2106 * we always intersect with the entire window, not only with the client area
2109 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2111 if ( m_peer
== NULL
)
2114 if ( !MacIsReallyShown() )
2120 wxMacRectToNative( rect
, &r
) ;
2121 m_peer
->SetNeedsDisplay( &r
) ;
2125 m_peer
->SetNeedsDisplay() ;
2129 void wxWindowMac::Freeze()
2131 #if TARGET_API_MAC_OSX
2132 if ( !m_frozenness
++ )
2134 if ( m_peer
&& m_peer
->Ok() )
2135 m_peer
->SetDrawingEnabled( false ) ;
2141 void wxWindowMac::Thaw()
2143 #if TARGET_API_MAC_OSX
2144 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2146 if ( !--m_frozenness
)
2148 if ( m_peer
&& m_peer
->Ok() )
2150 m_peer
->SetDrawingEnabled( true ) ;
2151 m_peer
->InvalidateWithChildren() ;
2157 wxWindowMac
*wxGetActiveWindow()
2159 // actually this is a windows-only concept
2163 // Coordinates relative to the window
2164 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2166 // We really don't move the mouse programmatically under Mac.
2169 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2171 #if TARGET_API_MAC_OSX
2172 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2179 event
.GetDC()->Clear() ;
2183 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2188 int wxWindowMac::GetScrollPos(int orient
) const
2190 if ( orient
== wxHORIZONTAL
)
2193 return m_hScrollBar
->GetThumbPosition() ;
2198 return m_vScrollBar
->GetThumbPosition() ;
2203 // This now returns the whole range, not just the number
2204 // of positions that we can scroll.
2205 int wxWindowMac::GetScrollRange(int orient
) const
2207 if ( orient
== wxHORIZONTAL
)
2210 return m_hScrollBar
->GetRange() ;
2215 return m_vScrollBar
->GetRange() ;
2220 int wxWindowMac::GetScrollThumb(int orient
) const
2222 if ( orient
== wxHORIZONTAL
)
2225 return m_hScrollBar
->GetThumbSize() ;
2230 return m_vScrollBar
->GetThumbSize() ;
2235 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2237 if ( orient
== wxHORIZONTAL
)
2240 m_hScrollBar
->SetThumbPosition( pos
) ;
2245 m_vScrollBar
->SetThumbPosition( pos
) ;
2250 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2251 // our own window origin is at leftOrigin/rightOrigin
2254 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2260 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2261 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2263 m_peer
->GetRect( &rect
) ;
2264 // back to the surrounding frame rectangle
2265 InsetRect( &rect
, -1 , -1 ) ;
2267 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2268 if ( UMAGetSystemVersion() >= 0x1030 )
2270 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2271 rect
.bottom
- rect
.top
) ;
2273 HIThemeFrameDrawInfo info
;
2274 memset( &info
, 0 , sizeof( info
) ) ;
2278 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2279 info
.isFocused
= hasFocus
;
2281 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2282 wxASSERT( cgContext
) ;
2284 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2286 info
.kind
= kHIThemeFrameTextFieldSquare
;
2287 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2289 else if (HasFlag(wxSIMPLE_BORDER
))
2291 info
.kind
= kHIThemeFrameListBox
;
2292 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2294 else if ( hasFocus
)
2296 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2299 m_peer
->GetRect( &rect
) ;
2300 if ( hasBothScrollbars
)
2302 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2303 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2304 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2305 HIThemeGrowBoxDrawInfo info
;
2306 memset( &info
, 0 , sizeof( info
) ) ;
2308 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2309 info
.kind
= kHIThemeGrowBoxKindNone
;
2310 info
.size
= kHIThemeGrowBoxSizeNormal
;
2311 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2312 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2318 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2322 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2323 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2326 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2328 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2330 else if (HasFlag(wxSIMPLE_BORDER
))
2332 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2337 DrawThemeFocusRect( &rect
, true ) ;
2340 if ( hasBothScrollbars
)
2342 // GetThemeStandaloneGrowBoxBounds
2343 //DrawThemeStandaloneNoGrowBox
2348 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2350 if ( child
== m_hScrollBar
)
2351 m_hScrollBar
= NULL
;
2352 if ( child
== m_vScrollBar
)
2353 m_vScrollBar
= NULL
;
2355 wxWindowBase::RemoveChild( child
) ;
2358 // New function that will replace some of the above.
2359 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2360 int range
, bool refresh
)
2362 if ( orient
== wxHORIZONTAL
)
2366 if ( range
== 0 || thumbVisible
>= range
)
2368 if ( m_hScrollBar
->IsShown() )
2369 m_hScrollBar
->Show(false) ;
2373 if ( !m_hScrollBar
->IsShown() )
2374 m_hScrollBar
->Show(true) ;
2376 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2383 if ( range
== 0 || thumbVisible
>= range
)
2385 if ( m_vScrollBar
->IsShown() )
2386 m_vScrollBar
->Show(false) ;
2390 if ( !m_vScrollBar
->IsShown() )
2391 m_vScrollBar
->Show(true) ;
2393 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2396 MacRepositionScrollBars() ;
2399 // Does a physical scroll
2400 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2402 if( dx
== 0 && dy
==0 )
2405 int width
, height
;
2406 GetClientSize( &width
, &height
) ;
2407 #if TARGET_API_MAC_OSX
2408 if ( 1 /* m_peer->IsCompositing() */ )
2410 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2411 // area is scrolled, this does not occur if width and height are 2 pixels less,
2412 // TODO write optimal workaround
2413 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2416 scrollrect
.Intersect( *rect
) ;
2418 if ( m_peer
->GetNeedsDisplay() )
2420 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2421 // either immediate redraw or full invalidate
2423 // is the better overall solution, as it does not slow down scrolling
2424 m_peer
->SetNeedsDisplay() ;
2426 // this would be the preferred version for fast drawing controls
2428 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2429 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2430 HIViewRender(m_peer
->GetControlRef()) ;
2436 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2437 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2438 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2440 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2441 // either immediate redraw or full invalidate
2443 // is the better overall solution, as it does not slow down scrolling
2444 m_peer
->SetNeedsDisplay() ;
2446 // this would be the preferred version for fast drawing controls
2448 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2449 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2450 HIViewRender(m_peer
->GetControlRef()) ;
2465 RgnHandle updateRgn
= NewRgn() ;
2468 wxClientDC
dc(this) ;
2469 wxMacPortSetter
helper(&dc
) ;
2471 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2472 //scrollrect.top += MacGetTopBorderSize() ;
2473 //scrollrect.left += MacGetLeftBorderSize() ;
2474 scrollrect
.bottom
= scrollrect
.top
+ height
;
2475 scrollrect
.right
= scrollrect
.left
+ width
;
2479 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2480 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2481 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2483 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2485 // now scroll the former update region as well and add the new update region
2487 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2488 RgnHandle formerUpdateRgn
= NewRgn() ;
2489 RgnHandle scrollRgn
= NewRgn() ;
2490 RectRgn( scrollRgn
, &scrollrect
) ;
2491 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2493 LocalToGlobal( &pt
) ;
2494 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2495 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2496 if ( !EmptyRgn( formerUpdateRgn
) )
2498 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2499 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2500 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2502 InvalWindowRgn(rootWindow
, updateRgn
) ;
2503 DisposeRgn( updateRgn
) ;
2504 DisposeRgn( formerUpdateRgn
) ;
2505 DisposeRgn( scrollRgn
) ;
2510 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2512 wxWindowMac
*child
= node
->GetData();
2513 if (child
== m_vScrollBar
) continue;
2514 if (child
== m_hScrollBar
) continue;
2515 if (child
->IsTopLevel()) continue;
2518 child
->GetPosition( &x
, &y
);
2520 child
->GetSize( &w
, &h
);
2524 if (rect
->Intersects(rc
))
2525 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2529 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2534 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2536 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2538 wxScrollWinEvent wevent
;
2539 wevent
.SetPosition(event
.GetPosition());
2540 wevent
.SetOrientation(event
.GetOrientation());
2541 wevent
.SetEventObject(this);
2543 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2544 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2545 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2546 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2547 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2548 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2549 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2550 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2551 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2552 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2553 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2554 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2555 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2556 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2557 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2558 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2560 GetEventHandler()->ProcessEvent(wevent
);
2564 // Get the window with the focus
2565 wxWindowMac
*wxWindowBase::DoFindFocus()
2567 ControlRef control
;
2568 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2569 return wxFindControlFromMacControl( control
) ;
2572 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2574 // panel wants to track the window which was the last to have focus in it,
2575 // so we want to set ourselves as the window which last had focus
2577 // notice that it's also important to do it upwards the tree becaus
2578 // otherwise when the top level panel gets focus, it won't set it back to
2579 // us, but to some other sibling
2581 // CS:don't know if this is still needed:
2582 //wxChildFocusEvent eventFocus(this);
2583 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2585 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2587 #if !wxMAC_USE_CORE_GRAPHICS
2588 wxMacWindowStateSaver
sv( this ) ;
2590 m_peer
->GetRect( &rect
) ;
2591 // auf den umgebenden Rahmen zur\9fck
2592 InsetRect( &rect
, -1 , -1 ) ;
2594 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2598 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2600 rect
.right
+= pt
.x
;
2602 rect
.bottom
+= pt
.y
;
2605 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2606 DrawThemeFocusRect( &rect
, true ) ;
2609 DrawThemeFocusRect( &rect
, false ) ;
2611 // as this erases part of the frame we have to redraw borders
2612 // and because our z-ordering is not always correct (staticboxes)
2613 // we have to invalidate things, we cannot simple redraw
2614 MacInvalidateBorders() ;
2617 GetParent()->Refresh() ;
2624 void wxWindowMac::OnInternalIdle()
2626 // This calls the UI-update mechanism (querying windows for
2627 // menu/toolbar/control state information)
2628 if (wxUpdateUIEvent::CanUpdate(this))
2629 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2632 // Raise the window to the top of the Z order
2633 void wxWindowMac::Raise()
2635 m_peer
->SetZOrder( true , NULL
) ;
2638 // Lower the window to the bottom of the Z order
2639 void wxWindowMac::Lower()
2641 m_peer
->SetZOrder( false , NULL
) ;
2645 // static wxWindow *gs_lastWhich = NULL;
2647 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2649 // first trigger a set cursor event
2651 wxPoint clientorigin
= GetClientAreaOrigin() ;
2652 wxSize clientsize
= GetClientSize() ;
2654 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2656 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2658 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2659 if ( processedEvtSetCursor
&& event
.HasCursor() )
2661 cursor
= event
.GetCursor() ;
2666 // the test for processedEvtSetCursor is here to prevent using m_cursor
2667 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2668 // it - this is a way to say that our cursor shouldn't be used for this
2670 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2680 cursor
= *wxSTANDARD_CURSOR
;
2684 cursor
.MacInstall() ;
2686 return cursor
.Ok() ;
2689 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2694 return m_tooltip
->GetTip() ;
2697 return wxEmptyString
;
2700 void wxWindowMac::ClearBackground()
2706 void wxWindowMac::Update()
2708 #if TARGET_API_MAC_OSX
2709 MacGetTopLevelWindow()->MacPerformUpdates() ;
2711 ::Draw1Control( m_peer
->GetControlRef() ) ;
2715 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2717 wxTopLevelWindowMac
* win
= NULL
;
2718 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2721 win
= wxFindWinFromMacWindow( window
) ;
2726 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2728 MacUpdateClippedRects() ;
2729 return m_cachedClippedClientRect
;
2732 const wxRect
& wxWindowMac::MacGetClippedRect() const
2734 MacUpdateClippedRects() ;
2735 return m_cachedClippedRect
;
2738 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2740 MacUpdateClippedRects() ;
2741 return m_cachedClippedRectWithOuterStructure
;
2744 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2746 static wxRegion emptyrgn
;
2747 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2749 MacUpdateClippedRects() ;
2750 if ( includeOuterStructures
)
2751 return m_cachedClippedRegionWithOuterStructure
;
2753 return m_cachedClippedRegion
;
2761 void wxWindowMac::MacUpdateClippedRects() const
2763 if ( m_cachedClippedRectValid
)
2766 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2767 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2768 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2769 // to add focus borders everywhere
2772 Rect rIncludingOuterStructures
;
2774 m_peer
->GetRect( &r
) ;
2775 r
.left
-= MacGetLeftBorderSize() ;
2776 r
.top
-= MacGetTopBorderSize() ;
2777 r
.bottom
+= MacGetBottomBorderSize() ;
2778 r
.right
+= MacGetRightBorderSize() ;
2785 rIncludingOuterStructures
= r
;
2786 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2788 wxRect cl
= GetClientRect() ;
2789 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2791 const wxWindow
* child
= this ;
2792 const wxWindow
* parent
= NULL
;
2793 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2798 if ( parent
->MacIsChildOfClientArea(child
) )
2800 size
= parent
->GetClientSize() ;
2801 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2807 // this will be true for scrollbars, toolbars etc.
2808 size
= parent
->GetSize() ;
2809 y
= parent
->MacGetTopBorderSize() ;
2810 x
= parent
->MacGetLeftBorderSize() ;
2811 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2812 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2815 parent
->MacWindowToRootWindow( &x
, &y
) ;
2816 MacRootWindowToWindow( &x
, &y
) ;
2818 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2820 // the wxwindow and client rects will always be clipped
2821 SectRect( &r
, &rparent
, &r
) ;
2822 SectRect( &rClient
, &rparent
, &rClient
) ;
2824 // the structure only at 'hard' borders
2825 if ( parent
->MacClipChildren() ||
2826 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2828 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2833 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2834 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2835 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2836 m_cachedClippedRectWithOuterStructure
= wxRect(
2837 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2838 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2839 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2841 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2842 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2843 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2845 m_cachedClippedRectValid
= true ;
2849 This function must not change the updatergn !
2851 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2853 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2854 bool handled
= false ;
2856 GetRegionBounds( updatergn
, &updatebounds
) ;
2858 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2860 if ( !EmptyRgn(updatergn
) )
2862 RgnHandle newupdate
= NewRgn() ;
2863 wxSize point
= GetClientSize() ;
2864 wxPoint origin
= GetClientAreaOrigin() ;
2865 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2866 SectRgn( newupdate
, updatergn
, newupdate
) ;
2868 // first send an erase event to the entire update area
2870 // for the toplevel window this really is the entire area
2871 // for all the others only their client area, otherwise they
2872 // might be drawing with full alpha and eg put blue into
2873 // the grow-box area of a scrolled window (scroll sample)
2874 wxDC
* dc
= new wxWindowDC(this);
2876 dc
->SetClippingRegion(wxRegion(updatergn
));
2878 dc
->SetClippingRegion(wxRegion(newupdate
));
2880 wxEraseEvent
eevent( GetId(), dc
);
2881 eevent
.SetEventObject( this );
2882 GetEventHandler()->ProcessEvent( eevent
);
2886 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2887 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2888 m_updateRegion
= newupdate
;
2889 DisposeRgn( newupdate
) ;
2891 if ( !m_updateRegion
.Empty() )
2893 // paint the window itself
2896 event
.SetTimestamp(time
);
2897 event
.SetEventObject(this);
2898 GetEventHandler()->ProcessEvent(event
);
2902 // now we cannot rely on having its borders drawn by a window itself, as it does not
2903 // get the updateRgn wide enough to always do so, so we do it from the parent
2904 // this would also be the place to draw any custom backgrounds for native controls
2905 // in Composited windowing
2906 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2908 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2910 wxWindowMac
*child
= node
->GetData();
2911 if (child
== m_vScrollBar
) continue;
2912 if (child
== m_hScrollBar
) continue;
2913 if (child
->IsTopLevel()) continue;
2914 if (!child
->IsShown()) continue;
2916 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2919 child
->GetPosition( &x
, &y
);
2921 child
->GetSize( &w
, &h
);
2922 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2923 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2924 InsetRect( &childRect
, -10 , -10) ;
2926 if ( RectInRgn( &childRect
, updatergn
) )
2929 // paint custom borders
2930 wxNcPaintEvent
eventNc( child
->GetId() );
2931 eventNc
.SetEventObject( child
);
2932 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2934 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2935 if ( UMAGetSystemVersion() >= 0x1030 )
2937 child
->MacPaintBorders(0,0) ;
2942 wxWindowDC
dc(this) ;
2943 dc
.SetClippingRegion(wxRegion(updatergn
));
2944 wxMacPortSetter
helper(&dc
) ;
2945 child
->MacPaintBorders(0,0) ;
2955 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2957 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2961 if ( iter
->IsTopLevel() )
2962 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2964 iter
= iter
->GetParent() ;
2966 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2970 void wxWindowMac::MacCreateScrollBars( long style
)
2972 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2974 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2976 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2977 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2978 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2979 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2981 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2982 variant
= wxWINDOW_VARIANT_SMALL
;
2985 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2987 GetClientSize( &width
, &height
) ;
2989 wxPoint
vPoint(width
-scrlsize
, 0) ;
2990 wxSize
vSize(scrlsize
, height
- adjust
) ;
2991 wxPoint
hPoint(0 , height
-scrlsize
) ;
2992 wxSize
hSize( width
- adjust
, scrlsize
) ;
2995 if ( style
& wxVSCROLL
)
2997 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2998 vSize
, wxVERTICAL
);
3001 if ( style
& wxHSCROLL
)
3003 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3004 hSize
, wxHORIZONTAL
);
3009 // because the create does not take into account the client area origin
3010 MacRepositionScrollBars() ; // we might have a real position shift
3013 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3015 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3021 void wxWindowMac::MacRepositionScrollBars()
3023 if ( !m_hScrollBar
&& !m_vScrollBar
)
3026 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3027 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3028 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3030 // get real client area
3034 GetSize( &width
, &height
) ;
3036 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3037 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3039 wxPoint
vPoint(width
-scrlsize
, 0) ;
3040 wxSize
vSize(scrlsize
, height
- adjust
) ;
3041 wxPoint
hPoint(0 , height
-scrlsize
) ;
3042 wxSize
hSize( width
- adjust
, scrlsize
) ;
3048 GetSize( &w , &h ) ;
3050 MacClientToRootWindow( &x , &y ) ;
3051 MacClientToRootWindow( &w , &h ) ;
3053 wxWindowMac *iter = (wxWindowMac*)this ;
3055 int totW = 10000 , totH = 10000;
3058 if ( iter->IsTopLevel() )
3060 iter->GetSize( &totW , &totH ) ;
3064 iter = iter->GetParent() ;
3092 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3096 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3100 bool wxWindowMac::AcceptsFocus() const
3102 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3105 void wxWindowMac::MacSuperChangedPosition()
3107 m_cachedClippedRectValid
= false ;
3108 // only window-absolute structures have to be moved i.e. controls
3110 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3113 wxWindowMac
*child
= node
->GetData();
3114 child
->MacSuperChangedPosition() ;
3115 node
= node
->GetNext();
3119 void wxWindowMac::MacTopLevelWindowChangedPosition()
3121 // only screen-absolute structures have to be moved i.e. glcanvas
3123 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3126 wxWindowMac
*child
= node
->GetData();
3127 child
->MacTopLevelWindowChangedPosition() ;
3128 node
= node
->GetNext();
3132 long wxWindowMac::MacGetLeftBorderSize( ) const
3139 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3141 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3142 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3144 else if (HasFlag(wxSIMPLE_BORDER
))
3146 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3147 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3152 long wxWindowMac::MacGetRightBorderSize( ) const
3154 // they are all symmetric in mac themes
3155 return MacGetLeftBorderSize() ;
3158 long wxWindowMac::MacGetTopBorderSize( ) const
3160 // they are all symmetric in mac themes
3161 return MacGetLeftBorderSize() ;
3164 long wxWindowMac::MacGetBottomBorderSize( ) const
3166 // they are all symmetric in mac themes
3167 return MacGetLeftBorderSize() ;
3170 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3172 return style
& ~wxBORDER_MASK
;
3175 // Find the wxWindowMac at the current mouse position, returning the mouse
3177 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3179 pt
= wxGetMousePosition();
3180 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3184 // Get the current mouse position.
3185 wxPoint
wxGetMousePosition()
3188 wxGetMousePosition(& x
, & y
);
3189 return wxPoint(x
, y
);
3192 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3194 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3196 // copied from wxGTK : CS
3197 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3200 // (a) it's a command event and so is propagated to the parent
3201 // (b) under MSW it can be generated from kbd too
3202 // (c) it uses screen coords (because of (a))
3203 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3205 this->ClientToScreen(event
.GetPosition()));
3206 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3215 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3217 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3219 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3223 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3227 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3231 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3232 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3236 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3238 return eventNotHandledErr
;