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
) ;
467 wxWindowMac::~wxWindowMac()
471 m_isBeingDeleted
= TRUE
;
473 #ifndef __WXUNIVERSAL__
474 // VS: make sure there's no wxFrame with last focus set to us:
475 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
477 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
480 if ( frame
->GetLastFocus() == this )
482 frame
->SetLastFocus((wxWindow
*)NULL
);
487 #endif // __WXUNIVERSAL__
489 // wxRemoveMacControlAssociation( this ) ;
490 // If we delete an item, we should initialize the parent panel,
491 // because it could now be invalid.
492 wxWindow
*parent
= GetParent() ;
495 if (parent
->GetDefaultItem() == (wxButton
*) this)
496 parent
->SetDefaultItem(NULL
);
498 if ( (ControlRef
) m_macControl
)
500 // in case the callback might be called during destruction
501 wxRemoveMacControlAssociation( this) ;
502 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
503 ::DisposeControl( (ControlRef
) m_macControl
) ;
504 m_macControl
= NULL
;
507 if ( g_MacLastWindow
== this )
509 g_MacLastWindow
= NULL
;
512 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
515 if ( frame
->GetLastFocus() == this )
516 frame
->SetLastFocus( NULL
) ;
519 if ( gFocusWindow
== this )
521 gFocusWindow
= NULL
;
526 // delete our drop target if we've got one
527 #if wxUSE_DRAG_AND_DROP
528 if ( m_dropTarget
!= NULL
)
533 #endif // wxUSE_DRAG_AND_DROP
538 void wxWindowMac::MacInstallEventHandler()
540 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
541 GetEventTypeCount(eventList
), eventList
, this,
542 (EventHandlerRef
*)&m_macControlEventHandler
);
547 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
551 const wxString
& name
)
553 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
555 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
558 parent
->AddChild(this);
560 m_windowVariant
= parent
->GetWindowVariant() ;
562 if ( m_macIsUserPane
)
564 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
566 UInt32 features
= kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlHasSpecialBackground
|
567 kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle
;
569 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, kControlSupportsEmbedding
, (ControlRef
*) &m_macControl
);
571 MacPostControlCreate(pos
,size
) ;
572 #if !TARGET_API_MAC_OSX
573 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
574 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
575 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
576 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
577 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
578 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
579 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
580 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
581 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
582 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
583 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
584 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
585 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
586 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
587 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
588 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
591 #ifndef __WXUNIVERSAL__
592 // Don't give scrollbars to wxControls unless they ask for them
593 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
594 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
596 MacCreateScrollBars( style
) ;
600 wxWindowCreateEvent
event(this);
601 GetEventHandler()->AddPendingEvent(event
);
606 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
608 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
610 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
611 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
613 MacInstallEventHandler();
615 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
616 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
617 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
619 // adjust font, controlsize etc
620 DoSetWindowVariant( m_windowVariant
) ;
622 #if !TARGET_API_MAC_OSX
623 // eventually we can fix some clipping issues be reactivating this hook
624 //if ( m_macIsUserPane )
625 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
628 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
630 wxSize new_size
= size
;
631 if (!m_macIsUserPane
)
633 wxSize
best_size( DoGetBestSize() );
636 new_size
.x
= best_size
.x
;
639 new_size
.y
= best_size
.y
;
641 SetSize( pos
.x
, pos
.y
, new_size
.x
, new_size
.y
,wxSIZE_USE_EXISTING
);
644 SetCursor( *wxSTANDARD_CURSOR
) ;
648 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
650 wxASSERT( m_macControl
!= NULL
) ;
652 m_windowVariant
= variant
;
655 ThemeFontID themeFont
= kThemeSystemFont
;
657 // we will get that from the settings later
658 // and make this NORMAL later, but first
659 // we have a few calculations that we must fix
663 case wxWINDOW_VARIANT_NORMAL
:
664 size
= kControlSizeNormal
;
665 themeFont
= kThemeSystemFont
;
667 case wxWINDOW_VARIANT_SMALL
:
668 size
= kControlSizeSmall
;
669 themeFont
= kThemeSmallSystemFont
;
671 case wxWINDOW_VARIANT_MINI
:
672 if (UMAGetSystemVersion() >= 0x1030 )
674 // not always defined in the headers
680 size
= kControlSizeSmall
;
681 themeFont
= kThemeSmallSystemFont
;
684 case wxWINDOW_VARIANT_LARGE
:
685 size
= kControlSizeLarge
;
686 themeFont
= kThemeSystemFont
;
689 wxFAIL_MSG(_T("unexpected window variant"));
692 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
695 font
.MacCreateThemeFont( themeFont
) ;
699 void wxWindowMac::MacUpdateControlFont()
701 ControlFontStyleRec fontStyle
;
702 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
704 switch( m_font
.MacGetThemeFontID() )
706 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
707 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
708 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
709 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
711 fontStyle
.flags
= kControlUseFontMask
;
715 fontStyle
.font
= m_font
.MacGetFontNum() ;
716 fontStyle
.style
= m_font
.MacGetFontStyle() ;
717 fontStyle
.size
= m_font
.MacGetFontSize() ;
718 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
721 fontStyle
.just
= teJustLeft
;
722 fontStyle
.flags
|= kControlUseJustMask
;
723 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
724 fontStyle
.just
= teJustCenter
;
725 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
726 fontStyle
.just
= teJustRight
;
729 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
730 fontStyle
.flags
|= kControlUseForeColorMask
;
732 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
736 bool wxWindowMac::SetFont(const wxFont
& font
)
738 bool retval
= !wxWindowBase::SetFont( font
) ;
740 MacUpdateControlFont() ;
745 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
747 if ( !wxWindowBase::SetForegroundColour(col
) )
750 MacUpdateControlFont() ;
755 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
757 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
761 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
763 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
765 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
767 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
771 brush
.SetColour( col
) ;
773 MacSetBackgroundBrush( brush
) ;
775 MacUpdateControlFont() ;
781 bool wxWindowMac::MacCanFocus() const
783 wxASSERT( m_macControl
!= NULL
) ;
789 void wxWindowMac::SetFocus()
791 if ( gFocusWindow
== this )
794 if ( AcceptsFocus() )
800 if ( gFocusWindow
->m_caret
)
802 gFocusWindow
->m_caret
->OnKillFocus();
804 #endif // wxUSE_CARET
805 #ifndef __WXUNIVERSAL__
806 wxWindow
* control
= wxDynamicCast( gFocusWindow
, wxWindow
) ;
807 // TODO we must use the built-in focusing
808 if ( control
&& control
->GetHandle() /* && control->MacIsReallyShown() */ )
810 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNoPart
) ;
811 control
->MacRedrawControl() ;
814 // Without testing the window id, for some reason
815 // a kill focus event can still be sent to
816 // the control just being focussed.
817 int thisId
= this->m_windowId
;
818 int gFocusWindowId
= gFocusWindow
->m_windowId
;
819 if (gFocusWindowId
!= thisId
)
821 wxFocusEvent
event(wxEVT_KILL_FOCUS
, gFocusWindow
->m_windowId
);
822 event
.SetEventObject(gFocusWindow
);
823 gFocusWindow
->GetEventHandler()->ProcessEvent(event
) ;
826 gFocusWindow
= this ;
832 m_caret
->OnSetFocus();
834 #endif // wxUSE_CARET
835 // panel wants to track the window which was the last to have focus in it
836 wxChildFocusEvent
eventFocus(this);
837 GetEventHandler()->ProcessEvent(eventFocus
);
839 #ifndef __WXUNIVERSAL__
840 wxControl
* control
= wxDynamicCast( gFocusWindow
, wxControl
) ;
841 if ( control
&& control
->GetHandle() )
843 UMASetKeyboardFocus( (WindowRef
) gFocusWindow
->MacGetTopLevelWindowRef() , (ControlRef
) control
->GetHandle() , kControlFocusNextPart
) ;
846 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
847 event
.SetEventObject(this);
848 GetEventHandler()->ProcessEvent(event
) ;
854 void wxWindowMac::DoCaptureMouse()
856 wxTheApp
->s_captureWindow
= this ;
859 wxWindow
* wxWindowBase::GetCapture()
861 return wxTheApp
->s_captureWindow
;
864 void wxWindowMac::DoReleaseMouse()
866 wxTheApp
->s_captureWindow
= NULL
;
869 #if wxUSE_DRAG_AND_DROP
871 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
873 if ( m_dropTarget
!= 0 ) {
877 m_dropTarget
= pDropTarget
;
878 if ( m_dropTarget
!= 0 )
886 // Old style file-manager drag&drop
887 void wxWindowMac::DragAcceptFiles(bool accept
)
892 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
893 int& w
, int& h
) const
896 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
901 w
= bounds
.right
- bounds
.left
;
902 h
= bounds
.bottom
- bounds
.top
;
904 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
907 Point tlworigin
= { 0 , 0 } ;
910 ::SetPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) ) ;
911 ::LocalToGlobal( &tlworigin
) ;
918 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
921 int& w
, int& h
) const
925 // todo the default calls may be used as soon as PostCreateControl Is moved here
926 w
= size
.x
; // WidthDefault( size.x );
927 h
= size
.y
; // HeightDefault( size.y ) ;
928 #if !TARGET_API_MAC_OSX
929 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
936 void wxWindowMac::DoGetSize(int *x
, int *y
) const
938 #if TARGET_API_MAC_OSX
939 int x1
, y1
, w1
,h1
;
940 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
946 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
947 if(x
) *x
= bounds
.right
- bounds
.left
;
948 if(y
) *y
= bounds
.bottom
- bounds
.top
;
952 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
954 #if TARGET_API_MAC_OSX
955 int x1
, y1
, w1
,h1
;
956 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
959 wxWindow
*parent
= GetParent();
962 wxPoint
pt(parent
->GetClientAreaOrigin());
971 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
972 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
974 int xx
= bounds
.left
;
975 int yy
= bounds
.top
;
977 if ( !GetParent()->IsTopLevel() )
979 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
985 wxPoint
pt(GetParent()->GetClientAreaOrigin());
994 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
996 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
998 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1001 Point localwhere
= {0,0} ;
1003 if(x
) localwhere
.h
= * x
;
1004 if(y
) localwhere
.v
= * y
;
1006 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1007 ::GlobalToLocal( &localwhere
) ;
1008 if(x
) *x
= localwhere
.h
;
1009 if(y
) *y
= localwhere
.v
;
1012 MacRootWindowToWindow( x
, y
) ;
1014 wxPoint origin
= GetClientAreaOrigin() ;
1015 if(x
) *x
-= origin
.x
;
1016 if(y
) *y
-= origin
.y
;
1019 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1021 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1022 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1024 wxPoint origin
= GetClientAreaOrigin() ;
1025 if(x
) *x
+= origin
.x
;
1026 if(y
) *y
+= origin
.y
;
1028 MacWindowToRootWindow( x
, y
) ;
1031 Point localwhere
= { 0,0 };
1032 if(x
) localwhere
.h
= * x
;
1033 if(y
) localwhere
.v
= * y
;
1035 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1036 ::LocalToGlobal( &localwhere
) ;
1037 if(x
) *x
= localwhere
.h
;
1038 if(y
) *y
= localwhere
.v
;
1042 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1044 wxPoint origin
= GetClientAreaOrigin() ;
1045 if(x
) *x
+= origin
.x
;
1046 if(y
) *y
+= origin
.y
;
1048 MacWindowToRootWindow( x
, y
) ;
1051 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1053 MacRootWindowToWindow( x
, y
) ;
1055 wxPoint origin
= GetClientAreaOrigin() ;
1056 if(x
) *x
-= origin
.x
;
1057 if(y
) *y
-= origin
.y
;
1060 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1062 #if TARGET_API_MAC_OSX
1064 if ( x
) pt
.x
= *x
;
1065 if ( y
) pt
.y
= *y
;
1067 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1069 if ( x
) *x
= (int) pt
.x
;
1070 if ( y
) *y
= (int) pt
.y
;
1072 if ( !IsTopLevel() )
1075 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1076 if(x
) *x
+= bounds
.left
;
1077 if(y
) *y
+= bounds
.top
;
1082 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1087 MacWindowToRootWindow( &x1
, &y1
) ;
1092 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1094 #if TARGET_API_MAC_OSX
1096 if ( x
) pt
.x
= *x
;
1097 if ( y
) pt
.y
= *y
;
1099 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1101 if ( x
) *x
= (int) pt
.x
;
1102 if ( y
) *y
= (int) pt
.y
;
1104 if ( !IsTopLevel() )
1107 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1108 if(x
) *x
-= bounds
.left
;
1109 if(y
) *y
-= bounds
.top
;
1114 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1119 MacRootWindowToWindow( &x1
, &y1
) ;
1124 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1126 wxSize sizeTotal
= size
;
1128 RgnHandle rgn
= NewRgn() ;
1132 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1134 GetRegionBounds( rgn
, &content
) ;
1139 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1142 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1143 #if !TARGET_API_MAC_OSX
1144 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1147 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1148 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1150 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1151 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1157 // Get size *available for subwindows* i.e. excluding menu bar etc.
1158 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1162 RgnHandle rgn
= NewRgn() ;
1164 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1166 GetRegionBounds( rgn
, &content
) ;
1171 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1173 #if !TARGET_API_MAC_OSX
1175 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1176 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1178 ww
= content
.right
- content
.left
;
1179 hh
= content
.bottom
- content
.top
;
1181 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1182 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1184 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1190 GetSize( &w
, &h
) ;
1192 MacClientToRootWindow( &x1
, &y1
) ;
1193 MacClientToRootWindow( &w
, &h
) ;
1195 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1197 int totW
= 10000 , totH
= 10000;
1200 if ( iter
->IsTopLevel() )
1202 iter
->GetSize( &totW
, &totH
) ;
1206 iter
= iter
->GetParent() ;
1209 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1211 hh
-= MAC_SCROLLBAR_SIZE
;
1217 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1219 ww
-= MAC_SCROLLBAR_SIZE
;
1231 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1233 if (m_cursor
== cursor
)
1236 if (wxNullCursor
== cursor
)
1238 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1243 if ( ! wxWindowBase::SetCursor( cursor
) )
1247 wxASSERT_MSG( m_cursor
.Ok(),
1248 wxT("cursor must be valid after call to the base version"));
1252 TODO why do we have to use current coordinates ?
1255 wxWindowMac *mouseWin ;
1258 // Change the cursor NOW if we're within the correct window
1261 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1263 if ( mouseWin == this && !wxIsBusy() )
1265 m_cursor.MacInstall() ;
1271 m_cursor
.MacInstall() ;
1278 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1280 menu
->SetInvokingWindow(this);
1282 ClientToScreen( &x
, &y
) ;
1284 menu
->MacBeforeDisplay( true ) ;
1285 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1286 if ( HiWord(menuResult
) != 0 )
1289 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1290 wxMenuItem
* item
= NULL
;
1292 item
= menu
->FindItem(id
, &realmenu
) ;
1293 if (item
->IsCheckable())
1295 item
->Check( !item
->IsChecked() ) ;
1297 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1299 menu
->MacAfterDisplay( true ) ;
1301 menu
->SetInvokingWindow(NULL
);
1307 // ----------------------------------------------------------------------------
1309 // ----------------------------------------------------------------------------
1313 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1315 wxWindowBase::DoSetToolTip(tooltip
);
1318 m_tooltip
->SetWindow(this);
1321 #endif // wxUSE_TOOLTIPS
1323 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1325 int former_x
, former_y
, former_w
, former_h
;
1326 #if !TARGET_API_MAC_OSX
1327 DoGetPosition( &former_x
, &former_y
) ;
1328 DoGetSize( &former_w
, &former_h
) ;
1330 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1333 int actualWidth
= width
;
1334 int actualHeight
= height
;
1338 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1339 actualWidth
= m_minWidth
;
1340 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1341 actualHeight
= m_minHeight
;
1342 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1343 actualWidth
= m_maxWidth
;
1344 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1345 actualHeight
= m_maxHeight
;
1347 bool doMove
= false ;
1348 bool doResize
= false ;
1350 if ( actualX
!= former_x
|| actualY
!= former_y
)
1354 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1359 if ( doMove
|| doResize
)
1361 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) ) ;
1362 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1363 #if TARGET_API_MAC_OSX
1364 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1366 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1367 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1368 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1370 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1372 // TODO TEST SetControlBounds( (ControlRef) m_macControl , &r ) ;
1374 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1376 MoveControl( (ControlRef
) m_macControl
, r
.left
, r
.top
) ;
1378 SizeControl( (ControlRef
) m_macControl
, r
.right
-r
.left
, r
.bottom
-r
.top
) ;
1380 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1382 MacRepositionScrollBars() ;
1385 wxPoint
point(actualX
,actualY
);
1386 wxMoveEvent
event(point
, m_windowId
);
1387 event
.SetEventObject(this);
1388 GetEventHandler()->ProcessEvent(event
) ;
1392 MacRepositionScrollBars() ;
1393 wxSize
size(actualWidth
, actualHeight
);
1394 wxSizeEvent
event(size
, m_windowId
);
1395 event
.SetEventObject(this);
1396 GetEventHandler()->ProcessEvent(event
);
1402 wxSize
wxWindowMac::DoGetBestSize() const
1404 if ( m_macIsUserPane
|| IsTopLevel() )
1405 return wxWindowBase::DoGetBestSize() ;
1407 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1408 short baselineoffset
;
1409 int bestWidth
, bestHeight
;
1410 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1412 if ( EmptyRect( &bestsize
) )
1415 bestsize
.left
= bestsize
.top
= 0 ;
1416 bestsize
.right
= 16 ;
1417 bestsize
.bottom
= 16 ;
1418 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1420 bestsize
.bottom
= 16 ;
1422 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1424 bestsize
.bottom
= 24 ;
1428 // return wxWindowBase::DoGetBestSize() ;
1432 bestWidth
= bestsize
.right
- bestsize
.left
;
1433 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1434 if ( bestHeight
< 10 )
1437 return wxSize(bestWidth
, bestHeight
);
1438 // return wxWindowBase::DoGetBestSize() ;
1442 // set the size of the window: if the dimensions are positive, just use them,
1443 // but if any of them is equal to -1, it means that we must find the value for
1444 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1445 // which case -1 is a valid value for x and y)
1447 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1448 // the width/height to best suit our contents, otherwise we reuse the current
1450 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1452 // get the current size and position...
1453 int currentX
, currentY
;
1454 GetPosition(¤tX
, ¤tY
);
1456 int currentW
,currentH
;
1457 GetSize(¤tW
, ¤tH
);
1459 // ... and don't do anything (avoiding flicker) if it's already ok
1460 if ( x
== currentX
&& y
== currentY
&&
1461 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1464 MacRepositionScrollBars() ; // we might have a real position shift
1468 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1470 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1473 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1475 wxSize
size(-1, -1);
1478 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1480 size
= DoGetBestSize();
1485 // just take the current one
1492 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1496 size
= DoGetBestSize();
1498 //else: already called DoGetBestSize() above
1504 // just take the current one
1509 DoMoveWindow(x
, y
, width
, height
);
1513 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1515 RgnHandle rgn
= NewRgn() ;
1517 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1518 GetRegionBounds( rgn
, &content
) ;
1520 #if !TARGET_API_MAC_OSX
1522 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1523 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1526 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1529 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1531 if ( clientheight
!= -1 || clientheight
!= -1 )
1533 int currentclientwidth
, currentclientheight
;
1534 int currentwidth
, currentheight
;
1536 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1537 GetSize( ¤twidth
, ¤theight
) ;
1539 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1540 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1544 void wxWindowMac::SetTitle(const wxString
& title
)
1546 m_label
= wxStripMenuCodes(title
) ;
1550 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1555 wxString
wxWindowMac::GetTitle() const
1560 bool wxWindowMac::Show(bool show
)
1562 if ( !wxWindowBase::Show(show
) )
1565 // TODO use visibilityChanged Carbon Event for OSX
1566 bool former
= MacIsReallyShown() ;
1568 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1569 if ( former
!= MacIsReallyShown() )
1570 MacPropagateVisibilityChanged() ;
1574 bool wxWindowMac::Enable(bool enable
)
1576 wxASSERT( m_macControl
!= NULL
) ;
1577 if ( !wxWindowBase::Enable(enable
) )
1580 bool former
= MacIsReallyEnabled() ;
1582 EnableControl( (ControlRef
) m_macControl
) ;
1584 DisableControl( (ControlRef
) m_macControl
) ;
1586 if ( former
!= MacIsReallyEnabled() )
1587 MacPropagateEnabledStateChanged() ;
1592 // status change propagations (will be not necessary for OSX later )
1595 void wxWindowMac::MacPropagateVisibilityChanged()
1597 #if !TARGET_API_MAC_OSX
1598 MacVisibilityChanged() ;
1600 wxWindowListNode
*node
= GetChildren().GetFirst();
1603 wxWindowMac
*child
= node
->GetData();
1604 if ( child
->IsShown() )
1605 child
->MacPropagateVisibilityChanged( ) ;
1606 node
= node
->GetNext();
1611 void wxWindowMac::MacPropagateEnabledStateChanged( )
1613 #if !TARGET_API_MAC_OSX
1614 MacEnabledStateChanged() ;
1616 wxWindowListNode
*node
= GetChildren().GetFirst();
1619 wxWindowMac
*child
= node
->GetData();
1620 if ( child
->IsEnabled() )
1621 child
->MacPropagateEnabledStateChanged() ;
1622 node
= node
->GetNext();
1627 void wxWindowMac::MacPropagateHiliteChanged( )
1629 #if !TARGET_API_MAC_OSX
1630 MacHiliteChanged() ;
1632 wxWindowListNode
*node
= GetChildren().GetFirst();
1635 wxWindowMac
*child
= node
->GetData();
1636 // if ( child->IsEnabled() )
1637 child
->MacPropagateHiliteChanged() ;
1638 node
= node
->GetNext();
1644 // status change notifications
1647 void wxWindowMac::MacVisibilityChanged()
1651 void wxWindowMac::MacHiliteChanged()
1655 void wxWindowMac::MacEnabledStateChanged()
1660 // status queries on the inherited window's state
1663 bool wxWindowMac::MacIsReallyShown()
1665 // only under OSX the visibility of the TLW is taken into account
1666 #if TARGET_API_MAC_OSX
1667 return IsControlVisible( (ControlRef
) m_macControl
) ;
1669 wxWindow
* win
= this ;
1670 while( win
->IsShown() )
1672 if ( win
->IsTopLevel() )
1675 win
= win
->GetParent() ;
1684 bool wxWindowMac::MacIsReallyEnabled()
1686 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1689 bool wxWindowMac::MacIsReallyHilited()
1691 return IsControlActive( (ControlRef
) m_macControl
) ;
1698 int wxWindowMac::GetCharHeight() const
1700 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1701 return dc
.GetCharHeight() ;
1704 int wxWindowMac::GetCharWidth() const
1706 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1707 return dc
.GetCharWidth() ;
1710 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1711 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1713 const wxFont
*fontToUse
= theFont
;
1715 fontToUse
= &m_font
;
1717 wxClientDC
dc( (wxWindowMac
*) this ) ;
1719 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1720 if ( externalLeading
)
1721 *externalLeading
= le
;
1731 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1732 * we always intersect with the entire window, not only with the client area
1735 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1737 #if TARGET_API_MAC_OSX
1739 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1742 RgnHandle update
= NewRgn() ;
1743 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1744 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1745 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1749 RgnHandle updateRgn = NewRgn() ;
1752 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1756 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1757 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1759 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1760 DisposeRgn(updateRgn) ;
1762 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1764 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1765 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1768 if ( MacGetTopLevelWindow() == NULL )
1771 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1774 wxPoint client = GetClientAreaOrigin();
1777 int x2 = m_width - client.x;
1778 int y2 = m_height - client.y;
1780 if (IsKindOf( CLASSINFO(wxButton)))
1782 // buttons have an "aura"
1789 Rect clientrect = { y1, x1, y2, x2 };
1793 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1794 SectRect( &clientrect , &r , &clientrect ) ;
1797 if ( !EmptyRect( &clientrect ) )
1799 int top = 0 , left = 0 ;
1801 MacClientToRootWindow( &left , &top ) ;
1802 OffsetRect( &clientrect , left , top ) ;
1804 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1810 void wxWindowMac::MacRedrawControl()
1813 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1815 #if TARGET_API_MAC_CARBON
1818 wxClientDC dc(this) ;
1819 wxMacPortSetter helper(&dc) ;
1820 wxMacWindowClipper clipper(this) ;
1821 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1822 UMADrawControl( (ControlRef) m_macControl ) ;
1829 void wxWindowMac::OnPaint(wxPaintEvent& event)
1831 // why don't we skip that here ?
1835 wxWindowMac
*wxGetActiveWindow()
1837 // actually this is a windows-only concept
1841 // Coordinates relative to the window
1842 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1844 // We really don't move the mouse programmatically under Mac.
1847 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1849 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1854 event
.GetDC()->Clear() ;
1857 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1859 wxWindowDC
dc(this) ;
1860 wxMacPortSetter
helper(&dc
) ;
1862 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1865 int wxWindowMac::GetScrollPos(int orient
) const
1867 if ( orient
== wxHORIZONTAL
)
1870 return m_hScrollBar
->GetThumbPosition() ;
1875 return m_vScrollBar
->GetThumbPosition() ;
1880 // This now returns the whole range, not just the number
1881 // of positions that we can scroll.
1882 int wxWindowMac::GetScrollRange(int orient
) const
1884 if ( orient
== wxHORIZONTAL
)
1887 return m_hScrollBar
->GetRange() ;
1892 return m_vScrollBar
->GetRange() ;
1897 int wxWindowMac::GetScrollThumb(int orient
) const
1899 if ( orient
== wxHORIZONTAL
)
1902 return m_hScrollBar
->GetThumbSize() ;
1907 return m_vScrollBar
->GetThumbSize() ;
1912 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
1914 if ( orient
== wxHORIZONTAL
)
1917 m_hScrollBar
->SetThumbPosition( pos
) ;
1922 m_vScrollBar
->SetThumbPosition( pos
) ;
1926 void wxWindowMac::MacPaintBorders( int left
, int top
)
1932 wxGetOsVersion( &major
, &minor
);
1934 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
1935 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
1937 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
1938 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
1939 // OS X has lighter border edges than classic:
1942 darkShadow
.red
= 0x8E8E;
1943 darkShadow
.green
= 0x8E8E;
1944 darkShadow
.blue
= 0x8E8E;
1945 lightShadow
.red
= 0xBDBD;
1946 lightShadow
.green
= 0xBDBD;
1947 lightShadow
.blue
= 0xBDBD;
1953 GetSize( &w
, &h
) ;
1954 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
1956 #if wxMAC_USE_THEME_BORDER
1957 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
1960 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1961 InsetRect( &rect , border , border );
1962 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1965 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
1967 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
1968 RGBForeColor( &face
);
1969 MoveTo( left
+ 0 , top
+ h
- 2 );
1970 LineTo( left
+ 0 , top
+ 0 );
1971 LineTo( left
+ w
- 2 , top
+ 0 );
1973 MoveTo( left
+ 2 , top
+ h
- 3 );
1974 LineTo( left
+ w
- 3 , top
+ h
- 3 );
1975 LineTo( left
+ w
- 3 , top
+ 2 );
1977 RGBForeColor( sunken
? &face
: &darkShadow
);
1978 MoveTo( left
+ 0 , top
+ h
- 1 );
1979 LineTo( left
+ w
- 1 , top
+ h
- 1 );
1980 LineTo( left
+ w
- 1 , top
+ 0 );
1982 RGBForeColor( sunken
? &lightShadow
: &white
);
1983 MoveTo( left
+ 1 , top
+ h
- 3 );
1984 LineTo( left
+ 1, top
+ 1 );
1985 LineTo( left
+ w
- 3 , top
+ 1 );
1987 RGBForeColor( sunken
? &white
: &lightShadow
);
1988 MoveTo( left
+ 1 , top
+ h
- 2 );
1989 LineTo( left
+ w
- 2 , top
+ h
- 2 );
1990 LineTo( left
+ w
- 2 , top
+ 1 );
1992 RGBForeColor( sunken
? &darkShadow
: &face
);
1993 MoveTo( left
+ 2 , top
+ h
- 4 );
1994 LineTo( left
+ 2 , top
+ 2 );
1995 LineTo( left
+ w
- 4 , top
+ 2 );
1998 else if (HasFlag(wxSIMPLE_BORDER
))
2000 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2001 RGBForeColor( &darkShadow
) ;
2002 FrameRect( &rect
) ;
2006 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2008 if ( child
== m_hScrollBar
)
2009 m_hScrollBar
= NULL
;
2010 if ( child
== m_vScrollBar
)
2011 m_vScrollBar
= NULL
;
2013 wxWindowBase::RemoveChild( child
) ;
2016 // New function that will replace some of the above.
2017 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2018 int range
, bool refresh
)
2020 if ( orient
== wxHORIZONTAL
)
2024 if ( range
== 0 || thumbVisible
>= range
)
2026 if ( m_hScrollBar
->IsShown() )
2027 m_hScrollBar
->Show(false) ;
2031 if ( !m_hScrollBar
->IsShown() )
2032 m_hScrollBar
->Show(true) ;
2033 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2041 if ( range
== 0 || thumbVisible
>= range
)
2043 if ( m_vScrollBar
->IsShown() )
2044 m_vScrollBar
->Show(false) ;
2048 if ( !m_vScrollBar
->IsShown() )
2049 m_vScrollBar
->Show(true) ;
2050 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2054 MacRepositionScrollBars() ;
2057 // Does a physical scroll
2058 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2060 if( dx
== 0 && dy
==0 )
2065 wxClientDC
dc(this) ;
2066 wxMacPortSetter
helper(&dc
) ;
2068 int width
, height
;
2069 GetClientSize( &width
, &height
) ;
2076 // TODO take out the boundaries
2077 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2079 RgnHandle updateRgn
= NewRgn() ;
2082 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2083 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2084 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2086 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2088 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2089 // but it seems the update only refreshes the background of the control, rather than calling
2090 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2091 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2094 // we also have to scroll the update rgn in this rectangle
2095 // in order not to loose updates
2097 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2098 RgnHandle formerUpdateRgn
= NewRgn() ;
2099 RgnHandle scrollRgn
= NewRgn() ;
2100 RectRgn( scrollRgn
, &scrollrect
) ;
2101 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2103 LocalToGlobal( &pt
) ;
2104 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2105 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2106 if ( !EmptyRgn( formerUpdateRgn
) )
2108 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2109 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2110 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2112 InvalWindowRgn(rootWindow
, updateRgn
) ;
2113 DisposeRgn( updateRgn
) ;
2114 DisposeRgn( formerUpdateRgn
) ;
2115 DisposeRgn( scrollRgn
) ;
2119 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2121 wxWindowMac
*child
= node
->GetData();
2122 if (child
== m_vScrollBar
) continue;
2123 if (child
== m_hScrollBar
) continue;
2124 if (child
->IsTopLevel()) continue;
2127 child
->GetPosition( &x
, &y
);
2129 child
->GetSize( &w
, &h
);
2133 if (rect
->Intersects(rc
))
2134 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2138 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2142 // TODO remove, was moved higher up Update() ;
2146 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2148 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2150 wxScrollWinEvent wevent
;
2151 wevent
.SetPosition(event
.GetPosition());
2152 wevent
.SetOrientation(event
.GetOrientation());
2153 wevent
.m_eventObject
= this;
2155 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2156 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2157 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2158 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2159 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2160 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2161 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2162 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2163 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2164 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2165 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2166 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2167 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2168 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2169 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2170 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2172 GetEventHandler()->ProcessEvent(wevent
);
2176 // Get the window with the focus
2177 wxWindowMac
*wxWindowBase::FindFocus()
2179 return gFocusWindow
;
2182 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2184 // panel wants to track the window which was the last to have focus in it,
2185 // so we want to set ourselves as the window which last had focus
2187 // notice that it's also important to do it upwards the tree becaus
2188 // otherwise when the top level panel gets focus, it won't set it back to
2189 // us, but to some other sibling
2191 // CS:don't know if this is still needed:
2192 //wxChildFocusEvent eventFocus(this);
2193 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2198 void wxWindowMac::OnInternalIdle()
2200 // This calls the UI-update mechanism (querying windows for
2201 // menu/toolbar/control state information)
2202 if (wxUpdateUIEvent::CanUpdate(this))
2203 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2206 // Raise the window to the top of the Z order
2207 void wxWindowMac::Raise()
2211 // Lower the window to the bottom of the Z order
2212 void wxWindowMac::Lower()
2217 // static wxWindow *gs_lastWhich = NULL;
2219 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2221 // first trigger a set cursor event
2223 wxPoint clientorigin
= GetClientAreaOrigin() ;
2224 wxSize clientsize
= GetClientSize() ;
2226 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2228 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2230 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2231 if ( processedEvtSetCursor
&& event
.HasCursor() )
2233 cursor
= event
.GetCursor() ;
2238 // the test for processedEvtSetCursor is here to prevent using m_cursor
2239 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2240 // it - this is a way to say that our cursor shouldn't be used for this
2242 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2252 cursor
= *wxSTANDARD_CURSOR
;
2256 cursor
.MacInstall() ;
2258 return cursor
.Ok() ;
2261 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2265 return m_tooltip
->GetTip() ;
2267 return wxEmptyString
;
2270 void wxWindowMac::Update()
2272 #if TARGET_API_MAC_OSX
2273 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2275 ::Draw1Control( (ControlRef
) m_macControl
) ;
2279 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2281 wxTopLevelWindowMac
* win
= NULL
;
2282 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2285 win
= wxFindWinFromMacWindow( window
) ;
2289 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2293 RgnHandle visRgn
= NewRgn() ;
2294 RgnHandle tempRgn
= NewRgn() ;
2295 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2297 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2298 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2300 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2301 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2310 if ( includeOuterStructures
)
2311 InsetRect( &r
, -3 , -3 ) ;
2312 RectRgn( visRgn
, &r
) ;
2313 if ( !IsTopLevel() )
2315 wxWindow
* child
= this ;
2316 wxWindow
* parent
= child
->GetParent() ;
2321 // we have to find a better clipping algorithm here, in order not to clip things
2322 // positioned like status and toolbar
2323 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2325 size
= parent
->GetSize() ;
2330 size
= parent
->GetClientSize() ;
2331 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2335 parent
->MacWindowToRootWindow( &x
, &y
) ;
2336 MacRootWindowToWindow( &x
, &y
) ;
2338 SetRectRgn( tempRgn
,
2339 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2340 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2341 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2343 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2344 if ( parent
->IsTopLevel() )
2347 parent
= child
->GetParent() ;
2352 wxRegion vis
= visRgn
;
2353 DisposeRgn( visRgn
) ;
2354 DisposeRgn( tempRgn
) ;
2359 This function must not change the updatergn !
2361 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2363 // we let the OS handle root control redraws
2364 if ( m_macControl
== MacGetTopLevelWindow()->GetHandle() )
2367 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2368 bool handled
= false ;
2370 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2372 RgnHandle newupdate
= NewRgn() ;
2373 wxSize point
= GetClientSize() ;
2374 wxPoint origin
= GetClientAreaOrigin() ;
2375 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2376 SectRgn( newupdate
, updatergn
, newupdate
) ;
2377 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2378 m_updateRegion
= newupdate
;
2379 DisposeRgn( newupdate
) ;
2382 if ( !EmptyRgn(updatergn
) )
2384 wxWindowDC
dc(this);
2385 if (!EmptyRgn(updatergn
))
2386 dc
.SetClippingRegion(wxRegion(updatergn
));
2388 wxEraseEvent
eevent( GetId(), &dc
);
2389 eevent
.SetEventObject( this );
2390 GetEventHandler()->ProcessEvent( eevent
);
2392 if ( !m_updateRegion
.Empty() )
2394 // paint the window itself
2396 event
.m_timeStamp
= time
;
2397 event
.SetEventObject(this);
2398 handled
= GetEventHandler()->ProcessEvent(event
);
2400 // paint custom borders
2401 wxNcPaintEvent
eventNc( GetId() );
2402 eventNc
.SetEventObject( this );
2403 GetEventHandler()->ProcessEvent( eventNc
);
2409 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2411 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2412 // updatergn is always already clipped to our boundaries
2413 // if we are in compositing mode then it is in relative to the upper left of the control
2414 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2415 // of the toplevel window
2416 // it is in window coordinates, not in client coordinates
2418 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2419 RgnHandle ownUpdateRgn
= NewRgn() ;
2420 CopyRgn( updatergn
, ownUpdateRgn
) ;
2422 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2425 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2426 RgnHandle controlRgn
= NewRgn();
2427 RectRgn( controlRgn
, &bounds
);
2428 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2429 // the window update region
2430 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2431 DisposeRgn( controlRgn
);
2433 //KO: convert ownUpdateRgn to local coordinates
2434 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2437 MacDoRedraw( ownUpdateRgn
, time
) ;
2438 DisposeRgn( ownUpdateRgn
) ;
2442 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2444 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2448 if ( iter
->IsTopLevel() )
2449 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2451 iter
= iter
->GetParent() ;
2453 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2457 void wxWindowMac::MacCreateScrollBars( long style
)
2459 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2461 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2462 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2464 GetClientSize( &width
, &height
) ;
2466 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2467 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2468 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2469 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2471 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2472 vSize
, wxVERTICAL
);
2474 if ( style
& wxVSCROLL
)
2480 m_vScrollBar
->Show(false) ;
2482 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2483 hSize
, wxHORIZONTAL
);
2484 if ( style
& wxHSCROLL
)
2489 m_hScrollBar
->Show(false) ;
2492 // because the create does not take into account the client area origin
2493 MacRepositionScrollBars() ; // we might have a real position shift
2496 void wxWindowMac::MacRepositionScrollBars()
2498 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2499 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2501 // get real client area
2505 GetSize( &width
, &height
) ;
2507 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2508 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2510 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2511 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2512 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2513 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2519 GetSize( &w
, &h
) ;
2521 MacClientToRootWindow( &x
, &y
) ;
2522 MacClientToRootWindow( &w
, &h
) ;
2524 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2526 int totW
= 10000 , totH
= 10000;
2529 if ( iter
->IsTopLevel() )
2531 iter
->GetSize( &totW
, &totH
) ;
2535 iter
= iter
->GetParent() ;
2563 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2567 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2571 bool wxWindowMac::AcceptsFocus() const
2573 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2576 void wxWindowMac::MacSuperChangedPosition()
2578 // only window-absolute structures have to be moved i.e. controls
2580 wxWindowListNode
*node
= GetChildren().GetFirst();
2583 wxWindowMac
*child
= node
->GetData();
2584 child
->MacSuperChangedPosition() ;
2585 node
= node
->GetNext();
2589 void wxWindowMac::MacTopLevelWindowChangedPosition()
2591 // only screen-absolute structures have to be moved i.e. glcanvas
2593 wxWindowListNode
*node
= GetChildren().GetFirst();
2596 wxWindowMac
*child
= node
->GetData();
2597 child
->MacTopLevelWindowChangedPosition() ;
2598 node
= node
->GetNext();
2602 long wxWindowMac::MacGetLeftBorderSize( ) const
2607 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2610 #if wxMAC_USE_THEME_BORDER
2611 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2615 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2618 #if wxMAC_USE_THEME_BORDER
2619 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2623 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2630 long wxWindowMac::MacGetRightBorderSize( ) const
2632 // they are all symmetric in mac themes
2633 return MacGetLeftBorderSize() ;
2636 long wxWindowMac::MacGetTopBorderSize( ) const
2638 // they are all symmetric in mac themes
2639 return MacGetLeftBorderSize() ;
2642 long wxWindowMac::MacGetBottomBorderSize( ) const
2644 // they are all symmetric in mac themes
2645 return MacGetLeftBorderSize() ;
2648 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2650 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2653 // Find the wxWindowMac at the current mouse position, returning the mouse
2655 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2657 pt
= wxGetMousePosition();
2658 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2662 // Get the current mouse position.
2663 wxPoint
wxGetMousePosition()
2666 wxGetMousePosition(& x
, & y
);
2667 return wxPoint(x
, y
);
2670 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2672 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2674 // copied from wxGTK : CS
2675 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2678 // (a) it's a command event and so is propagated to the parent
2679 // (b) under MSW it can be generated from kbd too
2680 // (c) it uses screen coords (because of (a))
2681 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2683 this->ClientToScreen(event
.GetPosition()));
2684 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2687 else if (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
2693 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2695 // OS Needs it in tlw content area coordinates
2696 MacClientToRootWindow( &x
, &y
) ;
2700 // OS Needs it in window not client coordinates
2701 wxPoint origin
= GetClientAreaOrigin() ;
2706 SInt16 controlpart
;
2711 short modifiers
= 0;
2713 if ( !event
.m_leftDown
&& !event
.m_rightDown
)
2714 modifiers
|= btnState
;
2716 if ( event
.m_shiftDown
)
2717 modifiers
|= shiftKey
;
2719 if ( event
.m_controlDown
)
2720 modifiers
|= controlKey
;
2722 if ( event
.m_altDown
)
2723 modifiers
|= optionKey
;
2725 if ( event
.m_metaDown
)
2726 modifiers
|= cmdKey
;
2728 bool handled
= false ;
2730 if ( ::IsControlActive( (ControlRef
) m_macControl
) )
2732 controlpart
= ::HandleControlClick( (ControlRef
) m_macControl
, localwhere
, modifiers
, (ControlActionUPP
) -1 ) ;
2733 wxTheApp
->s_lastMouseDown
= 0 ;
2734 if ( controlpart
!= kControlNoPart
)
2736 MacHandleControlClick((WXWidget
) (ControlRef
) m_macControl
, controlpart
, false /* mouse not down anymore */ ) ;
2749 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2751 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
2754 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
2758 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
2759 Rect bounds
= { y
, x
, y
+h
, x
+w
};