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 to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1146 x1
+= parent
->MacGetLeftBorderSize() ;
1147 y1
+= parent
->MacGetTopBorderSize() ;
1148 // and now to client coordinates
1149 wxPoint
pt(parent
->GetClientAreaOrigin());
1158 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1160 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1162 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1165 Point localwhere
= {0,0} ;
1167 if(x
) localwhere
.h
= * x
;
1168 if(y
) localwhere
.v
= * y
;
1170 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1171 if(x
) *x
= localwhere
.h
;
1172 if(y
) *y
= localwhere
.v
;
1175 MacRootWindowToWindow( x
, y
) ;
1177 wxPoint origin
= GetClientAreaOrigin() ;
1178 if(x
) *x
-= origin
.x
;
1179 if(y
) *y
-= origin
.y
;
1182 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1184 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1185 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1187 wxPoint origin
= GetClientAreaOrigin() ;
1188 if(x
) *x
+= origin
.x
;
1189 if(y
) *y
+= origin
.y
;
1191 MacWindowToRootWindow( x
, y
) ;
1194 Point localwhere
= { 0,0 };
1195 if(x
) localwhere
.h
= * x
;
1196 if(y
) localwhere
.v
= * y
;
1197 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1198 if(x
) *x
= localwhere
.h
;
1199 if(y
) *y
= localwhere
.v
;
1203 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1205 wxPoint origin
= GetClientAreaOrigin() ;
1206 if(x
) *x
+= origin
.x
;
1207 if(y
) *y
+= origin
.y
;
1209 MacWindowToRootWindow( x
, y
) ;
1212 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1214 MacRootWindowToWindow( x
, y
) ;
1216 wxPoint origin
= GetClientAreaOrigin() ;
1217 if(x
) *x
-= origin
.x
;
1218 if(y
) *y
-= origin
.y
;
1221 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1223 #if TARGET_API_MAC_OSX
1225 if ( x
) pt
.x
= *x
;
1226 if ( y
) pt
.y
= *y
;
1228 if ( !IsTopLevel() )
1230 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1233 pt
.x
-= MacGetLeftBorderSize() ;
1234 pt
.y
-= MacGetTopBorderSize() ;
1235 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1239 if ( x
) *x
= (int) pt
.x
;
1240 if ( y
) *y
= (int) pt
.y
;
1242 if ( !IsTopLevel() )
1245 m_peer
->GetRect( &bounds
) ;
1246 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1247 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1252 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1257 MacWindowToRootWindow( &x1
, &y1
) ;
1262 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1264 #if TARGET_API_MAC_OSX
1266 if ( x
) pt
.x
= *x
;
1267 if ( y
) pt
.y
= *y
;
1269 if ( !IsTopLevel() )
1271 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1272 pt
.x
+= MacGetLeftBorderSize() ;
1273 pt
.y
+= MacGetTopBorderSize() ;
1276 if ( x
) *x
= (int) pt
.x
;
1277 if ( y
) *y
= (int) pt
.y
;
1279 if ( !IsTopLevel() )
1282 m_peer
->GetRect( &bounds
) ;
1283 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1284 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1289 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1294 MacRootWindowToWindow( &x1
, &y1
) ;
1299 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1301 RgnHandle rgn
= NewRgn() ;
1303 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1305 GetRegionBounds( rgn
, &content
) ;
1310 m_peer
->GetRect( &content
) ;
1313 m_peer
->GetRect( &structure
) ;
1314 #if !TARGET_API_MAC_OSX
1315 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1317 left
= content
.left
- structure
.left
;
1318 top
= content
.top
- structure
.top
;
1319 right
= structure
.right
- content
.right
;
1320 bottom
= structure
.bottom
- content
.bottom
;
1323 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1325 wxSize sizeTotal
= size
;
1327 RgnHandle rgn
= NewRgn() ;
1331 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1333 GetRegionBounds( rgn
, &content
) ;
1338 m_peer
->GetRect( &content
) ;
1341 m_peer
->GetRect( &structure
) ;
1342 #if !TARGET_API_MAC_OSX
1343 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1346 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1347 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1349 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1350 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1356 // Get size *available for subwindows* i.e. excluding menu bar etc.
1357 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1361 RgnHandle rgn
= NewRgn() ;
1363 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1365 GetRegionBounds( rgn
, &content
) ;
1370 m_peer
->GetRect( &content
) ;
1372 #if !TARGET_API_MAC_OSX
1374 m_peer
->GetRect( &structure
) ;
1375 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1377 ww
= content
.right
- content
.left
;
1378 hh
= content
.bottom
- content
.top
;
1380 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1381 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1384 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1390 GetSize( &w , &h ) ;
1392 MacClientToRootWindow( &x1 , &y1 ) ;
1393 MacClientToRootWindow( &w , &h ) ;
1395 wxWindowMac *iter = (wxWindowMac*)this ;
1397 int totW = 10000 , totH = 10000;
1400 if ( iter->IsTopLevel() )
1402 iter->GetSize( &totW , &totH ) ;
1406 iter = iter->GetParent() ;
1409 if (m_hScrollBar && m_hScrollBar->IsShown() )
1411 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1417 if (m_vScrollBar && m_vScrollBar->IsShown() )
1419 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1427 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1429 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1431 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1433 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1440 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1442 if (m_cursor
== cursor
)
1445 if (wxNullCursor
== cursor
)
1447 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1452 if ( ! wxWindowBase::SetCursor( cursor
) )
1456 wxASSERT_MSG( m_cursor
.Ok(),
1457 wxT("cursor must be valid after call to the base version"));
1460 wxWindowMac
*mouseWin
= 0 ;
1462 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1464 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1466 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1467 // position, use it...
1471 ControlPartCode part
;
1472 ControlRef control
;
1473 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1475 mouseWin
= wxFindControlFromMacControl( control
) ;
1478 QDSwapPort( savePort
, NULL
) ;
1481 if ( mouseWin
== this && !wxIsBusy() )
1483 m_cursor
.MacInstall() ;
1490 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1492 menu
->SetInvokingWindow(this);
1495 if ( x
== -1 && y
== -1 )
1497 wxPoint mouse
= wxGetMousePosition();
1498 x
= mouse
.x
; y
= mouse
.y
;
1502 ClientToScreen( &x
, &y
) ;
1505 menu
->MacBeforeDisplay( true ) ;
1506 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1507 if ( HiWord(menuResult
) != 0 )
1510 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1511 wxMenuItem
* item
= NULL
;
1513 item
= menu
->FindItem(id
, &realmenu
) ;
1514 if (item
->IsCheckable())
1516 item
->Check( !item
->IsChecked() ) ;
1518 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1520 menu
->MacAfterDisplay( true ) ;
1522 menu
->SetInvokingWindow(NULL
);
1528 // ----------------------------------------------------------------------------
1530 // ----------------------------------------------------------------------------
1534 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1536 wxWindowBase::DoSetToolTip(tooltip
);
1539 m_tooltip
->SetWindow(this);
1542 #endif // wxUSE_TOOLTIPS
1544 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1546 // this is never called for a toplevel window, so we know we have a parent
1547 int former_x
, former_y
, former_w
, former_h
;
1549 // Get true coordinates of former position
1550 DoGetPosition( &former_x
, &former_y
) ;
1551 DoGetSize( &former_w
, &former_h
) ;
1553 wxWindow
*parent
= GetParent();
1556 wxPoint
pt(parent
->GetClientAreaOrigin());
1561 int actualWidth
= width
;
1562 int actualHeight
= height
;
1566 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1567 actualWidth
= m_minWidth
;
1568 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1569 actualHeight
= m_minHeight
;
1570 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1571 actualWidth
= m_maxWidth
;
1572 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1573 actualHeight
= m_maxHeight
;
1575 bool doMove
= false ;
1576 bool doResize
= false ;
1578 if ( actualX
!= former_x
|| actualY
!= former_y
)
1582 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1587 if ( doMove
|| doResize
)
1589 // we don't adjust twice for the origin
1590 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1591 #if TARGET_API_MAC_OSX
1592 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1593 if ( ! GetParent()->IsTopLevel() )
1595 r
.left
-= GetParent()->MacGetLeftBorderSize() ;
1596 r
.top
-= GetParent()->MacGetTopBorderSize() ;
1597 r
.right
-= GetParent()->MacGetLeftBorderSize() ;
1598 r
.bottom
-= GetParent()->MacGetTopBorderSize() ;
1601 bool vis
= m_peer
->IsVisible();
1603 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1605 m_peer
->SetVisibility( false , true ) ;
1606 m_peer
->SetRect( &r
) ;
1608 m_peer
->SetVisibility( true , true ) ;
1610 MacRepositionScrollBars() ;
1613 wxPoint
point(actualX
,actualY
);
1614 wxMoveEvent
event(point
, m_windowId
);
1615 event
.SetEventObject(this);
1616 GetEventHandler()->ProcessEvent(event
) ;
1620 MacRepositionScrollBars() ;
1621 wxSize
size(actualWidth
, actualHeight
);
1622 wxSizeEvent
event(size
, m_windowId
);
1623 event
.SetEventObject(this);
1624 GetEventHandler()->ProcessEvent(event
);
1630 wxSize
wxWindowMac::DoGetBestSize() const
1632 if ( m_macIsUserPane
|| IsTopLevel() )
1633 return wxWindowBase::DoGetBestSize() ;
1635 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1636 int bestWidth
, bestHeight
;
1637 m_peer
->GetBestRect( &bestsize
) ;
1639 if ( EmptyRect( &bestsize
) )
1641 bestsize
.left
= bestsize
.top
= 0 ;
1642 bestsize
.right
= 16 ;
1643 bestsize
.bottom
= 16 ;
1644 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1646 bestsize
.bottom
= 16 ;
1648 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1650 bestsize
.bottom
= 24 ;
1654 // return wxWindowBase::DoGetBestSize() ;
1658 bestWidth
= bestsize
.right
- bestsize
.left
;
1659 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1660 if ( bestHeight
< 10 )
1663 return wxSize(bestWidth
, bestHeight
);
1667 // set the size of the window: if the dimensions are positive, just use them,
1668 // but if any of them is equal to -1, it means that we must find the value for
1669 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1670 // which case -1 is a valid value for x and y)
1672 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1673 // the width/height to best suit our contents, otherwise we reuse the current
1675 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1677 // get the current size and position...
1678 int currentX
, currentY
;
1679 GetPosition(¤tX
, ¤tY
);
1681 int currentW
,currentH
;
1682 GetSize(¤tW
, ¤tH
);
1684 // ... and don't do anything (avoiding flicker) if it's already ok
1685 if ( x
== currentX
&& y
== currentY
&&
1686 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1689 MacRepositionScrollBars() ; // we might have a real position shift
1693 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1695 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1698 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1700 wxSize
size(-1, -1);
1703 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1705 size
= DoGetBestSize();
1710 // just take the current one
1717 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1721 size
= DoGetBestSize();
1723 //else: already called DoGetBestSize() above
1729 // just take the current one
1734 DoMoveWindow(x
, y
, width
, height
);
1738 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1740 RgnHandle rgn
= NewRgn() ;
1742 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1743 GetRegionBounds( rgn
, &content
) ;
1745 #if !TARGET_API_MAC_OSX
1746 // if the content rgn is empty / not supported
1747 // don't attempt to correct the coordinates to wxWindow relative ones
1748 if (!::EmptyRect( &content
) )
1751 m_peer
->GetRect( &structure
) ;
1752 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1756 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1759 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1761 if ( clientheight
!= -1 || clientheight
!= -1 )
1763 int currentclientwidth
, currentclientheight
;
1764 int currentwidth
, currentheight
;
1766 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1767 GetSize( ¤twidth
, ¤theight
) ;
1769 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1770 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1774 void wxWindowMac::SetTitle(const wxString
& title
)
1776 m_label
= wxStripMenuCodes(title
) ;
1778 if ( m_peer
&& m_peer
->Ok() )
1780 m_peer
->SetTitle( m_label
) ;
1785 wxString
wxWindowMac::GetTitle() const
1790 bool wxWindowMac::Show(bool show
)
1792 if ( !wxWindowBase::Show(show
) )
1795 // TODO use visibilityChanged Carbon Event for OSX
1796 bool former
= MacIsReallyShown() ;
1798 m_peer
->SetVisibility( show
, true ) ;
1799 if ( former
!= MacIsReallyShown() )
1800 MacPropagateVisibilityChanged() ;
1804 bool wxWindowMac::Enable(bool enable
)
1806 wxASSERT( m_peer
->Ok() ) ;
1807 if ( !wxWindowBase::Enable(enable
) )
1810 bool former
= MacIsReallyEnabled() ;
1811 m_peer
->Enable( enable
) ;
1813 if ( former
!= MacIsReallyEnabled() )
1814 MacPropagateEnabledStateChanged() ;
1819 // status change propagations (will be not necessary for OSX later )
1822 void wxWindowMac::MacPropagateVisibilityChanged()
1824 #if !TARGET_API_MAC_OSX
1825 MacVisibilityChanged() ;
1827 wxWindowListNode
*node
= GetChildren().GetFirst();
1830 wxWindowMac
*child
= node
->GetData();
1831 if ( child
->IsShown() )
1832 child
->MacPropagateVisibilityChanged( ) ;
1833 node
= node
->GetNext();
1838 void wxWindowMac::MacPropagateEnabledStateChanged( )
1840 #if !TARGET_API_MAC_OSX
1841 MacEnabledStateChanged() ;
1843 wxWindowListNode
*node
= GetChildren().GetFirst();
1846 wxWindowMac
*child
= node
->GetData();
1847 if ( child
->IsEnabled() )
1848 child
->MacPropagateEnabledStateChanged() ;
1849 node
= node
->GetNext();
1854 void wxWindowMac::MacPropagateHiliteChanged( )
1856 #if !TARGET_API_MAC_OSX
1857 MacHiliteChanged() ;
1859 wxWindowListNode
*node
= GetChildren().GetFirst();
1862 wxWindowMac
*child
= node
->GetData();
1863 // if ( child->IsEnabled() )
1864 child
->MacPropagateHiliteChanged() ;
1865 node
= node
->GetNext();
1871 // status change notifications
1874 void wxWindowMac::MacVisibilityChanged()
1878 void wxWindowMac::MacHiliteChanged()
1882 void wxWindowMac::MacEnabledStateChanged()
1887 // status queries on the inherited window's state
1890 bool wxWindowMac::MacIsReallyShown()
1892 // only under OSX the visibility of the TLW is taken into account
1893 #if TARGET_API_MAC_OSX
1894 if ( m_peer
&& m_peer
->Ok() )
1895 return m_peer
->IsVisible();
1897 wxWindow
* win
= this ;
1898 while( win
->IsShown() )
1900 if ( win
->IsTopLevel() )
1903 win
= win
->GetParent() ;
1911 bool wxWindowMac::MacIsReallyEnabled()
1913 return m_peer
->IsEnabled() ;
1916 bool wxWindowMac::MacIsReallyHilited()
1918 return m_peer
->IsActive();
1921 void wxWindowMac::MacFlashInvalidAreas()
1923 #if TARGET_API_MAC_OSX
1924 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1932 int wxWindowMac::GetCharHeight() const
1934 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1935 return dc
.GetCharHeight() ;
1938 int wxWindowMac::GetCharWidth() const
1940 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1941 return dc
.GetCharWidth() ;
1944 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1945 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1947 const wxFont
*fontToUse
= theFont
;
1949 fontToUse
= &m_font
;
1951 wxClientDC
dc( (wxWindowMac
*) this ) ;
1953 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1954 if ( externalLeading
)
1955 *externalLeading
= le
;
1965 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1966 * we always intersect with the entire window, not only with the client area
1969 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1971 if ( m_peer
== NULL
)
1974 #if TARGET_API_MAC_OSX
1976 m_peer
->SetNeedsDisplay( true ) ;
1979 RgnHandle update
= NewRgn() ;
1980 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1981 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1982 wxPoint origin
= GetClientAreaOrigin() ;
1983 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1984 // right now this is wx' window coordinates, as our native peer does not have borders, this is
1986 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1987 m_peer
->SetNeedsDisplay( true , update
) ;
1988 DisposeRgn( update
) ;
1992 RgnHandle updateRgn = NewRgn() ;
1995 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1999 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2000 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2002 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2003 DisposeRgn(updateRgn) ;
2005 if ( m_peer
->IsVisible())
2007 m_peer
->SetVisibility( false , false ) ;
2008 m_peer
->SetVisibility( true , true ) ;
2011 if ( MacGetTopLevelWindow() == NULL )
2014 if ( !m_peer->IsVisible())
2017 wxPoint client = GetClientAreaOrigin();
2020 int x2 = m_width - client.x;
2021 int y2 = m_height - client.y;
2023 if (IsKindOf( CLASSINFO(wxButton)))
2025 // buttons have an "aura"
2032 Rect clientrect = { y1, x1, y2, x2 };
2036 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2037 SectRect( &clientrect , &r , &clientrect ) ;
2040 if ( !EmptyRect( &clientrect ) )
2042 int top = 0 , left = 0 ;
2044 MacClientToRootWindow( &left , &top ) ;
2045 OffsetRect( &clientrect , left , top ) ;
2047 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2053 void wxWindowMac::Freeze()
2055 #if TARGET_API_MAC_OSX
2056 if ( !m_frozenness
++ )
2058 m_peer
->SetDrawingEnabled( false ) ;
2064 void wxWindowMac::Thaw()
2066 #if TARGET_API_MAC_OSX
2067 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2069 if ( !--m_frozenness
)
2071 m_peer
->SetDrawingEnabled( true ) ;
2072 m_peer
->InvalidateWithChildren() ;
2077 void wxWindowMac::MacRedrawControl()
2080 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2082 #if TARGET_API_MAC_CARBON
2085 wxClientDC dc(this) ;
2086 wxMacPortSetter helper(&dc) ;
2087 wxMacWindowClipper clipper(this) ;
2088 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2089 UMADrawControl( *m_peer ) ;
2096 void wxWindowMac::OnPaint(wxPaintEvent& event)
2098 // why don't we skip that here ?
2102 wxWindowMac
*wxGetActiveWindow()
2104 // actually this is a windows-only concept
2108 // Coordinates relative to the window
2109 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2111 // We really don't move the mouse programmatically under Mac.
2114 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2116 #if TARGET_API_MAC_OSX
2117 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2123 event
.GetDC()->Clear() ;
2126 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2128 wxWindowDC
dc(this) ;
2129 wxMacPortSetter
helper(&dc
) ;
2131 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2134 int wxWindowMac::GetScrollPos(int orient
) const
2136 if ( orient
== wxHORIZONTAL
)
2139 return m_hScrollBar
->GetThumbPosition() ;
2144 return m_vScrollBar
->GetThumbPosition() ;
2149 // This now returns the whole range, not just the number
2150 // of positions that we can scroll.
2151 int wxWindowMac::GetScrollRange(int orient
) const
2153 if ( orient
== wxHORIZONTAL
)
2156 return m_hScrollBar
->GetRange() ;
2161 return m_vScrollBar
->GetRange() ;
2166 int wxWindowMac::GetScrollThumb(int orient
) const
2168 if ( orient
== wxHORIZONTAL
)
2171 return m_hScrollBar
->GetThumbSize() ;
2176 return m_vScrollBar
->GetThumbSize() ;
2181 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2183 if ( orient
== wxHORIZONTAL
)
2186 m_hScrollBar
->SetThumbPosition( pos
) ;
2191 m_vScrollBar
->SetThumbPosition( pos
) ;
2195 void wxWindowMac::MacPaintBorders( int left
, int top
)
2201 wxGetOsVersion( &major
, &minor
);
2203 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2204 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2205 // OS X has lighter border edges than classic:
2208 darkShadow
.red
= 0x8E8E;
2209 darkShadow
.green
= 0x8E8E;
2210 darkShadow
.blue
= 0x8E8E;
2211 lightShadow
.red
= 0xBDBD;
2212 lightShadow
.green
= 0xBDBD;
2213 lightShadow
.blue
= 0xBDBD;
2219 GetSize( &w
, &h
) ;
2220 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2221 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2223 #if wxMAC_USE_THEME_BORDER
2225 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2226 InsetRect( &rect
, border
, border
);
2227 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2229 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2230 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2232 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2233 RGBForeColor( &face
);
2234 MoveTo( left
+ 0 , top
+ h
- 2 );
2235 LineTo( left
+ 0 , top
+ 0 );
2236 LineTo( left
+ w
- 2 , top
+ 0 );
2238 MoveTo( left
+ 2 , top
+ h
- 3 );
2239 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2240 LineTo( left
+ w
- 3 , top
+ 2 );
2242 RGBForeColor( sunken
? &face
: &darkShadow
);
2243 MoveTo( left
+ 0 , top
+ h
- 1 );
2244 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2245 LineTo( left
+ w
- 1 , top
+ 0 );
2247 RGBForeColor( sunken
? &lightShadow
: &white
);
2248 MoveTo( left
+ 1 , top
+ h
- 3 );
2249 LineTo( left
+ 1, top
+ 1 );
2250 LineTo( left
+ w
- 3 , top
+ 1 );
2252 RGBForeColor( sunken
? &white
: &lightShadow
);
2253 MoveTo( left
+ 1 , top
+ h
- 2 );
2254 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2255 LineTo( left
+ w
- 2 , top
+ 1 );
2257 RGBForeColor( sunken
? &darkShadow
: &face
);
2258 MoveTo( left
+ 2 , top
+ h
- 4 );
2259 LineTo( left
+ 2 , top
+ 2 );
2260 LineTo( left
+ w
- 4 , top
+ 2 );
2263 else if (HasFlag(wxSIMPLE_BORDER
))
2265 #if wxMAC_USE_THEME_BORDER
2267 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2268 InsetRect( &rect
, border
, border
);
2269 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2271 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2272 RGBForeColor( &darkShadow
) ;
2273 FrameRect( &rect
) ;
2278 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2280 if ( child
== m_hScrollBar
)
2281 m_hScrollBar
= NULL
;
2282 if ( child
== m_vScrollBar
)
2283 m_vScrollBar
= NULL
;
2285 wxWindowBase::RemoveChild( child
) ;
2288 // New function that will replace some of the above.
2289 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2290 int range
, bool refresh
)
2292 if ( orient
== wxHORIZONTAL
)
2296 if ( range
== 0 || thumbVisible
>= range
)
2298 if ( m_hScrollBar
->IsShown() )
2299 m_hScrollBar
->Show(false) ;
2303 if ( !m_hScrollBar
->IsShown() )
2304 m_hScrollBar
->Show(true) ;
2305 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2313 if ( range
== 0 || thumbVisible
>= range
)
2315 if ( m_vScrollBar
->IsShown() )
2316 m_vScrollBar
->Show(false) ;
2320 if ( !m_vScrollBar
->IsShown() )
2321 m_vScrollBar
->Show(true) ;
2322 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2326 MacRepositionScrollBars() ;
2329 // Does a physical scroll
2330 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2332 if( dx
== 0 && dy
==0 )
2338 int width
, height
;
2339 GetClientSize( &width
, &height
) ;
2340 #if TARGET_API_MAC_OSX
2341 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2342 // area is scrolled, this does not occur if width and height are 2 pixels less,
2343 // TODO write optimal workaround
2344 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2347 scrollrect
.Intersect( *rect
) ;
2349 if ( m_peer
->GetNeedsDisplay() )
2351 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2352 // either immediate redraw or full invalidate
2354 // is the better overall solution, as it does not slow down scrolling
2355 m_peer
->SetNeedsDisplay( true ) ;
2357 // this would be the preferred version for fast drawing controls
2358 if( UMAGetSystemVersion() < 0x1030 )
2361 HIViewRender(m_peer
->GetControlRef()) ;
2364 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2365 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2366 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2373 RgnHandle updateRgn
= NewRgn() ;
2376 wxClientDC
dc(this) ;
2377 wxMacPortSetter
helper(&dc
) ;
2379 m_peer
->GetRect( &scrollrect
) ;
2380 scrollrect
.top
+= MacGetTopBorderSize() ;
2381 scrollrect
.left
+= MacGetLeftBorderSize() ;
2382 scrollrect
.bottom
= scrollrect
.top
+ height
;
2383 scrollrect
.right
= scrollrect
.left
+ width
;
2387 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2388 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2389 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2391 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2393 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2397 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2399 wxWindowMac
*child
= node
->GetData();
2400 if (child
== m_vScrollBar
) continue;
2401 if (child
== m_hScrollBar
) continue;
2402 if (child
->IsTopLevel()) continue;
2405 child
->GetPosition( &x
, &y
);
2407 child
->GetSize( &w
, &h
);
2411 if (rect
->Intersects(rc
))
2412 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2416 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2421 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2423 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2425 wxScrollWinEvent wevent
;
2426 wevent
.SetPosition(event
.GetPosition());
2427 wevent
.SetOrientation(event
.GetOrientation());
2428 wevent
.m_eventObject
= this;
2430 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2431 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2432 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2433 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2434 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2435 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2436 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2437 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2438 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2439 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2440 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2441 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2442 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2443 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2444 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2445 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2447 GetEventHandler()->ProcessEvent(wevent
);
2451 // Get the window with the focus
2452 wxWindowMac
*wxWindowBase::FindFocus()
2454 ControlRef control
;
2455 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2456 return wxFindControlFromMacControl( control
) ;
2459 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2461 // panel wants to track the window which was the last to have focus in it,
2462 // so we want to set ourselves as the window which last had focus
2464 // notice that it's also important to do it upwards the tree becaus
2465 // otherwise when the top level panel gets focus, it won't set it back to
2466 // us, but to some other sibling
2468 // CS:don't know if this is still needed:
2469 //wxChildFocusEvent eventFocus(this);
2470 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2472 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2474 wxMacWindowStateSaver
sv( this ) ;
2479 MacWindowToRootWindow( &x
, &y
) ;
2480 GetSize( &w
, &h
) ;
2481 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2483 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2484 DrawThemeFocusRect( &rect
, true ) ;
2486 DrawThemeFocusRect( &rect
, false ) ;
2492 void wxWindowMac::OnInternalIdle()
2494 // This calls the UI-update mechanism (querying windows for
2495 // menu/toolbar/control state information)
2496 if (wxUpdateUIEvent::CanUpdate(this))
2497 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2500 // Raise the window to the top of the Z order
2501 void wxWindowMac::Raise()
2503 m_peer
->SetZOrder( true , NULL
) ;
2506 // Lower the window to the bottom of the Z order
2507 void wxWindowMac::Lower()
2509 m_peer
->SetZOrder( false , NULL
) ;
2513 // static wxWindow *gs_lastWhich = NULL;
2515 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2517 // first trigger a set cursor event
2519 wxPoint clientorigin
= GetClientAreaOrigin() ;
2520 wxSize clientsize
= GetClientSize() ;
2522 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2524 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2526 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2527 if ( processedEvtSetCursor
&& event
.HasCursor() )
2529 cursor
= event
.GetCursor() ;
2534 // the test for processedEvtSetCursor is here to prevent using m_cursor
2535 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2536 // it - this is a way to say that our cursor shouldn't be used for this
2538 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2548 cursor
= *wxSTANDARD_CURSOR
;
2552 cursor
.MacInstall() ;
2554 return cursor
.Ok() ;
2557 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2561 return m_tooltip
->GetTip() ;
2563 return wxEmptyString
;
2566 void wxWindowMac::Update()
2568 #if TARGET_API_MAC_OSX
2569 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2570 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2571 // for composited windows this also triggers a redraw of all
2572 // invalid views in the window
2573 if( UMAGetSystemVersion() >= 0x1030 )
2574 HIWindowFlush(window
) ;
2578 // the only way to trigger the redrawing on earlier systems is to call
2581 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2582 UInt32 currentEventClass
= 0 ;
2583 UInt32 currentEventKind
= 0 ;
2584 if ( currentEvent
!= NULL
)
2586 currentEventClass
= ::GetEventClass( currentEvent
) ;
2587 currentEventKind
= ::GetEventKind( currentEvent
) ;
2589 if ( currentEventClass
!= kEventClassMenu
)
2591 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2594 OSStatus status
= noErr
;
2595 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2598 m_peer
->SetNeedsDisplay( true ) ;
2601 ::Draw1Control( m_peer
->GetControlRef() ) ;
2605 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2607 wxTopLevelWindowMac
* win
= NULL
;
2608 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2611 win
= wxFindWinFromMacWindow( window
) ;
2615 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2619 RgnHandle visRgn
= NewRgn() ;
2620 RgnHandle tempRgn
= NewRgn() ;
2621 if ( m_peer
->IsVisible())
2623 m_peer
->GetRect( &r
) ;
2624 r
.left
-= MacGetLeftBorderSize() ;
2625 r
.top
-= MacGetTopBorderSize() ;
2626 r
.bottom
+= MacGetBottomBorderSize() ;
2627 r
.right
+= MacGetRightBorderSize() ;
2629 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2631 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2632 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2641 if ( includeOuterStructures
)
2642 InsetRect( &r
, -3 , -3 ) ;
2643 RectRgn( visRgn
, &r
) ;
2645 if ( !IsTopLevel() )
2647 wxWindow
* child
= this ;
2648 wxWindow
* parent
= child
->GetParent() ;
2653 // we have to find a better clipping algorithm here, in order not to clip things
2654 // positioned like status and toolbar
2655 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2657 size
= parent
->GetSize() ;
2662 size
= parent
->GetClientSize() ;
2663 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2667 parent
->MacWindowToRootWindow( &x
, &y
) ;
2668 MacRootWindowToWindow( &x
, &y
) ;
2670 SetRectRgn( tempRgn
,
2671 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2672 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2673 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2675 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2676 if ( parent
->IsTopLevel() )
2679 parent
= child
->GetParent() ;
2684 wxRegion vis
= visRgn
;
2685 DisposeRgn( visRgn
) ;
2686 DisposeRgn( tempRgn
) ;
2691 This function must not change the updatergn !
2693 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2695 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2696 bool handled
= false ;
2698 GetRegionBounds( updatergn
, &updatebounds
) ;
2700 if ( !EmptyRgn(updatergn
) )
2702 RgnHandle newupdate
= NewRgn() ;
2703 wxSize point
= GetClientSize() ;
2704 wxPoint origin
= GetClientAreaOrigin() ;
2705 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2706 SectRgn( newupdate
, updatergn
, newupdate
) ;
2708 // if (!EmptyRgn(newupdate))
2710 wxWindowDC
dc(this);
2711 dc
.SetClippingRegion(wxRegion(updatergn
));
2712 wxEraseEvent
eevent( GetId(), &dc
);
2713 eevent
.SetEventObject( this );
2714 GetEventHandler()->ProcessEvent( eevent
);
2717 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2718 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2719 m_updateRegion
= newupdate
;
2720 DisposeRgn( newupdate
) ;
2722 if ( !m_updateRegion
.Empty() )
2724 // paint the window itself
2726 event
.m_timeStamp
= time
;
2727 event
.SetEventObject(this);
2728 handled
= GetEventHandler()->ProcessEvent(event
);
2730 // paint custom borders
2731 wxNcPaintEvent
eventNc( GetId() );
2732 eventNc
.SetEventObject( this );
2733 GetEventHandler()->ProcessEvent( eventNc
);
2739 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2741 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2742 // updatergn is always already clipped to our boundaries
2743 // if we are in compositing mode then it is in relative to the upper left of the control
2744 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2745 // of the toplevel window
2746 // it is in window coordinates, not in client coordinates
2748 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2749 RgnHandle ownUpdateRgn
= NewRgn() ;
2750 CopyRgn( updatergn
, ownUpdateRgn
) ;
2752 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2755 m_peer
->GetRectInWindowCoords( &bounds
);
2756 RgnHandle controlRgn
= NewRgn();
2757 RectRgn( controlRgn
, &bounds
);
2758 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2759 // the window update region
2760 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2761 DisposeRgn( controlRgn
);
2763 //KO: convert ownUpdateRgn to local coordinates
2764 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2767 MacDoRedraw( ownUpdateRgn
, time
) ;
2768 DisposeRgn( ownUpdateRgn
) ;
2772 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2774 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2778 if ( iter
->IsTopLevel() )
2779 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2781 iter
= iter
->GetParent() ;
2783 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2787 void wxWindowMac::MacCreateScrollBars( long style
)
2789 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2791 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2793 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2794 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2795 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2796 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2798 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2799 variant
= wxWINDOW_VARIANT_SMALL
;
2802 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2804 GetClientSize( &width
, &height
) ;
2806 wxPoint
vPoint(width
-scrlsize
, 0) ;
2807 wxSize
vSize(scrlsize
, height
- adjust
) ;
2808 wxPoint
hPoint(0 , height
-scrlsize
) ;
2809 wxSize
hSize( width
- adjust
, scrlsize
) ;
2812 if ( style
& wxVSCROLL
)
2814 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2815 vSize
, wxVERTICAL
);
2818 if ( style
& wxHSCROLL
)
2820 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2821 hSize
, wxHORIZONTAL
);
2826 // because the create does not take into account the client area origin
2827 MacRepositionScrollBars() ; // we might have a real position shift
2830 void wxWindowMac::MacRepositionScrollBars()
2832 if ( !m_hScrollBar
&& !m_vScrollBar
)
2835 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2836 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2837 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2839 // get real client area
2843 GetSize( &width
, &height
) ;
2845 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2846 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2848 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2849 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2850 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2851 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2857 GetSize( &w , &h ) ;
2859 MacClientToRootWindow( &x , &y ) ;
2860 MacClientToRootWindow( &w , &h ) ;
2862 wxWindowMac *iter = (wxWindowMac*)this ;
2864 int totW = 10000 , totH = 10000;
2867 if ( iter->IsTopLevel() )
2869 iter->GetSize( &totW , &totH ) ;
2873 iter = iter->GetParent() ;
2901 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2905 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2909 bool wxWindowMac::AcceptsFocus() const
2911 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2914 void wxWindowMac::MacSuperChangedPosition()
2916 // only window-absolute structures have to be moved i.e. controls
2918 wxWindowListNode
*node
= GetChildren().GetFirst();
2921 wxWindowMac
*child
= node
->GetData();
2922 child
->MacSuperChangedPosition() ;
2923 node
= node
->GetNext();
2927 void wxWindowMac::MacTopLevelWindowChangedPosition()
2929 // only screen-absolute structures have to be moved i.e. glcanvas
2931 wxWindowListNode
*node
= GetChildren().GetFirst();
2934 wxWindowMac
*child
= node
->GetData();
2935 child
->MacTopLevelWindowChangedPosition() ;
2936 node
= node
->GetNext();
2940 long wxWindowMac::MacGetLeftBorderSize( ) const
2945 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2950 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2955 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2962 long wxWindowMac::MacGetRightBorderSize( ) const
2964 // they are all symmetric in mac themes
2965 return MacGetLeftBorderSize() ;
2968 long wxWindowMac::MacGetTopBorderSize( ) const
2970 // they are all symmetric in mac themes
2971 return MacGetLeftBorderSize() ;
2974 long wxWindowMac::MacGetBottomBorderSize( ) const
2976 // they are all symmetric in mac themes
2977 return MacGetLeftBorderSize() ;
2980 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2982 return style
& ~wxBORDER_MASK
;
2985 // Find the wxWindowMac at the current mouse position, returning the mouse
2987 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2989 pt
= wxGetMousePosition();
2990 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2994 // Get the current mouse position.
2995 wxPoint
wxGetMousePosition()
2998 wxGetMousePosition(& x
, & y
);
2999 return wxPoint(x
, y
);
3002 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3004 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3006 // copied from wxGTK : CS
3007 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3010 // (a) it's a command event and so is propagated to the parent
3011 // (b) under MSW it can be generated from kbd too
3012 // (c) it uses screen coords (because of (a))
3013 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3015 this->ClientToScreen(event
.GetPosition()));
3016 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3025 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3029 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3033 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3034 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3038 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3040 return eventNotHandledErr
;