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_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
103 // ---------------------------------------------------------------------------
105 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
106 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
108 #if TARGET_API_MAC_OSX
110 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
112 kEventControlVisibilityChanged
= 157
118 static const EventTypeSpec eventList
[] =
120 { kEventClassControl
, kEventControlHit
} ,
121 #if TARGET_API_MAC_OSX
122 { kEventClassControl
, kEventControlDraw
} ,
123 { kEventClassControl
, kEventControlVisibilityChanged
} ,
124 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
125 { kEventClassControl
, kEventControlHiliteChanged
} ,
126 { kEventClassControl
, kEventControlSetFocusPart
} ,
128 { kEventClassService
, kEventServiceGetTypes
},
129 { kEventClassService
, kEventServiceCopy
},
130 { kEventClassService
, kEventServicePaste
},
132 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
133 // { kEventClassControl , kEventControlBoundsChanged } ,
137 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
139 OSStatus result
= eventNotHandledErr
;
141 wxMacCarbonEvent
cEvent( event
) ;
143 ControlRef controlRef
;
144 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
146 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
148 switch( GetEventKind( event
) )
150 #if TARGET_API_MAC_OSX
151 case kEventControlDraw
:
153 RgnHandle updateRgn
= NULL
;
154 RgnHandle allocatedRgn
= NULL
;
155 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
156 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
158 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
162 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
164 allocatedRgn
= NewRgn() ;
165 CopyRgn( updateRgn
, allocatedRgn
) ;
166 OffsetRgn( updateRgn
, thisWindow
->MacGetLeftBorderSize() , thisWindow
->MacGetTopBorderSize() ) ;
171 // in case we would need a coregraphics compliant background erase first
172 // now usable to track redraws
173 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
174 if ( thisWindow
->MacIsUserPane() )
176 static float color
= 0.5 ;
179 HIViewGetBounds( controlRef
, &bounds
);
180 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
181 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
182 CGContextFillRect( cgContext
, bounds
);
193 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
196 DisposeRgn( allocatedRgn
) ;
199 case kEventControlVisibilityChanged
:
200 thisWindow
->MacVisibilityChanged() ;
202 case kEventControlEnabledStateChanged
:
203 thisWindow
->MacEnabledStateChanged() ;
205 case kEventControlHiliteChanged
:
206 thisWindow
->MacHiliteChanged() ;
208 case kEventControlSetFocusPart
:
210 Boolean focusEverything
= false ;
211 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
212 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
215 if ( controlPart
== kControlFocusNoPart
)
218 if ( thisWindow
->GetCaret() )
220 thisWindow
->GetCaret()->OnKillFocus();
222 #endif // wxUSE_CARET
223 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
224 event
.SetEventObject(thisWindow
);
225 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
229 // panel wants to track the window which was the last to have focus in it
230 wxChildFocusEvent
eventFocus(thisWindow
);
231 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
234 if ( thisWindow
->GetCaret() )
236 thisWindow
->GetCaret()->OnSetFocus();
238 #endif // wxUSE_CARET
240 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
241 event
.SetEventObject(thisWindow
);
242 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
244 if ( thisWindow
->MacIsUserPane() )
249 case kEventControlHit
:
251 result
= thisWindow
->MacControlHit( handler
, event
) ;
260 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
262 OSStatus result
= eventNotHandledErr
;
264 wxMacCarbonEvent
cEvent( event
) ;
266 ControlRef controlRef
;
267 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
268 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
269 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
271 switch( GetEventKind( event
) )
273 case kEventServiceGetTypes
:
277 textCtrl
->GetSelection( &from
, &to
) ;
279 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
281 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
282 if ( textCtrl
->IsEditable() )
283 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
285 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
286 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
288 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
292 CFArrayAppendValue (copyTypes
, typestring
) ;
294 CFArrayAppendValue (pasteTypes
, typestring
) ;
295 CFRelease( typestring
) ;
301 case kEventServiceCopy
:
305 textCtrl
->GetSelection( &from
, &to
) ;
306 wxString val
= textCtrl
->GetValue() ;
307 val
= val
.Mid( from
, to
- from
) ;
308 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
309 verify_noerr( ClearScrap( &scrapRef
) ) ;
310 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
314 case kEventServicePaste
:
317 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
318 Size textSize
, pastedSize
;
319 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
321 char *content
= new char[textSize
] ;
322 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
323 content
[textSize
-1] = 0 ;
325 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
327 textCtrl
->WriteText( wxString( content
) ) ;
338 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
340 OSStatus result
= eventNotHandledErr
;
342 switch ( GetEventClass( event
) )
344 case kEventClassControl
:
345 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
347 case kEventClassService
:
348 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
355 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
357 // ---------------------------------------------------------------------------
358 // UserPane events for non OSX builds
359 // ---------------------------------------------------------------------------
361 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
363 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
364 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
365 win
->MacControlUserPaneDrawProc(part
) ;
368 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
370 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
371 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
372 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
375 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
377 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
378 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
379 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
382 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
384 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
385 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
386 win
->MacControlUserPaneIdleProc() ;
389 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
391 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
392 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
393 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
396 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
398 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
399 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
400 win
->MacControlUserPaneActivateProc(activating
) ;
403 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
405 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
406 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
407 return win
->MacControlUserPaneFocusProc(action
) ;
410 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
412 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
413 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
414 win
->MacControlUserPaneBackgroundProc(info
) ;
417 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
419 RgnHandle rgn
= NewRgn() ;
421 wxMacWindowStateSaver
sv( this ) ;
422 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
423 MacDoRedraw( rgn
, 0 ) ;
427 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
429 return kControlNoPart
;
432 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
434 return kControlNoPart
;
437 void wxWindowMac::MacControlUserPaneIdleProc()
441 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
443 return kControlNoPart
;
446 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
450 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
452 return kControlNoPart
;
455 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
459 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
460 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
461 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
462 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
463 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
464 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
465 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
466 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
468 // ===========================================================================
470 // ===========================================================================
472 wxList
wxWinMacControlList(wxKEY_INTEGER
);
474 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
476 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
479 return (wxControl
*)node
->GetData();
482 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
484 // adding NULL ControlRef is (first) surely a result of an error and
485 // (secondly) breaks native event processing
486 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
488 if ( !wxWinMacControlList
.Find((long)inControl
) )
489 wxWinMacControlList
.Append((long)inControl
, control
);
492 void wxRemoveMacControlAssociation(wxWindow
*control
)
494 wxWinMacControlList
.DeleteObject(control
);
498 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
500 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
502 // we have to setup the brush in the current port and return noErr
503 // or return an error code so that the control manager walks further up the
504 // hierarchy to find a correct background
506 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
508 OSStatus status
= paramErr
;
511 case kControlMsgApplyTextColor
:
513 case kControlMsgSetUpBackground
:
515 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
518 const wxBrush
&brush
= wx
->MacGetBackgroundBrush() ;
521 wxDC::MacSetupBackgroundForCurrentPort( brush
) ;
523 RgnHandle clip
= NewRgn() ;
526 wx
->MacWindowToRootWindow( &x
,&y
) ;
527 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
528 OffsetRgn( clip
, x
, y
) ;
534 else if ( wx
->MacIsUserPane() )
536 // if we don't have a valid brush for such a control, we have to call the
537 // setup of our parent ourselves
538 status
= SetUpControlBackground( (ControlRef
) wx
->GetParent()->GetHandle() , iDepth
, iIsColor
) ;
550 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
551 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
555 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
558 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
563 // ----------------------------------------------------------------------------
564 // constructors and such
565 // ----------------------------------------------------------------------------
567 wxWindowMac::wxWindowMac()
572 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
577 const wxString
& name
)
580 Create(parent
, id
, pos
, size
, style
, name
);
583 void wxWindowMac::Init()
587 #if WXWIN_COMPATIBILITY_2_4
588 m_backgroundTransparent
= FALSE
;
591 // as all windows are created with WS_VISIBLE style...
594 m_hScrollBar
= NULL
;
595 m_vScrollBar
= NULL
;
596 m_macBackgroundBrush
= wxNullBrush
;
598 m_macIsUserPane
= TRUE
;
600 // make sure all proc ptrs are available
602 if ( gControlUserPaneDrawUPP
== NULL
)
604 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
605 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
606 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
607 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
608 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
609 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
610 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
611 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
613 if ( wxMacLiveScrollbarActionUPP
== NULL
)
615 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
618 if ( wxMacSetupControlBackgroundUPP
== NULL
)
620 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
623 // we need a valid font for the encodings
624 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
628 wxWindowMac::~wxWindowMac()
632 m_isBeingDeleted
= TRUE
;
634 #ifndef __WXUNIVERSAL__
635 // VS: make sure there's no wxFrame with last focus set to us:
636 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
638 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
641 if ( frame
->GetLastFocus() == this )
643 frame
->SetLastFocus((wxWindow
*)NULL
);
648 #endif // __WXUNIVERSAL__
650 // wxRemoveMacControlAssociation( this ) ;
651 // If we delete an item, we should initialize the parent panel,
652 // because it could now be invalid.
653 wxWindow
*parent
= GetParent() ;
656 if (parent
->GetDefaultItem() == (wxButton
*) this)
657 parent
->SetDefaultItem(NULL
);
659 if ( m_peer
&& m_peer
->Ok() )
661 // in case the callback might be called during destruction
662 wxRemoveMacControlAssociation( this) ;
663 // we currently are not using this hook
664 // ::SetControlColorProc( *m_peer , NULL ) ;
668 if ( g_MacLastWindow
== this )
670 g_MacLastWindow
= NULL
;
673 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
676 if ( frame
->GetLastFocus() == this )
677 frame
->SetLastFocus( NULL
) ;
682 // delete our drop target if we've got one
683 #if wxUSE_DRAG_AND_DROP
684 if ( m_dropTarget
!= NULL
)
689 #endif // wxUSE_DRAG_AND_DROP
693 WXWidget
wxWindowMac::GetHandle() const
695 return (WXWidget
) m_peer
->GetControlRef() ;
699 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
701 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
702 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
703 GetEventTypeCount(eventList
), eventList
, this,
704 (EventHandlerRef
*)&m_macControlEventHandler
);
709 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
713 const wxString
& name
)
715 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
717 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
720 parent
->AddChild(this);
722 m_windowVariant
= parent
->GetWindowVariant() ;
724 if ( m_macIsUserPane
)
726 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
729 | kControlSupportsEmbedding
730 // | kControlSupportsLiveFeedback
731 // | kControlHasSpecialBackground
732 // | kControlSupportsCalcBestRect
733 // | kControlHandlesTracking
734 | kControlSupportsFocus
735 // | kControlWantsActivate
736 // | kControlWantsIdle
739 m_peer
= new wxMacControl() ;
740 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
743 MacPostControlCreate(pos
,size
) ;
744 #if !TARGET_API_MAC_OSX
745 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
746 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
747 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
748 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
749 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
750 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
751 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
752 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
755 #ifndef __WXUNIVERSAL__
756 // Don't give scrollbars to wxControls unless they ask for them
757 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
758 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
760 MacCreateScrollBars( style
) ;
764 wxWindowCreateEvent
event(this);
765 GetEventHandler()->AddPendingEvent(event
);
770 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
772 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
774 m_peer
->SetReference( (long) this ) ;
776 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
778 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
779 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
780 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
782 // adjust font, controlsize etc
783 DoSetWindowVariant( m_windowVariant
) ;
785 #if !TARGET_API_MAC_OSX
786 // eventually we can fix some clipping issues be reactivating this hook
787 //if ( m_macIsUserPane )
788 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
790 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
792 if (!m_macIsUserPane
)
794 SetInitialBestSize(size
);
797 SetCursor( *wxSTANDARD_CURSOR
) ;
800 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
802 // Don't assert, in case we set the window variant before
803 // the window is created
804 // wxASSERT( m_peer->Ok() ) ;
806 m_windowVariant
= variant
;
808 if (m_peer
== NULL
|| !m_peer
->Ok())
812 ThemeFontID themeFont
= kThemeSystemFont
;
814 // we will get that from the settings later
815 // and make this NORMAL later, but first
816 // we have a few calculations that we must fix
820 case wxWINDOW_VARIANT_NORMAL
:
821 size
= kControlSizeNormal
;
822 themeFont
= kThemeSystemFont
;
824 case wxWINDOW_VARIANT_SMALL
:
825 size
= kControlSizeSmall
;
826 themeFont
= kThemeSmallSystemFont
;
828 case wxWINDOW_VARIANT_MINI
:
829 if (UMAGetSystemVersion() >= 0x1030 )
831 // not always defined in the headers
837 size
= kControlSizeSmall
;
838 themeFont
= kThemeSmallSystemFont
;
841 case wxWINDOW_VARIANT_LARGE
:
842 size
= kControlSizeLarge
;
843 themeFont
= kThemeSystemFont
;
846 wxFAIL_MSG(_T("unexpected window variant"));
849 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
852 font
.MacCreateThemeFont( themeFont
) ;
856 void wxWindowMac::MacUpdateControlFont()
858 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
862 bool wxWindowMac::SetFont(const wxFont
& font
)
864 bool retval
= !wxWindowBase::SetFont( font
) ;
866 MacUpdateControlFont() ;
871 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
873 if ( !wxWindowBase::SetForegroundColour(col
) )
876 MacUpdateControlFont() ;
881 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
883 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
887 wxColour
newCol(GetBackgroundColour());
888 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
890 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
892 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
894 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
898 brush
.SetColour( newCol
) ;
900 MacSetBackgroundBrush( brush
) ;
905 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
907 m_macBackgroundBrush
= brush
;
908 m_peer
->SetBackground( brush
) ;
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 m_peer
->GetFeatures( & 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
= m_peer
->SetFocus( 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 // Returns the size of the native control. In the case of the toplevel window
1008 // this is the content area root control
1010 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1011 int& w
, int& h
) const
1014 m_peer
->GetRect( &bounds
) ;
1019 w
= bounds
.right
- bounds
.left
;
1020 h
= bounds
.bottom
- bounds
.top
;
1022 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1025 Point tlworigin
= { 0 , 0 } ;
1026 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1032 // From a wx position / size calculate the appropriate size of the native control
1034 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1037 int& w
, int& h
, bool adjustOrigin
) const
1039 // the desired size, minus the border pixels gives the correct size of the control
1043 // todo the default calls may be used as soon as PostCreateControl Is moved here
1044 w
= size
.x
; // WidthDefault( size.x );
1045 h
= size
.y
; // HeightDefault( size.y ) ;
1046 #if !TARGET_API_MAC_OSX
1047 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1050 x
+= MacGetLeftBorderSize() ;
1051 y
+= MacGetTopBorderSize() ;
1052 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1053 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1056 AdjustForParentClientOrigin( x
, y
) ;
1061 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1063 // take the size of the control and add the borders that have to be drawn outside
1064 int x1
, y1
, w1
,h1
;
1065 #if TARGET_API_MAC_OSX
1066 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1070 m_peer
->GetRect( &bounds
) ;
1071 w1
= bounds
.right
- bounds
.left
;
1072 h1
= bounds
.bottom
- bounds
.top
;
1074 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1075 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1081 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1083 #if TARGET_API_MAC_OSX
1084 int x1
, y1
, w1
,h1
;
1085 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1086 x1
-= MacGetLeftBorderSize() ;
1087 y1
-= MacGetTopBorderSize() ;
1088 if ( !IsTopLevel() )
1090 wxWindow
*parent
= GetParent();
1093 wxPoint
pt(parent
->GetClientAreaOrigin());
1102 m_peer
->GetRect( &bounds
) ;
1103 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1105 int xx
= bounds
.left
;
1106 int yy
= bounds
.top
;
1107 xx
-= MacGetLeftBorderSize() ;
1108 yy
-= MacGetTopBorderSize() ;
1110 if ( !GetParent()->IsTopLevel() )
1112 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1118 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1127 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1129 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1131 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1134 Point localwhere
= {0,0} ;
1136 if(x
) localwhere
.h
= * x
;
1137 if(y
) localwhere
.v
= * y
;
1139 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1140 if(x
) *x
= localwhere
.h
;
1141 if(y
) *y
= localwhere
.v
;
1144 MacRootWindowToWindow( x
, y
) ;
1146 wxPoint origin
= GetClientAreaOrigin() ;
1147 if(x
) *x
-= origin
.x
;
1148 if(y
) *y
-= origin
.y
;
1151 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1153 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1154 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1156 wxPoint origin
= GetClientAreaOrigin() ;
1157 if(x
) *x
+= origin
.x
;
1158 if(y
) *y
+= origin
.y
;
1160 MacWindowToRootWindow( x
, y
) ;
1163 Point localwhere
= { 0,0 };
1164 if(x
) localwhere
.h
= * x
;
1165 if(y
) localwhere
.v
= * y
;
1166 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1167 if(x
) *x
= localwhere
.h
;
1168 if(y
) *y
= localwhere
.v
;
1172 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1174 wxPoint origin
= GetClientAreaOrigin() ;
1175 if(x
) *x
+= origin
.x
;
1176 if(y
) *y
+= origin
.y
;
1178 MacWindowToRootWindow( x
, y
) ;
1181 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1183 MacRootWindowToWindow( x
, y
) ;
1185 wxPoint origin
= GetClientAreaOrigin() ;
1186 if(x
) *x
-= origin
.x
;
1187 if(y
) *y
-= origin
.y
;
1190 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1192 #if TARGET_API_MAC_OSX
1194 if ( x
) pt
.x
= *x
;
1195 if ( y
) pt
.y
= *y
;
1197 if ( !IsTopLevel() )
1199 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1202 pt
.x
-= MacGetLeftBorderSize() ;
1203 pt
.y
-= MacGetTopBorderSize() ;
1204 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1208 if ( x
) *x
= (int) pt
.x
;
1209 if ( y
) *y
= (int) pt
.y
;
1211 if ( !IsTopLevel() )
1214 m_peer
->GetRect( &bounds
) ;
1215 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1216 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1221 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1226 MacWindowToRootWindow( &x1
, &y1
) ;
1231 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1233 #if TARGET_API_MAC_OSX
1235 if ( x
) pt
.x
= *x
;
1236 if ( y
) pt
.y
= *y
;
1238 if ( !IsTopLevel() )
1240 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1241 pt
.x
+= MacGetLeftBorderSize() ;
1242 pt
.y
+= MacGetTopBorderSize() ;
1245 if ( x
) *x
= (int) pt
.x
;
1246 if ( y
) *y
= (int) pt
.y
;
1248 if ( !IsTopLevel() )
1251 m_peer
->GetRect( &bounds
) ;
1252 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1253 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1258 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1263 MacRootWindowToWindow( &x1
, &y1
) ;
1268 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1270 RgnHandle rgn
= NewRgn() ;
1272 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1274 GetRegionBounds( rgn
, &content
) ;
1279 m_peer
->GetRect( &content
) ;
1282 m_peer
->GetRect( &structure
) ;
1283 #if !TARGET_API_MAC_OSX
1284 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1286 left
= content
.left
- structure
.left
;
1287 top
= content
.top
- structure
.top
;
1288 right
= structure
.right
- content
.right
;
1289 bottom
= structure
.bottom
- content
.bottom
;
1292 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1294 wxSize sizeTotal
= size
;
1296 RgnHandle rgn
= NewRgn() ;
1300 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1302 GetRegionBounds( rgn
, &content
) ;
1307 m_peer
->GetRect( &content
) ;
1310 m_peer
->GetRect( &structure
) ;
1311 #if !TARGET_API_MAC_OSX
1312 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1315 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1316 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1318 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1319 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1325 // Get size *available for subwindows* i.e. excluding menu bar etc.
1326 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1330 RgnHandle rgn
= NewRgn() ;
1332 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1334 GetRegionBounds( rgn
, &content
) ;
1339 m_peer
->GetRect( &content
) ;
1341 #if !TARGET_API_MAC_OSX
1343 m_peer
->GetRect( &structure
) ;
1344 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1346 ww
= content
.right
- content
.left
;
1347 hh
= content
.bottom
- content
.top
;
1349 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1350 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1352 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1358 GetSize( &w
, &h
) ;
1360 MacClientToRootWindow( &x1
, &y1
) ;
1361 MacClientToRootWindow( &w
, &h
) ;
1363 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1365 int totW
= 10000 , totH
= 10000;
1368 if ( iter
->IsTopLevel() )
1370 iter
->GetSize( &totW
, &totH
) ;
1374 iter
= iter
->GetParent() ;
1377 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1379 hh
-= MAC_SCROLLBAR_SIZE
;
1385 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1387 ww
-= MAC_SCROLLBAR_SIZE
;
1399 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1401 if (m_cursor
== cursor
)
1404 if (wxNullCursor
== cursor
)
1406 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1411 if ( ! wxWindowBase::SetCursor( cursor
) )
1415 wxASSERT_MSG( m_cursor
.Ok(),
1416 wxT("cursor must be valid after call to the base version"));
1419 wxWindowMac
*mouseWin
= 0 ;
1421 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1423 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1425 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1426 // position, use it...
1430 ControlPartCode part
;
1431 ControlRef control
;
1432 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1434 mouseWin
= wxFindControlFromMacControl( control
) ;
1437 QDSwapPort( savePort
, NULL
) ;
1440 if ( mouseWin
== this && !wxIsBusy() )
1442 m_cursor
.MacInstall() ;
1449 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1451 menu
->SetInvokingWindow(this);
1454 if ( x
== -1 && y
== -1 )
1456 wxPoint mouse
= wxGetMousePosition();
1457 x
= mouse
.x
; y
= mouse
.y
;
1461 ClientToScreen( &x
, &y
) ;
1464 menu
->MacBeforeDisplay( true ) ;
1465 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1466 if ( HiWord(menuResult
) != 0 )
1469 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1470 wxMenuItem
* item
= NULL
;
1472 item
= menu
->FindItem(id
, &realmenu
) ;
1473 if (item
->IsCheckable())
1475 item
->Check( !item
->IsChecked() ) ;
1477 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1479 menu
->MacAfterDisplay( true ) ;
1481 menu
->SetInvokingWindow(NULL
);
1487 // ----------------------------------------------------------------------------
1489 // ----------------------------------------------------------------------------
1493 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1495 wxWindowBase::DoSetToolTip(tooltip
);
1498 m_tooltip
->SetWindow(this);
1501 #endif // wxUSE_TOOLTIPS
1503 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1505 int former_x
, former_y
, former_w
, former_h
;
1506 #if !TARGET_API_MAC_OSX
1507 DoGetPosition( &former_x
, &former_y
) ;
1508 DoGetSize( &former_w
, &former_h
) ;
1510 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1511 former_x
-= MacGetLeftBorderSize() ;
1512 former_y
-= MacGetTopBorderSize() ;
1513 former_w
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1514 former_h
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1517 int actualWidth
= width
;
1518 int actualHeight
= height
;
1522 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1523 actualWidth
= m_minWidth
;
1524 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1525 actualHeight
= m_minHeight
;
1526 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1527 actualWidth
= m_maxWidth
;
1528 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1529 actualHeight
= m_maxHeight
;
1531 bool doMove
= false ;
1532 bool doResize
= false ;
1534 if ( actualX
!= former_x
|| actualY
!= former_y
)
1538 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1543 if ( doMove
|| doResize
)
1545 // we don't adjust twice for the origin
1546 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1547 bool vis
= m_peer
->IsVisible();
1549 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1551 m_peer
->SetVisibility( false , true ) ;
1552 m_peer
->SetRect( &r
) ;
1554 m_peer
->SetVisibility( true , true ) ;
1556 MacRepositionScrollBars() ;
1559 wxPoint
point(actualX
,actualY
);
1560 wxMoveEvent
event(point
, m_windowId
);
1561 event
.SetEventObject(this);
1562 GetEventHandler()->ProcessEvent(event
) ;
1566 MacRepositionScrollBars() ;
1567 wxSize
size(actualWidth
, actualHeight
);
1568 wxSizeEvent
event(size
, m_windowId
);
1569 event
.SetEventObject(this);
1570 GetEventHandler()->ProcessEvent(event
);
1576 wxSize
wxWindowMac::DoGetBestSize() const
1578 if ( m_macIsUserPane
|| IsTopLevel() )
1579 return wxWindowBase::DoGetBestSize() ;
1581 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1582 int bestWidth
, bestHeight
;
1583 m_peer
->GetBestRect( &bestsize
) ;
1585 if ( EmptyRect( &bestsize
) )
1587 bestsize
.left
= bestsize
.top
= 0 ;
1588 bestsize
.right
= 16 ;
1589 bestsize
.bottom
= 16 ;
1590 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1592 bestsize
.bottom
= 16 ;
1594 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1596 bestsize
.bottom
= 24 ;
1600 // return wxWindowBase::DoGetBestSize() ;
1604 bestWidth
= bestsize
.right
- bestsize
.left
;
1605 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1606 if ( bestHeight
< 10 )
1609 return wxSize(bestWidth
, bestHeight
);
1613 // set the size of the window: if the dimensions are positive, just use them,
1614 // but if any of them is equal to -1, it means that we must find the value for
1615 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1616 // which case -1 is a valid value for x and y)
1618 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1619 // the width/height to best suit our contents, otherwise we reuse the current
1621 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1623 // get the current size and position...
1624 int currentX
, currentY
;
1625 GetPosition(¤tX
, ¤tY
);
1627 int currentW
,currentH
;
1628 GetSize(¤tW
, ¤tH
);
1630 // ... and don't do anything (avoiding flicker) if it's already ok
1631 if ( x
== currentX
&& y
== currentY
&&
1632 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1635 MacRepositionScrollBars() ; // we might have a real position shift
1639 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1641 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1644 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1646 wxSize
size(-1, -1);
1649 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1651 size
= DoGetBestSize();
1656 // just take the current one
1663 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1667 size
= DoGetBestSize();
1669 //else: already called DoGetBestSize() above
1675 // just take the current one
1680 DoMoveWindow(x
, y
, width
, height
);
1684 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1686 RgnHandle rgn
= NewRgn() ;
1688 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1689 GetRegionBounds( rgn
, &content
) ;
1691 #if !TARGET_API_MAC_OSX
1692 // if the content rgn is empty / not supported
1693 // don't attempt to correct the coordinates to wxWindow relative ones
1694 if (!::EmptyRect( &content
) )
1697 m_peer
->GetRect( &structure
) ;
1698 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1702 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1705 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1707 if ( clientheight
!= -1 || clientheight
!= -1 )
1709 int currentclientwidth
, currentclientheight
;
1710 int currentwidth
, currentheight
;
1712 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1713 GetSize( ¤twidth
, ¤theight
) ;
1715 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1716 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1720 void wxWindowMac::SetTitle(const wxString
& title
)
1722 m_label
= wxStripMenuCodes(title
) ;
1724 if ( m_peer
&& m_peer
->Ok() )
1726 m_peer
->SetTitle( m_label
) ;
1731 wxString
wxWindowMac::GetTitle() const
1736 bool wxWindowMac::Show(bool show
)
1738 if ( !wxWindowBase::Show(show
) )
1741 // TODO use visibilityChanged Carbon Event for OSX
1742 bool former
= MacIsReallyShown() ;
1744 m_peer
->SetVisibility( show
, true ) ;
1745 if ( former
!= MacIsReallyShown() )
1746 MacPropagateVisibilityChanged() ;
1750 bool wxWindowMac::Enable(bool enable
)
1752 wxASSERT( m_peer
->Ok() ) ;
1753 if ( !wxWindowBase::Enable(enable
) )
1756 bool former
= MacIsReallyEnabled() ;
1757 m_peer
->Enable( enable
) ;
1759 if ( former
!= MacIsReallyEnabled() )
1760 MacPropagateEnabledStateChanged() ;
1765 // status change propagations (will be not necessary for OSX later )
1768 void wxWindowMac::MacPropagateVisibilityChanged()
1770 #if !TARGET_API_MAC_OSX
1771 MacVisibilityChanged() ;
1773 wxWindowListNode
*node
= GetChildren().GetFirst();
1776 wxWindowMac
*child
= node
->GetData();
1777 if ( child
->IsShown() )
1778 child
->MacPropagateVisibilityChanged( ) ;
1779 node
= node
->GetNext();
1784 void wxWindowMac::MacPropagateEnabledStateChanged( )
1786 #if !TARGET_API_MAC_OSX
1787 MacEnabledStateChanged() ;
1789 wxWindowListNode
*node
= GetChildren().GetFirst();
1792 wxWindowMac
*child
= node
->GetData();
1793 if ( child
->IsEnabled() )
1794 child
->MacPropagateEnabledStateChanged() ;
1795 node
= node
->GetNext();
1800 void wxWindowMac::MacPropagateHiliteChanged( )
1802 #if !TARGET_API_MAC_OSX
1803 MacHiliteChanged() ;
1805 wxWindowListNode
*node
= GetChildren().GetFirst();
1808 wxWindowMac
*child
= node
->GetData();
1809 // if ( child->IsEnabled() )
1810 child
->MacPropagateHiliteChanged() ;
1811 node
= node
->GetNext();
1817 // status change notifications
1820 void wxWindowMac::MacVisibilityChanged()
1824 void wxWindowMac::MacHiliteChanged()
1828 void wxWindowMac::MacEnabledStateChanged()
1833 // status queries on the inherited window's state
1836 bool wxWindowMac::MacIsReallyShown()
1838 // only under OSX the visibility of the TLW is taken into account
1839 #if TARGET_API_MAC_OSX
1840 if ( m_peer
&& m_peer
->Ok() )
1841 return m_peer
->IsVisible();
1843 wxWindow
* win
= this ;
1844 while( win
->IsShown() )
1846 if ( win
->IsTopLevel() )
1849 win
= win
->GetParent() ;
1857 bool wxWindowMac::MacIsReallyEnabled()
1859 return m_peer
->IsEnabled() ;
1862 bool wxWindowMac::MacIsReallyHilited()
1864 return m_peer
->IsActive();
1867 void wxWindowMac::MacFlashInvalidAreas()
1869 #if TARGET_API_MAC_OSX
1870 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1878 int wxWindowMac::GetCharHeight() const
1880 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1881 return dc
.GetCharHeight() ;
1884 int wxWindowMac::GetCharWidth() const
1886 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1887 return dc
.GetCharWidth() ;
1890 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1891 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1893 const wxFont
*fontToUse
= theFont
;
1895 fontToUse
= &m_font
;
1897 wxClientDC
dc( (wxWindowMac
*) this ) ;
1899 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1900 if ( externalLeading
)
1901 *externalLeading
= le
;
1911 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1912 * we always intersect with the entire window, not only with the client area
1915 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1917 if ( m_peer
== NULL
)
1920 #if TARGET_API_MAC_OSX
1922 m_peer
->SetNeedsDisplay( true ) ;
1925 RgnHandle update
= NewRgn() ;
1926 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1927 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1928 wxPoint origin
= GetClientAreaOrigin() ;
1929 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1930 m_peer
->SetNeedsDisplay( true , update
) ;
1934 RgnHandle updateRgn = NewRgn() ;
1937 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1941 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1942 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1944 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1945 DisposeRgn(updateRgn) ;
1947 if ( m_peer
->IsVisible())
1949 m_peer
->SetVisibility( false , false ) ;
1950 m_peer
->SetVisibility( true , true ) ;
1953 if ( MacGetTopLevelWindow() == NULL )
1956 if ( !m_peer->IsVisible())
1959 wxPoint client = GetClientAreaOrigin();
1962 int x2 = m_width - client.x;
1963 int y2 = m_height - client.y;
1965 if (IsKindOf( CLASSINFO(wxButton)))
1967 // buttons have an "aura"
1974 Rect clientrect = { y1, x1, y2, x2 };
1978 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1979 SectRect( &clientrect , &r , &clientrect ) ;
1982 if ( !EmptyRect( &clientrect ) )
1984 int top = 0 , left = 0 ;
1986 MacClientToRootWindow( &left , &top ) ;
1987 OffsetRect( &clientrect , left , top ) ;
1989 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1995 void wxWindowMac::Freeze()
1997 #if TARGET_API_MAC_OSX
1998 if ( !m_frozenness
++ )
2000 m_peer
->SetDrawingEnabled( false ) ;
2006 void wxWindowMac::Thaw()
2008 #if TARGET_API_MAC_OSX
2009 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2011 if ( !--m_frozenness
)
2013 m_peer
->SetDrawingEnabled( true ) ;
2014 m_peer
->InvalidateWithChildren() ;
2019 void wxWindowMac::MacRedrawControl()
2022 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2024 #if TARGET_API_MAC_CARBON
2027 wxClientDC dc(this) ;
2028 wxMacPortSetter helper(&dc) ;
2029 wxMacWindowClipper clipper(this) ;
2030 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2031 UMADrawControl( *m_peer ) ;
2038 void wxWindowMac::OnPaint(wxPaintEvent& event)
2040 // why don't we skip that here ?
2044 wxWindowMac
*wxGetActiveWindow()
2046 // actually this is a windows-only concept
2050 // Coordinates relative to the window
2051 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2053 // We really don't move the mouse programmatically under Mac.
2056 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2058 #if TARGET_API_MAC_OSX
2059 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2065 event
.GetDC()->Clear() ;
2068 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2070 wxWindowDC
dc(this) ;
2071 wxMacPortSetter
helper(&dc
) ;
2073 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2076 int wxWindowMac::GetScrollPos(int orient
) const
2078 if ( orient
== wxHORIZONTAL
)
2081 return m_hScrollBar
->GetThumbPosition() ;
2086 return m_vScrollBar
->GetThumbPosition() ;
2091 // This now returns the whole range, not just the number
2092 // of positions that we can scroll.
2093 int wxWindowMac::GetScrollRange(int orient
) const
2095 if ( orient
== wxHORIZONTAL
)
2098 return m_hScrollBar
->GetRange() ;
2103 return m_vScrollBar
->GetRange() ;
2108 int wxWindowMac::GetScrollThumb(int orient
) const
2110 if ( orient
== wxHORIZONTAL
)
2113 return m_hScrollBar
->GetThumbSize() ;
2118 return m_vScrollBar
->GetThumbSize() ;
2123 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2125 if ( orient
== wxHORIZONTAL
)
2128 m_hScrollBar
->SetThumbPosition( pos
) ;
2133 m_vScrollBar
->SetThumbPosition( pos
) ;
2137 void wxWindowMac::MacPaintBorders( int left
, int top
)
2143 wxGetOsVersion( &major
, &minor
);
2145 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2146 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2147 // OS X has lighter border edges than classic:
2150 darkShadow
.red
= 0x8E8E;
2151 darkShadow
.green
= 0x8E8E;
2152 darkShadow
.blue
= 0x8E8E;
2153 lightShadow
.red
= 0xBDBD;
2154 lightShadow
.green
= 0xBDBD;
2155 lightShadow
.blue
= 0xBDBD;
2161 GetSize( &w
, &h
) ;
2162 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2163 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2165 #if wxMAC_USE_THEME_BORDER
2167 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2168 InsetRect( &rect
, border
, border
);
2169 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2171 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2172 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2174 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2175 RGBForeColor( &face
);
2176 MoveTo( left
+ 0 , top
+ h
- 2 );
2177 LineTo( left
+ 0 , top
+ 0 );
2178 LineTo( left
+ w
- 2 , top
+ 0 );
2180 MoveTo( left
+ 2 , top
+ h
- 3 );
2181 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2182 LineTo( left
+ w
- 3 , top
+ 2 );
2184 RGBForeColor( sunken
? &face
: &darkShadow
);
2185 MoveTo( left
+ 0 , top
+ h
- 1 );
2186 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2187 LineTo( left
+ w
- 1 , top
+ 0 );
2189 RGBForeColor( sunken
? &lightShadow
: &white
);
2190 MoveTo( left
+ 1 , top
+ h
- 3 );
2191 LineTo( left
+ 1, top
+ 1 );
2192 LineTo( left
+ w
- 3 , top
+ 1 );
2194 RGBForeColor( sunken
? &white
: &lightShadow
);
2195 MoveTo( left
+ 1 , top
+ h
- 2 );
2196 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2197 LineTo( left
+ w
- 2 , top
+ 1 );
2199 RGBForeColor( sunken
? &darkShadow
: &face
);
2200 MoveTo( left
+ 2 , top
+ h
- 4 );
2201 LineTo( left
+ 2 , top
+ 2 );
2202 LineTo( left
+ w
- 4 , top
+ 2 );
2205 else if (HasFlag(wxSIMPLE_BORDER
))
2207 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2208 RGBForeColor( &darkShadow
) ;
2209 FrameRect( &rect
) ;
2213 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2215 if ( child
== m_hScrollBar
)
2216 m_hScrollBar
= NULL
;
2217 if ( child
== m_vScrollBar
)
2218 m_vScrollBar
= NULL
;
2220 wxWindowBase::RemoveChild( child
) ;
2223 // New function that will replace some of the above.
2224 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2225 int range
, bool refresh
)
2227 if ( orient
== wxHORIZONTAL
)
2231 if ( range
== 0 || thumbVisible
>= range
)
2233 if ( m_hScrollBar
->IsShown() )
2234 m_hScrollBar
->Show(false) ;
2238 if ( !m_hScrollBar
->IsShown() )
2239 m_hScrollBar
->Show(true) ;
2240 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2248 if ( range
== 0 || thumbVisible
>= range
)
2250 if ( m_vScrollBar
->IsShown() )
2251 m_vScrollBar
->Show(false) ;
2255 if ( !m_vScrollBar
->IsShown() )
2256 m_vScrollBar
->Show(true) ;
2257 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2261 MacRepositionScrollBars() ;
2264 // Does a physical scroll
2265 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2267 if( dx
== 0 && dy
==0 )
2273 int width
, height
;
2274 GetClientSize( &width
, &height
) ;
2275 #if TARGET_API_MAC_OSX
2276 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2277 // area is scrolled, this does not occur if width and height are 2 pixels less,
2278 // TODO write optimal workaround
2279 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width
, MacGetTopBorderSize() + height
) ;
2282 scrollrect
.Intersect( *rect
) ;
2284 if ( m_peer
->GetNeedsDisplay() )
2286 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2287 // either immediate redraw or full invalidate
2289 // is the better overall solution, as it does not slow down scrolling
2290 m_peer
->SetNeedsDisplay( true ) ;
2292 // this would be the preferred version for fast drawing controls
2293 if( UMAGetSystemVersion() < 0x1030 )
2296 HIViewRender(*m_peer
) ;
2299 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2306 RgnHandle updateRgn
= NewRgn() ;
2309 wxClientDC
dc(this) ;
2310 wxMacPortSetter
helper(&dc
) ;
2312 m_peer
->GetRect( &scrollrect
) ;
2313 scrollrect
.top
+= MacGetTopBorderSize() ;
2314 scrollrect
.left
+= MacGetLeftBorderSize() ;
2315 scrollrect
.bottom
= scrollrect
.top
+ height
;
2316 scrollrect
.right
= scrollrect
.left
+ width
;
2320 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2321 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2322 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2324 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2326 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2330 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2332 wxWindowMac
*child
= node
->GetData();
2333 if (child
== m_vScrollBar
) continue;
2334 if (child
== m_hScrollBar
) continue;
2335 if (child
->IsTopLevel()) continue;
2338 child
->GetPosition( &x
, &y
);
2340 child
->GetSize( &w
, &h
);
2344 if (rect
->Intersects(rc
))
2345 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2349 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2354 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2356 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2358 wxScrollWinEvent wevent
;
2359 wevent
.SetPosition(event
.GetPosition());
2360 wevent
.SetOrientation(event
.GetOrientation());
2361 wevent
.m_eventObject
= this;
2363 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2364 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2365 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2366 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2367 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2368 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2369 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2370 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2371 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2372 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2373 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2374 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2375 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2377 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2378 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2380 GetEventHandler()->ProcessEvent(wevent
);
2384 // Get the window with the focus
2385 wxWindowMac
*wxWindowBase::FindFocus()
2387 ControlRef control
;
2388 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2389 return wxFindControlFromMacControl( control
) ;
2392 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2394 // panel wants to track the window which was the last to have focus in it,
2395 // so we want to set ourselves as the window which last had focus
2397 // notice that it's also important to do it upwards the tree becaus
2398 // otherwise when the top level panel gets focus, it won't set it back to
2399 // us, but to some other sibling
2401 // CS:don't know if this is still needed:
2402 //wxChildFocusEvent eventFocus(this);
2403 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2405 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2407 wxMacWindowStateSaver
sv( this ) ;
2412 MacWindowToRootWindow( &x
, &y
) ;
2413 GetSize( &w
, &h
) ;
2414 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2416 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2417 DrawThemeFocusRect( &rect
, true ) ;
2419 DrawThemeFocusRect( &rect
, false ) ;
2425 void wxWindowMac::OnInternalIdle()
2427 // This calls the UI-update mechanism (querying windows for
2428 // menu/toolbar/control state information)
2429 if (wxUpdateUIEvent::CanUpdate(this))
2430 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2433 // Raise the window to the top of the Z order
2434 void wxWindowMac::Raise()
2436 m_peer
->SetZOrder( true , NULL
) ;
2439 // Lower the window to the bottom of the Z order
2440 void wxWindowMac::Lower()
2442 m_peer
->SetZOrder( false , NULL
) ;
2446 // static wxWindow *gs_lastWhich = NULL;
2448 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2450 // first trigger a set cursor event
2452 wxPoint clientorigin
= GetClientAreaOrigin() ;
2453 wxSize clientsize
= GetClientSize() ;
2455 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2457 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2459 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2460 if ( processedEvtSetCursor
&& event
.HasCursor() )
2462 cursor
= event
.GetCursor() ;
2467 // the test for processedEvtSetCursor is here to prevent using m_cursor
2468 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2469 // it - this is a way to say that our cursor shouldn't be used for this
2471 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2481 cursor
= *wxSTANDARD_CURSOR
;
2485 cursor
.MacInstall() ;
2487 return cursor
.Ok() ;
2490 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2494 return m_tooltip
->GetTip() ;
2496 return wxEmptyString
;
2499 void wxWindowMac::Update()
2501 #if TARGET_API_MAC_OSX
2502 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2503 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2504 // for composited windows this also triggers a redraw of all
2505 // invalid views in the window
2506 if( UMAGetSystemVersion() >= 0x1030 )
2507 HIWindowFlush(window
) ;
2511 // the only way to trigger the redrawing on earlier systems is to call
2514 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2515 UInt32 currentEventClass
= 0 ;
2516 UInt32 currentEventKind
= 0 ;
2517 if ( currentEvent
!= NULL
)
2519 currentEventClass
= ::GetEventClass( currentEvent
) ;
2520 currentEventKind
= ::GetEventKind( currentEvent
) ;
2522 if ( currentEventClass
!= kEventClassMenu
)
2524 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2527 OSStatus status
= noErr
;
2528 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2531 m_peer
->SetNeedsDisplay( true ) ;
2534 ::Draw1Control( m_peer
->GetControlRef() ) ;
2538 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2540 wxTopLevelWindowMac
* win
= NULL
;
2541 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2544 win
= wxFindWinFromMacWindow( window
) ;
2548 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2552 RgnHandle visRgn
= NewRgn() ;
2553 RgnHandle tempRgn
= NewRgn() ;
2554 if ( m_peer
->IsVisible())
2556 m_peer
->GetRect( &r
) ;
2557 r
.left
-= MacGetLeftBorderSize() ;
2558 r
.top
-= MacGetTopBorderSize() ;
2559 r
.bottom
+= MacGetBottomBorderSize() ;
2560 r
.right
+= MacGetRightBorderSize() ;
2562 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2564 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2565 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2574 if ( includeOuterStructures
)
2575 InsetRect( &r
, -3 , -3 ) ;
2576 RectRgn( visRgn
, &r
) ;
2577 if ( !IsTopLevel() )
2579 wxWindow
* child
= this ;
2580 wxWindow
* parent
= child
->GetParent() ;
2585 // we have to find a better clipping algorithm here, in order not to clip things
2586 // positioned like status and toolbar
2587 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2589 size
= parent
->GetSize() ;
2594 size
= parent
->GetClientSize() ;
2595 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2599 parent
->MacWindowToRootWindow( &x
, &y
) ;
2600 MacRootWindowToWindow( &x
, &y
) ;
2602 SetRectRgn( tempRgn
,
2603 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2604 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2605 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2607 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2608 if ( parent
->IsTopLevel() )
2611 parent
= child
->GetParent() ;
2616 wxRegion vis
= visRgn
;
2617 DisposeRgn( visRgn
) ;
2618 DisposeRgn( tempRgn
) ;
2623 This function must not change the updatergn !
2625 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2627 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2628 bool handled
= false ;
2630 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2632 RgnHandle newupdate
= NewRgn() ;
2633 wxSize point
= GetClientSize() ;
2634 wxPoint origin
= GetClientAreaOrigin() ;
2635 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2636 SectRgn( newupdate
, updatergn
, newupdate
) ;
2637 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2638 m_updateRegion
= newupdate
;
2639 DisposeRgn( newupdate
) ;
2642 if ( !EmptyRgn(updatergn
) )
2644 wxWindowDC
dc(this);
2645 if (!EmptyRgn(updatergn
))
2646 dc
.SetClippingRegion(wxRegion(updatergn
));
2648 wxEraseEvent
eevent( GetId(), &dc
);
2649 eevent
.SetEventObject( this );
2650 GetEventHandler()->ProcessEvent( eevent
);
2652 if ( !m_updateRegion
.Empty() )
2654 // paint the window itself
2656 event
.m_timeStamp
= time
;
2657 event
.SetEventObject(this);
2658 handled
= GetEventHandler()->ProcessEvent(event
);
2660 // paint custom borders
2661 wxNcPaintEvent
eventNc( GetId() );
2662 eventNc
.SetEventObject( this );
2663 GetEventHandler()->ProcessEvent( eventNc
);
2669 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2671 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2672 // updatergn is always already clipped to our boundaries
2673 // if we are in compositing mode then it is in relative to the upper left of the control
2674 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2675 // of the toplevel window
2676 // it is in window coordinates, not in client coordinates
2678 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2679 RgnHandle ownUpdateRgn
= NewRgn() ;
2680 CopyRgn( updatergn
, ownUpdateRgn
) ;
2682 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2685 m_peer
->GetRectInWindowCoords( &bounds
);
2686 RgnHandle controlRgn
= NewRgn();
2687 RectRgn( controlRgn
, &bounds
);
2688 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2689 // the window update region
2690 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2691 DisposeRgn( controlRgn
);
2693 //KO: convert ownUpdateRgn to local coordinates
2694 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2697 MacDoRedraw( ownUpdateRgn
, time
) ;
2698 DisposeRgn( ownUpdateRgn
) ;
2702 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2704 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2708 if ( iter
->IsTopLevel() )
2709 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2711 iter
= iter
->GetParent() ;
2713 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2717 void wxWindowMac::MacCreateScrollBars( long style
)
2719 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2723 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2724 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2726 GetClientSize( &width
, &height
) ;
2728 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2729 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2730 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2731 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2733 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2734 vSize
, wxVERTICAL
);
2736 if ( style
& wxVSCROLL
)
2742 m_vScrollBar
->Show(false) ;
2744 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2745 hSize
, wxHORIZONTAL
);
2746 if ( style
& wxHSCROLL
)
2751 m_hScrollBar
->Show(false) ;
2754 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2756 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2757 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2759 GetClientSize( &width
, &height
) ;
2761 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2762 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2763 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2764 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2767 if ( style
& wxVSCROLL
)
2769 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2770 vSize
, wxVERTICAL
);
2773 if ( style
& wxHSCROLL
)
2775 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2776 hSize
, wxHORIZONTAL
);
2782 // because the create does not take into account the client area origin
2783 MacRepositionScrollBars() ; // we might have a real position shift
2786 void wxWindowMac::MacRepositionScrollBars()
2788 if ( !m_hScrollBar
&& !m_vScrollBar
)
2791 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2792 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2794 // get real client area
2798 GetSize( &width
, &height
) ;
2800 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2801 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2803 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2804 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2805 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2806 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2812 GetSize( &w
, &h
) ;
2814 MacClientToRootWindow( &x
, &y
) ;
2815 MacClientToRootWindow( &w
, &h
) ;
2817 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2819 int totW
= 10000 , totH
= 10000;
2822 if ( iter
->IsTopLevel() )
2824 iter
->GetSize( &totW
, &totH
) ;
2828 iter
= iter
->GetParent() ;
2856 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2860 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2864 bool wxWindowMac::AcceptsFocus() const
2866 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2869 void wxWindowMac::MacSuperChangedPosition()
2871 // only window-absolute structures have to be moved i.e. controls
2873 wxWindowListNode
*node
= GetChildren().GetFirst();
2876 wxWindowMac
*child
= node
->GetData();
2877 child
->MacSuperChangedPosition() ;
2878 node
= node
->GetNext();
2882 void wxWindowMac::MacTopLevelWindowChangedPosition()
2884 // only screen-absolute structures have to be moved i.e. glcanvas
2886 wxWindowListNode
*node
= GetChildren().GetFirst();
2889 wxWindowMac
*child
= node
->GetData();
2890 child
->MacTopLevelWindowChangedPosition() ;
2891 node
= node
->GetNext();
2895 long wxWindowMac::MacGetLeftBorderSize( ) const
2900 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2905 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2910 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2917 long wxWindowMac::MacGetRightBorderSize( ) const
2919 // they are all symmetric in mac themes
2920 return MacGetLeftBorderSize() ;
2923 long wxWindowMac::MacGetTopBorderSize( ) const
2925 // they are all symmetric in mac themes
2926 return MacGetLeftBorderSize() ;
2929 long wxWindowMac::MacGetBottomBorderSize( ) const
2931 // they are all symmetric in mac themes
2932 return MacGetLeftBorderSize() ;
2935 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2937 return style
& ~wxBORDER_MASK
;
2940 // Find the wxWindowMac at the current mouse position, returning the mouse
2942 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2944 pt
= wxGetMousePosition();
2945 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2949 // Get the current mouse position.
2950 wxPoint
wxGetMousePosition()
2953 wxGetMousePosition(& x
, & y
);
2954 return wxPoint(x
, y
);
2957 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2959 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2961 // copied from wxGTK : CS
2962 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2965 // (a) it's a command event and so is propagated to the parent
2966 // (b) under MSW it can be generated from kbd too
2967 // (c) it uses screen coords (because of (a))
2968 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2970 this->ClientToScreen(event
.GetPosition()));
2971 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2980 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2984 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2988 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2989 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2993 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2995 return eventNotHandledErr
;