1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
39 #include "wx/toolbar.h"
46 #define wxWINDOW_HSCROLL 5998
47 #define wxWINDOW_VSCROLL 5997
48 #define MAC_SCROLLBAR_SIZE 16
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
69 wxWindowMac
* gFocusWindow
= NULL
;
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
75 #endif // __WXUNIVERSAL__/__WXMAC__
77 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 0
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
103 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
105 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
107 kEventControlVisibilityChanged
= 157
111 static const EventTypeSpec eventList
[] =
113 #if TARGET_API_MAC_OSX
114 { kEventClassControl
, kEventControlDraw
} ,
115 { kEventClassControl
, kEventControlVisibilityChanged
} ,
116 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
117 { kEventClassControl
, kEventControlHiliteChanged
} ,
118 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
119 // { kEventClassControl , kEventControlBoundsChanged } ,
127 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
129 OSStatus result
= eventNotHandledErr
;
131 wxMacCarbonEvent
cEvent( event
) ;
133 ControlRef controlRef
;
134 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
136 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
138 switch( GetEventKind( event
) )
140 case kEventControlDraw
:
142 RgnHandle updateRgn
= NULL
;
144 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
145 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
147 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
149 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
152 // in case we would need a coregraphics compliant background erase first
153 // now usable to track redraws
154 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
155 if ( thisWindow
->MacIsUserPane() )
157 static float color
= 0.5 ;
160 HIViewGetBounds( controlRef
, &bounds
);
161 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
162 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
163 CGContextFillRect( cgContext
, bounds
);
174 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
178 case kEventControlVisibilityChanged
:
179 thisWindow
->MacVisibilityChanged() ;
181 case kEventControlEnabledStateChanged
:
182 thisWindow
->MacEnabledStateChanged() ;
184 case kEventControlHiliteChanged
:
185 thisWindow
->MacHiliteChanged() ;
193 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
195 OSStatus result
= eventNotHandledErr
;
197 switch ( GetEventClass( event
) )
199 case kEventClassControl
:
200 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
208 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
210 // ---------------------------------------------------------------------------
211 // UserPane events for non OSX builds
212 // ---------------------------------------------------------------------------
214 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
216 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
217 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
218 win
->MacControlUserPaneDrawProc(part
) ;
221 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
223 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
224 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
225 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
228 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
230 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
231 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
232 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
235 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
237 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
238 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
239 win
->MacControlUserPaneIdleProc() ;
242 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
244 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
245 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
246 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
249 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
251 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
252 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
253 win
->MacControlUserPaneActivateProc(activating
) ;
256 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
258 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
259 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
260 return win
->MacControlUserPaneFocusProc(action
) ;
263 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
265 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
266 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
267 win
->MacControlUserPaneBackgroundProc(info
) ;
270 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
272 RgnHandle rgn
= NewRgn() ;
274 wxMacWindowStateSaver
sv( this ) ;
275 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
276 MacDoRedraw( rgn
, 0 ) ;
280 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
282 return kControlNoPart
;
285 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
287 return kControlNoPart
;
290 void wxWindowMac::MacControlUserPaneIdleProc()
294 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
296 return kControlNoPart
;
299 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
303 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
305 return kControlNoPart
;
308 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
312 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
313 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
314 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
315 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
316 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
317 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
318 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
319 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
321 // ===========================================================================
323 // ===========================================================================
325 wxList
wxWinMacControlList(wxKEY_INTEGER
);
327 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
329 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
332 return (wxControl
*)node
->GetData();
335 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
337 // adding NULL ControlRef is (first) surely a result of an error and
338 // (secondly) breaks native event processing
339 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
341 if ( !wxWinMacControlList
.Find((long)inControl
) )
342 wxWinMacControlList
.Append((long)inControl
, control
);
345 void wxRemoveMacControlAssociation(wxWindow
*control
)
347 wxWinMacControlList
.DeleteObject(control
);
351 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
353 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
355 // we have to setup the brush in the current port and return noErr
356 // or return an error code so that the control manager walks further up the
357 // hierarchy to find a correct background
359 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
361 OSStatus status
= paramErr
;
364 case kControlMsgApplyTextColor
:
366 case kControlMsgSetUpBackground
:
368 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
372 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
376 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
378 // this clipping is only needed for non HIView
380 RgnHandle clip
= NewRgn() ;
383 wx
->MacWindowToRootWindow( &x
,&y
) ;
384 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
385 OffsetRgn( clip
, x
, y
) ;
392 else if ( wx->MacIsUserPane() )
394 // if we don't have a valid brush for such a control, we have to call the
395 // setup of our parent ourselves
396 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
409 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
410 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
414 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
417 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
422 // ----------------------------------------------------------------------------
423 // constructors and such
424 // ----------------------------------------------------------------------------
426 void wxWindowMac::Init()
428 m_backgroundTransparent
= FALSE
;
430 // as all windows are created with WS_VISIBLE style...
433 m_hScrollBar
= NULL
;
434 m_vScrollBar
= NULL
;
435 m_macBackgroundBrush
= wxNullBrush
;
437 m_macControl
= NULL
;
439 m_macIsUserPane
= TRUE
;
441 // make sure all proc ptrs are available
443 if ( gControlUserPaneDrawUPP
== NULL
)
445 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
446 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
447 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
448 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
449 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
450 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
451 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
452 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
454 if ( wxMacLiveScrollbarActionUPP
== NULL
)
456 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
459 if ( wxMacSetupControlBackgroundUPP
== NULL
)
461 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
464 // we need a valid font for the encodings
465 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
469 wxWindowMac::~wxWindowMac()
473 m_isBeingDeleted
= TRUE
;
475 #ifndef __WXUNIVERSAL__
476 // VS: make sure there's no wxFrame with last focus set to us:
477 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
479 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
482 if ( frame
->GetLastFocus() == this )
484 frame
->SetLastFocus((wxWindow
*)NULL
);
489 #endif // __WXUNIVERSAL__
491 // wxRemoveMacControlAssociation( this ) ;
492 // If we delete an item, we should initialize the parent panel,
493 // because it could now be invalid.
494 wxWindow
*parent
= GetParent() ;
497 if (parent
->GetDefaultItem() == (wxButton
*) this)
498 parent
->SetDefaultItem(NULL
);
500 if ( (ControlRef
) m_macControl
)
502 // in case the callback might be called during destruction
503 wxRemoveMacControlAssociation( this) ;
504 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
505 ::DisposeControl( (ControlRef
) m_macControl
) ;
506 m_macControl
= NULL
;
509 if ( g_MacLastWindow
== this )
511 g_MacLastWindow
= NULL
;
514 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
517 if ( frame
->GetLastFocus() == this )
518 frame
->SetLastFocus( NULL
) ;
521 if ( gFocusWindow
== this )
523 gFocusWindow
= NULL
;
528 // delete our drop target if we've got one
529 #if wxUSE_DRAG_AND_DROP
530 if ( m_dropTarget
!= NULL
)
535 #endif // wxUSE_DRAG_AND_DROP
540 void wxWindowMac::MacInstallEventHandler()
542 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
543 GetEventTypeCount(eventList
), eventList
, this,
544 (EventHandlerRef
*)&m_macControlEventHandler
);
549 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
553 const wxString
& name
)
555 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
557 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
560 parent
->AddChild(this);
562 m_windowVariant
= parent
->GetWindowVariant() ;
564 if ( m_macIsUserPane
)
566 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
568 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
569 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
571 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
573 MacPostControlCreate(pos
,size
) ;
574 #if !TARGET_API_MAC_OSX
575 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
576 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
577 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
578 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
579 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
580 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
581 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
582 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
583 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
584 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
585 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
586 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
587 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
588 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
589 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
590 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
593 #ifndef __WXUNIVERSAL__
594 // Don't give scrollbars to wxControls unless they ask for them
595 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
596 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
598 MacCreateScrollBars( style
) ;
602 wxWindowCreateEvent
event(this);
603 GetEventHandler()->AddPendingEvent(event
);
608 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
610 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
612 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
613 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
615 MacInstallEventHandler();
617 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
618 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
619 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
621 // adjust font, controlsize etc
622 DoSetWindowVariant( m_windowVariant
) ;
624 #if !TARGET_API_MAC_OSX
625 // eventually we can fix some clipping issues be reactivating this hook
626 //if ( m_macIsUserPane )
627 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
630 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
632 wxSize new_size
= size
;
633 if (!m_macIsUserPane
)
635 wxSize
best_size( DoGetBestSize() );
638 new_size
.x
= best_size
.x
;
641 new_size
.y
= best_size
.y
;
643 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
646 SetCursor( *wxSTANDARD_CURSOR
) ;
650 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
652 wxASSERT( m_macControl
!= NULL
) ;
654 m_windowVariant
= variant
;
657 ThemeFontID themeFont
= kThemeSystemFont
;
659 // we will get that from the settings later
660 // and make this NORMAL later, but first
661 // we have a few calculations that we must fix
665 case wxWINDOW_VARIANT_NORMAL
:
666 size
= kControlSizeNormal
;
667 themeFont
= kThemeSystemFont
;
669 case wxWINDOW_VARIANT_SMALL
:
670 size
= kControlSizeSmall
;
671 themeFont
= kThemeSmallSystemFont
;
673 case wxWINDOW_VARIANT_MINI
:
674 if (UMAGetSystemVersion() >= 0x1030 )
676 // not always defined in the headers
682 size
= kControlSizeSmall
;
683 themeFont
= kThemeSmallSystemFont
;
686 case wxWINDOW_VARIANT_LARGE
:
687 size
= kControlSizeLarge
;
688 themeFont
= kThemeSystemFont
;
691 wxFAIL_MSG(_T("unexpected window variant"));
694 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
697 font
.MacCreateThemeFont( themeFont
) ;
701 void wxWindowMac::MacUpdateControlFont()
703 ControlFontStyleRec fontStyle
;
704 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
706 switch( m_font
.MacGetThemeFontID() )
708 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
709 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
710 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
711 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
713 fontStyle
.flags
= kControlUseFontMask
;
717 fontStyle
.font
= m_font
.MacGetFontNum() ;
718 fontStyle
.style
= m_font
.MacGetFontStyle() ;
719 fontStyle
.size
= m_font
.MacGetFontSize() ;
720 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
723 fontStyle
.just
= teJustLeft
;
724 fontStyle
.flags
|= kControlUseJustMask
;
725 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
726 fontStyle
.just
= teJustCenter
;
727 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
728 fontStyle
.just
= teJustRight
;
731 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
732 fontStyle
.flags
|= kControlUseForeColorMask
;
734 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
738 bool wxWindowMac::SetFont(const wxFont
& font
)
740 bool retval
= !wxWindowBase::SetFont( font
) ;
742 MacUpdateControlFont() ;
747 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
749 if ( !wxWindowBase::SetForegroundColour(col
) )
752 MacUpdateControlFont() ;
757 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
759 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
763 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
765 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
767 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
769 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
773 brush
.SetColour( col
) ;
775 MacSetBackgroundBrush( brush
) ;
777 MacUpdateControlFont() ;
783 bool wxWindowMac::MacCanFocus() const
785 wxASSERT( m_macControl
!= NULL
) ;
791 void wxWindowMac::SetFocus()
793 if ( gFocusWindow
== this )
796 if ( AcceptsFocus() )
802 if ( gFocusWindow
->m_caret
)
804 gFocusWindow
->m_caret
->OnKillFocus();
806 #endif // wxUSE_CARET
807 #ifndef __WXUNIVERSAL__
808 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
809 // TODO we must use the built-in focusing
810 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
812 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
813 control
->MacRedrawControl() ;
816 // Without testing the window id, for some reason
817 // a kill focus event can still be sent to
818 // the control just being focussed.
819 int thisId
= this->m_windowId
;
820 int gFocusWindowId
= gFocusWindow
->m_windowId
;
821 if (gFocusWindowId
!= thisId
)
823 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
824 event
.SetEventObject(gFocusWindow
);
825 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
828 gFocusWindow
= this ;
834 m_caret
->OnSetFocus();
836 #endif // wxUSE_CARET
837 // panel wants to track the window which was the last to have focus in it
838 wxChildFocusEvent
eventFocus(this);
839 GetEventHandler()->ProcessEvent(eventFocus
);
841 #ifndef __WXUNIVERSAL__
842 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
843 if ( control
&& control
->GetHandle() )
845 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
848 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
849 event
.SetEventObject(this);
850 GetEventHandler()->ProcessEvent(event
) ;
856 void wxWindowMac::DoCaptureMouse()
858 wxTheApp
->s_captureWindow
= this ;
861 wxWindow
* wxWindowBase::GetCapture()
863 return wxTheApp
->s_captureWindow
;
866 void wxWindowMac::DoReleaseMouse()
868 wxTheApp
->s_captureWindow
= NULL
;
871 #if wxUSE_DRAG_AND_DROP
873 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
875 if ( m_dropTarget
!= 0 ) {
879 m_dropTarget
= pDropTarget
;
880 if ( m_dropTarget
!= 0 )
888 // Old style file-manager drag&drop
889 void wxWindowMac::DragAcceptFiles(bool accept
)
894 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
895 int& w
, int& h
) const
898 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
903 w
= bounds
.right
- bounds
.left
;
904 h
= bounds
.bottom
- bounds
.top
;
906 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
909 Point tlworigin
= { 0 , 0 } ;
912 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
913 ::LocalToGlobal( &tlworigin
) ;
920 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
923 int& w
, int& h
) const
927 // todo the default calls may be used as soon as PostCreateControl Is moved here
928 w
= size
.x
; // WidthDefault( size.x );
929 h
= size
.y
; // HeightDefault( size.y ) ;
930 #if !TARGET_API_MAC_OSX
931 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
938 void wxWindowMac::DoGetSize(int *x
, int *y
) const
940 #if TARGET_API_MAC_OSX
941 int x1
, y1
, w1
,h1
;
942 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
948 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
949 if(x
) *x
= bounds
.right
- bounds
.left
;
950 if(y
) *y
= bounds
.bottom
- bounds
.top
;
954 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
956 #if TARGET_API_MAC_OSX
957 int x1
, y1
, w1
,h1
;
958 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
961 wxWindow
*parent
= GetParent();
964 wxPoint
pt(parent
->GetClientAreaOrigin());
973 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
974 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
976 int xx
= bounds
.left
;
977 int yy
= bounds
.top
;
979 if ( !GetParent()->IsTopLevel() )
981 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
987 wxPoint
pt(GetParent()->GetClientAreaOrigin());
996 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
998 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1000 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1003 Point localwhere
= {0,0} ;
1005 if(x
) localwhere
.h
= * x
;
1006 if(y
) localwhere
.v
= * y
;
1008 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1009 ::GlobalToLocal( &localwhere
) ;
1010 if(x
) *x
= localwhere
.h
;
1011 if(y
) *y
= localwhere
.v
;
1014 MacRootWindowToWindow( x
, y
) ;
1016 wxPoint origin
= GetClientAreaOrigin() ;
1017 if(x
) *x
-= origin
.x
;
1018 if(y
) *y
-= origin
.y
;
1021 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1023 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1024 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1026 wxPoint origin
= GetClientAreaOrigin() ;
1027 if(x
) *x
+= origin
.x
;
1028 if(y
) *y
+= origin
.y
;
1030 MacWindowToRootWindow( x
, y
) ;
1033 Point localwhere
= { 0,0 };
1034 if(x
) localwhere
.h
= * x
;
1035 if(y
) localwhere
.v
= * y
;
1037 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1038 ::LocalToGlobal( &localwhere
) ;
1039 if(x
) *x
= localwhere
.h
;
1040 if(y
) *y
= localwhere
.v
;
1044 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1046 wxPoint origin
= GetClientAreaOrigin() ;
1047 if(x
) *x
+= origin
.x
;
1048 if(y
) *y
+= origin
.y
;
1050 MacWindowToRootWindow( x
, y
) ;
1053 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1055 MacRootWindowToWindow( x
, y
) ;
1057 wxPoint origin
= GetClientAreaOrigin() ;
1058 if(x
) *x
-= origin
.x
;
1059 if(y
) *y
-= origin
.y
;
1062 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1064 #if TARGET_API_MAC_OSX
1066 if ( x
) pt
.x
= *x
;
1067 if ( y
) pt
.y
= *y
;
1069 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1071 if ( x
) *x
= (int) pt
.x
;
1072 if ( y
) *y
= (int) pt
.y
;
1074 if ( !IsTopLevel() )
1077 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1078 if(x
) *x
+= bounds
.left
;
1079 if(y
) *y
+= bounds
.top
;
1084 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1089 MacWindowToRootWindow( &x1
, &y1
) ;
1094 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1096 #if TARGET_API_MAC_OSX
1098 if ( x
) pt
.x
= *x
;
1099 if ( y
) pt
.y
= *y
;
1101 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1103 if ( x
) *x
= (int) pt
.x
;
1104 if ( y
) *y
= (int) pt
.y
;
1106 if ( !IsTopLevel() )
1109 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1110 if(x
) *x
-= bounds
.left
;
1111 if(y
) *y
-= bounds
.top
;
1116 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1121 MacRootWindowToWindow( &x1
, &y1
) ;
1126 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1128 wxSize sizeTotal
= size
;
1130 RgnHandle rgn
= NewRgn() ;
1134 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1136 GetRegionBounds( rgn
, &content
) ;
1141 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1144 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1145 #if !TARGET_API_MAC_OSX
1146 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1149 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1150 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1152 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1153 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1159 // Get size *available for subwindows* i.e. excluding menu bar etc.
1160 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1164 RgnHandle rgn
= NewRgn() ;
1166 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1168 GetRegionBounds( rgn
, &content
) ;
1173 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1175 #if !TARGET_API_MAC_OSX
1177 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1178 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1180 ww
= content
.right
- content
.left
;
1181 hh
= content
.bottom
- content
.top
;
1183 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1184 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1186 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1192 GetSize( &w
, &h
) ;
1194 MacClientToRootWindow( &x1
, &y1
) ;
1195 MacClientToRootWindow( &w
, &h
) ;
1197 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1199 int totW
= 10000 , totH
= 10000;
1202 if ( iter
->IsTopLevel() )
1204 iter
->GetSize( &totW
, &totH
) ;
1208 iter
= iter
->GetParent() ;
1211 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1213 hh
-= MAC_SCROLLBAR_SIZE
;
1219 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1221 ww
-= MAC_SCROLLBAR_SIZE
;
1233 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1235 if (m_cursor
== cursor
)
1238 if (wxNullCursor
== cursor
)
1240 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1245 if ( ! wxWindowBase::SetCursor( cursor
) )
1249 wxASSERT_MSG( m_cursor
.Ok(),
1250 wxT("cursor must be valid after call to the base version"));
1254 TODO why do we have to use current coordinates ?
1257 wxWindowMac *mouseWin ;
1260 // Change the cursor NOW if we're within the correct window
1263 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1265 if ( mouseWin == this && !wxIsBusy() )
1267 m_cursor.MacInstall() ;
1273 m_cursor
.MacInstall() ;
1280 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1282 menu
->SetInvokingWindow(this);
1284 ClientToScreen( &x
, &y
) ;
1286 menu
->MacBeforeDisplay( true ) ;
1287 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1288 if ( HiWord(menuResult
) != 0 )
1291 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1292 wxMenuItem
* item
= NULL
;
1294 item
= menu
->FindItem(id
, &realmenu
) ;
1295 if (item
->IsCheckable())
1297 item
->Check( !item
->IsChecked() ) ;
1299 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1301 menu
->MacAfterDisplay( true ) ;
1303 menu
->SetInvokingWindow(NULL
);
1309 // ----------------------------------------------------------------------------
1311 // ----------------------------------------------------------------------------
1315 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1317 wxWindowBase::DoSetToolTip(tooltip
);
1320 m_tooltip
->SetWindow(this);
1323 #endif // wxUSE_TOOLTIPS
1325 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1327 int former_x
, former_y
, former_w
, former_h
;
1328 #if !TARGET_API_MAC_OSX
1329 DoGetPosition( &former_x
, &former_y
) ;
1330 DoGetSize( &former_w
, &former_h
) ;
1332 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1335 int actualWidth
= width
;
1336 int actualHeight
= height
;
1340 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1341 actualWidth
= m_minWidth
;
1342 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1343 actualHeight
= m_minHeight
;
1344 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1345 actualWidth
= m_maxWidth
;
1346 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1347 actualHeight
= m_maxHeight
;
1349 bool doMove
= false ;
1350 bool doResize
= false ;
1352 if ( actualX
!= former_x
|| actualY
!= former_y
)
1356 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1361 if ( doMove
|| doResize
)
1363 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1364 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1365 #if TARGET_API_MAC_OSX
1366 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1368 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1369 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1370 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1372 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1374 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1376 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1378 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1380 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1382 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1384 MacRepositionScrollBars() ;
1387 wxPoint
point(actualX
,actualY
);
1388 wxMoveEvent
event(point
, m_windowId
);
1389 event
.SetEventObject(this);
1390 GetEventHandler()->ProcessEvent(event
) ;
1394 MacRepositionScrollBars() ;
1395 wxSize
size(actualWidth
, actualHeight
);
1396 wxSizeEvent
event(size
, m_windowId
);
1397 event
.SetEventObject(this);
1398 GetEventHandler()->ProcessEvent(event
);
1404 wxSize
wxWindowMac::DoGetBestSize() const
1406 if ( m_macIsUserPane
|| IsTopLevel() )
1407 return wxWindowBase::DoGetBestSize() ;
1409 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1410 short baselineoffset
;
1411 int bestWidth
, bestHeight
;
1412 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1414 if ( EmptyRect( &bestsize
) )
1417 bestsize
.left
= bestsize
.top
= 0 ;
1418 bestsize
.right
= 16 ;
1419 bestsize
.bottom
= 16 ;
1420 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1422 bestsize
.bottom
= 16 ;
1424 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1426 bestsize
.bottom
= 24 ;
1430 // return wxWindowBase::DoGetBestSize() ;
1434 bestWidth
= bestsize
.right
- bestsize
.left
;
1435 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1436 if ( bestHeight
< 10 )
1439 return wxSize(bestWidth
, bestHeight
);
1440 // return wxWindowBase::DoGetBestSize() ;
1444 // set the size of the window: if the dimensions are positive, just use them,
1445 // but if any of them is equal to -1, it means that we must find the value for
1446 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1447 // which case -1 is a valid value for x and y)
1449 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1450 // the width/height to best suit our contents, otherwise we reuse the current
1452 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1454 // get the current size and position...
1455 int currentX
, currentY
;
1456 GetPosition(¤tX
, ¤tY
);
1458 int currentW
,currentH
;
1459 GetSize(¤tW
, ¤tH
);
1461 // ... and don't do anything (avoiding flicker) if it's already ok
1462 if ( x
== currentX
&& y
== currentY
&&
1463 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1466 MacRepositionScrollBars() ; // we might have a real position shift
1470 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1472 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1475 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1477 wxSize
size(-1, -1);
1480 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1482 size
= DoGetBestSize();
1487 // just take the current one
1494 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1498 size
= DoGetBestSize();
1500 //else: already called DoGetBestSize() above
1506 // just take the current one
1511 DoMoveWindow(x
, y
, width
, height
);
1515 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1517 RgnHandle rgn
= NewRgn() ;
1519 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1520 GetRegionBounds( rgn
, &content
) ;
1522 #if !TARGET_API_MAC_OSX
1524 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1525 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1528 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1531 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1533 if ( clientheight
!= -1 || clientheight
!= -1 )
1535 int currentclientwidth
, currentclientheight
;
1536 int currentwidth
, currentheight
;
1538 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1539 GetSize( ¤twidth
, ¤theight
) ;
1541 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1542 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1546 void wxWindowMac::SetTitle(const wxString
& title
)
1548 m_label
= wxStripMenuCodes(title
) ;
1552 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1557 wxString
wxWindowMac::GetTitle() const
1562 bool wxWindowMac::Show(bool show
)
1564 if ( !wxWindowBase::Show(show
) )
1567 // TODO use visibilityChanged Carbon Event for OSX
1568 bool former
= MacIsReallyShown() ;
1570 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1571 if ( former
!= MacIsReallyShown() )
1572 MacPropagateVisibilityChanged() ;
1576 bool wxWindowMac::Enable(bool enable
)
1578 wxASSERT( m_macControl
!= NULL
) ;
1579 if ( !wxWindowBase::Enable(enable
) )
1582 bool former
= MacIsReallyEnabled() ;
1584 EnableControl( (ControlRef
) m_macControl
) ;
1586 DisableControl( (ControlRef
) m_macControl
) ;
1588 if ( former
!= MacIsReallyEnabled() )
1589 MacPropagateEnabledStateChanged() ;
1594 // status change propagations (will be not necessary for OSX later )
1597 void wxWindowMac::MacPropagateVisibilityChanged()
1599 #if !TARGET_API_MAC_OSX
1600 MacVisibilityChanged() ;
1602 wxWindowListNode
*node
= GetChildren().GetFirst();
1605 wxWindowMac
*child
= node
->GetData();
1606 if ( child
->IsShown() )
1607 child
->MacPropagateVisibilityChanged( ) ;
1608 node
= node
->GetNext();
1613 void wxWindowMac::MacPropagateEnabledStateChanged( )
1615 #if !TARGET_API_MAC_OSX
1616 MacEnabledStateChanged() ;
1618 wxWindowListNode
*node
= GetChildren().GetFirst();
1621 wxWindowMac
*child
= node
->GetData();
1622 if ( child
->IsEnabled() )
1623 child
->MacPropagateEnabledStateChanged() ;
1624 node
= node
->GetNext();
1629 void wxWindowMac::MacPropagateHiliteChanged( )
1631 #if !TARGET_API_MAC_OSX
1632 MacHiliteChanged() ;
1634 wxWindowListNode
*node
= GetChildren().GetFirst();
1637 wxWindowMac
*child
= node
->GetData();
1638 // if ( child->IsEnabled() )
1639 child
->MacPropagateHiliteChanged() ;
1640 node
= node
->GetNext();
1646 // status change notifications
1649 void wxWindowMac::MacVisibilityChanged()
1653 void wxWindowMac::MacHiliteChanged()
1657 void wxWindowMac::MacEnabledStateChanged()
1662 // status queries on the inherited window's state
1665 bool wxWindowMac::MacIsReallyShown()
1667 // only under OSX the visibility of the TLW is taken into account
1668 #if TARGET_API_MAC_OSX
1669 return IsControlVisible( (ControlRef
) m_macControl
) ;
1671 wxWindow
* win
= this ;
1672 while( win
->IsShown() )
1674 if ( win
->IsTopLevel() )
1677 win
= win
->GetParent() ;
1686 bool wxWindowMac::MacIsReallyEnabled()
1688 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1691 bool wxWindowMac::MacIsReallyHilited()
1693 return IsControlActive( (ControlRef
) m_macControl
) ;
1700 int wxWindowMac::GetCharHeight() const
1702 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1703 return dc
.GetCharHeight() ;
1706 int wxWindowMac::GetCharWidth() const
1708 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1709 return dc
.GetCharWidth() ;
1712 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1713 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1715 const wxFont
*fontToUse
= theFont
;
1717 fontToUse
= &m_font
;
1719 wxClientDC
dc( (wxWindowMac
*) this ) ;
1721 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1722 if ( externalLeading
)
1723 *externalLeading
= le
;
1733 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1734 * we always intersect with the entire window, not only with the client area
1737 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1739 #if TARGET_API_MAC_OSX
1741 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1744 RgnHandle update
= NewRgn() ;
1745 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1746 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1747 wxPoint origin
= GetClientAreaOrigin() ;
1748 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1749 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1753 RgnHandle updateRgn = NewRgn() ;
1756 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1760 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1761 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1763 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1764 DisposeRgn(updateRgn) ;
1766 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1768 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1769 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1772 if ( MacGetTopLevelWindow() == NULL )
1775 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1778 wxPoint client = GetClientAreaOrigin();
1781 int x2 = m_width - client.x;
1782 int y2 = m_height - client.y;
1784 if (IsKindOf( CLASSINFO(wxButton)))
1786 // buttons have an "aura"
1793 Rect clientrect = { y1, x1, y2, x2 };
1797 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1798 SectRect( &clientrect , &r , &clientrect ) ;
1801 if ( !EmptyRect( &clientrect ) )
1803 int top = 0 , left = 0 ;
1805 MacClientToRootWindow( &left , &top ) ;
1806 OffsetRect( &clientrect , left , top ) ;
1808 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1814 void wxWindowMac::MacRedrawControl()
1817 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1819 #if TARGET_API_MAC_CARBON
1822 wxClientDC dc(this) ;
1823 wxMacPortSetter helper(&dc) ;
1824 wxMacWindowClipper clipper(this) ;
1825 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1826 UMADrawControl( (ControlRef) m_macControl ) ;
1833 void wxWindowMac::OnPaint(wxPaintEvent& event)
1835 // why don't we skip that here ?
1839 wxWindowMac
*wxGetActiveWindow()
1841 // actually this is a windows-only concept
1845 // Coordinates relative to the window
1846 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1848 // We really don't move the mouse programmatically under Mac.
1851 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1853 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1858 event
.GetDC()->Clear() ;
1861 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1863 wxWindowDC
dc(this) ;
1864 wxMacPortSetter
helper(&dc
) ;
1866 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1869 int wxWindowMac::GetScrollPos(int orient
) const
1871 if ( orient
== wxHORIZONTAL
)
1874 return m_hScrollBar
->GetThumbPosition() ;
1879 return m_vScrollBar
->GetThumbPosition() ;
1884 // This now returns the whole range, not just the number
1885 // of positions that we can scroll.
1886 int wxWindowMac::GetScrollRange(int orient
) const
1888 if ( orient
== wxHORIZONTAL
)
1891 return m_hScrollBar
->GetRange() ;
1896 return m_vScrollBar
->GetRange() ;
1901 int wxWindowMac::GetScrollThumb(int orient
) const
1903 if ( orient
== wxHORIZONTAL
)
1906 return m_hScrollBar
->GetThumbSize() ;
1911 return m_vScrollBar
->GetThumbSize() ;
1916 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1918 if ( orient
== wxHORIZONTAL
)
1921 m_hScrollBar
->SetThumbPosition( pos
) ;
1926 m_vScrollBar
->SetThumbPosition( pos
) ;
1930 void wxWindowMac::MacPaintBorders( int left
, int top
)
1936 wxGetOsVersion( &major
, &minor
);
1938 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1939 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1941 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1942 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1943 // OS X has lighter border edges than classic:
1946 darkShadow
.red
= 0x8E8E;
1947 darkShadow
.green
= 0x8E8E;
1948 darkShadow
.blue
= 0x8E8E;
1949 lightShadow
.red
= 0xBDBD;
1950 lightShadow
.green
= 0xBDBD;
1951 lightShadow
.blue
= 0xBDBD;
1957 GetSize( &w
, &h
) ;
1958 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1960 #if wxMAC_USE_THEME_BORDER
1961 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1964 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1965 InsetRect( &rect , border , border );
1966 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1969 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1971 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1972 RGBForeColor( &face
);
1973 MoveTo( left
+ 0 , top
+ h
- 2 );
1974 LineTo( left
+ 0 , top
+ 0 );
1975 LineTo( left
+ w
- 2 , top
+ 0 );
1977 MoveTo( left
+ 2 , top
+ h
- 3 );
1978 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1979 LineTo( left
+ w
- 3 , top
+ 2 );
1981 RGBForeColor( sunken
? &face
: &darkShadow
);
1982 MoveTo( left
+ 0 , top
+ h
- 1 );
1983 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1984 LineTo( left
+ w
- 1 , top
+ 0 );
1986 RGBForeColor( sunken
? &lightShadow
: &white
);
1987 MoveTo( left
+ 1 , top
+ h
- 3 );
1988 LineTo( left
+ 1, top
+ 1 );
1989 LineTo( left
+ w
- 3 , top
+ 1 );
1991 RGBForeColor( sunken
? &white
: &lightShadow
);
1992 MoveTo( left
+ 1 , top
+ h
- 2 );
1993 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1994 LineTo( left
+ w
- 2 , top
+ 1 );
1996 RGBForeColor( sunken
? &darkShadow
: &face
);
1997 MoveTo( left
+ 2 , top
+ h
- 4 );
1998 LineTo( left
+ 2 , top
+ 2 );
1999 LineTo( left
+ w
- 4 , top
+ 2 );
2002 else if (HasFlag(wxSIMPLE_BORDER
))
2004 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2005 RGBForeColor( &darkShadow
) ;
2006 FrameRect( &rect
) ;
2010 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2012 if ( child
== m_hScrollBar
)
2013 m_hScrollBar
= NULL
;
2014 if ( child
== m_vScrollBar
)
2015 m_vScrollBar
= NULL
;
2017 wxWindowBase::RemoveChild( child
) ;
2020 // New function that will replace some of the above.
2021 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2022 int range
, bool refresh
)
2024 if ( orient
== wxHORIZONTAL
)
2028 if ( range
== 0 || thumbVisible
>= range
)
2030 if ( m_hScrollBar
->IsShown() )
2031 m_hScrollBar
->Show(false) ;
2035 if ( !m_hScrollBar
->IsShown() )
2036 m_hScrollBar
->Show(true) ;
2037 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2045 if ( range
== 0 || thumbVisible
>= range
)
2047 if ( m_vScrollBar
->IsShown() )
2048 m_vScrollBar
->Show(false) ;
2052 if ( !m_vScrollBar
->IsShown() )
2053 m_vScrollBar
->Show(true) ;
2054 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2058 MacRepositionScrollBars() ;
2061 // Does a physical scroll
2062 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2064 if( dx
== 0 && dy
==0 )
2069 wxClientDC
dc(this) ;
2070 wxMacPortSetter
helper(&dc
) ;
2072 int width
, height
;
2073 GetClientSize( &width
, &height
) ;
2080 // TODO take out the boundaries
2081 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2083 RgnHandle updateRgn
= NewRgn() ;
2086 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2087 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2088 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2090 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2092 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2093 // but it seems the update only refreshes the background of the control, rather than calling
2094 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2095 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2098 // we also have to scroll the update rgn in this rectangle
2099 // in order not to loose updates
2101 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2102 RgnHandle formerUpdateRgn
= NewRgn() ;
2103 RgnHandle scrollRgn
= NewRgn() ;
2104 RectRgn( scrollRgn
, &scrollrect
) ;
2105 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2107 LocalToGlobal( &pt
) ;
2108 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2109 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2110 if ( !EmptyRgn( formerUpdateRgn
) )
2112 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2113 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2114 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2116 InvalWindowRgn(rootWindow
, updateRgn
) ;
2117 DisposeRgn( updateRgn
) ;
2118 DisposeRgn( formerUpdateRgn
) ;
2119 DisposeRgn( scrollRgn
) ;
2123 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2125 wxWindowMac
*child
= node
->GetData();
2126 if (child
== m_vScrollBar
) continue;
2127 if (child
== m_hScrollBar
) continue;
2128 if (child
->IsTopLevel()) continue;
2131 child
->GetPosition( &x
, &y
);
2133 child
->GetSize( &w
, &h
);
2137 if (rect
->Intersects(rc
))
2138 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2142 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2146 // TODO remove, was moved higher up Update() ;
2150 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2152 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2154 wxScrollWinEvent wevent
;
2155 wevent
.SetPosition(event
.GetPosition());
2156 wevent
.SetOrientation(event
.GetOrientation());
2157 wevent
.m_eventObject
= this;
2159 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2160 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2161 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2162 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2163 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2164 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2165 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2166 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2167 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2168 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2169 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2170 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2171 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2172 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2173 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2174 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2176 GetEventHandler()->ProcessEvent(wevent
);
2180 // Get the window with the focus
2181 wxWindowMac
*wxWindowBase::FindFocus()
2183 return gFocusWindow
;
2186 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2188 // panel wants to track the window which was the last to have focus in it,
2189 // so we want to set ourselves as the window which last had focus
2191 // notice that it's also important to do it upwards the tree becaus
2192 // otherwise when the top level panel gets focus, it won't set it back to
2193 // us, but to some other sibling
2195 // CS:don't know if this is still needed:
2196 //wxChildFocusEvent eventFocus(this);
2197 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2202 void wxWindowMac::OnInternalIdle()
2204 // This calls the UI-update mechanism (querying windows for
2205 // menu/toolbar/control state information)
2206 if (wxUpdateUIEvent::CanUpdate(this))
2207 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2210 // Raise the window to the top of the Z order
2211 void wxWindowMac::Raise()
2215 // Lower the window to the bottom of the Z order
2216 void wxWindowMac::Lower()
2221 // static wxWindow *gs_lastWhich = NULL;
2223 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2225 // first trigger a set cursor event
2227 wxPoint clientorigin
= GetClientAreaOrigin() ;
2228 wxSize clientsize
= GetClientSize() ;
2230 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2232 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2234 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2235 if ( processedEvtSetCursor
&& event
.HasCursor() )
2237 cursor
= event
.GetCursor() ;
2242 // the test for processedEvtSetCursor is here to prevent using m_cursor
2243 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2244 // it - this is a way to say that our cursor shouldn't be used for this
2246 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2256 cursor
= *wxSTANDARD_CURSOR
;
2260 cursor
.MacInstall() ;
2262 return cursor
.Ok() ;
2265 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2269 return m_tooltip
->GetTip() ;
2271 return wxEmptyString
;
2274 void wxWindowMac::Update()
2276 #if TARGET_API_MAC_OSX
2277 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2279 ::Draw1Control( (ControlRef
) m_macControl
) ;
2283 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2285 wxTopLevelWindowMac
* win
= NULL
;
2286 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2289 win
= wxFindWinFromMacWindow( window
) ;
2293 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2297 RgnHandle visRgn
= NewRgn() ;
2298 RgnHandle tempRgn
= NewRgn() ;
2299 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2301 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2302 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2304 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2305 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2314 if ( includeOuterStructures
)
2315 InsetRect( &r
, -3 , -3 ) ;
2316 RectRgn( visRgn
, &r
) ;
2317 if ( !IsTopLevel() )
2319 wxWindow
* child
= this ;
2320 wxWindow
* parent
= child
->GetParent() ;
2325 // we have to find a better clipping algorithm here, in order not to clip things
2326 // positioned like status and toolbar
2327 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2329 size
= parent
->GetSize() ;
2334 size
= parent
->GetClientSize() ;
2335 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2339 parent
->MacWindowToRootWindow( &x
, &y
) ;
2340 MacRootWindowToWindow( &x
, &y
) ;
2342 SetRectRgn( tempRgn
,
2343 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2344 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2345 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2347 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2348 if ( parent
->IsTopLevel() )
2351 parent
= child
->GetParent() ;
2356 wxRegion vis
= visRgn
;
2357 DisposeRgn( visRgn
) ;
2358 DisposeRgn( tempRgn
) ;
2363 This function must not change the updatergn !
2365 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2367 // we let the OS handle root control redraws
2368 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2371 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2372 bool handled
= false ;
2374 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2376 RgnHandle newupdate
= NewRgn() ;
2377 wxSize point
= GetClientSize() ;
2378 wxPoint origin
= GetClientAreaOrigin() ;
2379 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2380 SectRgn( newupdate
, updatergn
, newupdate
) ;
2381 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2382 m_updateRegion
= newupdate
;
2383 DisposeRgn( newupdate
) ;
2386 if ( !EmptyRgn(updatergn
) )
2388 wxWindowDC
dc(this);
2389 if (!EmptyRgn(updatergn
))
2390 dc
.SetClippingRegion(wxRegion(updatergn
));
2392 wxEraseEvent
eevent( GetId(), &dc
);
2393 eevent
.SetEventObject( this );
2394 GetEventHandler()->ProcessEvent( eevent
);
2396 if ( !m_updateRegion
.Empty() )
2398 // paint the window itself
2400 event
.m_timeStamp
= time
;
2401 event
.SetEventObject(this);
2402 handled
= GetEventHandler()->ProcessEvent(event
);
2404 // paint custom borders
2405 wxNcPaintEvent
eventNc( GetId() );
2406 eventNc
.SetEventObject( this );
2407 GetEventHandler()->ProcessEvent( eventNc
);
2413 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2415 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2416 // updatergn is always already clipped to our boundaries
2417 // if we are in compositing mode then it is in relative to the upper left of the control
2418 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2419 // of the toplevel window
2420 // it is in window coordinates, not in client coordinates
2422 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2423 RgnHandle ownUpdateRgn
= NewRgn() ;
2424 CopyRgn( updatergn
, ownUpdateRgn
) ;
2426 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2429 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2430 RgnHandle controlRgn
= NewRgn();
2431 RectRgn( controlRgn
, &bounds
);
2432 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2433 // the window update region
2434 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2435 DisposeRgn( controlRgn
);
2437 //KO: convert ownUpdateRgn to local coordinates
2438 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2441 MacDoRedraw( ownUpdateRgn
, time
) ;
2442 DisposeRgn( ownUpdateRgn
) ;
2446 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2448 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2452 if ( iter
->IsTopLevel() )
2453 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2455 iter
= iter
->GetParent() ;
2457 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2461 void wxWindowMac::MacCreateScrollBars( long style
)
2463 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2465 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2466 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2468 GetClientSize( &width
, &height
) ;
2470 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2471 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2472 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2473 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2475 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2476 vSize
, wxVERTICAL
);
2478 if ( style
& wxVSCROLL
)
2484 m_vScrollBar
->Show(false) ;
2486 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2487 hSize
, wxHORIZONTAL
);
2488 if ( style
& wxHSCROLL
)
2493 m_hScrollBar
->Show(false) ;
2496 // because the create does not take into account the client area origin
2497 MacRepositionScrollBars() ; // we might have a real position shift
2500 void wxWindowMac::MacRepositionScrollBars()
2502 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2503 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2505 // get real client area
2509 GetSize( &width
, &height
) ;
2511 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2512 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2514 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2515 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2516 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2517 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2523 GetSize( &w
, &h
) ;
2525 MacClientToRootWindow( &x
, &y
) ;
2526 MacClientToRootWindow( &w
, &h
) ;
2528 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2530 int totW
= 10000 , totH
= 10000;
2533 if ( iter
->IsTopLevel() )
2535 iter
->GetSize( &totW
, &totH
) ;
2539 iter
= iter
->GetParent() ;
2567 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2571 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2575 bool wxWindowMac::AcceptsFocus() const
2577 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2580 void wxWindowMac::MacSuperChangedPosition()
2582 // only window-absolute structures have to be moved i.e. controls
2584 wxWindowListNode
*node
= GetChildren().GetFirst();
2587 wxWindowMac
*child
= node
->GetData();
2588 child
->MacSuperChangedPosition() ;
2589 node
= node
->GetNext();
2593 void wxWindowMac::MacTopLevelWindowChangedPosition()
2595 // only screen-absolute structures have to be moved i.e. glcanvas
2597 wxWindowListNode
*node
= GetChildren().GetFirst();
2600 wxWindowMac
*child
= node
->GetData();
2601 child
->MacTopLevelWindowChangedPosition() ;
2602 node
= node
->GetNext();
2606 long wxWindowMac::MacGetLeftBorderSize( ) const
2611 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2614 #if wxMAC_USE_THEME_BORDER
2615 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2619 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2622 #if wxMAC_USE_THEME_BORDER
2623 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2627 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2634 long wxWindowMac::MacGetRightBorderSize( ) const
2636 // they are all symmetric in mac themes
2637 return MacGetLeftBorderSize() ;
2640 long wxWindowMac::MacGetTopBorderSize( ) const
2642 // they are all symmetric in mac themes
2643 return MacGetLeftBorderSize() ;
2646 long wxWindowMac::MacGetBottomBorderSize( ) const
2648 // they are all symmetric in mac themes
2649 return MacGetLeftBorderSize() ;
2652 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2654 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2657 // Find the wxWindowMac at the current mouse position, returning the mouse
2659 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2661 pt
= wxGetMousePosition();
2662 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2666 // Get the current mouse position.
2667 wxPoint
wxGetMousePosition()
2670 wxGetMousePosition(& x
, & y
);
2671 return wxPoint(x
, y
);
2674 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2676 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2678 // copied from wxGTK : CS
2679 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2682 // (a) it's a command event and so is propagated to the parent
2683 // (b) under MSW it can be generated from kbd too
2684 // (c) it uses screen coords (because of (a))
2685 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2687 this->ClientToScreen(event
.GetPosition()));
2688 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2691 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2697 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2699 // OS Needs it in tlw content area coordinates
2700 MacClientToRootWindow( &x
, &y
) ;
2704 // OS Needs it in window not client coordinates
2705 wxPoint origin
= GetClientAreaOrigin() ;
2710 SInt16 controlpart
;
2715 short modifiers
= 0;
2717 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2718 modifiers
|= btnState
;
2720 if ( event
.m_shiftDown
)
2721 modifiers
|= shiftKey
;
2723 if ( event
.m_controlDown
)
2724 modifiers
|= controlKey
;
2726 if ( event
.m_altDown
)
2727 modifiers
|= optionKey
;
2729 if ( event
.m_metaDown
)
2730 modifiers
|= cmdKey
;
2732 bool handled
= false ;
2734 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2736 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2737 wxTheApp
->s_lastMouseDown
= 0 ;
2738 if ( controlpart
!= kControlNoPart
)
2740 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2753 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2755 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2758 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2762 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2763 Rect bounds
= { y
, x
, y
+h
, x
+w
};