1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
16 #include "wx/wxprec.h"
19 #include "wx/window.h"
21 #include "wx/dcclient.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
41 #include "wx/toolbar.h"
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 // TODO EVT_PAINT(wxWindowMac::OnPaint)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
92 #define wxMAC_DEBUG_REDRAW 0
93 #ifndef wxMAC_DEBUG_REDRAW
94 #define wxMAC_DEBUG_REDRAW 0
97 #define wxMAC_USE_THEME_BORDER 1
99 // ---------------------------------------------------------------------------
100 // Utility Routines to move between different coordinate systems
101 // ---------------------------------------------------------------------------
104 * Right now we have the following setup :
105 * a border that is not part of the native control is always outside the
106 * control's border (otherwise we loose all native intelligence, future ways
107 * may be to have a second embedding control responsible for drawing borders
108 * and backgrounds eventually)
109 * so all this border calculations have to be taken into account when calling
110 * native methods or getting native oriented data
111 * so we have three coordinate systems here
112 * wx client coordinates
113 * wx window coordinates (including window frames)
118 // originating from native control
122 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
124 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
127 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
129 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
133 // directed towards native control
136 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
138 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
141 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
143 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
147 // ---------------------------------------------------------------------------
149 // ---------------------------------------------------------------------------
151 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
152 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
154 #if TARGET_API_MAC_OSX
156 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
158 kEventControlVisibilityChanged
= 157
164 static const EventTypeSpec eventList
[] =
166 { kEventClassControl
, kEventControlHit
} ,
167 #if TARGET_API_MAC_OSX
168 { kEventClassControl
, kEventControlDraw
} ,
169 { kEventClassControl
, kEventControlVisibilityChanged
} ,
170 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
171 { kEventClassControl
, kEventControlHiliteChanged
} ,
172 { kEventClassControl
, kEventControlSetFocusPart
} ,
174 { kEventClassService
, kEventServiceGetTypes
},
175 { kEventClassService
, kEventServiceCopy
},
176 { kEventClassService
, kEventServicePaste
},
178 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
179 // { kEventClassControl , kEventControlBoundsChanged } ,
183 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
185 OSStatus result
= eventNotHandledErr
;
187 wxMacCarbonEvent
cEvent( event
) ;
189 ControlRef controlRef
;
190 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
192 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
194 switch( GetEventKind( event
) )
196 #if TARGET_API_MAC_OSX
197 case kEventControlDraw
:
199 RgnHandle updateRgn
= NULL
;
200 RgnHandle allocatedRgn
= NULL
;
201 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
202 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
204 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
208 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
210 allocatedRgn
= NewRgn() ;
211 CopyRgn( updateRgn
, allocatedRgn
) ;
212 // hide the given region by the new region that must be shifted
213 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
214 updateRgn
= allocatedRgn
;
219 // in case we would need a coregraphics compliant background erase first
220 // now usable to track redraws
221 if ( thisWindow
->MacIsUserPane() )
223 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
224 static float color
= 0.5 ;
227 HIViewGetBounds( controlRef
, &bounds
);
228 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
229 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
230 CGContextFillRect( cgContext
, bounds
);
241 #if wxMAC_USE_CORE_GRAPHICS
242 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
243 thisWindow
->MacSetCGContextRef( cgContext
) ;
245 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
247 #if wxMAC_USE_CORE_GRAPHICS
248 thisWindow
->MacSetCGContextRef( NULL
) ;
251 DisposeRgn( allocatedRgn
) ;
254 case kEventControlVisibilityChanged
:
255 thisWindow
->MacVisibilityChanged() ;
257 case kEventControlEnabledStateChanged
:
258 thisWindow
->MacEnabledStateChanged() ;
260 case kEventControlHiliteChanged
:
261 thisWindow
->MacHiliteChanged() ;
263 case kEventControlSetFocusPart
:
265 Boolean focusEverything
= false ;
266 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
267 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
270 if ( controlPart
== kControlFocusNoPart
)
273 if ( thisWindow
->GetCaret() )
275 thisWindow
->GetCaret()->OnKillFocus();
277 #endif // wxUSE_CARET
278 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
279 event
.SetEventObject(thisWindow
);
280 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
284 // panel wants to track the window which was the last to have focus in it
285 wxChildFocusEvent
eventFocus(thisWindow
);
286 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
289 if ( thisWindow
->GetCaret() )
291 thisWindow
->GetCaret()->OnSetFocus();
293 #endif // wxUSE_CARET
295 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
296 event
.SetEventObject(thisWindow
);
297 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
299 if ( thisWindow
->MacIsUserPane() )
304 case kEventControlHit
:
306 result
= thisWindow
->MacControlHit( handler
, event
) ;
315 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
317 OSStatus result
= eventNotHandledErr
;
319 wxMacCarbonEvent
cEvent( event
) ;
321 ControlRef controlRef
;
322 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
323 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
324 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
326 switch( GetEventKind( event
) )
328 case kEventServiceGetTypes
:
332 textCtrl
->GetSelection( &from
, &to
) ;
334 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
336 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
337 if ( textCtrl
->IsEditable() )
338 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
340 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
341 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
343 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
347 CFArrayAppendValue (copyTypes
, typestring
) ;
349 CFArrayAppendValue (pasteTypes
, typestring
) ;
350 CFRelease( typestring
) ;
356 case kEventServiceCopy
:
360 textCtrl
->GetSelection( &from
, &to
) ;
361 wxString val
= textCtrl
->GetValue() ;
362 val
= val
.Mid( from
, to
- from
) ;
363 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
364 verify_noerr( ClearScrap( &scrapRef
) ) ;
365 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
369 case kEventServicePaste
:
372 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
373 Size textSize
, pastedSize
;
374 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
376 char *content
= new char[textSize
] ;
377 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
378 content
[textSize
-1] = 0 ;
380 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
382 textCtrl
->WriteText( wxString( content
) ) ;
393 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
395 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
396 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
397 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
398 OSStatus result
= eventNotHandledErr
;
400 switch ( GetEventClass( event
) )
402 case kEventClassControl
:
403 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
405 case kEventClassService
:
406 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
410 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
414 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
416 #if !TARGET_API_MAC_OSX
418 // ---------------------------------------------------------------------------
419 // UserPane events for non OSX builds
420 // ---------------------------------------------------------------------------
422 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
424 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
425 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
426 win
->MacControlUserPaneDrawProc(part
) ;
429 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
431 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
432 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
433 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
436 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
438 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
439 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
440 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
443 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
445 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
446 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
447 win
->MacControlUserPaneIdleProc() ;
450 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
452 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
453 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
454 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
457 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
459 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
460 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
461 win
->MacControlUserPaneActivateProc(activating
) ;
464 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
466 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
467 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
468 return win
->MacControlUserPaneFocusProc(action
) ;
471 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
473 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
474 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
475 win
->MacControlUserPaneBackgroundProc(info
) ;
478 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
480 RgnHandle rgn
= NewRgn() ;
482 wxMacWindowStateSaver
sv( this ) ;
483 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
484 MacDoRedraw( rgn
, 0 ) ;
488 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
490 return kControlNoPart
;
493 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
495 return kControlNoPart
;
498 void wxWindowMac::MacControlUserPaneIdleProc()
502 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
504 return kControlNoPart
;
507 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
511 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
513 return kControlNoPart
;
516 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
520 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
521 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
522 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
523 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
524 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
525 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
526 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
527 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
531 // ===========================================================================
533 // ===========================================================================
535 #if KEY_wxList_DEPRECATED
536 wxList
wxWinMacControlList(wxKEY_INTEGER
);
538 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
540 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
543 return (wxControl
*)node
->GetData();
546 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
548 // adding NULL ControlRef is (first) surely a result of an error and
549 // (secondly) breaks native event processing
550 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
552 if ( !wxWinMacControlList
.Find((long)inControl
) )
553 wxWinMacControlList
.Append((long)inControl
, control
);
556 void wxRemoveMacControlAssociation(wxWindow
*control
)
558 wxWinMacControlList
.DeleteObject(control
);
562 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
564 static MacControlMap wxWinMacControlList
;
566 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
568 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
570 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
573 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
575 // adding NULL ControlRef is (first) surely a result of an error and
576 // (secondly) breaks native event processing
577 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
579 wxWinMacControlList
[inControl
] = control
;
582 void wxRemoveMacControlAssociation(wxWindow
*control
)
584 // iterate over all the elements in the class
585 MacControlMap::iterator it
;
586 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
588 if ( it
->second
== control
)
590 wxWinMacControlList
.erase(it
);
595 #endif // deprecated wxList
598 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
600 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
602 // we have to setup the brush in the current port and return noErr
603 // or return an error code so that the control manager walks further up the
604 // hierarchy to find a correct background
606 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
608 OSStatus status
= paramErr
;
611 case kControlMsgApplyTextColor
:
613 case kControlMsgSetUpBackground
:
615 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
619 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
622 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
624 // this clipping is only needed for non HIView
626 RgnHandle clip
= NewRgn() ;
629 wx
->MacWindowToRootWindow( &x
,&y
) ;
630 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
631 OffsetRgn( clip
, x
, y
) ;
638 else if ( wx->MacIsUserPane() )
640 // if we don't have a valid brush for such a control, we have to call the
641 // setup of our parent ourselves
642 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
655 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
656 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
660 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
663 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
668 // ----------------------------------------------------------------------------
669 // constructors and such
670 // ----------------------------------------------------------------------------
672 wxWindowMac::wxWindowMac()
677 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
682 const wxString
& name
)
685 Create(parent
, id
, pos
, size
, style
, name
);
688 void wxWindowMac::Init()
692 #if WXWIN_COMPATIBILITY_2_4
693 m_backgroundTransparent
= FALSE
;
696 // as all windows are created with WS_VISIBLE style...
699 m_hScrollBar
= NULL
;
700 m_vScrollBar
= NULL
;
701 m_macBackgroundBrush
= wxNullBrush
;
703 m_macIsUserPane
= TRUE
;
704 #if wxMAC_USE_CORE_GRAPHICS
705 m_cgContextRef
= NULL
;
707 // make sure all proc ptrs are available
709 #if !TARGET_API_MAC_OSX
710 if ( gControlUserPaneDrawUPP
== NULL
)
712 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
713 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
714 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
715 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
716 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
717 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
718 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
719 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
722 if ( wxMacLiveScrollbarActionUPP
== NULL
)
724 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
727 if ( wxMacSetupControlBackgroundUPP
== NULL
)
729 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
732 // we need a valid font for the encodings
733 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
737 wxWindowMac::~wxWindowMac()
741 m_isBeingDeleted
= TRUE
;
745 // deleting a window while it is shown invalidates the region occupied by border or
747 int outerBorder
= MacGetLeftBorderSize() ;
748 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
751 if ( IsShown() && ( outerBorder
> 0 ) )
753 // as the borders are drawn on the parent we have to properly invalidate all these areas
754 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
758 m_peer
->GetRect( &rect
) ;
759 RectRgn( updateInner
, &rect
) ;
760 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
761 RectRgn( updateOuter
, &rect
) ;
762 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
764 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
765 parent
-= GetParent()->GetClientAreaOrigin() ;
766 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
767 CopyRgn( updateOuter
, updateTotal
) ;
769 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
770 DisposeRgn(updateOuter
) ;
771 DisposeRgn(updateInner
) ;
772 DisposeRgn(updateTotal
) ;
776 #ifndef __WXUNIVERSAL__
777 // VS: make sure there's no wxFrame with last focus set to us:
778 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
780 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
783 if ( frame
->GetLastFocus() == this )
785 frame
->SetLastFocus((wxWindow
*)NULL
);
790 #endif // __WXUNIVERSAL__
792 // destroy children before destroying this window itself
795 // wxRemoveMacControlAssociation( this ) ;
796 // If we delete an item, we should initialize the parent panel,
797 // because it could now be invalid.
798 wxWindow
*parent
= GetParent() ;
801 if (parent
->GetDefaultItem() == (wxButton
*) this)
802 parent
->SetDefaultItem(NULL
);
804 if ( m_peer
&& m_peer
->Ok() )
806 // in case the callback might be called during destruction
807 wxRemoveMacControlAssociation( this) ;
808 // we currently are not using this hook
809 // ::SetControlColorProc( *m_peer , NULL ) ;
813 if ( g_MacLastWindow
== this )
815 g_MacLastWindow
= NULL
;
818 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
821 if ( frame
->GetLastFocus() == this )
822 frame
->SetLastFocus( NULL
) ;
825 // delete our drop target if we've got one
826 #if wxUSE_DRAG_AND_DROP
827 if ( m_dropTarget
!= NULL
)
832 #endif // wxUSE_DRAG_AND_DROP
836 WXWidget
wxWindowMac::GetHandle() const
838 return (WXWidget
) m_peer
->GetControlRef() ;
842 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
844 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
845 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
846 GetEventTypeCount(eventList
), eventList
, this,
847 (EventHandlerRef
*)&m_macControlEventHandler
);
852 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
856 const wxString
& name
)
858 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
860 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
863 m_windowVariant
= parent
->GetWindowVariant() ;
865 if ( m_macIsUserPane
)
867 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
870 | kControlSupportsEmbedding
871 // | kControlSupportsLiveFeedback
872 // | kControlHasSpecialBackground
873 // | kControlSupportsCalcBestRect
874 // | kControlHandlesTracking
875 | kControlSupportsFocus
876 // | kControlWantsActivate
877 // | kControlWantsIdle
880 m_peer
= new wxMacControl() ;
881 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
884 MacPostControlCreate(pos
,size
) ;
885 #if !TARGET_API_MAC_OSX
886 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
887 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
888 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
889 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
890 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
891 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
892 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
893 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
896 #ifndef __WXUNIVERSAL__
897 // Don't give scrollbars to wxControls unless they ask for them
898 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
899 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
901 MacCreateScrollBars( style
) ;
905 wxWindowCreateEvent
event(this);
906 GetEventHandler()->AddPendingEvent(event
);
911 void wxWindowMac::MacChildAdded()
915 m_vScrollBar
->Raise() ;
919 m_hScrollBar
->Raise() ;
924 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
926 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
928 m_peer
->SetReference( (long) this ) ;
929 GetParent()->AddChild(this);
931 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
933 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
934 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
935 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
936 GetParent()->MacChildAdded() ;
938 // adjust font, controlsize etc
939 DoSetWindowVariant( m_windowVariant
) ;
941 #if !TARGET_API_MAC_OSX
942 // eventually we can fix some clipping issues be reactivating this hook
943 //if ( m_macIsUserPane )
944 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
946 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
948 if (!m_macIsUserPane
)
950 SetInitialBestSize(size
);
953 SetCursor( *wxSTANDARD_CURSOR
) ;
956 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
958 // Don't assert, in case we set the window variant before
959 // the window is created
960 // wxASSERT( m_peer->Ok() ) ;
962 m_windowVariant
= variant
;
964 if (m_peer
== NULL
|| !m_peer
->Ok())
968 ThemeFontID themeFont
= kThemeSystemFont
;
970 // we will get that from the settings later
971 // and make this NORMAL later, but first
972 // we have a few calculations that we must fix
976 case wxWINDOW_VARIANT_NORMAL
:
977 size
= kControlSizeNormal
;
978 themeFont
= kThemeSystemFont
;
980 case wxWINDOW_VARIANT_SMALL
:
981 size
= kControlSizeSmall
;
982 themeFont
= kThemeSmallSystemFont
;
984 case wxWINDOW_VARIANT_MINI
:
985 if (UMAGetSystemVersion() >= 0x1030 )
987 // not always defined in the headers
993 size
= kControlSizeSmall
;
994 themeFont
= kThemeSmallSystemFont
;
997 case wxWINDOW_VARIANT_LARGE
:
998 size
= kControlSizeLarge
;
999 themeFont
= kThemeSystemFont
;
1002 wxFAIL_MSG(_T("unexpected window variant"));
1005 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
1008 font
.MacCreateThemeFont( themeFont
) ;
1012 void wxWindowMac::MacUpdateControlFont()
1014 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1018 bool wxWindowMac::SetFont(const wxFont
& font
)
1020 bool retval
= wxWindowBase::SetFont( font
) ;
1022 MacUpdateControlFont() ;
1027 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1029 if ( !wxWindowBase::SetForegroundColour(col
) )
1032 MacUpdateControlFont() ;
1037 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1039 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1043 wxColour
newCol(GetBackgroundColour());
1044 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1046 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1048 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1050 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1054 brush
.SetColour( newCol
) ;
1056 MacSetBackgroundBrush( brush
) ;
1058 MacUpdateControlFont() ;
1063 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1065 m_macBackgroundBrush
= brush
;
1066 m_peer
->SetBackground( brush
) ;
1069 bool wxWindowMac::MacCanFocus() const
1071 // there is currently no way to determine whether the window is running in full keyboard
1072 // access mode, therefore we cannot rely on these features, yet the only other way would be
1073 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1074 // in event handlers...
1075 UInt32 features
= 0 ;
1076 m_peer
->GetFeatures( & features
) ;
1077 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1081 void wxWindowMac::SetFocus()
1083 if ( AcceptsFocus() )
1086 wxWindow
* former
= FindFocus() ;
1087 if ( former
== this )
1090 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1091 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1092 // leave in case of an error
1093 if ( err
== errCouldntSetFocus
)
1096 #if !TARGET_API_MAC_OSX
1097 // emulate carbon events when running under carbonlib where they are not natively available
1100 EventRef evRef
= NULL
;
1101 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1104 wxMacCarbonEvent
cEvent( evRef
) ;
1105 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1106 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1108 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1109 ReleaseEvent(evRef
) ;
1111 // send new focus event
1113 EventRef evRef
= NULL
;
1114 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1117 wxMacCarbonEvent
cEvent( evRef
) ;
1118 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1119 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1121 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1122 ReleaseEvent(evRef
) ;
1129 void wxWindowMac::DoCaptureMouse()
1131 wxTheApp
->s_captureWindow
= this ;
1134 wxWindow
* wxWindowBase::GetCapture()
1136 return wxTheApp
->s_captureWindow
;
1139 void wxWindowMac::DoReleaseMouse()
1141 wxTheApp
->s_captureWindow
= NULL
;
1144 #if wxUSE_DRAG_AND_DROP
1146 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1148 if ( m_dropTarget
!= 0 ) {
1149 delete m_dropTarget
;
1152 m_dropTarget
= pDropTarget
;
1153 if ( m_dropTarget
!= 0 )
1161 // Old style file-manager drag&drop
1162 void wxWindowMac::DragAcceptFiles(bool accept
)
1167 // Returns the size of the native control. In the case of the toplevel window
1168 // this is the content area root control
1170 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1171 int& w
, int& h
) const
1174 m_peer
->GetRect( &bounds
) ;
1179 w
= bounds
.right
- bounds
.left
;
1180 h
= bounds
.bottom
- bounds
.top
;
1183 // From a wx position / size calculate the appropriate size of the native control
1185 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1188 int& w
, int& h
, bool adjustOrigin
) const
1190 // the desired size, minus the border pixels gives the correct size of the control
1194 // todo the default calls may be used as soon as PostCreateControl Is moved here
1195 w
= size
.x
; // WidthDefault( size.x );
1196 h
= size
.y
; // HeightDefault( size.y ) ;
1197 #if !TARGET_API_MAC_OSX
1198 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1201 x
+= MacGetLeftBorderSize() ;
1202 y
+= MacGetTopBorderSize() ;
1203 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1204 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1207 AdjustForParentClientOrigin( x
, y
) ;
1208 #if TARGET_API_MAC_OSX
1209 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1210 if ( ! GetParent()->IsTopLevel() )
1212 x
-= GetParent()->MacGetLeftBorderSize() ;
1213 y
-= GetParent()->MacGetTopBorderSize() ;
1219 // Get window size (not client size)
1220 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1222 // take the size of the control and add the borders that have to be drawn outside
1223 int x1
, y1
, w1
, h1
;
1225 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1227 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1228 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1234 // get the position of the bounds of this window in client coordinates of its parent
1235 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1237 int x1
, y1
, w1
,h1
;
1238 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1239 x1
-= MacGetLeftBorderSize() ;
1240 y1
-= MacGetTopBorderSize() ;
1242 #if !TARGET_API_MAC_OSX
1243 if ( !GetParent()->IsTopLevel() )
1246 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1251 if ( !IsTopLevel() )
1253 wxWindow
*parent
= GetParent();
1256 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1257 x1
+= parent
->MacGetLeftBorderSize() ;
1258 y1
+= parent
->MacGetTopBorderSize() ;
1259 // and now to client coordinates
1260 wxPoint
pt(parent
->GetClientAreaOrigin());
1269 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1271 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1273 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1276 Point localwhere
= {0,0} ;
1278 if(x
) localwhere
.h
= * x
;
1279 if(y
) localwhere
.v
= * y
;
1281 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1282 if(x
) *x
= localwhere
.h
;
1283 if(y
) *y
= localwhere
.v
;
1286 MacRootWindowToWindow( x
, y
) ;
1288 wxPoint origin
= GetClientAreaOrigin() ;
1289 if(x
) *x
-= origin
.x
;
1290 if(y
) *y
-= origin
.y
;
1293 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1295 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1296 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1298 wxPoint origin
= GetClientAreaOrigin() ;
1299 if(x
) *x
+= origin
.x
;
1300 if(y
) *y
+= origin
.y
;
1302 MacWindowToRootWindow( x
, y
) ;
1305 Point localwhere
= { 0,0 };
1306 if(x
) localwhere
.h
= * x
;
1307 if(y
) localwhere
.v
= * y
;
1308 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1309 if(x
) *x
= localwhere
.h
;
1310 if(y
) *y
= localwhere
.v
;
1314 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1316 wxPoint origin
= GetClientAreaOrigin() ;
1317 if(x
) *x
+= origin
.x
;
1318 if(y
) *y
+= origin
.y
;
1320 MacWindowToRootWindow( x
, y
) ;
1323 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1325 MacRootWindowToWindow( x
, y
) ;
1327 wxPoint origin
= GetClientAreaOrigin() ;
1328 if(x
) *x
-= origin
.x
;
1329 if(y
) *y
-= origin
.y
;
1332 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1334 #if TARGET_API_MAC_OSX
1336 if ( x
) pt
.x
= *x
;
1337 if ( y
) pt
.y
= *y
;
1339 if ( !IsTopLevel() )
1341 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1344 pt
.x
-= MacGetLeftBorderSize() ;
1345 pt
.y
-= MacGetTopBorderSize() ;
1346 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1350 if ( x
) *x
= (int) pt
.x
;
1351 if ( y
) *y
= (int) pt
.y
;
1353 if ( !IsTopLevel() )
1356 m_peer
->GetRect( &bounds
) ;
1357 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1358 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1363 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1368 MacWindowToRootWindow( &x1
, &y1
) ;
1373 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1375 #if TARGET_API_MAC_OSX
1377 if ( x
) pt
.x
= *x
;
1378 if ( y
) pt
.y
= *y
;
1380 if ( !IsTopLevel() )
1382 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1383 pt
.x
+= MacGetLeftBorderSize() ;
1384 pt
.y
+= MacGetTopBorderSize() ;
1387 if ( x
) *x
= (int) pt
.x
;
1388 if ( y
) *y
= (int) pt
.y
;
1390 if ( !IsTopLevel() )
1393 m_peer
->GetRect( &bounds
) ;
1394 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1395 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1400 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1405 MacRootWindowToWindow( &x1
, &y1
) ;
1410 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1412 RgnHandle rgn
= NewRgn() ;
1414 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1416 GetRegionBounds( rgn
, &content
) ;
1420 m_peer
->GetRect( &content
) ;
1424 m_peer
->GetRect( &structure
) ;
1425 #if !TARGET_API_MAC_OSX
1426 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1428 left
= content
.left
- structure
.left
;
1429 top
= content
.top
- structure
.top
;
1430 right
= structure
.right
- content
.right
;
1431 bottom
= structure
.bottom
- content
.bottom
;
1434 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1436 wxSize sizeTotal
= size
;
1438 RgnHandle rgn
= NewRgn() ;
1442 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1444 GetRegionBounds( rgn
, &content
) ;
1448 m_peer
->GetRect( &content
) ;
1452 m_peer
->GetRect( &structure
) ;
1453 #if !TARGET_API_MAC_OSX
1454 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1457 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1458 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1460 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1461 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1467 // Get size *available for subwindows* i.e. excluding menu bar etc.
1468 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1472 RgnHandle rgn
= NewRgn() ;
1474 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1476 GetRegionBounds( rgn
, &content
) ;
1480 m_peer
->GetRect( &content
) ;
1483 #if !TARGET_API_MAC_OSX
1485 m_peer
->GetRect( &structure
) ;
1486 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1488 ww
= content
.right
- content
.left
;
1489 hh
= content
.bottom
- content
.top
;
1491 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1492 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1495 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1501 GetSize( &w , &h ) ;
1503 MacClientToRootWindow( &x1 , &y1 ) ;
1504 MacClientToRootWindow( &w , &h ) ;
1506 wxWindowMac *iter = (wxWindowMac*)this ;
1508 int totW = 10000 , totH = 10000;
1511 if ( iter->IsTopLevel() )
1513 iter->GetSize( &totW , &totH ) ;
1517 iter = iter->GetParent() ;
1520 if (m_hScrollBar && m_hScrollBar->IsShown() )
1522 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1528 if (m_vScrollBar && m_vScrollBar->IsShown() )
1530 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1538 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1540 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1542 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1544 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1551 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1553 if (m_cursor
== cursor
)
1556 if (wxNullCursor
== cursor
)
1558 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1563 if ( ! wxWindowBase::SetCursor( cursor
) )
1567 wxASSERT_MSG( m_cursor
.Ok(),
1568 wxT("cursor must be valid after call to the base version"));
1571 wxWindowMac
*mouseWin
= 0 ;
1573 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1575 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1577 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1578 // position, use it...
1582 ControlPartCode part
;
1583 ControlRef control
;
1584 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1586 mouseWin
= wxFindControlFromMacControl( control
) ;
1589 QDSwapPort( savePort
, NULL
) ;
1592 if ( mouseWin
== this && !wxIsBusy() )
1594 m_cursor
.MacInstall() ;
1601 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1603 menu
->SetInvokingWindow(this);
1606 if ( x
== -1 && y
== -1 )
1608 wxPoint mouse
= wxGetMousePosition();
1609 x
= mouse
.x
; y
= mouse
.y
;
1613 ClientToScreen( &x
, &y
) ;
1616 menu
->MacBeforeDisplay( true ) ;
1617 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1618 if ( HiWord(menuResult
) != 0 )
1621 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1622 wxMenuItem
* item
= NULL
;
1624 item
= menu
->FindItem(id
, &realmenu
) ;
1625 if (item
->IsCheckable())
1627 item
->Check( !item
->IsChecked() ) ;
1629 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1631 menu
->MacAfterDisplay( true ) ;
1633 menu
->SetInvokingWindow(NULL
);
1639 // ----------------------------------------------------------------------------
1641 // ----------------------------------------------------------------------------
1645 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1647 wxWindowBase::DoSetToolTip(tooltip
);
1650 m_tooltip
->SetWindow(this);
1653 #endif // wxUSE_TOOLTIPS
1655 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1657 // this is never called for a toplevel window, so we know we have a parent
1658 int former_x
, former_y
, former_w
, former_h
;
1660 // Get true coordinates of former position
1661 DoGetPosition( &former_x
, &former_y
) ;
1662 DoGetSize( &former_w
, &former_h
) ;
1664 wxWindow
*parent
= GetParent();
1667 wxPoint
pt(parent
->GetClientAreaOrigin());
1672 int actualWidth
= width
;
1673 int actualHeight
= height
;
1677 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1678 actualWidth
= m_minWidth
;
1679 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1680 actualHeight
= m_minHeight
;
1681 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1682 actualWidth
= m_maxWidth
;
1683 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1684 actualHeight
= m_maxHeight
;
1686 bool doMove
= false ;
1687 bool doResize
= false ;
1689 if ( actualX
!= former_x
|| actualY
!= former_y
)
1693 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1698 if ( doMove
|| doResize
)
1700 // we don't adjust twice for the origin
1701 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1702 bool vis
= m_peer
->IsVisible();
1704 int outerBorder
= MacGetLeftBorderSize() ;
1705 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1708 if ( vis
&& ( outerBorder
> 0 ) )
1710 // as the borders are drawn on the parent we have to properly invalidate all these areas
1711 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1715 m_peer
->GetRect( &rect
) ;
1716 RectRgn( updateInner
, &rect
) ;
1717 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1718 RectRgn( updateOuter
, &rect
) ;
1719 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1720 wxPoint
parent(0,0);
1721 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1722 parent
-= GetParent()->GetClientAreaOrigin() ;
1723 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1724 CopyRgn( updateOuter
, updateTotal
) ;
1727 RectRgn( updateInner
, &rect
) ;
1728 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1729 RectRgn( updateOuter
, &rect
) ;
1730 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1732 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1733 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1735 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1736 DisposeRgn(updateOuter
) ;
1737 DisposeRgn(updateInner
) ;
1738 DisposeRgn(updateTotal
) ;
1741 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1743 m_peer
->SetVisibility( false , true ) ;
1745 m_peer
->SetRect( &r
) ;
1747 m_peer
->SetVisibility( true , true ) ;
1749 MacRepositionScrollBars() ;
1752 wxPoint
point(actualX
,actualY
);
1753 wxMoveEvent
event(point
, m_windowId
);
1754 event
.SetEventObject(this);
1755 GetEventHandler()->ProcessEvent(event
) ;
1759 MacRepositionScrollBars() ;
1760 wxSize
size(actualWidth
, actualHeight
);
1761 wxSizeEvent
event(size
, m_windowId
);
1762 event
.SetEventObject(this);
1763 GetEventHandler()->ProcessEvent(event
);
1769 wxSize
wxWindowMac::DoGetBestSize() const
1771 if ( m_macIsUserPane
|| IsTopLevel() )
1772 return wxWindowBase::DoGetBestSize() ;
1774 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1775 int bestWidth
, bestHeight
;
1776 m_peer
->GetBestRect( &bestsize
) ;
1778 if ( EmptyRect( &bestsize
) )
1780 bestsize
.left
= bestsize
.top
= 0 ;
1781 bestsize
.right
= 16 ;
1782 bestsize
.bottom
= 16 ;
1783 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1785 bestsize
.bottom
= 16 ;
1788 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1790 bestsize
.bottom
= 24 ;
1792 #endif // wxUSE_SPINBTN
1795 // return wxWindowBase::DoGetBestSize() ;
1799 bestWidth
= bestsize
.right
- bestsize
.left
;
1800 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1801 if ( bestHeight
< 10 )
1804 return wxSize(bestWidth
, bestHeight
);
1808 // set the size of the window: if the dimensions are positive, just use them,
1809 // but if any of them is equal to -1, it means that we must find the value for
1810 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1811 // which case -1 is a valid value for x and y)
1813 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1814 // the width/height to best suit our contents, otherwise we reuse the current
1816 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1818 // get the current size and position...
1819 int currentX
, currentY
;
1820 GetPosition(¤tX
, ¤tY
);
1822 int currentW
,currentH
;
1823 GetSize(¤tW
, ¤tH
);
1825 // ... and don't do anything (avoiding flicker) if it's already ok
1826 if ( x
== currentX
&& y
== currentY
&&
1827 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1830 MacRepositionScrollBars() ; // we might have a real position shift
1834 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1836 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1839 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1841 wxSize
size(-1, -1);
1844 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1846 size
= DoGetBestSize();
1851 // just take the current one
1858 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1862 size
= DoGetBestSize();
1864 //else: already called DoGetBestSize() above
1870 // just take the current one
1875 DoMoveWindow(x
, y
, width
, height
);
1879 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1881 RgnHandle rgn
= NewRgn() ;
1883 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1884 GetRegionBounds( rgn
, &content
) ;
1886 #if !TARGET_API_MAC_OSX
1887 // if the content rgn is empty / not supported
1888 // don't attempt to correct the coordinates to wxWindow relative ones
1889 if (!::EmptyRect( &content
) )
1892 m_peer
->GetRect( &structure
) ;
1893 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1897 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1900 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1902 if ( clientheight
!= -1 || clientheight
!= -1 )
1904 int currentclientwidth
, currentclientheight
;
1905 int currentwidth
, currentheight
;
1907 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1908 GetSize( ¤twidth
, ¤theight
) ;
1910 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1911 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1915 void wxWindowMac::SetTitle(const wxString
& title
)
1917 m_label
= wxStripMenuCodes(title
) ;
1919 if ( m_peer
&& m_peer
->Ok() )
1921 m_peer
->SetTitle( m_label
) ;
1926 wxString
wxWindowMac::GetTitle() const
1931 bool wxWindowMac::Show(bool show
)
1933 if ( !wxWindowBase::Show(show
) )
1936 // TODO use visibilityChanged Carbon Event for OSX
1939 bool former
= MacIsReallyShown() ;
1941 m_peer
->SetVisibility( show
, true ) ;
1942 if ( former
!= MacIsReallyShown() )
1943 MacPropagateVisibilityChanged() ;
1948 bool wxWindowMac::Enable(bool enable
)
1950 wxASSERT( m_peer
->Ok() ) ;
1951 if ( !wxWindowBase::Enable(enable
) )
1954 bool former
= MacIsReallyEnabled() ;
1955 m_peer
->Enable( enable
) ;
1957 if ( former
!= MacIsReallyEnabled() )
1958 MacPropagateEnabledStateChanged() ;
1963 // status change propagations (will be not necessary for OSX later )
1966 void wxWindowMac::MacPropagateVisibilityChanged()
1968 #if !TARGET_API_MAC_OSX
1969 MacVisibilityChanged() ;
1971 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1974 wxWindowMac
*child
= node
->GetData();
1975 if ( child
->IsShown() )
1976 child
->MacPropagateVisibilityChanged( ) ;
1977 node
= node
->GetNext();
1982 void wxWindowMac::MacPropagateEnabledStateChanged( )
1984 #if !TARGET_API_MAC_OSX
1985 MacEnabledStateChanged() ;
1987 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1990 wxWindowMac
*child
= node
->GetData();
1991 if ( child
->IsEnabled() )
1992 child
->MacPropagateEnabledStateChanged() ;
1993 node
= node
->GetNext();
1998 void wxWindowMac::MacPropagateHiliteChanged( )
2000 #if !TARGET_API_MAC_OSX
2001 MacHiliteChanged() ;
2003 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2006 wxWindowMac
*child
= node
->GetData();
2007 // if ( child->IsEnabled() )
2008 child
->MacPropagateHiliteChanged() ;
2009 node
= node
->GetNext();
2015 // status change notifications
2018 void wxWindowMac::MacVisibilityChanged()
2022 void wxWindowMac::MacHiliteChanged()
2026 void wxWindowMac::MacEnabledStateChanged()
2031 // status queries on the inherited window's state
2034 bool wxWindowMac::MacIsReallyShown()
2036 // only under OSX the visibility of the TLW is taken into account
2037 if ( m_isBeingDeleted
)
2040 #if TARGET_API_MAC_OSX
2041 if ( m_peer
&& m_peer
->Ok() )
2042 return m_peer
->IsVisible();
2044 wxWindow
* win
= this ;
2045 while( win
->IsShown() )
2047 if ( win
->IsTopLevel() )
2050 win
= win
->GetParent() ;
2058 bool wxWindowMac::MacIsReallyEnabled()
2060 return m_peer
->IsEnabled() ;
2063 bool wxWindowMac::MacIsReallyHilited()
2065 return m_peer
->IsActive();
2068 void wxWindowMac::MacFlashInvalidAreas()
2070 #if TARGET_API_MAC_OSX
2071 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2079 int wxWindowMac::GetCharHeight() const
2081 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2082 return dc
.GetCharHeight() ;
2085 int wxWindowMac::GetCharWidth() const
2087 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2088 return dc
.GetCharWidth() ;
2091 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2092 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2094 const wxFont
*fontToUse
= theFont
;
2096 fontToUse
= &m_font
;
2098 wxClientDC
dc( (wxWindowMac
*) this ) ;
2100 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2101 if ( externalLeading
)
2102 *externalLeading
= le
;
2112 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2113 * we always intersect with the entire window, not only with the client area
2116 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2118 if ( m_peer
== NULL
)
2121 #if TARGET_API_MAC_OSX
2123 m_peer
->SetNeedsDisplay( true ) ;
2126 RgnHandle update
= NewRgn() ;
2127 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2128 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2129 wxPoint origin
= GetClientAreaOrigin() ;
2130 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2131 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2133 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2134 m_peer
->SetNeedsDisplay( true , update
) ;
2135 DisposeRgn( update
) ;
2139 RgnHandle updateRgn = NewRgn() ;
2142 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2146 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2147 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2149 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2150 DisposeRgn(updateRgn) ;
2152 if ( m_peer
->IsVisible())
2154 m_peer
->SetVisibility( false , false ) ;
2155 m_peer
->SetVisibility( true , true ) ;
2158 if ( MacGetTopLevelWindow() == NULL )
2161 if ( !m_peer->IsVisible())
2164 wxPoint client = GetClientAreaOrigin();
2167 int x2 = m_width - client.x;
2168 int y2 = m_height - client.y;
2170 if (IsKindOf( CLASSINFO(wxButton)))
2172 // buttons have an "aura"
2179 Rect clientrect = { y1, x1, y2, x2 };
2183 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2184 SectRect( &clientrect , &r , &clientrect ) ;
2187 if ( !EmptyRect( &clientrect ) )
2189 int top = 0 , left = 0 ;
2191 MacClientToRootWindow( &left , &top ) ;
2192 OffsetRect( &clientrect , left , top ) ;
2194 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2200 void wxWindowMac::Freeze()
2202 #if TARGET_API_MAC_OSX
2203 if ( !m_frozenness
++ )
2205 if ( m_peer
&& m_peer
->Ok() )
2206 m_peer
->SetDrawingEnabled( false ) ;
2212 void wxWindowMac::Thaw()
2214 #if TARGET_API_MAC_OSX
2215 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2217 if ( !--m_frozenness
)
2219 if ( m_peer
&& m_peer
->Ok() )
2221 m_peer
->SetDrawingEnabled( true ) ;
2222 m_peer
->InvalidateWithChildren() ;
2229 void wxWindowMac::OnPaint(wxPaintEvent& event)
2231 // why don't we skip that here ?
2235 wxWindowMac
*wxGetActiveWindow()
2237 // actually this is a windows-only concept
2241 // Coordinates relative to the window
2242 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2244 // We really don't move the mouse programmatically under Mac.
2247 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2249 #if TARGET_API_MAC_OSX
2250 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2257 event
.GetDC()->Clear() ;
2261 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2266 int wxWindowMac::GetScrollPos(int orient
) const
2268 if ( orient
== wxHORIZONTAL
)
2271 return m_hScrollBar
->GetThumbPosition() ;
2276 return m_vScrollBar
->GetThumbPosition() ;
2281 // This now returns the whole range, not just the number
2282 // of positions that we can scroll.
2283 int wxWindowMac::GetScrollRange(int orient
) const
2285 if ( orient
== wxHORIZONTAL
)
2288 return m_hScrollBar
->GetRange() ;
2293 return m_vScrollBar
->GetRange() ;
2298 int wxWindowMac::GetScrollThumb(int orient
) const
2300 if ( orient
== wxHORIZONTAL
)
2303 return m_hScrollBar
->GetThumbSize() ;
2308 return m_vScrollBar
->GetThumbSize() ;
2313 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2315 if ( orient
== wxHORIZONTAL
)
2318 m_hScrollBar
->SetThumbPosition( pos
) ;
2323 m_vScrollBar
->SetThumbPosition( pos
) ;
2327 void wxWindowMac::MacPaintBorders( int left
, int top
)
2333 m_peer
->GetRect( &rect
) ;
2334 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2336 if ( !IsTopLevel() )
2338 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2342 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2344 rect
.right
+= pt
.x
;
2346 rect
.bottom
+= pt
.y
;
2350 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2354 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2355 InsetRect( &srect
, border
, border
);
2356 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2358 else if (HasFlag(wxSIMPLE_BORDER
))
2362 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2363 InsetRect( &srect
, border
, border
);
2364 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2368 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2370 if ( child
== m_hScrollBar
)
2371 m_hScrollBar
= NULL
;
2372 if ( child
== m_vScrollBar
)
2373 m_vScrollBar
= NULL
;
2375 wxWindowBase::RemoveChild( child
) ;
2378 // New function that will replace some of the above.
2379 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2380 int range
, bool refresh
)
2382 if ( orient
== wxHORIZONTAL
)
2386 if ( range
== 0 || thumbVisible
>= range
)
2388 if ( m_hScrollBar
->IsShown() )
2389 m_hScrollBar
->Show(false) ;
2393 if ( !m_hScrollBar
->IsShown() )
2394 m_hScrollBar
->Show(true) ;
2396 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2403 if ( range
== 0 || thumbVisible
>= range
)
2405 if ( m_vScrollBar
->IsShown() )
2406 m_vScrollBar
->Show(false) ;
2410 if ( !m_vScrollBar
->IsShown() )
2411 m_vScrollBar
->Show(true) ;
2413 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2416 MacRepositionScrollBars() ;
2419 // Does a physical scroll
2420 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2422 if( dx
== 0 && dy
==0 )
2428 int width
, height
;
2429 GetClientSize( &width
, &height
) ;
2430 #if TARGET_API_MAC_OSX
2431 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2432 // area is scrolled, this does not occur if width and height are 2 pixels less,
2433 // TODO write optimal workaround
2434 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2437 scrollrect
.Intersect( *rect
) ;
2439 if ( m_peer
->GetNeedsDisplay() )
2441 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2442 // either immediate redraw or full invalidate
2444 // is the better overall solution, as it does not slow down scrolling
2445 m_peer
->SetNeedsDisplay( true ) ;
2447 // this would be the preferred version for fast drawing controls
2448 if( UMAGetSystemVersion() < 0x1030 )
2451 HIViewRender(m_peer
->GetControlRef()) ;
2454 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2455 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2456 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2463 RgnHandle updateRgn
= NewRgn() ;
2466 wxClientDC
dc(this) ;
2467 wxMacPortSetter
helper(&dc
) ;
2469 m_peer
->GetRect( &scrollrect
) ;
2470 scrollrect
.top
+= MacGetTopBorderSize() ;
2471 scrollrect
.left
+= MacGetLeftBorderSize() ;
2472 scrollrect
.bottom
= scrollrect
.top
+ height
;
2473 scrollrect
.right
= scrollrect
.left
+ width
;
2477 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2478 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2479 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2481 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2483 // now scroll the former update region as well and add the new update region
2485 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2486 RgnHandle formerUpdateRgn
= NewRgn() ;
2487 RgnHandle scrollRgn
= NewRgn() ;
2488 RectRgn( scrollRgn
, &scrollrect
) ;
2489 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2491 LocalToGlobal( &pt
) ;
2492 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2493 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2494 if ( !EmptyRgn( formerUpdateRgn
) )
2496 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2497 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2498 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2500 InvalWindowRgn(rootWindow
, updateRgn
) ;
2501 DisposeRgn( updateRgn
) ;
2502 DisposeRgn( formerUpdateRgn
) ;
2503 DisposeRgn( scrollRgn
) ;
2508 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2510 wxWindowMac
*child
= node
->GetData();
2511 if (child
== m_vScrollBar
) continue;
2512 if (child
== m_hScrollBar
) continue;
2513 if (child
->IsTopLevel()) continue;
2516 child
->GetPosition( &x
, &y
);
2518 child
->GetSize( &w
, &h
);
2522 if (rect
->Intersects(rc
))
2523 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2527 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2532 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2534 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2536 wxScrollWinEvent wevent
;
2537 wevent
.SetPosition(event
.GetPosition());
2538 wevent
.SetOrientation(event
.GetOrientation());
2539 wevent
.SetEventObject(this);
2541 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2542 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2543 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2544 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2545 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2546 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2547 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2548 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2549 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2550 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2551 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2552 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2553 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2554 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2555 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2556 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2558 GetEventHandler()->ProcessEvent(wevent
);
2562 // Get the window with the focus
2563 wxWindowMac
*wxWindowBase::DoFindFocus()
2565 ControlRef control
;
2566 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2567 return wxFindControlFromMacControl( control
) ;
2570 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2572 // panel wants to track the window which was the last to have focus in it,
2573 // so we want to set ourselves as the window which last had focus
2575 // notice that it's also important to do it upwards the tree becaus
2576 // otherwise when the top level panel gets focus, it won't set it back to
2577 // us, but to some other sibling
2579 // CS:don't know if this is still needed:
2580 //wxChildFocusEvent eventFocus(this);
2581 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2583 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2585 wxMacWindowStateSaver
sv( this ) ;
2590 MacWindowToRootWindow( &x
, &y
) ;
2591 GetSize( &w
, &h
) ;
2592 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2594 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2595 DrawThemeFocusRect( &rect
, true ) ;
2598 DrawThemeFocusRect( &rect
, false ) ;
2600 // as this erases part of the frame we have to redraw borders
2601 // and because our z-ordering is not always correct (staticboxes)
2602 // we have to invalidate things, we cannot simple redraw
2603 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2604 RectRgn( updateInner
, &rect
) ;
2605 InsetRect( &rect
, -4 , -4 ) ;
2606 RectRgn( updateOuter
, &rect
) ;
2607 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2608 wxPoint
parent(0,0);
2609 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2610 parent
-= GetParent()->GetClientAreaOrigin() ;
2611 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2612 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2613 DisposeRgn(updateOuter
) ;
2614 DisposeRgn(updateInner
) ;
2621 void wxWindowMac::OnInternalIdle()
2623 // This calls the UI-update mechanism (querying windows for
2624 // menu/toolbar/control state information)
2625 if (wxUpdateUIEvent::CanUpdate(this))
2626 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2629 // Raise the window to the top of the Z order
2630 void wxWindowMac::Raise()
2632 m_peer
->SetZOrder( true , NULL
) ;
2635 // Lower the window to the bottom of the Z order
2636 void wxWindowMac::Lower()
2638 m_peer
->SetZOrder( false , NULL
) ;
2642 // static wxWindow *gs_lastWhich = NULL;
2644 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2646 // first trigger a set cursor event
2648 wxPoint clientorigin
= GetClientAreaOrigin() ;
2649 wxSize clientsize
= GetClientSize() ;
2651 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2653 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2655 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2656 if ( processedEvtSetCursor
&& event
.HasCursor() )
2658 cursor
= event
.GetCursor() ;
2663 // the test for processedEvtSetCursor is here to prevent using m_cursor
2664 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2665 // it - this is a way to say that our cursor shouldn't be used for this
2667 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2677 cursor
= *wxSTANDARD_CURSOR
;
2681 cursor
.MacInstall() ;
2683 return cursor
.Ok() ;
2686 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2690 return m_tooltip
->GetTip() ;
2692 return wxEmptyString
;
2695 void wxWindowMac::Update()
2697 #if TARGET_API_MAC_OSX
2699 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2700 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2702 // for composited windows this also triggers a redraw of all
2703 // invalid views in the window
2704 if( UMAGetSystemVersion() >= 0x1030 )
2705 HIWindowFlush(window
) ;
2709 // the only way to trigger the redrawing on earlier systems is to call
2712 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2713 UInt32 currentEventClass
= 0 ;
2714 UInt32 currentEventKind
= 0 ;
2715 if ( currentEvent
!= NULL
)
2717 currentEventClass
= ::GetEventClass( currentEvent
) ;
2718 currentEventKind
= ::GetEventKind( currentEvent
) ;
2720 if ( currentEventClass
!= kEventClassMenu
)
2722 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2725 OSStatus status
= noErr
;
2726 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2729 m_peer
->SetNeedsDisplay( true ) ;
2732 ::Draw1Control( m_peer
->GetControlRef() ) ;
2736 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2738 wxTopLevelWindowMac
* win
= NULL
;
2739 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2742 win
= wxFindWinFromMacWindow( window
) ;
2746 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2748 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2749 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2750 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2751 // to add focus borders everywhere
2754 RgnHandle visRgn
= NewRgn() ;
2755 RgnHandle tempRgn
= NewRgn() ;
2756 if ( !m_isBeingDeleted
&& m_peer
->IsVisible())
2758 m_peer
->GetRect( &r
) ;
2759 r
.left
-= MacGetLeftBorderSize() ;
2760 r
.top
-= MacGetTopBorderSize() ;
2761 r
.bottom
+= MacGetBottomBorderSize() ;
2762 r
.right
+= MacGetRightBorderSize() ;
2764 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2766 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2767 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2776 if ( includeOuterStructures
)
2777 InsetRect( &r
, -4 , -4 ) ;
2778 RectRgn( visRgn
, &r
) ;
2780 if ( !IsTopLevel() )
2782 wxWindow
* child
= this ;
2783 wxWindow
* parent
= child
->GetParent() ;
2788 // we have to find a better clipping algorithm here, in order not to clip things
2789 // positioned like status and toolbar
2790 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2792 size
= parent
->GetSize() ;
2797 size
= parent
->GetClientSize() ;
2798 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2802 parent
->MacWindowToRootWindow( &x
, &y
) ;
2803 MacRootWindowToWindow( &x
, &y
) ;
2805 if ( !includeOuterStructures
|| (
2806 parent
->MacClipChildren() ||
2807 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2810 SetRectRgn( tempRgn
,
2811 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2812 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2813 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2815 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2817 if ( parent
->IsTopLevel() )
2820 parent
= child
->GetParent() ;
2825 wxRegion vis
= visRgn
;
2826 DisposeRgn( visRgn
) ;
2827 DisposeRgn( tempRgn
) ;
2832 This function must not change the updatergn !
2834 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2836 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2837 bool handled
= false ;
2839 GetRegionBounds( updatergn
, &updatebounds
) ;
2841 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2842 if ( !EmptyRgn(updatergn
) )
2844 RgnHandle newupdate
= NewRgn() ;
2845 wxSize point
= GetClientSize() ;
2846 wxPoint origin
= GetClientAreaOrigin() ;
2847 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2848 SectRgn( newupdate
, updatergn
, newupdate
) ;
2850 // first send an erase event to the entire update area
2852 wxWindowDC
dc(this);
2853 dc
.SetClippingRegion(wxRegion(updatergn
));
2854 wxEraseEvent
eevent( GetId(), &dc
);
2855 eevent
.SetEventObject( this );
2856 GetEventHandler()->ProcessEvent( eevent
);
2859 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2860 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2861 m_updateRegion
= newupdate
;
2862 DisposeRgn( newupdate
) ;
2864 if ( !m_updateRegion
.Empty() )
2866 // paint the window itself
2868 event
.SetTimestamp(time
);
2869 event
.SetEventObject(this);
2870 handled
= GetEventHandler()->ProcessEvent(event
);
2872 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2875 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2877 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2884 // now we cannot rely on having its borders drawn by a window itself, as it does not
2885 // get the updateRgn wide enough to always do so, so we do it from the parent
2886 // this would also be the place to draw any custom backgrounds for native controls
2887 // in Composited windowing
2888 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2890 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2892 wxWindowMac
*child
= node
->GetData();
2893 if (child
== m_vScrollBar
) continue;
2894 if (child
== m_hScrollBar
) continue;
2895 if (child
->IsTopLevel()) continue;
2896 if (!child
->IsShown()) continue;
2899 child
->GetPosition( &x
, &y
);
2901 child
->GetSize( &w
, &h
);
2902 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2903 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2904 if ( child
->MacGetTopBorderSize() )
2906 if ( RectInRgn( &childRect
, updatergn
) )
2908 #if wxMAC_USE_CORE_GRAPHICS
2910 // paint custom borders
2911 wxNcPaintEvent
eventNc( child
->GetId() );
2912 eventNc
.SetEventObject( child
);
2913 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2915 wxWindowDC
dc(this) ;
2916 dc
.SetClippingRegion(wxRegion(updatergn
));
2917 wxMacPortSetter
helper(&dc
) ;
2918 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2923 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2925 #if wxMAC_USE_CORE_GRAPHICS
2927 wxWindowDC
dc(this) ;
2928 dc
.SetClippingRegion(wxRegion(updatergn
));
2929 wxMacPortSetter
helper(&dc
) ;
2930 Rect r
= childRect
;
2931 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2932 DrawThemeFocusRect( &r
, true ) ;
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::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3198 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3202 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3203 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3207 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3209 return eventNotHandledErr
;