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