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