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"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
31 #include "wx/layout.h"
32 #include "wx/scrolbar.h"
33 #include "wx/statbox.h"
34 #include "wx/tooltip.h"
35 #include "wx/statusbr.h"
36 #include "wx/menuitem.h"
37 #include "wx/spinctrl.h"
38 #include "wx/geometry.h"
39 #include "wx/textctrl.h"
41 #include "wx/toolbar.h"
47 #if wxUSE_DRAG_AND_DROP
51 #include "wx/mac/uma.h"
53 #define MAC_SCROLLBAR_SIZE 15
54 #define MAC_SMALL_SCROLLBAR_SIZE 11
58 #include <ToolUtils.h>
60 #include <MacTextEditor.h>
63 #if TARGET_API_MAC_OSX
65 #include <HIToolbox/HIView.h>
71 #ifdef __WXUNIVERSAL__
72 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
74 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
77 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
78 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
79 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
80 #if TARGET_API_MAC_OSX
81 EVT_PAINT(wxWindowMac::OnPaint
)
83 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
85 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
88 #define wxMAC_DEBUG_REDRAW 0
89 #ifndef wxMAC_DEBUG_REDRAW
90 #define wxMAC_DEBUG_REDRAW 0
93 #define wxMAC_USE_THEME_BORDER 1
95 // ---------------------------------------------------------------------------
96 // Utility Routines to move between different coordinate systems
97 // ---------------------------------------------------------------------------
100 * Right now we have the following setup :
101 * a border that is not part of the native control is always outside the
102 * control's border (otherwise we loose all native intelligence, future ways
103 * may be to have a second embedding control responsible for drawing borders
104 * and backgrounds eventually)
105 * so all this border calculations have to be taken into account when calling
106 * native methods or getting native oriented data
107 * so we have three coordinate systems here
108 * wx client coordinates
109 * wx window coordinates (including window frames)
114 // originating from native control
118 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
120 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
123 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
125 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
129 // directed towards native control
132 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
134 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
137 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
139 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
142 // ---------------------------------------------------------------------------
144 // ---------------------------------------------------------------------------
146 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
147 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
149 #if TARGET_API_MAC_OSX
151 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
154 kEventControlVisibilityChanged
= 157
160 static const EventTypeSpec eventList
[] =
162 { kEventClassCommand
, kEventProcessCommand
} ,
163 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
165 { kEventClassControl
, kEventControlHit
} ,
167 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
168 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
170 { kEventClassControl
, kEventControlDraw
} ,
171 #if TARGET_API_MAC_OSX
172 { kEventClassControl
, kEventControlVisibilityChanged
} ,
173 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
174 { kEventClassControl
, kEventControlHiliteChanged
} ,
176 { kEventClassControl
, kEventControlSetFocusPart
} ,
178 { kEventClassService
, kEventServiceGetTypes
},
179 { kEventClassService
, kEventServiceCopy
},
180 { kEventClassService
, kEventServicePaste
},
182 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
183 // { kEventClassControl , kEventControlBoundsChanged } ,
186 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
188 OSStatus result
= eventNotHandledErr
;
190 wxMacCarbonEvent
cEvent( event
) ;
192 ControlRef controlRef
;
193 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
195 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
197 switch ( GetEventKind( event
) )
199 #if TARGET_API_MAC_OSX
200 case kEventControlDraw
:
202 RgnHandle updateRgn
= NULL
;
203 RgnHandle allocatedRgn
= NULL
;
204 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
207 if ( ! thisWindow
->GetPeer()->IsCompositing() )
209 if ( thisWindow
->GetPeer()->IsRootControl() )
210 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
212 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
215 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
217 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
221 if ( ! thisWindow
->GetPeer()->IsCompositing() )
223 allocatedRgn
= NewRgn() ;
224 CopyRgn( updateRgn
, allocatedRgn
) ;
225 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
227 // hide the given region by the new region that must be shifted
228 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
229 updateRgn
= allocatedRgn
;
233 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
235 // as this update region is in native window locals we must adapt it to wx window local
236 allocatedRgn
= NewRgn() ;
237 CopyRgn( updateRgn
, allocatedRgn
) ;
239 // hide the given region by the new region that must be shifted
240 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
241 updateRgn
= allocatedRgn
;
247 GetRegionBounds( updateRgn
, &rgnBounds
) ;
249 #if wxMAC_DEBUG_REDRAW
250 if ( thisWindow
->MacIsUserPane() )
252 static float color
= 0.5 ;
255 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
257 HIViewGetBounds( controlRef
, &bounds
);
258 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
259 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
260 CGContextFillRect( cgContext
, bounds
);
273 #if wxMAC_USE_CORE_GRAPHICS
274 bool created
= false ;
275 CGContextRef cgContext
= NULL
;
276 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
278 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
280 // this parameter is not provided on non-composited windows
283 // rest of the code expects this to be already transformed and clipped for local
284 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
286 GetPortBounds( port
, &bounds
) ;
287 CreateCGContextForPort( port
, &cgContext
) ;
289 wxMacWindowToNative( thisWindow
, updateRgn
) ;
290 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
291 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
292 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
293 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
295 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
296 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
298 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
301 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
302 CGContextFillRect( cgContext
,
304 controlBounds
.right
- controlBounds
.left
,
305 controlBounds
.bottom
- controlBounds
.top
) );
309 thisWindow
->MacSetCGContextRef( cgContext
) ;
312 wxMacCGContextStateSaver
sg( cgContext
) ;
314 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
317 #if wxMAC_USE_CORE_GRAPHICS
318 thisWindow
->MacSetCGContextRef( NULL
) ;
322 CGContextRelease( cgContext
) ;
327 DisposeRgn( allocatedRgn
) ;
331 case kEventControlVisibilityChanged
:
332 thisWindow
->MacVisibilityChanged() ;
335 case kEventControlEnabledStateChanged
:
336 thisWindow
->MacEnabledStateChanged() ;
339 case kEventControlHiliteChanged
:
340 thisWindow
->MacHiliteChanged() ;
344 // we emulate this event under Carbon CFM
345 case kEventControlSetFocusPart
:
347 Boolean focusEverything
= false ;
348 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
351 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
356 if ( controlPart
== kControlFocusNoPart
)
359 if ( thisWindow
->GetCaret() )
360 thisWindow
->GetCaret()->OnKillFocus();
363 static bool inKillFocusEvent
= false ;
365 if ( !inKillFocusEvent
)
367 inKillFocusEvent
= true ;
368 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
369 event
.SetEventObject(thisWindow
);
370 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
371 inKillFocusEvent
= false ;
376 // panel wants to track the window which was the last to have focus in it
377 wxChildFocusEvent
eventFocus(thisWindow
);
378 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
381 if ( thisWindow
->GetCaret() )
382 thisWindow
->GetCaret()->OnSetFocus();
385 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
386 event
.SetEventObject(thisWindow
);
387 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
390 if ( thisWindow
->MacIsUserPane() )
395 case kEventControlHit
:
396 result
= thisWindow
->MacControlHit( handler
, event
) ;
406 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
408 OSStatus result
= eventNotHandledErr
;
410 wxMacCarbonEvent
cEvent( event
) ;
412 ControlRef controlRef
;
413 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
414 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
415 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
417 switch ( GetEventKind( event
) )
419 case kEventServiceGetTypes
:
423 textCtrl
->GetSelection( &from
, &to
) ;
425 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
427 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
428 if ( textCtrl
->IsEditable() )
429 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
431 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
432 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
434 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
438 CFArrayAppendValue(copyTypes
, typestring
) ;
440 CFArrayAppendValue(pasteTypes
, typestring
) ;
442 CFRelease( typestring
) ;
450 case kEventServiceCopy
:
455 textCtrl
->GetSelection( &from
, &to
) ;
456 wxString val
= textCtrl
->GetValue() ;
457 val
= val
.Mid( from
, to
- from
) ;
458 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
459 verify_noerr( ClearScrap( &scrapRef
) ) ;
460 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
465 case kEventServicePaste
:
468 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
469 Size textSize
, pastedSize
;
470 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
472 char *content
= new char[textSize
] ;
473 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
474 content
[textSize
- 1] = 0 ;
477 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
479 textCtrl
->WriteText( wxString( content
) ) ;
494 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
496 OSStatus result
= eventNotHandledErr
;
497 wxWindowMac
* focus
= (wxWindowMac
*) data
;
499 wchar_t* uniChars
= NULL
;
500 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
502 UniChar
* charBuf
= NULL
;
503 UInt32 dataSize
= 0 ;
506 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
508 numChars
= dataSize
/ sizeof( UniChar
) + 1;
511 if ( (size_t) numChars
* 2 > sizeof(buf
) )
512 charBuf
= new UniChar
[ numChars
] ;
516 uniChars
= new wchar_t[ numChars
] ;
517 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
518 charBuf
[ numChars
- 1 ] = 0;
519 #if SIZEOF_WCHAR_T == 2
520 uniChars
= (wchar_t*) charBuf
;
521 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
523 // the resulting string will never have more chars than the utf16 version, so this is safe
524 wxMBConvUTF16 converter
;
525 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
529 switch ( GetEventKind( event
) )
531 case kEventTextInputUpdateActiveInputArea
:
533 // An IME input event may return several characters, but we need to send one char at a time to
535 for (int pos
=0 ; pos
< numChars
; pos
++)
537 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
538 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
539 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
541 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
542 if ( wxTheApp
->MacSendCharEvent(
543 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
548 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
552 case kEventTextInputUnicodeForKeyEvent
:
554 UInt32 keyCode
, modifiers
;
557 unsigned char charCode
;
559 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
560 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
561 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
562 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
563 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
565 UInt32 message
= (keyCode
<< 8) + charCode
;
567 // An IME input event may return several characters, but we need to send one char at a time to
569 for (int pos
=0 ; pos
< numChars
; pos
++)
571 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
572 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
573 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
575 if ( wxTheApp
->MacSendCharEvent(
576 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
581 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
590 if ( charBuf
!= buf
)
596 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
598 OSStatus result
= eventNotHandledErr
;
599 wxWindowMac
* focus
= (wxWindowMac
*) data
;
603 wxMacCarbonEvent
cEvent( event
) ;
604 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
606 wxMenuItem
* item
= NULL
;
607 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
608 int id
= wxMacCommandToId( command
.commandID
) ;
612 wxASSERT( itemMenu
!= NULL
) ;
614 switch ( cEvent
.GetKind() )
616 case kEventProcessCommand
:
618 if (item
->IsCheckable())
619 item
->Check( !item
->IsChecked() ) ;
621 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
625 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
626 event
.SetEventObject(focus
);
627 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
629 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
635 case kEventCommandUpdateStatus
:
637 wxUpdateUIEvent
event(id
);
638 event
.SetEventObject( itemMenu
);
640 bool processed
= false;
642 // Try the menu's event handler
644 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
646 processed
= handler
->ProcessEvent(event
);
649 // Try the window the menu was popped up from
650 // (and up through the hierarchy)
653 const wxMenuBase
*menu
= itemMenu
;
656 wxWindow
*win
= menu
->GetInvokingWindow();
659 processed
= win
->GetEventHandler()->ProcessEvent(event
);
663 menu
= menu
->GetParent();
669 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
674 // if anything changed, update the changed attribute
675 if (event
.GetSetText())
676 itemMenu
->SetLabel(id
, event
.GetText());
677 if (event
.GetSetChecked())
678 itemMenu
->Check(id
, event
.GetChecked());
679 if (event
.GetSetEnabled())
680 itemMenu
->Enable(id
, event
.GetEnabled());
694 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
696 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
697 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
698 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
699 OSStatus result
= eventNotHandledErr
;
701 switch ( GetEventClass( event
) )
703 case kEventClassCommand
:
704 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
707 case kEventClassControl
:
708 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
711 case kEventClassService
:
712 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
715 case kEventClassTextInput
:
716 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
723 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
728 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
730 #if !TARGET_API_MAC_OSX
732 // ---------------------------------------------------------------------------
733 // UserPane events for non OSX builds
734 // ---------------------------------------------------------------------------
736 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
738 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
740 win
->MacControlUserPaneDrawProc(part
) ;
742 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
744 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
746 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
748 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
750 return kControlNoPart
;
752 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
754 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
756 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
758 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
760 return kControlNoPart
;
762 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
764 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
766 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
768 win
->MacControlUserPaneIdleProc() ;
770 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
772 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
774 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
776 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
778 return kControlNoPart
;
780 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
782 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
784 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
786 win
->MacControlUserPaneActivateProc(activating
) ;
788 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
790 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
792 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
794 return win
->MacControlUserPaneFocusProc(action
) ;
796 return kControlNoPart
;
798 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
800 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
802 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
804 win
->MacControlUserPaneBackgroundProc(info
) ;
806 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
808 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
811 RgnHandle rgn
= NewRgn() ;
813 MacWindowToRootWindow( &x
, &y
) ;
814 OffsetRgn( rgn
, -x
, -y
) ;
815 wxMacWindowStateSaver
sv( this ) ;
816 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
817 MacDoRedraw( rgn
, 0 ) ;
821 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
823 return kControlNoPart
;
826 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
828 return kControlNoPart
;
831 void wxWindowMac::MacControlUserPaneIdleProc()
835 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
837 return kControlNoPart
;
840 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
844 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
846 if ( AcceptsFocus() )
849 return kControlNoPart
;
852 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
858 // ---------------------------------------------------------------------------
859 // Scrollbar Tracking for all
860 // ---------------------------------------------------------------------------
862 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
863 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
867 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
869 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
872 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
874 // ===========================================================================
876 // ===========================================================================
878 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
880 static MacControlMap wxWinMacControlList
;
882 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
884 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
886 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
889 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
891 // adding NULL ControlRef is (first) surely a result of an error and
892 // (secondly) breaks native event processing
893 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
895 wxWinMacControlList
[inControl
] = control
;
898 void wxRemoveMacControlAssociation(wxWindow
*control
)
900 // iterate over all the elements in the class
901 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
902 // we should go on...
908 MacControlMap::iterator it
;
909 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
911 if ( it
->second
== control
)
913 wxWinMacControlList
.erase(it
);
921 // ----------------------------------------------------------------------------
922 // constructors and such
923 // ----------------------------------------------------------------------------
925 wxWindowMac::wxWindowMac()
930 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
935 const wxString
& name
)
938 Create(parent
, id
, pos
, size
, style
, name
);
941 void wxWindowMac::Init()
946 #if WXWIN_COMPATIBILITY_2_4
947 m_backgroundTransparent
= false;
950 #if wxMAC_USE_CORE_GRAPHICS
951 m_cgContextRef
= NULL
;
954 // as all windows are created with WS_VISIBLE style...
957 m_hScrollBar
= NULL
;
958 m_vScrollBar
= NULL
;
959 m_macBackgroundBrush
= wxNullBrush
;
961 m_macIsUserPane
= true;
962 m_clipChildren
= false ;
963 m_cachedClippedRectValid
= false ;
965 // we need a valid font for the encodings
966 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
969 wxWindowMac::~wxWindowMac()
973 m_isBeingDeleted
= true;
975 MacInvalidateBorders() ;
977 #ifndef __WXUNIVERSAL__
978 // VS: make sure there's no wxFrame with last focus set to us:
979 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
981 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
984 if ( frame
->GetLastFocus() == this )
985 frame
->SetLastFocus((wxWindow
*)NULL
);
991 // destroy children before destroying this window itself
994 // wxRemoveMacControlAssociation( this ) ;
995 // If we delete an item, we should initialize the parent panel,
996 // because it could now be invalid.
997 wxWindow
*parent
= GetParent() ;
1000 if (parent
->GetDefaultItem() == (wxButton
*) this)
1001 parent
->SetDefaultItem(NULL
);
1004 if ( m_peer
&& m_peer
->Ok() )
1006 // in case the callback might be called during destruction
1007 wxRemoveMacControlAssociation( this) ;
1008 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1009 // we currently are not using this hook
1010 // ::SetControlColorProc( *m_peer , NULL ) ;
1014 if ( g_MacLastWindow
== this )
1015 g_MacLastWindow
= NULL
;
1017 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1020 if ( frame
->GetLastFocus() == this )
1021 frame
->SetLastFocus( NULL
) ;
1024 // delete our drop target if we've got one
1025 #if wxUSE_DRAG_AND_DROP
1026 if ( m_dropTarget
!= NULL
)
1028 delete m_dropTarget
;
1029 m_dropTarget
= NULL
;
1036 WXWidget
wxWindowMac::GetHandle() const
1038 return (WXWidget
) m_peer
->GetControlRef() ;
1041 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1043 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1044 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1045 GetEventTypeCount(eventList
), eventList
, this,
1046 (EventHandlerRef
*)&m_macControlEventHandler
);
1048 #if !TARGET_API_MAC_OSX
1049 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1051 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1052 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1053 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1054 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1055 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1056 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1057 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1058 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1064 bool wxWindowMac::Create(wxWindowMac
*parent
,
1069 const wxString
& name
)
1071 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1073 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1076 m_windowVariant
= parent
->GetWindowVariant() ;
1078 if ( m_macIsUserPane
)
1080 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1083 | kControlSupportsEmbedding
1084 | kControlSupportsLiveFeedback
1085 | kControlGetsFocusOnClick
1086 // | kControlHasSpecialBackground
1087 // | kControlSupportsCalcBestRect
1088 | kControlHandlesTracking
1089 | kControlSupportsFocus
1090 | kControlWantsActivate
1091 | kControlWantsIdle
;
1093 m_peer
= new wxMacControl(this) ;
1094 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1095 verify_noerr( err
);
1097 MacPostControlCreate(pos
, size
) ;
1100 #ifndef __WXUNIVERSAL__
1101 // Don't give scrollbars to wxControls unless they ask for them
1102 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1103 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1105 MacCreateScrollBars( style
) ;
1109 wxWindowCreateEvent
event(this);
1110 GetEventHandler()->AddPendingEvent(event
);
1115 void wxWindowMac::MacChildAdded()
1118 m_vScrollBar
->Raise() ;
1120 m_hScrollBar
->Raise() ;
1123 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1125 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1127 m_peer
->SetReference( (long)this ) ;
1128 GetParent()->AddChild( this );
1130 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1132 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1133 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1134 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1135 GetParent()->MacChildAdded() ;
1137 // adjust font, controlsize etc
1138 DoSetWindowVariant( m_windowVariant
) ;
1140 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
1142 if (!m_macIsUserPane
)
1143 SetInitialBestSize(size
);
1145 SetCursor( *wxSTANDARD_CURSOR
) ;
1148 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1150 // Don't assert, in case we set the window variant before
1151 // the window is created
1152 // wxASSERT( m_peer->Ok() ) ;
1154 m_windowVariant
= variant
;
1156 if (m_peer
== NULL
|| !m_peer
->Ok())
1160 ThemeFontID themeFont
= kThemeSystemFont
;
1162 // we will get that from the settings later
1163 // and make this NORMAL later, but first
1164 // we have a few calculations that we must fix
1168 case wxWINDOW_VARIANT_NORMAL
:
1169 size
= kControlSizeNormal
;
1170 themeFont
= kThemeSystemFont
;
1173 case wxWINDOW_VARIANT_SMALL
:
1174 size
= kControlSizeSmall
;
1175 themeFont
= kThemeSmallSystemFont
;
1178 case wxWINDOW_VARIANT_MINI
:
1179 if (UMAGetSystemVersion() >= 0x1030 )
1181 // not always defined in the headers
1187 size
= kControlSizeSmall
;
1188 themeFont
= kThemeSmallSystemFont
;
1192 case wxWINDOW_VARIANT_LARGE
:
1193 size
= kControlSizeLarge
;
1194 themeFont
= kThemeSystemFont
;
1198 wxFAIL_MSG(_T("unexpected window variant"));
1202 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1205 font
.MacCreateThemeFont( themeFont
) ;
1209 void wxWindowMac::MacUpdateControlFont()
1211 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1215 bool wxWindowMac::SetFont(const wxFont
& font
)
1217 bool retval
= wxWindowBase::SetFont( font
);
1219 MacUpdateControlFont() ;
1224 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1226 bool retval
= wxWindowBase::SetForegroundColour( col
);
1229 MacUpdateControlFont();
1234 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1236 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1240 wxColour
newCol(GetBackgroundColour());
1242 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1243 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1244 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1245 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1247 brush
.SetColour( newCol
) ;
1249 MacSetBackgroundBrush( brush
) ;
1250 MacUpdateControlFont() ;
1255 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1257 m_macBackgroundBrush
= brush
;
1258 m_peer
->SetBackground( brush
) ;
1261 bool wxWindowMac::MacCanFocus() const
1263 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1264 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1265 // but the value range is nowhere documented
1266 Boolean keyExistsAndHasValidFormat
;
1267 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1268 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1270 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1276 UInt32 features
= 0 ;
1277 m_peer
->GetFeatures( &features
) ;
1279 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1283 void wxWindowMac::SetFocus()
1285 if ( !AcceptsFocus() )
1288 wxWindow
* former
= FindFocus() ;
1289 if ( former
== this )
1292 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1293 // we can only leave in case of an error
1294 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1295 if ( err
== errCouldntSetFocus
)
1298 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1300 #if !TARGET_API_MAC_OSX
1301 // emulate carbon events when running under CarbonLib where they are not natively available
1304 EventRef evRef
= NULL
;
1306 err
= MacCreateEvent(
1307 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1308 kEventAttributeUserEvent
, &evRef
);
1309 verify_noerr( err
);
1311 wxMacCarbonEvent
cEvent( evRef
) ;
1312 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1313 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1315 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1316 ReleaseEvent( evRef
) ;
1319 // send new focus event
1321 EventRef evRef
= NULL
;
1323 err
= MacCreateEvent(
1324 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1325 kEventAttributeUserEvent
, &evRef
);
1326 verify_noerr( err
);
1328 wxMacCarbonEvent
cEvent( evRef
) ;
1329 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1330 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1332 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1333 ReleaseEvent( evRef
) ;
1338 void wxWindowMac::DoCaptureMouse()
1340 wxApp::s_captureWindow
= this ;
1343 wxWindow
* wxWindowBase::GetCapture()
1345 return wxApp::s_captureWindow
;
1348 void wxWindowMac::DoReleaseMouse()
1350 wxApp::s_captureWindow
= NULL
;
1353 #if wxUSE_DRAG_AND_DROP
1355 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1357 if ( m_dropTarget
!= NULL
)
1358 delete m_dropTarget
;
1360 m_dropTarget
= pDropTarget
;
1361 if ( m_dropTarget
!= NULL
)
1369 // Old-style File Manager Drag & Drop
1370 void wxWindowMac::DragAcceptFiles(bool accept
)
1375 // Returns the size of the native control. In the case of the toplevel window
1376 // this is the content area root control
1378 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1379 int& w
, int& h
) const
1381 wxFAIL_MSG( wxT("Not currently supported") ) ;
1384 // From a wx position / size calculate the appropriate size of the native control
1386 bool wxWindowMac::MacGetBoundsForControl(
1390 int& w
, int& h
, bool adjustOrigin
) const
1392 // the desired size, minus the border pixels gives the correct size of the control
1396 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1397 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1398 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1400 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1401 if ( !isCompositing
)
1402 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1404 x
+= MacGetLeftBorderSize() ;
1405 y
+= MacGetTopBorderSize() ;
1406 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1407 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1410 AdjustForParentClientOrigin( x
, y
) ;
1412 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1413 if ( !GetParent()->IsTopLevel() )
1415 x
-= GetParent()->MacGetLeftBorderSize() ;
1416 y
-= GetParent()->MacGetTopBorderSize() ;
1422 // Get window size (not client size)
1423 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1426 m_peer
->GetRect( &bounds
) ;
1429 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1431 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1434 // get the position of the bounds of this window in client coordinates of its parent
1435 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1438 m_peer
->GetRect( &bounds
) ;
1440 int x1
= bounds
.left
;
1441 int y1
= bounds
.top
;
1443 // get the wx window position from the native one
1444 x1
-= MacGetLeftBorderSize() ;
1445 y1
-= MacGetTopBorderSize() ;
1447 if ( !IsTopLevel() )
1449 wxWindow
*parent
= GetParent();
1452 // we must first adjust it to be in window coordinates of the parent,
1453 // as otherwise it gets lost by the ClientAreaOrigin fix
1454 x1
+= parent
->MacGetLeftBorderSize() ;
1455 y1
+= parent
->MacGetTopBorderSize() ;
1457 // and now to client coordinates
1458 wxPoint
pt(parent
->GetClientAreaOrigin());
1470 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1472 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1473 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1475 Point localwhere
= { 0, 0 } ;
1482 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1489 MacRootWindowToWindow( x
, y
) ;
1491 wxPoint origin
= GetClientAreaOrigin() ;
1498 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1500 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1501 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1503 wxPoint origin
= GetClientAreaOrigin() ;
1509 MacWindowToRootWindow( x
, y
) ;
1511 Point localwhere
= { 0, 0 };
1517 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1525 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1527 wxPoint origin
= GetClientAreaOrigin() ;
1533 MacWindowToRootWindow( x
, y
) ;
1536 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1538 MacRootWindowToWindow( x
, y
) ;
1540 wxPoint origin
= GetClientAreaOrigin() ;
1547 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1556 if ( !IsTopLevel() )
1558 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1561 pt
.x
-= MacGetLeftBorderSize() ;
1562 pt
.y
-= MacGetTopBorderSize() ;
1563 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1573 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1582 MacWindowToRootWindow( &x1
, &y1
) ;
1590 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1599 if ( !IsTopLevel() )
1601 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1604 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1605 pt
.x
+= MacGetLeftBorderSize() ;
1606 pt
.y
+= MacGetTopBorderSize() ;
1616 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1625 MacRootWindowToWindow( &x1
, &y1
) ;
1633 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1635 RgnHandle rgn
= NewRgn() ;
1637 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1639 Rect structure
, content
;
1641 GetRegionBounds( rgn
, &content
) ;
1642 m_peer
->GetRect( &structure
) ;
1643 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1645 left
= content
.left
- structure
.left
;
1646 top
= content
.top
- structure
.top
;
1647 right
= structure
.right
- content
.right
;
1648 bottom
= structure
.bottom
- content
.bottom
;
1652 left
= top
= right
= bottom
= 0 ;
1658 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1660 wxSize sizeTotal
= size
;
1662 RgnHandle rgn
= NewRgn() ;
1663 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1665 Rect content
, structure
;
1666 GetRegionBounds( rgn
, &content
) ;
1667 m_peer
->GetRect( &structure
) ;
1669 // structure is in parent coordinates, but we only need width and height, so it's ok
1671 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1672 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1677 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1678 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1683 // Get size *available for subwindows* i.e. excluding menu bar etc.
1684 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1688 RgnHandle rgn
= NewRgn() ;
1690 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1691 GetRegionBounds( rgn
, &content
) ;
1693 m_peer
->GetRect( &content
) ;
1696 ww
= content
.right
- content
.left
;
1697 hh
= content
.bottom
- content
.top
;
1699 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1700 hh
-= m_hScrollBar
->GetSize().y
;
1702 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1703 ww
-= m_vScrollBar
->GetSize().x
;
1711 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1713 if (m_cursor
== cursor
)
1716 if (wxNullCursor
== cursor
)
1718 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1723 if ( ! wxWindowBase::SetCursor( cursor
) )
1727 wxASSERT_MSG( m_cursor
.Ok(),
1728 wxT("cursor must be valid after call to the base version"));
1730 wxWindowMac
*mouseWin
= 0 ;
1732 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1733 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1735 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1737 // TODO: If we ever get a GetCurrentEvent... replacement
1738 // for the mouse position, use it...
1741 ControlPartCode part
;
1742 ControlRef control
;
1745 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1747 mouseWin
= wxFindControlFromMacControl( control
) ;
1750 QDSwapPort( savePort
, NULL
) ;
1753 if ( mouseWin
== this && !wxIsBusy() )
1754 m_cursor
.MacInstall() ;
1760 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1762 menu
->SetInvokingWindow(this);
1765 if ( x
== -1 && y
== -1 )
1767 wxPoint mouse
= wxGetMousePosition();
1773 ClientToScreen( &x
, &y
) ;
1776 menu
->MacBeforeDisplay( true ) ;
1777 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1778 if ( HiWord(menuResult
) != 0 )
1781 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1782 int id
= wxMacCommandToId( macid
);
1783 wxMenuItem
* item
= NULL
;
1785 item
= menu
->FindItem( id
, &realmenu
) ;
1788 if (item
->IsCheckable())
1789 item
->Check( !item
->IsChecked() ) ;
1791 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1795 menu
->MacAfterDisplay( true ) ;
1796 menu
->SetInvokingWindow( NULL
);
1802 // ----------------------------------------------------------------------------
1804 // ----------------------------------------------------------------------------
1808 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1810 wxWindowBase::DoSetToolTip(tooltip
);
1813 m_tooltip
->SetWindow(this);
1818 void wxWindowMac::MacInvalidateBorders()
1820 if ( m_peer
== NULL
)
1823 bool vis
= MacIsReallyShown() ;
1827 int outerBorder
= MacGetLeftBorderSize() ;
1828 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1831 if ( outerBorder
== 0 )
1834 // now we know that we have something to do at all
1836 // as the borders are drawn on the parent we have to properly invalidate all these areas
1837 RgnHandle updateInner
, updateOuter
;
1840 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1841 updateInner
= NewRgn() ;
1842 updateOuter
= NewRgn() ;
1844 m_peer
->GetRect( &rect
) ;
1845 RectRgn( updateInner
, &rect
) ;
1846 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1847 RectRgn( updateOuter
, &rect
) ;
1848 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1850 #ifdef __WXMAC_OSX__
1851 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1853 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1855 InvalWindowRgn( tlw
, updateOuter
) ;
1858 DisposeRgn( updateOuter
) ;
1859 DisposeRgn( updateInner
) ;
1862 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1864 // this is never called for a toplevel window, so we know we have a parent
1865 int former_x
, former_y
, former_w
, former_h
;
1867 // Get true coordinates of former position
1868 DoGetPosition( &former_x
, &former_y
) ;
1869 DoGetSize( &former_w
, &former_h
) ;
1871 wxWindow
*parent
= GetParent();
1874 wxPoint
pt(parent
->GetClientAreaOrigin());
1879 int actualWidth
= width
;
1880 int actualHeight
= height
;
1884 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1885 actualWidth
= m_minWidth
;
1886 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1887 actualHeight
= m_minHeight
;
1888 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1889 actualWidth
= m_maxWidth
;
1890 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1891 actualHeight
= m_maxHeight
;
1893 bool doMove
= false, doResize
= false ;
1895 if ( actualX
!= former_x
|| actualY
!= former_y
)
1898 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1901 if ( doMove
|| doResize
)
1903 // as the borders are drawn outside the native control, we adjust now
1905 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1906 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1907 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1910 wxMacRectToNative( &bounds
, &r
) ;
1912 if ( !GetParent()->IsTopLevel() )
1913 wxMacWindowToNative( GetParent() , &r
) ;
1915 MacInvalidateBorders() ;
1917 m_cachedClippedRectValid
= false ;
1918 m_peer
->SetRect( &r
) ;
1920 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1922 MacInvalidateBorders() ;
1924 MacRepositionScrollBars() ;
1927 wxPoint
point(actualX
, actualY
);
1928 wxMoveEvent
event(point
, m_windowId
);
1929 event
.SetEventObject(this);
1930 GetEventHandler()->ProcessEvent(event
) ;
1935 MacRepositionScrollBars() ;
1936 wxSize
size(actualWidth
, actualHeight
);
1937 wxSizeEvent
event(size
, m_windowId
);
1938 event
.SetEventObject(this);
1939 GetEventHandler()->ProcessEvent(event
);
1944 wxSize
wxWindowMac::DoGetBestSize() const
1946 if ( m_macIsUserPane
|| IsTopLevel() )
1947 return wxWindowBase::DoGetBestSize() ;
1949 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1950 int bestWidth
, bestHeight
;
1952 m_peer
->GetBestRect( &bestsize
) ;
1953 if ( EmptyRect( &bestsize
) )
1958 bestsize
.bottom
= 16 ;
1960 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1962 bestsize
.bottom
= 16 ;
1965 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1967 bestsize
.bottom
= 24 ;
1972 // return wxWindowBase::DoGetBestSize() ;
1976 bestWidth
= bestsize
.right
- bestsize
.left
;
1977 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1978 if ( bestHeight
< 10 )
1981 return wxSize(bestWidth
, bestHeight
);
1984 // set the size of the window: if the dimensions are positive, just use them,
1985 // but if any of them is equal to -1, it means that we must find the value for
1986 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1987 // which case -1 is a valid value for x and y)
1989 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1990 // the width/height to best suit our contents, otherwise we reuse the current
1992 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1994 // get the current size and position...
1995 int currentX
, currentY
;
1996 int currentW
, currentH
;
1998 GetPosition(¤tX
, ¤tY
);
1999 GetSize(¤tW
, ¤tH
);
2001 // ... and don't do anything (avoiding flicker) if it's already ok
2002 if ( x
== currentX
&& y
== currentY
&&
2003 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2006 MacRepositionScrollBars() ; // we might have a real position shift
2011 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2013 if ( x
== wxDefaultCoord
)
2015 if ( y
== wxDefaultCoord
)
2019 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2021 wxSize size
= wxDefaultSize
;
2022 if ( width
== wxDefaultCoord
)
2024 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2026 size
= DoGetBestSize();
2031 // just take the current one
2036 if ( height
== wxDefaultCoord
)
2038 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2040 if ( size
.x
== wxDefaultCoord
)
2041 size
= DoGetBestSize();
2042 // else: already called DoGetBestSize() above
2048 // just take the current one
2053 DoMoveWindow( x
, y
, width
, height
);
2056 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2058 RgnHandle rgn
= NewRgn() ;
2060 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2062 GetRegionBounds( rgn
, &content
) ;
2072 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2075 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2077 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2079 int currentclientwidth
, currentclientheight
;
2080 int currentwidth
, currentheight
;
2082 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2083 GetSize( ¤twidth
, ¤theight
) ;
2085 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2086 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2090 void wxWindowMac::SetLabel(const wxString
& title
)
2092 m_label
= wxStripMenuCodes(title
) ;
2094 if ( m_peer
&& m_peer
->Ok() )
2095 m_peer
->SetLabel( m_label
) ;
2100 wxString
wxWindowMac::GetLabel() const
2105 bool wxWindowMac::Show(bool show
)
2107 bool former
= MacIsReallyShown() ;
2108 if ( !wxWindowBase::Show(show
) )
2111 // TODO: use visibilityChanged Carbon Event for OSX
2113 m_peer
->SetVisibility( show
, true ) ;
2115 if ( former
!= MacIsReallyShown() )
2116 MacPropagateVisibilityChanged() ;
2121 bool wxWindowMac::Enable(bool enable
)
2123 wxASSERT( m_peer
->Ok() ) ;
2124 bool former
= MacIsReallyEnabled() ;
2125 if ( !wxWindowBase::Enable(enable
) )
2128 m_peer
->Enable( enable
) ;
2130 if ( former
!= MacIsReallyEnabled() )
2131 MacPropagateEnabledStateChanged() ;
2137 // status change propagations (will be not necessary for OSX later )
2140 void wxWindowMac::MacPropagateVisibilityChanged()
2142 #if !TARGET_API_MAC_OSX
2143 MacVisibilityChanged() ;
2146 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2149 child
= node
->GetData();
2150 if ( child
->IsShown() )
2151 child
->MacPropagateVisibilityChanged() ;
2153 node
= node
->GetNext();
2158 void wxWindowMac::MacPropagateEnabledStateChanged()
2160 #if !TARGET_API_MAC_OSX
2161 MacEnabledStateChanged() ;
2164 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2167 child
= node
->GetData();
2168 if ( child
->IsEnabled() )
2169 child
->MacPropagateEnabledStateChanged() ;
2171 node
= node
->GetNext();
2176 void wxWindowMac::MacPropagateHiliteChanged()
2178 #if !TARGET_API_MAC_OSX
2179 MacHiliteChanged() ;
2182 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2185 child
= node
->GetData();
2186 if (child
/* && child->IsEnabled() */)
2187 child
->MacPropagateHiliteChanged() ;
2189 node
= node
->GetNext();
2195 // status change notifications
2198 void wxWindowMac::MacVisibilityChanged()
2202 void wxWindowMac::MacHiliteChanged()
2206 void wxWindowMac::MacEnabledStateChanged()
2211 // status queries on the inherited window's state
2214 bool wxWindowMac::MacIsReallyShown()
2216 // only under OSX the visibility of the TLW is taken into account
2217 if ( m_isBeingDeleted
)
2220 #if TARGET_API_MAC_OSX
2221 if ( m_peer
&& m_peer
->Ok() )
2222 return m_peer
->IsVisible();
2225 wxWindow
* win
= this ;
2226 while ( win
->IsShown() )
2228 if ( win
->IsTopLevel() )
2231 win
= win
->GetParent() ;
2239 bool wxWindowMac::MacIsReallyEnabled()
2241 return m_peer
->IsEnabled() ;
2244 bool wxWindowMac::MacIsReallyHilited()
2246 return m_peer
->IsActive();
2249 void wxWindowMac::MacFlashInvalidAreas()
2251 #if TARGET_API_MAC_OSX
2252 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2256 int wxWindowMac::GetCharHeight() const
2258 wxClientDC
dc( (wxWindowMac
*)this ) ;
2260 return dc
.GetCharHeight() ;
2263 int wxWindowMac::GetCharWidth() const
2265 wxClientDC
dc( (wxWindowMac
*)this ) ;
2267 return dc
.GetCharWidth() ;
2270 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2271 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2273 const wxFont
*fontToUse
= theFont
;
2275 fontToUse
= &m_font
;
2277 wxClientDC
dc( (wxWindowMac
*) this ) ;
2279 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2280 if ( externalLeading
)
2281 *externalLeading
= le
;
2291 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2292 * we always intersect with the entire window, not only with the client area
2295 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2297 if ( m_peer
== NULL
)
2300 if ( !MacIsReallyShown() )
2307 wxMacRectToNative( rect
, &r
) ;
2308 m_peer
->SetNeedsDisplay( &r
) ;
2312 m_peer
->SetNeedsDisplay() ;
2316 void wxWindowMac::Freeze()
2318 #if TARGET_API_MAC_OSX
2319 if ( !m_frozenness
++ )
2321 if ( m_peer
&& m_peer
->Ok() )
2322 m_peer
->SetDrawingEnabled( false ) ;
2327 void wxWindowMac::Thaw()
2329 #if TARGET_API_MAC_OSX
2330 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2332 if ( !--m_frozenness
)
2334 if ( m_peer
&& m_peer
->Ok() )
2336 m_peer
->SetDrawingEnabled( true ) ;
2337 m_peer
->InvalidateWithChildren() ;
2343 wxWindowMac
*wxGetActiveWindow()
2345 // actually this is a windows-only concept
2349 // Coordinates relative to the window
2350 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2352 // We really don't move the mouse programmatically under Mac.
2355 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2357 if ( MacGetTopLevelWindow() == NULL
)
2360 #if TARGET_API_MAC_OSX
2361 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2368 event
.GetDC()->Clear() ;
2372 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2377 int wxWindowMac::GetScrollPos(int orient
) const
2379 if ( orient
== wxHORIZONTAL
)
2382 return m_hScrollBar
->GetThumbPosition() ;
2387 return m_vScrollBar
->GetThumbPosition() ;
2393 // This now returns the whole range, not just the number
2394 // of positions that we can scroll.
2395 int wxWindowMac::GetScrollRange(int orient
) const
2397 if ( orient
== wxHORIZONTAL
)
2400 return m_hScrollBar
->GetRange() ;
2405 return m_vScrollBar
->GetRange() ;
2411 int wxWindowMac::GetScrollThumb(int orient
) const
2413 if ( orient
== wxHORIZONTAL
)
2416 return m_hScrollBar
->GetThumbSize() ;
2421 return m_vScrollBar
->GetThumbSize() ;
2427 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2429 if ( orient
== wxHORIZONTAL
)
2432 m_hScrollBar
->SetThumbPosition( pos
) ;
2437 m_vScrollBar
->SetThumbPosition( pos
) ;
2442 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2443 // our own window origin is at leftOrigin/rightOrigin
2446 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2452 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2453 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2455 // back to the surrounding frame rectangle
2456 m_peer
->GetRect( &rect
) ;
2457 InsetRect( &rect
, -1 , -1 ) ;
2459 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2460 if ( UMAGetSystemVersion() >= 0x1030 )
2462 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2463 rect
.bottom
- rect
.top
) ;
2465 HIThemeFrameDrawInfo info
;
2466 memset( &info
, 0 , sizeof(info
) ) ;
2470 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2471 info
.isFocused
= hasFocus
;
2473 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2474 wxASSERT( cgContext
) ;
2476 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2478 info
.kind
= kHIThemeFrameTextFieldSquare
;
2479 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2481 else if ( HasFlag(wxSIMPLE_BORDER
) )
2483 info
.kind
= kHIThemeFrameListBox
;
2484 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2486 else if ( hasFocus
)
2488 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2491 m_peer
->GetRect( &rect
) ;
2492 if ( hasBothScrollbars
)
2494 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2495 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2496 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2497 HIThemeGrowBoxDrawInfo info
;
2498 memset( &info
, 0, sizeof(info
) ) ;
2500 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2501 info
.kind
= kHIThemeGrowBoxKindNone
;
2502 info
.size
= kHIThemeGrowBoxSizeNormal
;
2503 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2504 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2510 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2514 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2515 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2518 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2519 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2520 else if ( HasFlag(wxSIMPLE_BORDER
) )
2521 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2524 DrawThemeFocusRect( &rect
, true ) ;
2526 if ( hasBothScrollbars
)
2528 // GetThemeStandaloneGrowBoxBounds
2529 // DrawThemeStandaloneNoGrowBox
2534 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2536 if ( child
== m_hScrollBar
)
2537 m_hScrollBar
= NULL
;
2538 if ( child
== m_vScrollBar
)
2539 m_vScrollBar
= NULL
;
2541 wxWindowBase::RemoveChild( child
) ;
2544 // New function that will replace some of the above.
2545 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2546 int range
, bool refresh
)
2550 if ( orient
== wxHORIZONTAL
)
2554 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2555 if ( m_hScrollBar
->IsShown() != showScroller
)
2556 m_hScrollBar
->Show( showScroller
) ;
2558 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2565 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2566 if ( m_vScrollBar
->IsShown() != showScroller
)
2567 m_vScrollBar
->Show( showScroller
) ;
2569 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2573 MacRepositionScrollBars() ;
2576 // Does a physical scroll
2577 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2579 if ( dx
== 0 && dy
== 0 )
2582 int width
, height
;
2583 GetClientSize( &width
, &height
) ;
2585 #if TARGET_API_MAC_OSX
2586 if ( true /* m_peer->IsCompositing() */ )
2588 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2589 // area is scrolled, this does not occur if width and height are 2 pixels less,
2590 // TODO: write optimal workaround
2591 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2593 scrollrect
.Intersect( *rect
) ;
2595 if ( m_peer
->GetNeedsDisplay() )
2597 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2598 // either immediate redraw or full invalidate
2600 // is the better overall solution, as it does not slow down scrolling
2601 m_peer
->SetNeedsDisplay() ;
2603 // this would be the preferred version for fast drawing controls
2605 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2606 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2607 HIViewRender(m_peer
->GetControlRef()) ;
2614 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2615 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2616 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2618 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2619 // either immediate redraw or full invalidate
2621 // is the better overall solution, as it does not slow down scrolling
2622 m_peer
->SetNeedsDisplay() ;
2624 // this would be the preferred version for fast drawing controls
2626 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2627 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2628 HIViewRender(m_peer
->GetControlRef()) ;
2642 RgnHandle updateRgn
= NewRgn() ;
2645 wxClientDC
dc(this) ;
2646 wxMacPortSetter
helper(&dc
) ;
2648 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2649 //scrollrect.top += MacGetTopBorderSize() ;
2650 //scrollrect.left += MacGetLeftBorderSize() ;
2651 scrollrect
.bottom
= scrollrect
.top
+ height
;
2652 scrollrect
.right
= scrollrect
.left
+ width
;
2656 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2657 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2658 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2661 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2663 // now scroll the former update region as well and add the new update region
2664 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2665 RgnHandle formerUpdateRgn
= NewRgn() ;
2666 RgnHandle scrollRgn
= NewRgn() ;
2667 RectRgn( scrollRgn
, &scrollrect
) ;
2668 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2670 LocalToGlobal( &pt
) ;
2671 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2672 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2674 if ( !EmptyRgn( formerUpdateRgn
) )
2676 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2677 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2678 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2681 InvalWindowRgn(rootWindow
, updateRgn
) ;
2682 DisposeRgn( updateRgn
) ;
2683 DisposeRgn( formerUpdateRgn
) ;
2684 DisposeRgn( scrollRgn
) ;
2692 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2694 child
= node
->GetData();
2697 if (child
== m_vScrollBar
)
2699 if (child
== m_hScrollBar
)
2701 if (child
->IsTopLevel())
2704 child
->GetPosition( &x
, &y
);
2705 child
->GetSize( &w
, &h
);
2708 wxRect
rc( x
, y
, w
, h
);
2709 if (rect
->Intersects( rc
))
2710 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2714 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2719 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2721 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2723 wxScrollWinEvent wevent
;
2724 wevent
.SetPosition(event
.GetPosition());
2725 wevent
.SetOrientation(event
.GetOrientation());
2726 wevent
.SetEventObject(this);
2728 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2729 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2730 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2731 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2732 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2733 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2734 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2735 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2736 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2737 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2738 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2739 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2740 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2741 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2742 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2743 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2745 GetEventHandler()->ProcessEvent(wevent
);
2749 // Get the window with the focus
2750 wxWindowMac
*wxWindowBase::DoFindFocus()
2752 ControlRef control
;
2753 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2754 return wxFindControlFromMacControl( control
) ;
2757 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2759 // panel wants to track the window which was the last to have focus in it,
2760 // so we want to set ourselves as the window which last had focus
2762 // notice that it's also important to do it upwards the tree because
2763 // otherwise when the top level panel gets focus, it won't set it back to
2764 // us, but to some other sibling
2766 // CS: don't know if this is still needed:
2767 //wxChildFocusEvent eventFocus(this);
2768 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2770 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2772 #if wxMAC_USE_CORE_GRAPHICS
2773 GetParent()->Refresh() ;
2775 wxMacWindowStateSaver
sv( this ) ;
2778 m_peer
->GetRect( &rect
) ;
2779 // auf den umgebenden Rahmen zur\9fck
2780 InsetRect( &rect
, -1 , -1 ) ;
2782 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2786 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2788 rect
.right
+= pt
.x
;
2790 rect
.bottom
+= pt
.y
;
2793 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2794 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2795 if ( !bIsFocusEvent
)
2797 // as this erases part of the frame we have to redraw borders
2798 // and because our z-ordering is not always correct (staticboxes)
2799 // we have to invalidate things, we cannot simple redraw
2800 MacInvalidateBorders() ;
2808 void wxWindowMac::OnInternalIdle()
2810 // This calls the UI-update mechanism (querying windows for
2811 // menu/toolbar/control state information)
2812 if (wxUpdateUIEvent::CanUpdate(this))
2813 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2816 // Raise the window to the top of the Z order
2817 void wxWindowMac::Raise()
2819 m_peer
->SetZOrder( true , NULL
) ;
2822 // Lower the window to the bottom of the Z order
2823 void wxWindowMac::Lower()
2825 m_peer
->SetZOrder( false , NULL
) ;
2828 // static wxWindow *gs_lastWhich = NULL;
2830 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2832 // first trigger a set cursor event
2834 wxPoint clientorigin
= GetClientAreaOrigin() ;
2835 wxSize clientsize
= GetClientSize() ;
2837 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2839 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2841 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2842 if ( processedEvtSetCursor
&& event
.HasCursor() )
2844 cursor
= event
.GetCursor() ;
2848 // the test for processedEvtSetCursor is here to prevent using m_cursor
2849 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2850 // it - this is a way to say that our cursor shouldn't be used for this
2852 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2855 if ( !wxIsBusy() && !GetParent() )
2856 cursor
= *wxSTANDARD_CURSOR
;
2860 cursor
.MacInstall() ;
2863 return cursor
.Ok() ;
2866 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2870 return m_tooltip
->GetTip() ;
2873 return wxEmptyString
;
2876 void wxWindowMac::ClearBackground()
2882 void wxWindowMac::Update()
2884 #if TARGET_API_MAC_OSX
2885 MacGetTopLevelWindow()->MacPerformUpdates() ;
2887 ::Draw1Control( m_peer
->GetControlRef() ) ;
2891 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2893 wxTopLevelWindowMac
* win
= NULL
;
2894 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2896 win
= wxFindWinFromMacWindow( window
) ;
2901 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2903 MacUpdateClippedRects() ;
2905 return m_cachedClippedClientRect
;
2908 const wxRect
& wxWindowMac::MacGetClippedRect() const
2910 MacUpdateClippedRects() ;
2912 return m_cachedClippedRect
;
2915 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2917 MacUpdateClippedRects() ;
2919 return m_cachedClippedRectWithOuterStructure
;
2922 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2924 static wxRegion emptyrgn
;
2926 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2928 MacUpdateClippedRects() ;
2929 if ( includeOuterStructures
)
2930 return m_cachedClippedRegionWithOuterStructure
;
2932 return m_cachedClippedRegion
;
2940 void wxWindowMac::MacUpdateClippedRects() const
2942 if ( m_cachedClippedRectValid
)
2945 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2946 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2947 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2948 // to add focus borders everywhere
2950 Rect r
, rIncludingOuterStructures
;
2952 m_peer
->GetRect( &r
) ;
2953 r
.left
-= MacGetLeftBorderSize() ;
2954 r
.top
-= MacGetTopBorderSize() ;
2955 r
.bottom
+= MacGetBottomBorderSize() ;
2956 r
.right
+= MacGetRightBorderSize() ;
2963 rIncludingOuterStructures
= r
;
2964 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2966 wxRect cl
= GetClientRect() ;
2967 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2971 const wxWindow
* child
= this ;
2972 const wxWindow
* parent
= NULL
;
2974 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2976 if ( parent
->MacIsChildOfClientArea(child
) )
2978 size
= parent
->GetClientSize() ;
2979 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2985 // this will be true for scrollbars, toolbars etc.
2986 size
= parent
->GetSize() ;
2987 y
= parent
->MacGetTopBorderSize() ;
2988 x
= parent
->MacGetLeftBorderSize() ;
2989 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2990 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2993 parent
->MacWindowToRootWindow( &x
, &y
) ;
2994 MacRootWindowToWindow( &x
, &y
) ;
2996 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2998 // the wxwindow and client rects will always be clipped
2999 SectRect( &r
, &rparent
, &r
) ;
3000 SectRect( &rClient
, &rparent
, &rClient
) ;
3002 // the structure only at 'hard' borders
3003 if ( parent
->MacClipChildren() ||
3004 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
3006 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
3012 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
3013 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
3014 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
3015 m_cachedClippedRectWithOuterStructure
= wxRect(
3016 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
3017 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
3018 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
3020 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
3021 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
3022 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
3024 m_cachedClippedRectValid
= true ;
3028 This function must not change the updatergn !
3030 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3032 bool handled
= false ;
3034 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3035 GetRegionBounds( updatergn
, &updatebounds
) ;
3037 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3039 if ( !EmptyRgn(updatergn
) )
3041 RgnHandle newupdate
= NewRgn() ;
3042 wxSize point
= GetClientSize() ;
3043 wxPoint origin
= GetClientAreaOrigin() ;
3044 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3045 SectRgn( newupdate
, updatergn
, newupdate
) ;
3047 // first send an erase event to the entire update area
3049 // for the toplevel window this really is the entire area
3050 // for all the others only their client area, otherwise they
3051 // might be drawing with full alpha and eg put blue into
3052 // the grow-box area of a scrolled window (scroll sample)
3053 wxDC
* dc
= new wxWindowDC(this);
3055 dc
->SetClippingRegion(wxRegion(updatergn
));
3057 dc
->SetClippingRegion(wxRegion(newupdate
));
3059 wxEraseEvent
eevent( GetId(), dc
);
3060 eevent
.SetEventObject( this );
3061 GetEventHandler()->ProcessEvent( eevent
);
3065 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3066 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3067 m_updateRegion
= newupdate
;
3068 DisposeRgn( newupdate
) ;
3070 if ( !m_updateRegion
.Empty() )
3072 // paint the window itself
3075 event
.SetTimestamp(time
);
3076 event
.SetEventObject(this);
3077 GetEventHandler()->ProcessEvent(event
);
3081 // now we cannot rely on having its borders drawn by a window itself, as it does not
3082 // get the updateRgn wide enough to always do so, so we do it from the parent
3083 // this would also be the place to draw any custom backgrounds for native controls
3084 // in Composited windowing
3085 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3089 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3091 child
= node
->GetData();
3094 if (child
== m_vScrollBar
)
3096 if (child
== m_hScrollBar
)
3098 if (child
->IsTopLevel())
3100 if (!child
->IsShown())
3103 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3105 child
->GetPosition( &x
, &y
);
3106 child
->GetSize( &w
, &h
);
3107 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3108 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3109 InsetRect( &childRect
, -10 , -10) ;
3111 if ( RectInRgn( &childRect
, updatergn
) )
3113 // paint custom borders
3114 wxNcPaintEvent
eventNc( child
->GetId() );
3115 eventNc
.SetEventObject( child
);
3116 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3118 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3119 if ( UMAGetSystemVersion() >= 0x1030 )
3121 child
->MacPaintBorders(0, 0) ;
3126 wxWindowDC
dc(this) ;
3127 dc
.SetClippingRegion(wxRegion(updatergn
));
3128 wxMacPortSetter
helper(&dc
) ;
3129 child
->MacPaintBorders(0, 0) ;
3140 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3142 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3146 if ( iter
->IsTopLevel() )
3147 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3149 iter
= iter
->GetParent() ;
3152 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3157 void wxWindowMac::MacCreateScrollBars( long style
)
3159 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3161 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3163 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3164 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3165 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3166 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3168 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3169 variant
= wxWINDOW_VARIANT_SMALL
;
3172 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3174 GetClientSize( &width
, &height
) ;
3176 wxPoint
vPoint(width
- scrlsize
, 0) ;
3177 wxSize
vSize(scrlsize
, height
- adjust
) ;
3178 wxPoint
hPoint(0, height
- scrlsize
) ;
3179 wxSize
hSize(width
- adjust
, scrlsize
) ;
3181 if ( style
& wxVSCROLL
)
3182 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3184 if ( style
& wxHSCROLL
)
3185 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3188 // because the create does not take into account the client area origin
3189 // we might have a real position shift
3190 MacRepositionScrollBars() ;
3193 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3195 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3200 void wxWindowMac::MacRepositionScrollBars()
3202 if ( !m_hScrollBar
&& !m_vScrollBar
)
3205 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3206 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3207 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3209 // get real client area
3211 GetSize( &width
, &height
);
3213 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3214 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3216 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3217 wxSize
vSize( scrlsize
, height
- adjust
) ;
3218 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3219 wxSize
hSize( width
- adjust
, scrlsize
) ;
3222 int x
= 0, y
= 0, w
, h
;
3223 GetSize( &w
, &h
) ;
3225 MacClientToRootWindow( &x
, &y
) ;
3226 MacClientToRootWindow( &w
, &h
) ;
3228 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3230 int totW
= 10000 , totH
= 10000;
3233 if ( iter
->IsTopLevel() )
3235 iter
->GetSize( &totW
, &totH
) ;
3239 iter
= iter
->GetParent() ;
3253 if ( w
- x
>= totW
)
3258 if ( h
- y
>= totH
)
3266 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3268 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3271 bool wxWindowMac::AcceptsFocus() const
3273 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3276 void wxWindowMac::MacSuperChangedPosition()
3278 // only window-absolute structures have to be moved i.e. controls
3280 m_cachedClippedRectValid
= false ;
3283 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3286 child
= node
->GetData();
3287 child
->MacSuperChangedPosition() ;
3289 node
= node
->GetNext();
3293 void wxWindowMac::MacTopLevelWindowChangedPosition()
3295 // only screen-absolute structures have to be moved i.e. glcanvas
3298 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3301 child
= node
->GetData();
3302 child
->MacTopLevelWindowChangedPosition() ;
3304 node
= node
->GetNext();
3308 long wxWindowMac::MacGetLeftBorderSize() const
3315 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3317 // this metric is only the 'outset' outside the simple frame rect
3318 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3321 else if (HasFlag(wxSIMPLE_BORDER
))
3323 // this metric is only the 'outset' outside the simple frame rect
3324 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3331 long wxWindowMac::MacGetRightBorderSize() const
3333 // they are all symmetric in mac themes
3334 return MacGetLeftBorderSize() ;
3337 long wxWindowMac::MacGetTopBorderSize() const
3339 // they are all symmetric in mac themes
3340 return MacGetLeftBorderSize() ;
3343 long wxWindowMac::MacGetBottomBorderSize() const
3345 // they are all symmetric in mac themes
3346 return MacGetLeftBorderSize() ;
3349 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3351 return style
& ~wxBORDER_MASK
;
3354 // Find the wxWindowMac at the current mouse position, returning the mouse
3356 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3358 pt
= wxGetMousePosition();
3359 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3364 // Get the current mouse position.
3365 wxPoint
wxGetMousePosition()
3369 wxGetMousePosition( &x
, &y
);
3371 return wxPoint(x
, y
);
3374 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3376 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3378 // copied from wxGTK : CS
3379 // VZ: shouldn't we move this to base class then?
3381 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3384 // (a) it's a command event and so is propagated to the parent
3385 // (b) under MSW it can be generated from kbd too
3386 // (c) it uses screen coords (because of (a))
3387 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3389 this->ClientToScreen(event
.GetPosition()));
3390 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3399 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3401 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3402 CallNextEventHandler(
3403 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3404 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3407 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3411 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3415 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3416 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3421 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3423 return eventNotHandledErr
;
3426 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3428 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3429 if ( !wxWindowBase::Reparent(newParent
) )
3432 // copied from MacPostControlCreate
3433 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3435 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3437 ::EmbedControl( m_peer
->GetControlRef() , container
) ;