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 void wxWindowMac::Thaw()
1860 #if TARGET_API_MAC_OSX
1861 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1863 if ( !--m_frozenness
)
1865 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
1866 HIViewSetNeedsDisplay( (HIViewRef
) m_macControl
, true ) ;
1871 void wxWindowMac::MacRedrawControl()
1874 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1876 #if TARGET_API_MAC_CARBON
1879 wxClientDC dc(this) ;
1880 wxMacPortSetter helper(&dc) ;
1881 wxMacWindowClipper clipper(this) ;
1882 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1883 UMADrawControl( (ControlRef) m_macControl ) ;
1890 void wxWindowMac::OnPaint(wxPaintEvent& event)
1892 // why don't we skip that here ?
1896 wxWindowMac
*wxGetActiveWindow()
1898 // actually this is a windows-only concept
1902 // Coordinates relative to the window
1903 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1905 // We really don't move the mouse programmatically under Mac.
1908 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1910 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1915 event
.GetDC()->Clear() ;
1918 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1920 wxWindowDC
dc(this) ;
1921 wxMacPortSetter
helper(&dc
) ;
1923 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1926 int wxWindowMac::GetScrollPos(int orient
) const
1928 if ( orient
== wxHORIZONTAL
)
1931 return m_hScrollBar
->GetThumbPosition() ;
1936 return m_vScrollBar
->GetThumbPosition() ;
1941 // This now returns the whole range, not just the number
1942 // of positions that we can scroll.
1943 int wxWindowMac::GetScrollRange(int orient
) const
1945 if ( orient
== wxHORIZONTAL
)
1948 return m_hScrollBar
->GetRange() ;
1953 return m_vScrollBar
->GetRange() ;
1958 int wxWindowMac::GetScrollThumb(int orient
) const
1960 if ( orient
== wxHORIZONTAL
)
1963 return m_hScrollBar
->GetThumbSize() ;
1968 return m_vScrollBar
->GetThumbSize() ;
1973 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1975 if ( orient
== wxHORIZONTAL
)
1978 m_hScrollBar
->SetThumbPosition( pos
) ;
1983 m_vScrollBar
->SetThumbPosition( pos
) ;
1987 void wxWindowMac::MacPaintBorders( int left
, int top
)
1993 wxGetOsVersion( &major
, &minor
);
1995 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1996 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1998 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1999 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2000 // OS X has lighter border edges than classic:
2003 darkShadow
.red
= 0x8E8E;
2004 darkShadow
.green
= 0x8E8E;
2005 darkShadow
.blue
= 0x8E8E;
2006 lightShadow
.red
= 0xBDBD;
2007 lightShadow
.green
= 0xBDBD;
2008 lightShadow
.blue
= 0xBDBD;
2014 GetSize( &w
, &h
) ;
2015 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2017 #if wxMAC_USE_THEME_BORDER
2018 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2021 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2022 InsetRect( &rect , border , border );
2023 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2026 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2028 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2029 RGBForeColor( &face
);
2030 MoveTo( left
+ 0 , top
+ h
- 2 );
2031 LineTo( left
+ 0 , top
+ 0 );
2032 LineTo( left
+ w
- 2 , top
+ 0 );
2034 MoveTo( left
+ 2 , top
+ h
- 3 );
2035 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2036 LineTo( left
+ w
- 3 , top
+ 2 );
2038 RGBForeColor( sunken
? &face
: &darkShadow
);
2039 MoveTo( left
+ 0 , top
+ h
- 1 );
2040 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2041 LineTo( left
+ w
- 1 , top
+ 0 );
2043 RGBForeColor( sunken
? &lightShadow
: &white
);
2044 MoveTo( left
+ 1 , top
+ h
- 3 );
2045 LineTo( left
+ 1, top
+ 1 );
2046 LineTo( left
+ w
- 3 , top
+ 1 );
2048 RGBForeColor( sunken
? &white
: &lightShadow
);
2049 MoveTo( left
+ 1 , top
+ h
- 2 );
2050 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2051 LineTo( left
+ w
- 2 , top
+ 1 );
2053 RGBForeColor( sunken
? &darkShadow
: &face
);
2054 MoveTo( left
+ 2 , top
+ h
- 4 );
2055 LineTo( left
+ 2 , top
+ 2 );
2056 LineTo( left
+ w
- 4 , top
+ 2 );
2059 else if (HasFlag(wxSIMPLE_BORDER
))
2061 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2062 RGBForeColor( &darkShadow
) ;
2063 FrameRect( &rect
) ;
2067 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2069 if ( child
== m_hScrollBar
)
2070 m_hScrollBar
= NULL
;
2071 if ( child
== m_vScrollBar
)
2072 m_vScrollBar
= NULL
;
2074 wxWindowBase::RemoveChild( child
) ;
2077 // New function that will replace some of the above.
2078 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2079 int range
, bool refresh
)
2081 if ( orient
== wxHORIZONTAL
)
2085 if ( range
== 0 || thumbVisible
>= range
)
2087 if ( m_hScrollBar
->IsShown() )
2088 m_hScrollBar
->Show(false) ;
2092 if ( !m_hScrollBar
->IsShown() )
2093 m_hScrollBar
->Show(true) ;
2094 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2102 if ( range
== 0 || thumbVisible
>= range
)
2104 if ( m_vScrollBar
->IsShown() )
2105 m_vScrollBar
->Show(false) ;
2109 if ( !m_vScrollBar
->IsShown() )
2110 m_vScrollBar
->Show(true) ;
2111 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2115 MacRepositionScrollBars() ;
2118 // Does a physical scroll
2119 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2121 if( dx
== 0 && dy
==0 )
2126 wxClientDC
dc(this) ;
2127 wxMacPortSetter
helper(&dc
) ;
2129 int width
, height
;
2130 GetClientSize( &width
, &height
) ;
2137 // TODO take out the boundaries
2138 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2140 RgnHandle updateRgn
= NewRgn() ;
2143 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2144 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2145 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2147 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2149 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2150 // but it seems the update only refreshes the background of the control, rather than calling
2151 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2152 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2155 // we also have to scroll the update rgn in this rectangle
2156 // in order not to loose updates
2158 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2159 RgnHandle formerUpdateRgn
= NewRgn() ;
2160 RgnHandle scrollRgn
= NewRgn() ;
2161 RectRgn( scrollRgn
, &scrollrect
) ;
2162 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2164 LocalToGlobal( &pt
) ;
2165 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2166 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2167 if ( !EmptyRgn( formerUpdateRgn
) )
2169 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2170 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2171 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2173 InvalWindowRgn(rootWindow
, updateRgn
) ;
2174 DisposeRgn( updateRgn
) ;
2175 DisposeRgn( formerUpdateRgn
) ;
2176 DisposeRgn( scrollRgn
) ;
2180 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2182 wxWindowMac
*child
= node
->GetData();
2183 if (child
== m_vScrollBar
) continue;
2184 if (child
== m_hScrollBar
) continue;
2185 if (child
->IsTopLevel()) continue;
2188 child
->GetPosition( &x
, &y
);
2190 child
->GetSize( &w
, &h
);
2194 if (rect
->Intersects(rc
))
2195 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2199 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2203 // TODO remove, was moved higher up Update() ;
2207 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2209 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2211 wxScrollWinEvent wevent
;
2212 wevent
.SetPosition(event
.GetPosition());
2213 wevent
.SetOrientation(event
.GetOrientation());
2214 wevent
.m_eventObject
= this;
2216 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2217 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2218 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2219 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2220 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2221 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2222 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2223 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2224 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2225 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2226 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2227 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2228 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2229 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2230 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2231 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2233 GetEventHandler()->ProcessEvent(wevent
);
2237 // Get the window with the focus
2238 wxWindowMac
*wxWindowBase::FindFocus()
2240 return gFocusWindow
;
2243 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2245 // panel wants to track the window which was the last to have focus in it,
2246 // so we want to set ourselves as the window which last had focus
2248 // notice that it's also important to do it upwards the tree becaus
2249 // otherwise when the top level panel gets focus, it won't set it back to
2250 // us, but to some other sibling
2252 // CS:don't know if this is still needed:
2253 //wxChildFocusEvent eventFocus(this);
2254 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2259 void wxWindowMac::OnInternalIdle()
2261 // This calls the UI-update mechanism (querying windows for
2262 // menu/toolbar/control state information)
2263 if (wxUpdateUIEvent::CanUpdate(this))
2264 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2267 // Raise the window to the top of the Z order
2268 void wxWindowMac::Raise()
2272 // Lower the window to the bottom of the Z order
2273 void wxWindowMac::Lower()
2278 // static wxWindow *gs_lastWhich = NULL;
2280 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2282 // first trigger a set cursor event
2284 wxPoint clientorigin
= GetClientAreaOrigin() ;
2285 wxSize clientsize
= GetClientSize() ;
2287 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2289 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2291 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2292 if ( processedEvtSetCursor
&& event
.HasCursor() )
2294 cursor
= event
.GetCursor() ;
2299 // the test for processedEvtSetCursor is here to prevent using m_cursor
2300 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2301 // it - this is a way to say that our cursor shouldn't be used for this
2303 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2313 cursor
= *wxSTANDARD_CURSOR
;
2317 cursor
.MacInstall() ;
2319 return cursor
.Ok() ;
2322 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2326 return m_tooltip
->GetTip() ;
2328 return wxEmptyString
;
2331 void wxWindowMac::Update()
2333 #if TARGET_API_MAC_OSX
2334 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2336 ::Draw1Control( (ControlRef
) m_macControl
) ;
2340 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2342 wxTopLevelWindowMac
* win
= NULL
;
2343 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2346 win
= wxFindWinFromMacWindow( window
) ;
2350 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2354 RgnHandle visRgn
= NewRgn() ;
2355 RgnHandle tempRgn
= NewRgn() ;
2356 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2358 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2359 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2361 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2362 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2371 if ( includeOuterStructures
)
2372 InsetRect( &r
, -3 , -3 ) ;
2373 RectRgn( visRgn
, &r
) ;
2374 if ( !IsTopLevel() )
2376 wxWindow
* child
= this ;
2377 wxWindow
* parent
= child
->GetParent() ;
2382 // we have to find a better clipping algorithm here, in order not to clip things
2383 // positioned like status and toolbar
2384 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2386 size
= parent
->GetSize() ;
2391 size
= parent
->GetClientSize() ;
2392 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2396 parent
->MacWindowToRootWindow( &x
, &y
) ;
2397 MacRootWindowToWindow( &x
, &y
) ;
2399 SetRectRgn( tempRgn
,
2400 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2401 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2402 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2404 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2405 if ( parent
->IsTopLevel() )
2408 parent
= child
->GetParent() ;
2413 wxRegion vis
= visRgn
;
2414 DisposeRgn( visRgn
) ;
2415 DisposeRgn( tempRgn
) ;
2420 This function must not change the updatergn !
2422 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2424 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2425 bool handled
= false ;
2427 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2429 RgnHandle newupdate
= NewRgn() ;
2430 wxSize point
= GetClientSize() ;
2431 wxPoint origin
= GetClientAreaOrigin() ;
2432 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2433 SectRgn( newupdate
, updatergn
, newupdate
) ;
2434 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2435 m_updateRegion
= newupdate
;
2436 DisposeRgn( newupdate
) ;
2439 if ( !EmptyRgn(updatergn
) )
2441 wxWindowDC
dc(this);
2442 if (!EmptyRgn(updatergn
))
2443 dc
.SetClippingRegion(wxRegion(updatergn
));
2445 wxEraseEvent
eevent( GetId(), &dc
);
2446 eevent
.SetEventObject( this );
2447 GetEventHandler()->ProcessEvent( eevent
);
2449 if ( !m_updateRegion
.Empty() )
2451 // paint the window itself
2453 event
.m_timeStamp
= time
;
2454 event
.SetEventObject(this);
2455 handled
= GetEventHandler()->ProcessEvent(event
);
2457 // paint custom borders
2458 wxNcPaintEvent
eventNc( GetId() );
2459 eventNc
.SetEventObject( this );
2460 GetEventHandler()->ProcessEvent( eventNc
);
2466 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2468 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2469 // updatergn is always already clipped to our boundaries
2470 // if we are in compositing mode then it is in relative to the upper left of the control
2471 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2472 // of the toplevel window
2473 // it is in window coordinates, not in client coordinates
2475 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2476 RgnHandle ownUpdateRgn
= NewRgn() ;
2477 CopyRgn( updatergn
, ownUpdateRgn
) ;
2479 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2482 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2483 RgnHandle controlRgn
= NewRgn();
2484 RectRgn( controlRgn
, &bounds
);
2485 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2486 // the window update region
2487 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2488 DisposeRgn( controlRgn
);
2490 //KO: convert ownUpdateRgn to local coordinates
2491 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2494 MacDoRedraw( ownUpdateRgn
, time
) ;
2495 DisposeRgn( ownUpdateRgn
) ;
2499 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2501 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2505 if ( iter
->IsTopLevel() )
2506 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2508 iter
= iter
->GetParent() ;
2510 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2514 void wxWindowMac::MacCreateScrollBars( long style
)
2516 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2518 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2519 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2521 GetClientSize( &width
, &height
) ;
2523 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2524 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2525 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2526 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2528 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2529 vSize
, wxVERTICAL
);
2531 if ( style
& wxVSCROLL
)
2537 m_vScrollBar
->Show(false) ;
2539 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2540 hSize
, wxHORIZONTAL
);
2541 if ( style
& wxHSCROLL
)
2546 m_hScrollBar
->Show(false) ;
2549 // because the create does not take into account the client area origin
2550 MacRepositionScrollBars() ; // we might have a real position shift
2553 void wxWindowMac::MacRepositionScrollBars()
2555 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2556 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2558 // get real client area
2562 GetSize( &width
, &height
) ;
2564 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2565 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2567 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2568 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2569 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2570 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2576 GetSize( &w
, &h
) ;
2578 MacClientToRootWindow( &x
, &y
) ;
2579 MacClientToRootWindow( &w
, &h
) ;
2581 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2583 int totW
= 10000 , totH
= 10000;
2586 if ( iter
->IsTopLevel() )
2588 iter
->GetSize( &totW
, &totH
) ;
2592 iter
= iter
->GetParent() ;
2620 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2624 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2628 bool wxWindowMac::AcceptsFocus() const
2630 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2633 void wxWindowMac::MacSuperChangedPosition()
2635 // only window-absolute structures have to be moved i.e. controls
2637 wxWindowListNode
*node
= GetChildren().GetFirst();
2640 wxWindowMac
*child
= node
->GetData();
2641 child
->MacSuperChangedPosition() ;
2642 node
= node
->GetNext();
2646 void wxWindowMac::MacTopLevelWindowChangedPosition()
2648 // only screen-absolute structures have to be moved i.e. glcanvas
2650 wxWindowListNode
*node
= GetChildren().GetFirst();
2653 wxWindowMac
*child
= node
->GetData();
2654 child
->MacTopLevelWindowChangedPosition() ;
2655 node
= node
->GetNext();
2659 long wxWindowMac::MacGetLeftBorderSize( ) const
2664 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2667 #if wxMAC_USE_THEME_BORDER
2668 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2672 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2675 #if wxMAC_USE_THEME_BORDER
2676 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2680 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2687 long wxWindowMac::MacGetRightBorderSize( ) const
2689 // they are all symmetric in mac themes
2690 return MacGetLeftBorderSize() ;
2693 long wxWindowMac::MacGetTopBorderSize( ) const
2695 // they are all symmetric in mac themes
2696 return MacGetLeftBorderSize() ;
2699 long wxWindowMac::MacGetBottomBorderSize( ) const
2701 // they are all symmetric in mac themes
2702 return MacGetLeftBorderSize() ;
2705 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2707 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2710 // Find the wxWindowMac at the current mouse position, returning the mouse
2712 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2714 pt
= wxGetMousePosition();
2715 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2719 // Get the current mouse position.
2720 wxPoint
wxGetMousePosition()
2723 wxGetMousePosition(& x
, & y
);
2724 return wxPoint(x
, y
);
2727 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2729 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2731 // copied from wxGTK : CS
2732 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2735 // (a) it's a command event and so is propagated to the parent
2736 // (b) under MSW it can be generated from kbd too
2737 // (c) it uses screen coords (because of (a))
2738 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2740 this->ClientToScreen(event
.GetPosition()));
2741 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2744 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2750 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2752 // OS Needs it in tlw content area coordinates
2753 MacClientToRootWindow( &x
, &y
) ;
2757 // OS Needs it in window not client coordinates
2758 wxPoint origin
= GetClientAreaOrigin() ;
2763 SInt16 controlpart
;
2768 short modifiers
= 0;
2770 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2771 modifiers
|= btnState
;
2773 if ( event
.m_shiftDown
)
2774 modifiers
|= shiftKey
;
2776 if ( event
.m_controlDown
)
2777 modifiers
|= controlKey
;
2779 if ( event
.m_altDown
)
2780 modifiers
|= optionKey
;
2782 if ( event
.m_metaDown
)
2783 modifiers
|= cmdKey
;
2785 bool handled
= false ;
2787 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2789 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2790 wxTheApp
->s_lastMouseDown
= 0 ;
2791 if ( controlpart
!= kControlNoPart
)
2793 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2806 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2808 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2811 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2815 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2816 Rect bounds
= { y
, x
, y
+h
, x
+w
};