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