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::MacChildAdded()
899 m_vScrollBar
->Raise() ;
903 m_hScrollBar
->Raise() ;
908 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
910 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
912 m_peer
->SetReference( (long) this ) ;
913 GetParent()->AddChild(this);
915 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
917 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
918 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
919 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
920 GetParent()->MacChildAdded() ;
922 // adjust font, controlsize etc
923 DoSetWindowVariant( m_windowVariant
) ;
925 #if !TARGET_API_MAC_OSX
926 // eventually we can fix some clipping issues be reactivating this hook
927 //if ( m_macIsUserPane )
928 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
930 m_peer
->SetTitle( wxStripMenuCodes(m_label
) ) ;
932 if (!m_macIsUserPane
)
934 SetInitialBestSize(size
);
937 SetCursor( *wxSTANDARD_CURSOR
) ;
940 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
942 // Don't assert, in case we set the window variant before
943 // the window is created
944 // wxASSERT( m_peer->Ok() ) ;
946 m_windowVariant
= variant
;
948 if (m_peer
== NULL
|| !m_peer
->Ok())
952 ThemeFontID themeFont
= kThemeSystemFont
;
954 // we will get that from the settings later
955 // and make this NORMAL later, but first
956 // we have a few calculations that we must fix
960 case wxWINDOW_VARIANT_NORMAL
:
961 size
= kControlSizeNormal
;
962 themeFont
= kThemeSystemFont
;
964 case wxWINDOW_VARIANT_SMALL
:
965 size
= kControlSizeSmall
;
966 themeFont
= kThemeSmallSystemFont
;
968 case wxWINDOW_VARIANT_MINI
:
969 if (UMAGetSystemVersion() >= 0x1030 )
971 // not always defined in the headers
977 size
= kControlSizeSmall
;
978 themeFont
= kThemeSmallSystemFont
;
981 case wxWINDOW_VARIANT_LARGE
:
982 size
= kControlSizeLarge
;
983 themeFont
= kThemeSystemFont
;
986 wxFAIL_MSG(_T("unexpected window variant"));
989 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
,&size
) ;
992 font
.MacCreateThemeFont( themeFont
) ;
996 void wxWindowMac::MacUpdateControlFont()
998 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1002 bool wxWindowMac::SetFont(const wxFont
& font
)
1004 bool retval
= wxWindowBase::SetFont( font
) ;
1006 MacUpdateControlFont() ;
1011 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1013 if ( !wxWindowBase::SetForegroundColour(col
) )
1016 MacUpdateControlFont() ;
1021 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1023 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1027 wxColour
newCol(GetBackgroundColour());
1028 if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
) )
1030 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1032 else if ( newCol
== wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
) )
1034 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1038 brush
.SetColour( newCol
) ;
1040 MacSetBackgroundBrush( brush
) ;
1042 MacUpdateControlFont() ;
1047 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1049 m_macBackgroundBrush
= brush
;
1050 m_peer
->SetBackground( brush
) ;
1053 bool wxWindowMac::MacCanFocus() const
1055 // there is currently no way to determine whether the window is running in full keyboard
1056 // access mode, therefore we cannot rely on these features, yet the only other way would be
1057 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1058 // in event handlers...
1059 UInt32 features
= 0 ;
1060 m_peer
->GetFeatures( & features
) ;
1061 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1065 void wxWindowMac::SetFocus()
1067 if ( AcceptsFocus() )
1070 wxWindow
* former
= FindFocus() ;
1071 if ( former
== this )
1074 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1075 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1076 // leave in case of an error
1077 if ( err
== errCouldntSetFocus
)
1080 #if !TARGET_API_MAC_OSX
1081 // emulate carbon events when running under carbonlib where they are not natively available
1084 EventRef evRef
= NULL
;
1085 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1088 wxMacCarbonEvent
cEvent( evRef
) ;
1089 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1090 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1092 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1093 ReleaseEvent(evRef
) ;
1095 // send new focus event
1097 EventRef evRef
= NULL
;
1098 verify_noerr( MacCreateEvent( NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) , kEventAttributeUserEvent
,
1101 wxMacCarbonEvent
cEvent( evRef
) ;
1102 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1103 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1105 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1106 ReleaseEvent(evRef
) ;
1113 void wxWindowMac::DoCaptureMouse()
1115 wxTheApp
->s_captureWindow
= this ;
1118 wxWindow
* wxWindowBase::GetCapture()
1120 return wxTheApp
->s_captureWindow
;
1123 void wxWindowMac::DoReleaseMouse()
1125 wxTheApp
->s_captureWindow
= NULL
;
1128 #if wxUSE_DRAG_AND_DROP
1130 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1132 if ( m_dropTarget
!= 0 ) {
1133 delete m_dropTarget
;
1136 m_dropTarget
= pDropTarget
;
1137 if ( m_dropTarget
!= 0 )
1145 // Old style file-manager drag&drop
1146 void wxWindowMac::DragAcceptFiles(bool accept
)
1151 // Returns the size of the native control. In the case of the toplevel window
1152 // this is the content area root control
1154 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1155 int& w
, int& h
) const
1158 m_peer
->GetRect( &bounds
) ;
1163 w
= bounds
.right
- bounds
.left
;
1164 h
= bounds
.bottom
- bounds
.top
;
1167 // From a wx position / size calculate the appropriate size of the native control
1169 bool wxWindowMac::MacGetBoundsForControl(const wxPoint
& pos
,
1172 int& w
, int& h
, bool adjustOrigin
) const
1174 // the desired size, minus the border pixels gives the correct size of the control
1178 // todo the default calls may be used as soon as PostCreateControl Is moved here
1179 w
= size
.x
; // WidthDefault( size.x );
1180 h
= size
.y
; // HeightDefault( size.y ) ;
1181 #if !TARGET_API_MAC_OSX
1182 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1185 x
+= MacGetLeftBorderSize() ;
1186 y
+= MacGetTopBorderSize() ;
1187 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1188 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1191 AdjustForParentClientOrigin( x
, y
) ;
1192 #if TARGET_API_MAC_OSX
1193 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1194 if ( ! GetParent()->IsTopLevel() )
1196 x
-= GetParent()->MacGetLeftBorderSize() ;
1197 y
-= GetParent()->MacGetTopBorderSize() ;
1203 // Get window size (not client size)
1204 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1206 // take the size of the control and add the borders that have to be drawn outside
1207 int x1
, y1
, w1
, h1
;
1209 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1211 w1
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1212 h1
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1218 // get the position of the bounds of this window in client coordinates of its parent
1219 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1221 int x1
, y1
, w1
,h1
;
1222 MacGetPositionAndSizeFromControl( x1
, y1
, w1
,h1
) ;
1223 x1
-= MacGetLeftBorderSize() ;
1224 y1
-= MacGetTopBorderSize() ;
1226 #if !TARGET_API_MAC_OSX
1227 if ( !GetParent()->IsTopLevel() )
1230 GetControlBounds( (ControlRef
) GetParent()->GetHandle() , &bounds
) ;
1235 if ( !IsTopLevel() )
1237 wxWindow
*parent
= GetParent();
1240 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1241 x1
+= parent
->MacGetLeftBorderSize() ;
1242 y1
+= parent
->MacGetTopBorderSize() ;
1243 // and now to client coordinates
1244 wxPoint
pt(parent
->GetClientAreaOrigin());
1253 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1255 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1257 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1260 Point localwhere
= {0,0} ;
1262 if(x
) localwhere
.h
= * x
;
1263 if(y
) localwhere
.v
= * y
;
1265 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1266 if(x
) *x
= localwhere
.h
;
1267 if(y
) *y
= localwhere
.v
;
1270 MacRootWindowToWindow( x
, y
) ;
1272 wxPoint origin
= GetClientAreaOrigin() ;
1273 if(x
) *x
-= origin
.x
;
1274 if(y
) *y
-= origin
.y
;
1277 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1279 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1280 wxCHECK_RET( window
, wxT("TopLevel Window Missing") ) ;
1282 wxPoint origin
= GetClientAreaOrigin() ;
1283 if(x
) *x
+= origin
.x
;
1284 if(y
) *y
+= origin
.y
;
1286 MacWindowToRootWindow( x
, y
) ;
1289 Point localwhere
= { 0,0 };
1290 if(x
) localwhere
.h
= * x
;
1291 if(y
) localwhere
.v
= * y
;
1292 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1293 if(x
) *x
= localwhere
.h
;
1294 if(y
) *y
= localwhere
.v
;
1298 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1300 wxPoint origin
= GetClientAreaOrigin() ;
1301 if(x
) *x
+= origin
.x
;
1302 if(y
) *y
+= origin
.y
;
1304 MacWindowToRootWindow( x
, y
) ;
1307 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1309 MacRootWindowToWindow( x
, y
) ;
1311 wxPoint origin
= GetClientAreaOrigin() ;
1312 if(x
) *x
-= origin
.x
;
1313 if(y
) *y
-= origin
.y
;
1316 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1318 #if TARGET_API_MAC_OSX
1320 if ( x
) pt
.x
= *x
;
1321 if ( y
) pt
.y
= *y
;
1323 if ( !IsTopLevel() )
1325 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1328 pt
.x
-= MacGetLeftBorderSize() ;
1329 pt
.y
-= MacGetTopBorderSize() ;
1330 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1334 if ( x
) *x
= (int) pt
.x
;
1335 if ( y
) *y
= (int) pt
.y
;
1337 if ( !IsTopLevel() )
1340 m_peer
->GetRect( &bounds
) ;
1341 if(x
) *x
+= bounds
.left
- MacGetLeftBorderSize() ;
1342 if(y
) *y
+= bounds
.top
- MacGetTopBorderSize() ;
1347 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1352 MacWindowToRootWindow( &x1
, &y1
) ;
1357 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1359 #if TARGET_API_MAC_OSX
1361 if ( x
) pt
.x
= *x
;
1362 if ( y
) pt
.y
= *y
;
1364 if ( !IsTopLevel() )
1366 wxMacControl::Convert( &pt
, MacGetTopLevelWindow()->m_peer
, m_peer
) ;
1367 pt
.x
+= MacGetLeftBorderSize() ;
1368 pt
.y
+= MacGetTopBorderSize() ;
1371 if ( x
) *x
= (int) pt
.x
;
1372 if ( y
) *y
= (int) pt
.y
;
1374 if ( !IsTopLevel() )
1377 m_peer
->GetRect( &bounds
) ;
1378 if(x
) *x
-= bounds
.left
+ MacGetLeftBorderSize() ;
1379 if(y
) *y
-= bounds
.top
+ MacGetTopBorderSize() ;
1384 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1389 MacRootWindowToWindow( &x1
, &y1
) ;
1394 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1396 RgnHandle rgn
= NewRgn() ;
1398 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1400 GetRegionBounds( rgn
, &content
) ;
1404 m_peer
->GetRect( &content
) ;
1408 m_peer
->GetRect( &structure
) ;
1409 #if !TARGET_API_MAC_OSX
1410 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1412 left
= content
.left
- structure
.left
;
1413 top
= content
.top
- structure
.top
;
1414 right
= structure
.right
- content
.right
;
1415 bottom
= structure
.bottom
- content
.bottom
;
1418 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1420 wxSize sizeTotal
= size
;
1422 RgnHandle rgn
= NewRgn() ;
1426 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1428 GetRegionBounds( rgn
, &content
) ;
1432 m_peer
->GetRect( &content
) ;
1436 m_peer
->GetRect( &structure
) ;
1437 #if !TARGET_API_MAC_OSX
1438 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1441 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1442 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1444 sizeTotal
.x
+= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1445 sizeTotal
.y
+= MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
1451 // Get size *available for subwindows* i.e. excluding menu bar etc.
1452 void wxWindowMac::DoGetClientSize(int *x
, int *y
) const
1456 RgnHandle rgn
= NewRgn() ;
1458 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1460 GetRegionBounds( rgn
, &content
) ;
1464 m_peer
->GetRect( &content
) ;
1467 #if !TARGET_API_MAC_OSX
1469 m_peer
->GetRect( &structure
) ;
1470 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1472 ww
= content
.right
- content
.left
;
1473 hh
= content
.bottom
- content
.top
;
1475 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1476 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
1479 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1485 GetSize( &w , &h ) ;
1487 MacClientToRootWindow( &x1 , &y1 ) ;
1488 MacClientToRootWindow( &w , &h ) ;
1490 wxWindowMac *iter = (wxWindowMac*)this ;
1492 int totW = 10000 , totH = 10000;
1495 if ( iter->IsTopLevel() )
1497 iter->GetSize( &totW , &totH ) ;
1501 iter = iter->GetParent() ;
1504 if (m_hScrollBar && m_hScrollBar->IsShown() )
1506 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1512 if (m_vScrollBar && m_vScrollBar->IsShown() )
1514 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1522 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1524 hh
-= m_hScrollBar
->GetSize().y
; // MAC_SCROLLBAR_SIZE ;
1526 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1528 ww
-= m_vScrollBar
->GetSize().x
; // MAC_SCROLLBAR_SIZE;
1535 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1537 if (m_cursor
== cursor
)
1540 if (wxNullCursor
== cursor
)
1542 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1547 if ( ! wxWindowBase::SetCursor( cursor
) )
1551 wxASSERT_MSG( m_cursor
.Ok(),
1552 wxT("cursor must be valid after call to the base version"));
1555 wxWindowMac
*mouseWin
= 0 ;
1557 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1559 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1561 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1562 // position, use it...
1566 ControlPartCode part
;
1567 ControlRef control
;
1568 control
= wxMacFindControlUnderMouse( pt
, window
, &part
) ;
1570 mouseWin
= wxFindControlFromMacControl( control
) ;
1573 QDSwapPort( savePort
, NULL
) ;
1576 if ( mouseWin
== this && !wxIsBusy() )
1578 m_cursor
.MacInstall() ;
1585 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1587 menu
->SetInvokingWindow(this);
1590 if ( x
== -1 && y
== -1 )
1592 wxPoint mouse
= wxGetMousePosition();
1593 x
= mouse
.x
; y
= mouse
.y
;
1597 ClientToScreen( &x
, &y
) ;
1600 menu
->MacBeforeDisplay( true ) ;
1601 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() ,y
,x
, 0) ;
1602 if ( HiWord(menuResult
) != 0 )
1605 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &id
) ;
1606 wxMenuItem
* item
= NULL
;
1608 item
= menu
->FindItem(id
, &realmenu
) ;
1609 if (item
->IsCheckable())
1611 item
->Check( !item
->IsChecked() ) ;
1613 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1615 menu
->MacAfterDisplay( true ) ;
1617 menu
->SetInvokingWindow(NULL
);
1623 // ----------------------------------------------------------------------------
1625 // ----------------------------------------------------------------------------
1629 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1631 wxWindowBase::DoSetToolTip(tooltip
);
1634 m_tooltip
->SetWindow(this);
1637 #endif // wxUSE_TOOLTIPS
1639 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1641 // this is never called for a toplevel window, so we know we have a parent
1642 int former_x
, former_y
, former_w
, former_h
;
1644 // Get true coordinates of former position
1645 DoGetPosition( &former_x
, &former_y
) ;
1646 DoGetSize( &former_w
, &former_h
) ;
1648 wxWindow
*parent
= GetParent();
1651 wxPoint
pt(parent
->GetClientAreaOrigin());
1656 int actualWidth
= width
;
1657 int actualHeight
= height
;
1661 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1662 actualWidth
= m_minWidth
;
1663 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1664 actualHeight
= m_minHeight
;
1665 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1666 actualWidth
= m_maxWidth
;
1667 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1668 actualHeight
= m_maxHeight
;
1670 bool doMove
= false ;
1671 bool doResize
= false ;
1673 if ( actualX
!= former_x
|| actualY
!= former_y
)
1677 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1682 if ( doMove
|| doResize
)
1684 // we don't adjust twice for the origin
1685 Rect r
= wxMacGetBoundsForControl(this , wxPoint( actualX
,actualY
), wxSize( actualWidth
, actualHeight
) , false ) ;
1686 bool vis
= m_peer
->IsVisible();
1688 int outerBorder
= MacGetLeftBorderSize() ;
1689 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1692 if ( vis
&& ( outerBorder
> 0 ) )
1694 // as the borders are drawn on the parent we have to properly invalidate all these areas
1695 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() , updateTotal
= NewRgn() ;
1699 m_peer
->GetRect( &rect
) ;
1700 RectRgn( updateInner
, &rect
) ;
1701 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1702 RectRgn( updateOuter
, &rect
) ;
1703 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1704 wxPoint
parent(0,0);
1705 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
1706 parent
-= GetParent()->GetClientAreaOrigin() ;
1707 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1708 CopyRgn( updateOuter
, updateTotal
) ;
1711 RectRgn( updateInner
, &rect
) ;
1712 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1713 RectRgn( updateOuter
, &rect
) ;
1714 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
1716 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
1717 UnionRgn( updateOuter
, updateTotal
, updateTotal
) ;
1719 GetParent()->m_peer
->SetNeedsDisplay( true , updateTotal
) ;
1720 DisposeRgn(updateOuter
) ;
1721 DisposeRgn(updateInner
) ;
1722 DisposeRgn(updateTotal
) ;
1725 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1727 m_peer
->SetVisibility( false , true ) ;
1729 m_peer
->SetRect( &r
) ;
1731 m_peer
->SetVisibility( true , true ) ;
1733 MacRepositionScrollBars() ;
1736 wxPoint
point(actualX
,actualY
);
1737 wxMoveEvent
event(point
, m_windowId
);
1738 event
.SetEventObject(this);
1739 GetEventHandler()->ProcessEvent(event
) ;
1743 MacRepositionScrollBars() ;
1744 wxSize
size(actualWidth
, actualHeight
);
1745 wxSizeEvent
event(size
, m_windowId
);
1746 event
.SetEventObject(this);
1747 GetEventHandler()->ProcessEvent(event
);
1753 wxSize
wxWindowMac::DoGetBestSize() const
1755 if ( m_macIsUserPane
|| IsTopLevel() )
1756 return wxWindowBase::DoGetBestSize() ;
1758 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1759 int bestWidth
, bestHeight
;
1760 m_peer
->GetBestRect( &bestsize
) ;
1762 if ( EmptyRect( &bestsize
) )
1764 bestsize
.left
= bestsize
.top
= 0 ;
1765 bestsize
.right
= 16 ;
1766 bestsize
.bottom
= 16 ;
1767 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1769 bestsize
.bottom
= 16 ;
1772 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1774 bestsize
.bottom
= 24 ;
1776 #endif // wxUSE_SPINBTN
1779 // return wxWindowBase::DoGetBestSize() ;
1783 bestWidth
= bestsize
.right
- bestsize
.left
;
1784 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1785 if ( bestHeight
< 10 )
1788 return wxSize(bestWidth
, bestHeight
);
1792 // set the size of the window: if the dimensions are positive, just use them,
1793 // but if any of them is equal to -1, it means that we must find the value for
1794 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1795 // which case -1 is a valid value for x and y)
1797 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1798 // the width/height to best suit our contents, otherwise we reuse the current
1800 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1802 // get the current size and position...
1803 int currentX
, currentY
;
1804 GetPosition(¤tX
, ¤tY
);
1806 int currentW
,currentH
;
1807 GetSize(¤tW
, ¤tH
);
1809 // ... and don't do anything (avoiding flicker) if it's already ok
1810 if ( x
== currentX
&& y
== currentY
&&
1811 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1814 MacRepositionScrollBars() ; // we might have a real position shift
1818 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1820 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1823 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1825 wxSize
size(-1, -1);
1828 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1830 size
= DoGetBestSize();
1835 // just take the current one
1842 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1846 size
= DoGetBestSize();
1848 //else: already called DoGetBestSize() above
1854 // just take the current one
1859 DoMoveWindow(x
, y
, width
, height
);
1863 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1865 RgnHandle rgn
= NewRgn() ;
1867 m_peer
->GetRegion( kControlContentMetaPart
, rgn
) ;
1868 GetRegionBounds( rgn
, &content
) ;
1870 #if !TARGET_API_MAC_OSX
1871 // if the content rgn is empty / not supported
1872 // don't attempt to correct the coordinates to wxWindow relative ones
1873 if (!::EmptyRect( &content
) )
1876 m_peer
->GetRect( &structure
) ;
1877 OffsetRect( &content
, -structure
.left
, -structure
.top
) ;
1881 return wxPoint( content
.left
+ MacGetLeftBorderSize( ) , content
.top
+ MacGetTopBorderSize( ) );
1884 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1886 if ( clientheight
!= -1 || clientheight
!= -1 )
1888 int currentclientwidth
, currentclientheight
;
1889 int currentwidth
, currentheight
;
1891 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1892 GetSize( ¤twidth
, ¤theight
) ;
1894 DoSetSize( -1 , -1 , currentwidth
+ clientwidth
- currentclientwidth
,
1895 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1899 void wxWindowMac::SetTitle(const wxString
& title
)
1901 m_label
= wxStripMenuCodes(title
) ;
1903 if ( m_peer
&& m_peer
->Ok() )
1905 m_peer
->SetTitle( m_label
) ;
1910 wxString
wxWindowMac::GetTitle() const
1915 bool wxWindowMac::Show(bool show
)
1917 if ( !wxWindowBase::Show(show
) )
1920 // TODO use visibilityChanged Carbon Event for OSX
1923 bool former
= MacIsReallyShown() ;
1925 m_peer
->SetVisibility( show
, true ) ;
1926 if ( former
!= MacIsReallyShown() )
1927 MacPropagateVisibilityChanged() ;
1932 bool wxWindowMac::Enable(bool enable
)
1934 wxASSERT( m_peer
->Ok() ) ;
1935 if ( !wxWindowBase::Enable(enable
) )
1938 bool former
= MacIsReallyEnabled() ;
1939 m_peer
->Enable( enable
) ;
1941 if ( former
!= MacIsReallyEnabled() )
1942 MacPropagateEnabledStateChanged() ;
1947 // status change propagations (will be not necessary for OSX later )
1950 void wxWindowMac::MacPropagateVisibilityChanged()
1952 #if !TARGET_API_MAC_OSX
1953 MacVisibilityChanged() ;
1955 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1958 wxWindowMac
*child
= node
->GetData();
1959 if ( child
->IsShown() )
1960 child
->MacPropagateVisibilityChanged( ) ;
1961 node
= node
->GetNext();
1966 void wxWindowMac::MacPropagateEnabledStateChanged( )
1968 #if !TARGET_API_MAC_OSX
1969 MacEnabledStateChanged() ;
1971 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1974 wxWindowMac
*child
= node
->GetData();
1975 if ( child
->IsEnabled() )
1976 child
->MacPropagateEnabledStateChanged() ;
1977 node
= node
->GetNext();
1982 void wxWindowMac::MacPropagateHiliteChanged( )
1984 #if !TARGET_API_MAC_OSX
1985 MacHiliteChanged() ;
1987 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1990 wxWindowMac
*child
= node
->GetData();
1991 // if ( child->IsEnabled() )
1992 child
->MacPropagateHiliteChanged() ;
1993 node
= node
->GetNext();
1999 // status change notifications
2002 void wxWindowMac::MacVisibilityChanged()
2006 void wxWindowMac::MacHiliteChanged()
2010 void wxWindowMac::MacEnabledStateChanged()
2015 // status queries on the inherited window's state
2018 bool wxWindowMac::MacIsReallyShown()
2020 // only under OSX the visibility of the TLW is taken into account
2021 if ( m_isBeingDeleted
)
2024 #if TARGET_API_MAC_OSX
2025 if ( m_peer
&& m_peer
->Ok() )
2026 return m_peer
->IsVisible();
2028 wxWindow
* win
= this ;
2029 while( win
->IsShown() )
2031 if ( win
->IsTopLevel() )
2034 win
= win
->GetParent() ;
2042 bool wxWindowMac::MacIsReallyEnabled()
2044 return m_peer
->IsEnabled() ;
2047 bool wxWindowMac::MacIsReallyHilited()
2049 return m_peer
->IsActive();
2052 void wxWindowMac::MacFlashInvalidAreas()
2054 #if TARGET_API_MAC_OSX
2055 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2063 int wxWindowMac::GetCharHeight() const
2065 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2066 return dc
.GetCharHeight() ;
2069 int wxWindowMac::GetCharWidth() const
2071 wxClientDC
dc ( (wxWindowMac
*)this ) ;
2072 return dc
.GetCharWidth() ;
2075 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2076 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2078 const wxFont
*fontToUse
= theFont
;
2080 fontToUse
= &m_font
;
2082 wxClientDC
dc( (wxWindowMac
*) this ) ;
2084 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2085 if ( externalLeading
)
2086 *externalLeading
= le
;
2096 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2097 * we always intersect with the entire window, not only with the client area
2100 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2102 if ( m_peer
== NULL
)
2105 #if TARGET_API_MAC_OSX
2107 m_peer
->SetNeedsDisplay( true ) ;
2110 RgnHandle update
= NewRgn() ;
2111 SetRectRgn( update
, rect
->x
, rect
->y
, rect
->x
+ rect
->width
, rect
->y
+ rect
->height
) ;
2112 SectRgn( (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , update
, update
) ;
2113 wxPoint origin
= GetClientAreaOrigin() ;
2114 OffsetRgn( update
, origin
.x
, origin
.y
) ;
2115 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2117 OffsetRgn( update
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2118 m_peer
->SetNeedsDisplay( true , update
) ;
2119 DisposeRgn( update
) ;
2123 RgnHandle updateRgn = NewRgn() ;
2126 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2130 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
2131 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
2133 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2134 DisposeRgn(updateRgn) ;
2136 if ( m_peer
->IsVisible())
2138 m_peer
->SetVisibility( false , false ) ;
2139 m_peer
->SetVisibility( true , true ) ;
2142 if ( MacGetTopLevelWindow() == NULL )
2145 if ( !m_peer->IsVisible())
2148 wxPoint client = GetClientAreaOrigin();
2151 int x2 = m_width - client.x;
2152 int y2 = m_height - client.y;
2154 if (IsKindOf( CLASSINFO(wxButton)))
2156 // buttons have an "aura"
2163 Rect clientrect = { y1, x1, y2, x2 };
2167 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
2168 SectRect( &clientrect , &r , &clientrect ) ;
2171 if ( !EmptyRect( &clientrect ) )
2173 int top = 0 , left = 0 ;
2175 MacClientToRootWindow( &left , &top ) ;
2176 OffsetRect( &clientrect , left , top ) ;
2178 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
2184 void wxWindowMac::Freeze()
2186 #if TARGET_API_MAC_OSX
2187 if ( !m_frozenness
++ )
2189 if ( m_peer
&& m_peer
->Ok() )
2190 m_peer
->SetDrawingEnabled( false ) ;
2196 void wxWindowMac::Thaw()
2198 #if TARGET_API_MAC_OSX
2199 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
2201 if ( !--m_frozenness
)
2203 if ( m_peer
&& m_peer
->Ok() )
2205 m_peer
->SetDrawingEnabled( true ) ;
2206 m_peer
->InvalidateWithChildren() ;
2212 void wxWindowMac::MacRedrawControl()
2215 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
2217 #if TARGET_API_MAC_CARBON
2220 wxClientDC dc(this) ;
2221 wxMacPortSetter helper(&dc) ;
2222 wxMacWindowClipper clipper(this) ;
2223 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
2224 UMADrawControl( *m_peer ) ;
2231 void wxWindowMac::OnPaint(wxPaintEvent& event)
2233 // why don't we skip that here ?
2237 wxWindowMac
*wxGetActiveWindow()
2239 // actually this is a windows-only concept
2243 // Coordinates relative to the window
2244 void wxWindowMac::WarpPointer (int x_pos
, int y_pos
)
2246 // We really don't move the mouse programmatically under Mac.
2249 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2251 #if TARGET_API_MAC_OSX
2252 if ( m_macBackgroundBrush
.Ok() == false || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2259 event
.GetDC()->Clear() ;
2263 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2268 int wxWindowMac::GetScrollPos(int orient
) const
2270 if ( orient
== wxHORIZONTAL
)
2273 return m_hScrollBar
->GetThumbPosition() ;
2278 return m_vScrollBar
->GetThumbPosition() ;
2283 // This now returns the whole range, not just the number
2284 // of positions that we can scroll.
2285 int wxWindowMac::GetScrollRange(int orient
) const
2287 if ( orient
== wxHORIZONTAL
)
2290 return m_hScrollBar
->GetRange() ;
2295 return m_vScrollBar
->GetRange() ;
2300 int wxWindowMac::GetScrollThumb(int orient
) const
2302 if ( orient
== wxHORIZONTAL
)
2305 return m_hScrollBar
->GetThumbSize() ;
2310 return m_vScrollBar
->GetThumbSize() ;
2315 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2317 if ( orient
== wxHORIZONTAL
)
2320 m_hScrollBar
->SetThumbPosition( pos
) ;
2325 m_vScrollBar
->SetThumbPosition( pos
) ;
2329 void wxWindowMac::MacPaintBorders( int left
, int top
)
2335 m_peer
->GetRect( &rect
) ;
2336 InsetRect( &rect
, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2338 if ( !IsTopLevel() )
2340 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2344 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2346 rect
.right
+= pt
.x
;
2348 rect
.bottom
+= pt
.y
;
2352 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2356 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
2357 InsetRect( &srect
, border
, border
);
2358 DrawThemeEditTextFrame(&srect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2360 else if (HasFlag(wxSIMPLE_BORDER
))
2364 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
2365 InsetRect( &srect
, border
, border
);
2366 DrawThemeListBoxFrame(&rect
,IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2370 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2372 if ( child
== m_hScrollBar
)
2373 m_hScrollBar
= NULL
;
2374 if ( child
== m_vScrollBar
)
2375 m_vScrollBar
= NULL
;
2377 wxWindowBase::RemoveChild( child
) ;
2380 // New function that will replace some of the above.
2381 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2382 int range
, bool refresh
)
2384 if ( orient
== wxHORIZONTAL
)
2388 if ( range
== 0 || thumbVisible
>= range
)
2390 if ( m_hScrollBar
->IsShown() )
2391 m_hScrollBar
->Show(false) ;
2395 if ( !m_hScrollBar
->IsShown() )
2396 m_hScrollBar
->Show(true) ;
2397 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2405 if ( range
== 0 || thumbVisible
>= range
)
2407 if ( m_vScrollBar
->IsShown() )
2408 m_vScrollBar
->Show(false) ;
2412 if ( !m_vScrollBar
->IsShown() )
2413 m_vScrollBar
->Show(true) ;
2414 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2418 MacRepositionScrollBars() ;
2421 // Does a physical scroll
2422 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2424 if( dx
== 0 && dy
==0 )
2430 int width
, height
;
2431 GetClientSize( &width
, &height
) ;
2432 #if TARGET_API_MAC_OSX
2433 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2434 // area is scrolled, this does not occur if width and height are 2 pixels less,
2435 // TODO write optimal workaround
2436 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2439 scrollrect
.Intersect( *rect
) ;
2441 if ( m_peer
->GetNeedsDisplay() )
2443 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2444 // either immediate redraw or full invalidate
2446 // is the better overall solution, as it does not slow down scrolling
2447 m_peer
->SetNeedsDisplay( true ) ;
2449 // this would be the preferred version for fast drawing controls
2450 if( UMAGetSystemVersion() < 0x1030 )
2453 HIViewRender(m_peer
->GetControlRef()) ;
2456 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2457 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2458 m_peer
->ScrollRect( scrollrect
, dx
, dy
) ;
2465 RgnHandle updateRgn
= NewRgn() ;
2468 wxClientDC
dc(this) ;
2469 wxMacPortSetter
helper(&dc
) ;
2471 m_peer
->GetRect( &scrollrect
) ;
2472 scrollrect
.top
+= MacGetTopBorderSize() ;
2473 scrollrect
.left
+= MacGetLeftBorderSize() ;
2474 scrollrect
.bottom
= scrollrect
.top
+ height
;
2475 scrollrect
.right
= scrollrect
.left
+ width
;
2479 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2480 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2481 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2483 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2485 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
2489 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2491 wxWindowMac
*child
= node
->GetData();
2492 if (child
== m_vScrollBar
) continue;
2493 if (child
== m_hScrollBar
) continue;
2494 if (child
->IsTopLevel()) continue;
2497 child
->GetPosition( &x
, &y
);
2499 child
->GetSize( &w
, &h
);
2503 if (rect
->Intersects(rc
))
2504 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2508 child
->SetSize( x
+dx
, y
+dy
, w
, h
);
2513 void wxWindowMac::MacOnScroll(wxScrollEvent
&event
)
2515 if ( event
.m_eventObject
== m_vScrollBar
|| event
.m_eventObject
== m_hScrollBar
)
2517 wxScrollWinEvent wevent
;
2518 wevent
.SetPosition(event
.GetPosition());
2519 wevent
.SetOrientation(event
.GetOrientation());
2520 wevent
.m_eventObject
= this;
2522 if (event
.m_eventType
== wxEVT_SCROLL_TOP
)
2523 wevent
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
2524 else if (event
.m_eventType
== wxEVT_SCROLL_BOTTOM
)
2525 wevent
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2526 else if (event
.m_eventType
== wxEVT_SCROLL_LINEUP
)
2527 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
2528 else if (event
.m_eventType
== wxEVT_SCROLL_LINEDOWN
)
2529 wevent
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2530 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEUP
)
2531 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2532 else if (event
.m_eventType
== wxEVT_SCROLL_PAGEDOWN
)
2533 wevent
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2534 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBTRACK
)
2535 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2536 else if (event
.m_eventType
== wxEVT_SCROLL_THUMBRELEASE
)
2537 wevent
.m_eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2539 GetEventHandler()->ProcessEvent(wevent
);
2543 // Get the window with the focus
2544 wxWindowMac
*wxWindowBase::DoFindFocus()
2546 ControlRef control
;
2547 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2548 return wxFindControlFromMacControl( control
) ;
2551 void wxWindowMac::OnSetFocus(wxFocusEvent
& event
)
2553 // panel wants to track the window which was the last to have focus in it,
2554 // so we want to set ourselves as the window which last had focus
2556 // notice that it's also important to do it upwards the tree becaus
2557 // otherwise when the top level panel gets focus, it won't set it back to
2558 // us, but to some other sibling
2560 // CS:don't know if this is still needed:
2561 //wxChildFocusEvent eventFocus(this);
2562 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2564 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2566 wxMacWindowStateSaver
sv( this ) ;
2571 MacWindowToRootWindow( &x
, &y
) ;
2572 GetSize( &w
, &h
) ;
2573 Rect rect
= {y
, x
, h
+ y
, w
+ x
} ;
2575 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2576 DrawThemeFocusRect( &rect
, true ) ;
2579 DrawThemeFocusRect( &rect
, false ) ;
2581 // as this erases part of the frame we have to redraw borders
2582 // and because our z-ordering is not always correct (staticboxes)
2583 // we have to invalidate things, we cannot simple redraw
2584 RgnHandle updateInner
= NewRgn() , updateOuter
= NewRgn() ;
2585 RectRgn( updateInner
, &rect
) ;
2586 InsetRect( &rect
, -4 , -4 ) ;
2587 RectRgn( updateOuter
, &rect
) ;
2588 DiffRgn( updateOuter
, updateInner
,updateOuter
) ;
2589 wxPoint
parent(0,0);
2590 GetParent()->MacWindowToRootWindow( &parent
.x
, &parent
.y
) ;
2591 parent
-= GetParent()->GetClientAreaOrigin() ;
2592 OffsetRgn( updateOuter
, -parent
.x
, -parent
.y
) ;
2593 GetParent()->m_peer
->SetNeedsDisplay( true , updateOuter
) ;
2594 DisposeRgn(updateOuter
) ;
2595 DisposeRgn(updateInner
) ;
2602 void wxWindowMac::OnInternalIdle()
2604 // This calls the UI-update mechanism (querying windows for
2605 // menu/toolbar/control state information)
2606 if (wxUpdateUIEvent::CanUpdate(this))
2607 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2610 // Raise the window to the top of the Z order
2611 void wxWindowMac::Raise()
2613 m_peer
->SetZOrder( true , NULL
) ;
2616 // Lower the window to the bottom of the Z order
2617 void wxWindowMac::Lower()
2619 m_peer
->SetZOrder( false , NULL
) ;
2623 // static wxWindow *gs_lastWhich = NULL;
2625 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2627 // first trigger a set cursor event
2629 wxPoint clientorigin
= GetClientAreaOrigin() ;
2630 wxSize clientsize
= GetClientSize() ;
2632 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2634 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2636 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2637 if ( processedEvtSetCursor
&& event
.HasCursor() )
2639 cursor
= event
.GetCursor() ;
2644 // the test for processedEvtSetCursor is here to prevent using m_cursor
2645 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2646 // it - this is a way to say that our cursor shouldn't be used for this
2648 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2658 cursor
= *wxSTANDARD_CURSOR
;
2662 cursor
.MacInstall() ;
2664 return cursor
.Ok() ;
2667 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2671 return m_tooltip
->GetTip() ;
2673 return wxEmptyString
;
2676 void wxWindowMac::Update()
2678 #if TARGET_API_MAC_OSX
2680 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2681 WindowRef window
= (WindowRef
)MacGetTopLevelWindowRef() ;
2683 // for composited windows this also triggers a redraw of all
2684 // invalid views in the window
2685 if( UMAGetSystemVersion() >= 0x1030 )
2686 HIWindowFlush(window
) ;
2690 // the only way to trigger the redrawing on earlier systems is to call
2693 EventRef currentEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
2694 UInt32 currentEventClass
= 0 ;
2695 UInt32 currentEventKind
= 0 ;
2696 if ( currentEvent
!= NULL
)
2698 currentEventClass
= ::GetEventClass( currentEvent
) ;
2699 currentEventKind
= ::GetEventKind( currentEvent
) ;
2701 if ( currentEventClass
!= kEventClassMenu
)
2703 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2706 OSStatus status
= noErr
;
2707 status
= ReceiveNextEvent( 0 , NULL
, kEventDurationNoWait
, false , &theEvent
) ;
2710 m_peer
->SetNeedsDisplay( true ) ;
2713 ::Draw1Control( m_peer
->GetControlRef() ) ;
2717 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2719 wxTopLevelWindowMac
* win
= NULL
;
2720 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2723 win
= wxFindWinFromMacWindow( window
) ;
2727 wxRegion
wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2729 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2730 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2731 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2732 // to add focus borders everywhere
2735 RgnHandle visRgn
= NewRgn() ;
2736 RgnHandle tempRgn
= NewRgn() ;
2737 if ( !m_isBeingDeleted
&& m_peer
->IsVisible())
2739 m_peer
->GetRect( &r
) ;
2740 r
.left
-= MacGetLeftBorderSize() ;
2741 r
.top
-= MacGetTopBorderSize() ;
2742 r
.bottom
+= MacGetBottomBorderSize() ;
2743 r
.right
+= MacGetRightBorderSize() ;
2745 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
2747 MacRootWindowToWindow( &r
.left
, & r
.top
) ;
2748 MacRootWindowToWindow( &r
.right
, & r
.bottom
) ;
2757 if ( includeOuterStructures
)
2758 InsetRect( &r
, -4 , -4 ) ;
2759 RectRgn( visRgn
, &r
) ;
2761 if ( !IsTopLevel() )
2763 wxWindow
* child
= this ;
2764 wxWindow
* parent
= child
->GetParent() ;
2769 // we have to find a better clipping algorithm here, in order not to clip things
2770 // positioned like status and toolbar
2771 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
2773 size
= parent
->GetSize() ;
2778 size
= parent
->GetClientSize() ;
2779 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2783 parent
->MacWindowToRootWindow( &x
, &y
) ;
2784 MacRootWindowToWindow( &x
, &y
) ;
2786 if ( !includeOuterStructures
|| (
2787 parent
->MacClipChildren() ||
2788 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() )
2791 SetRectRgn( tempRgn
,
2792 x
+ parent
->MacGetLeftBorderSize() , y
+ parent
->MacGetTopBorderSize() ,
2793 x
+ size
.x
- parent
->MacGetRightBorderSize(),
2794 y
+ size
.y
- parent
->MacGetBottomBorderSize()) ;
2796 SectRgn( visRgn
, tempRgn
, visRgn
) ;
2798 if ( parent
->IsTopLevel() )
2801 parent
= child
->GetParent() ;
2806 wxRegion vis
= visRgn
;
2807 DisposeRgn( visRgn
) ;
2808 DisposeRgn( tempRgn
) ;
2813 This function must not change the updatergn !
2815 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2817 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2818 bool handled
= false ;
2820 GetRegionBounds( updatergn
, &updatebounds
) ;
2821 // wxLogDebug("update for %s bounds %d , %d , %d , %d",typeid(*this).name() , updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2822 if ( !EmptyRgn(updatergn
) )
2824 RgnHandle newupdate
= NewRgn() ;
2825 wxSize point
= GetClientSize() ;
2826 wxPoint origin
= GetClientAreaOrigin() ;
2827 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+point
.y
) ;
2828 SectRgn( newupdate
, updatergn
, newupdate
) ;
2830 // first send an erase event to the entire update area
2832 wxWindowDC
dc(this);
2833 dc
.SetClippingRegion(wxRegion(updatergn
));
2834 wxEraseEvent
eevent( GetId(), &dc
);
2835 eevent
.SetEventObject( this );
2836 GetEventHandler()->ProcessEvent( eevent
);
2839 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2840 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2841 m_updateRegion
= newupdate
;
2842 DisposeRgn( newupdate
) ;
2844 if ( !m_updateRegion
.Empty() )
2846 // paint the window itself
2848 event
.m_timeStamp
= time
;
2849 event
.SetEventObject(this);
2850 handled
= GetEventHandler()->ProcessEvent(event
);
2852 // we have to call the default built-in handler, as otherwise our frames will be drawn and immediately erased afterwards
2855 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
2857 CallNextEventHandler((EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() , (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
2864 // now we cannot rely on having its borders drawn by a window itself, as it does not
2865 // get the updateRgn wide enough to always do so, so we do it from the parent
2866 // this would also be the place to draw any custom backgrounds for native controls
2867 // in Composited windowing
2868 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2870 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2872 wxWindowMac
*child
= node
->GetData();
2873 if (child
== m_vScrollBar
) continue;
2874 if (child
== m_hScrollBar
) continue;
2875 if (child
->IsTopLevel()) continue;
2876 if (!child
->IsShown()) continue;
2879 child
->GetPosition( &x
, &y
);
2881 child
->GetSize( &w
, &h
);
2882 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2883 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2884 if ( child
->MacGetTopBorderSize() )
2886 if ( RectInRgn( &childRect
, updatergn
) )
2888 // paint custom borders
2889 wxNcPaintEvent
eventNc( child
->GetId() );
2890 eventNc
.SetEventObject( child
);
2891 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
2893 wxWindowDC
dc(this) ;
2894 dc
.SetClippingRegion(wxRegion(updatergn
));
2895 wxMacPortSetter
helper(&dc
) ;
2896 child
->MacPaintBorders( dc
.m_macLocalOrigin
.x
+ childRect
.left
, dc
.m_macLocalOrigin
.y
+ childRect
.top
) ;
2900 if ( child
->m_peer
->NeedsFocusRect() && child
->m_peer
->HasFocus() )
2902 wxWindowDC
dc(this) ;
2903 dc
.SetClippingRegion(wxRegion(updatergn
));
2904 wxMacPortSetter
helper(&dc
) ;
2905 Rect r
= childRect
;
2906 OffsetRect( &r
, dc
.m_macLocalOrigin
.x
, dc
.m_macLocalOrigin
.y
) ;
2907 DrawThemeFocusRect( &r
, true ) ;
2914 void wxWindowMac::MacRedraw( WXHRGN updatergnr
, long time
, bool erase
)
2916 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2917 // updatergn is always already clipped to our boundaries
2918 // if we are in compositing mode then it is in relative to the upper left of the control
2919 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2920 // of the toplevel window
2921 // it is in window coordinates, not in client coordinates
2923 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2924 RgnHandle ownUpdateRgn
= NewRgn() ;
2925 CopyRgn( updatergn
, ownUpdateRgn
) ;
2927 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2930 m_peer
->GetRectInWindowCoords( &bounds
);
2931 RgnHandle controlRgn
= NewRgn();
2932 RectRgn( controlRgn
, &bounds
);
2933 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2934 // the window update region
2935 SectRgn( ownUpdateRgn
, controlRgn
, ownUpdateRgn
);
2936 DisposeRgn( controlRgn
);
2938 //KO: convert ownUpdateRgn to local coordinates
2939 OffsetRgn( ownUpdateRgn
, -bounds
.left
, -bounds
.top
);
2942 MacDoRedraw( ownUpdateRgn
, time
) ;
2943 DisposeRgn( ownUpdateRgn
) ;
2947 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
2949 wxWindowMac
*iter
= (wxWindowMac
*)this ;
2953 if ( iter
->IsTopLevel() )
2954 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
2956 iter
= iter
->GetParent() ;
2958 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
2962 void wxWindowMac::MacCreateScrollBars( long style
)
2964 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
2966 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
2968 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
2969 int scrlsize
= MAC_SCROLLBAR_SIZE
;
2970 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
2971 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
2973 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
2974 variant
= wxWINDOW_VARIANT_SMALL
;
2977 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
2979 GetClientSize( &width
, &height
) ;
2981 wxPoint
vPoint(width
-scrlsize
, 0) ;
2982 wxSize
vSize(scrlsize
, height
- adjust
) ;
2983 wxPoint
hPoint(0 , height
-scrlsize
) ;
2984 wxSize
hSize( width
- adjust
, scrlsize
) ;
2987 if ( style
& wxVSCROLL
)
2989 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
,
2990 vSize
, wxVERTICAL
);
2993 if ( style
& wxHSCROLL
)
2995 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
,
2996 hSize
, wxHORIZONTAL
);
3001 // because the create does not take into account the client area origin
3002 MacRepositionScrollBars() ; // we might have a real position shift
3005 void wxWindowMac::MacRepositionScrollBars()
3007 if ( !m_hScrollBar
&& !m_vScrollBar
)
3010 bool hasBoth
= ( m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3011 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3012 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3014 // get real client area
3018 GetSize( &width
, &height
) ;
3020 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3021 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3023 wxPoint
vPoint(width
-MAC_SCROLLBAR_SIZE
, 0) ;
3024 wxSize
vSize(MAC_SCROLLBAR_SIZE
, height
- adjust
) ;
3025 wxPoint
hPoint(0 , height
-MAC_SCROLLBAR_SIZE
) ;
3026 wxSize
hSize( width
- adjust
, MAC_SCROLLBAR_SIZE
) ;
3032 GetSize( &w , &h ) ;
3034 MacClientToRootWindow( &x , &y ) ;
3035 MacClientToRootWindow( &w , &h ) ;
3037 wxWindowMac *iter = (wxWindowMac*)this ;
3039 int totW = 10000 , totH = 10000;
3042 if ( iter->IsTopLevel() )
3044 iter->GetSize( &totW , &totH ) ;
3048 iter = iter->GetParent() ;
3076 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3080 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3084 bool wxWindowMac::AcceptsFocus() const
3086 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3089 void wxWindowMac::MacSuperChangedPosition()
3091 // only window-absolute structures have to be moved i.e. controls
3093 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3096 wxWindowMac
*child
= node
->GetData();
3097 child
->MacSuperChangedPosition() ;
3098 node
= node
->GetNext();
3102 void wxWindowMac::MacTopLevelWindowChangedPosition()
3104 // only screen-absolute structures have to be moved i.e. glcanvas
3106 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3109 wxWindowMac
*child
= node
->GetData();
3110 child
->MacTopLevelWindowChangedPosition() ;
3111 node
= node
->GetNext();
3115 long wxWindowMac::MacGetLeftBorderSize( ) const
3120 if (m_windowStyle
& wxRAISED_BORDER
|| m_windowStyle
& wxSUNKEN_BORDER
)
3125 else if ( m_windowStyle
&wxDOUBLE_BORDER
)
3130 else if (m_windowStyle
&wxSIMPLE_BORDER
)
3137 long wxWindowMac::MacGetRightBorderSize( ) const
3139 // they are all symmetric in mac themes
3140 return MacGetLeftBorderSize() ;
3143 long wxWindowMac::MacGetTopBorderSize( ) const
3145 // they are all symmetric in mac themes
3146 return MacGetLeftBorderSize() ;
3149 long wxWindowMac::MacGetBottomBorderSize( ) const
3151 // they are all symmetric in mac themes
3152 return MacGetLeftBorderSize() ;
3155 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3157 return style
& ~wxBORDER_MASK
;
3160 // Find the wxWindowMac at the current mouse position, returning the mouse
3162 wxWindowMac
* wxFindWindowAtPointer(wxPoint
& pt
)
3164 pt
= wxGetMousePosition();
3165 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3169 // Get the current mouse position.
3170 wxPoint
wxGetMousePosition()
3173 wxGetMousePosition(& x
, & y
);
3174 return wxPoint(x
, y
);
3177 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3179 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3181 // copied from wxGTK : CS
3182 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3185 // (a) it's a command event and so is propagated to the parent
3186 // (b) under MSW it can be generated from kbd too
3187 // (c) it uses screen coords (because of (a))
3188 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3190 this->ClientToScreen(event
.GetPosition()));
3191 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3200 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3204 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3208 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3209 Rect bounds
= { y
, x
, y
+h
, x
+w
};
3213 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3215 return eventNotHandledErr
;