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() ;
206 if ( ! thisWindow
->GetPeer()->IsCompositing() )
208 if ( thisWindow
->GetPeer()->IsRootControl() )
209 thisWindow
->GetPeer()->GetRect( &controlBounds
) ;
211 GetControlBounds( thisWindow
->GetPeer()->GetControlRef() , &controlBounds
) ;
214 if ( cEvent
.GetParameter
<RgnHandle
>(kEventParamRgnHandle
, &updateRgn
) != noErr
)
216 updateRgn
= (RgnHandle
) visRegion
.GetWXHRGN() ;
220 if ( ! thisWindow
->GetPeer()->IsCompositing() )
222 allocatedRgn
= NewRgn() ;
223 CopyRgn( updateRgn
, allocatedRgn
) ;
224 OffsetRgn( allocatedRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
226 // hide the given region by the new region that must be shifted
227 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
228 updateRgn
= allocatedRgn
;
232 if ( thisWindow
->MacGetLeftBorderSize() != 0 || thisWindow
->MacGetTopBorderSize() != 0 )
234 // as this update region is in native window locals we must adapt it to wx window local
235 allocatedRgn
= NewRgn() ;
236 CopyRgn( updateRgn
, allocatedRgn
) ;
238 // hide the given region by the new region that must be shifted
239 wxMacNativeToWindow( thisWindow
, allocatedRgn
) ;
240 updateRgn
= allocatedRgn
;
246 GetRegionBounds( updateRgn
, &rgnBounds
) ;
248 #if wxMAC_DEBUG_REDRAW
249 if ( thisWindow
->MacIsUserPane() )
251 static float color
= 0.5 ;
254 CGContextRef cgContext
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
) ;
256 HIViewGetBounds( controlRef
, &bounds
);
257 CGContextSetRGBFillColor( cgContext
, channel
== 0 ? color
: 0.5 ,
258 channel
== 1 ? color
: 0.5 , channel
== 2 ? color
: 0.5 , 1 );
259 CGContextFillRect( cgContext
, bounds
);
272 #if wxMAC_USE_CORE_GRAPHICS
273 bool created
= false ;
274 CGContextRef cgContext
= NULL
;
275 if ( cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, &cgContext
) != noErr
)
277 wxASSERT( thisWindow
->GetPeer()->IsCompositing() == false ) ;
279 // this parameter is not provided on non-composited windows
282 // rest of the code expects this to be already transformed and clipped for local
283 CGrafPtr port
= GetWindowPort( (WindowRef
) thisWindow
->MacGetTopLevelWindowRef() ) ;
285 GetPortBounds( port
, &bounds
) ;
286 CreateCGContextForPort( port
, &cgContext
) ;
288 wxMacWindowToNative( thisWindow
, updateRgn
) ;
289 OffsetRgn( updateRgn
, controlBounds
.left
, controlBounds
.top
) ;
290 ClipCGContextToRegion( cgContext
, &bounds
, updateRgn
) ;
291 wxMacNativeToWindow( thisWindow
, updateRgn
) ;
292 OffsetRgn( updateRgn
, -controlBounds
.left
, -controlBounds
.top
) ;
294 CGContextTranslateCTM( cgContext
, 0 , bounds
.bottom
- bounds
.top
) ;
295 CGContextScaleCTM( cgContext
, 1 , -1 ) ;
297 CGContextTranslateCTM( cgContext
, controlBounds
.left
, controlBounds
.top
) ;
300 CGContextSetRGBFillColor( cgContext
, 1.0 , 1.0 , 1.0 , 1.0 ) ;
301 CGContextFillRect( cgContext
,
303 controlBounds
.right
- controlBounds
.left
,
304 controlBounds
.bottom
- controlBounds
.top
) );
308 thisWindow
->MacSetCGContextRef( cgContext
) ;
311 wxMacCGContextStateSaver
sg( cgContext
) ;
313 if ( thisWindow
->MacDoRedraw( updateRgn
, cEvent
.GetTicks() ) )
316 #if wxMAC_USE_CORE_GRAPHICS
317 thisWindow
->MacSetCGContextRef( NULL
) ;
321 CGContextRelease( cgContext
) ;
326 DisposeRgn( allocatedRgn
) ;
330 case kEventControlVisibilityChanged
:
331 thisWindow
->MacVisibilityChanged() ;
334 case kEventControlEnabledStateChanged
:
335 thisWindow
->MacEnabledStateChanged() ;
338 case kEventControlHiliteChanged
:
339 thisWindow
->MacHiliteChanged() ;
343 // we emulate this event under Carbon CFM
344 case kEventControlSetFocusPart
:
346 Boolean focusEverything
= false ;
347 ControlPartCode controlPart
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
);
350 if ( cEvent
.GetParameter
<Boolean
>(kEventParamControlFocusEverything
, &focusEverything
) == noErr
)
355 if ( controlPart
== kControlFocusNoPart
)
358 if ( thisWindow
->GetCaret() )
359 thisWindow
->GetCaret()->OnKillFocus();
362 static bool inKillFocusEvent
= false ;
364 if ( !inKillFocusEvent
)
366 inKillFocusEvent
= true ;
367 wxFocusEvent
event( wxEVT_KILL_FOCUS
, thisWindow
->GetId());
368 event
.SetEventObject(thisWindow
);
369 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
370 inKillFocusEvent
= false ;
375 // panel wants to track the window which was the last to have focus in it
376 wxChildFocusEvent
eventFocus(thisWindow
);
377 thisWindow
->GetEventHandler()->ProcessEvent(eventFocus
);
380 if ( thisWindow
->GetCaret() )
381 thisWindow
->GetCaret()->OnSetFocus();
384 wxFocusEvent
event(wxEVT_SET_FOCUS
, thisWindow
->GetId());
385 event
.SetEventObject(thisWindow
);
386 thisWindow
->GetEventHandler()->ProcessEvent(event
) ;
389 if ( thisWindow
->MacIsUserPane() )
394 case kEventControlHit
:
395 result
= thisWindow
->MacControlHit( handler
, event
) ;
405 static pascal OSStatus
wxMacWindowServiceEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
407 OSStatus result
= eventNotHandledErr
;
409 wxMacCarbonEvent
cEvent( event
) ;
411 ControlRef controlRef
;
412 wxWindowMac
* thisWindow
= (wxWindowMac
*) data
;
413 wxTextCtrl
* textCtrl
= wxDynamicCast( thisWindow
, wxTextCtrl
) ;
414 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
416 switch ( GetEventKind( event
) )
418 case kEventServiceGetTypes
:
422 textCtrl
->GetSelection( &from
, &to
) ;
424 CFMutableArrayRef copyTypes
= 0 , pasteTypes
= 0;
426 copyTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServiceCopyTypes
, typeCFMutableArrayRef
) ;
427 if ( textCtrl
->IsEditable() )
428 pasteTypes
= cEvent
.GetParameter
< CFMutableArrayRef
>( kEventParamServicePasteTypes
, typeCFMutableArrayRef
) ;
430 static const OSType textDataTypes
[] = { kTXNTextData
/* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
431 for ( size_t i
= 0 ; i
< WXSIZEOF(textDataTypes
) ; ++i
)
433 CFStringRef typestring
= CreateTypeStringWithOSType(textDataTypes
[i
]);
437 CFArrayAppendValue(copyTypes
, typestring
) ;
439 CFArrayAppendValue(pasteTypes
, typestring
) ;
441 CFRelease( typestring
) ;
449 case kEventServiceCopy
:
454 textCtrl
->GetSelection( &from
, &to
) ;
455 wxString val
= textCtrl
->GetValue() ;
456 val
= val
.Mid( from
, to
- from
) ;
457 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
458 verify_noerr( ClearScrap( &scrapRef
) ) ;
459 verify_noerr( PutScrapFlavor( scrapRef
, kTXNTextData
, 0 , val
.length() , val
.c_str() ) ) ;
464 case kEventServicePaste
:
467 ScrapRef scrapRef
= cEvent
.GetParameter
< ScrapRef
> ( kEventParamScrapRef
, typeScrapRef
) ;
468 Size textSize
, pastedSize
;
469 verify_noerr( GetScrapFlavorSize(scrapRef
, kTXNTextData
, &textSize
) ) ;
471 char *content
= new char[textSize
] ;
472 GetScrapFlavorData(scrapRef
, kTXNTextData
, &pastedSize
, content
);
473 content
[textSize
- 1] = 0 ;
476 textCtrl
->WriteText( wxString( content
, wxConvLocal
) );
478 textCtrl
->WriteText( wxString( content
) ) ;
493 pascal OSStatus
wxMacUnicodeTextEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
495 OSStatus result
= eventNotHandledErr
;
496 wxWindowMac
* focus
= (wxWindowMac
*) data
;
498 wchar_t* uniChars
= NULL
;
499 UInt32 when
= EventTimeToTicks( GetEventTime( event
) ) ;
501 UniChar
* charBuf
= NULL
;
502 UInt32 dataSize
= 0 ;
505 if ( GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, 0 , &dataSize
, NULL
) == noErr
)
507 numChars
= dataSize
/ sizeof( UniChar
) + 1;
510 if ( (size_t) numChars
* 2 > sizeof(buf
) )
511 charBuf
= new UniChar
[ numChars
] ;
515 uniChars
= new wchar_t[ numChars
] ;
516 GetEventParameter( event
, kEventParamTextInputSendText
, typeUnicodeText
, NULL
, dataSize
, NULL
, charBuf
) ;
517 charBuf
[ numChars
- 1 ] = 0;
518 #if SIZEOF_WCHAR_T == 2
519 uniChars
= (wchar_t*) charBuf
;
520 memcpy( uniChars
, charBuf
, numChars
* 2 ) ;
522 // the resulting string will never have more chars than the utf16 version, so this is safe
523 wxMBConvUTF16 converter
;
524 numChars
= converter
.MB2WC( uniChars
, (const char*)charBuf
, numChars
) ;
528 switch ( GetEventKind( event
) )
530 case kEventTextInputUpdateActiveInputArea
:
532 // An IME input event may return several characters, but we need to send one char at a time to
534 for (int pos
=0 ; pos
< numChars
; pos
++)
536 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
537 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
538 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
540 UInt32 message
= (0 << 8) + ((char)uniChars
[pos
] );
541 if ( wxTheApp
->MacSendCharEvent(
542 focus
, message
, 0 , when
, 0 , 0 , uniChars
[pos
] ) )
547 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
551 case kEventTextInputUnicodeForKeyEvent
:
553 UInt32 keyCode
, modifiers
;
556 unsigned char charCode
;
558 GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
, typeEventRef
, NULL
, sizeof(rawEvent
), NULL
, &rawEvent
) ;
559 GetEventParameter( rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(char), NULL
, &charCode
);
560 GetEventParameter( rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &keyCode
);
561 GetEventParameter( rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(UInt32
), NULL
, &modifiers
);
562 GetEventParameter( rawEvent
, kEventParamMouseLocation
, typeQDPoint
, NULL
, sizeof(Point
), NULL
, &point
);
564 UInt32 message
= (keyCode
<< 8) + charCode
;
566 // An IME input event may return several characters, but we need to send one char at a time to
568 for (int pos
=0 ; pos
< numChars
; pos
++)
570 WXEVENTREF formerEvent
= wxTheApp
->MacGetCurrentEvent() ;
571 WXEVENTHANDLERCALLREF formerHandler
= wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
572 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
574 if ( wxTheApp
->MacSendCharEvent(
575 focus
, message
, modifiers
, when
, point
.h
, point
.v
, uniChars
[pos
] ) )
580 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerHandler
) ;
589 if ( charBuf
!= buf
)
595 static pascal OSStatus
wxMacWindowCommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
597 OSStatus result
= eventNotHandledErr
;
598 wxWindowMac
* focus
= (wxWindowMac
*) data
;
602 wxMacCarbonEvent
cEvent( event
) ;
603 cEvent
.GetParameter
<HICommand
>(kEventParamDirectObject
,typeHICommand
,&command
) ;
605 wxMenuItem
* item
= NULL
;
606 wxMenu
* itemMenu
= wxFindMenuFromMacCommand( command
, item
) ;
607 int id
= wxMacCommandToId( command
.commandID
) ;
611 wxASSERT( itemMenu
!= NULL
) ;
613 switch ( cEvent
.GetKind() )
615 case kEventProcessCommand
:
617 if (item
->IsCheckable())
618 item
->Check( !item
->IsChecked() ) ;
620 if ( itemMenu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) )
624 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
625 event
.SetEventObject(focus
);
626 event
.SetInt(item
->IsCheckable() ? item
->IsChecked() : -1);
628 if ( focus
->GetEventHandler()->ProcessEvent(event
) )
634 case kEventCommandUpdateStatus
:
636 wxUpdateUIEvent
event(id
);
637 event
.SetEventObject( itemMenu
);
639 bool processed
= false;
641 // Try the menu's event handler
643 wxEvtHandler
*handler
= itemMenu
->GetEventHandler();
645 processed
= handler
->ProcessEvent(event
);
648 // Try the window the menu was popped up from
649 // (and up through the hierarchy)
652 const wxMenuBase
*menu
= itemMenu
;
655 wxWindow
*win
= menu
->GetInvokingWindow();
658 processed
= win
->GetEventHandler()->ProcessEvent(event
);
662 menu
= menu
->GetParent();
668 processed
= focus
->GetEventHandler()->ProcessEvent(event
);
673 // if anything changed, update the changed attribute
674 if (event
.GetSetText())
675 itemMenu
->SetLabel(id
, event
.GetText());
676 if (event
.GetSetChecked())
677 itemMenu
->Check(id
, event
.GetChecked());
678 if (event
.GetSetEnabled())
679 itemMenu
->Enable(id
, event
.GetEnabled());
693 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
695 EventRef formerEvent
= (EventRef
) wxTheApp
->MacGetCurrentEvent() ;
696 EventHandlerCallRef formerEventHandlerCallRef
= (EventHandlerCallRef
) wxTheApp
->MacGetCurrentEventHandlerCallRef() ;
697 wxTheApp
->MacSetCurrentEvent( event
, handler
) ;
698 OSStatus result
= eventNotHandledErr
;
700 switch ( GetEventClass( event
) )
702 case kEventClassCommand
:
703 result
= wxMacWindowCommandEventHandler( handler
, event
, data
) ;
706 case kEventClassControl
:
707 result
= wxMacWindowControlEventHandler( handler
, event
, data
) ;
710 case kEventClassService
:
711 result
= wxMacWindowServiceEventHandler( handler
, event
, data
) ;
714 case kEventClassTextInput
:
715 result
= wxMacUnicodeTextEventHandler( handler
, event
, data
) ;
722 wxTheApp
->MacSetCurrentEvent( formerEvent
, formerEventHandlerCallRef
) ;
727 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler
)
729 #if !TARGET_API_MAC_OSX
731 // ---------------------------------------------------------------------------
732 // UserPane events for non OSX builds
733 // ---------------------------------------------------------------------------
735 static pascal void wxMacControlUserPaneDrawProc(ControlRef control
, SInt16 part
)
737 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
739 win
->MacControlUserPaneDrawProc(part
) ;
741 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP
, wxMacControlUserPaneDrawProc
) ;
743 static pascal ControlPartCode
wxMacControlUserPaneHitTestProc(ControlRef control
, Point where
)
745 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
747 return win
->MacControlUserPaneHitTestProc(where
.h
, where
.v
) ;
749 return kControlNoPart
;
751 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP
, wxMacControlUserPaneHitTestProc
) ;
753 static pascal ControlPartCode
wxMacControlUserPaneTrackingProc(ControlRef control
, Point startPt
, ControlActionUPP actionProc
)
755 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
757 return win
->MacControlUserPaneTrackingProc( startPt
.h
, startPt
.v
, (void*) actionProc
) ;
759 return kControlNoPart
;
761 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP
, wxMacControlUserPaneTrackingProc
) ;
763 static pascal void wxMacControlUserPaneIdleProc(ControlRef control
)
765 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
767 win
->MacControlUserPaneIdleProc() ;
769 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP
, wxMacControlUserPaneIdleProc
) ;
771 static pascal ControlPartCode
wxMacControlUserPaneKeyDownProc(ControlRef control
, SInt16 keyCode
, SInt16 charCode
, SInt16 modifiers
)
773 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
775 return win
->MacControlUserPaneKeyDownProc(keyCode
,charCode
,modifiers
) ;
777 return kControlNoPart
;
779 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP
, wxMacControlUserPaneKeyDownProc
) ;
781 static pascal void wxMacControlUserPaneActivateProc(ControlRef control
, Boolean activating
)
783 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
785 win
->MacControlUserPaneActivateProc(activating
) ;
787 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP
, wxMacControlUserPaneActivateProc
) ;
789 static pascal ControlPartCode
wxMacControlUserPaneFocusProc(ControlRef control
, ControlFocusPart action
)
791 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
793 return win
->MacControlUserPaneFocusProc(action
) ;
795 return kControlNoPart
;
797 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP
, wxMacControlUserPaneFocusProc
) ;
799 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control
, ControlBackgroundPtr info
)
801 wxWindow
* win
= wxFindControlFromMacControl(control
) ;
803 win
->MacControlUserPaneBackgroundProc(info
) ;
805 wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP
, wxMacControlUserPaneBackgroundProc
) ;
807 void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part
)
810 RgnHandle rgn
= NewRgn() ;
812 MacWindowToRootWindow( &x
, &y
) ;
813 OffsetRgn( rgn
, -x
, -y
) ;
814 wxMacWindowStateSaver
sv( this ) ;
815 SectRgn( rgn
, (RgnHandle
) MacGetVisibleRegion().GetWXHRGN() , rgn
) ;
816 MacDoRedraw( rgn
, 0 ) ;
820 wxInt16
wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x
, wxInt16 y
)
822 return kControlNoPart
;
825 wxInt16
wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x
, wxInt16 y
, void* actionProc
)
827 return kControlNoPart
;
830 void wxWindowMac::MacControlUserPaneIdleProc()
834 wxInt16
wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode
, wxInt16 charCode
, wxInt16 modifiers
)
836 return kControlNoPart
;
839 void wxWindowMac::MacControlUserPaneActivateProc(bool activating
)
843 wxInt16
wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action
)
845 if ( AcceptsFocus() )
848 return kControlNoPart
;
851 void wxWindowMac::MacControlUserPaneBackgroundProc(void* info
)
857 // ---------------------------------------------------------------------------
858 // Scrollbar Tracking for all
859 // ---------------------------------------------------------------------------
861 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
) ;
862 pascal void wxMacLiveScrollbarActionProc( ControlRef control
, ControlPartCode partCode
)
866 wxWindow
* wx
= wxFindControlFromMacControl( control
) ;
868 wx
->MacHandleControlClick( (WXWidget
) control
, partCode
, true /* stillDown */ ) ;
871 wxMAC_DEFINE_PROC_GETTER( ControlActionUPP
, wxMacLiveScrollbarActionProc
) ;
873 // ===========================================================================
875 // ===========================================================================
877 WX_DECLARE_HASH_MAP(ControlRef
, wxWindow
*, wxPointerHash
, wxPointerEqual
, MacControlMap
);
879 static MacControlMap wxWinMacControlList
;
881 wxWindow
*wxFindControlFromMacControl(ControlRef inControl
)
883 MacControlMap::iterator node
= wxWinMacControlList
.find(inControl
);
885 return (node
== wxWinMacControlList
.end()) ? NULL
: node
->second
;
888 void wxAssociateControlWithMacControl(ControlRef inControl
, wxWindow
*control
)
890 // adding NULL ControlRef is (first) surely a result of an error and
891 // (secondly) breaks native event processing
892 wxCHECK_RET( inControl
!= (ControlRef
) NULL
, wxT("attempt to add a NULL WindowRef to window list") );
894 wxWinMacControlList
[inControl
] = control
;
897 void wxRemoveMacControlAssociation(wxWindow
*control
)
899 // iterate over all the elements in the class
900 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
901 // we should go on...
907 MacControlMap::iterator it
;
908 for ( it
= wxWinMacControlList
.begin(); it
!= wxWinMacControlList
.end(); ++it
)
910 if ( it
->second
== control
)
912 wxWinMacControlList
.erase(it
);
920 // ----------------------------------------------------------------------------
921 // constructors and such
922 // ----------------------------------------------------------------------------
924 wxWindowMac::wxWindowMac()
929 wxWindowMac::wxWindowMac(wxWindowMac
*parent
,
934 const wxString
& name
)
937 Create(parent
, id
, pos
, size
, style
, name
);
940 void wxWindowMac::Init()
945 #if WXWIN_COMPATIBILITY_2_4
946 m_backgroundTransparent
= false;
949 #if wxMAC_USE_CORE_GRAPHICS
950 m_cgContextRef
= NULL
;
953 // as all windows are created with WS_VISIBLE style...
956 m_hScrollBar
= NULL
;
957 m_vScrollBar
= NULL
;
958 m_macBackgroundBrush
= wxNullBrush
;
960 m_macIsUserPane
= true;
961 m_clipChildren
= false ;
962 m_cachedClippedRectValid
= false ;
964 // we need a valid font for the encodings
965 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
968 wxWindowMac::~wxWindowMac()
972 m_isBeingDeleted
= true;
974 MacInvalidateBorders() ;
976 #ifndef __WXUNIVERSAL__
977 // VS: make sure there's no wxFrame with last focus set to us:
978 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
980 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
983 if ( frame
->GetLastFocus() == this )
984 frame
->SetLastFocus((wxWindow
*)NULL
);
990 // destroy children before destroying this window itself
993 // wxRemoveMacControlAssociation( this ) ;
994 // If we delete an item, we should initialize the parent panel,
995 // because it could now be invalid.
996 wxWindow
*parent
= GetParent() ;
999 if (parent
->GetDefaultItem() == (wxButton
*) this)
1000 parent
->SetDefaultItem(NULL
);
1003 if ( m_peer
&& m_peer
->Ok() )
1005 // in case the callback might be called during destruction
1006 wxRemoveMacControlAssociation( this) ;
1007 ::RemoveEventHandler( (EventHandlerRef
) m_macControlEventHandler
) ;
1008 // we currently are not using this hook
1009 // ::SetControlColorProc( *m_peer , NULL ) ;
1013 if ( g_MacLastWindow
== this )
1014 g_MacLastWindow
= NULL
;
1016 wxFrame
* frame
= wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame
) ;
1019 if ( frame
->GetLastFocus() == this )
1020 frame
->SetLastFocus( NULL
) ;
1023 // delete our drop target if we've got one
1024 #if wxUSE_DRAG_AND_DROP
1025 if ( m_dropTarget
!= NULL
)
1027 delete m_dropTarget
;
1028 m_dropTarget
= NULL
;
1035 WXWidget
wxWindowMac::GetHandle() const
1037 return (WXWidget
) m_peer
->GetControlRef() ;
1040 void wxWindowMac::MacInstallEventHandler( WXWidget control
)
1042 wxAssociateControlWithMacControl( (ControlRef
) control
, this ) ;
1043 InstallControlEventHandler( (ControlRef
)control
, GetwxMacWindowEventHandlerUPP(),
1044 GetEventTypeCount(eventList
), eventList
, this,
1045 (EventHandlerRef
*)&m_macControlEventHandler
);
1047 #if !TARGET_API_MAC_OSX
1048 if ( (ControlRef
) control
== m_peer
->GetControlRef() )
1050 m_peer
->SetData
<ControlUserPaneDrawUPP
>(kControlEntireControl
, kControlUserPaneDrawProcTag
, GetwxMacControlUserPaneDrawProc()) ;
1051 m_peer
->SetData
<ControlUserPaneHitTestUPP
>(kControlEntireControl
, kControlUserPaneHitTestProcTag
, GetwxMacControlUserPaneHitTestProc()) ;
1052 m_peer
->SetData
<ControlUserPaneTrackingUPP
>(kControlEntireControl
, kControlUserPaneTrackingProcTag
, GetwxMacControlUserPaneTrackingProc()) ;
1053 m_peer
->SetData
<ControlUserPaneIdleUPP
>(kControlEntireControl
, kControlUserPaneIdleProcTag
, GetwxMacControlUserPaneIdleProc()) ;
1054 m_peer
->SetData
<ControlUserPaneKeyDownUPP
>(kControlEntireControl
, kControlUserPaneKeyDownProcTag
, GetwxMacControlUserPaneKeyDownProc()) ;
1055 m_peer
->SetData
<ControlUserPaneActivateUPP
>(kControlEntireControl
, kControlUserPaneActivateProcTag
, GetwxMacControlUserPaneActivateProc()) ;
1056 m_peer
->SetData
<ControlUserPaneFocusUPP
>(kControlEntireControl
, kControlUserPaneFocusProcTag
, GetwxMacControlUserPaneFocusProc()) ;
1057 m_peer
->SetData
<ControlUserPaneBackgroundUPP
>(kControlEntireControl
, kControlUserPaneBackgroundProcTag
, GetwxMacControlUserPaneBackgroundProc()) ;
1063 bool wxWindowMac::Create(wxWindowMac
*parent
,
1068 const wxString
& name
)
1070 wxCHECK_MSG( parent
, false, wxT("can't create wxWindowMac without parent") );
1072 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
1075 m_windowVariant
= parent
->GetWindowVariant() ;
1077 if ( m_macIsUserPane
)
1079 Rect bounds
= wxMacGetBoundsForControl( this , pos
, size
) ;
1082 | kControlSupportsEmbedding
1083 | kControlSupportsLiveFeedback
1084 | kControlGetsFocusOnClick
1085 // | kControlHasSpecialBackground
1086 // | kControlSupportsCalcBestRect
1087 | kControlHandlesTracking
1088 | kControlSupportsFocus
1089 | kControlWantsActivate
1090 | kControlWantsIdle
;
1092 m_peer
= new wxMacControl(this) ;
1093 OSStatus err
=::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds
, features
, m_peer
->GetControlRefAddr() );
1094 verify_noerr( err
);
1096 MacPostControlCreate(pos
, size
) ;
1099 #ifndef __WXUNIVERSAL__
1100 // Don't give scrollbars to wxControls unless they ask for them
1101 if ( (! IsKindOf(CLASSINFO(wxControl
)) && ! IsKindOf(CLASSINFO(wxStatusBar
)))
1102 || (IsKindOf(CLASSINFO(wxControl
)) && ((style
& wxHSCROLL
) || (style
& wxVSCROLL
))))
1104 MacCreateScrollBars( style
) ;
1108 wxWindowCreateEvent
event(this);
1109 GetEventHandler()->AddPendingEvent(event
);
1114 void wxWindowMac::MacChildAdded()
1117 m_vScrollBar
->Raise() ;
1119 m_hScrollBar
->Raise() ;
1122 void wxWindowMac::MacPostControlCreate(const wxPoint
& pos
, const wxSize
& size
)
1124 wxASSERT_MSG( m_peer
!= NULL
&& m_peer
->Ok() , wxT("No valid mac control") ) ;
1126 m_peer
->SetReference( (long)this ) ;
1127 GetParent()->AddChild( this );
1129 MacInstallEventHandler( (WXWidget
) m_peer
->GetControlRef() );
1131 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
1132 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
1133 ::EmbedControl( m_peer
->GetControlRef() , container
) ;
1134 GetParent()->MacChildAdded() ;
1136 // adjust font, controlsize etc
1137 DoSetWindowVariant( m_windowVariant
) ;
1139 m_peer
->SetLabel( wxStripMenuCodes(m_label
) ) ;
1141 if (!m_macIsUserPane
)
1142 SetInitialBestSize(size
);
1144 SetCursor( *wxSTANDARD_CURSOR
) ;
1147 void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant
)
1149 // Don't assert, in case we set the window variant before
1150 // the window is created
1151 // wxASSERT( m_peer->Ok() ) ;
1153 m_windowVariant
= variant
;
1155 if (m_peer
== NULL
|| !m_peer
->Ok())
1159 ThemeFontID themeFont
= kThemeSystemFont
;
1161 // we will get that from the settings later
1162 // and make this NORMAL later, but first
1163 // we have a few calculations that we must fix
1167 case wxWINDOW_VARIANT_NORMAL
:
1168 size
= kControlSizeNormal
;
1169 themeFont
= kThemeSystemFont
;
1172 case wxWINDOW_VARIANT_SMALL
:
1173 size
= kControlSizeSmall
;
1174 themeFont
= kThemeSmallSystemFont
;
1177 case wxWINDOW_VARIANT_MINI
:
1178 if (UMAGetSystemVersion() >= 0x1030 )
1180 // not always defined in the headers
1186 size
= kControlSizeSmall
;
1187 themeFont
= kThemeSmallSystemFont
;
1191 case wxWINDOW_VARIANT_LARGE
:
1192 size
= kControlSizeLarge
;
1193 themeFont
= kThemeSystemFont
;
1197 wxFAIL_MSG(_T("unexpected window variant"));
1201 m_peer
->SetData
<ControlSize
>(kControlEntireControl
, kControlSizeTag
, &size
) ;
1204 font
.MacCreateThemeFont( themeFont
) ;
1208 void wxWindowMac::MacUpdateControlFont()
1210 m_peer
->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1214 bool wxWindowMac::SetFont(const wxFont
& font
)
1216 bool retval
= wxWindowBase::SetFont( font
);
1218 MacUpdateControlFont() ;
1223 bool wxWindowMac::SetForegroundColour(const wxColour
& col
)
1225 bool retval
= wxWindowBase::SetForegroundColour( col
);
1228 MacUpdateControlFont();
1233 bool wxWindowMac::SetBackgroundColour(const wxColour
& col
)
1235 if ( !wxWindowBase::SetBackgroundColour(col
) && m_hasBgCol
)
1239 wxColour
newCol(GetBackgroundColour());
1241 if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE
) )
1242 brush
.MacSetTheme( kThemeBrushDocumentWindowBackground
) ;
1243 else if ( newCol
== wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE
) )
1244 brush
.MacSetTheme( kThemeBrushDialogBackgroundActive
) ;
1246 brush
.SetColour( newCol
) ;
1248 MacSetBackgroundBrush( brush
) ;
1249 MacUpdateControlFont() ;
1254 void wxWindowMac::MacSetBackgroundBrush( const wxBrush
&brush
)
1256 m_macBackgroundBrush
= brush
;
1257 m_peer
->SetBackground( brush
) ;
1260 bool wxWindowMac::MacCanFocus() const
1262 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1263 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1264 // but the value range is nowhere documented
1265 Boolean keyExistsAndHasValidFormat
;
1266 CFIndex fullKeyboardAccess
= CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1267 kCFPreferencesCurrentApplication
, &keyExistsAndHasValidFormat
);
1269 if ( keyExistsAndHasValidFormat
&& fullKeyboardAccess
> 0 )
1275 UInt32 features
= 0 ;
1276 m_peer
->GetFeatures( &features
) ;
1278 return features
& ( kControlSupportsFocus
| kControlGetsFocusOnClick
) ;
1282 void wxWindowMac::SetFocus()
1284 if ( !AcceptsFocus() )
1287 wxWindow
* former
= FindFocus() ;
1288 if ( former
== this )
1291 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1292 // we can only leave in case of an error
1293 OSStatus err
= m_peer
->SetFocus( kControlFocusNextPart
) ;
1294 if ( err
== errCouldntSetFocus
)
1297 SetUserFocusWindow( (WindowRef
)MacGetTopLevelWindowRef() );
1299 #if !TARGET_API_MAC_OSX
1300 // emulate carbon events when running under CarbonLib where they are not natively available
1303 EventRef evRef
= NULL
;
1305 err
= MacCreateEvent(
1306 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1307 kEventAttributeUserEvent
, &evRef
);
1308 verify_noerr( err
);
1310 wxMacCarbonEvent
cEvent( evRef
) ;
1311 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) former
->GetHandle() ) ;
1312 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNoPart
) ;
1314 wxMacWindowEventHandler( NULL
, evRef
, former
) ;
1315 ReleaseEvent( evRef
) ;
1318 // send new focus event
1320 EventRef evRef
= NULL
;
1322 err
= MacCreateEvent(
1323 NULL
, kEventClassControl
, kEventControlSetFocusPart
, TicksToEventTime( TickCount() ) ,
1324 kEventAttributeUserEvent
, &evRef
);
1325 verify_noerr( err
);
1327 wxMacCarbonEvent
cEvent( evRef
) ;
1328 cEvent
.SetParameter
<ControlRef
>( kEventParamDirectObject
, (ControlRef
) GetHandle() ) ;
1329 cEvent
.SetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
, kControlFocusNextPart
) ;
1331 wxMacWindowEventHandler( NULL
, evRef
, this ) ;
1332 ReleaseEvent( evRef
) ;
1337 void wxWindowMac::DoCaptureMouse()
1339 wxApp::s_captureWindow
= this ;
1342 wxWindow
* wxWindowBase::GetCapture()
1344 return wxApp::s_captureWindow
;
1347 void wxWindowMac::DoReleaseMouse()
1349 wxApp::s_captureWindow
= NULL
;
1352 #if wxUSE_DRAG_AND_DROP
1354 void wxWindowMac::SetDropTarget(wxDropTarget
*pDropTarget
)
1356 if ( m_dropTarget
!= NULL
)
1357 delete m_dropTarget
;
1359 m_dropTarget
= pDropTarget
;
1360 if ( m_dropTarget
!= NULL
)
1368 // Old-style File Manager Drag & Drop
1369 void wxWindowMac::DragAcceptFiles(bool accept
)
1374 // Returns the size of the native control. In the case of the toplevel window
1375 // this is the content area root control
1377 void wxWindowMac::MacGetPositionAndSizeFromControl(int& x
, int& y
,
1378 int& w
, int& h
) const
1380 wxFAIL_MSG( wxT("Not currently supported") ) ;
1383 // From a wx position / size calculate the appropriate size of the native control
1385 bool wxWindowMac::MacGetBoundsForControl(
1389 int& w
, int& h
, bool adjustOrigin
) const
1391 // the desired size, minus the border pixels gives the correct size of the control
1395 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1396 w
= wxMax(size
.x
, 0) ; // WidthDefault( size.x );
1397 h
= wxMax(size
.y
, 0) ; // HeightDefault( size.y ) ;
1399 bool isCompositing
= MacGetTopLevelWindow()->MacUsesCompositing() ;
1400 if ( !isCompositing
)
1401 GetParent()->MacWindowToRootWindow( &x
, &y
) ;
1403 x
+= MacGetLeftBorderSize() ;
1404 y
+= MacGetTopBorderSize() ;
1405 w
-= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1406 h
-= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1409 AdjustForParentClientOrigin( x
, y
) ;
1411 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1412 if ( !GetParent()->IsTopLevel() )
1414 x
-= GetParent()->MacGetLeftBorderSize() ;
1415 y
-= GetParent()->MacGetTopBorderSize() ;
1421 // Get window size (not client size)
1422 void wxWindowMac::DoGetSize(int *x
, int *y
) const
1425 m_peer
->GetRect( &bounds
) ;
1428 *x
= bounds
.right
- bounds
.left
+ MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1430 *y
= bounds
.bottom
- bounds
.top
+ MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1433 // get the position of the bounds of this window in client coordinates of its parent
1434 void wxWindowMac::DoGetPosition(int *x
, int *y
) const
1437 m_peer
->GetRect( &bounds
) ;
1439 int x1
= bounds
.left
;
1440 int y1
= bounds
.top
;
1442 // get the wx window position from the native one
1443 x1
-= MacGetLeftBorderSize() ;
1444 y1
-= MacGetTopBorderSize() ;
1446 if ( !IsTopLevel() )
1448 wxWindow
*parent
= GetParent();
1451 // we must first adjust it to be in window coordinates of the parent,
1452 // as otherwise it gets lost by the ClientAreaOrigin fix
1453 x1
+= parent
->MacGetLeftBorderSize() ;
1454 y1
+= parent
->MacGetTopBorderSize() ;
1456 // and now to client coordinates
1457 wxPoint
pt(parent
->GetClientAreaOrigin());
1469 void wxWindowMac::DoScreenToClient(int *x
, int *y
) const
1471 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1472 wxCHECK_RET( window
, wxT("TopLevel Window missing") ) ;
1474 Point localwhere
= { 0, 0 } ;
1481 QDGlobalToLocalPoint( GetWindowPort( window
) , &localwhere
) ;
1488 MacRootWindowToWindow( x
, y
) ;
1490 wxPoint origin
= GetClientAreaOrigin() ;
1497 void wxWindowMac::DoClientToScreen(int *x
, int *y
) const
1499 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
1500 wxCHECK_RET( window
, wxT("TopLevel window missing") ) ;
1502 wxPoint origin
= GetClientAreaOrigin() ;
1508 MacWindowToRootWindow( x
, y
) ;
1510 Point localwhere
= { 0, 0 };
1516 QDLocalToGlobalPoint( GetWindowPort( window
) , &localwhere
) ;
1524 void wxWindowMac::MacClientToRootWindow( int *x
, int *y
) const
1526 wxPoint origin
= GetClientAreaOrigin() ;
1532 MacWindowToRootWindow( x
, y
) ;
1535 void wxWindowMac::MacRootWindowToClient( int *x
, int *y
) const
1537 MacRootWindowToWindow( x
, y
) ;
1539 wxPoint origin
= GetClientAreaOrigin() ;
1546 void wxWindowMac::MacWindowToRootWindow( int *x
, int *y
) const
1555 if ( !IsTopLevel() )
1557 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1560 pt
.x
-= MacGetLeftBorderSize() ;
1561 pt
.y
-= MacGetTopBorderSize() ;
1562 wxMacControl::Convert( &pt
, m_peer
, top
->m_peer
) ;
1572 void wxWindowMac::MacWindowToRootWindow( short *x
, short *y
) const
1581 MacWindowToRootWindow( &x1
, &y1
) ;
1589 void wxWindowMac::MacRootWindowToWindow( int *x
, int *y
) const
1598 if ( !IsTopLevel() )
1600 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
1603 wxMacControl::Convert( &pt
, top
->m_peer
, m_peer
) ;
1604 pt
.x
+= MacGetLeftBorderSize() ;
1605 pt
.y
+= MacGetTopBorderSize() ;
1615 void wxWindowMac::MacRootWindowToWindow( short *x
, short *y
) const
1624 MacRootWindowToWindow( &x1
, &y1
) ;
1632 void wxWindowMac::MacGetContentAreaInset( int &left
, int &top
, int &right
, int &bottom
)
1634 RgnHandle rgn
= NewRgn() ;
1636 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1638 Rect structure
, content
;
1640 GetRegionBounds( rgn
, &content
) ;
1641 m_peer
->GetRect( &structure
) ;
1642 OffsetRect( &structure
, -structure
.left
, -structure
.top
) ;
1644 left
= content
.left
- structure
.left
;
1645 top
= content
.top
- structure
.top
;
1646 right
= structure
.right
- content
.right
;
1647 bottom
= structure
.bottom
- content
.bottom
;
1651 left
= top
= right
= bottom
= 0 ;
1657 wxSize
wxWindowMac::DoGetSizeFromClientSize( const wxSize
& size
) const
1659 wxSize sizeTotal
= size
;
1661 RgnHandle rgn
= NewRgn() ;
1662 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1664 Rect content
, structure
;
1665 GetRegionBounds( rgn
, &content
) ;
1666 m_peer
->GetRect( &structure
) ;
1668 // structure is in parent coordinates, but we only need width and height, so it's ok
1670 sizeTotal
.x
+= (structure
.right
- structure
.left
) - (content
.right
- content
.left
) ;
1671 sizeTotal
.y
+= (structure
.bottom
- structure
.top
) - (content
.bottom
- content
.top
) ;
1676 sizeTotal
.x
+= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1677 sizeTotal
.y
+= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1682 // Get size *available for subwindows* i.e. excluding menu bar etc.
1683 void wxWindowMac::DoGetClientSize( int *x
, int *y
) const
1687 RgnHandle rgn
= NewRgn() ;
1689 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
1690 GetRegionBounds( rgn
, &content
) ;
1692 m_peer
->GetRect( &content
) ;
1695 ww
= content
.right
- content
.left
;
1696 hh
= content
.bottom
- content
.top
;
1698 if (m_hScrollBar
&& m_hScrollBar
->IsShown() )
1699 hh
-= m_hScrollBar
->GetSize().y
;
1701 if (m_vScrollBar
&& m_vScrollBar
->IsShown() )
1702 ww
-= m_vScrollBar
->GetSize().x
;
1710 bool wxWindowMac::SetCursor(const wxCursor
& cursor
)
1712 if (m_cursor
== cursor
)
1715 if (wxNullCursor
== cursor
)
1717 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR
) )
1722 if ( ! wxWindowBase::SetCursor( cursor
) )
1726 wxASSERT_MSG( m_cursor
.Ok(),
1727 wxT("cursor must be valid after call to the base version"));
1729 wxWindowMac
*mouseWin
= 0 ;
1731 wxTopLevelWindowMac
*tlw
= MacGetTopLevelWindow() ;
1732 WindowRef window
= (WindowRef
) ( tlw
? tlw
->MacGetWindowRef() : 0 ) ;
1734 Boolean swapped
= QDSwapPort( GetWindowPort( window
) , &savePort
) ;
1736 // TODO: If we ever get a GetCurrentEvent... replacement
1737 // for the mouse position, use it...
1740 ControlPartCode part
;
1741 ControlRef control
;
1744 control
= wxMacFindControlUnderMouse( tlw
, pt
, window
, &part
) ;
1746 mouseWin
= wxFindControlFromMacControl( control
) ;
1749 QDSwapPort( savePort
, NULL
) ;
1752 if ( mouseWin
== this && !wxIsBusy() )
1753 m_cursor
.MacInstall() ;
1759 bool wxWindowMac::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1761 menu
->SetInvokingWindow(this);
1764 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1766 wxPoint mouse
= wxGetMousePosition();
1772 ClientToScreen( &x
, &y
) ;
1775 menu
->MacBeforeDisplay( true ) ;
1776 long menuResult
= ::PopUpMenuSelect((MenuHandle
) menu
->GetHMenu() , y
, x
, 0) ;
1777 if ( HiWord(menuResult
) != 0 )
1780 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult
)) , LoWord(menuResult
) , &macid
);
1781 int id
= wxMacCommandToId( macid
);
1782 wxMenuItem
* item
= NULL
;
1784 item
= menu
->FindItem( id
, &realmenu
) ;
1787 if (item
->IsCheckable())
1788 item
->Check( !item
->IsChecked() ) ;
1790 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
1794 menu
->MacAfterDisplay( true ) ;
1795 menu
->SetInvokingWindow( NULL
);
1801 // ----------------------------------------------------------------------------
1803 // ----------------------------------------------------------------------------
1807 void wxWindowMac::DoSetToolTip(wxToolTip
*tooltip
)
1809 wxWindowBase::DoSetToolTip(tooltip
);
1812 m_tooltip
->SetWindow(this);
1817 void wxWindowMac::MacInvalidateBorders()
1819 if ( m_peer
== NULL
)
1822 bool vis
= MacIsReallyShown() ;
1826 int outerBorder
= MacGetLeftBorderSize() ;
1827 if ( m_peer
->NeedsFocusRect() && m_peer
->HasFocus() )
1830 if ( outerBorder
== 0 )
1833 // now we know that we have something to do at all
1835 // as the borders are drawn on the parent we have to properly invalidate all these areas
1836 RgnHandle updateInner
, updateOuter
;
1839 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1840 updateInner
= NewRgn() ;
1841 updateOuter
= NewRgn() ;
1843 m_peer
->GetRect( &rect
) ;
1844 RectRgn( updateInner
, &rect
) ;
1845 InsetRect( &rect
, -outerBorder
, -outerBorder
) ;
1846 RectRgn( updateOuter
, &rect
) ;
1847 DiffRgn( updateOuter
, updateInner
, updateOuter
) ;
1849 #ifdef __WXMAC_OSX__
1850 GetParent()->m_peer
->SetNeedsDisplay( updateOuter
) ;
1852 WindowRef tlw
= (WindowRef
) MacGetTopLevelWindowRef() ;
1854 InvalWindowRgn( tlw
, updateOuter
) ;
1857 DisposeRgn( updateOuter
) ;
1858 DisposeRgn( updateInner
) ;
1861 void wxWindowMac::DoMoveWindow(int x
, int y
, int width
, int height
)
1863 // this is never called for a toplevel window, so we know we have a parent
1864 int former_x
, former_y
, former_w
, former_h
;
1866 // Get true coordinates of former position
1867 DoGetPosition( &former_x
, &former_y
) ;
1868 DoGetSize( &former_w
, &former_h
) ;
1870 wxWindow
*parent
= GetParent();
1873 wxPoint
pt(parent
->GetClientAreaOrigin());
1878 int actualWidth
= width
;
1879 int actualHeight
= height
;
1883 if ((m_minWidth
!= -1) && (actualWidth
< m_minWidth
))
1884 actualWidth
= m_minWidth
;
1885 if ((m_minHeight
!= -1) && (actualHeight
< m_minHeight
))
1886 actualHeight
= m_minHeight
;
1887 if ((m_maxWidth
!= -1) && (actualWidth
> m_maxWidth
))
1888 actualWidth
= m_maxWidth
;
1889 if ((m_maxHeight
!= -1) && (actualHeight
> m_maxHeight
))
1890 actualHeight
= m_maxHeight
;
1892 bool doMove
= false, doResize
= false ;
1894 if ( actualX
!= former_x
|| actualY
!= former_y
)
1897 if ( actualWidth
!= former_w
|| actualHeight
!= former_h
)
1900 if ( doMove
|| doResize
)
1902 // as the borders are drawn outside the native control, we adjust now
1904 wxRect
bounds( wxPoint( actualX
+ MacGetLeftBorderSize() ,actualY
+ MacGetTopBorderSize() ),
1905 wxSize( actualWidth
- (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1906 actualHeight
- (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1909 wxMacRectToNative( &bounds
, &r
) ;
1911 if ( !GetParent()->IsTopLevel() )
1912 wxMacWindowToNative( GetParent() , &r
) ;
1914 MacInvalidateBorders() ;
1916 m_cachedClippedRectValid
= false ;
1917 m_peer
->SetRect( &r
) ;
1919 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1921 MacInvalidateBorders() ;
1923 MacRepositionScrollBars() ;
1926 wxPoint
point(actualX
, actualY
);
1927 wxMoveEvent
event(point
, m_windowId
);
1928 event
.SetEventObject(this);
1929 GetEventHandler()->ProcessEvent(event
) ;
1934 MacRepositionScrollBars() ;
1935 wxSize
size(actualWidth
, actualHeight
);
1936 wxSizeEvent
event(size
, m_windowId
);
1937 event
.SetEventObject(this);
1938 GetEventHandler()->ProcessEvent(event
);
1943 wxSize
wxWindowMac::DoGetBestSize() const
1945 if ( m_macIsUserPane
|| IsTopLevel() )
1946 return wxWindowBase::DoGetBestSize() ;
1948 Rect bestsize
= { 0 , 0 , 0 , 0 } ;
1949 int bestWidth
, bestHeight
;
1951 m_peer
->GetBestRect( &bestsize
) ;
1952 if ( EmptyRect( &bestsize
) )
1957 bestsize
.bottom
= 16 ;
1959 if ( IsKindOf( CLASSINFO( wxScrollBar
) ) )
1961 bestsize
.bottom
= 16 ;
1964 else if ( IsKindOf( CLASSINFO( wxSpinButton
) ) )
1966 bestsize
.bottom
= 24 ;
1971 // return wxWindowBase::DoGetBestSize() ;
1975 bestWidth
= bestsize
.right
- bestsize
.left
;
1976 bestHeight
= bestsize
.bottom
- bestsize
.top
;
1977 if ( bestHeight
< 10 )
1980 return wxSize(bestWidth
, bestHeight
);
1983 // set the size of the window: if the dimensions are positive, just use them,
1984 // but if any of them is equal to -1, it means that we must find the value for
1985 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1986 // which case -1 is a valid value for x and y)
1988 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1989 // the width/height to best suit our contents, otherwise we reuse the current
1991 void wxWindowMac::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1993 // get the current size and position...
1994 int currentX
, currentY
;
1995 int currentW
, currentH
;
1997 GetPosition(¤tX
, ¤tY
);
1998 GetSize(¤tW
, ¤tH
);
2000 // ... and don't do anything (avoiding flicker) if it's already ok
2001 if ( x
== currentX
&& y
== currentY
&&
2002 width
== currentW
&& height
== currentH
&& ( height
!= -1 && width
!= -1 ) )
2005 MacRepositionScrollBars() ; // we might have a real position shift
2010 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2012 if ( x
== wxDefaultCoord
)
2014 if ( y
== wxDefaultCoord
)
2018 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
2020 wxSize size
= wxDefaultSize
;
2021 if ( width
== wxDefaultCoord
)
2023 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2025 size
= DoGetBestSize();
2030 // just take the current one
2035 if ( height
== wxDefaultCoord
)
2037 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2039 if ( size
.x
== wxDefaultCoord
)
2040 size
= DoGetBestSize();
2041 // else: already called DoGetBestSize() above
2047 // just take the current one
2052 DoMoveWindow( x
, y
, width
, height
);
2055 wxPoint
wxWindowMac::GetClientAreaOrigin() const
2057 RgnHandle rgn
= NewRgn() ;
2059 if ( m_peer
->GetRegion( kControlContentMetaPart
, rgn
) == noErr
)
2061 GetRegionBounds( rgn
, &content
) ;
2071 return wxPoint( content
.left
+ MacGetLeftBorderSize() , content
.top
+ MacGetTopBorderSize() );
2074 void wxWindowMac::DoSetClientSize(int clientwidth
, int clientheight
)
2076 if ( clientheight
!= wxDefaultCoord
|| clientheight
!= wxDefaultCoord
)
2078 int currentclientwidth
, currentclientheight
;
2079 int currentwidth
, currentheight
;
2081 GetClientSize( ¤tclientwidth
, ¤tclientheight
) ;
2082 GetSize( ¤twidth
, ¤theight
) ;
2084 DoSetSize( wxDefaultCoord
, wxDefaultCoord
, currentwidth
+ clientwidth
- currentclientwidth
,
2085 currentheight
+ clientheight
- currentclientheight
, wxSIZE_USE_EXISTING
) ;
2089 void wxWindowMac::SetLabel(const wxString
& title
)
2091 m_label
= wxStripMenuCodes(title
) ;
2093 if ( m_peer
&& m_peer
->Ok() )
2094 m_peer
->SetLabel( m_label
) ;
2099 wxString
wxWindowMac::GetLabel() const
2104 bool wxWindowMac::Show(bool show
)
2106 bool former
= MacIsReallyShown() ;
2107 if ( !wxWindowBase::Show(show
) )
2110 // TODO: use visibilityChanged Carbon Event for OSX
2112 m_peer
->SetVisibility( show
, true ) ;
2114 if ( former
!= MacIsReallyShown() )
2115 MacPropagateVisibilityChanged() ;
2120 bool wxWindowMac::Enable(bool enable
)
2122 wxASSERT( m_peer
->Ok() ) ;
2123 bool former
= MacIsReallyEnabled() ;
2124 if ( !wxWindowBase::Enable(enable
) )
2127 m_peer
->Enable( enable
) ;
2129 if ( former
!= MacIsReallyEnabled() )
2130 MacPropagateEnabledStateChanged() ;
2136 // status change propagations (will be not necessary for OSX later )
2139 void wxWindowMac::MacPropagateVisibilityChanged()
2141 #if !TARGET_API_MAC_OSX
2142 MacVisibilityChanged() ;
2145 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2148 child
= node
->GetData();
2149 if ( child
->IsShown() )
2150 child
->MacPropagateVisibilityChanged() ;
2152 node
= node
->GetNext();
2157 void wxWindowMac::MacPropagateEnabledStateChanged()
2159 #if !TARGET_API_MAC_OSX
2160 MacEnabledStateChanged() ;
2163 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2166 child
= node
->GetData();
2167 if ( child
->IsEnabled() )
2168 child
->MacPropagateEnabledStateChanged() ;
2170 node
= node
->GetNext();
2175 void wxWindowMac::MacPropagateHiliteChanged()
2177 #if !TARGET_API_MAC_OSX
2178 MacHiliteChanged() ;
2181 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2184 child
= node
->GetData();
2185 if (child
/* && child->IsEnabled() */)
2186 child
->MacPropagateHiliteChanged() ;
2188 node
= node
->GetNext();
2194 // status change notifications
2197 void wxWindowMac::MacVisibilityChanged()
2201 void wxWindowMac::MacHiliteChanged()
2205 void wxWindowMac::MacEnabledStateChanged()
2210 // status queries on the inherited window's state
2213 bool wxWindowMac::MacIsReallyShown()
2215 // only under OSX the visibility of the TLW is taken into account
2216 if ( m_isBeingDeleted
)
2219 #if TARGET_API_MAC_OSX
2220 if ( m_peer
&& m_peer
->Ok() )
2221 return m_peer
->IsVisible();
2224 wxWindow
* win
= this ;
2225 while ( win
->IsShown() )
2227 if ( win
->IsTopLevel() )
2230 win
= win
->GetParent() ;
2238 bool wxWindowMac::MacIsReallyEnabled()
2240 return m_peer
->IsEnabled() ;
2243 bool wxWindowMac::MacIsReallyHilited()
2245 return m_peer
->IsActive();
2248 void wxWindowMac::MacFlashInvalidAreas()
2250 #if TARGET_API_MAC_OSX
2251 HIViewFlashDirtyArea( (WindowRef
) MacGetTopLevelWindowRef() ) ;
2255 int wxWindowMac::GetCharHeight() const
2257 wxClientDC
dc( (wxWindowMac
*)this ) ;
2259 return dc
.GetCharHeight() ;
2262 int wxWindowMac::GetCharWidth() const
2264 wxClientDC
dc( (wxWindowMac
*)this ) ;
2266 return dc
.GetCharWidth() ;
2269 void wxWindowMac::GetTextExtent(const wxString
& string
, int *x
, int *y
,
2270 int *descent
, int *externalLeading
, const wxFont
*theFont
) const
2272 const wxFont
*fontToUse
= theFont
;
2274 fontToUse
= &m_font
;
2276 wxClientDC
dc( (wxWindowMac
*) this ) ;
2278 dc
.GetTextExtent( string
, &lx
, &ly
, &ld
, &le
, (wxFont
*)fontToUse
) ;
2279 if ( externalLeading
)
2280 *externalLeading
= le
;
2290 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2291 * we always intersect with the entire window, not only with the client area
2294 void wxWindowMac::Refresh(bool eraseBack
, const wxRect
*rect
)
2296 if ( m_peer
== NULL
)
2299 if ( !MacIsReallyShown() )
2306 wxMacRectToNative( rect
, &r
) ;
2307 m_peer
->SetNeedsDisplay( &r
) ;
2311 m_peer
->SetNeedsDisplay() ;
2315 void wxWindowMac::Freeze()
2317 #if TARGET_API_MAC_OSX
2318 if ( !m_frozenness
++ )
2320 if ( m_peer
&& m_peer
->Ok() )
2321 m_peer
->SetDrawingEnabled( false ) ;
2326 void wxWindowMac::Thaw()
2328 #if TARGET_API_MAC_OSX
2329 wxASSERT_MSG( m_frozenness
> 0, wxT("Thaw() without matching Freeze()") );
2331 if ( !--m_frozenness
)
2333 if ( m_peer
&& m_peer
->Ok() )
2335 m_peer
->SetDrawingEnabled( true ) ;
2336 m_peer
->InvalidateWithChildren() ;
2342 wxWindowMac
*wxGetActiveWindow()
2344 // actually this is a windows-only concept
2348 // Coordinates relative to the window
2349 void wxWindowMac::WarpPointer(int x_pos
, int y_pos
)
2351 // We really don't move the mouse programmatically under Mac.
2354 void wxWindowMac::OnEraseBackground(wxEraseEvent
& event
)
2356 if ( MacGetTopLevelWindow() == NULL
)
2359 #if TARGET_API_MAC_OSX
2360 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (!m_macBackgroundBrush
.Ok() || m_macBackgroundBrush
.GetStyle() == wxTRANSPARENT
) )
2367 event
.GetDC()->Clear() ;
2371 void wxWindowMac::OnNcPaint( wxNcPaintEvent
& event
)
2376 int wxWindowMac::GetScrollPos(int orient
) const
2378 if ( orient
== wxHORIZONTAL
)
2381 return m_hScrollBar
->GetThumbPosition() ;
2386 return m_vScrollBar
->GetThumbPosition() ;
2392 // This now returns the whole range, not just the number
2393 // of positions that we can scroll.
2394 int wxWindowMac::GetScrollRange(int orient
) const
2396 if ( orient
== wxHORIZONTAL
)
2399 return m_hScrollBar
->GetRange() ;
2404 return m_vScrollBar
->GetRange() ;
2410 int wxWindowMac::GetScrollThumb(int orient
) const
2412 if ( orient
== wxHORIZONTAL
)
2415 return m_hScrollBar
->GetThumbSize() ;
2420 return m_vScrollBar
->GetThumbSize() ;
2426 void wxWindowMac::SetScrollPos(int orient
, int pos
, bool refresh
)
2428 if ( orient
== wxHORIZONTAL
)
2431 m_hScrollBar
->SetThumbPosition( pos
) ;
2436 m_vScrollBar
->SetThumbPosition( pos
) ;
2441 // we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2442 // our own window origin is at leftOrigin/rightOrigin
2445 void wxWindowMac::MacPaintBorders( int leftOrigin
, int rightOrigin
)
2451 bool hasFocus
= m_peer
->NeedsFocusRect() && m_peer
->HasFocus() ;
2452 bool hasBothScrollbars
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && (m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
2454 // back to the surrounding frame rectangle
2455 m_peer
->GetRect( &rect
) ;
2456 InsetRect( &rect
, -1 , -1 ) ;
2458 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2459 if ( UMAGetSystemVersion() >= 0x1030 )
2461 CGRect cgrect
= CGRectMake( rect
.left
, rect
.top
, rect
.right
- rect
.left
,
2462 rect
.bottom
- rect
.top
) ;
2464 HIThemeFrameDrawInfo info
;
2465 memset( &info
, 0 , sizeof(info
) ) ;
2469 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2470 info
.isFocused
= hasFocus
;
2472 CGContextRef cgContext
= (CGContextRef
) GetParent()->MacGetCGContextRef() ;
2473 wxASSERT( cgContext
) ;
2475 if ( HasFlag(wxRAISED_BORDER
) || HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2477 info
.kind
= kHIThemeFrameTextFieldSquare
;
2478 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2480 else if ( HasFlag(wxSIMPLE_BORDER
) )
2482 info
.kind
= kHIThemeFrameListBox
;
2483 HIThemeDrawFrame( &cgrect
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2485 else if ( hasFocus
)
2487 HIThemeDrawFocusRect( &cgrect
, true , cgContext
, kHIThemeOrientationNormal
) ;
2490 m_peer
->GetRect( &rect
) ;
2491 if ( hasBothScrollbars
)
2493 int size
= m_hScrollBar
->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL
? 16 : 12 ;
2494 CGRect cgrect
= CGRectMake( rect
.right
- size
, rect
.bottom
- size
, size
, size
) ;
2495 CGPoint cgpoint
= CGPointMake( rect
.right
- size
, rect
.bottom
- size
) ;
2496 HIThemeGrowBoxDrawInfo info
;
2497 memset( &info
, 0, sizeof(info
) ) ;
2499 info
.state
= IsEnabled() ? kThemeStateActive
: kThemeStateInactive
;
2500 info
.kind
= kHIThemeGrowBoxKindNone
;
2501 info
.size
= kHIThemeGrowBoxSizeNormal
;
2502 info
.direction
= kThemeGrowRight
| kThemeGrowDown
;
2503 HIThemeDrawGrowBox( &cgpoint
, &info
, cgContext
, kHIThemeOrientationNormal
) ;
2509 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2513 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2514 OffsetRect( &rect
, pt
.x
, pt
.y
) ;
2517 if ( HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
) )
2518 DrawThemeEditTextFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2519 else if ( HasFlag(wxSIMPLE_BORDER
) )
2520 DrawThemeListBoxFrame( &rect
, IsEnabled() ? kThemeStateActive
: kThemeStateInactive
) ;
2523 DrawThemeFocusRect( &rect
, true ) ;
2525 if ( hasBothScrollbars
)
2527 // GetThemeStandaloneGrowBoxBounds
2528 // DrawThemeStandaloneNoGrowBox
2533 void wxWindowMac::RemoveChild( wxWindowBase
*child
)
2535 if ( child
== m_hScrollBar
)
2536 m_hScrollBar
= NULL
;
2537 if ( child
== m_vScrollBar
)
2538 m_vScrollBar
= NULL
;
2540 wxWindowBase::RemoveChild( child
) ;
2543 // New function that will replace some of the above.
2544 void wxWindowMac::SetScrollbar(int orient
, int pos
, int thumbVisible
,
2545 int range
, bool refresh
)
2548 bool triggerSizeEvent
= false;
2550 if ( orient
== wxHORIZONTAL
)
2554 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2555 if ( m_hScrollBar
->IsShown() != showScroller
)
2557 m_hScrollBar
->Show( showScroller
);
2558 triggerSizeEvent
= true;
2561 m_hScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2568 showScroller
= ((range
!= 0) && (range
> thumbVisible
));
2569 if ( m_vScrollBar
->IsShown() != showScroller
)
2571 m_vScrollBar
->Show( showScroller
) ;
2572 triggerSizeEvent
= true;
2575 m_vScrollBar
->SetScrollbar( pos
, thumbVisible
, range
, thumbVisible
, refresh
) ;
2579 MacRepositionScrollBars() ;
2580 if ( triggerSizeEvent
)
2582 wxSizeEvent
event(GetSize(), m_windowId
);
2583 event
.SetEventObject(this);
2584 GetEventHandler()->ProcessEvent(event
);
2588 // Does a physical scroll
2589 void wxWindowMac::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
2591 if ( dx
== 0 && dy
== 0 )
2594 int width
, height
;
2595 GetClientSize( &width
, &height
) ;
2597 #if TARGET_API_MAC_OSX
2598 if ( true /* m_peer->IsCompositing() */ )
2600 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2601 // area is scrolled, this does not occur if width and height are 2 pixels less,
2602 // TODO: write optimal workaround
2603 wxRect
scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width
, height
) ;
2605 scrollrect
.Intersect( *rect
) ;
2607 if ( m_peer
->GetNeedsDisplay() )
2609 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2610 // either immediate redraw or full invalidate
2612 // is the better overall solution, as it does not slow down scrolling
2613 m_peer
->SetNeedsDisplay() ;
2615 // this would be the preferred version for fast drawing controls
2617 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2618 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2619 HIViewRender(m_peer
->GetControlRef()) ;
2626 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2627 scrollrect
.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2628 m_peer
->ScrollRect( &scrollrect
, dx
, dy
) ;
2630 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2631 // either immediate redraw or full invalidate
2633 // is the better overall solution, as it does not slow down scrolling
2634 m_peer
->SetNeedsDisplay() ;
2636 // this would be the preferred version for fast drawing controls
2638 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2639 if ( UMAGetSystemVersion() >= 0x1030 && m_peer
->IsCompositing() )
2640 HIViewRender(m_peer
->GetControlRef()) ;
2654 RgnHandle updateRgn
= NewRgn() ;
2657 wxClientDC
dc(this) ;
2658 wxMacPortSetter
helper(&dc
) ;
2660 m_peer
->GetRectInWindowCoords( &scrollrect
) ;
2661 //scrollrect.top += MacGetTopBorderSize() ;
2662 //scrollrect.left += MacGetLeftBorderSize() ;
2663 scrollrect
.bottom
= scrollrect
.top
+ height
;
2664 scrollrect
.right
= scrollrect
.left
+ width
;
2668 Rect r
= { dc
.YLOG2DEVMAC(rect
->y
) , dc
.XLOG2DEVMAC(rect
->x
) , dc
.YLOG2DEVMAC(rect
->y
+ rect
->height
) ,
2669 dc
.XLOG2DEVMAC(rect
->x
+ rect
->width
) } ;
2670 SectRect( &scrollrect
, &r
, &scrollrect
) ;
2673 ScrollRect( &scrollrect
, dx
, dy
, updateRgn
) ;
2675 // now scroll the former update region as well and add the new update region
2676 WindowRef rootWindow
= (WindowRef
) MacGetTopLevelWindowRef() ;
2677 RgnHandle formerUpdateRgn
= NewRgn() ;
2678 RgnHandle scrollRgn
= NewRgn() ;
2679 RectRgn( scrollRgn
, &scrollrect
) ;
2680 GetWindowUpdateRgn( rootWindow
, formerUpdateRgn
) ;
2682 LocalToGlobal( &pt
) ;
2683 OffsetRgn( formerUpdateRgn
, -pt
.h
, -pt
.v
) ;
2684 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2686 if ( !EmptyRgn( formerUpdateRgn
) )
2688 MacOffsetRgn( formerUpdateRgn
, dx
, dy
) ;
2689 SectRgn( formerUpdateRgn
, scrollRgn
, formerUpdateRgn
) ;
2690 InvalWindowRgn( rootWindow
, formerUpdateRgn
) ;
2693 InvalWindowRgn(rootWindow
, updateRgn
) ;
2694 DisposeRgn( updateRgn
) ;
2695 DisposeRgn( formerUpdateRgn
) ;
2696 DisposeRgn( scrollRgn
) ;
2704 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
2706 child
= node
->GetData();
2709 if (child
== m_vScrollBar
)
2711 if (child
== m_hScrollBar
)
2713 if (child
->IsTopLevel())
2716 child
->GetPosition( &x
, &y
);
2717 child
->GetSize( &w
, &h
);
2720 wxRect
rc( x
, y
, w
, h
);
2721 if (rect
->Intersects( rc
))
2722 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2726 child
->SetSize( x
+ dx
, y
+ dy
, w
, h
);
2731 void wxWindowMac::MacOnScroll( wxScrollEvent
&event
)
2733 if ( event
.GetEventObject() == m_vScrollBar
|| event
.GetEventObject() == m_hScrollBar
)
2735 wxScrollWinEvent wevent
;
2736 wevent
.SetPosition(event
.GetPosition());
2737 wevent
.SetOrientation(event
.GetOrientation());
2738 wevent
.SetEventObject(this);
2740 if (event
.GetEventType() == wxEVT_SCROLL_TOP
)
2741 wevent
.SetEventType( wxEVT_SCROLLWIN_TOP
);
2742 else if (event
.GetEventType() == wxEVT_SCROLL_BOTTOM
)
2743 wevent
.SetEventType( wxEVT_SCROLLWIN_BOTTOM
);
2744 else if (event
.GetEventType() == wxEVT_SCROLL_LINEUP
)
2745 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEUP
);
2746 else if (event
.GetEventType() == wxEVT_SCROLL_LINEDOWN
)
2747 wevent
.SetEventType( wxEVT_SCROLLWIN_LINEDOWN
);
2748 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEUP
)
2749 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEUP
);
2750 else if (event
.GetEventType() == wxEVT_SCROLL_PAGEDOWN
)
2751 wevent
.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN
);
2752 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBTRACK
)
2753 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK
);
2754 else if (event
.GetEventType() == wxEVT_SCROLL_THUMBRELEASE
)
2755 wevent
.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE
);
2757 GetEventHandler()->ProcessEvent(wevent
);
2761 // Get the window with the focus
2762 wxWindowMac
*wxWindowBase::DoFindFocus()
2764 ControlRef control
;
2765 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
2766 return wxFindControlFromMacControl( control
) ;
2769 void wxWindowMac::OnSetFocus( wxFocusEvent
& event
)
2771 // panel wants to track the window which was the last to have focus in it,
2772 // so we want to set ourselves as the window which last had focus
2774 // notice that it's also important to do it upwards the tree because
2775 // otherwise when the top level panel gets focus, it won't set it back to
2776 // us, but to some other sibling
2778 // CS: don't know if this is still needed:
2779 //wxChildFocusEvent eventFocus(this);
2780 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2782 if ( MacGetTopLevelWindow() && m_peer
->NeedsFocusRect() )
2784 #if wxMAC_USE_CORE_GRAPHICS
2785 GetParent()->Refresh() ;
2787 wxMacWindowStateSaver
sv( this ) ;
2790 m_peer
->GetRect( &rect
) ;
2791 // auf den umgebenden Rahmen zur\9fck
2792 InsetRect( &rect
, -1 , -1 ) ;
2794 wxTopLevelWindowMac
* top
= MacGetTopLevelWindow();
2798 wxMacControl::Convert( &pt
, GetParent()->m_peer
, top
->m_peer
) ;
2800 rect
.right
+= pt
.x
;
2802 rect
.bottom
+= pt
.y
;
2805 bool bIsFocusEvent
= (event
.GetEventType() == wxEVT_SET_FOCUS
);
2806 DrawThemeFocusRect( &rect
, bIsFocusEvent
) ;
2807 if ( !bIsFocusEvent
)
2809 // as this erases part of the frame we have to redraw borders
2810 // and because our z-ordering is not always correct (staticboxes)
2811 // we have to invalidate things, we cannot simple redraw
2812 MacInvalidateBorders() ;
2820 void wxWindowMac::OnInternalIdle()
2822 // This calls the UI-update mechanism (querying windows for
2823 // menu/toolbar/control state information)
2824 if (wxUpdateUIEvent::CanUpdate(this))
2825 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
2828 // Raise the window to the top of the Z order
2829 void wxWindowMac::Raise()
2831 m_peer
->SetZOrder( true , NULL
) ;
2834 // Lower the window to the bottom of the Z order
2835 void wxWindowMac::Lower()
2837 m_peer
->SetZOrder( false , NULL
) ;
2840 // static wxWindow *gs_lastWhich = NULL;
2842 bool wxWindowMac::MacSetupCursor( const wxPoint
& pt
)
2844 // first trigger a set cursor event
2846 wxPoint clientorigin
= GetClientAreaOrigin() ;
2847 wxSize clientsize
= GetClientSize() ;
2849 if ( wxRect2DInt( clientorigin
.x
, clientorigin
.y
, clientsize
.x
, clientsize
.y
).Contains( wxPoint2DInt( pt
) ) )
2851 wxSetCursorEvent
event( pt
.x
, pt
.y
);
2853 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
2854 if ( processedEvtSetCursor
&& event
.HasCursor() )
2856 cursor
= event
.GetCursor() ;
2860 // the test for processedEvtSetCursor is here to prevent using m_cursor
2861 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2862 // it - this is a way to say that our cursor shouldn't be used for this
2864 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
2867 if ( !wxIsBusy() && !GetParent() )
2868 cursor
= *wxSTANDARD_CURSOR
;
2872 cursor
.MacInstall() ;
2875 return cursor
.Ok() ;
2878 wxString
wxWindowMac::MacGetToolTipString( wxPoint
&pt
)
2882 return m_tooltip
->GetTip() ;
2885 return wxEmptyString
;
2888 void wxWindowMac::ClearBackground()
2894 void wxWindowMac::Update()
2896 #if TARGET_API_MAC_OSX
2897 MacGetTopLevelWindow()->MacPerformUpdates() ;
2899 ::Draw1Control( m_peer
->GetControlRef() ) ;
2903 wxTopLevelWindowMac
* wxWindowMac::MacGetTopLevelWindow() const
2905 wxTopLevelWindowMac
* win
= NULL
;
2906 WindowRef window
= (WindowRef
) MacGetTopLevelWindowRef() ;
2908 win
= wxFindWinFromMacWindow( window
) ;
2913 const wxRect
& wxWindowMac::MacGetClippedClientRect() const
2915 MacUpdateClippedRects() ;
2917 return m_cachedClippedClientRect
;
2920 const wxRect
& wxWindowMac::MacGetClippedRect() const
2922 MacUpdateClippedRects() ;
2924 return m_cachedClippedRect
;
2927 const wxRect
&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
2929 MacUpdateClippedRects() ;
2931 return m_cachedClippedRectWithOuterStructure
;
2934 const wxRegion
& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures
)
2936 static wxRegion emptyrgn
;
2938 if ( !m_isBeingDeleted
&& MacIsReallyShown() /*m_peer->IsVisible() */ )
2940 MacUpdateClippedRects() ;
2941 if ( includeOuterStructures
)
2942 return m_cachedClippedRegionWithOuterStructure
;
2944 return m_cachedClippedRegion
;
2952 void wxWindowMac::MacUpdateClippedRects() const
2954 if ( m_cachedClippedRectValid
)
2957 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2958 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2959 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2960 // to add focus borders everywhere
2962 Rect r
, rIncludingOuterStructures
;
2964 m_peer
->GetRect( &r
) ;
2965 r
.left
-= MacGetLeftBorderSize() ;
2966 r
.top
-= MacGetTopBorderSize() ;
2967 r
.bottom
+= MacGetBottomBorderSize() ;
2968 r
.right
+= MacGetRightBorderSize() ;
2975 rIncludingOuterStructures
= r
;
2976 InsetRect( &rIncludingOuterStructures
, -4 , -4 ) ;
2978 wxRect cl
= GetClientRect() ;
2979 Rect rClient
= { cl
.y
, cl
.x
, cl
.y
+ cl
.height
, cl
.x
+ cl
.width
} ;
2983 const wxWindow
* child
= this ;
2984 const wxWindow
* parent
= NULL
;
2986 while ( !child
->IsTopLevel() && ( parent
= child
->GetParent() ) != NULL
)
2988 if ( parent
->MacIsChildOfClientArea(child
) )
2990 size
= parent
->GetClientSize() ;
2991 wxPoint origin
= parent
->GetClientAreaOrigin() ;
2997 // this will be true for scrollbars, toolbars etc.
2998 size
= parent
->GetSize() ;
2999 y
= parent
->MacGetTopBorderSize() ;
3000 x
= parent
->MacGetLeftBorderSize() ;
3001 size
.x
-= parent
->MacGetLeftBorderSize() + parent
->MacGetRightBorderSize() ;
3002 size
.y
-= parent
->MacGetTopBorderSize() + parent
->MacGetBottomBorderSize() ;
3005 parent
->MacWindowToRootWindow( &x
, &y
) ;
3006 MacRootWindowToWindow( &x
, &y
) ;
3008 Rect rparent
= { y
, x
, y
+ size
.y
, x
+ size
.x
} ;
3010 // the wxwindow and client rects will always be clipped
3011 SectRect( &r
, &rparent
, &r
) ;
3012 SectRect( &rClient
, &rparent
, &rClient
) ;
3014 // the structure only at 'hard' borders
3015 if ( parent
->MacClipChildren() ||
3016 ( parent
->GetParent() && parent
->GetParent()->MacClipGrandChildren() ) )
3018 SectRect( &rIncludingOuterStructures
, &rparent
, &rIncludingOuterStructures
) ;
3024 m_cachedClippedRect
= wxRect( r
.left
, r
.top
, r
.right
- r
.left
, r
.bottom
- r
.top
) ;
3025 m_cachedClippedClientRect
= wxRect( rClient
.left
, rClient
.top
,
3026 rClient
.right
- rClient
.left
, rClient
.bottom
- rClient
.top
) ;
3027 m_cachedClippedRectWithOuterStructure
= wxRect(
3028 rIncludingOuterStructures
.left
, rIncludingOuterStructures
.top
,
3029 rIncludingOuterStructures
.right
- rIncludingOuterStructures
.left
,
3030 rIncludingOuterStructures
.bottom
- rIncludingOuterStructures
.top
) ;
3032 m_cachedClippedRegionWithOuterStructure
= wxRegion( m_cachedClippedRectWithOuterStructure
) ;
3033 m_cachedClippedRegion
= wxRegion( m_cachedClippedRect
) ;
3034 m_cachedClippedClientRegion
= wxRegion( m_cachedClippedClientRect
) ;
3036 m_cachedClippedRectValid
= true ;
3040 This function must not change the updatergn !
3042 bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr
, long time
)
3044 bool handled
= false ;
3046 RgnHandle updatergn
= (RgnHandle
) updatergnr
;
3047 GetRegionBounds( updatergn
, &updatebounds
) ;
3049 // wxLogDebug(wxT("update for %s bounds %d, %d, %d, %d"), wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left, updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
3051 if ( !EmptyRgn(updatergn
) )
3053 RgnHandle newupdate
= NewRgn() ;
3054 wxSize point
= GetClientSize() ;
3055 wxPoint origin
= GetClientAreaOrigin() ;
3056 SetRectRgn( newupdate
, origin
.x
, origin
.y
, origin
.x
+ point
.x
, origin
.y
+ point
.y
) ;
3057 SectRgn( newupdate
, updatergn
, newupdate
) ;
3059 // first send an erase event to the entire update area
3061 // for the toplevel window this really is the entire area
3062 // for all the others only their client area, otherwise they
3063 // might be drawing with full alpha and eg put blue into
3064 // the grow-box area of a scrolled window (scroll sample)
3065 wxDC
* dc
= new wxWindowDC(this);
3067 dc
->SetClippingRegion(wxRegion(updatergn
));
3069 dc
->SetClippingRegion(wxRegion(newupdate
));
3071 wxEraseEvent
eevent( GetId(), dc
);
3072 eevent
.SetEventObject( this );
3073 GetEventHandler()->ProcessEvent( eevent
);
3077 // calculate a client-origin version of the update rgn and set m_updateRegion to that
3078 OffsetRgn( newupdate
, -origin
.x
, -origin
.y
) ;
3079 m_updateRegion
= newupdate
;
3080 DisposeRgn( newupdate
) ;
3082 if ( !m_updateRegion
.Empty() )
3084 // paint the window itself
3087 event
.SetTimestamp(time
);
3088 event
.SetEventObject(this);
3089 GetEventHandler()->ProcessEvent(event
);
3093 // now we cannot rely on having its borders drawn by a window itself, as it does not
3094 // get the updateRgn wide enough to always do so, so we do it from the parent
3095 // this would also be the place to draw any custom backgrounds for native controls
3096 // in Composited windowing
3097 wxPoint clientOrigin
= GetClientAreaOrigin() ;
3101 for (wxWindowList::compatibility_iterator node
= GetChildren().GetFirst(); node
; node
= node
->GetNext())
3103 child
= node
->GetData();
3106 if (child
== m_vScrollBar
)
3108 if (child
== m_hScrollBar
)
3110 if (child
->IsTopLevel())
3112 if (!child
->IsShown())
3115 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
3117 child
->GetPosition( &x
, &y
);
3118 child
->GetSize( &w
, &h
);
3119 Rect childRect
= { y
, x
, y
+ h
, x
+ w
} ;
3120 OffsetRect( &childRect
, clientOrigin
.x
, clientOrigin
.y
) ;
3121 InsetRect( &childRect
, -10 , -10) ;
3123 if ( RectInRgn( &childRect
, updatergn
) )
3125 // paint custom borders
3126 wxNcPaintEvent
eventNc( child
->GetId() );
3127 eventNc
.SetEventObject( child
);
3128 if ( !child
->GetEventHandler()->ProcessEvent( eventNc
) )
3130 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3131 if ( UMAGetSystemVersion() >= 0x1030 )
3133 child
->MacPaintBorders(0, 0) ;
3138 wxWindowDC
dc(this) ;
3139 dc
.SetClippingRegion(wxRegion(updatergn
));
3140 wxMacPortSetter
helper(&dc
) ;
3141 child
->MacPaintBorders(0, 0) ;
3152 WXWindow
wxWindowMac::MacGetTopLevelWindowRef() const
3154 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3158 if ( iter
->IsTopLevel() )
3159 return ((wxTopLevelWindow
*)iter
)->MacGetWindowRef() ;
3161 iter
= iter
->GetParent() ;
3164 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
3169 void wxWindowMac::MacCreateScrollBars( long style
)
3171 wxASSERT_MSG( m_vScrollBar
== NULL
&& m_hScrollBar
== NULL
, wxT("attempt to create window twice") ) ;
3173 if ( style
& ( wxVSCROLL
| wxHSCROLL
) )
3175 bool hasBoth
= ( style
& wxVSCROLL
) && ( style
& wxHSCROLL
) ;
3176 int scrlsize
= MAC_SCROLLBAR_SIZE
;
3177 wxWindowVariant variant
= wxWINDOW_VARIANT_NORMAL
;
3178 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL
|| GetWindowVariant() == wxWINDOW_VARIANT_MINI
)
3180 scrlsize
= MAC_SMALL_SCROLLBAR_SIZE
;
3181 variant
= wxWINDOW_VARIANT_SMALL
;
3184 int adjust
= hasBoth
? scrlsize
- 1: 0 ;
3186 GetClientSize( &width
, &height
) ;
3188 wxPoint
vPoint(width
- scrlsize
, 0) ;
3189 wxSize
vSize(scrlsize
, height
- adjust
) ;
3190 wxPoint
hPoint(0, height
- scrlsize
) ;
3191 wxSize
hSize(width
- adjust
, scrlsize
) ;
3193 if ( style
& wxVSCROLL
)
3194 m_vScrollBar
= new wxScrollBar(this, wxID_ANY
, vPoint
, vSize
, wxVERTICAL
);
3196 if ( style
& wxHSCROLL
)
3197 m_hScrollBar
= new wxScrollBar(this, wxID_ANY
, hPoint
, hSize
, wxHORIZONTAL
);
3200 // because the create does not take into account the client area origin
3201 // we might have a real position shift
3202 MacRepositionScrollBars() ;
3205 bool wxWindowMac::MacIsChildOfClientArea( const wxWindow
* child
) const
3207 bool result
= ((child
== NULL
) || ((child
!= m_hScrollBar
) && (child
!= m_vScrollBar
)));
3212 void wxWindowMac::MacRepositionScrollBars()
3214 if ( !m_hScrollBar
&& !m_vScrollBar
)
3217 bool hasBoth
= (m_hScrollBar
&& m_hScrollBar
->IsShown()) && ( m_vScrollBar
&& m_vScrollBar
->IsShown()) ;
3218 int scrlsize
= m_hScrollBar
? m_hScrollBar
->GetSize().y
: ( m_vScrollBar
? m_vScrollBar
->GetSize().x
: MAC_SCROLLBAR_SIZE
) ;
3219 int adjust
= hasBoth
? scrlsize
- 1 : 0 ;
3221 // get real client area
3223 GetSize( &width
, &height
);
3225 width
-= MacGetLeftBorderSize() + MacGetRightBorderSize();
3226 height
-= MacGetTopBorderSize() + MacGetBottomBorderSize();
3228 wxPoint
vPoint( width
- scrlsize
, 0 ) ;
3229 wxSize
vSize( scrlsize
, height
- adjust
) ;
3230 wxPoint
hPoint( 0 , height
- scrlsize
) ;
3231 wxSize
hSize( width
- adjust
, scrlsize
) ;
3234 int x
= 0, y
= 0, w
, h
;
3235 GetSize( &w
, &h
) ;
3237 MacClientToRootWindow( &x
, &y
) ;
3238 MacClientToRootWindow( &w
, &h
) ;
3240 wxWindowMac
*iter
= (wxWindowMac
*)this ;
3242 int totW
= 10000 , totH
= 10000;
3245 if ( iter
->IsTopLevel() )
3247 iter
->GetSize( &totW
, &totH
) ;
3251 iter
= iter
->GetParent() ;
3265 if ( w
- x
>= totW
)
3270 if ( h
- y
>= totH
)
3278 m_vScrollBar
->SetSize( vPoint
.x
, vPoint
.y
, vSize
.x
, vSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3280 m_hScrollBar
->SetSize( hPoint
.x
, hPoint
.y
, hSize
.x
, hSize
.y
, wxSIZE_ALLOW_MINUS_ONE
);
3283 bool wxWindowMac::AcceptsFocus() const
3285 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3288 void wxWindowMac::MacSuperChangedPosition()
3290 // only window-absolute structures have to be moved i.e. controls
3292 m_cachedClippedRectValid
= false ;
3295 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3298 child
= node
->GetData();
3299 child
->MacSuperChangedPosition() ;
3301 node
= node
->GetNext();
3305 void wxWindowMac::MacTopLevelWindowChangedPosition()
3307 // only screen-absolute structures have to be moved i.e. glcanvas
3310 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3313 child
= node
->GetData();
3314 child
->MacTopLevelWindowChangedPosition() ;
3316 node
= node
->GetNext();
3320 long wxWindowMac::MacGetLeftBorderSize() const
3327 if (HasFlag(wxRAISED_BORDER
) || HasFlag( wxSUNKEN_BORDER
) || HasFlag(wxDOUBLE_BORDER
))
3329 // this metric is only the 'outset' outside the simple frame rect
3330 GetThemeMetric( kThemeMetricEditTextFrameOutset
, &border
) ;
3333 else if (HasFlag(wxSIMPLE_BORDER
))
3335 // this metric is only the 'outset' outside the simple frame rect
3336 GetThemeMetric( kThemeMetricListBoxFrameOutset
, &border
) ;
3343 long wxWindowMac::MacGetRightBorderSize() const
3345 // they are all symmetric in mac themes
3346 return MacGetLeftBorderSize() ;
3349 long wxWindowMac::MacGetTopBorderSize() const
3351 // they are all symmetric in mac themes
3352 return MacGetLeftBorderSize() ;
3355 long wxWindowMac::MacGetBottomBorderSize() const
3357 // they are all symmetric in mac themes
3358 return MacGetLeftBorderSize() ;
3361 long wxWindowMac::MacRemoveBordersFromStyle( long style
)
3363 return style
& ~wxBORDER_MASK
;
3366 // Find the wxWindowMac at the current mouse position, returning the mouse
3368 wxWindowMac
* wxFindWindowAtPointer( wxPoint
& pt
)
3370 pt
= wxGetMousePosition();
3371 wxWindowMac
* found
= wxFindWindowAtPoint(pt
);
3376 // Get the current mouse position.
3377 wxPoint
wxGetMousePosition()
3381 wxGetMousePosition( &x
, &y
);
3383 return wxPoint(x
, y
);
3386 void wxWindowMac::OnMouseEvent( wxMouseEvent
&event
)
3388 if ( event
.GetEventType() == wxEVT_RIGHT_DOWN
)
3390 // copied from wxGTK : CS
3391 // VZ: shouldn't we move this to base class then?
3393 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
3396 // (a) it's a command event and so is propagated to the parent
3397 // (b) under MSW it can be generated from kbd too
3398 // (c) it uses screen coords (because of (a))
3399 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
,
3401 this->ClientToScreen(event
.GetPosition()));
3402 if ( ! GetEventHandler()->ProcessEvent(evtCtx
) )
3411 void wxWindowMac::OnPaint( wxPaintEvent
& event
)
3413 if ( wxTheApp
->MacGetCurrentEvent() != NULL
&& wxTheApp
->MacGetCurrentEventHandlerCallRef() != NULL
)
3414 CallNextEventHandler(
3415 (EventHandlerCallRef
)wxTheApp
->MacGetCurrentEventHandlerCallRef() ,
3416 (EventRef
) wxTheApp
->MacGetCurrentEvent() ) ;
3419 void wxWindowMac::MacHandleControlClick( WXWidget control
, wxInt16 controlpart
, bool WXUNUSED( mouseStillDown
) )
3423 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
)
3427 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
, adjustForOrigin
) ;
3428 Rect bounds
= { y
, x
, y
+ h
, x
+ w
};
3433 wxInt32
wxWindowMac::MacControlHit(WXEVENTHANDLERREF
WXUNUSED(handler
) , WXEVENTREF
WXUNUSED(event
) )
3435 return eventNotHandledErr
;
3438 bool wxWindowMac::Reparent(wxWindowBase
*newParentBase
)
3440 wxWindowMac
*newParent
= (wxWindowMac
*)newParentBase
;
3441 if ( !wxWindowBase::Reparent(newParent
) )
3444 // copied from MacPostControlCreate
3445 ControlRef container
= (ControlRef
) GetParent()->GetHandle() ;
3447 wxASSERT_MSG( container
!= NULL
, wxT("No valid mac container control") ) ;
3449 ::EmbedControl( m_peer
->GetControlRef() , container
) ;