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() ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
216 updateRgn
= allocatedRgn
;
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 if ( thisWindow
->MacIsUserPane() )
225 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
226 static float color
= 0.5 ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
244 #if wxMAC_USE_CORE_GRAPHICS
245 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
246 thisWindow
->MacSetCGContextRef( cgContext
) ;
247 wxMacCGContextStateSaver
sg( cgContext
) ;
249 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
251 #if wxMAC_USE_CORE_GRAPHICS
252 thisWindow
->MacSetCGContextRef( NULL
) ;
256 DisposeRgn( allocatedRgn
) ;
259 case kEventControlVisibilityChanged
:
260 thisWindow
->MacVisibilityChanged() ;
262 case kEventControlEnabledStateChanged
:
263 thisWindow
->MacEnabledStateChanged() ;
265 case kEventControlHiliteChanged
:
266 thisWindow
->MacHiliteChanged() ;
268 case kEventControlSetFocusPart
:
270 Boolean focusEverything
= false ;
271 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
272 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
275 if ( controlPart
== kControlFocusNoPart
)
278 if ( thisWindow
->GetCaret() )
280 thisWindow
->GetCaret()->OnKillFocus();
282 #endif // wxUSE_CARET
283 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
284 event
.SetEventObject(thisWindow
);
285 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
289 // panel wants to track the window which was the last to have focus in it
290 wxChildFocusEvent
eventFocus(thisWindow
);
291 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
294 if ( thisWindow
->GetCaret() )
296 thisWindow
->GetCaret()->OnSetFocus();
298 #endif // wxUSE_CARET
300 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
301 event
.SetEventObject(thisWindow
);
302 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
304 if ( thisWindow
->MacIsUserPane() )
309 case kEventControlHit
:
311 result
= thisWindow
->MacControlHit( handler
, event
) ;
320 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
322 OSStatus result
= eventNotHandledErr
;
324 wxMacCarbonEvent
cEvent( event
) ;
326 ControlRef controlRef
;
327 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
328 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
329 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
331 switch( GetEventKind( event
) )
333 case kEventServiceGetTypes
:
337 textCtrl
->GetSelection( &from
, &to
) ;
339 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
341 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
342 if ( textCtrl
->IsEditable() )
343 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
345 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
346 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
348 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
352 CFArrayAppendValue (copyTypes
, typestring
) ;
354 CFArrayAppendValue (pasteTypes
, typestring
) ;
355 CFRelease( typestring
) ;
361 case kEventServiceCopy
:
365 textCtrl
->GetSelection( &from
, &to
) ;
366 wxString val
= textCtrl
->GetValue() ;
367 val
= val
.Mid( from
, to
- from
) ;
368 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
369 verify_noerr( ClearScrap( &scrapRef
) ) ;
370 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
374 case kEventServicePaste
:
377 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
378 Size textSize
, pastedSize
;
379 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
381 char *content
= new char[textSize
] ;
382 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
383 content
[textSize
-1] = 0 ;
385 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
387 textCtrl
->WriteText( wxString( content
) ) ;
398 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
400 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
401 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
402 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
403 OSStatus result
= eventNotHandledErr
;
405 switch ( GetEventClass( event
) )
407 case kEventClassControl
:
408 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
410 case kEventClassService
:
411 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
415 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
419 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
421 #if !TARGET_API_MAC_OSX
423 // ---------------------------------------------------------------------------
424 // UserPane events for non OSX builds
425 // ---------------------------------------------------------------------------
427 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
429 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
430 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
431 win
->MacControlUserPaneDrawProc(part
) ;
434 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
436 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
437 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
438 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
441 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
443 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
444 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
445 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
448 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
450 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
451 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
452 win
->MacControlUserPaneIdleProc() ;
455 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
457 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
458 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
459 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
462 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
464 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
465 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
466 win
->MacControlUserPaneActivateProc(activating
) ;
469 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
471 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
472 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
473 return win
->MacControlUserPaneFocusProc(action
) ;
476 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
478 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
479 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
480 win
->MacControlUserPaneBackgroundProc(info
) ;
483 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
485 RgnHandle rgn
= NewRgn() ;
487 wxMacWindowStateSaver
sv( this ) ;
488 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
489 MacDoRedraw( rgn
, 0 ) ;
493 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
495 return kControlNoPart
;
498 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
500 return kControlNoPart
;
503 void wxWindowMac::MacControlUserPaneIdleProc()
507 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
509 return kControlNoPart
;
512 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
516 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
518 return kControlNoPart
;
521 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
525 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
526 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
527 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
528 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
529 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
530 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
531 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
532 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
536 // ===========================================================================
538 // ===========================================================================
540 #if KEY_wxList_DEPRECATED
541 wxList
wxWinMacControlList(wxKEY_INTEGER
);
543 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
545 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
548 return (wxControl
*)node
->GetData();
551 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
553 // adding NULL ControlRef is (first) surely a result of an error and
554 // (secondly) breaks native event processing
555 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
557 if ( !wxWinMacControlList
.Find((long)inControl
) )
558 wxWinMacControlList
.Append((long)inControl
, control
);
561 void wxRemoveMacControlAssociation(wxWindow
*control
)
563 wxWinMacControlList
.DeleteObject(control
);
567 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
569 static MacControlMap wxWinMacControlList
;
571 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
573 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
575 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
578 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
580 // adding NULL ControlRef is (first) surely a result of an error and
581 // (secondly) breaks native event processing
582 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
584 wxWinMacControlList
[inControl
] = control
;
587 void wxRemoveMacControlAssociation(wxWindow
*control
)
589 // iterate over all the elements in the class
590 MacControlMap::iterator it
;
591 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
593 if ( it
->second
== control
)
595 wxWinMacControlList
.erase(it
);
600 #endif // deprecated wxList
603 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
605 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
607 // we have to setup the brush in the current port and return noErr
608 // or return an error code so that the control manager walks further up the
609 // hierarchy to find a correct background
611 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
613 OSStatus status
= paramErr
;
616 case kControlMsgApplyTextColor
:
618 case kControlMsgSetUpBackground
:
620 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
624 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
627 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
629 // this clipping is only needed for non HIView
631 RgnHandle clip
= NewRgn() ;
634 wx
->MacWindowToRootWindow( &x
,&y
) ;
635 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
636 OffsetRgn( clip
, x
, y
) ;
643 else if ( wx->MacIsUserPane() )
645 // if we don't have a valid brush for such a control, we have to call the
646 // setup of our parent ourselves
647 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
660 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
661 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
665 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
668 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
673 // ----------------------------------------------------------------------------
674 // constructors and such
675 // ----------------------------------------------------------------------------
677 wxWindowMac::wxWindowMac()
682 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
687 const wxString
& name
)
690 Create(parent
, id
, pos
, size
, style
, name
);
693 void wxWindowMac::Init()
697 #if WXWIN_COMPATIBILITY_2_4
698 m_backgroundTransparent
= FALSE
;
701 // as all windows are created with WS_VISIBLE style...
704 m_hScrollBar
= NULL
;
705 m_vScrollBar
= NULL
;
706 m_macBackgroundBrush
= wxNullBrush
;
708 m_macIsUserPane
= TRUE
;
709 #if wxMAC_USE_CORE_GRAPHICS
710 m_cgContextRef
= NULL
;
712 // make sure all proc ptrs are available
714 #if !TARGET_API_MAC_OSX
715 if ( gControlUserPaneDrawUPP
== NULL
)
717 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
718 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
719 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
720 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
721 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
722 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
723 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
724 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
727 if ( wxMacLiveScrollbarActionUPP
== NULL
)
729 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
732 if ( wxMacSetupControlBackgroundUPP
== NULL
)
734 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
737 // we need a valid font for the encodings
738 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
742 wxWindowMac::~wxWindowMac()
746 m_isBeingDeleted
= TRUE
;
750 // deleting a window while it is shown invalidates the region occupied by border or
752 int outerBorder
= MacGetLeftBorderSize() ;
753 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
756 if ( IsShown() && ( outerBorder
> 0 ) )
758 // as the borders are drawn on the parent we have to properly invalidate all these areas
759 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
763 m_peer
->GetRect( &rect
) ;
764 RectRgn( updateInner
, &rect
) ;
765 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
766 RectRgn( updateOuter
, &rect
) ;
767 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
769 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
770 parent
-= GetParent()->GetClientAreaOrigin() ;
771 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
772 CopyRgn( updateOuter
, updateTotal
) ;
774 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
775 DisposeRgn(updateOuter
) ;
776 DisposeRgn(updateInner
) ;
777 DisposeRgn(updateTotal
) ;
781 #ifndef __WXUNIVERSAL__
782 // VS: make sure there's no wxFrame with last focus set to us:
783 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
785 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
788 if ( frame
->GetLastFocus() == this )
790 frame
->SetLastFocus((wxWindow
*)NULL
);
795 #endif // __WXUNIVERSAL__
797 // destroy children before destroying this window itself
800 // wxRemoveMacControlAssociation( this ) ;
801 // If we delete an item, we should initialize the parent panel,
802 // because it could now be invalid.
803 wxWindow
*parent
= GetParent() ;
806 if (parent
->GetDefaultItem() == (wxButton
*) this)
807 parent
->SetDefaultItem(NULL
);
809 if ( m_peer
&& m_peer
->Ok() )
811 // in case the callback might be called during destruction
812 wxRemoveMacControlAssociation( this) ;
813 // we currently are not using this hook
814 // ::SetControlColorProc( *m_peer , NULL ) ;
818 if ( g_MacLastWindow
== this )
820 g_MacLastWindow
= NULL
;
823 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
826 if ( frame
->GetLastFocus() == this )
827 frame
->SetLastFocus( NULL
) ;
830 // delete our drop target if we've got one
831 #if wxUSE_DRAG_AND_DROP
832 if ( m_dropTarget
!= NULL
)
837 #endif // wxUSE_DRAG_AND_DROP
841 WXWidget
wxWindowMac::GetHandle() const
843 return (WXWidget
) m_peer
->GetControlRef() ;
847 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
849 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
850 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
851 GetEventTypeCount(eventList
), eventList
, this,
852 (EventHandlerRef
*)&m_macControlEventHandler
);
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 // | kControlHasSpecialBackground
878 // | kControlSupportsCalcBestRect
879 // | kControlHandlesTracking
880 | kControlSupportsFocus
881 // | kControlWantsActivate
882 // | kControlWantsIdle
885 m_peer
= new wxMacControl() ;
886 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
889 MacPostControlCreate(pos
,size
) ;
890 #if !TARGET_API_MAC_OSX
891 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
892 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
893 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
894 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
895 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
896 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
897 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
898 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
901 #ifndef __WXUNIVERSAL__
902 // Don't give scrollbars to wxControls unless they ask for them
903 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
904 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
906 MacCreateScrollBars( style
) ;
910 wxWindowCreateEvent
event(this);
911 GetEventHandler()->AddPendingEvent(event
);
916 void wxWindowMac::MacChildAdded()
920 m_vScrollBar
->Raise() ;
924 m_hScrollBar
->Raise() ;
929 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
931 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
933 m_peer
->SetReference( (long) this ) ;
934 GetParent()->AddChild(this);
936 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
938 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
939 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
940 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
941 GetParent()->MacChildAdded() ;
943 // adjust font, controlsize etc
944 DoSetWindowVariant( m_windowVariant
) ;
946 #if !TARGET_API_MAC_OSX
947 // eventually we can fix some clipping issues be reactivating this hook
948 //if ( m_macIsUserPane )
949 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
951 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
953 if (!m_macIsUserPane
)
955 SetInitialBestSize(size
);
958 SetCursor( *wxSTANDARD_CURSOR
) ;
961 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
963 // Don't assert, in case we set the window variant before
964 // the window is created
965 // wxASSERT( m_peer->Ok() ) ;
967 m_windowVariant
= variant
;
969 if (m_peer
== NULL
|| !m_peer
->Ok())
973 ThemeFontID themeFont
= kThemeSystemFont
;
975 // we will get that from the settings later
976 // and make this NORMAL later, but first
977 // we have a few calculations that we must fix
981 case wxWINDOW_VARIANT_NORMAL
:
982 size
= kControlSizeNormal
;
983 themeFont
= kThemeSystemFont
;
985 case wxWINDOW_VARIANT_SMALL
:
986 size
= kControlSizeSmall
;
987 themeFont
= kThemeSmallSystemFont
;
989 case wxWINDOW_VARIANT_MINI
:
990 if (UMAGetSystemVersion() >= 0x1030 )
992 // not always defined in the headers
998 size
= kControlSizeSmall
;
999 themeFont
= kThemeSmallSystemFont
;
1002 case wxWINDOW_VARIANT_LARGE
:
1003 size
= kControlSizeLarge
;
1004 themeFont
= kThemeSystemFont
;
1007 wxFAIL_MSG(_T("unexpected window variant"));
1010 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
1013 font
.MacCreateThemeFont( themeFont
) ;
1017 void wxWindowMac::MacUpdateControlFont()
1019 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1023 bool wxWindowMac::SetFont(const wxFont
& font
)
1025 bool retval
= wxWindowBase::SetFont( font
) ;
1027 MacUpdateControlFont() ;
1032 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1034 if ( !wxWindowBase::SetForegroundColour(col
) )
1037 MacUpdateControlFont() ;
1042 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1044 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1048 wxColour
newCol(GetBackgroundColour());
1049 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1051 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1053 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1055 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1059 brush
.SetColour( newCol
) ;
1061 MacSetBackgroundBrush( brush
) ;
1063 MacUpdateControlFont() ;
1068 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1070 m_macBackgroundBrush
= brush
;
1071 m_peer
->SetBackground( brush
) ;
1074 bool wxWindowMac::MacCanFocus() const
1076 // there is currently no way to determine whether the window is running in full keyboard
1077 // access mode, therefore we cannot rely on these features, yet the only other way would be
1078 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1079 // in event handlers...
1080 UInt32 features
= 0 ;
1081 m_peer
->GetFeatures( & features
) ;
1082 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1086 void wxWindowMac::SetFocus()
1088 if ( AcceptsFocus() )
1091 wxWindow
* former
= FindFocus() ;
1092 if ( former
== this )
1095 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1096 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1097 // leave in case of an error
1098 if ( err
== errCouldntSetFocus
)
1101 #if !TARGET_API_MAC_OSX
1102 // emulate carbon events when running under carbonlib where they are not natively available
1105 EventRef evRef
= NULL
;
1106 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1109 wxMacCarbonEvent
cEvent( evRef
) ;
1110 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1111 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1113 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1114 ReleaseEvent(evRef
) ;
1116 // send new focus event
1118 EventRef evRef
= NULL
;
1119 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1122 wxMacCarbonEvent
cEvent( evRef
) ;
1123 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1124 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1126 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1127 ReleaseEvent(evRef
) ;
1134 void wxWindowMac::DoCaptureMouse()
1136 wxTheApp
->s_captureWindow
= this ;
1139 wxWindow
* wxWindowBase::GetCapture()
1141 return wxTheApp
->s_captureWindow
;
1144 void wxWindowMac::DoReleaseMouse()
1146 wxTheApp
->s_captureWindow
= NULL
;
1149 #if wxUSE_DRAG_AND_DROP
1151 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1153 if ( m_dropTarget
!= 0 ) {
1154 delete m_dropTarget
;
1157 m_dropTarget
= pDropTarget
;
1158 if ( m_dropTarget
!= 0 )
1166 // Old style file-manager drag&drop
1167 void wxWindowMac::DragAcceptFiles(bool accept
)
1172 // Returns the size of the native control. In the case of the toplevel window
1173 // this is the content area root control
1175 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1176 int& w
, int& h
) const
1179 m_peer
->GetRect( &bounds
) ;
1184 w
= bounds
.right
- bounds
.left
;
1185 h
= bounds
.bottom
- bounds
.top
;
1188 // From a wx position / size calculate the appropriate size of the native control
1190 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1193 int& w
, int& h
, bool adjustOrigin
) const
1195 // the desired size, minus the border pixels gives the correct size of the control
1199 // todo the default calls may be used as soon as PostCreateControl Is moved here
1200 w
= size
.x
; // WidthDefault( size.x );
1201 h
= size
.y
; // HeightDefault( size.y ) ;
1202 #if !TARGET_API_MAC_OSX
1203 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1206 x
+= MacGetLeftBorderSize() ;
1207 y
+= MacGetTopBorderSize() ;
1208 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1209 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1212 AdjustForParentClientOrigin( x
, y
) ;
1213 #if TARGET_API_MAC_OSX
1214 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1215 if ( ! GetParent()->IsTopLevel() )
1217 x
-= GetParent()->MacGetLeftBorderSize() ;
1218 y
-= GetParent()->MacGetTopBorderSize() ;
1224 // Get window size (not client size)
1225 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1227 // take the size of the control and add the borders that have to be drawn outside
1228 int x1
, y1
, w1
, h1
;
1230 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1232 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1233 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1239 // get the position of the bounds of this window in client coordinates of its parent
1240 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1242 int x1
, y1
, w1
,h1
;
1243 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1244 x1
-= MacGetLeftBorderSize() ;
1245 y1
-= MacGetTopBorderSize() ;
1247 #if !TARGET_API_MAC_OSX
1248 if ( !GetParent()->IsTopLevel() )
1251 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1256 if ( !IsTopLevel() )
1258 wxWindow
*parent
= GetParent();
1261 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1262 x1
+= parent
->MacGetLeftBorderSize() ;
1263 y1
+= parent
->MacGetTopBorderSize() ;
1264 // and now to client coordinates
1265 wxPoint
pt(parent
->GetClientAreaOrigin());
1274 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1276 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1278 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1281 Point localwhere
= {0,0} ;
1283 if(x
) localwhere
.h
= * x
;
1284 if(y
) localwhere
.v
= * y
;
1286 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1287 if(x
) *x
= localwhere
.h
;
1288 if(y
) *y
= localwhere
.v
;
1291 MacRootWindowToWindow( x
, y
) ;
1293 wxPoint origin
= GetClientAreaOrigin() ;
1294 if(x
) *x
-= origin
.x
;
1295 if(y
) *y
-= origin
.y
;
1298 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1300 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1301 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1303 wxPoint origin
= GetClientAreaOrigin() ;
1304 if(x
) *x
+= origin
.x
;
1305 if(y
) *y
+= origin
.y
;
1307 MacWindowToRootWindow( x
, y
) ;
1310 Point localwhere
= { 0,0 };
1311 if(x
) localwhere
.h
= * x
;
1312 if(y
) localwhere
.v
= * y
;
1313 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1314 if(x
) *x
= localwhere
.h
;
1315 if(y
) *y
= localwhere
.v
;
1319 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1321 wxPoint origin
= GetClientAreaOrigin() ;
1322 if(x
) *x
+= origin
.x
;
1323 if(y
) *y
+= origin
.y
;
1325 MacWindowToRootWindow( x
, y
) ;
1328 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1330 MacRootWindowToWindow( x
, y
) ;
1332 wxPoint origin
= GetClientAreaOrigin() ;
1333 if(x
) *x
-= origin
.x
;
1334 if(y
) *y
-= origin
.y
;
1337 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1339 #if TARGET_API_MAC_OSX
1341 if ( x
) pt
.x
= *x
;
1342 if ( y
) pt
.y
= *y
;
1344 if ( !IsTopLevel() )
1346 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1349 pt
.x
-= MacGetLeftBorderSize() ;
1350 pt
.y
-= MacGetTopBorderSize() ;
1351 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1355 if ( x
) *x
= (int) pt
.x
;
1356 if ( y
) *y
= (int) pt
.y
;
1358 if ( !IsTopLevel() )
1361 m_peer
->GetRect( &bounds
) ;
1362 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1363 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1368 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1373 MacWindowToRootWindow( &x1
, &y1
) ;
1378 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1380 #if TARGET_API_MAC_OSX
1382 if ( x
) pt
.x
= *x
;
1383 if ( y
) pt
.y
= *y
;
1385 if ( !IsTopLevel() )
1387 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1388 pt
.x
+= MacGetLeftBorderSize() ;
1389 pt
.y
+= MacGetTopBorderSize() ;
1392 if ( x
) *x
= (int) pt
.x
;
1393 if ( y
) *y
= (int) pt
.y
;
1395 if ( !IsTopLevel() )
1398 m_peer
->GetRect( &bounds
) ;
1399 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1400 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1405 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1410 MacRootWindowToWindow( &x1
, &y1
) ;
1415 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1417 RgnHandle rgn
= NewRgn() ;
1419 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1421 GetRegionBounds( rgn
, &content
) ;
1425 m_peer
->GetRect( &content
) ;
1429 m_peer
->GetRect( &structure
) ;
1430 #if !TARGET_API_MAC_OSX
1431 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1433 left
= content
.left
- structure
.left
;
1434 top
= content
.top
- structure
.top
;
1435 right
= structure
.right
- content
.right
;
1436 bottom
= structure
.bottom
- content
.bottom
;
1439 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1441 wxSize sizeTotal
= size
;
1443 RgnHandle rgn
= NewRgn() ;
1447 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1449 GetRegionBounds( rgn
, &content
) ;
1453 m_peer
->GetRect( &content
) ;
1457 m_peer
->GetRect( &structure
) ;
1458 #if !TARGET_API_MAC_OSX
1459 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1462 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1463 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1465 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1466 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1472 // Get size *available for subwindows* i.e. excluding menu bar etc.
1473 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1477 RgnHandle rgn
= NewRgn() ;
1479 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1481 GetRegionBounds( rgn
, &content
) ;
1485 m_peer
->GetRect( &content
) ;
1488 #if !TARGET_API_MAC_OSX
1490 m_peer
->GetRect( &structure
) ;
1491 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1493 ww
= content
.right
- content
.left
;
1494 hh
= content
.bottom
- content
.top
;
1496 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1497 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1500 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1506 GetSize( &w , &h ) ;
1508 MacClientToRootWindow( &x1 , &y1 ) ;
1509 MacClientToRootWindow( &w , &h ) ;
1511 wxWindowMac *iter = (wxWindowMac*)this ;
1513 int totW = 10000 , totH = 10000;
1516 if ( iter->IsTopLevel() )
1518 iter->GetSize( &totW , &totH ) ;
1522 iter = iter->GetParent() ;
1525 if (m_hScrollBar && m_hScrollBar->IsShown() )
1527 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1533 if (m_vScrollBar && m_vScrollBar->IsShown() )
1535 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1543 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1545 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1547 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1549 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1556 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1558 if (m_cursor
== cursor
)
1561 if (wxNullCursor
== cursor
)
1563 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1568 if ( ! wxWindowBase::SetCursor( cursor
) )
1572 wxASSERT_MSG( m_cursor
.Ok(),
1573 wxT("cursor must be valid after call to the base version"));
1576 wxWindowMac
*mouseWin
= 0 ;
1578 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1580 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1582 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1583 // position, use it...
1587 ControlPartCode part
;
1588 ControlRef control
;
1589 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1591 mouseWin
= wxFindControlFromMacControl( control
) ;
1594 QDSwapPort( savePort
, NULL
) ;
1597 if ( mouseWin
== this && !wxIsBusy() )
1599 m_cursor
.MacInstall() ;
1606 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1608 menu
->SetInvokingWindow(this);
1611 if ( x
== -1 && y
== -1 )
1613 wxPoint mouse
= wxGetMousePosition();
1614 x
= mouse
.x
; y
= mouse
.y
;
1618 ClientToScreen( &x
, &y
) ;
1621 menu
->MacBeforeDisplay( true ) ;
1622 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1623 if ( HiWord(menuResult
) != 0 )
1626 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1627 wxMenuItem
* item
= NULL
;
1629 item
= menu
->FindItem(id
, &realmenu
) ;
1630 if (item
->IsCheckable())
1632 item
->Check( !item
->IsChecked() ) ;
1634 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1636 menu
->MacAfterDisplay( true ) ;
1638 menu
->SetInvokingWindow(NULL
);
1644 // ----------------------------------------------------------------------------
1646 // ----------------------------------------------------------------------------
1650 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1652 wxWindowBase::DoSetToolTip(tooltip
);
1655 m_tooltip
->SetWindow(this);
1658 #endif // wxUSE_TOOLTIPS
1660 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1662 // this is never called for a toplevel window, so we know we have a parent
1663 int former_x
, former_y
, former_w
, former_h
;
1665 // Get true coordinates of former position
1666 DoGetPosition( &former_x
, &former_y
) ;
1667 DoGetSize( &former_w
, &former_h
) ;
1669 wxWindow
*parent
= GetParent();
1672 wxPoint
pt(parent
->GetClientAreaOrigin());
1677 int actualWidth
= width
;
1678 int actualHeight
= height
;
1682 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1683 actualWidth
= m_minWidth
;
1684 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1685 actualHeight
= m_minHeight
;
1686 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1687 actualWidth
= m_maxWidth
;
1688 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1689 actualHeight
= m_maxHeight
;
1691 bool doMove
= false ;
1692 bool doResize
= false ;
1694 if ( actualX
!= former_x
|| actualY
!= former_y
)
1698 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1703 if ( doMove
|| doResize
)
1705 // we don't adjust twice for the origin
1706 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1707 bool vis
= m_peer
->IsVisible();
1709 int outerBorder
= MacGetLeftBorderSize() ;
1710 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1713 if ( vis
&& ( outerBorder
> 0 ) )
1715 // as the borders are drawn on the parent we have to properly invalidate all these areas
1716 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1720 m_peer
->GetRect( &rect
) ;
1721 RectRgn( updateInner
, &rect
) ;
1722 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1723 RectRgn( updateOuter
, &rect
) ;
1724 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1725 wxPoint
parent(0,0);
1726 #if TARGET_API_MAC_OSX
1727 // no offsetting needed when compositing
1729 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1730 parent
-= GetParent()->GetClientAreaOrigin() ;
1731 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1733 CopyRgn( updateOuter
, updateTotal
) ;
1736 RectRgn( updateInner
, &rect
) ;
1737 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1738 RectRgn( updateOuter
, &rect
) ;
1739 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1741 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1742 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1744 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1745 DisposeRgn(updateOuter
) ;
1746 DisposeRgn(updateInner
) ;
1747 DisposeRgn(updateTotal
) ;
1750 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1752 m_peer
->SetVisibility( false , true ) ;
1754 m_peer
->SetRect( &r
) ;
1756 m_peer
->SetVisibility( true , true ) ;
1758 MacRepositionScrollBars() ;
1761 wxPoint
point(actualX
,actualY
);
1762 wxMoveEvent
event(point
, m_windowId
);
1763 event
.SetEventObject(this);
1764 GetEventHandler()->ProcessEvent(event
) ;
1768 MacRepositionScrollBars() ;
1769 wxSize
size(actualWidth
, actualHeight
);
1770 wxSizeEvent
event(size
, m_windowId
);
1771 event
.SetEventObject(this);
1772 GetEventHandler()->ProcessEvent(event
);
1778 wxSize
wxWindowMac::DoGetBestSize() const
1780 if ( m_macIsUserPane
|| IsTopLevel() )
1781 return wxWindowBase::DoGetBestSize() ;
1783 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1784 int bestWidth
, bestHeight
;
1785 m_peer
->GetBestRect( &bestsize
) ;
1787 if ( EmptyRect( &bestsize
) )
1789 bestsize
.left
= bestsize
.top
= 0 ;
1790 bestsize
.right
= 16 ;
1791 bestsize
.bottom
= 16 ;
1792 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1794 bestsize
.bottom
= 16 ;
1797 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1799 bestsize
.bottom
= 24 ;
1801 #endif // wxUSE_SPINBTN
1804 // return wxWindowBase::DoGetBestSize() ;
1808 bestWidth
= bestsize
.right
- bestsize
.left
;
1809 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1810 if ( bestHeight
< 10 )
1813 return wxSize(bestWidth
, bestHeight
);
1817 // set the size of the window: if the dimensions are positive, just use them,
1818 // but if any of them is equal to -1, it means that we must find the value for
1819 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1820 // which case -1 is a valid value for x and y)
1822 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1823 // the width/height to best suit our contents, otherwise we reuse the current
1825 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1827 // get the current size and position...
1828 int currentX
, currentY
;
1829 GetPosition(¤tX
, ¤tY
);
1831 int currentW
,currentH
;
1832 GetSize(¤tW
, ¤tH
);
1834 // ... and don't do anything (avoiding flicker) if it's already ok
1835 if ( x
== currentX
&& y
== currentY
&&
1836 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1839 MacRepositionScrollBars() ; // we might have a real position shift
1843 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1845 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1848 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1850 wxSize
size(-1, -1);
1853 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1855 size
= DoGetBestSize();
1860 // just take the current one
1867 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1871 size
= DoGetBestSize();
1873 //else: already called DoGetBestSize() above
1879 // just take the current one
1884 DoMoveWindow(x
, y
, width
, height
);
1888 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1890 RgnHandle rgn
= NewRgn() ;
1892 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1893 GetRegionBounds( rgn
, &content
) ;
1895 #if !TARGET_API_MAC_OSX
1896 // if the content rgn is empty / not supported
1897 // don't attempt to correct the coordinates to wxWindow relative ones
1898 if (!::EmptyRect( &content
) )
1901 m_peer
->GetRect( &structure
) ;
1902 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1906 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1909 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1911 if ( clientheight
!= -1 || clientheight
!= -1 )
1913 int currentclientwidth
, currentclientheight
;
1914 int currentwidth
, currentheight
;
1916 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1917 GetSize( ¤twidth
, ¤theight
) ;
1919 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1920 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1924 void wxWindowMac::SetTitle(const wxString
& title
)
1926 m_label
= wxStripMenuCodes(title
) ;
1928 if ( m_peer
&& m_peer
->Ok() )
1930 m_peer
->SetTitle( m_label
) ;
1935 wxString
wxWindowMac::GetTitle() const
1940 bool wxWindowMac::Show(bool show
)
1942 if ( !wxWindowBase::Show(show
) )
1945 // TODO use visibilityChanged Carbon Event for OSX
1948 bool former
= MacIsReallyShown() ;
1950 m_peer
->SetVisibility( show
, true ) ;
1951 if ( former
!= MacIsReallyShown() )
1952 MacPropagateVisibilityChanged() ;
1957 bool wxWindowMac::Enable(bool enable
)
1959 wxASSERT( m_peer
->Ok() ) ;
1960 if ( !wxWindowBase::Enable(enable
) )
1963 bool former
= MacIsReallyEnabled() ;
1964 m_peer
->Enable( enable
) ;
1966 if ( former
!= MacIsReallyEnabled() )
1967 MacPropagateEnabledStateChanged() ;
1972 // status change propagations (will be not necessary for OSX later )
1975 void wxWindowMac::MacPropagateVisibilityChanged()
1977 #if !TARGET_API_MAC_OSX
1978 MacVisibilityChanged() ;
1980 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1983 wxWindowMac
*child
= node
->GetData();
1984 if ( child
->IsShown() )
1985 child
->MacPropagateVisibilityChanged( ) ;
1986 node
= node
->GetNext();
1991 void wxWindowMac::MacPropagateEnabledStateChanged( )
1993 #if !TARGET_API_MAC_OSX
1994 MacEnabledStateChanged() ;
1996 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1999 wxWindowMac
*child
= node
->GetData();
2000 if ( child
->IsEnabled() )
2001 child
->MacPropagateEnabledStateChanged() ;
2002 node
= node
->GetNext();
2007 void wxWindowMac::MacPropagateHiliteChanged( )
2009 #if !TARGET_API_MAC_OSX
2010 MacHiliteChanged() ;
2012 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2015 wxWindowMac
*child
= node
->GetData();
2016 // if ( child->IsEnabled() )
2017 child
->MacPropagateHiliteChanged() ;
2018 node
= node
->GetNext();
2024 // status change notifications
2027 void wxWindowMac::MacVisibilityChanged()
2031 void wxWindowMac::MacHiliteChanged()
2035 void wxWindowMac::MacEnabledStateChanged()
2040 // status queries on the inherited window's state
2043 bool wxWindowMac::MacIsReallyShown()
2045 // only under OSX the visibility of the TLW is taken into account
2046 if ( m_isBeingDeleted
)
2049 #if TARGET_API_MAC_OSX
2050 if ( m_peer
&& m_peer
->Ok() )
2051 return m_peer
->IsVisible();
2053 wxWindow
* win
= this ;
2054 while( win
->IsShown() )
2056 if ( win
->IsTopLevel() )
2059 win
= win
->GetParent() ;
2067 bool wxWindowMac::MacIsReallyEnabled()
2069 return m_peer
->IsEnabled() ;
2072 bool wxWindowMac::MacIsReallyHilited()
2074 return m_peer
->IsActive();
2077 void wxWindowMac::MacFlashInvalidAreas()
2079 #if TARGET_API_MAC_OSX
2080 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2088 int wxWindowMac::GetCharHeight() const
2090 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2091 return dc
.GetCharHeight() ;
2094 int wxWindowMac::GetCharWidth() const
2096 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2097 return dc
.GetCharWidth() ;
2100 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2101 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2103 const wxFont
*fontToUse
= theFont
;
2105 fontToUse
= &m_font
;
2107 wxClientDC
dc( (wxWindowMac
*) this ) ;
2109 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2110 if ( externalLeading
)
2111 *externalLeading
= le
;
2121 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2122 * we always intersect with the entire window, not only with the client area
2125 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2127 if ( m_peer
== NULL
)
2130 #if TARGET_API_MAC_OSX
2132 m_peer
->SetNeedsDisplay( true ) ;
2135 RgnHandle update
= NewRgn() ;
2136 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2137 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2138 wxPoint origin
= GetClientAreaOrigin() ;
2139 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2140 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2142 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2143 m_peer
->SetNeedsDisplay( true , update
) ;
2144 DisposeRgn( update
) ;
2148 RgnHandle updateRgn = NewRgn() ;
2151 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2155 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2156 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2158 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2159 DisposeRgn(updateRgn) ;
2161 if ( m_peer
->IsVisible())
2163 m_peer
->SetVisibility( false , false ) ;
2164 m_peer
->SetVisibility( true , true ) ;
2167 if ( MacGetTopLevelWindow() == NULL )
2170 if ( !m_peer->IsVisible())
2173 wxPoint client = GetClientAreaOrigin();
2176 int x2 = m_width - client.x;
2177 int y2 = m_height - client.y;
2179 if (IsKindOf( CLASSINFO(wxButton)))
2181 // buttons have an "aura"
2188 Rect clientrect = { y1, x1, y2, x2 };
2192 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2193 SectRect( &clientrect , &r , &clientrect ) ;
2196 if ( !EmptyRect( &clientrect ) )
2198 int top = 0 , left = 0 ;
2200 MacClientToRootWindow( &left , &top ) ;
2201 OffsetRect( &clientrect , left , top ) ;
2203 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2209 void wxWindowMac::Freeze()
2211 #if TARGET_API_MAC_OSX
2212 if ( !m_frozenness
++ )
2214 if ( m_peer
&& m_peer
->Ok() )
2215 m_peer
->SetDrawingEnabled( false ) ;
2221 void wxWindowMac::Thaw()
2223 #if TARGET_API_MAC_OSX
2224 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2226 if ( !--m_frozenness
)
2228 if ( m_peer
&& m_peer
->Ok() )
2230 m_peer
->SetDrawingEnabled( true ) ;
2231 m_peer
->InvalidateWithChildren() ;
2237 wxWindowMac
*wxGetActiveWindow()
2239 // actually this is a windows-only concept
2243 // Coordinates relative to the window
2244 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2246 // We really don't move the mouse programmatically under Mac.
2249 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2251 #if TARGET_API_MAC_OSX
2252 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2259 event
.GetDC()->Clear() ;
2263 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2268 int wxWindowMac::GetScrollPos(int orient
) const
2270 if ( orient
== wxHORIZONTAL
)
2273 return m_hScrollBar
->GetThumbPosition() ;
2278 return m_vScrollBar
->GetThumbPosition() ;
2283 // This now returns the whole range, not just the number
2284 // of positions that we can scroll.
2285 int wxWindowMac::GetScrollRange(int orient
) const
2287 if ( orient
== wxHORIZONTAL
)
2290 return m_hScrollBar
->GetRange() ;
2295 return m_vScrollBar
->GetRange() ;
2300 int wxWindowMac::GetScrollThumb(int orient
) const
2302 if ( orient
== wxHORIZONTAL
)
2305 return m_hScrollBar
->GetThumbSize() ;
2310 return m_vScrollBar
->GetThumbSize() ;
2315 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2317 if ( orient
== wxHORIZONTAL
)
2320 m_hScrollBar
->SetThumbPosition( pos
) ;
2325 m_vScrollBar
->SetThumbPosition( pos
) ;
2330 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2331 // our own window origin is at leftOrigin/rightOrigin
2334 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2340 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2341 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2343 m_peer
->GetRect( &rect
) ;
2344 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2346 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2347 if ( HIThemeDrawFrame
!= 0)
2350 HIThemeFrameDrawInfo info
;
2351 memset( &info
, 0 , sizeof( info
) ) ;
2355 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2356 info
.isFocused
= hasFocus
;
2359 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2360 wxASSERT( cgContext
) ;
2362 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2365 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2366 InsetRect( &srect
, border
, border
);
2367 info
.kind
= kHIThemeFrameTextFieldSquare
;
2370 else if (HasFlag(wxSIMPLE_BORDER
))
2373 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2374 InsetRect( &srect
, border
, border
);
2375 info
.kind
= kHIThemeFrameListBox
;
2381 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2382 srect
.bottom
- srect
.top
) ;
2383 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2385 else if ( hasFocus
)
2388 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2389 srect
.bottom
- srect
.top
) ;
2390 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2393 m_peer
->GetRect( &rect
) ;
2394 if ( hasBothScrollbars
)
2397 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2398 CGRect cgrect
= CGRectMake( srect
.right
- size
, srect
.bottom
- size
, size
, size
) ;
2399 CGPoint cgpoint
= CGPointMake( srect
.right
- size
, srect
.bottom
- size
) ;
2400 HIThemeGrowBoxDrawInfo info
;
2401 memset( &info
, 0 , sizeof( info
) ) ;
2403 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2404 info
.kind
= kHIThemeGrowBoxKindNone
;
2405 info
.size
= kHIThemeGrowBoxSizeNormal
;
2406 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2407 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2413 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2417 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2419 rect
.right
+= pt
.x
;
2421 rect
.bottom
+= pt
.y
;
2424 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2428 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2429 InsetRect( &srect
, border
, border
);
2430 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2432 else if (HasFlag(wxSIMPLE_BORDER
))
2436 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2437 InsetRect( &srect
, border
, border
);
2438 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2444 DrawThemeFocusRect( &srect
, true ) ;
2446 if ( hasBothScrollbars
)
2448 // GetThemeStandaloneGrowBoxBounds
2449 //DrawThemeStandaloneNoGrowBox
2454 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2456 if ( child
== m_hScrollBar
)
2457 m_hScrollBar
= NULL
;
2458 if ( child
== m_vScrollBar
)
2459 m_vScrollBar
= NULL
;
2461 wxWindowBase::RemoveChild( child
) ;
2464 // New function that will replace some of the above.
2465 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2466 int range
, bool refresh
)
2468 if ( orient
== wxHORIZONTAL
)
2472 if ( range
== 0 || thumbVisible
>= range
)
2474 if ( m_hScrollBar
->IsShown() )
2475 m_hScrollBar
->Show(false) ;
2479 if ( !m_hScrollBar
->IsShown() )
2480 m_hScrollBar
->Show(true) ;
2482 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2489 if ( range
== 0 || thumbVisible
>= range
)
2491 if ( m_vScrollBar
->IsShown() )
2492 m_vScrollBar
->Show(false) ;
2496 if ( !m_vScrollBar
->IsShown() )
2497 m_vScrollBar
->Show(true) ;
2499 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2502 MacRepositionScrollBars() ;
2505 // Does a physical scroll
2506 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2508 if( dx
== 0 && dy
==0 )
2514 int width
, height
;
2515 GetClientSize( &width
, &height
) ;
2516 #if TARGET_API_MAC_OSX
2517 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2518 // area is scrolled, this does not occur if width and height are 2 pixels less,
2519 // TODO write optimal workaround
2520 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2523 scrollrect
.Intersect( *rect
) ;
2525 if ( m_peer
->GetNeedsDisplay() )
2527 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2528 // either immediate redraw or full invalidate
2530 // is the better overall solution, as it does not slow down scrolling
2531 m_peer
->SetNeedsDisplay( true ) ;
2533 // this would be the preferred version for fast drawing controls
2534 if( UMAGetSystemVersion() < 0x1030 )
2537 HIViewRender(m_peer
->GetControlRef()) ;
2540 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2541 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2542 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2549 RgnHandle updateRgn
= NewRgn() ;
2552 wxClientDC
dc(this) ;
2553 wxMacPortSetter
helper(&dc
) ;
2555 m_peer
->GetRect( &scrollrect
) ;
2556 scrollrect
.top
+= MacGetTopBorderSize() ;
2557 scrollrect
.left
+= MacGetLeftBorderSize() ;
2558 scrollrect
.bottom
= scrollrect
.top
+ height
;
2559 scrollrect
.right
= scrollrect
.left
+ width
;
2563 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2564 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2565 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2567 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2569 // now scroll the former update region as well and add the new update region
2571 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2572 RgnHandle formerUpdateRgn
= NewRgn() ;
2573 RgnHandle scrollRgn
= NewRgn() ;
2574 RectRgn( scrollRgn
, &scrollrect
) ;
2575 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2577 LocalToGlobal( &pt
) ;
2578 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2579 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2580 if ( !EmptyRgn( formerUpdateRgn
) )
2582 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2583 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2584 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2586 InvalWindowRgn(rootWindow
, updateRgn
) ;
2587 DisposeRgn( updateRgn
) ;
2588 DisposeRgn( formerUpdateRgn
) ;
2589 DisposeRgn( scrollRgn
) ;
2594 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2596 wxWindowMac
*child
= node
->GetData();
2597 if (child
== m_vScrollBar
) continue;
2598 if (child
== m_hScrollBar
) continue;
2599 if (child
->IsTopLevel()) continue;
2602 child
->GetPosition( &x
, &y
);
2604 child
->GetSize( &w
, &h
);
2608 if (rect
->Intersects(rc
))
2609 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2613 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2618 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2620 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2622 wxScrollWinEvent wevent
;
2623 wevent
.SetPosition(event
.GetPosition());
2624 wevent
.SetOrientation(event
.GetOrientation());
2625 wevent
.SetEventObject(this);
2627 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2628 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2629 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2630 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2631 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2632 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2633 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2634 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2635 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2636 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2637 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2638 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2639 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2640 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2641 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2642 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2644 GetEventHandler()->ProcessEvent(wevent
);
2648 // Get the window with the focus
2649 wxWindowMac
*wxWindowBase::DoFindFocus()
2651 ControlRef control
;
2652 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2653 return wxFindControlFromMacControl( control
) ;
2656 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2658 // panel wants to track the window which was the last to have focus in it,
2659 // so we want to set ourselves as the window which last had focus
2661 // notice that it's also important to do it upwards the tree becaus
2662 // otherwise when the top level panel gets focus, it won't set it back to
2663 // us, but to some other sibling
2665 // CS:don't know if this is still needed:
2666 //wxChildFocusEvent eventFocus(this);
2667 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2669 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2671 #if !wxMAC_USE_CORE_GRAPHICS
2672 wxMacWindowStateSaver
sv( this ) ;
2677 MacWindowToRootWindow( &x
, &y
) ;
2678 GetSize( &w
, &h
) ;
2679 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2681 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2682 DrawThemeFocusRect( &rect
, true ) ;
2685 DrawThemeFocusRect( &rect
, false ) ;
2687 // as this erases part of the frame we have to redraw borders
2688 // and because our z-ordering is not always correct (staticboxes)
2689 // we have to invalidate things, we cannot simple redraw
2690 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2691 RectRgn( updateInner
, &rect
) ;
2692 InsetRect( &rect
, -4 , -4 ) ;
2693 RectRgn( updateOuter
, &rect
) ;
2694 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2695 wxPoint
parent(0,0);
2696 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2697 parent
-= GetParent()->GetClientAreaOrigin() ;
2698 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2699 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2700 DisposeRgn(updateOuter
) ;
2701 DisposeRgn(updateInner
) ;
2704 GetParent()->Refresh() ;
2711 void wxWindowMac::OnInternalIdle()
2713 // This calls the UI-update mechanism (querying windows for
2714 // menu/toolbar/control state information)
2715 if (wxUpdateUIEvent::CanUpdate(this))
2716 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2719 // Raise the window to the top of the Z order
2720 void wxWindowMac::Raise()
2722 m_peer
->SetZOrder( true , NULL
) ;
2725 // Lower the window to the bottom of the Z order
2726 void wxWindowMac::Lower()
2728 m_peer
->SetZOrder( false , NULL
) ;
2732 // static wxWindow *gs_lastWhich = NULL;
2734 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2736 // first trigger a set cursor event
2738 wxPoint clientorigin
= GetClientAreaOrigin() ;
2739 wxSize clientsize
= GetClientSize() ;
2741 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2743 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2745 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2746 if ( processedEvtSetCursor
&& event
.HasCursor() )
2748 cursor
= event
.GetCursor() ;
2753 // the test for processedEvtSetCursor is here to prevent using m_cursor
2754 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2755 // it - this is a way to say that our cursor shouldn't be used for this
2757 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2767 cursor
= *wxSTANDARD_CURSOR
;
2771 cursor
.MacInstall() ;
2773 return cursor
.Ok() ;
2776 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2780 return m_tooltip
->GetTip() ;
2782 return wxEmptyString
;
2785 void wxWindowMac::ClearBackground()
2791 void wxWindowMac::Update()
2793 #if TARGET_API_MAC_OSX
2795 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2796 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2798 // for composited windows this also triggers a redraw of all
2799 // invalid views in the window
2800 if( UMAGetSystemVersion() >= 0x1030 )
2801 HIWindowFlush(window
) ;
2805 // the only way to trigger the redrawing on earlier systems is to call
2808 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2809 UInt32 currentEventClass
= 0 ;
2810 UInt32 currentEventKind
= 0 ;
2811 if ( currentEvent
!= NULL
)
2813 currentEventClass
= ::GetEventClass( currentEvent
) ;
2814 currentEventKind
= ::GetEventKind( currentEvent
) ;
2816 if ( currentEventClass
!= kEventClassMenu
)
2818 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2821 OSStatus status
= noErr
;
2822 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2825 m_peer
->SetNeedsDisplay( true ) ;
2828 ::Draw1Control( m_peer
->GetControlRef() ) ;
2832 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2834 wxTopLevelWindowMac
* win
= NULL
;
2835 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2838 win
= wxFindWinFromMacWindow( window
) ;
2842 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2844 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2845 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2846 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2847 // to add focus borders everywhere
2850 RgnHandle visRgn
= NewRgn() ;
2851 RgnHandle tempRgn
= NewRgn() ;
2852 if ( !m_isBeingDeleted
&& m_peer
->IsVisible())
2854 m_peer
->GetRect( &r
) ;
2855 r
.left
-= MacGetLeftBorderSize() ;
2856 r
.top
-= MacGetTopBorderSize() ;
2857 r
.bottom
+= MacGetBottomBorderSize() ;
2858 r
.right
+= MacGetRightBorderSize() ;
2860 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2862 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2863 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2872 if ( includeOuterStructures
)
2873 InsetRect( &r
, -4 , -4 ) ;
2874 RectRgn( visRgn
, &r
) ;
2876 if ( !IsTopLevel() )
2878 wxWindow
* child
= this ;
2879 wxWindow
* parent
= child
->GetParent() ;
2884 // we have to find a better clipping algorithm here, in order not to clip things
2885 // positioned like status and toolbar
2886 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2888 size
= parent
->GetSize() ;
2893 size
= parent
->GetClientSize() ;
2894 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2898 parent
->MacWindowToRootWindow( &x
, &y
) ;
2899 MacRootWindowToWindow( &x
, &y
) ;
2901 if ( !includeOuterStructures
|| (
2902 parent
->MacClipChildren() ||
2903 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2906 SetRectRgn( tempRgn
,
2907 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2908 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2909 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2911 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2913 if ( parent
->IsTopLevel() )
2916 parent
= child
->GetParent() ;
2921 wxRegion vis
= visRgn
;
2922 DisposeRgn( visRgn
) ;
2923 DisposeRgn( tempRgn
) ;
2928 This function must not change the updatergn !
2930 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2932 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2933 bool handled
= false ;
2935 GetRegionBounds( updatergn
, &updatebounds
) ;
2937 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2939 if ( !EmptyRgn(updatergn
) )
2941 RgnHandle newupdate
= NewRgn() ;
2942 wxSize point
= GetClientSize() ;
2943 wxPoint origin
= GetClientAreaOrigin() ;
2944 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2945 SectRgn( newupdate
, updatergn
, newupdate
) ;
2947 // first send an erase event to the entire update area
2949 // for the toplevel window this really is the entire area
2950 // for all the others only their client area, otherwise they
2951 // might be drawing with full alpha and eg put blue into
2952 // the grow-box area of a scrolled window (scroll sample)
2955 dc
= new wxWindowDC(this);
2957 dc
= new wxClientDC(this);
2958 dc
->SetClippingRegion(wxRegion(updatergn
));
2959 wxEraseEvent
eevent( GetId(), dc
);
2960 eevent
.SetEventObject( this );
2961 GetEventHandler()->ProcessEvent( eevent
);
2965 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2966 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2967 m_updateRegion
= newupdate
;
2968 DisposeRgn( newupdate
) ;
2970 if ( !m_updateRegion
.Empty() )
2972 // paint the window itself
2975 event
.SetTimestamp(time
);
2976 event
.SetEventObject(this);
2977 GetEventHandler()->ProcessEvent(event
);
2981 // now we cannot rely on having its borders drawn by a window itself, as it does not
2982 // get the updateRgn wide enough to always do so, so we do it from the parent
2983 // this would also be the place to draw any custom backgrounds for native controls
2984 // in Composited windowing
2985 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2987 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2989 wxWindowMac
*child
= node
->GetData();
2990 if (child
== m_vScrollBar
) continue;
2991 if (child
== m_hScrollBar
) continue;
2992 if (child
->IsTopLevel()) continue;
2993 if (!child
->IsShown()) continue;
2995 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2998 child
->GetPosition( &x
, &y
);
3000 child
->GetSize( &w
, &h
);
3001 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3002 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3003 InsetRect( &childRect
, -10 , -10) ;
3005 if ( RectInRgn( &childRect
, updatergn
) )
3008 // paint custom borders
3009 wxNcPaintEvent
eventNc( child
->GetId() );
3010 eventNc
.SetEventObject( child
);
3011 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3013 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3014 if ( HIThemeDrawFrame
!= 0)
3016 child
->MacPaintBorders(0,0) ;
3021 #if !wxMAC_USE_CORE_GRAPHICS
3022 wxWindowDC
dc(this) ;
3023 dc
.SetClippingRegion(wxRegion(updatergn
));
3024 wxMacPortSetter
helper(&dc
) ;
3025 child
->MacPaintBorders(0,0) ;
3036 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3038 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3042 if ( iter
->IsTopLevel() )
3043 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3045 iter
= iter
->GetParent() ;
3047 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3051 void wxWindowMac::MacCreateScrollBars( long style
)
3053 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3055 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3057 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3058 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3059 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3060 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3062 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3063 variant
= wxWINDOW_VARIANT_SMALL
;
3066 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3068 GetClientSize( &width
, &height
) ;
3070 wxPoint
vPoint(width
-scrlsize
, 0) ;
3071 wxSize
vSize(scrlsize
, height
- adjust
) ;
3072 wxPoint
hPoint(0 , height
-scrlsize
) ;
3073 wxSize
hSize( width
- adjust
, scrlsize
) ;
3076 if ( style
& wxVSCROLL
)
3078 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3079 vSize
, wxVERTICAL
);
3082 if ( style
& wxHSCROLL
)
3084 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3085 hSize
, wxHORIZONTAL
);
3090 // because the create does not take into account the client area origin
3091 MacRepositionScrollBars() ; // we might have a real position shift
3094 void wxWindowMac::MacRepositionScrollBars()
3096 if ( !m_hScrollBar
&& !m_vScrollBar
)
3099 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3100 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3101 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3103 // get real client area
3107 GetSize( &width
, &height
) ;
3109 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3110 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3112 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3113 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3114 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3115 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3121 GetSize( &w , &h ) ;
3123 MacClientToRootWindow( &x , &y ) ;
3124 MacClientToRootWindow( &w , &h ) ;
3126 wxWindowMac *iter = (wxWindowMac*)this ;
3128 int totW = 10000 , totH = 10000;
3131 if ( iter->IsTopLevel() )
3133 iter->GetSize( &totW , &totH ) ;
3137 iter = iter->GetParent() ;
3165 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3169 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3173 bool wxWindowMac::AcceptsFocus() const
3175 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3178 void wxWindowMac::MacSuperChangedPosition()
3180 // only window-absolute structures have to be moved i.e. controls
3182 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3185 wxWindowMac
*child
= node
->GetData();
3186 child
->MacSuperChangedPosition() ;
3187 node
= node
->GetNext();
3191 void wxWindowMac::MacTopLevelWindowChangedPosition()
3193 // only screen-absolute structures have to be moved i.e. glcanvas
3195 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3198 wxWindowMac
*child
= node
->GetData();
3199 child
->MacTopLevelWindowChangedPosition() ;
3200 node
= node
->GetNext();
3204 long wxWindowMac::MacGetLeftBorderSize( ) const
3209 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3214 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3219 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3226 long wxWindowMac::MacGetRightBorderSize( ) const
3228 // they are all symmetric in mac themes
3229 return MacGetLeftBorderSize() ;
3232 long wxWindowMac::MacGetTopBorderSize( ) const
3234 // they are all symmetric in mac themes
3235 return MacGetLeftBorderSize() ;
3238 long wxWindowMac::MacGetBottomBorderSize( ) const
3240 // they are all symmetric in mac themes
3241 return MacGetLeftBorderSize() ;
3244 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3246 return style
& ~wxBORDER_MASK
;
3249 // Find the wxWindowMac at the current mouse position, returning the mouse
3251 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3253 pt
= wxGetMousePosition();
3254 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3258 // Get the current mouse position.
3259 wxPoint
wxGetMousePosition()
3262 wxGetMousePosition(& x
, & y
);
3263 return wxPoint(x
, y
);
3266 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3268 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3270 // copied from wxGTK : CS
3271 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3274 // (a) it's a command event and so is propagated to the parent
3275 // (b) under MSW it can be generated from kbd too
3276 // (c) it uses screen coords (because of (a))
3277 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3279 this->ClientToScreen(event
.GetPosition()));
3280 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3289 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3291 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3293 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3297 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3301 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3305 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3306 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3310 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3312 return eventNotHandledErr
;