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 static const EventTypeSpec eventList
[] =
107 #if TARGET_API_MAC_OSX
108 { kEventClassControl
, kEventControlDraw
} ,
109 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
110 // { kEventClassControl , kEventControlBoundsChanged } ,
116 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
118 OSStatus result
= eventNotHandledErr
;
120 wxMacCarbonEvent
cEvent( event
) ;
122 ControlRef controlRef
;
123 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
125 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
127 switch( GetEventKind( event
) )
129 case kEventControlDraw
:
131 RgnHandle updateRgn
= cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
) ;
132 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
134 #if 0 // in case we would need a coregraphics compliant background erase first
135 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
136 if ( thisWindow
->MacIsUserPane() )
139 err
= HIViewGetBounds( controlRef
, &bounds
);
140 CGContextSetRGBFillColor( cgContext
, 1 , 1 , 1 , 1 );
141 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
142 CGContextFillRect( cgContext
, bounds
);
145 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
148 result
= eventNotHandledErr
;
157 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
159 OSStatus result
= eventNotHandledErr
;
161 switch ( GetEventClass( event
) )
163 case kEventClassControl
:
164 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
172 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
174 // ---------------------------------------------------------------------------
175 // UserPane events for non OSX builds
176 // ---------------------------------------------------------------------------
178 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
180 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
181 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
182 win
->MacControlUserPaneDrawProc(part
) ;
185 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
187 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
188 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
189 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
192 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
194 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
195 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
196 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
199 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
201 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
202 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
203 win
->MacControlUserPaneIdleProc() ;
206 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
208 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
209 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
210 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
213 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
215 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
216 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
217 win
->MacControlUserPaneActivateProc(activating
) ;
220 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
222 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
223 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
224 return win
->MacControlUserPaneFocusProc(action
) ;
227 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
229 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
230 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
231 win
->MacControlUserPaneBackgroundProc(info
) ;
234 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
236 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
239 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
241 return kControlNoPart
;
244 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
246 return kControlNoPart
;
249 void wxWindowMac::MacControlUserPaneIdleProc()
253 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
255 return kControlNoPart
;
258 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
262 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
264 return kControlNoPart
;
267 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
271 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
272 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
273 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
274 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
275 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
276 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
277 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
278 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
280 // ===========================================================================
282 // ===========================================================================
284 wxList
wxWinMacControlList(wxKEY_INTEGER
);
286 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
288 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
291 return (wxControl
*)node
->GetData();
294 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
296 // adding NULL ControlRef is (first) surely a result of an error and
297 // (secondly) breaks native event processing
298 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
300 if ( !wxWinMacControlList
.Find((long)inControl
) )
301 wxWinMacControlList
.Append((long)inControl
, control
);
304 void wxRemoveMacControlAssociation(wxWindow
*control
)
306 wxWinMacControlList
.DeleteObject(control
);
310 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
312 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
314 // we have to setup the brush in the current port and return noErr
315 // or return an error code so that the control manager walks further up the
316 // hierarchy to find a correct background
318 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
320 OSStatus status
= paramErr
;
323 case kControlMsgApplyTextColor
:
325 case kControlMsgSetUpBackground
:
327 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
331 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
335 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
337 // this clipping is only needed for non HIView
339 RgnHandle clip
= NewRgn() ;
342 wx
->MacWindowToRootWindow( &x
,&y
) ;
343 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
344 OffsetRgn( clip
, x
, y
) ;
351 else if ( wx->MacIsUserPane() )
353 // if we don't have a valid brush for such a control, we have to call the
354 // setup of our parent ourselves
355 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
368 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
369 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
373 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
376 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
381 // ----------------------------------------------------------------------------
382 // constructors and such
383 // ----------------------------------------------------------------------------
385 void wxWindowMac::Init()
387 m_backgroundTransparent
= FALSE
;
389 // as all windows are created with WS_VISIBLE style...
392 m_hScrollBar
= NULL
;
393 m_vScrollBar
= NULL
;
394 m_macBackgroundBrush
= wxNullBrush
;
396 m_macControl
= NULL
;
398 m_macIsUserPane
= TRUE
;
400 // make sure all proc ptrs are available
402 if ( gControlUserPaneDrawUPP
== NULL
)
404 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
405 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
406 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
407 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
408 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
409 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
410 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
411 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
413 if ( wxMacLiveScrollbarActionUPP
== NULL
)
415 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
418 if ( wxMacSetupControlBackgroundUPP
== NULL
)
420 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
426 wxWindowMac::~wxWindowMac()
430 m_isBeingDeleted
= TRUE
;
432 #ifndef __WXUNIVERSAL__
433 // VS: make sure there's no wxFrame with last focus set to us:
434 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
436 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
439 if ( frame
->GetLastFocus() == this )
441 frame
->SetLastFocus((wxWindow
*)NULL
);
446 #endif // __WXUNIVERSAL__
448 // wxRemoveMacControlAssociation( this ) ;
449 // If we delete an item, we should initialize the parent panel,
450 // because it could now be invalid.
451 wxWindow
*parent
= GetParent() ;
454 if (parent
->GetDefaultItem() == (wxButton
*) this)
455 parent
->SetDefaultItem(NULL
);
457 if ( (ControlRef
) m_macControl
)
459 // in case the callback might be called during destruction
460 wxRemoveMacControlAssociation( this) ;
461 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
462 ::DisposeControl( (ControlRef
) m_macControl
) ;
463 m_macControl
= NULL
;
466 if ( g_MacLastWindow
== this )
468 g_MacLastWindow
= NULL
;
471 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
474 if ( frame
->GetLastFocus() == this )
475 frame
->SetLastFocus( NULL
) ;
478 if ( gFocusWindow
== this )
480 gFocusWindow
= NULL
;
485 // delete our drop target if we've got one
486 #if wxUSE_DRAG_AND_DROP
487 if ( m_dropTarget
!= NULL
)
492 #endif // wxUSE_DRAG_AND_DROP
497 void wxWindowMac::MacInstallEventHandler()
499 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
500 GetEventTypeCount(eventList
), eventList
, this,
501 (EventHandlerRef
*)&m_macControlEventHandler
);
506 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
510 const wxString
& name
)
512 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
514 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
517 parent
->AddChild(this);
519 m_windowVariant
= parent
->GetWindowVariant() ;
521 if ( m_macIsUserPane
)
523 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
525 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
/*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
527 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
529 MacPostControlCreate(pos
,size
) ;
530 #if !TARGET_API_MAC_OSX
531 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
532 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
533 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
534 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
535 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
536 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
537 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
538 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
539 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
540 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
541 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
542 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
543 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
544 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
545 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
546 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
549 #ifndef __WXUNIVERSAL__
550 // Don't give scrollbars to wxControls unless they ask for them
551 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
552 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
554 MacCreateScrollBars( style
) ;
558 wxWindowCreateEvent
event(this);
559 GetEventHandler()->AddPendingEvent(event
);
564 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
566 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
568 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
569 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
571 MacInstallEventHandler();
573 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
574 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
575 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
577 // adjust font, controlsize etc
578 DoSetWindowVariant( m_windowVariant
) ;
580 #if !TARGET_API_MAC_OSX
581 // eventually we can fix some clipping issues be reactivating this hook
582 //if ( m_macIsUserPane )
583 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
586 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
588 wxSize new_size
= size
;
589 if (!m_macIsUserPane
)
591 wxSize
best_size( DoGetBestSize() );
594 new_size
.x
= best_size
.x
;
597 new_size
.y
= best_size
.y
;
599 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
602 SetCursor( *wxSTANDARD_CURSOR
) ;
606 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
608 wxASSERT( m_macControl
!= NULL
) ;
610 m_windowVariant
= variant
;
613 ThemeFontID themeFont
= kThemeSystemFont
;
615 // we will get that from the settings later
616 // and make this NORMAL later, but first
617 // we have a few calculations that we must fix
621 case wxWINDOW_VARIANT_NORMAL
:
622 size
= kControlSizeNormal
;
623 themeFont
= kThemeSystemFont
;
625 case wxWINDOW_VARIANT_SMALL
:
626 size
= kControlSizeSmall
;
627 themeFont
= kThemeSmallSystemFont
;
629 case wxWINDOW_VARIANT_MINI
:
630 if (UMAGetSystemVersion() >= 0x1030 )
632 // not always defined in the headers
638 size
= kControlSizeSmall
;
639 themeFont
= kThemeSmallSystemFont
;
642 case wxWINDOW_VARIANT_LARGE
:
643 size
= kControlSizeLarge
;
644 themeFont
= kThemeSystemFont
;
647 wxFAIL_MSG(_T("unexpected window variant"));
650 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
653 font
.MacCreateThemeFont( themeFont
) ;
657 void wxWindowMac::MacUpdateControlFont()
659 ControlFontStyleRec fontStyle
;
660 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
662 switch( m_font
.MacGetThemeFontID() )
664 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
665 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
666 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
667 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
669 fontStyle
.flags
= kControlUseFontMask
;
673 fontStyle
.font
= m_font
.MacGetFontNum() ;
674 fontStyle
.style
= m_font
.MacGetFontStyle() ;
675 fontStyle
.size
= m_font
.MacGetFontSize() ;
676 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
679 fontStyle
.just
= teJustLeft
;
680 fontStyle
.flags
|= kControlUseJustMask
;
681 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
682 fontStyle
.just
= teJustCenter
;
683 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
684 fontStyle
.just
= teJustRight
;
687 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
688 fontStyle
.flags
|= kControlUseForeColorMask
;
690 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
694 bool wxWindowMac::SetFont(const wxFont
& font
)
696 bool retval
= !wxWindowBase::SetFont( font
) ;
698 MacUpdateControlFont() ;
703 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
705 if ( !wxWindowBase::SetForegroundColour(col
) )
708 MacUpdateControlFont() ;
713 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
715 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
719 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
721 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
723 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
725 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
729 brush
.SetColour( col
) ;
731 MacSetBackgroundBrush( brush
) ;
733 MacUpdateControlFont() ;
739 bool wxWindowMac::MacCanFocus() const
741 wxASSERT( m_macControl
!= NULL
) ;
747 void wxWindowMac::SetFocus()
749 if ( gFocusWindow
== this )
752 if ( AcceptsFocus() )
758 if ( gFocusWindow
->m_caret
)
760 gFocusWindow
->m_caret
->OnKillFocus();
762 #endif // wxUSE_CARET
763 #ifndef __WXUNIVERSAL__
764 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
765 // TODO we must use the built-in focusing
766 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
768 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
769 control
->MacRedrawControl() ;
772 // Without testing the window id, for some reason
773 // a kill focus event can still be sent to
774 // the control just being focussed.
775 int thisId
= this->m_windowId
;
776 int gFocusWindowId
= gFocusWindow
->m_windowId
;
777 if (gFocusWindowId
!= thisId
)
779 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
780 event
.SetEventObject(gFocusWindow
);
781 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
784 gFocusWindow
= this ;
790 m_caret
->OnSetFocus();
792 #endif // wxUSE_CARET
793 // panel wants to track the window which was the last to have focus in it
794 wxChildFocusEvent
eventFocus(this);
795 GetEventHandler()->ProcessEvent(eventFocus
);
797 #ifndef __WXUNIVERSAL__
798 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
799 if ( control
&& control
->GetHandle() )
801 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
804 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
805 event
.SetEventObject(this);
806 GetEventHandler()->ProcessEvent(event
) ;
812 void wxWindowMac::DoCaptureMouse()
814 wxTheApp
->s_captureWindow
= this ;
817 wxWindow
* wxWindowBase::GetCapture()
819 return wxTheApp
->s_captureWindow
;
822 void wxWindowMac::DoReleaseMouse()
824 wxTheApp
->s_captureWindow
= NULL
;
827 #if wxUSE_DRAG_AND_DROP
829 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
831 if ( m_dropTarget
!= 0 ) {
835 m_dropTarget
= pDropTarget
;
836 if ( m_dropTarget
!= 0 )
844 // Old style file-manager drag&drop
845 void wxWindowMac::DragAcceptFiles(bool accept
)
850 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
851 int& w
, int& h
) const
854 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
859 w
= bounds
.right
- bounds
.left
;
860 h
= bounds
.bottom
- bounds
.top
;
862 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
865 Point tlworigin
= { 0 , 0 } ;
868 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
869 ::LocalToGlobal( &tlworigin
) ;
876 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
879 int& w
, int& h
) const
883 // todo the default calls may be used as soon as PostCreateControl Is moved here
884 w
= size
.x
; // WidthDefault( size.x );
885 h
= size
.y
; // HeightDefault( size.y ) ;
886 #if !TARGET_API_MAC_OSX
887 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
894 void wxWindowMac::DoGetSize(int *x
, int *y
) const
896 #if TARGET_API_MAC_OSX
897 int x1
, y1
, w1
,h1
;
898 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
904 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
905 if(x
) *x
= bounds
.right
- bounds
.left
;
906 if(y
) *y
= bounds
.bottom
- bounds
.top
;
910 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
912 #if TARGET_API_MAC_OSX
913 int x1
, y1
, w1
,h1
;
914 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
917 wxWindow
*parent
= GetParent();
920 wxPoint
pt(parent
->GetClientAreaOrigin());
929 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
930 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
932 int xx
= bounds
.left
;
933 int yy
= bounds
.top
;
935 if ( !GetParent()->IsTopLevel() )
937 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
943 wxPoint
pt(GetParent()->GetClientAreaOrigin());
952 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
954 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
956 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
959 Point localwhere
= {0,0} ;
961 if(x
) localwhere
.h
= * x
;
962 if(y
) localwhere
.v
= * y
;
964 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
965 ::GlobalToLocal( &localwhere
) ;
966 if(x
) *x
= localwhere
.h
;
967 if(y
) *y
= localwhere
.v
;
970 MacRootWindowToWindow( x
, y
) ;
972 wxPoint origin
= GetClientAreaOrigin() ;
973 if(x
) *x
-= origin
.x
;
974 if(y
) *y
-= origin
.y
;
977 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
979 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
980 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
982 wxPoint origin
= GetClientAreaOrigin() ;
983 if(x
) *x
+= origin
.x
;
984 if(y
) *y
+= origin
.y
;
986 MacWindowToRootWindow( x
, y
) ;
989 Point localwhere
= { 0,0 };
990 if(x
) localwhere
.h
= * x
;
991 if(y
) localwhere
.v
= * y
;
993 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
994 ::LocalToGlobal( &localwhere
) ;
995 if(x
) *x
= localwhere
.h
;
996 if(y
) *y
= localwhere
.v
;
1000 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1002 wxPoint origin
= GetClientAreaOrigin() ;
1003 if(x
) *x
+= origin
.x
;
1004 if(y
) *y
+= origin
.y
;
1006 MacWindowToRootWindow( x
, y
) ;
1009 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1011 MacRootWindowToWindow( x
, y
) ;
1013 wxPoint origin
= GetClientAreaOrigin() ;
1014 if(x
) *x
-= origin
.x
;
1015 if(y
) *y
-= origin
.y
;
1018 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1020 #if TARGET_API_MAC_OSX
1022 if ( x
) pt
.x
= *x
;
1023 if ( y
) pt
.y
= *y
;
1025 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1027 if ( x
) *x
= (int) pt
.x
;
1028 if ( y
) *y
= (int) pt
.y
;
1030 if ( !IsTopLevel() )
1033 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1034 if(x
) *x
+= bounds
.left
;
1035 if(y
) *y
+= bounds
.top
;
1040 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1045 MacWindowToRootWindow( &x1
, &y1
) ;
1050 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1052 #if TARGET_API_MAC_OSX
1054 if ( x
) pt
.x
= *x
;
1055 if ( y
) pt
.y
= *y
;
1057 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1059 if ( x
) *x
= (int) pt
.x
;
1060 if ( y
) *y
= (int) pt
.y
;
1062 if ( !IsTopLevel() )
1065 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1066 if(x
) *x
-= bounds
.left
;
1067 if(y
) *y
-= bounds
.top
;
1072 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1077 MacRootWindowToWindow( &x1
, &y1
) ;
1082 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1084 wxSize sizeTotal
= size
;
1086 RgnHandle rgn
= NewRgn() ;
1090 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1092 GetRegionBounds( rgn
, &content
) ;
1097 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1100 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1101 #if !TARGET_API_MAC_OSX
1102 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1105 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1106 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1108 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1109 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1115 // Get size *available for subwindows* i.e. excluding menu bar etc.
1116 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1120 RgnHandle rgn
= NewRgn() ;
1122 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1124 GetRegionBounds( rgn
, &content
) ;
1129 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1131 #if !TARGET_API_MAC_OSX
1133 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1134 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1136 ww
= content
.right
- content
.left
;
1137 hh
= content
.bottom
- content
.top
;
1139 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1140 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1142 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1148 GetSize( &w
, &h
) ;
1150 MacClientToRootWindow( &x1
, &y1
) ;
1151 MacClientToRootWindow( &w
, &h
) ;
1153 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1155 int totW
= 10000 , totH
= 10000;
1158 if ( iter
->IsTopLevel() )
1160 iter
->GetSize( &totW
, &totH
) ;
1164 iter
= iter
->GetParent() ;
1167 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1169 hh
-= MAC_SCROLLBAR_SIZE
;
1175 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1177 ww
-= MAC_SCROLLBAR_SIZE
;
1189 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1191 if (m_cursor
== cursor
)
1194 if (wxNullCursor
== cursor
)
1196 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1201 if ( ! wxWindowBase::SetCursor( cursor
) )
1205 wxASSERT_MSG( m_cursor
.Ok(),
1206 wxT("cursor must be valid after call to the base version"));
1210 TODO why do we have to use current coordinates ?
1213 wxWindowMac *mouseWin ;
1216 // Change the cursor NOW if we're within the correct window
1219 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1221 if ( mouseWin == this && !wxIsBusy() )
1223 m_cursor.MacInstall() ;
1229 m_cursor
.MacInstall() ;
1236 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1238 menu
->SetInvokingWindow(this);
1240 ClientToScreen( &x
, &y
) ;
1242 menu
->MacBeforeDisplay( true ) ;
1243 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1244 if ( HiWord(menuResult
) != 0 )
1247 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1248 wxMenuItem
* item
= NULL
;
1250 item
= menu
->FindItem(id
, &realmenu
) ;
1251 if (item
->IsCheckable())
1253 item
->Check( !item
->IsChecked() ) ;
1255 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1257 menu
->MacAfterDisplay( true ) ;
1259 menu
->SetInvokingWindow(NULL
);
1265 // ----------------------------------------------------------------------------
1267 // ----------------------------------------------------------------------------
1271 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1273 wxWindowBase::DoSetToolTip(tooltip
);
1276 m_tooltip
->SetWindow(this);
1279 #endif // wxUSE_TOOLTIPS
1281 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1283 int former_x
, former_y
, former_w
, former_h
;
1284 #if !TARGET_API_MAC_OSX
1285 DoGetPosition( &former_x
, &former_y
) ;
1286 DoGetSize( &former_w
, &former_h
) ;
1288 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1291 int actualWidth
= width
;
1292 int actualHeight
= height
;
1296 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1297 actualWidth
= m_minWidth
;
1298 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1299 actualHeight
= m_minHeight
;
1300 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1301 actualWidth
= m_maxWidth
;
1302 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1303 actualHeight
= m_maxHeight
;
1305 bool doMove
= false ;
1306 bool doResize
= false ;
1308 if ( actualX
!= former_x
|| actualY
!= former_y
)
1312 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1317 if ( doMove
|| doResize
)
1319 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1320 #if TARGET_API_MAC_OSX
1321 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1324 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1326 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1328 MacRepositionScrollBars() ;
1331 wxPoint
point(actualX
,actualY
);
1332 wxMoveEvent
event(point
, m_windowId
);
1333 event
.SetEventObject(this);
1334 GetEventHandler()->ProcessEvent(event
) ;
1338 MacRepositionScrollBars() ;
1339 wxSize
size(actualWidth
, actualHeight
);
1340 wxSizeEvent
event(size
, m_windowId
);
1341 event
.SetEventObject(this);
1342 GetEventHandler()->ProcessEvent(event
);
1348 wxSize
wxWindowMac::DoGetBestSize() const
1350 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1351 short baselineoffset
;
1352 int bestWidth
, bestHeight
;
1353 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1355 if ( EmptyRect( &bestsize
) )
1358 bestsize
.left
= bestsize
.top
= 0 ;
1359 bestsize
.right
= 16 ;
1360 bestsize
.bottom
= 16 ;
1361 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1363 bestsize
.bottom
= 16 ;
1365 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1367 bestsize
.bottom
= 24 ;
1371 // return wxWindowBase::DoGetBestSize() ;
1375 bestWidth
= bestsize
.right
- bestsize
.left
;
1376 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1377 if ( bestHeight
< 10 )
1380 return wxSize(bestWidth
, bestHeight
);
1384 // set the size of the window: if the dimensions are positive, just use them,
1385 // but if any of them is equal to -1, it means that we must find the value for
1386 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1387 // which case -1 is a valid value for x and y)
1389 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1390 // the width/height to best suit our contents, otherwise we reuse the current
1392 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1394 // get the current size and position...
1395 int currentX
, currentY
;
1396 GetPosition(¤tX
, ¤tY
);
1398 int currentW
,currentH
;
1399 GetSize(¤tW
, ¤tH
);
1401 // ... and don't do anything (avoiding flicker) if it's already ok
1402 if ( x
== currentX
&& y
== currentY
&&
1403 width
== currentW
&& height
== currentH
)
1406 MacRepositionScrollBars() ; // we might have a real position shift
1410 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1412 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1415 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1417 wxSize
size(-1, -1);
1420 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1422 size
= DoGetBestSize();
1427 // just take the current one
1434 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1438 size
= DoGetBestSize();
1440 //else: already called DoGetBestSize() above
1446 // just take the current one
1451 DoMoveWindow(x
, y
, width
, height
);
1455 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1457 RgnHandle rgn
= NewRgn() ;
1459 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1460 GetRegionBounds( rgn
, &content
) ;
1462 #if !TARGET_API_MAC_OSX
1464 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1465 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1468 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1471 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1473 if ( clientheight
!= -1 || clientheight
!= -1 )
1475 int currentclientwidth
, currentclientheight
;
1476 int currentwidth
, currentheight
;
1478 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1479 GetSize( ¤twidth
, ¤theight
) ;
1481 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1482 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1486 void wxWindowMac::SetTitle(const wxString
& title
)
1488 m_label
= wxStripMenuCodes(title
) ;
1492 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1497 wxString
wxWindowMac::GetTitle() const
1502 void wxWindowMac::MacPropagateVisibilityChanged()
1504 MacVisibilityChanged() ;
1506 wxWindowListNode
*node
= GetChildren().GetFirst();
1509 wxWindowMac
*child
= node
->GetData();
1510 if ( child
->IsShown() )
1511 child
->MacPropagateVisibilityChanged( ) ;
1512 node
= node
->GetNext();
1516 bool wxWindowMac::Show(bool show
)
1518 if ( !wxWindowBase::Show(show
) )
1521 // TODO use visibilityChanged Carbon Event for OSX
1522 bool former
= MacIsReallyShown() ;
1524 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1525 if ( former
!= MacIsReallyShown() )
1526 MacPropagateVisibilityChanged() ;
1530 bool wxWindowMac::MacIsReallyShown()
1532 // only under OSX the visibility of the TLW is taken into account
1533 #if TARGET_API_MAC_OSX
1534 return IsControlVisible( (ControlRef
) m_macControl
) ;
1536 wxWindow
* win
= this ;
1537 while( win
->IsShown() )
1539 if ( win
->IsTopLevel() )
1542 win
= win
->GetParent() ;
1551 void wxWindowMac::MacVisibilityChanged()
1555 void wxWindowMac::MacPropagateEnabledStateChanged( )
1557 MacEnabledStateChanged() ;
1559 wxWindowListNode
*node
= GetChildren().GetFirst();
1562 wxWindowMac
*child
= node
->GetData();
1563 if ( child
->IsEnabled() )
1564 child
->MacPropagateEnabledStateChanged() ;
1565 node
= node
->GetNext();
1569 bool wxWindowMac::Enable(bool enable
)
1571 wxASSERT( m_macControl
!= NULL
) ;
1572 if ( !wxWindowBase::Enable(enable
) )
1575 bool former
= MacIsReallyEnabled() ;
1577 UMAActivateControl( (ControlRef
) m_macControl
) ;
1579 UMADeactivateControl( (ControlRef
) m_macControl
) ;
1581 if ( former
!= MacIsReallyEnabled() )
1582 MacPropagateEnabledStateChanged() ;
1586 bool wxWindowMac::MacIsReallyEnabled()
1588 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1591 void wxWindowMac::MacEnabledStateChanged()
1595 int wxWindowMac::GetCharHeight() const
1597 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1598 return dc
.GetCharHeight() ;
1601 int wxWindowMac::GetCharWidth() const
1603 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1604 return dc
.GetCharWidth() ;
1607 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1608 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1610 const wxFont
*fontToUse
= theFont
;
1612 fontToUse
= &m_font
;
1614 wxClientDC
dc( (wxWindowMac
*) this ) ;
1616 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1617 if ( externalLeading
)
1618 *externalLeading
= le
;
1628 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1629 * we always intersect with the entire window, not only with the client area
1632 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1634 #if TARGET_API_MAC_OSX
1635 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1637 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1639 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1640 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1643 if ( MacGetTopLevelWindow() == NULL )
1646 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1649 wxPoint client = GetClientAreaOrigin();
1652 int x2 = m_width - client.x;
1653 int y2 = m_height - client.y;
1655 if (IsKindOf( CLASSINFO(wxButton)))
1657 // buttons have an "aura"
1664 Rect clientrect = { y1, x1, y2, x2 };
1668 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1669 SectRect( &clientrect , &r , &clientrect ) ;
1672 if ( !EmptyRect( &clientrect ) )
1674 int top = 0 , left = 0 ;
1676 MacClientToRootWindow( &left , &top ) ;
1677 OffsetRect( &clientrect , left , top ) ;
1679 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1685 void wxWindowMac::MacRedrawControl()
1688 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1690 #if TARGET_API_MAC_CARBON
1693 wxClientDC dc(this) ;
1694 wxMacPortSetter helper(&dc) ;
1695 wxMacWindowClipper clipper(this) ;
1696 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1697 UMADrawControl( (ControlRef) m_macControl ) ;
1704 void wxWindowMac::OnPaint(wxPaintEvent& event)
1706 // why don't we skip that here ?
1710 wxWindowMac
*wxGetActiveWindow()
1712 // actually this is a windows-only concept
1716 // Coordinates relative to the window
1717 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1719 // We really don't move the mouse programmatically under Mac.
1722 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1724 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1729 event
.GetDC()->Clear() ;
1732 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1734 wxWindowDC
dc(this) ;
1735 wxMacPortSetter
helper(&dc
) ;
1737 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1740 int wxWindowMac::GetScrollPos(int orient
) const
1742 if ( orient
== wxHORIZONTAL
)
1745 return m_hScrollBar
->GetThumbPosition() ;
1750 return m_vScrollBar
->GetThumbPosition() ;
1755 // This now returns the whole range, not just the number
1756 // of positions that we can scroll.
1757 int wxWindowMac::GetScrollRange(int orient
) const
1759 if ( orient
== wxHORIZONTAL
)
1762 return m_hScrollBar
->GetRange() ;
1767 return m_vScrollBar
->GetRange() ;
1772 int wxWindowMac::GetScrollThumb(int orient
) const
1774 if ( orient
== wxHORIZONTAL
)
1777 return m_hScrollBar
->GetThumbSize() ;
1782 return m_vScrollBar
->GetThumbSize() ;
1787 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1789 if ( orient
== wxHORIZONTAL
)
1792 m_hScrollBar
->SetThumbPosition( pos
) ;
1797 m_vScrollBar
->SetThumbPosition( pos
) ;
1801 void wxWindowMac::MacPaintBorders( int left
, int top
)
1807 wxGetOsVersion( &major
, &minor
);
1809 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1810 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1812 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1813 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1814 // OS X has lighter border edges than classic:
1817 darkShadow
.red
= 0x8E8E;
1818 darkShadow
.green
= 0x8E8E;
1819 darkShadow
.blue
= 0x8E8E;
1820 lightShadow
.red
= 0xBDBD;
1821 lightShadow
.green
= 0xBDBD;
1822 lightShadow
.blue
= 0xBDBD;
1828 GetSize( &w
, &h
) ;
1829 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1831 #if wxMAC_USE_THEME_BORDER
1832 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1835 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1836 InsetRect( &rect , border , border );
1837 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1840 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1842 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1843 RGBForeColor( &face
);
1844 MoveTo( left
+ 0 , top
+ h
- 2 );
1845 LineTo( left
+ 0 , top
+ 0 );
1846 LineTo( left
+ w
- 2 , top
+ 0 );
1848 MoveTo( left
+ 2 , top
+ h
- 3 );
1849 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1850 LineTo( left
+ w
- 3 , top
+ 2 );
1852 RGBForeColor( sunken
? &face
: &darkShadow
);
1853 MoveTo( left
+ 0 , top
+ h
- 1 );
1854 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1855 LineTo( left
+ w
- 1 , top
+ 0 );
1857 RGBForeColor( sunken
? &lightShadow
: &white
);
1858 MoveTo( left
+ 1 , top
+ h
- 3 );
1859 LineTo( left
+ 1, top
+ 1 );
1860 LineTo( left
+ w
- 3 , top
+ 1 );
1862 RGBForeColor( sunken
? &white
: &lightShadow
);
1863 MoveTo( left
+ 1 , top
+ h
- 2 );
1864 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1865 LineTo( left
+ w
- 2 , top
+ 1 );
1867 RGBForeColor( sunken
? &darkShadow
: &face
);
1868 MoveTo( left
+ 2 , top
+ h
- 4 );
1869 LineTo( left
+ 2 , top
+ 2 );
1870 LineTo( left
+ w
- 4 , top
+ 2 );
1873 else if (HasFlag(wxSIMPLE_BORDER
))
1875 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1876 RGBForeColor( &darkShadow
) ;
1877 FrameRect( &rect
) ;
1881 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1883 if ( child
== m_hScrollBar
)
1884 m_hScrollBar
= NULL
;
1885 if ( child
== m_vScrollBar
)
1886 m_vScrollBar
= NULL
;
1888 wxWindowBase::RemoveChild( child
) ;
1891 // New function that will replace some of the above.
1892 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1893 int range
, bool refresh
)
1895 if ( orient
== wxHORIZONTAL
)
1899 if ( range
== 0 || thumbVisible
>= range
)
1901 if ( m_hScrollBar
->IsShown() )
1902 m_hScrollBar
->Show(false) ;
1906 if ( !m_hScrollBar
->IsShown() )
1907 m_hScrollBar
->Show(true) ;
1908 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1916 if ( range
== 0 || thumbVisible
>= range
)
1918 if ( m_vScrollBar
->IsShown() )
1919 m_vScrollBar
->Show(false) ;
1923 if ( !m_vScrollBar
->IsShown() )
1924 m_vScrollBar
->Show(true) ;
1925 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1929 MacRepositionScrollBars() ;
1932 // Does a physical scroll
1933 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1935 if( dx
== 0 && dy
==0 )
1940 wxClientDC
dc(this) ;
1941 wxMacPortSetter
helper(&dc
) ;
1943 int width
, height
;
1944 GetClientSize( &width
, &height
) ;
1951 // TODO take out the boundaries
1952 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
1954 RgnHandle updateRgn
= NewRgn() ;
1957 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1958 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1959 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1961 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1963 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
1964 // but it seems the update only refreshes the background of the control, rather than calling
1965 // kEventControlDraw, so we need to force a proper update here. There has to be a better
1966 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
1969 // we also have to scroll the update rgn in this rectangle
1970 // in order not to loose updates
1972 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
1973 RgnHandle formerUpdateRgn
= NewRgn() ;
1974 RgnHandle scrollRgn
= NewRgn() ;
1975 RectRgn( scrollRgn
, &scrollrect
) ;
1976 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1978 LocalToGlobal( &pt
) ;
1979 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1980 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1981 if ( !EmptyRgn( formerUpdateRgn
) )
1983 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1984 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1985 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1987 InvalWindowRgn(rootWindow
, updateRgn
) ;
1988 DisposeRgn( updateRgn
) ;
1989 DisposeRgn( formerUpdateRgn
) ;
1990 DisposeRgn( scrollRgn
) ;
1994 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1996 wxWindowMac
*child
= node
->GetData();
1997 if (child
== m_vScrollBar
) continue;
1998 if (child
== m_hScrollBar
) continue;
1999 if (child
->IsTopLevel()) continue;
2002 child
->GetPosition( &x
, &y
);
2004 child
->GetSize( &w
, &h
);
2008 if (rect
->Intersects(rc
))
2009 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2013 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2017 // TODO remove, was moved higher up Update() ;
2021 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2023 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2025 wxScrollWinEvent wevent
;
2026 wevent
.SetPosition(event
.GetPosition());
2027 wevent
.SetOrientation(event
.GetOrientation());
2028 wevent
.m_eventObject
= this;
2030 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2031 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2032 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2033 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2034 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2035 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2036 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2037 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2038 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2039 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2040 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2041 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2042 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2043 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2044 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2045 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2047 GetEventHandler()->ProcessEvent(wevent
);
2051 // Get the window with the focus
2052 wxWindowMac
*wxWindowBase::FindFocus()
2054 return gFocusWindow
;
2057 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2059 // panel wants to track the window which was the last to have focus in it,
2060 // so we want to set ourselves as the window which last had focus
2062 // notice that it's also important to do it upwards the tree becaus
2063 // otherwise when the top level panel gets focus, it won't set it back to
2064 // us, but to some other sibling
2066 // CS:don't know if this is still needed:
2067 //wxChildFocusEvent eventFocus(this);
2068 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2073 void wxWindowMac::OnInternalIdle()
2075 // This calls the UI-update mechanism (querying windows for
2076 // menu/toolbar/control state information)
2077 if (wxUpdateUIEvent::CanUpdate(this))
2078 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2081 // Raise the window to the top of the Z order
2082 void wxWindowMac::Raise()
2086 // Lower the window to the bottom of the Z order
2087 void wxWindowMac::Lower()
2092 // static wxWindow *gs_lastWhich = NULL;
2094 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2096 // first trigger a set cursor event
2098 wxPoint clientorigin
= GetClientAreaOrigin() ;
2099 wxSize clientsize
= GetClientSize() ;
2101 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2103 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2105 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2106 if ( processedEvtSetCursor
&& event
.HasCursor() )
2108 cursor
= event
.GetCursor() ;
2113 // the test for processedEvtSetCursor is here to prevent using m_cursor
2114 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2115 // it - this is a way to say that our cursor shouldn't be used for this
2117 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2127 cursor
= *wxSTANDARD_CURSOR
;
2131 cursor
.MacInstall() ;
2133 return cursor
.Ok() ;
2136 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2140 return m_tooltip
->GetTip() ;
2142 return wxEmptyString
;
2145 void wxWindowMac::Update()
2147 #if TARGET_API_MAC_OSX
2148 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2150 ::Draw1Control( (ControlRef
) m_macControl
) ;
2154 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2156 wxTopLevelWindowMac
* win
= NULL
;
2157 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2160 win
= wxFindWinFromMacWindow( window
) ;
2164 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2168 RgnHandle visRgn
= NewRgn() ;
2169 RgnHandle tempRgn
= NewRgn() ;
2170 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2172 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2173 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2175 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2176 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2185 if ( includeOuterStructures
)
2186 InsetRect( &r
, -3 , -3 ) ;
2187 RectRgn( visRgn
, &r
) ;
2188 if ( !IsTopLevel() )
2190 wxWindow
* child
= this ;
2191 wxWindow
* parent
= child
->GetParent() ;
2196 // we have to find a better clipping algorithm here, in order not to clip things
2197 // positioned like status and toolbar
2198 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2200 size
= parent
->GetSize() ;
2205 size
= parent
->GetClientSize() ;
2206 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2210 parent
->MacWindowToRootWindow( &x
, &y
) ;
2211 MacRootWindowToWindow( &x
, &y
) ;
2213 SetRectRgn( tempRgn
,
2214 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2215 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2216 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2218 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2219 if ( parent
->IsTopLevel() )
2222 parent
= child
->GetParent() ;
2227 wxRegion vis
= visRgn
;
2228 DisposeRgn( visRgn
) ;
2229 DisposeRgn( tempRgn
) ;
2234 This function must not change the updatergn !
2236 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2238 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2239 bool handled
= false ;
2241 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2243 RgnHandle newupdate
= NewRgn() ;
2244 wxSize point
= GetClientSize() ;
2245 wxPoint origin
= GetClientAreaOrigin() ;
2246 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2247 SectRgn( newupdate
, updatergn
, newupdate
) ;
2248 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2249 m_updateRegion
= newupdate
;
2250 DisposeRgn( newupdate
) ;
2253 if ( !EmptyRgn(updatergn
) )
2255 wxWindowDC
dc(this);
2256 if (!EmptyRgn(updatergn
))
2257 dc
.SetClippingRegion(wxRegion(updatergn
));
2259 wxEraseEvent
eevent( GetId(), &dc
);
2260 eevent
.SetEventObject( this );
2261 GetEventHandler()->ProcessEvent( eevent
);
2263 if ( !m_updateRegion
.Empty() )
2265 // paint the window itself
2267 event
.m_timeStamp
= time
;
2268 event
.SetEventObject(this);
2269 handled
= GetEventHandler()->ProcessEvent(event
);
2271 // paint custom borders
2272 wxNcPaintEvent
eventNc( GetId() );
2273 eventNc
.SetEventObject( this );
2274 GetEventHandler()->ProcessEvent( eventNc
);
2280 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2282 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2283 // updatergn is always already clipped to our boundaries
2284 // if we are in compositing mode then it is in relative to the upper left of the control
2285 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2286 // of the toplevel window
2287 // it is in window coordinates, not in client coordinates
2289 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2290 RgnHandle ownUpdateRgn
= NewRgn() ;
2291 CopyRgn( updatergn
, ownUpdateRgn
) ;
2293 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2296 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2297 RgnHandle controlRgn
= NewRgn();
2298 RectRgn( controlRgn
, &bounds
);
2299 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2300 // the window update region
2301 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2302 DisposeRgn( controlRgn
);
2304 //KO: convert ownUpdateRgn to local coordinates
2305 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2308 MacDoRedraw( ownUpdateRgn
, time
) ;
2309 DisposeRgn( ownUpdateRgn
) ;
2313 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2315 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2319 if ( iter
->IsTopLevel() )
2320 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2322 iter
= iter
->GetParent() ;
2324 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2328 void wxWindowMac::MacCreateScrollBars( long style
)
2330 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2332 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2333 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2335 GetClientSize( &width
, &height
) ;
2337 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2338 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2339 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2340 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2342 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2343 vSize
, wxVERTICAL
);
2345 if ( style
& wxVSCROLL
)
2351 m_vScrollBar
->Show(false) ;
2353 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2354 hSize
, wxHORIZONTAL
);
2355 if ( style
& wxHSCROLL
)
2360 m_hScrollBar
->Show(false) ;
2363 // because the create does not take into account the client area origin
2364 MacRepositionScrollBars() ; // we might have a real position shift
2367 void wxWindowMac::MacRepositionScrollBars()
2369 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2370 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2372 // get real client area
2376 GetSize( &width
, &height
) ;
2378 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2379 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2381 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2382 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2383 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2384 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2390 GetSize( &w
, &h
) ;
2392 MacClientToRootWindow( &x
, &y
) ;
2393 MacClientToRootWindow( &w
, &h
) ;
2395 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2397 int totW
= 10000 , totH
= 10000;
2400 if ( iter
->IsTopLevel() )
2402 iter
->GetSize( &totW
, &totH
) ;
2406 iter
= iter
->GetParent() ;
2434 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2438 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2442 bool wxWindowMac::AcceptsFocus() const
2444 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2447 void wxWindowMac::MacSuperChangedPosition()
2449 // only window-absolute structures have to be moved i.e. controls
2451 wxWindowListNode
*node
= GetChildren().GetFirst();
2454 wxWindowMac
*child
= node
->GetData();
2455 child
->MacSuperChangedPosition() ;
2456 node
= node
->GetNext();
2460 void wxWindowMac::MacTopLevelWindowChangedPosition()
2462 // only screen-absolute structures have to be moved i.e. glcanvas
2464 wxWindowListNode
*node
= GetChildren().GetFirst();
2467 wxWindowMac
*child
= node
->GetData();
2468 child
->MacTopLevelWindowChangedPosition() ;
2469 node
= node
->GetNext();
2473 long wxWindowMac::MacGetLeftBorderSize( ) const
2478 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2481 #if wxMAC_USE_THEME_BORDER
2482 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2486 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2489 #if wxMAC_USE_THEME_BORDER
2490 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2494 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2501 long wxWindowMac::MacGetRightBorderSize( ) const
2503 // they are all symmetric in mac themes
2504 return MacGetLeftBorderSize() ;
2507 long wxWindowMac::MacGetTopBorderSize( ) const
2509 // they are all symmetric in mac themes
2510 return MacGetLeftBorderSize() ;
2513 long wxWindowMac::MacGetBottomBorderSize( ) const
2515 // they are all symmetric in mac themes
2516 return MacGetLeftBorderSize() ;
2519 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2521 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2524 // Find the wxWindowMac at the current mouse position, returning the mouse
2526 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2528 pt
= wxGetMousePosition();
2529 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2533 // Get the current mouse position.
2534 wxPoint
wxGetMousePosition()
2537 wxGetMousePosition(& x
, & y
);
2538 return wxPoint(x
, y
);
2541 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2543 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2545 // copied from wxGTK : CS
2546 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2549 // (a) it's a command event and so is propagated to the parent
2550 // (b) under MSW it can be generated from kbd too
2551 // (c) it uses screen coords (because of (a))
2552 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2554 this->ClientToScreen(event
.GetPosition()));
2555 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2558 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2564 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2566 // OS Needs it in tlw content area coordinates
2567 MacClientToRootWindow( &x
, &y
) ;
2571 // OS Needs it in window not client coordinates
2572 wxPoint origin
= GetClientAreaOrigin() ;
2577 SInt16 controlpart
;
2582 short modifiers
= 0;
2584 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2585 modifiers
|= btnState
;
2587 if ( event
.m_shiftDown
)
2588 modifiers
|= shiftKey
;
2590 if ( event
.m_controlDown
)
2591 modifiers
|= controlKey
;
2593 if ( event
.m_altDown
)
2594 modifiers
|= optionKey
;
2596 if ( event
.m_metaDown
)
2597 modifiers
|= cmdKey
;
2599 bool handled
= false ;
2601 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2603 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2604 wxTheApp
->s_lastMouseDown
= 0 ;
2605 if ( controlpart
!= kControlNoPart
)
2607 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2620 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2622 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2625 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2629 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2630 Rect bounds
= { y
, x
, y
+h
, x
+w
};