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
) ;
216 // panel wants to track the window which was the last to have focus in it
217 wxChildFocusEvent
eventFocus(thisWindow
);
218 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
221 if ( thisWindow
->GetCaret() )
223 thisWindow
->GetCaret()->OnSetFocus();
225 #endif // wxUSE_CARET
227 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
228 event
.SetEventObject(thisWindow
);
229 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
234 case kEventControlHit
:
236 result
= thisWindow
->MacControlHit( handler
, event
) ;
245 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
247 OSStatus result
= eventNotHandledErr
;
249 wxMacCarbonEvent
cEvent( event
) ;
251 ControlRef controlRef
;
252 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
253 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
254 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
256 switch( GetEventKind( event
) )
258 case kEventServiceGetTypes
:
262 textCtrl
->GetSelection( &from
, &to
) ;
264 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
266 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
267 if ( textCtrl
->IsEditable() )
268 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
270 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
271 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
273 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
277 CFArrayAppendValue (copyTypes
, typestring
) ;
279 CFArrayAppendValue (pasteTypes
, typestring
) ;
280 CFRelease( typestring
) ;
286 case kEventServiceCopy
:
290 textCtrl
->GetSelection( &from
, &to
) ;
291 wxString val
= textCtrl
->GetValue() ;
292 val
= val
.Mid( from
, to
- from
) ;
293 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
294 verify_noerr( ClearScrap( &scrapRef
) ) ;
295 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
299 case kEventServicePaste
:
302 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
303 Size textSize
, pastedSize
;
304 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
306 char *content
= new char[textSize
] ;
307 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
308 content
[textSize
-1] = 0 ;
309 textCtrl
->WriteText( wxString( content
) ) ;
319 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
321 OSStatus result
= eventNotHandledErr
;
323 switch ( GetEventClass( event
) )
325 case kEventClassControl
:
326 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
328 case kEventClassService
:
329 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
336 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
338 // ---------------------------------------------------------------------------
339 // UserPane events for non OSX builds
340 // ---------------------------------------------------------------------------
342 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
344 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
345 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
346 win
->MacControlUserPaneDrawProc(part
) ;
349 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
351 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
352 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
353 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
356 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
358 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
359 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
360 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
363 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
365 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
366 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
367 win
->MacControlUserPaneIdleProc() ;
370 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
372 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
373 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
374 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
377 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
379 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
380 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
381 win
->MacControlUserPaneActivateProc(activating
) ;
384 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
386 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
387 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
388 return win
->MacControlUserPaneFocusProc(action
) ;
391 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
393 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
394 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
395 win
->MacControlUserPaneBackgroundProc(info
) ;
398 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
400 RgnHandle rgn
= NewRgn() ;
402 wxMacWindowStateSaver
sv( this ) ;
403 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
404 MacDoRedraw( rgn
, 0 ) ;
408 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
410 return kControlNoPart
;
413 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
415 return kControlNoPart
;
418 void wxWindowMac::MacControlUserPaneIdleProc()
422 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
424 return kControlNoPart
;
427 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
431 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
433 return kControlNoPart
;
436 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
440 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
441 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
442 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
443 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
444 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
445 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
446 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
447 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
449 // ===========================================================================
451 // ===========================================================================
453 wxList
wxWinMacControlList(wxKEY_INTEGER
);
455 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
457 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
460 return (wxControl
*)node
->GetData();
463 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
465 // adding NULL ControlRef is (first) surely a result of an error and
466 // (secondly) breaks native event processing
467 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
469 if ( !wxWinMacControlList
.Find((long)inControl
) )
470 wxWinMacControlList
.Append((long)inControl
, control
);
473 void wxRemoveMacControlAssociation(wxWindow
*control
)
475 wxWinMacControlList
.DeleteObject(control
);
479 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
481 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
483 // we have to setup the brush in the current port and return noErr
484 // or return an error code so that the control manager walks further up the
485 // hierarchy to find a correct background
487 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
489 OSStatus status
= paramErr
;
492 case kControlMsgApplyTextColor
:
494 case kControlMsgSetUpBackground
:
496 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
500 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
504 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
506 // this clipping is only needed for non HIView
508 RgnHandle clip
= NewRgn() ;
511 wx
->MacWindowToRootWindow( &x
,&y
) ;
512 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
513 OffsetRgn( clip
, x
, y
) ;
520 else if ( wx->MacIsUserPane() )
522 // if we don't have a valid brush for such a control, we have to call the
523 // setup of our parent ourselves
524 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
537 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
538 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
542 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
545 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
550 // ----------------------------------------------------------------------------
551 // constructors and such
552 // ----------------------------------------------------------------------------
554 void wxWindowMac::Init()
557 #if WXWIN_COMPATIBILITY_2_4
558 m_backgroundTransparent
= FALSE
;
561 // as all windows are created with WS_VISIBLE style...
564 m_hScrollBar
= NULL
;
565 m_vScrollBar
= NULL
;
566 m_macBackgroundBrush
= wxNullBrush
;
568 m_macControl
= NULL
;
570 m_macIsUserPane
= TRUE
;
572 // make sure all proc ptrs are available
574 if ( gControlUserPaneDrawUPP
== NULL
)
576 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
577 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
578 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
579 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
580 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
581 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
582 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
583 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
585 if ( wxMacLiveScrollbarActionUPP
== NULL
)
587 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
590 if ( wxMacSetupControlBackgroundUPP
== NULL
)
592 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
595 // we need a valid font for the encodings
596 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
600 wxWindowMac::~wxWindowMac()
604 m_isBeingDeleted
= TRUE
;
606 #ifndef __WXUNIVERSAL__
607 // VS: make sure there's no wxFrame with last focus set to us:
608 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
610 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
613 if ( frame
->GetLastFocus() == this )
615 frame
->SetLastFocus((wxWindow
*)NULL
);
620 #endif // __WXUNIVERSAL__
622 // wxRemoveMacControlAssociation( this ) ;
623 // If we delete an item, we should initialize the parent panel,
624 // because it could now be invalid.
625 wxWindow
*parent
= GetParent() ;
628 if (parent
->GetDefaultItem() == (wxButton
*) this)
629 parent
->SetDefaultItem(NULL
);
631 if ( (ControlRef
) m_macControl
)
633 // in case the callback might be called during destruction
634 wxRemoveMacControlAssociation( this) ;
635 ::SetControlColorProc( (ControlRef
) m_macControl
, NULL
) ;
636 ::DisposeControl( (ControlRef
) m_macControl
) ;
637 m_macControl
= NULL
;
640 if ( g_MacLastWindow
== this )
642 g_MacLastWindow
= NULL
;
645 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
648 if ( frame
->GetLastFocus() == this )
649 frame
->SetLastFocus( NULL
) ;
654 // delete our drop target if we've got one
655 #if wxUSE_DRAG_AND_DROP
656 if ( m_dropTarget
!= NULL
)
661 #endif // wxUSE_DRAG_AND_DROP
666 void wxWindowMac::MacInstallEventHandler()
668 wxAssociateControlWithMacControl( (ControlRef
) m_macControl
, this ) ;
669 InstallControlEventHandler( (ControlRef
) m_macControl
, GetwxMacWindowEventHandlerUPP(),
670 GetEventTypeCount(eventList
), eventList
, this,
671 (EventHandlerRef
*)&m_macControlEventHandler
);
676 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
680 const wxString
& name
)
682 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
684 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
687 parent
->AddChild(this);
689 m_windowVariant
= parent
->GetWindowVariant() ;
691 if ( m_macIsUserPane
)
693 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
696 | kControlSupportsEmbedding
697 // | kControlSupportsLiveFeedback
698 // | kControlHasSpecialBackground
699 // | kControlSupportsCalcBestRect
700 // | kControlHandlesTracking
701 | kControlSupportsFocus
702 // | kControlWantsActivate
703 // | kControlWantsIdle
706 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, (ControlRef
*) &m_macControl
);
708 MacPostControlCreate(pos
,size
) ;
709 #if !TARGET_API_MAC_OSX
710 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
711 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
712 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
713 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
714 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
715 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
716 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
717 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
718 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
719 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
720 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
721 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
722 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
723 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
724 SetControlData((ControlRef
) m_macControl
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
725 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
728 #ifndef __WXUNIVERSAL__
729 // Don't give scrollbars to wxControls unless they ask for them
730 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
731 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
733 MacCreateScrollBars( style
) ;
737 wxWindowCreateEvent
event(this);
738 GetEventHandler()->AddPendingEvent(event
);
743 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
745 wxASSERT_MSG( (ControlRef
) m_macControl
!= NULL
, wxT("No valid mac control") ) ;
747 ::SetControlReference( (ControlRef
) m_macControl
, (long) this ) ;
749 MacInstallEventHandler();
751 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
752 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
753 ::EmbedControl( (ControlRef
) m_macControl
, container
) ;
755 // adjust font, controlsize etc
756 DoSetWindowVariant( m_windowVariant
) ;
758 #if !TARGET_API_MAC_OSX
759 // eventually we can fix some clipping issues be reactivating this hook
760 //if ( m_macIsUserPane )
761 // SetControlColorProc( (ControlRef) m_macControl , wxMacSetupControlBackgroundUPP ) ;
764 UMASetControlTitle( (ControlRef
) m_macControl
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
766 wxSize new_size
= size
;
767 if (!m_macIsUserPane
)
769 SetInitialBestSize(size
);
772 SetCursor( *wxSTANDARD_CURSOR
) ;
776 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
778 // Don't assert, in case we set the window variant before
779 // the window is created
780 // wxASSERT( m_macControl != NULL ) ;
782 m_windowVariant
= variant
;
788 ThemeFontID themeFont
= kThemeSystemFont
;
790 // we will get that from the settings later
791 // and make this NORMAL later, but first
792 // we have a few calculations that we must fix
796 case wxWINDOW_VARIANT_NORMAL
:
797 size
= kControlSizeNormal
;
798 themeFont
= kThemeSystemFont
;
800 case wxWINDOW_VARIANT_SMALL
:
801 size
= kControlSizeSmall
;
802 themeFont
= kThemeSmallSystemFont
;
804 case wxWINDOW_VARIANT_MINI
:
805 if (UMAGetSystemVersion() >= 0x1030 )
807 // not always defined in the headers
813 size
= kControlSizeSmall
;
814 themeFont
= kThemeSmallSystemFont
;
817 case wxWINDOW_VARIANT_LARGE
:
818 size
= kControlSizeLarge
;
819 themeFont
= kThemeSystemFont
;
822 wxFAIL_MSG(_T("unexpected window variant"));
825 ::SetControlData( (ControlRef
) m_macControl
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
828 font
.MacCreateThemeFont( themeFont
) ;
832 void wxWindowMac::MacUpdateControlFont()
834 ControlFontStyleRec fontStyle
;
835 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
837 switch( m_font
.MacGetThemeFontID() )
839 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
840 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
841 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
842 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
844 fontStyle
.flags
= kControlUseFontMask
;
848 fontStyle
.font
= m_font
.MacGetFontNum() ;
849 fontStyle
.style
= m_font
.MacGetFontStyle() ;
850 fontStyle
.size
= m_font
.MacGetFontSize() ;
851 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
854 fontStyle
.just
= teJustLeft
;
855 fontStyle
.flags
|= kControlUseJustMask
;
856 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
857 fontStyle
.just
= teJustCenter
;
858 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
859 fontStyle
.just
= teJustRight
;
862 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
863 fontStyle
.flags
|= kControlUseForeColorMask
;
865 ::SetControlFontStyle( (ControlRef
) m_macControl
, &fontStyle
);
869 bool wxWindowMac::SetFont(const wxFont
& font
)
871 bool retval
= !wxWindowBase::SetFont( font
) ;
873 MacUpdateControlFont() ;
878 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
880 if ( !wxWindowBase::SetForegroundColour(col
) )
883 MacUpdateControlFont() ;
888 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
890 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
894 if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
896 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
898 else if ( col
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
900 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
904 brush
.SetColour( col
) ;
906 MacSetBackgroundBrush( brush
) ;
908 MacUpdateControlFont() ;
914 bool wxWindowMac::MacCanFocus() const
917 // there is currently no way to determinate whether the window is running in full keyboard
918 // access mode, therefore we cannot rely on these features yet
919 UInt32 features
= 0 ;
920 GetControlFeatures( (ControlRef
) m_macControl
, &features
) ;
921 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
927 void wxWindowMac::SetFocus()
929 if ( AcceptsFocus() )
931 #if !TARGET_API_MAC_OSX
932 wxWindow
* former
= FindFocus() ;
934 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
935 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
936 // leave in case of an error
937 if ( err
== errCouldntSetFocus
)
940 #if !TARGET_API_MAC_OSX
941 // emulate carbon events when running under carbonlib where they are not natively available
944 EventRef evRef
= NULL
;
945 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
948 wxMacCarbonEvent
cEvent( evRef
) ;
949 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
950 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
952 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
953 ReleaseEvent(evRef
) ;
955 // send new focus event
957 EventRef evRef
= NULL
;
958 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
961 wxMacCarbonEvent
cEvent( evRef
) ;
962 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
963 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
965 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
966 ReleaseEvent(evRef
) ;
973 void wxWindowMac::DoCaptureMouse()
975 wxTheApp
->s_captureWindow
= this ;
978 wxWindow
* wxWindowBase::GetCapture()
980 return wxTheApp
->s_captureWindow
;
983 void wxWindowMac::DoReleaseMouse()
985 wxTheApp
->s_captureWindow
= NULL
;
988 #if wxUSE_DRAG_AND_DROP
990 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
992 if ( m_dropTarget
!= 0 ) {
996 m_dropTarget
= pDropTarget
;
997 if ( m_dropTarget
!= 0 )
1005 // Old style file-manager drag&drop
1006 void wxWindowMac::DragAcceptFiles(bool accept
)
1011 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1012 int& w
, int& h
) const
1015 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1020 w
= bounds
.right
- bounds
.left
;
1021 h
= bounds
.bottom
- bounds
.top
;
1023 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1026 Point tlworigin
= { 0 , 0 } ;
1028 bool swapped
= QDSwapPort( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &port
) ;
1029 ::LocalToGlobal( &tlworigin
) ;
1037 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1040 int& w
, int& h
, bool adjustOrigin
) const
1044 // todo the default calls may be used as soon as PostCreateControl Is moved here
1045 w
= size
.x
; // WidthDefault( size.x );
1046 h
= size
.y
; // HeightDefault( size.y ) ;
1047 #if !TARGET_API_MAC_OSX
1048 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1051 AdjustForParentClientOrigin( x
, y
) ;
1056 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1058 #if TARGET_API_MAC_OSX
1059 int x1
, y1
, w1
,h1
;
1060 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1066 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1067 if(x
) *x
= bounds
.right
- bounds
.left
;
1068 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1072 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1074 #if TARGET_API_MAC_OSX
1075 int x1
, y1
, w1
,h1
;
1076 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1077 if ( !IsTopLevel() )
1079 wxWindow
*parent
= GetParent();
1082 wxPoint
pt(parent
->GetClientAreaOrigin());
1091 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1092 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1094 int xx
= bounds
.left
;
1095 int yy
= bounds
.top
;
1097 if ( !GetParent()->IsTopLevel() )
1099 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1105 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1114 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1116 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1118 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1121 Point localwhere
= {0,0} ;
1123 if(x
) localwhere
.h
= * x
;
1124 if(y
) localwhere
.v
= * y
;
1126 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1127 ::GlobalToLocal( &localwhere
) ;
1128 if(x
) *x
= localwhere
.h
;
1129 if(y
) *y
= localwhere
.v
;
1132 MacRootWindowToWindow( x
, y
) ;
1134 wxPoint origin
= GetClientAreaOrigin() ;
1135 if(x
) *x
-= origin
.x
;
1136 if(y
) *y
-= origin
.y
;
1139 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1141 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1142 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1144 wxPoint origin
= GetClientAreaOrigin() ;
1145 if(x
) *x
+= origin
.x
;
1146 if(y
) *y
+= origin
.y
;
1148 MacWindowToRootWindow( x
, y
) ;
1151 Point localwhere
= { 0,0 };
1152 if(x
) localwhere
.h
= * x
;
1153 if(y
) localwhere
.v
= * y
;
1155 wxMacPortSaver
s((GrafPtr
)GetWindowPort( window
)) ;
1156 ::LocalToGlobal( &localwhere
) ;
1157 if(x
) *x
= localwhere
.h
;
1158 if(y
) *y
= localwhere
.v
;
1162 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1164 wxPoint origin
= GetClientAreaOrigin() ;
1165 if(x
) *x
+= origin
.x
;
1166 if(y
) *y
+= origin
.y
;
1168 MacWindowToRootWindow( x
, y
) ;
1171 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1173 MacRootWindowToWindow( x
, y
) ;
1175 wxPoint origin
= GetClientAreaOrigin() ;
1176 if(x
) *x
-= origin
.x
;
1177 if(y
) *y
-= origin
.y
;
1180 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1182 #if TARGET_API_MAC_OSX
1184 if ( x
) pt
.x
= *x
;
1185 if ( y
) pt
.y
= *y
;
1187 if ( !IsTopLevel() )
1188 HIViewConvertPoint( &pt
, (ControlRef
) m_macControl
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() ) ;
1190 if ( x
) *x
= (int) pt
.x
;
1191 if ( y
) *y
= (int) pt
.y
;
1193 if ( !IsTopLevel() )
1196 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1197 if(x
) *x
+= bounds
.left
;
1198 if(y
) *y
+= bounds
.top
;
1203 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1208 MacWindowToRootWindow( &x1
, &y1
) ;
1213 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1215 #if TARGET_API_MAC_OSX
1217 if ( x
) pt
.x
= *x
;
1218 if ( y
) pt
.y
= *y
;
1220 if ( !IsTopLevel() )
1221 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , (ControlRef
) m_macControl
) ;
1223 if ( x
) *x
= (int) pt
.x
;
1224 if ( y
) *y
= (int) pt
.y
;
1226 if ( !IsTopLevel() )
1229 GetControlBounds( (ControlRef
) m_macControl
, &bounds
) ;
1230 if(x
) *x
-= bounds
.left
;
1231 if(y
) *y
-= bounds
.top
;
1236 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1241 MacRootWindowToWindow( &x1
, &y1
) ;
1246 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1248 RgnHandle rgn
= NewRgn() ;
1250 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1252 GetRegionBounds( rgn
, &content
) ;
1257 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1260 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1261 #if !TARGET_API_MAC_OSX
1262 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1264 left
= content
.left
- structure
.left
;
1265 top
= content
.top
- structure
.top
;
1266 right
= structure
.right
- content
.right
;
1267 bottom
= structure
.bottom
- content
.bottom
;
1270 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1272 wxSize sizeTotal
= size
;
1274 RgnHandle rgn
= NewRgn() ;
1278 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1280 GetRegionBounds( rgn
, &content
) ;
1285 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1288 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1289 #if !TARGET_API_MAC_OSX
1290 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1293 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1294 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1296 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1297 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1303 // Get size *available for subwindows* i.e. excluding menu bar etc.
1304 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1308 RgnHandle rgn
= NewRgn() ;
1310 if ( GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) == noErr
)
1312 GetRegionBounds( rgn
, &content
) ;
1317 GetControlBounds( (ControlRef
) m_macControl
, &content
) ;
1319 #if !TARGET_API_MAC_OSX
1321 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1322 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1324 ww
= content
.right
- content
.left
;
1325 hh
= content
.bottom
- content
.top
;
1327 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1328 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1330 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1336 GetSize( &w
, &h
) ;
1338 MacClientToRootWindow( &x1
, &y1
) ;
1339 MacClientToRootWindow( &w
, &h
) ;
1341 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1343 int totW
= 10000 , totH
= 10000;
1346 if ( iter
->IsTopLevel() )
1348 iter
->GetSize( &totW
, &totH
) ;
1352 iter
= iter
->GetParent() ;
1355 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1357 hh
-= MAC_SCROLLBAR_SIZE
;
1363 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1365 ww
-= MAC_SCROLLBAR_SIZE
;
1377 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1379 if (m_cursor
== cursor
)
1382 if (wxNullCursor
== cursor
)
1384 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1389 if ( ! wxWindowBase::SetCursor( cursor
) )
1393 wxASSERT_MSG( m_cursor
.Ok(),
1394 wxT("cursor must be valid after call to the base version"));
1398 TODO why do we have to use current coordinates ?
1401 wxWindowMac *mouseWin ;
1404 // Change the cursor NOW if we're within the correct window
1407 if ( MacGetWindowFromPoint( wxPoint( pt.h , pt.v ) , &mouseWin ) )
1409 if ( mouseWin == this && !wxIsBusy() )
1411 m_cursor.MacInstall() ;
1417 m_cursor
.MacInstall() ;
1424 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1426 menu
->SetInvokingWindow(this);
1428 ClientToScreen( &x
, &y
) ;
1430 menu
->MacBeforeDisplay( true ) ;
1431 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1432 if ( HiWord(menuResult
) != 0 )
1435 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1436 wxMenuItem
* item
= NULL
;
1438 item
= menu
->FindItem(id
, &realmenu
) ;
1439 if (item
->IsCheckable())
1441 item
->Check( !item
->IsChecked() ) ;
1443 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1445 menu
->MacAfterDisplay( true ) ;
1447 menu
->SetInvokingWindow(NULL
);
1453 // ----------------------------------------------------------------------------
1455 // ----------------------------------------------------------------------------
1459 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1461 wxWindowBase::DoSetToolTip(tooltip
);
1464 m_tooltip
->SetWindow(this);
1467 #endif // wxUSE_TOOLTIPS
1469 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1471 int former_x
, former_y
, former_w
, former_h
;
1472 #if !TARGET_API_MAC_OSX
1473 DoGetPosition( &former_x
, &former_y
) ;
1474 DoGetSize( &former_w
, &former_h
) ;
1476 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1479 int actualWidth
= width
;
1480 int actualHeight
= height
;
1484 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1485 actualWidth
= m_minWidth
;
1486 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1487 actualHeight
= m_minHeight
;
1488 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1489 actualWidth
= m_maxWidth
;
1490 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1491 actualHeight
= m_maxHeight
;
1493 bool doMove
= false ;
1494 bool doResize
= false ;
1496 if ( actualX
!= former_x
|| actualY
!= former_y
)
1500 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1505 if ( doMove
|| doResize
)
1507 // we don't adjust twice for the origin
1508 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1509 bool vis
= IsControlVisible( (ControlRef
) m_macControl
) ;
1510 #if TARGET_API_MAC_OSX
1511 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1513 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1514 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1515 HIViewSetFrame ( (ControlRef
) m_macControl
, &hir
) ;
1517 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1520 SetControlVisibility( (ControlRef
)m_macControl
, false , true ) ;
1521 SetControlBounds( (ControlRef
) m_macControl
, &r
) ;
1523 SetControlVisibility( (ControlRef
)m_macControl
, true , true ) ;
1525 MacRepositionScrollBars() ;
1528 wxPoint
point(actualX
,actualY
);
1529 wxMoveEvent
event(point
, m_windowId
);
1530 event
.SetEventObject(this);
1531 GetEventHandler()->ProcessEvent(event
) ;
1535 MacRepositionScrollBars() ;
1536 wxSize
size(actualWidth
, actualHeight
);
1537 wxSizeEvent
event(size
, m_windowId
);
1538 event
.SetEventObject(this);
1539 GetEventHandler()->ProcessEvent(event
);
1545 wxSize
wxWindowMac::DoGetBestSize() const
1547 if ( m_macIsUserPane
|| IsTopLevel() )
1548 return wxWindowBase::DoGetBestSize() ;
1550 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1551 short baselineoffset
;
1552 int bestWidth
, bestHeight
;
1553 ::GetBestControlRect( (ControlRef
) m_macControl
, &bestsize
, &baselineoffset
) ;
1555 if ( EmptyRect( &bestsize
) )
1558 bestsize
.left
= bestsize
.top
= 0 ;
1559 bestsize
.right
= 16 ;
1560 bestsize
.bottom
= 16 ;
1561 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1563 bestsize
.bottom
= 16 ;
1565 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1567 bestsize
.bottom
= 24 ;
1571 // return wxWindowBase::DoGetBestSize() ;
1575 bestWidth
= bestsize
.right
- bestsize
.left
;
1576 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1577 if ( bestHeight
< 10 )
1580 return wxSize(bestWidth
, bestHeight
);
1581 // return wxWindowBase::DoGetBestSize() ;
1585 // set the size of the window: if the dimensions are positive, just use them,
1586 // but if any of them is equal to -1, it means that we must find the value for
1587 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1588 // which case -1 is a valid value for x and y)
1590 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1591 // the width/height to best suit our contents, otherwise we reuse the current
1593 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1595 // get the current size and position...
1596 int currentX
, currentY
;
1597 GetPosition(¤tX
, ¤tY
);
1599 int currentW
,currentH
;
1600 GetSize(¤tW
, ¤tH
);
1602 // ... and don't do anything (avoiding flicker) if it's already ok
1603 if ( x
== currentX
&& y
== currentY
&&
1604 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1607 MacRepositionScrollBars() ; // we might have a real position shift
1611 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1613 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1616 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1618 wxSize
size(-1, -1);
1621 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1623 size
= DoGetBestSize();
1628 // just take the current one
1635 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1639 size
= DoGetBestSize();
1641 //else: already called DoGetBestSize() above
1647 // just take the current one
1652 DoMoveWindow(x
, y
, width
, height
);
1656 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1658 RgnHandle rgn
= NewRgn() ;
1660 GetControlRegion( (ControlRef
) m_macControl
, kControlContentMetaPart
, rgn
) ;
1661 GetRegionBounds( rgn
, &content
) ;
1663 #if !TARGET_API_MAC_OSX
1664 // if the content rgn is empty / not supported
1665 // don't attempt to correct the coordinates to wxWindow relative ones
1666 if (!::EmptyRect( &content
) )
1669 GetControlBounds( (ControlRef
) m_macControl
, &structure
) ;
1670 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1674 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1677 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1679 if ( clientheight
!= -1 || clientheight
!= -1 )
1681 int currentclientwidth
, currentclientheight
;
1682 int currentwidth
, currentheight
;
1684 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1685 GetSize( ¤twidth
, ¤theight
) ;
1687 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1688 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1692 void wxWindowMac::SetTitle(const wxString
& title
)
1694 m_label
= wxStripMenuCodes(title
) ;
1698 UMASetControlTitle( (ControlRef
) m_macControl
, m_label
, m_font
.GetEncoding() ) ;
1703 wxString
wxWindowMac::GetTitle() const
1708 bool wxWindowMac::Show(bool show
)
1710 if ( !wxWindowBase::Show(show
) )
1713 // TODO use visibilityChanged Carbon Event for OSX
1714 bool former
= MacIsReallyShown() ;
1716 SetControlVisibility( (ControlRef
) m_macControl
, show
, true ) ;
1717 if ( former
!= MacIsReallyShown() )
1718 MacPropagateVisibilityChanged() ;
1722 bool wxWindowMac::Enable(bool enable
)
1724 wxASSERT( m_macControl
!= NULL
) ;
1725 if ( !wxWindowBase::Enable(enable
) )
1728 bool former
= MacIsReallyEnabled() ;
1729 #if TARGET_API_MAC_OSX
1731 EnableControl( (ControlRef
) m_macControl
) ;
1733 DisableControl( (ControlRef
) m_macControl
) ;
1736 ActivateControl( (ControlRef
) m_macControl
) ;
1738 DeactivateControl( (ControlRef
) m_macControl
) ;
1741 if ( former
!= MacIsReallyEnabled() )
1742 MacPropagateEnabledStateChanged() ;
1747 // status change propagations (will be not necessary for OSX later )
1750 void wxWindowMac::MacPropagateVisibilityChanged()
1752 #if !TARGET_API_MAC_OSX
1753 MacVisibilityChanged() ;
1755 wxWindowListNode
*node
= GetChildren().GetFirst();
1758 wxWindowMac
*child
= node
->GetData();
1759 if ( child
->IsShown() )
1760 child
->MacPropagateVisibilityChanged( ) ;
1761 node
= node
->GetNext();
1766 void wxWindowMac::MacPropagateEnabledStateChanged( )
1768 #if !TARGET_API_MAC_OSX
1769 MacEnabledStateChanged() ;
1771 wxWindowListNode
*node
= GetChildren().GetFirst();
1774 wxWindowMac
*child
= node
->GetData();
1775 if ( child
->IsEnabled() )
1776 child
->MacPropagateEnabledStateChanged() ;
1777 node
= node
->GetNext();
1782 void wxWindowMac::MacPropagateHiliteChanged( )
1784 #if !TARGET_API_MAC_OSX
1785 MacHiliteChanged() ;
1787 wxWindowListNode
*node
= GetChildren().GetFirst();
1790 wxWindowMac
*child
= node
->GetData();
1791 // if ( child->IsEnabled() )
1792 child
->MacPropagateHiliteChanged() ;
1793 node
= node
->GetNext();
1799 // status change notifications
1802 void wxWindowMac::MacVisibilityChanged()
1806 void wxWindowMac::MacHiliteChanged()
1810 void wxWindowMac::MacEnabledStateChanged()
1815 // status queries on the inherited window's state
1818 bool wxWindowMac::MacIsReallyShown()
1820 // only under OSX the visibility of the TLW is taken into account
1821 #if TARGET_API_MAC_OSX
1822 return IsControlVisible( (ControlRef
) m_macControl
) ;
1824 wxWindow
* win
= this ;
1825 while( win
->IsShown() )
1827 if ( win
->IsTopLevel() )
1830 win
= win
->GetParent() ;
1839 bool wxWindowMac::MacIsReallyEnabled()
1841 #if TARGET_API_MAC_OSX
1842 return IsControlEnabled( (ControlRef
) m_macControl
) ;
1844 return IsControlActive( (ControlRef
) m_macControl
) ;
1848 bool wxWindowMac::MacIsReallyHilited()
1850 return IsControlActive( (ControlRef
) m_macControl
) ;
1857 int wxWindowMac::GetCharHeight() const
1859 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1860 return dc
.GetCharHeight() ;
1863 int wxWindowMac::GetCharWidth() const
1865 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1866 return dc
.GetCharWidth() ;
1869 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1870 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1872 const wxFont
*fontToUse
= theFont
;
1874 fontToUse
= &m_font
;
1876 wxClientDC
dc( (wxWindowMac
*) this ) ;
1878 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1879 if ( externalLeading
)
1880 *externalLeading
= le
;
1890 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1891 * we always intersect with the entire window, not only with the client area
1894 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1896 #if TARGET_API_MAC_OSX
1898 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
1901 RgnHandle update
= NewRgn() ;
1902 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1903 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1904 wxPoint origin
= GetClientAreaOrigin() ;
1905 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1906 HIViewSetNeedsDisplayInRegion( (ControlRef
) m_macControl
, update
, true ) ;
1910 RgnHandle updateRgn = NewRgn() ;
1913 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1917 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1918 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1920 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1921 DisposeRgn(updateRgn) ;
1923 if ( IsControlVisible( (ControlRef
) m_macControl
) )
1925 SetControlVisibility( (ControlRef
) m_macControl
, false , false ) ;
1926 SetControlVisibility( (ControlRef
) m_macControl
, true , true ) ;
1929 if ( MacGetTopLevelWindow() == NULL )
1932 if ( !IsControlVisible( (ControlRef) m_macControl ) )
1935 wxPoint client = GetClientAreaOrigin();
1938 int x2 = m_width - client.x;
1939 int y2 = m_height - client.y;
1941 if (IsKindOf( CLASSINFO(wxButton)))
1943 // buttons have an "aura"
1950 Rect clientrect = { y1, x1, y2, x2 };
1954 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1955 SectRect( &clientrect , &r , &clientrect ) ;
1958 if ( !EmptyRect( &clientrect ) )
1960 int top = 0 , left = 0 ;
1962 MacClientToRootWindow( &left , &top ) ;
1963 OffsetRect( &clientrect , left , top ) ;
1965 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1971 void wxWindowMac::Freeze()
1973 #if TARGET_API_MAC_OSX
1974 if ( !m_frozenness
++ )
1976 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, false ) ;
1981 #if TARGET_API_MAC_OSX
1982 static void InvalidateControlAndChildren( HIViewRef control
)
1984 HIViewSetNeedsDisplay( control
, true ) ;
1985 UInt16 childrenCount
= 0 ;
1986 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1987 if ( err
== errControlIsNotEmbedder
)
1989 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1991 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1994 err
= GetIndexedSubControl( control
, i
, & child
) ;
1995 if ( err
== errControlIsNotEmbedder
)
1997 InvalidateControlAndChildren( child
) ;
2002 void wxWindowMac::Thaw()
2004 #if TARGET_API_MAC_OSX
2005 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2007 if ( !--m_frozenness
)
2009 HIViewSetDrawingEnabled( (HIViewRef
) m_macControl
, true ) ;
2010 InvalidateControlAndChildren( (HIViewRef
) m_macControl
) ;
2011 // HIViewSetNeedsDisplay( (HIViewRef) m_macControl , true ) ;
2016 void wxWindowMac::MacRedrawControl()
2019 if ( (ControlRef) m_macControl && MacGetTopLevelWindowRef() && IsControlVisible( (ControlRef) m_macControl ) )
2021 #if TARGET_API_MAC_CARBON
2024 wxClientDC dc(this) ;
2025 wxMacPortSetter helper(&dc) ;
2026 wxMacWindowClipper clipper(this) ;
2027 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2028 UMADrawControl( (ControlRef) m_macControl ) ;
2035 void wxWindowMac::OnPaint(wxPaintEvent& event)
2037 // why don't we skip that here ?
2041 wxWindowMac
*wxGetActiveWindow()
2043 // actually this is a windows-only concept
2047 // Coordinates relative to the window
2048 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2050 // We really don't move the mouse programmatically under Mac.
2053 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2055 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2060 event
.GetDC()->Clear() ;
2063 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2065 wxWindowDC
dc(this) ;
2066 wxMacPortSetter
helper(&dc
) ;
2068 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2071 int wxWindowMac::GetScrollPos(int orient
) const
2073 if ( orient
== wxHORIZONTAL
)
2076 return m_hScrollBar
->GetThumbPosition() ;
2081 return m_vScrollBar
->GetThumbPosition() ;
2086 // This now returns the whole range, not just the number
2087 // of positions that we can scroll.
2088 int wxWindowMac::GetScrollRange(int orient
) const
2090 if ( orient
== wxHORIZONTAL
)
2093 return m_hScrollBar
->GetRange() ;
2098 return m_vScrollBar
->GetRange() ;
2103 int wxWindowMac::GetScrollThumb(int orient
) const
2105 if ( orient
== wxHORIZONTAL
)
2108 return m_hScrollBar
->GetThumbSize() ;
2113 return m_vScrollBar
->GetThumbSize() ;
2118 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2120 if ( orient
== wxHORIZONTAL
)
2123 m_hScrollBar
->SetThumbPosition( pos
) ;
2128 m_vScrollBar
->SetThumbPosition( pos
) ;
2132 void wxWindowMac::MacPaintBorders( int left
, int top
)
2138 wxGetOsVersion( &major
, &minor
);
2140 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2141 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2143 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2144 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2145 // OS X has lighter border edges than classic:
2148 darkShadow
.red
= 0x8E8E;
2149 darkShadow
.green
= 0x8E8E;
2150 darkShadow
.blue
= 0x8E8E;
2151 lightShadow
.red
= 0xBDBD;
2152 lightShadow
.green
= 0xBDBD;
2153 lightShadow
.blue
= 0xBDBD;
2159 GetSize( &w
, &h
) ;
2160 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2162 #if wxMAC_USE_THEME_BORDER
2163 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2166 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2167 InsetRect( &rect , border , border );
2168 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2171 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2173 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2174 RGBForeColor( &face
);
2175 MoveTo( left
+ 0 , top
+ h
- 2 );
2176 LineTo( left
+ 0 , top
+ 0 );
2177 LineTo( left
+ w
- 2 , top
+ 0 );
2179 MoveTo( left
+ 2 , top
+ h
- 3 );
2180 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2181 LineTo( left
+ w
- 3 , top
+ 2 );
2183 RGBForeColor( sunken
? &face
: &darkShadow
);
2184 MoveTo( left
+ 0 , top
+ h
- 1 );
2185 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2186 LineTo( left
+ w
- 1 , top
+ 0 );
2188 RGBForeColor( sunken
? &lightShadow
: &white
);
2189 MoveTo( left
+ 1 , top
+ h
- 3 );
2190 LineTo( left
+ 1, top
+ 1 );
2191 LineTo( left
+ w
- 3 , top
+ 1 );
2193 RGBForeColor( sunken
? &white
: &lightShadow
);
2194 MoveTo( left
+ 1 , top
+ h
- 2 );
2195 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2196 LineTo( left
+ w
- 2 , top
+ 1 );
2198 RGBForeColor( sunken
? &darkShadow
: &face
);
2199 MoveTo( left
+ 2 , top
+ h
- 4 );
2200 LineTo( left
+ 2 , top
+ 2 );
2201 LineTo( left
+ w
- 4 , top
+ 2 );
2204 else if (HasFlag(wxSIMPLE_BORDER
))
2206 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2207 RGBForeColor( &darkShadow
) ;
2208 FrameRect( &rect
) ;
2212 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2214 if ( child
== m_hScrollBar
)
2215 m_hScrollBar
= NULL
;
2216 if ( child
== m_vScrollBar
)
2217 m_vScrollBar
= NULL
;
2219 wxWindowBase::RemoveChild( child
) ;
2222 // New function that will replace some of the above.
2223 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2224 int range
, bool refresh
)
2226 if ( orient
== wxHORIZONTAL
)
2230 if ( range
== 0 || thumbVisible
>= range
)
2232 if ( m_hScrollBar
->IsShown() )
2233 m_hScrollBar
->Show(false) ;
2237 if ( !m_hScrollBar
->IsShown() )
2238 m_hScrollBar
->Show(true) ;
2239 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2247 if ( range
== 0 || thumbVisible
>= range
)
2249 if ( m_vScrollBar
->IsShown() )
2250 m_vScrollBar
->Show(false) ;
2254 if ( !m_vScrollBar
->IsShown() )
2255 m_vScrollBar
->Show(true) ;
2256 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2260 MacRepositionScrollBars() ;
2263 // Does a physical scroll
2264 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2266 if( dx
== 0 && dy
==0 )
2271 wxClientDC
dc(this) ;
2272 wxMacPortSetter
helper(&dc
) ;
2274 int width
, height
;
2275 GetClientSize( &width
, &height
) ;
2282 // TODO take out the boundaries
2283 GetControlBounds( (ControlRef
) m_macControl
, &scrollrect
);
2285 RgnHandle updateRgn
= NewRgn() ;
2288 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2289 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2290 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2292 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2294 //KO: The docs say ScrollRect creates an update region, which thus calls an update event
2295 // but it seems the update only refreshes the background of the control, rather than calling
2296 // kEventControlDraw, so we need to force a proper update here. There has to be a better
2297 // way of doing this... (Note that code below under !TARGET_CARBON does not work either...)
2300 // we also have to scroll the update rgn in this rectangle
2301 // in order not to loose updates
2303 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2304 RgnHandle formerUpdateRgn
= NewRgn() ;
2305 RgnHandle scrollRgn
= NewRgn() ;
2306 RectRgn( scrollRgn
, &scrollrect
) ;
2307 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2309 LocalToGlobal( &pt
) ;
2310 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2311 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2312 if ( !EmptyRgn( formerUpdateRgn
) )
2314 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2315 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2316 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2318 InvalWindowRgn(rootWindow
, updateRgn
) ;
2319 DisposeRgn( updateRgn
) ;
2320 DisposeRgn( formerUpdateRgn
) ;
2321 DisposeRgn( scrollRgn
) ;
2325 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2327 wxWindowMac
*child
= node
->GetData();
2328 if (child
== m_vScrollBar
) continue;
2329 if (child
== m_hScrollBar
) continue;
2330 if (child
->IsTopLevel()) continue;
2333 child
->GetPosition( &x
, &y
);
2335 child
->GetSize( &w
, &h
);
2339 if (rect
->Intersects(rc
))
2340 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2344 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2348 // TODO remove, was moved higher up Update() ;
2352 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2354 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2356 wxScrollWinEvent wevent
;
2357 wevent
.SetPosition(event
.GetPosition());
2358 wevent
.SetOrientation(event
.GetOrientation());
2359 wevent
.m_eventObject
= this;
2361 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2362 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2363 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2364 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2365 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2366 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2367 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2368 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2369 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2370 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2371 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2372 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2373 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2374 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2375 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2378 GetEventHandler()->ProcessEvent(wevent
);
2382 // Get the window with the focus
2383 wxWindowMac
*wxWindowBase::FindFocus()
2385 ControlRef control
;
2386 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2387 return wxFindControlFromMacControl( control
) ;
2390 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2392 // panel wants to track the window which was the last to have focus in it,
2393 // so we want to set ourselves as the window which last had focus
2395 // notice that it's also important to do it upwards the tree becaus
2396 // otherwise when the top level panel gets focus, it won't set it back to
2397 // us, but to some other sibling
2399 // CS:don't know if this is still needed:
2400 //wxChildFocusEvent eventFocus(this);
2401 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2406 void wxWindowMac::OnInternalIdle()
2408 // This calls the UI-update mechanism (querying windows for
2409 // menu/toolbar/control state information)
2410 if (wxUpdateUIEvent::CanUpdate(this))
2411 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2414 // Raise the window to the top of the Z order
2415 void wxWindowMac::Raise()
2417 #if TARGET_API_MAC_OSX
2418 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderAbove
, NULL
) ;
2422 // Lower the window to the bottom of the Z order
2423 void wxWindowMac::Lower()
2425 #if TARGET_API_MAC_OSX
2426 HIViewSetZOrder((ControlRef
)m_macControl
,kHIViewZOrderBelow
, NULL
) ;
2431 // static wxWindow *gs_lastWhich = NULL;
2433 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2435 // first trigger a set cursor event
2437 wxPoint clientorigin
= GetClientAreaOrigin() ;
2438 wxSize clientsize
= GetClientSize() ;
2440 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2442 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2444 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2445 if ( processedEvtSetCursor
&& event
.HasCursor() )
2447 cursor
= event
.GetCursor() ;
2452 // the test for processedEvtSetCursor is here to prevent using m_cursor
2453 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2454 // it - this is a way to say that our cursor shouldn't be used for this
2456 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2466 cursor
= *wxSTANDARD_CURSOR
;
2470 cursor
.MacInstall() ;
2472 return cursor
.Ok() ;
2475 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2479 return m_tooltip
->GetTip() ;
2481 return wxEmptyString
;
2484 void wxWindowMac::Update()
2486 #if TARGET_API_MAC_OSX
2487 HIViewSetNeedsDisplay( (ControlRef
) m_macControl
, true ) ;
2489 ::Draw1Control( (ControlRef
) m_macControl
) ;
2493 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2495 wxTopLevelWindowMac
* win
= NULL
;
2496 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2499 win
= wxFindWinFromMacWindow( window
) ;
2503 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2507 RgnHandle visRgn
= NewRgn() ;
2508 RgnHandle tempRgn
= NewRgn() ;
2509 if ( IsControlVisible( (ControlRef
) m_macControl
) )
2511 GetControlBounds( (ControlRef
) m_macControl
, &r
) ;
2512 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2514 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2515 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2524 if ( includeOuterStructures
)
2525 InsetRect( &r
, -3 , -3 ) ;
2526 RectRgn( visRgn
, &r
) ;
2527 if ( !IsTopLevel() )
2529 wxWindow
* child
= this ;
2530 wxWindow
* parent
= child
->GetParent() ;
2535 // we have to find a better clipping algorithm here, in order not to clip things
2536 // positioned like status and toolbar
2537 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2539 size
= parent
->GetSize() ;
2544 size
= parent
->GetClientSize() ;
2545 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2549 parent
->MacWindowToRootWindow( &x
, &y
) ;
2550 MacRootWindowToWindow( &x
, &y
) ;
2552 SetRectRgn( tempRgn
,
2553 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2554 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2555 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2557 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2558 if ( parent
->IsTopLevel() )
2561 parent
= child
->GetParent() ;
2566 wxRegion vis
= visRgn
;
2567 DisposeRgn( visRgn
) ;
2568 DisposeRgn( tempRgn
) ;
2573 This function must not change the updatergn !
2575 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2577 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2578 bool handled
= false ;
2580 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2582 RgnHandle newupdate
= NewRgn() ;
2583 wxSize point
= GetClientSize() ;
2584 wxPoint origin
= GetClientAreaOrigin() ;
2585 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2586 SectRgn( newupdate
, updatergn
, newupdate
) ;
2587 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2588 m_updateRegion
= newupdate
;
2589 DisposeRgn( newupdate
) ;
2592 if ( !EmptyRgn(updatergn
) )
2594 wxWindowDC
dc(this);
2595 if (!EmptyRgn(updatergn
))
2596 dc
.SetClippingRegion(wxRegion(updatergn
));
2598 wxEraseEvent
eevent( GetId(), &dc
);
2599 eevent
.SetEventObject( this );
2600 GetEventHandler()->ProcessEvent( eevent
);
2602 if ( !m_updateRegion
.Empty() )
2604 // paint the window itself
2606 event
.m_timeStamp
= time
;
2607 event
.SetEventObject(this);
2608 handled
= GetEventHandler()->ProcessEvent(event
);
2610 // paint custom borders
2611 wxNcPaintEvent
eventNc( GetId() );
2612 eventNc
.SetEventObject( this );
2613 GetEventHandler()->ProcessEvent( eventNc
);
2619 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2621 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2622 // updatergn is always already clipped to our boundaries
2623 // if we are in compositing mode then it is in relative to the upper left of the control
2624 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2625 // of the toplevel window
2626 // it is in window coordinates, not in client coordinates
2628 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2629 RgnHandle ownUpdateRgn
= NewRgn() ;
2630 CopyRgn( updatergn
, ownUpdateRgn
) ;
2632 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2635 UMAGetControlBoundsInWindowCoords( (ControlRef
)m_macControl
, &bounds
);
2636 RgnHandle controlRgn
= NewRgn();
2637 RectRgn( controlRgn
, &bounds
);
2638 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2639 // the window update region
2640 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2641 DisposeRgn( controlRgn
);
2643 //KO: convert ownUpdateRgn to local coordinates
2644 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2647 MacDoRedraw( ownUpdateRgn
, time
) ;
2648 DisposeRgn( ownUpdateRgn
) ;
2652 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2654 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2658 if ( iter
->IsTopLevel() )
2659 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2661 iter
= iter
->GetParent() ;
2663 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2667 void wxWindowMac::MacCreateScrollBars( long style
)
2669 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2671 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2672 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2674 GetClientSize( &width
, &height
) ;
2676 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2677 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2678 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2679 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2681 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2682 vSize
, wxVERTICAL
);
2684 if ( style
& wxVSCROLL
)
2690 m_vScrollBar
->Show(false) ;
2692 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2693 hSize
, wxHORIZONTAL
);
2694 if ( style
& wxHSCROLL
)
2699 m_hScrollBar
->Show(false) ;
2702 // because the create does not take into account the client area origin
2703 MacRepositionScrollBars() ; // we might have a real position shift
2706 void wxWindowMac::MacRepositionScrollBars()
2708 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2709 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2711 // get real client area
2715 GetSize( &width
, &height
) ;
2717 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2718 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2720 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2721 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2722 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2723 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2729 GetSize( &w
, &h
) ;
2731 MacClientToRootWindow( &x
, &y
) ;
2732 MacClientToRootWindow( &w
, &h
) ;
2734 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2736 int totW
= 10000 , totH
= 10000;
2739 if ( iter
->IsTopLevel() )
2741 iter
->GetSize( &totW
, &totH
) ;
2745 iter
= iter
->GetParent() ;
2773 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2777 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2781 bool wxWindowMac::AcceptsFocus() const
2783 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2786 void wxWindowMac::MacSuperChangedPosition()
2788 // only window-absolute structures have to be moved i.e. controls
2790 wxWindowListNode
*node
= GetChildren().GetFirst();
2793 wxWindowMac
*child
= node
->GetData();
2794 child
->MacSuperChangedPosition() ;
2795 node
= node
->GetNext();
2799 void wxWindowMac::MacTopLevelWindowChangedPosition()
2801 // only screen-absolute structures have to be moved i.e. glcanvas
2803 wxWindowListNode
*node
= GetChildren().GetFirst();
2806 wxWindowMac
*child
= node
->GetData();
2807 child
->MacTopLevelWindowChangedPosition() ;
2808 node
= node
->GetNext();
2812 long wxWindowMac::MacGetLeftBorderSize( ) const
2817 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2820 #if wxMAC_USE_THEME_BORDER
2821 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2825 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2828 #if wxMAC_USE_THEME_BORDER
2829 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2833 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2840 long wxWindowMac::MacGetRightBorderSize( ) const
2842 // they are all symmetric in mac themes
2843 return MacGetLeftBorderSize() ;
2846 long wxWindowMac::MacGetTopBorderSize( ) const
2848 // they are all symmetric in mac themes
2849 return MacGetLeftBorderSize() ;
2852 long wxWindowMac::MacGetBottomBorderSize( ) const
2854 // they are all symmetric in mac themes
2855 return MacGetLeftBorderSize() ;
2858 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2860 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2863 // Find the wxWindowMac at the current mouse position, returning the mouse
2865 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2867 pt
= wxGetMousePosition();
2868 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2872 // Get the current mouse position.
2873 wxPoint
wxGetMousePosition()
2876 wxGetMousePosition(& x
, & y
);
2877 return wxPoint(x
, y
);
2880 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2882 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2884 // copied from wxGTK : CS
2885 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2888 // (a) it's a command event and so is propagated to the parent
2889 // (b) under MSW it can be generated from kbd too
2890 // (c) it uses screen coords (because of (a))
2891 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2893 this->ClientToScreen(event
.GetPosition()));
2894 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2903 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2907 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2911 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2912 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2916 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2918 return eventNotHandledErr
;