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>
57 #include <HIToolbox/HIView.h>
60 #if wxUSE_DRAG_AND_DROP
66 extern wxList wxPendingDelete
;
67 wxWindowMac
* gFocusWindow
= NULL
;
69 #ifdef __WXUNIVERSAL__
70 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
72 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
73 #endif // __WXUNIVERSAL__/__WXMAC__
75 #if !USE_SHARED_LIBRARY
77 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
78 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
79 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
80 // TODO EVT_PAINT(wxWindowMac::OnPaint)
81 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
82 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
83 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
89 #define wxMAC_DEBUG_REDRAW 0
90 #ifndef wxMAC_DEBUG_REDRAW
91 #define wxMAC_DEBUG_REDRAW 0
94 #define wxMAC_USE_THEME_BORDER 0
96 // ---------------------------------------------------------------------------
98 // ---------------------------------------------------------------------------
100 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
101 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
103 static const EventTypeSpec eventList
[] =
105 #if TARGET_API_MAC_OSX
106 { kEventClassControl
, kEventControlDraw
} ,
107 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
108 // { kEventClassControl , kEventControlBoundsChanged } ,
114 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
116 OSStatus result
= eventNotHandledErr
;
118 wxMacCarbonEvent
cEvent( event
) ;
120 ControlRef controlRef
;
121 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
123 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
125 switch( GetEventKind( event
) )
127 case kEventControlDraw
:
129 RgnHandle updateRgn
= cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
) ;
130 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
132 #if 0 // in case we would need a coregraphics compliant background erase first
133 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
134 if ( thisWindow
->MacIsUserPane() )
137 err
= HIViewGetBounds( controlRef
, &bounds
);
138 CGContextSetRGBFillColor( cgContext
, 1 , 1 , 1 , 1 );
139 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
140 CGContextFillRect( cgContext
, bounds
);
143 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
146 result
= eventNotHandledErr
;
155 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
157 OSStatus result
= eventNotHandledErr
;
159 switch ( GetEventClass( event
) )
161 case kEventClassControl
:
162 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
170 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
172 // ---------------------------------------------------------------------------
173 // UserPane events for non OSX builds
174 // ---------------------------------------------------------------------------
176 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
178 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
179 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
180 win
->MacControlUserPaneDrawProc(part
) ;
183 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
185 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
186 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
187 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
190 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
192 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
193 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
194 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
197 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
199 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
200 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
201 win
->MacControlUserPaneIdleProc() ;
204 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
206 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
207 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
208 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
211 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
213 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
214 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
215 win
->MacControlUserPaneActivateProc(activating
) ;
218 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
220 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
221 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
222 return win
->MacControlUserPaneFocusProc(action
) ;
225 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
227 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
228 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
229 win
->MacControlUserPaneBackgroundProc(info
) ;
232 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
234 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
237 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
239 return kControlNoPart
;
242 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
244 return kControlNoPart
;
247 void wxWindowMac::MacControlUserPaneIdleProc()
251 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
253 return kControlNoPart
;
256 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
260 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
262 return kControlNoPart
;
265 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
269 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
270 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
271 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
272 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
273 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
274 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
275 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
276 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
278 // ===========================================================================
280 // ===========================================================================
282 wxList
wxWinMacControlList(wxKEY_INTEGER
);
284 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
286 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
289 return (wxControl
*)node
->GetData();
292 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
294 // adding NULL ControlRef is (first) surely a result of an error and
295 // (secondly) breaks native event processing
296 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
298 if ( !wxWinMacControlList
.Find((long)inControl
) )
299 wxWinMacControlList
.Append((long)inControl
, control
);
302 void wxRemoveMacControlAssociation(wxWindow
*control
)
304 wxWinMacControlList
.DeleteObject(control
);
308 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
310 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
312 // we have to setup the brush in the current port and return noErr
313 // or return an error code so that the control manager walks further up the
314 // hierarchy to find a correct background
316 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
318 OSStatus status
= paramErr
;
321 case kControlMsgApplyTextColor
:
323 case kControlMsgSetUpBackground
:
325 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
329 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
333 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
335 // this clipping is only needed for non HIView
337 RgnHandle clip
= NewRgn() ;
340 wx
->MacWindowToRootWindow( &x
,&y
) ;
341 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
342 OffsetRgn( clip
, x
, y
) ;
349 else if ( wx->MacIsUserPane() )
351 // if we don't have a valid brush for such a control, we have to call the
352 // setup of our parent ourselves
353 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
366 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
367 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
371 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
374 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
379 // ----------------------------------------------------------------------------
380 // constructors and such
381 // ----------------------------------------------------------------------------
383 void wxWindowMac::Init()
385 m_backgroundTransparent
= FALSE
;
387 // as all windows are created with WS_VISIBLE style...
390 m_hScrollBar
= NULL
;
391 m_vScrollBar
= NULL
;
392 m_macBackgroundBrush
= wxNullBrush
;
394 m_macControl
= NULL
;
396 m_macIsUserPane
= TRUE
;
398 // make sure all proc ptrs are available
400 if ( gControlUserPaneDrawUPP
== NULL
)
402 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
403 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
404 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
405 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
406 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
407 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
408 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
409 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
411 if ( wxMacLiveScrollbarActionUPP
== NULL
)
413 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
416 if ( wxMacSetupControlBackgroundUPP
== NULL
)
418 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
424 wxWindowMac::~wxWindowMac()
428 m_isBeingDeleted
= TRUE
;
430 #ifndef __WXUNIVERSAL__
431 // VS: make sure there's no wxFrame with last focus set to us:
432 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
434 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
437 if ( frame
->GetLastFocus() == this )
439 frame
->SetLastFocus((wxWindow
*)NULL
);
444 #endif // __WXUNIVERSAL__
446 // wxRemoveMacControlAssociation( this ) ;
447 // If we delete an item, we should initialize the parent panel,
448 // because it could now be invalid.
449 wxWindow
*parent
= GetParent() ;
452 if (parent
->GetDefaultItem() == (wxButton
*) this)
453 parent
->SetDefaultItem(NULL
);
455 if ( (ControlRef
) m_macControl
)
457 // in case the callback might be called during destruction
458 wxRemoveMacControlAssociation( this) ;
459 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
460 ::DisposeControl( (ControlRef
) m_macControl
) ;
461 m_macControl
= NULL
;
464 if ( g_MacLastWindow
== this )
466 g_MacLastWindow
= NULL
;
469 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
472 if ( frame
->GetLastFocus() == this )
473 frame
->SetLastFocus( NULL
) ;
476 if ( gFocusWindow
== this )
478 gFocusWindow
= NULL
;
483 // delete our drop target if we've got one
484 #if wxUSE_DRAG_AND_DROP
485 if ( m_dropTarget
!= NULL
)
490 #endif // wxUSE_DRAG_AND_DROP
495 void wxWindowMac::MacInstallEventHandler()
497 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
498 GetEventTypeCount(eventList
), eventList
, this,
499 (EventHandlerRef
*)&m_macControlEventHandler
);
504 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
508 const wxString
& name
)
510 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
512 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
515 parent
->AddChild(this);
517 m_windowVariant
= parent
->GetWindowVariant() ;
519 if ( m_macIsUserPane
)
521 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
523 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
/*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
525 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
527 MacPostControlCreate(pos
,size
) ;
528 #if !TARGET_API_MAC_OSX
529 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
530 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
531 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
532 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
533 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
534 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
535 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
536 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
537 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
538 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
539 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
540 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
541 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
542 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
543 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
544 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
547 #ifndef __WXUNIVERSAL__
548 // Don't give scrollbars to wxControls unless they ask for them
549 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
550 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
552 MacCreateScrollBars( style
) ;
556 wxWindowCreateEvent
event(this);
557 GetEventHandler()->AddPendingEvent(event
);
562 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
564 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
566 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
567 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
569 MacInstallEventHandler();
571 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
572 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
573 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
575 // adjust font, controlsize etc
576 DoSetWindowVariant( m_windowVariant
) ;
578 #if !TARGET_API_MAC_OSX
579 // eventually we can fix some clipping issues be reactivating this hook
580 //if ( m_macIsUserPane )
581 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
584 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
586 wxSize new_size
= size
;
587 if (!m_macIsUserPane
)
589 wxSize
best_size( DoGetBestSize() );
592 new_size
.x
= best_size
.x
;
595 new_size
.y
= best_size
.y
;
597 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
600 SetCursor( *wxSTANDARD_CURSOR
) ;
604 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
606 wxASSERT( m_macControl
!= NULL
) ;
608 m_windowVariant
= variant
;
611 ThemeFontID themeFont
= kThemeSystemFont
;
613 // we will get that from the settings later
614 // and make this NORMAL later, but first
615 // we have a few calculations that we must fix
619 case wxWINDOW_VARIANT_NORMAL
:
620 size
= kControlSizeNormal
;
621 themeFont
= kThemeSystemFont
;
623 case wxWINDOW_VARIANT_SMALL
:
624 size
= kControlSizeSmall
;
625 themeFont
= kThemeSmallSystemFont
;
627 case wxWINDOW_VARIANT_MINI
:
628 if (UMAGetSystemVersion() >= 0x1030 )
630 // not always defined in the headers
636 size
= kControlSizeSmall
;
637 themeFont
= kThemeSmallSystemFont
;
640 case wxWINDOW_VARIANT_LARGE
:
641 size
= kControlSizeLarge
;
642 themeFont
= kThemeSystemFont
;
645 wxFAIL_MSG(_T("unexpected window variant"));
648 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
651 font
.MacCreateThemeFont( themeFont
) ;
655 void wxWindowMac::MacUpdateControlFont()
657 ControlFontStyleRec fontStyle
;
658 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
660 switch( m_font
.MacGetThemeFontID() )
662 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
663 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
664 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
665 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
667 fontStyle
.flags
= kControlUseFontMask
;
671 fontStyle
.font
= m_font
.MacGetFontNum() ;
672 fontStyle
.style
= m_font
.MacGetFontStyle() ;
673 fontStyle
.size
= m_font
.MacGetFontSize() ;
674 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
677 fontStyle
.just
= teJustLeft
;
678 fontStyle
.flags
|= kControlUseJustMask
;
679 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
680 fontStyle
.just
= teJustCenter
;
681 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
682 fontStyle
.just
= teJustRight
;
685 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
686 fontStyle
.flags
|= kControlUseForeColorMask
;
688 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
692 bool wxWindowMac::SetFont(const wxFont
& font
)
694 bool retval
= !wxWindowBase::SetFont( font
) ;
696 MacUpdateControlFont() ;
701 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
703 if ( !wxWindowBase::SetForegroundColour(col
) )
706 MacUpdateControlFont() ;
711 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
713 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
717 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
719 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
721 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
723 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
727 brush
.SetColour( col
) ;
729 MacSetBackgroundBrush( brush
) ;
731 MacUpdateControlFont() ;
737 bool wxWindowMac::MacCanFocus() const
739 wxASSERT( m_macControl
!= NULL
) ;
745 void wxWindowMac::SetFocus()
747 if ( gFocusWindow
== this )
750 if ( AcceptsFocus() )
756 if ( gFocusWindow
->m_caret
)
758 gFocusWindow
->m_caret
->OnKillFocus();
760 #endif // wxUSE_CARET
761 #ifndef __WXUNIVERSAL__
762 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
763 // TODO we must use the built-in focusing
764 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
766 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
767 control
->MacRedrawControl() ;
770 // Without testing the window id, for some reason
771 // a kill focus event can still be sent to
772 // the control just being focussed.
773 int thisId
= this->m_windowId
;
774 int gFocusWindowId
= gFocusWindow
->m_windowId
;
775 if (gFocusWindowId
!= thisId
)
777 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
778 event
.SetEventObject(gFocusWindow
);
779 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
782 gFocusWindow
= this ;
788 m_caret
->OnSetFocus();
790 #endif // wxUSE_CARET
791 // panel wants to track the window which was the last to have focus in it
792 wxChildFocusEvent
eventFocus(this);
793 GetEventHandler()->ProcessEvent(eventFocus
);
795 #ifndef __WXUNIVERSAL__
796 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
797 if ( control
&& control
->GetHandle() )
799 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
802 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
803 event
.SetEventObject(this);
804 GetEventHandler()->ProcessEvent(event
) ;
810 void wxWindowMac::DoCaptureMouse()
812 wxTheApp
->s_captureWindow
= this ;
815 wxWindow
* wxWindowBase::GetCapture()
817 return wxTheApp
->s_captureWindow
;
820 void wxWindowMac::DoReleaseMouse()
822 wxTheApp
->s_captureWindow
= NULL
;
825 #if wxUSE_DRAG_AND_DROP
827 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
829 if ( m_dropTarget
!= 0 ) {
833 m_dropTarget
= pDropTarget
;
834 if ( m_dropTarget
!= 0 )
842 // Old style file-manager drag&drop
843 void wxWindowMac::DragAcceptFiles(bool accept
)
848 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
849 int& w
, int& h
) const
852 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
857 w
= bounds
.right
- bounds
.left
;
858 h
= bounds
.bottom
- bounds
.top
;
860 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
863 Point tlworigin
= { 0 , 0 } ;
866 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
867 ::LocalToGlobal( &tlworigin
) ;
874 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
877 int& w
, int& h
) const
881 // todo the default calls may be used as soon as PostCreateControl Is moved here
882 w
= size
.x
; // WidthDefault( size.x );
883 h
= size
.y
; // HeightDefault( size.y ) ;
884 #if !TARGET_API_MAC_OSX
885 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
892 void wxWindowMac::DoGetSize(int *x
, int *y
) const
894 #if TARGET_API_MAC_OSX
895 int x1
, y1
, w1
,h1
;
896 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
902 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
903 if(x
) *x
= bounds
.right
- bounds
.left
;
904 if(y
) *y
= bounds
.bottom
- bounds
.top
;
908 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
910 #if TARGET_API_MAC_OSX
911 int x1
, y1
, w1
,h1
;
912 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
915 wxWindow
*parent
= GetParent();
918 wxPoint
pt(parent
->GetClientAreaOrigin());
927 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
928 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
930 int xx
= bounds
.left
;
931 int yy
= bounds
.top
;
933 if ( !GetParent()->IsTopLevel() )
935 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
941 wxPoint
pt(GetParent()->GetClientAreaOrigin());
950 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
952 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
954 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
957 Point localwhere
= {0,0} ;
959 if(x
) localwhere
.h
= * x
;
960 if(y
) localwhere
.v
= * y
;
962 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
963 ::GlobalToLocal( &localwhere
) ;
964 if(x
) *x
= localwhere
.h
;
965 if(y
) *y
= localwhere
.v
;
968 MacRootWindowToWindow( x
, y
) ;
970 wxPoint origin
= GetClientAreaOrigin() ;
971 if(x
) *x
-= origin
.x
;
972 if(y
) *y
-= origin
.y
;
975 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
977 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
978 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
980 wxPoint origin
= GetClientAreaOrigin() ;
981 if(x
) *x
+= origin
.x
;
982 if(y
) *y
+= origin
.y
;
984 MacWindowToRootWindow( x
, y
) ;
987 Point localwhere
= { 0,0 };
988 if(x
) localwhere
.h
= * x
;
989 if(y
) localwhere
.v
= * y
;
991 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
992 ::LocalToGlobal( &localwhere
) ;
993 if(x
) *x
= localwhere
.h
;
994 if(y
) *y
= localwhere
.v
;
998 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1000 wxPoint origin
= GetClientAreaOrigin() ;
1001 if(x
) *x
+= origin
.x
;
1002 if(y
) *y
+= origin
.y
;
1004 MacWindowToRootWindow( x
, y
) ;
1007 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1009 MacRootWindowToWindow( x
, y
) ;
1011 wxPoint origin
= GetClientAreaOrigin() ;
1012 if(x
) *x
-= origin
.x
;
1013 if(y
) *y
-= origin
.y
;
1016 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1018 #if TARGET_API_MAC_OSX
1020 if ( x
) pt
.x
= *x
;
1021 if ( y
) pt
.y
= *y
;
1023 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1025 if ( x
) *x
= (int) pt
.x
;
1026 if ( y
) *y
= (int) pt
.y
;
1028 if ( !IsTopLevel() )
1031 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1032 if(x
) *x
+= bounds
.left
;
1033 if(y
) *y
+= bounds
.top
;
1038 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1043 MacWindowToRootWindow( &x1
, &y1
) ;
1048 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1050 #if TARGET_API_MAC_OSX
1052 if ( x
) pt
.x
= *x
;
1053 if ( y
) pt
.y
= *y
;
1055 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1057 if ( x
) *x
= (int) pt
.x
;
1058 if ( y
) *y
= (int) pt
.y
;
1060 if ( !IsTopLevel() )
1063 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1064 if(x
) *x
-= bounds
.left
;
1065 if(y
) *y
-= bounds
.top
;
1070 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1075 MacRootWindowToWindow( &x1
, &y1
) ;
1080 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1082 wxSize sizeTotal
= size
;
1084 RgnHandle rgn
= NewRgn() ;
1088 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1090 GetRegionBounds( rgn
, &content
) ;
1095 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1098 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1099 #if !TARGET_API_MAC_OSX
1100 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1103 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1104 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1106 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1107 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1113 // Get size *available for subwindows* i.e. excluding menu bar etc.
1114 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1118 RgnHandle rgn
= NewRgn() ;
1120 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1122 GetRegionBounds( rgn
, &content
) ;
1127 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1129 #if !TARGET_API_MAC_OSX
1131 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1132 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1134 ww
= content
.right
- content
.left
;
1135 hh
= content
.bottom
- content
.top
;
1137 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1138 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1140 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1146 GetSize( &w
, &h
) ;
1148 MacClientToRootWindow( &x1
, &y1
) ;
1149 MacClientToRootWindow( &w
, &h
) ;
1151 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1153 int totW
= 10000 , totH
= 10000;
1156 if ( iter
->IsTopLevel() )
1158 iter
->GetSize( &totW
, &totH
) ;
1162 iter
= iter
->GetParent() ;
1165 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1167 hh
-= MAC_SCROLLBAR_SIZE
;
1173 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1175 ww
-= MAC_SCROLLBAR_SIZE
;
1187 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1189 if (m_cursor
== cursor
)
1192 if (wxNullCursor
== cursor
)
1194 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1199 if ( ! wxWindowBase::SetCursor( cursor
) )
1203 wxASSERT_MSG( m_cursor
.Ok(),
1204 wxT("cursor must be valid after call to the base version"));
1208 TODO why do we have to use current coordinates ?
1211 wxWindowMac *mouseWin ;
1214 // Change the cursor NOW if we're within the correct window
1217 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1219 if ( mouseWin == this && !wxIsBusy() )
1221 m_cursor.MacInstall() ;
1227 m_cursor
.MacInstall() ;
1234 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1236 menu
->SetInvokingWindow(this);
1238 ClientToScreen( &x
, &y
) ;
1240 menu
->MacBeforeDisplay( true ) ;
1241 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1242 if ( HiWord(menuResult
) != 0 )
1245 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1246 wxMenuItem
* item
= NULL
;
1248 item
= menu
->FindItem(id
, &realmenu
) ;
1249 if (item
->IsCheckable())
1251 item
->Check( !item
->IsChecked() ) ;
1253 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1255 menu
->MacAfterDisplay( true ) ;
1257 menu
->SetInvokingWindow(NULL
);
1263 // ----------------------------------------------------------------------------
1265 // ----------------------------------------------------------------------------
1269 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1271 wxWindowBase::DoSetToolTip(tooltip
);
1274 m_tooltip
->SetWindow(this);
1277 #endif // wxUSE_TOOLTIPS
1279 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1281 int former_x
, former_y
, former_w
, former_h
;
1282 #if !TARGET_API_MAC_OSX
1283 DoGetPosition( &former_x
, &former_y
) ;
1284 DoGetSize( &former_w
, &former_h
) ;
1286 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1289 int actualWidth
= width
;
1290 int actualHeight
= height
;
1294 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1295 actualWidth
= m_minWidth
;
1296 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1297 actualHeight
= m_minHeight
;
1298 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1299 actualWidth
= m_maxWidth
;
1300 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1301 actualHeight
= m_maxHeight
;
1303 bool doMove
= false ;
1304 bool doResize
= false ;
1306 if ( actualX
!= former_x
|| actualY
!= former_y
)
1310 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1315 if ( doMove
|| doResize
)
1317 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1318 #if TARGET_API_MAC_OSX
1319 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1322 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1324 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1326 MacRepositionScrollBars() ;
1329 wxPoint
point(actualX
,actualY
);
1330 wxMoveEvent
event(point
, m_windowId
);
1331 event
.SetEventObject(this);
1332 GetEventHandler()->ProcessEvent(event
) ;
1336 MacRepositionScrollBars() ;
1337 wxSize
size(actualWidth
, actualHeight
);
1338 wxSizeEvent
event(size
, m_windowId
);
1339 event
.SetEventObject(this);
1340 GetEventHandler()->ProcessEvent(event
);
1346 wxSize
wxWindowMac::DoGetBestSize() const
1348 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1349 short baselineoffset
;
1350 int bestWidth
, bestHeight
;
1351 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1353 if ( EmptyRect( &bestsize
) )
1356 bestsize
.left
= bestsize
.top
= 0 ;
1357 bestsize
.right
= 16 ;
1358 bestsize
.bottom
= 16 ;
1359 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1361 bestsize
.bottom
= 16 ;
1363 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1365 bestsize
.bottom
= 24 ;
1369 // return wxWindowBase::DoGetBestSize() ;
1373 bestWidth
= bestsize
.right
- bestsize
.left
;
1374 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1375 if ( bestHeight
< 10 )
1378 return wxSize(bestWidth
, bestHeight
);
1382 // set the size of the window: if the dimensions are positive, just use them,
1383 // but if any of them is equal to -1, it means that we must find the value for
1384 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1385 // which case -1 is a valid value for x and y)
1387 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1388 // the width/height to best suit our contents, otherwise we reuse the current
1390 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1392 // get the current size and position...
1393 int currentX
, currentY
;
1394 GetPosition(¤tX
, ¤tY
);
1396 int currentW
,currentH
;
1397 GetSize(¤tW
, ¤tH
);
1399 // ... and don't do anything (avoiding flicker) if it's already ok
1400 if ( x
== currentX
&& y
== currentY
&&
1401 width
== currentW
&& height
== currentH
)
1404 MacRepositionScrollBars() ; // we might have a real position shift
1408 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1410 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1413 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1415 wxSize
size(-1, -1);
1418 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1420 size
= DoGetBestSize();
1425 // just take the current one
1432 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1436 size
= DoGetBestSize();
1438 //else: already called DoGetBestSize() above
1444 // just take the current one
1449 DoMoveWindow(x
, y
, width
, height
);
1453 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1455 RgnHandle rgn
= NewRgn() ;
1457 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1458 GetRegionBounds( rgn
, &content
) ;
1460 #if !TARGET_API_MAC_OSX
1462 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1463 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1466 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1469 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1471 if ( clientheight
!= -1 || clientheight
!= -1 )
1473 int currentclientwidth
, currentclientheight
;
1474 int currentwidth
, currentheight
;
1476 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1477 GetSize( ¤twidth
, ¤theight
) ;
1479 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1480 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1484 void wxWindowMac::SetTitle(const wxString
& title
)
1486 m_label
= wxStripMenuCodes(title
) ;
1490 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1495 wxString
wxWindowMac::GetTitle() const
1500 void wxWindowMac::MacPropagateVisibilityChanged()
1502 MacVisibilityChanged() ;
1504 wxWindowListNode
*node
= GetChildren().GetFirst();
1507 wxWindowMac
*child
= node
->GetData();
1508 if ( child
->IsShown() )
1509 child
->MacPropagateVisibilityChanged( ) ;
1510 node
= node
->GetNext();
1514 bool wxWindowMac::Show(bool show
)
1516 if ( !wxWindowBase::Show(show
) )
1519 // TODO use visibilityChanged Carbon Event for OSX
1520 bool former
= MacIsReallyShown() ;
1522 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1523 if ( former
!= MacIsReallyShown() )
1524 MacPropagateVisibilityChanged() ;
1528 bool wxWindowMac::MacIsReallyShown()
1530 // only under OSX the visibility of the TLW is taken into account
1531 #if TARGET_API_MAC_OSX
1532 return IsControlVisible( (ControlRef
) m_macControl
) ;
1534 wxWindow
* win
= this ;
1535 while( win
->IsShown() )
1537 if ( win
->IsTopLevel() )
1540 win
= win
->GetParent() ;
1549 void wxWindowMac::MacVisibilityChanged()
1553 void wxWindowMac::MacPropagateEnabledStateChanged( )
1555 MacEnabledStateChanged() ;
1557 wxWindowListNode
*node
= GetChildren().GetFirst();
1560 wxWindowMac
*child
= node
->GetData();
1561 if ( child
->IsEnabled() )
1562 child
->MacPropagateEnabledStateChanged() ;
1563 node
= node
->GetNext();
1567 bool wxWindowMac::Enable(bool enable
)
1569 wxASSERT( m_macControl
!= NULL
) ;
1570 if ( !wxWindowBase::Enable(enable
) )
1573 bool former
= MacIsReallyEnabled() ;
1575 UMAActivateControl( (ControlRef
) m_macControl
) ;
1577 UMADeactivateControl( (ControlRef
) m_macControl
) ;
1579 if ( former
!= MacIsReallyEnabled() )
1580 MacPropagateEnabledStateChanged() ;
1584 bool wxWindowMac::MacIsReallyEnabled()
1586 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1589 void wxWindowMac::MacEnabledStateChanged()
1593 int wxWindowMac::GetCharHeight() const
1595 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1596 return dc
.GetCharHeight() ;
1599 int wxWindowMac::GetCharWidth() const
1601 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1602 return dc
.GetCharWidth() ;
1605 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1606 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1608 const wxFont
*fontToUse
= theFont
;
1610 fontToUse
= &m_font
;
1612 wxClientDC
dc( (wxWindowMac
*) this ) ;
1614 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1615 if ( externalLeading
)
1616 *externalLeading
= le
;
1626 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1627 * we always intersect with the entire window, not only with the client area
1630 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1632 #if TARGET_API_MAC_OSX
1633 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1635 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1637 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1638 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1641 if ( MacGetTopLevelWindow() == NULL )
1644 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1647 wxPoint client = GetClientAreaOrigin();
1650 int x2 = m_width - client.x;
1651 int y2 = m_height - client.y;
1653 if (IsKindOf( CLASSINFO(wxButton)))
1655 // buttons have an "aura"
1662 Rect clientrect = { y1, x1, y2, x2 };
1666 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1667 SectRect( &clientrect , &r , &clientrect ) ;
1670 if ( !EmptyRect( &clientrect ) )
1672 int top = 0 , left = 0 ;
1674 MacClientToRootWindow( &left , &top ) ;
1675 OffsetRect( &clientrect , left , top ) ;
1677 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1683 void wxWindowMac::MacRedrawControl()
1686 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1688 #if TARGET_API_MAC_CARBON
1691 wxClientDC dc(this) ;
1692 wxMacPortSetter helper(&dc) ;
1693 wxMacWindowClipper clipper(this) ;
1694 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1695 UMADrawControl( (ControlRef) m_macControl ) ;
1702 void wxWindowMac::OnPaint(wxPaintEvent& event)
1704 // why don't we skip that here ?
1708 wxWindowMac
*wxGetActiveWindow()
1710 // actually this is a windows-only concept
1714 // Coordinates relative to the window
1715 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1717 // We really don't move the mouse programmatically under Mac.
1720 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1722 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1727 event
.GetDC()->Clear() ;
1730 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1732 wxWindowDC
dc(this) ;
1733 wxMacPortSetter
helper(&dc
) ;
1735 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1738 int wxWindowMac::GetScrollPos(int orient
) const
1740 if ( orient
== wxHORIZONTAL
)
1743 return m_hScrollBar
->GetThumbPosition() ;
1748 return m_vScrollBar
->GetThumbPosition() ;
1753 // This now returns the whole range, not just the number
1754 // of positions that we can scroll.
1755 int wxWindowMac::GetScrollRange(int orient
) const
1757 if ( orient
== wxHORIZONTAL
)
1760 return m_hScrollBar
->GetRange() ;
1765 return m_vScrollBar
->GetRange() ;
1770 int wxWindowMac::GetScrollThumb(int orient
) const
1772 if ( orient
== wxHORIZONTAL
)
1775 return m_hScrollBar
->GetThumbSize() ;
1780 return m_vScrollBar
->GetThumbSize() ;
1785 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1787 if ( orient
== wxHORIZONTAL
)
1790 m_hScrollBar
->SetThumbPosition( pos
) ;
1795 m_vScrollBar
->SetThumbPosition( pos
) ;
1799 void wxWindowMac::MacPaintBorders( int left
, int top
)
1805 wxGetOsVersion( &major
, &minor
);
1807 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1808 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1810 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1811 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1812 // OS X has lighter border edges than classic:
1815 darkShadow
.red
= 0x8E8E;
1816 darkShadow
.green
= 0x8E8E;
1817 darkShadow
.blue
= 0x8E8E;
1818 lightShadow
.red
= 0xBDBD;
1819 lightShadow
.green
= 0xBDBD;
1820 lightShadow
.blue
= 0xBDBD;
1826 GetSize( &w
, &h
) ;
1827 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1829 #if wxMAC_USE_THEME_BORDER
1830 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1833 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1834 InsetRect( &rect , border , border );
1835 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1838 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1840 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1841 RGBForeColor( &face
);
1842 MoveTo( left
+ 0 , top
+ h
- 2 );
1843 LineTo( left
+ 0 , top
+ 0 );
1844 LineTo( left
+ w
- 2 , top
+ 0 );
1846 MoveTo( left
+ 2 , top
+ h
- 3 );
1847 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1848 LineTo( left
+ w
- 3 , top
+ 2 );
1850 RGBForeColor( sunken
? &face
: &darkShadow
);
1851 MoveTo( left
+ 0 , top
+ h
- 1 );
1852 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1853 LineTo( left
+ w
- 1 , top
+ 0 );
1855 RGBForeColor( sunken
? &lightShadow
: &white
);
1856 MoveTo( left
+ 1 , top
+ h
- 3 );
1857 LineTo( left
+ 1, top
+ 1 );
1858 LineTo( left
+ w
- 3 , top
+ 1 );
1860 RGBForeColor( sunken
? &white
: &lightShadow
);
1861 MoveTo( left
+ 1 , top
+ h
- 2 );
1862 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1863 LineTo( left
+ w
- 2 , top
+ 1 );
1865 RGBForeColor( sunken
? &darkShadow
: &face
);
1866 MoveTo( left
+ 2 , top
+ h
- 4 );
1867 LineTo( left
+ 2 , top
+ 2 );
1868 LineTo( left
+ w
- 4 , top
+ 2 );
1871 else if (HasFlag(wxSIMPLE_BORDER
))
1873 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1874 RGBForeColor( &darkShadow
) ;
1875 FrameRect( &rect
) ;
1879 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1881 if ( child
== m_hScrollBar
)
1882 m_hScrollBar
= NULL
;
1883 if ( child
== m_vScrollBar
)
1884 m_vScrollBar
= NULL
;
1886 wxWindowBase::RemoveChild( child
) ;
1889 // New function that will replace some of the above.
1890 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1891 int range
, bool refresh
)
1893 if ( orient
== wxHORIZONTAL
)
1897 if ( range
== 0 || thumbVisible
>= range
)
1899 if ( m_hScrollBar
->IsShown() )
1900 m_hScrollBar
->Show(false) ;
1904 if ( !m_hScrollBar
->IsShown() )
1905 m_hScrollBar
->Show(true) ;
1906 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1914 if ( range
== 0 || thumbVisible
>= range
)
1916 if ( m_vScrollBar
->IsShown() )
1917 m_vScrollBar
->Show(false) ;
1921 if ( !m_vScrollBar
->IsShown() )
1922 m_vScrollBar
->Show(true) ;
1923 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1927 MacRepositionScrollBars() ;
1930 // Does a physical scroll
1931 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1933 if( dx
== 0 && dy
==0 )
1938 wxClientDC
dc(this) ;
1939 wxMacPortSetter
helper(&dc
) ;
1941 int width
, height
;
1942 GetClientSize( &width
, &height
) ;
1949 // TODO take out the boundaries
1950 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
1952 RgnHandle updateRgn
= NewRgn() ;
1955 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1956 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1957 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1959 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1961 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
1962 // but it seems the update only refreshes the background of the control, rather than calling
1963 // kEventControlDraw, so we need to force a proper update here. There has to be a better
1964 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
1967 // we also have to scroll the update rgn in this rectangle
1968 // in order not to loose updates
1970 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
1971 RgnHandle formerUpdateRgn
= NewRgn() ;
1972 RgnHandle scrollRgn
= NewRgn() ;
1973 RectRgn( scrollRgn
, &scrollrect
) ;
1974 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1976 LocalToGlobal( &pt
) ;
1977 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1978 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1979 if ( !EmptyRgn( formerUpdateRgn
) )
1981 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1982 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1983 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1985 InvalWindowRgn(rootWindow
, updateRgn
) ;
1986 DisposeRgn( updateRgn
) ;
1987 DisposeRgn( formerUpdateRgn
) ;
1988 DisposeRgn( scrollRgn
) ;
1992 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1994 wxWindowMac
*child
= node
->GetData();
1995 if (child
== m_vScrollBar
) continue;
1996 if (child
== m_hScrollBar
) continue;
1997 if (child
->IsTopLevel()) continue;
2000 child
->GetPosition( &x
, &y
);
2002 child
->GetSize( &w
, &h
);
2006 if (rect
->Intersects(rc
))
2007 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2011 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2015 // TODO remove, was moved higher up Update() ;
2019 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2021 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2023 wxScrollWinEvent wevent
;
2024 wevent
.SetPosition(event
.GetPosition());
2025 wevent
.SetOrientation(event
.GetOrientation());
2026 wevent
.m_eventObject
= this;
2028 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2029 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2030 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2031 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2032 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2033 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2034 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2035 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2036 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2037 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2038 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2039 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2040 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2041 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2042 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2043 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2045 GetEventHandler()->ProcessEvent(wevent
);
2049 // Get the window with the focus
2050 wxWindowMac
*wxWindowBase::FindFocus()
2052 return gFocusWindow
;
2055 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2057 // panel wants to track the window which was the last to have focus in it,
2058 // so we want to set ourselves as the window which last had focus
2060 // notice that it's also important to do it upwards the tree becaus
2061 // otherwise when the top level panel gets focus, it won't set it back to
2062 // us, but to some other sibling
2064 // CS:don't know if this is still needed:
2065 //wxChildFocusEvent eventFocus(this);
2066 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2071 void wxWindowMac::OnInternalIdle()
2073 // This calls the UI-update mechanism (querying windows for
2074 // menu/toolbar/control state information)
2075 if (wxUpdateUIEvent::CanUpdate(this))
2076 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2079 // Raise the window to the top of the Z order
2080 void wxWindowMac::Raise()
2084 // Lower the window to the bottom of the Z order
2085 void wxWindowMac::Lower()
2090 // static wxWindow *gs_lastWhich = NULL;
2092 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2094 // first trigger a set cursor event
2096 wxPoint clientorigin
= GetClientAreaOrigin() ;
2097 wxSize clientsize
= GetClientSize() ;
2099 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2101 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2103 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2104 if ( processedEvtSetCursor
&& event
.HasCursor() )
2106 cursor
= event
.GetCursor() ;
2111 // the test for processedEvtSetCursor is here to prevent using m_cursor
2112 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2113 // it - this is a way to say that our cursor shouldn't be used for this
2115 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2125 cursor
= *wxSTANDARD_CURSOR
;
2129 cursor
.MacInstall() ;
2131 return cursor
.Ok() ;
2134 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2138 return m_tooltip
->GetTip() ;
2140 return wxEmptyString
;
2143 void wxWindowMac::Update()
2145 #if TARGET_API_MAC_OSX
2146 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2148 ::Draw1Control( (ControlRef
) m_macControl
) ;
2152 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2154 wxTopLevelWindowMac
* win
= NULL
;
2155 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2158 win
= wxFindWinFromMacWindow( window
) ;
2162 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2166 RgnHandle visRgn
= NewRgn() ;
2167 RgnHandle tempRgn
= NewRgn() ;
2168 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2170 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2171 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2173 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2174 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2183 if ( includeOuterStructures
)
2184 InsetRect( &r
, -3 , -3 ) ;
2185 RectRgn( visRgn
, &r
) ;
2186 if ( !IsTopLevel() )
2188 wxWindow
* child
= this ;
2189 wxWindow
* parent
= child
->GetParent() ;
2194 // we have to find a better clipping algorithm here, in order not to clip things
2195 // positioned like status and toolbar
2196 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2198 size
= parent
->GetSize() ;
2203 size
= parent
->GetClientSize() ;
2204 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2208 parent
->MacWindowToRootWindow( &x
, &y
) ;
2209 MacRootWindowToWindow( &x
, &y
) ;
2211 SetRectRgn( tempRgn
,
2212 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2213 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2214 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2216 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2217 if ( parent
->IsTopLevel() )
2220 parent
= child
->GetParent() ;
2225 wxRegion vis
= visRgn
;
2226 DisposeRgn( visRgn
) ;
2227 DisposeRgn( tempRgn
) ;
2232 This function must not change the updatergn !
2234 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2236 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2237 bool handled
= false ;
2239 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2241 RgnHandle newupdate
= NewRgn() ;
2242 wxSize point
= GetClientSize() ;
2243 wxPoint origin
= GetClientAreaOrigin() ;
2244 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2245 SectRgn( newupdate
, updatergn
, newupdate
) ;
2246 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2247 m_updateRegion
= newupdate
;
2248 DisposeRgn( newupdate
) ;
2251 if ( !EmptyRgn(updatergn
) )
2253 wxWindowDC
dc(this);
2254 if (!EmptyRgn(updatergn
))
2255 dc
.SetClippingRegion(wxRegion(updatergn
));
2257 wxEraseEvent
eevent( GetId(), &dc
);
2258 eevent
.SetEventObject( this );
2259 GetEventHandler()->ProcessEvent( eevent
);
2261 if ( !m_updateRegion
.Empty() )
2263 // paint the window itself
2265 event
.m_timeStamp
= time
;
2266 event
.SetEventObject(this);
2267 handled
= GetEventHandler()->ProcessEvent(event
);
2269 // paint custom borders
2270 wxNcPaintEvent
eventNc( GetId() );
2271 eventNc
.SetEventObject( this );
2272 GetEventHandler()->ProcessEvent( eventNc
);
2278 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2280 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2281 // updatergn is always already clipped to our boundaries
2282 // if we are in compositing mode then it is in relative to the upper left of the control
2283 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2284 // of the toplevel window
2285 // it is in window coordinates, not in client coordinates
2287 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2288 RgnHandle ownUpdateRgn
= NewRgn() ;
2289 CopyRgn( updatergn
, ownUpdateRgn
) ;
2291 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2294 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2295 RgnHandle controlRgn
= NewRgn();
2296 RectRgn( controlRgn
, &bounds
);
2297 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2298 // the window update region
2299 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2300 DisposeRgn( controlRgn
);
2302 //KO: convert ownUpdateRgn to local coordinates
2303 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2306 MacDoRedraw( ownUpdateRgn
, time
) ;
2307 DisposeRgn( ownUpdateRgn
) ;
2311 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2313 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2317 if ( iter
->IsTopLevel() )
2318 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2320 iter
= iter
->GetParent() ;
2322 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2326 void wxWindowMac::MacCreateScrollBars( long style
)
2328 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2330 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2331 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2333 GetClientSize( &width
, &height
) ;
2335 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2336 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2337 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2338 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2340 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2341 vSize
, wxVERTICAL
);
2343 if ( style
& wxVSCROLL
)
2349 m_vScrollBar
->Show(false) ;
2351 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2352 hSize
, wxHORIZONTAL
);
2353 if ( style
& wxHSCROLL
)
2358 m_hScrollBar
->Show(false) ;
2361 // because the create does not take into account the client area origin
2362 MacRepositionScrollBars() ; // we might have a real position shift
2365 void wxWindowMac::MacRepositionScrollBars()
2367 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2368 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2370 // get real client area
2374 GetSize( &width
, &height
) ;
2376 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2377 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2379 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2380 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2381 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2382 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2388 GetSize( &w
, &h
) ;
2390 MacClientToRootWindow( &x
, &y
) ;
2391 MacClientToRootWindow( &w
, &h
) ;
2393 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2395 int totW
= 10000 , totH
= 10000;
2398 if ( iter
->IsTopLevel() )
2400 iter
->GetSize( &totW
, &totH
) ;
2404 iter
= iter
->GetParent() ;
2432 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2436 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2440 bool wxWindowMac::AcceptsFocus() const
2442 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2445 void wxWindowMac::MacSuperChangedPosition()
2447 // only window-absolute structures have to be moved i.e. controls
2449 wxWindowListNode
*node
= GetChildren().GetFirst();
2452 wxWindowMac
*child
= node
->GetData();
2453 child
->MacSuperChangedPosition() ;
2454 node
= node
->GetNext();
2458 void wxWindowMac::MacTopLevelWindowChangedPosition()
2460 // only screen-absolute structures have to be moved i.e. glcanvas
2462 wxWindowListNode
*node
= GetChildren().GetFirst();
2465 wxWindowMac
*child
= node
->GetData();
2466 child
->MacTopLevelWindowChangedPosition() ;
2467 node
= node
->GetNext();
2471 long wxWindowMac::MacGetLeftBorderSize( ) const
2476 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2479 #if wxMAC_USE_THEME_BORDER
2480 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2484 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2487 #if wxMAC_USE_THEME_BORDER
2488 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2492 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2499 long wxWindowMac::MacGetRightBorderSize( ) const
2501 // they are all symmetric in mac themes
2502 return MacGetLeftBorderSize() ;
2505 long wxWindowMac::MacGetTopBorderSize( ) const
2507 // they are all symmetric in mac themes
2508 return MacGetLeftBorderSize() ;
2511 long wxWindowMac::MacGetBottomBorderSize( ) const
2513 // they are all symmetric in mac themes
2514 return MacGetLeftBorderSize() ;
2517 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2519 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2522 // Find the wxWindowMac at the current mouse position, returning the mouse
2524 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2526 pt
= wxGetMousePosition();
2527 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2531 // Get the current mouse position.
2532 wxPoint
wxGetMousePosition()
2535 wxGetMousePosition(& x
, & y
);
2536 return wxPoint(x
, y
);
2539 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2541 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2543 // copied from wxGTK : CS
2544 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2547 // (a) it's a command event and so is propagated to the parent
2548 // (b) under MSW it can be generated from kbd too
2549 // (c) it uses screen coords (because of (a))
2550 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2552 this->ClientToScreen(event
.GetPosition()));
2553 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2556 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2562 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2564 // OS Needs it in tlw content area coordinates
2565 MacClientToRootWindow( &x
, &y
) ;
2569 // OS Needs it in window not client coordinates
2570 wxPoint origin
= GetClientAreaOrigin() ;
2575 SInt16 controlpart
;
2580 short modifiers
= 0;
2582 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2583 modifiers
|= btnState
;
2585 if ( event
.m_shiftDown
)
2586 modifiers
|= shiftKey
;
2588 if ( event
.m_controlDown
)
2589 modifiers
|= controlKey
;
2591 if ( event
.m_altDown
)
2592 modifiers
|= optionKey
;
2594 if ( event
.m_metaDown
)
2595 modifiers
|= cmdKey
;
2597 bool handled
= false ;
2599 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2601 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2602 wxTheApp
->s_lastMouseDown
= 0 ;
2603 if ( controlpart
!= kControlNoPart
)
2605 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2618 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2620 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2623 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2627 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2628 Rect bounds
= { y
, x
, y
+h
, x
+w
};