1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
18 #include "wx/window.h"
20 #include "wx/dcclient.h"
24 #include "wx/layout.h"
25 #include "wx/dialog.h"
26 #include "wx/scrolbar.h"
27 #include "wx/statbox.h"
28 #include "wx/button.h"
29 #include "wx/settings.h"
30 #include "wx/msgdlg.h"
32 #include "wx/tooltip.h"
33 #include "wx/statusbr.h"
34 #include "wx/menuitem.h"
35 #include "wx/spinctrl.h"
37 #include "wx/geometry.h"
38 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
47 #define MAC_SCROLLBAR_SIZE 15
48 #define MAC_SMALL_SCROLLBAR_SIZE 11
50 #include "wx/mac/uma.h"
53 #include <ToolUtils.h>
55 #include <MacTextEditor.h>
58 #if TARGET_API_MAC_OSX
60 #include <HIToolbox/HIView.h>
64 #if wxUSE_DRAG_AND_DROP
70 extern wxList wxPendingDelete
;
72 #ifdef __WXUNIVERSAL__
73 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
75 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
76 #endif // __WXUNIVERSAL__/__WXMAC__
78 #if !USE_SHARED_LIBRARY
80 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
81 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
82 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
83 // TODO EVT_PAINT(wxWindowMac::OnPaint)
84 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
85 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 1
98 // ---------------------------------------------------------------------------
99 // Utility Routines to move between different coordinate systems
100 // ---------------------------------------------------------------------------
103 * Right now we have the following setup :
104 * a border that is not part of the native control is always outside the
105 * control's border (otherwise we loose all native intelligence, future ways
106 * may be to have a second embedding control responsible for drawing borders
107 * and backgrounds eventually)
108 * so all this border calculations have to be taken into account when calling
109 * native methods or getting native oriented data
110 * so we have three coordinate systems here
111 * wx client coordinates
112 * wx window coordinates (including window frames)
117 // originating from native control
121 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
123 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
126 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
128 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
132 // directed towards native control
135 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
137 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
140 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
142 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
146 // ---------------------------------------------------------------------------
148 // ---------------------------------------------------------------------------
150 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
151 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
153 #if TARGET_API_MAC_OSX
155 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
157 kEventControlVisibilityChanged
= 157
163 static const EventTypeSpec eventList
[] =
165 { kEventClassControl
, kEventControlHit
} ,
166 #if TARGET_API_MAC_OSX
167 { kEventClassControl
, kEventControlDraw
} ,
168 { kEventClassControl
, kEventControlVisibilityChanged
} ,
169 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
170 { kEventClassControl
, kEventControlHiliteChanged
} ,
171 { kEventClassControl
, kEventControlSetFocusPart
} ,
173 { kEventClassService
, kEventServiceGetTypes
},
174 { kEventClassService
, kEventServiceCopy
},
175 { kEventClassService
, kEventServicePaste
},
177 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
178 // { kEventClassControl , kEventControlBoundsChanged } ,
182 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
184 OSStatus result
= eventNotHandledErr
;
186 wxMacCarbonEvent
cEvent( event
) ;
188 ControlRef controlRef
;
189 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
191 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
193 switch( GetEventKind( event
) )
195 #if TARGET_API_MAC_OSX
196 case kEventControlDraw
:
198 RgnHandle updateRgn
= NULL
;
199 RgnHandle allocatedRgn
= NULL
;
200 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
201 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
203 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
207 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
209 allocatedRgn
= NewRgn() ;
210 CopyRgn( updateRgn
, allocatedRgn
) ;
211 // hide the given region by the new region that must be shifted
212 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
213 updateRgn
= allocatedRgn
;
218 // in case we would need a coregraphics compliant background erase first
219 // now usable to track redraws
220 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
221 if ( thisWindow
->MacIsUserPane() )
223 static float color
= 0.5 ;
226 HIViewGetBounds( controlRef
, &bounds
);
227 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
228 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
229 CGContextFillRect( cgContext
, bounds
);
240 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
243 DisposeRgn( allocatedRgn
) ;
246 case kEventControlVisibilityChanged
:
247 thisWindow
->MacVisibilityChanged() ;
249 case kEventControlEnabledStateChanged
:
250 thisWindow
->MacEnabledStateChanged() ;
252 case kEventControlHiliteChanged
:
253 thisWindow
->MacHiliteChanged() ;
255 case kEventControlSetFocusPart
:
257 Boolean focusEverything
= false ;
258 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
259 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
262 if ( controlPart
== kControlFocusNoPart
)
265 if ( thisWindow
->GetCaret() )
267 thisWindow
->GetCaret()->OnKillFocus();
269 #endif // wxUSE_CARET
270 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
271 event
.SetEventObject(thisWindow
);
272 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
276 // panel wants to track the window which was the last to have focus in it
277 wxChildFocusEvent
eventFocus(thisWindow
);
278 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
281 if ( thisWindow
->GetCaret() )
283 thisWindow
->GetCaret()->OnSetFocus();
285 #endif // wxUSE_CARET
287 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
288 event
.SetEventObject(thisWindow
);
289 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
291 if ( thisWindow
->MacIsUserPane() )
296 case kEventControlHit
:
298 result
= thisWindow
->MacControlHit( handler
, event
) ;
307 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
309 OSStatus result
= eventNotHandledErr
;
311 wxMacCarbonEvent
cEvent( event
) ;
313 ControlRef controlRef
;
314 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
315 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
316 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
318 switch( GetEventKind( event
) )
320 case kEventServiceGetTypes
:
324 textCtrl
->GetSelection( &from
, &to
) ;
326 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
328 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
329 if ( textCtrl
->IsEditable() )
330 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
332 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
333 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
335 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
339 CFArrayAppendValue (copyTypes
, typestring
) ;
341 CFArrayAppendValue (pasteTypes
, typestring
) ;
342 CFRelease( typestring
) ;
348 case kEventServiceCopy
:
352 textCtrl
->GetSelection( &from
, &to
) ;
353 wxString val
= textCtrl
->GetValue() ;
354 val
= val
.Mid( from
, to
- from
) ;
355 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
356 verify_noerr( ClearScrap( &scrapRef
) ) ;
357 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.Length() , val
.c_str() ) ) ;
361 case kEventServicePaste
:
364 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
365 Size textSize
, pastedSize
;
366 verify_noerr( GetScrapFlavorSize (scrapRef
, kTXNTextData
, &textSize
) ) ;
368 char *content
= new char[textSize
] ;
369 GetScrapFlavorData (scrapRef
, kTXNTextData
, &pastedSize
, content
);
370 content
[textSize
-1] = 0 ;
372 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
374 textCtrl
->WriteText( wxString( content
) ) ;
385 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
387 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
388 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
389 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
390 OSStatus result
= eventNotHandledErr
;
392 switch ( GetEventClass( event
) )
394 case kEventClassControl
:
395 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
397 case kEventClassService
:
398 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
402 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
406 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
408 // ---------------------------------------------------------------------------
409 // UserPane events for non OSX builds
410 // ---------------------------------------------------------------------------
412 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
414 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
415 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
416 win
->MacControlUserPaneDrawProc(part
) ;
419 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
421 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
422 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
423 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
426 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
428 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
429 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
430 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
433 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
435 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
436 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
437 win
->MacControlUserPaneIdleProc() ;
440 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
442 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
443 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
444 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
447 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
449 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
450 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
451 win
->MacControlUserPaneActivateProc(activating
) ;
454 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
456 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
457 wxCHECK_MSG( win
, kControlNoPart
, wxT("Callback from unkown control") ) ;
458 return win
->MacControlUserPaneFocusProc(action
) ;
461 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
463 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
464 wxCHECK_RET( win
, wxT("Callback from unkown control") ) ;
465 win
->MacControlUserPaneBackgroundProc(info
) ;
468 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
470 RgnHandle rgn
= NewRgn() ;
472 wxMacWindowStateSaver
sv( this ) ;
473 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
474 MacDoRedraw( rgn
, 0 ) ;
478 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
480 return kControlNoPart
;
483 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
485 return kControlNoPart
;
488 void wxWindowMac::MacControlUserPaneIdleProc()
492 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
494 return kControlNoPart
;
497 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
501 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
503 return kControlNoPart
;
506 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
510 ControlUserPaneDrawUPP gControlUserPaneDrawUPP
= NULL
;
511 ControlUserPaneHitTestUPP gControlUserPaneHitTestUPP
= NULL
;
512 ControlUserPaneTrackingUPP gControlUserPaneTrackingUPP
= NULL
;
513 ControlUserPaneIdleUPP gControlUserPaneIdleUPP
= NULL
;
514 ControlUserPaneKeyDownUPP gControlUserPaneKeyDownUPP
= NULL
;
515 ControlUserPaneActivateUPP gControlUserPaneActivateUPP
= NULL
;
516 ControlUserPaneFocusUPP gControlUserPaneFocusUPP
= NULL
;
517 ControlUserPaneBackgroundUPP gControlUserPaneBackgroundUPP
= NULL
;
519 // ===========================================================================
521 // ===========================================================================
523 #if KEY_wxList_DEPRECATED
524 wxList
wxWinMacControlList(wxKEY_INTEGER
);
526 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
528 wxNode
*node
= wxWinMacControlList
.Find((long)inControl
);
531 return (wxControl
*)node
->GetData();
534 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
536 // adding NULL ControlRef is (first) surely a result of an error and
537 // (secondly) breaks native event processing
538 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
540 if ( !wxWinMacControlList
.Find((long)inControl
) )
541 wxWinMacControlList
.Append((long)inControl
, control
);
544 void wxRemoveMacControlAssociation(wxWindow
*control
)
546 wxWinMacControlList
.DeleteObject(control
);
550 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
552 static MacControlMap wxWinMacControlList
;
554 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
556 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
558 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
561 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
563 // adding NULL ControlRef is (first) surely a result of an error and
564 // (secondly) breaks native event processing
565 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
567 wxWinMacControlList
[inControl
] = control
;
570 void wxRemoveMacControlAssociation(wxWindow
*control
)
572 // iterate over all the elements in the class
573 MacControlMap::iterator it
;
574 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
576 if ( it
->second
== control
)
578 wxWinMacControlList
.erase(it
);
583 #endif // deprecated wxList
586 ControlActionUPP wxMacLiveScrollbarActionUPP
= NULL
;
588 ControlColorUPP wxMacSetupControlBackgroundUPP
= NULL
;
590 // we have to setup the brush in the current port and return noErr
591 // or return an error code so that the control manager walks further up the
592 // hierarchy to find a correct background
594 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
)
596 OSStatus status
= paramErr
;
599 case kControlMsgApplyTextColor
:
601 case kControlMsgSetUpBackground
:
603 wxWindow
* wx
= (wxWindow
*) wxFindControlFromMacControl( iControl
) ;
607 const wxBrush &brush = wx->MacGetBackgroundBrush() ;
610 wxDC::MacSetupBackgroundForCurrentPort( brush ) ;
612 // this clipping is only needed for non HIView
614 RgnHandle clip
= NewRgn() ;
617 wx
->MacWindowToRootWindow( &x
,&y
) ;
618 CopyRgn( (RgnHandle
) wx
->MacGetVisibleRegion().GetWXHRGN() , clip
) ;
619 OffsetRgn( clip
, x
, y
) ;
626 else if ( wx->MacIsUserPane() )
628 // if we don't have a valid brush for such a control, we have to call the
629 // setup of our parent ourselves
630 status = SetUpControlBackground( (ControlRef) wx->GetParent()->GetHandle() , iDepth , iIsColor ) ;
643 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
644 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
648 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
651 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
656 // ----------------------------------------------------------------------------
657 // constructors and such
658 // ----------------------------------------------------------------------------
660 wxWindowMac::wxWindowMac()
665 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
670 const wxString
& name
)
673 Create(parent
, id
, pos
, size
, style
, name
);
676 void wxWindowMac::Init()
680 #if WXWIN_COMPATIBILITY_2_4
681 m_backgroundTransparent
= FALSE
;
684 // as all windows are created with WS_VISIBLE style...
687 m_hScrollBar
= NULL
;
688 m_vScrollBar
= NULL
;
689 m_macBackgroundBrush
= wxNullBrush
;
691 m_macIsUserPane
= TRUE
;
693 // make sure all proc ptrs are available
695 if ( gControlUserPaneDrawUPP
== NULL
)
697 gControlUserPaneDrawUPP
= NewControlUserPaneDrawUPP( wxMacControlUserPaneDrawProc
) ;
698 gControlUserPaneHitTestUPP
= NewControlUserPaneHitTestUPP( wxMacControlUserPaneHitTestProc
) ;
699 gControlUserPaneTrackingUPP
= NewControlUserPaneTrackingUPP( wxMacControlUserPaneTrackingProc
) ;
700 gControlUserPaneIdleUPP
= NewControlUserPaneIdleUPP( wxMacControlUserPaneIdleProc
) ;
701 gControlUserPaneKeyDownUPP
= NewControlUserPaneKeyDownUPP( wxMacControlUserPaneKeyDownProc
) ;
702 gControlUserPaneActivateUPP
= NewControlUserPaneActivateUPP( wxMacControlUserPaneActivateProc
) ;
703 gControlUserPaneFocusUPP
= NewControlUserPaneFocusUPP( wxMacControlUserPaneFocusProc
) ;
704 gControlUserPaneBackgroundUPP
= NewControlUserPaneBackgroundUPP( wxMacControlUserPaneBackgroundProc
) ;
706 if ( wxMacLiveScrollbarActionUPP
== NULL
)
708 wxMacLiveScrollbarActionUPP
= NewControlActionUPP( wxMacLiveScrollbarActionProc
);
711 if ( wxMacSetupControlBackgroundUPP
== NULL
)
713 wxMacSetupControlBackgroundUPP
= NewControlColorUPP( wxMacSetupControlBackground
) ;
716 // we need a valid font for the encodings
717 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
721 wxWindowMac::~wxWindowMac()
725 m_isBeingDeleted
= TRUE
;
729 // deleting a window while it is shown invalidates the region occupied by border or
731 int outerBorder
= MacGetLeftBorderSize() ;
732 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
735 if ( IsShown() && ( outerBorder
> 0 ) )
737 // as the borders are drawn on the parent we have to properly invalidate all these areas
738 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
742 m_peer
->GetRect( &rect
) ;
743 RectRgn( updateInner
, &rect
) ;
744 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
745 RectRgn( updateOuter
, &rect
) ;
746 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
748 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
749 parent
-= GetParent()->GetClientAreaOrigin() ;
750 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
751 CopyRgn( updateOuter
, updateTotal
) ;
753 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
754 DisposeRgn(updateOuter
) ;
755 DisposeRgn(updateInner
) ;
756 DisposeRgn(updateTotal
) ;
760 #ifndef __WXUNIVERSAL__
761 // VS: make sure there's no wxFrame with last focus set to us:
762 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
764 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
767 if ( frame
->GetLastFocus() == this )
769 frame
->SetLastFocus((wxWindow
*)NULL
);
774 #endif // __WXUNIVERSAL__
776 // destroy children before destroying this window itself
779 // wxRemoveMacControlAssociation( this ) ;
780 // If we delete an item, we should initialize the parent panel,
781 // because it could now be invalid.
782 wxWindow
*parent
= GetParent() ;
785 if (parent
->GetDefaultItem() == (wxButton
*) this)
786 parent
->SetDefaultItem(NULL
);
788 if ( m_peer
&& m_peer
->Ok() )
790 // in case the callback might be called during destruction
791 wxRemoveMacControlAssociation( this) ;
792 // we currently are not using this hook
793 // ::SetControlColorProc( *m_peer , NULL ) ;
797 if ( g_MacLastWindow
== this )
799 g_MacLastWindow
= NULL
;
802 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
805 if ( frame
->GetLastFocus() == this )
806 frame
->SetLastFocus( NULL
) ;
809 // delete our drop target if we've got one
810 #if wxUSE_DRAG_AND_DROP
811 if ( m_dropTarget
!= NULL
)
816 #endif // wxUSE_DRAG_AND_DROP
820 WXWidget
wxWindowMac::GetHandle() const
822 return (WXWidget
) m_peer
->GetControlRef() ;
826 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
828 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
829 InstallControlEventHandler( (ControlRef
) control
, GetwxMacWindowEventHandlerUPP(),
830 GetEventTypeCount(eventList
), eventList
, this,
831 (EventHandlerRef
*)&m_macControlEventHandler
);
836 bool wxWindowMac::Create(wxWindowMac
*parent
, wxWindowID id
,
840 const wxString
& name
)
842 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindowMac without parent") );
844 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
847 m_windowVariant
= parent
->GetWindowVariant() ;
849 if ( m_macIsUserPane
)
851 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
854 | kControlSupportsEmbedding
855 // | kControlSupportsLiveFeedback
856 // | kControlHasSpecialBackground
857 // | kControlSupportsCalcBestRect
858 // | kControlHandlesTracking
859 | kControlSupportsFocus
860 // | kControlWantsActivate
861 // | kControlWantsIdle
864 m_peer
= new wxMacControl() ;
865 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
868 MacPostControlCreate(pos
,size
) ;
869 #if !TARGET_API_MAC_OSX
870 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
,kControlUserPaneDrawProcTag
,&gControlUserPaneDrawUPP
) ;
871 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
,kControlUserPaneHitTestProcTag
,&gControlUserPaneHitTestUPP
) ;
872 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
,kControlUserPaneTrackingProcTag
,&gControlUserPaneTrackingUPP
) ;
873 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
,kControlUserPaneIdleProcTag
,&gControlUserPaneIdleUPP
) ;
874 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
,kControlUserPaneKeyDownProcTag
,&gControlUserPaneKeyDownUPP
) ;
875 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
,kControlUserPaneActivateProcTag
,&gControlUserPaneActivateUPP
) ;
876 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
,kControlUserPaneFocusProcTag
,&gControlUserPaneFocusUPP
) ;
877 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
,kControlUserPaneBackgroundProcTag
,&gControlUserPaneBackgroundUPP
) ;
880 #ifndef __WXUNIVERSAL__
881 // Don't give scrollbars to wxControls unless they ask for them
882 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
))) ||
883 (IsKindOf(CLASSINFO(wxControl
)) && ( style
& wxHSCROLL
|| style
& wxVSCROLL
)))
885 MacCreateScrollBars( style
) ;
889 wxWindowCreateEvent
event(this);
890 GetEventHandler()->AddPendingEvent(event
);
895 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
897 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
899 m_peer
->SetReference( (long) this ) ;
900 GetParent()->AddChild(this);
902 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
904 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
905 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
906 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
908 // adjust font, controlsize etc
909 DoSetWindowVariant( m_windowVariant
) ;
911 #if !TARGET_API_MAC_OSX
912 // eventually we can fix some clipping issues be reactivating this hook
913 //if ( m_macIsUserPane )
914 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
916 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
918 if (!m_macIsUserPane
)
920 SetInitialBestSize(size
);
923 SetCursor( *wxSTANDARD_CURSOR
) ;
926 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
928 // Don't assert, in case we set the window variant before
929 // the window is created
930 // wxASSERT( m_peer->Ok() ) ;
932 m_windowVariant
= variant
;
934 if (m_peer
== NULL
|| !m_peer
->Ok())
938 ThemeFontID themeFont
= kThemeSystemFont
;
940 // we will get that from the settings later
941 // and make this NORMAL later, but first
942 // we have a few calculations that we must fix
946 case wxWINDOW_VARIANT_NORMAL
:
947 size
= kControlSizeNormal
;
948 themeFont
= kThemeSystemFont
;
950 case wxWINDOW_VARIANT_SMALL
:
951 size
= kControlSizeSmall
;
952 themeFont
= kThemeSmallSystemFont
;
954 case wxWINDOW_VARIANT_MINI
:
955 if (UMAGetSystemVersion() >= 0x1030 )
957 // not always defined in the headers
963 size
= kControlSizeSmall
;
964 themeFont
= kThemeSmallSystemFont
;
967 case wxWINDOW_VARIANT_LARGE
:
968 size
= kControlSizeLarge
;
969 themeFont
= kThemeSystemFont
;
972 wxFAIL_MSG(_T("unexpected window variant"));
975 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
978 font
.MacCreateThemeFont( themeFont
) ;
982 void wxWindowMac::MacUpdateControlFont()
984 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
988 bool wxWindowMac::SetFont(const wxFont
& font
)
990 bool retval
= wxWindowBase::SetFont( font
) ;
992 MacUpdateControlFont() ;
997 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
999 if ( !wxWindowBase::SetForegroundColour(col
) )
1002 MacUpdateControlFont() ;
1007 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1009 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1013 wxColour
newCol(GetBackgroundColour());
1014 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1016 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1018 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1020 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1024 brush
.SetColour( newCol
) ;
1026 MacSetBackgroundBrush( brush
) ;
1028 MacUpdateControlFont() ;
1033 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1035 m_macBackgroundBrush
= brush
;
1036 m_peer
->SetBackground( brush
) ;
1039 bool wxWindowMac::MacCanFocus() const
1041 // there is currently no way to determine whether the window is running in full keyboard
1042 // access mode, therefore we cannot rely on these features, yet the only other way would be
1043 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1044 // in event handlers...
1045 UInt32 features
= 0 ;
1046 m_peer
->GetFeatures( & features
) ;
1047 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1051 void wxWindowMac::SetFocus()
1053 if ( AcceptsFocus() )
1056 wxWindow
* former
= FindFocus() ;
1057 if ( former
== this )
1060 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1061 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1062 // leave in case of an error
1063 if ( err
== errCouldntSetFocus
)
1066 #if !TARGET_API_MAC_OSX
1067 // emulate carbon events when running under carbonlib where they are not natively available
1070 EventRef evRef
= NULL
;
1071 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1074 wxMacCarbonEvent
cEvent( evRef
) ;
1075 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1076 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1078 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1079 ReleaseEvent(evRef
) ;
1081 // send new focus event
1083 EventRef evRef
= NULL
;
1084 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1087 wxMacCarbonEvent
cEvent( evRef
) ;
1088 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1089 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1091 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1092 ReleaseEvent(evRef
) ;
1099 void wxWindowMac::DoCaptureMouse()
1101 wxTheApp
->s_captureWindow
= this ;
1104 wxWindow
* wxWindowBase::GetCapture()
1106 return wxTheApp
->s_captureWindow
;
1109 void wxWindowMac::DoReleaseMouse()
1111 wxTheApp
->s_captureWindow
= NULL
;
1114 #if wxUSE_DRAG_AND_DROP
1116 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1118 if ( m_dropTarget
!= 0 ) {
1119 delete m_dropTarget
;
1122 m_dropTarget
= pDropTarget
;
1123 if ( m_dropTarget
!= 0 )
1131 // Old style file-manager drag&drop
1132 void wxWindowMac::DragAcceptFiles(bool accept
)
1137 // Returns the size of the native control. In the case of the toplevel window
1138 // this is the content area root control
1140 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1141 int& w
, int& h
) const
1144 m_peer
->GetRect( &bounds
) ;
1149 w
= bounds
.right
- bounds
.left
;
1150 h
= bounds
.bottom
- bounds
.top
;
1153 // From a wx position / size calculate the appropriate size of the native control
1155 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1158 int& w
, int& h
, bool adjustOrigin
) const
1160 // the desired size, minus the border pixels gives the correct size of the control
1164 // todo the default calls may be used as soon as PostCreateControl Is moved here
1165 w
= size
.x
; // WidthDefault( size.x );
1166 h
= size
.y
; // HeightDefault( size.y ) ;
1167 #if !TARGET_API_MAC_OSX
1168 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1171 x
+= MacGetLeftBorderSize() ;
1172 y
+= MacGetTopBorderSize() ;
1173 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1174 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1177 AdjustForParentClientOrigin( x
, y
) ;
1178 #if TARGET_API_MAC_OSX
1179 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1180 if ( ! GetParent()->IsTopLevel() )
1182 x
-= GetParent()->MacGetLeftBorderSize() ;
1183 y
-= GetParent()->MacGetTopBorderSize() ;
1189 // Get window size (not client size)
1190 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1192 // take the size of the control and add the borders that have to be drawn outside
1193 int x1
, y1
, w1
, h1
;
1195 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1197 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1198 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1204 // get the position of the bounds of this window in client coordinates of its parent
1205 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1207 int x1
, y1
, w1
,h1
;
1208 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1209 x1
-= MacGetLeftBorderSize() ;
1210 y1
-= MacGetTopBorderSize() ;
1212 #if !TARGET_API_MAC_OSX
1213 if ( !GetParent()->IsTopLevel() )
1216 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1221 if ( !IsTopLevel() )
1223 wxWindow
*parent
= GetParent();
1226 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1227 x1
+= parent
->MacGetLeftBorderSize() ;
1228 y1
+= parent
->MacGetTopBorderSize() ;
1229 // and now to client coordinates
1230 wxPoint
pt(parent
->GetClientAreaOrigin());
1239 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1241 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1243 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1246 Point localwhere
= {0,0} ;
1248 if(x
) localwhere
.h
= * x
;
1249 if(y
) localwhere
.v
= * y
;
1251 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1252 if(x
) *x
= localwhere
.h
;
1253 if(y
) *y
= localwhere
.v
;
1256 MacRootWindowToWindow( x
, y
) ;
1258 wxPoint origin
= GetClientAreaOrigin() ;
1259 if(x
) *x
-= origin
.x
;
1260 if(y
) *y
-= origin
.y
;
1263 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1265 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1266 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1268 wxPoint origin
= GetClientAreaOrigin() ;
1269 if(x
) *x
+= origin
.x
;
1270 if(y
) *y
+= origin
.y
;
1272 MacWindowToRootWindow( x
, y
) ;
1275 Point localwhere
= { 0,0 };
1276 if(x
) localwhere
.h
= * x
;
1277 if(y
) localwhere
.v
= * y
;
1278 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1279 if(x
) *x
= localwhere
.h
;
1280 if(y
) *y
= localwhere
.v
;
1284 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1286 wxPoint origin
= GetClientAreaOrigin() ;
1287 if(x
) *x
+= origin
.x
;
1288 if(y
) *y
+= origin
.y
;
1290 MacWindowToRootWindow( x
, y
) ;
1293 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1295 MacRootWindowToWindow( x
, y
) ;
1297 wxPoint origin
= GetClientAreaOrigin() ;
1298 if(x
) *x
-= origin
.x
;
1299 if(y
) *y
-= origin
.y
;
1302 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1304 #if TARGET_API_MAC_OSX
1306 if ( x
) pt
.x
= *x
;
1307 if ( y
) pt
.y
= *y
;
1309 if ( !IsTopLevel() )
1311 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1314 pt
.x
-= MacGetLeftBorderSize() ;
1315 pt
.y
-= MacGetTopBorderSize() ;
1316 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1320 if ( x
) *x
= (int) pt
.x
;
1321 if ( y
) *y
= (int) pt
.y
;
1323 if ( !IsTopLevel() )
1326 m_peer
->GetRect( &bounds
) ;
1327 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1328 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1333 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1338 MacWindowToRootWindow( &x1
, &y1
) ;
1343 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1345 #if TARGET_API_MAC_OSX
1347 if ( x
) pt
.x
= *x
;
1348 if ( y
) pt
.y
= *y
;
1350 if ( !IsTopLevel() )
1352 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1353 pt
.x
+= MacGetLeftBorderSize() ;
1354 pt
.y
+= MacGetTopBorderSize() ;
1357 if ( x
) *x
= (int) pt
.x
;
1358 if ( y
) *y
= (int) pt
.y
;
1360 if ( !IsTopLevel() )
1363 m_peer
->GetRect( &bounds
) ;
1364 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1365 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1370 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1375 MacRootWindowToWindow( &x1
, &y1
) ;
1380 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1382 RgnHandle rgn
= NewRgn() ;
1384 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1386 GetRegionBounds( rgn
, &content
) ;
1391 m_peer
->GetRect( &content
) ;
1394 m_peer
->GetRect( &structure
) ;
1395 #if !TARGET_API_MAC_OSX
1396 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1398 left
= content
.left
- structure
.left
;
1399 top
= content
.top
- structure
.top
;
1400 right
= structure
.right
- content
.right
;
1401 bottom
= structure
.bottom
- content
.bottom
;
1404 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1406 wxSize sizeTotal
= size
;
1408 RgnHandle rgn
= NewRgn() ;
1412 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1414 GetRegionBounds( rgn
, &content
) ;
1419 m_peer
->GetRect( &content
) ;
1422 m_peer
->GetRect( &structure
) ;
1423 #if !TARGET_API_MAC_OSX
1424 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1427 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1428 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1430 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1431 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1437 // Get size *available for subwindows* i.e. excluding menu bar etc.
1438 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1442 RgnHandle rgn
= NewRgn() ;
1444 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1446 GetRegionBounds( rgn
, &content
) ;
1451 m_peer
->GetRect( &content
) ;
1453 #if !TARGET_API_MAC_OSX
1455 m_peer
->GetRect( &structure
) ;
1456 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1458 ww
= content
.right
- content
.left
;
1459 hh
= content
.bottom
- content
.top
;
1461 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1462 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1465 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1471 GetSize( &w , &h ) ;
1473 MacClientToRootWindow( &x1 , &y1 ) ;
1474 MacClientToRootWindow( &w , &h ) ;
1476 wxWindowMac *iter = (wxWindowMac*)this ;
1478 int totW = 10000 , totH = 10000;
1481 if ( iter->IsTopLevel() )
1483 iter->GetSize( &totW , &totH ) ;
1487 iter = iter->GetParent() ;
1490 if (m_hScrollBar && m_hScrollBar->IsShown() )
1492 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1498 if (m_vScrollBar && m_vScrollBar->IsShown() )
1500 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1508 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1510 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1512 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1514 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1521 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1523 if (m_cursor
== cursor
)
1526 if (wxNullCursor
== cursor
)
1528 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1533 if ( ! wxWindowBase::SetCursor( cursor
) )
1537 wxASSERT_MSG( m_cursor
.Ok(),
1538 wxT("cursor must be valid after call to the base version"));
1541 wxWindowMac
*mouseWin
= 0 ;
1543 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1545 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1547 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1548 // position, use it...
1552 ControlPartCode part
;
1553 ControlRef control
;
1554 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1556 mouseWin
= wxFindControlFromMacControl( control
) ;
1559 QDSwapPort( savePort
, NULL
) ;
1562 if ( mouseWin
== this && !wxIsBusy() )
1564 m_cursor
.MacInstall() ;
1571 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1573 menu
->SetInvokingWindow(this);
1576 if ( x
== -1 && y
== -1 )
1578 wxPoint mouse
= wxGetMousePosition();
1579 x
= mouse
.x
; y
= mouse
.y
;
1583 ClientToScreen( &x
, &y
) ;
1586 menu
->MacBeforeDisplay( true ) ;
1587 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1588 if ( HiWord(menuResult
) != 0 )
1591 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1592 wxMenuItem
* item
= NULL
;
1594 item
= menu
->FindItem(id
, &realmenu
) ;
1595 if (item
->IsCheckable())
1597 item
->Check( !item
->IsChecked() ) ;
1599 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1601 menu
->MacAfterDisplay( true ) ;
1603 menu
->SetInvokingWindow(NULL
);
1609 // ----------------------------------------------------------------------------
1611 // ----------------------------------------------------------------------------
1615 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1617 wxWindowBase::DoSetToolTip(tooltip
);
1620 m_tooltip
->SetWindow(this);
1623 #endif // wxUSE_TOOLTIPS
1625 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1627 // this is never called for a toplevel window, so we know we have a parent
1628 int former_x
, former_y
, former_w
, former_h
;
1630 // Get true coordinates of former position
1631 DoGetPosition( &former_x
, &former_y
) ;
1632 DoGetSize( &former_w
, &former_h
) ;
1634 wxWindow
*parent
= GetParent();
1637 wxPoint
pt(parent
->GetClientAreaOrigin());
1642 int actualWidth
= width
;
1643 int actualHeight
= height
;
1647 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1648 actualWidth
= m_minWidth
;
1649 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1650 actualHeight
= m_minHeight
;
1651 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1652 actualWidth
= m_maxWidth
;
1653 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1654 actualHeight
= m_maxHeight
;
1656 bool doMove
= false ;
1657 bool doResize
= false ;
1659 if ( actualX
!= former_x
|| actualY
!= former_y
)
1663 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1668 if ( doMove
|| doResize
)
1670 // we don't adjust twice for the origin
1671 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1672 bool vis
= m_peer
->IsVisible();
1674 int outerBorder
= MacGetLeftBorderSize() ;
1675 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1678 if ( vis
&& ( outerBorder
> 0 ) )
1680 // as the borders are drawn on the parent we have to properly invalidate all these areas
1681 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1685 m_peer
->GetRect( &rect
) ;
1686 RectRgn( updateInner
, &rect
) ;
1687 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1688 RectRgn( updateOuter
, &rect
) ;
1689 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1690 wxPoint
parent(0,0);
1691 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1692 parent
-= GetParent()->GetClientAreaOrigin() ;
1693 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1694 CopyRgn( updateOuter
, updateTotal
) ;
1697 RectRgn( updateInner
, &rect
) ;
1698 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1699 RectRgn( updateOuter
, &rect
) ;
1700 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1702 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1703 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1705 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1706 DisposeRgn(updateOuter
) ;
1707 DisposeRgn(updateInner
) ;
1708 DisposeRgn(updateTotal
) ;
1711 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1713 m_peer
->SetVisibility( false , true ) ;
1715 m_peer
->SetRect( &r
) ;
1717 m_peer
->SetVisibility( true , true ) ;
1719 MacRepositionScrollBars() ;
1722 wxPoint
point(actualX
,actualY
);
1723 wxMoveEvent
event(point
, m_windowId
);
1724 event
.SetEventObject(this);
1725 GetEventHandler()->ProcessEvent(event
) ;
1729 MacRepositionScrollBars() ;
1730 wxSize
size(actualWidth
, actualHeight
);
1731 wxSizeEvent
event(size
, m_windowId
);
1732 event
.SetEventObject(this);
1733 GetEventHandler()->ProcessEvent(event
);
1739 wxSize
wxWindowMac::DoGetBestSize() const
1741 if ( m_macIsUserPane
|| IsTopLevel() )
1742 return wxWindowBase::DoGetBestSize() ;
1744 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1745 int bestWidth
, bestHeight
;
1746 m_peer
->GetBestRect( &bestsize
) ;
1748 if ( EmptyRect( &bestsize
) )
1750 bestsize
.left
= bestsize
.top
= 0 ;
1751 bestsize
.right
= 16 ;
1752 bestsize
.bottom
= 16 ;
1753 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1755 bestsize
.bottom
= 16 ;
1758 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1760 bestsize
.bottom
= 24 ;
1762 #endif // wxUSE_SPINBTN
1765 // return wxWindowBase::DoGetBestSize() ;
1769 bestWidth
= bestsize
.right
- bestsize
.left
;
1770 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1771 if ( bestHeight
< 10 )
1774 return wxSize(bestWidth
, bestHeight
);
1778 // set the size of the window: if the dimensions are positive, just use them,
1779 // but if any of them is equal to -1, it means that we must find the value for
1780 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1781 // which case -1 is a valid value for x and y)
1783 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1784 // the width/height to best suit our contents, otherwise we reuse the current
1786 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1788 // get the current size and position...
1789 int currentX
, currentY
;
1790 GetPosition(¤tX
, ¤tY
);
1792 int currentW
,currentH
;
1793 GetSize(¤tW
, ¤tH
);
1795 // ... and don't do anything (avoiding flicker) if it's already ok
1796 if ( x
== currentX
&& y
== currentY
&&
1797 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1800 MacRepositionScrollBars() ; // we might have a real position shift
1804 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1806 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1809 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1811 wxSize
size(-1, -1);
1814 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1816 size
= DoGetBestSize();
1821 // just take the current one
1828 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1832 size
= DoGetBestSize();
1834 //else: already called DoGetBestSize() above
1840 // just take the current one
1845 DoMoveWindow(x
, y
, width
, height
);
1849 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1851 RgnHandle rgn
= NewRgn() ;
1853 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1854 GetRegionBounds( rgn
, &content
) ;
1856 #if !TARGET_API_MAC_OSX
1857 // if the content rgn is empty / not supported
1858 // don't attempt to correct the coordinates to wxWindow relative ones
1859 if (!::EmptyRect( &content
) )
1862 m_peer
->GetRect( &structure
) ;
1863 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1867 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1870 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1872 if ( clientheight
!= -1 || clientheight
!= -1 )
1874 int currentclientwidth
, currentclientheight
;
1875 int currentwidth
, currentheight
;
1877 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1878 GetSize( ¤twidth
, ¤theight
) ;
1880 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1881 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1885 void wxWindowMac::SetTitle(const wxString
& title
)
1887 m_label
= wxStripMenuCodes(title
) ;
1889 if ( m_peer
&& m_peer
->Ok() )
1891 m_peer
->SetTitle( m_label
) ;
1896 wxString
wxWindowMac::GetTitle() const
1901 bool wxWindowMac::Show(bool show
)
1903 if ( !wxWindowBase::Show(show
) )
1906 // TODO use visibilityChanged Carbon Event for OSX
1909 bool former
= MacIsReallyShown() ;
1911 m_peer
->SetVisibility( show
, true ) ;
1912 if ( former
!= MacIsReallyShown() )
1913 MacPropagateVisibilityChanged() ;
1918 bool wxWindowMac::Enable(bool enable
)
1920 wxASSERT( m_peer
->Ok() ) ;
1921 if ( !wxWindowBase::Enable(enable
) )
1924 bool former
= MacIsReallyEnabled() ;
1925 m_peer
->Enable( enable
) ;
1927 if ( former
!= MacIsReallyEnabled() )
1928 MacPropagateEnabledStateChanged() ;
1933 // status change propagations (will be not necessary for OSX later )
1936 void wxWindowMac::MacPropagateVisibilityChanged()
1938 #if !TARGET_API_MAC_OSX
1939 MacVisibilityChanged() ;
1941 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1944 wxWindowMac
*child
= node
->GetData();
1945 if ( child
->IsShown() )
1946 child
->MacPropagateVisibilityChanged( ) ;
1947 node
= node
->GetNext();
1952 void wxWindowMac::MacPropagateEnabledStateChanged( )
1954 #if !TARGET_API_MAC_OSX
1955 MacEnabledStateChanged() ;
1957 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1960 wxWindowMac
*child
= node
->GetData();
1961 if ( child
->IsEnabled() )
1962 child
->MacPropagateEnabledStateChanged() ;
1963 node
= node
->GetNext();
1968 void wxWindowMac::MacPropagateHiliteChanged( )
1970 #if !TARGET_API_MAC_OSX
1971 MacHiliteChanged() ;
1973 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1976 wxWindowMac
*child
= node
->GetData();
1977 // if ( child->IsEnabled() )
1978 child
->MacPropagateHiliteChanged() ;
1979 node
= node
->GetNext();
1985 // status change notifications
1988 void wxWindowMac::MacVisibilityChanged()
1992 void wxWindowMac::MacHiliteChanged()
1996 void wxWindowMac::MacEnabledStateChanged()
2001 // status queries on the inherited window's state
2004 bool wxWindowMac::MacIsReallyShown()
2006 // only under OSX the visibility of the TLW is taken into account
2007 #if TARGET_API_MAC_OSX
2008 if ( m_peer
&& m_peer
->Ok() )
2009 return m_peer
->IsVisible();
2011 wxWindow
* win
= this ;
2012 while( win
->IsShown() )
2014 if ( win
->IsTopLevel() )
2017 win
= win
->GetParent() ;
2025 bool wxWindowMac::MacIsReallyEnabled()
2027 return m_peer
->IsEnabled() ;
2030 bool wxWindowMac::MacIsReallyHilited()
2032 return m_peer
->IsActive();
2035 void wxWindowMac::MacFlashInvalidAreas()
2037 #if TARGET_API_MAC_OSX
2038 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2046 int wxWindowMac::GetCharHeight() const
2048 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2049 return dc
.GetCharHeight() ;
2052 int wxWindowMac::GetCharWidth() const
2054 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2055 return dc
.GetCharWidth() ;
2058 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2059 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2061 const wxFont
*fontToUse
= theFont
;
2063 fontToUse
= &m_font
;
2065 wxClientDC
dc( (wxWindowMac
*) this ) ;
2067 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2068 if ( externalLeading
)
2069 *externalLeading
= le
;
2079 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2080 * we always intersect with the entire window, not only with the client area
2083 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2085 if ( m_peer
== NULL
)
2088 #if TARGET_API_MAC_OSX
2090 m_peer
->SetNeedsDisplay( true ) ;
2093 RgnHandle update
= NewRgn() ;
2094 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2095 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2096 wxPoint origin
= GetClientAreaOrigin() ;
2097 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2098 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2100 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2101 m_peer
->SetNeedsDisplay( true , update
) ;
2102 DisposeRgn( update
) ;
2106 RgnHandle updateRgn = NewRgn() ;
2109 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2113 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2114 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2116 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2117 DisposeRgn(updateRgn) ;
2119 if ( m_peer
->IsVisible())
2121 m_peer
->SetVisibility( false , false ) ;
2122 m_peer
->SetVisibility( true , true ) ;
2125 if ( MacGetTopLevelWindow() == NULL )
2128 if ( !m_peer->IsVisible())
2131 wxPoint client = GetClientAreaOrigin();
2134 int x2 = m_width - client.x;
2135 int y2 = m_height - client.y;
2137 if (IsKindOf( CLASSINFO(wxButton)))
2139 // buttons have an "aura"
2146 Rect clientrect = { y1, x1, y2, x2 };
2150 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2151 SectRect( &clientrect , &r , &clientrect ) ;
2154 if ( !EmptyRect( &clientrect ) )
2156 int top = 0 , left = 0 ;
2158 MacClientToRootWindow( &left , &top ) ;
2159 OffsetRect( &clientrect , left , top ) ;
2161 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2167 void wxWindowMac::Freeze()
2169 #if TARGET_API_MAC_OSX
2170 if ( !m_frozenness
++ )
2172 if ( m_peer
&& m_peer
->Ok() )
2173 m_peer
->SetDrawingEnabled( false ) ;
2179 void wxWindowMac::Thaw()
2181 #if TARGET_API_MAC_OSX
2182 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2184 if ( !--m_frozenness
)
2186 if ( m_peer
&& m_peer
->Ok() )
2188 m_peer
->SetDrawingEnabled( true ) ;
2189 m_peer
->InvalidateWithChildren() ;
2195 void wxWindowMac::MacRedrawControl()
2198 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2200 #if TARGET_API_MAC_CARBON
2203 wxClientDC dc(this) ;
2204 wxMacPortSetter helper(&dc) ;
2205 wxMacWindowClipper clipper(this) ;
2206 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2207 UMADrawControl( *m_peer ) ;
2214 void wxWindowMac::OnPaint(wxPaintEvent& event)
2216 // why don't we skip that here ?
2220 wxWindowMac
*wxGetActiveWindow()
2222 // actually this is a windows-only concept
2226 // Coordinates relative to the window
2227 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2229 // We really don't move the mouse programmatically under Mac.
2232 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2234 #if TARGET_API_MAC_OSX
2235 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2242 event
.GetDC()->Clear() ;
2246 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2251 int wxWindowMac::GetScrollPos(int orient
) const
2253 if ( orient
== wxHORIZONTAL
)
2256 return m_hScrollBar
->GetThumbPosition() ;
2261 return m_vScrollBar
->GetThumbPosition() ;
2266 // This now returns the whole range, not just the number
2267 // of positions that we can scroll.
2268 int wxWindowMac::GetScrollRange(int orient
) const
2270 if ( orient
== wxHORIZONTAL
)
2273 return m_hScrollBar
->GetRange() ;
2278 return m_vScrollBar
->GetRange() ;
2283 int wxWindowMac::GetScrollThumb(int orient
) const
2285 if ( orient
== wxHORIZONTAL
)
2288 return m_hScrollBar
->GetThumbSize() ;
2293 return m_vScrollBar
->GetThumbSize() ;
2298 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2300 if ( orient
== wxHORIZONTAL
)
2303 m_hScrollBar
->SetThumbPosition( pos
) ;
2308 m_vScrollBar
->SetThumbPosition( pos
) ;
2312 void wxWindowMac::MacPaintBorders( int left
, int top
)
2318 m_peer
->GetRect( &rect
) ;
2319 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2321 if ( !IsTopLevel() )
2323 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2327 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2329 rect
.right
+= pt
.x
;
2331 rect
.bottom
+= pt
.y
;
2335 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2339 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2340 InsetRect( &srect
, border
, border
);
2341 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2343 else if (HasFlag(wxSIMPLE_BORDER
))
2347 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2348 InsetRect( &srect
, border
, border
);
2349 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2353 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2355 if ( child
== m_hScrollBar
)
2356 m_hScrollBar
= NULL
;
2357 if ( child
== m_vScrollBar
)
2358 m_vScrollBar
= NULL
;
2360 wxWindowBase::RemoveChild( child
) ;
2363 // New function that will replace some of the above.
2364 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2365 int range
, bool refresh
)
2367 if ( orient
== wxHORIZONTAL
)
2371 if ( range
== 0 || thumbVisible
>= range
)
2373 if ( m_hScrollBar
->IsShown() )
2374 m_hScrollBar
->Show(false) ;
2378 if ( !m_hScrollBar
->IsShown() )
2379 m_hScrollBar
->Show(true) ;
2380 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2388 if ( range
== 0 || thumbVisible
>= range
)
2390 if ( m_vScrollBar
->IsShown() )
2391 m_vScrollBar
->Show(false) ;
2395 if ( !m_vScrollBar
->IsShown() )
2396 m_vScrollBar
->Show(true) ;
2397 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2401 MacRepositionScrollBars() ;
2404 // Does a physical scroll
2405 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2407 if( dx
== 0 && dy
==0 )
2413 int width
, height
;
2414 GetClientSize( &width
, &height
) ;
2415 #if TARGET_API_MAC_OSX
2416 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2417 // area is scrolled, this does not occur if width and height are 2 pixels less,
2418 // TODO write optimal workaround
2419 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2422 scrollrect
.Intersect( *rect
) ;
2424 if ( m_peer
->GetNeedsDisplay() )
2426 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2427 // either immediate redraw or full invalidate
2429 // is the better overall solution, as it does not slow down scrolling
2430 m_peer
->SetNeedsDisplay( true ) ;
2432 // this would be the preferred version for fast drawing controls
2433 if( UMAGetSystemVersion() < 0x1030 )
2436 HIViewRender(m_peer
->GetControlRef()) ;
2439 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2440 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2441 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2448 RgnHandle updateRgn
= NewRgn() ;
2451 wxClientDC
dc(this) ;
2452 wxMacPortSetter
helper(&dc
) ;
2454 m_peer
->GetRect( &scrollrect
) ;
2455 scrollrect
.top
+= MacGetTopBorderSize() ;
2456 scrollrect
.left
+= MacGetLeftBorderSize() ;
2457 scrollrect
.bottom
= scrollrect
.top
+ height
;
2458 scrollrect
.right
= scrollrect
.left
+ width
;
2462 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2463 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2464 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2466 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2468 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2472 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2474 wxWindowMac
*child
= node
->GetData();
2475 if (child
== m_vScrollBar
) continue;
2476 if (child
== m_hScrollBar
) continue;
2477 if (child
->IsTopLevel()) continue;
2480 child
->GetPosition( &x
, &y
);
2482 child
->GetSize( &w
, &h
);
2486 if (rect
->Intersects(rc
))
2487 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2491 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2496 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2498 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2500 wxScrollWinEvent wevent
;
2501 wevent
.SetPosition(event
.GetPosition());
2502 wevent
.SetOrientation(event
.GetOrientation());
2503 wevent
.m_eventObject
= this;
2505 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2506 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2507 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2508 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2509 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2510 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2511 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2512 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2513 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2514 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2515 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2516 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2517 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2518 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2519 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2520 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2522 GetEventHandler()->ProcessEvent(wevent
);
2526 // Get the window with the focus
2527 wxWindowMac
*wxWindowBase::DoFindFocus()
2529 ControlRef control
;
2530 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2531 return wxFindControlFromMacControl( control
) ;
2534 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2536 // panel wants to track the window which was the last to have focus in it,
2537 // so we want to set ourselves as the window which last had focus
2539 // notice that it's also important to do it upwards the tree becaus
2540 // otherwise when the top level panel gets focus, it won't set it back to
2541 // us, but to some other sibling
2543 // CS:don't know if this is still needed:
2544 //wxChildFocusEvent eventFocus(this);
2545 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2547 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2549 wxMacWindowStateSaver
sv( this ) ;
2554 MacWindowToRootWindow( &x
, &y
) ;
2555 GetSize( &w
, &h
) ;
2556 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2558 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2559 DrawThemeFocusRect( &rect
, true ) ;
2562 DrawThemeFocusRect( &rect
, false ) ;
2564 // as this erases part of the frame we have to redraw borders
2565 // and because our z-ordering is not always correct (staticboxes)
2566 // we have to invalidate things, we cannot simple redraw
2567 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2568 RectRgn( updateInner
, &rect
) ;
2569 InsetRect( &rect
, -4 , -4 ) ;
2570 RectRgn( updateOuter
, &rect
) ;
2571 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2572 wxPoint
parent(0,0);
2573 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2574 parent
-= GetParent()->GetClientAreaOrigin() ;
2575 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2576 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2577 DisposeRgn(updateOuter
) ;
2578 DisposeRgn(updateInner
) ;
2585 void wxWindowMac::OnInternalIdle()
2587 // This calls the UI-update mechanism (querying windows for
2588 // menu/toolbar/control state information)
2589 if (wxUpdateUIEvent::CanUpdate(this))
2590 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2593 // Raise the window to the top of the Z order
2594 void wxWindowMac::Raise()
2596 m_peer
->SetZOrder( true , NULL
) ;
2599 // Lower the window to the bottom of the Z order
2600 void wxWindowMac::Lower()
2602 m_peer
->SetZOrder( false , NULL
) ;
2606 // static wxWindow *gs_lastWhich = NULL;
2608 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2610 // first trigger a set cursor event
2612 wxPoint clientorigin
= GetClientAreaOrigin() ;
2613 wxSize clientsize
= GetClientSize() ;
2615 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2617 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2619 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2620 if ( processedEvtSetCursor
&& event
.HasCursor() )
2622 cursor
= event
.GetCursor() ;
2627 // the test for processedEvtSetCursor is here to prevent using m_cursor
2628 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2629 // it - this is a way to say that our cursor shouldn't be used for this
2631 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2641 cursor
= *wxSTANDARD_CURSOR
;
2645 cursor
.MacInstall() ;
2647 return cursor
.Ok() ;
2650 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2654 return m_tooltip
->GetTip() ;
2656 return wxEmptyString
;
2659 void wxWindowMac::Update()
2661 #if TARGET_API_MAC_OSX
2663 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2664 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2666 // for composited windows this also triggers a redraw of all
2667 // invalid views in the window
2668 if( UMAGetSystemVersion() >= 0x1030 )
2669 HIWindowFlush(window
) ;
2673 // the only way to trigger the redrawing on earlier systems is to call
2676 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2677 UInt32 currentEventClass
= 0 ;
2678 UInt32 currentEventKind
= 0 ;
2679 if ( currentEvent
!= NULL
)
2681 currentEventClass
= ::GetEventClass( currentEvent
) ;
2682 currentEventKind
= ::GetEventKind( currentEvent
) ;
2684 if ( currentEventClass
!= kEventClassMenu
)
2686 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2689 OSStatus status
= noErr
;
2690 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2693 m_peer
->SetNeedsDisplay( true ) ;
2696 ::Draw1Control( m_peer
->GetControlRef() ) ;
2700 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2702 wxTopLevelWindowMac
* win
= NULL
;
2703 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2706 win
= wxFindWinFromMacWindow( window
) ;
2710 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2712 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2713 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2714 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2715 // to add focus borders everywhere
2718 RgnHandle visRgn
= NewRgn() ;
2719 RgnHandle tempRgn
= NewRgn() ;
2720 if ( m_peer
->IsVisible())
2722 m_peer
->GetRect( &r
) ;
2723 r
.left
-= MacGetLeftBorderSize() ;
2724 r
.top
-= MacGetTopBorderSize() ;
2725 r
.bottom
+= MacGetBottomBorderSize() ;
2726 r
.right
+= MacGetRightBorderSize() ;
2728 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2730 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2731 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2740 if ( includeOuterStructures
)
2741 InsetRect( &r
, -4 , -4 ) ;
2742 RectRgn( visRgn
, &r
) ;
2744 if ( !IsTopLevel() )
2746 wxWindow
* child
= this ;
2747 wxWindow
* parent
= child
->GetParent() ;
2752 // we have to find a better clipping algorithm here, in order not to clip things
2753 // positioned like status and toolbar
2754 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2756 size
= parent
->GetSize() ;
2761 size
= parent
->GetClientSize() ;
2762 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2766 parent
->MacWindowToRootWindow( &x
, &y
) ;
2767 MacRootWindowToWindow( &x
, &y
) ;
2769 if ( !includeOuterStructures
|| (
2770 parent
->MacClipChildren() ||
2771 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2774 SetRectRgn( tempRgn
,
2775 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2776 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2777 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2779 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2781 if ( parent
->IsTopLevel() )
2784 parent
= child
->GetParent() ;
2789 wxRegion vis
= visRgn
;
2790 DisposeRgn( visRgn
) ;
2791 DisposeRgn( tempRgn
) ;
2796 This function must not change the updatergn !
2798 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2800 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2801 bool handled
= false ;
2803 GetRegionBounds( updatergn
, &updatebounds
) ;
2804 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2805 if ( !EmptyRgn(updatergn
) )
2807 RgnHandle newupdate
= NewRgn() ;
2808 wxSize point
= GetClientSize() ;
2809 wxPoint origin
= GetClientAreaOrigin() ;
2810 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2811 SectRgn( newupdate
, updatergn
, newupdate
) ;
2813 // first send an erase event to the entire update area
2815 wxWindowDC
dc(this);
2816 dc
.SetClippingRegion(wxRegion(updatergn
));
2817 wxEraseEvent
eevent( GetId(), &dc
);
2818 eevent
.SetEventObject( this );
2819 GetEventHandler()->ProcessEvent( eevent
);
2822 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2823 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2824 m_updateRegion
= newupdate
;
2825 DisposeRgn( newupdate
) ;
2827 if ( !m_updateRegion
.Empty() )
2829 // paint the window itself
2831 event
.m_timeStamp
= time
;
2832 event
.SetEventObject(this);
2833 handled
= GetEventHandler()->ProcessEvent(event
);
2835 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2838 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2840 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2847 // now we cannot rely on having its borders drawn by a window itself, as it does not
2848 // get the updateRgn wide enough to always do so, so we do it from the parent
2849 // this would also be the place to draw any custom backgrounds for native controls
2850 // in Composited windowing
2851 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2853 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2855 wxWindowMac
*child
= node
->GetData();
2856 if (child
== m_vScrollBar
) continue;
2857 if (child
== m_hScrollBar
) continue;
2858 if (child
->IsTopLevel()) continue;
2859 if (!child
->IsShown()) continue;
2862 child
->GetPosition( &x
, &y
);
2864 child
->GetSize( &w
, &h
);
2865 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2866 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2867 if ( child
->MacGetTopBorderSize() )
2869 if ( RectInRgn( &childRect
, updatergn
) )
2871 // paint custom borders
2872 wxNcPaintEvent
eventNc( child
->GetId() );
2873 eventNc
.SetEventObject( child
);
2874 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2876 wxWindowDC
dc(this) ;
2877 dc
.SetClippingRegion(wxRegion(updatergn
));
2878 wxMacPortSetter
helper(&dc
) ;
2879 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2883 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2885 wxWindowDC
dc(this) ;
2886 dc
.SetClippingRegion(wxRegion(updatergn
));
2887 wxMacPortSetter
helper(&dc
) ;
2888 Rect r
= childRect
;
2889 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2890 DrawThemeFocusRect( &r
, true ) ;
2897 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2899 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2900 // updatergn is always already clipped to our boundaries
2901 // if we are in compositing mode then it is in relative to the upper left of the control
2902 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2903 // of the toplevel window
2904 // it is in window coordinates, not in client coordinates
2906 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2907 RgnHandle ownUpdateRgn
= NewRgn() ;
2908 CopyRgn( updatergn
, ownUpdateRgn
) ;
2910 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2913 m_peer
->GetRectInWindowCoords( &bounds
);
2914 RgnHandle controlRgn
= NewRgn();
2915 RectRgn( controlRgn
, &bounds
);
2916 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2917 // the window update region
2918 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2919 DisposeRgn( controlRgn
);
2921 //KO: convert ownUpdateRgn to local coordinates
2922 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2925 MacDoRedraw( ownUpdateRgn
, time
) ;
2926 DisposeRgn( ownUpdateRgn
) ;
2930 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2932 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2936 if ( iter
->IsTopLevel() )
2937 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2939 iter
= iter
->GetParent() ;
2941 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2945 void wxWindowMac::MacCreateScrollBars( long style
)
2947 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2949 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2951 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2952 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2953 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2954 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2956 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2957 variant
= wxWINDOW_VARIANT_SMALL
;
2960 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2962 GetClientSize( &width
, &height
) ;
2964 wxPoint
vPoint(width
-scrlsize
, 0) ;
2965 wxSize
vSize(scrlsize
, height
- adjust
) ;
2966 wxPoint
hPoint(0 , height
-scrlsize
) ;
2967 wxSize
hSize( width
- adjust
, scrlsize
) ;
2970 if ( style
& wxVSCROLL
)
2972 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2973 vSize
, wxVERTICAL
);
2976 if ( style
& wxHSCROLL
)
2978 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2979 hSize
, wxHORIZONTAL
);
2984 // because the create does not take into account the client area origin
2985 MacRepositionScrollBars() ; // we might have a real position shift
2988 void wxWindowMac::MacRepositionScrollBars()
2990 if ( !m_hScrollBar
&& !m_vScrollBar
)
2993 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2994 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
2995 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
2997 // get real client area
3001 GetSize( &width
, &height
) ;
3003 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3004 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3006 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3007 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3008 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3009 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3015 GetSize( &w , &h ) ;
3017 MacClientToRootWindow( &x , &y ) ;
3018 MacClientToRootWindow( &w , &h ) ;
3020 wxWindowMac *iter = (wxWindowMac*)this ;
3022 int totW = 10000 , totH = 10000;
3025 if ( iter->IsTopLevel() )
3027 iter->GetSize( &totW , &totH ) ;
3031 iter = iter->GetParent() ;
3059 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3063 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3067 bool wxWindowMac::AcceptsFocus() const
3069 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3072 void wxWindowMac::MacSuperChangedPosition()
3074 // only window-absolute structures have to be moved i.e. controls
3076 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3079 wxWindowMac
*child
= node
->GetData();
3080 child
->MacSuperChangedPosition() ;
3081 node
= node
->GetNext();
3085 void wxWindowMac::MacTopLevelWindowChangedPosition()
3087 // only screen-absolute structures have to be moved i.e. glcanvas
3089 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3092 wxWindowMac
*child
= node
->GetData();
3093 child
->MacTopLevelWindowChangedPosition() ;
3094 node
= node
->GetNext();
3098 long wxWindowMac::MacGetLeftBorderSize( ) const
3103 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3108 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3113 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3120 long wxWindowMac::MacGetRightBorderSize( ) const
3122 // they are all symmetric in mac themes
3123 return MacGetLeftBorderSize() ;
3126 long wxWindowMac::MacGetTopBorderSize( ) const
3128 // they are all symmetric in mac themes
3129 return MacGetLeftBorderSize() ;
3132 long wxWindowMac::MacGetBottomBorderSize( ) const
3134 // they are all symmetric in mac themes
3135 return MacGetLeftBorderSize() ;
3138 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3140 return style
& ~wxBORDER_MASK
;
3143 // Find the wxWindowMac at the current mouse position, returning the mouse
3145 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3147 pt
= wxGetMousePosition();
3148 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3152 // Get the current mouse position.
3153 wxPoint
wxGetMousePosition()
3156 wxGetMousePosition(& x
, & y
);
3157 return wxPoint(x
, y
);
3160 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3162 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3164 // copied from wxGTK : CS
3165 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3168 // (a) it's a command event and so is propagated to the parent
3169 // (b) under MSW it can be generated from kbd too
3170 // (c) it uses screen coords (because of (a))
3171 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3173 this->ClientToScreen(event
.GetPosition()));
3174 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3183 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3187 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3191 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3192 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3196 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3198 return eventNotHandledErr
;