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 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
865 bool wxWindowMac::SetFont(const wxFont
& font
)
867 bool retval
= !wxWindowBase::SetFont( font
) ;
869 MacUpdateControlFont() ;
874 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
876 if ( !wxWindowBase::SetForegroundColour(col
) )
879 MacUpdateControlFont() ;
884 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
886 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
890 wxColour
newCol(GetBackgroundColour());
891 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
893 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
895 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
897 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
901 brush
.SetColour( newCol
) ;
903 MacSetBackgroundBrush( brush
) ;
905 MacUpdateControlFont() ;
911 bool wxWindowMac::MacCanFocus() const
913 // there is currently no way to determine whether the window is running in full keyboard
914 // access mode, therefore we cannot rely on these features, yet the only other way would be
915 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
916 // in event handlers...
917 UInt32 features
= 0 ;
918 GetControlFeatures( *m_peer
, &features
) ;
919 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
923 void wxWindowMac::SetFocus()
925 if ( AcceptsFocus() )
927 #if !TARGET_API_MAC_OSX
928 wxWindow
* former
= FindFocus() ;
930 OSStatus err
= SetKeyboardFocus( (WindowRef
) MacGetTopLevelWindowRef() , (ControlRef
) GetHandle() , kControlFocusNextPart
) ;
931 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
932 // leave in case of an error
933 if ( err
== errCouldntSetFocus
)
936 #if !TARGET_API_MAC_OSX
937 // emulate carbon events when running under carbonlib where they are not natively available
940 EventRef evRef
= NULL
;
941 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
944 wxMacCarbonEvent
cEvent( evRef
) ;
945 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
946 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
948 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
949 ReleaseEvent(evRef
) ;
951 // send new focus event
953 EventRef evRef
= NULL
;
954 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
957 wxMacCarbonEvent
cEvent( evRef
) ;
958 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
959 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
961 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
962 ReleaseEvent(evRef
) ;
969 void wxWindowMac::DoCaptureMouse()
971 wxTheApp
->s_captureWindow
= this ;
974 wxWindow
* wxWindowBase::GetCapture()
976 return wxTheApp
->s_captureWindow
;
979 void wxWindowMac::DoReleaseMouse()
981 wxTheApp
->s_captureWindow
= NULL
;
984 #if wxUSE_DRAG_AND_DROP
986 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
988 if ( m_dropTarget
!= 0 ) {
992 m_dropTarget
= pDropTarget
;
993 if ( m_dropTarget
!= 0 )
1001 // Old style file-manager drag&drop
1002 void wxWindowMac::DragAcceptFiles(bool accept
)
1007 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1008 int& w
, int& h
) const
1011 GetControlBounds( *m_peer
, &bounds
) ;
1016 w
= bounds
.right
- bounds
.left
;
1017 h
= bounds
.bottom
- bounds
.top
;
1019 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1022 Point tlworigin
= { 0 , 0 } ;
1023 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1029 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1032 int& w
, int& h
, bool adjustOrigin
) const
1036 // todo the default calls may be used as soon as PostCreateControl Is moved here
1037 w
= size
.x
; // WidthDefault( size.x );
1038 h
= size
.y
; // HeightDefault( size.y ) ;
1039 #if !TARGET_API_MAC_OSX
1040 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1043 AdjustForParentClientOrigin( x
, y
) ;
1048 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1050 #if TARGET_API_MAC_OSX
1051 int x1
, y1
, w1
,h1
;
1052 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1058 GetControlBounds( *m_peer
, &bounds
) ;
1059 if(x
) *x
= bounds
.right
- bounds
.left
;
1060 if(y
) *y
= bounds
.bottom
- bounds
.top
;
1064 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1066 #if TARGET_API_MAC_OSX
1067 int x1
, y1
, w1
,h1
;
1068 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1069 if ( !IsTopLevel() )
1071 wxWindow
*parent
= GetParent();
1074 wxPoint
pt(parent
->GetClientAreaOrigin());
1083 GetControlBounds( *m_peer
, &bounds
) ;
1084 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1086 int xx
= bounds
.left
;
1087 int yy
= bounds
.top
;
1089 if ( !GetParent()->IsTopLevel() )
1091 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1097 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1106 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1108 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1110 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1113 Point localwhere
= {0,0} ;
1115 if(x
) localwhere
.h
= * x
;
1116 if(y
) localwhere
.v
= * y
;
1118 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1119 if(x
) *x
= localwhere
.h
;
1120 if(y
) *y
= localwhere
.v
;
1123 MacRootWindowToWindow( x
, y
) ;
1125 wxPoint origin
= GetClientAreaOrigin() ;
1126 if(x
) *x
-= origin
.x
;
1127 if(y
) *y
-= origin
.y
;
1130 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1132 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1133 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1135 wxPoint origin
= GetClientAreaOrigin() ;
1136 if(x
) *x
+= origin
.x
;
1137 if(y
) *y
+= origin
.y
;
1139 MacWindowToRootWindow( x
, y
) ;
1142 Point localwhere
= { 0,0 };
1143 if(x
) localwhere
.h
= * x
;
1144 if(y
) localwhere
.v
= * y
;
1145 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1146 if(x
) *x
= localwhere
.h
;
1147 if(y
) *y
= localwhere
.v
;
1151 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1153 wxPoint origin
= GetClientAreaOrigin() ;
1154 if(x
) *x
+= origin
.x
;
1155 if(y
) *y
+= origin
.y
;
1157 MacWindowToRootWindow( x
, y
) ;
1160 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1162 MacRootWindowToWindow( x
, y
) ;
1164 wxPoint origin
= GetClientAreaOrigin() ;
1165 if(x
) *x
-= origin
.x
;
1166 if(y
) *y
-= origin
.y
;
1169 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1171 #if TARGET_API_MAC_OSX
1173 if ( x
) pt
.x
= *x
;
1174 if ( y
) pt
.y
= *y
;
1176 if ( !IsTopLevel() )
1178 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1180 HIViewConvertPoint( &pt
, *m_peer
, (ControlRef
) top
->GetHandle() ) ;
1183 if ( x
) *x
= (int) pt
.x
;
1184 if ( y
) *y
= (int) pt
.y
;
1186 if ( !IsTopLevel() )
1189 GetControlBounds( *m_peer
, &bounds
) ;
1190 if(x
) *x
+= bounds
.left
;
1191 if(y
) *y
+= bounds
.top
;
1196 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1201 MacWindowToRootWindow( &x1
, &y1
) ;
1206 void wxWindowMac::MacRootWindowToWindow( 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() )
1214 HIViewConvertPoint( &pt
, (ControlRef
) MacGetTopLevelWindow()->GetHandle() , *m_peer
) ;
1216 if ( x
) *x
= (int) pt
.x
;
1217 if ( y
) *y
= (int) pt
.y
;
1219 if ( !IsTopLevel() )
1222 GetControlBounds( *m_peer
, &bounds
) ;
1223 if(x
) *x
-= bounds
.left
;
1224 if(y
) *y
-= bounds
.top
;
1229 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1234 MacRootWindowToWindow( &x1
, &y1
) ;
1239 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1241 RgnHandle rgn
= NewRgn() ;
1243 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1245 GetRegionBounds( rgn
, &content
) ;
1250 GetControlBounds( *m_peer
, &content
) ;
1253 GetControlBounds( *m_peer
, &structure
) ;
1254 #if !TARGET_API_MAC_OSX
1255 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1257 left
= content
.left
- structure
.left
;
1258 top
= content
.top
- structure
.top
;
1259 right
= structure
.right
- content
.right
;
1260 bottom
= structure
.bottom
- content
.bottom
;
1263 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1265 wxSize sizeTotal
= size
;
1267 RgnHandle rgn
= NewRgn() ;
1271 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1273 GetRegionBounds( rgn
, &content
) ;
1278 GetControlBounds( *m_peer
, &content
) ;
1281 GetControlBounds( *m_peer
, &structure
) ;
1282 #if !TARGET_API_MAC_OSX
1283 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1286 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1287 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1289 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1290 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1296 // Get size *available for subwindows* i.e. excluding menu bar etc.
1297 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1301 RgnHandle rgn
= NewRgn() ;
1303 if ( GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) == noErr
)
1305 GetRegionBounds( rgn
, &content
) ;
1310 GetControlBounds( *m_peer
, &content
) ;
1312 #if !TARGET_API_MAC_OSX
1314 GetControlBounds( *m_peer
, &structure
) ;
1315 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1317 ww
= content
.right
- content
.left
;
1318 hh
= content
.bottom
- content
.top
;
1320 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1321 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1323 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1329 GetSize( &w
, &h
) ;
1331 MacClientToRootWindow( &x1
, &y1
) ;
1332 MacClientToRootWindow( &w
, &h
) ;
1334 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1336 int totW
= 10000 , totH
= 10000;
1339 if ( iter
->IsTopLevel() )
1341 iter
->GetSize( &totW
, &totH
) ;
1345 iter
= iter
->GetParent() ;
1348 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1350 hh
-= MAC_SCROLLBAR_SIZE
;
1356 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1358 ww
-= MAC_SCROLLBAR_SIZE
;
1370 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1372 if (m_cursor
== cursor
)
1375 if (wxNullCursor
== cursor
)
1377 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1382 if ( ! wxWindowBase::SetCursor( cursor
) )
1386 wxASSERT_MSG( m_cursor
.Ok(),
1387 wxT("cursor must be valid after call to the base version"));
1390 wxWindowMac
*mouseWin
= 0 ;
1392 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1394 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1396 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1397 // position, use it...
1401 ControlPartCode part
;
1402 ControlRef control
;
1403 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1405 mouseWin
= wxFindControlFromMacControl( control
) ;
1408 QDSwapPort( savePort
, NULL
) ;
1411 if ( mouseWin
== this && !wxIsBusy() )
1413 m_cursor
.MacInstall() ;
1420 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1422 menu
->SetInvokingWindow(this);
1425 if ( x
== -1 && y
== -1 )
1427 wxPoint mouse
= wxGetMousePosition();
1428 x
= mouse
.x
; y
= mouse
.y
;
1432 ClientToScreen( &x
, &y
) ;
1435 menu
->MacBeforeDisplay( true ) ;
1436 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1437 if ( HiWord(menuResult
) != 0 )
1440 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1441 wxMenuItem
* item
= NULL
;
1443 item
= menu
->FindItem(id
, &realmenu
) ;
1444 if (item
->IsCheckable())
1446 item
->Check( !item
->IsChecked() ) ;
1448 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1450 menu
->MacAfterDisplay( true ) ;
1452 menu
->SetInvokingWindow(NULL
);
1458 // ----------------------------------------------------------------------------
1460 // ----------------------------------------------------------------------------
1464 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1466 wxWindowBase::DoSetToolTip(tooltip
);
1469 m_tooltip
->SetWindow(this);
1472 #endif // wxUSE_TOOLTIPS
1474 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1476 int former_x
, former_y
, former_w
, former_h
;
1477 #if !TARGET_API_MAC_OSX
1478 DoGetPosition( &former_x
, &former_y
) ;
1479 DoGetSize( &former_w
, &former_h
) ;
1481 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1484 int actualWidth
= width
;
1485 int actualHeight
= height
;
1489 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1490 actualWidth
= m_minWidth
;
1491 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1492 actualHeight
= m_minHeight
;
1493 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1494 actualWidth
= m_maxWidth
;
1495 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1496 actualHeight
= m_maxHeight
;
1498 bool doMove
= false ;
1499 bool doResize
= false ;
1501 if ( actualX
!= former_x
|| actualY
!= former_y
)
1505 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1510 if ( doMove
|| doResize
)
1512 // we don't adjust twice for the origin
1513 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1514 bool vis
= IsControlVisible( *m_peer
) ;
1515 #if TARGET_API_MAC_OSX
1516 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1518 SetControlVisibility( *m_peer
, false , true ) ;
1519 HIRect hir
= { r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
} ;
1520 HIViewSetFrame ( *m_peer
, &hir
) ;
1522 SetControlVisibility( *m_peer
, true , true ) ;
1525 SetControlVisibility( *m_peer
, false , true ) ;
1526 SetControlBounds( *m_peer
, &r
) ;
1528 SetControlVisibility( *m_peer
, true , true ) ;
1530 MacRepositionScrollBars() ;
1533 wxPoint
point(actualX
,actualY
);
1534 wxMoveEvent
event(point
, m_windowId
);
1535 event
.SetEventObject(this);
1536 GetEventHandler()->ProcessEvent(event
) ;
1540 MacRepositionScrollBars() ;
1541 wxSize
size(actualWidth
, actualHeight
);
1542 wxSizeEvent
event(size
, m_windowId
);
1543 event
.SetEventObject(this);
1544 GetEventHandler()->ProcessEvent(event
);
1550 wxSize
wxWindowMac::DoGetBestSize() const
1552 if ( m_macIsUserPane
|| IsTopLevel() )
1553 return wxWindowBase::DoGetBestSize() ;
1555 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1556 short baselineoffset
;
1557 int bestWidth
, bestHeight
;
1558 ::GetBestControlRect( *m_peer
, &bestsize
, &baselineoffset
) ;
1560 if ( EmptyRect( &bestsize
) )
1563 bestsize
.left
= bestsize
.top
= 0 ;
1564 bestsize
.right
= 16 ;
1565 bestsize
.bottom
= 16 ;
1566 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1568 bestsize
.bottom
= 16 ;
1570 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1572 bestsize
.bottom
= 24 ;
1576 // return wxWindowBase::DoGetBestSize() ;
1580 bestWidth
= bestsize
.right
- bestsize
.left
;
1581 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1582 if ( bestHeight
< 10 )
1585 return wxSize(bestWidth
, bestHeight
);
1586 // return wxWindowBase::DoGetBestSize() ;
1590 // set the size of the window: if the dimensions are positive, just use them,
1591 // but if any of them is equal to -1, it means that we must find the value for
1592 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1593 // which case -1 is a valid value for x and y)
1595 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1596 // the width/height to best suit our contents, otherwise we reuse the current
1598 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1600 // get the current size and position...
1601 int currentX
, currentY
;
1602 GetPosition(¤tX
, ¤tY
);
1604 int currentW
,currentH
;
1605 GetSize(¤tW
, ¤tH
);
1607 // ... and don't do anything (avoiding flicker) if it's already ok
1608 if ( x
== currentX
&& y
== currentY
&&
1609 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1612 MacRepositionScrollBars() ; // we might have a real position shift
1616 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1618 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1621 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1623 wxSize
size(-1, -1);
1626 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1628 size
= DoGetBestSize();
1633 // just take the current one
1640 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1644 size
= DoGetBestSize();
1646 //else: already called DoGetBestSize() above
1652 // just take the current one
1657 DoMoveWindow(x
, y
, width
, height
);
1661 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1663 RgnHandle rgn
= NewRgn() ;
1665 GetControlRegion( *m_peer
, kControlContentMetaPart
, rgn
) ;
1666 GetRegionBounds( rgn
, &content
) ;
1668 #if !TARGET_API_MAC_OSX
1669 // if the content rgn is empty / not supported
1670 // don't attempt to correct the coordinates to wxWindow relative ones
1671 if (!::EmptyRect( &content
) )
1674 GetControlBounds( *m_peer
, &structure
) ;
1675 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1679 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1682 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1684 if ( clientheight
!= -1 || clientheight
!= -1 )
1686 int currentclientwidth
, currentclientheight
;
1687 int currentwidth
, currentheight
;
1689 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1690 GetSize( ¤twidth
, ¤theight
) ;
1692 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1693 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1697 void wxWindowMac::SetTitle(const wxString
& title
)
1699 m_label
= wxStripMenuCodes(title
) ;
1701 if ( m_peer
&& m_peer
->Ok() )
1703 UMASetControlTitle( *m_peer
, m_label
, m_font
.GetEncoding() ) ;
1708 wxString
wxWindowMac::GetTitle() const
1713 bool wxWindowMac::Show(bool show
)
1715 if ( !wxWindowBase::Show(show
) )
1718 // TODO use visibilityChanged Carbon Event for OSX
1719 bool former
= MacIsReallyShown() ;
1721 SetControlVisibility( *m_peer
, show
, true ) ;
1722 if ( former
!= MacIsReallyShown() )
1723 MacPropagateVisibilityChanged() ;
1727 bool wxWindowMac::Enable(bool enable
)
1729 wxASSERT( m_peer
->Ok() ) ;
1730 if ( !wxWindowBase::Enable(enable
) )
1733 bool former
= MacIsReallyEnabled() ;
1734 #if TARGET_API_MAC_OSX
1736 EnableControl( *m_peer
) ;
1738 DisableControl( *m_peer
) ;
1741 ActivateControl( *m_peer
) ;
1743 DeactivateControl( *m_peer
) ;
1746 if ( former
!= MacIsReallyEnabled() )
1747 MacPropagateEnabledStateChanged() ;
1752 // status change propagations (will be not necessary for OSX later )
1755 void wxWindowMac::MacPropagateVisibilityChanged()
1757 #if !TARGET_API_MAC_OSX
1758 MacVisibilityChanged() ;
1760 wxWindowListNode
*node
= GetChildren().GetFirst();
1763 wxWindowMac
*child
= node
->GetData();
1764 if ( child
->IsShown() )
1765 child
->MacPropagateVisibilityChanged( ) ;
1766 node
= node
->GetNext();
1771 void wxWindowMac::MacPropagateEnabledStateChanged( )
1773 #if !TARGET_API_MAC_OSX
1774 MacEnabledStateChanged() ;
1776 wxWindowListNode
*node
= GetChildren().GetFirst();
1779 wxWindowMac
*child
= node
->GetData();
1780 if ( child
->IsEnabled() )
1781 child
->MacPropagateEnabledStateChanged() ;
1782 node
= node
->GetNext();
1787 void wxWindowMac::MacPropagateHiliteChanged( )
1789 #if !TARGET_API_MAC_OSX
1790 MacHiliteChanged() ;
1792 wxWindowListNode
*node
= GetChildren().GetFirst();
1795 wxWindowMac
*child
= node
->GetData();
1796 // if ( child->IsEnabled() )
1797 child
->MacPropagateHiliteChanged() ;
1798 node
= node
->GetNext();
1804 // status change notifications
1807 void wxWindowMac::MacVisibilityChanged()
1811 void wxWindowMac::MacHiliteChanged()
1815 void wxWindowMac::MacEnabledStateChanged()
1820 // status queries on the inherited window's state
1823 bool wxWindowMac::MacIsReallyShown()
1825 // only under OSX the visibility of the TLW is taken into account
1826 #if TARGET_API_MAC_OSX
1827 return IsControlVisible( *m_peer
) ;
1829 wxWindow
* win
= this ;
1830 while( win
->IsShown() )
1832 if ( win
->IsTopLevel() )
1835 win
= win
->GetParent() ;
1844 bool wxWindowMac::MacIsReallyEnabled()
1846 #if TARGET_API_MAC_OSX
1847 return IsControlEnabled( *m_peer
) ;
1849 return IsControlActive( *m_peer
) ;
1853 bool wxWindowMac::MacIsReallyHilited()
1855 return IsControlActive( *m_peer
) ;
1858 void wxWindowMac::MacFlashInvalidAreas()
1860 #if TARGET_API_MAC_OSX
1861 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1869 int wxWindowMac::GetCharHeight() const
1871 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1872 return dc
.GetCharHeight() ;
1875 int wxWindowMac::GetCharWidth() const
1877 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1878 return dc
.GetCharWidth() ;
1881 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1882 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1884 const wxFont
*fontToUse
= theFont
;
1886 fontToUse
= &m_font
;
1888 wxClientDC
dc( (wxWindowMac
*) this ) ;
1890 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1891 if ( externalLeading
)
1892 *externalLeading
= le
;
1902 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1903 * we always intersect with the entire window, not only with the client area
1906 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1908 #if TARGET_API_MAC_OSX
1910 HIViewSetNeedsDisplay( *m_peer
, true ) ;
1913 RgnHandle update
= NewRgn() ;
1914 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1915 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1916 wxPoint origin
= GetClientAreaOrigin() ;
1917 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1918 HIViewSetNeedsDisplayInRegion( *m_peer
, update
, true ) ;
1922 RgnHandle updateRgn = NewRgn() ;
1925 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1929 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1930 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1932 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1933 DisposeRgn(updateRgn) ;
1935 if ( IsControlVisible( *m_peer
) )
1937 SetControlVisibility( *m_peer
, false , false ) ;
1938 SetControlVisibility( *m_peer
, true , true ) ;
1941 if ( MacGetTopLevelWindow() == NULL )
1944 if ( !IsControlVisible( *m_peer ) )
1947 wxPoint client = GetClientAreaOrigin();
1950 int x2 = m_width - client.x;
1951 int y2 = m_height - client.y;
1953 if (IsKindOf( CLASSINFO(wxButton)))
1955 // buttons have an "aura"
1962 Rect clientrect = { y1, x1, y2, x2 };
1966 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1967 SectRect( &clientrect , &r , &clientrect ) ;
1970 if ( !EmptyRect( &clientrect ) )
1972 int top = 0 , left = 0 ;
1974 MacClientToRootWindow( &left , &top ) ;
1975 OffsetRect( &clientrect , left , top ) ;
1977 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1983 void wxWindowMac::Freeze()
1985 #if TARGET_API_MAC_OSX
1986 if ( !m_frozenness
++ )
1988 HIViewSetDrawingEnabled( *m_peer
, false ) ;
1993 #if TARGET_API_MAC_OSX
1994 static void InvalidateControlAndChildren( HIViewRef control
)
1996 HIViewSetNeedsDisplay( control
, true ) ;
1997 UInt16 childrenCount
= 0 ;
1998 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1999 if ( err
== errControlIsNotEmbedder
)
2001 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
2003 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
2006 err
= GetIndexedSubControl( control
, i
, & child
) ;
2007 if ( err
== errControlIsNotEmbedder
)
2009 InvalidateControlAndChildren( child
) ;
2014 void wxWindowMac::Thaw()
2016 #if TARGET_API_MAC_OSX
2017 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2019 if ( !--m_frozenness
)
2021 HIViewSetDrawingEnabled( *m_peer
, true ) ;
2022 InvalidateControlAndChildren( *m_peer
) ;
2023 // HIViewSetNeedsDisplay( *m_peer , true ) ;
2028 void wxWindowMac::MacRedrawControl()
2031 if ( *m_peer && MacGetTopLevelWindowRef() && IsControlVisible( *m_peer ) )
2033 #if TARGET_API_MAC_CARBON
2036 wxClientDC dc(this) ;
2037 wxMacPortSetter helper(&dc) ;
2038 wxMacWindowClipper clipper(this) ;
2039 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2040 UMADrawControl( *m_peer ) ;
2047 void wxWindowMac::OnPaint(wxPaintEvent& event)
2049 // why don't we skip that here ?
2053 wxWindowMac
*wxGetActiveWindow()
2055 // actually this is a windows-only concept
2059 // Coordinates relative to the window
2060 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2062 // We really don't move the mouse programmatically under Mac.
2065 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2067 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2072 event
.GetDC()->Clear() ;
2075 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2077 wxWindowDC
dc(this) ;
2078 wxMacPortSetter
helper(&dc
) ;
2080 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2083 int wxWindowMac::GetScrollPos(int orient
) const
2085 if ( orient
== wxHORIZONTAL
)
2088 return m_hScrollBar
->GetThumbPosition() ;
2093 return m_vScrollBar
->GetThumbPosition() ;
2098 // This now returns the whole range, not just the number
2099 // of positions that we can scroll.
2100 int wxWindowMac::GetScrollRange(int orient
) const
2102 if ( orient
== wxHORIZONTAL
)
2105 return m_hScrollBar
->GetRange() ;
2110 return m_vScrollBar
->GetRange() ;
2115 int wxWindowMac::GetScrollThumb(int orient
) const
2117 if ( orient
== wxHORIZONTAL
)
2120 return m_hScrollBar
->GetThumbSize() ;
2125 return m_vScrollBar
->GetThumbSize() ;
2130 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2132 if ( orient
== wxHORIZONTAL
)
2135 m_hScrollBar
->SetThumbPosition( pos
) ;
2140 m_vScrollBar
->SetThumbPosition( pos
) ;
2144 void wxWindowMac::MacPaintBorders( int left
, int top
)
2150 wxGetOsVersion( &major
, &minor
);
2152 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2153 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2155 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2156 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2157 // OS X has lighter border edges than classic:
2160 darkShadow
.red
= 0x8E8E;
2161 darkShadow
.green
= 0x8E8E;
2162 darkShadow
.blue
= 0x8E8E;
2163 lightShadow
.red
= 0xBDBD;
2164 lightShadow
.green
= 0xBDBD;
2165 lightShadow
.blue
= 0xBDBD;
2171 GetSize( &w
, &h
) ;
2172 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2174 #if wxMAC_USE_THEME_BORDER
2175 Rect rect
= { top
, left
, m_height
+ top
, m_width
+ left
} ;
2178 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2179 InsetRect( &rect , border , border );
2180 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2183 DrawThemePrimaryGroup(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2185 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2186 RGBForeColor( &face
);
2187 MoveTo( left
+ 0 , top
+ h
- 2 );
2188 LineTo( left
+ 0 , top
+ 0 );
2189 LineTo( left
+ w
- 2 , top
+ 0 );
2191 MoveTo( left
+ 2 , top
+ h
- 3 );
2192 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2193 LineTo( left
+ w
- 3 , top
+ 2 );
2195 RGBForeColor( sunken
? &face
: &darkShadow
);
2196 MoveTo( left
+ 0 , top
+ h
- 1 );
2197 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2198 LineTo( left
+ w
- 1 , top
+ 0 );
2200 RGBForeColor( sunken
? &lightShadow
: &white
);
2201 MoveTo( left
+ 1 , top
+ h
- 3 );
2202 LineTo( left
+ 1, top
+ 1 );
2203 LineTo( left
+ w
- 3 , top
+ 1 );
2205 RGBForeColor( sunken
? &white
: &lightShadow
);
2206 MoveTo( left
+ 1 , top
+ h
- 2 );
2207 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2208 LineTo( left
+ w
- 2 , top
+ 1 );
2210 RGBForeColor( sunken
? &darkShadow
: &face
);
2211 MoveTo( left
+ 2 , top
+ h
- 4 );
2212 LineTo( left
+ 2 , top
+ 2 );
2213 LineTo( left
+ w
- 4 , top
+ 2 );
2216 else if (HasFlag(wxSIMPLE_BORDER
))
2218 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2219 RGBForeColor( &darkShadow
) ;
2220 FrameRect( &rect
) ;
2224 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2226 if ( child
== m_hScrollBar
)
2227 m_hScrollBar
= NULL
;
2228 if ( child
== m_vScrollBar
)
2229 m_vScrollBar
= NULL
;
2231 wxWindowBase::RemoveChild( child
) ;
2234 // New function that will replace some of the above.
2235 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2236 int range
, bool refresh
)
2238 if ( orient
== wxHORIZONTAL
)
2242 if ( range
== 0 || thumbVisible
>= range
)
2244 if ( m_hScrollBar
->IsShown() )
2245 m_hScrollBar
->Show(false) ;
2249 if ( !m_hScrollBar
->IsShown() )
2250 m_hScrollBar
->Show(true) ;
2251 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2259 if ( range
== 0 || thumbVisible
>= range
)
2261 if ( m_vScrollBar
->IsShown() )
2262 m_vScrollBar
->Show(false) ;
2266 if ( !m_vScrollBar
->IsShown() )
2267 m_vScrollBar
->Show(true) ;
2268 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2272 MacRepositionScrollBars() ;
2275 // Does a physical scroll
2276 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2278 if( dx
== 0 && dy
==0 )
2284 int width
, height
;
2285 GetClientSize( &width
, &height
) ;
2286 #if TARGET_API_MAC_OSX
2287 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2288 // area is scrolled, this does not occur if width and height are 2 pixels less,
2289 // TODO write optimal workaround
2290 HIRect scrollrect
= CGRectMake( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2293 HIRect scrollarea
= CGRectMake( rect
->x
, rect
->y
, rect
->width
, rect
->height
) ;
2294 scrollrect
= CGRectIntersection( scrollrect
, scrollarea
) ;
2296 if ( HIViewGetNeedsDisplay( *m_peer
) )
2298 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2299 // either immediate redraw or full invalidate
2301 // is the better overall solution, as it does not slow down scrolling
2302 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2304 // this would be the preferred version for fast drawing controls
2305 if( UMAGetSystemVersion() < 0x1030 )
2308 HIViewRender(*m_peer
) ;
2311 HIViewScrollRect ( *m_peer
, &scrollrect
, dx
,dy
) ;
2318 RgnHandle updateRgn
= NewRgn() ;
2321 wxClientDC
dc(this) ;
2322 wxMacPortSetter
helper(&dc
) ;
2324 GetControlBounds( *m_peer
, &scrollrect
);
2325 scrollrect
.top
+= MacGetTopBorderSize() ;
2326 scrollrect
.left
+= MacGetLeftBorderSize() ;
2327 scrollrect
.bottom
= scrollrect
.top
+ height
;
2328 scrollrect
.right
= scrollrect
.left
+ width
;
2332 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2333 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2334 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2336 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2338 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2342 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2344 wxWindowMac
*child
= node
->GetData();
2345 if (child
== m_vScrollBar
) continue;
2346 if (child
== m_hScrollBar
) continue;
2347 if (child
->IsTopLevel()) continue;
2350 child
->GetPosition( &x
, &y
);
2352 child
->GetSize( &w
, &h
);
2356 if (rect
->Intersects(rc
))
2357 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2361 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2366 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2368 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2370 wxScrollWinEvent wevent
;
2371 wevent
.SetPosition(event
.GetPosition());
2372 wevent
.SetOrientation(event
.GetOrientation());
2373 wevent
.m_eventObject
= this;
2375 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2377 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2378 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2379 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2380 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2381 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2382 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2383 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2384 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2385 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2386 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2387 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2388 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2389 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2390 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2392 GetEventHandler()->ProcessEvent(wevent
);
2396 // Get the window with the focus
2397 wxWindowMac
*wxWindowBase::FindFocus()
2399 ControlRef control
;
2400 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2401 return wxFindControlFromMacControl( control
) ;
2404 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2406 // panel wants to track the window which was the last to have focus in it,
2407 // so we want to set ourselves as the window which last had focus
2409 // notice that it's also important to do it upwards the tree becaus
2410 // otherwise when the top level panel gets focus, it won't set it back to
2411 // us, but to some other sibling
2413 // CS:don't know if this is still needed:
2414 //wxChildFocusEvent eventFocus(this);
2415 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2420 void wxWindowMac::OnInternalIdle()
2422 // This calls the UI-update mechanism (querying windows for
2423 // menu/toolbar/control state information)
2424 if (wxUpdateUIEvent::CanUpdate(this))
2425 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2428 // Raise the window to the top of the Z order
2429 void wxWindowMac::Raise()
2431 #if TARGET_API_MAC_OSX
2432 HIViewSetZOrder(*m_peer
,kHIViewZOrderAbove
, NULL
) ;
2436 // Lower the window to the bottom of the Z order
2437 void wxWindowMac::Lower()
2439 #if TARGET_API_MAC_OSX
2440 HIViewSetZOrder(*m_peer
,kHIViewZOrderBelow
, NULL
) ;
2445 // static wxWindow *gs_lastWhich = NULL;
2447 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2449 // first trigger a set cursor event
2451 wxPoint clientorigin
= GetClientAreaOrigin() ;
2452 wxSize clientsize
= GetClientSize() ;
2454 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2456 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2458 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2459 if ( processedEvtSetCursor
&& event
.HasCursor() )
2461 cursor
= event
.GetCursor() ;
2466 // the test for processedEvtSetCursor is here to prevent using m_cursor
2467 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2468 // it - this is a way to say that our cursor shouldn't be used for this
2470 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2480 cursor
= *wxSTANDARD_CURSOR
;
2484 cursor
.MacInstall() ;
2486 return cursor
.Ok() ;
2489 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2493 return m_tooltip
->GetTip() ;
2495 return wxEmptyString
;
2498 void wxWindowMac::Update()
2500 #if TARGET_API_MAC_OSX
2501 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2502 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2503 // for composited windows this also triggers a redraw of all
2504 // invalid views in the window
2505 if( UMAGetSystemVersion() >= 0x1030 )
2506 HIWindowFlush(window
) ;
2510 // the only way to trigger the redrawing on earlier systems is to call
2513 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2514 UInt32 currentEventClass
= 0 ;
2515 UInt32 currentEventKind
= 0 ;
2516 if ( currentEvent
!= NULL
)
2518 currentEventClass
= ::GetEventClass( currentEvent
) ;
2519 currentEventKind
= ::GetEventKind( currentEvent
) ;
2521 if ( currentEventClass
!= kEventClassMenu
)
2523 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2526 OSStatus status
= noErr
;
2527 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2530 HIViewSetNeedsDisplay( *m_peer
, true ) ;
2533 ::Draw1Control( *m_peer
) ;
2537 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2539 wxTopLevelWindowMac
* win
= NULL
;
2540 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2543 win
= wxFindWinFromMacWindow( window
) ;
2547 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2551 RgnHandle visRgn
= NewRgn() ;
2552 RgnHandle tempRgn
= NewRgn() ;
2553 if ( IsControlVisible( *m_peer
) )
2555 GetControlBounds( *m_peer
, &r
) ;
2556 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2558 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2559 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2568 if ( includeOuterStructures
)
2569 InsetRect( &r
, -3 , -3 ) ;
2570 RectRgn( visRgn
, &r
) ;
2571 if ( !IsTopLevel() )
2573 wxWindow
* child
= this ;
2574 wxWindow
* parent
= child
->GetParent() ;
2579 // we have to find a better clipping algorithm here, in order not to clip things
2580 // positioned like status and toolbar
2581 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2583 size
= parent
->GetSize() ;
2588 size
= parent
->GetClientSize() ;
2589 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2593 parent
->MacWindowToRootWindow( &x
, &y
) ;
2594 MacRootWindowToWindow( &x
, &y
) ;
2596 SetRectRgn( tempRgn
,
2597 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2598 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2599 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2601 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2602 if ( parent
->IsTopLevel() )
2605 parent
= child
->GetParent() ;
2610 wxRegion vis
= visRgn
;
2611 DisposeRgn( visRgn
) ;
2612 DisposeRgn( tempRgn
) ;
2617 This function must not change the updatergn !
2619 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2621 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2622 bool handled
= false ;
2624 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2626 RgnHandle newupdate
= NewRgn() ;
2627 wxSize point
= GetClientSize() ;
2628 wxPoint origin
= GetClientAreaOrigin() ;
2629 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2630 SectRgn( newupdate
, updatergn
, newupdate
) ;
2631 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2632 m_updateRegion
= newupdate
;
2633 DisposeRgn( newupdate
) ;
2636 if ( !EmptyRgn(updatergn
) )
2638 wxWindowDC
dc(this);
2639 if (!EmptyRgn(updatergn
))
2640 dc
.SetClippingRegion(wxRegion(updatergn
));
2642 wxEraseEvent
eevent( GetId(), &dc
);
2643 eevent
.SetEventObject( this );
2644 GetEventHandler()->ProcessEvent( eevent
);
2646 if ( !m_updateRegion
.Empty() )
2648 // paint the window itself
2650 event
.m_timeStamp
= time
;
2651 event
.SetEventObject(this);
2652 handled
= GetEventHandler()->ProcessEvent(event
);
2654 // paint custom borders
2655 wxNcPaintEvent
eventNc( GetId() );
2656 eventNc
.SetEventObject( this );
2657 GetEventHandler()->ProcessEvent( eventNc
);
2663 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2665 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2666 // updatergn is always already clipped to our boundaries
2667 // if we are in compositing mode then it is in relative to the upper left of the control
2668 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2669 // of the toplevel window
2670 // it is in window coordinates, not in client coordinates
2672 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2673 RgnHandle ownUpdateRgn
= NewRgn() ;
2674 CopyRgn( updatergn
, ownUpdateRgn
) ;
2676 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2679 UMAGetControlBoundsInWindowCoords( *m_peer
, &bounds
);
2680 RgnHandle controlRgn
= NewRgn();
2681 RectRgn( controlRgn
, &bounds
);
2682 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2683 // the window update region
2684 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2685 DisposeRgn( controlRgn
);
2687 //KO: convert ownUpdateRgn to local coordinates
2688 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2691 MacDoRedraw( ownUpdateRgn
, time
) ;
2692 DisposeRgn( ownUpdateRgn
) ;
2696 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2698 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2702 if ( iter
->IsTopLevel() )
2703 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2705 iter
= iter
->GetParent() ;
2707 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2711 void wxWindowMac::MacCreateScrollBars( long style
)
2713 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2715 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2716 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2718 GetClientSize( &width
, &height
) ;
2720 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2721 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2722 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2723 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2725 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2726 vSize
, wxVERTICAL
);
2728 if ( style
& wxVSCROLL
)
2734 m_vScrollBar
->Show(false) ;
2736 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2737 hSize
, wxHORIZONTAL
);
2738 if ( style
& wxHSCROLL
)
2743 m_hScrollBar
->Show(false) ;
2746 // because the create does not take into account the client area origin
2747 MacRepositionScrollBars() ; // we might have a real position shift
2750 void wxWindowMac::MacRepositionScrollBars()
2752 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2753 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2755 // get real client area
2759 GetSize( &width
, &height
) ;
2761 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2762 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2764 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2765 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2766 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2767 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2773 GetSize( &w
, &h
) ;
2775 MacClientToRootWindow( &x
, &y
) ;
2776 MacClientToRootWindow( &w
, &h
) ;
2778 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2780 int totW
= 10000 , totH
= 10000;
2783 if ( iter
->IsTopLevel() )
2785 iter
->GetSize( &totW
, &totH
) ;
2789 iter
= iter
->GetParent() ;
2817 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2821 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2825 bool wxWindowMac::AcceptsFocus() const
2827 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2830 void wxWindowMac::MacSuperChangedPosition()
2832 // only window-absolute structures have to be moved i.e. controls
2834 wxWindowListNode
*node
= GetChildren().GetFirst();
2837 wxWindowMac
*child
= node
->GetData();
2838 child
->MacSuperChangedPosition() ;
2839 node
= node
->GetNext();
2843 void wxWindowMac::MacTopLevelWindowChangedPosition()
2845 // only screen-absolute structures have to be moved i.e. glcanvas
2847 wxWindowListNode
*node
= GetChildren().GetFirst();
2850 wxWindowMac
*child
= node
->GetData();
2851 child
->MacTopLevelWindowChangedPosition() ;
2852 node
= node
->GetNext();
2856 long wxWindowMac::MacGetLeftBorderSize( ) const
2861 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2864 #if wxMAC_USE_THEME_BORDER
2865 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2869 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2872 #if wxMAC_USE_THEME_BORDER
2873 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2877 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2884 long wxWindowMac::MacGetRightBorderSize( ) const
2886 // they are all symmetric in mac themes
2887 return MacGetLeftBorderSize() ;
2890 long wxWindowMac::MacGetTopBorderSize( ) const
2892 // they are all symmetric in mac themes
2893 return MacGetLeftBorderSize() ;
2896 long wxWindowMac::MacGetBottomBorderSize( ) const
2898 // they are all symmetric in mac themes
2899 return MacGetLeftBorderSize() ;
2902 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2904 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2907 // Find the wxWindowMac at the current mouse position, returning the mouse
2909 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2911 pt
= wxGetMousePosition();
2912 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2916 // Get the current mouse position.
2917 wxPoint
wxGetMousePosition()
2920 wxGetMousePosition(& x
, & y
);
2921 return wxPoint(x
, y
);
2924 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2926 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2928 // copied from wxGTK : CS
2929 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2932 // (a) it's a command event and so is propagated to the parent
2933 // (b) under MSW it can be generated from kbd too
2934 // (c) it uses screen coords (because of (a))
2935 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2937 this->ClientToScreen(event
.GetPosition()));
2938 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2947 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2951 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2955 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2956 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2960 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2962 return eventNotHandledErr
;