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