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"
39 #include "wx/toolbar.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
69 wxWindowMac
* gFocusWindow
= NULL
;
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
75 #endif // __WXUNIVERSAL__/__WXMAC__
77 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 0
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
103 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
105 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
107 kEventControlVisibilityChanged
= 157
111 static const EventTypeSpec eventList
[] =
113 #if TARGET_API_MAC_OSX
114 { kEventClassControl
, kEventControlDraw
} ,
115 { kEventClassControl
, kEventControlVisibilityChanged
} ,
116 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
117 { kEventClassControl
, kEventControlHiliteChanged
} ,
118 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
119 // { kEventClassControl , kEventControlBoundsChanged } ,
127 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
129 OSStatus result
= eventNotHandledErr
;
131 wxMacCarbonEvent
cEvent( event
) ;
133 ControlRef controlRef
;
134 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
136 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
138 switch( GetEventKind( event
) )
140 case kEventControlDraw
:
142 RgnHandle updateRgn
= NULL
;
144 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
145 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
147 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
149 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
152 // in case we would need a coregraphics compliant background erase first
153 // now usable to track redraws
154 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
155 if ( thisWindow
->MacIsUserPane() )
157 static float color
= 0.5 ;
160 HIViewGetBounds( controlRef
, &bounds
);
161 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
162 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
163 CGContextFillRect( cgContext
, bounds
);
174 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
178 case kEventControlVisibilityChanged
:
179 thisWindow
->MacVisibilityChanged() ;
181 case kEventControlEnabledStateChanged
:
182 thisWindow
->MacEnabledStateChanged() ;
184 case kEventControlHiliteChanged
:
185 thisWindow
->MacHiliteChanged() ;
193 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
195 OSStatus result
= eventNotHandledErr
;
197 switch ( GetEventClass( event
) )
199 case kEventClassControl
:
200 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
208 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
210 // ---------------------------------------------------------------------------
211 // UserPane events for non OSX builds
212 // ---------------------------------------------------------------------------
214 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
216 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
217 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
218 win
->MacControlUserPaneDrawProc(part
) ;
221 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
223 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
224 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
225 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
228 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
230 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
231 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
232 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
235 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
237 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
238 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
239 win
->MacControlUserPaneIdleProc() ;
242 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
244 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
245 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
246 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
249 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
251 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
252 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
253 win
->MacControlUserPaneActivateProc(activating
) ;
256 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
258 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
259 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
260 return win
->MacControlUserPaneFocusProc(action
) ;
263 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
265 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
266 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
267 win
->MacControlUserPaneBackgroundProc(info
) ;
270 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
272 RgnHandle rgn
= NewRgn() ;
274 wxMacWindowStateSaver
sv( this ) ;
275 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
276 MacDoRedraw( rgn
, 0 ) ;
280 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
282 return kControlNoPart
;
285 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
287 return kControlNoPart
;
290 void wxWindowMac::MacControlUserPaneIdleProc()
294 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
296 return kControlNoPart
;
299 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
303 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
305 return kControlNoPart
;
308 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
312 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
313 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
314 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
315 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
316 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
317 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
318 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
319 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
321 // ===========================================================================
323 // ===========================================================================
325 wxList
wxWinMacControlList(wxKEY_INTEGER
);
327 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
329 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
332 return (wxControl
*)node
->GetData();
335 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
337 // adding NULL ControlRef is (first) surely a result of an error and
338 // (secondly) breaks native event processing
339 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
341 if ( !wxWinMacControlList
.Find((long)inControl
) )
342 wxWinMacControlList
.Append((long)inControl
, control
);
345 void wxRemoveMacControlAssociation(wxWindow
*control
)
347 wxWinMacControlList
.DeleteObject(control
);
351 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
353 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
355 // we have to setup the brush in the current port and return noErr
356 // or return an error code so that the control manager walks further up the
357 // hierarchy to find a correct background
359 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
361 OSStatus status
= paramErr
;
364 case kControlMsgApplyTextColor
:
366 case kControlMsgSetUpBackground
:
368 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
372 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
376 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
378 // this clipping is only needed for non HIView
380 RgnHandle clip
= NewRgn() ;
383 wx
->MacWindowToRootWindow( &x
,&y
) ;
384 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
385 OffsetRgn( clip
, x
, y
) ;
392 else if ( wx->MacIsUserPane() )
394 // if we don't have a valid brush for such a control, we have to call the
395 // setup of our parent ourselves
396 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
409 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
410 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
414 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
417 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
422 // ----------------------------------------------------------------------------
423 // constructors and such
424 // ----------------------------------------------------------------------------
426 void wxWindowMac::Init()
429 #if WXWIN_COMPATIBILITY_2_4
430 m_backgroundTransparent
= FALSE
;
433 // as all windows are created with WS_VISIBLE style...
436 m_hScrollBar
= NULL
;
437 m_vScrollBar
= NULL
;
438 m_macBackgroundBrush
= wxNullBrush
;
440 m_macControl
= NULL
;
442 m_macIsUserPane
= TRUE
;
444 // make sure all proc ptrs are available
446 if ( gControlUserPaneDrawUPP
== NULL
)
448 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
449 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
450 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
451 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
452 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
453 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
454 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
455 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
457 if ( wxMacLiveScrollbarActionUPP
== NULL
)
459 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
462 if ( wxMacSetupControlBackgroundUPP
== NULL
)
464 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
467 // we need a valid font for the encodings
468 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
472 wxWindowMac::~wxWindowMac()
476 m_isBeingDeleted
= TRUE
;
478 #ifndef __WXUNIVERSAL__
479 // VS: make sure there's no wxFrame with last focus set to us:
480 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
482 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
485 if ( frame
->GetLastFocus() == this )
487 frame
->SetLastFocus((wxWindow
*)NULL
);
492 #endif // __WXUNIVERSAL__
494 // wxRemoveMacControlAssociation( this ) ;
495 // If we delete an item, we should initialize the parent panel,
496 // because it could now be invalid.
497 wxWindow
*parent
= GetParent() ;
500 if (parent
->GetDefaultItem() == (wxButton
*) this)
501 parent
->SetDefaultItem(NULL
);
503 if ( (ControlRef
) m_macControl
)
505 // in case the callback might be called during destruction
506 wxRemoveMacControlAssociation( this) ;
507 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
508 ::DisposeControl( (ControlRef
) m_macControl
) ;
509 m_macControl
= NULL
;
512 if ( g_MacLastWindow
== this )
514 g_MacLastWindow
= NULL
;
517 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
520 if ( frame
->GetLastFocus() == this )
521 frame
->SetLastFocus( NULL
) ;
524 if ( gFocusWindow
== this )
526 gFocusWindow
= NULL
;
531 // delete our drop target if we've got one
532 #if wxUSE_DRAG_AND_DROP
533 if ( m_dropTarget
!= NULL
)
538 #endif // wxUSE_DRAG_AND_DROP
543 void wxWindowMac::MacInstallEventHandler()
545 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
546 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
547 GetEventTypeCount(eventList
), eventList
, this,
548 (EventHandlerRef
*)&m_macControlEventHandler
);
553 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
557 const wxString
& name
)
559 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
561 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
564 parent
->AddChild(this);
566 m_windowVariant
= parent
->GetWindowVariant() ;
568 if ( m_macIsUserPane
)
570 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
572 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
573 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
575 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
577 MacPostControlCreate(pos
,size
) ;
578 #if !TARGET_API_MAC_OSX
579 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
580 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
581 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
582 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
583 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
584 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
585 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
586 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
587 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
588 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
589 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
590 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
591 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
592 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
593 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
594 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
597 #ifndef __WXUNIVERSAL__
598 // Don't give scrollbars to wxControls unless they ask for them
599 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
600 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
602 MacCreateScrollBars( style
) ;
606 wxWindowCreateEvent
event(this);
607 GetEventHandler()->AddPendingEvent(event
);
612 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
614 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
616 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
618 MacInstallEventHandler();
620 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
621 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
622 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
624 // adjust font, controlsize etc
625 DoSetWindowVariant( m_windowVariant
) ;
627 #if !TARGET_API_MAC_OSX
628 // eventually we can fix some clipping issues be reactivating this hook
629 //if ( m_macIsUserPane )
630 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
633 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
635 wxSize new_size
= size
;
636 if (!m_macIsUserPane
)
638 wxSize
best_size( DoGetBestSize() );
641 new_size
.x
= best_size
.x
;
644 new_size
.y
= best_size
.y
;
646 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
649 SetCursor( *wxSTANDARD_CURSOR
) ;
653 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
655 // Don't assert, in case we set the window variant before
656 // the window is created
657 // wxASSERT( m_macControl != NULL ) ;
659 m_windowVariant
= variant
;
665 ThemeFontID themeFont
= kThemeSystemFont
;
667 // we will get that from the settings later
668 // and make this NORMAL later, but first
669 // we have a few calculations that we must fix
673 case wxWINDOW_VARIANT_NORMAL
:
674 size
= kControlSizeNormal
;
675 themeFont
= kThemeSystemFont
;
677 case wxWINDOW_VARIANT_SMALL
:
678 size
= kControlSizeSmall
;
679 themeFont
= kThemeSmallSystemFont
;
681 case wxWINDOW_VARIANT_MINI
:
682 if (UMAGetSystemVersion() >= 0x1030 )
684 // not always defined in the headers
690 size
= kControlSizeSmall
;
691 themeFont
= kThemeSmallSystemFont
;
694 case wxWINDOW_VARIANT_LARGE
:
695 size
= kControlSizeLarge
;
696 themeFont
= kThemeSystemFont
;
699 wxFAIL_MSG(_T("unexpected window variant"));
702 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
705 font
.MacCreateThemeFont( themeFont
) ;
709 void wxWindowMac::MacUpdateControlFont()
711 ControlFontStyleRec fontStyle
;
712 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
714 switch( m_font
.MacGetThemeFontID() )
716 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
717 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
718 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
719 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
721 fontStyle
.flags
= kControlUseFontMask
;
725 fontStyle
.font
= m_font
.MacGetFontNum() ;
726 fontStyle
.style
= m_font
.MacGetFontStyle() ;
727 fontStyle
.size
= m_font
.MacGetFontSize() ;
728 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
731 fontStyle
.just
= teJustLeft
;
732 fontStyle
.flags
|= kControlUseJustMask
;
733 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
734 fontStyle
.just
= teJustCenter
;
735 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
736 fontStyle
.just
= teJustRight
;
739 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
740 fontStyle
.flags
|= kControlUseForeColorMask
;
742 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
746 bool wxWindowMac::SetFont(const wxFont
& font
)
748 bool retval
= !wxWindowBase::SetFont( font
) ;
750 MacUpdateControlFont() ;
755 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
757 if ( !wxWindowBase::SetForegroundColour(col
) )
760 MacUpdateControlFont() ;
765 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
767 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
771 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
773 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
775 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
777 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
781 brush
.SetColour( col
) ;
783 MacSetBackgroundBrush( brush
) ;
785 MacUpdateControlFont() ;
791 bool wxWindowMac::MacCanFocus() const
793 wxASSERT( m_macControl
!= NULL
) ;
799 void wxWindowMac::SetFocus()
801 if ( gFocusWindow
== this )
804 if ( AcceptsFocus() )
810 if ( gFocusWindow
->m_caret
)
812 gFocusWindow
->m_caret
->OnKillFocus();
814 #endif // wxUSE_CARET
815 #ifndef __WXUNIVERSAL__
816 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
817 // TODO we must use the built-in focusing
818 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
820 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
821 control
->MacRedrawControl() ;
824 // Without testing the window id, for some reason
825 // a kill focus event can still be sent to
826 // the control just being focussed.
827 int thisId
= this->m_windowId
;
828 int gFocusWindowId
= gFocusWindow
->m_windowId
;
829 if (gFocusWindowId
!= thisId
)
831 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
832 event
.SetEventObject(gFocusWindow
);
833 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
836 gFocusWindow
= this ;
842 m_caret
->OnSetFocus();
844 #endif // wxUSE_CARET
845 // panel wants to track the window which was the last to have focus in it
846 wxChildFocusEvent
eventFocus(this);
847 GetEventHandler()->ProcessEvent(eventFocus
);
849 #ifndef __WXUNIVERSAL__
850 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
851 if ( control
&& control
->GetHandle() )
853 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
856 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
857 event
.SetEventObject(this);
858 GetEventHandler()->ProcessEvent(event
) ;
864 void wxWindowMac::DoCaptureMouse()
866 wxTheApp
->s_captureWindow
= this ;
869 wxWindow
* wxWindowBase::GetCapture()
871 return wxTheApp
->s_captureWindow
;
874 void wxWindowMac::DoReleaseMouse()
876 wxTheApp
->s_captureWindow
= NULL
;
879 #if wxUSE_DRAG_AND_DROP
881 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
883 if ( m_dropTarget
!= 0 ) {
887 m_dropTarget
= pDropTarget
;
888 if ( m_dropTarget
!= 0 )
896 // Old style file-manager drag&drop
897 void wxWindowMac::DragAcceptFiles(bool accept
)
902 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
903 int& w
, int& h
) const
906 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
911 w
= bounds
.right
- bounds
.left
;
912 h
= bounds
.bottom
- bounds
.top
;
914 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
917 Point tlworigin
= { 0 , 0 } ;
919 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
920 ::LocalToGlobal( &tlworigin
) ;
928 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
931 int& w
, int& h
, bool adjustOrigin
) const
935 // todo the default calls may be used as soon as PostCreateControl Is moved here
936 w
= size
.x
; // WidthDefault( size.x );
937 h
= size
.y
; // HeightDefault( size.y ) ;
938 #if !TARGET_API_MAC_OSX
939 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
942 AdjustForParentClientOrigin( x
, y
) ;
947 void wxWindowMac::DoGetSize(int *x
, int *y
) const
949 #if TARGET_API_MAC_OSX
950 int x1
, y1
, w1
,h1
;
951 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
957 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
958 if(x
) *x
= bounds
.right
- bounds
.left
;
959 if(y
) *y
= bounds
.bottom
- bounds
.top
;
963 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
965 #if TARGET_API_MAC_OSX
966 int x1
, y1
, w1
,h1
;
967 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
970 wxWindow
*parent
= GetParent();
973 wxPoint
pt(parent
->GetClientAreaOrigin());
982 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
983 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
985 int xx
= bounds
.left
;
986 int yy
= bounds
.top
;
988 if ( !GetParent()->IsTopLevel() )
990 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
996 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1005 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1007 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1009 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1012 Point localwhere
= {0,0} ;
1014 if(x
) localwhere
.h
= * x
;
1015 if(y
) localwhere
.v
= * y
;
1017 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1018 ::GlobalToLocal( &localwhere
) ;
1019 if(x
) *x
= localwhere
.h
;
1020 if(y
) *y
= localwhere
.v
;
1023 MacRootWindowToWindow( x
, y
) ;
1025 wxPoint origin
= GetClientAreaOrigin() ;
1026 if(x
) *x
-= origin
.x
;
1027 if(y
) *y
-= origin
.y
;
1030 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1032 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1033 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1035 wxPoint origin
= GetClientAreaOrigin() ;
1036 if(x
) *x
+= origin
.x
;
1037 if(y
) *y
+= origin
.y
;
1039 MacWindowToRootWindow( x
, y
) ;
1042 Point localwhere
= { 0,0 };
1043 if(x
) localwhere
.h
= * x
;
1044 if(y
) localwhere
.v
= * y
;
1046 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1047 ::LocalToGlobal( &localwhere
) ;
1048 if(x
) *x
= localwhere
.h
;
1049 if(y
) *y
= localwhere
.v
;
1053 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1055 wxPoint origin
= GetClientAreaOrigin() ;
1056 if(x
) *x
+= origin
.x
;
1057 if(y
) *y
+= origin
.y
;
1059 MacWindowToRootWindow( x
, y
) ;
1062 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1064 MacRootWindowToWindow( x
, y
) ;
1066 wxPoint origin
= GetClientAreaOrigin() ;
1067 if(x
) *x
-= origin
.x
;
1068 if(y
) *y
-= origin
.y
;
1071 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1073 #if TARGET_API_MAC_OSX
1075 if ( x
) pt
.x
= *x
;
1076 if ( y
) pt
.y
= *y
;
1078 if ( !IsTopLevel() )
1079 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1081 if ( x
) *x
= (int) pt
.x
;
1082 if ( y
) *y
= (int) pt
.y
;
1084 if ( !IsTopLevel() )
1087 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1088 if(x
) *x
+= bounds
.left
;
1089 if(y
) *y
+= bounds
.top
;
1094 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1099 MacWindowToRootWindow( &x1
, &y1
) ;
1104 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1106 #if TARGET_API_MAC_OSX
1108 if ( x
) pt
.x
= *x
;
1109 if ( y
) pt
.y
= *y
;
1111 if ( !IsTopLevel() )
1112 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1114 if ( x
) *x
= (int) pt
.x
;
1115 if ( y
) *y
= (int) pt
.y
;
1117 if ( !IsTopLevel() )
1120 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1121 if(x
) *x
-= bounds
.left
;
1122 if(y
) *y
-= bounds
.top
;
1127 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1132 MacRootWindowToWindow( &x1
, &y1
) ;
1137 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1139 RgnHandle rgn
= NewRgn() ;
1141 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1143 GetRegionBounds( rgn
, &content
) ;
1148 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1151 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1152 #if !TARGET_API_MAC_OSX
1153 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1155 left
= content
.left
- structure
.left
;
1156 top
= content
.top
- structure
.top
;
1157 right
= structure
.right
- content
.right
;
1158 bottom
= structure
.bottom
- content
.bottom
;
1161 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1163 wxSize sizeTotal
= size
;
1165 RgnHandle rgn
= NewRgn() ;
1169 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1171 GetRegionBounds( rgn
, &content
) ;
1176 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1179 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1180 #if !TARGET_API_MAC_OSX
1181 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1184 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1185 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1187 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1188 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1194 // Get size *available for subwindows* i.e. excluding menu bar etc.
1195 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1199 RgnHandle rgn
= NewRgn() ;
1201 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1203 GetRegionBounds( rgn
, &content
) ;
1208 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1210 #if !TARGET_API_MAC_OSX
1212 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1213 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1215 ww
= content
.right
- content
.left
;
1216 hh
= content
.bottom
- content
.top
;
1218 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1219 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1221 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1227 GetSize( &w
, &h
) ;
1229 MacClientToRootWindow( &x1
, &y1
) ;
1230 MacClientToRootWindow( &w
, &h
) ;
1232 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1234 int totW
= 10000 , totH
= 10000;
1237 if ( iter
->IsTopLevel() )
1239 iter
->GetSize( &totW
, &totH
) ;
1243 iter
= iter
->GetParent() ;
1246 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1248 hh
-= MAC_SCROLLBAR_SIZE
;
1254 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1256 ww
-= MAC_SCROLLBAR_SIZE
;
1268 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1270 if (m_cursor
== cursor
)
1273 if (wxNullCursor
== cursor
)
1275 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1280 if ( ! wxWindowBase::SetCursor( cursor
) )
1284 wxASSERT_MSG( m_cursor
.Ok(),
1285 wxT("cursor must be valid after call to the base version"));
1289 TODO why do we have to use current coordinates ?
1292 wxWindowMac *mouseWin ;
1295 // Change the cursor NOW if we're within the correct window
1298 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1300 if ( mouseWin == this && !wxIsBusy() )
1302 m_cursor.MacInstall() ;
1308 m_cursor
.MacInstall() ;
1315 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1317 menu
->SetInvokingWindow(this);
1319 ClientToScreen( &x
, &y
) ;
1321 menu
->MacBeforeDisplay( true ) ;
1322 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1323 if ( HiWord(menuResult
) != 0 )
1326 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1327 wxMenuItem
* item
= NULL
;
1329 item
= menu
->FindItem(id
, &realmenu
) ;
1330 if (item
->IsCheckable())
1332 item
->Check( !item
->IsChecked() ) ;
1334 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1336 menu
->MacAfterDisplay( true ) ;
1338 menu
->SetInvokingWindow(NULL
);
1344 // ----------------------------------------------------------------------------
1346 // ----------------------------------------------------------------------------
1350 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1352 wxWindowBase::DoSetToolTip(tooltip
);
1355 m_tooltip
->SetWindow(this);
1358 #endif // wxUSE_TOOLTIPS
1360 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1362 int former_x
, former_y
, former_w
, former_h
;
1363 #if !TARGET_API_MAC_OSX
1364 DoGetPosition( &former_x
, &former_y
) ;
1365 DoGetSize( &former_w
, &former_h
) ;
1367 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1370 int actualWidth
= width
;
1371 int actualHeight
= height
;
1375 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1376 actualWidth
= m_minWidth
;
1377 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1378 actualHeight
= m_minHeight
;
1379 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1380 actualWidth
= m_maxWidth
;
1381 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1382 actualHeight
= m_maxHeight
;
1384 bool doMove
= false ;
1385 bool doResize
= false ;
1387 if ( actualX
!= former_x
|| actualY
!= former_y
)
1391 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1396 if ( doMove
|| doResize
)
1398 // we don't adjust twice for the origin
1399 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1400 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1401 #if TARGET_API_MAC_OSX
1402 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1404 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1405 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1406 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1408 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1410 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1412 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1414 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1416 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1418 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1420 MacRepositionScrollBars() ;
1423 wxPoint
point(actualX
,actualY
);
1424 wxMoveEvent
event(point
, m_windowId
);
1425 event
.SetEventObject(this);
1426 GetEventHandler()->ProcessEvent(event
) ;
1430 MacRepositionScrollBars() ;
1431 wxSize
size(actualWidth
, actualHeight
);
1432 wxSizeEvent
event(size
, m_windowId
);
1433 event
.SetEventObject(this);
1434 GetEventHandler()->ProcessEvent(event
);
1440 wxSize
wxWindowMac::DoGetBestSize() const
1442 if ( m_macIsUserPane
|| IsTopLevel() )
1443 return wxWindowBase::DoGetBestSize() ;
1445 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1446 short baselineoffset
;
1447 int bestWidth
, bestHeight
;
1448 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1450 if ( EmptyRect( &bestsize
) )
1453 bestsize
.left
= bestsize
.top
= 0 ;
1454 bestsize
.right
= 16 ;
1455 bestsize
.bottom
= 16 ;
1456 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1458 bestsize
.bottom
= 16 ;
1460 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1462 bestsize
.bottom
= 24 ;
1466 // return wxWindowBase::DoGetBestSize() ;
1470 bestWidth
= bestsize
.right
- bestsize
.left
;
1471 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1472 if ( bestHeight
< 10 )
1475 return wxSize(bestWidth
, bestHeight
);
1476 // return wxWindowBase::DoGetBestSize() ;
1480 // set the size of the window: if the dimensions are positive, just use them,
1481 // but if any of them is equal to -1, it means that we must find the value for
1482 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1483 // which case -1 is a valid value for x and y)
1485 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1486 // the width/height to best suit our contents, otherwise we reuse the current
1488 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1490 // get the current size and position...
1491 int currentX
, currentY
;
1492 GetPosition(¤tX
, ¤tY
);
1494 int currentW
,currentH
;
1495 GetSize(¤tW
, ¤tH
);
1497 // ... and don't do anything (avoiding flicker) if it's already ok
1498 if ( x
== currentX
&& y
== currentY
&&
1499 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1502 MacRepositionScrollBars() ; // we might have a real position shift
1506 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1508 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1511 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1513 wxSize
size(-1, -1);
1516 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1518 size
= DoGetBestSize();
1523 // just take the current one
1530 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1534 size
= DoGetBestSize();
1536 //else: already called DoGetBestSize() above
1542 // just take the current one
1547 DoMoveWindow(x
, y
, width
, height
);
1551 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1553 RgnHandle rgn
= NewRgn() ;
1555 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1556 GetRegionBounds( rgn
, &content
) ;
1558 #if !TARGET_API_MAC_OSX
1560 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1561 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1564 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1567 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1569 if ( clientheight
!= -1 || clientheight
!= -1 )
1571 int currentclientwidth
, currentclientheight
;
1572 int currentwidth
, currentheight
;
1574 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1575 GetSize( ¤twidth
, ¤theight
) ;
1577 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1578 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1582 void wxWindowMac::SetTitle(const wxString
& title
)
1584 m_label
= wxStripMenuCodes(title
) ;
1588 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1593 wxString
wxWindowMac::GetTitle() const
1598 bool wxWindowMac::Show(bool show
)
1600 if ( !wxWindowBase::Show(show
) )
1603 // TODO use visibilityChanged Carbon Event for OSX
1604 bool former
= MacIsReallyShown() ;
1606 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1607 if ( former
!= MacIsReallyShown() )
1608 MacPropagateVisibilityChanged() ;
1612 bool wxWindowMac::Enable(bool enable
)
1614 wxASSERT( m_macControl
!= NULL
) ;
1615 if ( !wxWindowBase::Enable(enable
) )
1618 bool former
= MacIsReallyEnabled() ;
1620 EnableControl( (ControlRef
) m_macControl
) ;
1622 DisableControl( (ControlRef
) m_macControl
) ;
1624 if ( former
!= MacIsReallyEnabled() )
1625 MacPropagateEnabledStateChanged() ;
1630 // status change propagations (will be not necessary for OSX later )
1633 void wxWindowMac::MacPropagateVisibilityChanged()
1635 #if !TARGET_API_MAC_OSX
1636 MacVisibilityChanged() ;
1638 wxWindowListNode
*node
= GetChildren().GetFirst();
1641 wxWindowMac
*child
= node
->GetData();
1642 if ( child
->IsShown() )
1643 child
->MacPropagateVisibilityChanged( ) ;
1644 node
= node
->GetNext();
1649 void wxWindowMac::MacPropagateEnabledStateChanged( )
1651 #if !TARGET_API_MAC_OSX
1652 MacEnabledStateChanged() ;
1654 wxWindowListNode
*node
= GetChildren().GetFirst();
1657 wxWindowMac
*child
= node
->GetData();
1658 if ( child
->IsEnabled() )
1659 child
->MacPropagateEnabledStateChanged() ;
1660 node
= node
->GetNext();
1665 void wxWindowMac::MacPropagateHiliteChanged( )
1667 #if !TARGET_API_MAC_OSX
1668 MacHiliteChanged() ;
1670 wxWindowListNode
*node
= GetChildren().GetFirst();
1673 wxWindowMac
*child
= node
->GetData();
1674 // if ( child->IsEnabled() )
1675 child
->MacPropagateHiliteChanged() ;
1676 node
= node
->GetNext();
1682 // status change notifications
1685 void wxWindowMac::MacVisibilityChanged()
1689 void wxWindowMac::MacHiliteChanged()
1693 void wxWindowMac::MacEnabledStateChanged()
1698 // status queries on the inherited window's state
1701 bool wxWindowMac::MacIsReallyShown()
1703 // only under OSX the visibility of the TLW is taken into account
1704 #if TARGET_API_MAC_OSX
1705 return IsControlVisible( (ControlRef
) m_macControl
) ;
1707 wxWindow
* win
= this ;
1708 while( win
->IsShown() )
1710 if ( win
->IsTopLevel() )
1713 win
= win
->GetParent() ;
1722 bool wxWindowMac::MacIsReallyEnabled()
1724 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1727 bool wxWindowMac::MacIsReallyHilited()
1729 return IsControlActive( (ControlRef
) m_macControl
) ;
1736 int wxWindowMac::GetCharHeight() const
1738 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1739 return dc
.GetCharHeight() ;
1742 int wxWindowMac::GetCharWidth() const
1744 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1745 return dc
.GetCharWidth() ;
1748 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1749 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1751 const wxFont
*fontToUse
= theFont
;
1753 fontToUse
= &m_font
;
1755 wxClientDC
dc( (wxWindowMac
*) this ) ;
1757 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1758 if ( externalLeading
)
1759 *externalLeading
= le
;
1769 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1770 * we always intersect with the entire window, not only with the client area
1773 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1775 #if TARGET_API_MAC_OSX
1777 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1780 RgnHandle update
= NewRgn() ;
1781 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1782 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1783 wxPoint origin
= GetClientAreaOrigin() ;
1784 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1785 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1789 RgnHandle updateRgn = NewRgn() ;
1792 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1796 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1797 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1799 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1800 DisposeRgn(updateRgn) ;
1802 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1804 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1805 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1808 if ( MacGetTopLevelWindow() == NULL )
1811 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1814 wxPoint client = GetClientAreaOrigin();
1817 int x2 = m_width - client.x;
1818 int y2 = m_height - client.y;
1820 if (IsKindOf( CLASSINFO(wxButton)))
1822 // buttons have an "aura"
1829 Rect clientrect = { y1, x1, y2, x2 };
1833 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1834 SectRect( &clientrect , &r , &clientrect ) ;
1837 if ( !EmptyRect( &clientrect ) )
1839 int top = 0 , left = 0 ;
1841 MacClientToRootWindow( &left , &top ) ;
1842 OffsetRect( &clientrect , left , top ) ;
1844 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1850 void wxWindowMac::Freeze()
1852 #if TARGET_API_MAC_OSX
1853 if ( !m_frozenness
++ )
1855 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1860 #if TARGET_API_MAC_OSX
1861 static void InvalidateControlAndChildren( HIViewRef control
)
1863 HIViewSetNeedsDisplay( control
, true ) ;
1864 UInt16 childrenCount
= 0 ;
1865 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1866 if ( err
== errControlIsNotEmbedder
)
1868 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1870 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1873 err
= GetIndexedSubControl( control
, i
, & child
) ;
1874 if ( err
== errControlIsNotEmbedder
)
1876 InvalidateControlAndChildren( child
) ;
1881 void wxWindowMac::Thaw()
1883 #if TARGET_API_MAC_OSX
1884 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1886 if ( !--m_frozenness
)
1888 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
1889 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
1890 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
1895 void wxWindowMac::MacRedrawControl()
1898 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1900 #if TARGET_API_MAC_CARBON
1903 wxClientDC dc(this) ;
1904 wxMacPortSetter helper(&dc) ;
1905 wxMacWindowClipper clipper(this) ;
1906 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1907 UMADrawControl( (ControlRef) m_macControl ) ;
1914 void wxWindowMac::OnPaint(wxPaintEvent& event)
1916 // why don't we skip that here ?
1920 wxWindowMac
*wxGetActiveWindow()
1922 // actually this is a windows-only concept
1926 // Coordinates relative to the window
1927 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1929 // We really don't move the mouse programmatically under Mac.
1932 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1934 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1939 event
.GetDC()->Clear() ;
1942 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1944 wxWindowDC
dc(this) ;
1945 wxMacPortSetter
helper(&dc
) ;
1947 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1950 int wxWindowMac::GetScrollPos(int orient
) const
1952 if ( orient
== wxHORIZONTAL
)
1955 return m_hScrollBar
->GetThumbPosition() ;
1960 return m_vScrollBar
->GetThumbPosition() ;
1965 // This now returns the whole range, not just the number
1966 // of positions that we can scroll.
1967 int wxWindowMac::GetScrollRange(int orient
) const
1969 if ( orient
== wxHORIZONTAL
)
1972 return m_hScrollBar
->GetRange() ;
1977 return m_vScrollBar
->GetRange() ;
1982 int wxWindowMac::GetScrollThumb(int orient
) const
1984 if ( orient
== wxHORIZONTAL
)
1987 return m_hScrollBar
->GetThumbSize() ;
1992 return m_vScrollBar
->GetThumbSize() ;
1997 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1999 if ( orient
== wxHORIZONTAL
)
2002 m_hScrollBar
->SetThumbPosition( pos
) ;
2007 m_vScrollBar
->SetThumbPosition( pos
) ;
2011 void wxWindowMac::MacPaintBorders( int left
, int top
)
2017 wxGetOsVersion( &major
, &minor
);
2019 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2020 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2022 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2023 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2024 // OS X has lighter border edges than classic:
2027 darkShadow
.red
= 0x8E8E;
2028 darkShadow
.green
= 0x8E8E;
2029 darkShadow
.blue
= 0x8E8E;
2030 lightShadow
.red
= 0xBDBD;
2031 lightShadow
.green
= 0xBDBD;
2032 lightShadow
.blue
= 0xBDBD;
2038 GetSize( &w
, &h
) ;
2039 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2041 #if wxMAC_USE_THEME_BORDER
2042 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2045 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2046 InsetRect( &rect , border , border );
2047 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2050 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2052 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2053 RGBForeColor( &face
);
2054 MoveTo( left
+ 0 , top
+ h
- 2 );
2055 LineTo( left
+ 0 , top
+ 0 );
2056 LineTo( left
+ w
- 2 , top
+ 0 );
2058 MoveTo( left
+ 2 , top
+ h
- 3 );
2059 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2060 LineTo( left
+ w
- 3 , top
+ 2 );
2062 RGBForeColor( sunken
? &face
: &darkShadow
);
2063 MoveTo( left
+ 0 , top
+ h
- 1 );
2064 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2065 LineTo( left
+ w
- 1 , top
+ 0 );
2067 RGBForeColor( sunken
? &lightShadow
: &white
);
2068 MoveTo( left
+ 1 , top
+ h
- 3 );
2069 LineTo( left
+ 1, top
+ 1 );
2070 LineTo( left
+ w
- 3 , top
+ 1 );
2072 RGBForeColor( sunken
? &white
: &lightShadow
);
2073 MoveTo( left
+ 1 , top
+ h
- 2 );
2074 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2075 LineTo( left
+ w
- 2 , top
+ 1 );
2077 RGBForeColor( sunken
? &darkShadow
: &face
);
2078 MoveTo( left
+ 2 , top
+ h
- 4 );
2079 LineTo( left
+ 2 , top
+ 2 );
2080 LineTo( left
+ w
- 4 , top
+ 2 );
2083 else if (HasFlag(wxSIMPLE_BORDER
))
2085 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2086 RGBForeColor( &darkShadow
) ;
2087 FrameRect( &rect
) ;
2091 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2093 if ( child
== m_hScrollBar
)
2094 m_hScrollBar
= NULL
;
2095 if ( child
== m_vScrollBar
)
2096 m_vScrollBar
= NULL
;
2098 wxWindowBase::RemoveChild( child
) ;
2101 // New function that will replace some of the above.
2102 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2103 int range
, bool refresh
)
2105 if ( orient
== wxHORIZONTAL
)
2109 if ( range
== 0 || thumbVisible
>= range
)
2111 if ( m_hScrollBar
->IsShown() )
2112 m_hScrollBar
->Show(false) ;
2116 if ( !m_hScrollBar
->IsShown() )
2117 m_hScrollBar
->Show(true) ;
2118 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2126 if ( range
== 0 || thumbVisible
>= range
)
2128 if ( m_vScrollBar
->IsShown() )
2129 m_vScrollBar
->Show(false) ;
2133 if ( !m_vScrollBar
->IsShown() )
2134 m_vScrollBar
->Show(true) ;
2135 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2139 MacRepositionScrollBars() ;
2142 // Does a physical scroll
2143 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2145 if( dx
== 0 && dy
==0 )
2150 wxClientDC
dc(this) ;
2151 wxMacPortSetter
helper(&dc
) ;
2153 int width
, height
;
2154 GetClientSize( &width
, &height
) ;
2161 // TODO take out the boundaries
2162 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2164 RgnHandle updateRgn
= NewRgn() ;
2167 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2168 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2169 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2171 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2173 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2174 // but it seems the update only refreshes the background of the control, rather than calling
2175 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2176 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2179 // we also have to scroll the update rgn in this rectangle
2180 // in order not to loose updates
2182 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2183 RgnHandle formerUpdateRgn
= NewRgn() ;
2184 RgnHandle scrollRgn
= NewRgn() ;
2185 RectRgn( scrollRgn
, &scrollrect
) ;
2186 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2188 LocalToGlobal( &pt
) ;
2189 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2190 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2191 if ( !EmptyRgn( formerUpdateRgn
) )
2193 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2194 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2195 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2197 InvalWindowRgn(rootWindow
, updateRgn
) ;
2198 DisposeRgn( updateRgn
) ;
2199 DisposeRgn( formerUpdateRgn
) ;
2200 DisposeRgn( scrollRgn
) ;
2204 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2206 wxWindowMac
*child
= node
->GetData();
2207 if (child
== m_vScrollBar
) continue;
2208 if (child
== m_hScrollBar
) continue;
2209 if (child
->IsTopLevel()) continue;
2212 child
->GetPosition( &x
, &y
);
2214 child
->GetSize( &w
, &h
);
2218 if (rect
->Intersects(rc
))
2219 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2223 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2227 // TODO remove, was moved higher up Update() ;
2231 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2233 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2235 wxScrollWinEvent wevent
;
2236 wevent
.SetPosition(event
.GetPosition());
2237 wevent
.SetOrientation(event
.GetOrientation());
2238 wevent
.m_eventObject
= this;
2240 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2241 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2242 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2243 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2244 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2245 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2246 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2247 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2248 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2249 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2250 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2251 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2252 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2253 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2254 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2255 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2257 GetEventHandler()->ProcessEvent(wevent
);
2261 // Get the window with the focus
2262 wxWindowMac
*wxWindowBase::FindFocus()
2264 return gFocusWindow
;
2267 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2269 // panel wants to track the window which was the last to have focus in it,
2270 // so we want to set ourselves as the window which last had focus
2272 // notice that it's also important to do it upwards the tree becaus
2273 // otherwise when the top level panel gets focus, it won't set it back to
2274 // us, but to some other sibling
2276 // CS:don't know if this is still needed:
2277 //wxChildFocusEvent eventFocus(this);
2278 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2283 void wxWindowMac::OnInternalIdle()
2285 // This calls the UI-update mechanism (querying windows for
2286 // menu/toolbar/control state information)
2287 if (wxUpdateUIEvent::CanUpdate(this))
2288 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2291 // Raise the window to the top of the Z order
2292 void wxWindowMac::Raise()
2296 // Lower the window to the bottom of the Z order
2297 void wxWindowMac::Lower()
2302 // static wxWindow *gs_lastWhich = NULL;
2304 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2306 // first trigger a set cursor event
2308 wxPoint clientorigin
= GetClientAreaOrigin() ;
2309 wxSize clientsize
= GetClientSize() ;
2311 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2313 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2315 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2316 if ( processedEvtSetCursor
&& event
.HasCursor() )
2318 cursor
= event
.GetCursor() ;
2323 // the test for processedEvtSetCursor is here to prevent using m_cursor
2324 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2325 // it - this is a way to say that our cursor shouldn't be used for this
2327 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2337 cursor
= *wxSTANDARD_CURSOR
;
2341 cursor
.MacInstall() ;
2343 return cursor
.Ok() ;
2346 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2350 return m_tooltip
->GetTip() ;
2352 return wxEmptyString
;
2355 void wxWindowMac::Update()
2357 #if TARGET_API_MAC_OSX
2358 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2360 ::Draw1Control( (ControlRef
) m_macControl
) ;
2364 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2366 wxTopLevelWindowMac
* win
= NULL
;
2367 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2370 win
= wxFindWinFromMacWindow( window
) ;
2374 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2378 RgnHandle visRgn
= NewRgn() ;
2379 RgnHandle tempRgn
= NewRgn() ;
2380 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2382 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2383 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2385 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2386 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2395 if ( includeOuterStructures
)
2396 InsetRect( &r
, -3 , -3 ) ;
2397 RectRgn( visRgn
, &r
) ;
2398 if ( !IsTopLevel() )
2400 wxWindow
* child
= this ;
2401 wxWindow
* parent
= child
->GetParent() ;
2406 // we have to find a better clipping algorithm here, in order not to clip things
2407 // positioned like status and toolbar
2408 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2410 size
= parent
->GetSize() ;
2415 size
= parent
->GetClientSize() ;
2416 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2420 parent
->MacWindowToRootWindow( &x
, &y
) ;
2421 MacRootWindowToWindow( &x
, &y
) ;
2423 SetRectRgn( tempRgn
,
2424 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2425 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2426 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2428 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2429 if ( parent
->IsTopLevel() )
2432 parent
= child
->GetParent() ;
2437 wxRegion vis
= visRgn
;
2438 DisposeRgn( visRgn
) ;
2439 DisposeRgn( tempRgn
) ;
2444 This function must not change the updatergn !
2446 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2448 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2449 bool handled
= false ;
2451 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2453 RgnHandle newupdate
= NewRgn() ;
2454 wxSize point
= GetClientSize() ;
2455 wxPoint origin
= GetClientAreaOrigin() ;
2456 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2457 SectRgn( newupdate
, updatergn
, newupdate
) ;
2458 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2459 m_updateRegion
= newupdate
;
2460 DisposeRgn( newupdate
) ;
2463 if ( !EmptyRgn(updatergn
) )
2465 wxWindowDC
dc(this);
2466 if (!EmptyRgn(updatergn
))
2467 dc
.SetClippingRegion(wxRegion(updatergn
));
2469 wxEraseEvent
eevent( GetId(), &dc
);
2470 eevent
.SetEventObject( this );
2471 GetEventHandler()->ProcessEvent( eevent
);
2473 if ( !m_updateRegion
.Empty() )
2475 // paint the window itself
2477 event
.m_timeStamp
= time
;
2478 event
.SetEventObject(this);
2479 handled
= GetEventHandler()->ProcessEvent(event
);
2481 // paint custom borders
2482 wxNcPaintEvent
eventNc( GetId() );
2483 eventNc
.SetEventObject( this );
2484 GetEventHandler()->ProcessEvent( eventNc
);
2490 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2492 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2493 // updatergn is always already clipped to our boundaries
2494 // if we are in compositing mode then it is in relative to the upper left of the control
2495 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2496 // of the toplevel window
2497 // it is in window coordinates, not in client coordinates
2499 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2500 RgnHandle ownUpdateRgn
= NewRgn() ;
2501 CopyRgn( updatergn
, ownUpdateRgn
) ;
2503 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2506 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2507 RgnHandle controlRgn
= NewRgn();
2508 RectRgn( controlRgn
, &bounds
);
2509 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2510 // the window update region
2511 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2512 DisposeRgn( controlRgn
);
2514 //KO: convert ownUpdateRgn to local coordinates
2515 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2518 MacDoRedraw( ownUpdateRgn
, time
) ;
2519 DisposeRgn( ownUpdateRgn
) ;
2523 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2525 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2529 if ( iter
->IsTopLevel() )
2530 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2532 iter
= iter
->GetParent() ;
2534 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2538 void wxWindowMac::MacCreateScrollBars( long style
)
2540 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2542 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2543 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2545 GetClientSize( &width
, &height
) ;
2547 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2548 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2549 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2550 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2552 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2553 vSize
, wxVERTICAL
);
2555 if ( style
& wxVSCROLL
)
2561 m_vScrollBar
->Show(false) ;
2563 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2564 hSize
, wxHORIZONTAL
);
2565 if ( style
& wxHSCROLL
)
2570 m_hScrollBar
->Show(false) ;
2573 // because the create does not take into account the client area origin
2574 MacRepositionScrollBars() ; // we might have a real position shift
2577 void wxWindowMac::MacRepositionScrollBars()
2579 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2580 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2582 // get real client area
2586 GetSize( &width
, &height
) ;
2588 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2589 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2591 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2592 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2593 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2594 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2600 GetSize( &w
, &h
) ;
2602 MacClientToRootWindow( &x
, &y
) ;
2603 MacClientToRootWindow( &w
, &h
) ;
2605 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2607 int totW
= 10000 , totH
= 10000;
2610 if ( iter
->IsTopLevel() )
2612 iter
->GetSize( &totW
, &totH
) ;
2616 iter
= iter
->GetParent() ;
2644 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2648 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2652 bool wxWindowMac::AcceptsFocus() const
2654 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2657 void wxWindowMac::MacSuperChangedPosition()
2659 // only window-absolute structures have to be moved i.e. controls
2661 wxWindowListNode
*node
= GetChildren().GetFirst();
2664 wxWindowMac
*child
= node
->GetData();
2665 child
->MacSuperChangedPosition() ;
2666 node
= node
->GetNext();
2670 void wxWindowMac::MacTopLevelWindowChangedPosition()
2672 // only screen-absolute structures have to be moved i.e. glcanvas
2674 wxWindowListNode
*node
= GetChildren().GetFirst();
2677 wxWindowMac
*child
= node
->GetData();
2678 child
->MacTopLevelWindowChangedPosition() ;
2679 node
= node
->GetNext();
2683 long wxWindowMac::MacGetLeftBorderSize( ) const
2688 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2691 #if wxMAC_USE_THEME_BORDER
2692 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2696 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2699 #if wxMAC_USE_THEME_BORDER
2700 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2704 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2711 long wxWindowMac::MacGetRightBorderSize( ) const
2713 // they are all symmetric in mac themes
2714 return MacGetLeftBorderSize() ;
2717 long wxWindowMac::MacGetTopBorderSize( ) const
2719 // they are all symmetric in mac themes
2720 return MacGetLeftBorderSize() ;
2723 long wxWindowMac::MacGetBottomBorderSize( ) const
2725 // they are all symmetric in mac themes
2726 return MacGetLeftBorderSize() ;
2729 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2731 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2734 // Find the wxWindowMac at the current mouse position, returning the mouse
2736 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2738 pt
= wxGetMousePosition();
2739 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2743 // Get the current mouse position.
2744 wxPoint
wxGetMousePosition()
2747 wxGetMousePosition(& x
, & y
);
2748 return wxPoint(x
, y
);
2751 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2753 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2755 // copied from wxGTK : CS
2756 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2759 // (a) it's a command event and so is propagated to the parent
2760 // (b) under MSW it can be generated from kbd too
2761 // (c) it uses screen coords (because of (a))
2762 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2764 this->ClientToScreen(event
.GetPosition()));
2765 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2768 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2774 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2776 // OS Needs it in tlw content area coordinates
2777 MacClientToRootWindow( &x
, &y
) ;
2781 // OS Needs it in window not client coordinates
2782 wxPoint origin
= GetClientAreaOrigin() ;
2787 SInt16 controlpart
;
2792 short modifiers
= 0;
2794 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2795 modifiers
|= btnState
;
2797 if ( event
.m_shiftDown
)
2798 modifiers
|= shiftKey
;
2800 if ( event
.m_controlDown
)
2801 modifiers
|= controlKey
;
2803 if ( event
.m_altDown
)
2804 modifiers
|= optionKey
;
2806 if ( event
.m_metaDown
)
2807 modifiers
|= cmdKey
;
2809 bool handled
= false ;
2811 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2813 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2814 wxTheApp
->s_lastMouseDown
= 0 ;
2815 if ( controlpart
!= kControlNoPart
)
2817 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2830 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2832 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2835 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2839 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2840 Rect bounds
= { y
, x
, y
+h
, x
+w
};