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