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