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_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 #define wxMAC_USE_THEME_BORDER 1
99 // ---------------------------------------------------------------------------
101 // ---------------------------------------------------------------------------
103 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
104 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
106 #if TARGET_API_MAC_OSX
108 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
110 kEventControlVisibilityChanged
= 157
116 static const EventTypeSpec eventList
[] =
118 { kEventClassControl
, kEventControlHit
} ,
119 #if TARGET_API_MAC_OSX
120 { kEventClassControl
, kEventControlDraw
} ,
121 { kEventClassControl
, kEventControlVisibilityChanged
} ,
122 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
123 { kEventClassControl
, kEventControlHiliteChanged
} ,
124 { kEventClassControl
, kEventControlSetFocusPart
} ,
126 { kEventClassService
, kEventServiceGetTypes
},
127 { kEventClassService
, kEventServiceCopy
},
128 { kEventClassService
, kEventServicePaste
},
130 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
131 // { kEventClassControl , kEventControlBoundsChanged } ,
135 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
137 OSStatus result
= eventNotHandledErr
;
139 wxMacCarbonEvent
cEvent( event
) ;
141 ControlRef controlRef
;
142 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
144 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
146 switch( GetEventKind( event
) )
148 #if TARGET_API_MAC_OSX
149 case kEventControlDraw
:
151 RgnHandle updateRgn
= NULL
;
152 RgnHandle allocatedRgn
= NULL
;
153 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
154 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
156 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
160 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
162 allocatedRgn
= NewRgn() ;
163 CopyRgn( updateRgn
, allocatedRgn
) ;
164 OffsetRgn( updateRgn
, thisWindow
->MacGetLeftBorderSize() , thisWindow
->MacGetTopBorderSize() ) ;
169 // in case we would need a coregraphics compliant background erase first
170 // now usable to track redraws
171 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
172 if ( thisWindow
->MacIsUserPane() )
174 static float color
= 0.5 ;
177 HIViewGetBounds( controlRef
, &bounds
);
178 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
179 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
180 CGContextFillRect( cgContext
, bounds
);
191 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
194 DisposeRgn( allocatedRgn
) ;
197 case kEventControlVisibilityChanged
:
198 thisWindow
->MacVisibilityChanged() ;
200 case kEventControlEnabledStateChanged
:
201 thisWindow
->MacEnabledStateChanged() ;
203 case kEventControlHiliteChanged
:
204 thisWindow
->MacHiliteChanged() ;
206 case kEventControlSetFocusPart
:
208 Boolean focusEverything
= false ;
209 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
210 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
213 if ( controlPart
== kControlFocusNoPart
)
216 if ( thisWindow
->GetCaret() )
218 thisWindow
->GetCaret()->OnKillFocus();
220 #endif // wxUSE_CARET
221 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
222 event
.SetEventObject(thisWindow
);
223 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
227 // panel wants to track the window which was the last to have focus in it
228 wxChildFocusEvent
eventFocus(thisWindow
);
229 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
232 if ( thisWindow
->GetCaret() )
234 thisWindow
->GetCaret()->OnSetFocus();
236 #endif // wxUSE_CARET
238 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
239 event
.SetEventObject(thisWindow
);
240 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
242 if ( thisWindow
->MacIsUserPane() )
247 case kEventControlHit
:
249 result
= thisWindow
->MacControlHit( handler
, event
) ;
258 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
260 OSStatus result
= eventNotHandledErr
;
262 wxMacCarbonEvent
cEvent( event
) ;
264 ControlRef controlRef
;
265 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
266 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
267 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
269 switch( GetEventKind( event
) )
271 case kEventServiceGetTypes
:
275 textCtrl
->GetSelection( &from
, &to
) ;
277 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
279 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
280 if ( textCtrl
->IsEditable() )
281 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
283 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
284 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
286 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
290 CFArrayAppendValue (copyTypes
, typestring
) ;
292 CFArrayAppendValue (pasteTypes
, typestring
) ;
293 CFRelease( typestring
) ;
299 case kEventServiceCopy
:
303 textCtrl
->GetSelection( &from
, &to
) ;
304 wxString val
= textCtrl
->GetValue() ;
305 val
= val
.Mid( from
, to
- from
) ;
306 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
307 verify_noerr( ClearScrap( &scrapRef
) ) ;
308 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
312 case kEventServicePaste
:
315 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
316 Size textSize
, pastedSize
;
317 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
319 char *content
= new char[textSize
] ;
320 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
321 content
[textSize
-1] = 0 ;
323 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
325 textCtrl
->WriteText( wxString( content
) ) ;
336 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
338 OSStatus result
= eventNotHandledErr
;
340 switch ( GetEventClass( event
) )
342 case kEventClassControl
:
343 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
345 case kEventClassService
:
346 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
353 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
355 // ---------------------------------------------------------------------------
356 // UserPane events for non OSX builds
357 // ---------------------------------------------------------------------------
359 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
361 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
362 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
363 win
->MacControlUserPaneDrawProc(part
) ;
366 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
368 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
369 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
370 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
373 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
375 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
376 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
377 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
380 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
382 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
383 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
384 win
->MacControlUserPaneIdleProc() ;
387 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
389 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
390 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
391 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
394 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
396 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
397 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
398 win
->MacControlUserPaneActivateProc(activating
) ;
401 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
403 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
404 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
405 return win
->MacControlUserPaneFocusProc(action
) ;
408 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
410 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
411 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
412 win
->MacControlUserPaneBackgroundProc(info
) ;
415 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
417 RgnHandle rgn
= NewRgn() ;
419 wxMacWindowStateSaver
sv( this ) ;
420 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
421 MacDoRedraw( rgn
, 0 ) ;
425 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
427 return kControlNoPart
;
430 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
432 return kControlNoPart
;
435 void wxWindowMac::MacControlUserPaneIdleProc()
439 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
441 return kControlNoPart
;
444 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
448 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
450 return kControlNoPart
;
453 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
457 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
458 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
459 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
460 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
461 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
462 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
463 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
464 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
466 // ===========================================================================
468 // ===========================================================================
470 wxList
wxWinMacControlList(wxKEY_INTEGER
);
472 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
474 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
477 return (wxControl
*)node
->GetData();
480 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
482 // adding NULL ControlRef is (first) surely a result of an error and
483 // (secondly) breaks native event processing
484 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
486 if ( !wxWinMacControlList
.Find((long)inControl
) )
487 wxWinMacControlList
.Append((long)inControl
, control
);
490 void wxRemoveMacControlAssociation(wxWindow
*control
)
492 wxWinMacControlList
.DeleteObject(control
);
496 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
498 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
500 // we have to setup the brush in the current port and return noErr
501 // or return an error code so that the control manager walks further up the
502 // hierarchy to find a correct background
504 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
506 OSStatus status
= paramErr
;
509 case kControlMsgApplyTextColor
:
511 case kControlMsgSetUpBackground
:
513 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
516 const wxBrush
&brush
= wx
->MacGetBackgroundBrush() ;
519 wxDC::MacSetupBackgroundForCurrentPort( brush
) ;
521 RgnHandle clip
= NewRgn() ;
524 wx
->MacWindowToRootWindow( &x
,&y
) ;
525 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
526 OffsetRgn( clip
, x
, y
) ;
532 else if ( wx
->MacIsUserPane() )
534 // if we don't have a valid brush for such a control, we have to call the
535 // setup of our parent ourselves
536 status
= SetUpControlBackground( (ControlRef
) wx
->GetParent()->GetHandle() , iDepth
, iIsColor
) ;
548 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
549 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
553 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
556 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
561 // ----------------------------------------------------------------------------
562 // constructors and such
563 // ----------------------------------------------------------------------------
565 wxWindowMac::wxWindowMac()
570 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
575 const wxString
& name
)
578 Create(parent
, id
, pos
, size
, style
, name
);
581 void wxWindowMac::Init()
585 #if WXWIN_COMPATIBILITY_2_4
586 m_backgroundTransparent
= FALSE
;
589 // as all windows are created with WS_VISIBLE style...
592 m_hScrollBar
= NULL
;
593 m_vScrollBar
= NULL
;
594 m_macBackgroundBrush
= wxNullBrush
;
596 m_macIsUserPane
= TRUE
;
598 // make sure all proc ptrs are available
600 if ( gControlUserPaneDrawUPP
== NULL
)
602 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
603 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
604 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
605 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
606 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
607 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
608 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
609 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
611 if ( wxMacLiveScrollbarActionUPP
== NULL
)
613 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
616 if ( wxMacSetupControlBackgroundUPP
== NULL
)
618 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
621 // we need a valid font for the encodings
622 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
626 wxWindowMac::~wxWindowMac()
630 m_isBeingDeleted
= TRUE
;
632 #ifndef __WXUNIVERSAL__
633 // VS: make sure there's no wxFrame with last focus set to us:
634 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
636 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
639 if ( frame
->GetLastFocus() == this )
641 frame
->SetLastFocus((wxWindow
*)NULL
);
646 #endif // __WXUNIVERSAL__
648 // wxRemoveMacControlAssociation( this ) ;
649 // If we delete an item, we should initialize the parent panel,
650 // because it could now be invalid.
651 wxWindow
*parent
= GetParent() ;
654 if (parent
->GetDefaultItem() == (wxButton
*) this)
655 parent
->SetDefaultItem(NULL
);
657 if ( m_peer
&& m_peer
->Ok() )
659 // in case the callback might be called during destruction
660 wxRemoveMacControlAssociation( this) ;
661 // we currently are not using this hook
662 // ::SetControlColorProc( *m_peer , NULL ) ;
666 if ( g_MacLastWindow
== this )
668 g_MacLastWindow
= NULL
;
671 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
674 if ( frame
->GetLastFocus() == this )
675 frame
->SetLastFocus( NULL
) ;
680 // delete our drop target if we've got one
681 #if wxUSE_DRAG_AND_DROP
682 if ( m_dropTarget
!= NULL
)
687 #endif // wxUSE_DRAG_AND_DROP
691 WXWidget
wxWindowMac::GetHandle() const
693 return (WXWidget
) m_peer
->GetControlRef() ;
697 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
699 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
700 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
701 GetEventTypeCount(eventList
), eventList
, this,
702 (EventHandlerRef
*)&m_macControlEventHandler
);
707 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
711 const wxString
& name
)
713 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
715 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
718 parent
->AddChild(this);
720 m_windowVariant
= parent
->GetWindowVariant() ;
722 if ( m_macIsUserPane
)
724 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
727 | kControlSupportsEmbedding
728 // | kControlSupportsLiveFeedback
729 // | kControlHasSpecialBackground
730 // | kControlSupportsCalcBestRect
731 // | kControlHandlesTracking
732 | kControlSupportsFocus
733 // | kControlWantsActivate
734 // | kControlWantsIdle
737 m_peer
= new wxMacControl() ;
738 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
741 MacPostControlCreate(pos
,size
) ;
742 #if !TARGET_API_MAC_OSX
743 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
744 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
745 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
746 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
747 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
748 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
749 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
750 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
753 #ifndef __WXUNIVERSAL__
754 // Don't give scrollbars to wxControls unless they ask for them
755 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
756 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
758 MacCreateScrollBars( style
) ;
762 wxWindowCreateEvent
event(this);
763 GetEventHandler()->AddPendingEvent(event
);
768 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
770 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
772 m_peer
->SetReference( (long) this ) ;
774 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
776 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
777 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
778 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
780 // adjust font, controlsize etc
781 DoSetWindowVariant( m_windowVariant
) ;
783 #if !TARGET_API_MAC_OSX
784 // eventually we can fix some clipping issues be reactivating this hook
785 //if ( m_macIsUserPane )
786 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
788 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
790 if (!m_macIsUserPane
)
792 SetInitialBestSize(size
);
795 SetCursor( *wxSTANDARD_CURSOR
) ;
798 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
800 // Don't assert, in case we set the window variant before
801 // the window is created
802 // wxASSERT( m_peer->Ok() ) ;
804 m_windowVariant
= variant
;
806 if (m_peer
== NULL
|| !m_peer
->Ok())
810 ThemeFontID themeFont
= kThemeSystemFont
;
812 // we will get that from the settings later
813 // and make this NORMAL later, but first
814 // we have a few calculations that we must fix
818 case wxWINDOW_VARIANT_NORMAL
:
819 size
= kControlSizeNormal
;
820 themeFont
= kThemeSystemFont
;
822 case wxWINDOW_VARIANT_SMALL
:
823 size
= kControlSizeSmall
;
824 themeFont
= kThemeSmallSystemFont
;
826 case wxWINDOW_VARIANT_MINI
:
827 if (UMAGetSystemVersion() >= 0x1030 )
829 // not always defined in the headers
835 size
= kControlSizeSmall
;
836 themeFont
= kThemeSmallSystemFont
;
839 case wxWINDOW_VARIANT_LARGE
:
840 size
= kControlSizeLarge
;
841 themeFont
= kThemeSystemFont
;
844 wxFAIL_MSG(_T("unexpected window variant"));
847 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
850 font
.MacCreateThemeFont( themeFont
) ;
854 void wxWindowMac::MacUpdateControlFont()
856 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
860 bool wxWindowMac::SetFont(const wxFont
& font
)
862 bool retval
= !wxWindowBase::SetFont( font
) ;
864 MacUpdateControlFont() ;
869 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
871 if ( !wxWindowBase::SetForegroundColour(col
) )
874 MacUpdateControlFont() ;
879 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
881 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
885 wxColour
newCol(GetBackgroundColour());
886 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
888 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
890 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
892 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
896 brush
.SetColour( newCol
) ;
898 MacSetBackgroundBrush( brush
) ;
903 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
905 m_macBackgroundBrush
= brush
;
906 m_peer
->SetBackground( brush
) ;
909 bool wxWindowMac::MacCanFocus() const
911 // there is currently no way to determine whether the window is running in full keyboard
912 // access mode, therefore we cannot rely on these features, yet the only other way would be
913 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
914 // in event handlers...
915 UInt32 features
= 0 ;
916 m_peer
->GetFeatures( & features
) ;
917 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
921 void wxWindowMac::SetFocus()
923 if ( AcceptsFocus() )
925 #if !TARGET_API_MAC_OSX
926 wxWindow
* former
= FindFocus() ;
928 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
929 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
930 // leave in case of an error
931 if ( err
== errCouldntSetFocus
)
934 #if !TARGET_API_MAC_OSX
935 // emulate carbon events when running under carbonlib where they are not natively available
938 EventRef evRef
= NULL
;
939 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
942 wxMacCarbonEvent
cEvent( evRef
) ;
943 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
944 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
946 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
947 ReleaseEvent(evRef
) ;
949 // send new focus event
951 EventRef evRef
= NULL
;
952 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
955 wxMacCarbonEvent
cEvent( evRef
) ;
956 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
957 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
959 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
960 ReleaseEvent(evRef
) ;
967 void wxWindowMac::DoCaptureMouse()
969 wxTheApp
->s_captureWindow
= this ;
972 wxWindow
* wxWindowBase::GetCapture()
974 return wxTheApp
->s_captureWindow
;
977 void wxWindowMac::DoReleaseMouse()
979 wxTheApp
->s_captureWindow
= NULL
;
982 #if wxUSE_DRAG_AND_DROP
984 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
986 if ( m_dropTarget
!= 0 ) {
990 m_dropTarget
= pDropTarget
;
991 if ( m_dropTarget
!= 0 )
999 // Old style file-manager drag&drop
1000 void wxWindowMac::DragAcceptFiles(bool accept
)
1005 // Returns the size of the native control. In the case of the toplevel window
1006 // this is the content area root control
1008 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1009 int& w
, int& h
) const
1012 m_peer
->GetRect( &bounds
) ;
1017 w
= bounds
.right
- bounds
.left
;
1018 h
= bounds
.bottom
- bounds
.top
;
1020 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1023 Point tlworigin
= { 0 , 0 } ;
1024 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1030 // From a wx position / size calculate the appropriate size of the native control
1032 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1035 int& w
, int& h
, bool adjustOrigin
) const
1037 // the desired size, minus the border pixels gives the correct size of the control
1041 // todo the default calls may be used as soon as PostCreateControl Is moved here
1042 w
= size
.x
; // WidthDefault( size.x );
1043 h
= size
.y
; // HeightDefault( size.y ) ;
1044 #if !TARGET_API_MAC_OSX
1045 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1048 x
+= MacGetLeftBorderSize() ;
1049 y
+= MacGetTopBorderSize() ;
1050 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1051 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1054 AdjustForParentClientOrigin( x
, y
) ;
1059 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1061 // take the size of the control and add the borders that have to be drawn outside
1062 int x1
, y1
, w1
,h1
;
1063 #if TARGET_API_MAC_OSX
1064 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1068 m_peer
->GetRect( &bounds
) ;
1069 w1
= bounds
.right
- bounds
.left
;
1070 h1
= bounds
.bottom
- bounds
.top
;
1072 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1073 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1079 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1081 #if TARGET_API_MAC_OSX
1082 int x1
, y1
, w1
,h1
;
1083 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1084 x1
-= MacGetLeftBorderSize() ;
1085 y1
-= MacGetTopBorderSize() ;
1086 if ( !IsTopLevel() )
1088 wxWindow
*parent
= GetParent();
1091 wxPoint
pt(parent
->GetClientAreaOrigin());
1100 m_peer
->GetRect( &bounds
) ;
1101 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1103 int xx
= bounds
.left
;
1104 int yy
= bounds
.top
;
1105 xx
-= MacGetLeftBorderSize() ;
1106 yy
-= MacGetTopBorderSize() ;
1108 if ( !GetParent()->IsTopLevel() )
1110 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1116 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1125 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1127 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1129 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1132 Point localwhere
= {0,0} ;
1134 if(x
) localwhere
.h
= * x
;
1135 if(y
) localwhere
.v
= * y
;
1137 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1138 if(x
) *x
= localwhere
.h
;
1139 if(y
) *y
= localwhere
.v
;
1142 MacRootWindowToWindow( x
, y
) ;
1144 wxPoint origin
= GetClientAreaOrigin() ;
1145 if(x
) *x
-= origin
.x
;
1146 if(y
) *y
-= origin
.y
;
1149 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1151 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1152 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1154 wxPoint origin
= GetClientAreaOrigin() ;
1155 if(x
) *x
+= origin
.x
;
1156 if(y
) *y
+= origin
.y
;
1158 MacWindowToRootWindow( x
, y
) ;
1161 Point localwhere
= { 0,0 };
1162 if(x
) localwhere
.h
= * x
;
1163 if(y
) localwhere
.v
= * y
;
1164 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1165 if(x
) *x
= localwhere
.h
;
1166 if(y
) *y
= localwhere
.v
;
1170 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1172 wxPoint origin
= GetClientAreaOrigin() ;
1173 if(x
) *x
+= origin
.x
;
1174 if(y
) *y
+= origin
.y
;
1176 MacWindowToRootWindow( x
, y
) ;
1179 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1181 MacRootWindowToWindow( x
, y
) ;
1183 wxPoint origin
= GetClientAreaOrigin() ;
1184 if(x
) *x
-= origin
.x
;
1185 if(y
) *y
-= origin
.y
;
1188 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1190 #if TARGET_API_MAC_OSX
1192 if ( x
) pt
.x
= *x
;
1193 if ( y
) pt
.y
= *y
;
1195 if ( !IsTopLevel() )
1197 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1200 pt
.x
-= MacGetLeftBorderSize() ;
1201 pt
.y
-= MacGetTopBorderSize() ;
1202 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1206 if ( x
) *x
= (int) pt
.x
;
1207 if ( y
) *y
= (int) pt
.y
;
1209 if ( !IsTopLevel() )
1212 m_peer
->GetRect( &bounds
) ;
1213 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1214 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1219 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1224 MacWindowToRootWindow( &x1
, &y1
) ;
1229 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1231 #if TARGET_API_MAC_OSX
1233 if ( x
) pt
.x
= *x
;
1234 if ( y
) pt
.y
= *y
;
1236 if ( !IsTopLevel() )
1238 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1239 pt
.x
+= MacGetLeftBorderSize() ;
1240 pt
.y
+= MacGetTopBorderSize() ;
1243 if ( x
) *x
= (int) pt
.x
;
1244 if ( y
) *y
= (int) pt
.y
;
1246 if ( !IsTopLevel() )
1249 m_peer
->GetRect( &bounds
) ;
1250 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1251 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1256 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1261 MacRootWindowToWindow( &x1
, &y1
) ;
1266 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1268 RgnHandle rgn
= NewRgn() ;
1270 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1272 GetRegionBounds( rgn
, &content
) ;
1277 m_peer
->GetRect( &content
) ;
1280 m_peer
->GetRect( &structure
) ;
1281 #if !TARGET_API_MAC_OSX
1282 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1284 left
= content
.left
- structure
.left
;
1285 top
= content
.top
- structure
.top
;
1286 right
= structure
.right
- content
.right
;
1287 bottom
= structure
.bottom
- content
.bottom
;
1290 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1292 wxSize sizeTotal
= size
;
1294 RgnHandle rgn
= NewRgn() ;
1298 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1300 GetRegionBounds( rgn
, &content
) ;
1305 m_peer
->GetRect( &content
) ;
1308 m_peer
->GetRect( &structure
) ;
1309 #if !TARGET_API_MAC_OSX
1310 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1313 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1314 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1316 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1317 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1323 // Get size *available for subwindows* i.e. excluding menu bar etc.
1324 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1328 RgnHandle rgn
= NewRgn() ;
1330 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1332 GetRegionBounds( rgn
, &content
) ;
1337 m_peer
->GetRect( &content
) ;
1339 #if !TARGET_API_MAC_OSX
1341 m_peer
->GetRect( &structure
) ;
1342 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1344 ww
= content
.right
- content
.left
;
1345 hh
= content
.bottom
- content
.top
;
1347 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1348 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1350 if ( (m_vScrollBar
&& m_vScrollBar
->IsShown()) || (m_hScrollBar
&& m_hScrollBar
->IsShown()) )
1356 GetSize( &w
, &h
) ;
1358 MacClientToRootWindow( &x1
, &y1
) ;
1359 MacClientToRootWindow( &w
, &h
) ;
1361 wxWindowMac
*iter
= (wxWindowMac
*)this ;
1363 int totW
= 10000 , totH
= 10000;
1366 if ( iter
->IsTopLevel() )
1368 iter
->GetSize( &totW
, &totH
) ;
1372 iter
= iter
->GetParent() ;
1375 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1377 hh
-= MAC_SCROLLBAR_SIZE
;
1383 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1385 ww
-= MAC_SCROLLBAR_SIZE
;
1397 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1399 if (m_cursor
== cursor
)
1402 if (wxNullCursor
== cursor
)
1404 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1409 if ( ! wxWindowBase::SetCursor( cursor
) )
1413 wxASSERT_MSG( m_cursor
.Ok(),
1414 wxT("cursor must be valid after call to the base version"));
1417 wxWindowMac
*mouseWin
= 0 ;
1419 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1421 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1423 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1424 // position, use it...
1428 ControlPartCode part
;
1429 ControlRef control
;
1430 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1432 mouseWin
= wxFindControlFromMacControl( control
) ;
1435 QDSwapPort( savePort
, NULL
) ;
1438 if ( mouseWin
== this && !wxIsBusy() )
1440 m_cursor
.MacInstall() ;
1447 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1449 menu
->SetInvokingWindow(this);
1452 if ( x
== -1 && y
== -1 )
1454 wxPoint mouse
= wxGetMousePosition();
1455 x
= mouse
.x
; y
= mouse
.y
;
1459 ClientToScreen( &x
, &y
) ;
1462 menu
->MacBeforeDisplay( true ) ;
1463 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1464 if ( HiWord(menuResult
) != 0 )
1467 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1468 wxMenuItem
* item
= NULL
;
1470 item
= menu
->FindItem(id
, &realmenu
) ;
1471 if (item
->IsCheckable())
1473 item
->Check( !item
->IsChecked() ) ;
1475 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1477 menu
->MacAfterDisplay( true ) ;
1479 menu
->SetInvokingWindow(NULL
);
1485 // ----------------------------------------------------------------------------
1487 // ----------------------------------------------------------------------------
1491 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1493 wxWindowBase::DoSetToolTip(tooltip
);
1496 m_tooltip
->SetWindow(this);
1499 #endif // wxUSE_TOOLTIPS
1501 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1503 int former_x
, former_y
, former_w
, former_h
;
1504 #if !TARGET_API_MAC_OSX
1505 DoGetPosition( &former_x
, &former_y
) ;
1506 DoGetSize( &former_w
, &former_h
) ;
1508 MacGetPositionAndSizeFromControl( former_x
, former_y
, former_w
, former_h
) ;
1509 former_x
-= MacGetLeftBorderSize() ;
1510 former_y
-= MacGetTopBorderSize() ;
1511 former_w
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1512 former_h
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1515 int actualWidth
= width
;
1516 int actualHeight
= height
;
1520 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1521 actualWidth
= m_minWidth
;
1522 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1523 actualHeight
= m_minHeight
;
1524 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1525 actualWidth
= m_maxWidth
;
1526 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1527 actualHeight
= m_maxHeight
;
1529 bool doMove
= false ;
1530 bool doResize
= false ;
1532 if ( actualX
!= former_x
|| actualY
!= former_y
)
1536 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1541 if ( doMove
|| doResize
)
1543 // we don't adjust twice for the origin
1544 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1545 bool vis
= m_peer
->IsVisible();
1547 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1549 m_peer
->SetVisibility( false , true ) ;
1550 m_peer
->SetRect( &r
) ;
1552 m_peer
->SetVisibility( true , true ) ;
1554 MacRepositionScrollBars() ;
1557 wxPoint
point(actualX
,actualY
);
1558 wxMoveEvent
event(point
, m_windowId
);
1559 event
.SetEventObject(this);
1560 GetEventHandler()->ProcessEvent(event
) ;
1564 MacRepositionScrollBars() ;
1565 wxSize
size(actualWidth
, actualHeight
);
1566 wxSizeEvent
event(size
, m_windowId
);
1567 event
.SetEventObject(this);
1568 GetEventHandler()->ProcessEvent(event
);
1574 wxSize
wxWindowMac::DoGetBestSize() const
1576 if ( m_macIsUserPane
|| IsTopLevel() )
1577 return wxWindowBase::DoGetBestSize() ;
1579 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1580 int bestWidth
, bestHeight
;
1581 m_peer
->GetBestRect( &bestsize
) ;
1583 if ( EmptyRect( &bestsize
) )
1585 bestsize
.left
= bestsize
.top
= 0 ;
1586 bestsize
.right
= 16 ;
1587 bestsize
.bottom
= 16 ;
1588 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1590 bestsize
.bottom
= 16 ;
1592 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1594 bestsize
.bottom
= 24 ;
1598 // return wxWindowBase::DoGetBestSize() ;
1602 bestWidth
= bestsize
.right
- bestsize
.left
;
1603 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1604 if ( bestHeight
< 10 )
1607 return wxSize(bestWidth
, bestHeight
);
1611 // set the size of the window: if the dimensions are positive, just use them,
1612 // but if any of them is equal to -1, it means that we must find the value for
1613 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1614 // which case -1 is a valid value for x and y)
1616 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1617 // the width/height to best suit our contents, otherwise we reuse the current
1619 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1621 // get the current size and position...
1622 int currentX
, currentY
;
1623 GetPosition(¤tX
, ¤tY
);
1625 int currentW
,currentH
;
1626 GetSize(¤tW
, ¤tH
);
1628 // ... and don't do anything (avoiding flicker) if it's already ok
1629 if ( x
== currentX
&& y
== currentY
&&
1630 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1633 MacRepositionScrollBars() ; // we might have a real position shift
1637 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1639 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1642 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1644 wxSize
size(-1, -1);
1647 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1649 size
= DoGetBestSize();
1654 // just take the current one
1661 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1665 size
= DoGetBestSize();
1667 //else: already called DoGetBestSize() above
1673 // just take the current one
1678 DoMoveWindow(x
, y
, width
, height
);
1682 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1684 RgnHandle rgn
= NewRgn() ;
1686 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1687 GetRegionBounds( rgn
, &content
) ;
1689 #if !TARGET_API_MAC_OSX
1690 // if the content rgn is empty / not supported
1691 // don't attempt to correct the coordinates to wxWindow relative ones
1692 if (!::EmptyRect( &content
) )
1695 m_peer
->GetRect( &structure
) ;
1696 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1700 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1703 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1705 if ( clientheight
!= -1 || clientheight
!= -1 )
1707 int currentclientwidth
, currentclientheight
;
1708 int currentwidth
, currentheight
;
1710 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1711 GetSize( ¤twidth
, ¤theight
) ;
1713 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1714 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1718 void wxWindowMac::SetTitle(const wxString
& title
)
1720 m_label
= wxStripMenuCodes(title
) ;
1722 if ( m_peer
&& m_peer
->Ok() )
1724 m_peer
->SetTitle( m_label
) ;
1729 wxString
wxWindowMac::GetTitle() const
1734 bool wxWindowMac::Show(bool show
)
1736 if ( !wxWindowBase::Show(show
) )
1739 // TODO use visibilityChanged Carbon Event for OSX
1740 bool former
= MacIsReallyShown() ;
1742 m_peer
->SetVisibility( show
, true ) ;
1743 if ( former
!= MacIsReallyShown() )
1744 MacPropagateVisibilityChanged() ;
1748 bool wxWindowMac::Enable(bool enable
)
1750 wxASSERT( m_peer
->Ok() ) ;
1751 if ( !wxWindowBase::Enable(enable
) )
1754 bool former
= MacIsReallyEnabled() ;
1755 m_peer
->Enable( enable
) ;
1757 if ( former
!= MacIsReallyEnabled() )
1758 MacPropagateEnabledStateChanged() ;
1763 // status change propagations (will be not necessary for OSX later )
1766 void wxWindowMac::MacPropagateVisibilityChanged()
1768 #if !TARGET_API_MAC_OSX
1769 MacVisibilityChanged() ;
1771 wxWindowListNode
*node
= GetChildren().GetFirst();
1774 wxWindowMac
*child
= node
->GetData();
1775 if ( child
->IsShown() )
1776 child
->MacPropagateVisibilityChanged( ) ;
1777 node
= node
->GetNext();
1782 void wxWindowMac::MacPropagateEnabledStateChanged( )
1784 #if !TARGET_API_MAC_OSX
1785 MacEnabledStateChanged() ;
1787 wxWindowListNode
*node
= GetChildren().GetFirst();
1790 wxWindowMac
*child
= node
->GetData();
1791 if ( child
->IsEnabled() )
1792 child
->MacPropagateEnabledStateChanged() ;
1793 node
= node
->GetNext();
1798 void wxWindowMac::MacPropagateHiliteChanged( )
1800 #if !TARGET_API_MAC_OSX
1801 MacHiliteChanged() ;
1803 wxWindowListNode
*node
= GetChildren().GetFirst();
1806 wxWindowMac
*child
= node
->GetData();
1807 // if ( child->IsEnabled() )
1808 child
->MacPropagateHiliteChanged() ;
1809 node
= node
->GetNext();
1815 // status change notifications
1818 void wxWindowMac::MacVisibilityChanged()
1822 void wxWindowMac::MacHiliteChanged()
1826 void wxWindowMac::MacEnabledStateChanged()
1831 // status queries on the inherited window's state
1834 bool wxWindowMac::MacIsReallyShown()
1836 // only under OSX the visibility of the TLW is taken into account
1837 #if TARGET_API_MAC_OSX
1838 if ( m_peer
&& m_peer
->Ok() )
1839 return m_peer
->IsVisible();
1841 wxWindow
* win
= this ;
1842 while( win
->IsShown() )
1844 if ( win
->IsTopLevel() )
1847 win
= win
->GetParent() ;
1855 bool wxWindowMac::MacIsReallyEnabled()
1857 return m_peer
->IsEnabled() ;
1860 bool wxWindowMac::MacIsReallyHilited()
1862 return m_peer
->IsActive();
1865 void wxWindowMac::MacFlashInvalidAreas()
1867 #if TARGET_API_MAC_OSX
1868 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1876 int wxWindowMac::GetCharHeight() const
1878 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1879 return dc
.GetCharHeight() ;
1882 int wxWindowMac::GetCharWidth() const
1884 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1885 return dc
.GetCharWidth() ;
1888 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1889 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1891 const wxFont
*fontToUse
= theFont
;
1893 fontToUse
= &m_font
;
1895 wxClientDC
dc( (wxWindowMac
*) this ) ;
1897 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1898 if ( externalLeading
)
1899 *externalLeading
= le
;
1909 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1910 * we always intersect with the entire window, not only with the client area
1913 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1915 if ( m_peer
== NULL
)
1918 #if TARGET_API_MAC_OSX
1920 m_peer
->SetNeedsDisplay( true ) ;
1923 RgnHandle update
= NewRgn() ;
1924 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1925 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1926 wxPoint origin
= GetClientAreaOrigin() ;
1927 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1928 m_peer
->SetNeedsDisplay( true , update
) ;
1932 RgnHandle updateRgn = NewRgn() ;
1935 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1939 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1940 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1942 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1943 DisposeRgn(updateRgn) ;
1945 if ( m_peer
->IsVisible())
1947 m_peer
->SetVisibility( false , false ) ;
1948 m_peer
->SetVisibility( true , true ) ;
1951 if ( MacGetTopLevelWindow() == NULL )
1954 if ( !m_peer->IsVisible())
1957 wxPoint client = GetClientAreaOrigin();
1960 int x2 = m_width - client.x;
1961 int y2 = m_height - client.y;
1963 if (IsKindOf( CLASSINFO(wxButton)))
1965 // buttons have an "aura"
1972 Rect clientrect = { y1, x1, y2, x2 };
1976 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
1977 SectRect( &clientrect , &r , &clientrect ) ;
1980 if ( !EmptyRect( &clientrect ) )
1982 int top = 0 , left = 0 ;
1984 MacClientToRootWindow( &left , &top ) ;
1985 OffsetRect( &clientrect , left , top ) ;
1987 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
1993 void wxWindowMac::Freeze()
1995 #if TARGET_API_MAC_OSX
1996 if ( !m_frozenness
++ )
1998 m_peer
->SetDrawingEnabled( false ) ;
2004 void wxWindowMac::Thaw()
2006 #if TARGET_API_MAC_OSX
2007 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2009 if ( !--m_frozenness
)
2011 m_peer
->SetDrawingEnabled( true ) ;
2012 m_peer
->InvalidateWithChildren() ;
2017 void wxWindowMac::MacRedrawControl()
2020 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2022 #if TARGET_API_MAC_CARBON
2025 wxClientDC dc(this) ;
2026 wxMacPortSetter helper(&dc) ;
2027 wxMacWindowClipper clipper(this) ;
2028 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2029 UMADrawControl( *m_peer ) ;
2036 void wxWindowMac::OnPaint(wxPaintEvent& event)
2038 // why don't we skip that here ?
2042 wxWindowMac
*wxGetActiveWindow()
2044 // actually this is a windows-only concept
2048 // Coordinates relative to the window
2049 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2051 // We really don't move the mouse programmatically under Mac.
2054 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2056 #if TARGET_API_MAC_OSX
2057 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2063 event
.GetDC()->Clear() ;
2066 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2068 wxWindowDC
dc(this) ;
2069 wxMacPortSetter
helper(&dc
) ;
2071 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2074 int wxWindowMac::GetScrollPos(int orient
) const
2076 if ( orient
== wxHORIZONTAL
)
2079 return m_hScrollBar
->GetThumbPosition() ;
2084 return m_vScrollBar
->GetThumbPosition() ;
2089 // This now returns the whole range, not just the number
2090 // of positions that we can scroll.
2091 int wxWindowMac::GetScrollRange(int orient
) const
2093 if ( orient
== wxHORIZONTAL
)
2096 return m_hScrollBar
->GetRange() ;
2101 return m_vScrollBar
->GetRange() ;
2106 int wxWindowMac::GetScrollThumb(int orient
) const
2108 if ( orient
== wxHORIZONTAL
)
2111 return m_hScrollBar
->GetThumbSize() ;
2116 return m_vScrollBar
->GetThumbSize() ;
2121 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2123 if ( orient
== wxHORIZONTAL
)
2126 m_hScrollBar
->SetThumbPosition( pos
) ;
2131 m_vScrollBar
->SetThumbPosition( pos
) ;
2135 void wxWindowMac::MacPaintBorders( int left
, int top
)
2141 wxGetOsVersion( &major
, &minor
);
2143 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2144 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2145 // OS X has lighter border edges than classic:
2148 darkShadow
.red
= 0x8E8E;
2149 darkShadow
.green
= 0x8E8E;
2150 darkShadow
.blue
= 0x8E8E;
2151 lightShadow
.red
= 0xBDBD;
2152 lightShadow
.green
= 0xBDBD;
2153 lightShadow
.blue
= 0xBDBD;
2159 GetSize( &w
, &h
) ;
2160 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2161 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2163 #if wxMAC_USE_THEME_BORDER
2165 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2166 InsetRect( &rect
, border
, border
);
2167 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2169 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2170 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2172 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2173 RGBForeColor( &face
);
2174 MoveTo( left
+ 0 , top
+ h
- 2 );
2175 LineTo( left
+ 0 , top
+ 0 );
2176 LineTo( left
+ w
- 2 , top
+ 0 );
2178 MoveTo( left
+ 2 , top
+ h
- 3 );
2179 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2180 LineTo( left
+ w
- 3 , top
+ 2 );
2182 RGBForeColor( sunken
? &face
: &darkShadow
);
2183 MoveTo( left
+ 0 , top
+ h
- 1 );
2184 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2185 LineTo( left
+ w
- 1 , top
+ 0 );
2187 RGBForeColor( sunken
? &lightShadow
: &white
);
2188 MoveTo( left
+ 1 , top
+ h
- 3 );
2189 LineTo( left
+ 1, top
+ 1 );
2190 LineTo( left
+ w
- 3 , top
+ 1 );
2192 RGBForeColor( sunken
? &white
: &lightShadow
);
2193 MoveTo( left
+ 1 , top
+ h
- 2 );
2194 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2195 LineTo( left
+ w
- 2 , top
+ 1 );
2197 RGBForeColor( sunken
? &darkShadow
: &face
);
2198 MoveTo( left
+ 2 , top
+ h
- 4 );
2199 LineTo( left
+ 2 , top
+ 2 );
2200 LineTo( left
+ w
- 4 , top
+ 2 );
2203 else if (HasFlag(wxSIMPLE_BORDER
))
2205 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2206 RGBForeColor( &darkShadow
) ;
2207 FrameRect( &rect
) ;
2211 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2213 if ( child
== m_hScrollBar
)
2214 m_hScrollBar
= NULL
;
2215 if ( child
== m_vScrollBar
)
2216 m_vScrollBar
= NULL
;
2218 wxWindowBase::RemoveChild( child
) ;
2221 // New function that will replace some of the above.
2222 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2223 int range
, bool refresh
)
2225 if ( orient
== wxHORIZONTAL
)
2229 if ( range
== 0 || thumbVisible
>= range
)
2231 if ( m_hScrollBar
->IsShown() )
2232 m_hScrollBar
->Show(false) ;
2236 if ( !m_hScrollBar
->IsShown() )
2237 m_hScrollBar
->Show(true) ;
2238 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2246 if ( range
== 0 || thumbVisible
>= range
)
2248 if ( m_vScrollBar
->IsShown() )
2249 m_vScrollBar
->Show(false) ;
2253 if ( !m_vScrollBar
->IsShown() )
2254 m_vScrollBar
->Show(true) ;
2255 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2259 MacRepositionScrollBars() ;
2262 // Does a physical scroll
2263 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2265 if( dx
== 0 && dy
==0 )
2271 int width
, height
;
2272 GetClientSize( &width
, &height
) ;
2273 #if TARGET_API_MAC_OSX
2274 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2275 // area is scrolled, this does not occur if width and height are 2 pixels less,
2276 // TODO write optimal workaround
2277 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width
, MacGetTopBorderSize() + height
) ;
2280 scrollrect
.Intersect( *rect
) ;
2282 if ( m_peer
->GetNeedsDisplay() )
2284 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2285 // either immediate redraw or full invalidate
2287 // is the better overall solution, as it does not slow down scrolling
2288 m_peer
->SetNeedsDisplay( true ) ;
2290 // this would be the preferred version for fast drawing controls
2291 if( UMAGetSystemVersion() < 0x1030 )
2294 HIViewRender(*m_peer
) ;
2297 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2304 RgnHandle updateRgn
= NewRgn() ;
2307 wxClientDC
dc(this) ;
2308 wxMacPortSetter
helper(&dc
) ;
2310 m_peer
->GetRect( &scrollrect
) ;
2311 scrollrect
.top
+= MacGetTopBorderSize() ;
2312 scrollrect
.left
+= MacGetLeftBorderSize() ;
2313 scrollrect
.bottom
= scrollrect
.top
+ height
;
2314 scrollrect
.right
= scrollrect
.left
+ width
;
2318 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2319 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2320 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2322 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2324 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2328 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2330 wxWindowMac
*child
= node
->GetData();
2331 if (child
== m_vScrollBar
) continue;
2332 if (child
== m_hScrollBar
) continue;
2333 if (child
->IsTopLevel()) continue;
2336 child
->GetPosition( &x
, &y
);
2338 child
->GetSize( &w
, &h
);
2342 if (rect
->Intersects(rc
))
2343 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2347 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2352 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2354 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2356 wxScrollWinEvent wevent
;
2357 wevent
.SetPosition(event
.GetPosition());
2358 wevent
.SetOrientation(event
.GetOrientation());
2359 wevent
.m_eventObject
= this;
2361 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2362 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2363 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2364 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2365 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2366 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2367 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2368 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2369 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2370 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2371 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2372 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2373 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2374 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2375 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2376 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2378 GetEventHandler()->ProcessEvent(wevent
);
2382 // Get the window with the focus
2383 wxWindowMac
*wxWindowBase::FindFocus()
2385 ControlRef control
;
2386 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2387 return wxFindControlFromMacControl( control
) ;
2390 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2392 // panel wants to track the window which was the last to have focus in it,
2393 // so we want to set ourselves as the window which last had focus
2395 // notice that it's also important to do it upwards the tree becaus
2396 // otherwise when the top level panel gets focus, it won't set it back to
2397 // us, but to some other sibling
2399 // CS:don't know if this is still needed:
2400 //wxChildFocusEvent eventFocus(this);
2401 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2403 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2405 wxMacWindowStateSaver
sv( this ) ;
2410 MacWindowToRootWindow( &x
, &y
) ;
2411 GetSize( &w
, &h
) ;
2412 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2414 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2415 DrawThemeFocusRect( &rect
, true ) ;
2417 DrawThemeFocusRect( &rect
, false ) ;
2423 void wxWindowMac::OnInternalIdle()
2425 // This calls the UI-update mechanism (querying windows for
2426 // menu/toolbar/control state information)
2427 if (wxUpdateUIEvent::CanUpdate(this))
2428 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2431 // Raise the window to the top of the Z order
2432 void wxWindowMac::Raise()
2434 m_peer
->SetZOrder( true , NULL
) ;
2437 // Lower the window to the bottom of the Z order
2438 void wxWindowMac::Lower()
2440 m_peer
->SetZOrder( false , NULL
) ;
2444 // static wxWindow *gs_lastWhich = NULL;
2446 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2448 // first trigger a set cursor event
2450 wxPoint clientorigin
= GetClientAreaOrigin() ;
2451 wxSize clientsize
= GetClientSize() ;
2453 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2455 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2457 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2458 if ( processedEvtSetCursor
&& event
.HasCursor() )
2460 cursor
= event
.GetCursor() ;
2465 // the test for processedEvtSetCursor is here to prevent using m_cursor
2466 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2467 // it - this is a way to say that our cursor shouldn't be used for this
2469 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2479 cursor
= *wxSTANDARD_CURSOR
;
2483 cursor
.MacInstall() ;
2485 return cursor
.Ok() ;
2488 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2492 return m_tooltip
->GetTip() ;
2494 return wxEmptyString
;
2497 void wxWindowMac::Update()
2499 #if TARGET_API_MAC_OSX
2500 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2501 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2502 // for composited windows this also triggers a redraw of all
2503 // invalid views in the window
2504 if( UMAGetSystemVersion() >= 0x1030 )
2505 HIWindowFlush(window
) ;
2509 // the only way to trigger the redrawing on earlier systems is to call
2512 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2513 UInt32 currentEventClass
= 0 ;
2514 UInt32 currentEventKind
= 0 ;
2515 if ( currentEvent
!= NULL
)
2517 currentEventClass
= ::GetEventClass( currentEvent
) ;
2518 currentEventKind
= ::GetEventKind( currentEvent
) ;
2520 if ( currentEventClass
!= kEventClassMenu
)
2522 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2525 OSStatus status
= noErr
;
2526 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2529 m_peer
->SetNeedsDisplay( true ) ;
2532 ::Draw1Control( m_peer
->GetControlRef() ) ;
2536 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2538 wxTopLevelWindowMac
* win
= NULL
;
2539 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2542 win
= wxFindWinFromMacWindow( window
) ;
2546 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2550 RgnHandle visRgn
= NewRgn() ;
2551 RgnHandle tempRgn
= NewRgn() ;
2552 if ( m_peer
->IsVisible())
2554 m_peer
->GetRect( &r
) ;
2555 r
.left
-= MacGetLeftBorderSize() ;
2556 r
.top
-= MacGetTopBorderSize() ;
2557 r
.bottom
+= MacGetBottomBorderSize() ;
2558 r
.right
+= MacGetRightBorderSize() ;
2560 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2562 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2563 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2572 if ( includeOuterStructures
)
2573 InsetRect( &r
, -3 , -3 ) ;
2574 RectRgn( visRgn
, &r
) ;
2575 if ( !IsTopLevel() )
2577 wxWindow
* child
= this ;
2578 wxWindow
* parent
= child
->GetParent() ;
2583 // we have to find a better clipping algorithm here, in order not to clip things
2584 // positioned like status and toolbar
2585 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2587 size
= parent
->GetSize() ;
2592 size
= parent
->GetClientSize() ;
2593 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2597 parent
->MacWindowToRootWindow( &x
, &y
) ;
2598 MacRootWindowToWindow( &x
, &y
) ;
2600 SetRectRgn( tempRgn
,
2601 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2602 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2603 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2605 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2606 if ( parent
->IsTopLevel() )
2609 parent
= child
->GetParent() ;
2614 wxRegion vis
= visRgn
;
2615 DisposeRgn( visRgn
) ;
2616 DisposeRgn( tempRgn
) ;
2621 This function must not change the updatergn !
2623 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2625 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2626 bool handled
= false ;
2628 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2630 RgnHandle newupdate
= NewRgn() ;
2631 wxSize point
= GetClientSize() ;
2632 wxPoint origin
= GetClientAreaOrigin() ;
2633 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2634 SectRgn( newupdate
, updatergn
, newupdate
) ;
2635 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2636 m_updateRegion
= newupdate
;
2637 DisposeRgn( newupdate
) ;
2640 if ( !EmptyRgn(updatergn
) )
2642 wxWindowDC
dc(this);
2643 if (!EmptyRgn(updatergn
))
2644 dc
.SetClippingRegion(wxRegion(updatergn
));
2646 wxEraseEvent
eevent( GetId(), &dc
);
2647 eevent
.SetEventObject( this );
2648 GetEventHandler()->ProcessEvent( eevent
);
2650 if ( !m_updateRegion
.Empty() )
2652 // paint the window itself
2654 event
.m_timeStamp
= time
;
2655 event
.SetEventObject(this);
2656 handled
= GetEventHandler()->ProcessEvent(event
);
2658 // paint custom borders
2659 wxNcPaintEvent
eventNc( GetId() );
2660 eventNc
.SetEventObject( this );
2661 GetEventHandler()->ProcessEvent( eventNc
);
2667 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2669 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2670 // updatergn is always already clipped to our boundaries
2671 // if we are in compositing mode then it is in relative to the upper left of the control
2672 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2673 // of the toplevel window
2674 // it is in window coordinates, not in client coordinates
2676 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2677 RgnHandle ownUpdateRgn
= NewRgn() ;
2678 CopyRgn( updatergn
, ownUpdateRgn
) ;
2680 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2683 m_peer
->GetRectInWindowCoords( &bounds
);
2684 RgnHandle controlRgn
= NewRgn();
2685 RectRgn( controlRgn
, &bounds
);
2686 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2687 // the window update region
2688 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2689 DisposeRgn( controlRgn
);
2691 //KO: convert ownUpdateRgn to local coordinates
2692 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2695 MacDoRedraw( ownUpdateRgn
, time
) ;
2696 DisposeRgn( ownUpdateRgn
) ;
2700 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2702 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2706 if ( iter
->IsTopLevel() )
2707 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2709 iter
= iter
->GetParent() ;
2711 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2715 void wxWindowMac::MacCreateScrollBars( long style
)
2717 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2721 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2722 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2724 GetClientSize( &width
, &height
) ;
2726 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2727 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2728 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2729 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2731 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2732 vSize
, wxVERTICAL
);
2734 if ( style
& wxVSCROLL
)
2740 m_vScrollBar
->Show(false) ;
2742 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2743 hSize
, wxHORIZONTAL
);
2744 if ( style
& wxHSCROLL
)
2749 m_hScrollBar
->Show(false) ;
2752 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2754 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2755 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1: 0 ;
2757 GetClientSize( &width
, &height
) ;
2759 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2760 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2761 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2762 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2765 if ( style
& wxVSCROLL
)
2767 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2768 vSize
, wxVERTICAL
);
2771 if ( style
& wxHSCROLL
)
2773 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2774 hSize
, wxHORIZONTAL
);
2780 // because the create does not take into account the client area origin
2781 MacRepositionScrollBars() ; // we might have a real position shift
2784 void wxWindowMac::MacRepositionScrollBars()
2786 if ( !m_hScrollBar
&& !m_vScrollBar
)
2789 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2790 int adjust
= hasBoth
? MAC_SCROLLBAR_SIZE
- 1 : 0 ;
2792 // get real client area
2796 GetSize( &width
, &height
) ;
2798 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2799 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2801 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2802 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2803 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2804 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2810 GetSize( &w
, &h
) ;
2812 MacClientToRootWindow( &x
, &y
) ;
2813 MacClientToRootWindow( &w
, &h
) ;
2815 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2817 int totW
= 10000 , totH
= 10000;
2820 if ( iter
->IsTopLevel() )
2822 iter
->GetSize( &totW
, &totH
) ;
2826 iter
= iter
->GetParent() ;
2854 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2858 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2862 bool wxWindowMac::AcceptsFocus() const
2864 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2867 void wxWindowMac::MacSuperChangedPosition()
2869 // only window-absolute structures have to be moved i.e. controls
2871 wxWindowListNode
*node
= GetChildren().GetFirst();
2874 wxWindowMac
*child
= node
->GetData();
2875 child
->MacSuperChangedPosition() ;
2876 node
= node
->GetNext();
2880 void wxWindowMac::MacTopLevelWindowChangedPosition()
2882 // only screen-absolute structures have to be moved i.e. glcanvas
2884 wxWindowListNode
*node
= GetChildren().GetFirst();
2887 wxWindowMac
*child
= node
->GetData();
2888 child
->MacTopLevelWindowChangedPosition() ;
2889 node
= node
->GetNext();
2893 long wxWindowMac::MacGetLeftBorderSize( ) const
2898 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2903 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2908 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2915 long wxWindowMac::MacGetRightBorderSize( ) const
2917 // they are all symmetric in mac themes
2918 return MacGetLeftBorderSize() ;
2921 long wxWindowMac::MacGetTopBorderSize( ) const
2923 // they are all symmetric in mac themes
2924 return MacGetLeftBorderSize() ;
2927 long wxWindowMac::MacGetBottomBorderSize( ) const
2929 // they are all symmetric in mac themes
2930 return MacGetLeftBorderSize() ;
2933 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2935 return style
& ~wxBORDER_MASK
;
2938 // Find the wxWindowMac at the current mouse position, returning the mouse
2940 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2942 pt
= wxGetMousePosition();
2943 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2947 // Get the current mouse position.
2948 wxPoint
wxGetMousePosition()
2951 wxGetMousePosition(& x
, & y
);
2952 return wxPoint(x
, y
);
2955 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2957 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2959 // copied from wxGTK : CS
2960 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2963 // (a) it's a command event and so is propagated to the parent
2964 // (b) under MSW it can be generated from kbd too
2965 // (c) it uses screen coords (because of (a))
2966 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2968 this->ClientToScreen(event
.GetPosition()));
2969 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2978 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2982 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2986 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
2987 Rect bounds
= { y
, x
, y
+h
, x
+w
};
2991 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
2993 return eventNotHandledErr
;