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 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
544 GetEventTypeCount(eventList
), eventList
, this,
545 (EventHandlerRef
*)&m_macControlEventHandler
);
550 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
554 const wxString
& name
)
556 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
558 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
561 parent
->AddChild(this);
563 m_windowVariant
= parent
->GetWindowVariant() ;
565 if ( m_macIsUserPane
)
567 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
569 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
570 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
572 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
574 MacPostControlCreate(pos
,size
) ;
575 #if !TARGET_API_MAC_OSX
576 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
577 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
578 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
579 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
580 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
581 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
582 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
583 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
584 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
585 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
586 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
587 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
588 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
589 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
590 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
591 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
594 #ifndef __WXUNIVERSAL__
595 // Don't give scrollbars to wxControls unless they ask for them
596 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
597 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
599 MacCreateScrollBars( style
) ;
603 wxWindowCreateEvent
event(this);
604 GetEventHandler()->AddPendingEvent(event
);
609 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
611 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
613 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
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 } ;
913 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
914 ::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 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1073 if ( x
) *x
= (int) pt
.x
;
1074 if ( y
) *y
= (int) pt
.y
;
1076 if ( !IsTopLevel() )
1079 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1080 if(x
) *x
+= bounds
.left
;
1081 if(y
) *y
+= bounds
.top
;
1086 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1091 MacWindowToRootWindow( &x1
, &y1
) ;
1096 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1098 #if TARGET_API_MAC_OSX
1100 if ( x
) pt
.x
= *x
;
1101 if ( y
) pt
.y
= *y
;
1103 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1105 if ( x
) *x
= (int) pt
.x
;
1106 if ( y
) *y
= (int) pt
.y
;
1108 if ( !IsTopLevel() )
1111 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1112 if(x
) *x
-= bounds
.left
;
1113 if(y
) *y
-= bounds
.top
;
1118 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1123 MacRootWindowToWindow( &x1
, &y1
) ;
1128 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1130 wxSize sizeTotal
= size
;
1132 RgnHandle rgn
= NewRgn() ;
1136 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1138 GetRegionBounds( rgn
, &content
) ;
1143 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1146 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1147 #if !TARGET_API_MAC_OSX
1148 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1151 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1152 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1154 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1155 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1161 // Get size *available for subwindows* i.e. excluding menu bar etc.
1162 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1166 RgnHandle rgn
= NewRgn() ;
1168 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1170 GetRegionBounds( rgn
, &content
) ;
1175 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1177 #if !TARGET_API_MAC_OSX
1179 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1180 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1182 ww
= content
.right
- content
.left
;
1183 hh
= content
.bottom
- content
.top
;
1185 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1186 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1188 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1194 GetSize( &w
, &h
) ;
1196 MacClientToRootWindow( &x1
, &y1
) ;
1197 MacClientToRootWindow( &w
, &h
) ;
1199 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1201 int totW
= 10000 , totH
= 10000;
1204 if ( iter
->IsTopLevel() )
1206 iter
->GetSize( &totW
, &totH
) ;
1210 iter
= iter
->GetParent() ;
1213 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1215 hh
-= MAC_SCROLLBAR_SIZE
;
1221 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1223 ww
-= MAC_SCROLLBAR_SIZE
;
1235 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1237 if (m_cursor
== cursor
)
1240 if (wxNullCursor
== cursor
)
1242 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1247 if ( ! wxWindowBase::SetCursor( cursor
) )
1251 wxASSERT_MSG( m_cursor
.Ok(),
1252 wxT("cursor must be valid after call to the base version"));
1256 TODO why do we have to use current coordinates ?
1259 wxWindowMac *mouseWin ;
1262 // Change the cursor NOW if we're within the correct window
1265 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1267 if ( mouseWin == this && !wxIsBusy() )
1269 m_cursor.MacInstall() ;
1275 m_cursor
.MacInstall() ;
1282 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1284 menu
->SetInvokingWindow(this);
1286 ClientToScreen( &x
, &y
) ;
1288 menu
->MacBeforeDisplay( true ) ;
1289 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1290 if ( HiWord(menuResult
) != 0 )
1293 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1294 wxMenuItem
* item
= NULL
;
1296 item
= menu
->FindItem(id
, &realmenu
) ;
1297 if (item
->IsCheckable())
1299 item
->Check( !item
->IsChecked() ) ;
1301 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1303 menu
->MacAfterDisplay( true ) ;
1305 menu
->SetInvokingWindow(NULL
);
1311 // ----------------------------------------------------------------------------
1313 // ----------------------------------------------------------------------------
1317 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1319 wxWindowBase::DoSetToolTip(tooltip
);
1322 m_tooltip
->SetWindow(this);
1325 #endif // wxUSE_TOOLTIPS
1327 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1329 int former_x
, former_y
, former_w
, former_h
;
1330 #if !TARGET_API_MAC_OSX
1331 DoGetPosition( &former_x
, &former_y
) ;
1332 DoGetSize( &former_w
, &former_h
) ;
1334 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1337 int actualWidth
= width
;
1338 int actualHeight
= height
;
1342 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1343 actualWidth
= m_minWidth
;
1344 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1345 actualHeight
= m_minHeight
;
1346 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1347 actualWidth
= m_maxWidth
;
1348 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1349 actualHeight
= m_maxHeight
;
1351 bool doMove
= false ;
1352 bool doResize
= false ;
1354 if ( actualX
!= former_x
|| actualY
!= former_y
)
1358 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1363 if ( doMove
|| doResize
)
1365 // we don't adjust twice for the origin
1366 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1367 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1368 #if TARGET_API_MAC_OSX
1369 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1371 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1372 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1373 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1375 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1377 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1379 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1381 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1383 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1385 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1387 MacRepositionScrollBars() ;
1390 wxPoint
point(actualX
,actualY
);
1391 wxMoveEvent
event(point
, m_windowId
);
1392 event
.SetEventObject(this);
1393 GetEventHandler()->ProcessEvent(event
) ;
1397 MacRepositionScrollBars() ;
1398 wxSize
size(actualWidth
, actualHeight
);
1399 wxSizeEvent
event(size
, m_windowId
);
1400 event
.SetEventObject(this);
1401 GetEventHandler()->ProcessEvent(event
);
1407 wxSize
wxWindowMac::DoGetBestSize() const
1409 if ( m_macIsUserPane
|| IsTopLevel() )
1410 return wxWindowBase::DoGetBestSize() ;
1412 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1413 short baselineoffset
;
1414 int bestWidth
, bestHeight
;
1415 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1417 if ( EmptyRect( &bestsize
) )
1420 bestsize
.left
= bestsize
.top
= 0 ;
1421 bestsize
.right
= 16 ;
1422 bestsize
.bottom
= 16 ;
1423 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1425 bestsize
.bottom
= 16 ;
1427 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1429 bestsize
.bottom
= 24 ;
1433 // return wxWindowBase::DoGetBestSize() ;
1437 bestWidth
= bestsize
.right
- bestsize
.left
;
1438 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1439 if ( bestHeight
< 10 )
1442 return wxSize(bestWidth
, bestHeight
);
1443 // return wxWindowBase::DoGetBestSize() ;
1447 // set the size of the window: if the dimensions are positive, just use them,
1448 // but if any of them is equal to -1, it means that we must find the value for
1449 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1450 // which case -1 is a valid value for x and y)
1452 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1453 // the width/height to best suit our contents, otherwise we reuse the current
1455 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1457 // get the current size and position...
1458 int currentX
, currentY
;
1459 GetPosition(¤tX
, ¤tY
);
1461 int currentW
,currentH
;
1462 GetSize(¤tW
, ¤tH
);
1464 // ... and don't do anything (avoiding flicker) if it's already ok
1465 if ( x
== currentX
&& y
== currentY
&&
1466 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1469 MacRepositionScrollBars() ; // we might have a real position shift
1473 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1475 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1478 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1480 wxSize
size(-1, -1);
1483 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1485 size
= DoGetBestSize();
1490 // just take the current one
1497 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1501 size
= DoGetBestSize();
1503 //else: already called DoGetBestSize() above
1509 // just take the current one
1514 DoMoveWindow(x
, y
, width
, height
);
1518 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1520 RgnHandle rgn
= NewRgn() ;
1522 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1523 GetRegionBounds( rgn
, &content
) ;
1525 #if !TARGET_API_MAC_OSX
1527 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1528 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1531 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1534 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1536 if ( clientheight
!= -1 || clientheight
!= -1 )
1538 int currentclientwidth
, currentclientheight
;
1539 int currentwidth
, currentheight
;
1541 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1542 GetSize( ¤twidth
, ¤theight
) ;
1544 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1545 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1549 void wxWindowMac::SetTitle(const wxString
& title
)
1551 m_label
= wxStripMenuCodes(title
) ;
1555 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1560 wxString
wxWindowMac::GetTitle() const
1565 bool wxWindowMac::Show(bool show
)
1567 if ( !wxWindowBase::Show(show
) )
1570 // TODO use visibilityChanged Carbon Event for OSX
1571 bool former
= MacIsReallyShown() ;
1573 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1574 if ( former
!= MacIsReallyShown() )
1575 MacPropagateVisibilityChanged() ;
1579 bool wxWindowMac::Enable(bool enable
)
1581 wxASSERT( m_macControl
!= NULL
) ;
1582 if ( !wxWindowBase::Enable(enable
) )
1585 bool former
= MacIsReallyEnabled() ;
1587 EnableControl( (ControlRef
) m_macControl
) ;
1589 DisableControl( (ControlRef
) m_macControl
) ;
1591 if ( former
!= MacIsReallyEnabled() )
1592 MacPropagateEnabledStateChanged() ;
1597 // status change propagations (will be not necessary for OSX later )
1600 void wxWindowMac::MacPropagateVisibilityChanged()
1602 #if !TARGET_API_MAC_OSX
1603 MacVisibilityChanged() ;
1605 wxWindowListNode
*node
= GetChildren().GetFirst();
1608 wxWindowMac
*child
= node
->GetData();
1609 if ( child
->IsShown() )
1610 child
->MacPropagateVisibilityChanged( ) ;
1611 node
= node
->GetNext();
1616 void wxWindowMac::MacPropagateEnabledStateChanged( )
1618 #if !TARGET_API_MAC_OSX
1619 MacEnabledStateChanged() ;
1621 wxWindowListNode
*node
= GetChildren().GetFirst();
1624 wxWindowMac
*child
= node
->GetData();
1625 if ( child
->IsEnabled() )
1626 child
->MacPropagateEnabledStateChanged() ;
1627 node
= node
->GetNext();
1632 void wxWindowMac::MacPropagateHiliteChanged( )
1634 #if !TARGET_API_MAC_OSX
1635 MacHiliteChanged() ;
1637 wxWindowListNode
*node
= GetChildren().GetFirst();
1640 wxWindowMac
*child
= node
->GetData();
1641 // if ( child->IsEnabled() )
1642 child
->MacPropagateHiliteChanged() ;
1643 node
= node
->GetNext();
1649 // status change notifications
1652 void wxWindowMac::MacVisibilityChanged()
1656 void wxWindowMac::MacHiliteChanged()
1660 void wxWindowMac::MacEnabledStateChanged()
1665 // status queries on the inherited window's state
1668 bool wxWindowMac::MacIsReallyShown()
1670 // only under OSX the visibility of the TLW is taken into account
1671 #if TARGET_API_MAC_OSX
1672 return IsControlVisible( (ControlRef
) m_macControl
) ;
1674 wxWindow
* win
= this ;
1675 while( win
->IsShown() )
1677 if ( win
->IsTopLevel() )
1680 win
= win
->GetParent() ;
1689 bool wxWindowMac::MacIsReallyEnabled()
1691 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1694 bool wxWindowMac::MacIsReallyHilited()
1696 return IsControlActive( (ControlRef
) m_macControl
) ;
1703 int wxWindowMac::GetCharHeight() const
1705 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1706 return dc
.GetCharHeight() ;
1709 int wxWindowMac::GetCharWidth() const
1711 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1712 return dc
.GetCharWidth() ;
1715 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1716 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1718 const wxFont
*fontToUse
= theFont
;
1720 fontToUse
= &m_font
;
1722 wxClientDC
dc( (wxWindowMac
*) this ) ;
1724 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1725 if ( externalLeading
)
1726 *externalLeading
= le
;
1736 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1737 * we always intersect with the entire window, not only with the client area
1740 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1742 #if TARGET_API_MAC_OSX
1744 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1747 RgnHandle update
= NewRgn() ;
1748 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1749 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1750 wxPoint origin
= GetClientAreaOrigin() ;
1751 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1752 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1756 RgnHandle updateRgn = NewRgn() ;
1759 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1763 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1764 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1766 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1767 DisposeRgn(updateRgn) ;
1769 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1771 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1772 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1775 if ( MacGetTopLevelWindow() == NULL )
1778 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1781 wxPoint client = GetClientAreaOrigin();
1784 int x2 = m_width - client.x;
1785 int y2 = m_height - client.y;
1787 if (IsKindOf( CLASSINFO(wxButton)))
1789 // buttons have an "aura"
1796 Rect clientrect = { y1, x1, y2, x2 };
1800 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1801 SectRect( &clientrect , &r , &clientrect ) ;
1804 if ( !EmptyRect( &clientrect ) )
1806 int top = 0 , left = 0 ;
1808 MacClientToRootWindow( &left , &top ) ;
1809 OffsetRect( &clientrect , left , top ) ;
1811 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1817 void wxWindowMac::Freeze()
1819 #if TARGET_API_MAC_OSX
1820 if ( !m_frozenness
++ )
1822 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1827 void wxWindowMac::Thaw()
1829 #if TARGET_API_MAC_OSX
1830 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1832 if ( !--m_frozenness
)
1834 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
1835 HIViewSetNeedsDisplay( (HIViewRef
) m_macControl
, true ) ;
1840 void wxWindowMac::MacRedrawControl()
1843 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1845 #if TARGET_API_MAC_CARBON
1848 wxClientDC dc(this) ;
1849 wxMacPortSetter helper(&dc) ;
1850 wxMacWindowClipper clipper(this) ;
1851 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1852 UMADrawControl( (ControlRef) m_macControl ) ;
1859 void wxWindowMac::OnPaint(wxPaintEvent& event)
1861 // why don't we skip that here ?
1865 wxWindowMac
*wxGetActiveWindow()
1867 // actually this is a windows-only concept
1871 // Coordinates relative to the window
1872 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1874 // We really don't move the mouse programmatically under Mac.
1877 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1879 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1884 event
.GetDC()->Clear() ;
1887 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1889 wxWindowDC
dc(this) ;
1890 wxMacPortSetter
helper(&dc
) ;
1892 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1895 int wxWindowMac::GetScrollPos(int orient
) const
1897 if ( orient
== wxHORIZONTAL
)
1900 return m_hScrollBar
->GetThumbPosition() ;
1905 return m_vScrollBar
->GetThumbPosition() ;
1910 // This now returns the whole range, not just the number
1911 // of positions that we can scroll.
1912 int wxWindowMac::GetScrollRange(int orient
) const
1914 if ( orient
== wxHORIZONTAL
)
1917 return m_hScrollBar
->GetRange() ;
1922 return m_vScrollBar
->GetRange() ;
1927 int wxWindowMac::GetScrollThumb(int orient
) const
1929 if ( orient
== wxHORIZONTAL
)
1932 return m_hScrollBar
->GetThumbSize() ;
1937 return m_vScrollBar
->GetThumbSize() ;
1942 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1944 if ( orient
== wxHORIZONTAL
)
1947 m_hScrollBar
->SetThumbPosition( pos
) ;
1952 m_vScrollBar
->SetThumbPosition( pos
) ;
1956 void wxWindowMac::MacPaintBorders( int left
, int top
)
1962 wxGetOsVersion( &major
, &minor
);
1964 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1965 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1967 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1968 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1969 // OS X has lighter border edges than classic:
1972 darkShadow
.red
= 0x8E8E;
1973 darkShadow
.green
= 0x8E8E;
1974 darkShadow
.blue
= 0x8E8E;
1975 lightShadow
.red
= 0xBDBD;
1976 lightShadow
.green
= 0xBDBD;
1977 lightShadow
.blue
= 0xBDBD;
1983 GetSize( &w
, &h
) ;
1984 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1986 #if wxMAC_USE_THEME_BORDER
1987 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1990 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1991 InsetRect( &rect , border , border );
1992 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1995 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1997 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1998 RGBForeColor( &face
);
1999 MoveTo( left
+ 0 , top
+ h
- 2 );
2000 LineTo( left
+ 0 , top
+ 0 );
2001 LineTo( left
+ w
- 2 , top
+ 0 );
2003 MoveTo( left
+ 2 , top
+ h
- 3 );
2004 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2005 LineTo( left
+ w
- 3 , top
+ 2 );
2007 RGBForeColor( sunken
? &face
: &darkShadow
);
2008 MoveTo( left
+ 0 , top
+ h
- 1 );
2009 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2010 LineTo( left
+ w
- 1 , top
+ 0 );
2012 RGBForeColor( sunken
? &lightShadow
: &white
);
2013 MoveTo( left
+ 1 , top
+ h
- 3 );
2014 LineTo( left
+ 1, top
+ 1 );
2015 LineTo( left
+ w
- 3 , top
+ 1 );
2017 RGBForeColor( sunken
? &white
: &lightShadow
);
2018 MoveTo( left
+ 1 , top
+ h
- 2 );
2019 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2020 LineTo( left
+ w
- 2 , top
+ 1 );
2022 RGBForeColor( sunken
? &darkShadow
: &face
);
2023 MoveTo( left
+ 2 , top
+ h
- 4 );
2024 LineTo( left
+ 2 , top
+ 2 );
2025 LineTo( left
+ w
- 4 , top
+ 2 );
2028 else if (HasFlag(wxSIMPLE_BORDER
))
2030 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2031 RGBForeColor( &darkShadow
) ;
2032 FrameRect( &rect
) ;
2036 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2038 if ( child
== m_hScrollBar
)
2039 m_hScrollBar
= NULL
;
2040 if ( child
== m_vScrollBar
)
2041 m_vScrollBar
= NULL
;
2043 wxWindowBase::RemoveChild( child
) ;
2046 // New function that will replace some of the above.
2047 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2048 int range
, bool refresh
)
2050 if ( orient
== wxHORIZONTAL
)
2054 if ( range
== 0 || thumbVisible
>= range
)
2056 if ( m_hScrollBar
->IsShown() )
2057 m_hScrollBar
->Show(false) ;
2061 if ( !m_hScrollBar
->IsShown() )
2062 m_hScrollBar
->Show(true) ;
2063 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2071 if ( range
== 0 || thumbVisible
>= range
)
2073 if ( m_vScrollBar
->IsShown() )
2074 m_vScrollBar
->Show(false) ;
2078 if ( !m_vScrollBar
->IsShown() )
2079 m_vScrollBar
->Show(true) ;
2080 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2084 MacRepositionScrollBars() ;
2087 // Does a physical scroll
2088 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2090 if( dx
== 0 && dy
==0 )
2095 wxClientDC
dc(this) ;
2096 wxMacPortSetter
helper(&dc
) ;
2098 int width
, height
;
2099 GetClientSize( &width
, &height
) ;
2106 // TODO take out the boundaries
2107 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2109 RgnHandle updateRgn
= NewRgn() ;
2112 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2113 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2114 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2116 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2118 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2119 // but it seems the update only refreshes the background of the control, rather than calling
2120 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2121 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2124 // we also have to scroll the update rgn in this rectangle
2125 // in order not to loose updates
2127 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2128 RgnHandle formerUpdateRgn
= NewRgn() ;
2129 RgnHandle scrollRgn
= NewRgn() ;
2130 RectRgn( scrollRgn
, &scrollrect
) ;
2131 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2133 LocalToGlobal( &pt
) ;
2134 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2135 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2136 if ( !EmptyRgn( formerUpdateRgn
) )
2138 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2139 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2140 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2142 InvalWindowRgn(rootWindow
, updateRgn
) ;
2143 DisposeRgn( updateRgn
) ;
2144 DisposeRgn( formerUpdateRgn
) ;
2145 DisposeRgn( scrollRgn
) ;
2149 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2151 wxWindowMac
*child
= node
->GetData();
2152 if (child
== m_vScrollBar
) continue;
2153 if (child
== m_hScrollBar
) continue;
2154 if (child
->IsTopLevel()) continue;
2157 child
->GetPosition( &x
, &y
);
2159 child
->GetSize( &w
, &h
);
2163 if (rect
->Intersects(rc
))
2164 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2168 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2172 // TODO remove, was moved higher up Update() ;
2176 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2178 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2180 wxScrollWinEvent wevent
;
2181 wevent
.SetPosition(event
.GetPosition());
2182 wevent
.SetOrientation(event
.GetOrientation());
2183 wevent
.m_eventObject
= this;
2185 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2186 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2187 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2188 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2189 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2190 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2191 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2192 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2193 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2194 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2195 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2196 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2197 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2198 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2199 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2200 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2202 GetEventHandler()->ProcessEvent(wevent
);
2206 // Get the window with the focus
2207 wxWindowMac
*wxWindowBase::FindFocus()
2209 return gFocusWindow
;
2212 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2214 // panel wants to track the window which was the last to have focus in it,
2215 // so we want to set ourselves as the window which last had focus
2217 // notice that it's also important to do it upwards the tree becaus
2218 // otherwise when the top level panel gets focus, it won't set it back to
2219 // us, but to some other sibling
2221 // CS:don't know if this is still needed:
2222 //wxChildFocusEvent eventFocus(this);
2223 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2228 void wxWindowMac::OnInternalIdle()
2230 // This calls the UI-update mechanism (querying windows for
2231 // menu/toolbar/control state information)
2232 if (wxUpdateUIEvent::CanUpdate(this))
2233 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2236 // Raise the window to the top of the Z order
2237 void wxWindowMac::Raise()
2241 // Lower the window to the bottom of the Z order
2242 void wxWindowMac::Lower()
2247 // static wxWindow *gs_lastWhich = NULL;
2249 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2251 // first trigger a set cursor event
2253 wxPoint clientorigin
= GetClientAreaOrigin() ;
2254 wxSize clientsize
= GetClientSize() ;
2256 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2258 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2260 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2261 if ( processedEvtSetCursor
&& event
.HasCursor() )
2263 cursor
= event
.GetCursor() ;
2268 // the test for processedEvtSetCursor is here to prevent using m_cursor
2269 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2270 // it - this is a way to say that our cursor shouldn't be used for this
2272 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2282 cursor
= *wxSTANDARD_CURSOR
;
2286 cursor
.MacInstall() ;
2288 return cursor
.Ok() ;
2291 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2295 return m_tooltip
->GetTip() ;
2297 return wxEmptyString
;
2300 void wxWindowMac::Update()
2302 #if TARGET_API_MAC_OSX
2303 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2305 ::Draw1Control( (ControlRef
) m_macControl
) ;
2309 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2311 wxTopLevelWindowMac
* win
= NULL
;
2312 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2315 win
= wxFindWinFromMacWindow( window
) ;
2319 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2323 RgnHandle visRgn
= NewRgn() ;
2324 RgnHandle tempRgn
= NewRgn() ;
2325 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2327 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2328 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2330 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2331 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2340 if ( includeOuterStructures
)
2341 InsetRect( &r
, -3 , -3 ) ;
2342 RectRgn( visRgn
, &r
) ;
2343 if ( !IsTopLevel() )
2345 wxWindow
* child
= this ;
2346 wxWindow
* parent
= child
->GetParent() ;
2351 // we have to find a better clipping algorithm here, in order not to clip things
2352 // positioned like status and toolbar
2353 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2355 size
= parent
->GetSize() ;
2360 size
= parent
->GetClientSize() ;
2361 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2365 parent
->MacWindowToRootWindow( &x
, &y
) ;
2366 MacRootWindowToWindow( &x
, &y
) ;
2368 SetRectRgn( tempRgn
,
2369 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2370 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2371 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2373 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2374 if ( parent
->IsTopLevel() )
2377 parent
= child
->GetParent() ;
2382 wxRegion vis
= visRgn
;
2383 DisposeRgn( visRgn
) ;
2384 DisposeRgn( tempRgn
) ;
2389 This function must not change the updatergn !
2391 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2393 // we let the OS handle root control redraws
2394 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2397 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2398 bool handled
= false ;
2400 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2402 RgnHandle newupdate
= NewRgn() ;
2403 wxSize point
= GetClientSize() ;
2404 wxPoint origin
= GetClientAreaOrigin() ;
2405 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2406 SectRgn( newupdate
, updatergn
, newupdate
) ;
2407 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2408 m_updateRegion
= newupdate
;
2409 DisposeRgn( newupdate
) ;
2412 if ( !EmptyRgn(updatergn
) )
2414 wxWindowDC
dc(this);
2415 if (!EmptyRgn(updatergn
))
2416 dc
.SetClippingRegion(wxRegion(updatergn
));
2418 wxEraseEvent
eevent( GetId(), &dc
);
2419 eevent
.SetEventObject( this );
2420 GetEventHandler()->ProcessEvent( eevent
);
2422 if ( !m_updateRegion
.Empty() )
2424 // paint the window itself
2426 event
.m_timeStamp
= time
;
2427 event
.SetEventObject(this);
2428 handled
= GetEventHandler()->ProcessEvent(event
);
2430 // paint custom borders
2431 wxNcPaintEvent
eventNc( GetId() );
2432 eventNc
.SetEventObject( this );
2433 GetEventHandler()->ProcessEvent( eventNc
);
2439 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2441 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2442 // updatergn is always already clipped to our boundaries
2443 // if we are in compositing mode then it is in relative to the upper left of the control
2444 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2445 // of the toplevel window
2446 // it is in window coordinates, not in client coordinates
2448 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2449 RgnHandle ownUpdateRgn
= NewRgn() ;
2450 CopyRgn( updatergn
, ownUpdateRgn
) ;
2452 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2455 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2456 RgnHandle controlRgn
= NewRgn();
2457 RectRgn( controlRgn
, &bounds
);
2458 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2459 // the window update region
2460 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2461 DisposeRgn( controlRgn
);
2463 //KO: convert ownUpdateRgn to local coordinates
2464 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2467 MacDoRedraw( ownUpdateRgn
, time
) ;
2468 DisposeRgn( ownUpdateRgn
) ;
2472 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2474 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2478 if ( iter
->IsTopLevel() )
2479 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2481 iter
= iter
->GetParent() ;
2483 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2487 void wxWindowMac::MacCreateScrollBars( long style
)
2489 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2491 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2492 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2494 GetClientSize( &width
, &height
) ;
2496 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2497 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2498 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2499 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2501 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2502 vSize
, wxVERTICAL
);
2504 if ( style
& wxVSCROLL
)
2510 m_vScrollBar
->Show(false) ;
2512 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2513 hSize
, wxHORIZONTAL
);
2514 if ( style
& wxHSCROLL
)
2519 m_hScrollBar
->Show(false) ;
2522 // because the create does not take into account the client area origin
2523 MacRepositionScrollBars() ; // we might have a real position shift
2526 void wxWindowMac::MacRepositionScrollBars()
2528 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2529 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2531 // get real client area
2535 GetSize( &width
, &height
) ;
2537 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2538 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2540 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2541 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2542 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2543 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2549 GetSize( &w
, &h
) ;
2551 MacClientToRootWindow( &x
, &y
) ;
2552 MacClientToRootWindow( &w
, &h
) ;
2554 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2556 int totW
= 10000 , totH
= 10000;
2559 if ( iter
->IsTopLevel() )
2561 iter
->GetSize( &totW
, &totH
) ;
2565 iter
= iter
->GetParent() ;
2593 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2597 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2601 bool wxWindowMac::AcceptsFocus() const
2603 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2606 void wxWindowMac::MacSuperChangedPosition()
2608 // only window-absolute structures have to be moved i.e. controls
2610 wxWindowListNode
*node
= GetChildren().GetFirst();
2613 wxWindowMac
*child
= node
->GetData();
2614 child
->MacSuperChangedPosition() ;
2615 node
= node
->GetNext();
2619 void wxWindowMac::MacTopLevelWindowChangedPosition()
2621 // only screen-absolute structures have to be moved i.e. glcanvas
2623 wxWindowListNode
*node
= GetChildren().GetFirst();
2626 wxWindowMac
*child
= node
->GetData();
2627 child
->MacTopLevelWindowChangedPosition() ;
2628 node
= node
->GetNext();
2632 long wxWindowMac::MacGetLeftBorderSize( ) const
2637 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2640 #if wxMAC_USE_THEME_BORDER
2641 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2645 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2648 #if wxMAC_USE_THEME_BORDER
2649 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2653 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2660 long wxWindowMac::MacGetRightBorderSize( ) const
2662 // they are all symmetric in mac themes
2663 return MacGetLeftBorderSize() ;
2666 long wxWindowMac::MacGetTopBorderSize( ) const
2668 // they are all symmetric in mac themes
2669 return MacGetLeftBorderSize() ;
2672 long wxWindowMac::MacGetBottomBorderSize( ) const
2674 // they are all symmetric in mac themes
2675 return MacGetLeftBorderSize() ;
2678 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2680 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2683 // Find the wxWindowMac at the current mouse position, returning the mouse
2685 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2687 pt
= wxGetMousePosition();
2688 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2692 // Get the current mouse position.
2693 wxPoint
wxGetMousePosition()
2696 wxGetMousePosition(& x
, & y
);
2697 return wxPoint(x
, y
);
2700 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2702 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2704 // copied from wxGTK : CS
2705 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2708 // (a) it's a command event and so is propagated to the parent
2709 // (b) under MSW it can be generated from kbd too
2710 // (c) it uses screen coords (because of (a))
2711 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2713 this->ClientToScreen(event
.GetPosition()));
2714 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2717 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2723 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2725 // OS Needs it in tlw content area coordinates
2726 MacClientToRootWindow( &x
, &y
) ;
2730 // OS Needs it in window not client coordinates
2731 wxPoint origin
= GetClientAreaOrigin() ;
2736 SInt16 controlpart
;
2741 short modifiers
= 0;
2743 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2744 modifiers
|= btnState
;
2746 if ( event
.m_shiftDown
)
2747 modifiers
|= shiftKey
;
2749 if ( event
.m_controlDown
)
2750 modifiers
|= controlKey
;
2752 if ( event
.m_altDown
)
2753 modifiers
|= optionKey
;
2755 if ( event
.m_metaDown
)
2756 modifiers
|= cmdKey
;
2758 bool handled
= false ;
2760 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2762 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2763 wxTheApp
->s_lastMouseDown
= 0 ;
2764 if ( controlpart
!= kControlNoPart
)
2766 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2779 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2781 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2784 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2788 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2789 Rect bounds
= { y
, x
, y
+h
, x
+w
};