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
->MacIsUserPane() && thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
173 case kEventControlVisibilityChanged
:
174 thisWindow
->MacVisibilityChanged() ;
176 case kEventControlEnabledStateChanged
:
177 thisWindow
->MacEnabledStateChanged() ;
179 case kEventControlHiliteChanged
:
180 thisWindow
->MacHiliteChanged() ;
188 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
190 OSStatus result
= eventNotHandledErr
;
192 switch ( GetEventClass( event
) )
194 case kEventClassControl
:
195 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
203 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
205 // ---------------------------------------------------------------------------
206 // UserPane events for non OSX builds
207 // ---------------------------------------------------------------------------
209 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
211 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
212 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
213 win
->MacControlUserPaneDrawProc(part
) ;
216 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
218 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
219 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
220 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
223 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
225 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
226 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
227 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
230 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
232 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
233 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
234 win
->MacControlUserPaneIdleProc() ;
237 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
239 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
240 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
241 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
244 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
246 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
247 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
248 win
->MacControlUserPaneActivateProc(activating
) ;
251 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
253 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
254 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
255 return win
->MacControlUserPaneFocusProc(action
) ;
258 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
260 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
261 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
262 win
->MacControlUserPaneBackgroundProc(info
) ;
265 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
267 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
270 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
272 return kControlNoPart
;
275 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
277 return kControlNoPart
;
280 void wxWindowMac::MacControlUserPaneIdleProc()
284 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
286 return kControlNoPart
;
289 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
293 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
295 return kControlNoPart
;
298 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
302 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
303 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
304 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
305 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
306 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
307 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
308 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
309 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
311 // ===========================================================================
313 // ===========================================================================
315 wxList
wxWinMacControlList(wxKEY_INTEGER
);
317 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
319 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
322 return (wxControl
*)node
->GetData();
325 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
327 // adding NULL ControlRef is (first) surely a result of an error and
328 // (secondly) breaks native event processing
329 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
331 if ( !wxWinMacControlList
.Find((long)inControl
) )
332 wxWinMacControlList
.Append((long)inControl
, control
);
335 void wxRemoveMacControlAssociation(wxWindow
*control
)
337 wxWinMacControlList
.DeleteObject(control
);
341 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
343 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
345 // we have to setup the brush in the current port and return noErr
346 // or return an error code so that the control manager walks further up the
347 // hierarchy to find a correct background
349 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
351 OSStatus status
= paramErr
;
354 case kControlMsgApplyTextColor
:
356 case kControlMsgSetUpBackground
:
358 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
362 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
366 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
368 // this clipping is only needed for non HIView
370 RgnHandle clip
= NewRgn() ;
373 wx
->MacWindowToRootWindow( &x
,&y
) ;
374 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
375 OffsetRgn( clip
, x
, y
) ;
382 else if ( wx->MacIsUserPane() )
384 // if we don't have a valid brush for such a control, we have to call the
385 // setup of our parent ourselves
386 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
399 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
400 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
404 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
407 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
412 // ----------------------------------------------------------------------------
413 // constructors and such
414 // ----------------------------------------------------------------------------
416 void wxWindowMac::Init()
418 m_backgroundTransparent
= FALSE
;
420 // as all windows are created with WS_VISIBLE style...
423 m_hScrollBar
= NULL
;
424 m_vScrollBar
= NULL
;
425 m_macBackgroundBrush
= wxNullBrush
;
427 m_macControl
= NULL
;
429 m_macIsUserPane
= TRUE
;
431 // make sure all proc ptrs are available
433 if ( gControlUserPaneDrawUPP
== NULL
)
435 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
436 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
437 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
438 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
439 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
440 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
441 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
442 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
444 if ( wxMacLiveScrollbarActionUPP
== NULL
)
446 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
449 if ( wxMacSetupControlBackgroundUPP
== NULL
)
451 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
457 wxWindowMac::~wxWindowMac()
461 m_isBeingDeleted
= TRUE
;
463 #ifndef __WXUNIVERSAL__
464 // VS: make sure there's no wxFrame with last focus set to us:
465 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
467 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
470 if ( frame
->GetLastFocus() == this )
472 frame
->SetLastFocus((wxWindow
*)NULL
);
477 #endif // __WXUNIVERSAL__
479 // wxRemoveMacControlAssociation( this ) ;
480 // If we delete an item, we should initialize the parent panel,
481 // because it could now be invalid.
482 wxWindow
*parent
= GetParent() ;
485 if (parent
->GetDefaultItem() == (wxButton
*) this)
486 parent
->SetDefaultItem(NULL
);
488 if ( (ControlRef
) m_macControl
)
490 // in case the callback might be called during destruction
491 wxRemoveMacControlAssociation( this) ;
492 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
493 ::DisposeControl( (ControlRef
) m_macControl
) ;
494 m_macControl
= NULL
;
497 if ( g_MacLastWindow
== this )
499 g_MacLastWindow
= NULL
;
502 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
505 if ( frame
->GetLastFocus() == this )
506 frame
->SetLastFocus( NULL
) ;
509 if ( gFocusWindow
== this )
511 gFocusWindow
= NULL
;
516 // delete our drop target if we've got one
517 #if wxUSE_DRAG_AND_DROP
518 if ( m_dropTarget
!= NULL
)
523 #endif // wxUSE_DRAG_AND_DROP
528 void wxWindowMac::MacInstallEventHandler()
530 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
531 GetEventTypeCount(eventList
), eventList
, this,
532 (EventHandlerRef
*)&m_macControlEventHandler
);
537 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
541 const wxString
& name
)
543 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
545 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
548 parent
->AddChild(this);
550 m_windowVariant
= parent
->GetWindowVariant() ;
552 if ( m_macIsUserPane
)
554 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
556 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
557 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
559 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
561 MacPostControlCreate(pos
,size
) ;
562 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
563 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
564 #if !TARGET_API_MAC_OSX
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 ) ;
1727 RgnHandle updateRgn = NewRgn() ;
1730 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1734 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1735 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1737 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1738 DisposeRgn(updateRgn) ;
1740 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1742 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1743 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1746 if ( MacGetTopLevelWindow() == NULL )
1749 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1752 wxPoint client = GetClientAreaOrigin();
1755 int x2 = m_width - client.x;
1756 int y2 = m_height - client.y;
1758 if (IsKindOf( CLASSINFO(wxButton)))
1760 // buttons have an "aura"
1767 Rect clientrect = { y1, x1, y2, x2 };
1771 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1772 SectRect( &clientrect , &r , &clientrect ) ;
1775 if ( !EmptyRect( &clientrect ) )
1777 int top = 0 , left = 0 ;
1779 MacClientToRootWindow( &left , &top ) ;
1780 OffsetRect( &clientrect , left , top ) ;
1782 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1788 void wxWindowMac::MacRedrawControl()
1791 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1793 #if TARGET_API_MAC_CARBON
1796 wxClientDC dc(this) ;
1797 wxMacPortSetter helper(&dc) ;
1798 wxMacWindowClipper clipper(this) ;
1799 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1800 UMADrawControl( (ControlRef) m_macControl ) ;
1807 void wxWindowMac::OnPaint(wxPaintEvent& event)
1809 // why don't we skip that here ?
1813 wxWindowMac
*wxGetActiveWindow()
1815 // actually this is a windows-only concept
1819 // Coordinates relative to the window
1820 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1822 // We really don't move the mouse programmatically under Mac.
1825 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1827 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1832 event
.GetDC()->Clear() ;
1835 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1837 wxWindowDC
dc(this) ;
1838 wxMacPortSetter
helper(&dc
) ;
1840 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1843 int wxWindowMac::GetScrollPos(int orient
) const
1845 if ( orient
== wxHORIZONTAL
)
1848 return m_hScrollBar
->GetThumbPosition() ;
1853 return m_vScrollBar
->GetThumbPosition() ;
1858 // This now returns the whole range, not just the number
1859 // of positions that we can scroll.
1860 int wxWindowMac::GetScrollRange(int orient
) const
1862 if ( orient
== wxHORIZONTAL
)
1865 return m_hScrollBar
->GetRange() ;
1870 return m_vScrollBar
->GetRange() ;
1875 int wxWindowMac::GetScrollThumb(int orient
) const
1877 if ( orient
== wxHORIZONTAL
)
1880 return m_hScrollBar
->GetThumbSize() ;
1885 return m_vScrollBar
->GetThumbSize() ;
1890 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1892 if ( orient
== wxHORIZONTAL
)
1895 m_hScrollBar
->SetThumbPosition( pos
) ;
1900 m_vScrollBar
->SetThumbPosition( pos
) ;
1904 void wxWindowMac::MacPaintBorders( int left
, int top
)
1910 wxGetOsVersion( &major
, &minor
);
1912 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1913 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1915 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1916 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1917 // OS X has lighter border edges than classic:
1920 darkShadow
.red
= 0x8E8E;
1921 darkShadow
.green
= 0x8E8E;
1922 darkShadow
.blue
= 0x8E8E;
1923 lightShadow
.red
= 0xBDBD;
1924 lightShadow
.green
= 0xBDBD;
1925 lightShadow
.blue
= 0xBDBD;
1931 GetSize( &w
, &h
) ;
1932 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1934 #if wxMAC_USE_THEME_BORDER
1935 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1938 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1939 InsetRect( &rect , border , border );
1940 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1943 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1945 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1946 RGBForeColor( &face
);
1947 MoveTo( left
+ 0 , top
+ h
- 2 );
1948 LineTo( left
+ 0 , top
+ 0 );
1949 LineTo( left
+ w
- 2 , top
+ 0 );
1951 MoveTo( left
+ 2 , top
+ h
- 3 );
1952 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1953 LineTo( left
+ w
- 3 , top
+ 2 );
1955 RGBForeColor( sunken
? &face
: &darkShadow
);
1956 MoveTo( left
+ 0 , top
+ h
- 1 );
1957 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1958 LineTo( left
+ w
- 1 , top
+ 0 );
1960 RGBForeColor( sunken
? &lightShadow
: &white
);
1961 MoveTo( left
+ 1 , top
+ h
- 3 );
1962 LineTo( left
+ 1, top
+ 1 );
1963 LineTo( left
+ w
- 3 , top
+ 1 );
1965 RGBForeColor( sunken
? &white
: &lightShadow
);
1966 MoveTo( left
+ 1 , top
+ h
- 2 );
1967 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1968 LineTo( left
+ w
- 2 , top
+ 1 );
1970 RGBForeColor( sunken
? &darkShadow
: &face
);
1971 MoveTo( left
+ 2 , top
+ h
- 4 );
1972 LineTo( left
+ 2 , top
+ 2 );
1973 LineTo( left
+ w
- 4 , top
+ 2 );
1976 else if (HasFlag(wxSIMPLE_BORDER
))
1978 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1979 RGBForeColor( &darkShadow
) ;
1980 FrameRect( &rect
) ;
1984 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1986 if ( child
== m_hScrollBar
)
1987 m_hScrollBar
= NULL
;
1988 if ( child
== m_vScrollBar
)
1989 m_vScrollBar
= NULL
;
1991 wxWindowBase::RemoveChild( child
) ;
1994 // New function that will replace some of the above.
1995 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1996 int range
, bool refresh
)
1998 if ( orient
== wxHORIZONTAL
)
2002 if ( range
== 0 || thumbVisible
>= range
)
2004 if ( m_hScrollBar
->IsShown() )
2005 m_hScrollBar
->Show(false) ;
2009 if ( !m_hScrollBar
->IsShown() )
2010 m_hScrollBar
->Show(true) ;
2011 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2019 if ( range
== 0 || thumbVisible
>= range
)
2021 if ( m_vScrollBar
->IsShown() )
2022 m_vScrollBar
->Show(false) ;
2026 if ( !m_vScrollBar
->IsShown() )
2027 m_vScrollBar
->Show(true) ;
2028 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2032 MacRepositionScrollBars() ;
2035 // Does a physical scroll
2036 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2038 if( dx
== 0 && dy
==0 )
2043 wxClientDC
dc(this) ;
2044 wxMacPortSetter
helper(&dc
) ;
2046 int width
, height
;
2047 GetClientSize( &width
, &height
) ;
2054 // TODO take out the boundaries
2055 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2057 RgnHandle updateRgn
= NewRgn() ;
2060 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2061 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2062 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2064 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2066 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2067 // but it seems the update only refreshes the background of the control, rather than calling
2068 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2069 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2072 // we also have to scroll the update rgn in this rectangle
2073 // in order not to loose updates
2075 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2076 RgnHandle formerUpdateRgn
= NewRgn() ;
2077 RgnHandle scrollRgn
= NewRgn() ;
2078 RectRgn( scrollRgn
, &scrollrect
) ;
2079 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2081 LocalToGlobal( &pt
) ;
2082 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2083 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2084 if ( !EmptyRgn( formerUpdateRgn
) )
2086 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2087 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2088 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2090 InvalWindowRgn(rootWindow
, updateRgn
) ;
2091 DisposeRgn( updateRgn
) ;
2092 DisposeRgn( formerUpdateRgn
) ;
2093 DisposeRgn( scrollRgn
) ;
2097 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2099 wxWindowMac
*child
= node
->GetData();
2100 if (child
== m_vScrollBar
) continue;
2101 if (child
== m_hScrollBar
) continue;
2102 if (child
->IsTopLevel()) continue;
2105 child
->GetPosition( &x
, &y
);
2107 child
->GetSize( &w
, &h
);
2111 if (rect
->Intersects(rc
))
2112 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2116 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2120 // TODO remove, was moved higher up Update() ;
2124 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2126 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2128 wxScrollWinEvent wevent
;
2129 wevent
.SetPosition(event
.GetPosition());
2130 wevent
.SetOrientation(event
.GetOrientation());
2131 wevent
.m_eventObject
= this;
2133 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2134 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2135 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2136 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2137 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2138 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2139 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2140 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2141 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2142 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2143 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2144 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2145 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2146 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2147 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2148 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2150 GetEventHandler()->ProcessEvent(wevent
);
2154 // Get the window with the focus
2155 wxWindowMac
*wxWindowBase::FindFocus()
2157 return gFocusWindow
;
2160 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2162 // panel wants to track the window which was the last to have focus in it,
2163 // so we want to set ourselves as the window which last had focus
2165 // notice that it's also important to do it upwards the tree becaus
2166 // otherwise when the top level panel gets focus, it won't set it back to
2167 // us, but to some other sibling
2169 // CS:don't know if this is still needed:
2170 //wxChildFocusEvent eventFocus(this);
2171 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2176 void wxWindowMac::OnInternalIdle()
2178 // This calls the UI-update mechanism (querying windows for
2179 // menu/toolbar/control state information)
2180 if (wxUpdateUIEvent::CanUpdate(this))
2181 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2184 // Raise the window to the top of the Z order
2185 void wxWindowMac::Raise()
2189 // Lower the window to the bottom of the Z order
2190 void wxWindowMac::Lower()
2195 // static wxWindow *gs_lastWhich = NULL;
2197 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2199 // first trigger a set cursor event
2201 wxPoint clientorigin
= GetClientAreaOrigin() ;
2202 wxSize clientsize
= GetClientSize() ;
2204 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2206 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2208 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2209 if ( processedEvtSetCursor
&& event
.HasCursor() )
2211 cursor
= event
.GetCursor() ;
2216 // the test for processedEvtSetCursor is here to prevent using m_cursor
2217 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2218 // it - this is a way to say that our cursor shouldn't be used for this
2220 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2230 cursor
= *wxSTANDARD_CURSOR
;
2234 cursor
.MacInstall() ;
2236 return cursor
.Ok() ;
2239 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2243 return m_tooltip
->GetTip() ;
2245 return wxEmptyString
;
2248 void wxWindowMac::Update()
2250 #if TARGET_API_MAC_OSX
2251 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2253 ::Draw1Control( (ControlRef
) m_macControl
) ;
2257 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2259 wxTopLevelWindowMac
* win
= NULL
;
2260 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2263 win
= wxFindWinFromMacWindow( window
) ;
2267 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2271 RgnHandle visRgn
= NewRgn() ;
2272 RgnHandle tempRgn
= NewRgn() ;
2273 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2275 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2276 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2278 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2279 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2288 if ( includeOuterStructures
)
2289 InsetRect( &r
, -3 , -3 ) ;
2290 RectRgn( visRgn
, &r
) ;
2291 if ( !IsTopLevel() )
2293 wxWindow
* child
= this ;
2294 wxWindow
* parent
= child
->GetParent() ;
2299 // we have to find a better clipping algorithm here, in order not to clip things
2300 // positioned like status and toolbar
2301 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2303 size
= parent
->GetSize() ;
2308 size
= parent
->GetClientSize() ;
2309 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2313 parent
->MacWindowToRootWindow( &x
, &y
) ;
2314 MacRootWindowToWindow( &x
, &y
) ;
2316 SetRectRgn( tempRgn
,
2317 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2318 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2319 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2321 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2322 if ( parent
->IsTopLevel() )
2325 parent
= child
->GetParent() ;
2330 wxRegion vis
= visRgn
;
2331 DisposeRgn( visRgn
) ;
2332 DisposeRgn( tempRgn
) ;
2337 This function must not change the updatergn !
2339 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2341 // we let the OS handle root control redraws
2342 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2345 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2346 bool handled
= false ;
2348 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2350 RgnHandle newupdate
= NewRgn() ;
2351 wxSize point
= GetClientSize() ;
2352 wxPoint origin
= GetClientAreaOrigin() ;
2353 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2354 SectRgn( newupdate
, updatergn
, newupdate
) ;
2355 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2356 m_updateRegion
= newupdate
;
2357 DisposeRgn( newupdate
) ;
2360 if ( !EmptyRgn(updatergn
) )
2362 wxWindowDC
dc(this);
2363 if (!EmptyRgn(updatergn
))
2364 dc
.SetClippingRegion(wxRegion(updatergn
));
2366 wxEraseEvent
eevent( GetId(), &dc
);
2367 eevent
.SetEventObject( this );
2368 GetEventHandler()->ProcessEvent( eevent
);
2370 if ( !m_updateRegion
.Empty() )
2372 // paint the window itself
2374 event
.m_timeStamp
= time
;
2375 event
.SetEventObject(this);
2376 handled
= GetEventHandler()->ProcessEvent(event
);
2378 // paint custom borders
2379 wxNcPaintEvent
eventNc( GetId() );
2380 eventNc
.SetEventObject( this );
2381 GetEventHandler()->ProcessEvent( eventNc
);
2387 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2389 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2390 // updatergn is always already clipped to our boundaries
2391 // if we are in compositing mode then it is in relative to the upper left of the control
2392 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2393 // of the toplevel window
2394 // it is in window coordinates, not in client coordinates
2396 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2397 RgnHandle ownUpdateRgn
= NewRgn() ;
2398 CopyRgn( updatergn
, ownUpdateRgn
) ;
2400 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2403 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2404 RgnHandle controlRgn
= NewRgn();
2405 RectRgn( controlRgn
, &bounds
);
2406 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2407 // the window update region
2408 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2409 DisposeRgn( controlRgn
);
2411 //KO: convert ownUpdateRgn to local coordinates
2412 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2415 MacDoRedraw( ownUpdateRgn
, time
) ;
2416 DisposeRgn( ownUpdateRgn
) ;
2420 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2422 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2426 if ( iter
->IsTopLevel() )
2427 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2429 iter
= iter
->GetParent() ;
2431 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2435 void wxWindowMac::MacCreateScrollBars( long style
)
2437 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2439 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2440 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2442 GetClientSize( &width
, &height
) ;
2444 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2445 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2446 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2447 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2449 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2450 vSize
, wxVERTICAL
);
2452 if ( style
& wxVSCROLL
)
2458 m_vScrollBar
->Show(false) ;
2460 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2461 hSize
, wxHORIZONTAL
);
2462 if ( style
& wxHSCROLL
)
2467 m_hScrollBar
->Show(false) ;
2470 // because the create does not take into account the client area origin
2471 MacRepositionScrollBars() ; // we might have a real position shift
2474 void wxWindowMac::MacRepositionScrollBars()
2476 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2477 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2479 // get real client area
2483 GetSize( &width
, &height
) ;
2485 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2486 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2488 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2489 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2490 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2491 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2497 GetSize( &w
, &h
) ;
2499 MacClientToRootWindow( &x
, &y
) ;
2500 MacClientToRootWindow( &w
, &h
) ;
2502 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2504 int totW
= 10000 , totH
= 10000;
2507 if ( iter
->IsTopLevel() )
2509 iter
->GetSize( &totW
, &totH
) ;
2513 iter
= iter
->GetParent() ;
2541 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2545 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2549 bool wxWindowMac::AcceptsFocus() const
2551 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2554 void wxWindowMac::MacSuperChangedPosition()
2556 // only window-absolute structures have to be moved i.e. controls
2558 wxWindowListNode
*node
= GetChildren().GetFirst();
2561 wxWindowMac
*child
= node
->GetData();
2562 child
->MacSuperChangedPosition() ;
2563 node
= node
->GetNext();
2567 void wxWindowMac::MacTopLevelWindowChangedPosition()
2569 // only screen-absolute structures have to be moved i.e. glcanvas
2571 wxWindowListNode
*node
= GetChildren().GetFirst();
2574 wxWindowMac
*child
= node
->GetData();
2575 child
->MacTopLevelWindowChangedPosition() ;
2576 node
= node
->GetNext();
2580 long wxWindowMac::MacGetLeftBorderSize( ) const
2585 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2588 #if wxMAC_USE_THEME_BORDER
2589 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2593 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2596 #if wxMAC_USE_THEME_BORDER
2597 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2601 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2608 long wxWindowMac::MacGetRightBorderSize( ) const
2610 // they are all symmetric in mac themes
2611 return MacGetLeftBorderSize() ;
2614 long wxWindowMac::MacGetTopBorderSize( ) const
2616 // they are all symmetric in mac themes
2617 return MacGetLeftBorderSize() ;
2620 long wxWindowMac::MacGetBottomBorderSize( ) const
2622 // they are all symmetric in mac themes
2623 return MacGetLeftBorderSize() ;
2626 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2628 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2631 // Find the wxWindowMac at the current mouse position, returning the mouse
2633 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2635 pt
= wxGetMousePosition();
2636 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2640 // Get the current mouse position.
2641 wxPoint
wxGetMousePosition()
2644 wxGetMousePosition(& x
, & y
);
2645 return wxPoint(x
, y
);
2648 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2650 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2652 // copied from wxGTK : CS
2653 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2656 // (a) it's a command event and so is propagated to the parent
2657 // (b) under MSW it can be generated from kbd too
2658 // (c) it uses screen coords (because of (a))
2659 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2661 this->ClientToScreen(event
.GetPosition()));
2662 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2665 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2671 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2673 // OS Needs it in tlw content area coordinates
2674 MacClientToRootWindow( &x
, &y
) ;
2678 // OS Needs it in window not client coordinates
2679 wxPoint origin
= GetClientAreaOrigin() ;
2684 SInt16 controlpart
;
2689 short modifiers
= 0;
2691 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2692 modifiers
|= btnState
;
2694 if ( event
.m_shiftDown
)
2695 modifiers
|= shiftKey
;
2697 if ( event
.m_controlDown
)
2698 modifiers
|= controlKey
;
2700 if ( event
.m_altDown
)
2701 modifiers
|= optionKey
;
2703 if ( event
.m_metaDown
)
2704 modifiers
|= cmdKey
;
2706 bool handled
= false ;
2708 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2710 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2711 wxTheApp
->s_lastMouseDown
= 0 ;
2712 if ( controlpart
!= kControlNoPart
)
2714 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2727 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2729 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2732 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2736 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2737 Rect bounds
= { y
, x
, y
+h
, x
+w
};