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 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 #if TARGET_API_MAC_OSX
83 EVT_PAINT(wxWindowMac::OnPaint
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 1
97 // ---------------------------------------------------------------------------
98 // Utility Routines to move between different coordinate systems
99 // ---------------------------------------------------------------------------
102 * Right now we have the following setup :
103 * a border that is not part of the native control is always outside the
104 * control's border (otherwise we loose all native intelligence, future ways
105 * may be to have a second embedding control responsible for drawing borders
106 * and backgrounds eventually)
107 * so all this border calculations have to be taken into account when calling
108 * native methods or getting native oriented data
109 * so we have three coordinate systems here
110 * wx client coordinates
111 * wx window coordinates (including window frames)
116 // originating from native control
120 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
122 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
125 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
127 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
131 // directed towards native control
134 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
136 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
139 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
141 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
150 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
152 #if TARGET_API_MAC_OSX
154 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
156 kEventControlVisibilityChanged
= 157
162 static const EventTypeSpec eventList
[] =
164 { kEventClassControl
, kEventControlHit
} ,
165 #if TARGET_API_MAC_OSX
166 { kEventClassControl
, kEventControlDraw
} ,
167 { kEventClassControl
, kEventControlVisibilityChanged
} ,
168 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
169 { kEventClassControl
, kEventControlHiliteChanged
} ,
170 { kEventClassControl
, kEventControlSetFocusPart
} ,
172 { kEventClassService
, kEventServiceGetTypes
},
173 { kEventClassService
, kEventServiceCopy
},
174 { kEventClassService
, kEventServicePaste
},
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177 // { kEventClassControl , kEventControlBoundsChanged } ,
181 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
183 OSStatus result
= eventNotHandledErr
;
185 wxMacCarbonEvent
cEvent( event
) ;
187 ControlRef controlRef
;
188 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
190 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
192 switch( GetEventKind( event
) )
194 #if TARGET_API_MAC_OSX
195 case kEventControlDraw
:
197 RgnHandle updateRgn
= NULL
;
198 RgnHandle allocatedRgn
= NULL
;
199 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
201 if ( thisWindow
->GetPeer()->IsCompositing() == false )
203 if ( thisWindow
->GetPeer()->IsRootControl() == false )
205 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
209 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
213 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
215 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
219 if ( thisWindow
->GetPeer()->IsCompositing() == false )
222 if ( thisWindow->GetPeer()->IsRootControl() == false )
224 GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
228 thisWindow->GetPeer()->GetRect( &controlBounds ) ;
231 allocatedRgn
= NewRgn() ;
232 CopyRgn( updateRgn
, allocatedRgn
) ;
233 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
234 // hide the given region by the new region that must be shifted
235 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
236 updateRgn
= allocatedRgn
;
240 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
242 // as this update region is in native window locals we must adapt it to wx window local
243 allocatedRgn
= NewRgn() ;
244 CopyRgn( updateRgn
, allocatedRgn
) ;
245 // hide the given region by the new region that must be shifted
246 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
247 updateRgn
= allocatedRgn
;
252 GetRegionBounds( updateRgn
, &rgnBounds
) ;
253 #if wxMAC_DEBUG_REDRAW
254 if ( thisWindow
->MacIsUserPane() )
256 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
257 static float color
= 0.5 ;
260 HIViewGetBounds( controlRef
, &bounds
);
261 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
262 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
263 CGContextFillRect( cgContext
, bounds
);
275 #if wxMAC_USE_CORE_GRAPHICS
276 bool created
= false ;
277 CGContextRef cgContext
= 0 ;
278 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
280 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
282 // this parameter is not provided on non-composited windows
284 // rest of the code expects this to be already transformed and clipped for local
285 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
287 GetPortBounds( port
, &bounds
) ;
288 CreateCGContextForPort( port
, &cgContext
) ;
290 wxMacWindowToNative( thisWindow
, updateRgn
) ;
291 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
292 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
293 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
294 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
296 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
297 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
299 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
302 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
303 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
304 controlBounds.right - controlBounds.left ,
305 controlBounds.bottom - controlBounds.top ) );
309 thisWindow
->MacSetCGContextRef( cgContext
) ;
311 wxMacCGContextStateSaver
sg( cgContext
) ;
313 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
315 #if wxMAC_USE_CORE_GRAPHICS
316 thisWindow
->MacSetCGContextRef( NULL
) ;
320 CGContextRelease( cgContext
) ;
325 DisposeRgn( allocatedRgn
) ;
328 case kEventControlVisibilityChanged
:
329 thisWindow
->MacVisibilityChanged() ;
331 case kEventControlEnabledStateChanged
:
332 thisWindow
->MacEnabledStateChanged() ;
334 case kEventControlHiliteChanged
:
335 thisWindow
->MacHiliteChanged() ;
338 // we emulate this event under Carbon CFM
339 case kEventControlSetFocusPart
:
341 Boolean focusEverything
= false ;
342 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
344 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
348 if ( controlPart
== kControlFocusNoPart
)
351 if ( thisWindow
->GetCaret() )
353 thisWindow
->GetCaret()->OnKillFocus();
355 #endif // wxUSE_CARET
356 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
357 event
.SetEventObject(thisWindow
);
358 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
362 // panel wants to track the window which was the last to have focus in it
363 wxChildFocusEvent
eventFocus(thisWindow
);
364 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
367 if ( thisWindow
->GetCaret() )
369 thisWindow
->GetCaret()->OnSetFocus();
371 #endif // wxUSE_CARET
373 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
374 event
.SetEventObject(thisWindow
);
375 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
377 if ( thisWindow
->MacIsUserPane() )
381 case kEventControlHit
:
383 result
= thisWindow
->MacControlHit( handler
, event
) ;
392 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
394 OSStatus result
= eventNotHandledErr
;
396 wxMacCarbonEvent
cEvent( event
) ;
398 ControlRef controlRef
;
399 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
400 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
401 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
403 switch( GetEventKind( event
) )
405 case kEventServiceGetTypes
:
409 textCtrl
->GetSelection( &from
, &to
) ;
411 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
413 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
414 if ( textCtrl
->IsEditable() )
415 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
417 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
418 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
420 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
424 CFArrayAppendValue (copyTypes
, typestring
) ;
426 CFArrayAppendValue (pasteTypes
, typestring
) ;
427 CFRelease( typestring
) ;
433 case kEventServiceCopy
:
437 textCtrl
->GetSelection( &from
, &to
) ;
438 wxString val
= textCtrl
->GetValue() ;
439 val
= val
.Mid( from
, to
- from
) ;
440 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
441 verify_noerr( ClearScrap( &scrapRef
) ) ;
442 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
446 case kEventServicePaste
:
449 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
450 Size textSize
, pastedSize
;
451 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
453 char *content
= new char[textSize
] ;
454 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
455 content
[textSize
-1] = 0 ;
457 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
459 textCtrl
->WriteText( wxString( content
) ) ;
470 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
472 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
473 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
474 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
475 OSStatus result
= eventNotHandledErr
;
477 switch ( GetEventClass( event
) )
479 case kEventClassControl
:
480 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
482 case kEventClassService
:
483 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
487 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
491 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
493 #if !TARGET_API_MAC_OSX
495 // ---------------------------------------------------------------------------
496 // UserPane events for non OSX builds
497 // ---------------------------------------------------------------------------
499 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
501 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
503 win
->MacControlUserPaneDrawProc(part
) ;
505 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
507 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
509 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
511 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
513 return kControlNoPart
;
515 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
517 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
519 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
521 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
523 return kControlNoPart
;
525 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
527 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
529 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
531 win
->MacControlUserPaneIdleProc() ;
533 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
535 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
537 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
539 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
541 return kControlNoPart
;
543 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
545 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
547 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
549 win
->MacControlUserPaneActivateProc(activating
) ;
551 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
553 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
555 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
557 return win
->MacControlUserPaneFocusProc(action
) ;
559 return kControlNoPart
;
561 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
563 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
565 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
567 win
->MacControlUserPaneBackgroundProc(info
) ;
569 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
571 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
573 RgnHandle rgn
= NewRgn() ;
576 MacWindowToRootWindow( &x
,&y
) ;
577 OffsetRgn( rgn
, -x
, -y
) ;
578 wxMacWindowStateSaver
sv( this ) ;
579 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
580 MacDoRedraw( rgn
, 0 ) ;
584 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
586 return kControlNoPart
;
589 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
591 return kControlNoPart
;
594 void wxWindowMac::MacControlUserPaneIdleProc()
598 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
600 return kControlNoPart
;
603 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
607 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
609 return kControlNoPart
;
612 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
618 // ---------------------------------------------------------------------------
619 // Scrollbar Tracking for all
620 // ---------------------------------------------------------------------------
622 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
623 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
627 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
630 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
634 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
636 // ===========================================================================
638 // ===========================================================================
640 #if KEY_wxList_DEPRECATED
641 wxList
wxWinMacControlList(wxKEY_INTEGER
);
643 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
645 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
648 return (wxControl
*)node
->GetData();
651 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
653 // adding NULL ControlRef is (first) surely a result of an error and
654 // (secondly) breaks native event processing
655 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
657 if ( !wxWinMacControlList
.Find((long)inControl
) )
658 wxWinMacControlList
.Append((long)inControl
, control
);
661 void wxRemoveMacControlAssociation(wxWindow
*control
)
663 // remove all associations pointing to us
664 while ( wxWinMacControlList
.DeleteObject(control
) )
669 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
671 static MacControlMap wxWinMacControlList
;
673 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
675 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
677 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
680 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
682 // adding NULL ControlRef is (first) surely a result of an error and
683 // (secondly) breaks native event processing
684 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
686 wxWinMacControlList
[inControl
] = control
;
689 void wxRemoveMacControlAssociation(wxWindow
*control
)
691 // iterate over all the elements in the class
692 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
693 // we should go on...
699 MacControlMap::iterator it
;
700 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
702 if ( it
->second
== control
)
704 wxWinMacControlList
.erase(it
);
711 #endif // deprecated wxList
713 // ----------------------------------------------------------------------------
714 // constructors and such
715 // ----------------------------------------------------------------------------
717 wxWindowMac::wxWindowMac()
722 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
727 const wxString
& name
)
730 Create(parent
, id
, pos
, size
, style
, name
);
733 void wxWindowMac::Init()
737 #if WXWIN_COMPATIBILITY_2_4
738 m_backgroundTransparent
= FALSE
;
741 // as all windows are created with WS_VISIBLE style...
744 m_hScrollBar
= NULL
;
745 m_vScrollBar
= NULL
;
746 m_macBackgroundBrush
= wxNullBrush
;
748 m_macIsUserPane
= TRUE
;
749 #if wxMAC_USE_CORE_GRAPHICS
750 m_cgContextRef
= NULL
;
752 m_clipChildren
= false ;
753 m_cachedClippedRectValid
= false ;
754 // we need a valid font for the encodings
755 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
759 wxWindowMac::~wxWindowMac()
763 m_isBeingDeleted
= TRUE
;
765 MacInvalidateBorders() ;
767 #ifndef __WXUNIVERSAL__
768 // VS: make sure there's no wxFrame with last focus set to us:
769 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
771 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
774 if ( frame
->GetLastFocus() == this )
776 frame
->SetLastFocus((wxWindow
*)NULL
);
781 #endif // __WXUNIVERSAL__
783 // destroy children before destroying this window itself
786 // wxRemoveMacControlAssociation( this ) ;
787 // If we delete an item, we should initialize the parent panel,
788 // because it could now be invalid.
789 wxWindow
*parent
= GetParent() ;
792 if (parent
->GetDefaultItem() == (wxButton
*) this)
793 parent
->SetDefaultItem(NULL
);
795 if ( m_peer
&& m_peer
->Ok() )
797 // in case the callback might be called during destruction
798 wxRemoveMacControlAssociation( this) ;
799 // we currently are not using this hook
800 // ::SetControlColorProc( *m_peer , NULL ) ;
804 if ( g_MacLastWindow
== this )
806 g_MacLastWindow
= NULL
;
809 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
812 if ( frame
->GetLastFocus() == this )
813 frame
->SetLastFocus( NULL
) ;
816 // delete our drop target if we've got one
817 #if wxUSE_DRAG_AND_DROP
818 if ( m_dropTarget
!= NULL
)
823 #endif // wxUSE_DRAG_AND_DROP
827 WXWidget
wxWindowMac::GetHandle() const
829 return (WXWidget
) m_peer
->GetControlRef() ;
833 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
835 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
836 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
837 GetEventTypeCount(eventList
), eventList
, this,
838 (EventHandlerRef
*)&m_macControlEventHandler
);
839 #if !TARGET_API_MAC_OSX
840 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
842 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,GetwxMacControlUserPaneDrawProc()) ;
843 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,GetwxMacControlUserPaneHitTestProc()) ;
844 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,GetwxMacControlUserPaneTrackingProc()) ;
845 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,GetwxMacControlUserPaneIdleProc()) ;
846 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,GetwxMacControlUserPaneKeyDownProc()) ;
847 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,GetwxMacControlUserPaneActivateProc()) ;
848 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,GetwxMacControlUserPaneFocusProc()) ;
849 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,GetwxMacControlUserPaneBackgroundProc()) ;
856 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
860 const wxString
& name
)
862 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
864 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
867 m_windowVariant
= parent
->GetWindowVariant() ;
869 if ( m_macIsUserPane
)
871 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
874 | kControlSupportsEmbedding
875 | kControlSupportsLiveFeedback
876 | kControlGetsFocusOnClick
877 // | kControlHasSpecialBackground
878 // | kControlSupportsCalcBestRect
879 | kControlHandlesTracking
880 | kControlSupportsFocus
881 | kControlWantsActivate
885 m_peer
= new wxMacControl(this) ;
886 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
889 MacPostControlCreate(pos
,size
) ;
891 #ifndef __WXUNIVERSAL__
892 // Don't give scrollbars to wxControls unless they ask for them
893 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
894 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
896 MacCreateScrollBars( style
) ;
900 wxWindowCreateEvent
event(this);
901 GetEventHandler()->AddPendingEvent(event
);
906 void wxWindowMac::MacChildAdded()
910 m_vScrollBar
->Raise() ;
914 m_hScrollBar
->Raise() ;
919 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
921 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
923 m_peer
->SetReference( (long) this ) ;
924 GetParent()->AddChild(this);
926 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
928 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
929 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
930 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
931 GetParent()->MacChildAdded() ;
933 // adjust font, controlsize etc
934 DoSetWindowVariant( m_windowVariant
) ;
936 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
938 if (!m_macIsUserPane
)
940 SetInitialBestSize(size
);
943 SetCursor( *wxSTANDARD_CURSOR
) ;
946 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
948 // Don't assert, in case we set the window variant before
949 // the window is created
950 // wxASSERT( m_peer->Ok() ) ;
952 m_windowVariant
= variant
;
954 if (m_peer
== NULL
|| !m_peer
->Ok())
958 ThemeFontID themeFont
= kThemeSystemFont
;
960 // we will get that from the settings later
961 // and make this NORMAL later, but first
962 // we have a few calculations that we must fix
966 case wxWINDOW_VARIANT_NORMAL
:
967 size
= kControlSizeNormal
;
968 themeFont
= kThemeSystemFont
;
970 case wxWINDOW_VARIANT_SMALL
:
971 size
= kControlSizeSmall
;
972 themeFont
= kThemeSmallSystemFont
;
974 case wxWINDOW_VARIANT_MINI
:
975 if (UMAGetSystemVersion() >= 0x1030 )
977 // not always defined in the headers
983 size
= kControlSizeSmall
;
984 themeFont
= kThemeSmallSystemFont
;
987 case wxWINDOW_VARIANT_LARGE
:
988 size
= kControlSizeLarge
;
989 themeFont
= kThemeSystemFont
;
992 wxFAIL_MSG(_T("unexpected window variant"));
995 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
998 font
.MacCreateThemeFont( themeFont
) ;
1002 void wxWindowMac::MacUpdateControlFont()
1004 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1008 bool wxWindowMac::SetFont(const wxFont
& font
)
1010 bool retval
= wxWindowBase::SetFont( font
) ;
1012 MacUpdateControlFont() ;
1017 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1019 if ( !wxWindowBase::SetForegroundColour(col
) )
1022 MacUpdateControlFont() ;
1027 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1029 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1033 wxColour
newCol(GetBackgroundColour());
1034 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1036 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1038 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1040 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1044 brush
.SetColour( newCol
) ;
1046 MacSetBackgroundBrush( brush
) ;
1048 MacUpdateControlFont() ;
1053 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1055 m_macBackgroundBrush
= brush
;
1056 m_peer
->SetBackground( brush
) ;
1059 bool wxWindowMac::MacCanFocus() const
1061 // there is currently no way to determine whether the window is running in full keyboard
1062 // access mode, therefore we cannot rely on these features, yet the only other way would be
1063 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1064 // in event handlers...
1065 UInt32 features
= 0 ;
1066 m_peer
->GetFeatures( & features
) ;
1067 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1071 void wxWindowMac::SetFocus()
1073 if ( AcceptsFocus() )
1076 wxWindow
* former
= FindFocus() ;
1077 if ( former
== this )
1080 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1081 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1082 // leave in case of an error
1083 if ( err
== errCouldntSetFocus
)
1086 #if !TARGET_API_MAC_OSX
1087 // emulate carbon events when running under carbonlib where they are not natively available
1090 EventRef evRef
= NULL
;
1091 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1094 wxMacCarbonEvent
cEvent( evRef
) ;
1095 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1096 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1098 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1099 ReleaseEvent(evRef
) ;
1101 // send new focus event
1103 EventRef evRef
= NULL
;
1104 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1107 wxMacCarbonEvent
cEvent( evRef
) ;
1108 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1109 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1111 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1112 ReleaseEvent(evRef
) ;
1119 void wxWindowMac::DoCaptureMouse()
1121 wxApp::s_captureWindow
= this ;
1124 wxWindow
* wxWindowBase::GetCapture()
1126 return wxApp::s_captureWindow
;
1129 void wxWindowMac::DoReleaseMouse()
1131 wxApp::s_captureWindow
= NULL
;
1134 #if wxUSE_DRAG_AND_DROP
1136 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1138 if ( m_dropTarget
!= 0 ) {
1139 delete m_dropTarget
;
1142 m_dropTarget
= pDropTarget
;
1143 if ( m_dropTarget
!= 0 )
1151 // Old style file-manager drag&drop
1152 void wxWindowMac::DragAcceptFiles(bool accept
)
1157 // Returns the size of the native control. In the case of the toplevel window
1158 // this is the content area root control
1160 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1161 int& w
, int& h
) const
1163 wxFAIL_MSG( wxT("Not supported anymore") ) ;
1166 // From a wx position / size calculate the appropriate size of the native control
1168 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1171 int& w
, int& h
, bool adjustOrigin
) const
1173 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1175 // the desired size, minus the border pixels gives the correct size of the control
1179 // todo the default calls may be used as soon as PostCreateControl Is moved here
1180 w
= wxMax(size
.x
,0) ; // WidthDefault( size.x );
1181 h
= wxMax(size
.y
,0) ; // HeightDefault( size.y ) ;
1183 if ( !isCompositing
)
1184 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1186 x
+= MacGetLeftBorderSize() ;
1187 y
+= MacGetTopBorderSize() ;
1188 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1189 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1192 AdjustForParentClientOrigin( x
, y
) ;
1194 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1195 if ( !GetParent()->IsTopLevel() )
1197 x
-= GetParent()->MacGetLeftBorderSize() ;
1198 y
-= GetParent()->MacGetTopBorderSize() ;
1204 // Get window size (not client size)
1205 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1208 m_peer
->GetRect( &bounds
) ;
1210 if(x
) *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1211 if(y
) *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1214 // get the position of the bounds of this window in client coordinates of its parent
1215 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1218 m_peer
->GetRect( &bounds
) ;
1220 int x1
= bounds
.left
;
1221 int y1
= bounds
.top
;
1223 // get the wx window position from the native one
1224 x1
-= MacGetLeftBorderSize() ;
1225 y1
-= MacGetTopBorderSize() ;
1227 if ( !IsTopLevel() )
1229 wxWindow
*parent
= GetParent();
1232 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1233 x1
+= parent
->MacGetLeftBorderSize() ;
1234 y1
+= parent
->MacGetTopBorderSize() ;
1235 // and now to client coordinates
1236 wxPoint
pt(parent
->GetClientAreaOrigin());
1245 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1247 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1249 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1252 Point localwhere
= {0,0} ;
1254 if(x
) localwhere
.h
= * x
;
1255 if(y
) localwhere
.v
= * y
;
1257 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1258 if(x
) *x
= localwhere
.h
;
1259 if(y
) *y
= localwhere
.v
;
1262 MacRootWindowToWindow( x
, y
) ;
1264 wxPoint origin
= GetClientAreaOrigin() ;
1265 if(x
) *x
-= origin
.x
;
1266 if(y
) *y
-= origin
.y
;
1269 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1271 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1272 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1274 wxPoint origin
= GetClientAreaOrigin() ;
1275 if(x
) *x
+= origin
.x
;
1276 if(y
) *y
+= origin
.y
;
1278 MacWindowToRootWindow( x
, y
) ;
1281 Point localwhere
= { 0,0 };
1282 if(x
) localwhere
.h
= * x
;
1283 if(y
) localwhere
.v
= * y
;
1284 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1285 if(x
) *x
= localwhere
.h
;
1286 if(y
) *y
= localwhere
.v
;
1290 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1292 wxPoint origin
= GetClientAreaOrigin() ;
1293 if(x
) *x
+= origin
.x
;
1294 if(y
) *y
+= origin
.y
;
1296 MacWindowToRootWindow( x
, y
) ;
1299 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1301 MacRootWindowToWindow( x
, y
) ;
1303 wxPoint origin
= GetClientAreaOrigin() ;
1304 if(x
) *x
-= origin
.x
;
1305 if(y
) *y
-= origin
.y
;
1308 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1311 if ( x
) pt
.x
= *x
;
1312 if ( y
) pt
.y
= *y
;
1314 if ( !IsTopLevel() )
1316 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1319 pt
.x
-= MacGetLeftBorderSize() ;
1320 pt
.y
-= MacGetTopBorderSize() ;
1321 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1325 if ( x
) *x
= (int) pt
.x
;
1326 if ( y
) *y
= (int) pt
.y
;
1329 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1334 MacWindowToRootWindow( &x1
, &y1
) ;
1339 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1342 if ( x
) pt
.x
= *x
;
1343 if ( y
) pt
.y
= *y
;
1345 if ( !IsTopLevel() )
1347 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1350 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1351 pt
.x
+= MacGetLeftBorderSize() ;
1352 pt
.y
+= MacGetTopBorderSize() ;
1356 if ( x
) *x
= (int) pt
.x
;
1357 if ( y
) *y
= (int) pt
.y
;
1360 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1365 MacRootWindowToWindow( &x1
, &y1
) ;
1370 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1372 RgnHandle rgn
= NewRgn() ;
1373 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1377 GetRegionBounds( rgn
, &content
) ;
1378 m_peer
->GetRect( &structure
) ;
1379 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1381 left
= content
.left
- structure
.left
;
1382 top
= content
.top
- structure
.top
;
1383 right
= structure
.right
- content
.right
;
1384 bottom
= structure
.bottom
- content
.bottom
;
1388 left
= top
= right
= bottom
= 0 ;
1393 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1395 wxSize sizeTotal
= size
;
1397 RgnHandle rgn
= NewRgn() ;
1399 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1403 GetRegionBounds( rgn
, &content
) ;
1405 m_peer
->GetRect( &structure
) ;
1406 // structure is in parent coordinates, but we only need width and height, so it's ok
1408 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1409 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1413 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1414 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1420 // Get size *available for subwindows* i.e. excluding menu bar etc.
1421 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1425 RgnHandle rgn
= NewRgn() ;
1427 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1429 GetRegionBounds( rgn
, &content
) ;
1433 m_peer
->GetRect( &content
) ;
1437 ww
= content
.right
- content
.left
;
1438 hh
= content
.bottom
- content
.top
;
1440 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1442 hh
-= m_hScrollBar
->GetSize().y
;
1444 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1446 ww
-= m_vScrollBar
->GetSize().x
;
1453 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1455 if (m_cursor
== cursor
)
1458 if (wxNullCursor
== cursor
)
1460 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1465 if ( ! wxWindowBase::SetCursor( cursor
) )
1469 wxASSERT_MSG( m_cursor
.Ok(),
1470 wxT("cursor must be valid after call to the base version"));
1473 wxWindowMac
*mouseWin
= 0 ;
1475 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1476 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1478 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1480 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1481 // position, use it...
1485 ControlPartCode part
;
1486 ControlRef control
;
1487 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1489 mouseWin
= wxFindControlFromMacControl( control
) ;
1492 QDSwapPort( savePort
, NULL
) ;
1495 if ( mouseWin
== this && !wxIsBusy() )
1497 m_cursor
.MacInstall() ;
1504 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1506 menu
->SetInvokingWindow(this);
1509 if ( x
== -1 && y
== -1 )
1511 wxPoint mouse
= wxGetMousePosition();
1512 x
= mouse
.x
; y
= mouse
.y
;
1516 ClientToScreen( &x
, &y
) ;
1519 menu
->MacBeforeDisplay( true ) ;
1520 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1521 if ( HiWord(menuResult
) != 0 )
1524 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1525 wxMenuItem
* item
= NULL
;
1527 item
= menu
->FindItem(id
, &realmenu
) ;
1528 if (item
->IsCheckable())
1530 item
->Check( !item
->IsChecked() ) ;
1532 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1534 menu
->MacAfterDisplay( true ) ;
1536 menu
->SetInvokingWindow(NULL
);
1542 // ----------------------------------------------------------------------------
1544 // ----------------------------------------------------------------------------
1548 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1550 wxWindowBase::DoSetToolTip(tooltip
);
1553 m_tooltip
->SetWindow(this);
1556 #endif // wxUSE_TOOLTIPS
1558 void wxWindowMac::MacInvalidateBorders()
1560 if ( m_peer
== NULL
)
1563 bool vis
= MacIsReallyShown() ;
1567 int outerBorder
= MacGetLeftBorderSize() ;
1568 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1571 if ( outerBorder
== 0 )
1574 // now we know that we have something to do at all
1576 // as the borders are drawn on the parent we have to properly invalidate all these areas
1577 RgnHandle updateInner
= NewRgn() ,
1578 updateOuter
= NewRgn() ;
1580 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1582 m_peer
->GetRect( &rect
) ;
1583 RectRgn( updateInner
, &rect
) ;
1584 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1585 RectRgn( updateOuter
, &rect
) ;
1586 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1587 #ifdef __WXMAC_OSX__
1588 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1590 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1592 InvalWindowRgn( tlw
, updateOuter
) ;
1594 DisposeRgn(updateOuter
) ;
1595 DisposeRgn(updateInner
) ;
1597 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1598 RectRgn( updateInner , &rect ) ;
1599 InsetRect( &rect , -4 , -4 ) ;
1600 RectRgn( updateOuter , &rect ) ;
1601 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1602 wxPoint parent(0,0);
1603 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1604 parent -= GetParent()->GetClientAreaOrigin() ;
1605 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1606 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1607 DisposeRgn(updateOuter) ;
1608 DisposeRgn(updateInner) ;
1613 // deleting a window while it is shown invalidates the region occupied by border or
1616 if ( IsShown() && ( outerBorder > 0 ) )
1618 // as the borders are drawn on the parent we have to properly invalidate all these areas
1619 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1623 m_peer->GetRect( &rect ) ;
1624 RectRgn( updateInner , &rect ) ;
1625 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1626 RectRgn( updateOuter , &rect ) ;
1627 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1628 wxPoint parent(0,0);
1629 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1630 parent -= GetParent()->GetClientAreaOrigin() ;
1631 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1632 CopyRgn( updateOuter , updateTotal ) ;
1634 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1635 DisposeRgn(updateOuter) ;
1636 DisposeRgn(updateInner) ;
1637 DisposeRgn(updateTotal) ;
1642 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1644 int outerBorder
= MacGetLeftBorderSize() ;
1645 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1648 if ( vis
&& ( outerBorder
> 0 ) )
1650 // as the borders are drawn on the parent we have to properly invalidate all these areas
1651 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1655 m_peer
->GetRect( &rect
) ;
1656 RectRgn( updateInner
, &rect
) ;
1657 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1658 RectRgn( updateOuter
, &rect
) ;
1659 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1661 wxPoint parent(0,0);
1662 #if TARGET_API_MAC_OSX
1663 // no offsetting needed when compositing
1665 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1666 parent -= GetParent()->GetClientAreaOrigin() ;
1667 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1670 CopyRgn( updateOuter
, updateTotal
) ;
1673 RectRgn( updateInner
, &rect
) ;
1674 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1675 RectRgn( updateOuter
, &rect
) ;
1676 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1678 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1680 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1682 GetParent()->m_peer
->SetNeedsDisplay( updateTotal
) ;
1683 DisposeRgn(updateOuter
) ;
1684 DisposeRgn(updateInner
) ;
1685 DisposeRgn(updateTotal
) ;
1690 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1692 // this is never called for a toplevel window, so we know we have a parent
1693 int former_x
, former_y
, former_w
, former_h
;
1695 // Get true coordinates of former position
1696 DoGetPosition( &former_x
, &former_y
) ;
1697 DoGetSize( &former_w
, &former_h
) ;
1699 wxWindow
*parent
= GetParent();
1702 wxPoint
pt(parent
->GetClientAreaOrigin());
1707 int actualWidth
= width
;
1708 int actualHeight
= height
;
1712 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1713 actualWidth
= m_minWidth
;
1714 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1715 actualHeight
= m_minHeight
;
1716 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1717 actualWidth
= m_maxWidth
;
1718 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1719 actualHeight
= m_maxHeight
;
1721 bool doMove
= false ;
1722 bool doResize
= false ;
1724 if ( actualX
!= former_x
|| actualY
!= former_y
)
1728 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1733 if ( doMove
|| doResize
)
1735 // as the borders are drawn outside the native control, we adjust now
1737 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1738 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1739 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1742 wxMacRectToNative( &bounds
, &r
) ;
1744 if ( !GetParent()->IsTopLevel() )
1746 wxMacWindowToNative( GetParent() , &r
) ;
1749 MacInvalidateBorders() ;
1751 m_cachedClippedRectValid
= false ;
1752 m_peer
->SetRect( &r
) ;
1754 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1756 MacInvalidateBorders() ;
1758 MacRepositionScrollBars() ;
1761 wxPoint
point(actualX
,actualY
);
1762 wxMoveEvent
event(point
, m_windowId
);
1763 event
.SetEventObject(this);
1764 GetEventHandler()->ProcessEvent(event
) ;
1768 MacRepositionScrollBars() ;
1769 wxSize
size(actualWidth
, actualHeight
);
1770 wxSizeEvent
event(size
, m_windowId
);
1771 event
.SetEventObject(this);
1772 GetEventHandler()->ProcessEvent(event
);
1778 wxSize
wxWindowMac::DoGetBestSize() const
1780 if ( m_macIsUserPane
|| IsTopLevel() )
1781 return wxWindowBase::DoGetBestSize() ;
1783 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1784 int bestWidth
, bestHeight
;
1785 m_peer
->GetBestRect( &bestsize
) ;
1787 if ( EmptyRect( &bestsize
) )
1789 bestsize
.left
= bestsize
.top
= 0 ;
1790 bestsize
.right
= 16 ;
1791 bestsize
.bottom
= 16 ;
1792 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1794 bestsize
.bottom
= 16 ;
1797 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1799 bestsize
.bottom
= 24 ;
1801 #endif // wxUSE_SPINBTN
1804 // return wxWindowBase::DoGetBestSize() ;
1808 bestWidth
= bestsize
.right
- bestsize
.left
;
1809 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1810 if ( bestHeight
< 10 )
1813 return wxSize(bestWidth
, bestHeight
);
1817 // set the size of the window: if the dimensions are positive, just use them,
1818 // but if any of them is equal to -1, it means that we must find the value for
1819 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1820 // which case -1 is a valid value for x and y)
1822 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1823 // the width/height to best suit our contents, otherwise we reuse the current
1825 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1827 // get the current size and position...
1828 int currentX
, currentY
;
1829 GetPosition(¤tX
, ¤tY
);
1831 int currentW
,currentH
;
1832 GetSize(¤tW
, ¤tH
);
1834 // ... and don't do anything (avoiding flicker) if it's already ok
1835 if ( x
== currentX
&& y
== currentY
&&
1836 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1839 MacRepositionScrollBars() ; // we might have a real position shift
1843 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1845 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1848 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1850 wxSize
size(-1, -1);
1853 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1855 size
= DoGetBestSize();
1860 // just take the current one
1867 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1871 size
= DoGetBestSize();
1873 //else: already called DoGetBestSize() above
1879 // just take the current one
1884 DoMoveWindow(x
, y
, width
, height
);
1888 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1890 RgnHandle rgn
= NewRgn() ;
1892 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1894 GetRegionBounds( rgn
, &content
) ;
1898 content
.left
= content
.top
= 0 ;
1901 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1904 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1906 if ( clientheight
!= -1 || clientheight
!= -1 )
1908 int currentclientwidth
, currentclientheight
;
1909 int currentwidth
, currentheight
;
1911 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1912 GetSize( ¤twidth
, ¤theight
) ;
1914 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1915 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1919 void wxWindowMac::SetTitle(const wxString
& title
)
1921 m_label
= wxStripMenuCodes(title
) ;
1923 if ( m_peer
&& m_peer
->Ok() )
1925 m_peer
->SetTitle( m_label
) ;
1930 wxString
wxWindowMac::GetTitle() const
1935 bool wxWindowMac::Show(bool show
)
1937 bool former
= MacIsReallyShown() ;
1938 if ( !wxWindowBase::Show(show
) )
1941 // TODO use visibilityChanged Carbon Event for OSX
1944 m_peer
->SetVisibility( show
, true ) ;
1946 if ( former
!= MacIsReallyShown() )
1947 MacPropagateVisibilityChanged() ;
1951 bool wxWindowMac::Enable(bool enable
)
1953 wxASSERT( m_peer
->Ok() ) ;
1954 bool former
= MacIsReallyEnabled() ;
1955 if ( !wxWindowBase::Enable(enable
) )
1958 m_peer
->Enable( enable
) ;
1960 if ( former
!= MacIsReallyEnabled() )
1961 MacPropagateEnabledStateChanged() ;
1966 // status change propagations (will be not necessary for OSX later )
1969 void wxWindowMac::MacPropagateVisibilityChanged()
1971 #if !TARGET_API_MAC_OSX
1972 MacVisibilityChanged() ;
1974 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1977 wxWindowMac
*child
= node
->GetData();
1978 if ( child
->IsShown() )
1979 child
->MacPropagateVisibilityChanged( ) ;
1980 node
= node
->GetNext();
1985 void wxWindowMac::MacPropagateEnabledStateChanged( )
1987 #if !TARGET_API_MAC_OSX
1988 MacEnabledStateChanged() ;
1990 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1993 wxWindowMac
*child
= node
->GetData();
1994 if ( child
->IsEnabled() )
1995 child
->MacPropagateEnabledStateChanged() ;
1996 node
= node
->GetNext();
2001 void wxWindowMac::MacPropagateHiliteChanged( )
2003 #if !TARGET_API_MAC_OSX
2004 MacHiliteChanged() ;
2006 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2009 wxWindowMac
*child
= node
->GetData();
2010 // if ( child->IsEnabled() )
2011 child
->MacPropagateHiliteChanged() ;
2012 node
= node
->GetNext();
2018 // status change notifications
2021 void wxWindowMac::MacVisibilityChanged()
2025 void wxWindowMac::MacHiliteChanged()
2029 void wxWindowMac::MacEnabledStateChanged()
2034 // status queries on the inherited window's state
2037 bool wxWindowMac::MacIsReallyShown()
2039 // only under OSX the visibility of the TLW is taken into account
2040 if ( m_isBeingDeleted
)
2043 #if TARGET_API_MAC_OSX
2044 if ( m_peer
&& m_peer
->Ok() )
2045 return m_peer
->IsVisible();
2047 wxWindow
* win
= this ;
2048 while( win
->IsShown() )
2050 if ( win
->IsTopLevel() )
2053 win
= win
->GetParent() ;
2061 bool wxWindowMac::MacIsReallyEnabled()
2063 return m_peer
->IsEnabled() ;
2066 bool wxWindowMac::MacIsReallyHilited()
2068 return m_peer
->IsActive();
2071 void wxWindowMac::MacFlashInvalidAreas()
2073 #if TARGET_API_MAC_OSX
2074 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2082 int wxWindowMac::GetCharHeight() const
2084 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2085 return dc
.GetCharHeight() ;
2088 int wxWindowMac::GetCharWidth() const
2090 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2091 return dc
.GetCharWidth() ;
2094 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2095 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2097 const wxFont
*fontToUse
= theFont
;
2099 fontToUse
= &m_font
;
2101 wxClientDC
dc( (wxWindowMac
*) this ) ;
2103 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2104 if ( externalLeading
)
2105 *externalLeading
= le
;
2115 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2116 * we always intersect with the entire window, not only with the client area
2119 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2121 if ( m_peer
== NULL
)
2124 if ( !MacIsReallyShown() )
2130 wxMacRectToNative( rect
, &r
) ;
2131 m_peer
->SetNeedsDisplay( &r
) ;
2135 m_peer
->SetNeedsDisplay() ;
2139 void wxWindowMac::Freeze()
2141 #if TARGET_API_MAC_OSX
2142 if ( !m_frozenness
++ )
2144 if ( m_peer
&& m_peer
->Ok() )
2145 m_peer
->SetDrawingEnabled( false ) ;
2151 void wxWindowMac::Thaw()
2153 #if TARGET_API_MAC_OSX
2154 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2156 if ( !--m_frozenness
)
2158 if ( m_peer
&& m_peer
->Ok() )
2160 m_peer
->SetDrawingEnabled( true ) ;
2161 m_peer
->InvalidateWithChildren() ;
2167 wxWindowMac
*wxGetActiveWindow()
2169 // actually this is a windows-only concept
2173 // Coordinates relative to the window
2174 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2176 // We really don't move the mouse programmatically under Mac.
2179 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2181 #if TARGET_API_MAC_OSX
2182 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2189 event
.GetDC()->Clear() ;
2193 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2198 int wxWindowMac::GetScrollPos(int orient
) const
2200 if ( orient
== wxHORIZONTAL
)
2203 return m_hScrollBar
->GetThumbPosition() ;
2208 return m_vScrollBar
->GetThumbPosition() ;
2213 // This now returns the whole range, not just the number
2214 // of positions that we can scroll.
2215 int wxWindowMac::GetScrollRange(int orient
) const
2217 if ( orient
== wxHORIZONTAL
)
2220 return m_hScrollBar
->GetRange() ;
2225 return m_vScrollBar
->GetRange() ;
2230 int wxWindowMac::GetScrollThumb(int orient
) const
2232 if ( orient
== wxHORIZONTAL
)
2235 return m_hScrollBar
->GetThumbSize() ;
2240 return m_vScrollBar
->GetThumbSize() ;
2245 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2247 if ( orient
== wxHORIZONTAL
)
2250 m_hScrollBar
->SetThumbPosition( pos
) ;
2255 m_vScrollBar
->SetThumbPosition( pos
) ;
2260 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2261 // our own window origin is at leftOrigin/rightOrigin
2264 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2270 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2271 bool hasBothScrollbars
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2273 m_peer
->GetRect( &rect
) ;
2274 // back to the surrounding frame rectangle
2275 InsetRect( &rect
, -1 , -1 ) ;
2277 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2278 if ( UMAGetSystemVersion() >= 0x1030 )
2280 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2281 rect
.bottom
- rect
.top
) ;
2283 HIThemeFrameDrawInfo info
;
2284 memset( &info
, 0 , sizeof( info
) ) ;
2288 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2289 info
.isFocused
= hasFocus
;
2291 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2292 wxASSERT( cgContext
) ;
2294 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2296 info
.kind
= kHIThemeFrameTextFieldSquare
;
2297 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2299 else if (HasFlag(wxSIMPLE_BORDER
))
2301 info
.kind
= kHIThemeFrameListBox
;
2302 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2304 else if ( hasFocus
)
2306 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2309 m_peer
->GetRect( &rect
) ;
2310 if ( hasBothScrollbars
)
2312 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2313 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2314 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2315 HIThemeGrowBoxDrawInfo info
;
2316 memset( &info
, 0 , sizeof( info
) ) ;
2318 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2319 info
.kind
= kHIThemeGrowBoxKindNone
;
2320 info
.size
= kHIThemeGrowBoxSizeNormal
;
2321 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2322 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2328 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2332 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2333 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2336 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2338 DrawThemeEditTextFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2340 else if (HasFlag(wxSIMPLE_BORDER
))
2342 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2347 DrawThemeFocusRect( &rect
, true ) ;
2350 if ( hasBothScrollbars
)
2352 // GetThemeStandaloneGrowBoxBounds
2353 //DrawThemeStandaloneNoGrowBox
2358 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2360 if ( child
== m_hScrollBar
)
2361 m_hScrollBar
= NULL
;
2362 if ( child
== m_vScrollBar
)
2363 m_vScrollBar
= NULL
;
2365 wxWindowBase::RemoveChild( child
) ;
2368 // New function that will replace some of the above.
2369 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2370 int range
, bool refresh
)
2372 if ( orient
== wxHORIZONTAL
)
2376 if ( range
== 0 || thumbVisible
>= range
)
2378 if ( m_hScrollBar
->IsShown() )
2379 m_hScrollBar
->Show(false) ;
2383 if ( !m_hScrollBar
->IsShown() )
2384 m_hScrollBar
->Show(true) ;
2386 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2393 if ( range
== 0 || thumbVisible
>= range
)
2395 if ( m_vScrollBar
->IsShown() )
2396 m_vScrollBar
->Show(false) ;
2400 if ( !m_vScrollBar
->IsShown() )
2401 m_vScrollBar
->Show(true) ;
2403 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2406 MacRepositionScrollBars() ;
2409 // Does a physical scroll
2410 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2412 if( dx
== 0 && dy
==0 )
2415 int width
, height
;
2416 GetClientSize( &width
, &height
) ;
2417 #if TARGET_API_MAC_OSX
2418 if ( 1 /* m_peer->IsCompositing() */ )
2420 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2421 // area is scrolled, this does not occur if width and height are 2 pixels less,
2422 // TODO write optimal workaround
2423 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2426 scrollrect
.Intersect( *rect
) ;
2428 if ( m_peer
->GetNeedsDisplay() )
2430 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2431 // either immediate redraw or full invalidate
2433 // is the better overall solution, as it does not slow down scrolling
2434 m_peer
->SetNeedsDisplay() ;
2436 // this would be the preferred version for fast drawing controls
2438 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2439 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2440 HIViewRender(m_peer
->GetControlRef()) ;
2446 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2447 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2448 m_peer
->ScrollRect( (&scrollrect
) , dx
, dy
) ;
2450 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2451 // either immediate redraw or full invalidate
2453 // is the better overall solution, as it does not slow down scrolling
2454 m_peer
->SetNeedsDisplay() ;
2456 // this would be the preferred version for fast drawing controls
2458 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2459 if( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2460 HIViewRender(m_peer
->GetControlRef()) ;
2475 RgnHandle updateRgn
= NewRgn() ;
2478 wxClientDC
dc(this) ;
2479 wxMacPortSetter
helper(&dc
) ;
2481 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2482 //scrollrect.top += MacGetTopBorderSize() ;
2483 //scrollrect.left += MacGetLeftBorderSize() ;
2484 scrollrect
.bottom
= scrollrect
.top
+ height
;
2485 scrollrect
.right
= scrollrect
.left
+ width
;
2489 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2490 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2491 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2493 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2495 // now scroll the former update region as well and add the new update region
2497 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2498 RgnHandle formerUpdateRgn
= NewRgn() ;
2499 RgnHandle scrollRgn
= NewRgn() ;
2500 RectRgn( scrollRgn
, &scrollrect
) ;
2501 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2503 LocalToGlobal( &pt
) ;
2504 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2505 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2506 if ( !EmptyRgn( formerUpdateRgn
) )
2508 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2509 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2510 InvalWindowRgn(rootWindow
, formerUpdateRgn
) ;
2512 InvalWindowRgn(rootWindow
, updateRgn
) ;
2513 DisposeRgn( updateRgn
) ;
2514 DisposeRgn( formerUpdateRgn
) ;
2515 DisposeRgn( scrollRgn
) ;
2520 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2522 wxWindowMac
*child
= node
->GetData();
2523 if (child
== m_vScrollBar
) continue;
2524 if (child
== m_hScrollBar
) continue;
2525 if (child
->IsTopLevel()) continue;
2528 child
->GetPosition( &x
, &y
);
2530 child
->GetSize( &w
, &h
);
2534 if (rect
->Intersects(rc
))
2535 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2539 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2544 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2546 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2548 wxScrollWinEvent wevent
;
2549 wevent
.SetPosition(event
.GetPosition());
2550 wevent
.SetOrientation(event
.GetOrientation());
2551 wevent
.SetEventObject(this);
2553 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2554 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2555 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2556 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2557 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2558 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2559 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2560 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2561 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2562 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2563 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2564 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2565 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2566 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2567 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2568 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2570 GetEventHandler()->ProcessEvent(wevent
);
2574 // Get the window with the focus
2575 wxWindowMac
*wxWindowBase::DoFindFocus()
2577 ControlRef control
;
2578 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2579 return wxFindControlFromMacControl( control
) ;
2582 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2584 // panel wants to track the window which was the last to have focus in it,
2585 // so we want to set ourselves as the window which last had focus
2587 // notice that it's also important to do it upwards the tree becaus
2588 // otherwise when the top level panel gets focus, it won't set it back to
2589 // us, but to some other sibling
2591 // CS:don't know if this is still needed:
2592 //wxChildFocusEvent eventFocus(this);
2593 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2595 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2597 #if !wxMAC_USE_CORE_GRAPHICS
2598 wxMacWindowStateSaver
sv( this ) ;
2600 m_peer
->GetRect( &rect
) ;
2601 // auf den umgebenden Rahmen zur\9fck
2602 InsetRect( &rect
, -1 , -1 ) ;
2604 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2608 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2610 rect
.right
+= pt
.x
;
2612 rect
.bottom
+= pt
.y
;
2615 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2616 DrawThemeFocusRect( &rect
, true ) ;
2619 DrawThemeFocusRect( &rect
, false ) ;
2621 // as this erases part of the frame we have to redraw borders
2622 // and because our z-ordering is not always correct (staticboxes)
2623 // we have to invalidate things, we cannot simple redraw
2624 MacInvalidateBorders() ;
2627 GetParent()->Refresh() ;
2634 void wxWindowMac::OnInternalIdle()
2636 // This calls the UI-update mechanism (querying windows for
2637 // menu/toolbar/control state information)
2638 if (wxUpdateUIEvent::CanUpdate(this))
2639 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2642 // Raise the window to the top of the Z order
2643 void wxWindowMac::Raise()
2645 m_peer
->SetZOrder( true , NULL
) ;
2648 // Lower the window to the bottom of the Z order
2649 void wxWindowMac::Lower()
2651 m_peer
->SetZOrder( false , NULL
) ;
2655 // static wxWindow *gs_lastWhich = NULL;
2657 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2659 // first trigger a set cursor event
2661 wxPoint clientorigin
= GetClientAreaOrigin() ;
2662 wxSize clientsize
= GetClientSize() ;
2664 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2666 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2668 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2669 if ( processedEvtSetCursor
&& event
.HasCursor() )
2671 cursor
= event
.GetCursor() ;
2676 // the test for processedEvtSetCursor is here to prevent using m_cursor
2677 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2678 // it - this is a way to say that our cursor shouldn't be used for this
2680 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2690 cursor
= *wxSTANDARD_CURSOR
;
2694 cursor
.MacInstall() ;
2696 return cursor
.Ok() ;
2699 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2704 return m_tooltip
->GetTip() ;
2707 return wxEmptyString
;
2710 void wxWindowMac::ClearBackground()
2716 void wxWindowMac::Update()
2718 #if TARGET_API_MAC_OSX
2719 MacGetTopLevelWindow()->MacPerformUpdates() ;
2721 ::Draw1Control( m_peer
->GetControlRef() ) ;
2725 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2727 wxTopLevelWindowMac
* win
= NULL
;
2728 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2731 win
= wxFindWinFromMacWindow( window
) ;
2736 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2738 MacUpdateClippedRects() ;
2739 return m_cachedClippedClientRect
;
2742 const wxRect
& wxWindowMac::MacGetClippedRect() const
2744 MacUpdateClippedRects() ;
2745 return m_cachedClippedRect
;
2748 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2750 MacUpdateClippedRects() ;
2751 return m_cachedClippedRectWithOuterStructure
;
2754 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2756 static wxRegion emptyrgn
;
2757 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2759 MacUpdateClippedRects() ;
2760 if ( includeOuterStructures
)
2761 return m_cachedClippedRegionWithOuterStructure
;
2763 return m_cachedClippedRegion
;
2771 void wxWindowMac::MacUpdateClippedRects() const
2773 if ( m_cachedClippedRectValid
)
2776 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2777 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2778 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2779 // to add focus borders everywhere
2782 Rect rIncludingOuterStructures
;
2784 m_peer
->GetRect( &r
) ;
2785 r
.left
-= MacGetLeftBorderSize() ;
2786 r
.top
-= MacGetTopBorderSize() ;
2787 r
.bottom
+= MacGetBottomBorderSize() ;
2788 r
.right
+= MacGetRightBorderSize() ;
2795 rIncludingOuterStructures
= r
;
2796 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2798 wxRect cl
= GetClientRect() ;
2799 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2801 const wxWindow
* child
= this ;
2802 const wxWindow
* parent
= NULL
;
2803 while( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2808 if ( parent
->MacIsChildOfClientArea(child
) )
2810 size
= parent
->GetClientSize() ;
2811 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2817 // this will be true for scrollbars, toolbars etc.
2818 size
= parent
->GetSize() ;
2819 y
= parent
->MacGetTopBorderSize() ;
2820 x
= parent
->MacGetLeftBorderSize() ;
2821 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2822 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2825 parent
->MacWindowToRootWindow( &x
, &y
) ;
2826 MacRootWindowToWindow( &x
, &y
) ;
2828 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2830 // the wxwindow and client rects will always be clipped
2831 SectRect( &r
, &rparent
, &r
) ;
2832 SectRect( &rClient
, &rparent
, &rClient
) ;
2834 // the structure only at 'hard' borders
2835 if ( parent
->MacClipChildren() ||
2836 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2838 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2843 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2844 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2845 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2846 m_cachedClippedRectWithOuterStructure
= wxRect(
2847 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2848 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2849 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2851 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2852 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2853 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2855 m_cachedClippedRectValid
= true ;
2859 This function must not change the updatergn !
2861 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2863 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2864 bool handled
= false ;
2866 GetRegionBounds( updatergn
, &updatebounds
) ;
2868 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2870 if ( !EmptyRgn(updatergn
) )
2872 RgnHandle newupdate
= NewRgn() ;
2873 wxSize point
= GetClientSize() ;
2874 wxPoint origin
= GetClientAreaOrigin() ;
2875 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2876 SectRgn( newupdate
, updatergn
, newupdate
) ;
2878 // first send an erase event to the entire update area
2880 // for the toplevel window this really is the entire area
2881 // for all the others only their client area, otherwise they
2882 // might be drawing with full alpha and eg put blue into
2883 // the grow-box area of a scrolled window (scroll sample)
2884 wxDC
* dc
= new wxWindowDC(this);
2886 dc
->SetClippingRegion(wxRegion(updatergn
));
2888 dc
->SetClippingRegion(wxRegion(newupdate
));
2890 wxEraseEvent
eevent( GetId(), dc
);
2891 eevent
.SetEventObject( this );
2892 GetEventHandler()->ProcessEvent( eevent
);
2896 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2897 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2898 m_updateRegion
= newupdate
;
2899 DisposeRgn( newupdate
) ;
2901 if ( !m_updateRegion
.Empty() )
2903 // paint the window itself
2906 event
.SetTimestamp(time
);
2907 event
.SetEventObject(this);
2908 GetEventHandler()->ProcessEvent(event
);
2912 // now we cannot rely on having its borders drawn by a window itself, as it does not
2913 // get the updateRgn wide enough to always do so, so we do it from the parent
2914 // this would also be the place to draw any custom backgrounds for native controls
2915 // in Composited windowing
2916 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2918 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2920 wxWindowMac
*child
= node
->GetData();
2921 if (child
== m_vScrollBar
) continue;
2922 if (child
== m_hScrollBar
) continue;
2923 if (child
->IsTopLevel()) continue;
2924 if (!child
->IsShown()) continue;
2926 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2929 child
->GetPosition( &x
, &y
);
2931 child
->GetSize( &w
, &h
);
2932 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2933 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2934 InsetRect( &childRect
, -10 , -10) ;
2936 if ( RectInRgn( &childRect
, updatergn
) )
2939 // paint custom borders
2940 wxNcPaintEvent
eventNc( child
->GetId() );
2941 eventNc
.SetEventObject( child
);
2942 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2944 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2945 if ( UMAGetSystemVersion() >= 0x1030 )
2947 child
->MacPaintBorders(0,0) ;
2952 wxWindowDC
dc(this) ;
2953 dc
.SetClippingRegion(wxRegion(updatergn
));
2954 wxMacPortSetter
helper(&dc
) ;
2955 child
->MacPaintBorders(0,0) ;
2965 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2967 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2971 if ( iter
->IsTopLevel() )
2972 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2974 iter
= iter
->GetParent() ;
2976 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2980 void wxWindowMac::MacCreateScrollBars( long style
)
2982 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2984 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2986 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2987 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2988 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2989 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2991 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2992 variant
= wxWINDOW_VARIANT_SMALL
;
2995 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2997 GetClientSize( &width
, &height
) ;
2999 wxPoint
vPoint(width
-scrlsize
, 0) ;
3000 wxSize
vSize(scrlsize
, height
- adjust
) ;
3001 wxPoint
hPoint(0 , height
-scrlsize
) ;
3002 wxSize
hSize( width
- adjust
, scrlsize
) ;
3005 if ( style
& wxVSCROLL
)
3007 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
3008 vSize
, wxVERTICAL
);
3011 if ( style
& wxHSCROLL
)
3013 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
3014 hSize
, wxHORIZONTAL
);
3019 // because the create does not take into account the client area origin
3020 MacRepositionScrollBars() ; // we might have a real position shift
3023 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3025 if ( child
!= NULL
&& ( child
== m_hScrollBar
|| child
== m_vScrollBar
) )
3031 void wxWindowMac::MacRepositionScrollBars()
3033 if ( !m_hScrollBar
&& !m_vScrollBar
)
3036 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3037 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3038 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3040 // get real client area
3044 GetSize( &width
, &height
) ;
3046 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3047 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3049 wxPoint
vPoint(width
-scrlsize
, 0) ;
3050 wxSize
vSize(scrlsize
, height
- adjust
) ;
3051 wxPoint
hPoint(0 , height
-scrlsize
) ;
3052 wxSize
hSize( width
- adjust
, scrlsize
) ;
3058 GetSize( &w , &h ) ;
3060 MacClientToRootWindow( &x , &y ) ;
3061 MacClientToRootWindow( &w , &h ) ;
3063 wxWindowMac *iter = (wxWindowMac*)this ;
3065 int totW = 10000 , totH = 10000;
3068 if ( iter->IsTopLevel() )
3070 iter->GetSize( &totW , &totH ) ;
3074 iter = iter->GetParent() ;
3102 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3106 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3110 bool wxWindowMac::AcceptsFocus() const
3112 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3115 void wxWindowMac::MacSuperChangedPosition()
3117 m_cachedClippedRectValid
= false ;
3118 // only window-absolute structures have to be moved i.e. controls
3120 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3123 wxWindowMac
*child
= node
->GetData();
3124 child
->MacSuperChangedPosition() ;
3125 node
= node
->GetNext();
3129 void wxWindowMac::MacTopLevelWindowChangedPosition()
3131 // only screen-absolute structures have to be moved i.e. glcanvas
3133 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3136 wxWindowMac
*child
= node
->GetData();
3137 child
->MacTopLevelWindowChangedPosition() ;
3138 node
= node
->GetNext();
3142 long wxWindowMac::MacGetLeftBorderSize( ) const
3149 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
3151 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3152 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3154 else if (HasFlag(wxSIMPLE_BORDER
))
3156 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3157 border
+= 1 ; // the metric above is only the 'outset' outside the simple frame rect
3162 long wxWindowMac::MacGetRightBorderSize( ) const
3164 // they are all symmetric in mac themes
3165 return MacGetLeftBorderSize() ;
3168 long wxWindowMac::MacGetTopBorderSize( ) const
3170 // they are all symmetric in mac themes
3171 return MacGetLeftBorderSize() ;
3174 long wxWindowMac::MacGetBottomBorderSize( ) const
3176 // they are all symmetric in mac themes
3177 return MacGetLeftBorderSize() ;
3180 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3182 return style
& ~wxBORDER_MASK
;
3185 // Find the wxWindowMac at the current mouse position, returning the mouse
3187 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3189 pt
= wxGetMousePosition();
3190 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3194 // Get the current mouse position.
3195 wxPoint
wxGetMousePosition()
3198 wxGetMousePosition(& x
, & y
);
3199 return wxPoint(x
, y
);
3202 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3204 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3206 // copied from wxGTK : CS
3207 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3210 // (a) it's a command event and so is propagated to the parent
3211 // (b) under MSW it can be generated from kbd too
3212 // (c) it uses screen coords (because of (a))
3213 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3215 this->ClientToScreen(event
.GetPosition()));
3216 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3225 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3227 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3229 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3233 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3237 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3241 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3242 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3246 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3248 return eventNotHandledErr
;