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