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
;
155 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
156 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
158 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
160 // GrafPtr myport = cEvent.GetParameter<GrafPtr>(kEventParamGrafPort,typeGrafPtr) ;
163 // in case we would need a coregraphics compliant background erase first
164 // now usable to track redraws
165 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
166 if ( thisWindow
->MacIsUserPane() )
168 static float color
= 0.5 ;
171 HIViewGetBounds( controlRef
, &bounds
);
172 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
173 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
174 CGContextFillRect( cgContext
, bounds
);
185 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
189 case kEventControlVisibilityChanged
:
190 thisWindow
->MacVisibilityChanged() ;
192 case kEventControlEnabledStateChanged
:
193 thisWindow
->MacEnabledStateChanged() ;
195 case kEventControlHiliteChanged
:
196 thisWindow
->MacHiliteChanged() ;
198 case kEventControlSetFocusPart
:
200 Boolean focusEverything
= false ;
201 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
202 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
205 if ( controlPart
== kControlFocusNoPart
)
208 if ( thisWindow
->GetCaret() )
210 thisWindow
->GetCaret()->OnKillFocus();
212 #endif // wxUSE_CARET
213 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
214 event
.SetEventObject(thisWindow
);
215 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
219 // panel wants to track the window which was the last to have focus in it
220 wxChildFocusEvent
eventFocus(thisWindow
);
221 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
224 if ( thisWindow
->GetCaret() )
226 thisWindow
->GetCaret()->OnSetFocus();
228 #endif // wxUSE_CARET
230 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
231 event
.SetEventObject(thisWindow
);
232 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
234 if ( thisWindow
->MacIsUserPane() )
239 case kEventControlHit
:
241 result
= thisWindow
->MacControlHit( handler
, event
) ;
250 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
252 OSStatus result
= eventNotHandledErr
;
254 wxMacCarbonEvent
cEvent( event
) ;
256 ControlRef controlRef
;
257 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
258 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
259 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
261 switch( GetEventKind( event
) )
263 case kEventServiceGetTypes
:
267 textCtrl
->GetSelection( &from
, &to
) ;
269 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
271 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
272 if ( textCtrl
->IsEditable() )
273 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
275 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
276 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
278 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
282 CFArrayAppendValue (copyTypes
, typestring
) ;
284 CFArrayAppendValue (pasteTypes
, typestring
) ;
285 CFRelease( typestring
) ;
291 case kEventServiceCopy
:
295 textCtrl
->GetSelection( &from
, &to
) ;
296 wxString val
= textCtrl
->GetValue() ;
297 val
= val
.Mid( from
, to
- from
) ;
298 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
299 verify_noerr( ClearScrap( &scrapRef
) ) ;
300 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
304 case kEventServicePaste
:
307 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
308 Size textSize
, pastedSize
;
309 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
311 char *content
= new char[textSize
] ;
312 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
313 content
[textSize
-1] = 0 ;
315 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
317 textCtrl
->WriteText( wxString( content
) ) ;
328 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
330 OSStatus result
= eventNotHandledErr
;
332 switch ( GetEventClass( event
) )
334 case kEventClassControl
:
335 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
337 case kEventClassService
:
338 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
345 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
347 // ---------------------------------------------------------------------------
348 // UserPane events for non OSX builds
349 // ---------------------------------------------------------------------------
351 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
353 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
354 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
355 win
->MacControlUserPaneDrawProc(part
) ;
358 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
360 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
361 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
362 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
365 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
367 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
368 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
369 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
372 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
374 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
375 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
376 win
->MacControlUserPaneIdleProc() ;
379 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
381 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
382 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
383 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
386 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
388 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
389 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
390 win
->MacControlUserPaneActivateProc(activating
) ;
393 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
395 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
396 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
397 return win
->MacControlUserPaneFocusProc(action
) ;
400 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
402 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
403 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
404 win
->MacControlUserPaneBackgroundProc(info
) ;
407 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
409 RgnHandle rgn
= NewRgn() ;
411 wxMacWindowStateSaver
sv( this ) ;
412 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
413 MacDoRedraw( rgn
, 0 ) ;
417 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
419 return kControlNoPart
;
422 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
424 return kControlNoPart
;
427 void wxWindowMac::MacControlUserPaneIdleProc()
431 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
433 return kControlNoPart
;
436 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
440 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
442 return kControlNoPart
;
445 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
449 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
450 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
451 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
452 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
453 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
454 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
455 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
456 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
458 // ===========================================================================
460 // ===========================================================================
462 wxList
wxWinMacControlList(wxKEY_INTEGER
);
464 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
466 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
469 return (wxControl
*)node
->GetData();
472 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
474 // adding NULL ControlRef is (first) surely a result of an error and
475 // (secondly) breaks native event processing
476 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
478 if ( !wxWinMacControlList
.Find((long)inControl
) )
479 wxWinMacControlList
.Append((long)inControl
, control
);
482 void wxRemoveMacControlAssociation(wxWindow
*control
)
484 wxWinMacControlList
.DeleteObject(control
);
488 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
490 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
492 // we have to setup the brush in the current port and return noErr
493 // or return an error code so that the control manager walks further up the
494 // hierarchy to find a correct background
496 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
498 OSStatus status
= paramErr
;
501 case kControlMsgApplyTextColor
:
503 case kControlMsgSetUpBackground
:
505 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
508 const wxBrush
&brush
= wx
->MacGetBackgroundBrush() ;
511 wxDC::MacSetupBackgroundForCurrentPort( brush
) ;
513 RgnHandle clip
= NewRgn() ;
516 wx
->MacWindowToRootWindow( &x
,&y
) ;
517 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
518 OffsetRgn( clip
, x
, y
) ;
524 else if ( wx
->MacIsUserPane() )
526 // if we don't have a valid brush for such a control, we have to call the
527 // setup of our parent ourselves
528 status
= SetUpControlBackground( (ControlRef
) wx
->GetParent()->GetHandle() , iDepth
, iIsColor
) ;
540 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
541 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
545 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
548 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
553 // ----------------------------------------------------------------------------
554 // constructors and such
555 // ----------------------------------------------------------------------------
557 wxWindowMac::wxWindowMac()
562 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
567 const wxString
& name
)
570 Create(parent
, id
, pos
, size
, style
, name
);
573 void wxWindowMac::Init()
577 #if WXWIN_COMPATIBILITY_2_4
578 m_backgroundTransparent
= FALSE
;
581 // as all windows are created with WS_VISIBLE style...
584 m_hScrollBar
= NULL
;
585 m_vScrollBar
= NULL
;
586 m_macBackgroundBrush
= wxNullBrush
;
588 m_macIsUserPane
= TRUE
;
590 // make sure all proc ptrs are available
592 if ( gControlUserPaneDrawUPP
== NULL
)
594 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
595 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
596 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
597 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
598 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
599 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
600 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
601 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
603 if ( wxMacLiveScrollbarActionUPP
== NULL
)
605 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
608 if ( wxMacSetupControlBackgroundUPP
== NULL
)
610 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
613 // we need a valid font for the encodings
614 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
618 wxWindowMac::~wxWindowMac()
622 m_isBeingDeleted
= TRUE
;
624 #ifndef __WXUNIVERSAL__
625 // VS: make sure there's no wxFrame with last focus set to us:
626 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
628 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
631 if ( frame
->GetLastFocus() == this )
633 frame
->SetLastFocus((wxWindow
*)NULL
);
638 #endif // __WXUNIVERSAL__
640 // wxRemoveMacControlAssociation( this ) ;
641 // If we delete an item, we should initialize the parent panel,
642 // because it could now be invalid.
643 wxWindow
*parent
= GetParent() ;
646 if (parent
->GetDefaultItem() == (wxButton
*) this)
647 parent
->SetDefaultItem(NULL
);
649 if ( m_peer
&& m_peer
->Ok() )
651 // in case the callback might be called during destruction
652 wxRemoveMacControlAssociation( this) ;
653 // we currently are not using this hook
654 // ::SetControlColorProc( *m_peer , NULL ) ;
658 if ( g_MacLastWindow
== this )
660 g_MacLastWindow
= NULL
;
663 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
666 if ( frame
->GetLastFocus() == this )
667 frame
->SetLastFocus( NULL
) ;
672 // delete our drop target if we've got one
673 #if wxUSE_DRAG_AND_DROP
674 if ( m_dropTarget
!= NULL
)
679 #endif // wxUSE_DRAG_AND_DROP
683 WXWidget
wxWindowMac::GetHandle() const
685 return (WXWidget
) m_peer
->GetControlRef() ;
689 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
691 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
692 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
693 GetEventTypeCount(eventList
), eventList
, this,
694 (EventHandlerRef
*)&m_macControlEventHandler
);
699 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
703 const wxString
& name
)
705 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
707 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
710 parent
->AddChild(this);
712 m_windowVariant
= parent
->GetWindowVariant() ;
714 if ( m_macIsUserPane
)
716 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
719 | kControlSupportsEmbedding
720 // | kControlSupportsLiveFeedback
721 // | kControlHasSpecialBackground
722 // | kControlSupportsCalcBestRect
723 // | kControlHandlesTracking
724 | kControlSupportsFocus
725 // | kControlWantsActivate
726 // | kControlWantsIdle
729 m_peer
= new wxMacControl() ;
730 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
733 MacPostControlCreate(pos
,size
) ;
734 #if !TARGET_API_MAC_OSX
735 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
736 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
737 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
738 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
739 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
740 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
741 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
742 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
745 #ifndef __WXUNIVERSAL__
746 // Don't give scrollbars to wxControls unless they ask for them
747 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
748 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
750 MacCreateScrollBars( style
) ;
754 wxWindowCreateEvent
event(this);
755 GetEventHandler()->AddPendingEvent(event
);
760 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
762 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
764 m_peer
->SetReference( (long) this ) ;
766 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
768 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
769 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
770 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
772 // adjust font, controlsize etc
773 DoSetWindowVariant( m_windowVariant
) ;
775 #if !TARGET_API_MAC_OSX
776 // eventually we can fix some clipping issues be reactivating this hook
777 //if ( m_macIsUserPane )
778 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
780 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
782 if (!m_macIsUserPane
)
784 SetInitialBestSize(size
);
787 SetCursor( *wxSTANDARD_CURSOR
) ;
790 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
792 // Don't assert, in case we set the window variant before
793 // the window is created
794 // wxASSERT( m_peer->Ok() ) ;
796 m_windowVariant
= variant
;
798 if (m_peer
== NULL
|| !m_peer
->Ok())
802 ThemeFontID themeFont
= kThemeSystemFont
;
804 // we will get that from the settings later
805 // and make this NORMAL later, but first
806 // we have a few calculations that we must fix
810 case wxWINDOW_VARIANT_NORMAL
:
811 size
= kControlSizeNormal
;
812 themeFont
= kThemeSystemFont
;
814 case wxWINDOW_VARIANT_SMALL
:
815 size
= kControlSizeSmall
;
816 themeFont
= kThemeSmallSystemFont
;
818 case wxWINDOW_VARIANT_MINI
:
819 if (UMAGetSystemVersion() >= 0x1030 )
821 // not always defined in the headers
827 size
= kControlSizeSmall
;
828 themeFont
= kThemeSmallSystemFont
;
831 case wxWINDOW_VARIANT_LARGE
:
832 size
= kControlSizeLarge
;
833 themeFont
= kThemeSystemFont
;
836 wxFAIL_MSG(_T("unexpected window variant"));
839 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
842 font
.MacCreateThemeFont( themeFont
) ;
846 void wxWindowMac::MacUpdateControlFont()
848 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
852 bool wxWindowMac::SetFont(const wxFont
& font
)
854 bool retval
= !wxWindowBase::SetFont( font
) ;
856 MacUpdateControlFont() ;
861 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
863 if ( !wxWindowBase::SetForegroundColour(col
) )
866 MacUpdateControlFont() ;
871 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
873 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
877 wxColour
newCol(GetBackgroundColour());
878 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
880 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
882 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
884 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
888 brush
.SetColour( newCol
) ;
890 MacSetBackgroundBrush( brush
) ;
892 MacUpdateControlFont() ;
898 bool wxWindowMac::MacCanFocus() const
900 // there is currently no way to determine whether the window is running in full keyboard
901 // access mode, therefore we cannot rely on these features, yet the only other way would be
902 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
903 // in event handlers...
904 UInt32 features
= 0 ;
905 m_peer
->GetFeatures( & features
) ;
906 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
910 void wxWindowMac::SetFocus()
912 if ( AcceptsFocus() )
914 #if !TARGET_API_MAC_OSX
915 wxWindow
* former
= FindFocus() ;
917 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
918 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
919 // leave in case of an error
920 if ( err
== errCouldntSetFocus
)
923 #if !TARGET_API_MAC_OSX
924 // emulate carbon events when running under carbonlib where they are not natively available
927 EventRef evRef
= NULL
;
928 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
931 wxMacCarbonEvent
cEvent( evRef
) ;
932 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
933 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
935 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
936 ReleaseEvent(evRef
) ;
938 // send new focus event
940 EventRef evRef
= NULL
;
941 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
944 wxMacCarbonEvent
cEvent( evRef
) ;
945 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
946 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
948 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
949 ReleaseEvent(evRef
) ;
956 void wxWindowMac::DoCaptureMouse()
958 wxTheApp
->s_captureWindow
= this ;
961 wxWindow
* wxWindowBase::GetCapture()
963 return wxTheApp
->s_captureWindow
;
966 void wxWindowMac::DoReleaseMouse()
968 wxTheApp
->s_captureWindow
= NULL
;
971 #if wxUSE_DRAG_AND_DROP
973 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
975 if ( m_dropTarget
!= 0 ) {
979 m_dropTarget
= pDropTarget
;
980 if ( m_dropTarget
!= 0 )
988 // Old style file-manager drag&drop
989 void wxWindowMac::DragAcceptFiles(bool accept
)
994 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
995 int& w
, int& h
) const
998 m_peer
->GetRect( &bounds
) ;
1003 w
= bounds
.right
- bounds
.left
;
1004 h
= bounds
.bottom
- bounds
.top
;
1006 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1009 Point tlworigin
= { 0 , 0 } ;
1010 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1016 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1019 int& w
, int& h
, bool adjustOrigin
) const
1021 // the desired size, minus the border pixels gives the correct size of the control
1025 // todo the default calls may be used as soon as PostCreateControl Is moved here
1026 w
= size
.x
; // WidthDefault( size.x );
1027 h
= size
.y
; // HeightDefault( size.y ) ;
1028 #if !TARGET_API_MAC_OSX
1029 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1032 x
+= MacGetLeftBorderSize() ;
1033 y
+= MacGetTopBorderSize() ;
1034 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1035 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1038 AdjustForParentClientOrigin( x
, y
) ;
1043 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1045 // take the size of the control and add the borders that have to be drawn outside
1046 int x1
, y1
, w1
,h1
;
1047 #if TARGET_API_MAC_OSX
1048 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1052 m_peer
->GetRect( &bounds
) ;
1053 w1
= bounds
.right
- bounds
.left
;
1054 h1
= bounds
.bottom
- bounds
.top
;
1056 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1057 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1063 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1065 #if TARGET_API_MAC_OSX
1066 int x1
, y1
, w1
,h1
;
1067 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1068 x1
-= MacGetLeftBorderSize() ;
1069 y1
-= MacGetTopBorderSize() ;
1070 if ( !IsTopLevel() )
1072 wxWindow
*parent
= GetParent();
1075 wxPoint
pt(parent
->GetClientAreaOrigin());
1084 m_peer
->GetRect( &bounds
) ;
1085 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1087 int xx
= bounds
.left
;
1088 int yy
= bounds
.top
;
1089 xx
-= MacGetLeftBorderSize() ;
1090 yy
-= MacGetTopBorderSize() ;
1092 if ( !GetParent()->IsTopLevel() )
1094 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1100 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1109 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1111 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1113 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1116 Point localwhere
= {0,0} ;
1118 if(x
) localwhere
.h
= * x
;
1119 if(y
) localwhere
.v
= * y
;
1121 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1122 if(x
) *x
= localwhere
.h
;
1123 if(y
) *y
= localwhere
.v
;
1126 MacRootWindowToWindow( x
, y
) ;
1128 wxPoint origin
= GetClientAreaOrigin() ;
1129 if(x
) *x
-= origin
.x
;
1130 if(y
) *y
-= origin
.y
;
1133 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1135 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1136 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1138 wxPoint origin
= GetClientAreaOrigin() ;
1139 if(x
) *x
+= origin
.x
;
1140 if(y
) *y
+= origin
.y
;
1142 MacWindowToRootWindow( x
, y
) ;
1145 Point localwhere
= { 0,0 };
1146 if(x
) localwhere
.h
= * x
;
1147 if(y
) localwhere
.v
= * y
;
1148 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1149 if(x
) *x
= localwhere
.h
;
1150 if(y
) *y
= localwhere
.v
;
1154 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1156 wxPoint origin
= GetClientAreaOrigin() ;
1157 if(x
) *x
+= origin
.x
;
1158 if(y
) *y
+= origin
.y
;
1160 MacWindowToRootWindow( x
, y
) ;
1163 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1165 MacRootWindowToWindow( x
, y
) ;
1167 wxPoint origin
= GetClientAreaOrigin() ;
1168 if(x
) *x
-= origin
.x
;
1169 if(y
) *y
-= origin
.y
;
1172 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1174 #if TARGET_API_MAC_OSX
1176 if ( x
) pt
.x
= *x
;
1177 if ( y
) pt
.y
= *y
;
1179 if ( !IsTopLevel() )
1181 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1184 pt
.x
-= MacGetLeftBorderSize() ;
1185 pt
.y
-= MacGetTopBorderSize() ;
1186 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1190 if ( x
) *x
= (int) pt
.x
;
1191 if ( y
) *y
= (int) pt
.y
;
1193 if ( !IsTopLevel() )
1196 m_peer
->GetRect( &bounds
) ;
1197 if(x
) *x
+= bounds
.left
;
1198 if(y
) *y
+= bounds
.top
;
1203 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1208 MacWindowToRootWindow( &x1
, &y1
) ;
1213 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1215 #if TARGET_API_MAC_OSX
1217 if ( x
) pt
.x
= *x
;
1218 if ( y
) pt
.y
= *y
;
1220 if ( !IsTopLevel() )
1222 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1223 pt
.x
+= MacGetLeftBorderSize() ;
1224 pt
.y
+= MacGetTopBorderSize() ;
1227 if ( x
) *x
= (int) pt
.x
;
1228 if ( y
) *y
= (int) pt
.y
;
1230 if ( !IsTopLevel() )
1233 m_peer
->GetRect( &bounds
) ;
1234 if(x
) *x
-= bounds
.left
;
1235 if(y
) *y
-= bounds
.top
;
1240 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1245 MacRootWindowToWindow( &x1
, &y1
) ;
1250 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1252 RgnHandle rgn
= NewRgn() ;
1254 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1256 GetRegionBounds( rgn
, &content
) ;
1261 m_peer
->GetRect( &content
) ;
1264 m_peer
->GetRect( &structure
) ;
1265 #if !TARGET_API_MAC_OSX
1266 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1268 left
= content
.left
- structure
.left
;
1269 top
= content
.top
- structure
.top
;
1270 right
= structure
.right
- content
.right
;
1271 bottom
= structure
.bottom
- content
.bottom
;
1274 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1276 wxSize sizeTotal
= size
;
1278 RgnHandle rgn
= NewRgn() ;
1282 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1284 GetRegionBounds( rgn
, &content
) ;
1289 m_peer
->GetRect( &content
) ;
1292 m_peer
->GetRect( &structure
) ;
1293 #if !TARGET_API_MAC_OSX
1294 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1297 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1298 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1300 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1301 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1307 // Get size *available for subwindows* i.e. excluding menu bar etc.
1308 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1312 RgnHandle rgn
= NewRgn() ;
1314 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1316 GetRegionBounds( rgn
, &content
) ;
1321 m_peer
->GetRect( &content
) ;
1323 #if !TARGET_API_MAC_OSX
1325 m_peer
->GetRect( &structure
) ;
1326 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1328 ww
= content
.right
- content
.left
;
1329 hh
= content
.bottom
- content
.top
;
1331 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1332 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1334 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1340 GetSize( &w
, &h
) ;
1342 MacClientToRootWindow( &x1
, &y1
) ;
1343 MacClientToRootWindow( &w
, &h
) ;
1345 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1347 int totW
= 10000 , totH
= 10000;
1350 if ( iter
->IsTopLevel() )
1352 iter
->GetSize( &totW
, &totH
) ;
1356 iter
= iter
->GetParent() ;
1359 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1361 hh
-= MAC_SCROLLBAR_SIZE
;
1367 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1369 ww
-= MAC_SCROLLBAR_SIZE
;
1381 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1383 if (m_cursor
== cursor
)
1386 if (wxNullCursor
== cursor
)
1388 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1393 if ( ! wxWindowBase::SetCursor( cursor
) )
1397 wxASSERT_MSG( m_cursor
.Ok(),
1398 wxT("cursor must be valid after call to the base version"));
1401 wxWindowMac
*mouseWin
= 0 ;
1403 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1405 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1407 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1408 // position, use it...
1412 ControlPartCode part
;
1413 ControlRef control
;
1414 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1416 mouseWin
= wxFindControlFromMacControl( control
) ;
1419 QDSwapPort( savePort
, NULL
) ;
1422 if ( mouseWin
== this && !wxIsBusy() )
1424 m_cursor
.MacInstall() ;
1431 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1433 menu
->SetInvokingWindow(this);
1436 if ( x
== -1 && y
== -1 )
1438 wxPoint mouse
= wxGetMousePosition();
1439 x
= mouse
.x
; y
= mouse
.y
;
1443 ClientToScreen( &x
, &y
) ;
1446 menu
->MacBeforeDisplay( true ) ;
1447 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1448 if ( HiWord(menuResult
) != 0 )
1451 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1452 wxMenuItem
* item
= NULL
;
1454 item
= menu
->FindItem(id
, &realmenu
) ;
1455 if (item
->IsCheckable())
1457 item
->Check( !item
->IsChecked() ) ;
1459 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1461 menu
->MacAfterDisplay( true ) ;
1463 menu
->SetInvokingWindow(NULL
);
1469 // ----------------------------------------------------------------------------
1471 // ----------------------------------------------------------------------------
1475 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1477 wxWindowBase::DoSetToolTip(tooltip
);
1480 m_tooltip
->SetWindow(this);
1483 #endif // wxUSE_TOOLTIPS
1485 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1487 int former_x
, former_y
, former_w
, former_h
;
1488 #if !TARGET_API_MAC_OSX
1489 DoGetPosition( &former_x
, &former_y
) ;
1490 DoGetSize( &former_w
, &former_h
) ;
1492 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1493 former_x
-= MacGetLeftBorderSize() ;
1494 former_y
-= MacGetTopBorderSize() ;
1495 former_w
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1496 former_h
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1499 int actualWidth
= width
;
1500 int actualHeight
= height
;
1504 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1505 actualWidth
= m_minWidth
;
1506 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1507 actualHeight
= m_minHeight
;
1508 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1509 actualWidth
= m_maxWidth
;
1510 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1511 actualHeight
= m_maxHeight
;
1513 bool doMove
= false ;
1514 bool doResize
= false ;
1516 if ( actualX
!= former_x
|| actualY
!= former_y
)
1520 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1525 if ( doMove
|| doResize
)
1527 // we don't adjust twice for the origin
1528 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1529 bool vis
= m_peer
->IsVisible();
1531 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1533 m_peer
->SetVisibility( false , true ) ;
1534 m_peer
->SetRect( &r
) ;
1536 m_peer
->SetVisibility( true , true ) ;
1538 MacRepositionScrollBars() ;
1541 wxPoint
point(actualX
,actualY
);
1542 wxMoveEvent
event(point
, m_windowId
);
1543 event
.SetEventObject(this);
1544 GetEventHandler()->ProcessEvent(event
) ;
1548 MacRepositionScrollBars() ;
1549 wxSize
size(actualWidth
, actualHeight
);
1550 wxSizeEvent
event(size
, m_windowId
);
1551 event
.SetEventObject(this);
1552 GetEventHandler()->ProcessEvent(event
);
1558 wxSize
wxWindowMac::DoGetBestSize() const
1560 if ( m_macIsUserPane
|| IsTopLevel() )
1561 return wxWindowBase::DoGetBestSize() ;
1563 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1564 int bestWidth
, bestHeight
;
1565 m_peer
->GetBestRect( &bestsize
) ;
1567 if ( EmptyRect( &bestsize
) )
1569 bestsize
.left
= bestsize
.top
= 0 ;
1570 bestsize
.right
= 16 ;
1571 bestsize
.bottom
= 16 ;
1572 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1574 bestsize
.bottom
= 16 ;
1576 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1578 bestsize
.bottom
= 24 ;
1582 // return wxWindowBase::DoGetBestSize() ;
1586 bestWidth
= bestsize
.right
- bestsize
.left
;
1587 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1588 if ( bestHeight
< 10 )
1591 return wxSize(bestWidth
, bestHeight
);
1595 // set the size of the window: if the dimensions are positive, just use them,
1596 // but if any of them is equal to -1, it means that we must find the value for
1597 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1598 // which case -1 is a valid value for x and y)
1600 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1601 // the width/height to best suit our contents, otherwise we reuse the current
1603 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1605 // get the current size and position...
1606 int currentX
, currentY
;
1607 GetPosition(¤tX
, ¤tY
);
1609 int currentW
,currentH
;
1610 GetSize(¤tW
, ¤tH
);
1612 // ... and don't do anything (avoiding flicker) if it's already ok
1613 if ( x
== currentX
&& y
== currentY
&&
1614 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1617 MacRepositionScrollBars() ; // we might have a real position shift
1621 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1623 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1626 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1628 wxSize
size(-1, -1);
1631 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1633 size
= DoGetBestSize();
1638 // just take the current one
1645 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1649 size
= DoGetBestSize();
1651 //else: already called DoGetBestSize() above
1657 // just take the current one
1662 DoMoveWindow(x
, y
, width
, height
);
1666 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1668 RgnHandle rgn
= NewRgn() ;
1670 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1671 GetRegionBounds( rgn
, &content
) ;
1673 #if !TARGET_API_MAC_OSX
1674 // if the content rgn is empty / not supported
1675 // don't attempt to correct the coordinates to wxWindow relative ones
1676 if (!::EmptyRect( &content
) )
1679 m_peer
->GetRect( &structure
) ;
1680 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1684 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1687 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1689 if ( clientheight
!= -1 || clientheight
!= -1 )
1691 int currentclientwidth
, currentclientheight
;
1692 int currentwidth
, currentheight
;
1694 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1695 GetSize( ¤twidth
, ¤theight
) ;
1697 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1698 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1702 void wxWindowMac::SetTitle(const wxString
& title
)
1704 m_label
= wxStripMenuCodes(title
) ;
1706 if ( m_peer
&& m_peer
->Ok() )
1708 m_peer
->SetTitle( m_label
) ;
1713 wxString
wxWindowMac::GetTitle() const
1718 bool wxWindowMac::Show(bool show
)
1720 if ( !wxWindowBase::Show(show
) )
1723 // TODO use visibilityChanged Carbon Event for OSX
1724 bool former
= MacIsReallyShown() ;
1726 m_peer
->SetVisibility( show
, true ) ;
1727 if ( former
!= MacIsReallyShown() )
1728 MacPropagateVisibilityChanged() ;
1732 bool wxWindowMac::Enable(bool enable
)
1734 wxASSERT( m_peer
->Ok() ) ;
1735 if ( !wxWindowBase::Enable(enable
) )
1738 bool former
= MacIsReallyEnabled() ;
1739 m_peer
->Enable( enable
) ;
1741 if ( former
!= MacIsReallyEnabled() )
1742 MacPropagateEnabledStateChanged() ;
1747 // status change propagations (will be not necessary for OSX later )
1750 void wxWindowMac::MacPropagateVisibilityChanged()
1752 #if !TARGET_API_MAC_OSX
1753 MacVisibilityChanged() ;
1755 wxWindowListNode
*node
= GetChildren().GetFirst();
1758 wxWindowMac
*child
= node
->GetData();
1759 if ( child
->IsShown() )
1760 child
->MacPropagateVisibilityChanged( ) ;
1761 node
= node
->GetNext();
1766 void wxWindowMac::MacPropagateEnabledStateChanged( )
1768 #if !TARGET_API_MAC_OSX
1769 MacEnabledStateChanged() ;
1771 wxWindowListNode
*node
= GetChildren().GetFirst();
1774 wxWindowMac
*child
= node
->GetData();
1775 if ( child
->IsEnabled() )
1776 child
->MacPropagateEnabledStateChanged() ;
1777 node
= node
->GetNext();
1782 void wxWindowMac::MacPropagateHiliteChanged( )
1784 #if !TARGET_API_MAC_OSX
1785 MacHiliteChanged() ;
1787 wxWindowListNode
*node
= GetChildren().GetFirst();
1790 wxWindowMac
*child
= node
->GetData();
1791 // if ( child->IsEnabled() )
1792 child
->MacPropagateHiliteChanged() ;
1793 node
= node
->GetNext();
1799 // status change notifications
1802 void wxWindowMac::MacVisibilityChanged()
1806 void wxWindowMac::MacHiliteChanged()
1810 void wxWindowMac::MacEnabledStateChanged()
1815 // status queries on the inherited window's state
1818 bool wxWindowMac::MacIsReallyShown()
1820 // only under OSX the visibility of the TLW is taken into account
1821 #if TARGET_API_MAC_OSX
1822 if ( m_peer
&& m_peer
->Ok() )
1823 return m_peer
->IsVisible();
1825 wxWindow
* win
= this ;
1826 while( win
->IsShown() )
1828 if ( win
->IsTopLevel() )
1831 win
= win
->GetParent() ;
1839 bool wxWindowMac::MacIsReallyEnabled()
1841 return m_peer
->IsEnabled() ;
1844 bool wxWindowMac::MacIsReallyHilited()
1846 return m_peer
->IsActive();
1849 void wxWindowMac::MacFlashInvalidAreas()
1851 #if TARGET_API_MAC_OSX
1852 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1860 int wxWindowMac::GetCharHeight() const
1862 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1863 return dc
.GetCharHeight() ;
1866 int wxWindowMac::GetCharWidth() const
1868 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1869 return dc
.GetCharWidth() ;
1872 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1873 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1875 const wxFont
*fontToUse
= theFont
;
1877 fontToUse
= &m_font
;
1879 wxClientDC
dc( (wxWindowMac
*) this ) ;
1881 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1882 if ( externalLeading
)
1883 *externalLeading
= le
;
1893 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1894 * we always intersect with the entire window, not only with the client area
1897 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1899 #if TARGET_API_MAC_OSX
1901 m_peer
->SetNeedsDisplay( true ) ;
1904 RgnHandle update
= NewRgn() ;
1905 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1906 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1907 wxPoint origin
= GetClientAreaOrigin() ;
1908 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1909 m_peer
->SetNeedsDisplay( true , update
) ;
1913 RgnHandle updateRgn = NewRgn() ;
1916 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1920 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1921 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1923 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1924 DisposeRgn(updateRgn) ;
1926 if ( m_peer
->IsVisible())
1928 m_peer
->SetVisibility( false , false ) ;
1929 m_peer
->SetVisibility( true , true ) ;
1932 if ( MacGetTopLevelWindow() == NULL )
1935 if ( !m_peer->IsVisible())
1938 wxPoint client = GetClientAreaOrigin();
1941 int x2 = m_width - client.x;
1942 int y2 = m_height - client.y;
1944 if (IsKindOf( CLASSINFO(wxButton)))
1946 // buttons have an "aura"
1953 Rect clientrect = { y1, x1, y2, x2 };
1957 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1958 SectRect( &clientrect , &r , &clientrect ) ;
1961 if ( !EmptyRect( &clientrect ) )
1963 int top = 0 , left = 0 ;
1965 MacClientToRootWindow( &left , &top ) ;
1966 OffsetRect( &clientrect , left , top ) ;
1968 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1974 void wxWindowMac::Freeze()
1976 #if TARGET_API_MAC_OSX
1977 if ( !m_frozenness
++ )
1979 m_peer
->SetDrawingEnabled( false ) ;
1985 void wxWindowMac::Thaw()
1987 #if TARGET_API_MAC_OSX
1988 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1990 if ( !--m_frozenness
)
1992 m_peer
->SetDrawingEnabled( true ) ;
1993 m_peer
->InvalidateWithChildren() ;
1998 void wxWindowMac::MacRedrawControl()
2001 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2003 #if TARGET_API_MAC_CARBON
2006 wxClientDC dc(this) ;
2007 wxMacPortSetter helper(&dc) ;
2008 wxMacWindowClipper clipper(this) ;
2009 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2010 UMADrawControl( *m_peer ) ;
2017 void wxWindowMac::OnPaint(wxPaintEvent& event)
2019 // why don't we skip that here ?
2023 wxWindowMac
*wxGetActiveWindow()
2025 // actually this is a windows-only concept
2029 // Coordinates relative to the window
2030 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2032 // We really don't move the mouse programmatically under Mac.
2035 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2037 #if TARGET_API_MAC_OSX
2038 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2044 event
.GetDC()->Clear() ;
2047 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2049 wxWindowDC
dc(this) ;
2050 wxMacPortSetter
helper(&dc
) ;
2052 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2055 int wxWindowMac::GetScrollPos(int orient
) const
2057 if ( orient
== wxHORIZONTAL
)
2060 return m_hScrollBar
->GetThumbPosition() ;
2065 return m_vScrollBar
->GetThumbPosition() ;
2070 // This now returns the whole range, not just the number
2071 // of positions that we can scroll.
2072 int wxWindowMac::GetScrollRange(int orient
) const
2074 if ( orient
== wxHORIZONTAL
)
2077 return m_hScrollBar
->GetRange() ;
2082 return m_vScrollBar
->GetRange() ;
2087 int wxWindowMac::GetScrollThumb(int orient
) const
2089 if ( orient
== wxHORIZONTAL
)
2092 return m_hScrollBar
->GetThumbSize() ;
2097 return m_vScrollBar
->GetThumbSize() ;
2102 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2104 if ( orient
== wxHORIZONTAL
)
2107 m_hScrollBar
->SetThumbPosition( pos
) ;
2112 m_vScrollBar
->SetThumbPosition( pos
) ;
2116 void wxWindowMac::MacPaintBorders( int left
, int top
)
2122 wxGetOsVersion( &major
, &minor
);
2124 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2125 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2126 // OS X has lighter border edges than classic:
2129 darkShadow
.red
= 0x8E8E;
2130 darkShadow
.green
= 0x8E8E;
2131 darkShadow
.blue
= 0x8E8E;
2132 lightShadow
.red
= 0xBDBD;
2133 lightShadow
.green
= 0xBDBD;
2134 lightShadow
.blue
= 0xBDBD;
2140 GetSize( &w
, &h
) ;
2141 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2142 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2144 #if wxMAC_USE_THEME_BORDER
2146 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2147 InsetRect( &rect
, border
, border
);
2148 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2150 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2151 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2153 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2154 RGBForeColor( &face
);
2155 MoveTo( left
+ 0 , top
+ h
- 2 );
2156 LineTo( left
+ 0 , top
+ 0 );
2157 LineTo( left
+ w
- 2 , top
+ 0 );
2159 MoveTo( left
+ 2 , top
+ h
- 3 );
2160 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2161 LineTo( left
+ w
- 3 , top
+ 2 );
2163 RGBForeColor( sunken
? &face
: &darkShadow
);
2164 MoveTo( left
+ 0 , top
+ h
- 1 );
2165 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2166 LineTo( left
+ w
- 1 , top
+ 0 );
2168 RGBForeColor( sunken
? &lightShadow
: &white
);
2169 MoveTo( left
+ 1 , top
+ h
- 3 );
2170 LineTo( left
+ 1, top
+ 1 );
2171 LineTo( left
+ w
- 3 , top
+ 1 );
2173 RGBForeColor( sunken
? &white
: &lightShadow
);
2174 MoveTo( left
+ 1 , top
+ h
- 2 );
2175 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2176 LineTo( left
+ w
- 2 , top
+ 1 );
2178 RGBForeColor( sunken
? &darkShadow
: &face
);
2179 MoveTo( left
+ 2 , top
+ h
- 4 );
2180 LineTo( left
+ 2 , top
+ 2 );
2181 LineTo( left
+ w
- 4 , top
+ 2 );
2184 else if (HasFlag(wxSIMPLE_BORDER
))
2186 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2187 RGBForeColor( &darkShadow
) ;
2188 FrameRect( &rect
) ;
2192 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2194 if ( child
== m_hScrollBar
)
2195 m_hScrollBar
= NULL
;
2196 if ( child
== m_vScrollBar
)
2197 m_vScrollBar
= NULL
;
2199 wxWindowBase::RemoveChild( child
) ;
2202 // New function that will replace some of the above.
2203 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2204 int range
, bool refresh
)
2206 if ( orient
== wxHORIZONTAL
)
2210 if ( range
== 0 || thumbVisible
>= range
)
2212 if ( m_hScrollBar
->IsShown() )
2213 m_hScrollBar
->Show(false) ;
2217 if ( !m_hScrollBar
->IsShown() )
2218 m_hScrollBar
->Show(true) ;
2219 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2227 if ( range
== 0 || thumbVisible
>= range
)
2229 if ( m_vScrollBar
->IsShown() )
2230 m_vScrollBar
->Show(false) ;
2234 if ( !m_vScrollBar
->IsShown() )
2235 m_vScrollBar
->Show(true) ;
2236 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2240 MacRepositionScrollBars() ;
2243 // Does a physical scroll
2244 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2246 if( dx
== 0 && dy
==0 )
2252 int width
, height
;
2253 GetClientSize( &width
, &height
) ;
2254 #if TARGET_API_MAC_OSX
2255 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2256 // area is scrolled, this does not occur if width and height are 2 pixels less,
2257 // TODO write optimal workaround
2258 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width
, MacGetTopBorderSize() + height
) ;
2261 scrollrect
.Intersect( *rect
) ;
2263 if ( m_peer
->GetNeedsDisplay() )
2265 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2266 // either immediate redraw or full invalidate
2268 // is the better overall solution, as it does not slow down scrolling
2269 m_peer
->SetNeedsDisplay( true ) ;
2271 // this would be the preferred version for fast drawing controls
2272 if( UMAGetSystemVersion() < 0x1030 )
2275 HIViewRender(*m_peer
) ;
2278 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2285 RgnHandle updateRgn
= NewRgn() ;
2288 wxClientDC
dc(this) ;
2289 wxMacPortSetter
helper(&dc
) ;
2291 m_peer
->GetRect( &scrollrect
) ;
2292 scrollrect
.top
+= MacGetTopBorderSize() ;
2293 scrollrect
.left
+= MacGetLeftBorderSize() ;
2294 scrollrect
.bottom
= scrollrect
.top
+ height
;
2295 scrollrect
.right
= scrollrect
.left
+ width
;
2299 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2300 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2301 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2303 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2305 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2309 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2311 wxWindowMac
*child
= node
->GetData();
2312 if (child
== m_vScrollBar
) continue;
2313 if (child
== m_hScrollBar
) continue;
2314 if (child
->IsTopLevel()) continue;
2317 child
->GetPosition( &x
, &y
);
2319 child
->GetSize( &w
, &h
);
2323 if (rect
->Intersects(rc
))
2324 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2328 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2333 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2335 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2337 wxScrollWinEvent wevent
;
2338 wevent
.SetPosition(event
.GetPosition());
2339 wevent
.SetOrientation(event
.GetOrientation());
2340 wevent
.m_eventObject
= this;
2342 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2343 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2344 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2345 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2346 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2347 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2348 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2349 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2350 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2351 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2352 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2353 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2354 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2355 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2356 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2357 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2359 GetEventHandler()->ProcessEvent(wevent
);
2363 // Get the window with the focus
2364 wxWindowMac
*wxWindowBase::FindFocus()
2366 ControlRef control
;
2367 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2368 return wxFindControlFromMacControl( control
) ;
2371 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2373 // panel wants to track the window which was the last to have focus in it,
2374 // so we want to set ourselves as the window which last had focus
2376 // notice that it's also important to do it upwards the tree becaus
2377 // otherwise when the top level panel gets focus, it won't set it back to
2378 // us, but to some other sibling
2380 // CS:don't know if this is still needed:
2381 //wxChildFocusEvent eventFocus(this);
2382 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2384 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2386 wxMacWindowStateSaver
sv( this ) ;
2387 // wxWindowDC dc(this) ;
2388 // wxMacPortSetter helper(&dc) ;
2393 MacWindowToRootWindow( &x
, &y
) ;
2394 GetSize( &w
, &h
) ;
2395 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2397 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2398 DrawThemeFocusRect( &rect
, true ) ;
2400 DrawThemeFocusRect( &rect
, false ) ;
2406 void wxWindowMac::OnInternalIdle()
2408 // This calls the UI-update mechanism (querying windows for
2409 // menu/toolbar/control state information)
2410 if (wxUpdateUIEvent::CanUpdate(this))
2411 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2414 // Raise the window to the top of the Z order
2415 void wxWindowMac::Raise()
2417 m_peer
->SetZOrder( true , NULL
) ;
2420 // Lower the window to the bottom of the Z order
2421 void wxWindowMac::Lower()
2423 m_peer
->SetZOrder( false , NULL
) ;
2427 // static wxWindow *gs_lastWhich = NULL;
2429 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2431 // first trigger a set cursor event
2433 wxPoint clientorigin
= GetClientAreaOrigin() ;
2434 wxSize clientsize
= GetClientSize() ;
2436 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2438 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2440 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2441 if ( processedEvtSetCursor
&& event
.HasCursor() )
2443 cursor
= event
.GetCursor() ;
2448 // the test for processedEvtSetCursor is here to prevent using m_cursor
2449 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2450 // it - this is a way to say that our cursor shouldn't be used for this
2452 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2462 cursor
= *wxSTANDARD_CURSOR
;
2466 cursor
.MacInstall() ;
2468 return cursor
.Ok() ;
2471 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2475 return m_tooltip
->GetTip() ;
2477 return wxEmptyString
;
2480 void wxWindowMac::Update()
2482 #if TARGET_API_MAC_OSX
2483 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2484 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2485 // for composited windows this also triggers a redraw of all
2486 // invalid views in the window
2487 if( UMAGetSystemVersion() >= 0x1030 )
2488 HIWindowFlush(window
) ;
2492 // the only way to trigger the redrawing on earlier systems is to call
2495 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2496 UInt32 currentEventClass
= 0 ;
2497 UInt32 currentEventKind
= 0 ;
2498 if ( currentEvent
!= NULL
)
2500 currentEventClass
= ::GetEventClass( currentEvent
) ;
2501 currentEventKind
= ::GetEventKind( currentEvent
) ;
2503 if ( currentEventClass
!= kEventClassMenu
)
2505 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2508 OSStatus status
= noErr
;
2509 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2512 m_peer
->SetNeedsDisplay( true ) ;
2515 ::Draw1Control( m_peer
->GetControlRef() ) ;
2519 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2521 wxTopLevelWindowMac
* win
= NULL
;
2522 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2525 win
= wxFindWinFromMacWindow( window
) ;
2529 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2533 RgnHandle visRgn
= NewRgn() ;
2534 RgnHandle tempRgn
= NewRgn() ;
2535 if ( m_peer
->IsVisible())
2537 m_peer
->GetRect( &r
) ;
2538 r
.left
-= MacGetLeftBorderSize() ;
2539 r
.top
-= MacGetTopBorderSize() ;
2540 r
.bottom
+= MacGetBottomBorderSize() ;
2541 r
.right
+= MacGetRightBorderSize() ;
2543 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2545 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2546 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2555 if ( includeOuterStructures
)
2556 InsetRect( &r
, -3 , -3 ) ;
2557 RectRgn( visRgn
, &r
) ;
2558 if ( !IsTopLevel() )
2560 wxWindow
* child
= this ;
2561 wxWindow
* parent
= child
->GetParent() ;
2566 // we have to find a better clipping algorithm here, in order not to clip things
2567 // positioned like status and toolbar
2568 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2570 size
= parent
->GetSize() ;
2575 size
= parent
->GetClientSize() ;
2576 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2580 parent
->MacWindowToRootWindow( &x
, &y
) ;
2581 MacRootWindowToWindow( &x
, &y
) ;
2583 SetRectRgn( tempRgn
,
2584 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2585 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2586 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2588 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2589 if ( parent
->IsTopLevel() )
2592 parent
= child
->GetParent() ;
2597 wxRegion vis
= visRgn
;
2598 DisposeRgn( visRgn
) ;
2599 DisposeRgn( tempRgn
) ;
2604 This function must not change the updatergn !
2606 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2608 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2609 bool handled
= false ;
2611 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2613 RgnHandle newupdate
= NewRgn() ;
2614 wxSize point
= GetClientSize() ;
2615 wxPoint origin
= GetClientAreaOrigin() ;
2616 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2617 SectRgn( newupdate
, updatergn
, newupdate
) ;
2618 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2619 m_updateRegion
= newupdate
;
2620 DisposeRgn( newupdate
) ;
2623 if ( !EmptyRgn(updatergn
) )
2625 wxWindowDC
dc(this);
2626 if (!EmptyRgn(updatergn
))
2627 dc
.SetClippingRegion(wxRegion(updatergn
));
2629 wxEraseEvent
eevent( GetId(), &dc
);
2630 eevent
.SetEventObject( this );
2631 GetEventHandler()->ProcessEvent( eevent
);
2633 if ( !m_updateRegion
.Empty() )
2635 // paint the window itself
2637 event
.m_timeStamp
= time
;
2638 event
.SetEventObject(this);
2639 handled
= GetEventHandler()->ProcessEvent(event
);
2641 // paint custom borders
2642 wxNcPaintEvent
eventNc( GetId() );
2643 eventNc
.SetEventObject( this );
2644 GetEventHandler()->ProcessEvent( eventNc
);
2650 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2652 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2653 // updatergn is always already clipped to our boundaries
2654 // if we are in compositing mode then it is in relative to the upper left of the control
2655 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2656 // of the toplevel window
2657 // it is in window coordinates, not in client coordinates
2659 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2660 RgnHandle ownUpdateRgn
= NewRgn() ;
2661 CopyRgn( updatergn
, ownUpdateRgn
) ;
2663 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2666 m_peer
->GetRectInWindowCoords( &bounds
);
2667 RgnHandle controlRgn
= NewRgn();
2668 RectRgn( controlRgn
, &bounds
);
2669 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2670 // the window update region
2671 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2672 DisposeRgn( controlRgn
);
2674 //KO: convert ownUpdateRgn to local coordinates
2675 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2678 MacDoRedraw( ownUpdateRgn
, time
) ;
2679 DisposeRgn( ownUpdateRgn
) ;
2683 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2685 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2689 if ( iter
->IsTopLevel() )
2690 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2692 iter
= iter
->GetParent() ;
2694 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2698 void wxWindowMac::MacCreateScrollBars( long style
)
2700 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2702 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2703 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2705 GetClientSize( &width
, &height
) ;
2707 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2708 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2709 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2710 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2712 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2713 vSize
, wxVERTICAL
);
2715 if ( style
& wxVSCROLL
)
2721 m_vScrollBar
->Show(false) ;
2723 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2724 hSize
, wxHORIZONTAL
);
2725 if ( style
& wxHSCROLL
)
2730 m_hScrollBar
->Show(false) ;
2733 // because the create does not take into account the client area origin
2734 MacRepositionScrollBars() ; // we might have a real position shift
2737 void wxWindowMac::MacRepositionScrollBars()
2739 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2740 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2742 // get real client area
2746 GetSize( &width
, &height
) ;
2748 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2749 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2751 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2752 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2753 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2754 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2760 GetSize( &w
, &h
) ;
2762 MacClientToRootWindow( &x
, &y
) ;
2763 MacClientToRootWindow( &w
, &h
) ;
2765 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2767 int totW
= 10000 , totH
= 10000;
2770 if ( iter
->IsTopLevel() )
2772 iter
->GetSize( &totW
, &totH
) ;
2776 iter
= iter
->GetParent() ;
2804 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2808 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2812 bool wxWindowMac::AcceptsFocus() const
2814 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2817 void wxWindowMac::MacSuperChangedPosition()
2819 // only window-absolute structures have to be moved i.e. controls
2821 wxWindowListNode
*node
= GetChildren().GetFirst();
2824 wxWindowMac
*child
= node
->GetData();
2825 child
->MacSuperChangedPosition() ;
2826 node
= node
->GetNext();
2830 void wxWindowMac::MacTopLevelWindowChangedPosition()
2832 // only screen-absolute structures have to be moved i.e. glcanvas
2834 wxWindowListNode
*node
= GetChildren().GetFirst();
2837 wxWindowMac
*child
= node
->GetData();
2838 child
->MacTopLevelWindowChangedPosition() ;
2839 node
= node
->GetNext();
2843 long wxWindowMac::MacGetLeftBorderSize( ) const
2848 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2851 #if 0 // wxMAC_USE_THEME_BORDER
2852 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2856 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2859 #if 0 // wxMAC_USE_THEME_BORDER
2860 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2864 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2871 long wxWindowMac::MacGetRightBorderSize( ) const
2873 // they are all symmetric in mac themes
2874 return MacGetLeftBorderSize() ;
2877 long wxWindowMac::MacGetTopBorderSize( ) const
2879 // they are all symmetric in mac themes
2880 return MacGetLeftBorderSize() ;
2883 long wxWindowMac::MacGetBottomBorderSize( ) const
2885 // they are all symmetric in mac themes
2886 return MacGetLeftBorderSize() ;
2889 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2891 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2894 // Find the wxWindowMac at the current mouse position, returning the mouse
2896 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2898 pt
= wxGetMousePosition();
2899 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2903 // Get the current mouse position.
2904 wxPoint
wxGetMousePosition()
2907 wxGetMousePosition(& x
, & y
);
2908 return wxPoint(x
, y
);
2911 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2913 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2915 // copied from wxGTK : CS
2916 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2919 // (a) it's a command event and so is propagated to the parent
2920 // (b) under MSW it can be generated from kbd too
2921 // (c) it uses screen coords (because of (a))
2922 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2924 this->ClientToScreen(event
.GetPosition()));
2925 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2934 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2938 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2942 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2943 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2947 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2949 return eventNotHandledErr
;