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 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 #if TARGET_API_MAC_OSX
85 EVT_PAINT(wxWindowMac::OnPaint
)
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
120 // originating from native control
124 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
126 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
131 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
135 // directed towards native control
138 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
140 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
143 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
145 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
154 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
156 #if TARGET_API_MAC_OSX
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
160 kEventControlVisibilityChanged
= 157
166 static const EventTypeSpec eventList
[] =
168 { kEventClassControl
, kEventControlHit
} ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl
, kEventControlDraw
} ,
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
174 { kEventClassControl
, kEventControlSetFocusPart
} ,
176 { kEventClassService
, kEventServiceGetTypes
},
177 { kEventClassService
, kEventServiceCopy
},
178 { kEventClassService
, kEventServicePaste
},
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
205 if ( thisWindow
->GetPeer()->IsCompositing() == false )
207 if ( thisWindow
->GetPeer()->IsRootControl() == false )
209 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
213 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
217 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
219 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
223 if ( thisWindow
->GetPeer()->IsCompositing() == false )
226 if ( thisWindow->GetPeer()->IsRootControl() == false )
228 GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
232 thisWindow->GetPeer()->GetRect( &controlBounds ) ;
235 allocatedRgn
= NewRgn() ;
236 CopyRgn( updateRgn
, allocatedRgn
) ;
237 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
238 // hide the given region by the new region that must be shifted
239 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
240 updateRgn
= allocatedRgn
;
244 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
246 // as this update region is in native window locals we must adapt it to wx window local
247 allocatedRgn
= NewRgn() ;
248 CopyRgn( updateRgn
, allocatedRgn
) ;
249 // hide the given region by the new region that must be shifted
250 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
251 updateRgn
= allocatedRgn
;
256 GetRegionBounds( updateRgn
, &rgnBounds
) ;
257 #if wxMAC_DEBUG_REDRAW
258 if ( thisWindow
->MacIsUserPane() )
260 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
261 static float color
= 0.5 ;
264 HIViewGetBounds( controlRef
, &bounds
);
265 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
266 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
267 CGContextFillRect( cgContext
, bounds
);
279 #if wxMAC_USE_CORE_GRAPHICS
280 bool created
= false ;
281 CGContextRef cgContext
= 0 ;
282 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
284 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
286 // this parameter is not provided on non-composited windows
288 // rest of the code expects this to be already transformed and clipped for local
289 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
291 GetPortBounds( port
, &bounds
) ;
292 CreateCGContextForPort( port
, &cgContext
) ;
294 wxMacWindowToNative( thisWindow
, updateRgn
) ;
295 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
296 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
297 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
298 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
300 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
301 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
303 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
306 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
307 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
308 controlBounds.right - controlBounds.left ,
309 controlBounds.bottom - controlBounds.top ) );
313 thisWindow
->MacSetCGContextRef( cgContext
) ;
315 wxMacCGContextStateSaver
sg( cgContext
) ;
317 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
319 #if wxMAC_USE_CORE_GRAPHICS
320 thisWindow
->MacSetCGContextRef( NULL
) ;
324 CGContextRelease( cgContext
) ;
329 DisposeRgn( allocatedRgn
) ;
332 case kEventControlVisibilityChanged
:
333 thisWindow
->MacVisibilityChanged() ;
335 case kEventControlEnabledStateChanged
:
336 thisWindow
->MacEnabledStateChanged() ;
338 case kEventControlHiliteChanged
:
339 thisWindow
->MacHiliteChanged() ;
342 // we emulate this event under Carbon CFM
343 case kEventControlSetFocusPart
:
345 Boolean focusEverything
= false ;
346 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
348 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
352 if ( controlPart
== kControlFocusNoPart
)
355 if ( thisWindow
->GetCaret() )
357 thisWindow
->GetCaret()->OnKillFocus();
359 #endif // wxUSE_CARET
360 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
361 event
.SetEventObject(thisWindow
);
362 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
366 // panel wants to track the window which was the last to have focus in it
367 wxChildFocusEvent
eventFocus(thisWindow
);
368 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
371 if ( thisWindow
->GetCaret() )
373 thisWindow
->GetCaret()->OnSetFocus();
375 #endif // wxUSE_CARET
377 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
378 event
.SetEventObject(thisWindow
);
379 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
381 if ( thisWindow
->MacIsUserPane() )
385 case kEventControlHit
:
387 result
= thisWindow
->MacControlHit( handler
, event
) ;
396 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
398 OSStatus result
= eventNotHandledErr
;
400 wxMacCarbonEvent
cEvent( event
) ;
402 ControlRef controlRef
;
403 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
404 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
405 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
407 switch( GetEventKind( event
) )
409 case kEventServiceGetTypes
:
413 textCtrl
->GetSelection( &from
, &to
) ;
415 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
417 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
418 if ( textCtrl
->IsEditable() )
419 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
421 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
422 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
424 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
428 CFArrayAppendValue (copyTypes
, typestring
) ;
430 CFArrayAppendValue (pasteTypes
, typestring
) ;
431 CFRelease( typestring
) ;
437 case kEventServiceCopy
:
441 textCtrl
->GetSelection( &from
, &to
) ;
442 wxString val
= textCtrl
->GetValue() ;
443 val
= val
.Mid( from
, to
- from
) ;
444 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
445 verify_noerr( ClearScrap( &scrapRef
) ) ;
446 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
450 case kEventServicePaste
:
453 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
454 Size textSize
, pastedSize
;
455 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
457 char *content
= new char[textSize
] ;
458 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
459 content
[textSize
-1] = 0 ;
461 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
463 textCtrl
->WriteText( wxString( content
) ) ;
474 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
476 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
477 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
478 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
479 OSStatus result
= eventNotHandledErr
;
481 switch ( GetEventClass( event
) )
483 case kEventClassControl
:
484 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
486 case kEventClassService
:
487 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
491 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
495 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
497 #if !TARGET_API_MAC_OSX
499 // ---------------------------------------------------------------------------
500 // UserPane events for non OSX builds
501 // ---------------------------------------------------------------------------
503 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
505 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
507 win
->MacControlUserPaneDrawProc(part
) ;
509 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
511 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
513 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
515 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
517 return kControlNoPart
;
519 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
521 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
523 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
525 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
527 return kControlNoPart
;
529 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
531 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
533 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
535 win
->MacControlUserPaneIdleProc() ;
537 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
539 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
541 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
543 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
545 return kControlNoPart
;
547 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
549 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
551 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
553 win
->MacControlUserPaneActivateProc(activating
) ;
555 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
557 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
559 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
561 return win
->MacControlUserPaneFocusProc(action
) ;
563 return kControlNoPart
;
565 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
567 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
569 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
571 win
->MacControlUserPaneBackgroundProc(info
) ;
573 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
575 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
577 RgnHandle rgn
= NewRgn() ;
579 wxMacWindowStateSaver
sv( this ) ;
580 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
581 MacDoRedraw( rgn
, 0 ) ;
585 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
587 return kControlNoPart
;
590 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
592 return kControlNoPart
;
595 void wxWindowMac::MacControlUserPaneIdleProc()
599 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
601 return kControlNoPart
;
604 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
608 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
610 return kControlNoPart
;
613 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
619 // ---------------------------------------------------------------------------
620 // Scrollbar Tracking for all
621 // ---------------------------------------------------------------------------
623 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
624 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
628 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
631 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
635 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
637 // ===========================================================================
639 // ===========================================================================
641 #if KEY_wxList_DEPRECATED
642 wxList
wxWinMacControlList(wxKEY_INTEGER
);
644 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
646 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
649 return (wxControl
*)node
->GetData();
652 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
654 // adding NULL ControlRef is (first) surely a result of an error and
655 // (secondly) breaks native event processing
656 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
658 if ( !wxWinMacControlList
.Find((long)inControl
) )
659 wxWinMacControlList
.Append((long)inControl
, control
);
662 void wxRemoveMacControlAssociation(wxWindow
*control
)
664 // remove all associations pointing to us
665 while ( wxWinMacControlList
.DeleteObject(control
) )
670 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
672 static MacControlMap wxWinMacControlList
;
674 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
676 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
678 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
681 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
683 // adding NULL ControlRef is (first) surely a result of an error and
684 // (secondly) breaks native event processing
685 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
687 wxWinMacControlList
[inControl
] = control
;
690 void wxRemoveMacControlAssociation(wxWindow
*control
)
692 // iterate over all the elements in the class
693 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
694 // we should go on...
700 MacControlMap::iterator it
;
701 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
703 if ( it
->second
== control
)
705 wxWinMacControlList
.erase(it
);
712 #endif // deprecated wxList
714 // ----------------------------------------------------------------------------
715 // constructors and such
716 // ----------------------------------------------------------------------------
718 wxWindowMac::wxWindowMac()
723 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
728 const wxString
& name
)
731 Create(parent
, id
, pos
, size
, style
, name
);
734 void wxWindowMac::Init()
738 #if WXWIN_COMPATIBILITY_2_4
739 m_backgroundTransparent
= FALSE
;
742 // as all windows are created with WS_VISIBLE style...
745 m_hScrollBar
= NULL
;
746 m_vScrollBar
= NULL
;
747 m_macBackgroundBrush
= wxNullBrush
;
749 m_macIsUserPane
= TRUE
;
750 #if wxMAC_USE_CORE_GRAPHICS
751 m_cgContextRef
= NULL
;
753 m_clipChildren
= false ;
754 m_cachedClippedRectValid
= false ;
755 // we need a valid font for the encodings
756 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
760 wxWindowMac::~wxWindowMac()
764 m_isBeingDeleted
= TRUE
;
766 MacInvalidateBorders() ;
768 #ifndef __WXUNIVERSAL__
769 // VS: make sure there's no wxFrame with last focus set to us:
770 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
772 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
775 if ( frame
->GetLastFocus() == this )
777 frame
->SetLastFocus((wxWindow
*)NULL
);
782 #endif // __WXUNIVERSAL__
784 // destroy children before destroying this window itself
787 // wxRemoveMacControlAssociation( this ) ;
788 // If we delete an item, we should initialize the parent panel,
789 // because it could now be invalid.
790 wxWindow
*parent
= GetParent() ;
793 if (parent
->GetDefaultItem() == (wxButton
*) this)
794 parent
->SetDefaultItem(NULL
);
796 if ( m_peer
&& m_peer
->Ok() )
798 // in case the callback might be called during destruction
799 wxRemoveMacControlAssociation( this) ;
800 // we currently are not using this hook
801 // ::SetControlColorProc( *m_peer , NULL ) ;
805 if ( g_MacLastWindow
== this )
807 g_MacLastWindow
= NULL
;
810 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
813 if ( frame
->GetLastFocus() == this )
814 frame
->SetLastFocus( NULL
) ;
817 // delete our drop target if we've got one
818 #if wxUSE_DRAG_AND_DROP
819 if ( m_dropTarget
!= NULL
)
824 #endif // wxUSE_DRAG_AND_DROP
828 WXWidget
wxWindowMac::GetHandle() const
830 return (WXWidget
) m_peer
->GetControlRef() ;
834 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
836 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
837 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
838 GetEventTypeCount(eventList
), eventList
, this,
839 (EventHandlerRef
*)&m_macControlEventHandler
);
840 #if !TARGET_API_MAC_OSX
841 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
843 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
844 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
845 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
846 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
847 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
848 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
849 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
850 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
857 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
861 const wxString
& name
)
863 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
865 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
868 m_windowVariant
= parent
->GetWindowVariant() ;
870 if ( m_macIsUserPane
)
872 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
875 | kControlSupportsEmbedding
876 | kControlSupportsLiveFeedback
877 | kControlGetsFocusOnClick
878 // | kControlHasSpecialBackground
879 // | kControlSupportsCalcBestRect
880 | kControlHandlesTracking
881 | kControlSupportsFocus
882 | kControlWantsActivate
886 m_peer
= new wxMacControl(this) ;
887 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
890 MacPostControlCreate(pos
,size
) ;
892 #ifndef __WXUNIVERSAL__
893 // Don't give scrollbars to wxControls unless they ask for them
894 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
895 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
897 MacCreateScrollBars( style
) ;
901 wxWindowCreateEvent
event(this);
902 GetEventHandler()->AddPendingEvent(event
);
907 void wxWindowMac::MacChildAdded()
911 m_vScrollBar
->Raise() ;
915 m_hScrollBar
->Raise() ;
920 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
922 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
924 m_peer
->SetReference( (long) this ) ;
925 GetParent()->AddChild(this);
927 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
929 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
930 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
931 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
932 GetParent()->MacChildAdded() ;
934 // adjust font, controlsize etc
935 DoSetWindowVariant( m_windowVariant
) ;
937 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
939 if (!m_macIsUserPane
)
941 SetInitialBestSize(size
);
944 SetCursor( *wxSTANDARD_CURSOR
) ;
947 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
949 // Don't assert, in case we set the window variant before
950 // the window is created
951 // wxASSERT( m_peer->Ok() ) ;
953 m_windowVariant
= variant
;
955 if (m_peer
== NULL
|| !m_peer
->Ok())
959 ThemeFontID themeFont
= kThemeSystemFont
;
961 // we will get that from the settings later
962 // and make this NORMAL later, but first
963 // we have a few calculations that we must fix
967 case wxWINDOW_VARIANT_NORMAL
:
968 size
= kControlSizeNormal
;
969 themeFont
= kThemeSystemFont
;
971 case wxWINDOW_VARIANT_SMALL
:
972 size
= kControlSizeSmall
;
973 themeFont
= kThemeSmallSystemFont
;
975 case wxWINDOW_VARIANT_MINI
:
976 if (UMAGetSystemVersion() >= 0x1030 )
978 // not always defined in the headers
984 size
= kControlSizeSmall
;
985 themeFont
= kThemeSmallSystemFont
;
988 case wxWINDOW_VARIANT_LARGE
:
989 size
= kControlSizeLarge
;
990 themeFont
= kThemeSystemFont
;
993 wxFAIL_MSG(_T("unexpected window variant"));
996 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
999 font
.MacCreateThemeFont( themeFont
) ;
1003 void wxWindowMac::MacUpdateControlFont()
1005 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1009 bool wxWindowMac::SetFont(const wxFont
& font
)
1011 bool retval
= wxWindowBase::SetFont( font
) ;
1013 MacUpdateControlFont() ;
1018 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1020 if ( !wxWindowBase::SetForegroundColour(col
) )
1023 MacUpdateControlFont() ;
1028 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1030 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1034 wxColour
newCol(GetBackgroundColour());
1035 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1037 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1039 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1041 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1045 brush
.SetColour( newCol
) ;
1047 MacSetBackgroundBrush( brush
) ;
1049 MacUpdateControlFont() ;
1054 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1056 m_macBackgroundBrush
= brush
;
1057 m_peer
->SetBackground( brush
) ;
1060 bool wxWindowMac::MacCanFocus() const
1062 // there is currently no way to determine whether the window is running in full keyboard
1063 // access mode, therefore we cannot rely on these features, yet the only other way would be
1064 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1065 // in event handlers...
1066 UInt32 features
= 0 ;
1067 m_peer
->GetFeatures( & features
) ;
1068 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1072 void wxWindowMac::SetFocus()
1074 if ( AcceptsFocus() )
1077 wxWindow
* former
= FindFocus() ;
1078 if ( former
== this )
1081 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1082 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1083 // leave in case of an error
1084 if ( err
== errCouldntSetFocus
)
1087 #if !TARGET_API_MAC_OSX
1088 // emulate carbon events when running under carbonlib where they are not natively available
1091 EventRef evRef
= NULL
;
1092 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1095 wxMacCarbonEvent
cEvent( evRef
) ;
1096 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1097 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1099 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1100 ReleaseEvent(evRef
) ;
1102 // send new focus event
1104 EventRef evRef
= NULL
;
1105 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1108 wxMacCarbonEvent
cEvent( evRef
) ;
1109 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1110 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1112 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1113 ReleaseEvent(evRef
) ;
1120 void wxWindowMac::DoCaptureMouse()
1122 wxApp::s_captureWindow
= this ;
1125 wxWindow
* wxWindowBase::GetCapture()
1127 return wxApp::s_captureWindow
;
1130 void wxWindowMac::DoReleaseMouse()
1132 wxApp::s_captureWindow
= NULL
;
1135 #if wxUSE_DRAG_AND_DROP
1137 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1139 if ( m_dropTarget
!= 0 ) {
1140 delete m_dropTarget
;
1143 m_dropTarget
= pDropTarget
;
1144 if ( m_dropTarget
!= 0 )
1152 // Old style file-manager drag&drop
1153 void wxWindowMac::DragAcceptFiles(bool accept
)
1158 // Returns the size of the native control. In the case of the toplevel window
1159 // this is the content area root control
1161 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1162 int& w
, int& h
) const
1164 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1167 // From a wx position / size calculate the appropriate size of the native control
1169 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1172 int& w
, int& h
, bool adjustOrigin
) const
1174 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1176 // the desired size, minus the border pixels gives the correct size of the control
1180 // todo the default calls may be used as soon as PostCreateControl Is moved here
1181 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1182 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1184 if ( !isCompositing
)
1185 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1187 x
+= MacGetLeftBorderSize() ;
1188 y
+= MacGetTopBorderSize() ;
1189 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1190 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1193 AdjustForParentClientOrigin( x
, y
) ;
1195 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1196 if ( !GetParent()->IsTopLevel() )
1198 x
-= GetParent()->MacGetLeftBorderSize() ;
1199 y
-= GetParent()->MacGetTopBorderSize() ;
1205 // Get window size (not client size)
1206 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1209 m_peer
->GetRect( &bounds
) ;
1211 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1212 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1215 // get the position of the bounds of this window in client coordinates of its parent
1216 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1219 m_peer
->GetRect( &bounds
) ;
1221 int x1
= bounds
.left
;
1222 int y1
= bounds
.top
;
1224 // get the wx window position from the native one
1225 x1
-= MacGetLeftBorderSize() ;
1226 y1
-= MacGetTopBorderSize() ;
1228 if ( !IsTopLevel() )
1230 wxWindow
*parent
= GetParent();
1233 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1234 x1
+= parent
->MacGetLeftBorderSize() ;
1235 y1
+= parent
->MacGetTopBorderSize() ;
1236 // and now to client coordinates
1237 wxPoint
pt(parent
->GetClientAreaOrigin());
1246 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1248 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1250 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1253 Point localwhere
= {0,0} ;
1255 if(x
) localwhere
.h
= * x
;
1256 if(y
) localwhere
.v
= * y
;
1258 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1259 if(x
) *x
= localwhere
.h
;
1260 if(y
) *y
= localwhere
.v
;
1263 MacRootWindowToWindow( x
, y
) ;
1265 wxPoint origin
= GetClientAreaOrigin() ;
1266 if(x
) *x
-= origin
.x
;
1267 if(y
) *y
-= origin
.y
;
1270 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1272 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1273 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1275 wxPoint origin
= GetClientAreaOrigin() ;
1276 if(x
) *x
+= origin
.x
;
1277 if(y
) *y
+= origin
.y
;
1279 MacWindowToRootWindow( x
, y
) ;
1282 Point localwhere
= { 0,0 };
1283 if(x
) localwhere
.h
= * x
;
1284 if(y
) localwhere
.v
= * y
;
1285 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1286 if(x
) *x
= localwhere
.h
;
1287 if(y
) *y
= localwhere
.v
;
1291 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1293 wxPoint origin
= GetClientAreaOrigin() ;
1294 if(x
) *x
+= origin
.x
;
1295 if(y
) *y
+= origin
.y
;
1297 MacWindowToRootWindow( x
, y
) ;
1300 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1302 MacRootWindowToWindow( x
, y
) ;
1304 wxPoint origin
= GetClientAreaOrigin() ;
1305 if(x
) *x
-= origin
.x
;
1306 if(y
) *y
-= origin
.y
;
1309 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1312 if ( x
) pt
.x
= *x
;
1313 if ( y
) pt
.y
= *y
;
1315 if ( !IsTopLevel() )
1317 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1320 pt
.x
-= MacGetLeftBorderSize() ;
1321 pt
.y
-= MacGetTopBorderSize() ;
1322 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1326 if ( x
) *x
= (int) pt
.x
;
1327 if ( y
) *y
= (int) pt
.y
;
1330 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1335 MacWindowToRootWindow( &x1
, &y1
) ;
1340 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1343 if ( x
) pt
.x
= *x
;
1344 if ( y
) pt
.y
= *y
;
1346 if ( !IsTopLevel() )
1348 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1351 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1352 pt
.x
+= MacGetLeftBorderSize() ;
1353 pt
.y
+= MacGetTopBorderSize() ;
1357 if ( x
) *x
= (int) pt
.x
;
1358 if ( y
) *y
= (int) pt
.y
;
1361 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1366 MacRootWindowToWindow( &x1
, &y1
) ;
1371 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1373 RgnHandle rgn
= NewRgn() ;
1374 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1378 GetRegionBounds( rgn
, &content
) ;
1379 m_peer
->GetRect( &structure
) ;
1380 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1382 left
= content
.left
- structure
.left
;
1383 top
= content
.top
- structure
.top
;
1384 right
= structure
.right
- content
.right
;
1385 bottom
= structure
.bottom
- content
.bottom
;
1389 left
= top
= right
= bottom
= 0 ;
1394 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1396 wxSize sizeTotal
= size
;
1398 RgnHandle rgn
= NewRgn() ;
1400 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1404 GetRegionBounds( rgn
, &content
) ;
1406 m_peer
->GetRect( &structure
) ;
1407 // structure is in parent coordinates, but we only need width and height, so it's ok
1409 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1410 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1414 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1415 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1421 // Get size *available for subwindows* i.e. excluding menu bar etc.
1422 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1426 RgnHandle rgn
= NewRgn() ;
1428 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1430 GetRegionBounds( rgn
, &content
) ;
1434 m_peer
->GetRect( &content
) ;
1438 ww
= content
.right
- content
.left
;
1439 hh
= content
.bottom
- content
.top
;
1441 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1443 hh
-= m_hScrollBar
->GetSize().y
;
1445 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1447 ww
-= m_vScrollBar
->GetSize().x
;
1454 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1456 if (m_cursor
== cursor
)
1459 if (wxNullCursor
== cursor
)
1461 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1466 if ( ! wxWindowBase::SetCursor( cursor
) )
1470 wxASSERT_MSG( m_cursor
.Ok(),
1471 wxT("cursor must be valid after call to the base version"));
1474 wxWindowMac
*mouseWin
= 0 ;
1476 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1477 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1479 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1481 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1482 // position, use it...
1486 ControlPartCode part
;
1487 ControlRef control
;
1488 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1490 mouseWin
= wxFindControlFromMacControl( control
) ;
1493 QDSwapPort( savePort
, NULL
) ;
1496 if ( mouseWin
== this && !wxIsBusy() )
1498 m_cursor
.MacInstall() ;
1505 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1507 menu
->SetInvokingWindow(this);
1510 if ( x
== -1 && y
== -1 )
1512 wxPoint mouse
= wxGetMousePosition();
1513 x
= mouse
.x
; y
= mouse
.y
;
1517 ClientToScreen( &x
, &y
) ;
1520 menu
->MacBeforeDisplay( true ) ;
1521 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1522 if ( HiWord(menuResult
) != 0 )
1525 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1526 wxMenuItem
* item
= NULL
;
1528 item
= menu
->FindItem(id
, &realmenu
) ;
1529 if (item
->IsCheckable())
1531 item
->Check( !item
->IsChecked() ) ;
1533 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1535 menu
->MacAfterDisplay( true ) ;
1537 menu
->SetInvokingWindow(NULL
);
1543 // ----------------------------------------------------------------------------
1545 // ----------------------------------------------------------------------------
1549 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1551 wxWindowBase::DoSetToolTip(tooltip
);
1554 m_tooltip
->SetWindow(this);
1557 #endif // wxUSE_TOOLTIPS
1559 void wxWindowMac::MacInvalidateBorders()
1561 if ( m_peer
== NULL
)
1564 bool vis
= MacIsReallyShown() ;
1568 int outerBorder
= MacGetLeftBorderSize() ;
1569 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1572 if ( outerBorder
== 0 )
1575 // now we know that we have something to do at all
1577 // as the borders are drawn on the parent we have to properly invalidate all these areas
1578 RgnHandle updateInner
= NewRgn() ,
1579 updateOuter
= NewRgn() ;
1581 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1583 m_peer
->GetRect( &rect
) ;
1584 RectRgn( updateInner
, &rect
) ;
1585 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1586 RectRgn( updateOuter
, &rect
) ;
1587 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1588 #ifdef __WXMAC_OSX__
1589 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1591 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1593 InvalWindowRgn( tlw
, updateOuter
) ;
1595 DisposeRgn(updateOuter
) ;
1596 DisposeRgn(updateInner
) ;
1598 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1599 RectRgn( updateInner , &rect ) ;
1600 InsetRect( &rect , -4 , -4 ) ;
1601 RectRgn( updateOuter , &rect ) ;
1602 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1603 wxPoint parent(0,0);
1604 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1605 parent -= GetParent()->GetClientAreaOrigin() ;
1606 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1607 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1608 DisposeRgn(updateOuter) ;
1609 DisposeRgn(updateInner) ;
1614 // deleting a window while it is shown invalidates the region occupied by border or
1617 if ( IsShown() && ( outerBorder > 0 ) )
1619 // as the borders are drawn on the parent we have to properly invalidate all these areas
1620 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1624 m_peer->GetRect( &rect ) ;
1625 RectRgn( updateInner , &rect ) ;
1626 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1627 RectRgn( updateOuter , &rect ) ;
1628 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1629 wxPoint parent(0,0);
1630 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1631 parent -= GetParent()->GetClientAreaOrigin() ;
1632 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1633 CopyRgn( updateOuter , updateTotal ) ;
1635 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1636 DisposeRgn(updateOuter) ;
1637 DisposeRgn(updateInner) ;
1638 DisposeRgn(updateTotal) ;
1643 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1645 int outerBorder
= MacGetLeftBorderSize() ;
1646 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1649 if ( vis
&& ( outerBorder
> 0 ) )
1651 // as the borders are drawn on the parent we have to properly invalidate all these areas
1652 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1656 m_peer
->GetRect( &rect
) ;
1657 RectRgn( updateInner
, &rect
) ;
1658 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1659 RectRgn( updateOuter
, &rect
) ;
1660 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1662 wxPoint parent(0,0);
1663 #if TARGET_API_MAC_OSX
1664 // no offsetting needed when compositing
1666 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1667 parent -= GetParent()->GetClientAreaOrigin() ;
1668 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1671 CopyRgn( updateOuter
, updateTotal
) ;
1674 RectRgn( updateInner
, &rect
) ;
1675 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1676 RectRgn( updateOuter
, &rect
) ;
1677 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1679 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1681 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1683 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1684 DisposeRgn(updateOuter
) ;
1685 DisposeRgn(updateInner
) ;
1686 DisposeRgn(updateTotal
) ;
1691 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1693 // this is never called for a toplevel window, so we know we have a parent
1694 int former_x
, former_y
, former_w
, former_h
;
1696 // Get true coordinates of former position
1697 DoGetPosition( &former_x
, &former_y
) ;
1698 DoGetSize( &former_w
, &former_h
) ;
1700 wxWindow
*parent
= GetParent();
1703 wxPoint
pt(parent
->GetClientAreaOrigin());
1708 int actualWidth
= width
;
1709 int actualHeight
= height
;
1713 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1714 actualWidth
= m_minWidth
;
1715 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1716 actualHeight
= m_minHeight
;
1717 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1718 actualWidth
= m_maxWidth
;
1719 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1720 actualHeight
= m_maxHeight
;
1722 bool doMove
= false ;
1723 bool doResize
= false ;
1725 if ( actualX
!= former_x
|| actualY
!= former_y
)
1729 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1734 if ( doMove
|| doResize
)
1736 // as the borders are drawn outside the native control, we adjust now
1738 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1739 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1740 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1743 wxMacRectToNative( &bounds
, &r
) ;
1745 if ( !GetParent()->IsTopLevel() )
1747 wxMacWindowToNative( GetParent() , &r
) ;
1750 MacInvalidateBorders() ;
1752 m_cachedClippedRectValid
= false ;
1753 m_peer
->SetRect( &r
) ;
1755 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1757 MacInvalidateBorders() ;
1759 MacRepositionScrollBars() ;
1762 wxPoint
point(actualX
,actualY
);
1763 wxMoveEvent
event(point
, m_windowId
);
1764 event
.SetEventObject(this);
1765 GetEventHandler()->ProcessEvent(event
) ;
1769 MacRepositionScrollBars() ;
1770 wxSize
size(actualWidth
, actualHeight
);
1771 wxSizeEvent
event(size
, m_windowId
);
1772 event
.SetEventObject(this);
1773 GetEventHandler()->ProcessEvent(event
);
1779 wxSize
wxWindowMac::DoGetBestSize() const
1781 if ( m_macIsUserPane
|| IsTopLevel() )
1782 return wxWindowBase::DoGetBestSize() ;
1784 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1785 int bestWidth
, bestHeight
;
1786 m_peer
->GetBestRect( &bestsize
) ;
1788 if ( EmptyRect( &bestsize
) )
1790 bestsize
.left
= bestsize
.top
= 0 ;
1791 bestsize
.right
= 16 ;
1792 bestsize
.bottom
= 16 ;
1793 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1795 bestsize
.bottom
= 16 ;
1798 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1800 bestsize
.bottom
= 24 ;
1802 #endif // wxUSE_SPINBTN
1805 // return wxWindowBase::DoGetBestSize() ;
1809 bestWidth
= bestsize
.right
- bestsize
.left
;
1810 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1811 if ( bestHeight
< 10 )
1814 return wxSize(bestWidth
, bestHeight
);
1818 // set the size of the window: if the dimensions are positive, just use them,
1819 // but if any of them is equal to -1, it means that we must find the value for
1820 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1821 // which case -1 is a valid value for x and y)
1823 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1824 // the width/height to best suit our contents, otherwise we reuse the current
1826 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1828 // get the current size and position...
1829 int currentX
, currentY
;
1830 GetPosition(¤tX
, ¤tY
);
1832 int currentW
,currentH
;
1833 GetSize(¤tW
, ¤tH
);
1835 // ... and don't do anything (avoiding flicker) if it's already ok
1836 if ( x
== currentX
&& y
== currentY
&&
1837 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1840 MacRepositionScrollBars() ; // we might have a real position shift
1844 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1846 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1849 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1851 wxSize
size(-1, -1);
1854 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1856 size
= DoGetBestSize();
1861 // just take the current one
1868 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1872 size
= DoGetBestSize();
1874 //else: already called DoGetBestSize() above
1880 // just take the current one
1885 DoMoveWindow(x
, y
, width
, height
);
1889 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1891 RgnHandle rgn
= NewRgn() ;
1893 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1895 GetRegionBounds( rgn
, &content
) ;
1899 content
.left
= content
.top
= 0 ;
1902 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1905 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1907 if ( clientheight
!= -1 || clientheight
!= -1 )
1909 int currentclientwidth
, currentclientheight
;
1910 int currentwidth
, currentheight
;
1912 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1913 GetSize( ¤twidth
, ¤theight
) ;
1915 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1916 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1920 void wxWindowMac::SetTitle(const wxString
& title
)
1922 m_label
= wxStripMenuCodes(title
) ;
1924 if ( m_peer
&& m_peer
->Ok() )
1926 m_peer
->SetTitle( m_label
) ;
1931 wxString
wxWindowMac::GetTitle() const
1936 bool wxWindowMac::Show(bool show
)
1938 bool former
= MacIsReallyShown() ;
1939 if ( !wxWindowBase::Show(show
) )
1942 // TODO use visibilityChanged Carbon Event for OSX
1945 m_peer
->SetVisibility( show
, true ) ;
1947 if ( former
!= MacIsReallyShown() )
1948 MacPropagateVisibilityChanged() ;
1952 bool wxWindowMac::Enable(bool enable
)
1954 wxASSERT( m_peer
->Ok() ) ;
1955 bool former
= MacIsReallyEnabled() ;
1956 if ( !wxWindowBase::Enable(enable
) )
1959 m_peer
->Enable( enable
) ;
1961 if ( former
!= MacIsReallyEnabled() )
1962 MacPropagateEnabledStateChanged() ;
1967 // status change propagations (will be not necessary for OSX later )
1970 void wxWindowMac::MacPropagateVisibilityChanged()
1972 #if !TARGET_API_MAC_OSX
1973 MacVisibilityChanged() ;
1975 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1978 wxWindowMac
*child
= node
->GetData();
1979 if ( child
->IsShown() )
1980 child
->MacPropagateVisibilityChanged( ) ;
1981 node
= node
->GetNext();
1986 void wxWindowMac::MacPropagateEnabledStateChanged( )
1988 #if !TARGET_API_MAC_OSX
1989 MacEnabledStateChanged() ;
1991 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1994 wxWindowMac
*child
= node
->GetData();
1995 if ( child
->IsEnabled() )
1996 child
->MacPropagateEnabledStateChanged() ;
1997 node
= node
->GetNext();
2002 void wxWindowMac::MacPropagateHiliteChanged( )
2004 #if !TARGET_API_MAC_OSX
2005 MacHiliteChanged() ;
2007 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2010 wxWindowMac
*child
= node
->GetData();
2011 // if ( child->IsEnabled() )
2012 child
->MacPropagateHiliteChanged() ;
2013 node
= node
->GetNext();
2019 // status change notifications
2022 void wxWindowMac::MacVisibilityChanged()
2026 void wxWindowMac::MacHiliteChanged()
2030 void wxWindowMac::MacEnabledStateChanged()
2035 // status queries on the inherited window's state
2038 bool wxWindowMac::MacIsReallyShown()
2040 // only under OSX the visibility of the TLW is taken into account
2041 if ( m_isBeingDeleted
)
2044 #if TARGET_API_MAC_OSX
2045 if ( m_peer
&& m_peer
->Ok() )
2046 return m_peer
->IsVisible();
2048 wxWindow
* win
= this ;
2049 while( win
->IsShown() )
2051 if ( win
->IsTopLevel() )
2054 win
= win
->GetParent() ;
2062 bool wxWindowMac::MacIsReallyEnabled()
2064 return m_peer
->IsEnabled() ;
2067 bool wxWindowMac::MacIsReallyHilited()
2069 return m_peer
->IsActive();
2072 void wxWindowMac::MacFlashInvalidAreas()
2074 #if TARGET_API_MAC_OSX
2075 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2083 int wxWindowMac::GetCharHeight() const
2085 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2086 return dc
.GetCharHeight() ;
2089 int wxWindowMac::GetCharWidth() const
2091 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2092 return dc
.GetCharWidth() ;
2095 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2096 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2098 const wxFont
*fontToUse
= theFont
;
2100 fontToUse
= &m_font
;
2102 wxClientDC
dc( (wxWindowMac
*) this ) ;
2104 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2105 if ( externalLeading
)
2106 *externalLeading
= le
;
2116 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2117 * we always intersect with the entire window, not only with the client area
2120 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2122 if ( m_peer
== NULL
)
2125 if ( !MacIsReallyShown() )
2131 wxMacRectToNative( rect
, &r
) ;
2132 m_peer
->SetNeedsDisplay( &r
) ;
2136 m_peer
->SetNeedsDisplay() ;
2140 void wxWindowMac::Freeze()
2142 #if TARGET_API_MAC_OSX
2143 if ( !m_frozenness
++ )
2145 if ( m_peer
&& m_peer
->Ok() )
2146 m_peer
->SetDrawingEnabled( false ) ;
2152 void wxWindowMac::Thaw()
2154 #if TARGET_API_MAC_OSX
2155 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2157 if ( !--m_frozenness
)
2159 if ( m_peer
&& m_peer
->Ok() )
2161 m_peer
->SetDrawingEnabled( true ) ;
2162 m_peer
->InvalidateWithChildren() ;
2168 wxWindowMac
*wxGetActiveWindow()
2170 // actually this is a windows-only concept
2174 // Coordinates relative to the window
2175 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2177 // We really don't move the mouse programmatically under Mac.
2180 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2182 #if TARGET_API_MAC_OSX
2183 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2190 event
.GetDC()->Clear() ;
2194 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2199 int wxWindowMac::GetScrollPos(int orient
) const
2201 if ( orient
== wxHORIZONTAL
)
2204 return m_hScrollBar
->GetThumbPosition() ;
2209 return m_vScrollBar
->GetThumbPosition() ;
2214 // This now returns the whole range, not just the number
2215 // of positions that we can scroll.
2216 int wxWindowMac::GetScrollRange(int orient
) const
2218 if ( orient
== wxHORIZONTAL
)
2221 return m_hScrollBar
->GetRange() ;
2226 return m_vScrollBar
->GetRange() ;
2231 int wxWindowMac::GetScrollThumb(int orient
) const
2233 if ( orient
== wxHORIZONTAL
)
2236 return m_hScrollBar
->GetThumbSize() ;
2241 return m_vScrollBar
->GetThumbSize() ;
2246 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2248 if ( orient
== wxHORIZONTAL
)
2251 m_hScrollBar
->SetThumbPosition( pos
) ;
2256 m_vScrollBar
->SetThumbPosition( pos
) ;
2261 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2262 // our own window origin is at leftOrigin/rightOrigin
2265 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2271 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2272 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2274 m_peer
->GetRect( &rect
) ;
2275 // back to the surrounding frame rectangle
2276 InsetRect( &rect
, -1 , -1 ) ;
2278 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2279 if ( UMAGetSystemVersion() >= 0x1030 )
2281 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2282 rect
.bottom
- rect
.top
) ;
2284 HIThemeFrameDrawInfo info
;
2285 memset( &info
, 0 , sizeof( info
) ) ;
2289 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2290 info
.isFocused
= hasFocus
;
2292 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2293 wxASSERT( cgContext
) ;
2295 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2297 info
.kind
= kHIThemeFrameTextFieldSquare
;
2298 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2300 else if (HasFlag(wxSIMPLE_BORDER
))
2302 info
.kind
= kHIThemeFrameListBox
;
2303 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2305 else if ( hasFocus
)
2307 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2310 m_peer
->GetRect( &rect
) ;
2311 if ( hasBothScrollbars
)
2313 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2314 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2315 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2316 HIThemeGrowBoxDrawInfo info
;
2317 memset( &info
, 0 , sizeof( info
) ) ;
2319 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2320 info
.kind
= kHIThemeGrowBoxKindNone
;
2321 info
.size
= kHIThemeGrowBoxSizeNormal
;
2322 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2323 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2329 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2333 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2334 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2337 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2339 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2341 else if (HasFlag(wxSIMPLE_BORDER
))
2343 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2348 DrawThemeFocusRect( &rect
, true ) ;
2351 if ( hasBothScrollbars
)
2353 // GetThemeStandaloneGrowBoxBounds
2354 //DrawThemeStandaloneNoGrowBox
2359 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2361 if ( child
== m_hScrollBar
)
2362 m_hScrollBar
= NULL
;
2363 if ( child
== m_vScrollBar
)
2364 m_vScrollBar
= NULL
;
2366 wxWindowBase::RemoveChild( child
) ;
2369 // New function that will replace some of the above.
2370 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2371 int range
, bool refresh
)
2373 if ( orient
== wxHORIZONTAL
)
2377 if ( range
== 0 || thumbVisible
>= range
)
2379 if ( m_hScrollBar
->IsShown() )
2380 m_hScrollBar
->Show(false) ;
2384 if ( !m_hScrollBar
->IsShown() )
2385 m_hScrollBar
->Show(true) ;
2387 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2394 if ( range
== 0 || thumbVisible
>= range
)
2396 if ( m_vScrollBar
->IsShown() )
2397 m_vScrollBar
->Show(false) ;
2401 if ( !m_vScrollBar
->IsShown() )
2402 m_vScrollBar
->Show(true) ;
2404 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2407 MacRepositionScrollBars() ;
2410 // Does a physical scroll
2411 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2413 if( dx
== 0 && dy
==0 )
2416 int width
, height
;
2417 GetClientSize( &width
, &height
) ;
2418 #if TARGET_API_MAC_OSX
2419 if ( 1 /* m_peer->IsCompositing() */ )
2421 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2422 // area is scrolled, this does not occur if width and height are 2 pixels less,
2423 // TODO write optimal workaround
2424 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2427 scrollrect
.Intersect( *rect
) ;
2429 if ( m_peer
->GetNeedsDisplay() )
2431 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2432 // either immediate redraw or full invalidate
2434 // is the better overall solution, as it does not slow down scrolling
2435 m_peer
->SetNeedsDisplay() ;
2437 // this would be the preferred version for fast drawing controls
2439 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2440 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2441 HIViewRender(m_peer
->GetControlRef()) ;
2447 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2448 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2449 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2451 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2452 // either immediate redraw or full invalidate
2454 // is the better overall solution, as it does not slow down scrolling
2455 m_peer
->SetNeedsDisplay() ;
2457 // this would be the preferred version for fast drawing controls
2459 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2460 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2461 HIViewRender(m_peer
->GetControlRef()) ;
2476 RgnHandle updateRgn
= NewRgn() ;
2479 wxClientDC
dc(this) ;
2480 wxMacPortSetter
helper(&dc
) ;
2482 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2483 //scrollrect.top += MacGetTopBorderSize() ;
2484 //scrollrect.left += MacGetLeftBorderSize() ;
2485 scrollrect
.bottom
= scrollrect
.top
+ height
;
2486 scrollrect
.right
= scrollrect
.left
+ width
;
2490 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2491 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2492 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2494 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2496 // now scroll the former update region as well and add the new update region
2498 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2499 RgnHandle formerUpdateRgn
= NewRgn() ;
2500 RgnHandle scrollRgn
= NewRgn() ;
2501 RectRgn( scrollRgn
, &scrollrect
) ;
2502 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2504 LocalToGlobal( &pt
) ;
2505 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2506 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2507 if ( !EmptyRgn( formerUpdateRgn
) )
2509 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2510 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2511 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2513 InvalWindowRgn(rootWindow
, updateRgn
) ;
2514 DisposeRgn( updateRgn
) ;
2515 DisposeRgn( formerUpdateRgn
) ;
2516 DisposeRgn( scrollRgn
) ;
2521 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2523 wxWindowMac
*child
= node
->GetData();
2524 if (child
== m_vScrollBar
) continue;
2525 if (child
== m_hScrollBar
) continue;
2526 if (child
->IsTopLevel()) continue;
2529 child
->GetPosition( &x
, &y
);
2531 child
->GetSize( &w
, &h
);
2535 if (rect
->Intersects(rc
))
2536 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2540 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2545 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2547 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2549 wxScrollWinEvent wevent
;
2550 wevent
.SetPosition(event
.GetPosition());
2551 wevent
.SetOrientation(event
.GetOrientation());
2552 wevent
.SetEventObject(this);
2554 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2555 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2556 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2557 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2558 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2559 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2560 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2561 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2562 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2563 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2564 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2565 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2566 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2567 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2568 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2569 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2571 GetEventHandler()->ProcessEvent(wevent
);
2575 // Get the window with the focus
2576 wxWindowMac
*wxWindowBase::DoFindFocus()
2578 ControlRef control
;
2579 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2580 return wxFindControlFromMacControl( control
) ;
2583 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2585 // panel wants to track the window which was the last to have focus in it,
2586 // so we want to set ourselves as the window which last had focus
2588 // notice that it's also important to do it upwards the tree becaus
2589 // otherwise when the top level panel gets focus, it won't set it back to
2590 // us, but to some other sibling
2592 // CS:don't know if this is still needed:
2593 //wxChildFocusEvent eventFocus(this);
2594 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2596 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2598 #if !wxMAC_USE_CORE_GRAPHICS
2599 wxMacWindowStateSaver
sv( this ) ;
2601 m_peer
->GetRect( &rect
) ;
2602 // auf den umgebenden Rahmen zur\9fck
2603 InsetRect( &rect
, -1 , -1 ) ;
2605 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2609 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2611 rect
.right
+= pt
.x
;
2613 rect
.bottom
+= pt
.y
;
2616 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2617 DrawThemeFocusRect( &rect
, true ) ;
2620 DrawThemeFocusRect( &rect
, false ) ;
2622 // as this erases part of the frame we have to redraw borders
2623 // and because our z-ordering is not always correct (staticboxes)
2624 // we have to invalidate things, we cannot simple redraw
2625 MacInvalidateBorders() ;
2628 GetParent()->Refresh() ;
2635 void wxWindowMac::OnInternalIdle()
2637 // This calls the UI-update mechanism (querying windows for
2638 // menu/toolbar/control state information)
2639 if (wxUpdateUIEvent::CanUpdate(this))
2640 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2643 // Raise the window to the top of the Z order
2644 void wxWindowMac::Raise()
2646 m_peer
->SetZOrder( true , NULL
) ;
2649 // Lower the window to the bottom of the Z order
2650 void wxWindowMac::Lower()
2652 m_peer
->SetZOrder( false , NULL
) ;
2656 // static wxWindow *gs_lastWhich = NULL;
2658 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2660 // first trigger a set cursor event
2662 wxPoint clientorigin
= GetClientAreaOrigin() ;
2663 wxSize clientsize
= GetClientSize() ;
2665 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2667 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2669 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2670 if ( processedEvtSetCursor
&& event
.HasCursor() )
2672 cursor
= event
.GetCursor() ;
2677 // the test for processedEvtSetCursor is here to prevent using m_cursor
2678 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2679 // it - this is a way to say that our cursor shouldn't be used for this
2681 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2691 cursor
= *wxSTANDARD_CURSOR
;
2695 cursor
.MacInstall() ;
2697 return cursor
.Ok() ;
2700 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2705 return m_tooltip
->GetTip() ;
2708 return wxEmptyString
;
2711 void wxWindowMac::ClearBackground()
2717 void wxWindowMac::Update()
2719 #if TARGET_API_MAC_OSX
2720 MacGetTopLevelWindow()->MacPerformUpdates() ;
2722 ::Draw1Control( m_peer
->GetControlRef() ) ;
2726 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2728 wxTopLevelWindowMac
* win
= NULL
;
2729 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2732 win
= wxFindWinFromMacWindow( window
) ;
2737 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2739 MacUpdateClippedRects() ;
2740 return m_cachedClippedClientRect
;
2743 const wxRect
& wxWindowMac::MacGetClippedRect() const
2745 MacUpdateClippedRects() ;
2746 return m_cachedClippedRect
;
2749 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2751 MacUpdateClippedRects() ;
2752 return m_cachedClippedRectWithOuterStructure
;
2755 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2757 static wxRegion emptyrgn
;
2758 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2760 MacUpdateClippedRects() ;
2761 if ( includeOuterStructures
)
2762 return m_cachedClippedRegionWithOuterStructure
;
2764 return m_cachedClippedRegion
;
2772 void wxWindowMac::MacUpdateClippedRects() const
2774 if ( m_cachedClippedRectValid
)
2777 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2778 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2779 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2780 // to add focus borders everywhere
2783 Rect rIncludingOuterStructures
;
2785 m_peer
->GetRect( &r
) ;
2786 r
.left
-= MacGetLeftBorderSize() ;
2787 r
.top
-= MacGetTopBorderSize() ;
2788 r
.bottom
+= MacGetBottomBorderSize() ;
2789 r
.right
+= MacGetRightBorderSize() ;
2796 rIncludingOuterStructures
= r
;
2797 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2799 wxRect cl
= GetClientRect() ;
2800 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2802 const wxWindow
* child
= this ;
2803 const wxWindow
* parent
= NULL
;
2804 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2809 if ( parent
->MacIsChildOfClientArea(child
) )
2811 size
= parent
->GetClientSize() ;
2812 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2818 // this will be true for scrollbars, toolbars etc.
2819 size
= parent
->GetSize() ;
2820 y
= parent
->MacGetTopBorderSize() ;
2821 x
= parent
->MacGetLeftBorderSize() ;
2822 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2823 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2826 parent
->MacWindowToRootWindow( &x
, &y
) ;
2827 MacRootWindowToWindow( &x
, &y
) ;
2829 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2831 // the wxwindow and client rects will always be clipped
2832 SectRect( &r
, &rparent
, &r
) ;
2833 SectRect( &rClient
, &rparent
, &rClient
) ;
2835 // the structure only at 'hard' borders
2836 if ( parent
->MacClipChildren() ||
2837 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2839 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2844 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2845 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2846 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2847 m_cachedClippedRectWithOuterStructure
= wxRect(
2848 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2849 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2850 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2852 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2853 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2854 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2856 m_cachedClippedRectValid
= true ;
2860 This function must not change the updatergn !
2862 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2864 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2865 bool handled
= false ;
2867 GetRegionBounds( updatergn
, &updatebounds
) ;
2869 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2871 if ( !EmptyRgn(updatergn
) )
2873 RgnHandle newupdate
= NewRgn() ;
2874 wxSize point
= GetClientSize() ;
2875 wxPoint origin
= GetClientAreaOrigin() ;
2876 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2877 SectRgn( newupdate
, updatergn
, newupdate
) ;
2879 // first send an erase event to the entire update area
2881 // for the toplevel window this really is the entire area
2882 // for all the others only their client area, otherwise they
2883 // might be drawing with full alpha and eg put blue into
2884 // the grow-box area of a scrolled window (scroll sample)
2885 wxDC
* dc
= new wxWindowDC(this);
2887 dc
->SetClippingRegion(wxRegion(updatergn
));
2889 dc
->SetClippingRegion(wxRegion(newupdate
));
2891 wxEraseEvent
eevent( GetId(), dc
);
2892 eevent
.SetEventObject( this );
2893 GetEventHandler()->ProcessEvent( eevent
);
2897 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2898 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2899 m_updateRegion
= newupdate
;
2900 DisposeRgn( newupdate
) ;
2902 if ( !m_updateRegion
.Empty() )
2904 // paint the window itself
2907 event
.SetTimestamp(time
);
2908 event
.SetEventObject(this);
2909 GetEventHandler()->ProcessEvent(event
);
2913 // now we cannot rely on having its borders drawn by a window itself, as it does not
2914 // get the updateRgn wide enough to always do so, so we do it from the parent
2915 // this would also be the place to draw any custom backgrounds for native controls
2916 // in Composited windowing
2917 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2919 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2921 wxWindowMac
*child
= node
->GetData();
2922 if (child
== m_vScrollBar
) continue;
2923 if (child
== m_hScrollBar
) continue;
2924 if (child
->IsTopLevel()) continue;
2925 if (!child
->IsShown()) continue;
2927 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2930 child
->GetPosition( &x
, &y
);
2932 child
->GetSize( &w
, &h
);
2933 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2934 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2935 InsetRect( &childRect
, -10 , -10) ;
2937 if ( RectInRgn( &childRect
, updatergn
) )
2940 // paint custom borders
2941 wxNcPaintEvent
eventNc( child
->GetId() );
2942 eventNc
.SetEventObject( child
);
2943 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2945 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2946 if ( UMAGetSystemVersion() >= 0x1030 )
2948 child
->MacPaintBorders(0,0) ;
2953 wxWindowDC
dc(this) ;
2954 dc
.SetClippingRegion(wxRegion(updatergn
));
2955 wxMacPortSetter
helper(&dc
) ;
2956 child
->MacPaintBorders(0,0) ;
2966 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2968 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2972 if ( iter
->IsTopLevel() )
2973 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2975 iter
= iter
->GetParent() ;
2977 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2981 void wxWindowMac::MacCreateScrollBars( long style
)
2983 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2985 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2987 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2988 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2989 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2990 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2992 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2993 variant
= wxWINDOW_VARIANT_SMALL
;
2996 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2998 GetClientSize( &width
, &height
) ;
3000 wxPoint
vPoint(width
-scrlsize
, 0) ;
3001 wxSize
vSize(scrlsize
, height
- adjust
) ;
3002 wxPoint
hPoint(0 , height
-scrlsize
) ;
3003 wxSize
hSize( width
- adjust
, scrlsize
) ;
3006 if ( style
& wxVSCROLL
)
3008 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3009 vSize
, wxVERTICAL
);
3012 if ( style
& wxHSCROLL
)
3014 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3015 hSize
, wxHORIZONTAL
);
3020 // because the create does not take into account the client area origin
3021 MacRepositionScrollBars() ; // we might have a real position shift
3024 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3026 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3032 void wxWindowMac::MacRepositionScrollBars()
3034 if ( !m_hScrollBar
&& !m_vScrollBar
)
3037 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3038 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3039 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3041 // get real client area
3045 GetSize( &width
, &height
) ;
3047 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3048 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3050 wxPoint
vPoint(width
-scrlsize
, 0) ;
3051 wxSize
vSize(scrlsize
, height
- adjust
) ;
3052 wxPoint
hPoint(0 , height
-scrlsize
) ;
3053 wxSize
hSize( width
- adjust
, scrlsize
) ;
3059 GetSize( &w , &h ) ;
3061 MacClientToRootWindow( &x , &y ) ;
3062 MacClientToRootWindow( &w , &h ) ;
3064 wxWindowMac *iter = (wxWindowMac*)this ;
3066 int totW = 10000 , totH = 10000;
3069 if ( iter->IsTopLevel() )
3071 iter->GetSize( &totW , &totH ) ;
3075 iter = iter->GetParent() ;
3103 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3107 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3111 bool wxWindowMac::AcceptsFocus() const
3113 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3116 void wxWindowMac::MacSuperChangedPosition()
3118 m_cachedClippedRectValid
= false ;
3119 // only window-absolute structures have to be moved i.e. controls
3121 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3124 wxWindowMac
*child
= node
->GetData();
3125 child
->MacSuperChangedPosition() ;
3126 node
= node
->GetNext();
3130 void wxWindowMac::MacTopLevelWindowChangedPosition()
3132 // only screen-absolute structures have to be moved i.e. glcanvas
3134 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3137 wxWindowMac
*child
= node
->GetData();
3138 child
->MacTopLevelWindowChangedPosition() ;
3139 node
= node
->GetNext();
3143 long wxWindowMac::MacGetLeftBorderSize( ) const
3150 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3152 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3153 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3155 else if (HasFlag(wxSIMPLE_BORDER
))
3157 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3158 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3163 long wxWindowMac::MacGetRightBorderSize( ) const
3165 // they are all symmetric in mac themes
3166 return MacGetLeftBorderSize() ;
3169 long wxWindowMac::MacGetTopBorderSize( ) const
3171 // they are all symmetric in mac themes
3172 return MacGetLeftBorderSize() ;
3175 long wxWindowMac::MacGetBottomBorderSize( ) const
3177 // they are all symmetric in mac themes
3178 return MacGetLeftBorderSize() ;
3181 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3183 return style
& ~wxBORDER_MASK
;
3186 // Find the wxWindowMac at the current mouse position, returning the mouse
3188 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3190 pt
= wxGetMousePosition();
3191 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3195 // Get the current mouse position.
3196 wxPoint
wxGetMousePosition()
3199 wxGetMousePosition(& x
, & y
);
3200 return wxPoint(x
, y
);
3203 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3205 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3207 // copied from wxGTK : CS
3208 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3211 // (a) it's a command event and so is propagated to the parent
3212 // (b) under MSW it can be generated from kbd too
3213 // (c) it uses screen coords (because of (a))
3214 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3216 this->ClientToScreen(event
.GetPosition()));
3217 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3226 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3228 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3230 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3234 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3238 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3242 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3243 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3247 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3249 return eventNotHandledErr
;