]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/window.cpp
Replaced SOCKLEN_T by WX_SOCKLEN_T to resolve conflict with AIX system headers.
[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
fc0daf84 79BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
facd6764
SC
80 EVT_NC_PAINT(wxWindowMac::OnNcPaint)
81 EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
ff3795ee
SC
82#if TARGET_API_MAC_OSX
83 EVT_PAINT(wxWindowMac::OnPaint)
84#endif
5ca0d812
SC
85 EVT_SET_FOCUS(wxWindowMac::OnSetFocus)
86 EVT_KILL_FOCUS(wxWindowMac::OnSetFocus)
facd6764 87 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
e9576ca5
SC
88END_EVENT_TABLE()
89
94abc21f
SC
90#define wxMAC_DEBUG_REDRAW 0
91#ifndef wxMAC_DEBUG_REDRAW
92#define wxMAC_DEBUG_REDRAW 0
93#endif
94
5ca0d812 95#define wxMAC_USE_THEME_BORDER 1
e9576ca5 96
42ef83fa
SC
97// ---------------------------------------------------------------------------
98// Utility Routines to move between different coordinate systems
99// ---------------------------------------------------------------------------
100
101/*
102 * Right now we have the following setup :
103 * a border that is not part of the native control is always outside the
104 * control's border (otherwise we loose all native intelligence, future ways
105 * may be to have a second embedding control responsible for drawing borders
106 * and backgrounds eventually)
107 * so all this border calculations have to be taken into account when calling
108 * native methods or getting native oriented data
109 * so we have three coordinate systems here
110 * wx client coordinates
111 * wx window coordinates (including window frames)
112 * native coordinates
113 */
8b573fb8 114
42ef83fa
SC
115//
116// originating from native control
117//
118
119
120void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle )
121{
8b573fb8 122 OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
42ef83fa
SC
123}
124
125void wxMacNativeToWindow( const wxWindow* window , Rect *rect )
126{
8b573fb8 127 OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
42ef83fa
SC
128}
129
130//
131// directed towards native control
132//
133
134void wxMacWindowToNative( const wxWindow* window , RgnHandle handle )
135{
8b573fb8 136 OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
42ef83fa
SC
137}
138
139void wxMacWindowToNative( const wxWindow* window , Rect *rect )
140{
8b573fb8 141 OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ;
42ef83fa
SC
142}
143
144
facd6764
SC
145// ---------------------------------------------------------------------------
146// Carbon Events
147// ---------------------------------------------------------------------------
8b573fb8 148
facd6764
SC
149extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
150pascal OSStatus wxMacSetupControlBackground( ControlRef iControl , SInt16 iMessage , SInt16 iDepth , Boolean iIsColor ) ;
151
f1d527c1
SC
152#if TARGET_API_MAC_OSX
153
8b573fb8 154#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3
c2697b87
SC
155enum {
156 kEventControlVisibilityChanged = 157
157};
158#endif
159
f1d527c1
SC
160#endif
161
facd6764
SC
162static const EventTypeSpec eventList[] =
163{
f1d527c1 164 { kEventClassControl , kEventControlHit } ,
facd6764 165#if TARGET_API_MAC_OSX
73fe67bd
SC
166 { kEventClassControl , kEventControlDraw } ,
167 { kEventClassControl , kEventControlVisibilityChanged } ,
168 { kEventClassControl , kEventControlEnabledStateChanged } ,
169 { kEventClassControl , kEventControlHiliteChanged } ,
f1d527c1 170 { kEventClassControl , kEventControlSetFocusPart } ,
8b573fb8
VZ
171
172 { kEventClassService , kEventServiceGetTypes },
173 { kEventClassService , kEventServiceCopy },
174 { kEventClassService , kEventServicePaste },
175
176 // { kEventClassControl , kEventControlInvalidateForSizeChange } , // 10.3 only
facd6764 177// { kEventClassControl , kEventControlBoundsChanged } ,
facd6764
SC
178#endif
179} ;
180
181static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
182{
183 OSStatus result = eventNotHandledErr ;
184
185 wxMacCarbonEvent cEvent( event ) ;
8b573fb8 186
facd6764
SC
187 ControlRef controlRef ;
188 wxWindowMac* thisWindow = (wxWindowMac*) data ;
189
190 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
191
192 switch( GetEventKind( event ) )
193 {
f1d527c1 194#if TARGET_API_MAC_OSX
facd6764
SC
195 case kEventControlDraw :
196 {
1e8cde71 197 RgnHandle updateRgn = NULL ;
055a486b 198 RgnHandle allocatedRgn = NULL ;
1e8cde71 199 wxRegion visRegion = thisWindow->MacGetVisibleRegion() ;
e6616741
SC
200 Rect controlBounds ;
201 if ( thisWindow->GetPeer()->IsCompositing() == false )
202 {
203 if ( thisWindow->GetPeer()->IsRootControl() == false )
204 {
205 GetControlBounds( thisWindow->GetPeer()->GetControlRef() , &controlBounds ) ;
206 }
207 else
208 {
209 thisWindow->GetPeer()->GetRect( &controlBounds ) ;
210 }
211 }
902725ee 212
76c7012c 213 if ( cEvent.GetParameter<RgnHandle>(kEventParamRgnHandle, &updateRgn) != noErr )
1e8cde71
SC
214 {
215 updateRgn = (RgnHandle) visRegion.GetWXHRGN() ;
216 }
055a486b
SC
217 else
218 {
e6616741 219 if ( thisWindow->GetPeer()->IsCompositing() == false )
055a486b
SC
220 {
221 allocatedRgn = NewRgn() ;
222 CopyRgn( updateRgn , allocatedRgn ) ;
e6616741 223 OffsetRgn( allocatedRgn , -controlBounds.left , -controlBounds.top ) ;
42ef83fa
SC
224 // hide the given region by the new region that must be shifted
225 wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
902725ee 226 updateRgn = allocatedRgn ;
e6616741
SC
227 }
228 else
229 {
230 if ( thisWindow->MacGetLeftBorderSize() != 0 || thisWindow->MacGetTopBorderSize() != 0 )
231 {
232 // as this update region is in native window locals we must adapt it to wx window local
233 allocatedRgn = NewRgn() ;
234 CopyRgn( updateRgn , allocatedRgn ) ;
235 // hide the given region by the new region that must be shifted
236 wxMacNativeToWindow( thisWindow , allocatedRgn ) ;
237 updateRgn = allocatedRgn ;
238 }
055a486b
SC
239 }
240 }
e6616741
SC
241 Rect rgnBounds ;
242 GetRegionBounds( updateRgn , &rgnBounds ) ;
1f1c8bd4 243#if wxMAC_DEBUG_REDRAW
facd6764
SC
244 if ( thisWindow->MacIsUserPane() )
245 {
20b69855 246 CGContextRef cgContext = cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef) ;
bcbd6987
SC
247 static float color = 0.5 ;
248 static channel = 0 ;
8b573fb8
VZ
249 HIRect bounds;
250 HIViewGetBounds( controlRef, &bounds );
251 CGContextSetRGBFillColor( cgContext, channel == 0 ? color : 0.5 ,
252 channel == 1 ? color : 0.5 , channel == 2 ? color : 0.5 , 1 );
253 CGContextFillRect( cgContext, bounds );
254 color += 0.1 ;
255 if ( color > 0.9 )
256 {
257 color = 0.5 ;
258 channel++ ;
259 if ( channel == 3 )
260 channel = 0 ;
261 }
facd6764 262 }
20b69855 263#endif
c79aad8b 264 {
20b69855 265#if wxMAC_USE_CORE_GRAPHICS
e6616741
SC
266 bool created = false ;
267 CGContextRef cgContext = 0 ;
268 if ( cEvent.GetParameter<CGContextRef>(kEventParamCGContextRef, &cgContext) != noErr )
269 {
270 wxASSERT( thisWindow->GetPeer()->IsCompositing() == false ) ;
902725ee 271
e6616741
SC
272 // this parameter is not provided on non-composited windows
273 created = true ;
902725ee 274 // rest of the code expects this to be already transformed and clipped for local
e6616741
SC
275 CGrafPtr port = GetWindowPort( (WindowRef) thisWindow->MacGetTopLevelWindowRef() ) ;
276 Rect bounds ;
277 GetPortBounds( port , &bounds ) ;
278 CreateCGContextForPort( port , &cgContext ) ;
279
280 wxMacWindowToNative( thisWindow , updateRgn ) ;
281 OffsetRgn( updateRgn , controlBounds.left , controlBounds.top ) ;
282 ClipCGContextToRegion( cgContext , &bounds , updateRgn ) ;
283 wxMacNativeToWindow( thisWindow , updateRgn ) ;
284 OffsetRgn( updateRgn , -controlBounds.left , -controlBounds.top ) ;
285
286 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
287 CGContextScaleCTM( cgContext , 1 , -1 ) ;
902725ee 288
e6616741 289 CGContextTranslateCTM( cgContext , controlBounds.left , controlBounds.top ) ;
902725ee 290
e6616741
SC
291 /*
292 CGContextSetRGBFillColor( cgContext , 1.0 , 1.0 , 1.0 , 1.0 ) ;
902725ee
WS
293 CGContextFillRect(cgContext , CGRectMake( 0 , 0 ,
294 controlBounds.right - controlBounds.left ,
e6616741
SC
295 controlBounds.bottom - controlBounds.top ) );
296 */
297
298 }
c79aad8b 299 thisWindow->MacSetCGContextRef( cgContext ) ;
e6616741
SC
300 {
301 wxMacCGContextStateSaver sg( cgContext ) ;
facd6764 302#endif
e6616741
SC
303 if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) )
304 result = noErr ;
20b69855 305#if wxMAC_USE_CORE_GRAPHICS
e6616741
SC
306 thisWindow->MacSetCGContextRef( NULL ) ;
307 }
308 if ( created )
309 {
310 CGContextRelease( cgContext ) ;
311 }
20b69855 312#endif
c79aad8b 313 }
055a486b
SC
314 if ( allocatedRgn )
315 DisposeRgn( allocatedRgn ) ;
facd6764
SC
316 }
317 break ;
73fe67bd
SC
318 case kEventControlVisibilityChanged :
319 thisWindow->MacVisibilityChanged() ;
320 break ;
321 case kEventControlEnabledStateChanged :
322 thisWindow->MacEnabledStateChanged() ;
323 break ;
324 case kEventControlHiliteChanged :
325 thisWindow->MacHiliteChanged() ;
326 break ;
6449b3a8
SC
327#endif
328 // we emulate this event under Carbon CFM
f1d527c1
SC
329 case kEventControlSetFocusPart :
330 {
331 Boolean focusEverything = false ;
332 ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode );
6449b3a8 333#ifdef __WXMAC_OSX__
f1d527c1
SC
334 if ( cEvent.GetParameter<Boolean>(kEventParamControlFocusEverything , &focusEverything ) == noErr )
335 {
336 }
6449b3a8 337#endif
f1d527c1
SC
338 if ( controlPart == kControlFocusNoPart )
339 {
340 #if wxUSE_CARET
341 if ( thisWindow->GetCaret() )
342 {
343 thisWindow->GetCaret()->OnKillFocus();
344 }
345 #endif // wxUSE_CARET
92b6cd62
SC
346 static bool inKillFocusEvent = false ;
347 if ( !inKillFocusEvent )
348 {
349 inKillFocusEvent = true ;
350 wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
351 event.SetEventObject(thisWindow);
352 thisWindow->GetEventHandler()->ProcessEvent(event) ;
353 inKillFocusEvent = false ;
354 }
f1d527c1
SC
355 }
356 else
357 {
358 // panel wants to track the window which was the last to have focus in it
359 wxChildFocusEvent eventFocus(thisWindow);
360 thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
8b573fb8 361
f1d527c1
SC
362 #if wxUSE_CARET
363 if ( thisWindow->GetCaret() )
364 {
365 thisWindow->GetCaret()->OnSetFocus();
366 }
367 #endif // wxUSE_CARET
368
369 wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
370 event.SetEventObject(thisWindow);
371 thisWindow->GetEventHandler()->ProcessEvent(event) ;
372 }
64fec3ab
SC
373 if ( thisWindow->MacIsUserPane() )
374 result = noErr ;
f1d527c1
SC
375 }
376 break ;
f1d527c1
SC
377 case kEventControlHit :
378 {
379 result = thisWindow->MacControlHit( handler , event ) ;
380 }
381 break ;
facd6764
SC
382 default :
383 break ;
384 }
385 return result ;
386}
387
e4727773
SC
388static pascal OSStatus wxMacWindowServiceEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
389{
390 OSStatus result = eventNotHandledErr ;
391
392 wxMacCarbonEvent cEvent( event ) ;
8b573fb8 393
e4727773
SC
394 ControlRef controlRef ;
395 wxWindowMac* thisWindow = (wxWindowMac*) data ;
396 wxTextCtrl* textCtrl = wxDynamicCast( thisWindow , wxTextCtrl ) ;
397 cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ;
398
399 switch( GetEventKind( event ) )
400 {
401 case kEventServiceGetTypes :
402 if( textCtrl )
403 {
404 long from, to ;
405 textCtrl->GetSelection( &from , &to ) ;
406
8b573fb8 407 CFMutableArrayRef copyTypes = 0 , pasteTypes = 0;
e4727773
SC
408 if( from != to )
409 copyTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServiceCopyTypes , typeCFMutableArrayRef ) ;
410 if ( textCtrl->IsEditable() )
411 pasteTypes = cEvent.GetParameter< CFMutableArrayRef >( kEventParamServicePasteTypes , typeCFMutableArrayRef ) ;
8b573fb8
VZ
412
413 static const OSType textDataTypes[] = { kTXNTextData /* , 'utxt' , 'PICT', 'MooV', 'AIFF' */ };
e4727773
SC
414 for ( size_t i = 0 ; i < WXSIZEOF(textDataTypes) ; ++i )
415 {
416 CFStringRef typestring = CreateTypeStringWithOSType(textDataTypes[i]);
417 if ( typestring )
418 {
419 if ( copyTypes )
420 CFArrayAppendValue (copyTypes, typestring) ;
421 if ( pasteTypes )
422 CFArrayAppendValue (pasteTypes, typestring) ;
423 CFRelease( typestring ) ;
424 }
425 }
426 result = noErr ;
427 }
428 break ;
429 case kEventServiceCopy :
430 if ( textCtrl )
431 {
432 long from, to ;
433 textCtrl->GetSelection( &from , &to ) ;
434 wxString val = textCtrl->GetValue() ;
435 val = val.Mid( from , to - from ) ;
436 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
437 verify_noerr( ClearScrap( &scrapRef ) ) ;
438 verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.Length() , val.c_str() ) ) ;
439 result = noErr ;
440 }
441 break ;
442 case kEventServicePaste :
443 if ( textCtrl )
444 {
445 ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
446 Size textSize, pastedSize ;
447 verify_noerr( GetScrapFlavorSize (scrapRef, kTXNTextData, &textSize) ) ;
448 textSize++ ;
449 char *content = new char[textSize] ;
8b573fb8 450 GetScrapFlavorData (scrapRef, kTXNTextData, &pastedSize, content );
e4727773 451 content[textSize-1] = 0 ;
8ef4d6e2
SC
452#if wxUSE_UNICODE
453 textCtrl->WriteText( wxString( content , wxConvLocal ) );
454#else
e4727773 455 textCtrl->WriteText( wxString( content ) ) ;
8ef4d6e2 456#endif
e4727773
SC
457 delete[] content ;
458 result = noErr ;
459 }
460 break ;
461 }
8b573fb8 462
e4727773 463 return result ;
8b573fb8 464}
e4727773 465
facd6764
SC
466pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
467{
af6b7b80
SC
468 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
469 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
470 wxTheApp->MacSetCurrentEvent( event , handler ) ;
facd6764
SC
471 OSStatus result = eventNotHandledErr ;
472
473 switch ( GetEventClass( event ) )
474 {
475 case kEventClassControl :
476 result = wxMacWindowControlEventHandler( handler, event, data ) ;
477 break ;
e4727773
SC
478 case kEventClassService :
479 result = wxMacWindowServiceEventHandler( handler, event , data ) ;
902725ee 480 break ;
facd6764
SC
481 default :
482 break ;
483 }
af6b7b80 484 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
facd6764
SC
485 return result ;
486}
487
488DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler )
489
20b69855
SC
490#if !TARGET_API_MAC_OSX
491
facd6764
SC
492// ---------------------------------------------------------------------------
493// UserPane events for non OSX builds
494// ---------------------------------------------------------------------------
8b573fb8 495
facd6764
SC
496static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
497{
498 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
499 if ( win )
500 win->MacControlUserPaneDrawProc(part) ;
facd6764 501}
1f1c8bd4 502wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ;
facd6764
SC
503
504static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
505{
506 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
507 if ( win )
508 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
509 else
510 return kControlNoPart ;
facd6764 511}
1f1c8bd4 512wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ;
facd6764
SC
513
514static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
515{
516 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
517 if ( win )
518 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
519 else
520 return kControlNoPart ;
facd6764 521}
1f1c8bd4 522wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ;
facd6764
SC
523
524static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
525{
526 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
527 if ( win )
528 win->MacControlUserPaneIdleProc() ;
facd6764 529}
1f1c8bd4 530wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ;
facd6764
SC
531
532static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
533{
534 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
535 if ( win )
536 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
537 else
538 return kControlNoPart ;
facd6764 539}
1f1c8bd4 540wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ;
facd6764
SC
541
542static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
543{
544 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
545 if ( win )
546 win->MacControlUserPaneActivateProc(activating) ;
facd6764 547}
1f1c8bd4 548wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ;
facd6764
SC
549
550static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
551{
552 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
553 if ( win )
554 return win->MacControlUserPaneFocusProc(action) ;
555 else
556 return kControlNoPart ;
facd6764 557}
1f1c8bd4 558wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ;
facd6764
SC
559
560static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
561{
562 wxWindow * win = wxFindControlFromMacControl(control) ;
542f604f
SC
563 if ( win )
564 win->MacControlUserPaneBackgroundProc(info) ;
facd6764 565}
1f1c8bd4 566wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ;
facd6764 567
8b573fb8 568void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part)
facd6764 569{
bcbd6987
SC
570 RgnHandle rgn = NewRgn() ;
571 GetClip( rgn ) ;
d35bd499
SC
572 int x = 0 , y = 0;
573 MacWindowToRootWindow( &x,&y ) ;
574 OffsetRgn( rgn , -x , -y ) ;
bcbd6987
SC
575 wxMacWindowStateSaver sv( this ) ;
576 SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ;
577 MacDoRedraw( rgn , 0 ) ;
578 DisposeRgn( rgn ) ;
facd6764
SC
579}
580
8b573fb8 581wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
facd6764
SC
582{
583 return kControlNoPart ;
584}
585
8b573fb8 586wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc)
facd6764
SC
587{
588 return kControlNoPart ;
589}
590
8b573fb8 591void wxWindowMac::MacControlUserPaneIdleProc()
facd6764
SC
592{
593}
594
8b573fb8 595wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
facd6764
SC
596{
597 return kControlNoPart ;
598}
599
8b573fb8 600void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
facd6764
SC
601{
602}
603
8b573fb8 604wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
facd6764
SC
605{
606 return kControlNoPart ;
607}
608
8b573fb8 609void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
facd6764
SC
610{
611}
612
20b69855
SC
613#endif
614
1f1c8bd4
SC
615// ---------------------------------------------------------------------------
616// Scrollbar Tracking for all
617// ---------------------------------------------------------------------------
618
619pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
620pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
621{
622 if ( partCode != 0)
623 {
624 wxWindow* wx = wxFindControlFromMacControl( control ) ;
625 if ( wx )
626 {
627 wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
628 }
629 }
630}
631wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
632
e7549107
SC
633// ===========================================================================
634// implementation
635// ===========================================================================
636
71f2fb52
RN
637WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
638
639static MacControlMap wxWinMacControlList;
640
641wxWindow *wxFindControlFromMacControl(ControlRef inControl )
642{
643 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
644
645 return (node == wxWinMacControlList.end()) ? NULL : node->second;
646}
647
648void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
649{
650 // adding NULL ControlRef is (first) surely a result of an error and
651 // (secondly) breaks native event processing
652 wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
653
654 wxWinMacControlList[inControl] = control;
655}
656
657void wxRemoveMacControlAssociation(wxWindow *control)
658{
659 // iterate over all the elements in the class
a8683134
SC
660 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
661 // we should go on...
662
663 bool found = true ;
664 while( found )
71f2fb52 665 {
a8683134
SC
666 found = false ;
667 MacControlMap::iterator it;
668 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
71f2fb52 669 {
a8683134
SC
670 if ( it->second == control )
671 {
672 wxWinMacControlList.erase(it);
673 found = true ;
674 break;
675 }
71f2fb52
RN
676 }
677 }
678}
facd6764 679
e7549107 680// ----------------------------------------------------------------------------
facd6764 681 // constructors and such
e7549107
SC
682// ----------------------------------------------------------------------------
683
94f9b1f0 684wxWindowMac::wxWindowMac()
8b573fb8
VZ
685{
686 Init();
94f9b1f0
SC
687}
688
689wxWindowMac::wxWindowMac(wxWindowMac *parent,
690 wxWindowID id,
691 const wxPoint& pos ,
692 const wxSize& size ,
693 long style ,
694 const wxString& name )
695{
696 Init();
697 Create(parent, id, pos, size, style, name);
698}
699
e766c8a9 700void wxWindowMac::Init()
519cb848 701{
21fd5529 702 m_peer = NULL ;
79392158 703 m_frozenness = 0 ;
557d6f32 704#if WXWIN_COMPATIBILITY_2_4
902725ee 705 m_backgroundTransparent = false;
557d6f32 706#endif
e7549107
SC
707
708 // as all windows are created with WS_VISIBLE style...
902725ee 709 m_isShown = true;
e7549107 710
6264b550
RR
711 m_hScrollBar = NULL ;
712 m_vScrollBar = NULL ;
facd6764
SC
713 m_macBackgroundBrush = wxNullBrush ;
714
902725ee 715 m_macIsUserPane = true;
20b69855
SC
716#if wxMAC_USE_CORE_GRAPHICS
717 m_cgContextRef = NULL ;
718#endif
8adc196b 719 m_clipChildren = false ;
5c840e5b 720 m_cachedClippedRectValid = false ;
c6f9fb05
SC
721 // we need a valid font for the encodings
722 wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
e9576ca5
SC
723}
724
725// Destructor
e766c8a9 726wxWindowMac::~wxWindowMac()
e9576ca5 727{
7de59551
RD
728 SendDestroyEvent();
729
902725ee 730 m_isBeingDeleted = true;
6ed71b4f 731
6449b3a8 732 MacInvalidateBorders() ;
7ebf5540 733
d4380aaf
SC
734#ifndef __WXUNIVERSAL__
735 // VS: make sure there's no wxFrame with last focus set to us:
736 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
737 {
738 wxFrame *frame = wxDynamicCast(win, wxFrame);
739 if ( frame )
740 {
741 if ( frame->GetLastFocus() == this )
742 {
743 frame->SetLastFocus((wxWindow*)NULL);
744 }
745 break;
746 }
747 }
748#endif // __WXUNIVERSAL__
8b573fb8
VZ
749
750 // destroy children before destroying this window itself
751 DestroyChildren();
752
facd6764
SC
753 // wxRemoveMacControlAssociation( this ) ;
754 // If we delete an item, we should initialize the parent panel,
755 // because it could now be invalid.
756 wxWindow *parent = GetParent() ;
757 if ( parent )
758 {
759 if (parent->GetDefaultItem() == (wxButton*) this)
760 parent->SetDefaultItem(NULL);
761 }
21fd5529 762 if ( m_peer && m_peer->Ok() )
facd6764
SC
763 {
764 // in case the callback might be called during destruction
765 wxRemoveMacControlAssociation( this) ;
229f6270 766 ::RemoveEventHandler( (EventHandlerRef ) m_macControlEventHandler ) ;
5ca0d812
SC
767 // we currently are not using this hook
768 // ::SetControlColorProc( *m_peer , NULL ) ;
769 m_peer->Dispose() ;
facd6764 770 }
d4380aaf 771
facd6764 772 if ( g_MacLastWindow == this )
6264b550 773 {
facd6764 774 g_MacLastWindow = NULL ;
6264b550 775 }
7de59551 776
fd76aa8d
SC
777 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
778 if ( frame )
779 {
e40298d5
JS
780 if ( frame->GetLastFocus() == this )
781 frame->SetLastFocus( NULL ) ;
fd76aa8d 782 }
e7549107 783
42683dfb
SC
784 // delete our drop target if we've got one
785#if wxUSE_DRAG_AND_DROP
786 if ( m_dropTarget != NULL )
787 {
788 delete m_dropTarget;
789 m_dropTarget = NULL;
790 }
791#endif // wxUSE_DRAG_AND_DROP
21fd5529
SC
792 delete m_peer ;
793}
794
8b573fb8
VZ
795WXWidget wxWindowMac::GetHandle() const
796{
797 return (WXWidget) m_peer->GetControlRef() ;
e9576ca5
SC
798}
799
facd6764 800
5ca0d812 801void wxWindowMac::MacInstallEventHandler( WXWidget control )
facd6764 802{
5ca0d812
SC
803 wxAssociateControlWithMacControl( (ControlRef) control , this ) ;
804 InstallControlEventHandler( (ControlRef) control , GetwxMacWindowEventHandlerUPP(),
8b573fb8 805 GetEventTypeCount(eventList), eventList, this,
facd6764 806 (EventHandlerRef *)&m_macControlEventHandler);
4a63451b
SC
807#if !TARGET_API_MAC_OSX
808 if ( (ControlRef) control == m_peer->GetControlRef() )
809 {
1f1c8bd4
SC
810 m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl,kControlUserPaneDrawProcTag,GetwxMacControlUserPaneDrawProc()) ;
811 m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl,kControlUserPaneHitTestProcTag,GetwxMacControlUserPaneHitTestProc()) ;
812 m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl,kControlUserPaneTrackingProcTag,GetwxMacControlUserPaneTrackingProc()) ;
813 m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl,kControlUserPaneIdleProcTag,GetwxMacControlUserPaneIdleProc()) ;
814 m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl,kControlUserPaneKeyDownProcTag,GetwxMacControlUserPaneKeyDownProc()) ;
815 m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl,kControlUserPaneActivateProcTag,GetwxMacControlUserPaneActivateProc()) ;
816 m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl,kControlUserPaneFocusProcTag,GetwxMacControlUserPaneFocusProc()) ;
817 m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl,kControlUserPaneBackgroundProcTag,GetwxMacControlUserPaneBackgroundProc()) ;
4a63451b
SC
818 }
819#endif
facd6764
SC
820
821}
822
e9576ca5 823// Constructor
e766c8a9 824bool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id,
e9576ca5
SC
825 const wxPoint& pos,
826 const wxSize& size,
827 long style,
828 const wxString& name)
829{
902725ee 830 wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
e9576ca5 831
e7549107 832 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
902725ee 833 return false;
e9576ca5 834
facd6764 835 m_windowVariant = parent->GetWindowVariant() ;
8b573fb8 836
facd6764
SC
837 if ( m_macIsUserPane )
838 {
839 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
8b573fb8 840
ebe86b1e 841 UInt32 features = 0
8b573fb8 842 | kControlSupportsEmbedding
1f1c8bd4
SC
843 | kControlSupportsLiveFeedback
844 | kControlGetsFocusOnClick
8b573fb8
VZ
845// | kControlHasSpecialBackground
846// | kControlSupportsCalcBestRect
1f1c8bd4 847 | kControlHandlesTracking
8b573fb8 848 | kControlSupportsFocus
1f1c8bd4
SC
849 | kControlWantsActivate
850 | kControlWantsIdle
8b573fb8 851 ;
ebe86b1e 852
6449b3a8 853 m_peer = new wxMacControl(this) ;
5ca0d812 854 ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
8b573fb8 855
facd6764
SC
856
857 MacPostControlCreate(pos,size) ;
facd6764 858 }
e766c8a9 859#ifndef __WXUNIVERSAL__
14c9cbdb
RD
860 // Don't give scrollbars to wxControls unless they ask for them
861 if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) ||
862 (IsKindOf(CLASSINFO(wxControl)) && ( style & wxHSCROLL || style & wxVSCROLL)))
6264b550
RR
863 {
864 MacCreateScrollBars( style ) ;
865 }
e766c8a9 866#endif
3dfafdb9
RD
867
868 wxWindowCreateEvent event(this);
7e4a196e 869 GetEventHandler()->AddPendingEvent(event);
3dfafdb9 870
902725ee 871 return true;
e9576ca5
SC
872}
873
902725ee 874void wxWindowMac::MacChildAdded()
08422003
SC
875{
876 if ( m_vScrollBar )
877 {
878 m_vScrollBar->Raise() ;
879 }
880 if ( m_hScrollBar )
881 {
882 m_hScrollBar->Raise() ;
883 }
884
885}
886
facd6764
SC
887void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
888{
21fd5529 889 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
facd6764 890
5ca0d812 891 m_peer->SetReference( (long) this ) ;
488abb22 892 GetParent()->AddChild(this);
facd6764 893
5ca0d812 894 MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
facd6764
SC
895
896 ControlRef container = (ControlRef) GetParent()->GetHandle() ;
897 wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
5ca0d812 898 ::EmbedControl( m_peer->GetControlRef() , container ) ;
08422003 899 GetParent()->MacChildAdded() ;
facd6764
SC
900
901 // adjust font, controlsize etc
902 DoSetWindowVariant( m_windowVariant ) ;
903
5ca0d812 904 m_peer->SetTitle( wxStripMenuCodes(m_label) ) ;
facd6764 905
facd6764 906 if (!m_macIsUserPane)
d3b5db4b
RD
907 {
908 SetInitialBestSize(size);
facd6764
SC
909 }
910
911 SetCursor( *wxSTANDARD_CURSOR ) ;
facd6764
SC
912}
913
914void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
915{
23176131
JS
916 // Don't assert, in case we set the window variant before
917 // the window is created
21fd5529 918 // wxASSERT( m_peer->Ok() ) ;
facd6764 919
23176131
JS
920 m_windowVariant = variant ;
921
21fd5529 922 if (m_peer == NULL || !m_peer->Ok())
23176131 923 return;
facd6764 924
8b573fb8 925 ControlSize size ;
facd6764
SC
926 ThemeFontID themeFont = kThemeSystemFont ;
927
928 // we will get that from the settings later
8b573fb8 929 // and make this NORMAL later, but first
facd6764 930 // we have a few calculations that we must fix
8b573fb8 931
facd6764
SC
932 switch ( variant )
933 {
934 case wxWINDOW_VARIANT_NORMAL :
8b573fb8
VZ
935 size = kControlSizeNormal;
936 themeFont = kThemeSystemFont ;
facd6764
SC
937 break ;
938 case wxWINDOW_VARIANT_SMALL :
8b573fb8
VZ
939 size = kControlSizeSmall;
940 themeFont = kThemeSmallSystemFont ;
facd6764
SC
941 break ;
942 case wxWINDOW_VARIANT_MINI :
943 if (UMAGetSystemVersion() >= 0x1030 )
944 {
8b573fb8
VZ
945 // not always defined in the headers
946 size = 3 ;
947 themeFont = 109 ;
facd6764
SC
948 }
949 else
950 {
8b573fb8
VZ
951 size = kControlSizeSmall;
952 themeFont = kThemeSmallSystemFont ;
facd6764
SC
953 }
954 break ;
955 case wxWINDOW_VARIANT_LARGE :
8b573fb8
VZ
956 size = kControlSizeLarge;
957 themeFont = kThemeSystemFont ;
facd6764
SC
958 break ;
959 default:
960 wxFAIL_MSG(_T("unexpected window variant"));
961 break ;
962 }
5ca0d812 963 m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag,&size ) ;
facd6764
SC
964
965 wxFont font ;
966 font.MacCreateThemeFont( themeFont ) ;
967 SetFont( font ) ;
968}
969
8b573fb8 970void wxWindowMac::MacUpdateControlFont()
facd6764 971{
ac99838a 972 m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
8b573fb8 973 Refresh() ;
facd6764
SC
974}
975
976bool wxWindowMac::SetFont(const wxFont& font)
977{
d5ccba72 978 bool retval = wxWindowBase::SetFont( font ) ;
8b573fb8 979
facd6764 980 MacUpdateControlFont() ;
8b573fb8 981
facd6764
SC
982 return retval;
983}
984
985bool wxWindowMac::SetForegroundColour(const wxColour& col )
986{
987 if ( !wxWindowBase::SetForegroundColour(col) )
988 return false ;
8b573fb8 989
facd6764 990 MacUpdateControlFont() ;
8b573fb8 991
facd6764
SC
992 return true ;
993}
994
995bool wxWindowMac::SetBackgroundColour(const wxColour& col )
996{
997 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
998 return false ;
999
1000 wxBrush brush ;
b52acd03
RD
1001 wxColour newCol(GetBackgroundColour());
1002 if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
facd6764
SC
1003 {
1004 brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
1005 }
b52acd03 1006 else if ( newCol == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
facd6764 1007 {
8b573fb8
VZ
1008 brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
1009 }
facd6764
SC
1010 else
1011 {
b52acd03 1012 brush.SetColour( newCol ) ;
facd6764
SC
1013 }
1014 MacSetBackgroundBrush( brush ) ;
8b573fb8 1015
db7a550b 1016 MacUpdateControlFont() ;
8b573fb8 1017
facd6764
SC
1018 return true ;
1019}
1020
7ea087b7
SC
1021void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush )
1022{
1023 m_macBackgroundBrush = brush ;
1024 m_peer->SetBackground( brush ) ;
1025}
facd6764
SC
1026
1027bool wxWindowMac::MacCanFocus() const
1028{
f6e3849c
SC
1029 // there is currently no way to determine whether the window is running in full keyboard
1030 // access mode, therefore we cannot rely on these features, yet the only other way would be
1031 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
1032 // in event handlers...
f1d527c1 1033 UInt32 features = 0 ;
5ca0d812 1034 m_peer->GetFeatures( & features ) ;
8b573fb8 1035 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
facd6764
SC
1036}
1037
1038
e766c8a9 1039void wxWindowMac::SetFocus()
e9576ca5 1040{
6264b550
RR
1041 if ( AcceptsFocus() )
1042 {
7d0cfe71 1043
f1d527c1 1044 wxWindow* former = FindFocus() ;
7d0cfe71
SC
1045 if ( former == this )
1046 return ;
1047
5ca0d812 1048 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
f1d527c1
SC
1049 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
1050 // leave in case of an error
1051 if ( err == errCouldntSetFocus )
1052 return ;
1053
1054#if !TARGET_API_MAC_OSX
1055 // emulate carbon events when running under carbonlib where they are not natively available
1056 if ( former )
1057 {
1058 EventRef evRef = NULL ;
1059 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1060 &evRef ) );
1061
1062 wxMacCarbonEvent cEvent( evRef ) ;
1063 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
1064 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
8b573fb8 1065
f1d527c1
SC
1066 wxMacWindowEventHandler( NULL , evRef , former ) ;
1067 ReleaseEvent(evRef) ;
6264b550 1068 }
f1d527c1 1069 // send new focus event
6264b550 1070 {
f1d527c1
SC
1071 EventRef evRef = NULL ;
1072 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
1073 &evRef ) );
1074
1075 wxMacCarbonEvent cEvent( evRef ) ;
1076 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
1077 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
8b573fb8 1078
f1d527c1
SC
1079 wxMacWindowEventHandler( NULL , evRef , this ) ;
1080 ReleaseEvent(evRef) ;
6264b550 1081 }
f1d527c1 1082#endif
6264b550 1083 }
e9576ca5
SC
1084}
1085
e9576ca5 1086
4116c221 1087void wxWindowMac::DoCaptureMouse()
e9576ca5 1088{
2a1f999f 1089 wxApp::s_captureWindow = this ;
e9576ca5
SC
1090}
1091
90b959ae
SC
1092wxWindow* wxWindowBase::GetCapture()
1093{
2a1f999f 1094 return wxApp::s_captureWindow ;
90b959ae
SC
1095}
1096
4116c221 1097void wxWindowMac::DoReleaseMouse()
e9576ca5 1098{
2a1f999f 1099 wxApp::s_captureWindow = NULL ;
e9576ca5
SC
1100}
1101
e9576ca5
SC
1102#if wxUSE_DRAG_AND_DROP
1103
e766c8a9 1104void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
e9576ca5 1105{
e40298d5
JS
1106 if ( m_dropTarget != 0 ) {
1107 delete m_dropTarget;
1108 }
6ed71b4f 1109
e40298d5
JS
1110 m_dropTarget = pDropTarget;
1111 if ( m_dropTarget != 0 )
1112 {
1113 // TODO
1114 }
e9576ca5
SC
1115}
1116
1117#endif
1118
1119// Old style file-manager drag&drop
e766c8a9 1120void wxWindowMac::DragAcceptFiles(bool accept)
e9576ca5
SC
1121{
1122 // TODO
1123}
1124
055a486b
SC
1125// Returns the size of the native control. In the case of the toplevel window
1126// this is the content area root control
1127
facd6764 1128void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
8b573fb8 1129 int& w, int& h) const
e9576ca5 1130{
1f1c8bd4 1131 wxFAIL_MSG( wxT("Not supported anymore") ) ;
e9576ca5
SC
1132}
1133
055a486b 1134// From a wx position / size calculate the appropriate size of the native control
8b573fb8 1135
facd6764
SC
1136bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
1137 const wxSize& size,
1138 int& x, int& y,
8b573fb8 1139 int& w, int& h , bool adjustOrigin ) const
51abe921 1140{
789ae0cf 1141 bool isCompositing = MacGetTopLevelWindow()->MacUsesCompositing() ;
902725ee 1142
5ca0d812 1143 // the desired size, minus the border pixels gives the correct size of the control
8b573fb8 1144
facd6764
SC
1145 x = (int)pos.x;
1146 y = (int)pos.y;
1147 // todo the default calls may be used as soon as PostCreateControl Is moved here
29ee02df
SC
1148 w = wxMax(size.x,0) ; // WidthDefault( size.x );
1149 h = wxMax(size.y,0) ; // HeightDefault( size.y ) ;
789ae0cf
SC
1150
1151 if ( !isCompositing )
1152 GetParent()->MacWindowToRootWindow( &x , &y ) ;
5ca0d812
SC
1153
1154 x += MacGetLeftBorderSize() ;
1155 y += MacGetTopBorderSize() ;
1156 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1157 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
8b573fb8 1158
79392158
SC
1159 if ( adjustOrigin )
1160 AdjustForParentClientOrigin( x , y ) ;
789ae0cf 1161
7ebf5540 1162 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
789ae0cf 1163 if ( !GetParent()->IsTopLevel() )
7ebf5540
SC
1164 {
1165 x -= GetParent()->MacGetLeftBorderSize() ;
1166 y -= GetParent()->MacGetTopBorderSize() ;
1167 }
789ae0cf 1168
facd6764
SC
1169 return true ;
1170}
1171
42ef83fa 1172// Get window size (not client size)
facd6764
SC
1173void wxWindowMac::DoGetSize(int *x, int *y) const
1174{
1f1c8bd4
SC
1175 Rect bounds ;
1176 m_peer->GetRect( &bounds ) ;
8b573fb8 1177
1f1c8bd4
SC
1178 if(x) *x = bounds.right - bounds.left + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1179 if(y) *y = bounds.bottom - bounds.top + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
facd6764
SC
1180}
1181
42ef83fa 1182// get the position of the bounds of this window in client coordinates of its parent
facd6764
SC
1183void wxWindowMac::DoGetPosition(int *x, int *y) const
1184{
1f1c8bd4
SC
1185 Rect bounds ;
1186 m_peer->GetRect( &bounds ) ;
902725ee 1187
1f1c8bd4
SC
1188 int x1 = bounds.left ;
1189 int y1 = bounds.top ;
789ae0cf 1190
bc2b0c1b
SC
1191 // get the wx window position from the native one
1192 x1 -= MacGetLeftBorderSize() ;
1193 y1 -= MacGetTopBorderSize() ;
1194
facd6764 1195 if ( !IsTopLevel() )
2b5f62a0 1196 {
facd6764
SC
1197 wxWindow *parent = GetParent();
1198 if ( parent )
8950f7cc 1199 {
1a02aff9
SC
1200 // we must first adjust it to be in window coordinates of the parent, as otherwise it gets lost by the clientareaorigin fix
1201 x1 += parent->MacGetLeftBorderSize() ;
1202 y1 += parent->MacGetTopBorderSize() ;
1203 // and now to client coordinates
facd6764
SC
1204 wxPoint pt(parent->GetClientAreaOrigin());
1205 x1 -= pt.x ;
1206 y1 -= pt.y ;
6ed71b4f 1207 }
2b5f62a0 1208 }
facd6764
SC
1209 if(x) *x = x1 ;
1210 if(y) *y = y1 ;
facd6764 1211}
51abe921 1212
e766c8a9 1213void wxWindowMac::DoScreenToClient(int *x, int *y) const
e9576ca5 1214{
facd6764 1215 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
8b573fb8 1216
facd6764 1217 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
8b573fb8 1218
facd6764
SC
1219 {
1220 Point localwhere = {0,0} ;
519cb848 1221
facd6764
SC
1222 if(x) localwhere.h = * x ;
1223 if(y) localwhere.v = * y ;
8b573fb8 1224
a9de2608 1225 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
facd6764
SC
1226 if(x) *x = localwhere.h ;
1227 if(y) *y = localwhere.v ;
6ed71b4f 1228
facd6764 1229 }
2078220e 1230 MacRootWindowToWindow( x , y ) ;
8b573fb8 1231
facd6764
SC
1232 wxPoint origin = GetClientAreaOrigin() ;
1233 if(x) *x -= origin.x ;
1234 if(y) *y -= origin.y ;
e9576ca5
SC
1235}
1236
e766c8a9 1237void wxWindowMac::DoClientToScreen(int *x, int *y) const
e9576ca5 1238{
facd6764
SC
1239 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1240 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
14c9cbdb 1241
facd6764
SC
1242 wxPoint origin = GetClientAreaOrigin() ;
1243 if(x) *x += origin.x ;
1244 if(y) *y += origin.y ;
14c9cbdb 1245
2078220e 1246 MacWindowToRootWindow( x , y ) ;
14c9cbdb 1247
facd6764
SC
1248 {
1249 Point localwhere = { 0,0 };
1250 if(x) localwhere.h = * x ;
1251 if(y) localwhere.v = * y ;
a9de2608 1252 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
facd6764
SC
1253 if(x) *x = localwhere.h ;
1254 if(y) *y = localwhere.v ;
1255 }
519cb848
SC
1256}
1257
e766c8a9 1258void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
519cb848 1259{
1c310985
SC
1260 wxPoint origin = GetClientAreaOrigin() ;
1261 if(x) *x += origin.x ;
1262 if(y) *y += origin.y ;
14c9cbdb 1263
1c310985
SC
1264 MacWindowToRootWindow( x , y ) ;
1265}
1266
1267void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1268{
1c310985 1269 MacRootWindowToWindow( x , y ) ;
facd6764
SC
1270
1271 wxPoint origin = GetClientAreaOrigin() ;
1c310985
SC
1272 if(x) *x -= origin.x ;
1273 if(y) *y -= origin.y ;
1274}
1275
1276void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1277{
5ca0d812 1278 wxPoint pt ;
facd6764
SC
1279 if ( x ) pt.x = *x ;
1280 if ( y ) pt.y = *y ;
1281
125c7984 1282 if ( !IsTopLevel() )
5437ff47
RD
1283 {
1284 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1285 if (top)
5ca0d812
SC
1286 {
1287 pt.x -= MacGetLeftBorderSize() ;
1288 pt.y -= MacGetTopBorderSize() ;
1289 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1290 }
5437ff47 1291 }
8b573fb8 1292
facd6764
SC
1293 if ( x ) *x = (int) pt.x ;
1294 if ( y ) *y = (int) pt.y ;
facd6764
SC
1295}
1296
1297void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1298{
1299 int x1 , y1 ;
1300 if ( x ) x1 = *x ;
1301 if ( y ) y1 = *y ;
1302 MacWindowToRootWindow( &x1 , &y1 ) ;
1303 if ( x ) *x = x1 ;
1304 if ( y ) *y = y1 ;
519cb848
SC
1305}
1306
1c310985 1307void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
519cb848 1308{
5ca0d812 1309 wxPoint pt ;
facd6764
SC
1310 if ( x ) pt.x = *x ;
1311 if ( y ) pt.y = *y ;
1312
125c7984 1313 if ( !IsTopLevel() )
5ca0d812 1314 {
5c840e5b
SC
1315 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1316 if (top)
1317 {
1318 wxMacControl::Convert( &pt , top->m_peer , m_peer ) ;
1319 pt.x += MacGetLeftBorderSize() ;
1320 pt.y += MacGetTopBorderSize() ;
1321 }
5ca0d812 1322 }
8b573fb8 1323
facd6764
SC
1324 if ( x ) *x = (int) pt.x ;
1325 if ( y ) *y = (int) pt.y ;
e9576ca5
SC
1326}
1327
facd6764 1328void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
e9576ca5 1329{
facd6764
SC
1330 int x1 , y1 ;
1331 if ( x ) x1 = *x ;
1332 if ( y ) y1 = *y ;
1333 MacRootWindowToWindow( &x1 , &y1 ) ;
1334 if ( x ) *x = x1 ;
1335 if ( y ) *y = y1 ;
1336}
6ed71b4f 1337
29281095
SC
1338void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1339{
1340 RgnHandle rgn = NewRgn() ;
5ca0d812 1341 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
29281095 1342 {
1f1c8bd4
SC
1343 Rect structure ;
1344 Rect content ;
29281095 1345 GetRegionBounds( rgn , &content ) ;
1f1c8bd4
SC
1346 m_peer->GetRect( &structure ) ;
1347 OffsetRect( &structure, -structure.left , -structure.top ) ;
902725ee 1348
1f1c8bd4
SC
1349 left = content.left - structure.left ;
1350 top = content.top - structure.top ;
1351 right = structure.right - content.right ;
1352 bottom = structure.bottom - content.bottom ;
29281095
SC
1353 }
1354 else
1355 {
1f1c8bd4 1356 left = top = right = bottom = 0 ;
29281095 1357 }
7596e51d 1358 DisposeRgn( rgn ) ;
29281095
SC
1359}
1360
facd6764
SC
1361wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1362{
1363 wxSize sizeTotal = size;
1364
1365 RgnHandle rgn = NewRgn() ;
1366
5ca0d812 1367 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
6618870d 1368 {
1f1c8bd4
SC
1369 Rect content ;
1370 Rect structure ;
facd6764 1371 GetRegionBounds( rgn , &content ) ;
789ae0cf 1372
1f1c8bd4
SC
1373 m_peer->GetRect( &structure ) ;
1374 // structure is in parent coordinates, but we only need width and height, so it's ok
6ed71b4f 1375
1f1c8bd4
SC
1376 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1377 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
1378 }
1379 DisposeRgn( rgn ) ;
6ed71b4f 1380
facd6764
SC
1381 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1382 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
6ed71b4f 1383
facd6764 1384 return sizeTotal;
e9576ca5
SC
1385}
1386
1387
1388// Get size *available for subwindows* i.e. excluding menu bar etc.
e766c8a9 1389void wxWindowMac::DoGetClientSize(int *x, int *y) const
e9576ca5 1390{
9453cf2b 1391 int ww, hh;
6ed71b4f 1392
facd6764
SC
1393 RgnHandle rgn = NewRgn() ;
1394 Rect content ;
5ca0d812 1395 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
facd6764
SC
1396 {
1397 GetRegionBounds( rgn , &content ) ;
facd6764
SC
1398 }
1399 else
1400 {
5ca0d812 1401 m_peer->GetRect( &content ) ;
facd6764 1402 }
7596e51d 1403 DisposeRgn( rgn ) ;
789ae0cf 1404
facd6764
SC
1405 ww = content.right - content.left ;
1406 hh = content.bottom - content.top ;
6ed71b4f 1407
db7a550b
SC
1408 if (m_hScrollBar && m_hScrollBar->IsShown() )
1409 {
e905b636 1410 hh -= m_hScrollBar->GetSize().y ;
db7a550b
SC
1411 }
1412 if (m_vScrollBar && m_vScrollBar->IsShown() )
1413 {
e905b636 1414 ww -= m_vScrollBar->GetSize().x ;
db7a550b 1415 }
e40298d5
JS
1416 if(x) *x = ww;
1417 if(y) *y = hh;
facd6764
SC
1418
1419}
1420
1421bool wxWindowMac::SetCursor(const wxCursor& cursor)
1422{
1423 if (m_cursor == cursor)
902725ee 1424 return false;
facd6764
SC
1425
1426 if (wxNullCursor == cursor)
1427 {
1428 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
902725ee 1429 return false ;
facd6764
SC
1430 }
1431 else
1432 {
1433 if ( ! wxWindowBase::SetCursor( cursor ) )
902725ee 1434 return false ;
facd6764
SC
1435 }
1436
1437 wxASSERT_MSG( m_cursor.Ok(),
1438 wxT("cursor must be valid after call to the base version"));
8b573fb8
VZ
1439
1440
2d1760d3 1441 wxWindowMac *mouseWin = 0 ;
facd6764 1442 {
789ae0cf
SC
1443 wxTopLevelWindowMac *tlw = MacGetTopLevelWindow() ;
1444 WindowRef window = (WindowRef) ( tlw ? tlw->MacGetWindowRef() : 0 ) ;
2d1760d3
SC
1445 CGrafPtr savePort ;
1446 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
8b573fb8 1447
2d1760d3
SC
1448 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1449 // position, use it...
8b573fb8 1450
2d1760d3
SC
1451 Point pt ;
1452 GetMouse( &pt ) ;
1453 ControlPartCode part ;
1454 ControlRef control ;
789ae0cf 1455 control = wxMacFindControlUnderMouse( tlw , pt , window , &part ) ;
2d1760d3
SC
1456 if ( control )
1457 mouseWin = wxFindControlFromMacControl( control ) ;
8b573fb8 1458
2d1760d3
SC
1459 if ( swapped )
1460 QDSwapPort( savePort , NULL ) ;
facd6764 1461 }
2d1760d3
SC
1462
1463 if ( mouseWin == this && !wxIsBusy() )
facd6764
SC
1464 {
1465 m_cursor.MacInstall() ;
1466 }
1467
902725ee 1468 return true ;
519cb848
SC
1469}
1470
facd6764
SC
1471#if wxUSE_MENUS
1472bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1473{
1474 menu->SetInvokingWindow(this);
1475 menu->UpdateUI();
8b573fb8 1476
971562cb
VS
1477 if ( x == -1 && y == -1 )
1478 {
1479 wxPoint mouse = wxGetMousePosition();
1480 x = mouse.x; y = mouse.y;
1481 }
1482 else
1483 {
1484 ClientToScreen( &x , &y ) ;
1485 }
facd6764
SC
1486
1487 menu->MacBeforeDisplay( true ) ;
1488 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1489 if ( HiWord(menuResult) != 0 )
1490 {
1491 MenuCommand id ;
1492 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1493 wxMenuItem* item = NULL ;
1494 wxMenu* realmenu ;
1495 item = menu->FindItem(id, &realmenu) ;
1496 if (item->IsCheckable())
1497 {
1498 item->Check( !item->IsChecked() ) ;
1499 }
1500 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1501 }
1502 menu->MacAfterDisplay( true ) ;
1503
1504 menu->SetInvokingWindow(NULL);
1505
902725ee 1506 return true;
facd6764
SC
1507}
1508#endif
51abe921
SC
1509
1510// ----------------------------------------------------------------------------
1511// tooltips
1512// ----------------------------------------------------------------------------
1513
1514#if wxUSE_TOOLTIPS
1515
e766c8a9 1516void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
51abe921
SC
1517{
1518 wxWindowBase::DoSetToolTip(tooltip);
6ed71b4f 1519
6264b550
RR
1520 if ( m_tooltip )
1521 m_tooltip->SetWindow(this);
51abe921
SC
1522}
1523
1524#endif // wxUSE_TOOLTIPS
1525
902725ee 1526void wxWindowMac::MacInvalidateBorders()
6449b3a8
SC
1527{
1528 if ( m_peer == NULL )
1529 return ;
1530
1531 bool vis = MacIsReallyShown() ;
1532 if ( !vis )
1533 return ;
902725ee 1534
6449b3a8
SC
1535 int outerBorder = MacGetLeftBorderSize() ;
1536 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1537 outerBorder += 4 ;
1538
1539 if ( outerBorder == 0 )
1540 return ;
902725ee
WS
1541
1542 // now we know that we have something to do at all
6449b3a8
SC
1543
1544 // as the borders are drawn on the parent we have to properly invalidate all these areas
902725ee 1545 RgnHandle updateInner = NewRgn() ,
6449b3a8
SC
1546 updateOuter = NewRgn() ;
1547
1548 // this rectangle is in HIViewCoordinates under OSX and in Window Coordinates under Carbon
1549 Rect rect ;
1550 m_peer->GetRect( &rect ) ;
1551 RectRgn( updateInner , &rect ) ;
1552 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1553 RectRgn( updateOuter , &rect ) ;
1554 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1555#ifdef __WXMAC_OSX__
1f1c8bd4 1556 GetParent()->m_peer->SetNeedsDisplay( updateOuter ) ;
6449b3a8
SC
1557#else
1558 WindowRef tlw = (WindowRef) MacGetTopLevelWindowRef() ;
1559 if ( tlw )
1560 InvalWindowRgn( tlw , updateOuter ) ;
1561#endif
1562 DisposeRgn(updateOuter) ;
1563 DisposeRgn(updateInner) ;
1564/*
1565 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() ;
1566 RectRgn( updateInner , &rect ) ;
1567 InsetRect( &rect , -4 , -4 ) ;
1568 RectRgn( updateOuter , &rect ) ;
1569 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1570 wxPoint parent(0,0);
1571 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1572 parent -= GetParent()->GetClientAreaOrigin() ;
1573 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1574 GetParent()->m_peer->SetNeedsDisplay( true , updateOuter ) ;
1575 DisposeRgn(updateOuter) ;
1576 DisposeRgn(updateInner) ;
1577*/
1578/*
1579 if ( m_peer )
1580 {
1581 // deleting a window while it is shown invalidates the region occupied by border or
1582 // focus
1583
1584 if ( IsShown() && ( outerBorder > 0 ) )
1585 {
1586 // as the borders are drawn on the parent we have to properly invalidate all these areas
1587 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1588
1589 Rect rect ;
1590
1591 m_peer->GetRect( &rect ) ;
1592 RectRgn( updateInner , &rect ) ;
1593 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1594 RectRgn( updateOuter , &rect ) ;
1595 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1596 wxPoint parent(0,0);
1597 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1598 parent -= GetParent()->GetClientAreaOrigin() ;
1599 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1600 CopyRgn( updateOuter , updateTotal ) ;
1601
1602 GetParent()->m_peer->SetNeedsDisplay( true , updateTotal ) ;
1603 DisposeRgn(updateOuter) ;
1604 DisposeRgn(updateInner) ;
1605 DisposeRgn(updateTotal) ;
1606 }
1607 }
1608*/
1609#if 0
1610 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
1611
1612 int outerBorder = MacGetLeftBorderSize() ;
1613 if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() )
1614 outerBorder += 4 ;
1615
1616 if ( vis && ( outerBorder > 0 ) )
1617 {
1618 // as the borders are drawn on the parent we have to properly invalidate all these areas
1619 RgnHandle updateInner = NewRgn() , updateOuter = NewRgn() , updateTotal = NewRgn() ;
1620
1621 Rect rect ;
1622
1623 m_peer->GetRect( &rect ) ;
1624 RectRgn( updateInner , &rect ) ;
1625 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1626 RectRgn( updateOuter , &rect ) ;
1627 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1628 /*
1629 wxPoint parent(0,0);
1630#if TARGET_API_MAC_OSX
1631 // no offsetting needed when compositing
1632#else
1633 GetParent()->MacWindowToRootWindow( &parent.x , &parent.y ) ;
1634 parent -= GetParent()->GetClientAreaOrigin() ;
1635 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1636#endif
1637 */
1638 CopyRgn( updateOuter , updateTotal ) ;
1639
1640 rect = r ;
1641 RectRgn( updateInner , &rect ) ;
1642 InsetRect( &rect , -outerBorder , -outerBorder ) ;
1643 RectRgn( updateOuter , &rect ) ;
1644 DiffRgn( updateOuter , updateInner ,updateOuter ) ;
1645/*
1646 OffsetRgn( updateOuter , -parent.x , -parent.y ) ;
1647*/
1648 UnionRgn( updateOuter , updateTotal , updateTotal ) ;
1649
1f1c8bd4 1650 GetParent()->m_peer->SetNeedsDisplay( updateTotal ) ;
6449b3a8
SC
1651 DisposeRgn(updateOuter) ;
1652 DisposeRgn(updateInner) ;
1653 DisposeRgn(updateTotal) ;
1654 }
1655#endif
1656}
1657
e766c8a9 1658void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
51abe921 1659{
db7a550b 1660 // this is never called for a toplevel window, so we know we have a parent
facd6764 1661 int former_x , former_y , former_w, former_h ;
db7a550b
SC
1662
1663 // Get true coordinates of former position
facd6764
SC
1664 DoGetPosition( &former_x , &former_y ) ;
1665 DoGetSize( &former_w , &former_h ) ;
db7a550b
SC
1666
1667 wxWindow *parent = GetParent();
1668 if ( parent )
1669 {
1670 wxPoint pt(parent->GetClientAreaOrigin());
1671 former_x += pt.x ;
1672 former_y += pt.y ;
1673 }
6ed71b4f 1674
29ee02df
SC
1675 int actualWidth = width ;
1676 int actualHeight = height ;
e40298d5
JS
1677 int actualX = x;
1678 int actualY = y;
6ed71b4f 1679
14c9cbdb 1680 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
6264b550 1681 actualWidth = m_minWidth;
14c9cbdb 1682 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
6264b550 1683 actualHeight = m_minHeight;
14c9cbdb 1684 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
6264b550 1685 actualWidth = m_maxWidth;
14c9cbdb 1686 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
902725ee 1687 actualHeight = m_maxHeight;
6ed71b4f 1688
6264b550
RR
1689 bool doMove = false ;
1690 bool doResize = false ;
6ed71b4f 1691
6264b550
RR
1692 if ( actualX != former_x || actualY != former_y )
1693 {
1694 doMove = true ;
1695 }
1696 if ( actualWidth != former_w || actualHeight != former_h )
1697 {
1698 doResize = true ;
1699 }
6ed71b4f 1700
6264b550
RR
1701 if ( doMove || doResize )
1702 {
902725ee 1703 // as the borders are drawn outside the native control, we adjust now
1f1c8bd4 1704
902725ee
WS
1705 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
1706 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1f1c8bd4
SC
1707 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1708
1709 Rect r ;
1710 wxMacRectToNative( &bounds , &r ) ;
1711
1712 if ( !GetParent()->IsTopLevel() )
1713 {
1714 wxMacWindowToNative( GetParent() , &r ) ;
1715 }
8b573fb8 1716
6449b3a8 1717 MacInvalidateBorders() ;
902725ee 1718
5c840e5b 1719 m_cachedClippedRectValid = false ;
8b573fb8 1720 m_peer->SetRect( &r ) ;
902725ee 1721
e905b636 1722 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
91ae6e3a 1723
6449b3a8
SC
1724 MacInvalidateBorders() ;
1725
6264b550
RR
1726 MacRepositionScrollBars() ;
1727 if ( doMove )
1728 {
facd6764 1729 wxPoint point(actualX,actualY);
6264b550
RR
1730 wxMoveEvent event(point, m_windowId);
1731 event.SetEventObject(this);
1732 GetEventHandler()->ProcessEvent(event) ;
1733 }
1734 if ( doResize )
1735 {
e40298d5 1736 MacRepositionScrollBars() ;
facd6764 1737 wxSize size(actualWidth, actualHeight);
e40298d5
JS
1738 wxSizeEvent event(size, m_windowId);
1739 event.SetEventObject(this);
1740 GetEventHandler()->ProcessEvent(event);
6264b550
RR
1741 }
1742 }
6ed71b4f 1743
954fc50b
SC
1744}
1745
facd6764
SC
1746wxSize wxWindowMac::DoGetBestSize() const
1747{
eb69d46e
SC
1748 if ( m_macIsUserPane || IsTopLevel() )
1749 return wxWindowBase::DoGetBestSize() ;
8b573fb8 1750
facd6764 1751 Rect bestsize = { 0 , 0 , 0 , 0 } ;
facd6764 1752 int bestWidth, bestHeight ;
5ca0d812 1753 m_peer->GetBestRect( &bestsize ) ;
facd6764
SC
1754
1755 if ( EmptyRect( &bestsize ) )
1756 {
facd6764
SC
1757 bestsize.left = bestsize.top = 0 ;
1758 bestsize.right = 16 ;
1759 bestsize.bottom = 16 ;
1760 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1761 {
1762 bestsize.bottom = 16 ;
1763 }
902725ee 1764#if wxUSE_SPINBTN
facd6764
SC
1765 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1766 {
8b573fb8 1767 bestsize.bottom = 24 ;
facd6764 1768 }
902725ee 1769#endif // wxUSE_SPINBTN
facd6764
SC
1770 else
1771 {
8b573fb8 1772 // return wxWindowBase::DoGetBestSize() ;
facd6764
SC
1773 }
1774 }
1775
1776 bestWidth = bestsize.right - bestsize.left ;
1777 bestHeight = bestsize.bottom - bestsize.top ;
1778 if ( bestHeight < 10 )
1779 bestHeight = 13 ;
8b573fb8 1780
facd6764
SC
1781 return wxSize(bestWidth, bestHeight);
1782}
1783
1784
954fc50b
SC
1785// set the size of the window: if the dimensions are positive, just use them,
1786// but if any of them is equal to -1, it means that we must find the value for
1787// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1788// which case -1 is a valid value for x and y)
1789//
1790// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1791// the width/height to best suit our contents, otherwise we reuse the current
1792// width/height
1793void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1794{
1795 // get the current size and position...
1796 int currentX, currentY;
1797 GetPosition(&currentX, &currentY);
6ed71b4f 1798
954fc50b
SC
1799 int currentW,currentH;
1800 GetSize(&currentW, &currentH);
6ed71b4f 1801
954fc50b
SC
1802 // ... and don't do anything (avoiding flicker) if it's already ok
1803 if ( x == currentX && y == currentY &&
769ac869 1804 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
954fc50b 1805 {
facd6764 1806 // TODO REMOVE
6264b550 1807 MacRepositionScrollBars() ; // we might have a real position shift
954fc50b
SC
1808 return;
1809 }
6ed71b4f 1810
3dee36ae 1811 if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
954fc50b 1812 x = currentX;
3dee36ae 1813 if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
954fc50b 1814 y = currentY;
6ed71b4f 1815
954fc50b 1816 AdjustForParentClientOrigin(x, y, sizeFlags);
6ed71b4f 1817
3dee36ae
WS
1818 wxSize size = wxDefaultSize;
1819 if ( width == wxDefaultCoord )
954fc50b
SC
1820 {
1821 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1822 {
1823 size = DoGetBestSize();
1824 width = size.x;
1825 }
1826 else
1827 {
1828 // just take the current one
1829 width = currentW;
1830 }
1831 }
6ed71b4f 1832
3dee36ae 1833 if ( height == wxDefaultCoord )
954fc50b
SC
1834 {
1835 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1836 {
3dee36ae 1837 if ( size.x == wxDefaultCoord )
954fc50b
SC
1838 {
1839 size = DoGetBestSize();
1840 }
1841 //else: already called DoGetBestSize() above
6ed71b4f 1842
954fc50b
SC
1843 height = size.y;
1844 }
1845 else
1846 {
1847 // just take the current one
1848 height = currentH;
1849 }
1850 }
6ed71b4f 1851
954fc50b 1852 DoMoveWindow(x, y, width, height);
6ed71b4f 1853
e9576ca5 1854}
519cb848 1855
e766c8a9 1856wxPoint wxWindowMac::GetClientAreaOrigin() const
e9576ca5 1857{
facd6764
SC
1858 RgnHandle rgn = NewRgn() ;
1859 Rect content ;
04d4e684 1860 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
21638402
SC
1861 {
1862 GetRegionBounds( rgn , &content ) ;
1863 }
1864 else
1865 {
1866 content.left = content.top = 0 ;
1867 }
facd6764 1868 DisposeRgn( rgn ) ;
facd6764
SC
1869 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1870}
1871
1872void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1873{
3dee36ae 1874 if ( clientheight != wxDefaultCoord || clientheight != wxDefaultCoord )
facd6764
SC
1875 {
1876 int currentclientwidth , currentclientheight ;
1877 int currentwidth , currentheight ;
1878
1879 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1880 GetSize( &currentwidth , &currentheight ) ;
1881
3dee36ae 1882 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
facd6764
SC
1883 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1884 }
e9576ca5
SC
1885}
1886
d84afea9 1887void wxWindowMac::SetTitle(const wxString& title)
e9576ca5 1888{
facd6764
SC
1889 m_label = wxStripMenuCodes(title) ;
1890
21fd5529 1891 if ( m_peer && m_peer->Ok() )
facd6764 1892 {
5ca0d812 1893 m_peer->SetTitle( m_label ) ;
facd6764
SC
1894 }
1895 Refresh() ;
519cb848
SC
1896}
1897
d84afea9 1898wxString wxWindowMac::GetTitle() const
519cb848 1899{
ed60b502 1900 return m_label ;
519cb848
SC
1901}
1902
8ab50549
SC
1903bool wxWindowMac::Show(bool show)
1904{
542f604f 1905 bool former = MacIsReallyShown() ;
8ab50549 1906 if ( !wxWindowBase::Show(show) )
902725ee 1907 return false;
8b573fb8 1908
8ab50549 1909 // TODO use visibilityChanged Carbon Event for OSX
2c899c20
SC
1910 if ( m_peer )
1911 {
2c899c20 1912 m_peer->SetVisibility( show , true ) ;
2c899c20 1913 }
542f604f
SC
1914 if ( former != MacIsReallyShown() )
1915 MacPropagateVisibilityChanged() ;
902725ee 1916 return true;
8ab50549
SC
1917}
1918
1919bool wxWindowMac::Enable(bool enable)
1920{
21fd5529 1921 wxASSERT( m_peer->Ok() ) ;
542f604f 1922 bool former = MacIsReallyEnabled() ;
8ab50549 1923 if ( !wxWindowBase::Enable(enable) )
902725ee 1924 return false;
8ab50549 1925
5ca0d812 1926 m_peer->Enable( enable ) ;
8ab50549
SC
1927
1928 if ( former != MacIsReallyEnabled() )
1929 MacPropagateEnabledStateChanged() ;
902725ee 1930 return true;
8ab50549
SC
1931}
1932
8b573fb8 1933//
8ab50549
SC
1934// status change propagations (will be not necessary for OSX later )
1935//
1936
facd6764
SC
1937void wxWindowMac::MacPropagateVisibilityChanged()
1938{
73fe67bd 1939#if !TARGET_API_MAC_OSX
facd6764 1940 MacVisibilityChanged() ;
8b573fb8 1941
71f2fb52 1942 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
facd6764
SC
1943 while ( node )
1944 {
1945 wxWindowMac *child = node->GetData();
1946 if ( child->IsShown() )
1947 child->MacPropagateVisibilityChanged( ) ;
1948 node = node->GetNext();
1949 }
73fe67bd 1950#endif
facd6764
SC
1951}
1952
8ab50549 1953void wxWindowMac::MacPropagateEnabledStateChanged( )
e9576ca5 1954{
73fe67bd 1955#if !TARGET_API_MAC_OSX
8ab50549 1956 MacEnabledStateChanged() ;
8b573fb8 1957
71f2fb52 1958 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
8ab50549
SC
1959 while ( node )
1960 {
1961 wxWindowMac *child = node->GetData();
1962 if ( child->IsEnabled() )
1963 child->MacPropagateEnabledStateChanged() ;
1964 node = node->GetNext();
1965 }
73fe67bd 1966#endif
8ab50549
SC
1967}
1968
1969void wxWindowMac::MacPropagateHiliteChanged( )
1970{
73fe67bd 1971#if !TARGET_API_MAC_OSX
8ab50549 1972 MacHiliteChanged() ;
8b573fb8 1973
71f2fb52 1974 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
8ab50549
SC
1975 while ( node )
1976 {
1977 wxWindowMac *child = node->GetData();
1978 // if ( child->IsEnabled() )
1979 child->MacPropagateHiliteChanged() ;
1980 node = node->GetNext();
1981 }
73fe67bd 1982#endif
8ab50549
SC
1983}
1984
1985//
1986// status change notifications
8b573fb8 1987//
8ab50549 1988
8b573fb8 1989void wxWindowMac::MacVisibilityChanged()
8ab50549
SC
1990{
1991}
1992
8b573fb8 1993void wxWindowMac::MacHiliteChanged()
8ab50549
SC
1994{
1995}
1996
8b573fb8 1997void wxWindowMac::MacEnabledStateChanged()
8ab50549 1998{
facd6764 1999}
e7549107 2000
8ab50549
SC
2001//
2002// status queries on the inherited window's state
2003//
2004
8b573fb8 2005bool wxWindowMac::MacIsReallyShown()
facd6764
SC
2006{
2007 // only under OSX the visibility of the TLW is taken into account
66ffb23b
SC
2008 if ( m_isBeingDeleted )
2009 return false ;
902725ee 2010
facd6764 2011#if TARGET_API_MAC_OSX
aa522e33
SC
2012 if ( m_peer && m_peer->Ok() )
2013 return m_peer->IsVisible();
2014#endif
facd6764
SC
2015 wxWindow* win = this ;
2016 while( win->IsShown() )
2017 {
2018 if ( win->IsTopLevel() )
2019 return true ;
8b573fb8 2020
facd6764
SC
2021 win = win->GetParent() ;
2022 if ( win == NULL )
2023 return true ;
8b573fb8 2024
facd6764
SC
2025 } ;
2026 return false ;
facd6764 2027}
4241baae 2028
8b573fb8 2029bool wxWindowMac::MacIsReallyEnabled()
facd6764 2030{
5ca0d812 2031 return m_peer->IsEnabled() ;
facd6764
SC
2032}
2033
8b573fb8 2034bool wxWindowMac::MacIsReallyHilited()
c809f3be 2035{
5ca0d812 2036 return m_peer->IsActive();
c809f3be
SC
2037}
2038
8b573fb8 2039void wxWindowMac::MacFlashInvalidAreas()
002c9672
SC
2040{
2041#if TARGET_API_MAC_OSX
2042 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
2043#endif
2044}
2045
8ab50549
SC
2046//
2047//
2048//
2049
e766c8a9 2050int wxWindowMac::GetCharHeight() const
e9576ca5 2051{
6264b550
RR
2052 wxClientDC dc ( (wxWindowMac*)this ) ;
2053 return dc.GetCharHeight() ;
e9576ca5
SC
2054}
2055
e766c8a9 2056int wxWindowMac::GetCharWidth() const
e9576ca5 2057{
6264b550
RR
2058 wxClientDC dc ( (wxWindowMac*)this ) ;
2059 return dc.GetCharWidth() ;
e9576ca5
SC
2060}
2061
e766c8a9 2062void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 2063 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 2064{
e7549107
SC
2065 const wxFont *fontToUse = theFont;
2066 if ( !fontToUse )
2067 fontToUse = &m_font;
14c9cbdb 2068
e766c8a9 2069 wxClientDC dc( (wxWindowMac*) this ) ;
7c74e7fe 2070 long lx,ly,ld,le ;
5fde6fcc 2071 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2f1ae414 2072 if ( externalLeading )
6264b550 2073 *externalLeading = le ;
2f1ae414 2074 if ( descent )
6264b550 2075 *descent = ld ;
2f1ae414 2076 if ( x )
6264b550 2077 *x = lx ;
2f1ae414 2078 if ( y )
6264b550 2079 *y = ly ;
e9576ca5
SC
2080}
2081
0a67a93b 2082/*
14c9cbdb 2083 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1c310985
SC
2084 * we always intersect with the entire window, not only with the client area
2085 */
14c9cbdb 2086
e766c8a9 2087void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
e9576ca5 2088{
065ab451
SC
2089 if ( m_peer == NULL )
2090 return ;
8b573fb8 2091
1f1c8bd4
SC
2092 if ( !MacIsReallyShown() )
2093 return ;
789ae0cf 2094
1f1c8bd4 2095 if ( rect )
1e8cde71 2096 {
1f1c8bd4
SC
2097 Rect r ;
2098 wxMacRectToNative( rect , &r ) ;
2099 m_peer->SetNeedsDisplay( &r ) ;
facd6764 2100 }
1f1c8bd4 2101 else
9a456218 2102 {
1f1c8bd4 2103 m_peer->SetNeedsDisplay() ;
e9576ca5 2104 }
facd6764
SC
2105}
2106
79392158
SC
2107void wxWindowMac::Freeze()
2108{
2109#if TARGET_API_MAC_OSX
2110 if ( !m_frozenness++ )
2111 {
52ef5c3c
RD
2112 if ( m_peer && m_peer->Ok() )
2113 m_peer->SetDrawingEnabled( false ) ;
79392158
SC
2114 }
2115#endif
2116}
2117
b175b96b 2118
79392158
SC
2119void wxWindowMac::Thaw()
2120{
2121#if TARGET_API_MAC_OSX
2122 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
2123
2124 if ( !--m_frozenness )
2125 {
52ef5c3c
RD
2126 if ( m_peer && m_peer->Ok() )
2127 {
2128 m_peer->SetDrawingEnabled( true ) ;
2129 m_peer->InvalidateWithChildren() ;
2130 }
79392158
SC
2131 }
2132#endif
2133}
2134
e766c8a9 2135wxWindowMac *wxGetActiveWindow()
e9576ca5 2136{
519cb848 2137 // actually this is a windows-only concept
e9576ca5
SC
2138 return NULL;
2139}
2140
e9576ca5 2141// Coordinates relative to the window
e766c8a9 2142void wxWindowMac::WarpPointer (int x_pos, int y_pos)
e9576ca5 2143{
e40298d5 2144 // We really don't move the mouse programmatically under Mac.
e9576ca5
SC
2145}
2146
facd6764 2147void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
e9576ca5 2148{
3dee36ae
WS
2149 if ( MacGetTopLevelWindow() == NULL )
2150 return ;
be346c26 2151#if TARGET_API_MAC_OSX
789ae0cf 2152 if ( MacGetTopLevelWindow()->MacUsesCompositing() && (m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT ) )
94abc21f 2153 {
facd6764 2154 event.Skip() ;
94abc21f
SC
2155 }
2156 else
be346c26 2157#endif
7ebf5540 2158 {
8b573fb8 2159 event.GetDC()->Clear() ;
7ebf5540 2160 }
1c310985
SC
2161}
2162
2163void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2164{
af6b7b80 2165 event.Skip() ;
e9576ca5
SC
2166}
2167
e766c8a9 2168int wxWindowMac::GetScrollPos(int orient) const
e9576ca5 2169{
1c310985
SC
2170 if ( orient == wxHORIZONTAL )
2171 {
2172 if ( m_hScrollBar )
2173 return m_hScrollBar->GetThumbPosition() ;
2174 }
2175 else
2176 {
2177 if ( m_vScrollBar )
2178 return m_vScrollBar->GetThumbPosition() ;
2179 }
e9576ca5
SC
2180 return 0;
2181}
2182
2183// This now returns the whole range, not just the number
2184// of positions that we can scroll.
e766c8a9 2185int wxWindowMac::GetScrollRange(int orient) const
e9576ca5 2186{
1c310985
SC
2187 if ( orient == wxHORIZONTAL )
2188 {
2189 if ( m_hScrollBar )
2190 return m_hScrollBar->GetRange() ;
2191 }
2192 else
2193 {
2194 if ( m_vScrollBar )
2195 return m_vScrollBar->GetRange() ;
2196 }
e9576ca5
SC
2197 return 0;
2198}
2199
e766c8a9 2200int wxWindowMac::GetScrollThumb(int orient) const
e9576ca5 2201{
1c310985
SC
2202 if ( orient == wxHORIZONTAL )
2203 {
2204 if ( m_hScrollBar )
2205 return m_hScrollBar->GetThumbSize() ;
2206 }
2207 else
2208 {
2209 if ( m_vScrollBar )
2210 return m_vScrollBar->GetThumbSize() ;
2211 }
e9576ca5
SC
2212 return 0;
2213}
2214
e766c8a9 2215void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
e9576ca5 2216{
1c310985 2217 if ( orient == wxHORIZONTAL )
6264b550 2218 {
1c310985
SC
2219 if ( m_hScrollBar )
2220 m_hScrollBar->SetThumbPosition( pos ) ;
6264b550
RR
2221 }
2222 else
2223 {
1c310985
SC
2224 if ( m_vScrollBar )
2225 m_vScrollBar->SetThumbPosition( pos ) ;
6264b550 2226 }
2f1ae414
SC
2227}
2228
c79aad8b
SC
2229//
2230// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
2231// our own window origin is at leftOrigin/rightOrigin
2232//
2233
2234void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2f1ae414 2235{
1c310985 2236 if( IsTopLevel() )
6264b550 2237 return ;
8b573fb8 2238
fd926bcc 2239 Rect rect ;
c79aad8b
SC
2240 bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2241 bool hasBothScrollbars = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2242
8b573fb8 2243 m_peer->GetRect( &rect ) ;
8f39b6c4
SC
2244 // back to the surrounding frame rectangle
2245 InsetRect( &rect, -1 , -1 ) ;
fd926bcc 2246
c79aad8b 2247#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
91ae6e3a 2248 if ( UMAGetSystemVersion() >= 0x1030 )
c79aad8b 2249 {
8f39b6c4
SC
2250 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
2251 rect.bottom - rect.top ) ;
2252
c79aad8b
SC
2253 HIThemeFrameDrawInfo info ;
2254 memset( &info, 0 , sizeof( info ) ) ;
902725ee 2255
c79aad8b
SC
2256 info.version = 0 ;
2257 info.kind = 0 ;
2258 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2259 info.isFocused = hasFocus ;
c79aad8b
SC
2260
2261 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
2262 wxASSERT( cgContext ) ;
902725ee 2263
c79aad8b
SC
2264 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2265 {
c79aad8b 2266 info.kind = kHIThemeFrameTextFieldSquare ;
8f39b6c4 2267 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
c79aad8b
SC
2268 }
2269 else if (HasFlag(wxSIMPLE_BORDER))
2270 {
c79aad8b 2271 info.kind = kHIThemeFrameListBox ;
c79aad8b
SC
2272 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
2273 }
2274 else if ( hasFocus )
2275 {
c79aad8b
SC
2276 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2277 }
902725ee 2278
c79aad8b
SC
2279 m_peer->GetRect( &rect ) ;
2280 if ( hasBothScrollbars )
2281 {
c79aad8b 2282 int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
8f39b6c4
SC
2283 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
2284 CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
902725ee 2285 HIThemeGrowBoxDrawInfo info ;
c79aad8b
SC
2286 memset( &info, 0 , sizeof( info ) ) ;
2287 info.version = 0 ;
2288 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2289 info.kind = kHIThemeGrowBoxKindNone ;
2290 info.size = kHIThemeGrowBoxSizeNormal ;
2291 info.direction = kThemeGrowRight | kThemeGrowDown ;
2292 HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2293 }
2294 }
2295 else
2296#endif
fd926bcc
SC
2297 {
2298 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1f1c8bd4 2299 if (top )
fd926bcc
SC
2300 {
2301 wxPoint pt(0,0) ;
2302 wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ;
1f1c8bd4 2303 OffsetRect( &rect , pt.x , pt.y ) ;
fd926bcc 2304 }
8b573fb8 2305
c79aad8b
SC
2306 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2307 {
8f39b6c4 2308 DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
c79aad8b
SC
2309 }
2310 else if (HasFlag(wxSIMPLE_BORDER))
2311 {
c79aad8b
SC
2312 DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
2313 }
902725ee 2314
c79aad8b
SC
2315 if ( hasFocus )
2316 {
8f39b6c4 2317 DrawThemeFocusRect( &rect , true ) ;
c79aad8b 2318 }
8f39b6c4 2319
c79aad8b
SC
2320 if ( hasBothScrollbars )
2321 {
902725ee 2322 // GetThemeStandaloneGrowBoxBounds
c79aad8b
SC
2323 //DrawThemeStandaloneNoGrowBox
2324 }
eec462f8 2325 }
8208e181
SC
2326}
2327
abda5788
SC
2328void wxWindowMac::RemoveChild( wxWindowBase *child )
2329{
2330 if ( child == m_hScrollBar )
2331 m_hScrollBar = NULL ;
2332 if ( child == m_vScrollBar )
2333 m_vScrollBar = NULL ;
14c9cbdb 2334
abda5788
SC
2335 wxWindowBase::RemoveChild( child ) ;
2336}
2337
e9576ca5 2338// New function that will replace some of the above.
e766c8a9 2339void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
e9576ca5
SC
2340 int range, bool refresh)
2341{
e40298d5
JS
2342 if ( orient == wxHORIZONTAL )
2343 {
2344 if ( m_hScrollBar )
6264b550 2345 {
e40298d5 2346 if ( range == 0 || thumbVisible >= range )
6264b550 2347 {
e40298d5
JS
2348 if ( m_hScrollBar->IsShown() )
2349 m_hScrollBar->Show(false) ;
2350 }
2351 else
2352 {
2353 if ( !m_hScrollBar->IsShown() )
2354 m_hScrollBar->Show(true) ;
6264b550 2355 }
11ca2edf 2356 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
6264b550 2357 }
e40298d5
JS
2358 }
2359 else
2360 {
2361 if ( m_vScrollBar )
6264b550 2362 {
e40298d5 2363 if ( range == 0 || thumbVisible >= range )
6264b550 2364 {
e40298d5
JS
2365 if ( m_vScrollBar->IsShown() )
2366 m_vScrollBar->Show(false) ;
2367 }
2368 else
2369 {
2370 if ( !m_vScrollBar->IsShown() )
2371 m_vScrollBar->Show(true) ;
6264b550 2372 }
11ca2edf 2373 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
6264b550 2374 }
e40298d5
JS
2375 }
2376 MacRepositionScrollBars() ;
e9576ca5
SC
2377}
2378
2379// Does a physical scroll
e766c8a9 2380void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
e9576ca5 2381{
ba87f54c
SC
2382 if( dx == 0 && dy ==0 )
2383 return ;
8b573fb8 2384
3dee36ae
WS
2385 int width , height ;
2386 GetClientSize( &width , &height ) ;
adb8a71b 2387#if TARGET_API_MAC_OSX
902725ee
WS
2388 if ( 1 /* m_peer->IsCompositing() */ )
2389 {
002c9672 2390 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
8b573fb8 2391 // area is scrolled, this does not occur if width and height are 2 pixels less,
002c9672 2392 // TODO write optimal workaround
42ef83fa 2393 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
8b573fb8 2394 if ( rect )
adb8a71b 2395 {
5ca0d812 2396 scrollrect.Intersect( *rect ) ;
adb8a71b 2397 }
5ca0d812 2398 if ( m_peer->GetNeedsDisplay() )
002c9672
SC
2399 {
2400 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2401 // either immediate redraw or full invalidate
2402#if 1
2403 // is the better overall solution, as it does not slow down scrolling
1f1c8bd4 2404 m_peer->SetNeedsDisplay() ;
002c9672 2405#else
8b573fb8 2406 // this would be the preferred version for fast drawing controls
92346151 2407
f474cc8c
SC
2408#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2409 if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
42ef83fa 2410 HIViewRender(m_peer->GetControlRef()) ;
f474cc8c
SC
2411 else
2412#endif
2413 Update() ;
002c9672
SC
2414#endif
2415 }
84e5d27d
SC
2416 // as the native control might be not a 0/0 wx window coordinates, we have to offset
2417 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
92346151
SC
2418 m_peer->ScrollRect( (&scrollrect) , dx , dy ) ;
2419
2420 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2421 // either immediate redraw or full invalidate
2422#if 0
2423 // is the better overall solution, as it does not slow down scrolling
2424 m_peer->SetNeedsDisplay() ;
adb8a71b 2425#else
902725ee 2426 // this would be the preferred version for fast drawing controls
92346151 2427
f474cc8c
SC
2428#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2429 if( UMAGetSystemVersion() >= 0x1030 && m_peer->IsCompositing() )
2430 HIViewRender(m_peer->GetControlRef()) ;
2431 else
2432#endif
902725ee 2433 Update() ;
f474cc8c 2434
92346151 2435#endif
902725ee
WS
2436 }
2437 else
92346151 2438#endif
902725ee 2439 {
6ed71b4f 2440
facd6764 2441 wxPoint pos;
8b573fb8 2442 pos.x = pos.y = 0;
430e1eed 2443
facd6764 2444 Rect scrollrect;
6264b550 2445 RgnHandle updateRgn = NewRgn() ;
430e1eed 2446
3dee36ae 2447 {
430e1eed
SC
2448 wxClientDC dc(this) ;
2449 wxMacPortSetter helper(&dc) ;
8b573fb8 2450
92346151
SC
2451 m_peer->GetRectInWindowCoords( &scrollrect ) ;
2452 //scrollrect.top += MacGetTopBorderSize() ;
2453 //scrollrect.left += MacGetLeftBorderSize() ;
430e1eed
SC
2454 scrollrect.bottom = scrollrect.top + height ;
2455 scrollrect.right = scrollrect.left + width ;
8b573fb8 2456
430e1eed
SC
2457 if ( rect )
2458 {
2459 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2460 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2461 SectRect( &scrollrect , &r , &scrollrect ) ;
2462 }
2463 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
20b69855
SC
2464
2465 // now scroll the former update region as well and add the new update region
902725ee 2466
20b69855
SC
2467 WindowRef rootWindow = (WindowRef) MacGetTopLevelWindowRef() ;
2468 RgnHandle formerUpdateRgn = NewRgn() ;
2469 RgnHandle scrollRgn = NewRgn() ;
2470 RectRgn( scrollRgn , &scrollrect ) ;
2471 GetWindowUpdateRgn( rootWindow , formerUpdateRgn ) ;
2472 Point pt = {0,0} ;
2473 LocalToGlobal( &pt ) ;
2474 OffsetRgn( formerUpdateRgn , -pt.h , -pt.v ) ;
2475 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2476 if ( !EmptyRgn( formerUpdateRgn ) )
2477 {
2478 MacOffsetRgn( formerUpdateRgn , dx , dy ) ;
2479 SectRgn( formerUpdateRgn , scrollRgn , formerUpdateRgn ) ;
2480 InvalWindowRgn(rootWindow , formerUpdateRgn ) ;
2481 }
2482 InvalWindowRgn(rootWindow , updateRgn ) ;
2483 DisposeRgn( updateRgn ) ;
2484 DisposeRgn( formerUpdateRgn ) ;
2485 DisposeRgn( scrollRgn ) ;
ba87f54c 2486 }
92346151 2487 Update() ;
6264b550 2488 }
6ed71b4f 2489
71f2fb52 2490 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
6264b550 2491 {
9bd1404d 2492 wxWindowMac *child = node->GetData();
6264b550
RR
2493 if (child == m_vScrollBar) continue;
2494 if (child == m_hScrollBar) continue;
2495 if (child->IsTopLevel()) continue;
6ed71b4f 2496
6264b550
RR
2497 int x,y;
2498 child->GetPosition( &x, &y );
2499 int w,h;
2500 child->GetSize( &w, &h );
00f55394
SC
2501 if (rect)
2502 {
2503 wxRect rc(x,y,w,h);
2504 if (rect->Intersects(rc))
2505 child->SetSize( x+dx, y+dy, w, h );
2506 }
2507 else
2508 {
8b573fb8
VZ
2509 child->SetSize( x+dx, y+dy, w, h );
2510 }
6264b550 2511 }
e9576ca5
SC
2512}
2513
e766c8a9 2514void wxWindowMac::MacOnScroll(wxScrollEvent &event )
7c74e7fe 2515{
687706f5 2516 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
6264b550
RR
2517 {
2518 wxScrollWinEvent wevent;
2519 wevent.SetPosition(event.GetPosition());
2520 wevent.SetOrientation(event.GetOrientation());
687706f5
KH
2521 wevent.SetEventObject(this);
2522
2523 if (event.GetEventType() == wxEVT_SCROLL_TOP)
2524 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
2525 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
2526 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
2527 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
2528 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
2529 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
2530 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
2531 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
2532 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
2533 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
2534 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
2535 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
2536 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
2537 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
2538 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
6ed71b4f
VZ
2539
2540 GetEventHandler()->ProcessEvent(wevent);
7c74e7fe
SC
2541 }
2542}
2543
e9576ca5 2544// Get the window with the focus
0fe02759 2545wxWindowMac *wxWindowBase::DoFindFocus()
e9576ca5 2546{
f1d527c1
SC
2547 ControlRef control ;
2548 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2549 return wxFindControlFromMacControl( control ) ;
519cb848
SC
2550}
2551
e766c8a9 2552void wxWindowMac::OnSetFocus(wxFocusEvent& event)
7810c95b
SC
2553{
2554 // panel wants to track the window which was the last to have focus in it,
2555 // so we want to set ourselves as the window which last had focus
2556 //
2557 // notice that it's also important to do it upwards the tree becaus
2558 // otherwise when the top level panel gets focus, it won't set it back to
2559 // us, but to some other sibling
6ed71b4f 2560
c1fb8167
SC
2561 // CS:don't know if this is still needed:
2562 //wxChildFocusEvent eventFocus(this);
2563 //(void)GetEventHandler()->ProcessEvent(eventFocus);
7810c95b 2564
5ca0d812
SC
2565 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2566 {
ff3795ee 2567 #if !wxMAC_USE_CORE_GRAPHICS
788e118f 2568 wxMacWindowStateSaver sv( this ) ;
6449b3a8
SC
2569 Rect rect ;
2570 m_peer->GetRect( &rect ) ;
8f39b6c4
SC
2571