1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
16 #include "wx/wxprec.h"
19 #include "wx/window.h"
21 #include "wx/dcclient.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
41 #include "wx/toolbar.h"
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
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 // ---------------------------------------------------------------------------
100 // Utility Routines to move between different coordinate systems
101 // ---------------------------------------------------------------------------
104 * Right now we have the following setup :
105 * a border that is not part of the native control is always outside the
106 * control's border (otherwise we loose all native intelligence, future ways
107 * may be to have a second embedding control responsible for drawing borders
108 * and backgrounds eventually)
109 * so all this border calculations have to be taken into account when calling
110 * native methods or getting native oriented data
111 * so we have three coordinate systems here
112 * wx client coordinates
113 * wx window coordinates (including window frames)
118 // originating from native control
122 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
124 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
127 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
129 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
133 // directed towards native control
136 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
138 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
141 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
143 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
147 // ---------------------------------------------------------------------------
149 // ---------------------------------------------------------------------------
151 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
152 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
154 #if TARGET_API_MAC_OSX
156 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
158 kEventControlVisibilityChanged
= 157
164 static const EventTypeSpec eventList
[] =
166 { kEventClassControl
, kEventControlHit
} ,
167 #if TARGET_API_MAC_OSX
168 { kEventClassControl
, kEventControlDraw
} ,
169 { kEventClassControl
, kEventControlVisibilityChanged
} ,
170 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
171 { kEventClassControl
, kEventControlHiliteChanged
} ,
172 { kEventClassControl
, kEventControlSetFocusPart
} ,
174 { kEventClassService
, kEventServiceGetTypes
},
175 { kEventClassService
, kEventServiceCopy
},
176 { kEventClassService
, kEventServicePaste
},
178 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
179 // { kEventClassControl , kEventControlBoundsChanged } ,
183 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
185 OSStatus result
= eventNotHandledErr
;
187 wxMacCarbonEvent
cEvent( event
) ;
189 ControlRef controlRef
;
190 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
192 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
194 switch( GetEventKind( event
) )
196 #if TARGET_API_MAC_OSX
197 case kEventControlDraw
:
199 RgnHandle updateRgn
= NULL
;
200 RgnHandle allocatedRgn
= NULL
;
201 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
202 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
204 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
208 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
210 allocatedRgn
= NewRgn() ;
211 CopyRgn( updateRgn
, allocatedRgn
) ;
212 // hide the given region by the new region that must be shifted
213 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
214 updateRgn
= allocatedRgn
;
219 // in case we would need a coregraphics compliant background erase first
220 // now usable to track redraws
221 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
222 if ( thisWindow
->MacIsUserPane() )
224 static float color
= 0.5 ;
227 HIViewGetBounds( controlRef
, &bounds
);
228 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
229 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
230 CGContextFillRect( cgContext
, bounds
);
241 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
244 DisposeRgn( allocatedRgn
) ;
247 case kEventControlVisibilityChanged
:
248 thisWindow
->MacVisibilityChanged() ;
250 case kEventControlEnabledStateChanged
:
251 thisWindow
->MacEnabledStateChanged() ;
253 case kEventControlHiliteChanged
:
254 thisWindow
->MacHiliteChanged() ;
256 case kEventControlSetFocusPart
:
258 Boolean focusEverything
= false ;
259 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
260 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
263 if ( controlPart
== kControlFocusNoPart
)
266 if ( thisWindow
->GetCaret() )
268 thisWindow
->GetCaret()->OnKillFocus();
270 #endif // wxUSE_CARET
271 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
272 event
.SetEventObject(thisWindow
);
273 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
277 // panel wants to track the window which was the last to have focus in it
278 wxChildFocusEvent
eventFocus(thisWindow
);
279 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
282 if ( thisWindow
->GetCaret() )
284 thisWindow
->GetCaret()->OnSetFocus();
286 #endif // wxUSE_CARET
288 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
289 event
.SetEventObject(thisWindow
);
290 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
292 if ( thisWindow
->MacIsUserPane() )
297 case kEventControlHit
:
299 result
= thisWindow
->MacControlHit( handler
, event
) ;
308 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
310 OSStatus result
= eventNotHandledErr
;
312 wxMacCarbonEvent
cEvent( event
) ;
314 ControlRef controlRef
;
315 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
316 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
317 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
319 switch( GetEventKind( event
) )
321 case kEventServiceGetTypes
:
325 textCtrl
->GetSelection( &from
, &to
) ;
327 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
329 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
330 if ( textCtrl
->IsEditable() )
331 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
333 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
334 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
336 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
340 CFArrayAppendValue (copyTypes
, typestring
) ;
342 CFArrayAppendValue (pasteTypes
, typestring
) ;
343 CFRelease( typestring
) ;
349 case kEventServiceCopy
:
353 textCtrl
->GetSelection( &from
, &to
) ;
354 wxString val
= textCtrl
->GetValue() ;
355 val
= val
.Mid( from
, to
- from
) ;
356 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
357 verify_noerr( ClearScrap( &scrapRef
) ) ;
358 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
362 case kEventServicePaste
:
365 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
366 Size textSize
, pastedSize
;
367 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
369 char *content
= new char[textSize
] ;
370 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
371 content
[textSize
-1] = 0 ;
373 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
375 textCtrl
->WriteText( wxString( content
) ) ;
386 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
388 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
389 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
390 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
391 OSStatus result
= eventNotHandledErr
;
393 switch ( GetEventClass( event
) )
395 case kEventClassControl
:
396 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
398 case kEventClassService
:
399 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
403 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
407 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
409 // ---------------------------------------------------------------------------
410 // UserPane events for non OSX builds
411 // ---------------------------------------------------------------------------
413 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
415 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
416 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
417 win
->MacControlUserPaneDrawProc(part
) ;
420 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
422 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
423 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
424 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
427 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
429 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
430 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
431 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
434 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
436 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
437 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
438 win
->MacControlUserPaneIdleProc() ;
441 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
443 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
444 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
445 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
448 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
450 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
451 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
452 win
->MacControlUserPaneActivateProc(activating
) ;
455 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
457 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
458 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
459 return win
->MacControlUserPaneFocusProc(action
) ;
462 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
464 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
465 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
466 win
->MacControlUserPaneBackgroundProc(info
) ;
469 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
471 RgnHandle rgn
= NewRgn() ;
473 wxMacWindowStateSaver
sv( this ) ;
474 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
475 MacDoRedraw( rgn
, 0 ) ;
479 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
481 return kControlNoPart
;
484 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
486 return kControlNoPart
;
489 void wxWindowMac::MacControlUserPaneIdleProc()
493 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
495 return kControlNoPart
;
498 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
502 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
504 return kControlNoPart
;
507 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
511 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
512 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
513 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
514 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
515 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
516 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
517 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
518 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
520 // ===========================================================================
522 // ===========================================================================
524 #if KEY_wxList_DEPRECATED
525 wxList
wxWinMacControlList(wxKEY_INTEGER
);
527 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
529 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
532 return (wxControl
*)node
->GetData();
535 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
537 // adding NULL ControlRef is (first) surely a result of an error and
538 // (secondly) breaks native event processing
539 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
541 if ( !wxWinMacControlList
.Find((long)inControl
) )
542 wxWinMacControlList
.Append((long)inControl
, control
);
545 void wxRemoveMacControlAssociation(wxWindow
*control
)
547 wxWinMacControlList
.DeleteObject(control
);
551 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
553 static MacControlMap wxWinMacControlList
;
555 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
557 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
559 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
562 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
564 // adding NULL ControlRef is (first) surely a result of an error and
565 // (secondly) breaks native event processing
566 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
568 wxWinMacControlList
[inControl
] = control
;
571 void wxRemoveMacControlAssociation(wxWindow
*control
)
573 // iterate over all the elements in the class
574 MacControlMap::iterator it
;
575 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
577 if ( it
->second
== control
)
579 wxWinMacControlList
.erase(it
);
584 #endif // deprecated wxList
587 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
589 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
591 // we have to setup the brush in the current port and return noErr
592 // or return an error code so that the control manager walks further up the
593 // hierarchy to find a correct background
595 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
597 OSStatus status
= paramErr
;
600 case kControlMsgApplyTextColor
:
602 case kControlMsgSetUpBackground
:
604 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
608 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
611 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
613 // this clipping is only needed for non HIView
615 RgnHandle clip
= NewRgn() ;
618 wx
->MacWindowToRootWindow( &x
,&y
) ;
619 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
620 OffsetRgn( clip
, x
, y
) ;
627 else if ( wx->MacIsUserPane() )
629 // if we don't have a valid brush for such a control, we have to call the
630 // setup of our parent ourselves
631 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
644 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
645 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
649 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
652 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
657 // ----------------------------------------------------------------------------
658 // constructors and such
659 // ----------------------------------------------------------------------------
661 wxWindowMac::wxWindowMac()
666 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
671 const wxString
& name
)
674 Create(parent
, id
, pos
, size
, style
, name
);
677 void wxWindowMac::Init()
681 #if WXWIN_COMPATIBILITY_2_4
682 m_backgroundTransparent
= FALSE
;
685 // as all windows are created with WS_VISIBLE style...
688 m_hScrollBar
= NULL
;
689 m_vScrollBar
= NULL
;
690 m_macBackgroundBrush
= wxNullBrush
;
692 m_macIsUserPane
= TRUE
;
694 // make sure all proc ptrs are available
696 if ( gControlUserPaneDrawUPP
== NULL
)
698 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
699 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
700 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
701 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
702 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
703 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
704 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
705 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
707 if ( wxMacLiveScrollbarActionUPP
== NULL
)
709 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
712 if ( wxMacSetupControlBackgroundUPP
== NULL
)
714 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
717 // we need a valid font for the encodings
718 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
722 wxWindowMac::~wxWindowMac()
726 m_isBeingDeleted
= TRUE
;
730 // deleting a window while it is shown invalidates the region occupied by border or
732 int outerBorder
= MacGetLeftBorderSize() ;
733 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
736 if ( IsShown() && ( outerBorder
> 0 ) )
738 // as the borders are drawn on the parent we have to properly invalidate all these areas
739 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
743 m_peer
->GetRect( &rect
) ;
744 RectRgn( updateInner
, &rect
) ;
745 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
746 RectRgn( updateOuter
, &rect
) ;
747 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
749 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
750 parent
-= GetParent()->GetClientAreaOrigin() ;
751 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
752 CopyRgn( updateOuter
, updateTotal
) ;
754 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
755 DisposeRgn(updateOuter
) ;
756 DisposeRgn(updateInner
) ;
757 DisposeRgn(updateTotal
) ;
761 #ifndef __WXUNIVERSAL__
762 // VS: make sure there's no wxFrame with last focus set to us:
763 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
765 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
768 if ( frame
->GetLastFocus() == this )
770 frame
->SetLastFocus((wxWindow
*)NULL
);
775 #endif // __WXUNIVERSAL__
777 // destroy children before destroying this window itself
780 // wxRemoveMacControlAssociation( this ) ;
781 // If we delete an item, we should initialize the parent panel,
782 // because it could now be invalid.
783 wxWindow
*parent
= GetParent() ;
786 if (parent
->GetDefaultItem() == (wxButton
*) this)
787 parent
->SetDefaultItem(NULL
);
789 if ( m_peer
&& m_peer
->Ok() )
791 // in case the callback might be called during destruction
792 wxRemoveMacControlAssociation( this) ;
793 // we currently are not using this hook
794 // ::SetControlColorProc( *m_peer , NULL ) ;
798 if ( g_MacLastWindow
== this )
800 g_MacLastWindow
= NULL
;
803 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
806 if ( frame
->GetLastFocus() == this )
807 frame
->SetLastFocus( NULL
) ;
810 // delete our drop target if we've got one
811 #if wxUSE_DRAG_AND_DROP
812 if ( m_dropTarget
!= NULL
)
817 #endif // wxUSE_DRAG_AND_DROP
821 WXWidget
wxWindowMac::GetHandle() const
823 return (WXWidget
) m_peer
->GetControlRef() ;
827 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
829 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
830 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
831 GetEventTypeCount(eventList
), eventList
, this,
832 (EventHandlerRef
*)&m_macControlEventHandler
);
837 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
841 const wxString
& name
)
843 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
845 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
848 m_windowVariant
= parent
->GetWindowVariant() ;
850 if ( m_macIsUserPane
)
852 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
855 | kControlSupportsEmbedding
856 // | kControlSupportsLiveFeedback
857 // | kControlHasSpecialBackground
858 // | kControlSupportsCalcBestRect
859 // | kControlHandlesTracking
860 | kControlSupportsFocus
861 // | kControlWantsActivate
862 // | kControlWantsIdle
865 m_peer
= new wxMacControl() ;
866 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
869 MacPostControlCreate(pos
,size
) ;
870 #if !TARGET_API_MAC_OSX
871 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
872 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
873 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
874 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
875 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
876 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
877 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
878 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
881 #ifndef __WXUNIVERSAL__
882 // Don't give scrollbars to wxControls unless they ask for them
883 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
884 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
886 MacCreateScrollBars( style
) ;
890 wxWindowCreateEvent
event(this);
891 GetEventHandler()->AddPendingEvent(event
);
896 void wxWindowMac::MacChildAdded()
900 m_vScrollBar
->Raise() ;
904 m_hScrollBar
->Raise() ;
909 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
911 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
913 m_peer
->SetReference( (long) this ) ;
914 GetParent()->AddChild(this);
916 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
918 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
919 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
920 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
921 GetParent()->MacChildAdded() ;
923 // adjust font, controlsize etc
924 DoSetWindowVariant( m_windowVariant
) ;
926 #if !TARGET_API_MAC_OSX
927 // eventually we can fix some clipping issues be reactivating this hook
928 //if ( m_macIsUserPane )
929 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
931 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
933 if (!m_macIsUserPane
)
935 SetInitialBestSize(size
);
938 SetCursor( *wxSTANDARD_CURSOR
) ;
941 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
943 // Don't assert, in case we set the window variant before
944 // the window is created
945 // wxASSERT( m_peer->Ok() ) ;
947 m_windowVariant
= variant
;
949 if (m_peer
== NULL
|| !m_peer
->Ok())
953 ThemeFontID themeFont
= kThemeSystemFont
;
955 // we will get that from the settings later
956 // and make this NORMAL later, but first
957 // we have a few calculations that we must fix
961 case wxWINDOW_VARIANT_NORMAL
:
962 size
= kControlSizeNormal
;
963 themeFont
= kThemeSystemFont
;
965 case wxWINDOW_VARIANT_SMALL
:
966 size
= kControlSizeSmall
;
967 themeFont
= kThemeSmallSystemFont
;
969 case wxWINDOW_VARIANT_MINI
:
970 if (UMAGetSystemVersion() >= 0x1030 )
972 // not always defined in the headers
978 size
= kControlSizeSmall
;
979 themeFont
= kThemeSmallSystemFont
;
982 case wxWINDOW_VARIANT_LARGE
:
983 size
= kControlSizeLarge
;
984 themeFont
= kThemeSystemFont
;
987 wxFAIL_MSG(_T("unexpected window variant"));
990 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
993 font
.MacCreateThemeFont( themeFont
) ;
997 void wxWindowMac::MacUpdateControlFont()
999 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1003 bool wxWindowMac::SetFont(const wxFont
& font
)
1005 bool retval
= wxWindowBase::SetFont( font
) ;
1007 MacUpdateControlFont() ;
1012 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1014 if ( !wxWindowBase::SetForegroundColour(col
) )
1017 MacUpdateControlFont() ;
1022 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1024 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1028 wxColour
newCol(GetBackgroundColour());
1029 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1031 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1033 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1035 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1039 brush
.SetColour( newCol
) ;
1041 MacSetBackgroundBrush( brush
) ;
1043 MacUpdateControlFont() ;
1048 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1050 m_macBackgroundBrush
= brush
;
1051 m_peer
->SetBackground( brush
) ;
1054 bool wxWindowMac::MacCanFocus() const
1056 // there is currently no way to determine whether the window is running in full keyboard
1057 // access mode, therefore we cannot rely on these features, yet the only other way would be
1058 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1059 // in event handlers...
1060 UInt32 features
= 0 ;
1061 m_peer
->GetFeatures( & features
) ;
1062 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1066 void wxWindowMac::SetFocus()
1068 if ( AcceptsFocus() )
1071 wxWindow
* former
= FindFocus() ;
1072 if ( former
== this )
1075 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1076 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1077 // leave in case of an error
1078 if ( err
== errCouldntSetFocus
)
1081 #if !TARGET_API_MAC_OSX
1082 // emulate carbon events when running under carbonlib where they are not natively available
1085 EventRef evRef
= NULL
;
1086 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1089 wxMacCarbonEvent
cEvent( evRef
) ;
1090 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1091 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1093 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1094 ReleaseEvent(evRef
) ;
1096 // send new focus event
1098 EventRef evRef
= NULL
;
1099 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1102 wxMacCarbonEvent
cEvent( evRef
) ;
1103 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1104 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1106 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1107 ReleaseEvent(evRef
) ;
1114 void wxWindowMac::DoCaptureMouse()
1116 wxTheApp
->s_captureWindow
= this ;
1119 wxWindow
* wxWindowBase::GetCapture()
1121 return wxTheApp
->s_captureWindow
;
1124 void wxWindowMac::DoReleaseMouse()
1126 wxTheApp
->s_captureWindow
= NULL
;
1129 #if wxUSE_DRAG_AND_DROP
1131 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1133 if ( m_dropTarget
!= 0 ) {
1134 delete m_dropTarget
;
1137 m_dropTarget
= pDropTarget
;
1138 if ( m_dropTarget
!= 0 )
1146 // Old style file-manager drag&drop
1147 void wxWindowMac::DragAcceptFiles(bool accept
)
1152 // Returns the size of the native control. In the case of the toplevel window
1153 // this is the content area root control
1155 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1156 int& w
, int& h
) const
1159 m_peer
->GetRect( &bounds
) ;
1164 w
= bounds
.right
- bounds
.left
;
1165 h
= bounds
.bottom
- bounds
.top
;
1168 // From a wx position / size calculate the appropriate size of the native control
1170 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1173 int& w
, int& h
, bool adjustOrigin
) const
1175 // the desired size, minus the border pixels gives the correct size of the control
1179 // todo the default calls may be used as soon as PostCreateControl Is moved here
1180 w
= size
.x
; // WidthDefault( size.x );
1181 h
= size
.y
; // HeightDefault( size.y ) ;
1182 #if !TARGET_API_MAC_OSX
1183 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1186 x
+= MacGetLeftBorderSize() ;
1187 y
+= MacGetTopBorderSize() ;
1188 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1189 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1192 AdjustForParentClientOrigin( x
, y
) ;
1193 #if TARGET_API_MAC_OSX
1194 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1195 if ( ! GetParent()->IsTopLevel() )
1197 x
-= GetParent()->MacGetLeftBorderSize() ;
1198 y
-= GetParent()->MacGetTopBorderSize() ;
1204 // Get window size (not client size)
1205 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1207 // take the size of the control and add the borders that have to be drawn outside
1208 int x1
, y1
, w1
, h1
;
1210 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1212 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1213 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1219 // get the position of the bounds of this window in client coordinates of its parent
1220 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1222 int x1
, y1
, w1
,h1
;
1223 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1224 x1
-= MacGetLeftBorderSize() ;
1225 y1
-= MacGetTopBorderSize() ;
1227 #if !TARGET_API_MAC_OSX
1228 if ( !GetParent()->IsTopLevel() )
1231 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1236 if ( !IsTopLevel() )
1238 wxWindow
*parent
= GetParent();
1241 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1242 x1
+= parent
->MacGetLeftBorderSize() ;
1243 y1
+= parent
->MacGetTopBorderSize() ;
1244 // and now to client coordinates
1245 wxPoint
pt(parent
->GetClientAreaOrigin());
1254 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1256 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1258 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1261 Point localwhere
= {0,0} ;
1263 if(x
) localwhere
.h
= * x
;
1264 if(y
) localwhere
.v
= * y
;
1266 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1267 if(x
) *x
= localwhere
.h
;
1268 if(y
) *y
= localwhere
.v
;
1271 MacRootWindowToWindow( x
, y
) ;
1273 wxPoint origin
= GetClientAreaOrigin() ;
1274 if(x
) *x
-= origin
.x
;
1275 if(y
) *y
-= origin
.y
;
1278 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1280 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1281 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1283 wxPoint origin
= GetClientAreaOrigin() ;
1284 if(x
) *x
+= origin
.x
;
1285 if(y
) *y
+= origin
.y
;
1287 MacWindowToRootWindow( x
, y
) ;
1290 Point localwhere
= { 0,0 };
1291 if(x
) localwhere
.h
= * x
;
1292 if(y
) localwhere
.v
= * y
;
1293 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1294 if(x
) *x
= localwhere
.h
;
1295 if(y
) *y
= localwhere
.v
;
1299 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1301 wxPoint origin
= GetClientAreaOrigin() ;
1302 if(x
) *x
+= origin
.x
;
1303 if(y
) *y
+= origin
.y
;
1305 MacWindowToRootWindow( x
, y
) ;
1308 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1310 MacRootWindowToWindow( x
, y
) ;
1312 wxPoint origin
= GetClientAreaOrigin() ;
1313 if(x
) *x
-= origin
.x
;
1314 if(y
) *y
-= origin
.y
;
1317 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1319 #if TARGET_API_MAC_OSX
1321 if ( x
) pt
.x
= *x
;
1322 if ( y
) pt
.y
= *y
;
1324 if ( !IsTopLevel() )
1326 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1329 pt
.x
-= MacGetLeftBorderSize() ;
1330 pt
.y
-= MacGetTopBorderSize() ;
1331 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1335 if ( x
) *x
= (int) pt
.x
;
1336 if ( y
) *y
= (int) pt
.y
;
1338 if ( !IsTopLevel() )
1341 m_peer
->GetRect( &bounds
) ;
1342 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1343 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1348 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1353 MacWindowToRootWindow( &x1
, &y1
) ;
1358 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1360 #if TARGET_API_MAC_OSX
1362 if ( x
) pt
.x
= *x
;
1363 if ( y
) pt
.y
= *y
;
1365 if ( !IsTopLevel() )
1367 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1368 pt
.x
+= MacGetLeftBorderSize() ;
1369 pt
.y
+= MacGetTopBorderSize() ;
1372 if ( x
) *x
= (int) pt
.x
;
1373 if ( y
) *y
= (int) pt
.y
;
1375 if ( !IsTopLevel() )
1378 m_peer
->GetRect( &bounds
) ;
1379 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1380 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1385 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1390 MacRootWindowToWindow( &x1
, &y1
) ;
1395 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1397 RgnHandle rgn
= NewRgn() ;
1399 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1401 GetRegionBounds( rgn
, &content
) ;
1405 m_peer
->GetRect( &content
) ;
1409 m_peer
->GetRect( &structure
) ;
1410 #if !TARGET_API_MAC_OSX
1411 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1413 left
= content
.left
- structure
.left
;
1414 top
= content
.top
- structure
.top
;
1415 right
= structure
.right
- content
.right
;
1416 bottom
= structure
.bottom
- content
.bottom
;
1419 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1421 wxSize sizeTotal
= size
;
1423 RgnHandle rgn
= NewRgn() ;
1427 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1429 GetRegionBounds( rgn
, &content
) ;
1433 m_peer
->GetRect( &content
) ;
1437 m_peer
->GetRect( &structure
) ;
1438 #if !TARGET_API_MAC_OSX
1439 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1442 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1443 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1445 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1446 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1452 // Get size *available for subwindows* i.e. excluding menu bar etc.
1453 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1457 RgnHandle rgn
= NewRgn() ;
1459 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1461 GetRegionBounds( rgn
, &content
) ;
1465 m_peer
->GetRect( &content
) ;
1468 #if !TARGET_API_MAC_OSX
1470 m_peer
->GetRect( &structure
) ;
1471 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1473 ww
= content
.right
- content
.left
;
1474 hh
= content
.bottom
- content
.top
;
1476 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1477 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1480 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1486 GetSize( &w , &h ) ;
1488 MacClientToRootWindow( &x1 , &y1 ) ;
1489 MacClientToRootWindow( &w , &h ) ;
1491 wxWindowMac *iter = (wxWindowMac*)this ;
1493 int totW = 10000 , totH = 10000;
1496 if ( iter->IsTopLevel() )
1498 iter->GetSize( &totW , &totH ) ;
1502 iter = iter->GetParent() ;
1505 if (m_hScrollBar && m_hScrollBar->IsShown() )
1507 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1513 if (m_vScrollBar && m_vScrollBar->IsShown() )
1515 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1523 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1525 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1527 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1529 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1536 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1538 if (m_cursor
== cursor
)
1541 if (wxNullCursor
== cursor
)
1543 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1548 if ( ! wxWindowBase::SetCursor( cursor
) )
1552 wxASSERT_MSG( m_cursor
.Ok(),
1553 wxT("cursor must be valid after call to the base version"));
1556 wxWindowMac
*mouseWin
= 0 ;
1558 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1560 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1562 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1563 // position, use it...
1567 ControlPartCode part
;
1568 ControlRef control
;
1569 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1571 mouseWin
= wxFindControlFromMacControl( control
) ;
1574 QDSwapPort( savePort
, NULL
) ;
1577 if ( mouseWin
== this && !wxIsBusy() )
1579 m_cursor
.MacInstall() ;
1586 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1588 menu
->SetInvokingWindow(this);
1591 if ( x
== -1 && y
== -1 )
1593 wxPoint mouse
= wxGetMousePosition();
1594 x
= mouse
.x
; y
= mouse
.y
;
1598 ClientToScreen( &x
, &y
) ;
1601 menu
->MacBeforeDisplay( true ) ;
1602 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1603 if ( HiWord(menuResult
) != 0 )
1606 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1607 wxMenuItem
* item
= NULL
;
1609 item
= menu
->FindItem(id
, &realmenu
) ;
1610 if (item
->IsCheckable())
1612 item
->Check( !item
->IsChecked() ) ;
1614 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1616 menu
->MacAfterDisplay( true ) ;
1618 menu
->SetInvokingWindow(NULL
);
1624 // ----------------------------------------------------------------------------
1626 // ----------------------------------------------------------------------------
1630 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1632 wxWindowBase::DoSetToolTip(tooltip
);
1635 m_tooltip
->SetWindow(this);
1638 #endif // wxUSE_TOOLTIPS
1640 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1642 // this is never called for a toplevel window, so we know we have a parent
1643 int former_x
, former_y
, former_w
, former_h
;
1645 // Get true coordinates of former position
1646 DoGetPosition( &former_x
, &former_y
) ;
1647 DoGetSize( &former_w
, &former_h
) ;
1649 wxWindow
*parent
= GetParent();
1652 wxPoint
pt(parent
->GetClientAreaOrigin());
1657 int actualWidth
= width
;
1658 int actualHeight
= height
;
1662 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1663 actualWidth
= m_minWidth
;
1664 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1665 actualHeight
= m_minHeight
;
1666 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1667 actualWidth
= m_maxWidth
;
1668 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1669 actualHeight
= m_maxHeight
;
1671 bool doMove
= false ;
1672 bool doResize
= false ;
1674 if ( actualX
!= former_x
|| actualY
!= former_y
)
1678 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1683 if ( doMove
|| doResize
)
1685 // we don't adjust twice for the origin
1686 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1687 bool vis
= m_peer
->IsVisible();
1689 int outerBorder
= MacGetLeftBorderSize() ;
1690 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1693 if ( vis
&& ( outerBorder
> 0 ) )
1695 // as the borders are drawn on the parent we have to properly invalidate all these areas
1696 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1700 m_peer
->GetRect( &rect
) ;
1701 RectRgn( updateInner
, &rect
) ;
1702 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1703 RectRgn( updateOuter
, &rect
) ;
1704 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1705 wxPoint
parent(0,0);
1706 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1707 parent
-= GetParent()->GetClientAreaOrigin() ;
1708 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1709 CopyRgn( updateOuter
, updateTotal
) ;
1712 RectRgn( updateInner
, &rect
) ;
1713 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1714 RectRgn( updateOuter
, &rect
) ;
1715 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1717 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1718 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1720 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1721 DisposeRgn(updateOuter
) ;
1722 DisposeRgn(updateInner
) ;
1723 DisposeRgn(updateTotal
) ;
1726 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1728 m_peer
->SetVisibility( false , true ) ;
1730 m_peer
->SetRect( &r
) ;
1732 m_peer
->SetVisibility( true , true ) ;
1734 MacRepositionScrollBars() ;
1737 wxPoint
point(actualX
,actualY
);
1738 wxMoveEvent
event(point
, m_windowId
);
1739 event
.SetEventObject(this);
1740 GetEventHandler()->ProcessEvent(event
) ;
1744 MacRepositionScrollBars() ;
1745 wxSize
size(actualWidth
, actualHeight
);
1746 wxSizeEvent
event(size
, m_windowId
);
1747 event
.SetEventObject(this);
1748 GetEventHandler()->ProcessEvent(event
);
1754 wxSize
wxWindowMac::DoGetBestSize() const
1756 if ( m_macIsUserPane
|| IsTopLevel() )
1757 return wxWindowBase::DoGetBestSize() ;
1759 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1760 int bestWidth
, bestHeight
;
1761 m_peer
->GetBestRect( &bestsize
) ;
1763 if ( EmptyRect( &bestsize
) )
1765 bestsize
.left
= bestsize
.top
= 0 ;
1766 bestsize
.right
= 16 ;
1767 bestsize
.bottom
= 16 ;
1768 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1770 bestsize
.bottom
= 16 ;
1773 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1775 bestsize
.bottom
= 24 ;
1777 #endif // wxUSE_SPINBTN
1780 // return wxWindowBase::DoGetBestSize() ;
1784 bestWidth
= bestsize
.right
- bestsize
.left
;
1785 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1786 if ( bestHeight
< 10 )
1789 return wxSize(bestWidth
, bestHeight
);
1793 // set the size of the window: if the dimensions are positive, just use them,
1794 // but if any of them is equal to -1, it means that we must find the value for
1795 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1796 // which case -1 is a valid value for x and y)
1798 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1799 // the width/height to best suit our contents, otherwise we reuse the current
1801 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1803 // get the current size and position...
1804 int currentX
, currentY
;
1805 GetPosition(¤tX
, ¤tY
);
1807 int currentW
,currentH
;
1808 GetSize(¤tW
, ¤tH
);
1810 // ... and don't do anything (avoiding flicker) if it's already ok
1811 if ( x
== currentX
&& y
== currentY
&&
1812 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1815 MacRepositionScrollBars() ; // we might have a real position shift
1819 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1821 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1824 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1826 wxSize
size(-1, -1);
1829 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1831 size
= DoGetBestSize();
1836 // just take the current one
1843 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1847 size
= DoGetBestSize();
1849 //else: already called DoGetBestSize() above
1855 // just take the current one
1860 DoMoveWindow(x
, y
, width
, height
);
1864 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1866 RgnHandle rgn
= NewRgn() ;
1868 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1869 GetRegionBounds( rgn
, &content
) ;
1871 #if !TARGET_API_MAC_OSX
1872 // if the content rgn is empty / not supported
1873 // don't attempt to correct the coordinates to wxWindow relative ones
1874 if (!::EmptyRect( &content
) )
1877 m_peer
->GetRect( &structure
) ;
1878 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1882 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1885 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1887 if ( clientheight
!= -1 || clientheight
!= -1 )
1889 int currentclientwidth
, currentclientheight
;
1890 int currentwidth
, currentheight
;
1892 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1893 GetSize( ¤twidth
, ¤theight
) ;
1895 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1896 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1900 void wxWindowMac::SetTitle(const wxString
& title
)
1902 m_label
= wxStripMenuCodes(title
) ;
1904 if ( m_peer
&& m_peer
->Ok() )
1906 m_peer
->SetTitle( m_label
) ;
1911 wxString
wxWindowMac::GetTitle() const
1916 bool wxWindowMac::Show(bool show
)
1918 if ( !wxWindowBase::Show(show
) )
1921 // TODO use visibilityChanged Carbon Event for OSX
1924 bool former
= MacIsReallyShown() ;
1926 m_peer
->SetVisibility( show
, true ) ;
1927 if ( former
!= MacIsReallyShown() )
1928 MacPropagateVisibilityChanged() ;
1933 bool wxWindowMac::Enable(bool enable
)
1935 wxASSERT( m_peer
->Ok() ) ;
1936 if ( !wxWindowBase::Enable(enable
) )
1939 bool former
= MacIsReallyEnabled() ;
1940 m_peer
->Enable( enable
) ;
1942 if ( former
!= MacIsReallyEnabled() )
1943 MacPropagateEnabledStateChanged() ;
1948 // status change propagations (will be not necessary for OSX later )
1951 void wxWindowMac::MacPropagateVisibilityChanged()
1953 #if !TARGET_API_MAC_OSX
1954 MacVisibilityChanged() ;
1956 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1959 wxWindowMac
*child
= node
->GetData();
1960 if ( child
->IsShown() )
1961 child
->MacPropagateVisibilityChanged( ) ;
1962 node
= node
->GetNext();
1967 void wxWindowMac::MacPropagateEnabledStateChanged( )
1969 #if !TARGET_API_MAC_OSX
1970 MacEnabledStateChanged() ;
1972 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1975 wxWindowMac
*child
= node
->GetData();
1976 if ( child
->IsEnabled() )
1977 child
->MacPropagateEnabledStateChanged() ;
1978 node
= node
->GetNext();
1983 void wxWindowMac::MacPropagateHiliteChanged( )
1985 #if !TARGET_API_MAC_OSX
1986 MacHiliteChanged() ;
1988 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1991 wxWindowMac
*child
= node
->GetData();
1992 // if ( child->IsEnabled() )
1993 child
->MacPropagateHiliteChanged() ;
1994 node
= node
->GetNext();
2000 // status change notifications
2003 void wxWindowMac::MacVisibilityChanged()
2007 void wxWindowMac::MacHiliteChanged()
2011 void wxWindowMac::MacEnabledStateChanged()
2016 // status queries on the inherited window's state
2019 bool wxWindowMac::MacIsReallyShown()
2021 // only under OSX the visibility of the TLW is taken into account
2022 if ( m_isBeingDeleted
)
2025 #if TARGET_API_MAC_OSX
2026 if ( m_peer
&& m_peer
->Ok() )
2027 return m_peer
->IsVisible();
2029 wxWindow
* win
= this ;
2030 while( win
->IsShown() )
2032 if ( win
->IsTopLevel() )
2035 win
= win
->GetParent() ;
2043 bool wxWindowMac::MacIsReallyEnabled()
2045 return m_peer
->IsEnabled() ;
2048 bool wxWindowMac::MacIsReallyHilited()
2050 return m_peer
->IsActive();
2053 void wxWindowMac::MacFlashInvalidAreas()
2055 #if TARGET_API_MAC_OSX
2056 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2064 int wxWindowMac::GetCharHeight() const
2066 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2067 return dc
.GetCharHeight() ;
2070 int wxWindowMac::GetCharWidth() const
2072 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2073 return dc
.GetCharWidth() ;
2076 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2077 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2079 const wxFont
*fontToUse
= theFont
;
2081 fontToUse
= &m_font
;
2083 wxClientDC
dc( (wxWindowMac
*) this ) ;
2085 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2086 if ( externalLeading
)
2087 *externalLeading
= le
;
2097 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2098 * we always intersect with the entire window, not only with the client area
2101 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2103 if ( m_peer
== NULL
)
2106 #if TARGET_API_MAC_OSX
2108 m_peer
->SetNeedsDisplay( true ) ;
2111 RgnHandle update
= NewRgn() ;
2112 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2113 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2114 wxPoint origin
= GetClientAreaOrigin() ;
2115 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2116 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2118 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2119 m_peer
->SetNeedsDisplay( true , update
) ;
2120 DisposeRgn( update
) ;
2124 RgnHandle updateRgn = NewRgn() ;
2127 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2131 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2132 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2134 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2135 DisposeRgn(updateRgn) ;
2137 if ( m_peer
->IsVisible())
2139 m_peer
->SetVisibility( false , false ) ;
2140 m_peer
->SetVisibility( true , true ) ;
2143 if ( MacGetTopLevelWindow() == NULL )
2146 if ( !m_peer->IsVisible())
2149 wxPoint client = GetClientAreaOrigin();
2152 int x2 = m_width - client.x;
2153 int y2 = m_height - client.y;
2155 if (IsKindOf( CLASSINFO(wxButton)))
2157 // buttons have an "aura"
2164 Rect clientrect = { y1, x1, y2, x2 };
2168 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2169 SectRect( &clientrect , &r , &clientrect ) ;
2172 if ( !EmptyRect( &clientrect ) )
2174 int top = 0 , left = 0 ;
2176 MacClientToRootWindow( &left , &top ) ;
2177 OffsetRect( &clientrect , left , top ) ;
2179 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2185 void wxWindowMac::Freeze()
2187 #if TARGET_API_MAC_OSX
2188 if ( !m_frozenness
++ )
2190 if ( m_peer
&& m_peer
->Ok() )
2191 m_peer
->SetDrawingEnabled( false ) ;
2197 void wxWindowMac::Thaw()
2199 #if TARGET_API_MAC_OSX
2200 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2202 if ( !--m_frozenness
)
2204 if ( m_peer
&& m_peer
->Ok() )
2206 m_peer
->SetDrawingEnabled( true ) ;
2207 m_peer
->InvalidateWithChildren() ;
2213 void wxWindowMac::MacRedrawControl()
2216 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2218 #if TARGET_API_MAC_CARBON
2221 wxClientDC dc(this) ;
2222 wxMacPortSetter helper(&dc) ;
2223 wxMacWindowClipper clipper(this) ;
2224 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2225 UMADrawControl( *m_peer ) ;
2232 void wxWindowMac::OnPaint(wxPaintEvent& event)
2234 // why don't we skip that here ?
2238 wxWindowMac
*wxGetActiveWindow()
2240 // actually this is a windows-only concept
2244 // Coordinates relative to the window
2245 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2247 // We really don't move the mouse programmatically under Mac.
2250 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2252 #if TARGET_API_MAC_OSX
2253 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2260 event
.GetDC()->Clear() ;
2264 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2269 int wxWindowMac::GetScrollPos(int orient
) const
2271 if ( orient
== wxHORIZONTAL
)
2274 return m_hScrollBar
->GetThumbPosition() ;
2279 return m_vScrollBar
->GetThumbPosition() ;
2284 // This now returns the whole range, not just the number
2285 // of positions that we can scroll.
2286 int wxWindowMac::GetScrollRange(int orient
) const
2288 if ( orient
== wxHORIZONTAL
)
2291 return m_hScrollBar
->GetRange() ;
2296 return m_vScrollBar
->GetRange() ;
2301 int wxWindowMac::GetScrollThumb(int orient
) const
2303 if ( orient
== wxHORIZONTAL
)
2306 return m_hScrollBar
->GetThumbSize() ;
2311 return m_vScrollBar
->GetThumbSize() ;
2316 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2318 if ( orient
== wxHORIZONTAL
)
2321 m_hScrollBar
->SetThumbPosition( pos
) ;
2326 m_vScrollBar
->SetThumbPosition( pos
) ;
2330 void wxWindowMac::MacPaintBorders( int left
, int top
)
2336 m_peer
->GetRect( &rect
) ;
2337 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2339 if ( !IsTopLevel() )
2341 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2345 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2347 rect
.right
+= pt
.x
;
2349 rect
.bottom
+= pt
.y
;
2353 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2357 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2358 InsetRect( &srect
, border
, border
);
2359 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2361 else if (HasFlag(wxSIMPLE_BORDER
))
2365 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2366 InsetRect( &srect
, border
, border
);
2367 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2371 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2373 if ( child
== m_hScrollBar
)
2374 m_hScrollBar
= NULL
;
2375 if ( child
== m_vScrollBar
)
2376 m_vScrollBar
= NULL
;
2378 wxWindowBase::RemoveChild( child
) ;
2381 // New function that will replace some of the above.
2382 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2383 int range
, bool refresh
)
2385 if ( orient
== wxHORIZONTAL
)
2389 if ( range
== 0 || thumbVisible
>= range
)
2391 if ( m_hScrollBar
->IsShown() )
2392 m_hScrollBar
->Show(false) ;
2396 if ( !m_hScrollBar
->IsShown() )
2397 m_hScrollBar
->Show(true) ;
2399 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2406 if ( range
== 0 || thumbVisible
>= range
)
2408 if ( m_vScrollBar
->IsShown() )
2409 m_vScrollBar
->Show(false) ;
2413 if ( !m_vScrollBar
->IsShown() )
2414 m_vScrollBar
->Show(true) ;
2416 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2419 MacRepositionScrollBars() ;
2422 // Does a physical scroll
2423 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2425 if( dx
== 0 && dy
==0 )
2431 int width
, height
;
2432 GetClientSize( &width
, &height
) ;
2433 #if TARGET_API_MAC_OSX
2434 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2435 // area is scrolled, this does not occur if width and height are 2 pixels less,
2436 // TODO write optimal workaround
2437 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2440 scrollrect
.Intersect( *rect
) ;
2442 if ( m_peer
->GetNeedsDisplay() )
2444 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2445 // either immediate redraw or full invalidate
2447 // is the better overall solution, as it does not slow down scrolling
2448 m_peer
->SetNeedsDisplay( true ) ;
2450 // this would be the preferred version for fast drawing controls
2451 if( UMAGetSystemVersion() < 0x1030 )
2454 HIViewRender(m_peer
->GetControlRef()) ;
2457 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2458 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2459 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2466 RgnHandle updateRgn
= NewRgn() ;
2469 wxClientDC
dc(this) ;
2470 wxMacPortSetter
helper(&dc
) ;
2472 m_peer
->GetRect( &scrollrect
) ;
2473 scrollrect
.top
+= MacGetTopBorderSize() ;
2474 scrollrect
.left
+= MacGetLeftBorderSize() ;
2475 scrollrect
.bottom
= scrollrect
.top
+ height
;
2476 scrollrect
.right
= scrollrect
.left
+ width
;
2480 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2481 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2482 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2484 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2486 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2490 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2492 wxWindowMac
*child
= node
->GetData();
2493 if (child
== m_vScrollBar
) continue;
2494 if (child
== m_hScrollBar
) continue;
2495 if (child
->IsTopLevel()) continue;
2498 child
->GetPosition( &x
, &y
);
2500 child
->GetSize( &w
, &h
);
2504 if (rect
->Intersects(rc
))
2505 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2509 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2514 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2516 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2518 wxScrollWinEvent wevent
;
2519 wevent
.SetPosition(event
.GetPosition());
2520 wevent
.SetOrientation(event
.GetOrientation());
2521 wevent
.SetEventObject(this);
2523 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2524 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2525 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2526 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2527 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2528 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2529 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2530 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2531 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2532 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2533 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2534 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2535 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2536 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2537 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2538 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2540 GetEventHandler()->ProcessEvent(wevent
);
2544 // Get the window with the focus
2545 wxWindowMac
*wxWindowBase::DoFindFocus()
2547 ControlRef control
;
2548 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2549 return wxFindControlFromMacControl( control
) ;
2552 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2554 // panel wants to track the window which was the last to have focus in it,
2555 // so we want to set ourselves as the window which last had focus
2557 // notice that it's also important to do it upwards the tree becaus
2558 // otherwise when the top level panel gets focus, it won't set it back to
2559 // us, but to some other sibling
2561 // CS:don't know if this is still needed:
2562 //wxChildFocusEvent eventFocus(this);
2563 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2565 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2567 wxMacWindowStateSaver
sv( this ) ;
2572 MacWindowToRootWindow( &x
, &y
) ;
2573 GetSize( &w
, &h
) ;
2574 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2576 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2577 DrawThemeFocusRect( &rect
, true ) ;
2580 DrawThemeFocusRect( &rect
, false ) ;
2582 // as this erases part of the frame we have to redraw borders
2583 // and because our z-ordering is not always correct (staticboxes)
2584 // we have to invalidate things, we cannot simple redraw
2585 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2586 RectRgn( updateInner
, &rect
) ;
2587 InsetRect( &rect
, -4 , -4 ) ;
2588 RectRgn( updateOuter
, &rect
) ;
2589 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2590 wxPoint
parent(0,0);
2591 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2592 parent
-= GetParent()->GetClientAreaOrigin() ;
2593 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2594 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2595 DisposeRgn(updateOuter
) ;
2596 DisposeRgn(updateInner
) ;
2603 void wxWindowMac::OnInternalIdle()
2605 // This calls the UI-update mechanism (querying windows for
2606 // menu/toolbar/control state information)
2607 if (wxUpdateUIEvent::CanUpdate(this))
2608 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2611 // Raise the window to the top of the Z order
2612 void wxWindowMac::Raise()
2614 m_peer
->SetZOrder( true , NULL
) ;
2617 // Lower the window to the bottom of the Z order
2618 void wxWindowMac::Lower()
2620 m_peer
->SetZOrder( false , NULL
) ;
2624 // static wxWindow *gs_lastWhich = NULL;
2626 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2628 // first trigger a set cursor event
2630 wxPoint clientorigin
= GetClientAreaOrigin() ;
2631 wxSize clientsize
= GetClientSize() ;
2633 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2635 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2637 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2638 if ( processedEvtSetCursor
&& event
.HasCursor() )
2640 cursor
= event
.GetCursor() ;
2645 // the test for processedEvtSetCursor is here to prevent using m_cursor
2646 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2647 // it - this is a way to say that our cursor shouldn't be used for this
2649 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2659 cursor
= *wxSTANDARD_CURSOR
;
2663 cursor
.MacInstall() ;
2665 return cursor
.Ok() ;
2668 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2672 return m_tooltip
->GetTip() ;
2674 return wxEmptyString
;
2677 void wxWindowMac::Update()
2679 #if TARGET_API_MAC_OSX
2681 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2682 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2684 // for composited windows this also triggers a redraw of all
2685 // invalid views in the window
2686 if( UMAGetSystemVersion() >= 0x1030 )
2687 HIWindowFlush(window
) ;
2691 // the only way to trigger the redrawing on earlier systems is to call
2694 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2695 UInt32 currentEventClass
= 0 ;
2696 UInt32 currentEventKind
= 0 ;
2697 if ( currentEvent
!= NULL
)
2699 currentEventClass
= ::GetEventClass( currentEvent
) ;
2700 currentEventKind
= ::GetEventKind( currentEvent
) ;
2702 if ( currentEventClass
!= kEventClassMenu
)
2704 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2707 OSStatus status
= noErr
;
2708 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2711 m_peer
->SetNeedsDisplay( true ) ;
2714 ::Draw1Control( m_peer
->GetControlRef() ) ;
2718 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2720 wxTopLevelWindowMac
* win
= NULL
;
2721 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2724 win
= wxFindWinFromMacWindow( window
) ;
2728 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2730 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2731 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2732 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2733 // to add focus borders everywhere
2736 RgnHandle visRgn
= NewRgn() ;
2737 RgnHandle tempRgn
= NewRgn() ;
2738 if ( !m_isBeingDeleted
&& m_peer
->IsVisible())
2740 m_peer
->GetRect( &r
) ;
2741 r
.left
-= MacGetLeftBorderSize() ;
2742 r
.top
-= MacGetTopBorderSize() ;
2743 r
.bottom
+= MacGetBottomBorderSize() ;
2744 r
.right
+= MacGetRightBorderSize() ;
2746 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2748 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2749 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2758 if ( includeOuterStructures
)
2759 InsetRect( &r
, -4 , -4 ) ;
2760 RectRgn( visRgn
, &r
) ;
2762 if ( !IsTopLevel() )
2764 wxWindow
* child
= this ;
2765 wxWindow
* parent
= child
->GetParent() ;
2770 // we have to find a better clipping algorithm here, in order not to clip things
2771 // positioned like status and toolbar
2772 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2774 size
= parent
->GetSize() ;
2779 size
= parent
->GetClientSize() ;
2780 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2784 parent
->MacWindowToRootWindow( &x
, &y
) ;
2785 MacRootWindowToWindow( &x
, &y
) ;
2787 if ( !includeOuterStructures
|| (
2788 parent
->MacClipChildren() ||
2789 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2792 SetRectRgn( tempRgn
,
2793 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2794 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2795 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2797 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2799 if ( parent
->IsTopLevel() )
2802 parent
= child
->GetParent() ;
2807 wxRegion vis
= visRgn
;
2808 DisposeRgn( visRgn
) ;
2809 DisposeRgn( tempRgn
) ;
2814 This function must not change the updatergn !
2816 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2818 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2819 bool handled
= false ;
2821 GetRegionBounds( updatergn
, &updatebounds
) ;
2822 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2823 if ( !EmptyRgn(updatergn
) )
2825 RgnHandle newupdate
= NewRgn() ;
2826 wxSize point
= GetClientSize() ;
2827 wxPoint origin
= GetClientAreaOrigin() ;
2828 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2829 SectRgn( newupdate
, updatergn
, newupdate
) ;
2831 // first send an erase event to the entire update area
2833 wxWindowDC
dc(this);
2834 dc
.SetClippingRegion(wxRegion(updatergn
));
2835 wxEraseEvent
eevent( GetId(), &dc
);
2836 eevent
.SetEventObject( this );
2837 GetEventHandler()->ProcessEvent( eevent
);
2840 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2841 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2842 m_updateRegion
= newupdate
;
2843 DisposeRgn( newupdate
) ;
2845 if ( !m_updateRegion
.Empty() )
2847 // paint the window itself
2849 event
.SetTimestamp(time
);
2850 event
.SetEventObject(this);
2851 handled
= GetEventHandler()->ProcessEvent(event
);
2853 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2856 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2858 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2865 // now we cannot rely on having its borders drawn by a window itself, as it does not
2866 // get the updateRgn wide enough to always do so, so we do it from the parent
2867 // this would also be the place to draw any custom backgrounds for native controls
2868 // in Composited windowing
2869 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2871 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2873 wxWindowMac
*child
= node
->GetData();
2874 if (child
== m_vScrollBar
) continue;
2875 if (child
== m_hScrollBar
) continue;
2876 if (child
->IsTopLevel()) continue;
2877 if (!child
->IsShown()) continue;
2880 child
->GetPosition( &x
, &y
);
2882 child
->GetSize( &w
, &h
);
2883 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2884 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2885 if ( child
->MacGetTopBorderSize() )
2887 if ( RectInRgn( &childRect
, updatergn
) )
2889 // paint custom borders
2890 wxNcPaintEvent
eventNc( child
->GetId() );
2891 eventNc
.SetEventObject( child
);
2892 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2894 wxWindowDC
dc(this) ;
2895 dc
.SetClippingRegion(wxRegion(updatergn
));
2896 wxMacPortSetter
helper(&dc
) ;
2897 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2901 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2903 wxWindowDC
dc(this) ;
2904 dc
.SetClippingRegion(wxRegion(updatergn
));
2905 wxMacPortSetter
helper(&dc
) ;
2906 Rect r
= childRect
;
2907 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2908 DrawThemeFocusRect( &r
, true ) ;
2915 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2917 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2918 // updatergn is always already clipped to our boundaries
2919 // if we are in compositing mode then it is in relative to the upper left of the control
2920 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2921 // of the toplevel window
2922 // it is in window coordinates, not in client coordinates
2924 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2925 RgnHandle ownUpdateRgn
= NewRgn() ;
2926 CopyRgn( updatergn
, ownUpdateRgn
) ;
2928 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2931 m_peer
->GetRectInWindowCoords( &bounds
);
2932 RgnHandle controlRgn
= NewRgn();
2933 RectRgn( controlRgn
, &bounds
);
2934 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2935 // the window update region
2936 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2937 DisposeRgn( controlRgn
);
2939 //KO: convert ownUpdateRgn to local coordinates
2940 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2943 MacDoRedraw( ownUpdateRgn
, time
) ;
2944 DisposeRgn( ownUpdateRgn
) ;
2948 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2950 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2954 if ( iter
->IsTopLevel() )
2955 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2957 iter
= iter
->GetParent() ;
2959 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2963 void wxWindowMac::MacCreateScrollBars( long style
)
2965 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2967 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2969 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2970 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2971 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2972 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2974 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2975 variant
= wxWINDOW_VARIANT_SMALL
;
2978 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2980 GetClientSize( &width
, &height
) ;
2982 wxPoint
vPoint(width
-scrlsize
, 0) ;
2983 wxSize
vSize(scrlsize
, height
- adjust
) ;
2984 wxPoint
hPoint(0 , height
-scrlsize
) ;
2985 wxSize
hSize( width
- adjust
, scrlsize
) ;
2988 if ( style
& wxVSCROLL
)
2990 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2991 vSize
, wxVERTICAL
);
2994 if ( style
& wxHSCROLL
)
2996 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2997 hSize
, wxHORIZONTAL
);
3002 // because the create does not take into account the client area origin
3003 MacRepositionScrollBars() ; // we might have a real position shift
3006 void wxWindowMac::MacRepositionScrollBars()
3008 if ( !m_hScrollBar
&& !m_vScrollBar
)
3011 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3012 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3013 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3015 // get real client area
3019 GetSize( &width
, &height
) ;
3021 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3022 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3024 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3025 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3026 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3027 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3033 GetSize( &w , &h ) ;
3035 MacClientToRootWindow( &x , &y ) ;
3036 MacClientToRootWindow( &w , &h ) ;
3038 wxWindowMac *iter = (wxWindowMac*)this ;
3040 int totW = 10000 , totH = 10000;
3043 if ( iter->IsTopLevel() )
3045 iter->GetSize( &totW , &totH ) ;
3049 iter = iter->GetParent() ;
3077 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3081 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3085 bool wxWindowMac::AcceptsFocus() const
3087 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3090 void wxWindowMac::MacSuperChangedPosition()
3092 // only window-absolute structures have to be moved i.e. controls
3094 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3097 wxWindowMac
*child
= node
->GetData();
3098 child
->MacSuperChangedPosition() ;
3099 node
= node
->GetNext();
3103 void wxWindowMac::MacTopLevelWindowChangedPosition()
3105 // only screen-absolute structures have to be moved i.e. glcanvas
3107 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3110 wxWindowMac
*child
= node
->GetData();
3111 child
->MacTopLevelWindowChangedPosition() ;
3112 node
= node
->GetNext();
3116 long wxWindowMac::MacGetLeftBorderSize( ) const
3121 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3126 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3131 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3138 long wxWindowMac::MacGetRightBorderSize( ) const
3140 // they are all symmetric in mac themes
3141 return MacGetLeftBorderSize() ;
3144 long wxWindowMac::MacGetTopBorderSize( ) const
3146 // they are all symmetric in mac themes
3147 return MacGetLeftBorderSize() ;
3150 long wxWindowMac::MacGetBottomBorderSize( ) const
3152 // they are all symmetric in mac themes
3153 return MacGetLeftBorderSize() ;
3156 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3158 return style
& ~wxBORDER_MASK
;
3161 // Find the wxWindowMac at the current mouse position, returning the mouse
3163 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3165 pt
= wxGetMousePosition();
3166 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3170 // Get the current mouse position.
3171 wxPoint
wxGetMousePosition()
3174 wxGetMousePosition(& x
, & y
);
3175 return wxPoint(x
, y
);
3178 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3180 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3182 // copied from wxGTK : CS
3183 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3186 // (a) it's a command event and so is propagated to the parent
3187 // (b) under MSW it can be generated from kbd too
3188 // (c) it uses screen coords (because of (a))
3189 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3191 this->ClientToScreen(event
.GetPosition()));
3192 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3201 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3205 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3209 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3210 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3214 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3216 return eventNotHandledErr
;