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