]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/window.cpp
Fixup Blit so it can be used with a source that is a wxBufferedDC,
[wxWidgets.git] / src / mac / carbon / window.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/window.cpp
3// Purpose: wxWindowMac
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/window.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
18 #include "wx/app.h"
19 #include "wx/utils.h"
20 #include "wx/panel.h"
21 #include "wx/frame.h"
22 #include "wx/dc.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
25 #include "wx/menu.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"
36#endif
37
38#include "wx/tooltip.h"
39#include "wx/spinctrl.h"
40#include "wx/geometry.h"
41
42#if wxUSE_CARET
43 #include "wx/caret.h"
44#endif
45
46#if wxUSE_DRAG_AND_DROP
47#include "wx/dnd.h"
48#endif
49
50#include "wx/mac/uma.h"
51
52#define MAC_SCROLLBAR_SIZE 15
53#define MAC_SMALL_SCROLLBAR_SIZE 11
54
55#ifndef __DARWIN__
56#include <Windows.h>
57#include <ToolUtils.h>
58#include <Scrap.h>
59#include <MacTextEditor.h>
60#endif
61
62#if TARGET_API_MAC_OSX
63#ifndef __HIVIEW__
64 #include <HIToolbox/HIView.h>
65#endif
66#endif
67
68#include <string.h>
69
70#ifdef __WXUNIVERSAL__
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
72#else
73 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
74#endif
75
76BEGIN_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)
81#endif
82 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
83 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
84 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
85END_EVENT_TABLE()
86
87#define wxMAC_DEBUG_REDRAW 0
88#ifndef wxMAC_DEBUG_REDRAW
89#define wxMAC_DEBUG_REDRAW 0
90#endif
91
92// ---------------------------------------------------------------------------
93// Utility Routines to move between different coordinate systems
94// ---------------------------------------------------------------------------
95
96/*
97 * Right now we have the following setup :
98 * a border that is not part of the native control is always outside the
99 * control's border (otherwise we loose all native intelligence, future ways
100 * may be to have a second embedding control responsible for drawing borders
101 * and backgrounds eventually)
102 * so all this border calculations have to be taken into account when calling
103 * native methods or getting native oriented data
104 * so we have three coordinate systems here
105 * wx client coordinates
106 * wx window coordinates (including window frames)
107 * native coordinates
108 */
109
110//
111// originating from native control
112//
113
114
115void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle )
116{
117 OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
118}
119
120void wxMacNativeToWindow( const wxWindow* window , Rect *rect )
121{
122 OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
123}
124
125//
126// directed towards native control
127//
128
129void wxMacWindowToNative( const wxWindow* window , RgnHandle handle )
130{
131 OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
132}
133
134void wxMacWindowToNative( const wxWindow* window , Rect *rect )
135{
136 OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ;
137}
138
139// ---------------------------------------------------------------------------
140// Carbon Events
141// ---------------------------------------------------------------------------
142
143#if TARGET_API_MAC_OSX
144
145#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
146enum
147{
148 kEventControlVisibilityChanged = 157
149};
150#endif
151
152#endif
153
154static const EventTypeSpec eventList[] =
155{
156 { kEventClassCommand, kEventProcessCommand } ,
157 { kEventClassCommand, kEventCommandUpdateStatus } ,
158
159 { kEventClassControl , kEventControlHit } ,
160
161 { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
162 { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } ,
163
164 { kEventClassControl , kEventControlDraw } ,
165#if TARGET_API_MAC_OSX
166 { kEventClassControl , kEventControlVisibilityChanged } ,
167 { kEventClassControl , kEventControlEnabledStateChanged } ,
168 { kEventClassControl , kEventControlHiliteChanged } ,
169#endif
170 { kEventClassControl , kEventControlSetFocusPart } ,
171
172 { kEventClassService , kEventServiceGetTypes },
173 { kEventClassService , kEventServiceCopy },
174 { kEventClassService , kEventServicePaste },
175
176// { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
177// { kEventClassControl , kEventControlBoundsChanged } ,
178} ;
179
180static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
181{
182 OSStatus result = eventNotHandledErr ;
183
184 wxMacCarbonEvent cEvent( event ) ;
185
186 ControlRef controlRef ;
187 wxWindowMac* thisWindow = (wxWindowMac*) data ;
188
189 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
190
191 switch ( GetEventKind( event ) )
192 {
193#if TARGET_API_MAC_OSX
194 case kEventControlDraw :
195 {
196 RgnHandle updateRgn = NULL ;
197 RgnHandle allocatedRgn = NULL ;
198 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
199
200 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
201 {
202 updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
203 }
204 else
205 {
206 if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
207 {
208 // as this update region is in native window locals we must adapt it to wx window local
209 allocatedRgn = NewRgn() ;
210 CopyRgn( updateRgn , allocatedRgn ) ;
211
212 // hide the given region by the new region that must be shifted
213 wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
214 updateRgn = allocatedRgn ;
215 }
216 }
217
218 Rect rgnBounds ;
219 GetRegionBounds( updateRgn , &rgnBounds ) ;
220
221#if wxMAC_DEBUG_REDRAW
222 if ( thisWindow->MacIsUserPane() )
223 {
224 static float color = 0.5 ;
225 static channel = 0 ;
226 HIRect bounds;
227 CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
228
229 HIViewGetBounds( controlRef, &bounds );
230 CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 ,
231 channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 );
232 CGContextFillRect( cgContext, bounds );
233 color += 0.1 ;
234 if ( color > 0.9 )
235 {
236 color = 0.5 ;
237 channel++ ;
238 if ( channel == 3 )
239 channel = 0 ;
240 }
241 }
242#endif
243
244 {
245#if wxMAC_USE_CORE_GRAPHICS
246 bool created = false ;
247 CGContextRef cgContext = NULL ;
248 OSStatus err = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) ;
249 wxASSERT_MSG( err == noErr , wxT("Unable to retrieve CGContextRef") ) ;
250 thisWindow->MacSetCGContextRef( cgContext ) ;
251
252 {
253 wxMacCGContextStateSaver sg( cgContext ) ;
254 float alpha = 1.0 ;
255 {
256 wxWindow* iter = thisWindow ;
257 while ( iter )
258 {
259 alpha *= (float) iter->GetTransparent()/255.0 ;
260 if ( iter->IsTopLevel() )
261 iter = NULL ;
262 else
263 iter = iter->GetParent() ;
264 }
265 }
266 CGContextSetAlpha( cgContext , alpha ) ;
267#endif
268 if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
269 result = noErr ;
270
271#if wxMAC_USE_CORE_GRAPHICS
272 thisWindow->MacSetCGContextRef( NULL ) ;
273 }
274
275 if ( created )
276 CGContextRelease( cgContext ) ;
277#endif
278 }
279
280 if ( allocatedRgn )
281 DisposeRgn( allocatedRgn ) ;
282 }
283 break ;
284
285 case kEventControlVisibilityChanged :
286 thisWindow->MacVisibilityChanged() ;
287 break ;
288
289 case kEventControlEnabledStateChanged :
290 thisWindow->MacEnabledStateChanged() ;
291 break ;
292
293 case kEventControlHiliteChanged :
294 thisWindow->MacHiliteChanged() ;
295 break ;
296#endif
297
298 // we emulate this event under Carbon CFM
299 case kEventControlSetFocusPart :
300 {
301 Boolean focusEverything = false ;
302 ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
303
304#ifdef __WXMAC_OSX__
305 if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
306 {
307 }
308#endif
309
310 if ( controlPart == kControlFocusNoPart )
311 {
312#if wxUSE_CARET
313 if ( thisWindow->GetCaret() )
314 thisWindow->GetCaret()->OnKillFocus();
315#endif
316
317 static bool inKillFocusEvent = false ;
318
319 if ( !inKillFocusEvent )
320 {
321 inKillFocusEvent = true ;
322 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
323 event.SetEventObject(thisWindow);
324 thisWindow->GetEventHandler()->ProcessEvent(event) ;
325 inKillFocusEvent = false ;
326 }
327 }
328 else
329 {
330 // panel wants to track the window which was the last to have focus in it
331 wxChildFocusEvent eventFocus(thisWindow);
332 thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
333
334#if wxUSE_CARET
335 if ( thisWindow->GetCaret() )
336 thisWindow->GetCaret()->OnSetFocus();
337#endif
338
339 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
340 event.SetEventObject(thisWindow);
341 thisWindow->GetEventHandler()->ProcessEvent(event) ;
342 }
343
344 if ( thisWindow->MacIsUserPane() )
345 result = noErr ;
346 }
347 break ;
348
349 case kEventControlHit :
350 result = thisWindow->MacControlHit( handler , event ) ;
351 break ;
352
353 default :
354 break ;
355 }
356
357 return result ;
358}
359
360static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
361{
362 OSStatus result = eventNotHandledErr ;
363
364 wxMacCarbonEvent cEvent( event ) ;
365
366 ControlRef controlRef ;
367 wxWindowMac* thisWindow = (wxWindowMac*) data ;
368 wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ;
369 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
370
371 switch ( GetEventKind( event ) )
372 {
373 case kEventServiceGetTypes :
374 if ( textCtrl )
375 {
376 long from, to ;
377 textCtrl->GetSelection( &from , &to ) ;
378
379 CFMutableArrayRef copyTypes = 0 , pasteTypes = 0;
380 if ( from != to )
381 copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ;
382 if ( textCtrl->IsEditable() )
383 pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ;
384
385 static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt', 'PICT', 'MooV', 'AIFF' */ };
386 for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i )
387 {
388 CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]);
389 if ( typestring )
390 {
391 if ( copyTypes )
392 CFArrayAppendValue(copyTypes, typestring) ;
393 if ( pasteTypes )
394 CFArrayAppendValue(pasteTypes, typestring) ;
395
396 CFRelease( typestring ) ;
397 }
398 }
399
400 result = noErr ;
401 }
402 break ;
403
404 case kEventServiceCopy :
405 if ( textCtrl )
406 {
407 long from, to ;
408
409 textCtrl->GetSelection( &from , &to ) ;
410 wxString val = textCtrl->GetValue() ;
411 val = val.Mid( from , to - from ) ;
412 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
413 verify_noerr( ClearScrap( &scrapRef ) ) ;
414 verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.length() , val.c_str() ) ) ;
415 result = noErr ;
416 }
417 break ;
418
419 case kEventServicePaste :
420 if ( textCtrl )
421 {
422 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
423 Size textSize, pastedSize ;
424 verify_noerr( GetScrapFlavorSize(scrapRef, kTXNTextData, &textSize) ) ;
425 textSize++ ;
426 char *content = new char[textSize] ;
427 GetScrapFlavorData(scrapRef, kTXNTextData, &pastedSize, content );
428 content[textSize - 1] = 0 ;
429
430#if wxUSE_UNICODE
431 textCtrl->WriteText( wxString( content , wxConvLocal ) );
432#else
433 textCtrl->WriteText( wxString( content ) ) ;
434#endif
435
436 delete[] content ;
437 result = noErr ;
438 }
439 break ;
440
441 default:
442 break ;
443 }
444
445 return result ;
446}
447
448pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
449{
450 OSStatus result = eventNotHandledErr ;
451 wxWindowMac* focus = (wxWindowMac*) data ;
452
453 wchar_t* uniChars = NULL ;
454 UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
455
456 UniChar* charBuf = NULL;
457 UInt32 dataSize = 0 ;
458 int numChars = 0 ;
459 UniChar buf[2] ;
460 if ( GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr )
461 {
462 numChars = dataSize / sizeof( UniChar) + 1;
463 charBuf = buf ;
464
465 if ( (size_t) numChars * 2 > sizeof(buf) )
466 charBuf = new UniChar[ numChars ] ;
467 else
468 charBuf = buf ;
469
470 uniChars = new wchar_t[ numChars ] ;
471 GetEventParameter( event, kEventParamTextInputSendText, typeUnicodeText, NULL, dataSize , NULL , charBuf ) ;
472 charBuf[ numChars - 1 ] = 0;
473#if SIZEOF_WCHAR_T == 2
474 uniChars = (wchar_t*) charBuf ;
475 memcpy( uniChars , charBuf , numChars * 2 ) ;
476#else
477 // the resulting string will never have more chars than the utf16 version, so this is safe
478 wxMBConvUTF16 converter ;
479 numChars = converter.MB2WC( uniChars , (const char*)charBuf , numChars ) ;
480#endif
481 }
482
483 switch ( GetEventKind( event ) )
484 {
485 case kEventTextInputUpdateActiveInputArea :
486 {
487 // An IME input event may return several characters, but we need to send one char at a time to
488 // EVT_CHAR
489 for (int pos=0 ; pos < numChars ; pos++)
490 {
491 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
492 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
493 wxTheApp->MacSetCurrentEvent( event , handler ) ;
494
495 UInt32 message = (0 << 8) + ((char)uniChars[pos] );
496 if ( wxTheApp->MacSendCharEvent(
497 focus , message , 0 , when , 0 , 0 , uniChars[pos] ) )
498 {
499 result = noErr ;
500 }
501
502 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
503 }
504 }
505 break ;
506 case kEventTextInputUnicodeForKeyEvent :
507 {
508 UInt32 keyCode, modifiers ;
509 Point point ;
510 EventRef rawEvent ;
511 unsigned char charCode ;
512
513 GetEventParameter( event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(rawEvent), NULL, &rawEvent ) ;
514 GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &charCode );
515 GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
516 GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers );
517 GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &point );
518
519 UInt32 message = (keyCode << 8) + charCode;
520
521 // An IME input event may return several characters, but we need to send one char at a time to
522 // EVT_CHAR
523 for (int pos=0 ; pos < numChars ; pos++)
524 {
525 WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ;
526 WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
527 wxTheApp->MacSetCurrentEvent( event , handler ) ;
528
529 if ( wxTheApp->MacSendCharEvent(
530 focus , message , modifiers , when , point.h , point.v , uniChars[pos] ) )
531 {
532 result = noErr ;
533 }
534
535 wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ;
536 }
537 }
538 break;
539 default:
540 break ;
541 }
542
543 delete [] uniChars ;
544 if ( charBuf != buf )
545 delete [] charBuf ;
546
547 return result ;
548}
549
550static pascal OSStatus wxMacWindowCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
551{
552 OSStatus result = eventNotHandledErr ;
553 wxWindowMac* focus = (wxWindowMac*) data ;
554
555 HICommand command ;
556
557 wxMacCarbonEvent cEvent( event ) ;
558 cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;
559
560 wxMenuItem* item = NULL ;
561 wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ;
562 int id = wxMacCommandToId( command.commandID ) ;
563
564 if ( item )
565 {
566 wxASSERT( itemMenu != NULL ) ;
567
568 switch ( cEvent.GetKind() )
569 {
570 case kEventProcessCommand :
571 {
572 if (item->IsCheckable())
573 item->Check( !item->IsChecked() ) ;
574
575 if ( itemMenu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) )
576 result = noErr ;
577 else
578 {
579 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED , id);
580 event.SetEventObject(focus);
581 event.SetInt(item->IsCheckable() ? item->IsChecked() : -1);
582
583 if ( focus->GetEventHandler()->ProcessEvent(event) )
584 result = noErr ;
585 }
586 }
587 break ;
588
589 case kEventCommandUpdateStatus:
590 {
591 wxUpdateUIEvent event(id);
592 event.SetEventObject( itemMenu );
593
594 bool processed = false;
595
596 // Try the menu's event handler
597 {
598 wxEvtHandler *handler = itemMenu->GetEventHandler();
599 if ( handler )
600 processed = handler->ProcessEvent(event);
601 }
602
603 // Try the window the menu was popped up from
604 // (and up through the hierarchy)
605 if ( !processed )
606 {
607 const wxMenuBase *menu = itemMenu;
608 while ( menu )
609 {
610 wxWindow *win = menu->GetInvokingWindow();
611 if ( win )
612 {
613 processed = win->GetEventHandler()->ProcessEvent(event);
614 break;
615 }
616
617 menu = menu->GetParent();
618 }
619 }
620
621 if ( !processed )
622 {
623 processed = focus->GetEventHandler()->ProcessEvent(event);
624 }
625
626 if ( processed )
627 {
628 // if anything changed, update the changed attribute
629 if (event.GetSetText())
630 itemMenu->SetLabel(id, event.GetText());
631 if (event.GetSetChecked())
632 itemMenu->Check(id, event.GetChecked());
633 if (event.GetSetEnabled())
634 itemMenu->Enable(id, event.GetEnabled());
635
636 result = noErr ;
637 }
638 }
639 break ;
640
641 default :
642 break ;
643 }
644 }
645 return result ;
646}
647
648pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
649{
650 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
651 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
652 wxTheApp->MacSetCurrentEvent( event , handler ) ;
653 OSStatus result = eventNotHandledErr ;
654
655 switch ( GetEventClass( event ) )
656 {
657 case kEventClassCommand :
658 result = wxMacWindowCommandEventHandler( handler , event , data ) ;
659 break ;
660
661 case kEventClassControl :
662 result = wxMacWindowControlEventHandler( handler, event, data ) ;
663 break ;
664
665 case kEventClassService :
666 result = wxMacWindowServiceEventHandler( handler, event , data ) ;
667 break ;
668
669 case kEventClassTextInput :
670 result = wxMacUnicodeTextEventHandler( handler , event , data ) ;
671 break ;
672
673 default :
674 break ;
675 }
676
677 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
678
679 return result ;
680}
681
682DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
683
684#if !TARGET_API_MAC_OSX
685
686// ---------------------------------------------------------------------------
687// UserPane events for non OSX builds
688// ---------------------------------------------------------------------------
689
690static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
691{
692 wxWindow * win = wxFindControlFromMacControl(control) ;
693 if ( win )
694 win->MacControlUserPaneDrawProc(part) ;
695}
696wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ;
697
698static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
699{
700 wxWindow * win = wxFindControlFromMacControl(control) ;
701 if ( win )
702 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
703 else
704 return kControlNoPart ;
705}
706wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ;
707
708static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
709{
710 wxWindow * win = wxFindControlFromMacControl(control) ;
711 if ( win )
712 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
713 else
714 return kControlNoPart ;
715}
716wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ;
717
718static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
719{
720 wxWindow * win = wxFindControlFromMacControl(control) ;
721 if ( win )
722 win->MacControlUserPaneIdleProc() ;
723}
724wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ;
725
726static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
727{
728 wxWindow * win = wxFindControlFromMacControl(control) ;
729 if ( win )
730 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
731 else
732 return kControlNoPart ;
733}
734wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ;
735
736static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
737{
738 wxWindow * win = wxFindControlFromMacControl(control) ;
739 if ( win )
740 win->MacControlUserPaneActivateProc(activating) ;
741}
742wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ;
743
744static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
745{
746 wxWindow * win = wxFindControlFromMacControl(control) ;
747 if ( win )
748 return win->MacControlUserPaneFocusProc(action) ;
749 else
750 return kControlNoPart ;
751}
752wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ;
753
754static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
755{
756 wxWindow * win = wxFindControlFromMacControl(control) ;
757 if ( win )
758 win->MacControlUserPaneBackgroundProc(info) ;
759}
760wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ;
761
762void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
763{
764 int x = 0 , y = 0;
765 RgnHandle rgn = NewRgn() ;
766 GetClip( rgn ) ;
767 MacWindowToRootWindow( &x, &y ) ;
768 OffsetRgn( rgn , -x , -y ) ;
769 wxMacWindowStateSaver sv( this ) ;
770 SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ;
771 MacDoRedraw( rgn , 0 ) ;
772 DisposeRgn( rgn ) ;
773}
774
775wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
776{
777 return kControlNoPart ;
778}
779
780wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
781{
782 return kControlNoPart ;
783}
784
785void wxWindowMac::MacControlUserPaneIdleProc()
786{
787}
788
789wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
790{
791 return kControlNoPart ;
792}
793
794void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
795{
796}
797
798wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
799{
800 if ( AcceptsFocus() )
801 return 1 ;
802 else
803 return kControlNoPart ;
804}
805
806void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
807{
808}
809
810#endif
811
812// ---------------------------------------------------------------------------
813// Scrollbar Tracking for all
814// ---------------------------------------------------------------------------
815
816pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
817pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
818{
819 if ( partCode != 0)
820 {
821 wxWindow* wx = wxFindControlFromMacControl( control ) ;
822 if ( wx )
823 wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
824 }
825}
826wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
827
828// ===========================================================================
829// implementation
830// ===========================================================================
831
832WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
833
834static MacControlMap wxWinMacControlList;
835
836wxWindow *wxFindControlFromMacControl(ControlRef inControl )
837{
838 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
839
840 return (node == wxWinMacControlList.end()) ? NULL : node->second;
841}
842
843void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
844{
845 // adding NULL ControlRef is (first) surely a result of an error and
846 // (secondly) breaks native event processing
847 wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
848
849 wxWinMacControlList[inControl] = control;
850}
851
852void wxRemoveMacControlAssociation(wxWindow *control)
853{
854 // iterate over all the elements in the class
855 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
856 // we should go on...
857
858 bool found = true ;
859 while ( found )
860 {
861 found = false ;
862 MacControlMap::iterator it;
863 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
864 {
865 if ( it->second == control )
866 {
867 wxWinMacControlList.erase(it);
868 found = true ;
869 break;
870 }
871 }
872 }
873}
874
875// ----------------------------------------------------------------------------
876 // constructors and such
877// ----------------------------------------------------------------------------
878
879wxWindowMac::wxWindowMac()
880{
881 Init();
882}
883
884wxWindowMac::wxWindowMac(wxWindowMac *parent,
885 wxWindowID id,
886 const wxPoint& pos ,
887 const wxSize& size ,
888 long style ,
889 const wxString& name )
890{
891 Init();
892 Create(parent, id, pos, size, style, name);
893}
894
895void wxWindowMac::Init()
896{
897 m_peer = NULL ;
898 m_frozenness = 0 ;
899 m_macAlpha = 255 ;
900
901#if WXWIN_COMPATIBILITY_2_4
902 m_backgroundTransparent = false;
903#endif
904
905#if wxMAC_USE_CORE_GRAPHICS
906 m_cgContextRef = NULL ;
907#endif
908
909 // as all windows are created with WS_VISIBLE style...
910 m_isShown = true;
911
912 m_hScrollBar = NULL ;
913 m_vScrollBar = NULL ;
914 m_macBackgroundBrush = wxNullBrush ;
915
916 m_macIsUserPane = true;
917 m_clipChildren = false ;
918 m_cachedClippedRectValid = false ;
919
920 // we need a valid font for the encodings
921 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
922}
923
924wxWindowMac::~wxWindowMac()
925{
926 SendDestroyEvent();
927
928 m_isBeingDeleted = true;
929
930 MacInvalidateBorders() ;
931
932#ifndef __WXUNIVERSAL__
933 // VS: make sure there's no wxFrame with last focus set to us:
934 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
935 {
936 wxFrame *frame = wxDynamicCast(win, wxFrame);
937 if ( frame )
938 {
939 if ( frame->GetLastFocus() == this )
940 frame->SetLastFocus((wxWindow*)NULL);
941 break;
942 }
943 }
944#endif
945
946 // destroy children before destroying this window itself
947 DestroyChildren();
948
949 // wxRemoveMacControlAssociation( this ) ;
950 // If we delete an item, we should initialize the parent panel,
951 // because it could now be invalid.
952 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
953 if ( tlw )
954 {
955 if ( tlw->GetDefaultItem() == (wxButton*) this)
956 tlw->SetDefaultItem(NULL);
957 }
958
959 if ( m_peer && m_peer->Ok() )
960 {
961 // in case the callback might be called during destruction
962 wxRemoveMacControlAssociation( this) ;
963 ::RemoveEventHandler( (EventHandlerRef ) m_macControlEventHandler ) ;
964 // we currently are not using this hook
965 // ::SetControlColorProc( *m_peer , NULL ) ;
966 m_peer->Dispose() ;
967 }
968
969 if ( g_MacLastWindow == this )
970 g_MacLastWindow = NULL ;
971
972 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
973 if ( frame )
974 {
975 if ( frame->GetLastFocus() == this )
976 frame->SetLastFocus( NULL ) ;
977 }
978
979 // delete our drop target if we've got one
980#if wxUSE_DRAG_AND_DROP
981 if ( m_dropTarget != NULL )
982 {
983 delete m_dropTarget;
984 m_dropTarget = NULL;
985 }
986#endif
987
988 delete m_peer ;
989}
990
991WXWidget wxWindowMac::GetHandle() const
992{
993 return (WXWidget) m_peer->GetControlRef() ;
994}
995
996void wxWindowMac::MacInstallEventHandler( WXWidget control )
997{
998 wxAssociateControlWithMacControl( (ControlRef) control , this ) ;
999 InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(),
1000 GetEventTypeCount(eventList), eventList, this,
1001 (EventHandlerRef *)&m_macControlEventHandler);
1002
1003#if !TARGET_API_MAC_OSX
1004 if ( (ControlRef) control == m_peer->GetControlRef() )
1005 {
1006 m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ;
1007 m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ;
1008 m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ;
1009 m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ;
1010 m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ;
1011 m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ;
1012 m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ;
1013 m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ;
1014 }
1015#endif
1016}
1017
1018// Constructor
1019bool wxWindowMac::Create(wxWindowMac *parent,
1020 wxWindowID id,
1021 const wxPoint& pos,
1022 const wxSize& size,
1023 long style,
1024 const wxString& name)
1025{
1026 wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
1027
1028 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
1029 return false;
1030
1031 m_windowVariant = parent->GetWindowVariant() ;
1032
1033 if ( m_macIsUserPane )
1034 {
1035 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
1036
1037 UInt32 features = 0
1038 | kControlSupportsEmbedding
1039 | kControlSupportsLiveFeedback
1040 | kControlGetsFocusOnClick
1041// | kControlHasSpecialBackground
1042// | kControlSupportsCalcBestRect
1043 | kControlHandlesTracking
1044 | kControlSupportsFocus
1045 | kControlWantsActivate
1046 | kControlWantsIdle ;
1047
1048 m_peer = new wxMacControl(this) ;
1049 OSStatus err =::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
1050 verify_noerr( err );
1051
1052 MacPostControlCreate(pos, size) ;
1053 }
1054
1055#ifndef __WXUNIVERSAL__
1056 // Don't give scrollbars to wxControls unless they ask for them
1057 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar)))
1058 || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL))))
1059 {
1060 MacCreateScrollBars( style ) ;
1061 }
1062#endif
1063
1064 wxWindowCreateEvent event(this);
1065 GetEventHandler()->AddPendingEvent(event);
1066
1067 return true;
1068}
1069
1070void wxWindowMac::MacChildAdded()
1071{
1072 if ( m_vScrollBar )
1073 m_vScrollBar->Raise() ;
1074 if ( m_hScrollBar )
1075 m_hScrollBar->Raise() ;
1076}
1077
1078void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
1079{
1080 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
1081
1082 m_peer->SetReference( (long)this ) ;
1083 GetParent()->AddChild( this );
1084
1085 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
1086
1087 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
1088 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
1089 ::EmbedControl( m_peer->GetControlRef() , container ) ;
1090 GetParent()->MacChildAdded() ;
1091
1092 // adjust font, controlsize etc
1093 DoSetWindowVariant( m_windowVariant ) ;
1094
1095 m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ;
1096
1097 if (!m_macIsUserPane)
1098 SetInitialBestSize(size);
1099
1100 SetCursor( *wxSTANDARD_CURSOR ) ;
1101}
1102
1103void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
1104{
1105 // Don't assert, in case we set the window variant before
1106 // the window is created
1107 // wxASSERT( m_peer->Ok() ) ;
1108
1109 m_windowVariant = variant ;
1110
1111 if (m_peer == NULL || !m_peer->Ok())
1112 return;
1113
1114 ControlSize size ;
1115 ThemeFontID themeFont = kThemeSystemFont ;
1116
1117 // we will get that from the settings later
1118 // and make this NORMAL later, but first
1119 // we have a few calculations that we must fix
1120
1121 switch ( variant )
1122 {
1123 case wxWINDOW_VARIANT_NORMAL :
1124 size = kControlSizeNormal;
1125 themeFont = kThemeSystemFont ;
1126 break ;
1127
1128 case wxWINDOW_VARIANT_SMALL :
1129 size = kControlSizeSmall;
1130 themeFont = kThemeSmallSystemFont ;
1131 break ;
1132
1133 case wxWINDOW_VARIANT_MINI :
1134 if (UMAGetSystemVersion() >= 0x1030 )
1135 {
1136 // not always defined in the headers
1137 size = 3 ;
1138 themeFont = 109 ;
1139 }
1140 else
1141 {
1142 size = kControlSizeSmall;
1143 themeFont = kThemeSmallSystemFont ;
1144 }
1145 break ;
1146
1147 case wxWINDOW_VARIANT_LARGE :
1148 size = kControlSizeLarge;
1149 themeFont = kThemeSystemFont ;
1150 break ;
1151
1152 default:
1153 wxFAIL_MSG(_T("unexpected window variant"));
1154 break ;
1155 }
1156
1157 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
1158
1159 wxFont font ;
1160 font.MacCreateThemeFont( themeFont ) ;
1161 SetFont( font ) ;
1162}
1163
1164void wxWindowMac::MacUpdateControlFont()
1165{
1166 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1167 Refresh() ;
1168}
1169
1170bool wxWindowMac::SetFont(const wxFont& font)
1171{
1172 bool retval = wxWindowBase::SetFont( font );
1173
1174 MacUpdateControlFont() ;
1175
1176 return retval;
1177}
1178
1179bool wxWindowMac::SetForegroundColour(const wxColour& col )
1180{
1181 bool retval = wxWindowBase::SetForegroundColour( col );
1182
1183 if (retval)
1184 MacUpdateControlFont();
1185
1186 return retval;
1187}
1188
1189bool wxWindowMac::SetBackgroundColour(const wxColour& col )
1190{
1191 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1192 return false ;
1193
1194 wxBrush brush ;
1195 wxColour newCol(GetBackgroundColour());
1196
1197 if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) )
1198 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
1199 else if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
1200 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
1201 else
1202 brush.SetColour( newCol ) ;
1203
1204 MacSetBackgroundBrush( brush ) ;
1205 MacUpdateControlFont() ;
1206
1207 return true ;
1208}
1209
1210void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
1211{
1212 m_macBackgroundBrush = brush ;
1213 m_peer->SetBackground( brush ) ;
1214}
1215
1216bool wxWindowMac::MacCanFocus() const
1217{
1218 // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so
1219 // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning,
1220 // but the value range is nowhere documented
1221 Boolean keyExistsAndHasValidFormat ;
1222 CFIndex fullKeyboardAccess = CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) ,
1223 kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat );
1224
1225 if ( keyExistsAndHasValidFormat && fullKeyboardAccess > 0 )
1226 {
1227 return true ;
1228 }
1229 else
1230 {
1231 UInt32 features = 0 ;
1232 m_peer->GetFeatures( &features ) ;
1233
1234 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
1235 }
1236}
1237
1238void wxWindowMac::SetFocus()
1239{
1240 if ( !AcceptsFocus() )
1241 return ;
1242
1243 wxWindow* former = FindFocus() ;
1244 if ( former == this )
1245 return ;
1246
1247 // as we cannot rely on the control features to find out whether we are in full keyboard mode,
1248 // we can only leave in case of an error
1249 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
1250 if ( err == errCouldntSetFocus )
1251 return ;
1252
1253 SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() );
1254
1255#if !TARGET_API_MAC_OSX
1256 // emulate carbon events when running under CarbonLib where they are not natively available
1257 if ( former )
1258 {
1259 EventRef evRef = NULL ;
1260
1261 err = MacCreateEvent(
1262 NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
1263 kEventAttributeUserEvent , &evRef );
1264 verify_noerr( err );
1265
1266 wxMacCarbonEvent cEvent( evRef ) ;
1267 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
1268 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
1269
1270 wxMacWindowEventHandler( NULL , evRef , former ) ;
1271 ReleaseEvent( evRef ) ;
1272 }
1273
1274 // send new focus event
1275 {
1276 EventRef evRef = NULL ;
1277
1278 err = MacCreateEvent(
1279 NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) ,
1280 kEventAttributeUserEvent , &evRef );
1281 verify_noerr( err );
1282
1283 wxMacCarbonEvent cEvent( evRef ) ;
1284 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
1285 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
1286
1287 wxMacWindowEventHandler( NULL , evRef , this ) ;
1288 ReleaseEvent( evRef ) ;
1289 }
1290#endif
1291}
1292
1293void wxWindowMac::DoCaptureMouse()
1294{
1295 wxApp::s_captureWindow = this ;
1296}
1297
1298wxWindow * wxWindowBase::GetCapture()
1299{
1300 return wxApp::s_captureWindow ;
1301}
1302
1303void wxWindowMac::DoReleaseMouse()
1304{
1305 wxApp::s_captureWindow = NULL ;
1306}
1307
1308#if wxUSE_DRAG_AND_DROP
1309
1310void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
1311{
1312 if ( m_dropTarget != NULL )
1313 delete m_dropTarget;
1314
1315 m_dropTarget = pDropTarget;
1316 if ( m_dropTarget != NULL )
1317 {
1318 // TODO:
1319 }
1320}
1321
1322#endif
1323
1324// Old-style File Manager Drag & Drop
1325void wxWindowMac::DragAcceptFiles(bool accept)
1326{
1327 // TODO:
1328}
1329
1330// Returns the size of the native control. In the case of the toplevel window
1331// this is the content area root control
1332
1333void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
1334 int& w, int& h) const
1335{
1336 wxFAIL_MSG( wxT("Not currently supported") ) ;
1337}
1338
1339// From a wx position / size calculate the appropriate size of the native control
1340
1341bool wxWindowMac::MacGetBoundsForControl(
1342 const wxPoint& pos,
1343 const wxSize& size,
1344 int& x, int& y,
1345 int& w, int& h , bool adjustOrigin ) const
1346{
1347 // the desired size, minus the border pixels gives the correct size of the control
1348 x = (int)pos.x;
1349 y = (int)pos.y;
1350
1351 // TODO: the default calls may be used as soon as PostCreateControl Is moved here
1352 w = wxMax(size.x, 0) ; // WidthDefault( size.x );
1353 h = wxMax(size.y, 0) ; // HeightDefault( size.y ) ;
1354
1355 x += MacGetLeftBorderSize() ;
1356 y += MacGetTopBorderSize() ;
1357 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1358 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1359
1360 if ( adjustOrigin )
1361 AdjustForParentClientOrigin( x , y ) ;
1362
1363 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1364 if ( !GetParent()->IsTopLevel() )
1365 {
1366 x -= GetParent()->MacGetLeftBorderSize() ;
1367 y -= GetParent()->MacGetTopBorderSize() ;
1368 }
1369
1370 return true ;
1371}
1372
1373// Get window size (not client size)
1374void wxWindowMac::DoGetSize(int *x, int *y) const
1375{
1376 Rect bounds ;
1377 m_peer->GetRect( &bounds ) ;
1378
1379 if (x)
1380 *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1381 if (y)
1382 *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1383}
1384
1385// get the position of the bounds of this window in client coordinates of its parent
1386void wxWindowMac::DoGetPosition(int *x, int *y) const
1387{
1388 Rect bounds ;
1389 m_peer->GetRect( &bounds ) ;
1390
1391 int x1 = bounds.left ;
1392 int y1 = bounds.top ;
1393
1394 // get the wx window position from the native one
1395 x1 -= MacGetLeftBorderSize() ;
1396 y1 -= MacGetTopBorderSize() ;
1397
1398 if ( !IsTopLevel() )
1399 {
1400 wxWindow *parent = GetParent();
1401 if ( parent )
1402 {
1403 // we must first adjust it to be in window coordinates of the parent,
1404 // as otherwise it gets lost by the ClientAreaOrigin fix
1405 x1 += parent->MacGetLeftBorderSize() ;
1406 y1 += parent->MacGetTopBorderSize() ;
1407
1408 // and now to client coordinates
1409 wxPoint pt(parent->GetClientAreaOrigin());
1410 x1 -= pt.x ;
1411 y1 -= pt.y ;
1412 }
1413 }
1414
1415 if (x)
1416 *x = x1 ;
1417 if (y)
1418 *y = y1 ;
1419}
1420
1421void wxWindowMac::DoScreenToClient(int *x, int *y) const
1422{
1423 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1424 wxCHECK_RET( window , wxT("TopLevel Window missing") ) ;
1425
1426 Point localwhere = { 0, 0 } ;
1427
1428 if (x)
1429 localwhere.h = *x ;
1430 if (y)
1431 localwhere.v = *y ;
1432
1433 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
1434
1435 if (x)
1436 *x = localwhere.h ;
1437 if (y)
1438 *y = localwhere.v ;
1439
1440 MacRootWindowToWindow( x , y ) ;
1441
1442 wxPoint origin = GetClientAreaOrigin() ;
1443 if (x)
1444 *x -= origin.x ;
1445 if (y)
1446 *y -= origin.y ;
1447}
1448
1449void wxWindowMac::DoClientToScreen(int *x, int *y) const
1450{
1451 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1452 wxCHECK_RET( window , wxT("TopLevel window missing") ) ;
1453
1454 wxPoint origin = GetClientAreaOrigin() ;
1455 if (x)
1456 *x += origin.x ;
1457 if (y)
1458 *y += origin.y ;
1459
1460 MacWindowToRootWindow( x , y ) ;
1461
1462 Point localwhere = { 0, 0 };
1463 if (x)
1464 localwhere.h = *x ;
1465 if (y)
1466 localwhere.v = *y ;
1467
1468 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
1469
1470 if (x)
1471 *x = localwhere.h ;
1472 if (y)
1473 *y = localwhere.v ;
1474}
1475
1476void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
1477{
1478 wxPoint origin = GetClientAreaOrigin() ;
1479 if (x)
1480 *x += origin.x ;
1481 if (y)
1482 *y += origin.y ;
1483
1484 MacWindowToRootWindow( x , y ) ;
1485}
1486
1487void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1488{
1489 MacRootWindowToWindow( x , y ) ;
1490
1491 wxPoint origin = GetClientAreaOrigin() ;
1492 if (x)
1493 *x -= origin.x ;
1494 if (y)
1495 *y -= origin.y ;
1496}
1497
1498void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1499{
1500 wxPoint pt ;
1501
1502 if (x)
1503 pt.x = *x ;
1504 if (y)
1505 pt.y = *y ;
1506
1507 if ( !IsTopLevel() )
1508 {
1509 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1510 if (top)
1511 {
1512 pt.x -= MacGetLeftBorderSize() ;
1513 pt.y -= MacGetTopBorderSize() ;
1514 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1515 }
1516 }
1517
1518 if (x)
1519 *x = (int) pt.x ;
1520 if (y)
1521 *y = (int) pt.y ;
1522}
1523
1524void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1525{
1526 int x1 , y1 ;
1527
1528 if (x)
1529 x1 = *x ;
1530 if (y)
1531 y1 = *y ;
1532
1533 MacWindowToRootWindow( &x1 , &y1 ) ;
1534
1535 if (x)
1536 *x = x1 ;
1537 if (y)
1538 *y = y1 ;
1539}
1540
1541void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
1542{
1543 wxPoint pt ;
1544
1545 if (x)
1546 pt.x = *x ;
1547 if (y)
1548 pt.y = *y ;
1549
1550 if ( !IsTopLevel() )
1551 {
1552 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1553 if (top)
1554 {
1555 wxMacControl::Convert( &pt , top->m_peer , m_peer ) ;
1556 pt.x += MacGetLeftBorderSize() ;
1557 pt.y += MacGetTopBorderSize() ;
1558 }
1559 }
1560
1561 if (x)
1562 *x = (int) pt.x ;
1563 if (y)
1564 *y = (int) pt.y ;
1565}
1566
1567void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
1568{
1569 int x1 , y1 ;
1570
1571 if (x)
1572 x1 = *x ;
1573 if (y)
1574 y1 = *y ;
1575
1576 MacRootWindowToWindow( &x1 , &y1 ) ;
1577
1578 if (x)
1579 *x = x1 ;
1580 if (y)
1581 *y = y1 ;
1582}
1583
1584void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1585{
1586 RgnHandle rgn = NewRgn() ;
1587
1588 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1589 {
1590 Rect structure, content ;
1591
1592 GetRegionBounds( rgn , &content ) ;
1593 m_peer->GetRect( &structure ) ;
1594 OffsetRect( &structure, -structure.left , -structure.top ) ;
1595
1596 left = content.left - structure.left ;
1597 top = content.top - structure.top ;
1598 right = structure.right - content.right ;
1599 bottom = structure.bottom - content.bottom ;
1600 }
1601 else
1602 {
1603 left = top = right = bottom = 0 ;
1604 }
1605
1606 DisposeRgn( rgn ) ;
1607}
1608
1609wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1610{
1611 wxSize sizeTotal = size;
1612
1613 RgnHandle rgn = NewRgn() ;
1614 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1615 {
1616 Rect content, structure ;
1617 GetRegionBounds( rgn , &content ) ;
1618 m_peer->GetRect( &structure ) ;
1619
1620 // structure is in parent coordinates, but we only need width and height, so it's ok
1621
1622 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1623 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top) ;
1624 }
1625
1626 DisposeRgn( rgn ) ;
1627
1628 sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1629 sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1630
1631 return sizeTotal;
1632}
1633
1634// Get size *available for subwindows* i.e. excluding menu bar etc.
1635void wxWindowMac::DoGetClientSize( int *x, int *y ) const
1636{
1637 int ww, hh;
1638
1639 RgnHandle rgn = NewRgn() ;
1640 Rect content ;
1641 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
1642 GetRegionBounds( rgn , &content ) ;
1643 else
1644 m_peer->GetRect( &content ) ;
1645 DisposeRgn( rgn ) ;
1646
1647 ww = content.right - content.left ;
1648 hh = content.bottom - content.top ;
1649
1650 if (m_hScrollBar && m_hScrollBar->IsShown() )
1651 hh -= m_hScrollBar->GetSize().y ;
1652
1653 if (m_vScrollBar && m_vScrollBar->IsShown() )
1654 ww -= m_vScrollBar->GetSize().x ;
1655
1656 if (x)
1657 *x = ww;
1658 if (y)
1659 *y = hh;
1660}
1661
1662bool wxWindowMac::SetCursor(const wxCursor& cursor)
1663{
1664 if (m_cursor == cursor)
1665 return false;
1666
1667 if (wxNullCursor == cursor)
1668 {
1669 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1670 return false ;
1671 }
1672 else
1673 {
1674 if ( ! wxWindowBase::SetCursor( cursor ) )
1675 return false ;
1676 }
1677
1678 wxASSERT_MSG( m_cursor.Ok(),
1679 wxT("cursor must be valid after call to the base version"));
1680
1681 wxWindowMac *mouseWin = 0 ;
1682 {
1683 wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ;
1684 WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ;
1685 CGrafPtr savePort ;
1686 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1687
1688 // TODO: If we ever get a GetCurrentEvent... replacement
1689 // for the mouse position, use it...
1690
1691 Point pt ;
1692 ControlPartCode part ;
1693 ControlRef control ;
1694
1695 GetMouse( &pt ) ;
1696 control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ;
1697 if ( control )
1698 mouseWin = wxFindControlFromMacControl( control ) ;
1699
1700 if ( swapped )
1701 QDSwapPort( savePort , NULL ) ;
1702 }
1703
1704 if ( mouseWin == this && !wxIsBusy() )
1705 m_cursor.MacInstall() ;
1706
1707 return true ;
1708}
1709
1710#if wxUSE_MENUS
1711bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1712{
1713 menu->SetInvokingWindow(this);
1714 menu->UpdateUI();
1715
1716 if ( x == wxDefaultCoord && y == wxDefaultCoord )
1717 {
1718 wxPoint mouse = wxGetMousePosition();
1719 x = mouse.x;
1720 y = mouse.y;
1721 }
1722 else
1723 {
1724 ClientToScreen( &x , &y ) ;
1725 }
1726
1727 menu->MacBeforeDisplay( true ) ;
1728 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() , y, x, 0) ;
1729 if ( HiWord(menuResult) != 0 )
1730 {
1731 MenuCommand macid;
1732 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &macid );
1733 int id = wxMacCommandToId( macid );
1734 wxMenuItem* item = NULL ;
1735 wxMenu* realmenu ;
1736 item = menu->FindItem( id, &realmenu ) ;
1737 if ( item )
1738 {
1739 if (item->IsCheckable())
1740 item->Check( !item->IsChecked() ) ;
1741
1742 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1743 }
1744 }
1745
1746 menu->MacAfterDisplay( true ) ;
1747 menu->SetInvokingWindow( NULL );
1748
1749 return true;
1750}
1751#endif
1752
1753// ----------------------------------------------------------------------------
1754// tooltips
1755// ----------------------------------------------------------------------------
1756
1757#if wxUSE_TOOLTIPS
1758
1759void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
1760{
1761 wxWindowBase::DoSetToolTip(tooltip);
1762
1763 if ( m_tooltip )
1764 m_tooltip->SetWindow(this);
1765}
1766
1767#endif
1768
1769void wxWindowMac::MacInvalidateBorders()
1770{
1771 if ( m_peer == NULL )
1772 return ;
1773
1774 bool vis = MacIsReallyShown() ;
1775 if ( !vis )
1776 return ;
1777
1778 int outerBorder = MacGetLeftBorderSize() ;
1779 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1780 outerBorder += 4 ;
1781
1782 if ( outerBorder == 0 )
1783 return ;
1784
1785 // now we know that we have something to do at all
1786
1787 // as the borders are drawn on the parent we have to properly invalidate all these areas
1788 RgnHandle updateInner , updateOuter;
1789 Rect rect ;
1790
1791 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1792 updateInner = NewRgn() ;
1793 updateOuter = NewRgn() ;
1794
1795 m_peer->GetRect( &rect ) ;
1796 RectRgn( updateInner, &rect ) ;
1797 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1798 RectRgn( updateOuter, &rect ) ;
1799 DiffRgn( updateOuter, updateInner , updateOuter ) ;
1800
1801#ifdef __WXMAC_OSX__
1802 GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ;
1803#else
1804 WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ;
1805 if ( tlw )
1806 InvalWindowRgn( tlw , updateOuter ) ;
1807#endif
1808
1809 DisposeRgn( updateOuter ) ;
1810 DisposeRgn( updateInner ) ;
1811}
1812
1813void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
1814{
1815 // this is never called for a toplevel window, so we know we have a parent
1816 int former_x , former_y , former_w, former_h ;
1817
1818 // Get true coordinates of former position
1819 DoGetPosition( &former_x , &former_y ) ;
1820 DoGetSize( &former_w , &former_h ) ;
1821
1822 wxWindow *parent = GetParent();
1823 if ( parent )
1824 {
1825 wxPoint pt(parent->GetClientAreaOrigin());
1826 former_x += pt.x ;
1827 former_y += pt.y ;
1828 }
1829
1830 int actualWidth = width ;
1831 int actualHeight = height ;
1832 int actualX = x;
1833 int actualY = y;
1834
1835 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
1836 actualWidth = m_minWidth;
1837 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
1838 actualHeight = m_minHeight;
1839 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
1840 actualWidth = m_maxWidth;
1841 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
1842 actualHeight = m_maxHeight;
1843
1844 bool doMove = false, doResize = false ;
1845
1846 if ( actualX != former_x || actualY != former_y )
1847 doMove = true ;
1848
1849 if ( actualWidth != former_w || actualHeight != former_h )
1850 doResize = true ;
1851
1852 if ( doMove || doResize )
1853 {
1854 // as the borders are drawn outside the native control, we adjust now
1855
1856 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
1857 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1858 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1859
1860 Rect r ;
1861 wxMacRectToNative( &bounds , &r ) ;
1862
1863 if ( !GetParent()->IsTopLevel() )
1864 wxMacWindowToNative( GetParent() , &r ) ;
1865
1866 MacInvalidateBorders() ;
1867
1868 m_cachedClippedRectValid = false ;
1869 m_peer->SetRect( &r ) ;
1870
1871 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1872
1873 MacInvalidateBorders() ;
1874
1875 MacRepositionScrollBars() ;
1876 if ( doMove )
1877 {
1878 wxPoint point(actualX, actualY);
1879 wxMoveEvent event(point, m_windowId);
1880 event.SetEventObject(this);
1881 GetEventHandler()->ProcessEvent(event) ;
1882 }
1883
1884 if ( doResize )
1885 {
1886 MacRepositionScrollBars() ;
1887 wxSize size(actualWidth, actualHeight);
1888 wxSizeEvent event(size, m_windowId);
1889 event.SetEventObject(this);
1890 GetEventHandler()->ProcessEvent(event);
1891 }
1892 }
1893}
1894
1895wxSize wxWindowMac::DoGetBestSize() const
1896{
1897 if ( m_macIsUserPane || IsTopLevel() )
1898 return wxWindowBase::DoGetBestSize() ;
1899
1900 Rect bestsize = { 0 , 0 , 0 , 0 } ;
1901 int bestWidth, bestHeight ;
1902
1903 m_peer->GetBestRect( &bestsize ) ;
1904 if ( EmptyRect( &bestsize ) )
1905 {
1906 bestsize.left =
1907 bestsize.top = 0 ;
1908 bestsize.right =
1909 bestsize.bottom = 16 ;
1910
1911 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1912 {
1913 bestsize.bottom = 16 ;
1914 }
1915#if wxUSE_SPINBTN
1916 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1917 {
1918 bestsize.bottom = 24 ;
1919 }
1920#endif
1921 else
1922 {
1923 // return wxWindowBase::DoGetBestSize() ;
1924 }
1925 }
1926
1927 bestWidth = bestsize.right - bestsize.left ;
1928 bestHeight = bestsize.bottom - bestsize.top ;
1929 if ( bestHeight < 10 )
1930 bestHeight = 13 ;
1931
1932 return wxSize(bestWidth, bestHeight);
1933}
1934
1935// set the size of the window: if the dimensions are positive, just use them,
1936// but if any of them is equal to -1, it means that we must find the value for
1937// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1938// which case -1 is a valid value for x and y)
1939//
1940// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1941// the width/height to best suit our contents, otherwise we reuse the current
1942// width/height
1943void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1944{
1945 // get the current size and position...
1946 int currentX, currentY;
1947 int currentW, currentH;
1948
1949 GetPosition(&currentX, &currentY);
1950 GetSize(&currentW, &currentH);
1951
1952 // ... and don't do anything (avoiding flicker) if it's already ok
1953 if ( x == currentX && y == currentY &&
1954 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1955 {
1956 // TODO: REMOVE
1957 MacRepositionScrollBars() ; // we might have a real position shift
1958
1959 return;
1960 }
1961
1962 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1963 {
1964 if ( x == wxDefaultCoord )
1965 x = currentX;
1966 if ( y == wxDefaultCoord )
1967 y = currentY;
1968 }
1969
1970 AdjustForParentClientOrigin( x, y, sizeFlags );
1971
1972 wxSize size = wxDefaultSize;
1973 if ( width == wxDefaultCoord )
1974 {
1975 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1976 {
1977 size = DoGetBestSize();
1978 width = size.x;
1979 }
1980 else
1981 {
1982 // just take the current one
1983 width = currentW;
1984 }
1985 }
1986
1987 if ( height == wxDefaultCoord )
1988 {
1989 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1990 {
1991 if ( size.x == wxDefaultCoord )
1992 size = DoGetBestSize();
1993 // else: already called DoGetBestSize() above
1994
1995 height = size.y;
1996 }
1997 else
1998 {
1999 // just take the current one
2000 height = currentH;
2001 }
2002 }
2003
2004 DoMoveWindow( x, y, width, height );
2005}
2006
2007wxPoint wxWindowMac::GetClientAreaOrigin() const
2008{
2009 RgnHandle rgn = NewRgn() ;
2010 Rect content ;
2011 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
2012 {
2013 GetRegionBounds( rgn , &content ) ;
2014 }
2015 else
2016 {
2017 content.left =
2018 content.top = 0 ;
2019 }
2020
2021 DisposeRgn( rgn ) ;
2022
2023 return wxPoint( content.left + MacGetLeftBorderSize() , content.top + MacGetTopBorderSize() );
2024}
2025
2026void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
2027{
2028 if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord )
2029 {
2030 int currentclientwidth , currentclientheight ;
2031 int currentwidth , currentheight ;
2032
2033 GetClientSize( &currentclientwidth , &currentclientheight ) ;
2034 GetSize( &currentwidth , &currentheight ) ;
2035
2036 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
2037 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
2038 }
2039}
2040
2041void wxWindowMac::SetLabel(const wxString& title)
2042{
2043 m_label = wxStripMenuCodes(title, wxStrip_Mnemonics) ;
2044
2045 if ( m_peer && m_peer->Ok() )
2046 m_peer->SetLabel( m_label ) ;
2047
2048 Refresh() ;
2049}
2050
2051wxString wxWindowMac::GetLabel() const
2052{
2053 return m_label ;
2054}
2055
2056bool wxWindowMac::Show(bool show)
2057{
2058 bool former = MacIsReallyShown() ;
2059 if ( !wxWindowBase::Show(show) )
2060 return false;
2061
2062 // TODO: use visibilityChanged Carbon Event for OSX
2063 if ( m_peer )
2064 m_peer->SetVisibility( show , true ) ;
2065
2066 if ( former != MacIsReallyShown() )
2067 MacPropagateVisibilityChanged() ;
2068
2069 return true;
2070}
2071
2072bool wxWindowMac::Enable(bool enable)
2073{
2074 wxASSERT( m_peer->Ok() ) ;
2075 bool former = MacIsReallyEnabled() ;
2076 if ( !wxWindowBase::Enable(enable) )
2077 return false;
2078
2079 m_peer->Enable( enable ) ;
2080
2081 if ( former != MacIsReallyEnabled() )
2082 MacPropagateEnabledStateChanged() ;
2083
2084 return true;
2085}
2086
2087//
2088// status change propagations (will be not necessary for OSX later )
2089//
2090
2091void wxWindowMac::MacPropagateVisibilityChanged()
2092{
2093#if !TARGET_API_MAC_OSX
2094 MacVisibilityChanged() ;
2095
2096 wxWindowMac *child;
2097 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2098 while ( node )
2099 {
2100 child = node->GetData();
2101 if ( child->IsShown() )
2102 child->MacPropagateVisibilityChanged() ;
2103
2104 node = node->GetNext();
2105 }
2106#endif
2107}
2108
2109void wxWindowMac::MacPropagateEnabledStateChanged()
2110{
2111#if !TARGET_API_MAC_OSX
2112 MacEnabledStateChanged() ;
2113
2114 wxWindowMac *child;
2115 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2116 while ( node )
2117 {
2118 child = node->GetData();
2119 if ( child->IsEnabled() )
2120 child->MacPropagateEnabledStateChanged() ;
2121
2122 node = node->GetNext();
2123 }
2124#endif
2125}
2126
2127void wxWindowMac::MacPropagateHiliteChanged()
2128{
2129#if !TARGET_API_MAC_OSX
2130 MacHiliteChanged() ;
2131
2132 wxWindowMac *child;
2133 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2134 while ( node )
2135 {
2136 child = node->GetData();
2137 if (child /* && child->IsEnabled() */)
2138 child->MacPropagateHiliteChanged() ;
2139
2140 node = node->GetNext();
2141 }
2142#endif
2143}
2144
2145//
2146// status change notifications
2147//
2148
2149void wxWindowMac::MacVisibilityChanged()
2150{
2151}
2152
2153void wxWindowMac::MacHiliteChanged()
2154{
2155}
2156
2157void wxWindowMac::MacEnabledStateChanged()
2158{
2159}
2160
2161//
2162// status queries on the inherited window's state
2163//
2164
2165bool wxWindowMac::MacIsReallyShown()
2166{
2167 // only under OSX the visibility of the TLW is taken into account
2168 if ( m_isBeingDeleted )
2169 return false ;
2170
2171#if TARGET_API_MAC_OSX
2172 if ( m_peer && m_peer->Ok() )
2173 return m_peer->IsVisible();
2174#endif
2175
2176 wxWindow* win = this ;
2177 while ( win->IsShown() )
2178 {
2179 if ( win->IsTopLevel() )
2180 return true ;
2181
2182 win = win->GetParent() ;
2183 if ( win == NULL )
2184 return true ;
2185 }
2186
2187 return false ;
2188}
2189
2190bool wxWindowMac::MacIsReallyEnabled()
2191{
2192 return m_peer->IsEnabled() ;
2193}
2194
2195bool wxWindowMac::MacIsReallyHilited()
2196{
2197 return m_peer->IsActive();
2198}
2199
2200void wxWindowMac::MacFlashInvalidAreas()
2201{
2202#if TARGET_API_MAC_OSX
2203 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2204#endif
2205}
2206
2207int wxWindowMac::GetCharHeight() const
2208{
2209 wxClientDC dc( (wxWindowMac*)this ) ;
2210
2211 return dc.GetCharHeight() ;
2212}
2213
2214int wxWindowMac::GetCharWidth() const
2215{
2216 wxClientDC dc( (wxWindowMac*)this ) ;
2217
2218 return dc.GetCharWidth() ;
2219}
2220
2221void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
2222 int *descent, int *externalLeading, const wxFont *theFont ) const
2223{
2224 const wxFont *fontToUse = theFont;
2225 if ( !fontToUse )
2226 fontToUse = &m_font;
2227
2228 wxClientDC dc( (wxWindowMac*) this ) ;
2229 long lx,ly,ld,le ;
2230 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2231 if ( externalLeading )
2232 *externalLeading = le ;
2233 if ( descent )
2234 *descent = ld ;
2235 if ( x )
2236 *x = lx ;
2237 if ( y )
2238 *y = ly ;
2239}
2240
2241/*
2242 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
2243 * we always intersect with the entire window, not only with the client area
2244 */
2245
2246void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
2247{
2248 if ( m_peer == NULL )
2249 return ;
2250
2251 if ( !MacIsReallyShown() )
2252 return ;
2253
2254 if ( rect )
2255 {
2256 Rect r ;
2257
2258 wxMacRectToNative( rect , &r ) ;
2259 m_peer->SetNeedsDisplay( &r ) ;
2260 }
2261 else
2262 {
2263 m_peer->SetNeedsDisplay() ;
2264 }
2265}
2266
2267void wxWindowMac::Freeze()
2268{
2269#if TARGET_API_MAC_OSX
2270 if ( !m_frozenness++ )
2271 {
2272 if ( m_peer && m_peer->Ok() )
2273 m_peer->SetDrawingEnabled( false ) ;
2274 }
2275#endif
2276}
2277
2278void wxWindowMac::Thaw()
2279{
2280#if TARGET_API_MAC_OSX
2281 wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") );
2282
2283 if ( !--m_frozenness )
2284 {
2285 if ( m_peer && m_peer->Ok() )
2286 {
2287 m_peer->SetDrawingEnabled( true ) ;
2288 m_peer->InvalidateWithChildren() ;
2289 }
2290 }
2291#endif
2292}
2293
2294wxWindowMac *wxGetActiveWindow()
2295{
2296 // actually this is a windows-only concept
2297 return NULL;
2298}
2299
2300// Coordinates relative to the window
2301void wxWindowMac::WarpPointer(int x_pos, int y_pos)
2302{
2303 // We really don't move the mouse programmatically under Mac.
2304}
2305
2306void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
2307{
2308 if ( MacGetTopLevelWindow() == NULL )
2309 return ;
2310
2311#if TARGET_API_MAC_OSX
2312 if ( !m_macBackgroundBrush.Ok() || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
2313 {
2314 event.Skip() ;
2315 }
2316 else
2317#endif
2318 {
2319 event.GetDC()->Clear() ;
2320 }
2321}
2322
2323void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2324{
2325 event.Skip() ;
2326}
2327
2328int wxWindowMac::GetScrollPos(int orient) const
2329{
2330 if ( orient == wxHORIZONTAL )
2331 {
2332 if ( m_hScrollBar )
2333 return m_hScrollBar->GetThumbPosition() ;
2334 }
2335 else
2336 {
2337 if ( m_vScrollBar )
2338 return m_vScrollBar->GetThumbPosition() ;
2339 }
2340
2341 return 0;
2342}
2343
2344// This now returns the whole range, not just the number
2345// of positions that we can scroll.
2346int wxWindowMac::GetScrollRange(int orient) const
2347{
2348 if ( orient == wxHORIZONTAL )
2349 {
2350 if ( m_hScrollBar )
2351 return m_hScrollBar->GetRange() ;
2352 }
2353 else
2354 {
2355 if ( m_vScrollBar )
2356 return m_vScrollBar->GetRange() ;
2357 }
2358
2359 return 0;
2360}
2361
2362int wxWindowMac::GetScrollThumb(int orient) const
2363{
2364 if ( orient == wxHORIZONTAL )
2365 {
2366 if ( m_hScrollBar )
2367 return m_hScrollBar->GetThumbSize() ;
2368 }
2369 else
2370 {
2371 if ( m_vScrollBar )
2372 return m_vScrollBar->GetThumbSize() ;
2373 }
2374
2375 return 0;
2376}
2377
2378void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
2379{
2380 if ( orient == wxHORIZONTAL )
2381 {
2382 if ( m_hScrollBar )
2383 m_hScrollBar->SetThumbPosition( pos ) ;
2384 }
2385 else
2386 {
2387 if ( m_vScrollBar )
2388 m_vScrollBar->SetThumbPosition( pos ) ;
2389 }
2390}
2391
2392//
2393// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2394// our own window origin is at leftOrigin/rightOrigin
2395//
2396
2397void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2398{
2399 if ( IsTopLevel() )
2400 return ;
2401
2402 Rect rect ;
2403 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2404 bool hasBothScrollbars = (m_hScrollBar && m_hScrollBar->IsShown()) && (m_vScrollBar && m_vScrollBar->IsShown()) ;
2405
2406 // back to the surrounding frame rectangle
2407 m_peer->GetRect( &rect ) ;
2408 InsetRect( &rect, -1 , -1 ) ;
2409
2410#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2411 if ( UMAGetSystemVersion() >= 0x1030 )
2412 {
2413 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
2414 rect.bottom - rect.top ) ;
2415
2416 HIThemeFrameDrawInfo info ;
2417 memset( &info, 0 , sizeof(info) ) ;
2418
2419 info.version = 0 ;
2420 info.kind = 0 ;
2421 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2422 info.isFocused = hasFocus ;
2423
2424 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2425 wxASSERT( cgContext ) ;
2426
2427 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2428 {
2429 info.kind = kHIThemeFrameTextFieldSquare ;
2430 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2431 }
2432 else if ( HasFlag(wxSIMPLE_BORDER) )
2433 {
2434 info.kind = kHIThemeFrameListBox ;
2435 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2436 }
2437 else if ( hasFocus )
2438 {
2439 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2440 }
2441
2442 m_peer->GetRect( &rect ) ;
2443 if ( hasBothScrollbars )
2444 {
2445 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
2446 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
2447 CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
2448 HIThemeGrowBoxDrawInfo info ;
2449 memset( &info, 0, sizeof(info) ) ;
2450 info.version = 0 ;
2451 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2452 info.kind = kHIThemeGrowBoxKindNone ;
2453 info.size = kHIThemeGrowBoxSizeNormal ;
2454 info.direction = kThemeGrowRight | kThemeGrowDown ;
2455 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2456 }
2457 }
2458 else
2459#endif
2460 {
2461 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2462 if ( top )
2463 {
2464 wxPoint pt(0, 0) ;
2465 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2466 OffsetRect( &rect , pt.x , pt.y ) ;
2467 }
2468
2469 if ( HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2470 DrawThemeEditTextFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
2471 else if ( HasFlag(wxSIMPLE_BORDER) )
2472 DrawThemeListBoxFrame( &rect, IsEnabled() ? kThemeStateActive : kThemeStateInactive ) ;
2473
2474 if ( hasFocus )
2475 DrawThemeFocusRect( &rect , true ) ;
2476
2477 if ( hasBothScrollbars )
2478 {
2479 // GetThemeStandaloneGrowBoxBounds
2480 // DrawThemeStandaloneNoGrowBox
2481 }
2482 }
2483}
2484
2485void wxWindowMac::RemoveChild( wxWindowBase *child )
2486{
2487 if ( child == m_hScrollBar )
2488 m_hScrollBar = NULL ;
2489 if ( child == m_vScrollBar )
2490 m_vScrollBar = NULL ;
2491
2492 wxWindowBase::RemoveChild( child ) ;
2493}
2494
2495// New function that will replace some of the above.
2496void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
2497 int range, bool refresh)
2498{
2499 bool showScroller;
2500 bool triggerSizeEvent = false;
2501
2502 if ( orient == wxHORIZONTAL )
2503 {
2504 if ( m_hScrollBar )
2505 {
2506 showScroller = ((range != 0) && (range > thumbVisible));
2507 if ( m_hScrollBar->IsShown() != showScroller )
2508 {
2509 m_hScrollBar->Show( showScroller );
2510 triggerSizeEvent = true;
2511 }
2512
2513 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2514 }
2515 }
2516 else
2517 {
2518 if ( m_vScrollBar )
2519 {
2520 showScroller = ((range != 0) && (range > thumbVisible));
2521 if ( m_vScrollBar->IsShown() != showScroller )
2522 {
2523 m_vScrollBar->Show( showScroller ) ;
2524 triggerSizeEvent = true;
2525 }
2526
2527 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
2528 }
2529 }
2530
2531 MacRepositionScrollBars() ;
2532 if ( triggerSizeEvent )
2533 {
2534 wxSizeEvent event(GetSize(), m_windowId);
2535 event.SetEventObject(this);
2536 GetEventHandler()->ProcessEvent(event);
2537 }
2538}
2539
2540// Does a physical scroll
2541void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
2542{
2543 if ( dx == 0 && dy == 0 )
2544 return ;
2545
2546 int width , height ;
2547 GetClientSize( &width , &height ) ;
2548
2549#if TARGET_API_MAC_OSX
2550 if ( true )
2551 {
2552 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2553 // area is scrolled, this does not occur if width and height are 2 pixels less,
2554 // TODO: write optimal workaround
2555 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
2556 if ( rect )
2557 scrollrect.Intersect( *rect ) ;
2558
2559 if ( m_peer->GetNeedsDisplay() )
2560 {
2561 // because HIViewScrollRect does not scroll the already invalidated area we have two options:
2562 // either immediate redraw or full invalidate
2563#if 1
2564 // is the better overall solution, as it does not slow down scrolling
2565 m_peer->SetNeedsDisplay() ;
2566#else
2567 // this would be the preferred version for fast drawing controls
2568
2569#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2570 if ( UMAGetSystemVersion() >= 0x1030 )
2571 HIViewRender(m_peer->GetControlRef()) ;
2572 else
2573#endif
2574 Update() ;
2575#endif
2576 }
2577
2578 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2579 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2580 m_peer->ScrollRect( &scrollrect , dx , dy ) ;
2581
2582 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2583 // either immediate redraw or full invalidate
2584#if 0
2585 // is the better overall solution, as it does not slow down scrolling
2586 m_peer->SetNeedsDisplay() ;
2587#else
2588 // this would be the preferred version for fast drawing controls
2589
2590#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2591 if ( UMAGetSystemVersion() >= 0x1030 )
2592 HIViewRender(m_peer->GetControlRef()) ;
2593 else
2594#endif
2595 Update() ;
2596#endif
2597 }
2598 else
2599#endif
2600 {
2601 wxPoint pos;
2602 pos.x =
2603 pos.y = 0;
2604
2605 Rect scrollrect;
2606 RgnHandle updateRgn = NewRgn() ;
2607
2608 {
2609 wxClientDC dc(this) ;
2610 wxMacPortSetter helper(&dc) ;
2611
2612 m_peer->GetRectInWindowCoords( &scrollrect ) ;
2613 //scrollrect.top += MacGetTopBorderSize() ;
2614 //scrollrect.left += MacGetLeftBorderSize() ;
2615 scrollrect.bottom = scrollrect.top + height ;
2616 scrollrect.right = scrollrect.left + width ;
2617
2618 if ( rect )
2619 {
2620 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2621 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2622 SectRect( &scrollrect , &r , &scrollrect ) ;
2623 }
2624
2625 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
2626
2627 // now scroll the former update region as well and add the new update region
2628 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2629 RgnHandle formerUpdateRgn = NewRgn() ;
2630 RgnHandle scrollRgn = NewRgn() ;
2631 RectRgn( scrollRgn , &scrollrect ) ;
2632 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2633 Point pt = {0, 0} ;
2634 LocalToGlobal( &pt ) ;
2635 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2636 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2637
2638 if ( !EmptyRgn( formerUpdateRgn ) )
2639 {
2640 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2641 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2642 InvalWindowRgn( rootWindow, formerUpdateRgn ) ;
2643 }
2644
2645 InvalWindowRgn(rootWindow, updateRgn ) ;
2646 DisposeRgn( updateRgn ) ;
2647 DisposeRgn( formerUpdateRgn ) ;
2648 DisposeRgn( scrollRgn ) ;
2649 }
2650
2651 Update() ;
2652 }
2653
2654 wxWindowMac *child;
2655 int x, y, w, h;
2656 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2657 {
2658 child = node->GetData();
2659 if (child == NULL)
2660 continue;
2661 if (child == m_vScrollBar)
2662 continue;
2663 if (child == m_hScrollBar)
2664 continue;
2665 if (child->IsTopLevel())
2666 continue;
2667
2668 child->GetPosition( &x, &y );
2669 child->GetSize( &w, &h );
2670 if (rect)
2671 {
2672 wxRect rc( x, y, w, h );
2673 if (rect->Intersects( rc ))
2674 child->SetSize( x + dx, y + dy, w, h );
2675 }
2676 else
2677 {
2678 child->SetSize( x + dx, y + dy, w, h );
2679 }
2680 }
2681}
2682
2683void wxWindowMac::MacOnScroll( wxScrollEvent &event )
2684{
2685 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
2686 {
2687 wxScrollWinEvent wevent;
2688 wevent.SetPosition(event.GetPosition());
2689 wevent.SetOrientation(event.GetOrientation());
2690 wevent.SetEventObject(this);
2691
2692 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2693 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2694 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2695 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2696 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2697 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2698 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2699 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2700 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2701 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2702 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2703 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2704 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2705 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2706 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2707 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
2708
2709 GetEventHandler()->ProcessEvent(wevent);
2710 }
2711}
2712
2713// Get the window with the focus
2714wxWindowMac *wxWindowBase::DoFindFocus()
2715{
2716 ControlRef control ;
2717 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2718 return wxFindControlFromMacControl( control ) ;
2719}
2720
2721void wxWindowMac::OnSetFocus( wxFocusEvent& event )
2722{
2723 // panel wants to track the window which was the last to have focus in it,
2724 // so we want to set ourselves as the window which last had focus
2725 //
2726 // notice that it's also important to do it upwards the tree because
2727 // otherwise when the top level panel gets focus, it won't set it back to
2728 // us, but to some other sibling
2729
2730 // CS: don't know if this is still needed:
2731 //wxChildFocusEvent eventFocus(this);
2732 //(void)GetEventHandler()->ProcessEvent(eventFocus);
2733
2734 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2735 {
2736#if wxMAC_USE_CORE_GRAPHICS
2737 GetParent()->Refresh() ;
2738#else
2739 wxMacWindowStateSaver sv( this ) ;
2740 Rect rect ;
2741
2742 m_peer->GetRect( &rect ) ;
2743