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