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
) ;
509 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
513 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
515 // this clipping is only needed for non HIView
517 RgnHandle clip
= NewRgn() ;
520 wx
->MacWindowToRootWindow( &x
,&y
) ;
521 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
522 OffsetRgn( clip
, x
, y
) ;
529 else if ( wx->MacIsUserPane() )
531 // if we don't have a valid brush for such a control, we have to call the
532 // setup of our parent ourselves
533 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
546 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
547 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
551 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
554 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
559 // ----------------------------------------------------------------------------
560 // constructors and such
561 // ----------------------------------------------------------------------------
563 wxWindowMac::wxWindowMac()
568 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
573 const wxString
& name
)
576 Create(parent
, id
, pos
, size
, style
, name
);
579 void wxWindowMac::Init()
583 #if WXWIN_COMPATIBILITY_2_4
584 m_backgroundTransparent
= FALSE
;
587 // as all windows are created with WS_VISIBLE style...
590 m_hScrollBar
= NULL
;
591 m_vScrollBar
= NULL
;
592 m_macBackgroundBrush
= wxNullBrush
;
594 m_macIsUserPane
= TRUE
;
596 // make sure all proc ptrs are available
598 if ( gControlUserPaneDrawUPP
== NULL
)
600 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
601 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
602 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
603 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
604 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
605 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
606 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
607 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
609 if ( wxMacLiveScrollbarActionUPP
== NULL
)
611 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
614 if ( wxMacSetupControlBackgroundUPP
== NULL
)
616 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
619 // we need a valid font for the encodings
620 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
624 wxWindowMac::~wxWindowMac()
628 m_isBeingDeleted
= TRUE
;
630 #ifndef __WXUNIVERSAL__
631 // VS: make sure there's no wxFrame with last focus set to us:
632 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
634 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
637 if ( frame
->GetLastFocus() == this )
639 frame
->SetLastFocus((wxWindow
*)NULL
);
644 #endif // __WXUNIVERSAL__
646 // wxRemoveMacControlAssociation( this ) ;
647 // If we delete an item, we should initialize the parent panel,
648 // because it could now be invalid.
649 wxWindow
*parent
= GetParent() ;
652 if (parent
->GetDefaultItem() == (wxButton
*) this)
653 parent
->SetDefaultItem(NULL
);
655 if ( m_peer
&& m_peer
->Ok() )
657 // in case the callback might be called during destruction
658 wxRemoveMacControlAssociation( this) ;
659 // we currently are not using this hook
660 // ::SetControlColorProc( *m_peer , NULL ) ;
664 if ( g_MacLastWindow
== this )
666 g_MacLastWindow
= NULL
;
669 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
672 if ( frame
->GetLastFocus() == this )
673 frame
->SetLastFocus( NULL
) ;
678 // delete our drop target if we've got one
679 #if wxUSE_DRAG_AND_DROP
680 if ( m_dropTarget
!= NULL
)
685 #endif // wxUSE_DRAG_AND_DROP
689 WXWidget
wxWindowMac::GetHandle() const
691 return (WXWidget
) m_peer
->GetControlRef() ;
695 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
697 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
698 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
699 GetEventTypeCount(eventList
), eventList
, this,
700 (EventHandlerRef
*)&m_macControlEventHandler
);
705 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
709 const wxString
& name
)
711 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
713 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
716 parent
->AddChild(this);
718 m_windowVariant
= parent
->GetWindowVariant() ;
720 if ( m_macIsUserPane
)
722 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
725 | kControlSupportsEmbedding
726 // | kControlSupportsLiveFeedback
727 // | kControlHasSpecialBackground
728 // | kControlSupportsCalcBestRect
729 // | kControlHandlesTracking
730 | kControlSupportsFocus
731 // | kControlWantsActivate
732 // | kControlWantsIdle
735 m_peer
= new wxMacControl() ;
736 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
739 MacPostControlCreate(pos
,size
) ;
740 #if !TARGET_API_MAC_OSX
741 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
742 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
743 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
744 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
745 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
746 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
747 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
748 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
751 #ifndef __WXUNIVERSAL__
752 // Don't give scrollbars to wxControls unless they ask for them
753 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
754 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
756 MacCreateScrollBars( style
) ;
760 wxWindowCreateEvent
event(this);
761 GetEventHandler()->AddPendingEvent(event
);
766 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
768 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
770 m_peer
->SetReference( (long) this ) ;
772 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
774 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
775 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
776 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
778 // adjust font, controlsize etc
779 DoSetWindowVariant( m_windowVariant
) ;
781 #if !TARGET_API_MAC_OSX
782 // eventually we can fix some clipping issues be reactivating this hook
783 //if ( m_macIsUserPane )
784 // SetControlColorProc( *m_peer , wxMacSetupControlBackgroundUPP ) ;
786 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
788 if (!m_macIsUserPane
)
790 SetInitialBestSize(size
);
793 SetCursor( *wxSTANDARD_CURSOR
) ;
796 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
798 // Don't assert, in case we set the window variant before
799 // the window is created
800 // wxASSERT( m_peer->Ok() ) ;
802 m_windowVariant
= variant
;
804 if (m_peer
== NULL
|| !m_peer
->Ok())
808 ThemeFontID themeFont
= kThemeSystemFont
;
810 // we will get that from the settings later
811 // and make this NORMAL later, but first
812 // we have a few calculations that we must fix
816 case wxWINDOW_VARIANT_NORMAL
:
817 size
= kControlSizeNormal
;
818 themeFont
= kThemeSystemFont
;
820 case wxWINDOW_VARIANT_SMALL
:
821 size
= kControlSizeSmall
;
822 themeFont
= kThemeSmallSystemFont
;
824 case wxWINDOW_VARIANT_MINI
:
825 if (UMAGetSystemVersion() >= 0x1030 )
827 // not always defined in the headers
833 size
= kControlSizeSmall
;
834 themeFont
= kThemeSmallSystemFont
;
837 case wxWINDOW_VARIANT_LARGE
:
838 size
= kControlSizeLarge
;
839 themeFont
= kThemeSystemFont
;
842 wxFAIL_MSG(_T("unexpected window variant"));
845 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
848 font
.MacCreateThemeFont( themeFont
) ;
852 void wxWindowMac::MacUpdateControlFont()
854 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
858 bool wxWindowMac::SetFont(const wxFont
& font
)
860 bool retval
= !wxWindowBase::SetFont( font
) ;
862 MacUpdateControlFont() ;
867 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
869 if ( !wxWindowBase::SetForegroundColour(col
) )
872 MacUpdateControlFont() ;
877 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
879 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
883 wxColour
newCol(GetBackgroundColour());
884 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
886 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
888 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
890 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
894 brush
.SetColour( newCol
) ;
896 MacSetBackgroundBrush( brush
) ;
898 MacUpdateControlFont() ;
904 bool wxWindowMac::MacCanFocus() const
906 // there is currently no way to determine whether the window is running in full keyboard
907 // access mode, therefore we cannot rely on these features, yet the only other way would be
908 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
909 // in event handlers...
910 UInt32 features
= 0 ;
911 m_peer
->GetFeatures( & features
) ;
912 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
916 void wxWindowMac::SetFocus()
918 if ( AcceptsFocus() )
920 #if !TARGET_API_MAC_OSX
921 wxWindow
* former
= FindFocus() ;
923 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
924 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
925 // leave in case of an error
926 if ( err
== errCouldntSetFocus
)
929 #if !TARGET_API_MAC_OSX
930 // emulate carbon events when running under carbonlib where they are not natively available
933 EventRef evRef
= NULL
;
934 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
937 wxMacCarbonEvent
cEvent( evRef
) ;
938 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
939 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
941 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
942 ReleaseEvent(evRef
) ;
944 // send new focus event
946 EventRef evRef
= NULL
;
947 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
950 wxMacCarbonEvent
cEvent( evRef
) ;
951 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
952 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
954 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
955 ReleaseEvent(evRef
) ;
962 void wxWindowMac::DoCaptureMouse()
964 wxTheApp
->s_captureWindow
= this ;
967 wxWindow
* wxWindowBase::GetCapture()
969 return wxTheApp
->s_captureWindow
;
972 void wxWindowMac::DoReleaseMouse()
974 wxTheApp
->s_captureWindow
= NULL
;
977 #if wxUSE_DRAG_AND_DROP
979 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
981 if ( m_dropTarget
!= 0 ) {
985 m_dropTarget
= pDropTarget
;
986 if ( m_dropTarget
!= 0 )
994 // Old style file-manager drag&drop
995 void wxWindowMac::DragAcceptFiles(bool accept
)
1000 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1001 int& w
, int& h
) const
1004 m_peer
->GetRect( &bounds
) ;
1009 w
= bounds
.right
- bounds
.left
;
1010 h
= bounds
.bottom
- bounds
.top
;
1012 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1015 Point tlworigin
= { 0 , 0 } ;
1016 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1022 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1025 int& w
, int& h
, bool adjustOrigin
) const
1027 // the desired size, minus the border pixels gives the correct size of the control
1031 // todo the default calls may be used as soon as PostCreateControl Is moved here
1032 w
= size
.x
; // WidthDefault( size.x );
1033 h
= size
.y
; // HeightDefault( size.y ) ;
1034 #if !TARGET_API_MAC_OSX
1035 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1038 x
+= MacGetLeftBorderSize() ;
1039 y
+= MacGetTopBorderSize() ;
1040 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1041 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1044 AdjustForParentClientOrigin( x
, y
) ;
1049 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1051 // take the size of the control and add the borders that have to be drawn outside
1052 int x1
, y1
, w1
,h1
;
1053 #if TARGET_API_MAC_OSX
1054 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1058 m_peer
->GetRect( &bounds
) ;
1059 w1
= bounds
.right
- bounds
.left
;
1060 h1
= bounds
.bottom
- bounds
.top
;
1062 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1063 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1069 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1071 #if TARGET_API_MAC_OSX
1072 int x1
, y1
, w1
,h1
;
1073 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1074 x1
-= MacGetLeftBorderSize() ;
1075 y1
-= MacGetTopBorderSize() ;
1076 if ( !IsTopLevel() )
1078 wxWindow
*parent
= GetParent();
1081 wxPoint
pt(parent
->GetClientAreaOrigin());
1090 m_peer
->GetRect( &bounds
) ;
1091 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1093 int xx
= bounds
.left
;
1094 int yy
= bounds
.top
;
1095 xx
-= MacGetLeftBorderSize() ;
1096 yy
-= MacGetTopBorderSize() ;
1098 if ( !GetParent()->IsTopLevel() )
1100 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1106 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1115 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1117 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1119 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1122 Point localwhere
= {0,0} ;
1124 if(x
) localwhere
.h
= * x
;
1125 if(y
) localwhere
.v
= * y
;
1127 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1128 if(x
) *x
= localwhere
.h
;
1129 if(y
) *y
= localwhere
.v
;
1132 MacRootWindowToWindow( x
, y
) ;
1134 wxPoint origin
= GetClientAreaOrigin() ;
1135 if(x
) *x
-= origin
.x
;
1136 if(y
) *y
-= origin
.y
;
1139 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1141 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1142 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1144 wxPoint origin
= GetClientAreaOrigin() ;
1145 if(x
) *x
+= origin
.x
;
1146 if(y
) *y
+= origin
.y
;
1148 MacWindowToRootWindow( x
, y
) ;
1151 Point localwhere
= { 0,0 };
1152 if(x
) localwhere
.h
= * x
;
1153 if(y
) localwhere
.v
= * y
;
1154 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1155 if(x
) *x
= localwhere
.h
;
1156 if(y
) *y
= localwhere
.v
;
1160 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1162 wxPoint origin
= GetClientAreaOrigin() ;
1163 if(x
) *x
+= origin
.x
;
1164 if(y
) *y
+= origin
.y
;
1166 MacWindowToRootWindow( x
, y
) ;
1169 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1171 MacRootWindowToWindow( x
, y
) ;
1173 wxPoint origin
= GetClientAreaOrigin() ;
1174 if(x
) *x
-= origin
.x
;
1175 if(y
) *y
-= origin
.y
;
1178 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1180 #if TARGET_API_MAC_OSX
1182 if ( x
) pt
.x
= *x
;
1183 if ( y
) pt
.y
= *y
;
1185 if ( !IsTopLevel() )
1187 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1190 pt
.x
-= MacGetLeftBorderSize() ;
1191 pt
.y
-= MacGetTopBorderSize() ;
1192 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1196 if ( x
) *x
= (int) pt
.x
;
1197 if ( y
) *y
= (int) pt
.y
;
1199 if ( !IsTopLevel() )
1202 m_peer
->GetRect( &bounds
) ;
1203 if(x
) *x
+= bounds
.left
;
1204 if(y
) *y
+= bounds
.top
;
1209 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1214 MacWindowToRootWindow( &x1
, &y1
) ;
1219 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1221 #if TARGET_API_MAC_OSX
1223 if ( x
) pt
.x
= *x
;
1224 if ( y
) pt
.y
= *y
;
1226 if ( !IsTopLevel() )
1228 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1229 pt
.x
+= MacGetLeftBorderSize() ;
1230 pt
.y
+= MacGetTopBorderSize() ;
1233 if ( x
) *x
= (int) pt
.x
;
1234 if ( y
) *y
= (int) pt
.y
;
1236 if ( !IsTopLevel() )
1239 m_peer
->GetRect( &bounds
) ;
1240 if(x
) *x
-= bounds
.left
;
1241 if(y
) *y
-= bounds
.top
;
1246 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1251 MacRootWindowToWindow( &x1
, &y1
) ;
1256 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1258 RgnHandle rgn
= NewRgn() ;
1260 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1262 GetRegionBounds( rgn
, &content
) ;
1267 m_peer
->GetRect( &content
) ;
1270 m_peer
->GetRect( &structure
) ;
1271 #if !TARGET_API_MAC_OSX
1272 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1274 left
= content
.left
- structure
.left
;
1275 top
= content
.top
- structure
.top
;
1276 right
= structure
.right
- content
.right
;
1277 bottom
= structure
.bottom
- content
.bottom
;
1280 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1282 wxSize sizeTotal
= size
;
1284 RgnHandle rgn
= NewRgn() ;
1288 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1290 GetRegionBounds( rgn
, &content
) ;
1295 m_peer
->GetRect( &content
) ;
1298 m_peer
->GetRect( &structure
) ;
1299 #if !TARGET_API_MAC_OSX
1300 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1303 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1304 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1306 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1307 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1313 // Get size *available for subwindows* i.e. excluding menu bar etc.
1314 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1318 RgnHandle rgn
= NewRgn() ;
1320 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1322 GetRegionBounds( rgn
, &content
) ;
1327 m_peer
->GetRect( &content
) ;
1329 #if !TARGET_API_MAC_OSX
1331 m_peer
->GetRect( &structure
) ;
1332 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1334 ww
= content
.right
- content
.left
;
1335 hh
= content
.bottom
- content
.top
;
1337 ww
-= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1338 hh
-= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1340 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1346 GetSize( &w
, &h
) ;
1348 MacClientToRootWindow( &x1
, &y1
) ;
1349 MacClientToRootWindow( &w
, &h
) ;
1351 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1353 int totW
= 10000 , totH
= 10000;
1356 if ( iter
->IsTopLevel() )
1358 iter
->GetSize( &totW
, &totH
) ;
1362 iter
= iter
->GetParent() ;
1365 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1367 hh
-= MAC_SCROLLBAR_SIZE
;
1373 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1375 ww
-= MAC_SCROLLBAR_SIZE
;
1387 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1389 if (m_cursor
== cursor
)
1392 if (wxNullCursor
== cursor
)
1394 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1399 if ( ! wxWindowBase::SetCursor( cursor
) )
1403 wxASSERT_MSG( m_cursor
.Ok(),
1404 wxT("cursor must be valid after call to the base version"));
1407 wxWindowMac
*mouseWin
= 0 ;
1409 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1411 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1413 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1414 // position, use it...
1418 ControlPartCode part
;
1419 ControlRef control
;
1420 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1422 mouseWin
= wxFindControlFromMacControl( control
) ;
1425 QDSwapPort( savePort
, NULL
) ;
1428 if ( mouseWin
== this && !wxIsBusy() )
1430 m_cursor
.MacInstall() ;
1437 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1439 menu
->SetInvokingWindow(this);
1442 if ( x
== -1 && y
== -1 )
1444 wxPoint mouse
= wxGetMousePosition();
1445 x
= mouse
.x
; y
= mouse
.y
;
1449 ClientToScreen( &x
, &y
) ;
1452 menu
->MacBeforeDisplay( true ) ;
1453 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1454 if ( HiWord(menuResult
) != 0 )
1457 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1458 wxMenuItem
* item
= NULL
;
1460 item
= menu
->FindItem(id
, &realmenu
) ;
1461 if (item
->IsCheckable())
1463 item
->Check( !item
->IsChecked() ) ;
1465 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1467 menu
->MacAfterDisplay( true ) ;
1469 menu
->SetInvokingWindow(NULL
);
1475 // ----------------------------------------------------------------------------
1477 // ----------------------------------------------------------------------------
1481 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1483 wxWindowBase::DoSetToolTip(tooltip
);
1486 m_tooltip
->SetWindow(this);
1489 #endif // wxUSE_TOOLTIPS
1491 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1493 int former_x
, former_y
, former_w
, former_h
;
1494 #if !TARGET_API_MAC_OSX
1495 DoGetPosition( &former_x
, &former_y
) ;
1496 DoGetSize( &former_w
, &former_h
) ;
1498 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1499 former_x
-= MacGetLeftBorderSize() ;
1500 former_y
-= MacGetTopBorderSize() ;
1501 former_w
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1502 former_h
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1505 int actualWidth
= width
;
1506 int actualHeight
= height
;
1510 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1511 actualWidth
= m_minWidth
;
1512 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1513 actualHeight
= m_minHeight
;
1514 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1515 actualWidth
= m_maxWidth
;
1516 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1517 actualHeight
= m_maxHeight
;
1519 bool doMove
= false ;
1520 bool doResize
= false ;
1522 if ( actualX
!= former_x
|| actualY
!= former_y
)
1526 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1531 if ( doMove
|| doResize
)
1533 // we don't adjust twice for the origin
1534 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1535 bool vis
= m_peer
->IsVisible();
1537 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1539 m_peer
->SetVisibility( false , true ) ;
1540 m_peer
->SetRect( &r
) ;
1542 m_peer
->SetVisibility( true , true ) ;
1544 MacRepositionScrollBars() ;
1547 wxPoint
point(actualX
,actualY
);
1548 wxMoveEvent
event(point
, m_windowId
);
1549 event
.SetEventObject(this);
1550 GetEventHandler()->ProcessEvent(event
) ;
1554 MacRepositionScrollBars() ;
1555 wxSize
size(actualWidth
, actualHeight
);
1556 wxSizeEvent
event(size
, m_windowId
);
1557 event
.SetEventObject(this);
1558 GetEventHandler()->ProcessEvent(event
);
1564 wxSize
wxWindowMac::DoGetBestSize() const
1566 if ( m_macIsUserPane
|| IsTopLevel() )
1567 return wxWindowBase::DoGetBestSize() ;
1569 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1570 int bestWidth
, bestHeight
;
1571 m_peer
->GetBestRect( &bestsize
) ;
1573 if ( EmptyRect( &bestsize
) )
1575 bestsize
.left
= bestsize
.top
= 0 ;
1576 bestsize
.right
= 16 ;
1577 bestsize
.bottom
= 16 ;
1578 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1580 bestsize
.bottom
= 16 ;
1582 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1584 bestsize
.bottom
= 24 ;
1588 // return wxWindowBase::DoGetBestSize() ;
1592 bestWidth
= bestsize
.right
- bestsize
.left
;
1593 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1594 if ( bestHeight
< 10 )
1597 return wxSize(bestWidth
, bestHeight
);
1601 // set the size of the window: if the dimensions are positive, just use them,
1602 // but if any of them is equal to -1, it means that we must find the value for
1603 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1604 // which case -1 is a valid value for x and y)
1606 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1607 // the width/height to best suit our contents, otherwise we reuse the current
1609 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1611 // get the current size and position...
1612 int currentX
, currentY
;
1613 GetPosition(¤tX
, ¤tY
);
1615 int currentW
,currentH
;
1616 GetSize(¤tW
, ¤tH
);
1618 // ... and don't do anything (avoiding flicker) if it's already ok
1619 if ( x
== currentX
&& y
== currentY
&&
1620 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1623 MacRepositionScrollBars() ; // we might have a real position shift
1627 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1629 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1632 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1634 wxSize
size(-1, -1);
1637 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1639 size
= DoGetBestSize();
1644 // just take the current one
1651 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1655 size
= DoGetBestSize();
1657 //else: already called DoGetBestSize() above
1663 // just take the current one
1668 DoMoveWindow(x
, y
, width
, height
);
1672 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1674 RgnHandle rgn
= NewRgn() ;
1676 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1677 GetRegionBounds( rgn
, &content
) ;
1679 #if !TARGET_API_MAC_OSX
1680 // if the content rgn is empty / not supported
1681 // don't attempt to correct the coordinates to wxWindow relative ones
1682 if (!::EmptyRect( &content
) )
1685 m_peer
->GetRect( &structure
) ;
1686 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1690 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1693 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1695 if ( clientheight
!= -1 || clientheight
!= -1 )
1697 int currentclientwidth
, currentclientheight
;
1698 int currentwidth
, currentheight
;
1700 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1701 GetSize( ¤twidth
, ¤theight
) ;
1703 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1704 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1708 void wxWindowMac::SetTitle(const wxString
& title
)
1710 m_label
= wxStripMenuCodes(title
) ;
1712 if ( m_peer
&& m_peer
->Ok() )
1714 m_peer
->SetTitle( m_label
) ;
1719 wxString
wxWindowMac::GetTitle() const
1724 bool wxWindowMac::Show(bool show
)
1726 if ( !wxWindowBase::Show(show
) )
1729 // TODO use visibilityChanged Carbon Event for OSX
1730 bool former
= MacIsReallyShown() ;
1732 m_peer
->SetVisibility( show
, true ) ;
1733 if ( former
!= MacIsReallyShown() )
1734 MacPropagateVisibilityChanged() ;
1738 bool wxWindowMac::Enable(bool enable
)
1740 wxASSERT( m_peer
->Ok() ) ;
1741 if ( !wxWindowBase::Enable(enable
) )
1744 bool former
= MacIsReallyEnabled() ;
1745 m_peer
->Enable( enable
) ;
1747 if ( former
!= MacIsReallyEnabled() )
1748 MacPropagateEnabledStateChanged() ;
1753 // status change propagations (will be not necessary for OSX later )
1756 void wxWindowMac::MacPropagateVisibilityChanged()
1758 #if !TARGET_API_MAC_OSX
1759 MacVisibilityChanged() ;
1761 wxWindowListNode
*node
= GetChildren().GetFirst();
1764 wxWindowMac
*child
= node
->GetData();
1765 if ( child
->IsShown() )
1766 child
->MacPropagateVisibilityChanged( ) ;
1767 node
= node
->GetNext();
1772 void wxWindowMac::MacPropagateEnabledStateChanged( )
1774 #if !TARGET_API_MAC_OSX
1775 MacEnabledStateChanged() ;
1777 wxWindowListNode
*node
= GetChildren().GetFirst();
1780 wxWindowMac
*child
= node
->GetData();
1781 if ( child
->IsEnabled() )
1782 child
->MacPropagateEnabledStateChanged() ;
1783 node
= node
->GetNext();
1788 void wxWindowMac::MacPropagateHiliteChanged( )
1790 #if !TARGET_API_MAC_OSX
1791 MacHiliteChanged() ;
1793 wxWindowListNode
*node
= GetChildren().GetFirst();
1796 wxWindowMac
*child
= node
->GetData();
1797 // if ( child->IsEnabled() )
1798 child
->MacPropagateHiliteChanged() ;
1799 node
= node
->GetNext();
1805 // status change notifications
1808 void wxWindowMac::MacVisibilityChanged()
1812 void wxWindowMac::MacHiliteChanged()
1816 void wxWindowMac::MacEnabledStateChanged()
1821 // status queries on the inherited window's state
1824 bool wxWindowMac::MacIsReallyShown()
1826 // only under OSX the visibility of the TLW is taken into account
1827 #if TARGET_API_MAC_OSX
1828 if ( m_peer
&& m_peer
->Ok() )
1829 return m_peer
->IsVisible();
1831 wxWindow
* win
= this ;
1832 while( win
->IsShown() )
1834 if ( win
->IsTopLevel() )
1837 win
= win
->GetParent() ;
1845 bool wxWindowMac::MacIsReallyEnabled()
1847 return m_peer
->IsEnabled() ;
1850 bool wxWindowMac::MacIsReallyHilited()
1852 return m_peer
->IsActive();
1855 void wxWindowMac::MacFlashInvalidAreas()
1857 #if TARGET_API_MAC_OSX
1858 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1866 int wxWindowMac::GetCharHeight() const
1868 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1869 return dc
.GetCharHeight() ;
1872 int wxWindowMac::GetCharWidth() const
1874 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1875 return dc
.GetCharWidth() ;
1878 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1879 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1881 const wxFont
*fontToUse
= theFont
;
1883 fontToUse
= &m_font
;
1885 wxClientDC
dc( (wxWindowMac
*) this ) ;
1887 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1888 if ( externalLeading
)
1889 *externalLeading
= le
;
1899 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1900 * we always intersect with the entire window, not only with the client area
1903 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
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 ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2048 event
.GetDC()->Clear() ;
2051 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2053 wxWindowDC
dc(this) ;
2054 wxMacPortSetter
helper(&dc
) ;
2056 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2059 int wxWindowMac::GetScrollPos(int orient
) const
2061 if ( orient
== wxHORIZONTAL
)
2064 return m_hScrollBar
->GetThumbPosition() ;
2069 return m_vScrollBar
->GetThumbPosition() ;
2074 // This now returns the whole range, not just the number
2075 // of positions that we can scroll.
2076 int wxWindowMac::GetScrollRange(int orient
) const
2078 if ( orient
== wxHORIZONTAL
)
2081 return m_hScrollBar
->GetRange() ;
2086 return m_vScrollBar
->GetRange() ;
2091 int wxWindowMac::GetScrollThumb(int orient
) const
2093 if ( orient
== wxHORIZONTAL
)
2096 return m_hScrollBar
->GetThumbSize() ;
2101 return m_vScrollBar
->GetThumbSize() ;
2106 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2108 if ( orient
== wxHORIZONTAL
)
2111 m_hScrollBar
->SetThumbPosition( pos
) ;
2116 m_vScrollBar
->SetThumbPosition( pos
) ;
2120 void wxWindowMac::MacPaintBorders( int left
, int top
)
2126 wxGetOsVersion( &major
, &minor
);
2128 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2129 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2130 // OS X has lighter border edges than classic:
2133 darkShadow
.red
= 0x8E8E;
2134 darkShadow
.green
= 0x8E8E;
2135 darkShadow
.blue
= 0x8E8E;
2136 lightShadow
.red
= 0xBDBD;
2137 lightShadow
.green
= 0xBDBD;
2138 lightShadow
.blue
= 0xBDBD;
2144 GetSize( &w
, &h
) ;
2145 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2146 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2148 #if wxMAC_USE_THEME_BORDER
2150 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2151 InsetRect( &rect
, border
, border
);
2152 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2154 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2155 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2157 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2158 RGBForeColor( &face
);
2159 MoveTo( left
+ 0 , top
+ h
- 2 );
2160 LineTo( left
+ 0 , top
+ 0 );
2161 LineTo( left
+ w
- 2 , top
+ 0 );
2163 MoveTo( left
+ 2 , top
+ h
- 3 );
2164 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2165 LineTo( left
+ w
- 3 , top
+ 2 );
2167 RGBForeColor( sunken
? &face
: &darkShadow
);
2168 MoveTo( left
+ 0 , top
+ h
- 1 );
2169 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2170 LineTo( left
+ w
- 1 , top
+ 0 );
2172 RGBForeColor( sunken
? &lightShadow
: &white
);
2173 MoveTo( left
+ 1 , top
+ h
- 3 );
2174 LineTo( left
+ 1, top
+ 1 );
2175 LineTo( left
+ w
- 3 , top
+ 1 );
2177 RGBForeColor( sunken
? &white
: &lightShadow
);
2178 MoveTo( left
+ 1 , top
+ h
- 2 );
2179 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2180 LineTo( left
+ w
- 2 , top
+ 1 );
2182 RGBForeColor( sunken
? &darkShadow
: &face
);
2183 MoveTo( left
+ 2 , top
+ h
- 4 );
2184 LineTo( left
+ 2 , top
+ 2 );
2185 LineTo( left
+ w
- 4 , top
+ 2 );
2188 else if (HasFlag(wxSIMPLE_BORDER
))
2190 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2191 RGBForeColor( &darkShadow
) ;
2192 FrameRect( &rect
) ;
2196 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2198 if ( child
== m_hScrollBar
)
2199 m_hScrollBar
= NULL
;
2200 if ( child
== m_vScrollBar
)
2201 m_vScrollBar
= NULL
;
2203 wxWindowBase::RemoveChild( child
) ;
2206 // New function that will replace some of the above.
2207 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2208 int range
, bool refresh
)
2210 if ( orient
== wxHORIZONTAL
)
2214 if ( range
== 0 || thumbVisible
>= range
)
2216 if ( m_hScrollBar
->IsShown() )
2217 m_hScrollBar
->Show(false) ;
2221 if ( !m_hScrollBar
->IsShown() )
2222 m_hScrollBar
->Show(true) ;
2223 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2231 if ( range
== 0 || thumbVisible
>= range
)
2233 if ( m_vScrollBar
->IsShown() )
2234 m_vScrollBar
->Show(false) ;
2238 if ( !m_vScrollBar
->IsShown() )
2239 m_vScrollBar
->Show(true) ;
2240 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2244 MacRepositionScrollBars() ;
2247 // Does a physical scroll
2248 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2250 if( dx
== 0 && dy
==0 )
2256 int width
, height
;
2257 GetClientSize( &width
, &height
) ;
2258 #if TARGET_API_MAC_OSX
2259 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2260 // area is scrolled, this does not occur if width and height are 2 pixels less,
2261 // TODO write optimal workaround
2262 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width
, MacGetTopBorderSize() + height
) ;
2265 scrollrect
.Intersect( *rect
) ;
2267 if ( m_peer
->GetNeedsDisplay() )
2269 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2270 // either immediate redraw or full invalidate
2272 // is the better overall solution, as it does not slow down scrolling
2273 m_peer
->SetNeedsDisplay( true ) ;
2275 // this would be the preferred version for fast drawing controls
2276 if( UMAGetSystemVersion() < 0x1030 )
2279 HIViewRender(*m_peer
) ;
2282 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2289 RgnHandle updateRgn
= NewRgn() ;
2292 wxClientDC
dc(this) ;
2293 wxMacPortSetter
helper(&dc
) ;
2295 m_peer
->GetRect( &scrollrect
) ;
2296 scrollrect
.top
+= MacGetTopBorderSize() ;
2297 scrollrect
.left
+= MacGetLeftBorderSize() ;
2298 scrollrect
.bottom
= scrollrect
.top
+ height
;
2299 scrollrect
.right
= scrollrect
.left
+ width
;
2303 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2304 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2305 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2307 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2309 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2313 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2315 wxWindowMac
*child
= node
->GetData();
2316 if (child
== m_vScrollBar
) continue;
2317 if (child
== m_hScrollBar
) continue;
2318 if (child
->IsTopLevel()) continue;
2321 child
->GetPosition( &x
, &y
);
2323 child
->GetSize( &w
, &h
);
2327 if (rect
->Intersects(rc
))
2328 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2332 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2337 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2339 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2341 wxScrollWinEvent wevent
;
2342 wevent
.SetPosition(event
.GetPosition());
2343 wevent
.SetOrientation(event
.GetOrientation());
2344 wevent
.m_eventObject
= this;
2346 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2347 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2348 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2349 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2350 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2351 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2352 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2353 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2354 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2355 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2356 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2357 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2358 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2359 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2360 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2361 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2363 GetEventHandler()->ProcessEvent(wevent
);
2367 // Get the window with the focus
2368 wxWindowMac
*wxWindowBase::FindFocus()
2370 ControlRef control
;
2371 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2372 return wxFindControlFromMacControl( control
) ;
2375 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2377 // panel wants to track the window which was the last to have focus in it,
2378 // so we want to set ourselves as the window which last had focus
2380 // notice that it's also important to do it upwards the tree becaus
2381 // otherwise when the top level panel gets focus, it won't set it back to
2382 // us, but to some other sibling
2384 // CS:don't know if this is still needed:
2385 //wxChildFocusEvent eventFocus(this);
2386 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2388 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2390 wxMacWindowStateSaver
sv( this ) ;
2391 // wxWindowDC dc(this) ;
2392 // wxMacPortSetter helper(&dc) ;
2397 MacWindowToRootWindow( &x
, &y
) ;
2398 GetSize( &w
, &h
) ;
2399 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2401 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2402 DrawThemeFocusRect( &rect
, true ) ;
2404 DrawThemeFocusRect( &rect
, false ) ;
2410 void wxWindowMac::OnInternalIdle()
2412 // This calls the UI-update mechanism (querying windows for
2413 // menu/toolbar/control state information)
2414 if (wxUpdateUIEvent::CanUpdate(this))
2415 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2418 // Raise the window to the top of the Z order
2419 void wxWindowMac::Raise()
2421 m_peer
->SetZOrder( true , NULL
) ;
2424 // Lower the window to the bottom of the Z order
2425 void wxWindowMac::Lower()
2427 m_peer
->SetZOrder( false , NULL
) ;
2431 // static wxWindow *gs_lastWhich = NULL;
2433 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2435 // first trigger a set cursor event
2437 wxPoint clientorigin
= GetClientAreaOrigin() ;
2438 wxSize clientsize
= GetClientSize() ;
2440 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2442 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2444 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2445 if ( processedEvtSetCursor
&& event
.HasCursor() )
2447 cursor
= event
.GetCursor() ;
2452 // the test for processedEvtSetCursor is here to prevent using m_cursor
2453 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2454 // it - this is a way to say that our cursor shouldn't be used for this
2456 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2466 cursor
= *wxSTANDARD_CURSOR
;
2470 cursor
.MacInstall() ;
2472 return cursor
.Ok() ;
2475 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2479 return m_tooltip
->GetTip() ;
2481 return wxEmptyString
;
2484 void wxWindowMac::Update()
2486 #if TARGET_API_MAC_OSX
2487 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2488 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2489 // for composited windows this also triggers a redraw of all
2490 // invalid views in the window
2491 if( UMAGetSystemVersion() >= 0x1030 )
2492 HIWindowFlush(window
) ;
2496 // the only way to trigger the redrawing on earlier systems is to call
2499 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2500 UInt32 currentEventClass
= 0 ;
2501 UInt32 currentEventKind
= 0 ;
2502 if ( currentEvent
!= NULL
)
2504 currentEventClass
= ::GetEventClass( currentEvent
) ;
2505 currentEventKind
= ::GetEventKind( currentEvent
) ;
2507 if ( currentEventClass
!= kEventClassMenu
)
2509 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2512 OSStatus status
= noErr
;
2513 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2516 m_peer
->SetNeedsDisplay( true ) ;
2519 ::Draw1Control( m_peer
->GetControlRef() ) ;
2523 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2525 wxTopLevelWindowMac
* win
= NULL
;
2526 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2529 win
= wxFindWinFromMacWindow( window
) ;
2533 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2537 RgnHandle visRgn
= NewRgn() ;
2538 RgnHandle tempRgn
= NewRgn() ;
2539 if ( m_peer
->IsVisible())
2541 m_peer
->GetRect( &r
) ;
2542 r
.left
-= MacGetLeftBorderSize() ;
2543 r
.top
-= MacGetTopBorderSize() ;
2544 r
.bottom
+= MacGetBottomBorderSize() ;
2545 r
.right
+= MacGetRightBorderSize() ;
2547 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2549 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2550 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2559 if ( includeOuterStructures
)
2560 InsetRect( &r
, -3 , -3 ) ;
2561 RectRgn( visRgn
, &r
) ;
2562 if ( !IsTopLevel() )
2564 wxWindow
* child
= this ;
2565 wxWindow
* parent
= child
->GetParent() ;
2570 // we have to find a better clipping algorithm here, in order not to clip things
2571 // positioned like status and toolbar
2572 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2574 size
= parent
->GetSize() ;
2579 size
= parent
->GetClientSize() ;
2580 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2584 parent
->MacWindowToRootWindow( &x
, &y
) ;
2585 MacRootWindowToWindow( &x
, &y
) ;
2587 SetRectRgn( tempRgn
,
2588 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2589 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2590 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2592 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2593 if ( parent
->IsTopLevel() )
2596 parent
= child
->GetParent() ;
2601 wxRegion vis
= visRgn
;
2602 DisposeRgn( visRgn
) ;
2603 DisposeRgn( tempRgn
) ;
2608 This function must not change the updatergn !
2610 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2612 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2613 bool handled
= false ;
2615 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2617 RgnHandle newupdate
= NewRgn() ;
2618 wxSize point
= GetClientSize() ;
2619 wxPoint origin
= GetClientAreaOrigin() ;
2620 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2621 SectRgn( newupdate
, updatergn
, newupdate
) ;
2622 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2623 m_updateRegion
= newupdate
;
2624 DisposeRgn( newupdate
) ;
2627 if ( !EmptyRgn(updatergn
) )
2629 wxWindowDC
dc(this);
2630 if (!EmptyRgn(updatergn
))
2631 dc
.SetClippingRegion(wxRegion(updatergn
));
2633 wxEraseEvent
eevent( GetId(), &dc
);
2634 eevent
.SetEventObject( this );
2635 GetEventHandler()->ProcessEvent( eevent
);
2637 if ( !m_updateRegion
.Empty() )
2639 // paint the window itself
2641 event
.m_timeStamp
= time
;
2642 event
.SetEventObject(this);
2643 handled
= GetEventHandler()->ProcessEvent(event
);
2645 // paint custom borders
2646 wxNcPaintEvent
eventNc( GetId() );
2647 eventNc
.SetEventObject( this );
2648 GetEventHandler()->ProcessEvent( eventNc
);
2654 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2656 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2657 // updatergn is always already clipped to our boundaries
2658 // if we are in compositing mode then it is in relative to the upper left of the control
2659 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2660 // of the toplevel window
2661 // it is in window coordinates, not in client coordinates
2663 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2664 RgnHandle ownUpdateRgn
= NewRgn() ;
2665 CopyRgn( updatergn
, ownUpdateRgn
) ;
2667 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2670 m_peer
->GetRectInWindowCoords( &bounds
);
2671 RgnHandle controlRgn
= NewRgn();
2672 RectRgn( controlRgn
, &bounds
);
2673 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2674 // the window update region
2675 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2676 DisposeRgn( controlRgn
);
2678 //KO: convert ownUpdateRgn to local coordinates
2679 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2682 MacDoRedraw( ownUpdateRgn
, time
) ;
2683 DisposeRgn( ownUpdateRgn
) ;
2687 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2689 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2693 if ( iter
->IsTopLevel() )
2694 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2696 iter
= iter
->GetParent() ;
2698 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2702 void wxWindowMac::MacCreateScrollBars( long style
)
2704 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2706 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2707 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2709 GetClientSize( &width
, &height
) ;
2711 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2712 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2713 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2714 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2716 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2717 vSize
, wxVERTICAL
);
2719 if ( style
& wxVSCROLL
)
2725 m_vScrollBar
->Show(false) ;
2727 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2728 hSize
, wxHORIZONTAL
);
2729 if ( style
& wxHSCROLL
)
2734 m_hScrollBar
->Show(false) ;
2737 // because the create does not take into account the client area origin
2738 MacRepositionScrollBars() ; // we might have a real position shift
2741 void wxWindowMac::MacRepositionScrollBars()
2743 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2744 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2746 // get real client area
2750 GetSize( &width
, &height
) ;
2752 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2753 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2755 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2756 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2757 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2758 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2764 GetSize( &w
, &h
) ;
2766 MacClientToRootWindow( &x
, &y
) ;
2767 MacClientToRootWindow( &w
, &h
) ;
2769 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2771 int totW
= 10000 , totH
= 10000;
2774 if ( iter
->IsTopLevel() )
2776 iter
->GetSize( &totW
, &totH
) ;
2780 iter
= iter
->GetParent() ;
2808 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2812 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2816 bool wxWindowMac::AcceptsFocus() const
2818 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2821 void wxWindowMac::MacSuperChangedPosition()
2823 // only window-absolute structures have to be moved i.e. controls
2825 wxWindowListNode
*node
= GetChildren().GetFirst();
2828 wxWindowMac
*child
= node
->GetData();
2829 child
->MacSuperChangedPosition() ;
2830 node
= node
->GetNext();
2834 void wxWindowMac::MacTopLevelWindowChangedPosition()
2836 // only screen-absolute structures have to be moved i.e. glcanvas
2838 wxWindowListNode
*node
= GetChildren().GetFirst();
2841 wxWindowMac
*child
= node
->GetData();
2842 child
->MacTopLevelWindowChangedPosition() ;
2843 node
= node
->GetNext();
2847 long wxWindowMac::MacGetLeftBorderSize( ) const
2852 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2855 #if 0 // wxMAC_USE_THEME_BORDER
2856 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2860 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2863 #if 0 // wxMAC_USE_THEME_BORDER
2864 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2868 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2875 long wxWindowMac::MacGetRightBorderSize( ) const
2877 // they are all symmetric in mac themes
2878 return MacGetLeftBorderSize() ;
2881 long wxWindowMac::MacGetTopBorderSize( ) const
2883 // they are all symmetric in mac themes
2884 return MacGetLeftBorderSize() ;
2887 long wxWindowMac::MacGetBottomBorderSize( ) const
2889 // they are all symmetric in mac themes
2890 return MacGetLeftBorderSize() ;
2893 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2895 return style
& ~( wxDOUBLE_BORDER
| wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxBORDER
| wxSTATIC_BORDER
) ;
2898 // Find the wxWindowMac at the current mouse position, returning the mouse
2900 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2902 pt
= wxGetMousePosition();
2903 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2907 // Get the current mouse position.
2908 wxPoint
wxGetMousePosition()
2911 wxGetMousePosition(& x
, & y
);
2912 return wxPoint(x
, y
);
2915 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2917 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2919 // copied from wxGTK : CS
2920 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2923 // (a) it's a command event and so is propagated to the parent
2924 // (b) under MSW it can be generated from kbd too
2925 // (c) it uses screen coords (because of (a))
2926 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2928 this->ClientToScreen(event
.GetPosition()));
2929 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2938 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2942 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2946 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2947 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2951 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2953 return eventNotHandledErr
;