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
) ;
895 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
897 m_macBackgroundBrush
= brush
;
898 m_peer
->SetBackground( brush
) ;
901 bool wxWindowMac::MacCanFocus() const
903 // there is currently no way to determine whether the window is running in full keyboard
904 // access mode, therefore we cannot rely on these features, yet the only other way would be
905 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
906 // in event handlers...
907 UInt32 features
= 0 ;
908 m_peer
->GetFeatures( & features
) ;
909 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
913 void wxWindowMac::SetFocus()
915 if ( AcceptsFocus() )
917 #if !TARGET_API_MAC_OSX
918 wxWindow
* former
= FindFocus() ;
920 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
921 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
922 // leave in case of an error
923 if ( err
== errCouldntSetFocus
)
926 #if !TARGET_API_MAC_OSX
927 // emulate carbon events when running under carbonlib where they are not natively available
930 EventRef evRef
= NULL
;
931 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
934 wxMacCarbonEvent
cEvent( evRef
) ;
935 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
936 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
938 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
939 ReleaseEvent(evRef
) ;
941 // send new focus event
943 EventRef evRef
= NULL
;
944 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
947 wxMacCarbonEvent
cEvent( evRef
) ;
948 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
949 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
951 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
952 ReleaseEvent(evRef
) ;
959 void wxWindowMac::DoCaptureMouse()
961 wxTheApp
->s_captureWindow
= this ;
964 wxWindow
* wxWindowBase::GetCapture()
966 return wxTheApp
->s_captureWindow
;
969 void wxWindowMac::DoReleaseMouse()
971 wxTheApp
->s_captureWindow
= NULL
;
974 #if wxUSE_DRAG_AND_DROP
976 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
978 if ( m_dropTarget
!= 0 ) {
982 m_dropTarget
= pDropTarget
;
983 if ( m_dropTarget
!= 0 )
991 // Old style file-manager drag&drop
992 void wxWindowMac::DragAcceptFiles(bool accept
)
997 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
998 int& w
, int& h
) const
1001 m_peer
->GetRect( &bounds
) ;
1006 w
= bounds
.right
- bounds
.left
;
1007 h
= bounds
.bottom
- bounds
.top
;
1009 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1012 Point tlworigin
= { 0 , 0 } ;
1013 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1019 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1022 int& w
, int& h
, bool adjustOrigin
) const
1024 // the desired size, minus the border pixels gives the correct size of the control
1028 // todo the default calls may be used as soon as PostCreateControl Is moved here
1029 w
= size
.x
; // WidthDefault( size.x );
1030 h
= size
.y
; // HeightDefault( size.y ) ;
1031 #if !TARGET_API_MAC_OSX
1032 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1035 x
+= MacGetLeftBorderSize() ;
1036 y
+= MacGetTopBorderSize() ;
1037 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1038 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1041 AdjustForParentClientOrigin( x
, y
) ;
1046 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1048 // take the size of the control and add the borders that have to be drawn outside
1049 int x1
, y1
, w1
,h1
;
1050 #if TARGET_API_MAC_OSX
1051 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1055 m_peer
->GetRect( &bounds
) ;
1056 w1
= bounds
.right
- bounds
.left
;
1057 h1
= bounds
.bottom
- bounds
.top
;
1059 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1060 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1066 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1068 #if TARGET_API_MAC_OSX
1069 int x1
, y1
, w1
,h1
;
1070 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1071 x1
-= MacGetLeftBorderSize() ;
1072 y1
-= MacGetTopBorderSize() ;
1073 if ( !IsTopLevel() )
1075 wxWindow
*parent
= GetParent();
1078 wxPoint
pt(parent
->GetClientAreaOrigin());
1087 m_peer
->GetRect( &bounds
) ;
1088 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1090 int xx
= bounds
.left
;
1091 int yy
= bounds
.top
;
1092 xx
-= MacGetLeftBorderSize() ;
1093 yy
-= MacGetTopBorderSize() ;
1095 if ( !GetParent()->IsTopLevel() )
1097 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1103 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1112 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1114 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1116 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1119 Point localwhere
= {0,0} ;
1121 if(x
) localwhere
.h
= * x
;
1122 if(y
) localwhere
.v
= * y
;
1124 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1125 if(x
) *x
= localwhere
.h
;
1126 if(y
) *y
= localwhere
.v
;
1129 MacRootWindowToWindow( x
, y
) ;
1131 wxPoint origin
= GetClientAreaOrigin() ;
1132 if(x
) *x
-= origin
.x
;
1133 if(y
) *y
-= origin
.y
;
1136 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1138 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1139 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1141 wxPoint origin
= GetClientAreaOrigin() ;
1142 if(x
) *x
+= origin
.x
;
1143 if(y
) *y
+= origin
.y
;
1145 MacWindowToRootWindow( x
, y
) ;
1148 Point localwhere
= { 0,0 };
1149 if(x
) localwhere
.h
= * x
;
1150 if(y
) localwhere
.v
= * y
;
1151 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1152 if(x
) *x
= localwhere
.h
;
1153 if(y
) *y
= localwhere
.v
;
1157 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1159 wxPoint origin
= GetClientAreaOrigin() ;
1160 if(x
) *x
+= origin
.x
;
1161 if(y
) *y
+= origin
.y
;
1163 MacWindowToRootWindow( x
, y
) ;
1166 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1168 MacRootWindowToWindow( x
, y
) ;
1170 wxPoint origin
= GetClientAreaOrigin() ;
1171 if(x
) *x
-= origin
.x
;
1172 if(y
) *y
-= origin
.y
;
1175 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1177 #if TARGET_API_MAC_OSX
1179 if ( x
) pt
.x
= *x
;
1180 if ( y
) pt
.y
= *y
;
1182 if ( !IsTopLevel() )
1184 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1187 pt
.x
-= MacGetLeftBorderSize() ;
1188 pt
.y
-= MacGetTopBorderSize() ;
1189 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1193 if ( x
) *x
= (int) pt
.x
;
1194 if ( y
) *y
= (int) pt
.y
;
1196 if ( !IsTopLevel() )
1199 m_peer
->GetRect( &bounds
) ;
1200 if(x
) *x
+= bounds
.left
;
1201 if(y
) *y
+= bounds
.top
;
1206 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1211 MacWindowToRootWindow( &x1
, &y1
) ;
1216 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1218 #if TARGET_API_MAC_OSX
1220 if ( x
) pt
.x
= *x
;
1221 if ( y
) pt
.y
= *y
;
1223 if ( !IsTopLevel() )
1225 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1226 pt
.x
+= MacGetLeftBorderSize() ;
1227 pt
.y
+= MacGetTopBorderSize() ;
1230 if ( x
) *x
= (int) pt
.x
;
1231 if ( y
) *y
= (int) pt
.y
;
1233 if ( !IsTopLevel() )
1236 m_peer
->GetRect( &bounds
) ;
1237 if(x
) *x
-= bounds
.left
;
1238 if(y
) *y
-= bounds
.top
;
1243 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1248 MacRootWindowToWindow( &x1
, &y1
) ;
1253 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1255 RgnHandle rgn
= NewRgn() ;
1257 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1259 GetRegionBounds( rgn
, &content
) ;
1264 m_peer
->GetRect( &content
) ;
1267 m_peer
->GetRect( &structure
) ;
1268 #if !TARGET_API_MAC_OSX
1269 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1271 left
= content
.left
- structure
.left
;
1272 top
= content
.top
- structure
.top
;
1273 right
= structure
.right
- content
.right
;
1274 bottom
= structure
.bottom
- content
.bottom
;
1277 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1279 wxSize sizeTotal
= size
;
1281 RgnHandle rgn
= NewRgn() ;
1285 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1287 GetRegionBounds( rgn
, &content
) ;
1292 m_peer
->GetRect( &content
) ;
1295 m_peer
->GetRect( &structure
) ;
1296 #if !TARGET_API_MAC_OSX
1297 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1300 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1301 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1303 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1304 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1310 // Get size *available for subwindows* i.e. excluding menu bar etc.
1311 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1315 RgnHandle rgn
= NewRgn() ;
1317 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1319 GetRegionBounds( rgn
, &content
) ;
1324 m_peer
->GetRect( &content
) ;
1326 #if !TARGET_API_MAC_OSX
1328 m_peer
->GetRect( &structure
) ;
1329 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1331 ww
= content
.right
- content
.left
;
1332 hh
= content
.bottom
- content
.top
;
1334 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1335 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1337 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1343 GetSize( &w
, &h
) ;
1345 MacClientToRootWindow( &x1
, &y1
) ;
1346 MacClientToRootWindow( &w
, &h
) ;
1348 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1350 int totW
= 10000 , totH
= 10000;
1353 if ( iter
->IsTopLevel() )
1355 iter
->GetSize( &totW
, &totH
) ;
1359 iter
= iter
->GetParent() ;
1362 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1364 hh
-= MAC_SCROLLBAR_SIZE
;
1370 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1372 ww
-= MAC_SCROLLBAR_SIZE
;
1384 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1386 if (m_cursor
== cursor
)
1389 if (wxNullCursor
== cursor
)
1391 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1396 if ( ! wxWindowBase::SetCursor( cursor
) )
1400 wxASSERT_MSG( m_cursor
.Ok(),
1401 wxT("cursor must be valid after call to the base version"));
1404 wxWindowMac
*mouseWin
= 0 ;
1406 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1408 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1410 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1411 // position, use it...
1415 ControlPartCode part
;
1416 ControlRef control
;
1417 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1419 mouseWin
= wxFindControlFromMacControl( control
) ;
1422 QDSwapPort( savePort
, NULL
) ;
1425 if ( mouseWin
== this && !wxIsBusy() )
1427 m_cursor
.MacInstall() ;
1434 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1436 menu
->SetInvokingWindow(this);
1439 if ( x
== -1 && y
== -1 )
1441 wxPoint mouse
= wxGetMousePosition();
1442 x
= mouse
.x
; y
= mouse
.y
;
1446 ClientToScreen( &x
, &y
) ;
1449 menu
->MacBeforeDisplay( true ) ;
1450 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1451 if ( HiWord(menuResult
) != 0 )
1454 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1455 wxMenuItem
* item
= NULL
;
1457 item
= menu
->FindItem(id
, &realmenu
) ;
1458 if (item
->IsCheckable())
1460 item
->Check( !item
->IsChecked() ) ;
1462 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1464 menu
->MacAfterDisplay( true ) ;
1466 menu
->SetInvokingWindow(NULL
);
1472 // ----------------------------------------------------------------------------
1474 // ----------------------------------------------------------------------------
1478 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1480 wxWindowBase::DoSetToolTip(tooltip
);
1483 m_tooltip
->SetWindow(this);
1486 #endif // wxUSE_TOOLTIPS
1488 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1490 int former_x
, former_y
, former_w
, former_h
;
1491 #if !TARGET_API_MAC_OSX
1492 DoGetPosition( &former_x
, &former_y
) ;
1493 DoGetSize( &former_w
, &former_h
) ;
1495 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1496 former_x
-= MacGetLeftBorderSize() ;
1497 former_y
-= MacGetTopBorderSize() ;
1498 former_w
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1499 former_h
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1502 int actualWidth
= width
;
1503 int actualHeight
= height
;
1507 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1508 actualWidth
= m_minWidth
;
1509 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1510 actualHeight
= m_minHeight
;
1511 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1512 actualWidth
= m_maxWidth
;
1513 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1514 actualHeight
= m_maxHeight
;
1516 bool doMove
= false ;
1517 bool doResize
= false ;
1519 if ( actualX
!= former_x
|| actualY
!= former_y
)
1523 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1528 if ( doMove
|| doResize
)
1530 // we don't adjust twice for the origin
1531 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1532 bool vis
= m_peer
->IsVisible();
1534 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1536 m_peer
->SetVisibility( false , true ) ;
1537 m_peer
->SetRect( &r
) ;
1539 m_peer
->SetVisibility( true , true ) ;
1541 MacRepositionScrollBars() ;
1544 wxPoint
point(actualX
,actualY
);
1545 wxMoveEvent
event(point
, m_windowId
);
1546 event
.SetEventObject(this);
1547 GetEventHandler()->ProcessEvent(event
) ;
1551 MacRepositionScrollBars() ;
1552 wxSize
size(actualWidth
, actualHeight
);
1553 wxSizeEvent
event(size
, m_windowId
);
1554 event
.SetEventObject(this);
1555 GetEventHandler()->ProcessEvent(event
);
1561 wxSize
wxWindowMac::DoGetBestSize() const
1563 if ( m_macIsUserPane
|| IsTopLevel() )
1564 return wxWindowBase::DoGetBestSize() ;
1566 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1567 int bestWidth
, bestHeight
;
1568 m_peer
->GetBestRect( &bestsize
) ;
1570 if ( EmptyRect( &bestsize
) )
1572 bestsize
.left
= bestsize
.top
= 0 ;
1573 bestsize
.right
= 16 ;
1574 bestsize
.bottom
= 16 ;
1575 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1577 bestsize
.bottom
= 16 ;
1579 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1581 bestsize
.bottom
= 24 ;
1585 // return wxWindowBase::DoGetBestSize() ;
1589 bestWidth
= bestsize
.right
- bestsize
.left
;
1590 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1591 if ( bestHeight
< 10 )
1594 return wxSize(bestWidth
, bestHeight
);
1598 // set the size of the window: if the dimensions are positive, just use them,
1599 // but if any of them is equal to -1, it means that we must find the value for
1600 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1601 // which case -1 is a valid value for x and y)
1603 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1604 // the width/height to best suit our contents, otherwise we reuse the current
1606 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1608 // get the current size and position...
1609 int currentX
, currentY
;
1610 GetPosition(¤tX
, ¤tY
);
1612 int currentW
,currentH
;
1613 GetSize(¤tW
, ¤tH
);
1615 // ... and don't do anything (avoiding flicker) if it's already ok
1616 if ( x
== currentX
&& y
== currentY
&&
1617 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1620 MacRepositionScrollBars() ; // we might have a real position shift
1624 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1626 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1629 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1631 wxSize
size(-1, -1);
1634 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1636 size
= DoGetBestSize();
1641 // just take the current one
1648 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1652 size
= DoGetBestSize();
1654 //else: already called DoGetBestSize() above
1660 // just take the current one
1665 DoMoveWindow(x
, y
, width
, height
);
1669 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1671 RgnHandle rgn
= NewRgn() ;
1673 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1674 GetRegionBounds( rgn
, &content
) ;
1676 #if !TARGET_API_MAC_OSX
1677 // if the content rgn is empty / not supported
1678 // don't attempt to correct the coordinates to wxWindow relative ones
1679 if (!::EmptyRect( &content
) )
1682 m_peer
->GetRect( &structure
) ;
1683 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1687 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1690 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1692 if ( clientheight
!= -1 || clientheight
!= -1 )
1694 int currentclientwidth
, currentclientheight
;
1695 int currentwidth
, currentheight
;
1697 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1698 GetSize( ¤twidth
, ¤theight
) ;
1700 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1701 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1705 void wxWindowMac::SetTitle(const wxString
& title
)
1707 m_label
= wxStripMenuCodes(title
) ;
1709 if ( m_peer
&& m_peer
->Ok() )
1711 m_peer
->SetTitle( m_label
) ;
1716 wxString
wxWindowMac::GetTitle() const
1721 bool wxWindowMac::Show(bool show
)
1723 if ( !wxWindowBase::Show(show
) )
1726 // TODO use visibilityChanged Carbon Event for OSX
1727 bool former
= MacIsReallyShown() ;
1729 m_peer
->SetVisibility( show
, true ) ;
1730 if ( former
!= MacIsReallyShown() )
1731 MacPropagateVisibilityChanged() ;
1735 bool wxWindowMac::Enable(bool enable
)
1737 wxASSERT( m_peer
->Ok() ) ;
1738 if ( !wxWindowBase::Enable(enable
) )
1741 bool former
= MacIsReallyEnabled() ;
1742 m_peer
->Enable( enable
) ;
1744 if ( former
!= MacIsReallyEnabled() )
1745 MacPropagateEnabledStateChanged() ;
1750 // status change propagations (will be not necessary for OSX later )
1753 void wxWindowMac::MacPropagateVisibilityChanged()
1755 #if !TARGET_API_MAC_OSX
1756 MacVisibilityChanged() ;
1758 wxWindowListNode
*node
= GetChildren().GetFirst();
1761 wxWindowMac
*child
= node
->GetData();
1762 if ( child
->IsShown() )
1763 child
->MacPropagateVisibilityChanged( ) ;
1764 node
= node
->GetNext();
1769 void wxWindowMac::MacPropagateEnabledStateChanged( )
1771 #if !TARGET_API_MAC_OSX
1772 MacEnabledStateChanged() ;
1774 wxWindowListNode
*node
= GetChildren().GetFirst();
1777 wxWindowMac
*child
= node
->GetData();
1778 if ( child
->IsEnabled() )
1779 child
->MacPropagateEnabledStateChanged() ;
1780 node
= node
->GetNext();
1785 void wxWindowMac::MacPropagateHiliteChanged( )
1787 #if !TARGET_API_MAC_OSX
1788 MacHiliteChanged() ;
1790 wxWindowListNode
*node
= GetChildren().GetFirst();
1793 wxWindowMac
*child
= node
->GetData();
1794 // if ( child->IsEnabled() )
1795 child
->MacPropagateHiliteChanged() ;
1796 node
= node
->GetNext();
1802 // status change notifications
1805 void wxWindowMac::MacVisibilityChanged()
1809 void wxWindowMac::MacHiliteChanged()
1813 void wxWindowMac::MacEnabledStateChanged()
1818 // status queries on the inherited window's state
1821 bool wxWindowMac::MacIsReallyShown()
1823 // only under OSX the visibility of the TLW is taken into account
1824 #if TARGET_API_MAC_OSX
1825 if ( m_peer
&& m_peer
->Ok() )
1826 return m_peer
->IsVisible();
1828 wxWindow
* win
= this ;
1829 while( win
->IsShown() )
1831 if ( win
->IsTopLevel() )
1834 win
= win
->GetParent() ;
1842 bool wxWindowMac::MacIsReallyEnabled()
1844 return m_peer
->IsEnabled() ;
1847 bool wxWindowMac::MacIsReallyHilited()
1849 return m_peer
->IsActive();
1852 void wxWindowMac::MacFlashInvalidAreas()
1854 #if TARGET_API_MAC_OSX
1855 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1863 int wxWindowMac::GetCharHeight() const
1865 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1866 return dc
.GetCharHeight() ;
1869 int wxWindowMac::GetCharWidth() const
1871 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1872 return dc
.GetCharWidth() ;
1875 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1876 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1878 const wxFont
*fontToUse
= theFont
;
1880 fontToUse
= &m_font
;
1882 wxClientDC
dc( (wxWindowMac
*) this ) ;
1884 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1885 if ( externalLeading
)
1886 *externalLeading
= le
;
1896 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1897 * we always intersect with the entire window, not only with the client area
1900 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1902 if ( m_peer
== NULL
)
1905 #if TARGET_API_MAC_OSX
1907 m_peer
->SetNeedsDisplay( true ) ;
1910 RgnHandle update
= NewRgn() ;
1911 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1912 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1913 wxPoint origin
= GetClientAreaOrigin() ;
1914 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1915 m_peer
->SetNeedsDisplay( true , update
) ;
1919 RgnHandle updateRgn = NewRgn() ;
1922 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1926 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1927 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1929 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1930 DisposeRgn(updateRgn) ;
1932 if ( m_peer
->IsVisible())
1934 m_peer
->SetVisibility( false , false ) ;
1935 m_peer
->SetVisibility( true , true ) ;
1938 if ( MacGetTopLevelWindow() == NULL )
1941 if ( !m_peer->IsVisible())
1944 wxPoint client = GetClientAreaOrigin();
1947 int x2 = m_width - client.x;
1948 int y2 = m_height - client.y;
1950 if (IsKindOf( CLASSINFO(wxButton)))
1952 // buttons have an "aura"
1959 Rect clientrect = { y1, x1, y2, x2 };
1963 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1964 SectRect( &clientrect , &r , &clientrect ) ;
1967 if ( !EmptyRect( &clientrect ) )
1969 int top = 0 , left = 0 ;
1971 MacClientToRootWindow( &left , &top ) ;
1972 OffsetRect( &clientrect , left , top ) ;
1974 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1980 void wxWindowMac::Freeze()
1982 #if TARGET_API_MAC_OSX
1983 if ( !m_frozenness
++ )
1985 m_peer
->SetDrawingEnabled( false ) ;
1991 void wxWindowMac::Thaw()
1993 #if TARGET_API_MAC_OSX
1994 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1996 if ( !--m_frozenness
)
1998 m_peer
->SetDrawingEnabled( true ) ;
1999 m_peer
->InvalidateWithChildren() ;
2004 void wxWindowMac::MacRedrawControl()
2007 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2009 #if TARGET_API_MAC_CARBON
2012 wxClientDC dc(this) ;
2013 wxMacPortSetter helper(&dc) ;
2014 wxMacWindowClipper clipper(this) ;
2015 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2016 UMADrawControl( *m_peer ) ;
2023 void wxWindowMac::OnPaint(wxPaintEvent& event)
2025 // why don't we skip that here ?
2029 wxWindowMac
*wxGetActiveWindow()
2031 // actually this is a windows-only concept
2035 // Coordinates relative to the window
2036 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2038 // We really don't move the mouse programmatically under Mac.
2041 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2043 #if TARGET_API_MAC_OSX
2044 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2050 event
.GetDC()->Clear() ;
2053 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2055 wxWindowDC
dc(this) ;
2056 wxMacPortSetter
helper(&dc
) ;
2058 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2061 int wxWindowMac::GetScrollPos(int orient
) const
2063 if ( orient
== wxHORIZONTAL
)
2066 return m_hScrollBar
->GetThumbPosition() ;
2071 return m_vScrollBar
->GetThumbPosition() ;
2076 // This now returns the whole range, not just the number
2077 // of positions that we can scroll.
2078 int wxWindowMac::GetScrollRange(int orient
) const
2080 if ( orient
== wxHORIZONTAL
)
2083 return m_hScrollBar
->GetRange() ;
2088 return m_vScrollBar
->GetRange() ;
2093 int wxWindowMac::GetScrollThumb(int orient
) const
2095 if ( orient
== wxHORIZONTAL
)
2098 return m_hScrollBar
->GetThumbSize() ;
2103 return m_vScrollBar
->GetThumbSize() ;
2108 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2110 if ( orient
== wxHORIZONTAL
)
2113 m_hScrollBar
->SetThumbPosition( pos
) ;
2118 m_vScrollBar
->SetThumbPosition( pos
) ;
2122 void wxWindowMac::MacPaintBorders( int left
, int top
)
2128 wxGetOsVersion( &major
, &minor
);
2130 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2131 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2132 // OS X has lighter border edges than classic:
2135 darkShadow
.red
= 0x8E8E;
2136 darkShadow
.green
= 0x8E8E;
2137 darkShadow
.blue
= 0x8E8E;
2138 lightShadow
.red
= 0xBDBD;
2139 lightShadow
.green
= 0xBDBD;
2140 lightShadow
.blue
= 0xBDBD;
2146 GetSize( &w
, &h
) ;
2147 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2148 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2150 #if wxMAC_USE_THEME_BORDER
2152 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2153 InsetRect( &rect
, border
, border
);
2154 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2156 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2157 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2159 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2160 RGBForeColor( &face
);
2161 MoveTo( left
+ 0 , top
+ h
- 2 );
2162 LineTo( left
+ 0 , top
+ 0 );
2163 LineTo( left
+ w
- 2 , top
+ 0 );
2165 MoveTo( left
+ 2 , top
+ h
- 3 );
2166 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2167 LineTo( left
+ w
- 3 , top
+ 2 );
2169 RGBForeColor( sunken
? &face
: &darkShadow
);
2170 MoveTo( left
+ 0 , top
+ h
- 1 );
2171 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2172 LineTo( left
+ w
- 1 , top
+ 0 );
2174 RGBForeColor( sunken
? &lightShadow
: &white
);
2175 MoveTo( left
+ 1 , top
+ h
- 3 );
2176 LineTo( left
+ 1, top
+ 1 );
2177 LineTo( left
+ w
- 3 , top
+ 1 );
2179 RGBForeColor( sunken
? &white
: &lightShadow
);
2180 MoveTo( left
+ 1 , top
+ h
- 2 );
2181 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2182 LineTo( left
+ w
- 2 , top
+ 1 );
2184 RGBForeColor( sunken
? &darkShadow
: &face
);
2185 MoveTo( left
+ 2 , top
+ h
- 4 );
2186 LineTo( left
+ 2 , top
+ 2 );
2187 LineTo( left
+ w
- 4 , top
+ 2 );
2190 else if (HasFlag(wxSIMPLE_BORDER
))
2192 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2193 RGBForeColor( &darkShadow
) ;
2194 FrameRect( &rect
) ;
2198 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2200 if ( child
== m_hScrollBar
)
2201 m_hScrollBar
= NULL
;
2202 if ( child
== m_vScrollBar
)
2203 m_vScrollBar
= NULL
;
2205 wxWindowBase::RemoveChild( child
) ;
2208 // New function that will replace some of the above.
2209 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2210 int range
, bool refresh
)
2212 if ( orient
== wxHORIZONTAL
)
2216 if ( range
== 0 || thumbVisible
>= range
)
2218 if ( m_hScrollBar
->IsShown() )
2219 m_hScrollBar
->Show(false) ;
2223 if ( !m_hScrollBar
->IsShown() )
2224 m_hScrollBar
->Show(true) ;
2225 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2233 if ( range
== 0 || thumbVisible
>= range
)
2235 if ( m_vScrollBar
->IsShown() )
2236 m_vScrollBar
->Show(false) ;
2240 if ( !m_vScrollBar
->IsShown() )
2241 m_vScrollBar
->Show(true) ;
2242 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2246 MacRepositionScrollBars() ;
2249 // Does a physical scroll
2250 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2252 if( dx
== 0 && dy
==0 )
2258 int width
, height
;
2259 GetClientSize( &width
, &height
) ;
2260 #if TARGET_API_MAC_OSX
2261 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2262 // area is scrolled, this does not occur if width and height are 2 pixels less,
2263 // TODO write optimal workaround
2264 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width
, MacGetTopBorderSize() + height
) ;
2267 scrollrect
.Intersect( *rect
) ;
2269 if ( m_peer
->GetNeedsDisplay() )
2271 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2272 // either immediate redraw or full invalidate
2274 // is the better overall solution, as it does not slow down scrolling
2275 m_peer
->SetNeedsDisplay( true ) ;
2277 // this would be the preferred version for fast drawing controls
2278 if( UMAGetSystemVersion() < 0x1030 )
2281 HIViewRender(*m_peer
) ;
2284 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2291 RgnHandle updateRgn
= NewRgn() ;
2294 wxClientDC
dc(this) ;
2295 wxMacPortSetter
helper(&dc
) ;
2297 m_peer
->GetRect( &scrollrect
) ;
2298 scrollrect
.top
+= MacGetTopBorderSize() ;
2299 scrollrect
.left
+= MacGetLeftBorderSize() ;
2300 scrollrect
.bottom
= scrollrect
.top
+ height
;
2301 scrollrect
.right
= scrollrect
.left
+ width
;
2305 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2306 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2307 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2309 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2311 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2315 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2317 wxWindowMac
*child
= node
->GetData();
2318 if (child
== m_vScrollBar
) continue;
2319 if (child
== m_hScrollBar
) continue;
2320 if (child
->IsTopLevel()) continue;
2323 child
->GetPosition( &x
, &y
);
2325 child
->GetSize( &w
, &h
);
2329 if (rect
->Intersects(rc
))
2330 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2334 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2339 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2341 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2343 wxScrollWinEvent wevent
;
2344 wevent
.SetPosition(event
.GetPosition());
2345 wevent
.SetOrientation(event
.GetOrientation());
2346 wevent
.m_eventObject
= this;
2348 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2349 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2350 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2351 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2352 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2353 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2354 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2355 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2356 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2357 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2358 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2359 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2360 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2361 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2362 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2363 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2365 GetEventHandler()->ProcessEvent(wevent
);
2369 // Get the window with the focus
2370 wxWindowMac
*wxWindowBase::FindFocus()
2372 ControlRef control
;
2373 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2374 return wxFindControlFromMacControl( control
) ;
2377 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2379 // panel wants to track the window which was the last to have focus in it,
2380 // so we want to set ourselves as the window which last had focus
2382 // notice that it's also important to do it upwards the tree becaus
2383 // otherwise when the top level panel gets focus, it won't set it back to
2384 // us, but to some other sibling
2386 // CS:don't know if this is still needed:
2387 //wxChildFocusEvent eventFocus(this);
2388 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2390 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2392 wxMacWindowStateSaver
sv( this ) ;
2393 // wxWindowDC dc(this) ;
2394 // wxMacPortSetter helper(&dc) ;
2399 MacWindowToRootWindow( &x
, &y
) ;
2400 GetSize( &w
, &h
) ;
2401 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2403 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2404 DrawThemeFocusRect( &rect
, true ) ;
2406 DrawThemeFocusRect( &rect
, false ) ;
2412 void wxWindowMac::OnInternalIdle()
2414 // This calls the UI-update mechanism (querying windows for
2415 // menu/toolbar/control state information)
2416 if (wxUpdateUIEvent::CanUpdate(this))
2417 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2420 // Raise the window to the top of the Z order
2421 void wxWindowMac::Raise()
2423 m_peer
->SetZOrder( true , NULL
) ;
2426 // Lower the window to the bottom of the Z order
2427 void wxWindowMac::Lower()
2429 m_peer
->SetZOrder( false , NULL
) ;
2433 // static wxWindow *gs_lastWhich = NULL;
2435 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2437 // first trigger a set cursor event
2439 wxPoint clientorigin
= GetClientAreaOrigin() ;
2440 wxSize clientsize
= GetClientSize() ;
2442 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2444 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2446 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2447 if ( processedEvtSetCursor
&& event
.HasCursor() )
2449 cursor
= event
.GetCursor() ;
2454 // the test for processedEvtSetCursor is here to prevent using m_cursor
2455 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2456 // it - this is a way to say that our cursor shouldn't be used for this
2458 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2468 cursor
= *wxSTANDARD_CURSOR
;
2472 cursor
.MacInstall() ;
2474 return cursor
.Ok() ;
2477 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2481 return m_tooltip
->GetTip() ;
2483 return wxEmptyString
;
2486 void wxWindowMac::Update()
2488 #if TARGET_API_MAC_OSX
2489 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2490 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2491 // for composited windows this also triggers a redraw of all
2492 // invalid views in the window
2493 if( UMAGetSystemVersion() >= 0x1030 )
2494 HIWindowFlush(window
) ;
2498 // the only way to trigger the redrawing on earlier systems is to call
2501 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2502 UInt32 currentEventClass
= 0 ;
2503 UInt32 currentEventKind
= 0 ;
2504 if ( currentEvent
!= NULL
)
2506 currentEventClass
= ::GetEventClass( currentEvent
) ;
2507 currentEventKind
= ::GetEventKind( currentEvent
) ;
2509 if ( currentEventClass
!= kEventClassMenu
)
2511 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2514 OSStatus status
= noErr
;
2515 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2518 m_peer
->SetNeedsDisplay( true ) ;
2521 ::Draw1Control( m_peer
->GetControlRef() ) ;
2525 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2527 wxTopLevelWindowMac
* win
= NULL
;
2528 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2531 win
= wxFindWinFromMacWindow( window
) ;
2535 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2539 RgnHandle visRgn
= NewRgn() ;
2540 RgnHandle tempRgn
= NewRgn() ;
2541 if ( m_peer
->IsVisible())
2543 m_peer
->GetRect( &r
) ;
2544 r
.left
-= MacGetLeftBorderSize() ;
2545 r
.top
-= MacGetTopBorderSize() ;
2546 r
.bottom
+= MacGetBottomBorderSize() ;
2547 r
.right
+= MacGetRightBorderSize() ;
2549 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2551 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2552 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2561 if ( includeOuterStructures
)
2562 InsetRect( &r
, -3 , -3 ) ;
2563 RectRgn( visRgn
, &r
) ;
2564 if ( !IsTopLevel() )
2566 wxWindow
* child
= this ;
2567 wxWindow
* parent
= child
->GetParent() ;
2572 // we have to find a better clipping algorithm here, in order not to clip things
2573 // positioned like status and toolbar
2574 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2576 size
= parent
->GetSize() ;
2581 size
= parent
->GetClientSize() ;
2582 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2586 parent
->MacWindowToRootWindow( &x
, &y
) ;
2587 MacRootWindowToWindow( &x
, &y
) ;
2589 SetRectRgn( tempRgn
,
2590 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2591 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2592 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2594 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2595 if ( parent
->IsTopLevel() )
2598 parent
= child
->GetParent() ;
2603 wxRegion vis
= visRgn
;
2604 DisposeRgn( visRgn
) ;
2605 DisposeRgn( tempRgn
) ;
2610 This function must not change the updatergn !
2612 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2614 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2615 bool handled
= false ;
2617 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2619 RgnHandle newupdate
= NewRgn() ;
2620 wxSize point
= GetClientSize() ;
2621 wxPoint origin
= GetClientAreaOrigin() ;
2622 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2623 SectRgn( newupdate
, updatergn
, newupdate
) ;
2624 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2625 m_updateRegion
= newupdate
;
2626 DisposeRgn( newupdate
) ;
2629 if ( !EmptyRgn(updatergn
) )
2631 wxWindowDC
dc(this);
2632 if (!EmptyRgn(updatergn
))
2633 dc
.SetClippingRegion(wxRegion(updatergn
));
2635 wxEraseEvent
eevent( GetId(), &dc
);
2636 eevent
.SetEventObject( this );
2637 GetEventHandler()->ProcessEvent( eevent
);
2639 if ( !m_updateRegion
.Empty() )
2641 // paint the window itself
2643 event
.m_timeStamp
= time
;
2644 event
.SetEventObject(this);
2645 handled
= GetEventHandler()->ProcessEvent(event
);
2647 // paint custom borders
2648 wxNcPaintEvent
eventNc( GetId() );
2649 eventNc
.SetEventObject( this );
2650 GetEventHandler()->ProcessEvent( eventNc
);
2656 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2658 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2659 // updatergn is always already clipped to our boundaries
2660 // if we are in compositing mode then it is in relative to the upper left of the control
2661 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2662 // of the toplevel window
2663 // it is in window coordinates, not in client coordinates
2665 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2666 RgnHandle ownUpdateRgn
= NewRgn() ;
2667 CopyRgn( updatergn
, ownUpdateRgn
) ;
2669 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2672 m_peer
->GetRectInWindowCoords( &bounds
);
2673 RgnHandle controlRgn
= NewRgn();
2674 RectRgn( controlRgn
, &bounds
);
2675 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2676 // the window update region
2677 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2678 DisposeRgn( controlRgn
);
2680 //KO: convert ownUpdateRgn to local coordinates
2681 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2684 MacDoRedraw( ownUpdateRgn
, time
) ;
2685 DisposeRgn( ownUpdateRgn
) ;
2689 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2691 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2695 if ( iter
->IsTopLevel() )
2696 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2698 iter
= iter
->GetParent() ;
2700 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2704 void wxWindowMac::MacCreateScrollBars( long style
)
2706 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2710 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2711 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2713 GetClientSize( &width
, &height
) ;
2715 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2716 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2717 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2718 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2720 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2721 vSize
, wxVERTICAL
);
2723 if ( style
& wxVSCROLL
)
2729 m_vScrollBar
->Show(false) ;
2731 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2732 hSize
, wxHORIZONTAL
);
2733 if ( style
& wxHSCROLL
)
2738 m_hScrollBar
->Show(false) ;
2741 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2743 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2744 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2746 GetClientSize( &width
, &height
) ;
2748 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2749 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2750 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2751 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2754 if ( style
& wxVSCROLL
)
2756 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2757 vSize
, wxVERTICAL
);
2760 if ( style
& wxHSCROLL
)
2762 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2763 hSize
, wxHORIZONTAL
);
2769 // because the create does not take into account the client area origin
2770 MacRepositionScrollBars() ; // we might have a real position shift
2773 void wxWindowMac::MacRepositionScrollBars()
2775 if ( !m_hScrollBar
&& !m_vScrollBar
)
2778 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2779 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2781 // get real client area
2785 GetSize( &width
, &height
) ;
2787 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2788 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2790 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2791 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2792 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2793 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2799 GetSize( &w
, &h
) ;
2801 MacClientToRootWindow( &x
, &y
) ;
2802 MacClientToRootWindow( &w
, &h
) ;
2804 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2806 int totW
= 10000 , totH
= 10000;
2809 if ( iter
->IsTopLevel() )
2811 iter
->GetSize( &totW
, &totH
) ;
2815 iter
= iter
->GetParent() ;
2843 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2847 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2851 bool wxWindowMac::AcceptsFocus() const
2853 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2856 void wxWindowMac::MacSuperChangedPosition()
2858 // only window-absolute structures have to be moved i.e. controls
2860 wxWindowListNode
*node
= GetChildren().GetFirst();
2863 wxWindowMac
*child
= node
->GetData();
2864 child
->MacSuperChangedPosition() ;
2865 node
= node
->GetNext();
2869 void wxWindowMac::MacTopLevelWindowChangedPosition()
2871 // only screen-absolute structures have to be moved i.e. glcanvas
2873 wxWindowListNode
*node
= GetChildren().GetFirst();
2876 wxWindowMac
*child
= node
->GetData();
2877 child
->MacTopLevelWindowChangedPosition() ;
2878 node
= node
->GetNext();
2882 long wxWindowMac::MacGetLeftBorderSize( ) const
2887 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2890 #if 0 // wxMAC_USE_THEME_BORDER
2891 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2895 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2898 #if 0 // wxMAC_USE_THEME_BORDER
2899 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2903 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2910 long wxWindowMac::MacGetRightBorderSize( ) const
2912 // they are all symmetric in mac themes
2913 return MacGetLeftBorderSize() ;
2916 long wxWindowMac::MacGetTopBorderSize( ) const
2918 // they are all symmetric in mac themes
2919 return MacGetLeftBorderSize() ;
2922 long wxWindowMac::MacGetBottomBorderSize( ) const
2924 // they are all symmetric in mac themes
2925 return MacGetLeftBorderSize() ;
2928 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2930 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2933 // Find the wxWindowMac at the current mouse position, returning the mouse
2935 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2937 pt
= wxGetMousePosition();
2938 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2942 // Get the current mouse position.
2943 wxPoint
wxGetMousePosition()
2946 wxGetMousePosition(& x
, & y
);
2947 return wxPoint(x
, y
);
2950 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2952 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2954 // copied from wxGTK : CS
2955 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2958 // (a) it's a command event and so is propagated to the parent
2959 // (b) under MSW it can be generated from kbd too
2960 // (c) it uses screen coords (because of (a))
2961 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2963 this->ClientToScreen(event
.GetPosition()));
2964 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2973 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2977 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2981 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2982 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2986 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2988 return eventNotHandledErr
;