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