1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
49 #define MAC_SCROLLBAR_SIZE 16
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 // TODO EVT_PAINT(wxWindowMac::OnPaint)
85 EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged
)
86 EVT_INIT_DIALOG(wxWindowMac::OnInitDialog
)
87 // EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
88 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
93 #define wxMAC_DEBUG_REDRAW 0
94 #ifndef wxMAC_DEBUG_REDRAW
95 #define wxMAC_DEBUG_REDRAW 0
98 #define wxMAC_USE_THEME_BORDER 0
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
105 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
107 #if TARGET_API_MAC_OSX
109 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
111 kEventControlVisibilityChanged
= 157
117 static const EventTypeSpec eventList
[] =
119 { kEventClassControl
, kEventControlHit
} ,
120 #if TARGET_API_MAC_OSX
121 { kEventClassControl
, kEventControlDraw
} ,
122 { kEventClassControl
, kEventControlVisibilityChanged
} ,
123 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
124 { kEventClassControl
, kEventControlHiliteChanged
} ,
125 { kEventClassControl
, kEventControlSetFocusPart
} ,
127 { kEventClassService
, kEventServiceGetTypes
},
128 { kEventClassService
, kEventServiceCopy
},
129 { kEventClassService
, kEventServicePaste
},
131 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
132 // { kEventClassControl , kEventControlBoundsChanged } ,
136 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
138 OSStatus result
= eventNotHandledErr
;
140 wxMacCarbonEvent
cEvent( event
) ;
142 ControlRef controlRef
;
143 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
145 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
147 switch( GetEventKind( event
) )
149 #if TARGET_API_MAC_OSX
150 case kEventControlDraw
:
152 RgnHandle updateRgn
= NULL
;
154 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
155 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
157 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
159 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
162 // in case we would need a coregraphics compliant background erase first
163 // now usable to track redraws
164 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
165 if ( thisWindow
->MacIsUserPane() )
167 static float color
= 0.5 ;
170 HIViewGetBounds( controlRef
, &bounds
);
171 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
172 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
173 CGContextFillRect( cgContext
, bounds
);
184 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
188 case kEventControlVisibilityChanged
:
189 thisWindow
->MacVisibilityChanged() ;
191 case kEventControlEnabledStateChanged
:
192 thisWindow
->MacEnabledStateChanged() ;
194 case kEventControlHiliteChanged
:
195 thisWindow
->MacHiliteChanged() ;
197 case kEventControlSetFocusPart
:
199 Boolean focusEverything
= false ;
200 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
201 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
204 if ( controlPart
== kControlFocusNoPart
)
207 if ( thisWindow
->GetCaret() )
209 thisWindow
->GetCaret()->OnKillFocus();
211 #endif // wxUSE_CARET
212 wxFocusEvent
event(wxEVT_KILL_FOCUS
, thisWindow
->GetId());
213 event
.SetEventObject(thisWindow
);
214 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
218 // panel wants to track the window which was the last to have focus in it
219 wxChildFocusEvent
eventFocus(thisWindow
);
220 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
223 if ( thisWindow
->GetCaret() )
225 thisWindow
->GetCaret()->OnSetFocus();
227 #endif // wxUSE_CARET
229 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
230 event
.SetEventObject(thisWindow
);
231 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
233 if ( thisWindow
->MacIsUserPane() )
238 case kEventControlHit
:
240 result
= thisWindow
->MacControlHit( handler
, event
) ;
249 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
251 OSStatus result
= eventNotHandledErr
;
253 wxMacCarbonEvent
cEvent( event
) ;
255 ControlRef controlRef
;
256 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
257 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
258 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
260 switch( GetEventKind( event
) )
262 case kEventServiceGetTypes
:
266 textCtrl
->GetSelection( &from
, &to
) ;
268 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
270 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
271 if ( textCtrl
->IsEditable() )
272 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
274 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
275 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
277 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
281 CFArrayAppendValue (copyTypes
, typestring
) ;
283 CFArrayAppendValue (pasteTypes
, typestring
) ;
284 CFRelease( typestring
) ;
290 case kEventServiceCopy
:
294 textCtrl
->GetSelection( &from
, &to
) ;
295 wxString val
= textCtrl
->GetValue() ;
296 val
= val
.Mid( from
, to
- from
) ;
297 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
298 verify_noerr( ClearScrap( &scrapRef
) ) ;
299 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
303 case kEventServicePaste
:
306 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
307 Size textSize
, pastedSize
;
308 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
310 char *content
= new char[textSize
] ;
311 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
312 content
[textSize
-1] = 0 ;
314 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
316 textCtrl
->WriteText( wxString( content
) ) ;
327 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
329 OSStatus result
= eventNotHandledErr
;
331 switch ( GetEventClass( event
) )
333 case kEventClassControl
:
334 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
336 case kEventClassService
:
337 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
344 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
346 // ---------------------------------------------------------------------------
347 // UserPane events for non OSX builds
348 // ---------------------------------------------------------------------------
350 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
352 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
353 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
354 win
->MacControlUserPaneDrawProc(part
) ;
357 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
359 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
360 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
361 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
364 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
366 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
367 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
368 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
371 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
373 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
374 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
375 win
->MacControlUserPaneIdleProc() ;
378 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
380 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
381 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
382 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
385 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
387 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
388 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
389 win
->MacControlUserPaneActivateProc(activating
) ;
392 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
394 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
395 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
396 return win
->MacControlUserPaneFocusProc(action
) ;
399 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
401 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
402 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
403 win
->MacControlUserPaneBackgroundProc(info
) ;
406 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
408 RgnHandle rgn
= NewRgn() ;
410 wxMacWindowStateSaver
sv( this ) ;
411 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
412 MacDoRedraw( rgn
, 0 ) ;
416 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
418 return kControlNoPart
;
421 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
423 return kControlNoPart
;
426 void wxWindowMac::MacControlUserPaneIdleProc()
430 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
432 return kControlNoPart
;
435 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
439 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
441 return kControlNoPart
;
444 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
448 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
449 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
450 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
451 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
452 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
453 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
454 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
455 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
457 // ===========================================================================
459 // ===========================================================================
461 wxList
wxWinMacControlList(wxKEY_INTEGER
);
463 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
465 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
468 return (wxControl
*)node
->GetData();
471 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
473 // adding NULL ControlRef is (first) surely a result of an error and
474 // (secondly) breaks native event processing
475 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
477 if ( !wxWinMacControlList
.Find((long)inControl
) )
478 wxWinMacControlList
.Append((long)inControl
, control
);
481 void wxRemoveMacControlAssociation(wxWindow
*control
)
483 wxWinMacControlList
.DeleteObject(control
);
487 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
489 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
491 // we have to setup the brush in the current port and return noErr
492 // or return an error code so that the control manager walks further up the
493 // hierarchy to find a correct background
495 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
497 OSStatus status
= paramErr
;
500 case kControlMsgApplyTextColor
:
502 case kControlMsgSetUpBackground
:
504 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
508 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
512 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
514 // this clipping is only needed for non HIView
516 RgnHandle clip
= NewRgn() ;
519 wx
->MacWindowToRootWindow( &x
,&y
) ;
520 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
521 OffsetRgn( clip
, x
, y
) ;
528 else if ( wx->MacIsUserPane() )
530 // if we don't have a valid brush for such a control, we have to call the
531 // setup of our parent ourselves
532 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
545 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
546 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
550 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
553 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
558 // ----------------------------------------------------------------------------
559 // constructors and such
560 // ----------------------------------------------------------------------------
562 wxWindowMac::wxWindowMac()
567 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
572 const wxString
& name
)
575 Create(parent
, id
, pos
, size
, style
, name
);
578 void wxWindowMac::Init()
582 #if WXWIN_COMPATIBILITY_2_4
583 m_backgroundTransparent
= FALSE
;
586 // as all windows are created with WS_VISIBLE style...
589 m_hScrollBar
= NULL
;
590 m_vScrollBar
= NULL
;
591 m_macBackgroundBrush
= wxNullBrush
;
593 m_macIsUserPane
= TRUE
;
595 // make sure all proc ptrs are available
597 if ( gControlUserPaneDrawUPP
== NULL
)
599 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
600 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
601 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
602 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
603 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
604 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
605 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
606 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
608 if ( wxMacLiveScrollbarActionUPP
== NULL
)
610 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
613 if ( wxMacSetupControlBackgroundUPP
== NULL
)
615 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
618 // we need a valid font for the encodings
619 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
623 wxWindowMac::~wxWindowMac()
627 m_isBeingDeleted
= TRUE
;
629 #ifndef __WXUNIVERSAL__
630 // VS: make sure there's no wxFrame with last focus set to us:
631 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
633 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
636 if ( frame
->GetLastFocus() == this )
638 frame
->SetLastFocus((wxWindow
*)NULL
);
643 #endif // __WXUNIVERSAL__
645 // wxRemoveMacControlAssociation( this ) ;
646 // If we delete an item, we should initialize the parent panel,
647 // because it could now be invalid.
648 wxWindow
*parent
= GetParent() ;
651 if (parent
->GetDefaultItem() == (wxButton
*) this)
652 parent
->SetDefaultItem(NULL
);
654 if ( m_peer
&& m_peer
->Ok() )
656 // in case the callback might be called during destruction
657 wxRemoveMacControlAssociation( this) ;
658 ::SetControlColorProc( *m_peer
, NULL
) ;
659 ::DisposeControl( *m_peer
) ;
662 if ( g_MacLastWindow
== this )
664 g_MacLastWindow
= NULL
;
667 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
670 if ( frame
->GetLastFocus() == this )
671 frame
->SetLastFocus( NULL
) ;
676 // delete our drop target if we've got one
677 #if wxUSE_DRAG_AND_DROP
678 if ( m_dropTarget
!= NULL
)
683 #endif // wxUSE_DRAG_AND_DROP
687 WXWidget
wxWindowMac::GetHandle() const
689 return (WXWidget
) (ControlRef
) *m_peer
;
693 void wxWindowMac::MacInstallEventHandler()
695 wxAssociateControlWithMacControl( *m_peer
, this ) ;
696 InstallControlEventHandler( *m_peer
, GetwxMacWindowEventHandlerUPP(),
697 GetEventTypeCount(eventList
), eventList
, this,
698 (EventHandlerRef
*)&m_macControlEventHandler
);
703 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
707 const wxString
& name
)
709 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
711 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
714 parent
->AddChild(this);
716 m_windowVariant
= parent
->GetWindowVariant() ;
718 if ( m_macIsUserPane
)
720 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
723 | kControlSupportsEmbedding
724 // | kControlSupportsLiveFeedback
725 // | kControlHasSpecialBackground
726 // | kControlSupportsCalcBestRect
727 // | kControlHandlesTracking
728 | kControlSupportsFocus
729 // | kControlWantsActivate
730 // | kControlWantsIdle
733 m_peer
= new wxMacControl() ;
734 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, *m_peer
);
737 MacPostControlCreate(pos
,size
) ;
738 #if !TARGET_API_MAC_OSX
739 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneDrawProcTag
,
740 sizeof(gControlUserPaneDrawUPP
),(Ptr
) &gControlUserPaneDrawUPP
);
741 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneHitTestProcTag
,
742 sizeof(gControlUserPaneHitTestUPP
),(Ptr
) &gControlUserPaneHitTestUPP
);
743 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneTrackingProcTag
,
744 sizeof(gControlUserPaneTrackingUPP
),(Ptr
) &gControlUserPaneTrackingUPP
);
745 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneIdleProcTag
,
746 sizeof(gControlUserPaneIdleUPP
),(Ptr
) &gControlUserPaneIdleUPP
);
747 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneKeyDownProcTag
,
748 sizeof(gControlUserPaneKeyDownUPP
),(Ptr
) &gControlUserPaneKeyDownUPP
);
749 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneActivateProcTag
,
750 sizeof(gControlUserPaneActivateUPP
),(Ptr
) &gControlUserPaneActivateUPP
);
751 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneFocusProcTag
,
752 sizeof(gControlUserPaneFocusUPP
),(Ptr
) &gControlUserPaneFocusUPP
);
753 SetControlData(*m_peer
,kControlEntireControl
,kControlUserPaneBackgroundProcTag
,
754 sizeof(gControlUserPaneBackgroundUPP
),(Ptr
) &gControlUserPaneBackgroundUPP
);
757 #ifndef __WXUNIVERSAL__
758 // Don't give scrollbars to wxControls unless they ask for them
759 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
760 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
762 MacCreateScrollBars( style
) ;
766 wxWindowCreateEvent
event(this);
767 GetEventHandler()->AddPendingEvent(event
);
772 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
774 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
776 ::SetControlReference( *m_peer
, (long) this ) ;
778 MacInstallEventHandler();
780 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
781 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
782 ::EmbedControl( *m_peer
, container
) ;
784 // adjust font, controlsize etc
785 DoSetWindowVariant( m_windowVariant
) ;
787 #if !TARGET_API_MAC_OSX
788 // eventually we can fix some clipping issues be reactivating this hook
789 //if ( m_macIsUserPane )
790 // SetControlColorProc( *m_peer , wxMacSetupControlBackgroundUPP ) ;
793 UMASetControlTitle( *m_peer
, wxStripMenuCodes(m_label
) , m_font
.GetEncoding() ) ;
795 if (!m_macIsUserPane
)
797 SetInitialBestSize(size
);
800 SetCursor( *wxSTANDARD_CURSOR
) ;
803 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
805 // Don't assert, in case we set the window variant before
806 // the window is created
807 // wxASSERT( m_peer->Ok() ) ;
809 m_windowVariant
= variant
;
811 if (m_peer
== NULL
|| !m_peer
->Ok())
815 ThemeFontID themeFont
= kThemeSystemFont
;
817 // we will get that from the settings later
818 // and make this NORMAL later, but first
819 // we have a few calculations that we must fix
823 case wxWINDOW_VARIANT_NORMAL
:
824 size
= kControlSizeNormal
;
825 themeFont
= kThemeSystemFont
;
827 case wxWINDOW_VARIANT_SMALL
:
828 size
= kControlSizeSmall
;
829 themeFont
= kThemeSmallSystemFont
;
831 case wxWINDOW_VARIANT_MINI
:
832 if (UMAGetSystemVersion() >= 0x1030 )
834 // not always defined in the headers
840 size
= kControlSizeSmall
;
841 themeFont
= kThemeSmallSystemFont
;
844 case wxWINDOW_VARIANT_LARGE
:
845 size
= kControlSizeLarge
;
846 themeFont
= kThemeSystemFont
;
849 wxFAIL_MSG(_T("unexpected window variant"));
852 ::SetControlData( *m_peer
, kControlEntireControl
, kControlSizeTag
, sizeof( ControlSize
), &size
);
855 font
.MacCreateThemeFont( themeFont
) ;
859 void wxWindowMac::MacUpdateControlFont()
861 ControlFontStyleRec fontStyle
;
862 wxFont myfont
= GetFont();
863 if ( myfont
.MacGetThemeFontID() != kThemeCurrentPortFont
)
865 switch( myfont
.MacGetThemeFontID() )
867 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
868 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
869 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
870 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
872 fontStyle
.flags
= kControlUseFontMask
;
876 fontStyle
.font
= myfont
.MacGetFontNum() ;
877 fontStyle
.style
= myfont
.MacGetFontStyle() ;
878 fontStyle
.size
= myfont
.MacGetFontSize() ;
879 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
882 fontStyle
.just
= teJustLeft
;
883 fontStyle
.flags
|= kControlUseJustMask
;
884 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
885 fontStyle
.just
= teJustCenter
;
886 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
887 fontStyle
.just
= teJustRight
;
890 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
891 // won't get grayed out by the system anymore
893 if ( GetForegroundColour() != *wxBLACK
)
895 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
896 fontStyle
.flags
|= kControlUseForeColorMask
;
899 ::SetControlFontStyle( *m_peer
, &fontStyle
);
903 bool wxWindowMac::SetFont(const wxFont
& font
)
905 bool retval
= !wxWindowBase::SetFont( font
) ;
907 MacUpdateControlFont() ;
912 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
914 if ( !wxWindowBase::SetForegroundColour(col
) )
917 MacUpdateControlFont() ;
922 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
924 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
928 wxColour
newCol(GetBackgroundColour());
929 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
931 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
933 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
935 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
939 brush
.SetColour( newCol
) ;
941 MacSetBackgroundBrush( brush
) ;
943 MacUpdateControlFont() ;
949 bool wxWindowMac::MacCanFocus() const
951 // there is currently no way to determine whether the window is running in full keyboard
952 // access mode, therefore we cannot rely on these features, yet the only other way would be
953 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
954 // in event handlers...
955 UInt32 features
= 0 ;
956 GetControlFeatures( *m_peer
, &features
) ;
957 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
961 void wxWindowMac::SetFocus()
963 if ( AcceptsFocus() )
965 #if !TARGET_API_MAC_OSX
966 wxWindow
* former
= FindFocus() ;
968 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
969 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
970 // leave in case of an error
971 if ( err
== errCouldntSetFocus
)
974 #if !TARGET_API_MAC_OSX
975 // emulate carbon events when running under carbonlib where they are not natively available
978 EventRef evRef
= NULL
;
979 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
982 wxMacCarbonEvent
cEvent( evRef
) ;
983 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
984 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
986 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
987 ReleaseEvent(evRef
) ;
989 // send new focus event
991 EventRef evRef
= NULL
;
992 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
995 wxMacCarbonEvent
cEvent( evRef
) ;
996 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
997 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
999 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1000 ReleaseEvent(evRef
) ;
1007 void wxWindowMac::DoCaptureMouse()
1009 wxTheApp
->s_captureWindow
= this ;
1012 wxWindow
* wxWindowBase::GetCapture()
1014 return wxTheApp
->s_captureWindow
;
1017 void wxWindowMac::DoReleaseMouse()
1019 wxTheApp
->s_captureWindow
= NULL
;
1022 #if wxUSE_DRAG_AND_DROP
1024 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1026 if ( m_dropTarget
!= 0 ) {
1027 delete m_dropTarget
;
1030 m_dropTarget
= pDropTarget
;
1031 if ( m_dropTarget
!= 0 )
1039 // Old style file-manager drag&drop
1040 void wxWindowMac::DragAcceptFiles(bool accept
)
1045 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1046 int& w
, int& h
) const
1049 GetControlBounds( *m_peer
, &bounds
) ;
1054 w
= bounds
.right
- bounds
.left
;
1055 h
= bounds
.bottom
- bounds
.top
;
1057 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1060 Point tlworigin
= { 0 , 0 } ;
1061 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1067 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1070 int& w
, int& h
, bool adjustOrigin
) const
1074 // todo the default calls may be used as soon as PostCreateControl Is moved here
1075 w
= size
.x
; // WidthDefault( size.x );
1076 h
= size
.y
; // HeightDefault( size.y ) ;
1077 #if !TARGET_API_MAC_OSX
1078 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1081 AdjustForParentClientOrigin( x
, y
) ;
1086 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1088 #if TARGET_API_MAC_OSX
1089 int x1
, y1
, w1
,h1
;
1090 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1096 GetControlBounds( *m_peer
, &bounds
) ;
1097 if(x
) *x
= bounds
.right
- bounds
.left
;
1098 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1102 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1104 #if TARGET_API_MAC_OSX
1105 int x1
, y1
, w1
,h1
;
1106 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1107 if ( !IsTopLevel() )
1109 wxWindow
*parent
= GetParent();
1112 wxPoint
pt(parent
->GetClientAreaOrigin());
1121 GetControlBounds( *m_peer
, &bounds
) ;
1122 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1124 int xx
= bounds
.left
;
1125 int yy
= bounds
.top
;
1127 if ( !GetParent()->IsTopLevel() )
1129 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1135 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1144 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1146 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1148 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1151 Point localwhere
= {0,0} ;
1153 if(x
) localwhere
.h
= * x
;
1154 if(y
) localwhere
.v
= * y
;
1156 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1157 if(x
) *x
= localwhere
.h
;
1158 if(y
) *y
= localwhere
.v
;
1161 MacRootWindowToWindow( x
, y
) ;
1163 wxPoint origin
= GetClientAreaOrigin() ;
1164 if(x
) *x
-= origin
.x
;
1165 if(y
) *y
-= origin
.y
;
1168 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1170 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1171 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1173 wxPoint origin
= GetClientAreaOrigin() ;
1174 if(x
) *x
+= origin
.x
;
1175 if(y
) *y
+= origin
.y
;
1177 MacWindowToRootWindow( x
, y
) ;
1180 Point localwhere
= { 0,0 };
1181 if(x
) localwhere
.h
= * x
;
1182 if(y
) localwhere
.v
= * y
;
1183 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1184 if(x
) *x
= localwhere
.h
;
1185 if(y
) *y
= localwhere
.v
;
1189 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1191 wxPoint origin
= GetClientAreaOrigin() ;
1192 if(x
) *x
+= origin
.x
;
1193 if(y
) *y
+= origin
.y
;
1195 MacWindowToRootWindow( x
, y
) ;
1198 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1200 MacRootWindowToWindow( x
, y
) ;
1202 wxPoint origin
= GetClientAreaOrigin() ;
1203 if(x
) *x
-= origin
.x
;
1204 if(y
) *y
-= origin
.y
;
1207 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1209 #if TARGET_API_MAC_OSX
1211 if ( x
) pt
.x
= *x
;
1212 if ( y
) pt
.y
= *y
;
1214 if ( !IsTopLevel() )
1216 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1218 HIViewConvertPoint( &pt
, *m_peer
, (ControlRef
) top
->GetHandle() ) ;
1221 if ( x
) *x
= (int) pt
.x
;
1222 if ( y
) *y
= (int) pt
.y
;
1224 if ( !IsTopLevel() )
1227 GetControlBounds( *m_peer
, &bounds
) ;
1228 if(x
) *x
+= bounds
.left
;
1229 if(y
) *y
+= bounds
.top
;
1234 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1239 MacWindowToRootWindow( &x1
, &y1
) ;
1244 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1246 #if TARGET_API_MAC_OSX
1248 if ( x
) pt
.x
= *x
;
1249 if ( y
) pt
.y
= *y
;
1251 if ( !IsTopLevel() )
1252 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , *m_peer
) ;
1254 if ( x
) *x
= (int) pt
.x
;
1255 if ( y
) *y
= (int) pt
.y
;
1257 if ( !IsTopLevel() )
1260 GetControlBounds( *m_peer
, &bounds
) ;
1261 if(x
) *x
-= bounds
.left
;
1262 if(y
) *y
-= bounds
.top
;
1267 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1272 MacRootWindowToWindow( &x1
, &y1
) ;
1277 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1279 RgnHandle rgn
= NewRgn() ;
1281 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1283 GetRegionBounds( rgn
, &content
) ;
1288 GetControlBounds( *m_peer
, &content
) ;
1291 GetControlBounds( *m_peer
, &structure
) ;
1292 #if !TARGET_API_MAC_OSX
1293 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1295 left
= content
.left
- structure
.left
;
1296 top
= content
.top
- structure
.top
;
1297 right
= structure
.right
- content
.right
;
1298 bottom
= structure
.bottom
- content
.bottom
;
1301 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1303 wxSize sizeTotal
= size
;
1305 RgnHandle rgn
= NewRgn() ;
1309 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1311 GetRegionBounds( rgn
, &content
) ;
1316 GetControlBounds( *m_peer
, &content
) ;
1319 GetControlBounds( *m_peer
, &structure
) ;
1320 #if !TARGET_API_MAC_OSX
1321 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1324 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1325 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1327 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1328 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1334 // Get size *available for subwindows* i.e. excluding menu bar etc.
1335 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1339 RgnHandle rgn
= NewRgn() ;
1341 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1343 GetRegionBounds( rgn
, &content
) ;
1348 GetControlBounds( *m_peer
, &content
) ;
1350 #if !TARGET_API_MAC_OSX
1352 GetControlBounds( *m_peer
, &structure
) ;
1353 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1355 ww
= content
.right
- content
.left
;
1356 hh
= content
.bottom
- content
.top
;
1358 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1359 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1361 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1367 GetSize( &w
, &h
) ;
1369 MacClientToRootWindow( &x1
, &y1
) ;
1370 MacClientToRootWindow( &w
, &h
) ;
1372 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1374 int totW
= 10000 , totH
= 10000;
1377 if ( iter
->IsTopLevel() )
1379 iter
->GetSize( &totW
, &totH
) ;
1383 iter
= iter
->GetParent() ;
1386 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1388 hh
-= MAC_SCROLLBAR_SIZE
;
1394 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1396 ww
-= MAC_SCROLLBAR_SIZE
;
1408 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1410 if (m_cursor
== cursor
)
1413 if (wxNullCursor
== cursor
)
1415 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1420 if ( ! wxWindowBase::SetCursor( cursor
) )
1424 wxASSERT_MSG( m_cursor
.Ok(),
1425 wxT("cursor must be valid after call to the base version"));
1428 wxWindowMac
*mouseWin
= 0 ;
1430 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1432 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1434 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1435 // position, use it...
1439 ControlPartCode part
;
1440 ControlRef control
;
1441 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1443 mouseWin
= wxFindControlFromMacControl( control
) ;
1446 QDSwapPort( savePort
, NULL
) ;
1449 if ( mouseWin
== this && !wxIsBusy() )
1451 m_cursor
.MacInstall() ;
1458 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1460 menu
->SetInvokingWindow(this);
1463 if ( x
== -1 && y
== -1 )
1465 wxPoint mouse
= wxGetMousePosition();
1466 x
= mouse
.x
; y
= mouse
.y
;
1470 ClientToScreen( &x
, &y
) ;
1473 menu
->MacBeforeDisplay( true ) ;
1474 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1475 if ( HiWord(menuResult
) != 0 )
1478 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1479 wxMenuItem
* item
= NULL
;
1481 item
= menu
->FindItem(id
, &realmenu
) ;
1482 if (item
->IsCheckable())
1484 item
->Check( !item
->IsChecked() ) ;
1486 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1488 menu
->MacAfterDisplay( true ) ;
1490 menu
->SetInvokingWindow(NULL
);
1496 // ----------------------------------------------------------------------------
1498 // ----------------------------------------------------------------------------
1502 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1504 wxWindowBase::DoSetToolTip(tooltip
);
1507 m_tooltip
->SetWindow(this);
1510 #endif // wxUSE_TOOLTIPS
1512 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1514 int former_x
, former_y
, former_w
, former_h
;
1515 #if !TARGET_API_MAC_OSX
1516 DoGetPosition( &former_x
, &former_y
) ;
1517 DoGetSize( &former_w
, &former_h
) ;
1519 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1522 int actualWidth
= width
;
1523 int actualHeight
= height
;
1527 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1528 actualWidth
= m_minWidth
;
1529 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1530 actualHeight
= m_minHeight
;
1531 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1532 actualWidth
= m_maxWidth
;
1533 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1534 actualHeight
= m_maxHeight
;
1536 bool doMove
= false ;
1537 bool doResize
= false ;
1539 if ( actualX
!= former_x
|| actualY
!= former_y
)
1543 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1548 if ( doMove
|| doResize
)
1550 // we don't adjust twice for the origin
1551 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1552 bool vis
= IsControlVisible( *m_peer
) ;
1553 #if TARGET_API_MAC_OSX
1554 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1556 SetControlVisibility( *m_peer
, false , true ) ;
1557 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1558 HIViewSetFrame ( *m_peer
, &hir
) ;
1560 SetControlVisibility( *m_peer
, true , true ) ;
1563 SetControlVisibility( *m_peer
, false , true ) ;
1564 SetControlBounds( *m_peer
, &r
) ;
1566 SetControlVisibility( *m_peer
, true , true ) ;
1568 MacRepositionScrollBars() ;
1571 wxPoint
point(actualX
,actualY
);
1572 wxMoveEvent
event(point
, m_windowId
);
1573 event
.SetEventObject(this);
1574 GetEventHandler()->ProcessEvent(event
) ;
1578 MacRepositionScrollBars() ;
1579 wxSize
size(actualWidth
, actualHeight
);
1580 wxSizeEvent
event(size
, m_windowId
);
1581 event
.SetEventObject(this);
1582 GetEventHandler()->ProcessEvent(event
);
1588 wxSize
wxWindowMac::DoGetBestSize() const
1590 if ( m_macIsUserPane
|| IsTopLevel() )
1591 return wxWindowBase::DoGetBestSize() ;
1593 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1594 short baselineoffset
;
1595 int bestWidth
, bestHeight
;
1596 ::GetBestControlRect( *m_peer
, &bestsize
, &baselineoffset
) ;
1598 if ( EmptyRect( &bestsize
) )
1601 bestsize
.left
= bestsize
.top
= 0 ;
1602 bestsize
.right
= 16 ;
1603 bestsize
.bottom
= 16 ;
1604 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1606 bestsize
.bottom
= 16 ;
1608 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1610 bestsize
.bottom
= 24 ;
1614 // return wxWindowBase::DoGetBestSize() ;
1618 bestWidth
= bestsize
.right
- bestsize
.left
;
1619 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1620 if ( bestHeight
< 10 )
1623 return wxSize(bestWidth
, bestHeight
);
1624 // return wxWindowBase::DoGetBestSize() ;
1628 // set the size of the window: if the dimensions are positive, just use them,
1629 // but if any of them is equal to -1, it means that we must find the value for
1630 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1631 // which case -1 is a valid value for x and y)
1633 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1634 // the width/height to best suit our contents, otherwise we reuse the current
1636 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1638 // get the current size and position...
1639 int currentX
, currentY
;
1640 GetPosition(¤tX
, ¤tY
);
1642 int currentW
,currentH
;
1643 GetSize(¤tW
, ¤tH
);
1645 // ... and don't do anything (avoiding flicker) if it's already ok
1646 if ( x
== currentX
&& y
== currentY
&&
1647 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1650 MacRepositionScrollBars() ; // we might have a real position shift
1654 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1656 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1659 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1661 wxSize
size(-1, -1);
1664 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1666 size
= DoGetBestSize();
1671 // just take the current one
1678 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1682 size
= DoGetBestSize();
1684 //else: already called DoGetBestSize() above
1690 // just take the current one
1695 DoMoveWindow(x
, y
, width
, height
);
1699 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1701 RgnHandle rgn
= NewRgn() ;
1703 GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) ;
1704 GetRegionBounds( rgn
, &content
) ;
1706 #if !TARGET_API_MAC_OSX
1707 // if the content rgn is empty / not supported
1708 // don't attempt to correct the coordinates to wxWindow relative ones
1709 if (!::EmptyRect( &content
) )
1712 GetControlBounds( *m_peer
, &structure
) ;
1713 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1717 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1720 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1722 if ( clientheight
!= -1 || clientheight
!= -1 )
1724 int currentclientwidth
, currentclientheight
;
1725 int currentwidth
, currentheight
;
1727 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1728 GetSize( ¤twidth
, ¤theight
) ;
1730 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1731 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1735 void wxWindowMac::SetTitle(const wxString
& title
)
1737 m_label
= wxStripMenuCodes(title
) ;
1739 if ( m_peer
&& m_peer
->Ok() )
1741 UMASetControlTitle( *m_peer
, m_label
, m_font
.GetEncoding() ) ;
1746 wxString
wxWindowMac::GetTitle() const
1751 bool wxWindowMac::Show(bool show
)
1753 if ( !wxWindowBase::Show(show
) )
1756 // TODO use visibilityChanged Carbon Event for OSX
1757 bool former
= MacIsReallyShown() ;
1759 SetControlVisibility( *m_peer
, show
, true ) ;
1760 if ( former
!= MacIsReallyShown() )
1761 MacPropagateVisibilityChanged() ;
1765 bool wxWindowMac::Enable(bool enable
)
1767 wxASSERT( m_peer
->Ok() ) ;
1768 if ( !wxWindowBase::Enable(enable
) )
1771 bool former
= MacIsReallyEnabled() ;
1772 #if TARGET_API_MAC_OSX
1774 EnableControl( *m_peer
) ;
1776 DisableControl( *m_peer
) ;
1779 ActivateControl( *m_peer
) ;
1781 DeactivateControl( *m_peer
) ;
1784 if ( former
!= MacIsReallyEnabled() )
1785 MacPropagateEnabledStateChanged() ;
1790 // status change propagations (will be not necessary for OSX later )
1793 void wxWindowMac::MacPropagateVisibilityChanged()
1795 #if !TARGET_API_MAC_OSX
1796 MacVisibilityChanged() ;
1798 wxWindowListNode
*node
= GetChildren().GetFirst();
1801 wxWindowMac
*child
= node
->GetData();
1802 if ( child
->IsShown() )
1803 child
->MacPropagateVisibilityChanged( ) ;
1804 node
= node
->GetNext();
1809 void wxWindowMac::MacPropagateEnabledStateChanged( )
1811 #if !TARGET_API_MAC_OSX
1812 MacEnabledStateChanged() ;
1814 wxWindowListNode
*node
= GetChildren().GetFirst();
1817 wxWindowMac
*child
= node
->GetData();
1818 if ( child
->IsEnabled() )
1819 child
->MacPropagateEnabledStateChanged() ;
1820 node
= node
->GetNext();
1825 void wxWindowMac::MacPropagateHiliteChanged( )
1827 #if !TARGET_API_MAC_OSX
1828 MacHiliteChanged() ;
1830 wxWindowListNode
*node
= GetChildren().GetFirst();
1833 wxWindowMac
*child
= node
->GetData();
1834 // if ( child->IsEnabled() )
1835 child
->MacPropagateHiliteChanged() ;
1836 node
= node
->GetNext();
1842 // status change notifications
1845 void wxWindowMac::MacVisibilityChanged()
1849 void wxWindowMac::MacHiliteChanged()
1853 void wxWindowMac::MacEnabledStateChanged()
1858 // status queries on the inherited window's state
1861 bool wxWindowMac::MacIsReallyShown()
1863 // only under OSX the visibility of the TLW is taken into account
1864 #if TARGET_API_MAC_OSX
1865 return IsControlVisible( *m_peer
) ;
1867 wxWindow
* win
= this ;
1868 while( win
->IsShown() )
1870 if ( win
->IsTopLevel() )
1873 win
= win
->GetParent() ;
1882 bool wxWindowMac::MacIsReallyEnabled()
1884 #if TARGET_API_MAC_OSX
1885 return IsControlEnabled( *m_peer
) ;
1887 return IsControlActive( *m_peer
) ;
1891 bool wxWindowMac::MacIsReallyHilited()
1893 return IsControlActive( *m_peer
) ;
1896 void wxWindowMac::MacFlashInvalidAreas()
1898 #if TARGET_API_MAC_OSX
1899 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1907 int wxWindowMac::GetCharHeight() const
1909 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1910 return dc
.GetCharHeight() ;
1913 int wxWindowMac::GetCharWidth() const
1915 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1916 return dc
.GetCharWidth() ;
1919 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1920 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1922 const wxFont
*fontToUse
= theFont
;
1924 fontToUse
= &m_font
;
1926 wxClientDC
dc( (wxWindowMac
*) this ) ;
1928 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1929 if ( externalLeading
)
1930 *externalLeading
= le
;
1940 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1941 * we always intersect with the entire window, not only with the client area
1944 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1946 #if TARGET_API_MAC_OSX
1948 HIViewSetNeedsDisplay( *m_peer
, true ) ;
1951 RgnHandle update
= NewRgn() ;
1952 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1953 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1954 wxPoint origin
= GetClientAreaOrigin() ;
1955 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1956 HIViewSetNeedsDisplayInRegion( *m_peer
, update
, true ) ;
1960 RgnHandle updateRgn = NewRgn() ;
1963 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1967 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1968 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1970 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1971 DisposeRgn(updateRgn) ;
1973 if ( IsControlVisible( *m_peer
) )
1975 SetControlVisibility( *m_peer
, false , false ) ;
1976 SetControlVisibility( *m_peer
, true , true ) ;
1979 if ( MacGetTopLevelWindow() == NULL )
1982 if ( !IsControlVisible( *m_peer ) )
1985 wxPoint client = GetClientAreaOrigin();
1988 int x2 = m_width - client.x;
1989 int y2 = m_height - client.y;
1991 if (IsKindOf( CLASSINFO(wxButton)))
1993 // buttons have an "aura"
2000 Rect clientrect = { y1, x1, y2, x2 };
2004 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2005 SectRect( &clientrect , &r , &clientrect ) ;
2008 if ( !EmptyRect( &clientrect ) )
2010 int top = 0 , left = 0 ;
2012 MacClientToRootWindow( &left , &top ) ;
2013 OffsetRect( &clientrect , left , top ) ;
2015 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2021 void wxWindowMac::Freeze()
2023 #if TARGET_API_MAC_OSX
2024 if ( !m_frozenness
++ )
2026 HIViewSetDrawingEnabled( *m_peer
, false ) ;
2031 #if TARGET_API_MAC_OSX
2032 static void InvalidateControlAndChildren( HIViewRef control
)
2034 HIViewSetNeedsDisplay( control
, true ) ;
2035 UInt16 childrenCount
= 0 ;
2036 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2037 if ( err
== errControlIsNotEmbedder
)
2039 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2041 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2044 err
= GetIndexedSubControl( control
, i
, & child
) ;
2045 if ( err
== errControlIsNotEmbedder
)
2047 InvalidateControlAndChildren( child
) ;
2052 void wxWindowMac::Thaw()
2054 #if TARGET_API_MAC_OSX
2055 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2057 if ( !--m_frozenness
)
2059 HIViewSetDrawingEnabled( *m_peer
, true ) ;
2060 InvalidateControlAndChildren( *m_peer
) ;
2061 // HIViewSetNeedsDisplay( *m_peer , true ) ;
2066 void wxWindowMac::MacRedrawControl()
2069 if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) )
2071 #if TARGET_API_MAC_CARBON
2074 wxClientDC dc(this) ;
2075 wxMacPortSetter helper(&dc) ;
2076 wxMacWindowClipper clipper(this) ;
2077 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2078 UMADrawControl( *m_peer ) ;
2085 void wxWindowMac::OnPaint(wxPaintEvent& event)
2087 // why don't we skip that here ?
2091 wxWindowMac
*wxGetActiveWindow()
2093 // actually this is a windows-only concept
2097 // Coordinates relative to the window
2098 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2100 // We really don't move the mouse programmatically under Mac.
2103 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2105 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2110 event
.GetDC()->Clear() ;
2113 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2115 wxWindowDC
dc(this) ;
2116 wxMacPortSetter
helper(&dc
) ;
2118 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2121 int wxWindowMac::GetScrollPos(int orient
) const
2123 if ( orient
== wxHORIZONTAL
)
2126 return m_hScrollBar
->GetThumbPosition() ;
2131 return m_vScrollBar
->GetThumbPosition() ;
2136 // This now returns the whole range, not just the number
2137 // of positions that we can scroll.
2138 int wxWindowMac::GetScrollRange(int orient
) const
2140 if ( orient
== wxHORIZONTAL
)
2143 return m_hScrollBar
->GetRange() ;
2148 return m_vScrollBar
->GetRange() ;
2153 int wxWindowMac::GetScrollThumb(int orient
) const
2155 if ( orient
== wxHORIZONTAL
)
2158 return m_hScrollBar
->GetThumbSize() ;
2163 return m_vScrollBar
->GetThumbSize() ;
2168 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2170 if ( orient
== wxHORIZONTAL
)
2173 m_hScrollBar
->SetThumbPosition( pos
) ;
2178 m_vScrollBar
->SetThumbPosition( pos
) ;
2182 void wxWindowMac::MacPaintBorders( int left
, int top
)
2188 wxGetOsVersion( &major
, &minor
);
2190 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2191 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2193 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2194 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2195 // OS X has lighter border edges than classic:
2198 darkShadow
.red
= 0x8E8E;
2199 darkShadow
.green
= 0x8E8E;
2200 darkShadow
.blue
= 0x8E8E;
2201 lightShadow
.red
= 0xBDBD;
2202 lightShadow
.green
= 0xBDBD;
2203 lightShadow
.blue
= 0xBDBD;
2209 GetSize( &w
, &h
) ;
2210 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2212 #if wxMAC_USE_THEME_BORDER
2213 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2216 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2217 InsetRect( &rect , border , border );
2218 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2221 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2223 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2224 RGBForeColor( &face
);
2225 MoveTo( left
+ 0 , top
+ h
- 2 );
2226 LineTo( left
+ 0 , top
+ 0 );
2227 LineTo( left
+ w
- 2 , top
+ 0 );
2229 MoveTo( left
+ 2 , top
+ h
- 3 );
2230 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2231 LineTo( left
+ w
- 3 , top
+ 2 );
2233 RGBForeColor( sunken
? &face
: &darkShadow
);
2234 MoveTo( left
+ 0 , top
+ h
- 1 );
2235 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2236 LineTo( left
+ w
- 1 , top
+ 0 );
2238 RGBForeColor( sunken
? &lightShadow
: &white
);
2239 MoveTo( left
+ 1 , top
+ h
- 3 );
2240 LineTo( left
+ 1, top
+ 1 );
2241 LineTo( left
+ w
- 3 , top
+ 1 );
2243 RGBForeColor( sunken
? &white
: &lightShadow
);
2244 MoveTo( left
+ 1 , top
+ h
- 2 );
2245 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2246 LineTo( left
+ w
- 2 , top
+ 1 );
2248 RGBForeColor( sunken
? &darkShadow
: &face
);
2249 MoveTo( left
+ 2 , top
+ h
- 4 );
2250 LineTo( left
+ 2 , top
+ 2 );
2251 LineTo( left
+ w
- 4 , top
+ 2 );
2254 else if (HasFlag(wxSIMPLE_BORDER
))
2256 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2257 RGBForeColor( &darkShadow
) ;
2258 FrameRect( &rect
) ;
2262 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2264 if ( child
== m_hScrollBar
)
2265 m_hScrollBar
= NULL
;
2266 if ( child
== m_vScrollBar
)
2267 m_vScrollBar
= NULL
;
2269 wxWindowBase::RemoveChild( child
) ;
2272 // New function that will replace some of the above.
2273 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2274 int range
, bool refresh
)
2276 if ( orient
== wxHORIZONTAL
)
2280 if ( range
== 0 || thumbVisible
>= range
)
2282 if ( m_hScrollBar
->IsShown() )
2283 m_hScrollBar
->Show(false) ;
2287 if ( !m_hScrollBar
->IsShown() )
2288 m_hScrollBar
->Show(true) ;
2289 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2297 if ( range
== 0 || thumbVisible
>= range
)
2299 if ( m_vScrollBar
->IsShown() )
2300 m_vScrollBar
->Show(false) ;
2304 if ( !m_vScrollBar
->IsShown() )
2305 m_vScrollBar
->Show(true) ;
2306 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2310 MacRepositionScrollBars() ;
2313 // Does a physical scroll
2314 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2316 if( dx
== 0 && dy
==0 )
2322 int width
, height
;
2323 GetClientSize( &width
, &height
) ;
2324 #if TARGET_API_MAC_OSX
2325 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2326 // area is scrolled, this does not occur if width and height are 2 pixels less,
2327 // TODO write optimal workaround
2328 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2331 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2332 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2334 if ( HIViewGetNeedsDisplay( *m_peer
) )
2336 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2337 // either immediate redraw or full invalidate
2339 // is the better overall solution, as it does not slow down scrolling
2340 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2342 // this would be the preferred version for fast drawing controls
2343 if( UMAGetSystemVersion() < 0x1030 )
2346 HIViewRender(*m_peer
) ;
2349 HIViewScrollRect ( *m_peer
, &scrollrect
, dx
,dy
) ;
2356 RgnHandle updateRgn
= NewRgn() ;
2359 wxClientDC
dc(this) ;
2360 wxMacPortSetter
helper(&dc
) ;
2362 GetControlBounds( *m_peer
, &scrollrect
);
2363 scrollrect
.top
+= MacGetTopBorderSize() ;
2364 scrollrect
.left
+= MacGetLeftBorderSize() ;
2365 scrollrect
.bottom
= scrollrect
.top
+ height
;
2366 scrollrect
.right
= scrollrect
.left
+ width
;
2370 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2371 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2372 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2374 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2376 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2380 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2382 wxWindowMac
*child
= node
->GetData();
2383 if (child
== m_vScrollBar
) continue;
2384 if (child
== m_hScrollBar
) continue;
2385 if (child
->IsTopLevel()) continue;
2388 child
->GetPosition( &x
, &y
);
2390 child
->GetSize( &w
, &h
);
2394 if (rect
->Intersects(rc
))
2395 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2399 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2404 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2406 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2408 wxScrollWinEvent wevent
;
2409 wevent
.SetPosition(event
.GetPosition());
2410 wevent
.SetOrientation(event
.GetOrientation());
2411 wevent
.m_eventObject
= this;
2413 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2414 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2415 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2416 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2417 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2418 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2419 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2420 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2421 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2422 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2423 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2424 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2425 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2426 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2427 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2428 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2430 GetEventHandler()->ProcessEvent(wevent
);
2434 // Get the window with the focus
2435 wxWindowMac
*wxWindowBase::FindFocus()
2437 ControlRef control
;
2438 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2439 return wxFindControlFromMacControl( control
) ;
2442 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2444 // panel wants to track the window which was the last to have focus in it,
2445 // so we want to set ourselves as the window which last had focus
2447 // notice that it's also important to do it upwards the tree becaus
2448 // otherwise when the top level panel gets focus, it won't set it back to
2449 // us, but to some other sibling
2451 // CS:don't know if this is still needed:
2452 //wxChildFocusEvent eventFocus(this);
2453 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2458 void wxWindowMac::OnInternalIdle()
2460 // This calls the UI-update mechanism (querying windows for
2461 // menu/toolbar/control state information)
2462 if (wxUpdateUIEvent::CanUpdate(this))
2463 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2466 // Raise the window to the top of the Z order
2467 void wxWindowMac::Raise()
2469 #if TARGET_API_MAC_OSX
2470 HIViewSetZOrder(*m_peer
,kHIViewZOrderAbove
, NULL
) ;
2474 // Lower the window to the bottom of the Z order
2475 void wxWindowMac::Lower()
2477 #if TARGET_API_MAC_OSX
2478 HIViewSetZOrder(*m_peer
,kHIViewZOrderBelow
, NULL
) ;
2483 // static wxWindow *gs_lastWhich = NULL;
2485 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2487 // first trigger a set cursor event
2489 wxPoint clientorigin
= GetClientAreaOrigin() ;
2490 wxSize clientsize
= GetClientSize() ;
2492 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2494 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2496 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2497 if ( processedEvtSetCursor
&& event
.HasCursor() )
2499 cursor
= event
.GetCursor() ;
2504 // the test for processedEvtSetCursor is here to prevent using m_cursor
2505 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2506 // it - this is a way to say that our cursor shouldn't be used for this
2508 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2518 cursor
= *wxSTANDARD_CURSOR
;
2522 cursor
.MacInstall() ;
2524 return cursor
.Ok() ;
2527 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2531 return m_tooltip
->GetTip() ;
2533 return wxEmptyString
;
2536 void wxWindowMac::Update()
2538 #if TARGET_API_MAC_OSX
2539 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2540 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2541 // for composited windows this also triggers a redraw of all
2542 // invalid views in the window
2543 if( UMAGetSystemVersion() >= 0x1030 )
2544 HIWindowFlush(window
) ;
2548 // the only way to trigger the redrawing on earlier systems is to call
2551 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2552 UInt32 currentEventClass
= 0 ;
2553 UInt32 currentEventKind
= 0 ;
2554 if ( currentEvent
!= NULL
)
2556 currentEventClass
= ::GetEventClass( currentEvent
) ;
2557 currentEventKind
= ::GetEventKind( currentEvent
) ;
2559 if ( currentEventClass
!= kEventClassMenu
)
2561 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2564 OSStatus status
= noErr
;
2565 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2568 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2571 ::Draw1Control( *m_peer
) ;
2575 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2577 wxTopLevelWindowMac
* win
= NULL
;
2578 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2581 win
= wxFindWinFromMacWindow( window
) ;
2585 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2589 RgnHandle visRgn
= NewRgn() ;
2590 RgnHandle tempRgn
= NewRgn() ;
2591 if ( IsControlVisible( *m_peer
) )
2593 GetControlBounds( *m_peer
, &r
) ;
2594 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2596 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2597 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2606 if ( includeOuterStructures
)
2607 InsetRect( &r
, -3 , -3 ) ;
2608 RectRgn( visRgn
, &r
) ;
2609 if ( !IsTopLevel() )
2611 wxWindow
* child
= this ;
2612 wxWindow
* parent
= child
->GetParent() ;
2617 // we have to find a better clipping algorithm here, in order not to clip things
2618 // positioned like status and toolbar
2619 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2621 size
= parent
->GetSize() ;
2626 size
= parent
->GetClientSize() ;
2627 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2631 parent
->MacWindowToRootWindow( &x
, &y
) ;
2632 MacRootWindowToWindow( &x
, &y
) ;
2634 SetRectRgn( tempRgn
,
2635 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2636 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2637 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2639 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2640 if ( parent
->IsTopLevel() )
2643 parent
= child
->GetParent() ;
2648 wxRegion vis
= visRgn
;
2649 DisposeRgn( visRgn
) ;
2650 DisposeRgn( tempRgn
) ;
2655 This function must not change the updatergn !
2657 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2659 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2660 bool handled
= false ;
2662 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2664 RgnHandle newupdate
= NewRgn() ;
2665 wxSize point
= GetClientSize() ;
2666 wxPoint origin
= GetClientAreaOrigin() ;
2667 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2668 SectRgn( newupdate
, updatergn
, newupdate
) ;
2669 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2670 m_updateRegion
= newupdate
;
2671 DisposeRgn( newupdate
) ;
2674 if ( !EmptyRgn(updatergn
) )
2676 wxWindowDC
dc(this);
2677 if (!EmptyRgn(updatergn
))
2678 dc
.SetClippingRegion(wxRegion(updatergn
));
2680 wxEraseEvent
eevent( GetId(), &dc
);
2681 eevent
.SetEventObject( this );
2682 GetEventHandler()->ProcessEvent( eevent
);
2684 if ( !m_updateRegion
.Empty() )
2686 // paint the window itself
2688 event
.m_timeStamp
= time
;
2689 event
.SetEventObject(this);
2690 handled
= GetEventHandler()->ProcessEvent(event
);
2692 // paint custom borders
2693 wxNcPaintEvent
eventNc( GetId() );
2694 eventNc
.SetEventObject( this );
2695 GetEventHandler()->ProcessEvent( eventNc
);
2701 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2703 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2704 // updatergn is always already clipped to our boundaries
2705 // if we are in compositing mode then it is in relative to the upper left of the control
2706 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2707 // of the toplevel window
2708 // it is in window coordinates, not in client coordinates
2710 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2711 RgnHandle ownUpdateRgn
= NewRgn() ;
2712 CopyRgn( updatergn
, ownUpdateRgn
) ;
2714 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2717 UMAGetControlBoundsInWindowCoords( *m_peer
, &bounds
);
2718 RgnHandle controlRgn
= NewRgn();
2719 RectRgn( controlRgn
, &bounds
);
2720 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2721 // the window update region
2722 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2723 DisposeRgn( controlRgn
);
2725 //KO: convert ownUpdateRgn to local coordinates
2726 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2729 MacDoRedraw( ownUpdateRgn
, time
) ;
2730 DisposeRgn( ownUpdateRgn
) ;
2734 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2736 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2740 if ( iter
->IsTopLevel() )
2741 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2743 iter
= iter
->GetParent() ;
2745 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2749 void wxWindowMac::MacCreateScrollBars( long style
)
2751 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2753 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2754 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2756 GetClientSize( &width
, &height
) ;
2758 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2759 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2760 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2761 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2763 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2764 vSize
, wxVERTICAL
);
2766 if ( style
& wxVSCROLL
)
2772 m_vScrollBar
->Show(false) ;
2774 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2775 hSize
, wxHORIZONTAL
);
2776 if ( style
& wxHSCROLL
)
2781 m_hScrollBar
->Show(false) ;
2784 // because the create does not take into account the client area origin
2785 MacRepositionScrollBars() ; // we might have a real position shift
2788 void wxWindowMac::MacRepositionScrollBars()
2790 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2791 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2793 // get real client area
2797 GetSize( &width
, &height
) ;
2799 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2800 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2802 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2803 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2804 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2805 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2811 GetSize( &w
, &h
) ;
2813 MacClientToRootWindow( &x
, &y
) ;
2814 MacClientToRootWindow( &w
, &h
) ;
2816 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2818 int totW
= 10000 , totH
= 10000;
2821 if ( iter
->IsTopLevel() )
2823 iter
->GetSize( &totW
, &totH
) ;
2827 iter
= iter
->GetParent() ;
2855 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2859 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2863 bool wxWindowMac::AcceptsFocus() const
2865 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2868 void wxWindowMac::MacSuperChangedPosition()
2870 // only window-absolute structures have to be moved i.e. controls
2872 wxWindowListNode
*node
= GetChildren().GetFirst();
2875 wxWindowMac
*child
= node
->GetData();
2876 child
->MacSuperChangedPosition() ;
2877 node
= node
->GetNext();
2881 void wxWindowMac::MacTopLevelWindowChangedPosition()
2883 // only screen-absolute structures have to be moved i.e. glcanvas
2885 wxWindowListNode
*node
= GetChildren().GetFirst();
2888 wxWindowMac
*child
= node
->GetData();
2889 child
->MacTopLevelWindowChangedPosition() ;
2890 node
= node
->GetNext();
2894 long wxWindowMac::MacGetLeftBorderSize( ) const
2899 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2902 #if wxMAC_USE_THEME_BORDER
2903 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2907 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2910 #if wxMAC_USE_THEME_BORDER
2911 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2915 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2922 long wxWindowMac::MacGetRightBorderSize( ) const
2924 // they are all symmetric in mac themes
2925 return MacGetLeftBorderSize() ;
2928 long wxWindowMac::MacGetTopBorderSize( ) const
2930 // they are all symmetric in mac themes
2931 return MacGetLeftBorderSize() ;
2934 long wxWindowMac::MacGetBottomBorderSize( ) const
2936 // they are all symmetric in mac themes
2937 return MacGetLeftBorderSize() ;
2940 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2942 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2945 // Find the wxWindowMac at the current mouse position, returning the mouse
2947 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2949 pt
= wxGetMousePosition();
2950 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2954 // Get the current mouse position.
2955 wxPoint
wxGetMousePosition()
2958 wxGetMousePosition(& x
, & y
);
2959 return wxPoint(x
, y
);
2962 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2964 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2966 // copied from wxGTK : CS
2967 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2970 // (a) it's a command event and so is propagated to the parent
2971 // (b) under MSW it can be generated from kbd too
2972 // (c) it uses screen coords (because of (a))
2973 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2975 this->ClientToScreen(event
.GetPosition()));
2976 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2985 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2989 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2993 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2994 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2998 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3000 return eventNotHandledErr
;