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