1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
28 #include "wx/layout.h"
29 #include "wx/dialog.h"
30 #include "wx/scrolbar.h"
31 #include "wx/statbox.h"
32 #include "wx/settings.h"
33 #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"
47 #if wxUSE_DRAG_AND_DROP
51 #include "wx/mac/uma.h"
53 #define MAC_SCROLLBAR_SIZE 15
54 #define MAC_SMALL_SCROLLBAR_SIZE 11
58 #include <ToolUtils.h>
60 #include <MacTextEditor.h>
63 #if TARGET_API_MAC_OSX
65 #include <HIToolbox/HIView.h>
71 extern wxList wxPendingDelete
;
73 #ifdef __WXUNIVERSAL__
74 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
76 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
79 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
82 #if TARGET_API_MAC_OSX
83 EVT_PAINT(wxWindowMac::OnPaint
)
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
90 #define wxMAC_DEBUG_REDRAW 0
91 #ifndef wxMAC_DEBUG_REDRAW
92 #define wxMAC_DEBUG_REDRAW 0
95 #define wxMAC_USE_THEME_BORDER 1
97 // ---------------------------------------------------------------------------
98 // Utility Routines to move between different coordinate systems
99 // ---------------------------------------------------------------------------
102 * Right now we have the following setup :
103 * a border that is not part of the native control is always outside the
104 * control's border (otherwise we loose all native intelligence, future ways
105 * may be to have a second embedding control responsible for drawing borders
106 * and backgrounds eventually)
107 * so all this border calculations have to be taken into account when calling
108 * native methods or getting native oriented data
109 * so we have three coordinate systems here
110 * wx client coordinates
111 * wx window coordinates (including window frames)
116 // originating from native control
120 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
122 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
125 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
127 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
131 // directed towards native control
134 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
136 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
139 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
141 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
144 // ---------------------------------------------------------------------------
146 // ---------------------------------------------------------------------------
148 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
149 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
151 #if TARGET_API_MAC_OSX
153 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
156 kEventControlVisibilityChanged
= 157
162 static const EventTypeSpec eventList
[] =
164 { kEventClassCommand
, kEventProcessCommand
} ,
165 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
167 { kEventClassControl
, kEventControlHit
} ,
169 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
170 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
172 { kEventClassControl
, kEventControlDraw
} ,
173 #if TARGET_API_MAC_OSX
174 { kEventClassControl
, kEventControlVisibilityChanged
} ,
175 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
176 { kEventClassControl
, kEventControlHiliteChanged
} ,
178 { kEventClassControl
, kEventControlSetFocusPart
} ,
180 { kEventClassService
, kEventServiceGetTypes
},
181 { kEventClassService
, kEventServiceCopy
},
182 { kEventClassService
, kEventServicePaste
},
184 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
185 // { kEventClassControl , kEventControlBoundsChanged } ,
188 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
190 OSStatus result
= eventNotHandledErr
;
192 wxMacCarbonEvent
cEvent( event
) ;
194 ControlRef controlRef
;
195 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
197 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
199 switch ( GetEventKind( event
) )
201 #if TARGET_API_MAC_OSX
202 case kEventControlDraw
:
204 RgnHandle updateRgn
= NULL
;
205 RgnHandle allocatedRgn
= NULL
;
206 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
209 if ( ! thisWindow
->GetPeer()->IsCompositing() )
211 if ( thisWindow
->GetPeer()->IsRootControl() )
212 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
214 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
217 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
219 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
223 if ( ! thisWindow
->GetPeer()->IsCompositing() )
225 allocatedRgn
= NewRgn() ;
226 CopyRgn( updateRgn
, allocatedRgn
) ;
227 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
229 // hide the given region by the new region that must be shifted
230 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
231 updateRgn
= allocatedRgn
;
235 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
237 // as this update region is in native window locals we must adapt it to wx window local
238 allocatedRgn
= NewRgn() ;
239 CopyRgn( updateRgn
, allocatedRgn
) ;
241 // hide the given region by the new region that must be shifted
242 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
243 updateRgn
= allocatedRgn
;
249 GetRegionBounds( updateRgn
, &rgnBounds
) ;
251 #if wxMAC_DEBUG_REDRAW
252 if ( thisWindow
->MacIsUserPane() )
254 static float color
= 0.5 ;
257 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
259 HIViewGetBounds( controlRef
, &bounds
);
260 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
261 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
262 CGContextFillRect( cgContext
, bounds
);
275 #if wxMAC_USE_CORE_GRAPHICS
276 bool created
= false ;
277 CGContextRef cgContext
= NULL
;
278 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
280 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
282 // this parameter is not provided on non-composited windows
285 // rest of the code expects this to be already transformed and clipped for local
286 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
288 GetPortBounds( port
, &bounds
) ;
289 CreateCGContextForPort( port
, &cgContext
) ;
291 wxMacWindowToNative( thisWindow
, updateRgn
) ;
292 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
293 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
294 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
295 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
297 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
298 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
300 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
303 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
304 CGContextFillRect( cgContext
,
306 controlBounds
.right
- controlBounds
.left
,
307 controlBounds
.bottom
- controlBounds
.top
) );
311 thisWindow
->MacSetCGContextRef( cgContext
) ;
314 wxMacCGContextStateSaver
sg( cgContext
) ;
316 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
319 #if wxMAC_USE_CORE_GRAPHICS
320 thisWindow
->MacSetCGContextRef( NULL
) ;
324 CGContextRelease( cgContext
) ;
329 DisposeRgn( allocatedRgn
) ;
333 case kEventControlVisibilityChanged
:
334 thisWindow
->MacVisibilityChanged() ;
337 case kEventControlEnabledStateChanged
:
338 thisWindow
->MacEnabledStateChanged() ;
341 case kEventControlHiliteChanged
:
342 thisWindow
->MacHiliteChanged() ;
346 // we emulate this event under Carbon CFM
347 case kEventControlSetFocusPart
:
349 Boolean focusEverything
= false ;
350 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
353 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
358 if ( controlPart
== kControlFocusNoPart
)
361 if ( thisWindow
->GetCaret() )
362 thisWindow
->GetCaret()->OnKillFocus();
365 static bool inKillFocusEvent
= false ;
367 if ( !inKillFocusEvent
)
369 inKillFocusEvent
= true ;
370 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
371 event
.SetEventObject(thisWindow
);
372 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
373 inKillFocusEvent
= false ;
378 // panel wants to track the window which was the last to have focus in it
379 wxChildFocusEvent
eventFocus(thisWindow
);
380 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
383 if ( thisWindow
->GetCaret() )
384 thisWindow
->GetCaret()->OnSetFocus();
387 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
388 event
.SetEventObject(thisWindow
);
389 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
392 if ( thisWindow
->MacIsUserPane() )
397 case kEventControlHit
:
398 result
= thisWindow
->MacControlHit( handler
, event
) ;
408 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
410 OSStatus result
= eventNotHandledErr
;
412 wxMacCarbonEvent
cEvent( event
) ;
414 ControlRef controlRef
;
415 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
416 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
417 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
419 switch ( GetEventKind( event
) )
421 case kEventServiceGetTypes
:
425 textCtrl
->GetSelection( &from
, &to
) ;
427 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
429 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
430 if ( textCtrl
->IsEditable() )
431 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
433 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
434 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
436 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
440 CFArrayAppendValue(copyTypes
, typestring
) ;
442 CFArrayAppendValue(pasteTypes
, typestring
) ;
444 CFRelease( typestring
) ;
452 case kEventServiceCopy
:
457 textCtrl
->GetSelection( &from
, &to
) ;
458 wxString val
= textCtrl
->GetValue() ;
459 val
= val
.Mid( from
, to
- from
) ;
460 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
461 verify_noerr( ClearScrap( &scrapRef
) ) ;
462 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
467 case kEventServicePaste
:
470 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
471 Size textSize
, pastedSize
;
472 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
474 char *content
= new char[textSize
] ;
475 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
476 content
[textSize
- 1] = 0 ;
479 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
481 textCtrl
->WriteText( wxString( content
) ) ;
496 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
498 OSStatus result
= eventNotHandledErr
;
499 wxWindowMac
* focus
= (wxWindowMac
*) data
;
501 wchar_t* uniChars
= NULL
;
502 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
504 UniChar
* charBuf
= NULL
;
505 UInt32 dataSize
= 0 ;
508 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
510 numChars
= dataSize
/ sizeof( UniChar
) + 1;
513 if ( (size_t) numChars
* 2 > sizeof(buf
) )
514 charBuf
= new UniChar
[ numChars
] ;
518 uniChars
= new wchar_t[ numChars
] ;
519 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
520 charBuf
[ numChars
- 1 ] = 0;
521 #if SIZEOF_WCHAR_T == 2
522 uniChars
= (wchar_t*) charBuf
;
523 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
525 // the resulting string will never have more chars than the utf16 version, so this is safe
526 wxMBConvUTF16 converter
;
527 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
531 switch ( GetEventKind( event
) )
533 case kEventTextInputUpdateActiveInputArea
:
535 // An IME input event may return several characters, but we need to send one char at a time to
537 for (int pos
=0 ; pos
< numChars
; pos
++)
539 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
540 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
541 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
543 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
544 if ( wxTheApp
->MacSendCharEvent(
545 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
550 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
554 case kEventTextInputUnicodeForKeyEvent
:
556 UInt32 keyCode
, modifiers
;
559 unsigned char charCode
;
561 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
562 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
563 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
564 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
565 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
567 UInt32 message
= (keyCode
<< 8) + charCode
;
569 // An IME input event may return several characters, but we need to send one char at a time to
571 for (int pos
=0 ; pos
< numChars
; pos
++)
573 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
574 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
575 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
577 if ( wxTheApp
->MacSendCharEvent(
578 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
583 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
592 if ( charBuf
!= buf
)
598 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
600 OSStatus result
= eventNotHandledErr
;
601 wxWindowMac
* focus
= (wxWindowMac
*) data
;
605 wxMacCarbonEvent
cEvent( event
) ;
606 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
608 wxMenuItem
* item
= NULL
;
609 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
610 int id
= wxMacCommandToId( command
.commandID
) ;
614 wxASSERT( itemMenu
!= NULL
) ;
616 switch ( cEvent
.GetKind() )
618 case kEventProcessCommand
:
620 if (item
->IsCheckable())
621 item
->Check( !item
->IsChecked() ) ;
623 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
627 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
628 event
.SetEventObject(focus
);
629 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
631 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
637 case kEventCommandUpdateStatus
:
639 wxUpdateUIEvent
event(id
);
640 event
.SetEventObject( itemMenu
);
642 bool processed
= false;
644 // Try the menu's event handler
646 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
648 processed
= handler
->ProcessEvent(event
);
651 // Try the window the menu was popped up from
652 // (and up through the hierarchy)
655 const wxMenuBase
*menu
= itemMenu
;
658 wxWindow
*win
= menu
->GetInvokingWindow();
661 processed
= win
->GetEventHandler()->ProcessEvent(event
);
665 menu
= menu
->GetParent();
671 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
676 // if anything changed, update the changed attribute
677 if (event
.GetSetText())
678 itemMenu
->SetLabel(id
, event
.GetText());
679 if (event
.GetSetChecked())
680 itemMenu
->Check(id
, event
.GetChecked());
681 if (event
.GetSetEnabled())
682 itemMenu
->Enable(id
, event
.GetEnabled());
696 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
698 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
699 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
700 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
701 OSStatus result
= eventNotHandledErr
;
703 switch ( GetEventClass( event
) )
705 case kEventClassCommand
:
706 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
709 case kEventClassControl
:
710 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
713 case kEventClassService
:
714 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
717 case kEventClassTextInput
:
718 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
725 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
730 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
732 #if !TARGET_API_MAC_OSX
734 // ---------------------------------------------------------------------------
735 // UserPane events for non OSX builds
736 // ---------------------------------------------------------------------------
738 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
740 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
742 win
->MacControlUserPaneDrawProc(part
) ;
744 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
746 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
748 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
750 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
752 return kControlNoPart
;
754 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
756 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
758 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
760 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
762 return kControlNoPart
;
764 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
766 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
768 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
770 win
->MacControlUserPaneIdleProc() ;
772 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
774 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
776 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
778 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
780 return kControlNoPart
;
782 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
784 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
786 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
788 win
->MacControlUserPaneActivateProc(activating
) ;
790 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
792 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
794 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
796 return win
->MacControlUserPaneFocusProc(action
) ;
798 return kControlNoPart
;
800 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
802 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
804 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
806 win
->MacControlUserPaneBackgroundProc(info
) ;
808 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
810 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
813 RgnHandle rgn
= NewRgn() ;
815 MacWindowToRootWindow( &x
, &y
) ;
816 OffsetRgn( rgn
, -x
, -y
) ;
817 wxMacWindowStateSaver
sv( this ) ;
818 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
819 MacDoRedraw( rgn
, 0 ) ;
823 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
825 return kControlNoPart
;
828 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
830 return kControlNoPart
;
833 void wxWindowMac::MacControlUserPaneIdleProc()
837 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
839 return kControlNoPart
;
842 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
846 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
848 if ( AcceptsFocus() )
851 return kControlNoPart
;
854 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
860 // ---------------------------------------------------------------------------
861 // Scrollbar Tracking for all
862 // ---------------------------------------------------------------------------
864 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
865 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
869 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
871 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
874 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
876 // ===========================================================================
878 // ===========================================================================
880 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
882 static MacControlMap wxWinMacControlList
;
884 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
886 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
888 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
891 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
893 // adding NULL ControlRef is (first) surely a result of an error and
894 // (secondly) breaks native event processing
895 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
897 wxWinMacControlList
[inControl
] = control
;
900 void wxRemoveMacControlAssociation(wxWindow
*control
)
902 // iterate over all the elements in the class
903 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
904 // we should go on...
910 MacControlMap::iterator it
;
911 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
913 if ( it
->second
== control
)
915 wxWinMacControlList
.erase(it
);
923 // ----------------------------------------------------------------------------
924 // constructors and such
925 // ----------------------------------------------------------------------------
927 wxWindowMac::wxWindowMac()
932 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
937 const wxString
& name
)
940 Create(parent
, id
, pos
, size
, style
, name
);
943 void wxWindowMac::Init()
948 #if WXWIN_COMPATIBILITY_2_4
949 m_backgroundTransparent
= false;
952 #if wxMAC_USE_CORE_GRAPHICS
953 m_cgContextRef
= NULL
;
956 // as all windows are created with WS_VISIBLE style...
959 m_hScrollBar
= NULL
;
960 m_vScrollBar
= NULL
;
961 m_macBackgroundBrush
= wxNullBrush
;
963 m_macIsUserPane
= true;
964 m_clipChildren
= false ;
965 m_cachedClippedRectValid
= false ;
967 // we need a valid font for the encodings
968 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
971 wxWindowMac::~wxWindowMac()
975 m_isBeingDeleted
= true;
977 MacInvalidateBorders() ;
979 #ifndef __WXUNIVERSAL__
980 // VS: make sure there's no wxFrame with last focus set to us:
981 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
983 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
986 if ( frame
->GetLastFocus() == this )
987 frame
->SetLastFocus((wxWindow
*)NULL
);
993 // destroy children before destroying this window itself
996 // wxRemoveMacControlAssociation( this ) ;
997 // If we delete an item, we should initialize the parent panel,
998 // because it could now be invalid.
999 wxWindow
*parent
= GetParent() ;
1002 if (parent
->GetDefaultItem() == (wxButton
*) this)
1003 parent
->SetDefaultItem(NULL
);
1006 if ( m_peer
&& m_peer
->Ok() )
1008 // in case the callback might be called during destruction
1009 wxRemoveMacControlAssociation( this) ;
1010 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1011 // we currently are not using this hook
1012 // ::SetControlColorProc( *m_peer , NULL ) ;
1016 if ( g_MacLastWindow
== this )
1017 g_MacLastWindow
= NULL
;
1019 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1022 if ( frame
->GetLastFocus() == this )
1023 frame
->SetLastFocus( NULL
) ;
1026 // delete our drop target if we've got one
1027 #if wxUSE_DRAG_AND_DROP
1028 if ( m_dropTarget
!= NULL
)
1030 delete m_dropTarget
;
1031 m_dropTarget
= NULL
;
1038 WXWidget
wxWindowMac::GetHandle() const
1040 return (WXWidget
) m_peer
->GetControlRef() ;
1043 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1045 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1046 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1047 GetEventTypeCount(eventList
), eventList
, this,
1048 (EventHandlerRef
*)&m_macControlEventHandler
);
1050 #if !TARGET_API_MAC_OSX
1051 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1053 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1054 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1055 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1056 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1057 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1058 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1059 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1060 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1066 bool wxWindowMac::Create(wxWindowMac
*parent
,
1071 const wxString
& name
)
1073 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1075 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1078 m_windowVariant
= parent
->GetWindowVariant() ;
1080 if ( m_macIsUserPane
)
1082 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1085 | kControlSupportsEmbedding
1086 | kControlSupportsLiveFeedback
1087 | kControlGetsFocusOnClick
1088 // | kControlHasSpecialBackground
1089 // | kControlSupportsCalcBestRect
1090 | kControlHandlesTracking
1091 | kControlSupportsFocus
1092 | kControlWantsActivate
1093 | kControlWantsIdle
;
1095 m_peer
= new wxMacControl(this) ;
1096 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1097 verify_noerr( err
);
1099 MacPostControlCreate(pos
, size
) ;
1102 #ifndef __WXUNIVERSAL__
1103 // Don't give scrollbars to wxControls unless they ask for them
1104 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1105 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1107 MacCreateScrollBars( style
) ;
1111 wxWindowCreateEvent
event(this);
1112 GetEventHandler()->AddPendingEvent(event
);
1117 void wxWindowMac::MacChildAdded()
1120 m_vScrollBar
->Raise() ;
1122 m_hScrollBar
->Raise() ;
1125 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1127 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1129 m_peer
->SetReference( (long)this ) ;
1130 GetParent()->AddChild( this );
1132 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1134 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1135 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1136 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1137 GetParent()->MacChildAdded() ;
1139 // adjust font, controlsize etc
1140 DoSetWindowVariant( m_windowVariant
) ;
1142 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
1144 if (!m_macIsUserPane
)
1145 SetInitialBestSize(size
);
1147 SetCursor( *wxSTANDARD_CURSOR
) ;
1150 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1152 // Don't assert, in case we set the window variant before
1153 // the window is created
1154 // wxASSERT( m_peer->Ok() ) ;
1156 m_windowVariant
= variant
;
1158 if (m_peer
== NULL
|| !m_peer
->Ok())
1162 ThemeFontID themeFont
= kThemeSystemFont
;
1164 // we will get that from the settings later
1165 // and make this NORMAL later, but first
1166 // we have a few calculations that we must fix
1170 case wxWINDOW_VARIANT_NORMAL
:
1171 size
= kControlSizeNormal
;
1172 themeFont
= kThemeSystemFont
;
1175 case wxWINDOW_VARIANT_SMALL
:
1176 size
= kControlSizeSmall
;
1177 themeFont
= kThemeSmallSystemFont
;
1180 case wxWINDOW_VARIANT_MINI
:
1181 if (UMAGetSystemVersion() >= 0x1030 )
1183 // not always defined in the headers
1189 size
= kControlSizeSmall
;
1190 themeFont
= kThemeSmallSystemFont
;
1194 case wxWINDOW_VARIANT_LARGE
:
1195 size
= kControlSizeLarge
;
1196 themeFont
= kThemeSystemFont
;
1200 wxFAIL_MSG(_T("unexpected window variant"));
1204 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1207 font
.MacCreateThemeFont( themeFont
) ;
1211 void wxWindowMac::MacUpdateControlFont()
1213 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1217 bool wxWindowMac::SetFont(const wxFont
& font
)
1219 bool retval
= wxWindowBase::SetFont( font
);
1221 MacUpdateControlFont() ;
1226 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1228 bool retval
= wxWindowBase::SetForegroundColour( col
);
1231 MacUpdateControlFont();
1236 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1238 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1242 wxColour
newCol(GetBackgroundColour());
1244 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1245 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1246 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1247 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1249 brush
.SetColour( newCol
) ;
1251 MacSetBackgroundBrush( brush
) ;
1252 MacUpdateControlFont() ;
1257 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1259 m_macBackgroundBrush
= brush
;
1260 m_peer
->SetBackground( brush
) ;
1263 bool wxWindowMac::MacCanFocus() const
1265 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1266 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1267 // but the value range is nowhere documented
1268 Boolean keyExistsAndHasValidFormat
;
1269 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1270 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1272 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1278 UInt32 features
= 0 ;
1279 m_peer
->GetFeatures( &features
) ;
1281 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1285 void wxWindowMac::SetFocus()
1287 if ( !AcceptsFocus() )
1290 wxWindow
* former
= FindFocus() ;
1291 if ( former
== this )
1294 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1295 // we can only leave in case of an error
1296 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1297 if ( err
== errCouldntSetFocus
)
1300 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1302 #if !TARGET_API_MAC_OSX
1303 // emulate carbon events when running under CarbonLib where they are not natively available
1306 EventRef evRef
= NULL
;
1308 err
= MacCreateEvent(
1309 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1310 kEventAttributeUserEvent
, &evRef
);
1311 verify_noerr( err
);
1313 wxMacCarbonEvent
cEvent( evRef
) ;
1314 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1315 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1317 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1318 ReleaseEvent( evRef
) ;
1321 // send new focus event
1323 EventRef evRef
= NULL
;
1325 err
= MacCreateEvent(
1326 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1327 kEventAttributeUserEvent
, &evRef
);
1328 verify_noerr( err
);
1330 wxMacCarbonEvent
cEvent( evRef
) ;
1331 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1332 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1334 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1335 ReleaseEvent( evRef
) ;
1340 void wxWindowMac::DoCaptureMouse()
1342 wxApp::s_captureWindow
= this ;
1345 wxWindow
* wxWindowBase::GetCapture()
1347 return wxApp::s_captureWindow
;
1350 void wxWindowMac::DoReleaseMouse()
1352 wxApp::s_captureWindow
= NULL
;
1355 #if wxUSE_DRAG_AND_DROP
1357 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1359 if ( m_dropTarget
!= NULL
)
1360 delete m_dropTarget
;
1362 m_dropTarget
= pDropTarget
;
1363 if ( m_dropTarget
!= NULL
)
1371 // Old-style File Manager Drag & Drop
1372 void wxWindowMac::DragAcceptFiles(bool accept
)
1377 // Returns the size of the native control. In the case of the toplevel window
1378 // this is the content area root control
1380 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1381 int& w
, int& h
) const
1383 wxFAIL_MSG( wxT("Not currently supported") ) ;
1386 // From a wx position / size calculate the appropriate size of the native control
1388 bool wxWindowMac::MacGetBoundsForControl(
1392 int& w
, int& h
, bool adjustOrigin
) const
1394 // the desired size, minus the border pixels gives the correct size of the control
1398 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1399 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1400 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1402 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1403 if ( !isCompositing
)
1404 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1406 x
+= MacGetLeftBorderSize() ;
1407 y
+= MacGetTopBorderSize() ;
1408 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1409 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1412 AdjustForParentClientOrigin( x
, y
) ;
1414 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1415 if ( !GetParent()->IsTopLevel() )
1417 x
-= GetParent()->MacGetLeftBorderSize() ;
1418 y
-= GetParent()->MacGetTopBorderSize() ;
1424 // Get window size (not client size)
1425 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1428 m_peer
->GetRect( &bounds
) ;
1431 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1433 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1436 // get the position of the bounds of this window in client coordinates of its parent
1437 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1440 m_peer
->GetRect( &bounds
) ;
1442 int x1
= bounds
.left
;
1443 int y1
= bounds
.top
;
1445 // get the wx window position from the native one
1446 x1
-= MacGetLeftBorderSize() ;
1447 y1
-= MacGetTopBorderSize() ;
1449 if ( !IsTopLevel() )
1451 wxWindow
*parent
= GetParent();
1454 // we must first adjust it to be in window coordinates of the parent,
1455 // as otherwise it gets lost by the ClientAreaOrigin fix
1456 x1
+= parent
->MacGetLeftBorderSize() ;
1457 y1
+= parent
->MacGetTopBorderSize() ;
1459 // and now to client coordinates
1460 wxPoint
pt(parent
->GetClientAreaOrigin());
1472 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1474 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1475 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1477 Point localwhere
= { 0, 0 } ;
1484 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1491 MacRootWindowToWindow( x
, y
) ;
1493 wxPoint origin
= GetClientAreaOrigin() ;
1500 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1502 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1503 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1505 wxPoint origin
= GetClientAreaOrigin() ;
1511 MacWindowToRootWindow( x
, y
) ;
1513 Point localwhere
= { 0, 0 };
1519 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1527 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1529 wxPoint origin
= GetClientAreaOrigin() ;
1535 MacWindowToRootWindow( x
, y
) ;
1538 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1540 MacRootWindowToWindow( x
, y
) ;
1542 wxPoint origin
= GetClientAreaOrigin() ;
1549 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1558 if ( !IsTopLevel() )
1560 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1563 pt
.x
-= MacGetLeftBorderSize() ;
1564 pt
.y
-= MacGetTopBorderSize() ;
1565 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1575 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1584 MacWindowToRootWindow( &x1
, &y1
) ;
1592 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1601 if ( !IsTopLevel() )
1603 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1606 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1607 pt
.x
+= MacGetLeftBorderSize() ;
1608 pt
.y
+= MacGetTopBorderSize() ;
1618 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1627 MacRootWindowToWindow( &x1
, &y1
) ;
1635 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1637 RgnHandle rgn
= NewRgn() ;
1639 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1641 Rect structure
, content
;
1643 GetRegionBounds( rgn
, &content
) ;
1644 m_peer
->GetRect( &structure
) ;
1645 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1647 left
= content
.left
- structure
.left
;
1648 top
= content
.top
- structure
.top
;
1649 right
= structure
.right
- content
.right
;
1650 bottom
= structure
.bottom
- content
.bottom
;
1654 left
= top
= right
= bottom
= 0 ;
1660 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1662 wxSize sizeTotal
= size
;
1664 RgnHandle rgn
= NewRgn() ;
1665 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1667 Rect content
, structure
;
1668 GetRegionBounds( rgn
, &content
) ;
1669 m_peer
->GetRect( &structure
) ;
1671 // structure is in parent coordinates, but we only need width and height, so it's ok
1673 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1674 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1679 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1680 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1685 // Get size *available for subwindows* i.e. excluding menu bar etc.
1686 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1690 RgnHandle rgn
= NewRgn() ;
1692 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1693 GetRegionBounds( rgn
, &content
) ;
1695 m_peer
->GetRect( &content
) ;
1698 ww
= content
.right
- content
.left
;
1699 hh
= content
.bottom
- content
.top
;
1701 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1702 hh
-= m_hScrollBar
->GetSize().y
;
1704 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1705 ww
-= m_vScrollBar
->GetSize().x
;
1713 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1715 if (m_cursor
== cursor
)
1718 if (wxNullCursor
== cursor
)
1720 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1725 if ( ! wxWindowBase::SetCursor( cursor
) )
1729 wxASSERT_MSG( m_cursor
.Ok(),
1730 wxT("cursor must be valid after call to the base version"));
1732 wxWindowMac
*mouseWin
= 0 ;
1734 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1735 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1737 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1739 // TODO: If we ever get a GetCurrentEvent... replacement
1740 // for the mouse position, use it...
1743 ControlPartCode part
;
1744 ControlRef control
;
1747 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1749 mouseWin
= wxFindControlFromMacControl( control
) ;
1752 QDSwapPort( savePort
, NULL
) ;
1755 if ( mouseWin
== this && !wxIsBusy() )
1756 m_cursor
.MacInstall() ;
1762 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1764 menu
->SetInvokingWindow(this);
1767 if ( x
== -1 && y
== -1 )
1769 wxPoint mouse
= wxGetMousePosition();
1775 ClientToScreen( &x
, &y
) ;
1778 menu
->MacBeforeDisplay( true ) ;
1779 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1780 if ( HiWord(menuResult
) != 0 )
1783 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1784 int id
= wxMacCommandToId( macid
);
1785 wxMenuItem
* item
= NULL
;
1787 item
= menu
->FindItem( id
, &realmenu
) ;
1790 if (item
->IsCheckable())
1791 item
->Check( !item
->IsChecked() ) ;
1793 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1797 menu
->MacAfterDisplay( true ) ;
1798 menu
->SetInvokingWindow( NULL
);
1804 // ----------------------------------------------------------------------------
1806 // ----------------------------------------------------------------------------
1810 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1812 wxWindowBase::DoSetToolTip(tooltip
);
1815 m_tooltip
->SetWindow(this);
1820 void wxWindowMac::MacInvalidateBorders()
1822 if ( m_peer
== NULL
)
1825 bool vis
= MacIsReallyShown() ;
1829 int outerBorder
= MacGetLeftBorderSize() ;
1830 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1833 if ( outerBorder
== 0 )
1836 // now we know that we have something to do at all
1838 // as the borders are drawn on the parent we have to properly invalidate all these areas
1839 RgnHandle updateInner
, updateOuter
;
1842 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1843 updateInner
= NewRgn() ;
1844 updateOuter
= NewRgn() ;
1846 m_peer
->GetRect( &rect
) ;
1847 RectRgn( updateInner
, &rect
) ;
1848 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1849 RectRgn( updateOuter
, &rect
) ;
1850 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1852 #ifdef __WXMAC_OSX__
1853 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1855 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1857 InvalWindowRgn( tlw
, updateOuter
) ;
1860 DisposeRgn( updateOuter
) ;
1861 DisposeRgn( updateInner
) ;
1864 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1866 // this is never called for a toplevel window, so we know we have a parent
1867 int former_x
, former_y
, former_w
, former_h
;
1869 // Get true coordinates of former position
1870 DoGetPosition( &former_x
, &former_y
) ;
1871 DoGetSize( &former_w
, &former_h
) ;
1873 wxWindow
*parent
= GetParent();
1876 wxPoint
pt(parent
->GetClientAreaOrigin());
1881 int actualWidth
= width
;
1882 int actualHeight
= height
;
1886 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1887 actualWidth
= m_minWidth
;
1888 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1889 actualHeight
= m_minHeight
;
1890 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1891 actualWidth
= m_maxWidth
;
1892 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1893 actualHeight
= m_maxHeight
;
1895 bool doMove
= false, doResize
= false ;
1897 if ( actualX
!= former_x
|| actualY
!= former_y
)
1900 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1903 if ( doMove
|| doResize
)
1905 // as the borders are drawn outside the native control, we adjust now
1907 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1908 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1909 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1912 wxMacRectToNative( &bounds
, &r
) ;
1914 if ( !GetParent()->IsTopLevel() )
1915 wxMacWindowToNative( GetParent() , &r
) ;
1917 MacInvalidateBorders() ;
1919 m_cachedClippedRectValid
= false ;
1920 m_peer
->SetRect( &r
) ;
1922 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1924 MacInvalidateBorders() ;
1926 MacRepositionScrollBars() ;
1929 wxPoint
point(actualX
, actualY
);
1930 wxMoveEvent
event(point
, m_windowId
);
1931 event
.SetEventObject(this);
1932 GetEventHandler()->ProcessEvent(event
) ;
1937 MacRepositionScrollBars() ;
1938 wxSize
size(actualWidth
, actualHeight
);
1939 wxSizeEvent
event(size
, m_windowId
);
1940 event
.SetEventObject(this);
1941 GetEventHandler()->ProcessEvent(event
);
1946 wxSize
wxWindowMac::DoGetBestSize() const
1948 if ( m_macIsUserPane
|| IsTopLevel() )
1949 return wxWindowBase::DoGetBestSize() ;
1951 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1952 int bestWidth
, bestHeight
;
1954 m_peer
->GetBestRect( &bestsize
) ;
1955 if ( EmptyRect( &bestsize
) )
1960 bestsize
.bottom
= 16 ;
1962 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1964 bestsize
.bottom
= 16 ;
1967 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1969 bestsize
.bottom
= 24 ;
1974 // return wxWindowBase::DoGetBestSize() ;
1978 bestWidth
= bestsize
.right
- bestsize
.left
;
1979 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1980 if ( bestHeight
< 10 )
1983 return wxSize(bestWidth
, bestHeight
);
1986 // set the size of the window: if the dimensions are positive, just use them,
1987 // but if any of them is equal to -1, it means that we must find the value for
1988 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1989 // which case -1 is a valid value for x and y)
1991 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1992 // the width/height to best suit our contents, otherwise we reuse the current
1994 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1996 // get the current size and position...
1997 int currentX
, currentY
;
1998 int currentW
, currentH
;
2000 GetPosition(¤tX
, ¤tY
);
2001 GetSize(¤tW
, ¤tH
);
2003 // ... and don't do anything (avoiding flicker) if it's already ok
2004 if ( x
== currentX
&& y
== currentY
&&
2005 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2008 MacRepositionScrollBars() ; // we might have a real position shift
2013 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2015 if ( x
== wxDefaultCoord
)
2017 if ( y
== wxDefaultCoord
)
2021 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2023 wxSize size
= wxDefaultSize
;
2024 if ( width
== wxDefaultCoord
)
2026 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2028 size
= DoGetBestSize();
2033 // just take the current one
2038 if ( height
== wxDefaultCoord
)
2040 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2042 if ( size
.x
== wxDefaultCoord
)
2043 size
= DoGetBestSize();
2044 // else: already called DoGetBestSize() above
2050 // just take the current one
2055 DoMoveWindow( x
, y
, width
, height
);
2058 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2060 RgnHandle rgn
= NewRgn() ;
2062 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2064 GetRegionBounds( rgn
, &content
) ;
2074 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2077 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2079 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2081 int currentclientwidth
, currentclientheight
;
2082 int currentwidth
, currentheight
;
2084 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2085 GetSize( ¤twidth
, ¤theight
) ;
2087 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2088 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2092 void wxWindowMac::SetLabel(const wxString
& title
)
2094 m_label
= wxStripMenuCodes(title
) ;
2096 if ( m_peer
&& m_peer
->Ok() )
2097 m_peer
->SetLabel( m_label
) ;
2102 wxString
wxWindowMac::GetLabel() const
2107 bool wxWindowMac::Show(bool show
)
2109 bool former
= MacIsReallyShown() ;
2110 if ( !wxWindowBase::Show(show
) )
2113 // TODO: use visibilityChanged Carbon Event for OSX
2115 m_peer
->SetVisibility( show
, true ) ;
2117 if ( former
!= MacIsReallyShown() )
2118 MacPropagateVisibilityChanged() ;
2123 bool wxWindowMac::Enable(bool enable
)
2125 wxASSERT( m_peer
->Ok() ) ;
2126 bool former
= MacIsReallyEnabled() ;
2127 if ( !wxWindowBase::Enable(enable
) )
2130 m_peer
->Enable( enable
) ;
2132 if ( former
!= MacIsReallyEnabled() )
2133 MacPropagateEnabledStateChanged() ;
2139 // status change propagations (will be not necessary for OSX later )
2142 void wxWindowMac::MacPropagateVisibilityChanged()
2144 #if !TARGET_API_MAC_OSX
2145 MacVisibilityChanged() ;
2148 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2151 child
= node
->GetData();
2152 if ( child
->IsShown() )
2153 child
->MacPropagateVisibilityChanged() ;
2155 node
= node
->GetNext();
2160 void wxWindowMac::MacPropagateEnabledStateChanged()
2162 #if !TARGET_API_MAC_OSX
2163 MacEnabledStateChanged() ;
2166 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2169 child
= node
->GetData();
2170 if ( child
->IsEnabled() )
2171 child
->MacPropagateEnabledStateChanged() ;
2173 node
= node
->GetNext();
2178 void wxWindowMac::MacPropagateHiliteChanged()
2180 #if !TARGET_API_MAC_OSX
2181 MacHiliteChanged() ;
2184 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2187 child
= node
->GetData();
2188 if (child
/* && child->IsEnabled() */)
2189 child
->MacPropagateHiliteChanged() ;
2191 node
= node
->GetNext();
2197 // status change notifications
2200 void wxWindowMac::MacVisibilityChanged()
2204 void wxWindowMac::MacHiliteChanged()
2208 void wxWindowMac::MacEnabledStateChanged()
2213 // status queries on the inherited window's state
2216 bool wxWindowMac::MacIsReallyShown()
2218 // only under OSX the visibility of the TLW is taken into account
2219 if ( m_isBeingDeleted
)
2222 #if TARGET_API_MAC_OSX
2223 if ( m_peer
&& m_peer
->Ok() )
2224 return m_peer
->IsVisible();
2227 wxWindow
* win
= this ;
2228 while ( win
->IsShown() )
2230 if ( win
->IsTopLevel() )
2233 win
= win
->GetParent() ;
2241 bool wxWindowMac::MacIsReallyEnabled()
2243 return m_peer
->IsEnabled() ;
2246 bool wxWindowMac::MacIsReallyHilited()
2248 return m_peer
->IsActive();
2251 void wxWindowMac::MacFlashInvalidAreas()
2253 #if TARGET_API_MAC_OSX
2254 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2258 int wxWindowMac::GetCharHeight() const
2260 wxClientDC
dc( (wxWindowMac
*)this ) ;
2262 return dc
.GetCharHeight() ;
2265 int wxWindowMac::GetCharWidth() const
2267 wxClientDC
dc( (wxWindowMac
*)this ) ;
2269 return dc
.GetCharWidth() ;
2272 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2273 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2275 const wxFont
*fontToUse
= theFont
;
2277 fontToUse
= &m_font
;
2279 wxClientDC
dc( (wxWindowMac
*) this ) ;
2281 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2282 if ( externalLeading
)
2283 *externalLeading
= le
;
2293 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2294 * we always intersect with the entire window, not only with the client area
2297 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2299 if ( m_peer
== NULL
)
2302 if ( !MacIsReallyShown() )
2309 wxMacRectToNative( rect
, &r
) ;
2310 m_peer
->SetNeedsDisplay( &r
) ;
2314 m_peer
->SetNeedsDisplay() ;
2318 void wxWindowMac::Freeze()
2320 #if TARGET_API_MAC_OSX
2321 if ( !m_frozenness
++ )
2323 if ( m_peer
&& m_peer
->Ok() )
2324 m_peer
->SetDrawingEnabled( false ) ;
2329 void wxWindowMac::Thaw()
2331 #if TARGET_API_MAC_OSX
2332 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2334 if ( !--m_frozenness
)
2336 if ( m_peer
&& m_peer
->Ok() )
2338 m_peer
->SetDrawingEnabled( true ) ;
2339 m_peer
->InvalidateWithChildren() ;
2345 wxWindowMac
*wxGetActiveWindow()
2347 // actually this is a windows-only concept
2351 // Coordinates relative to the window
2352 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2354 // We really don't move the mouse programmatically under Mac.
2357 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2359 if ( MacGetTopLevelWindow() == NULL
)
2362 #if TARGET_API_MAC_OSX
2363 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2370 event
.GetDC()->Clear() ;
2374 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2379 int wxWindowMac::GetScrollPos(int orient
) const
2381 if ( orient
== wxHORIZONTAL
)
2384 return m_hScrollBar
->GetThumbPosition() ;
2389 return m_vScrollBar
->GetThumbPosition() ;
2395 // This now returns the whole range, not just the number
2396 // of positions that we can scroll.
2397 int wxWindowMac::GetScrollRange(int orient
) const
2399 if ( orient
== wxHORIZONTAL
)
2402 return m_hScrollBar
->GetRange() ;
2407 return m_vScrollBar
->GetRange() ;
2413 int wxWindowMac::GetScrollThumb(int orient
) const
2415 if ( orient
== wxHORIZONTAL
)
2418 return m_hScrollBar
->GetThumbSize() ;
2423 return m_vScrollBar
->GetThumbSize() ;
2429 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2431 if ( orient
== wxHORIZONTAL
)
2434 m_hScrollBar
->SetThumbPosition( pos
) ;
2439 m_vScrollBar
->SetThumbPosition( pos
) ;
2444 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2445 // our own window origin is at leftOrigin/rightOrigin
2448 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2454 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2455 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2457 // back to the surrounding frame rectangle
2458 m_peer
->GetRect( &rect
) ;
2459 InsetRect( &rect
, -1 , -1 ) ;
2461 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2462 if ( UMAGetSystemVersion() >= 0x1030 )
2464 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2465 rect
.bottom
- rect
.top
) ;
2467 HIThemeFrameDrawInfo info
;
2468 memset( &info
, 0 , sizeof(info
) ) ;
2472 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2473 info
.isFocused
= hasFocus
;
2475 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2476 wxASSERT( cgContext
) ;
2478 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2480 info
.kind
= kHIThemeFrameTextFieldSquare
;
2481 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2483 else if ( HasFlag(wxSIMPLE_BORDER
) )
2485 info
.kind
= kHIThemeFrameListBox
;
2486 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2488 else if ( hasFocus
)
2490 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2493 m_peer
->GetRect( &rect
) ;
2494 if ( hasBothScrollbars
)
2496 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2497 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2498 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2499 HIThemeGrowBoxDrawInfo info
;
2500 memset( &info
, 0, sizeof(info
) ) ;
2502 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2503 info
.kind
= kHIThemeGrowBoxKindNone
;
2504 info
.size
= kHIThemeGrowBoxSizeNormal
;
2505 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2506 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2512 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2516 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2517 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2520 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2521 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2522 else if ( HasFlag(wxSIMPLE_BORDER
) )
2523 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2526 DrawThemeFocusRect( &rect
, true ) ;
2528 if ( hasBothScrollbars
)
2530 // GetThemeStandaloneGrowBoxBounds
2531 // DrawThemeStandaloneNoGrowBox
2536 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2538 if ( child
== m_hScrollBar
)
2539 m_hScrollBar
= NULL
;
2540 if ( child
== m_vScrollBar
)
2541 m_vScrollBar
= NULL
;
2543 wxWindowBase::RemoveChild( child
) ;
2546 // New function that will replace some of the above.
2547 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2548 int range
, bool refresh
)
2552 if ( orient
== wxHORIZONTAL
)
2556 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2557 if ( m_hScrollBar
->IsShown() != showScroller
)
2558 m_hScrollBar
->Show( showScroller
) ;
2560 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2567 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2568 if ( m_vScrollBar
->IsShown() != showScroller
)
2569 m_vScrollBar
->Show( showScroller
) ;
2571 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2575 MacRepositionScrollBars() ;
2578 // Does a physical scroll
2579 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2581 if ( dx
== 0 && dy
== 0 )
2584 int width
, height
;
2585 GetClientSize( &width
, &height
) ;
2587 #if TARGET_API_MAC_OSX
2588 if ( true /* m_peer->IsCompositing() */ )
2590 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2591 // area is scrolled, this does not occur if width and height are 2 pixels less,
2592 // TODO: write optimal workaround
2593 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2595 scrollrect
.Intersect( *rect
) ;
2597 if ( m_peer
->GetNeedsDisplay() )
2599 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2600 // either immediate redraw or full invalidate
2602 // is the better overall solution, as it does not slow down scrolling
2603 m_peer
->SetNeedsDisplay() ;
2605 // this would be the preferred version for fast drawing controls
2607 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2608 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2609 HIViewRender(m_peer
->GetControlRef()) ;
2616 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2617 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2618 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2620 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2621 // either immediate redraw or full invalidate
2623 // is the better overall solution, as it does not slow down scrolling
2624 m_peer
->SetNeedsDisplay() ;
2626 // this would be the preferred version for fast drawing controls
2628 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2629 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2630 HIViewRender(m_peer
->GetControlRef()) ;
2644 RgnHandle updateRgn
= NewRgn() ;
2647 wxClientDC
dc(this) ;
2648 wxMacPortSetter
helper(&dc
) ;
2650 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2651 //scrollrect.top += MacGetTopBorderSize() ;
2652 //scrollrect.left += MacGetLeftBorderSize() ;
2653 scrollrect
.bottom
= scrollrect
.top
+ height
;
2654 scrollrect
.right
= scrollrect
.left
+ width
;
2658 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2659 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2660 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2663 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2665 // now scroll the former update region as well and add the new update region
2666 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2667 RgnHandle formerUpdateRgn
= NewRgn() ;
2668 RgnHandle scrollRgn
= NewRgn() ;
2669 RectRgn( scrollRgn
, &scrollrect
) ;
2670 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2672 LocalToGlobal( &pt
) ;
2673 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2674 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2676 if ( !EmptyRgn( formerUpdateRgn
) )
2678 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2679 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2680 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2683 InvalWindowRgn(rootWindow
, updateRgn
) ;
2684 DisposeRgn( updateRgn
) ;
2685 DisposeRgn( formerUpdateRgn
) ;
2686 DisposeRgn( scrollRgn
) ;
2694 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2696 child
= node
->GetData();
2699 if (child
== m_vScrollBar
)
2701 if (child
== m_hScrollBar
)
2703 if (child
->IsTopLevel())
2706 child
->GetPosition( &x
, &y
);
2707 child
->GetSize( &w
, &h
);
2710 wxRect
rc( x
, y
, w
, h
);
2711 if (rect
->Intersects( rc
))
2712 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2716 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2721 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2723 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2725 wxScrollWinEvent wevent
;
2726 wevent
.SetPosition(event
.GetPosition());
2727 wevent
.SetOrientation(event
.GetOrientation());
2728 wevent
.SetEventObject(this);
2730 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2731 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2732 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2733 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2734 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2735 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2736 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2737 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2738 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2739 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2740 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2741 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2742 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2743 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2744 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2745 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2747 GetEventHandler()->ProcessEvent(wevent
);
2751 // Get the window with the focus
2752 wxWindowMac
*wxWindowBase::DoFindFocus()
2754 ControlRef control
;
2755 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2756 return wxFindControlFromMacControl( control
) ;
2759 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2761 // panel wants to track the window which was the last to have focus in it,
2762 // so we want to set ourselves as the window which last had focus
2764 // notice that it's also important to do it upwards the tree because
2765 // otherwise when the top level panel gets focus, it won't set it back to
2766 // us, but to some other sibling
2768 // CS: don't know if this is still needed:
2769 //wxChildFocusEvent eventFocus(this);
2770 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2772 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2774 #if wxMAC_USE_CORE_GRAPHICS
2775 GetParent()->Refresh() ;
2777 wxMacWindowStateSaver
sv( this ) ;
2780 m_peer
->GetRect( &rect
) ;
2781 // auf den umgebenden Rahmen zur\9fck
2782 InsetRect( &rect
, -1 , -1 ) ;
2784 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2788 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2790 rect
.right
+= pt
.x
;
2792 rect
.bottom
+= pt
.y
;
2795 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2796 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2797 if ( !bIsFocusEvent
)
2799 // as this erases part of the frame we have to redraw borders
2800 // and because our z-ordering is not always correct (staticboxes)
2801 // we have to invalidate things, we cannot simple redraw
2802 MacInvalidateBorders() ;
2810 void wxWindowMac::OnInternalIdle()
2812 // This calls the UI-update mechanism (querying windows for
2813 // menu/toolbar/control state information)
2814 if (wxUpdateUIEvent::CanUpdate(this))
2815 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2818 // Raise the window to the top of the Z order
2819 void wxWindowMac::Raise()
2821 m_peer
->SetZOrder( true , NULL
) ;
2824 // Lower the window to the bottom of the Z order
2825 void wxWindowMac::Lower()
2827 m_peer
->SetZOrder( false , NULL
) ;
2830 // static wxWindow *gs_lastWhich = NULL;
2832 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2834 // first trigger a set cursor event
2836 wxPoint clientorigin
= GetClientAreaOrigin() ;
2837 wxSize clientsize
= GetClientSize() ;
2839 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2841 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2843 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2844 if ( processedEvtSetCursor
&& event
.HasCursor() )
2846 cursor
= event
.GetCursor() ;
2850 // the test for processedEvtSetCursor is here to prevent using m_cursor
2851 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2852 // it - this is a way to say that our cursor shouldn't be used for this
2854 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2857 if ( !wxIsBusy() && !GetParent() )
2858 cursor
= *wxSTANDARD_CURSOR
;
2862 cursor
.MacInstall() ;
2865 return cursor
.Ok() ;
2868 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2872 return m_tooltip
->GetTip() ;
2875 return wxEmptyString
;
2878 void wxWindowMac::ClearBackground()
2884 void wxWindowMac::Update()
2886 #if TARGET_API_MAC_OSX
2887 MacGetTopLevelWindow()->MacPerformUpdates() ;
2889 ::Draw1Control( m_peer
->GetControlRef() ) ;
2893 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2895 wxTopLevelWindowMac
* win
= NULL
;
2896 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2898 win
= wxFindWinFromMacWindow( window
) ;
2903 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2905 MacUpdateClippedRects() ;
2907 return m_cachedClippedClientRect
;
2910 const wxRect
& wxWindowMac::MacGetClippedRect() const
2912 MacUpdateClippedRects() ;
2914 return m_cachedClippedRect
;
2917 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2919 MacUpdateClippedRects() ;
2921 return m_cachedClippedRectWithOuterStructure
;
2924 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2926 static wxRegion emptyrgn
;
2928 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2930 MacUpdateClippedRects() ;
2931 if ( includeOuterStructures
)
2932 return m_cachedClippedRegionWithOuterStructure
;
2934 return m_cachedClippedRegion
;
2942 void wxWindowMac::MacUpdateClippedRects() const
2944 if ( m_cachedClippedRectValid
)
2947 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2948 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2949 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2950 // to add focus borders everywhere
2952 Rect r
, rIncludingOuterStructures
;
2954 m_peer
->GetRect( &r
) ;
2955 r
.left
-= MacGetLeftBorderSize() ;
2956 r
.top
-= MacGetTopBorderSize() ;
2957 r
.bottom
+= MacGetBottomBorderSize() ;
2958 r
.right
+= MacGetRightBorderSize() ;
2965 rIncludingOuterStructures
= r
;
2966 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2968 wxRect cl
= GetClientRect() ;
2969 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2973 const wxWindow
* child
= this ;
2974 const wxWindow
* parent
= NULL
;
2976 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2978 if ( parent
->MacIsChildOfClientArea(child
) )
2980 size
= parent
->GetClientSize() ;
2981 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2987 // this will be true for scrollbars, toolbars etc.
2988 size
= parent
->GetSize() ;
2989 y
= parent
->MacGetTopBorderSize() ;
2990 x
= parent
->MacGetLeftBorderSize() ;
2991 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2992 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2995 parent
->MacWindowToRootWindow( &x
, &y
) ;
2996 MacRootWindowToWindow( &x
, &y
) ;
2998 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
3000 // the wxwindow and client rects will always be clipped
3001 SectRect( &r
, &rparent
, &r
) ;
3002 SectRect( &rClient
, &rparent
, &rClient
) ;
3004 // the structure only at 'hard' borders
3005 if ( parent
->MacClipChildren() ||
3006 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
3008 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
3014 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
3015 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
3016 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
3017 m_cachedClippedRectWithOuterStructure
= wxRect(
3018 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
3019 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
3020 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
3022 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
3023 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
3024 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
3026 m_cachedClippedRectValid
= true ;
3030 This function must not change the updatergn !
3032 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3034 bool handled
= false ;
3036 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3037 GetRegionBounds( updatergn
, &updatebounds
) ;
3039 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3041 if ( !EmptyRgn(updatergn
) )
3043 RgnHandle newupdate
= NewRgn() ;
3044 wxSize point
= GetClientSize() ;
3045 wxPoint origin
= GetClientAreaOrigin() ;
3046 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3047 SectRgn( newupdate
, updatergn
, newupdate
) ;
3049 // first send an erase event to the entire update area
3051 // for the toplevel window this really is the entire area
3052 // for all the others only their client area, otherwise they
3053 // might be drawing with full alpha and eg put blue into
3054 // the grow-box area of a scrolled window (scroll sample)
3055 wxDC
* dc
= new wxWindowDC(this);
3057 dc
->SetClippingRegion(wxRegion(updatergn
));
3059 dc
->SetClippingRegion(wxRegion(newupdate
));
3061 wxEraseEvent
eevent( GetId(), dc
);
3062 eevent
.SetEventObject( this );
3063 GetEventHandler()->ProcessEvent( eevent
);
3067 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3068 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3069 m_updateRegion
= newupdate
;
3070 DisposeRgn( newupdate
) ;
3072 if ( !m_updateRegion
.Empty() )
3074 // paint the window itself
3077 event
.SetTimestamp(time
);
3078 event
.SetEventObject(this);
3079 GetEventHandler()->ProcessEvent(event
);
3083 // now we cannot rely on having its borders drawn by a window itself, as it does not
3084 // get the updateRgn wide enough to always do so, so we do it from the parent
3085 // this would also be the place to draw any custom backgrounds for native controls
3086 // in Composited windowing
3087 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3091 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3093 child
= node
->GetData();
3096 if (child
== m_vScrollBar
)
3098 if (child
== m_hScrollBar
)
3100 if (child
->IsTopLevel())
3102 if (!child
->IsShown())
3105 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3107 child
->GetPosition( &x
, &y
);
3108 child
->GetSize( &w
, &h
);
3109 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3110 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3111 InsetRect( &childRect
, -10 , -10) ;
3113 if ( RectInRgn( &childRect
, updatergn
) )
3115 // paint custom borders
3116 wxNcPaintEvent
eventNc( child
->GetId() );
3117 eventNc
.SetEventObject( child
);
3118 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3120 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3121 if ( UMAGetSystemVersion() >= 0x1030 )
3123 child
->MacPaintBorders(0, 0) ;
3128 wxWindowDC
dc(this) ;
3129 dc
.SetClippingRegion(wxRegion(updatergn
));
3130 wxMacPortSetter
helper(&dc
) ;
3131 child
->MacPaintBorders(0, 0) ;
3142 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3144 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3148 if ( iter
->IsTopLevel() )
3149 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3151 iter
= iter
->GetParent() ;
3154 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3159 void wxWindowMac::MacCreateScrollBars( long style
)
3161 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3163 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3165 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3166 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3167 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3168 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3170 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3171 variant
= wxWINDOW_VARIANT_SMALL
;
3174 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3176 GetClientSize( &width
, &height
) ;
3178 wxPoint
vPoint(width
- scrlsize
, 0) ;
3179 wxSize
vSize(scrlsize
, height
- adjust
) ;
3180 wxPoint
hPoint(0, height
- scrlsize
) ;
3181 wxSize
hSize(width
- adjust
, scrlsize
) ;
3183 if ( style
& wxVSCROLL
)
3184 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3186 if ( style
& wxHSCROLL
)
3187 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3190 // because the create does not take into account the client area origin
3191 // we might have a real position shift
3192 MacRepositionScrollBars() ;
3195 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3197 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3202 void wxWindowMac::MacRepositionScrollBars()
3204 if ( !m_hScrollBar
&& !m_vScrollBar
)
3207 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3208 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3209 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3211 // get real client area
3213 GetSize( &width
, &height
);
3215 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3216 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3218 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3219 wxSize
vSize( scrlsize
, height
- adjust
) ;
3220 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3221 wxSize
hSize( width
- adjust
, scrlsize
) ;
3224 int x
= 0, y
= 0, w
, h
;
3225 GetSize( &w
, &h
) ;
3227 MacClientToRootWindow( &x
, &y
) ;
3228 MacClientToRootWindow( &w
, &h
) ;
3230 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3232 int totW
= 10000 , totH
= 10000;
3235 if ( iter
->IsTopLevel() )
3237 iter
->GetSize( &totW
, &totH
) ;
3241 iter
= iter
->GetParent() ;
3255 if ( w
- x
>= totW
)
3260 if ( h
- y
>= totH
)
3268 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3270 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3273 bool wxWindowMac::AcceptsFocus() const
3275 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3278 void wxWindowMac::MacSuperChangedPosition()
3280 // only window-absolute structures have to be moved i.e. controls
3282 m_cachedClippedRectValid
= false ;
3285 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3288 child
= node
->GetData();
3289 child
->MacSuperChangedPosition() ;
3291 node
= node
->GetNext();
3295 void wxWindowMac::MacTopLevelWindowChangedPosition()
3297 // only screen-absolute structures have to be moved i.e. glcanvas
3300 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3303 child
= node
->GetData();
3304 child
->MacTopLevelWindowChangedPosition() ;
3306 node
= node
->GetNext();
3310 long wxWindowMac::MacGetLeftBorderSize() const
3317 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3319 // this metric is only the 'outset' outside the simple frame rect
3320 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3323 else if (HasFlag(wxSIMPLE_BORDER
))
3325 // this metric is only the 'outset' outside the simple frame rect
3326 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3333 long wxWindowMac::MacGetRightBorderSize() const
3335 // they are all symmetric in mac themes
3336 return MacGetLeftBorderSize() ;
3339 long wxWindowMac::MacGetTopBorderSize() const
3341 // they are all symmetric in mac themes
3342 return MacGetLeftBorderSize() ;
3345 long wxWindowMac::MacGetBottomBorderSize() const
3347 // they are all symmetric in mac themes
3348 return MacGetLeftBorderSize() ;
3351 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3353 return style
& ~wxBORDER_MASK
;
3356 // Find the wxWindowMac at the current mouse position, returning the mouse
3358 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3360 pt
= wxGetMousePosition();
3361 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3366 // Get the current mouse position.
3367 wxPoint
wxGetMousePosition()
3371 wxGetMousePosition( &x
, &y
);
3373 return wxPoint(x
, y
);
3376 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3378 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3380 // copied from wxGTK : CS
3381 // VZ: shouldn't we move this to base class then?
3383 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3386 // (a) it's a command event and so is propagated to the parent
3387 // (b) under MSW it can be generated from kbd too
3388 // (c) it uses screen coords (because of (a))
3389 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3391 this->ClientToScreen(event
.GetPosition()));
3392 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3401 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3403 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3404 CallNextEventHandler(
3405 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3406 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3409 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3413 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3417 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3418 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3423 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3425 return eventNotHandledErr
;
3428 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3430 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3431 if ( !wxWindowBase::Reparent(newParent
) )
3434 // copied from MacPostControlCreate
3435 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3437 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3439 ::EmbedControl( m_peer
->GetControlRef() , container
) ;