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"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
49 #define MAC_SCROLLBAR_SIZE 16
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 // TODO EVT_PAINT(wxWindowMac::OnPaint)
85 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
86 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
87 // EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
88 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
93 #define wxMAC_DEBUG_REDRAW 0
94 #ifndef wxMAC_DEBUG_REDRAW
95 #define wxMAC_DEBUG_REDRAW 0
98 #define wxMAC_USE_THEME_BORDER 0
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
105 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
107 #if TARGET_API_MAC_OSX
109 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
111 kEventControlVisibilityChanged
= 157
117 static const EventTypeSpec eventList
[] =
119 { kEventClassControl
, kEventControlHit
} ,
120 #if TARGET_API_MAC_OSX
121 { kEventClassControl
, kEventControlDraw
} ,
122 { kEventClassControl
, kEventControlVisibilityChanged
} ,
123 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
124 { kEventClassControl
, kEventControlHiliteChanged
} ,
125 { kEventClassControl
, kEventControlSetFocusPart
} ,
127 { kEventClassService
, kEventServiceGetTypes
},
128 { kEventClassService
, kEventServiceCopy
},
129 { kEventClassService
, kEventServicePaste
},
131 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
132 // { kEventClassControl , kEventControlBoundsChanged } ,
136 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
138 OSStatus result
= eventNotHandledErr
;
140 wxMacCarbonEvent
cEvent( event
) ;
142 ControlRef controlRef
;
143 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
145 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
147 switch( GetEventKind( event
) )
149 #if TARGET_API_MAC_OSX
150 case kEventControlDraw
:
152 RgnHandle updateRgn
= NULL
;
154 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
155 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
157 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
159 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
162 // in case we would need a coregraphics compliant background erase first
163 // now usable to track redraws
164 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
165 if ( thisWindow
->MacIsUserPane() )
167 static float color
= 0.5 ;
170 HIViewGetBounds( controlRef
, &bounds
);
171 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
172 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
173 CGContextFillRect( cgContext
, bounds
);
184 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
188 case kEventControlVisibilityChanged
:
189 thisWindow
->MacVisibilityChanged() ;
191 case kEventControlEnabledStateChanged
:
192 thisWindow
->MacEnabledStateChanged() ;
194 case kEventControlHiliteChanged
:
195 thisWindow
->MacHiliteChanged() ;
197 case kEventControlSetFocusPart
:
199 Boolean focusEverything
= false ;
200 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
201 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
204 if ( controlPart
== kControlFocusNoPart
)
207 if ( thisWindow
->GetCaret() )
209 thisWindow
->GetCaret()->OnKillFocus();
211 #endif // wxUSE_CARET
212 wxFocusEvent
event(wxEVT_KILL_FOCUS
, thisWindow
->GetId());
213 event
.SetEventObject(thisWindow
);
214 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
218 // panel wants to track the window which was the last to have focus in it
219 wxChildFocusEvent
eventFocus(thisWindow
);
220 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
223 if ( thisWindow
->GetCaret() )
225 thisWindow
->GetCaret()->OnSetFocus();
227 #endif // wxUSE_CARET
229 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
230 event
.SetEventObject(thisWindow
);
231 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
233 if ( thisWindow
->MacIsUserPane() )
238 case kEventControlHit
:
240 result
= thisWindow
->MacControlHit( handler
, event
) ;
249 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
251 OSStatus result
= eventNotHandledErr
;
253 wxMacCarbonEvent
cEvent( event
) ;
255 ControlRef controlRef
;
256 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
257 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
258 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
260 switch( GetEventKind( event
) )
262 case kEventServiceGetTypes
:
266 textCtrl
->GetSelection( &from
, &to
) ;
268 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
270 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
271 if ( textCtrl
->IsEditable() )
272 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
274 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
275 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
277 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
281 CFArrayAppendValue (copyTypes
, typestring
) ;
283 CFArrayAppendValue (pasteTypes
, typestring
) ;
284 CFRelease( typestring
) ;
290 case kEventServiceCopy
:
294 textCtrl
->GetSelection( &from
, &to
) ;
295 wxString val
= textCtrl
->GetValue() ;
296 val
= val
.Mid( from
, to
- from
) ;
297 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
298 verify_noerr( ClearScrap( &scrapRef
) ) ;
299 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
303 case kEventServicePaste
:
306 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
307 Size textSize
, pastedSize
;
308 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
310 char *content
= new char[textSize
] ;
311 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
312 content
[textSize
-1] = 0 ;
314 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
316 textCtrl
->WriteText( wxString( content
) ) ;
327 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
329 OSStatus result
= eventNotHandledErr
;
331 switch ( GetEventClass( event
) )
333 case kEventClassControl
:
334 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
336 case kEventClassService
:
337 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
344 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
346 // ---------------------------------------------------------------------------
347 // UserPane events for non OSX builds
348 // ---------------------------------------------------------------------------
350 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
352 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
353 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
354 win
->MacControlUserPaneDrawProc(part
) ;
357 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
359 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
360 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
361 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
364 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
366 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
367 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
368 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
371 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
373 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
374 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
375 win
->MacControlUserPaneIdleProc() ;
378 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
380 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
381 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
382 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
385 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
387 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
388 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
389 win
->MacControlUserPaneActivateProc(activating
) ;
392 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
394 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
395 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
396 return win
->MacControlUserPaneFocusProc(action
) ;
399 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
401 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
402 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
403 win
->MacControlUserPaneBackgroundProc(info
) ;
406 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
408 RgnHandle rgn
= NewRgn() ;
410 wxMacWindowStateSaver
sv( this ) ;
411 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
412 MacDoRedraw( rgn
, 0 ) ;
416 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
418 return kControlNoPart
;
421 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
423 return kControlNoPart
;
426 void wxWindowMac::MacControlUserPaneIdleProc()
430 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
432 return kControlNoPart
;
435 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
439 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
441 return kControlNoPart
;
444 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
448 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
449 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
450 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
451 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
452 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
453 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
454 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
455 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
457 // ===========================================================================
459 // ===========================================================================
461 wxList
wxWinMacControlList(wxKEY_INTEGER
);
463 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
465 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
468 return (wxControl
*)node
->GetData();
471 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
473 // adding NULL ControlRef is (first) surely a result of an error and
474 // (secondly) breaks native event processing
475 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
477 if ( !wxWinMacControlList
.Find((long)inControl
) )
478 wxWinMacControlList
.Append((long)inControl
, control
);
481 void wxRemoveMacControlAssociation(wxWindow
*control
)
483 wxWinMacControlList
.DeleteObject(control
);
487 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
489 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
491 // we have to setup the brush in the current port and return noErr
492 // or return an error code so that the control manager walks further up the
493 // hierarchy to find a correct background
495 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
497 OSStatus status
= paramErr
;
500 case kControlMsgApplyTextColor
:
502 case kControlMsgSetUpBackground
:
504 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
508 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
512 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
514 // this clipping is only needed for non HIView
516 RgnHandle clip
= NewRgn() ;
519 wx
->MacWindowToRootWindow( &x
,&y
) ;
520 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
521 OffsetRgn( clip
, x
, y
) ;
528 else if ( wx->MacIsUserPane() )
530 // if we don't have a valid brush for such a control, we have to call the
531 // setup of our parent ourselves
532 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
545 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
546 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
550 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
553 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
558 // ----------------------------------------------------------------------------
559 // constructors and such
560 // ----------------------------------------------------------------------------
562 wxWindowMac::wxWindowMac()
567 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
572 const wxString
& name
)
575 Create(parent
, id
, pos
, size
, style
, name
);
578 void wxWindowMac::Init()
581 #if WXWIN_COMPATIBILITY_2_4
582 m_backgroundTransparent
= FALSE
;
585 // as all windows are created with WS_VISIBLE style...
588 m_hScrollBar
= NULL
;
589 m_vScrollBar
= NULL
;
590 m_macBackgroundBrush
= wxNullBrush
;
592 m_macControl
= NULL
;
594 m_macIsUserPane
= TRUE
;
596 // make sure all proc ptrs are available
598 if ( gControlUserPaneDrawUPP
== NULL
)
600 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
601 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
602 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
603 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
604 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
605 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
606 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
607 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
609 if ( wxMacLiveScrollbarActionUPP
== NULL
)
611 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
614 if ( wxMacSetupControlBackgroundUPP
== NULL
)
616 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
619 // we need a valid font for the encodings
620 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
624 wxWindowMac::~wxWindowMac()
628 m_isBeingDeleted
= TRUE
;
630 #ifndef __WXUNIVERSAL__
631 // VS: make sure there's no wxFrame with last focus set to us:
632 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
634 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
637 if ( frame
->GetLastFocus() == this )
639 frame
->SetLastFocus((wxWindow
*)NULL
);
644 #endif // __WXUNIVERSAL__
646 // wxRemoveMacControlAssociation( this ) ;
647 // If we delete an item, we should initialize the parent panel,
648 // because it could now be invalid.
649 wxWindow
*parent
= GetParent() ;
652 if (parent
->GetDefaultItem() == (wxButton
*) this)
653 parent
->SetDefaultItem(NULL
);
655 if ( (ControlRef
) m_macControl
)
657 // in case the callback might be called during destruction
658 wxRemoveMacControlAssociation( this) ;
659 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
660 ::DisposeControl( (ControlRef
) m_macControl
) ;
661 m_macControl
= NULL
;
664 if ( g_MacLastWindow
== this )
666 g_MacLastWindow
= NULL
;
669 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
672 if ( frame
->GetLastFocus() == this )
673 frame
->SetLastFocus( NULL
) ;
678 // delete our drop target if we've got one
679 #if wxUSE_DRAG_AND_DROP
680 if ( m_dropTarget
!= NULL
)
685 #endif // wxUSE_DRAG_AND_DROP
690 void wxWindowMac::MacInstallEventHandler()
692 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
693 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
694 GetEventTypeCount(eventList
), eventList
, this,
695 (EventHandlerRef
*)&m_macControlEventHandler
);
700 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
704 const wxString
& name
)
706 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
708 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
711 parent
->AddChild(this);
713 m_windowVariant
= parent
->GetWindowVariant() ;
715 if ( m_macIsUserPane
)
717 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
720 | kControlSupportsEmbedding
721 // | kControlSupportsLiveFeedback
722 // | kControlHasSpecialBackground
723 // | kControlSupportsCalcBestRect
724 // | kControlHandlesTracking
725 | kControlSupportsFocus
726 // | kControlWantsActivate
727 // | kControlWantsIdle
730 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
732 MacPostControlCreate(pos
,size
) ;
733 #if !TARGET_API_MAC_OSX
734 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
735 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
736 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
737 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
738 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
739 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
740 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
741 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
742 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
743 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
744 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
745 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
746 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
747 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
748 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
749 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
752 #ifndef __WXUNIVERSAL__
753 // Don't give scrollbars to wxControls unless they ask for them
754 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
755 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
757 MacCreateScrollBars( style
) ;
761 wxWindowCreateEvent
event(this);
762 GetEventHandler()->AddPendingEvent(event
);
767 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
769 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
771 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
773 MacInstallEventHandler();
775 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
776 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
777 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
779 // adjust font, controlsize etc
780 DoSetWindowVariant( m_windowVariant
) ;
782 #if !TARGET_API_MAC_OSX
783 // eventually we can fix some clipping issues be reactivating this hook
784 //if ( m_macIsUserPane )
785 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
788 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
790 if (!m_macIsUserPane
)
792 SetInitialBestSize(size
);
795 SetCursor( *wxSTANDARD_CURSOR
) ;
798 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
800 // Don't assert, in case we set the window variant before
801 // the window is created
802 // wxASSERT( m_macControl != NULL ) ;
804 m_windowVariant
= variant
;
810 ThemeFontID themeFont
= kThemeSystemFont
;
812 // we will get that from the settings later
813 // and make this NORMAL later, but first
814 // we have a few calculations that we must fix
818 case wxWINDOW_VARIANT_NORMAL
:
819 size
= kControlSizeNormal
;
820 themeFont
= kThemeSystemFont
;
822 case wxWINDOW_VARIANT_SMALL
:
823 size
= kControlSizeSmall
;
824 themeFont
= kThemeSmallSystemFont
;
826 case wxWINDOW_VARIANT_MINI
:
827 if (UMAGetSystemVersion() >= 0x1030 )
829 // not always defined in the headers
835 size
= kControlSizeSmall
;
836 themeFont
= kThemeSmallSystemFont
;
839 case wxWINDOW_VARIANT_LARGE
:
840 size
= kControlSizeLarge
;
841 themeFont
= kThemeSystemFont
;
844 wxFAIL_MSG(_T("unexpected window variant"));
847 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
850 font
.MacCreateThemeFont( themeFont
) ;
854 void wxWindowMac::MacUpdateControlFont()
856 ControlFontStyleRec fontStyle
;
857 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
859 switch( m_font
.MacGetThemeFontID() )
861 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
862 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
863 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
864 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
866 fontStyle
.flags
= kControlUseFontMask
;
870 fontStyle
.font
= m_font
.MacGetFontNum() ;
871 fontStyle
.style
= m_font
.MacGetFontStyle() ;
872 fontStyle
.size
= m_font
.MacGetFontSize() ;
873 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
876 fontStyle
.just
= teJustLeft
;
877 fontStyle
.flags
|= kControlUseJustMask
;
878 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
879 fontStyle
.just
= teJustCenter
;
880 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
881 fontStyle
.just
= teJustRight
;
884 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
885 fontStyle
.flags
|= kControlUseForeColorMask
;
887 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
891 bool wxWindowMac::SetFont(const wxFont
& font
)
893 bool retval
= !wxWindowBase::SetFont( font
) ;
895 MacUpdateControlFont() ;
900 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
902 if ( !wxWindowBase::SetForegroundColour(col
) )
905 MacUpdateControlFont() ;
910 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
912 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
916 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
918 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
920 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
922 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
926 brush
.SetColour( col
) ;
928 MacSetBackgroundBrush( brush
) ;
930 MacUpdateControlFont() ;
936 bool wxWindowMac::MacCanFocus() const
938 // there is currently no way to determine whether the window is running in full keyboard
939 // access mode, therefore we cannot rely on these features, yet the only other way would be
940 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
941 // in event handlers...
942 UInt32 features
= 0 ;
943 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
944 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
948 void wxWindowMac::SetFocus()
950 if ( AcceptsFocus() )
952 #if !TARGET_API_MAC_OSX
953 wxWindow
* former
= FindFocus() ;
955 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
956 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
957 // leave in case of an error
958 if ( err
== errCouldntSetFocus
)
961 #if !TARGET_API_MAC_OSX
962 // emulate carbon events when running under carbonlib where they are not natively available
965 EventRef evRef
= NULL
;
966 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
969 wxMacCarbonEvent
cEvent( evRef
) ;
970 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
971 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
973 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
974 ReleaseEvent(evRef
) ;
976 // send new focus event
978 EventRef evRef
= NULL
;
979 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
982 wxMacCarbonEvent
cEvent( evRef
) ;
983 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
984 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
986 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
987 ReleaseEvent(evRef
) ;
994 void wxWindowMac::DoCaptureMouse()
996 wxTheApp
->s_captureWindow
= this ;
999 wxWindow
* wxWindowBase::GetCapture()
1001 return wxTheApp
->s_captureWindow
;
1004 void wxWindowMac::DoReleaseMouse()
1006 wxTheApp
->s_captureWindow
= NULL
;
1009 #if wxUSE_DRAG_AND_DROP
1011 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1013 if ( m_dropTarget
!= 0 ) {
1014 delete m_dropTarget
;
1017 m_dropTarget
= pDropTarget
;
1018 if ( m_dropTarget
!= 0 )
1026 // Old style file-manager drag&drop
1027 void wxWindowMac::DragAcceptFiles(bool accept
)
1032 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1033 int& w
, int& h
) const
1036 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1041 w
= bounds
.right
- bounds
.left
;
1042 h
= bounds
.bottom
- bounds
.top
;
1044 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1047 Point tlworigin
= { 0 , 0 } ;
1048 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1054 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1057 int& w
, int& h
, bool adjustOrigin
) const
1061 // todo the default calls may be used as soon as PostCreateControl Is moved here
1062 w
= size
.x
; // WidthDefault( size.x );
1063 h
= size
.y
; // HeightDefault( size.y ) ;
1064 #if !TARGET_API_MAC_OSX
1065 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1068 AdjustForParentClientOrigin( x
, y
) ;
1073 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1075 #if TARGET_API_MAC_OSX
1076 int x1
, y1
, w1
,h1
;
1077 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1083 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1084 if(x
) *x
= bounds
.right
- bounds
.left
;
1085 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1089 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1091 #if TARGET_API_MAC_OSX
1092 int x1
, y1
, w1
,h1
;
1093 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1094 if ( !IsTopLevel() )
1096 wxWindow
*parent
= GetParent();
1099 wxPoint
pt(parent
->GetClientAreaOrigin());
1108 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1109 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1111 int xx
= bounds
.left
;
1112 int yy
= bounds
.top
;
1114 if ( !GetParent()->IsTopLevel() )
1116 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1122 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1131 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1133 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1135 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1138 Point localwhere
= {0,0} ;
1140 if(x
) localwhere
.h
= * x
;
1141 if(y
) localwhere
.v
= * y
;
1143 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1144 if(x
) *x
= localwhere
.h
;
1145 if(y
) *y
= localwhere
.v
;
1148 MacRootWindowToWindow( x
, y
) ;
1150 wxPoint origin
= GetClientAreaOrigin() ;
1151 if(x
) *x
-= origin
.x
;
1152 if(y
) *y
-= origin
.y
;
1155 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1157 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1158 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1160 wxPoint origin
= GetClientAreaOrigin() ;
1161 if(x
) *x
+= origin
.x
;
1162 if(y
) *y
+= origin
.y
;
1164 MacWindowToRootWindow( x
, y
) ;
1167 Point localwhere
= { 0,0 };
1168 if(x
) localwhere
.h
= * x
;
1169 if(y
) localwhere
.v
= * y
;
1170 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1171 if(x
) *x
= localwhere
.h
;
1172 if(y
) *y
= localwhere
.v
;
1176 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1178 wxPoint origin
= GetClientAreaOrigin() ;
1179 if(x
) *x
+= origin
.x
;
1180 if(y
) *y
+= origin
.y
;
1182 MacWindowToRootWindow( x
, y
) ;
1185 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1187 MacRootWindowToWindow( x
, y
) ;
1189 wxPoint origin
= GetClientAreaOrigin() ;
1190 if(x
) *x
-= origin
.x
;
1191 if(y
) *y
-= origin
.y
;
1194 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1196 #if TARGET_API_MAC_OSX
1198 if ( x
) pt
.x
= *x
;
1199 if ( y
) pt
.y
= *y
;
1201 if ( !IsTopLevel() )
1202 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1204 if ( x
) *x
= (int) pt
.x
;
1205 if ( y
) *y
= (int) pt
.y
;
1207 if ( !IsTopLevel() )
1210 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1211 if(x
) *x
+= bounds
.left
;
1212 if(y
) *y
+= bounds
.top
;
1217 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1222 MacWindowToRootWindow( &x1
, &y1
) ;
1227 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1229 #if TARGET_API_MAC_OSX
1231 if ( x
) pt
.x
= *x
;
1232 if ( y
) pt
.y
= *y
;
1234 if ( !IsTopLevel() )
1235 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1237 if ( x
) *x
= (int) pt
.x
;
1238 if ( y
) *y
= (int) pt
.y
;
1240 if ( !IsTopLevel() )
1243 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1244 if(x
) *x
-= bounds
.left
;
1245 if(y
) *y
-= bounds
.top
;
1250 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1255 MacRootWindowToWindow( &x1
, &y1
) ;
1260 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1262 RgnHandle rgn
= NewRgn() ;
1264 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1266 GetRegionBounds( rgn
, &content
) ;
1271 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1274 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1275 #if !TARGET_API_MAC_OSX
1276 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1278 left
= content
.left
- structure
.left
;
1279 top
= content
.top
- structure
.top
;
1280 right
= structure
.right
- content
.right
;
1281 bottom
= structure
.bottom
- content
.bottom
;
1284 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1286 wxSize sizeTotal
= size
;
1288 RgnHandle rgn
= NewRgn() ;
1292 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1294 GetRegionBounds( rgn
, &content
) ;
1299 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1302 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1303 #if !TARGET_API_MAC_OSX
1304 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1307 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1308 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1310 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1311 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1317 // Get size *available for subwindows* i.e. excluding menu bar etc.
1318 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1322 RgnHandle rgn
= NewRgn() ;
1324 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1326 GetRegionBounds( rgn
, &content
) ;
1331 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1333 #if !TARGET_API_MAC_OSX
1335 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1336 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1338 ww
= content
.right
- content
.left
;
1339 hh
= content
.bottom
- content
.top
;
1341 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1342 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1344 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1350 GetSize( &w
, &h
) ;
1352 MacClientToRootWindow( &x1
, &y1
) ;
1353 MacClientToRootWindow( &w
, &h
) ;
1355 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1357 int totW
= 10000 , totH
= 10000;
1360 if ( iter
->IsTopLevel() )
1362 iter
->GetSize( &totW
, &totH
) ;
1366 iter
= iter
->GetParent() ;
1369 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1371 hh
-= MAC_SCROLLBAR_SIZE
;
1377 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1379 ww
-= MAC_SCROLLBAR_SIZE
;
1391 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1393 if (m_cursor
== cursor
)
1396 if (wxNullCursor
== cursor
)
1398 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1403 if ( ! wxWindowBase::SetCursor( cursor
) )
1407 wxASSERT_MSG( m_cursor
.Ok(),
1408 wxT("cursor must be valid after call to the base version"));
1412 TODO why do we have to use current coordinates ?
1415 wxWindowMac *mouseWin ;
1418 // Change the cursor NOW if we're within the correct window
1421 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1423 if ( mouseWin == this && !wxIsBusy() )
1425 m_cursor.MacInstall() ;
1431 m_cursor
.MacInstall() ;
1438 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1440 menu
->SetInvokingWindow(this);
1442 ClientToScreen( &x
, &y
) ;
1444 menu
->MacBeforeDisplay( true ) ;
1445 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1446 if ( HiWord(menuResult
) != 0 )
1449 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1450 wxMenuItem
* item
= NULL
;
1452 item
= menu
->FindItem(id
, &realmenu
) ;
1453 if (item
->IsCheckable())
1455 item
->Check( !item
->IsChecked() ) ;
1457 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1459 menu
->MacAfterDisplay( true ) ;
1461 menu
->SetInvokingWindow(NULL
);
1467 // ----------------------------------------------------------------------------
1469 // ----------------------------------------------------------------------------
1473 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1475 wxWindowBase::DoSetToolTip(tooltip
);
1478 m_tooltip
->SetWindow(this);
1481 #endif // wxUSE_TOOLTIPS
1483 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1485 int former_x
, former_y
, former_w
, former_h
;
1486 #if !TARGET_API_MAC_OSX
1487 DoGetPosition( &former_x
, &former_y
) ;
1488 DoGetSize( &former_w
, &former_h
) ;
1490 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1493 int actualWidth
= width
;
1494 int actualHeight
= height
;
1498 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1499 actualWidth
= m_minWidth
;
1500 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1501 actualHeight
= m_minHeight
;
1502 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1503 actualWidth
= m_maxWidth
;
1504 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1505 actualHeight
= m_maxHeight
;
1507 bool doMove
= false ;
1508 bool doResize
= false ;
1510 if ( actualX
!= former_x
|| actualY
!= former_y
)
1514 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1519 if ( doMove
|| doResize
)
1521 // we don't adjust twice for the origin
1522 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1523 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1524 #if TARGET_API_MAC_OSX
1525 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1527 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1528 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1529 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1531 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1534 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1535 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1537 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1539 MacRepositionScrollBars() ;
1542 wxPoint
point(actualX
,actualY
);
1543 wxMoveEvent
event(point
, m_windowId
);
1544 event
.SetEventObject(this);
1545 GetEventHandler()->ProcessEvent(event
) ;
1549 MacRepositionScrollBars() ;
1550 wxSize
size(actualWidth
, actualHeight
);
1551 wxSizeEvent
event(size
, m_windowId
);
1552 event
.SetEventObject(this);
1553 GetEventHandler()->ProcessEvent(event
);
1559 wxSize
wxWindowMac::DoGetBestSize() const
1561 if ( m_macIsUserPane
|| IsTopLevel() )
1562 return wxWindowBase::DoGetBestSize() ;
1564 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1565 short baselineoffset
;
1566 int bestWidth
, bestHeight
;
1567 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1569 if ( EmptyRect( &bestsize
) )
1572 bestsize
.left
= bestsize
.top
= 0 ;
1573 bestsize
.right
= 16 ;
1574 bestsize
.bottom
= 16 ;
1575 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1577 bestsize
.bottom
= 16 ;
1579 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1581 bestsize
.bottom
= 24 ;
1585 // return wxWindowBase::DoGetBestSize() ;
1589 bestWidth
= bestsize
.right
- bestsize
.left
;
1590 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1591 if ( bestHeight
< 10 )
1594 return wxSize(bestWidth
, bestHeight
);
1595 // return wxWindowBase::DoGetBestSize() ;
1599 // set the size of the window: if the dimensions are positive, just use them,
1600 // but if any of them is equal to -1, it means that we must find the value for
1601 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1602 // which case -1 is a valid value for x and y)
1604 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1605 // the width/height to best suit our contents, otherwise we reuse the current
1607 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1609 // get the current size and position...
1610 int currentX
, currentY
;
1611 GetPosition(¤tX
, ¤tY
);
1613 int currentW
,currentH
;
1614 GetSize(¤tW
, ¤tH
);
1616 // ... and don't do anything (avoiding flicker) if it's already ok
1617 if ( x
== currentX
&& y
== currentY
&&
1618 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1621 MacRepositionScrollBars() ; // we might have a real position shift
1625 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1627 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1630 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1632 wxSize
size(-1, -1);
1635 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1637 size
= DoGetBestSize();
1642 // just take the current one
1649 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1653 size
= DoGetBestSize();
1655 //else: already called DoGetBestSize() above
1661 // just take the current one
1666 DoMoveWindow(x
, y
, width
, height
);
1670 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1672 RgnHandle rgn
= NewRgn() ;
1674 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1675 GetRegionBounds( rgn
, &content
) ;
1677 #if !TARGET_API_MAC_OSX
1678 // if the content rgn is empty / not supported
1679 // don't attempt to correct the coordinates to wxWindow relative ones
1680 if (!::EmptyRect( &content
) )
1683 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1684 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1688 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1691 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1693 if ( clientheight
!= -1 || clientheight
!= -1 )
1695 int currentclientwidth
, currentclientheight
;
1696 int currentwidth
, currentheight
;
1698 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1699 GetSize( ¤twidth
, ¤theight
) ;
1701 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1702 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1706 void wxWindowMac::SetTitle(const wxString
& title
)
1708 m_label
= wxStripMenuCodes(title
) ;
1712 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1717 wxString
wxWindowMac::GetTitle() const
1722 bool wxWindowMac::Show(bool show
)
1724 if ( !wxWindowBase::Show(show
) )
1727 // TODO use visibilityChanged Carbon Event for OSX
1728 bool former
= MacIsReallyShown() ;
1730 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1731 if ( former
!= MacIsReallyShown() )
1732 MacPropagateVisibilityChanged() ;
1736 bool wxWindowMac::Enable(bool enable
)
1738 wxASSERT( m_macControl
!= NULL
) ;
1739 if ( !wxWindowBase::Enable(enable
) )
1742 bool former
= MacIsReallyEnabled() ;
1743 #if TARGET_API_MAC_OSX
1745 EnableControl( (ControlRef
) m_macControl
) ;
1747 DisableControl( (ControlRef
) m_macControl
) ;
1750 ActivateControl( (ControlRef
) m_macControl
) ;
1752 DeactivateControl( (ControlRef
) m_macControl
) ;
1755 if ( former
!= MacIsReallyEnabled() )
1756 MacPropagateEnabledStateChanged() ;
1761 // status change propagations (will be not necessary for OSX later )
1764 void wxWindowMac::MacPropagateVisibilityChanged()
1766 #if !TARGET_API_MAC_OSX
1767 MacVisibilityChanged() ;
1769 wxWindowListNode
*node
= GetChildren().GetFirst();
1772 wxWindowMac
*child
= node
->GetData();
1773 if ( child
->IsShown() )
1774 child
->MacPropagateVisibilityChanged( ) ;
1775 node
= node
->GetNext();
1780 void wxWindowMac::MacPropagateEnabledStateChanged( )
1782 #if !TARGET_API_MAC_OSX
1783 MacEnabledStateChanged() ;
1785 wxWindowListNode
*node
= GetChildren().GetFirst();
1788 wxWindowMac
*child
= node
->GetData();
1789 if ( child
->IsEnabled() )
1790 child
->MacPropagateEnabledStateChanged() ;
1791 node
= node
->GetNext();
1796 void wxWindowMac::MacPropagateHiliteChanged( )
1798 #if !TARGET_API_MAC_OSX
1799 MacHiliteChanged() ;
1801 wxWindowListNode
*node
= GetChildren().GetFirst();
1804 wxWindowMac
*child
= node
->GetData();
1805 // if ( child->IsEnabled() )
1806 child
->MacPropagateHiliteChanged() ;
1807 node
= node
->GetNext();
1813 // status change notifications
1816 void wxWindowMac::MacVisibilityChanged()
1820 void wxWindowMac::MacHiliteChanged()
1824 void wxWindowMac::MacEnabledStateChanged()
1829 // status queries on the inherited window's state
1832 bool wxWindowMac::MacIsReallyShown()
1834 // only under OSX the visibility of the TLW is taken into account
1835 #if TARGET_API_MAC_OSX
1836 return IsControlVisible( (ControlRef
) m_macControl
) ;
1838 wxWindow
* win
= this ;
1839 while( win
->IsShown() )
1841 if ( win
->IsTopLevel() )
1844 win
= win
->GetParent() ;
1853 bool wxWindowMac::MacIsReallyEnabled()
1855 #if TARGET_API_MAC_OSX
1856 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1858 return IsControlActive( (ControlRef
) m_macControl
) ;
1862 bool wxWindowMac::MacIsReallyHilited()
1864 return IsControlActive( (ControlRef
) m_macControl
) ;
1867 void wxWindowMac::MacFlashInvalidAreas()
1869 #if TARGET_API_MAC_OSX
1870 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1878 int wxWindowMac::GetCharHeight() const
1880 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1881 return dc
.GetCharHeight() ;
1884 int wxWindowMac::GetCharWidth() const
1886 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1887 return dc
.GetCharWidth() ;
1890 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1891 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1893 const wxFont
*fontToUse
= theFont
;
1895 fontToUse
= &m_font
;
1897 wxClientDC
dc( (wxWindowMac
*) this ) ;
1899 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1900 if ( externalLeading
)
1901 *externalLeading
= le
;
1911 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1912 * we always intersect with the entire window, not only with the client area
1915 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1917 #if TARGET_API_MAC_OSX
1919 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1922 RgnHandle update
= NewRgn() ;
1923 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1924 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1925 wxPoint origin
= GetClientAreaOrigin() ;
1926 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1927 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1931 RgnHandle updateRgn = NewRgn() ;
1934 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1938 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1939 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1941 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1942 DisposeRgn(updateRgn) ;
1944 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1946 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1947 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1950 if ( MacGetTopLevelWindow() == NULL )
1953 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1956 wxPoint client = GetClientAreaOrigin();
1959 int x2 = m_width - client.x;
1960 int y2 = m_height - client.y;
1962 if (IsKindOf( CLASSINFO(wxButton)))
1964 // buttons have an "aura"
1971 Rect clientrect = { y1, x1, y2, x2 };
1975 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1976 SectRect( &clientrect , &r , &clientrect ) ;
1979 if ( !EmptyRect( &clientrect ) )
1981 int top = 0 , left = 0 ;
1983 MacClientToRootWindow( &left , &top ) ;
1984 OffsetRect( &clientrect , left , top ) ;
1986 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1992 void wxWindowMac::Freeze()
1994 #if TARGET_API_MAC_OSX
1995 if ( !m_frozenness
++ )
1997 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
2002 #if TARGET_API_MAC_OSX
2003 static void InvalidateControlAndChildren( HIViewRef control
)
2005 HIViewSetNeedsDisplay( control
, true ) ;
2006 UInt16 childrenCount
= 0 ;
2007 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2008 if ( err
== errControlIsNotEmbedder
)
2010 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2012 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2015 err
= GetIndexedSubControl( control
, i
, & child
) ;
2016 if ( err
== errControlIsNotEmbedder
)
2018 InvalidateControlAndChildren( child
) ;
2023 void wxWindowMac::Thaw()
2025 #if TARGET_API_MAC_OSX
2026 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2028 if ( !--m_frozenness
)
2030 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2031 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2032 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2037 void wxWindowMac::MacRedrawControl()
2040 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2042 #if TARGET_API_MAC_CARBON
2045 wxClientDC dc(this) ;
2046 wxMacPortSetter helper(&dc) ;
2047 wxMacWindowClipper clipper(this) ;
2048 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2049 UMADrawControl( (ControlRef) m_macControl ) ;
2056 void wxWindowMac::OnPaint(wxPaintEvent& event)
2058 // why don't we skip that here ?
2062 wxWindowMac
*wxGetActiveWindow()
2064 // actually this is a windows-only concept
2068 // Coordinates relative to the window
2069 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2071 // We really don't move the mouse programmatically under Mac.
2074 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2076 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2081 event
.GetDC()->Clear() ;
2084 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2086 wxWindowDC
dc(this) ;
2087 wxMacPortSetter
helper(&dc
) ;
2089 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2092 int wxWindowMac::GetScrollPos(int orient
) const
2094 if ( orient
== wxHORIZONTAL
)
2097 return m_hScrollBar
->GetThumbPosition() ;
2102 return m_vScrollBar
->GetThumbPosition() ;
2107 // This now returns the whole range, not just the number
2108 // of positions that we can scroll.
2109 int wxWindowMac::GetScrollRange(int orient
) const
2111 if ( orient
== wxHORIZONTAL
)
2114 return m_hScrollBar
->GetRange() ;
2119 return m_vScrollBar
->GetRange() ;
2124 int wxWindowMac::GetScrollThumb(int orient
) const
2126 if ( orient
== wxHORIZONTAL
)
2129 return m_hScrollBar
->GetThumbSize() ;
2134 return m_vScrollBar
->GetThumbSize() ;
2139 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2141 if ( orient
== wxHORIZONTAL
)
2144 m_hScrollBar
->SetThumbPosition( pos
) ;
2149 m_vScrollBar
->SetThumbPosition( pos
) ;
2153 void wxWindowMac::MacPaintBorders( int left
, int top
)
2159 wxGetOsVersion( &major
, &minor
);
2161 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2162 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2164 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2165 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2166 // OS X has lighter border edges than classic:
2169 darkShadow
.red
= 0x8E8E;
2170 darkShadow
.green
= 0x8E8E;
2171 darkShadow
.blue
= 0x8E8E;
2172 lightShadow
.red
= 0xBDBD;
2173 lightShadow
.green
= 0xBDBD;
2174 lightShadow
.blue
= 0xBDBD;
2180 GetSize( &w
, &h
) ;
2181 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2183 #if wxMAC_USE_THEME_BORDER
2184 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2187 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2188 InsetRect( &rect , border , border );
2189 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2192 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2194 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2195 RGBForeColor( &face
);
2196 MoveTo( left
+ 0 , top
+ h
- 2 );
2197 LineTo( left
+ 0 , top
+ 0 );
2198 LineTo( left
+ w
- 2 , top
+ 0 );
2200 MoveTo( left
+ 2 , top
+ h
- 3 );
2201 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2202 LineTo( left
+ w
- 3 , top
+ 2 );
2204 RGBForeColor( sunken
? &face
: &darkShadow
);
2205 MoveTo( left
+ 0 , top
+ h
- 1 );
2206 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2207 LineTo( left
+ w
- 1 , top
+ 0 );
2209 RGBForeColor( sunken
? &lightShadow
: &white
);
2210 MoveTo( left
+ 1 , top
+ h
- 3 );
2211 LineTo( left
+ 1, top
+ 1 );
2212 LineTo( left
+ w
- 3 , top
+ 1 );
2214 RGBForeColor( sunken
? &white
: &lightShadow
);
2215 MoveTo( left
+ 1 , top
+ h
- 2 );
2216 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2217 LineTo( left
+ w
- 2 , top
+ 1 );
2219 RGBForeColor( sunken
? &darkShadow
: &face
);
2220 MoveTo( left
+ 2 , top
+ h
- 4 );
2221 LineTo( left
+ 2 , top
+ 2 );
2222 LineTo( left
+ w
- 4 , top
+ 2 );
2225 else if (HasFlag(wxSIMPLE_BORDER
))
2227 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2228 RGBForeColor( &darkShadow
) ;
2229 FrameRect( &rect
) ;
2233 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2235 if ( child
== m_hScrollBar
)
2236 m_hScrollBar
= NULL
;
2237 if ( child
== m_vScrollBar
)
2238 m_vScrollBar
= NULL
;
2240 wxWindowBase::RemoveChild( child
) ;
2243 // New function that will replace some of the above.
2244 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2245 int range
, bool refresh
)
2247 if ( orient
== wxHORIZONTAL
)
2251 if ( range
== 0 || thumbVisible
>= range
)
2253 if ( m_hScrollBar
->IsShown() )
2254 m_hScrollBar
->Show(false) ;
2258 if ( !m_hScrollBar
->IsShown() )
2259 m_hScrollBar
->Show(true) ;
2260 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2268 if ( range
== 0 || thumbVisible
>= range
)
2270 if ( m_vScrollBar
->IsShown() )
2271 m_vScrollBar
->Show(false) ;
2275 if ( !m_vScrollBar
->IsShown() )
2276 m_vScrollBar
->Show(true) ;
2277 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2281 MacRepositionScrollBars() ;
2284 // Does a physical scroll
2285 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2287 if( dx
== 0 && dy
==0 )
2293 int width
, height
;
2294 GetClientSize( &width
, &height
) ;
2295 #if TARGET_API_MAC_OSX
2296 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2297 // area is scrolled, this does not occur if width and height are 2 pixels less,
2298 // TODO write optimal workaround
2299 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2302 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2303 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2305 if ( HIViewGetNeedsDisplay( (ControlRef
) m_macControl
) )
2307 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2308 // either immediate redraw or full invalidate
2310 // is the better overall solution, as it does not slow down scrolling
2311 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2313 // this would be the preferred version for fast drawing controls
2314 if( UMAGetSystemVersion() < 0x1030 )
2317 HIViewRender((ControlRef
) m_macControl
) ;
2320 HIViewScrollRect ( (ControlRef
) m_macControl
, &scrollrect
, dx
,dy
) ;
2327 RgnHandle updateRgn
= NewRgn() ;
2330 wxClientDC
dc(this) ;
2331 wxMacPortSetter
helper(&dc
) ;
2333 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2334 scrollrect
.top
+= MacGetTopBorderSize() ;
2335 scrollrect
.left
+= MacGetLeftBorderSize() ;
2336 scrollrect
.bottom
= scrollrect
.top
+ height
;
2337 scrollrect
.right
= scrollrect
.left
+ width
;
2341 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2342 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2343 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2345 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2347 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2351 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2353 wxWindowMac
*child
= node
->GetData();
2354 if (child
== m_vScrollBar
) continue;
2355 if (child
== m_hScrollBar
) continue;
2356 if (child
->IsTopLevel()) continue;
2359 child
->GetPosition( &x
, &y
);
2361 child
->GetSize( &w
, &h
);
2365 if (rect
->Intersects(rc
))
2366 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2370 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2375 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2377 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2379 wxScrollWinEvent wevent
;
2380 wevent
.SetPosition(event
.GetPosition());
2381 wevent
.SetOrientation(event
.GetOrientation());
2382 wevent
.m_eventObject
= this;
2384 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2385 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2386 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2387 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2388 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2389 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2390 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2391 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2392 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2393 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2394 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2395 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2396 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2397 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2398 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2399 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2401 GetEventHandler()->ProcessEvent(wevent
);
2405 // Get the window with the focus
2406 wxWindowMac
*wxWindowBase::FindFocus()
2408 ControlRef control
;
2409 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2410 return wxFindControlFromMacControl( control
) ;
2413 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2415 // panel wants to track the window which was the last to have focus in it,
2416 // so we want to set ourselves as the window which last had focus
2418 // notice that it's also important to do it upwards the tree becaus
2419 // otherwise when the top level panel gets focus, it won't set it back to
2420 // us, but to some other sibling
2422 // CS:don't know if this is still needed:
2423 //wxChildFocusEvent eventFocus(this);
2424 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2429 void wxWindowMac::OnInternalIdle()
2431 // This calls the UI-update mechanism (querying windows for
2432 // menu/toolbar/control state information)
2433 if (wxUpdateUIEvent::CanUpdate(this))
2434 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2437 // Raise the window to the top of the Z order
2438 void wxWindowMac::Raise()
2440 #if TARGET_API_MAC_OSX
2441 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2445 // Lower the window to the bottom of the Z order
2446 void wxWindowMac::Lower()
2448 #if TARGET_API_MAC_OSX
2449 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2454 // static wxWindow *gs_lastWhich = NULL;
2456 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2458 // first trigger a set cursor event
2460 wxPoint clientorigin
= GetClientAreaOrigin() ;
2461 wxSize clientsize
= GetClientSize() ;
2463 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2465 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2467 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2468 if ( processedEvtSetCursor
&& event
.HasCursor() )
2470 cursor
= event
.GetCursor() ;
2475 // the test for processedEvtSetCursor is here to prevent using m_cursor
2476 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2477 // it - this is a way to say that our cursor shouldn't be used for this
2479 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2489 cursor
= *wxSTANDARD_CURSOR
;
2493 cursor
.MacInstall() ;
2495 return cursor
.Ok() ;
2498 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2502 return m_tooltip
->GetTip() ;
2504 return wxEmptyString
;
2507 void wxWindowMac::Update()
2509 #if TARGET_API_MAC_OSX
2510 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2511 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2512 // for composited windows this also triggers a redraw of all
2513 // invalid views in the window
2514 if( UMAGetSystemVersion() >= 0x1030 )
2515 HIWindowFlush(window
) ;
2519 // the only way to trigger the redrawing on earlier systems is to call
2522 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2523 UInt32 currentEventClass
= 0 ;
2524 UInt32 currentEventKind
= 0 ;
2525 if ( currentEvent
!= NULL
)
2527 currentEventClass
= ::GetEventClass( currentEvent
) ;
2528 currentEventKind
= ::GetEventKind( currentEvent
) ;
2530 if ( currentEventClass
!= kEventClassMenu
)
2532 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2535 OSStatus status
= noErr
;
2536 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2539 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2542 ::Draw1Control( (ControlRef
) m_macControl
) ;
2546 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2548 wxTopLevelWindowMac
* win
= NULL
;
2549 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2552 win
= wxFindWinFromMacWindow( window
) ;
2556 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2560 RgnHandle visRgn
= NewRgn() ;
2561 RgnHandle tempRgn
= NewRgn() ;
2562 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2564 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2565 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2567 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2568 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2577 if ( includeOuterStructures
)
2578 InsetRect( &r
, -3 , -3 ) ;
2579 RectRgn( visRgn
, &r
) ;
2580 if ( !IsTopLevel() )
2582 wxWindow
* child
= this ;
2583 wxWindow
* parent
= child
->GetParent() ;
2588 // we have to find a better clipping algorithm here, in order not to clip things
2589 // positioned like status and toolbar
2590 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2592 size
= parent
->GetSize() ;
2597 size
= parent
->GetClientSize() ;
2598 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2602 parent
->MacWindowToRootWindow( &x
, &y
) ;
2603 MacRootWindowToWindow( &x
, &y
) ;
2605 SetRectRgn( tempRgn
,
2606 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2607 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2608 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2610 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2611 if ( parent
->IsTopLevel() )
2614 parent
= child
->GetParent() ;
2619 wxRegion vis
= visRgn
;
2620 DisposeRgn( visRgn
) ;
2621 DisposeRgn( tempRgn
) ;
2626 This function must not change the updatergn !
2628 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2630 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2631 bool handled
= false ;
2633 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2635 RgnHandle newupdate
= NewRgn() ;
2636 wxSize point
= GetClientSize() ;
2637 wxPoint origin
= GetClientAreaOrigin() ;
2638 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2639 SectRgn( newupdate
, updatergn
, newupdate
) ;
2640 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2641 m_updateRegion
= newupdate
;
2642 DisposeRgn( newupdate
) ;
2645 if ( !EmptyRgn(updatergn
) )
2647 wxWindowDC
dc(this);
2648 if (!EmptyRgn(updatergn
))
2649 dc
.SetClippingRegion(wxRegion(updatergn
));
2651 wxEraseEvent
eevent( GetId(), &dc
);
2652 eevent
.SetEventObject( this );
2653 GetEventHandler()->ProcessEvent( eevent
);
2655 if ( !m_updateRegion
.Empty() )
2657 // paint the window itself
2659 event
.m_timeStamp
= time
;
2660 event
.SetEventObject(this);
2661 handled
= GetEventHandler()->ProcessEvent(event
);
2663 // paint custom borders
2664 wxNcPaintEvent
eventNc( GetId() );
2665 eventNc
.SetEventObject( this );
2666 GetEventHandler()->ProcessEvent( eventNc
);
2672 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2674 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2675 // updatergn is always already clipped to our boundaries
2676 // if we are in compositing mode then it is in relative to the upper left of the control
2677 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2678 // of the toplevel window
2679 // it is in window coordinates, not in client coordinates
2681 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2682 RgnHandle ownUpdateRgn
= NewRgn() ;
2683 CopyRgn( updatergn
, ownUpdateRgn
) ;
2685 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2688 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2689 RgnHandle controlRgn
= NewRgn();
2690 RectRgn( controlRgn
, &bounds
);
2691 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2692 // the window update region
2693 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2694 DisposeRgn( controlRgn
);
2696 //KO: convert ownUpdateRgn to local coordinates
2697 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2700 MacDoRedraw( ownUpdateRgn
, time
) ;
2701 DisposeRgn( ownUpdateRgn
) ;
2705 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2707 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2711 if ( iter
->IsTopLevel() )
2712 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2714 iter
= iter
->GetParent() ;
2716 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2720 void wxWindowMac::MacCreateScrollBars( long style
)
2722 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2724 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2725 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2727 GetClientSize( &width
, &height
) ;
2729 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2730 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2731 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2732 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2734 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2735 vSize
, wxVERTICAL
);
2737 if ( style
& wxVSCROLL
)
2743 m_vScrollBar
->Show(false) ;
2745 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2746 hSize
, wxHORIZONTAL
);
2747 if ( style
& wxHSCROLL
)
2752 m_hScrollBar
->Show(false) ;
2755 // because the create does not take into account the client area origin
2756 MacRepositionScrollBars() ; // we might have a real position shift
2759 void wxWindowMac::MacRepositionScrollBars()
2761 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2762 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2764 // get real client area
2768 GetSize( &width
, &height
) ;
2770 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2771 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2773 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2774 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2775 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2776 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2782 GetSize( &w
, &h
) ;
2784 MacClientToRootWindow( &x
, &y
) ;
2785 MacClientToRootWindow( &w
, &h
) ;
2787 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2789 int totW
= 10000 , totH
= 10000;
2792 if ( iter
->IsTopLevel() )
2794 iter
->GetSize( &totW
, &totH
) ;
2798 iter
= iter
->GetParent() ;
2826 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2830 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2834 bool wxWindowMac::AcceptsFocus() const
2836 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2839 void wxWindowMac::MacSuperChangedPosition()
2841 // only window-absolute structures have to be moved i.e. controls
2843 wxWindowListNode
*node
= GetChildren().GetFirst();
2846 wxWindowMac
*child
= node
->GetData();
2847 child
->MacSuperChangedPosition() ;
2848 node
= node
->GetNext();
2852 void wxWindowMac::MacTopLevelWindowChangedPosition()
2854 // only screen-absolute structures have to be moved i.e. glcanvas
2856 wxWindowListNode
*node
= GetChildren().GetFirst();
2859 wxWindowMac
*child
= node
->GetData();
2860 child
->MacTopLevelWindowChangedPosition() ;
2861 node
= node
->GetNext();
2865 long wxWindowMac::MacGetLeftBorderSize( ) const
2870 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2873 #if wxMAC_USE_THEME_BORDER
2874 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2878 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2881 #if wxMAC_USE_THEME_BORDER
2882 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2886 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2893 long wxWindowMac::MacGetRightBorderSize( ) const
2895 // they are all symmetric in mac themes
2896 return MacGetLeftBorderSize() ;
2899 long wxWindowMac::MacGetTopBorderSize( ) const
2901 // they are all symmetric in mac themes
2902 return MacGetLeftBorderSize() ;
2905 long wxWindowMac::MacGetBottomBorderSize( ) const
2907 // they are all symmetric in mac themes
2908 return MacGetLeftBorderSize() ;
2911 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2913 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2916 // Find the wxWindowMac at the current mouse position, returning the mouse
2918 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2920 pt
= wxGetMousePosition();
2921 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2925 // Get the current mouse position.
2926 wxPoint
wxGetMousePosition()
2929 wxGetMousePosition(& x
, & y
);
2930 return wxPoint(x
, y
);
2933 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2935 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2937 // copied from wxGTK : CS
2938 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2941 // (a) it's a command event and so is propagated to the parent
2942 // (b) under MSW it can be generated from kbd too
2943 // (c) it uses screen coords (because of (a))
2944 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2946 this->ClientToScreen(event
.GetPosition()));
2947 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2956 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2960 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2964 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2965 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2969 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2971 return eventNotHandledErr
;