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"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
33 #include "wx/layout.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
== wxDefaultCoord
&& y
== wxDefaultCoord
)
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
)
2549 bool triggerSizeEvent
= false;
2551 if ( orient
== wxHORIZONTAL
)
2555 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2556 if ( m_hScrollBar
->IsShown() != showScroller
)
2558 m_hScrollBar
->Show( showScroller
);
2559 triggerSizeEvent
= true;
2562 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2569 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2570 if ( m_vScrollBar
->IsShown() != showScroller
)
2572 m_vScrollBar
->Show( showScroller
) ;
2573 triggerSizeEvent
= true;
2576 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2580 MacRepositionScrollBars() ;
2581 if ( triggerSizeEvent
)
2583 wxSizeEvent
event(GetSize(), m_windowId
);
2584 event
.SetEventObject(this);
2585 GetEventHandler()->ProcessEvent(event
);
2589 // Does a physical scroll
2590 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2592 if ( dx
== 0 && dy
== 0 )
2595 int width
, height
;
2596 GetClientSize( &width
, &height
) ;
2598 #if TARGET_API_MAC_OSX
2599 if ( true /* m_peer->IsCompositing() */ )
2601 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2602 // area is scrolled, this does not occur if width and height are 2 pixels less,
2603 // TODO: write optimal workaround
2604 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2606 scrollrect
.Intersect( *rect
) ;
2608 if ( m_peer
->GetNeedsDisplay() )
2610 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2611 // either immediate redraw or full invalidate
2613 // is the better overall solution, as it does not slow down scrolling
2614 m_peer
->SetNeedsDisplay() ;
2616 // this would be the preferred version for fast drawing controls
2618 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2619 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2620 HIViewRender(m_peer
->GetControlRef()) ;
2627 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2628 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2629 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2631 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2632 // either immediate redraw or full invalidate
2634 // is the better overall solution, as it does not slow down scrolling
2635 m_peer
->SetNeedsDisplay() ;
2637 // this would be the preferred version for fast drawing controls
2639 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2640 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2641 HIViewRender(m_peer
->GetControlRef()) ;
2655 RgnHandle updateRgn
= NewRgn() ;
2658 wxClientDC
dc(this) ;
2659 wxMacPortSetter
helper(&dc
) ;
2661 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2662 //scrollrect.top += MacGetTopBorderSize() ;
2663 //scrollrect.left += MacGetLeftBorderSize() ;
2664 scrollrect
.bottom
= scrollrect
.top
+ height
;
2665 scrollrect
.right
= scrollrect
.left
+ width
;
2669 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2670 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2671 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2674 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2676 // now scroll the former update region as well and add the new update region
2677 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2678 RgnHandle formerUpdateRgn
= NewRgn() ;
2679 RgnHandle scrollRgn
= NewRgn() ;
2680 RectRgn( scrollRgn
, &scrollrect
) ;
2681 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2683 LocalToGlobal( &pt
) ;
2684 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2685 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2687 if ( !EmptyRgn( formerUpdateRgn
) )
2689 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2690 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2691 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2694 InvalWindowRgn(rootWindow
, updateRgn
) ;
2695 DisposeRgn( updateRgn
) ;
2696 DisposeRgn( formerUpdateRgn
) ;
2697 DisposeRgn( scrollRgn
) ;
2705 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2707 child
= node
->GetData();
2710 if (child
== m_vScrollBar
)
2712 if (child
== m_hScrollBar
)
2714 if (child
->IsTopLevel())
2717 child
->GetPosition( &x
, &y
);
2718 child
->GetSize( &w
, &h
);
2721 wxRect
rc( x
, y
, w
, h
);
2722 if (rect
->Intersects( rc
))
2723 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2727 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2732 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2734 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2736 wxScrollWinEvent wevent
;
2737 wevent
.SetPosition(event
.GetPosition());
2738 wevent
.SetOrientation(event
.GetOrientation());
2739 wevent
.SetEventObject(this);
2741 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2742 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2743 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2744 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2745 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2746 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2747 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2748 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2749 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2750 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2751 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2752 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2753 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2754 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2755 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2756 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2758 GetEventHandler()->ProcessEvent(wevent
);
2762 // Get the window with the focus
2763 wxWindowMac
*wxWindowBase::DoFindFocus()
2765 ControlRef control
;
2766 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2767 return wxFindControlFromMacControl( control
) ;
2770 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2772 // panel wants to track the window which was the last to have focus in it,
2773 // so we want to set ourselves as the window which last had focus
2775 // notice that it's also important to do it upwards the tree because
2776 // otherwise when the top level panel gets focus, it won't set it back to
2777 // us, but to some other sibling
2779 // CS: don't know if this is still needed:
2780 //wxChildFocusEvent eventFocus(this);
2781 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2783 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2785 #if wxMAC_USE_CORE_GRAPHICS
2786 GetParent()->Refresh() ;
2788 wxMacWindowStateSaver
sv( this ) ;
2791 m_peer
->GetRect( &rect
) ;
2792 // auf den umgebenden Rahmen zur\9fck
2793 InsetRect( &rect
, -1 , -1 ) ;
2795 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2799 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2801 rect
.right
+= pt
.x
;
2803 rect
.bottom
+= pt
.y
;
2806 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2807 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2808 if ( !bIsFocusEvent
)
2810 // as this erases part of the frame we have to redraw borders
2811 // and because our z-ordering is not always correct (staticboxes)
2812 // we have to invalidate things, we cannot simple redraw
2813 MacInvalidateBorders() ;
2821 void wxWindowMac::OnInternalIdle()
2823 // This calls the UI-update mechanism (querying windows for
2824 // menu/toolbar/control state information)
2825 if (wxUpdateUIEvent::CanUpdate(this))
2826 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2829 // Raise the window to the top of the Z order
2830 void wxWindowMac::Raise()
2832 m_peer
->SetZOrder( true , NULL
) ;
2835 // Lower the window to the bottom of the Z order
2836 void wxWindowMac::Lower()
2838 m_peer
->SetZOrder( false , NULL
) ;
2841 // static wxWindow *gs_lastWhich = NULL;
2843 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2845 // first trigger a set cursor event
2847 wxPoint clientorigin
= GetClientAreaOrigin() ;
2848 wxSize clientsize
= GetClientSize() ;
2850 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2852 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2854 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2855 if ( processedEvtSetCursor
&& event
.HasCursor() )
2857 cursor
= event
.GetCursor() ;
2861 // the test for processedEvtSetCursor is here to prevent using m_cursor
2862 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2863 // it - this is a way to say that our cursor shouldn't be used for this
2865 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2868 if ( !wxIsBusy() && !GetParent() )
2869 cursor
= *wxSTANDARD_CURSOR
;
2873 cursor
.MacInstall() ;
2876 return cursor
.Ok() ;
2879 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2883 return m_tooltip
->GetTip() ;
2886 return wxEmptyString
;
2889 void wxWindowMac::ClearBackground()
2895 void wxWindowMac::Update()
2897 #if TARGET_API_MAC_OSX
2898 MacGetTopLevelWindow()->MacPerformUpdates() ;
2900 ::Draw1Control( m_peer
->GetControlRef() ) ;
2904 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2906 wxTopLevelWindowMac
* win
= NULL
;
2907 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2909 win
= wxFindWinFromMacWindow( window
) ;
2914 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2916 MacUpdateClippedRects() ;
2918 return m_cachedClippedClientRect
;
2921 const wxRect
& wxWindowMac::MacGetClippedRect() const
2923 MacUpdateClippedRects() ;
2925 return m_cachedClippedRect
;
2928 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2930 MacUpdateClippedRects() ;
2932 return m_cachedClippedRectWithOuterStructure
;
2935 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2937 static wxRegion emptyrgn
;
2939 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2941 MacUpdateClippedRects() ;
2942 if ( includeOuterStructures
)
2943 return m_cachedClippedRegionWithOuterStructure
;
2945 return m_cachedClippedRegion
;
2953 void wxWindowMac::MacUpdateClippedRects() const
2955 if ( m_cachedClippedRectValid
)
2958 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2959 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2960 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2961 // to add focus borders everywhere
2963 Rect r
, rIncludingOuterStructures
;
2965 m_peer
->GetRect( &r
) ;
2966 r
.left
-= MacGetLeftBorderSize() ;
2967 r
.top
-= MacGetTopBorderSize() ;
2968 r
.bottom
+= MacGetBottomBorderSize() ;
2969 r
.right
+= MacGetRightBorderSize() ;
2976 rIncludingOuterStructures
= r
;
2977 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2979 wxRect cl
= GetClientRect() ;
2980 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2984 const wxWindow
* child
= this ;
2985 const wxWindow
* parent
= NULL
;
2987 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2989 if ( parent
->MacIsChildOfClientArea(child
) )
2991 size
= parent
->GetClientSize() ;
2992 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2998 // this will be true for scrollbars, toolbars etc.
2999 size
= parent
->GetSize() ;
3000 y
= parent
->MacGetTopBorderSize() ;
3001 x
= parent
->MacGetLeftBorderSize() ;
3002 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
3003 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
3006 parent
->MacWindowToRootWindow( &x
, &y
) ;
3007 MacRootWindowToWindow( &x
, &y
) ;
3009 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
3011 // the wxwindow and client rects will always be clipped
3012 SectRect( &r
, &rparent
, &r
) ;
3013 SectRect( &rClient
, &rparent
, &rClient
) ;
3015 // the structure only at 'hard' borders
3016 if ( parent
->MacClipChildren() ||
3017 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
3019 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
3025 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
3026 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
3027 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
3028 m_cachedClippedRectWithOuterStructure
= wxRect(
3029 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
3030 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
3031 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
3033 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
3034 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
3035 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
3037 m_cachedClippedRectValid
= true ;
3041 This function must not change the updatergn !
3043 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3045 bool handled
= false ;
3047 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3048 GetRegionBounds( updatergn
, &updatebounds
) ;
3050 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3052 if ( !EmptyRgn(updatergn
) )
3054 RgnHandle newupdate
= NewRgn() ;
3055 wxSize point
= GetClientSize() ;
3056 wxPoint origin
= GetClientAreaOrigin() ;
3057 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3058 SectRgn( newupdate
, updatergn
, newupdate
) ;
3060 // first send an erase event to the entire update area
3062 // for the toplevel window this really is the entire area
3063 // for all the others only their client area, otherwise they
3064 // might be drawing with full alpha and eg put blue into
3065 // the grow-box area of a scrolled window (scroll sample)
3066 wxDC
* dc
= new wxWindowDC(this);
3068 dc
->SetClippingRegion(wxRegion(updatergn
));
3070 dc
->SetClippingRegion(wxRegion(newupdate
));
3072 wxEraseEvent
eevent( GetId(), dc
);
3073 eevent
.SetEventObject( this );
3074 GetEventHandler()->ProcessEvent( eevent
);
3078 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3079 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3080 m_updateRegion
= newupdate
;
3081 DisposeRgn( newupdate
) ;
3083 if ( !m_updateRegion
.Empty() )
3085 // paint the window itself
3088 event
.SetTimestamp(time
);
3089 event
.SetEventObject(this);
3090 GetEventHandler()->ProcessEvent(event
);
3094 // now we cannot rely on having its borders drawn by a window itself, as it does not
3095 // get the updateRgn wide enough to always do so, so we do it from the parent
3096 // this would also be the place to draw any custom backgrounds for native controls
3097 // in Composited windowing
3098 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3102 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3104 child
= node
->GetData();
3107 if (child
== m_vScrollBar
)
3109 if (child
== m_hScrollBar
)
3111 if (child
->IsTopLevel())
3113 if (!child
->IsShown())
3116 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3118 child
->GetPosition( &x
, &y
);
3119 child
->GetSize( &w
, &h
);
3120 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3121 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3122 InsetRect( &childRect
, -10 , -10) ;
3124 if ( RectInRgn( &childRect
, updatergn
) )
3126 // paint custom borders
3127 wxNcPaintEvent
eventNc( child
->GetId() );
3128 eventNc
.SetEventObject( child
);
3129 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3131 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3132 if ( UMAGetSystemVersion() >= 0x1030 )
3134 child
->MacPaintBorders(0, 0) ;
3139 wxWindowDC
dc(this) ;
3140 dc
.SetClippingRegion(wxRegion(updatergn
));
3141 wxMacPortSetter
helper(&dc
) ;
3142 child
->MacPaintBorders(0, 0) ;
3153 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3155 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3159 if ( iter
->IsTopLevel() )
3160 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3162 iter
= iter
->GetParent() ;
3165 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3170 void wxWindowMac::MacCreateScrollBars( long style
)
3172 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3174 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3176 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3177 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3178 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3179 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3181 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3182 variant
= wxWINDOW_VARIANT_SMALL
;
3185 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3187 GetClientSize( &width
, &height
) ;
3189 wxPoint
vPoint(width
- scrlsize
, 0) ;
3190 wxSize
vSize(scrlsize
, height
- adjust
) ;
3191 wxPoint
hPoint(0, height
- scrlsize
) ;
3192 wxSize
hSize(width
- adjust
, scrlsize
) ;
3194 if ( style
& wxVSCROLL
)
3195 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3197 if ( style
& wxHSCROLL
)
3198 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3201 // because the create does not take into account the client area origin
3202 // we might have a real position shift
3203 MacRepositionScrollBars() ;
3206 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3208 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3213 void wxWindowMac::MacRepositionScrollBars()
3215 if ( !m_hScrollBar
&& !m_vScrollBar
)
3218 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3219 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3220 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3222 // get real client area
3224 GetSize( &width
, &height
);
3226 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3227 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3229 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3230 wxSize
vSize( scrlsize
, height
- adjust
) ;
3231 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3232 wxSize
hSize( width
- adjust
, scrlsize
) ;
3235 int x
= 0, y
= 0, w
, h
;
3236 GetSize( &w
, &h
) ;
3238 MacClientToRootWindow( &x
, &y
) ;
3239 MacClientToRootWindow( &w
, &h
) ;
3241 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3243 int totW
= 10000 , totH
= 10000;
3246 if ( iter
->IsTopLevel() )
3248 iter
->GetSize( &totW
, &totH
) ;
3252 iter
= iter
->GetParent() ;
3266 if ( w
- x
>= totW
)
3271 if ( h
- y
>= totH
)
3279 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3281 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3284 bool wxWindowMac::AcceptsFocus() const
3286 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3289 void wxWindowMac::MacSuperChangedPosition()
3291 // only window-absolute structures have to be moved i.e. controls
3293 m_cachedClippedRectValid
= false ;
3296 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3299 child
= node
->GetData();
3300 child
->MacSuperChangedPosition() ;
3302 node
= node
->GetNext();
3306 void wxWindowMac::MacTopLevelWindowChangedPosition()
3308 // only screen-absolute structures have to be moved i.e. glcanvas
3311 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3314 child
= node
->GetData();
3315 child
->MacTopLevelWindowChangedPosition() ;
3317 node
= node
->GetNext();
3321 long wxWindowMac::MacGetLeftBorderSize() const
3328 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3330 // this metric is only the 'outset' outside the simple frame rect
3331 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3334 else if (HasFlag(wxSIMPLE_BORDER
))
3336 // this metric is only the 'outset' outside the simple frame rect
3337 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3344 long wxWindowMac::MacGetRightBorderSize() const
3346 // they are all symmetric in mac themes
3347 return MacGetLeftBorderSize() ;
3350 long wxWindowMac::MacGetTopBorderSize() const
3352 // they are all symmetric in mac themes
3353 return MacGetLeftBorderSize() ;
3356 long wxWindowMac::MacGetBottomBorderSize() const
3358 // they are all symmetric in mac themes
3359 return MacGetLeftBorderSize() ;
3362 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3364 return style
& ~wxBORDER_MASK
;
3367 // Find the wxWindowMac at the current mouse position, returning the mouse
3369 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3371 pt
= wxGetMousePosition();
3372 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3377 // Get the current mouse position.
3378 wxPoint
wxGetMousePosition()
3382 wxGetMousePosition( &x
, &y
);
3384 return wxPoint(x
, y
);
3387 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3389 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3391 // copied from wxGTK : CS
3392 // VZ: shouldn't we move this to base class then?
3394 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3397 // (a) it's a command event and so is propagated to the parent
3398 // (b) under MSW it can be generated from kbd too
3399 // (c) it uses screen coords (because of (a))
3400 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3402 this->ClientToScreen(event
.GetPosition()));
3403 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3412 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3414 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3415 CallNextEventHandler(
3416 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3417 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3420 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3424 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3428 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3429 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3434 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3436 return eventNotHandledErr
;
3439 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3441 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3442 if ( !wxWindowBase::Reparent(newParent
) )
3445 // copied from MacPostControlCreate
3446 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3448 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3450 ::EmbedControl( m_peer
->GetControlRef() , container
) ;