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
;
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
74 #endif // __WXUNIVERSAL__/__WXMAC__
76 #if !USE_SHARED_LIBRARY
78 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
79 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
80 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
81 // TODO EVT_PAINT(wxWindowMac::OnPaint)
82 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
83 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
84 // EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
85 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 0
97 // ---------------------------------------------------------------------------
99 // ---------------------------------------------------------------------------
101 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
102 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
104 #if TARGET_API_MAC_OSX
106 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
108 kEventControlVisibilityChanged
= 157
114 static const EventTypeSpec eventList
[] =
116 { kEventClassControl
, kEventControlHit
} ,
117 #if TARGET_API_MAC_OSX
118 { kEventClassControl
, kEventControlDraw
} ,
119 { kEventClassControl
, kEventControlVisibilityChanged
} ,
120 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
121 { kEventClassControl
, kEventControlHiliteChanged
} ,
122 { kEventClassControl
, kEventControlSetFocusPart
} ,
123 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
124 // { kEventClassControl , kEventControlBoundsChanged } ,
128 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
130 OSStatus result
= eventNotHandledErr
;
132 wxMacCarbonEvent
cEvent( event
) ;
134 ControlRef controlRef
;
135 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
137 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
139 switch( GetEventKind( event
) )
141 #if TARGET_API_MAC_OSX
142 case kEventControlDraw
:
144 RgnHandle updateRgn
= NULL
;
146 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
147 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
149 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
151 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
154 // in case we would need a coregraphics compliant background erase first
155 // now usable to track redraws
156 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
157 if ( thisWindow
->MacIsUserPane() )
159 static float color
= 0.5 ;
162 HIViewGetBounds( controlRef
, &bounds
);
163 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
164 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
165 CGContextFillRect( cgContext
, bounds
);
176 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
180 case kEventControlVisibilityChanged
:
181 thisWindow
->MacVisibilityChanged() ;
183 case kEventControlEnabledStateChanged
:
184 thisWindow
->MacEnabledStateChanged() ;
186 case kEventControlHiliteChanged
:
187 thisWindow
->MacHiliteChanged() ;
189 case kEventControlSetFocusPart
:
191 Boolean focusEverything
= false ;
192 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
193 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
196 if ( controlPart
== kControlFocusNoPart
)
199 if ( thisWindow
->GetCaret() )
201 thisWindow
->GetCaret()->OnKillFocus();
203 #endif // wxUSE_CARET
204 wxFocusEvent
event(wxEVT_KILL_FOCUS
, thisWindow
->GetId());
205 event
.SetEventObject(thisWindow
);
206 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
210 // panel wants to track the window which was the last to have focus in it
211 wxChildFocusEvent
eventFocus(thisWindow
);
212 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
215 if ( thisWindow
->GetCaret() )
217 thisWindow
->GetCaret()->OnSetFocus();
219 #endif // wxUSE_CARET
221 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
222 event
.SetEventObject(thisWindow
);
223 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
228 case kEventControlHit
:
230 result
= thisWindow
->MacControlHit( handler
, event
) ;
239 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
241 OSStatus result
= eventNotHandledErr
;
243 switch ( GetEventClass( event
) )
245 case kEventClassControl
:
246 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
254 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
256 // ---------------------------------------------------------------------------
257 // UserPane events for non OSX builds
258 // ---------------------------------------------------------------------------
260 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
262 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
263 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
264 win
->MacControlUserPaneDrawProc(part
) ;
267 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
269 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
270 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
271 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
274 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
276 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
277 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
278 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
281 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
283 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
284 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
285 win
->MacControlUserPaneIdleProc() ;
288 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
290 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
291 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
292 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
295 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
297 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
298 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
299 win
->MacControlUserPaneActivateProc(activating
) ;
302 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
304 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
305 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
306 return win
->MacControlUserPaneFocusProc(action
) ;
309 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
311 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
312 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
313 win
->MacControlUserPaneBackgroundProc(info
) ;
316 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
318 RgnHandle rgn
= NewRgn() ;
320 wxMacWindowStateSaver
sv( this ) ;
321 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
322 MacDoRedraw( rgn
, 0 ) ;
326 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
328 return kControlNoPart
;
331 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
333 return kControlNoPart
;
336 void wxWindowMac::MacControlUserPaneIdleProc()
340 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
342 return kControlNoPart
;
345 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
349 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
351 return kControlNoPart
;
354 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
358 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
359 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
360 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
361 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
362 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
363 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
364 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
365 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
367 // ===========================================================================
369 // ===========================================================================
371 wxList
wxWinMacControlList(wxKEY_INTEGER
);
373 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
375 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
378 return (wxControl
*)node
->GetData();
381 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
383 // adding NULL ControlRef is (first) surely a result of an error and
384 // (secondly) breaks native event processing
385 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
387 if ( !wxWinMacControlList
.Find((long)inControl
) )
388 wxWinMacControlList
.Append((long)inControl
, control
);
391 void wxRemoveMacControlAssociation(wxWindow
*control
)
393 wxWinMacControlList
.DeleteObject(control
);
397 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
399 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
401 // we have to setup the brush in the current port and return noErr
402 // or return an error code so that the control manager walks further up the
403 // hierarchy to find a correct background
405 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
407 OSStatus status
= paramErr
;
410 case kControlMsgApplyTextColor
:
412 case kControlMsgSetUpBackground
:
414 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
418 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
422 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
424 // this clipping is only needed for non HIView
426 RgnHandle clip
= NewRgn() ;
429 wx
->MacWindowToRootWindow( &x
,&y
) ;
430 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
431 OffsetRgn( clip
, x
, y
) ;
438 else if ( wx->MacIsUserPane() )
440 // if we don't have a valid brush for such a control, we have to call the
441 // setup of our parent ourselves
442 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
455 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
456 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
460 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
463 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
468 // ----------------------------------------------------------------------------
469 // constructors and such
470 // ----------------------------------------------------------------------------
472 void wxWindowMac::Init()
475 #if WXWIN_COMPATIBILITY_2_4
476 m_backgroundTransparent
= FALSE
;
479 // as all windows are created with WS_VISIBLE style...
482 m_hScrollBar
= NULL
;
483 m_vScrollBar
= NULL
;
484 m_macBackgroundBrush
= wxNullBrush
;
486 m_macControl
= NULL
;
488 m_macIsUserPane
= TRUE
;
490 // make sure all proc ptrs are available
492 if ( gControlUserPaneDrawUPP
== NULL
)
494 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
495 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
496 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
497 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
498 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
499 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
500 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
501 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
503 if ( wxMacLiveScrollbarActionUPP
== NULL
)
505 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
508 if ( wxMacSetupControlBackgroundUPP
== NULL
)
510 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
513 // we need a valid font for the encodings
514 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
518 wxWindowMac::~wxWindowMac()
522 m_isBeingDeleted
= TRUE
;
524 #ifndef __WXUNIVERSAL__
525 // VS: make sure there's no wxFrame with last focus set to us:
526 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
528 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
531 if ( frame
->GetLastFocus() == this )
533 frame
->SetLastFocus((wxWindow
*)NULL
);
538 #endif // __WXUNIVERSAL__
540 // wxRemoveMacControlAssociation( this ) ;
541 // If we delete an item, we should initialize the parent panel,
542 // because it could now be invalid.
543 wxWindow
*parent
= GetParent() ;
546 if (parent
->GetDefaultItem() == (wxButton
*) this)
547 parent
->SetDefaultItem(NULL
);
549 if ( (ControlRef
) m_macControl
)
551 // in case the callback might be called during destruction
552 wxRemoveMacControlAssociation( this) ;
553 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
554 ::DisposeControl( (ControlRef
) m_macControl
) ;
555 m_macControl
= NULL
;
558 if ( g_MacLastWindow
== this )
560 g_MacLastWindow
= NULL
;
563 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
566 if ( frame
->GetLastFocus() == this )
567 frame
->SetLastFocus( NULL
) ;
572 // delete our drop target if we've got one
573 #if wxUSE_DRAG_AND_DROP
574 if ( m_dropTarget
!= NULL
)
579 #endif // wxUSE_DRAG_AND_DROP
584 void wxWindowMac::MacInstallEventHandler()
586 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
587 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
588 GetEventTypeCount(eventList
), eventList
, this,
589 (EventHandlerRef
*)&m_macControlEventHandler
);
594 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
598 const wxString
& name
)
600 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
602 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
605 parent
->AddChild(this);
607 m_windowVariant
= parent
->GetWindowVariant() ;
609 if ( m_macIsUserPane
)
611 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
614 | kControlSupportsEmbedding
615 // | kControlSupportsLiveFeedback
616 // | kControlHasSpecialBackground
617 // | kControlSupportsCalcBestRect
618 // | kControlHandlesTracking
619 | kControlSupportsFocus
620 // | kControlWantsActivate
621 // | kControlWantsIdle
624 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
626 MacPostControlCreate(pos
,size
) ;
627 #if !TARGET_API_MAC_OSX
628 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
629 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
630 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
631 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
632 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
633 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
634 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
635 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
636 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
637 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
638 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
639 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
640 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
641 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
642 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
643 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
646 #ifndef __WXUNIVERSAL__
647 // Don't give scrollbars to wxControls unless they ask for them
648 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
649 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
651 MacCreateScrollBars( style
) ;
655 wxWindowCreateEvent
event(this);
656 GetEventHandler()->AddPendingEvent(event
);
661 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
663 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
665 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
667 MacInstallEventHandler();
669 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
670 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
671 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
673 // adjust font, controlsize etc
674 DoSetWindowVariant( m_windowVariant
) ;
676 #if !TARGET_API_MAC_OSX
677 // eventually we can fix some clipping issues be reactivating this hook
678 //if ( m_macIsUserPane )
679 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
682 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
684 wxSize new_size
= size
;
685 if (!m_macIsUserPane
)
687 SetInitialBestSize(size
);
690 SetCursor( *wxSTANDARD_CURSOR
) ;
694 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
696 // Don't assert, in case we set the window variant before
697 // the window is created
698 // wxASSERT( m_macControl != NULL ) ;
700 m_windowVariant
= variant
;
706 ThemeFontID themeFont
= kThemeSystemFont
;
708 // we will get that from the settings later
709 // and make this NORMAL later, but first
710 // we have a few calculations that we must fix
714 case wxWINDOW_VARIANT_NORMAL
:
715 size
= kControlSizeNormal
;
716 themeFont
= kThemeSystemFont
;
718 case wxWINDOW_VARIANT_SMALL
:
719 size
= kControlSizeSmall
;
720 themeFont
= kThemeSmallSystemFont
;
722 case wxWINDOW_VARIANT_MINI
:
723 if (UMAGetSystemVersion() >= 0x1030 )
725 // not always defined in the headers
731 size
= kControlSizeSmall
;
732 themeFont
= kThemeSmallSystemFont
;
735 case wxWINDOW_VARIANT_LARGE
:
736 size
= kControlSizeLarge
;
737 themeFont
= kThemeSystemFont
;
740 wxFAIL_MSG(_T("unexpected window variant"));
743 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
746 font
.MacCreateThemeFont( themeFont
) ;
750 void wxWindowMac::MacUpdateControlFont()
752 ControlFontStyleRec fontStyle
;
753 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
755 switch( m_font
.MacGetThemeFontID() )
757 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
758 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
759 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
760 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
762 fontStyle
.flags
= kControlUseFontMask
;
766 fontStyle
.font
= m_font
.MacGetFontNum() ;
767 fontStyle
.style
= m_font
.MacGetFontStyle() ;
768 fontStyle
.size
= m_font
.MacGetFontSize() ;
769 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
772 fontStyle
.just
= teJustLeft
;
773 fontStyle
.flags
|= kControlUseJustMask
;
774 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
775 fontStyle
.just
= teJustCenter
;
776 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
777 fontStyle
.just
= teJustRight
;
780 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
781 fontStyle
.flags
|= kControlUseForeColorMask
;
783 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
787 bool wxWindowMac::SetFont(const wxFont
& font
)
789 bool retval
= !wxWindowBase::SetFont( font
) ;
791 MacUpdateControlFont() ;
796 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
798 if ( !wxWindowBase::SetForegroundColour(col
) )
801 MacUpdateControlFont() ;
806 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
808 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
812 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
814 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
816 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
818 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
822 brush
.SetColour( col
) ;
824 MacSetBackgroundBrush( brush
) ;
826 MacUpdateControlFont() ;
832 bool wxWindowMac::MacCanFocus() const
835 // there is currently no way to determinate whether the window is running in full keyboard
836 // access mode, therefore we cannot rely on these features yet
837 UInt32 features
= 0 ;
838 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
839 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
845 void wxWindowMac::SetFocus()
847 if ( AcceptsFocus() )
849 #if !TARGET_API_MAC_OSX
850 wxWindow
* former
= FindFocus() ;
852 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
853 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
854 // leave in case of an error
855 if ( err
== errCouldntSetFocus
)
858 #if !TARGET_API_MAC_OSX
859 // emulate carbon events when running under carbonlib where they are not natively available
862 EventRef evRef
= NULL
;
863 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
866 wxMacCarbonEvent
cEvent( evRef
) ;
867 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
868 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
870 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
871 ReleaseEvent(evRef
) ;
873 // send new focus event
875 EventRef evRef
= NULL
;
876 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
879 wxMacCarbonEvent
cEvent( evRef
) ;
880 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
881 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
883 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
884 ReleaseEvent(evRef
) ;
891 void wxWindowMac::DoCaptureMouse()
893 wxTheApp
->s_captureWindow
= this ;
896 wxWindow
* wxWindowBase::GetCapture()
898 return wxTheApp
->s_captureWindow
;
901 void wxWindowMac::DoReleaseMouse()
903 wxTheApp
->s_captureWindow
= NULL
;
906 #if wxUSE_DRAG_AND_DROP
908 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
910 if ( m_dropTarget
!= 0 ) {
914 m_dropTarget
= pDropTarget
;
915 if ( m_dropTarget
!= 0 )
923 // Old style file-manager drag&drop
924 void wxWindowMac::DragAcceptFiles(bool accept
)
929 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
930 int& w
, int& h
) const
933 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
938 w
= bounds
.right
- bounds
.left
;
939 h
= bounds
.bottom
- bounds
.top
;
941 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
944 Point tlworigin
= { 0 , 0 } ;
946 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
947 ::LocalToGlobal( &tlworigin
) ;
955 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
958 int& w
, int& h
, bool adjustOrigin
) const
962 // todo the default calls may be used as soon as PostCreateControl Is moved here
963 w
= size
.x
; // WidthDefault( size.x );
964 h
= size
.y
; // HeightDefault( size.y ) ;
965 #if !TARGET_API_MAC_OSX
966 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
969 AdjustForParentClientOrigin( x
, y
) ;
974 void wxWindowMac::DoGetSize(int *x
, int *y
) const
976 #if TARGET_API_MAC_OSX
977 int x1
, y1
, w1
,h1
;
978 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
984 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
985 if(x
) *x
= bounds
.right
- bounds
.left
;
986 if(y
) *y
= bounds
.bottom
- bounds
.top
;
990 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
992 #if TARGET_API_MAC_OSX
993 int x1
, y1
, w1
,h1
;
994 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
997 wxWindow
*parent
= GetParent();
1000 wxPoint
pt(parent
->GetClientAreaOrigin());
1009 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1010 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1012 int xx
= bounds
.left
;
1013 int yy
= bounds
.top
;
1015 if ( !GetParent()->IsTopLevel() )
1017 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1023 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1032 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1034 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1036 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1039 Point localwhere
= {0,0} ;
1041 if(x
) localwhere
.h
= * x
;
1042 if(y
) localwhere
.v
= * y
;
1044 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1045 ::GlobalToLocal( &localwhere
) ;
1046 if(x
) *x
= localwhere
.h
;
1047 if(y
) *y
= localwhere
.v
;
1050 MacRootWindowToWindow( x
, y
) ;
1052 wxPoint origin
= GetClientAreaOrigin() ;
1053 if(x
) *x
-= origin
.x
;
1054 if(y
) *y
-= origin
.y
;
1057 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1059 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1060 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1062 wxPoint origin
= GetClientAreaOrigin() ;
1063 if(x
) *x
+= origin
.x
;
1064 if(y
) *y
+= origin
.y
;
1066 MacWindowToRootWindow( x
, y
) ;
1069 Point localwhere
= { 0,0 };
1070 if(x
) localwhere
.h
= * x
;
1071 if(y
) localwhere
.v
= * y
;
1073 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1074 ::LocalToGlobal( &localwhere
) ;
1075 if(x
) *x
= localwhere
.h
;
1076 if(y
) *y
= localwhere
.v
;
1080 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1082 wxPoint origin
= GetClientAreaOrigin() ;
1083 if(x
) *x
+= origin
.x
;
1084 if(y
) *y
+= origin
.y
;
1086 MacWindowToRootWindow( x
, y
) ;
1089 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1091 MacRootWindowToWindow( x
, y
) ;
1093 wxPoint origin
= GetClientAreaOrigin() ;
1094 if(x
) *x
-= origin
.x
;
1095 if(y
) *y
-= origin
.y
;
1098 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1100 #if TARGET_API_MAC_OSX
1102 if ( x
) pt
.x
= *x
;
1103 if ( y
) pt
.y
= *y
;
1105 if ( !IsTopLevel() )
1106 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1108 if ( x
) *x
= (int) pt
.x
;
1109 if ( y
) *y
= (int) pt
.y
;
1111 if ( !IsTopLevel() )
1114 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1115 if(x
) *x
+= bounds
.left
;
1116 if(y
) *y
+= bounds
.top
;
1121 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1126 MacWindowToRootWindow( &x1
, &y1
) ;
1131 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1133 #if TARGET_API_MAC_OSX
1135 if ( x
) pt
.x
= *x
;
1136 if ( y
) pt
.y
= *y
;
1138 if ( !IsTopLevel() )
1139 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1141 if ( x
) *x
= (int) pt
.x
;
1142 if ( y
) *y
= (int) pt
.y
;
1144 if ( !IsTopLevel() )
1147 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1148 if(x
) *x
-= bounds
.left
;
1149 if(y
) *y
-= bounds
.top
;
1154 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1159 MacRootWindowToWindow( &x1
, &y1
) ;
1164 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1166 RgnHandle rgn
= NewRgn() ;
1168 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1170 GetRegionBounds( rgn
, &content
) ;
1175 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1178 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1179 #if !TARGET_API_MAC_OSX
1180 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1182 left
= content
.left
- structure
.left
;
1183 top
= content
.top
- structure
.top
;
1184 right
= structure
.right
- content
.right
;
1185 bottom
= structure
.bottom
- content
.bottom
;
1188 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1190 wxSize sizeTotal
= size
;
1192 RgnHandle rgn
= NewRgn() ;
1196 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1198 GetRegionBounds( rgn
, &content
) ;
1203 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1206 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1207 #if !TARGET_API_MAC_OSX
1208 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1211 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1212 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1214 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1215 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1221 // Get size *available for subwindows* i.e. excluding menu bar etc.
1222 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1226 RgnHandle rgn
= NewRgn() ;
1228 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1230 GetRegionBounds( rgn
, &content
) ;
1235 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1237 #if !TARGET_API_MAC_OSX
1239 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1240 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1242 ww
= content
.right
- content
.left
;
1243 hh
= content
.bottom
- content
.top
;
1245 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1246 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1248 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1254 GetSize( &w
, &h
) ;
1256 MacClientToRootWindow( &x1
, &y1
) ;
1257 MacClientToRootWindow( &w
, &h
) ;
1259 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1261 int totW
= 10000 , totH
= 10000;
1264 if ( iter
->IsTopLevel() )
1266 iter
->GetSize( &totW
, &totH
) ;
1270 iter
= iter
->GetParent() ;
1273 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1275 hh
-= MAC_SCROLLBAR_SIZE
;
1281 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1283 ww
-= MAC_SCROLLBAR_SIZE
;
1295 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1297 if (m_cursor
== cursor
)
1300 if (wxNullCursor
== cursor
)
1302 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1307 if ( ! wxWindowBase::SetCursor( cursor
) )
1311 wxASSERT_MSG( m_cursor
.Ok(),
1312 wxT("cursor must be valid after call to the base version"));
1316 TODO why do we have to use current coordinates ?
1319 wxWindowMac *mouseWin ;
1322 // Change the cursor NOW if we're within the correct window
1325 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1327 if ( mouseWin == this && !wxIsBusy() )
1329 m_cursor.MacInstall() ;
1335 m_cursor
.MacInstall() ;
1342 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1344 menu
->SetInvokingWindow(this);
1346 ClientToScreen( &x
, &y
) ;
1348 menu
->MacBeforeDisplay( true ) ;
1349 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1350 if ( HiWord(menuResult
) != 0 )
1353 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1354 wxMenuItem
* item
= NULL
;
1356 item
= menu
->FindItem(id
, &realmenu
) ;
1357 if (item
->IsCheckable())
1359 item
->Check( !item
->IsChecked() ) ;
1361 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1363 menu
->MacAfterDisplay( true ) ;
1365 menu
->SetInvokingWindow(NULL
);
1371 // ----------------------------------------------------------------------------
1373 // ----------------------------------------------------------------------------
1377 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1379 wxWindowBase::DoSetToolTip(tooltip
);
1382 m_tooltip
->SetWindow(this);
1385 #endif // wxUSE_TOOLTIPS
1387 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1389 int former_x
, former_y
, former_w
, former_h
;
1390 #if !TARGET_API_MAC_OSX
1391 DoGetPosition( &former_x
, &former_y
) ;
1392 DoGetSize( &former_w
, &former_h
) ;
1394 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1397 int actualWidth
= width
;
1398 int actualHeight
= height
;
1402 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1403 actualWidth
= m_minWidth
;
1404 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1405 actualHeight
= m_minHeight
;
1406 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1407 actualWidth
= m_maxWidth
;
1408 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1409 actualHeight
= m_maxHeight
;
1411 bool doMove
= false ;
1412 bool doResize
= false ;
1414 if ( actualX
!= former_x
|| actualY
!= former_y
)
1418 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1423 if ( doMove
|| doResize
)
1425 // we don't adjust twice for the origin
1426 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1427 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1428 #if TARGET_API_MAC_OSX
1429 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1431 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1432 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1433 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1435 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1438 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1439 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1441 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1443 MacRepositionScrollBars() ;
1446 wxPoint
point(actualX
,actualY
);
1447 wxMoveEvent
event(point
, m_windowId
);
1448 event
.SetEventObject(this);
1449 GetEventHandler()->ProcessEvent(event
) ;
1453 MacRepositionScrollBars() ;
1454 wxSize
size(actualWidth
, actualHeight
);
1455 wxSizeEvent
event(size
, m_windowId
);
1456 event
.SetEventObject(this);
1457 GetEventHandler()->ProcessEvent(event
);
1463 wxSize
wxWindowMac::DoGetBestSize() const
1465 if ( m_macIsUserPane
|| IsTopLevel() )
1466 return wxWindowBase::DoGetBestSize() ;
1468 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1469 short baselineoffset
;
1470 int bestWidth
, bestHeight
;
1471 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1473 if ( EmptyRect( &bestsize
) )
1476 bestsize
.left
= bestsize
.top
= 0 ;
1477 bestsize
.right
= 16 ;
1478 bestsize
.bottom
= 16 ;
1479 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1481 bestsize
.bottom
= 16 ;
1483 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1485 bestsize
.bottom
= 24 ;
1489 // return wxWindowBase::DoGetBestSize() ;
1493 bestWidth
= bestsize
.right
- bestsize
.left
;
1494 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1495 if ( bestHeight
< 10 )
1498 return wxSize(bestWidth
, bestHeight
);
1499 // return wxWindowBase::DoGetBestSize() ;
1503 // set the size of the window: if the dimensions are positive, just use them,
1504 // but if any of them is equal to -1, it means that we must find the value for
1505 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1506 // which case -1 is a valid value for x and y)
1508 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1509 // the width/height to best suit our contents, otherwise we reuse the current
1511 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1513 // get the current size and position...
1514 int currentX
, currentY
;
1515 GetPosition(¤tX
, ¤tY
);
1517 int currentW
,currentH
;
1518 GetSize(¤tW
, ¤tH
);
1520 // ... and don't do anything (avoiding flicker) if it's already ok
1521 if ( x
== currentX
&& y
== currentY
&&
1522 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1525 MacRepositionScrollBars() ; // we might have a real position shift
1529 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1531 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1534 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1536 wxSize
size(-1, -1);
1539 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1541 size
= DoGetBestSize();
1546 // just take the current one
1553 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1557 size
= DoGetBestSize();
1559 //else: already called DoGetBestSize() above
1565 // just take the current one
1570 DoMoveWindow(x
, y
, width
, height
);
1574 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1576 RgnHandle rgn
= NewRgn() ;
1578 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1579 GetRegionBounds( rgn
, &content
) ;
1581 #if !TARGET_API_MAC_OSX
1582 // if the content rgn is empty / not supported
1583 // don't attempt to correct the coordinates to wxWindow relative ones
1584 if (!::EmptyRect( &content
) )
1587 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1588 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1592 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1595 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1597 if ( clientheight
!= -1 || clientheight
!= -1 )
1599 int currentclientwidth
, currentclientheight
;
1600 int currentwidth
, currentheight
;
1602 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1603 GetSize( ¤twidth
, ¤theight
) ;
1605 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1606 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1610 void wxWindowMac::SetTitle(const wxString
& title
)
1612 m_label
= wxStripMenuCodes(title
) ;
1616 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1621 wxString
wxWindowMac::GetTitle() const
1626 bool wxWindowMac::Show(bool show
)
1628 if ( !wxWindowBase::Show(show
) )
1631 // TODO use visibilityChanged Carbon Event for OSX
1632 bool former
= MacIsReallyShown() ;
1634 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1635 if ( former
!= MacIsReallyShown() )
1636 MacPropagateVisibilityChanged() ;
1640 bool wxWindowMac::Enable(bool enable
)
1642 wxASSERT( m_macControl
!= NULL
) ;
1643 if ( !wxWindowBase::Enable(enable
) )
1646 bool former
= MacIsReallyEnabled() ;
1647 #if TARGET_API_MAC_OSX
1649 EnableControl( (ControlRef
) m_macControl
) ;
1651 DisableControl( (ControlRef
) m_macControl
) ;
1654 ActivateControl( (ControlRef
) m_macControl
) ;
1656 DeactivateControl( (ControlRef
) m_macControl
) ;
1659 if ( former
!= MacIsReallyEnabled() )
1660 MacPropagateEnabledStateChanged() ;
1665 // status change propagations (will be not necessary for OSX later )
1668 void wxWindowMac::MacPropagateVisibilityChanged()
1670 #if !TARGET_API_MAC_OSX
1671 MacVisibilityChanged() ;
1673 wxWindowListNode
*node
= GetChildren().GetFirst();
1676 wxWindowMac
*child
= node
->GetData();
1677 if ( child
->IsShown() )
1678 child
->MacPropagateVisibilityChanged( ) ;
1679 node
= node
->GetNext();
1684 void wxWindowMac::MacPropagateEnabledStateChanged( )
1686 #if !TARGET_API_MAC_OSX
1687 MacEnabledStateChanged() ;
1689 wxWindowListNode
*node
= GetChildren().GetFirst();
1692 wxWindowMac
*child
= node
->GetData();
1693 if ( child
->IsEnabled() )
1694 child
->MacPropagateEnabledStateChanged() ;
1695 node
= node
->GetNext();
1700 void wxWindowMac::MacPropagateHiliteChanged( )
1702 #if !TARGET_API_MAC_OSX
1703 MacHiliteChanged() ;
1705 wxWindowListNode
*node
= GetChildren().GetFirst();
1708 wxWindowMac
*child
= node
->GetData();
1709 // if ( child->IsEnabled() )
1710 child
->MacPropagateHiliteChanged() ;
1711 node
= node
->GetNext();
1717 // status change notifications
1720 void wxWindowMac::MacVisibilityChanged()
1724 void wxWindowMac::MacHiliteChanged()
1728 void wxWindowMac::MacEnabledStateChanged()
1733 // status queries on the inherited window's state
1736 bool wxWindowMac::MacIsReallyShown()
1738 // only under OSX the visibility of the TLW is taken into account
1739 #if TARGET_API_MAC_OSX
1740 return IsControlVisible( (ControlRef
) m_macControl
) ;
1742 wxWindow
* win
= this ;
1743 while( win
->IsShown() )
1745 if ( win
->IsTopLevel() )
1748 win
= win
->GetParent() ;
1757 bool wxWindowMac::MacIsReallyEnabled()
1759 #if TARGET_API_MAC_OSX
1760 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1762 return IsControlActive( (ControlRef
) m_macControl
) ;
1766 bool wxWindowMac::MacIsReallyHilited()
1768 return IsControlActive( (ControlRef
) m_macControl
) ;
1775 int wxWindowMac::GetCharHeight() const
1777 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1778 return dc
.GetCharHeight() ;
1781 int wxWindowMac::GetCharWidth() const
1783 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1784 return dc
.GetCharWidth() ;
1787 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1788 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1790 const wxFont
*fontToUse
= theFont
;
1792 fontToUse
= &m_font
;
1794 wxClientDC
dc( (wxWindowMac
*) this ) ;
1796 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1797 if ( externalLeading
)
1798 *externalLeading
= le
;
1808 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1809 * we always intersect with the entire window, not only with the client area
1812 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1814 #if TARGET_API_MAC_OSX
1816 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1819 RgnHandle update
= NewRgn() ;
1820 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1821 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1822 wxPoint origin
= GetClientAreaOrigin() ;
1823 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1824 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1828 RgnHandle updateRgn = NewRgn() ;
1831 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1835 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1836 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1838 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1839 DisposeRgn(updateRgn) ;
1841 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1843 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1844 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1847 if ( MacGetTopLevelWindow() == NULL )
1850 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1853 wxPoint client = GetClientAreaOrigin();
1856 int x2 = m_width - client.x;
1857 int y2 = m_height - client.y;
1859 if (IsKindOf( CLASSINFO(wxButton)))
1861 // buttons have an "aura"
1868 Rect clientrect = { y1, x1, y2, x2 };
1872 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1873 SectRect( &clientrect , &r , &clientrect ) ;
1876 if ( !EmptyRect( &clientrect ) )
1878 int top = 0 , left = 0 ;
1880 MacClientToRootWindow( &left , &top ) ;
1881 OffsetRect( &clientrect , left , top ) ;
1883 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1889 void wxWindowMac::Freeze()
1891 #if TARGET_API_MAC_OSX
1892 if ( !m_frozenness
++ )
1894 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1899 #if TARGET_API_MAC_OSX
1900 static void InvalidateControlAndChildren( HIViewRef control
)
1902 HIViewSetNeedsDisplay( control
, true ) ;
1903 UInt16 childrenCount
= 0 ;
1904 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1905 if ( err
== errControlIsNotEmbedder
)
1907 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1909 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1912 err
= GetIndexedSubControl( control
, i
, & child
) ;
1913 if ( err
== errControlIsNotEmbedder
)
1915 InvalidateControlAndChildren( child
) ;
1920 void wxWindowMac::Thaw()
1922 #if TARGET_API_MAC_OSX
1923 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1925 if ( !--m_frozenness
)
1927 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
1928 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
1929 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
1934 void wxWindowMac::MacRedrawControl()
1937 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
1939 #if TARGET_API_MAC_CARBON
1942 wxClientDC dc(this) ;
1943 wxMacPortSetter helper(&dc) ;
1944 wxMacWindowClipper clipper(this) ;
1945 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
1946 UMADrawControl( (ControlRef) m_macControl ) ;
1953 void wxWindowMac::OnPaint(wxPaintEvent& event)
1955 // why don't we skip that here ?
1959 wxWindowMac
*wxGetActiveWindow()
1961 // actually this is a windows-only concept
1965 // Coordinates relative to the window
1966 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
1968 // We really don't move the mouse programmatically under Mac.
1971 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
1973 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
1978 event
.GetDC()->Clear() ;
1981 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
1983 wxWindowDC
dc(this) ;
1984 wxMacPortSetter
helper(&dc
) ;
1986 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
1989 int wxWindowMac::GetScrollPos(int orient
) const
1991 if ( orient
== wxHORIZONTAL
)
1994 return m_hScrollBar
->GetThumbPosition() ;
1999 return m_vScrollBar
->GetThumbPosition() ;
2004 // This now returns the whole range, not just the number
2005 // of positions that we can scroll.
2006 int wxWindowMac::GetScrollRange(int orient
) const
2008 if ( orient
== wxHORIZONTAL
)
2011 return m_hScrollBar
->GetRange() ;
2016 return m_vScrollBar
->GetRange() ;
2021 int wxWindowMac::GetScrollThumb(int orient
) const
2023 if ( orient
== wxHORIZONTAL
)
2026 return m_hScrollBar
->GetThumbSize() ;
2031 return m_vScrollBar
->GetThumbSize() ;
2036 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2038 if ( orient
== wxHORIZONTAL
)
2041 m_hScrollBar
->SetThumbPosition( pos
) ;
2046 m_vScrollBar
->SetThumbPosition( pos
) ;
2050 void wxWindowMac::MacPaintBorders( int left
, int top
)
2056 wxGetOsVersion( &major
, &minor
);
2058 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2059 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2061 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2062 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2063 // OS X has lighter border edges than classic:
2066 darkShadow
.red
= 0x8E8E;
2067 darkShadow
.green
= 0x8E8E;
2068 darkShadow
.blue
= 0x8E8E;
2069 lightShadow
.red
= 0xBDBD;
2070 lightShadow
.green
= 0xBDBD;
2071 lightShadow
.blue
= 0xBDBD;
2077 GetSize( &w
, &h
) ;
2078 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2080 #if wxMAC_USE_THEME_BORDER
2081 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2084 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2085 InsetRect( &rect , border , border );
2086 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2089 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2091 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2092 RGBForeColor( &face
);
2093 MoveTo( left
+ 0 , top
+ h
- 2 );
2094 LineTo( left
+ 0 , top
+ 0 );
2095 LineTo( left
+ w
- 2 , top
+ 0 );
2097 MoveTo( left
+ 2 , top
+ h
- 3 );
2098 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2099 LineTo( left
+ w
- 3 , top
+ 2 );
2101 RGBForeColor( sunken
? &face
: &darkShadow
);
2102 MoveTo( left
+ 0 , top
+ h
- 1 );
2103 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2104 LineTo( left
+ w
- 1 , top
+ 0 );
2106 RGBForeColor( sunken
? &lightShadow
: &white
);
2107 MoveTo( left
+ 1 , top
+ h
- 3 );
2108 LineTo( left
+ 1, top
+ 1 );
2109 LineTo( left
+ w
- 3 , top
+ 1 );
2111 RGBForeColor( sunken
? &white
: &lightShadow
);
2112 MoveTo( left
+ 1 , top
+ h
- 2 );
2113 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2114 LineTo( left
+ w
- 2 , top
+ 1 );
2116 RGBForeColor( sunken
? &darkShadow
: &face
);
2117 MoveTo( left
+ 2 , top
+ h
- 4 );
2118 LineTo( left
+ 2 , top
+ 2 );
2119 LineTo( left
+ w
- 4 , top
+ 2 );
2122 else if (HasFlag(wxSIMPLE_BORDER
))
2124 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2125 RGBForeColor( &darkShadow
) ;
2126 FrameRect( &rect
) ;
2130 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2132 if ( child
== m_hScrollBar
)
2133 m_hScrollBar
= NULL
;
2134 if ( child
== m_vScrollBar
)
2135 m_vScrollBar
= NULL
;
2137 wxWindowBase::RemoveChild( child
) ;
2140 // New function that will replace some of the above.
2141 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2142 int range
, bool refresh
)
2144 if ( orient
== wxHORIZONTAL
)
2148 if ( range
== 0 || thumbVisible
>= range
)
2150 if ( m_hScrollBar
->IsShown() )
2151 m_hScrollBar
->Show(false) ;
2155 if ( !m_hScrollBar
->IsShown() )
2156 m_hScrollBar
->Show(true) ;
2157 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2165 if ( range
== 0 || thumbVisible
>= range
)
2167 if ( m_vScrollBar
->IsShown() )
2168 m_vScrollBar
->Show(false) ;
2172 if ( !m_vScrollBar
->IsShown() )
2173 m_vScrollBar
->Show(true) ;
2174 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2178 MacRepositionScrollBars() ;
2181 // Does a physical scroll
2182 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2184 if( dx
== 0 && dy
==0 )
2189 wxClientDC
dc(this) ;
2190 wxMacPortSetter
helper(&dc
) ;
2192 int width
, height
;
2193 GetClientSize( &width
, &height
) ;
2200 // TODO take out the boundaries
2201 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2203 RgnHandle updateRgn
= NewRgn() ;
2206 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2207 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2208 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2210 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2212 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2213 // but it seems the update only refreshes the background of the control, rather than calling
2214 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2215 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2218 // we also have to scroll the update rgn in this rectangle
2219 // in order not to loose updates
2221 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2222 RgnHandle formerUpdateRgn
= NewRgn() ;
2223 RgnHandle scrollRgn
= NewRgn() ;
2224 RectRgn( scrollRgn
, &scrollrect
) ;
2225 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2227 LocalToGlobal( &pt
) ;
2228 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2229 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2230 if ( !EmptyRgn( formerUpdateRgn
) )
2232 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2233 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2234 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2236 InvalWindowRgn(rootWindow
, updateRgn
) ;
2237 DisposeRgn( updateRgn
) ;
2238 DisposeRgn( formerUpdateRgn
) ;
2239 DisposeRgn( scrollRgn
) ;
2243 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2245 wxWindowMac
*child
= node
->GetData();
2246 if (child
== m_vScrollBar
) continue;
2247 if (child
== m_hScrollBar
) continue;
2248 if (child
->IsTopLevel()) continue;
2251 child
->GetPosition( &x
, &y
);
2253 child
->GetSize( &w
, &h
);
2257 if (rect
->Intersects(rc
))
2258 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2262 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2266 // TODO remove, was moved higher up Update() ;
2270 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2272 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2274 wxScrollWinEvent wevent
;
2275 wevent
.SetPosition(event
.GetPosition());
2276 wevent
.SetOrientation(event
.GetOrientation());
2277 wevent
.m_eventObject
= this;
2279 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2280 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2281 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2282 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2283 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2284 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2285 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2286 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2287 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2288 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2289 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2290 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2291 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2292 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2293 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2294 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2296 GetEventHandler()->ProcessEvent(wevent
);
2300 // Get the window with the focus
2301 wxWindowMac
*wxWindowBase::FindFocus()
2303 ControlRef control
;
2304 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2305 return wxFindControlFromMacControl( control
) ;
2308 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2310 // panel wants to track the window which was the last to have focus in it,
2311 // so we want to set ourselves as the window which last had focus
2313 // notice that it's also important to do it upwards the tree becaus
2314 // otherwise when the top level panel gets focus, it won't set it back to
2315 // us, but to some other sibling
2317 // CS:don't know if this is still needed:
2318 //wxChildFocusEvent eventFocus(this);
2319 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2324 void wxWindowMac::OnInternalIdle()
2326 // This calls the UI-update mechanism (querying windows for
2327 // menu/toolbar/control state information)
2328 if (wxUpdateUIEvent::CanUpdate(this))
2329 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2332 // Raise the window to the top of the Z order
2333 void wxWindowMac::Raise()
2335 #if TARGET_API_MAC_OSX
2336 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2340 // Lower the window to the bottom of the Z order
2341 void wxWindowMac::Lower()
2343 #if TARGET_API_MAC_OSX
2344 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2349 // static wxWindow *gs_lastWhich = NULL;
2351 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2353 // first trigger a set cursor event
2355 wxPoint clientorigin
= GetClientAreaOrigin() ;
2356 wxSize clientsize
= GetClientSize() ;
2358 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2360 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2362 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2363 if ( processedEvtSetCursor
&& event
.HasCursor() )
2365 cursor
= event
.GetCursor() ;
2370 // the test for processedEvtSetCursor is here to prevent using m_cursor
2371 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2372 // it - this is a way to say that our cursor shouldn't be used for this
2374 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2384 cursor
= *wxSTANDARD_CURSOR
;
2388 cursor
.MacInstall() ;
2390 return cursor
.Ok() ;
2393 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2397 return m_tooltip
->GetTip() ;
2399 return wxEmptyString
;
2402 void wxWindowMac::Update()
2404 #if TARGET_API_MAC_OSX
2405 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2407 ::Draw1Control( (ControlRef
) m_macControl
) ;
2411 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2413 wxTopLevelWindowMac
* win
= NULL
;
2414 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2417 win
= wxFindWinFromMacWindow( window
) ;
2421 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2425 RgnHandle visRgn
= NewRgn() ;
2426 RgnHandle tempRgn
= NewRgn() ;
2427 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2429 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2430 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2432 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2433 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2442 if ( includeOuterStructures
)
2443 InsetRect( &r
, -3 , -3 ) ;
2444 RectRgn( visRgn
, &r
) ;
2445 if ( !IsTopLevel() )
2447 wxWindow
* child
= this ;
2448 wxWindow
* parent
= child
->GetParent() ;
2453 // we have to find a better clipping algorithm here, in order not to clip things
2454 // positioned like status and toolbar
2455 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2457 size
= parent
->GetSize() ;
2462 size
= parent
->GetClientSize() ;
2463 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2467 parent
->MacWindowToRootWindow( &x
, &y
) ;
2468 MacRootWindowToWindow( &x
, &y
) ;
2470 SetRectRgn( tempRgn
,
2471 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2472 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2473 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2475 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2476 if ( parent
->IsTopLevel() )
2479 parent
= child
->GetParent() ;
2484 wxRegion vis
= visRgn
;
2485 DisposeRgn( visRgn
) ;
2486 DisposeRgn( tempRgn
) ;
2491 This function must not change the updatergn !
2493 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2495 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2496 bool handled
= false ;
2498 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2500 RgnHandle newupdate
= NewRgn() ;
2501 wxSize point
= GetClientSize() ;
2502 wxPoint origin
= GetClientAreaOrigin() ;
2503 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2504 SectRgn( newupdate
, updatergn
, newupdate
) ;
2505 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2506 m_updateRegion
= newupdate
;
2507 DisposeRgn( newupdate
) ;
2510 if ( !EmptyRgn(updatergn
) )
2512 wxWindowDC
dc(this);
2513 if (!EmptyRgn(updatergn
))
2514 dc
.SetClippingRegion(wxRegion(updatergn
));
2516 wxEraseEvent
eevent( GetId(), &dc
);
2517 eevent
.SetEventObject( this );
2518 GetEventHandler()->ProcessEvent( eevent
);
2520 if ( !m_updateRegion
.Empty() )
2522 // paint the window itself
2524 event
.m_timeStamp
= time
;
2525 event
.SetEventObject(this);
2526 handled
= GetEventHandler()->ProcessEvent(event
);
2528 // paint custom borders
2529 wxNcPaintEvent
eventNc( GetId() );
2530 eventNc
.SetEventObject( this );
2531 GetEventHandler()->ProcessEvent( eventNc
);
2537 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2539 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2540 // updatergn is always already clipped to our boundaries
2541 // if we are in compositing mode then it is in relative to the upper left of the control
2542 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2543 // of the toplevel window
2544 // it is in window coordinates, not in client coordinates
2546 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2547 RgnHandle ownUpdateRgn
= NewRgn() ;
2548 CopyRgn( updatergn
, ownUpdateRgn
) ;
2550 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2553 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2554 RgnHandle controlRgn
= NewRgn();
2555 RectRgn( controlRgn
, &bounds
);
2556 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2557 // the window update region
2558 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2559 DisposeRgn( controlRgn
);
2561 //KO: convert ownUpdateRgn to local coordinates
2562 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2565 MacDoRedraw( ownUpdateRgn
, time
) ;
2566 DisposeRgn( ownUpdateRgn
) ;
2570 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2572 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2576 if ( iter
->IsTopLevel() )
2577 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2579 iter
= iter
->GetParent() ;
2581 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2585 void wxWindowMac::MacCreateScrollBars( long style
)
2587 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2589 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2590 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2592 GetClientSize( &width
, &height
) ;
2594 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2595 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2596 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2597 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2599 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2600 vSize
, wxVERTICAL
);
2602 if ( style
& wxVSCROLL
)
2608 m_vScrollBar
->Show(false) ;
2610 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2611 hSize
, wxHORIZONTAL
);
2612 if ( style
& wxHSCROLL
)
2617 m_hScrollBar
->Show(false) ;
2620 // because the create does not take into account the client area origin
2621 MacRepositionScrollBars() ; // we might have a real position shift
2624 void wxWindowMac::MacRepositionScrollBars()
2626 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2627 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2629 // get real client area
2633 GetSize( &width
, &height
) ;
2635 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2636 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2638 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2639 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2640 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2641 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2647 GetSize( &w
, &h
) ;
2649 MacClientToRootWindow( &x
, &y
) ;
2650 MacClientToRootWindow( &w
, &h
) ;
2652 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2654 int totW
= 10000 , totH
= 10000;
2657 if ( iter
->IsTopLevel() )
2659 iter
->GetSize( &totW
, &totH
) ;
2663 iter
= iter
->GetParent() ;
2691 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2695 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2699 bool wxWindowMac::AcceptsFocus() const
2701 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2704 void wxWindowMac::MacSuperChangedPosition()
2706 // only window-absolute structures have to be moved i.e. controls
2708 wxWindowListNode
*node
= GetChildren().GetFirst();
2711 wxWindowMac
*child
= node
->GetData();
2712 child
->MacSuperChangedPosition() ;
2713 node
= node
->GetNext();
2717 void wxWindowMac::MacTopLevelWindowChangedPosition()
2719 // only screen-absolute structures have to be moved i.e. glcanvas
2721 wxWindowListNode
*node
= GetChildren().GetFirst();
2724 wxWindowMac
*child
= node
->GetData();
2725 child
->MacTopLevelWindowChangedPosition() ;
2726 node
= node
->GetNext();
2730 long wxWindowMac::MacGetLeftBorderSize( ) const
2735 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2738 #if wxMAC_USE_THEME_BORDER
2739 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2743 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2746 #if wxMAC_USE_THEME_BORDER
2747 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2751 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2758 long wxWindowMac::MacGetRightBorderSize( ) const
2760 // they are all symmetric in mac themes
2761 return MacGetLeftBorderSize() ;
2764 long wxWindowMac::MacGetTopBorderSize( ) const
2766 // they are all symmetric in mac themes
2767 return MacGetLeftBorderSize() ;
2770 long wxWindowMac::MacGetBottomBorderSize( ) const
2772 // they are all symmetric in mac themes
2773 return MacGetLeftBorderSize() ;
2776 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2778 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2781 // Find the wxWindowMac at the current mouse position, returning the mouse
2783 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2785 pt
= wxGetMousePosition();
2786 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2790 // Get the current mouse position.
2791 wxPoint
wxGetMousePosition()
2794 wxGetMousePosition(& x
, & y
);
2795 return wxPoint(x
, y
);
2798 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2800 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2802 // copied from wxGTK : CS
2803 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2806 // (a) it's a command event and so is propagated to the parent
2807 // (b) under MSW it can be generated from kbd too
2808 // (c) it uses screen coords (because of (a))
2809 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2811 this->ClientToScreen(event
.GetPosition()));
2812 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2821 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2825 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2829 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2830 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2834 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2836 return eventNotHandledErr
;