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"
22 #include "wx/dcclient.h"
26 #include "wx/layout.h"
27 #include "wx/dialog.h"
28 #include "wx/scrolbar.h"
29 #include "wx/statbox.h"
30 #include "wx/button.h"
31 #include "wx/settings.h"
32 #include "wx/msgdlg.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"
48 #if wxUSE_DRAG_AND_DROP
52 #include "wx/mac/uma.h"
54 #define MAC_SCROLLBAR_SIZE 15
55 #define MAC_SMALL_SCROLLBAR_SIZE 11
59 #include <ToolUtils.h>
61 #include <MacTextEditor.h>
64 #if TARGET_API_MAC_OSX
66 #include <HIToolbox/HIView.h>
72 extern wxList wxPendingDelete
;
74 #ifdef __WXUNIVERSAL__
75 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
77 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
80 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
81 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
82 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
83 #if TARGET_API_MAC_OSX
84 EVT_PAINT(wxWindowMac::OnPaint
)
86 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
88 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
91 #define wxMAC_DEBUG_REDRAW 0
92 #ifndef wxMAC_DEBUG_REDRAW
93 #define wxMAC_DEBUG_REDRAW 0
96 #define wxMAC_USE_THEME_BORDER 1
98 // ---------------------------------------------------------------------------
99 // Utility Routines to move between different coordinate systems
100 // ---------------------------------------------------------------------------
103 * Right now we have the following setup :
104 * a border that is not part of the native control is always outside the
105 * control's border (otherwise we loose all native intelligence, future ways
106 * may be to have a second embedding control responsible for drawing borders
107 * and backgrounds eventually)
108 * so all this border calculations have to be taken into account when calling
109 * native methods or getting native oriented data
110 * so we have three coordinate systems here
111 * wx client coordinates
112 * wx window coordinates (including window frames)
117 // originating from native control
121 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
123 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
126 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
128 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
132 // directed towards native control
135 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
137 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
140 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
142 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
150 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
152 #if TARGET_API_MAC_OSX
154 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
157 kEventControlVisibilityChanged
= 157
163 static const EventTypeSpec eventList
[] =
165 { kEventClassCommand
, kEventProcessCommand
} ,
166 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
168 { kEventClassControl
, kEventControlHit
} ,
170 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
171 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
173 { kEventClassControl
, kEventControlDraw
} ,
174 #if TARGET_API_MAC_OSX
175 { kEventClassControl
, kEventControlVisibilityChanged
} ,
176 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
177 { kEventClassControl
, kEventControlHiliteChanged
} ,
179 { kEventClassControl
, kEventControlSetFocusPart
} ,
181 { kEventClassService
, kEventServiceGetTypes
},
182 { kEventClassService
, kEventServiceCopy
},
183 { kEventClassService
, kEventServicePaste
},
185 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
186 // { kEventClassControl , kEventControlBoundsChanged } ,
189 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
191 OSStatus result
= eventNotHandledErr
;
193 wxMacCarbonEvent
cEvent( event
) ;
195 ControlRef controlRef
;
196 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
198 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
200 switch ( GetEventKind( event
) )
202 #if TARGET_API_MAC_OSX
203 case kEventControlDraw
:
205 RgnHandle updateRgn
= NULL
;
206 RgnHandle allocatedRgn
= NULL
;
207 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
210 if ( ! thisWindow
->GetPeer()->IsCompositing() )
212 if ( thisWindow
->GetPeer()->IsRootControl() )
213 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
215 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
218 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
220 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
224 if ( ! thisWindow
->GetPeer()->IsCompositing() )
226 allocatedRgn
= NewRgn() ;
227 CopyRgn( updateRgn
, allocatedRgn
) ;
228 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
230 // hide the given region by the new region that must be shifted
231 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
232 updateRgn
= allocatedRgn
;
236 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
238 // as this update region is in native window locals we must adapt it to wx window local
239 allocatedRgn
= NewRgn() ;
240 CopyRgn( updateRgn
, allocatedRgn
) ;
242 // hide the given region by the new region that must be shifted
243 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
244 updateRgn
= allocatedRgn
;
250 GetRegionBounds( updateRgn
, &rgnBounds
) ;
252 #if wxMAC_DEBUG_REDRAW
253 if ( thisWindow
->MacIsUserPane() )
255 static float color
= 0.5 ;
258 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
260 HIViewGetBounds( controlRef
, &bounds
);
261 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
262 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
263 CGContextFillRect( cgContext
, bounds
);
276 #if wxMAC_USE_CORE_GRAPHICS
277 bool created
= false ;
278 CGContextRef cgContext
= NULL
;
279 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
281 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
283 // this parameter is not provided on non-composited windows
286 // rest of the code expects this to be already transformed and clipped for local
287 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
289 GetPortBounds( port
, &bounds
) ;
290 CreateCGContextForPort( port
, &cgContext
) ;
292 wxMacWindowToNative( thisWindow
, updateRgn
) ;
293 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
294 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
295 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
296 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
298 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
299 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
301 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
304 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
305 CGContextFillRect( cgContext
,
307 controlBounds
.right
- controlBounds
.left
,
308 controlBounds
.bottom
- controlBounds
.top
) );
312 thisWindow
->MacSetCGContextRef( cgContext
) ;
315 wxMacCGContextStateSaver
sg( cgContext
) ;
317 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
320 #if wxMAC_USE_CORE_GRAPHICS
321 thisWindow
->MacSetCGContextRef( NULL
) ;
325 CGContextRelease( cgContext
) ;
330 DisposeRgn( allocatedRgn
) ;
334 case kEventControlVisibilityChanged
:
335 thisWindow
->MacVisibilityChanged() ;
338 case kEventControlEnabledStateChanged
:
339 thisWindow
->MacEnabledStateChanged() ;
342 case kEventControlHiliteChanged
:
343 thisWindow
->MacHiliteChanged() ;
347 // we emulate this event under Carbon CFM
348 case kEventControlSetFocusPart
:
350 Boolean focusEverything
= false ;
351 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
354 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
359 if ( controlPart
== kControlFocusNoPart
)
362 if ( thisWindow
->GetCaret() )
363 thisWindow
->GetCaret()->OnKillFocus();
366 static bool inKillFocusEvent
= false ;
368 if ( !inKillFocusEvent
)
370 inKillFocusEvent
= true ;
371 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
372 event
.SetEventObject(thisWindow
);
373 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
374 inKillFocusEvent
= false ;
379 // panel wants to track the window which was the last to have focus in it
380 wxChildFocusEvent
eventFocus(thisWindow
);
381 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
384 if ( thisWindow
->GetCaret() )
385 thisWindow
->GetCaret()->OnSetFocus();
388 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
389 event
.SetEventObject(thisWindow
);
390 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
393 if ( thisWindow
->MacIsUserPane() )
398 case kEventControlHit
:
399 result
= thisWindow
->MacControlHit( handler
, event
) ;
409 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
411 OSStatus result
= eventNotHandledErr
;
413 wxMacCarbonEvent
cEvent( event
) ;
415 ControlRef controlRef
;
416 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
417 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
418 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
420 switch ( GetEventKind( event
) )
422 case kEventServiceGetTypes
:
426 textCtrl
->GetSelection( &from
, &to
) ;
428 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
430 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
431 if ( textCtrl
->IsEditable() )
432 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
434 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
435 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
437 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
441 CFArrayAppendValue(copyTypes
, typestring
) ;
443 CFArrayAppendValue(pasteTypes
, typestring
) ;
445 CFRelease( typestring
) ;
453 case kEventServiceCopy
:
458 textCtrl
->GetSelection( &from
, &to
) ;
459 wxString val
= textCtrl
->GetValue() ;
460 val
= val
.Mid( from
, to
- from
) ;
461 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
462 verify_noerr( ClearScrap( &scrapRef
) ) ;
463 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
468 case kEventServicePaste
:
471 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
472 Size textSize
, pastedSize
;
473 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
475 char *content
= new char[textSize
] ;
476 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
477 content
[textSize
- 1] = 0 ;
480 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
482 textCtrl
->WriteText( wxString( content
) ) ;
497 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
499 OSStatus result
= eventNotHandledErr
;
500 wxWindowMac
* focus
= (wxWindowMac
*) data
;
502 wchar_t* uniChars
= NULL
;
503 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
505 UniChar
* charBuf
= NULL
;
506 UInt32 dataSize
= 0 ;
509 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
511 numChars
= dataSize
/ sizeof( UniChar
) + 1;
514 if ( (size_t) numChars
* 2 > sizeof(buf
) )
515 charBuf
= new UniChar
[ numChars
] ;
519 uniChars
= new wchar_t[ numChars
] ;
520 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
521 charBuf
[ numChars
- 1 ] = 0;
522 #if SIZEOF_WCHAR_T == 2
523 uniChars
= (wchar_t*) charBuf
;
524 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
526 // the resulting string will never have more chars than the utf16 version, so this is safe
527 wxMBConvUTF16 converter
;
528 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
532 switch ( GetEventKind( event
) )
534 case kEventTextInputUpdateActiveInputArea
:
536 // An IME input event may return several characters, but we need to send one char at a time to
538 for (int pos
=0 ; pos
< numChars
; pos
++)
540 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
541 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
542 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
544 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
545 if ( wxTheApp
->MacSendCharEvent(
546 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
551 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
555 case kEventTextInputUnicodeForKeyEvent
:
557 UInt32 keyCode
, modifiers
;
560 unsigned char charCode
;
562 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
563 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
564 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
565 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
566 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
568 UInt32 message
= (keyCode
<< 8) + charCode
;
570 // An IME input event may return several characters, but we need to send one char at a time to
572 for (int pos
=0 ; pos
< numChars
; pos
++)
574 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
575 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
576 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
578 if ( wxTheApp
->MacSendCharEvent(
579 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
584 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
593 if ( charBuf
!= buf
)
599 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
601 OSStatus result
= eventNotHandledErr
;
602 wxWindowMac
* focus
= (wxWindowMac
*) data
;
606 wxMacCarbonEvent
cEvent( event
) ;
607 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
609 wxMenuItem
* item
= NULL
;
610 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
611 int id
= wxMacCommandToId( command
.commandID
) ;
615 wxASSERT( itemMenu
!= NULL
) ;
617 switch ( cEvent
.GetKind() )
619 case kEventProcessCommand
:
621 if (item
->IsCheckable())
622 item
->Check( !item
->IsChecked() ) ;
624 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
628 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
629 event
.SetEventObject(focus
);
630 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
632 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
638 case kEventCommandUpdateStatus
:
640 wxUpdateUIEvent
event(id
);
641 event
.SetEventObject( itemMenu
);
643 bool processed
= false;
645 // Try the menu's event handler
647 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
649 processed
= handler
->ProcessEvent(event
);
652 // Try the window the menu was popped up from
653 // (and up through the hierarchy)
656 const wxMenuBase
*menu
= itemMenu
;
659 wxWindow
*win
= menu
->GetInvokingWindow();
662 processed
= win
->GetEventHandler()->ProcessEvent(event
);
666 menu
= menu
->GetParent();
672 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
677 // if anything changed, update the changed attribute
678 if (event
.GetSetText())
679 itemMenu
->SetLabel(id
, event
.GetText());
680 if (event
.GetSetChecked())
681 itemMenu
->Check(id
, event
.GetChecked());
682 if (event
.GetSetEnabled())
683 itemMenu
->Enable(id
, event
.GetEnabled());
697 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
699 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
700 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
701 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
702 OSStatus result
= eventNotHandledErr
;
704 switch ( GetEventClass( event
) )
706 case kEventClassCommand
:
707 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
710 case kEventClassControl
:
711 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
714 case kEventClassService
:
715 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
718 case kEventClassTextInput
:
719 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
726 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
731 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
733 #if !TARGET_API_MAC_OSX
735 // ---------------------------------------------------------------------------
736 // UserPane events for non OSX builds
737 // ---------------------------------------------------------------------------
739 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
741 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
743 win
->MacControlUserPaneDrawProc(part
) ;
745 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
747 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
749 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
751 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
753 return kControlNoPart
;
755 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
757 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
759 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
761 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
763 return kControlNoPart
;
765 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
767 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
769 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
771 win
->MacControlUserPaneIdleProc() ;
773 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
775 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
777 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
779 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
781 return kControlNoPart
;
783 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
785 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
787 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
789 win
->MacControlUserPaneActivateProc(activating
) ;
791 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
793 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
795 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
797 return win
->MacControlUserPaneFocusProc(action
) ;
799 return kControlNoPart
;
801 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
803 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
805 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
807 win
->MacControlUserPaneBackgroundProc(info
) ;
809 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
811 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
814 RgnHandle rgn
= NewRgn() ;
816 MacWindowToRootWindow( &x
, &y
) ;
817 OffsetRgn( rgn
, -x
, -y
) ;
818 wxMacWindowStateSaver
sv( this ) ;
819 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
820 MacDoRedraw( rgn
, 0 ) ;
824 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
826 return kControlNoPart
;
829 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
831 return kControlNoPart
;
834 void wxWindowMac::MacControlUserPaneIdleProc()
838 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
840 return kControlNoPart
;
843 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
847 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
849 if ( AcceptsFocus() )
852 return kControlNoPart
;
855 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
861 // ---------------------------------------------------------------------------
862 // Scrollbar Tracking for all
863 // ---------------------------------------------------------------------------
865 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
866 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
870 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
872 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
875 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
877 // ===========================================================================
879 // ===========================================================================
881 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
883 static MacControlMap wxWinMacControlList
;
885 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
887 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
889 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
892 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
894 // adding NULL ControlRef is (first) surely a result of an error and
895 // (secondly) breaks native event processing
896 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
898 wxWinMacControlList
[inControl
] = control
;
901 void wxRemoveMacControlAssociation(wxWindow
*control
)
903 // iterate over all the elements in the class
904 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
905 // we should go on...
911 MacControlMap::iterator it
;
912 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
914 if ( it
->second
== control
)
916 wxWinMacControlList
.erase(it
);
924 // ----------------------------------------------------------------------------
925 // constructors and such
926 // ----------------------------------------------------------------------------
928 wxWindowMac::wxWindowMac()
933 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
938 const wxString
& name
)
941 Create(parent
, id
, pos
, size
, style
, name
);
944 void wxWindowMac::Init()
949 #if WXWIN_COMPATIBILITY_2_4
950 m_backgroundTransparent
= false;
953 #if wxMAC_USE_CORE_GRAPHICS
954 m_cgContextRef
= NULL
;
957 // as all windows are created with WS_VISIBLE style...
960 m_hScrollBar
= NULL
;
961 m_vScrollBar
= NULL
;
962 m_macBackgroundBrush
= wxNullBrush
;
964 m_macIsUserPane
= true;
965 m_clipChildren
= false ;
966 m_cachedClippedRectValid
= false ;
968 // we need a valid font for the encodings
969 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
972 wxWindowMac::~wxWindowMac()
976 m_isBeingDeleted
= true;
978 MacInvalidateBorders() ;
980 #ifndef __WXUNIVERSAL__
981 // VS: make sure there's no wxFrame with last focus set to us:
982 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
984 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
987 if ( frame
->GetLastFocus() == this )
988 frame
->SetLastFocus((wxWindow
*)NULL
);
994 // destroy children before destroying this window itself
997 // wxRemoveMacControlAssociation( this ) ;
998 // If we delete an item, we should initialize the parent panel,
999 // because it could now be invalid.
1000 wxWindow
*parent
= GetParent() ;
1003 if (parent
->GetDefaultItem() == (wxButton
*) this)
1004 parent
->SetDefaultItem(NULL
);
1007 if ( m_peer
&& m_peer
->Ok() )
1009 // in case the callback might be called during destruction
1010 wxRemoveMacControlAssociation( this) ;
1011 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1012 // we currently are not using this hook
1013 // ::SetControlColorProc( *m_peer , NULL ) ;
1017 if ( g_MacLastWindow
== this )
1018 g_MacLastWindow
= NULL
;
1020 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1023 if ( frame
->GetLastFocus() == this )
1024 frame
->SetLastFocus( NULL
) ;
1027 // delete our drop target if we've got one
1028 #if wxUSE_DRAG_AND_DROP
1029 if ( m_dropTarget
!= NULL
)
1031 delete m_dropTarget
;
1032 m_dropTarget
= NULL
;
1039 WXWidget
wxWindowMac::GetHandle() const
1041 return (WXWidget
) m_peer
->GetControlRef() ;
1044 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1046 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1047 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1048 GetEventTypeCount(eventList
), eventList
, this,
1049 (EventHandlerRef
*)&m_macControlEventHandler
);
1051 #if !TARGET_API_MAC_OSX
1052 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1054 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1055 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1056 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1057 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1058 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1059 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1060 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1061 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1067 bool wxWindowMac::Create(wxWindowMac
*parent
,
1072 const wxString
& name
)
1074 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1076 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1079 m_windowVariant
= parent
->GetWindowVariant() ;
1081 if ( m_macIsUserPane
)
1083 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1086 | kControlSupportsEmbedding
1087 | kControlSupportsLiveFeedback
1088 | kControlGetsFocusOnClick
1089 // | kControlHasSpecialBackground
1090 // | kControlSupportsCalcBestRect
1091 | kControlHandlesTracking
1092 | kControlSupportsFocus
1093 | kControlWantsActivate
1094 | kControlWantsIdle
;
1096 m_peer
= new wxMacControl(this) ;
1097 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1098 verify_noerr( err
);
1100 MacPostControlCreate(pos
, size
) ;
1103 #ifndef __WXUNIVERSAL__
1104 // Don't give scrollbars to wxControls unless they ask for them
1105 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1106 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1108 MacCreateScrollBars( style
) ;
1112 wxWindowCreateEvent
event(this);
1113 GetEventHandler()->AddPendingEvent(event
);
1118 void wxWindowMac::MacChildAdded()
1121 m_vScrollBar
->Raise() ;
1123 m_hScrollBar
->Raise() ;
1126 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1128 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1130 m_peer
->SetReference( (long)this ) ;
1131 GetParent()->AddChild( this );
1133 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1135 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1136 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1137 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1138 GetParent()->MacChildAdded() ;
1140 // adjust font, controlsize etc
1141 DoSetWindowVariant( m_windowVariant
) ;
1143 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
1145 if (!m_macIsUserPane
)
1146 SetInitialBestSize(size
);
1148 SetCursor( *wxSTANDARD_CURSOR
) ;
1151 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1153 // Don't assert, in case we set the window variant before
1154 // the window is created
1155 // wxASSERT( m_peer->Ok() ) ;
1157 m_windowVariant
= variant
;
1159 if (m_peer
== NULL
|| !m_peer
->Ok())
1163 ThemeFontID themeFont
= kThemeSystemFont
;
1165 // we will get that from the settings later
1166 // and make this NORMAL later, but first
1167 // we have a few calculations that we must fix
1171 case wxWINDOW_VARIANT_NORMAL
:
1172 size
= kControlSizeNormal
;
1173 themeFont
= kThemeSystemFont
;
1176 case wxWINDOW_VARIANT_SMALL
:
1177 size
= kControlSizeSmall
;
1178 themeFont
= kThemeSmallSystemFont
;
1181 case wxWINDOW_VARIANT_MINI
:
1182 if (UMAGetSystemVersion() >= 0x1030 )
1184 // not always defined in the headers
1190 size
= kControlSizeSmall
;
1191 themeFont
= kThemeSmallSystemFont
;
1195 case wxWINDOW_VARIANT_LARGE
:
1196 size
= kControlSizeLarge
;
1197 themeFont
= kThemeSystemFont
;
1201 wxFAIL_MSG(_T("unexpected window variant"));
1205 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1208 font
.MacCreateThemeFont( themeFont
) ;
1212 void wxWindowMac::MacUpdateControlFont()
1214 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1218 bool wxWindowMac::SetFont(const wxFont
& font
)
1220 bool retval
= wxWindowBase::SetFont( font
);
1222 MacUpdateControlFont() ;
1227 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1229 bool retval
= wxWindowBase::SetForegroundColour( col
);
1232 MacUpdateControlFont();
1237 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1239 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1243 wxColour
newCol(GetBackgroundColour());
1245 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1246 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1247 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1248 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1250 brush
.SetColour( newCol
) ;
1252 MacSetBackgroundBrush( brush
) ;
1253 MacUpdateControlFont() ;
1258 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1260 m_macBackgroundBrush
= brush
;
1261 m_peer
->SetBackground( brush
) ;
1264 bool wxWindowMac::MacCanFocus() const
1266 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1267 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1268 // but the value range is nowhere documented
1269 Boolean keyExistsAndHasValidFormat
;
1270 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1271 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1273 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1279 UInt32 features
= 0 ;
1280 m_peer
->GetFeatures( &features
) ;
1282 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1286 void wxWindowMac::SetFocus()
1288 if ( !AcceptsFocus() )
1291 wxWindow
* former
= FindFocus() ;
1292 if ( former
== this )
1295 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1296 // we can only leave in case of an error
1297 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1298 if ( err
== errCouldntSetFocus
)
1301 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1303 #if !TARGET_API_MAC_OSX
1304 // emulate carbon events when running under CarbonLib where they are not natively available
1307 EventRef evRef
= NULL
;
1309 err
= MacCreateEvent(
1310 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1311 kEventAttributeUserEvent
, &evRef
);
1312 verify_noerr( err
);
1314 wxMacCarbonEvent
cEvent( evRef
) ;
1315 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1316 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1318 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1319 ReleaseEvent( evRef
) ;
1322 // send new focus event
1324 EventRef evRef
= NULL
;
1326 err
= MacCreateEvent(
1327 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1328 kEventAttributeUserEvent
, &evRef
);
1329 verify_noerr( err
);
1331 wxMacCarbonEvent
cEvent( evRef
) ;
1332 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1333 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1335 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1336 ReleaseEvent( evRef
) ;
1341 void wxWindowMac::DoCaptureMouse()
1343 wxApp::s_captureWindow
= this ;
1346 wxWindow
* wxWindowBase::GetCapture()
1348 return wxApp::s_captureWindow
;
1351 void wxWindowMac::DoReleaseMouse()
1353 wxApp::s_captureWindow
= NULL
;
1356 #if wxUSE_DRAG_AND_DROP
1358 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1360 if ( m_dropTarget
!= NULL
)
1361 delete m_dropTarget
;
1363 m_dropTarget
= pDropTarget
;
1364 if ( m_dropTarget
!= NULL
)
1372 // Old-style File Manager Drag & Drop
1373 void wxWindowMac::DragAcceptFiles(bool accept
)
1378 // Returns the size of the native control. In the case of the toplevel window
1379 // this is the content area root control
1381 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1382 int& w
, int& h
) const
1384 wxFAIL_MSG( wxT("Not currently supported") ) ;
1387 // From a wx position / size calculate the appropriate size of the native control
1389 bool wxWindowMac::MacGetBoundsForControl(
1393 int& w
, int& h
, bool adjustOrigin
) const
1395 // the desired size, minus the border pixels gives the correct size of the control
1399 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1400 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1401 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1403 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1404 if ( !isCompositing
)
1405 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1407 x
+= MacGetLeftBorderSize() ;
1408 y
+= MacGetTopBorderSize() ;
1409 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1410 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1413 AdjustForParentClientOrigin( x
, y
) ;
1415 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1416 if ( !GetParent()->IsTopLevel() )
1418 x
-= GetParent()->MacGetLeftBorderSize() ;
1419 y
-= GetParent()->MacGetTopBorderSize() ;
1425 // Get window size (not client size)
1426 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1429 m_peer
->GetRect( &bounds
) ;
1432 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1434 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1437 // get the position of the bounds of this window in client coordinates of its parent
1438 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1441 m_peer
->GetRect( &bounds
) ;
1443 int x1
= bounds
.left
;
1444 int y1
= bounds
.top
;
1446 // get the wx window position from the native one
1447 x1
-= MacGetLeftBorderSize() ;
1448 y1
-= MacGetTopBorderSize() ;
1450 if ( !IsTopLevel() )
1452 wxWindow
*parent
= GetParent();
1455 // we must first adjust it to be in window coordinates of the parent,
1456 // as otherwise it gets lost by the ClientAreaOrigin fix
1457 x1
+= parent
->MacGetLeftBorderSize() ;
1458 y1
+= parent
->MacGetTopBorderSize() ;
1460 // and now to client coordinates
1461 wxPoint
pt(parent
->GetClientAreaOrigin());
1473 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1475 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1476 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1478 Point localwhere
= { 0, 0 } ;
1485 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1492 MacRootWindowToWindow( x
, y
) ;
1494 wxPoint origin
= GetClientAreaOrigin() ;
1501 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1503 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1504 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1506 wxPoint origin
= GetClientAreaOrigin() ;
1512 MacWindowToRootWindow( x
, y
) ;
1514 Point localwhere
= { 0, 0 };
1520 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1528 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1530 wxPoint origin
= GetClientAreaOrigin() ;
1536 MacWindowToRootWindow( x
, y
) ;
1539 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1541 MacRootWindowToWindow( x
, y
) ;
1543 wxPoint origin
= GetClientAreaOrigin() ;
1550 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1559 if ( !IsTopLevel() )
1561 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1564 pt
.x
-= MacGetLeftBorderSize() ;
1565 pt
.y
-= MacGetTopBorderSize() ;
1566 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1576 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1585 MacWindowToRootWindow( &x1
, &y1
) ;
1593 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1602 if ( !IsTopLevel() )
1604 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1607 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1608 pt
.x
+= MacGetLeftBorderSize() ;
1609 pt
.y
+= MacGetTopBorderSize() ;
1619 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1628 MacRootWindowToWindow( &x1
, &y1
) ;
1636 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1638 RgnHandle rgn
= NewRgn() ;
1640 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1642 Rect structure
, content
;
1644 GetRegionBounds( rgn
, &content
) ;
1645 m_peer
->GetRect( &structure
) ;
1646 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1648 left
= content
.left
- structure
.left
;
1649 top
= content
.top
- structure
.top
;
1650 right
= structure
.right
- content
.right
;
1651 bottom
= structure
.bottom
- content
.bottom
;
1655 left
= top
= right
= bottom
= 0 ;
1661 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1663 wxSize sizeTotal
= size
;
1665 RgnHandle rgn
= NewRgn() ;
1666 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1668 Rect content
, structure
;
1669 GetRegionBounds( rgn
, &content
) ;
1670 m_peer
->GetRect( &structure
) ;
1672 // structure is in parent coordinates, but we only need width and height, so it's ok
1674 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1675 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1680 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1681 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1686 // Get size *available for subwindows* i.e. excluding menu bar etc.
1687 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1691 RgnHandle rgn
= NewRgn() ;
1693 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1694 GetRegionBounds( rgn
, &content
) ;
1696 m_peer
->GetRect( &content
) ;
1699 ww
= content
.right
- content
.left
;
1700 hh
= content
.bottom
- content
.top
;
1702 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1703 hh
-= m_hScrollBar
->GetSize().y
;
1705 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1706 ww
-= m_vScrollBar
->GetSize().x
;
1714 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1716 if (m_cursor
== cursor
)
1719 if (wxNullCursor
== cursor
)
1721 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1726 if ( ! wxWindowBase::SetCursor( cursor
) )
1730 wxASSERT_MSG( m_cursor
.Ok(),
1731 wxT("cursor must be valid after call to the base version"));
1733 wxWindowMac
*mouseWin
= 0 ;
1735 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1736 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1738 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1740 // TODO: If we ever get a GetCurrentEvent... replacement
1741 // for the mouse position, use it...
1744 ControlPartCode part
;
1745 ControlRef control
;
1748 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1750 mouseWin
= wxFindControlFromMacControl( control
) ;
1753 QDSwapPort( savePort
, NULL
) ;
1756 if ( mouseWin
== this && !wxIsBusy() )
1757 m_cursor
.MacInstall() ;
1763 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1765 menu
->SetInvokingWindow(this);
1768 if ( x
== -1 && y
== -1 )
1770 wxPoint mouse
= wxGetMousePosition();
1776 ClientToScreen( &x
, &y
) ;
1779 menu
->MacBeforeDisplay( true ) ;
1780 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1781 if ( HiWord(menuResult
) != 0 )
1784 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1785 int id
= wxMacCommandToId( macid
);
1786 wxMenuItem
* item
= NULL
;
1788 item
= menu
->FindItem( id
, &realmenu
) ;
1791 if (item
->IsCheckable())
1792 item
->Check( !item
->IsChecked() ) ;
1794 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1798 menu
->MacAfterDisplay( true ) ;
1799 menu
->SetInvokingWindow( NULL
);
1805 // ----------------------------------------------------------------------------
1807 // ----------------------------------------------------------------------------
1811 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1813 wxWindowBase::DoSetToolTip(tooltip
);
1816 m_tooltip
->SetWindow(this);
1821 void wxWindowMac::MacInvalidateBorders()
1823 if ( m_peer
== NULL
)
1826 bool vis
= MacIsReallyShown() ;
1830 int outerBorder
= MacGetLeftBorderSize() ;
1831 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1834 if ( outerBorder
== 0 )
1837 // now we know that we have something to do at all
1839 // as the borders are drawn on the parent we have to properly invalidate all these areas
1840 RgnHandle updateInner
, updateOuter
;
1843 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1844 updateInner
= NewRgn() ;
1845 updateOuter
= NewRgn() ;
1847 m_peer
->GetRect( &rect
) ;
1848 RectRgn( updateInner
, &rect
) ;
1849 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1850 RectRgn( updateOuter
, &rect
) ;
1851 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1853 #ifdef __WXMAC_OSX__
1854 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1856 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1858 InvalWindowRgn( tlw
, updateOuter
) ;
1861 DisposeRgn( updateOuter
) ;
1862 DisposeRgn( updateInner
) ;
1865 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1867 // this is never called for a toplevel window, so we know we have a parent
1868 int former_x
, former_y
, former_w
, former_h
;
1870 // Get true coordinates of former position
1871 DoGetPosition( &former_x
, &former_y
) ;
1872 DoGetSize( &former_w
, &former_h
) ;
1874 wxWindow
*parent
= GetParent();
1877 wxPoint
pt(parent
->GetClientAreaOrigin());
1882 int actualWidth
= width
;
1883 int actualHeight
= height
;
1887 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1888 actualWidth
= m_minWidth
;
1889 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1890 actualHeight
= m_minHeight
;
1891 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1892 actualWidth
= m_maxWidth
;
1893 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1894 actualHeight
= m_maxHeight
;
1896 bool doMove
= false, doResize
= false ;
1898 if ( actualX
!= former_x
|| actualY
!= former_y
)
1901 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1904 if ( doMove
|| doResize
)
1906 // as the borders are drawn outside the native control, we adjust now
1908 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1909 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1910 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1913 wxMacRectToNative( &bounds
, &r
) ;
1915 if ( !GetParent()->IsTopLevel() )
1916 wxMacWindowToNative( GetParent() , &r
) ;
1918 MacInvalidateBorders() ;
1920 m_cachedClippedRectValid
= false ;
1921 m_peer
->SetRect( &r
) ;
1923 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1925 MacInvalidateBorders() ;
1927 MacRepositionScrollBars() ;
1930 wxPoint
point(actualX
, actualY
);
1931 wxMoveEvent
event(point
, m_windowId
);
1932 event
.SetEventObject(this);
1933 GetEventHandler()->ProcessEvent(event
) ;
1938 MacRepositionScrollBars() ;
1939 wxSize
size(actualWidth
, actualHeight
);
1940 wxSizeEvent
event(size
, m_windowId
);
1941 event
.SetEventObject(this);
1942 GetEventHandler()->ProcessEvent(event
);
1947 wxSize
wxWindowMac::DoGetBestSize() const
1949 if ( m_macIsUserPane
|| IsTopLevel() )
1950 return wxWindowBase::DoGetBestSize() ;
1952 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1953 int bestWidth
, bestHeight
;
1955 m_peer
->GetBestRect( &bestsize
) ;
1956 if ( EmptyRect( &bestsize
) )
1961 bestsize
.bottom
= 16 ;
1963 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1965 bestsize
.bottom
= 16 ;
1968 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1970 bestsize
.bottom
= 24 ;
1975 // return wxWindowBase::DoGetBestSize() ;
1979 bestWidth
= bestsize
.right
- bestsize
.left
;
1980 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1981 if ( bestHeight
< 10 )
1984 return wxSize(bestWidth
, bestHeight
);
1987 // set the size of the window: if the dimensions are positive, just use them,
1988 // but if any of them is equal to -1, it means that we must find the value for
1989 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1990 // which case -1 is a valid value for x and y)
1992 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1993 // the width/height to best suit our contents, otherwise we reuse the current
1995 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1997 // get the current size and position...
1998 int currentX
, currentY
;
1999 int currentW
, currentH
;
2001 GetPosition(¤tX
, ¤tY
);
2002 GetSize(¤tW
, ¤tH
);
2004 // ... and don't do anything (avoiding flicker) if it's already ok
2005 if ( x
== currentX
&& y
== currentY
&&
2006 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2009 MacRepositionScrollBars() ; // we might have a real position shift
2014 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2016 if ( x
== wxDefaultCoord
)
2018 if ( y
== wxDefaultCoord
)
2022 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2024 wxSize size
= wxDefaultSize
;
2025 if ( width
== wxDefaultCoord
)
2027 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2029 size
= DoGetBestSize();
2034 // just take the current one
2039 if ( height
== wxDefaultCoord
)
2041 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2043 if ( size
.x
== wxDefaultCoord
)
2044 size
= DoGetBestSize();
2045 // else: already called DoGetBestSize() above
2051 // just take the current one
2056 DoMoveWindow( x
, y
, width
, height
);
2059 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2061 RgnHandle rgn
= NewRgn() ;
2063 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2065 GetRegionBounds( rgn
, &content
) ;
2075 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2078 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2080 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2082 int currentclientwidth
, currentclientheight
;
2083 int currentwidth
, currentheight
;
2085 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2086 GetSize( ¤twidth
, ¤theight
) ;
2088 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2089 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2093 void wxWindowMac::SetLabel(const wxString
& title
)
2095 m_label
= wxStripMenuCodes(title
) ;
2097 if ( m_peer
&& m_peer
->Ok() )
2098 m_peer
->SetLabel( m_label
) ;
2103 wxString
wxWindowMac::GetLabel() const
2108 bool wxWindowMac::Show(bool show
)
2110 bool former
= MacIsReallyShown() ;
2111 if ( !wxWindowBase::Show(show
) )
2114 // TODO: use visibilityChanged Carbon Event for OSX
2116 m_peer
->SetVisibility( show
, true ) ;
2118 if ( former
!= MacIsReallyShown() )
2119 MacPropagateVisibilityChanged() ;
2124 bool wxWindowMac::Enable(bool enable
)
2126 wxASSERT( m_peer
->Ok() ) ;
2127 bool former
= MacIsReallyEnabled() ;
2128 if ( !wxWindowBase::Enable(enable
) )
2131 m_peer
->Enable( enable
) ;
2133 if ( former
!= MacIsReallyEnabled() )
2134 MacPropagateEnabledStateChanged() ;
2140 // status change propagations (will be not necessary for OSX later )
2143 void wxWindowMac::MacPropagateVisibilityChanged()
2145 #if !TARGET_API_MAC_OSX
2146 MacVisibilityChanged() ;
2149 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2152 child
= node
->GetData();
2153 if ( child
->IsShown() )
2154 child
->MacPropagateVisibilityChanged() ;
2156 node
= node
->GetNext();
2161 void wxWindowMac::MacPropagateEnabledStateChanged()
2163 #if !TARGET_API_MAC_OSX
2164 MacEnabledStateChanged() ;
2167 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2170 child
= node
->GetData();
2171 if ( child
->IsEnabled() )
2172 child
->MacPropagateEnabledStateChanged() ;
2174 node
= node
->GetNext();
2179 void wxWindowMac::MacPropagateHiliteChanged()
2181 #if !TARGET_API_MAC_OSX
2182 MacHiliteChanged() ;
2185 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2188 child
= node
->GetData();
2189 if (child
/* && child->IsEnabled() */)
2190 child
->MacPropagateHiliteChanged() ;
2192 node
= node
->GetNext();
2198 // status change notifications
2201 void wxWindowMac::MacVisibilityChanged()
2205 void wxWindowMac::MacHiliteChanged()
2209 void wxWindowMac::MacEnabledStateChanged()
2214 // status queries on the inherited window's state
2217 bool wxWindowMac::MacIsReallyShown()
2219 // only under OSX the visibility of the TLW is taken into account
2220 if ( m_isBeingDeleted
)
2223 #if TARGET_API_MAC_OSX
2224 if ( m_peer
&& m_peer
->Ok() )
2225 return m_peer
->IsVisible();
2228 wxWindow
* win
= this ;
2229 while ( win
->IsShown() )
2231 if ( win
->IsTopLevel() )
2234 win
= win
->GetParent() ;
2242 bool wxWindowMac::MacIsReallyEnabled()
2244 return m_peer
->IsEnabled() ;
2247 bool wxWindowMac::MacIsReallyHilited()
2249 return m_peer
->IsActive();
2252 void wxWindowMac::MacFlashInvalidAreas()
2254 #if TARGET_API_MAC_OSX
2255 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2259 int wxWindowMac::GetCharHeight() const
2261 wxClientDC
dc( (wxWindowMac
*)this ) ;
2263 return dc
.GetCharHeight() ;
2266 int wxWindowMac::GetCharWidth() const
2268 wxClientDC
dc( (wxWindowMac
*)this ) ;
2270 return dc
.GetCharWidth() ;
2273 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2274 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2276 const wxFont
*fontToUse
= theFont
;
2278 fontToUse
= &m_font
;
2280 wxClientDC
dc( (wxWindowMac
*) this ) ;
2282 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2283 if ( externalLeading
)
2284 *externalLeading
= le
;
2294 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2295 * we always intersect with the entire window, not only with the client area
2298 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2300 if ( m_peer
== NULL
)
2303 if ( !MacIsReallyShown() )
2310 wxMacRectToNative( rect
, &r
) ;
2311 m_peer
->SetNeedsDisplay( &r
) ;
2315 m_peer
->SetNeedsDisplay() ;
2319 void wxWindowMac::Freeze()
2321 #if TARGET_API_MAC_OSX
2322 if ( !m_frozenness
++ )
2324 if ( m_peer
&& m_peer
->Ok() )
2325 m_peer
->SetDrawingEnabled( false ) ;
2330 void wxWindowMac::Thaw()
2332 #if TARGET_API_MAC_OSX
2333 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2335 if ( !--m_frozenness
)
2337 if ( m_peer
&& m_peer
->Ok() )
2339 m_peer
->SetDrawingEnabled( true ) ;
2340 m_peer
->InvalidateWithChildren() ;
2346 wxWindowMac
*wxGetActiveWindow()
2348 // actually this is a windows-only concept
2352 // Coordinates relative to the window
2353 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2355 // We really don't move the mouse programmatically under Mac.
2358 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2360 if ( MacGetTopLevelWindow() == NULL
)
2363 #if TARGET_API_MAC_OSX
2364 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2371 event
.GetDC()->Clear() ;
2375 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2380 int wxWindowMac::GetScrollPos(int orient
) const
2382 if ( orient
== wxHORIZONTAL
)
2385 return m_hScrollBar
->GetThumbPosition() ;
2390 return m_vScrollBar
->GetThumbPosition() ;
2396 // This now returns the whole range, not just the number
2397 // of positions that we can scroll.
2398 int wxWindowMac::GetScrollRange(int orient
) const
2400 if ( orient
== wxHORIZONTAL
)
2403 return m_hScrollBar
->GetRange() ;
2408 return m_vScrollBar
->GetRange() ;
2414 int wxWindowMac::GetScrollThumb(int orient
) const
2416 if ( orient
== wxHORIZONTAL
)
2419 return m_hScrollBar
->GetThumbSize() ;
2424 return m_vScrollBar
->GetThumbSize() ;
2430 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2432 if ( orient
== wxHORIZONTAL
)
2435 m_hScrollBar
->SetThumbPosition( pos
) ;
2440 m_vScrollBar
->SetThumbPosition( pos
) ;
2445 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2446 // our own window origin is at leftOrigin/rightOrigin
2449 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2455 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2456 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2458 // back to the surrounding frame rectangle
2459 m_peer
->GetRect( &rect
) ;
2460 InsetRect( &rect
, -1 , -1 ) ;
2462 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2463 if ( UMAGetSystemVersion() >= 0x1030 )
2465 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2466 rect
.bottom
- rect
.top
) ;
2468 HIThemeFrameDrawInfo info
;
2469 memset( &info
, 0 , sizeof(info
) ) ;
2473 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2474 info
.isFocused
= hasFocus
;
2476 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2477 wxASSERT( cgContext
) ;
2479 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2481 info
.kind
= kHIThemeFrameTextFieldSquare
;
2482 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2484 else if ( HasFlag(wxSIMPLE_BORDER
) )
2486 info
.kind
= kHIThemeFrameListBox
;
2487 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2489 else if ( hasFocus
)
2491 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2494 m_peer
->GetRect( &rect
) ;
2495 if ( hasBothScrollbars
)
2497 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2498 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2499 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2500 HIThemeGrowBoxDrawInfo info
;
2501 memset( &info
, 0, sizeof(info
) ) ;
2503 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2504 info
.kind
= kHIThemeGrowBoxKindNone
;
2505 info
.size
= kHIThemeGrowBoxSizeNormal
;
2506 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2507 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2513 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2517 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2518 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2521 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2522 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2523 else if ( HasFlag(wxSIMPLE_BORDER
) )
2524 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2527 DrawThemeFocusRect( &rect
, true ) ;
2529 if ( hasBothScrollbars
)
2531 // GetThemeStandaloneGrowBoxBounds
2532 // DrawThemeStandaloneNoGrowBox
2537 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2539 if ( child
== m_hScrollBar
)
2540 m_hScrollBar
= NULL
;
2541 if ( child
== m_vScrollBar
)
2542 m_vScrollBar
= NULL
;
2544 wxWindowBase::RemoveChild( child
) ;
2547 // New function that will replace some of the above.
2548 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2549 int range
, bool refresh
)
2553 if ( orient
== wxHORIZONTAL
)
2557 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2558 if ( m_hScrollBar
->IsShown() != showScroller
)
2559 m_hScrollBar
->Show( showScroller
) ;
2561 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2568 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2569 if ( m_vScrollBar
->IsShown() != showScroller
)
2570 m_vScrollBar
->Show( showScroller
) ;
2572 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2576 MacRepositionScrollBars() ;
2579 // Does a physical scroll
2580 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2582 if ( dx
== 0 && dy
== 0 )
2585 int width
, height
;
2586 GetClientSize( &width
, &height
) ;
2588 #if TARGET_API_MAC_OSX
2589 if ( true /* m_peer->IsCompositing() */ )
2591 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2592 // area is scrolled, this does not occur if width and height are 2 pixels less,
2593 // TODO: write optimal workaround
2594 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2596 scrollrect
.Intersect( *rect
) ;
2598 if ( m_peer
->GetNeedsDisplay() )
2600 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2601 // either immediate redraw or full invalidate
2603 // is the better overall solution, as it does not slow down scrolling
2604 m_peer
->SetNeedsDisplay() ;
2606 // this would be the preferred version for fast drawing controls
2608 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2609 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2610 HIViewRender(m_peer
->GetControlRef()) ;
2617 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2618 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2619 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2621 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2622 // either immediate redraw or full invalidate
2624 // is the better overall solution, as it does not slow down scrolling
2625 m_peer
->SetNeedsDisplay() ;
2627 // this would be the preferred version for fast drawing controls
2629 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2630 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2631 HIViewRender(m_peer
->GetControlRef()) ;
2645 RgnHandle updateRgn
= NewRgn() ;
2648 wxClientDC
dc(this) ;
2649 wxMacPortSetter
helper(&dc
) ;
2651 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2652 //scrollrect.top += MacGetTopBorderSize() ;
2653 //scrollrect.left += MacGetLeftBorderSize() ;
2654 scrollrect
.bottom
= scrollrect
.top
+ height
;
2655 scrollrect
.right
= scrollrect
.left
+ width
;
2659 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2660 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2661 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2664 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2666 // now scroll the former update region as well and add the new update region
2667 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2668 RgnHandle formerUpdateRgn
= NewRgn() ;
2669 RgnHandle scrollRgn
= NewRgn() ;
2670 RectRgn( scrollRgn
, &scrollrect
) ;
2671 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2673 LocalToGlobal( &pt
) ;
2674 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2675 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2677 if ( !EmptyRgn( formerUpdateRgn
) )
2679 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2680 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2681 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2684 InvalWindowRgn(rootWindow
, updateRgn
) ;
2685 DisposeRgn( updateRgn
) ;
2686 DisposeRgn( formerUpdateRgn
) ;
2687 DisposeRgn( scrollRgn
) ;
2695 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2697 child
= node
->GetData();
2700 if (child
== m_vScrollBar
)
2702 if (child
== m_hScrollBar
)
2704 if (child
->IsTopLevel())
2707 child
->GetPosition( &x
, &y
);
2708 child
->GetSize( &w
, &h
);
2711 wxRect
rc( x
, y
, w
, h
);
2712 if (rect
->Intersects( rc
))
2713 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2717 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2722 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2724 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2726 wxScrollWinEvent wevent
;
2727 wevent
.SetPosition(event
.GetPosition());
2728 wevent
.SetOrientation(event
.GetOrientation());
2729 wevent
.SetEventObject(this);
2731 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2732 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2733 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2734 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2735 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2736 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2737 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2738 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2739 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2740 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2741 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2742 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2743 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2744 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2745 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2746 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2748 GetEventHandler()->ProcessEvent(wevent
);
2752 // Get the window with the focus
2753 wxWindowMac
*wxWindowBase::DoFindFocus()
2755 ControlRef control
;
2756 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2757 return wxFindControlFromMacControl( control
) ;
2760 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2762 // panel wants to track the window which was the last to have focus in it,
2763 // so we want to set ourselves as the window which last had focus
2765 // notice that it's also important to do it upwards the tree because
2766 // otherwise when the top level panel gets focus, it won't set it back to
2767 // us, but to some other sibling
2769 // CS: don't know if this is still needed:
2770 //wxChildFocusEvent eventFocus(this);
2771 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2773 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2775 #if wxMAC_USE_CORE_GRAPHICS
2776 GetParent()->Refresh() ;
2778 wxMacWindowStateSaver
sv( this ) ;
2781 m_peer
->GetRect( &rect
) ;
2782 // auf den umgebenden Rahmen zur\9fck
2783 InsetRect( &rect
, -1 , -1 ) ;
2785 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2789 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2791 rect
.right
+= pt
.x
;
2793 rect
.bottom
+= pt
.y
;
2796 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2797 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2798 if ( !bIsFocusEvent
)
2800 // as this erases part of the frame we have to redraw borders
2801 // and because our z-ordering is not always correct (staticboxes)
2802 // we have to invalidate things, we cannot simple redraw
2803 MacInvalidateBorders() ;
2811 void wxWindowMac::OnInternalIdle()
2813 // This calls the UI-update mechanism (querying windows for
2814 // menu/toolbar/control state information)
2815 if (wxUpdateUIEvent::CanUpdate(this))
2816 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2819 // Raise the window to the top of the Z order
2820 void wxWindowMac::Raise()
2822 m_peer
->SetZOrder( true , NULL
) ;
2825 // Lower the window to the bottom of the Z order
2826 void wxWindowMac::Lower()
2828 m_peer
->SetZOrder( false , NULL
) ;
2831 // static wxWindow *gs_lastWhich = NULL;
2833 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2835 // first trigger a set cursor event
2837 wxPoint clientorigin
= GetClientAreaOrigin() ;
2838 wxSize clientsize
= GetClientSize() ;
2840 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2842 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2844 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2845 if ( processedEvtSetCursor
&& event
.HasCursor() )
2847 cursor
= event
.GetCursor() ;
2851 // the test for processedEvtSetCursor is here to prevent using m_cursor
2852 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2853 // it - this is a way to say that our cursor shouldn't be used for this
2855 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2858 if ( !wxIsBusy() && !GetParent() )
2859 cursor
= *wxSTANDARD_CURSOR
;
2863 cursor
.MacInstall() ;
2866 return cursor
.Ok() ;
2869 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2873 return m_tooltip
->GetTip() ;
2876 return wxEmptyString
;
2879 void wxWindowMac::ClearBackground()
2885 void wxWindowMac::Update()
2887 #if TARGET_API_MAC_OSX
2888 MacGetTopLevelWindow()->MacPerformUpdates() ;
2890 ::Draw1Control( m_peer
->GetControlRef() ) ;
2894 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2896 wxTopLevelWindowMac
* win
= NULL
;
2897 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2899 win
= wxFindWinFromMacWindow( window
) ;
2904 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2906 MacUpdateClippedRects() ;
2908 return m_cachedClippedClientRect
;
2911 const wxRect
& wxWindowMac::MacGetClippedRect() const
2913 MacUpdateClippedRects() ;
2915 return m_cachedClippedRect
;
2918 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2920 MacUpdateClippedRects() ;
2922 return m_cachedClippedRectWithOuterStructure
;
2925 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2927 static wxRegion emptyrgn
;
2929 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2931 MacUpdateClippedRects() ;
2932 if ( includeOuterStructures
)
2933 return m_cachedClippedRegionWithOuterStructure
;
2935 return m_cachedClippedRegion
;
2943 void wxWindowMac::MacUpdateClippedRects() const
2945 if ( m_cachedClippedRectValid
)
2948 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2949 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2950 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2951 // to add focus borders everywhere
2953 Rect r
, rIncludingOuterStructures
;
2955 m_peer
->GetRect( &r
) ;
2956 r
.left
-= MacGetLeftBorderSize() ;
2957 r
.top
-= MacGetTopBorderSize() ;
2958 r
.bottom
+= MacGetBottomBorderSize() ;
2959 r
.right
+= MacGetRightBorderSize() ;
2966 rIncludingOuterStructures
= r
;
2967 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2969 wxRect cl
= GetClientRect() ;
2970 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2974 const wxWindow
* child
= this ;
2975 const wxWindow
* parent
= NULL
;
2977 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2979 if ( parent
->MacIsChildOfClientArea(child
) )
2981 size
= parent
->GetClientSize() ;
2982 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2988 // this will be true for scrollbars, toolbars etc.
2989 size
= parent
->GetSize() ;
2990 y
= parent
->MacGetTopBorderSize() ;
2991 x
= parent
->MacGetLeftBorderSize() ;
2992 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2993 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2996 parent
->MacWindowToRootWindow( &x
, &y
) ;
2997 MacRootWindowToWindow( &x
, &y
) ;
2999 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
3001 // the wxwindow and client rects will always be clipped
3002 SectRect( &r
, &rparent
, &r
) ;
3003 SectRect( &rClient
, &rparent
, &rClient
) ;
3005 // the structure only at 'hard' borders
3006 if ( parent
->MacClipChildren() ||
3007 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
3009 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
3015 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
3016 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
3017 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
3018 m_cachedClippedRectWithOuterStructure
= wxRect(
3019 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
3020 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
3021 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
3023 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
3024 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
3025 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
3027 m_cachedClippedRectValid
= true ;
3031 This function must not change the updatergn !
3033 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3035 bool handled
= false ;
3037 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3038 GetRegionBounds( updatergn
, &updatebounds
) ;
3040 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3042 if ( !EmptyRgn(updatergn
) )
3044 RgnHandle newupdate
= NewRgn() ;
3045 wxSize point
= GetClientSize() ;
3046 wxPoint origin
= GetClientAreaOrigin() ;
3047 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3048 SectRgn( newupdate
, updatergn
, newupdate
) ;
3050 // first send an erase event to the entire update area
3052 // for the toplevel window this really is the entire area
3053 // for all the others only their client area, otherwise they
3054 // might be drawing with full alpha and eg put blue into
3055 // the grow-box area of a scrolled window (scroll sample)
3056 wxDC
* dc
= new wxWindowDC(this);
3058 dc
->SetClippingRegion(wxRegion(updatergn
));
3060 dc
->SetClippingRegion(wxRegion(newupdate
));
3062 wxEraseEvent
eevent( GetId(), dc
);
3063 eevent
.SetEventObject( this );
3064 GetEventHandler()->ProcessEvent( eevent
);
3068 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3069 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3070 m_updateRegion
= newupdate
;
3071 DisposeRgn( newupdate
) ;
3073 if ( !m_updateRegion
.Empty() )
3075 // paint the window itself
3078 event
.SetTimestamp(time
);
3079 event
.SetEventObject(this);
3080 GetEventHandler()->ProcessEvent(event
);
3084 // now we cannot rely on having its borders drawn by a window itself, as it does not
3085 // get the updateRgn wide enough to always do so, so we do it from the parent
3086 // this would also be the place to draw any custom backgrounds for native controls
3087 // in Composited windowing
3088 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3092 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3094 child
= node
->GetData();
3097 if (child
== m_vScrollBar
)
3099 if (child
== m_hScrollBar
)
3101 if (child
->IsTopLevel())
3103 if (!child
->IsShown())
3106 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3108 child
->GetPosition( &x
, &y
);
3109 child
->GetSize( &w
, &h
);
3110 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3111 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3112 InsetRect( &childRect
, -10 , -10) ;
3114 if ( RectInRgn( &childRect
, updatergn
) )
3116 // paint custom borders
3117 wxNcPaintEvent
eventNc( child
->GetId() );
3118 eventNc
.SetEventObject( child
);
3119 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3121 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3122 if ( UMAGetSystemVersion() >= 0x1030 )
3124 child
->MacPaintBorders(0, 0) ;
3129 wxWindowDC
dc(this) ;
3130 dc
.SetClippingRegion(wxRegion(updatergn
));
3131 wxMacPortSetter
helper(&dc
) ;
3132 child
->MacPaintBorders(0, 0) ;
3143 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3145 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3149 if ( iter
->IsTopLevel() )
3150 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3152 iter
= iter
->GetParent() ;
3155 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3160 void wxWindowMac::MacCreateScrollBars( long style
)
3162 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3164 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3166 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3167 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3168 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3169 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3171 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3172 variant
= wxWINDOW_VARIANT_SMALL
;
3175 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3177 GetClientSize( &width
, &height
) ;
3179 wxPoint
vPoint(width
- scrlsize
, 0) ;
3180 wxSize
vSize(scrlsize
, height
- adjust
) ;
3181 wxPoint
hPoint(0, height
- scrlsize
) ;
3182 wxSize
hSize(width
- adjust
, scrlsize
) ;
3184 if ( style
& wxVSCROLL
)
3185 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3187 if ( style
& wxHSCROLL
)
3188 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3191 // because the create does not take into account the client area origin
3192 // we might have a real position shift
3193 MacRepositionScrollBars() ;
3196 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3198 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3203 void wxWindowMac::MacRepositionScrollBars()
3205 if ( !m_hScrollBar
&& !m_vScrollBar
)
3208 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3209 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3210 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3212 // get real client area
3214 GetSize( &width
, &height
);
3216 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3217 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3219 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3220 wxSize
vSize( scrlsize
, height
- adjust
) ;
3221 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3222 wxSize
hSize( width
- adjust
, scrlsize
) ;
3225 int x
= 0, y
= 0, w
, h
;
3226 GetSize( &w
, &h
) ;
3228 MacClientToRootWindow( &x
, &y
) ;
3229 MacClientToRootWindow( &w
, &h
) ;
3231 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3233 int totW
= 10000 , totH
= 10000;
3236 if ( iter
->IsTopLevel() )
3238 iter
->GetSize( &totW
, &totH
) ;
3242 iter
= iter
->GetParent() ;
3256 if ( w
- x
>= totW
)
3261 if ( h
- y
>= totH
)
3269 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3271 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3274 bool wxWindowMac::AcceptsFocus() const
3276 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3279 void wxWindowMac::MacSuperChangedPosition()
3281 // only window-absolute structures have to be moved i.e. controls
3283 m_cachedClippedRectValid
= false ;
3286 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3289 child
= node
->GetData();
3290 child
->MacSuperChangedPosition() ;
3292 node
= node
->GetNext();
3296 void wxWindowMac::MacTopLevelWindowChangedPosition()
3298 // only screen-absolute structures have to be moved i.e. glcanvas
3301 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3304 child
= node
->GetData();
3305 child
->MacTopLevelWindowChangedPosition() ;
3307 node
= node
->GetNext();
3311 long wxWindowMac::MacGetLeftBorderSize() const
3318 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3320 // this metric is only the 'outset' outside the simple frame rect
3321 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3324 else if (HasFlag(wxSIMPLE_BORDER
))
3326 // this metric is only the 'outset' outside the simple frame rect
3327 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3334 long wxWindowMac::MacGetRightBorderSize() const
3336 // they are all symmetric in mac themes
3337 return MacGetLeftBorderSize() ;
3340 long wxWindowMac::MacGetTopBorderSize() const
3342 // they are all symmetric in mac themes
3343 return MacGetLeftBorderSize() ;
3346 long wxWindowMac::MacGetBottomBorderSize() const
3348 // they are all symmetric in mac themes
3349 return MacGetLeftBorderSize() ;
3352 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3354 return style
& ~wxBORDER_MASK
;
3357 // Find the wxWindowMac at the current mouse position, returning the mouse
3359 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3361 pt
= wxGetMousePosition();
3362 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3367 // Get the current mouse position.
3368 wxPoint
wxGetMousePosition()
3372 wxGetMousePosition( &x
, &y
);
3374 return wxPoint(x
, y
);
3377 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3379 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3381 // copied from wxGTK : CS
3382 // VZ: shouldn't we move this to base class then?
3384 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3387 // (a) it's a command event and so is propagated to the parent
3388 // (b) under MSW it can be generated from kbd too
3389 // (c) it uses screen coords (because of (a))
3390 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3392 this->ClientToScreen(event
.GetPosition()));
3393 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3402 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3404 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3405 CallNextEventHandler(
3406 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3407 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3410 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3414 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3418 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3419 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3424 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3426 return eventNotHandledErr
;
3429 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3431 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3432 if ( !wxWindowBase::Reparent(newParent
) )
3435 // copied from MacPostControlCreate
3436 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3438 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3440 ::EmbedControl( m_peer
->GetControlRef() , container
) ;