1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
39 #include "wx/toolbar.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
69 wxWindowMac
* gFocusWindow
= NULL
;
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
75 #endif // __WXUNIVERSAL__/__WXMAC__
77 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 0
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
103 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
105 static const EventTypeSpec eventList
[] =
107 #if TARGET_API_MAC_OSX
108 { kEventClassControl
, kEventControlDraw
} ,
109 { kEventClassControl
, kEventControlVisibilityChanged
} ,
110 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
111 { kEventClassControl
, kEventControlHiliteChanged
} ,
112 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
113 // { kEventClassControl , kEventControlBoundsChanged } ,
121 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
123 OSStatus result
= eventNotHandledErr
;
125 wxMacCarbonEvent
cEvent( event
) ;
127 ControlRef controlRef
;
128 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
130 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
132 switch( GetEventKind( event
) )
134 case kEventControlDraw
:
136 RgnHandle updateRgn
= NULL
;
138 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
139 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
141 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
145 // unfortunately this update region may be incorrect (tree ctrl sample )
146 // so we have to reset it
147 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
149 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
151 #if 0 // in case we would need a coregraphics compliant background erase first
152 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
153 if ( thisWindow
->MacIsUserPane() )
156 err
= HIViewGetBounds( controlRef
, &bounds
);
157 CGContextSetRGBFillColor( cgContext
, 1 , 1 , 1 , 1 );
158 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
159 CGContextFillRect( cgContext
, bounds
);
162 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
165 result
= eventNotHandledErr
;
168 case kEventControlVisibilityChanged
:
169 thisWindow
->MacVisibilityChanged() ;
171 case kEventControlEnabledStateChanged
:
172 thisWindow
->MacEnabledStateChanged() ;
174 case kEventControlHiliteChanged
:
175 thisWindow
->MacHiliteChanged() ;
183 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
185 OSStatus result
= eventNotHandledErr
;
187 switch ( GetEventClass( event
) )
189 case kEventClassControl
:
190 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
198 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
200 // ---------------------------------------------------------------------------
201 // UserPane events for non OSX builds
202 // ---------------------------------------------------------------------------
204 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
206 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
207 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
208 win
->MacControlUserPaneDrawProc(part
) ;
211 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
213 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
214 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
215 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
218 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
220 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
221 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
222 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
225 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
227 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
228 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
229 win
->MacControlUserPaneIdleProc() ;
232 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
234 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
235 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
236 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
239 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
241 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
242 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
243 win
->MacControlUserPaneActivateProc(activating
) ;
246 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
248 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
249 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
250 return win
->MacControlUserPaneFocusProc(action
) ;
253 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
255 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
256 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
257 win
->MacControlUserPaneBackgroundProc(info
) ;
260 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
262 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
265 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
267 return kControlNoPart
;
270 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
272 return kControlNoPart
;
275 void wxWindowMac::MacControlUserPaneIdleProc()
279 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
281 return kControlNoPart
;
284 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
288 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
290 return kControlNoPart
;
293 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
297 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
298 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
299 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
300 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
301 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
302 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
303 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
304 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
306 // ===========================================================================
308 // ===========================================================================
310 wxList
wxWinMacControlList(wxKEY_INTEGER
);
312 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
314 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
317 return (wxControl
*)node
->GetData();
320 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
322 // adding NULL ControlRef is (first) surely a result of an error and
323 // (secondly) breaks native event processing
324 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
326 if ( !wxWinMacControlList
.Find((long)inControl
) )
327 wxWinMacControlList
.Append((long)inControl
, control
);
330 void wxRemoveMacControlAssociation(wxWindow
*control
)
332 wxWinMacControlList
.DeleteObject(control
);
336 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
338 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
340 // we have to setup the brush in the current port and return noErr
341 // or return an error code so that the control manager walks further up the
342 // hierarchy to find a correct background
344 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
346 OSStatus status
= paramErr
;
349 case kControlMsgApplyTextColor
:
351 case kControlMsgSetUpBackground
:
353 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
357 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
361 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
363 // this clipping is only needed for non HIView
365 RgnHandle clip
= NewRgn() ;
368 wx
->MacWindowToRootWindow( &x
,&y
) ;
369 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
370 OffsetRgn( clip
, x
, y
) ;
377 else if ( wx->MacIsUserPane() )
379 // if we don't have a valid brush for such a control, we have to call the
380 // setup of our parent ourselves
381 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
394 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
395 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
399 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
402 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
407 // ----------------------------------------------------------------------------
408 // constructors and such
409 // ----------------------------------------------------------------------------
411 void wxWindowMac::Init()
413 m_backgroundTransparent
= FALSE
;
415 // as all windows are created with WS_VISIBLE style...
418 m_hScrollBar
= NULL
;
419 m_vScrollBar
= NULL
;
420 m_macBackgroundBrush
= wxNullBrush
;
422 m_macControl
= NULL
;
424 m_macIsUserPane
= TRUE
;
426 // make sure all proc ptrs are available
428 if ( gControlUserPaneDrawUPP
== NULL
)
430 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
431 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
432 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
433 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
434 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
435 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
436 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
437 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
439 if ( wxMacLiveScrollbarActionUPP
== NULL
)
441 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
444 if ( wxMacSetupControlBackgroundUPP
== NULL
)
446 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
452 wxWindowMac::~wxWindowMac()
456 m_isBeingDeleted
= TRUE
;
458 #ifndef __WXUNIVERSAL__
459 // VS: make sure there's no wxFrame with last focus set to us:
460 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
462 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
465 if ( frame
->GetLastFocus() == this )
467 frame
->SetLastFocus((wxWindow
*)NULL
);
472 #endif // __WXUNIVERSAL__
474 // wxRemoveMacControlAssociation( this ) ;
475 // If we delete an item, we should initialize the parent panel,
476 // because it could now be invalid.
477 wxWindow
*parent
= GetParent() ;
480 if (parent
->GetDefaultItem() == (wxButton
*) this)
481 parent
->SetDefaultItem(NULL
);
483 if ( (ControlRef
) m_macControl
)
485 // in case the callback might be called during destruction
486 wxRemoveMacControlAssociation( this) ;
487 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
488 ::DisposeControl( (ControlRef
) m_macControl
) ;
489 m_macControl
= NULL
;
492 if ( g_MacLastWindow
== this )
494 g_MacLastWindow
= NULL
;
497 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
500 if ( frame
->GetLastFocus() == this )
501 frame
->SetLastFocus( NULL
) ;
504 if ( gFocusWindow
== this )
506 gFocusWindow
= NULL
;
511 // delete our drop target if we've got one
512 #if wxUSE_DRAG_AND_DROP
513 if ( m_dropTarget
!= NULL
)
518 #endif // wxUSE_DRAG_AND_DROP
523 void wxWindowMac::MacInstallEventHandler()
525 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
526 GetEventTypeCount(eventList
), eventList
, this,
527 (EventHandlerRef
*)&m_macControlEventHandler
);
532 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
536 const wxString
& name
)
538 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
540 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
543 parent
->AddChild(this);
545 m_windowVariant
= parent
->GetWindowVariant() ;
547 if ( m_macIsUserPane
)
549 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
551 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
/*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
553 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
555 MacPostControlCreate(pos
,size
) ;
556 #if !TARGET_API_MAC_OSX
557 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
558 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
559 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
560 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
561 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
562 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
563 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
564 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
565 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
566 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
567 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
568 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
569 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
570 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
571 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
572 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
575 #ifndef __WXUNIVERSAL__
576 // Don't give scrollbars to wxControls unless they ask for them
577 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
578 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
580 MacCreateScrollBars( style
) ;
584 wxWindowCreateEvent
event(this);
585 GetEventHandler()->AddPendingEvent(event
);
590 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
592 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
594 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
595 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
597 MacInstallEventHandler();
599 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
600 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
601 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
603 // adjust font, controlsize etc
604 DoSetWindowVariant( m_windowVariant
) ;
606 #if !TARGET_API_MAC_OSX
607 // eventually we can fix some clipping issues be reactivating this hook
608 //if ( m_macIsUserPane )
609 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
612 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
614 wxSize new_size
= size
;
615 if (!m_macIsUserPane
)
617 wxSize
best_size( DoGetBestSize() );
620 new_size
.x
= best_size
.x
;
623 new_size
.y
= best_size
.y
;
625 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
628 SetCursor( *wxSTANDARD_CURSOR
) ;
632 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
634 wxASSERT( m_macControl
!= NULL
) ;
636 m_windowVariant
= variant
;
639 ThemeFontID themeFont
= kThemeSystemFont
;
641 // we will get that from the settings later
642 // and make this NORMAL later, but first
643 // we have a few calculations that we must fix
647 case wxWINDOW_VARIANT_NORMAL
:
648 size
= kControlSizeNormal
;
649 themeFont
= kThemeSystemFont
;
651 case wxWINDOW_VARIANT_SMALL
:
652 size
= kControlSizeSmall
;
653 themeFont
= kThemeSmallSystemFont
;
655 case wxWINDOW_VARIANT_MINI
:
656 if (UMAGetSystemVersion() >= 0x1030 )
658 // not always defined in the headers
664 size
= kControlSizeSmall
;
665 themeFont
= kThemeSmallSystemFont
;
668 case wxWINDOW_VARIANT_LARGE
:
669 size
= kControlSizeLarge
;
670 themeFont
= kThemeSystemFont
;
673 wxFAIL_MSG(_T("unexpected window variant"));
676 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
679 font
.MacCreateThemeFont( themeFont
) ;
683 void wxWindowMac::MacUpdateControlFont()
685 ControlFontStyleRec fontStyle
;
686 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
688 switch( m_font
.MacGetThemeFontID() )
690 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
691 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
692 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
693 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
695 fontStyle
.flags
= kControlUseFontMask
;
699 fontStyle
.font
= m_font
.MacGetFontNum() ;
700 fontStyle
.style
= m_font
.MacGetFontStyle() ;
701 fontStyle
.size
= m_font
.MacGetFontSize() ;
702 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
705 fontStyle
.just
= teJustLeft
;
706 fontStyle
.flags
|= kControlUseJustMask
;
707 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
708 fontStyle
.just
= teJustCenter
;
709 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
710 fontStyle
.just
= teJustRight
;
713 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
714 fontStyle
.flags
|= kControlUseForeColorMask
;
716 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
720 bool wxWindowMac::SetFont(const wxFont
& font
)
722 bool retval
= !wxWindowBase::SetFont( font
) ;
724 MacUpdateControlFont() ;
729 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
731 if ( !wxWindowBase::SetForegroundColour(col
) )
734 MacUpdateControlFont() ;
739 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
741 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
745 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
747 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
749 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
751 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
755 brush
.SetColour( col
) ;
757 MacSetBackgroundBrush( brush
) ;
759 MacUpdateControlFont() ;
765 bool wxWindowMac::MacCanFocus() const
767 wxASSERT( m_macControl
!= NULL
) ;
773 void wxWindowMac::SetFocus()
775 if ( gFocusWindow
== this )
778 if ( AcceptsFocus() )
784 if ( gFocusWindow
->m_caret
)
786 gFocusWindow
->m_caret
->OnKillFocus();
788 #endif // wxUSE_CARET
789 #ifndef __WXUNIVERSAL__
790 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
791 // TODO we must use the built-in focusing
792 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
794 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
795 control
->MacRedrawControl() ;
798 // Without testing the window id, for some reason
799 // a kill focus event can still be sent to
800 // the control just being focussed.
801 int thisId
= this->m_windowId
;
802 int gFocusWindowId
= gFocusWindow
->m_windowId
;
803 if (gFocusWindowId
!= thisId
)
805 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
806 event
.SetEventObject(gFocusWindow
);
807 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
810 gFocusWindow
= this ;
816 m_caret
->OnSetFocus();
818 #endif // wxUSE_CARET
819 // panel wants to track the window which was the last to have focus in it
820 wxChildFocusEvent
eventFocus(this);
821 GetEventHandler()->ProcessEvent(eventFocus
);
823 #ifndef __WXUNIVERSAL__
824 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
825 if ( control
&& control
->GetHandle() )
827 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
830 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
831 event
.SetEventObject(this);
832 GetEventHandler()->ProcessEvent(event
) ;
838 void wxWindowMac::DoCaptureMouse()
840 wxTheApp
->s_captureWindow
= this ;
843 wxWindow
* wxWindowBase::GetCapture()
845 return wxTheApp
->s_captureWindow
;
848 void wxWindowMac::DoReleaseMouse()
850 wxTheApp
->s_captureWindow
= NULL
;
853 #if wxUSE_DRAG_AND_DROP
855 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
857 if ( m_dropTarget
!= 0 ) {
861 m_dropTarget
= pDropTarget
;
862 if ( m_dropTarget
!= 0 )
870 // Old style file-manager drag&drop
871 void wxWindowMac::DragAcceptFiles(bool accept
)
876 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
877 int& w
, int& h
) const
880 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
885 w
= bounds
.right
- bounds
.left
;
886 h
= bounds
.bottom
- bounds
.top
;
888 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
891 Point tlworigin
= { 0 , 0 } ;
894 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
895 ::LocalToGlobal( &tlworigin
) ;
902 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
905 int& w
, int& h
) const
909 // todo the default calls may be used as soon as PostCreateControl Is moved here
910 w
= size
.x
; // WidthDefault( size.x );
911 h
= size
.y
; // HeightDefault( size.y ) ;
912 #if !TARGET_API_MAC_OSX
913 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
920 void wxWindowMac::DoGetSize(int *x
, int *y
) const
922 #if TARGET_API_MAC_OSX
923 int x1
, y1
, w1
,h1
;
924 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
930 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
931 if(x
) *x
= bounds
.right
- bounds
.left
;
932 if(y
) *y
= bounds
.bottom
- bounds
.top
;
936 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
938 #if TARGET_API_MAC_OSX
939 int x1
, y1
, w1
,h1
;
940 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
943 wxWindow
*parent
= GetParent();
946 wxPoint
pt(parent
->GetClientAreaOrigin());
955 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
956 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
958 int xx
= bounds
.left
;
959 int yy
= bounds
.top
;
961 if ( !GetParent()->IsTopLevel() )
963 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
969 wxPoint
pt(GetParent()->GetClientAreaOrigin());
978 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
980 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
982 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
985 Point localwhere
= {0,0} ;
987 if(x
) localwhere
.h
= * x
;
988 if(y
) localwhere
.v
= * y
;
990 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
991 ::GlobalToLocal( &localwhere
) ;
992 if(x
) *x
= localwhere
.h
;
993 if(y
) *y
= localwhere
.v
;
996 MacRootWindowToWindow( x
, y
) ;
998 wxPoint origin
= GetClientAreaOrigin() ;
999 if(x
) *x
-= origin
.x
;
1000 if(y
) *y
-= origin
.y
;
1003 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1005 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1006 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1008 wxPoint origin
= GetClientAreaOrigin() ;
1009 if(x
) *x
+= origin
.x
;
1010 if(y
) *y
+= origin
.y
;
1012 MacWindowToRootWindow( x
, y
) ;
1015 Point localwhere
= { 0,0 };
1016 if(x
) localwhere
.h
= * x
;
1017 if(y
) localwhere
.v
= * y
;
1019 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1020 ::LocalToGlobal( &localwhere
) ;
1021 if(x
) *x
= localwhere
.h
;
1022 if(y
) *y
= localwhere
.v
;
1026 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1028 wxPoint origin
= GetClientAreaOrigin() ;
1029 if(x
) *x
+= origin
.x
;
1030 if(y
) *y
+= origin
.y
;
1032 MacWindowToRootWindow( x
, y
) ;
1035 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1037 MacRootWindowToWindow( x
, y
) ;
1039 wxPoint origin
= GetClientAreaOrigin() ;
1040 if(x
) *x
-= origin
.x
;
1041 if(y
) *y
-= origin
.y
;
1044 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1046 #if TARGET_API_MAC_OSX
1048 if ( x
) pt
.x
= *x
;
1049 if ( y
) pt
.y
= *y
;
1051 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1053 if ( x
) *x
= (int) pt
.x
;
1054 if ( y
) *y
= (int) pt
.y
;
1056 if ( !IsTopLevel() )
1059 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1060 if(x
) *x
+= bounds
.left
;
1061 if(y
) *y
+= bounds
.top
;
1066 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1071 MacWindowToRootWindow( &x1
, &y1
) ;
1076 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1078 #if TARGET_API_MAC_OSX
1080 if ( x
) pt
.x
= *x
;
1081 if ( y
) pt
.y
= *y
;
1083 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1085 if ( x
) *x
= (int) pt
.x
;
1086 if ( y
) *y
= (int) pt
.y
;
1088 if ( !IsTopLevel() )
1091 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1092 if(x
) *x
-= bounds
.left
;
1093 if(y
) *y
-= bounds
.top
;
1098 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1103 MacRootWindowToWindow( &x1
, &y1
) ;
1108 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1110 wxSize sizeTotal
= size
;
1112 RgnHandle rgn
= NewRgn() ;
1116 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1118 GetRegionBounds( rgn
, &content
) ;
1123 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1126 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1127 #if !TARGET_API_MAC_OSX
1128 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1131 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1132 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1134 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1135 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1141 // Get size *available for subwindows* i.e. excluding menu bar etc.
1142 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1146 RgnHandle rgn
= NewRgn() ;
1148 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1150 GetRegionBounds( rgn
, &content
) ;
1155 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1157 #if !TARGET_API_MAC_OSX
1159 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1160 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1162 ww
= content
.right
- content
.left
;
1163 hh
= content
.bottom
- content
.top
;
1165 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1166 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1168 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1174 GetSize( &w
, &h
) ;
1176 MacClientToRootWindow( &x1
, &y1
) ;
1177 MacClientToRootWindow( &w
, &h
) ;
1179 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1181 int totW
= 10000 , totH
= 10000;
1184 if ( iter
->IsTopLevel() )
1186 iter
->GetSize( &totW
, &totH
) ;
1190 iter
= iter
->GetParent() ;
1193 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1195 hh
-= MAC_SCROLLBAR_SIZE
;
1201 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1203 ww
-= MAC_SCROLLBAR_SIZE
;
1215 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1217 if (m_cursor
== cursor
)
1220 if (wxNullCursor
== cursor
)
1222 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1227 if ( ! wxWindowBase::SetCursor( cursor
) )
1231 wxASSERT_MSG( m_cursor
.Ok(),
1232 wxT("cursor must be valid after call to the base version"));
1236 TODO why do we have to use current coordinates ?
1239 wxWindowMac *mouseWin ;
1242 // Change the cursor NOW if we're within the correct window
1245 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1247 if ( mouseWin == this && !wxIsBusy() )
1249 m_cursor.MacInstall() ;
1255 m_cursor
.MacInstall() ;
1262 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1264 menu
->SetInvokingWindow(this);
1266 ClientToScreen( &x
, &y
) ;
1268 menu
->MacBeforeDisplay( true ) ;
1269 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1270 if ( HiWord(menuResult
) != 0 )
1273 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1274 wxMenuItem
* item
= NULL
;
1276 item
= menu
->FindItem(id
, &realmenu
) ;
1277 if (item
->IsCheckable())
1279 item
->Check( !item
->IsChecked() ) ;
1281 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1283 menu
->MacAfterDisplay( true ) ;
1285 menu
->SetInvokingWindow(NULL
);
1291 // ----------------------------------------------------------------------------
1293 // ----------------------------------------------------------------------------
1297 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1299 wxWindowBase::DoSetToolTip(tooltip
);
1302 m_tooltip
->SetWindow(this);
1305 #endif // wxUSE_TOOLTIPS
1307 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1309 int former_x
, former_y
, former_w
, former_h
;
1310 #if !TARGET_API_MAC_OSX
1311 DoGetPosition( &former_x
, &former_y
) ;
1312 DoGetSize( &former_w
, &former_h
) ;
1314 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1317 int actualWidth
= width
;
1318 int actualHeight
= height
;
1322 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1323 actualWidth
= m_minWidth
;
1324 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1325 actualHeight
= m_minHeight
;
1326 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1327 actualWidth
= m_maxWidth
;
1328 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1329 actualHeight
= m_maxHeight
;
1331 bool doMove
= false ;
1332 bool doResize
= false ;
1334 if ( actualX
!= former_x
|| actualY
!= former_y
)
1338 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1343 if ( doMove
|| doResize
)
1345 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1346 #if TARGET_API_MAC_OSX
1347 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1350 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1352 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1354 MacRepositionScrollBars() ;
1357 wxPoint
point(actualX
,actualY
);
1358 wxMoveEvent
event(point
, m_windowId
);
1359 event
.SetEventObject(this);
1360 GetEventHandler()->ProcessEvent(event
) ;
1364 MacRepositionScrollBars() ;
1365 wxSize
size(actualWidth
, actualHeight
);
1366 wxSizeEvent
event(size
, m_windowId
);
1367 event
.SetEventObject(this);
1368 GetEventHandler()->ProcessEvent(event
);
1374 wxSize
wxWindowMac::DoGetBestSize() const
1377 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1378 short baselineoffset ;
1379 int bestWidth, bestHeight ;
1380 ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ;
1382 if ( EmptyRect( &bestsize ) )
1385 bestsize.left = bestsize.top = 0 ;
1386 bestsize.right = 16 ;
1387 bestsize.bottom = 16 ;
1388 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1390 bestsize.bottom = 16 ;
1392 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1394 bestsize.bottom = 24 ;
1398 // return wxWindowBase::DoGetBestSize() ;
1402 bestWidth = bestsize.right - bestsize.left ;
1403 bestHeight = bestsize.bottom - bestsize.top ;
1404 if ( bestHeight < 10 )
1407 return wxSize(bestWidth, bestHeight);
1409 return wxWindowBase::DoGetBestSize() ;
1413 // set the size of the window: if the dimensions are positive, just use them,
1414 // but if any of them is equal to -1, it means that we must find the value for
1415 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1416 // which case -1 is a valid value for x and y)
1418 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1419 // the width/height to best suit our contents, otherwise we reuse the current
1421 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1423 // get the current size and position...
1424 int currentX
, currentY
;
1425 GetPosition(¤tX
, ¤tY
);
1427 int currentW
,currentH
;
1428 GetSize(¤tW
, ¤tH
);
1430 // ... and don't do anything (avoiding flicker) if it's already ok
1431 if ( x
== currentX
&& y
== currentY
&&
1432 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1435 MacRepositionScrollBars() ; // we might have a real position shift
1439 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1441 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1444 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1446 wxSize
size(-1, -1);
1449 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1451 size
= DoGetBestSize();
1456 // just take the current one
1463 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1467 size
= DoGetBestSize();
1469 //else: already called DoGetBestSize() above
1475 // just take the current one
1480 DoMoveWindow(x
, y
, width
, height
);
1484 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1486 RgnHandle rgn
= NewRgn() ;
1488 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1489 GetRegionBounds( rgn
, &content
) ;
1491 #if !TARGET_API_MAC_OSX
1493 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1494 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1497 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1500 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1502 if ( clientheight
!= -1 || clientheight
!= -1 )
1504 int currentclientwidth
, currentclientheight
;
1505 int currentwidth
, currentheight
;
1507 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1508 GetSize( ¤twidth
, ¤theight
) ;
1510 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1511 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1515 void wxWindowMac::SetTitle(const wxString
& title
)
1517 m_label
= wxStripMenuCodes(title
) ;
1521 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1526 wxString
wxWindowMac::GetTitle() const
1531 bool wxWindowMac::Show(bool show
)
1533 if ( !wxWindowBase::Show(show
) )
1536 // TODO use visibilityChanged Carbon Event for OSX
1537 bool former
= MacIsReallyShown() ;
1539 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1540 if ( former
!= MacIsReallyShown() )
1541 MacPropagateVisibilityChanged() ;
1545 bool wxWindowMac::Enable(bool enable
)
1547 wxASSERT( m_macControl
!= NULL
) ;
1548 if ( !wxWindowBase::Enable(enable
) )
1551 bool former
= MacIsReallyEnabled() ;
1553 EnableControl( (ControlRef
) m_macControl
) ;
1555 DisableControl( (ControlRef
) m_macControl
) ;
1557 if ( former
!= MacIsReallyEnabled() )
1558 MacPropagateEnabledStateChanged() ;
1563 // status change propagations (will be not necessary for OSX later )
1566 void wxWindowMac::MacPropagateVisibilityChanged()
1568 #if !TARGET_API_MAC_OSX
1569 MacVisibilityChanged() ;
1571 wxWindowListNode
*node
= GetChildren().GetFirst();
1574 wxWindowMac
*child
= node
->GetData();
1575 if ( child
->IsShown() )
1576 child
->MacPropagateVisibilityChanged( ) ;
1577 node
= node
->GetNext();
1582 void wxWindowMac::MacPropagateEnabledStateChanged( )
1584 #if !TARGET_API_MAC_OSX
1585 MacEnabledStateChanged() ;
1587 wxWindowListNode
*node
= GetChildren().GetFirst();
1590 wxWindowMac
*child
= node
->GetData();
1591 if ( child
->IsEnabled() )
1592 child
->MacPropagateEnabledStateChanged() ;
1593 node
= node
->GetNext();
1598 void wxWindowMac::MacPropagateHiliteChanged( )
1600 #if !TARGET_API_MAC_OSX
1601 MacHiliteChanged() ;
1603 wxWindowListNode
*node
= GetChildren().GetFirst();
1606 wxWindowMac
*child
= node
->GetData();
1607 // if ( child->IsEnabled() )
1608 child
->MacPropagateHiliteChanged() ;
1609 node
= node
->GetNext();
1615 // status change notifications
1618 void wxWindowMac::MacVisibilityChanged()
1622 void wxWindowMac::MacHiliteChanged()
1626 void wxWindowMac::MacEnabledStateChanged()
1631 // status queries on the inherited window's state
1634 bool wxWindowMac::MacIsReallyShown()
1636 // only under OSX the visibility of the TLW is taken into account
1637 #if TARGET_API_MAC_OSX
1638 return IsControlVisible( (ControlRef
) m_macControl
) ;
1640 wxWindow
* win
= this ;
1641 while( win
->IsShown() )
1643 if ( win
->IsTopLevel() )
1646 win
= win
->GetParent() ;
1655 bool wxWindowMac::MacIsReallyEnabled()
1657 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1660 bool wxWindowMac::MacIsReallyHilited()
1662 return IsControlActive( (ControlRef
) m_macControl
) ;
1669 int wxWindowMac::GetCharHeight() const
1671 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1672 return dc
.GetCharHeight() ;
1675 int wxWindowMac::GetCharWidth() const
1677 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1678 return dc
.GetCharWidth() ;
1681 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1682 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1684 const wxFont
*fontToUse
= theFont
;
1686 fontToUse
= &m_font
;
1688 wxClientDC
dc( (wxWindowMac
*) this ) ;
1690 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1691 if ( externalLeading
)
1692 *externalLeading
= le
;
1702 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1703 * we always intersect with the entire window, not only with the client area
1706 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1708 #if TARGET_API_MAC_OSX
1710 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1713 RgnHandle update
= NewRgn() ;
1714 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1715 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1716 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1719 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1721 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1722 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1725 if ( MacGetTopLevelWindow() == NULL )
1728 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1731 wxPoint client = GetClientAreaOrigin();
1734 int x2 = m_width - client.x;
1735 int y2 = m_height - client.y;
1737 if (IsKindOf( CLASSINFO(wxButton)))
1739 // buttons have an "aura"
1746 Rect clientrect = { y1, x1, y2, x2 };
1750 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1751 SectRect( &clientrect , &r , &clientrect ) ;
1754 if ( !EmptyRect( &clientrect ) )
1756 int top = 0 , left = 0 ;
1758 MacClientToRootWindow( &left , &top ) ;
1759 OffsetRect( &clientrect , left , top ) ;
1761 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1767 void wxWindowMac::MacRedrawControl()
1770 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1772 #if TARGET_API_MAC_CARBON
1775 wxClientDC dc(this) ;
1776 wxMacPortSetter helper(&dc) ;
1777 wxMacWindowClipper clipper(this) ;
1778 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1779 UMADrawControl( (ControlRef) m_macControl ) ;
1786 void wxWindowMac::OnPaint(wxPaintEvent& event)
1788 // why don't we skip that here ?
1792 wxWindowMac
*wxGetActiveWindow()
1794 // actually this is a windows-only concept
1798 // Coordinates relative to the window
1799 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1801 // We really don't move the mouse programmatically under Mac.
1804 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1806 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1811 event
.GetDC()->Clear() ;
1814 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1816 wxWindowDC
dc(this) ;
1817 wxMacPortSetter
helper(&dc
) ;
1819 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1822 int wxWindowMac::GetScrollPos(int orient
) const
1824 if ( orient
== wxHORIZONTAL
)
1827 return m_hScrollBar
->GetThumbPosition() ;
1832 return m_vScrollBar
->GetThumbPosition() ;
1837 // This now returns the whole range, not just the number
1838 // of positions that we can scroll.
1839 int wxWindowMac::GetScrollRange(int orient
) const
1841 if ( orient
== wxHORIZONTAL
)
1844 return m_hScrollBar
->GetRange() ;
1849 return m_vScrollBar
->GetRange() ;
1854 int wxWindowMac::GetScrollThumb(int orient
) const
1856 if ( orient
== wxHORIZONTAL
)
1859 return m_hScrollBar
->GetThumbSize() ;
1864 return m_vScrollBar
->GetThumbSize() ;
1869 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1871 if ( orient
== wxHORIZONTAL
)
1874 m_hScrollBar
->SetThumbPosition( pos
) ;
1879 m_vScrollBar
->SetThumbPosition( pos
) ;
1883 void wxWindowMac::MacPaintBorders( int left
, int top
)
1889 wxGetOsVersion( &major
, &minor
);
1891 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1892 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1894 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1895 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1896 // OS X has lighter border edges than classic:
1899 darkShadow
.red
= 0x8E8E;
1900 darkShadow
.green
= 0x8E8E;
1901 darkShadow
.blue
= 0x8E8E;
1902 lightShadow
.red
= 0xBDBD;
1903 lightShadow
.green
= 0xBDBD;
1904 lightShadow
.blue
= 0xBDBD;
1910 GetSize( &w
, &h
) ;
1911 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1913 #if wxMAC_USE_THEME_BORDER
1914 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1917 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1918 InsetRect( &rect , border , border );
1919 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1922 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1924 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1925 RGBForeColor( &face
);
1926 MoveTo( left
+ 0 , top
+ h
- 2 );
1927 LineTo( left
+ 0 , top
+ 0 );
1928 LineTo( left
+ w
- 2 , top
+ 0 );
1930 MoveTo( left
+ 2 , top
+ h
- 3 );
1931 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1932 LineTo( left
+ w
- 3 , top
+ 2 );
1934 RGBForeColor( sunken
? &face
: &darkShadow
);
1935 MoveTo( left
+ 0 , top
+ h
- 1 );
1936 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1937 LineTo( left
+ w
- 1 , top
+ 0 );
1939 RGBForeColor( sunken
? &lightShadow
: &white
);
1940 MoveTo( left
+ 1 , top
+ h
- 3 );
1941 LineTo( left
+ 1, top
+ 1 );
1942 LineTo( left
+ w
- 3 , top
+ 1 );
1944 RGBForeColor( sunken
? &white
: &lightShadow
);
1945 MoveTo( left
+ 1 , top
+ h
- 2 );
1946 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1947 LineTo( left
+ w
- 2 , top
+ 1 );
1949 RGBForeColor( sunken
? &darkShadow
: &face
);
1950 MoveTo( left
+ 2 , top
+ h
- 4 );
1951 LineTo( left
+ 2 , top
+ 2 );
1952 LineTo( left
+ w
- 4 , top
+ 2 );
1955 else if (HasFlag(wxSIMPLE_BORDER
))
1957 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1958 RGBForeColor( &darkShadow
) ;
1959 FrameRect( &rect
) ;
1963 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1965 if ( child
== m_hScrollBar
)
1966 m_hScrollBar
= NULL
;
1967 if ( child
== m_vScrollBar
)
1968 m_vScrollBar
= NULL
;
1970 wxWindowBase::RemoveChild( child
) ;
1973 // New function that will replace some of the above.
1974 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1975 int range
, bool refresh
)
1977 if ( orient
== wxHORIZONTAL
)
1981 if ( range
== 0 || thumbVisible
>= range
)
1983 if ( m_hScrollBar
->IsShown() )
1984 m_hScrollBar
->Show(false) ;
1988 if ( !m_hScrollBar
->IsShown() )
1989 m_hScrollBar
->Show(true) ;
1990 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1998 if ( range
== 0 || thumbVisible
>= range
)
2000 if ( m_vScrollBar
->IsShown() )
2001 m_vScrollBar
->Show(false) ;
2005 if ( !m_vScrollBar
->IsShown() )
2006 m_vScrollBar
->Show(true) ;
2007 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2011 MacRepositionScrollBars() ;
2014 // Does a physical scroll
2015 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2017 if( dx
== 0 && dy
==0 )
2022 wxClientDC
dc(this) ;
2023 wxMacPortSetter
helper(&dc
) ;
2025 int width
, height
;
2026 GetClientSize( &width
, &height
) ;
2033 // TODO take out the boundaries
2034 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2036 RgnHandle updateRgn
= NewRgn() ;
2039 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2040 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2041 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2043 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2045 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2046 // but it seems the update only refreshes the background of the control, rather than calling
2047 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2048 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2051 // we also have to scroll the update rgn in this rectangle
2052 // in order not to loose updates
2054 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2055 RgnHandle formerUpdateRgn
= NewRgn() ;
2056 RgnHandle scrollRgn
= NewRgn() ;
2057 RectRgn( scrollRgn
, &scrollrect
) ;
2058 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2060 LocalToGlobal( &pt
) ;
2061 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2062 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2063 if ( !EmptyRgn( formerUpdateRgn
) )
2065 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2066 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2067 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2069 InvalWindowRgn(rootWindow
, updateRgn
) ;
2070 DisposeRgn( updateRgn
) ;
2071 DisposeRgn( formerUpdateRgn
) ;
2072 DisposeRgn( scrollRgn
) ;
2076 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2078 wxWindowMac
*child
= node
->GetData();
2079 if (child
== m_vScrollBar
) continue;
2080 if (child
== m_hScrollBar
) continue;
2081 if (child
->IsTopLevel()) continue;
2084 child
->GetPosition( &x
, &y
);
2086 child
->GetSize( &w
, &h
);
2090 if (rect
->Intersects(rc
))
2091 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2095 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2099 // TODO remove, was moved higher up Update() ;
2103 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2105 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2107 wxScrollWinEvent wevent
;
2108 wevent
.SetPosition(event
.GetPosition());
2109 wevent
.SetOrientation(event
.GetOrientation());
2110 wevent
.m_eventObject
= this;
2112 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2113 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2114 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2115 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2116 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2117 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2118 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2119 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2120 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2121 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2122 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2123 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2124 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2125 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2126 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2127 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2129 GetEventHandler()->ProcessEvent(wevent
);
2133 // Get the window with the focus
2134 wxWindowMac
*wxWindowBase::FindFocus()
2136 return gFocusWindow
;
2139 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2141 // panel wants to track the window which was the last to have focus in it,
2142 // so we want to set ourselves as the window which last had focus
2144 // notice that it's also important to do it upwards the tree becaus
2145 // otherwise when the top level panel gets focus, it won't set it back to
2146 // us, but to some other sibling
2148 // CS:don't know if this is still needed:
2149 //wxChildFocusEvent eventFocus(this);
2150 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2155 void wxWindowMac::OnInternalIdle()
2157 // This calls the UI-update mechanism (querying windows for
2158 // menu/toolbar/control state information)
2159 if (wxUpdateUIEvent::CanUpdate(this))
2160 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2163 // Raise the window to the top of the Z order
2164 void wxWindowMac::Raise()
2168 // Lower the window to the bottom of the Z order
2169 void wxWindowMac::Lower()
2174 // static wxWindow *gs_lastWhich = NULL;
2176 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2178 // first trigger a set cursor event
2180 wxPoint clientorigin
= GetClientAreaOrigin() ;
2181 wxSize clientsize
= GetClientSize() ;
2183 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2185 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2187 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2188 if ( processedEvtSetCursor
&& event
.HasCursor() )
2190 cursor
= event
.GetCursor() ;
2195 // the test for processedEvtSetCursor is here to prevent using m_cursor
2196 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2197 // it - this is a way to say that our cursor shouldn't be used for this
2199 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2209 cursor
= *wxSTANDARD_CURSOR
;
2213 cursor
.MacInstall() ;
2215 return cursor
.Ok() ;
2218 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2222 return m_tooltip
->GetTip() ;
2224 return wxEmptyString
;
2227 void wxWindowMac::Update()
2229 #if TARGET_API_MAC_OSX
2230 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2232 ::Draw1Control( (ControlRef
) m_macControl
) ;
2236 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2238 wxTopLevelWindowMac
* win
= NULL
;
2239 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2242 win
= wxFindWinFromMacWindow( window
) ;
2246 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2250 RgnHandle visRgn
= NewRgn() ;
2251 RgnHandle tempRgn
= NewRgn() ;
2252 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2254 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2255 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2257 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2258 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2267 if ( includeOuterStructures
)
2268 InsetRect( &r
, -3 , -3 ) ;
2269 RectRgn( visRgn
, &r
) ;
2270 if ( !IsTopLevel() )
2272 wxWindow
* child
= this ;
2273 wxWindow
* parent
= child
->GetParent() ;
2278 // we have to find a better clipping algorithm here, in order not to clip things
2279 // positioned like status and toolbar
2280 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2282 size
= parent
->GetSize() ;
2287 size
= parent
->GetClientSize() ;
2288 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2292 parent
->MacWindowToRootWindow( &x
, &y
) ;
2293 MacRootWindowToWindow( &x
, &y
) ;
2295 SetRectRgn( tempRgn
,
2296 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2297 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2298 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2300 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2301 if ( parent
->IsTopLevel() )
2304 parent
= child
->GetParent() ;
2309 wxRegion vis
= visRgn
;
2310 DisposeRgn( visRgn
) ;
2311 DisposeRgn( tempRgn
) ;
2316 This function must not change the updatergn !
2318 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2320 // we let the OS handle root control redraws
2321 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2324 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2325 bool handled
= false ;
2327 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2329 RgnHandle newupdate
= NewRgn() ;
2330 wxSize point
= GetClientSize() ;
2331 wxPoint origin
= GetClientAreaOrigin() ;
2332 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2333 SectRgn( newupdate
, updatergn
, newupdate
) ;
2334 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2335 m_updateRegion
= newupdate
;
2336 DisposeRgn( newupdate
) ;
2339 if ( !EmptyRgn(updatergn
) )
2341 wxWindowDC
dc(this);
2342 if (!EmptyRgn(updatergn
))
2343 dc
.SetClippingRegion(wxRegion(updatergn
));
2345 wxEraseEvent
eevent( GetId(), &dc
);
2346 eevent
.SetEventObject( this );
2347 GetEventHandler()->ProcessEvent( eevent
);
2349 if ( !m_updateRegion
.Empty() )
2351 // paint the window itself
2353 event
.m_timeStamp
= time
;
2354 event
.SetEventObject(this);
2355 handled
= GetEventHandler()->ProcessEvent(event
);
2357 // paint custom borders
2358 wxNcPaintEvent
eventNc( GetId() );
2359 eventNc
.SetEventObject( this );
2360 GetEventHandler()->ProcessEvent( eventNc
);
2366 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2368 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2369 // updatergn is always already clipped to our boundaries
2370 // if we are in compositing mode then it is in relative to the upper left of the control
2371 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2372 // of the toplevel window
2373 // it is in window coordinates, not in client coordinates
2375 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2376 RgnHandle ownUpdateRgn
= NewRgn() ;
2377 CopyRgn( updatergn
, ownUpdateRgn
) ;
2379 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2382 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2383 RgnHandle controlRgn
= NewRgn();
2384 RectRgn( controlRgn
, &bounds
);
2385 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2386 // the window update region
2387 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2388 DisposeRgn( controlRgn
);
2390 //KO: convert ownUpdateRgn to local coordinates
2391 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2394 MacDoRedraw( ownUpdateRgn
, time
) ;
2395 DisposeRgn( ownUpdateRgn
) ;
2399 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2401 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2405 if ( iter
->IsTopLevel() )
2406 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2408 iter
= iter
->GetParent() ;
2410 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2414 void wxWindowMac::MacCreateScrollBars( long style
)
2416 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2418 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2419 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2421 GetClientSize( &width
, &height
) ;
2423 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2424 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2425 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2426 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2428 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2429 vSize
, wxVERTICAL
);
2431 if ( style
& wxVSCROLL
)
2437 m_vScrollBar
->Show(false) ;
2439 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2440 hSize
, wxHORIZONTAL
);
2441 if ( style
& wxHSCROLL
)
2446 m_hScrollBar
->Show(false) ;
2449 // because the create does not take into account the client area origin
2450 MacRepositionScrollBars() ; // we might have a real position shift
2453 void wxWindowMac::MacRepositionScrollBars()
2455 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2456 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2458 // get real client area
2462 GetSize( &width
, &height
) ;
2464 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2465 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2467 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2468 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2469 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2470 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2476 GetSize( &w
, &h
) ;
2478 MacClientToRootWindow( &x
, &y
) ;
2479 MacClientToRootWindow( &w
, &h
) ;
2481 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2483 int totW
= 10000 , totH
= 10000;
2486 if ( iter
->IsTopLevel() )
2488 iter
->GetSize( &totW
, &totH
) ;
2492 iter
= iter
->GetParent() ;
2520 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2524 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2528 bool wxWindowMac::AcceptsFocus() const
2530 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2533 void wxWindowMac::MacSuperChangedPosition()
2535 // only window-absolute structures have to be moved i.e. controls
2537 wxWindowListNode
*node
= GetChildren().GetFirst();
2540 wxWindowMac
*child
= node
->GetData();
2541 child
->MacSuperChangedPosition() ;
2542 node
= node
->GetNext();
2546 void wxWindowMac::MacTopLevelWindowChangedPosition()
2548 // only screen-absolute structures have to be moved i.e. glcanvas
2550 wxWindowListNode
*node
= GetChildren().GetFirst();
2553 wxWindowMac
*child
= node
->GetData();
2554 child
->MacTopLevelWindowChangedPosition() ;
2555 node
= node
->GetNext();
2559 long wxWindowMac::MacGetLeftBorderSize( ) const
2564 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2567 #if wxMAC_USE_THEME_BORDER
2568 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2572 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2575 #if wxMAC_USE_THEME_BORDER
2576 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2580 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2587 long wxWindowMac::MacGetRightBorderSize( ) const
2589 // they are all symmetric in mac themes
2590 return MacGetLeftBorderSize() ;
2593 long wxWindowMac::MacGetTopBorderSize( ) const
2595 // they are all symmetric in mac themes
2596 return MacGetLeftBorderSize() ;
2599 long wxWindowMac::MacGetBottomBorderSize( ) const
2601 // they are all symmetric in mac themes
2602 return MacGetLeftBorderSize() ;
2605 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2607 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2610 // Find the wxWindowMac at the current mouse position, returning the mouse
2612 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2614 pt
= wxGetMousePosition();
2615 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2619 // Get the current mouse position.
2620 wxPoint
wxGetMousePosition()
2623 wxGetMousePosition(& x
, & y
);
2624 return wxPoint(x
, y
);
2627 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2629 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2631 // copied from wxGTK : CS
2632 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2635 // (a) it's a command event and so is propagated to the parent
2636 // (b) under MSW it can be generated from kbd too
2637 // (c) it uses screen coords (because of (a))
2638 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2640 this->ClientToScreen(event
.GetPosition()));
2641 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2644 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2650 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2652 // OS Needs it in tlw content area coordinates
2653 MacClientToRootWindow( &x
, &y
) ;
2657 // OS Needs it in window not client coordinates
2658 wxPoint origin
= GetClientAreaOrigin() ;
2663 SInt16 controlpart
;
2668 short modifiers
= 0;
2670 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2671 modifiers
|= btnState
;
2673 if ( event
.m_shiftDown
)
2674 modifiers
|= shiftKey
;
2676 if ( event
.m_controlDown
)
2677 modifiers
|= controlKey
;
2679 if ( event
.m_altDown
)
2680 modifiers
|= optionKey
;
2682 if ( event
.m_metaDown
)
2683 modifiers
|= cmdKey
;
2685 bool handled
= false ;
2687 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2689 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2690 wxTheApp
->s_lastMouseDown
= 0 ;
2691 if ( controlpart
!= kControlNoPart
)
2693 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2706 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2708 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2711 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2715 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2716 Rect bounds
= { y
, x
, y
+h
, x
+w
};