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>
57 #if TARGET_API_MAC_OSX
59 #include <HIToolbox/HIView.h>
63 #if wxUSE_DRAG_AND_DROP
69 extern wxList wxPendingDelete
;
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
75 #endif // __WXUNIVERSAL__/__WXMAC__
77 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 // TODO EVT_PAINT(wxWindowMac::OnPaint)
83 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
85 // EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 0
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
103 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
105 #if TARGET_API_MAC_OSX
107 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
109 kEventControlVisibilityChanged
= 157
115 static const EventTypeSpec eventList
[] =
117 { kEventClassControl
, kEventControlHit
} ,
118 #if TARGET_API_MAC_OSX
119 { kEventClassControl
, kEventControlDraw
} ,
120 { kEventClassControl
, kEventControlVisibilityChanged
} ,
121 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
122 { kEventClassControl
, kEventControlHiliteChanged
} ,
123 { kEventClassControl
, kEventControlSetFocusPart
} ,
125 { kEventClassService
, kEventServiceGetTypes
},
126 { kEventClassService
, kEventServiceCopy
},
127 { kEventClassService
, kEventServicePaste
},
129 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
130 // { kEventClassControl , kEventControlBoundsChanged } ,
134 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
136 OSStatus result
= eventNotHandledErr
;
138 wxMacCarbonEvent
cEvent( event
) ;
140 ControlRef controlRef
;
141 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
143 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
145 switch( GetEventKind( event
) )
147 #if TARGET_API_MAC_OSX
148 case kEventControlDraw
:
150 RgnHandle updateRgn
= NULL
;
152 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
153 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
155 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
157 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
160 // in case we would need a coregraphics compliant background erase first
161 // now usable to track redraws
162 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
163 if ( thisWindow
->MacIsUserPane() )
165 static float color
= 0.5 ;
168 HIViewGetBounds( controlRef
, &bounds
);
169 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
170 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
171 CGContextFillRect( cgContext
, bounds
);
182 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
186 case kEventControlVisibilityChanged
:
187 thisWindow
->MacVisibilityChanged() ;
189 case kEventControlEnabledStateChanged
:
190 thisWindow
->MacEnabledStateChanged() ;
192 case kEventControlHiliteChanged
:
193 thisWindow
->MacHiliteChanged() ;
195 case kEventControlSetFocusPart
:
197 Boolean focusEverything
= false ;
198 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
199 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
202 if ( controlPart
== kControlFocusNoPart
)
205 if ( thisWindow
->GetCaret() )
207 thisWindow
->GetCaret()->OnKillFocus();
209 #endif // wxUSE_CARET
210 wxFocusEvent
event(wxEVT_KILL_FOCUS
, thisWindow
->GetId());
211 event
.SetEventObject(thisWindow
);
212 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
213 if (thisWindow
->MacIsUserPane())
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
) ;
232 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 ;
313 textCtrl
->WriteText( wxString( content
) ) ;
323 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
325 OSStatus result
= eventNotHandledErr
;
327 switch ( GetEventClass( event
) )
329 case kEventClassControl
:
330 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
332 case kEventClassService
:
333 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
340 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
342 // ---------------------------------------------------------------------------
343 // UserPane events for non OSX builds
344 // ---------------------------------------------------------------------------
346 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
348 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
349 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
350 win
->MacControlUserPaneDrawProc(part
) ;
353 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
355 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
356 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
357 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
360 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
362 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
363 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
364 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
367 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
369 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
370 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
371 win
->MacControlUserPaneIdleProc() ;
374 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
376 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
377 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
378 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
381 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
383 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
384 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
385 win
->MacControlUserPaneActivateProc(activating
) ;
388 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
390 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
391 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
392 return win
->MacControlUserPaneFocusProc(action
) ;
395 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
397 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
398 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
399 win
->MacControlUserPaneBackgroundProc(info
) ;
402 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
404 RgnHandle rgn
= NewRgn() ;
406 wxMacWindowStateSaver
sv( this ) ;
407 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
408 MacDoRedraw( rgn
, 0 ) ;
412 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
414 return kControlNoPart
;
417 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
419 return kControlNoPart
;
422 void wxWindowMac::MacControlUserPaneIdleProc()
426 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
428 return kControlNoPart
;
431 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
435 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
437 return kControlNoPart
;
440 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
444 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
445 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
446 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
447 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
448 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
449 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
450 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
451 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
453 // ===========================================================================
455 // ===========================================================================
457 wxList
wxWinMacControlList(wxKEY_INTEGER
);
459 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
461 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
464 return (wxControl
*)node
->GetData();
467 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
469 // adding NULL ControlRef is (first) surely a result of an error and
470 // (secondly) breaks native event processing
471 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
473 if ( !wxWinMacControlList
.Find((long)inControl
) )
474 wxWinMacControlList
.Append((long)inControl
, control
);
477 void wxRemoveMacControlAssociation(wxWindow
*control
)
479 wxWinMacControlList
.DeleteObject(control
);
483 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
485 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
487 // we have to setup the brush in the current port and return noErr
488 // or return an error code so that the control manager walks further up the
489 // hierarchy to find a correct background
491 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
493 OSStatus status
= paramErr
;
496 case kControlMsgApplyTextColor
:
498 case kControlMsgSetUpBackground
:
500 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
504 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
508 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
510 // this clipping is only needed for non HIView
512 RgnHandle clip
= NewRgn() ;
515 wx
->MacWindowToRootWindow( &x
,&y
) ;
516 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
517 OffsetRgn( clip
, x
, y
) ;
524 else if ( wx->MacIsUserPane() )
526 // if we don't have a valid brush for such a control, we have to call the
527 // setup of our parent ourselves
528 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
541 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
542 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
546 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
549 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
554 // ----------------------------------------------------------------------------
555 // constructors and such
556 // ----------------------------------------------------------------------------
558 void wxWindowMac::Init()
561 #if WXWIN_COMPATIBILITY_2_4
562 m_backgroundTransparent
= FALSE
;
565 // as all windows are created with WS_VISIBLE style...
568 m_hScrollBar
= NULL
;
569 m_vScrollBar
= NULL
;
570 m_macBackgroundBrush
= wxNullBrush
;
572 m_macControl
= NULL
;
574 m_macIsUserPane
= TRUE
;
576 // make sure all proc ptrs are available
578 if ( gControlUserPaneDrawUPP
== NULL
)
580 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
581 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
582 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
583 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
584 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
585 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
586 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
587 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
589 if ( wxMacLiveScrollbarActionUPP
== NULL
)
591 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
594 if ( wxMacSetupControlBackgroundUPP
== NULL
)
596 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
599 // we need a valid font for the encodings
600 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
604 wxWindowMac::~wxWindowMac()
608 m_isBeingDeleted
= TRUE
;
610 #ifndef __WXUNIVERSAL__
611 // VS: make sure there's no wxFrame with last focus set to us:
612 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
614 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
617 if ( frame
->GetLastFocus() == this )
619 frame
->SetLastFocus((wxWindow
*)NULL
);
624 #endif // __WXUNIVERSAL__
626 // wxRemoveMacControlAssociation( this ) ;
627 // If we delete an item, we should initialize the parent panel,
628 // because it could now be invalid.
629 wxWindow
*parent
= GetParent() ;
632 if (parent
->GetDefaultItem() == (wxButton
*) this)
633 parent
->SetDefaultItem(NULL
);
635 if ( (ControlRef
) m_macControl
)
637 // in case the callback might be called during destruction
638 wxRemoveMacControlAssociation( this) ;
639 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
640 ::DisposeControl( (ControlRef
) m_macControl
) ;
641 m_macControl
= NULL
;
644 if ( g_MacLastWindow
== this )
646 g_MacLastWindow
= NULL
;
649 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
652 if ( frame
->GetLastFocus() == this )
653 frame
->SetLastFocus( NULL
) ;
658 // delete our drop target if we've got one
659 #if wxUSE_DRAG_AND_DROP
660 if ( m_dropTarget
!= NULL
)
665 #endif // wxUSE_DRAG_AND_DROP
670 void wxWindowMac::MacInstallEventHandler()
672 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
673 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
674 GetEventTypeCount(eventList
), eventList
, this,
675 (EventHandlerRef
*)&m_macControlEventHandler
);
680 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
684 const wxString
& name
)
686 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
688 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
691 parent
->AddChild(this);
693 m_windowVariant
= parent
->GetWindowVariant() ;
695 if ( m_macIsUserPane
)
697 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
700 | kControlSupportsEmbedding
701 // | kControlSupportsLiveFeedback
702 // | kControlHasSpecialBackground
703 // | kControlSupportsCalcBestRect
704 // | kControlHandlesTracking
705 | kControlSupportsFocus
706 // | kControlWantsActivate
707 // | kControlWantsIdle
710 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
712 MacPostControlCreate(pos
,size
) ;
713 #if !TARGET_API_MAC_OSX
714 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
715 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
716 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
717 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
718 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
719 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
720 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
721 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
722 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
723 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
724 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
725 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
726 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
727 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
728 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
729 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
732 #ifndef __WXUNIVERSAL__
733 // Don't give scrollbars to wxControls unless they ask for them
734 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
735 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
737 MacCreateScrollBars( style
) ;
741 wxWindowCreateEvent
event(this);
742 GetEventHandler()->AddPendingEvent(event
);
747 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
749 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
751 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
753 MacInstallEventHandler();
755 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
756 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
757 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
759 // adjust font, controlsize etc
760 DoSetWindowVariant( m_windowVariant
) ;
762 #if !TARGET_API_MAC_OSX
763 // eventually we can fix some clipping issues be reactivating this hook
764 //if ( m_macIsUserPane )
765 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
768 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
770 wxSize new_size
= size
;
771 if (!m_macIsUserPane
)
773 SetInitialBestSize(size
);
776 SetCursor( *wxSTANDARD_CURSOR
) ;
780 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
782 // Don't assert, in case we set the window variant before
783 // the window is created
784 // wxASSERT( m_macControl != NULL ) ;
786 m_windowVariant
= variant
;
792 ThemeFontID themeFont
= kThemeSystemFont
;
794 // we will get that from the settings later
795 // and make this NORMAL later, but first
796 // we have a few calculations that we must fix
800 case wxWINDOW_VARIANT_NORMAL
:
801 size
= kControlSizeNormal
;
802 themeFont
= kThemeSystemFont
;
804 case wxWINDOW_VARIANT_SMALL
:
805 size
= kControlSizeSmall
;
806 themeFont
= kThemeSmallSystemFont
;
808 case wxWINDOW_VARIANT_MINI
:
809 if (UMAGetSystemVersion() >= 0x1030 )
811 // not always defined in the headers
817 size
= kControlSizeSmall
;
818 themeFont
= kThemeSmallSystemFont
;
821 case wxWINDOW_VARIANT_LARGE
:
822 size
= kControlSizeLarge
;
823 themeFont
= kThemeSystemFont
;
826 wxFAIL_MSG(_T("unexpected window variant"));
829 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
832 font
.MacCreateThemeFont( themeFont
) ;
836 void wxWindowMac::MacUpdateControlFont()
838 ControlFontStyleRec fontStyle
;
839 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
841 switch( m_font
.MacGetThemeFontID() )
843 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
844 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
845 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
846 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
848 fontStyle
.flags
= kControlUseFontMask
;
852 fontStyle
.font
= m_font
.MacGetFontNum() ;
853 fontStyle
.style
= m_font
.MacGetFontStyle() ;
854 fontStyle
.size
= m_font
.MacGetFontSize() ;
855 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
858 fontStyle
.just
= teJustLeft
;
859 fontStyle
.flags
|= kControlUseJustMask
;
860 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
861 fontStyle
.just
= teJustCenter
;
862 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
863 fontStyle
.just
= teJustRight
;
866 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
867 fontStyle
.flags
|= kControlUseForeColorMask
;
869 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
873 bool wxWindowMac::SetFont(const wxFont
& font
)
875 bool retval
= !wxWindowBase::SetFont( font
) ;
877 MacUpdateControlFont() ;
882 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
884 if ( !wxWindowBase::SetForegroundColour(col
) )
887 MacUpdateControlFont() ;
892 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
894 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
898 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
900 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
902 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
904 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
908 brush
.SetColour( col
) ;
910 MacSetBackgroundBrush( brush
) ;
912 MacUpdateControlFont() ;
918 bool wxWindowMac::MacCanFocus() const
921 // there is currently no way to determinate whether the window is running in full keyboard
922 // access mode, therefore we cannot rely on these features yet
923 UInt32 features
= 0 ;
924 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
925 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
931 void wxWindowMac::SetFocus()
933 if ( AcceptsFocus() )
935 #if !TARGET_API_MAC_OSX
936 wxWindow
* former
= FindFocus() ;
938 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
939 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
940 // leave in case of an error
941 if ( err
== errCouldntSetFocus
)
944 #if !TARGET_API_MAC_OSX
945 // emulate carbon events when running under carbonlib where they are not natively available
948 EventRef evRef
= NULL
;
949 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
952 wxMacCarbonEvent
cEvent( evRef
) ;
953 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
954 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
956 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
957 ReleaseEvent(evRef
) ;
959 // send new focus event
961 EventRef evRef
= NULL
;
962 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
965 wxMacCarbonEvent
cEvent( evRef
) ;
966 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
967 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
969 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
970 ReleaseEvent(evRef
) ;
977 void wxWindowMac::DoCaptureMouse()
979 wxTheApp
->s_captureWindow
= this ;
982 wxWindow
* wxWindowBase::GetCapture()
984 return wxTheApp
->s_captureWindow
;
987 void wxWindowMac::DoReleaseMouse()
989 wxTheApp
->s_captureWindow
= NULL
;
992 #if wxUSE_DRAG_AND_DROP
994 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
996 if ( m_dropTarget
!= 0 ) {
1000 m_dropTarget
= pDropTarget
;
1001 if ( m_dropTarget
!= 0 )
1009 // Old style file-manager drag&drop
1010 void wxWindowMac::DragAcceptFiles(bool accept
)
1015 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1016 int& w
, int& h
) const
1019 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1024 w
= bounds
.right
- bounds
.left
;
1025 h
= bounds
.bottom
- bounds
.top
;
1027 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1030 Point tlworigin
= { 0 , 0 } ;
1032 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1033 ::LocalToGlobal( &tlworigin
) ;
1041 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1044 int& w
, int& h
, bool adjustOrigin
) const
1048 // todo the default calls may be used as soon as PostCreateControl Is moved here
1049 w
= size
.x
; // WidthDefault( size.x );
1050 h
= size
.y
; // HeightDefault( size.y ) ;
1051 #if !TARGET_API_MAC_OSX
1052 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1055 AdjustForParentClientOrigin( x
, y
) ;
1060 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1062 #if TARGET_API_MAC_OSX
1063 int x1
, y1
, w1
,h1
;
1064 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1070 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1071 if(x
) *x
= bounds
.right
- bounds
.left
;
1072 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1076 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1078 #if TARGET_API_MAC_OSX
1079 int x1
, y1
, w1
,h1
;
1080 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1081 if ( !IsTopLevel() )
1083 wxWindow
*parent
= GetParent();
1086 wxPoint
pt(parent
->GetClientAreaOrigin());
1095 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1096 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1098 int xx
= bounds
.left
;
1099 int yy
= bounds
.top
;
1101 if ( !GetParent()->IsTopLevel() )
1103 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1109 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1118 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1120 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1122 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1125 Point localwhere
= {0,0} ;
1127 if(x
) localwhere
.h
= * x
;
1128 if(y
) localwhere
.v
= * y
;
1130 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1131 ::GlobalToLocal( &localwhere
) ;
1132 if(x
) *x
= localwhere
.h
;
1133 if(y
) *y
= localwhere
.v
;
1136 MacRootWindowToWindow( x
, y
) ;
1138 wxPoint origin
= GetClientAreaOrigin() ;
1139 if(x
) *x
-= origin
.x
;
1140 if(y
) *y
-= origin
.y
;
1143 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1145 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1146 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1148 wxPoint origin
= GetClientAreaOrigin() ;
1149 if(x
) *x
+= origin
.x
;
1150 if(y
) *y
+= origin
.y
;
1152 MacWindowToRootWindow( x
, y
) ;
1155 Point localwhere
= { 0,0 };
1156 if(x
) localwhere
.h
= * x
;
1157 if(y
) localwhere
.v
= * y
;
1159 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1160 ::LocalToGlobal( &localwhere
) ;
1161 if(x
) *x
= localwhere
.h
;
1162 if(y
) *y
= localwhere
.v
;
1166 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1168 wxPoint origin
= GetClientAreaOrigin() ;
1169 if(x
) *x
+= origin
.x
;
1170 if(y
) *y
+= origin
.y
;
1172 MacWindowToRootWindow( x
, y
) ;
1175 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1177 MacRootWindowToWindow( x
, y
) ;
1179 wxPoint origin
= GetClientAreaOrigin() ;
1180 if(x
) *x
-= origin
.x
;
1181 if(y
) *y
-= origin
.y
;
1184 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1186 #if TARGET_API_MAC_OSX
1188 if ( x
) pt
.x
= *x
;
1189 if ( y
) pt
.y
= *y
;
1191 if ( !IsTopLevel() )
1192 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1194 if ( x
) *x
= (int) pt
.x
;
1195 if ( y
) *y
= (int) pt
.y
;
1197 if ( !IsTopLevel() )
1200 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1201 if(x
) *x
+= bounds
.left
;
1202 if(y
) *y
+= bounds
.top
;
1207 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1212 MacWindowToRootWindow( &x1
, &y1
) ;
1217 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1219 #if TARGET_API_MAC_OSX
1221 if ( x
) pt
.x
= *x
;
1222 if ( y
) pt
.y
= *y
;
1224 if ( !IsTopLevel() )
1225 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1227 if ( x
) *x
= (int) pt
.x
;
1228 if ( y
) *y
= (int) pt
.y
;
1230 if ( !IsTopLevel() )
1233 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1234 if(x
) *x
-= bounds
.left
;
1235 if(y
) *y
-= bounds
.top
;
1240 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1245 MacRootWindowToWindow( &x1
, &y1
) ;
1250 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1252 RgnHandle rgn
= NewRgn() ;
1254 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1256 GetRegionBounds( rgn
, &content
) ;
1261 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1264 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1265 #if !TARGET_API_MAC_OSX
1266 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1268 left
= content
.left
- structure
.left
;
1269 top
= content
.top
- structure
.top
;
1270 right
= structure
.right
- content
.right
;
1271 bottom
= structure
.bottom
- content
.bottom
;
1274 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1276 wxSize sizeTotal
= size
;
1278 RgnHandle rgn
= NewRgn() ;
1282 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1284 GetRegionBounds( rgn
, &content
) ;
1289 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1292 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1293 #if !TARGET_API_MAC_OSX
1294 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1297 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1298 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1300 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1301 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1307 // Get size *available for subwindows* i.e. excluding menu bar etc.
1308 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1312 RgnHandle rgn
= NewRgn() ;
1314 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1316 GetRegionBounds( rgn
, &content
) ;
1321 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1323 #if !TARGET_API_MAC_OSX
1325 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1326 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1328 ww
= content
.right
- content
.left
;
1329 hh
= content
.bottom
- content
.top
;
1331 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1332 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1334 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1340 GetSize( &w
, &h
) ;
1342 MacClientToRootWindow( &x1
, &y1
) ;
1343 MacClientToRootWindow( &w
, &h
) ;
1345 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1347 int totW
= 10000 , totH
= 10000;
1350 if ( iter
->IsTopLevel() )
1352 iter
->GetSize( &totW
, &totH
) ;
1356 iter
= iter
->GetParent() ;
1359 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1361 hh
-= MAC_SCROLLBAR_SIZE
;
1367 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1369 ww
-= MAC_SCROLLBAR_SIZE
;
1381 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1383 if (m_cursor
== cursor
)
1386 if (wxNullCursor
== cursor
)
1388 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1393 if ( ! wxWindowBase::SetCursor( cursor
) )
1397 wxASSERT_MSG( m_cursor
.Ok(),
1398 wxT("cursor must be valid after call to the base version"));
1402 TODO why do we have to use current coordinates ?
1405 wxWindowMac *mouseWin ;
1408 // Change the cursor NOW if we're within the correct window
1411 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1413 if ( mouseWin == this && !wxIsBusy() )
1415 m_cursor.MacInstall() ;
1421 m_cursor
.MacInstall() ;
1428 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1430 menu
->SetInvokingWindow(this);
1432 ClientToScreen( &x
, &y
) ;
1434 menu
->MacBeforeDisplay( true ) ;
1435 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1436 if ( HiWord(menuResult
) != 0 )
1439 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1440 wxMenuItem
* item
= NULL
;
1442 item
= menu
->FindItem(id
, &realmenu
) ;
1443 if (item
->IsCheckable())
1445 item
->Check( !item
->IsChecked() ) ;
1447 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1449 menu
->MacAfterDisplay( true ) ;
1451 menu
->SetInvokingWindow(NULL
);
1457 // ----------------------------------------------------------------------------
1459 // ----------------------------------------------------------------------------
1463 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1465 wxWindowBase::DoSetToolTip(tooltip
);
1468 m_tooltip
->SetWindow(this);
1471 #endif // wxUSE_TOOLTIPS
1473 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1475 int former_x
, former_y
, former_w
, former_h
;
1476 #if !TARGET_API_MAC_OSX
1477 DoGetPosition( &former_x
, &former_y
) ;
1478 DoGetSize( &former_w
, &former_h
) ;
1480 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1483 int actualWidth
= width
;
1484 int actualHeight
= height
;
1488 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1489 actualWidth
= m_minWidth
;
1490 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1491 actualHeight
= m_minHeight
;
1492 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1493 actualWidth
= m_maxWidth
;
1494 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1495 actualHeight
= m_maxHeight
;
1497 bool doMove
= false ;
1498 bool doResize
= false ;
1500 if ( actualX
!= former_x
|| actualY
!= former_y
)
1504 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1509 if ( doMove
|| doResize
)
1511 // we don't adjust twice for the origin
1512 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1513 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1514 #if TARGET_API_MAC_OSX
1515 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1517 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1518 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1519 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1521 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1524 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1525 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1527 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1529 MacRepositionScrollBars() ;
1532 wxPoint
point(actualX
,actualY
);
1533 wxMoveEvent
event(point
, m_windowId
);
1534 event
.SetEventObject(this);
1535 GetEventHandler()->ProcessEvent(event
) ;
1539 MacRepositionScrollBars() ;
1540 wxSize
size(actualWidth
, actualHeight
);
1541 wxSizeEvent
event(size
, m_windowId
);
1542 event
.SetEventObject(this);
1543 GetEventHandler()->ProcessEvent(event
);
1549 wxSize
wxWindowMac::DoGetBestSize() const
1551 if ( m_macIsUserPane
|| IsTopLevel() )
1552 return wxWindowBase::DoGetBestSize() ;
1554 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1555 short baselineoffset
;
1556 int bestWidth
, bestHeight
;
1557 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1559 if ( EmptyRect( &bestsize
) )
1562 bestsize
.left
= bestsize
.top
= 0 ;
1563 bestsize
.right
= 16 ;
1564 bestsize
.bottom
= 16 ;
1565 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1567 bestsize
.bottom
= 16 ;
1569 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1571 bestsize
.bottom
= 24 ;
1575 // return wxWindowBase::DoGetBestSize() ;
1579 bestWidth
= bestsize
.right
- bestsize
.left
;
1580 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1581 if ( bestHeight
< 10 )
1584 return wxSize(bestWidth
, bestHeight
);
1585 // return wxWindowBase::DoGetBestSize() ;
1589 // set the size of the window: if the dimensions are positive, just use them,
1590 // but if any of them is equal to -1, it means that we must find the value for
1591 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1592 // which case -1 is a valid value for x and y)
1594 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1595 // the width/height to best suit our contents, otherwise we reuse the current
1597 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1599 // get the current size and position...
1600 int currentX
, currentY
;
1601 GetPosition(¤tX
, ¤tY
);
1603 int currentW
,currentH
;
1604 GetSize(¤tW
, ¤tH
);
1606 // ... and don't do anything (avoiding flicker) if it's already ok
1607 if ( x
== currentX
&& y
== currentY
&&
1608 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1611 MacRepositionScrollBars() ; // we might have a real position shift
1615 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1617 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1620 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1622 wxSize
size(-1, -1);
1625 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1627 size
= DoGetBestSize();
1632 // just take the current one
1639 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1643 size
= DoGetBestSize();
1645 //else: already called DoGetBestSize() above
1651 // just take the current one
1656 DoMoveWindow(x
, y
, width
, height
);
1660 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1662 RgnHandle rgn
= NewRgn() ;
1664 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1665 GetRegionBounds( rgn
, &content
) ;
1667 #if !TARGET_API_MAC_OSX
1668 // if the content rgn is empty / not supported
1669 // don't attempt to correct the coordinates to wxWindow relative ones
1670 if (!::EmptyRect( &content
) )
1673 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1674 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1678 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1681 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1683 if ( clientheight
!= -1 || clientheight
!= -1 )
1685 int currentclientwidth
, currentclientheight
;
1686 int currentwidth
, currentheight
;
1688 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1689 GetSize( ¤twidth
, ¤theight
) ;
1691 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1692 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1696 void wxWindowMac::SetTitle(const wxString
& title
)
1698 m_label
= wxStripMenuCodes(title
) ;
1702 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1707 wxString
wxWindowMac::GetTitle() const
1712 bool wxWindowMac::Show(bool show
)
1714 if ( !wxWindowBase::Show(show
) )
1717 // TODO use visibilityChanged Carbon Event for OSX
1718 bool former
= MacIsReallyShown() ;
1720 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1721 if ( former
!= MacIsReallyShown() )
1722 MacPropagateVisibilityChanged() ;
1726 bool wxWindowMac::Enable(bool enable
)
1728 wxASSERT( m_macControl
!= NULL
) ;
1729 if ( !wxWindowBase::Enable(enable
) )
1732 bool former
= MacIsReallyEnabled() ;
1733 #if TARGET_API_MAC_OSX
1735 EnableControl( (ControlRef
) m_macControl
) ;
1737 DisableControl( (ControlRef
) m_macControl
) ;
1740 ActivateControl( (ControlRef
) m_macControl
) ;
1742 DeactivateControl( (ControlRef
) m_macControl
) ;
1745 if ( former
!= MacIsReallyEnabled() )
1746 MacPropagateEnabledStateChanged() ;
1751 // status change propagations (will be not necessary for OSX later )
1754 void wxWindowMac::MacPropagateVisibilityChanged()
1756 #if !TARGET_API_MAC_OSX
1757 MacVisibilityChanged() ;
1759 wxWindowListNode
*node
= GetChildren().GetFirst();
1762 wxWindowMac
*child
= node
->GetData();
1763 if ( child
->IsShown() )
1764 child
->MacPropagateVisibilityChanged( ) ;
1765 node
= node
->GetNext();
1770 void wxWindowMac::MacPropagateEnabledStateChanged( )
1772 #if !TARGET_API_MAC_OSX
1773 MacEnabledStateChanged() ;
1775 wxWindowListNode
*node
= GetChildren().GetFirst();
1778 wxWindowMac
*child
= node
->GetData();
1779 if ( child
->IsEnabled() )
1780 child
->MacPropagateEnabledStateChanged() ;
1781 node
= node
->GetNext();
1786 void wxWindowMac::MacPropagateHiliteChanged( )
1788 #if !TARGET_API_MAC_OSX
1789 MacHiliteChanged() ;
1791 wxWindowListNode
*node
= GetChildren().GetFirst();
1794 wxWindowMac
*child
= node
->GetData();
1795 // if ( child->IsEnabled() )
1796 child
->MacPropagateHiliteChanged() ;
1797 node
= node
->GetNext();
1803 // status change notifications
1806 void wxWindowMac::MacVisibilityChanged()
1810 void wxWindowMac::MacHiliteChanged()
1814 void wxWindowMac::MacEnabledStateChanged()
1819 // status queries on the inherited window's state
1822 bool wxWindowMac::MacIsReallyShown()
1824 // only under OSX the visibility of the TLW is taken into account
1825 #if TARGET_API_MAC_OSX
1826 return IsControlVisible( (ControlRef
) m_macControl
) ;
1828 wxWindow
* win
= this ;
1829 while( win
->IsShown() )
1831 if ( win
->IsTopLevel() )
1834 win
= win
->GetParent() ;
1843 bool wxWindowMac::MacIsReallyEnabled()
1845 #if TARGET_API_MAC_OSX
1846 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1848 return IsControlActive( (ControlRef
) m_macControl
) ;
1852 bool wxWindowMac::MacIsReallyHilited()
1854 return IsControlActive( (ControlRef
) m_macControl
) ;
1861 int wxWindowMac::GetCharHeight() const
1863 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1864 return dc
.GetCharHeight() ;
1867 int wxWindowMac::GetCharWidth() const
1869 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1870 return dc
.GetCharWidth() ;
1873 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1874 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1876 const wxFont
*fontToUse
= theFont
;
1878 fontToUse
= &m_font
;
1880 wxClientDC
dc( (wxWindowMac
*) this ) ;
1882 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1883 if ( externalLeading
)
1884 *externalLeading
= le
;
1894 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1895 * we always intersect with the entire window, not only with the client area
1898 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1900 #if TARGET_API_MAC_OSX
1902 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1905 RgnHandle update
= NewRgn() ;
1906 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1907 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1908 wxPoint origin
= GetClientAreaOrigin() ;
1909 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1910 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1914 RgnHandle updateRgn = NewRgn() ;
1917 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1921 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1922 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1924 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1925 DisposeRgn(updateRgn) ;
1927 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1929 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1930 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1933 if ( MacGetTopLevelWindow() == NULL )
1936 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1939 wxPoint client = GetClientAreaOrigin();
1942 int x2 = m_width - client.x;
1943 int y2 = m_height - client.y;
1945 if (IsKindOf( CLASSINFO(wxButton)))
1947 // buttons have an "aura"
1954 Rect clientrect = { y1, x1, y2, x2 };
1958 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1959 SectRect( &clientrect , &r , &clientrect ) ;
1962 if ( !EmptyRect( &clientrect ) )
1964 int top = 0 , left = 0 ;
1966 MacClientToRootWindow( &left , &top ) ;
1967 OffsetRect( &clientrect , left , top ) ;
1969 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1975 void wxWindowMac::Freeze()
1977 #if TARGET_API_MAC_OSX
1978 if ( !m_frozenness
++ )
1980 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1985 #if TARGET_API_MAC_OSX
1986 static void InvalidateControlAndChildren( HIViewRef control
)
1988 HIViewSetNeedsDisplay( control
, true ) ;
1989 UInt16 childrenCount
= 0 ;
1990 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1991 if ( err
== errControlIsNotEmbedder
)
1993 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1995 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1998 err
= GetIndexedSubControl( control
, i
, & child
) ;
1999 if ( err
== errControlIsNotEmbedder
)
2001 InvalidateControlAndChildren( child
) ;
2006 void wxWindowMac::Thaw()
2008 #if TARGET_API_MAC_OSX
2009 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2011 if ( !--m_frozenness
)
2013 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2014 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2015 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2020 void wxWindowMac::MacRedrawControl()
2023 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2025 #if TARGET_API_MAC_CARBON
2028 wxClientDC dc(this) ;
2029 wxMacPortSetter helper(&dc) ;
2030 wxMacWindowClipper clipper(this) ;
2031 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2032 UMADrawControl( (ControlRef) m_macControl ) ;
2039 void wxWindowMac::OnPaint(wxPaintEvent& event)
2041 // why don't we skip that here ?
2045 wxWindowMac
*wxGetActiveWindow()
2047 // actually this is a windows-only concept
2051 // Coordinates relative to the window
2052 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2054 // We really don't move the mouse programmatically under Mac.
2057 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2059 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2064 event
.GetDC()->Clear() ;
2067 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2069 wxWindowDC
dc(this) ;
2070 wxMacPortSetter
helper(&dc
) ;
2072 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2075 int wxWindowMac::GetScrollPos(int orient
) const
2077 if ( orient
== wxHORIZONTAL
)
2080 return m_hScrollBar
->GetThumbPosition() ;
2085 return m_vScrollBar
->GetThumbPosition() ;
2090 // This now returns the whole range, not just the number
2091 // of positions that we can scroll.
2092 int wxWindowMac::GetScrollRange(int orient
) const
2094 if ( orient
== wxHORIZONTAL
)
2097 return m_hScrollBar
->GetRange() ;
2102 return m_vScrollBar
->GetRange() ;
2107 int wxWindowMac::GetScrollThumb(int orient
) const
2109 if ( orient
== wxHORIZONTAL
)
2112 return m_hScrollBar
->GetThumbSize() ;
2117 return m_vScrollBar
->GetThumbSize() ;
2122 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2124 if ( orient
== wxHORIZONTAL
)
2127 m_hScrollBar
->SetThumbPosition( pos
) ;
2132 m_vScrollBar
->SetThumbPosition( pos
) ;
2136 void wxWindowMac::MacPaintBorders( int left
, int top
)
2142 wxGetOsVersion( &major
, &minor
);
2144 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2145 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2147 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2148 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2149 // OS X has lighter border edges than classic:
2152 darkShadow
.red
= 0x8E8E;
2153 darkShadow
.green
= 0x8E8E;
2154 darkShadow
.blue
= 0x8E8E;
2155 lightShadow
.red
= 0xBDBD;
2156 lightShadow
.green
= 0xBDBD;
2157 lightShadow
.blue
= 0xBDBD;
2163 GetSize( &w
, &h
) ;
2164 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2166 #if wxMAC_USE_THEME_BORDER
2167 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2170 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2171 InsetRect( &rect , border , border );
2172 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2175 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2177 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2178 RGBForeColor( &face
);
2179 MoveTo( left
+ 0 , top
+ h
- 2 );
2180 LineTo( left
+ 0 , top
+ 0 );
2181 LineTo( left
+ w
- 2 , top
+ 0 );
2183 MoveTo( left
+ 2 , top
+ h
- 3 );
2184 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2185 LineTo( left
+ w
- 3 , top
+ 2 );
2187 RGBForeColor( sunken
? &face
: &darkShadow
);
2188 MoveTo( left
+ 0 , top
+ h
- 1 );
2189 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2190 LineTo( left
+ w
- 1 , top
+ 0 );
2192 RGBForeColor( sunken
? &lightShadow
: &white
);
2193 MoveTo( left
+ 1 , top
+ h
- 3 );
2194 LineTo( left
+ 1, top
+ 1 );
2195 LineTo( left
+ w
- 3 , top
+ 1 );
2197 RGBForeColor( sunken
? &white
: &lightShadow
);
2198 MoveTo( left
+ 1 , top
+ h
- 2 );
2199 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2200 LineTo( left
+ w
- 2 , top
+ 1 );
2202 RGBForeColor( sunken
? &darkShadow
: &face
);
2203 MoveTo( left
+ 2 , top
+ h
- 4 );
2204 LineTo( left
+ 2 , top
+ 2 );
2205 LineTo( left
+ w
- 4 , top
+ 2 );
2208 else if (HasFlag(wxSIMPLE_BORDER
))
2210 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2211 RGBForeColor( &darkShadow
) ;
2212 FrameRect( &rect
) ;
2216 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2218 if ( child
== m_hScrollBar
)
2219 m_hScrollBar
= NULL
;
2220 if ( child
== m_vScrollBar
)
2221 m_vScrollBar
= NULL
;
2223 wxWindowBase::RemoveChild( child
) ;
2226 // New function that will replace some of the above.
2227 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2228 int range
, bool refresh
)
2230 if ( orient
== wxHORIZONTAL
)
2234 if ( range
== 0 || thumbVisible
>= range
)
2236 if ( m_hScrollBar
->IsShown() )
2237 m_hScrollBar
->Show(false) ;
2241 if ( !m_hScrollBar
->IsShown() )
2242 m_hScrollBar
->Show(true) ;
2243 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2251 if ( range
== 0 || thumbVisible
>= range
)
2253 if ( m_vScrollBar
->IsShown() )
2254 m_vScrollBar
->Show(false) ;
2258 if ( !m_vScrollBar
->IsShown() )
2259 m_vScrollBar
->Show(true) ;
2260 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2264 MacRepositionScrollBars() ;
2267 // Does a physical scroll
2268 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2270 if( dx
== 0 && dy
==0 )
2275 wxClientDC
dc(this) ;
2276 wxMacPortSetter
helper(&dc
) ;
2278 int width
, height
;
2279 GetClientSize( &width
, &height
) ;
2286 // TODO take out the boundaries
2287 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2289 RgnHandle updateRgn
= NewRgn() ;
2292 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2293 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2294 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2296 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2298 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2299 // but it seems the update only refreshes the background of the control, rather than calling
2300 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2301 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2304 // we also have to scroll the update rgn in this rectangle
2305 // in order not to loose updates
2307 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2308 RgnHandle formerUpdateRgn
= NewRgn() ;
2309 RgnHandle scrollRgn
= NewRgn() ;
2310 RectRgn( scrollRgn
, &scrollrect
) ;
2311 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2313 LocalToGlobal( &pt
) ;
2314 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2315 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2316 if ( !EmptyRgn( formerUpdateRgn
) )
2318 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2319 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2320 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2322 InvalWindowRgn(rootWindow
, updateRgn
) ;
2323 DisposeRgn( updateRgn
) ;
2324 DisposeRgn( formerUpdateRgn
) ;
2325 DisposeRgn( scrollRgn
) ;
2329 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2331 wxWindowMac
*child
= node
->GetData();
2332 if (child
== m_vScrollBar
) continue;
2333 if (child
== m_hScrollBar
) continue;
2334 if (child
->IsTopLevel()) continue;
2337 child
->GetPosition( &x
, &y
);
2339 child
->GetSize( &w
, &h
);
2343 if (rect
->Intersects(rc
))
2344 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2348 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2352 // TODO remove, was moved higher up Update() ;
2356 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2358 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2360 wxScrollWinEvent wevent
;
2361 wevent
.SetPosition(event
.GetPosition());
2362 wevent
.SetOrientation(event
.GetOrientation());
2363 wevent
.m_eventObject
= this;
2365 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2366 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2367 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2368 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2369 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2370 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2371 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2372 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2373 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2374 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2375 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2377 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2378 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2379 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2380 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2382 GetEventHandler()->ProcessEvent(wevent
);
2386 // Get the window with the focus
2387 wxWindowMac
*wxWindowBase::FindFocus()
2389 ControlRef control
;
2390 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2391 return wxFindControlFromMacControl( control
) ;
2394 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2396 // panel wants to track the window which was the last to have focus in it,
2397 // so we want to set ourselves as the window which last had focus
2399 // notice that it's also important to do it upwards the tree becaus
2400 // otherwise when the top level panel gets focus, it won't set it back to
2401 // us, but to some other sibling
2403 // CS:don't know if this is still needed:
2404 //wxChildFocusEvent eventFocus(this);
2405 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2410 void wxWindowMac::OnInternalIdle()
2412 // This calls the UI-update mechanism (querying windows for
2413 // menu/toolbar/control state information)
2414 if (wxUpdateUIEvent::CanUpdate(this))
2415 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2418 // Raise the window to the top of the Z order
2419 void wxWindowMac::Raise()
2421 #if TARGET_API_MAC_OSX
2422 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2426 // Lower the window to the bottom of the Z order
2427 void wxWindowMac::Lower()
2429 #if TARGET_API_MAC_OSX
2430 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2435 // static wxWindow *gs_lastWhich = NULL;
2437 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2439 // first trigger a set cursor event
2441 wxPoint clientorigin
= GetClientAreaOrigin() ;
2442 wxSize clientsize
= GetClientSize() ;
2444 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2446 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2448 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2449 if ( processedEvtSetCursor
&& event
.HasCursor() )
2451 cursor
= event
.GetCursor() ;
2456 // the test for processedEvtSetCursor is here to prevent using m_cursor
2457 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2458 // it - this is a way to say that our cursor shouldn't be used for this
2460 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2470 cursor
= *wxSTANDARD_CURSOR
;
2474 cursor
.MacInstall() ;
2476 return cursor
.Ok() ;
2479 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2483 return m_tooltip
->GetTip() ;
2485 return wxEmptyString
;
2488 void wxWindowMac::Update()
2490 #if TARGET_API_MAC_OSX
2491 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2493 ::Draw1Control( (ControlRef
) m_macControl
) ;
2497 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2499 wxTopLevelWindowMac
* win
= NULL
;
2500 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2503 win
= wxFindWinFromMacWindow( window
) ;
2507 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2511 RgnHandle visRgn
= NewRgn() ;
2512 RgnHandle tempRgn
= NewRgn() ;
2513 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2515 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2516 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2518 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2519 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2528 if ( includeOuterStructures
)
2529 InsetRect( &r
, -3 , -3 ) ;
2530 RectRgn( visRgn
, &r
) ;
2531 if ( !IsTopLevel() )
2533 wxWindow
* child
= this ;
2534 wxWindow
* parent
= child
->GetParent() ;
2539 // we have to find a better clipping algorithm here, in order not to clip things
2540 // positioned like status and toolbar
2541 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2543 size
= parent
->GetSize() ;
2548 size
= parent
->GetClientSize() ;
2549 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2553 parent
->MacWindowToRootWindow( &x
, &y
) ;
2554 MacRootWindowToWindow( &x
, &y
) ;
2556 SetRectRgn( tempRgn
,
2557 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2558 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2559 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2561 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2562 if ( parent
->IsTopLevel() )
2565 parent
= child
->GetParent() ;
2570 wxRegion vis
= visRgn
;
2571 DisposeRgn( visRgn
) ;
2572 DisposeRgn( tempRgn
) ;
2577 This function must not change the updatergn !
2579 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2581 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2582 bool handled
= false ;
2584 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2586 RgnHandle newupdate
= NewRgn() ;
2587 wxSize point
= GetClientSize() ;
2588 wxPoint origin
= GetClientAreaOrigin() ;
2589 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2590 SectRgn( newupdate
, updatergn
, newupdate
) ;
2591 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2592 m_updateRegion
= newupdate
;
2593 DisposeRgn( newupdate
) ;
2596 if ( !EmptyRgn(updatergn
) )
2598 wxWindowDC
dc(this);
2599 if (!EmptyRgn(updatergn
))
2600 dc
.SetClippingRegion(wxRegion(updatergn
));
2602 wxEraseEvent
eevent( GetId(), &dc
);
2603 eevent
.SetEventObject( this );
2604 GetEventHandler()->ProcessEvent( eevent
);
2606 if ( !m_updateRegion
.Empty() )
2608 // paint the window itself
2610 event
.m_timeStamp
= time
;
2611 event
.SetEventObject(this);
2612 handled
= GetEventHandler()->ProcessEvent(event
);
2614 // paint custom borders
2615 wxNcPaintEvent
eventNc( GetId() );
2616 eventNc
.SetEventObject( this );
2617 GetEventHandler()->ProcessEvent( eventNc
);
2623 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2625 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2626 // updatergn is always already clipped to our boundaries
2627 // if we are in compositing mode then it is in relative to the upper left of the control
2628 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2629 // of the toplevel window
2630 // it is in window coordinates, not in client coordinates
2632 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2633 RgnHandle ownUpdateRgn
= NewRgn() ;
2634 CopyRgn( updatergn
, ownUpdateRgn
) ;
2636 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2639 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2640 RgnHandle controlRgn
= NewRgn();
2641 RectRgn( controlRgn
, &bounds
);
2642 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2643 // the window update region
2644 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2645 DisposeRgn( controlRgn
);
2647 //KO: convert ownUpdateRgn to local coordinates
2648 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2651 MacDoRedraw( ownUpdateRgn
, time
) ;
2652 DisposeRgn( ownUpdateRgn
) ;
2656 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2658 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2662 if ( iter
->IsTopLevel() )
2663 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2665 iter
= iter
->GetParent() ;
2667 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2671 void wxWindowMac::MacCreateScrollBars( long style
)
2673 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2675 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2676 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2678 GetClientSize( &width
, &height
) ;
2680 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2681 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2682 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2683 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2685 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2686 vSize
, wxVERTICAL
);
2688 if ( style
& wxVSCROLL
)
2694 m_vScrollBar
->Show(false) ;
2696 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2697 hSize
, wxHORIZONTAL
);
2698 if ( style
& wxHSCROLL
)
2703 m_hScrollBar
->Show(false) ;
2706 // because the create does not take into account the client area origin
2707 MacRepositionScrollBars() ; // we might have a real position shift
2710 void wxWindowMac::MacRepositionScrollBars()
2712 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2713 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2715 // get real client area
2719 GetSize( &width
, &height
) ;
2721 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2722 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2724 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2725 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2726 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2727 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2733 GetSize( &w
, &h
) ;
2735 MacClientToRootWindow( &x
, &y
) ;
2736 MacClientToRootWindow( &w
, &h
) ;
2738 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2740 int totW
= 10000 , totH
= 10000;
2743 if ( iter
->IsTopLevel() )
2745 iter
->GetSize( &totW
, &totH
) ;
2749 iter
= iter
->GetParent() ;
2777 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2781 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2785 bool wxWindowMac::AcceptsFocus() const
2787 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2790 void wxWindowMac::MacSuperChangedPosition()
2792 // only window-absolute structures have to be moved i.e. controls
2794 wxWindowListNode
*node
= GetChildren().GetFirst();
2797 wxWindowMac
*child
= node
->GetData();
2798 child
->MacSuperChangedPosition() ;
2799 node
= node
->GetNext();
2803 void wxWindowMac::MacTopLevelWindowChangedPosition()
2805 // only screen-absolute structures have to be moved i.e. glcanvas
2807 wxWindowListNode
*node
= GetChildren().GetFirst();
2810 wxWindowMac
*child
= node
->GetData();
2811 child
->MacTopLevelWindowChangedPosition() ;
2812 node
= node
->GetNext();
2816 long wxWindowMac::MacGetLeftBorderSize( ) const
2821 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2824 #if wxMAC_USE_THEME_BORDER
2825 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2829 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2832 #if wxMAC_USE_THEME_BORDER
2833 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2837 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2844 long wxWindowMac::MacGetRightBorderSize( ) const
2846 // they are all symmetric in mac themes
2847 return MacGetLeftBorderSize() ;
2850 long wxWindowMac::MacGetTopBorderSize( ) const
2852 // they are all symmetric in mac themes
2853 return MacGetLeftBorderSize() ;
2856 long wxWindowMac::MacGetBottomBorderSize( ) const
2858 // they are all symmetric in mac themes
2859 return MacGetLeftBorderSize() ;
2862 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2864 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2867 // Find the wxWindowMac at the current mouse position, returning the mouse
2869 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2871 pt
= wxGetMousePosition();
2872 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2876 // Get the current mouse position.
2877 wxPoint
wxGetMousePosition()
2880 wxGetMousePosition(& x
, & y
);
2881 return wxPoint(x
, y
);
2884 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2886 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2888 // copied from wxGTK : CS
2889 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2892 // (a) it's a command event and so is propagated to the parent
2893 // (b) under MSW it can be generated from kbd too
2894 // (c) it uses screen coords (because of (a))
2895 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2897 this->ClientToScreen(event
.GetPosition()));
2898 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2907 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2911 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2915 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2916 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2920 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2922 return eventNotHandledErr
;