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