1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/window.h"
17 #include "wx/dcclient.h"
21 #include "wx/layout.h"
22 #include "wx/dialog.h"
23 #include "wx/scrolbar.h"
24 #include "wx/statbox.h"
25 #include "wx/button.h"
26 #include "wx/settings.h"
27 #include "wx/msgdlg.h"
29 #include "wx/tooltip.h"
30 #include "wx/statusbr.h"
31 #include "wx/menuitem.h"
32 #include "wx/spinctrl.h"
34 #include "wx/geometry.h"
35 #include "wx/textctrl.h"
37 #include "wx/toolbar.h"
44 #if wxUSE_DRAG_AND_DROP
48 #include "wx/mac/uma.h"
50 #define MAC_SCROLLBAR_SIZE 15
51 #define MAC_SMALL_SCROLLBAR_SIZE 11
55 #include <ToolUtils.h>
57 #include <MacTextEditor.h>
60 #if TARGET_API_MAC_OSX
62 #include <HIToolbox/HIView.h>
68 extern wxList wxPendingDelete
;
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
76 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
77 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
78 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
79 #if TARGET_API_MAC_OSX
80 EVT_PAINT(wxWindowMac::OnPaint
)
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 #define wxMAC_USE_THEME_BORDER 1
94 // ---------------------------------------------------------------------------
95 // Utility Routines to move between different coordinate systems
96 // ---------------------------------------------------------------------------
99 * Right now we have the following setup :
100 * a border that is not part of the native control is always outside the
101 * control's border (otherwise we loose all native intelligence, future ways
102 * may be to have a second embedding control responsible for drawing borders
103 * and backgrounds eventually)
104 * so all this border calculations have to be taken into account when calling
105 * native methods or getting native oriented data
106 * so we have three coordinate systems here
107 * wx client coordinates
108 * wx window coordinates (including window frames)
113 // originating from native control
117 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
119 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
122 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
124 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
128 // directed towards native control
131 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
133 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
136 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
138 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
146 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
148 #if TARGET_API_MAC_OSX
150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
153 kEventControlVisibilityChanged
= 157
159 static const EventTypeSpec eventList
[] =
161 { kEventClassCommand
, kEventProcessCommand
} ,
162 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
164 { kEventClassControl
, kEventControlHit
} ,
166 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
167 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
169 { kEventClassControl
, kEventControlDraw
} ,
170 #if TARGET_API_MAC_OSX
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
175 { kEventClassControl
, kEventControlSetFocusPart
} ,
177 { kEventClassService
, kEventServiceGetTypes
},
178 { kEventClassService
, kEventServiceCopy
},
179 { kEventClassService
, kEventServicePaste
},
181 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
182 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch ( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
206 if ( ! thisWindow
->GetPeer()->IsCompositing() )
208 if ( thisWindow
->GetPeer()->IsRootControl() )
209 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
211 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
214 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
216 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
220 if ( ! thisWindow
->GetPeer()->IsCompositing() )
222 allocatedRgn
= NewRgn() ;
223 CopyRgn( updateRgn
, allocatedRgn
) ;
224 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
226 // hide the given region by the new region that must be shifted
227 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
228 updateRgn
= allocatedRgn
;
232 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
234 // as this update region is in native window locals we must adapt it to wx window local
235 allocatedRgn
= NewRgn() ;
236 CopyRgn( updateRgn
, allocatedRgn
) ;
238 // hide the given region by the new region that must be shifted
239 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
240 updateRgn
= allocatedRgn
;
246 GetRegionBounds( updateRgn
, &rgnBounds
) ;
248 #if wxMAC_DEBUG_REDRAW
249 if ( thisWindow
->MacIsUserPane() )
251 static float color
= 0.5 ;
254 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
256 HIViewGetBounds( controlRef
, &bounds
);
257 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
258 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
259 CGContextFillRect( cgContext
, bounds
);
272 #if wxMAC_USE_CORE_GRAPHICS
273 bool created
= false ;
274 CGContextRef cgContext
= NULL
;
275 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
277 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
279 // this parameter is not provided on non-composited windows
282 // rest of the code expects this to be already transformed and clipped for local
283 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
285 GetPortBounds( port
, &bounds
) ;
286 CreateCGContextForPort( port
, &cgContext
) ;
288 wxMacWindowToNative( thisWindow
, updateRgn
) ;
289 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
290 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
291 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
292 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
294 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
295 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
297 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
300 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
301 CGContextFillRect( cgContext
,
303 controlBounds
.right
- controlBounds
.left
,
304 controlBounds
.bottom
- controlBounds
.top
) );
308 thisWindow
->MacSetCGContextRef( cgContext
) ;
311 wxMacCGContextStateSaver
sg( cgContext
) ;
313 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
316 #if wxMAC_USE_CORE_GRAPHICS
317 thisWindow
->MacSetCGContextRef( NULL
) ;
321 CGContextRelease( cgContext
) ;
326 DisposeRgn( allocatedRgn
) ;
330 case kEventControlVisibilityChanged
:
331 thisWindow
->MacVisibilityChanged() ;
334 case kEventControlEnabledStateChanged
:
335 thisWindow
->MacEnabledStateChanged() ;
338 case kEventControlHiliteChanged
:
339 thisWindow
->MacHiliteChanged() ;
343 // we emulate this event under Carbon CFM
344 case kEventControlSetFocusPart
:
346 Boolean focusEverything
= false ;
347 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
350 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
355 if ( controlPart
== kControlFocusNoPart
)
358 if ( thisWindow
->GetCaret() )
359 thisWindow
->GetCaret()->OnKillFocus();
362 static bool inKillFocusEvent
= false ;
364 if ( !inKillFocusEvent
)
366 inKillFocusEvent
= true ;
367 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
368 event
.SetEventObject(thisWindow
);
369 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
370 inKillFocusEvent
= false ;
375 // panel wants to track the window which was the last to have focus in it
376 wxChildFocusEvent
eventFocus(thisWindow
);
377 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
380 if ( thisWindow
->GetCaret() )
381 thisWindow
->GetCaret()->OnSetFocus();
384 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
385 event
.SetEventObject(thisWindow
);
386 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
389 if ( thisWindow
->MacIsUserPane() )
394 case kEventControlHit
:
395 result
= thisWindow
->MacControlHit( handler
, event
) ;
405 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
407 OSStatus result
= eventNotHandledErr
;
409 wxMacCarbonEvent
cEvent( event
) ;
411 ControlRef controlRef
;
412 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
413 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
414 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
416 switch ( GetEventKind( event
) )
418 case kEventServiceGetTypes
:
422 textCtrl
->GetSelection( &from
, &to
) ;
424 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
426 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
427 if ( textCtrl
->IsEditable() )
428 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
430 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
431 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
433 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
437 CFArrayAppendValue(copyTypes
, typestring
) ;
439 CFArrayAppendValue(pasteTypes
, typestring
) ;
441 CFRelease( typestring
) ;
449 case kEventServiceCopy
:
454 textCtrl
->GetSelection( &from
, &to
) ;
455 wxString val
= textCtrl
->GetValue() ;
456 val
= val
.Mid( from
, to
- from
) ;
457 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
458 verify_noerr( ClearScrap( &scrapRef
) ) ;
459 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
464 case kEventServicePaste
:
467 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
468 Size textSize
, pastedSize
;
469 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
471 char *content
= new char[textSize
] ;
472 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
473 content
[textSize
- 1] = 0 ;
476 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
478 textCtrl
->WriteText( wxString( content
) ) ;
493 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
495 OSStatus result
= eventNotHandledErr
;
496 wxWindowMac
* focus
= (wxWindowMac
*) data
;
498 wchar_t* uniChars
= NULL
;
499 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
502 UInt32 dataSize
= 0 ;
505 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
507 numChars
= dataSize
/ sizeof( UniChar
) ;
510 if ( dataSize
> sizeof(buf
) )
511 charBuf
= new UniChar
[ numChars
] ;
515 uniChars
= new wchar_t[ numChars
] ;
516 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
517 #if SIZEOF_WCHAR_T == 2
518 uniChars
= (wchar_t*) charBuf
;
519 memcpy( uniChars
, charBuf
, dataSize
) ;
521 // the resulting string will never have more chars than the utf16 version, so this is safe
522 wxMBConvUTF16 converter
;
523 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
527 switch ( GetEventKind( event
) )
529 case kEventTextInputUpdateActiveInputArea
:
531 // An IME input event may return several characters, but we need to send one char at a time to
533 for (int pos
=0 ; pos
< numChars
; pos
++)
535 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
536 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
537 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
539 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
540 if ( wxTheApp
->MacSendCharEvent(
541 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
546 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
550 case kEventTextInputUnicodeForKeyEvent
:
552 UInt32 keyCode
, modifiers
;
555 unsigned char charCode
;
557 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
558 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
559 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
560 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
561 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
563 UInt32 message
= (keyCode
<< 8) + charCode
;
565 // An IME input event may return several characters, but we need to send one char at a time to
567 for (int pos
=0 ; pos
< numChars
; pos
++)
569 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
570 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
571 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
573 if ( wxTheApp
->MacSendCharEvent(
574 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
579 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
588 if ( charBuf
!= buf
)
594 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
596 OSStatus result
= eventNotHandledErr
;
597 wxWindowMac
* focus
= (wxWindowMac
*) data
;
601 wxMacCarbonEvent
cEvent( event
) ;
602 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
604 wxMenuItem
* item
= NULL
;
605 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
606 int id
= wxMacCommandToId( command
.commandID
) ;
610 wxASSERT( itemMenu
!= NULL
) ;
612 switch ( cEvent
.GetKind() )
614 case kEventProcessCommand
:
616 if (item
->IsCheckable())
617 item
->Check( !item
->IsChecked() ) ;
619 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
623 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
624 event
.SetEventObject(focus
);
625 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
627 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
633 case kEventCommandUpdateStatus
:
635 wxUpdateUIEvent
event(id
);
636 event
.SetEventObject( itemMenu
);
638 bool processed
= false;
640 // Try the menu's event handler
642 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
644 processed
= handler
->ProcessEvent(event
);
647 // Try the window the menu was popped up from
648 // (and up through the hierarchy)
651 const wxMenuBase
*menu
= itemMenu
;
654 wxWindow
*win
= menu
->GetInvokingWindow();
657 processed
= win
->GetEventHandler()->ProcessEvent(event
);
661 menu
= menu
->GetParent();
667 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
672 // if anything changed, update the changed attribute
673 if (event
.GetSetText())
674 itemMenu
->SetLabel(id
, event
.GetText());
675 if (event
.GetSetChecked())
676 itemMenu
->Check(id
, event
.GetChecked());
677 if (event
.GetSetEnabled())
678 itemMenu
->Enable(id
, event
.GetEnabled());
692 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
694 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
695 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
696 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
697 OSStatus result
= eventNotHandledErr
;
699 switch ( GetEventClass( event
) )
701 case kEventClassCommand
:
702 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
705 case kEventClassControl
:
706 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
709 case kEventClassService
:
710 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
713 case kEventClassTextInput
:
714 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
721 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
726 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
728 #if !TARGET_API_MAC_OSX
730 // ---------------------------------------------------------------------------
731 // UserPane events for non OSX builds
732 // ---------------------------------------------------------------------------
734 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
736 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
738 win
->MacControlUserPaneDrawProc(part
) ;
740 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
742 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
744 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
746 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
748 return kControlNoPart
;
750 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
752 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
754 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
756 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
758 return kControlNoPart
;
760 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
762 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
764 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
766 win
->MacControlUserPaneIdleProc() ;
768 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
770 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
772 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
774 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
776 return kControlNoPart
;
778 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
780 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
782 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
784 win
->MacControlUserPaneActivateProc(activating
) ;
786 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
788 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
790 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
792 return win
->MacControlUserPaneFocusProc(action
) ;
794 return kControlNoPart
;
796 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
798 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
800 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
802 win
->MacControlUserPaneBackgroundProc(info
) ;
804 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
806 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
809 RgnHandle rgn
= NewRgn() ;
811 MacWindowToRootWindow( &x
, &y
) ;
812 OffsetRgn( rgn
, -x
, -y
) ;
813 wxMacWindowStateSaver
sv( this ) ;
814 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
815 MacDoRedraw( rgn
, 0 ) ;
819 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
821 return kControlNoPart
;
824 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
826 return kControlNoPart
;
829 void wxWindowMac::MacControlUserPaneIdleProc()
833 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
835 return kControlNoPart
;
838 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
842 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
844 if ( AcceptsFocus() )
847 return kControlNoPart
;
850 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
856 // ---------------------------------------------------------------------------
857 // Scrollbar Tracking for all
858 // ---------------------------------------------------------------------------
860 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
861 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
865 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
867 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
870 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
872 // ===========================================================================
874 // ===========================================================================
876 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
878 static MacControlMap wxWinMacControlList
;
880 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
882 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
884 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
887 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
889 // adding NULL ControlRef is (first) surely a result of an error and
890 // (secondly) breaks native event processing
891 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
893 wxWinMacControlList
[inControl
] = control
;
896 void wxRemoveMacControlAssociation(wxWindow
*control
)
898 // iterate over all the elements in the class
899 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
900 // we should go on...
906 MacControlMap::iterator it
;
907 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
909 if ( it
->second
== control
)
911 wxWinMacControlList
.erase(it
);
919 // ----------------------------------------------------------------------------
920 // constructors and such
921 // ----------------------------------------------------------------------------
923 wxWindowMac::wxWindowMac()
928 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
933 const wxString
& name
)
936 Create(parent
, id
, pos
, size
, style
, name
);
939 void wxWindowMac::Init()
944 #if WXWIN_COMPATIBILITY_2_4
945 m_backgroundTransparent
= false;
948 #if wxMAC_USE_CORE_GRAPHICS
949 m_cgContextRef
= NULL
;
952 // as all windows are created with WS_VISIBLE style...
955 m_hScrollBar
= NULL
;
956 m_vScrollBar
= NULL
;
957 m_macBackgroundBrush
= wxNullBrush
;
959 m_macIsUserPane
= true;
960 m_clipChildren
= false ;
961 m_cachedClippedRectValid
= false ;
963 // we need a valid font for the encodings
964 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
967 wxWindowMac::~wxWindowMac()
971 m_isBeingDeleted
= true;
973 MacInvalidateBorders() ;
975 #ifndef __WXUNIVERSAL__
976 // VS: make sure there's no wxFrame with last focus set to us:
977 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
979 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
982 if ( frame
->GetLastFocus() == this )
983 frame
->SetLastFocus((wxWindow
*)NULL
);
989 // destroy children before destroying this window itself
992 // wxRemoveMacControlAssociation( this ) ;
993 // If we delete an item, we should initialize the parent panel,
994 // because it could now be invalid.
995 wxWindow
*parent
= GetParent() ;
998 if (parent
->GetDefaultItem() == (wxButton
*) this)
999 parent
->SetDefaultItem(NULL
);
1002 if ( m_peer
&& m_peer
->Ok() )
1004 // in case the callback might be called during destruction
1005 wxRemoveMacControlAssociation( this) ;
1006 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1007 // we currently are not using this hook
1008 // ::SetControlColorProc( *m_peer , NULL ) ;
1012 if ( g_MacLastWindow
== this )
1013 g_MacLastWindow
= NULL
;
1015 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1018 if ( frame
->GetLastFocus() == this )
1019 frame
->SetLastFocus( NULL
) ;
1022 // delete our drop target if we've got one
1023 #if wxUSE_DRAG_AND_DROP
1024 if ( m_dropTarget
!= NULL
)
1026 delete m_dropTarget
;
1027 m_dropTarget
= NULL
;
1034 WXWidget
wxWindowMac::GetHandle() const
1036 return (WXWidget
) m_peer
->GetControlRef() ;
1039 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1041 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1042 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1043 GetEventTypeCount(eventList
), eventList
, this,
1044 (EventHandlerRef
*)&m_macControlEventHandler
);
1046 #if !TARGET_API_MAC_OSX
1047 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1049 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1050 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1051 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1052 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1053 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1054 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1055 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1056 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1062 bool wxWindowMac::Create(wxWindowMac
*parent
,
1067 const wxString
& name
)
1069 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1071 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1074 m_windowVariant
= parent
->GetWindowVariant() ;
1076 if ( m_macIsUserPane
)
1078 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1081 | kControlSupportsEmbedding
1082 | kControlSupportsLiveFeedback
1083 | kControlGetsFocusOnClick
1084 // | kControlHasSpecialBackground
1085 // | kControlSupportsCalcBestRect
1086 | kControlHandlesTracking
1087 | kControlSupportsFocus
1088 | kControlWantsActivate
1089 | kControlWantsIdle
;
1091 m_peer
= new wxMacControl(this) ;
1092 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1093 verify_noerr( err
);
1095 MacPostControlCreate(pos
, size
) ;
1098 #ifndef __WXUNIVERSAL__
1099 // Don't give scrollbars to wxControls unless they ask for them
1100 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1101 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1103 MacCreateScrollBars( style
) ;
1107 wxWindowCreateEvent
event(this);
1108 GetEventHandler()->AddPendingEvent(event
);
1113 void wxWindowMac::MacChildAdded()
1116 m_vScrollBar
->Raise() ;
1118 m_hScrollBar
->Raise() ;
1121 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1123 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1125 m_peer
->SetReference( (long)this ) ;
1126 GetParent()->AddChild( this );
1128 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1130 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1131 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1132 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1133 GetParent()->MacChildAdded() ;
1135 // adjust font, controlsize etc
1136 DoSetWindowVariant( m_windowVariant
) ;
1138 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
1140 if (!m_macIsUserPane
)
1141 SetInitialBestSize(size
);
1143 SetCursor( *wxSTANDARD_CURSOR
) ;
1146 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1148 // Don't assert, in case we set the window variant before
1149 // the window is created
1150 // wxASSERT( m_peer->Ok() ) ;
1152 m_windowVariant
= variant
;
1154 if (m_peer
== NULL
|| !m_peer
->Ok())
1158 ThemeFontID themeFont
= kThemeSystemFont
;
1160 // we will get that from the settings later
1161 // and make this NORMAL later, but first
1162 // we have a few calculations that we must fix
1166 case wxWINDOW_VARIANT_NORMAL
:
1167 size
= kControlSizeNormal
;
1168 themeFont
= kThemeSystemFont
;
1171 case wxWINDOW_VARIANT_SMALL
:
1172 size
= kControlSizeSmall
;
1173 themeFont
= kThemeSmallSystemFont
;
1176 case wxWINDOW_VARIANT_MINI
:
1177 if (UMAGetSystemVersion() >= 0x1030 )
1179 // not always defined in the headers
1185 size
= kControlSizeSmall
;
1186 themeFont
= kThemeSmallSystemFont
;
1190 case wxWINDOW_VARIANT_LARGE
:
1191 size
= kControlSizeLarge
;
1192 themeFont
= kThemeSystemFont
;
1196 wxFAIL_MSG(_T("unexpected window variant"));
1200 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1203 font
.MacCreateThemeFont( themeFont
) ;
1207 void wxWindowMac::MacUpdateControlFont()
1209 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1213 bool wxWindowMac::SetFont(const wxFont
& font
)
1215 bool retval
= wxWindowBase::SetFont( font
);
1217 MacUpdateControlFont() ;
1222 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1224 bool retval
= wxWindowBase::SetForegroundColour( col
);
1227 MacUpdateControlFont();
1232 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1234 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1238 wxColour
newCol(GetBackgroundColour());
1240 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1241 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1242 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1243 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1245 brush
.SetColour( newCol
) ;
1247 MacSetBackgroundBrush( brush
) ;
1248 MacUpdateControlFont() ;
1253 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1255 m_macBackgroundBrush
= brush
;
1256 m_peer
->SetBackground( brush
) ;
1259 bool wxWindowMac::MacCanFocus() const
1261 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1262 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1263 // but the value range is nowhere documented
1264 Boolean keyExistsAndHasValidFormat
;
1265 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1266 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1268 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1274 UInt32 features
= 0 ;
1275 m_peer
->GetFeatures( &features
) ;
1277 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1281 void wxWindowMac::SetFocus()
1283 if ( !AcceptsFocus() )
1286 wxWindow
* former
= FindFocus() ;
1287 if ( former
== this )
1290 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1291 // we can only leave in case of an error
1292 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1293 if ( err
== errCouldntSetFocus
)
1296 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1298 #if !TARGET_API_MAC_OSX
1299 // emulate carbon events when running under CarbonLib where they are not natively available
1302 EventRef evRef
= NULL
;
1304 err
= MacCreateEvent(
1305 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1306 kEventAttributeUserEvent
, &evRef
);
1307 verify_noerr( err
);
1309 wxMacCarbonEvent
cEvent( evRef
) ;
1310 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1311 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1313 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1314 ReleaseEvent( evRef
) ;
1317 // send new focus event
1319 EventRef evRef
= NULL
;
1321 err
= MacCreateEvent(
1322 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1323 kEventAttributeUserEvent
, &evRef
);
1324 verify_noerr( err
);
1326 wxMacCarbonEvent
cEvent( evRef
) ;
1327 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1328 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1330 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1331 ReleaseEvent( evRef
) ;
1336 void wxWindowMac::DoCaptureMouse()
1338 wxApp::s_captureWindow
= this ;
1341 wxWindow
* wxWindowBase::GetCapture()
1343 return wxApp::s_captureWindow
;
1346 void wxWindowMac::DoReleaseMouse()
1348 wxApp::s_captureWindow
= NULL
;
1351 #if wxUSE_DRAG_AND_DROP
1353 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1355 if ( m_dropTarget
!= NULL
)
1356 delete m_dropTarget
;
1358 m_dropTarget
= pDropTarget
;
1359 if ( m_dropTarget
!= NULL
)
1367 // Old-style File Manager Drag & Drop
1368 void wxWindowMac::DragAcceptFiles(bool accept
)
1373 // Returns the size of the native control. In the case of the toplevel window
1374 // this is the content area root control
1376 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1377 int& w
, int& h
) const
1379 wxFAIL_MSG( wxT("Not currently supported") ) ;
1382 // From a wx position / size calculate the appropriate size of the native control
1384 bool wxWindowMac::MacGetBoundsForControl(
1388 int& w
, int& h
, bool adjustOrigin
) const
1390 // the desired size, minus the border pixels gives the correct size of the control
1394 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1395 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1396 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1398 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1399 if ( !isCompositing
)
1400 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1402 x
+= MacGetLeftBorderSize() ;
1403 y
+= MacGetTopBorderSize() ;
1404 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1405 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1408 AdjustForParentClientOrigin( x
, y
) ;
1410 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1411 if ( !GetParent()->IsTopLevel() )
1413 x
-= GetParent()->MacGetLeftBorderSize() ;
1414 y
-= GetParent()->MacGetTopBorderSize() ;
1420 // Get window size (not client size)
1421 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1424 m_peer
->GetRect( &bounds
) ;
1427 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1429 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1432 // get the position of the bounds of this window in client coordinates of its parent
1433 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1436 m_peer
->GetRect( &bounds
) ;
1438 int x1
= bounds
.left
;
1439 int y1
= bounds
.top
;
1441 // get the wx window position from the native one
1442 x1
-= MacGetLeftBorderSize() ;
1443 y1
-= MacGetTopBorderSize() ;
1445 if ( !IsTopLevel() )
1447 wxWindow
*parent
= GetParent();
1450 // we must first adjust it to be in window coordinates of the parent,
1451 // as otherwise it gets lost by the ClientAreaOrigin fix
1452 x1
+= parent
->MacGetLeftBorderSize() ;
1453 y1
+= parent
->MacGetTopBorderSize() ;
1455 // and now to client coordinates
1456 wxPoint
pt(parent
->GetClientAreaOrigin());
1468 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1470 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1471 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1473 Point localwhere
= { 0, 0 } ;
1480 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1487 MacRootWindowToWindow( x
, y
) ;
1489 wxPoint origin
= GetClientAreaOrigin() ;
1496 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1498 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1499 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1501 wxPoint origin
= GetClientAreaOrigin() ;
1507 MacWindowToRootWindow( x
, y
) ;
1509 Point localwhere
= { 0, 0 };
1515 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1523 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1525 wxPoint origin
= GetClientAreaOrigin() ;
1531 MacWindowToRootWindow( x
, y
) ;
1534 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1536 MacRootWindowToWindow( x
, y
) ;
1538 wxPoint origin
= GetClientAreaOrigin() ;
1545 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1554 if ( !IsTopLevel() )
1556 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1559 pt
.x
-= MacGetLeftBorderSize() ;
1560 pt
.y
-= MacGetTopBorderSize() ;
1561 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1571 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1580 MacWindowToRootWindow( &x1
, &y1
) ;
1588 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1597 if ( !IsTopLevel() )
1599 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1602 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1603 pt
.x
+= MacGetLeftBorderSize() ;
1604 pt
.y
+= MacGetTopBorderSize() ;
1614 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1623 MacRootWindowToWindow( &x1
, &y1
) ;
1631 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1633 RgnHandle rgn
= NewRgn() ;
1635 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1637 Rect structure
, content
;
1639 GetRegionBounds( rgn
, &content
) ;
1640 m_peer
->GetRect( &structure
) ;
1641 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1643 left
= content
.left
- structure
.left
;
1644 top
= content
.top
- structure
.top
;
1645 right
= structure
.right
- content
.right
;
1646 bottom
= structure
.bottom
- content
.bottom
;
1650 left
= top
= right
= bottom
= 0 ;
1656 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1658 wxSize sizeTotal
= size
;
1660 RgnHandle rgn
= NewRgn() ;
1661 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1663 Rect content
, structure
;
1664 GetRegionBounds( rgn
, &content
) ;
1665 m_peer
->GetRect( &structure
) ;
1667 // structure is in parent coordinates, but we only need width and height, so it's ok
1669 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1670 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1675 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1676 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1681 // Get size *available for subwindows* i.e. excluding menu bar etc.
1682 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1686 RgnHandle rgn
= NewRgn() ;
1688 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1689 GetRegionBounds( rgn
, &content
) ;
1691 m_peer
->GetRect( &content
) ;
1694 ww
= content
.right
- content
.left
;
1695 hh
= content
.bottom
- content
.top
;
1697 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1698 hh
-= m_hScrollBar
->GetSize().y
;
1700 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1701 ww
-= m_vScrollBar
->GetSize().x
;
1709 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1711 if (m_cursor
== cursor
)
1714 if (wxNullCursor
== cursor
)
1716 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1721 if ( ! wxWindowBase::SetCursor( cursor
) )
1725 wxASSERT_MSG( m_cursor
.Ok(),
1726 wxT("cursor must be valid after call to the base version"));
1728 wxWindowMac
*mouseWin
= 0 ;
1730 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1731 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1733 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1735 // TODO: If we ever get a GetCurrentEvent... replacement
1736 // for the mouse position, use it...
1739 ControlPartCode part
;
1740 ControlRef control
;
1743 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1745 mouseWin
= wxFindControlFromMacControl( control
) ;
1748 QDSwapPort( savePort
, NULL
) ;
1751 if ( mouseWin
== this && !wxIsBusy() )
1752 m_cursor
.MacInstall() ;
1758 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1760 menu
->SetInvokingWindow(this);
1763 if ( x
== -1 && y
== -1 )
1765 wxPoint mouse
= wxGetMousePosition();
1771 ClientToScreen( &x
, &y
) ;
1774 menu
->MacBeforeDisplay( true ) ;
1775 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1776 if ( HiWord(menuResult
) != 0 )
1779 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1780 int id
= wxMacCommandToId( macid
);
1781 wxMenuItem
* item
= NULL
;
1783 item
= menu
->FindItem( id
, &realmenu
) ;
1786 if (item
->IsCheckable())
1787 item
->Check( !item
->IsChecked() ) ;
1789 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1793 menu
->MacAfterDisplay( true ) ;
1794 menu
->SetInvokingWindow( NULL
);
1800 // ----------------------------------------------------------------------------
1802 // ----------------------------------------------------------------------------
1806 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1808 wxWindowBase::DoSetToolTip(tooltip
);
1811 m_tooltip
->SetWindow(this);
1816 void wxWindowMac::MacInvalidateBorders()
1818 if ( m_peer
== NULL
)
1821 bool vis
= MacIsReallyShown() ;
1825 int outerBorder
= MacGetLeftBorderSize() ;
1826 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1829 if ( outerBorder
== 0 )
1832 // now we know that we have something to do at all
1834 // as the borders are drawn on the parent we have to properly invalidate all these areas
1835 RgnHandle updateInner
, updateOuter
;
1838 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1839 updateInner
= NewRgn() ;
1840 updateOuter
= NewRgn() ;
1842 m_peer
->GetRect( &rect
) ;
1843 RectRgn( updateInner
, &rect
) ;
1844 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1845 RectRgn( updateOuter
, &rect
) ;
1846 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1848 #ifdef __WXMAC_OSX__
1849 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1851 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1853 InvalWindowRgn( tlw
, updateOuter
) ;
1856 DisposeRgn( updateOuter
) ;
1857 DisposeRgn( updateInner
) ;
1860 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1862 // this is never called for a toplevel window, so we know we have a parent
1863 int former_x
, former_y
, former_w
, former_h
;
1865 // Get true coordinates of former position
1866 DoGetPosition( &former_x
, &former_y
) ;
1867 DoGetSize( &former_w
, &former_h
) ;
1869 wxWindow
*parent
= GetParent();
1872 wxPoint
pt(parent
->GetClientAreaOrigin());
1877 int actualWidth
= width
;
1878 int actualHeight
= height
;
1882 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1883 actualWidth
= m_minWidth
;
1884 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1885 actualHeight
= m_minHeight
;
1886 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1887 actualWidth
= m_maxWidth
;
1888 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1889 actualHeight
= m_maxHeight
;
1891 bool doMove
= false, doResize
= false ;
1893 if ( actualX
!= former_x
|| actualY
!= former_y
)
1896 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1899 if ( doMove
|| doResize
)
1901 // as the borders are drawn outside the native control, we adjust now
1903 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1904 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1905 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1908 wxMacRectToNative( &bounds
, &r
) ;
1910 if ( !GetParent()->IsTopLevel() )
1911 wxMacWindowToNative( GetParent() , &r
) ;
1913 MacInvalidateBorders() ;
1915 m_cachedClippedRectValid
= false ;
1916 m_peer
->SetRect( &r
) ;
1918 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1920 MacInvalidateBorders() ;
1922 MacRepositionScrollBars() ;
1925 wxPoint
point(actualX
, actualY
);
1926 wxMoveEvent
event(point
, m_windowId
);
1927 event
.SetEventObject(this);
1928 GetEventHandler()->ProcessEvent(event
) ;
1933 MacRepositionScrollBars() ;
1934 wxSize
size(actualWidth
, actualHeight
);
1935 wxSizeEvent
event(size
, m_windowId
);
1936 event
.SetEventObject(this);
1937 GetEventHandler()->ProcessEvent(event
);
1942 wxSize
wxWindowMac::DoGetBestSize() const
1944 if ( m_macIsUserPane
|| IsTopLevel() )
1945 return wxWindowBase::DoGetBestSize() ;
1947 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1948 int bestWidth
, bestHeight
;
1950 m_peer
->GetBestRect( &bestsize
) ;
1951 if ( EmptyRect( &bestsize
) )
1956 bestsize
.bottom
= 16 ;
1958 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1960 bestsize
.bottom
= 16 ;
1963 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1965 bestsize
.bottom
= 24 ;
1970 // return wxWindowBase::DoGetBestSize() ;
1974 bestWidth
= bestsize
.right
- bestsize
.left
;
1975 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1976 if ( bestHeight
< 10 )
1979 return wxSize(bestWidth
, bestHeight
);
1982 // set the size of the window: if the dimensions are positive, just use them,
1983 // but if any of them is equal to -1, it means that we must find the value for
1984 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1985 // which case -1 is a valid value for x and y)
1987 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1988 // the width/height to best suit our contents, otherwise we reuse the current
1990 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1992 // get the current size and position...
1993 int currentX
, currentY
;
1994 int currentW
, currentH
;
1996 GetPosition(¤tX
, ¤tY
);
1997 GetSize(¤tW
, ¤tH
);
1999 // ... and don't do anything (avoiding flicker) if it's already ok
2000 if ( x
== currentX
&& y
== currentY
&&
2001 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2004 MacRepositionScrollBars() ; // we might have a real position shift
2009 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2011 if ( x
== wxDefaultCoord
)
2013 if ( y
== wxDefaultCoord
)
2017 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2019 wxSize size
= wxDefaultSize
;
2020 if ( width
== wxDefaultCoord
)
2022 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2024 size
= DoGetBestSize();
2029 // just take the current one
2034 if ( height
== wxDefaultCoord
)
2036 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2038 if ( size
.x
== wxDefaultCoord
)
2039 size
= DoGetBestSize();
2040 // else: already called DoGetBestSize() above
2046 // just take the current one
2051 DoMoveWindow( x
, y
, width
, height
);
2054 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2056 RgnHandle rgn
= NewRgn() ;
2058 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2060 GetRegionBounds( rgn
, &content
) ;
2070 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2073 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2075 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2077 int currentclientwidth
, currentclientheight
;
2078 int currentwidth
, currentheight
;
2080 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2081 GetSize( ¤twidth
, ¤theight
) ;
2083 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2084 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2088 void wxWindowMac::SetLabel(const wxString
& title
)
2090 m_label
= wxStripMenuCodes(title
) ;
2092 if ( m_peer
&& m_peer
->Ok() )
2093 m_peer
->SetLabel( m_label
) ;
2098 wxString
wxWindowMac::GetLabel() const
2103 bool wxWindowMac::Show(bool show
)
2105 bool former
= MacIsReallyShown() ;
2106 if ( !wxWindowBase::Show(show
) )
2109 // TODO: use visibilityChanged Carbon Event for OSX
2111 m_peer
->SetVisibility( show
, true ) ;
2113 if ( former
!= MacIsReallyShown() )
2114 MacPropagateVisibilityChanged() ;
2119 bool wxWindowMac::Enable(bool enable
)
2121 wxASSERT( m_peer
->Ok() ) ;
2122 bool former
= MacIsReallyEnabled() ;
2123 if ( !wxWindowBase::Enable(enable
) )
2126 m_peer
->Enable( enable
) ;
2128 if ( former
!= MacIsReallyEnabled() )
2129 MacPropagateEnabledStateChanged() ;
2135 // status change propagations (will be not necessary for OSX later )
2138 void wxWindowMac::MacPropagateVisibilityChanged()
2140 #if !TARGET_API_MAC_OSX
2141 MacVisibilityChanged() ;
2144 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2147 child
= node
->GetData();
2148 if ( child
->IsShown() )
2149 child
->MacPropagateVisibilityChanged() ;
2151 node
= node
->GetNext();
2156 void wxWindowMac::MacPropagateEnabledStateChanged()
2158 #if !TARGET_API_MAC_OSX
2159 MacEnabledStateChanged() ;
2162 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2165 child
= node
->GetData();
2166 if ( child
->IsEnabled() )
2167 child
->MacPropagateEnabledStateChanged() ;
2169 node
= node
->GetNext();
2174 void wxWindowMac::MacPropagateHiliteChanged()
2176 #if !TARGET_API_MAC_OSX
2177 MacHiliteChanged() ;
2180 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2183 child
= node
->GetData();
2184 if (child
/* && child->IsEnabled() */)
2185 child
->MacPropagateHiliteChanged() ;
2187 node
= node
->GetNext();
2193 // status change notifications
2196 void wxWindowMac::MacVisibilityChanged()
2200 void wxWindowMac::MacHiliteChanged()
2204 void wxWindowMac::MacEnabledStateChanged()
2209 // status queries on the inherited window's state
2212 bool wxWindowMac::MacIsReallyShown()
2214 // only under OSX the visibility of the TLW is taken into account
2215 if ( m_isBeingDeleted
)
2218 #if TARGET_API_MAC_OSX
2219 if ( m_peer
&& m_peer
->Ok() )
2220 return m_peer
->IsVisible();
2223 wxWindow
* win
= this ;
2224 while ( win
->IsShown() )
2226 if ( win
->IsTopLevel() )
2229 win
= win
->GetParent() ;
2237 bool wxWindowMac::MacIsReallyEnabled()
2239 return m_peer
->IsEnabled() ;
2242 bool wxWindowMac::MacIsReallyHilited()
2244 return m_peer
->IsActive();
2247 void wxWindowMac::MacFlashInvalidAreas()
2249 #if TARGET_API_MAC_OSX
2250 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2254 int wxWindowMac::GetCharHeight() const
2256 wxClientDC
dc( (wxWindowMac
*)this ) ;
2258 return dc
.GetCharHeight() ;
2261 int wxWindowMac::GetCharWidth() const
2263 wxClientDC
dc( (wxWindowMac
*)this ) ;
2265 return dc
.GetCharWidth() ;
2268 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2269 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2271 const wxFont
*fontToUse
= theFont
;
2273 fontToUse
= &m_font
;
2275 wxClientDC
dc( (wxWindowMac
*) this ) ;
2277 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2278 if ( externalLeading
)
2279 *externalLeading
= le
;
2289 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2290 * we always intersect with the entire window, not only with the client area
2293 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2295 if ( m_peer
== NULL
)
2298 if ( !MacIsReallyShown() )
2305 wxMacRectToNative( rect
, &r
) ;
2306 m_peer
->SetNeedsDisplay( &r
) ;
2310 m_peer
->SetNeedsDisplay() ;
2314 void wxWindowMac::Freeze()
2316 #if TARGET_API_MAC_OSX
2317 if ( !m_frozenness
++ )
2319 if ( m_peer
&& m_peer
->Ok() )
2320 m_peer
->SetDrawingEnabled( false ) ;
2325 void wxWindowMac::Thaw()
2327 #if TARGET_API_MAC_OSX
2328 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2330 if ( !--m_frozenness
)
2332 if ( m_peer
&& m_peer
->Ok() )
2334 m_peer
->SetDrawingEnabled( true ) ;
2335 m_peer
->InvalidateWithChildren() ;
2341 wxWindowMac
*wxGetActiveWindow()
2343 // actually this is a windows-only concept
2347 // Coordinates relative to the window
2348 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2350 // We really don't move the mouse programmatically under Mac.
2353 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2355 if ( MacGetTopLevelWindow() == NULL
)
2358 #if TARGET_API_MAC_OSX
2359 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2366 event
.GetDC()->Clear() ;
2370 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2375 int wxWindowMac::GetScrollPos(int orient
) const
2377 if ( orient
== wxHORIZONTAL
)
2380 return m_hScrollBar
->GetThumbPosition() ;
2385 return m_vScrollBar
->GetThumbPosition() ;
2391 // This now returns the whole range, not just the number
2392 // of positions that we can scroll.
2393 int wxWindowMac::GetScrollRange(int orient
) const
2395 if ( orient
== wxHORIZONTAL
)
2398 return m_hScrollBar
->GetRange() ;
2403 return m_vScrollBar
->GetRange() ;
2409 int wxWindowMac::GetScrollThumb(int orient
) const
2411 if ( orient
== wxHORIZONTAL
)
2414 return m_hScrollBar
->GetThumbSize() ;
2419 return m_vScrollBar
->GetThumbSize() ;
2425 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2427 if ( orient
== wxHORIZONTAL
)
2430 m_hScrollBar
->SetThumbPosition( pos
) ;
2435 m_vScrollBar
->SetThumbPosition( pos
) ;
2440 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2441 // our own window origin is at leftOrigin/rightOrigin
2444 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2450 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2451 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2453 // back to the surrounding frame rectangle
2454 m_peer
->GetRect( &rect
) ;
2455 InsetRect( &rect
, -1 , -1 ) ;
2457 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2458 if ( UMAGetSystemVersion() >= 0x1030 )
2460 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2461 rect
.bottom
- rect
.top
) ;
2463 HIThemeFrameDrawInfo info
;
2464 memset( &info
, 0 , sizeof(info
) ) ;
2468 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2469 info
.isFocused
= hasFocus
;
2471 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2472 wxASSERT( cgContext
) ;
2474 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2476 info
.kind
= kHIThemeFrameTextFieldSquare
;
2477 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2479 else if ( HasFlag(wxSIMPLE_BORDER
) )
2481 info
.kind
= kHIThemeFrameListBox
;
2482 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2484 else if ( hasFocus
)
2486 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2489 m_peer
->GetRect( &rect
) ;
2490 if ( hasBothScrollbars
)
2492 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2493 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2494 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2495 HIThemeGrowBoxDrawInfo info
;
2496 memset( &info
, 0, sizeof(info
) ) ;
2498 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2499 info
.kind
= kHIThemeGrowBoxKindNone
;
2500 info
.size
= kHIThemeGrowBoxSizeNormal
;
2501 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2502 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2508 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2512 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2513 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2516 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2517 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2518 else if ( HasFlag(wxSIMPLE_BORDER
) )
2519 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2522 DrawThemeFocusRect( &rect
, true ) ;
2524 if ( hasBothScrollbars
)
2526 // GetThemeStandaloneGrowBoxBounds
2527 // DrawThemeStandaloneNoGrowBox
2532 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2534 if ( child
== m_hScrollBar
)
2535 m_hScrollBar
= NULL
;
2536 if ( child
== m_vScrollBar
)
2537 m_vScrollBar
= NULL
;
2539 wxWindowBase::RemoveChild( child
) ;
2542 // New function that will replace some of the above.
2543 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2544 int range
, bool refresh
)
2548 if ( orient
== wxHORIZONTAL
)
2552 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2553 if ( m_hScrollBar
->IsShown() != showScroller
)
2554 m_hScrollBar
->Show( showScroller
) ;
2556 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2563 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2564 if ( m_vScrollBar
->IsShown() != showScroller
)
2565 m_vScrollBar
->Show( showScroller
) ;
2567 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2571 MacRepositionScrollBars() ;
2574 // Does a physical scroll
2575 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2577 if ( dx
== 0 && dy
== 0 )
2580 int width
, height
;
2581 GetClientSize( &width
, &height
) ;
2583 #if TARGET_API_MAC_OSX
2584 if ( true /* m_peer->IsCompositing() */ )
2586 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2587 // area is scrolled, this does not occur if width and height are 2 pixels less,
2588 // TODO: write optimal workaround
2589 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2591 scrollrect
.Intersect( *rect
) ;
2593 if ( m_peer
->GetNeedsDisplay() )
2595 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2596 // either immediate redraw or full invalidate
2598 // is the better overall solution, as it does not slow down scrolling
2599 m_peer
->SetNeedsDisplay() ;
2601 // this would be the preferred version for fast drawing controls
2603 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2604 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2605 HIViewRender(m_peer
->GetControlRef()) ;
2612 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2613 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2614 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2616 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2617 // either immediate redraw or full invalidate
2619 // is the better overall solution, as it does not slow down scrolling
2620 m_peer
->SetNeedsDisplay() ;
2622 // this would be the preferred version for fast drawing controls
2624 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2625 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2626 HIViewRender(m_peer
->GetControlRef()) ;
2640 RgnHandle updateRgn
= NewRgn() ;
2643 wxClientDC
dc(this) ;
2644 wxMacPortSetter
helper(&dc
) ;
2646 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2647 //scrollrect.top += MacGetTopBorderSize() ;
2648 //scrollrect.left += MacGetLeftBorderSize() ;
2649 scrollrect
.bottom
= scrollrect
.top
+ height
;
2650 scrollrect
.right
= scrollrect
.left
+ width
;
2654 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2655 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2656 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2659 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2661 // now scroll the former update region as well and add the new update region
2662 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2663 RgnHandle formerUpdateRgn
= NewRgn() ;
2664 RgnHandle scrollRgn
= NewRgn() ;
2665 RectRgn( scrollRgn
, &scrollrect
) ;
2666 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2668 LocalToGlobal( &pt
) ;
2669 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2670 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2672 if ( !EmptyRgn( formerUpdateRgn
) )
2674 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2675 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2676 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2679 InvalWindowRgn(rootWindow
, updateRgn
) ;
2680 DisposeRgn( updateRgn
) ;
2681 DisposeRgn( formerUpdateRgn
) ;
2682 DisposeRgn( scrollRgn
) ;
2690 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2692 child
= node
->GetData();
2695 if (child
== m_vScrollBar
)
2697 if (child
== m_hScrollBar
)
2699 if (child
->IsTopLevel())
2702 child
->GetPosition( &x
, &y
);
2703 child
->GetSize( &w
, &h
);
2706 wxRect
rc( x
, y
, w
, h
);
2707 if (rect
->Intersects( rc
))
2708 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2712 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2717 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2719 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2721 wxScrollWinEvent wevent
;
2722 wevent
.SetPosition(event
.GetPosition());
2723 wevent
.SetOrientation(event
.GetOrientation());
2724 wevent
.SetEventObject(this);
2726 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2727 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2728 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2729 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2730 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2731 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2732 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2733 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2734 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2735 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2736 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2737 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2738 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2739 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2740 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2741 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2743 GetEventHandler()->ProcessEvent(wevent
);
2747 // Get the window with the focus
2748 wxWindowMac
*wxWindowBase::DoFindFocus()
2750 ControlRef control
;
2751 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2752 return wxFindControlFromMacControl( control
) ;
2755 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2757 // panel wants to track the window which was the last to have focus in it,
2758 // so we want to set ourselves as the window which last had focus
2760 // notice that it's also important to do it upwards the tree because
2761 // otherwise when the top level panel gets focus, it won't set it back to
2762 // us, but to some other sibling
2764 // CS: don't know if this is still needed:
2765 //wxChildFocusEvent eventFocus(this);
2766 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2768 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2770 #if wxMAC_USE_CORE_GRAPHICS
2771 GetParent()->Refresh() ;
2773 wxMacWindowStateSaver
sv( this ) ;
2776 m_peer
->GetRect( &rect
) ;
2777 // auf den umgebenden Rahmen zur\9fck
2778 InsetRect( &rect
, -1 , -1 ) ;
2780 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2784 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2786 rect
.right
+= pt
.x
;
2788 rect
.bottom
+= pt
.y
;
2791 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2792 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2793 if ( !bIsFocusEvent
)
2795 // as this erases part of the frame we have to redraw borders
2796 // and because our z-ordering is not always correct (staticboxes)
2797 // we have to invalidate things, we cannot simple redraw
2798 MacInvalidateBorders() ;
2806 void wxWindowMac::OnInternalIdle()
2808 // This calls the UI-update mechanism (querying windows for
2809 // menu/toolbar/control state information)
2810 if (wxUpdateUIEvent::CanUpdate(this))
2811 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2814 // Raise the window to the top of the Z order
2815 void wxWindowMac::Raise()
2817 m_peer
->SetZOrder( true , NULL
) ;
2820 // Lower the window to the bottom of the Z order
2821 void wxWindowMac::Lower()
2823 m_peer
->SetZOrder( false , NULL
) ;
2826 // static wxWindow *gs_lastWhich = NULL;
2828 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2830 // first trigger a set cursor event
2832 wxPoint clientorigin
= GetClientAreaOrigin() ;
2833 wxSize clientsize
= GetClientSize() ;
2835 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2837 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2839 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2840 if ( processedEvtSetCursor
&& event
.HasCursor() )
2842 cursor
= event
.GetCursor() ;
2846 // the test for processedEvtSetCursor is here to prevent using m_cursor
2847 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2848 // it - this is a way to say that our cursor shouldn't be used for this
2850 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2853 if ( !wxIsBusy() && !GetParent() )
2854 cursor
= *wxSTANDARD_CURSOR
;
2858 cursor
.MacInstall() ;
2861 return cursor
.Ok() ;
2864 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2868 return m_tooltip
->GetTip() ;
2871 return wxEmptyString
;
2874 void wxWindowMac::ClearBackground()
2880 void wxWindowMac::Update()
2882 #if TARGET_API_MAC_OSX
2883 MacGetTopLevelWindow()->MacPerformUpdates() ;
2885 ::Draw1Control( m_peer
->GetControlRef() ) ;
2889 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2891 wxTopLevelWindowMac
* win
= NULL
;
2892 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2894 win
= wxFindWinFromMacWindow( window
) ;
2899 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2901 MacUpdateClippedRects() ;
2903 return m_cachedClippedClientRect
;
2906 const wxRect
& wxWindowMac::MacGetClippedRect() const
2908 MacUpdateClippedRects() ;
2910 return m_cachedClippedRect
;
2913 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2915 MacUpdateClippedRects() ;
2917 return m_cachedClippedRectWithOuterStructure
;
2920 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2922 static wxRegion emptyrgn
;
2924 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2926 MacUpdateClippedRects() ;
2927 if ( includeOuterStructures
)
2928 return m_cachedClippedRegionWithOuterStructure
;
2930 return m_cachedClippedRegion
;
2938 void wxWindowMac::MacUpdateClippedRects() const
2940 if ( m_cachedClippedRectValid
)
2943 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2944 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2945 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2946 // to add focus borders everywhere
2948 Rect r
, rIncludingOuterStructures
;
2950 m_peer
->GetRect( &r
) ;
2951 r
.left
-= MacGetLeftBorderSize() ;
2952 r
.top
-= MacGetTopBorderSize() ;
2953 r
.bottom
+= MacGetBottomBorderSize() ;
2954 r
.right
+= MacGetRightBorderSize() ;
2961 rIncludingOuterStructures
= r
;
2962 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2964 wxRect cl
= GetClientRect() ;
2965 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2969 const wxWindow
* child
= this ;
2970 const wxWindow
* parent
= NULL
;
2972 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2974 if ( parent
->MacIsChildOfClientArea(child
) )
2976 size
= parent
->GetClientSize() ;
2977 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2983 // this will be true for scrollbars, toolbars etc.
2984 size
= parent
->GetSize() ;
2985 y
= parent
->MacGetTopBorderSize() ;
2986 x
= parent
->MacGetLeftBorderSize() ;
2987 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2988 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2991 parent
->MacWindowToRootWindow( &x
, &y
) ;
2992 MacRootWindowToWindow( &x
, &y
) ;
2994 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2996 // the wxwindow and client rects will always be clipped
2997 SectRect( &r
, &rparent
, &r
) ;
2998 SectRect( &rClient
, &rparent
, &rClient
) ;
3000 // the structure only at 'hard' borders
3001 if ( parent
->MacClipChildren() ||
3002 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
3004 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
3010 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
3011 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
3012 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
3013 m_cachedClippedRectWithOuterStructure
= wxRect(
3014 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
3015 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
3016 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
3018 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
3019 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
3020 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
3022 m_cachedClippedRectValid
= true ;
3026 This function must not change the updatergn !
3028 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3030 bool handled
= false ;
3032 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3033 GetRegionBounds( updatergn
, &updatebounds
) ;
3035 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3037 if ( !EmptyRgn(updatergn
) )
3039 RgnHandle newupdate
= NewRgn() ;
3040 wxSize point
= GetClientSize() ;
3041 wxPoint origin
= GetClientAreaOrigin() ;
3042 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3043 SectRgn( newupdate
, updatergn
, newupdate
) ;
3045 // first send an erase event to the entire update area
3047 // for the toplevel window this really is the entire area
3048 // for all the others only their client area, otherwise they
3049 // might be drawing with full alpha and eg put blue into
3050 // the grow-box area of a scrolled window (scroll sample)
3051 wxDC
* dc
= new wxWindowDC(this);
3053 dc
->SetClippingRegion(wxRegion(updatergn
));
3055 dc
->SetClippingRegion(wxRegion(newupdate
));
3057 wxEraseEvent
eevent( GetId(), dc
);
3058 eevent
.SetEventObject( this );
3059 GetEventHandler()->ProcessEvent( eevent
);
3063 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3064 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3065 m_updateRegion
= newupdate
;
3066 DisposeRgn( newupdate
) ;
3068 if ( !m_updateRegion
.Empty() )
3070 // paint the window itself
3073 event
.SetTimestamp(time
);
3074 event
.SetEventObject(this);
3075 GetEventHandler()->ProcessEvent(event
);
3079 // now we cannot rely on having its borders drawn by a window itself, as it does not
3080 // get the updateRgn wide enough to always do so, so we do it from the parent
3081 // this would also be the place to draw any custom backgrounds for native controls
3082 // in Composited windowing
3083 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3087 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3089 child
= node
->GetData();
3092 if (child
== m_vScrollBar
)
3094 if (child
== m_hScrollBar
)
3096 if (child
->IsTopLevel())
3098 if (!child
->IsShown())
3101 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3103 child
->GetPosition( &x
, &y
);
3104 child
->GetSize( &w
, &h
);
3105 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3106 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3107 InsetRect( &childRect
, -10 , -10) ;
3109 if ( RectInRgn( &childRect
, updatergn
) )
3111 // paint custom borders
3112 wxNcPaintEvent
eventNc( child
->GetId() );
3113 eventNc
.SetEventObject( child
);
3114 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3116 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3117 if ( UMAGetSystemVersion() >= 0x1030 )
3119 child
->MacPaintBorders(0, 0) ;
3124 wxWindowDC
dc(this) ;
3125 dc
.SetClippingRegion(wxRegion(updatergn
));
3126 wxMacPortSetter
helper(&dc
) ;
3127 child
->MacPaintBorders(0, 0) ;
3138 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3140 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3144 if ( iter
->IsTopLevel() )
3145 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3147 iter
= iter
->GetParent() ;
3150 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3155 void wxWindowMac::MacCreateScrollBars( long style
)
3157 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3159 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3161 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3162 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3163 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3164 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3166 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3167 variant
= wxWINDOW_VARIANT_SMALL
;
3170 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3172 GetClientSize( &width
, &height
) ;
3174 wxPoint
vPoint(width
- scrlsize
, 0) ;
3175 wxSize
vSize(scrlsize
, height
- adjust
) ;
3176 wxPoint
hPoint(0, height
- scrlsize
) ;
3177 wxSize
hSize(width
- adjust
, scrlsize
) ;
3179 if ( style
& wxVSCROLL
)
3180 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3182 if ( style
& wxHSCROLL
)
3183 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3186 // because the create does not take into account the client area origin
3187 // we might have a real position shift
3188 MacRepositionScrollBars() ;
3191 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3193 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3198 void wxWindowMac::MacRepositionScrollBars()
3200 if ( !m_hScrollBar
&& !m_vScrollBar
)
3203 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3204 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3205 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3207 // get real client area
3209 GetSize( &width
, &height
);
3211 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3212 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3214 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3215 wxSize
vSize( scrlsize
, height
- adjust
) ;
3216 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3217 wxSize
hSize( width
- adjust
, scrlsize
) ;
3220 int x
= 0, y
= 0, w
, h
;
3221 GetSize( &w
, &h
) ;
3223 MacClientToRootWindow( &x
, &y
) ;
3224 MacClientToRootWindow( &w
, &h
) ;
3226 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3228 int totW
= 10000 , totH
= 10000;
3231 if ( iter
->IsTopLevel() )
3233 iter
->GetSize( &totW
, &totH
) ;
3237 iter
= iter
->GetParent() ;
3251 if ( w
- x
>= totW
)
3256 if ( h
- y
>= totH
)
3264 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3266 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3269 bool wxWindowMac::AcceptsFocus() const
3271 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3274 void wxWindowMac::MacSuperChangedPosition()
3276 // only window-absolute structures have to be moved i.e. controls
3278 m_cachedClippedRectValid
= false ;
3281 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3284 child
= node
->GetData();
3285 child
->MacSuperChangedPosition() ;
3287 node
= node
->GetNext();
3291 void wxWindowMac::MacTopLevelWindowChangedPosition()
3293 // only screen-absolute structures have to be moved i.e. glcanvas
3296 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3299 child
= node
->GetData();
3300 child
->MacTopLevelWindowChangedPosition() ;
3302 node
= node
->GetNext();
3306 long wxWindowMac::MacGetLeftBorderSize() const
3313 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3315 // this metric is only the 'outset' outside the simple frame rect
3316 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3319 else if (HasFlag(wxSIMPLE_BORDER
))
3321 // this metric is only the 'outset' outside the simple frame rect
3322 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3329 long wxWindowMac::MacGetRightBorderSize() const
3331 // they are all symmetric in mac themes
3332 return MacGetLeftBorderSize() ;
3335 long wxWindowMac::MacGetTopBorderSize() const
3337 // they are all symmetric in mac themes
3338 return MacGetLeftBorderSize() ;
3341 long wxWindowMac::MacGetBottomBorderSize() const
3343 // they are all symmetric in mac themes
3344 return MacGetLeftBorderSize() ;
3347 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3349 return style
& ~wxBORDER_MASK
;
3352 // Find the wxWindowMac at the current mouse position, returning the mouse
3354 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3356 pt
= wxGetMousePosition();
3357 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3362 // Get the current mouse position.
3363 wxPoint
wxGetMousePosition()
3367 wxGetMousePosition( &x
, &y
);
3369 return wxPoint(x
, y
);
3372 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3374 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3376 // copied from wxGTK : CS
3377 // VZ: shouldn't we move this to base class then?
3379 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3382 // (a) it's a command event and so is propagated to the parent
3383 // (b) under MSW it can be generated from kbd too
3384 // (c) it uses screen coords (because of (a))
3385 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3387 this->ClientToScreen(event
.GetPosition()));
3388 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3397 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3399 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3400 CallNextEventHandler(
3401 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3402 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3405 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3409 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3413 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3414 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3419 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3421 return eventNotHandledErr
;
3424 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3426 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3427 if ( !wxWindowBase::Reparent(newParent
) )
3430 // copied from MacPostControlCreate
3431 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3433 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3435 ::EmbedControl( m_peer
->GetControlRef() , container
) ;