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() ;
580 MacWindowToRootWindow( &x
,&y
) ;
581 OffsetRgn( rgn
, -x
, -y
) ;
582 wxMacWindowStateSaver
sv( this ) ;
583 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
584 MacDoRedraw( rgn
, 0 ) ;
588 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
590 return kControlNoPart
;
593 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
595 return kControlNoPart
;
598 void wxWindowMac::MacControlUserPaneIdleProc()
602 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
604 return kControlNoPart
;
607 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
611 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
613 return kControlNoPart
;
616 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
622 // ---------------------------------------------------------------------------
623 // Scrollbar Tracking for all
624 // ---------------------------------------------------------------------------
626 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
627 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
631 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
634 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
638 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
640 // ===========================================================================
642 // ===========================================================================
644 #if KEY_wxList_DEPRECATED
645 wxList
wxWinMacControlList(wxKEY_INTEGER
);
647 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
649 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
652 return (wxControl
*)node
->GetData();
655 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
657 // adding NULL ControlRef is (first) surely a result of an error and
658 // (secondly) breaks native event processing
659 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
661 if ( !wxWinMacControlList
.Find((long)inControl
) )
662 wxWinMacControlList
.Append((long)inControl
, control
);
665 void wxRemoveMacControlAssociation(wxWindow
*control
)
667 // remove all associations pointing to us
668 while ( wxWinMacControlList
.DeleteObject(control
) )
673 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
675 static MacControlMap wxWinMacControlList
;
677 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
679 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
681 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
684 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
686 // adding NULL ControlRef is (first) surely a result of an error and
687 // (secondly) breaks native event processing
688 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
690 wxWinMacControlList
[inControl
] = control
;
693 void wxRemoveMacControlAssociation(wxWindow
*control
)
695 // iterate over all the elements in the class
696 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
697 // we should go on...
703 MacControlMap::iterator it
;
704 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
706 if ( it
->second
== control
)
708 wxWinMacControlList
.erase(it
);
715 #endif // deprecated wxList
717 // ----------------------------------------------------------------------------
718 // constructors and such
719 // ----------------------------------------------------------------------------
721 wxWindowMac::wxWindowMac()
726 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
731 const wxString
& name
)
734 Create(parent
, id
, pos
, size
, style
, name
);
737 void wxWindowMac::Init()
741 #if WXWIN_COMPATIBILITY_2_4
742 m_backgroundTransparent
= FALSE
;
745 // as all windows are created with WS_VISIBLE style...
748 m_hScrollBar
= NULL
;
749 m_vScrollBar
= NULL
;
750 m_macBackgroundBrush
= wxNullBrush
;
752 m_macIsUserPane
= TRUE
;
753 #if wxMAC_USE_CORE_GRAPHICS
754 m_cgContextRef
= NULL
;
756 m_clipChildren
= false ;
757 m_cachedClippedRectValid
= false ;
758 // we need a valid font for the encodings
759 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
763 wxWindowMac::~wxWindowMac()
767 m_isBeingDeleted
= TRUE
;
769 MacInvalidateBorders() ;
771 #ifndef __WXUNIVERSAL__
772 // VS: make sure there's no wxFrame with last focus set to us:
773 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
775 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
778 if ( frame
->GetLastFocus() == this )
780 frame
->SetLastFocus((wxWindow
*)NULL
);
785 #endif // __WXUNIVERSAL__
787 // destroy children before destroying this window itself
790 // wxRemoveMacControlAssociation( this ) ;
791 // If we delete an item, we should initialize the parent panel,
792 // because it could now be invalid.
793 wxWindow
*parent
= GetParent() ;
796 if (parent
->GetDefaultItem() == (wxButton
*) this)
797 parent
->SetDefaultItem(NULL
);
799 if ( m_peer
&& m_peer
->Ok() )
801 // in case the callback might be called during destruction
802 wxRemoveMacControlAssociation( this) ;
803 // we currently are not using this hook
804 // ::SetControlColorProc( *m_peer , NULL ) ;
808 if ( g_MacLastWindow
== this )
810 g_MacLastWindow
= NULL
;
813 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
816 if ( frame
->GetLastFocus() == this )
817 frame
->SetLastFocus( NULL
) ;
820 // delete our drop target if we've got one
821 #if wxUSE_DRAG_AND_DROP
822 if ( m_dropTarget
!= NULL
)
827 #endif // wxUSE_DRAG_AND_DROP
831 WXWidget
wxWindowMac::GetHandle() const
833 return (WXWidget
) m_peer
->GetControlRef() ;
837 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
839 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
840 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
841 GetEventTypeCount(eventList
), eventList
, this,
842 (EventHandlerRef
*)&m_macControlEventHandler
);
843 #if !TARGET_API_MAC_OSX
844 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
846 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
847 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
848 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
849 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
850 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
851 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
852 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
853 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
860 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
864 const wxString
& name
)
866 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
868 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
871 m_windowVariant
= parent
->GetWindowVariant() ;
873 if ( m_macIsUserPane
)
875 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
878 | kControlSupportsEmbedding
879 | kControlSupportsLiveFeedback
880 | kControlGetsFocusOnClick
881 // | kControlHasSpecialBackground
882 // | kControlSupportsCalcBestRect
883 | kControlHandlesTracking
884 | kControlSupportsFocus
885 | kControlWantsActivate
889 m_peer
= new wxMacControl(this) ;
890 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
893 MacPostControlCreate(pos
,size
) ;
895 #ifndef __WXUNIVERSAL__
896 // Don't give scrollbars to wxControls unless they ask for them
897 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
898 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
900 MacCreateScrollBars( style
) ;
904 wxWindowCreateEvent
event(this);
905 GetEventHandler()->AddPendingEvent(event
);
910 void wxWindowMac::MacChildAdded()
914 m_vScrollBar
->Raise() ;
918 m_hScrollBar
->Raise() ;
923 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
925 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
927 m_peer
->SetReference( (long) this ) ;
928 GetParent()->AddChild(this);
930 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
932 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
933 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
934 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
935 GetParent()->MacChildAdded() ;
937 // adjust font, controlsize etc
938 DoSetWindowVariant( m_windowVariant
) ;
940 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
942 if (!m_macIsUserPane
)
944 SetInitialBestSize(size
);
947 SetCursor( *wxSTANDARD_CURSOR
) ;
950 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
952 // Don't assert, in case we set the window variant before
953 // the window is created
954 // wxASSERT( m_peer->Ok() ) ;
956 m_windowVariant
= variant
;
958 if (m_peer
== NULL
|| !m_peer
->Ok())
962 ThemeFontID themeFont
= kThemeSystemFont
;
964 // we will get that from the settings later
965 // and make this NORMAL later, but first
966 // we have a few calculations that we must fix
970 case wxWINDOW_VARIANT_NORMAL
:
971 size
= kControlSizeNormal
;
972 themeFont
= kThemeSystemFont
;
974 case wxWINDOW_VARIANT_SMALL
:
975 size
= kControlSizeSmall
;
976 themeFont
= kThemeSmallSystemFont
;
978 case wxWINDOW_VARIANT_MINI
:
979 if (UMAGetSystemVersion() >= 0x1030 )
981 // not always defined in the headers
987 size
= kControlSizeSmall
;
988 themeFont
= kThemeSmallSystemFont
;
991 case wxWINDOW_VARIANT_LARGE
:
992 size
= kControlSizeLarge
;
993 themeFont
= kThemeSystemFont
;
996 wxFAIL_MSG(_T("unexpected window variant"));
999 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
1002 font
.MacCreateThemeFont( themeFont
) ;
1006 void wxWindowMac::MacUpdateControlFont()
1008 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1012 bool wxWindowMac::SetFont(const wxFont
& font
)
1014 bool retval
= wxWindowBase::SetFont( font
) ;
1016 MacUpdateControlFont() ;
1021 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1023 if ( !wxWindowBase::SetForegroundColour(col
) )
1026 MacUpdateControlFont() ;
1031 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1033 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1037 wxColour
newCol(GetBackgroundColour());
1038 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1040 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1042 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1044 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1048 brush
.SetColour( newCol
) ;
1050 MacSetBackgroundBrush( brush
) ;
1052 MacUpdateControlFont() ;
1057 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1059 m_macBackgroundBrush
= brush
;
1060 m_peer
->SetBackground( brush
) ;
1063 bool wxWindowMac::MacCanFocus() const
1065 // there is currently no way to determine whether the window is running in full keyboard
1066 // access mode, therefore we cannot rely on these features, yet the only other way would be
1067 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1068 // in event handlers...
1069 UInt32 features
= 0 ;
1070 m_peer
->GetFeatures( & features
) ;
1071 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1075 void wxWindowMac::SetFocus()
1077 if ( AcceptsFocus() )
1080 wxWindow
* former
= FindFocus() ;
1081 if ( former
== this )
1084 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1085 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1086 // leave in case of an error
1087 if ( err
== errCouldntSetFocus
)
1090 #if !TARGET_API_MAC_OSX
1091 // emulate carbon events when running under carbonlib where they are not natively available
1094 EventRef evRef
= NULL
;
1095 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1098 wxMacCarbonEvent
cEvent( evRef
) ;
1099 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1100 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1102 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1103 ReleaseEvent(evRef
) ;
1105 // send new focus event
1107 EventRef evRef
= NULL
;
1108 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1111 wxMacCarbonEvent
cEvent( evRef
) ;
1112 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1113 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1115 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1116 ReleaseEvent(evRef
) ;
1123 void wxWindowMac::DoCaptureMouse()
1125 wxApp::s_captureWindow
= this ;
1128 wxWindow
* wxWindowBase::GetCapture()
1130 return wxApp::s_captureWindow
;
1133 void wxWindowMac::DoReleaseMouse()
1135 wxApp::s_captureWindow
= NULL
;
1138 #if wxUSE_DRAG_AND_DROP
1140 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1142 if ( m_dropTarget
!= 0 ) {
1143 delete m_dropTarget
;
1146 m_dropTarget
= pDropTarget
;
1147 if ( m_dropTarget
!= 0 )
1155 // Old style file-manager drag&drop
1156 void wxWindowMac::DragAcceptFiles(bool accept
)
1161 // Returns the size of the native control. In the case of the toplevel window
1162 // this is the content area root control
1164 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1165 int& w
, int& h
) const
1167 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1170 // From a wx position / size calculate the appropriate size of the native control
1172 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1175 int& w
, int& h
, bool adjustOrigin
) const
1177 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1179 // the desired size, minus the border pixels gives the correct size of the control
1183 // todo the default calls may be used as soon as PostCreateControl Is moved here
1184 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1185 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1187 if ( !isCompositing
)
1188 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1190 x
+= MacGetLeftBorderSize() ;
1191 y
+= MacGetTopBorderSize() ;
1192 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1193 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1196 AdjustForParentClientOrigin( x
, y
) ;
1198 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1199 if ( !GetParent()->IsTopLevel() )
1201 x
-= GetParent()->MacGetLeftBorderSize() ;
1202 y
-= GetParent()->MacGetTopBorderSize() ;
1208 // Get window size (not client size)
1209 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1212 m_peer
->GetRect( &bounds
) ;
1214 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1215 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1218 // get the position of the bounds of this window in client coordinates of its parent
1219 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1222 m_peer
->GetRect( &bounds
) ;
1224 int x1
= bounds
.left
;
1225 int y1
= bounds
.top
;
1227 // get the wx window position from the native one
1228 x1
-= MacGetLeftBorderSize() ;
1229 y1
-= MacGetTopBorderSize() ;
1231 if ( !IsTopLevel() )
1233 wxWindow
*parent
= GetParent();
1236 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1237 x1
+= parent
->MacGetLeftBorderSize() ;
1238 y1
+= parent
->MacGetTopBorderSize() ;
1239 // and now to client coordinates
1240 wxPoint
pt(parent
->GetClientAreaOrigin());
1249 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1251 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1253 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1256 Point localwhere
= {0,0} ;
1258 if(x
) localwhere
.h
= * x
;
1259 if(y
) localwhere
.v
= * y
;
1261 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1262 if(x
) *x
= localwhere
.h
;
1263 if(y
) *y
= localwhere
.v
;
1266 MacRootWindowToWindow( x
, y
) ;
1268 wxPoint origin
= GetClientAreaOrigin() ;
1269 if(x
) *x
-= origin
.x
;
1270 if(y
) *y
-= origin
.y
;
1273 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1275 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1276 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1278 wxPoint origin
= GetClientAreaOrigin() ;
1279 if(x
) *x
+= origin
.x
;
1280 if(y
) *y
+= origin
.y
;
1282 MacWindowToRootWindow( x
, y
) ;
1285 Point localwhere
= { 0,0 };
1286 if(x
) localwhere
.h
= * x
;
1287 if(y
) localwhere
.v
= * y
;
1288 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1289 if(x
) *x
= localwhere
.h
;
1290 if(y
) *y
= localwhere
.v
;
1294 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1296 wxPoint origin
= GetClientAreaOrigin() ;
1297 if(x
) *x
+= origin
.x
;
1298 if(y
) *y
+= origin
.y
;
1300 MacWindowToRootWindow( x
, y
) ;
1303 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1305 MacRootWindowToWindow( x
, y
) ;
1307 wxPoint origin
= GetClientAreaOrigin() ;
1308 if(x
) *x
-= origin
.x
;
1309 if(y
) *y
-= origin
.y
;
1312 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1315 if ( x
) pt
.x
= *x
;
1316 if ( y
) pt
.y
= *y
;
1318 if ( !IsTopLevel() )
1320 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1323 pt
.x
-= MacGetLeftBorderSize() ;
1324 pt
.y
-= MacGetTopBorderSize() ;
1325 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1329 if ( x
) *x
= (int) pt
.x
;
1330 if ( y
) *y
= (int) pt
.y
;
1333 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1338 MacWindowToRootWindow( &x1
, &y1
) ;
1343 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1346 if ( x
) pt
.x
= *x
;
1347 if ( y
) pt
.y
= *y
;
1349 if ( !IsTopLevel() )
1351 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1354 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1355 pt
.x
+= MacGetLeftBorderSize() ;
1356 pt
.y
+= MacGetTopBorderSize() ;
1360 if ( x
) *x
= (int) pt
.x
;
1361 if ( y
) *y
= (int) pt
.y
;
1364 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1369 MacRootWindowToWindow( &x1
, &y1
) ;
1374 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1376 RgnHandle rgn
= NewRgn() ;
1377 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1381 GetRegionBounds( rgn
, &content
) ;
1382 m_peer
->GetRect( &structure
) ;
1383 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1385 left
= content
.left
- structure
.left
;
1386 top
= content
.top
- structure
.top
;
1387 right
= structure
.right
- content
.right
;
1388 bottom
= structure
.bottom
- content
.bottom
;
1392 left
= top
= right
= bottom
= 0 ;
1397 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1399 wxSize sizeTotal
= size
;
1401 RgnHandle rgn
= NewRgn() ;
1403 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1407 GetRegionBounds( rgn
, &content
) ;
1409 m_peer
->GetRect( &structure
) ;
1410 // structure is in parent coordinates, but we only need width and height, so it's ok
1412 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1413 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1417 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1418 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1424 // Get size *available for subwindows* i.e. excluding menu bar etc.
1425 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1429 RgnHandle rgn
= NewRgn() ;
1431 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1433 GetRegionBounds( rgn
, &content
) ;
1437 m_peer
->GetRect( &content
) ;
1441 ww
= content
.right
- content
.left
;
1442 hh
= content
.bottom
- content
.top
;
1444 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1446 hh
-= m_hScrollBar
->GetSize().y
;
1448 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1450 ww
-= m_vScrollBar
->GetSize().x
;
1457 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1459 if (m_cursor
== cursor
)
1462 if (wxNullCursor
== cursor
)
1464 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1469 if ( ! wxWindowBase::SetCursor( cursor
) )
1473 wxASSERT_MSG( m_cursor
.Ok(),
1474 wxT("cursor must be valid after call to the base version"));
1477 wxWindowMac
*mouseWin
= 0 ;
1479 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1480 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1482 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1484 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1485 // position, use it...
1489 ControlPartCode part
;
1490 ControlRef control
;
1491 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1493 mouseWin
= wxFindControlFromMacControl( control
) ;
1496 QDSwapPort( savePort
, NULL
) ;
1499 if ( mouseWin
== this && !wxIsBusy() )
1501 m_cursor
.MacInstall() ;
1508 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1510 menu
->SetInvokingWindow(this);
1513 if ( x
== -1 && y
== -1 )
1515 wxPoint mouse
= wxGetMousePosition();
1516 x
= mouse
.x
; y
= mouse
.y
;
1520 ClientToScreen( &x
, &y
) ;
1523 menu
->MacBeforeDisplay( true ) ;
1524 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1525 if ( HiWord(menuResult
) != 0 )
1528 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1529 wxMenuItem
* item
= NULL
;
1531 item
= menu
->FindItem(id
, &realmenu
) ;
1532 if (item
->IsCheckable())
1534 item
->Check( !item
->IsChecked() ) ;
1536 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1538 menu
->MacAfterDisplay( true ) ;
1540 menu
->SetInvokingWindow(NULL
);
1546 // ----------------------------------------------------------------------------
1548 // ----------------------------------------------------------------------------
1552 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1554 wxWindowBase::DoSetToolTip(tooltip
);
1557 m_tooltip
->SetWindow(this);
1560 #endif // wxUSE_TOOLTIPS
1562 void wxWindowMac::MacInvalidateBorders()
1564 if ( m_peer
== NULL
)
1567 bool vis
= MacIsReallyShown() ;
1571 int outerBorder
= MacGetLeftBorderSize() ;
1572 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1575 if ( outerBorder
== 0 )
1578 // now we know that we have something to do at all
1580 // as the borders are drawn on the parent we have to properly invalidate all these areas
1581 RgnHandle updateInner
= NewRgn() ,
1582 updateOuter
= NewRgn() ;
1584 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1586 m_peer
->GetRect( &rect
) ;
1587 RectRgn( updateInner
, &rect
) ;
1588 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1589 RectRgn( updateOuter
, &rect
) ;
1590 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1591 #ifdef __WXMAC_OSX__
1592 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1594 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1596 InvalWindowRgn( tlw
, updateOuter
) ;
1598 DisposeRgn(updateOuter
) ;
1599 DisposeRgn(updateInner
) ;
1601 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1602 RectRgn( updateInner , &rect ) ;
1603 InsetRect( &rect , -4 , -4 ) ;
1604 RectRgn( updateOuter , &rect ) ;
1605 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1606 wxPoint parent(0,0);
1607 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1608 parent -= GetParent()->GetClientAreaOrigin() ;
1609 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1610 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1611 DisposeRgn(updateOuter) ;
1612 DisposeRgn(updateInner) ;
1617 // deleting a window while it is shown invalidates the region occupied by border or
1620 if ( IsShown() && ( outerBorder > 0 ) )
1622 // as the borders are drawn on the parent we have to properly invalidate all these areas
1623 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1627 m_peer->GetRect( &rect ) ;
1628 RectRgn( updateInner , &rect ) ;
1629 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1630 RectRgn( updateOuter , &rect ) ;
1631 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1632 wxPoint parent(0,0);
1633 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1634 parent -= GetParent()->GetClientAreaOrigin() ;
1635 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1636 CopyRgn( updateOuter , updateTotal ) ;
1638 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1639 DisposeRgn(updateOuter) ;
1640 DisposeRgn(updateInner) ;
1641 DisposeRgn(updateTotal) ;
1646 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1648 int outerBorder
= MacGetLeftBorderSize() ;
1649 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1652 if ( vis
&& ( outerBorder
> 0 ) )
1654 // as the borders are drawn on the parent we have to properly invalidate all these areas
1655 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1659 m_peer
->GetRect( &rect
) ;
1660 RectRgn( updateInner
, &rect
) ;
1661 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1662 RectRgn( updateOuter
, &rect
) ;
1663 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1665 wxPoint parent(0,0);
1666 #if TARGET_API_MAC_OSX
1667 // no offsetting needed when compositing
1669 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1670 parent -= GetParent()->GetClientAreaOrigin() ;
1671 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1674 CopyRgn( updateOuter
, updateTotal
) ;
1677 RectRgn( updateInner
, &rect
) ;
1678 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1679 RectRgn( updateOuter
, &rect
) ;
1680 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1682 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1684 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1686 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1687 DisposeRgn(updateOuter
) ;
1688 DisposeRgn(updateInner
) ;
1689 DisposeRgn(updateTotal
) ;
1694 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1696 // this is never called for a toplevel window, so we know we have a parent
1697 int former_x
, former_y
, former_w
, former_h
;
1699 // Get true coordinates of former position
1700 DoGetPosition( &former_x
, &former_y
) ;
1701 DoGetSize( &former_w
, &former_h
) ;
1703 wxWindow
*parent
= GetParent();
1706 wxPoint
pt(parent
->GetClientAreaOrigin());
1711 int actualWidth
= width
;
1712 int actualHeight
= height
;
1716 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1717 actualWidth
= m_minWidth
;
1718 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1719 actualHeight
= m_minHeight
;
1720 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1721 actualWidth
= m_maxWidth
;
1722 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1723 actualHeight
= m_maxHeight
;
1725 bool doMove
= false ;
1726 bool doResize
= false ;
1728 if ( actualX
!= former_x
|| actualY
!= former_y
)
1732 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1737 if ( doMove
|| doResize
)
1739 // as the borders are drawn outside the native control, we adjust now
1741 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1742 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1743 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1746 wxMacRectToNative( &bounds
, &r
) ;
1748 if ( !GetParent()->IsTopLevel() )
1750 wxMacWindowToNative( GetParent() , &r
) ;
1753 MacInvalidateBorders() ;
1755 m_cachedClippedRectValid
= false ;
1756 m_peer
->SetRect( &r
) ;
1758 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1760 MacInvalidateBorders() ;
1762 MacRepositionScrollBars() ;
1765 wxPoint
point(actualX
,actualY
);
1766 wxMoveEvent
event(point
, m_windowId
);
1767 event
.SetEventObject(this);
1768 GetEventHandler()->ProcessEvent(event
) ;
1772 MacRepositionScrollBars() ;
1773 wxSize
size(actualWidth
, actualHeight
);
1774 wxSizeEvent
event(size
, m_windowId
);
1775 event
.SetEventObject(this);
1776 GetEventHandler()->ProcessEvent(event
);
1782 wxSize
wxWindowMac::DoGetBestSize() const
1784 if ( m_macIsUserPane
|| IsTopLevel() )
1785 return wxWindowBase::DoGetBestSize() ;
1787 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1788 int bestWidth
, bestHeight
;
1789 m_peer
->GetBestRect( &bestsize
) ;
1791 if ( EmptyRect( &bestsize
) )
1793 bestsize
.left
= bestsize
.top
= 0 ;
1794 bestsize
.right
= 16 ;
1795 bestsize
.bottom
= 16 ;
1796 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1798 bestsize
.bottom
= 16 ;
1801 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1803 bestsize
.bottom
= 24 ;
1805 #endif // wxUSE_SPINBTN
1808 // return wxWindowBase::DoGetBestSize() ;
1812 bestWidth
= bestsize
.right
- bestsize
.left
;
1813 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1814 if ( bestHeight
< 10 )
1817 return wxSize(bestWidth
, bestHeight
);
1821 // set the size of the window: if the dimensions are positive, just use them,
1822 // but if any of them is equal to -1, it means that we must find the value for
1823 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1824 // which case -1 is a valid value for x and y)
1826 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1827 // the width/height to best suit our contents, otherwise we reuse the current
1829 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1831 // get the current size and position...
1832 int currentX
, currentY
;
1833 GetPosition(¤tX
, ¤tY
);
1835 int currentW
,currentH
;
1836 GetSize(¤tW
, ¤tH
);
1838 // ... and don't do anything (avoiding flicker) if it's already ok
1839 if ( x
== currentX
&& y
== currentY
&&
1840 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1843 MacRepositionScrollBars() ; // we might have a real position shift
1847 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1849 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1852 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1854 wxSize
size(-1, -1);
1857 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1859 size
= DoGetBestSize();
1864 // just take the current one
1871 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1875 size
= DoGetBestSize();
1877 //else: already called DoGetBestSize() above
1883 // just take the current one
1888 DoMoveWindow(x
, y
, width
, height
);
1892 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1894 RgnHandle rgn
= NewRgn() ;
1896 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1898 GetRegionBounds( rgn
, &content
) ;
1902 content
.left
= content
.top
= 0 ;
1905 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1908 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1910 if ( clientheight
!= -1 || clientheight
!= -1 )
1912 int currentclientwidth
, currentclientheight
;
1913 int currentwidth
, currentheight
;
1915 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1916 GetSize( ¤twidth
, ¤theight
) ;
1918 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1919 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1923 void wxWindowMac::SetTitle(const wxString
& title
)
1925 m_label
= wxStripMenuCodes(title
) ;
1927 if ( m_peer
&& m_peer
->Ok() )
1929 m_peer
->SetTitle( m_label
) ;
1934 wxString
wxWindowMac::GetTitle() const
1939 bool wxWindowMac::Show(bool show
)
1941 bool former
= MacIsReallyShown() ;
1942 if ( !wxWindowBase::Show(show
) )
1945 // TODO use visibilityChanged Carbon Event for OSX
1948 m_peer
->SetVisibility( show
, true ) ;
1950 if ( former
!= MacIsReallyShown() )
1951 MacPropagateVisibilityChanged() ;
1955 bool wxWindowMac::Enable(bool enable
)
1957 wxASSERT( m_peer
->Ok() ) ;
1958 bool former
= MacIsReallyEnabled() ;
1959 if ( !wxWindowBase::Enable(enable
) )
1962 m_peer
->Enable( enable
) ;
1964 if ( former
!= MacIsReallyEnabled() )
1965 MacPropagateEnabledStateChanged() ;
1970 // status change propagations (will be not necessary for OSX later )
1973 void wxWindowMac::MacPropagateVisibilityChanged()
1975 #if !TARGET_API_MAC_OSX
1976 MacVisibilityChanged() ;
1978 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1981 wxWindowMac
*child
= node
->GetData();
1982 if ( child
->IsShown() )
1983 child
->MacPropagateVisibilityChanged( ) ;
1984 node
= node
->GetNext();
1989 void wxWindowMac::MacPropagateEnabledStateChanged( )
1991 #if !TARGET_API_MAC_OSX
1992 MacEnabledStateChanged() ;
1994 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1997 wxWindowMac
*child
= node
->GetData();
1998 if ( child
->IsEnabled() )
1999 child
->MacPropagateEnabledStateChanged() ;
2000 node
= node
->GetNext();
2005 void wxWindowMac::MacPropagateHiliteChanged( )
2007 #if !TARGET_API_MAC_OSX
2008 MacHiliteChanged() ;
2010 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2013 wxWindowMac
*child
= node
->GetData();
2014 // if ( child->IsEnabled() )
2015 child
->MacPropagateHiliteChanged() ;
2016 node
= node
->GetNext();
2022 // status change notifications
2025 void wxWindowMac::MacVisibilityChanged()
2029 void wxWindowMac::MacHiliteChanged()
2033 void wxWindowMac::MacEnabledStateChanged()
2038 // status queries on the inherited window's state
2041 bool wxWindowMac::MacIsReallyShown()
2043 // only under OSX the visibility of the TLW is taken into account
2044 if ( m_isBeingDeleted
)
2047 #if TARGET_API_MAC_OSX
2048 if ( m_peer
&& m_peer
->Ok() )
2049 return m_peer
->IsVisible();
2051 wxWindow
* win
= this ;
2052 while( win
->IsShown() )
2054 if ( win
->IsTopLevel() )
2057 win
= win
->GetParent() ;
2065 bool wxWindowMac::MacIsReallyEnabled()
2067 return m_peer
->IsEnabled() ;
2070 bool wxWindowMac::MacIsReallyHilited()
2072 return m_peer
->IsActive();
2075 void wxWindowMac::MacFlashInvalidAreas()
2077 #if TARGET_API_MAC_OSX
2078 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2086 int wxWindowMac::GetCharHeight() const
2088 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2089 return dc
.GetCharHeight() ;
2092 int wxWindowMac::GetCharWidth() const
2094 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2095 return dc
.GetCharWidth() ;
2098 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2099 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2101 const wxFont
*fontToUse
= theFont
;
2103 fontToUse
= &m_font
;
2105 wxClientDC
dc( (wxWindowMac
*) this ) ;
2107 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2108 if ( externalLeading
)
2109 *externalLeading
= le
;
2119 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2120 * we always intersect with the entire window, not only with the client area
2123 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2125 if ( m_peer
== NULL
)
2128 if ( !MacIsReallyShown() )
2134 wxMacRectToNative( rect
, &r
) ;
2135 m_peer
->SetNeedsDisplay( &r
) ;
2139 m_peer
->SetNeedsDisplay() ;
2143 void wxWindowMac::Freeze()
2145 #if TARGET_API_MAC_OSX
2146 if ( !m_frozenness
++ )
2148 if ( m_peer
&& m_peer
->Ok() )
2149 m_peer
->SetDrawingEnabled( false ) ;
2155 void wxWindowMac::Thaw()
2157 #if TARGET_API_MAC_OSX
2158 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2160 if ( !--m_frozenness
)
2162 if ( m_peer
&& m_peer
->Ok() )
2164 m_peer
->SetDrawingEnabled( true ) ;
2165 m_peer
->InvalidateWithChildren() ;
2171 wxWindowMac
*wxGetActiveWindow()
2173 // actually this is a windows-only concept
2177 // Coordinates relative to the window
2178 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2180 // We really don't move the mouse programmatically under Mac.
2183 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2185 #if TARGET_API_MAC_OSX
2186 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2193 event
.GetDC()->Clear() ;
2197 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2202 int wxWindowMac::GetScrollPos(int orient
) const
2204 if ( orient
== wxHORIZONTAL
)
2207 return m_hScrollBar
->GetThumbPosition() ;
2212 return m_vScrollBar
->GetThumbPosition() ;
2217 // This now returns the whole range, not just the number
2218 // of positions that we can scroll.
2219 int wxWindowMac::GetScrollRange(int orient
) const
2221 if ( orient
== wxHORIZONTAL
)
2224 return m_hScrollBar
->GetRange() ;
2229 return m_vScrollBar
->GetRange() ;
2234 int wxWindowMac::GetScrollThumb(int orient
) const
2236 if ( orient
== wxHORIZONTAL
)
2239 return m_hScrollBar
->GetThumbSize() ;
2244 return m_vScrollBar
->GetThumbSize() ;
2249 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2251 if ( orient
== wxHORIZONTAL
)
2254 m_hScrollBar
->SetThumbPosition( pos
) ;
2259 m_vScrollBar
->SetThumbPosition( pos
) ;
2264 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2265 // our own window origin is at leftOrigin/rightOrigin
2268 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2274 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2275 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2277 m_peer
->GetRect( &rect
) ;
2278 // back to the surrounding frame rectangle
2279 InsetRect( &rect
, -1 , -1 ) ;
2281 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2282 if ( UMAGetSystemVersion() >= 0x1030 )
2284 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2285 rect
.bottom
- rect
.top
) ;
2287 HIThemeFrameDrawInfo info
;
2288 memset( &info
, 0 , sizeof( info
) ) ;
2292 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2293 info
.isFocused
= hasFocus
;
2295 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2296 wxASSERT( cgContext
) ;
2298 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2300 info
.kind
= kHIThemeFrameTextFieldSquare
;
2301 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2303 else if (HasFlag(wxSIMPLE_BORDER
))
2305 info
.kind
= kHIThemeFrameListBox
;
2306 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2308 else if ( hasFocus
)
2310 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2313 m_peer
->GetRect( &rect
) ;
2314 if ( hasBothScrollbars
)
2316 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2317 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2318 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2319 HIThemeGrowBoxDrawInfo info
;
2320 memset( &info
, 0 , sizeof( info
) ) ;
2322 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2323 info
.kind
= kHIThemeGrowBoxKindNone
;
2324 info
.size
= kHIThemeGrowBoxSizeNormal
;
2325 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2326 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2332 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2336 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2337 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2340 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2342 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2344 else if (HasFlag(wxSIMPLE_BORDER
))
2346 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2351 DrawThemeFocusRect( &rect
, true ) ;
2354 if ( hasBothScrollbars
)
2356 // GetThemeStandaloneGrowBoxBounds
2357 //DrawThemeStandaloneNoGrowBox
2362 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2364 if ( child
== m_hScrollBar
)
2365 m_hScrollBar
= NULL
;
2366 if ( child
== m_vScrollBar
)
2367 m_vScrollBar
= NULL
;
2369 wxWindowBase::RemoveChild( child
) ;
2372 // New function that will replace some of the above.
2373 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2374 int range
, bool refresh
)
2376 if ( orient
== wxHORIZONTAL
)
2380 if ( range
== 0 || thumbVisible
>= range
)
2382 if ( m_hScrollBar
->IsShown() )
2383 m_hScrollBar
->Show(false) ;
2387 if ( !m_hScrollBar
->IsShown() )
2388 m_hScrollBar
->Show(true) ;
2390 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2397 if ( range
== 0 || thumbVisible
>= range
)
2399 if ( m_vScrollBar
->IsShown() )
2400 m_vScrollBar
->Show(false) ;
2404 if ( !m_vScrollBar
->IsShown() )
2405 m_vScrollBar
->Show(true) ;
2407 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2410 MacRepositionScrollBars() ;
2413 // Does a physical scroll
2414 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2416 if( dx
== 0 && dy
==0 )
2419 int width
, height
;
2420 GetClientSize( &width
, &height
) ;
2421 #if TARGET_API_MAC_OSX
2422 if ( 1 /* m_peer->IsCompositing() */ )
2424 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2425 // area is scrolled, this does not occur if width and height are 2 pixels less,
2426 // TODO write optimal workaround
2427 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2430 scrollrect
.Intersect( *rect
) ;
2432 if ( m_peer
->GetNeedsDisplay() )
2434 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2435 // either immediate redraw or full invalidate
2437 // is the better overall solution, as it does not slow down scrolling
2438 m_peer
->SetNeedsDisplay() ;
2440 // this would be the preferred version for fast drawing controls
2442 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2443 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2444 HIViewRender(m_peer
->GetControlRef()) ;
2450 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2451 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2452 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2454 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2455 // either immediate redraw or full invalidate
2457 // is the better overall solution, as it does not slow down scrolling
2458 m_peer
->SetNeedsDisplay() ;
2460 // this would be the preferred version for fast drawing controls
2462 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2463 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2464 HIViewRender(m_peer
->GetControlRef()) ;
2479 RgnHandle updateRgn
= NewRgn() ;
2482 wxClientDC
dc(this) ;
2483 wxMacPortSetter
helper(&dc
) ;
2485 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2486 //scrollrect.top += MacGetTopBorderSize() ;
2487 //scrollrect.left += MacGetLeftBorderSize() ;
2488 scrollrect
.bottom
= scrollrect
.top
+ height
;
2489 scrollrect
.right
= scrollrect
.left
+ width
;
2493 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2494 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2495 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2497 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2499 // now scroll the former update region as well and add the new update region
2501 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2502 RgnHandle formerUpdateRgn
= NewRgn() ;
2503 RgnHandle scrollRgn
= NewRgn() ;
2504 RectRgn( scrollRgn
, &scrollrect
) ;
2505 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2507 LocalToGlobal( &pt
) ;
2508 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2509 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2510 if ( !EmptyRgn( formerUpdateRgn
) )
2512 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2513 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2514 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2516 InvalWindowRgn(rootWindow
, updateRgn
) ;
2517 DisposeRgn( updateRgn
) ;
2518 DisposeRgn( formerUpdateRgn
) ;
2519 DisposeRgn( scrollRgn
) ;
2524 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2526 wxWindowMac
*child
= node
->GetData();
2527 if (child
== m_vScrollBar
) continue;
2528 if (child
== m_hScrollBar
) continue;
2529 if (child
->IsTopLevel()) continue;
2532 child
->GetPosition( &x
, &y
);
2534 child
->GetSize( &w
, &h
);
2538 if (rect
->Intersects(rc
))
2539 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2543 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2548 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2550 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2552 wxScrollWinEvent wevent
;
2553 wevent
.SetPosition(event
.GetPosition());
2554 wevent
.SetOrientation(event
.GetOrientation());
2555 wevent
.SetEventObject(this);
2557 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2558 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2559 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2560 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2561 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2562 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2563 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2564 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2565 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2566 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2567 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2568 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2569 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2570 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2571 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2572 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2574 GetEventHandler()->ProcessEvent(wevent
);
2578 // Get the window with the focus
2579 wxWindowMac
*wxWindowBase::DoFindFocus()
2581 ControlRef control
;
2582 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2583 return wxFindControlFromMacControl( control
) ;
2586 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2588 // panel wants to track the window which was the last to have focus in it,
2589 // so we want to set ourselves as the window which last had focus
2591 // notice that it's also important to do it upwards the tree becaus
2592 // otherwise when the top level panel gets focus, it won't set it back to
2593 // us, but to some other sibling
2595 // CS:don't know if this is still needed:
2596 //wxChildFocusEvent eventFocus(this);
2597 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2599 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2601 #if !wxMAC_USE_CORE_GRAPHICS
2602 wxMacWindowStateSaver
sv( this ) ;
2604 m_peer
->GetRect( &rect
) ;
2605 // auf den umgebenden Rahmen zur\9fck
2606 InsetRect( &rect
, -1 , -1 ) ;
2608 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2612 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2614 rect
.right
+= pt
.x
;
2616 rect
.bottom
+= pt
.y
;
2619 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2620 DrawThemeFocusRect( &rect
, true ) ;
2623 DrawThemeFocusRect( &rect
, false ) ;
2625 // as this erases part of the frame we have to redraw borders
2626 // and because our z-ordering is not always correct (staticboxes)
2627 // we have to invalidate things, we cannot simple redraw
2628 MacInvalidateBorders() ;
2631 GetParent()->Refresh() ;
2638 void wxWindowMac::OnInternalIdle()
2640 // This calls the UI-update mechanism (querying windows for
2641 // menu/toolbar/control state information)
2642 if (wxUpdateUIEvent::CanUpdate(this))
2643 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2646 // Raise the window to the top of the Z order
2647 void wxWindowMac::Raise()
2649 m_peer
->SetZOrder( true , NULL
) ;
2652 // Lower the window to the bottom of the Z order
2653 void wxWindowMac::Lower()
2655 m_peer
->SetZOrder( false , NULL
) ;
2659 // static wxWindow *gs_lastWhich = NULL;
2661 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2663 // first trigger a set cursor event
2665 wxPoint clientorigin
= GetClientAreaOrigin() ;
2666 wxSize clientsize
= GetClientSize() ;
2668 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2670 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2672 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2673 if ( processedEvtSetCursor
&& event
.HasCursor() )
2675 cursor
= event
.GetCursor() ;
2680 // the test for processedEvtSetCursor is here to prevent using m_cursor
2681 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2682 // it - this is a way to say that our cursor shouldn't be used for this
2684 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2694 cursor
= *wxSTANDARD_CURSOR
;
2698 cursor
.MacInstall() ;
2700 return cursor
.Ok() ;
2703 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2708 return m_tooltip
->GetTip() ;
2711 return wxEmptyString
;
2714 void wxWindowMac::ClearBackground()
2720 void wxWindowMac::Update()
2722 #if TARGET_API_MAC_OSX
2723 MacGetTopLevelWindow()->MacPerformUpdates() ;
2725 ::Draw1Control( m_peer
->GetControlRef() ) ;
2729 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2731 wxTopLevelWindowMac
* win
= NULL
;
2732 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2735 win
= wxFindWinFromMacWindow( window
) ;
2740 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2742 MacUpdateClippedRects() ;
2743 return m_cachedClippedClientRect
;
2746 const wxRect
& wxWindowMac::MacGetClippedRect() const
2748 MacUpdateClippedRects() ;
2749 return m_cachedClippedRect
;
2752 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2754 MacUpdateClippedRects() ;
2755 return m_cachedClippedRectWithOuterStructure
;
2758 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2760 static wxRegion emptyrgn
;
2761 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2763 MacUpdateClippedRects() ;
2764 if ( includeOuterStructures
)
2765 return m_cachedClippedRegionWithOuterStructure
;
2767 return m_cachedClippedRegion
;
2775 void wxWindowMac::MacUpdateClippedRects() const
2777 if ( m_cachedClippedRectValid
)
2780 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2781 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2782 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2783 // to add focus borders everywhere
2786 Rect rIncludingOuterStructures
;
2788 m_peer
->GetRect( &r
) ;
2789 r
.left
-= MacGetLeftBorderSize() ;
2790 r
.top
-= MacGetTopBorderSize() ;
2791 r
.bottom
+= MacGetBottomBorderSize() ;
2792 r
.right
+= MacGetRightBorderSize() ;
2799 rIncludingOuterStructures
= r
;
2800 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2802 wxRect cl
= GetClientRect() ;
2803 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2805 const wxWindow
* child
= this ;
2806 const wxWindow
* parent
= NULL
;
2807 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2812 if ( parent
->MacIsChildOfClientArea(child
) )
2814 size
= parent
->GetClientSize() ;
2815 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2821 // this will be true for scrollbars, toolbars etc.
2822 size
= parent
->GetSize() ;
2823 y
= parent
->MacGetTopBorderSize() ;
2824 x
= parent
->MacGetLeftBorderSize() ;
2825 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2826 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2829 parent
->MacWindowToRootWindow( &x
, &y
) ;
2830 MacRootWindowToWindow( &x
, &y
) ;
2832 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2834 // the wxwindow and client rects will always be clipped
2835 SectRect( &r
, &rparent
, &r
) ;
2836 SectRect( &rClient
, &rparent
, &rClient
) ;
2838 // the structure only at 'hard' borders
2839 if ( parent
->MacClipChildren() ||
2840 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2842 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2847 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2848 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2849 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2850 m_cachedClippedRectWithOuterStructure
= wxRect(
2851 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2852 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2853 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2855 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2856 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2857 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2859 m_cachedClippedRectValid
= true ;
2863 This function must not change the updatergn !
2865 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2867 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2868 bool handled
= false ;
2870 GetRegionBounds( updatergn
, &updatebounds
) ;
2872 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2874 if ( !EmptyRgn(updatergn
) )
2876 RgnHandle newupdate
= NewRgn() ;
2877 wxSize point
= GetClientSize() ;
2878 wxPoint origin
= GetClientAreaOrigin() ;
2879 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2880 SectRgn( newupdate
, updatergn
, newupdate
) ;
2882 // first send an erase event to the entire update area
2884 // for the toplevel window this really is the entire area
2885 // for all the others only their client area, otherwise they
2886 // might be drawing with full alpha and eg put blue into
2887 // the grow-box area of a scrolled window (scroll sample)
2888 wxDC
* dc
= new wxWindowDC(this);
2890 dc
->SetClippingRegion(wxRegion(updatergn
));
2892 dc
->SetClippingRegion(wxRegion(newupdate
));
2894 wxEraseEvent
eevent( GetId(), dc
);
2895 eevent
.SetEventObject( this );
2896 GetEventHandler()->ProcessEvent( eevent
);
2900 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2901 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2902 m_updateRegion
= newupdate
;
2903 DisposeRgn( newupdate
) ;
2905 if ( !m_updateRegion
.Empty() )
2907 // paint the window itself
2910 event
.SetTimestamp(time
);
2911 event
.SetEventObject(this);
2912 GetEventHandler()->ProcessEvent(event
);
2916 // now we cannot rely on having its borders drawn by a window itself, as it does not
2917 // get the updateRgn wide enough to always do so, so we do it from the parent
2918 // this would also be the place to draw any custom backgrounds for native controls
2919 // in Composited windowing
2920 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2922 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2924 wxWindowMac
*child
= node
->GetData();
2925 if (child
== m_vScrollBar
) continue;
2926 if (child
== m_hScrollBar
) continue;
2927 if (child
->IsTopLevel()) continue;
2928 if (!child
->IsShown()) continue;
2930 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2933 child
->GetPosition( &x
, &y
);
2935 child
->GetSize( &w
, &h
);
2936 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2937 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2938 InsetRect( &childRect
, -10 , -10) ;
2940 if ( RectInRgn( &childRect
, updatergn
) )
2943 // paint custom borders
2944 wxNcPaintEvent
eventNc( child
->GetId() );
2945 eventNc
.SetEventObject( child
);
2946 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2948 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2949 if ( UMAGetSystemVersion() >= 0x1030 )
2951 child
->MacPaintBorders(0,0) ;
2956 wxWindowDC
dc(this) ;
2957 dc
.SetClippingRegion(wxRegion(updatergn
));
2958 wxMacPortSetter
helper(&dc
) ;
2959 child
->MacPaintBorders(0,0) ;
2969 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2971 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2975 if ( iter
->IsTopLevel() )
2976 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2978 iter
= iter
->GetParent() ;
2980 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2984 void wxWindowMac::MacCreateScrollBars( long style
)
2986 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2988 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2990 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2991 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2992 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2993 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2995 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2996 variant
= wxWINDOW_VARIANT_SMALL
;
2999 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3001 GetClientSize( &width
, &height
) ;
3003 wxPoint
vPoint(width
-scrlsize
, 0) ;
3004 wxSize
vSize(scrlsize
, height
- adjust
) ;
3005 wxPoint
hPoint(0 , height
-scrlsize
) ;
3006 wxSize
hSize( width
- adjust
, scrlsize
) ;
3009 if ( style
& wxVSCROLL
)
3011 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3012 vSize
, wxVERTICAL
);
3015 if ( style
& wxHSCROLL
)
3017 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3018 hSize
, wxHORIZONTAL
);
3023 // because the create does not take into account the client area origin
3024 MacRepositionScrollBars() ; // we might have a real position shift
3027 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3029 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3035 void wxWindowMac::MacRepositionScrollBars()
3037 if ( !m_hScrollBar
&& !m_vScrollBar
)
3040 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3041 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3042 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3044 // get real client area
3048 GetSize( &width
, &height
) ;
3050 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3051 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3053 wxPoint
vPoint(width
-scrlsize
, 0) ;
3054 wxSize
vSize(scrlsize
, height
- adjust
) ;
3055 wxPoint
hPoint(0 , height
-scrlsize
) ;
3056 wxSize
hSize( width
- adjust
, scrlsize
) ;
3062 GetSize( &w , &h ) ;
3064 MacClientToRootWindow( &x , &y ) ;
3065 MacClientToRootWindow( &w , &h ) ;
3067 wxWindowMac *iter = (wxWindowMac*)this ;
3069 int totW = 10000 , totH = 10000;
3072 if ( iter->IsTopLevel() )
3074 iter->GetSize( &totW , &totH ) ;
3078 iter = iter->GetParent() ;
3106 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3110 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3114 bool wxWindowMac::AcceptsFocus() const
3116 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3119 void wxWindowMac::MacSuperChangedPosition()
3121 m_cachedClippedRectValid
= false ;
3122 // only window-absolute structures have to be moved i.e. controls
3124 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3127 wxWindowMac
*child
= node
->GetData();
3128 child
->MacSuperChangedPosition() ;
3129 node
= node
->GetNext();
3133 void wxWindowMac::MacTopLevelWindowChangedPosition()
3135 // only screen-absolute structures have to be moved i.e. glcanvas
3137 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3140 wxWindowMac
*child
= node
->GetData();
3141 child
->MacTopLevelWindowChangedPosition() ;
3142 node
= node
->GetNext();
3146 long wxWindowMac::MacGetLeftBorderSize( ) const
3153 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3155 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3156 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3158 else if (HasFlag(wxSIMPLE_BORDER
))
3160 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3161 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3166 long wxWindowMac::MacGetRightBorderSize( ) const
3168 // they are all symmetric in mac themes
3169 return MacGetLeftBorderSize() ;
3172 long wxWindowMac::MacGetTopBorderSize( ) const
3174 // they are all symmetric in mac themes
3175 return MacGetLeftBorderSize() ;
3178 long wxWindowMac::MacGetBottomBorderSize( ) const
3180 // they are all symmetric in mac themes
3181 return MacGetLeftBorderSize() ;
3184 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3186 return style
& ~wxBORDER_MASK
;
3189 // Find the wxWindowMac at the current mouse position, returning the mouse
3191 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3193 pt
= wxGetMousePosition();
3194 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3198 // Get the current mouse position.
3199 wxPoint
wxGetMousePosition()
3202 wxGetMousePosition(& x
, & y
);
3203 return wxPoint(x
, y
);
3206 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3208 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3210 // copied from wxGTK : CS
3211 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3214 // (a) it's a command event and so is propagated to the parent
3215 // (b) under MSW it can be generated from kbd too
3216 // (c) it uses screen coords (because of (a))
3217 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3219 this->ClientToScreen(event
.GetPosition()));
3220 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3229 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3231 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3233 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3237 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3241 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3245 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3246 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3250 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3252 return eventNotHandledErr
;