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 m_windowVariant
= parent
->GetWindowVariant() ;
815 if ( m_macIsUserPane
)
817 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
820 | kControlSupportsEmbedding
821 // | kControlSupportsLiveFeedback
822 // | kControlHasSpecialBackground
823 // | kControlSupportsCalcBestRect
824 // | kControlHandlesTracking
825 | kControlSupportsFocus
826 // | kControlWantsActivate
827 // | kControlWantsIdle
830 m_peer
= new wxMacControl() ;
831 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
834 MacPostControlCreate(pos
,size
) ;
835 #if !TARGET_API_MAC_OSX
836 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
837 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
838 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
839 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
840 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
841 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
842 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
843 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
846 #ifndef __WXUNIVERSAL__
847 // Don't give scrollbars to wxControls unless they ask for them
848 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
849 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
851 MacCreateScrollBars( style
) ;
855 wxWindowCreateEvent
event(this);
856 GetEventHandler()->AddPendingEvent(event
);
861 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
863 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
865 m_peer
->SetReference( (long) this ) ;
866 GetParent()->AddChild(this);
868 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
870 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
871 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
872 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
874 // adjust font, controlsize etc
875 DoSetWindowVariant( m_windowVariant
) ;
877 #if !TARGET_API_MAC_OSX
878 // eventually we can fix some clipping issues be reactivating this hook
879 //if ( m_macIsUserPane )
880 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
882 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
884 if (!m_macIsUserPane
)
886 SetInitialBestSize(size
);
889 SetCursor( *wxSTANDARD_CURSOR
) ;
892 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
894 // Don't assert, in case we set the window variant before
895 // the window is created
896 // wxASSERT( m_peer->Ok() ) ;
898 m_windowVariant
= variant
;
900 if (m_peer
== NULL
|| !m_peer
->Ok())
904 ThemeFontID themeFont
= kThemeSystemFont
;
906 // we will get that from the settings later
907 // and make this NORMAL later, but first
908 // we have a few calculations that we must fix
912 case wxWINDOW_VARIANT_NORMAL
:
913 size
= kControlSizeNormal
;
914 themeFont
= kThemeSystemFont
;
916 case wxWINDOW_VARIANT_SMALL
:
917 size
= kControlSizeSmall
;
918 themeFont
= kThemeSmallSystemFont
;
920 case wxWINDOW_VARIANT_MINI
:
921 if (UMAGetSystemVersion() >= 0x1030 )
923 // not always defined in the headers
929 size
= kControlSizeSmall
;
930 themeFont
= kThemeSmallSystemFont
;
933 case wxWINDOW_VARIANT_LARGE
:
934 size
= kControlSizeLarge
;
935 themeFont
= kThemeSystemFont
;
938 wxFAIL_MSG(_T("unexpected window variant"));
941 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
944 font
.MacCreateThemeFont( themeFont
) ;
948 void wxWindowMac::MacUpdateControlFont()
950 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
954 bool wxWindowMac::SetFont(const wxFont
& font
)
956 bool retval
= wxWindowBase::SetFont( font
) ;
958 MacUpdateControlFont() ;
963 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
965 if ( !wxWindowBase::SetForegroundColour(col
) )
968 MacUpdateControlFont() ;
973 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
975 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
979 wxColour
newCol(GetBackgroundColour());
980 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
982 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
984 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
986 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
990 brush
.SetColour( newCol
) ;
992 MacSetBackgroundBrush( brush
) ;
994 MacUpdateControlFont() ;
999 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1001 m_macBackgroundBrush
= brush
;
1002 m_peer
->SetBackground( brush
) ;
1005 bool wxWindowMac::MacCanFocus() const
1007 // there is currently no way to determine whether the window is running in full keyboard
1008 // access mode, therefore we cannot rely on these features, yet the only other way would be
1009 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1010 // in event handlers...
1011 UInt32 features
= 0 ;
1012 m_peer
->GetFeatures( & features
) ;
1013 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1017 void wxWindowMac::SetFocus()
1019 if ( AcceptsFocus() )
1022 wxWindow
* former
= FindFocus() ;
1023 if ( former
== this )
1026 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1027 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1028 // leave in case of an error
1029 if ( err
== errCouldntSetFocus
)
1032 #if !TARGET_API_MAC_OSX
1033 // emulate carbon events when running under carbonlib where they are not natively available
1036 EventRef evRef
= NULL
;
1037 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1040 wxMacCarbonEvent
cEvent( evRef
) ;
1041 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1042 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1044 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1045 ReleaseEvent(evRef
) ;
1047 // send new focus event
1049 EventRef evRef
= NULL
;
1050 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1053 wxMacCarbonEvent
cEvent( evRef
) ;
1054 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1055 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1057 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1058 ReleaseEvent(evRef
) ;
1065 void wxWindowMac::DoCaptureMouse()
1067 wxTheApp
->s_captureWindow
= this ;
1070 wxWindow
* wxWindowBase::GetCapture()
1072 return wxTheApp
->s_captureWindow
;
1075 void wxWindowMac::DoReleaseMouse()
1077 wxTheApp
->s_captureWindow
= NULL
;
1080 #if wxUSE_DRAG_AND_DROP
1082 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1084 if ( m_dropTarget
!= 0 ) {
1085 delete m_dropTarget
;
1088 m_dropTarget
= pDropTarget
;
1089 if ( m_dropTarget
!= 0 )
1097 // Old style file-manager drag&drop
1098 void wxWindowMac::DragAcceptFiles(bool accept
)
1103 // Returns the size of the native control. In the case of the toplevel window
1104 // this is the content area root control
1106 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1107 int& w
, int& h
) const
1110 m_peer
->GetRect( &bounds
) ;
1115 w
= bounds
.right
- bounds
.left
;
1116 h
= bounds
.bottom
- bounds
.top
;
1119 // From a wx position / size calculate the appropriate size of the native control
1121 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1124 int& w
, int& h
, bool adjustOrigin
) const
1126 // the desired size, minus the border pixels gives the correct size of the control
1130 // todo the default calls may be used as soon as PostCreateControl Is moved here
1131 w
= size
.x
; // WidthDefault( size.x );
1132 h
= size
.y
; // HeightDefault( size.y ) ;
1133 #if !TARGET_API_MAC_OSX
1134 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1137 x
+= MacGetLeftBorderSize() ;
1138 y
+= MacGetTopBorderSize() ;
1139 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1140 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1143 AdjustForParentClientOrigin( x
, y
) ;
1144 #if TARGET_API_MAC_OSX
1145 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1146 if ( ! GetParent()->IsTopLevel() )
1148 x
-= GetParent()->MacGetLeftBorderSize() ;
1149 y
-= GetParent()->MacGetTopBorderSize() ;
1155 // Get window size (not client size)
1156 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1158 // take the size of the control and add the borders that have to be drawn outside
1159 int x1
, y1
, w1
, h1
;
1161 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1163 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1164 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1170 // get the position of the bounds of this window in client coordinates of its parent
1171 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1173 int x1
, y1
, w1
,h1
;
1174 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1175 x1
-= MacGetLeftBorderSize() ;
1176 y1
-= MacGetTopBorderSize() ;
1178 #if !TARGET_API_MAC_OSX
1179 if ( !GetParent()->IsTopLevel() )
1182 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1187 if ( !IsTopLevel() )
1189 wxWindow
*parent
= GetParent();
1192 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1193 x1
+= parent
->MacGetLeftBorderSize() ;
1194 y1
+= parent
->MacGetTopBorderSize() ;
1195 // and now to client coordinates
1196 wxPoint
pt(parent
->GetClientAreaOrigin());
1205 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1207 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1209 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1212 Point localwhere
= {0,0} ;
1214 if(x
) localwhere
.h
= * x
;
1215 if(y
) localwhere
.v
= * y
;
1217 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1218 if(x
) *x
= localwhere
.h
;
1219 if(y
) *y
= localwhere
.v
;
1222 MacRootWindowToWindow( x
, y
) ;
1224 wxPoint origin
= GetClientAreaOrigin() ;
1225 if(x
) *x
-= origin
.x
;
1226 if(y
) *y
-= origin
.y
;
1229 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1231 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1232 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1234 wxPoint origin
= GetClientAreaOrigin() ;
1235 if(x
) *x
+= origin
.x
;
1236 if(y
) *y
+= origin
.y
;
1238 MacWindowToRootWindow( x
, y
) ;
1241 Point localwhere
= { 0,0 };
1242 if(x
) localwhere
.h
= * x
;
1243 if(y
) localwhere
.v
= * y
;
1244 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1245 if(x
) *x
= localwhere
.h
;
1246 if(y
) *y
= localwhere
.v
;
1250 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1252 wxPoint origin
= GetClientAreaOrigin() ;
1253 if(x
) *x
+= origin
.x
;
1254 if(y
) *y
+= origin
.y
;
1256 MacWindowToRootWindow( x
, y
) ;
1259 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1261 MacRootWindowToWindow( x
, y
) ;
1263 wxPoint origin
= GetClientAreaOrigin() ;
1264 if(x
) *x
-= origin
.x
;
1265 if(y
) *y
-= origin
.y
;
1268 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1270 #if TARGET_API_MAC_OSX
1272 if ( x
) pt
.x
= *x
;
1273 if ( y
) pt
.y
= *y
;
1275 if ( !IsTopLevel() )
1277 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1280 pt
.x
-= MacGetLeftBorderSize() ;
1281 pt
.y
-= MacGetTopBorderSize() ;
1282 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1286 if ( x
) *x
= (int) pt
.x
;
1287 if ( y
) *y
= (int) pt
.y
;
1289 if ( !IsTopLevel() )
1292 m_peer
->GetRect( &bounds
) ;
1293 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1294 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1299 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1304 MacWindowToRootWindow( &x1
, &y1
) ;
1309 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1311 #if TARGET_API_MAC_OSX
1313 if ( x
) pt
.x
= *x
;
1314 if ( y
) pt
.y
= *y
;
1316 if ( !IsTopLevel() )
1318 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1319 pt
.x
+= MacGetLeftBorderSize() ;
1320 pt
.y
+= MacGetTopBorderSize() ;
1323 if ( x
) *x
= (int) pt
.x
;
1324 if ( y
) *y
= (int) pt
.y
;
1326 if ( !IsTopLevel() )
1329 m_peer
->GetRect( &bounds
) ;
1330 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1331 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1336 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1341 MacRootWindowToWindow( &x1
, &y1
) ;
1346 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1348 RgnHandle rgn
= NewRgn() ;
1350 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1352 GetRegionBounds( rgn
, &content
) ;
1357 m_peer
->GetRect( &content
) ;
1360 m_peer
->GetRect( &structure
) ;
1361 #if !TARGET_API_MAC_OSX
1362 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1364 left
= content
.left
- structure
.left
;
1365 top
= content
.top
- structure
.top
;
1366 right
= structure
.right
- content
.right
;
1367 bottom
= structure
.bottom
- content
.bottom
;
1370 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1372 wxSize sizeTotal
= size
;
1374 RgnHandle rgn
= NewRgn() ;
1378 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1380 GetRegionBounds( rgn
, &content
) ;
1385 m_peer
->GetRect( &content
) ;
1388 m_peer
->GetRect( &structure
) ;
1389 #if !TARGET_API_MAC_OSX
1390 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1393 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1394 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1396 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1397 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1403 // Get size *available for subwindows* i.e. excluding menu bar etc.
1404 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1408 RgnHandle rgn
= NewRgn() ;
1410 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1412 GetRegionBounds( rgn
, &content
) ;
1417 m_peer
->GetRect( &content
) ;
1419 #if !TARGET_API_MAC_OSX
1421 m_peer
->GetRect( &structure
) ;
1422 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1424 ww
= content
.right
- content
.left
;
1425 hh
= content
.bottom
- content
.top
;
1427 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1428 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1431 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1437 GetSize( &w , &h ) ;
1439 MacClientToRootWindow( &x1 , &y1 ) ;
1440 MacClientToRootWindow( &w , &h ) ;
1442 wxWindowMac *iter = (wxWindowMac*)this ;
1444 int totW = 10000 , totH = 10000;
1447 if ( iter->IsTopLevel() )
1449 iter->GetSize( &totW , &totH ) ;
1453 iter = iter->GetParent() ;
1456 if (m_hScrollBar && m_hScrollBar->IsShown() )
1458 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1464 if (m_vScrollBar && m_vScrollBar->IsShown() )
1466 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1474 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1476 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1478 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1480 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1487 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1489 if (m_cursor
== cursor
)
1492 if (wxNullCursor
== cursor
)
1494 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1499 if ( ! wxWindowBase::SetCursor( cursor
) )
1503 wxASSERT_MSG( m_cursor
.Ok(),
1504 wxT("cursor must be valid after call to the base version"));
1507 wxWindowMac
*mouseWin
= 0 ;
1509 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1511 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1513 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1514 // position, use it...
1518 ControlPartCode part
;
1519 ControlRef control
;
1520 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1522 mouseWin
= wxFindControlFromMacControl( control
) ;
1525 QDSwapPort( savePort
, NULL
) ;
1528 if ( mouseWin
== this && !wxIsBusy() )
1530 m_cursor
.MacInstall() ;
1537 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1539 menu
->SetInvokingWindow(this);
1542 if ( x
== -1 && y
== -1 )
1544 wxPoint mouse
= wxGetMousePosition();
1545 x
= mouse
.x
; y
= mouse
.y
;
1549 ClientToScreen( &x
, &y
) ;
1552 menu
->MacBeforeDisplay( true ) ;
1553 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1554 if ( HiWord(menuResult
) != 0 )
1557 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1558 wxMenuItem
* item
= NULL
;
1560 item
= menu
->FindItem(id
, &realmenu
) ;
1561 if (item
->IsCheckable())
1563 item
->Check( !item
->IsChecked() ) ;
1565 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1567 menu
->MacAfterDisplay( true ) ;
1569 menu
->SetInvokingWindow(NULL
);
1575 // ----------------------------------------------------------------------------
1577 // ----------------------------------------------------------------------------
1581 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1583 wxWindowBase::DoSetToolTip(tooltip
);
1586 m_tooltip
->SetWindow(this);
1589 #endif // wxUSE_TOOLTIPS
1591 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1593 // this is never called for a toplevel window, so we know we have a parent
1594 int former_x
, former_y
, former_w
, former_h
;
1596 // Get true coordinates of former position
1597 DoGetPosition( &former_x
, &former_y
) ;
1598 DoGetSize( &former_w
, &former_h
) ;
1600 wxWindow
*parent
= GetParent();
1603 wxPoint
pt(parent
->GetClientAreaOrigin());
1608 int actualWidth
= width
;
1609 int actualHeight
= height
;
1613 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1614 actualWidth
= m_minWidth
;
1615 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1616 actualHeight
= m_minHeight
;
1617 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1618 actualWidth
= m_maxWidth
;
1619 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1620 actualHeight
= m_maxHeight
;
1622 bool doMove
= false ;
1623 bool doResize
= false ;
1625 if ( actualX
!= former_x
|| actualY
!= former_y
)
1629 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1634 if ( doMove
|| doResize
)
1636 // we don't adjust twice for the origin
1637 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1638 bool vis
= m_peer
->IsVisible();
1640 int outerBorder
= MacGetLeftBorderSize() ;
1641 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1644 if ( vis
&& ( outerBorder
> 0 ) )
1646 // as the borders are drawn on the parent we have to properly invalidate all these areas
1647 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1651 m_peer
->GetRect( &rect
) ;
1652 RectRgn( updateInner
, &rect
) ;
1653 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1654 RectRgn( updateOuter
, &rect
) ;
1655 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1656 wxPoint
parent(0,0);
1657 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1658 parent
-= GetParent()->GetClientAreaOrigin() ;
1659 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1660 CopyRgn( updateOuter
, updateTotal
) ;
1663 RectRgn( updateInner
, &rect
) ;
1664 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1665 RectRgn( updateOuter
, &rect
) ;
1666 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1668 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1669 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1671 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1672 DisposeRgn(updateOuter
) ;
1673 DisposeRgn(updateInner
) ;
1674 DisposeRgn(updateTotal
) ;
1677 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1679 m_peer
->SetVisibility( false , true ) ;
1681 m_peer
->SetRect( &r
) ;
1683 m_peer
->SetVisibility( true , true ) ;
1685 MacRepositionScrollBars() ;
1688 wxPoint
point(actualX
,actualY
);
1689 wxMoveEvent
event(point
, m_windowId
);
1690 event
.SetEventObject(this);
1691 GetEventHandler()->ProcessEvent(event
) ;
1695 MacRepositionScrollBars() ;
1696 wxSize
size(actualWidth
, actualHeight
);
1697 wxSizeEvent
event(size
, m_windowId
);
1698 event
.SetEventObject(this);
1699 GetEventHandler()->ProcessEvent(event
);
1705 wxSize
wxWindowMac::DoGetBestSize() const
1707 if ( m_macIsUserPane
|| IsTopLevel() )
1708 return wxWindowBase::DoGetBestSize() ;
1710 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1711 int bestWidth
, bestHeight
;
1712 m_peer
->GetBestRect( &bestsize
) ;
1714 if ( EmptyRect( &bestsize
) )
1716 bestsize
.left
= bestsize
.top
= 0 ;
1717 bestsize
.right
= 16 ;
1718 bestsize
.bottom
= 16 ;
1719 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1721 bestsize
.bottom
= 16 ;
1723 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1725 bestsize
.bottom
= 24 ;
1729 // return wxWindowBase::DoGetBestSize() ;
1733 bestWidth
= bestsize
.right
- bestsize
.left
;
1734 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1735 if ( bestHeight
< 10 )
1738 return wxSize(bestWidth
, bestHeight
);
1742 // set the size of the window: if the dimensions are positive, just use them,
1743 // but if any of them is equal to -1, it means that we must find the value for
1744 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1745 // which case -1 is a valid value for x and y)
1747 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1748 // the width/height to best suit our contents, otherwise we reuse the current
1750 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1752 // get the current size and position...
1753 int currentX
, currentY
;
1754 GetPosition(¤tX
, ¤tY
);
1756 int currentW
,currentH
;
1757 GetSize(¤tW
, ¤tH
);
1759 // ... and don't do anything (avoiding flicker) if it's already ok
1760 if ( x
== currentX
&& y
== currentY
&&
1761 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1764 MacRepositionScrollBars() ; // we might have a real position shift
1768 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1770 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1773 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1775 wxSize
size(-1, -1);
1778 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1780 size
= DoGetBestSize();
1785 // just take the current one
1792 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1796 size
= DoGetBestSize();
1798 //else: already called DoGetBestSize() above
1804 // just take the current one
1809 DoMoveWindow(x
, y
, width
, height
);
1813 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1815 RgnHandle rgn
= NewRgn() ;
1817 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1818 GetRegionBounds( rgn
, &content
) ;
1820 #if !TARGET_API_MAC_OSX
1821 // if the content rgn is empty / not supported
1822 // don't attempt to correct the coordinates to wxWindow relative ones
1823 if (!::EmptyRect( &content
) )
1826 m_peer
->GetRect( &structure
) ;
1827 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1831 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1834 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1836 if ( clientheight
!= -1 || clientheight
!= -1 )
1838 int currentclientwidth
, currentclientheight
;
1839 int currentwidth
, currentheight
;
1841 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1842 GetSize( ¤twidth
, ¤theight
) ;
1844 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1845 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1849 void wxWindowMac::SetTitle(const wxString
& title
)
1851 m_label
= wxStripMenuCodes(title
) ;
1853 if ( m_peer
&& m_peer
->Ok() )
1855 m_peer
->SetTitle( m_label
) ;
1860 wxString
wxWindowMac::GetTitle() const
1865 bool wxWindowMac::Show(bool show
)
1867 if ( !wxWindowBase::Show(show
) )
1870 // TODO use visibilityChanged Carbon Event for OSX
1873 bool former
= MacIsReallyShown() ;
1875 m_peer
->SetVisibility( show
, true ) ;
1876 if ( former
!= MacIsReallyShown() )
1877 MacPropagateVisibilityChanged() ;
1882 bool wxWindowMac::Enable(bool enable
)
1884 wxASSERT( m_peer
->Ok() ) ;
1885 if ( !wxWindowBase::Enable(enable
) )
1888 bool former
= MacIsReallyEnabled() ;
1889 m_peer
->Enable( enable
) ;
1891 if ( former
!= MacIsReallyEnabled() )
1892 MacPropagateEnabledStateChanged() ;
1897 // status change propagations (will be not necessary for OSX later )
1900 void wxWindowMac::MacPropagateVisibilityChanged()
1902 #if !TARGET_API_MAC_OSX
1903 MacVisibilityChanged() ;
1905 wxWindowListNode
*node
= GetChildren().GetFirst();
1908 wxWindowMac
*child
= node
->GetData();
1909 if ( child
->IsShown() )
1910 child
->MacPropagateVisibilityChanged( ) ;
1911 node
= node
->GetNext();
1916 void wxWindowMac::MacPropagateEnabledStateChanged( )
1918 #if !TARGET_API_MAC_OSX
1919 MacEnabledStateChanged() ;
1921 wxWindowListNode
*node
= GetChildren().GetFirst();
1924 wxWindowMac
*child
= node
->GetData();
1925 if ( child
->IsEnabled() )
1926 child
->MacPropagateEnabledStateChanged() ;
1927 node
= node
->GetNext();
1932 void wxWindowMac::MacPropagateHiliteChanged( )
1934 #if !TARGET_API_MAC_OSX
1935 MacHiliteChanged() ;
1937 wxWindowListNode
*node
= GetChildren().GetFirst();
1940 wxWindowMac
*child
= node
->GetData();
1941 // if ( child->IsEnabled() )
1942 child
->MacPropagateHiliteChanged() ;
1943 node
= node
->GetNext();
1949 // status change notifications
1952 void wxWindowMac::MacVisibilityChanged()
1956 void wxWindowMac::MacHiliteChanged()
1960 void wxWindowMac::MacEnabledStateChanged()
1965 // status queries on the inherited window's state
1968 bool wxWindowMac::MacIsReallyShown()
1970 // only under OSX the visibility of the TLW is taken into account
1971 #if TARGET_API_MAC_OSX
1972 if ( m_peer
&& m_peer
->Ok() )
1973 return m_peer
->IsVisible();
1975 wxWindow
* win
= this ;
1976 while( win
->IsShown() )
1978 if ( win
->IsTopLevel() )
1981 win
= win
->GetParent() ;
1989 bool wxWindowMac::MacIsReallyEnabled()
1991 return m_peer
->IsEnabled() ;
1994 bool wxWindowMac::MacIsReallyHilited()
1996 return m_peer
->IsActive();
1999 void wxWindowMac::MacFlashInvalidAreas()
2001 #if TARGET_API_MAC_OSX
2002 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2010 int wxWindowMac::GetCharHeight() const
2012 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2013 return dc
.GetCharHeight() ;
2016 int wxWindowMac::GetCharWidth() const
2018 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2019 return dc
.GetCharWidth() ;
2022 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2023 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2025 const wxFont
*fontToUse
= theFont
;
2027 fontToUse
= &m_font
;
2029 wxClientDC
dc( (wxWindowMac
*) this ) ;
2031 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2032 if ( externalLeading
)
2033 *externalLeading
= le
;
2043 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2044 * we always intersect with the entire window, not only with the client area
2047 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2049 if ( m_peer
== NULL
)
2052 #if TARGET_API_MAC_OSX
2054 m_peer
->SetNeedsDisplay( true ) ;
2057 RgnHandle update
= NewRgn() ;
2058 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2059 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2060 wxPoint origin
= GetClientAreaOrigin() ;
2061 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2062 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2064 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2065 m_peer
->SetNeedsDisplay( true , update
) ;
2066 DisposeRgn( update
) ;
2070 RgnHandle updateRgn = NewRgn() ;
2073 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2077 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2078 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2080 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2081 DisposeRgn(updateRgn) ;
2083 if ( m_peer
->IsVisible())
2085 m_peer
->SetVisibility( false , false ) ;
2086 m_peer
->SetVisibility( true , true ) ;
2089 if ( MacGetTopLevelWindow() == NULL )
2092 if ( !m_peer->IsVisible())
2095 wxPoint client = GetClientAreaOrigin();
2098 int x2 = m_width - client.x;
2099 int y2 = m_height - client.y;
2101 if (IsKindOf( CLASSINFO(wxButton)))
2103 // buttons have an "aura"
2110 Rect clientrect = { y1, x1, y2, x2 };
2114 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2115 SectRect( &clientrect , &r , &clientrect ) ;
2118 if ( !EmptyRect( &clientrect ) )
2120 int top = 0 , left = 0 ;
2122 MacClientToRootWindow( &left , &top ) ;
2123 OffsetRect( &clientrect , left , top ) ;
2125 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2131 void wxWindowMac::Freeze()
2133 #if TARGET_API_MAC_OSX
2134 if ( !m_frozenness
++ )
2136 if ( m_peer
&& m_peer
->Ok() )
2137 m_peer
->SetDrawingEnabled( false ) ;
2143 void wxWindowMac::Thaw()
2145 #if TARGET_API_MAC_OSX
2146 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2148 if ( !--m_frozenness
)
2150 if ( m_peer
&& m_peer
->Ok() )
2152 m_peer
->SetDrawingEnabled( true ) ;
2153 m_peer
->InvalidateWithChildren() ;
2159 void wxWindowMac::MacRedrawControl()
2162 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2164 #if TARGET_API_MAC_CARBON
2167 wxClientDC dc(this) ;
2168 wxMacPortSetter helper(&dc) ;
2169 wxMacWindowClipper clipper(this) ;
2170 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2171 UMADrawControl( *m_peer ) ;
2178 void wxWindowMac::OnPaint(wxPaintEvent& event)
2180 // why don't we skip that here ?
2184 wxWindowMac
*wxGetActiveWindow()
2186 // actually this is a windows-only concept
2190 // Coordinates relative to the window
2191 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2193 // We really don't move the mouse programmatically under Mac.
2196 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2198 #if TARGET_API_MAC_OSX
2199 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2206 event
.GetDC()->Clear() ;
2210 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2215 int wxWindowMac::GetScrollPos(int orient
) const
2217 if ( orient
== wxHORIZONTAL
)
2220 return m_hScrollBar
->GetThumbPosition() ;
2225 return m_vScrollBar
->GetThumbPosition() ;
2230 // This now returns the whole range, not just the number
2231 // of positions that we can scroll.
2232 int wxWindowMac::GetScrollRange(int orient
) const
2234 if ( orient
== wxHORIZONTAL
)
2237 return m_hScrollBar
->GetRange() ;
2242 return m_vScrollBar
->GetRange() ;
2247 int wxWindowMac::GetScrollThumb(int orient
) const
2249 if ( orient
== wxHORIZONTAL
)
2252 return m_hScrollBar
->GetThumbSize() ;
2257 return m_vScrollBar
->GetThumbSize() ;
2262 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2264 if ( orient
== wxHORIZONTAL
)
2267 m_hScrollBar
->SetThumbPosition( pos
) ;
2272 m_vScrollBar
->SetThumbPosition( pos
) ;
2276 void wxWindowMac::MacPaintBorders( int left
, int top
)
2282 m_peer
->GetRect( &rect
) ;
2283 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2285 if ( !IsTopLevel() )
2287 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2291 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2293 rect
.right
+= pt
.x
;
2295 rect
.bottom
+= pt
.y
;
2299 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2303 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2304 InsetRect( &srect
, border
, border
);
2305 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2307 else if (HasFlag(wxSIMPLE_BORDER
))
2311 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2312 InsetRect( &srect
, border
, border
);
2313 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2317 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2319 if ( child
== m_hScrollBar
)
2320 m_hScrollBar
= NULL
;
2321 if ( child
== m_vScrollBar
)
2322 m_vScrollBar
= NULL
;
2324 wxWindowBase::RemoveChild( child
) ;
2327 // New function that will replace some of the above.
2328 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2329 int range
, bool refresh
)
2331 if ( orient
== wxHORIZONTAL
)
2335 if ( range
== 0 || thumbVisible
>= range
)
2337 if ( m_hScrollBar
->IsShown() )
2338 m_hScrollBar
->Show(false) ;
2342 if ( !m_hScrollBar
->IsShown() )
2343 m_hScrollBar
->Show(true) ;
2344 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2352 if ( range
== 0 || thumbVisible
>= range
)
2354 if ( m_vScrollBar
->IsShown() )
2355 m_vScrollBar
->Show(false) ;
2359 if ( !m_vScrollBar
->IsShown() )
2360 m_vScrollBar
->Show(true) ;
2361 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2365 MacRepositionScrollBars() ;
2368 // Does a physical scroll
2369 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2371 if( dx
== 0 && dy
==0 )
2377 int width
, height
;
2378 GetClientSize( &width
, &height
) ;
2379 #if TARGET_API_MAC_OSX
2380 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2381 // area is scrolled, this does not occur if width and height are 2 pixels less,
2382 // TODO write optimal workaround
2383 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2386 scrollrect
.Intersect( *rect
) ;
2388 if ( m_peer
->GetNeedsDisplay() )
2390 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2391 // either immediate redraw or full invalidate
2393 // is the better overall solution, as it does not slow down scrolling
2394 m_peer
->SetNeedsDisplay( true ) ;
2396 // this would be the preferred version for fast drawing controls
2397 if( UMAGetSystemVersion() < 0x1030 )
2400 HIViewRender(m_peer
->GetControlRef()) ;
2403 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2404 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2405 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2412 RgnHandle updateRgn
= NewRgn() ;
2415 wxClientDC
dc(this) ;
2416 wxMacPortSetter
helper(&dc
) ;
2418 m_peer
->GetRect( &scrollrect
) ;
2419 scrollrect
.top
+= MacGetTopBorderSize() ;
2420 scrollrect
.left
+= MacGetLeftBorderSize() ;
2421 scrollrect
.bottom
= scrollrect
.top
+ height
;
2422 scrollrect
.right
= scrollrect
.left
+ width
;
2426 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2427 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2428 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2430 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2432 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2436 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2438 wxWindowMac
*child
= node
->GetData();
2439 if (child
== m_vScrollBar
) continue;
2440 if (child
== m_hScrollBar
) continue;
2441 if (child
->IsTopLevel()) continue;
2444 child
->GetPosition( &x
, &y
);
2446 child
->GetSize( &w
, &h
);
2450 if (rect
->Intersects(rc
))
2451 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2455 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2460 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2462 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2464 wxScrollWinEvent wevent
;
2465 wevent
.SetPosition(event
.GetPosition());
2466 wevent
.SetOrientation(event
.GetOrientation());
2467 wevent
.m_eventObject
= this;
2469 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2470 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2471 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2472 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2473 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2474 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2475 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2476 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2477 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2478 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2479 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2480 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2481 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2482 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2483 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2484 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2486 GetEventHandler()->ProcessEvent(wevent
);
2490 // Get the window with the focus
2491 wxWindowMac
*wxWindowBase::DoFindFocus()
2493 ControlRef control
;
2494 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2495 return wxFindControlFromMacControl( control
) ;
2498 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2500 // panel wants to track the window which was the last to have focus in it,
2501 // so we want to set ourselves as the window which last had focus
2503 // notice that it's also important to do it upwards the tree becaus
2504 // otherwise when the top level panel gets focus, it won't set it back to
2505 // us, but to some other sibling
2507 // CS:don't know if this is still needed:
2508 //wxChildFocusEvent eventFocus(this);
2509 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2511 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2513 wxMacWindowStateSaver
sv( this ) ;
2518 MacWindowToRootWindow( &x
, &y
) ;
2519 GetSize( &w
, &h
) ;
2520 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2522 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2523 DrawThemeFocusRect( &rect
, true ) ;
2526 DrawThemeFocusRect( &rect
, false ) ;
2528 // as this erases part of the frame we have to redraw borders
2529 // and because our z-ordering is not always correct (staticboxes)
2530 // we have to invalidate things, we cannot simple redraw
2531 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2532 RectRgn( updateInner
, &rect
) ;
2533 InsetRect( &rect
, -4 , -4 ) ;
2534 RectRgn( updateOuter
, &rect
) ;
2535 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2536 wxPoint
parent(0,0);
2537 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2538 parent
-= GetParent()->GetClientAreaOrigin() ;
2539 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2540 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2541 DisposeRgn(updateOuter
) ;
2542 DisposeRgn(updateInner
) ;
2549 void wxWindowMac::OnInternalIdle()
2551 // This calls the UI-update mechanism (querying windows for
2552 // menu/toolbar/control state information)
2553 if (wxUpdateUIEvent::CanUpdate(this))
2554 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2557 // Raise the window to the top of the Z order
2558 void wxWindowMac::Raise()
2560 m_peer
->SetZOrder( true , NULL
) ;
2563 // Lower the window to the bottom of the Z order
2564 void wxWindowMac::Lower()
2566 m_peer
->SetZOrder( false , NULL
) ;
2570 // static wxWindow *gs_lastWhich = NULL;
2572 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2574 // first trigger a set cursor event
2576 wxPoint clientorigin
= GetClientAreaOrigin() ;
2577 wxSize clientsize
= GetClientSize() ;
2579 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2581 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2583 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2584 if ( processedEvtSetCursor
&& event
.HasCursor() )
2586 cursor
= event
.GetCursor() ;
2591 // the test for processedEvtSetCursor is here to prevent using m_cursor
2592 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2593 // it - this is a way to say that our cursor shouldn't be used for this
2595 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2605 cursor
= *wxSTANDARD_CURSOR
;
2609 cursor
.MacInstall() ;
2611 return cursor
.Ok() ;
2614 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2618 return m_tooltip
->GetTip() ;
2620 return wxEmptyString
;
2623 void wxWindowMac::Update()
2625 #if TARGET_API_MAC_OSX
2627 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2628 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2630 // for composited windows this also triggers a redraw of all
2631 // invalid views in the window
2632 if( UMAGetSystemVersion() >= 0x1030 )
2633 HIWindowFlush(window
) ;
2637 // the only way to trigger the redrawing on earlier systems is to call
2640 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2641 UInt32 currentEventClass
= 0 ;
2642 UInt32 currentEventKind
= 0 ;
2643 if ( currentEvent
!= NULL
)
2645 currentEventClass
= ::GetEventClass( currentEvent
) ;
2646 currentEventKind
= ::GetEventKind( currentEvent
) ;
2648 if ( currentEventClass
!= kEventClassMenu
)
2650 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2653 OSStatus status
= noErr
;
2654 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2657 m_peer
->SetNeedsDisplay( true ) ;
2660 ::Draw1Control( m_peer
->GetControlRef() ) ;
2664 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2666 wxTopLevelWindowMac
* win
= NULL
;
2667 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2670 win
= wxFindWinFromMacWindow( window
) ;
2674 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2676 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2677 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2678 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2679 // to add focus borders everywhere
2682 RgnHandle visRgn
= NewRgn() ;
2683 RgnHandle tempRgn
= NewRgn() ;
2684 if ( m_peer
->IsVisible())
2686 m_peer
->GetRect( &r
) ;
2687 r
.left
-= MacGetLeftBorderSize() ;
2688 r
.top
-= MacGetTopBorderSize() ;
2689 r
.bottom
+= MacGetBottomBorderSize() ;
2690 r
.right
+= MacGetRightBorderSize() ;
2692 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2694 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2695 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2704 if ( includeOuterStructures
)
2705 InsetRect( &r
, -4 , -4 ) ;
2706 RectRgn( visRgn
, &r
) ;
2708 if ( !IsTopLevel() )
2710 wxWindow
* child
= this ;
2711 wxWindow
* parent
= child
->GetParent() ;
2716 // we have to find a better clipping algorithm here, in order not to clip things
2717 // positioned like status and toolbar
2718 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2720 size
= parent
->GetSize() ;
2725 size
= parent
->GetClientSize() ;
2726 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2730 parent
->MacWindowToRootWindow( &x
, &y
) ;
2731 MacRootWindowToWindow( &x
, &y
) ;
2733 if ( !includeOuterStructures
|| (
2734 parent
->MacClipChildren() ||
2735 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2738 SetRectRgn( tempRgn
,
2739 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2740 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2741 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2743 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2745 if ( parent
->IsTopLevel() )
2748 parent
= child
->GetParent() ;
2753 wxRegion vis
= visRgn
;
2754 DisposeRgn( visRgn
) ;
2755 DisposeRgn( tempRgn
) ;
2760 This function must not change the updatergn !
2762 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2764 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2765 bool handled
= false ;
2767 GetRegionBounds( updatergn
, &updatebounds
) ;
2768 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2769 if ( !EmptyRgn(updatergn
) )
2771 RgnHandle newupdate
= NewRgn() ;
2772 wxSize point
= GetClientSize() ;
2773 wxPoint origin
= GetClientAreaOrigin() ;
2774 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2775 SectRgn( newupdate
, updatergn
, newupdate
) ;
2777 // first send an erase event to the entire update area
2779 wxWindowDC
dc(this);
2780 dc
.SetClippingRegion(wxRegion(updatergn
));
2781 wxEraseEvent
eevent( GetId(), &dc
);
2782 eevent
.SetEventObject( this );
2783 GetEventHandler()->ProcessEvent( eevent
);
2786 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2787 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2788 m_updateRegion
= newupdate
;
2789 DisposeRgn( newupdate
) ;
2791 if ( !m_updateRegion
.Empty() )
2793 // paint the window itself
2795 event
.m_timeStamp
= time
;
2796 event
.SetEventObject(this);
2797 handled
= GetEventHandler()->ProcessEvent(event
);
2799 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2802 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2804 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2811 // now we cannot rely on having its borders drawn by a window itself, as it does not
2812 // get the updateRgn wide enough to always do so, so we do it from the parent
2813 // this would also be the place to draw any custom backgrounds for native controls
2814 // in Composited windowing
2815 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2817 for (wxWindowListNode
*node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2819 wxWindowMac
*child
= node
->GetData();
2820 if (child
== m_vScrollBar
) continue;
2821 if (child
== m_hScrollBar
) continue;
2822 if (child
->IsTopLevel()) continue;
2823 if (!child
->IsShown()) continue;
2826 child
->GetPosition( &x
, &y
);
2828 child
->GetSize( &w
, &h
);
2829 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2830 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2831 if ( child
->MacGetTopBorderSize() )
2833 if ( RectInRgn( &childRect
, updatergn
) )
2835 // paint custom borders
2836 wxNcPaintEvent
eventNc( child
->GetId() );
2837 eventNc
.SetEventObject( child
);
2838 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2840 wxWindowDC
dc(this) ;
2841 dc
.SetClippingRegion(wxRegion(updatergn
));
2842 wxMacPortSetter
helper(&dc
) ;
2843 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2847 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2849 wxWindowDC
dc(this) ;
2850 dc
.SetClippingRegion(wxRegion(updatergn
));
2851 wxMacPortSetter
helper(&dc
) ;
2852 Rect r
= childRect
;
2853 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2854 DrawThemeFocusRect( &r
, true ) ;
2861 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2863 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2864 // updatergn is always already clipped to our boundaries
2865 // if we are in compositing mode then it is in relative to the upper left of the control
2866 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2867 // of the toplevel window
2868 // it is in window coordinates, not in client coordinates
2870 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2871 RgnHandle ownUpdateRgn
= NewRgn() ;
2872 CopyRgn( updatergn
, ownUpdateRgn
) ;
2874 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2877 m_peer
->GetRectInWindowCoords( &bounds
);
2878 RgnHandle controlRgn
= NewRgn();
2879 RectRgn( controlRgn
, &bounds
);
2880 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2881 // the window update region
2882 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2883 DisposeRgn( controlRgn
);
2885 //KO: convert ownUpdateRgn to local coordinates
2886 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2889 MacDoRedraw( ownUpdateRgn
, time
) ;
2890 DisposeRgn( ownUpdateRgn
) ;
2894 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2896 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2900 if ( iter
->IsTopLevel() )
2901 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2903 iter
= iter
->GetParent() ;
2905 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2909 void wxWindowMac::MacCreateScrollBars( long style
)
2911 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2913 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2915 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2916 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2917 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2918 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2920 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2921 variant
= wxWINDOW_VARIANT_SMALL
;
2924 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2926 GetClientSize( &width
, &height
) ;
2928 wxPoint
vPoint(width
-scrlsize
, 0) ;
2929 wxSize
vSize(scrlsize
, height
- adjust
) ;
2930 wxPoint
hPoint(0 , height
-scrlsize
) ;
2931 wxSize
hSize( width
- adjust
, scrlsize
) ;
2934 if ( style
& wxVSCROLL
)
2936 m_vScrollBar
= new wxScrollBar(this, wxWINDOW_VSCROLL
, vPoint
,
2937 vSize
, wxVERTICAL
);
2940 if ( style
& wxHSCROLL
)
2942 m_hScrollBar
= new wxScrollBar(this, wxWINDOW_HSCROLL
, hPoint
,
2943 hSize
, wxHORIZONTAL
);
2948 // because the create does not take into account the client area origin
2949 MacRepositionScrollBars() ; // we might have a real position shift
2952 void wxWindowMac::MacRepositionScrollBars()
2954 if ( !m_hScrollBar
&& !m_vScrollBar
)
2957 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2958 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2959 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2961 // get real client area
2965 GetSize( &width
, &height
) ;
2967 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
2968 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
2970 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
2971 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
2972 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
2973 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
2979 GetSize( &w , &h ) ;
2981 MacClientToRootWindow( &x , &y ) ;
2982 MacClientToRootWindow( &w , &h ) ;
2984 wxWindowMac *iter = (wxWindowMac*)this ;
2986 int totW = 10000 , totH = 10000;
2989 if ( iter->IsTopLevel() )
2991 iter->GetSize( &totW , &totH ) ;
2995 iter = iter->GetParent() ;
3023 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3027 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3031 bool wxWindowMac::AcceptsFocus() const
3033 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3036 void wxWindowMac::MacSuperChangedPosition()
3038 // only window-absolute structures have to be moved i.e. controls
3040 wxWindowListNode
*node
= GetChildren().GetFirst();
3043 wxWindowMac
*child
= node
->GetData();
3044 child
->MacSuperChangedPosition() ;
3045 node
= node
->GetNext();
3049 void wxWindowMac::MacTopLevelWindowChangedPosition()
3051 // only screen-absolute structures have to be moved i.e. glcanvas
3053 wxWindowListNode
*node
= GetChildren().GetFirst();
3056 wxWindowMac
*child
= node
->GetData();
3057 child
->MacTopLevelWindowChangedPosition() ;
3058 node
= node
->GetNext();
3062 long wxWindowMac::MacGetLeftBorderSize( ) const
3067 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3072 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3077 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3084 long wxWindowMac::MacGetRightBorderSize( ) const
3086 // they are all symmetric in mac themes
3087 return MacGetLeftBorderSize() ;
3090 long wxWindowMac::MacGetTopBorderSize( ) const
3092 // they are all symmetric in mac themes
3093 return MacGetLeftBorderSize() ;
3096 long wxWindowMac::MacGetBottomBorderSize( ) const
3098 // they are all symmetric in mac themes
3099 return MacGetLeftBorderSize() ;
3102 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3104 return style
& ~wxBORDER_MASK
;
3107 // Find the wxWindowMac at the current mouse position, returning the mouse
3109 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3111 pt
= wxGetMousePosition();
3112 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3116 // Get the current mouse position.
3117 wxPoint
wxGetMousePosition()
3120 wxGetMousePosition(& x
, & y
);
3121 return wxPoint(x
, y
);
3124 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3126 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3128 // copied from wxGTK : CS
3129 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3132 // (a) it's a command event and so is propagated to the parent
3133 // (b) under MSW it can be generated from kbd too
3134 // (c) it uses screen coords (because of (a))
3135 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3137 this->ClientToScreen(event
.GetPosition()));
3138 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3147 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3151 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3155 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3156 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3160 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3162 return eventNotHandledErr
;