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
);
853 #if !TARGET_API_MAC_OSX
854 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
856 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
857 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
858 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
859 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
860 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
861 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
862 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
863 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
870 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
874 const wxString
& name
)
876 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
878 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
881 m_windowVariant
= parent
->GetWindowVariant() ;
883 if ( m_macIsUserPane
)
885 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
888 | kControlSupportsEmbedding
889 // | kControlSupportsLiveFeedback
890 // | kControlHasSpecialBackground
891 // | kControlSupportsCalcBestRect
892 // | kControlHandlesTracking
893 | kControlSupportsFocus
894 // | kControlWantsActivate
895 // | kControlWantsIdle
898 m_peer
= new wxMacControl() ;
899 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
902 MacPostControlCreate(pos
,size
) ;
904 #ifndef __WXUNIVERSAL__
905 // Don't give scrollbars to wxControls unless they ask for them
906 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
907 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
909 MacCreateScrollBars( style
) ;
913 wxWindowCreateEvent
event(this);
914 GetEventHandler()->AddPendingEvent(event
);
919 void wxWindowMac::MacChildAdded()
923 m_vScrollBar
->Raise() ;
927 m_hScrollBar
->Raise() ;
932 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
934 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
936 m_peer
->SetReference( (long) this ) ;
937 GetParent()->AddChild(this);
939 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
941 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
942 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
943 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
944 GetParent()->MacChildAdded() ;
946 // adjust font, controlsize etc
947 DoSetWindowVariant( m_windowVariant
) ;
949 #if !TARGET_API_MAC_OSX
950 // eventually we can fix some clipping issues be reactivating this hook
951 //if ( m_macIsUserPane )
952 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
954 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
956 if (!m_macIsUserPane
)
958 SetInitialBestSize(size
);
961 SetCursor( *wxSTANDARD_CURSOR
) ;
964 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
966 // Don't assert, in case we set the window variant before
967 // the window is created
968 // wxASSERT( m_peer->Ok() ) ;
970 m_windowVariant
= variant
;
972 if (m_peer
== NULL
|| !m_peer
->Ok())
976 ThemeFontID themeFont
= kThemeSystemFont
;
978 // we will get that from the settings later
979 // and make this NORMAL later, but first
980 // we have a few calculations that we must fix
984 case wxWINDOW_VARIANT_NORMAL
:
985 size
= kControlSizeNormal
;
986 themeFont
= kThemeSystemFont
;
988 case wxWINDOW_VARIANT_SMALL
:
989 size
= kControlSizeSmall
;
990 themeFont
= kThemeSmallSystemFont
;
992 case wxWINDOW_VARIANT_MINI
:
993 if (UMAGetSystemVersion() >= 0x1030 )
995 // not always defined in the headers
1001 size
= kControlSizeSmall
;
1002 themeFont
= kThemeSmallSystemFont
;
1005 case wxWINDOW_VARIANT_LARGE
:
1006 size
= kControlSizeLarge
;
1007 themeFont
= kThemeSystemFont
;
1010 wxFAIL_MSG(_T("unexpected window variant"));
1013 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
1016 font
.MacCreateThemeFont( themeFont
) ;
1020 void wxWindowMac::MacUpdateControlFont()
1022 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1026 bool wxWindowMac::SetFont(const wxFont
& font
)
1028 bool retval
= wxWindowBase::SetFont( font
) ;
1030 MacUpdateControlFont() ;
1035 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1037 if ( !wxWindowBase::SetForegroundColour(col
) )
1040 MacUpdateControlFont() ;
1045 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1047 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1051 wxColour
newCol(GetBackgroundColour());
1052 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1054 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1056 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1058 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1062 brush
.SetColour( newCol
) ;
1064 MacSetBackgroundBrush( brush
) ;
1066 MacUpdateControlFont() ;
1071 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1073 m_macBackgroundBrush
= brush
;
1074 m_peer
->SetBackground( brush
) ;
1077 bool wxWindowMac::MacCanFocus() const
1079 // there is currently no way to determine whether the window is running in full keyboard
1080 // access mode, therefore we cannot rely on these features, yet the only other way would be
1081 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1082 // in event handlers...
1083 UInt32 features
= 0 ;
1084 m_peer
->GetFeatures( & features
) ;
1085 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1089 void wxWindowMac::SetFocus()
1091 if ( AcceptsFocus() )
1094 wxWindow
* former
= FindFocus() ;
1095 if ( former
== this )
1098 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1099 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1100 // leave in case of an error
1101 if ( err
== errCouldntSetFocus
)
1104 #if !TARGET_API_MAC_OSX
1105 // emulate carbon events when running under carbonlib where they are not natively available
1108 EventRef evRef
= NULL
;
1109 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1112 wxMacCarbonEvent
cEvent( evRef
) ;
1113 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1114 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1116 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1117 ReleaseEvent(evRef
) ;
1119 // send new focus event
1121 EventRef evRef
= NULL
;
1122 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1125 wxMacCarbonEvent
cEvent( evRef
) ;
1126 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1127 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1129 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1130 ReleaseEvent(evRef
) ;
1137 void wxWindowMac::DoCaptureMouse()
1139 wxTheApp
->s_captureWindow
= this ;
1142 wxWindow
* wxWindowBase::GetCapture()
1144 return wxTheApp
->s_captureWindow
;
1147 void wxWindowMac::DoReleaseMouse()
1149 wxTheApp
->s_captureWindow
= NULL
;
1152 #if wxUSE_DRAG_AND_DROP
1154 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1156 if ( m_dropTarget
!= 0 ) {
1157 delete m_dropTarget
;
1160 m_dropTarget
= pDropTarget
;
1161 if ( m_dropTarget
!= 0 )
1169 // Old style file-manager drag&drop
1170 void wxWindowMac::DragAcceptFiles(bool accept
)
1175 // Returns the size of the native control. In the case of the toplevel window
1176 // this is the content area root control
1178 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1179 int& w
, int& h
) const
1182 m_peer
->GetRect( &bounds
) ;
1187 w
= bounds
.right
- bounds
.left
;
1188 h
= bounds
.bottom
- bounds
.top
;
1191 // From a wx position / size calculate the appropriate size of the native control
1193 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1196 int& w
, int& h
, bool adjustOrigin
) const
1198 // the desired size, minus the border pixels gives the correct size of the control
1202 // todo the default calls may be used as soon as PostCreateControl Is moved here
1203 w
= size
.x
; // WidthDefault( size.x );
1204 h
= size
.y
; // HeightDefault( size.y ) ;
1205 #if !TARGET_API_MAC_OSX
1206 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1209 x
+= MacGetLeftBorderSize() ;
1210 y
+= MacGetTopBorderSize() ;
1211 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1212 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1215 AdjustForParentClientOrigin( x
, y
) ;
1216 #if TARGET_API_MAC_OSX
1217 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1218 if ( ! GetParent()->IsTopLevel() )
1220 x
-= GetParent()->MacGetLeftBorderSize() ;
1221 y
-= GetParent()->MacGetTopBorderSize() ;
1227 // Get window size (not client size)
1228 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1230 // take the size of the control and add the borders that have to be drawn outside
1231 int x1
, y1
, w1
, h1
;
1233 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1235 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1236 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1242 // get the position of the bounds of this window in client coordinates of its parent
1243 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1245 int x1
, y1
, w1
,h1
;
1246 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1247 x1
-= MacGetLeftBorderSize() ;
1248 y1
-= MacGetTopBorderSize() ;
1250 #if !TARGET_API_MAC_OSX
1251 if ( !GetParent()->IsTopLevel() )
1254 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1259 if ( !IsTopLevel() )
1261 wxWindow
*parent
= GetParent();
1264 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1265 x1
+= parent
->MacGetLeftBorderSize() ;
1266 y1
+= parent
->MacGetTopBorderSize() ;
1267 // and now to client coordinates
1268 wxPoint
pt(parent
->GetClientAreaOrigin());
1277 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1279 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1281 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1284 Point localwhere
= {0,0} ;
1286 if(x
) localwhere
.h
= * x
;
1287 if(y
) localwhere
.v
= * y
;
1289 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1290 if(x
) *x
= localwhere
.h
;
1291 if(y
) *y
= localwhere
.v
;
1294 MacRootWindowToWindow( x
, y
) ;
1296 wxPoint origin
= GetClientAreaOrigin() ;
1297 if(x
) *x
-= origin
.x
;
1298 if(y
) *y
-= origin
.y
;
1301 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1303 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1304 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1306 wxPoint origin
= GetClientAreaOrigin() ;
1307 if(x
) *x
+= origin
.x
;
1308 if(y
) *y
+= origin
.y
;
1310 MacWindowToRootWindow( x
, y
) ;
1313 Point localwhere
= { 0,0 };
1314 if(x
) localwhere
.h
= * x
;
1315 if(y
) localwhere
.v
= * y
;
1316 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1317 if(x
) *x
= localwhere
.h
;
1318 if(y
) *y
= localwhere
.v
;
1322 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1324 wxPoint origin
= GetClientAreaOrigin() ;
1325 if(x
) *x
+= origin
.x
;
1326 if(y
) *y
+= origin
.y
;
1328 MacWindowToRootWindow( x
, y
) ;
1331 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1333 MacRootWindowToWindow( x
, y
) ;
1335 wxPoint origin
= GetClientAreaOrigin() ;
1336 if(x
) *x
-= origin
.x
;
1337 if(y
) *y
-= origin
.y
;
1340 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1342 #if TARGET_API_MAC_OSX
1344 if ( x
) pt
.x
= *x
;
1345 if ( y
) pt
.y
= *y
;
1347 if ( !IsTopLevel() )
1349 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1352 pt
.x
-= MacGetLeftBorderSize() ;
1353 pt
.y
-= MacGetTopBorderSize() ;
1354 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1358 if ( x
) *x
= (int) pt
.x
;
1359 if ( y
) *y
= (int) pt
.y
;
1361 if ( !IsTopLevel() )
1364 m_peer
->GetRect( &bounds
) ;
1365 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1366 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1371 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1376 MacWindowToRootWindow( &x1
, &y1
) ;
1381 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1383 #if TARGET_API_MAC_OSX
1385 if ( x
) pt
.x
= *x
;
1386 if ( y
) pt
.y
= *y
;
1388 if ( !IsTopLevel() )
1390 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1391 pt
.x
+= MacGetLeftBorderSize() ;
1392 pt
.y
+= MacGetTopBorderSize() ;
1395 if ( x
) *x
= (int) pt
.x
;
1396 if ( y
) *y
= (int) pt
.y
;
1398 if ( !IsTopLevel() )
1401 m_peer
->GetRect( &bounds
) ;
1402 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1403 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1408 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1413 MacRootWindowToWindow( &x1
, &y1
) ;
1418 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1420 RgnHandle rgn
= NewRgn() ;
1422 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1424 GetRegionBounds( rgn
, &content
) ;
1428 m_peer
->GetRect( &content
) ;
1432 m_peer
->GetRect( &structure
) ;
1433 #if !TARGET_API_MAC_OSX
1434 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1436 left
= content
.left
- structure
.left
;
1437 top
= content
.top
- structure
.top
;
1438 right
= structure
.right
- content
.right
;
1439 bottom
= structure
.bottom
- content
.bottom
;
1442 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1444 wxSize sizeTotal
= size
;
1446 RgnHandle rgn
= NewRgn() ;
1450 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1452 GetRegionBounds( rgn
, &content
) ;
1456 m_peer
->GetRect( &content
) ;
1460 m_peer
->GetRect( &structure
) ;
1461 #if !TARGET_API_MAC_OSX
1462 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1465 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1466 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1468 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1469 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1475 // Get size *available for subwindows* i.e. excluding menu bar etc.
1476 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1480 RgnHandle rgn
= NewRgn() ;
1482 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1484 GetRegionBounds( rgn
, &content
) ;
1488 m_peer
->GetRect( &content
) ;
1491 #if !TARGET_API_MAC_OSX
1493 m_peer
->GetRect( &structure
) ;
1494 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1496 ww
= content
.right
- content
.left
;
1497 hh
= content
.bottom
- content
.top
;
1499 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1500 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1503 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1509 GetSize( &w , &h ) ;
1511 MacClientToRootWindow( &x1 , &y1 ) ;
1512 MacClientToRootWindow( &w , &h ) ;
1514 wxWindowMac *iter = (wxWindowMac*)this ;
1516 int totW = 10000 , totH = 10000;
1519 if ( iter->IsTopLevel() )
1521 iter->GetSize( &totW , &totH ) ;
1525 iter = iter->GetParent() ;
1528 if (m_hScrollBar && m_hScrollBar->IsShown() )
1530 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1536 if (m_vScrollBar && m_vScrollBar->IsShown() )
1538 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1546 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1548 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1550 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1552 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1559 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1561 if (m_cursor
== cursor
)
1564 if (wxNullCursor
== cursor
)
1566 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1571 if ( ! wxWindowBase::SetCursor( cursor
) )
1575 wxASSERT_MSG( m_cursor
.Ok(),
1576 wxT("cursor must be valid after call to the base version"));
1579 wxWindowMac
*mouseWin
= 0 ;
1581 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1583 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1585 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1586 // position, use it...
1590 ControlPartCode part
;
1591 ControlRef control
;
1592 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1594 mouseWin
= wxFindControlFromMacControl( control
) ;
1597 QDSwapPort( savePort
, NULL
) ;
1600 if ( mouseWin
== this && !wxIsBusy() )
1602 m_cursor
.MacInstall() ;
1609 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1611 menu
->SetInvokingWindow(this);
1614 if ( x
== -1 && y
== -1 )
1616 wxPoint mouse
= wxGetMousePosition();
1617 x
= mouse
.x
; y
= mouse
.y
;
1621 ClientToScreen( &x
, &y
) ;
1624 menu
->MacBeforeDisplay( true ) ;
1625 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1626 if ( HiWord(menuResult
) != 0 )
1629 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1630 wxMenuItem
* item
= NULL
;
1632 item
= menu
->FindItem(id
, &realmenu
) ;
1633 if (item
->IsCheckable())
1635 item
->Check( !item
->IsChecked() ) ;
1637 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1639 menu
->MacAfterDisplay( true ) ;
1641 menu
->SetInvokingWindow(NULL
);
1647 // ----------------------------------------------------------------------------
1649 // ----------------------------------------------------------------------------
1653 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1655 wxWindowBase::DoSetToolTip(tooltip
);
1658 m_tooltip
->SetWindow(this);
1661 #endif // wxUSE_TOOLTIPS
1663 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1665 // this is never called for a toplevel window, so we know we have a parent
1666 int former_x
, former_y
, former_w
, former_h
;
1668 // Get true coordinates of former position
1669 DoGetPosition( &former_x
, &former_y
) ;
1670 DoGetSize( &former_w
, &former_h
) ;
1672 wxWindow
*parent
= GetParent();
1675 wxPoint
pt(parent
->GetClientAreaOrigin());
1680 int actualWidth
= width
;
1681 int actualHeight
= height
;
1685 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1686 actualWidth
= m_minWidth
;
1687 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1688 actualHeight
= m_minHeight
;
1689 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1690 actualWidth
= m_maxWidth
;
1691 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1692 actualHeight
= m_maxHeight
;
1694 bool doMove
= false ;
1695 bool doResize
= false ;
1697 if ( actualX
!= former_x
|| actualY
!= former_y
)
1701 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1706 if ( doMove
|| doResize
)
1708 // we don't adjust twice for the origin
1709 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1710 bool vis
= m_peer
->IsVisible();
1712 int outerBorder
= MacGetLeftBorderSize() ;
1713 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1716 if ( vis
&& ( outerBorder
> 0 ) )
1718 // as the borders are drawn on the parent we have to properly invalidate all these areas
1719 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1723 m_peer
->GetRect( &rect
) ;
1724 RectRgn( updateInner
, &rect
) ;
1725 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1726 RectRgn( updateOuter
, &rect
) ;
1727 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1728 wxPoint
parent(0,0);
1729 #if TARGET_API_MAC_OSX
1730 // no offsetting needed when compositing
1732 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1733 parent
-= GetParent()->GetClientAreaOrigin() ;
1734 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1736 CopyRgn( updateOuter
, updateTotal
) ;
1739 RectRgn( updateInner
, &rect
) ;
1740 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1741 RectRgn( updateOuter
, &rect
) ;
1742 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1744 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1745 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1747 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1748 DisposeRgn(updateOuter
) ;
1749 DisposeRgn(updateInner
) ;
1750 DisposeRgn(updateTotal
) ;
1753 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1755 m_peer
->SetVisibility( false , true ) ;
1757 m_peer
->SetRect( &r
) ;
1759 m_peer
->SetVisibility( true , true ) ;
1761 MacRepositionScrollBars() ;
1764 wxPoint
point(actualX
,actualY
);
1765 wxMoveEvent
event(point
, m_windowId
);
1766 event
.SetEventObject(this);
1767 GetEventHandler()->ProcessEvent(event
) ;
1771 MacRepositionScrollBars() ;
1772 wxSize
size(actualWidth
, actualHeight
);
1773 wxSizeEvent
event(size
, m_windowId
);
1774 event
.SetEventObject(this);
1775 GetEventHandler()->ProcessEvent(event
);
1781 wxSize
wxWindowMac::DoGetBestSize() const
1783 if ( m_macIsUserPane
|| IsTopLevel() )
1784 return wxWindowBase::DoGetBestSize() ;
1786 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1787 int bestWidth
, bestHeight
;
1788 m_peer
->GetBestRect( &bestsize
) ;
1790 if ( EmptyRect( &bestsize
) )
1792 bestsize
.left
= bestsize
.top
= 0 ;
1793 bestsize
.right
= 16 ;
1794 bestsize
.bottom
= 16 ;
1795 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1797 bestsize
.bottom
= 16 ;
1800 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1802 bestsize
.bottom
= 24 ;
1804 #endif // wxUSE_SPINBTN
1807 // return wxWindowBase::DoGetBestSize() ;
1811 bestWidth
= bestsize
.right
- bestsize
.left
;
1812 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1813 if ( bestHeight
< 10 )
1816 return wxSize(bestWidth
, bestHeight
);
1820 // set the size of the window: if the dimensions are positive, just use them,
1821 // but if any of them is equal to -1, it means that we must find the value for
1822 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1823 // which case -1 is a valid value for x and y)
1825 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1826 // the width/height to best suit our contents, otherwise we reuse the current
1828 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1830 // get the current size and position...
1831 int currentX
, currentY
;
1832 GetPosition(¤tX
, ¤tY
);
1834 int currentW
,currentH
;
1835 GetSize(¤tW
, ¤tH
);
1837 // ... and don't do anything (avoiding flicker) if it's already ok
1838 if ( x
== currentX
&& y
== currentY
&&
1839 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1842 MacRepositionScrollBars() ; // we might have a real position shift
1846 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1848 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1851 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1853 wxSize
size(-1, -1);
1856 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1858 size
= DoGetBestSize();
1863 // just take the current one
1870 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1874 size
= DoGetBestSize();
1876 //else: already called DoGetBestSize() above
1882 // just take the current one
1887 DoMoveWindow(x
, y
, width
, height
);
1891 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1893 RgnHandle rgn
= NewRgn() ;
1895 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1896 GetRegionBounds( rgn
, &content
) ;
1898 #if !TARGET_API_MAC_OSX
1899 // if the content rgn is empty / not supported
1900 // don't attempt to correct the coordinates to wxWindow relative ones
1901 if (!::EmptyRect( &content
) )
1904 m_peer
->GetRect( &structure
) ;
1905 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1909 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1912 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1914 if ( clientheight
!= -1 || clientheight
!= -1 )
1916 int currentclientwidth
, currentclientheight
;
1917 int currentwidth
, currentheight
;
1919 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1920 GetSize( ¤twidth
, ¤theight
) ;
1922 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1923 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1927 void wxWindowMac::SetTitle(const wxString
& title
)
1929 m_label
= wxStripMenuCodes(title
) ;
1931 if ( m_peer
&& m_peer
->Ok() )
1933 m_peer
->SetTitle( m_label
) ;
1938 wxString
wxWindowMac::GetTitle() const
1943 bool wxWindowMac::Show(bool show
)
1945 if ( !wxWindowBase::Show(show
) )
1948 // TODO use visibilityChanged Carbon Event for OSX
1951 bool former
= MacIsReallyShown() ;
1953 m_peer
->SetVisibility( show
, true ) ;
1954 if ( former
!= MacIsReallyShown() )
1955 MacPropagateVisibilityChanged() ;
1960 bool wxWindowMac::Enable(bool enable
)
1962 wxASSERT( m_peer
->Ok() ) ;
1963 if ( !wxWindowBase::Enable(enable
) )
1966 bool former
= MacIsReallyEnabled() ;
1967 m_peer
->Enable( enable
) ;
1969 if ( former
!= MacIsReallyEnabled() )
1970 MacPropagateEnabledStateChanged() ;
1975 // status change propagations (will be not necessary for OSX later )
1978 void wxWindowMac::MacPropagateVisibilityChanged()
1980 #if !TARGET_API_MAC_OSX
1981 MacVisibilityChanged() ;
1983 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1986 wxWindowMac
*child
= node
->GetData();
1987 if ( child
->IsShown() )
1988 child
->MacPropagateVisibilityChanged( ) ;
1989 node
= node
->GetNext();
1994 void wxWindowMac::MacPropagateEnabledStateChanged( )
1996 #if !TARGET_API_MAC_OSX
1997 MacEnabledStateChanged() ;
1999 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2002 wxWindowMac
*child
= node
->GetData();
2003 if ( child
->IsEnabled() )
2004 child
->MacPropagateEnabledStateChanged() ;
2005 node
= node
->GetNext();
2010 void wxWindowMac::MacPropagateHiliteChanged( )
2012 #if !TARGET_API_MAC_OSX
2013 MacHiliteChanged() ;
2015 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2018 wxWindowMac
*child
= node
->GetData();
2019 // if ( child->IsEnabled() )
2020 child
->MacPropagateHiliteChanged() ;
2021 node
= node
->GetNext();
2027 // status change notifications
2030 void wxWindowMac::MacVisibilityChanged()
2034 void wxWindowMac::MacHiliteChanged()
2038 void wxWindowMac::MacEnabledStateChanged()
2043 // status queries on the inherited window's state
2046 bool wxWindowMac::MacIsReallyShown()
2048 // only under OSX the visibility of the TLW is taken into account
2049 if ( m_isBeingDeleted
)
2052 #if TARGET_API_MAC_OSX
2053 if ( m_peer
&& m_peer
->Ok() )
2054 return m_peer
->IsVisible();
2056 wxWindow
* win
= this ;
2057 while( win
->IsShown() )
2059 if ( win
->IsTopLevel() )
2062 win
= win
->GetParent() ;
2070 bool wxWindowMac::MacIsReallyEnabled()
2072 return m_peer
->IsEnabled() ;
2075 bool wxWindowMac::MacIsReallyHilited()
2077 return m_peer
->IsActive();
2080 void wxWindowMac::MacFlashInvalidAreas()
2082 #if TARGET_API_MAC_OSX
2083 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2091 int wxWindowMac::GetCharHeight() const
2093 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2094 return dc
.GetCharHeight() ;
2097 int wxWindowMac::GetCharWidth() const
2099 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2100 return dc
.GetCharWidth() ;
2103 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2104 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2106 const wxFont
*fontToUse
= theFont
;
2108 fontToUse
= &m_font
;
2110 wxClientDC
dc( (wxWindowMac
*) this ) ;
2112 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2113 if ( externalLeading
)
2114 *externalLeading
= le
;
2124 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2125 * we always intersect with the entire window, not only with the client area
2128 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2130 if ( m_peer
== NULL
)
2133 #if TARGET_API_MAC_OSX
2135 m_peer
->SetNeedsDisplay( true ) ;
2138 RgnHandle update
= NewRgn() ;
2139 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2140 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2141 wxPoint origin
= GetClientAreaOrigin() ;
2142 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2143 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2145 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2146 m_peer
->SetNeedsDisplay( true , update
) ;
2147 DisposeRgn( update
) ;
2151 RgnHandle updateRgn = NewRgn() ;
2154 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2158 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2159 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2161 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2162 DisposeRgn(updateRgn) ;
2164 if ( m_peer
->IsVisible())
2166 m_peer
->SetVisibility( false , false ) ;
2167 m_peer
->SetVisibility( true , true ) ;
2170 if ( MacGetTopLevelWindow() == NULL )
2173 if ( !m_peer->IsVisible())
2176 wxPoint client = GetClientAreaOrigin();
2179 int x2 = m_width - client.x;
2180 int y2 = m_height - client.y;
2182 if (IsKindOf( CLASSINFO(wxButton)))
2184 // buttons have an "aura"
2191 Rect clientrect = { y1, x1, y2, x2 };
2195 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2196 SectRect( &clientrect , &r , &clientrect ) ;
2199 if ( !EmptyRect( &clientrect ) )
2201 int top = 0 , left = 0 ;
2203 MacClientToRootWindow( &left , &top ) ;
2204 OffsetRect( &clientrect , left , top ) ;
2206 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2212 void wxWindowMac::Freeze()
2214 #if TARGET_API_MAC_OSX
2215 if ( !m_frozenness
++ )
2217 if ( m_peer
&& m_peer
->Ok() )
2218 m_peer
->SetDrawingEnabled( false ) ;
2224 void wxWindowMac::Thaw()
2226 #if TARGET_API_MAC_OSX
2227 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2229 if ( !--m_frozenness
)
2231 if ( m_peer
&& m_peer
->Ok() )
2233 m_peer
->SetDrawingEnabled( true ) ;
2234 m_peer
->InvalidateWithChildren() ;
2240 wxWindowMac
*wxGetActiveWindow()
2242 // actually this is a windows-only concept
2246 // Coordinates relative to the window
2247 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2249 // We really don't move the mouse programmatically under Mac.
2252 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2254 #if TARGET_API_MAC_OSX
2255 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2262 event
.GetDC()->Clear() ;
2266 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2271 int wxWindowMac::GetScrollPos(int orient
) const
2273 if ( orient
== wxHORIZONTAL
)
2276 return m_hScrollBar
->GetThumbPosition() ;
2281 return m_vScrollBar
->GetThumbPosition() ;
2286 // This now returns the whole range, not just the number
2287 // of positions that we can scroll.
2288 int wxWindowMac::GetScrollRange(int orient
) const
2290 if ( orient
== wxHORIZONTAL
)
2293 return m_hScrollBar
->GetRange() ;
2298 return m_vScrollBar
->GetRange() ;
2303 int wxWindowMac::GetScrollThumb(int orient
) const
2305 if ( orient
== wxHORIZONTAL
)
2308 return m_hScrollBar
->GetThumbSize() ;
2313 return m_vScrollBar
->GetThumbSize() ;
2318 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2320 if ( orient
== wxHORIZONTAL
)
2323 m_hScrollBar
->SetThumbPosition( pos
) ;
2328 m_vScrollBar
->SetThumbPosition( pos
) ;
2333 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2334 // our own window origin is at leftOrigin/rightOrigin
2337 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2343 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2344 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2346 m_peer
->GetRect( &rect
) ;
2347 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2349 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2350 if ( HIThemeDrawFrame
!= 0)
2353 HIThemeFrameDrawInfo info
;
2354 memset( &info
, 0 , sizeof( info
) ) ;
2358 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2359 info
.isFocused
= hasFocus
;
2362 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2363 wxASSERT( cgContext
) ;
2365 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2368 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2369 InsetRect( &srect
, border
, border
);
2370 info
.kind
= kHIThemeFrameTextFieldSquare
;
2373 else if (HasFlag(wxSIMPLE_BORDER
))
2376 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2377 InsetRect( &srect
, border
, border
);
2378 info
.kind
= kHIThemeFrameListBox
;
2384 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2385 srect
.bottom
- srect
.top
) ;
2386 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2388 else if ( hasFocus
)
2391 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2392 srect
.bottom
- srect
.top
) ;
2393 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2396 m_peer
->GetRect( &rect
) ;
2397 if ( hasBothScrollbars
)
2400 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2401 CGRect cgrect
= CGRectMake( srect
.right
- size
, srect
.bottom
- size
, size
, size
) ;
2402 CGPoint cgpoint
= CGPointMake( srect
.right
- size
, srect
.bottom
- size
) ;
2403 HIThemeGrowBoxDrawInfo info
;
2404 memset( &info
, 0 , sizeof( info
) ) ;
2406 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2407 info
.kind
= kHIThemeGrowBoxKindNone
;
2408 info
.size
= kHIThemeGrowBoxSizeNormal
;
2409 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2410 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2416 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2420 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2422 rect
.right
+= pt
.x
;
2424 rect
.bottom
+= pt
.y
;
2427 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2431 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2432 InsetRect( &srect
, border
, border
);
2433 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2435 else if (HasFlag(wxSIMPLE_BORDER
))
2439 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2440 InsetRect( &srect
, border
, border
);
2441 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2447 DrawThemeFocusRect( &srect
, true ) ;
2449 if ( hasBothScrollbars
)
2451 // GetThemeStandaloneGrowBoxBounds
2452 //DrawThemeStandaloneNoGrowBox
2457 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2459 if ( child
== m_hScrollBar
)
2460 m_hScrollBar
= NULL
;
2461 if ( child
== m_vScrollBar
)
2462 m_vScrollBar
= NULL
;
2464 wxWindowBase::RemoveChild( child
) ;
2467 // New function that will replace some of the above.
2468 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2469 int range
, bool refresh
)
2471 if ( orient
== wxHORIZONTAL
)
2475 if ( range
== 0 || thumbVisible
>= range
)
2477 if ( m_hScrollBar
->IsShown() )
2478 m_hScrollBar
->Show(false) ;
2482 if ( !m_hScrollBar
->IsShown() )
2483 m_hScrollBar
->Show(true) ;
2485 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2492 if ( range
== 0 || thumbVisible
>= range
)
2494 if ( m_vScrollBar
->IsShown() )
2495 m_vScrollBar
->Show(false) ;
2499 if ( !m_vScrollBar
->IsShown() )
2500 m_vScrollBar
->Show(true) ;
2502 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2505 MacRepositionScrollBars() ;
2508 // Does a physical scroll
2509 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2511 if( dx
== 0 && dy
==0 )
2517 int width
, height
;
2518 GetClientSize( &width
, &height
) ;
2519 #if TARGET_API_MAC_OSX
2520 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2521 // area is scrolled, this does not occur if width and height are 2 pixels less,
2522 // TODO write optimal workaround
2523 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2526 scrollrect
.Intersect( *rect
) ;
2528 if ( m_peer
->GetNeedsDisplay() )
2530 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2531 // either immediate redraw or full invalidate
2533 // is the better overall solution, as it does not slow down scrolling
2534 m_peer
->SetNeedsDisplay( true ) ;
2536 // this would be the preferred version for fast drawing controls
2537 if( UMAGetSystemVersion() < 0x1030 )
2540 HIViewRender(m_peer
->GetControlRef()) ;
2543 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2544 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2545 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2552 RgnHandle updateRgn
= NewRgn() ;
2555 wxClientDC
dc(this) ;
2556 wxMacPortSetter
helper(&dc
) ;
2558 m_peer
->GetRect( &scrollrect
) ;
2559 scrollrect
.top
+= MacGetTopBorderSize() ;
2560 scrollrect
.left
+= MacGetLeftBorderSize() ;
2561 scrollrect
.bottom
= scrollrect
.top
+ height
;
2562 scrollrect
.right
= scrollrect
.left
+ width
;
2566 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2567 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2568 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2570 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2572 // now scroll the former update region as well and add the new update region
2574 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2575 RgnHandle formerUpdateRgn
= NewRgn() ;
2576 RgnHandle scrollRgn
= NewRgn() ;
2577 RectRgn( scrollRgn
, &scrollrect
) ;
2578 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2580 LocalToGlobal( &pt
) ;
2581 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2582 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2583 if ( !EmptyRgn( formerUpdateRgn
) )
2585 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2586 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2587 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2589 InvalWindowRgn(rootWindow
, updateRgn
) ;
2590 DisposeRgn( updateRgn
) ;
2591 DisposeRgn( formerUpdateRgn
) ;
2592 DisposeRgn( scrollRgn
) ;
2597 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2599 wxWindowMac
*child
= node
->GetData();
2600 if (child
== m_vScrollBar
) continue;
2601 if (child
== m_hScrollBar
) continue;
2602 if (child
->IsTopLevel()) continue;
2605 child
->GetPosition( &x
, &y
);
2607 child
->GetSize( &w
, &h
);
2611 if (rect
->Intersects(rc
))
2612 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2616 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2621 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2623 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2625 wxScrollWinEvent wevent
;
2626 wevent
.SetPosition(event
.GetPosition());
2627 wevent
.SetOrientation(event
.GetOrientation());
2628 wevent
.SetEventObject(this);
2630 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2631 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2632 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2633 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2634 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2635 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2636 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2637 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2638 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2639 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2640 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2641 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2642 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2643 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2644 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2645 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2647 GetEventHandler()->ProcessEvent(wevent
);
2651 // Get the window with the focus
2652 wxWindowMac
*wxWindowBase::DoFindFocus()
2654 ControlRef control
;
2655 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2656 return wxFindControlFromMacControl( control
) ;
2659 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2661 // panel wants to track the window which was the last to have focus in it,
2662 // so we want to set ourselves as the window which last had focus
2664 // notice that it's also important to do it upwards the tree becaus
2665 // otherwise when the top level panel gets focus, it won't set it back to
2666 // us, but to some other sibling
2668 // CS:don't know if this is still needed:
2669 //wxChildFocusEvent eventFocus(this);
2670 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2672 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2674 #if !wxMAC_USE_CORE_GRAPHICS
2675 wxMacWindowStateSaver
sv( this ) ;
2680 MacWindowToRootWindow( &x
, &y
) ;
2681 GetSize( &w
, &h
) ;
2682 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2684 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2685 DrawThemeFocusRect( &rect
, true ) ;
2688 DrawThemeFocusRect( &rect
, false ) ;
2690 // as this erases part of the frame we have to redraw borders
2691 // and because our z-ordering is not always correct (staticboxes)
2692 // we have to invalidate things, we cannot simple redraw
2693 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2694 RectRgn( updateInner
, &rect
) ;
2695 InsetRect( &rect
, -4 , -4 ) ;
2696 RectRgn( updateOuter
, &rect
) ;
2697 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2698 wxPoint
parent(0,0);
2699 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2700 parent
-= GetParent()->GetClientAreaOrigin() ;
2701 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2702 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2703 DisposeRgn(updateOuter
) ;
2704 DisposeRgn(updateInner
) ;
2707 GetParent()->Refresh() ;
2714 void wxWindowMac::OnInternalIdle()
2716 // This calls the UI-update mechanism (querying windows for
2717 // menu/toolbar/control state information)
2718 if (wxUpdateUIEvent::CanUpdate(this))
2719 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2722 // Raise the window to the top of the Z order
2723 void wxWindowMac::Raise()
2725 m_peer
->SetZOrder( true , NULL
) ;
2728 // Lower the window to the bottom of the Z order
2729 void wxWindowMac::Lower()
2731 m_peer
->SetZOrder( false , NULL
) ;
2735 // static wxWindow *gs_lastWhich = NULL;
2737 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2739 // first trigger a set cursor event
2741 wxPoint clientorigin
= GetClientAreaOrigin() ;
2742 wxSize clientsize
= GetClientSize() ;
2744 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2746 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2748 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2749 if ( processedEvtSetCursor
&& event
.HasCursor() )
2751 cursor
= event
.GetCursor() ;
2756 // the test for processedEvtSetCursor is here to prevent using m_cursor
2757 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2758 // it - this is a way to say that our cursor shouldn't be used for this
2760 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2770 cursor
= *wxSTANDARD_CURSOR
;
2774 cursor
.MacInstall() ;
2776 return cursor
.Ok() ;
2779 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2783 return m_tooltip
->GetTip() ;
2785 return wxEmptyString
;
2788 void wxWindowMac::ClearBackground()
2794 void wxWindowMac::Update()
2796 #if TARGET_API_MAC_OSX
2798 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2799 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2801 // for composited windows this also triggers a redraw of all
2802 // invalid views in the window
2803 if( UMAGetSystemVersion() >= 0x1030 )
2804 HIWindowFlush(window
) ;
2808 // the only way to trigger the redrawing on earlier systems is to call
2811 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2812 UInt32 currentEventClass
= 0 ;
2813 UInt32 currentEventKind
= 0 ;
2814 if ( currentEvent
!= NULL
)
2816 currentEventClass
= ::GetEventClass( currentEvent
) ;
2817 currentEventKind
= ::GetEventKind( currentEvent
) ;
2819 if ( currentEventClass
!= kEventClassMenu
)
2821 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2824 OSStatus status
= noErr
;
2825 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2828 m_peer
->SetNeedsDisplay( true ) ;
2831 ::Draw1Control( m_peer
->GetControlRef() ) ;
2835 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2837 wxTopLevelWindowMac
* win
= NULL
;
2838 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2841 win
= wxFindWinFromMacWindow( window
) ;
2845 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2847 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2848 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2849 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2850 // to add focus borders everywhere
2853 RgnHandle visRgn
= NewRgn() ;
2854 RgnHandle tempRgn
= NewRgn() ;
2855 if ( !m_isBeingDeleted
&& m_peer
->IsVisible())
2857 m_peer
->GetRect( &r
) ;
2858 r
.left
-= MacGetLeftBorderSize() ;
2859 r
.top
-= MacGetTopBorderSize() ;
2860 r
.bottom
+= MacGetBottomBorderSize() ;
2861 r
.right
+= MacGetRightBorderSize() ;
2863 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2865 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2866 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2875 if ( includeOuterStructures
)
2876 InsetRect( &r
, -4 , -4 ) ;
2877 RectRgn( visRgn
, &r
) ;
2879 if ( !IsTopLevel() )
2881 wxWindow
* child
= this ;
2882 wxWindow
* parent
= child
->GetParent() ;
2887 // we have to find a better clipping algorithm here, in order not to clip things
2888 // positioned like status and toolbar
2889 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2891 size
= parent
->GetSize() ;
2896 size
= parent
->GetClientSize() ;
2897 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2901 parent
->MacWindowToRootWindow( &x
, &y
) ;
2902 MacRootWindowToWindow( &x
, &y
) ;
2904 if ( !includeOuterStructures
|| (
2905 parent
->MacClipChildren() ||
2906 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2909 SetRectRgn( tempRgn
,
2910 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2911 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2912 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2914 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2916 if ( parent
->IsTopLevel() )
2919 parent
= child
->GetParent() ;
2924 wxRegion vis
= visRgn
;
2925 DisposeRgn( visRgn
) ;
2926 DisposeRgn( tempRgn
) ;
2931 This function must not change the updatergn !
2933 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2935 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2936 bool handled
= false ;
2938 GetRegionBounds( updatergn
, &updatebounds
) ;
2940 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2942 if ( !EmptyRgn(updatergn
) )
2944 RgnHandle newupdate
= NewRgn() ;
2945 wxSize point
= GetClientSize() ;
2946 wxPoint origin
= GetClientAreaOrigin() ;
2947 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2948 SectRgn( newupdate
, updatergn
, newupdate
) ;
2950 // first send an erase event to the entire update area
2952 // for the toplevel window this really is the entire area
2953 // for all the others only their client area, otherwise they
2954 // might be drawing with full alpha and eg put blue into
2955 // the grow-box area of a scrolled window (scroll sample)
2958 dc
= new wxWindowDC(this);
2960 dc
= new wxClientDC(this);
2961 dc
->SetClippingRegion(wxRegion(updatergn
));
2962 wxEraseEvent
eevent( GetId(), dc
);
2963 eevent
.SetEventObject( this );
2964 GetEventHandler()->ProcessEvent( eevent
);
2968 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2969 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2970 m_updateRegion
= newupdate
;
2971 DisposeRgn( newupdate
) ;
2973 if ( !m_updateRegion
.Empty() )
2975 // paint the window itself
2978 event
.SetTimestamp(time
);
2979 event
.SetEventObject(this);
2980 GetEventHandler()->ProcessEvent(event
);
2984 // now we cannot rely on having its borders drawn by a window itself, as it does not
2985 // get the updateRgn wide enough to always do so, so we do it from the parent
2986 // this would also be the place to draw any custom backgrounds for native controls
2987 // in Composited windowing
2988 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2990 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2992 wxWindowMac
*child
= node
->GetData();
2993 if (child
== m_vScrollBar
) continue;
2994 if (child
== m_hScrollBar
) continue;
2995 if (child
->IsTopLevel()) continue;
2996 if (!child
->IsShown()) continue;
2998 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3001 child
->GetPosition( &x
, &y
);
3003 child
->GetSize( &w
, &h
);
3004 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3005 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3006 InsetRect( &childRect
, -10 , -10) ;
3008 if ( RectInRgn( &childRect
, updatergn
) )
3011 // paint custom borders
3012 wxNcPaintEvent
eventNc( child
->GetId() );
3013 eventNc
.SetEventObject( child
);
3014 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3016 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3017 if ( HIThemeDrawFrame
!= 0)
3019 child
->MacPaintBorders(0,0) ;
3024 wxWindowDC
dc(this) ;
3025 dc
.SetClippingRegion(wxRegion(updatergn
));
3026 wxMacPortSetter
helper(&dc
) ;
3027 child
->MacPaintBorders(0,0) ;
3037 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3039 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3043 if ( iter
->IsTopLevel() )
3044 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3046 iter
= iter
->GetParent() ;
3048 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3052 void wxWindowMac::MacCreateScrollBars( long style
)
3054 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3056 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3058 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3059 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3060 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3061 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3063 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3064 variant
= wxWINDOW_VARIANT_SMALL
;
3067 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3069 GetClientSize( &width
, &height
) ;
3071 wxPoint
vPoint(width
-scrlsize
, 0) ;
3072 wxSize
vSize(scrlsize
, height
- adjust
) ;
3073 wxPoint
hPoint(0 , height
-scrlsize
) ;
3074 wxSize
hSize( width
- adjust
, scrlsize
) ;
3077 if ( style
& wxVSCROLL
)
3079 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3080 vSize
, wxVERTICAL
);
3083 if ( style
& wxHSCROLL
)
3085 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3086 hSize
, wxHORIZONTAL
);
3091 // because the create does not take into account the client area origin
3092 MacRepositionScrollBars() ; // we might have a real position shift
3095 void wxWindowMac::MacRepositionScrollBars()
3097 if ( !m_hScrollBar
&& !m_vScrollBar
)
3100 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3101 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3102 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3104 // get real client area
3108 GetSize( &width
, &height
) ;
3110 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3111 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3113 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3114 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3115 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3116 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3122 GetSize( &w , &h ) ;
3124 MacClientToRootWindow( &x , &y ) ;
3125 MacClientToRootWindow( &w , &h ) ;
3127 wxWindowMac *iter = (wxWindowMac*)this ;
3129 int totW = 10000 , totH = 10000;
3132 if ( iter->IsTopLevel() )
3134 iter->GetSize( &totW , &totH ) ;
3138 iter = iter->GetParent() ;
3166 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3170 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3174 bool wxWindowMac::AcceptsFocus() const
3176 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3179 void wxWindowMac::MacSuperChangedPosition()
3181 // only window-absolute structures have to be moved i.e. controls
3183 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3186 wxWindowMac
*child
= node
->GetData();
3187 child
->MacSuperChangedPosition() ;
3188 node
= node
->GetNext();
3192 void wxWindowMac::MacTopLevelWindowChangedPosition()
3194 // only screen-absolute structures have to be moved i.e. glcanvas
3196 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3199 wxWindowMac
*child
= node
->GetData();
3200 child
->MacTopLevelWindowChangedPosition() ;
3201 node
= node
->GetNext();
3205 long wxWindowMac::MacGetLeftBorderSize( ) const
3210 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3215 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3220 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3227 long wxWindowMac::MacGetRightBorderSize( ) const
3229 // they are all symmetric in mac themes
3230 return MacGetLeftBorderSize() ;
3233 long wxWindowMac::MacGetTopBorderSize( ) const
3235 // they are all symmetric in mac themes
3236 return MacGetLeftBorderSize() ;
3239 long wxWindowMac::MacGetBottomBorderSize( ) const
3241 // they are all symmetric in mac themes
3242 return MacGetLeftBorderSize() ;
3245 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3247 return style
& ~wxBORDER_MASK
;
3250 // Find the wxWindowMac at the current mouse position, returning the mouse
3252 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3254 pt
= wxGetMousePosition();
3255 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3259 // Get the current mouse position.
3260 wxPoint
wxGetMousePosition()
3263 wxGetMousePosition(& x
, & y
);
3264 return wxPoint(x
, y
);
3267 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3269 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3271 // copied from wxGTK : CS
3272 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3275 // (a) it's a command event and so is propagated to the parent
3276 // (b) under MSW it can be generated from kbd too
3277 // (c) it uses screen coords (because of (a))
3278 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3280 this->ClientToScreen(event
.GetPosition()));
3281 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3290 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3292 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3294 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3298 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3302 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3306 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3307 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3311 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3313 return eventNotHandledErr
;