1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
50 #define MAC_SCROLLBAR_SIZE 15
51 #define MAC_SMALL_SCROLLBAR_SIZE 11
53 #include "wx/mac/uma.h"
56 #include <ToolUtils.h>
58 #include <MacTextEditor.h>
61 #if TARGET_API_MAC_OSX
63 #include <HIToolbox/HIView.h>
67 #if wxUSE_DRAG_AND_DROP
73 extern wxList wxPendingDelete
;
75 #ifdef __WXUNIVERSAL__
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
78 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
79 #endif // __WXUNIVERSAL__/__WXMAC__
81 #if !USE_SHARED_LIBRARY
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
85 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
86 // TODO 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 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
224 if ( thisWindow
->MacIsUserPane() )
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
);
243 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
246 DisposeRgn( allocatedRgn
) ;
249 case kEventControlVisibilityChanged
:
250 thisWindow
->MacVisibilityChanged() ;
252 case kEventControlEnabledStateChanged
:
253 thisWindow
->MacEnabledStateChanged() ;
255 case kEventControlHiliteChanged
:
256 thisWindow
->MacHiliteChanged() ;
258 case kEventControlSetFocusPart
:
260 Boolean focusEverything
= false ;
261 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
262 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
265 if ( controlPart
== kControlFocusNoPart
)
268 if ( thisWindow
->GetCaret() )
270 thisWindow
->GetCaret()->OnKillFocus();
272 #endif // wxUSE_CARET
273 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
274 event
.SetEventObject(thisWindow
);
275 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
279 // panel wants to track the window which was the last to have focus in it
280 wxChildFocusEvent
eventFocus(thisWindow
);
281 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
284 if ( thisWindow
->GetCaret() )
286 thisWindow
->GetCaret()->OnSetFocus();
288 #endif // wxUSE_CARET
290 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
291 event
.SetEventObject(thisWindow
);
292 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
294 if ( thisWindow
->MacIsUserPane() )
299 case kEventControlHit
:
301 result
= thisWindow
->MacControlHit( handler
, event
) ;
310 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
312 OSStatus result
= eventNotHandledErr
;
314 wxMacCarbonEvent
cEvent( event
) ;
316 ControlRef controlRef
;
317 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
318 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
319 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
321 switch( GetEventKind( event
) )
323 case kEventServiceGetTypes
:
327 textCtrl
->GetSelection( &from
, &to
) ;
329 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
331 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
332 if ( textCtrl
->IsEditable() )
333 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
335 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
336 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
338 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
342 CFArrayAppendValue (copyTypes
, typestring
) ;
344 CFArrayAppendValue (pasteTypes
, typestring
) ;
345 CFRelease( typestring
) ;
351 case kEventServiceCopy
:
355 textCtrl
->GetSelection( &from
, &to
) ;
356 wxString val
= textCtrl
->GetValue() ;
357 val
= val
.Mid( from
, to
- from
) ;
358 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
359 verify_noerr( ClearScrap( &scrapRef
) ) ;
360 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
364 case kEventServicePaste
:
367 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
368 Size textSize
, pastedSize
;
369 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
371 char *content
= new char[textSize
] ;
372 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
373 content
[textSize
-1] = 0 ;
375 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
377 textCtrl
->WriteText( wxString( content
) ) ;
388 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
390 OSStatus result
= eventNotHandledErr
;
392 switch ( GetEventClass( event
) )
394 case kEventClassControl
:
395 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
397 case kEventClassService
:
398 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
405 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
407 // ---------------------------------------------------------------------------
408 // UserPane events for non OSX builds
409 // ---------------------------------------------------------------------------
411 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
413 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
414 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
415 win
->MacControlUserPaneDrawProc(part
) ;
418 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
420 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
421 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
422 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
425 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
427 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
428 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
429 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
432 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
434 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
435 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
436 win
->MacControlUserPaneIdleProc() ;
439 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
441 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
442 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
443 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
446 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
448 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
449 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
450 win
->MacControlUserPaneActivateProc(activating
) ;
453 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
455 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
456 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
457 return win
->MacControlUserPaneFocusProc(action
) ;
460 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
462 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
463 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
464 win
->MacControlUserPaneBackgroundProc(info
) ;
467 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
469 RgnHandle rgn
= NewRgn() ;
471 wxMacWindowStateSaver
sv( this ) ;
472 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
473 MacDoRedraw( rgn
, 0 ) ;
477 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
479 return kControlNoPart
;
482 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
484 return kControlNoPart
;
487 void wxWindowMac::MacControlUserPaneIdleProc()
491 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
493 return kControlNoPart
;
496 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
500 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
502 return kControlNoPart
;
505 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
509 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
510 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
511 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
512 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
513 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
514 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
515 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
516 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
518 // ===========================================================================
520 // ===========================================================================
522 wxList
wxWinMacControlList(wxKEY_INTEGER
);
524 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
526 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
529 return (wxControl
*)node
->GetData();
532 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
534 // adding NULL ControlRef is (first) surely a result of an error and
535 // (secondly) breaks native event processing
536 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
538 if ( !wxWinMacControlList
.Find((long)inControl
) )
539 wxWinMacControlList
.Append((long)inControl
, control
);
542 void wxRemoveMacControlAssociation(wxWindow
*control
)
544 wxWinMacControlList
.DeleteObject(control
);
548 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
550 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
552 // we have to setup the brush in the current port and return noErr
553 // or return an error code so that the control manager walks further up the
554 // hierarchy to find a correct background
556 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
558 OSStatus status
= paramErr
;
561 case kControlMsgApplyTextColor
:
563 case kControlMsgSetUpBackground
:
565 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
569 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
572 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
574 // this clipping is only needed for non HIView
576 RgnHandle clip
= NewRgn() ;
579 wx
->MacWindowToRootWindow( &x
,&y
) ;
580 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
581 OffsetRgn( clip
, x
, y
) ;
588 else if ( wx->MacIsUserPane() )
590 // if we don't have a valid brush for such a control, we have to call the
591 // setup of our parent ourselves
592 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
605 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
606 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
610 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
613 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
618 // ----------------------------------------------------------------------------
619 // constructors and such
620 // ----------------------------------------------------------------------------
622 wxWindowMac::wxWindowMac()
627 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
632 const wxString
& name
)
635 Create(parent
, id
, pos
, size
, style
, name
);
638 void wxWindowMac::Init()
642 #if WXWIN_COMPATIBILITY_2_4
643 m_backgroundTransparent
= FALSE
;
646 // as all windows are created with WS_VISIBLE style...
649 m_hScrollBar
= NULL
;
650 m_vScrollBar
= NULL
;
651 m_macBackgroundBrush
= wxNullBrush
;
653 m_macIsUserPane
= TRUE
;
655 // make sure all proc ptrs are available
657 if ( gControlUserPaneDrawUPP
== NULL
)
659 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
660 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
661 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
662 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
663 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
664 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
665 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
666 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
668 if ( wxMacLiveScrollbarActionUPP
== NULL
)
670 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
673 if ( wxMacSetupControlBackgroundUPP
== NULL
)
675 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
678 // we need a valid font for the encodings
679 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
683 wxWindowMac::~wxWindowMac()
687 m_isBeingDeleted
= TRUE
;
689 #ifndef __WXUNIVERSAL__
690 // VS: make sure there's no wxFrame with last focus set to us:
691 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
693 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
696 if ( frame
->GetLastFocus() == this )
698 frame
->SetLastFocus((wxWindow
*)NULL
);
703 #endif // __WXUNIVERSAL__
705 // wxRemoveMacControlAssociation( this ) ;
706 // If we delete an item, we should initialize the parent panel,
707 // because it could now be invalid.
708 wxWindow
*parent
= GetParent() ;
711 if (parent
->GetDefaultItem() == (wxButton
*) this)
712 parent
->SetDefaultItem(NULL
);
714 if ( m_peer
&& m_peer
->Ok() )
716 // in case the callback might be called during destruction
717 wxRemoveMacControlAssociation( this) ;
718 // we currently are not using this hook
719 // ::SetControlColorProc( *m_peer , NULL ) ;
723 if ( g_MacLastWindow
== this )
725 g_MacLastWindow
= NULL
;
728 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
731 if ( frame
->GetLastFocus() == this )
732 frame
->SetLastFocus( NULL
) ;
737 // delete our drop target if we've got one
738 #if wxUSE_DRAG_AND_DROP
739 if ( m_dropTarget
!= NULL
)
744 #endif // wxUSE_DRAG_AND_DROP
748 WXWidget
wxWindowMac::GetHandle() const
750 return (WXWidget
) m_peer
->GetControlRef() ;
754 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
756 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
757 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
758 GetEventTypeCount(eventList
), eventList
, this,
759 (EventHandlerRef
*)&m_macControlEventHandler
);
764 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
768 const wxString
& name
)
770 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
772 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
775 parent
->AddChild(this);
777 m_windowVariant
= parent
->GetWindowVariant() ;
779 if ( m_macIsUserPane
)
781 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
784 | kControlSupportsEmbedding
785 // | kControlSupportsLiveFeedback
786 // | kControlHasSpecialBackground
787 // | kControlSupportsCalcBestRect
788 // | kControlHandlesTracking
789 | kControlSupportsFocus
790 // | kControlWantsActivate
791 // | kControlWantsIdle
794 m_peer
= new wxMacControl() ;
795 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
798 MacPostControlCreate(pos
,size
) ;
799 #if !TARGET_API_MAC_OSX
800 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
801 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
802 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
803 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
804 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
805 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
806 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
807 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
810 #ifndef __WXUNIVERSAL__
811 // Don't give scrollbars to wxControls unless they ask for them
812 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
813 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
815 MacCreateScrollBars( style
) ;
819 wxWindowCreateEvent
event(this);
820 GetEventHandler()->AddPendingEvent(event
);
825 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
827 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
829 m_peer
->SetReference( (long) this ) ;
831 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
833 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
834 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
835 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
837 // adjust font, controlsize etc
838 DoSetWindowVariant( m_windowVariant
) ;
840 #if !TARGET_API_MAC_OSX
841 // eventually we can fix some clipping issues be reactivating this hook
842 //if ( m_macIsUserPane )
843 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
845 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
847 if (!m_macIsUserPane
)
849 SetInitialBestSize(size
);
852 SetCursor( *wxSTANDARD_CURSOR
) ;
855 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
857 // Don't assert, in case we set the window variant before
858 // the window is created
859 // wxASSERT( m_peer->Ok() ) ;
861 m_windowVariant
= variant
;
863 if (m_peer
== NULL
|| !m_peer
->Ok())
867 ThemeFontID themeFont
= kThemeSystemFont
;
869 // we will get that from the settings later
870 // and make this NORMAL later, but first
871 // we have a few calculations that we must fix
875 case wxWINDOW_VARIANT_NORMAL
:
876 size
= kControlSizeNormal
;
877 themeFont
= kThemeSystemFont
;
879 case wxWINDOW_VARIANT_SMALL
:
880 size
= kControlSizeSmall
;
881 themeFont
= kThemeSmallSystemFont
;
883 case wxWINDOW_VARIANT_MINI
:
884 if (UMAGetSystemVersion() >= 0x1030 )
886 // not always defined in the headers
892 size
= kControlSizeSmall
;
893 themeFont
= kThemeSmallSystemFont
;
896 case wxWINDOW_VARIANT_LARGE
:
897 size
= kControlSizeLarge
;
898 themeFont
= kThemeSystemFont
;
901 wxFAIL_MSG(_T("unexpected window variant"));
904 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
907 font
.MacCreateThemeFont( themeFont
) ;
911 void wxWindowMac::MacUpdateControlFont()
913 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
917 bool wxWindowMac::SetFont(const wxFont
& font
)
919 bool retval
= !wxWindowBase::SetFont( font
) ;
921 MacUpdateControlFont() ;
926 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
928 if ( !wxWindowBase::SetForegroundColour(col
) )
931 MacUpdateControlFont() ;
936 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
938 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
942 wxColour
newCol(GetBackgroundColour());
943 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
945 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
947 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
949 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
953 brush
.SetColour( newCol
) ;
955 MacSetBackgroundBrush( brush
) ;
957 MacUpdateControlFont() ;
962 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
964 m_macBackgroundBrush
= brush
;
965 m_peer
->SetBackground( brush
) ;
968 bool wxWindowMac::MacCanFocus() const
970 // there is currently no way to determine whether the window is running in full keyboard
971 // access mode, therefore we cannot rely on these features, yet the only other way would be
972 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
973 // in event handlers...
974 UInt32 features
= 0 ;
975 m_peer
->GetFeatures( & features
) ;
976 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
980 void wxWindowMac::SetFocus()
982 if ( AcceptsFocus() )
984 #if !TARGET_API_MAC_OSX
985 wxWindow
* former
= FindFocus() ;
987 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
988 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
989 // leave in case of an error
990 if ( err
== errCouldntSetFocus
)
993 #if !TARGET_API_MAC_OSX
994 // emulate carbon events when running under carbonlib where they are not natively available
997 EventRef evRef
= NULL
;
998 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1001 wxMacCarbonEvent
cEvent( evRef
) ;
1002 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1003 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1005 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1006 ReleaseEvent(evRef
) ;
1008 // send new focus event
1010 EventRef evRef
= NULL
;
1011 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1014 wxMacCarbonEvent
cEvent( evRef
) ;
1015 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1016 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1018 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1019 ReleaseEvent(evRef
) ;
1026 void wxWindowMac::DoCaptureMouse()
1028 wxTheApp
->s_captureWindow
= this ;
1031 wxWindow
* wxWindowBase::GetCapture()
1033 return wxTheApp
->s_captureWindow
;
1036 void wxWindowMac::DoReleaseMouse()
1038 wxTheApp
->s_captureWindow
= NULL
;
1041 #if wxUSE_DRAG_AND_DROP
1043 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1045 if ( m_dropTarget
!= 0 ) {
1046 delete m_dropTarget
;
1049 m_dropTarget
= pDropTarget
;
1050 if ( m_dropTarget
!= 0 )
1058 // Old style file-manager drag&drop
1059 void wxWindowMac::DragAcceptFiles(bool accept
)
1064 // Returns the size of the native control. In the case of the toplevel window
1065 // this is the content area root control
1067 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1068 int& w
, int& h
) const
1071 m_peer
->GetRect( &bounds
) ;
1076 w
= bounds
.right
- bounds
.left
;
1077 h
= bounds
.bottom
- bounds
.top
;
1080 // From a wx position / size calculate the appropriate size of the native control
1082 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1085 int& w
, int& h
, bool adjustOrigin
) const
1087 // the desired size, minus the border pixels gives the correct size of the control
1091 // todo the default calls may be used as soon as PostCreateControl Is moved here
1092 w
= size
.x
; // WidthDefault( size.x );
1093 h
= size
.y
; // HeightDefault( size.y ) ;
1094 #if !TARGET_API_MAC_OSX
1095 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1098 x
+= MacGetLeftBorderSize() ;
1099 y
+= MacGetTopBorderSize() ;
1100 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1101 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1104 AdjustForParentClientOrigin( x
, y
) ;
1108 // Get window size (not client size)
1109 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1111 // take the size of the control and add the borders that have to be drawn outside
1112 int x1
, y1
, w1
, h1
;
1114 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1116 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1117 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1123 // get the position of the bounds of this window in client coordinates of its parent
1124 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1126 int x1
, y1
, w1
,h1
;
1127 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1128 x1
-= MacGetLeftBorderSize() ;
1129 y1
-= MacGetTopBorderSize() ;
1131 #if !TARGET_API_MAC_OSX
1132 if ( !GetParent()->IsTopLevel() )
1135 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1140 if ( !IsTopLevel() )
1142 wxWindow
*parent
= GetParent();
1145 // we must first adjust it twice, as otherwise it gets lost by the clientareaorigin fix
1146 x1
+= 2 * parent
->MacGetLeftBorderSize() ;
1147 y1
+= 2 * parent
->MacGetTopBorderSize() ;
1148 wxPoint
pt(parent
->GetClientAreaOrigin());
1157 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1159 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1161 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1164 Point localwhere
= {0,0} ;
1166 if(x
) localwhere
.h
= * x
;
1167 if(y
) localwhere
.v
= * y
;
1169 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1170 if(x
) *x
= localwhere
.h
;
1171 if(y
) *y
= localwhere
.v
;
1174 MacRootWindowToWindow( x
, y
) ;
1176 wxPoint origin
= GetClientAreaOrigin() ;
1177 if(x
) *x
-= origin
.x
;
1178 if(y
) *y
-= origin
.y
;
1181 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1183 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1184 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1186 wxPoint origin
= GetClientAreaOrigin() ;
1187 if(x
) *x
+= origin
.x
;
1188 if(y
) *y
+= origin
.y
;
1190 MacWindowToRootWindow( x
, y
) ;
1193 Point localwhere
= { 0,0 };
1194 if(x
) localwhere
.h
= * x
;
1195 if(y
) localwhere
.v
= * y
;
1196 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1197 if(x
) *x
= localwhere
.h
;
1198 if(y
) *y
= localwhere
.v
;
1202 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1204 wxPoint origin
= GetClientAreaOrigin() ;
1205 if(x
) *x
+= origin
.x
;
1206 if(y
) *y
+= origin
.y
;
1208 MacWindowToRootWindow( x
, y
) ;
1211 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1213 MacRootWindowToWindow( x
, y
) ;
1215 wxPoint origin
= GetClientAreaOrigin() ;
1216 if(x
) *x
-= origin
.x
;
1217 if(y
) *y
-= origin
.y
;
1220 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1222 #if TARGET_API_MAC_OSX
1224 if ( x
) pt
.x
= *x
;
1225 if ( y
) pt
.y
= *y
;
1227 if ( !IsTopLevel() )
1229 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1232 pt
.x
-= MacGetLeftBorderSize() ;
1233 pt
.y
-= MacGetTopBorderSize() ;
1234 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1238 if ( x
) *x
= (int) pt
.x
;
1239 if ( y
) *y
= (int) pt
.y
;
1241 if ( !IsTopLevel() )
1244 m_peer
->GetRect( &bounds
) ;
1245 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1246 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1251 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1256 MacWindowToRootWindow( &x1
, &y1
) ;
1261 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1263 #if TARGET_API_MAC_OSX
1265 if ( x
) pt
.x
= *x
;
1266 if ( y
) pt
.y
= *y
;
1268 if ( !IsTopLevel() )
1270 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1271 pt
.x
+= MacGetLeftBorderSize() ;
1272 pt
.y
+= MacGetTopBorderSize() ;
1275 if ( x
) *x
= (int) pt
.x
;
1276 if ( y
) *y
= (int) pt
.y
;
1278 if ( !IsTopLevel() )
1281 m_peer
->GetRect( &bounds
) ;
1282 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1283 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1288 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1293 MacRootWindowToWindow( &x1
, &y1
) ;
1298 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1300 RgnHandle rgn
= NewRgn() ;
1302 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1304 GetRegionBounds( rgn
, &content
) ;
1309 m_peer
->GetRect( &content
) ;
1312 m_peer
->GetRect( &structure
) ;
1313 #if !TARGET_API_MAC_OSX
1314 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1316 left
= content
.left
- structure
.left
;
1317 top
= content
.top
- structure
.top
;
1318 right
= structure
.right
- content
.right
;
1319 bottom
= structure
.bottom
- content
.bottom
;
1322 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1324 wxSize sizeTotal
= size
;
1326 RgnHandle rgn
= NewRgn() ;
1330 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1332 GetRegionBounds( rgn
, &content
) ;
1337 m_peer
->GetRect( &content
) ;
1340 m_peer
->GetRect( &structure
) ;
1341 #if !TARGET_API_MAC_OSX
1342 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1345 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1346 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1348 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1349 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1355 // Get size *available for subwindows* i.e. excluding menu bar etc.
1356 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1360 RgnHandle rgn
= NewRgn() ;
1362 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1364 GetRegionBounds( rgn
, &content
) ;
1369 m_peer
->GetRect( &content
) ;
1371 #if !TARGET_API_MAC_OSX
1373 m_peer
->GetRect( &structure
) ;
1374 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1376 ww
= content
.right
- content
.left
;
1377 hh
= content
.bottom
- content
.top
;
1379 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1380 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1383 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1389 GetSize( &w , &h ) ;
1391 MacClientToRootWindow( &x1 , &y1 ) ;
1392 MacClientToRootWindow( &w , &h ) ;
1394 wxWindowMac *iter = (wxWindowMac*)this ;
1396 int totW = 10000 , totH = 10000;
1399 if ( iter->IsTopLevel() )
1401 iter->GetSize( &totW , &totH ) ;
1405 iter = iter->GetParent() ;
1408 if (m_hScrollBar && m_hScrollBar->IsShown() )
1410 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1416 if (m_vScrollBar && m_vScrollBar->IsShown() )
1418 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1426 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1428 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1430 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1432 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1439 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1441 if (m_cursor
== cursor
)
1444 if (wxNullCursor
== cursor
)
1446 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1451 if ( ! wxWindowBase::SetCursor( cursor
) )
1455 wxASSERT_MSG( m_cursor
.Ok(),
1456 wxT("cursor must be valid after call to the base version"));
1459 wxWindowMac
*mouseWin
= 0 ;
1461 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1463 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1465 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1466 // position, use it...
1470 ControlPartCode part
;
1471 ControlRef control
;
1472 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1474 mouseWin
= wxFindControlFromMacControl( control
) ;
1477 QDSwapPort( savePort
, NULL
) ;
1480 if ( mouseWin
== this && !wxIsBusy() )
1482 m_cursor
.MacInstall() ;
1489 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1491 menu
->SetInvokingWindow(this);
1494 if ( x
== -1 && y
== -1 )
1496 wxPoint mouse
= wxGetMousePosition();
1497 x
= mouse
.x
; y
= mouse
.y
;
1501 ClientToScreen( &x
, &y
) ;
1504 menu
->MacBeforeDisplay( true ) ;
1505 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1506 if ( HiWord(menuResult
) != 0 )
1509 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1510 wxMenuItem
* item
= NULL
;
1512 item
= menu
->FindItem(id
, &realmenu
) ;
1513 if (item
->IsCheckable())
1515 item
->Check( !item
->IsChecked() ) ;
1517 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1519 menu
->MacAfterDisplay( true ) ;
1521 menu
->SetInvokingWindow(NULL
);
1527 // ----------------------------------------------------------------------------
1529 // ----------------------------------------------------------------------------
1533 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1535 wxWindowBase::DoSetToolTip(tooltip
);
1538 m_tooltip
->SetWindow(this);
1541 #endif // wxUSE_TOOLTIPS
1543 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1545 // this is never called for a toplevel window, so we know we have a parent
1546 int former_x
, former_y
, former_w
, former_h
;
1548 // Get true coordinates of former position
1549 DoGetPosition( &former_x
, &former_y
) ;
1550 DoGetSize( &former_w
, &former_h
) ;
1552 wxWindow
*parent
= GetParent();
1555 wxPoint
pt(parent
->GetClientAreaOrigin());
1560 int actualWidth
= width
;
1561 int actualHeight
= height
;
1565 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1566 actualWidth
= m_minWidth
;
1567 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1568 actualHeight
= m_minHeight
;
1569 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1570 actualWidth
= m_maxWidth
;
1571 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1572 actualHeight
= m_maxHeight
;
1574 bool doMove
= false ;
1575 bool doResize
= false ;
1577 if ( actualX
!= former_x
|| actualY
!= former_y
)
1581 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1586 if ( doMove
|| doResize
)
1588 // we don't adjust twice for the origin
1589 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1590 #if TARGET_API_MAC_OSX
1591 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1592 if ( ! GetParent()->IsTopLevel() )
1594 r
.left
-= GetParent()->MacGetLeftBorderSize() ;
1595 r
.top
-= GetParent()->MacGetTopBorderSize() ;
1596 r
.right
-= GetParent()->MacGetLeftBorderSize() ;
1597 r
.bottom
-= GetParent()->MacGetTopBorderSize() ;
1600 bool vis
= m_peer
->IsVisible();
1602 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1604 m_peer
->SetVisibility( false , true ) ;
1605 m_peer
->SetRect( &r
) ;
1607 m_peer
->SetVisibility( true , true ) ;
1609 MacRepositionScrollBars() ;
1612 wxPoint
point(actualX
,actualY
);
1613 wxMoveEvent
event(point
, m_windowId
);
1614 event
.SetEventObject(this);
1615 GetEventHandler()->ProcessEvent(event
) ;
1619 MacRepositionScrollBars() ;
1620 wxSize
size(actualWidth
, actualHeight
);
1621 wxSizeEvent
event(size
, m_windowId
);
1622 event
.SetEventObject(this);
1623 GetEventHandler()->ProcessEvent(event
);
1629 wxSize
wxWindowMac::DoGetBestSize() const
1631 if ( m_macIsUserPane
|| IsTopLevel() )
1632 return wxWindowBase::DoGetBestSize() ;
1634 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1635 int bestWidth
, bestHeight
;
1636 m_peer
->GetBestRect( &bestsize
) ;
1638 if ( EmptyRect( &bestsize
) )
1640 bestsize
.left
= bestsize
.top
= 0 ;
1641 bestsize
.right
= 16 ;
1642 bestsize
.bottom
= 16 ;
1643 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1645 bestsize
.bottom
= 16 ;
1647 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1649 bestsize
.bottom
= 24 ;
1653 // return wxWindowBase::DoGetBestSize() ;
1657 bestWidth
= bestsize
.right
- bestsize
.left
;
1658 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1659 if ( bestHeight
< 10 )
1662 return wxSize(bestWidth
, bestHeight
);
1666 // set the size of the window: if the dimensions are positive, just use them,
1667 // but if any of them is equal to -1, it means that we must find the value for
1668 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1669 // which case -1 is a valid value for x and y)
1671 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1672 // the width/height to best suit our contents, otherwise we reuse the current
1674 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1676 // get the current size and position...
1677 int currentX
, currentY
;
1678 GetPosition(¤tX
, ¤tY
);
1680 int currentW
,currentH
;
1681 GetSize(¤tW
, ¤tH
);
1683 // ... and don't do anything (avoiding flicker) if it's already ok
1684 if ( x
== currentX
&& y
== currentY
&&
1685 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1688 MacRepositionScrollBars() ; // we might have a real position shift
1692 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1694 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1697 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1699 wxSize
size(-1, -1);
1702 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1704 size
= DoGetBestSize();
1709 // just take the current one
1716 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1720 size
= DoGetBestSize();
1722 //else: already called DoGetBestSize() above
1728 // just take the current one
1733 DoMoveWindow(x
, y
, width
, height
);
1737 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1739 RgnHandle rgn
= NewRgn() ;
1741 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1742 GetRegionBounds( rgn
, &content
) ;
1744 #if !TARGET_API_MAC_OSX
1745 // if the content rgn is empty / not supported
1746 // don't attempt to correct the coordinates to wxWindow relative ones
1747 if (!::EmptyRect( &content
) )
1750 m_peer
->GetRect( &structure
) ;
1751 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1755 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1758 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1760 if ( clientheight
!= -1 || clientheight
!= -1 )
1762 int currentclientwidth
, currentclientheight
;
1763 int currentwidth
, currentheight
;
1765 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1766 GetSize( ¤twidth
, ¤theight
) ;
1768 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1769 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1773 void wxWindowMac::SetTitle(const wxString
& title
)
1775 m_label
= wxStripMenuCodes(title
) ;
1777 if ( m_peer
&& m_peer
->Ok() )
1779 m_peer
->SetTitle( m_label
) ;
1784 wxString
wxWindowMac::GetTitle() const
1789 bool wxWindowMac::Show(bool show
)
1791 if ( !wxWindowBase::Show(show
) )
1794 // TODO use visibilityChanged Carbon Event for OSX
1795 bool former
= MacIsReallyShown() ;
1797 m_peer
->SetVisibility( show
, true ) ;
1798 if ( former
!= MacIsReallyShown() )
1799 MacPropagateVisibilityChanged() ;
1803 bool wxWindowMac::Enable(bool enable
)
1805 wxASSERT( m_peer
->Ok() ) ;
1806 if ( !wxWindowBase::Enable(enable
) )
1809 bool former
= MacIsReallyEnabled() ;
1810 m_peer
->Enable( enable
) ;
1812 if ( former
!= MacIsReallyEnabled() )
1813 MacPropagateEnabledStateChanged() ;
1818 // status change propagations (will be not necessary for OSX later )
1821 void wxWindowMac::MacPropagateVisibilityChanged()
1823 #if !TARGET_API_MAC_OSX
1824 MacVisibilityChanged() ;
1826 wxWindowListNode
*node
= GetChildren().GetFirst();
1829 wxWindowMac
*child
= node
->GetData();
1830 if ( child
->IsShown() )
1831 child
->MacPropagateVisibilityChanged( ) ;
1832 node
= node
->GetNext();
1837 void wxWindowMac::MacPropagateEnabledStateChanged( )
1839 #if !TARGET_API_MAC_OSX
1840 MacEnabledStateChanged() ;
1842 wxWindowListNode
*node
= GetChildren().GetFirst();
1845 wxWindowMac
*child
= node
->GetData();
1846 if ( child
->IsEnabled() )
1847 child
->MacPropagateEnabledStateChanged() ;
1848 node
= node
->GetNext();
1853 void wxWindowMac::MacPropagateHiliteChanged( )
1855 #if !TARGET_API_MAC_OSX
1856 MacHiliteChanged() ;
1858 wxWindowListNode
*node
= GetChildren().GetFirst();
1861 wxWindowMac
*child
= node
->GetData();
1862 // if ( child->IsEnabled() )
1863 child
->MacPropagateHiliteChanged() ;
1864 node
= node
->GetNext();
1870 // status change notifications
1873 void wxWindowMac::MacVisibilityChanged()
1877 void wxWindowMac::MacHiliteChanged()
1881 void wxWindowMac::MacEnabledStateChanged()
1886 // status queries on the inherited window's state
1889 bool wxWindowMac::MacIsReallyShown()
1891 // only under OSX the visibility of the TLW is taken into account
1892 #if TARGET_API_MAC_OSX
1893 if ( m_peer
&& m_peer
->Ok() )
1894 return m_peer
->IsVisible();
1896 wxWindow
* win
= this ;
1897 while( win
->IsShown() )
1899 if ( win
->IsTopLevel() )
1902 win
= win
->GetParent() ;
1910 bool wxWindowMac::MacIsReallyEnabled()
1912 return m_peer
->IsEnabled() ;
1915 bool wxWindowMac::MacIsReallyHilited()
1917 return m_peer
->IsActive();
1920 void wxWindowMac::MacFlashInvalidAreas()
1922 #if TARGET_API_MAC_OSX
1923 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1931 int wxWindowMac::GetCharHeight() const
1933 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1934 return dc
.GetCharHeight() ;
1937 int wxWindowMac::GetCharWidth() const
1939 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1940 return dc
.GetCharWidth() ;
1943 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1944 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1946 const wxFont
*fontToUse
= theFont
;
1948 fontToUse
= &m_font
;
1950 wxClientDC
dc( (wxWindowMac
*) this ) ;
1952 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1953 if ( externalLeading
)
1954 *externalLeading
= le
;
1964 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1965 * we always intersect with the entire window, not only with the client area
1968 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1970 if ( m_peer
== NULL
)
1973 #if TARGET_API_MAC_OSX
1975 m_peer
->SetNeedsDisplay( true ) ;
1978 RgnHandle update
= NewRgn() ;
1979 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1980 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1981 wxPoint origin
= GetClientAreaOrigin() ;
1982 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1983 // right now this is wx' window coordinates, as our native peer does not have borders, this is
1985 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1986 m_peer
->SetNeedsDisplay( true , update
) ;
1990 RgnHandle updateRgn = NewRgn() ;
1993 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1997 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1998 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2000 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2001 DisposeRgn(updateRgn) ;
2003 if ( m_peer
->IsVisible())
2005 m_peer
->SetVisibility( false , false ) ;
2006 m_peer
->SetVisibility( true , true ) ;
2009 if ( MacGetTopLevelWindow() == NULL )
2012 if ( !m_peer->IsVisible())
2015 wxPoint client = GetClientAreaOrigin();
2018 int x2 = m_width - client.x;
2019 int y2 = m_height - client.y;
2021 if (IsKindOf( CLASSINFO(wxButton)))
2023 // buttons have an "aura"
2030 Rect clientrect = { y1, x1, y2, x2 };
2034 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2035 SectRect( &clientrect , &r , &clientrect ) ;
2038 if ( !EmptyRect( &clientrect ) )
2040 int top = 0 , left = 0 ;
2042 MacClientToRootWindow( &left , &top ) ;
2043 OffsetRect( &clientrect , left , top ) ;
2045 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2051 void wxWindowMac::Freeze()
2053 #if TARGET_API_MAC_OSX
2054 if ( !m_frozenness
++ )
2056 m_peer
->SetDrawingEnabled( false ) ;
2062 void wxWindowMac::Thaw()
2064 #if TARGET_API_MAC_OSX
2065 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2067 if ( !--m_frozenness
)
2069 m_peer
->SetDrawingEnabled( true ) ;
2070 m_peer
->InvalidateWithChildren() ;
2075 void wxWindowMac::MacRedrawControl()
2078 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2080 #if TARGET_API_MAC_CARBON
2083 wxClientDC dc(this) ;
2084 wxMacPortSetter helper(&dc) ;
2085 wxMacWindowClipper clipper(this) ;
2086 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2087 UMADrawControl( *m_peer ) ;
2094 void wxWindowMac::OnPaint(wxPaintEvent& event)
2096 // why don't we skip that here ?
2100 wxWindowMac
*wxGetActiveWindow()
2102 // actually this is a windows-only concept
2106 // Coordinates relative to the window
2107 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2109 // We really don't move the mouse programmatically under Mac.
2112 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2114 #if TARGET_API_MAC_OSX
2115 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2121 event
.GetDC()->Clear() ;
2124 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2126 wxWindowDC
dc(this) ;
2127 wxMacPortSetter
helper(&dc
) ;
2129 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2132 int wxWindowMac::GetScrollPos(int orient
) const
2134 if ( orient
== wxHORIZONTAL
)
2137 return m_hScrollBar
->GetThumbPosition() ;
2142 return m_vScrollBar
->GetThumbPosition() ;
2147 // This now returns the whole range, not just the number
2148 // of positions that we can scroll.
2149 int wxWindowMac::GetScrollRange(int orient
) const
2151 if ( orient
== wxHORIZONTAL
)
2154 return m_hScrollBar
->GetRange() ;
2159 return m_vScrollBar
->GetRange() ;
2164 int wxWindowMac::GetScrollThumb(int orient
) const
2166 if ( orient
== wxHORIZONTAL
)
2169 return m_hScrollBar
->GetThumbSize() ;
2174 return m_vScrollBar
->GetThumbSize() ;
2179 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2181 if ( orient
== wxHORIZONTAL
)
2184 m_hScrollBar
->SetThumbPosition( pos
) ;
2189 m_vScrollBar
->SetThumbPosition( pos
) ;
2193 void wxWindowMac::MacPaintBorders( int left
, int top
)
2199 wxGetOsVersion( &major
, &minor
);
2201 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2202 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2203 // OS X has lighter border edges than classic:
2206 darkShadow
.red
= 0x8E8E;
2207 darkShadow
.green
= 0x8E8E;
2208 darkShadow
.blue
= 0x8E8E;
2209 lightShadow
.red
= 0xBDBD;
2210 lightShadow
.green
= 0xBDBD;
2211 lightShadow
.blue
= 0xBDBD;
2217 GetSize( &w
, &h
) ;
2218 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2219 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2221 #if wxMAC_USE_THEME_BORDER
2223 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2224 InsetRect( &rect
, border
, border
);
2225 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2227 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2228 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2230 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2231 RGBForeColor( &face
);
2232 MoveTo( left
+ 0 , top
+ h
- 2 );
2233 LineTo( left
+ 0 , top
+ 0 );
2234 LineTo( left
+ w
- 2 , top
+ 0 );
2236 MoveTo( left
+ 2 , top
+ h
- 3 );
2237 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2238 LineTo( left
+ w
- 3 , top
+ 2 );
2240 RGBForeColor( sunken
? &face
: &darkShadow
);
2241 MoveTo( left
+ 0 , top
+ h
- 1 );
2242 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2243 LineTo( left
+ w
- 1 , top
+ 0 );
2245 RGBForeColor( sunken
? &lightShadow
: &white
);
2246 MoveTo( left
+ 1 , top
+ h
- 3 );
2247 LineTo( left
+ 1, top
+ 1 );
2248 LineTo( left
+ w
- 3 , top
+ 1 );
2250 RGBForeColor( sunken
? &white
: &lightShadow
);
2251 MoveTo( left
+ 1 , top
+ h
- 2 );
2252 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2253 LineTo( left
+ w
- 2 , top
+ 1 );
2255 RGBForeColor( sunken
? &darkShadow
: &face
);
2256 MoveTo( left
+ 2 , top
+ h
- 4 );
2257 LineTo( left
+ 2 , top
+ 2 );
2258 LineTo( left
+ w
- 4 , top
+ 2 );
2261 else if (HasFlag(wxSIMPLE_BORDER
))
2263 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2264 RGBForeColor( &darkShadow
) ;
2265 FrameRect( &rect
) ;
2269 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2271 if ( child
== m_hScrollBar
)
2272 m_hScrollBar
= NULL
;
2273 if ( child
== m_vScrollBar
)
2274 m_vScrollBar
= NULL
;
2276 wxWindowBase::RemoveChild( child
) ;
2279 // New function that will replace some of the above.
2280 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2281 int range
, bool refresh
)
2283 if ( orient
== wxHORIZONTAL
)
2287 if ( range
== 0 || thumbVisible
>= range
)
2289 if ( m_hScrollBar
->IsShown() )
2290 m_hScrollBar
->Show(false) ;
2294 if ( !m_hScrollBar
->IsShown() )
2295 m_hScrollBar
->Show(true) ;
2296 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2304 if ( range
== 0 || thumbVisible
>= range
)
2306 if ( m_vScrollBar
->IsShown() )
2307 m_vScrollBar
->Show(false) ;
2311 if ( !m_vScrollBar
->IsShown() )
2312 m_vScrollBar
->Show(true) ;
2313 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2317 MacRepositionScrollBars() ;
2320 // Does a physical scroll
2321 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2323 if( dx
== 0 && dy
==0 )
2329 int width
, height
;
2330 GetClientSize( &width
, &height
) ;
2331 #if TARGET_API_MAC_OSX
2332 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2333 // area is scrolled, this does not occur if width and height are 2 pixels less,
2334 // TODO write optimal workaround
2335 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2338 scrollrect
.Intersect( *rect
) ;
2340 if ( m_peer
->GetNeedsDisplay() )
2342 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2343 // either immediate redraw or full invalidate
2345 // is the better overall solution, as it does not slow down scrolling
2346 m_peer
->SetNeedsDisplay( true ) ;
2348 // this would be the preferred version for fast drawing controls
2349 if( UMAGetSystemVersion() < 0x1030 )
2352 HIViewRender(m_peer
->GetControlRef()) ;
2355 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2356 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2357 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2364 RgnHandle updateRgn
= NewRgn() ;
2367 wxClientDC
dc(this) ;
2368 wxMacPortSetter
helper(&dc
) ;
2370 m_peer
->GetRect( &scrollrect
) ;
2371 scrollrect
.top
+= MacGetTopBorderSize() ;
2372 scrollrect
.left
+= MacGetLeftBorderSize() ;
2373 scrollrect
.bottom
= scrollrect
.top
+ height
;
2374 scrollrect
.right
= scrollrect
.left
+ width
;
2378 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2379 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2380 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2382 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2384 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2388 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2390 wxWindowMac
*child
= node
->GetData();
2391 if (child
== m_vScrollBar
) continue;
2392 if (child
== m_hScrollBar
) continue;
2393 if (child
->IsTopLevel()) continue;
2396 child
->GetPosition( &x
, &y
);
2398 child
->GetSize( &w
, &h
);
2402 if (rect
->Intersects(rc
))
2403 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2407 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2412 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2414 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2416 wxScrollWinEvent wevent
;
2417 wevent
.SetPosition(event
.GetPosition());
2418 wevent
.SetOrientation(event
.GetOrientation());
2419 wevent
.m_eventObject
= this;
2421 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2422 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2423 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2424 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2425 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2426 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2427 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2428 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2429 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2430 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2431 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2432 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2433 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2434 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2435 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2436 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2438 GetEventHandler()->ProcessEvent(wevent
);
2442 // Get the window with the focus
2443 wxWindowMac
*wxWindowBase::FindFocus()
2445 ControlRef control
;
2446 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2447 return wxFindControlFromMacControl( control
) ;
2450 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2452 // panel wants to track the window which was the last to have focus in it,
2453 // so we want to set ourselves as the window which last had focus
2455 // notice that it's also important to do it upwards the tree becaus
2456 // otherwise when the top level panel gets focus, it won't set it back to
2457 // us, but to some other sibling
2459 // CS:don't know if this is still needed:
2460 //wxChildFocusEvent eventFocus(this);
2461 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2463 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2465 wxMacWindowStateSaver
sv( this ) ;
2470 MacWindowToRootWindow( &x
, &y
) ;
2471 GetSize( &w
, &h
) ;
2472 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2474 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2475 DrawThemeFocusRect( &rect
, true ) ;
2477 DrawThemeFocusRect( &rect
, false ) ;
2483 void wxWindowMac::OnInternalIdle()
2485 // This calls the UI-update mechanism (querying windows for
2486 // menu/toolbar/control state information)
2487 if (wxUpdateUIEvent::CanUpdate(this))
2488 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2491 // Raise the window to the top of the Z order
2492 void wxWindowMac::Raise()
2494 m_peer
->SetZOrder( true , NULL
) ;
2497 // Lower the window to the bottom of the Z order
2498 void wxWindowMac::Lower()
2500 m_peer
->SetZOrder( false , NULL
) ;
2504 // static wxWindow *gs_lastWhich = NULL;
2506 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2508 // first trigger a set cursor event
2510 wxPoint clientorigin
= GetClientAreaOrigin() ;
2511 wxSize clientsize
= GetClientSize() ;
2513 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2515 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2517 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2518 if ( processedEvtSetCursor
&& event
.HasCursor() )
2520 cursor
= event
.GetCursor() ;
2525 // the test for processedEvtSetCursor is here to prevent using m_cursor
2526 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2527 // it - this is a way to say that our cursor shouldn't be used for this
2529 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2539 cursor
= *wxSTANDARD_CURSOR
;
2543 cursor
.MacInstall() ;
2545 return cursor
.Ok() ;
2548 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2552 return m_tooltip
->GetTip() ;
2554 return wxEmptyString
;
2557 void wxWindowMac::Update()
2559 #if TARGET_API_MAC_OSX
2560 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2561 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2562 // for composited windows this also triggers a redraw of all
2563 // invalid views in the window
2564 if( UMAGetSystemVersion() >= 0x1030 )
2565 HIWindowFlush(window
) ;
2569 // the only way to trigger the redrawing on earlier systems is to call
2572 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2573 UInt32 currentEventClass
= 0 ;
2574 UInt32 currentEventKind
= 0 ;
2575 if ( currentEvent
!= NULL
)
2577 currentEventClass
= ::GetEventClass( currentEvent
) ;
2578 currentEventKind
= ::GetEventKind( currentEvent
) ;
2580 if ( currentEventClass
!= kEventClassMenu
)
2582 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2585 OSStatus status
= noErr
;
2586 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2589 m_peer
->SetNeedsDisplay( true ) ;
2592 ::Draw1Control( m_peer
->GetControlRef() ) ;
2596 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2598 wxTopLevelWindowMac
* win
= NULL
;
2599 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2602 win
= wxFindWinFromMacWindow( window
) ;
2606 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2610 RgnHandle visRgn
= NewRgn() ;
2611 RgnHandle tempRgn
= NewRgn() ;
2612 if ( m_peer
->IsVisible())
2614 m_peer
->GetRect( &r
) ;
2615 r
.left
-= MacGetLeftBorderSize() ;
2616 r
.top
-= MacGetTopBorderSize() ;
2617 r
.bottom
+= MacGetBottomBorderSize() ;
2618 r
.right
+= MacGetRightBorderSize() ;
2620 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2622 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2623 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2632 if ( includeOuterStructures
)
2633 InsetRect( &r
, -3 , -3 ) ;
2634 RectRgn( visRgn
, &r
) ;
2636 if ( !IsTopLevel() )
2638 wxWindow
* child
= this ;
2639 wxWindow
* parent
= child
->GetParent() ;
2644 // we have to find a better clipping algorithm here, in order not to clip things
2645 // positioned like status and toolbar
2646 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2648 size
= parent
->GetSize() ;
2653 size
= parent
->GetClientSize() ;
2654 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2658 parent
->MacWindowToRootWindow( &x
, &y
) ;
2659 MacRootWindowToWindow( &x
, &y
) ;
2661 SetRectRgn( tempRgn
,
2662 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2663 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2664 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2666 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2667 if ( parent
->IsTopLevel() )
2670 parent
= child
->GetParent() ;
2675 wxRegion vis
= visRgn
;
2676 DisposeRgn( visRgn
) ;
2677 DisposeRgn( tempRgn
) ;
2682 This function must not change the updatergn !
2684 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2686 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2687 bool handled
= false ;
2689 GetRegionBounds( updatergn
, &updatebounds
) ;
2691 if ( !EmptyRgn(updatergn
) )
2693 RgnHandle newupdate
= NewRgn() ;
2694 wxSize point
= GetClientSize() ;
2695 wxPoint origin
= GetClientAreaOrigin() ;
2696 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2697 SectRgn( newupdate
, updatergn
, newupdate
) ;
2700 wxWindowDC
dc(this);
2701 if (!EmptyRgn(newupdate
))
2702 dc
.SetClippingRegion(wxRegion(newupdate
));
2704 wxEraseEvent
eevent( GetId(), &dc
);
2705 eevent
.SetEventObject( this );
2706 GetEventHandler()->ProcessEvent( eevent
);
2709 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2710 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2711 m_updateRegion
= newupdate
;
2712 DisposeRgn( newupdate
) ;
2714 if ( !m_updateRegion
.Empty() )
2716 // paint the window itself
2718 event
.m_timeStamp
= time
;
2719 event
.SetEventObject(this);
2720 handled
= GetEventHandler()->ProcessEvent(event
);
2722 // paint custom borders
2723 wxNcPaintEvent
eventNc( GetId() );
2724 eventNc
.SetEventObject( this );
2725 GetEventHandler()->ProcessEvent( eventNc
);
2731 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2733 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2734 // updatergn is always already clipped to our boundaries
2735 // if we are in compositing mode then it is in relative to the upper left of the control
2736 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2737 // of the toplevel window
2738 // it is in window coordinates, not in client coordinates
2740 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2741 RgnHandle ownUpdateRgn
= NewRgn() ;
2742 CopyRgn( updatergn
, ownUpdateRgn
) ;
2744 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2747 m_peer
->GetRectInWindowCoords( &bounds
);
2748 RgnHandle controlRgn
= NewRgn();
2749 RectRgn( controlRgn
, &bounds
);
2750 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2751 // the window update region
2752 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2753 DisposeRgn( controlRgn
);
2755 //KO: convert ownUpdateRgn to local coordinates
2756 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2759 MacDoRedraw( ownUpdateRgn
, time
) ;
2760 DisposeRgn( ownUpdateRgn
) ;
2764 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2766 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2770 if ( iter
->IsTopLevel() )
2771 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2773 iter
= iter
->GetParent() ;
2775 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2779 void wxWindowMac::MacCreateScrollBars( long style
)
2781 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2783 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2785 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2786 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2787 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2788 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2790 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2791 variant
= wxWINDOW_VARIANT_SMALL
;
2794 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2796 GetClientSize( &width
, &height
) ;
2798 wxPoint
vPoint(width
-scrlsize
, 0) ;
2799 wxSize
vSize(scrlsize
, height
- adjust
) ;
2800 wxPoint
hPoint(0 , height
-scrlsize
) ;
2801 wxSize
hSize( width
- adjust
, scrlsize
) ;
2804 if ( style
& wxVSCROLL
)
2806 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2807 vSize
, wxVERTICAL
);
2810 if ( style
& wxHSCROLL
)
2812 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2813 hSize
, wxHORIZONTAL
);
2818 // because the create does not take into account the client area origin
2819 MacRepositionScrollBars() ; // we might have a real position shift
2822 void wxWindowMac::MacRepositionScrollBars()
2824 if ( !m_hScrollBar
&& !m_vScrollBar
)
2827 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2828 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2829 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2831 // get real client area
2835 GetSize( &width
, &height
) ;
2837 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2838 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2840 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2841 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2842 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2843 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2849 GetSize( &w , &h ) ;
2851 MacClientToRootWindow( &x , &y ) ;
2852 MacClientToRootWindow( &w , &h ) ;
2854 wxWindowMac *iter = (wxWindowMac*)this ;
2856 int totW = 10000 , totH = 10000;
2859 if ( iter->IsTopLevel() )
2861 iter->GetSize( &totW , &totH ) ;
2865 iter = iter->GetParent() ;
2893 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2897 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2901 bool wxWindowMac::AcceptsFocus() const
2903 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2906 void wxWindowMac::MacSuperChangedPosition()
2908 // only window-absolute structures have to be moved i.e. controls
2910 wxWindowListNode
*node
= GetChildren().GetFirst();
2913 wxWindowMac
*child
= node
->GetData();
2914 child
->MacSuperChangedPosition() ;
2915 node
= node
->GetNext();
2919 void wxWindowMac::MacTopLevelWindowChangedPosition()
2921 // only screen-absolute structures have to be moved i.e. glcanvas
2923 wxWindowListNode
*node
= GetChildren().GetFirst();
2926 wxWindowMac
*child
= node
->GetData();
2927 child
->MacTopLevelWindowChangedPosition() ;
2928 node
= node
->GetNext();
2932 long wxWindowMac::MacGetLeftBorderSize( ) const
2937 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2942 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2947 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2954 long wxWindowMac::MacGetRightBorderSize( ) const
2956 // they are all symmetric in mac themes
2957 return MacGetLeftBorderSize() ;
2960 long wxWindowMac::MacGetTopBorderSize( ) const
2962 // they are all symmetric in mac themes
2963 return MacGetLeftBorderSize() ;
2966 long wxWindowMac::MacGetBottomBorderSize( ) const
2968 // they are all symmetric in mac themes
2969 return MacGetLeftBorderSize() ;
2972 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2974 return style
& ~wxBORDER_MASK
;
2977 // Find the wxWindowMac at the current mouse position, returning the mouse
2979 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2981 pt
= wxGetMousePosition();
2982 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2986 // Get the current mouse position.
2987 wxPoint
wxGetMousePosition()
2990 wxGetMousePosition(& x
, & y
);
2991 return wxPoint(x
, y
);
2994 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2996 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2998 // copied from wxGTK : CS
2999 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3002 // (a) it's a command event and so is propagated to the parent
3003 // (b) under MSW it can be generated from kbd too
3004 // (c) it uses screen coords (because of (a))
3005 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3007 this->ClientToScreen(event
.GetPosition()));
3008 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3017 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3021 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3025 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3026 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3030 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3032 return eventNotHandledErr
;