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