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
;
676 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
677 fontStyle
.flags
|= kControlUseForeColorMask
;
678 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
682 bool wxWindowMac::SetFont(const wxFont
& font
)
684 bool retval
= !wxWindowBase::SetFont( font
) ;
686 MacUpdateControlFont() ;
691 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
693 if ( !wxWindowBase::SetForegroundColour(col
) )
696 MacUpdateControlFont() ;
701 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
703 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
707 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
709 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
711 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
713 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
717 brush
.SetColour( col
) ;
719 MacSetBackgroundBrush( brush
) ;
721 MacUpdateControlFont() ;
727 bool wxWindowMac::MacCanFocus() const
729 wxASSERT( m_macControl
!= NULL
) ;
735 void wxWindowMac::SetFocus()
737 if ( gFocusWindow
== this )
740 if ( AcceptsFocus() )
746 if ( gFocusWindow
->m_caret
)
748 gFocusWindow
->m_caret
->OnKillFocus();
750 #endif // wxUSE_CARET
751 #ifndef __WXUNIVERSAL__
752 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
753 // TODO we must use the built-in focusing
754 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
756 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
757 control
->MacRedrawControl() ;
760 // Without testing the window id, for some reason
761 // a kill focus event can still be sent to
762 // the control just being focussed.
763 int thisId
= this->m_windowId
;
764 int gFocusWindowId
= gFocusWindow
->m_windowId
;
765 if (gFocusWindowId
!= thisId
)
767 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
768 event
.SetEventObject(gFocusWindow
);
769 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
772 gFocusWindow
= this ;
778 m_caret
->OnSetFocus();
780 #endif // wxUSE_CARET
781 // panel wants to track the window which was the last to have focus in it
782 wxChildFocusEvent
eventFocus(this);
783 GetEventHandler()->ProcessEvent(eventFocus
);
785 #ifndef __WXUNIVERSAL__
786 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
787 if ( control
&& control
->GetHandle() )
789 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
792 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
793 event
.SetEventObject(this);
794 GetEventHandler()->ProcessEvent(event
) ;
800 void wxWindowMac::DoCaptureMouse()
802 wxTheApp
->s_captureWindow
= this ;
805 wxWindow
* wxWindowBase::GetCapture()
807 return wxTheApp
->s_captureWindow
;
810 void wxWindowMac::DoReleaseMouse()
812 wxTheApp
->s_captureWindow
= NULL
;
815 #if wxUSE_DRAG_AND_DROP
817 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
819 if ( m_dropTarget
!= 0 ) {
823 m_dropTarget
= pDropTarget
;
824 if ( m_dropTarget
!= 0 )
832 // Old style file-manager drag&drop
833 void wxWindowMac::DragAcceptFiles(bool accept
)
838 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
839 int& w
, int& h
) const
842 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
847 w
= bounds
.right
- bounds
.left
;
848 h
= bounds
.bottom
- bounds
.top
;
850 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
853 Point tlworigin
= { 0 , 0 } ;
856 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
857 ::LocalToGlobal( &tlworigin
) ;
864 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
867 int& w
, int& h
) const
871 // todo the default calls may be used as soon as PostCreateControl Is moved here
872 w
= size
.x
; // WidthDefault( size.x );
873 h
= size
.y
; // HeightDefault( size.y ) ;
874 #if !TARGET_API_MAC_OSX
875 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
882 void wxWindowMac::DoGetSize(int *x
, int *y
) const
884 #if TARGET_API_MAC_OSX
885 int x1
, y1
, w1
,h1
;
886 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
892 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
893 if(x
) *x
= bounds
.right
- bounds
.left
;
894 if(y
) *y
= bounds
.bottom
- bounds
.top
;
898 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
900 #if TARGET_API_MAC_OSX
901 int x1
, y1
, w1
,h1
;
902 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
905 wxWindow
*parent
= GetParent();
908 wxPoint
pt(parent
->GetClientAreaOrigin());
917 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
918 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
920 int xx
= bounds
.left
;
921 int yy
= bounds
.top
;
923 if ( !GetParent()->IsTopLevel() )
925 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
931 wxPoint
pt(GetParent()->GetClientAreaOrigin());
940 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
942 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
944 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
947 Point localwhere
= {0,0} ;
949 if(x
) localwhere
.h
= * x
;
950 if(y
) localwhere
.v
= * y
;
952 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
953 ::GlobalToLocal( &localwhere
) ;
954 if(x
) *x
= localwhere
.h
;
955 if(y
) *y
= localwhere
.v
;
958 MacRootWindowToWindow( x
, y
) ;
960 wxPoint origin
= GetClientAreaOrigin() ;
961 if(x
) *x
-= origin
.x
;
962 if(y
) *y
-= origin
.y
;
965 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
967 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
968 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
970 wxPoint origin
= GetClientAreaOrigin() ;
971 if(x
) *x
+= origin
.x
;
972 if(y
) *y
+= origin
.y
;
974 MacWindowToRootWindow( x
, y
) ;
977 Point localwhere
= { 0,0 };
978 if(x
) localwhere
.h
= * x
;
979 if(y
) localwhere
.v
= * y
;
981 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
982 ::LocalToGlobal( &localwhere
) ;
983 if(x
) *x
= localwhere
.h
;
984 if(y
) *y
= localwhere
.v
;
988 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
990 wxPoint origin
= GetClientAreaOrigin() ;
991 if(x
) *x
+= origin
.x
;
992 if(y
) *y
+= origin
.y
;
994 MacWindowToRootWindow( x
, y
) ;
997 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
999 MacRootWindowToWindow( x
, y
) ;
1001 wxPoint origin
= GetClientAreaOrigin() ;
1002 if(x
) *x
-= origin
.x
;
1003 if(y
) *y
-= origin
.y
;
1006 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1008 #if TARGET_API_MAC_OSX
1010 if ( x
) pt
.x
= *x
;
1011 if ( y
) pt
.y
= *y
;
1013 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1015 if ( x
) *x
= (int) pt
.x
;
1016 if ( y
) *y
= (int) pt
.y
;
1018 if ( !IsTopLevel() )
1021 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1022 if(x
) *x
+= bounds
.left
;
1023 if(y
) *y
+= bounds
.top
;
1028 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1033 MacWindowToRootWindow( &x1
, &y1
) ;
1038 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1040 #if TARGET_API_MAC_OSX
1042 if ( x
) pt
.x
= *x
;
1043 if ( y
) pt
.y
= *y
;
1045 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1047 if ( x
) *x
= (int) pt
.x
;
1048 if ( y
) *y
= (int) pt
.y
;
1050 if ( !IsTopLevel() )
1053 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1054 if(x
) *x
-= bounds
.left
;
1055 if(y
) *y
-= bounds
.top
;
1060 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1065 MacRootWindowToWindow( &x1
, &y1
) ;
1070 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1072 wxSize sizeTotal
= size
;
1074 RgnHandle rgn
= NewRgn() ;
1078 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1080 GetRegionBounds( rgn
, &content
) ;
1085 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1088 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1089 #if !TARGET_API_MAC_OSX
1090 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1093 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1094 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1096 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1097 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1103 // Get size *available for subwindows* i.e. excluding menu bar etc.
1104 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1108 RgnHandle rgn
= NewRgn() ;
1110 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1112 GetRegionBounds( rgn
, &content
) ;
1117 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1119 #if !TARGET_API_MAC_OSX
1121 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1122 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1124 ww
= content
.right
- content
.left
;
1125 hh
= content
.bottom
- content
.top
;
1127 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1128 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1130 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1136 GetSize( &w
, &h
) ;
1138 MacClientToRootWindow( &x1
, &y1
) ;
1139 MacClientToRootWindow( &w
, &h
) ;
1141 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1143 int totW
= 10000 , totH
= 10000;
1146 if ( iter
->IsTopLevel() )
1148 iter
->GetSize( &totW
, &totH
) ;
1152 iter
= iter
->GetParent() ;
1155 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1157 hh
-= MAC_SCROLLBAR_SIZE
;
1163 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1165 ww
-= MAC_SCROLLBAR_SIZE
;
1177 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1179 if (m_cursor
== cursor
)
1182 if (wxNullCursor
== cursor
)
1184 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1189 if ( ! wxWindowBase::SetCursor( cursor
) )
1193 wxASSERT_MSG( m_cursor
.Ok(),
1194 wxT("cursor must be valid after call to the base version"));
1198 TODO why do we have to use current coordinates ?
1201 wxWindowMac *mouseWin ;
1204 // Change the cursor NOW if we're within the correct window
1207 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1209 if ( mouseWin == this && !wxIsBusy() )
1211 m_cursor.MacInstall() ;
1217 m_cursor
.MacInstall() ;
1224 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1226 menu
->SetInvokingWindow(this);
1228 ClientToScreen( &x
, &y
) ;
1230 menu
->MacBeforeDisplay( true ) ;
1231 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1232 if ( HiWord(menuResult
) != 0 )
1235 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1236 wxMenuItem
* item
= NULL
;
1238 item
= menu
->FindItem(id
, &realmenu
) ;
1239 if (item
->IsCheckable())
1241 item
->Check( !item
->IsChecked() ) ;
1243 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1245 menu
->MacAfterDisplay( true ) ;
1247 menu
->SetInvokingWindow(NULL
);
1253 // ----------------------------------------------------------------------------
1255 // ----------------------------------------------------------------------------
1259 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1261 wxWindowBase::DoSetToolTip(tooltip
);
1264 m_tooltip
->SetWindow(this);
1267 #endif // wxUSE_TOOLTIPS
1269 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1271 int former_x
, former_y
, former_w
, former_h
;
1272 #if !TARGET_API_MAC_OSX
1273 DoGetPosition( &former_x
, &former_y
) ;
1274 DoGetSize( &former_w
, &former_h
) ;
1276 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1279 int actualWidth
= width
;
1280 int actualHeight
= height
;
1284 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1285 actualWidth
= m_minWidth
;
1286 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1287 actualHeight
= m_minHeight
;
1288 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1289 actualWidth
= m_maxWidth
;
1290 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1291 actualHeight
= m_maxHeight
;
1293 bool doMove
= false ;
1294 bool doResize
= false ;
1296 if ( actualX
!= former_x
|| actualY
!= former_y
)
1300 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1305 if ( doMove
|| doResize
)
1307 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1308 #if TARGET_API_MAC_OSX
1309 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1312 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1314 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1316 MacRepositionScrollBars() ;
1319 wxPoint
point(actualX
,actualY
);
1320 wxMoveEvent
event(point
, m_windowId
);
1321 event
.SetEventObject(this);
1322 GetEventHandler()->ProcessEvent(event
) ;
1326 MacRepositionScrollBars() ;
1327 wxSize
size(actualWidth
, actualHeight
);
1328 wxSizeEvent
event(size
, m_windowId
);
1329 event
.SetEventObject(this);
1330 GetEventHandler()->ProcessEvent(event
);
1336 wxSize
wxWindowMac::DoGetBestSize() const
1338 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1339 short baselineoffset
;
1340 int bestWidth
, bestHeight
;
1341 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1343 if ( EmptyRect( &bestsize
) )
1346 bestsize
.left
= bestsize
.top
= 0 ;
1347 bestsize
.right
= 16 ;
1348 bestsize
.bottom
= 16 ;
1349 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1351 bestsize
.bottom
= 16 ;
1353 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1355 bestsize
.bottom
= 24 ;
1359 // return wxWindowBase::DoGetBestSize() ;
1363 bestWidth
= bestsize
.right
- bestsize
.left
;
1364 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1365 if ( bestHeight
< 10 )
1368 return wxSize(bestWidth
, bestHeight
);
1372 // set the size of the window: if the dimensions are positive, just use them,
1373 // but if any of them is equal to -1, it means that we must find the value for
1374 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1375 // which case -1 is a valid value for x and y)
1377 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1378 // the width/height to best suit our contents, otherwise we reuse the current
1380 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1382 // get the current size and position...
1383 int currentX
, currentY
;
1384 GetPosition(¤tX
, ¤tY
);
1386 int currentW
,currentH
;
1387 GetSize(¤tW
, ¤tH
);
1389 // ... and don't do anything (avoiding flicker) if it's already ok
1390 if ( x
== currentX
&& y
== currentY
&&
1391 width
== currentW
&& height
== currentH
)
1394 MacRepositionScrollBars() ; // we might have a real position shift
1398 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1400 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1403 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1405 wxSize
size(-1, -1);
1408 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1410 size
= DoGetBestSize();
1415 // just take the current one
1422 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1426 size
= DoGetBestSize();
1428 //else: already called DoGetBestSize() above
1434 // just take the current one
1439 DoMoveWindow(x
, y
, width
, height
);
1443 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1445 RgnHandle rgn
= NewRgn() ;
1447 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1448 GetRegionBounds( rgn
, &content
) ;
1450 #if !TARGET_API_MAC_OSX
1452 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1453 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1456 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1459 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1461 if ( clientheight
!= -1 || clientheight
!= -1 )
1463 int currentclientwidth
, currentclientheight
;
1464 int currentwidth
, currentheight
;
1466 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1467 GetSize( ¤twidth
, ¤theight
) ;
1469 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1470 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1474 void wxWindowMac::SetTitle(const wxString
& title
)
1476 m_label
= wxStripMenuCodes(title
) ;
1480 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1485 wxString
wxWindowMac::GetTitle() const
1490 void wxWindowMac::MacPropagateVisibilityChanged()
1492 MacVisibilityChanged() ;
1494 wxWindowListNode
*node
= GetChildren().GetFirst();
1497 wxWindowMac
*child
= node
->GetData();
1498 if ( child
->IsShown() )
1499 child
->MacPropagateVisibilityChanged( ) ;
1500 node
= node
->GetNext();
1504 bool wxWindowMac::Show(bool show
)
1506 if ( !wxWindowBase::Show(show
) )
1509 // TODO use visibilityChanged Carbon Event for OSX
1510 bool former
= MacIsReallyShown() ;
1512 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1513 if ( former
!= MacIsReallyShown() )
1514 MacPropagateVisibilityChanged() ;
1518 bool wxWindowMac::MacIsReallyShown()
1520 // only under OSX the visibility of the TLW is taken into account
1521 #if TARGET_API_MAC_OSX
1522 return IsControlVisible( (ControlRef
) m_macControl
) ;
1524 wxWindow
* win
= this ;
1525 while( win
->IsShown() )
1527 if ( win
->IsTopLevel() )
1530 win
= win
->GetParent() ;
1539 void wxWindowMac::MacVisibilityChanged()
1543 void wxWindowMac::MacPropagateEnabledStateChanged( )
1545 MacEnabledStateChanged() ;
1547 wxWindowListNode
*node
= GetChildren().GetFirst();
1550 wxWindowMac
*child
= node
->GetData();
1551 if ( child
->IsEnabled() )
1552 child
->MacPropagateEnabledStateChanged() ;
1553 node
= node
->GetNext();
1557 bool wxWindowMac::Enable(bool enable
)
1559 wxASSERT( m_macControl
!= NULL
) ;
1560 if ( !wxWindowBase::Enable(enable
) )
1563 bool former
= MacIsReallyEnabled() ;
1565 UMAActivateControl( (ControlRef
) m_macControl
) ;
1567 UMADeactivateControl( (ControlRef
) m_macControl
) ;
1569 if ( former
!= MacIsReallyEnabled() )
1570 MacPropagateEnabledStateChanged() ;
1574 bool wxWindowMac::MacIsReallyEnabled()
1576 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1579 void wxWindowMac::MacEnabledStateChanged()
1583 int wxWindowMac::GetCharHeight() const
1585 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1586 return dc
.GetCharHeight() ;
1589 int wxWindowMac::GetCharWidth() const
1591 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1592 return dc
.GetCharWidth() ;
1595 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1596 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1598 const wxFont
*fontToUse
= theFont
;
1600 fontToUse
= &m_font
;
1602 wxClientDC
dc( (wxWindowMac
*) this ) ;
1604 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1605 if ( externalLeading
)
1606 *externalLeading
= le
;
1616 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1617 * we always intersect with the entire window, not only with the client area
1620 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1622 #if TARGET_API_MAC_OSX
1623 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1625 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1627 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1628 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1631 if ( MacGetTopLevelWindow() == NULL )
1634 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1637 wxPoint client = GetClientAreaOrigin();
1640 int x2 = m_width - client.x;
1641 int y2 = m_height - client.y;
1643 if (IsKindOf( CLASSINFO(wxButton)))
1645 // buttons have an "aura"
1652 Rect clientrect = { y1, x1, y2, x2 };
1656 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1657 SectRect( &clientrect , &r , &clientrect ) ;
1660 if ( !EmptyRect( &clientrect ) )
1662 int top = 0 , left = 0 ;
1664 MacClientToRootWindow( &left , &top ) ;
1665 OffsetRect( &clientrect , left , top ) ;
1667 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1673 void wxWindowMac::MacRedrawControl()
1676 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1678 #if TARGET_API_MAC_CARBON
1681 wxClientDC dc(this) ;
1682 wxMacPortSetter helper(&dc) ;
1683 wxMacWindowClipper clipper(this) ;
1684 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1685 UMADrawControl( (ControlRef) m_macControl ) ;
1692 void wxWindowMac::OnPaint(wxPaintEvent& event)
1694 // why don't we skip that here ?
1698 wxWindowMac
*wxGetActiveWindow()
1700 // actually this is a windows-only concept
1704 // Coordinates relative to the window
1705 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1707 // We really don't move the mouse programmatically under Mac.
1710 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1714 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
1719 event.GetDC()->Clear() ;
1723 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1725 wxWindowDC
dc(this) ;
1726 wxMacPortSetter
helper(&dc
) ;
1728 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1731 int wxWindowMac::GetScrollPos(int orient
) const
1733 if ( orient
== wxHORIZONTAL
)
1736 return m_hScrollBar
->GetThumbPosition() ;
1741 return m_vScrollBar
->GetThumbPosition() ;
1746 // This now returns the whole range, not just the number
1747 // of positions that we can scroll.
1748 int wxWindowMac::GetScrollRange(int orient
) const
1750 if ( orient
== wxHORIZONTAL
)
1753 return m_hScrollBar
->GetRange() ;
1758 return m_vScrollBar
->GetRange() ;
1763 int wxWindowMac::GetScrollThumb(int orient
) const
1765 if ( orient
== wxHORIZONTAL
)
1768 return m_hScrollBar
->GetThumbSize() ;
1773 return m_vScrollBar
->GetThumbSize() ;
1778 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1780 if ( orient
== wxHORIZONTAL
)
1783 m_hScrollBar
->SetThumbPosition( pos
) ;
1788 m_vScrollBar
->SetThumbPosition( pos
) ;
1792 void wxWindowMac::MacPaintBorders( int left
, int top
)
1798 wxGetOsVersion( &major
, &minor
);
1800 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1801 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1803 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1804 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1805 // OS X has lighter border edges than classic:
1808 darkShadow
.red
= 0x8E8E;
1809 darkShadow
.green
= 0x8E8E;
1810 darkShadow
.blue
= 0x8E8E;
1811 lightShadow
.red
= 0xBDBD;
1812 lightShadow
.green
= 0xBDBD;
1813 lightShadow
.blue
= 0xBDBD;
1819 GetSize( &w
, &h
) ;
1820 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1822 #if wxMAC_USE_THEME_BORDER
1823 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1826 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1827 InsetRect( &rect , border , border );
1828 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1831 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1833 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1834 RGBForeColor( &face
);
1835 MoveTo( left
+ 0 , top
+ h
- 2 );
1836 LineTo( left
+ 0 , top
+ 0 );
1837 LineTo( left
+ w
- 2 , top
+ 0 );
1839 MoveTo( left
+ 2 , top
+ h
- 3 );
1840 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1841 LineTo( left
+ w
- 3 , top
+ 2 );
1843 RGBForeColor( sunken
? &face
: &darkShadow
);
1844 MoveTo( left
+ 0 , top
+ h
- 1 );
1845 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1846 LineTo( left
+ w
- 1 , top
+ 0 );
1848 RGBForeColor( sunken
? &lightShadow
: &white
);
1849 MoveTo( left
+ 1 , top
+ h
- 3 );
1850 LineTo( left
+ 1, top
+ 1 );
1851 LineTo( left
+ w
- 3 , top
+ 1 );
1853 RGBForeColor( sunken
? &white
: &lightShadow
);
1854 MoveTo( left
+ 1 , top
+ h
- 2 );
1855 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1856 LineTo( left
+ w
- 2 , top
+ 1 );
1858 RGBForeColor( sunken
? &darkShadow
: &face
);
1859 MoveTo( left
+ 2 , top
+ h
- 4 );
1860 LineTo( left
+ 2 , top
+ 2 );
1861 LineTo( left
+ w
- 4 , top
+ 2 );
1864 else if (HasFlag(wxSIMPLE_BORDER
))
1866 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1867 RGBForeColor( &darkShadow
) ;
1868 FrameRect( &rect
) ;
1872 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1874 if ( child
== m_hScrollBar
)
1875 m_hScrollBar
= NULL
;
1876 if ( child
== m_vScrollBar
)
1877 m_vScrollBar
= NULL
;
1879 wxWindowBase::RemoveChild( child
) ;
1882 // New function that will replace some of the above.
1883 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1884 int range
, bool refresh
)
1886 if ( orient
== wxHORIZONTAL
)
1890 if ( range
== 0 || thumbVisible
>= range
)
1892 if ( m_hScrollBar
->IsShown() )
1893 m_hScrollBar
->Show(false) ;
1897 if ( !m_hScrollBar
->IsShown() )
1898 m_hScrollBar
->Show(true) ;
1899 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1907 if ( range
== 0 || thumbVisible
>= range
)
1909 if ( m_vScrollBar
->IsShown() )
1910 m_vScrollBar
->Show(false) ;
1914 if ( !m_vScrollBar
->IsShown() )
1915 m_vScrollBar
->Show(true) ;
1916 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1920 MacRepositionScrollBars() ;
1923 // Does a physical scroll
1924 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1926 if( dx
== 0 && dy
==0 )
1931 wxClientDC
dc(this) ;
1932 wxMacPortSetter
helper(&dc
) ;
1934 int width
, height
;
1935 GetClientSize( &width
, &height
) ;
1942 // TODO take out the boundaries
1943 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
1945 RgnHandle updateRgn
= NewRgn() ;
1948 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1949 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1950 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1952 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1954 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
1955 // but it seems the update only refreshes the background of the control, rather than calling
1956 // kEventControlDraw, so we need to force a proper update here. There has to be a better
1957 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
1960 // we also have to scroll the update rgn in this rectangle
1961 // in order not to loose updates
1963 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
1964 RgnHandle formerUpdateRgn
= NewRgn() ;
1965 RgnHandle scrollRgn
= NewRgn() ;
1966 RectRgn( scrollRgn
, &scrollrect
) ;
1967 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1969 LocalToGlobal( &pt
) ;
1970 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1971 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1972 if ( !EmptyRgn( formerUpdateRgn
) )
1974 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1975 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1976 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1978 InvalWindowRgn(rootWindow
, updateRgn
) ;
1979 DisposeRgn( updateRgn
) ;
1980 DisposeRgn( formerUpdateRgn
) ;
1981 DisposeRgn( scrollRgn
) ;
1985 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
1987 wxWindowMac
*child
= node
->GetData();
1988 if (child
== m_vScrollBar
) continue;
1989 if (child
== m_hScrollBar
) continue;
1990 if (child
->IsTopLevel()) continue;
1993 child
->GetPosition( &x
, &y
);
1995 child
->GetSize( &w
, &h
);
1999 if (rect
->Intersects(rc
))
2000 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2004 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2008 // TODO remove, was moved higher up Update() ;
2012 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2014 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2016 wxScrollWinEvent wevent
;
2017 wevent
.SetPosition(event
.GetPosition());
2018 wevent
.SetOrientation(event
.GetOrientation());
2019 wevent
.m_eventObject
= this;
2021 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2022 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2023 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2024 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2025 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2026 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2027 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2028 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2029 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2030 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2031 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2032 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2033 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2034 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2035 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2036 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2038 GetEventHandler()->ProcessEvent(wevent
);
2042 // Get the window with the focus
2043 wxWindowMac
*wxWindowBase::FindFocus()
2045 return gFocusWindow
;
2048 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2050 // panel wants to track the window which was the last to have focus in it,
2051 // so we want to set ourselves as the window which last had focus
2053 // notice that it's also important to do it upwards the tree becaus
2054 // otherwise when the top level panel gets focus, it won't set it back to
2055 // us, but to some other sibling
2057 // CS:don't know if this is still needed:
2058 //wxChildFocusEvent eventFocus(this);
2059 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2064 void wxWindowMac::OnInternalIdle()
2066 // This calls the UI-update mechanism (querying windows for
2067 // menu/toolbar/control state information)
2068 if (wxUpdateUIEvent::CanUpdate(this))
2069 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2072 // Raise the window to the top of the Z order
2073 void wxWindowMac::Raise()
2077 // Lower the window to the bottom of the Z order
2078 void wxWindowMac::Lower()
2083 // static wxWindow *gs_lastWhich = NULL;
2085 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2087 // first trigger a set cursor event
2089 wxPoint clientorigin
= GetClientAreaOrigin() ;
2090 wxSize clientsize
= GetClientSize() ;
2092 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2094 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2096 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2097 if ( processedEvtSetCursor
&& event
.HasCursor() )
2099 cursor
= event
.GetCursor() ;
2104 // the test for processedEvtSetCursor is here to prevent using m_cursor
2105 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2106 // it - this is a way to say that our cursor shouldn't be used for this
2108 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2118 cursor
= *wxSTANDARD_CURSOR
;
2122 cursor
.MacInstall() ;
2124 return cursor
.Ok() ;
2127 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2131 return m_tooltip
->GetTip() ;
2133 return wxEmptyString
;
2136 void wxWindowMac::Update()
2138 #if TARGET_API_MAC_OSX
2139 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2141 ::Draw1Control( (ControlRef
) m_macControl
) ;
2145 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2147 wxTopLevelWindowMac
* win
= NULL
;
2148 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2151 win
= wxFindWinFromMacWindow( window
) ;
2155 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2159 RgnHandle visRgn
= NewRgn() ;
2160 RgnHandle tempRgn
= NewRgn() ;
2161 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2163 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2164 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2166 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2167 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2176 if ( includeOuterStructures
)
2177 InsetRect( &r
, -3 , -3 ) ;
2178 RectRgn( visRgn
, &r
) ;
2179 if ( !IsTopLevel() )
2181 wxWindow
* child
= this ;
2182 wxWindow
* parent
= child
->GetParent() ;
2187 if ( parent
->IsTopLevel() && child
->IsKindOf( CLASSINFO( wxToolBar
) ) )
2189 size
= parent
->GetSize() ;
2194 size
= parent
->GetClientSize() ;
2195 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2199 parent
->MacWindowToRootWindow( &x
, &y
) ;
2200 MacRootWindowToWindow( &x
, &y
) ;
2202 SetRectRgn( tempRgn
,
2203 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2204 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2205 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2207 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2208 if ( parent
->IsTopLevel() )
2211 parent
= child
->GetParent() ;
2216 wxRegion vis
= visRgn
;
2217 DisposeRgn( visRgn
) ;
2218 DisposeRgn( tempRgn
) ;
2223 This function must not change the updatergn !
2225 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2227 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2228 bool handled
= false ;
2230 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2232 RgnHandle newupdate
= NewRgn() ;
2233 wxSize point
= GetClientSize() ;
2234 wxPoint origin
= GetClientAreaOrigin() ;
2235 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2236 SectRgn( newupdate
, updatergn
, newupdate
) ;
2237 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2238 m_updateRegion
= newupdate
;
2239 DisposeRgn( newupdate
) ;
2242 if ( !EmptyRgn(updatergn
) )
2244 wxWindowDC
dc(this);
2245 if (!EmptyRgn(updatergn
))
2246 dc
.SetClippingRegion(wxRegion(updatergn
));
2248 wxEraseEvent
eevent( GetId(), &dc
);
2249 eevent
.SetEventObject( this );
2250 GetEventHandler()->ProcessEvent( eevent
);
2252 if ( !m_updateRegion
.Empty() )
2254 // paint the window itself
2256 event
.m_timeStamp
= time
;
2257 event
.SetEventObject(this);
2258 handled
= GetEventHandler()->ProcessEvent(event
);
2260 // paint custom borders
2261 wxNcPaintEvent
eventNc( GetId() );
2262 eventNc
.SetEventObject( this );
2263 GetEventHandler()->ProcessEvent( eventNc
);
2269 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2271 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2272 // updatergn is always already clipped to our boundaries
2273 // if we are in compositing mode then it is in relative to the upper left of the control
2274 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2275 // of the toplevel window
2276 // it is in window coordinates, not in client coordinates
2278 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2279 RgnHandle ownUpdateRgn
= NewRgn() ;
2280 CopyRgn( updatergn
, ownUpdateRgn
) ;
2282 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2285 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2286 RgnHandle controlRgn
= NewRgn();
2287 RectRgn( controlRgn
, &bounds
);
2288 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2289 // the window update region
2290 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2291 DisposeRgn( controlRgn
);
2293 //KO: convert ownUpdateRgn to local coordinates
2294 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2297 MacDoRedraw( ownUpdateRgn
, time
) ;
2298 DisposeRgn( ownUpdateRgn
) ;
2302 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2304 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2308 if ( iter
->IsTopLevel() )
2309 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2311 iter
= iter
->GetParent() ;
2313 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2317 void wxWindowMac::MacCreateScrollBars( long style
)
2319 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2321 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2322 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2324 GetClientSize( &width
, &height
) ;
2326 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2327 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2328 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2329 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2331 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2332 vSize
, wxVERTICAL
);
2334 if ( style
& wxVSCROLL
)
2340 m_vScrollBar
->Show(false) ;
2342 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2343 hSize
, wxHORIZONTAL
);
2344 if ( style
& wxHSCROLL
)
2349 m_hScrollBar
->Show(false) ;
2352 // because the create does not take into account the client area origin
2353 MacRepositionScrollBars() ; // we might have a real position shift
2356 void wxWindowMac::MacRepositionScrollBars()
2358 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2359 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2361 // get real client area
2365 GetSize( &width
, &height
) ;
2367 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2368 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2370 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2371 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2372 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2373 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2379 GetSize( &w
, &h
) ;
2381 MacClientToRootWindow( &x
, &y
) ;
2382 MacClientToRootWindow( &w
, &h
) ;
2384 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2386 int totW
= 10000 , totH
= 10000;
2389 if ( iter
->IsTopLevel() )
2391 iter
->GetSize( &totW
, &totH
) ;
2395 iter
= iter
->GetParent() ;
2423 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2427 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2431 bool wxWindowMac::AcceptsFocus() const
2433 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2436 void wxWindowMac::MacSuperChangedPosition()
2438 // only window-absolute structures have to be moved i.e. controls
2440 wxWindowListNode
*node
= GetChildren().GetFirst();
2443 wxWindowMac
*child
= node
->GetData();
2444 child
->MacSuperChangedPosition() ;
2445 node
= node
->GetNext();
2449 void wxWindowMac::MacTopLevelWindowChangedPosition()
2451 // only screen-absolute structures have to be moved i.e. glcanvas
2453 wxWindowListNode
*node
= GetChildren().GetFirst();
2456 wxWindowMac
*child
= node
->GetData();
2457 child
->MacTopLevelWindowChangedPosition() ;
2458 node
= node
->GetNext();
2462 long wxWindowMac::MacGetLeftBorderSize( ) const
2467 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2470 #if wxMAC_USE_THEME_BORDER
2471 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2475 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2478 #if wxMAC_USE_THEME_BORDER
2479 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2483 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2490 long wxWindowMac::MacGetRightBorderSize( ) const
2492 // they are all symmetric in mac themes
2493 return MacGetLeftBorderSize() ;
2496 long wxWindowMac::MacGetTopBorderSize( ) const
2498 // they are all symmetric in mac themes
2499 return MacGetLeftBorderSize() ;
2502 long wxWindowMac::MacGetBottomBorderSize( ) const
2504 // they are all symmetric in mac themes
2505 return MacGetLeftBorderSize() ;
2508 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2510 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2513 // Find the wxWindowMac at the current mouse position, returning the mouse
2515 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2517 pt
= wxGetMousePosition();
2518 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2522 // Get the current mouse position.
2523 wxPoint
wxGetMousePosition()
2526 wxGetMousePosition(& x
, & y
);
2527 return wxPoint(x
, y
);
2530 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2532 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2534 // copied from wxGTK : CS
2535 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2538 // (a) it's a command event and so is propagated to the parent
2539 // (b) under MSW it can be generated from kbd too
2540 // (c) it uses screen coords (because of (a))
2541 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2543 this->ClientToScreen(event
.GetPosition()));
2544 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2547 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2553 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2555 // OS Needs it in tlw content area coordinates
2556 MacClientToRootWindow( &x
, &y
) ;
2560 // OS Needs it in window not client coordinates
2561 wxPoint origin
= GetClientAreaOrigin() ;
2565 ControlRef control
;
2567 SInt16 controlpart
;
2572 short modifiers
= 0;
2574 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2575 modifiers
|= btnState
;
2577 if ( event
.m_shiftDown
)
2578 modifiers
|= shiftKey
;
2580 if ( event
.m_controlDown
)
2581 modifiers
|= controlKey
;
2583 if ( event
.m_altDown
)
2584 modifiers
|= optionKey
;
2586 if ( event
.m_metaDown
)
2587 modifiers
|= cmdKey
;
2589 control
= (ControlRef
) m_macControl
;
2590 if ( control
&& ::IsControlActive( control
) )
2593 controlpart
= ::HandleControlClick( control
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2594 wxTheApp
->s_lastMouseDown
= 0 ;
2595 if ( control
&& controlpart
!= kControlNoPart
)
2597 MacHandleControlClick((WXWidget
) control
, controlpart
, false /* mouse not down anymore */ ) ;
2609 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2611 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2614 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2618 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2619 Rect bounds
= { y
, x
, y
+h
, x
+w
};