1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define wxWINDOW_HSCROLL 5998
48 #define wxWINDOW_VSCROLL 5997
50 #define MAC_SCROLLBAR_SIZE 15
51 #define MAC_SMALL_SCROLLBAR_SIZE 11
53 #include "wx/mac/uma.h"
56 #include <ToolUtils.h>
58 #include <MacTextEditor.h>
61 #if TARGET_API_MAC_OSX
63 #include <HIToolbox/HIView.h>
67 #if wxUSE_DRAG_AND_DROP
73 extern wxList wxPendingDelete
;
75 #ifdef __WXUNIVERSAL__
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
78 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
79 #endif // __WXUNIVERSAL__/__WXMAC__
81 #if !USE_SHARED_LIBRARY
83 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
84 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
85 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
86 // TODO EVT_PAINT(wxWindowMac::OnPaint)
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
120 // originating from native control
124 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
126 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
131 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
135 // directed towards native control
138 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
140 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
143 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
145 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
154 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
156 #if TARGET_API_MAC_OSX
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
160 kEventControlVisibilityChanged
= 157
166 static const EventTypeSpec eventList
[] =
168 { kEventClassControl
, kEventControlHit
} ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl
, kEventControlDraw
} ,
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
174 { kEventClassControl
, kEventControlSetFocusPart
} ,
176 { kEventClassService
, kEventServiceGetTypes
},
177 { kEventClassService
, kEventServiceCopy
},
178 { kEventClassService
, kEventServicePaste
},
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
204 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
216 updateRgn
= allocatedRgn
;
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
224 if ( thisWindow
->MacIsUserPane() )
226 static float color
= 0.5 ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
243 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
246 DisposeRgn( allocatedRgn
) ;
249 case kEventControlVisibilityChanged
:
250 thisWindow
->MacVisibilityChanged() ;
252 case kEventControlEnabledStateChanged
:
253 thisWindow
->MacEnabledStateChanged() ;
255 case kEventControlHiliteChanged
:
256 thisWindow
->MacHiliteChanged() ;
258 case kEventControlSetFocusPart
:
260 Boolean focusEverything
= false ;
261 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
262 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
265 if ( controlPart
== kControlFocusNoPart
)
268 if ( thisWindow
->GetCaret() )
270 thisWindow
->GetCaret()->OnKillFocus();
272 #endif // wxUSE_CARET
273 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
274 event
.SetEventObject(thisWindow
);
275 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
279 // panel wants to track the window which was the last to have focus in it
280 wxChildFocusEvent
eventFocus(thisWindow
);
281 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
284 if ( thisWindow
->GetCaret() )
286 thisWindow
->GetCaret()->OnSetFocus();
288 #endif // wxUSE_CARET
290 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
291 event
.SetEventObject(thisWindow
);
292 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
294 if ( thisWindow
->MacIsUserPane() )
299 case kEventControlHit
:
301 result
= thisWindow
->MacControlHit( handler
, event
) ;
310 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
312 OSStatus result
= eventNotHandledErr
;
314 wxMacCarbonEvent
cEvent( event
) ;
316 ControlRef controlRef
;
317 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
318 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
319 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
321 switch( GetEventKind( event
) )
323 case kEventServiceGetTypes
:
327 textCtrl
->GetSelection( &from
, &to
) ;
329 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
331 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
332 if ( textCtrl
->IsEditable() )
333 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
335 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
336 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
338 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
342 CFArrayAppendValue (copyTypes
, typestring
) ;
344 CFArrayAppendValue (pasteTypes
, typestring
) ;
345 CFRelease( typestring
) ;
351 case kEventServiceCopy
:
355 textCtrl
->GetSelection( &from
, &to
) ;
356 wxString val
= textCtrl
->GetValue() ;
357 val
= val
.Mid( from
, to
- from
) ;
358 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
359 verify_noerr( ClearScrap( &scrapRef
) ) ;
360 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
364 case kEventServicePaste
:
367 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
368 Size textSize
, pastedSize
;
369 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
371 char *content
= new char[textSize
] ;
372 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
373 content
[textSize
-1] = 0 ;
375 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
377 textCtrl
->WriteText( wxString( content
) ) ;
388 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
390 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
391 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
392 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
393 OSStatus result
= eventNotHandledErr
;
395 switch ( GetEventClass( event
) )
397 case kEventClassControl
:
398 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
400 case kEventClassService
:
401 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
405 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
409 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
411 // ---------------------------------------------------------------------------
412 // UserPane events for non OSX builds
413 // ---------------------------------------------------------------------------
415 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
417 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
418 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
419 win
->MacControlUserPaneDrawProc(part
) ;
422 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
424 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
425 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
426 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
429 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
431 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
432 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
433 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
436 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
438 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
439 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
440 win
->MacControlUserPaneIdleProc() ;
443 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
445 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
446 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
447 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
450 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
452 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
453 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
454 win
->MacControlUserPaneActivateProc(activating
) ;
457 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
459 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
460 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
461 return win
->MacControlUserPaneFocusProc(action
) ;
464 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
466 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
467 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
468 win
->MacControlUserPaneBackgroundProc(info
) ;
471 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
473 RgnHandle rgn
= NewRgn() ;
475 wxMacWindowStateSaver
sv( this ) ;
476 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
477 MacDoRedraw( rgn
, 0 ) ;
481 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
483 return kControlNoPart
;
486 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
488 return kControlNoPart
;
491 void wxWindowMac::MacControlUserPaneIdleProc()
495 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
497 return kControlNoPart
;
500 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
504 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
506 return kControlNoPart
;
509 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
513 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
514 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
515 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
516 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
517 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
518 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
519 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
520 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
522 // ===========================================================================
524 // ===========================================================================
526 wxList
wxWinMacControlList(wxKEY_INTEGER
);
528 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
530 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
533 return (wxControl
*)node
->GetData();
536 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
538 // adding NULL ControlRef is (first) surely a result of an error and
539 // (secondly) breaks native event processing
540 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
542 if ( !wxWinMacControlList
.Find((long)inControl
) )
543 wxWinMacControlList
.Append((long)inControl
, control
);
546 void wxRemoveMacControlAssociation(wxWindow
*control
)
548 wxWinMacControlList
.DeleteObject(control
);
552 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
554 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
556 // we have to setup the brush in the current port and return noErr
557 // or return an error code so that the control manager walks further up the
558 // hierarchy to find a correct background
560 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
562 OSStatus status
= paramErr
;
565 case kControlMsgApplyTextColor
:
567 case kControlMsgSetUpBackground
:
569 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
573 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
576 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
578 // this clipping is only needed for non HIView
580 RgnHandle clip
= NewRgn() ;
583 wx
->MacWindowToRootWindow( &x
,&y
) ;
584 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
585 OffsetRgn( clip
, x
, y
) ;
592 else if ( wx->MacIsUserPane() )
594 // if we don't have a valid brush for such a control, we have to call the
595 // setup of our parent ourselves
596 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
609 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
610 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
614 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
617 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
622 // ----------------------------------------------------------------------------
623 // constructors and such
624 // ----------------------------------------------------------------------------
626 wxWindowMac::wxWindowMac()
631 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
636 const wxString
& name
)
639 Create(parent
, id
, pos
, size
, style
, name
);
642 void wxWindowMac::Init()
646 #if WXWIN_COMPATIBILITY_2_4
647 m_backgroundTransparent
= FALSE
;
650 // as all windows are created with WS_VISIBLE style...
653 m_hScrollBar
= NULL
;
654 m_vScrollBar
= NULL
;
655 m_macBackgroundBrush
= wxNullBrush
;
657 m_macIsUserPane
= TRUE
;
659 // make sure all proc ptrs are available
661 if ( gControlUserPaneDrawUPP
== NULL
)
663 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
664 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
665 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
666 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
667 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
668 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
669 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
670 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
672 if ( wxMacLiveScrollbarActionUPP
== NULL
)
674 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
677 if ( wxMacSetupControlBackgroundUPP
== NULL
)
679 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
682 // we need a valid font for the encodings
683 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
687 wxWindowMac::~wxWindowMac()
691 m_isBeingDeleted
= TRUE
;
695 // deleting a window while it is shown invalidates the region occupied by border or
697 int outerBorder
= MacGetLeftBorderSize() ;
698 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
701 if ( IsShown() && ( outerBorder
> 0 ) )
703 // as the borders are drawn on the parent we have to properly invalidate all these areas
704 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
708 m_peer
->GetRect( &rect
) ;
709 RectRgn( updateInner
, &rect
) ;
710 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
711 RectRgn( updateOuter
, &rect
) ;
712 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
714 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
715 parent
-= GetParent()->GetClientAreaOrigin() ;
716 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
717 CopyRgn( updateOuter
, updateTotal
) ;
719 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
720 DisposeRgn(updateOuter
) ;
721 DisposeRgn(updateInner
) ;
722 DisposeRgn(updateTotal
) ;
726 #ifndef __WXUNIVERSAL__
727 // VS: make sure there's no wxFrame with last focus set to us:
728 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
730 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
733 if ( frame
->GetLastFocus() == this )
735 frame
->SetLastFocus((wxWindow
*)NULL
);
740 #endif // __WXUNIVERSAL__
742 // destroy children before destroying this window itself
745 // wxRemoveMacControlAssociation( this ) ;
746 // If we delete an item, we should initialize the parent panel,
747 // because it could now be invalid.
748 wxWindow
*parent
= GetParent() ;
751 if (parent
->GetDefaultItem() == (wxButton
*) this)
752 parent
->SetDefaultItem(NULL
);
754 if ( m_peer
&& m_peer
->Ok() )
756 // in case the callback might be called during destruction
757 wxRemoveMacControlAssociation( this) ;
758 // we currently are not using this hook
759 // ::SetControlColorProc( *m_peer , NULL ) ;
763 if ( g_MacLastWindow
== this )
765 g_MacLastWindow
= NULL
;
768 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
771 if ( frame
->GetLastFocus() == this )
772 frame
->SetLastFocus( NULL
) ;
775 // delete our drop target if we've got one
776 #if wxUSE_DRAG_AND_DROP
777 if ( m_dropTarget
!= NULL
)
782 #endif // wxUSE_DRAG_AND_DROP
786 WXWidget
wxWindowMac::GetHandle() const
788 return (WXWidget
) m_peer
->GetControlRef() ;
792 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
794 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
795 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
796 GetEventTypeCount(eventList
), eventList
, this,
797 (EventHandlerRef
*)&m_macControlEventHandler
);
802 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
806 const wxString
& name
)
808 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
810 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
813 parent
->AddChild(this);
815 m_windowVariant
= parent
->GetWindowVariant() ;
817 if ( m_macIsUserPane
)
819 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
822 | kControlSupportsEmbedding
823 // | kControlSupportsLiveFeedback
824 // | kControlHasSpecialBackground
825 // | kControlSupportsCalcBestRect
826 // | kControlHandlesTracking
827 | kControlSupportsFocus
828 // | kControlWantsActivate
829 // | kControlWantsIdle
832 m_peer
= new wxMacControl() ;
833 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
836 MacPostControlCreate(pos
,size
) ;
837 #if !TARGET_API_MAC_OSX
838 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
839 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
840 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
841 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
842 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
843 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
844 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
845 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
848 #ifndef __WXUNIVERSAL__
849 // Don't give scrollbars to wxControls unless they ask for them
850 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
851 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
853 MacCreateScrollBars( style
) ;
857 wxWindowCreateEvent
event(this);
858 GetEventHandler()->AddPendingEvent(event
);
863 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
865 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
867 m_peer
->SetReference( (long) this ) ;
869 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
871 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
872 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
873 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
875 // adjust font, controlsize etc
876 DoSetWindowVariant( m_windowVariant
) ;
878 #if !TARGET_API_MAC_OSX
879 // eventually we can fix some clipping issues be reactivating this hook
880 //if ( m_macIsUserPane )
881 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
883 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
885 if (!m_macIsUserPane
)
887 SetInitialBestSize(size
);
890 SetCursor( *wxSTANDARD_CURSOR
) ;
893 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
895 // Don't assert, in case we set the window variant before
896 // the window is created
897 // wxASSERT( m_peer->Ok() ) ;
899 m_windowVariant
= variant
;
901 if (m_peer
== NULL
|| !m_peer
->Ok())
905 ThemeFontID themeFont
= kThemeSystemFont
;
907 // we will get that from the settings later
908 // and make this NORMAL later, but first
909 // we have a few calculations that we must fix
913 case wxWINDOW_VARIANT_NORMAL
:
914 size
= kControlSizeNormal
;
915 themeFont
= kThemeSystemFont
;
917 case wxWINDOW_VARIANT_SMALL
:
918 size
= kControlSizeSmall
;
919 themeFont
= kThemeSmallSystemFont
;
921 case wxWINDOW_VARIANT_MINI
:
922 if (UMAGetSystemVersion() >= 0x1030 )
924 // not always defined in the headers
930 size
= kControlSizeSmall
;
931 themeFont
= kThemeSmallSystemFont
;
934 case wxWINDOW_VARIANT_LARGE
:
935 size
= kControlSizeLarge
;
936 themeFont
= kThemeSystemFont
;
939 wxFAIL_MSG(_T("unexpected window variant"));
942 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
945 font
.MacCreateThemeFont( themeFont
) ;
949 void wxWindowMac::MacUpdateControlFont()
951 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
955 bool wxWindowMac::SetFont(const wxFont
& font
)
957 bool retval
= wxWindowBase::SetFont( font
) ;
959 MacUpdateControlFont() ;
964 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
966 if ( !wxWindowBase::SetForegroundColour(col
) )
969 MacUpdateControlFont() ;
974 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
976 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
980 wxColour
newCol(GetBackgroundColour());
981 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
983 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
985 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
987 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
991 brush
.SetColour( newCol
) ;
993 MacSetBackgroundBrush( brush
) ;
995 MacUpdateControlFont() ;
1000 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1002 m_macBackgroundBrush
= brush
;
1003 m_peer
->SetBackground( brush
) ;
1006 bool wxWindowMac::MacCanFocus() const
1008 // there is currently no way to determine whether the window is running in full keyboard
1009 // access mode, therefore we cannot rely on these features, yet the only other way would be
1010 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1011 // in event handlers...
1012 UInt32 features
= 0 ;
1013 m_peer
->GetFeatures( & features
) ;
1014 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1018 void wxWindowMac::SetFocus()
1020 if ( AcceptsFocus() )
1023 wxWindow
* former
= FindFocus() ;
1024 if ( former
== this )
1027 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1028 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1029 // leave in case of an error
1030 if ( err
== errCouldntSetFocus
)
1033 #if !TARGET_API_MAC_OSX
1034 // emulate carbon events when running under carbonlib where they are not natively available
1037 EventRef evRef
= NULL
;
1038 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1041 wxMacCarbonEvent
cEvent( evRef
) ;
1042 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1043 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1045 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1046 ReleaseEvent(evRef
) ;
1048 // send new focus event
1050 EventRef evRef
= NULL
;
1051 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1054 wxMacCarbonEvent
cEvent( evRef
) ;
1055 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1056 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1058 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1059 ReleaseEvent(evRef
) ;
1066 void wxWindowMac::DoCaptureMouse()
1068 wxTheApp
->s_captureWindow
= this ;
1071 wxWindow
* wxWindowBase::GetCapture()
1073 return wxTheApp
->s_captureWindow
;
1076 void wxWindowMac::DoReleaseMouse()
1078 wxTheApp
->s_captureWindow
= NULL
;
1081 #if wxUSE_DRAG_AND_DROP
1083 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1085 if ( m_dropTarget
!= 0 ) {
1086 delete m_dropTarget
;
1089 m_dropTarget
= pDropTarget
;
1090 if ( m_dropTarget
!= 0 )
1098 // Old style file-manager drag&drop
1099 void wxWindowMac::DragAcceptFiles(bool accept
)
1104 // Returns the size of the native control. In the case of the toplevel window
1105 // this is the content area root control
1107 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1108 int& w
, int& h
) const
1111 m_peer
->GetRect( &bounds
) ;
1116 w
= bounds
.right
- bounds
.left
;
1117 h
= bounds
.bottom
- bounds
.top
;
1120 // From a wx position / size calculate the appropriate size of the native control
1122 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1125 int& w
, int& h
, bool adjustOrigin
) const
1127 // the desired size, minus the border pixels gives the correct size of the control
1131 // todo the default calls may be used as soon as PostCreateControl Is moved here
1132 w
= size
.x
; // WidthDefault( size.x );
1133 h
= size
.y
; // HeightDefault( size.y ) ;
1134 #if !TARGET_API_MAC_OSX
1135 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1138 x
+= MacGetLeftBorderSize() ;
1139 y
+= MacGetTopBorderSize() ;
1140 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1141 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1144 AdjustForParentClientOrigin( x
, y
) ;
1145 #if TARGET_API_MAC_OSX
1146 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1147 if ( ! GetParent()->IsTopLevel() )
1149 x
-= GetParent()->MacGetLeftBorderSize() ;
1150 y
-= GetParent()->MacGetTopBorderSize() ;
1156 // Get window size (not client size)
1157 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1159 // take the size of the control and add the borders that have to be drawn outside
1160 int x1
, y1
, w1
, h1
;
1162 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1164 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1165 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1171 // get the position of the bounds of this window in client coordinates of its parent
1172 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1174 int x1
, y1
, w1
,h1
;
1175 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1176 x1
-= MacGetLeftBorderSize() ;
1177 y1
-= MacGetTopBorderSize() ;
1179 #if !TARGET_API_MAC_OSX
1180 if ( !GetParent()->IsTopLevel() )
1183 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1188 if ( !IsTopLevel() )
1190 wxWindow
*parent
= GetParent();
1193 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1194 x1
+= parent
->MacGetLeftBorderSize() ;
1195 y1
+= parent
->MacGetTopBorderSize() ;
1196 // and now to client coordinates
1197 wxPoint
pt(parent
->GetClientAreaOrigin());
1206 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1208 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1210 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1213 Point localwhere
= {0,0} ;
1215 if(x
) localwhere
.h
= * x
;
1216 if(y
) localwhere
.v
= * y
;
1218 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1219 if(x
) *x
= localwhere
.h
;
1220 if(y
) *y
= localwhere
.v
;
1223 MacRootWindowToWindow( x
, y
) ;
1225 wxPoint origin
= GetClientAreaOrigin() ;
1226 if(x
) *x
-= origin
.x
;
1227 if(y
) *y
-= origin
.y
;
1230 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1232 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1233 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1235 wxPoint origin
= GetClientAreaOrigin() ;
1236 if(x
) *x
+= origin
.x
;
1237 if(y
) *y
+= origin
.y
;
1239 MacWindowToRootWindow( x
, y
) ;
1242 Point localwhere
= { 0,0 };
1243 if(x
) localwhere
.h
= * x
;
1244 if(y
) localwhere
.v
= * y
;
1245 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1246 if(x
) *x
= localwhere
.h
;
1247 if(y
) *y
= localwhere
.v
;
1251 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1253 wxPoint origin
= GetClientAreaOrigin() ;
1254 if(x
) *x
+= origin
.x
;
1255 if(y
) *y
+= origin
.y
;
1257 MacWindowToRootWindow( x
, y
) ;
1260 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1262 MacRootWindowToWindow( x
, y
) ;
1264 wxPoint origin
= GetClientAreaOrigin() ;
1265 if(x
) *x
-= origin
.x
;
1266 if(y
) *y
-= origin
.y
;
1269 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1271 #if TARGET_API_MAC_OSX
1273 if ( x
) pt
.x
= *x
;
1274 if ( y
) pt
.y
= *y
;
1276 if ( !IsTopLevel() )
1278 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1281 pt
.x
-= MacGetLeftBorderSize() ;
1282 pt
.y
-= MacGetTopBorderSize() ;
1283 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1287 if ( x
) *x
= (int) pt
.x
;
1288 if ( y
) *y
= (int) pt
.y
;
1290 if ( !IsTopLevel() )
1293 m_peer
->GetRect( &bounds
) ;
1294 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1295 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1300 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1305 MacWindowToRootWindow( &x1
, &y1
) ;
1310 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1312 #if TARGET_API_MAC_OSX
1314 if ( x
) pt
.x
= *x
;
1315 if ( y
) pt
.y
= *y
;
1317 if ( !IsTopLevel() )
1319 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1320 pt
.x
+= MacGetLeftBorderSize() ;
1321 pt
.y
+= MacGetTopBorderSize() ;
1324 if ( x
) *x
= (int) pt
.x
;
1325 if ( y
) *y
= (int) pt
.y
;
1327 if ( !IsTopLevel() )
1330 m_peer
->GetRect( &bounds
) ;
1331 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1332 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1337 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1342 MacRootWindowToWindow( &x1
, &y1
) ;
1347 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1349 RgnHandle rgn
= NewRgn() ;
1351 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1353 GetRegionBounds( rgn
, &content
) ;
1358 m_peer
->GetRect( &content
) ;
1361 m_peer
->GetRect( &structure
) ;
1362 #if !TARGET_API_MAC_OSX
1363 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1365 left
= content
.left
- structure
.left
;
1366 top
= content
.top
- structure
.top
;
1367 right
= structure
.right
- content
.right
;
1368 bottom
= structure
.bottom
- content
.bottom
;
1371 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1373 wxSize sizeTotal
= size
;
1375 RgnHandle rgn
= NewRgn() ;
1379 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1381 GetRegionBounds( rgn
, &content
) ;
1386 m_peer
->GetRect( &content
) ;
1389 m_peer
->GetRect( &structure
) ;
1390 #if !TARGET_API_MAC_OSX
1391 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1394 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1395 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1397 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1398 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1404 // Get size *available for subwindows* i.e. excluding menu bar etc.
1405 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1409 RgnHandle rgn
= NewRgn() ;
1411 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1413 GetRegionBounds( rgn
, &content
) ;
1418 m_peer
->GetRect( &content
) ;
1420 #if !TARGET_API_MAC_OSX
1422 m_peer
->GetRect( &structure
) ;
1423 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1425 ww
= content
.right
- content
.left
;
1426 hh
= content
.bottom
- content
.top
;
1428 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1429 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1432 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1438 GetSize( &w , &h ) ;
1440 MacClientToRootWindow( &x1 , &y1 ) ;
1441 MacClientToRootWindow( &w , &h ) ;
1443 wxWindowMac *iter = (wxWindowMac*)this ;
1445 int totW = 10000 , totH = 10000;
1448 if ( iter->IsTopLevel() )
1450 iter->GetSize( &totW , &totH ) ;
1454 iter = iter->GetParent() ;
1457 if (m_hScrollBar && m_hScrollBar->IsShown() )
1459 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1465 if (m_vScrollBar && m_vScrollBar->IsShown() )
1467 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1475 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1477 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1479 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1481 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1488 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1490 if (m_cursor
== cursor
)
1493 if (wxNullCursor
== cursor
)
1495 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1500 if ( ! wxWindowBase::SetCursor( cursor
) )
1504 wxASSERT_MSG( m_cursor
.Ok(),
1505 wxT("cursor must be valid after call to the base version"));
1508 wxWindowMac
*mouseWin
= 0 ;
1510 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1512 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1514 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1515 // position, use it...
1519 ControlPartCode part
;
1520 ControlRef control
;
1521 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1523 mouseWin
= wxFindControlFromMacControl( control
) ;
1526 QDSwapPort( savePort
, NULL
) ;
1529 if ( mouseWin
== this && !wxIsBusy() )
1531 m_cursor
.MacInstall() ;
1538 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1540 menu
->SetInvokingWindow(this);
1543 if ( x
== -1 && y
== -1 )
1545 wxPoint mouse
= wxGetMousePosition();
1546 x
= mouse
.x
; y
= mouse
.y
;
1550 ClientToScreen( &x
, &y
) ;
1553 menu
->MacBeforeDisplay( true ) ;
1554 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1555 if ( HiWord(menuResult
) != 0 )
1558 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1559 wxMenuItem
* item
= NULL
;
1561 item
= menu
->FindItem(id
, &realmenu
) ;
1562 if (item
->IsCheckable())
1564 item
->Check( !item
->IsChecked() ) ;
1566 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1568 menu
->MacAfterDisplay( true ) ;
1570 menu
->SetInvokingWindow(NULL
);
1576 // ----------------------------------------------------------------------------
1578 // ----------------------------------------------------------------------------
1582 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1584 wxWindowBase::DoSetToolTip(tooltip
);
1587 m_tooltip
->SetWindow(this);
1590 #endif // wxUSE_TOOLTIPS
1592 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1594 // this is never called for a toplevel window, so we know we have a parent
1595 int former_x
, former_y
, former_w
, former_h
;
1597 // Get true coordinates of former position
1598 DoGetPosition( &former_x
, &former_y
) ;
1599 DoGetSize( &former_w
, &former_h
) ;
1601 wxWindow
*parent
= GetParent();
1604 wxPoint
pt(parent
->GetClientAreaOrigin());
1609 int actualWidth
= width
;
1610 int actualHeight
= height
;
1614 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1615 actualWidth
= m_minWidth
;
1616 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1617 actualHeight
= m_minHeight
;
1618 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1619 actualWidth
= m_maxWidth
;
1620 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1621 actualHeight
= m_maxHeight
;
1623 bool doMove
= false ;
1624 bool doResize
= false ;
1626 if ( actualX
!= former_x
|| actualY
!= former_y
)
1630 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1635 if ( doMove
|| doResize
)
1637 // we don't adjust twice for the origin
1638 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1639 bool vis
= m_peer
->IsVisible();
1641 int outerBorder
= MacGetLeftBorderSize() ;
1642 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1645 if ( vis
&& ( outerBorder
> 0 ) )
1647 // as the borders are drawn on the parent we have to properly invalidate all these areas
1648 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1652 m_peer
->GetRect( &rect
) ;
1653 RectRgn( updateInner
, &rect
) ;
1654 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1655 RectRgn( updateOuter
, &rect
) ;
1656 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1657 wxPoint
parent(0,0);
1658 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1659 parent
-= GetParent()->GetClientAreaOrigin() ;
1660 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1661 CopyRgn( updateOuter
, updateTotal
) ;
1664 RectRgn( updateInner
, &rect
) ;
1665 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1666 RectRgn( updateOuter
, &rect
) ;
1667 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1669 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1670 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1672 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1673 DisposeRgn(updateOuter
) ;
1674 DisposeRgn(updateInner
) ;
1675 DisposeRgn(updateTotal
) ;
1678 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1680 m_peer
->SetVisibility( false , true ) ;
1682 m_peer
->SetRect( &r
) ;
1684 m_peer
->SetVisibility( true , true ) ;
1686 MacRepositionScrollBars() ;
1689 wxPoint
point(actualX
,actualY
);
1690 wxMoveEvent
event(point
, m_windowId
);
1691 event
.SetEventObject(this);
1692 GetEventHandler()->ProcessEvent(event
) ;
1696 MacRepositionScrollBars() ;
1697 wxSize
size(actualWidth
, actualHeight
);
1698 wxSizeEvent
event(size
, m_windowId
);
1699 event
.SetEventObject(this);
1700 GetEventHandler()->ProcessEvent(event
);
1706 wxSize
wxWindowMac::DoGetBestSize() const
1708 if ( m_macIsUserPane
|| IsTopLevel() )
1709 return wxWindowBase::DoGetBestSize() ;
1711 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1712 int bestWidth
, bestHeight
;
1713 m_peer
->GetBestRect( &bestsize
) ;
1715 if ( EmptyRect( &bestsize
) )
1717 bestsize
.left
= bestsize
.top
= 0 ;
1718 bestsize
.right
= 16 ;
1719 bestsize
.bottom
= 16 ;
1720 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1722 bestsize
.bottom
= 16 ;
1724 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1726 bestsize
.bottom
= 24 ;
1730 // return wxWindowBase::DoGetBestSize() ;
1734 bestWidth
= bestsize
.right
- bestsize
.left
;
1735 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1736 if ( bestHeight
< 10 )
1739 return wxSize(bestWidth
, bestHeight
);
1743 // set the size of the window: if the dimensions are positive, just use them,
1744 // but if any of them is equal to -1, it means that we must find the value for
1745 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1746 // which case -1 is a valid value for x and y)
1748 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1749 // the width/height to best suit our contents, otherwise we reuse the current
1751 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1753 // get the current size and position...
1754 int currentX
, currentY
;
1755 GetPosition(¤tX
, ¤tY
);
1757 int currentW
,currentH
;
1758 GetSize(¤tW
, ¤tH
);
1760 // ... and don't do anything (avoiding flicker) if it's already ok
1761 if ( x
== currentX
&& y
== currentY
&&
1762 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1765 MacRepositionScrollBars() ; // we might have a real position shift
1769 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1771 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1774 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1776 wxSize
size(-1, -1);
1779 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1781 size
= DoGetBestSize();
1786 // just take the current one
1793 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1797 size
= DoGetBestSize();
1799 //else: already called DoGetBestSize() above
1805 // just take the current one
1810 DoMoveWindow(x
, y
, width
, height
);
1814 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1816 RgnHandle rgn
= NewRgn() ;
1818 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1819 GetRegionBounds( rgn
, &content
) ;
1821 #if !TARGET_API_MAC_OSX
1822 // if the content rgn is empty / not supported
1823 // don't attempt to correct the coordinates to wxWindow relative ones
1824 if (!::EmptyRect( &content
) )
1827 m_peer
->GetRect( &structure
) ;
1828 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1832 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1835 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1837 if ( clientheight
!= -1 || clientheight
!= -1 )
1839 int currentclientwidth
, currentclientheight
;
1840 int currentwidth
, currentheight
;
1842 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1843 GetSize( ¤twidth
, ¤theight
) ;
1845 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1846 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1850 void wxWindowMac::SetTitle(const wxString
& title
)
1852 m_label
= wxStripMenuCodes(title
) ;
1854 if ( m_peer
&& m_peer
->Ok() )
1856 m_peer
->SetTitle( m_label
) ;
1861 wxString
wxWindowMac::GetTitle() const
1866 bool wxWindowMac::Show(bool show
)
1868 if ( !wxWindowBase::Show(show
) )
1871 // TODO use visibilityChanged Carbon Event for OSX
1872 bool former
= MacIsReallyShown() ;
1874 m_peer
->SetVisibility( show
, true ) ;
1875 if ( former
!= MacIsReallyShown() )
1876 MacPropagateVisibilityChanged() ;
1880 bool wxWindowMac::Enable(bool enable
)
1882 wxASSERT( m_peer
->Ok() ) ;
1883 if ( !wxWindowBase::Enable(enable
) )
1886 bool former
= MacIsReallyEnabled() ;
1887 m_peer
->Enable( enable
) ;
1889 if ( former
!= MacIsReallyEnabled() )
1890 MacPropagateEnabledStateChanged() ;
1895 // status change propagations (will be not necessary for OSX later )
1898 void wxWindowMac::MacPropagateVisibilityChanged()
1900 #if !TARGET_API_MAC_OSX
1901 MacVisibilityChanged() ;
1903 wxWindowListNode
*node
= GetChildren().GetFirst();
1906 wxWindowMac
*child
= node
->GetData();
1907 if ( child
->IsShown() )
1908 child
->MacPropagateVisibilityChanged( ) ;
1909 node
= node
->GetNext();
1914 void wxWindowMac::MacPropagateEnabledStateChanged( )
1916 #if !TARGET_API_MAC_OSX
1917 MacEnabledStateChanged() ;
1919 wxWindowListNode
*node
= GetChildren().GetFirst();
1922 wxWindowMac
*child
= node
->GetData();
1923 if ( child
->IsEnabled() )
1924 child
->MacPropagateEnabledStateChanged() ;
1925 node
= node
->GetNext();
1930 void wxWindowMac::MacPropagateHiliteChanged( )
1932 #if !TARGET_API_MAC_OSX
1933 MacHiliteChanged() ;
1935 wxWindowListNode
*node
= GetChildren().GetFirst();
1938 wxWindowMac
*child
= node
->GetData();
1939 // if ( child->IsEnabled() )
1940 child
->MacPropagateHiliteChanged() ;
1941 node
= node
->GetNext();
1947 // status change notifications
1950 void wxWindowMac::MacVisibilityChanged()
1954 void wxWindowMac::MacHiliteChanged()
1958 void wxWindowMac::MacEnabledStateChanged()
1963 // status queries on the inherited window's state
1966 bool wxWindowMac::MacIsReallyShown()
1968 // only under OSX the visibility of the TLW is taken into account
1969 #if TARGET_API_MAC_OSX
1970 if ( m_peer
&& m_peer
->Ok() )
1971 return m_peer
->IsVisible();
1973 wxWindow
* win
= this ;
1974 while( win
->IsShown() )
1976 if ( win
->IsTopLevel() )
1979 win
= win
->GetParent() ;
1987 bool wxWindowMac::MacIsReallyEnabled()
1989 return m_peer
->IsEnabled() ;
1992 bool wxWindowMac::MacIsReallyHilited()
1994 return m_peer
->IsActive();
1997 void wxWindowMac::MacFlashInvalidAreas()
1999 #if TARGET_API_MAC_OSX
2000 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2008 int wxWindowMac::GetCharHeight() const
2010 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2011 return dc
.GetCharHeight() ;
2014 int wxWindowMac::GetCharWidth() const
2016 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2017 return dc
.GetCharWidth() ;
2020 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2021 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2023 const wxFont
*fontToUse
= theFont
;
2025 fontToUse
= &m_font
;
2027 wxClientDC
dc( (wxWindowMac
*) this ) ;
2029 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2030 if ( externalLeading
)
2031 *externalLeading
= le
;
2041 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2042 * we always intersect with the entire window, not only with the client area
2045 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2047 if ( m_peer
== NULL
)
2050 #if TARGET_API_MAC_OSX
2052 m_peer
->SetNeedsDisplay( true ) ;
2055 RgnHandle update
= NewRgn() ;
2056 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2057 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2058 wxPoint origin
= GetClientAreaOrigin() ;
2059 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2060 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2062 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2063 m_peer
->SetNeedsDisplay( true , update
) ;
2064 DisposeRgn( update
) ;
2068 RgnHandle updateRgn = NewRgn() ;
2071 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2075 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2076 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2078 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2079 DisposeRgn(updateRgn) ;
2081 if ( m_peer
->IsVisible())
2083 m_peer
->SetVisibility( false , false ) ;
2084 m_peer
->SetVisibility( true , true ) ;
2087 if ( MacGetTopLevelWindow() == NULL )
2090 if ( !m_peer->IsVisible())
2093 wxPoint client = GetClientAreaOrigin();
2096 int x2 = m_width - client.x;
2097 int y2 = m_height - client.y;
2099 if (IsKindOf( CLASSINFO(wxButton)))
2101 // buttons have an "aura"
2108 Rect clientrect = { y1, x1, y2, x2 };
2112 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2113 SectRect( &clientrect , &r , &clientrect ) ;
2116 if ( !EmptyRect( &clientrect ) )
2118 int top = 0 , left = 0 ;
2120 MacClientToRootWindow( &left , &top ) ;
2121 OffsetRect( &clientrect , left , top ) ;
2123 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2129 void wxWindowMac::Freeze()
2131 #if TARGET_API_MAC_OSX
2132 if ( !m_frozenness
++ )
2134 if ( m_peer
&& m_peer
->Ok() )
2135 m_peer
->SetDrawingEnabled( false ) ;
2141 void wxWindowMac::Thaw()
2143 #if TARGET_API_MAC_OSX
2144 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2146 if ( !--m_frozenness
)
2148 if ( m_peer
&& m_peer
->Ok() )
2150 m_peer
->SetDrawingEnabled( true ) ;
2151 m_peer
->InvalidateWithChildren() ;
2157 void wxWindowMac::MacRedrawControl()
2160 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2162 #if TARGET_API_MAC_CARBON
2165 wxClientDC dc(this) ;
2166 wxMacPortSetter helper(&dc) ;
2167 wxMacWindowClipper clipper(this) ;
2168 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2169 UMADrawControl( *m_peer ) ;
2176 void wxWindowMac::OnPaint(wxPaintEvent& event)
2178 // why don't we skip that here ?
2182 wxWindowMac
*wxGetActiveWindow()
2184 // actually this is a windows-only concept
2188 // Coordinates relative to the window
2189 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2191 // We really don't move the mouse programmatically under Mac.
2194 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2196 #if TARGET_API_MAC_OSX
2197 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2204 event
.GetDC()->Clear() ;
2208 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2213 int wxWindowMac::GetScrollPos(int orient
) const
2215 if ( orient
== wxHORIZONTAL
)
2218 return m_hScrollBar
->GetThumbPosition() ;
2223 return m_vScrollBar
->GetThumbPosition() ;
2228 // This now returns the whole range, not just the number
2229 // of positions that we can scroll.
2230 int wxWindowMac::GetScrollRange(int orient
) const
2232 if ( orient
== wxHORIZONTAL
)
2235 return m_hScrollBar
->GetRange() ;
2240 return m_vScrollBar
->GetRange() ;
2245 int wxWindowMac::GetScrollThumb(int orient
) const
2247 if ( orient
== wxHORIZONTAL
)
2250 return m_hScrollBar
->GetThumbSize() ;
2255 return m_vScrollBar
->GetThumbSize() ;
2260 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2262 if ( orient
== wxHORIZONTAL
)
2265 m_hScrollBar
->SetThumbPosition( pos
) ;
2270 m_vScrollBar
->SetThumbPosition( pos
) ;
2274 void wxWindowMac::MacPaintBorders( int left
, int top
)
2280 m_peer
->GetRect( &rect
) ;
2281 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2283 if ( !IsTopLevel() )
2285 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2289 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2291 rect
.right
+= pt
.x
;
2293 rect
.bottom
+= pt
.y
;
2297 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2301 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2302 InsetRect( &srect
, border
, border
);
2303 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2305 else if (HasFlag(wxSIMPLE_BORDER
))
2309 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2310 InsetRect( &srect
, border
, border
);
2311 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2315 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2317 if ( child
== m_hScrollBar
)
2318 m_hScrollBar
= NULL
;
2319 if ( child
== m_vScrollBar
)
2320 m_vScrollBar
= NULL
;
2322 wxWindowBase::RemoveChild( child
) ;
2325 // New function that will replace some of the above.
2326 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2327 int range
, bool refresh
)
2329 if ( orient
== wxHORIZONTAL
)
2333 if ( range
== 0 || thumbVisible
>= range
)
2335 if ( m_hScrollBar
->IsShown() )
2336 m_hScrollBar
->Show(false) ;
2340 if ( !m_hScrollBar
->IsShown() )
2341 m_hScrollBar
->Show(true) ;
2342 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2350 if ( range
== 0 || thumbVisible
>= range
)
2352 if ( m_vScrollBar
->IsShown() )
2353 m_vScrollBar
->Show(false) ;
2357 if ( !m_vScrollBar
->IsShown() )
2358 m_vScrollBar
->Show(true) ;
2359 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2363 MacRepositionScrollBars() ;
2366 // Does a physical scroll
2367 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2369 if( dx
== 0 && dy
==0 )
2375 int width
, height
;
2376 GetClientSize( &width
, &height
) ;
2377 #if TARGET_API_MAC_OSX
2378 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2379 // area is scrolled, this does not occur if width and height are 2 pixels less,
2380 // TODO write optimal workaround
2381 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2384 scrollrect
.Intersect( *rect
) ;
2386 if ( m_peer
->GetNeedsDisplay() )
2388 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2389 // either immediate redraw or full invalidate
2391 // is the better overall solution, as it does not slow down scrolling
2392 m_peer
->SetNeedsDisplay( true ) ;
2394 // this would be the preferred version for fast drawing controls
2395 if( UMAGetSystemVersion() < 0x1030 )
2398 HIViewRender(m_peer
->GetControlRef()) ;
2401 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2402 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2403 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2410 RgnHandle updateRgn
= NewRgn() ;
2413 wxClientDC
dc(this) ;
2414 wxMacPortSetter
helper(&dc
) ;
2416 m_peer
->GetRect( &scrollrect
) ;
2417 scrollrect
.top
+= MacGetTopBorderSize() ;
2418 scrollrect
.left
+= MacGetLeftBorderSize() ;
2419 scrollrect
.bottom
= scrollrect
.top
+ height
;
2420 scrollrect
.right
= scrollrect
.left
+ width
;
2424 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2425 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2426 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2428 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2430 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2434 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2436 wxWindowMac
*child
= node
->GetData();
2437 if (child
== m_vScrollBar
) continue;
2438 if (child
== m_hScrollBar
) continue;
2439 if (child
->IsTopLevel()) continue;
2442 child
->GetPosition( &x
, &y
);
2444 child
->GetSize( &w
, &h
);
2448 if (rect
->Intersects(rc
))
2449 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2453 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2458 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2460 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2462 wxScrollWinEvent wevent
;
2463 wevent
.SetPosition(event
.GetPosition());
2464 wevent
.SetOrientation(event
.GetOrientation());
2465 wevent
.m_eventObject
= this;
2467 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2468 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2469 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2470 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2471 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2472 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2473 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2474 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2475 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2476 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2477 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2478 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2479 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2480 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2481 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2482 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2484 GetEventHandler()->ProcessEvent(wevent
);
2488 // Get the window with the focus
2489 wxWindowMac
*wxWindowBase::FindFocus()
2491 ControlRef control
;
2492 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2493 return wxFindControlFromMacControl( control
) ;
2496 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2498 // panel wants to track the window which was the last to have focus in it,
2499 // so we want to set ourselves as the window which last had focus
2501 // notice that it's also important to do it upwards the tree becaus
2502 // otherwise when the top level panel gets focus, it won't set it back to
2503 // us, but to some other sibling
2505 // CS:don't know if this is still needed:
2506 //wxChildFocusEvent eventFocus(this);
2507 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2509 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2511 wxMacWindowStateSaver
sv( this ) ;
2516 MacWindowToRootWindow( &x
, &y
) ;
2517 GetSize( &w
, &h
) ;
2518 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2520 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2521 DrawThemeFocusRect( &rect
, true ) ;
2524 DrawThemeFocusRect( &rect
, false ) ;
2526 // as this erases part of the frame we have to redraw borders
2527 // and because our z-ordering is not always correct (staticboxes)
2528 // we have to invalidate things, we cannot simple redraw
2529 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2530 RectRgn( updateInner
, &rect
) ;
2531 InsetRect( &rect
, -4 , -4 ) ;
2532 RectRgn( updateOuter
, &rect
) ;
2533 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2534 wxPoint
parent(0,0);
2535 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2536 parent
-= GetParent()->GetClientAreaOrigin() ;
2537 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2538 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2539 DisposeRgn(updateOuter
) ;
2540 DisposeRgn(updateInner
) ;
2547 void wxWindowMac::OnInternalIdle()
2549 // This calls the UI-update mechanism (querying windows for
2550 // menu/toolbar/control state information)
2551 if (wxUpdateUIEvent::CanUpdate(this))
2552 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2555 // Raise the window to the top of the Z order
2556 void wxWindowMac::Raise()
2558 m_peer
->SetZOrder( true , NULL
) ;
2561 // Lower the window to the bottom of the Z order
2562 void wxWindowMac::Lower()
2564 m_peer
->SetZOrder( false , NULL
) ;
2568 // static wxWindow *gs_lastWhich = NULL;
2570 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2572 // first trigger a set cursor event
2574 wxPoint clientorigin
= GetClientAreaOrigin() ;
2575 wxSize clientsize
= GetClientSize() ;
2577 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2579 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2581 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2582 if ( processedEvtSetCursor
&& event
.HasCursor() )
2584 cursor
= event
.GetCursor() ;
2589 // the test for processedEvtSetCursor is here to prevent using m_cursor
2590 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2591 // it - this is a way to say that our cursor shouldn't be used for this
2593 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2603 cursor
= *wxSTANDARD_CURSOR
;
2607 cursor
.MacInstall() ;
2609 return cursor
.Ok() ;
2612 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2616 return m_tooltip
->GetTip() ;
2618 return wxEmptyString
;
2621 void wxWindowMac::Update()
2623 #if TARGET_API_MAC_OSX
2625 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2626 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2628 // for composited windows this also triggers a redraw of all
2629 // invalid views in the window
2630 if( UMAGetSystemVersion() >= 0x1030 )
2631 HIWindowFlush(window
) ;
2635 // the only way to trigger the redrawing on earlier systems is to call
2638 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2639 UInt32 currentEventClass
= 0 ;
2640 UInt32 currentEventKind
= 0 ;
2641 if ( currentEvent
!= NULL
)
2643 currentEventClass
= ::GetEventClass( currentEvent
) ;
2644 currentEventKind
= ::GetEventKind( currentEvent
) ;
2646 if ( currentEventClass
!= kEventClassMenu
)
2648 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2651 OSStatus status
= noErr
;
2652 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2655 m_peer
->SetNeedsDisplay( true ) ;
2658 ::Draw1Control( m_peer
->GetControlRef() ) ;
2662 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2664 wxTopLevelWindowMac
* win
= NULL
;
2665 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2668 win
= wxFindWinFromMacWindow( window
) ;
2672 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2674 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2675 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2676 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2677 // to add focus borders everywhere
2680 RgnHandle visRgn
= NewRgn() ;
2681 RgnHandle tempRgn
= NewRgn() ;
2682 if ( m_peer
->IsVisible())
2684 m_peer
->GetRect( &r
) ;
2685 r
.left
-= MacGetLeftBorderSize() ;
2686 r
.top
-= MacGetTopBorderSize() ;
2687 r
.bottom
+= MacGetBottomBorderSize() ;
2688 r
.right
+= MacGetRightBorderSize() ;
2690 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2692 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2693 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2702 if ( includeOuterStructures
)
2703 InsetRect( &r
, -4 , -4 ) ;
2704 RectRgn( visRgn
, &r
) ;
2706 if ( !IsTopLevel() )
2708 wxWindow
* child
= this ;
2709 wxWindow
* parent
= child
->GetParent() ;
2714 // we have to find a better clipping algorithm here, in order not to clip things
2715 // positioned like status and toolbar
2716 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2718 size
= parent
->GetSize() ;
2723 size
= parent
->GetClientSize() ;
2724 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2728 parent
->MacWindowToRootWindow( &x
, &y
) ;
2729 MacRootWindowToWindow( &x
, &y
) ;
2731 if ( !includeOuterStructures
|| (
2732 parent
->MacClipChildren() ||
2733 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2736 SetRectRgn( tempRgn
,
2737 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2738 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2739 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2741 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2743 if ( parent
->IsTopLevel() )
2746 parent
= child
->GetParent() ;
2751 wxRegion vis
= visRgn
;
2752 DisposeRgn( visRgn
) ;
2753 DisposeRgn( tempRgn
) ;
2758 This function must not change the updatergn !
2760 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2762 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2763 bool handled
= false ;
2765 GetRegionBounds( updatergn
, &updatebounds
) ;
2766 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2767 if ( !EmptyRgn(updatergn
) )
2769 RgnHandle newupdate
= NewRgn() ;
2770 wxSize point
= GetClientSize() ;
2771 wxPoint origin
= GetClientAreaOrigin() ;
2772 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2773 SectRgn( newupdate
, updatergn
, newupdate
) ;
2775 // first send an erase event to the entire update area
2777 wxWindowDC
dc(this);
2778 dc
.SetClippingRegion(wxRegion(updatergn
));
2779 wxEraseEvent
eevent( GetId(), &dc
);
2780 eevent
.SetEventObject( this );
2781 GetEventHandler()->ProcessEvent( eevent
);
2784 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2785 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2786 m_updateRegion
= newupdate
;
2787 DisposeRgn( newupdate
) ;
2789 if ( !m_updateRegion
.Empty() )
2791 // paint the window itself
2793 event
.m_timeStamp
= time
;
2794 event
.SetEventObject(this);
2795 handled
= GetEventHandler()->ProcessEvent(event
);
2797 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2800 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2802 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2809 // now we cannot rely on having its borders drawn by a window itself, as it does not
2810 // get the updateRgn wide enough to always do so, so we do it from the parent
2811 // this would also be the place to draw any custom backgrounds for native controls
2812 // in Composited windowing
2813 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2815 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2817 wxWindowMac
*child
= node
->GetData();
2818 if (child
== m_vScrollBar
) continue;
2819 if (child
== m_hScrollBar
) continue;
2820 if (child
->IsTopLevel()) continue;
2821 if (!child
->IsShown()) continue;
2824 child
->GetPosition( &x
, &y
);
2826 child
->GetSize( &w
, &h
);
2827 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2828 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2829 if ( child
->MacGetTopBorderSize() )
2831 if ( RectInRgn( &childRect
, updatergn
) )
2833 // paint custom borders
2834 wxNcPaintEvent
eventNc( child
->GetId() );
2835 eventNc
.SetEventObject( child
);
2836 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2838 wxWindowDC
dc(this) ;
2839 dc
.SetClippingRegion(wxRegion(updatergn
));
2840 wxMacPortSetter
helper(&dc
) ;
2841 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2845 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2847 wxWindowDC
dc(this) ;
2848 dc
.SetClippingRegion(wxRegion(updatergn
));
2849 wxMacPortSetter
helper(&dc
) ;
2850 Rect r
= childRect
;
2851 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2852 DrawThemeFocusRect( &r
, true ) ;
2859 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2861 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2862 // updatergn is always already clipped to our boundaries
2863 // if we are in compositing mode then it is in relative to the upper left of the control
2864 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2865 // of the toplevel window
2866 // it is in window coordinates, not in client coordinates
2868 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2869 RgnHandle ownUpdateRgn
= NewRgn() ;
2870 CopyRgn( updatergn
, ownUpdateRgn
) ;
2872 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2875 m_peer
->GetRectInWindowCoords( &bounds
);
2876 RgnHandle controlRgn
= NewRgn();
2877 RectRgn( controlRgn
, &bounds
);
2878 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2879 // the window update region
2880 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2881 DisposeRgn( controlRgn
);
2883 //KO: convert ownUpdateRgn to local coordinates
2884 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2887 MacDoRedraw( ownUpdateRgn
, time
) ;
2888 DisposeRgn( ownUpdateRgn
) ;
2892 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2894 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2898 if ( iter
->IsTopLevel() )
2899 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2901 iter
= iter
->GetParent() ;
2903 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2907 void wxWindowMac::MacCreateScrollBars( long style
)
2909 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2911 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2913 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2914 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2915 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2916 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2918 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2919 variant
= wxWINDOW_VARIANT_SMALL
;
2922 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2924 GetClientSize( &width
, &height
) ;
2926 wxPoint
vPoint(width
-scrlsize
, 0) ;
2927 wxSize
vSize(scrlsize
, height
- adjust
) ;
2928 wxPoint
hPoint(0 , height
-scrlsize
) ;
2929 wxSize
hSize( width
- adjust
, scrlsize
) ;
2932 if ( style
& wxVSCROLL
)
2934 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2935 vSize
, wxVERTICAL
);
2938 if ( style
& wxHSCROLL
)
2940 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2941 hSize
, wxHORIZONTAL
);
2946 // because the create does not take into account the client area origin
2947 MacRepositionScrollBars() ; // we might have a real position shift
2950 void wxWindowMac::MacRepositionScrollBars()
2952 if ( !m_hScrollBar
&& !m_vScrollBar
)
2955 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2956 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2957 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2959 // get real client area
2963 GetSize( &width
, &height
) ;
2965 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2966 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2968 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2969 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2970 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2971 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2977 GetSize( &w , &h ) ;
2979 MacClientToRootWindow( &x , &y ) ;
2980 MacClientToRootWindow( &w , &h ) ;
2982 wxWindowMac *iter = (wxWindowMac*)this ;
2984 int totW = 10000 , totH = 10000;
2987 if ( iter->IsTopLevel() )
2989 iter->GetSize( &totW , &totH ) ;
2993 iter = iter->GetParent() ;
3021 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3025 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3029 bool wxWindowMac::AcceptsFocus() const
3031 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3034 void wxWindowMac::MacSuperChangedPosition()
3036 // only window-absolute structures have to be moved i.e. controls
3038 wxWindowListNode
*node
= GetChildren().GetFirst();
3041 wxWindowMac
*child
= node
->GetData();
3042 child
->MacSuperChangedPosition() ;
3043 node
= node
->GetNext();
3047 void wxWindowMac::MacTopLevelWindowChangedPosition()
3049 // only screen-absolute structures have to be moved i.e. glcanvas
3051 wxWindowListNode
*node
= GetChildren().GetFirst();
3054 wxWindowMac
*child
= node
->GetData();
3055 child
->MacTopLevelWindowChangedPosition() ;
3056 node
= node
->GetNext();
3060 long wxWindowMac::MacGetLeftBorderSize( ) const
3065 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3070 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3075 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3082 long wxWindowMac::MacGetRightBorderSize( ) const
3084 // they are all symmetric in mac themes
3085 return MacGetLeftBorderSize() ;
3088 long wxWindowMac::MacGetTopBorderSize( ) const
3090 // they are all symmetric in mac themes
3091 return MacGetLeftBorderSize() ;
3094 long wxWindowMac::MacGetBottomBorderSize( ) const
3096 // they are all symmetric in mac themes
3097 return MacGetLeftBorderSize() ;
3100 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3102 return style
& ~wxBORDER_MASK
;
3105 // Find the wxWindowMac at the current mouse position, returning the mouse
3107 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3109 pt
= wxGetMousePosition();
3110 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3114 // Get the current mouse position.
3115 wxPoint
wxGetMousePosition()
3118 wxGetMousePosition(& x
, & y
);
3119 return wxPoint(x
, y
);
3122 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3124 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3126 // copied from wxGTK : CS
3127 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3130 // (a) it's a command event and so is propagated to the parent
3131 // (b) under MSW it can be generated from kbd too
3132 // (c) it uses screen coords (because of (a))
3133 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3135 this->ClientToScreen(event
.GetPosition()));
3136 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3145 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3149 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3153 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3154 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3158 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3160 return eventNotHandledErr
;