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