1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/window.cpp
3 // Purpose: wxWindowMac
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/window.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
38 #include "wx/tooltip.h"
39 #include "wx/spinctrl.h"
40 #include "wx/geometry.h"
46 #if wxUSE_DRAG_AND_DROP
50 #include "wx/mac/uma.h"
52 #define MAC_SCROLLBAR_SIZE 15
53 #define MAC_SMALL_SCROLLBAR_SIZE 11
57 #include <ToolUtils.h>
59 #include <MacTextEditor.h>
62 #if TARGET_API_MAC_OSX
64 #include <HIToolbox/HIView.h>
70 #ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac
, wxWindowBase
)
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
76 BEGIN_EVENT_TABLE(wxWindowMac
, wxWindowBase
)
77 EVT_NC_PAINT(wxWindowMac::OnNcPaint
)
78 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground
)
79 #if TARGET_API_MAC_OSX
80 EVT_PAINT(wxWindowMac::OnPaint
)
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus
)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus
)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent
)
87 #define wxMAC_DEBUG_REDRAW 0
88 #ifndef wxMAC_DEBUG_REDRAW
89 #define wxMAC_DEBUG_REDRAW 0
92 #define wxMAC_USE_THEME_BORDER 1
94 // ---------------------------------------------------------------------------
95 // Utility Routines to move between different coordinate systems
96 // ---------------------------------------------------------------------------
99 * Right now we have the following setup :
100 * a border that is not part of the native control is always outside the
101 * control's border (otherwise we loose all native intelligence, future ways
102 * may be to have a second embedding control responsible for drawing borders
103 * and backgrounds eventually)
104 * so all this border calculations have to be taken into account when calling
105 * native methods or getting native oriented data
106 * so we have three coordinate systems here
107 * wx client coordinates
108 * wx window coordinates (including window frames)
113 // originating from native control
117 void wxMacNativeToWindow( const wxWindow
* window
, RgnHandle handle
)
119 OffsetRgn( handle
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
122 void wxMacNativeToWindow( const wxWindow
* window
, Rect
*rect
)
124 OffsetRect( rect
, window
->MacGetLeftBorderSize() , window
->MacGetTopBorderSize() ) ;
128 // directed towards native control
131 void wxMacWindowToNative( const wxWindow
* window
, RgnHandle handle
)
133 OffsetRgn( handle
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() );
136 void wxMacWindowToNative( const wxWindow
* window
, Rect
*rect
)
138 OffsetRect( rect
, -window
->MacGetLeftBorderSize() , -window
->MacGetTopBorderSize() ) ;
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 extern long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
146 pascal OSStatus
wxMacSetupControlBackground( ControlRef iControl
, SInt16 iMessage
, SInt16 iDepth
, Boolean iIsColor
) ;
148 #if TARGET_API_MAC_OSX
150 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
153 kEventControlVisibilityChanged
= 157
159 static const EventTypeSpec eventList
[] =
161 { kEventClassCommand
, kEventProcessCommand
} ,
162 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
164 { kEventClassControl
, kEventControlHit
} ,
166 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
167 { kEventClassTextInput
, kEventTextInputUpdateActiveInputArea
} ,
169 { kEventClassControl
, kEventControlDraw
} ,
170 #if TARGET_API_MAC_OSX
171 { kEventClassControl
, kEventControlVisibilityChanged
} ,
172 { kEventClassControl
, kEventControlEnabledStateChanged
} ,
173 { kEventClassControl
, kEventControlHiliteChanged
} ,
175 { kEventClassControl
, kEventControlSetFocusPart
} ,
177 { kEventClassService
, kEventServiceGetTypes
},
178 { kEventClassService
, kEventServiceCopy
},
179 { kEventClassService
, kEventServicePaste
},
181 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
182 // { kEventClassControl , kEventControlBoundsChanged } ,
185 static pascal OSStatus
wxMacWindowControlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
187 OSStatus result
= eventNotHandledErr
;
189 wxMacCarbonEvent
cEvent( event
) ;
191 ControlRef controlRef
;
192 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
194 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
196 switch ( GetEventKind( event
) )
198 #if TARGET_API_MAC_OSX
199 case kEventControlDraw
:
201 RgnHandle updateRgn
= NULL
;
202 RgnHandle allocatedRgn
= NULL
;
203 wxRegion visRegion
= thisWindow
->MacGetVisibleRegion() ;
205 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
207 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
211 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
213 // as this update region is in native window locals we must adapt it to wx window local
214 allocatedRgn
= NewRgn() ;
215 CopyRgn( updateRgn
, allocatedRgn
) ;
217 // hide the given region by the new region that must be shifted
218 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
219 updateRgn
= allocatedRgn
;
224 GetRegionBounds( updateRgn
, &rgnBounds
) ;
226 #if wxMAC_DEBUG_REDRAW
227 if ( thisWindow
->MacIsUserPane() )
229 static float color
= 0.5 ;
232 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
234 HIViewGetBounds( controlRef
, &bounds
);
235 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
236 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
237 CGContextFillRect( cgContext
, bounds
);
250 #if wxMAC_USE_CORE_GRAPHICS
251 bool created
= false ;
252 CGContextRef cgContext
= NULL
;
253 OSStatus err
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) ;
254 wxASSERT_MSG( err
== noErr
, wxT("Unable to retrieve CGContextRef") ) ;
255 thisWindow
->MacSetCGContextRef( cgContext
) ;
258 wxMacCGContextStateSaver
sg( cgContext
) ;
261 wxWindow
* iter
= thisWindow
;
264 alpha
*= (float) iter
->GetTransparent()/255.0 ;
265 if ( iter
->IsTopLevel() )
268 iter
= iter
->GetParent() ;
271 CGContextSetAlpha( cgContext
, alpha
) ;
273 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
276 #if wxMAC_USE_CORE_GRAPHICS
277 thisWindow
->MacSetCGContextRef( NULL
) ;
281 CGContextRelease( cgContext
) ;
286 DisposeRgn( allocatedRgn
) ;
290 case kEventControlVisibilityChanged
:
291 thisWindow
->MacVisibilityChanged() ;
294 case kEventControlEnabledStateChanged
:
295 thisWindow
->MacEnabledStateChanged() ;
298 case kEventControlHiliteChanged
:
299 thisWindow
->MacHiliteChanged() ;
303 // we emulate this event under Carbon CFM
304 case kEventControlSetFocusPart
:
306 Boolean focusEverything
= false ;
307 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
310 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
315 if ( controlPart
== kControlFocusNoPart
)
318 if ( thisWindow
->GetCaret() )
319 thisWindow
->GetCaret()->OnKillFocus();
322 static bool inKillFocusEvent
= false ;
324 if ( !inKillFocusEvent
)
326 inKillFocusEvent
= true ;
327 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
328 event
.SetEventObject(thisWindow
);
329 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
330 inKillFocusEvent
= false ;
335 // panel wants to track the window which was the last to have focus in it
336 wxChildFocusEvent
eventFocus(thisWindow
);
337 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
340 if ( thisWindow
->GetCaret() )
341 thisWindow
->GetCaret()->OnSetFocus();
344 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
345 event
.SetEventObject(thisWindow
);
346 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
349 if ( thisWindow
->MacIsUserPane() )
354 case kEventControlHit
:
355 result
= thisWindow
->MacControlHit( handler
, event
) ;
365 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
367 OSStatus result
= eventNotHandledErr
;
369 wxMacCarbonEvent
cEvent( event
) ;
371 ControlRef controlRef
;
372 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
373 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
374 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
376 switch ( GetEventKind( event
) )
378 case kEventServiceGetTypes
:
382 textCtrl
->GetSelection( &from
, &to
) ;
384 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
386 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
387 if ( textCtrl
->IsEditable() )
388 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
390 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
391 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
393 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
397 CFArrayAppendValue(copyTypes
, typestring
) ;
399 CFArrayAppendValue(pasteTypes
, typestring
) ;
401 CFRelease( typestring
) ;
409 case kEventServiceCopy
:
414 textCtrl
->GetSelection( &from
, &to
) ;
415 wxString val
= textCtrl
->GetValue() ;
416 val
= val
.Mid( from
, to
- from
) ;
417 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
418 verify_noerr( ClearScrap( &scrapRef
) ) ;
419 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
424 case kEventServicePaste
:
427 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
428 Size textSize
, pastedSize
;
429 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
431 char *content
= new char[textSize
] ;
432 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
433 content
[textSize
- 1] = 0 ;
436 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
438 textCtrl
->WriteText( wxString( content
) ) ;
453 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
455 OSStatus result
= eventNotHandledErr
;
456 wxWindowMac
* focus
= (wxWindowMac
*) data
;
458 wchar_t* uniChars
= NULL
;
459 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
461 UniChar
* charBuf
= NULL
;
462 UInt32 dataSize
= 0 ;
465 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
467 numChars
= dataSize
/ sizeof( UniChar
) + 1;
470 if ( (size_t) numChars
* 2 > sizeof(buf
) )
471 charBuf
= new UniChar
[ numChars
] ;
475 uniChars
= new wchar_t[ numChars
] ;
476 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
477 charBuf
[ numChars
- 1 ] = 0;
478 #if SIZEOF_WCHAR_T == 2
479 uniChars
= (wchar_t*) charBuf
;
480 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
482 // the resulting string will never have more chars than the utf16 version, so this is safe
483 wxMBConvUTF16 converter
;
484 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
488 switch ( GetEventKind( event
) )
490 case kEventTextInputUpdateActiveInputArea
:
492 // An IME input event may return several characters, but we need to send one char at a time to
494 for (int pos
=0 ; pos
< numChars
; pos
++)
496 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
497 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
498 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
500 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
501 if ( wxTheApp
->MacSendCharEvent(
502 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
507 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
511 case kEventTextInputUnicodeForKeyEvent
:
513 UInt32 keyCode
, modifiers
;
516 unsigned char charCode
;
518 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
519 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
520 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
521 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
522 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
524 UInt32 message
= (keyCode
<< 8) + charCode
;
526 // An IME input event may return several characters, but we need to send one char at a time to
528 for (int pos
=0 ; pos
< numChars
; pos
++)
530 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
531 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
532 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
534 if ( wxTheApp
->MacSendCharEvent(
535 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
540 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
549 if ( charBuf
!= buf
)
555 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
557 OSStatus result
= eventNotHandledErr
;
558 wxWindowMac
* focus
= (wxWindowMac
*) data
;
562 wxMacCarbonEvent
cEvent( event
) ;
563 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
565 wxMenuItem
* item
= NULL
;
566 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
567 int id
= wxMacCommandToId( command
.commandID
) ;
571 wxASSERT( itemMenu
!= NULL
) ;
573 switch ( cEvent
.GetKind() )
575 case kEventProcessCommand
:
577 if (item
->IsCheckable())
578 item
->Check( !item
->IsChecked() ) ;
580 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
584 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
585 event
.SetEventObject(focus
);
586 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
588 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
594 case kEventCommandUpdateStatus
:
596 wxUpdateUIEvent
event(id
);
597 event
.SetEventObject( itemMenu
);
599 bool processed
= false;
601 // Try the menu's event handler
603 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
605 processed
= handler
->ProcessEvent(event
);
608 // Try the window the menu was popped up from
609 // (and up through the hierarchy)
612 const wxMenuBase
*menu
= itemMenu
;
615 wxWindow
*win
= menu
->GetInvokingWindow();
618 processed
= win
->GetEventHandler()->ProcessEvent(event
);
622 menu
= menu
->GetParent();
628 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
633 // if anything changed, update the changed attribute
634 if (event
.GetSetText())
635 itemMenu
->SetLabel(id
, event
.GetText());
636 if (event
.GetSetChecked())
637 itemMenu
->Check(id
, event
.GetChecked());
638 if (event
.GetSetEnabled())
639 itemMenu
->Enable(id
, event
.GetEnabled());
653 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
655 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
656 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
657 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
658 OSStatus result
= eventNotHandledErr
;
660 switch ( GetEventClass( event
) )
662 case kEventClassCommand
:
663 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
666 case kEventClassControl
:
667 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
670 case kEventClassService
:
671 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
674 case kEventClassTextInput
:
675 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
682 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
687 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
689 #if !TARGET_API_MAC_OSX
691 // ---------------------------------------------------------------------------
692 // UserPane events for non OSX builds
693 // ---------------------------------------------------------------------------
695 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
697 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
699 win
->MacControlUserPaneDrawProc(part
) ;
701 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
703 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
705 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
707 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
709 return kControlNoPart
;
711 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
713 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
715 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
717 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
719 return kControlNoPart
;
721 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
723 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
725 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
727 win
->MacControlUserPaneIdleProc() ;
729 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
731 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
733 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
735 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
737 return kControlNoPart
;
739 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
741 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
743 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
745 win
->MacControlUserPaneActivateProc(activating
) ;
747 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
749 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
751 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
753 return win
->MacControlUserPaneFocusProc(action
) ;
755 return kControlNoPart
;
757 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
759 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
761 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
763 win
->MacControlUserPaneBackgroundProc(info
) ;
765 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
767 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
770 RgnHandle rgn
= NewRgn() ;
772 MacWindowToRootWindow( &x
, &y
) ;
773 OffsetRgn( rgn
, -x
, -y
) ;
774 wxMacWindowStateSaver
sv( this ) ;
775 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
776 MacDoRedraw( rgn
, 0 ) ;
780 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
782 return kControlNoPart
;
785 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
787 return kControlNoPart
;
790 void wxWindowMac::MacControlUserPaneIdleProc()
794 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
796 return kControlNoPart
;
799 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
803 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
805 if ( AcceptsFocus() )
808 return kControlNoPart
;
811 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
817 // ---------------------------------------------------------------------------
818 // Scrollbar Tracking for all
819 // ---------------------------------------------------------------------------
821 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
822 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
826 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
828 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
831 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
833 // ===========================================================================
835 // ===========================================================================
837 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
839 static MacControlMap wxWinMacControlList
;
841 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
843 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
845 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
848 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
850 // adding NULL ControlRef is (first) surely a result of an error and
851 // (secondly) breaks native event processing
852 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
854 wxWinMacControlList
[inControl
] = control
;
857 void wxRemoveMacControlAssociation(wxWindow
*control
)
859 // iterate over all the elements in the class
860 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
861 // we should go on...
867 MacControlMap::iterator it
;
868 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
870 if ( it
->second
== control
)
872 wxWinMacControlList
.erase(it
);
880 // ----------------------------------------------------------------------------
881 // constructors and such
882 // ----------------------------------------------------------------------------
884 wxWindowMac::wxWindowMac()
889 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
894 const wxString
& name
)
897 Create(parent
, id
, pos
, size
, style
, name
);
900 void wxWindowMac::Init()
906 #if WXWIN_COMPATIBILITY_2_4
907 m_backgroundTransparent
= false;
910 #if wxMAC_USE_CORE_GRAPHICS
911 m_cgContextRef
= NULL
;
914 // as all windows are created with WS_VISIBLE style...
917 m_hScrollBar
= NULL
;
918 m_vScrollBar
= NULL
;
919 m_macBackgroundBrush
= wxNullBrush
;
921 m_macIsUserPane
= true;
922 m_clipChildren
= false ;
923 m_cachedClippedRectValid
= false ;
925 // we need a valid font for the encodings
926 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
929 wxWindowMac::~wxWindowMac()
933 m_isBeingDeleted
= true;
935 MacInvalidateBorders() ;
937 #ifndef __WXUNIVERSAL__
938 // VS: make sure there's no wxFrame with last focus set to us:
939 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
941 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
944 if ( frame
->GetLastFocus() == this )
945 frame
->SetLastFocus((wxWindow
*)NULL
);
951 // destroy children before destroying this window itself
954 // wxRemoveMacControlAssociation( this ) ;
955 // If we delete an item, we should initialize the parent panel,
956 // because it could now be invalid.
957 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow
);
960 if ( tlw
->GetDefaultItem() == (wxButton
*) this)
961 tlw
->SetDefaultItem(NULL
);
964 if ( m_peer
&& m_peer
->Ok() )
966 // in case the callback might be called during destruction
967 wxRemoveMacControlAssociation( this) ;
968 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
969 // we currently are not using this hook
970 // ::SetControlColorProc( *m_peer , NULL ) ;
974 if ( g_MacLastWindow
== this )
975 g_MacLastWindow
= NULL
;
977 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
980 if ( frame
->GetLastFocus() == this )
981 frame
->SetLastFocus( NULL
) ;
984 // delete our drop target if we've got one
985 #if wxUSE_DRAG_AND_DROP
986 if ( m_dropTarget
!= NULL
)
996 WXWidget
wxWindowMac::GetHandle() const
998 return (WXWidget
) m_peer
->GetControlRef() ;
1001 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1003 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1004 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1005 GetEventTypeCount(eventList
), eventList
, this,
1006 (EventHandlerRef
*)&m_macControlEventHandler
);
1008 #if !TARGET_API_MAC_OSX
1009 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1011 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1012 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1013 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1014 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1015 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1016 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1017 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1018 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1024 bool wxWindowMac::Create(wxWindowMac
*parent
,
1029 const wxString
& name
)
1031 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1033 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1036 m_windowVariant
= parent
->GetWindowVariant() ;
1038 if ( m_macIsUserPane
)
1040 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1043 | kControlSupportsEmbedding
1044 | kControlSupportsLiveFeedback
1045 | kControlGetsFocusOnClick
1046 // | kControlHasSpecialBackground
1047 // | kControlSupportsCalcBestRect
1048 | kControlHandlesTracking
1049 | kControlSupportsFocus
1050 | kControlWantsActivate
1051 | kControlWantsIdle
;
1053 m_peer
= new wxMacControl(this) ;
1054 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1055 verify_noerr( err
);
1057 MacPostControlCreate(pos
, size
) ;
1060 #ifndef __WXUNIVERSAL__
1061 // Don't give scrollbars to wxControls unless they ask for them
1062 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1063 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1065 MacCreateScrollBars( style
) ;
1069 wxWindowCreateEvent
event(this);
1070 GetEventHandler()->AddPendingEvent(event
);
1075 void wxWindowMac::MacChildAdded()
1078 m_vScrollBar
->Raise() ;
1080 m_hScrollBar
->Raise() ;
1083 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1085 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1087 m_peer
->SetReference( (long)this ) ;
1088 GetParent()->AddChild( this );
1090 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1092 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1093 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1094 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1095 GetParent()->MacChildAdded() ;
1097 // adjust font, controlsize etc
1098 DoSetWindowVariant( m_windowVariant
) ;
1100 m_peer
->SetLabel( wxStripMenuCodes(m_label
, wxStrip_Mnemonics
) ) ;
1102 if (!m_macIsUserPane
)
1103 SetInitialBestSize(size
);
1105 SetCursor( *wxSTANDARD_CURSOR
) ;
1108 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1110 // Don't assert, in case we set the window variant before
1111 // the window is created
1112 // wxASSERT( m_peer->Ok() ) ;
1114 m_windowVariant
= variant
;
1116 if (m_peer
== NULL
|| !m_peer
->Ok())
1120 ThemeFontID themeFont
= kThemeSystemFont
;
1122 // we will get that from the settings later
1123 // and make this NORMAL later, but first
1124 // we have a few calculations that we must fix
1128 case wxWINDOW_VARIANT_NORMAL
:
1129 size
= kControlSizeNormal
;
1130 themeFont
= kThemeSystemFont
;
1133 case wxWINDOW_VARIANT_SMALL
:
1134 size
= kControlSizeSmall
;
1135 themeFont
= kThemeSmallSystemFont
;
1138 case wxWINDOW_VARIANT_MINI
:
1139 if (UMAGetSystemVersion() >= 0x1030 )
1141 // not always defined in the headers
1147 size
= kControlSizeSmall
;
1148 themeFont
= kThemeSmallSystemFont
;
1152 case wxWINDOW_VARIANT_LARGE
:
1153 size
= kControlSizeLarge
;
1154 themeFont
= kThemeSystemFont
;
1158 wxFAIL_MSG(_T("unexpected window variant"));
1162 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1165 font
.MacCreateThemeFont( themeFont
) ;
1169 void wxWindowMac::MacUpdateControlFont()
1171 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1175 bool wxWindowMac::SetFont(const wxFont
& font
)
1177 bool retval
= wxWindowBase::SetFont( font
);
1179 MacUpdateControlFont() ;
1184 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1186 bool retval
= wxWindowBase::SetForegroundColour( col
);
1189 MacUpdateControlFont();
1194 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1196 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1200 wxColour
newCol(GetBackgroundColour());
1202 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW
) )
1203 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1204 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1205 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1207 brush
.SetColour( newCol
) ;
1209 MacSetBackgroundBrush( brush
) ;
1210 MacUpdateControlFont() ;
1215 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1217 m_macBackgroundBrush
= brush
;
1218 m_peer
->SetBackground( brush
) ;
1221 bool wxWindowMac::MacCanFocus() const
1223 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1224 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1225 // but the value range is nowhere documented
1226 Boolean keyExistsAndHasValidFormat
;
1227 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1228 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1230 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1236 UInt32 features
= 0 ;
1237 m_peer
->GetFeatures( &features
) ;
1239 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1243 void wxWindowMac::SetFocus()
1245 if ( !AcceptsFocus() )
1248 wxWindow
* former
= FindFocus() ;
1249 if ( former
== this )
1252 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1253 // we can only leave in case of an error
1254 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1255 if ( err
== errCouldntSetFocus
)
1258 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1260 #if !TARGET_API_MAC_OSX
1261 // emulate carbon events when running under CarbonLib where they are not natively available
1264 EventRef evRef
= NULL
;
1266 err
= MacCreateEvent(
1267 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1268 kEventAttributeUserEvent
, &evRef
);
1269 verify_noerr( err
);
1271 wxMacCarbonEvent
cEvent( evRef
) ;
1272 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1273 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1275 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1276 ReleaseEvent( evRef
) ;
1279 // send new focus event
1281 EventRef evRef
= NULL
;
1283 err
= MacCreateEvent(
1284 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1285 kEventAttributeUserEvent
, &evRef
);
1286 verify_noerr( err
);
1288 wxMacCarbonEvent
cEvent( evRef
) ;
1289 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1290 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1292 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1293 ReleaseEvent( evRef
) ;
1298 void wxWindowMac::DoCaptureMouse()
1300 wxApp::s_captureWindow
= this ;
1303 wxWindow
* wxWindowBase::GetCapture()
1305 return wxApp::s_captureWindow
;
1308 void wxWindowMac::DoReleaseMouse()
1310 wxApp::s_captureWindow
= NULL
;
1313 #if wxUSE_DRAG_AND_DROP
1315 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1317 if ( m_dropTarget
!= NULL
)
1318 delete m_dropTarget
;
1320 m_dropTarget
= pDropTarget
;
1321 if ( m_dropTarget
!= NULL
)
1329 // Old-style File Manager Drag & Drop
1330 void wxWindowMac::DragAcceptFiles(bool accept
)
1335 // Returns the size of the native control. In the case of the toplevel window
1336 // this is the content area root control
1338 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1339 int& w
, int& h
) const
1341 wxFAIL_MSG( wxT("Not currently supported") ) ;
1344 // From a wx position / size calculate the appropriate size of the native control
1346 bool wxWindowMac::MacGetBoundsForControl(
1350 int& w
, int& h
, bool adjustOrigin
) const
1352 // the desired size, minus the border pixels gives the correct size of the control
1356 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1357 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1358 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1360 x
+= MacGetLeftBorderSize() ;
1361 y
+= MacGetTopBorderSize() ;
1362 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1363 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1366 AdjustForParentClientOrigin( x
, y
) ;
1368 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1369 if ( !GetParent()->IsTopLevel() )
1371 x
-= GetParent()->MacGetLeftBorderSize() ;
1372 y
-= GetParent()->MacGetTopBorderSize() ;
1378 // Get window size (not client size)
1379 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1382 m_peer
->GetRect( &bounds
) ;
1385 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1387 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1390 // get the position of the bounds of this window in client coordinates of its parent
1391 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1394 m_peer
->GetRect( &bounds
) ;
1396 int x1
= bounds
.left
;
1397 int y1
= bounds
.top
;
1399 // get the wx window position from the native one
1400 x1
-= MacGetLeftBorderSize() ;
1401 y1
-= MacGetTopBorderSize() ;
1403 if ( !IsTopLevel() )
1405 wxWindow
*parent
= GetParent();
1408 // we must first adjust it to be in window coordinates of the parent,
1409 // as otherwise it gets lost by the ClientAreaOrigin fix
1410 x1
+= parent
->MacGetLeftBorderSize() ;
1411 y1
+= parent
->MacGetTopBorderSize() ;
1413 // and now to client coordinates
1414 wxPoint
pt(parent
->GetClientAreaOrigin());
1426 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1428 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1429 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1431 Point localwhere
= { 0, 0 } ;
1438 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1445 MacRootWindowToWindow( x
, y
) ;
1447 wxPoint origin
= GetClientAreaOrigin() ;
1454 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1456 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1457 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1459 wxPoint origin
= GetClientAreaOrigin() ;
1465 MacWindowToRootWindow( x
, y
) ;
1467 Point localwhere
= { 0, 0 };
1473 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1481 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1483 wxPoint origin
= GetClientAreaOrigin() ;
1489 MacWindowToRootWindow( x
, y
) ;
1492 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1494 MacRootWindowToWindow( x
, y
) ;
1496 wxPoint origin
= GetClientAreaOrigin() ;
1503 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1512 if ( !IsTopLevel() )
1514 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1517 pt
.x
-= MacGetLeftBorderSize() ;
1518 pt
.y
-= MacGetTopBorderSize() ;
1519 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1529 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1538 MacWindowToRootWindow( &x1
, &y1
) ;
1546 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1555 if ( !IsTopLevel() )
1557 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1560 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1561 pt
.x
+= MacGetLeftBorderSize() ;
1562 pt
.y
+= MacGetTopBorderSize() ;
1572 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1581 MacRootWindowToWindow( &x1
, &y1
) ;
1589 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1591 RgnHandle rgn
= NewRgn() ;
1593 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1595 Rect structure
, content
;
1597 GetRegionBounds( rgn
, &content
) ;
1598 m_peer
->GetRect( &structure
) ;
1599 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1601 left
= content
.left
- structure
.left
;
1602 top
= content
.top
- structure
.top
;
1603 right
= structure
.right
- content
.right
;
1604 bottom
= structure
.bottom
- content
.bottom
;
1608 left
= top
= right
= bottom
= 0 ;
1614 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1616 wxSize sizeTotal
= size
;
1618 RgnHandle rgn
= NewRgn() ;
1619 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1621 Rect content
, structure
;
1622 GetRegionBounds( rgn
, &content
) ;
1623 m_peer
->GetRect( &structure
) ;
1625 // structure is in parent coordinates, but we only need width and height, so it's ok
1627 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1628 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1633 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1634 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1639 // Get size *available for subwindows* i.e. excluding menu bar etc.
1640 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1644 RgnHandle rgn
= NewRgn() ;
1646 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1647 GetRegionBounds( rgn
, &content
) ;
1649 m_peer
->GetRect( &content
) ;
1652 ww
= content
.right
- content
.left
;
1653 hh
= content
.bottom
- content
.top
;
1655 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1656 hh
-= m_hScrollBar
->GetSize().y
;
1658 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1659 ww
-= m_vScrollBar
->GetSize().x
;
1667 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1669 if (m_cursor
== cursor
)
1672 if (wxNullCursor
== cursor
)
1674 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1679 if ( ! wxWindowBase::SetCursor( cursor
) )
1683 wxASSERT_MSG( m_cursor
.Ok(),
1684 wxT("cursor must be valid after call to the base version"));
1686 wxWindowMac
*mouseWin
= 0 ;
1688 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1689 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1691 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1693 // TODO: If we ever get a GetCurrentEvent... replacement
1694 // for the mouse position, use it...
1697 ControlPartCode part
;
1698 ControlRef control
;
1701 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1703 mouseWin
= wxFindControlFromMacControl( control
) ;
1706 QDSwapPort( savePort
, NULL
) ;
1709 if ( mouseWin
== this && !wxIsBusy() )
1710 m_cursor
.MacInstall() ;
1716 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1718 menu
->SetInvokingWindow(this);
1721 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1723 wxPoint mouse
= wxGetMousePosition();
1729 ClientToScreen( &x
, &y
) ;
1732 menu
->MacBeforeDisplay( true ) ;
1733 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1734 if ( HiWord(menuResult
) != 0 )
1737 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1738 int id
= wxMacCommandToId( macid
);
1739 wxMenuItem
* item
= NULL
;
1741 item
= menu
->FindItem( id
, &realmenu
) ;
1744 if (item
->IsCheckable())
1745 item
->Check( !item
->IsChecked() ) ;
1747 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1751 menu
->MacAfterDisplay( true ) ;
1752 menu
->SetInvokingWindow( NULL
);
1758 // ----------------------------------------------------------------------------
1760 // ----------------------------------------------------------------------------
1764 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1766 wxWindowBase::DoSetToolTip(tooltip
);
1769 m_tooltip
->SetWindow(this);
1774 void wxWindowMac::MacInvalidateBorders()
1776 if ( m_peer
== NULL
)
1779 bool vis
= MacIsReallyShown() ;
1783 int outerBorder
= MacGetLeftBorderSize() ;
1784 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1787 if ( outerBorder
== 0 )
1790 // now we know that we have something to do at all
1792 // as the borders are drawn on the parent we have to properly invalidate all these areas
1793 RgnHandle updateInner
, updateOuter
;
1796 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1797 updateInner
= NewRgn() ;
1798 updateOuter
= NewRgn() ;
1800 m_peer
->GetRect( &rect
) ;
1801 RectRgn( updateInner
, &rect
) ;
1802 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1803 RectRgn( updateOuter
, &rect
) ;
1804 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1806 #ifdef __WXMAC_OSX__
1807 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1809 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1811 InvalWindowRgn( tlw
, updateOuter
) ;
1814 DisposeRgn( updateOuter
) ;
1815 DisposeRgn( updateInner
) ;
1818 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1820 // this is never called for a toplevel window, so we know we have a parent
1821 int former_x
, former_y
, former_w
, former_h
;
1823 // Get true coordinates of former position
1824 DoGetPosition( &former_x
, &former_y
) ;
1825 DoGetSize( &former_w
, &former_h
) ;
1827 wxWindow
*parent
= GetParent();
1830 wxPoint
pt(parent
->GetClientAreaOrigin());
1835 int actualWidth
= width
;
1836 int actualHeight
= height
;
1840 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1841 actualWidth
= m_minWidth
;
1842 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1843 actualHeight
= m_minHeight
;
1844 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1845 actualWidth
= m_maxWidth
;
1846 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1847 actualHeight
= m_maxHeight
;
1849 bool doMove
= false, doResize
= false ;
1851 if ( actualX
!= former_x
|| actualY
!= former_y
)
1854 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1857 if ( doMove
|| doResize
)
1859 // as the borders are drawn outside the native control, we adjust now
1861 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1862 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1863 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1866 wxMacRectToNative( &bounds
, &r
) ;
1868 if ( !GetParent()->IsTopLevel() )
1869 wxMacWindowToNative( GetParent() , &r
) ;
1871 MacInvalidateBorders() ;
1873 m_cachedClippedRectValid
= false ;
1874 m_peer
->SetRect( &r
) ;
1876 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1878 MacInvalidateBorders() ;
1880 MacRepositionScrollBars() ;
1883 wxPoint
point(actualX
, actualY
);
1884 wxMoveEvent
event(point
, m_windowId
);
1885 event
.SetEventObject(this);
1886 GetEventHandler()->ProcessEvent(event
) ;
1891 MacRepositionScrollBars() ;
1892 wxSize
size(actualWidth
, actualHeight
);
1893 wxSizeEvent
event(size
, m_windowId
);
1894 event
.SetEventObject(this);
1895 GetEventHandler()->ProcessEvent(event
);
1900 wxSize
wxWindowMac::DoGetBestSize() const
1902 if ( m_macIsUserPane
|| IsTopLevel() )
1903 return wxWindowBase::DoGetBestSize() ;
1905 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1906 int bestWidth
, bestHeight
;
1908 m_peer
->GetBestRect( &bestsize
) ;
1909 if ( EmptyRect( &bestsize
) )
1914 bestsize
.bottom
= 16 ;
1916 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1918 bestsize
.bottom
= 16 ;
1921 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1923 bestsize
.bottom
= 24 ;
1928 // return wxWindowBase::DoGetBestSize() ;
1932 bestWidth
= bestsize
.right
- bestsize
.left
;
1933 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1934 if ( bestHeight
< 10 )
1937 return wxSize(bestWidth
, bestHeight
);
1940 // set the size of the window: if the dimensions are positive, just use them,
1941 // but if any of them is equal to -1, it means that we must find the value for
1942 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1943 // which case -1 is a valid value for x and y)
1945 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1946 // the width/height to best suit our contents, otherwise we reuse the current
1948 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1950 // get the current size and position...
1951 int currentX
, currentY
;
1952 int currentW
, currentH
;
1954 GetPosition(¤tX
, ¤tY
);
1955 GetSize(¤tW
, ¤tH
);
1957 // ... and don't do anything (avoiding flicker) if it's already ok
1958 if ( x
== currentX
&& y
== currentY
&&
1959 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
1962 MacRepositionScrollBars() ; // we might have a real position shift
1967 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1969 if ( x
== wxDefaultCoord
)
1971 if ( y
== wxDefaultCoord
)
1975 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1977 wxSize size
= wxDefaultSize
;
1978 if ( width
== wxDefaultCoord
)
1980 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1982 size
= DoGetBestSize();
1987 // just take the current one
1992 if ( height
== wxDefaultCoord
)
1994 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1996 if ( size
.x
== wxDefaultCoord
)
1997 size
= DoGetBestSize();
1998 // else: already called DoGetBestSize() above
2004 // just take the current one
2009 DoMoveWindow( x
, y
, width
, height
);
2012 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2014 RgnHandle rgn
= NewRgn() ;
2016 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2018 GetRegionBounds( rgn
, &content
) ;
2028 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2031 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2033 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2035 int currentclientwidth
, currentclientheight
;
2036 int currentwidth
, currentheight
;
2038 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2039 GetSize( ¤twidth
, ¤theight
) ;
2041 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2042 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2046 void wxWindowMac::SetLabel(const wxString
& title
)
2048 m_label
= wxStripMenuCodes(title
, wxStrip_Mnemonics
) ;
2050 if ( m_peer
&& m_peer
->Ok() )
2051 m_peer
->SetLabel( m_label
) ;
2056 wxString
wxWindowMac::GetLabel() const
2061 bool wxWindowMac::Show(bool show
)
2063 bool former
= MacIsReallyShown() ;
2064 if ( !wxWindowBase::Show(show
) )
2067 // TODO: use visibilityChanged Carbon Event for OSX
2069 m_peer
->SetVisibility( show
, true ) ;
2071 if ( former
!= MacIsReallyShown() )
2072 MacPropagateVisibilityChanged() ;
2077 bool wxWindowMac::Enable(bool enable
)
2079 wxASSERT( m_peer
->Ok() ) ;
2080 bool former
= MacIsReallyEnabled() ;
2081 if ( !wxWindowBase::Enable(enable
) )
2084 m_peer
->Enable( enable
) ;
2086 if ( former
!= MacIsReallyEnabled() )
2087 MacPropagateEnabledStateChanged() ;
2093 // status change propagations (will be not necessary for OSX later )
2096 void wxWindowMac::MacPropagateVisibilityChanged()
2098 #if !TARGET_API_MAC_OSX
2099 MacVisibilityChanged() ;
2102 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2105 child
= node
->GetData();
2106 if ( child
->IsShown() )
2107 child
->MacPropagateVisibilityChanged() ;
2109 node
= node
->GetNext();
2114 void wxWindowMac::MacPropagateEnabledStateChanged()
2116 #if !TARGET_API_MAC_OSX
2117 MacEnabledStateChanged() ;
2120 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2123 child
= node
->GetData();
2124 if ( child
->IsEnabled() )
2125 child
->MacPropagateEnabledStateChanged() ;
2127 node
= node
->GetNext();
2132 void wxWindowMac::MacPropagateHiliteChanged()
2134 #if !TARGET_API_MAC_OSX
2135 MacHiliteChanged() ;
2138 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2141 child
= node
->GetData();
2142 if (child
/* && child->IsEnabled() */)
2143 child
->MacPropagateHiliteChanged() ;
2145 node
= node
->GetNext();
2151 // status change notifications
2154 void wxWindowMac::MacVisibilityChanged()
2158 void wxWindowMac::MacHiliteChanged()
2162 void wxWindowMac::MacEnabledStateChanged()
2167 // status queries on the inherited window's state
2170 bool wxWindowMac::MacIsReallyShown()
2172 // only under OSX the visibility of the TLW is taken into account
2173 if ( m_isBeingDeleted
)
2176 #if TARGET_API_MAC_OSX
2177 if ( m_peer
&& m_peer
->Ok() )
2178 return m_peer
->IsVisible();
2181 wxWindow
* win
= this ;
2182 while ( win
->IsShown() )
2184 if ( win
->IsTopLevel() )
2187 win
= win
->GetParent() ;
2195 bool wxWindowMac::MacIsReallyEnabled()
2197 return m_peer
->IsEnabled() ;
2200 bool wxWindowMac::MacIsReallyHilited()
2202 return m_peer
->IsActive();
2205 void wxWindowMac::MacFlashInvalidAreas()
2207 #if TARGET_API_MAC_OSX
2208 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2212 int wxWindowMac::GetCharHeight() const
2214 wxClientDC
dc( (wxWindowMac
*)this ) ;
2216 return dc
.GetCharHeight() ;
2219 int wxWindowMac::GetCharWidth() const
2221 wxClientDC
dc( (wxWindowMac
*)this ) ;
2223 return dc
.GetCharWidth() ;
2226 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2227 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2229 const wxFont
*fontToUse
= theFont
;
2231 fontToUse
= &m_font
;
2233 wxClientDC
dc( (wxWindowMac
*) this ) ;
2235 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2236 if ( externalLeading
)
2237 *externalLeading
= le
;
2247 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2248 * we always intersect with the entire window, not only with the client area
2251 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2253 if ( m_peer
== NULL
)
2256 if ( !MacIsReallyShown() )
2263 wxMacRectToNative( rect
, &r
) ;
2264 m_peer
->SetNeedsDisplay( &r
) ;
2268 m_peer
->SetNeedsDisplay() ;
2272 void wxWindowMac::Freeze()
2274 #if TARGET_API_MAC_OSX
2275 if ( !m_frozenness
++ )
2277 if ( m_peer
&& m_peer
->Ok() )
2278 m_peer
->SetDrawingEnabled( false ) ;
2283 void wxWindowMac::Thaw()
2285 #if TARGET_API_MAC_OSX
2286 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2288 if ( !--m_frozenness
)
2290 if ( m_peer
&& m_peer
->Ok() )
2292 m_peer
->SetDrawingEnabled( true ) ;
2293 m_peer
->InvalidateWithChildren() ;
2299 wxWindowMac
*wxGetActiveWindow()
2301 // actually this is a windows-only concept
2305 // Coordinates relative to the window
2306 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2308 // We really don't move the mouse programmatically under Mac.
2311 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2313 if ( MacGetTopLevelWindow() == NULL
)
2316 #if TARGET_API_MAC_OSX
2317 if ( !m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
)
2324 event
.GetDC()->Clear() ;
2328 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2333 int wxWindowMac::GetScrollPos(int orient
) const
2335 if ( orient
== wxHORIZONTAL
)
2338 return m_hScrollBar
->GetThumbPosition() ;
2343 return m_vScrollBar
->GetThumbPosition() ;
2349 // This now returns the whole range, not just the number
2350 // of positions that we can scroll.
2351 int wxWindowMac::GetScrollRange(int orient
) const
2353 if ( orient
== wxHORIZONTAL
)
2356 return m_hScrollBar
->GetRange() ;
2361 return m_vScrollBar
->GetRange() ;
2367 int wxWindowMac::GetScrollThumb(int orient
) const
2369 if ( orient
== wxHORIZONTAL
)
2372 return m_hScrollBar
->GetThumbSize() ;
2377 return m_vScrollBar
->GetThumbSize() ;
2383 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2385 if ( orient
== wxHORIZONTAL
)
2388 m_hScrollBar
->SetThumbPosition( pos
) ;
2393 m_vScrollBar
->SetThumbPosition( pos
) ;
2398 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2399 // our own window origin is at leftOrigin/rightOrigin
2402 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2408 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2409 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2411 // back to the surrounding frame rectangle
2412 m_peer
->GetRect( &rect
) ;
2413 InsetRect( &rect
, -1 , -1 ) ;
2415 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2416 if ( UMAGetSystemVersion() >= 0x1030 )
2418 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2419 rect
.bottom
- rect
.top
) ;
2421 HIThemeFrameDrawInfo info
;
2422 memset( &info
, 0 , sizeof(info
) ) ;
2426 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2427 info
.isFocused
= hasFocus
;
2429 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2430 wxASSERT( cgContext
) ;
2432 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2434 info
.kind
= kHIThemeFrameTextFieldSquare
;
2435 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2437 else if ( HasFlag(wxSIMPLE_BORDER
) )
2439 info
.kind
= kHIThemeFrameListBox
;
2440 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2442 else if ( hasFocus
)
2444 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2447 m_peer
->GetRect( &rect
) ;
2448 if ( hasBothScrollbars
)
2450 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2451 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2452 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2453 HIThemeGrowBoxDrawInfo info
;
2454 memset( &info
, 0, sizeof(info
) ) ;
2456 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2457 info
.kind
= kHIThemeGrowBoxKindNone
;
2458 info
.size
= kHIThemeGrowBoxSizeNormal
;
2459 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2460 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2466 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2470 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2471 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2474 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2475 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2476 else if ( HasFlag(wxSIMPLE_BORDER
) )
2477 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2480 DrawThemeFocusRect( &rect
, true ) ;
2482 if ( hasBothScrollbars
)
2484 // GetThemeStandaloneGrowBoxBounds
2485 // DrawThemeStandaloneNoGrowBox
2490 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2492 if ( child
== m_hScrollBar
)
2493 m_hScrollBar
= NULL
;
2494 if ( child
== m_vScrollBar
)
2495 m_vScrollBar
= NULL
;
2497 wxWindowBase::RemoveChild( child
) ;
2500 // New function that will replace some of the above.
2501 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2502 int range
, bool refresh
)
2505 bool triggerSizeEvent
= false;
2507 if ( orient
== wxHORIZONTAL
)
2511 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2512 if ( m_hScrollBar
->IsShown() != showScroller
)
2514 m_hScrollBar
->Show( showScroller
);
2515 triggerSizeEvent
= true;
2518 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2525 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2526 if ( m_vScrollBar
->IsShown() != showScroller
)
2528 m_vScrollBar
->Show( showScroller
) ;
2529 triggerSizeEvent
= true;
2532 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2536 MacRepositionScrollBars() ;
2537 if ( triggerSizeEvent
)
2539 wxSizeEvent
event(GetSize(), m_windowId
);
2540 event
.SetEventObject(this);
2541 GetEventHandler()->ProcessEvent(event
);
2545 // Does a physical scroll
2546 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2548 if ( dx
== 0 && dy
== 0 )
2551 int width
, height
;
2552 GetClientSize( &width
, &height
) ;
2554 #if TARGET_API_MAC_OSX
2557 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2558 // area is scrolled, this does not occur if width and height are 2 pixels less,
2559 // TODO: write optimal workaround
2560 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2562 scrollrect
.Intersect( *rect
) ;
2564 if ( m_peer
->GetNeedsDisplay() )
2566 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2567 // either immediate redraw or full invalidate
2569 // is the better overall solution, as it does not slow down scrolling
2570 m_peer
->SetNeedsDisplay() ;
2572 // this would be the preferred version for fast drawing controls
2574 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2575 if ( UMAGetSystemVersion() >= 0x1030 )
2576 HIViewRender(m_peer
->GetControlRef()) ;
2583 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2584 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2585 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2587 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2588 // either immediate redraw or full invalidate
2590 // is the better overall solution, as it does not slow down scrolling
2591 m_peer
->SetNeedsDisplay() ;
2593 // this would be the preferred version for fast drawing controls
2595 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2596 if ( UMAGetSystemVersion() >= 0x1030 )
2597 HIViewRender(m_peer
->GetControlRef()) ;
2611 RgnHandle updateRgn
= NewRgn() ;
2614 wxClientDC
dc(this) ;
2615 wxMacPortSetter
helper(&dc
) ;
2617 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2618 //scrollrect.top += MacGetTopBorderSize() ;
2619 //scrollrect.left += MacGetLeftBorderSize() ;
2620 scrollrect
.bottom
= scrollrect
.top
+ height
;
2621 scrollrect
.right
= scrollrect
.left
+ width
;
2625 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2626 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2627 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2630 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2632 // now scroll the former update region as well and add the new update region
2633 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2634 RgnHandle formerUpdateRgn
= NewRgn() ;
2635 RgnHandle scrollRgn
= NewRgn() ;
2636 RectRgn( scrollRgn
, &scrollrect
) ;
2637 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2639 LocalToGlobal( &pt
) ;
2640 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2641 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2643 if ( !EmptyRgn( formerUpdateRgn
) )
2645 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2646 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2647 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2650 InvalWindowRgn(rootWindow
, updateRgn
) ;
2651 DisposeRgn( updateRgn
) ;
2652 DisposeRgn( formerUpdateRgn
) ;
2653 DisposeRgn( scrollRgn
) ;
2661 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2663 child
= node
->GetData();
2666 if (child
== m_vScrollBar
)
2668 if (child
== m_hScrollBar
)
2670 if (child
->IsTopLevel())
2673 child
->GetPosition( &x
, &y
);
2674 child
->GetSize( &w
, &h
);
2677 wxRect
rc( x
, y
, w
, h
);
2678 if (rect
->Intersects( rc
))
2679 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2683 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2688 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2690 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2692 wxScrollWinEvent wevent
;
2693 wevent
.SetPosition(event
.GetPosition());
2694 wevent
.SetOrientation(event
.GetOrientation());
2695 wevent
.SetEventObject(this);
2697 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2698 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2699 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2700 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2701 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2702 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2703 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2704 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2705 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2706 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2707 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2708 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2709 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2710 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2711 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2712 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2714 GetEventHandler()->ProcessEvent(wevent
);
2718 // Get the window with the focus
2719 wxWindowMac
*wxWindowBase::DoFindFocus()
2721 ControlRef control
;
2722 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2723 return wxFindControlFromMacControl( control
) ;
2726 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2728 // panel wants to track the window which was the last to have focus in it,
2729 // so we want to set ourselves as the window which last had focus
2731 // notice that it's also important to do it upwards the tree because
2732 // otherwise when the top level panel gets focus, it won't set it back to
2733 // us, but to some other sibling
2735 // CS: don't know if this is still needed:
2736 //wxChildFocusEvent eventFocus(this);
2737 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2739 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2741 #if wxMAC_USE_CORE_GRAPHICS
2742 GetParent()->Refresh() ;
2744 wxMacWindowStateSaver
sv( this ) ;
2747 m_peer
->GetRect( &rect
) ;
2748 // auf den umgebenden Rahmen zur\9fck
2749 InsetRect( &rect
, -1 , -1 ) ;
2751 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2755 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2757 rect
.right
+= pt
.x
;
2759 rect
.bottom
+= pt
.y
;
2762 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2763 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2764 if ( !bIsFocusEvent
)
2766 // as this erases part of the frame we have to redraw borders
2767 // and because our z-ordering is not always correct (staticboxes)
2768 // we have to invalidate things, we cannot simple redraw
2769 MacInvalidateBorders() ;
2777 void wxWindowMac::OnInternalIdle()
2779 // This calls the UI-update mechanism (querying windows for
2780 // menu/toolbar/control state information)
2781 if (wxUpdateUIEvent::CanUpdate(this))
2782 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2785 // Raise the window to the top of the Z order
2786 void wxWindowMac::Raise()
2788 m_peer
->SetZOrder( true , NULL
) ;
2791 // Lower the window to the bottom of the Z order
2792 void wxWindowMac::Lower()
2794 m_peer
->SetZOrder( false , NULL
) ;
2797 // static wxWindow *gs_lastWhich = NULL;
2799 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2801 // first trigger a set cursor event
2803 wxPoint clientorigin
= GetClientAreaOrigin() ;
2804 wxSize clientsize
= GetClientSize() ;
2806 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2808 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2810 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2811 if ( processedEvtSetCursor
&& event
.HasCursor() )
2813 cursor
= event
.GetCursor() ;
2817 // the test for processedEvtSetCursor is here to prevent using m_cursor
2818 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2819 // it - this is a way to say that our cursor shouldn't be used for this
2821 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2824 if ( !wxIsBusy() && !GetParent() )
2825 cursor
= *wxSTANDARD_CURSOR
;
2829 cursor
.MacInstall() ;
2832 return cursor
.Ok() ;
2835 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2839 return m_tooltip
->GetTip() ;
2842 return wxEmptyString
;
2845 void wxWindowMac::ClearBackground()
2851 void wxWindowMac::Update()
2853 #if TARGET_API_MAC_OSX
2854 MacGetTopLevelWindow()->MacPerformUpdates() ;
2856 ::Draw1Control( m_peer
->GetControlRef() ) ;
2860 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2862 wxTopLevelWindowMac
* win
= NULL
;
2863 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2865 win
= wxFindWinFromMacWindow( window
) ;
2870 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2872 MacUpdateClippedRects() ;
2874 return m_cachedClippedClientRect
;
2877 const wxRect
& wxWindowMac::MacGetClippedRect() const
2879 MacUpdateClippedRects() ;
2881 return m_cachedClippedRect
;
2884 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2886 MacUpdateClippedRects() ;
2888 return m_cachedClippedRectWithOuterStructure
;
2891 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2893 static wxRegion emptyrgn
;
2895 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2897 MacUpdateClippedRects() ;
2898 if ( includeOuterStructures
)
2899 return m_cachedClippedRegionWithOuterStructure
;
2901 return m_cachedClippedRegion
;
2909 void wxWindowMac::MacUpdateClippedRects() const
2911 if ( m_cachedClippedRectValid
)
2914 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2915 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2916 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2917 // to add focus borders everywhere
2919 Rect r
, rIncludingOuterStructures
;
2921 m_peer
->GetRect( &r
) ;
2922 r
.left
-= MacGetLeftBorderSize() ;
2923 r
.top
-= MacGetTopBorderSize() ;
2924 r
.bottom
+= MacGetBottomBorderSize() ;
2925 r
.right
+= MacGetRightBorderSize() ;
2932 rIncludingOuterStructures
= r
;
2933 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2935 wxRect cl
= GetClientRect() ;
2936 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2940 const wxWindow
* child
= this ;
2941 const wxWindow
* parent
= NULL
;
2943 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2945 if ( parent
->MacIsChildOfClientArea(child
) )
2947 size
= parent
->GetClientSize() ;
2948 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2954 // this will be true for scrollbars, toolbars etc.
2955 size
= parent
->GetSize() ;
2956 y
= parent
->MacGetTopBorderSize() ;
2957 x
= parent
->MacGetLeftBorderSize() ;
2958 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
2959 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
2962 parent
->MacWindowToRootWindow( &x
, &y
) ;
2963 MacRootWindowToWindow( &x
, &y
) ;
2965 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
2967 // the wxwindow and client rects will always be clipped
2968 SectRect( &r
, &rparent
, &r
) ;
2969 SectRect( &rClient
, &rparent
, &rClient
) ;
2971 // the structure only at 'hard' borders
2972 if ( parent
->MacClipChildren() ||
2973 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
2975 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
2981 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
2982 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
2983 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
2984 m_cachedClippedRectWithOuterStructure
= wxRect(
2985 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
2986 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
2987 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
2989 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
2990 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
2991 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
2993 m_cachedClippedRectValid
= true ;
2997 This function must not change the updatergn !
2999 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3001 bool handled
= false ;
3003 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3004 GetRegionBounds( updatergn
, &updatebounds
) ;
3006 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3008 if ( !EmptyRgn(updatergn
) )
3010 RgnHandle newupdate
= NewRgn() ;
3011 wxSize point
= GetClientSize() ;
3012 wxPoint origin
= GetClientAreaOrigin() ;
3013 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3014 SectRgn( newupdate
, updatergn
, newupdate
) ;
3016 // first send an erase event to the entire update area
3018 // for the toplevel window this really is the entire area
3019 // for all the others only their client area, otherwise they
3020 // might be drawing with full alpha and eg put blue into
3021 // the grow-box area of a scrolled window (scroll sample)
3022 wxDC
* dc
= new wxWindowDC(this);
3024 dc
->SetClippingRegion(wxRegion(updatergn
));
3026 dc
->SetClippingRegion(wxRegion(newupdate
));
3028 wxEraseEvent
eevent( GetId(), dc
);
3029 eevent
.SetEventObject( this );
3030 GetEventHandler()->ProcessEvent( eevent
);
3034 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3035 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3036 m_updateRegion
= newupdate
;
3037 DisposeRgn( newupdate
) ;
3039 if ( !m_updateRegion
.Empty() )
3041 // paint the window itself
3044 event
.SetTimestamp(time
);
3045 event
.SetEventObject(this);
3046 GetEventHandler()->ProcessEvent(event
);
3050 // now we cannot rely on having its borders drawn by a window itself, as it does not
3051 // get the updateRgn wide enough to always do so, so we do it from the parent
3052 // this would also be the place to draw any custom backgrounds for native controls
3053 // in Composited windowing
3054 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3058 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3060 child
= node
->GetData();
3063 if (child
== m_vScrollBar
)
3065 if (child
== m_hScrollBar
)
3067 if (child
->IsTopLevel())
3069 if (!child
->IsShown())
3072 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3074 child
->GetPosition( &x
, &y
);
3075 child
->GetSize( &w
, &h
);
3076 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3077 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3078 InsetRect( &childRect
, -10 , -10) ;
3080 if ( RectInRgn( &childRect
, updatergn
) )
3082 // paint custom borders
3083 wxNcPaintEvent
eventNc( child
->GetId() );
3084 eventNc
.SetEventObject( child
);
3085 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3087 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3088 if ( UMAGetSystemVersion() >= 0x1030 )
3090 child
->MacPaintBorders(0, 0) ;
3095 wxWindowDC
dc(this) ;
3096 dc
.SetClippingRegion(wxRegion(updatergn
));
3097 wxMacPortSetter
helper(&dc
) ;
3098 child
->MacPaintBorders(0, 0) ;
3109 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3111 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3115 if ( iter
->IsTopLevel() )
3116 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3118 iter
= iter
->GetParent() ;
3121 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3126 void wxWindowMac::MacCreateScrollBars( long style
)
3128 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3130 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3132 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3133 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3134 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3135 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3137 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3138 variant
= wxWINDOW_VARIANT_SMALL
;
3141 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3143 GetClientSize( &width
, &height
) ;
3145 wxPoint
vPoint(width
- scrlsize
, 0) ;
3146 wxSize
vSize(scrlsize
, height
- adjust
) ;
3147 wxPoint
hPoint(0, height
- scrlsize
) ;
3148 wxSize
hSize(width
- adjust
, scrlsize
) ;
3150 if ( style
& wxVSCROLL
)
3151 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3153 if ( style
& wxHSCROLL
)
3154 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3157 // because the create does not take into account the client area origin
3158 // we might have a real position shift
3159 MacRepositionScrollBars() ;
3162 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3164 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3169 void wxWindowMac::MacRepositionScrollBars()
3171 if ( !m_hScrollBar
&& !m_vScrollBar
)
3174 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3175 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3176 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3178 // get real client area
3180 GetSize( &width
, &height
);
3182 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3183 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3185 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3186 wxSize
vSize( scrlsize
, height
- adjust
) ;
3187 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3188 wxSize
hSize( width
- adjust
, scrlsize
) ;
3191 int x
= 0, y
= 0, w
, h
;
3192 GetSize( &w
, &h
) ;
3194 MacClientToRootWindow( &x
, &y
) ;
3195 MacClientToRootWindow( &w
, &h
) ;
3197 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3199 int totW
= 10000 , totH
= 10000;
3202 if ( iter
->IsTopLevel() )
3204 iter
->GetSize( &totW
, &totH
) ;
3208 iter
= iter
->GetParent() ;
3222 if ( w
- x
>= totW
)
3227 if ( h
- y
>= totH
)
3235 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3237 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3240 bool wxWindowMac::AcceptsFocus() const
3242 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3245 void wxWindowMac::MacSuperChangedPosition()
3247 // only window-absolute structures have to be moved i.e. controls
3249 m_cachedClippedRectValid
= false ;
3252 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3255 child
= node
->GetData();
3256 child
->MacSuperChangedPosition() ;
3258 node
= node
->GetNext();
3262 void wxWindowMac::MacTopLevelWindowChangedPosition()
3264 // only screen-absolute structures have to be moved i.e. glcanvas
3267 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3270 child
= node
->GetData();
3271 child
->MacTopLevelWindowChangedPosition() ;
3273 node
= node
->GetNext();
3277 long wxWindowMac::MacGetLeftBorderSize() const
3284 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3286 // this metric is only the 'outset' outside the simple frame rect
3287 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3290 else if (HasFlag(wxSIMPLE_BORDER
))
3292 // this metric is only the 'outset' outside the simple frame rect
3293 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3300 long wxWindowMac::MacGetRightBorderSize() const
3302 // they are all symmetric in mac themes
3303 return MacGetLeftBorderSize() ;
3306 long wxWindowMac::MacGetTopBorderSize() const
3308 // they are all symmetric in mac themes
3309 return MacGetLeftBorderSize() ;
3312 long wxWindowMac::MacGetBottomBorderSize() const
3314 // they are all symmetric in mac themes
3315 return MacGetLeftBorderSize() ;
3318 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3320 return style
& ~wxBORDER_MASK
;
3323 // Find the wxWindowMac at the current mouse position, returning the mouse
3325 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3327 pt
= wxGetMousePosition();
3328 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3333 // Get the current mouse position.
3334 wxPoint
wxGetMousePosition()
3338 wxGetMousePosition( &x
, &y
);
3340 return wxPoint(x
, y
);
3343 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3345 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3347 // copied from wxGTK : CS
3348 // VZ: shouldn't we move this to base class then?
3350 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3353 // (a) it's a command event and so is propagated to the parent
3354 // (b) under MSW it can be generated from kbd too
3355 // (c) it uses screen coords (because of (a))
3356 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3358 this->ClientToScreen(event
.GetPosition()));
3359 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3368 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3370 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3371 CallNextEventHandler(
3372 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3373 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3376 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3380 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3384 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3385 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3390 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3392 return eventNotHandledErr
;
3395 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3397 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3398 if ( !wxWindowBase::Reparent(newParent
) )
3401 // copied from MacPostControlCreate
3402 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3404 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3406 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
3411 bool wxWindowMac::SetTransparent(wxByte alpha
)
3413 #if wxMAC_USE_CORE_GRAPHICS
3414 if ( alpha
!= m_macAlpha
)
3416 m_macAlpha
= alpha
;
3426 bool wxWindowMac::CanSetTransparent()
3428 #if wxMAC_USE_CORE_GRAPHICS
3435 wxByte
wxWindowMac::GetTransparent() const