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 m_backgroundTransparent
= FALSE
;
431 // as all windows are created with WS_VISIBLE style...
434 m_hScrollBar
= NULL
;
435 m_vScrollBar
= NULL
;
436 m_macBackgroundBrush
= wxNullBrush
;
438 m_macControl
= NULL
;
440 m_macIsUserPane
= TRUE
;
442 // make sure all proc ptrs are available
444 if ( gControlUserPaneDrawUPP
== NULL
)
446 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
447 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
448 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
449 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
450 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
451 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
452 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
453 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
455 if ( wxMacLiveScrollbarActionUPP
== NULL
)
457 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
460 if ( wxMacSetupControlBackgroundUPP
== NULL
)
462 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
465 // we need a valid font for the encodings
466 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
470 wxWindowMac::~wxWindowMac()
474 m_isBeingDeleted
= TRUE
;
476 #ifndef __WXUNIVERSAL__
477 // VS: make sure there's no wxFrame with last focus set to us:
478 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
480 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
483 if ( frame
->GetLastFocus() == this )
485 frame
->SetLastFocus((wxWindow
*)NULL
);
490 #endif // __WXUNIVERSAL__
492 // wxRemoveMacControlAssociation( this ) ;
493 // If we delete an item, we should initialize the parent panel,
494 // because it could now be invalid.
495 wxWindow
*parent
= GetParent() ;
498 if (parent
->GetDefaultItem() == (wxButton
*) this)
499 parent
->SetDefaultItem(NULL
);
501 if ( (ControlRef
) m_macControl
)
503 // in case the callback might be called during destruction
504 wxRemoveMacControlAssociation( this) ;
505 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
506 ::DisposeControl( (ControlRef
) m_macControl
) ;
507 m_macControl
= NULL
;
510 if ( g_MacLastWindow
== this )
512 g_MacLastWindow
= NULL
;
515 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
518 if ( frame
->GetLastFocus() == this )
519 frame
->SetLastFocus( NULL
) ;
522 if ( gFocusWindow
== this )
524 gFocusWindow
= NULL
;
529 // delete our drop target if we've got one
530 #if wxUSE_DRAG_AND_DROP
531 if ( m_dropTarget
!= NULL
)
536 #endif // wxUSE_DRAG_AND_DROP
541 void wxWindowMac::MacInstallEventHandler()
543 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
544 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
545 GetEventTypeCount(eventList
), eventList
, this,
546 (EventHandlerRef
*)&m_macControlEventHandler
);
551 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
555 const wxString
& name
)
557 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
559 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
562 parent
->AddChild(this);
564 m_windowVariant
= parent
->GetWindowVariant() ;
566 if ( m_macIsUserPane
)
568 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
570 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
571 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
573 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
575 MacPostControlCreate(pos
,size
) ;
576 #if !TARGET_API_MAC_OSX
577 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
578 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
579 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
580 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
581 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
582 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
583 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
584 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
585 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
586 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
587 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
588 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
589 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
590 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
591 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
592 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
595 #ifndef __WXUNIVERSAL__
596 // Don't give scrollbars to wxControls unless they ask for them
597 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
598 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
600 MacCreateScrollBars( style
) ;
604 wxWindowCreateEvent
event(this);
605 GetEventHandler()->AddPendingEvent(event
);
610 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
612 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
614 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
616 MacInstallEventHandler();
618 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
619 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
620 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
622 // adjust font, controlsize etc
623 DoSetWindowVariant( m_windowVariant
) ;
625 #if !TARGET_API_MAC_OSX
626 // eventually we can fix some clipping issues be reactivating this hook
627 //if ( m_macIsUserPane )
628 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
631 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
633 wxSize new_size
= size
;
634 if (!m_macIsUserPane
)
636 wxSize
best_size( DoGetBestSize() );
639 new_size
.x
= best_size
.x
;
642 new_size
.y
= best_size
.y
;
644 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
647 SetCursor( *wxSTANDARD_CURSOR
) ;
651 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
653 // Don't assert, in case we set the window variant before
654 // the window is created
655 // wxASSERT( m_macControl != NULL ) ;
657 m_windowVariant
= variant
;
663 ThemeFontID themeFont
= kThemeSystemFont
;
665 // we will get that from the settings later
666 // and make this NORMAL later, but first
667 // we have a few calculations that we must fix
671 case wxWINDOW_VARIANT_NORMAL
:
672 size
= kControlSizeNormal
;
673 themeFont
= kThemeSystemFont
;
675 case wxWINDOW_VARIANT_SMALL
:
676 size
= kControlSizeSmall
;
677 themeFont
= kThemeSmallSystemFont
;
679 case wxWINDOW_VARIANT_MINI
:
680 if (UMAGetSystemVersion() >= 0x1030 )
682 // not always defined in the headers
688 size
= kControlSizeSmall
;
689 themeFont
= kThemeSmallSystemFont
;
692 case wxWINDOW_VARIANT_LARGE
:
693 size
= kControlSizeLarge
;
694 themeFont
= kThemeSystemFont
;
697 wxFAIL_MSG(_T("unexpected window variant"));
700 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
703 font
.MacCreateThemeFont( themeFont
) ;
707 void wxWindowMac::MacUpdateControlFont()
709 ControlFontStyleRec fontStyle
;
710 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
712 switch( m_font
.MacGetThemeFontID() )
714 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
715 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
716 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
717 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
719 fontStyle
.flags
= kControlUseFontMask
;
723 fontStyle
.font
= m_font
.MacGetFontNum() ;
724 fontStyle
.style
= m_font
.MacGetFontStyle() ;
725 fontStyle
.size
= m_font
.MacGetFontSize() ;
726 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
729 fontStyle
.just
= teJustLeft
;
730 fontStyle
.flags
|= kControlUseJustMask
;
731 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
732 fontStyle
.just
= teJustCenter
;
733 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
734 fontStyle
.just
= teJustRight
;
737 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
738 fontStyle
.flags
|= kControlUseForeColorMask
;
740 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
744 bool wxWindowMac::SetFont(const wxFont
& font
)
746 bool retval
= !wxWindowBase::SetFont( font
) ;
748 MacUpdateControlFont() ;
753 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
755 if ( !wxWindowBase::SetForegroundColour(col
) )
758 MacUpdateControlFont() ;
763 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
765 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
769 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
771 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
773 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
775 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
779 brush
.SetColour( col
) ;
781 MacSetBackgroundBrush( brush
) ;
783 MacUpdateControlFont() ;
789 bool wxWindowMac::MacCanFocus() const
791 wxASSERT( m_macControl
!= NULL
) ;
797 void wxWindowMac::SetFocus()
799 if ( gFocusWindow
== this )
802 if ( AcceptsFocus() )
808 if ( gFocusWindow
->m_caret
)
810 gFocusWindow
->m_caret
->OnKillFocus();
812 #endif // wxUSE_CARET
813 #ifndef __WXUNIVERSAL__
814 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
815 // TODO we must use the built-in focusing
816 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
818 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
819 control
->MacRedrawControl() ;
822 // Without testing the window id, for some reason
823 // a kill focus event can still be sent to
824 // the control just being focussed.
825 int thisId
= this->m_windowId
;
826 int gFocusWindowId
= gFocusWindow
->m_windowId
;
827 if (gFocusWindowId
!= thisId
)
829 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
830 event
.SetEventObject(gFocusWindow
);
831 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
834 gFocusWindow
= this ;
840 m_caret
->OnSetFocus();
842 #endif // wxUSE_CARET
843 // panel wants to track the window which was the last to have focus in it
844 wxChildFocusEvent
eventFocus(this);
845 GetEventHandler()->ProcessEvent(eventFocus
);
847 #ifndef __WXUNIVERSAL__
848 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
849 if ( control
&& control
->GetHandle() )
851 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
854 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
855 event
.SetEventObject(this);
856 GetEventHandler()->ProcessEvent(event
) ;
862 void wxWindowMac::DoCaptureMouse()
864 wxTheApp
->s_captureWindow
= this ;
867 wxWindow
* wxWindowBase::GetCapture()
869 return wxTheApp
->s_captureWindow
;
872 void wxWindowMac::DoReleaseMouse()
874 wxTheApp
->s_captureWindow
= NULL
;
877 #if wxUSE_DRAG_AND_DROP
879 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
881 if ( m_dropTarget
!= 0 ) {
885 m_dropTarget
= pDropTarget
;
886 if ( m_dropTarget
!= 0 )
894 // Old style file-manager drag&drop
895 void wxWindowMac::DragAcceptFiles(bool accept
)
900 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
901 int& w
, int& h
) const
904 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
909 w
= bounds
.right
- bounds
.left
;
910 h
= bounds
.bottom
- bounds
.top
;
912 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
915 Point tlworigin
= { 0 , 0 } ;
917 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
918 ::LocalToGlobal( &tlworigin
) ;
926 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
929 int& w
, int& h
, bool adjustOrigin
) const
933 // todo the default calls may be used as soon as PostCreateControl Is moved here
934 w
= size
.x
; // WidthDefault( size.x );
935 h
= size
.y
; // HeightDefault( size.y ) ;
936 #if !TARGET_API_MAC_OSX
937 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
940 AdjustForParentClientOrigin( x
, y
) ;
945 void wxWindowMac::DoGetSize(int *x
, int *y
) const
947 #if TARGET_API_MAC_OSX
948 int x1
, y1
, w1
,h1
;
949 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
955 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
956 if(x
) *x
= bounds
.right
- bounds
.left
;
957 if(y
) *y
= bounds
.bottom
- bounds
.top
;
961 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
963 #if TARGET_API_MAC_OSX
964 int x1
, y1
, w1
,h1
;
965 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
968 wxWindow
*parent
= GetParent();
971 wxPoint
pt(parent
->GetClientAreaOrigin());
980 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
981 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
983 int xx
= bounds
.left
;
984 int yy
= bounds
.top
;
986 if ( !GetParent()->IsTopLevel() )
988 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
994 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1003 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1005 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1007 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1010 Point localwhere
= {0,0} ;
1012 if(x
) localwhere
.h
= * x
;
1013 if(y
) localwhere
.v
= * y
;
1015 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1016 ::GlobalToLocal( &localwhere
) ;
1017 if(x
) *x
= localwhere
.h
;
1018 if(y
) *y
= localwhere
.v
;
1021 MacRootWindowToWindow( x
, y
) ;
1023 wxPoint origin
= GetClientAreaOrigin() ;
1024 if(x
) *x
-= origin
.x
;
1025 if(y
) *y
-= origin
.y
;
1028 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1030 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1031 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1033 wxPoint origin
= GetClientAreaOrigin() ;
1034 if(x
) *x
+= origin
.x
;
1035 if(y
) *y
+= origin
.y
;
1037 MacWindowToRootWindow( x
, y
) ;
1040 Point localwhere
= { 0,0 };
1041 if(x
) localwhere
.h
= * x
;
1042 if(y
) localwhere
.v
= * y
;
1044 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1045 ::LocalToGlobal( &localwhere
) ;
1046 if(x
) *x
= localwhere
.h
;
1047 if(y
) *y
= localwhere
.v
;
1051 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1053 wxPoint origin
= GetClientAreaOrigin() ;
1054 if(x
) *x
+= origin
.x
;
1055 if(y
) *y
+= origin
.y
;
1057 MacWindowToRootWindow( x
, y
) ;
1060 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1062 MacRootWindowToWindow( x
, y
) ;
1064 wxPoint origin
= GetClientAreaOrigin() ;
1065 if(x
) *x
-= origin
.x
;
1066 if(y
) *y
-= origin
.y
;
1069 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1071 #if TARGET_API_MAC_OSX
1073 if ( x
) pt
.x
= *x
;
1074 if ( y
) pt
.y
= *y
;
1076 if ( !IsTopLevel() )
1077 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1079 if ( x
) *x
= (int) pt
.x
;
1080 if ( y
) *y
= (int) pt
.y
;
1082 if ( !IsTopLevel() )
1085 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1086 if(x
) *x
+= bounds
.left
;
1087 if(y
) *y
+= bounds
.top
;
1092 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1097 MacWindowToRootWindow( &x1
, &y1
) ;
1102 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1104 #if TARGET_API_MAC_OSX
1106 if ( x
) pt
.x
= *x
;
1107 if ( y
) pt
.y
= *y
;
1109 if ( !IsTopLevel() )
1110 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1112 if ( x
) *x
= (int) pt
.x
;
1113 if ( y
) *y
= (int) pt
.y
;
1115 if ( !IsTopLevel() )
1118 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1119 if(x
) *x
-= bounds
.left
;
1120 if(y
) *y
-= bounds
.top
;
1125 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1130 MacRootWindowToWindow( &x1
, &y1
) ;
1135 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1137 RgnHandle rgn
= NewRgn() ;
1139 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1141 GetRegionBounds( rgn
, &content
) ;
1146 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1149 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1150 #if !TARGET_API_MAC_OSX
1151 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1153 left
= content
.left
- structure
.left
;
1154 top
= content
.top
- structure
.top
;
1155 right
= structure
.right
- content
.right
;
1156 bottom
= structure
.bottom
- content
.bottom
;
1159 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1161 wxSize sizeTotal
= size
;
1163 RgnHandle rgn
= NewRgn() ;
1167 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1169 GetRegionBounds( rgn
, &content
) ;
1174 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1177 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1178 #if !TARGET_API_MAC_OSX
1179 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1182 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1183 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1185 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1186 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1192 // Get size *available for subwindows* i.e. excluding menu bar etc.
1193 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1197 RgnHandle rgn
= NewRgn() ;
1199 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1201 GetRegionBounds( rgn
, &content
) ;
1206 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1208 #if !TARGET_API_MAC_OSX
1210 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1211 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1213 ww
= content
.right
- content
.left
;
1214 hh
= content
.bottom
- content
.top
;
1216 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1217 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1219 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1225 GetSize( &w
, &h
) ;
1227 MacClientToRootWindow( &x1
, &y1
) ;
1228 MacClientToRootWindow( &w
, &h
) ;
1230 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1232 int totW
= 10000 , totH
= 10000;
1235 if ( iter
->IsTopLevel() )
1237 iter
->GetSize( &totW
, &totH
) ;
1241 iter
= iter
->GetParent() ;
1244 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1246 hh
-= MAC_SCROLLBAR_SIZE
;
1252 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1254 ww
-= MAC_SCROLLBAR_SIZE
;
1266 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1268 if (m_cursor
== cursor
)
1271 if (wxNullCursor
== cursor
)
1273 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1278 if ( ! wxWindowBase::SetCursor( cursor
) )
1282 wxASSERT_MSG( m_cursor
.Ok(),
1283 wxT("cursor must be valid after call to the base version"));
1287 TODO why do we have to use current coordinates ?
1290 wxWindowMac *mouseWin ;
1293 // Change the cursor NOW if we're within the correct window
1296 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1298 if ( mouseWin == this && !wxIsBusy() )
1300 m_cursor.MacInstall() ;
1306 m_cursor
.MacInstall() ;
1313 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1315 menu
->SetInvokingWindow(this);
1317 ClientToScreen( &x
, &y
) ;
1319 menu
->MacBeforeDisplay( true ) ;
1320 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1321 if ( HiWord(menuResult
) != 0 )
1324 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1325 wxMenuItem
* item
= NULL
;
1327 item
= menu
->FindItem(id
, &realmenu
) ;
1328 if (item
->IsCheckable())
1330 item
->Check( !item
->IsChecked() ) ;
1332 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1334 menu
->MacAfterDisplay( true ) ;
1336 menu
->SetInvokingWindow(NULL
);
1342 // ----------------------------------------------------------------------------
1344 // ----------------------------------------------------------------------------
1348 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1350 wxWindowBase::DoSetToolTip(tooltip
);
1353 m_tooltip
->SetWindow(this);
1356 #endif // wxUSE_TOOLTIPS
1358 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1360 int former_x
, former_y
, former_w
, former_h
;
1361 #if !TARGET_API_MAC_OSX
1362 DoGetPosition( &former_x
, &former_y
) ;
1363 DoGetSize( &former_w
, &former_h
) ;
1365 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1368 int actualWidth
= width
;
1369 int actualHeight
= height
;
1373 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1374 actualWidth
= m_minWidth
;
1375 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1376 actualHeight
= m_minHeight
;
1377 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1378 actualWidth
= m_maxWidth
;
1379 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1380 actualHeight
= m_maxHeight
;
1382 bool doMove
= false ;
1383 bool doResize
= false ;
1385 if ( actualX
!= former_x
|| actualY
!= former_y
)
1389 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1394 if ( doMove
|| doResize
)
1396 // we don't adjust twice for the origin
1397 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1398 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1399 #if TARGET_API_MAC_OSX
1400 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1402 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1403 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1404 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1406 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1408 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1410 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1412 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1414 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1416 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1418 MacRepositionScrollBars() ;
1421 wxPoint
point(actualX
,actualY
);
1422 wxMoveEvent
event(point
, m_windowId
);
1423 event
.SetEventObject(this);
1424 GetEventHandler()->ProcessEvent(event
) ;
1428 MacRepositionScrollBars() ;
1429 wxSize
size(actualWidth
, actualHeight
);
1430 wxSizeEvent
event(size
, m_windowId
);
1431 event
.SetEventObject(this);
1432 GetEventHandler()->ProcessEvent(event
);
1438 wxSize
wxWindowMac::DoGetBestSize() const
1440 if ( m_macIsUserPane
|| IsTopLevel() )
1441 return wxWindowBase::DoGetBestSize() ;
1443 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1444 short baselineoffset
;
1445 int bestWidth
, bestHeight
;
1446 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1448 if ( EmptyRect( &bestsize
) )
1451 bestsize
.left
= bestsize
.top
= 0 ;
1452 bestsize
.right
= 16 ;
1453 bestsize
.bottom
= 16 ;
1454 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1456 bestsize
.bottom
= 16 ;
1458 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1460 bestsize
.bottom
= 24 ;
1464 // return wxWindowBase::DoGetBestSize() ;
1468 bestWidth
= bestsize
.right
- bestsize
.left
;
1469 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1470 if ( bestHeight
< 10 )
1473 return wxSize(bestWidth
, bestHeight
);
1474 // return wxWindowBase::DoGetBestSize() ;
1478 // set the size of the window: if the dimensions are positive, just use them,
1479 // but if any of them is equal to -1, it means that we must find the value for
1480 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1481 // which case -1 is a valid value for x and y)
1483 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1484 // the width/height to best suit our contents, otherwise we reuse the current
1486 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1488 // get the current size and position...
1489 int currentX
, currentY
;
1490 GetPosition(¤tX
, ¤tY
);
1492 int currentW
,currentH
;
1493 GetSize(¤tW
, ¤tH
);
1495 // ... and don't do anything (avoiding flicker) if it's already ok
1496 if ( x
== currentX
&& y
== currentY
&&
1497 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1500 MacRepositionScrollBars() ; // we might have a real position shift
1504 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1506 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1509 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1511 wxSize
size(-1, -1);
1514 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1516 size
= DoGetBestSize();
1521 // just take the current one
1528 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1532 size
= DoGetBestSize();
1534 //else: already called DoGetBestSize() above
1540 // just take the current one
1545 DoMoveWindow(x
, y
, width
, height
);
1549 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1551 RgnHandle rgn
= NewRgn() ;
1553 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1554 GetRegionBounds( rgn
, &content
) ;
1556 #if !TARGET_API_MAC_OSX
1558 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1559 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1562 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1565 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1567 if ( clientheight
!= -1 || clientheight
!= -1 )
1569 int currentclientwidth
, currentclientheight
;
1570 int currentwidth
, currentheight
;
1572 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1573 GetSize( ¤twidth
, ¤theight
) ;
1575 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1576 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1580 void wxWindowMac::SetTitle(const wxString
& title
)
1582 m_label
= wxStripMenuCodes(title
) ;
1586 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1591 wxString
wxWindowMac::GetTitle() const
1596 bool wxWindowMac::Show(bool show
)
1598 if ( !wxWindowBase::Show(show
) )
1601 // TODO use visibilityChanged Carbon Event for OSX
1602 bool former
= MacIsReallyShown() ;
1604 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1605 if ( former
!= MacIsReallyShown() )
1606 MacPropagateVisibilityChanged() ;
1610 bool wxWindowMac::Enable(bool enable
)
1612 wxASSERT( m_macControl
!= NULL
) ;
1613 if ( !wxWindowBase::Enable(enable
) )
1616 bool former
= MacIsReallyEnabled() ;
1618 EnableControl( (ControlRef
) m_macControl
) ;
1620 DisableControl( (ControlRef
) m_macControl
) ;
1622 if ( former
!= MacIsReallyEnabled() )
1623 MacPropagateEnabledStateChanged() ;
1628 // status change propagations (will be not necessary for OSX later )
1631 void wxWindowMac::MacPropagateVisibilityChanged()
1633 #if !TARGET_API_MAC_OSX
1634 MacVisibilityChanged() ;
1636 wxWindowListNode
*node
= GetChildren().GetFirst();
1639 wxWindowMac
*child
= node
->GetData();
1640 if ( child
->IsShown() )
1641 child
->MacPropagateVisibilityChanged( ) ;
1642 node
= node
->GetNext();
1647 void wxWindowMac::MacPropagateEnabledStateChanged( )
1649 #if !TARGET_API_MAC_OSX
1650 MacEnabledStateChanged() ;
1652 wxWindowListNode
*node
= GetChildren().GetFirst();
1655 wxWindowMac
*child
= node
->GetData();
1656 if ( child
->IsEnabled() )
1657 child
->MacPropagateEnabledStateChanged() ;
1658 node
= node
->GetNext();
1663 void wxWindowMac::MacPropagateHiliteChanged( )
1665 #if !TARGET_API_MAC_OSX
1666 MacHiliteChanged() ;
1668 wxWindowListNode
*node
= GetChildren().GetFirst();
1671 wxWindowMac
*child
= node
->GetData();
1672 // if ( child->IsEnabled() )
1673 child
->MacPropagateHiliteChanged() ;
1674 node
= node
->GetNext();
1680 // status change notifications
1683 void wxWindowMac::MacVisibilityChanged()
1687 void wxWindowMac::MacHiliteChanged()
1691 void wxWindowMac::MacEnabledStateChanged()
1696 // status queries on the inherited window's state
1699 bool wxWindowMac::MacIsReallyShown()
1701 // only under OSX the visibility of the TLW is taken into account
1702 #if TARGET_API_MAC_OSX
1703 return IsControlVisible( (ControlRef
) m_macControl
) ;
1705 wxWindow
* win
= this ;
1706 while( win
->IsShown() )
1708 if ( win
->IsTopLevel() )
1711 win
= win
->GetParent() ;
1720 bool wxWindowMac::MacIsReallyEnabled()
1722 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1725 bool wxWindowMac::MacIsReallyHilited()
1727 return IsControlActive( (ControlRef
) m_macControl
) ;
1734 int wxWindowMac::GetCharHeight() const
1736 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1737 return dc
.GetCharHeight() ;
1740 int wxWindowMac::GetCharWidth() const
1742 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1743 return dc
.GetCharWidth() ;
1746 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1747 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1749 const wxFont
*fontToUse
= theFont
;
1751 fontToUse
= &m_font
;
1753 wxClientDC
dc( (wxWindowMac
*) this ) ;
1755 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1756 if ( externalLeading
)
1757 *externalLeading
= le
;
1767 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1768 * we always intersect with the entire window, not only with the client area
1771 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1773 #if TARGET_API_MAC_OSX
1775 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1778 RgnHandle update
= NewRgn() ;
1779 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1780 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1781 wxPoint origin
= GetClientAreaOrigin() ;
1782 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1783 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1787 RgnHandle updateRgn = NewRgn() ;
1790 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1794 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1795 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1797 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1798 DisposeRgn(updateRgn) ;
1800 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1802 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1803 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1806 if ( MacGetTopLevelWindow() == NULL )
1809 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1812 wxPoint client = GetClientAreaOrigin();
1815 int x2 = m_width - client.x;
1816 int y2 = m_height - client.y;
1818 if (IsKindOf( CLASSINFO(wxButton)))
1820 // buttons have an "aura"
1827 Rect clientrect = { y1, x1, y2, x2 };
1831 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1832 SectRect( &clientrect , &r , &clientrect ) ;
1835 if ( !EmptyRect( &clientrect ) )
1837 int top = 0 , left = 0 ;
1839 MacClientToRootWindow( &left , &top ) ;
1840 OffsetRect( &clientrect , left , top ) ;
1842 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1848 void wxWindowMac::Freeze()
1850 #if TARGET_API_MAC_OSX
1851 if ( !m_frozenness
++ )
1853 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1858 #if TARGET_API_MAC_OSX
1859 static void InvalidateControlAndChildren( HIViewRef control
)
1861 HIViewSetNeedsDisplay( control
, true ) ;
1862 UInt16 childrenCount
= 0 ;
1863 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1864 if ( err
== errControlIsNotEmbedder
)
1866 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1868 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1871 err
= GetIndexedSubControl( control
, i
, & child
) ;
1872 if ( err
== errControlIsNotEmbedder
)
1874 InvalidateControlAndChildren( child
) ;
1879 void wxWindowMac::Thaw()
1881 #if TARGET_API_MAC_OSX
1882 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1884 if ( !--m_frozenness
)
1886 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
1887 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
1888 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
1893 void wxWindowMac::MacRedrawControl()
1896 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1898 #if TARGET_API_MAC_CARBON
1901 wxClientDC dc(this) ;
1902 wxMacPortSetter helper(&dc) ;
1903 wxMacWindowClipper clipper(this) ;
1904 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1905 UMADrawControl( (ControlRef) m_macControl ) ;
1912 void wxWindowMac::OnPaint(wxPaintEvent& event)
1914 // why don't we skip that here ?
1918 wxWindowMac
*wxGetActiveWindow()
1920 // actually this is a windows-only concept
1924 // Coordinates relative to the window
1925 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1927 // We really don't move the mouse programmatically under Mac.
1930 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1932 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1937 event
.GetDC()->Clear() ;
1940 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1942 wxWindowDC
dc(this) ;
1943 wxMacPortSetter
helper(&dc
) ;
1945 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1948 int wxWindowMac::GetScrollPos(int orient
) const
1950 if ( orient
== wxHORIZONTAL
)
1953 return m_hScrollBar
->GetThumbPosition() ;
1958 return m_vScrollBar
->GetThumbPosition() ;
1963 // This now returns the whole range, not just the number
1964 // of positions that we can scroll.
1965 int wxWindowMac::GetScrollRange(int orient
) const
1967 if ( orient
== wxHORIZONTAL
)
1970 return m_hScrollBar
->GetRange() ;
1975 return m_vScrollBar
->GetRange() ;
1980 int wxWindowMac::GetScrollThumb(int orient
) const
1982 if ( orient
== wxHORIZONTAL
)
1985 return m_hScrollBar
->GetThumbSize() ;
1990 return m_vScrollBar
->GetThumbSize() ;
1995 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1997 if ( orient
== wxHORIZONTAL
)
2000 m_hScrollBar
->SetThumbPosition( pos
) ;
2005 m_vScrollBar
->SetThumbPosition( pos
) ;
2009 void wxWindowMac::MacPaintBorders( int left
, int top
)
2015 wxGetOsVersion( &major
, &minor
);
2017 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2018 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2020 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2021 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2022 // OS X has lighter border edges than classic:
2025 darkShadow
.red
= 0x8E8E;
2026 darkShadow
.green
= 0x8E8E;
2027 darkShadow
.blue
= 0x8E8E;
2028 lightShadow
.red
= 0xBDBD;
2029 lightShadow
.green
= 0xBDBD;
2030 lightShadow
.blue
= 0xBDBD;
2036 GetSize( &w
, &h
) ;
2037 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2039 #if wxMAC_USE_THEME_BORDER
2040 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2043 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2044 InsetRect( &rect , border , border );
2045 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2048 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2050 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2051 RGBForeColor( &face
);
2052 MoveTo( left
+ 0 , top
+ h
- 2 );
2053 LineTo( left
+ 0 , top
+ 0 );
2054 LineTo( left
+ w
- 2 , top
+ 0 );
2056 MoveTo( left
+ 2 , top
+ h
- 3 );
2057 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2058 LineTo( left
+ w
- 3 , top
+ 2 );
2060 RGBForeColor( sunken
? &face
: &darkShadow
);
2061 MoveTo( left
+ 0 , top
+ h
- 1 );
2062 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2063 LineTo( left
+ w
- 1 , top
+ 0 );
2065 RGBForeColor( sunken
? &lightShadow
: &white
);
2066 MoveTo( left
+ 1 , top
+ h
- 3 );
2067 LineTo( left
+ 1, top
+ 1 );
2068 LineTo( left
+ w
- 3 , top
+ 1 );
2070 RGBForeColor( sunken
? &white
: &lightShadow
);
2071 MoveTo( left
+ 1 , top
+ h
- 2 );
2072 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2073 LineTo( left
+ w
- 2 , top
+ 1 );
2075 RGBForeColor( sunken
? &darkShadow
: &face
);
2076 MoveTo( left
+ 2 , top
+ h
- 4 );
2077 LineTo( left
+ 2 , top
+ 2 );
2078 LineTo( left
+ w
- 4 , top
+ 2 );
2081 else if (HasFlag(wxSIMPLE_BORDER
))
2083 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2084 RGBForeColor( &darkShadow
) ;
2085 FrameRect( &rect
) ;
2089 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2091 if ( child
== m_hScrollBar
)
2092 m_hScrollBar
= NULL
;
2093 if ( child
== m_vScrollBar
)
2094 m_vScrollBar
= NULL
;
2096 wxWindowBase::RemoveChild( child
) ;
2099 // New function that will replace some of the above.
2100 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2101 int range
, bool refresh
)
2103 if ( orient
== wxHORIZONTAL
)
2107 if ( range
== 0 || thumbVisible
>= range
)
2109 if ( m_hScrollBar
->IsShown() )
2110 m_hScrollBar
->Show(false) ;
2114 if ( !m_hScrollBar
->IsShown() )
2115 m_hScrollBar
->Show(true) ;
2116 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2124 if ( range
== 0 || thumbVisible
>= range
)
2126 if ( m_vScrollBar
->IsShown() )
2127 m_vScrollBar
->Show(false) ;
2131 if ( !m_vScrollBar
->IsShown() )
2132 m_vScrollBar
->Show(true) ;
2133 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2137 MacRepositionScrollBars() ;
2140 // Does a physical scroll
2141 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2143 if( dx
== 0 && dy
==0 )
2148 wxClientDC
dc(this) ;
2149 wxMacPortSetter
helper(&dc
) ;
2151 int width
, height
;
2152 GetClientSize( &width
, &height
) ;
2159 // TODO take out the boundaries
2160 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2162 RgnHandle updateRgn
= NewRgn() ;
2165 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2166 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2167 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2169 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2171 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2172 // but it seems the update only refreshes the background of the control, rather than calling
2173 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2174 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2177 // we also have to scroll the update rgn in this rectangle
2178 // in order not to loose updates
2180 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2181 RgnHandle formerUpdateRgn
= NewRgn() ;
2182 RgnHandle scrollRgn
= NewRgn() ;
2183 RectRgn( scrollRgn
, &scrollrect
) ;
2184 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2186 LocalToGlobal( &pt
) ;
2187 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2188 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2189 if ( !EmptyRgn( formerUpdateRgn
) )
2191 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2192 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2193 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2195 InvalWindowRgn(rootWindow
, updateRgn
) ;
2196 DisposeRgn( updateRgn
) ;
2197 DisposeRgn( formerUpdateRgn
) ;
2198 DisposeRgn( scrollRgn
) ;
2202 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2204 wxWindowMac
*child
= node
->GetData();
2205 if (child
== m_vScrollBar
) continue;
2206 if (child
== m_hScrollBar
) continue;
2207 if (child
->IsTopLevel()) continue;
2210 child
->GetPosition( &x
, &y
);
2212 child
->GetSize( &w
, &h
);
2216 if (rect
->Intersects(rc
))
2217 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2221 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2225 // TODO remove, was moved higher up Update() ;
2229 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2231 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2233 wxScrollWinEvent wevent
;
2234 wevent
.SetPosition(event
.GetPosition());
2235 wevent
.SetOrientation(event
.GetOrientation());
2236 wevent
.m_eventObject
= this;
2238 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2239 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2240 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2241 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2242 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2243 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2244 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2245 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2246 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2247 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2248 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2249 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2250 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2251 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2252 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2253 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2255 GetEventHandler()->ProcessEvent(wevent
);
2259 // Get the window with the focus
2260 wxWindowMac
*wxWindowBase::FindFocus()
2262 return gFocusWindow
;
2265 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2267 // panel wants to track the window which was the last to have focus in it,
2268 // so we want to set ourselves as the window which last had focus
2270 // notice that it's also important to do it upwards the tree becaus
2271 // otherwise when the top level panel gets focus, it won't set it back to
2272 // us, but to some other sibling
2274 // CS:don't know if this is still needed:
2275 //wxChildFocusEvent eventFocus(this);
2276 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2281 void wxWindowMac::OnInternalIdle()
2283 // This calls the UI-update mechanism (querying windows for
2284 // menu/toolbar/control state information)
2285 if (wxUpdateUIEvent::CanUpdate(this))
2286 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2289 // Raise the window to the top of the Z order
2290 void wxWindowMac::Raise()
2294 // Lower the window to the bottom of the Z order
2295 void wxWindowMac::Lower()
2300 // static wxWindow *gs_lastWhich = NULL;
2302 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2304 // first trigger a set cursor event
2306 wxPoint clientorigin
= GetClientAreaOrigin() ;
2307 wxSize clientsize
= GetClientSize() ;
2309 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2311 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2313 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2314 if ( processedEvtSetCursor
&& event
.HasCursor() )
2316 cursor
= event
.GetCursor() ;
2321 // the test for processedEvtSetCursor is here to prevent using m_cursor
2322 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2323 // it - this is a way to say that our cursor shouldn't be used for this
2325 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2335 cursor
= *wxSTANDARD_CURSOR
;
2339 cursor
.MacInstall() ;
2341 return cursor
.Ok() ;
2344 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2348 return m_tooltip
->GetTip() ;
2350 return wxEmptyString
;
2353 void wxWindowMac::Update()
2355 #if TARGET_API_MAC_OSX
2356 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2358 ::Draw1Control( (ControlRef
) m_macControl
) ;
2362 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2364 wxTopLevelWindowMac
* win
= NULL
;
2365 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2368 win
= wxFindWinFromMacWindow( window
) ;
2372 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2376 RgnHandle visRgn
= NewRgn() ;
2377 RgnHandle tempRgn
= NewRgn() ;
2378 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2380 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2381 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2383 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2384 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2393 if ( includeOuterStructures
)
2394 InsetRect( &r
, -3 , -3 ) ;
2395 RectRgn( visRgn
, &r
) ;
2396 if ( !IsTopLevel() )
2398 wxWindow
* child
= this ;
2399 wxWindow
* parent
= child
->GetParent() ;
2404 // we have to find a better clipping algorithm here, in order not to clip things
2405 // positioned like status and toolbar
2406 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2408 size
= parent
->GetSize() ;
2413 size
= parent
->GetClientSize() ;
2414 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2418 parent
->MacWindowToRootWindow( &x
, &y
) ;
2419 MacRootWindowToWindow( &x
, &y
) ;
2421 SetRectRgn( tempRgn
,
2422 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2423 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2424 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2426 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2427 if ( parent
->IsTopLevel() )
2430 parent
= child
->GetParent() ;
2435 wxRegion vis
= visRgn
;
2436 DisposeRgn( visRgn
) ;
2437 DisposeRgn( tempRgn
) ;
2442 This function must not change the updatergn !
2444 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2446 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2447 bool handled
= false ;
2449 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2451 RgnHandle newupdate
= NewRgn() ;
2452 wxSize point
= GetClientSize() ;
2453 wxPoint origin
= GetClientAreaOrigin() ;
2454 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2455 SectRgn( newupdate
, updatergn
, newupdate
) ;
2456 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2457 m_updateRegion
= newupdate
;
2458 DisposeRgn( newupdate
) ;
2461 if ( !EmptyRgn(updatergn
) )
2463 wxWindowDC
dc(this);
2464 if (!EmptyRgn(updatergn
))
2465 dc
.SetClippingRegion(wxRegion(updatergn
));
2467 wxEraseEvent
eevent( GetId(), &dc
);
2468 eevent
.SetEventObject( this );
2469 GetEventHandler()->ProcessEvent( eevent
);
2471 if ( !m_updateRegion
.Empty() )
2473 // paint the window itself
2475 event
.m_timeStamp
= time
;
2476 event
.SetEventObject(this);
2477 handled
= GetEventHandler()->ProcessEvent(event
);
2479 // paint custom borders
2480 wxNcPaintEvent
eventNc( GetId() );
2481 eventNc
.SetEventObject( this );
2482 GetEventHandler()->ProcessEvent( eventNc
);
2488 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2490 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2491 // updatergn is always already clipped to our boundaries
2492 // if we are in compositing mode then it is in relative to the upper left of the control
2493 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2494 // of the toplevel window
2495 // it is in window coordinates, not in client coordinates
2497 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2498 RgnHandle ownUpdateRgn
= NewRgn() ;
2499 CopyRgn( updatergn
, ownUpdateRgn
) ;
2501 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2504 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2505 RgnHandle controlRgn
= NewRgn();
2506 RectRgn( controlRgn
, &bounds
);
2507 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2508 // the window update region
2509 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2510 DisposeRgn( controlRgn
);
2512 //KO: convert ownUpdateRgn to local coordinates
2513 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2516 MacDoRedraw( ownUpdateRgn
, time
) ;
2517 DisposeRgn( ownUpdateRgn
) ;
2521 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2523 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2527 if ( iter
->IsTopLevel() )
2528 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2530 iter
= iter
->GetParent() ;
2532 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2536 void wxWindowMac::MacCreateScrollBars( long style
)
2538 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2540 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2541 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2543 GetClientSize( &width
, &height
) ;
2545 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2546 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2547 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2548 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2550 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2551 vSize
, wxVERTICAL
);
2553 if ( style
& wxVSCROLL
)
2559 m_vScrollBar
->Show(false) ;
2561 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2562 hSize
, wxHORIZONTAL
);
2563 if ( style
& wxHSCROLL
)
2568 m_hScrollBar
->Show(false) ;
2571 // because the create does not take into account the client area origin
2572 MacRepositionScrollBars() ; // we might have a real position shift
2575 void wxWindowMac::MacRepositionScrollBars()
2577 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2578 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2580 // get real client area
2584 GetSize( &width
, &height
) ;
2586 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2587 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2589 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2590 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2591 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2592 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2598 GetSize( &w
, &h
) ;
2600 MacClientToRootWindow( &x
, &y
) ;
2601 MacClientToRootWindow( &w
, &h
) ;
2603 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2605 int totW
= 10000 , totH
= 10000;
2608 if ( iter
->IsTopLevel() )
2610 iter
->GetSize( &totW
, &totH
) ;
2614 iter
= iter
->GetParent() ;
2642 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2646 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2650 bool wxWindowMac::AcceptsFocus() const
2652 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2655 void wxWindowMac::MacSuperChangedPosition()
2657 // only window-absolute structures have to be moved i.e. controls
2659 wxWindowListNode
*node
= GetChildren().GetFirst();
2662 wxWindowMac
*child
= node
->GetData();
2663 child
->MacSuperChangedPosition() ;
2664 node
= node
->GetNext();
2668 void wxWindowMac::MacTopLevelWindowChangedPosition()
2670 // only screen-absolute structures have to be moved i.e. glcanvas
2672 wxWindowListNode
*node
= GetChildren().GetFirst();
2675 wxWindowMac
*child
= node
->GetData();
2676 child
->MacTopLevelWindowChangedPosition() ;
2677 node
= node
->GetNext();
2681 long wxWindowMac::MacGetLeftBorderSize( ) const
2686 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2689 #if wxMAC_USE_THEME_BORDER
2690 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2694 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2697 #if wxMAC_USE_THEME_BORDER
2698 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2702 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2709 long wxWindowMac::MacGetRightBorderSize( ) const
2711 // they are all symmetric in mac themes
2712 return MacGetLeftBorderSize() ;
2715 long wxWindowMac::MacGetTopBorderSize( ) const
2717 // they are all symmetric in mac themes
2718 return MacGetLeftBorderSize() ;
2721 long wxWindowMac::MacGetBottomBorderSize( ) const
2723 // they are all symmetric in mac themes
2724 return MacGetLeftBorderSize() ;
2727 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2729 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2732 // Find the wxWindowMac at the current mouse position, returning the mouse
2734 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2736 pt
= wxGetMousePosition();
2737 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2741 // Get the current mouse position.
2742 wxPoint
wxGetMousePosition()
2745 wxGetMousePosition(& x
, & y
);
2746 return wxPoint(x
, y
);
2749 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2751 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2753 // copied from wxGTK : CS
2754 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2757 // (a) it's a command event and so is propagated to the parent
2758 // (b) under MSW it can be generated from kbd too
2759 // (c) it uses screen coords (because of (a))
2760 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2762 this->ClientToScreen(event
.GetPosition()));
2763 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2766 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2772 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2774 // OS Needs it in tlw content area coordinates
2775 MacClientToRootWindow( &x
, &y
) ;
2779 // OS Needs it in window not client coordinates
2780 wxPoint origin
= GetClientAreaOrigin() ;
2785 SInt16 controlpart
;
2790 short modifiers
= 0;
2792 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2793 modifiers
|= btnState
;
2795 if ( event
.m_shiftDown
)
2796 modifiers
|= shiftKey
;
2798 if ( event
.m_controlDown
)
2799 modifiers
|= controlKey
;
2801 if ( event
.m_altDown
)
2802 modifiers
|= optionKey
;
2804 if ( event
.m_metaDown
)
2805 modifiers
|= cmdKey
;
2807 bool handled
= false ;
2809 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2811 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2812 wxTheApp
->s_lastMouseDown
= 0 ;
2813 if ( controlpart
!= kControlNoPart
)
2815 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2828 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2830 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2833 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2837 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2838 Rect bounds
= { y
, x
, y
+h
, x
+w
};