1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
39 #include "wx/toolbar.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
69 wxWindowMac
* gFocusWindow
= NULL
;
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
75 #endif // __WXUNIVERSAL__/__WXMAC__
77 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 0
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
103 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
105 static const EventTypeSpec eventList
[] =
107 #if TARGET_API_MAC_OSX
108 { kEventClassControl
, kEventControlDraw
} ,
109 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
110 // { kEventClassControl , kEventControlBoundsChanged } ,
111 // kEventControlEnabledStateChanged , kEventControlVisibilityChanged , kEventControlHiliteChanged
117 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
119 OSStatus result
= eventNotHandledErr
;
121 wxMacCarbonEvent
cEvent( event
) ;
123 ControlRef controlRef
;
124 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
126 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
128 switch( GetEventKind( event
) )
130 case kEventControlDraw
:
132 RgnHandle updateRgn
= cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
) ;
133 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
135 #if 0 // in case we would need a coregraphics compliant background erase first
136 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
137 if ( thisWindow
->MacIsUserPane() )
140 err
= HIViewGetBounds( controlRef
, &bounds
);
141 CGContextSetRGBFillColor( cgContext
, 1 , 1 , 1 , 1 );
142 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
143 CGContextFillRect( cgContext
, bounds
);
146 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
149 result
= eventNotHandledErr
;
158 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
160 OSStatus result
= eventNotHandledErr
;
162 switch ( GetEventClass( event
) )
164 case kEventClassControl
:
165 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
173 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
175 // ---------------------------------------------------------------------------
176 // UserPane events for non OSX builds
177 // ---------------------------------------------------------------------------
179 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
181 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
182 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
183 win
->MacControlUserPaneDrawProc(part
) ;
186 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
188 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
189 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
190 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
193 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
195 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
196 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
197 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
200 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
202 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
203 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
204 win
->MacControlUserPaneIdleProc() ;
207 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
209 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
210 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
211 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
214 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
216 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
217 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
218 win
->MacControlUserPaneActivateProc(activating
) ;
221 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
223 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
224 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
225 return win
->MacControlUserPaneFocusProc(action
) ;
228 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
230 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
231 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
232 win
->MacControlUserPaneBackgroundProc(info
) ;
235 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
237 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
240 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
242 return kControlNoPart
;
245 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
247 return kControlNoPart
;
250 void wxWindowMac::MacControlUserPaneIdleProc()
254 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
256 return kControlNoPart
;
259 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
263 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
265 return kControlNoPart
;
268 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
272 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
273 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
274 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
275 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
276 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
277 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
278 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
279 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
281 // ===========================================================================
283 // ===========================================================================
285 wxList
wxWinMacControlList(wxKEY_INTEGER
);
287 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
289 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
292 return (wxControl
*)node
->GetData();
295 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
297 // adding NULL ControlRef is (first) surely a result of an error and
298 // (secondly) breaks native event processing
299 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
301 if ( !wxWinMacControlList
.Find((long)inControl
) )
302 wxWinMacControlList
.Append((long)inControl
, control
);
305 void wxRemoveMacControlAssociation(wxWindow
*control
)
307 wxWinMacControlList
.DeleteObject(control
);
311 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
313 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
315 // we have to setup the brush in the current port and return noErr
316 // or return an error code so that the control manager walks further up the
317 // hierarchy to find a correct background
319 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
321 OSStatus status
= paramErr
;
324 case kControlMsgApplyTextColor
:
326 case kControlMsgSetUpBackground
:
328 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
332 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
336 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
338 // this clipping is only needed for non HIView
340 RgnHandle clip
= NewRgn() ;
343 wx
->MacWindowToRootWindow( &x
,&y
) ;
344 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
345 OffsetRgn( clip
, x
, y
) ;
352 else if ( wx->MacIsUserPane() )
354 // if we don't have a valid brush for such a control, we have to call the
355 // setup of our parent ourselves
356 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
369 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
370 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
374 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
377 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
382 // ----------------------------------------------------------------------------
383 // constructors and such
384 // ----------------------------------------------------------------------------
386 void wxWindowMac::Init()
388 m_backgroundTransparent
= FALSE
;
390 // as all windows are created with WS_VISIBLE style...
393 m_hScrollBar
= NULL
;
394 m_vScrollBar
= NULL
;
395 m_macBackgroundBrush
= wxNullBrush
;
397 m_macControl
= NULL
;
399 m_macIsUserPane
= TRUE
;
401 // make sure all proc ptrs are available
403 if ( gControlUserPaneDrawUPP
== NULL
)
405 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
406 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
407 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
408 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
409 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
410 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
411 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
412 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
414 if ( wxMacLiveScrollbarActionUPP
== NULL
)
416 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
419 if ( wxMacSetupControlBackgroundUPP
== NULL
)
421 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
427 wxWindowMac::~wxWindowMac()
431 m_isBeingDeleted
= TRUE
;
433 #ifndef __WXUNIVERSAL__
434 // VS: make sure there's no wxFrame with last focus set to us:
435 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
437 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
440 if ( frame
->GetLastFocus() == this )
442 frame
->SetLastFocus((wxWindow
*)NULL
);
447 #endif // __WXUNIVERSAL__
449 // wxRemoveMacControlAssociation( this ) ;
450 // If we delete an item, we should initialize the parent panel,
451 // because it could now be invalid.
452 wxWindow
*parent
= GetParent() ;
455 if (parent
->GetDefaultItem() == (wxButton
*) this)
456 parent
->SetDefaultItem(NULL
);
458 if ( (ControlRef
) m_macControl
)
460 // in case the callback might be called during destruction
461 wxRemoveMacControlAssociation( this) ;
462 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
463 ::DisposeControl( (ControlRef
) m_macControl
) ;
464 m_macControl
= NULL
;
467 if ( g_MacLastWindow
== this )
469 g_MacLastWindow
= NULL
;
472 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
475 if ( frame
->GetLastFocus() == this )
476 frame
->SetLastFocus( NULL
) ;
479 if ( gFocusWindow
== this )
481 gFocusWindow
= NULL
;
486 // delete our drop target if we've got one
487 #if wxUSE_DRAG_AND_DROP
488 if ( m_dropTarget
!= NULL
)
493 #endif // wxUSE_DRAG_AND_DROP
498 void wxWindowMac::MacInstallEventHandler()
500 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
501 GetEventTypeCount(eventList
), eventList
, this,
502 (EventHandlerRef
*)&m_macControlEventHandler
);
507 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
511 const wxString
& name
)
513 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
515 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
518 parent
->AddChild(this);
520 m_windowVariant
= parent
->GetWindowVariant() ;
522 if ( m_macIsUserPane
)
524 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
526 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
/*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
528 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
530 MacPostControlCreate(pos
,size
) ;
531 #if !TARGET_API_MAC_OSX
532 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
533 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
534 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
535 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
536 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
537 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
538 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
539 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
540 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
541 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
542 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
543 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
544 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
545 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
546 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
547 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
550 #ifndef __WXUNIVERSAL__
551 // Don't give scrollbars to wxControls unless they ask for them
552 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
553 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
555 MacCreateScrollBars( style
) ;
559 wxWindowCreateEvent
event(this);
560 GetEventHandler()->AddPendingEvent(event
);
565 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
567 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
569 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
570 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
572 MacInstallEventHandler();
574 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
575 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
576 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
578 // adjust font, controlsize etc
579 DoSetWindowVariant( m_windowVariant
) ;
581 #if !TARGET_API_MAC_OSX
582 // eventually we can fix some clipping issues be reactivating this hook
583 //if ( m_macIsUserPane )
584 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
587 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
589 wxSize new_size
= size
;
590 if (!m_macIsUserPane
)
592 wxSize
best_size( DoGetBestSize() );
595 new_size
.x
= best_size
.x
;
598 new_size
.y
= best_size
.y
;
600 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
603 SetCursor( *wxSTANDARD_CURSOR
) ;
607 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
609 wxASSERT( m_macControl
!= NULL
) ;
611 m_windowVariant
= variant
;
614 ThemeFontID themeFont
= kThemeSystemFont
;
616 // we will get that from the settings later
617 // and make this NORMAL later, but first
618 // we have a few calculations that we must fix
622 case wxWINDOW_VARIANT_NORMAL
:
623 size
= kControlSizeNormal
;
624 themeFont
= kThemeSystemFont
;
626 case wxWINDOW_VARIANT_SMALL
:
627 size
= kControlSizeSmall
;
628 themeFont
= kThemeSmallSystemFont
;
630 case wxWINDOW_VARIANT_MINI
:
631 if (UMAGetSystemVersion() >= 0x1030 )
633 // not always defined in the headers
639 size
= kControlSizeSmall
;
640 themeFont
= kThemeSmallSystemFont
;
643 case wxWINDOW_VARIANT_LARGE
:
644 size
= kControlSizeLarge
;
645 themeFont
= kThemeSystemFont
;
648 wxFAIL_MSG(_T("unexpected window variant"));
651 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
654 font
.MacCreateThemeFont( themeFont
) ;
658 void wxWindowMac::MacUpdateControlFont()
660 ControlFontStyleRec fontStyle
;
661 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
663 switch( m_font
.MacGetThemeFontID() )
665 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
666 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
667 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
668 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
670 fontStyle
.flags
= kControlUseFontMask
;
674 fontStyle
.font
= m_font
.MacGetFontNum() ;
675 fontStyle
.style
= m_font
.MacGetFontStyle() ;
676 fontStyle
.size
= m_font
.MacGetFontSize() ;
677 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
680 fontStyle
.just
= teJustLeft
;
681 fontStyle
.flags
|= kControlUseJustMask
;
682 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
683 fontStyle
.just
= teJustCenter
;
684 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
685 fontStyle
.just
= teJustRight
;
688 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
689 fontStyle
.flags
|= kControlUseForeColorMask
;
691 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
695 bool wxWindowMac::SetFont(const wxFont
& font
)
697 bool retval
= !wxWindowBase::SetFont( font
) ;
699 MacUpdateControlFont() ;
704 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
706 if ( !wxWindowBase::SetForegroundColour(col
) )
709 MacUpdateControlFont() ;
714 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
716 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
720 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
722 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
724 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
726 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
730 brush
.SetColour( col
) ;
732 MacSetBackgroundBrush( brush
) ;
734 MacUpdateControlFont() ;
740 bool wxWindowMac::MacCanFocus() const
742 wxASSERT( m_macControl
!= NULL
) ;
748 void wxWindowMac::SetFocus()
750 if ( gFocusWindow
== this )
753 if ( AcceptsFocus() )
759 if ( gFocusWindow
->m_caret
)
761 gFocusWindow
->m_caret
->OnKillFocus();
763 #endif // wxUSE_CARET
764 #ifndef __WXUNIVERSAL__
765 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
766 // TODO we must use the built-in focusing
767 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
769 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
770 control
->MacRedrawControl() ;
773 // Without testing the window id, for some reason
774 // a kill focus event can still be sent to
775 // the control just being focussed.
776 int thisId
= this->m_windowId
;
777 int gFocusWindowId
= gFocusWindow
->m_windowId
;
778 if (gFocusWindowId
!= thisId
)
780 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
781 event
.SetEventObject(gFocusWindow
);
782 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
785 gFocusWindow
= this ;
791 m_caret
->OnSetFocus();
793 #endif // wxUSE_CARET
794 // panel wants to track the window which was the last to have focus in it
795 wxChildFocusEvent
eventFocus(this);
796 GetEventHandler()->ProcessEvent(eventFocus
);
798 #ifndef __WXUNIVERSAL__
799 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
800 if ( control
&& control
->GetHandle() )
802 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
805 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
806 event
.SetEventObject(this);
807 GetEventHandler()->ProcessEvent(event
) ;
813 void wxWindowMac::DoCaptureMouse()
815 wxTheApp
->s_captureWindow
= this ;
818 wxWindow
* wxWindowBase::GetCapture()
820 return wxTheApp
->s_captureWindow
;
823 void wxWindowMac::DoReleaseMouse()
825 wxTheApp
->s_captureWindow
= NULL
;
828 #if wxUSE_DRAG_AND_DROP
830 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
832 if ( m_dropTarget
!= 0 ) {
836 m_dropTarget
= pDropTarget
;
837 if ( m_dropTarget
!= 0 )
845 // Old style file-manager drag&drop
846 void wxWindowMac::DragAcceptFiles(bool accept
)
851 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
852 int& w
, int& h
) const
855 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
860 w
= bounds
.right
- bounds
.left
;
861 h
= bounds
.bottom
- bounds
.top
;
863 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
866 Point tlworigin
= { 0 , 0 } ;
869 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
870 ::LocalToGlobal( &tlworigin
) ;
877 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
880 int& w
, int& h
) const
884 // todo the default calls may be used as soon as PostCreateControl Is moved here
885 w
= size
.x
; // WidthDefault( size.x );
886 h
= size
.y
; // HeightDefault( size.y ) ;
887 #if !TARGET_API_MAC_OSX
888 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
895 void wxWindowMac::DoGetSize(int *x
, int *y
) const
897 #if TARGET_API_MAC_OSX
898 int x1
, y1
, w1
,h1
;
899 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
905 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
906 if(x
) *x
= bounds
.right
- bounds
.left
;
907 if(y
) *y
= bounds
.bottom
- bounds
.top
;
911 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
913 #if TARGET_API_MAC_OSX
914 int x1
, y1
, w1
,h1
;
915 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
918 wxWindow
*parent
= GetParent();
921 wxPoint
pt(parent
->GetClientAreaOrigin());
930 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
931 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
933 int xx
= bounds
.left
;
934 int yy
= bounds
.top
;
936 if ( !GetParent()->IsTopLevel() )
938 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
944 wxPoint
pt(GetParent()->GetClientAreaOrigin());
953 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
955 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
957 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
960 Point localwhere
= {0,0} ;
962 if(x
) localwhere
.h
= * x
;
963 if(y
) localwhere
.v
= * y
;
965 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
966 ::GlobalToLocal( &localwhere
) ;
967 if(x
) *x
= localwhere
.h
;
968 if(y
) *y
= localwhere
.v
;
971 MacRootWindowToWindow( x
, y
) ;
973 wxPoint origin
= GetClientAreaOrigin() ;
974 if(x
) *x
-= origin
.x
;
975 if(y
) *y
-= origin
.y
;
978 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
980 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
981 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
983 wxPoint origin
= GetClientAreaOrigin() ;
984 if(x
) *x
+= origin
.x
;
985 if(y
) *y
+= origin
.y
;
987 MacWindowToRootWindow( x
, y
) ;
990 Point localwhere
= { 0,0 };
991 if(x
) localwhere
.h
= * x
;
992 if(y
) localwhere
.v
= * y
;
994 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
995 ::LocalToGlobal( &localwhere
) ;
996 if(x
) *x
= localwhere
.h
;
997 if(y
) *y
= localwhere
.v
;
1001 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1003 wxPoint origin
= GetClientAreaOrigin() ;
1004 if(x
) *x
+= origin
.x
;
1005 if(y
) *y
+= origin
.y
;
1007 MacWindowToRootWindow( x
, y
) ;
1010 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1012 MacRootWindowToWindow( x
, y
) ;
1014 wxPoint origin
= GetClientAreaOrigin() ;
1015 if(x
) *x
-= origin
.x
;
1016 if(y
) *y
-= origin
.y
;
1019 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1021 #if TARGET_API_MAC_OSX
1023 if ( x
) pt
.x
= *x
;
1024 if ( y
) pt
.y
= *y
;
1026 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1028 if ( x
) *x
= (int) pt
.x
;
1029 if ( y
) *y
= (int) pt
.y
;
1031 if ( !IsTopLevel() )
1034 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1035 if(x
) *x
+= bounds
.left
;
1036 if(y
) *y
+= bounds
.top
;
1041 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1046 MacWindowToRootWindow( &x1
, &y1
) ;
1051 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1053 #if TARGET_API_MAC_OSX
1055 if ( x
) pt
.x
= *x
;
1056 if ( y
) pt
.y
= *y
;
1058 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1060 if ( x
) *x
= (int) pt
.x
;
1061 if ( y
) *y
= (int) pt
.y
;
1063 if ( !IsTopLevel() )
1066 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1067 if(x
) *x
-= bounds
.left
;
1068 if(y
) *y
-= bounds
.top
;
1073 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1078 MacRootWindowToWindow( &x1
, &y1
) ;
1083 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1085 wxSize sizeTotal
= size
;
1087 RgnHandle rgn
= NewRgn() ;
1091 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1093 GetRegionBounds( rgn
, &content
) ;
1098 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1101 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1102 #if !TARGET_API_MAC_OSX
1103 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1106 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1107 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1109 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1110 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1116 // Get size *available for subwindows* i.e. excluding menu bar etc.
1117 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1121 RgnHandle rgn
= NewRgn() ;
1123 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1125 GetRegionBounds( rgn
, &content
) ;
1130 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1132 #if !TARGET_API_MAC_OSX
1134 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1135 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1137 ww
= content
.right
- content
.left
;
1138 hh
= content
.bottom
- content
.top
;
1140 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1141 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1143 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1149 GetSize( &w
, &h
) ;
1151 MacClientToRootWindow( &x1
, &y1
) ;
1152 MacClientToRootWindow( &w
, &h
) ;
1154 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1156 int totW
= 10000 , totH
= 10000;
1159 if ( iter
->IsTopLevel() )
1161 iter
->GetSize( &totW
, &totH
) ;
1165 iter
= iter
->GetParent() ;
1168 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1170 hh
-= MAC_SCROLLBAR_SIZE
;
1176 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1178 ww
-= MAC_SCROLLBAR_SIZE
;
1190 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1192 if (m_cursor
== cursor
)
1195 if (wxNullCursor
== cursor
)
1197 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1202 if ( ! wxWindowBase::SetCursor( cursor
) )
1206 wxASSERT_MSG( m_cursor
.Ok(),
1207 wxT("cursor must be valid after call to the base version"));
1211 TODO why do we have to use current coordinates ?
1214 wxWindowMac *mouseWin ;
1217 // Change the cursor NOW if we're within the correct window
1220 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1222 if ( mouseWin == this && !wxIsBusy() )
1224 m_cursor.MacInstall() ;
1230 m_cursor
.MacInstall() ;
1237 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1239 menu
->SetInvokingWindow(this);
1241 ClientToScreen( &x
, &y
) ;
1243 menu
->MacBeforeDisplay( true ) ;
1244 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1245 if ( HiWord(menuResult
) != 0 )
1248 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1249 wxMenuItem
* item
= NULL
;
1251 item
= menu
->FindItem(id
, &realmenu
) ;
1252 if (item
->IsCheckable())
1254 item
->Check( !item
->IsChecked() ) ;
1256 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1258 menu
->MacAfterDisplay( true ) ;
1260 menu
->SetInvokingWindow(NULL
);
1266 // ----------------------------------------------------------------------------
1268 // ----------------------------------------------------------------------------
1272 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1274 wxWindowBase::DoSetToolTip(tooltip
);
1277 m_tooltip
->SetWindow(this);
1280 #endif // wxUSE_TOOLTIPS
1282 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1284 int former_x
, former_y
, former_w
, former_h
;
1285 #if !TARGET_API_MAC_OSX
1286 DoGetPosition( &former_x
, &former_y
) ;
1287 DoGetSize( &former_w
, &former_h
) ;
1289 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1292 int actualWidth
= width
;
1293 int actualHeight
= height
;
1297 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1298 actualWidth
= m_minWidth
;
1299 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1300 actualHeight
= m_minHeight
;
1301 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1302 actualWidth
= m_maxWidth
;
1303 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1304 actualHeight
= m_maxHeight
;
1306 bool doMove
= false ;
1307 bool doResize
= false ;
1309 if ( actualX
!= former_x
|| actualY
!= former_y
)
1313 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1318 if ( doMove
|| doResize
)
1320 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1321 #if TARGET_API_MAC_OSX
1322 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1325 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1327 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1329 MacRepositionScrollBars() ;
1332 wxPoint
point(actualX
,actualY
);
1333 wxMoveEvent
event(point
, m_windowId
);
1334 event
.SetEventObject(this);
1335 GetEventHandler()->ProcessEvent(event
) ;
1339 MacRepositionScrollBars() ;
1340 wxSize
size(actualWidth
, actualHeight
);
1341 wxSizeEvent
event(size
, m_windowId
);
1342 event
.SetEventObject(this);
1343 GetEventHandler()->ProcessEvent(event
);
1349 wxSize
wxWindowMac::DoGetBestSize() const
1352 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1353 short baselineoffset ;
1354 int bestWidth, bestHeight ;
1355 ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ;
1357 if ( EmptyRect( &bestsize ) )
1360 bestsize.left = bestsize.top = 0 ;
1361 bestsize.right = 16 ;
1362 bestsize.bottom = 16 ;
1363 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1365 bestsize.bottom = 16 ;
1367 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1369 bestsize.bottom = 24 ;
1373 // return wxWindowBase::DoGetBestSize() ;
1377 bestWidth = bestsize.right - bestsize.left ;
1378 bestHeight = bestsize.bottom - bestsize.top ;
1379 if ( bestHeight < 10 )
1382 return wxSize(bestWidth, bestHeight);
1384 return wxWindowBase::DoGetBestSize() ;
1388 // set the size of the window: if the dimensions are positive, just use them,
1389 // but if any of them is equal to -1, it means that we must find the value for
1390 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1391 // which case -1 is a valid value for x and y)
1393 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1394 // the width/height to best suit our contents, otherwise we reuse the current
1396 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1398 // get the current size and position...
1399 int currentX
, currentY
;
1400 GetPosition(¤tX
, ¤tY
);
1402 int currentW
,currentH
;
1403 GetSize(¤tW
, ¤tH
);
1405 // ... and don't do anything (avoiding flicker) if it's already ok
1406 if ( x
== currentX
&& y
== currentY
&&
1407 width
== currentW
&& height
== currentH
)
1410 MacRepositionScrollBars() ; // we might have a real position shift
1414 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1416 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1419 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1421 wxSize
size(-1, -1);
1424 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1426 size
= DoGetBestSize();
1431 // just take the current one
1438 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1442 size
= DoGetBestSize();
1444 //else: already called DoGetBestSize() above
1450 // just take the current one
1455 DoMoveWindow(x
, y
, width
, height
);
1459 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1461 RgnHandle rgn
= NewRgn() ;
1463 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1464 GetRegionBounds( rgn
, &content
) ;
1466 #if !TARGET_API_MAC_OSX
1468 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1469 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1472 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1475 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1477 if ( clientheight
!= -1 || clientheight
!= -1 )
1479 int currentclientwidth
, currentclientheight
;
1480 int currentwidth
, currentheight
;
1482 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1483 GetSize( ¤twidth
, ¤theight
) ;
1485 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1486 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1490 void wxWindowMac::SetTitle(const wxString
& title
)
1492 m_label
= wxStripMenuCodes(title
) ;
1496 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1501 wxString
wxWindowMac::GetTitle() const
1506 void wxWindowMac::MacPropagateVisibilityChanged()
1508 MacVisibilityChanged() ;
1510 wxWindowListNode
*node
= GetChildren().GetFirst();
1513 wxWindowMac
*child
= node
->GetData();
1514 if ( child
->IsShown() )
1515 child
->MacPropagateVisibilityChanged( ) ;
1516 node
= node
->GetNext();
1520 bool wxWindowMac::Show(bool show
)
1522 if ( !wxWindowBase::Show(show
) )
1525 // TODO use visibilityChanged Carbon Event for OSX
1526 bool former
= MacIsReallyShown() ;
1528 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1529 if ( former
!= MacIsReallyShown() )
1530 MacPropagateVisibilityChanged() ;
1534 bool wxWindowMac::MacIsReallyShown()
1536 // only under OSX the visibility of the TLW is taken into account
1537 #if TARGET_API_MAC_OSX
1538 return IsControlVisible( (ControlRef
) m_macControl
) ;
1540 wxWindow
* win
= this ;
1541 while( win
->IsShown() )
1543 if ( win
->IsTopLevel() )
1546 win
= win
->GetParent() ;
1555 void wxWindowMac::MacVisibilityChanged()
1559 void wxWindowMac::MacPropagateEnabledStateChanged( )
1561 MacEnabledStateChanged() ;
1563 wxWindowListNode
*node
= GetChildren().GetFirst();
1566 wxWindowMac
*child
= node
->GetData();
1567 if ( child
->IsEnabled() )
1568 child
->MacPropagateEnabledStateChanged() ;
1569 node
= node
->GetNext();
1573 bool wxWindowMac::Enable(bool enable
)
1575 wxASSERT( m_macControl
!= NULL
) ;
1576 if ( !wxWindowBase::Enable(enable
) )
1579 bool former
= MacIsReallyEnabled() ;
1581 UMAActivateControl( (ControlRef
) m_macControl
) ;
1583 UMADeactivateControl( (ControlRef
) m_macControl
) ;
1585 if ( former
!= MacIsReallyEnabled() )
1586 MacPropagateEnabledStateChanged() ;
1590 bool wxWindowMac::MacIsReallyEnabled()
1592 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1595 void wxWindowMac::MacEnabledStateChanged()
1599 int wxWindowMac::GetCharHeight() const
1601 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1602 return dc
.GetCharHeight() ;
1605 int wxWindowMac::GetCharWidth() const
1607 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1608 return dc
.GetCharWidth() ;
1611 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1612 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1614 const wxFont
*fontToUse
= theFont
;
1616 fontToUse
= &m_font
;
1618 wxClientDC
dc( (wxWindowMac
*) this ) ;
1620 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1621 if ( externalLeading
)
1622 *externalLeading
= le
;
1632 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1633 * we always intersect with the entire window, not only with the client area
1636 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1638 #if TARGET_API_MAC_OSX
1639 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1641 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1643 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1644 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1647 if ( MacGetTopLevelWindow() == NULL )
1650 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1653 wxPoint client = GetClientAreaOrigin();
1656 int x2 = m_width - client.x;
1657 int y2 = m_height - client.y;
1659 if (IsKindOf( CLASSINFO(wxButton)))
1661 // buttons have an "aura"
1668 Rect clientrect = { y1, x1, y2, x2 };
1672 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1673 SectRect( &clientrect , &r , &clientrect ) ;
1676 if ( !EmptyRect( &clientrect ) )
1678 int top = 0 , left = 0 ;
1680 MacClientToRootWindow( &left , &top ) ;
1681 OffsetRect( &clientrect , left , top ) ;
1683 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1689 void wxWindowMac::MacRedrawControl()
1692 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1694 #if TARGET_API_MAC_CARBON
1697 wxClientDC dc(this) ;
1698 wxMacPortSetter helper(&dc) ;
1699 wxMacWindowClipper clipper(this) ;
1700 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1701 UMADrawControl( (ControlRef) m_macControl ) ;
1708 void wxWindowMac::OnPaint(wxPaintEvent& event)
1710 // why don't we skip that here ?
1714 wxWindowMac
*wxGetActiveWindow()
1716 // actually this is a windows-only concept
1720 // Coordinates relative to the window
1721 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1723 // We really don't move the mouse programmatically under Mac.
1726 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1728 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1733 event
.GetDC()->Clear() ;
1736 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1738 wxWindowDC
dc(this) ;
1739 wxMacPortSetter
helper(&dc
) ;
1741 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1744 int wxWindowMac::GetScrollPos(int orient
) const
1746 if ( orient
== wxHORIZONTAL
)
1749 return m_hScrollBar
->GetThumbPosition() ;
1754 return m_vScrollBar
->GetThumbPosition() ;
1759 // This now returns the whole range, not just the number
1760 // of positions that we can scroll.
1761 int wxWindowMac::GetScrollRange(int orient
) const
1763 if ( orient
== wxHORIZONTAL
)
1766 return m_hScrollBar
->GetRange() ;
1771 return m_vScrollBar
->GetRange() ;
1776 int wxWindowMac::GetScrollThumb(int orient
) const
1778 if ( orient
== wxHORIZONTAL
)
1781 return m_hScrollBar
->GetThumbSize() ;
1786 return m_vScrollBar
->GetThumbSize() ;
1791 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1793 if ( orient
== wxHORIZONTAL
)
1796 m_hScrollBar
->SetThumbPosition( pos
) ;
1801 m_vScrollBar
->SetThumbPosition( pos
) ;
1805 void wxWindowMac::MacPaintBorders( int left
, int top
)
1811 wxGetOsVersion( &major
, &minor
);
1813 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1814 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1816 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1817 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1818 // OS X has lighter border edges than classic:
1821 darkShadow
.red
= 0x8E8E;
1822 darkShadow
.green
= 0x8E8E;
1823 darkShadow
.blue
= 0x8E8E;
1824 lightShadow
.red
= 0xBDBD;
1825 lightShadow
.green
= 0xBDBD;
1826 lightShadow
.blue
= 0xBDBD;
1832 GetSize( &w
, &h
) ;
1833 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1835 #if wxMAC_USE_THEME_BORDER
1836 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1839 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1840 InsetRect( &rect , border , border );
1841 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1844 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1846 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1847 RGBForeColor( &face
);
1848 MoveTo( left
+ 0 , top
+ h
- 2 );
1849 LineTo( left
+ 0 , top
+ 0 );
1850 LineTo( left
+ w
- 2 , top
+ 0 );
1852 MoveTo( left
+ 2 , top
+ h
- 3 );
1853 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1854 LineTo( left
+ w
- 3 , top
+ 2 );
1856 RGBForeColor( sunken
? &face
: &darkShadow
);
1857 MoveTo( left
+ 0 , top
+ h
- 1 );
1858 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1859 LineTo( left
+ w
- 1 , top
+ 0 );
1861 RGBForeColor( sunken
? &lightShadow
: &white
);
1862 MoveTo( left
+ 1 , top
+ h
- 3 );
1863 LineTo( left
+ 1, top
+ 1 );
1864 LineTo( left
+ w
- 3 , top
+ 1 );
1866 RGBForeColor( sunken
? &white
: &lightShadow
);
1867 MoveTo( left
+ 1 , top
+ h
- 2 );
1868 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1869 LineTo( left
+ w
- 2 , top
+ 1 );
1871 RGBForeColor( sunken
? &darkShadow
: &face
);
1872 MoveTo( left
+ 2 , top
+ h
- 4 );
1873 LineTo( left
+ 2 , top
+ 2 );
1874 LineTo( left
+ w
- 4 , top
+ 2 );
1877 else if (HasFlag(wxSIMPLE_BORDER
))
1879 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1880 RGBForeColor( &darkShadow
) ;
1881 FrameRect( &rect
) ;
1885 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1887 if ( child
== m_hScrollBar
)
1888 m_hScrollBar
= NULL
;
1889 if ( child
== m_vScrollBar
)
1890 m_vScrollBar
= NULL
;
1892 wxWindowBase::RemoveChild( child
) ;
1895 // New function that will replace some of the above.
1896 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1897 int range
, bool refresh
)
1899 if ( orient
== wxHORIZONTAL
)
1903 if ( range
== 0 || thumbVisible
>= range
)
1905 if ( m_hScrollBar
->IsShown() )
1906 m_hScrollBar
->Show(false) ;
1910 if ( !m_hScrollBar
->IsShown() )
1911 m_hScrollBar
->Show(true) ;
1912 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1920 if ( range
== 0 || thumbVisible
>= range
)
1922 if ( m_vScrollBar
->IsShown() )
1923 m_vScrollBar
->Show(false) ;
1927 if ( !m_vScrollBar
->IsShown() )
1928 m_vScrollBar
->Show(true) ;
1929 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1933 MacRepositionScrollBars() ;
1936 // Does a physical scroll
1937 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1939 if( dx
== 0 && dy
==0 )
1944 wxClientDC
dc(this) ;
1945 wxMacPortSetter
helper(&dc
) ;
1947 int width
, height
;
1948 GetClientSize( &width
, &height
) ;
1955 // TODO take out the boundaries
1956 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
1958 RgnHandle updateRgn
= NewRgn() ;
1961 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
1962 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
1963 SectRect( &scrollrect
, &r
, &scrollrect
) ;
1965 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
1967 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
1968 // but it seems the update only refreshes the background of the control, rather than calling
1969 // kEventControlDraw, so we need to force a proper update here. There has to be a better
1970 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
1973 // we also have to scroll the update rgn in this rectangle
1974 // in order not to loose updates
1976 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
1977 RgnHandle formerUpdateRgn
= NewRgn() ;
1978 RgnHandle scrollRgn
= NewRgn() ;
1979 RectRgn( scrollRgn
, &scrollrect
) ;
1980 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
1982 LocalToGlobal( &pt
) ;
1983 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
1984 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1985 if ( !EmptyRgn( formerUpdateRgn
) )
1987 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
1988 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
1989 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
1991 InvalWindowRgn(rootWindow
, updateRgn
) ;
1992 DisposeRgn( updateRgn
) ;
1993 DisposeRgn( formerUpdateRgn
) ;
1994 DisposeRgn( scrollRgn
) ;
1998 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2000 wxWindowMac
*child
= node
->GetData();
2001 if (child
== m_vScrollBar
) continue;
2002 if (child
== m_hScrollBar
) continue;
2003 if (child
->IsTopLevel()) continue;
2006 child
->GetPosition( &x
, &y
);
2008 child
->GetSize( &w
, &h
);
2012 if (rect
->Intersects(rc
))
2013 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2017 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2021 // TODO remove, was moved higher up Update() ;
2025 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2027 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2029 wxScrollWinEvent wevent
;
2030 wevent
.SetPosition(event
.GetPosition());
2031 wevent
.SetOrientation(event
.GetOrientation());
2032 wevent
.m_eventObject
= this;
2034 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2035 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2036 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2037 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2038 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2039 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2040 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2041 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2042 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2043 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2044 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2045 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2046 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2047 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2048 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2049 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2051 GetEventHandler()->ProcessEvent(wevent
);
2055 // Get the window with the focus
2056 wxWindowMac
*wxWindowBase::FindFocus()
2058 return gFocusWindow
;
2061 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2063 // panel wants to track the window which was the last to have focus in it,
2064 // so we want to set ourselves as the window which last had focus
2066 // notice that it's also important to do it upwards the tree becaus
2067 // otherwise when the top level panel gets focus, it won't set it back to
2068 // us, but to some other sibling
2070 // CS:don't know if this is still needed:
2071 //wxChildFocusEvent eventFocus(this);
2072 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2077 void wxWindowMac::OnInternalIdle()
2079 // This calls the UI-update mechanism (querying windows for
2080 // menu/toolbar/control state information)
2081 if (wxUpdateUIEvent::CanUpdate(this))
2082 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2085 // Raise the window to the top of the Z order
2086 void wxWindowMac::Raise()
2090 // Lower the window to the bottom of the Z order
2091 void wxWindowMac::Lower()
2096 // static wxWindow *gs_lastWhich = NULL;
2098 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2100 // first trigger a set cursor event
2102 wxPoint clientorigin
= GetClientAreaOrigin() ;
2103 wxSize clientsize
= GetClientSize() ;
2105 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2107 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2109 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2110 if ( processedEvtSetCursor
&& event
.HasCursor() )
2112 cursor
= event
.GetCursor() ;
2117 // the test for processedEvtSetCursor is here to prevent using m_cursor
2118 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2119 // it - this is a way to say that our cursor shouldn't be used for this
2121 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2131 cursor
= *wxSTANDARD_CURSOR
;
2135 cursor
.MacInstall() ;
2137 return cursor
.Ok() ;
2140 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2144 return m_tooltip
->GetTip() ;
2146 return wxEmptyString
;
2149 void wxWindowMac::Update()
2151 #if TARGET_API_MAC_OSX
2152 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2154 ::Draw1Control( (ControlRef
) m_macControl
) ;
2158 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2160 wxTopLevelWindowMac
* win
= NULL
;
2161 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2164 win
= wxFindWinFromMacWindow( window
) ;
2168 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2172 RgnHandle visRgn
= NewRgn() ;
2173 RgnHandle tempRgn
= NewRgn() ;
2174 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2176 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2177 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2179 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2180 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2189 if ( includeOuterStructures
)
2190 InsetRect( &r
, -3 , -3 ) ;
2191 RectRgn( visRgn
, &r
) ;
2192 if ( !IsTopLevel() )
2194 wxWindow
* child
= this ;
2195 wxWindow
* parent
= child
->GetParent() ;
2200 // we have to find a better clipping algorithm here, in order not to clip things
2201 // positioned like status and toolbar
2202 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2204 size
= parent
->GetSize() ;
2209 size
= parent
->GetClientSize() ;
2210 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2214 parent
->MacWindowToRootWindow( &x
, &y
) ;
2215 MacRootWindowToWindow( &x
, &y
) ;
2217 SetRectRgn( tempRgn
,
2218 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2219 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2220 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2222 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2223 if ( parent
->IsTopLevel() )
2226 parent
= child
->GetParent() ;
2231 wxRegion vis
= visRgn
;
2232 DisposeRgn( visRgn
) ;
2233 DisposeRgn( tempRgn
) ;
2238 This function must not change the updatergn !
2240 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2242 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2243 bool handled
= false ;
2245 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2247 RgnHandle newupdate
= NewRgn() ;
2248 wxSize point
= GetClientSize() ;
2249 wxPoint origin
= GetClientAreaOrigin() ;
2250 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2251 SectRgn( newupdate
, updatergn
, newupdate
) ;
2252 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2253 m_updateRegion
= newupdate
;
2254 DisposeRgn( newupdate
) ;
2257 if ( !EmptyRgn(updatergn
) )
2259 wxWindowDC
dc(this);
2260 if (!EmptyRgn(updatergn
))
2261 dc
.SetClippingRegion(wxRegion(updatergn
));
2263 wxEraseEvent
eevent( GetId(), &dc
);
2264 eevent
.SetEventObject( this );
2265 GetEventHandler()->ProcessEvent( eevent
);
2267 if ( !m_updateRegion
.Empty() )
2269 // paint the window itself
2271 event
.m_timeStamp
= time
;
2272 event
.SetEventObject(this);
2273 handled
= GetEventHandler()->ProcessEvent(event
);
2275 // paint custom borders
2276 wxNcPaintEvent
eventNc( GetId() );
2277 eventNc
.SetEventObject( this );
2278 GetEventHandler()->ProcessEvent( eventNc
);
2284 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2286 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2287 // updatergn is always already clipped to our boundaries
2288 // if we are in compositing mode then it is in relative to the upper left of the control
2289 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2290 // of the toplevel window
2291 // it is in window coordinates, not in client coordinates
2293 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2294 RgnHandle ownUpdateRgn
= NewRgn() ;
2295 CopyRgn( updatergn
, ownUpdateRgn
) ;
2297 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2300 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2301 RgnHandle controlRgn
= NewRgn();
2302 RectRgn( controlRgn
, &bounds
);
2303 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2304 // the window update region
2305 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2306 DisposeRgn( controlRgn
);
2308 //KO: convert ownUpdateRgn to local coordinates
2309 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2312 MacDoRedraw( ownUpdateRgn
, time
) ;
2313 DisposeRgn( ownUpdateRgn
) ;
2317 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2319 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2323 if ( iter
->IsTopLevel() )
2324 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2326 iter
= iter
->GetParent() ;
2328 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2332 void wxWindowMac::MacCreateScrollBars( long style
)
2334 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2336 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2337 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2339 GetClientSize( &width
, &height
) ;
2341 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2342 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2343 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2344 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2346 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2347 vSize
, wxVERTICAL
);
2349 if ( style
& wxVSCROLL
)
2355 m_vScrollBar
->Show(false) ;
2357 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2358 hSize
, wxHORIZONTAL
);
2359 if ( style
& wxHSCROLL
)
2364 m_hScrollBar
->Show(false) ;
2367 // because the create does not take into account the client area origin
2368 MacRepositionScrollBars() ; // we might have a real position shift
2371 void wxWindowMac::MacRepositionScrollBars()
2373 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2374 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2376 // get real client area
2380 GetSize( &width
, &height
) ;
2382 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2383 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2385 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2386 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2387 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2388 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2394 GetSize( &w
, &h
) ;
2396 MacClientToRootWindow( &x
, &y
) ;
2397 MacClientToRootWindow( &w
, &h
) ;
2399 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2401 int totW
= 10000 , totH
= 10000;
2404 if ( iter
->IsTopLevel() )
2406 iter
->GetSize( &totW
, &totH
) ;
2410 iter
= iter
->GetParent() ;
2438 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2442 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2446 bool wxWindowMac::AcceptsFocus() const
2448 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2451 void wxWindowMac::MacSuperChangedPosition()
2453 // only window-absolute structures have to be moved i.e. controls
2455 wxWindowListNode
*node
= GetChildren().GetFirst();
2458 wxWindowMac
*child
= node
->GetData();
2459 child
->MacSuperChangedPosition() ;
2460 node
= node
->GetNext();
2464 void wxWindowMac::MacTopLevelWindowChangedPosition()
2466 // only screen-absolute structures have to be moved i.e. glcanvas
2468 wxWindowListNode
*node
= GetChildren().GetFirst();
2471 wxWindowMac
*child
= node
->GetData();
2472 child
->MacTopLevelWindowChangedPosition() ;
2473 node
= node
->GetNext();
2477 long wxWindowMac::MacGetLeftBorderSize( ) const
2482 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2485 #if wxMAC_USE_THEME_BORDER
2486 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2490 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2493 #if wxMAC_USE_THEME_BORDER
2494 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2498 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2505 long wxWindowMac::MacGetRightBorderSize( ) const
2507 // they are all symmetric in mac themes
2508 return MacGetLeftBorderSize() ;
2511 long wxWindowMac::MacGetTopBorderSize( ) const
2513 // they are all symmetric in mac themes
2514 return MacGetLeftBorderSize() ;
2517 long wxWindowMac::MacGetBottomBorderSize( ) const
2519 // they are all symmetric in mac themes
2520 return MacGetLeftBorderSize() ;
2523 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2525 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2528 // Find the wxWindowMac at the current mouse position, returning the mouse
2530 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2532 pt
= wxGetMousePosition();
2533 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2537 // Get the current mouse position.
2538 wxPoint
wxGetMousePosition()
2541 wxGetMousePosition(& x
, & y
);
2542 return wxPoint(x
, y
);
2545 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2547 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2549 // copied from wxGTK : CS
2550 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2553 // (a) it's a command event and so is propagated to the parent
2554 // (b) under MSW it can be generated from kbd too
2555 // (c) it uses screen coords (because of (a))
2556 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2558 this->ClientToScreen(event
.GetPosition()));
2559 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2562 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2568 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2570 // OS Needs it in tlw content area coordinates
2571 MacClientToRootWindow( &x
, &y
) ;
2575 // OS Needs it in window not client coordinates
2576 wxPoint origin
= GetClientAreaOrigin() ;
2581 SInt16 controlpart
;
2586 short modifiers
= 0;
2588 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2589 modifiers
|= btnState
;
2591 if ( event
.m_shiftDown
)
2592 modifiers
|= shiftKey
;
2594 if ( event
.m_controlDown
)
2595 modifiers
|= controlKey
;
2597 if ( event
.m_altDown
)
2598 modifiers
|= optionKey
;
2600 if ( event
.m_metaDown
)
2601 modifiers
|= cmdKey
;
2603 bool handled
= false ;
2605 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2607 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2608 wxTheApp
->s_lastMouseDown
= 0 ;
2609 if ( controlpart
!= kControlNoPart
)
2611 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2624 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2626 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2629 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2633 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2634 Rect bounds
= { y
, x
, y
+h
, x
+w
};