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 , kEventControlInvalidateForSizeChange } , // 10.3 only
110 // { kEventClassControl , kEventControlBoundsChanged } ,
111 // kEventControlEnabledStateChanged , kEventControlVisibilityChanged , kEventControlHiliteChanged
117 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
119 OSStatus result
= eventNotHandledErr
;
121 wxMacCarbonEvent
cEvent( event
) ;
123 ControlRef controlRef
;
124 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
126 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
128 switch( GetEventKind( event
) )
130 case kEventControlDraw
:
132 RgnHandle updateRgn
= cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
) ;
133 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
135 #if 0 // in case we would need a coregraphics compliant background erase first
136 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
137 if ( thisWindow
->MacIsUserPane() )
140 err
= HIViewGetBounds( controlRef
, &bounds
);
141 CGContextSetRGBFillColor( cgContext
, 1 , 1 , 1 , 1 );
142 // CGContextSetRGBFillColor( cgContext, .95, .95, .95, 1 );
143 CGContextFillRect( cgContext
, bounds
);
146 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
149 result
= eventNotHandledErr
;
158 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
160 OSStatus result
= eventNotHandledErr
;
162 switch ( GetEventClass( event
) )
164 case kEventClassControl
:
165 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
173 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
175 // ---------------------------------------------------------------------------
176 // UserPane events for non OSX builds
177 // ---------------------------------------------------------------------------
179 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
181 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
182 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
183 win
->MacControlUserPaneDrawProc(part
) ;
186 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
188 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
189 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
190 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
193 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
195 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
196 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
197 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
200 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
202 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
203 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
204 win
->MacControlUserPaneIdleProc() ;
207 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
209 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
210 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
211 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
214 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
216 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
217 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
218 win
->MacControlUserPaneActivateProc(activating
) ;
221 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
223 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
224 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
225 return win
->MacControlUserPaneFocusProc(action
) ;
228 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
230 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
231 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
232 win
->MacControlUserPaneBackgroundProc(info
) ;
235 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
237 MacDoRedraw( MacGetVisibleRegion().GetWXHRGN() , 0 ) ;
240 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
242 return kControlNoPart
;
245 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
247 return kControlNoPart
;
250 void wxWindowMac::MacControlUserPaneIdleProc()
254 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
256 return kControlNoPart
;
259 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
263 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
265 return kControlNoPart
;
268 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
272 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
273 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
274 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
275 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
276 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
277 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
278 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
279 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
281 // ===========================================================================
283 // ===========================================================================
285 wxList
wxWinMacControlList(wxKEY_INTEGER
);
287 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
289 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
292 return (wxControl
*)node
->GetData();
295 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
297 // adding NULL ControlRef is (first) surely a result of an error and
298 // (secondly) breaks native event processing
299 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
301 if ( !wxWinMacControlList
.Find((long)inControl
) )
302 wxWinMacControlList
.Append((long)inControl
, control
);
305 void wxRemoveMacControlAssociation(wxWindow
*control
)
307 wxWinMacControlList
.DeleteObject(control
);
311 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
313 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
315 // we have to setup the brush in the current port and return noErr
316 // or return an error code so that the control manager walks further up the
317 // hierarchy to find a correct background
319 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
321 OSStatus status
= paramErr
;
324 case kControlMsgApplyTextColor
:
326 case kControlMsgSetUpBackground
:
328 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
332 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
336 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
338 // this clipping is only needed for non HIView
340 RgnHandle clip
= NewRgn() ;
343 wx
->MacWindowToRootWindow( &x
,&y
) ;
344 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
345 OffsetRgn( clip
, x
, y
) ;
352 else if ( wx->MacIsUserPane() )
354 // if we don't have a valid brush for such a control, we have to call the
355 // setup of our parent ourselves
356 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
369 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
370 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
374 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
377 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
382 // ----------------------------------------------------------------------------
383 // constructors and such
384 // ----------------------------------------------------------------------------
386 void wxWindowMac::Init()
388 m_backgroundTransparent
= FALSE
;
390 // as all windows are created with WS_VISIBLE style...
393 m_hScrollBar
= NULL
;
394 m_vScrollBar
= NULL
;
395 m_macBackgroundBrush
= wxNullBrush
;
397 m_macControl
= NULL
;
399 m_macIsUserPane
= TRUE
;
401 // make sure all proc ptrs are available
403 if ( gControlUserPaneDrawUPP
== NULL
)
405 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
406 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
407 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
408 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
409 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
410 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
411 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
412 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
414 if ( wxMacLiveScrollbarActionUPP
== NULL
)
416 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
419 if ( wxMacSetupControlBackgroundUPP
== NULL
)
421 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
427 wxWindowMac::~wxWindowMac()
431 m_isBeingDeleted
= TRUE
;
433 #ifndef __WXUNIVERSAL__
434 // VS: make sure there's no wxFrame with last focus set to us:
435 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
437 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
440 if ( frame
->GetLastFocus() == this )
442 frame
->SetLastFocus((wxWindow
*)NULL
);
447 #endif // __WXUNIVERSAL__
449 // wxRemoveMacControlAssociation( this ) ;
450 // If we delete an item, we should initialize the parent panel,
451 // because it could now be invalid.
452 wxWindow
*parent
= GetParent() ;
455 if (parent
->GetDefaultItem() == (wxButton
*) this)
456 parent
->SetDefaultItem(NULL
);
458 if ( (ControlRef
) m_macControl
)
460 // in case the callback might be called during destruction
461 wxRemoveMacControlAssociation( this) ;
462 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
463 ::DisposeControl( (ControlRef
) m_macControl
) ;
464 m_macControl
= NULL
;
467 if ( g_MacLastWindow
== this )
469 g_MacLastWindow
= NULL
;
472 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
475 if ( frame
->GetLastFocus() == this )
476 frame
->SetLastFocus( NULL
) ;
479 if ( gFocusWindow
== this )
481 gFocusWindow
= NULL
;
486 // delete our drop target if we've got one
487 #if wxUSE_DRAG_AND_DROP
488 if ( m_dropTarget
!= NULL
)
493 #endif // wxUSE_DRAG_AND_DROP
498 void wxWindowMac::MacInstallEventHandler()
500 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
501 GetEventTypeCount(eventList
), eventList
, this,
502 (EventHandlerRef
*)&m_macControlEventHandler
);
507 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
511 const wxString
& name
)
513 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
515 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
518 parent
->AddChild(this);
520 m_windowVariant
= parent
->GetWindowVariant() ;
522 if ( m_macIsUserPane
)
524 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
526 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
/*| kControlHasSpecialBackground */ | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
528 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
530 MacPostControlCreate(pos
,size
) ;
531 #if !TARGET_API_MAC_OSX
532 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
533 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
534 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
535 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
536 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
537 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
538 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
539 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
540 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
541 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
542 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
543 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
544 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
545 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
546 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
547 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
550 #ifndef __WXUNIVERSAL__
551 // Don't give scrollbars to wxControls unless they ask for them
552 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
553 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
555 MacCreateScrollBars( style
) ;
559 wxWindowCreateEvent
event(this);
560 GetEventHandler()->AddPendingEvent(event
);
565 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
567 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
569 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
570 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
572 MacInstallEventHandler();
574 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
575 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
576 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
578 // adjust font, controlsize etc
579 DoSetWindowVariant( m_windowVariant
) ;
581 #if !TARGET_API_MAC_OSX
582 // eventually we can fix some clipping issues be reactivating this hook
583 //if ( m_macIsUserPane )
584 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
587 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
589 wxSize new_size
= size
;
590 if (!m_macIsUserPane
)
592 wxSize
best_size( DoGetBestSize() );
595 new_size
.x
= best_size
.x
;
598 new_size
.y
= best_size
.y
;
600 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
603 SetCursor( *wxSTANDARD_CURSOR
) ;
607 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
609 wxASSERT( m_macControl
!= NULL
) ;
611 m_windowVariant
= variant
;
614 ThemeFontID themeFont
= kThemeSystemFont
;
616 // we will get that from the settings later
617 // and make this NORMAL later, but first
618 // we have a few calculations that we must fix
622 case wxWINDOW_VARIANT_NORMAL
:
623 size
= kControlSizeNormal
;
624 themeFont
= kThemeSystemFont
;
626 case wxWINDOW_VARIANT_SMALL
:
627 size
= kControlSizeSmall
;
628 themeFont
= kThemeSmallSystemFont
;
630 case wxWINDOW_VARIANT_MINI
:
631 if (UMAGetSystemVersion() >= 0x1030 )
633 // not always defined in the headers
639 size
= kControlSizeSmall
;
640 themeFont
= kThemeSmallSystemFont
;
643 case wxWINDOW_VARIANT_LARGE
:
644 size
= kControlSizeLarge
;
645 themeFont
= kThemeSystemFont
;
648 wxFAIL_MSG(_T("unexpected window variant"));
651 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
654 font
.MacCreateThemeFont( themeFont
) ;
658 void wxWindowMac::MacUpdateControlFont()
660 ControlFontStyleRec fontStyle
;
661 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
663 switch( m_font
.MacGetThemeFontID() )
665 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
666 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
667 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
668 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
670 fontStyle
.flags
= kControlUseFontMask
;
674 fontStyle
.font
= m_font
.MacGetFontNum() ;
675 fontStyle
.style
= m_font
.MacGetFontStyle() ;
676 fontStyle
.size
= m_font
.MacGetFontSize() ;
677 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
680 fontStyle
.just
= teJustLeft
;
681 fontStyle
.flags
|= kControlUseJustMask
;
682 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
683 fontStyle
.just
= teJustCenter
;
684 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
685 fontStyle
.just
= teJustRight
;
688 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
689 fontStyle
.flags
|= kControlUseForeColorMask
;
691 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
695 bool wxWindowMac::SetFont(const wxFont
& font
)
697 bool retval
= !wxWindowBase::SetFont( font
) ;
699 MacUpdateControlFont() ;
704 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
706 if ( !wxWindowBase::SetForegroundColour(col
) )
709 MacUpdateControlFont() ;
714 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
716 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
720 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
722 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
724 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
726 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
730 brush
.SetColour( col
) ;
732 MacSetBackgroundBrush( brush
) ;
734 MacUpdateControlFont() ;
740 bool wxWindowMac::MacCanFocus() const
742 wxASSERT( m_macControl
!= NULL
) ;
748 void wxWindowMac::SetFocus()
750 if ( gFocusWindow
== this )
753 if ( AcceptsFocus() )
759 if ( gFocusWindow
->m_caret
)
761 gFocusWindow
->m_caret
->OnKillFocus();
763 #endif // wxUSE_CARET
764 #ifndef __WXUNIVERSAL__
765 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
766 // TODO we must use the built-in focusing
767 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
769 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
770 control
->MacRedrawControl() ;
773 // Without testing the window id, for some reason
774 // a kill focus event can still be sent to
775 // the control just being focussed.
776 int thisId
= this->m_windowId
;
777 int gFocusWindowId
= gFocusWindow
->m_windowId
;
778 if (gFocusWindowId
!= thisId
)
780 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
781 event
.SetEventObject(gFocusWindow
);
782 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
785 gFocusWindow
= this ;
791 m_caret
->OnSetFocus();
793 #endif // wxUSE_CARET
794 // panel wants to track the window which was the last to have focus in it
795 wxChildFocusEvent
eventFocus(this);
796 GetEventHandler()->ProcessEvent(eventFocus
);
798 #ifndef __WXUNIVERSAL__
799 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
800 if ( control
&& control
->GetHandle() )
802 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
805 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
806 event
.SetEventObject(this);
807 GetEventHandler()->ProcessEvent(event
) ;
813 void wxWindowMac::DoCaptureMouse()
815 wxTheApp
->s_captureWindow
= this ;
818 wxWindow
* wxWindowBase::GetCapture()
820 return wxTheApp
->s_captureWindow
;
823 void wxWindowMac::DoReleaseMouse()
825 wxTheApp
->s_captureWindow
= NULL
;
828 #if wxUSE_DRAG_AND_DROP
830 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
832 if ( m_dropTarget
!= 0 ) {
836 m_dropTarget
= pDropTarget
;
837 if ( m_dropTarget
!= 0 )
845 // Old style file-manager drag&drop
846 void wxWindowMac::DragAcceptFiles(bool accept
)
851 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
852 int& w
, int& h
) const
855 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
860 w
= bounds
.right
- bounds
.left
;
861 h
= bounds
.bottom
- bounds
.top
;
863 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
866 Point tlworigin
= { 0 , 0 } ;
869 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
870 ::LocalToGlobal( &tlworigin
) ;
877 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
880 int& w
, int& h
) const
884 // todo the default calls may be used as soon as PostCreateControl Is moved here
885 w
= size
.x
; // WidthDefault( size.x );
886 h
= size
.y
; // HeightDefault( size.y ) ;
887 #if !TARGET_API_MAC_OSX
888 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
895 void wxWindowMac::DoGetSize(int *x
, int *y
) const
897 #if TARGET_API_MAC_OSX
898 int x1
, y1
, w1
,h1
;
899 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
905 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
906 if(x
) *x
= bounds
.right
- bounds
.left
;
907 if(y
) *y
= bounds
.bottom
- bounds
.top
;
911 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
913 #if TARGET_API_MAC_OSX
914 int x1
, y1
, w1
,h1
;
915 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
918 wxWindow
*parent
= GetParent();
921 wxPoint
pt(parent
->GetClientAreaOrigin());
930 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
931 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
933 int xx
= bounds
.left
;
934 int yy
= bounds
.top
;
936 if ( !GetParent()->IsTopLevel() )
938 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
944 wxPoint
pt(GetParent()->GetClientAreaOrigin());
953 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
955 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
957 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
960 Point localwhere
= {0,0} ;
962 if(x
) localwhere
.h
= * x
;
963 if(y
) localwhere
.v
= * y
;
965 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
966 ::GlobalToLocal( &localwhere
) ;
967 if(x
) *x
= localwhere
.h
;
968 if(y
) *y
= localwhere
.v
;
971 MacRootWindowToWindow( x
, y
) ;
973 wxPoint origin
= GetClientAreaOrigin() ;
974 if(x
) *x
-= origin
.x
;
975 if(y
) *y
-= origin
.y
;
978 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
980 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
981 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
983 wxPoint origin
= GetClientAreaOrigin() ;
984 if(x
) *x
+= origin
.x
;
985 if(y
) *y
+= origin
.y
;
987 MacWindowToRootWindow( x
, y
) ;
990 Point localwhere
= { 0,0 };
991 if(x
) localwhere
.h
= * x
;
992 if(y
) localwhere
.v
= * y
;
994 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
995 ::LocalToGlobal( &localwhere
) ;
996 if(x
) *x
= localwhere
.h
;
997 if(y
) *y
= localwhere
.v
;
1001 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1003 wxPoint origin
= GetClientAreaOrigin() ;
1004 if(x
) *x
+= origin
.x
;
1005 if(y
) *y
+= origin
.y
;
1007 MacWindowToRootWindow( x
, y
) ;
1010 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1012 MacRootWindowToWindow( x
, y
) ;
1014 wxPoint origin
= GetClientAreaOrigin() ;
1015 if(x
) *x
-= origin
.x
;
1016 if(y
) *y
-= origin
.y
;
1019 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1021 #if TARGET_API_MAC_OSX
1023 if ( x
) pt
.x
= *x
;
1024 if ( y
) pt
.y
= *y
;
1026 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1028 if ( x
) *x
= (int) pt
.x
;
1029 if ( y
) *y
= (int) pt
.y
;
1031 if ( !IsTopLevel() )
1034 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1035 if(x
) *x
+= bounds
.left
;
1036 if(y
) *y
+= bounds
.top
;
1041 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1046 MacWindowToRootWindow( &x1
, &y1
) ;
1051 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1053 #if TARGET_API_MAC_OSX
1055 if ( x
) pt
.x
= *x
;
1056 if ( y
) pt
.y
= *y
;
1058 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1060 if ( x
) *x
= (int) pt
.x
;
1061 if ( y
) *y
= (int) pt
.y
;
1063 if ( !IsTopLevel() )
1066 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1067 if(x
) *x
-= bounds
.left
;
1068 if(y
) *y
-= bounds
.top
;
1073 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1078 MacRootWindowToWindow( &x1
, &y1
) ;
1083 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1085 wxSize sizeTotal
= size
;
1087 RgnHandle rgn
= NewRgn() ;
1091 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1093 GetRegionBounds( rgn
, &content
) ;
1098 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1101 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1102 #if !TARGET_API_MAC_OSX
1103 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1106 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1107 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1109 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1110 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1116 // Get size *available for subwindows* i.e. excluding menu bar etc.
1117 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1121 RgnHandle rgn
= NewRgn() ;
1123 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1125 GetRegionBounds( rgn
, &content
) ;
1130 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1132 #if !TARGET_API_MAC_OSX
1134 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1135 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1137 ww
= content
.right
- content
.left
;
1138 hh
= content
.bottom
- content
.top
;
1140 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1141 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1143 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1149 GetSize( &w
, &h
) ;
1151 MacClientToRootWindow( &x1
, &y1
) ;
1152 MacClientToRootWindow( &w
, &h
) ;
1154 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1156 int totW
= 10000 , totH
= 10000;
1159 if ( iter
->IsTopLevel() )
1161 iter
->GetSize( &totW
, &totH
) ;
1165 iter
= iter
->GetParent() ;
1168 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1170 hh
-= MAC_SCROLLBAR_SIZE
;
1176 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1178 ww
-= MAC_SCROLLBAR_SIZE
;
1190 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1192 if (m_cursor
== cursor
)
1195 if (wxNullCursor
== cursor
)
1197 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1202 if ( ! wxWindowBase::SetCursor( cursor
) )
1206 wxASSERT_MSG( m_cursor
.Ok(),
1207 wxT("cursor must be valid after call to the base version"));
1211 TODO why do we have to use current coordinates ?
1214 wxWindowMac *mouseWin ;
1217 // Change the cursor NOW if we're within the correct window
1220 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1222 if ( mouseWin == this && !wxIsBusy() )
1224 m_cursor.MacInstall() ;
1230 m_cursor
.MacInstall() ;
1237 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1239 menu
->SetInvokingWindow(this);
1241 ClientToScreen( &x
, &y
) ;
1243 menu
->MacBeforeDisplay( true ) ;
1244 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1245 if ( HiWord(menuResult
) != 0 )
1248 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1249 wxMenuItem
* item
= NULL
;
1251 item
= menu
->FindItem(id
, &realmenu
) ;
1252 if (item
->IsCheckable())
1254 item
->Check( !item
->IsChecked() ) ;
1256 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1258 menu
->MacAfterDisplay( true ) ;
1260 menu
->SetInvokingWindow(NULL
);
1266 // ----------------------------------------------------------------------------
1268 // ----------------------------------------------------------------------------
1272 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1274 wxWindowBase::DoSetToolTip(tooltip
);
1277 m_tooltip
->SetWindow(this);
1280 #endif // wxUSE_TOOLTIPS
1282 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1284 int former_x
, former_y
, former_w
, former_h
;
1285 #if !TARGET_API_MAC_OSX
1286 DoGetPosition( &former_x
, &former_y
) ;
1287 DoGetSize( &former_w
, &former_h
) ;
1289 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1292 int actualWidth
= width
;
1293 int actualHeight
= height
;
1297 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1298 actualWidth
= m_minWidth
;
1299 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1300 actualHeight
= m_minHeight
;
1301 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1302 actualWidth
= m_maxWidth
;
1303 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1304 actualHeight
= m_maxHeight
;
1306 bool doMove
= false ;
1307 bool doResize
= false ;
1309 if ( actualX
!= former_x
|| actualY
!= former_y
)
1313 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1318 if ( doMove
|| doResize
)
1320 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1321 #if TARGET_API_MAC_OSX
1322 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1325 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1327 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1329 MacRepositionScrollBars() ;
1332 wxPoint
point(actualX
,actualY
);
1333 wxMoveEvent
event(point
, m_windowId
);
1334 event
.SetEventObject(this);
1335 GetEventHandler()->ProcessEvent(event
) ;
1339 MacRepositionScrollBars() ;
1340 wxSize
size(actualWidth
, actualHeight
);
1341 wxSizeEvent
event(size
, m_windowId
);
1342 event
.SetEventObject(this);
1343 GetEventHandler()->ProcessEvent(event
);
1349 wxSize
wxWindowMac::DoGetBestSize() const
1352 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1353 short baselineoffset ;
1354 int bestWidth, bestHeight ;
1355 ::GetBestControlRect( (ControlRef) m_macControl , &bestsize , &baselineoffset ) ;
1357 if ( EmptyRect( &bestsize ) )
1360 bestsize.left = bestsize.top = 0 ;
1361 bestsize.right = 16 ;
1362 bestsize.bottom = 16 ;
1363 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1365 bestsize.bottom = 16 ;
1367 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1369 bestsize.bottom = 24 ;
1373 // return wxWindowBase::DoGetBestSize() ;
1377 bestWidth = bestsize.right - bestsize.left ;
1378 bestHeight = bestsize.bottom - bestsize.top ;
1379 if ( bestHeight < 10 )
1382 return wxSize(bestWidth, bestHeight);
1384 return wxWindowBase::DoGetBestSize() ;
1388 // set the size of the window: if the dimensions are positive, just use them,
1389 // but if any of them is equal to -1, it means that we must find the value for
1390 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1391 // which case -1 is a valid value for x and y)
1393 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1394 // the width/height to best suit our contents, otherwise we reuse the current
1396 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1398 // get the current size and position...
1399 int currentX
, currentY
;
1400 GetPosition(¤tX
, ¤tY
);
1402 int currentW
,currentH
;
1403 GetSize(¤tW
, ¤tH
);
1405 // ... and don't do anything (avoiding flicker) if it's already ok
1406 if ( x
== currentX
&& y
== currentY
&&
1407 width
== currentW
&& height
== currentH
)
1410 MacRepositionScrollBars() ; // we might have a real position shift
1414 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1416 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1419 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1421 wxSize
size(-1, -1);
1424 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1426 size
= DoGetBestSize();
1431 // just take the current one
1438 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1442 size
= DoGetBestSize();
1444 //else: already called DoGetBestSize() above
1450 // just take the current one
1455 DoMoveWindow(x
, y
, width
, height
);
1459 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1461 RgnHandle rgn
= NewRgn() ;
1463 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1464 GetRegionBounds( rgn
, &content
) ;
1466 #if !TARGET_API_MAC_OSX
1468 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1469 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1472 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1475 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1477 if ( clientheight
!= -1 || clientheight
!= -1 )
1479 int currentclientwidth
, currentclientheight
;
1480 int currentwidth
, currentheight
;
1482 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1483 GetSize( ¤twidth
, ¤theight
) ;
1485 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1486 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1490 void wxWindowMac::SetTitle(const wxString
& title
)
1492 m_label
= wxStripMenuCodes(title
) ;
1496 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1501 wxString
wxWindowMac::GetTitle() const
1506 bool wxWindowMac::Show(bool show
)
1508 if ( !wxWindowBase::Show(show
) )
1511 // TODO use visibilityChanged Carbon Event for OSX
1512 bool former
= MacIsReallyShown() ;
1514 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1515 if ( former
!= MacIsReallyShown() )
1516 MacPropagateVisibilityChanged() ;
1520 bool wxWindowMac::Enable(bool enable
)
1522 wxASSERT( m_macControl
!= NULL
) ;
1523 if ( !wxWindowBase::Enable(enable
) )
1526 bool former
= MacIsReallyEnabled() ;
1528 EnableControl( (ControlRef
) m_macControl
) ;
1530 DisableControl( (ControlRef
) m_macControl
) ;
1532 if ( former
!= MacIsReallyEnabled() )
1533 MacPropagateEnabledStateChanged() ;
1538 // status change propagations (will be not necessary for OSX later )
1541 void wxWindowMac::MacPropagateVisibilityChanged()
1543 MacVisibilityChanged() ;
1545 wxWindowListNode
*node
= GetChildren().GetFirst();
1548 wxWindowMac
*child
= node
->GetData();
1549 if ( child
->IsShown() )
1550 child
->MacPropagateVisibilityChanged( ) ;
1551 node
= node
->GetNext();
1555 void wxWindowMac::MacPropagateEnabledStateChanged( )
1557 MacEnabledStateChanged() ;
1559 wxWindowListNode
*node
= GetChildren().GetFirst();
1562 wxWindowMac
*child
= node
->GetData();
1563 if ( child
->IsEnabled() )
1564 child
->MacPropagateEnabledStateChanged() ;
1565 node
= node
->GetNext();
1569 void wxWindowMac::MacPropagateHiliteChanged( )
1571 MacHiliteChanged() ;
1573 wxWindowListNode
*node
= GetChildren().GetFirst();
1576 wxWindowMac
*child
= node
->GetData();
1577 // if ( child->IsEnabled() )
1578 child
->MacPropagateHiliteChanged() ;
1579 node
= node
->GetNext();
1584 // status change notifications
1587 void wxWindowMac::MacVisibilityChanged()
1591 void wxWindowMac::MacHiliteChanged()
1595 void wxWindowMac::MacEnabledStateChanged()
1600 // status queries on the inherited window's state
1603 bool wxWindowMac::MacIsReallyShown()
1605 // only under OSX the visibility of the TLW is taken into account
1606 #if TARGET_API_MAC_OSX
1607 return IsControlVisible( (ControlRef
) m_macControl
) ;
1609 wxWindow
* win
= this ;
1610 while( win
->IsShown() )
1612 if ( win
->IsTopLevel() )
1615 win
= win
->GetParent() ;
1624 bool wxWindowMac::MacIsReallyEnabled()
1626 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1629 bool wxWindowMac::MacIsReallyHilited()
1631 return IsControlActive( (ControlRef
) m_macControl
) ;
1638 int wxWindowMac::GetCharHeight() const
1640 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1641 return dc
.GetCharHeight() ;
1644 int wxWindowMac::GetCharWidth() const
1646 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1647 return dc
.GetCharWidth() ;
1650 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1651 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1653 const wxFont
*fontToUse
= theFont
;
1655 fontToUse
= &m_font
;
1657 wxClientDC
dc( (wxWindowMac
*) this ) ;
1659 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1660 if ( externalLeading
)
1661 *externalLeading
= le
;
1671 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1672 * we always intersect with the entire window, not only with the client area
1675 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1677 #if TARGET_API_MAC_OSX
1678 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1680 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1682 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1683 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1686 if ( MacGetTopLevelWindow() == NULL )
1689 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1692 wxPoint client = GetClientAreaOrigin();
1695 int x2 = m_width - client.x;
1696 int y2 = m_height - client.y;
1698 if (IsKindOf( CLASSINFO(wxButton)))
1700 // buttons have an "aura"
1707 Rect clientrect = { y1, x1, y2, x2 };
1711 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1712 SectRect( &clientrect , &r , &clientrect ) ;
1715 if ( !EmptyRect( &clientrect ) )
1717 int top = 0 , left = 0 ;
1719 MacClientToRootWindow( &left , &top ) ;
1720 OffsetRect( &clientrect , left , top ) ;
1722 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1728 void wxWindowMac::MacRedrawControl()
1731 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1733 #if TARGET_API_MAC_CARBON
1736 wxClientDC dc(this) ;
1737 wxMacPortSetter helper(&dc) ;
1738 wxMacWindowClipper clipper(this) ;
1739 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1740 UMADrawControl( (ControlRef) m_macControl ) ;
1747 void wxWindowMac::OnPaint(wxPaintEvent& event)
1749 // why don't we skip that here ?
1753 wxWindowMac
*wxGetActiveWindow()
1755 // actually this is a windows-only concept
1759 // Coordinates relative to the window
1760 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1762 // We really don't move the mouse programmatically under Mac.
1765 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1767 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1772 event
.GetDC()->Clear() ;
1775 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1777 wxWindowDC
dc(this) ;
1778 wxMacPortSetter
helper(&dc
) ;
1780 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1783 int wxWindowMac::GetScrollPos(int orient
) const
1785 if ( orient
== wxHORIZONTAL
)
1788 return m_hScrollBar
->GetThumbPosition() ;
1793 return m_vScrollBar
->GetThumbPosition() ;
1798 // This now returns the whole range, not just the number
1799 // of positions that we can scroll.
1800 int wxWindowMac::GetScrollRange(int orient
) const
1802 if ( orient
== wxHORIZONTAL
)
1805 return m_hScrollBar
->GetRange() ;
1810 return m_vScrollBar
->GetRange() ;
1815 int wxWindowMac::GetScrollThumb(int orient
) const
1817 if ( orient
== wxHORIZONTAL
)
1820 return m_hScrollBar
->GetThumbSize() ;
1825 return m_vScrollBar
->GetThumbSize() ;
1830 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1832 if ( orient
== wxHORIZONTAL
)
1835 m_hScrollBar
->SetThumbPosition( pos
) ;
1840 m_vScrollBar
->SetThumbPosition( pos
) ;
1844 void wxWindowMac::MacPaintBorders( int left
, int top
)
1850 wxGetOsVersion( &major
, &minor
);
1852 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1853 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1855 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1856 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1857 // OS X has lighter border edges than classic:
1860 darkShadow
.red
= 0x8E8E;
1861 darkShadow
.green
= 0x8E8E;
1862 darkShadow
.blue
= 0x8E8E;
1863 lightShadow
.red
= 0xBDBD;
1864 lightShadow
.green
= 0xBDBD;
1865 lightShadow
.blue
= 0xBDBD;
1871 GetSize( &w
, &h
) ;
1872 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1874 #if wxMAC_USE_THEME_BORDER
1875 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1878 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1879 InsetRect( &rect , border , border );
1880 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1883 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1885 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1886 RGBForeColor( &face
);
1887 MoveTo( left
+ 0 , top
+ h
- 2 );
1888 LineTo( left
+ 0 , top
+ 0 );
1889 LineTo( left
+ w
- 2 , top
+ 0 );
1891 MoveTo( left
+ 2 , top
+ h
- 3 );
1892 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1893 LineTo( left
+ w
- 3 , top
+ 2 );
1895 RGBForeColor( sunken
? &face
: &darkShadow
);
1896 MoveTo( left
+ 0 , top
+ h
- 1 );
1897 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1898 LineTo( left
+ w
- 1 , top
+ 0 );
1900 RGBForeColor( sunken
? &lightShadow
: &white
);
1901 MoveTo( left
+ 1 , top
+ h
- 3 );
1902 LineTo( left
+ 1, top
+ 1 );
1903 LineTo( left
+ w
- 3 , top
+ 1 );
1905 RGBForeColor( sunken
? &white
: &lightShadow
);
1906 MoveTo( left
+ 1 , top
+ h
- 2 );
1907 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1908 LineTo( left
+ w
- 2 , top
+ 1 );
1910 RGBForeColor( sunken
? &darkShadow
: &face
);
1911 MoveTo( left
+ 2 , top
+ h
- 4 );
1912 LineTo( left
+ 2 , top
+ 2 );
1913 LineTo( left
+ w
- 4 , top
+ 2 );
1916 else if (HasFlag(wxSIMPLE_BORDER
))
1918 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
1919 RGBForeColor( &darkShadow
) ;
1920 FrameRect( &rect
) ;
1924 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
1926 if ( child
== m_hScrollBar
)
1927 m_hScrollBar
= NULL
;
1928 if ( child
== m_vScrollBar
)
1929 m_vScrollBar
= NULL
;
1931 wxWindowBase::RemoveChild( child
) ;
1934 // New function that will replace some of the above.
1935 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1936 int range
, bool refresh
)
1938 if ( orient
== wxHORIZONTAL
)
1942 if ( range
== 0 || thumbVisible
>= range
)
1944 if ( m_hScrollBar
->IsShown() )
1945 m_hScrollBar
->Show(false) ;
1949 if ( !m_hScrollBar
->IsShown() )
1950 m_hScrollBar
->Show(true) ;
1951 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1959 if ( range
== 0 || thumbVisible
>= range
)
1961 if ( m_vScrollBar
->IsShown() )
1962 m_vScrollBar
->Show(false) ;
1966 if ( !m_vScrollBar
->IsShown() )
1967 m_vScrollBar
->Show(true) ;
1968 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
1972 MacRepositionScrollBars() ;
1975 // Does a physical scroll
1976 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1978 if( dx
== 0 && dy
==0 )
1983 wxClientDC
dc(this) ;
1984 wxMacPortSetter
helper(&dc
) ;
1986 int width
, height
;
1987 GetClientSize( &width
, &height
) ;
1994 // TODO take out the boundaries
1995 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
1997 RgnHandle updateRgn
= NewRgn() ;
2000 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2001 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2002 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2004 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2006 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2007 // but it seems the update only refreshes the background of the control, rather than calling
2008 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2009 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2012 // we also have to scroll the update rgn in this rectangle
2013 // in order not to loose updates
2015 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2016 RgnHandle formerUpdateRgn
= NewRgn() ;
2017 RgnHandle scrollRgn
= NewRgn() ;
2018 RectRgn( scrollRgn
, &scrollrect
) ;
2019 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2021 LocalToGlobal( &pt
) ;
2022 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2023 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2024 if ( !EmptyRgn( formerUpdateRgn
) )
2026 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2027 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2028 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2030 InvalWindowRgn(rootWindow
, updateRgn
) ;
2031 DisposeRgn( updateRgn
) ;
2032 DisposeRgn( formerUpdateRgn
) ;
2033 DisposeRgn( scrollRgn
) ;
2037 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2039 wxWindowMac
*child
= node
->GetData();
2040 if (child
== m_vScrollBar
) continue;
2041 if (child
== m_hScrollBar
) continue;
2042 if (child
->IsTopLevel()) continue;
2045 child
->GetPosition( &x
, &y
);
2047 child
->GetSize( &w
, &h
);
2051 if (rect
->Intersects(rc
))
2052 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2056 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2060 // TODO remove, was moved higher up Update() ;
2064 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2066 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2068 wxScrollWinEvent wevent
;
2069 wevent
.SetPosition(event
.GetPosition());
2070 wevent
.SetOrientation(event
.GetOrientation());
2071 wevent
.m_eventObject
= this;
2073 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2074 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2075 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2076 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2077 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2078 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2079 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2080 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2081 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2082 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2083 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2084 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2085 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2086 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2087 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2088 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2090 GetEventHandler()->ProcessEvent(wevent
);
2094 // Get the window with the focus
2095 wxWindowMac
*wxWindowBase::FindFocus()
2097 return gFocusWindow
;
2100 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2102 // panel wants to track the window which was the last to have focus in it,
2103 // so we want to set ourselves as the window which last had focus
2105 // notice that it's also important to do it upwards the tree becaus
2106 // otherwise when the top level panel gets focus, it won't set it back to
2107 // us, but to some other sibling
2109 // CS:don't know if this is still needed:
2110 //wxChildFocusEvent eventFocus(this);
2111 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2116 void wxWindowMac::OnInternalIdle()
2118 // This calls the UI-update mechanism (querying windows for
2119 // menu/toolbar/control state information)
2120 if (wxUpdateUIEvent::CanUpdate(this))
2121 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2124 // Raise the window to the top of the Z order
2125 void wxWindowMac::Raise()
2129 // Lower the window to the bottom of the Z order
2130 void wxWindowMac::Lower()
2135 // static wxWindow *gs_lastWhich = NULL;
2137 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2139 // first trigger a set cursor event
2141 wxPoint clientorigin
= GetClientAreaOrigin() ;
2142 wxSize clientsize
= GetClientSize() ;
2144 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2146 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2148 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2149 if ( processedEvtSetCursor
&& event
.HasCursor() )
2151 cursor
= event
.GetCursor() ;
2156 // the test for processedEvtSetCursor is here to prevent using m_cursor
2157 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2158 // it - this is a way to say that our cursor shouldn't be used for this
2160 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2170 cursor
= *wxSTANDARD_CURSOR
;
2174 cursor
.MacInstall() ;
2176 return cursor
.Ok() ;
2179 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2183 return m_tooltip
->GetTip() ;
2185 return wxEmptyString
;
2188 void wxWindowMac::Update()
2190 #if TARGET_API_MAC_OSX
2191 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2193 ::Draw1Control( (ControlRef
) m_macControl
) ;
2197 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2199 wxTopLevelWindowMac
* win
= NULL
;
2200 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2203 win
= wxFindWinFromMacWindow( window
) ;
2207 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2211 RgnHandle visRgn
= NewRgn() ;
2212 RgnHandle tempRgn
= NewRgn() ;
2213 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2215 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2216 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2218 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2219 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2228 if ( includeOuterStructures
)
2229 InsetRect( &r
, -3 , -3 ) ;
2230 RectRgn( visRgn
, &r
) ;
2231 if ( !IsTopLevel() )
2233 wxWindow
* child
= this ;
2234 wxWindow
* parent
= child
->GetParent() ;
2239 // we have to find a better clipping algorithm here, in order not to clip things
2240 // positioned like status and toolbar
2241 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2243 size
= parent
->GetSize() ;
2248 size
= parent
->GetClientSize() ;
2249 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2253 parent
->MacWindowToRootWindow( &x
, &y
) ;
2254 MacRootWindowToWindow( &x
, &y
) ;
2256 SetRectRgn( tempRgn
,
2257 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2258 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2259 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2261 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2262 if ( parent
->IsTopLevel() )
2265 parent
= child
->GetParent() ;
2270 wxRegion vis
= visRgn
;
2271 DisposeRgn( visRgn
) ;
2272 DisposeRgn( tempRgn
) ;
2277 This function must not change the updatergn !
2279 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2281 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2282 bool handled
= false ;
2284 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2286 RgnHandle newupdate
= NewRgn() ;
2287 wxSize point
= GetClientSize() ;
2288 wxPoint origin
= GetClientAreaOrigin() ;
2289 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2290 SectRgn( newupdate
, updatergn
, newupdate
) ;
2291 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2292 m_updateRegion
= newupdate
;
2293 DisposeRgn( newupdate
) ;
2296 if ( !EmptyRgn(updatergn
) )
2298 wxWindowDC
dc(this);
2299 if (!EmptyRgn(updatergn
))
2300 dc
.SetClippingRegion(wxRegion(updatergn
));
2302 wxEraseEvent
eevent( GetId(), &dc
);
2303 eevent
.SetEventObject( this );
2304 GetEventHandler()->ProcessEvent( eevent
);
2306 if ( !m_updateRegion
.Empty() )
2308 // paint the window itself
2310 event
.m_timeStamp
= time
;
2311 event
.SetEventObject(this);
2312 handled
= GetEventHandler()->ProcessEvent(event
);
2314 // paint custom borders
2315 wxNcPaintEvent
eventNc( GetId() );
2316 eventNc
.SetEventObject( this );
2317 GetEventHandler()->ProcessEvent( eventNc
);
2323 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2325 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2326 // updatergn is always already clipped to our boundaries
2327 // if we are in compositing mode then it is in relative to the upper left of the control
2328 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2329 // of the toplevel window
2330 // it is in window coordinates, not in client coordinates
2332 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2333 RgnHandle ownUpdateRgn
= NewRgn() ;
2334 CopyRgn( updatergn
, ownUpdateRgn
) ;
2336 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2339 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2340 RgnHandle controlRgn
= NewRgn();
2341 RectRgn( controlRgn
, &bounds
);
2342 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2343 // the window update region
2344 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2345 DisposeRgn( controlRgn
);
2347 //KO: convert ownUpdateRgn to local coordinates
2348 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2351 MacDoRedraw( ownUpdateRgn
, time
) ;
2352 DisposeRgn( ownUpdateRgn
) ;
2356 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2358 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2362 if ( iter
->IsTopLevel() )
2363 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2365 iter
= iter
->GetParent() ;
2367 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2371 void wxWindowMac::MacCreateScrollBars( long style
)
2373 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2375 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2376 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2378 GetClientSize( &width
, &height
) ;
2380 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2381 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2382 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2383 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2385 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2386 vSize
, wxVERTICAL
);
2388 if ( style
& wxVSCROLL
)
2394 m_vScrollBar
->Show(false) ;
2396 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2397 hSize
, wxHORIZONTAL
);
2398 if ( style
& wxHSCROLL
)
2403 m_hScrollBar
->Show(false) ;
2406 // because the create does not take into account the client area origin
2407 MacRepositionScrollBars() ; // we might have a real position shift
2410 void wxWindowMac::MacRepositionScrollBars()
2412 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2413 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2415 // get real client area
2419 GetSize( &width
, &height
) ;
2421 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2422 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
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
) ;
2433 GetSize( &w
, &h
) ;
2435 MacClientToRootWindow( &x
, &y
) ;
2436 MacClientToRootWindow( &w
, &h
) ;
2438 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2440 int totW
= 10000 , totH
= 10000;
2443 if ( iter
->IsTopLevel() )
2445 iter
->GetSize( &totW
, &totH
) ;
2449 iter
= iter
->GetParent() ;
2477 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2481 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2485 bool wxWindowMac::AcceptsFocus() const
2487 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2490 void wxWindowMac::MacSuperChangedPosition()
2492 // only window-absolute structures have to be moved i.e. controls
2494 wxWindowListNode
*node
= GetChildren().GetFirst();
2497 wxWindowMac
*child
= node
->GetData();
2498 child
->MacSuperChangedPosition() ;
2499 node
= node
->GetNext();
2503 void wxWindowMac::MacTopLevelWindowChangedPosition()
2505 // only screen-absolute structures have to be moved i.e. glcanvas
2507 wxWindowListNode
*node
= GetChildren().GetFirst();
2510 wxWindowMac
*child
= node
->GetData();
2511 child
->MacTopLevelWindowChangedPosition() ;
2512 node
= node
->GetNext();
2516 long wxWindowMac::MacGetLeftBorderSize( ) const
2521 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2524 #if wxMAC_USE_THEME_BORDER
2525 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2529 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2532 #if wxMAC_USE_THEME_BORDER
2533 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2537 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2544 long wxWindowMac::MacGetRightBorderSize( ) const
2546 // they are all symmetric in mac themes
2547 return MacGetLeftBorderSize() ;
2550 long wxWindowMac::MacGetTopBorderSize( ) const
2552 // they are all symmetric in mac themes
2553 return MacGetLeftBorderSize() ;
2556 long wxWindowMac::MacGetBottomBorderSize( ) const
2558 // they are all symmetric in mac themes
2559 return MacGetLeftBorderSize() ;
2562 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2564 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2567 // Find the wxWindowMac at the current mouse position, returning the mouse
2569 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2571 pt
= wxGetMousePosition();
2572 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2576 // Get the current mouse position.
2577 wxPoint
wxGetMousePosition()
2580 wxGetMousePosition(& x
, & y
);
2581 return wxPoint(x
, y
);
2584 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2586 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2588 // copied from wxGTK : CS
2589 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2592 // (a) it's a command event and so is propagated to the parent
2593 // (b) under MSW it can be generated from kbd too
2594 // (c) it uses screen coords (because of (a))
2595 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2597 this->ClientToScreen(event
.GetPosition()));
2598 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2601 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2607 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2609 // OS Needs it in tlw content area coordinates
2610 MacClientToRootWindow( &x
, &y
) ;
2614 // OS Needs it in window not client coordinates
2615 wxPoint origin
= GetClientAreaOrigin() ;
2620 SInt16 controlpart
;
2625 short modifiers
= 0;
2627 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2628 modifiers
|= btnState
;
2630 if ( event
.m_shiftDown
)
2631 modifiers
|= shiftKey
;
2633 if ( event
.m_controlDown
)
2634 modifiers
|= controlKey
;
2636 if ( event
.m_altDown
)
2637 modifiers
|= optionKey
;
2639 if ( event
.m_metaDown
)
2640 modifiers
|= cmdKey
;
2642 bool handled
= false ;
2644 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2646 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2647 wxTheApp
->s_lastMouseDown
= 0 ;
2648 if ( controlpart
!= kControlNoPart
)
2650 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2663 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2665 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2668 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2672 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2673 Rect bounds
= { y
, x
, y
+h
, x
+w
};