1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
39 #include "wx/toolbar.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
69 wxWindowMac
* gFocusWindow
= NULL
;
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
75 #endif // __WXUNIVERSAL__/__WXMAC__
77 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 0
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
103 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
105 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
107 kEventControlVisibilityChanged
= 157
111 static const EventTypeSpec eventList
[] =
113 #if TARGET_API_MAC_OSX
114 { kEventClassControl
, kEventControlDraw
} ,
115 { kEventClassControl
, kEventControlVisibilityChanged
} ,
116 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
117 { kEventClassControl
, kEventControlHiliteChanged
} ,
118 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
119 // { kEventClassControl , kEventControlBoundsChanged } ,
127 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
129 OSStatus result
= eventNotHandledErr
;
131 wxMacCarbonEvent
cEvent( event
) ;
133 ControlRef controlRef
;
134 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
136 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
138 switch( GetEventKind( event
) )
140 case kEventControlDraw
:
142 RgnHandle updateRgn
= NULL
;
144 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
145 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
147 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
149 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
152 // in case we would need a coregraphics compliant background erase first
153 // now usable to track redraws
154 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
155 if ( thisWindow
->MacIsUserPane() )
157 static float color
= 0.5 ;
160 HIViewGetBounds( controlRef
, &bounds
);
161 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
162 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
163 CGContextFillRect( cgContext
, bounds
);
174 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
178 case kEventControlVisibilityChanged
:
179 thisWindow
->MacVisibilityChanged() ;
181 case kEventControlEnabledStateChanged
:
182 thisWindow
->MacEnabledStateChanged() ;
184 case kEventControlHiliteChanged
:
185 thisWindow
->MacHiliteChanged() ;
193 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
195 OSStatus result
= eventNotHandledErr
;
197 switch ( GetEventClass( event
) )
199 case kEventClassControl
:
200 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
208 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
210 // ---------------------------------------------------------------------------
211 // UserPane events for non OSX builds
212 // ---------------------------------------------------------------------------
214 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
216 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
217 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
218 win
->MacControlUserPaneDrawProc(part
) ;
221 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
223 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
224 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
225 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
228 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
230 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
231 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
232 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
235 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
237 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
238 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
239 win
->MacControlUserPaneIdleProc() ;
242 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
244 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
245 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
246 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
249 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
251 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
252 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
253 win
->MacControlUserPaneActivateProc(activating
) ;
256 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
258 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
259 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
260 return win
->MacControlUserPaneFocusProc(action
) ;
263 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
265 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
266 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
267 win
->MacControlUserPaneBackgroundProc(info
) ;
270 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
272 RgnHandle rgn
= NewRgn() ;
274 wxMacWindowStateSaver
sv( this ) ;
275 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
276 MacDoRedraw( rgn
, 0 ) ;
280 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
282 return kControlNoPart
;
285 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
287 return kControlNoPart
;
290 void wxWindowMac::MacControlUserPaneIdleProc()
294 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
296 return kControlNoPart
;
299 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
303 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
305 return kControlNoPart
;
308 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
312 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
313 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
314 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
315 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
316 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
317 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
318 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
319 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
321 // ===========================================================================
323 // ===========================================================================
325 wxList
wxWinMacControlList(wxKEY_INTEGER
);
327 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
329 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
332 return (wxControl
*)node
->GetData();
335 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
337 // adding NULL ControlRef is (first) surely a result of an error and
338 // (secondly) breaks native event processing
339 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
341 if ( !wxWinMacControlList
.Find((long)inControl
) )
342 wxWinMacControlList
.Append((long)inControl
, control
);
345 void wxRemoveMacControlAssociation(wxWindow
*control
)
347 wxWinMacControlList
.DeleteObject(control
);
351 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
353 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
355 // we have to setup the brush in the current port and return noErr
356 // or return an error code so that the control manager walks further up the
357 // hierarchy to find a correct background
359 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
361 OSStatus status
= paramErr
;
364 case kControlMsgApplyTextColor
:
366 case kControlMsgSetUpBackground
:
368 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
372 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
376 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
378 // this clipping is only needed for non HIView
380 RgnHandle clip
= NewRgn() ;
383 wx
->MacWindowToRootWindow( &x
,&y
) ;
384 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
385 OffsetRgn( clip
, x
, y
) ;
392 else if ( wx->MacIsUserPane() )
394 // if we don't have a valid brush for such a control, we have to call the
395 // setup of our parent ourselves
396 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
409 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
410 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
414 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
417 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
422 // ----------------------------------------------------------------------------
423 // constructors and such
424 // ----------------------------------------------------------------------------
426 void wxWindowMac::Init()
429 m_backgroundTransparent
= FALSE
;
431 // as all windows are created with WS_VISIBLE style...
434 m_hScrollBar
= NULL
;
435 m_vScrollBar
= NULL
;
436 m_macBackgroundBrush
= wxNullBrush
;
438 m_macControl
= NULL
;
440 m_macIsUserPane
= TRUE
;
442 // make sure all proc ptrs are available
444 if ( gControlUserPaneDrawUPP
== NULL
)
446 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
447 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
448 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
449 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
450 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
451 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
452 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
453 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
455 if ( wxMacLiveScrollbarActionUPP
== NULL
)
457 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
460 if ( wxMacSetupControlBackgroundUPP
== NULL
)
462 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
465 // we need a valid font for the encodings
466 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
470 wxWindowMac::~wxWindowMac()
474 m_isBeingDeleted
= TRUE
;
476 #ifndef __WXUNIVERSAL__
477 // VS: make sure there's no wxFrame with last focus set to us:
478 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
480 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
483 if ( frame
->GetLastFocus() == this )
485 frame
->SetLastFocus((wxWindow
*)NULL
);
490 #endif // __WXUNIVERSAL__
492 // wxRemoveMacControlAssociation( this ) ;
493 // If we delete an item, we should initialize the parent panel,
494 // because it could now be invalid.
495 wxWindow
*parent
= GetParent() ;
498 if (parent
->GetDefaultItem() == (wxButton
*) this)
499 parent
->SetDefaultItem(NULL
);
501 if ( (ControlRef
) m_macControl
)
503 // in case the callback might be called during destruction
504 wxRemoveMacControlAssociation( this) ;
505 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
506 ::DisposeControl( (ControlRef
) m_macControl
) ;
507 m_macControl
= NULL
;
510 if ( g_MacLastWindow
== this )
512 g_MacLastWindow
= NULL
;
515 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
518 if ( frame
->GetLastFocus() == this )
519 frame
->SetLastFocus( NULL
) ;
522 if ( gFocusWindow
== this )
524 gFocusWindow
= NULL
;
529 // delete our drop target if we've got one
530 #if wxUSE_DRAG_AND_DROP
531 if ( m_dropTarget
!= NULL
)
536 #endif // wxUSE_DRAG_AND_DROP
541 void wxWindowMac::MacInstallEventHandler()
543 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
544 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
545 GetEventTypeCount(eventList
), eventList
, this,
546 (EventHandlerRef
*)&m_macControlEventHandler
);
551 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
555 const wxString
& name
)
557 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
559 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
562 parent
->AddChild(this);
564 m_windowVariant
= parent
->GetWindowVariant() ;
566 if ( m_macIsUserPane
)
568 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
570 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
571 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
573 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
575 MacPostControlCreate(pos
,size
) ;
576 #if !TARGET_API_MAC_OSX
577 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
578 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
579 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
580 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
581 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
582 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
583 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
584 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
585 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
586 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
587 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
588 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
589 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
590 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
591 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
592 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
595 #ifndef __WXUNIVERSAL__
596 // Don't give scrollbars to wxControls unless they ask for them
597 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
598 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
600 MacCreateScrollBars( style
) ;
604 wxWindowCreateEvent
event(this);
605 GetEventHandler()->AddPendingEvent(event
);
610 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
612 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
614 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
616 MacInstallEventHandler();
618 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
619 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
620 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
622 // adjust font, controlsize etc
623 DoSetWindowVariant( m_windowVariant
) ;
625 #if !TARGET_API_MAC_OSX
626 // eventually we can fix some clipping issues be reactivating this hook
627 //if ( m_macIsUserPane )
628 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
631 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
633 wxSize new_size
= size
;
634 if (!m_macIsUserPane
)
636 wxSize
best_size( DoGetBestSize() );
639 new_size
.x
= best_size
.x
;
642 new_size
.y
= best_size
.y
;
644 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
647 SetCursor( *wxSTANDARD_CURSOR
) ;
651 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
653 wxASSERT( m_macControl
!= NULL
) ;
655 m_windowVariant
= variant
;
658 ThemeFontID themeFont
= kThemeSystemFont
;
660 // we will get that from the settings later
661 // and make this NORMAL later, but first
662 // we have a few calculations that we must fix
666 case wxWINDOW_VARIANT_NORMAL
:
667 size
= kControlSizeNormal
;
668 themeFont
= kThemeSystemFont
;
670 case wxWINDOW_VARIANT_SMALL
:
671 size
= kControlSizeSmall
;
672 themeFont
= kThemeSmallSystemFont
;
674 case wxWINDOW_VARIANT_MINI
:
675 if (UMAGetSystemVersion() >= 0x1030 )
677 // not always defined in the headers
683 size
= kControlSizeSmall
;
684 themeFont
= kThemeSmallSystemFont
;
687 case wxWINDOW_VARIANT_LARGE
:
688 size
= kControlSizeLarge
;
689 themeFont
= kThemeSystemFont
;
692 wxFAIL_MSG(_T("unexpected window variant"));
695 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
698 font
.MacCreateThemeFont( themeFont
) ;
702 void wxWindowMac::MacUpdateControlFont()
704 ControlFontStyleRec fontStyle
;
705 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
707 switch( m_font
.MacGetThemeFontID() )
709 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
710 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
711 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
712 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
714 fontStyle
.flags
= kControlUseFontMask
;
718 fontStyle
.font
= m_font
.MacGetFontNum() ;
719 fontStyle
.style
= m_font
.MacGetFontStyle() ;
720 fontStyle
.size
= m_font
.MacGetFontSize() ;
721 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
724 fontStyle
.just
= teJustLeft
;
725 fontStyle
.flags
|= kControlUseJustMask
;
726 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
727 fontStyle
.just
= teJustCenter
;
728 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
729 fontStyle
.just
= teJustRight
;
732 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
733 fontStyle
.flags
|= kControlUseForeColorMask
;
735 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
739 bool wxWindowMac::SetFont(const wxFont
& font
)
741 bool retval
= !wxWindowBase::SetFont( font
) ;
743 MacUpdateControlFont() ;
748 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
750 if ( !wxWindowBase::SetForegroundColour(col
) )
753 MacUpdateControlFont() ;
758 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
760 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
764 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
766 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
768 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
770 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
774 brush
.SetColour( col
) ;
776 MacSetBackgroundBrush( brush
) ;
778 MacUpdateControlFont() ;
784 bool wxWindowMac::MacCanFocus() const
786 wxASSERT( m_macControl
!= NULL
) ;
792 void wxWindowMac::SetFocus()
794 if ( gFocusWindow
== this )
797 if ( AcceptsFocus() )
803 if ( gFocusWindow
->m_caret
)
805 gFocusWindow
->m_caret
->OnKillFocus();
807 #endif // wxUSE_CARET
808 #ifndef __WXUNIVERSAL__
809 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
810 // TODO we must use the built-in focusing
811 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
813 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
814 control
->MacRedrawControl() ;
817 // Without testing the window id, for some reason
818 // a kill focus event can still be sent to
819 // the control just being focussed.
820 int thisId
= this->m_windowId
;
821 int gFocusWindowId
= gFocusWindow
->m_windowId
;
822 if (gFocusWindowId
!= thisId
)
824 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
825 event
.SetEventObject(gFocusWindow
);
826 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
829 gFocusWindow
= this ;
835 m_caret
->OnSetFocus();
837 #endif // wxUSE_CARET
838 // panel wants to track the window which was the last to have focus in it
839 wxChildFocusEvent
eventFocus(this);
840 GetEventHandler()->ProcessEvent(eventFocus
);
842 #ifndef __WXUNIVERSAL__
843 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
844 if ( control
&& control
->GetHandle() )
846 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
849 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
850 event
.SetEventObject(this);
851 GetEventHandler()->ProcessEvent(event
) ;
857 void wxWindowMac::DoCaptureMouse()
859 wxTheApp
->s_captureWindow
= this ;
862 wxWindow
* wxWindowBase::GetCapture()
864 return wxTheApp
->s_captureWindow
;
867 void wxWindowMac::DoReleaseMouse()
869 wxTheApp
->s_captureWindow
= NULL
;
872 #if wxUSE_DRAG_AND_DROP
874 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
876 if ( m_dropTarget
!= 0 ) {
880 m_dropTarget
= pDropTarget
;
881 if ( m_dropTarget
!= 0 )
889 // Old style file-manager drag&drop
890 void wxWindowMac::DragAcceptFiles(bool accept
)
895 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
896 int& w
, int& h
) const
899 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
904 w
= bounds
.right
- bounds
.left
;
905 h
= bounds
.bottom
- bounds
.top
;
907 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
910 Point tlworigin
= { 0 , 0 } ;
912 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
913 ::LocalToGlobal( &tlworigin
) ;
921 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
924 int& w
, int& h
, bool adjustOrigin
) const
928 // todo the default calls may be used as soon as PostCreateControl Is moved here
929 w
= size
.x
; // WidthDefault( size.x );
930 h
= size
.y
; // HeightDefault( size.y ) ;
931 #if !TARGET_API_MAC_OSX
932 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
935 AdjustForParentClientOrigin( x
, y
) ;
940 void wxWindowMac::DoGetSize(int *x
, int *y
) const
942 #if TARGET_API_MAC_OSX
943 int x1
, y1
, w1
,h1
;
944 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
950 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
951 if(x
) *x
= bounds
.right
- bounds
.left
;
952 if(y
) *y
= bounds
.bottom
- bounds
.top
;
956 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
958 #if TARGET_API_MAC_OSX
959 int x1
, y1
, w1
,h1
;
960 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
963 wxWindow
*parent
= GetParent();
966 wxPoint
pt(parent
->GetClientAreaOrigin());
975 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
976 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
978 int xx
= bounds
.left
;
979 int yy
= bounds
.top
;
981 if ( !GetParent()->IsTopLevel() )
983 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
989 wxPoint
pt(GetParent()->GetClientAreaOrigin());
998 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1000 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1002 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1005 Point localwhere
= {0,0} ;
1007 if(x
) localwhere
.h
= * x
;
1008 if(y
) localwhere
.v
= * y
;
1010 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1011 ::GlobalToLocal( &localwhere
) ;
1012 if(x
) *x
= localwhere
.h
;
1013 if(y
) *y
= localwhere
.v
;
1016 MacRootWindowToWindow( x
, y
) ;
1018 wxPoint origin
= GetClientAreaOrigin() ;
1019 if(x
) *x
-= origin
.x
;
1020 if(y
) *y
-= origin
.y
;
1023 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1025 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1026 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1028 wxPoint origin
= GetClientAreaOrigin() ;
1029 if(x
) *x
+= origin
.x
;
1030 if(y
) *y
+= origin
.y
;
1032 MacWindowToRootWindow( x
, y
) ;
1035 Point localwhere
= { 0,0 };
1036 if(x
) localwhere
.h
= * x
;
1037 if(y
) localwhere
.v
= * y
;
1039 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1040 ::LocalToGlobal( &localwhere
) ;
1041 if(x
) *x
= localwhere
.h
;
1042 if(y
) *y
= localwhere
.v
;
1046 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1048 wxPoint origin
= GetClientAreaOrigin() ;
1049 if(x
) *x
+= origin
.x
;
1050 if(y
) *y
+= origin
.y
;
1052 MacWindowToRootWindow( x
, y
) ;
1055 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1057 MacRootWindowToWindow( x
, y
) ;
1059 wxPoint origin
= GetClientAreaOrigin() ;
1060 if(x
) *x
-= origin
.x
;
1061 if(y
) *y
-= origin
.y
;
1064 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1066 #if TARGET_API_MAC_OSX
1068 if ( x
) pt
.x
= *x
;
1069 if ( y
) pt
.y
= *y
;
1071 if ( !IsTopLevel() )
1072 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1074 if ( x
) *x
= (int) pt
.x
;
1075 if ( y
) *y
= (int) pt
.y
;
1077 if ( !IsTopLevel() )
1080 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1081 if(x
) *x
+= bounds
.left
;
1082 if(y
) *y
+= bounds
.top
;
1087 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1092 MacWindowToRootWindow( &x1
, &y1
) ;
1097 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1099 #if TARGET_API_MAC_OSX
1101 if ( x
) pt
.x
= *x
;
1102 if ( y
) pt
.y
= *y
;
1104 if ( !IsTopLevel() )
1105 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1107 if ( x
) *x
= (int) pt
.x
;
1108 if ( y
) *y
= (int) pt
.y
;
1110 if ( !IsTopLevel() )
1113 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1114 if(x
) *x
-= bounds
.left
;
1115 if(y
) *y
-= bounds
.top
;
1120 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1125 MacRootWindowToWindow( &x1
, &y1
) ;
1130 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1132 wxSize sizeTotal
= size
;
1134 RgnHandle rgn
= NewRgn() ;
1138 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1140 GetRegionBounds( rgn
, &content
) ;
1145 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1148 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1149 #if !TARGET_API_MAC_OSX
1150 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1153 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1154 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1156 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1157 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1163 // Get size *available for subwindows* i.e. excluding menu bar etc.
1164 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1168 RgnHandle rgn
= NewRgn() ;
1170 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1172 GetRegionBounds( rgn
, &content
) ;
1177 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1179 #if !TARGET_API_MAC_OSX
1181 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1182 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1184 ww
= content
.right
- content
.left
;
1185 hh
= content
.bottom
- content
.top
;
1187 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1188 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1190 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1196 GetSize( &w
, &h
) ;
1198 MacClientToRootWindow( &x1
, &y1
) ;
1199 MacClientToRootWindow( &w
, &h
) ;
1201 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1203 int totW
= 10000 , totH
= 10000;
1206 if ( iter
->IsTopLevel() )
1208 iter
->GetSize( &totW
, &totH
) ;
1212 iter
= iter
->GetParent() ;
1215 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1217 hh
-= MAC_SCROLLBAR_SIZE
;
1223 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1225 ww
-= MAC_SCROLLBAR_SIZE
;
1237 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1239 if (m_cursor
== cursor
)
1242 if (wxNullCursor
== cursor
)
1244 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1249 if ( ! wxWindowBase::SetCursor( cursor
) )
1253 wxASSERT_MSG( m_cursor
.Ok(),
1254 wxT("cursor must be valid after call to the base version"));
1258 TODO why do we have to use current coordinates ?
1261 wxWindowMac *mouseWin ;
1264 // Change the cursor NOW if we're within the correct window
1267 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1269 if ( mouseWin == this && !wxIsBusy() )
1271 m_cursor.MacInstall() ;
1277 m_cursor
.MacInstall() ;
1284 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1286 menu
->SetInvokingWindow(this);
1288 ClientToScreen( &x
, &y
) ;
1290 menu
->MacBeforeDisplay( true ) ;
1291 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1292 if ( HiWord(menuResult
) != 0 )
1295 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1296 wxMenuItem
* item
= NULL
;
1298 item
= menu
->FindItem(id
, &realmenu
) ;
1299 if (item
->IsCheckable())
1301 item
->Check( !item
->IsChecked() ) ;
1303 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1305 menu
->MacAfterDisplay( true ) ;
1307 menu
->SetInvokingWindow(NULL
);
1313 // ----------------------------------------------------------------------------
1315 // ----------------------------------------------------------------------------
1319 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1321 wxWindowBase::DoSetToolTip(tooltip
);
1324 m_tooltip
->SetWindow(this);
1327 #endif // wxUSE_TOOLTIPS
1329 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1331 int former_x
, former_y
, former_w
, former_h
;
1332 #if !TARGET_API_MAC_OSX
1333 DoGetPosition( &former_x
, &former_y
) ;
1334 DoGetSize( &former_w
, &former_h
) ;
1336 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1339 int actualWidth
= width
;
1340 int actualHeight
= height
;
1344 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1345 actualWidth
= m_minWidth
;
1346 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1347 actualHeight
= m_minHeight
;
1348 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1349 actualWidth
= m_maxWidth
;
1350 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1351 actualHeight
= m_maxHeight
;
1353 bool doMove
= false ;
1354 bool doResize
= false ;
1356 if ( actualX
!= former_x
|| actualY
!= former_y
)
1360 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1365 if ( doMove
|| doResize
)
1367 // we don't adjust twice for the origin
1368 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1369 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1370 #if TARGET_API_MAC_OSX
1371 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1373 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1374 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1375 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1377 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1379 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1381 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1383 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1385 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1387 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1389 MacRepositionScrollBars() ;
1392 wxPoint
point(actualX
,actualY
);
1393 wxMoveEvent
event(point
, m_windowId
);
1394 event
.SetEventObject(this);
1395 GetEventHandler()->ProcessEvent(event
) ;
1399 MacRepositionScrollBars() ;
1400 wxSize
size(actualWidth
, actualHeight
);
1401 wxSizeEvent
event(size
, m_windowId
);
1402 event
.SetEventObject(this);
1403 GetEventHandler()->ProcessEvent(event
);
1409 wxSize
wxWindowMac::DoGetBestSize() const
1411 if ( m_macIsUserPane
|| IsTopLevel() )
1412 return wxWindowBase::DoGetBestSize() ;
1414 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1415 short baselineoffset
;
1416 int bestWidth
, bestHeight
;
1417 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1419 if ( EmptyRect( &bestsize
) )
1422 bestsize
.left
= bestsize
.top
= 0 ;
1423 bestsize
.right
= 16 ;
1424 bestsize
.bottom
= 16 ;
1425 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1427 bestsize
.bottom
= 16 ;
1429 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1431 bestsize
.bottom
= 24 ;
1435 // return wxWindowBase::DoGetBestSize() ;
1439 bestWidth
= bestsize
.right
- bestsize
.left
;
1440 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1441 if ( bestHeight
< 10 )
1444 return wxSize(bestWidth
, bestHeight
);
1445 // return wxWindowBase::DoGetBestSize() ;
1449 // set the size of the window: if the dimensions are positive, just use them,
1450 // but if any of them is equal to -1, it means that we must find the value for
1451 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1452 // which case -1 is a valid value for x and y)
1454 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1455 // the width/height to best suit our contents, otherwise we reuse the current
1457 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1459 // get the current size and position...
1460 int currentX
, currentY
;
1461 GetPosition(¤tX
, ¤tY
);
1463 int currentW
,currentH
;
1464 GetSize(¤tW
, ¤tH
);
1466 // ... and don't do anything (avoiding flicker) if it's already ok
1467 if ( x
== currentX
&& y
== currentY
&&
1468 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1471 MacRepositionScrollBars() ; // we might have a real position shift
1475 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1477 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1480 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1482 wxSize
size(-1, -1);
1485 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1487 size
= DoGetBestSize();
1492 // just take the current one
1499 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1503 size
= DoGetBestSize();
1505 //else: already called DoGetBestSize() above
1511 // just take the current one
1516 DoMoveWindow(x
, y
, width
, height
);
1520 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1522 RgnHandle rgn
= NewRgn() ;
1524 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1525 GetRegionBounds( rgn
, &content
) ;
1527 #if !TARGET_API_MAC_OSX
1529 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1530 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1533 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1536 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1538 if ( clientheight
!= -1 || clientheight
!= -1 )
1540 int currentclientwidth
, currentclientheight
;
1541 int currentwidth
, currentheight
;
1543 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1544 GetSize( ¤twidth
, ¤theight
) ;
1546 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1547 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1551 void wxWindowMac::SetTitle(const wxString
& title
)
1553 m_label
= wxStripMenuCodes(title
) ;
1557 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1562 wxString
wxWindowMac::GetTitle() const
1567 bool wxWindowMac::Show(bool show
)
1569 if ( !wxWindowBase::Show(show
) )
1572 // TODO use visibilityChanged Carbon Event for OSX
1573 bool former
= MacIsReallyShown() ;
1575 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1576 if ( former
!= MacIsReallyShown() )
1577 MacPropagateVisibilityChanged() ;
1581 bool wxWindowMac::Enable(bool enable
)
1583 wxASSERT( m_macControl
!= NULL
) ;
1584 if ( !wxWindowBase::Enable(enable
) )
1587 bool former
= MacIsReallyEnabled() ;
1589 EnableControl( (ControlRef
) m_macControl
) ;
1591 DisableControl( (ControlRef
) m_macControl
) ;
1593 if ( former
!= MacIsReallyEnabled() )
1594 MacPropagateEnabledStateChanged() ;
1599 // status change propagations (will be not necessary for OSX later )
1602 void wxWindowMac::MacPropagateVisibilityChanged()
1604 #if !TARGET_API_MAC_OSX
1605 MacVisibilityChanged() ;
1607 wxWindowListNode
*node
= GetChildren().GetFirst();
1610 wxWindowMac
*child
= node
->GetData();
1611 if ( child
->IsShown() )
1612 child
->MacPropagateVisibilityChanged( ) ;
1613 node
= node
->GetNext();
1618 void wxWindowMac::MacPropagateEnabledStateChanged( )
1620 #if !TARGET_API_MAC_OSX
1621 MacEnabledStateChanged() ;
1623 wxWindowListNode
*node
= GetChildren().GetFirst();
1626 wxWindowMac
*child
= node
->GetData();
1627 if ( child
->IsEnabled() )
1628 child
->MacPropagateEnabledStateChanged() ;
1629 node
= node
->GetNext();
1634 void wxWindowMac::MacPropagateHiliteChanged( )
1636 #if !TARGET_API_MAC_OSX
1637 MacHiliteChanged() ;
1639 wxWindowListNode
*node
= GetChildren().GetFirst();
1642 wxWindowMac
*child
= node
->GetData();
1643 // if ( child->IsEnabled() )
1644 child
->MacPropagateHiliteChanged() ;
1645 node
= node
->GetNext();
1651 // status change notifications
1654 void wxWindowMac::MacVisibilityChanged()
1658 void wxWindowMac::MacHiliteChanged()
1662 void wxWindowMac::MacEnabledStateChanged()
1667 // status queries on the inherited window's state
1670 bool wxWindowMac::MacIsReallyShown()
1672 // only under OSX the visibility of the TLW is taken into account
1673 #if TARGET_API_MAC_OSX
1674 return IsControlVisible( (ControlRef
) m_macControl
) ;
1676 wxWindow
* win
= this ;
1677 while( win
->IsShown() )
1679 if ( win
->IsTopLevel() )
1682 win
= win
->GetParent() ;
1691 bool wxWindowMac::MacIsReallyEnabled()
1693 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1696 bool wxWindowMac::MacIsReallyHilited()
1698 return IsControlActive( (ControlRef
) m_macControl
) ;
1705 int wxWindowMac::GetCharHeight() const
1707 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1708 return dc
.GetCharHeight() ;
1711 int wxWindowMac::GetCharWidth() const
1713 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1714 return dc
.GetCharWidth() ;
1717 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1718 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1720 const wxFont
*fontToUse
= theFont
;
1722 fontToUse
= &m_font
;
1724 wxClientDC
dc( (wxWindowMac
*) this ) ;
1726 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1727 if ( externalLeading
)
1728 *externalLeading
= le
;
1738 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1739 * we always intersect with the entire window, not only with the client area
1742 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1744 #if TARGET_API_MAC_OSX
1746 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1749 RgnHandle update
= NewRgn() ;
1750 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1751 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1752 wxPoint origin
= GetClientAreaOrigin() ;
1753 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1754 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1758 RgnHandle updateRgn = NewRgn() ;
1761 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1765 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1766 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1768 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1769 DisposeRgn(updateRgn) ;
1771 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1773 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1774 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1777 if ( MacGetTopLevelWindow() == NULL )
1780 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1783 wxPoint client = GetClientAreaOrigin();
1786 int x2 = m_width - client.x;
1787 int y2 = m_height - client.y;
1789 if (IsKindOf( CLASSINFO(wxButton)))
1791 // buttons have an "aura"
1798 Rect clientrect = { y1, x1, y2, x2 };
1802 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1803 SectRect( &clientrect , &r , &clientrect ) ;
1806 if ( !EmptyRect( &clientrect ) )
1808 int top = 0 , left = 0 ;
1810 MacClientToRootWindow( &left , &top ) ;
1811 OffsetRect( &clientrect , left , top ) ;
1813 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1819 void wxWindowMac::Freeze()
1821 #if TARGET_API_MAC_OSX
1822 if ( !m_frozenness
++ )
1824 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1829 void wxWindowMac::Thaw()
1831 #if TARGET_API_MAC_OSX
1832 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1834 if ( !--m_frozenness
)
1836 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
1837 HIViewSetNeedsDisplay( (HIViewRef
) m_macControl
, true ) ;
1842 void wxWindowMac::MacRedrawControl()
1845 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1847 #if TARGET_API_MAC_CARBON
1850 wxClientDC dc(this) ;
1851 wxMacPortSetter helper(&dc) ;
1852 wxMacWindowClipper clipper(this) ;
1853 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1854 UMADrawControl( (ControlRef) m_macControl ) ;
1861 void wxWindowMac::OnPaint(wxPaintEvent& event)
1863 // why don't we skip that here ?
1867 wxWindowMac
*wxGetActiveWindow()
1869 // actually this is a windows-only concept
1873 // Coordinates relative to the window
1874 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1876 // We really don't move the mouse programmatically under Mac.
1879 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1881 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1886 event
.GetDC()->Clear() ;
1889 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1891 wxWindowDC
dc(this) ;
1892 wxMacPortSetter
helper(&dc
) ;
1894 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1897 int wxWindowMac::GetScrollPos(int orient
) const
1899 if ( orient
== wxHORIZONTAL
)
1902 return m_hScrollBar
->GetThumbPosition() ;
1907 return m_vScrollBar
->GetThumbPosition() ;
1912 // This now returns the whole range, not just the number
1913 // of positions that we can scroll.
1914 int wxWindowMac::GetScrollRange(int orient
) const
1916 if ( orient
== wxHORIZONTAL
)
1919 return m_hScrollBar
->GetRange() ;
1924 return m_vScrollBar
->GetRange() ;
1929 int wxWindowMac::GetScrollThumb(int orient
) const
1931 if ( orient
== wxHORIZONTAL
)
1934 return m_hScrollBar
->GetThumbSize() ;
1939 return m_vScrollBar
->GetThumbSize() ;
1944 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1946 if ( orient
== wxHORIZONTAL
)
1949 m_hScrollBar
->SetThumbPosition( pos
) ;
1954 m_vScrollBar
->SetThumbPosition( pos
) ;
1958 void wxWindowMac::MacPaintBorders( int left
, int top
)
1964 wxGetOsVersion( &major
, &minor
);
1966 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1967 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1969 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1970 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1971 // OS X has lighter border edges than classic:
1974 darkShadow
.red
= 0x8E8E;
1975 darkShadow
.green
= 0x8E8E;
1976 darkShadow
.blue
= 0x8E8E;
1977 lightShadow
.red
= 0xBDBD;
1978 lightShadow
.green
= 0xBDBD;
1979 lightShadow
.blue
= 0xBDBD;
1985 GetSize( &w
, &h
) ;
1986 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1988 #if wxMAC_USE_THEME_BORDER
1989 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1992 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1993 InsetRect( &rect , border , border );
1994 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1997 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1999 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2000 RGBForeColor( &face
);
2001 MoveTo( left
+ 0 , top
+ h
- 2 );
2002 LineTo( left
+ 0 , top
+ 0 );
2003 LineTo( left
+ w
- 2 , top
+ 0 );
2005 MoveTo( left
+ 2 , top
+ h
- 3 );
2006 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2007 LineTo( left
+ w
- 3 , top
+ 2 );
2009 RGBForeColor( sunken
? &face
: &darkShadow
);
2010 MoveTo( left
+ 0 , top
+ h
- 1 );
2011 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2012 LineTo( left
+ w
- 1 , top
+ 0 );
2014 RGBForeColor( sunken
? &lightShadow
: &white
);
2015 MoveTo( left
+ 1 , top
+ h
- 3 );
2016 LineTo( left
+ 1, top
+ 1 );
2017 LineTo( left
+ w
- 3 , top
+ 1 );
2019 RGBForeColor( sunken
? &white
: &lightShadow
);
2020 MoveTo( left
+ 1 , top
+ h
- 2 );
2021 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2022 LineTo( left
+ w
- 2 , top
+ 1 );
2024 RGBForeColor( sunken
? &darkShadow
: &face
);
2025 MoveTo( left
+ 2 , top
+ h
- 4 );
2026 LineTo( left
+ 2 , top
+ 2 );
2027 LineTo( left
+ w
- 4 , top
+ 2 );
2030 else if (HasFlag(wxSIMPLE_BORDER
))
2032 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2033 RGBForeColor( &darkShadow
) ;
2034 FrameRect( &rect
) ;
2038 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2040 if ( child
== m_hScrollBar
)
2041 m_hScrollBar
= NULL
;
2042 if ( child
== m_vScrollBar
)
2043 m_vScrollBar
= NULL
;
2045 wxWindowBase::RemoveChild( child
) ;
2048 // New function that will replace some of the above.
2049 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2050 int range
, bool refresh
)
2052 if ( orient
== wxHORIZONTAL
)
2056 if ( range
== 0 || thumbVisible
>= range
)
2058 if ( m_hScrollBar
->IsShown() )
2059 m_hScrollBar
->Show(false) ;
2063 if ( !m_hScrollBar
->IsShown() )
2064 m_hScrollBar
->Show(true) ;
2065 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2073 if ( range
== 0 || thumbVisible
>= range
)
2075 if ( m_vScrollBar
->IsShown() )
2076 m_vScrollBar
->Show(false) ;
2080 if ( !m_vScrollBar
->IsShown() )
2081 m_vScrollBar
->Show(true) ;
2082 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2086 MacRepositionScrollBars() ;
2089 // Does a physical scroll
2090 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2092 if( dx
== 0 && dy
==0 )
2097 wxClientDC
dc(this) ;
2098 wxMacPortSetter
helper(&dc
) ;
2100 int width
, height
;
2101 GetClientSize( &width
, &height
) ;
2108 // TODO take out the boundaries
2109 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2111 RgnHandle updateRgn
= NewRgn() ;
2114 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2115 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2116 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2118 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2120 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2121 // but it seems the update only refreshes the background of the control, rather than calling
2122 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2123 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2126 // we also have to scroll the update rgn in this rectangle
2127 // in order not to loose updates
2129 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2130 RgnHandle formerUpdateRgn
= NewRgn() ;
2131 RgnHandle scrollRgn
= NewRgn() ;
2132 RectRgn( scrollRgn
, &scrollrect
) ;
2133 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2135 LocalToGlobal( &pt
) ;
2136 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2137 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2138 if ( !EmptyRgn( formerUpdateRgn
) )
2140 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2141 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2142 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2144 InvalWindowRgn(rootWindow
, updateRgn
) ;
2145 DisposeRgn( updateRgn
) ;
2146 DisposeRgn( formerUpdateRgn
) ;
2147 DisposeRgn( scrollRgn
) ;
2151 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2153 wxWindowMac
*child
= node
->GetData();
2154 if (child
== m_vScrollBar
) continue;
2155 if (child
== m_hScrollBar
) continue;
2156 if (child
->IsTopLevel()) continue;
2159 child
->GetPosition( &x
, &y
);
2161 child
->GetSize( &w
, &h
);
2165 if (rect
->Intersects(rc
))
2166 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2170 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2174 // TODO remove, was moved higher up Update() ;
2178 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2180 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2182 wxScrollWinEvent wevent
;
2183 wevent
.SetPosition(event
.GetPosition());
2184 wevent
.SetOrientation(event
.GetOrientation());
2185 wevent
.m_eventObject
= this;
2187 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2188 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2189 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2190 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2191 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2192 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2193 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2194 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2195 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2196 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2197 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2198 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2199 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2200 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2201 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2202 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2204 GetEventHandler()->ProcessEvent(wevent
);
2208 // Get the window with the focus
2209 wxWindowMac
*wxWindowBase::FindFocus()
2211 return gFocusWindow
;
2214 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2216 // panel wants to track the window which was the last to have focus in it,
2217 // so we want to set ourselves as the window which last had focus
2219 // notice that it's also important to do it upwards the tree becaus
2220 // otherwise when the top level panel gets focus, it won't set it back to
2221 // us, but to some other sibling
2223 // CS:don't know if this is still needed:
2224 //wxChildFocusEvent eventFocus(this);
2225 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2230 void wxWindowMac::OnInternalIdle()
2232 // This calls the UI-update mechanism (querying windows for
2233 // menu/toolbar/control state information)
2234 if (wxUpdateUIEvent::CanUpdate(this))
2235 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2238 // Raise the window to the top of the Z order
2239 void wxWindowMac::Raise()
2243 // Lower the window to the bottom of the Z order
2244 void wxWindowMac::Lower()
2249 // static wxWindow *gs_lastWhich = NULL;
2251 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2253 // first trigger a set cursor event
2255 wxPoint clientorigin
= GetClientAreaOrigin() ;
2256 wxSize clientsize
= GetClientSize() ;
2258 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2260 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2262 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2263 if ( processedEvtSetCursor
&& event
.HasCursor() )
2265 cursor
= event
.GetCursor() ;
2270 // the test for processedEvtSetCursor is here to prevent using m_cursor
2271 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2272 // it - this is a way to say that our cursor shouldn't be used for this
2274 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2284 cursor
= *wxSTANDARD_CURSOR
;
2288 cursor
.MacInstall() ;
2290 return cursor
.Ok() ;
2293 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2297 return m_tooltip
->GetTip() ;
2299 return wxEmptyString
;
2302 void wxWindowMac::Update()
2304 #if TARGET_API_MAC_OSX
2305 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2307 ::Draw1Control( (ControlRef
) m_macControl
) ;
2311 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2313 wxTopLevelWindowMac
* win
= NULL
;
2314 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2317 win
= wxFindWinFromMacWindow( window
) ;
2321 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2325 RgnHandle visRgn
= NewRgn() ;
2326 RgnHandle tempRgn
= NewRgn() ;
2327 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2329 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2330 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2332 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2333 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2342 if ( includeOuterStructures
)
2343 InsetRect( &r
, -3 , -3 ) ;
2344 RectRgn( visRgn
, &r
) ;
2345 if ( !IsTopLevel() )
2347 wxWindow
* child
= this ;
2348 wxWindow
* parent
= child
->GetParent() ;
2353 // we have to find a better clipping algorithm here, in order not to clip things
2354 // positioned like status and toolbar
2355 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2357 size
= parent
->GetSize() ;
2362 size
= parent
->GetClientSize() ;
2363 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2367 parent
->MacWindowToRootWindow( &x
, &y
) ;
2368 MacRootWindowToWindow( &x
, &y
) ;
2370 SetRectRgn( tempRgn
,
2371 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2372 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2373 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2375 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2376 if ( parent
->IsTopLevel() )
2379 parent
= child
->GetParent() ;
2384 wxRegion vis
= visRgn
;
2385 DisposeRgn( visRgn
) ;
2386 DisposeRgn( tempRgn
) ;
2391 This function must not change the updatergn !
2393 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2395 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2396 bool handled
= false ;
2398 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2400 RgnHandle newupdate
= NewRgn() ;
2401 wxSize point
= GetClientSize() ;
2402 wxPoint origin
= GetClientAreaOrigin() ;
2403 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2404 SectRgn( newupdate
, updatergn
, newupdate
) ;
2405 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2406 m_updateRegion
= newupdate
;
2407 DisposeRgn( newupdate
) ;
2410 if ( !EmptyRgn(updatergn
) )
2412 wxWindowDC
dc(this);
2413 if (!EmptyRgn(updatergn
))
2414 dc
.SetClippingRegion(wxRegion(updatergn
));
2416 wxEraseEvent
eevent( GetId(), &dc
);
2417 eevent
.SetEventObject( this );
2418 GetEventHandler()->ProcessEvent( eevent
);
2420 if ( !m_updateRegion
.Empty() )
2422 // paint the window itself
2424 event
.m_timeStamp
= time
;
2425 event
.SetEventObject(this);
2426 handled
= GetEventHandler()->ProcessEvent(event
);
2428 // paint custom borders
2429 wxNcPaintEvent
eventNc( GetId() );
2430 eventNc
.SetEventObject( this );
2431 GetEventHandler()->ProcessEvent( eventNc
);
2437 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2439 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2440 // updatergn is always already clipped to our boundaries
2441 // if we are in compositing mode then it is in relative to the upper left of the control
2442 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2443 // of the toplevel window
2444 // it is in window coordinates, not in client coordinates
2446 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2447 RgnHandle ownUpdateRgn
= NewRgn() ;
2448 CopyRgn( updatergn
, ownUpdateRgn
) ;
2450 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2453 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2454 RgnHandle controlRgn
= NewRgn();
2455 RectRgn( controlRgn
, &bounds
);
2456 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2457 // the window update region
2458 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2459 DisposeRgn( controlRgn
);
2461 //KO: convert ownUpdateRgn to local coordinates
2462 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2465 MacDoRedraw( ownUpdateRgn
, time
) ;
2466 DisposeRgn( ownUpdateRgn
) ;
2470 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2472 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2476 if ( iter
->IsTopLevel() )
2477 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2479 iter
= iter
->GetParent() ;
2481 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2485 void wxWindowMac::MacCreateScrollBars( long style
)
2487 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2489 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2490 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2492 GetClientSize( &width
, &height
) ;
2494 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2495 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2496 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2497 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2499 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2500 vSize
, wxVERTICAL
);
2502 if ( style
& wxVSCROLL
)
2508 m_vScrollBar
->Show(false) ;
2510 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2511 hSize
, wxHORIZONTAL
);
2512 if ( style
& wxHSCROLL
)
2517 m_hScrollBar
->Show(false) ;
2520 // because the create does not take into account the client area origin
2521 MacRepositionScrollBars() ; // we might have a real position shift
2524 void wxWindowMac::MacRepositionScrollBars()
2526 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2527 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2529 // get real client area
2533 GetSize( &width
, &height
) ;
2535 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2536 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2538 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2539 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2540 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2541 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2547 GetSize( &w
, &h
) ;
2549 MacClientToRootWindow( &x
, &y
) ;
2550 MacClientToRootWindow( &w
, &h
) ;
2552 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2554 int totW
= 10000 , totH
= 10000;
2557 if ( iter
->IsTopLevel() )
2559 iter
->GetSize( &totW
, &totH
) ;
2563 iter
= iter
->GetParent() ;
2591 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2595 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2599 bool wxWindowMac::AcceptsFocus() const
2601 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2604 void wxWindowMac::MacSuperChangedPosition()
2606 // only window-absolute structures have to be moved i.e. controls
2608 wxWindowListNode
*node
= GetChildren().GetFirst();
2611 wxWindowMac
*child
= node
->GetData();
2612 child
->MacSuperChangedPosition() ;
2613 node
= node
->GetNext();
2617 void wxWindowMac::MacTopLevelWindowChangedPosition()
2619 // only screen-absolute structures have to be moved i.e. glcanvas
2621 wxWindowListNode
*node
= GetChildren().GetFirst();
2624 wxWindowMac
*child
= node
->GetData();
2625 child
->MacTopLevelWindowChangedPosition() ;
2626 node
= node
->GetNext();
2630 long wxWindowMac::MacGetLeftBorderSize( ) const
2635 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2638 #if wxMAC_USE_THEME_BORDER
2639 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2643 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2646 #if wxMAC_USE_THEME_BORDER
2647 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2651 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2658 long wxWindowMac::MacGetRightBorderSize( ) const
2660 // they are all symmetric in mac themes
2661 return MacGetLeftBorderSize() ;
2664 long wxWindowMac::MacGetTopBorderSize( ) const
2666 // they are all symmetric in mac themes
2667 return MacGetLeftBorderSize() ;
2670 long wxWindowMac::MacGetBottomBorderSize( ) const
2672 // they are all symmetric in mac themes
2673 return MacGetLeftBorderSize() ;
2676 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2678 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2681 // Find the wxWindowMac at the current mouse position, returning the mouse
2683 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2685 pt
= wxGetMousePosition();
2686 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2690 // Get the current mouse position.
2691 wxPoint
wxGetMousePosition()
2694 wxGetMousePosition(& x
, & y
);
2695 return wxPoint(x
, y
);
2698 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2700 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2702 // copied from wxGTK : CS
2703 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2706 // (a) it's a command event and so is propagated to the parent
2707 // (b) under MSW it can be generated from kbd too
2708 // (c) it uses screen coords (because of (a))
2709 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2711 this->ClientToScreen(event
.GetPosition()));
2712 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2715 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2721 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2723 // OS Needs it in tlw content area coordinates
2724 MacClientToRootWindow( &x
, &y
) ;
2728 // OS Needs it in window not client coordinates
2729 wxPoint origin
= GetClientAreaOrigin() ;
2734 SInt16 controlpart
;
2739 short modifiers
= 0;
2741 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2742 modifiers
|= btnState
;
2744 if ( event
.m_shiftDown
)
2745 modifiers
|= shiftKey
;
2747 if ( event
.m_controlDown
)
2748 modifiers
|= controlKey
;
2750 if ( event
.m_altDown
)
2751 modifiers
|= optionKey
;
2753 if ( event
.m_metaDown
)
2754 modifiers
|= cmdKey
;
2756 bool handled
= false ;
2758 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2760 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2761 wxTheApp
->s_lastMouseDown
= 0 ;
2762 if ( controlpart
!= kControlNoPart
)
2764 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2777 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2779 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2782 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2786 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2787 Rect bounds
= { y
, x
, y
+h
, x
+w
};