]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/window.cpp
moving native format generation into bitmap ref data because of the owner semantics...
[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 852 (EventHandlerRef *)&m_macControlEventHandler);
4a63451b
SC
853#if !TARGET_API_MAC_OSX
854 if ( (ControlRef) control == m_peer->GetControlRef() )
855 {
856 m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,&gControlUserPaneDrawUPP) ;
857 m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,&gControlUserPaneHitTestUPP) ;
858 m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,&gControlUserPaneTrackingUPP) ;
859 m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,&gControlUserPaneIdleUPP) ;
860 m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,&gControlUserPaneKeyDownUPP) ;
861 m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,&gControlUserPaneActivateUPP) ;
862 m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,&gControlUserPaneFocusUPP) ;
863 m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,&gControlUserPaneBackgroundUPP) ;
864 }
865#endif
facd6764
SC
866
867}
868
e9576ca5 869// Constructor
e766c8a9 870bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
e9576ca5
SC
871 const wxPoint& pos,
872 const wxSize& size,
873 long style,
874 const wxString& name)
875{
e766c8a9 876 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindowMac without parent") );
e9576ca5 877
e7549107 878 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
e9576ca5
SC
879 return FALSE;
880
facd6764 881 m_windowVariant = parent->GetWindowVariant() ;
8b573fb8 882
facd6764
SC
883 if ( m_macIsUserPane )
884 {
885 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
8b573fb8 886
ebe86b1e 887 UInt32 features = 0
8b573fb8
VZ
888 | kControlSupportsEmbedding
889// | kControlSupportsLiveFeedback
890// | kControlHasSpecialBackground
891// | kControlSupportsCalcBestRect
892// | kControlHandlesTracking
893 | kControlSupportsFocus
894// | kControlWantsActivate
895// | kControlWantsIdle
896 ;
ebe86b1e 897
21fd5529 898 m_peer = new wxMacControl() ;
5ca0d812 899 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
8b573fb8 900
facd6764
SC
901
902 MacPostControlCreate(pos,size) ;
facd6764 903 }
e766c8a9 904#ifndef __WXUNIVERSAL__
14c9cbdb
RD
905 // Don't give scrollbars to wxControls unless they ask for them
906 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
907 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
6264b550
RR
908 {
909 MacCreateScrollBars( style ) ;
910 }
e766c8a9 911#endif
3dfafdb9
RD
912
913 wxWindowCreateEvent event(this);
7e4a196e 914 GetEventHandler()->AddPendingEvent(event);
3dfafdb9 915
e9576ca5
SC
916 return TRUE;
917}
918
08422003
SC
919void wxWindowMac::MacChildAdded()
920{
921 if ( m_vScrollBar )
922 {
923 m_vScrollBar->Raise() ;
924 }
925 if ( m_hScrollBar )
926 {
927 m_hScrollBar->Raise() ;
928 }
929
930}
931
facd6764
SC
932void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
933{
21fd5529 934 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
facd6764 935
5ca0d812 936 m_peer->SetReference( (long) this ) ;
488abb22 937 GetParent()->AddChild(this);
facd6764 938
5ca0d812 939 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
facd6764
SC
940
941 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
942 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
5ca0d812 943 ::EmbedControl( m_peer->GetControlRef() , container ) ;
08422003 944 GetParent()->MacChildAdded() ;
facd6764
SC
945
946 // adjust font, controlsize etc
947 DoSetWindowVariant( m_windowVariant ) ;
948
949#if !TARGET_API_MAC_OSX
8b573fb8 950 // eventually we can fix some clipping issues be reactivating this hook
facd6764 951 //if ( m_macIsUserPane )
be346c26 952 // SetControlColorProc( m_peer->GetControlRef() , wxMacSetupControlBackgroundUPP ) ;
facd6764 953#endif
5ca0d812 954 m_peer->SetTitle( wxStripMenuCodes(m_label) ) ;
facd6764 955
facd6764 956 if (!m_macIsUserPane)
d3b5db4b
RD
957 {
958 SetInitialBestSize(size);
facd6764
SC
959 }
960
961 SetCursor( *wxSTANDARD_CURSOR ) ;
facd6764
SC
962}
963
964void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
965{
23176131
JS
966 // Don't assert, in case we set the window variant before
967 // the window is created
21fd5529 968 // wxASSERT( m_peer->Ok() ) ;
facd6764 969
23176131
JS
970 m_windowVariant = variant ;
971
21fd5529 972 if (m_peer == NULL || !m_peer->Ok())
23176131 973 return;
facd6764 974
8b573fb8 975 ControlSize size ;
facd6764
SC
976 ThemeFontID themeFont = kThemeSystemFont ;
977
978 // we will get that from the settings later
8b573fb8 979 // and make this NORMAL later, but first
facd6764 980 // we have a few calculations that we must fix
8b573fb8 981
facd6764
SC
982 switch ( variant )
983 {
984 case wxWINDOW_VARIANT_NORMAL :
8b573fb8
VZ
985 size = kControlSizeNormal;
986 themeFont = kThemeSystemFont ;
facd6764
SC
987 break ;
988 case wxWINDOW_VARIANT_SMALL :
8b573fb8
VZ
989 size = kControlSizeSmall;
990 themeFont = kThemeSmallSystemFont ;
facd6764
SC
991 break ;
992 case wxWINDOW_VARIANT_MINI :
993 if (UMAGetSystemVersion() >= 0x1030 )
994 {
8b573fb8
VZ
995 // not always defined in the headers
996 size = 3 ;
997 themeFont = 109 ;
facd6764
SC
998 }
999 else
1000 {
8b573fb8
VZ
1001 size = kControlSizeSmall;
1002 themeFont = kThemeSmallSystemFont ;
facd6764
SC
1003 }
1004 break ;
1005 case wxWINDOW_VARIANT_LARGE :
8b573fb8
VZ
1006 size = kControlSizeLarge;
1007 themeFont = kThemeSystemFont ;
facd6764
SC
1008 break ;
1009 default:
1010 wxFAIL_MSG(_T("unexpected window variant"));
1011 break ;
1012 }
5ca0d812 1013 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ;
facd6764
SC
1014
1015 wxFont font ;
1016 font.MacCreateThemeFont( themeFont ) ;
1017 SetFont( font ) ;
1018}
1019
8b573fb8 1020void wxWindowMac::MacUpdateControlFont()
facd6764 1021{
ac99838a 1022 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
8b573fb8 1023 Refresh() ;
facd6764
SC
1024}
1025
1026bool wxWindowMac::SetFont(const wxFont& font)
1027{
d5ccba72 1028 bool retval = wxWindowBase::SetFont( font ) ;
8b573fb8 1029
facd6764 1030 MacUpdateControlFont() ;
8b573fb8 1031
facd6764
SC
1032 return retval;
1033}
1034
1035bool wxWindowMac::SetForegroundColour(const wxColour& col )
1036{
1037 if ( !wxWindowBase::SetForegroundColour(col) )
1038 return false ;
8b573fb8 1039
facd6764 1040 MacUpdateControlFont() ;
8b573fb8 1041
facd6764
SC
1042 return true ;
1043}
1044
1045bool wxWindowMac::SetBackgroundColour(const wxColour& col )
1046{
1047 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
1048 return false ;
1049
1050 wxBrush brush ;
b52acd03
RD
1051 wxColour newCol(GetBackgroundColour());
1052 if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
facd6764
SC
1053 {
1054 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
1055 }
b52acd03 1056 else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
facd6764 1057 {
8b573fb8
VZ
1058 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
1059 }
facd6764
SC
1060 else
1061 {
b52acd03 1062 brush.SetColour( newCol ) ;
facd6764
SC
1063 }
1064 MacSetBackgroundBrush( brush ) ;
8b573fb8 1065
db7a550b 1066 MacUpdateControlFont() ;
8b573fb8 1067
facd6764
SC
1068 return true ;
1069}
1070
7ea087b7
SC
1071void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
1072{
1073 m_macBackgroundBrush = brush ;
1074 m_peer->SetBackground( brush ) ;
1075}
facd6764
SC
1076
1077bool wxWindowMac::MacCanFocus() const
1078{
f6e3849c
SC
1079 // there is currently no way to determine whether the window is running in full keyboard
1080 // access mode, therefore we cannot rely on these features, yet the only other way would be
1081 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1082 // in event handlers...
f1d527c1 1083 UInt32 features = 0 ;
5ca0d812 1084 m_peer->GetFeatures( & features ) ;
8b573fb8 1085 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
facd6764
SC
1086}
1087
1088
e766c8a9 1089void wxWindowMac::SetFocus()
e9576ca5 1090{
6264b550
RR
1091 if ( AcceptsFocus() )
1092 {
7d0cfe71 1093
f1d527c1 1094 wxWindow* former = FindFocus() ;
7d0cfe71
SC
1095 if ( former == this )
1096 return ;
1097
5ca0d812 1098 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
f1d527c1
SC
1099 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1100 // leave in case of an error
1101 if ( err == errCouldntSetFocus )
1102 return ;
1103
1104#if !TARGET_API_MAC_OSX
1105 // emulate carbon events when running under carbonlib where they are not natively available
1106 if ( former )
1107 {
1108 EventRef evRef = NULL ;
1109 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1110 &evRef ) );
1111
1112 wxMacCarbonEvent cEvent( evRef ) ;
1113 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
1114 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
8b573fb8 1115
f1d527c1
SC
1116 wxMacWindowEventHandler( NULL , evRef , former ) ;
1117 ReleaseEvent(evRef) ;
6264b550 1118 }
f1d527c1 1119 // send new focus event
6264b550 1120 {
f1d527c1
SC
1121 EventRef evRef = NULL ;
1122 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1123 &evRef ) );
1124
1125 wxMacCarbonEvent cEvent( evRef ) ;
1126 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
1127 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
8b573fb8 1128
f1d527c1
SC
1129 wxMacWindowEventHandler( NULL , evRef , this ) ;
1130 ReleaseEvent(evRef) ;
6264b550 1131 }
f1d527c1 1132#endif
6264b550 1133 }
e9576ca5
SC
1134}
1135
e9576ca5 1136
4116c221 1137void wxWindowMac::DoCaptureMouse()
e9576ca5 1138{
519cb848 1139 wxTheApp->s_captureWindow = this ;
e9576ca5
SC
1140}
1141
90b959ae
SC
1142wxWindow* wxWindowBase::GetCapture()
1143{
1144 return wxTheApp->s_captureWindow ;
1145}
1146
4116c221 1147void wxWindowMac::DoReleaseMouse()
e9576ca5 1148{
519cb848 1149 wxTheApp->s_captureWindow = NULL ;
e9576ca5
SC
1150}
1151
e9576ca5
SC
1152#if wxUSE_DRAG_AND_DROP
1153
e766c8a9 1154void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
e9576ca5 1155{
e40298d5
JS
1156 if ( m_dropTarget != 0 ) {
1157 delete m_dropTarget;
1158 }
6ed71b4f 1159
e40298d5
JS
1160 m_dropTarget = pDropTarget;
1161 if ( m_dropTarget != 0 )
1162 {
1163 // TODO
1164 }
e9576ca5
SC
1165}
1166
1167#endif
1168
1169// Old style file-manager drag&drop
e766c8a9 1170void wxWindowMac::DragAcceptFiles(bool accept)
e9576ca5
SC
1171{
1172 // TODO
1173}
1174
055a486b
SC
1175// Returns the size of the native control. In the case of the toplevel window
1176// this is the content area root control
1177
facd6764 1178void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
8b573fb8 1179 int& w, int& h) const
e9576ca5 1180{
facd6764 1181 Rect bounds ;
8b573fb8 1182 m_peer->GetRect( &bounds ) ;
e9576ca5 1183
14c9cbdb 1184
facd6764
SC
1185 x = bounds.left ;
1186 y = bounds.top ;
1187 w = bounds.right - bounds.left ;
1188 h = bounds.bottom - bounds.top ;
e9576ca5
SC
1189}
1190
055a486b 1191// From a wx position / size calculate the appropriate size of the native control
8b573fb8 1192
facd6764
SC
1193bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
1194 const wxSize& size,
1195 int& x, int& y,
8b573fb8 1196 int& w, int& h , bool adjustOrigin ) const
51abe921 1197{
5ca0d812 1198 // the desired size, minus the border pixels gives the correct size of the control
8b573fb8 1199
facd6764
SC
1200 x = (int)pos.x;
1201 y = (int)pos.y;
1202 // todo the default calls may be used as soon as PostCreateControl Is moved here
1203 w = size.x ; // WidthDefault( size.x );
1204 h = size.y ; // HeightDefault( size.y ) ;
1205#if !TARGET_API_MAC_OSX
1206 GetParent()->MacWindowToRootWindow( &x , &y ) ;
1207#endif
5ca0d812
SC
1208
1209 x += MacGetLeftBorderSize() ;
1210 y += MacGetTopBorderSize() ;
1211 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1212 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
8b573fb8 1213
79392158
SC
1214 if ( adjustOrigin )
1215 AdjustForParentClientOrigin( x , y ) ;
7ebf5540
SC
1216#if TARGET_API_MAC_OSX
1217 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1218 if ( ! GetParent()->IsTopLevel() )
1219 {
1220 x -= GetParent()->MacGetLeftBorderSize() ;
1221 y -= GetParent()->MacGetTopBorderSize() ;
1222 }
1223#endif
facd6764
SC
1224 return true ;
1225}
1226
42ef83fa 1227// Get window size (not client size)
facd6764
SC
1228void wxWindowMac::DoGetSize(int *x, int *y) const
1229{
5ca0d812 1230 // take the size of the control and add the borders that have to be drawn outside
42ef83fa
SC
1231 int x1 , y1 , w1 , h1 ;
1232
facd6764 1233 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
42ef83fa 1234
5ca0d812
SC
1235 w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1236 h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
8b573fb8 1237
5ca0d812
SC
1238 if(x) *x = w1 ;
1239 if(y) *y = h1 ;
facd6764
SC
1240}
1241
42ef83fa 1242// get the position of the bounds of this window in client coordinates of its parent
facd6764
SC
1243void wxWindowMac::DoGetPosition(int *x, int *y) const
1244{
facd6764
SC
1245 int x1 , y1 , w1 ,h1 ;
1246 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
5ca0d812
SC
1247 x1 -= MacGetLeftBorderSize() ;
1248 y1 -= MacGetTopBorderSize() ;
42ef83fa
SC
1249 // to non-client
1250 #if !TARGET_API_MAC_OSX
1251 if ( !GetParent()->IsTopLevel() )
1252 {
1253 Rect bounds ;
1254 GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
1255 x1 -= bounds.left ;
1256 y1 -= bounds.top ;
1257 }
1258#endif
facd6764 1259 if ( !IsTopLevel() )
2b5f62a0 1260 {
facd6764
SC
1261 wxWindow *parent = GetParent();
1262 if ( parent )
8950f7cc 1263 {
1a02aff9
SC
1264 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1265 x1 += parent->MacGetLeftBorderSize() ;
1266 y1 += parent->MacGetTopBorderSize() ;
1267 // and now to client coordinates
facd6764
SC
1268 wxPoint pt(parent->GetClientAreaOrigin());
1269 x1 -= pt.x ;
1270 y1 -= pt.y ;
6ed71b4f 1271 }
2b5f62a0 1272 }
facd6764
SC
1273 if(x) *x = x1 ;
1274 if(y) *y = y1 ;
facd6764 1275}
51abe921 1276
e766c8a9 1277void wxWindowMac::DoScreenToClient(int *x, int *y) const
e9576ca5 1278{
facd6764 1279 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
8b573fb8 1280
facd6764 1281 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
8b573fb8 1282
facd6764
SC
1283 {
1284 Point localwhere = {0,0} ;
519cb848 1285
facd6764
SC
1286 if(x) localwhere.h = * x ;
1287 if(y) localwhere.v = * y ;
8b573fb8 1288
a9de2608 1289 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
facd6764
SC
1290 if(x) *x = localwhere.h ;
1291 if(y) *y = localwhere.v ;
6ed71b4f 1292
facd6764 1293 }
2078220e 1294 MacRootWindowToWindow( x , y ) ;
8b573fb8 1295
facd6764
SC
1296 wxPoint origin = GetClientAreaOrigin() ;
1297 if(x) *x -= origin.x ;
1298 if(y) *y -= origin.y ;
e9576ca5
SC
1299}
1300
e766c8a9 1301void wxWindowMac::DoClientToScreen(int *x, int *y) const
e9576ca5 1302{
facd6764
SC
1303 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1304 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
14c9cbdb 1305
facd6764
SC
1306 wxPoint origin = GetClientAreaOrigin() ;
1307 if(x) *x += origin.x ;
1308 if(y) *y += origin.y ;
14c9cbdb 1309
2078220e 1310 MacWindowToRootWindow( x , y ) ;
14c9cbdb 1311
facd6764
SC
1312 {
1313 Point localwhere = { 0,0 };
1314 if(x) localwhere.h = * x ;
1315 if(y) localwhere.v = * y ;
a9de2608 1316 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
facd6764
SC
1317 if(x) *x = localwhere.h ;
1318 if(y) *y = localwhere.v ;
1319 }
519cb848
SC
1320}
1321
e766c8a9 1322void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
519cb848 1323{
1c310985
SC
1324 wxPoint origin = GetClientAreaOrigin() ;
1325 if(x) *x += origin.x ;
1326 if(y) *y += origin.y ;
14c9cbdb 1327
1c310985
SC
1328 MacWindowToRootWindow( x , y ) ;
1329}
1330
1331void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1332{
1c310985 1333 MacRootWindowToWindow( x , y ) ;
facd6764
SC
1334
1335 wxPoint origin = GetClientAreaOrigin() ;
1c310985
SC
1336 if(x) *x -= origin.x ;
1337 if(y) *y -= origin.y ;
1338}
1339
1340void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1341{
facd6764 1342 #if TARGET_API_MAC_OSX
5ca0d812 1343 wxPoint pt ;
facd6764
SC
1344 if ( x ) pt.x = *x ;
1345 if ( y ) pt.y = *y ;
1346
125c7984 1347 if ( !IsTopLevel() )
5437ff47
RD
1348 {
1349 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1350 if (top)
5ca0d812
SC
1351 {
1352 pt.x -= MacGetLeftBorderSize() ;
1353 pt.y -= MacGetTopBorderSize() ;
1354 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1355 }
5437ff47 1356 }
8b573fb8 1357
facd6764
SC
1358 if ( x ) *x = (int) pt.x ;
1359 if ( y ) *y = (int) pt.y ;
1360 #else
1c310985 1361 if ( !IsTopLevel() )
6264b550 1362 {
facd6764 1363 Rect bounds ;
8b573fb8 1364 m_peer->GetRect( &bounds ) ;
055a486b
SC
1365 if(x) *x += bounds.left - MacGetLeftBorderSize() ;
1366 if(y) *y += bounds.top - MacGetTopBorderSize() ;
6264b550 1367 }
facd6764
SC
1368#endif
1369}
1370
1371void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1372{
1373 int x1 , y1 ;
1374 if ( x ) x1 = *x ;
1375 if ( y ) y1 = *y ;
1376 MacWindowToRootWindow( &x1 , &y1 ) ;
1377 if ( x ) *x = x1 ;
1378 if ( y ) *y = y1 ;
519cb848
SC
1379}
1380
1c310985 1381void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
519cb848 1382{
facd6764 1383 #if TARGET_API_MAC_OSX
5ca0d812 1384 wxPoint pt ;
facd6764
SC
1385 if ( x ) pt.x = *x ;
1386 if ( y ) pt.y = *y ;
1387
125c7984 1388 if ( !IsTopLevel() )
5ca0d812
SC
1389 {
1390 wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ;
1391 pt.x += MacGetLeftBorderSize() ;
1392 pt.y += MacGetTopBorderSize() ;
1393 }
8b573fb8 1394
facd6764
SC
1395 if ( x ) *x = (int) pt.x ;
1396 if ( y ) *y = (int) pt.y ;
1397 #else
1c310985 1398 if ( !IsTopLevel() )
6264b550 1399 {
facd6764 1400 Rect bounds ;
8b573fb8 1401 m_peer->GetRect( &bounds ) ;
055a486b
SC
1402 if(x) *x -= bounds.left + MacGetLeftBorderSize() ;
1403 if(y) *y -= bounds.top + MacGetTopBorderSize() ;
6264b550 1404 }
facd6764 1405#endif
e9576ca5
SC
1406}
1407
facd6764 1408void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
e9576ca5 1409{
facd6764
SC
1410 int x1 , y1 ;
1411 if ( x ) x1 = *x ;
1412 if ( y ) y1 = *y ;
1413 MacRootWindowToWindow( &x1 , &y1 ) ;
1414 if ( x ) *x = x1 ;
1415 if ( y ) *y = y1 ;
1416}
6ed71b4f 1417
29281095
SC
1418void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1419{
1420 RgnHandle rgn = NewRgn() ;
1421 Rect content ;
5ca0d812 1422 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
29281095
SC
1423 {
1424 GetRegionBounds( rgn , &content ) ;
29281095
SC
1425 }
1426 else
1427 {
5ca0d812 1428 m_peer->GetRect( &content ) ;
29281095 1429 }
7596e51d 1430 DisposeRgn( rgn ) ;
29281095 1431 Rect structure ;
5ca0d812 1432 m_peer->GetRect( &structure ) ;
8b573fb8 1433#if !TARGET_API_MAC_OSX
29281095
SC
1434 OffsetRect( &content , -structure.left , -structure.top ) ;
1435#endif
1436 left = content.left - structure.left ;
1437 top = content.top - structure.top ;
1438 right = structure.right - content.right ;
1439 bottom = structure.bottom - content.bottom ;
1440}
1441
facd6764
SC
1442wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1443{
1444 wxSize sizeTotal = size;
1445
1446 RgnHandle rgn = NewRgn() ;
1447
1448 Rect content ;
8b573fb8 1449
5ca0d812 1450 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
6618870d 1451 {
facd6764 1452 GetRegionBounds( rgn , &content ) ;
6618870d
SC
1453 }
1454 else
1455 {
5ca0d812 1456 m_peer->GetRect( &content ) ;
e40298d5 1457 }
7596e51d 1458 DisposeRgn( rgn ) ;
facd6764 1459 Rect structure ;
5ca0d812 1460 m_peer->GetRect( &structure ) ;
8b573fb8 1461#if !TARGET_API_MAC_OSX
facd6764
SC
1462 OffsetRect( &content , -structure.left , -structure.top ) ;
1463#endif
6ed71b4f 1464
facd6764 1465 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
8b573fb8 1466 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
6ed71b4f 1467
facd6764
SC
1468 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1469 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
6ed71b4f 1470
facd6764 1471 return sizeTotal;
e9576ca5
SC
1472}
1473
1474
1475// Get size *available for subwindows* i.e. excluding menu bar etc.
e766c8a9 1476void wxWindowMac::DoGetClientSize(int *x, int *y) const
e9576ca5 1477{
9453cf2b 1478 int ww, hh;
6ed71b4f 1479
facd6764
SC
1480 RgnHandle rgn = NewRgn() ;
1481 Rect content ;
5ca0d812 1482 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
facd6764
SC
1483 {
1484 GetRegionBounds( rgn , &content ) ;
facd6764
SC
1485 }
1486 else
1487 {
5ca0d812 1488 m_peer->GetRect( &content ) ;
facd6764 1489 }
7596e51d 1490 DisposeRgn( rgn ) ;
facd6764
SC
1491#if !TARGET_API_MAC_OSX
1492 Rect structure ;
5ca0d812 1493 m_peer->GetRect( &structure ) ;
facd6764 1494 OffsetRect( &content , -structure.left , -structure.top ) ;
8b573fb8 1495#endif
facd6764
SC
1496 ww = content.right - content.left ;
1497 hh = content.bottom - content.top ;
055a486b 1498 /*
6264b550
RR
1499 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1500 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
055a486b 1501 */
db7a550b 1502 /*
e40298d5
JS
1503 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1504 {
1505 int x1 = 0 ;
1506 int y1 = 0 ;
facd6764
SC
1507 int w ;
1508 int h ;
1509 GetSize( &w , &h ) ;
8b573fb8 1510
e40298d5
JS
1511 MacClientToRootWindow( &x1 , &y1 ) ;
1512 MacClientToRootWindow( &w , &h ) ;
6ed71b4f 1513
e40298d5 1514 wxWindowMac *iter = (wxWindowMac*)this ;
6ed71b4f 1515
e40298d5
JS
1516 int totW = 10000 , totH = 10000;
1517 while( iter )
6264b550 1518 {
e40298d5
JS
1519 if ( iter->IsTopLevel() )
1520 {
facd6764 1521 iter->GetSize( &totW , &totH ) ;
e40298d5
JS
1522 break ;
1523 }
6ed71b4f 1524
e40298d5 1525 iter = iter->GetParent() ;
6264b550 1526 }
6ed71b4f 1527
e40298d5 1528 if (m_hScrollBar && m_hScrollBar->IsShown() )
6264b550 1529 {
db7a550b 1530 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
e40298d5
JS
1531 if ( h-y1 >= totH )
1532 {
1533 hh += 1 ;
1534 }
6264b550 1535 }
e40298d5 1536 if (m_vScrollBar && m_vScrollBar->IsShown() )
6264b550 1537 {
db7a550b 1538 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
e40298d5
JS
1539 if ( w-x1 >= totW )
1540 {
1541 ww += 1 ;
1542 }
6264b550
RR
1543 }
1544 }
db7a550b
SC
1545 */
1546 if (m_hScrollBar && m_hScrollBar->IsShown() )
1547 {
1548 hh -= m_hScrollBar->GetSize().y ; // MAC_SCROLLBAR_SIZE ;
1549 }
1550 if (m_vScrollBar && m_vScrollBar->IsShown() )
1551 {
1552 ww -= m_vScrollBar->GetSize().x ; // MAC_SCROLLBAR_SIZE;
1553 }
e40298d5
JS
1554 if(x) *x = ww;
1555 if(y) *y = hh;
facd6764
SC
1556
1557}
1558
1559bool wxWindowMac::SetCursor(const wxCursor& cursor)
1560{
1561 if (m_cursor == cursor)
1562 return FALSE;
1563
1564 if (wxNullCursor == cursor)
1565 {
1566 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1567 return FALSE ;
1568 }
1569 else
1570 {
1571 if ( ! wxWindowBase::SetCursor( cursor ) )
1572 return FALSE ;
1573 }
1574
1575 wxASSERT_MSG( m_cursor.Ok(),
1576 wxT("cursor must be valid after call to the base version"));
8b573fb8
VZ
1577
1578
2d1760d3 1579 wxWindowMac *mouseWin = 0 ;
facd6764 1580 {
2d1760d3
SC
1581 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1582 CGrafPtr savePort ;
1583 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
8b573fb8 1584
2d1760d3
SC
1585 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1586 // position, use it...
8b573fb8 1587
2d1760d3
SC
1588 Point pt ;
1589 GetMouse( &pt ) ;
1590 ControlPartCode part ;
1591 ControlRef control ;
1592 control = wxMacFindControlUnderMouse( pt , window , &part ) ;
1593 if ( control )
1594 mouseWin = wxFindControlFromMacControl( control ) ;
8b573fb8 1595
2d1760d3
SC
1596 if ( swapped )
1597 QDSwapPort( savePort , NULL ) ;
facd6764 1598 }
2d1760d3
SC
1599
1600 if ( mouseWin == this && !wxIsBusy() )
facd6764
SC
1601 {
1602 m_cursor.MacInstall() ;
1603 }
1604
1605 return TRUE ;
519cb848
SC
1606}
1607
facd6764
SC
1608#if wxUSE_MENUS
1609bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1610{
1611 menu->SetInvokingWindow(this);
1612 menu->UpdateUI();
8b573fb8 1613
971562cb
VS
1614 if ( x == -1 && y == -1 )
1615 {
1616 wxPoint mouse = wxGetMousePosition();
1617 x = mouse.x; y = mouse.y;
1618 }
1619 else
1620 {
1621 ClientToScreen( &x , &y ) ;
1622 }
facd6764
SC
1623
1624 menu->MacBeforeDisplay( true ) ;
1625 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1626 if ( HiWord(menuResult) != 0 )
1627 {
1628 MenuCommand id ;
1629 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1630 wxMenuItem* item = NULL ;
1631 wxMenu* realmenu ;
1632 item = menu->FindItem(id, &realmenu) ;
1633 if (item->IsCheckable())
1634 {
1635 item->Check( !item->IsChecked() ) ;
1636 }
1637 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1638 }
1639 menu->MacAfterDisplay( true ) ;
1640
1641 menu->SetInvokingWindow(NULL);
1642
1643 return TRUE;
1644}
1645#endif
51abe921
SC
1646
1647// ----------------------------------------------------------------------------
1648// tooltips
1649// ----------------------------------------------------------------------------
1650
1651#if wxUSE_TOOLTIPS
1652
e766c8a9 1653void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
51abe921
SC
1654{
1655 wxWindowBase::DoSetToolTip(tooltip);
6ed71b4f 1656
6264b550
RR
1657 if ( m_tooltip )
1658 m_tooltip->SetWindow(this);
51abe921
SC
1659}
1660
1661#endif // wxUSE_TOOLTIPS
1662
e766c8a9 1663void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
51abe921 1664{
db7a550b 1665 // this is never called for a toplevel window, so we know we have a parent
facd6764 1666 int former_x , former_y , former_w, former_h ;
db7a550b
SC
1667
1668 // Get true coordinates of former position
facd6764
SC
1669 DoGetPosition( &former_x , &former_y ) ;
1670 DoGetSize( &former_w , &former_h ) ;
db7a550b
SC
1671
1672 wxWindow *parent = GetParent();
1673 if ( parent )
1674 {
1675 wxPoint pt(parent->GetClientAreaOrigin());
1676 former_x += pt.x ;
1677 former_y += pt.y ;
1678 }
6ed71b4f 1679
e40298d5
JS
1680 int actualWidth = width;
1681 int actualHeight = height;
1682 int actualX = x;
1683 int actualY = y;
6ed71b4f 1684
14c9cbdb 1685 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
6264b550 1686 actualWidth = m_minWidth;
14c9cbdb 1687 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
6264b550 1688 actualHeight = m_minHeight;
14c9cbdb 1689 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
6264b550 1690 actualWidth = m_maxWidth;
14c9cbdb 1691 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
6264b550 1692 actualHeight = m_maxHeight;
6ed71b4f 1693
6264b550
RR
1694 bool doMove = false ;
1695 bool doResize = false ;
6ed71b4f 1696
6264b550
RR
1697 if ( actualX != former_x || actualY != former_y )
1698 {
1699 doMove = true ;
1700 }
1701 if ( actualWidth != former_w || actualHeight != former_h )
1702 {
1703 doResize = true ;
1704 }
6ed71b4f 1705
6264b550
RR
1706 if ( doMove || doResize )
1707 {
79392158
SC
1708 // we don't adjust twice for the origin
1709 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
5ca0d812 1710 bool vis = m_peer->IsVisible();
8b573fb8 1711
d390fdcf
SC
1712 int outerBorder = MacGetLeftBorderSize() ;
1713 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
8b573fb8 1714 outerBorder += 4 ;
d390fdcf
SC
1715
1716 if ( vis && ( outerBorder > 0 ) )
1717 {
1718 // as the borders are drawn on the parent we have to properly invalidate all these areas
1719 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
8b573fb8 1720
d390fdcf
SC
1721 Rect rect ;
1722
1723 m_peer->GetRect( &rect ) ;
1724 RectRgn( updateInner , &rect ) ;
1725 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1726 RectRgn( updateOuter , &rect ) ;
1727 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
8b573fb8 1728 wxPoint parent(0,0);
c79aad8b
SC
1729#if TARGET_API_MAC_OSX
1730 // no offsetting needed when compositing
1731#else
d390fdcf
SC
1732 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1733 parent -= GetParent()->GetClientAreaOrigin() ;
1734 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
c79aad8b 1735#endif
8b573fb8
VZ
1736 CopyRgn( updateOuter , updateTotal ) ;
1737
d390fdcf
SC
1738 rect = r ;
1739 RectRgn( updateInner , &rect ) ;
1740 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1741 RectRgn( updateOuter , &rect ) ;
1742 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
7ebf5540
SC
1743
1744 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
8b573fb8 1745 UnionRgn( updateOuter , updateTotal , updateTotal ) ;
d390fdcf 1746
c79aad8b 1747 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
d390fdcf
SC
1748 DisposeRgn(updateOuter) ;
1749 DisposeRgn(updateInner) ;
1750 DisposeRgn(updateTotal) ;
1751 }
5ca0d812 1752
b05bf6ee
SC
1753 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1754 if ( vis )
5ca0d812 1755 m_peer->SetVisibility( false , true ) ;
d390fdcf 1756
8b573fb8 1757 m_peer->SetRect( &r ) ;
b05bf6ee 1758 if ( vis )
5ca0d812
SC
1759 m_peer->SetVisibility( true , true ) ;
1760
6264b550
RR
1761 MacRepositionScrollBars() ;
1762 if ( doMove )
1763 {
facd6764 1764 wxPoint point(actualX,actualY);
6264b550
RR
1765 wxMoveEvent event(point, m_windowId);
1766 event.SetEventObject(this);
1767 GetEventHandler()->ProcessEvent(event) ;
1768 }
1769 if ( doResize )
1770 {
e40298d5 1771 MacRepositionScrollBars() ;
facd6764 1772 wxSize size(actualWidth, actualHeight);
e40298d5
JS
1773 wxSizeEvent event(size, m_windowId);
1774 event.SetEventObject(this);
1775 GetEventHandler()->ProcessEvent(event);
6264b550
RR
1776 }
1777 }
6ed71b4f 1778
954fc50b
SC
1779}
1780
facd6764
SC
1781wxSize wxWindowMac::DoGetBestSize() const
1782{
eb69d46e
SC
1783 if ( m_macIsUserPane || IsTopLevel() )
1784 return wxWindowBase::DoGetBestSize() ;
8b573fb8 1785
facd6764 1786 Rect bestsize = { 0 , 0 , 0 , 0 } ;
facd6764 1787 int bestWidth, bestHeight ;
5ca0d812 1788 m_peer->GetBestRect( &bestsize ) ;
facd6764
SC
1789
1790 if ( EmptyRect( &bestsize ) )
1791 {
facd6764
SC
1792 bestsize.left = bestsize.top = 0 ;
1793 bestsize.right = 16 ;
1794 bestsize.bottom = 16 ;
1795 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1796 {
1797 bestsize.bottom = 16 ;
1798 }
e3e817d4 1799#if wxUSE_SPINBTN
facd6764
SC
1800 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1801 {
8b573fb8 1802 bestsize.bottom = 24 ;
facd6764 1803 }
e3e817d4 1804#endif // wxUSE_SPINBTN
facd6764
SC
1805 else
1806 {
8b573fb8 1807 // return wxWindowBase::DoGetBestSize() ;
facd6764
SC
1808 }
1809 }
1810
1811 bestWidth = bestsize.right - bestsize.left ;
1812 bestHeight = bestsize.bottom - bestsize.top ;
1813 if ( bestHeight < 10 )
1814 bestHeight = 13 ;
8b573fb8 1815
facd6764
SC
1816 return wxSize(bestWidth, bestHeight);
1817}
1818
1819
954fc50b
SC
1820// set the size of the window: if the dimensions are positive, just use them,
1821// but if any of them is equal to -1, it means that we must find the value for
1822// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1823// which case -1 is a valid value for x and y)
1824//
1825// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1826// the width/height to best suit our contents, otherwise we reuse the current
1827// width/height
1828void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1829{
1830 // get the current size and position...
1831 int currentX, currentY;
1832 GetPosition(&currentX, &currentY);
6ed71b4f 1833
954fc50b
SC
1834 int currentW,currentH;
1835 GetSize(&currentW, &currentH);
6ed71b4f 1836
954fc50b
SC
1837 // ... and don't do anything (avoiding flicker) if it's already ok
1838 if ( x == currentX && y == currentY &&
769ac869 1839 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
954fc50b 1840 {
facd6764 1841 // TODO REMOVE
6264b550 1842 MacRepositionScrollBars() ; // we might have a real position shift
954fc50b
SC
1843 return;
1844 }
6ed71b4f 1845
954fc50b
SC
1846 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1847 x = currentX;
1848 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1849 y = currentY;
6ed71b4f 1850
954fc50b 1851 AdjustForParentClientOrigin(x, y, sizeFlags);
6ed71b4f 1852
954fc50b
SC
1853 wxSize size(-1, -1);
1854 if ( width == -1 )
1855 {
1856 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1857 {
1858 size = DoGetBestSize();
1859 width = size.x;
1860 }
1861 else
1862 {
1863 // just take the current one
1864 width = currentW;
1865 }
1866 }
6ed71b4f 1867
954fc50b
SC
1868 if ( height == -1 )
1869 {
1870 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1871 {
1872 if ( size.x == -1 )
1873 {
1874 size = DoGetBestSize();
1875 }
1876 //else: already called DoGetBestSize() above
6ed71b4f 1877
954fc50b
SC
1878 height = size.y;
1879 }
1880 else
1881 {
1882 // just take the current one
1883 height = currentH;
1884 }
1885 }
6ed71b4f 1886
954fc50b 1887 DoMoveWindow(x, y, width, height);
6ed71b4f 1888
e9576ca5 1889}
519cb848 1890
e766c8a9 1891wxPoint wxWindowMac::GetClientAreaOrigin() const
e9576ca5 1892{
facd6764
SC
1893 RgnHandle rgn = NewRgn() ;
1894 Rect content ;
5ca0d812 1895 m_peer->GetRegion( kControlContentMetaPart , rgn ) ;
facd6764
SC
1896 GetRegionBounds( rgn , &content ) ;
1897 DisposeRgn( rgn ) ;
1898#if !TARGET_API_MAC_OSX
736fac3a
SC
1899 // if the content rgn is empty / not supported
1900 // don't attempt to correct the coordinates to wxWindow relative ones
1901 if (!::EmptyRect( &content ) )
1902 {
1903 Rect structure ;
5ca0d812 1904 m_peer->GetRect( &structure ) ;
736fac3a
SC
1905 OffsetRect( &content , -structure.left , -structure.top ) ;
1906 }
8b573fb8 1907#endif
facd6764
SC
1908
1909 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1910}
1911
1912void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1913{
1914 if ( clientheight != -1 || clientheight != -1 )
1915 {
1916 int currentclientwidth , currentclientheight ;
1917 int currentwidth , currentheight ;
1918
1919 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1920 GetSize( &currentwidth , &currentheight ) ;
1921
1922 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1923 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1924 }
e9576ca5
SC
1925}
1926
d84afea9 1927void wxWindowMac::SetTitle(const wxString& title)
e9576ca5 1928{
facd6764
SC
1929 m_label = wxStripMenuCodes(title) ;
1930
21fd5529 1931 if ( m_peer && m_peer->Ok() )
facd6764 1932 {
5ca0d812 1933 m_peer->SetTitle( m_label ) ;
facd6764
SC
1934 }
1935 Refresh() ;
519cb848
SC
1936}
1937
d84afea9 1938wxString wxWindowMac::GetTitle() const
519cb848 1939{
ed60b502 1940 return m_label ;
519cb848
SC
1941}
1942
8ab50549
SC
1943bool wxWindowMac::Show(bool show)
1944{
1945 if ( !wxWindowBase::Show(show) )
1946 return FALSE;
8b573fb8 1947
8ab50549 1948 // TODO use visibilityChanged Carbon Event for OSX
2c899c20
SC
1949 if ( m_peer )
1950 {
1951 bool former = MacIsReallyShown() ;
8b573fb8 1952
2c899c20
SC
1953 m_peer->SetVisibility( show , true ) ;
1954 if ( former != MacIsReallyShown() )
1955 MacPropagateVisibilityChanged() ;
1956 }
8ab50549
SC
1957 return TRUE;
1958}
1959
1960bool wxWindowMac::Enable(bool enable)
1961{
21fd5529 1962 wxASSERT( m_peer->Ok() ) ;
8ab50549
SC
1963 if ( !wxWindowBase::Enable(enable) )
1964 return FALSE;
1965
1966 bool former = MacIsReallyEnabled() ;
5ca0d812 1967 m_peer->Enable( enable ) ;
8ab50549
SC
1968
1969 if ( former != MacIsReallyEnabled() )
1970 MacPropagateEnabledStateChanged() ;
1971 return TRUE;
1972}
1973
8b573fb8 1974//
8ab50549
SC
1975// status change propagations (will be not necessary for OSX later )
1976//
1977
facd6764
SC
1978void wxWindowMac::MacPropagateVisibilityChanged()
1979{
73fe67bd 1980#if !TARGET_API_MAC_OSX
facd6764 1981 MacVisibilityChanged() ;
8b573fb8 1982
71f2fb52 1983 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
facd6764
SC
1984 while ( node )
1985 {
1986 wxWindowMac *child = node->GetData();
1987 if ( child->IsShown() )
1988 child->MacPropagateVisibilityChanged( ) ;
1989 node = node->GetNext();
1990 }
73fe67bd 1991#endif
facd6764
SC
1992}
1993
8ab50549 1994void wxWindowMac::MacPropagateEnabledStateChanged( )
e9576ca5 1995{
73fe67bd 1996#if !TARGET_API_MAC_OSX
8ab50549 1997 MacEnabledStateChanged() ;
8b573fb8 1998
71f2fb52 1999 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
8ab50549
SC
2000 while ( node )
2001 {
2002 wxWindowMac *child = node->GetData();
2003 if ( child->IsEnabled() )
2004 child->MacPropagateEnabledStateChanged() ;
2005 node = node->GetNext();
2006 }
73fe67bd 2007#endif
8ab50549
SC
2008}
2009
2010void wxWindowMac::MacPropagateHiliteChanged( )
2011{
73fe67bd 2012#if !TARGET_API_MAC_OSX
8ab50549 2013 MacHiliteChanged() ;
8b573fb8 2014
71f2fb52 2015 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
8ab50549
SC
2016 while ( node )
2017 {
2018 wxWindowMac *child = node->GetData();
2019 // if ( child->IsEnabled() )
2020 child->MacPropagateHiliteChanged() ;
2021 node = node->GetNext();
2022 }
73fe67bd 2023#endif
8ab50549
SC
2024}
2025
2026//
2027// status change notifications
8b573fb8 2028//
8ab50549 2029
8b573fb8 2030void wxWindowMac::MacVisibilityChanged()
8ab50549
SC
2031{
2032}
2033
8b573fb8 2034void wxWindowMac::MacHiliteChanged()
8ab50549
SC
2035{
2036}
2037
8b573fb8 2038void wxWindowMac::MacEnabledStateChanged()
8ab50549 2039{
facd6764 2040}
e7549107 2041
8ab50549
SC
2042//
2043// status queries on the inherited window's state
2044//
2045
8b573fb8 2046bool wxWindowMac::MacIsReallyShown()
facd6764
SC
2047{
2048 // only under OSX the visibility of the TLW is taken into account
66ffb23b
SC
2049 if ( m_isBeingDeleted )
2050 return false ;
2051
facd6764 2052#if TARGET_API_MAC_OSX
aa522e33
SC
2053 if ( m_peer && m_peer->Ok() )
2054 return m_peer->IsVisible();
2055#endif
facd6764
SC
2056 wxWindow* win = this ;
2057 while( win->IsShown() )
2058 {
2059 if ( win->IsTopLevel() )
2060 return true ;
8b573fb8 2061
facd6764
SC
2062 win = win->GetParent() ;
2063 if ( win == NULL )
2064 return true ;
8b573fb8 2065
facd6764
SC
2066 } ;
2067 return false ;
facd6764 2068}
4241baae 2069
8b573fb8 2070bool wxWindowMac::MacIsReallyEnabled()
facd6764 2071{
5ca0d812 2072 return m_peer->IsEnabled() ;
facd6764
SC
2073}
2074
8b573fb8 2075bool wxWindowMac::MacIsReallyHilited()
c809f3be 2076{
5ca0d812 2077 return m_peer->IsActive();
c809f3be
SC
2078}
2079
8b573fb8 2080void wxWindowMac::MacFlashInvalidAreas()
002c9672
SC
2081{
2082#if TARGET_API_MAC_OSX
2083 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2084#endif
2085}
2086
8ab50549
SC
2087//
2088//
2089//
2090
e766c8a9 2091int wxWindowMac::GetCharHeight() const
e9576ca5 2092{
6264b550
RR
2093 wxClientDC dc ( (wxWindowMac*)this ) ;
2094 return dc.GetCharHeight() ;
e9576ca5
SC
2095}
2096
e766c8a9 2097int wxWindowMac::GetCharWidth() const
e9576ca5 2098{
6264b550
RR
2099 wxClientDC dc ( (wxWindowMac*)this ) ;
2100 return dc.GetCharWidth() ;
e9576ca5
SC
2101}
2102
e766c8a9 2103void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 2104 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 2105{
e7549107
SC
2106 const wxFont *fontToUse = theFont;
2107 if ( !fontToUse )
2108 fontToUse = &m_font;
14c9cbdb 2109
e766c8a9 2110 wxClientDC dc( (wxWindowMac*) this ) ;
7c74e7fe 2111 long lx,ly,ld,le ;
5fde6fcc 2112 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2f1ae414 2113 if ( externalLeading )
6264b550 2114 *externalLeading = le ;
2f1ae414 2115 if ( descent )
6264b550 2116 *descent = ld ;
2f1ae414 2117 if ( x )
6264b550 2118 *x = lx ;
2f1ae414 2119 if ( y )
6264b550 2120 *y = ly ;
e9576ca5
SC
2121}
2122
0a67a93b 2123/*
14c9cbdb 2124 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1c310985
SC
2125 * we always intersect with the entire window, not only with the client area
2126 */
14c9cbdb 2127
e766c8a9 2128void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
e9576ca5 2129{
065ab451
SC
2130 if ( m_peer == NULL )
2131 return ;
8b573fb8 2132
facd6764 2133#if TARGET_API_MAC_OSX
1e8cde71 2134 if ( rect == NULL )
8b573fb8 2135 m_peer->SetNeedsDisplay( true ) ;
1e8cde71
SC
2136 else
2137 {
2138 RgnHandle update = NewRgn() ;
2139 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
84f6927e
SC
2140 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
2141 wxPoint origin = GetClientAreaOrigin() ;
8b573fb8 2142 OffsetRgn( update, origin.x , origin.y ) ;
db7a550b
SC
2143 // right now this is wx' window coordinates, as our native peer does not have borders, this is
2144 // inset
2145 OffsetRgn( update , -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
8b573fb8
VZ
2146 m_peer->SetNeedsDisplay( true , update) ;
2147 DisposeRgn( update ) ;
1e8cde71 2148 }
facd6764 2149#else
a9825a9b
SC
2150/*
2151 RgnHandle updateRgn = NewRgn() ;
2152 if ( rect == NULL )
2153 {
2154 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
2155 }
2156 else
2157 {
2158 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
8b573fb8 2159 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
a9825a9b
SC
2160 }
2161 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
2162 DisposeRgn(updateRgn) ;
2163*/
5ca0d812 2164 if ( m_peer->IsVisible())
facd6764 2165 {
5ca0d812
SC
2166 m_peer->SetVisibility( false , false ) ;
2167 m_peer->SetVisibility( true , true ) ;
facd6764
SC
2168 }
2169 /*
94abc21f 2170 if ( MacGetTopLevelWindow() == NULL )
9a456218 2171 return ;
14c9cbdb 2172
5ca0d812 2173 if ( !m_peer->IsVisible())
8b573fb8
VZ
2174 return ;
2175
c3a05e8a 2176 wxPoint client = GetClientAreaOrigin();
9a456218
RR
2177 int x1 = -client.x;
2178 int y1 = -client.y;
2179 int x2 = m_width - client.x;
2180 int y2 = m_height - client.y;
2181
2182 if (IsKindOf( CLASSINFO(wxButton)))
2183 {
2184 // buttons have an "aura"
2185 y1 -= 5;
2186 x1 -= 5;
2187 y2 += 5;
2188 x2 += 5;
2189 }
2190
2191 Rect clientrect = { y1, x1, y2, x2 };
14c9cbdb 2192
1c310985 2193 if ( rect )
6264b550 2194 {
1c310985 2195 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
14c9cbdb 2196 SectRect( &clientrect , &r , &clientrect ) ;
6264b550 2197 }
14c9cbdb 2198
1c310985 2199 if ( !EmptyRect( &clientrect ) )
e9576ca5 2200 {
1c310985 2201 int top = 0 , left = 0 ;
14c9cbdb 2202
1c310985
SC
2203 MacClientToRootWindow( &left , &top ) ;
2204 OffsetRect( &clientrect , left , top ) ;
14c9cbdb 2205
1c310985 2206 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
e9576ca5 2207 }
facd6764
SC
2208 */
2209#endif
2210}
2211
79392158
SC
2212void wxWindowMac::Freeze()
2213{
2214#if TARGET_API_MAC_OSX
2215 if ( !m_frozenness++ )
2216 {
52ef5c3c
RD
2217 if ( m_peer && m_peer->Ok() )
2218 m_peer->SetDrawingEnabled( false ) ;
79392158
SC
2219 }
2220#endif
2221}
2222
b175b96b 2223
79392158
SC
2224void wxWindowMac::Thaw()
2225{
2226#if TARGET_API_MAC_OSX
2227 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
2228
2229 if ( !--m_frozenness )
2230 {
52ef5c3c
RD
2231 if ( m_peer && m_peer->Ok() )
2232 {
2233 m_peer->SetDrawingEnabled( true ) ;
2234 m_peer->InvalidateWithChildren() ;
2235 }
79392158
SC
2236 }
2237#endif
2238}
2239
e766c8a9 2240wxWindowMac *wxGetActiveWindow()
e9576ca5 2241{
519cb848 2242 // actually this is a windows-only concept
e9576ca5
SC
2243 return NULL;
2244}
2245
e9576ca5 2246// Coordinates relative to the window
e766c8a9 2247void wxWindowMac::WarpPointer (int x_pos, int y_pos)
e9576ca5 2248{
e40298d5 2249 // We really don't move the mouse programmatically under Mac.
e9576ca5
SC
2250}
2251
facd6764 2252void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
e9576ca5 2253{
be346c26 2254#if TARGET_API_MAC_OSX
facd6764 2255 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
94abc21f 2256 {
facd6764 2257 event.Skip() ;
94abc21f
SC
2258 }
2259 else
be346c26 2260#endif
7ebf5540 2261 {
8b573fb8 2262 event.GetDC()->Clear() ;
7ebf5540 2263 }
1c310985
SC
2264}
2265
2266void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2267{
af6b7b80 2268 event.Skip() ;
e9576ca5
SC
2269}
2270
e766c8a9 2271int wxWindowMac::GetScrollPos(int orient) const
e9576ca5 2272{
1c310985
SC
2273 if ( orient == wxHORIZONTAL )
2274 {
2275 if ( m_hScrollBar )
2276 return m_hScrollBar->GetThumbPosition() ;
2277 }
2278 else
2279 {
2280 if ( m_vScrollBar )
2281 return m_vScrollBar->GetThumbPosition() ;
2282 }
e9576ca5
SC
2283 return 0;
2284}
2285
2286// This now returns the whole range, not just the number
2287// of positions that we can scroll.
e766c8a9 2288int wxWindowMac::GetScrollRange(int orient) const
e9576ca5 2289{
1c310985
SC
2290 if ( orient == wxHORIZONTAL )
2291 {
2292 if ( m_hScrollBar )
2293 return m_hScrollBar->GetRange() ;
2294 }
2295 else
2296 {
2297 if ( m_vScrollBar )
2298 return m_vScrollBar->GetRange() ;
2299 }
e9576ca5
SC
2300 return 0;
2301}
2302
e766c8a9 2303int wxWindowMac::GetScrollThumb(int orient) const
e9576ca5 2304{
1c310985
SC
2305 if ( orient == wxHORIZONTAL )
2306 {
2307 if ( m_hScrollBar )
2308 return m_hScrollBar->GetThumbSize() ;
2309 }
2310 else
2311 {
2312 if ( m_vScrollBar )
2313 return m_vScrollBar->GetThumbSize() ;
2314 }
e9576ca5
SC
2315 return 0;
2316}
2317
e766c8a9 2318void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
e9576ca5 2319{
1c310985 2320 if ( orient == wxHORIZONTAL )
6264b550 2321 {
1c310985
SC
2322 if ( m_hScrollBar )
2323 m_hScrollBar->SetThumbPosition( pos ) ;
6264b550
RR
2324 }
2325 else
2326 {
1c310985
SC
2327 if ( m_vScrollBar )
2328 m_vScrollBar->SetThumbPosition( pos ) ;
6264b550 2329 }
2f1ae414
SC
2330}
2331
c79aad8b
SC
2332//
2333// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2334// our own window origin is at leftOrigin/rightOrigin
2335//
2336
2337void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2f1ae414 2338{
1c310985 2339 if( IsTopLevel() )
6264b550 2340 return ;
8b573fb8 2341
fd926bcc 2342 Rect rect ;
c79aad8b
SC
2343 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2344 bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2345
8b573fb8 2346 m_peer->GetRect( &rect ) ;
fd926bcc
SC
2347 InsetRect( &rect, -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
2348
c79aad8b
SC
2349#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2350 if ( HIThemeDrawFrame != 0)
2351 {
2352 Rect srect = rect ;
2353 HIThemeFrameDrawInfo info ;
2354 memset( &info, 0 , sizeof( info ) ) ;
2355
2356 info.version = 0 ;
2357 info.kind = 0 ;
2358 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2359 info.isFocused = hasFocus ;
2360 bool draw = false ;
2361
2362 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2363 wxASSERT( cgContext ) ;
2364
2365 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2366 {
2367 SInt32 border = 0 ;
2368 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2369 InsetRect( &srect , border , border );
2370 info.kind = kHIThemeFrameTextFieldSquare ;
2371 draw = true ;
2372 }
2373 else if (HasFlag(wxSIMPLE_BORDER))
2374 {
2375 SInt32 border = 0 ;
2376 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2377 InsetRect( &srect , border , border );
2378 info.kind = kHIThemeFrameListBox ;
2379 draw = true ;
2380 }
2381
2382 if ( draw )
2383 {
2384 CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
2385 srect.bottom - srect.top ) ;
2386 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2387 }
2388 else if ( hasFocus )
2389 {
2390 srect = rect ;
2391 CGRect cgrect = CGRectMake( srect.left , srect.top , srect.right - srect.left ,
2392 srect.bottom - srect.top ) ;
2393 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2394 }
2395
2396 m_peer->GetRect( &rect ) ;
2397 if ( hasBothScrollbars )
2398 {
2399 srect = rect ;
2400 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
2401 CGRect cgrect = CGRectMake( srect.right - size , srect.bottom - size , size , size ) ;
2402 CGPoint cgpoint = CGPointMake( srect.right - size , srect.bottom - size ) ;
2403 HIThemeGrowBoxDrawInfo info ;
2404 memset( &info, 0 , sizeof( info ) ) ;
2405 info.version = 0 ;
2406 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2407 info.kind = kHIThemeGrowBoxKindNone ;
2408 info.size = kHIThemeGrowBoxSizeNormal ;
2409 info.direction = kThemeGrowRight | kThemeGrowDown ;
2410 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2411 }
2412 }
2413 else
2414#endif
fd926bcc
SC
2415 {
2416 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2417 if (top)
2418 {
2419 wxPoint pt(0,0) ;
2420 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
2421 rect.left += pt.x ;
2422 rect.right += pt.x ;
2423 rect.top += pt.y ;
2424 rect.bottom += pt.y ;
2425 }
8b573fb8 2426
c79aad8b
SC
2427 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2428 {
2429 Rect srect = rect ;
2430 SInt32 border = 0 ;
2431 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2432 InsetRect( &srect , border , border );
2433 DrawThemeEditTextFrame(&srect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2434 }
2435 else if (HasFlag(wxSIMPLE_BORDER))
2436 {
2437 Rect srect = rect ;
2438 SInt32 border = 0 ;
2439 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2440 InsetRect( &srect , border , border );
2441 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2442 }
2443
2444 if ( hasFocus )
2445 {
2446 Rect srect = rect ;
2447 DrawThemeFocusRect( &srect , true ) ;
2448 }
2449 if ( hasBothScrollbars )
2450 {
2451 // GetThemeStandaloneGrowBoxBounds
2452 //DrawThemeStandaloneNoGrowBox
2453 }
eec462f8 2454 }
8208e181
SC
2455}
2456
abda5788
SC
2457void wxWindowMac::RemoveChild( wxWindowBase *child )
2458{
2459 if ( child == m_hScrollBar )
2460 m_hScrollBar = NULL ;
2461 if ( child == m_vScrollBar )
2462 m_vScrollBar = NULL ;
14c9cbdb 2463
abda5788
SC
2464 wxWindowBase::RemoveChild( child ) ;
2465}
2466
e9576ca5 2467// New function that will replace some of the above.
e766c8a9 2468void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
e9576ca5
SC
2469 int range, bool refresh)
2470{
e40298d5
JS
2471 if ( orient == wxHORIZONTAL )
2472 {
2473 if ( m_hScrollBar )
6264b550 2474 {
e40298d5 2475 if ( range == 0 || thumbVisible >= range )
6264b550 2476 {
e40298d5
JS
2477 if ( m_hScrollBar->IsShown() )
2478 m_hScrollBar->Show(false) ;
2479 }
2480 else
2481 {
2482 if ( !m_hScrollBar->IsShown() )
2483 m_hScrollBar->Show(true) ;
6264b550 2484 }
11ca2edf 2485 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
6264b550 2486 }
e40298d5
JS
2487 }
2488 else
2489 {
2490 if ( m_vScrollBar )
6264b550 2491 {
e40298d5 2492 if ( range == 0 || thumbVisible >= range )
6264b550 2493 {
e40298d5
JS
2494 if ( m_vScrollBar->IsShown() )
2495 m_vScrollBar->Show(false) ;
2496 }
2497 else
2498 {
2499 if ( !m_vScrollBar->IsShown() )
2500 m_vScrollBar->Show(true) ;
6264b550 2501 }
11ca2edf 2502 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
6264b550 2503 }
e40298d5
JS
2504 }
2505 MacRepositionScrollBars() ;
e9576ca5
SC
2506}
2507
2508// Does a physical scroll
e766c8a9 2509void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
e9576ca5 2510{
ba87f54c
SC
2511 if( dx == 0 && dy ==0 )
2512 return ;
8b573fb8 2513
6ed71b4f 2514
6264b550 2515 {
adb8a71b 2516
6264b550
RR
2517 int width , height ;
2518 GetClientSize( &width , &height ) ;
adb8a71b 2519#if TARGET_API_MAC_OSX
002c9672 2520 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
8b573fb8 2521 // area is scrolled, this does not occur if width and height are 2 pixels less,
002c9672 2522 // TODO write optimal workaround
42ef83fa 2523 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
8b573fb8 2524 if ( rect )
adb8a71b 2525 {
5ca0d812 2526 scrollrect.Intersect( *rect ) ;
adb8a71b 2527 }
5ca0d812 2528 if ( m_peer->GetNeedsDisplay() )
002c9672
SC
2529 {
2530 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2531 // either immediate redraw or full invalidate
2532#if 1
2533 // is the better overall solution, as it does not slow down scrolling
5ca0d812 2534 m_peer->SetNeedsDisplay( true ) ;
002c9672 2535#else
8b573fb8 2536 // this would be the preferred version for fast drawing controls
002c9672
SC
2537 if( UMAGetSystemVersion() < 0x1030 )
2538 Update() ;
2539 else
42ef83fa 2540 HIViewRender(m_peer->GetControlRef()) ;
002c9672
SC
2541#endif
2542 }
84e5d27d
SC
2543 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2544 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
5ca0d812 2545 m_peer->ScrollRect( scrollrect , dx , dy ) ;
adb8a71b 2546#else
6ed71b4f 2547
facd6764 2548 wxPoint pos;
8b573fb8 2549 pos.x = pos.y = 0;
430e1eed 2550
facd6764 2551 Rect scrollrect;
6264b550 2552 RgnHandle updateRgn = NewRgn() ;
430e1eed 2553
adb8a71b 2554 {
430e1eed
SC
2555 wxClientDC dc(this) ;
2556 wxMacPortSetter helper(&dc) ;
8b573fb8 2557
5ca0d812 2558 m_peer->GetRect( &scrollrect ) ;
430e1eed
SC
2559 scrollrect.top += MacGetTopBorderSize() ;
2560 scrollrect.left += MacGetLeftBorderSize() ;
2561 scrollrect.bottom = scrollrect.top + height ;
2562 scrollrect.right = scrollrect.left + width ;
8b573fb8 2563
430e1eed
SC
2564 if ( rect )
2565 {
2566 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2567 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2568 SectRect( &scrollrect , &r , &scrollrect ) ;
2569 }
2570 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
20b69855
SC
2571
2572 // now scroll the former update region as well and add the new update region
2573
2574 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2575 RgnHandle formerUpdateRgn = NewRgn() ;
2576 RgnHandle scrollRgn = NewRgn() ;
2577 RectRgn( scrollRgn , &scrollrect ) ;
2578 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2579 Point pt = {0,0} ;
2580 LocalToGlobal( &pt ) ;
2581 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2582 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2583 if ( !EmptyRgn( formerUpdateRgn ) )
2584 {
2585 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2586 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2587 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2588 }
2589 InvalWindowRgn(rootWindow , updateRgn ) ;
2590 DisposeRgn( updateRgn ) ;
2591 DisposeRgn( formerUpdateRgn ) ;
2592 DisposeRgn( scrollRgn ) ;
ba87f54c 2593 }
facd6764 2594#endif
6264b550 2595 }
6ed71b4f 2596
71f2fb52 2597 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
6264b550 2598 {
9bd1404d 2599 wxWindowMac *child = node->GetData();
6264b550
RR
2600 if (child == m_vScrollBar) continue;
2601 if (child == m_hScrollBar) continue;
2602 if (child->IsTopLevel()) continue;
6ed71b4f 2603
6264b550
RR
2604 int x,y;
2605 child->GetPosition( &x, &y );
2606 int w,h;
2607 child->GetSize( &w, &h );
00f55394
SC
2608 if (rect)
2609 {
2610 wxRect rc(x,y,w,h);
2611 if (rect->Intersects(rc))
2612 child->SetSize( x+dx, y+dy, w, h );
2613 }
2614 else
2615 {
8b573fb8
VZ
2616 child->SetSize( x+dx, y+dy, w, h );
2617 }
6264b550 2618 }
e9576ca5
SC
2619}
2620
e766c8a9 2621void wxWindowMac::MacOnScroll(wxScrollEvent &event )
7c74e7fe 2622{
687706f5 2623 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
6264b550
RR
2624 {
2625 wxScrollWinEvent wevent;
2626 wevent.SetPosition(event.GetPosition());
2627 wevent.SetOrientation(event.GetOrientation());
687706f5
KH
2628 wevent.SetEventObject(this);
2629
2630 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2631 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2632 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2633 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2634 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2635 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2636 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2637 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2638 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2639 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2640 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2641 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2642 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2643 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2644 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2645 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
6ed71b4f
VZ
2646
2647 GetEventHandler()->ProcessEvent(wevent);
7c74e7fe
SC
2648 }
2649}
2650
e9576ca5 2651// Get the window with the focus
0fe02759 2652wxWindowMac *wxWindowBase::DoFindFocus()
e9576ca5 2653{
f1d527c1
SC
2654 ControlRef control ;
2655 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2656 return wxFindControlFromMacControl( control ) ;
519cb848
SC
2657}
2658
e766c8a9 2659void wxWindowMac::OnSetFocus(wxFocusEvent& event)
7810c95b
SC
2660{
2661 // panel wants to track the window which was the last to have focus in it,
2662 // so we want to set ourselves as the window which last had focus
2663 //
2664 // notice that it's also important to do it upwards the tree becaus
2665 // otherwise when the top level panel gets focus, it won't set it back to
2666 // us, but to some other sibling
6ed71b4f 2667
c1fb8167
SC
2668 // CS:don't know if this is still needed:
2669 //wxChildFocusEvent eventFocus(this);
2670 //(void)GetEventHandler()->ProcessEvent(eventFocus);
7810c95b 2671
5ca0d812
SC
2672 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2673 {
ff3795ee 2674 #if !wxMAC_USE_CORE_GRAPHICS
788e118f 2675 wxMacWindowStateSaver sv( this ) ;
5ca0d812
SC
2676
2677 int w , h ;
788e118f
SC
2678 int x , y ;
2679 x = y = 0 ;
2680 MacWindowToRootWindow( &x , &y ) ;
5ca0d812 2681 GetSize( &w , &h ) ;
788e118f 2682 Rect rect = {y , x , h + y , w + x } ;
5ca0d812
SC
2683
2684 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2685 DrawThemeFocusRect( &rect , true ) ;
2686 else
af6b7b80 2687 {
5ca0d812 2688 DrawThemeFocusRect( &rect , false ) ;
8b573fb8 2689
af6b7b80 2690 // as this erases part of the frame we have to redraw borders
101634b2
SC
2691 // and because our z-ordering is not always correct (staticboxes)
2692 // we have to invalidate things, we cannot simple redraw
2693 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
2694 RectRgn( updateInner , &rect ) ;
2695 InsetRect( &rect , -4 , -4 ) ;
2696 RectRgn( updateOuter , &rect ) ;
2697 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
8b573fb8 2698 wxPoint parent(0,0);
101634b2
SC
2699 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
2700 parent -= GetParent()->GetClientAreaOrigin() ;
2701 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
2702 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
2703 DisposeRgn(updateOuter) ;
2704 DisposeRgn(updateInner) ;
af6b7b80 2705 }
ff3795ee
SC
2706#else
2707 GetParent()->Refresh() ;
2708#endif
5ca0d812
SC
2709 }
2710
7810c95b
SC
2711 event.Skip();
2712}
2713
e39af974 2714void wxWindowMac::OnInternalIdle()
e9576ca5 2715{
e9576ca5
SC
2716 // This calls the UI-update mechanism (querying windows for
2717 // menu/toolbar/control state information)
e39af974
JS
2718 if (wxUpdateUIEvent::CanUpdate(this))
2719 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
e9576ca5
SC
2720}
2721
2722// Raise the window to the top of the Z order
e766c8a9 2723void wxWindowMac::Raise()
e9576ca5 2724{
5ca0d812 2725 m_peer->SetZOrder( true , NULL ) ;
e9576ca5
SC
2726}
2727
2728// Lower the window to the bottom of the Z order
e766c8a9 2729void wxWindowMac::Lower()
e9576ca5 2730{
5ca0d812 2731 m_peer->SetZOrder( false , NULL ) ;
e9576ca5
SC
2732}
2733
6ed71b4f 2734
facd6764 2735// static wxWindow *gs_lastWhich = NULL;
519cb848 2736
7de59551 2737bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
467e3168
SC
2738{
2739 // first trigger a set cursor event
6ed71b4f 2740
467e3168
SC
2741 wxPoint clientorigin = GetClientAreaOrigin() ;
2742 wxSize clientsize = GetClientSize() ;
2743 wxCursor cursor ;
2744 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
7de59551 2745 {
467e3168 2746 wxSetCursorEvent event( pt.x , pt.y );
6ed71b4f 2747
467e3168
SC
2748 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2749 if ( processedEvtSetCursor && event.HasCursor() )
2750 {
e40298d5 2751 cursor = event.GetCursor() ;
467e3168
SC
2752 }
2753 else
2754 {
6ed71b4f 2755
467e3168
SC
2756 // the test for processedEvtSetCursor is here to prevent using m_cursor
2757 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2758 // it - this is a way to say that our cursor shouldn't be used for this
2759 // point
2760 if ( !processedEvtSetCursor && m_cursor.Ok() )
2761 {
2762 cursor = m_cursor ;
2763 }
2764 if ( wxIsBusy() )
2765 {
2766 }
2767 else
2768 {
2769 if ( !GetParent() )
2770 cursor = *wxSTANDARD_CURSOR ;
2771 }
2772 }
2773 if ( cursor.Ok() )
2774 cursor.MacInstall() ;
2775 }
2776 return cursor.Ok() ;
2777}
2778
e766c8a9 2779wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2f1ae414 2780{
6264b550
RR
2781 if ( m_tooltip )
2782 {
2783 return m_tooltip->GetTip() ;
2784 }
427ff662 2785 return wxEmptyString ;
2f1ae414 2786}
6264b550 2787
cb4b0966
SC
2788void wxWindowMac::ClearBackground()
2789{
2790 Refresh() ;
2791 Update() ;
2792}
2793
1c310985 2794void wxWindowMac::Update()
519cb848 2795{
facd6764 2796#if TARGET_API_MAC_OSX
957f865c 2797
430e1eed 2798#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
957f865c
RN
2799 WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ;
2800
430e1eed
SC
2801 // for composited windows this also triggers a redraw of all
2802 // invalid views in the window
2803 if( UMAGetSystemVersion() >= 0x1030 )
8b573fb8
VZ
2804 HIWindowFlush(window) ;
2805 else
430e1eed
SC
2806#endif
2807 {
2808 // the only way to trigger the redrawing on earlier systems is to call
2809 // ReceiveNextEvent
2810
2811 EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
2812 UInt32 currentEventClass = 0 ;
2813 UInt32 currentEventKind = 0 ;
2814 if ( currentEvent != NULL )
2815 {
2816 currentEventClass = ::GetEventClass( currentEvent ) ;
2817 currentEventKind = ::GetEventKind( currentEvent ) ;
8b573fb8 2818 }
430e1eed
SC
2819 if ( currentEventClass != kEventClassMenu )
2820 {
2821 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2822
2823 EventRef theEvent;
2824 OSStatus status = noErr ;
2825 status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ;
2826 }
3e444781 2827 else
5ca0d812 2828 m_peer->SetNeedsDisplay( true ) ;
430e1eed 2829 }
facd6764 2830#else
5ca0d812 2831 ::Draw1Control( m_peer->GetControlRef() ) ;
bec721ec 2832#endif
519cb848
SC
2833}
2834
14c9cbdb 2835wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
519cb848 2836{
1c310985 2837 wxTopLevelWindowMac* win = NULL ;
facd6764 2838 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1c310985 2839 if ( window )
6264b550 2840 {
1c310985 2841 win = wxFindWinFromMacWindow( window ) ;
14c9cbdb 2842 }
1c310985 2843 return win ;
519cb848 2844}
facd6764 2845wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
94abc21f 2846{
0fa8508d
SC
2847 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
2848 // also a window dc uses this, in this case we only clip in the hierarchy for hard
2849 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
2850 // to add focus borders everywhere
8b573fb8 2851
facd6764 2852 Rect r ;
e40298d5
JS
2853 RgnHandle visRgn = NewRgn() ;
2854 RgnHandle tempRgn = NewRgn() ;
66ffb23b 2855 if ( !m_isBeingDeleted && m_peer->IsVisible())
e40298d5 2856 {
5ca0d812
SC
2857 m_peer->GetRect( &r ) ;
2858 r.left -= MacGetLeftBorderSize() ;
2859 r.top -= MacGetTopBorderSize() ;
2860 r.bottom += MacGetBottomBorderSize() ;
2861 r.right += MacGetRightBorderSize() ;
8b573fb8 2862
facd6764 2863 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
21f9e953 2864 {
facd6764
SC
2865 MacRootWindowToWindow( &r.left , & r.top ) ;
2866 MacRootWindowToWindow( &r.right , & r.bottom ) ;
21f9e953 2867 }
facd6764
SC
2868 else
2869 {
2870 r.right -= r.left ;
2871 r.bottom -= r.top ;
2872 r.left = 0 ;
2873 r.top = 0 ;
2874 }
2875 if ( includeOuterStructures )
af6b7b80 2876 InsetRect( &r , -4 , -4 ) ;
facd6764 2877 RectRgn( visRgn , &r ) ;
db7a550b 2878
21f9e953 2879 if ( !IsTopLevel() )
94abc21f 2880 {
facd6764
SC
2881 wxWindow* child = this ;
2882 wxWindow* parent = child->GetParent() ;
21f9e953
SC
2883 while( parent )
2884 {
21f9e953 2885 int x , y ;
facd6764 2886 wxSize size ;
d3e780ec
SC
2887 // we have to find a better clipping algorithm here, in order not to clip things
2888 // positioned like status and toolbar
2889 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
facd6764
SC
2890 {
2891 size = parent->GetSize() ;
2892 x = y = 0 ;
2893 }
2894 else
2895 {
2896 size = parent->GetClientSize() ;
2897 wxPoint origin = parent->GetClientAreaOrigin() ;
2898 x = origin.x ;
2899 y = origin.y ;
2900 }
21f9e953
SC
2901 parent->MacWindowToRootWindow( &x, &y ) ;
2902 MacRootWindowToWindow( &x , &y ) ;
2903
0fa8508d 2904 if ( !includeOuterStructures || (
7f17ac74
SC
2905 parent->MacClipChildren() ||
2906 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() )
0fa8508d
SC
2907 ) )
2908 {
2909 SetRectRgn( tempRgn ,
2910 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2911 x + size.x - parent->MacGetRightBorderSize(),
2912 y + size.y - parent->MacGetBottomBorderSize()) ;
21f9e953 2913
0fa8508d
SC
2914 SectRgn( visRgn , tempRgn , visRgn ) ;
2915 }
21f9e953
SC
2916 if ( parent->IsTopLevel() )
2917 break ;
facd6764
SC
2918 child = parent ;
2919 parent = child->GetParent() ;
7372fd0a 2920 }
94abc21f 2921 }
e40298d5 2922 }
facd6764
SC
2923
2924 wxRegion vis = visRgn ;
e40298d5
JS
2925 DisposeRgn( visRgn ) ;
2926 DisposeRgn( tempRgn ) ;
facd6764 2927 return vis ;
94abc21f
SC
2928}
2929
facd6764
SC
2930/*
2931 This function must not change the updatergn !
2932 */
8b573fb8 2933bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
519cb848 2934{
76a5e5d2 2935 RgnHandle updatergn = (RgnHandle) updatergnr ;
facd6764 2936 bool handled = false ;
42ef83fa
SC
2937 Rect updatebounds ;
2938 GetRegionBounds( updatergn , &updatebounds ) ;
20b69855 2939
c79aad8b
SC
2940 // wxLogDebug(wxT("update for %s bounds %d , %d , %d , %d"),wxString(GetClassInfo()->GetClassName()).c_str(), updatebounds.left , updatebounds.top , updatebounds.right , updatebounds.bottom ) ;
2941
2942 if ( !EmptyRgn(updatergn) )
6264b550 2943 {
1c310985
SC
2944 RgnHandle newupdate = NewRgn() ;
2945 wxSize point = GetClientSize() ;
2946 wxPoint origin = GetClientAreaOrigin() ;
1c310985 2947 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
facd6764 2948 SectRgn( newupdate , updatergn , newupdate ) ;
8b573fb8 2949
eec462f8
SC
2950 // first send an erase event to the entire update area
2951 {
c79aad8b
SC
2952 // for the toplevel window this really is the entire area
2953 // for all the others only their client area, otherwise they
2954 // might be drawing with full alpha and eg put blue into
2955 // the grow-box area of a scrolled window (scroll sample)
2956 wxDC* dc ;
2957 if ( IsTopLevel() )
2958 dc = new wxWindowDC(this);
2959 else
2960 dc = new wxClientDC(this);
2961 dc->SetClippingRegion(wxRegion(updatergn));
2962 wxEraseEvent eevent( GetId(), dc );
42ef83fa
SC
2963 eevent.SetEventObject( this );
2964 GetEventHandler()->ProcessEvent( eevent );
c79aad8b 2965 delete dc ;
eec462f8 2966 }
8b573fb8 2967
42ef83fa 2968 // calculate a client-origin version of the update rgn and set m_updateRegion to that
1c310985
SC
2969 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2970 m_updateRegion = newupdate ;
8b573fb8 2971 DisposeRgn( newupdate ) ;
6ed71b4f 2972
1c310985 2973 if ( !m_updateRegion.Empty() )
6264b550 2974 {
facd6764 2975 // paint the window itself
ff3795ee 2976
e40298d5 2977 wxPaintEvent event;
687706f5 2978 event.SetTimestamp(time);
e40298d5 2979 event.SetEventObject(this);
ff3795ee
SC
2980 GetEventHandler()->ProcessEvent(event);
2981 handled = true ;
eec462f8 2982 }
8b573fb8 2983
eec462f8
SC
2984 // now we cannot rely on having its borders drawn by a window itself, as it does not
2985 // get the updateRgn wide enough to always do so, so we do it from the parent
2986 // this would also be the place to draw any custom backgrounds for native controls
2987 // in Composited windowing
36d7f54e 2988 wxPoint clientOrigin = GetClientAreaOrigin() ;
8b573fb8 2989
71f2fb52 2990 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
eec462f8
SC
2991 {
2992 wxWindowMac *child = node->GetData();
2993 if (child == m_vScrollBar) continue;
2994 if (child == m_hScrollBar) continue;
2995 if (child->IsTopLevel()) continue;
2996 if (!child->IsShown()) continue;
fe779e40 2997
c79aad8b
SC
2998 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2999
af6b7b80
SC
3000 int x,y;
3001 child->GetPosition( &x, &y );
3002 int w,h;
3003 child->GetSize( &w, &h );
3004 Rect childRect = { y , x , y + h , x + w } ;
36d7f54e 3005 OffsetRect( &childRect , clientOrigin.x , clientOrigin.y ) ;
c79aad8b
SC
3006 InsetRect( &childRect , -10 , -10) ;
3007
3008 if ( RectInRgn( &childRect , updatergn ) )
eec462f8 3009 {
c79aad8b
SC
3010
3011 // paint custom borders
3012 wxNcPaintEvent eventNc( child->GetId() );
3013 eventNc.SetEventObject( child );
3014 if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
eec462f8 3015 {
c79aad8b
SC
3016#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
3017 if ( HIThemeDrawFrame != 0)
cb4b0966 3018 {
c79aad8b 3019 child->MacPaintBorders(0,0) ;
cb4b0966 3020 }
c79aad8b 3021 else
cb4b0966 3022#endif
af6b7b80
SC
3023 {
3024 wxWindowDC dc(this) ;
3025 dc.SetClippingRegion(wxRegion(updatergn));
3026 wxMacPortSetter helper(&dc) ;
c79aad8b 3027 child->MacPaintBorders(0,0) ;
c79aad8b 3028 }
eec462f8 3029 }
8b573fb8 3030 }
14c9cbdb 3031 }
6264b550 3032 }
facd6764
SC
3033 return handled ;
3034}
6ed71b4f 3035
519cb848 3036
facd6764 3037WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
519cb848 3038{
6264b550 3039 wxWindowMac *iter = (wxWindowMac*)this ;
14c9cbdb 3040
6264b550
RR
3041 while( iter )
3042 {
1c310985
SC
3043 if ( iter->IsTopLevel() )
3044 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
519cb848 3045
6264b550 3046 iter = iter->GetParent() ;
14c9cbdb 3047 }
427ff662 3048 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
6264b550 3049 return NULL ;
519cb848
SC
3050}
3051
14c9cbdb 3052void wxWindowMac::MacCreateScrollBars( long style )
519cb848 3053{
427ff662 3054 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
14c9cbdb 3055
aa99e0cd
SC
3056 if ( style & ( wxVSCROLL | wxHSCROLL ) )
3057 {
3058 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
db7a550b 3059 int scrlsize = MAC_SCROLLBAR_SIZE ;
8b573fb8
VZ
3060 wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL ;
3061 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
3062 {
3063 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
3064 variant = wxWINDOW_VARIANT_SMALL ;
3065 }
db7a550b
SC
3066
3067 int adjust = hasBoth ? scrlsize - 1: 0 ;
aa99e0cd
SC
3068 int width, height ;
3069 GetClientSize( &width , &height ) ;
3070
db7a550b
SC
3071 wxPoint vPoint(width-scrlsize, 0) ;
3072 wxSize vSize(scrlsize, height - adjust) ;
3073 wxPoint hPoint(0 , height-scrlsize ) ;
3074 wxSize hSize( width - adjust, scrlsize) ;
aa99e0cd
SC
3075
3076
3077 if ( style & wxVSCROLL )
3078 {
375bb200 3079 m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint,
aa99e0cd
SC
3080 vSize , wxVERTICAL);
3081 }
3082
3083 if ( style & wxHSCROLL )
3084 {
375bb200 3085 m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint,
aa99e0cd
SC
3086 hSize , wxHORIZONTAL);
3087 }
3088 }
aa99e0cd 3089
14c9cbdb 3090
6264b550
RR
3091 // because the create does not take into account the client area origin
3092 MacRepositionScrollBars() ; // we might have a real position shift
519cb848
SC
3093}
3094
e766c8a9 3095void wxWindowMac::MacRepositionScrollBars()
519cb848 3096{
aa99e0cd
SC
3097 if ( !m_hScrollBar && !m_vScrollBar )
3098 return ;
8b573fb8 3099
6264b550 3100 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
db7a550b
SC
3101 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
3102 int adjust = hasBoth ? scrlsize - 1 : 0 ;
14c9cbdb 3103
6264b550 3104 // get real client area
14c9cbdb 3105
facd6764
SC
3106 int width ;
3107 int height ;
3108 GetSize( &width , &height ) ;
6264b550
RR
3109
3110 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
3111 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
14c9cbdb 3112
6264b550
RR
3113 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
3114 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
3115 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
3116 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
db7a550b 3117/*
14c9cbdb 3118 int x = 0 ;
6264b550 3119 int y = 0 ;
facd6764
SC
3120 int w ;
3121 int h ;
3122 GetSize( &w , &h ) ;
14c9cbdb 3123
6264b550
RR
3124 MacClientToRootWindow( &x , &y ) ;
3125 MacClientToRootWindow( &w , &h ) ;
14c9cbdb 3126
6264b550 3127 wxWindowMac *iter = (wxWindowMac*)this ;
14c9cbdb 3128
6264b550
RR
3129 int totW = 10000 , totH = 10000;
3130 while( iter )
3131 {
1c310985 3132 if ( iter->IsTopLevel() )
6264b550 3133 {
facd6764 3134 iter->GetSize( &totW , &totH ) ;
6264b550
RR
3135 break ;
3136 }
3137
3138 iter = iter->GetParent() ;
14c9cbdb
RD
3139 }
3140
6264b550
RR
3141 if ( x == 0 )
3142 {
3143 hPoint.x = -1 ;
3144 hSize.x += 1 ;
3145 }
3146 if ( y == 0 )
3147 {
3148 vPoint.y = -1 ;
3149 vSize.y += 1 ;
3150 }
14c9cbdb 3151
6264b550
RR
3152 if ( w-x >= totW )
3153 {
3154 hSize.x += 1 ;
3155 vPoint.x += 1 ;
3156 }
14c9cbdb 3157
6264b550
RR
3158 if ( h-y >= totH )
3159 {
3160 vSize.y += 1 ;
3161 hPoint.y += 1 ;
3162 }
db7a550b 3163*/
6264b550
RR
3164 if ( m_vScrollBar )
3165 {
3166 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
3167 }
3168 if ( m_hScrollBar )
3169 {
3170 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
3171 }
519cb848
SC
3172}
3173
e766c8a9 3174bool wxWindowMac::AcceptsFocus() const
7c551d95
SC
3175{
3176 return MacCanFocus() && wxWindowBase::AcceptsFocus();
3177}
519cb848 3178
14c9cbdb 3179void wxWindowMac::MacSuperChangedPosition()
519cb848 3180{
6264b550 3181 // only window-absolute structures have to be moved i.e. controls
519cb848 3182
71f2fb52 3183 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
6264b550
RR
3184 while ( node )
3185 {
9bd1404d 3186 wxWindowMac *child = node->GetData();
6264b550 3187 child->MacSuperChangedPosition() ;
eb22f2a6 3188 node = node->GetNext();
6264b550 3189 }
519cb848 3190}
519cb848 3191
14c9cbdb 3192void wxWindowMac::MacTopLevelWindowChangedPosition()
a3bf4a62 3193{
6264b550 3194 // only screen-absolute structures have to be moved i.e. glcanvas
a3bf4a62 3195
71f2fb52 3196 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
6264b550
RR
3197 while ( node )
3198 {
9bd1404d 3199 wxWindowMac *child = node->GetData();
6264b550 3200 child->MacTopLevelWindowChangedPosition() ;
eb22f2a6 3201 node = node->GetNext();
6264b550 3202 }
a3bf4a62 3203}
facd6764 3204
e766c8a9 3205long wxWindowMac::MacGetLeftBorderSize( ) const
2f1ae414 3206{
1c310985 3207 if( IsTopLevel() )
6264b550 3208 return 0 ;
2f1ae414
SC
3209
3210 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
3211 {
ed60b502 3212 SInt32 border = 3 ;
ed60b502 3213 return border ;
2f1ae414
SC
3214 }
3215 else if ( m_windowStyle &wxDOUBLE_BORDER)
3216 {
ed60b502 3217 SInt32 border = 3 ;
ed60b502 3218 return border ;
2f1ae414
SC
3219 }
3220 else if (m_windowStyle &wxSIMPLE_BORDER)
3221 {
6264b550 3222 return 1 ;
2f1ae414 3223 }
6264b550 3224 return 0 ;
2f1ae414
SC
3225}
3226
e766c8a9 3227long wxWindowMac::MacGetRightBorderSize( ) const
5b781a67 3228{
1c310985
SC
3229 // they are all symmetric in mac themes
3230 return MacGetLeftBorderSize() ;
5b781a67
SC
3231}
3232
e766c8a9 3233long wxWindowMac::MacGetTopBorderSize( ) const
5b781a67 3234{
1c310985
SC
3235 // they are all symmetric in mac themes
3236 return MacGetLeftBorderSize() ;
5b781a67
SC
3237}
3238
e766c8a9 3239long wxWindowMac::MacGetBottomBorderSize( ) const
5b781a67 3240{
1c310985
SC
3241 // they are all symmetric in mac themes
3242 return MacGetLeftBorderSize() ;
5b781a67
SC
3243}
3244
14c9cbdb 3245long wxWindowMac::MacRemoveBordersFromStyle( long style )
2f1ae414 3246{
055a486b 3247 return style & ~wxBORDER_MASK ;
2f1ae414 3248}
0a67a93b 3249
e766c8a9 3250// Find the wxWindowMac at the current mouse position, returning the mouse
3723b7b1 3251// position.
e766c8a9 3252wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
3723b7b1 3253{
59a12e90 3254 pt = wxGetMousePosition();
e766c8a9 3255 wxWindowMac* found = wxFindWindowAtPoint(pt);
59a12e90 3256 return found;
3723b7b1
JS
3257}
3258
3259// Get the current mouse position.
3260wxPoint wxGetMousePosition()
3261{
57591e0e
JS
3262 int x, y;
3263 wxGetMousePosition(& x, & y);
3264 return wxPoint(x, y);
3723b7b1
JS
3265}
3266
6ed71b4f 3267void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
8950f7cc 3268{
8b573fb8
VZ
3269 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
3270 {
3271 // copied from wxGTK : CS
249aad30 3272 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
8950f7cc
SC
3273 // except that:
3274 //
3275 // (a) it's a command event and so is propagated to the parent
3276 // (b) under MSW it can be generated from kbd too
3277 // (c) it uses screen coords (because of (a))
3278 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
3279 this->GetId(),
3280 this->ClientToScreen(event.GetPosition()));
249aad30
SC
3281 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
3282 event.Skip() ;
8b573fb8 3283 }
facd6764
SC
3284 else
3285 {
8b573fb8 3286 event.Skip() ;
facd6764 3287 }
8950f7cc
SC
3288}
3289
ff3795ee
SC
3290void wxWindowMac::OnPaint( wxPaintEvent & event )
3291{
c79aad8b 3292 if ( wxTheApp->MacGetCurrentEvent() != NULL && wxTheApp->MacGetCurrentEventHandlerCallRef() != NULL )
ff3795ee 3293 {
c79aad8b 3294 CallNextEventHandler((EventHandlerCallRef)wxTheApp->MacGetCurrentEventHandlerCallRef() , (EventRef) wxTheApp->MacGetCurrentEvent() ) ;
ff3795ee
SC
3295 }
3296}
3297
8b573fb8 3298void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
facd6764 3299{
facd6764
SC
3300}
3301
8b573fb8 3302Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3083eb85
SC
3303{
3304 int x ,y , w ,h ;
8b573fb8 3305
79392158 3306 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
3083eb85
SC
3307 Rect bounds = { y , x , y+h , x+w };
3308 return bounds ;
3309}
3310
8b573fb8 3311wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
f1d527c1
SC
3312{
3313 return eventNotHandledErr ;
3314}
3315
facd6764 3316