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