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 } ;
1049 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1055 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1058 int& w
, int& h
, bool adjustOrigin
) const
1062 // todo the default calls may be used as soon as PostCreateControl Is moved here
1063 w
= size
.x
; // WidthDefault( size.x );
1064 h
= size
.y
; // HeightDefault( size.y ) ;
1065 #if !TARGET_API_MAC_OSX
1066 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1069 AdjustForParentClientOrigin( x
, y
) ;
1074 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1076 #if TARGET_API_MAC_OSX
1077 int x1
, y1
, w1
,h1
;
1078 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1084 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1085 if(x
) *x
= bounds
.right
- bounds
.left
;
1086 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1090 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1092 #if TARGET_API_MAC_OSX
1093 int x1
, y1
, w1
,h1
;
1094 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1095 if ( !IsTopLevel() )
1097 wxWindow
*parent
= GetParent();
1100 wxPoint
pt(parent
->GetClientAreaOrigin());
1109 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1110 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1112 int xx
= bounds
.left
;
1113 int yy
= bounds
.top
;
1115 if ( !GetParent()->IsTopLevel() )
1117 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1123 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1132 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1134 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1136 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1139 Point localwhere
= {0,0} ;
1141 if(x
) localwhere
.h
= * x
;
1142 if(y
) localwhere
.v
= * y
;
1144 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1145 if(x
) *x
= localwhere
.h
;
1146 if(y
) *y
= localwhere
.v
;
1149 MacRootWindowToWindow( x
, y
) ;
1151 wxPoint origin
= GetClientAreaOrigin() ;
1152 if(x
) *x
-= origin
.x
;
1153 if(y
) *y
-= origin
.y
;
1156 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1158 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1159 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1161 wxPoint origin
= GetClientAreaOrigin() ;
1162 if(x
) *x
+= origin
.x
;
1163 if(y
) *y
+= origin
.y
;
1165 MacWindowToRootWindow( x
, y
) ;
1168 Point localwhere
= { 0,0 };
1169 if(x
) localwhere
.h
= * x
;
1170 if(y
) localwhere
.v
= * y
;
1171 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1172 if(x
) *x
= localwhere
.h
;
1173 if(y
) *y
= localwhere
.v
;
1177 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1179 wxPoint origin
= GetClientAreaOrigin() ;
1180 if(x
) *x
+= origin
.x
;
1181 if(y
) *y
+= origin
.y
;
1183 MacWindowToRootWindow( x
, y
) ;
1186 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1188 MacRootWindowToWindow( x
, y
) ;
1190 wxPoint origin
= GetClientAreaOrigin() ;
1191 if(x
) *x
-= origin
.x
;
1192 if(y
) *y
-= origin
.y
;
1195 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1197 #if TARGET_API_MAC_OSX
1199 if ( x
) pt
.x
= *x
;
1200 if ( y
) pt
.y
= *y
;
1202 if ( !IsTopLevel() )
1203 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1205 if ( x
) *x
= (int) pt
.x
;
1206 if ( y
) *y
= (int) pt
.y
;
1208 if ( !IsTopLevel() )
1211 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1212 if(x
) *x
+= bounds
.left
;
1213 if(y
) *y
+= bounds
.top
;
1218 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1223 MacWindowToRootWindow( &x1
, &y1
) ;
1228 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1230 #if TARGET_API_MAC_OSX
1232 if ( x
) pt
.x
= *x
;
1233 if ( y
) pt
.y
= *y
;
1235 if ( !IsTopLevel() )
1236 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1238 if ( x
) *x
= (int) pt
.x
;
1239 if ( y
) *y
= (int) pt
.y
;
1241 if ( !IsTopLevel() )
1244 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1245 if(x
) *x
-= bounds
.left
;
1246 if(y
) *y
-= bounds
.top
;
1251 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1256 MacRootWindowToWindow( &x1
, &y1
) ;
1261 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1263 RgnHandle rgn
= NewRgn() ;
1265 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1267 GetRegionBounds( rgn
, &content
) ;
1272 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1275 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1276 #if !TARGET_API_MAC_OSX
1277 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1279 left
= content
.left
- structure
.left
;
1280 top
= content
.top
- structure
.top
;
1281 right
= structure
.right
- content
.right
;
1282 bottom
= structure
.bottom
- content
.bottom
;
1285 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1287 wxSize sizeTotal
= size
;
1289 RgnHandle rgn
= NewRgn() ;
1293 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1295 GetRegionBounds( rgn
, &content
) ;
1300 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1303 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1304 #if !TARGET_API_MAC_OSX
1305 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1308 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1309 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1311 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1312 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1318 // Get size *available for subwindows* i.e. excluding menu bar etc.
1319 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1323 RgnHandle rgn
= NewRgn() ;
1325 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1327 GetRegionBounds( rgn
, &content
) ;
1332 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1334 #if !TARGET_API_MAC_OSX
1336 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1337 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1339 ww
= content
.right
- content
.left
;
1340 hh
= content
.bottom
- content
.top
;
1342 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1343 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1345 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1351 GetSize( &w
, &h
) ;
1353 MacClientToRootWindow( &x1
, &y1
) ;
1354 MacClientToRootWindow( &w
, &h
) ;
1356 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1358 int totW
= 10000 , totH
= 10000;
1361 if ( iter
->IsTopLevel() )
1363 iter
->GetSize( &totW
, &totH
) ;
1367 iter
= iter
->GetParent() ;
1370 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1372 hh
-= MAC_SCROLLBAR_SIZE
;
1378 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1380 ww
-= MAC_SCROLLBAR_SIZE
;
1392 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1394 if (m_cursor
== cursor
)
1397 if (wxNullCursor
== cursor
)
1399 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1404 if ( ! wxWindowBase::SetCursor( cursor
) )
1408 wxASSERT_MSG( m_cursor
.Ok(),
1409 wxT("cursor must be valid after call to the base version"));
1413 TODO why do we have to use current coordinates ?
1416 wxWindowMac *mouseWin ;
1419 // Change the cursor NOW if we're within the correct window
1422 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1424 if ( mouseWin == this && !wxIsBusy() )
1426 m_cursor.MacInstall() ;
1432 m_cursor
.MacInstall() ;
1439 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1441 menu
->SetInvokingWindow(this);
1443 ClientToScreen( &x
, &y
) ;
1445 menu
->MacBeforeDisplay( true ) ;
1446 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1447 if ( HiWord(menuResult
) != 0 )
1450 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1451 wxMenuItem
* item
= NULL
;
1453 item
= menu
->FindItem(id
, &realmenu
) ;
1454 if (item
->IsCheckable())
1456 item
->Check( !item
->IsChecked() ) ;
1458 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1460 menu
->MacAfterDisplay( true ) ;
1462 menu
->SetInvokingWindow(NULL
);
1468 // ----------------------------------------------------------------------------
1470 // ----------------------------------------------------------------------------
1474 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1476 wxWindowBase::DoSetToolTip(tooltip
);
1479 m_tooltip
->SetWindow(this);
1482 #endif // wxUSE_TOOLTIPS
1484 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1486 int former_x
, former_y
, former_w
, former_h
;
1487 #if !TARGET_API_MAC_OSX
1488 DoGetPosition( &former_x
, &former_y
) ;
1489 DoGetSize( &former_w
, &former_h
) ;
1491 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1494 int actualWidth
= width
;
1495 int actualHeight
= height
;
1499 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1500 actualWidth
= m_minWidth
;
1501 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1502 actualHeight
= m_minHeight
;
1503 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1504 actualWidth
= m_maxWidth
;
1505 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1506 actualHeight
= m_maxHeight
;
1508 bool doMove
= false ;
1509 bool doResize
= false ;
1511 if ( actualX
!= former_x
|| actualY
!= former_y
)
1515 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1520 if ( doMove
|| doResize
)
1522 // we don't adjust twice for the origin
1523 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1524 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1525 #if TARGET_API_MAC_OSX
1526 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1528 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1529 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1530 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1532 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1535 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1536 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1538 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1540 MacRepositionScrollBars() ;
1543 wxPoint
point(actualX
,actualY
);
1544 wxMoveEvent
event(point
, m_windowId
);
1545 event
.SetEventObject(this);
1546 GetEventHandler()->ProcessEvent(event
) ;
1550 MacRepositionScrollBars() ;
1551 wxSize
size(actualWidth
, actualHeight
);
1552 wxSizeEvent
event(size
, m_windowId
);
1553 event
.SetEventObject(this);
1554 GetEventHandler()->ProcessEvent(event
);
1560 wxSize
wxWindowMac::DoGetBestSize() const
1562 if ( m_macIsUserPane
|| IsTopLevel() )
1563 return wxWindowBase::DoGetBestSize() ;
1565 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1566 short baselineoffset
;
1567 int bestWidth
, bestHeight
;
1568 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1570 if ( EmptyRect( &bestsize
) )
1573 bestsize
.left
= bestsize
.top
= 0 ;
1574 bestsize
.right
= 16 ;
1575 bestsize
.bottom
= 16 ;
1576 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1578 bestsize
.bottom
= 16 ;
1580 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1582 bestsize
.bottom
= 24 ;
1586 // return wxWindowBase::DoGetBestSize() ;
1590 bestWidth
= bestsize
.right
- bestsize
.left
;
1591 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1592 if ( bestHeight
< 10 )
1595 return wxSize(bestWidth
, bestHeight
);
1596 // return wxWindowBase::DoGetBestSize() ;
1600 // set the size of the window: if the dimensions are positive, just use them,
1601 // but if any of them is equal to -1, it means that we must find the value for
1602 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1603 // which case -1 is a valid value for x and y)
1605 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1606 // the width/height to best suit our contents, otherwise we reuse the current
1608 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1610 // get the current size and position...
1611 int currentX
, currentY
;
1612 GetPosition(¤tX
, ¤tY
);
1614 int currentW
,currentH
;
1615 GetSize(¤tW
, ¤tH
);
1617 // ... and don't do anything (avoiding flicker) if it's already ok
1618 if ( x
== currentX
&& y
== currentY
&&
1619 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1622 MacRepositionScrollBars() ; // we might have a real position shift
1626 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1628 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1631 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1633 wxSize
size(-1, -1);
1636 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1638 size
= DoGetBestSize();
1643 // just take the current one
1650 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1654 size
= DoGetBestSize();
1656 //else: already called DoGetBestSize() above
1662 // just take the current one
1667 DoMoveWindow(x
, y
, width
, height
);
1671 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1673 RgnHandle rgn
= NewRgn() ;
1675 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1676 GetRegionBounds( rgn
, &content
) ;
1678 #if !TARGET_API_MAC_OSX
1679 // if the content rgn is empty / not supported
1680 // don't attempt to correct the coordinates to wxWindow relative ones
1681 if (!::EmptyRect( &content
) )
1684 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1685 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1689 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1692 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1694 if ( clientheight
!= -1 || clientheight
!= -1 )
1696 int currentclientwidth
, currentclientheight
;
1697 int currentwidth
, currentheight
;
1699 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1700 GetSize( ¤twidth
, ¤theight
) ;
1702 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1703 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1707 void wxWindowMac::SetTitle(const wxString
& title
)
1709 m_label
= wxStripMenuCodes(title
) ;
1713 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1718 wxString
wxWindowMac::GetTitle() const
1723 bool wxWindowMac::Show(bool show
)
1725 if ( !wxWindowBase::Show(show
) )
1728 // TODO use visibilityChanged Carbon Event for OSX
1729 bool former
= MacIsReallyShown() ;
1731 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1732 if ( former
!= MacIsReallyShown() )
1733 MacPropagateVisibilityChanged() ;
1737 bool wxWindowMac::Enable(bool enable
)
1739 wxASSERT( m_macControl
!= NULL
) ;
1740 if ( !wxWindowBase::Enable(enable
) )
1743 bool former
= MacIsReallyEnabled() ;
1744 #if TARGET_API_MAC_OSX
1746 EnableControl( (ControlRef
) m_macControl
) ;
1748 DisableControl( (ControlRef
) m_macControl
) ;
1751 ActivateControl( (ControlRef
) m_macControl
) ;
1753 DeactivateControl( (ControlRef
) m_macControl
) ;
1756 if ( former
!= MacIsReallyEnabled() )
1757 MacPropagateEnabledStateChanged() ;
1762 // status change propagations (will be not necessary for OSX later )
1765 void wxWindowMac::MacPropagateVisibilityChanged()
1767 #if !TARGET_API_MAC_OSX
1768 MacVisibilityChanged() ;
1770 wxWindowListNode
*node
= GetChildren().GetFirst();
1773 wxWindowMac
*child
= node
->GetData();
1774 if ( child
->IsShown() )
1775 child
->MacPropagateVisibilityChanged( ) ;
1776 node
= node
->GetNext();
1781 void wxWindowMac::MacPropagateEnabledStateChanged( )
1783 #if !TARGET_API_MAC_OSX
1784 MacEnabledStateChanged() ;
1786 wxWindowListNode
*node
= GetChildren().GetFirst();
1789 wxWindowMac
*child
= node
->GetData();
1790 if ( child
->IsEnabled() )
1791 child
->MacPropagateEnabledStateChanged() ;
1792 node
= node
->GetNext();
1797 void wxWindowMac::MacPropagateHiliteChanged( )
1799 #if !TARGET_API_MAC_OSX
1800 MacHiliteChanged() ;
1802 wxWindowListNode
*node
= GetChildren().GetFirst();
1805 wxWindowMac
*child
= node
->GetData();
1806 // if ( child->IsEnabled() )
1807 child
->MacPropagateHiliteChanged() ;
1808 node
= node
->GetNext();
1814 // status change notifications
1817 void wxWindowMac::MacVisibilityChanged()
1821 void wxWindowMac::MacHiliteChanged()
1825 void wxWindowMac::MacEnabledStateChanged()
1830 // status queries on the inherited window's state
1833 bool wxWindowMac::MacIsReallyShown()
1835 // only under OSX the visibility of the TLW is taken into account
1836 #if TARGET_API_MAC_OSX
1837 return IsControlVisible( (ControlRef
) m_macControl
) ;
1839 wxWindow
* win
= this ;
1840 while( win
->IsShown() )
1842 if ( win
->IsTopLevel() )
1845 win
= win
->GetParent() ;
1854 bool wxWindowMac::MacIsReallyEnabled()
1856 #if TARGET_API_MAC_OSX
1857 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1859 return IsControlActive( (ControlRef
) m_macControl
) ;
1863 bool wxWindowMac::MacIsReallyHilited()
1865 return IsControlActive( (ControlRef
) m_macControl
) ;
1868 void wxWindowMac::MacFlashInvalidAreas()
1870 #if TARGET_API_MAC_OSX
1871 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1879 int wxWindowMac::GetCharHeight() const
1881 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1882 return dc
.GetCharHeight() ;
1885 int wxWindowMac::GetCharWidth() const
1887 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1888 return dc
.GetCharWidth() ;
1891 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1892 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1894 const wxFont
*fontToUse
= theFont
;
1896 fontToUse
= &m_font
;
1898 wxClientDC
dc( (wxWindowMac
*) this ) ;
1900 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1901 if ( externalLeading
)
1902 *externalLeading
= le
;
1912 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1913 * we always intersect with the entire window, not only with the client area
1916 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1918 #if TARGET_API_MAC_OSX
1920 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1923 RgnHandle update
= NewRgn() ;
1924 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1925 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1926 wxPoint origin
= GetClientAreaOrigin() ;
1927 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1928 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1932 RgnHandle updateRgn = NewRgn() ;
1935 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1939 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1940 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1942 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1943 DisposeRgn(updateRgn) ;
1945 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1947 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1948 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1951 if ( MacGetTopLevelWindow() == NULL )
1954 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1957 wxPoint client = GetClientAreaOrigin();
1960 int x2 = m_width - client.x;
1961 int y2 = m_height - client.y;
1963 if (IsKindOf( CLASSINFO(wxButton)))
1965 // buttons have an "aura"
1972 Rect clientrect = { y1, x1, y2, x2 };
1976 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1977 SectRect( &clientrect , &r , &clientrect ) ;
1980 if ( !EmptyRect( &clientrect ) )
1982 int top = 0 , left = 0 ;
1984 MacClientToRootWindow( &left , &top ) ;
1985 OffsetRect( &clientrect , left , top ) ;
1987 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1993 void wxWindowMac::Freeze()
1995 #if TARGET_API_MAC_OSX
1996 if ( !m_frozenness
++ )
1998 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
2003 #if TARGET_API_MAC_OSX
2004 static void InvalidateControlAndChildren( HIViewRef control
)
2006 HIViewSetNeedsDisplay( control
, true ) ;
2007 UInt16 childrenCount
= 0 ;
2008 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2009 if ( err
== errControlIsNotEmbedder
)
2011 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2013 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2016 err
= GetIndexedSubControl( control
, i
, & child
) ;
2017 if ( err
== errControlIsNotEmbedder
)
2019 InvalidateControlAndChildren( child
) ;
2024 void wxWindowMac::Thaw()
2026 #if TARGET_API_MAC_OSX
2027 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2029 if ( !--m_frozenness
)
2031 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2032 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2033 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2038 void wxWindowMac::MacRedrawControl()
2041 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2043 #if TARGET_API_MAC_CARBON
2046 wxClientDC dc(this) ;
2047 wxMacPortSetter helper(&dc) ;
2048 wxMacWindowClipper clipper(this) ;
2049 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2050 UMADrawControl( (ControlRef) m_macControl ) ;
2057 void wxWindowMac::OnPaint(wxPaintEvent& event)
2059 // why don't we skip that here ?
2063 wxWindowMac
*wxGetActiveWindow()
2065 // actually this is a windows-only concept
2069 // Coordinates relative to the window
2070 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2072 // We really don't move the mouse programmatically under Mac.
2075 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2077 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2082 event
.GetDC()->Clear() ;
2085 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2087 wxWindowDC
dc(this) ;
2088 wxMacPortSetter
helper(&dc
) ;
2090 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2093 int wxWindowMac::GetScrollPos(int orient
) const
2095 if ( orient
== wxHORIZONTAL
)
2098 return m_hScrollBar
->GetThumbPosition() ;
2103 return m_vScrollBar
->GetThumbPosition() ;
2108 // This now returns the whole range, not just the number
2109 // of positions that we can scroll.
2110 int wxWindowMac::GetScrollRange(int orient
) const
2112 if ( orient
== wxHORIZONTAL
)
2115 return m_hScrollBar
->GetRange() ;
2120 return m_vScrollBar
->GetRange() ;
2125 int wxWindowMac::GetScrollThumb(int orient
) const
2127 if ( orient
== wxHORIZONTAL
)
2130 return m_hScrollBar
->GetThumbSize() ;
2135 return m_vScrollBar
->GetThumbSize() ;
2140 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2142 if ( orient
== wxHORIZONTAL
)
2145 m_hScrollBar
->SetThumbPosition( pos
) ;
2150 m_vScrollBar
->SetThumbPosition( pos
) ;
2154 void wxWindowMac::MacPaintBorders( int left
, int top
)
2160 wxGetOsVersion( &major
, &minor
);
2162 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2163 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2165 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2166 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2167 // OS X has lighter border edges than classic:
2170 darkShadow
.red
= 0x8E8E;
2171 darkShadow
.green
= 0x8E8E;
2172 darkShadow
.blue
= 0x8E8E;
2173 lightShadow
.red
= 0xBDBD;
2174 lightShadow
.green
= 0xBDBD;
2175 lightShadow
.blue
= 0xBDBD;
2181 GetSize( &w
, &h
) ;
2182 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2184 #if wxMAC_USE_THEME_BORDER
2185 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2188 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2189 InsetRect( &rect , border , border );
2190 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2193 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2195 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2196 RGBForeColor( &face
);
2197 MoveTo( left
+ 0 , top
+ h
- 2 );
2198 LineTo( left
+ 0 , top
+ 0 );
2199 LineTo( left
+ w
- 2 , top
+ 0 );
2201 MoveTo( left
+ 2 , top
+ h
- 3 );
2202 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2203 LineTo( left
+ w
- 3 , top
+ 2 );
2205 RGBForeColor( sunken
? &face
: &darkShadow
);
2206 MoveTo( left
+ 0 , top
+ h
- 1 );
2207 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2208 LineTo( left
+ w
- 1 , top
+ 0 );
2210 RGBForeColor( sunken
? &lightShadow
: &white
);
2211 MoveTo( left
+ 1 , top
+ h
- 3 );
2212 LineTo( left
+ 1, top
+ 1 );
2213 LineTo( left
+ w
- 3 , top
+ 1 );
2215 RGBForeColor( sunken
? &white
: &lightShadow
);
2216 MoveTo( left
+ 1 , top
+ h
- 2 );
2217 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2218 LineTo( left
+ w
- 2 , top
+ 1 );
2220 RGBForeColor( sunken
? &darkShadow
: &face
);
2221 MoveTo( left
+ 2 , top
+ h
- 4 );
2222 LineTo( left
+ 2 , top
+ 2 );
2223 LineTo( left
+ w
- 4 , top
+ 2 );
2226 else if (HasFlag(wxSIMPLE_BORDER
))
2228 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2229 RGBForeColor( &darkShadow
) ;
2230 FrameRect( &rect
) ;
2234 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2236 if ( child
== m_hScrollBar
)
2237 m_hScrollBar
= NULL
;
2238 if ( child
== m_vScrollBar
)
2239 m_vScrollBar
= NULL
;
2241 wxWindowBase::RemoveChild( child
) ;
2244 // New function that will replace some of the above.
2245 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2246 int range
, bool refresh
)
2248 if ( orient
== wxHORIZONTAL
)
2252 if ( range
== 0 || thumbVisible
>= range
)
2254 if ( m_hScrollBar
->IsShown() )
2255 m_hScrollBar
->Show(false) ;
2259 if ( !m_hScrollBar
->IsShown() )
2260 m_hScrollBar
->Show(true) ;
2261 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2269 if ( range
== 0 || thumbVisible
>= range
)
2271 if ( m_vScrollBar
->IsShown() )
2272 m_vScrollBar
->Show(false) ;
2276 if ( !m_vScrollBar
->IsShown() )
2277 m_vScrollBar
->Show(true) ;
2278 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2282 MacRepositionScrollBars() ;
2285 // Does a physical scroll
2286 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2288 if( dx
== 0 && dy
==0 )
2294 int width
, height
;
2295 GetClientSize( &width
, &height
) ;
2296 #if TARGET_API_MAC_OSX
2297 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2298 // area is scrolled, this does not occur if width and height are 2 pixels less,
2299 // TODO write optimal workaround
2300 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2303 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2304 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2306 if ( HIViewGetNeedsDisplay( (ControlRef
) m_macControl
) )
2308 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2309 // either immediate redraw or full invalidate
2311 // is the better overall solution, as it does not slow down scrolling
2312 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2314 // this would be the preferred version for fast drawing controls
2315 if( UMAGetSystemVersion() < 0x1030 )
2318 HIViewRender((ControlRef
) m_macControl
) ;
2321 HIViewScrollRect ( (ControlRef
) m_macControl
, &scrollrect
, dx
,dy
) ;
2328 RgnHandle updateRgn
= NewRgn() ;
2331 wxClientDC
dc(this) ;
2332 wxMacPortSetter
helper(&dc
) ;
2334 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2335 scrollrect
.top
+= MacGetTopBorderSize() ;
2336 scrollrect
.left
+= MacGetLeftBorderSize() ;
2337 scrollrect
.bottom
= scrollrect
.top
+ height
;
2338 scrollrect
.right
= scrollrect
.left
+ width
;
2342 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2343 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2344 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2346 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2348 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2352 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2354 wxWindowMac
*child
= node
->GetData();
2355 if (child
== m_vScrollBar
) continue;
2356 if (child
== m_hScrollBar
) continue;
2357 if (child
->IsTopLevel()) continue;
2360 child
->GetPosition( &x
, &y
);
2362 child
->GetSize( &w
, &h
);
2366 if (rect
->Intersects(rc
))
2367 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2371 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2376 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2378 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2380 wxScrollWinEvent wevent
;
2381 wevent
.SetPosition(event
.GetPosition());
2382 wevent
.SetOrientation(event
.GetOrientation());
2383 wevent
.m_eventObject
= this;
2385 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2386 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2387 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2388 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2389 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2390 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2391 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2392 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2393 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2394 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2395 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2396 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2397 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2398 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2399 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2400 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2402 GetEventHandler()->ProcessEvent(wevent
);
2406 // Get the window with the focus
2407 wxWindowMac
*wxWindowBase::FindFocus()
2409 ControlRef control
;
2410 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2411 return wxFindControlFromMacControl( control
) ;
2414 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2416 // panel wants to track the window which was the last to have focus in it,
2417 // so we want to set ourselves as the window which last had focus
2419 // notice that it's also important to do it upwards the tree becaus
2420 // otherwise when the top level panel gets focus, it won't set it back to
2421 // us, but to some other sibling
2423 // CS:don't know if this is still needed:
2424 //wxChildFocusEvent eventFocus(this);
2425 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2430 void wxWindowMac::OnInternalIdle()
2432 // This calls the UI-update mechanism (querying windows for
2433 // menu/toolbar/control state information)
2434 if (wxUpdateUIEvent::CanUpdate(this))
2435 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2438 // Raise the window to the top of the Z order
2439 void wxWindowMac::Raise()
2441 #if TARGET_API_MAC_OSX
2442 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2446 // Lower the window to the bottom of the Z order
2447 void wxWindowMac::Lower()
2449 #if TARGET_API_MAC_OSX
2450 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2455 // static wxWindow *gs_lastWhich = NULL;
2457 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2459 // first trigger a set cursor event
2461 wxPoint clientorigin
= GetClientAreaOrigin() ;
2462 wxSize clientsize
= GetClientSize() ;
2464 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2466 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2468 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2469 if ( processedEvtSetCursor
&& event
.HasCursor() )
2471 cursor
= event
.GetCursor() ;
2476 // the test for processedEvtSetCursor is here to prevent using m_cursor
2477 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2478 // it - this is a way to say that our cursor shouldn't be used for this
2480 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2490 cursor
= *wxSTANDARD_CURSOR
;
2494 cursor
.MacInstall() ;
2496 return cursor
.Ok() ;
2499 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2503 return m_tooltip
->GetTip() ;
2505 return wxEmptyString
;
2508 void wxWindowMac::Update()
2510 #if TARGET_API_MAC_OSX
2511 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2512 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2513 // for composited windows this also triggers a redraw of all
2514 // invalid views in the window
2515 if( UMAGetSystemVersion() >= 0x1030 )
2516 HIWindowFlush(window
) ;
2520 // the only way to trigger the redrawing on earlier systems is to call
2523 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2524 UInt32 currentEventClass
= 0 ;
2525 UInt32 currentEventKind
= 0 ;
2526 if ( currentEvent
!= NULL
)
2528 currentEventClass
= ::GetEventClass( currentEvent
) ;
2529 currentEventKind
= ::GetEventKind( currentEvent
) ;
2531 if ( currentEventClass
!= kEventClassMenu
)
2533 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2536 OSStatus status
= noErr
;
2537 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2540 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2543 ::Draw1Control( (ControlRef
) m_macControl
) ;
2547 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2549 wxTopLevelWindowMac
* win
= NULL
;
2550 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2553 win
= wxFindWinFromMacWindow( window
) ;
2557 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2561 RgnHandle visRgn
= NewRgn() ;
2562 RgnHandle tempRgn
= NewRgn() ;
2563 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2565 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2566 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2568 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2569 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2578 if ( includeOuterStructures
)
2579 InsetRect( &r
, -3 , -3 ) ;
2580 RectRgn( visRgn
, &r
) ;
2581 if ( !IsTopLevel() )
2583 wxWindow
* child
= this ;
2584 wxWindow
* parent
= child
->GetParent() ;
2589 // we have to find a better clipping algorithm here, in order not to clip things
2590 // positioned like status and toolbar
2591 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2593 size
= parent
->GetSize() ;
2598 size
= parent
->GetClientSize() ;
2599 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2603 parent
->MacWindowToRootWindow( &x
, &y
) ;
2604 MacRootWindowToWindow( &x
, &y
) ;
2606 SetRectRgn( tempRgn
,
2607 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2608 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2609 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2611 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2612 if ( parent
->IsTopLevel() )
2615 parent
= child
->GetParent() ;
2620 wxRegion vis
= visRgn
;
2621 DisposeRgn( visRgn
) ;
2622 DisposeRgn( tempRgn
) ;
2627 This function must not change the updatergn !
2629 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2631 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2632 bool handled
= false ;
2634 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2636 RgnHandle newupdate
= NewRgn() ;
2637 wxSize point
= GetClientSize() ;
2638 wxPoint origin
= GetClientAreaOrigin() ;
2639 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2640 SectRgn( newupdate
, updatergn
, newupdate
) ;
2641 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2642 m_updateRegion
= newupdate
;
2643 DisposeRgn( newupdate
) ;
2646 if ( !EmptyRgn(updatergn
) )
2648 wxWindowDC
dc(this);
2649 if (!EmptyRgn(updatergn
))
2650 dc
.SetClippingRegion(wxRegion(updatergn
));
2652 wxEraseEvent
eevent( GetId(), &dc
);
2653 eevent
.SetEventObject( this );
2654 GetEventHandler()->ProcessEvent( eevent
);
2656 if ( !m_updateRegion
.Empty() )
2658 // paint the window itself
2660 event
.m_timeStamp
= time
;
2661 event
.SetEventObject(this);
2662 handled
= GetEventHandler()->ProcessEvent(event
);
2664 // paint custom borders
2665 wxNcPaintEvent
eventNc( GetId() );
2666 eventNc
.SetEventObject( this );
2667 GetEventHandler()->ProcessEvent( eventNc
);
2673 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2675 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2676 // updatergn is always already clipped to our boundaries
2677 // if we are in compositing mode then it is in relative to the upper left of the control
2678 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2679 // of the toplevel window
2680 // it is in window coordinates, not in client coordinates
2682 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2683 RgnHandle ownUpdateRgn
= NewRgn() ;
2684 CopyRgn( updatergn
, ownUpdateRgn
) ;
2686 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2689 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2690 RgnHandle controlRgn
= NewRgn();
2691 RectRgn( controlRgn
, &bounds
);
2692 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2693 // the window update region
2694 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2695 DisposeRgn( controlRgn
);
2697 //KO: convert ownUpdateRgn to local coordinates
2698 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2701 MacDoRedraw( ownUpdateRgn
, time
) ;
2702 DisposeRgn( ownUpdateRgn
) ;
2706 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2708 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2712 if ( iter
->IsTopLevel() )
2713 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2715 iter
= iter
->GetParent() ;
2717 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2721 void wxWindowMac::MacCreateScrollBars( long style
)
2723 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2725 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2726 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2728 GetClientSize( &width
, &height
) ;
2730 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2731 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2732 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2733 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2735 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2736 vSize
, wxVERTICAL
);
2738 if ( style
& wxVSCROLL
)
2744 m_vScrollBar
->Show(false) ;
2746 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2747 hSize
, wxHORIZONTAL
);
2748 if ( style
& wxHSCROLL
)
2753 m_hScrollBar
->Show(false) ;
2756 // because the create does not take into account the client area origin
2757 MacRepositionScrollBars() ; // we might have a real position shift
2760 void wxWindowMac::MacRepositionScrollBars()
2762 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2763 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2765 // get real client area
2769 GetSize( &width
, &height
) ;
2771 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2772 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2774 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2775 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2776 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2777 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2783 GetSize( &w
, &h
) ;
2785 MacClientToRootWindow( &x
, &y
) ;
2786 MacClientToRootWindow( &w
, &h
) ;
2788 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2790 int totW
= 10000 , totH
= 10000;
2793 if ( iter
->IsTopLevel() )
2795 iter
->GetSize( &totW
, &totH
) ;
2799 iter
= iter
->GetParent() ;
2827 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2831 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2835 bool wxWindowMac::AcceptsFocus() const
2837 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2840 void wxWindowMac::MacSuperChangedPosition()
2842 // only window-absolute structures have to be moved i.e. controls
2844 wxWindowListNode
*node
= GetChildren().GetFirst();
2847 wxWindowMac
*child
= node
->GetData();
2848 child
->MacSuperChangedPosition() ;
2849 node
= node
->GetNext();
2853 void wxWindowMac::MacTopLevelWindowChangedPosition()
2855 // only screen-absolute structures have to be moved i.e. glcanvas
2857 wxWindowListNode
*node
= GetChildren().GetFirst();
2860 wxWindowMac
*child
= node
->GetData();
2861 child
->MacTopLevelWindowChangedPosition() ;
2862 node
= node
->GetNext();
2866 long wxWindowMac::MacGetLeftBorderSize( ) const
2871 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2874 #if wxMAC_USE_THEME_BORDER
2875 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2879 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2882 #if wxMAC_USE_THEME_BORDER
2883 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2887 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2894 long wxWindowMac::MacGetRightBorderSize( ) const
2896 // they are all symmetric in mac themes
2897 return MacGetLeftBorderSize() ;
2900 long wxWindowMac::MacGetTopBorderSize( ) const
2902 // they are all symmetric in mac themes
2903 return MacGetLeftBorderSize() ;
2906 long wxWindowMac::MacGetBottomBorderSize( ) const
2908 // they are all symmetric in mac themes
2909 return MacGetLeftBorderSize() ;
2912 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2914 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2917 // Find the wxWindowMac at the current mouse position, returning the mouse
2919 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2921 pt
= wxGetMousePosition();
2922 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2926 // Get the current mouse position.
2927 wxPoint
wxGetMousePosition()
2930 wxGetMousePosition(& x
, & y
);
2931 return wxPoint(x
, y
);
2934 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2936 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2938 // copied from wxGTK : CS
2939 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2942 // (a) it's a command event and so is propagated to the parent
2943 // (b) under MSW it can be generated from kbd too
2944 // (c) it uses screen coords (because of (a))
2945 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2947 this->ClientToScreen(event
.GetPosition()));
2948 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2957 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2961 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2965 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2966 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2970 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2972 return eventNotHandledErr
;