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() ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
216 updateRgn
= allocatedRgn
;
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 if ( thisWindow
->MacIsUserPane() )
225 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
226 static float color
= 0.5 ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
243 #if wxMAC_USE_CORE_GRAPHICS
244 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
245 thisWindow
->MacSetCGContextRef( cgContext
) ;
247 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
249 #if wxMAC_USE_CORE_GRAPHICS
250 thisWindow
->MacSetCGContextRef( NULL
) ;
253 DisposeRgn( allocatedRgn
) ;
256 case kEventControlVisibilityChanged
:
257 thisWindow
->MacVisibilityChanged() ;
259 case kEventControlEnabledStateChanged
:
260 thisWindow
->MacEnabledStateChanged() ;
262 case kEventControlHiliteChanged
:
263 thisWindow
->MacHiliteChanged() ;
265 case kEventControlSetFocusPart
:
267 Boolean focusEverything
= false ;
268 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
269 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
272 if ( controlPart
== kControlFocusNoPart
)
275 if ( thisWindow
->GetCaret() )
277 thisWindow
->GetCaret()->OnKillFocus();
279 #endif // wxUSE_CARET
280 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
281 event
.SetEventObject(thisWindow
);
282 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
286 // panel wants to track the window which was the last to have focus in it
287 wxChildFocusEvent
eventFocus(thisWindow
);
288 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
291 if ( thisWindow
->GetCaret() )
293 thisWindow
->GetCaret()->OnSetFocus();
295 #endif // wxUSE_CARET
297 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
298 event
.SetEventObject(thisWindow
);
299 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
301 if ( thisWindow
->MacIsUserPane() )
306 case kEventControlHit
:
308 result
= thisWindow
->MacControlHit( handler
, event
) ;
317 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
319 OSStatus result
= eventNotHandledErr
;
321 wxMacCarbonEvent
cEvent( event
) ;
323 ControlRef controlRef
;
324 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
325 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
326 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
328 switch( GetEventKind( event
) )
330 case kEventServiceGetTypes
:
334 textCtrl
->GetSelection( &from
, &to
) ;
336 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
338 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
339 if ( textCtrl
->IsEditable() )
340 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
342 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
343 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
345 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
349 CFArrayAppendValue (copyTypes
, typestring
) ;
351 CFArrayAppendValue (pasteTypes
, typestring
) ;
352 CFRelease( typestring
) ;
358 case kEventServiceCopy
:
362 textCtrl
->GetSelection( &from
, &to
) ;
363 wxString val
= textCtrl
->GetValue() ;
364 val
= val
.Mid( from
, to
- from
) ;
365 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
366 verify_noerr( ClearScrap( &scrapRef
) ) ;
367 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
371 case kEventServicePaste
:
374 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
375 Size textSize
, pastedSize
;
376 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
378 char *content
= new char[textSize
] ;
379 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
380 content
[textSize
-1] = 0 ;
382 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
384 textCtrl
->WriteText( wxString( content
) ) ;
395 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
397 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
398 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
399 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
400 OSStatus result
= eventNotHandledErr
;
402 switch ( GetEventClass( event
) )
404 case kEventClassControl
:
405 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
407 case kEventClassService
:
408 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
412 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
416 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
418 #if !TARGET_API_MAC_OSX
420 // ---------------------------------------------------------------------------
421 // UserPane events for non OSX builds
422 // ---------------------------------------------------------------------------
424 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
426 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
427 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
428 win
->MacControlUserPaneDrawProc(part
) ;
431 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
433 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
434 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
435 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
438 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
440 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
441 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
442 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
445 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
447 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
448 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
449 win
->MacControlUserPaneIdleProc() ;
452 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
454 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
455 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
456 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
459 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
461 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
462 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
463 win
->MacControlUserPaneActivateProc(activating
) ;
466 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
468 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
469 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
470 return win
->MacControlUserPaneFocusProc(action
) ;
473 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
475 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
476 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
477 win
->MacControlUserPaneBackgroundProc(info
) ;
480 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
482 RgnHandle rgn
= NewRgn() ;
484 wxMacWindowStateSaver
sv( this ) ;
485 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
486 MacDoRedraw( rgn
, 0 ) ;
490 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
492 return kControlNoPart
;
495 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
497 return kControlNoPart
;
500 void wxWindowMac::MacControlUserPaneIdleProc()
504 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
506 return kControlNoPart
;
509 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
513 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
515 return kControlNoPart
;
518 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
522 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
523 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
524 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
525 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
526 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
527 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
528 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
529 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
533 // ===========================================================================
535 // ===========================================================================
537 #if KEY_wxList_DEPRECATED
538 wxList
wxWinMacControlList(wxKEY_INTEGER
);
540 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
542 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
545 return (wxControl
*)node
->GetData();
548 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
550 // adding NULL ControlRef is (first) surely a result of an error and
551 // (secondly) breaks native event processing
552 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
554 if ( !wxWinMacControlList
.Find((long)inControl
) )
555 wxWinMacControlList
.Append((long)inControl
, control
);
558 void wxRemoveMacControlAssociation(wxWindow
*control
)
560 wxWinMacControlList
.DeleteObject(control
);
564 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
566 static MacControlMap wxWinMacControlList
;
568 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
570 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
572 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
575 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
577 // adding NULL ControlRef is (first) surely a result of an error and
578 // (secondly) breaks native event processing
579 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
581 wxWinMacControlList
[inControl
] = control
;
584 void wxRemoveMacControlAssociation(wxWindow
*control
)
586 // iterate over all the elements in the class
587 MacControlMap::iterator it
;
588 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
590 if ( it
->second
== control
)
592 wxWinMacControlList
.erase(it
);
597 #endif // deprecated wxList
600 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
602 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
604 // we have to setup the brush in the current port and return noErr
605 // or return an error code so that the control manager walks further up the
606 // hierarchy to find a correct background
608 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
610 OSStatus status
= paramErr
;
613 case kControlMsgApplyTextColor
:
615 case kControlMsgSetUpBackground
:
617 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
621 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
624 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
626 // this clipping is only needed for non HIView
628 RgnHandle clip
= NewRgn() ;
631 wx
->MacWindowToRootWindow( &x
,&y
) ;
632 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
633 OffsetRgn( clip
, x
, y
) ;
640 else if ( wx->MacIsUserPane() )
642 // if we don't have a valid brush for such a control, we have to call the
643 // setup of our parent ourselves
644 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
657 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
658 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
662 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
665 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
670 // ----------------------------------------------------------------------------
671 // constructors and such
672 // ----------------------------------------------------------------------------
674 wxWindowMac::wxWindowMac()
679 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
684 const wxString
& name
)
687 Create(parent
, id
, pos
, size
, style
, name
);
690 void wxWindowMac::Init()
694 #if WXWIN_COMPATIBILITY_2_4
695 m_backgroundTransparent
= FALSE
;
698 // as all windows are created with WS_VISIBLE style...
701 m_hScrollBar
= NULL
;
702 m_vScrollBar
= NULL
;
703 m_macBackgroundBrush
= wxNullBrush
;
705 m_macIsUserPane
= TRUE
;
706 #if wxMAC_USE_CORE_GRAPHICS
707 m_cgContextRef
= NULL
;
709 // make sure all proc ptrs are available
711 #if !TARGET_API_MAC_OSX
712 if ( gControlUserPaneDrawUPP
== NULL
)
714 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
715 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
716 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
717 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
718 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
719 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
720 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
721 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
724 if ( wxMacLiveScrollbarActionUPP
== NULL
)
726 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
729 if ( wxMacSetupControlBackgroundUPP
== NULL
)
731 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
734 // we need a valid font for the encodings
735 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
739 wxWindowMac::~wxWindowMac()
743 m_isBeingDeleted
= TRUE
;
747 // deleting a window while it is shown invalidates the region occupied by border or
749 int outerBorder
= MacGetLeftBorderSize() ;
750 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
753 if ( IsShown() && ( outerBorder
> 0 ) )
755 // as the borders are drawn on the parent we have to properly invalidate all these areas
756 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
760 m_peer
->GetRect( &rect
) ;
761 RectRgn( updateInner
, &rect
) ;
762 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
763 RectRgn( updateOuter
, &rect
) ;
764 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
766 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
767 parent
-= GetParent()->GetClientAreaOrigin() ;
768 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
769 CopyRgn( updateOuter
, updateTotal
) ;
771 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
772 DisposeRgn(updateOuter
) ;
773 DisposeRgn(updateInner
) ;
774 DisposeRgn(updateTotal
) ;
778 #ifndef __WXUNIVERSAL__
779 // VS: make sure there's no wxFrame with last focus set to us:
780 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
782 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
785 if ( frame
->GetLastFocus() == this )
787 frame
->SetLastFocus((wxWindow
*)NULL
);
792 #endif // __WXUNIVERSAL__
794 // destroy children before destroying this window itself
797 // wxRemoveMacControlAssociation( this ) ;
798 // If we delete an item, we should initialize the parent panel,
799 // because it could now be invalid.
800 wxWindow
*parent
= GetParent() ;
803 if (parent
->GetDefaultItem() == (wxButton
*) this)
804 parent
->SetDefaultItem(NULL
);
806 if ( m_peer
&& m_peer
->Ok() )
808 // in case the callback might be called during destruction
809 wxRemoveMacControlAssociation( this) ;
810 // we currently are not using this hook
811 // ::SetControlColorProc( *m_peer , NULL ) ;
815 if ( g_MacLastWindow
== this )
817 g_MacLastWindow
= NULL
;
820 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
823 if ( frame
->GetLastFocus() == this )
824 frame
->SetLastFocus( NULL
) ;
827 // delete our drop target if we've got one
828 #if wxUSE_DRAG_AND_DROP
829 if ( m_dropTarget
!= NULL
)
834 #endif // wxUSE_DRAG_AND_DROP
838 WXWidget
wxWindowMac::GetHandle() const
840 return (WXWidget
) m_peer
->GetControlRef() ;
844 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
846 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
847 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
848 GetEventTypeCount(eventList
), eventList
, this,
849 (EventHandlerRef
*)&m_macControlEventHandler
);
854 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
858 const wxString
& name
)
860 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
862 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
865 m_windowVariant
= parent
->GetWindowVariant() ;
867 if ( m_macIsUserPane
)
869 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
872 | kControlSupportsEmbedding
873 // | kControlSupportsLiveFeedback
874 // | kControlHasSpecialBackground
875 // | kControlSupportsCalcBestRect
876 // | kControlHandlesTracking
877 | kControlSupportsFocus
878 // | kControlWantsActivate
879 // | kControlWantsIdle
882 m_peer
= new wxMacControl() ;
883 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
886 MacPostControlCreate(pos
,size
) ;
887 #if !TARGET_API_MAC_OSX
888 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
889 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
890 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
891 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
892 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
893 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
894 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
895 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
898 #ifndef __WXUNIVERSAL__
899 // Don't give scrollbars to wxControls unless they ask for them
900 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
901 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
903 MacCreateScrollBars( style
) ;
907 wxWindowCreateEvent
event(this);
908 GetEventHandler()->AddPendingEvent(event
);
913 void wxWindowMac::MacChildAdded()
917 m_vScrollBar
->Raise() ;
921 m_hScrollBar
->Raise() ;
926 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
928 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
930 m_peer
->SetReference( (long) this ) ;
931 GetParent()->AddChild(this);
933 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
935 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
936 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
937 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
938 GetParent()->MacChildAdded() ;
940 // adjust font, controlsize etc
941 DoSetWindowVariant( m_windowVariant
) ;
943 #if !TARGET_API_MAC_OSX
944 // eventually we can fix some clipping issues be reactivating this hook
945 //if ( m_macIsUserPane )
946 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
948 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
950 if (!m_macIsUserPane
)
952 SetInitialBestSize(size
);
955 SetCursor( *wxSTANDARD_CURSOR
) ;
958 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
960 // Don't assert, in case we set the window variant before
961 // the window is created
962 // wxASSERT( m_peer->Ok() ) ;
964 m_windowVariant
= variant
;
966 if (m_peer
== NULL
|| !m_peer
->Ok())
970 ThemeFontID themeFont
= kThemeSystemFont
;
972 // we will get that from the settings later
973 // and make this NORMAL later, but first
974 // we have a few calculations that we must fix
978 case wxWINDOW_VARIANT_NORMAL
:
979 size
= kControlSizeNormal
;
980 themeFont
= kThemeSystemFont
;
982 case wxWINDOW_VARIANT_SMALL
:
983 size
= kControlSizeSmall
;
984 themeFont
= kThemeSmallSystemFont
;
986 case wxWINDOW_VARIANT_MINI
:
987 if (UMAGetSystemVersion() >= 0x1030 )
989 // not always defined in the headers
995 size
= kControlSizeSmall
;
996 themeFont
= kThemeSmallSystemFont
;
999 case wxWINDOW_VARIANT_LARGE
:
1000 size
= kControlSizeLarge
;
1001 themeFont
= kThemeSystemFont
;
1004 wxFAIL_MSG(_T("unexpected window variant"));
1007 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
1010 font
.MacCreateThemeFont( themeFont
) ;
1014 void wxWindowMac::MacUpdateControlFont()
1016 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1020 bool wxWindowMac::SetFont(const wxFont
& font
)
1022 bool retval
= wxWindowBase::SetFont( font
) ;
1024 MacUpdateControlFont() ;
1029 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1031 if ( !wxWindowBase::SetForegroundColour(col
) )
1034 MacUpdateControlFont() ;
1039 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1041 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1045 wxColour
newCol(GetBackgroundColour());
1046 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1048 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1050 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1052 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1056 brush
.SetColour( newCol
) ;
1058 MacSetBackgroundBrush( brush
) ;
1060 MacUpdateControlFont() ;
1065 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1067 m_macBackgroundBrush
= brush
;
1068 m_peer
->SetBackground( brush
) ;
1071 bool wxWindowMac::MacCanFocus() const
1073 // there is currently no way to determine whether the window is running in full keyboard
1074 // access mode, therefore we cannot rely on these features, yet the only other way would be
1075 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1076 // in event handlers...
1077 UInt32 features
= 0 ;
1078 m_peer
->GetFeatures( & features
) ;
1079 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1083 void wxWindowMac::SetFocus()
1085 if ( AcceptsFocus() )
1088 wxWindow
* former
= FindFocus() ;
1089 if ( former
== this )
1092 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1093 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1094 // leave in case of an error
1095 if ( err
== errCouldntSetFocus
)
1098 #if !TARGET_API_MAC_OSX
1099 // emulate carbon events when running under carbonlib where they are not natively available
1102 EventRef evRef
= NULL
;
1103 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1106 wxMacCarbonEvent
cEvent( evRef
) ;
1107 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1108 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1110 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1111 ReleaseEvent(evRef
) ;
1113 // send new focus event
1115 EventRef evRef
= NULL
;
1116 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1119 wxMacCarbonEvent
cEvent( evRef
) ;
1120 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1121 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1123 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1124 ReleaseEvent(evRef
) ;
1131 void wxWindowMac::DoCaptureMouse()
1133 wxTheApp
->s_captureWindow
= this ;
1136 wxWindow
* wxWindowBase::GetCapture()
1138 return wxTheApp
->s_captureWindow
;
1141 void wxWindowMac::DoReleaseMouse()
1143 wxTheApp
->s_captureWindow
= NULL
;
1146 #if wxUSE_DRAG_AND_DROP
1148 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1150 if ( m_dropTarget
!= 0 ) {
1151 delete m_dropTarget
;
1154 m_dropTarget
= pDropTarget
;
1155 if ( m_dropTarget
!= 0 )
1163 // Old style file-manager drag&drop
1164 void wxWindowMac::DragAcceptFiles(bool accept
)
1169 // Returns the size of the native control. In the case of the toplevel window
1170 // this is the content area root control
1172 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1173 int& w
, int& h
) const
1176 m_peer
->GetRect( &bounds
) ;
1181 w
= bounds
.right
- bounds
.left
;
1182 h
= bounds
.bottom
- bounds
.top
;
1185 // From a wx position / size calculate the appropriate size of the native control
1187 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1190 int& w
, int& h
, bool adjustOrigin
) const
1192 // the desired size, minus the border pixels gives the correct size of the control
1196 // todo the default calls may be used as soon as PostCreateControl Is moved here
1197 w
= size
.x
; // WidthDefault( size.x );
1198 h
= size
.y
; // HeightDefault( size.y ) ;
1199 #if !TARGET_API_MAC_OSX
1200 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1203 x
+= MacGetLeftBorderSize() ;
1204 y
+= MacGetTopBorderSize() ;
1205 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1206 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1209 AdjustForParentClientOrigin( x
, y
) ;
1210 #if TARGET_API_MAC_OSX
1211 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1212 if ( ! GetParent()->IsTopLevel() )
1214 x
-= GetParent()->MacGetLeftBorderSize() ;
1215 y
-= GetParent()->MacGetTopBorderSize() ;
1221 // Get window size (not client size)
1222 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1224 // take the size of the control and add the borders that have to be drawn outside
1225 int x1
, y1
, w1
, h1
;
1227 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1229 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1230 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1236 // get the position of the bounds of this window in client coordinates of its parent
1237 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1239 int x1
, y1
, w1
,h1
;
1240 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1241 x1
-= MacGetLeftBorderSize() ;
1242 y1
-= MacGetTopBorderSize() ;
1244 #if !TARGET_API_MAC_OSX
1245 if ( !GetParent()->IsTopLevel() )
1248 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1253 if ( !IsTopLevel() )
1255 wxWindow
*parent
= GetParent();
1258 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1259 x1
+= parent
->MacGetLeftBorderSize() ;
1260 y1
+= parent
->MacGetTopBorderSize() ;
1261 // and now to client coordinates
1262 wxPoint
pt(parent
->GetClientAreaOrigin());
1271 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1273 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1275 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1278 Point localwhere
= {0,0} ;
1280 if(x
) localwhere
.h
= * x
;
1281 if(y
) localwhere
.v
= * y
;
1283 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1284 if(x
) *x
= localwhere
.h
;
1285 if(y
) *y
= localwhere
.v
;
1288 MacRootWindowToWindow( x
, y
) ;
1290 wxPoint origin
= GetClientAreaOrigin() ;
1291 if(x
) *x
-= origin
.x
;
1292 if(y
) *y
-= origin
.y
;
1295 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1297 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1298 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1300 wxPoint origin
= GetClientAreaOrigin() ;
1301 if(x
) *x
+= origin
.x
;
1302 if(y
) *y
+= origin
.y
;
1304 MacWindowToRootWindow( x
, y
) ;
1307 Point localwhere
= { 0,0 };
1308 if(x
) localwhere
.h
= * x
;
1309 if(y
) localwhere
.v
= * y
;
1310 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1311 if(x
) *x
= localwhere
.h
;
1312 if(y
) *y
= localwhere
.v
;
1316 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1318 wxPoint origin
= GetClientAreaOrigin() ;
1319 if(x
) *x
+= origin
.x
;
1320 if(y
) *y
+= origin
.y
;
1322 MacWindowToRootWindow( x
, y
) ;
1325 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1327 MacRootWindowToWindow( x
, y
) ;
1329 wxPoint origin
= GetClientAreaOrigin() ;
1330 if(x
) *x
-= origin
.x
;
1331 if(y
) *y
-= origin
.y
;
1334 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1336 #if TARGET_API_MAC_OSX
1338 if ( x
) pt
.x
= *x
;
1339 if ( y
) pt
.y
= *y
;
1341 if ( !IsTopLevel() )
1343 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1346 pt
.x
-= MacGetLeftBorderSize() ;
1347 pt
.y
-= MacGetTopBorderSize() ;
1348 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1352 if ( x
) *x
= (int) pt
.x
;
1353 if ( y
) *y
= (int) pt
.y
;
1355 if ( !IsTopLevel() )
1358 m_peer
->GetRect( &bounds
) ;
1359 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1360 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1365 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1370 MacWindowToRootWindow( &x1
, &y1
) ;
1375 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1377 #if TARGET_API_MAC_OSX
1379 if ( x
) pt
.x
= *x
;
1380 if ( y
) pt
.y
= *y
;
1382 if ( !IsTopLevel() )
1384 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1385 pt
.x
+= MacGetLeftBorderSize() ;
1386 pt
.y
+= MacGetTopBorderSize() ;
1389 if ( x
) *x
= (int) pt
.x
;
1390 if ( y
) *y
= (int) pt
.y
;
1392 if ( !IsTopLevel() )
1395 m_peer
->GetRect( &bounds
) ;
1396 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1397 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1402 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1407 MacRootWindowToWindow( &x1
, &y1
) ;
1412 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1414 RgnHandle rgn
= NewRgn() ;
1416 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1418 GetRegionBounds( rgn
, &content
) ;
1422 m_peer
->GetRect( &content
) ;
1426 m_peer
->GetRect( &structure
) ;
1427 #if !TARGET_API_MAC_OSX
1428 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1430 left
= content
.left
- structure
.left
;
1431 top
= content
.top
- structure
.top
;
1432 right
= structure
.right
- content
.right
;
1433 bottom
= structure
.bottom
- content
.bottom
;
1436 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1438 wxSize sizeTotal
= size
;
1440 RgnHandle rgn
= NewRgn() ;
1444 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1446 GetRegionBounds( rgn
, &content
) ;
1450 m_peer
->GetRect( &content
) ;
1454 m_peer
->GetRect( &structure
) ;
1455 #if !TARGET_API_MAC_OSX
1456 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1459 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1460 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1462 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1463 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1469 // Get size *available for subwindows* i.e. excluding menu bar etc.
1470 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1474 RgnHandle rgn
= NewRgn() ;
1476 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1478 GetRegionBounds( rgn
, &content
) ;
1482 m_peer
->GetRect( &content
) ;
1485 #if !TARGET_API_MAC_OSX
1487 m_peer
->GetRect( &structure
) ;
1488 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1490 ww
= content
.right
- content
.left
;
1491 hh
= content
.bottom
- content
.top
;
1493 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1494 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1497 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1503 GetSize( &w , &h ) ;
1505 MacClientToRootWindow( &x1 , &y1 ) ;
1506 MacClientToRootWindow( &w , &h ) ;
1508 wxWindowMac *iter = (wxWindowMac*)this ;
1510 int totW = 10000 , totH = 10000;
1513 if ( iter->IsTopLevel() )
1515 iter->GetSize( &totW , &totH ) ;
1519 iter = iter->GetParent() ;
1522 if (m_hScrollBar && m_hScrollBar->IsShown() )
1524 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1530 if (m_vScrollBar && m_vScrollBar->IsShown() )
1532 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1540 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1542 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1544 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1546 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1553 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1555 if (m_cursor
== cursor
)
1558 if (wxNullCursor
== cursor
)
1560 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1565 if ( ! wxWindowBase::SetCursor( cursor
) )
1569 wxASSERT_MSG( m_cursor
.Ok(),
1570 wxT("cursor must be valid after call to the base version"));
1573 wxWindowMac
*mouseWin
= 0 ;
1575 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1577 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1579 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1580 // position, use it...
1584 ControlPartCode part
;
1585 ControlRef control
;
1586 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1588 mouseWin
= wxFindControlFromMacControl( control
) ;
1591 QDSwapPort( savePort
, NULL
) ;
1594 if ( mouseWin
== this && !wxIsBusy() )
1596 m_cursor
.MacInstall() ;
1603 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1605 menu
->SetInvokingWindow(this);
1608 if ( x
== -1 && y
== -1 )
1610 wxPoint mouse
= wxGetMousePosition();
1611 x
= mouse
.x
; y
= mouse
.y
;
1615 ClientToScreen( &x
, &y
) ;
1618 menu
->MacBeforeDisplay( true ) ;
1619 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1620 if ( HiWord(menuResult
) != 0 )
1623 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1624 wxMenuItem
* item
= NULL
;
1626 item
= menu
->FindItem(id
, &realmenu
) ;
1627 if (item
->IsCheckable())
1629 item
->Check( !item
->IsChecked() ) ;
1631 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1633 menu
->MacAfterDisplay( true ) ;
1635 menu
->SetInvokingWindow(NULL
);
1641 // ----------------------------------------------------------------------------
1643 // ----------------------------------------------------------------------------
1647 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1649 wxWindowBase::DoSetToolTip(tooltip
);
1652 m_tooltip
->SetWindow(this);
1655 #endif // wxUSE_TOOLTIPS
1657 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1659 // this is never called for a toplevel window, so we know we have a parent
1660 int former_x
, former_y
, former_w
, former_h
;
1662 // Get true coordinates of former position
1663 DoGetPosition( &former_x
, &former_y
) ;
1664 DoGetSize( &former_w
, &former_h
) ;
1666 wxWindow
*parent
= GetParent();
1669 wxPoint
pt(parent
->GetClientAreaOrigin());
1674 int actualWidth
= width
;
1675 int actualHeight
= height
;
1679 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1680 actualWidth
= m_minWidth
;
1681 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1682 actualHeight
= m_minHeight
;
1683 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1684 actualWidth
= m_maxWidth
;
1685 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1686 actualHeight
= m_maxHeight
;
1688 bool doMove
= false ;
1689 bool doResize
= false ;
1691 if ( actualX
!= former_x
|| actualY
!= former_y
)
1695 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1700 if ( doMove
|| doResize
)
1702 // we don't adjust twice for the origin
1703 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1704 bool vis
= m_peer
->IsVisible();
1706 int outerBorder
= MacGetLeftBorderSize() ;
1707 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1710 if ( vis
&& ( outerBorder
> 0 ) )
1712 // as the borders are drawn on the parent we have to properly invalidate all these areas
1713 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1717 m_peer
->GetRect( &rect
) ;
1718 RectRgn( updateInner
, &rect
) ;
1719 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1720 RectRgn( updateOuter
, &rect
) ;
1721 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1722 wxPoint
parent(0,0);
1723 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1724 parent
-= GetParent()->GetClientAreaOrigin() ;
1725 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1726 CopyRgn( updateOuter
, updateTotal
) ;
1729 RectRgn( updateInner
, &rect
) ;
1730 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1731 RectRgn( updateOuter
, &rect
) ;
1732 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1734 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1735 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1737 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1738 DisposeRgn(updateOuter
) ;
1739 DisposeRgn(updateInner
) ;
1740 DisposeRgn(updateTotal
) ;
1743 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1745 m_peer
->SetVisibility( false , true ) ;
1747 m_peer
->SetRect( &r
) ;
1749 m_peer
->SetVisibility( true , true ) ;
1751 MacRepositionScrollBars() ;
1754 wxPoint
point(actualX
,actualY
);
1755 wxMoveEvent
event(point
, m_windowId
);
1756 event
.SetEventObject(this);
1757 GetEventHandler()->ProcessEvent(event
) ;
1761 MacRepositionScrollBars() ;
1762 wxSize
size(actualWidth
, actualHeight
);
1763 wxSizeEvent
event(size
, m_windowId
);
1764 event
.SetEventObject(this);
1765 GetEventHandler()->ProcessEvent(event
);
1771 wxSize
wxWindowMac::DoGetBestSize() const
1773 if ( m_macIsUserPane
|| IsTopLevel() )
1774 return wxWindowBase::DoGetBestSize() ;
1776 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1777 int bestWidth
, bestHeight
;
1778 m_peer
->GetBestRect( &bestsize
) ;
1780 if ( EmptyRect( &bestsize
) )
1782 bestsize
.left
= bestsize
.top
= 0 ;
1783 bestsize
.right
= 16 ;
1784 bestsize
.bottom
= 16 ;
1785 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1787 bestsize
.bottom
= 16 ;
1790 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1792 bestsize
.bottom
= 24 ;
1794 #endif // wxUSE_SPINBTN
1797 // return wxWindowBase::DoGetBestSize() ;
1801 bestWidth
= bestsize
.right
- bestsize
.left
;
1802 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1803 if ( bestHeight
< 10 )
1806 return wxSize(bestWidth
, bestHeight
);
1810 // set the size of the window: if the dimensions are positive, just use them,
1811 // but if any of them is equal to -1, it means that we must find the value for
1812 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1813 // which case -1 is a valid value for x and y)
1815 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1816 // the width/height to best suit our contents, otherwise we reuse the current
1818 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1820 // get the current size and position...
1821 int currentX
, currentY
;
1822 GetPosition(¤tX
, ¤tY
);
1824 int currentW
,currentH
;
1825 GetSize(¤tW
, ¤tH
);
1827 // ... and don't do anything (avoiding flicker) if it's already ok
1828 if ( x
== currentX
&& y
== currentY
&&
1829 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1832 MacRepositionScrollBars() ; // we might have a real position shift
1836 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1838 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1841 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1843 wxSize
size(-1, -1);
1846 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1848 size
= DoGetBestSize();
1853 // just take the current one
1860 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1864 size
= DoGetBestSize();
1866 //else: already called DoGetBestSize() above
1872 // just take the current one
1877 DoMoveWindow(x
, y
, width
, height
);
1881 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1883 RgnHandle rgn
= NewRgn() ;
1885 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1886 GetRegionBounds( rgn
, &content
) ;
1888 #if !TARGET_API_MAC_OSX
1889 // if the content rgn is empty / not supported
1890 // don't attempt to correct the coordinates to wxWindow relative ones
1891 if (!::EmptyRect( &content
) )
1894 m_peer
->GetRect( &structure
) ;
1895 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1899 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1902 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1904 if ( clientheight
!= -1 || clientheight
!= -1 )
1906 int currentclientwidth
, currentclientheight
;
1907 int currentwidth
, currentheight
;
1909 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1910 GetSize( ¤twidth
, ¤theight
) ;
1912 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1913 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1917 void wxWindowMac::SetTitle(const wxString
& title
)
1919 m_label
= wxStripMenuCodes(title
) ;
1921 if ( m_peer
&& m_peer
->Ok() )
1923 m_peer
->SetTitle( m_label
) ;
1928 wxString
wxWindowMac::GetTitle() const
1933 bool wxWindowMac::Show(bool show
)
1935 if ( !wxWindowBase::Show(show
) )
1938 // TODO use visibilityChanged Carbon Event for OSX
1941 bool former
= MacIsReallyShown() ;
1943 m_peer
->SetVisibility( show
, true ) ;
1944 if ( former
!= MacIsReallyShown() )
1945 MacPropagateVisibilityChanged() ;
1950 bool wxWindowMac::Enable(bool enable
)
1952 wxASSERT( m_peer
->Ok() ) ;
1953 if ( !wxWindowBase::Enable(enable
) )
1956 bool former
= MacIsReallyEnabled() ;
1957 m_peer
->Enable( enable
) ;
1959 if ( former
!= MacIsReallyEnabled() )
1960 MacPropagateEnabledStateChanged() ;
1965 // status change propagations (will be not necessary for OSX later )
1968 void wxWindowMac::MacPropagateVisibilityChanged()
1970 #if !TARGET_API_MAC_OSX
1971 MacVisibilityChanged() ;
1973 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1976 wxWindowMac
*child
= node
->GetData();
1977 if ( child
->IsShown() )
1978 child
->MacPropagateVisibilityChanged( ) ;
1979 node
= node
->GetNext();
1984 void wxWindowMac::MacPropagateEnabledStateChanged( )
1986 #if !TARGET_API_MAC_OSX
1987 MacEnabledStateChanged() ;
1989 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1992 wxWindowMac
*child
= node
->GetData();
1993 if ( child
->IsEnabled() )
1994 child
->MacPropagateEnabledStateChanged() ;
1995 node
= node
->GetNext();
2000 void wxWindowMac::MacPropagateHiliteChanged( )
2002 #if !TARGET_API_MAC_OSX
2003 MacHiliteChanged() ;
2005 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2008 wxWindowMac
*child
= node
->GetData();
2009 // if ( child->IsEnabled() )
2010 child
->MacPropagateHiliteChanged() ;
2011 node
= node
->GetNext();
2017 // status change notifications
2020 void wxWindowMac::MacVisibilityChanged()
2024 void wxWindowMac::MacHiliteChanged()
2028 void wxWindowMac::MacEnabledStateChanged()
2033 // status queries on the inherited window's state
2036 bool wxWindowMac::MacIsReallyShown()
2038 // only under OSX the visibility of the TLW is taken into account
2039 if ( m_isBeingDeleted
)
2042 #if TARGET_API_MAC_OSX
2043 if ( m_peer
&& m_peer
->Ok() )
2044 return m_peer
->IsVisible();
2046 wxWindow
* win
= this ;
2047 while( win
->IsShown() )
2049 if ( win
->IsTopLevel() )
2052 win
= win
->GetParent() ;
2060 bool wxWindowMac::MacIsReallyEnabled()
2062 return m_peer
->IsEnabled() ;
2065 bool wxWindowMac::MacIsReallyHilited()
2067 return m_peer
->IsActive();
2070 void wxWindowMac::MacFlashInvalidAreas()
2072 #if TARGET_API_MAC_OSX
2073 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2081 int wxWindowMac::GetCharHeight() const
2083 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2084 return dc
.GetCharHeight() ;
2087 int wxWindowMac::GetCharWidth() const
2089 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2090 return dc
.GetCharWidth() ;
2093 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2094 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2096 const wxFont
*fontToUse
= theFont
;
2098 fontToUse
= &m_font
;
2100 wxClientDC
dc( (wxWindowMac
*) this ) ;
2102 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2103 if ( externalLeading
)
2104 *externalLeading
= le
;
2114 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2115 * we always intersect with the entire window, not only with the client area
2118 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2120 if ( m_peer
== NULL
)
2123 #if TARGET_API_MAC_OSX
2125 m_peer
->SetNeedsDisplay( true ) ;
2128 RgnHandle update
= NewRgn() ;
2129 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2130 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2131 wxPoint origin
= GetClientAreaOrigin() ;
2132 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2133 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2135 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2136 m_peer
->SetNeedsDisplay( true , update
) ;
2137 DisposeRgn( update
) ;
2141 RgnHandle updateRgn = NewRgn() ;
2144 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2148 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2149 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2151 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2152 DisposeRgn(updateRgn) ;
2154 if ( m_peer
->IsVisible())
2156 m_peer
->SetVisibility( false , false ) ;
2157 m_peer
->SetVisibility( true , true ) ;
2160 if ( MacGetTopLevelWindow() == NULL )
2163 if ( !m_peer->IsVisible())
2166 wxPoint client = GetClientAreaOrigin();
2169 int x2 = m_width - client.x;
2170 int y2 = m_height - client.y;
2172 if (IsKindOf( CLASSINFO(wxButton)))
2174 // buttons have an "aura"
2181 Rect clientrect = { y1, x1, y2, x2 };
2185 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2186 SectRect( &clientrect , &r , &clientrect ) ;
2189 if ( !EmptyRect( &clientrect ) )
2191 int top = 0 , left = 0 ;
2193 MacClientToRootWindow( &left , &top ) ;
2194 OffsetRect( &clientrect , left , top ) ;
2196 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2202 void wxWindowMac::Freeze()
2204 #if TARGET_API_MAC_OSX
2205 if ( !m_frozenness
++ )
2207 if ( m_peer
&& m_peer
->Ok() )
2208 m_peer
->SetDrawingEnabled( false ) ;
2214 void wxWindowMac::Thaw()
2216 #if TARGET_API_MAC_OSX
2217 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2219 if ( !--m_frozenness
)
2221 if ( m_peer
&& m_peer
->Ok() )
2223 m_peer
->SetDrawingEnabled( true ) ;
2224 m_peer
->InvalidateWithChildren() ;
2231 void wxWindowMac::OnPaint(wxPaintEvent& event)
2233 // why don't we skip that here ?
2237 wxWindowMac
*wxGetActiveWindow()
2239 // actually this is a windows-only concept
2243 // Coordinates relative to the window
2244 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2246 // We really don't move the mouse programmatically under Mac.
2249 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2251 #if TARGET_API_MAC_OSX
2252 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2256 else if ( m_macBackgroundBrush
.MacGetBrushKind() == kwxMacBrushTheme
)
2258 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2260 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2266 event
.GetDC()->Clear() ;
2270 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2275 int wxWindowMac::GetScrollPos(int orient
) const
2277 if ( orient
== wxHORIZONTAL
)
2280 return m_hScrollBar
->GetThumbPosition() ;
2285 return m_vScrollBar
->GetThumbPosition() ;
2290 // This now returns the whole range, not just the number
2291 // of positions that we can scroll.
2292 int wxWindowMac::GetScrollRange(int orient
) const
2294 if ( orient
== wxHORIZONTAL
)
2297 return m_hScrollBar
->GetRange() ;
2302 return m_vScrollBar
->GetRange() ;
2307 int wxWindowMac::GetScrollThumb(int orient
) const
2309 if ( orient
== wxHORIZONTAL
)
2312 return m_hScrollBar
->GetThumbSize() ;
2317 return m_vScrollBar
->GetThumbSize() ;
2322 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2324 if ( orient
== wxHORIZONTAL
)
2327 m_hScrollBar
->SetThumbPosition( pos
) ;
2332 m_vScrollBar
->SetThumbPosition( pos
) ;
2336 void wxWindowMac::MacPaintBorders( int left
, int top
)
2342 m_peer
->GetRect( &rect
) ;
2343 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2345 if ( !IsTopLevel() )
2347 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2351 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2353 rect
.right
+= pt
.x
;
2355 rect
.bottom
+= pt
.y
;
2359 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2363 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2364 InsetRect( &srect
, border
, border
);
2365 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2367 else if (HasFlag(wxSIMPLE_BORDER
))
2371 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2372 InsetRect( &srect
, border
, border
);
2373 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2377 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2379 if ( child
== m_hScrollBar
)
2380 m_hScrollBar
= NULL
;
2381 if ( child
== m_vScrollBar
)
2382 m_vScrollBar
= NULL
;
2384 wxWindowBase::RemoveChild( child
) ;
2387 // New function that will replace some of the above.
2388 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2389 int range
, bool refresh
)
2391 if ( orient
== wxHORIZONTAL
)
2395 if ( range
== 0 || thumbVisible
>= range
)
2397 if ( m_hScrollBar
->IsShown() )
2398 m_hScrollBar
->Show(false) ;
2402 if ( !m_hScrollBar
->IsShown() )
2403 m_hScrollBar
->Show(true) ;
2405 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2412 if ( range
== 0 || thumbVisible
>= range
)
2414 if ( m_vScrollBar
->IsShown() )
2415 m_vScrollBar
->Show(false) ;
2419 if ( !m_vScrollBar
->IsShown() )
2420 m_vScrollBar
->Show(true) ;
2422 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2425 MacRepositionScrollBars() ;
2428 // Does a physical scroll
2429 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2431 if( dx
== 0 && dy
==0 )
2437 int width
, height
;
2438 GetClientSize( &width
, &height
) ;
2439 #if TARGET_API_MAC_OSX
2440 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2441 // area is scrolled, this does not occur if width and height are 2 pixels less,
2442 // TODO write optimal workaround
2443 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2446 scrollrect
.Intersect( *rect
) ;
2448 if ( m_peer
->GetNeedsDisplay() )
2450 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2451 // either immediate redraw or full invalidate
2453 // is the better overall solution, as it does not slow down scrolling
2454 m_peer
->SetNeedsDisplay( true ) ;
2456 // this would be the preferred version for fast drawing controls
2457 if( UMAGetSystemVersion() < 0x1030 )
2460 HIViewRender(m_peer
->GetControlRef()) ;
2463 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2464 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2465 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2472 RgnHandle updateRgn
= NewRgn() ;
2475 wxClientDC
dc(this) ;
2476 wxMacPortSetter
helper(&dc
) ;
2478 m_peer
->GetRect( &scrollrect
) ;
2479 scrollrect
.top
+= MacGetTopBorderSize() ;
2480 scrollrect
.left
+= MacGetLeftBorderSize() ;
2481 scrollrect
.bottom
= scrollrect
.top
+ height
;
2482 scrollrect
.right
= scrollrect
.left
+ width
;
2486 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2487 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2488 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2490 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2492 // now scroll the former update region as well and add the new update region
2494 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2495 RgnHandle formerUpdateRgn
= NewRgn() ;
2496 RgnHandle scrollRgn
= NewRgn() ;
2497 RectRgn( scrollRgn
, &scrollrect
) ;
2498 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2500 LocalToGlobal( &pt
) ;
2501 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2502 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2503 if ( !EmptyRgn( formerUpdateRgn
) )
2505 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2506 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2507 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2509 InvalWindowRgn(rootWindow
, updateRgn
) ;
2510 DisposeRgn( updateRgn
) ;
2511 DisposeRgn( formerUpdateRgn
) ;
2512 DisposeRgn( scrollRgn
) ;
2517 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2519 wxWindowMac
*child
= node
->GetData();
2520 if (child
== m_vScrollBar
) continue;
2521 if (child
== m_hScrollBar
) continue;
2522 if (child
->IsTopLevel()) continue;
2525 child
->GetPosition( &x
, &y
);
2527 child
->GetSize( &w
, &h
);
2531 if (rect
->Intersects(rc
))
2532 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2536 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2541 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2543 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2545 wxScrollWinEvent wevent
;
2546 wevent
.SetPosition(event
.GetPosition());
2547 wevent
.SetOrientation(event
.GetOrientation());
2548 wevent
.SetEventObject(this);
2550 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2551 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2552 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2553 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2554 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2555 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2556 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2557 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2558 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2559 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2560 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2561 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2562 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2563 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2564 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2565 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2567 GetEventHandler()->ProcessEvent(wevent
);
2571 // Get the window with the focus
2572 wxWindowMac
*wxWindowBase::DoFindFocus()
2574 ControlRef control
;
2575 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2576 return wxFindControlFromMacControl( control
) ;
2579 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2581 // panel wants to track the window which was the last to have focus in it,
2582 // so we want to set ourselves as the window which last had focus
2584 // notice that it's also important to do it upwards the tree becaus
2585 // otherwise when the top level panel gets focus, it won't set it back to
2586 // us, but to some other sibling
2588 // CS:don't know if this is still needed:
2589 //wxChildFocusEvent eventFocus(this);
2590 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2592 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2594 #if !wxMAC_USE_CORE_GRAPHICS
2595 wxMacWindowStateSaver
sv( this ) ;
2600 MacWindowToRootWindow( &x
, &y
) ;
2601 GetSize( &w
, &h
) ;
2602 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
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 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2614 RectRgn( updateInner
, &rect
) ;
2615 InsetRect( &rect
, -4 , -4 ) ;
2616 RectRgn( updateOuter
, &rect
) ;
2617 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2618 wxPoint
parent(0,0);
2619 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2620 parent
-= GetParent()->GetClientAreaOrigin() ;
2621 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2622 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2623 DisposeRgn(updateOuter
) ;
2624 DisposeRgn(updateInner
) ;
2627 GetParent()->Refresh() ;
2634 void wxWindowMac::OnInternalIdle()
2636 // This calls the UI-update mechanism (querying windows for
2637 // menu/toolbar/control state information)
2638 if (wxUpdateUIEvent::CanUpdate(this))
2639 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2642 // Raise the window to the top of the Z order
2643 void wxWindowMac::Raise()
2645 m_peer
->SetZOrder( true , NULL
) ;
2648 // Lower the window to the bottom of the Z order
2649 void wxWindowMac::Lower()
2651 m_peer
->SetZOrder( false , NULL
) ;
2655 // static wxWindow *gs_lastWhich = NULL;
2657 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2659 // first trigger a set cursor event
2661 wxPoint clientorigin
= GetClientAreaOrigin() ;
2662 wxSize clientsize
= GetClientSize() ;
2664 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2666 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2668 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2669 if ( processedEvtSetCursor
&& event
.HasCursor() )
2671 cursor
= event
.GetCursor() ;
2676 // the test for processedEvtSetCursor is here to prevent using m_cursor
2677 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2678 // it - this is a way to say that our cursor shouldn't be used for this
2680 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2690 cursor
= *wxSTANDARD_CURSOR
;
2694 cursor
.MacInstall() ;
2696 return cursor
.Ok() ;
2699 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2703 return m_tooltip
->GetTip() ;
2705 return wxEmptyString
;
2708 void wxWindowMac::ClearBackground()
2714 void wxWindowMac::Update()
2716 #if TARGET_API_MAC_OSX
2718 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2719 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2721 // for composited windows this also triggers a redraw of all
2722 // invalid views in the window
2723 if( UMAGetSystemVersion() >= 0x1030 )
2724 HIWindowFlush(window
) ;
2728 // the only way to trigger the redrawing on earlier systems is to call
2731 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2732 UInt32 currentEventClass
= 0 ;
2733 UInt32 currentEventKind
= 0 ;
2734 if ( currentEvent
!= NULL
)
2736 currentEventClass
= ::GetEventClass( currentEvent
) ;
2737 currentEventKind
= ::GetEventKind( currentEvent
) ;
2739 if ( currentEventClass
!= kEventClassMenu
)
2741 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2744 OSStatus status
= noErr
;
2745 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2748 m_peer
->SetNeedsDisplay( true ) ;
2751 ::Draw1Control( m_peer
->GetControlRef() ) ;
2755 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2757 wxTopLevelWindowMac
* win
= NULL
;
2758 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2761 win
= wxFindWinFromMacWindow( window
) ;
2765 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2767 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2768 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2769 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2770 // to add focus borders everywhere
2773 RgnHandle visRgn
= NewRgn() ;
2774 RgnHandle tempRgn
= NewRgn() ;
2775 if ( !m_isBeingDeleted
&& m_peer
->IsVisible())
2777 m_peer
->GetRect( &r
) ;
2778 r
.left
-= MacGetLeftBorderSize() ;
2779 r
.top
-= MacGetTopBorderSize() ;
2780 r
.bottom
+= MacGetBottomBorderSize() ;
2781 r
.right
+= MacGetRightBorderSize() ;
2783 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2785 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2786 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2795 if ( includeOuterStructures
)
2796 InsetRect( &r
, -4 , -4 ) ;
2797 RectRgn( visRgn
, &r
) ;
2799 if ( !IsTopLevel() )
2801 wxWindow
* child
= this ;
2802 wxWindow
* parent
= child
->GetParent() ;
2807 // we have to find a better clipping algorithm here, in order not to clip things
2808 // positioned like status and toolbar
2809 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2811 size
= parent
->GetSize() ;
2816 size
= parent
->GetClientSize() ;
2817 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2821 parent
->MacWindowToRootWindow( &x
, &y
) ;
2822 MacRootWindowToWindow( &x
, &y
) ;
2824 if ( !includeOuterStructures
|| (
2825 parent
->MacClipChildren() ||
2826 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2829 SetRectRgn( tempRgn
,
2830 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2831 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2832 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2834 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2836 if ( parent
->IsTopLevel() )
2839 parent
= child
->GetParent() ;
2844 wxRegion vis
= visRgn
;
2845 DisposeRgn( visRgn
) ;
2846 DisposeRgn( tempRgn
) ;
2851 This function must not change the updatergn !
2853 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2855 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2856 bool handled
= false ;
2858 GetRegionBounds( updatergn
, &updatebounds
) ;
2860 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2861 if ( !EmptyRgn(updatergn
) )
2863 RgnHandle newupdate
= NewRgn() ;
2864 wxSize point
= GetClientSize() ;
2865 wxPoint origin
= GetClientAreaOrigin() ;
2866 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2867 SectRgn( newupdate
, updatergn
, newupdate
) ;
2869 // first send an erase event to the entire update area
2871 wxWindowDC
dc(this);
2872 dc
.SetClippingRegion(wxRegion(updatergn
));
2873 wxEraseEvent
eevent( GetId(), &dc
);
2874 eevent
.SetEventObject( this );
2875 GetEventHandler()->ProcessEvent( eevent
);
2878 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2879 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2880 m_updateRegion
= newupdate
;
2881 DisposeRgn( newupdate
) ;
2883 if ( !m_updateRegion
.Empty() )
2885 // paint the window itself
2888 event
.SetTimestamp(time
);
2889 event
.SetEventObject(this);
2890 GetEventHandler()->ProcessEvent(event
);
2894 // now we cannot rely on having its borders drawn by a window itself, as it does not
2895 // get the updateRgn wide enough to always do so, so we do it from the parent
2896 // this would also be the place to draw any custom backgrounds for native controls
2897 // in Composited windowing
2898 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2900 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2902 wxWindowMac
*child
= node
->GetData();
2903 if (child
== m_vScrollBar
) continue;
2904 if (child
== m_hScrollBar
) continue;
2905 if (child
->IsTopLevel()) continue;
2906 if (!child
->IsShown()) continue;
2909 child
->GetPosition( &x
, &y
);
2911 child
->GetSize( &w
, &h
);
2912 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2913 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2914 if ( child
->MacGetTopBorderSize() )
2916 if ( RectInRgn( &childRect
, updatergn
) )
2918 #if wxMAC_USE_CORE_GRAPHICS
2919 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2920 if ( HIThemeDrawFrame
)
2922 Rect srect
= childRect
;
2923 HIThemeFrameDrawInfo info
;
2926 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2927 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2930 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2931 InsetRect( &srect
, border
, border
);
2932 info
.kind
= kHIThemeFrameTextFieldSquare
;
2934 else if (HasFlag(wxSIMPLE_BORDER
))
2937 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2938 InsetRect( &srect
, border
, border
);
2939 info
.kind
= kHIThemeFrameListBox
;
2942 CGRect rect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2943 srect
.bottom
- srect
.top
) ;
2944 HIThemeDrawFrame( &rect
, &info
, (CGContextRef
) MacGetCGContextRef() , kHIThemeOrientationNormal
) ;
2948 // paint custom borders
2949 wxNcPaintEvent
eventNc( child
->GetId() );
2950 eventNc
.SetEventObject( child
);
2951 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2953 wxWindowDC
dc(this) ;
2954 dc
.SetClippingRegion(wxRegion(updatergn
));
2955 wxMacPortSetter
helper(&dc
) ;
2956 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2961 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2963 #if wxMAC_USE_CORE_GRAPHICS
2964 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2965 if ( HIThemeDrawFocusRect
)
2967 CGRect rect
= CGRectMake( childRect
.left
, childRect
.top
, childRect
.right
- childRect
.left
,
2968 childRect
.bottom
- childRect
.top
) ;
2969 HIThemeDrawFocusRect( &rect
, true , (CGContextRef
) MacGetCGContextRef() , kHIThemeOrientationNormal
) ;
2973 wxWindowDC
dc(this) ;
2974 dc
.SetClippingRegion(wxRegion(updatergn
));
2975 wxMacPortSetter
helper(&dc
) ;
2976 Rect r
= childRect
;
2977 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2978 DrawThemeFocusRect( &r
, true ) ;
2987 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2989 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2993 if ( iter
->IsTopLevel() )
2994 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2996 iter
= iter
->GetParent() ;
2998 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3002 void wxWindowMac::MacCreateScrollBars( long style
)
3004 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3006 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3008 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3009 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3010 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3011 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3013 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3014 variant
= wxWINDOW_VARIANT_SMALL
;
3017 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3019 GetClientSize( &width
, &height
) ;
3021 wxPoint
vPoint(width
-scrlsize
, 0) ;
3022 wxSize
vSize(scrlsize
, height
- adjust
) ;
3023 wxPoint
hPoint(0 , height
-scrlsize
) ;
3024 wxSize
hSize( width
- adjust
, scrlsize
) ;
3027 if ( style
& wxVSCROLL
)
3029 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3030 vSize
, wxVERTICAL
);
3033 if ( style
& wxHSCROLL
)
3035 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3036 hSize
, wxHORIZONTAL
);
3041 // because the create does not take into account the client area origin
3042 MacRepositionScrollBars() ; // we might have a real position shift
3045 void wxWindowMac::MacRepositionScrollBars()
3047 if ( !m_hScrollBar
&& !m_vScrollBar
)
3050 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3051 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3052 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3054 // get real client area
3058 GetSize( &width
, &height
) ;
3060 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3061 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3063 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3064 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3065 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3066 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3072 GetSize( &w , &h ) ;
3074 MacClientToRootWindow( &x , &y ) ;
3075 MacClientToRootWindow( &w , &h ) ;
3077 wxWindowMac *iter = (wxWindowMac*)this ;
3079 int totW = 10000 , totH = 10000;
3082 if ( iter->IsTopLevel() )
3084 iter->GetSize( &totW , &totH ) ;
3088 iter = iter->GetParent() ;
3116 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3120 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3124 bool wxWindowMac::AcceptsFocus() const
3126 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3129 void wxWindowMac::MacSuperChangedPosition()
3131 // only window-absolute structures have to be moved i.e. controls
3133 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3136 wxWindowMac
*child
= node
->GetData();
3137 child
->MacSuperChangedPosition() ;
3138 node
= node
->GetNext();
3142 void wxWindowMac::MacTopLevelWindowChangedPosition()
3144 // only screen-absolute structures have to be moved i.e. glcanvas
3146 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3149 wxWindowMac
*child
= node
->GetData();
3150 child
->MacTopLevelWindowChangedPosition() ;
3151 node
= node
->GetNext();
3155 long wxWindowMac::MacGetLeftBorderSize( ) const
3160 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3165 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3170 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3177 long wxWindowMac::MacGetRightBorderSize( ) const
3179 // they are all symmetric in mac themes
3180 return MacGetLeftBorderSize() ;
3183 long wxWindowMac::MacGetTopBorderSize( ) const
3185 // they are all symmetric in mac themes
3186 return MacGetLeftBorderSize() ;
3189 long wxWindowMac::MacGetBottomBorderSize( ) const
3191 // they are all symmetric in mac themes
3192 return MacGetLeftBorderSize() ;
3195 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3197 return style
& ~wxBORDER_MASK
;
3200 // Find the wxWindowMac at the current mouse position, returning the mouse
3202 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3204 pt
= wxGetMousePosition();
3205 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3209 // Get the current mouse position.
3210 wxPoint
wxGetMousePosition()
3213 wxGetMousePosition(& x
, & y
);
3214 return wxPoint(x
, y
);
3217 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3219 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3221 // copied from wxGTK : CS
3222 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3225 // (a) it's a command event and so is propagated to the parent
3226 // (b) under MSW it can be generated from kbd too
3227 // (c) it uses screen coords (because of (a))
3228 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3230 this->ClientToScreen(event
.GetPosition()));
3231 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3240 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3242 // in the other case we already have drawn from the OnEraseBackground Handler
3243 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
||
3244 m_macBackgroundBrush
.MacGetBrushKind() != kwxMacBrushTheme
)
3246 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3248 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3253 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3257 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3261 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3262 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3266 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3268 return eventNotHandledErr
;