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 if ( m_font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
864 switch( m_font
.MacGetThemeFontID() )
866 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
867 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
868 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
869 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
871 fontStyle
.flags
= kControlUseFontMask
;
875 fontStyle
.font
= m_font
.MacGetFontNum() ;
876 fontStyle
.style
= m_font
.MacGetFontStyle() ;
877 fontStyle
.size
= m_font
.MacGetFontSize() ;
878 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
881 fontStyle
.just
= teJustLeft
;
882 fontStyle
.flags
|= kControlUseJustMask
;
883 if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
884 fontStyle
.just
= teJustCenter
;
885 else if ( ( GetWindowStyle() & wxALIGN_MASK
) & wxALIGN_RIGHT
)
886 fontStyle
.just
= teJustRight
;
889 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
890 // won't get grayed out by the system anymore
892 if ( GetForegroundColour() != *wxBLACK
)
894 fontStyle
.foreColor
= MAC_WXCOLORREF(GetForegroundColour().GetPixel() ) ;
895 fontStyle
.flags
|= kControlUseForeColorMask
;
898 ::SetControlFontStyle( *m_peer
, &fontStyle
);
902 bool wxWindowMac::SetFont(const wxFont
& font
)
904 bool retval
= !wxWindowBase::SetFont( font
) ;
906 MacUpdateControlFont() ;
911 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
913 if ( !wxWindowBase::SetForegroundColour(col
) )
916 MacUpdateControlFont() ;
921 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
923 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
927 wxColour
newCol(GetBackgroundColour());
928 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
930 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
932 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
934 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
938 brush
.SetColour( newCol
) ;
940 MacSetBackgroundBrush( brush
) ;
942 MacUpdateControlFont() ;
948 bool wxWindowMac::MacCanFocus() const
950 // there is currently no way to determine whether the window is running in full keyboard
951 // access mode, therefore we cannot rely on these features, yet the only other way would be
952 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
953 // in event handlers...
954 UInt32 features
= 0 ;
955 GetControlFeatures( *m_peer
, &features
) ;
956 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
960 void wxWindowMac::SetFocus()
962 if ( AcceptsFocus() )
964 #if !TARGET_API_MAC_OSX
965 wxWindow
* former
= FindFocus() ;
967 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
968 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
969 // leave in case of an error
970 if ( err
== errCouldntSetFocus
)
973 #if !TARGET_API_MAC_OSX
974 // emulate carbon events when running under carbonlib where they are not natively available
977 EventRef evRef
= NULL
;
978 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
981 wxMacCarbonEvent
cEvent( evRef
) ;
982 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
983 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
985 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
986 ReleaseEvent(evRef
) ;
988 // send new focus event
990 EventRef evRef
= NULL
;
991 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
994 wxMacCarbonEvent
cEvent( evRef
) ;
995 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
996 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
998 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
999 ReleaseEvent(evRef
) ;
1006 void wxWindowMac::DoCaptureMouse()
1008 wxTheApp
->s_captureWindow
= this ;
1011 wxWindow
* wxWindowBase::GetCapture()
1013 return wxTheApp
->s_captureWindow
;
1016 void wxWindowMac::DoReleaseMouse()
1018 wxTheApp
->s_captureWindow
= NULL
;
1021 #if wxUSE_DRAG_AND_DROP
1023 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1025 if ( m_dropTarget
!= 0 ) {
1026 delete m_dropTarget
;
1029 m_dropTarget
= pDropTarget
;
1030 if ( m_dropTarget
!= 0 )
1038 // Old style file-manager drag&drop
1039 void wxWindowMac::DragAcceptFiles(bool accept
)
1044 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1045 int& w
, int& h
) const
1048 GetControlBounds( *m_peer
, &bounds
) ;
1053 w
= bounds
.right
- bounds
.left
;
1054 h
= bounds
.bottom
- bounds
.top
;
1056 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1059 Point tlworigin
= { 0 , 0 } ;
1060 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1066 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1069 int& w
, int& h
, bool adjustOrigin
) const
1073 // todo the default calls may be used as soon as PostCreateControl Is moved here
1074 w
= size
.x
; // WidthDefault( size.x );
1075 h
= size
.y
; // HeightDefault( size.y ) ;
1076 #if !TARGET_API_MAC_OSX
1077 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1080 AdjustForParentClientOrigin( x
, y
) ;
1085 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1087 #if TARGET_API_MAC_OSX
1088 int x1
, y1
, w1
,h1
;
1089 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1095 GetControlBounds( *m_peer
, &bounds
) ;
1096 if(x
) *x
= bounds
.right
- bounds
.left
;
1097 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1101 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1103 #if TARGET_API_MAC_OSX
1104 int x1
, y1
, w1
,h1
;
1105 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1106 if ( !IsTopLevel() )
1108 wxWindow
*parent
= GetParent();
1111 wxPoint
pt(parent
->GetClientAreaOrigin());
1120 GetControlBounds( *m_peer
, &bounds
) ;
1121 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1123 int xx
= bounds
.left
;
1124 int yy
= bounds
.top
;
1126 if ( !GetParent()->IsTopLevel() )
1128 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1134 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1143 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1145 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1147 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1150 Point localwhere
= {0,0} ;
1152 if(x
) localwhere
.h
= * x
;
1153 if(y
) localwhere
.v
= * y
;
1155 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1156 if(x
) *x
= localwhere
.h
;
1157 if(y
) *y
= localwhere
.v
;
1160 MacRootWindowToWindow( x
, y
) ;
1162 wxPoint origin
= GetClientAreaOrigin() ;
1163 if(x
) *x
-= origin
.x
;
1164 if(y
) *y
-= origin
.y
;
1167 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1169 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1170 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1172 wxPoint origin
= GetClientAreaOrigin() ;
1173 if(x
) *x
+= origin
.x
;
1174 if(y
) *y
+= origin
.y
;
1176 MacWindowToRootWindow( x
, y
) ;
1179 Point localwhere
= { 0,0 };
1180 if(x
) localwhere
.h
= * x
;
1181 if(y
) localwhere
.v
= * y
;
1182 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1183 if(x
) *x
= localwhere
.h
;
1184 if(y
) *y
= localwhere
.v
;
1188 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1190 wxPoint origin
= GetClientAreaOrigin() ;
1191 if(x
) *x
+= origin
.x
;
1192 if(y
) *y
+= origin
.y
;
1194 MacWindowToRootWindow( x
, y
) ;
1197 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1199 MacRootWindowToWindow( x
, y
) ;
1201 wxPoint origin
= GetClientAreaOrigin() ;
1202 if(x
) *x
-= origin
.x
;
1203 if(y
) *y
-= origin
.y
;
1206 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1208 #if TARGET_API_MAC_OSX
1210 if ( x
) pt
.x
= *x
;
1211 if ( y
) pt
.y
= *y
;
1213 if ( !IsTopLevel() )
1215 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1217 HIViewConvertPoint( &pt
, *m_peer
, (ControlRef
) top
->GetHandle() ) ;
1220 if ( x
) *x
= (int) pt
.x
;
1221 if ( y
) *y
= (int) pt
.y
;
1223 if ( !IsTopLevel() )
1226 GetControlBounds( *m_peer
, &bounds
) ;
1227 if(x
) *x
+= bounds
.left
;
1228 if(y
) *y
+= bounds
.top
;
1233 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1238 MacWindowToRootWindow( &x1
, &y1
) ;
1243 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1245 #if TARGET_API_MAC_OSX
1247 if ( x
) pt
.x
= *x
;
1248 if ( y
) pt
.y
= *y
;
1250 if ( !IsTopLevel() )
1251 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , *m_peer
) ;
1253 if ( x
) *x
= (int) pt
.x
;
1254 if ( y
) *y
= (int) pt
.y
;
1256 if ( !IsTopLevel() )
1259 GetControlBounds( *m_peer
, &bounds
) ;
1260 if(x
) *x
-= bounds
.left
;
1261 if(y
) *y
-= bounds
.top
;
1266 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1271 MacRootWindowToWindow( &x1
, &y1
) ;
1276 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1278 RgnHandle rgn
= NewRgn() ;
1280 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1282 GetRegionBounds( rgn
, &content
) ;
1287 GetControlBounds( *m_peer
, &content
) ;
1290 GetControlBounds( *m_peer
, &structure
) ;
1291 #if !TARGET_API_MAC_OSX
1292 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1294 left
= content
.left
- structure
.left
;
1295 top
= content
.top
- structure
.top
;
1296 right
= structure
.right
- content
.right
;
1297 bottom
= structure
.bottom
- content
.bottom
;
1300 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1302 wxSize sizeTotal
= size
;
1304 RgnHandle rgn
= NewRgn() ;
1308 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1310 GetRegionBounds( rgn
, &content
) ;
1315 GetControlBounds( *m_peer
, &content
) ;
1318 GetControlBounds( *m_peer
, &structure
) ;
1319 #if !TARGET_API_MAC_OSX
1320 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1323 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1324 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1326 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1327 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1333 // Get size *available for subwindows* i.e. excluding menu bar etc.
1334 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1338 RgnHandle rgn
= NewRgn() ;
1340 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1342 GetRegionBounds( rgn
, &content
) ;
1347 GetControlBounds( *m_peer
, &content
) ;
1349 #if !TARGET_API_MAC_OSX
1351 GetControlBounds( *m_peer
, &structure
) ;
1352 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1354 ww
= content
.right
- content
.left
;
1355 hh
= content
.bottom
- content
.top
;
1357 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1358 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1360 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1366 GetSize( &w
, &h
) ;
1368 MacClientToRootWindow( &x1
, &y1
) ;
1369 MacClientToRootWindow( &w
, &h
) ;
1371 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1373 int totW
= 10000 , totH
= 10000;
1376 if ( iter
->IsTopLevel() )
1378 iter
->GetSize( &totW
, &totH
) ;
1382 iter
= iter
->GetParent() ;
1385 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1387 hh
-= MAC_SCROLLBAR_SIZE
;
1393 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1395 ww
-= MAC_SCROLLBAR_SIZE
;
1407 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1409 if (m_cursor
== cursor
)
1412 if (wxNullCursor
== cursor
)
1414 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1419 if ( ! wxWindowBase::SetCursor( cursor
) )
1423 wxASSERT_MSG( m_cursor
.Ok(),
1424 wxT("cursor must be valid after call to the base version"));
1427 wxWindowMac
*mouseWin
= 0 ;
1429 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1431 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1433 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1434 // position, use it...
1438 ControlPartCode part
;
1439 ControlRef control
;
1440 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1442 mouseWin
= wxFindControlFromMacControl( control
) ;
1445 QDSwapPort( savePort
, NULL
) ;
1448 if ( mouseWin
== this && !wxIsBusy() )
1450 m_cursor
.MacInstall() ;
1457 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1459 menu
->SetInvokingWindow(this);
1462 if ( x
== -1 && y
== -1 )
1464 wxPoint mouse
= wxGetMousePosition();
1465 x
= mouse
.x
; y
= mouse
.y
;
1469 ClientToScreen( &x
, &y
) ;
1472 menu
->MacBeforeDisplay( true ) ;
1473 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1474 if ( HiWord(menuResult
) != 0 )
1477 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1478 wxMenuItem
* item
= NULL
;
1480 item
= menu
->FindItem(id
, &realmenu
) ;
1481 if (item
->IsCheckable())
1483 item
->Check( !item
->IsChecked() ) ;
1485 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1487 menu
->MacAfterDisplay( true ) ;
1489 menu
->SetInvokingWindow(NULL
);
1495 // ----------------------------------------------------------------------------
1497 // ----------------------------------------------------------------------------
1501 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1503 wxWindowBase::DoSetToolTip(tooltip
);
1506 m_tooltip
->SetWindow(this);
1509 #endif // wxUSE_TOOLTIPS
1511 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1513 int former_x
, former_y
, former_w
, former_h
;
1514 #if !TARGET_API_MAC_OSX
1515 DoGetPosition( &former_x
, &former_y
) ;
1516 DoGetSize( &former_w
, &former_h
) ;
1518 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1521 int actualWidth
= width
;
1522 int actualHeight
= height
;
1526 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1527 actualWidth
= m_minWidth
;
1528 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1529 actualHeight
= m_minHeight
;
1530 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1531 actualWidth
= m_maxWidth
;
1532 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1533 actualHeight
= m_maxHeight
;
1535 bool doMove
= false ;
1536 bool doResize
= false ;
1538 if ( actualX
!= former_x
|| actualY
!= former_y
)
1542 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1547 if ( doMove
|| doResize
)
1549 // we don't adjust twice for the origin
1550 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1551 bool vis
= IsControlVisible( *m_peer
) ;
1552 #if TARGET_API_MAC_OSX
1553 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1555 SetControlVisibility( *m_peer
, false , true ) ;
1556 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1557 HIViewSetFrame ( *m_peer
, &hir
) ;
1559 SetControlVisibility( *m_peer
, true , true ) ;
1562 SetControlVisibility( *m_peer
, false , true ) ;
1563 SetControlBounds( *m_peer
, &r
) ;
1565 SetControlVisibility( *m_peer
, true , true ) ;
1567 MacRepositionScrollBars() ;
1570 wxPoint
point(actualX
,actualY
);
1571 wxMoveEvent
event(point
, m_windowId
);
1572 event
.SetEventObject(this);
1573 GetEventHandler()->ProcessEvent(event
) ;
1577 MacRepositionScrollBars() ;
1578 wxSize
size(actualWidth
, actualHeight
);
1579 wxSizeEvent
event(size
, m_windowId
);
1580 event
.SetEventObject(this);
1581 GetEventHandler()->ProcessEvent(event
);
1587 wxSize
wxWindowMac::DoGetBestSize() const
1589 if ( m_macIsUserPane
|| IsTopLevel() )
1590 return wxWindowBase::DoGetBestSize() ;
1592 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1593 short baselineoffset
;
1594 int bestWidth
, bestHeight
;
1595 ::GetBestControlRect( *m_peer
, &bestsize
, &baselineoffset
) ;
1597 if ( EmptyRect( &bestsize
) )
1600 bestsize
.left
= bestsize
.top
= 0 ;
1601 bestsize
.right
= 16 ;
1602 bestsize
.bottom
= 16 ;
1603 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1605 bestsize
.bottom
= 16 ;
1607 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1609 bestsize
.bottom
= 24 ;
1613 // return wxWindowBase::DoGetBestSize() ;
1617 bestWidth
= bestsize
.right
- bestsize
.left
;
1618 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1619 if ( bestHeight
< 10 )
1622 return wxSize(bestWidth
, bestHeight
);
1623 // return wxWindowBase::DoGetBestSize() ;
1627 // set the size of the window: if the dimensions are positive, just use them,
1628 // but if any of them is equal to -1, it means that we must find the value for
1629 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1630 // which case -1 is a valid value for x and y)
1632 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1633 // the width/height to best suit our contents, otherwise we reuse the current
1635 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1637 // get the current size and position...
1638 int currentX
, currentY
;
1639 GetPosition(¤tX
, ¤tY
);
1641 int currentW
,currentH
;
1642 GetSize(¤tW
, ¤tH
);
1644 // ... and don't do anything (avoiding flicker) if it's already ok
1645 if ( x
== currentX
&& y
== currentY
&&
1646 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1649 MacRepositionScrollBars() ; // we might have a real position shift
1653 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1655 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1658 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1660 wxSize
size(-1, -1);
1663 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1665 size
= DoGetBestSize();
1670 // just take the current one
1677 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1681 size
= DoGetBestSize();
1683 //else: already called DoGetBestSize() above
1689 // just take the current one
1694 DoMoveWindow(x
, y
, width
, height
);
1698 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1700 RgnHandle rgn
= NewRgn() ;
1702 GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) ;
1703 GetRegionBounds( rgn
, &content
) ;
1705 #if !TARGET_API_MAC_OSX
1706 // if the content rgn is empty / not supported
1707 // don't attempt to correct the coordinates to wxWindow relative ones
1708 if (!::EmptyRect( &content
) )
1711 GetControlBounds( *m_peer
, &structure
) ;
1712 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1716 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1719 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1721 if ( clientheight
!= -1 || clientheight
!= -1 )
1723 int currentclientwidth
, currentclientheight
;
1724 int currentwidth
, currentheight
;
1726 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1727 GetSize( ¤twidth
, ¤theight
) ;
1729 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1730 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1734 void wxWindowMac::SetTitle(const wxString
& title
)
1736 m_label
= wxStripMenuCodes(title
) ;
1738 if ( m_peer
&& m_peer
->Ok() )
1740 UMASetControlTitle( *m_peer
, m_label
, m_font
.GetEncoding() ) ;
1745 wxString
wxWindowMac::GetTitle() const
1750 bool wxWindowMac::Show(bool show
)
1752 if ( !wxWindowBase::Show(show
) )
1755 // TODO use visibilityChanged Carbon Event for OSX
1756 bool former
= MacIsReallyShown() ;
1758 SetControlVisibility( *m_peer
, show
, true ) ;
1759 if ( former
!= MacIsReallyShown() )
1760 MacPropagateVisibilityChanged() ;
1764 bool wxWindowMac::Enable(bool enable
)
1766 wxASSERT( m_peer
->Ok() ) ;
1767 if ( !wxWindowBase::Enable(enable
) )
1770 bool former
= MacIsReallyEnabled() ;
1771 #if TARGET_API_MAC_OSX
1773 EnableControl( *m_peer
) ;
1775 DisableControl( *m_peer
) ;
1778 ActivateControl( *m_peer
) ;
1780 DeactivateControl( *m_peer
) ;
1783 if ( former
!= MacIsReallyEnabled() )
1784 MacPropagateEnabledStateChanged() ;
1789 // status change propagations (will be not necessary for OSX later )
1792 void wxWindowMac::MacPropagateVisibilityChanged()
1794 #if !TARGET_API_MAC_OSX
1795 MacVisibilityChanged() ;
1797 wxWindowListNode
*node
= GetChildren().GetFirst();
1800 wxWindowMac
*child
= node
->GetData();
1801 if ( child
->IsShown() )
1802 child
->MacPropagateVisibilityChanged( ) ;
1803 node
= node
->GetNext();
1808 void wxWindowMac::MacPropagateEnabledStateChanged( )
1810 #if !TARGET_API_MAC_OSX
1811 MacEnabledStateChanged() ;
1813 wxWindowListNode
*node
= GetChildren().GetFirst();
1816 wxWindowMac
*child
= node
->GetData();
1817 if ( child
->IsEnabled() )
1818 child
->MacPropagateEnabledStateChanged() ;
1819 node
= node
->GetNext();
1824 void wxWindowMac::MacPropagateHiliteChanged( )
1826 #if !TARGET_API_MAC_OSX
1827 MacHiliteChanged() ;
1829 wxWindowListNode
*node
= GetChildren().GetFirst();
1832 wxWindowMac
*child
= node
->GetData();
1833 // if ( child->IsEnabled() )
1834 child
->MacPropagateHiliteChanged() ;
1835 node
= node
->GetNext();
1841 // status change notifications
1844 void wxWindowMac::MacVisibilityChanged()
1848 void wxWindowMac::MacHiliteChanged()
1852 void wxWindowMac::MacEnabledStateChanged()
1857 // status queries on the inherited window's state
1860 bool wxWindowMac::MacIsReallyShown()
1862 // only under OSX the visibility of the TLW is taken into account
1863 #if TARGET_API_MAC_OSX
1864 return IsControlVisible( *m_peer
) ;
1866 wxWindow
* win
= this ;
1867 while( win
->IsShown() )
1869 if ( win
->IsTopLevel() )
1872 win
= win
->GetParent() ;
1881 bool wxWindowMac::MacIsReallyEnabled()
1883 #if TARGET_API_MAC_OSX
1884 return IsControlEnabled( *m_peer
) ;
1886 return IsControlActive( *m_peer
) ;
1890 bool wxWindowMac::MacIsReallyHilited()
1892 return IsControlActive( *m_peer
) ;
1895 void wxWindowMac::MacFlashInvalidAreas()
1897 #if TARGET_API_MAC_OSX
1898 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1906 int wxWindowMac::GetCharHeight() const
1908 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1909 return dc
.GetCharHeight() ;
1912 int wxWindowMac::GetCharWidth() const
1914 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1915 return dc
.GetCharWidth() ;
1918 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1919 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1921 const wxFont
*fontToUse
= theFont
;
1923 fontToUse
= &m_font
;
1925 wxClientDC
dc( (wxWindowMac
*) this ) ;
1927 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1928 if ( externalLeading
)
1929 *externalLeading
= le
;
1939 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1940 * we always intersect with the entire window, not only with the client area
1943 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1945 #if TARGET_API_MAC_OSX
1947 HIViewSetNeedsDisplay( *m_peer
, true ) ;
1950 RgnHandle update
= NewRgn() ;
1951 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1952 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1953 wxPoint origin
= GetClientAreaOrigin() ;
1954 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1955 HIViewSetNeedsDisplayInRegion( *m_peer
, update
, true ) ;
1959 RgnHandle updateRgn = NewRgn() ;
1962 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1966 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1967 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1969 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1970 DisposeRgn(updateRgn) ;
1972 if ( IsControlVisible( *m_peer
) )
1974 SetControlVisibility( *m_peer
, false , false ) ;
1975 SetControlVisibility( *m_peer
, true , true ) ;
1978 if ( MacGetTopLevelWindow() == NULL )
1981 if ( !IsControlVisible( *m_peer ) )
1984 wxPoint client = GetClientAreaOrigin();
1987 int x2 = m_width - client.x;
1988 int y2 = m_height - client.y;
1990 if (IsKindOf( CLASSINFO(wxButton)))
1992 // buttons have an "aura"
1999 Rect clientrect = { y1, x1, y2, x2 };
2003 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2004 SectRect( &clientrect , &r , &clientrect ) ;
2007 if ( !EmptyRect( &clientrect ) )
2009 int top = 0 , left = 0 ;
2011 MacClientToRootWindow( &left , &top ) ;
2012 OffsetRect( &clientrect , left , top ) ;
2014 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2020 void wxWindowMac::Freeze()
2022 #if TARGET_API_MAC_OSX
2023 if ( !m_frozenness
++ )
2025 HIViewSetDrawingEnabled( *m_peer
, false ) ;
2030 #if TARGET_API_MAC_OSX
2031 static void InvalidateControlAndChildren( HIViewRef control
)
2033 HIViewSetNeedsDisplay( control
, true ) ;
2034 UInt16 childrenCount
= 0 ;
2035 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
2036 if ( err
== errControlIsNotEmbedder
)
2038 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2040 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2043 err
= GetIndexedSubControl( control
, i
, & child
) ;
2044 if ( err
== errControlIsNotEmbedder
)
2046 InvalidateControlAndChildren( child
) ;
2051 void wxWindowMac::Thaw()
2053 #if TARGET_API_MAC_OSX
2054 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2056 if ( !--m_frozenness
)
2058 HIViewSetDrawingEnabled( *m_peer
, true ) ;
2059 InvalidateControlAndChildren( *m_peer
) ;
2060 // HIViewSetNeedsDisplay( *m_peer , true ) ;
2065 void wxWindowMac::MacRedrawControl()
2068 if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) )
2070 #if TARGET_API_MAC_CARBON
2073 wxClientDC dc(this) ;
2074 wxMacPortSetter helper(&dc) ;
2075 wxMacWindowClipper clipper(this) ;
2076 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2077 UMADrawControl( *m_peer ) ;
2084 void wxWindowMac::OnPaint(wxPaintEvent& event)
2086 // why don't we skip that here ?
2090 wxWindowMac
*wxGetActiveWindow()
2092 // actually this is a windows-only concept
2096 // Coordinates relative to the window
2097 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2099 // We really don't move the mouse programmatically under Mac.
2102 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2104 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2109 event
.GetDC()->Clear() ;
2112 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2114 wxWindowDC
dc(this) ;
2115 wxMacPortSetter
helper(&dc
) ;
2117 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2120 int wxWindowMac::GetScrollPos(int orient
) const
2122 if ( orient
== wxHORIZONTAL
)
2125 return m_hScrollBar
->GetThumbPosition() ;
2130 return m_vScrollBar
->GetThumbPosition() ;
2135 // This now returns the whole range, not just the number
2136 // of positions that we can scroll.
2137 int wxWindowMac::GetScrollRange(int orient
) const
2139 if ( orient
== wxHORIZONTAL
)
2142 return m_hScrollBar
->GetRange() ;
2147 return m_vScrollBar
->GetRange() ;
2152 int wxWindowMac::GetScrollThumb(int orient
) const
2154 if ( orient
== wxHORIZONTAL
)
2157 return m_hScrollBar
->GetThumbSize() ;
2162 return m_vScrollBar
->GetThumbSize() ;
2167 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2169 if ( orient
== wxHORIZONTAL
)
2172 m_hScrollBar
->SetThumbPosition( pos
) ;
2177 m_vScrollBar
->SetThumbPosition( pos
) ;
2181 void wxWindowMac::MacPaintBorders( int left
, int top
)
2187 wxGetOsVersion( &major
, &minor
);
2189 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2190 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2192 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2193 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2194 // OS X has lighter border edges than classic:
2197 darkShadow
.red
= 0x8E8E;
2198 darkShadow
.green
= 0x8E8E;
2199 darkShadow
.blue
= 0x8E8E;
2200 lightShadow
.red
= 0xBDBD;
2201 lightShadow
.green
= 0xBDBD;
2202 lightShadow
.blue
= 0xBDBD;
2208 GetSize( &w
, &h
) ;
2209 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2211 #if wxMAC_USE_THEME_BORDER
2212 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2215 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2216 InsetRect( &rect , border , border );
2217 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2220 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2222 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2223 RGBForeColor( &face
);
2224 MoveTo( left
+ 0 , top
+ h
- 2 );
2225 LineTo( left
+ 0 , top
+ 0 );
2226 LineTo( left
+ w
- 2 , top
+ 0 );
2228 MoveTo( left
+ 2 , top
+ h
- 3 );
2229 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2230 LineTo( left
+ w
- 3 , top
+ 2 );
2232 RGBForeColor( sunken
? &face
: &darkShadow
);
2233 MoveTo( left
+ 0 , top
+ h
- 1 );
2234 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2235 LineTo( left
+ w
- 1 , top
+ 0 );
2237 RGBForeColor( sunken
? &lightShadow
: &white
);
2238 MoveTo( left
+ 1 , top
+ h
- 3 );
2239 LineTo( left
+ 1, top
+ 1 );
2240 LineTo( left
+ w
- 3 , top
+ 1 );
2242 RGBForeColor( sunken
? &white
: &lightShadow
);
2243 MoveTo( left
+ 1 , top
+ h
- 2 );
2244 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2245 LineTo( left
+ w
- 2 , top
+ 1 );
2247 RGBForeColor( sunken
? &darkShadow
: &face
);
2248 MoveTo( left
+ 2 , top
+ h
- 4 );
2249 LineTo( left
+ 2 , top
+ 2 );
2250 LineTo( left
+ w
- 4 , top
+ 2 );
2253 else if (HasFlag(wxSIMPLE_BORDER
))
2255 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2256 RGBForeColor( &darkShadow
) ;
2257 FrameRect( &rect
) ;
2261 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2263 if ( child
== m_hScrollBar
)
2264 m_hScrollBar
= NULL
;
2265 if ( child
== m_vScrollBar
)
2266 m_vScrollBar
= NULL
;
2268 wxWindowBase::RemoveChild( child
) ;
2271 // New function that will replace some of the above.
2272 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2273 int range
, bool refresh
)
2275 if ( orient
== wxHORIZONTAL
)
2279 if ( range
== 0 || thumbVisible
>= range
)
2281 if ( m_hScrollBar
->IsShown() )
2282 m_hScrollBar
->Show(false) ;
2286 if ( !m_hScrollBar
->IsShown() )
2287 m_hScrollBar
->Show(true) ;
2288 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2296 if ( range
== 0 || thumbVisible
>= range
)
2298 if ( m_vScrollBar
->IsShown() )
2299 m_vScrollBar
->Show(false) ;
2303 if ( !m_vScrollBar
->IsShown() )
2304 m_vScrollBar
->Show(true) ;
2305 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2309 MacRepositionScrollBars() ;
2312 // Does a physical scroll
2313 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2315 if( dx
== 0 && dy
==0 )
2321 int width
, height
;
2322 GetClientSize( &width
, &height
) ;
2323 #if TARGET_API_MAC_OSX
2324 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2325 // area is scrolled, this does not occur if width and height are 2 pixels less,
2326 // TODO write optimal workaround
2327 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2330 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2331 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2333 if ( HIViewGetNeedsDisplay( *m_peer
) )
2335 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2336 // either immediate redraw or full invalidate
2338 // is the better overall solution, as it does not slow down scrolling
2339 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2341 // this would be the preferred version for fast drawing controls
2342 if( UMAGetSystemVersion() < 0x1030 )
2345 HIViewRender(*m_peer
) ;
2348 HIViewScrollRect ( *m_peer
, &scrollrect
, dx
,dy
) ;
2355 RgnHandle updateRgn
= NewRgn() ;
2358 wxClientDC
dc(this) ;
2359 wxMacPortSetter
helper(&dc
) ;
2361 GetControlBounds( *m_peer
, &scrollrect
);
2362 scrollrect
.top
+= MacGetTopBorderSize() ;
2363 scrollrect
.left
+= MacGetLeftBorderSize() ;
2364 scrollrect
.bottom
= scrollrect
.top
+ height
;
2365 scrollrect
.right
= scrollrect
.left
+ width
;
2369 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2370 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2371 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2373 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2375 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2379 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2381 wxWindowMac
*child
= node
->GetData();
2382 if (child
== m_vScrollBar
) continue;
2383 if (child
== m_hScrollBar
) continue;
2384 if (child
->IsTopLevel()) continue;
2387 child
->GetPosition( &x
, &y
);
2389 child
->GetSize( &w
, &h
);
2393 if (rect
->Intersects(rc
))
2394 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2398 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2403 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2405 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2407 wxScrollWinEvent wevent
;
2408 wevent
.SetPosition(event
.GetPosition());
2409 wevent
.SetOrientation(event
.GetOrientation());
2410 wevent
.m_eventObject
= this;
2412 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2413 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2414 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2415 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2416 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2417 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2418 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2419 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2420 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2421 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2422 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2423 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2424 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2425 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2426 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2427 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2429 GetEventHandler()->ProcessEvent(wevent
);
2433 // Get the window with the focus
2434 wxWindowMac
*wxWindowBase::FindFocus()
2436 ControlRef control
;
2437 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2438 return wxFindControlFromMacControl( control
) ;
2441 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2443 // panel wants to track the window which was the last to have focus in it,
2444 // so we want to set ourselves as the window which last had focus
2446 // notice that it's also important to do it upwards the tree becaus
2447 // otherwise when the top level panel gets focus, it won't set it back to
2448 // us, but to some other sibling
2450 // CS:don't know if this is still needed:
2451 //wxChildFocusEvent eventFocus(this);
2452 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2457 void wxWindowMac::OnInternalIdle()
2459 // This calls the UI-update mechanism (querying windows for
2460 // menu/toolbar/control state information)
2461 if (wxUpdateUIEvent::CanUpdate(this))
2462 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2465 // Raise the window to the top of the Z order
2466 void wxWindowMac::Raise()
2468 #if TARGET_API_MAC_OSX
2469 HIViewSetZOrder(*m_peer
,kHIViewZOrderAbove
, NULL
) ;
2473 // Lower the window to the bottom of the Z order
2474 void wxWindowMac::Lower()
2476 #if TARGET_API_MAC_OSX
2477 HIViewSetZOrder(*m_peer
,kHIViewZOrderBelow
, NULL
) ;
2482 // static wxWindow *gs_lastWhich = NULL;
2484 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2486 // first trigger a set cursor event
2488 wxPoint clientorigin
= GetClientAreaOrigin() ;
2489 wxSize clientsize
= GetClientSize() ;
2491 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2493 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2495 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2496 if ( processedEvtSetCursor
&& event
.HasCursor() )
2498 cursor
= event
.GetCursor() ;
2503 // the test for processedEvtSetCursor is here to prevent using m_cursor
2504 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2505 // it - this is a way to say that our cursor shouldn't be used for this
2507 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2517 cursor
= *wxSTANDARD_CURSOR
;
2521 cursor
.MacInstall() ;
2523 return cursor
.Ok() ;
2526 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2530 return m_tooltip
->GetTip() ;
2532 return wxEmptyString
;
2535 void wxWindowMac::Update()
2537 #if TARGET_API_MAC_OSX
2538 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2539 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2540 // for composited windows this also triggers a redraw of all
2541 // invalid views in the window
2542 if( UMAGetSystemVersion() >= 0x1030 )
2543 HIWindowFlush(window
) ;
2547 // the only way to trigger the redrawing on earlier systems is to call
2550 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2551 UInt32 currentEventClass
= 0 ;
2552 UInt32 currentEventKind
= 0 ;
2553 if ( currentEvent
!= NULL
)
2555 currentEventClass
= ::GetEventClass( currentEvent
) ;
2556 currentEventKind
= ::GetEventKind( currentEvent
) ;
2558 if ( currentEventClass
!= kEventClassMenu
)
2560 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2563 OSStatus status
= noErr
;
2564 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2567 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2570 ::Draw1Control( *m_peer
) ;
2574 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2576 wxTopLevelWindowMac
* win
= NULL
;
2577 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2580 win
= wxFindWinFromMacWindow( window
) ;
2584 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2588 RgnHandle visRgn
= NewRgn() ;
2589 RgnHandle tempRgn
= NewRgn() ;
2590 if ( IsControlVisible( *m_peer
) )
2592 GetControlBounds( *m_peer
, &r
) ;
2593 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2595 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2596 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2605 if ( includeOuterStructures
)
2606 InsetRect( &r
, -3 , -3 ) ;
2607 RectRgn( visRgn
, &r
) ;
2608 if ( !IsTopLevel() )
2610 wxWindow
* child
= this ;
2611 wxWindow
* parent
= child
->GetParent() ;
2616 // we have to find a better clipping algorithm here, in order not to clip things
2617 // positioned like status and toolbar
2618 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2620 size
= parent
->GetSize() ;
2625 size
= parent
->GetClientSize() ;
2626 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2630 parent
->MacWindowToRootWindow( &x
, &y
) ;
2631 MacRootWindowToWindow( &x
, &y
) ;
2633 SetRectRgn( tempRgn
,
2634 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2635 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2636 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2638 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2639 if ( parent
->IsTopLevel() )
2642 parent
= child
->GetParent() ;
2647 wxRegion vis
= visRgn
;
2648 DisposeRgn( visRgn
) ;
2649 DisposeRgn( tempRgn
) ;
2654 This function must not change the updatergn !
2656 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2658 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2659 bool handled
= false ;
2661 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2663 RgnHandle newupdate
= NewRgn() ;
2664 wxSize point
= GetClientSize() ;
2665 wxPoint origin
= GetClientAreaOrigin() ;
2666 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2667 SectRgn( newupdate
, updatergn
, newupdate
) ;
2668 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2669 m_updateRegion
= newupdate
;
2670 DisposeRgn( newupdate
) ;
2673 if ( !EmptyRgn(updatergn
) )
2675 wxWindowDC
dc(this);
2676 if (!EmptyRgn(updatergn
))
2677 dc
.SetClippingRegion(wxRegion(updatergn
));
2679 wxEraseEvent
eevent( GetId(), &dc
);
2680 eevent
.SetEventObject( this );
2681 GetEventHandler()->ProcessEvent( eevent
);
2683 if ( !m_updateRegion
.Empty() )
2685 // paint the window itself
2687 event
.m_timeStamp
= time
;
2688 event
.SetEventObject(this);
2689 handled
= GetEventHandler()->ProcessEvent(event
);
2691 // paint custom borders
2692 wxNcPaintEvent
eventNc( GetId() );
2693 eventNc
.SetEventObject( this );
2694 GetEventHandler()->ProcessEvent( eventNc
);
2700 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2702 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2703 // updatergn is always already clipped to our boundaries
2704 // if we are in compositing mode then it is in relative to the upper left of the control
2705 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2706 // of the toplevel window
2707 // it is in window coordinates, not in client coordinates
2709 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2710 RgnHandle ownUpdateRgn
= NewRgn() ;
2711 CopyRgn( updatergn
, ownUpdateRgn
) ;
2713 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2716 UMAGetControlBoundsInWindowCoords( *m_peer
, &bounds
);
2717 RgnHandle controlRgn
= NewRgn();
2718 RectRgn( controlRgn
, &bounds
);
2719 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2720 // the window update region
2721 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2722 DisposeRgn( controlRgn
);
2724 //KO: convert ownUpdateRgn to local coordinates
2725 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2728 MacDoRedraw( ownUpdateRgn
, time
) ;
2729 DisposeRgn( ownUpdateRgn
) ;
2733 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2735 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2739 if ( iter
->IsTopLevel() )
2740 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2742 iter
= iter
->GetParent() ;
2744 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2748 void wxWindowMac::MacCreateScrollBars( long style
)
2750 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2752 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2753 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2755 GetClientSize( &width
, &height
) ;
2757 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2758 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2759 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2760 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2762 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2763 vSize
, wxVERTICAL
);
2765 if ( style
& wxVSCROLL
)
2771 m_vScrollBar
->Show(false) ;
2773 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2774 hSize
, wxHORIZONTAL
);
2775 if ( style
& wxHSCROLL
)
2780 m_hScrollBar
->Show(false) ;
2783 // because the create does not take into account the client area origin
2784 MacRepositionScrollBars() ; // we might have a real position shift
2787 void wxWindowMac::MacRepositionScrollBars()
2789 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2790 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2792 // get real client area
2796 GetSize( &width
, &height
) ;
2798 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2799 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2801 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2802 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2803 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2804 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2810 GetSize( &w
, &h
) ;
2812 MacClientToRootWindow( &x
, &y
) ;
2813 MacClientToRootWindow( &w
, &h
) ;
2815 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2817 int totW
= 10000 , totH
= 10000;
2820 if ( iter
->IsTopLevel() )
2822 iter
->GetSize( &totW
, &totH
) ;
2826 iter
= iter
->GetParent() ;
2854 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2858 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2862 bool wxWindowMac::AcceptsFocus() const
2864 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2867 void wxWindowMac::MacSuperChangedPosition()
2869 // only window-absolute structures have to be moved i.e. controls
2871 wxWindowListNode
*node
= GetChildren().GetFirst();
2874 wxWindowMac
*child
= node
->GetData();
2875 child
->MacSuperChangedPosition() ;
2876 node
= node
->GetNext();
2880 void wxWindowMac::MacTopLevelWindowChangedPosition()
2882 // only screen-absolute structures have to be moved i.e. glcanvas
2884 wxWindowListNode
*node
= GetChildren().GetFirst();
2887 wxWindowMac
*child
= node
->GetData();
2888 child
->MacTopLevelWindowChangedPosition() ;
2889 node
= node
->GetNext();
2893 long wxWindowMac::MacGetLeftBorderSize( ) const
2898 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2901 #if wxMAC_USE_THEME_BORDER
2902 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2906 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2909 #if wxMAC_USE_THEME_BORDER
2910 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2914 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2921 long wxWindowMac::MacGetRightBorderSize( ) const
2923 // they are all symmetric in mac themes
2924 return MacGetLeftBorderSize() ;
2927 long wxWindowMac::MacGetTopBorderSize( ) const
2929 // they are all symmetric in mac themes
2930 return MacGetLeftBorderSize() ;
2933 long wxWindowMac::MacGetBottomBorderSize( ) const
2935 // they are all symmetric in mac themes
2936 return MacGetLeftBorderSize() ;
2939 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2941 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2944 // Find the wxWindowMac at the current mouse position, returning the mouse
2946 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2948 pt
= wxGetMousePosition();
2949 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2953 // Get the current mouse position.
2954 wxPoint
wxGetMousePosition()
2957 wxGetMousePosition(& x
, & y
);
2958 return wxPoint(x
, y
);
2961 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2963 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2965 // copied from wxGTK : CS
2966 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2969 // (a) it's a command event and so is propagated to the parent
2970 // (b) under MSW it can be generated from kbd too
2971 // (c) it uses screen coords (because of (a))
2972 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2974 this->ClientToScreen(event
.GetPosition()));
2975 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2984 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2988 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2992 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2993 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2997 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2999 return eventNotHandledErr
;