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
939 // there is currently no way to determinate whether the window is running in full keyboard
940 // access mode, therefore we cannot rely on these features yet
941 UInt32 features
= 0 ;
942 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
943 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
949 void wxWindowMac::SetFocus()
951 if ( AcceptsFocus() )
953 #if !TARGET_API_MAC_OSX
954 wxWindow
* former
= FindFocus() ;
956 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
957 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
958 // leave in case of an error
959 if ( err
== errCouldntSetFocus
)
962 #if !TARGET_API_MAC_OSX
963 // emulate carbon events when running under carbonlib where they are not natively available
966 EventRef evRef
= NULL
;
967 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
970 wxMacCarbonEvent
cEvent( evRef
) ;
971 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
972 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
974 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
975 ReleaseEvent(evRef
) ;
977 // send new focus event
979 EventRef evRef
= NULL
;
980 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
983 wxMacCarbonEvent
cEvent( evRef
) ;
984 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
985 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
987 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
988 ReleaseEvent(evRef
) ;
995 void wxWindowMac::DoCaptureMouse()
997 wxTheApp
->s_captureWindow
= this ;
1000 wxWindow
* wxWindowBase::GetCapture()
1002 return wxTheApp
->s_captureWindow
;
1005 void wxWindowMac::DoReleaseMouse()
1007 wxTheApp
->s_captureWindow
= NULL
;
1010 #if wxUSE_DRAG_AND_DROP
1012 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1014 if ( m_dropTarget
!= 0 ) {
1015 delete m_dropTarget
;
1018 m_dropTarget
= pDropTarget
;
1019 if ( m_dropTarget
!= 0 )
1027 // Old style file-manager drag&drop
1028 void wxWindowMac::DragAcceptFiles(bool accept
)
1033 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1034 int& w
, int& h
) const
1037 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1042 w
= bounds
.right
- bounds
.left
;
1043 h
= bounds
.bottom
- bounds
.top
;
1045 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1048 Point tlworigin
= { 0 , 0 } ;
1050 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1051 ::LocalToGlobal( &tlworigin
) ;
1059 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1062 int& w
, int& h
, bool adjustOrigin
) const
1066 // todo the default calls may be used as soon as PostCreateControl Is moved here
1067 w
= size
.x
; // WidthDefault( size.x );
1068 h
= size
.y
; // HeightDefault( size.y ) ;
1069 #if !TARGET_API_MAC_OSX
1070 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1073 AdjustForParentClientOrigin( x
, y
) ;
1078 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1080 #if TARGET_API_MAC_OSX
1081 int x1
, y1
, w1
,h1
;
1082 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1088 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1089 if(x
) *x
= bounds
.right
- bounds
.left
;
1090 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1094 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1096 #if TARGET_API_MAC_OSX
1097 int x1
, y1
, w1
,h1
;
1098 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1099 if ( !IsTopLevel() )
1101 wxWindow
*parent
= GetParent();
1104 wxPoint
pt(parent
->GetClientAreaOrigin());
1113 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1114 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1116 int xx
= bounds
.left
;
1117 int yy
= bounds
.top
;
1119 if ( !GetParent()->IsTopLevel() )
1121 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1127 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1136 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1138 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1140 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1143 Point localwhere
= {0,0} ;
1145 if(x
) localwhere
.h
= * x
;
1146 if(y
) localwhere
.v
= * y
;
1148 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1149 ::GlobalToLocal( &localwhere
) ;
1150 if(x
) *x
= localwhere
.h
;
1151 if(y
) *y
= localwhere
.v
;
1154 MacRootWindowToWindow( x
, y
) ;
1156 wxPoint origin
= GetClientAreaOrigin() ;
1157 if(x
) *x
-= origin
.x
;
1158 if(y
) *y
-= origin
.y
;
1161 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1163 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1164 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1166 wxPoint origin
= GetClientAreaOrigin() ;
1167 if(x
) *x
+= origin
.x
;
1168 if(y
) *y
+= origin
.y
;
1170 MacWindowToRootWindow( x
, y
) ;
1173 Point localwhere
= { 0,0 };
1174 if(x
) localwhere
.h
= * x
;
1175 if(y
) localwhere
.v
= * y
;
1177 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1178 ::LocalToGlobal( &localwhere
) ;
1179 if(x
) *x
= localwhere
.h
;
1180 if(y
) *y
= localwhere
.v
;
1184 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1186 wxPoint origin
= GetClientAreaOrigin() ;
1187 if(x
) *x
+= origin
.x
;
1188 if(y
) *y
+= origin
.y
;
1190 MacWindowToRootWindow( x
, y
) ;
1193 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1195 MacRootWindowToWindow( x
, y
) ;
1197 wxPoint origin
= GetClientAreaOrigin() ;
1198 if(x
) *x
-= origin
.x
;
1199 if(y
) *y
-= origin
.y
;
1202 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1204 #if TARGET_API_MAC_OSX
1206 if ( x
) pt
.x
= *x
;
1207 if ( y
) pt
.y
= *y
;
1209 if ( !IsTopLevel() )
1210 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1212 if ( x
) *x
= (int) pt
.x
;
1213 if ( y
) *y
= (int) pt
.y
;
1215 if ( !IsTopLevel() )
1218 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1219 if(x
) *x
+= bounds
.left
;
1220 if(y
) *y
+= bounds
.top
;
1225 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1230 MacWindowToRootWindow( &x1
, &y1
) ;
1235 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1237 #if TARGET_API_MAC_OSX
1239 if ( x
) pt
.x
= *x
;
1240 if ( y
) pt
.y
= *y
;
1242 if ( !IsTopLevel() )
1243 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1245 if ( x
) *x
= (int) pt
.x
;
1246 if ( y
) *y
= (int) pt
.y
;
1248 if ( !IsTopLevel() )
1251 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1252 if(x
) *x
-= bounds
.left
;
1253 if(y
) *y
-= bounds
.top
;
1258 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1263 MacRootWindowToWindow( &x1
, &y1
) ;
1268 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1270 RgnHandle rgn
= NewRgn() ;
1272 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1274 GetRegionBounds( rgn
, &content
) ;
1279 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1282 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1283 #if !TARGET_API_MAC_OSX
1284 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1286 left
= content
.left
- structure
.left
;
1287 top
= content
.top
- structure
.top
;
1288 right
= structure
.right
- content
.right
;
1289 bottom
= structure
.bottom
- content
.bottom
;
1292 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1294 wxSize sizeTotal
= size
;
1296 RgnHandle rgn
= NewRgn() ;
1300 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1302 GetRegionBounds( rgn
, &content
) ;
1307 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1310 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1311 #if !TARGET_API_MAC_OSX
1312 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1315 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1316 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1318 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1319 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1325 // Get size *available for subwindows* i.e. excluding menu bar etc.
1326 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1330 RgnHandle rgn
= NewRgn() ;
1332 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1334 GetRegionBounds( rgn
, &content
) ;
1339 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1341 #if !TARGET_API_MAC_OSX
1343 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1344 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1346 ww
= content
.right
- content
.left
;
1347 hh
= content
.bottom
- content
.top
;
1349 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1350 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1352 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1358 GetSize( &w
, &h
) ;
1360 MacClientToRootWindow( &x1
, &y1
) ;
1361 MacClientToRootWindow( &w
, &h
) ;
1363 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1365 int totW
= 10000 , totH
= 10000;
1368 if ( iter
->IsTopLevel() )
1370 iter
->GetSize( &totW
, &totH
) ;
1374 iter
= iter
->GetParent() ;
1377 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1379 hh
-= MAC_SCROLLBAR_SIZE
;
1385 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1387 ww
-= MAC_SCROLLBAR_SIZE
;
1399 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1401 if (m_cursor
== cursor
)
1404 if (wxNullCursor
== cursor
)
1406 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1411 if ( ! wxWindowBase::SetCursor( cursor
) )
1415 wxASSERT_MSG( m_cursor
.Ok(),
1416 wxT("cursor must be valid after call to the base version"));
1420 TODO why do we have to use current coordinates ?
1423 wxWindowMac *mouseWin ;
1426 // Change the cursor NOW if we're within the correct window
1429 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1431 if ( mouseWin == this && !wxIsBusy() )
1433 m_cursor.MacInstall() ;
1439 m_cursor
.MacInstall() ;
1446 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1448 menu
->SetInvokingWindow(this);
1450 ClientToScreen( &x
, &y
) ;
1452 menu
->MacBeforeDisplay( true ) ;
1453 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1454 if ( HiWord(menuResult
) != 0 )
1457 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1458 wxMenuItem
* item
= NULL
;
1460 item
= menu
->FindItem(id
, &realmenu
) ;
1461 if (item
->IsCheckable())
1463 item
->Check( !item
->IsChecked() ) ;
1465 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1467 menu
->MacAfterDisplay( true ) ;
1469 menu
->SetInvokingWindow(NULL
);
1475 // ----------------------------------------------------------------------------
1477 // ----------------------------------------------------------------------------
1481 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1483 wxWindowBase::DoSetToolTip(tooltip
);
1486 m_tooltip
->SetWindow(this);
1489 #endif // wxUSE_TOOLTIPS
1491 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1493 int former_x
, former_y
, former_w
, former_h
;
1494 #if !TARGET_API_MAC_OSX
1495 DoGetPosition( &former_x
, &former_y
) ;
1496 DoGetSize( &former_w
, &former_h
) ;
1498 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1501 int actualWidth
= width
;
1502 int actualHeight
= height
;
1506 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1507 actualWidth
= m_minWidth
;
1508 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1509 actualHeight
= m_minHeight
;
1510 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1511 actualWidth
= m_maxWidth
;
1512 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1513 actualHeight
= m_maxHeight
;
1515 bool doMove
= false ;
1516 bool doResize
= false ;
1518 if ( actualX
!= former_x
|| actualY
!= former_y
)
1522 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1527 if ( doMove
|| doResize
)
1529 // we don't adjust twice for the origin
1530 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1531 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1532 #if TARGET_API_MAC_OSX
1533 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1535 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1536 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1537 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1539 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1542 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1543 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1545 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1547 MacRepositionScrollBars() ;
1550 wxPoint
point(actualX
,actualY
);
1551 wxMoveEvent
event(point
, m_windowId
);
1552 event
.SetEventObject(this);
1553 GetEventHandler()->ProcessEvent(event
) ;
1557 MacRepositionScrollBars() ;
1558 wxSize
size(actualWidth
, actualHeight
);
1559 wxSizeEvent
event(size
, m_windowId
);
1560 event
.SetEventObject(this);
1561 GetEventHandler()->ProcessEvent(event
);
1567 wxSize
wxWindowMac::DoGetBestSize() const
1569 if ( m_macIsUserPane
|| IsTopLevel() )
1570 return wxWindowBase::DoGetBestSize() ;
1572 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1573 short baselineoffset
;
1574 int bestWidth
, bestHeight
;
1575 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1577 if ( EmptyRect( &bestsize
) )
1580 bestsize
.left
= bestsize
.top
= 0 ;
1581 bestsize
.right
= 16 ;
1582 bestsize
.bottom
= 16 ;
1583 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1585 bestsize
.bottom
= 16 ;
1587 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1589 bestsize
.bottom
= 24 ;
1593 // return wxWindowBase::DoGetBestSize() ;
1597 bestWidth
= bestsize
.right
- bestsize
.left
;
1598 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1599 if ( bestHeight
< 10 )
1602 return wxSize(bestWidth
, bestHeight
);
1603 // return wxWindowBase::DoGetBestSize() ;
1607 // set the size of the window: if the dimensions are positive, just use them,
1608 // but if any of them is equal to -1, it means that we must find the value for
1609 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1610 // which case -1 is a valid value for x and y)
1612 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1613 // the width/height to best suit our contents, otherwise we reuse the current
1615 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1617 // get the current size and position...
1618 int currentX
, currentY
;
1619 GetPosition(¤tX
, ¤tY
);
1621 int currentW
,currentH
;
1622 GetSize(¤tW
, ¤tH
);
1624 // ... and don't do anything (avoiding flicker) if it's already ok
1625 if ( x
== currentX
&& y
== currentY
&&
1626 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1629 MacRepositionScrollBars() ; // we might have a real position shift
1633 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1635 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1638 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1640 wxSize
size(-1, -1);
1643 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1645 size
= DoGetBestSize();
1650 // just take the current one
1657 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1661 size
= DoGetBestSize();
1663 //else: already called DoGetBestSize() above
1669 // just take the current one
1674 DoMoveWindow(x
, y
, width
, height
);
1678 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1680 RgnHandle rgn
= NewRgn() ;
1682 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1683 GetRegionBounds( rgn
, &content
) ;
1685 #if !TARGET_API_MAC_OSX
1686 // if the content rgn is empty / not supported
1687 // don't attempt to correct the coordinates to wxWindow relative ones
1688 if (!::EmptyRect( &content
) )
1691 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1692 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1696 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1699 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1701 if ( clientheight
!= -1 || clientheight
!= -1 )
1703 int currentclientwidth
, currentclientheight
;
1704 int currentwidth
, currentheight
;
1706 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1707 GetSize( ¤twidth
, ¤theight
) ;
1709 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1710 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1714 void wxWindowMac::SetTitle(const wxString
& title
)
1716 m_label
= wxStripMenuCodes(title
) ;
1720 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1725 wxString
wxWindowMac::GetTitle() const
1730 bool wxWindowMac::Show(bool show
)
1732 if ( !wxWindowBase::Show(show
) )
1735 // TODO use visibilityChanged Carbon Event for OSX
1736 bool former
= MacIsReallyShown() ;
1738 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1739 if ( former
!= MacIsReallyShown() )
1740 MacPropagateVisibilityChanged() ;
1744 bool wxWindowMac::Enable(bool enable
)
1746 wxASSERT( m_macControl
!= NULL
) ;
1747 if ( !wxWindowBase::Enable(enable
) )
1750 bool former
= MacIsReallyEnabled() ;
1751 #if TARGET_API_MAC_OSX
1753 EnableControl( (ControlRef
) m_macControl
) ;
1755 DisableControl( (ControlRef
) m_macControl
) ;
1758 ActivateControl( (ControlRef
) m_macControl
) ;
1760 DeactivateControl( (ControlRef
) m_macControl
) ;
1763 if ( former
!= MacIsReallyEnabled() )
1764 MacPropagateEnabledStateChanged() ;
1769 // status change propagations (will be not necessary for OSX later )
1772 void wxWindowMac::MacPropagateVisibilityChanged()
1774 #if !TARGET_API_MAC_OSX
1775 MacVisibilityChanged() ;
1777 wxWindowListNode
*node
= GetChildren().GetFirst();
1780 wxWindowMac
*child
= node
->GetData();
1781 if ( child
->IsShown() )
1782 child
->MacPropagateVisibilityChanged( ) ;
1783 node
= node
->GetNext();
1788 void wxWindowMac::MacPropagateEnabledStateChanged( )
1790 #if !TARGET_API_MAC_OSX
1791 MacEnabledStateChanged() ;
1793 wxWindowListNode
*node
= GetChildren().GetFirst();
1796 wxWindowMac
*child
= node
->GetData();
1797 if ( child
->IsEnabled() )
1798 child
->MacPropagateEnabledStateChanged() ;
1799 node
= node
->GetNext();
1804 void wxWindowMac::MacPropagateHiliteChanged( )
1806 #if !TARGET_API_MAC_OSX
1807 MacHiliteChanged() ;
1809 wxWindowListNode
*node
= GetChildren().GetFirst();
1812 wxWindowMac
*child
= node
->GetData();
1813 // if ( child->IsEnabled() )
1814 child
->MacPropagateHiliteChanged() ;
1815 node
= node
->GetNext();
1821 // status change notifications
1824 void wxWindowMac::MacVisibilityChanged()
1828 void wxWindowMac::MacHiliteChanged()
1832 void wxWindowMac::MacEnabledStateChanged()
1837 // status queries on the inherited window's state
1840 bool wxWindowMac::MacIsReallyShown()
1842 // only under OSX the visibility of the TLW is taken into account
1843 #if TARGET_API_MAC_OSX
1844 return IsControlVisible( (ControlRef
) m_macControl
) ;
1846 wxWindow
* win
= this ;
1847 while( win
->IsShown() )
1849 if ( win
->IsTopLevel() )
1852 win
= win
->GetParent() ;
1861 bool wxWindowMac::MacIsReallyEnabled()
1863 #if TARGET_API_MAC_OSX
1864 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1866 return IsControlActive( (ControlRef
) m_macControl
) ;
1870 bool wxWindowMac::MacIsReallyHilited()
1872 return IsControlActive( (ControlRef
) m_macControl
) ;
1875 void wxWindowMac::MacFlashInvalidAreas()
1877 #if TARGET_API_MAC_OSX
1878 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1886 int wxWindowMac::GetCharHeight() const
1888 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1889 return dc
.GetCharHeight() ;
1892 int wxWindowMac::GetCharWidth() const
1894 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1895 return dc
.GetCharWidth() ;
1898 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1899 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1901 const wxFont
*fontToUse
= theFont
;
1903 fontToUse
= &m_font
;
1905 wxClientDC
dc( (wxWindowMac
*) this ) ;
1907 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1908 if ( externalLeading
)
1909 *externalLeading
= le
;
1919 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1920 * we always intersect with the entire window, not only with the client area
1923 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1925 #if TARGET_API_MAC_OSX
1927 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1930 RgnHandle update
= NewRgn() ;
1931 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1932 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1933 wxPoint origin
= GetClientAreaOrigin() ;
1934 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1935 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1939 RgnHandle updateRgn = NewRgn() ;
1942 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1946 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1947 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1949 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1950 DisposeRgn(updateRgn) ;
1952 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1954 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1955 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1958 if ( MacGetTopLevelWindow() == NULL )
1961 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1964 wxPoint client = GetClientAreaOrigin();
1967 int x2 = m_width - client.x;
1968 int y2 = m_height - client.y;
1970 if (IsKindOf( CLASSINFO(wxButton)))
1972 // buttons have an "aura"
1979 Rect clientrect = { y1, x1, y2, x2 };
1983 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1984 SectRect( &clientrect , &r , &clientrect ) ;
1987 if ( !EmptyRect( &clientrect ) )
1989 int top = 0 , left = 0 ;
1991 MacClientToRootWindow( &left , &top ) ;
1992 OffsetRect( &clientrect , left , top ) ;
1994 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2000 void wxWindowMac::Freeze()
2002 #if TARGET_API_MAC_OSX
2003 if ( !m_frozenness
++ )
2005 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
2010 #if TARGET_API_MAC_OSX
2011 static void InvalidateControlAndChildren( HIViewRef control
)
2013 HIViewSetNeedsDisplay( control
, true ) ;
2014 UInt16 childrenCount
= 0 ;
2015 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2016 if ( err
== errControlIsNotEmbedder
)
2018 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2020 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2023 err
= GetIndexedSubControl( control
, i
, & child
) ;
2024 if ( err
== errControlIsNotEmbedder
)
2026 InvalidateControlAndChildren( child
) ;
2031 void wxWindowMac::Thaw()
2033 #if TARGET_API_MAC_OSX
2034 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2036 if ( !--m_frozenness
)
2038 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2039 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2040 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2045 void wxWindowMac::MacRedrawControl()
2048 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2050 #if TARGET_API_MAC_CARBON
2053 wxClientDC dc(this) ;
2054 wxMacPortSetter helper(&dc) ;
2055 wxMacWindowClipper clipper(this) ;
2056 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2057 UMADrawControl( (ControlRef) m_macControl ) ;
2064 void wxWindowMac::OnPaint(wxPaintEvent& event)
2066 // why don't we skip that here ?
2070 wxWindowMac
*wxGetActiveWindow()
2072 // actually this is a windows-only concept
2076 // Coordinates relative to the window
2077 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2079 // We really don't move the mouse programmatically under Mac.
2082 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2084 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2089 event
.GetDC()->Clear() ;
2092 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2094 wxWindowDC
dc(this) ;
2095 wxMacPortSetter
helper(&dc
) ;
2097 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2100 int wxWindowMac::GetScrollPos(int orient
) const
2102 if ( orient
== wxHORIZONTAL
)
2105 return m_hScrollBar
->GetThumbPosition() ;
2110 return m_vScrollBar
->GetThumbPosition() ;
2115 // This now returns the whole range, not just the number
2116 // of positions that we can scroll.
2117 int wxWindowMac::GetScrollRange(int orient
) const
2119 if ( orient
== wxHORIZONTAL
)
2122 return m_hScrollBar
->GetRange() ;
2127 return m_vScrollBar
->GetRange() ;
2132 int wxWindowMac::GetScrollThumb(int orient
) const
2134 if ( orient
== wxHORIZONTAL
)
2137 return m_hScrollBar
->GetThumbSize() ;
2142 return m_vScrollBar
->GetThumbSize() ;
2147 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2149 if ( orient
== wxHORIZONTAL
)
2152 m_hScrollBar
->SetThumbPosition( pos
) ;
2157 m_vScrollBar
->SetThumbPosition( pos
) ;
2161 void wxWindowMac::MacPaintBorders( int left
, int top
)
2167 wxGetOsVersion( &major
, &minor
);
2169 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2170 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2172 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2173 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2174 // OS X has lighter border edges than classic:
2177 darkShadow
.red
= 0x8E8E;
2178 darkShadow
.green
= 0x8E8E;
2179 darkShadow
.blue
= 0x8E8E;
2180 lightShadow
.red
= 0xBDBD;
2181 lightShadow
.green
= 0xBDBD;
2182 lightShadow
.blue
= 0xBDBD;
2188 GetSize( &w
, &h
) ;
2189 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2191 #if wxMAC_USE_THEME_BORDER
2192 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2195 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2196 InsetRect( &rect , border , border );
2197 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2200 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2202 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2203 RGBForeColor( &face
);
2204 MoveTo( left
+ 0 , top
+ h
- 2 );
2205 LineTo( left
+ 0 , top
+ 0 );
2206 LineTo( left
+ w
- 2 , top
+ 0 );
2208 MoveTo( left
+ 2 , top
+ h
- 3 );
2209 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2210 LineTo( left
+ w
- 3 , top
+ 2 );
2212 RGBForeColor( sunken
? &face
: &darkShadow
);
2213 MoveTo( left
+ 0 , top
+ h
- 1 );
2214 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2215 LineTo( left
+ w
- 1 , top
+ 0 );
2217 RGBForeColor( sunken
? &lightShadow
: &white
);
2218 MoveTo( left
+ 1 , top
+ h
- 3 );
2219 LineTo( left
+ 1, top
+ 1 );
2220 LineTo( left
+ w
- 3 , top
+ 1 );
2222 RGBForeColor( sunken
? &white
: &lightShadow
);
2223 MoveTo( left
+ 1 , top
+ h
- 2 );
2224 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2225 LineTo( left
+ w
- 2 , top
+ 1 );
2227 RGBForeColor( sunken
? &darkShadow
: &face
);
2228 MoveTo( left
+ 2 , top
+ h
- 4 );
2229 LineTo( left
+ 2 , top
+ 2 );
2230 LineTo( left
+ w
- 4 , top
+ 2 );
2233 else if (HasFlag(wxSIMPLE_BORDER
))
2235 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2236 RGBForeColor( &darkShadow
) ;
2237 FrameRect( &rect
) ;
2241 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2243 if ( child
== m_hScrollBar
)
2244 m_hScrollBar
= NULL
;
2245 if ( child
== m_vScrollBar
)
2246 m_vScrollBar
= NULL
;
2248 wxWindowBase::RemoveChild( child
) ;
2251 // New function that will replace some of the above.
2252 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2253 int range
, bool refresh
)
2255 if ( orient
== wxHORIZONTAL
)
2259 if ( range
== 0 || thumbVisible
>= range
)
2261 if ( m_hScrollBar
->IsShown() )
2262 m_hScrollBar
->Show(false) ;
2266 if ( !m_hScrollBar
->IsShown() )
2267 m_hScrollBar
->Show(true) ;
2268 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2276 if ( range
== 0 || thumbVisible
>= range
)
2278 if ( m_vScrollBar
->IsShown() )
2279 m_vScrollBar
->Show(false) ;
2283 if ( !m_vScrollBar
->IsShown() )
2284 m_vScrollBar
->Show(true) ;
2285 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2289 MacRepositionScrollBars() ;
2292 // Does a physical scroll
2293 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2295 if( dx
== 0 && dy
==0 )
2301 int width
, height
;
2302 GetClientSize( &width
, &height
) ;
2303 #if TARGET_API_MAC_OSX
2304 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2305 // area is scrolled, this does not occur if width and height are 2 pixels less,
2306 // TODO write optimal workaround
2307 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2310 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2311 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2313 if ( HIViewGetNeedsDisplay( (ControlRef
) m_macControl
) )
2315 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2316 // either immediate redraw or full invalidate
2318 // is the better overall solution, as it does not slow down scrolling
2319 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2321 // this would be the preferred version for fast drawing controls
2322 if( UMAGetSystemVersion() < 0x1030 )
2325 HIViewRender((ControlRef
) m_macControl
) ;
2328 HIViewScrollRect ( (ControlRef
) m_macControl
, &scrollrect
, dx
,dy
) ;
2335 RgnHandle updateRgn
= NewRgn() ;
2338 wxClientDC
dc(this) ;
2339 wxMacPortSetter
helper(&dc
) ;
2341 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2342 scrollrect
.top
+= MacGetTopBorderSize() ;
2343 scrollrect
.left
+= MacGetLeftBorderSize() ;
2344 scrollrect
.bottom
= scrollrect
.top
+ height
;
2345 scrollrect
.right
= scrollrect
.left
+ width
;
2349 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2350 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2351 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2353 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2355 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2359 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2361 wxWindowMac
*child
= node
->GetData();
2362 if (child
== m_vScrollBar
) continue;
2363 if (child
== m_hScrollBar
) continue;
2364 if (child
->IsTopLevel()) continue;
2367 child
->GetPosition( &x
, &y
);
2369 child
->GetSize( &w
, &h
);
2373 if (rect
->Intersects(rc
))
2374 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2378 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2383 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2385 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2387 wxScrollWinEvent wevent
;
2388 wevent
.SetPosition(event
.GetPosition());
2389 wevent
.SetOrientation(event
.GetOrientation());
2390 wevent
.m_eventObject
= this;
2392 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2393 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2394 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2395 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2396 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2397 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2398 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2399 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2400 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2401 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2402 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2403 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2404 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2405 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2406 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2407 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2409 GetEventHandler()->ProcessEvent(wevent
);
2413 // Get the window with the focus
2414 wxWindowMac
*wxWindowBase::FindFocus()
2416 ControlRef control
;
2417 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2418 return wxFindControlFromMacControl( control
) ;
2421 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2423 // panel wants to track the window which was the last to have focus in it,
2424 // so we want to set ourselves as the window which last had focus
2426 // notice that it's also important to do it upwards the tree becaus
2427 // otherwise when the top level panel gets focus, it won't set it back to
2428 // us, but to some other sibling
2430 // CS:don't know if this is still needed:
2431 //wxChildFocusEvent eventFocus(this);
2432 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2437 void wxWindowMac::OnInternalIdle()
2439 // This calls the UI-update mechanism (querying windows for
2440 // menu/toolbar/control state information)
2441 if (wxUpdateUIEvent::CanUpdate(this))
2442 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2445 // Raise the window to the top of the Z order
2446 void wxWindowMac::Raise()
2448 #if TARGET_API_MAC_OSX
2449 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2453 // Lower the window to the bottom of the Z order
2454 void wxWindowMac::Lower()
2456 #if TARGET_API_MAC_OSX
2457 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2462 // static wxWindow *gs_lastWhich = NULL;
2464 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2466 // first trigger a set cursor event
2468 wxPoint clientorigin
= GetClientAreaOrigin() ;
2469 wxSize clientsize
= GetClientSize() ;
2471 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2473 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2475 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2476 if ( processedEvtSetCursor
&& event
.HasCursor() )
2478 cursor
= event
.GetCursor() ;
2483 // the test for processedEvtSetCursor is here to prevent using m_cursor
2484 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2485 // it - this is a way to say that our cursor shouldn't be used for this
2487 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2497 cursor
= *wxSTANDARD_CURSOR
;
2501 cursor
.MacInstall() ;
2503 return cursor
.Ok() ;
2506 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2510 return m_tooltip
->GetTip() ;
2512 return wxEmptyString
;
2515 void wxWindowMac::Update()
2517 #if TARGET_API_MAC_OSX
2518 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2519 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2520 // for composited windows this also triggers a redraw of all
2521 // invalid views in the window
2522 if( UMAGetSystemVersion() >= 0x1030 )
2523 HIWindowFlush(window
) ;
2527 // the only way to trigger the redrawing on earlier systems is to call
2530 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2531 UInt32 currentEventClass
= 0 ;
2532 UInt32 currentEventKind
= 0 ;
2533 if ( currentEvent
!= NULL
)
2535 currentEventClass
= ::GetEventClass( currentEvent
) ;
2536 currentEventKind
= ::GetEventKind( currentEvent
) ;
2538 if ( currentEventClass
!= kEventClassMenu
)
2540 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2543 OSStatus status
= noErr
;
2544 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2547 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2550 ::Draw1Control( (ControlRef
) m_macControl
) ;
2554 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2556 wxTopLevelWindowMac
* win
= NULL
;
2557 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2560 win
= wxFindWinFromMacWindow( window
) ;
2564 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2568 RgnHandle visRgn
= NewRgn() ;
2569 RgnHandle tempRgn
= NewRgn() ;
2570 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2572 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2573 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2575 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2576 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2585 if ( includeOuterStructures
)
2586 InsetRect( &r
, -3 , -3 ) ;
2587 RectRgn( visRgn
, &r
) ;
2588 if ( !IsTopLevel() )
2590 wxWindow
* child
= this ;
2591 wxWindow
* parent
= child
->GetParent() ;
2596 // we have to find a better clipping algorithm here, in order not to clip things
2597 // positioned like status and toolbar
2598 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2600 size
= parent
->GetSize() ;
2605 size
= parent
->GetClientSize() ;
2606 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2610 parent
->MacWindowToRootWindow( &x
, &y
) ;
2611 MacRootWindowToWindow( &x
, &y
) ;
2613 SetRectRgn( tempRgn
,
2614 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2615 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2616 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2618 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2619 if ( parent
->IsTopLevel() )
2622 parent
= child
->GetParent() ;
2627 wxRegion vis
= visRgn
;
2628 DisposeRgn( visRgn
) ;
2629 DisposeRgn( tempRgn
) ;
2634 This function must not change the updatergn !
2636 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2638 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2639 bool handled
= false ;
2641 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2643 RgnHandle newupdate
= NewRgn() ;
2644 wxSize point
= GetClientSize() ;
2645 wxPoint origin
= GetClientAreaOrigin() ;
2646 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2647 SectRgn( newupdate
, updatergn
, newupdate
) ;
2648 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2649 m_updateRegion
= newupdate
;
2650 DisposeRgn( newupdate
) ;
2653 if ( !EmptyRgn(updatergn
) )
2655 wxWindowDC
dc(this);
2656 if (!EmptyRgn(updatergn
))
2657 dc
.SetClippingRegion(wxRegion(updatergn
));
2659 wxEraseEvent
eevent( GetId(), &dc
);
2660 eevent
.SetEventObject( this );
2661 GetEventHandler()->ProcessEvent( eevent
);
2663 if ( !m_updateRegion
.Empty() )
2665 // paint the window itself
2667 event
.m_timeStamp
= time
;
2668 event
.SetEventObject(this);
2669 handled
= GetEventHandler()->ProcessEvent(event
);
2671 // paint custom borders
2672 wxNcPaintEvent
eventNc( GetId() );
2673 eventNc
.SetEventObject( this );
2674 GetEventHandler()->ProcessEvent( eventNc
);
2680 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2682 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2683 // updatergn is always already clipped to our boundaries
2684 // if we are in compositing mode then it is in relative to the upper left of the control
2685 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2686 // of the toplevel window
2687 // it is in window coordinates, not in client coordinates
2689 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2690 RgnHandle ownUpdateRgn
= NewRgn() ;
2691 CopyRgn( updatergn
, ownUpdateRgn
) ;
2693 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2696 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2697 RgnHandle controlRgn
= NewRgn();
2698 RectRgn( controlRgn
, &bounds
);
2699 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2700 // the window update region
2701 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2702 DisposeRgn( controlRgn
);
2704 //KO: convert ownUpdateRgn to local coordinates
2705 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2708 MacDoRedraw( ownUpdateRgn
, time
) ;
2709 DisposeRgn( ownUpdateRgn
) ;
2713 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2715 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2719 if ( iter
->IsTopLevel() )
2720 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2722 iter
= iter
->GetParent() ;
2724 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2728 void wxWindowMac::MacCreateScrollBars( long style
)
2730 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2732 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2733 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2735 GetClientSize( &width
, &height
) ;
2737 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2738 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2739 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2740 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2742 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2743 vSize
, wxVERTICAL
);
2745 if ( style
& wxVSCROLL
)
2751 m_vScrollBar
->Show(false) ;
2753 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2754 hSize
, wxHORIZONTAL
);
2755 if ( style
& wxHSCROLL
)
2760 m_hScrollBar
->Show(false) ;
2763 // because the create does not take into account the client area origin
2764 MacRepositionScrollBars() ; // we might have a real position shift
2767 void wxWindowMac::MacRepositionScrollBars()
2769 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2770 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2772 // get real client area
2776 GetSize( &width
, &height
) ;
2778 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2779 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2781 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2782 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2783 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2784 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2790 GetSize( &w
, &h
) ;
2792 MacClientToRootWindow( &x
, &y
) ;
2793 MacClientToRootWindow( &w
, &h
) ;
2795 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2797 int totW
= 10000 , totH
= 10000;
2800 if ( iter
->IsTopLevel() )
2802 iter
->GetSize( &totW
, &totH
) ;
2806 iter
= iter
->GetParent() ;
2834 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2838 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2842 bool wxWindowMac::AcceptsFocus() const
2844 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2847 void wxWindowMac::MacSuperChangedPosition()
2849 // only window-absolute structures have to be moved i.e. controls
2851 wxWindowListNode
*node
= GetChildren().GetFirst();
2854 wxWindowMac
*child
= node
->GetData();
2855 child
->MacSuperChangedPosition() ;
2856 node
= node
->GetNext();
2860 void wxWindowMac::MacTopLevelWindowChangedPosition()
2862 // only screen-absolute structures have to be moved i.e. glcanvas
2864 wxWindowListNode
*node
= GetChildren().GetFirst();
2867 wxWindowMac
*child
= node
->GetData();
2868 child
->MacTopLevelWindowChangedPosition() ;
2869 node
= node
->GetNext();
2873 long wxWindowMac::MacGetLeftBorderSize( ) const
2878 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2881 #if wxMAC_USE_THEME_BORDER
2882 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2886 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2889 #if wxMAC_USE_THEME_BORDER
2890 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2894 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2901 long wxWindowMac::MacGetRightBorderSize( ) const
2903 // they are all symmetric in mac themes
2904 return MacGetLeftBorderSize() ;
2907 long wxWindowMac::MacGetTopBorderSize( ) const
2909 // they are all symmetric in mac themes
2910 return MacGetLeftBorderSize() ;
2913 long wxWindowMac::MacGetBottomBorderSize( ) const
2915 // they are all symmetric in mac themes
2916 return MacGetLeftBorderSize() ;
2919 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2921 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2924 // Find the wxWindowMac at the current mouse position, returning the mouse
2926 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2928 pt
= wxGetMousePosition();
2929 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2933 // Get the current mouse position.
2934 wxPoint
wxGetMousePosition()
2937 wxGetMousePosition(& x
, & y
);
2938 return wxPoint(x
, y
);
2941 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2943 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2945 // copied from wxGTK : CS
2946 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2949 // (a) it's a command event and so is propagated to the parent
2950 // (b) under MSW it can be generated from kbd too
2951 // (c) it uses screen coords (because of (a))
2952 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2954 this->ClientToScreen(event
.GetPosition()));
2955 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2964 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2968 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2972 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2973 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2977 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2979 return eventNotHandledErr
;