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 #ifndef 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() ;
151 // unfortunately this update region may be incorrect (tree ctrl sample )
152 // so we have to reset it
153 // updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
155 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
157 #if 0 // in case we would need a coregraphics compliant background erase first
158 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
159 if ( thisWindow
->MacIsUserPane() )
162 err
= HIViewGetBounds( controlRef
, &bounds
);
163 CGContextSetRGBFillColor( cgContext
, 1 , 1 , 1 , 1 );
164 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
165 CGContextFillRect( cgContext
, bounds
);
168 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
171 result
= eventNotHandledErr
;
174 case kEventControlVisibilityChanged
:
175 thisWindow
->MacVisibilityChanged() ;
177 case kEventControlEnabledStateChanged
:
178 thisWindow
->MacEnabledStateChanged() ;
180 case kEventControlHiliteChanged
:
181 thisWindow
->MacHiliteChanged() ;
189 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
191 OSStatus result
= eventNotHandledErr
;
193 switch ( GetEventClass( event
) )
195 case kEventClassControl
:
196 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
204 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
206 // ---------------------------------------------------------------------------
207 // UserPane events for non OSX builds
208 // ---------------------------------------------------------------------------
210 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
212 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
213 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
214 win
->MacControlUserPaneDrawProc(part
) ;
217 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
219 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
220 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
221 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
224 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
226 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
227 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
228 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
231 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
233 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
234 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
235 win
->MacControlUserPaneIdleProc() ;
238 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
240 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
241 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
242 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
245 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
247 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
248 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
249 win
->MacControlUserPaneActivateProc(activating
) ;
252 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
254 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
255 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
256 return win
->MacControlUserPaneFocusProc(action
) ;
259 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
261 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
262 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
263 win
->MacControlUserPaneBackgroundProc(info
) ;
266 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
268 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
271 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
273 return kControlNoPart
;
276 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
278 return kControlNoPart
;
281 void wxWindowMac::MacControlUserPaneIdleProc()
285 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
287 return kControlNoPart
;
290 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
294 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
296 return kControlNoPart
;
299 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
303 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
304 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
305 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
306 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
307 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
308 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
309 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
310 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
312 // ===========================================================================
314 // ===========================================================================
316 wxList
wxWinMacControlList(wxKEY_INTEGER
);
318 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
320 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
323 return (wxControl
*)node
->GetData();
326 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
328 // adding NULL ControlRef is (first) surely a result of an error and
329 // (secondly) breaks native event processing
330 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
332 if ( !wxWinMacControlList
.Find((long)inControl
) )
333 wxWinMacControlList
.Append((long)inControl
, control
);
336 void wxRemoveMacControlAssociation(wxWindow
*control
)
338 wxWinMacControlList
.DeleteObject(control
);
342 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
344 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
346 // we have to setup the brush in the current port and return noErr
347 // or return an error code so that the control manager walks further up the
348 // hierarchy to find a correct background
350 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
352 OSStatus status
= paramErr
;
355 case kControlMsgApplyTextColor
:
357 case kControlMsgSetUpBackground
:
359 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
363 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
367 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
369 // this clipping is only needed for non HIView
371 RgnHandle clip
= NewRgn() ;
374 wx
->MacWindowToRootWindow( &x
,&y
) ;
375 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
376 OffsetRgn( clip
, x
, y
) ;
383 else if ( wx->MacIsUserPane() )
385 // if we don't have a valid brush for such a control, we have to call the
386 // setup of our parent ourselves
387 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
400 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
401 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
405 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
408 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
413 // ----------------------------------------------------------------------------
414 // constructors and such
415 // ----------------------------------------------------------------------------
417 void wxWindowMac::Init()
419 m_backgroundTransparent
= FALSE
;
421 // as all windows are created with WS_VISIBLE style...
424 m_hScrollBar
= NULL
;
425 m_vScrollBar
= NULL
;
426 m_macBackgroundBrush
= wxNullBrush
;
428 m_macControl
= NULL
;
430 m_macIsUserPane
= TRUE
;
432 // make sure all proc ptrs are available
434 if ( gControlUserPaneDrawUPP
== NULL
)
436 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
437 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
438 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
439 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
440 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
441 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
442 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
443 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
445 if ( wxMacLiveScrollbarActionUPP
== NULL
)
447 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
450 if ( wxMacSetupControlBackgroundUPP
== NULL
)
452 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
458 wxWindowMac::~wxWindowMac()
462 m_isBeingDeleted
= TRUE
;
464 #ifndef __WXUNIVERSAL__
465 // VS: make sure there's no wxFrame with last focus set to us:
466 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
468 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
471 if ( frame
->GetLastFocus() == this )
473 frame
->SetLastFocus((wxWindow
*)NULL
);
478 #endif // __WXUNIVERSAL__
480 // wxRemoveMacControlAssociation( this ) ;
481 // If we delete an item, we should initialize the parent panel,
482 // because it could now be invalid.
483 wxWindow
*parent
= GetParent() ;
486 if (parent
->GetDefaultItem() == (wxButton
*) this)
487 parent
->SetDefaultItem(NULL
);
489 if ( (ControlRef
) m_macControl
)
491 // in case the callback might be called during destruction
492 wxRemoveMacControlAssociation( this) ;
493 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
494 ::DisposeControl( (ControlRef
) m_macControl
) ;
495 m_macControl
= NULL
;
498 if ( g_MacLastWindow
== this )
500 g_MacLastWindow
= NULL
;
503 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
506 if ( frame
->GetLastFocus() == this )
507 frame
->SetLastFocus( NULL
) ;
510 if ( gFocusWindow
== this )
512 gFocusWindow
= NULL
;
517 // delete our drop target if we've got one
518 #if wxUSE_DRAG_AND_DROP
519 if ( m_dropTarget
!= NULL
)
524 #endif // wxUSE_DRAG_AND_DROP
529 void wxWindowMac::MacInstallEventHandler()
531 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
532 GetEventTypeCount(eventList
), eventList
, this,
533 (EventHandlerRef
*)&m_macControlEventHandler
);
538 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
542 const wxString
& name
)
544 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
546 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
549 parent
->AddChild(this);
551 m_windowVariant
= parent
->GetWindowVariant() ;
553 if ( m_macIsUserPane
)
555 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
557 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
/*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
559 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
561 MacPostControlCreate(pos
,size
) ;
562 #if !TARGET_API_MAC_OSX
563 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
564 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
565 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
566 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
567 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
568 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
569 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
570 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
571 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
572 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
573 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
574 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
575 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
576 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
577 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
578 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
581 #ifndef __WXUNIVERSAL__
582 // Don't give scrollbars to wxControls unless they ask for them
583 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
584 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
586 MacCreateScrollBars( style
) ;
590 wxWindowCreateEvent
event(this);
591 GetEventHandler()->AddPendingEvent(event
);
596 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
598 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
600 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
601 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
603 MacInstallEventHandler();
605 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
606 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
607 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
609 // adjust font, controlsize etc
610 DoSetWindowVariant( m_windowVariant
) ;
612 #if !TARGET_API_MAC_OSX
613 // eventually we can fix some clipping issues be reactivating this hook
614 //if ( m_macIsUserPane )
615 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
618 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
620 wxSize new_size
= size
;
621 if (!m_macIsUserPane
)
623 wxSize
best_size( DoGetBestSize() );
626 new_size
.x
= best_size
.x
;
629 new_size
.y
= best_size
.y
;
631 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
634 SetCursor( *wxSTANDARD_CURSOR
) ;
638 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
640 wxASSERT( m_macControl
!= NULL
) ;
642 m_windowVariant
= variant
;
645 ThemeFontID themeFont
= kThemeSystemFont
;
647 // we will get that from the settings later
648 // and make this NORMAL later, but first
649 // we have a few calculations that we must fix
653 case wxWINDOW_VARIANT_NORMAL
:
654 size
= kControlSizeNormal
;
655 themeFont
= kThemeSystemFont
;
657 case wxWINDOW_VARIANT_SMALL
:
658 size
= kControlSizeSmall
;
659 themeFont
= kThemeSmallSystemFont
;
661 case wxWINDOW_VARIANT_MINI
:
662 if (UMAGetSystemVersion() >= 0x1030 )
664 // not always defined in the headers
670 size
= kControlSizeSmall
;
671 themeFont
= kThemeSmallSystemFont
;
674 case wxWINDOW_VARIANT_LARGE
:
675 size
= kControlSizeLarge
;
676 themeFont
= kThemeSystemFont
;
679 wxFAIL_MSG(_T("unexpected window variant"));
682 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
685 font
.MacCreateThemeFont( themeFont
) ;
689 void wxWindowMac::MacUpdateControlFont()
691 ControlFontStyleRec fontStyle
;
692 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
694 switch( m_font
.MacGetThemeFontID() )
696 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
697 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
698 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
699 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
701 fontStyle
.flags
= kControlUseFontMask
;
705 fontStyle
.font
= m_font
.MacGetFontNum() ;
706 fontStyle
.style
= m_font
.MacGetFontStyle() ;
707 fontStyle
.size
= m_font
.MacGetFontSize() ;
708 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
711 fontStyle
.just
= teJustLeft
;
712 fontStyle
.flags
|= kControlUseJustMask
;
713 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
714 fontStyle
.just
= teJustCenter
;
715 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
716 fontStyle
.just
= teJustRight
;
719 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
720 fontStyle
.flags
|= kControlUseForeColorMask
;
722 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
726 bool wxWindowMac::SetFont(const wxFont
& font
)
728 bool retval
= !wxWindowBase::SetFont( font
) ;
730 MacUpdateControlFont() ;
735 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
737 if ( !wxWindowBase::SetForegroundColour(col
) )
740 MacUpdateControlFont() ;
745 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
747 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
751 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
753 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
755 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
757 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
761 brush
.SetColour( col
) ;
763 MacSetBackgroundBrush( brush
) ;
765 MacUpdateControlFont() ;
771 bool wxWindowMac::MacCanFocus() const
773 wxASSERT( m_macControl
!= NULL
) ;
779 void wxWindowMac::SetFocus()
781 if ( gFocusWindow
== this )
784 if ( AcceptsFocus() )
790 if ( gFocusWindow
->m_caret
)
792 gFocusWindow
->m_caret
->OnKillFocus();
794 #endif // wxUSE_CARET
795 #ifndef __WXUNIVERSAL__
796 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
797 // TODO we must use the built-in focusing
798 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
800 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
801 control
->MacRedrawControl() ;
804 // Without testing the window id, for some reason
805 // a kill focus event can still be sent to
806 // the control just being focussed.
807 int thisId
= this->m_windowId
;
808 int gFocusWindowId
= gFocusWindow
->m_windowId
;
809 if (gFocusWindowId
!= thisId
)
811 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
812 event
.SetEventObject(gFocusWindow
);
813 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
816 gFocusWindow
= this ;
822 m_caret
->OnSetFocus();
824 #endif // wxUSE_CARET
825 // panel wants to track the window which was the last to have focus in it
826 wxChildFocusEvent
eventFocus(this);
827 GetEventHandler()->ProcessEvent(eventFocus
);
829 #ifndef __WXUNIVERSAL__
830 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
831 if ( control
&& control
->GetHandle() )
833 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
836 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
837 event
.SetEventObject(this);
838 GetEventHandler()->ProcessEvent(event
) ;
844 void wxWindowMac::DoCaptureMouse()
846 wxTheApp
->s_captureWindow
= this ;
849 wxWindow
* wxWindowBase::GetCapture()
851 return wxTheApp
->s_captureWindow
;
854 void wxWindowMac::DoReleaseMouse()
856 wxTheApp
->s_captureWindow
= NULL
;
859 #if wxUSE_DRAG_AND_DROP
861 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
863 if ( m_dropTarget
!= 0 ) {
867 m_dropTarget
= pDropTarget
;
868 if ( m_dropTarget
!= 0 )
876 // Old style file-manager drag&drop
877 void wxWindowMac::DragAcceptFiles(bool accept
)
882 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
883 int& w
, int& h
) const
886 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
891 w
= bounds
.right
- bounds
.left
;
892 h
= bounds
.bottom
- bounds
.top
;
894 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
897 Point tlworigin
= { 0 , 0 } ;
900 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
901 ::LocalToGlobal( &tlworigin
) ;
908 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
911 int& w
, int& h
) const
915 // todo the default calls may be used as soon as PostCreateControl Is moved here
916 w
= size
.x
; // WidthDefault( size.x );
917 h
= size
.y
; // HeightDefault( size.y ) ;
918 #if !TARGET_API_MAC_OSX
919 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
926 void wxWindowMac::DoGetSize(int *x
, int *y
) const
928 #if TARGET_API_MAC_OSX
929 int x1
, y1
, w1
,h1
;
930 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
936 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
937 if(x
) *x
= bounds
.right
- bounds
.left
;
938 if(y
) *y
= bounds
.bottom
- bounds
.top
;
942 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
944 #if TARGET_API_MAC_OSX
945 int x1
, y1
, w1
,h1
;
946 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
949 wxWindow
*parent
= GetParent();
952 wxPoint
pt(parent
->GetClientAreaOrigin());
961 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
962 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
964 int xx
= bounds
.left
;
965 int yy
= bounds
.top
;
967 if ( !GetParent()->IsTopLevel() )
969 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
975 wxPoint
pt(GetParent()->GetClientAreaOrigin());
984 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
986 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
988 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
991 Point localwhere
= {0,0} ;
993 if(x
) localwhere
.h
= * x
;
994 if(y
) localwhere
.v
= * y
;
996 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
997 ::GlobalToLocal( &localwhere
) ;
998 if(x
) *x
= localwhere
.h
;
999 if(y
) *y
= localwhere
.v
;
1002 MacRootWindowToWindow( x
, y
) ;
1004 wxPoint origin
= GetClientAreaOrigin() ;
1005 if(x
) *x
-= origin
.x
;
1006 if(y
) *y
-= origin
.y
;
1009 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1011 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1012 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1014 wxPoint origin
= GetClientAreaOrigin() ;
1015 if(x
) *x
+= origin
.x
;
1016 if(y
) *y
+= origin
.y
;
1018 MacWindowToRootWindow( x
, y
) ;
1021 Point localwhere
= { 0,0 };
1022 if(x
) localwhere
.h
= * x
;
1023 if(y
) localwhere
.v
= * y
;
1025 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1026 ::LocalToGlobal( &localwhere
) ;
1027 if(x
) *x
= localwhere
.h
;
1028 if(y
) *y
= localwhere
.v
;
1032 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1034 wxPoint origin
= GetClientAreaOrigin() ;
1035 if(x
) *x
+= origin
.x
;
1036 if(y
) *y
+= origin
.y
;
1038 MacWindowToRootWindow( x
, y
) ;
1041 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1043 MacRootWindowToWindow( x
, y
) ;
1045 wxPoint origin
= GetClientAreaOrigin() ;
1046 if(x
) *x
-= origin
.x
;
1047 if(y
) *y
-= origin
.y
;
1050 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1052 #if TARGET_API_MAC_OSX
1054 if ( x
) pt
.x
= *x
;
1055 if ( y
) pt
.y
= *y
;
1057 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1059 if ( x
) *x
= (int) pt
.x
;
1060 if ( y
) *y
= (int) pt
.y
;
1062 if ( !IsTopLevel() )
1065 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1066 if(x
) *x
+= bounds
.left
;
1067 if(y
) *y
+= bounds
.top
;
1072 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1077 MacWindowToRootWindow( &x1
, &y1
) ;
1082 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1084 #if TARGET_API_MAC_OSX
1086 if ( x
) pt
.x
= *x
;
1087 if ( y
) pt
.y
= *y
;
1089 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1091 if ( x
) *x
= (int) pt
.x
;
1092 if ( y
) *y
= (int) pt
.y
;
1094 if ( !IsTopLevel() )
1097 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1098 if(x
) *x
-= bounds
.left
;
1099 if(y
) *y
-= bounds
.top
;
1104 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1109 MacRootWindowToWindow( &x1
, &y1
) ;
1114 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1116 wxSize sizeTotal
= size
;
1118 RgnHandle rgn
= NewRgn() ;
1122 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1124 GetRegionBounds( rgn
, &content
) ;
1129 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1132 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1133 #if !TARGET_API_MAC_OSX
1134 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1137 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1138 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1140 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1141 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1147 // Get size *available for subwindows* i.e. excluding menu bar etc.
1148 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1152 RgnHandle rgn
= NewRgn() ;
1154 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1156 GetRegionBounds( rgn
, &content
) ;
1161 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1163 #if !TARGET_API_MAC_OSX
1165 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1166 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1168 ww
= content
.right
- content
.left
;
1169 hh
= content
.bottom
- content
.top
;
1171 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1172 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1174 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1180 GetSize( &w
, &h
) ;
1182 MacClientToRootWindow( &x1
, &y1
) ;
1183 MacClientToRootWindow( &w
, &h
) ;
1185 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1187 int totW
= 10000 , totH
= 10000;
1190 if ( iter
->IsTopLevel() )
1192 iter
->GetSize( &totW
, &totH
) ;
1196 iter
= iter
->GetParent() ;
1199 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1201 hh
-= MAC_SCROLLBAR_SIZE
;
1207 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1209 ww
-= MAC_SCROLLBAR_SIZE
;
1221 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1223 if (m_cursor
== cursor
)
1226 if (wxNullCursor
== cursor
)
1228 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1233 if ( ! wxWindowBase::SetCursor( cursor
) )
1237 wxASSERT_MSG( m_cursor
.Ok(),
1238 wxT("cursor must be valid after call to the base version"));
1242 TODO why do we have to use current coordinates ?
1245 wxWindowMac *mouseWin ;
1248 // Change the cursor NOW if we're within the correct window
1251 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1253 if ( mouseWin == this && !wxIsBusy() )
1255 m_cursor.MacInstall() ;
1261 m_cursor
.MacInstall() ;
1268 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1270 menu
->SetInvokingWindow(this);
1272 ClientToScreen( &x
, &y
) ;
1274 menu
->MacBeforeDisplay( true ) ;
1275 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1276 if ( HiWord(menuResult
) != 0 )
1279 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1280 wxMenuItem
* item
= NULL
;
1282 item
= menu
->FindItem(id
, &realmenu
) ;
1283 if (item
->IsCheckable())
1285 item
->Check( !item
->IsChecked() ) ;
1287 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1289 menu
->MacAfterDisplay( true ) ;
1291 menu
->SetInvokingWindow(NULL
);
1297 // ----------------------------------------------------------------------------
1299 // ----------------------------------------------------------------------------
1303 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1305 wxWindowBase::DoSetToolTip(tooltip
);
1308 m_tooltip
->SetWindow(this);
1311 #endif // wxUSE_TOOLTIPS
1313 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1315 int former_x
, former_y
, former_w
, former_h
;
1316 #if !TARGET_API_MAC_OSX
1317 DoGetPosition( &former_x
, &former_y
) ;
1318 DoGetSize( &former_w
, &former_h
) ;
1320 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1323 int actualWidth
= width
;
1324 int actualHeight
= height
;
1328 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1329 actualWidth
= m_minWidth
;
1330 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1331 actualHeight
= m_minHeight
;
1332 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1333 actualWidth
= m_maxWidth
;
1334 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1335 actualHeight
= m_maxHeight
;
1337 bool doMove
= false ;
1338 bool doResize
= false ;
1340 if ( actualX
!= former_x
|| actualY
!= former_y
)
1344 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1349 if ( doMove
|| doResize
)
1351 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1352 #if TARGET_API_MAC_OSX
1353 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1356 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1358 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1360 MacRepositionScrollBars() ;
1363 wxPoint
point(actualX
,actualY
);
1364 wxMoveEvent
event(point
, m_windowId
);
1365 event
.SetEventObject(this);
1366 GetEventHandler()->ProcessEvent(event
) ;
1370 MacRepositionScrollBars() ;
1371 wxSize
size(actualWidth
, actualHeight
);
1372 wxSizeEvent
event(size
, m_windowId
);
1373 event
.SetEventObject(this);
1374 GetEventHandler()->ProcessEvent(event
);
1380 wxSize
wxWindowMac::DoGetBestSize() const
1382 if ( m_macIsUserPane
|| IsTopLevel() )
1383 return wxWindowBase::DoGetBestSize() ;
1385 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1386 short baselineoffset
;
1387 int bestWidth
, bestHeight
;
1388 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1390 if ( EmptyRect( &bestsize
) )
1393 bestsize
.left
= bestsize
.top
= 0 ;
1394 bestsize
.right
= 16 ;
1395 bestsize
.bottom
= 16 ;
1396 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1398 bestsize
.bottom
= 16 ;
1400 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1402 bestsize
.bottom
= 24 ;
1406 // return wxWindowBase::DoGetBestSize() ;
1410 bestWidth
= bestsize
.right
- bestsize
.left
;
1411 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1412 if ( bestHeight
< 10 )
1415 return wxSize(bestWidth
, bestHeight
);
1416 // return wxWindowBase::DoGetBestSize() ;
1420 // set the size of the window: if the dimensions are positive, just use them,
1421 // but if any of them is equal to -1, it means that we must find the value for
1422 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1423 // which case -1 is a valid value for x and y)
1425 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1426 // the width/height to best suit our contents, otherwise we reuse the current
1428 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1430 // get the current size and position...
1431 int currentX
, currentY
;
1432 GetPosition(¤tX
, ¤tY
);
1434 int currentW
,currentH
;
1435 GetSize(¤tW
, ¤tH
);
1437 // ... and don't do anything (avoiding flicker) if it's already ok
1438 if ( x
== currentX
&& y
== currentY
&&
1439 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1442 MacRepositionScrollBars() ; // we might have a real position shift
1446 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1448 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1451 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1453 wxSize
size(-1, -1);
1456 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1458 size
= DoGetBestSize();
1463 // just take the current one
1470 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1474 size
= DoGetBestSize();
1476 //else: already called DoGetBestSize() above
1482 // just take the current one
1487 DoMoveWindow(x
, y
, width
, height
);
1491 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1493 RgnHandle rgn
= NewRgn() ;
1495 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1496 GetRegionBounds( rgn
, &content
) ;
1498 #if !TARGET_API_MAC_OSX
1500 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1501 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1504 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1507 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1509 if ( clientheight
!= -1 || clientheight
!= -1 )
1511 int currentclientwidth
, currentclientheight
;
1512 int currentwidth
, currentheight
;
1514 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1515 GetSize( ¤twidth
, ¤theight
) ;
1517 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1518 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1522 void wxWindowMac::SetTitle(const wxString
& title
)
1524 m_label
= wxStripMenuCodes(title
) ;
1528 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1533 wxString
wxWindowMac::GetTitle() const
1538 bool wxWindowMac::Show(bool show
)
1540 if ( !wxWindowBase::Show(show
) )
1543 // TODO use visibilityChanged Carbon Event for OSX
1544 bool former
= MacIsReallyShown() ;
1546 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1547 if ( former
!= MacIsReallyShown() )
1548 MacPropagateVisibilityChanged() ;
1552 bool wxWindowMac::Enable(bool enable
)
1554 wxASSERT( m_macControl
!= NULL
) ;
1555 if ( !wxWindowBase::Enable(enable
) )
1558 bool former
= MacIsReallyEnabled() ;
1560 EnableControl( (ControlRef
) m_macControl
) ;
1562 DisableControl( (ControlRef
) m_macControl
) ;
1564 if ( former
!= MacIsReallyEnabled() )
1565 MacPropagateEnabledStateChanged() ;
1570 // status change propagations (will be not necessary for OSX later )
1573 void wxWindowMac::MacPropagateVisibilityChanged()
1575 #if !TARGET_API_MAC_OSX
1576 MacVisibilityChanged() ;
1578 wxWindowListNode
*node
= GetChildren().GetFirst();
1581 wxWindowMac
*child
= node
->GetData();
1582 if ( child
->IsShown() )
1583 child
->MacPropagateVisibilityChanged( ) ;
1584 node
= node
->GetNext();
1589 void wxWindowMac::MacPropagateEnabledStateChanged( )
1591 #if !TARGET_API_MAC_OSX
1592 MacEnabledStateChanged() ;
1594 wxWindowListNode
*node
= GetChildren().GetFirst();
1597 wxWindowMac
*child
= node
->GetData();
1598 if ( child
->IsEnabled() )
1599 child
->MacPropagateEnabledStateChanged() ;
1600 node
= node
->GetNext();
1605 void wxWindowMac::MacPropagateHiliteChanged( )
1607 #if !TARGET_API_MAC_OSX
1608 MacHiliteChanged() ;
1610 wxWindowListNode
*node
= GetChildren().GetFirst();
1613 wxWindowMac
*child
= node
->GetData();
1614 // if ( child->IsEnabled() )
1615 child
->MacPropagateHiliteChanged() ;
1616 node
= node
->GetNext();
1622 // status change notifications
1625 void wxWindowMac::MacVisibilityChanged()
1629 void wxWindowMac::MacHiliteChanged()
1633 void wxWindowMac::MacEnabledStateChanged()
1638 // status queries on the inherited window's state
1641 bool wxWindowMac::MacIsReallyShown()
1643 // only under OSX the visibility of the TLW is taken into account
1644 #if TARGET_API_MAC_OSX
1645 return IsControlVisible( (ControlRef
) m_macControl
) ;
1647 wxWindow
* win
= this ;
1648 while( win
->IsShown() )
1650 if ( win
->IsTopLevel() )
1653 win
= win
->GetParent() ;
1662 bool wxWindowMac::MacIsReallyEnabled()
1664 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1667 bool wxWindowMac::MacIsReallyHilited()
1669 return IsControlActive( (ControlRef
) m_macControl
) ;
1676 int wxWindowMac::GetCharHeight() const
1678 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1679 return dc
.GetCharHeight() ;
1682 int wxWindowMac::GetCharWidth() const
1684 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1685 return dc
.GetCharWidth() ;
1688 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1689 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1691 const wxFont
*fontToUse
= theFont
;
1693 fontToUse
= &m_font
;
1695 wxClientDC
dc( (wxWindowMac
*) this ) ;
1697 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1698 if ( externalLeading
)
1699 *externalLeading
= le
;
1709 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1710 * we always intersect with the entire window, not only with the client area
1713 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1715 #if TARGET_API_MAC_OSX
1717 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1720 RgnHandle update
= NewRgn() ;
1721 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1722 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1723 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1726 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1728 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1729 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1732 if ( MacGetTopLevelWindow() == NULL )
1735 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1738 wxPoint client = GetClientAreaOrigin();
1741 int x2 = m_width - client.x;
1742 int y2 = m_height - client.y;
1744 if (IsKindOf( CLASSINFO(wxButton)))
1746 // buttons have an "aura"
1753 Rect clientrect = { y1, x1, y2, x2 };
1757 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1758 SectRect( &clientrect , &r , &clientrect ) ;
1761 if ( !EmptyRect( &clientrect ) )
1763 int top = 0 , left = 0 ;
1765 MacClientToRootWindow( &left , &top ) ;
1766 OffsetRect( &clientrect , left , top ) ;
1768 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1774 void wxWindowMac::MacRedrawControl()
1777 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1779 #if TARGET_API_MAC_CARBON
1782 wxClientDC dc(this) ;
1783 wxMacPortSetter helper(&dc) ;
1784 wxMacWindowClipper clipper(this) ;
1785 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1786 UMADrawControl( (ControlRef) m_macControl ) ;
1793 void wxWindowMac::OnPaint(wxPaintEvent& event)
1795 // why don't we skip that here ?
1799 wxWindowMac
*wxGetActiveWindow()
1801 // actually this is a windows-only concept
1805 // Coordinates relative to the window
1806 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1808 // We really don't move the mouse programmatically under Mac.
1811 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1813 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1818 event
.GetDC()->Clear() ;
1821 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1823 wxWindowDC
dc(this) ;
1824 wxMacPortSetter
helper(&dc
) ;
1826 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1829 int wxWindowMac::GetScrollPos(int orient
) const
1831 if ( orient
== wxHORIZONTAL
)
1834 return m_hScrollBar
->GetThumbPosition() ;
1839 return m_vScrollBar
->GetThumbPosition() ;
1844 // This now returns the whole range, not just the number
1845 // of positions that we can scroll.
1846 int wxWindowMac::GetScrollRange(int orient
) const
1848 if ( orient
== wxHORIZONTAL
)
1851 return m_hScrollBar
->GetRange() ;
1856 return m_vScrollBar
->GetRange() ;
1861 int wxWindowMac::GetScrollThumb(int orient
) const
1863 if ( orient
== wxHORIZONTAL
)
1866 return m_hScrollBar
->GetThumbSize() ;
1871 return m_vScrollBar
->GetThumbSize() ;
1876 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1878 if ( orient
== wxHORIZONTAL
)
1881 m_hScrollBar
->SetThumbPosition( pos
) ;
1886 m_vScrollBar
->SetThumbPosition( pos
) ;
1890 void wxWindowMac::MacPaintBorders( int left
, int top
)
1896 wxGetOsVersion( &major
, &minor
);
1898 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1899 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1901 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1902 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1903 // OS X has lighter border edges than classic:
1906 darkShadow
.red
= 0x8E8E;
1907 darkShadow
.green
= 0x8E8E;
1908 darkShadow
.blue
= 0x8E8E;
1909 lightShadow
.red
= 0xBDBD;
1910 lightShadow
.green
= 0xBDBD;
1911 lightShadow
.blue
= 0xBDBD;
1917 GetSize( &w
, &h
) ;
1918 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1920 #if wxMAC_USE_THEME_BORDER
1921 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1924 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1925 InsetRect( &rect , border , border );
1926 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1929 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1931 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1932 RGBForeColor( &face
);
1933 MoveTo( left
+ 0 , top
+ h
- 2 );
1934 LineTo( left
+ 0 , top
+ 0 );
1935 LineTo( left
+ w
- 2 , top
+ 0 );
1937 MoveTo( left
+ 2 , top
+ h
- 3 );
1938 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1939 LineTo( left
+ w
- 3 , top
+ 2 );
1941 RGBForeColor( sunken
? &face
: &darkShadow
);
1942 MoveTo( left
+ 0 , top
+ h
- 1 );
1943 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1944 LineTo( left
+ w
- 1 , top
+ 0 );
1946 RGBForeColor( sunken
? &lightShadow
: &white
);
1947 MoveTo( left
+ 1 , top
+ h
- 3 );
1948 LineTo( left
+ 1, top
+ 1 );
1949 LineTo( left
+ w
- 3 , top
+ 1 );
1951 RGBForeColor( sunken
? &white
: &lightShadow
);
1952 MoveTo( left
+ 1 , top
+ h
- 2 );
1953 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1954 LineTo( left
+ w
- 2 , top
+ 1 );
1956 RGBForeColor( sunken
? &darkShadow
: &face
);
1957 MoveTo( left
+ 2 , top
+ h
- 4 );
1958 LineTo( left
+ 2 , top
+ 2 );
1959 LineTo( left
+ w
- 4 , top
+ 2 );
1962 else if (HasFlag(wxSIMPLE_BORDER
))
1964 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1965 RGBForeColor( &darkShadow
) ;
1966 FrameRect( &rect
) ;
1970 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1972 if ( child
== m_hScrollBar
)
1973 m_hScrollBar
= NULL
;
1974 if ( child
== m_vScrollBar
)
1975 m_vScrollBar
= NULL
;
1977 wxWindowBase::RemoveChild( child
) ;
1980 // New function that will replace some of the above.
1981 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1982 int range
, bool refresh
)
1984 if ( orient
== wxHORIZONTAL
)
1988 if ( range
== 0 || thumbVisible
>= range
)
1990 if ( m_hScrollBar
->IsShown() )
1991 m_hScrollBar
->Show(false) ;
1995 if ( !m_hScrollBar
->IsShown() )
1996 m_hScrollBar
->Show(true) ;
1997 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2005 if ( range
== 0 || thumbVisible
>= range
)
2007 if ( m_vScrollBar
->IsShown() )
2008 m_vScrollBar
->Show(false) ;
2012 if ( !m_vScrollBar
->IsShown() )
2013 m_vScrollBar
->Show(true) ;
2014 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2018 MacRepositionScrollBars() ;
2021 // Does a physical scroll
2022 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2024 if( dx
== 0 && dy
==0 )
2029 wxClientDC
dc(this) ;
2030 wxMacPortSetter
helper(&dc
) ;
2032 int width
, height
;
2033 GetClientSize( &width
, &height
) ;
2040 // TODO take out the boundaries
2041 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2043 RgnHandle updateRgn
= NewRgn() ;
2046 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2047 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2048 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2050 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2052 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2053 // but it seems the update only refreshes the background of the control, rather than calling
2054 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2055 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2058 // we also have to scroll the update rgn in this rectangle
2059 // in order not to loose updates
2061 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2062 RgnHandle formerUpdateRgn
= NewRgn() ;
2063 RgnHandle scrollRgn
= NewRgn() ;
2064 RectRgn( scrollRgn
, &scrollrect
) ;
2065 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2067 LocalToGlobal( &pt
) ;
2068 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2069 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2070 if ( !EmptyRgn( formerUpdateRgn
) )
2072 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2073 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2074 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2076 InvalWindowRgn(rootWindow
, updateRgn
) ;
2077 DisposeRgn( updateRgn
) ;
2078 DisposeRgn( formerUpdateRgn
) ;
2079 DisposeRgn( scrollRgn
) ;
2083 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2085 wxWindowMac
*child
= node
->GetData();
2086 if (child
== m_vScrollBar
) continue;
2087 if (child
== m_hScrollBar
) continue;
2088 if (child
->IsTopLevel()) continue;
2091 child
->GetPosition( &x
, &y
);
2093 child
->GetSize( &w
, &h
);
2097 if (rect
->Intersects(rc
))
2098 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2102 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2106 // TODO remove, was moved higher up Update() ;
2110 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2112 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2114 wxScrollWinEvent wevent
;
2115 wevent
.SetPosition(event
.GetPosition());
2116 wevent
.SetOrientation(event
.GetOrientation());
2117 wevent
.m_eventObject
= this;
2119 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2120 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2121 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2122 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2123 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2124 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2125 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2126 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2127 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2128 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2129 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2130 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2131 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2132 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2133 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2134 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2136 GetEventHandler()->ProcessEvent(wevent
);
2140 // Get the window with the focus
2141 wxWindowMac
*wxWindowBase::FindFocus()
2143 return gFocusWindow
;
2146 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2148 // panel wants to track the window which was the last to have focus in it,
2149 // so we want to set ourselves as the window which last had focus
2151 // notice that it's also important to do it upwards the tree becaus
2152 // otherwise when the top level panel gets focus, it won't set it back to
2153 // us, but to some other sibling
2155 // CS:don't know if this is still needed:
2156 //wxChildFocusEvent eventFocus(this);
2157 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2162 void wxWindowMac::OnInternalIdle()
2164 // This calls the UI-update mechanism (querying windows for
2165 // menu/toolbar/control state information)
2166 if (wxUpdateUIEvent::CanUpdate(this))
2167 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2170 // Raise the window to the top of the Z order
2171 void wxWindowMac::Raise()
2175 // Lower the window to the bottom of the Z order
2176 void wxWindowMac::Lower()
2181 // static wxWindow *gs_lastWhich = NULL;
2183 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2185 // first trigger a set cursor event
2187 wxPoint clientorigin
= GetClientAreaOrigin() ;
2188 wxSize clientsize
= GetClientSize() ;
2190 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2192 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2194 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2195 if ( processedEvtSetCursor
&& event
.HasCursor() )
2197 cursor
= event
.GetCursor() ;
2202 // the test for processedEvtSetCursor is here to prevent using m_cursor
2203 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2204 // it - this is a way to say that our cursor shouldn't be used for this
2206 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2216 cursor
= *wxSTANDARD_CURSOR
;
2220 cursor
.MacInstall() ;
2222 return cursor
.Ok() ;
2225 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2229 return m_tooltip
->GetTip() ;
2231 return wxEmptyString
;
2234 void wxWindowMac::Update()
2236 #if TARGET_API_MAC_OSX
2237 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2239 ::Draw1Control( (ControlRef
) m_macControl
) ;
2243 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2245 wxTopLevelWindowMac
* win
= NULL
;
2246 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2249 win
= wxFindWinFromMacWindow( window
) ;
2253 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2257 RgnHandle visRgn
= NewRgn() ;
2258 RgnHandle tempRgn
= NewRgn() ;
2259 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2261 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2262 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2264 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2265 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2274 if ( includeOuterStructures
)
2275 InsetRect( &r
, -3 , -3 ) ;
2276 RectRgn( visRgn
, &r
) ;
2277 if ( !IsTopLevel() )
2279 wxWindow
* child
= this ;
2280 wxWindow
* parent
= child
->GetParent() ;
2285 // we have to find a better clipping algorithm here, in order not to clip things
2286 // positioned like status and toolbar
2287 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2289 size
= parent
->GetSize() ;
2294 size
= parent
->GetClientSize() ;
2295 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2299 parent
->MacWindowToRootWindow( &x
, &y
) ;
2300 MacRootWindowToWindow( &x
, &y
) ;
2302 SetRectRgn( tempRgn
,
2303 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2304 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2305 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2307 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2308 if ( parent
->IsTopLevel() )
2311 parent
= child
->GetParent() ;
2316 wxRegion vis
= visRgn
;
2317 DisposeRgn( visRgn
) ;
2318 DisposeRgn( tempRgn
) ;
2323 This function must not change the updatergn !
2325 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2327 // we let the OS handle root control redraws
2328 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2331 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2332 bool handled
= false ;
2334 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2336 RgnHandle newupdate
= NewRgn() ;
2337 wxSize point
= GetClientSize() ;
2338 wxPoint origin
= GetClientAreaOrigin() ;
2339 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2340 SectRgn( newupdate
, updatergn
, newupdate
) ;
2341 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2342 m_updateRegion
= newupdate
;
2343 DisposeRgn( newupdate
) ;
2346 if ( !EmptyRgn(updatergn
) )
2348 wxWindowDC
dc(this);
2349 if (!EmptyRgn(updatergn
))
2350 dc
.SetClippingRegion(wxRegion(updatergn
));
2352 wxEraseEvent
eevent( GetId(), &dc
);
2353 eevent
.SetEventObject( this );
2354 GetEventHandler()->ProcessEvent( eevent
);
2356 if ( !m_updateRegion
.Empty() )
2358 // paint the window itself
2360 event
.m_timeStamp
= time
;
2361 event
.SetEventObject(this);
2362 handled
= GetEventHandler()->ProcessEvent(event
);
2364 // paint custom borders
2365 wxNcPaintEvent
eventNc( GetId() );
2366 eventNc
.SetEventObject( this );
2367 GetEventHandler()->ProcessEvent( eventNc
);
2373 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2375 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2376 // updatergn is always already clipped to our boundaries
2377 // if we are in compositing mode then it is in relative to the upper left of the control
2378 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2379 // of the toplevel window
2380 // it is in window coordinates, not in client coordinates
2382 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2383 RgnHandle ownUpdateRgn
= NewRgn() ;
2384 CopyRgn( updatergn
, ownUpdateRgn
) ;
2386 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2389 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2390 RgnHandle controlRgn
= NewRgn();
2391 RectRgn( controlRgn
, &bounds
);
2392 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2393 // the window update region
2394 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2395 DisposeRgn( controlRgn
);
2397 //KO: convert ownUpdateRgn to local coordinates
2398 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2401 MacDoRedraw( ownUpdateRgn
, time
) ;
2402 DisposeRgn( ownUpdateRgn
) ;
2406 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2408 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2412 if ( iter
->IsTopLevel() )
2413 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2415 iter
= iter
->GetParent() ;
2417 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2421 void wxWindowMac::MacCreateScrollBars( long style
)
2423 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2425 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2426 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2428 GetClientSize( &width
, &height
) ;
2430 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2431 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2432 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2433 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2435 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2436 vSize
, wxVERTICAL
);
2438 if ( style
& wxVSCROLL
)
2444 m_vScrollBar
->Show(false) ;
2446 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2447 hSize
, wxHORIZONTAL
);
2448 if ( style
& wxHSCROLL
)
2453 m_hScrollBar
->Show(false) ;
2456 // because the create does not take into account the client area origin
2457 MacRepositionScrollBars() ; // we might have a real position shift
2460 void wxWindowMac::MacRepositionScrollBars()
2462 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2463 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2465 // get real client area
2469 GetSize( &width
, &height
) ;
2471 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2472 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2474 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2475 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2476 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2477 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2483 GetSize( &w
, &h
) ;
2485 MacClientToRootWindow( &x
, &y
) ;
2486 MacClientToRootWindow( &w
, &h
) ;
2488 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2490 int totW
= 10000 , totH
= 10000;
2493 if ( iter
->IsTopLevel() )
2495 iter
->GetSize( &totW
, &totH
) ;
2499 iter
= iter
->GetParent() ;
2527 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2531 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2535 bool wxWindowMac::AcceptsFocus() const
2537 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2540 void wxWindowMac::MacSuperChangedPosition()
2542 // only window-absolute structures have to be moved i.e. controls
2544 wxWindowListNode
*node
= GetChildren().GetFirst();
2547 wxWindowMac
*child
= node
->GetData();
2548 child
->MacSuperChangedPosition() ;
2549 node
= node
->GetNext();
2553 void wxWindowMac::MacTopLevelWindowChangedPosition()
2555 // only screen-absolute structures have to be moved i.e. glcanvas
2557 wxWindowListNode
*node
= GetChildren().GetFirst();
2560 wxWindowMac
*child
= node
->GetData();
2561 child
->MacTopLevelWindowChangedPosition() ;
2562 node
= node
->GetNext();
2566 long wxWindowMac::MacGetLeftBorderSize( ) const
2571 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2574 #if wxMAC_USE_THEME_BORDER
2575 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2579 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2582 #if wxMAC_USE_THEME_BORDER
2583 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2587 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2594 long wxWindowMac::MacGetRightBorderSize( ) const
2596 // they are all symmetric in mac themes
2597 return MacGetLeftBorderSize() ;
2600 long wxWindowMac::MacGetTopBorderSize( ) const
2602 // they are all symmetric in mac themes
2603 return MacGetLeftBorderSize() ;
2606 long wxWindowMac::MacGetBottomBorderSize( ) const
2608 // they are all symmetric in mac themes
2609 return MacGetLeftBorderSize() ;
2612 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2614 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2617 // Find the wxWindowMac at the current mouse position, returning the mouse
2619 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2621 pt
= wxGetMousePosition();
2622 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2626 // Get the current mouse position.
2627 wxPoint
wxGetMousePosition()
2630 wxGetMousePosition(& x
, & y
);
2631 return wxPoint(x
, y
);
2634 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2636 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2638 // copied from wxGTK : CS
2639 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2642 // (a) it's a command event and so is propagated to the parent
2643 // (b) under MSW it can be generated from kbd too
2644 // (c) it uses screen coords (because of (a))
2645 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2647 this->ClientToScreen(event
.GetPosition()));
2648 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2651 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2657 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2659 // OS Needs it in tlw content area coordinates
2660 MacClientToRootWindow( &x
, &y
) ;
2664 // OS Needs it in window not client coordinates
2665 wxPoint origin
= GetClientAreaOrigin() ;
2670 SInt16 controlpart
;
2675 short modifiers
= 0;
2677 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2678 modifiers
|= btnState
;
2680 if ( event
.m_shiftDown
)
2681 modifiers
|= shiftKey
;
2683 if ( event
.m_controlDown
)
2684 modifiers
|= controlKey
;
2686 if ( event
.m_altDown
)
2687 modifiers
|= optionKey
;
2689 if ( event
.m_metaDown
)
2690 modifiers
|= cmdKey
;
2692 bool handled
= false ;
2694 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2696 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2697 wxTheApp
->s_lastMouseDown
= 0 ;
2698 if ( controlpart
!= kControlNoPart
)
2700 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2713 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2715 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2718 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2722 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2723 Rect bounds
= { y
, x
, y
+h
, x
+w
};