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 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
120 // originating from native control
124 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
126 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
131 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
135 // directed towards native control
138 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
140 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
143 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
145 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
154 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
156 #if TARGET_API_MAC_OSX
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
160 kEventControlVisibilityChanged
= 157
166 static const EventTypeSpec eventList
[] =
168 { kEventClassControl
, kEventControlHit
} ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl
, kEventControlDraw
} ,
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
174 { kEventClassControl
, kEventControlSetFocusPart
} ,
176 { kEventClassService
, kEventServiceGetTypes
},
177 { kEventClassService
, kEventServiceCopy
},
178 { kEventClassService
, kEventServicePaste
},
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
216 updateRgn
= allocatedRgn
;
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
224 if ( thisWindow
->MacIsUserPane() )
226 static float color
= 0.5 ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
243 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
246 DisposeRgn( allocatedRgn
) ;
249 case kEventControlVisibilityChanged
:
250 thisWindow
->MacVisibilityChanged() ;
252 case kEventControlEnabledStateChanged
:
253 thisWindow
->MacEnabledStateChanged() ;
255 case kEventControlHiliteChanged
:
256 thisWindow
->MacHiliteChanged() ;
258 case kEventControlSetFocusPart
:
260 Boolean focusEverything
= false ;
261 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
262 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
265 if ( controlPart
== kControlFocusNoPart
)
268 if ( thisWindow
->GetCaret() )
270 thisWindow
->GetCaret()->OnKillFocus();
272 #endif // wxUSE_CARET
273 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
274 event
.SetEventObject(thisWindow
);
275 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
279 // panel wants to track the window which was the last to have focus in it
280 wxChildFocusEvent
eventFocus(thisWindow
);
281 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
284 if ( thisWindow
->GetCaret() )
286 thisWindow
->GetCaret()->OnSetFocus();
288 #endif // wxUSE_CARET
290 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
291 event
.SetEventObject(thisWindow
);
292 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
294 if ( thisWindow
->MacIsUserPane() )
299 case kEventControlHit
:
301 result
= thisWindow
->MacControlHit( handler
, event
) ;
310 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
312 OSStatus result
= eventNotHandledErr
;
314 wxMacCarbonEvent
cEvent( event
) ;
316 ControlRef controlRef
;
317 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
318 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
319 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
321 switch( GetEventKind( event
) )
323 case kEventServiceGetTypes
:
327 textCtrl
->GetSelection( &from
, &to
) ;
329 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
331 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
332 if ( textCtrl
->IsEditable() )
333 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
335 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
336 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
338 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
342 CFArrayAppendValue (copyTypes
, typestring
) ;
344 CFArrayAppendValue (pasteTypes
, typestring
) ;
345 CFRelease( typestring
) ;
351 case kEventServiceCopy
:
355 textCtrl
->GetSelection( &from
, &to
) ;
356 wxString val
= textCtrl
->GetValue() ;
357 val
= val
.Mid( from
, to
- from
) ;
358 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
359 verify_noerr( ClearScrap( &scrapRef
) ) ;
360 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
364 case kEventServicePaste
:
367 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
368 Size textSize
, pastedSize
;
369 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
371 char *content
= new char[textSize
] ;
372 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
373 content
[textSize
-1] = 0 ;
375 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
377 textCtrl
->WriteText( wxString( content
) ) ;
388 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
390 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
391 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
392 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
393 OSStatus result
= eventNotHandledErr
;
395 switch ( GetEventClass( event
) )
397 case kEventClassControl
:
398 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
400 case kEventClassService
:
401 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
405 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
409 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
411 // ---------------------------------------------------------------------------
412 // UserPane events for non OSX builds
413 // ---------------------------------------------------------------------------
415 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
417 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
418 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
419 win
->MacControlUserPaneDrawProc(part
) ;
422 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
424 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
425 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
426 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
429 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
431 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
432 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
433 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
436 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
438 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
439 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
440 win
->MacControlUserPaneIdleProc() ;
443 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
445 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
446 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
447 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
450 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
452 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
453 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
454 win
->MacControlUserPaneActivateProc(activating
) ;
457 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
459 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
460 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
461 return win
->MacControlUserPaneFocusProc(action
) ;
464 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
466 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
467 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
468 win
->MacControlUserPaneBackgroundProc(info
) ;
471 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
473 RgnHandle rgn
= NewRgn() ;
475 wxMacWindowStateSaver
sv( this ) ;
476 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
477 MacDoRedraw( rgn
, 0 ) ;
481 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
483 return kControlNoPart
;
486 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
488 return kControlNoPart
;
491 void wxWindowMac::MacControlUserPaneIdleProc()
495 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
497 return kControlNoPart
;
500 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
504 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
506 return kControlNoPart
;
509 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
513 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
514 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
515 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
516 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
517 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
518 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
519 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
520 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
522 // ===========================================================================
524 // ===========================================================================
526 #if KEY_wxList_DEPRECATED
527 wxList
wxWinMacControlList(wxKEY_INTEGER
);
529 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
531 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
534 return (wxControl
*)node
->GetData();
537 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
539 // adding NULL ControlRef is (first) surely a result of an error and
540 // (secondly) breaks native event processing
541 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
543 if ( !wxWinMacControlList
.Find((long)inControl
) )
544 wxWinMacControlList
.Append((long)inControl
, control
);
547 void wxRemoveMacControlAssociation(wxWindow
*control
)
549 wxWinMacControlList
.DeleteObject(control
);
553 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
555 static MacControlMap wxWinMacControlList
;
557 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
559 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
561 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
564 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
566 // adding NULL ControlRef is (first) surely a result of an error and
567 // (secondly) breaks native event processing
568 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
570 wxWinMacControlList
[inControl
] = control
;
573 void wxRemoveMacControlAssociation(wxWindow
*control
)
575 // iterate over all the elements in the class
576 MacControlMap::iterator it
;
577 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
579 if ( it
->second
== control
)
581 wxWinMacControlList
.erase(it
);
586 #endif // deprecated wxList
589 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
591 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
593 // we have to setup the brush in the current port and return noErr
594 // or return an error code so that the control manager walks further up the
595 // hierarchy to find a correct background
597 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
599 OSStatus status
= paramErr
;
602 case kControlMsgApplyTextColor
:
604 case kControlMsgSetUpBackground
:
606 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
610 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
613 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
615 // this clipping is only needed for non HIView
617 RgnHandle clip
= NewRgn() ;
620 wx
->MacWindowToRootWindow( &x
,&y
) ;
621 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
622 OffsetRgn( clip
, x
, y
) ;
629 else if ( wx->MacIsUserPane() )
631 // if we don't have a valid brush for such a control, we have to call the
632 // setup of our parent ourselves
633 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
646 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
647 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
651 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
654 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
659 // ----------------------------------------------------------------------------
660 // constructors and such
661 // ----------------------------------------------------------------------------
663 wxWindowMac::wxWindowMac()
668 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
673 const wxString
& name
)
676 Create(parent
, id
, pos
, size
, style
, name
);
679 void wxWindowMac::Init()
683 #if WXWIN_COMPATIBILITY_2_4
684 m_backgroundTransparent
= FALSE
;
687 // as all windows are created with WS_VISIBLE style...
690 m_hScrollBar
= NULL
;
691 m_vScrollBar
= NULL
;
692 m_macBackgroundBrush
= wxNullBrush
;
694 m_macIsUserPane
= TRUE
;
696 // make sure all proc ptrs are available
698 if ( gControlUserPaneDrawUPP
== NULL
)
700 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
701 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
702 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
703 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
704 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
705 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
706 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
707 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
709 if ( wxMacLiveScrollbarActionUPP
== NULL
)
711 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
714 if ( wxMacSetupControlBackgroundUPP
== NULL
)
716 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
719 // we need a valid font for the encodings
720 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
724 wxWindowMac::~wxWindowMac()
728 m_isBeingDeleted
= TRUE
;
732 // deleting a window while it is shown invalidates the region occupied by border or
734 int outerBorder
= MacGetLeftBorderSize() ;
735 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
738 if ( IsShown() && ( outerBorder
> 0 ) )
740 // as the borders are drawn on the parent we have to properly invalidate all these areas
741 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
745 m_peer
->GetRect( &rect
) ;
746 RectRgn( updateInner
, &rect
) ;
747 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
748 RectRgn( updateOuter
, &rect
) ;
749 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
751 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
752 parent
-= GetParent()->GetClientAreaOrigin() ;
753 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
754 CopyRgn( updateOuter
, updateTotal
) ;
756 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
757 DisposeRgn(updateOuter
) ;
758 DisposeRgn(updateInner
) ;
759 DisposeRgn(updateTotal
) ;
763 #ifndef __WXUNIVERSAL__
764 // VS: make sure there's no wxFrame with last focus set to us:
765 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
767 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
770 if ( frame
->GetLastFocus() == this )
772 frame
->SetLastFocus((wxWindow
*)NULL
);
777 #endif // __WXUNIVERSAL__
779 // destroy children before destroying this window itself
782 // wxRemoveMacControlAssociation( this ) ;
783 // If we delete an item, we should initialize the parent panel,
784 // because it could now be invalid.
785 wxWindow
*parent
= GetParent() ;
788 if (parent
->GetDefaultItem() == (wxButton
*) this)
789 parent
->SetDefaultItem(NULL
);
791 if ( m_peer
&& m_peer
->Ok() )
793 // in case the callback might be called during destruction
794 wxRemoveMacControlAssociation( this) ;
795 // we currently are not using this hook
796 // ::SetControlColorProc( *m_peer , NULL ) ;
800 if ( g_MacLastWindow
== this )
802 g_MacLastWindow
= NULL
;
805 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
808 if ( frame
->GetLastFocus() == this )
809 frame
->SetLastFocus( NULL
) ;
812 // delete our drop target if we've got one
813 #if wxUSE_DRAG_AND_DROP
814 if ( m_dropTarget
!= NULL
)
819 #endif // wxUSE_DRAG_AND_DROP
823 WXWidget
wxWindowMac::GetHandle() const
825 return (WXWidget
) m_peer
->GetControlRef() ;
829 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
831 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
832 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
833 GetEventTypeCount(eventList
), eventList
, this,
834 (EventHandlerRef
*)&m_macControlEventHandler
);
839 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
843 const wxString
& name
)
845 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
847 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
850 m_windowVariant
= parent
->GetWindowVariant() ;
852 if ( m_macIsUserPane
)
854 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
857 | kControlSupportsEmbedding
858 // | kControlSupportsLiveFeedback
859 // | kControlHasSpecialBackground
860 // | kControlSupportsCalcBestRect
861 // | kControlHandlesTracking
862 | kControlSupportsFocus
863 // | kControlWantsActivate
864 // | kControlWantsIdle
867 m_peer
= new wxMacControl() ;
868 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
871 MacPostControlCreate(pos
,size
) ;
872 #if !TARGET_API_MAC_OSX
873 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
874 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
875 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
876 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
877 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
878 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
879 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
880 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
883 #ifndef __WXUNIVERSAL__
884 // Don't give scrollbars to wxControls unless they ask for them
885 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
886 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
888 MacCreateScrollBars( style
) ;
892 wxWindowCreateEvent
event(this);
893 GetEventHandler()->AddPendingEvent(event
);
898 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
900 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
902 m_peer
->SetReference( (long) this ) ;
903 GetParent()->AddChild(this);
905 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
907 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
908 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
909 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
911 // adjust font, controlsize etc
912 DoSetWindowVariant( m_windowVariant
) ;
914 #if !TARGET_API_MAC_OSX
915 // eventually we can fix some clipping issues be reactivating this hook
916 //if ( m_macIsUserPane )
917 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
919 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
921 if (!m_macIsUserPane
)
923 SetInitialBestSize(size
);
926 SetCursor( *wxSTANDARD_CURSOR
) ;
929 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
931 // Don't assert, in case we set the window variant before
932 // the window is created
933 // wxASSERT( m_peer->Ok() ) ;
935 m_windowVariant
= variant
;
937 if (m_peer
== NULL
|| !m_peer
->Ok())
941 ThemeFontID themeFont
= kThemeSystemFont
;
943 // we will get that from the settings later
944 // and make this NORMAL later, but first
945 // we have a few calculations that we must fix
949 case wxWINDOW_VARIANT_NORMAL
:
950 size
= kControlSizeNormal
;
951 themeFont
= kThemeSystemFont
;
953 case wxWINDOW_VARIANT_SMALL
:
954 size
= kControlSizeSmall
;
955 themeFont
= kThemeSmallSystemFont
;
957 case wxWINDOW_VARIANT_MINI
:
958 if (UMAGetSystemVersion() >= 0x1030 )
960 // not always defined in the headers
966 size
= kControlSizeSmall
;
967 themeFont
= kThemeSmallSystemFont
;
970 case wxWINDOW_VARIANT_LARGE
:
971 size
= kControlSizeLarge
;
972 themeFont
= kThemeSystemFont
;
975 wxFAIL_MSG(_T("unexpected window variant"));
978 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
981 font
.MacCreateThemeFont( themeFont
) ;
985 void wxWindowMac::MacUpdateControlFont()
987 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
991 bool wxWindowMac::SetFont(const wxFont
& font
)
993 bool retval
= wxWindowBase::SetFont( font
) ;
995 MacUpdateControlFont() ;
1000 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1002 if ( !wxWindowBase::SetForegroundColour(col
) )
1005 MacUpdateControlFont() ;
1010 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1012 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1016 wxColour
newCol(GetBackgroundColour());
1017 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1019 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1021 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1023 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1027 brush
.SetColour( newCol
) ;
1029 MacSetBackgroundBrush( brush
) ;
1031 MacUpdateControlFont() ;
1036 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1038 m_macBackgroundBrush
= brush
;
1039 m_peer
->SetBackground( brush
) ;
1042 bool wxWindowMac::MacCanFocus() const
1044 // there is currently no way to determine whether the window is running in full keyboard
1045 // access mode, therefore we cannot rely on these features, yet the only other way would be
1046 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1047 // in event handlers...
1048 UInt32 features
= 0 ;
1049 m_peer
->GetFeatures( & features
) ;
1050 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1054 void wxWindowMac::SetFocus()
1056 if ( AcceptsFocus() )
1059 wxWindow
* former
= FindFocus() ;
1060 if ( former
== this )
1063 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1064 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1065 // leave in case of an error
1066 if ( err
== errCouldntSetFocus
)
1069 #if !TARGET_API_MAC_OSX
1070 // emulate carbon events when running under carbonlib where they are not natively available
1073 EventRef evRef
= NULL
;
1074 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1077 wxMacCarbonEvent
cEvent( evRef
) ;
1078 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1079 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1081 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1082 ReleaseEvent(evRef
) ;
1084 // send new focus event
1086 EventRef evRef
= NULL
;
1087 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1090 wxMacCarbonEvent
cEvent( evRef
) ;
1091 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1092 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1094 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1095 ReleaseEvent(evRef
) ;
1102 void wxWindowMac::DoCaptureMouse()
1104 wxTheApp
->s_captureWindow
= this ;
1107 wxWindow
* wxWindowBase::GetCapture()
1109 return wxTheApp
->s_captureWindow
;
1112 void wxWindowMac::DoReleaseMouse()
1114 wxTheApp
->s_captureWindow
= NULL
;
1117 #if wxUSE_DRAG_AND_DROP
1119 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1121 if ( m_dropTarget
!= 0 ) {
1122 delete m_dropTarget
;
1125 m_dropTarget
= pDropTarget
;
1126 if ( m_dropTarget
!= 0 )
1134 // Old style file-manager drag&drop
1135 void wxWindowMac::DragAcceptFiles(bool accept
)
1140 // Returns the size of the native control. In the case of the toplevel window
1141 // this is the content area root control
1143 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1144 int& w
, int& h
) const
1147 m_peer
->GetRect( &bounds
) ;
1152 w
= bounds
.right
- bounds
.left
;
1153 h
= bounds
.bottom
- bounds
.top
;
1156 // From a wx position / size calculate the appropriate size of the native control
1158 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1161 int& w
, int& h
, bool adjustOrigin
) const
1163 // the desired size, minus the border pixels gives the correct size of the control
1167 // todo the default calls may be used as soon as PostCreateControl Is moved here
1168 w
= size
.x
; // WidthDefault( size.x );
1169 h
= size
.y
; // HeightDefault( size.y ) ;
1170 #if !TARGET_API_MAC_OSX
1171 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1174 x
+= MacGetLeftBorderSize() ;
1175 y
+= MacGetTopBorderSize() ;
1176 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1177 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1180 AdjustForParentClientOrigin( x
, y
) ;
1181 #if TARGET_API_MAC_OSX
1182 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1183 if ( ! GetParent()->IsTopLevel() )
1185 x
-= GetParent()->MacGetLeftBorderSize() ;
1186 y
-= GetParent()->MacGetTopBorderSize() ;
1192 // Get window size (not client size)
1193 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1195 // take the size of the control and add the borders that have to be drawn outside
1196 int x1
, y1
, w1
, h1
;
1198 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1200 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1201 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1207 // get the position of the bounds of this window in client coordinates of its parent
1208 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1210 int x1
, y1
, w1
,h1
;
1211 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1212 x1
-= MacGetLeftBorderSize() ;
1213 y1
-= MacGetTopBorderSize() ;
1215 #if !TARGET_API_MAC_OSX
1216 if ( !GetParent()->IsTopLevel() )
1219 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1224 if ( !IsTopLevel() )
1226 wxWindow
*parent
= GetParent();
1229 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1230 x1
+= parent
->MacGetLeftBorderSize() ;
1231 y1
+= parent
->MacGetTopBorderSize() ;
1232 // and now to client coordinates
1233 wxPoint
pt(parent
->GetClientAreaOrigin());
1242 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1244 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1246 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1249 Point localwhere
= {0,0} ;
1251 if(x
) localwhere
.h
= * x
;
1252 if(y
) localwhere
.v
= * y
;
1254 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1255 if(x
) *x
= localwhere
.h
;
1256 if(y
) *y
= localwhere
.v
;
1259 MacRootWindowToWindow( x
, y
) ;
1261 wxPoint origin
= GetClientAreaOrigin() ;
1262 if(x
) *x
-= origin
.x
;
1263 if(y
) *y
-= origin
.y
;
1266 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1268 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1269 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1271 wxPoint origin
= GetClientAreaOrigin() ;
1272 if(x
) *x
+= origin
.x
;
1273 if(y
) *y
+= origin
.y
;
1275 MacWindowToRootWindow( x
, y
) ;
1278 Point localwhere
= { 0,0 };
1279 if(x
) localwhere
.h
= * x
;
1280 if(y
) localwhere
.v
= * y
;
1281 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1282 if(x
) *x
= localwhere
.h
;
1283 if(y
) *y
= localwhere
.v
;
1287 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1289 wxPoint origin
= GetClientAreaOrigin() ;
1290 if(x
) *x
+= origin
.x
;
1291 if(y
) *y
+= origin
.y
;
1293 MacWindowToRootWindow( x
, y
) ;
1296 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1298 MacRootWindowToWindow( x
, y
) ;
1300 wxPoint origin
= GetClientAreaOrigin() ;
1301 if(x
) *x
-= origin
.x
;
1302 if(y
) *y
-= origin
.y
;
1305 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1307 #if TARGET_API_MAC_OSX
1309 if ( x
) pt
.x
= *x
;
1310 if ( y
) pt
.y
= *y
;
1312 if ( !IsTopLevel() )
1314 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1317 pt
.x
-= MacGetLeftBorderSize() ;
1318 pt
.y
-= MacGetTopBorderSize() ;
1319 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1323 if ( x
) *x
= (int) pt
.x
;
1324 if ( y
) *y
= (int) pt
.y
;
1326 if ( !IsTopLevel() )
1329 m_peer
->GetRect( &bounds
) ;
1330 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1331 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1336 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1341 MacWindowToRootWindow( &x1
, &y1
) ;
1346 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1348 #if TARGET_API_MAC_OSX
1350 if ( x
) pt
.x
= *x
;
1351 if ( y
) pt
.y
= *y
;
1353 if ( !IsTopLevel() )
1355 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1356 pt
.x
+= MacGetLeftBorderSize() ;
1357 pt
.y
+= MacGetTopBorderSize() ;
1360 if ( x
) *x
= (int) pt
.x
;
1361 if ( y
) *y
= (int) pt
.y
;
1363 if ( !IsTopLevel() )
1366 m_peer
->GetRect( &bounds
) ;
1367 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1368 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1373 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1378 MacRootWindowToWindow( &x1
, &y1
) ;
1383 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1385 RgnHandle rgn
= NewRgn() ;
1387 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1389 GetRegionBounds( rgn
, &content
) ;
1394 m_peer
->GetRect( &content
) ;
1397 m_peer
->GetRect( &structure
) ;
1398 #if !TARGET_API_MAC_OSX
1399 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1401 left
= content
.left
- structure
.left
;
1402 top
= content
.top
- structure
.top
;
1403 right
= structure
.right
- content
.right
;
1404 bottom
= structure
.bottom
- content
.bottom
;
1407 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1409 wxSize sizeTotal
= size
;
1411 RgnHandle rgn
= NewRgn() ;
1415 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1417 GetRegionBounds( rgn
, &content
) ;
1422 m_peer
->GetRect( &content
) ;
1425 m_peer
->GetRect( &structure
) ;
1426 #if !TARGET_API_MAC_OSX
1427 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1430 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1431 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1433 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1434 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1440 // Get size *available for subwindows* i.e. excluding menu bar etc.
1441 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1445 RgnHandle rgn
= NewRgn() ;
1447 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1449 GetRegionBounds( rgn
, &content
) ;
1454 m_peer
->GetRect( &content
) ;
1456 #if !TARGET_API_MAC_OSX
1458 m_peer
->GetRect( &structure
) ;
1459 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1461 ww
= content
.right
- content
.left
;
1462 hh
= content
.bottom
- content
.top
;
1464 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1465 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1468 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1474 GetSize( &w , &h ) ;
1476 MacClientToRootWindow( &x1 , &y1 ) ;
1477 MacClientToRootWindow( &w , &h ) ;
1479 wxWindowMac *iter = (wxWindowMac*)this ;
1481 int totW = 10000 , totH = 10000;
1484 if ( iter->IsTopLevel() )
1486 iter->GetSize( &totW , &totH ) ;
1490 iter = iter->GetParent() ;
1493 if (m_hScrollBar && m_hScrollBar->IsShown() )
1495 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1501 if (m_vScrollBar && m_vScrollBar->IsShown() )
1503 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1511 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1513 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1515 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1517 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1524 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1526 if (m_cursor
== cursor
)
1529 if (wxNullCursor
== cursor
)
1531 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1536 if ( ! wxWindowBase::SetCursor( cursor
) )
1540 wxASSERT_MSG( m_cursor
.Ok(),
1541 wxT("cursor must be valid after call to the base version"));
1544 wxWindowMac
*mouseWin
= 0 ;
1546 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1548 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1550 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1551 // position, use it...
1555 ControlPartCode part
;
1556 ControlRef control
;
1557 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1559 mouseWin
= wxFindControlFromMacControl( control
) ;
1562 QDSwapPort( savePort
, NULL
) ;
1565 if ( mouseWin
== this && !wxIsBusy() )
1567 m_cursor
.MacInstall() ;
1574 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1576 menu
->SetInvokingWindow(this);
1579 if ( x
== -1 && y
== -1 )
1581 wxPoint mouse
= wxGetMousePosition();
1582 x
= mouse
.x
; y
= mouse
.y
;
1586 ClientToScreen( &x
, &y
) ;
1589 menu
->MacBeforeDisplay( true ) ;
1590 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1591 if ( HiWord(menuResult
) != 0 )
1594 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1595 wxMenuItem
* item
= NULL
;
1597 item
= menu
->FindItem(id
, &realmenu
) ;
1598 if (item
->IsCheckable())
1600 item
->Check( !item
->IsChecked() ) ;
1602 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1604 menu
->MacAfterDisplay( true ) ;
1606 menu
->SetInvokingWindow(NULL
);
1612 // ----------------------------------------------------------------------------
1614 // ----------------------------------------------------------------------------
1618 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1620 wxWindowBase::DoSetToolTip(tooltip
);
1623 m_tooltip
->SetWindow(this);
1626 #endif // wxUSE_TOOLTIPS
1628 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1630 // this is never called for a toplevel window, so we know we have a parent
1631 int former_x
, former_y
, former_w
, former_h
;
1633 // Get true coordinates of former position
1634 DoGetPosition( &former_x
, &former_y
) ;
1635 DoGetSize( &former_w
, &former_h
) ;
1637 wxWindow
*parent
= GetParent();
1640 wxPoint
pt(parent
->GetClientAreaOrigin());
1645 int actualWidth
= width
;
1646 int actualHeight
= height
;
1650 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1651 actualWidth
= m_minWidth
;
1652 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1653 actualHeight
= m_minHeight
;
1654 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1655 actualWidth
= m_maxWidth
;
1656 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1657 actualHeight
= m_maxHeight
;
1659 bool doMove
= false ;
1660 bool doResize
= false ;
1662 if ( actualX
!= former_x
|| actualY
!= former_y
)
1666 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1671 if ( doMove
|| doResize
)
1673 // we don't adjust twice for the origin
1674 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1675 bool vis
= m_peer
->IsVisible();
1677 int outerBorder
= MacGetLeftBorderSize() ;
1678 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1681 if ( vis
&& ( outerBorder
> 0 ) )
1683 // as the borders are drawn on the parent we have to properly invalidate all these areas
1684 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1688 m_peer
->GetRect( &rect
) ;
1689 RectRgn( updateInner
, &rect
) ;
1690 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1691 RectRgn( updateOuter
, &rect
) ;
1692 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1693 wxPoint
parent(0,0);
1694 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1695 parent
-= GetParent()->GetClientAreaOrigin() ;
1696 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1697 CopyRgn( updateOuter
, updateTotal
) ;
1700 RectRgn( updateInner
, &rect
) ;
1701 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1702 RectRgn( updateOuter
, &rect
) ;
1703 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1705 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1706 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1708 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1709 DisposeRgn(updateOuter
) ;
1710 DisposeRgn(updateInner
) ;
1711 DisposeRgn(updateTotal
) ;
1714 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1716 m_peer
->SetVisibility( false , true ) ;
1718 m_peer
->SetRect( &r
) ;
1720 m_peer
->SetVisibility( true , true ) ;
1722 MacRepositionScrollBars() ;
1725 wxPoint
point(actualX
,actualY
);
1726 wxMoveEvent
event(point
, m_windowId
);
1727 event
.SetEventObject(this);
1728 GetEventHandler()->ProcessEvent(event
) ;
1732 MacRepositionScrollBars() ;
1733 wxSize
size(actualWidth
, actualHeight
);
1734 wxSizeEvent
event(size
, m_windowId
);
1735 event
.SetEventObject(this);
1736 GetEventHandler()->ProcessEvent(event
);
1742 wxSize
wxWindowMac::DoGetBestSize() const
1744 if ( m_macIsUserPane
|| IsTopLevel() )
1745 return wxWindowBase::DoGetBestSize() ;
1747 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1748 int bestWidth
, bestHeight
;
1749 m_peer
->GetBestRect( &bestsize
) ;
1751 if ( EmptyRect( &bestsize
) )
1753 bestsize
.left
= bestsize
.top
= 0 ;
1754 bestsize
.right
= 16 ;
1755 bestsize
.bottom
= 16 ;
1756 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1758 bestsize
.bottom
= 16 ;
1761 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1763 bestsize
.bottom
= 24 ;
1765 #endif // wxUSE_SPINBTN
1768 // return wxWindowBase::DoGetBestSize() ;
1772 bestWidth
= bestsize
.right
- bestsize
.left
;
1773 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1774 if ( bestHeight
< 10 )
1777 return wxSize(bestWidth
, bestHeight
);
1781 // set the size of the window: if the dimensions are positive, just use them,
1782 // but if any of them is equal to -1, it means that we must find the value for
1783 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1784 // which case -1 is a valid value for x and y)
1786 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1787 // the width/height to best suit our contents, otherwise we reuse the current
1789 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1791 // get the current size and position...
1792 int currentX
, currentY
;
1793 GetPosition(¤tX
, ¤tY
);
1795 int currentW
,currentH
;
1796 GetSize(¤tW
, ¤tH
);
1798 // ... and don't do anything (avoiding flicker) if it's already ok
1799 if ( x
== currentX
&& y
== currentY
&&
1800 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1803 MacRepositionScrollBars() ; // we might have a real position shift
1807 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1809 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1812 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1814 wxSize
size(-1, -1);
1817 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1819 size
= DoGetBestSize();
1824 // just take the current one
1831 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1835 size
= DoGetBestSize();
1837 //else: already called DoGetBestSize() above
1843 // just take the current one
1848 DoMoveWindow(x
, y
, width
, height
);
1852 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1854 RgnHandle rgn
= NewRgn() ;
1856 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1857 GetRegionBounds( rgn
, &content
) ;
1859 #if !TARGET_API_MAC_OSX
1860 // if the content rgn is empty / not supported
1861 // don't attempt to correct the coordinates to wxWindow relative ones
1862 if (!::EmptyRect( &content
) )
1865 m_peer
->GetRect( &structure
) ;
1866 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1870 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1873 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1875 if ( clientheight
!= -1 || clientheight
!= -1 )
1877 int currentclientwidth
, currentclientheight
;
1878 int currentwidth
, currentheight
;
1880 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1881 GetSize( ¤twidth
, ¤theight
) ;
1883 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1884 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1888 void wxWindowMac::SetTitle(const wxString
& title
)
1890 m_label
= wxStripMenuCodes(title
) ;
1892 if ( m_peer
&& m_peer
->Ok() )
1894 m_peer
->SetTitle( m_label
) ;
1899 wxString
wxWindowMac::GetTitle() const
1904 bool wxWindowMac::Show(bool show
)
1906 if ( !wxWindowBase::Show(show
) )
1909 // TODO use visibilityChanged Carbon Event for OSX
1912 bool former
= MacIsReallyShown() ;
1914 m_peer
->SetVisibility( show
, true ) ;
1915 if ( former
!= MacIsReallyShown() )
1916 MacPropagateVisibilityChanged() ;
1921 bool wxWindowMac::Enable(bool enable
)
1923 wxASSERT( m_peer
->Ok() ) ;
1924 if ( !wxWindowBase::Enable(enable
) )
1927 bool former
= MacIsReallyEnabled() ;
1928 m_peer
->Enable( enable
) ;
1930 if ( former
!= MacIsReallyEnabled() )
1931 MacPropagateEnabledStateChanged() ;
1936 // status change propagations (will be not necessary for OSX later )
1939 void wxWindowMac::MacPropagateVisibilityChanged()
1941 #if !TARGET_API_MAC_OSX
1942 MacVisibilityChanged() ;
1944 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1947 wxWindowMac
*child
= node
->GetData();
1948 if ( child
->IsShown() )
1949 child
->MacPropagateVisibilityChanged( ) ;
1950 node
= node
->GetNext();
1955 void wxWindowMac::MacPropagateEnabledStateChanged( )
1957 #if !TARGET_API_MAC_OSX
1958 MacEnabledStateChanged() ;
1960 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1963 wxWindowMac
*child
= node
->GetData();
1964 if ( child
->IsEnabled() )
1965 child
->MacPropagateEnabledStateChanged() ;
1966 node
= node
->GetNext();
1971 void wxWindowMac::MacPropagateHiliteChanged( )
1973 #if !TARGET_API_MAC_OSX
1974 MacHiliteChanged() ;
1976 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1979 wxWindowMac
*child
= node
->GetData();
1980 // if ( child->IsEnabled() )
1981 child
->MacPropagateHiliteChanged() ;
1982 node
= node
->GetNext();
1988 // status change notifications
1991 void wxWindowMac::MacVisibilityChanged()
1995 void wxWindowMac::MacHiliteChanged()
1999 void wxWindowMac::MacEnabledStateChanged()
2004 // status queries on the inherited window's state
2007 bool wxWindowMac::MacIsReallyShown()
2009 // only under OSX the visibility of the TLW is taken into account
2010 #if TARGET_API_MAC_OSX
2011 if ( m_peer
&& m_peer
->Ok() )
2012 return m_peer
->IsVisible();
2014 wxWindow
* win
= this ;
2015 while( win
->IsShown() )
2017 if ( win
->IsTopLevel() )
2020 win
= win
->GetParent() ;
2028 bool wxWindowMac::MacIsReallyEnabled()
2030 return m_peer
->IsEnabled() ;
2033 bool wxWindowMac::MacIsReallyHilited()
2035 return m_peer
->IsActive();
2038 void wxWindowMac::MacFlashInvalidAreas()
2040 #if TARGET_API_MAC_OSX
2041 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2049 int wxWindowMac::GetCharHeight() const
2051 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2052 return dc
.GetCharHeight() ;
2055 int wxWindowMac::GetCharWidth() const
2057 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2058 return dc
.GetCharWidth() ;
2061 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2062 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2064 const wxFont
*fontToUse
= theFont
;
2066 fontToUse
= &m_font
;
2068 wxClientDC
dc( (wxWindowMac
*) this ) ;
2070 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2071 if ( externalLeading
)
2072 *externalLeading
= le
;
2082 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2083 * we always intersect with the entire window, not only with the client area
2086 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2088 if ( m_peer
== NULL
)
2091 #if TARGET_API_MAC_OSX
2093 m_peer
->SetNeedsDisplay( true ) ;
2096 RgnHandle update
= NewRgn() ;
2097 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2098 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2099 wxPoint origin
= GetClientAreaOrigin() ;
2100 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2101 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2103 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2104 m_peer
->SetNeedsDisplay( true , update
) ;
2105 DisposeRgn( update
) ;
2109 RgnHandle updateRgn = NewRgn() ;
2112 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2116 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2117 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2119 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2120 DisposeRgn(updateRgn) ;
2122 if ( m_peer
->IsVisible())
2124 m_peer
->SetVisibility( false , false ) ;
2125 m_peer
->SetVisibility( true , true ) ;
2128 if ( MacGetTopLevelWindow() == NULL )
2131 if ( !m_peer->IsVisible())
2134 wxPoint client = GetClientAreaOrigin();
2137 int x2 = m_width - client.x;
2138 int y2 = m_height - client.y;
2140 if (IsKindOf( CLASSINFO(wxButton)))
2142 // buttons have an "aura"
2149 Rect clientrect = { y1, x1, y2, x2 };
2153 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2154 SectRect( &clientrect , &r , &clientrect ) ;
2157 if ( !EmptyRect( &clientrect ) )
2159 int top = 0 , left = 0 ;
2161 MacClientToRootWindow( &left , &top ) ;
2162 OffsetRect( &clientrect , left , top ) ;
2164 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2170 void wxWindowMac::Freeze()
2172 #if TARGET_API_MAC_OSX
2173 if ( !m_frozenness
++ )
2175 if ( m_peer
&& m_peer
->Ok() )
2176 m_peer
->SetDrawingEnabled( false ) ;
2182 void wxWindowMac::Thaw()
2184 #if TARGET_API_MAC_OSX
2185 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2187 if ( !--m_frozenness
)
2189 if ( m_peer
&& m_peer
->Ok() )
2191 m_peer
->SetDrawingEnabled( true ) ;
2192 m_peer
->InvalidateWithChildren() ;
2198 void wxWindowMac::MacRedrawControl()
2201 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2203 #if TARGET_API_MAC_CARBON
2206 wxClientDC dc(this) ;
2207 wxMacPortSetter helper(&dc) ;
2208 wxMacWindowClipper clipper(this) ;
2209 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2210 UMADrawControl( *m_peer ) ;
2217 void wxWindowMac::OnPaint(wxPaintEvent& event)
2219 // why don't we skip that here ?
2223 wxWindowMac
*wxGetActiveWindow()
2225 // actually this is a windows-only concept
2229 // Coordinates relative to the window
2230 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2232 // We really don't move the mouse programmatically under Mac.
2235 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2237 #if TARGET_API_MAC_OSX
2238 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2245 event
.GetDC()->Clear() ;
2249 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2254 int wxWindowMac::GetScrollPos(int orient
) const
2256 if ( orient
== wxHORIZONTAL
)
2259 return m_hScrollBar
->GetThumbPosition() ;
2264 return m_vScrollBar
->GetThumbPosition() ;
2269 // This now returns the whole range, not just the number
2270 // of positions that we can scroll.
2271 int wxWindowMac::GetScrollRange(int orient
) const
2273 if ( orient
== wxHORIZONTAL
)
2276 return m_hScrollBar
->GetRange() ;
2281 return m_vScrollBar
->GetRange() ;
2286 int wxWindowMac::GetScrollThumb(int orient
) const
2288 if ( orient
== wxHORIZONTAL
)
2291 return m_hScrollBar
->GetThumbSize() ;
2296 return m_vScrollBar
->GetThumbSize() ;
2301 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2303 if ( orient
== wxHORIZONTAL
)
2306 m_hScrollBar
->SetThumbPosition( pos
) ;
2311 m_vScrollBar
->SetThumbPosition( pos
) ;
2315 void wxWindowMac::MacPaintBorders( int left
, int top
)
2321 m_peer
->GetRect( &rect
) ;
2322 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2324 if ( !IsTopLevel() )
2326 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2330 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2332 rect
.right
+= pt
.x
;
2334 rect
.bottom
+= pt
.y
;
2338 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2342 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2343 InsetRect( &srect
, border
, border
);
2344 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2346 else if (HasFlag(wxSIMPLE_BORDER
))
2350 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2351 InsetRect( &srect
, border
, border
);
2352 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2356 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2358 if ( child
== m_hScrollBar
)
2359 m_hScrollBar
= NULL
;
2360 if ( child
== m_vScrollBar
)
2361 m_vScrollBar
= NULL
;
2363 wxWindowBase::RemoveChild( child
) ;
2366 // New function that will replace some of the above.
2367 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2368 int range
, bool refresh
)
2370 if ( orient
== wxHORIZONTAL
)
2374 if ( range
== 0 || thumbVisible
>= range
)
2376 if ( m_hScrollBar
->IsShown() )
2377 m_hScrollBar
->Show(false) ;
2381 if ( !m_hScrollBar
->IsShown() )
2382 m_hScrollBar
->Show(true) ;
2383 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2391 if ( range
== 0 || thumbVisible
>= range
)
2393 if ( m_vScrollBar
->IsShown() )
2394 m_vScrollBar
->Show(false) ;
2398 if ( !m_vScrollBar
->IsShown() )
2399 m_vScrollBar
->Show(true) ;
2400 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2404 MacRepositionScrollBars() ;
2407 // Does a physical scroll
2408 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2410 if( dx
== 0 && dy
==0 )
2416 int width
, height
;
2417 GetClientSize( &width
, &height
) ;
2418 #if TARGET_API_MAC_OSX
2419 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2420 // area is scrolled, this does not occur if width and height are 2 pixels less,
2421 // TODO write optimal workaround
2422 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2425 scrollrect
.Intersect( *rect
) ;
2427 if ( m_peer
->GetNeedsDisplay() )
2429 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2430 // either immediate redraw or full invalidate
2432 // is the better overall solution, as it does not slow down scrolling
2433 m_peer
->SetNeedsDisplay( true ) ;
2435 // this would be the preferred version for fast drawing controls
2436 if( UMAGetSystemVersion() < 0x1030 )
2439 HIViewRender(m_peer
->GetControlRef()) ;
2442 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2443 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2444 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2451 RgnHandle updateRgn
= NewRgn() ;
2454 wxClientDC
dc(this) ;
2455 wxMacPortSetter
helper(&dc
) ;
2457 m_peer
->GetRect( &scrollrect
) ;
2458 scrollrect
.top
+= MacGetTopBorderSize() ;
2459 scrollrect
.left
+= MacGetLeftBorderSize() ;
2460 scrollrect
.bottom
= scrollrect
.top
+ height
;
2461 scrollrect
.right
= scrollrect
.left
+ width
;
2465 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2466 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2467 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2469 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2471 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2475 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2477 wxWindowMac
*child
= node
->GetData();
2478 if (child
== m_vScrollBar
) continue;
2479 if (child
== m_hScrollBar
) continue;
2480 if (child
->IsTopLevel()) continue;
2483 child
->GetPosition( &x
, &y
);
2485 child
->GetSize( &w
, &h
);
2489 if (rect
->Intersects(rc
))
2490 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2494 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2499 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2501 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2503 wxScrollWinEvent wevent
;
2504 wevent
.SetPosition(event
.GetPosition());
2505 wevent
.SetOrientation(event
.GetOrientation());
2506 wevent
.m_eventObject
= this;
2508 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2509 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2510 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2511 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2512 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2513 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2514 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2515 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2516 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2517 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2518 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2519 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2520 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2521 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2522 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2523 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2525 GetEventHandler()->ProcessEvent(wevent
);
2529 // Get the window with the focus
2530 wxWindowMac
*wxWindowBase::DoFindFocus()
2532 ControlRef control
;
2533 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2534 return wxFindControlFromMacControl( control
) ;
2537 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2539 // panel wants to track the window which was the last to have focus in it,
2540 // so we want to set ourselves as the window which last had focus
2542 // notice that it's also important to do it upwards the tree becaus
2543 // otherwise when the top level panel gets focus, it won't set it back to
2544 // us, but to some other sibling
2546 // CS:don't know if this is still needed:
2547 //wxChildFocusEvent eventFocus(this);
2548 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2550 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2552 wxMacWindowStateSaver
sv( this ) ;
2557 MacWindowToRootWindow( &x
, &y
) ;
2558 GetSize( &w
, &h
) ;
2559 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2561 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2562 DrawThemeFocusRect( &rect
, true ) ;
2565 DrawThemeFocusRect( &rect
, false ) ;
2567 // as this erases part of the frame we have to redraw borders
2568 // and because our z-ordering is not always correct (staticboxes)
2569 // we have to invalidate things, we cannot simple redraw
2570 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2571 RectRgn( updateInner
, &rect
) ;
2572 InsetRect( &rect
, -4 , -4 ) ;
2573 RectRgn( updateOuter
, &rect
) ;
2574 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2575 wxPoint
parent(0,0);
2576 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2577 parent
-= GetParent()->GetClientAreaOrigin() ;
2578 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2579 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2580 DisposeRgn(updateOuter
) ;
2581 DisposeRgn(updateInner
) ;
2588 void wxWindowMac::OnInternalIdle()
2590 // This calls the UI-update mechanism (querying windows for
2591 // menu/toolbar/control state information)
2592 if (wxUpdateUIEvent::CanUpdate(this))
2593 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2596 // Raise the window to the top of the Z order
2597 void wxWindowMac::Raise()
2599 m_peer
->SetZOrder( true , NULL
) ;
2602 // Lower the window to the bottom of the Z order
2603 void wxWindowMac::Lower()
2605 m_peer
->SetZOrder( false , NULL
) ;
2609 // static wxWindow *gs_lastWhich = NULL;
2611 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2613 // first trigger a set cursor event
2615 wxPoint clientorigin
= GetClientAreaOrigin() ;
2616 wxSize clientsize
= GetClientSize() ;
2618 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2620 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2622 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2623 if ( processedEvtSetCursor
&& event
.HasCursor() )
2625 cursor
= event
.GetCursor() ;
2630 // the test for processedEvtSetCursor is here to prevent using m_cursor
2631 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2632 // it - this is a way to say that our cursor shouldn't be used for this
2634 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2644 cursor
= *wxSTANDARD_CURSOR
;
2648 cursor
.MacInstall() ;
2650 return cursor
.Ok() ;
2653 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2657 return m_tooltip
->GetTip() ;
2659 return wxEmptyString
;
2662 void wxWindowMac::Update()
2664 #if TARGET_API_MAC_OSX
2666 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2667 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2669 // for composited windows this also triggers a redraw of all
2670 // invalid views in the window
2671 if( UMAGetSystemVersion() >= 0x1030 )
2672 HIWindowFlush(window
) ;
2676 // the only way to trigger the redrawing on earlier systems is to call
2679 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2680 UInt32 currentEventClass
= 0 ;
2681 UInt32 currentEventKind
= 0 ;
2682 if ( currentEvent
!= NULL
)
2684 currentEventClass
= ::GetEventClass( currentEvent
) ;
2685 currentEventKind
= ::GetEventKind( currentEvent
) ;
2687 if ( currentEventClass
!= kEventClassMenu
)
2689 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2692 OSStatus status
= noErr
;
2693 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2696 m_peer
->SetNeedsDisplay( true ) ;
2699 ::Draw1Control( m_peer
->GetControlRef() ) ;
2703 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2705 wxTopLevelWindowMac
* win
= NULL
;
2706 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2709 win
= wxFindWinFromMacWindow( window
) ;
2713 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2715 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2716 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2717 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2718 // to add focus borders everywhere
2721 RgnHandle visRgn
= NewRgn() ;
2722 RgnHandle tempRgn
= NewRgn() ;
2723 if ( m_peer
->IsVisible())
2725 m_peer
->GetRect( &r
) ;
2726 r
.left
-= MacGetLeftBorderSize() ;
2727 r
.top
-= MacGetTopBorderSize() ;
2728 r
.bottom
+= MacGetBottomBorderSize() ;
2729 r
.right
+= MacGetRightBorderSize() ;
2731 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2733 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2734 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2743 if ( includeOuterStructures
)
2744 InsetRect( &r
, -4 , -4 ) ;
2745 RectRgn( visRgn
, &r
) ;
2747 if ( !IsTopLevel() )
2749 wxWindow
* child
= this ;
2750 wxWindow
* parent
= child
->GetParent() ;
2755 // we have to find a better clipping algorithm here, in order not to clip things
2756 // positioned like status and toolbar
2757 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2759 size
= parent
->GetSize() ;
2764 size
= parent
->GetClientSize() ;
2765 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2769 parent
->MacWindowToRootWindow( &x
, &y
) ;
2770 MacRootWindowToWindow( &x
, &y
) ;
2772 if ( !includeOuterStructures
|| (
2773 parent
->MacClipChildren() ||
2774 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2777 SetRectRgn( tempRgn
,
2778 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2779 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2780 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2782 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2784 if ( parent
->IsTopLevel() )
2787 parent
= child
->GetParent() ;
2792 wxRegion vis
= visRgn
;
2793 DisposeRgn( visRgn
) ;
2794 DisposeRgn( tempRgn
) ;
2799 This function must not change the updatergn !
2801 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2803 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2804 bool handled
= false ;
2806 GetRegionBounds( updatergn
, &updatebounds
) ;
2807 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2808 if ( !EmptyRgn(updatergn
) )
2810 RgnHandle newupdate
= NewRgn() ;
2811 wxSize point
= GetClientSize() ;
2812 wxPoint origin
= GetClientAreaOrigin() ;
2813 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2814 SectRgn( newupdate
, updatergn
, newupdate
) ;
2816 // first send an erase event to the entire update area
2818 wxWindowDC
dc(this);
2819 dc
.SetClippingRegion(wxRegion(updatergn
));
2820 wxEraseEvent
eevent( GetId(), &dc
);
2821 eevent
.SetEventObject( this );
2822 GetEventHandler()->ProcessEvent( eevent
);
2825 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2826 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2827 m_updateRegion
= newupdate
;
2828 DisposeRgn( newupdate
) ;
2830 if ( !m_updateRegion
.Empty() )
2832 // paint the window itself
2834 event
.m_timeStamp
= time
;
2835 event
.SetEventObject(this);
2836 handled
= GetEventHandler()->ProcessEvent(event
);
2838 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2841 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2843 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2850 // now we cannot rely on having its borders drawn by a window itself, as it does not
2851 // get the updateRgn wide enough to always do so, so we do it from the parent
2852 // this would also be the place to draw any custom backgrounds for native controls
2853 // in Composited windowing
2854 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2856 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2858 wxWindowMac
*child
= node
->GetData();
2859 if (child
== m_vScrollBar
) continue;
2860 if (child
== m_hScrollBar
) continue;
2861 if (child
->IsTopLevel()) continue;
2862 if (!child
->IsShown()) continue;
2865 child
->GetPosition( &x
, &y
);
2867 child
->GetSize( &w
, &h
);
2868 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2869 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2870 if ( child
->MacGetTopBorderSize() )
2872 if ( RectInRgn( &childRect
, updatergn
) )
2874 // paint custom borders
2875 wxNcPaintEvent
eventNc( child
->GetId() );
2876 eventNc
.SetEventObject( child
);
2877 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2879 wxWindowDC
dc(this) ;
2880 dc
.SetClippingRegion(wxRegion(updatergn
));
2881 wxMacPortSetter
helper(&dc
) ;
2882 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2886 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2888 wxWindowDC
dc(this) ;
2889 dc
.SetClippingRegion(wxRegion(updatergn
));
2890 wxMacPortSetter
helper(&dc
) ;
2891 Rect r
= childRect
;
2892 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2893 DrawThemeFocusRect( &r
, true ) ;
2900 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2902 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2903 // updatergn is always already clipped to our boundaries
2904 // if we are in compositing mode then it is in relative to the upper left of the control
2905 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2906 // of the toplevel window
2907 // it is in window coordinates, not in client coordinates
2909 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2910 RgnHandle ownUpdateRgn
= NewRgn() ;
2911 CopyRgn( updatergn
, ownUpdateRgn
) ;
2913 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2916 m_peer
->GetRectInWindowCoords( &bounds
);
2917 RgnHandle controlRgn
= NewRgn();
2918 RectRgn( controlRgn
, &bounds
);
2919 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2920 // the window update region
2921 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2922 DisposeRgn( controlRgn
);
2924 //KO: convert ownUpdateRgn to local coordinates
2925 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2928 MacDoRedraw( ownUpdateRgn
, time
) ;
2929 DisposeRgn( ownUpdateRgn
) ;
2933 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2935 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2939 if ( iter
->IsTopLevel() )
2940 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2942 iter
= iter
->GetParent() ;
2944 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2948 void wxWindowMac::MacCreateScrollBars( long style
)
2950 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2952 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2954 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2955 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2956 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2957 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2959 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2960 variant
= wxWINDOW_VARIANT_SMALL
;
2963 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2965 GetClientSize( &width
, &height
) ;
2967 wxPoint
vPoint(width
-scrlsize
, 0) ;
2968 wxSize
vSize(scrlsize
, height
- adjust
) ;
2969 wxPoint
hPoint(0 , height
-scrlsize
) ;
2970 wxSize
hSize( width
- adjust
, scrlsize
) ;
2973 if ( style
& wxVSCROLL
)
2975 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2976 vSize
, wxVERTICAL
);
2979 if ( style
& wxHSCROLL
)
2981 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2982 hSize
, wxHORIZONTAL
);
2987 // because the create does not take into account the client area origin
2988 MacRepositionScrollBars() ; // we might have a real position shift
2991 void wxWindowMac::MacRepositionScrollBars()
2993 if ( !m_hScrollBar
&& !m_vScrollBar
)
2996 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2997 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2998 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3000 // get real client area
3004 GetSize( &width
, &height
) ;
3006 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3007 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3009 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3010 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3011 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3012 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3018 GetSize( &w , &h ) ;
3020 MacClientToRootWindow( &x , &y ) ;
3021 MacClientToRootWindow( &w , &h ) ;
3023 wxWindowMac *iter = (wxWindowMac*)this ;
3025 int totW = 10000 , totH = 10000;
3028 if ( iter->IsTopLevel() )
3030 iter->GetSize( &totW , &totH ) ;
3034 iter = iter->GetParent() ;
3062 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3066 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3070 bool wxWindowMac::AcceptsFocus() const
3072 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3075 void wxWindowMac::MacSuperChangedPosition()
3077 // only window-absolute structures have to be moved i.e. controls
3079 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3082 wxWindowMac
*child
= node
->GetData();
3083 child
->MacSuperChangedPosition() ;
3084 node
= node
->GetNext();
3088 void wxWindowMac::MacTopLevelWindowChangedPosition()
3090 // only screen-absolute structures have to be moved i.e. glcanvas
3092 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3095 wxWindowMac
*child
= node
->GetData();
3096 child
->MacTopLevelWindowChangedPosition() ;
3097 node
= node
->GetNext();
3101 long wxWindowMac::MacGetLeftBorderSize( ) const
3106 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3111 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3116 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3123 long wxWindowMac::MacGetRightBorderSize( ) const
3125 // they are all symmetric in mac themes
3126 return MacGetLeftBorderSize() ;
3129 long wxWindowMac::MacGetTopBorderSize( ) const
3131 // they are all symmetric in mac themes
3132 return MacGetLeftBorderSize() ;
3135 long wxWindowMac::MacGetBottomBorderSize( ) const
3137 // they are all symmetric in mac themes
3138 return MacGetLeftBorderSize() ;
3141 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3143 return style
& ~wxBORDER_MASK
;
3146 // Find the wxWindowMac at the current mouse position, returning the mouse
3148 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3150 pt
= wxGetMousePosition();
3151 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3155 // Get the current mouse position.
3156 wxPoint
wxGetMousePosition()
3159 wxGetMousePosition(& x
, & y
);
3160 return wxPoint(x
, y
);
3163 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3165 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3167 // copied from wxGTK : CS
3168 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3171 // (a) it's a command event and so is propagated to the parent
3172 // (b) under MSW it can be generated from kbd too
3173 // (c) it uses screen coords (because of (a))
3174 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3176 this->ClientToScreen(event
.GetPosition()));
3177 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3186 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3190 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3194 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3195 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3199 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3201 return eventNotHandledErr
;