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