1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/window.h"
17 #include "wx/dcclient.h"
21 #include "wx/layout.h"
22 #include "wx/dialog.h"
23 #include "wx/scrolbar.h"
24 #include "wx/statbox.h"
25 #include "wx/button.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
29 #include "wx/tooltip.h"
30 #include "wx/statusbr.h"
31 #include "wx/menuitem.h"
32 #include "wx/spinctrl.h"
34 #include "wx/geometry.h"
35 #include "wx/textctrl.h"
37 #include "wx/toolbar.h"
44 #define MAC_SCROLLBAR_SIZE 15
45 #define MAC_SMALL_SCROLLBAR_SIZE 11
47 #include "wx/mac/uma.h"
51 #include <ToolUtils.h>
53 #include <MacTextEditor.h>
56 #if TARGET_API_MAC_OSX
58 #include <HIToolbox/HIView.h>
62 #if wxUSE_DRAG_AND_DROP
68 extern wxList wxPendingDelete
;
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
76 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
77 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
78 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
79 #if TARGET_API_MAC_OSX
80 EVT_PAINT(wxWindowMac::OnPaint
)
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 #define wxMAC_USE_THEME_BORDER 1
94 // ---------------------------------------------------------------------------
95 // Utility Routines to move between different coordinate systems
96 // ---------------------------------------------------------------------------
99 * Right now we have the following setup :
100 * a border that is not part of the native control is always outside the
101 * control's border (otherwise we loose all native intelligence, future ways
102 * may be to have a second embedding control responsible for drawing borders
103 * and backgrounds eventually)
104 * so all this border calculations have to be taken into account when calling
105 * native methods or getting native oriented data
106 * so we have three coordinate systems here
107 * wx client coordinates
108 * wx window coordinates (including window frames)
113 // originating from native control
117 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
119 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
122 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
124 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
128 // directed towards native control
131 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
133 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
136 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
138 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
146 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
148 #if TARGET_API_MAC_OSX
150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
153 kEventControlVisibilityChanged
= 157
159 static const EventTypeSpec eventList
[] =
161 { kEventClassControl
, kEventControlHit
} ,
163 #if TARGET_API_MAC_OSX
164 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
165 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
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() ;
203 if ( ! thisWindow
->GetPeer()->IsCompositing() )
205 if ( thisWindow
->GetPeer()->IsRootControl() )
206 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
208 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
211 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
213 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
217 if ( ! thisWindow
->GetPeer()->IsCompositing() )
219 allocatedRgn
= NewRgn() ;
220 CopyRgn( updateRgn
, allocatedRgn
) ;
221 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
223 // hide the given region by the new region that must be shifted
224 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
225 updateRgn
= allocatedRgn
;
229 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
231 // as this update region is in native window locals we must adapt it to wx window local
232 allocatedRgn
= NewRgn() ;
233 CopyRgn( updateRgn
, allocatedRgn
) ;
235 // hide the given region by the new region that must be shifted
236 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
237 updateRgn
= allocatedRgn
;
243 GetRegionBounds( updateRgn
, &rgnBounds
) ;
245 #if wxMAC_DEBUG_REDRAW
246 if ( thisWindow
->MacIsUserPane() )
248 static float color
= 0.5 ;
251 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
253 HIViewGetBounds( controlRef
, &bounds
);
254 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
255 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
256 CGContextFillRect( cgContext
, bounds
);
269 #if wxMAC_USE_CORE_GRAPHICS
270 bool created
= false ;
271 CGContextRef cgContext
= NULL
;
272 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
274 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
276 // this parameter is not provided on non-composited windows
279 // rest of the code expects this to be already transformed and clipped for local
280 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
282 GetPortBounds( port
, &bounds
) ;
283 CreateCGContextForPort( port
, &cgContext
) ;
285 wxMacWindowToNative( thisWindow
, updateRgn
) ;
286 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
287 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
288 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
289 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
291 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
292 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
294 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
297 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
298 CGContextFillRect( cgContext
,
300 controlBounds
.right
- controlBounds
.left
,
301 controlBounds
.bottom
- controlBounds
.top
) );
305 thisWindow
->MacSetCGContextRef( cgContext
) ;
308 wxMacCGContextStateSaver
sg( cgContext
) ;
310 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
313 #if wxMAC_USE_CORE_GRAPHICS
314 thisWindow
->MacSetCGContextRef( NULL
) ;
318 CGContextRelease( cgContext
) ;
323 DisposeRgn( allocatedRgn
) ;
327 case kEventControlVisibilityChanged
:
328 thisWindow
->MacVisibilityChanged() ;
331 case kEventControlEnabledStateChanged
:
332 thisWindow
->MacEnabledStateChanged() ;
335 case kEventControlHiliteChanged
:
336 thisWindow
->MacHiliteChanged() ;
340 // we emulate this event under Carbon CFM
341 case kEventControlSetFocusPart
:
343 Boolean focusEverything
= false ;
344 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
347 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
352 if ( controlPart
== kControlFocusNoPart
)
355 if ( thisWindow
->GetCaret() )
356 thisWindow
->GetCaret()->OnKillFocus();
359 static bool inKillFocusEvent
= false ;
361 if ( !inKillFocusEvent
)
363 inKillFocusEvent
= true ;
364 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
365 event
.SetEventObject(thisWindow
);
366 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
367 inKillFocusEvent
= false ;
372 // panel wants to track the window which was the last to have focus in it
373 wxChildFocusEvent
eventFocus(thisWindow
);
374 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
377 if ( thisWindow
->GetCaret() )
378 thisWindow
->GetCaret()->OnSetFocus();
381 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
382 event
.SetEventObject(thisWindow
);
383 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
386 if ( thisWindow
->MacIsUserPane() )
391 case kEventControlHit
:
392 result
= thisWindow
->MacControlHit( handler
, event
) ;
402 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
404 OSStatus result
= eventNotHandledErr
;
406 wxMacCarbonEvent
cEvent( event
) ;
408 ControlRef controlRef
;
409 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
410 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
411 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
413 switch ( GetEventKind( event
) )
415 case kEventServiceGetTypes
:
419 textCtrl
->GetSelection( &from
, &to
) ;
421 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
423 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
424 if ( textCtrl
->IsEditable() )
425 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
427 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
428 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
430 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
434 CFArrayAppendValue(copyTypes
, typestring
) ;
436 CFArrayAppendValue(pasteTypes
, typestring
) ;
438 CFRelease( typestring
) ;
446 case kEventServiceCopy
:
451 textCtrl
->GetSelection( &from
, &to
) ;
452 wxString val
= textCtrl
->GetValue() ;
453 val
= val
.Mid( from
, to
- from
) ;
454 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
455 verify_noerr( ClearScrap( &scrapRef
) ) ;
456 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
461 case kEventServicePaste
:
464 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
465 Size textSize
, pastedSize
;
466 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
468 char *content
= new char[textSize
] ;
469 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
470 content
[textSize
- 1] = 0 ;
473 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
475 textCtrl
->WriteText( wxString( content
) ) ;
490 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
492 OSStatus result
= eventNotHandledErr
;
493 wxWindowMac
* focus
= (wxWindowMac
*) data
;
495 wchar_t* uniChars
= NULL
;
496 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
499 UInt32 dataSize
= 0 ;
502 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
504 numChars
= dataSize
/ sizeof( UniChar
) ;
507 if ( dataSize
> sizeof(buf
) )
508 charBuf
= new UniChar
[ numChars
] ;
512 uniChars
= new wchar_t[ numChars
] ;
513 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
514 #if SIZEOF_WCHAR_T == 2
516 memcpy( uniChars
, charBuf
, dataSize
) ;
518 // the resulting string will never have more chars than the utf16 version, so this is safe
519 wxMBConvUTF16 converter
;
520 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
524 switch ( GetEventKind( event
) )
526 case kEventTextInputUpdateActiveInputArea
:
528 // An IME input event may return several characters, but we need to send one char at a time to
530 for (int pos
=0 ; pos
< numChars
; pos
++)
533 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
534 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
535 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
537 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
538 if ( wxTheApp
->MacSendCharEvent(
539 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
544 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
548 case kEventTextInputUnicodeForKeyEvent
:
550 UInt32 keyCode
, modifiers
;
553 unsigned char charCode
;
555 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
556 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
557 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
558 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
559 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
561 UInt32 message
= (keyCode
<< 8) + charCode
;
563 // An IME input event may return several characters, but we need to send one char at a time to
565 for (int pos
=0 ; pos
< numChars
; pos
++)
568 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
569 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
570 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
572 if ( wxTheApp
->MacSendCharEvent(
573 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
578 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
587 if ( charBuf
!= buf
)
594 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
596 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
597 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
598 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
599 OSStatus result
= eventNotHandledErr
;
601 switch ( GetEventClass( event
) )
603 case kEventClassControl
:
604 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
607 case kEventClassService
:
608 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
611 case kEventClassTextInput
:
612 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
618 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
623 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
625 #if !TARGET_API_MAC_OSX
627 // ---------------------------------------------------------------------------
628 // UserPane events for non OSX builds
629 // ---------------------------------------------------------------------------
631 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
633 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
635 win
->MacControlUserPaneDrawProc(part
) ;
637 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
639 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
641 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
643 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
645 return kControlNoPart
;
647 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
649 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
651 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
653 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
655 return kControlNoPart
;
657 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
659 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
661 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
663 win
->MacControlUserPaneIdleProc() ;
665 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
667 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
669 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
671 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
673 return kControlNoPart
;
675 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
677 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
679 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
681 win
->MacControlUserPaneActivateProc(activating
) ;
683 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
685 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
687 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
689 return win
->MacControlUserPaneFocusProc(action
) ;
691 return kControlNoPart
;
693 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
695 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
697 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
699 win
->MacControlUserPaneBackgroundProc(info
) ;
701 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
703 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
706 RgnHandle rgn
= NewRgn() ;
708 MacWindowToRootWindow( &x
, &y
) ;
709 OffsetRgn( rgn
, -x
, -y
) ;
710 wxMacWindowStateSaver
sv( this ) ;
711 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
712 MacDoRedraw( rgn
, 0 ) ;
716 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
718 return kControlNoPart
;
721 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
723 return kControlNoPart
;
726 void wxWindowMac::MacControlUserPaneIdleProc()
730 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
732 return kControlNoPart
;
735 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
739 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
741 if ( AcceptsFocus() )
744 return kControlNoPart
;
747 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
753 // ---------------------------------------------------------------------------
754 // Scrollbar Tracking for all
755 // ---------------------------------------------------------------------------
757 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
758 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
762 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
764 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
767 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
769 // ===========================================================================
771 // ===========================================================================
773 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
775 static MacControlMap wxWinMacControlList
;
777 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
779 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
781 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
784 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
786 // adding NULL ControlRef is (first) surely a result of an error and
787 // (secondly) breaks native event processing
788 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
790 wxWinMacControlList
[inControl
] = control
;
793 void wxRemoveMacControlAssociation(wxWindow
*control
)
795 // iterate over all the elements in the class
796 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
797 // we should go on...
803 MacControlMap::iterator it
;
804 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
806 if ( it
->second
== control
)
808 wxWinMacControlList
.erase(it
);
816 // ----------------------------------------------------------------------------
817 // constructors and such
818 // ----------------------------------------------------------------------------
820 wxWindowMac::wxWindowMac()
825 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
830 const wxString
& name
)
833 Create(parent
, id
, pos
, size
, style
, name
);
836 void wxWindowMac::Init()
841 #if WXWIN_COMPATIBILITY_2_4
842 m_backgroundTransparent
= false;
845 #if wxMAC_USE_CORE_GRAPHICS
846 m_cgContextRef
= NULL
;
849 // as all windows are created with WS_VISIBLE style...
852 m_hScrollBar
= NULL
;
853 m_vScrollBar
= NULL
;
854 m_macBackgroundBrush
= wxNullBrush
;
856 m_macIsUserPane
= true;
857 m_clipChildren
= false ;
858 m_cachedClippedRectValid
= false ;
860 // we need a valid font for the encodings
861 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
865 wxWindowMac::~wxWindowMac()
869 m_isBeingDeleted
= true;
871 MacInvalidateBorders() ;
873 #ifndef __WXUNIVERSAL__
874 // VS: make sure there's no wxFrame with last focus set to us:
875 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
877 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
880 if ( frame
->GetLastFocus() == this )
881 frame
->SetLastFocus((wxWindow
*)NULL
);
885 #endif // __WXUNIVERSAL__
887 // destroy children before destroying this window itself
890 // wxRemoveMacControlAssociation( this ) ;
891 // If we delete an item, we should initialize the parent panel,
892 // because it could now be invalid.
893 wxWindow
*parent
= GetParent() ;
896 if (parent
->GetDefaultItem() == (wxButton
*) this)
897 parent
->SetDefaultItem(NULL
);
900 if ( m_peer
&& m_peer
->Ok() )
902 // in case the callback might be called during destruction
903 wxRemoveMacControlAssociation( this) ;
904 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
905 // we currently are not using this hook
906 // ::SetControlColorProc( *m_peer , NULL ) ;
910 if ( g_MacLastWindow
== this )
911 g_MacLastWindow
= NULL
;
913 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
916 if ( frame
->GetLastFocus() == this )
917 frame
->SetLastFocus( NULL
) ;
920 // delete our drop target if we've got one
921 #if wxUSE_DRAG_AND_DROP
922 if ( m_dropTarget
!= NULL
)
932 WXWidget
wxWindowMac::GetHandle() const
934 return (WXWidget
) m_peer
->GetControlRef() ;
937 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
939 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
940 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
941 GetEventTypeCount(eventList
), eventList
, this,
942 (EventHandlerRef
*)&m_macControlEventHandler
);
944 #if !TARGET_API_MAC_OSX
945 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
947 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
948 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
949 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
950 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
951 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
952 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
953 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
954 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
960 bool wxWindowMac::Create(wxWindowMac
*parent
,
965 const wxString
& name
)
967 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
969 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
972 m_windowVariant
= parent
->GetWindowVariant() ;
974 if ( m_macIsUserPane
)
976 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
979 | kControlSupportsEmbedding
980 | kControlSupportsLiveFeedback
981 | kControlGetsFocusOnClick
982 // | kControlHasSpecialBackground
983 // | kControlSupportsCalcBestRect
984 | kControlHandlesTracking
985 | kControlSupportsFocus
986 | kControlWantsActivate
987 | kControlWantsIdle
;
989 m_peer
= new wxMacControl(this) ;
990 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
993 MacPostControlCreate(pos
, size
) ;
996 #ifndef __WXUNIVERSAL__
997 // Don't give scrollbars to wxControls unless they ask for them
998 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
999 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1001 MacCreateScrollBars( style
) ;
1005 wxWindowCreateEvent
event(this);
1006 GetEventHandler()->AddPendingEvent(event
);
1011 void wxWindowMac::MacChildAdded()
1014 m_vScrollBar
->Raise() ;
1016 m_hScrollBar
->Raise() ;
1019 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1021 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1023 m_peer
->SetReference( (long)this ) ;
1024 GetParent()->AddChild( this );
1026 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1028 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1029 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1030 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1031 GetParent()->MacChildAdded() ;
1033 // adjust font, controlsize etc
1034 DoSetWindowVariant( m_windowVariant
) ;
1036 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
1038 if (!m_macIsUserPane
)
1039 SetInitialBestSize(size
);
1041 SetCursor( *wxSTANDARD_CURSOR
) ;
1044 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1046 // Don't assert, in case we set the window variant before
1047 // the window is created
1048 // wxASSERT( m_peer->Ok() ) ;
1050 m_windowVariant
= variant
;
1052 if (m_peer
== NULL
|| !m_peer
->Ok())
1056 ThemeFontID themeFont
= kThemeSystemFont
;
1058 // we will get that from the settings later
1059 // and make this NORMAL later, but first
1060 // we have a few calculations that we must fix
1064 case wxWINDOW_VARIANT_NORMAL
:
1065 size
= kControlSizeNormal
;
1066 themeFont
= kThemeSystemFont
;
1069 case wxWINDOW_VARIANT_SMALL
:
1070 size
= kControlSizeSmall
;
1071 themeFont
= kThemeSmallSystemFont
;
1074 case wxWINDOW_VARIANT_MINI
:
1075 if (UMAGetSystemVersion() >= 0x1030 )
1077 // not always defined in the headers
1083 size
= kControlSizeSmall
;
1084 themeFont
= kThemeSmallSystemFont
;
1088 case wxWINDOW_VARIANT_LARGE
:
1089 size
= kControlSizeLarge
;
1090 themeFont
= kThemeSystemFont
;
1094 wxFAIL_MSG(_T("unexpected window variant"));
1098 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1101 font
.MacCreateThemeFont( themeFont
) ;
1105 void wxWindowMac::MacUpdateControlFont()
1107 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1111 bool wxWindowMac::SetFont(const wxFont
& font
)
1113 bool retval
= wxWindowBase::SetFont( font
);
1115 MacUpdateControlFont() ;
1120 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1122 bool retval
= wxWindowBase::SetForegroundColour( col
);
1125 MacUpdateControlFont();
1130 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1132 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1136 wxColour
newCol(GetBackgroundColour());
1138 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1139 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1140 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1141 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1143 brush
.SetColour( newCol
) ;
1145 MacSetBackgroundBrush( brush
) ;
1146 MacUpdateControlFont() ;
1151 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1153 m_macBackgroundBrush
= brush
;
1154 m_peer
->SetBackground( brush
) ;
1157 bool wxWindowMac::MacCanFocus() const
1159 // there is currently no way to determine whether the window is running in full keyboard
1160 // access mode, therefore we cannot rely on these features, yet the only other way would be
1161 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1162 // in event handlers...
1163 UInt32 features
= 0 ;
1164 m_peer
->GetFeatures( &features
) ;
1166 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1169 void wxWindowMac::SetFocus()
1171 if ( !AcceptsFocus() )
1174 wxWindow
* former
= FindFocus() ;
1175 if ( former
== this )
1178 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1179 // we can only leave in case of an error
1180 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1181 if ( err
== errCouldntSetFocus
)
1184 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1186 #if !TARGET_API_MAC_OSX
1187 // emulate carbon events when running under CarbonLib where they are not natively available
1190 EventRef evRef
= NULL
;
1192 err
= MacCreateEvent(
1193 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1194 kEventAttributeUserEvent
, &evRef
);
1195 verify_noerr( err
);
1197 wxMacCarbonEvent
cEvent( evRef
) ;
1198 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1199 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1201 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1202 ReleaseEvent( evRef
) ;
1205 // send new focus event
1207 EventRef evRef
= NULL
;
1209 err
= MacCreateEvent(
1210 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1211 kEventAttributeUserEvent
, &evRef
);
1212 verify_noerr( err
);
1214 wxMacCarbonEvent
cEvent( evRef
) ;
1215 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1216 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1218 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1219 ReleaseEvent( evRef
) ;
1224 void wxWindowMac::DoCaptureMouse()
1226 wxApp::s_captureWindow
= this ;
1229 wxWindow
* wxWindowBase::GetCapture()
1231 return wxApp::s_captureWindow
;
1234 void wxWindowMac::DoReleaseMouse()
1236 wxApp::s_captureWindow
= NULL
;
1239 #if wxUSE_DRAG_AND_DROP
1241 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1243 if ( m_dropTarget
!= NULL
)
1244 delete m_dropTarget
;
1246 m_dropTarget
= pDropTarget
;
1247 if ( m_dropTarget
!= NULL
)
1255 // Old style file-manager drag&drop
1256 void wxWindowMac::DragAcceptFiles(bool accept
)
1261 // Returns the size of the native control. In the case of the toplevel window
1262 // this is the content area root control
1264 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1265 int& w
, int& h
) const
1267 wxFAIL_MSG( wxT("Not currently supported") ) ;
1270 // From a wx position / size calculate the appropriate size of the native control
1272 bool wxWindowMac::MacGetBoundsForControl(
1276 int& w
, int& h
, bool adjustOrigin
) const
1278 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1280 // the desired size, minus the border pixels gives the correct size of the control
1285 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1286 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1287 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1289 if ( !isCompositing
)
1290 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1292 x
+= MacGetLeftBorderSize() ;
1293 y
+= MacGetTopBorderSize() ;
1294 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1295 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1298 AdjustForParentClientOrigin( x
, y
) ;
1300 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1301 if ( !GetParent()->IsTopLevel() )
1303 x
-= GetParent()->MacGetLeftBorderSize() ;
1304 y
-= GetParent()->MacGetTopBorderSize() ;
1310 // Get window size (not client size)
1311 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1314 m_peer
->GetRect( &bounds
) ;
1317 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1319 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1322 // get the position of the bounds of this window in client coordinates of its parent
1323 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1326 m_peer
->GetRect( &bounds
) ;
1328 int x1
= bounds
.left
;
1329 int y1
= bounds
.top
;
1331 // get the wx window position from the native one
1332 x1
-= MacGetLeftBorderSize() ;
1333 y1
-= MacGetTopBorderSize() ;
1335 if ( !IsTopLevel() )
1337 wxWindow
*parent
= GetParent();
1340 // we must first adjust it to be in window coordinates of the parent,
1341 // as otherwise it gets lost by the ClientAreaOrigin fix
1342 x1
+= parent
->MacGetLeftBorderSize() ;
1343 y1
+= parent
->MacGetTopBorderSize() ;
1345 // and now to client coordinates
1346 wxPoint
pt(parent
->GetClientAreaOrigin());
1358 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1360 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1361 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1363 Point localwhere
= { 0, 0 } ;
1370 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1377 MacRootWindowToWindow( x
, y
) ;
1379 wxPoint origin
= GetClientAreaOrigin() ;
1386 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1388 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1389 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1391 wxPoint origin
= GetClientAreaOrigin() ;
1397 MacWindowToRootWindow( x
, y
) ;
1399 Point localwhere
= { 0, 0 };
1405 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1413 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1415 wxPoint origin
= GetClientAreaOrigin() ;
1421 MacWindowToRootWindow( x
, y
) ;
1424 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1426 MacRootWindowToWindow( x
, y
) ;
1428 wxPoint origin
= GetClientAreaOrigin() ;
1435 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1444 if ( !IsTopLevel() )
1446 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1449 pt
.x
-= MacGetLeftBorderSize() ;
1450 pt
.y
-= MacGetTopBorderSize() ;
1451 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1461 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1470 MacWindowToRootWindow( &x1
, &y1
) ;
1478 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1487 if ( !IsTopLevel() )
1489 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1492 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1493 pt
.x
+= MacGetLeftBorderSize() ;
1494 pt
.y
+= MacGetTopBorderSize() ;
1504 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1513 MacRootWindowToWindow( &x1
, &y1
) ;
1521 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1523 RgnHandle rgn
= NewRgn() ;
1525 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1527 Rect structure
, content
;
1529 GetRegionBounds( rgn
, &content
) ;
1530 m_peer
->GetRect( &structure
) ;
1531 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1533 left
= content
.left
- structure
.left
;
1534 top
= content
.top
- structure
.top
;
1535 right
= structure
.right
- content
.right
;
1536 bottom
= structure
.bottom
- content
.bottom
;
1540 left
= top
= right
= bottom
= 0 ;
1546 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1548 wxSize sizeTotal
= size
;
1550 RgnHandle rgn
= NewRgn() ;
1551 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1553 Rect content
, structure
;
1554 GetRegionBounds( rgn
, &content
) ;
1555 m_peer
->GetRect( &structure
) ;
1557 // structure is in parent coordinates, but we only need width and height, so it's ok
1559 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1560 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1565 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1566 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1571 // Get size *available for subwindows* i.e. excluding menu bar etc.
1572 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1576 RgnHandle rgn
= NewRgn() ;
1578 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1579 GetRegionBounds( rgn
, &content
) ;
1581 m_peer
->GetRect( &content
) ;
1584 ww
= content
.right
- content
.left
;
1585 hh
= content
.bottom
- content
.top
;
1587 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1588 hh
-= m_hScrollBar
->GetSize().y
;
1590 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1591 ww
-= m_vScrollBar
->GetSize().x
;
1599 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1601 if (m_cursor
== cursor
)
1604 if (wxNullCursor
== cursor
)
1606 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1611 if ( ! wxWindowBase::SetCursor( cursor
) )
1615 wxASSERT_MSG( m_cursor
.Ok(),
1616 wxT("cursor must be valid after call to the base version"));
1618 wxWindowMac
*mouseWin
= 0 ;
1620 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1621 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1623 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1625 // TODO: If we ever get a GetCurrentEvent... replacement
1626 // for the mouse position, use it...
1629 ControlPartCode part
;
1630 ControlRef control
;
1633 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1635 mouseWin
= wxFindControlFromMacControl( control
) ;
1638 QDSwapPort( savePort
, NULL
) ;
1641 if ( mouseWin
== this && !wxIsBusy() )
1642 m_cursor
.MacInstall() ;
1648 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1650 menu
->SetInvokingWindow(this);
1653 if ( x
== -1 && y
== -1 )
1655 wxPoint mouse
= wxGetMousePosition();
1661 ClientToScreen( &x
, &y
) ;
1664 menu
->MacBeforeDisplay( true ) ;
1665 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1666 if ( HiWord(menuResult
) != 0 )
1669 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1670 int id
= wxMacCommandToId( macid
);
1671 wxMenuItem
* item
= NULL
;
1673 item
= menu
->FindItem( id
, &realmenu
) ;
1676 if (item
->IsCheckable())
1677 item
->Check( !item
->IsChecked() ) ;
1679 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1683 menu
->MacAfterDisplay( true ) ;
1684 menu
->SetInvokingWindow( NULL
);
1690 // ----------------------------------------------------------------------------
1692 // ----------------------------------------------------------------------------
1696 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1698 wxWindowBase::DoSetToolTip(tooltip
);
1701 m_tooltip
->SetWindow(this);
1706 void wxWindowMac::MacInvalidateBorders()
1708 if ( m_peer
== NULL
)
1711 bool vis
= MacIsReallyShown() ;
1715 int outerBorder
= MacGetLeftBorderSize() ;
1716 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1719 if ( outerBorder
== 0 )
1722 // now we know that we have something to do at all
1724 // as the borders are drawn on the parent we have to properly invalidate all these areas
1725 RgnHandle updateInner
, updateOuter
;
1728 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1729 updateInner
= NewRgn() ;
1730 updateOuter
= NewRgn() ;
1732 m_peer
->GetRect( &rect
) ;
1733 RectRgn( updateInner
, &rect
) ;
1734 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1735 RectRgn( updateOuter
, &rect
) ;
1736 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1738 #ifdef __WXMAC_OSX__
1739 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1741 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1743 InvalWindowRgn( tlw
, updateOuter
) ;
1746 DisposeRgn( updateOuter
) ;
1747 DisposeRgn( updateInner
) ;
1750 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1752 // this is never called for a toplevel window, so we know we have a parent
1753 int former_x
, former_y
, former_w
, former_h
;
1755 // Get true coordinates of former position
1756 DoGetPosition( &former_x
, &former_y
) ;
1757 DoGetSize( &former_w
, &former_h
) ;
1759 wxWindow
*parent
= GetParent();
1762 wxPoint
pt(parent
->GetClientAreaOrigin());
1767 int actualWidth
= width
;
1768 int actualHeight
= height
;
1772 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1773 actualWidth
= m_minWidth
;
1774 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1775 actualHeight
= m_minHeight
;
1776 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1777 actualWidth
= m_maxWidth
;
1778 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1779 actualHeight
= m_maxHeight
;
1781 bool doMove
= false, doResize
= false ;
1783 if ( actualX
!= former_x
|| actualY
!= former_y
)
1786 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1789 if ( doMove
|| doResize
)
1791 // as the borders are drawn outside the native control, we adjust now
1793 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1794 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1795 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1798 wxMacRectToNative( &bounds
, &r
) ;
1800 if ( !GetParent()->IsTopLevel() )
1801 wxMacWindowToNative( GetParent() , &r
) ;
1803 MacInvalidateBorders() ;
1805 m_cachedClippedRectValid
= false ;
1806 m_peer
->SetRect( &r
) ;
1808 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1810 MacInvalidateBorders() ;
1812 MacRepositionScrollBars() ;
1815 wxPoint
point(actualX
, actualY
);
1816 wxMoveEvent
event(point
, m_windowId
);
1817 event
.SetEventObject(this);
1818 GetEventHandler()->ProcessEvent(event
) ;
1823 MacRepositionScrollBars() ;
1824 wxSize
size(actualWidth
, actualHeight
);
1825 wxSizeEvent
event(size
, m_windowId
);
1826 event
.SetEventObject(this);
1827 GetEventHandler()->ProcessEvent(event
);
1832 wxSize
wxWindowMac::DoGetBestSize() const
1834 if ( m_macIsUserPane
|| IsTopLevel() )
1835 return wxWindowBase::DoGetBestSize() ;
1837 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1838 int bestWidth
, bestHeight
;
1840 m_peer
->GetBestRect( &bestsize
) ;
1841 if ( EmptyRect( &bestsize
) )
1846 bestsize
.bottom
= 16 ;
1848 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1850 bestsize
.bottom
= 16 ;
1853 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1855 bestsize
.bottom
= 24 ;
1860 // return wxWindowBase::DoGetBestSize() ;
1864 bestWidth
= bestsize
.right
- bestsize
.left
;
1865 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1866 if ( bestHeight
< 10 )
1869 return wxSize(bestWidth
, bestHeight
);
1872 // set the size of the window: if the dimensions are positive, just use them,
1873 // but if any of them is equal to -1, it means that we must find the value for
1874 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1875 // which case -1 is a valid value for x and y)
1877 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1878 // the width/height to best suit our contents, otherwise we reuse the current
1880 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1882 // get the current size and position...
1883 int currentX
, currentY
;
1884 int currentW
, currentH
;
1886 GetPosition(¤tX
, ¤tY
);
1887 GetSize(¤tW
, ¤tH
);
1889 // ... and don't do anything (avoiding flicker) if it's already ok
1890 if ( x
== currentX
&& y
== currentY
&&
1891 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1894 MacRepositionScrollBars() ; // we might have a real position shift
1899 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1901 if ( x
== wxDefaultCoord
)
1903 if ( y
== wxDefaultCoord
)
1907 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1909 wxSize size
= wxDefaultSize
;
1910 if ( width
== wxDefaultCoord
)
1912 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1914 size
= DoGetBestSize();
1919 // just take the current one
1924 if ( height
== wxDefaultCoord
)
1926 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1928 if ( size
.x
== wxDefaultCoord
)
1929 size
= DoGetBestSize();
1930 // else: already called DoGetBestSize() above
1936 // just take the current one
1941 DoMoveWindow( x
, y
, width
, height
);
1944 wxPoint
wxWindowMac::GetClientAreaOrigin() const
1946 RgnHandle rgn
= NewRgn() ;
1948 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1950 GetRegionBounds( rgn
, &content
) ;
1960 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
1963 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
1965 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
1967 int currentclientwidth
, currentclientheight
;
1968 int currentwidth
, currentheight
;
1970 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
1971 GetSize( ¤twidth
, ¤theight
) ;
1973 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
1974 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
1978 void wxWindowMac::SetLabel(const wxString
& title
)
1980 m_label
= wxStripMenuCodes(title
) ;
1982 if ( m_peer
&& m_peer
->Ok() )
1983 m_peer
->SetLabel( m_label
) ;
1988 wxString
wxWindowMac::GetLabel() const
1993 bool wxWindowMac::Show(bool show
)
1995 bool former
= MacIsReallyShown() ;
1996 if ( !wxWindowBase::Show(show
) )
1999 // TODO: use visibilityChanged Carbon Event for OSX
2001 m_peer
->SetVisibility( show
, true ) ;
2003 if ( former
!= MacIsReallyShown() )
2004 MacPropagateVisibilityChanged() ;
2009 bool wxWindowMac::Enable(bool enable
)
2011 wxASSERT( m_peer
->Ok() ) ;
2012 bool former
= MacIsReallyEnabled() ;
2013 if ( !wxWindowBase::Enable(enable
) )
2016 m_peer
->Enable( enable
) ;
2018 if ( former
!= MacIsReallyEnabled() )
2019 MacPropagateEnabledStateChanged() ;
2025 // status change propagations (will be not necessary for OSX later )
2028 void wxWindowMac::MacPropagateVisibilityChanged()
2030 #if !TARGET_API_MAC_OSX
2031 MacVisibilityChanged() ;
2034 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2037 child
= node
->GetData();
2038 if ( child
->IsShown() )
2039 child
->MacPropagateVisibilityChanged() ;
2041 node
= node
->GetNext();
2046 void wxWindowMac::MacPropagateEnabledStateChanged()
2048 #if !TARGET_API_MAC_OSX
2049 MacEnabledStateChanged() ;
2052 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2055 child
= node
->GetData();
2056 if ( child
->IsEnabled() )
2057 child
->MacPropagateEnabledStateChanged() ;
2059 node
= node
->GetNext();
2064 void wxWindowMac::MacPropagateHiliteChanged()
2066 #if !TARGET_API_MAC_OSX
2067 MacHiliteChanged() ;
2070 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2073 child
= node
->GetData();
2074 if (child
/* && child->IsEnabled() */)
2075 child
->MacPropagateHiliteChanged() ;
2077 node
= node
->GetNext();
2083 // status change notifications
2086 void wxWindowMac::MacVisibilityChanged()
2090 void wxWindowMac::MacHiliteChanged()
2094 void wxWindowMac::MacEnabledStateChanged()
2099 // status queries on the inherited window's state
2102 bool wxWindowMac::MacIsReallyShown()
2104 // only under OSX the visibility of the TLW is taken into account
2105 if ( m_isBeingDeleted
)
2108 #if TARGET_API_MAC_OSX
2109 if ( m_peer
&& m_peer
->Ok() )
2110 return m_peer
->IsVisible();
2113 wxWindow
* win
= this ;
2114 while ( win
->IsShown() )
2116 if ( win
->IsTopLevel() )
2119 win
= win
->GetParent() ;
2127 bool wxWindowMac::MacIsReallyEnabled()
2129 return m_peer
->IsEnabled() ;
2132 bool wxWindowMac::MacIsReallyHilited()
2134 return m_peer
->IsActive();
2137 void wxWindowMac::MacFlashInvalidAreas()
2139 #if TARGET_API_MAC_OSX
2140 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2144 int wxWindowMac::GetCharHeight() const
2146 wxClientDC
dc( (wxWindowMac
*)this ) ;
2148 return dc
.GetCharHeight() ;
2151 int wxWindowMac::GetCharWidth() const
2153 wxClientDC
dc( (wxWindowMac
*)this ) ;
2155 return dc
.GetCharWidth() ;
2158 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2159 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2161 const wxFont
*fontToUse
= theFont
;
2163 fontToUse
= &m_font
;
2165 wxClientDC
dc( (wxWindowMac
*) this ) ;
2167 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2168 if ( externalLeading
)
2169 *externalLeading
= le
;
2179 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2180 * we always intersect with the entire window, not only with the client area
2183 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2185 if ( m_peer
== NULL
)
2188 if ( !MacIsReallyShown() )
2195 wxMacRectToNative( rect
, &r
) ;
2196 m_peer
->SetNeedsDisplay( &r
) ;
2200 m_peer
->SetNeedsDisplay() ;
2204 void wxWindowMac::Freeze()
2206 #if TARGET_API_MAC_OSX
2207 if ( !m_frozenness
++ )
2209 if ( m_peer
&& m_peer
->Ok() )
2210 m_peer
->SetDrawingEnabled( false ) ;
2215 void wxWindowMac::Thaw()
2217 #if TARGET_API_MAC_OSX
2218 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2220 if ( !--m_frozenness
)
2222 if ( m_peer
&& m_peer
->Ok() )
2224 m_peer
->SetDrawingEnabled( true ) ;
2225 m_peer
->InvalidateWithChildren() ;
2231 wxWindowMac
*wxGetActiveWindow()
2233 // actually this is a windows-only concept
2237 // Coordinates relative to the window
2238 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2240 // We really don't move the mouse programmatically under Mac.
2243 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2245 if ( MacGetTopLevelWindow() == NULL
)
2248 #if TARGET_API_MAC_OSX
2249 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2256 event
.GetDC()->Clear() ;
2260 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2265 int wxWindowMac::GetScrollPos(int orient
) const
2267 if ( orient
== wxHORIZONTAL
)
2270 return m_hScrollBar
->GetThumbPosition() ;
2275 return m_vScrollBar
->GetThumbPosition() ;
2281 // This now returns the whole range, not just the number
2282 // of positions that we can scroll.
2283 int wxWindowMac::GetScrollRange(int orient
) const
2285 if ( orient
== wxHORIZONTAL
)
2288 return m_hScrollBar
->GetRange() ;
2293 return m_vScrollBar
->GetRange() ;
2299 int wxWindowMac::GetScrollThumb(int orient
) const
2301 if ( orient
== wxHORIZONTAL
)
2304 return m_hScrollBar
->GetThumbSize() ;
2309 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
) ;
2330 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2331 // our own window origin is at leftOrigin/rightOrigin
2334 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2340 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2341 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2343 // back to the surrounding frame rectangle
2344 m_peer
->GetRect( &rect
) ;
2345 InsetRect( &rect
, -1 , -1 ) ;
2347 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2348 if ( UMAGetSystemVersion() >= 0x1030 )
2350 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2351 rect
.bottom
- rect
.top
) ;
2353 HIThemeFrameDrawInfo info
;
2354 memset( &info
, 0 , sizeof(info
) ) ;
2358 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2359 info
.isFocused
= hasFocus
;
2361 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2362 wxASSERT( cgContext
) ;
2364 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2366 info
.kind
= kHIThemeFrameTextFieldSquare
;
2367 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2369 else if ( HasFlag(wxSIMPLE_BORDER
) )
2371 info
.kind
= kHIThemeFrameListBox
;
2372 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2374 else if ( hasFocus
)
2376 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2379 m_peer
->GetRect( &rect
) ;
2380 if ( hasBothScrollbars
)
2382 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2383 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2384 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2385 HIThemeGrowBoxDrawInfo info
;
2386 memset( &info
, 0, sizeof(info
) ) ;
2388 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2389 info
.kind
= kHIThemeGrowBoxKindNone
;
2390 info
.size
= kHIThemeGrowBoxSizeNormal
;
2391 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2392 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2398 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2402 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2403 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2406 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2407 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2408 else if ( HasFlag(wxSIMPLE_BORDER
) )
2409 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2412 DrawThemeFocusRect( &rect
, true ) ;
2414 if ( hasBothScrollbars
)
2416 // GetThemeStandaloneGrowBoxBounds
2417 // DrawThemeStandaloneNoGrowBox
2422 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2424 if ( child
== m_hScrollBar
)
2425 m_hScrollBar
= NULL
;
2426 if ( child
== m_vScrollBar
)
2427 m_vScrollBar
= NULL
;
2429 wxWindowBase::RemoveChild( child
) ;
2432 // New function that will replace some of the above.
2433 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2434 int range
, bool refresh
)
2438 if ( orient
== wxHORIZONTAL
)
2442 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2443 if ( m_hScrollBar
->IsShown() != showScroller
)
2444 m_hScrollBar
->Show( showScroller
) ;
2446 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2453 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2454 if ( m_vScrollBar
->IsShown() != showScroller
)
2455 m_vScrollBar
->Show( showScroller
) ;
2457 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2461 MacRepositionScrollBars() ;
2464 // Does a physical scroll
2465 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2467 if ( dx
== 0 && dy
== 0 )
2470 int width
, height
;
2471 GetClientSize( &width
, &height
) ;
2473 #if TARGET_API_MAC_OSX
2474 if ( true /* m_peer->IsCompositing() */ )
2476 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2477 // area is scrolled, this does not occur if width and height are 2 pixels less,
2478 // TODO: write optimal workaround
2479 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2481 scrollrect
.Intersect( *rect
) ;
2483 if ( m_peer
->GetNeedsDisplay() )
2485 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2486 // either immediate redraw or full invalidate
2488 // is the better overall solution, as it does not slow down scrolling
2489 m_peer
->SetNeedsDisplay() ;
2491 // this would be the preferred version for fast drawing controls
2493 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2494 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2495 HIViewRender(m_peer
->GetControlRef()) ;
2502 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2503 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2504 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2506 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2507 // either immediate redraw or full invalidate
2509 // is the better overall solution, as it does not slow down scrolling
2510 m_peer
->SetNeedsDisplay() ;
2512 // this would be the preferred version for fast drawing controls
2514 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2515 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2516 HIViewRender(m_peer
->GetControlRef()) ;
2530 RgnHandle updateRgn
= NewRgn() ;
2533 wxClientDC
dc(this) ;
2534 wxMacPortSetter
helper(&dc
) ;
2536 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2537 //scrollrect.top += MacGetTopBorderSize() ;
2538 //scrollrect.left += MacGetLeftBorderSize() ;
2539 scrollrect
.bottom
= scrollrect
.top
+ height
;
2540 scrollrect
.right
= scrollrect
.left
+ width
;
2544 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2545 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2546 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2549 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2551 // now scroll the former update region as well and add the new update region
2552 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2553 RgnHandle formerUpdateRgn
= NewRgn() ;
2554 RgnHandle scrollRgn
= NewRgn() ;
2555 RectRgn( scrollRgn
, &scrollrect
) ;
2556 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2558 LocalToGlobal( &pt
) ;
2559 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2560 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2562 if ( !EmptyRgn( formerUpdateRgn
) )
2564 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2565 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2566 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2569 InvalWindowRgn(rootWindow
, updateRgn
) ;
2570 DisposeRgn( updateRgn
) ;
2571 DisposeRgn( formerUpdateRgn
) ;
2572 DisposeRgn( scrollRgn
) ;
2580 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2582 child
= node
->GetData();
2585 if (child
== m_vScrollBar
)
2587 if (child
== m_hScrollBar
)
2589 if (child
->IsTopLevel())
2592 child
->GetPosition( &x
, &y
);
2593 child
->GetSize( &w
, &h
);
2596 wxRect
rc( x
, y
, w
, h
);
2597 if (rect
->Intersects( rc
))
2598 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2602 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2607 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2609 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2611 wxScrollWinEvent wevent
;
2612 wevent
.SetPosition(event
.GetPosition());
2613 wevent
.SetOrientation(event
.GetOrientation());
2614 wevent
.SetEventObject(this);
2616 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2617 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2618 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2619 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2620 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2621 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2622 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2623 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2624 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2625 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2626 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2627 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2628 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2629 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2630 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2631 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2633 GetEventHandler()->ProcessEvent(wevent
);
2637 // Get the window with the focus
2638 wxWindowMac
*wxWindowBase::DoFindFocus()
2640 ControlRef control
;
2641 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2642 return wxFindControlFromMacControl( control
) ;
2645 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2647 // panel wants to track the window which was the last to have focus in it,
2648 // so we want to set ourselves as the window which last had focus
2650 // notice that it's also important to do it upwards the tree because
2651 // otherwise when the top level panel gets focus, it won't set it back to
2652 // us, but to some other sibling
2654 // CS: don't know if this is still needed:
2655 //wxChildFocusEvent eventFocus(this);
2656 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2658 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2660 #if wxMAC_USE_CORE_GRAPHICS
2661 GetParent()->Refresh() ;
2663 wxMacWindowStateSaver
sv( this ) ;
2666 m_peer
->GetRect( &rect
) ;
2667 // auf den umgebenden Rahmen zur\9fck
2668 InsetRect( &rect
, -1 , -1 ) ;
2670 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2674 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2676 rect
.right
+= pt
.x
;
2678 rect
.bottom
+= pt
.y
;
2681 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2682 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2683 if ( !bIsFocusEvent
)
2685 // as this erases part of the frame we have to redraw borders
2686 // and because our z-ordering is not always correct (staticboxes)
2687 // we have to invalidate things, we cannot simple redraw
2688 MacInvalidateBorders() ;
2696 void wxWindowMac::OnInternalIdle()
2698 // This calls the UI-update mechanism (querying windows for
2699 // menu/toolbar/control state information)
2700 if (wxUpdateUIEvent::CanUpdate(this))
2701 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2704 // Raise the window to the top of the Z order
2705 void wxWindowMac::Raise()
2707 m_peer
->SetZOrder( true , NULL
) ;
2710 // Lower the window to the bottom of the Z order
2711 void wxWindowMac::Lower()
2713 m_peer
->SetZOrder( false , NULL
) ;
2716 // static wxWindow *gs_lastWhich = NULL;
2718 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2720 // first trigger a set cursor event
2722 wxPoint clientorigin
= GetClientAreaOrigin() ;
2723 wxSize clientsize
= GetClientSize() ;
2725 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2727 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2729 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2730 if ( processedEvtSetCursor
&& event
.HasCursor() )
2732 cursor
= event
.GetCursor() ;
2736 // the test for processedEvtSetCursor is here to prevent using m_cursor
2737 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2738 // it - this is a way to say that our cursor shouldn't be used for this
2740 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2743 if ( !wxIsBusy() && !GetParent() )
2744 cursor
= *wxSTANDARD_CURSOR
;
2748 cursor
.MacInstall() ;
2751 return cursor
.Ok() ;
2754 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2758 return m_tooltip
->GetTip() ;
2761 return wxEmptyString
;
2764 void wxWindowMac::ClearBackground()
2770 void wxWindowMac::Update()
2772 #if TARGET_API_MAC_OSX
2773 MacGetTopLevelWindow()->MacPerformUpdates() ;
2775 ::Draw1Control( m_peer
->GetControlRef() ) ;
2779 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2781 wxTopLevelWindowMac
* win
= NULL
;
2782 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2784 win
= wxFindWinFromMacWindow( window
) ;
2789 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2791 MacUpdateClippedRects() ;
2793 return m_cachedClippedClientRect
;
2796 const wxRect
& wxWindowMac::MacGetClippedRect() const
2798 MacUpdateClippedRects() ;
2800 return m_cachedClippedRect
;
2803 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2805 MacUpdateClippedRects() ;
2807 return m_cachedClippedRectWithOuterStructure
;
2810 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2812 static wxRegion emptyrgn
;
2814 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2816 MacUpdateClippedRects() ;
2817 if ( includeOuterStructures
)
2818 return m_cachedClippedRegionWithOuterStructure
;
2820 return m_cachedClippedRegion
;
2828 void wxWindowMac::MacUpdateClippedRects() const
2830 if ( m_cachedClippedRectValid
)
2833 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2834 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2835 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2836 // to add focus borders everywhere
2838 Rect r
, rIncludingOuterStructures
;
2840 m_peer
->GetRect( &r
) ;
2841 r
.left
-= MacGetLeftBorderSize() ;
2842 r
.top
-= MacGetTopBorderSize() ;
2843 r
.bottom
+= MacGetBottomBorderSize() ;
2844 r
.right
+= MacGetRightBorderSize() ;
2851 rIncludingOuterStructures
= r
;
2852 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2854 wxRect cl
= GetClientRect() ;
2855 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2859 const wxWindow
* child
= this ;
2860 const wxWindow
* parent
= NULL
;
2862 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2864 if ( parent
->MacIsChildOfClientArea(child
) )
2866 size
= parent
->GetClientSize() ;
2867 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2873 // this will be true for scrollbars, toolbars etc.
2874 size
= parent
->GetSize() ;
2875 y
= parent
->MacGetTopBorderSize() ;
2876 x
= parent
->MacGetLeftBorderSize() ;
2877 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2878 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2881 parent
->MacWindowToRootWindow( &x
, &y
) ;
2882 MacRootWindowToWindow( &x
, &y
) ;
2884 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2886 // the wxwindow and client rects will always be clipped
2887 SectRect( &r
, &rparent
, &r
) ;
2888 SectRect( &rClient
, &rparent
, &rClient
) ;
2890 // the structure only at 'hard' borders
2891 if ( parent
->MacClipChildren() ||
2892 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2894 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2900 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2901 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2902 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2903 m_cachedClippedRectWithOuterStructure
= wxRect(
2904 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2905 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2906 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2908 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2909 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2910 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2912 m_cachedClippedRectValid
= true ;
2916 This function must not change the updatergn !
2918 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
2920 bool handled
= false ;
2922 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
2923 GetRegionBounds( updatergn
, &updatebounds
) ;
2925 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2927 if ( !EmptyRgn(updatergn
) )
2929 RgnHandle newupdate
= NewRgn() ;
2930 wxSize point
= GetClientSize() ;
2931 wxPoint origin
= GetClientAreaOrigin() ;
2932 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
2933 SectRgn( newupdate
, updatergn
, newupdate
) ;
2935 // first send an erase event to the entire update area
2937 // for the toplevel window this really is the entire area
2938 // for all the others only their client area, otherwise they
2939 // might be drawing with full alpha and eg put blue into
2940 // the grow-box area of a scrolled window (scroll sample)
2941 wxDC
* dc
= new wxWindowDC(this);
2943 dc
->SetClippingRegion(wxRegion(updatergn
));
2945 dc
->SetClippingRegion(wxRegion(newupdate
));
2947 wxEraseEvent
eevent( GetId(), dc
);
2948 eevent
.SetEventObject( this );
2949 GetEventHandler()->ProcessEvent( eevent
);
2953 // calculate a client-origin version of the update rgn and set m_updateRegion to that
2954 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
2955 m_updateRegion
= newupdate
;
2956 DisposeRgn( newupdate
) ;
2958 if ( !m_updateRegion
.Empty() )
2960 // paint the window itself
2963 event
.SetTimestamp(time
);
2964 event
.SetEventObject(this);
2965 GetEventHandler()->ProcessEvent(event
);
2969 // now we cannot rely on having its borders drawn by a window itself, as it does not
2970 // get the updateRgn wide enough to always do so, so we do it from the parent
2971 // this would also be the place to draw any custom backgrounds for native controls
2972 // in Composited windowing
2973 wxPoint clientOrigin
= GetClientAreaOrigin() ;
2977 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2979 child
= node
->GetData();
2982 if (child
== m_vScrollBar
)
2984 if (child
== m_hScrollBar
)
2986 if (child
->IsTopLevel())
2988 if (!child
->IsShown())
2991 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2993 child
->GetPosition( &x
, &y
);
2994 child
->GetSize( &w
, &h
);
2995 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
2996 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
2997 InsetRect( &childRect
, -10 , -10) ;
2999 if ( RectInRgn( &childRect
, updatergn
) )
3001 // paint custom borders
3002 wxNcPaintEvent
eventNc( child
->GetId() );
3003 eventNc
.SetEventObject( child
);
3004 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3006 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3007 if ( UMAGetSystemVersion() >= 0x1030 )
3009 child
->MacPaintBorders(0, 0) ;
3014 wxWindowDC
dc(this) ;
3015 dc
.SetClippingRegion(wxRegion(updatergn
));
3016 wxMacPortSetter
helper(&dc
) ;
3017 child
->MacPaintBorders(0, 0) ;
3028 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3030 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3034 if ( iter
->IsTopLevel() )
3035 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3037 iter
= iter
->GetParent() ;
3040 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3045 void wxWindowMac::MacCreateScrollBars( long style
)
3047 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3049 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3051 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3052 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3053 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3054 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3056 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3057 variant
= wxWINDOW_VARIANT_SMALL
;
3060 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3062 GetClientSize( &width
, &height
) ;
3064 wxPoint
vPoint(width
- scrlsize
, 0) ;
3065 wxSize
vSize(scrlsize
, height
- adjust
) ;
3066 wxPoint
hPoint(0, height
- scrlsize
) ;
3067 wxSize
hSize(width
- adjust
, scrlsize
) ;
3069 if ( style
& wxVSCROLL
)
3070 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3072 if ( style
& wxHSCROLL
)
3073 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3076 // because the create does not take into account the client area origin
3077 // we might have a real position shift
3078 MacRepositionScrollBars() ;
3081 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3083 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3088 void wxWindowMac::MacRepositionScrollBars()
3090 if ( !m_hScrollBar
&& !m_vScrollBar
)
3093 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3094 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3095 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3097 // get real client area
3099 GetSize( &width
, &height
);
3101 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3102 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3104 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3105 wxSize
vSize( scrlsize
, height
- adjust
) ;
3106 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3107 wxSize
hSize( width
- adjust
, scrlsize
) ;
3110 int x
= 0, y
= 0, w
, h
;
3111 GetSize( &w
, &h
) ;
3113 MacClientToRootWindow( &x
, &y
) ;
3114 MacClientToRootWindow( &w
, &h
) ;
3116 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3118 int totW
= 10000 , totH
= 10000;
3121 if ( iter
->IsTopLevel() )
3123 iter
->GetSize( &totW
, &totH
) ;
3127 iter
= iter
->GetParent() ;
3141 if ( w
- x
>= totW
)
3146 if ( h
- y
>= totH
)
3154 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3156 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3159 bool wxWindowMac::AcceptsFocus() const
3161 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3164 void wxWindowMac::MacSuperChangedPosition()
3166 // only window-absolute structures have to be moved i.e. controls
3168 m_cachedClippedRectValid
= false ;
3171 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3174 child
= node
->GetData();
3175 child
->MacSuperChangedPosition() ;
3177 node
= node
->GetNext();
3181 void wxWindowMac::MacTopLevelWindowChangedPosition()
3183 // only screen-absolute structures have to be moved i.e. glcanvas
3186 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3189 child
= node
->GetData();
3190 child
->MacTopLevelWindowChangedPosition() ;
3192 node
= node
->GetNext();
3196 long wxWindowMac::MacGetLeftBorderSize() const
3203 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3205 // this metric is only the 'outset' outside the simple frame rect
3206 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3209 else if (HasFlag(wxSIMPLE_BORDER
))
3211 // this metric is only the 'outset' outside the simple frame rect
3212 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3219 long wxWindowMac::MacGetRightBorderSize() const
3221 // they are all symmetric in mac themes
3222 return MacGetLeftBorderSize() ;
3225 long wxWindowMac::MacGetTopBorderSize() const
3227 // they are all symmetric in mac themes
3228 return MacGetLeftBorderSize() ;
3231 long wxWindowMac::MacGetBottomBorderSize() const
3233 // they are all symmetric in mac themes
3234 return MacGetLeftBorderSize() ;
3237 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3239 return style
& ~wxBORDER_MASK
;
3242 // Find the wxWindowMac at the current mouse position, returning the mouse
3244 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3246 pt
= wxGetMousePosition();
3247 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3252 // Get the current mouse position.
3253 wxPoint
wxGetMousePosition()
3257 wxGetMousePosition( &x
, &y
);
3259 return wxPoint(x
, y
);
3262 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3264 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3266 // copied from wxGTK : CS
3267 // VZ: shouldn't we move this to base class then?
3269 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3272 // (a) it's a command event and so is propagated to the parent
3273 // (b) under MSW it can be generated from kbd too
3274 // (c) it uses screen coords (because of (a))
3275 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3277 this->ClientToScreen(event
.GetPosition()));
3278 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3287 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3289 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3290 CallNextEventHandler(
3291 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3292 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3295 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3299 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3303 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3304 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3309 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3311 return eventNotHandledErr
;
3314 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3316 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3317 if ( !wxWindowBase::Reparent(newParent
) )
3320 // copied from MacPostControlCreate
3321 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3323 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3325 ::EmbedControl( m_peer
->GetControlRef() , container
) ;