1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "window.h"
16 #include "wx/wxprec.h"
19 #include "wx/window.h"
21 #include "wx/dcclient.h"
25 #include "wx/layout.h"
26 #include "wx/dialog.h"
27 #include "wx/scrolbar.h"
28 #include "wx/statbox.h"
29 #include "wx/button.h"
30 #include "wx/settings.h"
31 #include "wx/msgdlg.h"
33 #include "wx/tooltip.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
41 #include "wx/toolbar.h"
48 #define MAC_SCROLLBAR_SIZE 15
49 #define MAC_SMALL_SCROLLBAR_SIZE 11
51 #include "wx/mac/uma.h"
54 #include <ToolUtils.h>
56 #include <MacTextEditor.h>
59 #if TARGET_API_MAC_OSX
61 #include <HIToolbox/HIView.h>
65 #if wxUSE_DRAG_AND_DROP
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 #endif // __WXUNIVERSAL__/__WXMAC__
79 #if !USE_SHARED_LIBRARY
81 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
82 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
83 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
84 #if TARGET_API_MAC_OSX
85 EVT_PAINT(wxWindowMac::OnPaint
)
87 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
89 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
94 #define wxMAC_DEBUG_REDRAW 0
95 #ifndef wxMAC_DEBUG_REDRAW
96 #define wxMAC_DEBUG_REDRAW 0
99 #define wxMAC_USE_THEME_BORDER 1
101 // ---------------------------------------------------------------------------
102 // Utility Routines to move between different coordinate systems
103 // ---------------------------------------------------------------------------
106 * Right now we have the following setup :
107 * a border that is not part of the native control is always outside the
108 * control's border (otherwise we loose all native intelligence, future ways
109 * may be to have a second embedding control responsible for drawing borders
110 * and backgrounds eventually)
111 * so all this border calculations have to be taken into account when calling
112 * native methods or getting native oriented data
113 * so we have three coordinate systems here
114 * wx client coordinates
115 * wx window coordinates (including window frames)
120 // originating from native control
124 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
126 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
131 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
135 // directed towards native control
138 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
140 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
143 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
145 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
149 // ---------------------------------------------------------------------------
151 // ---------------------------------------------------------------------------
153 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
154 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
156 #if TARGET_API_MAC_OSX
158 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
160 kEventControlVisibilityChanged
= 157
166 static const EventTypeSpec eventList
[] =
168 { kEventClassControl
, kEventControlHit
} ,
169 #if TARGET_API_MAC_OSX
170 { kEventClassControl
, kEventControlDraw
} ,
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
174 { kEventClassControl
, kEventControlSetFocusPart
} ,
176 { kEventClassService
, kEventServiceGetTypes
},
177 { kEventClassService
, kEventServiceCopy
},
178 { kEventClassService
, kEventServicePaste
},
180 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
181 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
204 if ( thisWindow
->MacGetTopLevelWindow()->MacUsesCompositing() == false || cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
206 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
210 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
212 allocatedRgn
= NewRgn() ;
213 CopyRgn( updateRgn
, allocatedRgn
) ;
214 // hide the given region by the new region that must be shifted
215 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
216 updateRgn
= allocatedRgn
;
221 // in case we would need a coregraphics compliant background erase first
222 // now usable to track redraws
223 if ( thisWindow
->MacIsUserPane() )
225 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
226 static float color
= 0.5 ;
229 HIViewGetBounds( controlRef
, &bounds
);
230 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
231 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
232 CGContextFillRect( cgContext
, bounds
);
244 #if wxMAC_USE_CORE_GRAPHICS
245 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
246 thisWindow
->MacSetCGContextRef( cgContext
) ;
247 wxMacCGContextStateSaver
sg( cgContext
) ;
249 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
251 #if wxMAC_USE_CORE_GRAPHICS
252 thisWindow
->MacSetCGContextRef( NULL
) ;
256 DisposeRgn( allocatedRgn
) ;
259 case kEventControlVisibilityChanged
:
260 thisWindow
->MacVisibilityChanged() ;
262 case kEventControlEnabledStateChanged
:
263 thisWindow
->MacEnabledStateChanged() ;
265 case kEventControlHiliteChanged
:
266 thisWindow
->MacHiliteChanged() ;
269 // we emulate this event under Carbon CFM
270 case kEventControlSetFocusPart
:
272 Boolean focusEverything
= false ;
273 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
275 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
279 if ( controlPart
== kControlFocusNoPart
)
282 if ( thisWindow
->GetCaret() )
284 thisWindow
->GetCaret()->OnKillFocus();
286 #endif // wxUSE_CARET
287 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
288 event
.SetEventObject(thisWindow
);
289 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
293 // panel wants to track the window which was the last to have focus in it
294 wxChildFocusEvent
eventFocus(thisWindow
);
295 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
298 if ( thisWindow
->GetCaret() )
300 thisWindow
->GetCaret()->OnSetFocus();
302 #endif // wxUSE_CARET
304 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
305 event
.SetEventObject(thisWindow
);
306 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
308 if ( thisWindow
->MacIsUserPane() )
312 case kEventControlHit
:
314 result
= thisWindow
->MacControlHit( handler
, event
) ;
323 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
325 OSStatus result
= eventNotHandledErr
;
327 wxMacCarbonEvent
cEvent( event
) ;
329 ControlRef controlRef
;
330 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
331 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
332 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
334 switch( GetEventKind( event
) )
336 case kEventServiceGetTypes
:
340 textCtrl
->GetSelection( &from
, &to
) ;
342 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
344 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
345 if ( textCtrl
->IsEditable() )
346 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
348 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
349 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
351 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
355 CFArrayAppendValue (copyTypes
, typestring
) ;
357 CFArrayAppendValue (pasteTypes
, typestring
) ;
358 CFRelease( typestring
) ;
364 case kEventServiceCopy
:
368 textCtrl
->GetSelection( &from
, &to
) ;
369 wxString val
= textCtrl
->GetValue() ;
370 val
= val
.Mid( from
, to
- from
) ;
371 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
372 verify_noerr( ClearScrap( &scrapRef
) ) ;
373 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
377 case kEventServicePaste
:
380 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
381 Size textSize
, pastedSize
;
382 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
384 char *content
= new char[textSize
] ;
385 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
386 content
[textSize
-1] = 0 ;
388 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
390 textCtrl
->WriteText( wxString( content
) ) ;
401 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
403 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
404 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
405 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
406 OSStatus result
= eventNotHandledErr
;
408 switch ( GetEventClass( event
) )
410 case kEventClassControl
:
411 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
413 case kEventClassService
:
414 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
418 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
422 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
424 #if !TARGET_API_MAC_OSX
426 // ---------------------------------------------------------------------------
427 // UserPane events for non OSX builds
428 // ---------------------------------------------------------------------------
430 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
432 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
434 win
->MacControlUserPaneDrawProc(part
) ;
437 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
439 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
441 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
443 return kControlNoPart
;
446 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
448 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
450 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
452 return kControlNoPart
;
455 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
457 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
459 win
->MacControlUserPaneIdleProc() ;
462 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
464 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
466 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
468 return kControlNoPart
;
471 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
473 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
475 win
->MacControlUserPaneActivateProc(activating
) ;
478 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
480 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
482 return win
->MacControlUserPaneFocusProc(action
) ;
484 return kControlNoPart
;
487 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
489 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
491 win
->MacControlUserPaneBackgroundProc(info
) ;
494 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
496 RgnHandle rgn
= NewRgn() ;
498 wxMacWindowStateSaver
sv( this ) ;
499 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
500 MacDoRedraw( rgn
, 0 ) ;
504 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
506 return kControlNoPart
;
509 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
511 return kControlNoPart
;
514 void wxWindowMac::MacControlUserPaneIdleProc()
518 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
520 return kControlNoPart
;
523 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
527 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
529 return kControlNoPart
;
532 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
536 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
537 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
538 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
539 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
540 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
541 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
542 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
543 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
547 // ===========================================================================
549 // ===========================================================================
551 #if KEY_wxList_DEPRECATED
552 wxList
wxWinMacControlList(wxKEY_INTEGER
);
554 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
556 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
559 return (wxControl
*)node
->GetData();
562 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
564 // adding NULL ControlRef is (first) surely a result of an error and
565 // (secondly) breaks native event processing
566 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
568 if ( !wxWinMacControlList
.Find((long)inControl
) )
569 wxWinMacControlList
.Append((long)inControl
, control
);
572 void wxRemoveMacControlAssociation(wxWindow
*control
)
574 wxWinMacControlList
.DeleteObject(control
);
578 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
580 static MacControlMap wxWinMacControlList
;
582 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
584 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
586 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
589 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
591 // adding NULL ControlRef is (first) surely a result of an error and
592 // (secondly) breaks native event processing
593 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
595 wxWinMacControlList
[inControl
] = control
;
598 void wxRemoveMacControlAssociation(wxWindow
*control
)
600 // iterate over all the elements in the class
601 MacControlMap::iterator it
;
602 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
604 if ( it
->second
== control
)
606 wxWinMacControlList
.erase(it
);
611 #endif // deprecated wxList
614 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
616 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
618 // we have to setup the brush in the current port and return noErr
619 // or return an error code so that the control manager walks further up the
620 // hierarchy to find a correct background
622 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
624 OSStatus status
= paramErr
;
627 case kControlMsgApplyTextColor
:
629 case kControlMsgSetUpBackground
:
631 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
635 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
638 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
640 // this clipping is only needed for non HIView
642 RgnHandle clip
= NewRgn() ;
645 wx
->MacWindowToRootWindow( &x
,&y
) ;
646 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
647 OffsetRgn( clip
, x
, y
) ;
654 else if ( wx->MacIsUserPane() )
656 // if we don't have a valid brush for such a control, we have to call the
657 // setup of our parent ourselves
658 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
671 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
672 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
676 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
679 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
684 // ----------------------------------------------------------------------------
685 // constructors and such
686 // ----------------------------------------------------------------------------
688 wxWindowMac::wxWindowMac()
693 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
698 const wxString
& name
)
701 Create(parent
, id
, pos
, size
, style
, name
);
704 void wxWindowMac::Init()
708 #if WXWIN_COMPATIBILITY_2_4
709 m_backgroundTransparent
= FALSE
;
712 // as all windows are created with WS_VISIBLE style...
715 m_hScrollBar
= NULL
;
716 m_vScrollBar
= NULL
;
717 m_macBackgroundBrush
= wxNullBrush
;
719 m_macIsUserPane
= TRUE
;
720 #if wxMAC_USE_CORE_GRAPHICS
721 m_cgContextRef
= NULL
;
723 // make sure all proc ptrs are available
725 #if !TARGET_API_MAC_OSX
726 if ( gControlUserPaneDrawUPP
== NULL
)
728 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
729 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
730 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
731 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
732 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
733 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
734 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
735 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
738 if ( wxMacLiveScrollbarActionUPP
== NULL
)
740 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
743 if ( wxMacSetupControlBackgroundUPP
== NULL
)
745 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
748 // we need a valid font for the encodings
749 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
753 wxWindowMac::~wxWindowMac()
757 m_isBeingDeleted
= TRUE
;
759 MacInvalidateBorders() ;
761 #ifndef __WXUNIVERSAL__
762 // VS: make sure there's no wxFrame with last focus set to us:
763 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
765 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
768 if ( frame
->GetLastFocus() == this )
770 frame
->SetLastFocus((wxWindow
*)NULL
);
775 #endif // __WXUNIVERSAL__
777 // destroy children before destroying this window itself
780 // wxRemoveMacControlAssociation( this ) ;
781 // If we delete an item, we should initialize the parent panel,
782 // because it could now be invalid.
783 wxWindow
*parent
= GetParent() ;
786 if (parent
->GetDefaultItem() == (wxButton
*) this)
787 parent
->SetDefaultItem(NULL
);
789 if ( m_peer
&& m_peer
->Ok() )
791 // in case the callback might be called during destruction
792 wxRemoveMacControlAssociation( this) ;
793 // we currently are not using this hook
794 // ::SetControlColorProc( *m_peer , NULL ) ;
798 if ( g_MacLastWindow
== this )
800 g_MacLastWindow
= NULL
;
803 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
806 if ( frame
->GetLastFocus() == this )
807 frame
->SetLastFocus( NULL
) ;
810 // delete our drop target if we've got one
811 #if wxUSE_DRAG_AND_DROP
812 if ( m_dropTarget
!= NULL
)
817 #endif // wxUSE_DRAG_AND_DROP
821 WXWidget
wxWindowMac::GetHandle() const
823 return (WXWidget
) m_peer
->GetControlRef() ;
827 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
829 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
830 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
831 GetEventTypeCount(eventList
), eventList
, this,
832 (EventHandlerRef
*)&m_macControlEventHandler
);
833 #if !TARGET_API_MAC_OSX
834 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
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
) ;
850 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
854 const wxString
& name
)
856 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
858 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
861 m_windowVariant
= parent
->GetWindowVariant() ;
863 if ( m_macIsUserPane
)
865 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
868 | kControlSupportsEmbedding
869 // | kControlSupportsLiveFeedback
870 // | kControlHasSpecialBackground
871 // | kControlSupportsCalcBestRect
872 // | kControlHandlesTracking
873 | kControlSupportsFocus
874 // | kControlWantsActivate
875 // | kControlWantsIdle
878 m_peer
= new wxMacControl(this) ;
879 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
882 MacPostControlCreate(pos
,size
) ;
884 #ifndef __WXUNIVERSAL__
885 // Don't give scrollbars to wxControls unless they ask for them
886 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
887 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
889 MacCreateScrollBars( style
) ;
893 wxWindowCreateEvent
event(this);
894 GetEventHandler()->AddPendingEvent(event
);
899 void wxWindowMac::MacChildAdded()
903 m_vScrollBar
->Raise() ;
907 m_hScrollBar
->Raise() ;
912 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
914 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
916 m_peer
->SetReference( (long) this ) ;
917 GetParent()->AddChild(this);
919 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
921 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
922 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
923 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
924 GetParent()->MacChildAdded() ;
926 // adjust font, controlsize etc
927 DoSetWindowVariant( m_windowVariant
) ;
929 #if !TARGET_API_MAC_OSX
930 // eventually we can fix some clipping issues be reactivating this hook
931 //if ( m_macIsUserPane )
932 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
934 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
936 if (!m_macIsUserPane
)
938 SetInitialBestSize(size
);
941 SetCursor( *wxSTANDARD_CURSOR
) ;
944 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
946 // Don't assert, in case we set the window variant before
947 // the window is created
948 // wxASSERT( m_peer->Ok() ) ;
950 m_windowVariant
= variant
;
952 if (m_peer
== NULL
|| !m_peer
->Ok())
956 ThemeFontID themeFont
= kThemeSystemFont
;
958 // we will get that from the settings later
959 // and make this NORMAL later, but first
960 // we have a few calculations that we must fix
964 case wxWINDOW_VARIANT_NORMAL
:
965 size
= kControlSizeNormal
;
966 themeFont
= kThemeSystemFont
;
968 case wxWINDOW_VARIANT_SMALL
:
969 size
= kControlSizeSmall
;
970 themeFont
= kThemeSmallSystemFont
;
972 case wxWINDOW_VARIANT_MINI
:
973 if (UMAGetSystemVersion() >= 0x1030 )
975 // not always defined in the headers
981 size
= kControlSizeSmall
;
982 themeFont
= kThemeSmallSystemFont
;
985 case wxWINDOW_VARIANT_LARGE
:
986 size
= kControlSizeLarge
;
987 themeFont
= kThemeSystemFont
;
990 wxFAIL_MSG(_T("unexpected window variant"));
993 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
996 font
.MacCreateThemeFont( themeFont
) ;
1000 void wxWindowMac::MacUpdateControlFont()
1002 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1006 bool wxWindowMac::SetFont(const wxFont
& font
)
1008 bool retval
= wxWindowBase::SetFont( font
) ;
1010 MacUpdateControlFont() ;
1015 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1017 if ( !wxWindowBase::SetForegroundColour(col
) )
1020 MacUpdateControlFont() ;
1025 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1027 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1031 wxColour
newCol(GetBackgroundColour());
1032 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1034 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1036 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1038 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1042 brush
.SetColour( newCol
) ;
1044 MacSetBackgroundBrush( brush
) ;
1046 MacUpdateControlFont() ;
1051 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1053 m_macBackgroundBrush
= brush
;
1054 m_peer
->SetBackground( brush
) ;
1057 bool wxWindowMac::MacCanFocus() const
1059 // there is currently no way to determine whether the window is running in full keyboard
1060 // access mode, therefore we cannot rely on these features, yet the only other way would be
1061 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1062 // in event handlers...
1063 UInt32 features
= 0 ;
1064 m_peer
->GetFeatures( & features
) ;
1065 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1069 void wxWindowMac::SetFocus()
1071 if ( AcceptsFocus() )
1074 wxWindow
* former
= FindFocus() ;
1075 if ( former
== this )
1078 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1079 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1080 // leave in case of an error
1081 if ( err
== errCouldntSetFocus
)
1084 #if !TARGET_API_MAC_OSX
1085 // emulate carbon events when running under carbonlib where they are not natively available
1088 EventRef evRef
= NULL
;
1089 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1092 wxMacCarbonEvent
cEvent( evRef
) ;
1093 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1094 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1096 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1097 ReleaseEvent(evRef
) ;
1099 // send new focus event
1101 EventRef evRef
= NULL
;
1102 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1105 wxMacCarbonEvent
cEvent( evRef
) ;
1106 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1107 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1109 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1110 ReleaseEvent(evRef
) ;
1117 void wxWindowMac::DoCaptureMouse()
1119 wxTheApp
->s_captureWindow
= this ;
1122 wxWindow
* wxWindowBase::GetCapture()
1124 return wxTheApp
->s_captureWindow
;
1127 void wxWindowMac::DoReleaseMouse()
1129 wxTheApp
->s_captureWindow
= NULL
;
1132 #if wxUSE_DRAG_AND_DROP
1134 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1136 if ( m_dropTarget
!= 0 ) {
1137 delete m_dropTarget
;
1140 m_dropTarget
= pDropTarget
;
1141 if ( m_dropTarget
!= 0 )
1149 // Old style file-manager drag&drop
1150 void wxWindowMac::DragAcceptFiles(bool accept
)
1155 // Returns the size of the native control. In the case of the toplevel window
1156 // this is the content area root control
1158 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1159 int& w
, int& h
) const
1162 m_peer
->GetRect( &bounds
) ;
1167 w
= bounds
.right
- bounds
.left
;
1168 h
= bounds
.bottom
- bounds
.top
;
1171 // From a wx position / size calculate the appropriate size of the native control
1173 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1176 int& w
, int& h
, bool adjustOrigin
) const
1178 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1180 // the desired size, minus the border pixels gives the correct size of the control
1184 // todo the default calls may be used as soon as PostCreateControl Is moved here
1185 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1186 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1188 if ( !isCompositing
)
1189 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1191 x
+= MacGetLeftBorderSize() ;
1192 y
+= MacGetTopBorderSize() ;
1193 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1194 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1197 AdjustForParentClientOrigin( x
, y
) ;
1199 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1200 if ( !GetParent()->IsTopLevel() )
1202 x
-= GetParent()->MacGetLeftBorderSize() ;
1203 y
-= GetParent()->MacGetTopBorderSize() ;
1209 // Get window size (not client size)
1210 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1212 // take the size of the control and add the borders that have to be drawn outside
1213 int x1
, y1
, w1
, h1
;
1215 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1217 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1218 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1224 // get the position of the bounds of this window in client coordinates of its parent
1225 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1227 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1229 int x1
, y1
, w1
,h1
;
1230 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1231 x1
-= MacGetLeftBorderSize() ;
1232 y1
-= MacGetTopBorderSize() ;
1235 if ( !isCompositing
&& !GetParent()->IsTopLevel() )
1238 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1243 if ( !IsTopLevel() )
1245 wxWindow
*parent
= GetParent();
1248 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1249 x1
+= parent
->MacGetLeftBorderSize() ;
1250 y1
+= parent
->MacGetTopBorderSize() ;
1251 // and now to client coordinates
1252 wxPoint
pt(parent
->GetClientAreaOrigin());
1261 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1263 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1265 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1268 Point localwhere
= {0,0} ;
1270 if(x
) localwhere
.h
= * x
;
1271 if(y
) localwhere
.v
= * y
;
1273 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1274 if(x
) *x
= localwhere
.h
;
1275 if(y
) *y
= localwhere
.v
;
1278 MacRootWindowToWindow( x
, y
) ;
1280 wxPoint origin
= GetClientAreaOrigin() ;
1281 if(x
) *x
-= origin
.x
;
1282 if(y
) *y
-= origin
.y
;
1285 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1287 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1288 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1290 wxPoint origin
= GetClientAreaOrigin() ;
1291 if(x
) *x
+= origin
.x
;
1292 if(y
) *y
+= origin
.y
;
1294 MacWindowToRootWindow( x
, y
) ;
1297 Point localwhere
= { 0,0 };
1298 if(x
) localwhere
.h
= * x
;
1299 if(y
) localwhere
.v
= * y
;
1300 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1301 if(x
) *x
= localwhere
.h
;
1302 if(y
) *y
= localwhere
.v
;
1306 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1308 wxPoint origin
= GetClientAreaOrigin() ;
1309 if(x
) *x
+= origin
.x
;
1310 if(y
) *y
+= origin
.y
;
1312 MacWindowToRootWindow( x
, y
) ;
1315 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1317 MacRootWindowToWindow( x
, y
) ;
1319 wxPoint origin
= GetClientAreaOrigin() ;
1320 if(x
) *x
-= origin
.x
;
1321 if(y
) *y
-= origin
.y
;
1324 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1327 if ( x
) pt
.x
= *x
;
1328 if ( y
) pt
.y
= *y
;
1330 if ( !IsTopLevel() )
1332 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1335 pt
.x
-= MacGetLeftBorderSize() ;
1336 pt
.y
-= MacGetTopBorderSize() ;
1337 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1341 if ( x
) *x
= (int) pt
.x
;
1342 if ( y
) *y
= (int) pt
.y
;
1345 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1350 MacWindowToRootWindow( &x1
, &y1
) ;
1355 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1358 if ( x
) pt
.x
= *x
;
1359 if ( y
) pt
.y
= *y
;
1361 if ( !IsTopLevel() )
1363 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1364 pt
.x
+= MacGetLeftBorderSize() ;
1365 pt
.y
+= MacGetTopBorderSize() ;
1368 if ( x
) *x
= (int) pt
.x
;
1369 if ( y
) *y
= (int) pt
.y
;
1372 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1377 MacRootWindowToWindow( &x1
, &y1
) ;
1382 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1384 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1386 RgnHandle rgn
= NewRgn() ;
1388 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1390 GetRegionBounds( rgn
, &content
) ;
1394 m_peer
->GetRect( &content
) ;
1398 m_peer
->GetRect( &structure
) ;
1400 if ( !isCompositing
)
1401 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1403 left
= content
.left
- structure
.left
;
1404 top
= content
.top
- structure
.top
;
1405 right
= structure
.right
- content
.right
;
1406 bottom
= structure
.bottom
- content
.bottom
;
1409 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1411 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1412 wxSize sizeTotal
= size
;
1414 RgnHandle rgn
= NewRgn() ;
1418 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1420 GetRegionBounds( rgn
, &content
) ;
1424 m_peer
->GetRect( &content
) ;
1428 m_peer
->GetRect( &structure
) ;
1430 if ( !isCompositing
)
1431 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1433 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1434 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1436 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1437 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1443 // Get size *available for subwindows* i.e. excluding menu bar etc.
1444 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1446 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1449 RgnHandle rgn
= NewRgn() ;
1451 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1453 GetRegionBounds( rgn
, &content
) ;
1457 m_peer
->GetRect( &content
) ;
1461 if ( !isCompositing
)
1464 m_peer
->GetRect( &structure
) ;
1465 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1467 ww
= content
.right
- content
.left
;
1468 hh
= content
.bottom
- content
.top
;
1470 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1471 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1474 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1480 GetSize( &w , &h ) ;
1482 MacClientToRootWindow( &x1 , &y1 ) ;
1483 MacClientToRootWindow( &w , &h ) ;
1485 wxWindowMac *iter = (wxWindowMac*)this ;
1487 int totW = 10000 , totH = 10000;
1490 if ( iter->IsTopLevel() )
1492 iter->GetSize( &totW , &totH ) ;
1496 iter = iter->GetParent() ;
1499 if (m_hScrollBar && m_hScrollBar->IsShown() )
1501 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1507 if (m_vScrollBar && m_vScrollBar->IsShown() )
1509 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1517 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1519 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1521 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1523 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1530 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1532 if (m_cursor
== cursor
)
1535 if (wxNullCursor
== cursor
)
1537 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1542 if ( ! wxWindowBase::SetCursor( cursor
) )
1546 wxASSERT_MSG( m_cursor
.Ok(),
1547 wxT("cursor must be valid after call to the base version"));
1550 wxWindowMac
*mouseWin
= 0 ;
1552 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1553 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1555 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1557 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1558 // position, use it...
1562 ControlPartCode part
;
1563 ControlRef control
;
1564 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1566 mouseWin
= wxFindControlFromMacControl( control
) ;
1569 QDSwapPort( savePort
, NULL
) ;
1572 if ( mouseWin
== this && !wxIsBusy() )
1574 m_cursor
.MacInstall() ;
1581 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1583 menu
->SetInvokingWindow(this);
1586 if ( x
== -1 && y
== -1 )
1588 wxPoint mouse
= wxGetMousePosition();
1589 x
= mouse
.x
; y
= mouse
.y
;
1593 ClientToScreen( &x
, &y
) ;
1596 menu
->MacBeforeDisplay( true ) ;
1597 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1598 if ( HiWord(menuResult
) != 0 )
1601 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1602 wxMenuItem
* item
= NULL
;
1604 item
= menu
->FindItem(id
, &realmenu
) ;
1605 if (item
->IsCheckable())
1607 item
->Check( !item
->IsChecked() ) ;
1609 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1611 menu
->MacAfterDisplay( true ) ;
1613 menu
->SetInvokingWindow(NULL
);
1619 // ----------------------------------------------------------------------------
1621 // ----------------------------------------------------------------------------
1625 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1627 wxWindowBase::DoSetToolTip(tooltip
);
1630 m_tooltip
->SetWindow(this);
1633 #endif // wxUSE_TOOLTIPS
1635 void wxWindowMac::MacInvalidateBorders()
1637 if ( m_peer
== NULL
)
1640 bool vis
= MacIsReallyShown() ;
1644 int outerBorder
= MacGetLeftBorderSize() ;
1645 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1648 if ( outerBorder
== 0 )
1651 // now we know that we have something to do at all
1653 // as the borders are drawn on the parent we have to properly invalidate all these areas
1654 RgnHandle updateInner
= NewRgn() ,
1655 updateOuter
= NewRgn() ;
1657 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1659 m_peer
->GetRect( &rect
) ;
1660 RectRgn( updateInner
, &rect
) ;
1661 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1662 RectRgn( updateOuter
, &rect
) ;
1663 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1664 #ifdef __WXMAC_OSX__
1665 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
1667 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1669 InvalWindowRgn( tlw
, updateOuter
) ;
1671 DisposeRgn(updateOuter
) ;
1672 DisposeRgn(updateInner
) ;
1674 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1675 RectRgn( updateInner , &rect ) ;
1676 InsetRect( &rect , -4 , -4 ) ;
1677 RectRgn( updateOuter , &rect ) ;
1678 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1679 wxPoint parent(0,0);
1680 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1681 parent -= GetParent()->GetClientAreaOrigin() ;
1682 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1683 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1684 DisposeRgn(updateOuter) ;
1685 DisposeRgn(updateInner) ;
1690 // deleting a window while it is shown invalidates the region occupied by border or
1693 if ( IsShown() && ( outerBorder > 0 ) )
1695 // as the borders are drawn on the parent we have to properly invalidate all these areas
1696 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1700 m_peer->GetRect( &rect ) ;
1701 RectRgn( updateInner , &rect ) ;
1702 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1703 RectRgn( updateOuter , &rect ) ;
1704 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1705 wxPoint parent(0,0);
1706 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1707 parent -= GetParent()->GetClientAreaOrigin() ;
1708 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1709 CopyRgn( updateOuter , updateTotal ) ;
1711 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1712 DisposeRgn(updateOuter) ;
1713 DisposeRgn(updateInner) ;
1714 DisposeRgn(updateTotal) ;
1719 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1721 int outerBorder
= MacGetLeftBorderSize() ;
1722 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1725 if ( vis
&& ( outerBorder
> 0 ) )
1727 // as the borders are drawn on the parent we have to properly invalidate all these areas
1728 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1732 m_peer
->GetRect( &rect
) ;
1733 RectRgn( updateInner
, &rect
) ;
1734 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1735 RectRgn( updateOuter
, &rect
) ;
1736 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1738 wxPoint parent(0,0);
1739 #if TARGET_API_MAC_OSX
1740 // no offsetting needed when compositing
1742 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1743 parent -= GetParent()->GetClientAreaOrigin() ;
1744 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1747 CopyRgn( updateOuter
, updateTotal
) ;
1750 RectRgn( updateInner
, &rect
) ;
1751 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1752 RectRgn( updateOuter
, &rect
) ;
1753 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1755 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1757 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1759 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1760 DisposeRgn(updateOuter
) ;
1761 DisposeRgn(updateInner
) ;
1762 DisposeRgn(updateTotal
) ;
1767 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1769 // this is never called for a toplevel window, so we know we have a parent
1770 int former_x
, former_y
, former_w
, former_h
;
1772 // Get true coordinates of former position
1773 DoGetPosition( &former_x
, &former_y
) ;
1774 DoGetSize( &former_w
, &former_h
) ;
1776 wxWindow
*parent
= GetParent();
1779 wxPoint
pt(parent
->GetClientAreaOrigin());
1784 int actualWidth
= width
;
1785 int actualHeight
= height
;
1789 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1790 actualWidth
= m_minWidth
;
1791 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1792 actualHeight
= m_minHeight
;
1793 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1794 actualWidth
= m_maxWidth
;
1795 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1796 actualHeight
= m_maxHeight
;
1798 bool doMove
= false ;
1799 bool doResize
= false ;
1801 if ( actualX
!= former_x
|| actualY
!= former_y
)
1805 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1810 if ( doMove
|| doResize
)
1812 // we don't adjust twice for the origin
1813 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1814 bool vis
= MacIsReallyShown() ;
1816 MacInvalidateBorders() ;
1818 m_peer
->SetRect( &r
) ;
1821 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1823 MacInvalidateBorders() ;
1825 MacRepositionScrollBars() ;
1828 wxPoint
point(actualX
,actualY
);
1829 wxMoveEvent
event(point
, m_windowId
);
1830 event
.SetEventObject(this);
1831 GetEventHandler()->ProcessEvent(event
) ;
1835 MacRepositionScrollBars() ;
1836 wxSize
size(actualWidth
, actualHeight
);
1837 wxSizeEvent
event(size
, m_windowId
);
1838 event
.SetEventObject(this);
1839 GetEventHandler()->ProcessEvent(event
);
1845 wxSize
wxWindowMac::DoGetBestSize() const
1847 if ( m_macIsUserPane
|| IsTopLevel() )
1848 return wxWindowBase::DoGetBestSize() ;
1850 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1851 int bestWidth
, bestHeight
;
1852 m_peer
->GetBestRect( &bestsize
) ;
1854 if ( EmptyRect( &bestsize
) )
1856 bestsize
.left
= bestsize
.top
= 0 ;
1857 bestsize
.right
= 16 ;
1858 bestsize
.bottom
= 16 ;
1859 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1861 bestsize
.bottom
= 16 ;
1864 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1866 bestsize
.bottom
= 24 ;
1868 #endif // wxUSE_SPINBTN
1871 // return wxWindowBase::DoGetBestSize() ;
1875 bestWidth
= bestsize
.right
- bestsize
.left
;
1876 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1877 if ( bestHeight
< 10 )
1880 return wxSize(bestWidth
, bestHeight
);
1884 // set the size of the window: if the dimensions are positive, just use them,
1885 // but if any of them is equal to -1, it means that we must find the value for
1886 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1887 // which case -1 is a valid value for x and y)
1889 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1890 // the width/height to best suit our contents, otherwise we reuse the current
1892 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1894 // get the current size and position...
1895 int currentX
, currentY
;
1896 GetPosition(¤tX
, ¤tY
);
1898 int currentW
,currentH
;
1899 GetSize(¤tW
, ¤tH
);
1901 // ... and don't do anything (avoiding flicker) if it's already ok
1902 if ( x
== currentX
&& y
== currentY
&&
1903 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1906 MacRepositionScrollBars() ; // we might have a real position shift
1910 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1912 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1915 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1917 wxSize
size(-1, -1);
1920 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1922 size
= DoGetBestSize();
1927 // just take the current one
1934 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1938 size
= DoGetBestSize();
1940 //else: already called DoGetBestSize() above
1946 // just take the current one
1951 DoMoveWindow(x
, y
, width
, height
);
1955 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1957 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1958 RgnHandle rgn
= NewRgn() ;
1960 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1961 GetRegionBounds( rgn
, &content
) ;
1964 if ( !isCompositing
)
1966 // if the content rgn is empty / not supported
1967 // don't attempt to correct the coordinates to wxWindow relative ones
1968 if (!::EmptyRect( &content
) )
1971 m_peer
->GetRect( &structure
) ;
1972 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1976 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1979 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1981 if ( clientheight
!= -1 || clientheight
!= -1 )
1983 int currentclientwidth
, currentclientheight
;
1984 int currentwidth
, currentheight
;
1986 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1987 GetSize( ¤twidth
, ¤theight
) ;
1989 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1990 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1994 void wxWindowMac::SetTitle(const wxString
& title
)
1996 m_label
= wxStripMenuCodes(title
) ;
1998 if ( m_peer
&& m_peer
->Ok() )
2000 m_peer
->SetTitle( m_label
) ;
2005 wxString
wxWindowMac::GetTitle() const
2010 bool wxWindowMac::Show(bool show
)
2012 bool former
= MacIsReallyShown() ;
2013 if ( !wxWindowBase::Show(show
) )
2016 // TODO use visibilityChanged Carbon Event for OSX
2019 m_peer
->SetVisibility( show
, true ) ;
2021 if ( former
!= MacIsReallyShown() )
2022 MacPropagateVisibilityChanged() ;
2026 bool wxWindowMac::Enable(bool enable
)
2028 wxASSERT( m_peer
->Ok() ) ;
2029 bool former
= MacIsReallyEnabled() ;
2030 if ( !wxWindowBase::Enable(enable
) )
2033 m_peer
->Enable( enable
) ;
2035 if ( former
!= MacIsReallyEnabled() )
2036 MacPropagateEnabledStateChanged() ;
2041 // status change propagations (will be not necessary for OSX later )
2044 void wxWindowMac::MacPropagateVisibilityChanged()
2046 #if !TARGET_API_MAC_OSX
2047 MacVisibilityChanged() ;
2049 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2052 wxWindowMac
*child
= node
->GetData();
2053 if ( child
->IsShown() )
2054 child
->MacPropagateVisibilityChanged( ) ;
2055 node
= node
->GetNext();
2060 void wxWindowMac::MacPropagateEnabledStateChanged( )
2062 #if !TARGET_API_MAC_OSX
2063 MacEnabledStateChanged() ;
2065 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2068 wxWindowMac
*child
= node
->GetData();
2069 if ( child
->IsEnabled() )
2070 child
->MacPropagateEnabledStateChanged() ;
2071 node
= node
->GetNext();
2076 void wxWindowMac::MacPropagateHiliteChanged( )
2078 #if !TARGET_API_MAC_OSX
2079 MacHiliteChanged() ;
2081 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2084 wxWindowMac
*child
= node
->GetData();
2085 // if ( child->IsEnabled() )
2086 child
->MacPropagateHiliteChanged() ;
2087 node
= node
->GetNext();
2093 // status change notifications
2096 void wxWindowMac::MacVisibilityChanged()
2100 void wxWindowMac::MacHiliteChanged()
2104 void wxWindowMac::MacEnabledStateChanged()
2109 // status queries on the inherited window's state
2112 bool wxWindowMac::MacIsReallyShown()
2114 // only under OSX the visibility of the TLW is taken into account
2115 if ( m_isBeingDeleted
)
2118 #if TARGET_API_MAC_OSX
2119 if ( m_peer
&& m_peer
->Ok() )
2120 return m_peer
->IsVisible();
2122 wxWindow
* win
= this ;
2123 while( win
->IsShown() )
2125 if ( win
->IsTopLevel() )
2128 win
= win
->GetParent() ;
2136 bool wxWindowMac::MacIsReallyEnabled()
2138 return m_peer
->IsEnabled() ;
2141 bool wxWindowMac::MacIsReallyHilited()
2143 return m_peer
->IsActive();
2146 void wxWindowMac::MacFlashInvalidAreas()
2148 #if TARGET_API_MAC_OSX
2149 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2157 int wxWindowMac::GetCharHeight() const
2159 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2160 return dc
.GetCharHeight() ;
2163 int wxWindowMac::GetCharWidth() const
2165 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2166 return dc
.GetCharWidth() ;
2169 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2170 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2172 const wxFont
*fontToUse
= theFont
;
2174 fontToUse
= &m_font
;
2176 wxClientDC
dc( (wxWindowMac
*) this ) ;
2178 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2179 if ( externalLeading
)
2180 *externalLeading
= le
;
2190 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2191 * we always intersect with the entire window, not only with the client area
2194 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2196 if ( m_peer
== NULL
)
2200 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
2201 // if ( isCompositing )
2203 if ( rect
== NULL
&& isCompositing
)
2204 m_peer
->SetNeedsDisplay( true ) ;
2208 Rect controlBounds
;
2209 m_peer
->GetRect( &controlBounds
) ;
2210 InvalWindowRect( (WindowRef
) MacGetTopLevelWindowRef() , &controlBounds
) ;
2212 RgnHandle update = NewRgn() ;
2215 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update ) ;
2219 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2220 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
2223 wxPoint origin = GetClientAreaOrigin() ;
2224 OffsetRgn( update, origin.x , origin.y ) ;
2225 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2227 if ( isCompositing )
2229 OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2230 m_peer->SetNeedsDisplay( true , update) ;
2236 MacWindowToRootWindow( &x , &y ) ;
2237 OffsetRgn( update , x , y ) ;
2238 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , update ) ;
2240 DisposeRgn( update ) ;
2247 if ( MacIsReallyShown() )
2250 m_peer->SetVisibility( false , false ) ;
2251 m_peer->SetVisibility( true , true ) ;
2257 void wxWindowMac::Freeze()
2259 #if TARGET_API_MAC_OSX
2260 if ( !m_frozenness
++ )
2262 if ( m_peer
&& m_peer
->Ok() )
2263 m_peer
->SetDrawingEnabled( false ) ;
2269 void wxWindowMac::Thaw()
2271 #if TARGET_API_MAC_OSX
2272 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2274 if ( !--m_frozenness
)
2276 if ( m_peer
&& m_peer
->Ok() )
2278 m_peer
->SetDrawingEnabled( true ) ;
2279 m_peer
->InvalidateWithChildren() ;
2285 wxWindowMac
*wxGetActiveWindow()
2287 // actually this is a windows-only concept
2291 // Coordinates relative to the window
2292 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2294 // We really don't move the mouse programmatically under Mac.
2297 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2299 #if TARGET_API_MAC_OSX
2300 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2307 event
.GetDC()->Clear() ;
2311 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2316 int wxWindowMac::GetScrollPos(int orient
) const
2318 if ( orient
== wxHORIZONTAL
)
2321 return m_hScrollBar
->GetThumbPosition() ;
2326 return m_vScrollBar
->GetThumbPosition() ;
2331 // This now returns the whole range, not just the number
2332 // of positions that we can scroll.
2333 int wxWindowMac::GetScrollRange(int orient
) const
2335 if ( orient
== wxHORIZONTAL
)
2338 return m_hScrollBar
->GetRange() ;
2343 return m_vScrollBar
->GetRange() ;
2348 int wxWindowMac::GetScrollThumb(int orient
) const
2350 if ( orient
== wxHORIZONTAL
)
2353 return m_hScrollBar
->GetThumbSize() ;
2358 return m_vScrollBar
->GetThumbSize() ;
2363 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2365 if ( orient
== wxHORIZONTAL
)
2368 m_hScrollBar
->SetThumbPosition( pos
) ;
2373 m_vScrollBar
->SetThumbPosition( pos
) ;
2378 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2379 // our own window origin is at leftOrigin/rightOrigin
2382 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2388 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2389 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2391 m_peer
->GetRect( &rect
) ;
2392 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2394 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2395 if ( UMAGetSystemVersion() >= 0x1030 )
2398 HIThemeFrameDrawInfo info
;
2399 memset( &info
, 0 , sizeof( info
) ) ;
2403 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2404 info
.isFocused
= hasFocus
;
2407 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2408 wxASSERT( cgContext
) ;
2410 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2413 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2414 InsetRect( &srect
, border
, border
);
2415 info
.kind
= kHIThemeFrameTextFieldSquare
;
2418 else if (HasFlag(wxSIMPLE_BORDER
))
2421 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2422 InsetRect( &srect
, border
, border
);
2423 info
.kind
= kHIThemeFrameListBox
;
2429 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2430 srect
.bottom
- srect
.top
) ;
2431 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2433 else if ( hasFocus
)
2436 CGRect cgrect
= CGRectMake( srect
.left
, srect
.top
, srect
.right
- srect
.left
,
2437 srect
.bottom
- srect
.top
) ;
2438 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2441 m_peer
->GetRect( &rect
) ;
2442 if ( hasBothScrollbars
)
2445 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2446 CGRect cgrect
= CGRectMake( srect
.right
- size
, srect
.bottom
- size
, size
, size
) ;
2447 CGPoint cgpoint
= CGPointMake( srect
.right
- size
, srect
.bottom
- size
) ;
2448 HIThemeGrowBoxDrawInfo info
;
2449 memset( &info
, 0 , sizeof( info
) ) ;
2451 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2452 info
.kind
= kHIThemeGrowBoxKindNone
;
2453 info
.size
= kHIThemeGrowBoxSizeNormal
;
2454 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2455 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2461 // as the non OSX Version is already working in window relative coordinates, it's not needed
2462 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2463 if (top
&& top
->MacUsesCompositing())
2466 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2468 rect
.right
+= pt
.x
;
2470 rect
.bottom
+= pt
.y
;
2473 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2477 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2478 InsetRect( &srect
, border
, border
);
2479 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2481 else if (HasFlag(wxSIMPLE_BORDER
))
2485 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2486 InsetRect( &srect
, border
, border
);
2487 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2493 DrawThemeFocusRect( &srect
, true ) ;
2495 if ( hasBothScrollbars
)
2497 // GetThemeStandaloneGrowBoxBounds
2498 //DrawThemeStandaloneNoGrowBox
2503 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2505 if ( child
== m_hScrollBar
)
2506 m_hScrollBar
= NULL
;
2507 if ( child
== m_vScrollBar
)
2508 m_vScrollBar
= NULL
;
2510 wxWindowBase::RemoveChild( child
) ;
2513 // New function that will replace some of the above.
2514 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2515 int range
, bool refresh
)
2517 if ( orient
== wxHORIZONTAL
)
2521 if ( range
== 0 || thumbVisible
>= range
)
2523 if ( m_hScrollBar
->IsShown() )
2524 m_hScrollBar
->Show(false) ;
2528 if ( !m_hScrollBar
->IsShown() )
2529 m_hScrollBar
->Show(true) ;
2531 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2538 if ( range
== 0 || thumbVisible
>= range
)
2540 if ( m_vScrollBar
->IsShown() )
2541 m_vScrollBar
->Show(false) ;
2545 if ( !m_vScrollBar
->IsShown() )
2546 m_vScrollBar
->Show(true) ;
2548 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2551 MacRepositionScrollBars() ;
2554 // Does a physical scroll
2555 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2557 if( dx
== 0 && dy
==0 )
2563 int width
, height
;
2564 GetClientSize( &width
, &height
) ;
2565 #if TARGET_API_MAC_OSX
2566 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2567 // area is scrolled, this does not occur if width and height are 2 pixels less,
2568 // TODO write optimal workaround
2569 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2572 scrollrect
.Intersect( *rect
) ;
2574 if ( m_peer
->GetNeedsDisplay() )
2576 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2577 // either immediate redraw or full invalidate
2579 // is the better overall solution, as it does not slow down scrolling
2580 m_peer
->SetNeedsDisplay( true ) ;
2582 // this would be the preferred version for fast drawing controls
2583 if( UMAGetSystemVersion() < 0x1030 )
2586 HIViewRender(m_peer
->GetControlRef()) ;
2589 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2590 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2591 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2598 RgnHandle updateRgn
= NewRgn() ;
2601 wxClientDC
dc(this) ;
2602 wxMacPortSetter
helper(&dc
) ;
2604 m_peer
->GetRect( &scrollrect
) ;
2605 scrollrect
.top
+= MacGetTopBorderSize() ;
2606 scrollrect
.left
+= MacGetLeftBorderSize() ;
2607 scrollrect
.bottom
= scrollrect
.top
+ height
;
2608 scrollrect
.right
= scrollrect
.left
+ width
;
2612 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2613 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2614 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2616 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2618 // now scroll the former update region as well and add the new update region
2620 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2621 RgnHandle formerUpdateRgn
= NewRgn() ;
2622 RgnHandle scrollRgn
= NewRgn() ;
2623 RectRgn( scrollRgn
, &scrollrect
) ;
2624 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2626 LocalToGlobal( &pt
) ;
2627 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2628 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2629 if ( !EmptyRgn( formerUpdateRgn
) )
2631 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2632 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2633 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2635 InvalWindowRgn(rootWindow
, updateRgn
) ;
2636 DisposeRgn( updateRgn
) ;
2637 DisposeRgn( formerUpdateRgn
) ;
2638 DisposeRgn( scrollRgn
) ;
2643 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2645 wxWindowMac
*child
= node
->GetData();
2646 if (child
== m_vScrollBar
) continue;
2647 if (child
== m_hScrollBar
) continue;
2648 if (child
->IsTopLevel()) continue;
2651 child
->GetPosition( &x
, &y
);
2653 child
->GetSize( &w
, &h
);
2657 if (rect
->Intersects(rc
))
2658 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2662 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2667 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2669 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2671 wxScrollWinEvent wevent
;
2672 wevent
.SetPosition(event
.GetPosition());
2673 wevent
.SetOrientation(event
.GetOrientation());
2674 wevent
.SetEventObject(this);
2676 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2677 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2678 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2679 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2680 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2681 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2682 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2683 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2684 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2685 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2686 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2687 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2688 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2689 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2690 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2691 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2693 GetEventHandler()->ProcessEvent(wevent
);
2697 // Get the window with the focus
2698 wxWindowMac
*wxWindowBase::DoFindFocus()
2700 ControlRef control
;
2701 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2702 return wxFindControlFromMacControl( control
) ;
2705 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2707 // panel wants to track the window which was the last to have focus in it,
2708 // so we want to set ourselves as the window which last had focus
2710 // notice that it's also important to do it upwards the tree becaus
2711 // otherwise when the top level panel gets focus, it won't set it back to
2712 // us, but to some other sibling
2714 // CS:don't know if this is still needed:
2715 //wxChildFocusEvent eventFocus(this);
2716 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2718 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2720 #if !wxMAC_USE_CORE_GRAPHICS
2721 wxMacWindowStateSaver
sv( this ) ;
2723 m_peer
->GetRect( &rect
) ;
2724 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2725 #ifdef __WXMAC_OSX__
2726 // as the non OSX Version is already working in window relative coordinates, it's not needed
2727 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2728 if (top
&& top
->MacUsesCompositing() )
2731 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2733 rect
.right
+= pt
.x
;
2735 rect
.bottom
+= pt
.y
;
2739 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2740 DrawThemeFocusRect( &rect
, true ) ;
2743 DrawThemeFocusRect( &rect
, false ) ;
2745 // as this erases part of the frame we have to redraw borders
2746 // and because our z-ordering is not always correct (staticboxes)
2747 // we have to invalidate things, we cannot simple redraw
2748 MacInvalidateBorders() ;
2751 GetParent()->Refresh() ;
2758 void wxWindowMac::OnInternalIdle()
2760 // This calls the UI-update mechanism (querying windows for
2761 // menu/toolbar/control state information)
2762 if (wxUpdateUIEvent::CanUpdate(this))
2763 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2766 // Raise the window to the top of the Z order
2767 void wxWindowMac::Raise()
2769 m_peer
->SetZOrder( true , NULL
) ;
2772 // Lower the window to the bottom of the Z order
2773 void wxWindowMac::Lower()
2775 m_peer
->SetZOrder( false , NULL
) ;
2779 // static wxWindow *gs_lastWhich = NULL;
2781 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2783 // first trigger a set cursor event
2785 wxPoint clientorigin
= GetClientAreaOrigin() ;
2786 wxSize clientsize
= GetClientSize() ;
2788 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2790 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2792 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2793 if ( processedEvtSetCursor
&& event
.HasCursor() )
2795 cursor
= event
.GetCursor() ;
2800 // the test for processedEvtSetCursor is here to prevent using m_cursor
2801 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2802 // it - this is a way to say that our cursor shouldn't be used for this
2804 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2814 cursor
= *wxSTANDARD_CURSOR
;
2818 cursor
.MacInstall() ;
2820 return cursor
.Ok() ;
2823 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2827 return m_tooltip
->GetTip() ;
2829 return wxEmptyString
;
2832 void wxWindowMac::ClearBackground()
2838 void wxWindowMac::Update()
2840 #if TARGET_API_MAC_OSX
2842 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2843 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2845 // for composited windows this also triggers a redraw of all
2846 // invalid views in the window
2847 if( UMAGetSystemVersion() >= 0x1030 )
2848 HIWindowFlush(window
) ;
2852 // the only way to trigger the redrawing on earlier systems is to call
2855 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2856 UInt32 currentEventClass
= 0 ;
2857 UInt32 currentEventKind
= 0 ;
2858 if ( currentEvent
!= NULL
)
2860 currentEventClass
= ::GetEventClass( currentEvent
) ;
2861 currentEventKind
= ::GetEventKind( currentEvent
) ;
2863 if ( currentEventClass
!= kEventClassMenu
)
2865 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2868 OSStatus status
= noErr
;
2869 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2872 m_peer
->SetNeedsDisplay( true ) ;
2875 ::Draw1Control( m_peer
->GetControlRef() ) ;
2879 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2881 wxTopLevelWindowMac
* win
= NULL
;
2882 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2885 win
= wxFindWinFromMacWindow( window
) ;
2889 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2891 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2892 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2893 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2894 // to add focus borders everywhere
2897 RgnHandle visRgn
= NewRgn() ;
2898 RgnHandle tempRgn
= NewRgn() ;
2899 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2901 m_peer
->GetRect( &r
) ;
2902 r
.left
-= MacGetLeftBorderSize() ;
2903 r
.top
-= MacGetTopBorderSize() ;
2904 r
.bottom
+= MacGetBottomBorderSize() ;
2905 r
.right
+= MacGetRightBorderSize() ;
2907 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2909 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2910 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2919 if ( includeOuterStructures
)
2920 InsetRect( &r
, -4 , -4 ) ;
2921 RectRgn( visRgn
, &r
) ;
2923 if ( !IsTopLevel() )
2925 wxWindow
* child
= this ;
2926 wxWindow
* parent
= child
->GetParent() ;
2931 // we have to find a better clipping algorithm here, in order not to clip things
2932 // positioned like status and toolbar
2933 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2935 size
= parent
->GetSize() ;
2940 size
= parent
->GetClientSize() ;
2941 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2945 parent
->MacWindowToRootWindow( &x
, &y
) ;
2946 MacRootWindowToWindow( &x
, &y
) ;
2948 if ( !includeOuterStructures
|| (
2949 parent
->MacClipChildren() ||
2950 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2953 SetRectRgn( tempRgn
,
2954 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2955 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2956 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2958 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2960 if ( parent
->IsTopLevel() )
2963 parent
= child
->GetParent() ;
2968 wxRegion vis
= visRgn
;
2969 DisposeRgn( visRgn
) ;
2970 DisposeRgn( tempRgn
) ;
2975 This function must not change the updatergn !
2977 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2979 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2980 bool handled
= false ;
2982 GetRegionBounds( updatergn
, &updatebounds
) ;
2984 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2986 if ( !EmptyRgn(updatergn
) )
2988 RgnHandle newupdate
= NewRgn() ;
2989 wxSize point
= GetClientSize() ;
2990 wxPoint origin
= GetClientAreaOrigin() ;
2991 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2992 SectRgn( newupdate
, updatergn
, newupdate
) ;
2994 // first send an erase event to the entire update area
2996 // for the toplevel window this really is the entire area
2997 // for all the others only their client area, otherwise they
2998 // might be drawing with full alpha and eg put blue into
2999 // the grow-box area of a scrolled window (scroll sample)
3002 dc
= new wxWindowDC(this);
3004 dc
= new wxClientDC(this);
3005 dc
->SetClippingRegion(wxRegion(updatergn
));
3006 wxEraseEvent
eevent( GetId(), dc
);
3007 eevent
.SetEventObject( this );
3008 GetEventHandler()->ProcessEvent( eevent
);
3012 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3013 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3014 m_updateRegion
= newupdate
;
3015 DisposeRgn( newupdate
) ;
3017 if ( !m_updateRegion
.Empty() )
3019 // paint the window itself
3022 event
.SetTimestamp(time
);
3023 event
.SetEventObject(this);
3024 GetEventHandler()->ProcessEvent(event
);
3028 // now we cannot rely on having its borders drawn by a window itself, as it does not
3029 // get the updateRgn wide enough to always do so, so we do it from the parent
3030 // this would also be the place to draw any custom backgrounds for native controls
3031 // in Composited windowing
3032 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3034 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3036 wxWindowMac
*child
= node
->GetData();
3037 if (child
== m_vScrollBar
) continue;
3038 if (child
== m_hScrollBar
) continue;
3039 if (child
->IsTopLevel()) continue;
3040 if (!child
->IsShown()) continue;
3042 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3045 child
->GetPosition( &x
, &y
);
3047 child
->GetSize( &w
, &h
);
3048 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3049 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3050 InsetRect( &childRect
, -10 , -10) ;
3052 if ( RectInRgn( &childRect
, updatergn
) )
3055 // paint custom borders
3056 wxNcPaintEvent
eventNc( child
->GetId() );
3057 eventNc
.SetEventObject( child
);
3058 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3060 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3061 if ( UMAGetSystemVersion() >= 0x1030 )
3063 child
->MacPaintBorders(0,0) ;
3068 wxWindowDC
dc(this) ;
3069 dc
.SetClippingRegion(wxRegion(updatergn
));
3070 wxMacPortSetter
helper(&dc
) ;
3071 child
->MacPaintBorders(0,0) ;
3081 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3083 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3087 if ( iter
->IsTopLevel() )
3088 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3090 iter
= iter
->GetParent() ;
3092 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3096 void wxWindowMac::MacCreateScrollBars( long style
)
3098 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3100 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3102 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3103 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3104 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3105 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3107 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3108 variant
= wxWINDOW_VARIANT_SMALL
;
3111 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3113 GetClientSize( &width
, &height
) ;
3115 wxPoint
vPoint(width
-scrlsize
, 0) ;
3116 wxSize
vSize(scrlsize
, height
- adjust
) ;
3117 wxPoint
hPoint(0 , height
-scrlsize
) ;
3118 wxSize
hSize( width
- adjust
, scrlsize
) ;
3121 if ( style
& wxVSCROLL
)
3123 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3124 vSize
, wxVERTICAL
);
3127 if ( style
& wxHSCROLL
)
3129 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3130 hSize
, wxHORIZONTAL
);
3135 // because the create does not take into account the client area origin
3136 MacRepositionScrollBars() ; // we might have a real position shift
3139 void wxWindowMac::MacRepositionScrollBars()
3141 if ( !m_hScrollBar
&& !m_vScrollBar
)
3144 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3145 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3146 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3148 // get real client area
3152 GetSize( &width
, &height
) ;
3154 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3155 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3157 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3158 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3159 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3160 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3166 GetSize( &w , &h ) ;
3168 MacClientToRootWindow( &x , &y ) ;
3169 MacClientToRootWindow( &w , &h ) ;
3171 wxWindowMac *iter = (wxWindowMac*)this ;
3173 int totW = 10000 , totH = 10000;
3176 if ( iter->IsTopLevel() )
3178 iter->GetSize( &totW , &totH ) ;
3182 iter = iter->GetParent() ;
3210 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3214 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3218 bool wxWindowMac::AcceptsFocus() const
3220 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3223 void wxWindowMac::MacSuperChangedPosition()
3225 // only window-absolute structures have to be moved i.e. controls
3227 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3230 wxWindowMac
*child
= node
->GetData();
3231 child
->MacSuperChangedPosition() ;
3232 node
= node
->GetNext();
3236 void wxWindowMac::MacTopLevelWindowChangedPosition()
3238 // only screen-absolute structures have to be moved i.e. glcanvas
3240 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3243 wxWindowMac
*child
= node
->GetData();
3244 child
->MacTopLevelWindowChangedPosition() ;
3245 node
= node
->GetNext();
3249 long wxWindowMac::MacGetLeftBorderSize( ) const
3254 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3259 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3264 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3271 long wxWindowMac::MacGetRightBorderSize( ) const
3273 // they are all symmetric in mac themes
3274 return MacGetLeftBorderSize() ;
3277 long wxWindowMac::MacGetTopBorderSize( ) const
3279 // they are all symmetric in mac themes
3280 return MacGetLeftBorderSize() ;
3283 long wxWindowMac::MacGetBottomBorderSize( ) const
3285 // they are all symmetric in mac themes
3286 return MacGetLeftBorderSize() ;
3289 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3291 return style
& ~wxBORDER_MASK
;
3294 // Find the wxWindowMac at the current mouse position, returning the mouse
3296 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3298 pt
= wxGetMousePosition();
3299 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3303 // Get the current mouse position.
3304 wxPoint
wxGetMousePosition()
3307 wxGetMousePosition(& x
, & y
);
3308 return wxPoint(x
, y
);
3311 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3313 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3315 // copied from wxGTK : CS
3316 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3319 // (a) it's a command event and so is propagated to the parent
3320 // (b) under MSW it can be generated from kbd too
3321 // (c) it uses screen coords (because of (a))
3322 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3324 this->ClientToScreen(event
.GetPosition()));
3325 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3334 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3336 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3338 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3342 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3346 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3350 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3351 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3355 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3357 return eventNotHandledErr
;