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
50 #define MAC_SCROLLBAR_SIZE 15
51 #define MAC_SMALL_SCROLLBAR_SIZE 11
53 #include "wx/mac/uma.h"
56 #include <ToolUtils.h>
58 #include <MacTextEditor.h>
61 #if TARGET_API_MAC_OSX
63 #include <HIToolbox/HIView.h>
67 #if wxUSE_DRAG_AND_DROP
73 extern wxList wxPendingDelete
;
75 #ifdef __WXUNIVERSAL__
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
78 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
79 #endif // __WXUNIVERSAL__/__WXMAC__
81 #if !USE_SHARED_LIBRARY
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
85 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
86 // TODO EVT_PAINT(wxWindowMac::OnPaint)
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
103 // ---------------------------------------------------------------------------
105 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
106 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
108 #if TARGET_API_MAC_OSX
110 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
112 kEventControlVisibilityChanged
= 157
118 static const EventTypeSpec eventList
[] =
120 { kEventClassControl
, kEventControlHit
} ,
121 #if TARGET_API_MAC_OSX
122 { kEventClassControl
, kEventControlDraw
} ,
123 { kEventClassControl
, kEventControlVisibilityChanged
} ,
124 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
125 { kEventClassControl
, kEventControlHiliteChanged
} ,
126 { kEventClassControl
, kEventControlSetFocusPart
} ,
128 { kEventClassService
, kEventServiceGetTypes
},
129 { kEventClassService
, kEventServiceCopy
},
130 { kEventClassService
, kEventServicePaste
},
132 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
133 // { kEventClassControl , kEventControlBoundsChanged } ,
137 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
139 OSStatus result
= eventNotHandledErr
;
141 wxMacCarbonEvent
cEvent( event
) ;
143 ControlRef controlRef
;
144 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
146 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
148 switch( GetEventKind( event
) )
150 #if TARGET_API_MAC_OSX
151 case kEventControlDraw
:
153 RgnHandle updateRgn
= NULL
;
154 RgnHandle allocatedRgn
= NULL
;
155 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
156 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
158 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
162 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
164 allocatedRgn
= NewRgn() ;
165 CopyRgn( updateRgn
, allocatedRgn
) ;
166 OffsetRgn( updateRgn
, thisWindow
->MacGetLeftBorderSize() , thisWindow
->MacGetTopBorderSize() ) ;
171 // in case we would need a coregraphics compliant background erase first
172 // now usable to track redraws
173 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
174 if ( thisWindow
->MacIsUserPane() )
176 static float color
= 0.5 ;
179 HIViewGetBounds( controlRef
, &bounds
);
180 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
181 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
182 CGContextFillRect( cgContext
, bounds
);
193 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
196 DisposeRgn( allocatedRgn
) ;
199 case kEventControlVisibilityChanged
:
200 thisWindow
->MacVisibilityChanged() ;
202 case kEventControlEnabledStateChanged
:
203 thisWindow
->MacEnabledStateChanged() ;
205 case kEventControlHiliteChanged
:
206 thisWindow
->MacHiliteChanged() ;
208 case kEventControlSetFocusPart
:
210 Boolean focusEverything
= false ;
211 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
212 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
215 if ( controlPart
== kControlFocusNoPart
)
218 if ( thisWindow
->GetCaret() )
220 thisWindow
->GetCaret()->OnKillFocus();
222 #endif // wxUSE_CARET
223 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
224 event
.SetEventObject(thisWindow
);
225 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
229 // panel wants to track the window which was the last to have focus in it
230 wxChildFocusEvent
eventFocus(thisWindow
);
231 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
234 if ( thisWindow
->GetCaret() )
236 thisWindow
->GetCaret()->OnSetFocus();
238 #endif // wxUSE_CARET
240 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
241 event
.SetEventObject(thisWindow
);
242 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
244 if ( thisWindow
->MacIsUserPane() )
249 case kEventControlHit
:
251 result
= thisWindow
->MacControlHit( handler
, event
) ;
260 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
262 OSStatus result
= eventNotHandledErr
;
264 wxMacCarbonEvent
cEvent( event
) ;
266 ControlRef controlRef
;
267 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
268 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
269 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
271 switch( GetEventKind( event
) )
273 case kEventServiceGetTypes
:
277 textCtrl
->GetSelection( &from
, &to
) ;
279 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
281 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
282 if ( textCtrl
->IsEditable() )
283 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
285 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
286 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
288 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
292 CFArrayAppendValue (copyTypes
, typestring
) ;
294 CFArrayAppendValue (pasteTypes
, typestring
) ;
295 CFRelease( typestring
) ;
301 case kEventServiceCopy
:
305 textCtrl
->GetSelection( &from
, &to
) ;
306 wxString val
= textCtrl
->GetValue() ;
307 val
= val
.Mid( from
, to
- from
) ;
308 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
309 verify_noerr( ClearScrap( &scrapRef
) ) ;
310 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
314 case kEventServicePaste
:
317 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
318 Size textSize
, pastedSize
;
319 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
321 char *content
= new char[textSize
] ;
322 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
323 content
[textSize
-1] = 0 ;
325 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
327 textCtrl
->WriteText( wxString( content
) ) ;
338 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
340 OSStatus result
= eventNotHandledErr
;
342 switch ( GetEventClass( event
) )
344 case kEventClassControl
:
345 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
347 case kEventClassService
:
348 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
355 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
357 // ---------------------------------------------------------------------------
358 // UserPane events for non OSX builds
359 // ---------------------------------------------------------------------------
361 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
363 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
364 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
365 win
->MacControlUserPaneDrawProc(part
) ;
368 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
370 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
371 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
372 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
375 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
377 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
378 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
379 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
382 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
384 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
385 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
386 win
->MacControlUserPaneIdleProc() ;
389 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
391 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
392 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
393 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
396 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
398 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
399 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
400 win
->MacControlUserPaneActivateProc(activating
) ;
403 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
405 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
406 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
407 return win
->MacControlUserPaneFocusProc(action
) ;
410 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
412 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
413 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
414 win
->MacControlUserPaneBackgroundProc(info
) ;
417 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
419 RgnHandle rgn
= NewRgn() ;
421 wxMacWindowStateSaver
sv( this ) ;
422 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
423 MacDoRedraw( rgn
, 0 ) ;
427 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
429 return kControlNoPart
;
432 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
434 return kControlNoPart
;
437 void wxWindowMac::MacControlUserPaneIdleProc()
441 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
443 return kControlNoPart
;
446 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
450 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
452 return kControlNoPart
;
455 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
459 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
460 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
461 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
462 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
463 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
464 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
465 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
466 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
468 // ===========================================================================
470 // ===========================================================================
472 wxList
wxWinMacControlList(wxKEY_INTEGER
);
474 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
476 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
479 return (wxControl
*)node
->GetData();
482 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
484 // adding NULL ControlRef is (first) surely a result of an error and
485 // (secondly) breaks native event processing
486 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
488 if ( !wxWinMacControlList
.Find((long)inControl
) )
489 wxWinMacControlList
.Append((long)inControl
, control
);
492 void wxRemoveMacControlAssociation(wxWindow
*control
)
494 wxWinMacControlList
.DeleteObject(control
);
498 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
500 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
502 // we have to setup the brush in the current port and return noErr
503 // or return an error code so that the control manager walks further up the
504 // hierarchy to find a correct background
506 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
508 OSStatus status
= paramErr
;
511 case kControlMsgApplyTextColor
:
513 case kControlMsgSetUpBackground
:
515 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
519 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
522 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
524 // this clipping is only needed for non HIView
526 RgnHandle clip
= NewRgn() ;
529 wx
->MacWindowToRootWindow( &x
,&y
) ;
530 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
531 OffsetRgn( clip
, x
, y
) ;
538 else if ( wx->MacIsUserPane() )
540 // if we don't have a valid brush for such a control, we have to call the
541 // setup of our parent ourselves
542 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
555 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
556 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
560 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
563 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
568 // ----------------------------------------------------------------------------
569 // constructors and such
570 // ----------------------------------------------------------------------------
572 wxWindowMac::wxWindowMac()
577 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
582 const wxString
& name
)
585 Create(parent
, id
, pos
, size
, style
, name
);
588 void wxWindowMac::Init()
592 #if WXWIN_COMPATIBILITY_2_4
593 m_backgroundTransparent
= FALSE
;
596 // as all windows are created with WS_VISIBLE style...
599 m_hScrollBar
= NULL
;
600 m_vScrollBar
= NULL
;
601 m_macBackgroundBrush
= wxNullBrush
;
603 m_macIsUserPane
= TRUE
;
605 // make sure all proc ptrs are available
607 if ( gControlUserPaneDrawUPP
== NULL
)
609 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
610 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
611 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
612 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
613 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
614 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
615 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
616 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
618 if ( wxMacLiveScrollbarActionUPP
== NULL
)
620 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
623 if ( wxMacSetupControlBackgroundUPP
== NULL
)
625 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
628 // we need a valid font for the encodings
629 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
633 wxWindowMac::~wxWindowMac()
637 m_isBeingDeleted
= TRUE
;
639 #ifndef __WXUNIVERSAL__
640 // VS: make sure there's no wxFrame with last focus set to us:
641 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
643 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
646 if ( frame
->GetLastFocus() == this )
648 frame
->SetLastFocus((wxWindow
*)NULL
);
653 #endif // __WXUNIVERSAL__
655 // wxRemoveMacControlAssociation( this ) ;
656 // If we delete an item, we should initialize the parent panel,
657 // because it could now be invalid.
658 wxWindow
*parent
= GetParent() ;
661 if (parent
->GetDefaultItem() == (wxButton
*) this)
662 parent
->SetDefaultItem(NULL
);
664 if ( m_peer
&& m_peer
->Ok() )
666 // in case the callback might be called during destruction
667 wxRemoveMacControlAssociation( this) ;
668 // we currently are not using this hook
669 // ::SetControlColorProc( *m_peer , NULL ) ;
673 if ( g_MacLastWindow
== this )
675 g_MacLastWindow
= NULL
;
678 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
681 if ( frame
->GetLastFocus() == this )
682 frame
->SetLastFocus( NULL
) ;
687 // delete our drop target if we've got one
688 #if wxUSE_DRAG_AND_DROP
689 if ( m_dropTarget
!= NULL
)
694 #endif // wxUSE_DRAG_AND_DROP
698 WXWidget
wxWindowMac::GetHandle() const
700 return (WXWidget
) m_peer
->GetControlRef() ;
704 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
706 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
707 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
708 GetEventTypeCount(eventList
), eventList
, this,
709 (EventHandlerRef
*)&m_macControlEventHandler
);
714 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
718 const wxString
& name
)
720 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
722 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
725 parent
->AddChild(this);
727 m_windowVariant
= parent
->GetWindowVariant() ;
729 if ( m_macIsUserPane
)
731 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
734 | kControlSupportsEmbedding
735 // | kControlSupportsLiveFeedback
736 // | kControlHasSpecialBackground
737 // | kControlSupportsCalcBestRect
738 // | kControlHandlesTracking
739 | kControlSupportsFocus
740 // | kControlWantsActivate
741 // | kControlWantsIdle
744 m_peer
= new wxMacControl() ;
745 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
748 MacPostControlCreate(pos
,size
) ;
749 #if !TARGET_API_MAC_OSX
750 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
751 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
752 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
753 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
754 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
755 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
756 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
757 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
760 #ifndef __WXUNIVERSAL__
761 // Don't give scrollbars to wxControls unless they ask for them
762 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
763 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
765 MacCreateScrollBars( style
) ;
769 wxWindowCreateEvent
event(this);
770 GetEventHandler()->AddPendingEvent(event
);
775 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
777 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
779 m_peer
->SetReference( (long) this ) ;
781 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
783 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
784 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
785 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
787 // adjust font, controlsize etc
788 DoSetWindowVariant( m_windowVariant
) ;
790 #if !TARGET_API_MAC_OSX
791 // eventually we can fix some clipping issues be reactivating this hook
792 //if ( m_macIsUserPane )
793 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
795 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
797 if (!m_macIsUserPane
)
799 SetInitialBestSize(size
);
802 SetCursor( *wxSTANDARD_CURSOR
) ;
805 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
807 // Don't assert, in case we set the window variant before
808 // the window is created
809 // wxASSERT( m_peer->Ok() ) ;
811 m_windowVariant
= variant
;
813 if (m_peer
== NULL
|| !m_peer
->Ok())
817 ThemeFontID themeFont
= kThemeSystemFont
;
819 // we will get that from the settings later
820 // and make this NORMAL later, but first
821 // we have a few calculations that we must fix
825 case wxWINDOW_VARIANT_NORMAL
:
826 size
= kControlSizeNormal
;
827 themeFont
= kThemeSystemFont
;
829 case wxWINDOW_VARIANT_SMALL
:
830 size
= kControlSizeSmall
;
831 themeFont
= kThemeSmallSystemFont
;
833 case wxWINDOW_VARIANT_MINI
:
834 if (UMAGetSystemVersion() >= 0x1030 )
836 // not always defined in the headers
842 size
= kControlSizeSmall
;
843 themeFont
= kThemeSmallSystemFont
;
846 case wxWINDOW_VARIANT_LARGE
:
847 size
= kControlSizeLarge
;
848 themeFont
= kThemeSystemFont
;
851 wxFAIL_MSG(_T("unexpected window variant"));
854 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
857 font
.MacCreateThemeFont( themeFont
) ;
861 void wxWindowMac::MacUpdateControlFont()
863 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
867 bool wxWindowMac::SetFont(const wxFont
& font
)
869 bool retval
= !wxWindowBase::SetFont( font
) ;
871 MacUpdateControlFont() ;
876 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
878 if ( !wxWindowBase::SetForegroundColour(col
) )
881 MacUpdateControlFont() ;
886 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
888 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
892 wxColour
newCol(GetBackgroundColour());
893 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
895 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
897 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
899 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
903 brush
.SetColour( newCol
) ;
905 MacSetBackgroundBrush( brush
) ;
907 MacUpdateControlFont() ;
912 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
914 m_macBackgroundBrush
= brush
;
915 m_peer
->SetBackground( brush
) ;
918 bool wxWindowMac::MacCanFocus() const
920 // there is currently no way to determine whether the window is running in full keyboard
921 // access mode, therefore we cannot rely on these features, yet the only other way would be
922 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
923 // in event handlers...
924 UInt32 features
= 0 ;
925 m_peer
->GetFeatures( & features
) ;
926 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
930 void wxWindowMac::SetFocus()
932 if ( AcceptsFocus() )
934 #if !TARGET_API_MAC_OSX
935 wxWindow
* former
= FindFocus() ;
937 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
938 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
939 // leave in case of an error
940 if ( err
== errCouldntSetFocus
)
943 #if !TARGET_API_MAC_OSX
944 // emulate carbon events when running under carbonlib where they are not natively available
947 EventRef evRef
= NULL
;
948 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
951 wxMacCarbonEvent
cEvent( evRef
) ;
952 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
953 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
955 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
956 ReleaseEvent(evRef
) ;
958 // send new focus event
960 EventRef evRef
= NULL
;
961 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
964 wxMacCarbonEvent
cEvent( evRef
) ;
965 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
966 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
968 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
969 ReleaseEvent(evRef
) ;
976 void wxWindowMac::DoCaptureMouse()
978 wxTheApp
->s_captureWindow
= this ;
981 wxWindow
* wxWindowBase::GetCapture()
983 return wxTheApp
->s_captureWindow
;
986 void wxWindowMac::DoReleaseMouse()
988 wxTheApp
->s_captureWindow
= NULL
;
991 #if wxUSE_DRAG_AND_DROP
993 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
995 if ( m_dropTarget
!= 0 ) {
999 m_dropTarget
= pDropTarget
;
1000 if ( m_dropTarget
!= 0 )
1008 // Old style file-manager drag&drop
1009 void wxWindowMac::DragAcceptFiles(bool accept
)
1014 // Returns the size of the native control. In the case of the toplevel window
1015 // this is the content area root control
1017 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1018 int& w
, int& h
) const
1021 m_peer
->GetRect( &bounds
) ;
1026 w
= bounds
.right
- bounds
.left
;
1027 h
= bounds
.bottom
- bounds
.top
;
1029 wxTopLevelWindow
* tlw
= wxDynamicCast( this , wxTopLevelWindow
) ;
1032 Point tlworigin
= { 0 , 0 } ;
1033 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef
) tlw
->MacGetWindowRef() ) , &tlworigin
) ;
1039 // From a wx position / size calculate the appropriate size of the native control
1041 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1044 int& w
, int& h
, bool adjustOrigin
) const
1046 // the desired size, minus the border pixels gives the correct size of the control
1050 // todo the default calls may be used as soon as PostCreateControl Is moved here
1051 w
= size
.x
; // WidthDefault( size.x );
1052 h
= size
.y
; // HeightDefault( size.y ) ;
1053 #if !TARGET_API_MAC_OSX
1054 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1057 x
+= MacGetLeftBorderSize() ;
1058 y
+= MacGetTopBorderSize() ;
1059 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1060 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1063 AdjustForParentClientOrigin( x
, y
) ;
1068 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1070 // take the size of the control and add the borders that have to be drawn outside
1071 int x1
, y1
, w1
,h1
;
1072 #if TARGET_API_MAC_OSX
1073 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1077 m_peer
->GetRect( &bounds
) ;
1078 w1
= bounds
.right
- bounds
.left
;
1079 h1
= bounds
.bottom
- bounds
.top
;
1081 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1082 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1088 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1090 #if TARGET_API_MAC_OSX
1091 int x1
, y1
, w1
,h1
;
1092 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1093 x1
-= MacGetLeftBorderSize() ;
1094 y1
-= MacGetTopBorderSize() ;
1095 if ( !IsTopLevel() )
1097 wxWindow
*parent
= GetParent();
1100 wxPoint
pt(parent
->GetClientAreaOrigin());
1109 m_peer
->GetRect( &bounds
) ;
1110 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1112 int xx
= bounds
.left
;
1113 int yy
= bounds
.top
;
1114 xx
-= MacGetLeftBorderSize() ;
1115 yy
-= MacGetTopBorderSize() ;
1117 if ( !GetParent()->IsTopLevel() )
1119 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1125 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1134 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1136 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1138 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1141 Point localwhere
= {0,0} ;
1143 if(x
) localwhere
.h
= * x
;
1144 if(y
) localwhere
.v
= * y
;
1146 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1147 if(x
) *x
= localwhere
.h
;
1148 if(y
) *y
= localwhere
.v
;
1151 MacRootWindowToWindow( x
, y
) ;
1153 wxPoint origin
= GetClientAreaOrigin() ;
1154 if(x
) *x
-= origin
.x
;
1155 if(y
) *y
-= origin
.y
;
1158 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1160 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1161 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1163 wxPoint origin
= GetClientAreaOrigin() ;
1164 if(x
) *x
+= origin
.x
;
1165 if(y
) *y
+= origin
.y
;
1167 MacWindowToRootWindow( x
, y
) ;
1170 Point localwhere
= { 0,0 };
1171 if(x
) localwhere
.h
= * x
;
1172 if(y
) localwhere
.v
= * y
;
1173 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1174 if(x
) *x
= localwhere
.h
;
1175 if(y
) *y
= localwhere
.v
;
1179 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1181 wxPoint origin
= GetClientAreaOrigin() ;
1182 if(x
) *x
+= origin
.x
;
1183 if(y
) *y
+= origin
.y
;
1185 MacWindowToRootWindow( x
, y
) ;
1188 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1190 MacRootWindowToWindow( x
, y
) ;
1192 wxPoint origin
= GetClientAreaOrigin() ;
1193 if(x
) *x
-= origin
.x
;
1194 if(y
) *y
-= origin
.y
;
1197 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1199 #if TARGET_API_MAC_OSX
1201 if ( x
) pt
.x
= *x
;
1202 if ( y
) pt
.y
= *y
;
1204 if ( !IsTopLevel() )
1206 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1209 pt
.x
-= MacGetLeftBorderSize() ;
1210 pt
.y
-= MacGetTopBorderSize() ;
1211 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1215 if ( x
) *x
= (int) pt
.x
;
1216 if ( y
) *y
= (int) pt
.y
;
1218 if ( !IsTopLevel() )
1221 m_peer
->GetRect( &bounds
) ;
1222 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1223 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1228 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1233 MacWindowToRootWindow( &x1
, &y1
) ;
1238 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1240 #if TARGET_API_MAC_OSX
1242 if ( x
) pt
.x
= *x
;
1243 if ( y
) pt
.y
= *y
;
1245 if ( !IsTopLevel() )
1247 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1248 pt
.x
+= MacGetLeftBorderSize() ;
1249 pt
.y
+= MacGetTopBorderSize() ;
1252 if ( x
) *x
= (int) pt
.x
;
1253 if ( y
) *y
= (int) pt
.y
;
1255 if ( !IsTopLevel() )
1258 m_peer
->GetRect( &bounds
) ;
1259 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1260 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1265 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1270 MacRootWindowToWindow( &x1
, &y1
) ;
1275 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1277 RgnHandle rgn
= NewRgn() ;
1279 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1281 GetRegionBounds( rgn
, &content
) ;
1286 m_peer
->GetRect( &content
) ;
1289 m_peer
->GetRect( &structure
) ;
1290 #if !TARGET_API_MAC_OSX
1291 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1293 left
= content
.left
- structure
.left
;
1294 top
= content
.top
- structure
.top
;
1295 right
= structure
.right
- content
.right
;
1296 bottom
= structure
.bottom
- content
.bottom
;
1299 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1301 wxSize sizeTotal
= size
;
1303 RgnHandle rgn
= NewRgn() ;
1307 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1309 GetRegionBounds( rgn
, &content
) ;
1314 m_peer
->GetRect( &content
) ;
1317 m_peer
->GetRect( &structure
) ;
1318 #if !TARGET_API_MAC_OSX
1319 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1322 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1323 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1325 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1326 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1332 // Get size *available for subwindows* i.e. excluding menu bar etc.
1333 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1337 RgnHandle rgn
= NewRgn() ;
1339 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1341 GetRegionBounds( rgn
, &content
) ;
1346 m_peer
->GetRect( &content
) ;
1348 #if !TARGET_API_MAC_OSX
1350 m_peer
->GetRect( &structure
) ;
1351 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1353 ww
= content
.right
- content
.left
;
1354 hh
= content
.bottom
- content
.top
;
1356 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1357 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1360 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1366 GetSize( &w , &h ) ;
1368 MacClientToRootWindow( &x1 , &y1 ) ;
1369 MacClientToRootWindow( &w , &h ) ;
1371 wxWindowMac *iter = (wxWindowMac*)this ;
1373 int totW = 10000 , totH = 10000;
1376 if ( iter->IsTopLevel() )
1378 iter->GetSize( &totW , &totH ) ;
1382 iter = iter->GetParent() ;
1385 if (m_hScrollBar && m_hScrollBar->IsShown() )
1387 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1393 if (m_vScrollBar && m_vScrollBar->IsShown() )
1395 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1403 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1405 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1407 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1409 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1416 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1418 if (m_cursor
== cursor
)
1421 if (wxNullCursor
== cursor
)
1423 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1428 if ( ! wxWindowBase::SetCursor( cursor
) )
1432 wxASSERT_MSG( m_cursor
.Ok(),
1433 wxT("cursor must be valid after call to the base version"));
1436 wxWindowMac
*mouseWin
= 0 ;
1438 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1440 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1442 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1443 // position, use it...
1447 ControlPartCode part
;
1448 ControlRef control
;
1449 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1451 mouseWin
= wxFindControlFromMacControl( control
) ;
1454 QDSwapPort( savePort
, NULL
) ;
1457 if ( mouseWin
== this && !wxIsBusy() )
1459 m_cursor
.MacInstall() ;
1466 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1468 menu
->SetInvokingWindow(this);
1471 if ( x
== -1 && y
== -1 )
1473 wxPoint mouse
= wxGetMousePosition();
1474 x
= mouse
.x
; y
= mouse
.y
;
1478 ClientToScreen( &x
, &y
) ;
1481 menu
->MacBeforeDisplay( true ) ;
1482 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1483 if ( HiWord(menuResult
) != 0 )
1486 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1487 wxMenuItem
* item
= NULL
;
1489 item
= menu
->FindItem(id
, &realmenu
) ;
1490 if (item
->IsCheckable())
1492 item
->Check( !item
->IsChecked() ) ;
1494 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1496 menu
->MacAfterDisplay( true ) ;
1498 menu
->SetInvokingWindow(NULL
);
1504 // ----------------------------------------------------------------------------
1506 // ----------------------------------------------------------------------------
1510 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1512 wxWindowBase::DoSetToolTip(tooltip
);
1515 m_tooltip
->SetWindow(this);
1518 #endif // wxUSE_TOOLTIPS
1520 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1522 // this is never called for a toplevel window, so we know we have a parent
1523 int former_x
, former_y
, former_w
, former_h
;
1525 // Get true coordinates of former position
1526 DoGetPosition( &former_x
, &former_y
) ;
1527 DoGetSize( &former_w
, &former_h
) ;
1529 wxWindow
*parent
= GetParent();
1532 wxPoint
pt(parent
->GetClientAreaOrigin());
1537 int actualWidth
= width
;
1538 int actualHeight
= height
;
1542 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1543 actualWidth
= m_minWidth
;
1544 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1545 actualHeight
= m_minHeight
;
1546 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1547 actualWidth
= m_maxWidth
;
1548 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1549 actualHeight
= m_maxHeight
;
1551 bool doMove
= false ;
1552 bool doResize
= false ;
1554 if ( actualX
!= former_x
|| actualY
!= former_y
)
1558 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1563 if ( doMove
|| doResize
)
1565 // we don't adjust twice for the origin
1566 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1567 #if TARGET_API_MAC_OSX
1568 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1569 if ( ! GetParent()->IsTopLevel() )
1571 r
.left
-= GetParent()->MacGetLeftBorderSize() ;
1572 r
.top
-= GetParent()->MacGetTopBorderSize() ;
1573 r
.right
-= GetParent()->MacGetLeftBorderSize() ;
1574 r
.bottom
-= GetParent()->MacGetTopBorderSize() ;
1577 bool vis
= m_peer
->IsVisible();
1579 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1581 m_peer
->SetVisibility( false , true ) ;
1582 m_peer
->SetRect( &r
) ;
1584 m_peer
->SetVisibility( true , true ) ;
1586 MacRepositionScrollBars() ;
1589 wxPoint
point(actualX
,actualY
);
1590 wxMoveEvent
event(point
, m_windowId
);
1591 event
.SetEventObject(this);
1592 GetEventHandler()->ProcessEvent(event
) ;
1596 MacRepositionScrollBars() ;
1597 wxSize
size(actualWidth
, actualHeight
);
1598 wxSizeEvent
event(size
, m_windowId
);
1599 event
.SetEventObject(this);
1600 GetEventHandler()->ProcessEvent(event
);
1606 wxSize
wxWindowMac::DoGetBestSize() const
1608 if ( m_macIsUserPane
|| IsTopLevel() )
1609 return wxWindowBase::DoGetBestSize() ;
1611 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1612 int bestWidth
, bestHeight
;
1613 m_peer
->GetBestRect( &bestsize
) ;
1615 if ( EmptyRect( &bestsize
) )
1617 bestsize
.left
= bestsize
.top
= 0 ;
1618 bestsize
.right
= 16 ;
1619 bestsize
.bottom
= 16 ;
1620 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1622 bestsize
.bottom
= 16 ;
1624 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1626 bestsize
.bottom
= 24 ;
1630 // return wxWindowBase::DoGetBestSize() ;
1634 bestWidth
= bestsize
.right
- bestsize
.left
;
1635 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1636 if ( bestHeight
< 10 )
1639 return wxSize(bestWidth
, bestHeight
);
1643 // set the size of the window: if the dimensions are positive, just use them,
1644 // but if any of them is equal to -1, it means that we must find the value for
1645 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1646 // which case -1 is a valid value for x and y)
1648 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1649 // the width/height to best suit our contents, otherwise we reuse the current
1651 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1653 // get the current size and position...
1654 int currentX
, currentY
;
1655 GetPosition(¤tX
, ¤tY
);
1657 int currentW
,currentH
;
1658 GetSize(¤tW
, ¤tH
);
1660 // ... and don't do anything (avoiding flicker) if it's already ok
1661 if ( x
== currentX
&& y
== currentY
&&
1662 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1665 MacRepositionScrollBars() ; // we might have a real position shift
1669 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1671 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1674 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1676 wxSize
size(-1, -1);
1679 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1681 size
= DoGetBestSize();
1686 // just take the current one
1693 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1697 size
= DoGetBestSize();
1699 //else: already called DoGetBestSize() above
1705 // just take the current one
1710 DoMoveWindow(x
, y
, width
, height
);
1714 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1716 RgnHandle rgn
= NewRgn() ;
1718 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1719 GetRegionBounds( rgn
, &content
) ;
1721 #if !TARGET_API_MAC_OSX
1722 // if the content rgn is empty / not supported
1723 // don't attempt to correct the coordinates to wxWindow relative ones
1724 if (!::EmptyRect( &content
) )
1727 m_peer
->GetRect( &structure
) ;
1728 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1732 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1735 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1737 if ( clientheight
!= -1 || clientheight
!= -1 )
1739 int currentclientwidth
, currentclientheight
;
1740 int currentwidth
, currentheight
;
1742 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1743 GetSize( ¤twidth
, ¤theight
) ;
1745 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1746 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1750 void wxWindowMac::SetTitle(const wxString
& title
)
1752 m_label
= wxStripMenuCodes(title
) ;
1754 if ( m_peer
&& m_peer
->Ok() )
1756 m_peer
->SetTitle( m_label
) ;
1761 wxString
wxWindowMac::GetTitle() const
1766 bool wxWindowMac::Show(bool show
)
1768 if ( !wxWindowBase::Show(show
) )
1771 // TODO use visibilityChanged Carbon Event for OSX
1772 bool former
= MacIsReallyShown() ;
1774 m_peer
->SetVisibility( show
, true ) ;
1775 if ( former
!= MacIsReallyShown() )
1776 MacPropagateVisibilityChanged() ;
1780 bool wxWindowMac::Enable(bool enable
)
1782 wxASSERT( m_peer
->Ok() ) ;
1783 if ( !wxWindowBase::Enable(enable
) )
1786 bool former
= MacIsReallyEnabled() ;
1787 m_peer
->Enable( enable
) ;
1789 if ( former
!= MacIsReallyEnabled() )
1790 MacPropagateEnabledStateChanged() ;
1795 // status change propagations (will be not necessary for OSX later )
1798 void wxWindowMac::MacPropagateVisibilityChanged()
1800 #if !TARGET_API_MAC_OSX
1801 MacVisibilityChanged() ;
1803 wxWindowListNode
*node
= GetChildren().GetFirst();
1806 wxWindowMac
*child
= node
->GetData();
1807 if ( child
->IsShown() )
1808 child
->MacPropagateVisibilityChanged( ) ;
1809 node
= node
->GetNext();
1814 void wxWindowMac::MacPropagateEnabledStateChanged( )
1816 #if !TARGET_API_MAC_OSX
1817 MacEnabledStateChanged() ;
1819 wxWindowListNode
*node
= GetChildren().GetFirst();
1822 wxWindowMac
*child
= node
->GetData();
1823 if ( child
->IsEnabled() )
1824 child
->MacPropagateEnabledStateChanged() ;
1825 node
= node
->GetNext();
1830 void wxWindowMac::MacPropagateHiliteChanged( )
1832 #if !TARGET_API_MAC_OSX
1833 MacHiliteChanged() ;
1835 wxWindowListNode
*node
= GetChildren().GetFirst();
1838 wxWindowMac
*child
= node
->GetData();
1839 // if ( child->IsEnabled() )
1840 child
->MacPropagateHiliteChanged() ;
1841 node
= node
->GetNext();
1847 // status change notifications
1850 void wxWindowMac::MacVisibilityChanged()
1854 void wxWindowMac::MacHiliteChanged()
1858 void wxWindowMac::MacEnabledStateChanged()
1863 // status queries on the inherited window's state
1866 bool wxWindowMac::MacIsReallyShown()
1868 // only under OSX the visibility of the TLW is taken into account
1869 #if TARGET_API_MAC_OSX
1870 if ( m_peer
&& m_peer
->Ok() )
1871 return m_peer
->IsVisible();
1873 wxWindow
* win
= this ;
1874 while( win
->IsShown() )
1876 if ( win
->IsTopLevel() )
1879 win
= win
->GetParent() ;
1887 bool wxWindowMac::MacIsReallyEnabled()
1889 return m_peer
->IsEnabled() ;
1892 bool wxWindowMac::MacIsReallyHilited()
1894 return m_peer
->IsActive();
1897 void wxWindowMac::MacFlashInvalidAreas()
1899 #if TARGET_API_MAC_OSX
1900 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
1908 int wxWindowMac::GetCharHeight() const
1910 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1911 return dc
.GetCharHeight() ;
1914 int wxWindowMac::GetCharWidth() const
1916 wxClientDC
dc ( (wxWindowMac
*)this ) ;
1917 return dc
.GetCharWidth() ;
1920 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
1921 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
1923 const wxFont
*fontToUse
= theFont
;
1925 fontToUse
= &m_font
;
1927 wxClientDC
dc( (wxWindowMac
*) this ) ;
1929 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
1930 if ( externalLeading
)
1931 *externalLeading
= le
;
1941 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1942 * we always intersect with the entire window, not only with the client area
1945 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
1947 if ( m_peer
== NULL
)
1950 #if TARGET_API_MAC_OSX
1952 m_peer
->SetNeedsDisplay( true ) ;
1955 RgnHandle update
= NewRgn() ;
1956 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
1957 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
1958 wxPoint origin
= GetClientAreaOrigin() ;
1959 OffsetRgn( update
, origin
.x
, origin
.y
) ;
1960 // right now this is wx' window coordinates, as our native peer does not have borders, this is
1962 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1963 m_peer
->SetNeedsDisplay( true , update
) ;
1967 RgnHandle updateRgn = NewRgn() ;
1970 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1974 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1975 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1977 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1978 DisposeRgn(updateRgn) ;
1980 if ( m_peer
->IsVisible())
1982 m_peer
->SetVisibility( false , false ) ;
1983 m_peer
->SetVisibility( true , true ) ;
1986 if ( MacGetTopLevelWindow() == NULL )
1989 if ( !m_peer->IsVisible())
1992 wxPoint client = GetClientAreaOrigin();
1995 int x2 = m_width - client.x;
1996 int y2 = m_height - client.y;
1998 if (IsKindOf( CLASSINFO(wxButton)))
2000 // buttons have an "aura"
2007 Rect clientrect = { y1, x1, y2, x2 };
2011 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2012 SectRect( &clientrect , &r , &clientrect ) ;
2015 if ( !EmptyRect( &clientrect ) )
2017 int top = 0 , left = 0 ;
2019 MacClientToRootWindow( &left , &top ) ;
2020 OffsetRect( &clientrect , left , top ) ;
2022 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2028 void wxWindowMac::Freeze()
2030 #if TARGET_API_MAC_OSX
2031 if ( !m_frozenness
++ )
2033 m_peer
->SetDrawingEnabled( false ) ;
2039 void wxWindowMac::Thaw()
2041 #if TARGET_API_MAC_OSX
2042 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2044 if ( !--m_frozenness
)
2046 m_peer
->SetDrawingEnabled( true ) ;
2047 m_peer
->InvalidateWithChildren() ;
2052 void wxWindowMac::MacRedrawControl()
2055 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2057 #if TARGET_API_MAC_CARBON
2060 wxClientDC dc(this) ;
2061 wxMacPortSetter helper(&dc) ;
2062 wxMacWindowClipper clipper(this) ;
2063 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2064 UMADrawControl( *m_peer ) ;
2071 void wxWindowMac::OnPaint(wxPaintEvent& event)
2073 // why don't we skip that here ?
2077 wxWindowMac
*wxGetActiveWindow()
2079 // actually this is a windows-only concept
2083 // Coordinates relative to the window
2084 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2086 // We really don't move the mouse programmatically under Mac.
2089 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2091 #if TARGET_API_MAC_OSX
2092 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2098 event
.GetDC()->Clear() ;
2101 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2103 wxWindowDC
dc(this) ;
2104 wxMacPortSetter
helper(&dc
) ;
2106 MacPaintBorders( dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2109 int wxWindowMac::GetScrollPos(int orient
) const
2111 if ( orient
== wxHORIZONTAL
)
2114 return m_hScrollBar
->GetThumbPosition() ;
2119 return m_vScrollBar
->GetThumbPosition() ;
2124 // This now returns the whole range, not just the number
2125 // of positions that we can scroll.
2126 int wxWindowMac::GetScrollRange(int orient
) const
2128 if ( orient
== wxHORIZONTAL
)
2131 return m_hScrollBar
->GetRange() ;
2136 return m_vScrollBar
->GetRange() ;
2141 int wxWindowMac::GetScrollThumb(int orient
) const
2143 if ( orient
== wxHORIZONTAL
)
2146 return m_hScrollBar
->GetThumbSize() ;
2151 return m_vScrollBar
->GetThumbSize() ;
2156 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2158 if ( orient
== wxHORIZONTAL
)
2161 m_hScrollBar
->SetThumbPosition( pos
) ;
2166 m_vScrollBar
->SetThumbPosition( pos
) ;
2170 void wxWindowMac::MacPaintBorders( int left
, int top
)
2176 wxGetOsVersion( &major
, &minor
);
2178 RGBColor darkShadow
= { 0x0000, 0x0000 , 0x0000 } ;
2179 RGBColor lightShadow
= { 0x4444, 0x4444 , 0x4444 } ;
2180 // OS X has lighter border edges than classic:
2183 darkShadow
.red
= 0x8E8E;
2184 darkShadow
.green
= 0x8E8E;
2185 darkShadow
.blue
= 0x8E8E;
2186 lightShadow
.red
= 0xBDBD;
2187 lightShadow
.green
= 0xBDBD;
2188 lightShadow
.blue
= 0xBDBD;
2194 GetSize( &w
, &h
) ;
2195 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2196 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2198 #if wxMAC_USE_THEME_BORDER
2200 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2201 InsetRect( &rect
, border
, border
);
2202 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2204 RGBColor white
= { 0xFFFF, 0xFFFF , 0xFFFF } ;
2205 RGBColor face
= { 0xDDDD, 0xDDDD , 0xDDDD } ;
2207 bool sunken
= HasFlag( wxSUNKEN_BORDER
) ;
2208 RGBForeColor( &face
);
2209 MoveTo( left
+ 0 , top
+ h
- 2 );
2210 LineTo( left
+ 0 , top
+ 0 );
2211 LineTo( left
+ w
- 2 , top
+ 0 );
2213 MoveTo( left
+ 2 , top
+ h
- 3 );
2214 LineTo( left
+ w
- 3 , top
+ h
- 3 );
2215 LineTo( left
+ w
- 3 , top
+ 2 );
2217 RGBForeColor( sunken
? &face
: &darkShadow
);
2218 MoveTo( left
+ 0 , top
+ h
- 1 );
2219 LineTo( left
+ w
- 1 , top
+ h
- 1 );
2220 LineTo( left
+ w
- 1 , top
+ 0 );
2222 RGBForeColor( sunken
? &lightShadow
: &white
);
2223 MoveTo( left
+ 1 , top
+ h
- 3 );
2224 LineTo( left
+ 1, top
+ 1 );
2225 LineTo( left
+ w
- 3 , top
+ 1 );
2227 RGBForeColor( sunken
? &white
: &lightShadow
);
2228 MoveTo( left
+ 1 , top
+ h
- 2 );
2229 LineTo( left
+ w
- 2 , top
+ h
- 2 );
2230 LineTo( left
+ w
- 2 , top
+ 1 );
2232 RGBForeColor( sunken
? &darkShadow
: &face
);
2233 MoveTo( left
+ 2 , top
+ h
- 4 );
2234 LineTo( left
+ 2 , top
+ 2 );
2235 LineTo( left
+ w
- 4 , top
+ 2 );
2238 else if (HasFlag(wxSIMPLE_BORDER
))
2240 Rect rect
= { top
, left
, h
+ top
, w
+ left
} ;
2241 RGBForeColor( &darkShadow
) ;
2242 FrameRect( &rect
) ;
2246 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2248 if ( child
== m_hScrollBar
)
2249 m_hScrollBar
= NULL
;
2250 if ( child
== m_vScrollBar
)
2251 m_vScrollBar
= NULL
;
2253 wxWindowBase::RemoveChild( child
) ;
2256 // New function that will replace some of the above.
2257 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2258 int range
, bool refresh
)
2260 if ( orient
== wxHORIZONTAL
)
2264 if ( range
== 0 || thumbVisible
>= range
)
2266 if ( m_hScrollBar
->IsShown() )
2267 m_hScrollBar
->Show(false) ;
2271 if ( !m_hScrollBar
->IsShown() )
2272 m_hScrollBar
->Show(true) ;
2273 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2281 if ( range
== 0 || thumbVisible
>= range
)
2283 if ( m_vScrollBar
->IsShown() )
2284 m_vScrollBar
->Show(false) ;
2288 if ( !m_vScrollBar
->IsShown() )
2289 m_vScrollBar
->Show(true) ;
2290 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2294 MacRepositionScrollBars() ;
2297 // Does a physical scroll
2298 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2300 if( dx
== 0 && dy
==0 )
2306 int width
, height
;
2307 GetClientSize( &width
, &height
) ;
2308 #if TARGET_API_MAC_OSX
2309 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2310 // area is scrolled, this does not occur if width and height are 2 pixels less,
2311 // TODO write optimal workaround
2312 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width
, MacGetTopBorderSize() + height
) ;
2315 scrollrect
.Intersect( *rect
) ;
2317 if ( m_peer
->GetNeedsDisplay() )
2319 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2320 // either immediate redraw or full invalidate
2322 // is the better overall solution, as it does not slow down scrolling
2323 m_peer
->SetNeedsDisplay( true ) ;
2325 // this would be the preferred version for fast drawing controls
2326 if( UMAGetSystemVersion() < 0x1030 )
2329 HIViewRender(*m_peer
) ;
2332 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2333 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2334 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2341 RgnHandle updateRgn
= NewRgn() ;
2344 wxClientDC
dc(this) ;
2345 wxMacPortSetter
helper(&dc
) ;
2347 m_peer
->GetRect( &scrollrect
) ;
2348 scrollrect
.top
+= MacGetTopBorderSize() ;
2349 scrollrect
.left
+= MacGetLeftBorderSize() ;
2350 scrollrect
.bottom
= scrollrect
.top
+ height
;
2351 scrollrect
.right
= scrollrect
.left
+ width
;
2355 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2356 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2357 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2359 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2361 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2365 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2367 wxWindowMac
*child
= node
->GetData();
2368 if (child
== m_vScrollBar
) continue;
2369 if (child
== m_hScrollBar
) continue;
2370 if (child
->IsTopLevel()) continue;
2373 child
->GetPosition( &x
, &y
);
2375 child
->GetSize( &w
, &h
);
2379 if (rect
->Intersects(rc
))
2380 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2384 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2389 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2391 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2393 wxScrollWinEvent wevent
;
2394 wevent
.SetPosition(event
.GetPosition());
2395 wevent
.SetOrientation(event
.GetOrientation());
2396 wevent
.m_eventObject
= this;
2398 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2399 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2400 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2401 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2402 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2403 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2404 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2405 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2406 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2407 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2408 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2409 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2410 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2411 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2412 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2413 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2415 GetEventHandler()->ProcessEvent(wevent
);
2419 // Get the window with the focus
2420 wxWindowMac
*wxWindowBase::FindFocus()
2422 ControlRef control
;
2423 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2424 return wxFindControlFromMacControl( control
) ;
2427 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2429 // panel wants to track the window which was the last to have focus in it,
2430 // so we want to set ourselves as the window which last had focus
2432 // notice that it's also important to do it upwards the tree becaus
2433 // otherwise when the top level panel gets focus, it won't set it back to
2434 // us, but to some other sibling
2436 // CS:don't know if this is still needed:
2437 //wxChildFocusEvent eventFocus(this);
2438 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2440 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2442 wxMacWindowStateSaver
sv( this ) ;
2447 MacWindowToRootWindow( &x
, &y
) ;
2448 GetSize( &w
, &h
) ;
2449 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2451 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2452 DrawThemeFocusRect( &rect
, true ) ;
2454 DrawThemeFocusRect( &rect
, false ) ;
2460 void wxWindowMac::OnInternalIdle()
2462 // This calls the UI-update mechanism (querying windows for
2463 // menu/toolbar/control state information)
2464 if (wxUpdateUIEvent::CanUpdate(this))
2465 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2468 // Raise the window to the top of the Z order
2469 void wxWindowMac::Raise()
2471 m_peer
->SetZOrder( true , NULL
) ;
2474 // Lower the window to the bottom of the Z order
2475 void wxWindowMac::Lower()
2477 m_peer
->SetZOrder( false , NULL
) ;
2481 // static wxWindow *gs_lastWhich = NULL;
2483 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2485 // first trigger a set cursor event
2487 wxPoint clientorigin
= GetClientAreaOrigin() ;
2488 wxSize clientsize
= GetClientSize() ;
2490 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2492 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2494 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2495 if ( processedEvtSetCursor
&& event
.HasCursor() )
2497 cursor
= event
.GetCursor() ;
2502 // the test for processedEvtSetCursor is here to prevent using m_cursor
2503 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2504 // it - this is a way to say that our cursor shouldn't be used for this
2506 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2516 cursor
= *wxSTANDARD_CURSOR
;
2520 cursor
.MacInstall() ;
2522 return cursor
.Ok() ;
2525 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2529 return m_tooltip
->GetTip() ;
2531 return wxEmptyString
;
2534 void wxWindowMac::Update()
2536 #if TARGET_API_MAC_OSX
2537 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2538 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2539 // for composited windows this also triggers a redraw of all
2540 // invalid views in the window
2541 if( UMAGetSystemVersion() >= 0x1030 )
2542 HIWindowFlush(window
) ;
2546 // the only way to trigger the redrawing on earlier systems is to call
2549 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2550 UInt32 currentEventClass
= 0 ;
2551 UInt32 currentEventKind
= 0 ;
2552 if ( currentEvent
!= NULL
)
2554 currentEventClass
= ::GetEventClass( currentEvent
) ;
2555 currentEventKind
= ::GetEventKind( currentEvent
) ;
2557 if ( currentEventClass
!= kEventClassMenu
)
2559 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2562 OSStatus status
= noErr
;
2563 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2566 m_peer
->SetNeedsDisplay( true ) ;
2569 ::Draw1Control( m_peer
->GetControlRef() ) ;
2573 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2575 wxTopLevelWindowMac
* win
= NULL
;
2576 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2579 win
= wxFindWinFromMacWindow( window
) ;
2583 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2587 RgnHandle visRgn
= NewRgn() ;
2588 RgnHandle tempRgn
= NewRgn() ;
2589 if ( m_peer
->IsVisible())
2591 m_peer
->GetRect( &r
) ;
2592 r
.left
-= MacGetLeftBorderSize() ;
2593 r
.top
-= MacGetTopBorderSize() ;
2594 r
.bottom
+= MacGetBottomBorderSize() ;
2595 r
.right
+= MacGetRightBorderSize() ;
2597 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2599 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2600 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2609 if ( includeOuterStructures
)
2610 InsetRect( &r
, -3 , -3 ) ;
2611 RectRgn( visRgn
, &r
) ;
2613 if ( !IsTopLevel() )
2615 wxWindow
* child
= this ;
2616 wxWindow
* parent
= child
->GetParent() ;
2621 // we have to find a better clipping algorithm here, in order not to clip things
2622 // positioned like status and toolbar
2623 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2625 size
= parent
->GetSize() ;
2630 size
= parent
->GetClientSize() ;
2631 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2635 parent
->MacWindowToRootWindow( &x
, &y
) ;
2636 MacRootWindowToWindow( &x
, &y
) ;
2638 SetRectRgn( tempRgn
,
2639 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2640 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2641 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2643 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2644 if ( parent
->IsTopLevel() )
2647 parent
= child
->GetParent() ;
2652 wxRegion vis
= visRgn
;
2653 DisposeRgn( visRgn
) ;
2654 DisposeRgn( tempRgn
) ;
2659 This function must not change the updatergn !
2661 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2663 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2664 bool handled
= false ;
2666 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2668 RgnHandle newupdate
= NewRgn() ;
2669 wxSize point
= GetClientSize() ;
2670 wxPoint origin
= GetClientAreaOrigin() ;
2671 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2672 SectRgn( newupdate
, updatergn
, newupdate
) ;
2673 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2674 m_updateRegion
= newupdate
;
2675 DisposeRgn( newupdate
) ;
2678 if ( !EmptyRgn(updatergn
) )
2680 wxWindowDC
dc(this);
2681 if (!EmptyRgn(updatergn
))
2682 dc
.SetClippingRegion(wxRegion(updatergn
));
2684 wxEraseEvent
eevent( GetId(), &dc
);
2685 eevent
.SetEventObject( this );
2686 GetEventHandler()->ProcessEvent( eevent
);
2688 if ( !m_updateRegion
.Empty() )
2690 // paint the window itself
2692 event
.m_timeStamp
= time
;
2693 event
.SetEventObject(this);
2694 handled
= GetEventHandler()->ProcessEvent(event
);
2696 // paint custom borders
2697 wxNcPaintEvent
eventNc( GetId() );
2698 eventNc
.SetEventObject( this );
2699 GetEventHandler()->ProcessEvent( eventNc
);
2705 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2707 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2708 // updatergn is always already clipped to our boundaries
2709 // if we are in compositing mode then it is in relative to the upper left of the control
2710 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2711 // of the toplevel window
2712 // it is in window coordinates, not in client coordinates
2714 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2715 RgnHandle ownUpdateRgn
= NewRgn() ;
2716 CopyRgn( updatergn
, ownUpdateRgn
) ;
2718 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2721 m_peer
->GetRectInWindowCoords( &bounds
);
2722 RgnHandle controlRgn
= NewRgn();
2723 RectRgn( controlRgn
, &bounds
);
2724 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2725 // the window update region
2726 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2727 DisposeRgn( controlRgn
);
2729 //KO: convert ownUpdateRgn to local coordinates
2730 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2733 MacDoRedraw( ownUpdateRgn
, time
) ;
2734 DisposeRgn( ownUpdateRgn
) ;
2738 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2740 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2744 if ( iter
->IsTopLevel() )
2745 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2747 iter
= iter
->GetParent() ;
2749 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2753 void wxWindowMac::MacCreateScrollBars( long style
)
2755 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2757 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2759 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2760 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2761 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2762 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2764 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2765 variant
= wxWINDOW_VARIANT_SMALL
;
2768 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2770 GetClientSize( &width
, &height
) ;
2772 wxPoint
vPoint(width
-scrlsize
, 0) ;
2773 wxSize
vSize(scrlsize
, height
- adjust
) ;
2774 wxPoint
hPoint(0 , height
-scrlsize
) ;
2775 wxSize
hSize( width
- adjust
, scrlsize
) ;
2778 if ( style
& wxVSCROLL
)
2780 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2781 vSize
, wxVERTICAL
);
2784 if ( style
& wxHSCROLL
)
2786 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2787 hSize
, wxHORIZONTAL
);
2792 // because the create does not take into account the client area origin
2793 MacRepositionScrollBars() ; // we might have a real position shift
2796 void wxWindowMac::MacRepositionScrollBars()
2798 if ( !m_hScrollBar
&& !m_vScrollBar
)
2801 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2802 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2803 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2805 // get real client area
2809 GetSize( &width
, &height
) ;
2811 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2812 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2814 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2815 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2816 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2817 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2823 GetSize( &w , &h ) ;
2825 MacClientToRootWindow( &x , &y ) ;
2826 MacClientToRootWindow( &w , &h ) ;
2828 wxWindowMac *iter = (wxWindowMac*)this ;
2830 int totW = 10000 , totH = 10000;
2833 if ( iter->IsTopLevel() )
2835 iter->GetSize( &totW , &totH ) ;
2839 iter = iter->GetParent() ;
2867 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2871 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
2875 bool wxWindowMac::AcceptsFocus() const
2877 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2880 void wxWindowMac::MacSuperChangedPosition()
2882 // only window-absolute structures have to be moved i.e. controls
2884 wxWindowListNode
*node
= GetChildren().GetFirst();
2887 wxWindowMac
*child
= node
->GetData();
2888 child
->MacSuperChangedPosition() ;
2889 node
= node
->GetNext();
2893 void wxWindowMac::MacTopLevelWindowChangedPosition()
2895 // only screen-absolute structures have to be moved i.e. glcanvas
2897 wxWindowListNode
*node
= GetChildren().GetFirst();
2900 wxWindowMac
*child
= node
->GetData();
2901 child
->MacTopLevelWindowChangedPosition() ;
2902 node
= node
->GetNext();
2906 long wxWindowMac::MacGetLeftBorderSize( ) const
2911 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
2916 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
2921 else if (m_windowStyle
&wxSIMPLE_BORDER
)
2928 long wxWindowMac::MacGetRightBorderSize( ) const
2930 // they are all symmetric in mac themes
2931 return MacGetLeftBorderSize() ;
2934 long wxWindowMac::MacGetTopBorderSize( ) const
2936 // they are all symmetric in mac themes
2937 return MacGetLeftBorderSize() ;
2940 long wxWindowMac::MacGetBottomBorderSize( ) const
2942 // they are all symmetric in mac themes
2943 return MacGetLeftBorderSize() ;
2946 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
2948 return style
& ~wxBORDER_MASK
;
2951 // Find the wxWindowMac at the current mouse position, returning the mouse
2953 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
2955 pt
= wxGetMousePosition();
2956 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
2960 // Get the current mouse position.
2961 wxPoint
wxGetMousePosition()
2964 wxGetMousePosition(& x
, & y
);
2965 return wxPoint(x
, y
);
2968 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
2970 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
2972 // copied from wxGTK : CS
2973 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2976 // (a) it's a command event and so is propagated to the parent
2977 // (b) under MSW it can be generated from kbd too
2978 // (c) it uses screen coords (because of (a))
2979 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
2981 this->ClientToScreen(event
.GetPosition()));
2982 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
2991 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
2995 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
2999 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3000 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3004 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3006 return eventNotHandledErr
;