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 #if TARGET_API_MAC_OSX
85 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() ;
205 if ( thisWindow
->GetPeer()->IsCompositing() == false )
207 if ( thisWindow
->GetPeer()->IsRootControl() == false )
209 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
213 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
217 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
219 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
223 if ( thisWindow
->GetPeer()->IsCompositing() == false )
225 if ( thisWindow
->GetPeer()->IsRootControl() == false )
227 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
231 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
233 allocatedRgn
= NewRgn() ;
234 CopyRgn( updateRgn
, allocatedRgn
) ;
235 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
236 // hide the given region by the new region that must be shifted
237 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
238 updateRgn
= allocatedRgn
;
242 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
244 // as this update region is in native window locals we must adapt it to wx window local
245 allocatedRgn
= NewRgn() ;
246 CopyRgn( updateRgn
, allocatedRgn
) ;
247 // hide the given region by the new region that must be shifted
248 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
249 updateRgn
= allocatedRgn
;
254 GetRegionBounds( updateRgn
, &rgnBounds
) ;
255 #if wxMAC_DEBUG_REDRAW
256 if ( thisWindow
->MacIsUserPane() )
258 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
259 static float color
= 0.5 ;
262 HIViewGetBounds( controlRef
, &bounds
);
263 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
264 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
265 CGContextFillRect( cgContext
, bounds
);
277 #if wxMAC_USE_CORE_GRAPHICS
278 bool created
= false ;
279 CGContextRef cgContext
= 0 ;
280 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
282 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
284 // this parameter is not provided on non-composited windows
286 // rest of the code expects this to be already transformed and clipped for local
287 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
289 GetPortBounds( port
, &bounds
) ;
290 CreateCGContextForPort( port
, &cgContext
) ;
292 wxMacWindowToNative( thisWindow
, updateRgn
) ;
293 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
294 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
295 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
296 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
298 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
299 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
301 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
304 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
305 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
306 controlBounds.right - controlBounds.left ,
307 controlBounds.bottom - controlBounds.top ) );
311 thisWindow
->MacSetCGContextRef( cgContext
) ;
313 wxMacCGContextStateSaver
sg( cgContext
) ;
315 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
317 #if wxMAC_USE_CORE_GRAPHICS
318 thisWindow
->MacSetCGContextRef( NULL
) ;
322 CGContextRelease( cgContext
) ;
327 DisposeRgn( allocatedRgn
) ;
330 case kEventControlVisibilityChanged
:
331 thisWindow
->MacVisibilityChanged() ;
333 case kEventControlEnabledStateChanged
:
334 thisWindow
->MacEnabledStateChanged() ;
336 case kEventControlHiliteChanged
:
337 thisWindow
->MacHiliteChanged() ;
340 // we emulate this event under Carbon CFM
341 case kEventControlSetFocusPart
:
343 Boolean focusEverything
= false ;
344 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
346 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
350 if ( controlPart
== kControlFocusNoPart
)
353 if ( thisWindow
->GetCaret() )
355 thisWindow
->GetCaret()->OnKillFocus();
357 #endif // wxUSE_CARET
358 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
359 event
.SetEventObject(thisWindow
);
360 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
364 // panel wants to track the window which was the last to have focus in it
365 wxChildFocusEvent
eventFocus(thisWindow
);
366 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
369 if ( thisWindow
->GetCaret() )
371 thisWindow
->GetCaret()->OnSetFocus();
373 #endif // wxUSE_CARET
375 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
376 event
.SetEventObject(thisWindow
);
377 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
379 if ( thisWindow
->MacIsUserPane() )
383 case kEventControlHit
:
385 result
= thisWindow
->MacControlHit( handler
, event
) ;
394 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
396 OSStatus result
= eventNotHandledErr
;
398 wxMacCarbonEvent
cEvent( event
) ;
400 ControlRef controlRef
;
401 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
402 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
403 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
405 switch( GetEventKind( event
) )
407 case kEventServiceGetTypes
:
411 textCtrl
->GetSelection( &from
, &to
) ;
413 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
415 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
416 if ( textCtrl
->IsEditable() )
417 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
419 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
420 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
422 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
426 CFArrayAppendValue (copyTypes
, typestring
) ;
428 CFArrayAppendValue (pasteTypes
, typestring
) ;
429 CFRelease( typestring
) ;
435 case kEventServiceCopy
:
439 textCtrl
->GetSelection( &from
, &to
) ;
440 wxString val
= textCtrl
->GetValue() ;
441 val
= val
.Mid( from
, to
- from
) ;
442 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
443 verify_noerr( ClearScrap( &scrapRef
) ) ;
444 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
448 case kEventServicePaste
:
451 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
452 Size textSize
, pastedSize
;
453 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
455 char *content
= new char[textSize
] ;
456 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
457 content
[textSize
-1] = 0 ;
459 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
461 textCtrl
->WriteText( wxString( content
) ) ;
472 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
474 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
475 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
476 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
477 OSStatus result
= eventNotHandledErr
;
479 switch ( GetEventClass( event
) )
481 case kEventClassControl
:
482 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
484 case kEventClassService
:
485 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
489 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
493 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
495 #if !TARGET_API_MAC_OSX
497 // ---------------------------------------------------------------------------
498 // UserPane events for non OSX builds
499 // ---------------------------------------------------------------------------
501 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
503 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
505 win
->MacControlUserPaneDrawProc(part
) ;
507 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
509 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
511 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
513 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
515 return kControlNoPart
;
517 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
519 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
521 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
523 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
525 return kControlNoPart
;
527 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
529 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
531 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
533 win
->MacControlUserPaneIdleProc() ;
535 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
537 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
539 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
541 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
543 return kControlNoPart
;
545 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
547 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
549 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
551 win
->MacControlUserPaneActivateProc(activating
) ;
553 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
555 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
557 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
559 return win
->MacControlUserPaneFocusProc(action
) ;
561 return kControlNoPart
;
563 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
565 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
567 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
569 win
->MacControlUserPaneBackgroundProc(info
) ;
571 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
573 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
575 RgnHandle rgn
= NewRgn() ;
577 wxMacWindowStateSaver
sv( this ) ;
578 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
579 MacDoRedraw( rgn
, 0 ) ;
583 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
585 return kControlNoPart
;
588 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
590 return kControlNoPart
;
593 void wxWindowMac::MacControlUserPaneIdleProc()
597 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
599 return kControlNoPart
;
602 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
606 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
608 return kControlNoPart
;
611 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
617 // ---------------------------------------------------------------------------
618 // Scrollbar Tracking for all
619 // ---------------------------------------------------------------------------
621 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
622 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
626 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
629 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
633 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
635 // ===========================================================================
637 // ===========================================================================
639 #if KEY_wxList_DEPRECATED
640 wxList
wxWinMacControlList(wxKEY_INTEGER
);
642 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
644 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
647 return (wxControl
*)node
->GetData();
650 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
652 // adding NULL ControlRef is (first) surely a result of an error and
653 // (secondly) breaks native event processing
654 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
656 if ( !wxWinMacControlList
.Find((long)inControl
) )
657 wxWinMacControlList
.Append((long)inControl
, control
);
660 void wxRemoveMacControlAssociation(wxWindow
*control
)
662 // remove all associations pointing to us
663 while ( wxWinMacControlList
.DeleteObject(control
) )
668 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
670 static MacControlMap wxWinMacControlList
;
672 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
674 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
676 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
679 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
681 // adding NULL ControlRef is (first) surely a result of an error and
682 // (secondly) breaks native event processing
683 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
685 wxWinMacControlList
[inControl
] = control
;
688 void wxRemoveMacControlAssociation(wxWindow
*control
)
690 // iterate over all the elements in the class
691 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
692 // we should go on...
698 MacControlMap::iterator it
;
699 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
701 if ( it
->second
== control
)
703 wxWinMacControlList
.erase(it
);
710 #endif // deprecated wxList
712 // ----------------------------------------------------------------------------
713 // constructors and such
714 // ----------------------------------------------------------------------------
716 wxWindowMac::wxWindowMac()
721 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
726 const wxString
& name
)
729 Create(parent
, id
, pos
, size
, style
, name
);
732 void wxWindowMac::Init()
736 #if WXWIN_COMPATIBILITY_2_4
737 m_backgroundTransparent
= FALSE
;
740 // as all windows are created with WS_VISIBLE style...
743 m_hScrollBar
= NULL
;
744 m_vScrollBar
= NULL
;
745 m_macBackgroundBrush
= wxNullBrush
;
747 m_macIsUserPane
= TRUE
;
748 #if wxMAC_USE_CORE_GRAPHICS
749 m_cgContextRef
= NULL
;
751 // we need a valid font for the encodings
752 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
756 wxWindowMac::~wxWindowMac()
760 m_isBeingDeleted
= TRUE
;
762 MacInvalidateBorders() ;
764 #ifndef __WXUNIVERSAL__
765 // VS: make sure there's no wxFrame with last focus set to us:
766 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
768 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
771 if ( frame
->GetLastFocus() == this )
773 frame
->SetLastFocus((wxWindow
*)NULL
);
778 #endif // __WXUNIVERSAL__
780 // destroy children before destroying this window itself
783 // wxRemoveMacControlAssociation( this ) ;
784 // If we delete an item, we should initialize the parent panel,
785 // because it could now be invalid.
786 wxWindow
*parent
= GetParent() ;
789 if (parent
->GetDefaultItem() == (wxButton
*) this)
790 parent
->SetDefaultItem(NULL
);
792 if ( m_peer
&& m_peer
->Ok() )
794 // in case the callback might be called during destruction
795 wxRemoveMacControlAssociation( this) ;
796 // we currently are not using this hook
797 // ::SetControlColorProc( *m_peer , NULL ) ;
801 if ( g_MacLastWindow
== this )
803 g_MacLastWindow
= NULL
;
806 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
809 if ( frame
->GetLastFocus() == this )
810 frame
->SetLastFocus( NULL
) ;
813 // delete our drop target if we've got one
814 #if wxUSE_DRAG_AND_DROP
815 if ( m_dropTarget
!= NULL
)
820 #endif // wxUSE_DRAG_AND_DROP
824 WXWidget
wxWindowMac::GetHandle() const
826 return (WXWidget
) m_peer
->GetControlRef() ;
830 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
832 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
833 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
834 GetEventTypeCount(eventList
), eventList
, this,
835 (EventHandlerRef
*)&m_macControlEventHandler
);
836 #if !TARGET_API_MAC_OSX
837 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
839 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
840 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
841 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
842 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
843 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
844 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
845 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
846 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
853 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
857 const wxString
& name
)
859 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
861 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
864 m_windowVariant
= parent
->GetWindowVariant() ;
866 if ( m_macIsUserPane
)
868 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
871 | kControlSupportsEmbedding
872 | kControlSupportsLiveFeedback
873 | kControlGetsFocusOnClick
874 // | kControlHasSpecialBackground
875 // | kControlSupportsCalcBestRect
876 | kControlHandlesTracking
877 | kControlSupportsFocus
878 | kControlWantsActivate
882 m_peer
= new wxMacControl(this) ;
883 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
886 MacPostControlCreate(pos
,size
) ;
888 #ifndef __WXUNIVERSAL__
889 // Don't give scrollbars to wxControls unless they ask for them
890 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
891 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
893 MacCreateScrollBars( style
) ;
897 wxWindowCreateEvent
event(this);
898 GetEventHandler()->AddPendingEvent(event
);
903 void wxWindowMac::MacChildAdded()
907 m_vScrollBar
->Raise() ;
911 m_hScrollBar
->Raise() ;
916 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
918 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
920 m_peer
->SetReference( (long) this ) ;
921 GetParent()->AddChild(this);
923 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
925 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
926 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
927 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
928 GetParent()->MacChildAdded() ;
930 // adjust font, controlsize etc
931 DoSetWindowVariant( m_windowVariant
) ;
933 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
935 if (!m_macIsUserPane
)
937 SetInitialBestSize(size
);
940 SetCursor( *wxSTANDARD_CURSOR
) ;
943 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
945 // Don't assert, in case we set the window variant before
946 // the window is created
947 // wxASSERT( m_peer->Ok() ) ;
949 m_windowVariant
= variant
;
951 if (m_peer
== NULL
|| !m_peer
->Ok())
955 ThemeFontID themeFont
= kThemeSystemFont
;
957 // we will get that from the settings later
958 // and make this NORMAL later, but first
959 // we have a few calculations that we must fix
963 case wxWINDOW_VARIANT_NORMAL
:
964 size
= kControlSizeNormal
;
965 themeFont
= kThemeSystemFont
;
967 case wxWINDOW_VARIANT_SMALL
:
968 size
= kControlSizeSmall
;
969 themeFont
= kThemeSmallSystemFont
;
971 case wxWINDOW_VARIANT_MINI
:
972 if (UMAGetSystemVersion() >= 0x1030 )
974 // not always defined in the headers
980 size
= kControlSizeSmall
;
981 themeFont
= kThemeSmallSystemFont
;
984 case wxWINDOW_VARIANT_LARGE
:
985 size
= kControlSizeLarge
;
986 themeFont
= kThemeSystemFont
;
989 wxFAIL_MSG(_T("unexpected window variant"));
992 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
995 font
.MacCreateThemeFont( themeFont
) ;
999 void wxWindowMac::MacUpdateControlFont()
1001 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1005 bool wxWindowMac::SetFont(const wxFont
& font
)
1007 bool retval
= wxWindowBase::SetFont( font
) ;
1009 MacUpdateControlFont() ;
1014 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1016 if ( !wxWindowBase::SetForegroundColour(col
) )
1019 MacUpdateControlFont() ;
1024 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1026 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1030 wxColour
newCol(GetBackgroundColour());
1031 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1033 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1035 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1037 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1041 brush
.SetColour( newCol
) ;
1043 MacSetBackgroundBrush( brush
) ;
1045 MacUpdateControlFont() ;
1050 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1052 m_macBackgroundBrush
= brush
;
1053 m_peer
->SetBackground( brush
) ;
1056 bool wxWindowMac::MacCanFocus() const
1058 // there is currently no way to determine whether the window is running in full keyboard
1059 // access mode, therefore we cannot rely on these features, yet the only other way would be
1060 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1061 // in event handlers...
1062 UInt32 features
= 0 ;
1063 m_peer
->GetFeatures( & features
) ;
1064 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1068 void wxWindowMac::SetFocus()
1070 if ( AcceptsFocus() )
1073 wxWindow
* former
= FindFocus() ;
1074 if ( former
== this )
1077 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1078 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1079 // leave in case of an error
1080 if ( err
== errCouldntSetFocus
)
1083 #if !TARGET_API_MAC_OSX
1084 // emulate carbon events when running under carbonlib where they are not natively available
1087 EventRef evRef
= NULL
;
1088 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1091 wxMacCarbonEvent
cEvent( evRef
) ;
1092 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1093 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1095 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1096 ReleaseEvent(evRef
) ;
1098 // send new focus event
1100 EventRef evRef
= NULL
;
1101 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1104 wxMacCarbonEvent
cEvent( evRef
) ;
1105 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1106 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1108 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1109 ReleaseEvent(evRef
) ;
1116 void wxWindowMac::DoCaptureMouse()
1118 wxTheApp
->s_captureWindow
= this ;
1121 wxWindow
* wxWindowBase::GetCapture()
1123 return wxTheApp
->s_captureWindow
;
1126 void wxWindowMac::DoReleaseMouse()
1128 wxTheApp
->s_captureWindow
= NULL
;
1131 #if wxUSE_DRAG_AND_DROP
1133 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1135 if ( m_dropTarget
!= 0 ) {
1136 delete m_dropTarget
;
1139 m_dropTarget
= pDropTarget
;
1140 if ( m_dropTarget
!= 0 )
1148 // Old style file-manager drag&drop
1149 void wxWindowMac::DragAcceptFiles(bool accept
)
1154 // Returns the size of the native control. In the case of the toplevel window
1155 // this is the content area root control
1157 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1158 int& w
, int& h
) const
1160 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1163 // From a wx position / size calculate the appropriate size of the native control
1165 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1168 int& w
, int& h
, bool adjustOrigin
) const
1170 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1172 // the desired size, minus the border pixels gives the correct size of the control
1176 // todo the default calls may be used as soon as PostCreateControl Is moved here
1177 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1178 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1180 if ( !isCompositing
)
1181 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1183 x
+= MacGetLeftBorderSize() ;
1184 y
+= MacGetTopBorderSize() ;
1185 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1186 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1189 AdjustForParentClientOrigin( x
, y
) ;
1191 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1192 if ( !GetParent()->IsTopLevel() )
1194 x
-= GetParent()->MacGetLeftBorderSize() ;
1195 y
-= GetParent()->MacGetTopBorderSize() ;
1201 // Get window size (not client size)
1202 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1205 m_peer
->GetRect( &bounds
) ;
1207 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1208 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1211 // get the position of the bounds of this window in client coordinates of its parent
1212 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1215 m_peer
->GetRect( &bounds
) ;
1217 int x1
= bounds
.left
;
1218 int y1
= bounds
.top
;
1220 if ( !IsTopLevel() )
1222 wxWindow
*parent
= GetParent();
1225 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1226 x1
+= parent
->MacGetLeftBorderSize() ;
1227 y1
+= parent
->MacGetTopBorderSize() ;
1228 // and now to client coordinates
1229 wxPoint
pt(parent
->GetClientAreaOrigin());
1238 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1240 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1242 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1245 Point localwhere
= {0,0} ;
1247 if(x
) localwhere
.h
= * x
;
1248 if(y
) localwhere
.v
= * y
;
1250 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1251 if(x
) *x
= localwhere
.h
;
1252 if(y
) *y
= localwhere
.v
;
1255 MacRootWindowToWindow( x
, y
) ;
1257 wxPoint origin
= GetClientAreaOrigin() ;
1258 if(x
) *x
-= origin
.x
;
1259 if(y
) *y
-= origin
.y
;
1262 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1264 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1265 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1267 wxPoint origin
= GetClientAreaOrigin() ;
1268 if(x
) *x
+= origin
.x
;
1269 if(y
) *y
+= origin
.y
;
1271 MacWindowToRootWindow( x
, y
) ;
1274 Point localwhere
= { 0,0 };
1275 if(x
) localwhere
.h
= * x
;
1276 if(y
) localwhere
.v
= * y
;
1277 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1278 if(x
) *x
= localwhere
.h
;
1279 if(y
) *y
= localwhere
.v
;
1283 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1285 wxPoint origin
= GetClientAreaOrigin() ;
1286 if(x
) *x
+= origin
.x
;
1287 if(y
) *y
+= origin
.y
;
1289 MacWindowToRootWindow( x
, y
) ;
1292 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1294 MacRootWindowToWindow( x
, y
) ;
1296 wxPoint origin
= GetClientAreaOrigin() ;
1297 if(x
) *x
-= origin
.x
;
1298 if(y
) *y
-= origin
.y
;
1301 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1304 if ( x
) pt
.x
= *x
;
1305 if ( y
) pt
.y
= *y
;
1307 if ( !IsTopLevel() )
1309 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1312 pt
.x
-= MacGetLeftBorderSize() ;
1313 pt
.y
-= MacGetTopBorderSize() ;
1314 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1318 if ( x
) *x
= (int) pt
.x
;
1319 if ( y
) *y
= (int) pt
.y
;
1322 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1327 MacWindowToRootWindow( &x1
, &y1
) ;
1332 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1335 if ( x
) pt
.x
= *x
;
1336 if ( y
) pt
.y
= *y
;
1338 if ( !IsTopLevel() )
1340 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1341 pt
.x
+= MacGetLeftBorderSize() ;
1342 pt
.y
+= MacGetTopBorderSize() ;
1345 if ( x
) *x
= (int) pt
.x
;
1346 if ( y
) *y
= (int) pt
.y
;
1349 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1354 MacRootWindowToWindow( &x1
, &y1
) ;
1359 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1361 RgnHandle rgn
= NewRgn() ;
1362 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1366 GetRegionBounds( rgn
, &content
) ;
1367 m_peer
->GetRect( &structure
) ;
1368 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1370 left
= content
.left
- structure
.left
;
1371 top
= content
.top
- structure
.top
;
1372 right
= structure
.right
- content
.right
;
1373 bottom
= structure
.bottom
- content
.bottom
;
1377 left
= top
= right
= bottom
= 0 ;
1382 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1384 wxSize sizeTotal
= size
;
1386 RgnHandle rgn
= NewRgn() ;
1388 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1392 GetRegionBounds( rgn
, &content
) ;
1394 m_peer
->GetRect( &structure
) ;
1395 // structure is in parent coordinates, but we only need width and height, so it's ok
1397 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1398 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1402 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1403 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1409 // Get size *available for subwindows* i.e. excluding menu bar etc.
1410 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1414 RgnHandle rgn
= NewRgn() ;
1416 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1418 GetRegionBounds( rgn
, &content
) ;
1422 m_peer
->GetRect( &content
) ;
1426 ww
= content
.right
- content
.left
;
1427 hh
= content
.bottom
- content
.top
;
1429 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1431 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1433 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1435 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1442 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1444 if (m_cursor
== cursor
)
1447 if (wxNullCursor
== cursor
)
1449 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1454 if ( ! wxWindowBase::SetCursor( cursor
) )
1458 wxASSERT_MSG( m_cursor
.Ok(),
1459 wxT("cursor must be valid after call to the base version"));
1462 wxWindowMac
*mouseWin
= 0 ;
1464 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1465 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1467 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1469 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1470 // position, use it...
1474 ControlPartCode part
;
1475 ControlRef control
;
1476 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1478 mouseWin
= wxFindControlFromMacControl( control
) ;
1481 QDSwapPort( savePort
, NULL
) ;
1484 if ( mouseWin
== this && !wxIsBusy() )
1486 m_cursor
.MacInstall() ;
1493 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1495 menu
->SetInvokingWindow(this);
1498 if ( x
== -1 && y
== -1 )
1500 wxPoint mouse
= wxGetMousePosition();
1501 x
= mouse
.x
; y
= mouse
.y
;
1505 ClientToScreen( &x
, &y
) ;
1508 menu
->MacBeforeDisplay( true ) ;
1509 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1510 if ( HiWord(menuResult
) != 0 )
1513 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1514 wxMenuItem
* item
= NULL
;
1516 item
= menu
->FindItem(id
, &realmenu
) ;
1517 if (item
->IsCheckable())
1519 item
->Check( !item
->IsChecked() ) ;
1521 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1523 menu
->MacAfterDisplay( true ) ;
1525 menu
->SetInvokingWindow(NULL
);
1531 // ----------------------------------------------------------------------------
1533 // ----------------------------------------------------------------------------
1537 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1539 wxWindowBase::DoSetToolTip(tooltip
);
1542 m_tooltip
->SetWindow(this);
1545 #endif // wxUSE_TOOLTIPS
1547 void wxWindowMac::MacInvalidateBorders()
1549 if ( m_peer
== NULL
)
1552 bool vis
= MacIsReallyShown() ;
1556 int outerBorder
= MacGetLeftBorderSize() ;
1557 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1560 if ( outerBorder
== 0 )
1563 // now we know that we have something to do at all
1565 // as the borders are drawn on the parent we have to properly invalidate all these areas
1566 RgnHandle updateInner
= NewRgn() ,
1567 updateOuter
= NewRgn() ;
1569 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1571 m_peer
->GetRect( &rect
) ;
1572 RectRgn( updateInner
, &rect
) ;
1573 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1574 RectRgn( updateOuter
, &rect
) ;
1575 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1576 #ifdef __WXMAC_OSX__
1577 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1579 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1581 InvalWindowRgn( tlw
, updateOuter
) ;
1583 DisposeRgn(updateOuter
) ;
1584 DisposeRgn(updateInner
) ;
1586 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1587 RectRgn( updateInner , &rect ) ;
1588 InsetRect( &rect , -4 , -4 ) ;
1589 RectRgn( updateOuter , &rect ) ;
1590 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1591 wxPoint parent(0,0);
1592 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1593 parent -= GetParent()->GetClientAreaOrigin() ;
1594 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1595 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1596 DisposeRgn(updateOuter) ;
1597 DisposeRgn(updateInner) ;
1602 // deleting a window while it is shown invalidates the region occupied by border or
1605 if ( IsShown() && ( outerBorder > 0 ) )
1607 // as the borders are drawn on the parent we have to properly invalidate all these areas
1608 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1612 m_peer->GetRect( &rect ) ;
1613 RectRgn( updateInner , &rect ) ;
1614 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1615 RectRgn( updateOuter , &rect ) ;
1616 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1617 wxPoint parent(0,0);
1618 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1619 parent -= GetParent()->GetClientAreaOrigin() ;
1620 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1621 CopyRgn( updateOuter , updateTotal ) ;
1623 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1624 DisposeRgn(updateOuter) ;
1625 DisposeRgn(updateInner) ;
1626 DisposeRgn(updateTotal) ;
1631 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1633 int outerBorder
= MacGetLeftBorderSize() ;
1634 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1637 if ( vis
&& ( outerBorder
> 0 ) )
1639 // as the borders are drawn on the parent we have to properly invalidate all these areas
1640 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1644 m_peer
->GetRect( &rect
) ;
1645 RectRgn( updateInner
, &rect
) ;
1646 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1647 RectRgn( updateOuter
, &rect
) ;
1648 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1650 wxPoint parent(0,0);
1651 #if TARGET_API_MAC_OSX
1652 // no offsetting needed when compositing
1654 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1655 parent -= GetParent()->GetClientAreaOrigin() ;
1656 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1659 CopyRgn( updateOuter
, updateTotal
) ;
1662 RectRgn( updateInner
, &rect
) ;
1663 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1664 RectRgn( updateOuter
, &rect
) ;
1665 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1667 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1669 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1671 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1672 DisposeRgn(updateOuter
) ;
1673 DisposeRgn(updateInner
) ;
1674 DisposeRgn(updateTotal
) ;
1679 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1681 // this is never called for a toplevel window, so we know we have a parent
1682 int former_x
, former_y
, former_w
, former_h
;
1684 // Get true coordinates of former position
1685 DoGetPosition( &former_x
, &former_y
) ;
1686 DoGetSize( &former_w
, &former_h
) ;
1688 wxWindow
*parent
= GetParent();
1691 wxPoint
pt(parent
->GetClientAreaOrigin());
1696 int actualWidth
= width
;
1697 int actualHeight
= height
;
1701 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1702 actualWidth
= m_minWidth
;
1703 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1704 actualHeight
= m_minHeight
;
1705 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1706 actualWidth
= m_maxWidth
;
1707 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1708 actualHeight
= m_maxHeight
;
1710 bool doMove
= false ;
1711 bool doResize
= false ;
1713 if ( actualX
!= former_x
|| actualY
!= former_y
)
1717 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1722 if ( doMove
|| doResize
)
1724 // as the borders are drawn outside the native control, we adjust now
1726 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1727 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1728 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1731 wxMacRectToNative( &bounds
, &r
) ;
1733 if ( !GetParent()->IsTopLevel() )
1735 wxMacWindowToNative( GetParent() , &r
) ;
1738 MacInvalidateBorders() ;
1740 m_peer
->SetRect( &r
) ;
1743 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1745 MacInvalidateBorders() ;
1747 MacRepositionScrollBars() ;
1750 wxPoint
point(actualX
,actualY
);
1751 wxMoveEvent
event(point
, m_windowId
);
1752 event
.SetEventObject(this);
1753 GetEventHandler()->ProcessEvent(event
) ;
1757 MacRepositionScrollBars() ;
1758 wxSize
size(actualWidth
, actualHeight
);
1759 wxSizeEvent
event(size
, m_windowId
);
1760 event
.SetEventObject(this);
1761 GetEventHandler()->ProcessEvent(event
);
1767 wxSize
wxWindowMac::DoGetBestSize() const
1769 if ( m_macIsUserPane
|| IsTopLevel() )
1770 return wxWindowBase::DoGetBestSize() ;
1772 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1773 int bestWidth
, bestHeight
;
1774 m_peer
->GetBestRect( &bestsize
) ;
1776 if ( EmptyRect( &bestsize
) )
1778 bestsize
.left
= bestsize
.top
= 0 ;
1779 bestsize
.right
= 16 ;
1780 bestsize
.bottom
= 16 ;
1781 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1783 bestsize
.bottom
= 16 ;
1786 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1788 bestsize
.bottom
= 24 ;
1790 #endif // wxUSE_SPINBTN
1793 // return wxWindowBase::DoGetBestSize() ;
1797 bestWidth
= bestsize
.right
- bestsize
.left
;
1798 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1799 if ( bestHeight
< 10 )
1802 return wxSize(bestWidth
, bestHeight
);
1806 // set the size of the window: if the dimensions are positive, just use them,
1807 // but if any of them is equal to -1, it means that we must find the value for
1808 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1809 // which case -1 is a valid value for x and y)
1811 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1812 // the width/height to best suit our contents, otherwise we reuse the current
1814 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1816 // get the current size and position...
1817 int currentX
, currentY
;
1818 GetPosition(¤tX
, ¤tY
);
1820 int currentW
,currentH
;
1821 GetSize(¤tW
, ¤tH
);
1823 // ... and don't do anything (avoiding flicker) if it's already ok
1824 if ( x
== currentX
&& y
== currentY
&&
1825 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1828 MacRepositionScrollBars() ; // we might have a real position shift
1832 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1834 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1837 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1839 wxSize
size(-1, -1);
1842 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1844 size
= DoGetBestSize();
1849 // just take the current one
1856 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1860 size
= DoGetBestSize();
1862 //else: already called DoGetBestSize() above
1868 // just take the current one
1873 DoMoveWindow(x
, y
, width
, height
);
1877 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1879 RgnHandle rgn
= NewRgn() ;
1881 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1883 GetRegionBounds( rgn
, &content
) ;
1887 content
.left
= content
.top
= 0 ;
1890 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1893 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1895 if ( clientheight
!= -1 || clientheight
!= -1 )
1897 int currentclientwidth
, currentclientheight
;
1898 int currentwidth
, currentheight
;
1900 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1901 GetSize( ¤twidth
, ¤theight
) ;
1903 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1904 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1908 void wxWindowMac::SetTitle(const wxString
& title
)
1910 m_label
= wxStripMenuCodes(title
) ;
1912 if ( m_peer
&& m_peer
->Ok() )
1914 m_peer
->SetTitle( m_label
) ;
1919 wxString
wxWindowMac::GetTitle() const
1924 bool wxWindowMac::Show(bool show
)
1926 bool former
= MacIsReallyShown() ;
1927 if ( !wxWindowBase::Show(show
) )
1930 // TODO use visibilityChanged Carbon Event for OSX
1933 m_peer
->SetVisibility( show
, true ) ;
1935 if ( former
!= MacIsReallyShown() )
1936 MacPropagateVisibilityChanged() ;
1940 bool wxWindowMac::Enable(bool enable
)
1942 wxASSERT( m_peer
->Ok() ) ;
1943 bool former
= MacIsReallyEnabled() ;
1944 if ( !wxWindowBase::Enable(enable
) )
1947 m_peer
->Enable( enable
) ;
1949 if ( former
!= MacIsReallyEnabled() )
1950 MacPropagateEnabledStateChanged() ;
1955 // status change propagations (will be not necessary for OSX later )
1958 void wxWindowMac::MacPropagateVisibilityChanged()
1960 #if !TARGET_API_MAC_OSX
1961 MacVisibilityChanged() ;
1963 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1966 wxWindowMac
*child
= node
->GetData();
1967 if ( child
->IsShown() )
1968 child
->MacPropagateVisibilityChanged( ) ;
1969 node
= node
->GetNext();
1974 void wxWindowMac::MacPropagateEnabledStateChanged( )
1976 #if !TARGET_API_MAC_OSX
1977 MacEnabledStateChanged() ;
1979 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1982 wxWindowMac
*child
= node
->GetData();
1983 if ( child
->IsEnabled() )
1984 child
->MacPropagateEnabledStateChanged() ;
1985 node
= node
->GetNext();
1990 void wxWindowMac::MacPropagateHiliteChanged( )
1992 #if !TARGET_API_MAC_OSX
1993 MacHiliteChanged() ;
1995 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1998 wxWindowMac
*child
= node
->GetData();
1999 // if ( child->IsEnabled() )
2000 child
->MacPropagateHiliteChanged() ;
2001 node
= node
->GetNext();
2007 // status change notifications
2010 void wxWindowMac::MacVisibilityChanged()
2014 void wxWindowMac::MacHiliteChanged()
2018 void wxWindowMac::MacEnabledStateChanged()
2023 // status queries on the inherited window's state
2026 bool wxWindowMac::MacIsReallyShown()
2028 // only under OSX the visibility of the TLW is taken into account
2029 if ( m_isBeingDeleted
)
2032 #if TARGET_API_MAC_OSX
2033 if ( m_peer
&& m_peer
->Ok() )
2034 return m_peer
->IsVisible();
2036 wxWindow
* win
= this ;
2037 while( win
->IsShown() )
2039 if ( win
->IsTopLevel() )
2042 win
= win
->GetParent() ;
2050 bool wxWindowMac::MacIsReallyEnabled()
2052 return m_peer
->IsEnabled() ;
2055 bool wxWindowMac::MacIsReallyHilited()
2057 return m_peer
->IsActive();
2060 void wxWindowMac::MacFlashInvalidAreas()
2062 #if TARGET_API_MAC_OSX
2063 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2071 int wxWindowMac::GetCharHeight() const
2073 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2074 return dc
.GetCharHeight() ;
2077 int wxWindowMac::GetCharWidth() const
2079 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2080 return dc
.GetCharWidth() ;
2083 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2084 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2086 const wxFont
*fontToUse
= theFont
;
2088 fontToUse
= &m_font
;
2090 wxClientDC
dc( (wxWindowMac
*) this ) ;
2092 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2093 if ( externalLeading
)
2094 *externalLeading
= le
;
2104 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2105 * we always intersect with the entire window, not only with the client area
2108 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2110 if ( m_peer
== NULL
)
2113 if ( !MacIsReallyShown() )
2119 wxMacRectToNative( rect
, &r
) ;
2120 m_peer
->SetNeedsDisplay( &r
) ;
2124 m_peer
->SetNeedsDisplay() ;
2128 void wxWindowMac::Freeze()
2130 #if TARGET_API_MAC_OSX
2131 if ( !m_frozenness
++ )
2133 if ( m_peer
&& m_peer
->Ok() )
2134 m_peer
->SetDrawingEnabled( false ) ;
2140 void wxWindowMac::Thaw()
2142 #if TARGET_API_MAC_OSX
2143 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2145 if ( !--m_frozenness
)
2147 if ( m_peer
&& m_peer
->Ok() )
2149 m_peer
->SetDrawingEnabled( true ) ;
2150 m_peer
->InvalidateWithChildren() ;
2156 wxWindowMac
*wxGetActiveWindow()
2158 // actually this is a windows-only concept
2162 // Coordinates relative to the window
2163 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2165 // We really don't move the mouse programmatically under Mac.
2168 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2170 #if TARGET_API_MAC_OSX
2171 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2178 event
.GetDC()->Clear() ;
2182 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2187 int wxWindowMac::GetScrollPos(int orient
) const
2189 if ( orient
== wxHORIZONTAL
)
2192 return m_hScrollBar
->GetThumbPosition() ;
2197 return m_vScrollBar
->GetThumbPosition() ;
2202 // This now returns the whole range, not just the number
2203 // of positions that we can scroll.
2204 int wxWindowMac::GetScrollRange(int orient
) const
2206 if ( orient
== wxHORIZONTAL
)
2209 return m_hScrollBar
->GetRange() ;
2214 return m_vScrollBar
->GetRange() ;
2219 int wxWindowMac::GetScrollThumb(int orient
) const
2221 if ( orient
== wxHORIZONTAL
)
2224 return m_hScrollBar
->GetThumbSize() ;
2229 return m_vScrollBar
->GetThumbSize() ;
2234 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2236 if ( orient
== wxHORIZONTAL
)
2239 m_hScrollBar
->SetThumbPosition( pos
) ;
2244 m_vScrollBar
->SetThumbPosition( pos
) ;
2249 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2250 // our own window origin is at leftOrigin/rightOrigin
2253 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2259 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2260 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2262 m_peer
->GetRect( &rect
) ;
2263 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2265 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2266 if ( UMAGetSystemVersion() >= 0x1030 )
2269 HIThemeFrameDrawInfo info
;
2270 memset( &info
, 0 , sizeof( info
) ) ;
2274 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2275 info
.isFocused
= hasFocus
;
2278 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2279 wxASSERT( cgContext
) ;
2281 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2284 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2285 InsetRect( &srect
, border
, border
);
2286 info
.kind
= kHIThemeFrameTextFieldSquare
;
2289 else if (HasFlag(wxSIMPLE_BORDER
))
2292 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2293 InsetRect( &srect
, border
, border
);
2294 info
.kind
= kHIThemeFrameListBox
;
2300 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2301 srect
.bottom
- srect
.top
) ;
2302 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2304 else if ( hasFocus
)
2307 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2308 srect
.bottom
- srect
.top
) ;
2309 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2312 m_peer
->GetRect( &rect
) ;
2313 if ( hasBothScrollbars
)
2316 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2317 CGRect cgrect
= CGRectMake( srect
.right
- size
, srect
.bottom
- size
, size
, size
) ;
2318 CGPoint cgpoint
= CGPointMake( srect
.right
- size
, srect
.bottom
- size
) ;
2319 HIThemeGrowBoxDrawInfo info
;
2320 memset( &info
, 0 , sizeof( info
) ) ;
2322 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2323 info
.kind
= kHIThemeGrowBoxKindNone
;
2324 info
.size
= kHIThemeGrowBoxSizeNormal
;
2325 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2326 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2332 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2336 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2337 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2340 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2344 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2345 InsetRect( &srect
, border
, border
);
2346 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2348 else if (HasFlag(wxSIMPLE_BORDER
))
2352 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2353 InsetRect( &srect
, border
, border
);
2354 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2360 DrawThemeFocusRect( &srect
, true ) ;
2362 if ( hasBothScrollbars
)
2364 // GetThemeStandaloneGrowBoxBounds
2365 //DrawThemeStandaloneNoGrowBox
2370 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2372 if ( child
== m_hScrollBar
)
2373 m_hScrollBar
= NULL
;
2374 if ( child
== m_vScrollBar
)
2375 m_vScrollBar
= NULL
;
2377 wxWindowBase::RemoveChild( child
) ;
2380 // New function that will replace some of the above.
2381 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2382 int range
, bool refresh
)
2384 if ( orient
== wxHORIZONTAL
)
2388 if ( range
== 0 || thumbVisible
>= range
)
2390 if ( m_hScrollBar
->IsShown() )
2391 m_hScrollBar
->Show(false) ;
2395 if ( !m_hScrollBar
->IsShown() )
2396 m_hScrollBar
->Show(true) ;
2398 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2405 if ( range
== 0 || thumbVisible
>= range
)
2407 if ( m_vScrollBar
->IsShown() )
2408 m_vScrollBar
->Show(false) ;
2412 if ( !m_vScrollBar
->IsShown() )
2413 m_vScrollBar
->Show(true) ;
2415 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2418 MacRepositionScrollBars() ;
2421 // Does a physical scroll
2422 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2424 if( dx
== 0 && dy
==0 )
2430 int width
, height
;
2431 GetClientSize( &width
, &height
) ;
2432 #if TARGET_API_MAC_OSX
2433 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2434 // area is scrolled, this does not occur if width and height are 2 pixels less,
2435 // TODO write optimal workaround
2436 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2439 scrollrect
.Intersect( *rect
) ;
2441 if ( m_peer
->GetNeedsDisplay() )
2443 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2444 // either immediate redraw or full invalidate
2446 // is the better overall solution, as it does not slow down scrolling
2447 m_peer
->SetNeedsDisplay() ;
2449 // this would be the preferred version for fast drawing controls
2450 if( UMAGetSystemVersion() < 0x1030 )
2453 HIViewRender(m_peer
->GetControlRef()) ;
2456 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2457 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2458 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2465 RgnHandle updateRgn
= NewRgn() ;
2468 wxClientDC
dc(this) ;
2469 wxMacPortSetter
helper(&dc
) ;
2471 m_peer
->GetRect( &scrollrect
) ;
2472 scrollrect
.top
+= MacGetTopBorderSize() ;
2473 scrollrect
.left
+= MacGetLeftBorderSize() ;
2474 scrollrect
.bottom
= scrollrect
.top
+ height
;
2475 scrollrect
.right
= scrollrect
.left
+ width
;
2479 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2480 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2481 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2483 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2485 // now scroll the former update region as well and add the new update region
2487 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2488 RgnHandle formerUpdateRgn
= NewRgn() ;
2489 RgnHandle scrollRgn
= NewRgn() ;
2490 RectRgn( scrollRgn
, &scrollrect
) ;
2491 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2493 LocalToGlobal( &pt
) ;
2494 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2495 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2496 if ( !EmptyRgn( formerUpdateRgn
) )
2498 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2499 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2500 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2502 InvalWindowRgn(rootWindow
, updateRgn
) ;
2503 DisposeRgn( updateRgn
) ;
2504 DisposeRgn( formerUpdateRgn
) ;
2505 DisposeRgn( scrollRgn
) ;
2510 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2512 wxWindowMac
*child
= node
->GetData();
2513 if (child
== m_vScrollBar
) continue;
2514 if (child
== m_hScrollBar
) continue;
2515 if (child
->IsTopLevel()) continue;
2518 child
->GetPosition( &x
, &y
);
2520 child
->GetSize( &w
, &h
);
2524 if (rect
->Intersects(rc
))
2525 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2529 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2534 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2536 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2538 wxScrollWinEvent wevent
;
2539 wevent
.SetPosition(event
.GetPosition());
2540 wevent
.SetOrientation(event
.GetOrientation());
2541 wevent
.SetEventObject(this);
2543 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2544 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2545 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2546 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2547 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2548 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2549 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2550 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2551 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2552 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2553 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2554 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2555 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2556 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2557 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2558 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2560 GetEventHandler()->ProcessEvent(wevent
);
2564 // Get the window with the focus
2565 wxWindowMac
*wxWindowBase::DoFindFocus()
2567 ControlRef control
;
2568 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2569 return wxFindControlFromMacControl( control
) ;
2572 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2574 // panel wants to track the window which was the last to have focus in it,
2575 // so we want to set ourselves as the window which last had focus
2577 // notice that it's also important to do it upwards the tree becaus
2578 // otherwise when the top level panel gets focus, it won't set it back to
2579 // us, but to some other sibling
2581 // CS:don't know if this is still needed:
2582 //wxChildFocusEvent eventFocus(this);
2583 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2585 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2587 #if !wxMAC_USE_CORE_GRAPHICS
2588 wxMacWindowStateSaver
sv( this ) ;
2590 m_peer
->GetRect( &rect
) ;
2591 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2593 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2597 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2599 rect
.right
+= pt
.x
;
2601 rect
.bottom
+= pt
.y
;
2604 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2605 DrawThemeFocusRect( &rect
, true ) ;
2608 DrawThemeFocusRect( &rect
, false ) ;
2610 // as this erases part of the frame we have to redraw borders
2611 // and because our z-ordering is not always correct (staticboxes)
2612 // we have to invalidate things, we cannot simple redraw
2613 MacInvalidateBorders() ;
2616 GetParent()->Refresh() ;
2623 void wxWindowMac::OnInternalIdle()
2625 // This calls the UI-update mechanism (querying windows for
2626 // menu/toolbar/control state information)
2627 if (wxUpdateUIEvent::CanUpdate(this))
2628 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2631 // Raise the window to the top of the Z order
2632 void wxWindowMac::Raise()
2634 m_peer
->SetZOrder( true , NULL
) ;
2637 // Lower the window to the bottom of the Z order
2638 void wxWindowMac::Lower()
2640 m_peer
->SetZOrder( false , NULL
) ;
2644 // static wxWindow *gs_lastWhich = NULL;
2646 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2648 // first trigger a set cursor event
2650 wxPoint clientorigin
= GetClientAreaOrigin() ;
2651 wxSize clientsize
= GetClientSize() ;
2653 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2655 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2657 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2658 if ( processedEvtSetCursor
&& event
.HasCursor() )
2660 cursor
= event
.GetCursor() ;
2665 // the test for processedEvtSetCursor is here to prevent using m_cursor
2666 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2667 // it - this is a way to say that our cursor shouldn't be used for this
2669 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2679 cursor
= *wxSTANDARD_CURSOR
;
2683 cursor
.MacInstall() ;
2685 return cursor
.Ok() ;
2688 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2693 return m_tooltip
->GetTip() ;
2696 return wxEmptyString
;
2699 void wxWindowMac::ClearBackground()
2705 void wxWindowMac::Update()
2707 #if TARGET_API_MAC_OSX
2709 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2710 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2712 // for composited windows this also triggers a redraw of all
2713 // invalid views in the window
2714 if( UMAGetSystemVersion() >= 0x1030 )
2715 HIWindowFlush(window
) ;
2719 // the only way to trigger the redrawing on earlier systems is to call
2722 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2723 UInt32 currentEventClass
= 0 ;
2724 UInt32 currentEventKind
= 0 ;
2725 if ( currentEvent
!= NULL
)
2727 currentEventClass
= ::GetEventClass( currentEvent
) ;
2728 currentEventKind
= ::GetEventKind( currentEvent
) ;
2730 if ( currentEventClass
!= kEventClassMenu
)
2732 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2735 OSStatus status
= noErr
;
2736 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2739 m_peer
->SetNeedsDisplay() ;
2742 ::Draw1Control( m_peer
->GetControlRef() ) ;
2746 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2748 wxTopLevelWindowMac
* win
= NULL
;
2749 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2752 win
= wxFindWinFromMacWindow( window
) ;
2756 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2758 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2759 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2760 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2761 // to add focus borders everywhere
2764 RgnHandle visRgn
= NewRgn() ;
2765 RgnHandle tempRgn
= NewRgn() ;
2766 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2768 m_peer
->GetRect( &r
) ;
2769 r
.left
-= MacGetLeftBorderSize() ;
2770 r
.top
-= MacGetTopBorderSize() ;
2771 r
.bottom
+= MacGetBottomBorderSize() ;
2772 r
.right
+= MacGetRightBorderSize() ;
2779 if ( includeOuterStructures
)
2780 InsetRect( &r
, -4 , -4 ) ;
2781 RectRgn( visRgn
, &r
) ;
2783 if ( !IsTopLevel() )
2785 wxWindow
* child
= this ;
2786 wxWindow
* parent
= child
->GetParent() ;
2791 // we have to find a better clipping algorithm here, in order not to clip things
2792 // positioned like status and toolbar
2793 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2795 size
= parent
->GetSize() ;
2800 size
= parent
->GetClientSize() ;
2801 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2805 parent
->MacWindowToRootWindow( &x
, &y
) ;
2806 MacRootWindowToWindow( &x
, &y
) ;
2808 if ( !includeOuterStructures
|| (
2809 parent
->MacClipChildren() ||
2810 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2813 SetRectRgn( tempRgn
,
2814 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2815 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2816 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2818 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2820 if ( parent
->IsTopLevel() )
2823 parent
= child
->GetParent() ;
2828 wxRegion vis
= visRgn
;
2829 DisposeRgn( visRgn
) ;
2830 DisposeRgn( tempRgn
) ;
2835 This function must not change the updatergn !
2837 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2839 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2840 bool handled
= false ;
2842 GetRegionBounds( updatergn
, &updatebounds
) ;
2844 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2846 if ( !EmptyRgn(updatergn
) )
2848 RgnHandle newupdate
= NewRgn() ;
2849 wxSize point
= GetClientSize() ;
2850 wxPoint origin
= GetClientAreaOrigin() ;
2851 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2852 SectRgn( newupdate
, updatergn
, newupdate
) ;
2854 // first send an erase event to the entire update area
2856 // for the toplevel window this really is the entire area
2857 // for all the others only their client area, otherwise they
2858 // might be drawing with full alpha and eg put blue into
2859 // the grow-box area of a scrolled window (scroll sample)
2862 dc
= new wxWindowDC(this);
2864 dc
= new wxClientDC(this);
2865 dc
->SetClippingRegion(wxRegion(updatergn
));
2866 wxEraseEvent
eevent( GetId(), dc
);
2867 eevent
.SetEventObject( this );
2868 GetEventHandler()->ProcessEvent( eevent
);
2872 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2873 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2874 m_updateRegion
= newupdate
;
2875 DisposeRgn( newupdate
) ;
2877 if ( !m_updateRegion
.Empty() )
2879 // paint the window itself
2882 event
.SetTimestamp(time
);
2883 event
.SetEventObject(this);
2884 GetEventHandler()->ProcessEvent(event
);
2888 // now we cannot rely on having its borders drawn by a window itself, as it does not
2889 // get the updateRgn wide enough to always do so, so we do it from the parent
2890 // this would also be the place to draw any custom backgrounds for native controls
2891 // in Composited windowing
2892 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2894 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2896 wxWindowMac
*child
= node
->GetData();
2897 if (child
== m_vScrollBar
) continue;
2898 if (child
== m_hScrollBar
) continue;
2899 if (child
->IsTopLevel()) continue;
2900 if (!child
->IsShown()) continue;
2902 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2905 child
->GetPosition( &x
, &y
);
2907 child
->GetSize( &w
, &h
);
2908 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2909 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2910 InsetRect( &childRect
, -10 , -10) ;
2912 if ( RectInRgn( &childRect
, updatergn
) )
2915 // paint custom borders
2916 wxNcPaintEvent
eventNc( child
->GetId() );
2917 eventNc
.SetEventObject( child
);
2918 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2920 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2921 if ( UMAGetSystemVersion() >= 0x1030 )
2923 child
->MacPaintBorders(0,0) ;
2928 wxWindowDC
dc(this) ;
2929 dc
.SetClippingRegion(wxRegion(updatergn
));
2930 wxMacPortSetter
helper(&dc
) ;
2931 child
->MacPaintBorders(0,0) ;
2941 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2943 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2947 if ( iter
->IsTopLevel() )
2948 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2950 iter
= iter
->GetParent() ;
2952 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2956 void wxWindowMac::MacCreateScrollBars( long style
)
2958 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2960 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2962 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2963 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2964 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2965 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2967 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2968 variant
= wxWINDOW_VARIANT_SMALL
;
2971 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2973 GetClientSize( &width
, &height
) ;
2975 wxPoint
vPoint(width
-scrlsize
, 0) ;
2976 wxSize
vSize(scrlsize
, height
- adjust
) ;
2977 wxPoint
hPoint(0 , height
-scrlsize
) ;
2978 wxSize
hSize( width
- adjust
, scrlsize
) ;
2981 if ( style
& wxVSCROLL
)
2983 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2984 vSize
, wxVERTICAL
);
2987 if ( style
& wxHSCROLL
)
2989 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2990 hSize
, wxHORIZONTAL
);
2995 // because the create does not take into account the client area origin
2996 MacRepositionScrollBars() ; // we might have a real position shift
2999 void wxWindowMac::MacRepositionScrollBars()
3001 if ( !m_hScrollBar
&& !m_vScrollBar
)
3004 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3005 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3006 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3008 // get real client area
3012 GetSize( &width
, &height
) ;
3014 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3015 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3017 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3018 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3019 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3020 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3026 GetSize( &w , &h ) ;
3028 MacClientToRootWindow( &x , &y ) ;
3029 MacClientToRootWindow( &w , &h ) ;
3031 wxWindowMac *iter = (wxWindowMac*)this ;
3033 int totW = 10000 , totH = 10000;
3036 if ( iter->IsTopLevel() )
3038 iter->GetSize( &totW , &totH ) ;
3042 iter = iter->GetParent() ;
3070 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3074 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3078 bool wxWindowMac::AcceptsFocus() const
3080 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3083 void wxWindowMac::MacSuperChangedPosition()
3085 // only window-absolute structures have to be moved i.e. controls
3087 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3090 wxWindowMac
*child
= node
->GetData();
3091 child
->MacSuperChangedPosition() ;
3092 node
= node
->GetNext();
3096 void wxWindowMac::MacTopLevelWindowChangedPosition()
3098 // only screen-absolute structures have to be moved i.e. glcanvas
3100 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3103 wxWindowMac
*child
= node
->GetData();
3104 child
->MacTopLevelWindowChangedPosition() ;
3105 node
= node
->GetNext();
3109 long wxWindowMac::MacGetLeftBorderSize( ) const
3114 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3119 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3124 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3131 long wxWindowMac::MacGetRightBorderSize( ) const
3133 // they are all symmetric in mac themes
3134 return MacGetLeftBorderSize() ;
3137 long wxWindowMac::MacGetTopBorderSize( ) const
3139 // they are all symmetric in mac themes
3140 return MacGetLeftBorderSize() ;
3143 long wxWindowMac::MacGetBottomBorderSize( ) const
3145 // they are all symmetric in mac themes
3146 return MacGetLeftBorderSize() ;
3149 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3151 return style
& ~wxBORDER_MASK
;
3154 // Find the wxWindowMac at the current mouse position, returning the mouse
3156 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3158 pt
= wxGetMousePosition();
3159 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3163 // Get the current mouse position.
3164 wxPoint
wxGetMousePosition()
3167 wxGetMousePosition(& x
, & y
);
3168 return wxPoint(x
, y
);
3171 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3173 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3175 // copied from wxGTK : CS
3176 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3179 // (a) it's a command event and so is propagated to the parent
3180 // (b) under MSW it can be generated from kbd too
3181 // (c) it uses screen coords (because of (a))
3182 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3184 this->ClientToScreen(event
.GetPosition()));
3185 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3194 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3196 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3198 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3202 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3206 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3210 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3211 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3215 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3217 return eventNotHandledErr
;