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
1376 if ( m_macIsUserPane
|| IsTopLevel() )
1377 return wxWindowBase::DoGetBestSize() ;
1379 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1380 short baselineoffset
;
1381 int bestWidth
, bestHeight
;
1382 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1384 if ( EmptyRect( &bestsize
) )
1387 bestsize
.left
= bestsize
.top
= 0 ;
1388 bestsize
.right
= 16 ;
1389 bestsize
.bottom
= 16 ;
1390 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1392 bestsize
.bottom
= 16 ;
1394 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1396 bestsize
.bottom
= 24 ;
1400 // return wxWindowBase::DoGetBestSize() ;
1404 bestWidth
= bestsize
.right
- bestsize
.left
;
1405 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1406 if ( bestHeight
< 10 )
1409 return wxSize(bestWidth
, bestHeight
);
1410 // return wxWindowBase::DoGetBestSize() ;
1414 // set the size of the window: if the dimensions are positive, just use them,
1415 // but if any of them is equal to -1, it means that we must find the value for
1416 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1417 // which case -1 is a valid value for x and y)
1419 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1420 // the width/height to best suit our contents, otherwise we reuse the current
1422 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1424 // get the current size and position...
1425 int currentX
, currentY
;
1426 GetPosition(¤tX
, ¤tY
);
1428 int currentW
,currentH
;
1429 GetSize(¤tW
, ¤tH
);
1431 // ... and don't do anything (avoiding flicker) if it's already ok
1432 if ( x
== currentX
&& y
== currentY
&&
1433 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1436 MacRepositionScrollBars() ; // we might have a real position shift
1440 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1442 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1445 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1447 wxSize
size(-1, -1);
1450 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1452 size
= DoGetBestSize();
1457 // just take the current one
1464 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1468 size
= DoGetBestSize();
1470 //else: already called DoGetBestSize() above
1476 // just take the current one
1481 DoMoveWindow(x
, y
, width
, height
);
1485 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1487 RgnHandle rgn
= NewRgn() ;
1489 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1490 GetRegionBounds( rgn
, &content
) ;
1492 #if !TARGET_API_MAC_OSX
1494 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1495 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1498 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1501 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1503 if ( clientheight
!= -1 || clientheight
!= -1 )
1505 int currentclientwidth
, currentclientheight
;
1506 int currentwidth
, currentheight
;
1508 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1509 GetSize( ¤twidth
, ¤theight
) ;
1511 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1512 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1516 void wxWindowMac::SetTitle(const wxString
& title
)
1518 m_label
= wxStripMenuCodes(title
) ;
1522 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1527 wxString
wxWindowMac::GetTitle() const
1532 bool wxWindowMac::Show(bool show
)
1534 if ( !wxWindowBase::Show(show
) )
1537 // TODO use visibilityChanged Carbon Event for OSX
1538 bool former
= MacIsReallyShown() ;
1540 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1541 if ( former
!= MacIsReallyShown() )
1542 MacPropagateVisibilityChanged() ;
1546 bool wxWindowMac::Enable(bool enable
)
1548 wxASSERT( m_macControl
!= NULL
) ;
1549 if ( !wxWindowBase::Enable(enable
) )
1552 bool former
= MacIsReallyEnabled() ;
1554 EnableControl( (ControlRef
) m_macControl
) ;
1556 DisableControl( (ControlRef
) m_macControl
) ;
1558 if ( former
!= MacIsReallyEnabled() )
1559 MacPropagateEnabledStateChanged() ;
1564 // status change propagations (will be not necessary for OSX later )
1567 void wxWindowMac::MacPropagateVisibilityChanged()
1569 #if !TARGET_API_MAC_OSX
1570 MacVisibilityChanged() ;
1572 wxWindowListNode
*node
= GetChildren().GetFirst();
1575 wxWindowMac
*child
= node
->GetData();
1576 if ( child
->IsShown() )
1577 child
->MacPropagateVisibilityChanged( ) ;
1578 node
= node
->GetNext();
1583 void wxWindowMac::MacPropagateEnabledStateChanged( )
1585 #if !TARGET_API_MAC_OSX
1586 MacEnabledStateChanged() ;
1588 wxWindowListNode
*node
= GetChildren().GetFirst();
1591 wxWindowMac
*child
= node
->GetData();
1592 if ( child
->IsEnabled() )
1593 child
->MacPropagateEnabledStateChanged() ;
1594 node
= node
->GetNext();
1599 void wxWindowMac::MacPropagateHiliteChanged( )
1601 #if !TARGET_API_MAC_OSX
1602 MacHiliteChanged() ;
1604 wxWindowListNode
*node
= GetChildren().GetFirst();
1607 wxWindowMac
*child
= node
->GetData();
1608 // if ( child->IsEnabled() )
1609 child
->MacPropagateHiliteChanged() ;
1610 node
= node
->GetNext();
1616 // status change notifications
1619 void wxWindowMac::MacVisibilityChanged()
1623 void wxWindowMac::MacHiliteChanged()
1627 void wxWindowMac::MacEnabledStateChanged()
1632 // status queries on the inherited window's state
1635 bool wxWindowMac::MacIsReallyShown()
1637 // only under OSX the visibility of the TLW is taken into account
1638 #if TARGET_API_MAC_OSX
1639 return IsControlVisible( (ControlRef
) m_macControl
) ;
1641 wxWindow
* win
= this ;
1642 while( win
->IsShown() )
1644 if ( win
->IsTopLevel() )
1647 win
= win
->GetParent() ;
1656 bool wxWindowMac::MacIsReallyEnabled()
1658 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1661 bool wxWindowMac::MacIsReallyHilited()
1663 return IsControlActive( (ControlRef
) m_macControl
) ;
1670 int wxWindowMac::GetCharHeight() const
1672 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1673 return dc
.GetCharHeight() ;
1676 int wxWindowMac::GetCharWidth() const
1678 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1679 return dc
.GetCharWidth() ;
1682 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1683 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1685 const wxFont
*fontToUse
= theFont
;
1687 fontToUse
= &m_font
;
1689 wxClientDC
dc( (wxWindowMac
*) this ) ;
1691 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1692 if ( externalLeading
)
1693 *externalLeading
= le
;
1703 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1704 * we always intersect with the entire window, not only with the client area
1707 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1709 #if TARGET_API_MAC_OSX
1711 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1714 RgnHandle update
= NewRgn() ;
1715 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1716 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1717 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1720 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1722 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1723 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1726 if ( MacGetTopLevelWindow() == NULL )
1729 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1732 wxPoint client = GetClientAreaOrigin();
1735 int x2 = m_width - client.x;
1736 int y2 = m_height - client.y;
1738 if (IsKindOf( CLASSINFO(wxButton)))
1740 // buttons have an "aura"
1747 Rect clientrect = { y1, x1, y2, x2 };
1751 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1752 SectRect( &clientrect , &r , &clientrect ) ;
1755 if ( !EmptyRect( &clientrect ) )
1757 int top = 0 , left = 0 ;
1759 MacClientToRootWindow( &left , &top ) ;
1760 OffsetRect( &clientrect , left , top ) ;
1762 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1768 void wxWindowMac::MacRedrawControl()
1771 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1773 #if TARGET_API_MAC_CARBON
1776 wxClientDC dc(this) ;
1777 wxMacPortSetter helper(&dc) ;
1778 wxMacWindowClipper clipper(this) ;
1779 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1780 UMADrawControl( (ControlRef) m_macControl ) ;
1787 void wxWindowMac::OnPaint(wxPaintEvent& event)
1789 // why don't we skip that here ?
1793 wxWindowMac
*wxGetActiveWindow()
1795 // actually this is a windows-only concept
1799 // Coordinates relative to the window
1800 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1802 // We really don't move the mouse programmatically under Mac.
1805 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1807 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1812 event
.GetDC()->Clear() ;
1815 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1817 wxWindowDC
dc(this) ;
1818 wxMacPortSetter
helper(&dc
) ;
1820 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1823 int wxWindowMac::GetScrollPos(int orient
) const
1825 if ( orient
== wxHORIZONTAL
)
1828 return m_hScrollBar
->GetThumbPosition() ;
1833 return m_vScrollBar
->GetThumbPosition() ;
1838 // This now returns the whole range, not just the number
1839 // of positions that we can scroll.
1840 int wxWindowMac::GetScrollRange(int orient
) const
1842 if ( orient
== wxHORIZONTAL
)
1845 return m_hScrollBar
->GetRange() ;
1850 return m_vScrollBar
->GetRange() ;
1855 int wxWindowMac::GetScrollThumb(int orient
) const
1857 if ( orient
== wxHORIZONTAL
)
1860 return m_hScrollBar
->GetThumbSize() ;
1865 return m_vScrollBar
->GetThumbSize() ;
1870 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1872 if ( orient
== wxHORIZONTAL
)
1875 m_hScrollBar
->SetThumbPosition( pos
) ;
1880 m_vScrollBar
->SetThumbPosition( pos
) ;
1884 void wxWindowMac::MacPaintBorders( int left
, int top
)
1890 wxGetOsVersion( &major
, &minor
);
1892 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1893 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1895 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1896 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1897 // OS X has lighter border edges than classic:
1900 darkShadow
.red
= 0x8E8E;
1901 darkShadow
.green
= 0x8E8E;
1902 darkShadow
.blue
= 0x8E8E;
1903 lightShadow
.red
= 0xBDBD;
1904 lightShadow
.green
= 0xBDBD;
1905 lightShadow
.blue
= 0xBDBD;
1911 GetSize( &w
, &h
) ;
1912 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1914 #if wxMAC_USE_THEME_BORDER
1915 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1918 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1919 InsetRect( &rect , border , border );
1920 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1923 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1925 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1926 RGBForeColor( &face
);
1927 MoveTo( left
+ 0 , top
+ h
- 2 );
1928 LineTo( left
+ 0 , top
+ 0 );
1929 LineTo( left
+ w
- 2 , top
+ 0 );
1931 MoveTo( left
+ 2 , top
+ h
- 3 );
1932 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1933 LineTo( left
+ w
- 3 , top
+ 2 );
1935 RGBForeColor( sunken
? &face
: &darkShadow
);
1936 MoveTo( left
+ 0 , top
+ h
- 1 );
1937 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1938 LineTo( left
+ w
- 1 , top
+ 0 );
1940 RGBForeColor( sunken
? &lightShadow
: &white
);
1941 MoveTo( left
+ 1 , top
+ h
- 3 );
1942 LineTo( left
+ 1, top
+ 1 );
1943 LineTo( left
+ w
- 3 , top
+ 1 );
1945 RGBForeColor( sunken
? &white
: &lightShadow
);
1946 MoveTo( left
+ 1 , top
+ h
- 2 );
1947 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1948 LineTo( left
+ w
- 2 , top
+ 1 );
1950 RGBForeColor( sunken
? &darkShadow
: &face
);
1951 MoveTo( left
+ 2 , top
+ h
- 4 );
1952 LineTo( left
+ 2 , top
+ 2 );
1953 LineTo( left
+ w
- 4 , top
+ 2 );
1956 else if (HasFlag(wxSIMPLE_BORDER
))
1958 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1959 RGBForeColor( &darkShadow
) ;
1960 FrameRect( &rect
) ;
1964 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1966 if ( child
== m_hScrollBar
)
1967 m_hScrollBar
= NULL
;
1968 if ( child
== m_vScrollBar
)
1969 m_vScrollBar
= NULL
;
1971 wxWindowBase::RemoveChild( child
) ;
1974 // New function that will replace some of the above.
1975 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1976 int range
, bool refresh
)
1978 if ( orient
== wxHORIZONTAL
)
1982 if ( range
== 0 || thumbVisible
>= range
)
1984 if ( m_hScrollBar
->IsShown() )
1985 m_hScrollBar
->Show(false) ;
1989 if ( !m_hScrollBar
->IsShown() )
1990 m_hScrollBar
->Show(true) ;
1991 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1999 if ( range
== 0 || thumbVisible
>= range
)
2001 if ( m_vScrollBar
->IsShown() )
2002 m_vScrollBar
->Show(false) ;
2006 if ( !m_vScrollBar
->IsShown() )
2007 m_vScrollBar
->Show(true) ;
2008 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2012 MacRepositionScrollBars() ;
2015 // Does a physical scroll
2016 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2018 if( dx
== 0 && dy
==0 )
2023 wxClientDC
dc(this) ;
2024 wxMacPortSetter
helper(&dc
) ;
2026 int width
, height
;
2027 GetClientSize( &width
, &height
) ;
2034 // TODO take out the boundaries
2035 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2037 RgnHandle updateRgn
= NewRgn() ;
2040 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2041 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2042 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2044 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2046 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2047 // but it seems the update only refreshes the background of the control, rather than calling
2048 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2049 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2052 // we also have to scroll the update rgn in this rectangle
2053 // in order not to loose updates
2055 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2056 RgnHandle formerUpdateRgn
= NewRgn() ;
2057 RgnHandle scrollRgn
= NewRgn() ;
2058 RectRgn( scrollRgn
, &scrollrect
) ;
2059 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2061 LocalToGlobal( &pt
) ;
2062 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2063 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2064 if ( !EmptyRgn( formerUpdateRgn
) )
2066 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2067 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2068 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2070 InvalWindowRgn(rootWindow
, updateRgn
) ;
2071 DisposeRgn( updateRgn
) ;
2072 DisposeRgn( formerUpdateRgn
) ;
2073 DisposeRgn( scrollRgn
) ;
2077 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2079 wxWindowMac
*child
= node
->GetData();
2080 if (child
== m_vScrollBar
) continue;
2081 if (child
== m_hScrollBar
) continue;
2082 if (child
->IsTopLevel()) continue;
2085 child
->GetPosition( &x
, &y
);
2087 child
->GetSize( &w
, &h
);
2091 if (rect
->Intersects(rc
))
2092 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2096 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2100 // TODO remove, was moved higher up Update() ;
2104 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2106 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2108 wxScrollWinEvent wevent
;
2109 wevent
.SetPosition(event
.GetPosition());
2110 wevent
.SetOrientation(event
.GetOrientation());
2111 wevent
.m_eventObject
= this;
2113 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2114 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2115 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2116 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2117 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2118 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2119 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2120 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2121 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2122 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2123 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2124 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2125 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2126 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2127 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2128 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2130 GetEventHandler()->ProcessEvent(wevent
);
2134 // Get the window with the focus
2135 wxWindowMac
*wxWindowBase::FindFocus()
2137 return gFocusWindow
;
2140 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2142 // panel wants to track the window which was the last to have focus in it,
2143 // so we want to set ourselves as the window which last had focus
2145 // notice that it's also important to do it upwards the tree becaus
2146 // otherwise when the top level panel gets focus, it won't set it back to
2147 // us, but to some other sibling
2149 // CS:don't know if this is still needed:
2150 //wxChildFocusEvent eventFocus(this);
2151 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2156 void wxWindowMac::OnInternalIdle()
2158 // This calls the UI-update mechanism (querying windows for
2159 // menu/toolbar/control state information)
2160 if (wxUpdateUIEvent::CanUpdate(this))
2161 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2164 // Raise the window to the top of the Z order
2165 void wxWindowMac::Raise()
2169 // Lower the window to the bottom of the Z order
2170 void wxWindowMac::Lower()
2175 // static wxWindow *gs_lastWhich = NULL;
2177 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2179 // first trigger a set cursor event
2181 wxPoint clientorigin
= GetClientAreaOrigin() ;
2182 wxSize clientsize
= GetClientSize() ;
2184 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2186 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2188 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2189 if ( processedEvtSetCursor
&& event
.HasCursor() )
2191 cursor
= event
.GetCursor() ;
2196 // the test for processedEvtSetCursor is here to prevent using m_cursor
2197 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2198 // it - this is a way to say that our cursor shouldn't be used for this
2200 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2210 cursor
= *wxSTANDARD_CURSOR
;
2214 cursor
.MacInstall() ;
2216 return cursor
.Ok() ;
2219 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2223 return m_tooltip
->GetTip() ;
2225 return wxEmptyString
;
2228 void wxWindowMac::Update()
2230 #if TARGET_API_MAC_OSX
2231 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2233 ::Draw1Control( (ControlRef
) m_macControl
) ;
2237 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2239 wxTopLevelWindowMac
* win
= NULL
;
2240 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2243 win
= wxFindWinFromMacWindow( window
) ;
2247 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2251 RgnHandle visRgn
= NewRgn() ;
2252 RgnHandle tempRgn
= NewRgn() ;
2253 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2255 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2256 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2258 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2259 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2268 if ( includeOuterStructures
)
2269 InsetRect( &r
, -3 , -3 ) ;
2270 RectRgn( visRgn
, &r
) ;
2271 if ( !IsTopLevel() )
2273 wxWindow
* child
= this ;
2274 wxWindow
* parent
= child
->GetParent() ;
2279 // we have to find a better clipping algorithm here, in order not to clip things
2280 // positioned like status and toolbar
2281 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2283 size
= parent
->GetSize() ;
2288 size
= parent
->GetClientSize() ;
2289 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2293 parent
->MacWindowToRootWindow( &x
, &y
) ;
2294 MacRootWindowToWindow( &x
, &y
) ;
2296 SetRectRgn( tempRgn
,
2297 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2298 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2299 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2301 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2302 if ( parent
->IsTopLevel() )
2305 parent
= child
->GetParent() ;
2310 wxRegion vis
= visRgn
;
2311 DisposeRgn( visRgn
) ;
2312 DisposeRgn( tempRgn
) ;
2317 This function must not change the updatergn !
2319 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2321 // we let the OS handle root control redraws
2322 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2325 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2326 bool handled
= false ;
2328 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2330 RgnHandle newupdate
= NewRgn() ;
2331 wxSize point
= GetClientSize() ;
2332 wxPoint origin
= GetClientAreaOrigin() ;
2333 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2334 SectRgn( newupdate
, updatergn
, newupdate
) ;
2335 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2336 m_updateRegion
= newupdate
;
2337 DisposeRgn( newupdate
) ;
2340 if ( !EmptyRgn(updatergn
) )
2342 wxWindowDC
dc(this);
2343 if (!EmptyRgn(updatergn
))
2344 dc
.SetClippingRegion(wxRegion(updatergn
));
2346 wxEraseEvent
eevent( GetId(), &dc
);
2347 eevent
.SetEventObject( this );
2348 GetEventHandler()->ProcessEvent( eevent
);
2350 if ( !m_updateRegion
.Empty() )
2352 // paint the window itself
2354 event
.m_timeStamp
= time
;
2355 event
.SetEventObject(this);
2356 handled
= GetEventHandler()->ProcessEvent(event
);
2358 // paint custom borders
2359 wxNcPaintEvent
eventNc( GetId() );
2360 eventNc
.SetEventObject( this );
2361 GetEventHandler()->ProcessEvent( eventNc
);
2367 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2369 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2370 // updatergn is always already clipped to our boundaries
2371 // if we are in compositing mode then it is in relative to the upper left of the control
2372 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2373 // of the toplevel window
2374 // it is in window coordinates, not in client coordinates
2376 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2377 RgnHandle ownUpdateRgn
= NewRgn() ;
2378 CopyRgn( updatergn
, ownUpdateRgn
) ;
2380 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2383 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2384 RgnHandle controlRgn
= NewRgn();
2385 RectRgn( controlRgn
, &bounds
);
2386 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2387 // the window update region
2388 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2389 DisposeRgn( controlRgn
);
2391 //KO: convert ownUpdateRgn to local coordinates
2392 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2395 MacDoRedraw( ownUpdateRgn
, time
) ;
2396 DisposeRgn( ownUpdateRgn
) ;
2400 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2402 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2406 if ( iter
->IsTopLevel() )
2407 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2409 iter
= iter
->GetParent() ;
2411 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2415 void wxWindowMac::MacCreateScrollBars( long style
)
2417 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2419 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2420 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2422 GetClientSize( &width
, &height
) ;
2424 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2425 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2426 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2427 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2429 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2430 vSize
, wxVERTICAL
);
2432 if ( style
& wxVSCROLL
)
2438 m_vScrollBar
->Show(false) ;
2440 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2441 hSize
, wxHORIZONTAL
);
2442 if ( style
& wxHSCROLL
)
2447 m_hScrollBar
->Show(false) ;
2450 // because the create does not take into account the client area origin
2451 MacRepositionScrollBars() ; // we might have a real position shift
2454 void wxWindowMac::MacRepositionScrollBars()
2456 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2457 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2459 // get real client area
2463 GetSize( &width
, &height
) ;
2465 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2466 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2468 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2469 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2470 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2471 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2477 GetSize( &w
, &h
) ;
2479 MacClientToRootWindow( &x
, &y
) ;
2480 MacClientToRootWindow( &w
, &h
) ;
2482 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2484 int totW
= 10000 , totH
= 10000;
2487 if ( iter
->IsTopLevel() )
2489 iter
->GetSize( &totW
, &totH
) ;
2493 iter
= iter
->GetParent() ;
2521 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2525 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2529 bool wxWindowMac::AcceptsFocus() const
2531 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2534 void wxWindowMac::MacSuperChangedPosition()
2536 // only window-absolute structures have to be moved i.e. controls
2538 wxWindowListNode
*node
= GetChildren().GetFirst();
2541 wxWindowMac
*child
= node
->GetData();
2542 child
->MacSuperChangedPosition() ;
2543 node
= node
->GetNext();
2547 void wxWindowMac::MacTopLevelWindowChangedPosition()
2549 // only screen-absolute structures have to be moved i.e. glcanvas
2551 wxWindowListNode
*node
= GetChildren().GetFirst();
2554 wxWindowMac
*child
= node
->GetData();
2555 child
->MacTopLevelWindowChangedPosition() ;
2556 node
= node
->GetNext();
2560 long wxWindowMac::MacGetLeftBorderSize( ) const
2565 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2568 #if wxMAC_USE_THEME_BORDER
2569 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2573 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2576 #if wxMAC_USE_THEME_BORDER
2577 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2581 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2588 long wxWindowMac::MacGetRightBorderSize( ) const
2590 // they are all symmetric in mac themes
2591 return MacGetLeftBorderSize() ;
2594 long wxWindowMac::MacGetTopBorderSize( ) const
2596 // they are all symmetric in mac themes
2597 return MacGetLeftBorderSize() ;
2600 long wxWindowMac::MacGetBottomBorderSize( ) const
2602 // they are all symmetric in mac themes
2603 return MacGetLeftBorderSize() ;
2606 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2608 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2611 // Find the wxWindowMac at the current mouse position, returning the mouse
2613 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2615 pt
= wxGetMousePosition();
2616 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2620 // Get the current mouse position.
2621 wxPoint
wxGetMousePosition()
2624 wxGetMousePosition(& x
, & y
);
2625 return wxPoint(x
, y
);
2628 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2630 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2632 // copied from wxGTK : CS
2633 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2636 // (a) it's a command event and so is propagated to the parent
2637 // (b) under MSW it can be generated from kbd too
2638 // (c) it uses screen coords (because of (a))
2639 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2641 this->ClientToScreen(event
.GetPosition()));
2642 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2645 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2651 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2653 // OS Needs it in tlw content area coordinates
2654 MacClientToRootWindow( &x
, &y
) ;
2658 // OS Needs it in window not client coordinates
2659 wxPoint origin
= GetClientAreaOrigin() ;
2664 SInt16 controlpart
;
2669 short modifiers
= 0;
2671 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2672 modifiers
|= btnState
;
2674 if ( event
.m_shiftDown
)
2675 modifiers
|= shiftKey
;
2677 if ( event
.m_controlDown
)
2678 modifiers
|= controlKey
;
2680 if ( event
.m_altDown
)
2681 modifiers
|= optionKey
;
2683 if ( event
.m_metaDown
)
2684 modifiers
|= cmdKey
;
2686 bool handled
= false ;
2688 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2690 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2691 wxTheApp
->s_lastMouseDown
= 0 ;
2692 if ( controlpart
!= kControlNoPart
)
2694 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2707 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2709 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2712 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2716 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2717 Rect bounds
= { y
, x
, y
+h
, x
+w
};