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