]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/window.cpp
HAVE_XIM is disabled in GTK2 build, don't include useless member variables
[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
892 MacUpdateControlFont() ;
893
894 return true ;
895}
896
897
898bool wxWindowMac::MacCanFocus() const
899{
f6e3849c
SC
900 // there is currently no way to determine whether the window is running in full keyboard
901 // access mode, therefore we cannot rely on these features, yet the only other way would be
902 // to issue a SetKeyboardFocus event and verify after whether it succeeded, this would risk problems
903 // in event handlers...
f1d527c1 904 UInt32 features = 0 ;
5ca0d812 905 m_peer->GetFeatures( & features ) ;
f1d527c1 906 return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ;
facd6764
SC
907}
908
909
e766c8a9 910void wxWindowMac::SetFocus()
e9576ca5 911{
6264b550
RR
912 if ( AcceptsFocus() )
913 {
f1d527c1
SC
914#if !TARGET_API_MAC_OSX
915 wxWindow* former = FindFocus() ;
eed1be65 916#endif
5ca0d812 917 OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ;
f1d527c1
SC
918 // as we cannot rely on the control features to find out whether we are in full keyboard mode, we can only
919 // leave in case of an error
920 if ( err == errCouldntSetFocus )
921 return ;
922
923#if !TARGET_API_MAC_OSX
924 // emulate carbon events when running under carbonlib where they are not natively available
925 if ( former )
926 {
927 EventRef evRef = NULL ;
928 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
929 &evRef ) );
930
931 wxMacCarbonEvent cEvent( evRef ) ;
932 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ;
933 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ;
934
935 wxMacWindowEventHandler( NULL , evRef , former ) ;
936 ReleaseEvent(evRef) ;
6264b550 937 }
f1d527c1 938 // send new focus event
6264b550 939 {
f1d527c1
SC
940 EventRef evRef = NULL ;
941 verify_noerr( MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent ,
942 &evRef ) );
943
944 wxMacCarbonEvent cEvent( evRef ) ;
945 cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ;
946 cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ;
947
948 wxMacWindowEventHandler( NULL , evRef , this ) ;
949 ReleaseEvent(evRef) ;
6264b550 950 }
f1d527c1 951#endif
6264b550 952 }
e9576ca5
SC
953}
954
e9576ca5 955
4116c221 956void wxWindowMac::DoCaptureMouse()
e9576ca5 957{
519cb848 958 wxTheApp->s_captureWindow = this ;
e9576ca5
SC
959}
960
90b959ae
SC
961wxWindow* wxWindowBase::GetCapture()
962{
963 return wxTheApp->s_captureWindow ;
964}
965
4116c221 966void wxWindowMac::DoReleaseMouse()
e9576ca5 967{
519cb848 968 wxTheApp->s_captureWindow = NULL ;
e9576ca5
SC
969}
970
e9576ca5
SC
971#if wxUSE_DRAG_AND_DROP
972
e766c8a9 973void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
e9576ca5 974{
e40298d5
JS
975 if ( m_dropTarget != 0 ) {
976 delete m_dropTarget;
977 }
6ed71b4f 978
e40298d5
JS
979 m_dropTarget = pDropTarget;
980 if ( m_dropTarget != 0 )
981 {
982 // TODO
983 }
e9576ca5
SC
984}
985
986#endif
987
988// Old style file-manager drag&drop
e766c8a9 989void wxWindowMac::DragAcceptFiles(bool accept)
e9576ca5
SC
990{
991 // TODO
992}
993
facd6764
SC
994void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
995 int& w, int& h) const
e9576ca5 996{
facd6764 997 Rect bounds ;
5ca0d812 998 m_peer->GetRect( &bounds ) ;
e9576ca5 999
14c9cbdb 1000
facd6764
SC
1001 x = bounds.left ;
1002 y = bounds.top ;
1003 w = bounds.right - bounds.left ;
1004 h = bounds.bottom - bounds.top ;
1005
1006 wxTopLevelWindow* tlw = wxDynamicCast( this , wxTopLevelWindow ) ;
1007 if ( tlw )
519cb848 1008 {
facd6764 1009 Point tlworigin = { 0 , 0 } ;
a9de2608 1010 QDLocalToGlobalPoint( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) , &tlworigin ) ;
facd6764
SC
1011 x = tlworigin.h ;
1012 y = tlworigin.v ;
519cb848 1013 }
e9576ca5
SC
1014}
1015
facd6764
SC
1016bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
1017 const wxSize& size,
1018 int& x, int& y,
79392158 1019 int& w, int& h , bool adjustOrigin ) const
51abe921 1020{
5ca0d812
SC
1021 // the desired size, minus the border pixels gives the correct size of the control
1022
facd6764
SC
1023 x = (int)pos.x;
1024 y = (int)pos.y;
1025 // todo the default calls may be used as soon as PostCreateControl Is moved here
1026 w = size.x ; // WidthDefault( size.x );
1027 h = size.y ; // HeightDefault( size.y ) ;
1028#if !TARGET_API_MAC_OSX
1029 GetParent()->MacWindowToRootWindow( &x , &y ) ;
1030#endif
5ca0d812
SC
1031
1032 x += MacGetLeftBorderSize() ;
1033 y += MacGetTopBorderSize() ;
1034 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1035 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1036
79392158
SC
1037 if ( adjustOrigin )
1038 AdjustForParentClientOrigin( x , y ) ;
facd6764
SC
1039 return true ;
1040}
1041
1042// Get total size
1043void wxWindowMac::DoGetSize(int *x, int *y) const
1044{
5ca0d812 1045 // take the size of the control and add the borders that have to be drawn outside
facd6764 1046 int x1 , y1 , w1 ,h1 ;
5ca0d812 1047#if TARGET_API_MAC_OSX
facd6764 1048 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
facd6764
SC
1049
1050#else
1051 Rect bounds ;
5ca0d812
SC
1052 m_peer->GetRect( &bounds ) ;
1053 w1 = bounds.right - bounds.left ;
1054 h1 = bounds.bottom - bounds.top ;
facd6764 1055#endif
5ca0d812
SC
1056 w1 += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1057 h1 += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
1058
1059 if(x) *x = w1 ;
1060 if(y) *y = h1 ;
facd6764
SC
1061}
1062
1063void wxWindowMac::DoGetPosition(int *x, int *y) const
1064{
1065 #if TARGET_API_MAC_OSX
1066 int x1 , y1 , w1 ,h1 ;
1067 MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
5ca0d812
SC
1068 x1 -= MacGetLeftBorderSize() ;
1069 y1 -= MacGetTopBorderSize() ;
facd6764 1070 if ( !IsTopLevel() )
2b5f62a0 1071 {
facd6764
SC
1072 wxWindow *parent = GetParent();
1073 if ( parent )
8950f7cc 1074 {
facd6764
SC
1075 wxPoint pt(parent->GetClientAreaOrigin());
1076 x1 -= pt.x ;
1077 y1 -= pt.y ;
6ed71b4f 1078 }
2b5f62a0 1079 }
facd6764
SC
1080 if(x) *x = x1 ;
1081 if(y) *y = y1 ;
1082 #else
1083 Rect bounds ;
5ca0d812 1084 m_peer->GetRect( &bounds ) ;
facd6764
SC
1085 wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
1086
1087 int xx = bounds.left ;
1088 int yy = bounds.top ;
5ca0d812
SC
1089 xx -= MacGetLeftBorderSize() ;
1090 yy -= MacGetTopBorderSize() ;
facd6764
SC
1091
1092 if ( !GetParent()->IsTopLevel() )
1093 {
1094 GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
1095
1096 xx -= bounds.left ;
1097 yy -= bounds.top ;
1098 }
1099
1100 wxPoint pt(GetParent()->GetClientAreaOrigin());
1101 xx -= pt.x;
1102 yy -= pt.y;
51abe921 1103
facd6764
SC
1104 if(x) *x = xx;
1105 if(y) *y = yy;
e766c8a9 1106#endif
facd6764 1107}
51abe921 1108
e766c8a9 1109void wxWindowMac::DoScreenToClient(int *x, int *y) const
e9576ca5 1110{
facd6764
SC
1111 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1112
1113 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
1114
1115 {
1116 Point localwhere = {0,0} ;
519cb848 1117
facd6764
SC
1118 if(x) localwhere.h = * x ;
1119 if(y) localwhere.v = * y ;
1120
a9de2608 1121 QDGlobalToLocalPoint( GetWindowPort( window ) , &localwhere ) ;
facd6764
SC
1122 if(x) *x = localwhere.h ;
1123 if(y) *y = localwhere.v ;
6ed71b4f 1124
facd6764 1125 }
2078220e 1126 MacRootWindowToWindow( x , y ) ;
facd6764
SC
1127
1128 wxPoint origin = GetClientAreaOrigin() ;
1129 if(x) *x -= origin.x ;
1130 if(y) *y -= origin.y ;
e9576ca5
SC
1131}
1132
e766c8a9 1133void wxWindowMac::DoClientToScreen(int *x, int *y) const
e9576ca5 1134{
facd6764
SC
1135 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1136 wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
14c9cbdb 1137
facd6764
SC
1138 wxPoint origin = GetClientAreaOrigin() ;
1139 if(x) *x += origin.x ;
1140 if(y) *y += origin.y ;
14c9cbdb 1141
2078220e 1142 MacWindowToRootWindow( x , y ) ;
14c9cbdb 1143
facd6764
SC
1144 {
1145 Point localwhere = { 0,0 };
1146 if(x) localwhere.h = * x ;
1147 if(y) localwhere.v = * y ;
a9de2608 1148 QDLocalToGlobalPoint( GetWindowPort( window ) , &localwhere ) ;
facd6764
SC
1149 if(x) *x = localwhere.h ;
1150 if(y) *y = localwhere.v ;
1151 }
519cb848
SC
1152}
1153
e766c8a9 1154void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
519cb848 1155{
1c310985
SC
1156 wxPoint origin = GetClientAreaOrigin() ;
1157 if(x) *x += origin.x ;
1158 if(y) *y += origin.y ;
14c9cbdb 1159
1c310985
SC
1160 MacWindowToRootWindow( x , y ) ;
1161}
1162
1163void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
1164{
1c310985 1165 MacRootWindowToWindow( x , y ) ;
facd6764
SC
1166
1167 wxPoint origin = GetClientAreaOrigin() ;
1c310985
SC
1168 if(x) *x -= origin.x ;
1169 if(y) *y -= origin.y ;
1170}
1171
1172void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
1173{
facd6764 1174 #if TARGET_API_MAC_OSX
5ca0d812 1175 wxPoint pt ;
facd6764
SC
1176 if ( x ) pt.x = *x ;
1177 if ( y ) pt.y = *y ;
1178
125c7984 1179 if ( !IsTopLevel() )
5437ff47
RD
1180 {
1181 wxTopLevelWindowMac* top = MacGetTopLevelWindow();
1182 if (top)
5ca0d812
SC
1183 {
1184 pt.x -= MacGetLeftBorderSize() ;
1185 pt.y -= MacGetTopBorderSize() ;
1186 wxMacControl::Convert( &pt , m_peer , top->m_peer ) ;
1187 }
5437ff47 1188 }
facd6764
SC
1189
1190 if ( x ) *x = (int) pt.x ;
1191 if ( y ) *y = (int) pt.y ;
1192 #else
1c310985 1193 if ( !IsTopLevel() )
6264b550 1194 {
facd6764 1195 Rect bounds ;
5ca0d812 1196 m_peer->GetRect( &bounds ) ;
facd6764
SC
1197 if(x) *x += bounds.left ;
1198 if(y) *y += bounds.top ;
6264b550 1199 }
facd6764
SC
1200#endif
1201}
1202
1203void wxWindowMac::MacWindowToRootWindow( short *x , short *y ) const
1204{
1205 int x1 , y1 ;
1206 if ( x ) x1 = *x ;
1207 if ( y ) y1 = *y ;
1208 MacWindowToRootWindow( &x1 , &y1 ) ;
1209 if ( x ) *x = x1 ;
1210 if ( y ) *y = y1 ;
519cb848
SC
1211}
1212
1c310985 1213void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
519cb848 1214{
facd6764 1215 #if TARGET_API_MAC_OSX
5ca0d812 1216 wxPoint pt ;
facd6764
SC
1217 if ( x ) pt.x = *x ;
1218 if ( y ) pt.y = *y ;
1219
125c7984 1220 if ( !IsTopLevel() )
5ca0d812
SC
1221 {
1222 wxMacControl::Convert( &pt , MacGetTopLevelWindow()->m_peer , m_peer ) ;
1223 pt.x += MacGetLeftBorderSize() ;
1224 pt.y += MacGetTopBorderSize() ;
1225 }
facd6764
SC
1226
1227 if ( x ) *x = (int) pt.x ;
1228 if ( y ) *y = (int) pt.y ;
1229 #else
1c310985 1230 if ( !IsTopLevel() )
6264b550 1231 {
facd6764 1232 Rect bounds ;
5ca0d812 1233 m_peer->GetRect( &bounds ) ;
facd6764
SC
1234 if(x) *x -= bounds.left ;
1235 if(y) *y -= bounds.top ;
6264b550 1236 }
facd6764 1237#endif
e9576ca5
SC
1238}
1239
facd6764 1240void wxWindowMac::MacRootWindowToWindow( short *x , short *y ) const
e9576ca5 1241{
facd6764
SC
1242 int x1 , y1 ;
1243 if ( x ) x1 = *x ;
1244 if ( y ) y1 = *y ;
1245 MacRootWindowToWindow( &x1 , &y1 ) ;
1246 if ( x ) *x = x1 ;
1247 if ( y ) *y = y1 ;
1248}
6ed71b4f 1249
29281095
SC
1250void wxWindowMac::MacGetContentAreaInset( int &left , int &top , int &right , int &bottom )
1251{
1252 RgnHandle rgn = NewRgn() ;
1253 Rect content ;
5ca0d812 1254 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
29281095
SC
1255 {
1256 GetRegionBounds( rgn , &content ) ;
1257 DisposeRgn( rgn ) ;
1258 }
1259 else
1260 {
5ca0d812 1261 m_peer->GetRect( &content ) ;
29281095
SC
1262 }
1263 Rect structure ;
5ca0d812 1264 m_peer->GetRect( &structure ) ;
29281095
SC
1265#if !TARGET_API_MAC_OSX
1266 OffsetRect( &content , -structure.left , -structure.top ) ;
1267#endif
1268 left = content.left - structure.left ;
1269 top = content.top - structure.top ;
1270 right = structure.right - content.right ;
1271 bottom = structure.bottom - content.bottom ;
1272}
1273
facd6764
SC
1274wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
1275{
1276 wxSize sizeTotal = size;
1277
1278 RgnHandle rgn = NewRgn() ;
1279
1280 Rect content ;
1281
5ca0d812 1282 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
6618870d 1283 {
facd6764
SC
1284 GetRegionBounds( rgn , &content ) ;
1285 DisposeRgn( rgn ) ;
6618870d
SC
1286 }
1287 else
1288 {
5ca0d812 1289 m_peer->GetRect( &content ) ;
e40298d5 1290 }
facd6764 1291 Rect structure ;
5ca0d812 1292 m_peer->GetRect( &structure ) ;
facd6764
SC
1293#if !TARGET_API_MAC_OSX
1294 OffsetRect( &content , -structure.left , -structure.top ) ;
1295#endif
6ed71b4f 1296
facd6764
SC
1297 sizeTotal.x += (structure.right - structure.left) - (content.right - content.left) ;
1298 sizeTotal.y += (structure.bottom - structure.top) - (content.bottom - content.top ) ;
6ed71b4f 1299
facd6764
SC
1300 sizeTotal.x += MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1301 sizeTotal.y += MacGetTopBorderSize( ) + MacGetBottomBorderSize( ) ;
6ed71b4f 1302
facd6764 1303 return sizeTotal;
e9576ca5
SC
1304}
1305
1306
1307// Get size *available for subwindows* i.e. excluding menu bar etc.
e766c8a9 1308void wxWindowMac::DoGetClientSize(int *x, int *y) const
e9576ca5 1309{
9453cf2b 1310 int ww, hh;
6ed71b4f 1311
facd6764
SC
1312 RgnHandle rgn = NewRgn() ;
1313 Rect content ;
5ca0d812 1314 if ( m_peer->GetRegion( kControlContentMetaPart , rgn ) == noErr )
facd6764
SC
1315 {
1316 GetRegionBounds( rgn , &content ) ;
1317 DisposeRgn( rgn ) ;
1318 }
1319 else
1320 {
5ca0d812 1321 m_peer->GetRect( &content ) ;
facd6764
SC
1322 }
1323#if !TARGET_API_MAC_OSX
1324 Rect structure ;
5ca0d812 1325 m_peer->GetRect( &structure ) ;
facd6764
SC
1326 OffsetRect( &content , -structure.left , -structure.top ) ;
1327#endif
1328 ww = content.right - content.left ;
1329 hh = content.bottom - content.top ;
1330
6264b550
RR
1331 ww -= MacGetLeftBorderSize( ) + MacGetRightBorderSize( ) ;
1332 hh -= MacGetTopBorderSize( ) + MacGetBottomBorderSize( );
6ed71b4f 1333
e40298d5
JS
1334 if ( (m_vScrollBar && m_vScrollBar->IsShown()) || (m_hScrollBar && m_hScrollBar->IsShown()) )
1335 {
1336 int x1 = 0 ;
1337 int y1 = 0 ;
facd6764
SC
1338 int w ;
1339 int h ;
1340 GetSize( &w , &h ) ;
1341
e40298d5
JS
1342 MacClientToRootWindow( &x1 , &y1 ) ;
1343 MacClientToRootWindow( &w , &h ) ;
6ed71b4f 1344
e40298d5 1345 wxWindowMac *iter = (wxWindowMac*)this ;
6ed71b4f 1346
e40298d5
JS
1347 int totW = 10000 , totH = 10000;
1348 while( iter )
6264b550 1349 {
e40298d5
JS
1350 if ( iter->IsTopLevel() )
1351 {
facd6764 1352 iter->GetSize( &totW , &totH ) ;
e40298d5
JS
1353 break ;
1354 }
6ed71b4f 1355
e40298d5 1356 iter = iter->GetParent() ;
6264b550 1357 }
6ed71b4f 1358
e40298d5 1359 if (m_hScrollBar && m_hScrollBar->IsShown() )
6264b550 1360 {
e40298d5
JS
1361 hh -= MAC_SCROLLBAR_SIZE;
1362 if ( h-y1 >= totH )
1363 {
1364 hh += 1 ;
1365 }
6264b550 1366 }
e40298d5 1367 if (m_vScrollBar && m_vScrollBar->IsShown() )
6264b550 1368 {
e40298d5
JS
1369 ww -= MAC_SCROLLBAR_SIZE;
1370 if ( w-x1 >= totW )
1371 {
1372 ww += 1 ;
1373 }
6264b550
RR
1374 }
1375 }
e40298d5
JS
1376 if(x) *x = ww;
1377 if(y) *y = hh;
facd6764
SC
1378
1379}
1380
1381bool wxWindowMac::SetCursor(const wxCursor& cursor)
1382{
1383 if (m_cursor == cursor)
1384 return FALSE;
1385
1386 if (wxNullCursor == cursor)
1387 {
1388 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
1389 return FALSE ;
1390 }
1391 else
1392 {
1393 if ( ! wxWindowBase::SetCursor( cursor ) )
1394 return FALSE ;
1395 }
1396
1397 wxASSERT_MSG( m_cursor.Ok(),
1398 wxT("cursor must be valid after call to the base version"));
facd6764 1399
facd6764 1400
2d1760d3 1401 wxWindowMac *mouseWin = 0 ;
facd6764 1402 {
2d1760d3
SC
1403 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1404 CGrafPtr savePort ;
1405 Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1406
1407 // TODO If we ever get a GetCurrentEvent.. replacement for the mouse
1408 // position, use it...
1409
1410 Point pt ;
1411 GetMouse( &pt ) ;
1412 ControlPartCode part ;
1413 ControlRef control ;
1414 control = wxMacFindControlUnderMouse( pt , window , &part ) ;
1415 if ( control )
1416 mouseWin = wxFindControlFromMacControl( control ) ;
1417
1418 if ( swapped )
1419 QDSwapPort( savePort , NULL ) ;
facd6764 1420 }
2d1760d3
SC
1421
1422 if ( mouseWin == this && !wxIsBusy() )
facd6764
SC
1423 {
1424 m_cursor.MacInstall() ;
1425 }
1426
1427 return TRUE ;
519cb848
SC
1428}
1429
facd6764
SC
1430#if wxUSE_MENUS
1431bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1432{
1433 menu->SetInvokingWindow(this);
1434 menu->UpdateUI();
971562cb
VS
1435
1436 if ( x == -1 && y == -1 )
1437 {
1438 wxPoint mouse = wxGetMousePosition();
1439 x = mouse.x; y = mouse.y;
1440 }
1441 else
1442 {
1443 ClientToScreen( &x , &y ) ;
1444 }
facd6764
SC
1445
1446 menu->MacBeforeDisplay( true ) ;
1447 long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
1448 if ( HiWord(menuResult) != 0 )
1449 {
1450 MenuCommand id ;
1451 GetMenuItemCommandID( GetMenuHandle(HiWord(menuResult)) , LoWord(menuResult) , &id ) ;
1452 wxMenuItem* item = NULL ;
1453 wxMenu* realmenu ;
1454 item = menu->FindItem(id, &realmenu) ;
1455 if (item->IsCheckable())
1456 {
1457 item->Check( !item->IsChecked() ) ;
1458 }
1459 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
1460 }
1461 menu->MacAfterDisplay( true ) ;
1462
1463 menu->SetInvokingWindow(NULL);
1464
1465 return TRUE;
1466}
1467#endif
51abe921
SC
1468
1469// ----------------------------------------------------------------------------
1470// tooltips
1471// ----------------------------------------------------------------------------
1472
1473#if wxUSE_TOOLTIPS
1474
e766c8a9 1475void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
51abe921
SC
1476{
1477 wxWindowBase::DoSetToolTip(tooltip);
6ed71b4f 1478
6264b550
RR
1479 if ( m_tooltip )
1480 m_tooltip->SetWindow(this);
51abe921
SC
1481}
1482
1483#endif // wxUSE_TOOLTIPS
1484
e766c8a9 1485void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
51abe921 1486{
facd6764
SC
1487 int former_x , former_y , former_w, former_h ;
1488#if !TARGET_API_MAC_OSX
1489 DoGetPosition( &former_x , &former_y ) ;
1490 DoGetSize( &former_w , &former_h ) ;
1491#else
1492 MacGetPositionAndSizeFromControl( former_x , former_y , former_w , former_h ) ;
5ca0d812
SC
1493 former_x -= MacGetLeftBorderSize() ;
1494 former_y -= MacGetTopBorderSize() ;
1495 former_w += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
1496 former_h += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
facd6764 1497#endif
6ed71b4f 1498
e40298d5
JS
1499 int actualWidth = width;
1500 int actualHeight = height;
1501 int actualX = x;
1502 int actualY = y;
6ed71b4f 1503
14c9cbdb 1504 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
6264b550 1505 actualWidth = m_minWidth;
14c9cbdb 1506 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
6264b550 1507 actualHeight = m_minHeight;
14c9cbdb 1508 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
6264b550 1509 actualWidth = m_maxWidth;
14c9cbdb 1510 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
6264b550 1511 actualHeight = m_maxHeight;
6ed71b4f 1512
6264b550
RR
1513 bool doMove = false ;
1514 bool doResize = false ;
6ed71b4f 1515
6264b550
RR
1516 if ( actualX != former_x || actualY != former_y )
1517 {
1518 doMove = true ;
1519 }
1520 if ( actualWidth != former_w || actualHeight != former_h )
1521 {
1522 doResize = true ;
1523 }
6ed71b4f 1524
6264b550
RR
1525 if ( doMove || doResize )
1526 {
79392158
SC
1527 // we don't adjust twice for the origin
1528 Rect r = wxMacGetBoundsForControl(this , wxPoint( actualX,actualY), wxSize( actualWidth, actualHeight ) , false ) ;
5ca0d812
SC
1529 bool vis = m_peer->IsVisible();
1530
b05bf6ee
SC
1531 // the HIViewSetFrame call itself should invalidate the areas, but when testing with the UnicodeTextCtrl it does not !
1532 if ( vis )
5ca0d812
SC
1533 m_peer->SetVisibility( false , true ) ;
1534 m_peer->SetRect( &r ) ;
b05bf6ee 1535 if ( vis )
5ca0d812
SC
1536 m_peer->SetVisibility( true , true ) ;
1537
6264b550
RR
1538 MacRepositionScrollBars() ;
1539 if ( doMove )
1540 {
facd6764 1541 wxPoint point(actualX,actualY);
6264b550
RR
1542 wxMoveEvent event(point, m_windowId);
1543 event.SetEventObject(this);
1544 GetEventHandler()->ProcessEvent(event) ;
1545 }
1546 if ( doResize )
1547 {
e40298d5 1548 MacRepositionScrollBars() ;
facd6764 1549 wxSize size(actualWidth, actualHeight);
e40298d5
JS
1550 wxSizeEvent event(size, m_windowId);
1551 event.SetEventObject(this);
1552 GetEventHandler()->ProcessEvent(event);
6264b550
RR
1553 }
1554 }
6ed71b4f 1555
954fc50b
SC
1556}
1557
facd6764
SC
1558wxSize wxWindowMac::DoGetBestSize() const
1559{
eb69d46e
SC
1560 if ( m_macIsUserPane || IsTopLevel() )
1561 return wxWindowBase::DoGetBestSize() ;
1562
facd6764 1563 Rect bestsize = { 0 , 0 , 0 , 0 } ;
facd6764 1564 int bestWidth, bestHeight ;
5ca0d812 1565 m_peer->GetBestRect( &bestsize ) ;
facd6764
SC
1566
1567 if ( EmptyRect( &bestsize ) )
1568 {
facd6764
SC
1569 bestsize.left = bestsize.top = 0 ;
1570 bestsize.right = 16 ;
1571 bestsize.bottom = 16 ;
1572 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
1573 {
1574 bestsize.bottom = 16 ;
1575 }
1576 else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
1577 {
1578 bestsize.bottom = 24 ;
1579 }
1580 else
1581 {
1582 // return wxWindowBase::DoGetBestSize() ;
1583 }
1584 }
1585
1586 bestWidth = bestsize.right - bestsize.left ;
1587 bestHeight = bestsize.bottom - bestsize.top ;
1588 if ( bestHeight < 10 )
1589 bestHeight = 13 ;
1590
1591 return wxSize(bestWidth, bestHeight);
1592}
1593
1594
954fc50b
SC
1595// set the size of the window: if the dimensions are positive, just use them,
1596// but if any of them is equal to -1, it means that we must find the value for
1597// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1598// which case -1 is a valid value for x and y)
1599//
1600// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1601// the width/height to best suit our contents, otherwise we reuse the current
1602// width/height
1603void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1604{
1605 // get the current size and position...
1606 int currentX, currentY;
1607 GetPosition(&currentX, &currentY);
6ed71b4f 1608
954fc50b
SC
1609 int currentW,currentH;
1610 GetSize(&currentW, &currentH);
6ed71b4f 1611
954fc50b
SC
1612 // ... and don't do anything (avoiding flicker) if it's already ok
1613 if ( x == currentX && y == currentY &&
769ac869 1614 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
954fc50b 1615 {
facd6764 1616 // TODO REMOVE
6264b550 1617 MacRepositionScrollBars() ; // we might have a real position shift
954fc50b
SC
1618 return;
1619 }
6ed71b4f 1620
954fc50b
SC
1621 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1622 x = currentX;
1623 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1624 y = currentY;
6ed71b4f 1625
954fc50b 1626 AdjustForParentClientOrigin(x, y, sizeFlags);
6ed71b4f 1627
954fc50b
SC
1628 wxSize size(-1, -1);
1629 if ( width == -1 )
1630 {
1631 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1632 {
1633 size = DoGetBestSize();
1634 width = size.x;
1635 }
1636 else
1637 {
1638 // just take the current one
1639 width = currentW;
1640 }
1641 }
6ed71b4f 1642
954fc50b
SC
1643 if ( height == -1 )
1644 {
1645 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1646 {
1647 if ( size.x == -1 )
1648 {
1649 size = DoGetBestSize();
1650 }
1651 //else: already called DoGetBestSize() above
6ed71b4f 1652
954fc50b
SC
1653 height = size.y;
1654 }
1655 else
1656 {
1657 // just take the current one
1658 height = currentH;
1659 }
1660 }
6ed71b4f 1661
954fc50b 1662 DoMoveWindow(x, y, width, height);
6ed71b4f 1663
e9576ca5 1664}
519cb848 1665
e766c8a9 1666wxPoint wxWindowMac::GetClientAreaOrigin() const
e9576ca5 1667{
facd6764
SC
1668 RgnHandle rgn = NewRgn() ;
1669 Rect content ;
5ca0d812 1670 m_peer->GetRegion( kControlContentMetaPart , rgn ) ;
facd6764
SC
1671 GetRegionBounds( rgn , &content ) ;
1672 DisposeRgn( rgn ) ;
1673#if !TARGET_API_MAC_OSX
736fac3a
SC
1674 // if the content rgn is empty / not supported
1675 // don't attempt to correct the coordinates to wxWindow relative ones
1676 if (!::EmptyRect( &content ) )
1677 {
1678 Rect structure ;
5ca0d812 1679 m_peer->GetRect( &structure ) ;
736fac3a
SC
1680 OffsetRect( &content , -structure.left , -structure.top ) ;
1681 }
facd6764
SC
1682#endif
1683
1684 return wxPoint( content.left + MacGetLeftBorderSize( ) , content.top + MacGetTopBorderSize( ) );
1685}
1686
1687void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1688{
1689 if ( clientheight != -1 || clientheight != -1 )
1690 {
1691 int currentclientwidth , currentclientheight ;
1692 int currentwidth , currentheight ;
1693
1694 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1695 GetSize( &currentwidth , &currentheight ) ;
1696
1697 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
1698 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1699 }
e9576ca5
SC
1700}
1701
d84afea9 1702void wxWindowMac::SetTitle(const wxString& title)
e9576ca5 1703{
facd6764
SC
1704 m_label = wxStripMenuCodes(title) ;
1705
21fd5529 1706 if ( m_peer && m_peer->Ok() )
facd6764 1707 {
5ca0d812 1708 m_peer->SetTitle( m_label ) ;
facd6764
SC
1709 }
1710 Refresh() ;
519cb848
SC
1711}
1712
d84afea9 1713wxString wxWindowMac::GetTitle() const
519cb848 1714{
ed60b502 1715 return m_label ;
519cb848
SC
1716}
1717
8ab50549
SC
1718bool wxWindowMac::Show(bool show)
1719{
1720 if ( !wxWindowBase::Show(show) )
1721 return FALSE;
1722
1723 // TODO use visibilityChanged Carbon Event for OSX
1724 bool former = MacIsReallyShown() ;
1725
5ca0d812 1726 m_peer->SetVisibility( show , true ) ;
8ab50549
SC
1727 if ( former != MacIsReallyShown() )
1728 MacPropagateVisibilityChanged() ;
1729 return TRUE;
1730}
1731
1732bool wxWindowMac::Enable(bool enable)
1733{
21fd5529 1734 wxASSERT( m_peer->Ok() ) ;
8ab50549
SC
1735 if ( !wxWindowBase::Enable(enable) )
1736 return FALSE;
1737
1738 bool former = MacIsReallyEnabled() ;
5ca0d812 1739 m_peer->Enable( enable ) ;
8ab50549
SC
1740
1741 if ( former != MacIsReallyEnabled() )
1742 MacPropagateEnabledStateChanged() ;
1743 return TRUE;
1744}
1745
1746//
1747// status change propagations (will be not necessary for OSX later )
1748//
1749
facd6764
SC
1750void wxWindowMac::MacPropagateVisibilityChanged()
1751{
73fe67bd 1752#if !TARGET_API_MAC_OSX
facd6764
SC
1753 MacVisibilityChanged() ;
1754
1755 wxWindowListNode *node = GetChildren().GetFirst();
1756 while ( node )
1757 {
1758 wxWindowMac *child = node->GetData();
1759 if ( child->IsShown() )
1760 child->MacPropagateVisibilityChanged( ) ;
1761 node = node->GetNext();
1762 }
73fe67bd 1763#endif
facd6764
SC
1764}
1765
8ab50549 1766void wxWindowMac::MacPropagateEnabledStateChanged( )
e9576ca5 1767{
73fe67bd 1768#if !TARGET_API_MAC_OSX
8ab50549 1769 MacEnabledStateChanged() ;
facd6764 1770
8ab50549
SC
1771 wxWindowListNode *node = GetChildren().GetFirst();
1772 while ( node )
1773 {
1774 wxWindowMac *child = node->GetData();
1775 if ( child->IsEnabled() )
1776 child->MacPropagateEnabledStateChanged() ;
1777 node = node->GetNext();
1778 }
73fe67bd 1779#endif
8ab50549
SC
1780}
1781
1782void wxWindowMac::MacPropagateHiliteChanged( )
1783{
73fe67bd 1784#if !TARGET_API_MAC_OSX
8ab50549 1785 MacHiliteChanged() ;
facd6764 1786
8ab50549
SC
1787 wxWindowListNode *node = GetChildren().GetFirst();
1788 while ( node )
1789 {
1790 wxWindowMac *child = node->GetData();
1791 // if ( child->IsEnabled() )
1792 child->MacPropagateHiliteChanged() ;
1793 node = node->GetNext();
1794 }
73fe67bd 1795#endif
8ab50549
SC
1796}
1797
1798//
1799// status change notifications
1800//
1801
1802void wxWindowMac::MacVisibilityChanged()
1803{
1804}
1805
1806void wxWindowMac::MacHiliteChanged()
1807{
1808}
1809
1810void wxWindowMac::MacEnabledStateChanged()
1811{
facd6764 1812}
e7549107 1813
8ab50549
SC
1814//
1815// status queries on the inherited window's state
1816//
1817
facd6764
SC
1818bool wxWindowMac::MacIsReallyShown()
1819{
1820 // only under OSX the visibility of the TLW is taken into account
1821#if TARGET_API_MAC_OSX
aa522e33
SC
1822 if ( m_peer && m_peer->Ok() )
1823 return m_peer->IsVisible();
1824#endif
facd6764
SC
1825 wxWindow* win = this ;
1826 while( win->IsShown() )
1827 {
1828 if ( win->IsTopLevel() )
1829 return true ;
1830
1831 win = win->GetParent() ;
1832 if ( win == NULL )
1833 return true ;
1834
1835 } ;
1836 return false ;
facd6764 1837}
4241baae 1838
facd6764
SC
1839bool wxWindowMac::MacIsReallyEnabled()
1840{
5ca0d812 1841 return m_peer->IsEnabled() ;
facd6764
SC
1842}
1843
8ab50549 1844bool wxWindowMac::MacIsReallyHilited()
c809f3be 1845{
5ca0d812 1846 return m_peer->IsActive();
c809f3be
SC
1847}
1848
002c9672
SC
1849void wxWindowMac::MacFlashInvalidAreas()
1850{
1851#if TARGET_API_MAC_OSX
1852 HIViewFlashDirtyArea( (WindowRef) MacGetTopLevelWindowRef() ) ;
1853#endif
1854}
1855
8ab50549
SC
1856//
1857//
1858//
1859
e766c8a9 1860int wxWindowMac::GetCharHeight() const
e9576ca5 1861{
6264b550
RR
1862 wxClientDC dc ( (wxWindowMac*)this ) ;
1863 return dc.GetCharHeight() ;
e9576ca5
SC
1864}
1865
e766c8a9 1866int wxWindowMac::GetCharWidth() const
e9576ca5 1867{
6264b550
RR
1868 wxClientDC dc ( (wxWindowMac*)this ) ;
1869 return dc.GetCharWidth() ;
e9576ca5
SC
1870}
1871
e766c8a9 1872void wxWindowMac::GetTextExtent(const wxString& string, int *x, int *y,
e7549107 1873 int *descent, int *externalLeading, const wxFont *theFont ) const
e9576ca5 1874{
e7549107
SC
1875 const wxFont *fontToUse = theFont;
1876 if ( !fontToUse )
1877 fontToUse = &m_font;
14c9cbdb 1878
e766c8a9 1879 wxClientDC dc( (wxWindowMac*) this ) ;
7c74e7fe 1880 long lx,ly,ld,le ;
5fde6fcc 1881 dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2f1ae414 1882 if ( externalLeading )
6264b550 1883 *externalLeading = le ;
2f1ae414 1884 if ( descent )
6264b550 1885 *descent = ld ;
2f1ae414 1886 if ( x )
6264b550 1887 *x = lx ;
2f1ae414 1888 if ( y )
6264b550 1889 *y = ly ;
e9576ca5
SC
1890}
1891
0a67a93b 1892/*
14c9cbdb 1893 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1c310985
SC
1894 * we always intersect with the entire window, not only with the client area
1895 */
14c9cbdb 1896
e766c8a9 1897void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
e9576ca5 1898{
facd6764 1899#if TARGET_API_MAC_OSX
1e8cde71 1900 if ( rect == NULL )
5ca0d812 1901 m_peer->SetNeedsDisplay( true ) ;
1e8cde71
SC
1902 else
1903 {
1904 RgnHandle update = NewRgn() ;
1905 SetRectRgn( update , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
84f6927e
SC
1906 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , update , update ) ;
1907 wxPoint origin = GetClientAreaOrigin() ;
5ca0d812
SC
1908 OffsetRgn( update, origin.x , origin.y ) ;
1909 m_peer->SetNeedsDisplay( true , update) ;
1e8cde71 1910 }
facd6764 1911#else
a9825a9b
SC
1912/*
1913 RgnHandle updateRgn = NewRgn() ;
1914 if ( rect == NULL )
1915 {
1916 CopyRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn ) ;
1917 }
1918 else
1919 {
1920 SetRectRgn( updateRgn , rect->x , rect->y , rect->x + rect->width , rect->y + rect->height ) ;
1921 SectRgn( (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , updateRgn , updateRgn ) ;
1922 }
1923 InvalWindowRgn( (WindowRef) MacGetTopLevelWindowRef() , updateRgn ) ;
1924 DisposeRgn(updateRgn) ;
1925*/
5ca0d812 1926 if ( m_peer->IsVisible())
facd6764 1927 {
5ca0d812
SC
1928 m_peer->SetVisibility( false , false ) ;
1929 m_peer->SetVisibility( true , true ) ;
facd6764
SC
1930 }
1931 /*
94abc21f 1932 if ( MacGetTopLevelWindow() == NULL )
9a456218 1933 return ;
14c9cbdb 1934
5ca0d812 1935 if ( !m_peer->IsVisible())
c3a05e8a
SC
1936 return ;
1937
1938 wxPoint client = GetClientAreaOrigin();
9a456218
RR
1939 int x1 = -client.x;
1940 int y1 = -client.y;
1941 int x2 = m_width - client.x;
1942 int y2 = m_height - client.y;
1943
1944 if (IsKindOf( CLASSINFO(wxButton)))
1945 {
1946 // buttons have an "aura"
1947 y1 -= 5;
1948 x1 -= 5;
1949 y2 += 5;
1950 x2 += 5;
1951 }
1952
1953 Rect clientrect = { y1, x1, y2, x2 };
14c9cbdb 1954
1c310985 1955 if ( rect )
6264b550 1956 {
1c310985 1957 Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
14c9cbdb 1958 SectRect( &clientrect , &r , &clientrect ) ;
6264b550 1959 }
14c9cbdb 1960
1c310985 1961 if ( !EmptyRect( &clientrect ) )
e9576ca5 1962 {
1c310985 1963 int top = 0 , left = 0 ;
14c9cbdb 1964
1c310985
SC
1965 MacClientToRootWindow( &left , &top ) ;
1966 OffsetRect( &clientrect , left , top ) ;
14c9cbdb 1967
1c310985 1968 MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
e9576ca5 1969 }
facd6764
SC
1970 */
1971#endif
1972}
1973
79392158
SC
1974void wxWindowMac::Freeze()
1975{
1976#if TARGET_API_MAC_OSX
1977 if ( !m_frozenness++ )
1978 {
5ca0d812 1979 m_peer->SetDrawingEnabled( false ) ;
79392158
SC
1980 }
1981#endif
1982}
1983
b175b96b 1984
79392158
SC
1985void wxWindowMac::Thaw()
1986{
1987#if TARGET_API_MAC_OSX
1988 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
1989
1990 if ( !--m_frozenness )
1991 {
5ca0d812
SC
1992 m_peer->SetDrawingEnabled( true ) ;
1993 m_peer->InvalidateWithChildren() ;
79392158
SC
1994 }
1995#endif
1996}
1997
facd6764
SC
1998void wxWindowMac::MacRedrawControl()
1999{
2000/*
5ca0d812 2001 if ( *m_peer && MacGetTopLevelWindowRef() && m_peer->IsVisible())
facd6764
SC
2002 {
2003#if TARGET_API_MAC_CARBON
2004 Update() ;
2005#else
2006 wxClientDC dc(this) ;
2007 wxMacPortSetter helper(&dc) ;
2008 wxMacWindowClipper clipper(this) ;
2009 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
21fd5529 2010 UMADrawControl( *m_peer ) ;
facd6764
SC
2011#endif
2012 }
2013*/
2014}
2015
2016/* TODO
2017void wxWindowMac::OnPaint(wxPaintEvent& event)
2018{
2019 // why don't we skip that here ?
e9576ca5 2020}
facd6764 2021*/
e9576ca5 2022
e766c8a9 2023wxWindowMac *wxGetActiveWindow()
e9576ca5 2024{
519cb848 2025 // actually this is a windows-only concept
e9576ca5
SC
2026 return NULL;
2027}
2028
e9576ca5 2029// Coordinates relative to the window
e766c8a9 2030void wxWindowMac::WarpPointer (int x_pos, int y_pos)
e9576ca5 2031{
e40298d5 2032 // We really don't move the mouse programmatically under Mac.
e9576ca5
SC
2033}
2034
facd6764 2035void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
e9576ca5 2036{
be346c26 2037#if TARGET_API_MAC_OSX
facd6764 2038 if ( m_macBackgroundBrush.Ok() == false || m_macBackgroundBrush.GetStyle() == wxTRANSPARENT )
94abc21f 2039 {
facd6764 2040 event.Skip() ;
94abc21f
SC
2041 }
2042 else
be346c26 2043#endif
facd6764 2044 event.GetDC()->Clear() ;
1c310985
SC
2045}
2046
2047void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
2048{
de043984
SC
2049 wxWindowDC dc(this) ;
2050 wxMacPortSetter helper(&dc) ;
14c9cbdb 2051
76a5e5d2 2052 MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
e9576ca5
SC
2053}
2054
e766c8a9 2055int wxWindowMac::GetScrollPos(int orient) const
e9576ca5 2056{
1c310985
SC
2057 if ( orient == wxHORIZONTAL )
2058 {
2059 if ( m_hScrollBar )
2060 return m_hScrollBar->GetThumbPosition() ;
2061 }
2062 else
2063 {
2064 if ( m_vScrollBar )
2065 return m_vScrollBar->GetThumbPosition() ;
2066 }
e9576ca5
SC
2067 return 0;
2068}
2069
2070// This now returns the whole range, not just the number
2071// of positions that we can scroll.
e766c8a9 2072int wxWindowMac::GetScrollRange(int orient) const
e9576ca5 2073{
1c310985
SC
2074 if ( orient == wxHORIZONTAL )
2075 {
2076 if ( m_hScrollBar )
2077 return m_hScrollBar->GetRange() ;
2078 }
2079 else
2080 {
2081 if ( m_vScrollBar )
2082 return m_vScrollBar->GetRange() ;
2083 }
e9576ca5
SC
2084 return 0;
2085}
2086
e766c8a9 2087int wxWindowMac::GetScrollThumb(int orient) const
e9576ca5 2088{
1c310985
SC
2089 if ( orient == wxHORIZONTAL )
2090 {
2091 if ( m_hScrollBar )
2092 return m_hScrollBar->GetThumbSize() ;
2093 }
2094 else
2095 {
2096 if ( m_vScrollBar )
2097 return m_vScrollBar->GetThumbSize() ;
2098 }
e9576ca5
SC
2099 return 0;
2100}
2101
e766c8a9 2102void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
e9576ca5 2103{
1c310985 2104 if ( orient == wxHORIZONTAL )
6264b550 2105 {
1c310985
SC
2106 if ( m_hScrollBar )
2107 m_hScrollBar->SetThumbPosition( pos ) ;
6264b550
RR
2108 }
2109 else
2110 {
1c310985
SC
2111 if ( m_vScrollBar )
2112 m_vScrollBar->SetThumbPosition( pos ) ;
6264b550 2113 }
2f1ae414
SC
2114}
2115
14c9cbdb 2116void wxWindowMac::MacPaintBorders( int left , int top )
2f1ae414 2117{
1c310985 2118 if( IsTopLevel() )
6264b550 2119 return ;
11d1adbf
SC
2120
2121 int major,minor;
2122 wxGetOsVersion( &major, &minor );
14c9cbdb 2123
11d1adbf
SC
2124 RGBColor darkShadow = { 0x0000, 0x0000 , 0x0000 } ;
2125 RGBColor lightShadow = { 0x4444, 0x4444 , 0x4444 } ;
2126 // OS X has lighter border edges than classic:
2127 if (major >= 10)
2128 {
2129 darkShadow.red = 0x8E8E;
2130 darkShadow.green = 0x8E8E;
2131 darkShadow.blue = 0x8E8E;
2132 lightShadow.red = 0xBDBD;
2133 lightShadow.green = 0xBDBD;
2134 lightShadow.blue = 0xBDBD;
2135 }
2136
6264b550 2137 PenNormal() ;
2f1ae414 2138
facd6764
SC
2139 int w , h ;
2140 GetSize( &w , &h ) ;
5ca0d812 2141 Rect rect = { top , left , h + top , w + left } ;
2f1ae414
SC
2142 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
2143 {
1c310985 2144#if wxMAC_USE_THEME_BORDER
11d1adbf 2145 SInt32 border = 0 ;
5ca0d812 2146 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
11d1adbf 2147 InsetRect( &rect , border , border );
5ca0d812 2148 DrawThemeEditTextFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
1c310985 2149#else
6ea4a266
VZ
2150 RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
2151 RGBColor face = { 0xDDDD, 0xDDDD , 0xDDDD } ;
2152
ed60b502 2153 bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
653b2449 2154 RGBForeColor( &face );
facd6764 2155 MoveTo( left + 0 , top + h - 2 );
7d9d1fd7 2156 LineTo( left + 0 , top + 0 );
facd6764 2157 LineTo( left + w - 2 , top + 0 );
653b2449 2158
facd6764
SC
2159 MoveTo( left + 2 , top + h - 3 );
2160 LineTo( left + w - 3 , top + h - 3 );
2161 LineTo( left + w - 3 , top + 2 );
653b2449 2162
11d1adbf 2163 RGBForeColor( sunken ? &face : &darkShadow );
facd6764
SC
2164 MoveTo( left + 0 , top + h - 1 );
2165 LineTo( left + w - 1 , top + h - 1 );
2166 LineTo( left + w - 1 , top + 0 );
653b2449 2167
11d1adbf 2168 RGBForeColor( sunken ? &lightShadow : &white );
facd6764 2169 MoveTo( left + 1 , top + h - 3 );
7d9d1fd7 2170 LineTo( left + 1, top + 1 );
facd6764 2171 LineTo( left + w - 3 , top + 1 );
653b2449 2172
11d1adbf 2173 RGBForeColor( sunken ? &white : &lightShadow );
facd6764
SC
2174 MoveTo( left + 1 , top + h - 2 );
2175 LineTo( left + w - 2 , top + h - 2 );
2176 LineTo( left + w - 2 , top + 1 );
653b2449 2177
11d1adbf 2178 RGBForeColor( sunken ? &darkShadow : &face );
facd6764 2179 MoveTo( left + 2 , top + h - 4 );
7d9d1fd7 2180 LineTo( left + 2 , top + 2 );
facd6764 2181 LineTo( left + w - 4 , top + 2 );
1c310985 2182#endif
8208e181
SC
2183 }
2184 else if (HasFlag(wxSIMPLE_BORDER))
2185 {
facd6764 2186 Rect rect = { top , left , h + top , w + left } ;
11d1adbf 2187 RGBForeColor( &darkShadow ) ;
6264b550 2188 FrameRect( &rect ) ;
2f1ae414 2189 }
8208e181
SC
2190}
2191
abda5788
SC
2192void wxWindowMac::RemoveChild( wxWindowBase *child )
2193{
2194 if ( child == m_hScrollBar )
2195 m_hScrollBar = NULL ;
2196 if ( child == m_vScrollBar )
2197 m_vScrollBar = NULL ;
14c9cbdb 2198
abda5788
SC
2199 wxWindowBase::RemoveChild( child ) ;
2200}
2201
e9576ca5 2202// New function that will replace some of the above.
e766c8a9 2203void wxWindowMac::SetScrollbar(int orient, int pos, int thumbVisible,
e9576ca5
SC
2204 int range, bool refresh)
2205{
e40298d5
JS
2206 if ( orient == wxHORIZONTAL )
2207 {
2208 if ( m_hScrollBar )
6264b550 2209 {
e40298d5 2210 if ( range == 0 || thumbVisible >= range )
6264b550 2211 {
e40298d5
JS
2212 if ( m_hScrollBar->IsShown() )
2213 m_hScrollBar->Show(false) ;
2214 }
2215 else
2216 {
2217 if ( !m_hScrollBar->IsShown() )
2218 m_hScrollBar->Show(true) ;
2219 m_hScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
6264b550
RR
2220 }
2221 }
e40298d5
JS
2222 }
2223 else
2224 {
2225 if ( m_vScrollBar )
6264b550 2226 {
e40298d5 2227 if ( range == 0 || thumbVisible >= range )
6264b550 2228 {
e40298d5
JS
2229 if ( m_vScrollBar->IsShown() )
2230 m_vScrollBar->Show(false) ;
2231 }
2232 else
2233 {
2234 if ( !m_vScrollBar->IsShown() )
2235 m_vScrollBar->Show(true) ;
2236 m_vScrollBar->SetScrollbar( pos , thumbVisible , range , thumbVisible , refresh ) ;
6264b550
RR
2237 }
2238 }
e40298d5
JS
2239 }
2240 MacRepositionScrollBars() ;
e9576ca5
SC
2241}
2242
2243// Does a physical scroll
e766c8a9 2244void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
e9576ca5 2245{
ba87f54c
SC
2246 if( dx == 0 && dy ==0 )
2247 return ;
2248
6ed71b4f 2249
6264b550 2250 {
adb8a71b 2251
6264b550
RR
2252 int width , height ;
2253 GetClientSize( &width , &height ) ;
adb8a71b 2254#if TARGET_API_MAC_OSX
002c9672
SC
2255 // note there currently is a bug in OSX which makes inefficient refreshes in case an entire control
2256 // area is scrolled, this does not occur if width and height are 2 pixels less,
2257 // TODO write optimal workaround
5ca0d812 2258 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , MacGetLeftBorderSize() + width , MacGetTopBorderSize() + height ) ;
adb8a71b
SC
2259 if ( rect )
2260 {
5ca0d812 2261 scrollrect.Intersect( *rect ) ;
adb8a71b 2262 }
5ca0d812 2263 if ( m_peer->GetNeedsDisplay() )
002c9672
SC
2264 {
2265 // becuase HIViewScrollRect does not scroll the already invalidated area we have two options
2266 // either immediate redraw or full invalidate
2267#if 1
2268 // is the better overall solution, as it does not slow down scrolling
5ca0d812 2269 m_peer->SetNeedsDisplay( true ) ;
002c9672
SC
2270#else
2271 // this would be the preferred version for fast drawing controls
2272 if( UMAGetSystemVersion() < 0x1030 )
2273 Update() ;
2274 else
21fd5529 2275 HIViewRender(*m_peer) ;
002c9672
SC
2276#endif
2277 }
5ca0d812 2278 m_peer->ScrollRect( scrollrect , dx , dy ) ;
adb8a71b 2279#else
6ed71b4f 2280
facd6764
SC
2281 wxPoint pos;
2282 pos.x = pos.y = 0;
430e1eed 2283
facd6764 2284 Rect scrollrect;
6264b550 2285 RgnHandle updateRgn = NewRgn() ;
430e1eed 2286
adb8a71b 2287 {
430e1eed
SC
2288 wxClientDC dc(this) ;
2289 wxMacPortSetter helper(&dc) ;
2290
5ca0d812 2291 m_peer->GetRect( &scrollrect ) ;
430e1eed
SC
2292 scrollrect.top += MacGetTopBorderSize() ;
2293 scrollrect.left += MacGetLeftBorderSize() ;
2294 scrollrect.bottom = scrollrect.top + height ;
2295 scrollrect.right = scrollrect.left + width ;
2296
2297 if ( rect )
2298 {
2299 Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
2300 dc.XLOG2DEVMAC(rect->x + rect->width) } ;
2301 SectRect( &scrollrect , &r , &scrollrect ) ;
2302 }
2303 ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
ba87f54c 2304 }
430e1eed 2305 // ScrollWindowRect( (WindowRef) MacGetTopLevelWindowRef() , &scrollrect , dx , dy , kScrollWindowInvalidate, updateRgn ) ;
facd6764 2306#endif
6264b550 2307 }
6ed71b4f 2308
eb22f2a6 2309 for (wxWindowListNode *node = GetChildren().GetFirst(); node; node = node->GetNext())
6264b550 2310 {
9bd1404d 2311 wxWindowMac *child = node->GetData();
6264b550
RR
2312 if (child == m_vScrollBar) continue;
2313 if (child == m_hScrollBar) continue;
2314 if (child->IsTopLevel()) continue;
6ed71b4f 2315
6264b550
RR
2316 int x,y;
2317 child->GetPosition( &x, &y );
2318 int w,h;
2319 child->GetSize( &w, &h );
00f55394
SC
2320 if (rect)
2321 {
2322 wxRect rc(x,y,w,h);
2323 if (rect->Intersects(rc))
2324 child->SetSize( x+dx, y+dy, w, h );
2325 }
2326 else
2327 {
2328 child->SetSize( x+dx, y+dy, w, h );
2329 }
6264b550 2330 }
e9576ca5
SC
2331}
2332
e766c8a9 2333void wxWindowMac::MacOnScroll(wxScrollEvent &event )
7c74e7fe 2334{
6264b550
RR
2335 if ( event.m_eventObject == m_vScrollBar || event.m_eventObject == m_hScrollBar )
2336 {
2337 wxScrollWinEvent wevent;
2338 wevent.SetPosition(event.GetPosition());
2339 wevent.SetOrientation(event.GetOrientation());
2340 wevent.m_eventObject = this;
6ed71b4f
VZ
2341
2342 if (event.m_eventType == wxEVT_SCROLL_TOP)
6264b550 2343 wevent.m_eventType = wxEVT_SCROLLWIN_TOP;
6ed71b4f
VZ
2344 else if (event.m_eventType == wxEVT_SCROLL_BOTTOM)
2345 wevent.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
2346 else if (event.m_eventType == wxEVT_SCROLL_LINEUP)
2347 wevent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
2348 else if (event.m_eventType == wxEVT_SCROLL_LINEDOWN)
2349 wevent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
2350 else if (event.m_eventType == wxEVT_SCROLL_PAGEUP)
2351 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
2352 else if (event.m_eventType == wxEVT_SCROLL_PAGEDOWN)
2353 wevent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
2354 else if (event.m_eventType == wxEVT_SCROLL_THUMBTRACK)
2355 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
2356 else if (event.m_eventType == wxEVT_SCROLL_THUMBRELEASE)
2357 wevent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
2358
2359 GetEventHandler()->ProcessEvent(wevent);
7c74e7fe
SC
2360 }
2361}
2362
e9576ca5 2363// Get the window with the focus
e766c8a9 2364wxWindowMac *wxWindowBase::FindFocus()
e9576ca5 2365{
f1d527c1
SC
2366 ControlRef control ;
2367 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2368 return wxFindControlFromMacControl( control ) ;
519cb848
SC
2369}
2370
e766c8a9 2371void wxWindowMac::OnSetFocus(wxFocusEvent& event)
7810c95b
SC
2372{
2373 // panel wants to track the window which was the last to have focus in it,
2374 // so we want to set ourselves as the window which last had focus
2375 //
2376 // notice that it's also important to do it upwards the tree becaus
2377 // otherwise when the top level panel gets focus, it won't set it back to
2378 // us, but to some other sibling
6ed71b4f 2379
c1fb8167
SC
2380 // CS:don't know if this is still needed:
2381 //wxChildFocusEvent eventFocus(this);
2382 //(void)GetEventHandler()->ProcessEvent(eventFocus);
7810c95b 2383
5ca0d812
SC
2384 if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() )
2385 {
788e118f
SC
2386 wxMacWindowStateSaver sv( this ) ;
2387// wxWindowDC dc(this) ;
2388// wxMacPortSetter helper(&dc) ;
5ca0d812
SC
2389
2390 int w , h ;
788e118f
SC
2391 int x , y ;
2392 x = y = 0 ;
2393 MacWindowToRootWindow( &x , &y ) ;
5ca0d812 2394 GetSize( &w , &h ) ;
788e118f 2395 Rect rect = {y , x , h + y , w + x } ;
5ca0d812
SC
2396
2397 if ( event.GetEventType() == wxEVT_SET_FOCUS )
2398 DrawThemeFocusRect( &rect , true ) ;
2399 else
2400 DrawThemeFocusRect( &rect , false ) ;
2401 }
2402
7810c95b
SC
2403 event.Skip();
2404}
2405
e39af974 2406void wxWindowMac::OnInternalIdle()
e9576ca5 2407{
e9576ca5
SC
2408 // This calls the UI-update mechanism (querying windows for
2409 // menu/toolbar/control state information)
e39af974
JS
2410 if (wxUpdateUIEvent::CanUpdate(this))
2411 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
e9576ca5
SC
2412}
2413
2414// Raise the window to the top of the Z order
e766c8a9 2415void wxWindowMac::Raise()
e9576ca5 2416{
5ca0d812 2417 m_peer->SetZOrder( true , NULL ) ;
e9576ca5
SC
2418}
2419
2420// Lower the window to the bottom of the Z order
e766c8a9 2421void wxWindowMac::Lower()
e9576ca5 2422{
5ca0d812 2423 m_peer->SetZOrder( false , NULL ) ;
e9576ca5
SC
2424}
2425
6ed71b4f 2426
facd6764 2427// static wxWindow *gs_lastWhich = NULL;
519cb848 2428
7de59551 2429bool wxWindowMac::MacSetupCursor( const wxPoint& pt)
467e3168
SC
2430{
2431 // first trigger a set cursor event
6ed71b4f 2432
467e3168
SC
2433 wxPoint clientorigin = GetClientAreaOrigin() ;
2434 wxSize clientsize = GetClientSize() ;
2435 wxCursor cursor ;
2436 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
7de59551 2437 {
467e3168 2438 wxSetCursorEvent event( pt.x , pt.y );
6ed71b4f 2439
467e3168
SC
2440 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
2441 if ( processedEvtSetCursor && event.HasCursor() )
2442 {
e40298d5 2443 cursor = event.GetCursor() ;
467e3168
SC
2444 }
2445 else
2446 {
6ed71b4f 2447
467e3168
SC
2448 // the test for processedEvtSetCursor is here to prevent using m_cursor
2449 // if the user code caught EVT_SET_CURSOR() and returned nothing from
2450 // it - this is a way to say that our cursor shouldn't be used for this
2451 // point
2452 if ( !processedEvtSetCursor && m_cursor.Ok() )
2453 {
2454 cursor = m_cursor ;
2455 }
2456 if ( wxIsBusy() )
2457 {
2458 }
2459 else
2460 {
2461 if ( !GetParent() )
2462 cursor = *wxSTANDARD_CURSOR ;
2463 }
2464 }
2465 if ( cursor.Ok() )
2466 cursor.MacInstall() ;
2467 }
2468 return cursor.Ok() ;
2469}
2470
e766c8a9 2471wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
2f1ae414 2472{
6264b550
RR
2473 if ( m_tooltip )
2474 {
2475 return m_tooltip->GetTip() ;
2476 }
427ff662 2477 return wxEmptyString ;
2f1ae414 2478}
6264b550 2479
1c310985 2480void wxWindowMac::Update()
519cb848 2481{
facd6764 2482#if TARGET_API_MAC_OSX
430e1eed
SC
2483 WindowRef window = (WindowRef)MacGetTopLevelWindowRef() ;
2484#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
2485 // for composited windows this also triggers a redraw of all
2486 // invalid views in the window
2487 if( UMAGetSystemVersion() >= 0x1030 )
2488 HIWindowFlush(window) ;
2489 else
2490#endif
2491 {
2492 // the only way to trigger the redrawing on earlier systems is to call
2493 // ReceiveNextEvent
2494
2495 EventRef currentEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
2496 UInt32 currentEventClass = 0 ;
2497 UInt32 currentEventKind = 0 ;
2498 if ( currentEvent != NULL )
2499 {
2500 currentEventClass = ::GetEventClass( currentEvent ) ;
2501 currentEventKind = ::GetEventKind( currentEvent ) ;
2502 }
2503 if ( currentEventClass != kEventClassMenu )
2504 {
2505 // when tracking a menu, strange redraw errors occur if we flush now, so leave..
2506
2507 EventRef theEvent;
2508 OSStatus status = noErr ;
2509 status = ReceiveNextEvent( 0 , NULL , kEventDurationNoWait , false , &theEvent ) ;
2510 }
3e444781 2511 else
5ca0d812 2512 m_peer->SetNeedsDisplay( true ) ;
430e1eed 2513 }
facd6764 2514#else
5ca0d812 2515 ::Draw1Control( m_peer->GetControlRef() ) ;
bec721ec 2516#endif
519cb848
SC
2517}
2518
14c9cbdb 2519wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
519cb848 2520{
1c310985 2521 wxTopLevelWindowMac* win = NULL ;
facd6764 2522 WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
1c310985 2523 if ( window )
6264b550 2524 {
1c310985 2525 win = wxFindWinFromMacWindow( window ) ;
14c9cbdb 2526 }
1c310985 2527 return win ;
519cb848 2528}
facd6764 2529wxRegion wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
94abc21f 2530{
facd6764
SC
2531
2532 Rect r ;
e40298d5
JS
2533 RgnHandle visRgn = NewRgn() ;
2534 RgnHandle tempRgn = NewRgn() ;
5ca0d812 2535 if ( m_peer->IsVisible())
e40298d5 2536 {
5ca0d812
SC
2537 m_peer->GetRect( &r ) ;
2538 r.left -= MacGetLeftBorderSize() ;
2539 r.top -= MacGetTopBorderSize() ;
2540 r.bottom += MacGetBottomBorderSize() ;
2541 r.right += MacGetRightBorderSize() ;
2542
facd6764 2543 if (! MacGetTopLevelWindow()->MacUsesCompositing() )
21f9e953 2544 {
facd6764
SC
2545 MacRootWindowToWindow( &r.left , & r.top ) ;
2546 MacRootWindowToWindow( &r.right , & r.bottom ) ;
21f9e953 2547 }
facd6764
SC
2548 else
2549 {
2550 r.right -= r.left ;
2551 r.bottom -= r.top ;
2552 r.left = 0 ;
2553 r.top = 0 ;
2554 }
2555 if ( includeOuterStructures )
2556 InsetRect( &r , -3 , -3 ) ;
2557 RectRgn( visRgn , &r ) ;
21f9e953 2558 if ( !IsTopLevel() )
94abc21f 2559 {
facd6764
SC
2560 wxWindow* child = this ;
2561 wxWindow* parent = child->GetParent() ;
21f9e953
SC
2562 while( parent )
2563 {
21f9e953 2564 int x , y ;
facd6764 2565 wxSize size ;
d3e780ec
SC
2566 // we have to find a better clipping algorithm here, in order not to clip things
2567 // positioned like status and toolbar
2568 if ( 1 /* parent->IsTopLevel() && child->IsKindOf( CLASSINFO( wxToolBar ) ) */ )
facd6764
SC
2569 {
2570 size = parent->GetSize() ;
2571 x = y = 0 ;
2572 }
2573 else
2574 {
2575 size = parent->GetClientSize() ;
2576 wxPoint origin = parent->GetClientAreaOrigin() ;
2577 x = origin.x ;
2578 y = origin.y ;
2579 }
21f9e953
SC
2580 parent->MacWindowToRootWindow( &x, &y ) ;
2581 MacRootWindowToWindow( &x , &y ) ;
2582
2583 SetRectRgn( tempRgn ,
2584 x + parent->MacGetLeftBorderSize() , y + parent->MacGetTopBorderSize() ,
2585 x + size.x - parent->MacGetRightBorderSize(),
2586 y + size.y - parent->MacGetBottomBorderSize()) ;
2587
2588 SectRgn( visRgn , tempRgn , visRgn ) ;
2589 if ( parent->IsTopLevel() )
2590 break ;
facd6764
SC
2591 child = parent ;
2592 parent = child->GetParent() ;
7372fd0a 2593 }
94abc21f 2594 }
e40298d5 2595 }
facd6764
SC
2596
2597 wxRegion vis = visRgn ;
e40298d5
JS
2598 DisposeRgn( visRgn ) ;
2599 DisposeRgn( tempRgn ) ;
facd6764 2600 return vis ;
94abc21f
SC
2601}
2602
facd6764
SC
2603/*
2604 This function must not change the updatergn !
2605 */
2606bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time )
519cb848 2607{
76a5e5d2 2608 RgnHandle updatergn = (RgnHandle) updatergnr ;
facd6764
SC
2609 bool handled = false ;
2610
2611 // calculate a client-origin version of the update rgn and set m_updateRegion to that
6264b550 2612 {
1c310985
SC
2613 RgnHandle newupdate = NewRgn() ;
2614 wxSize point = GetClientSize() ;
2615 wxPoint origin = GetClientAreaOrigin() ;
1c310985 2616 SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
facd6764 2617 SectRgn( newupdate , updatergn , newupdate ) ;
1c310985
SC
2618 OffsetRgn( newupdate , -origin.x , -origin.y ) ;
2619 m_updateRegion = newupdate ;
facd6764
SC
2620 DisposeRgn( newupdate ) ;
2621 }
6ed71b4f 2622
facd6764
SC
2623 if ( !EmptyRgn(updatergn) )
2624 {
2625 wxWindowDC dc(this);
2626 if (!EmptyRgn(updatergn))
2627 dc.SetClippingRegion(wxRegion(updatergn));
2628
2629 wxEraseEvent eevent( GetId(), &dc );
2630 eevent.SetEventObject( this );
2631 GetEventHandler()->ProcessEvent( eevent );
2632
1c310985 2633 if ( !m_updateRegion.Empty() )
6264b550 2634 {
facd6764 2635 // paint the window itself
e40298d5
JS
2636 wxPaintEvent event;
2637 event.m_timeStamp = time ;
2638 event.SetEventObject(this);
facd6764 2639 handled = GetEventHandler()->ProcessEvent(event);
fe779e40 2640
facd6764
SC
2641 // paint custom borders
2642 wxNcPaintEvent eventNc( GetId() );
2643 eventNc.SetEventObject( this );
2644 GetEventHandler()->ProcessEvent( eventNc );
14c9cbdb 2645 }
6264b550 2646 }
facd6764
SC
2647 return handled ;
2648}
6ed71b4f 2649
facd6764
SC
2650void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
2651{
2652 RgnHandle updatergn = (RgnHandle) updatergnr ;
2653 // updatergn is always already clipped to our boundaries
2654 // if we are in compositing mode then it is in relative to the upper left of the control
2655 // if we are in non-compositing, then it is relatvie to the uppder left of the content area
2656 // of the toplevel window
2657 // it is in window coordinates, not in client coordinates
6ed71b4f 2658
facd6764
SC
2659 // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
2660 RgnHandle ownUpdateRgn = NewRgn() ;
2661 CopyRgn( updatergn , ownUpdateRgn ) ;
2662
2663 if ( MacGetTopLevelWindow()->MacUsesCompositing() == false )
2664 {
2665 Rect bounds;
5ca0d812 2666 m_peer->GetRectInWindowCoords( &bounds );
facd6764
SC
2667 RgnHandle controlRgn = NewRgn();
2668 RectRgn( controlRgn, &bounds );
2669 //KO: This sets the ownUpdateRgn to the area of this control that is inside
2670 // the window update region
2671 SectRgn( ownUpdateRgn, controlRgn, ownUpdateRgn );
2672 DisposeRgn( controlRgn );
2673
2674 //KO: convert ownUpdateRgn to local coordinates
2675 OffsetRgn( ownUpdateRgn, -bounds.left, -bounds.top );
6264b550 2676 }
facd6764
SC
2677
2678 MacDoRedraw( ownUpdateRgn , time ) ;
2679 DisposeRgn( ownUpdateRgn ) ;
6ed71b4f 2680
519cb848
SC
2681}
2682
facd6764 2683WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
519cb848 2684{
6264b550 2685 wxWindowMac *iter = (wxWindowMac*)this ;
14c9cbdb 2686
6264b550
RR
2687 while( iter )
2688 {
1c310985
SC
2689 if ( iter->IsTopLevel() )
2690 return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
519cb848 2691
6264b550 2692 iter = iter->GetParent() ;
14c9cbdb 2693 }
427ff662 2694 wxASSERT_MSG( 1 , wxT("No valid mac root window") ) ;
6264b550 2695 return NULL ;
519cb848
SC
2696}
2697
14c9cbdb 2698void wxWindowMac::MacCreateScrollBars( long style )
519cb848 2699{
427ff662 2700 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
14c9cbdb 2701
6264b550
RR
2702 bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
2703 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1: 0 ;
2704 int width, height ;
2705 GetClientSize( &width , &height ) ;
14c9cbdb 2706
6264b550
RR
2707 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2708 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2709 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2710 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
14c9cbdb
RD
2711
2712 m_vScrollBar = new wxScrollBar(this, wxWINDOW_VSCROLL, vPoint,
6264b550
RR
2713 vSize , wxVERTICAL);
2714
2715 if ( style & wxVSCROLL )
2716 {
14c9cbdb 2717
6264b550
RR
2718 }
2719 else
2720 {
2721 m_vScrollBar->Show(false) ;
2722 }
14c9cbdb 2723 m_hScrollBar = new wxScrollBar(this, wxWINDOW_HSCROLL, hPoint,
6264b550
RR
2724 hSize , wxHORIZONTAL);
2725 if ( style & wxHSCROLL )
2726 {
2727 }
2728 else
2729 {
2730 m_hScrollBar->Show(false) ;
2731 }
14c9cbdb 2732
6264b550
RR
2733 // because the create does not take into account the client area origin
2734 MacRepositionScrollBars() ; // we might have a real position shift
519cb848
SC
2735}
2736
e766c8a9 2737void wxWindowMac::MacRepositionScrollBars()
519cb848 2738{
6264b550
RR
2739 bool hasBoth = ( m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
2740 int adjust = hasBoth ? MAC_SCROLLBAR_SIZE - 1 : 0 ;
14c9cbdb 2741
6264b550 2742 // get real client area
14c9cbdb 2743
facd6764
SC
2744 int width ;
2745 int height ;
2746 GetSize( &width , &height ) ;
6264b550
RR
2747
2748 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2749 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
14c9cbdb 2750
6264b550
RR
2751 wxPoint vPoint(width-MAC_SCROLLBAR_SIZE, 0) ;
2752 wxSize vSize(MAC_SCROLLBAR_SIZE, height - adjust) ;
2753 wxPoint hPoint(0 , height-MAC_SCROLLBAR_SIZE ) ;
2754 wxSize hSize( width - adjust, MAC_SCROLLBAR_SIZE) ;
14c9cbdb
RD
2755
2756 int x = 0 ;
6264b550 2757 int y = 0 ;
facd6764
SC
2758 int w ;
2759 int h ;
2760 GetSize( &w , &h ) ;
14c9cbdb 2761
6264b550
RR
2762 MacClientToRootWindow( &x , &y ) ;
2763 MacClientToRootWindow( &w , &h ) ;
14c9cbdb 2764
6264b550 2765 wxWindowMac *iter = (wxWindowMac*)this ;
14c9cbdb 2766
6264b550
RR
2767 int totW = 10000 , totH = 10000;
2768 while( iter )
2769 {
1c310985 2770 if ( iter->IsTopLevel() )
6264b550 2771 {
facd6764 2772 iter->GetSize( &totW , &totH ) ;
6264b550
RR
2773 break ;
2774 }
2775
2776 iter = iter->GetParent() ;
14c9cbdb
RD
2777 }
2778
6264b550
RR
2779 if ( x == 0 )
2780 {
2781 hPoint.x = -1 ;
2782 hSize.x += 1 ;
2783 }
2784 if ( y == 0 )
2785 {
2786 vPoint.y = -1 ;
2787 vSize.y += 1 ;
2788 }
14c9cbdb 2789
6264b550
RR
2790 if ( w-x >= totW )
2791 {
2792 hSize.x += 1 ;
2793 vPoint.x += 1 ;
2794 }
14c9cbdb 2795
6264b550
RR
2796 if ( h-y >= totH )
2797 {
2798 vSize.y += 1 ;
2799 hPoint.y += 1 ;
2800 }
2801
2802 if ( m_vScrollBar )
2803 {
2804 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE);
2805 }
2806 if ( m_hScrollBar )
2807 {
2808 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE);
2809 }
519cb848
SC
2810}
2811
e766c8a9 2812bool wxWindowMac::AcceptsFocus() const
7c551d95
SC
2813{
2814 return MacCanFocus() && wxWindowBase::AcceptsFocus();
2815}
519cb848 2816
14c9cbdb 2817void wxWindowMac::MacSuperChangedPosition()
519cb848 2818{
6264b550 2819 // only window-absolute structures have to be moved i.e. controls
519cb848 2820
eb22f2a6 2821 wxWindowListNode *node = GetChildren().GetFirst();
6264b550
RR
2822 while ( node )
2823 {
9bd1404d 2824 wxWindowMac *child = node->GetData();
6264b550 2825 child->MacSuperChangedPosition() ;
eb22f2a6 2826 node = node->GetNext();
6264b550 2827 }
519cb848 2828}
519cb848 2829
14c9cbdb 2830void wxWindowMac::MacTopLevelWindowChangedPosition()
a3bf4a62 2831{
6264b550 2832 // only screen-absolute structures have to be moved i.e. glcanvas
a3bf4a62 2833
eb22f2a6 2834 wxWindowListNode *node = GetChildren().GetFirst();
6264b550
RR
2835 while ( node )
2836 {
9bd1404d 2837 wxWindowMac *child = node->GetData();
6264b550 2838 child->MacTopLevelWindowChangedPosition() ;
eb22f2a6 2839 node = node->GetNext();
6264b550 2840 }
a3bf4a62 2841}
facd6764 2842
e766c8a9 2843long wxWindowMac::MacGetLeftBorderSize( ) const
2f1ae414 2844{
1c310985 2845 if( IsTopLevel() )
6264b550 2846 return 0 ;
2f1ae414
SC
2847
2848 if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
2849 {
ed60b502 2850 SInt32 border = 3 ;
5ca0d812 2851#if 0 // wxMAC_USE_THEME_BORDER
ed60b502 2852 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
1c310985 2853#endif
ed60b502 2854 return border ;
2f1ae414
SC
2855 }
2856 else if ( m_windowStyle &wxDOUBLE_BORDER)
2857 {
ed60b502 2858 SInt32 border = 3 ;
5ca0d812
SC
2859#if 0 // wxMAC_USE_THEME_BORDER
2860 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
1c310985 2861#endif
ed60b502 2862 return border ;
2f1ae414
SC
2863 }
2864 else if (m_windowStyle &wxSIMPLE_BORDER)
2865 {
6264b550 2866 return 1 ;
2f1ae414 2867 }
6264b550 2868 return 0 ;
2f1ae414
SC
2869}
2870
e766c8a9 2871long wxWindowMac::MacGetRightBorderSize( ) const
5b781a67 2872{
1c310985
SC
2873 // they are all symmetric in mac themes
2874 return MacGetLeftBorderSize() ;
5b781a67
SC
2875}
2876
e766c8a9 2877long wxWindowMac::MacGetTopBorderSize( ) const
5b781a67 2878{
1c310985
SC
2879 // they are all symmetric in mac themes
2880 return MacGetLeftBorderSize() ;
5b781a67
SC
2881}
2882
e766c8a9 2883long wxWindowMac::MacGetBottomBorderSize( ) const
5b781a67 2884{
1c310985
SC
2885 // they are all symmetric in mac themes
2886 return MacGetLeftBorderSize() ;
5b781a67
SC
2887}
2888
14c9cbdb 2889long wxWindowMac::MacRemoveBordersFromStyle( long style )
2f1ae414 2890{
6264b550 2891 return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
2f1ae414 2892}
0a67a93b 2893
e766c8a9 2894// Find the wxWindowMac at the current mouse position, returning the mouse
3723b7b1 2895// position.
e766c8a9 2896wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)
3723b7b1 2897{
59a12e90 2898 pt = wxGetMousePosition();
e766c8a9 2899 wxWindowMac* found = wxFindWindowAtPoint(pt);
59a12e90 2900 return found;
3723b7b1
JS
2901}
2902
2903// Get the current mouse position.
2904wxPoint wxGetMousePosition()
2905{
57591e0e
JS
2906 int x, y;
2907 wxGetMousePosition(& x, & y);
2908 return wxPoint(x, y);
3723b7b1
JS
2909}
2910
6ed71b4f 2911void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
8950f7cc
SC
2912{
2913 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2914 {
2915 // copied from wxGTK : CS
249aad30 2916 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
8950f7cc
SC
2917 // except that:
2918 //
2919 // (a) it's a command event and so is propagated to the parent
2920 // (b) under MSW it can be generated from kbd too
2921 // (c) it uses screen coords (because of (a))
2922 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2923 this->GetId(),
2924 this->ClientToScreen(event.GetPosition()));
249aad30
SC
2925 if ( ! GetEventHandler()->ProcessEvent(evtCtx) )
2926 event.Skip() ;
8950f7cc 2927 }
facd6764
SC
2928 else
2929 {
2930 event.Skip() ;
2931 }
8950f7cc
SC
2932}
2933
facd6764
SC
2934void wxWindowMac::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED( mouseStillDown ) )
2935{
facd6764
SC
2936}
2937
79392158 2938Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3083eb85
SC
2939{
2940 int x ,y , w ,h ;
2941
79392158 2942 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin) ;
3083eb85
SC
2943 Rect bounds = { y , x , y+h , x+w };
2944 return bounds ;
2945}
2946
f1d527c1
SC
2947wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
2948{
2949 return eventNotHandledErr ;
2950}
2951
facd6764 2952