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