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