]> git.saurik.com Git - wxWidgets.git/blame - src/osx/window_osx.cpp
Add wxPanel::SetBackgroundBitmap().
[wxWidgets.git] / src / osx / window_osx.cpp
CommitLineData
524c47aa
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/carbon/window.cpp
3// Purpose: wxWindowMac
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
524c47aa
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/window.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/log.h"
18 #include "wx/app.h"
19 #include "wx/utils.h"
20 #include "wx/panel.h"
21 #include "wx/frame.h"
22 #include "wx/dc.h"
23 #include "wx/dcclient.h"
24 #include "wx/button.h"
25 #include "wx/menu.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
29 #include "wx/scrolbar.h"
30 #include "wx/statbox.h"
31 #include "wx/textctrl.h"
32 #include "wx/toolbar.h"
33 #include "wx/layout.h"
34 #include "wx/statusbr.h"
35 #include "wx/menuitem.h"
36 #include "wx/treectrl.h"
37 #include "wx/listctrl.h"
38#endif
39
40#include "wx/tooltip.h"
41#include "wx/spinctrl.h"
42#include "wx/geometry.h"
43
44#if wxUSE_LISTCTRL
45 #include "wx/listctrl.h"
46#endif
47
48#if wxUSE_TREECTRL
49 #include "wx/treectrl.h"
50#endif
51
52#if wxUSE_CARET
53 #include "wx/caret.h"
54#endif
55
56#if wxUSE_POPUPWIN
57 #include "wx/popupwin.h"
58#endif
59
60#if wxUSE_DRAG_AND_DROP
61#include "wx/dnd.h"
62#endif
63
f55d9f74
SC
64#include "wx/graphics.h"
65
524c47aa
SC
66#if wxOSX_USE_CARBON
67#include "wx/osx/uma.h"
68#else
69#include "wx/osx/private.h"
11fed901 70#endif
524c47aa
SC
71
72#define MAC_SCROLLBAR_SIZE 15
73#define MAC_SMALL_SCROLLBAR_SIZE 11
74
75#include <string.h>
76
77#ifdef __WXUNIVERSAL__
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowMac, wxWindowBase)
524c47aa
SC
79#endif
80
81BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
524c47aa
SC
82 EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent)
83END_EVENT_TABLE()
84
85#define wxMAC_DEBUG_REDRAW 0
86#ifndef wxMAC_DEBUG_REDRAW
87#define wxMAC_DEBUG_REDRAW 0
88#endif
89
d15694e8
SC
90wxWidgetImplType* kOSXNoWidgetImpl = (wxWidgetImplType*) -1L;
91
524c47aa
SC
92// ===========================================================================
93// implementation
94// ===========================================================================
95
82f8ea85
SC
96// the grow box has to be implemented as an inactive window, so that nothing can direct
97// the focus to it
98
99class WXDLLIMPEXP_CORE wxBlindPlateWindow : public wxWindow
100{
101public:
102 wxBlindPlateWindow() { Init(); }
c59aa14a 103
82f8ea85
SC
104 // Old-style constructor (no default values for coordinates to avoid
105 // ambiguity with the new one)
106 wxBlindPlateWindow(wxWindow *parent,
107 int x, int y, int width, int height,
108 long style = wxTAB_TRAVERSAL | wxNO_BORDER,
109 const wxString& name = wxPanelNameStr)
110 {
111 Init();
c59aa14a 112
82f8ea85
SC
113 Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), style, name);
114 }
c59aa14a 115
82f8ea85
SC
116 // Constructor
117 wxBlindPlateWindow(wxWindow *parent,
118 wxWindowID winid = wxID_ANY,
119 const wxPoint& pos = wxDefaultPosition,
120 const wxSize& size = wxDefaultSize,
121 long style = wxTAB_TRAVERSAL | wxNO_BORDER,
122 const wxString& name = wxPanelNameStr)
123 {
124 Init();
c59aa14a 125
82f8ea85
SC
126 Create(parent, winid, pos, size, style, name);
127 }
c59aa14a 128
82f8ea85
SC
129 // Pseudo ctor
130 bool Create(wxWindow *parent,
131 wxWindowID winid = wxID_ANY,
132 const wxPoint& pos = wxDefaultPosition,
133 const wxSize& size = wxDefaultSize,
134 long style = wxTAB_TRAVERSAL | wxNO_BORDER,
135 const wxString& name = wxPanelNameStr)
136 {
137 if ( !wxWindow::Create(parent, winid, pos, size, style, name) )
138 return false;
c59aa14a 139
82f8ea85
SC
140 // so that non-solid background renders correctly under GTK+:
141 SetThemeEnabled(true);
48159545 142 return true;
82f8ea85 143 }
c59aa14a 144
82f8ea85 145 virtual ~wxBlindPlateWindow();
c59aa14a 146
82f8ea85
SC
147 virtual bool AcceptsFocus() const
148 {
149 return false;
150 }
c59aa14a 151
82f8ea85
SC
152protected:
153 // common part of all ctors
154 void Init()
155 {
156 }
c59aa14a 157
82f8ea85
SC
158 DECLARE_DYNAMIC_CLASS_NO_COPY(wxBlindPlateWindow)
159 DECLARE_EVENT_TABLE()
160};
161
162wxBlindPlateWindow::~wxBlindPlateWindow()
163{
164}
165
166IMPLEMENT_DYNAMIC_CLASS(wxBlindPlateWindow, wxWindow)
167
168BEGIN_EVENT_TABLE(wxBlindPlateWindow, wxWindow)
169END_EVENT_TABLE()
170
171
524c47aa
SC
172// ----------------------------------------------------------------------------
173 // constructors and such
174// ----------------------------------------------------------------------------
175
176wxWindowMac::wxWindowMac()
177{
178 Init();
179}
180
181wxWindowMac::wxWindowMac(wxWindowMac *parent,
182 wxWindowID id,
183 const wxPoint& pos ,
184 const wxSize& size ,
185 long style ,
186 const wxString& name )
187{
188 Init();
189 Create(parent, id, pos, size, style, name);
190}
191
192void wxWindowMac::Init()
193{
194 m_peer = NULL ;
195 m_macAlpha = 255 ;
196 m_cgContextRef = NULL ;
197
198 // as all windows are created with WS_VISIBLE style...
199 m_isShown = true;
200
201 m_hScrollBar = NULL ;
202 m_vScrollBar = NULL ;
203 m_hScrollBarAlwaysShown = false;
204 m_vScrollBarAlwaysShown = false;
2ae3afa0 205 m_growBox = NULL ;
524c47aa 206
524c47aa
SC
207 m_clipChildren = false ;
208 m_cachedClippedRectValid = false ;
17e2694c 209 m_isNativeWindowWrapper = false;
524c47aa
SC
210}
211
212wxWindowMac::~wxWindowMac()
213{
214 SendDestroyEvent();
215
524c47aa
SC
216 MacInvalidateBorders() ;
217
218#ifndef __WXUNIVERSAL__
219 // VS: make sure there's no wxFrame with last focus set to us:
220 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
221 {
222 wxFrame *frame = wxDynamicCast(win, wxFrame);
223 if ( frame )
224 {
225 if ( frame->GetLastFocus() == this )
d3b9f782 226 frame->SetLastFocus(NULL);
524c47aa
SC
227 break;
228 }
229 }
230#endif
231
232 // destroy children before destroying this window itself
233 DestroyChildren();
234
235 // wxRemoveMacControlAssociation( this ) ;
236 // If we delete an item, we should initialize the parent panel,
237 // because it could now be invalid.
238 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow);
239 if ( tlw )
240 {
241 if ( tlw->GetDefaultItem() == (wxButton*) this)
242 tlw->SetDefaultItem(NULL);
243 }
244
245 if ( g_MacLastWindow == this )
246 g_MacLastWindow = NULL ;
247
248#ifndef __WXUNIVERSAL__
249 wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ;
250 if ( frame )
251 {
252 if ( frame->GetLastFocus() == this )
253 frame->SetLastFocus( NULL ) ;
254 }
255#endif
256
257 // delete our drop target if we've got one
258#if wxUSE_DRAG_AND_DROP
5276b0a5 259 wxDELETE(m_dropTarget);
524c47aa
SC
260#endif
261
d15694e8 262 delete GetPeer() ;
524c47aa
SC
263}
264
265WXWidget wxWindowMac::GetHandle() const
266{
d15694e8
SC
267 if ( GetPeer() )
268 return (WXWidget) GetPeer()->GetWXWidget() ;
d4e4ba48 269 return NULL;
524c47aa
SC
270}
271
d15694e8
SC
272wxOSXWidgetImpl* wxWindowMac::GetPeer() const
273{
274 return m_peer == kOSXNoWidgetImpl ? NULL : m_peer ;
275}
276
277void wxWindowMac::DontCreatePeer()
278{
279 m_peer = kOSXNoWidgetImpl;
280}
281
282void wxWindowMac::SetWrappingPeer(wxOSXWidgetImpl* wrapper)
283{
284 wxOSXWidgetImpl* inner = GetPeer();
285 wxASSERT_MSG( inner != NULL && inner->IsOk(), "missing or incomplete inner peer" );
286 wxASSERT_MSG( wrapper != NULL && wrapper->IsOk(), "missing or incomplete wrapper" );
287
288 if ( !(inner != NULL && inner->IsOk() && wrapper != NULL && wrapper->IsOk()) )
289 return;
290
291 inner->RemoveFromParent();
292 wrapper->InstallEventHandler();
293 wrapper->Embed(inner);
294 m_peer = wrapper;
295}
296
22756322
SC
297void wxWindowMac::SetPeer(wxOSXWidgetImpl* peer)
298{
d15694e8
SC
299 if ( GetPeer() )
300 {
301 GetPeer()->RemoveFromParent();
302 wxDELETE(m_peer);
303 }
304
22756322 305 m_peer = peer;
d15694e8
SC
306
307 if ( GetPeer() && !GetPeer()->IsRootControl())
308 {
309 wxASSERT_MSG( GetPeer()->IsOk() , wxT("The native control must exist already") ) ;
310
311 if (!GetParent()->GetChildren().Find((wxWindow*)this))
312 GetParent()->AddChild( this );
313
314 GetPeer()->InstallEventHandler();
315 GetPeer()->Embed(GetParent()->GetPeer());
316
317 GetParent()->MacChildAdded() ;
318
319 // adjust font, controlsize etc
320 DoSetWindowVariant( m_windowVariant ) ;
321
322 GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
323
324 // for controls we want to use best size for wxDefaultSize params )
325 if ( !GetPeer()->IsUserPane() )
326 SetInitialSize(GetMinSize());
327
328 SetCursor( *wxSTANDARD_CURSOR ) ;
329 }
330}
331
332#if WXWIN_COMPATIBILITY_2_8
333
334bool wxWindowMac::MacIsUserPane()
335{
336 return GetPeer() == NULL || GetPeer()->IsUserPane();
337}
338
339#endif
340
341bool wxWindowMac::MacIsUserPane() const
342{
343 return GetPeer() == NULL || GetPeer()->IsUserPane();
22756322
SC
344}
345
524c47aa
SC
346// ---------------------------------------------------------------------------
347// Utility Routines to move between different coordinate systems
348// ---------------------------------------------------------------------------
349
350/*
351 * Right now we have the following setup :
352 * a border that is not part of the native control is always outside the
353 * control's border (otherwise we loose all native intelligence, future ways
354 * may be to have a second embedding control responsible for drawing borders
355 * and backgrounds eventually)
356 * so all this border calculations have to be taken into account when calling
357 * native methods or getting native oriented data
358 * so we have three coordinate systems here
359 * wx client coordinates
360 * wx window coordinates (including window frames)
361 * native coordinates
362 */
363
364//
365//
366
367// Constructor
368bool wxWindowMac::Create(wxWindowMac *parent,
369 wxWindowID id,
370 const wxPoint& pos,
371 const wxSize& size,
372 long style,
373 const wxString& name)
374{
375 wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
376
377 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
378 return false;
379
380 m_windowVariant = parent->GetWindowVariant() ;
381
d15694e8 382 if ( m_peer != kOSXNoWidgetImpl )
524c47aa 383 {
d15694e8 384 SetPeer(wxWidgetImpl::CreateUserPane( this, parent, id, pos, size , style, GetExtraStyle() ));
524c47aa
SC
385 MacPostControlCreate(pos, size) ;
386 }
387
388#ifndef __WXUNIVERSAL__
389 // Don't give scrollbars to wxControls unless they ask for them
03647350 390 if ( (! IsKindOf(CLASSINFO(wxControl))
11fed901
SC
391#if wxUSE_STATUSBAR
392 && ! IsKindOf(CLASSINFO(wxStatusBar))
393#endif
394 )
524c47aa
SC
395 || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL))))
396 {
397 MacCreateScrollBars( style ) ;
398 }
399#endif
400
401 wxWindowCreateEvent event((wxWindow*)this);
402 GetEventHandler()->AddPendingEvent(event);
403
404 return true;
405}
406
407void wxWindowMac::MacChildAdded()
408{
11fed901 409#if wxUSE_SCROLLBAR
524c47aa
SC
410 if ( m_vScrollBar )
411 m_vScrollBar->Raise() ;
412 if ( m_hScrollBar )
413 m_hScrollBar->Raise() ;
2ae3afa0
JS
414 if ( m_growBox )
415 m_growBox->Raise() ;
11fed901 416#endif
524c47aa
SC
417}
418
419void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size)
420{
d15694e8
SC
421 // todo remove if refactoring works correctly
422#if 0
423 wxASSERT_MSG( GetPeer() != NULL && GetPeer()->IsOk() , wxT("No valid mac control") ) ;
524c47aa 424
d15694e8
SC
425 if (!GetParent()->GetChildren().Find((wxWindow*)this))
426 GetParent()->AddChild( this );
524c47aa 427
d15694e8
SC
428 GetPeer()->InstallEventHandler();
429 GetPeer()->Embed(GetParent()->GetPeer());
524c47aa 430
524c47aa
SC
431 GetParent()->MacChildAdded() ;
432
433 // adjust font, controlsize etc
434 DoSetWindowVariant( m_windowVariant ) ;
435
d15694e8 436 GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
524c47aa 437
f55d9f74 438 // for controls we want to use best size for wxDefaultSize params )
d15694e8 439 if ( !GetPeer()->IsUserPane() )
524c47aa
SC
440 SetInitialSize(size);
441
442 SetCursor( *wxSTANDARD_CURSOR ) ;
d15694e8 443#endif
524c47aa
SC
444}
445
446void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
447{
448 // Don't assert, in case we set the window variant before
449 // the window is created
d15694e8 450 // wxASSERT( GetPeer()->Ok() ) ;
524c47aa
SC
451
452 m_windowVariant = variant ;
453
d15694e8 454 if (GetPeer() == NULL || !GetPeer()->IsOk())
524c47aa
SC
455 return;
456
d15694e8 457 GetPeer()->SetControlSize( variant );
7ac5e1c9
SC
458#if wxOSX_USE_CARBON
459 ControlSize size ;
460
461 // we will get that from the settings later
462 // and make this NORMAL later, but first
463 // we have a few calculations that we must fix
464
465 switch ( variant )
466 {
467 case wxWINDOW_VARIANT_NORMAL :
468 size = kControlSizeNormal;
469 break ;
470
471 case wxWINDOW_VARIANT_SMALL :
472 size = kControlSizeSmall;
473 break ;
474
475 case wxWINDOW_VARIANT_MINI :
476 // not always defined in the headers
477 size = 3 ;
478 break ;
479
480 case wxWINDOW_VARIANT_LARGE :
481 size = kControlSizeLarge;
482 break ;
483
484 default:
9a83f860 485 wxFAIL_MSG(wxT("unexpected window variant"));
7ac5e1c9
SC
486 break ;
487 }
d15694e8 488 GetPeer()->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
7ac5e1c9
SC
489#endif
490
c59aa14a 491
524c47aa
SC
492 switch ( variant )
493 {
494 case wxWINDOW_VARIANT_NORMAL :
7eb8aeb8
SC
495 static wxFont sysNormal(wxOSX_SYSTEM_FONT_NORMAL);
496 SetFont(sysNormal) ;
524c47aa
SC
497 break ;
498
499 case wxWINDOW_VARIANT_SMALL :
7eb8aeb8
SC
500 static wxFont sysSmall(wxOSX_SYSTEM_FONT_SMALL);
501 SetFont(sysSmall) ;
524c47aa
SC
502 break ;
503
504 case wxWINDOW_VARIANT_MINI :
7eb8aeb8
SC
505 static wxFont sysMini(wxOSX_SYSTEM_FONT_MINI);
506 SetFont(sysMini) ;
524c47aa
SC
507 break ;
508
509 case wxWINDOW_VARIANT_LARGE :
7eb8aeb8
SC
510 static wxFont sysLarge(wxOSX_SYSTEM_FONT_NORMAL);
511 SetFont(sysLarge) ;
524c47aa
SC
512 break ;
513
514 default:
9a83f860 515 wxFAIL_MSG(wxT("unexpected window variant"));
524c47aa
SC
516 break ;
517 }
524c47aa
SC
518}
519
520void wxWindowMac::MacUpdateControlFont()
521{
d15694e8
SC
522 if ( GetPeer() )
523 GetPeer()->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1e181c7a 524
524c47aa
SC
525 // do not trigger refreshes upon invisible and possible partly created objects
526 if ( IsShownOnScreen() )
527 Refresh() ;
528}
529
530bool wxWindowMac::SetFont(const wxFont& font)
531{
532 bool retval = wxWindowBase::SetFont( font );
533
534 MacUpdateControlFont() ;
535
536 return retval;
537}
538
539bool wxWindowMac::SetForegroundColour(const wxColour& col )
540{
541 bool retval = wxWindowBase::SetForegroundColour( col );
542
543 if (retval)
544 MacUpdateControlFont();
545
546 return retval;
547}
548
bc5c09a3
SC
549bool wxWindowMac::SetBackgroundStyle(wxBackgroundStyle style)
550{
551 if ( !wxWindowBase::SetBackgroundStyle(style) )
552 return false;
c59aa14a 553
d15694e8
SC
554 if ( GetPeer() )
555 GetPeer()->SetBackgroundStyle(style);
bc5c09a3
SC
556 return true;
557}
558
524c47aa
SC
559bool wxWindowMac::SetBackgroundColour(const wxColour& col )
560{
82f8ea85
SC
561 if (m_growBox)
562 {
563 if ( m_backgroundColour.Ok() )
564 m_growBox->SetBackgroundColour(m_backgroundColour);
565 else
566 m_growBox->SetBackgroundColour(*wxWHITE);
567 }
568
524c47aa
SC
569 if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
570 return false ;
571
d15694e8
SC
572 if ( GetPeer() )
573 GetPeer()->SetBackgroundColour( col ) ;
524c47aa
SC
574
575 return true ;
576}
577
77a246e1
JS
578static bool wxIsWindowOrParentDisabled(wxWindow* w)
579{
580 while (w && !w->IsTopLevel())
581 {
582 if (!w->IsEnabled())
583 return true;
584 w = w->GetParent();
585 }
586 return false;
587}
588
524c47aa
SC
589void wxWindowMac::SetFocus()
590{
591 if ( !AcceptsFocus() )
592 return ;
593
77a246e1
JS
594 if (wxIsWindowOrParentDisabled((wxWindow*) this))
595 return;
596
524c47aa
SC
597 wxWindow* former = FindFocus() ;
598 if ( former == this )
599 return ;
600
d15694e8 601 GetPeer()->SetFocus() ;
524c47aa
SC
602}
603
604void wxWindowMac::DoCaptureMouse()
605{
606 wxApp::s_captureWindow = (wxWindow*) this ;
d15694e8 607 GetPeer()->CaptureMouse() ;
524c47aa
SC
608}
609
610wxWindow * wxWindowBase::GetCapture()
611{
612 return wxApp::s_captureWindow ;
613}
614
615void wxWindowMac::DoReleaseMouse()
616{
617 wxApp::s_captureWindow = NULL ;
54f11060 618
d15694e8 619 GetPeer()->ReleaseMouse() ;
524c47aa
SC
620}
621
622#if wxUSE_DRAG_AND_DROP
623
624void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
625{
0b1ca117 626 delete m_dropTarget;
524c47aa
SC
627
628 m_dropTarget = pDropTarget;
629 if ( m_dropTarget != NULL )
630 {
631 // TODO:
632 }
633}
634
635#endif
636
637// Old-style File Manager Drag & Drop
638void wxWindowMac::DragAcceptFiles(bool WXUNUSED(accept))
639{
640 // TODO:
641}
642
643// From a wx position / size calculate the appropriate size of the native control
644
645bool wxWindowMac::MacGetBoundsForControl(
646 const wxPoint& pos,
647 const wxSize& size,
648 int& x, int& y,
649 int& w, int& h , bool adjustOrigin ) const
650{
651 // the desired size, minus the border pixels gives the correct size of the control
652 x = (int)pos.x;
653 y = (int)pos.y;
654
69ce9cea
VZ
655 w = WidthDefault( size.x );
656 h = HeightDefault( size.y );
524c47aa
SC
657
658 x += MacGetLeftBorderSize() ;
659 y += MacGetTopBorderSize() ;
660 w -= MacGetLeftBorderSize() + MacGetRightBorderSize() ;
661 h -= MacGetTopBorderSize() + MacGetBottomBorderSize() ;
662
663 if ( adjustOrigin )
664 AdjustForParentClientOrigin( x , y ) ;
665
666 // this is in window relative coordinate, as this parent may have a border, its physical position is offset by this border
1a4e2d5b 667 if ( GetParent() && !GetParent()->IsTopLevel() )
524c47aa
SC
668 {
669 x -= GetParent()->MacGetLeftBorderSize() ;
670 y -= GetParent()->MacGetTopBorderSize() ;
671 }
672
673 return true ;
674}
675
676// Get window size (not client size)
677void wxWindowMac::DoGetSize(int *x, int *y) const
678{
679 int width, height;
d15694e8 680 GetPeer()->GetSize( width, height );
524c47aa
SC
681
682 if (x)
683 *x = width + MacGetLeftBorderSize() + MacGetRightBorderSize() ;
684 if (y)
685 *y = height + MacGetTopBorderSize() + MacGetBottomBorderSize() ;
686}
687
688// get the position of the bounds of this window in client coordinates of its parent
689void wxWindowMac::DoGetPosition(int *x, int *y) const
690{
691 int x1, y1;
69ce9cea 692
d15694e8 693 GetPeer()->GetPosition( x1, y1 ) ;
524c47aa
SC
694
695 // get the wx window position from the native one
696 x1 -= MacGetLeftBorderSize() ;
697 y1 -= MacGetTopBorderSize() ;
698
699 if ( !IsTopLevel() )
700 {
701 wxWindow *parent = GetParent();
702 if ( parent )
703 {
704 // we must first adjust it to be in window coordinates of the parent,
705 // as otherwise it gets lost by the ClientAreaOrigin fix
706 x1 += parent->MacGetLeftBorderSize() ;
707 y1 += parent->MacGetTopBorderSize() ;
708
709 // and now to client coordinates
710 wxPoint pt(parent->GetClientAreaOrigin());
711 x1 -= pt.x ;
712 y1 -= pt.y ;
713 }
714 }
715
716 if (x)
717 *x = x1 ;
718 if (y)
719 *y = y1 ;
720}
721
722void wxWindowMac::DoScreenToClient(int *x, int *y) const
723{
724 wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ;
725 wxCHECK_RET( tlw , wxT("TopLevel Window missing") ) ;
726 tlw->GetNonOwnedPeer()->ScreenToWindow( x, y);
727 MacRootWindowToWindow( x , y ) ;
728
729 wxPoint origin = GetClientAreaOrigin() ;
730 if (x)
731 *x -= origin.x ;
732 if (y)
733 *y -= origin.y ;
734}
735
736void wxWindowMac::DoClientToScreen(int *x, int *y) const
737{
738 wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ;
739 wxCHECK_RET( tlw , wxT("TopLevel window missing") ) ;
740
741 wxPoint origin = GetClientAreaOrigin() ;
742 if (x)
743 *x += origin.x ;
744 if (y)
745 *y += origin.y ;
746
747 MacWindowToRootWindow( x , y ) ;
748 tlw->GetNonOwnedPeer()->WindowToScreen( x , y );
749}
750
751void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
752{
753 wxPoint origin = GetClientAreaOrigin() ;
754 if (x)
755 *x += origin.x ;
756 if (y)
757 *y += origin.y ;
758
759 MacWindowToRootWindow( x , y ) ;
760}
761
762void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
763{
764 wxPoint pt ;
765
766 if (x)
767 pt.x = *x ;
768 if (y)
769 pt.y = *y ;
770
771 if ( !IsTopLevel() )
772 {
773 wxNonOwnedWindow* top = MacGetTopLevelWindow();
774 if (top)
775 {
776 pt.x -= MacGetLeftBorderSize() ;
777 pt.y -= MacGetTopBorderSize() ;
d15694e8 778 wxWidgetImpl::Convert( &pt , GetPeer() , top->GetPeer() ) ;
524c47aa
SC
779 }
780 }
781
782 if (x)
783 *x = (int) pt.x ;
784 if (y)
785 *y = (int) pt.y ;
786}
787
788void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
789{
790 wxPoint pt ;
791
792 if (x)
793 pt.x = *x ;
794 if (y)
795 pt.y = *y ;
796
797 if ( !IsTopLevel() )
798 {
799 wxNonOwnedWindow* top = MacGetTopLevelWindow();
800 if (top)
801 {
d15694e8 802 wxWidgetImpl::Convert( &pt , top->GetPeer() , GetPeer() ) ;
524c47aa
SC
803 pt.x += MacGetLeftBorderSize() ;
804 pt.y += MacGetTopBorderSize() ;
805 }
806 }
807
808 if (x)
809 *x = (int) pt.x ;
810 if (y)
811 *y = (int) pt.y ;
812}
813
814wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const
815{
816 wxSize sizeTotal = size;
817
818 int innerwidth, innerheight;
819 int left, top;
820 int outerwidth, outerheight;
69ce9cea 821
d15694e8
SC
822 GetPeer()->GetContentArea( left, top, innerwidth, innerheight );
823 GetPeer()->GetSize( outerwidth, outerheight );
69ce9cea 824
0c530e5a
SC
825 sizeTotal.x += outerwidth-innerwidth;
826 sizeTotal.y += outerheight-innerheight;
69ce9cea 827
524c47aa
SC
828 sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ;
829 sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ;
830
831 return sizeTotal;
832}
833
834// Get size *available for subwindows* i.e. excluding menu bar etc.
835void wxWindowMac::DoGetClientSize( int *x, int *y ) const
836{
837 int ww, hh;
838
839 int left, top;
69ce9cea 840
d15694e8 841 GetPeer()->GetContentArea( left, top, ww, hh );
11fed901 842#if wxUSE_SCROLLBAR
524c47aa
SC
843 if (m_hScrollBar && m_hScrollBar->IsShown() )
844 hh -= m_hScrollBar->GetSize().y ;
845
846 if (m_vScrollBar && m_vScrollBar->IsShown() )
847 ww -= m_vScrollBar->GetSize().x ;
848
11fed901 849#endif
524c47aa
SC
850 if (x)
851 *x = ww;
852 if (y)
853 *y = hh;
854}
855
856bool wxWindowMac::SetCursor(const wxCursor& cursor)
857{
858 if (m_cursor.IsSameAs(cursor))
859 return false;
860
861 if (!cursor.IsOk())
862 {
863 if ( ! wxWindowBase::SetCursor( *wxSTANDARD_CURSOR ) )
864 return false ;
865 }
866 else
867 {
868 if ( ! wxWindowBase::SetCursor( cursor ) )
869 return false ;
870 }
871
872 wxASSERT_MSG( m_cursor.Ok(),
873 wxT("cursor must be valid after call to the base version"));
874
54f11060
SC
875 if ( GetPeer() != NULL )
876 GetPeer()->SetCursor( m_cursor );
524c47aa
SC
877
878 return true ;
879}
880
881#if wxUSE_MENUS
882bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
883{
884#ifndef __WXUNIVERSAL__
524c47aa
SC
885 menu->UpdateUI();
886
887 if ( x == wxDefaultCoord && y == wxDefaultCoord )
888 {
889 wxPoint mouse = wxGetMousePosition();
890 x = mouse.x;
891 y = mouse.y;
892 }
893 else
894 {
895 ClientToScreen( &x , &y ) ;
896 }
2cb5d2d2 897 menu->GetPeer()->PopUp(this, x, y);
524c47aa
SC
898 return true;
899#else
900 // actually this shouldn't be called, because universal is having its own implementation
901 return false;
902#endif
903}
904#endif
905
906// ----------------------------------------------------------------------------
907// tooltips
908// ----------------------------------------------------------------------------
909
910#if wxUSE_TOOLTIPS
911
912void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
913{
914 wxWindowBase::DoSetToolTip(tooltip);
915
916 if ( m_tooltip )
917 m_tooltip->SetWindow(this);
c59aa14a 918
d15694e8
SC
919 if (GetPeer())
920 GetPeer()->SetToolTip(tooltip);
524c47aa
SC
921}
922
923#endif
924
925void wxWindowMac::MacInvalidateBorders()
926{
d15694e8 927 if ( GetPeer() == NULL )
524c47aa
SC
928 return ;
929
930 bool vis = IsShownOnScreen() ;
931 if ( !vis )
932 return ;
933
934 int outerBorder = MacGetLeftBorderSize() ;
b2088388 935
d15694e8 936 if ( GetPeer()->NeedsFocusRect() )
524c47aa 937 outerBorder += 4 ;
524c47aa
SC
938
939 if ( outerBorder == 0 )
940 return ;
941
942 // now we know that we have something to do at all
524c47aa
SC
943
944 int tx,ty,tw,th;
69ce9cea 945
d15694e8
SC
946 GetPeer()->GetSize( tw, th );
947 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
948
949 wxRect leftupdate( tx-outerBorder,ty,outerBorder,th );
950 wxRect rightupdate( tx+tw, ty, outerBorder, th );
951 wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder );
952 wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder );
69ce9cea 953
1a4e2d5b 954 if (GetParent()) {
d15694e8
SC
955 GetParent()->GetPeer()->SetNeedsDisplay(&leftupdate);
956 GetParent()->GetPeer()->SetNeedsDisplay(&rightupdate);
957 GetParent()->GetPeer()->SetNeedsDisplay(&topupdate);
958 GetParent()->GetPeer()->SetNeedsDisplay(&bottomupdate);
1a4e2d5b 959 }
524c47aa
SC
960}
961
962void wxWindowMac::DoMoveWindow(int x, int y, int width, int height)
963{
964 // this is never called for a toplevel window, so we know we have a parent
965 int former_x , former_y , former_w, former_h ;
966
967 // Get true coordinates of former position
968 DoGetPosition( &former_x , &former_y ) ;
969 DoGetSize( &former_w , &former_h ) ;
970
971 wxWindow *parent = GetParent();
972 if ( parent )
973 {
974 wxPoint pt(parent->GetClientAreaOrigin());
975 former_x += pt.x ;
976 former_y += pt.y ;
977 }
978
979 int actualWidth = width ;
980 int actualHeight = height ;
981 int actualX = x;
982 int actualY = y;
983
f1b1c779
SC
984#if 0
985 // min and max sizes are only for sizers, not for explicit size setting
524c47aa
SC
986 if ((m_minWidth != -1) && (actualWidth < m_minWidth))
987 actualWidth = m_minWidth;
988 if ((m_minHeight != -1) && (actualHeight < m_minHeight))
989 actualHeight = m_minHeight;
990 if ((m_maxWidth != -1) && (actualWidth > m_maxWidth))
991 actualWidth = m_maxWidth;
992 if ((m_maxHeight != -1) && (actualHeight > m_maxHeight))
993 actualHeight = m_maxHeight;
f1b1c779 994#endif
524c47aa
SC
995
996 bool doMove = false, doResize = false ;
997
998 if ( actualX != former_x || actualY != former_y )
999 doMove = true ;
1000
1001 if ( actualWidth != former_w || actualHeight != former_h )
1002 doResize = true ;
1003
1004 if ( doMove || doResize )
1005 {
1006 // as the borders are drawn outside the native control, we adjust now
1007
1008 wxRect bounds( wxPoint( actualX + MacGetLeftBorderSize() ,actualY + MacGetTopBorderSize() ),
1009 wxSize( actualWidth - (MacGetLeftBorderSize() + MacGetRightBorderSize()) ,
1010 actualHeight - (MacGetTopBorderSize() + MacGetBottomBorderSize()) ) ) ;
1011
1a4e2d5b 1012 if ( parent && !parent->IsTopLevel() )
524c47aa 1013 {
1a4e2d5b 1014 bounds.Offset( -parent->MacGetLeftBorderSize(), -parent->MacGetTopBorderSize() );
524c47aa
SC
1015 }
1016
1017 MacInvalidateBorders() ;
1018
1019 m_cachedClippedRectValid = false ;
69ce9cea 1020
d15694e8 1021 GetPeer()->Move( bounds.x, bounds.y, bounds.width, bounds.height);
524c47aa
SC
1022
1023 wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
1024
1025 MacInvalidateBorders() ;
1026
1027 MacRepositionScrollBars() ;
1028 if ( doMove )
1029 {
1030 wxPoint point(actualX, actualY);
1031 wxMoveEvent event(point, m_windowId);
1032 event.SetEventObject(this);
1033 HandleWindowEvent(event) ;
1034 }
1035
1036 if ( doResize )
1037 {
1038 MacRepositionScrollBars() ;
1039 wxSize size(actualWidth, actualHeight);
1040 wxSizeEvent event(size, m_windowId);
1041 event.SetEventObject(this);
1042 HandleWindowEvent(event);
1043 }
1044 }
1045}
1046
1047wxSize wxWindowMac::DoGetBestSize() const
1048{
d15694e8 1049 if ( GetPeer() == NULL || GetPeer()->IsUserPane() || IsTopLevel() )
524c47aa
SC
1050 {
1051 return wxWindowBase::DoGetBestSize() ;
1052 }
1053 else
1054 {
1055 wxRect r ;
69ce9cea 1056
d15694e8 1057 GetPeer()->GetBestRect(&r);
524c47aa
SC
1058
1059 if ( r.GetWidth() == 0 && r.GetHeight() == 0 )
1060 {
1061 r.x =
1062 r.y = 0 ;
1063 r.width =
1064 r.height = 16 ;
1065
11fed901 1066#if wxUSE_SCROLLBAR
65391c8f 1067 if ( IsKindOf( CLASSINFO( wxScrollBar ) ) )
524c47aa
SC
1068 {
1069 r.height = 16 ;
1070 }
65391c8f 1071 else
11fed901
SC
1072#endif
1073#if wxUSE_SPINBTN
65391c8f 1074 if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
524c47aa
SC
1075 {
1076 r.height = 24 ;
1077 }
524c47aa 1078 else
65391c8f 1079#endif
524c47aa
SC
1080 {
1081 // return wxWindowBase::DoGetBestSize() ;
1082 }
1083 }
1084
69ce9cea 1085 int bestWidth = r.width + MacGetLeftBorderSize() +
524c47aa 1086 MacGetRightBorderSize();
69ce9cea 1087 int bestHeight = r.height + MacGetTopBorderSize() +
524c47aa
SC
1088 MacGetBottomBorderSize();
1089 if ( bestHeight < 10 )
1090 bestHeight = 13 ;
1091
1092 return wxSize(bestWidth, bestHeight);
1093 }
1094}
1095
1096// set the size of the window: if the dimensions are positive, just use them,
1097// but if any of them is equal to -1, it means that we must find the value for
1098// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1099// which case -1 is a valid value for x and y)
1100//
1101// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1102// the width/height to best suit our contents, otherwise we reuse the current
1103// width/height
1104void wxWindowMac::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1105{
1106 // get the current size and position...
1107 int currentX, currentY;
1108 int currentW, currentH;
1109
1110 GetPosition(&currentX, &currentY);
1111 GetSize(&currentW, &currentH);
1112
1113 // ... and don't do anything (avoiding flicker) if it's already ok
1114 if ( x == currentX && y == currentY &&
1115 width == currentW && height == currentH && ( height != -1 && width != -1 ) )
1116 {
1117 // TODO: REMOVE
1118 MacRepositionScrollBars() ; // we might have a real position shift
1119
e47e063a
RR
1120 if (sizeFlags & wxSIZE_FORCE_EVENT)
1121 {
1122 wxSizeEvent event( wxSize(width,height), GetId() );
1123 event.SetEventObject( this );
1124 HandleWindowEvent( event );
1125 }
1126
524c47aa
SC
1127 return;
1128 }
1129
1130 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1131 {
1132 if ( x == wxDefaultCoord )
1133 x = currentX;
1134 if ( y == wxDefaultCoord )
1135 y = currentY;
1136 }
1137
1138 AdjustForParentClientOrigin( x, y, sizeFlags );
1139
1140 wxSize size = wxDefaultSize;
1141 if ( width == wxDefaultCoord )
1142 {
1143 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
1144 {
1145 size = DoGetBestSize();
1146 width = size.x;
1147 }
1148 else
1149 {
1150 // just take the current one
1151 width = currentW;
1152 }
1153 }
1154
1155 if ( height == wxDefaultCoord )
1156 {
1157 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
1158 {
1159 if ( size.x == wxDefaultCoord )
1160 size = DoGetBestSize();
1161 // else: already called DoGetBestSize() above
1162
1163 height = size.y;
1164 }
1165 else
1166 {
1167 // just take the current one
1168 height = currentH;
1169 }
1170 }
1171
1172 DoMoveWindow( x, y, width, height );
1173}
1174
1175wxPoint wxWindowMac::GetClientAreaOrigin() const
1176{
1177 int left,top,width,height;
d15694e8 1178 GetPeer()->GetContentArea( left , top , width , height);
524c47aa
SC
1179 return wxPoint( left + MacGetLeftBorderSize() , top + MacGetTopBorderSize() );
1180}
1181
1182void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight)
1183{
1184 if ( clientwidth != wxDefaultCoord || clientheight != wxDefaultCoord )
1185 {
1186 int currentclientwidth , currentclientheight ;
1187 int currentwidth , currentheight ;
1188
1189 GetClientSize( &currentclientwidth , &currentclientheight ) ;
1190 GetSize( &currentwidth , &currentheight ) ;
1191
1192 DoSetSize( wxDefaultCoord , wxDefaultCoord , currentwidth + clientwidth - currentclientwidth ,
1193 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
1194 }
1195}
1196
f18b5ee7
SC
1197float wxWindowMac::GetContentScaleFactor() const
1198{
d15694e8 1199 return GetPeer()->GetContentScaleFactor();
f18b5ee7
SC
1200}
1201
524c47aa
SC
1202void wxWindowMac::SetLabel(const wxString& title)
1203{
8c6c5778
VZ
1204 if ( title == m_label )
1205 return;
1206
524c47aa
SC
1207 m_label = title ;
1208
8c6c5778
VZ
1209 InvalidateBestSize();
1210
d15694e8
SC
1211 if ( GetPeer() && GetPeer()->IsOk() )
1212 GetPeer()->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ;
524c47aa
SC
1213
1214 // do not trigger refreshes upon invisible and possible partly created objects
1215 if ( IsShownOnScreen() )
1216 Refresh() ;
1217}
1218
1219wxString wxWindowMac::GetLabel() const
1220{
1221 return m_label ;
1222}
1223
1224bool wxWindowMac::Show(bool show)
1225{
1226 if ( !wxWindowBase::Show(show) )
1227 return false;
1228
d15694e8
SC
1229 if ( GetPeer() )
1230 GetPeer()->SetVisibility( show ) ;
524c47aa 1231
4cc16dcb 1232#ifdef __WXOSX_IPHONE__
c59aa14a 1233 // only when there's no native event support
4cc16dcb
SC
1234 if ( !IsTopLevel() )
1235#endif
1236 {
1237 wxShowEvent eventShow(GetId(), show);
1238 eventShow.SetEventObject(this);
c59aa14a 1239
4cc16dcb
SC
1240 HandleWindowEvent(eventShow);
1241 }
c59aa14a 1242
524c47aa
SC
1243 return true;
1244}
1245
ab9a0b84
VZ
1246bool wxWindowMac::OSXShowWithEffect(bool show,
1247 wxShowEffect effect,
1248 unsigned timeout)
1249{
1250 if ( effect == wxSHOW_EFFECT_NONE ||
d15694e8 1251 !GetPeer() || !GetPeer()->ShowWithEffect(show, effect, timeout) )
ab9a0b84
VZ
1252 return Show(show);
1253
1254 return true;
1255}
1256
524c47aa
SC
1257void wxWindowMac::DoEnable(bool enable)
1258{
d15694e8 1259 GetPeer()->Enable( enable ) ;
c4a7e284 1260 MacInvalidateBorders();
524c47aa
SC
1261}
1262
1263//
1264// status change notifications
1265//
1266
1267void wxWindowMac::MacVisibilityChanged()
1268{
1269}
1270
1271void wxWindowMac::MacHiliteChanged()
1272{
1273}
1274
1275void wxWindowMac::MacEnabledStateChanged()
1276{
d15694e8 1277 OnEnabled( GetPeer()->IsEnabled() );
524c47aa
SC
1278}
1279
1280//
1281// status queries on the inherited window's state
1282//
1283
1284bool wxWindowMac::MacIsReallyEnabled()
1285{
d15694e8 1286 return GetPeer()->IsEnabled() ;
524c47aa
SC
1287}
1288
1289bool wxWindowMac::MacIsReallyHilited()
1290{
1291#if wxOSX_USE_CARBON
d15694e8 1292 return GetPeer()->IsActive();
524c47aa
SC
1293#else
1294 return true; // TODO
1295#endif
1296}
1297
1298int wxWindowMac::GetCharHeight() const
1299{
f55d9f74
SC
1300 wxCoord height;
1301 GetTextExtent( wxT("g") , NULL , &height , NULL , NULL , NULL );
524c47aa 1302
f55d9f74 1303 return height;
524c47aa
SC
1304}
1305
1306int wxWindowMac::GetCharWidth() const
1307{
f55d9f74
SC
1308 wxCoord width;
1309 GetTextExtent( wxT("g") , &width , NULL , NULL , NULL , NULL );
524c47aa 1310
f55d9f74 1311 return width;
524c47aa
SC
1312}
1313
6de70470
VZ
1314void wxWindowMac::DoGetTextExtent(const wxString& str,
1315 int *x, int *y,
1316 int *descent,
1317 int *externalLeading,
1318 const wxFont *theFont) const
524c47aa
SC
1319{
1320 const wxFont *fontToUse = theFont;
1321 wxFont tempFont;
1322 if ( !fontToUse )
1323 {
1324 tempFont = GetFont();
1325 fontToUse = &tempFont;
1326 }
1327
f55d9f74
SC
1328 wxGraphicsContext* ctx = wxGraphicsContext::Create();
1329 ctx->SetFont( *fontToUse, *wxBLACK );
1330
1331 wxDouble h , d , e , w;
1332 ctx->GetTextExtent( str, &w, &h, &d, &e );
69ce9cea 1333
f55d9f74 1334 delete ctx;
69ce9cea 1335
524c47aa 1336 if ( externalLeading )
f55d9f74 1337 *externalLeading = (wxCoord)(e+0.5);
524c47aa 1338 if ( descent )
f55d9f74 1339 *descent = (wxCoord)(d+0.5);
524c47aa 1340 if ( x )
f55d9f74 1341 *x = (wxCoord)(w+0.5);
524c47aa 1342 if ( y )
f55d9f74 1343 *y = (wxCoord)(h+0.5);
524c47aa
SC
1344}
1345
1346/*
1347 * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
1348 * we always intersect with the entire window, not only with the client area
1349 */
1350
1351void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect)
1352{
d15694e8 1353 if ( GetPeer() == NULL )
524c47aa
SC
1354 return ;
1355
1356 if ( !IsShownOnScreen() )
1357 return ;
69ce9cea 1358
d15694e8 1359 GetPeer()->SetNeedsDisplay( rect ) ;
524c47aa
SC
1360}
1361
1362void wxWindowMac::DoFreeze()
1363{
1364#if wxOSX_USE_CARBON
d15694e8
SC
1365 if ( GetPeer() && GetPeer()->IsOk() )
1366 GetPeer()->SetDrawingEnabled( false ) ;
524c47aa
SC
1367#endif
1368}
1369
1370void wxWindowMac::DoThaw()
1371{
1372#if wxOSX_USE_CARBON
d15694e8 1373 if ( GetPeer() && GetPeer()->IsOk() )
524c47aa 1374 {
d15694e8
SC
1375 GetPeer()->SetDrawingEnabled( true ) ;
1376 GetPeer()->InvalidateWithChildren() ;
524c47aa
SC
1377 }
1378#endif
1379}
1380
1381wxWindow *wxGetActiveWindow()
1382{
1383 // actually this is a windows-only concept
1384 return NULL;
1385}
1386
1387// Coordinates relative to the window
1508fcac 1388void wxWindowMac::WarpPointer(int x_pos, int y_pos)
524c47aa 1389{
b2665b86 1390#if wxOSX_USE_COCOA_OR_CARBON
1508fcac
JS
1391 int x = x_pos;
1392 int y = y_pos;
1393 DoClientToScreen(&x, &y);
1394 CGPoint cgpoint = CGPointMake( x, y );
1395 CGWarpMouseCursorPosition( cgpoint );
1396
1397 // At least GTK sends a mouse moved event after WarpMouse
1398 wxMouseEvent event(wxEVT_MOTION);
1399 event.m_x = x_pos;
1400 event.m_y = y_pos;
1401 wxMouseState mState = ::wxGetMouseState();
1402
1403 event.m_altDown = mState.AltDown();
1404 event.m_controlDown = mState.ControlDown();
b2665b86
SC
1405 event.m_leftDown = mState.LeftIsDown();
1406 event.m_middleDown = mState.MiddleIsDown();
1407 event.m_rightDown = mState.RightIsDown();
1508fcac
JS
1408 event.m_metaDown = mState.MetaDown();
1409 event.m_shiftDown = mState.ShiftDown();
1410 event.SetId(GetId());
1411 event.SetEventObject(this);
1412 GetEventHandler()->ProcessEvent(event);
b2665b86 1413#endif
524c47aa
SC
1414}
1415
524c47aa
SC
1416int wxWindowMac::GetScrollPos(int orient) const
1417{
11fed901 1418#if wxUSE_SCROLLBAR
524c47aa
SC
1419 if ( orient == wxHORIZONTAL )
1420 {
1421 if ( m_hScrollBar )
1422 return m_hScrollBar->GetThumbPosition() ;
1423 }
1424 else
1425 {
1426 if ( m_vScrollBar )
1427 return m_vScrollBar->GetThumbPosition() ;
1428 }
11fed901 1429#endif
524c47aa
SC
1430 return 0;
1431}
1432
1433// This now returns the whole range, not just the number
1434// of positions that we can scroll.
1435int wxWindowMac::GetScrollRange(int orient) const
1436{
11fed901 1437#if wxUSE_SCROLLBAR
524c47aa
SC
1438 if ( orient == wxHORIZONTAL )
1439 {
1440 if ( m_hScrollBar )
1441 return m_hScrollBar->GetRange() ;
1442 }
1443 else
1444 {
1445 if ( m_vScrollBar )
1446 return m_vScrollBar->GetRange() ;
1447 }
11fed901 1448#endif
524c47aa
SC
1449 return 0;
1450}
1451
1452int wxWindowMac::GetScrollThumb(int orient) const
1453{
11fed901 1454#if wxUSE_SCROLLBAR
524c47aa
SC
1455 if ( orient == wxHORIZONTAL )
1456 {
1457 if ( m_hScrollBar )
1458 return m_hScrollBar->GetThumbSize() ;
1459 }
1460 else
1461 {
1462 if ( m_vScrollBar )
1463 return m_vScrollBar->GetThumbSize() ;
1464 }
11fed901 1465#endif
524c47aa
SC
1466 return 0;
1467}
1468
1469void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
1470{
11fed901 1471#if wxUSE_SCROLLBAR
524c47aa
SC
1472 if ( orient == wxHORIZONTAL )
1473 {
1474 if ( m_hScrollBar )
1475 m_hScrollBar->SetThumbPosition( pos ) ;
1476 }
1477 else
1478 {
1479 if ( m_vScrollBar )
1480 m_vScrollBar->SetThumbPosition( pos ) ;
1481 }
11fed901 1482#endif
524c47aa
SC
1483}
1484
1485void
1486wxWindowMac::AlwaysShowScrollbars(bool hflag, bool vflag)
1487{
1488 bool needVisibilityUpdate = false;
1489
1490 if ( m_hScrollBarAlwaysShown != hflag )
1491 {
1492 m_hScrollBarAlwaysShown = hflag;
1493 needVisibilityUpdate = true;
1494 }
1495
1496 if ( m_vScrollBarAlwaysShown != vflag )
1497 {
1498 m_vScrollBarAlwaysShown = vflag;
1499 needVisibilityUpdate = true;
1500 }
1501
1502 if ( needVisibilityUpdate )
1503 DoUpdateScrollbarVisibility();
1504}
1505
1506//
1507// we draw borders and grow boxes, are already set up and clipped in the current port / cgContextRef
1508// our own window origin is at leftOrigin/rightOrigin
1509//
1510
1511void wxWindowMac::MacPaintGrowBox()
1512{
1513 if ( IsTopLevel() )
1514 return ;
1515
11fed901 1516#if wxUSE_SCROLLBAR
524c47aa
SC
1517 if ( MacHasScrollBarCorner() )
1518 {
2ae3afa0 1519#if 0
524c47aa
SC
1520 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
1521 wxASSERT( cgContext ) ;
1522
1523 int tx,ty,tw,th;
69ce9cea 1524
d15694e8
SC
1525 GetPeer()->GetSize( tw, th );
1526 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
1527
1528 Rect rect = { ty,tx, ty+th, tx+tw };
1529
1530
1531 int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
1532 CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
524c47aa
SC
1533 CGContextSaveGState( cgContext );
1534
1535 if ( m_backgroundColour.Ok() )
1536 {
1537 CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() );
1538 }
1539 else
1540 {
1541 CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 );
1542 }
1543 CGContextFillRect( cgContext, cgrect );
1544 CGContextRestoreGState( cgContext );
2ae3afa0
JS
1545#else
1546 if (m_growBox)
1547 {
1548 if ( m_backgroundColour.Ok() )
1549 m_growBox->SetBackgroundColour(m_backgroundColour);
1550 else
1551 m_growBox->SetBackgroundColour(*wxWHITE);
1552 }
1553#endif
524c47aa 1554 }
2ae3afa0 1555
11fed901 1556#endif
524c47aa
SC
1557}
1558
1559void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) )
1560{
1561 if ( IsTopLevel() )
1562 return ;
1563
d15694e8 1564 bool hasFocus = GetPeer()->NeedsFocusRect() && HasFocus();
524c47aa
SC
1565
1566 // back to the surrounding frame rectangle
1567 int tx,ty,tw,th;
69ce9cea 1568
d15694e8
SC
1569 GetPeer()->GetSize( tw, th );
1570 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
1571
1572 Rect rect = { ty,tx, ty+th, tx+tw };
1573
1574#if wxOSX_USE_COCOA_OR_CARBON
1575
1576 InsetRect( &rect, -1 , -1 ) ;
1577
1578 {
1579 CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
1580 rect.bottom - rect.top ) ;
1581
524c47aa
SC
1582 CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ;
1583 wxASSERT( cgContext ) ;
1584
d15694e8 1585 if ( GetPeer()->NeedsFrame() )
524c47aa 1586 {
f2f6030e
SC
1587 HIThemeFrameDrawInfo info ;
1588 memset( &info, 0 , sizeof(info) ) ;
1589
1590 info.version = 0 ;
1591 info.kind = 0 ;
1592 info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
1593 info.isFocused = hasFocus ;
1594
1595 if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
1596 {
1597 info.kind = kHIThemeFrameTextFieldSquare ;
1598 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1599 }
1600 else if ( HasFlag(wxSIMPLE_BORDER) )
1601 {
1602 info.kind = kHIThemeFrameListBox ;
1603 HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ;
1604 }
524c47aa 1605 }
69ce9cea 1606
f2f6030e 1607 if ( hasFocus )
524c47aa
SC
1608 {
1609 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
1610 }
524c47aa
SC
1611 }
1612#endif // wxOSX_USE_COCOA_OR_CARBON
1613}
1614
1615void wxWindowMac::RemoveChild( wxWindowBase *child )
1616{
11fed901 1617#if wxUSE_SCROLLBAR
524c47aa
SC
1618 if ( child == m_hScrollBar )
1619 m_hScrollBar = NULL ;
1620 if ( child == m_vScrollBar )
1621 m_vScrollBar = NULL ;
2ae3afa0
JS
1622 if ( child == m_growBox )
1623 m_growBox = NULL ;
11fed901 1624#endif
524c47aa
SC
1625 wxWindowBase::RemoveChild( child ) ;
1626}
1627
1628void wxWindowMac::DoUpdateScrollbarVisibility()
1629{
11fed901 1630#if wxUSE_SCROLLBAR
524c47aa
SC
1631 bool triggerSizeEvent = false;
1632
1633 if ( m_hScrollBar )
1634 {
1635 bool showHScrollBar = m_hScrollBarAlwaysShown || m_hScrollBar->IsNeeded();
1636
1637 if ( m_hScrollBar->IsShown() != showHScrollBar )
1638 {
1639 m_hScrollBar->Show( showHScrollBar );
1640 triggerSizeEvent = true;
1641 }
1642 }
1643
1644 if ( m_vScrollBar)
1645 {
1646 bool showVScrollBar = m_vScrollBarAlwaysShown || m_vScrollBar->IsNeeded();
1647
1648 if ( m_vScrollBar->IsShown() != showVScrollBar )
1649 {
1650 m_vScrollBar->Show( showVScrollBar ) ;
1651 triggerSizeEvent = true;
1652 }
1653 }
1654
1655 MacRepositionScrollBars() ;
1656 if ( triggerSizeEvent )
1657 {
1658 wxSizeEvent event(GetSize(), m_windowId);
1659 event.SetEventObject(this);
1660 HandleWindowEvent(event);
1661 }
11fed901 1662#endif
524c47aa
SC
1663}
1664
1665// New function that will replace some of the above.
1666void wxWindowMac::SetScrollbar(int orient, int pos, int thumb,
1667 int range, bool refresh)
1668{
11fed901 1669#if wxUSE_SCROLLBAR
209a9f58
VZ
1670 // Updating scrollbars when window is being deleted is useless and
1671 // currently results in asserts in client-to-screen coordinates conversion
1672 // code which is used by DoUpdateScrollbarVisibility() so just skip it.
1673 if ( m_isBeingDeleted )
1674 return;
1675
524c47aa
SC
1676 if ( orient == wxHORIZONTAL && m_hScrollBar )
1677 m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1678 else if ( orient == wxVERTICAL && m_vScrollBar )
1679 m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh);
1680
1681 DoUpdateScrollbarVisibility();
11fed901 1682#endif
524c47aa
SC
1683}
1684
1685// Does a physical scroll
1686void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
1687{
1688 if ( dx == 0 && dy == 0 )
1689 return ;
1690
1691 int width , height ;
1692 GetClientSize( &width , &height ) ;
1693
1694 {
1695 wxRect scrollrect( MacGetLeftBorderSize() , MacGetTopBorderSize() , width , height ) ;
1696 if ( rect )
1697 scrollrect.Intersect( *rect ) ;
1698 // as the native control might be not a 0/0 wx window coordinates, we have to offset
1699 scrollrect.Offset( -MacGetLeftBorderSize() , -MacGetTopBorderSize() ) ;
1700
d15694e8 1701 GetPeer()->ScrollRect( &scrollrect, dx, dy );
524c47aa
SC
1702 }
1703
1704 wxWindowMac *child;
1705 int x, y, w, h;
1706 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
1707 {
1708 child = node->GetData();
1709 if (child == NULL)
1710 continue;
82f8ea85 1711
524c47aa
SC
1712 if (child->IsTopLevel())
1713 continue;
c59aa14a 1714
82f8ea85
SC
1715 if ( !IsClientAreaChild(child) )
1716 continue;
524c47aa
SC
1717
1718 child->GetPosition( &x, &y );
1719 child->GetSize( &w, &h );
1720 if (rect)
1721 {
1722 wxRect rc( x, y, w, h );
1723 if (rect->Intersects( rc ))
1724 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1725 }
1726 else
1727 {
1728 child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
1729 }
1730 }
1731}
1732
1733void wxWindowMac::MacOnScroll( wxScrollEvent &event )
1734{
11fed901 1735#if wxUSE_SCROLLBAR
524c47aa
SC
1736 if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar )
1737 {
1738 wxScrollWinEvent wevent;
1739 wevent.SetPosition(event.GetPosition());
1740 wevent.SetOrientation(event.GetOrientation());
1741 wevent.SetEventObject(this);
1742
1743 if (event.GetEventType() == wxEVT_SCROLL_TOP)
1744 wevent.SetEventType( wxEVT_SCROLLWIN_TOP );
1745 else if (event.GetEventType() == wxEVT_SCROLL_BOTTOM)
1746 wevent.SetEventType( wxEVT_SCROLLWIN_BOTTOM );
1747 else if (event.GetEventType() == wxEVT_SCROLL_LINEUP)
1748 wevent.SetEventType( wxEVT_SCROLLWIN_LINEUP );
1749 else if (event.GetEventType() == wxEVT_SCROLL_LINEDOWN)
1750 wevent.SetEventType( wxEVT_SCROLLWIN_LINEDOWN );
1751 else if (event.GetEventType() == wxEVT_SCROLL_PAGEUP)
1752 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEUP );
1753 else if (event.GetEventType() == wxEVT_SCROLL_PAGEDOWN)
1754 wevent.SetEventType( wxEVT_SCROLLWIN_PAGEDOWN );
1755 else if (event.GetEventType() == wxEVT_SCROLL_THUMBTRACK)
1756 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBTRACK );
1757 else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE)
1758 wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE );
1759
1760 HandleWindowEvent(wevent);
1761 }
11fed901 1762#endif
524c47aa
SC
1763}
1764
524c47aa
SC
1765wxWindow *wxWindowBase::DoFindFocus()
1766{
f06e0fea 1767 return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus());
524c47aa
SC
1768}
1769
524c47aa
SC
1770// Raise the window to the top of the Z order
1771void wxWindowMac::Raise()
1772{
d15694e8 1773 GetPeer()->Raise();
524c47aa
SC
1774}
1775
1776// Lower the window to the bottom of the Z order
1777void wxWindowMac::Lower()
1778{
d15694e8 1779 GetPeer()->Lower();
524c47aa
SC
1780}
1781
1782// static wxWindow *gs_lastWhich = NULL;
1783
1784bool wxWindowMac::MacSetupCursor( const wxPoint& pt )
1785{
1786 // first trigger a set cursor event
1787
1788 wxPoint clientorigin = GetClientAreaOrigin() ;
1789 wxSize clientsize = GetClientSize() ;
1790 wxCursor cursor ;
1791 if ( wxRect2DInt( clientorigin.x , clientorigin.y , clientsize.x , clientsize.y ).Contains( wxPoint2DInt( pt ) ) )
1792 {
1793 wxSetCursorEvent event( pt.x , pt.y );
1794
1795 bool processedEvtSetCursor = HandleWindowEvent(event);
1796 if ( processedEvtSetCursor && event.HasCursor() )
1797 {
1798 cursor = event.GetCursor() ;
1799 }
1800 else
1801 {
1802 // the test for processedEvtSetCursor is here to prevent using m_cursor
1803 // if the user code caught EVT_SET_CURSOR() and returned nothing from
1804 // it - this is a way to say that our cursor shouldn't be used for this
1805 // point
1806 if ( !processedEvtSetCursor && m_cursor.Ok() )
1807 cursor = m_cursor ;
1808
1809 if ( !wxIsBusy() && !GetParent() )
1810 cursor = *wxSTANDARD_CURSOR ;
1811 }
1812
1813 if ( cursor.Ok() )
1814 cursor.MacInstall() ;
1815 }
1816
1817 return cursor.Ok() ;
1818}
1819
1820wxString wxWindowMac::MacGetToolTipString( wxPoint &WXUNUSED(pt) )
1821{
1822#if wxUSE_TOOLTIPS
1823 if ( m_tooltip )
1824 return m_tooltip->GetTip() ;
1825#endif
1826
1827 return wxEmptyString ;
1828}
1829
1830void wxWindowMac::ClearBackground()
1831{
1832 Refresh() ;
1833 Update() ;
1834}
1835
1836void wxWindowMac::Update()
1837{
1838 wxNonOwnedWindow* top = MacGetTopLevelWindow();
1839 if (top)
1840 top->Update() ;
1841}
1842
1843wxNonOwnedWindow* wxWindowMac::MacGetTopLevelWindow() const
1844{
1845 wxWindowMac *iter = (wxWindowMac*)this ;
1846
1847 while ( iter )
1848 {
1849 if ( iter->IsTopLevel() )
1850 {
1851 wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow);
1852 if ( toplevel )
1853 return toplevel;
1854#if wxUSE_POPUPWIN
1855 wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow);
1856 if ( popupwin )
1857 return popupwin;
1858#endif
1859 }
1860 iter = iter->GetParent() ;
1861 }
1862
1863 return NULL ;
1864}
1865
1866const wxRect& wxWindowMac::MacGetClippedClientRect() const
1867{
1868 MacUpdateClippedRects() ;
1869
1870 return m_cachedClippedClientRect ;
1871}
1872
1873const wxRect& wxWindowMac::MacGetClippedRect() const
1874{
1875 MacUpdateClippedRects() ;
1876
1877 return m_cachedClippedRect ;
1878}
1879
1880const wxRect&wxWindowMac:: MacGetClippedRectWithOuterStructure() const
1881{
1882 MacUpdateClippedRects() ;
1883
1884 return m_cachedClippedRectWithOuterStructure ;
1885}
1886
1887const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures )
1888{
1889 static wxRegion emptyrgn ;
1890
1891 if ( !m_isBeingDeleted && IsShownOnScreen() )
1892 {
1893 MacUpdateClippedRects() ;
1894 if ( includeOuterStructures )
1895 return m_cachedClippedRegionWithOuterStructure ;
1896 else
1897 return m_cachedClippedRegion ;
1898 }
1899 else
1900 {
1901 return emptyrgn ;
1902 }
1903}
1904
1905void wxWindowMac::MacUpdateClippedRects() const
1906{
1907#if wxOSX_USE_CARBON
1908 if ( m_cachedClippedRectValid )
1909 return ;
1910
1911 // includeOuterStructures is true if we try to draw somthing like a focus ring etc.
1912 // also a window dc uses this, in this case we only clip in the hierarchy for hard
1913 // borders like a scrollwindow, splitter etc otherwise we end up in a paranoia having
1914 // to add focus borders everywhere
1915
1916 Rect rIncludingOuterStructures ;
1917
1918 int tx,ty,tw,th;
69ce9cea 1919
d15694e8
SC
1920 GetPeer()->GetSize( tw, th );
1921 GetPeer()->GetPosition( tx, ty );
524c47aa
SC
1922
1923 Rect r = { ty,tx, ty+th, tx+tw };
1924
1925 r.left -= MacGetLeftBorderSize() ;
1926 r.top -= MacGetTopBorderSize() ;
1927 r.bottom += MacGetBottomBorderSize() ;
1928 r.right += MacGetRightBorderSize() ;
1929
1930 r.right -= r.left ;
1931 r.bottom -= r.top ;
1932 r.left = 0 ;
1933 r.top = 0 ;
1934
1935 rIncludingOuterStructures = r ;
1936 InsetRect( &rIncludingOuterStructures , -4 , -4 ) ;
1937
1938 wxRect cl = GetClientRect() ;
1939 Rect rClient = { cl.y , cl.x , cl.y + cl.height , cl.x + cl.width } ;
1940
1941 int x , y ;
1942 wxSize size ;
1943 const wxWindow* child = (wxWindow*) this ;
1944 const wxWindow* parent = NULL ;
1945
1946 while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
1947 {
1948 if ( parent->MacIsChildOfClientArea(child) )
1949 {
1950 size = parent->GetClientSize() ;
1951 wxPoint origin = parent->GetClientAreaOrigin() ;
1952 x = origin.x ;
1953 y = origin.y ;
1954 }
1955 else
1956 {
1957 // this will be true for scrollbars, toolbars etc.
1958 size = parent->GetSize() ;
1959 y = parent->MacGetTopBorderSize() ;
1960 x = parent->MacGetLeftBorderSize() ;
1961 size.x -= parent->MacGetLeftBorderSize() + parent->MacGetRightBorderSize() ;
1962 size.y -= parent->MacGetTopBorderSize() + parent->MacGetBottomBorderSize() ;
1963 }
1964
1965 parent->MacWindowToRootWindow( &x, &y ) ;
1966 MacRootWindowToWindow( &x , &y ) ;
1967
1968 Rect rparent = { y , x , y + size.y , x + size.x } ;
1969
1970 // the wxwindow and client rects will always be clipped
1971 SectRect( &r , &rparent , &r ) ;
1972 SectRect( &rClient , &rparent , &rClient ) ;
1973
1974 // the structure only at 'hard' borders
1975 if ( parent->MacClipChildren() ||
1976 ( parent->GetParent() && parent->GetParent()->MacClipGrandChildren() ) )
1977 {
1978 SectRect( &rIncludingOuterStructures , &rparent , &rIncludingOuterStructures ) ;
1979 }
1980
1981 child = parent ;
1982 }
1983
1984 m_cachedClippedRect = wxRect( r.left , r.top , r.right - r.left , r.bottom - r.top ) ;
1985 m_cachedClippedClientRect = wxRect( rClient.left , rClient.top ,
1986 rClient.right - rClient.left , rClient.bottom - rClient.top ) ;
1987 m_cachedClippedRectWithOuterStructure = wxRect(
1988 rIncludingOuterStructures.left , rIncludingOuterStructures.top ,
1989 rIncludingOuterStructures.right - rIncludingOuterStructures.left ,
1990 rIncludingOuterStructures.bottom - rIncludingOuterStructures.top ) ;
1991
1992 m_cachedClippedRegionWithOuterStructure = wxRegion( m_cachedClippedRectWithOuterStructure ) ;
1993 m_cachedClippedRegion = wxRegion( m_cachedClippedRect ) ;
1994 m_cachedClippedClientRegion = wxRegion( m_cachedClippedClientRect ) ;
1995
1996 m_cachedClippedRectValid = true ;
1997#endif
1998}
1999
2000/*
2001 This function must not change the updatergn !
2002 */
5398a2e0 2003bool wxWindowMac::MacDoRedraw( long time )
524c47aa
SC
2004{
2005 bool handled = false ;
69ce9cea 2006
5398a2e0
SC
2007 wxRegion formerUpdateRgn = m_updateRegion;
2008 wxRegion clientUpdateRgn = formerUpdateRgn;
524c47aa 2009
69ce9cea
VZ
2010 const wxRect clientRect = GetClientRect();
2011
2012 clientUpdateRgn.Intersect(clientRect);
2013
5398a2e0 2014 // first send an erase event to the entire update area
69ce9cea 2015 const wxBackgroundStyle bgStyle = GetBackgroundStyle();
6a5594e0 2016 switch ( bgStyle )
524c47aa 2017 {
6a5594e0
VZ
2018 case wxBG_STYLE_ERASE:
2019 case wxBG_STYLE_SYSTEM:
8301a0e8 2020 case wxBG_STYLE_COLOUR:
69ce9cea 2021 {
6a5594e0
VZ
2022 // for the toplevel window this really is the entire area for
2023 // all the others only their client area, otherwise they might
2024 // be drawing with full alpha and eg put blue into the grow-box
2025 // area of a scrolled window (scroll sample)
2026 wxWindowDC dc(this);
2027 if ( IsTopLevel() )
2028 dc.SetDeviceClippingRegion(formerUpdateRgn);
2029 else
2030 dc.SetDeviceClippingRegion(clientUpdateRgn);
2031
2032 if ( bgStyle == wxBG_STYLE_ERASE )
2033 {
2034 wxEraseEvent eevent( GetId(), &dc );
2035 eevent.SetEventObject( this );
2036 if ( ProcessWindowEvent( eevent ) )
2037 break;
2038 }
2039
773809f5 2040 if ( UseBgCol() )
6a5594e0
VZ
2041 {
2042 dc.SetBackground(GetBackgroundColour());
2043 dc.Clear();
2044 }
69ce9cea 2045 }
6a5594e0
VZ
2046 break;
2047
2048 case wxBG_STYLE_PAINT:
4f6bcb83 2049 case wxBG_STYLE_TRANSPARENT:
6a5594e0
VZ
2050 // nothing to do, user-defined EVT_PAINT handler will overwrite the
2051 // entire window client area
2052 break;
2053
2054 default:
2055 wxFAIL_MSG( "unsupported background style" );
5398a2e0 2056 }
524c47aa 2057
82f8ea85
SC
2058 // as this is a full window, shouldn't be necessary anymore
2059 // MacPaintGrowBox();
524c47aa 2060
69ce9cea
VZ
2061 // calculate a client-origin version of the update rgn and set
2062 // m_updateRegion to that
2063 clientUpdateRgn.Offset(-clientRect.GetPosition());
5398a2e0 2064 m_updateRegion = clientUpdateRgn ;
524c47aa 2065
5398a2e0
SC
2066 if ( !m_updateRegion.Empty() )
2067 {
2068 // paint the window itself
524c47aa 2069
45f5bb03 2070 wxPaintEvent event(GetId());
5398a2e0
SC
2071 event.SetTimestamp(time);
2072 event.SetEventObject(this);
2073 handled = HandleWindowEvent(event);
2074 }
524c47aa 2075
5398a2e0
SC
2076 m_updateRegion = formerUpdateRgn;
2077 return handled;
2078}
524c47aa 2079
5398a2e0
SC
2080void wxWindowMac::MacPaintChildrenBorders()
2081{
2082 // now we cannot rely on having its borders drawn by a window itself, as it does not
2083 // get the updateRgn wide enough to always do so, so we do it from the parent
2084 // this would also be the place to draw any custom backgrounds for native controls
2085 // in Composited windowing
2086 wxPoint clientOrigin = GetClientAreaOrigin() ;
524c47aa 2087
5398a2e0
SC
2088 wxWindowMac *child;
2089 int x, y, w, h;
2090 for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext())
2091 {
2092 child = node->GetData();
2093 if (child == NULL)
2094 continue;
11fed901 2095#if wxUSE_SCROLLBAR
5398a2e0
SC
2096 if (child == m_vScrollBar)
2097 continue;
2098 if (child == m_hScrollBar)
2099 continue;
2ae3afa0
JS
2100 if (child == m_growBox)
2101 continue;
11fed901 2102#endif
5398a2e0
SC
2103 if (child->IsTopLevel())
2104 continue;
2105 if (!child->IsShown())
2106 continue;
2107
2108 // only draw those in the update region (add a safety margin of 10 pixels for shadow effects
2109
2110 child->GetPosition( &x, &y );
2111 child->GetSize( &w, &h );
69ce9cea 2112
5398a2e0 2113 if ( m_updateRegion.Contains(clientOrigin.x+x-10, clientOrigin.y+y-10, w+20, h+20) )
524c47aa 2114 {
5398a2e0
SC
2115 // paint custom borders
2116 wxNcPaintEvent eventNc( child->GetId() );
2117 eventNc.SetEventObject( child );
2118 if ( !child->HandleWindowEvent( eventNc ) )
524c47aa 2119 {
5398a2e0 2120 child->MacPaintBorders(0, 0) ;
524c47aa
SC
2121 }
2122 }
2123 }
524c47aa
SC
2124}
2125
2126
2127WXWindow wxWindowMac::MacGetTopLevelWindowRef() const
2128{
69ce9cea 2129 wxNonOwnedWindow* tlw = MacGetTopLevelWindow();
524c47aa
SC
2130 return tlw ? tlw->GetWXWindow() : NULL ;
2131}
2132
2133bool wxWindowMac::MacHasScrollBarCorner() const
2134{
11fed901 2135#if wxUSE_SCROLLBAR
524c47aa
SC
2136 /* Returns whether the scroll bars in a wxScrolledWindow should be
2137 * shortened. Scroll bars should be shortened if either:
2138 *
2139 * - both scroll bars are visible, or
2140 *
2141 * - there is a resize box in the parent frame's corner and this
2142 * window shares the bottom and right edge with the parent
2143 * frame.
2144 */
2145
2146 if ( m_hScrollBar == NULL && m_vScrollBar == NULL )
2147 return false;
2148
2149 if ( ( m_hScrollBar && m_hScrollBar->IsShown() )
2150 && ( m_vScrollBar && m_vScrollBar->IsShown() ) )
2151 {
2152 // Both scroll bars visible
2153 return true;
2154 }
2155 else
2156 {
2157 wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight();
2158
2159 for ( const wxWindow *win = (wxWindow*)this; win; win = win->GetParent() )
2160 {
2161 const wxFrame *frame = wxDynamicCast( win, wxFrame ) ;
2162 if ( frame )
2163 {
2164 if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER )
2165 {
2166 // Parent frame has resize handle
2167 wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight();
2168
2169 // Note: allow for some wiggle room here as wxMac's
2170 // window rect calculations seem to be imprecise
2171 if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2
2172 && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 )
2173 {
2174 // Parent frame has resize handle and shares
2175 // right bottom corner
2176 return true ;
2177 }
2178 else
2179 {
2180 // Parent frame has resize handle but doesn't
2181 // share right bottom corner
2182 return false ;
2183 }
2184 }
2185 else
2186 {
2187 // Parent frame doesn't have resize handle
2188 return false ;
2189 }
2190 }
2191 }
2192
2193 // No parent frame found
2194 return false ;
2195 }
11fed901
SC
2196#else
2197 return false;
2198#endif
524c47aa
SC
2199}
2200
2201void wxWindowMac::MacCreateScrollBars( long style )
2202{
11fed901 2203#if wxUSE_SCROLLBAR
524c47aa
SC
2204 wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
2205
2206 if ( style & ( wxVSCROLL | wxHSCROLL ) )
2207 {
2208 int scrlsize = MAC_SCROLLBAR_SIZE ;
2209 if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
2210 {
2211 scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
2212 }
2213
2214 int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ;
2215 int width, height ;
2216 GetClientSize( &width , &height ) ;
2217
2218 wxPoint vPoint(width - scrlsize, 0) ;
2219 wxSize vSize(scrlsize, height - adjust) ;
2220 wxPoint hPoint(0, height - scrlsize) ;
2221 wxSize hSize(width - adjust, scrlsize) ;
2222
2223 // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
2224 if ( style & wxVSCROLL )
2225 {
2226 m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL);
2227 m_vScrollBar->SetMinSize( wxDefaultSize );
2228 }
2229
2230 if ( style & wxHSCROLL )
2231 {
2232 m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
2233 m_hScrollBar->SetMinSize( wxDefaultSize );
2234 }
2ae3afa0
JS
2235
2236 wxPoint gPoint(width - scrlsize, height - scrlsize);
2237 wxSize gSize(scrlsize, scrlsize);
82f8ea85 2238 m_growBox = new wxBlindPlateWindow((wxWindow *)this, wxID_ANY, gPoint, gSize, 0);
524c47aa
SC
2239 }
2240
2241 // because the create does not take into account the client area origin
2242 // we might have a real position shift
2243 MacRepositionScrollBars() ;
11fed901 2244#endif
524c47aa
SC
2245}
2246
2247bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const
2248{
11fed901
SC
2249 bool result = ((child == NULL)
2250#if wxUSE_SCROLLBAR
2ae3afa0 2251 || ((child != m_hScrollBar) && (child != m_vScrollBar) && (child != m_growBox))
11fed901
SC
2252#endif
2253 );
524c47aa
SC
2254
2255 return result ;
2256}
2257
2258void wxWindowMac::MacRepositionScrollBars()
2259{
11fed901 2260#if wxUSE_SCROLLBAR
524c47aa
SC
2261 if ( !m_hScrollBar && !m_vScrollBar )
2262 return ;
2263
2264 int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
2265 int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ;
2266
2267 // get real client area
2268 int width, height ;
2269 GetSize( &width , &height );
2270
2271 width -= MacGetLeftBorderSize() + MacGetRightBorderSize();
2272 height -= MacGetTopBorderSize() + MacGetBottomBorderSize();
2273
2274 wxPoint vPoint( width - scrlsize, 0 ) ;
2275 wxSize vSize( scrlsize, height - adjust ) ;
2276 wxPoint hPoint( 0 , height - scrlsize ) ;
2277 wxSize hSize( width - adjust, scrlsize ) ;
2278
2279 if ( m_vScrollBar )
2280 m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE );
2281 if ( m_hScrollBar )
2282 m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE );
2ae3afa0
JS
2283 if ( m_growBox )
2284 {
2285 if ( MacHasScrollBarCorner() )
2286 {
2287 m_growBox->SetSize( width - scrlsize, height - scrlsize, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING );
2288 if ( !m_growBox->IsShown() )
2289 m_growBox->Show();
2290 }
2291 else
2292 {
2293 if ( m_growBox->IsShown() )
2294 m_growBox->Hide();
2295 }
2296 }
11fed901 2297#endif
524c47aa
SC
2298}
2299
2300bool wxWindowMac::AcceptsFocus() const
2301{
d15694e8 2302 if ( GetPeer() == NULL || GetPeer()->IsUserPane() )
f06e0fea
SC
2303 return wxWindowBase::AcceptsFocus();
2304 else
d15694e8 2305 return GetPeer()->CanFocus();
524c47aa
SC
2306}
2307
2308void wxWindowMac::MacSuperChangedPosition()
2309{
2310 // only window-absolute structures have to be moved i.e. controls
2311
2312 m_cachedClippedRectValid = false ;
2313
2314 wxWindowMac *child;
2315 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2316 while ( node )
2317 {
2318 child = node->GetData();
2319 child->MacSuperChangedPosition() ;
2320
2321 node = node->GetNext();
2322 }
2323}
2324
2325void wxWindowMac::MacTopLevelWindowChangedPosition()
2326{
2327 // only screen-absolute structures have to be moved i.e. glcanvas
2328
2329 wxWindowMac *child;
2330 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2331 while ( node )
2332 {
2333 child = node->GetData();
2334 child->MacTopLevelWindowChangedPosition() ;
2335
2336 node = node->GetNext();
2337 }
2338}
2339
54ea2834 2340long wxWindowMac::MacGetWXBorderSize() const
524c47aa
SC
2341{
2342 if ( IsTopLevel() )
2343 return 0 ;
2344
2345 SInt32 border = 0 ;
2346
d15694e8 2347 if ( GetPeer() && GetPeer()->NeedsFrame() )
524c47aa 2348 {
f2f6030e
SC
2349 if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER))
2350 {
524c47aa 2351#if wxOSX_USE_COCOA_OR_CARBON
f2f6030e
SC
2352 // this metric is only the 'outset' outside the simple frame rect
2353 GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ;
2354 border += 1;
524c47aa 2355#else
f2f6030e 2356 border += 2;
524c47aa 2357#endif
f2f6030e
SC
2358 }
2359 else if (HasFlag(wxSIMPLE_BORDER))
2360 {
524c47aa 2361#if wxOSX_USE_COCOA_OR_CARBON
f2f6030e
SC
2362 // this metric is only the 'outset' outside the simple frame rect
2363 GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
2364 border += 1;
524c47aa 2365#else
f2f6030e 2366 border += 1;
524c47aa 2367#endif
f2f6030e 2368 }
524c47aa
SC
2369 }
2370
2371 return border ;
2372}
2373
54ea2834
SC
2374long wxWindowMac::MacGetLeftBorderSize() const
2375{
2376 // the wx borders are all symmetric in mac themes
2377 long border = MacGetWXBorderSize() ;
2378
d15694e8 2379 if ( GetPeer() )
54ea2834
SC
2380 {
2381 int left, top, right, bottom;
d15694e8 2382 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2383 border -= left;
2384 }
2385
2386 return border;
2387}
2388
2389
524c47aa
SC
2390long wxWindowMac::MacGetRightBorderSize() const
2391{
54ea2834
SC
2392 // the wx borders are all symmetric in mac themes
2393 long border = MacGetWXBorderSize() ;
2394
d15694e8 2395 if ( GetPeer() )
54ea2834
SC
2396 {
2397 int left, top, right, bottom;
d15694e8 2398 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2399 border -= right;
2400 }
2401
2402 return border;
524c47aa
SC
2403}
2404
2405long wxWindowMac::MacGetTopBorderSize() const
2406{
54ea2834
SC
2407 // the wx borders are all symmetric in mac themes
2408 long border = MacGetWXBorderSize() ;
2409
d15694e8 2410 if ( GetPeer() )
54ea2834
SC
2411 {
2412 int left, top, right, bottom;
d15694e8 2413 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2414 border -= top;
2415 }
2416
2417 return border;
524c47aa
SC
2418}
2419
2420long wxWindowMac::MacGetBottomBorderSize() const
2421{
54ea2834
SC
2422 // the wx borders are all symmetric in mac themes
2423 long border = MacGetWXBorderSize() ;
2424
d15694e8 2425 if ( GetPeer() )
54ea2834
SC
2426 {
2427 int left, top, right, bottom;
d15694e8 2428 GetPeer()->GetLayoutInset( left, top, right, bottom );
54ea2834
SC
2429 border -= bottom;
2430 }
2431
2432 return border;
524c47aa
SC
2433}
2434
2435long wxWindowMac::MacRemoveBordersFromStyle( long style )
2436{
2437 return style & ~wxBORDER_MASK ;
2438}
2439
2440// Find the wxWindowMac at the current mouse position, returning the mouse
2441// position.
2442wxWindow * wxFindWindowAtPointer( wxPoint& pt )
2443{
2444 pt = wxGetMousePosition();
2445 wxWindowMac* found = wxFindWindowAtPoint(pt);
2446
2447 return (wxWindow*) found;
2448}
2449
2450// Get the current mouse position.
2451wxPoint wxGetMousePosition()
2452{
2453 int x, y;
2454
2455 wxGetMousePosition( &x, &y );
2456
2457 return wxPoint(x, y);
2458}
2459
2460void wxWindowMac::OnMouseEvent( wxMouseEvent &event )
2461{
2462 if ( event.GetEventType() == wxEVT_RIGHT_DOWN )
2463 {
2464 // copied from wxGTK : CS
2465 // VZ: shouldn't we move this to base class then?
2466
2467 // generate a "context menu" event: this is similar to wxEVT_RIGHT_DOWN
2468 // except that:
2469 //
2470 // (a) it's a command event and so is propagated to the parent
2471 // (b) under MSW it can be generated from kbd too
2472 // (c) it uses screen coords (because of (a))
2473 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU,
2474 this->GetId(),
2475 this->ClientToScreen(event.GetPosition()));
2476 evtCtx.SetEventObject(this);
2477 if ( ! HandleWindowEvent(evtCtx) )
2478 event.Skip() ;
2479 }
2480 else
2481 {
2482 event.Skip() ;
2483 }
2484}
2485
19c7ac3d 2486void wxWindowMac::TriggerScrollEvent( wxEventType WXUNUSED(scrollEvent) )
524c47aa
SC
2487{
2488}
2489
2490Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
2491{
2492 int x, y, w, h ;
2493
2494 window->MacGetBoundsForControl( pos , size , x , y, w, h , adjustForOrigin ) ;
2495 Rect bounds = { y, x, y + h, x + w };
2496
2497 return bounds ;
2498}
2499
0faf03bf 2500bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec) )
524c47aa
SC
2501{
2502 return false;
2503}
2504
2505wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF event )
2506{
2507#if wxOSX_USE_COCOA_OR_CARBON
4eb5a0ec 2508 if ( OSXHandleClicked( GetEventTime((EventRef)event) ) )
524c47aa 2509 return noErr;
69ce9cea 2510
524c47aa
SC
2511 return eventNotHandledErr ;
2512#else
2513 return 0;
2514#endif
2515}
2516
2517bool wxWindowMac::Reparent(wxWindowBase *newParentBase)
2518{
2519 wxWindowMac *newParent = (wxWindowMac *)newParentBase;
2520 if ( !wxWindowBase::Reparent(newParent) )
2521 return false;
2522
d15694e8
SC
2523 GetPeer()->RemoveFromParent();
2524 GetPeer()->Embed( GetParent()->GetPeer() );
b80fdc02
JS
2525
2526 MacChildAdded();
524c47aa
SC
2527 return true;
2528}
2529
2530bool wxWindowMac::SetTransparent(wxByte alpha)
2531{
2532 SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
2533
2534 if ( alpha != m_macAlpha )
2535 {
2536 m_macAlpha = alpha ;
2537 Refresh() ;
2538 }
2539 return true ;
2540}
2541
2542
2543bool wxWindowMac::CanSetTransparent()
2544{
2545 return true ;
2546}
2547
2548wxByte wxWindowMac::GetTransparent() const
2549{
2550 return m_macAlpha ;
2551}
2552
2553bool wxWindowMac::IsShownOnScreen() const
2554{
d15694e8 2555 if ( GetPeer() && GetPeer()->IsOk() )
524c47aa 2556 {
d15694e8 2557 bool peerVis = GetPeer()->IsVisible();
524c47aa
SC
2558 bool wxVis = wxWindowBase::IsShownOnScreen();
2559 if( peerVis != wxVis )
2560 {
2561 // CS : put a breakpoint here to investigate differences
2562 // between native an wx visibilities
2563 // the only place where I've encountered them until now
2564 // are the hiding/showing sequences where the vis-changed event is
2565 // first sent to the innermost control, while wx does things
2566 // from the outmost control
2567 wxVis = wxWindowBase::IsShownOnScreen();
2568 return wxVis;
2569 }
2570
d15694e8 2571 return GetPeer()->IsVisible();
524c47aa
SC
2572 }
2573 return wxWindowBase::IsShownOnScreen();
2574}
2575
4eb5a0ec 2576bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event )
19c7ac3d 2577{
ba950d44
SC
2578 bool handled = false;
2579
2580 // moved the ordinary key event sending AFTER the accel evaluation
19c7ac3d
SC
2581
2582#if wxUSE_ACCEL
2583 if ( !handled && event.GetEventType() == wxEVT_KEY_DOWN)
2584 {
2585 wxWindow *ancestor = this;
2586 while (ancestor)
2587 {
2588 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
2589 if (command != -1)
2590 {
2591 wxEvtHandler * const handler = ancestor->GetEventHandler();
2592
2593 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
2594 handled = handler->ProcessEvent( command_event );
2595
2596 if ( !handled )
2597 {
2598 // accelerators can also be used with buttons, try them too
2599 command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED);
2600 handled = handler->ProcessEvent( command_event );
2601 }
2602
2603 break;
2604 }
2605
2606 if (ancestor->IsTopLevel())
2607 break;
2608
2609 ancestor = ancestor->GetParent();
2610 }
2611 }
2612#endif // wxUSE_ACCEL
ba950d44
SC
2613
2614 if ( !handled )
2615 {
2616 handled = HandleWindowEvent( event ) ;
2617 if ( handled && event.GetSkipped() )
2618 handled = false ;
2619 }
19c7ac3d
SC
2620
2621 return handled ;
2622}
2623
524c47aa 2624//
69ce9cea 2625// wxWidgetImpl
524c47aa
SC
2626//
2627
f55d9f74
SC
2628WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap);
2629
2630static MacControlMap wxWinMacControlList;
2631
2632wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl )
2633{
2634 wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl );
2635 if ( impl )
2636 return impl->GetWXPeer();
69ce9cea 2637
f55d9f74
SC
2638 return NULL;
2639}
2640
2641wxWidgetImpl *wxWidgetImpl::FindFromWXWidget(WXWidget inControl )
2642{
2643 MacControlMap::iterator node = wxWinMacControlList.find(inControl);
2644
2645 return (node == wxWinMacControlList.end()) ? NULL : node->second;
2646}
2647
2648void wxWidgetImpl::Associate(WXWidget inControl, wxWidgetImpl *impl)
2649{
2650 // adding NULL ControlRef is (first) surely a result of an error and
2651 // (secondly) breaks native event processing
2652 wxCHECK_RET( inControl != (WXWidget) NULL, wxT("attempt to add a NULL WXWidget to control map") );
2653
2654 wxWinMacControlList[inControl] = impl;
2655}
2656
2657void wxWidgetImpl::RemoveAssociations(wxWidgetImpl* impl)
2658{
2659 // iterate over all the elements in the class
2660 // is the iterator stable ? as we might have two associations pointing to the same wxWindow
2661 // we should go on...
2662
2663 bool found = true ;
2664 while ( found )
2665 {
2666 found = false ;
2667 MacControlMap::iterator it;
2668 for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
2669 {
2670 if ( it->second == impl )
2671 {
2672 wxWinMacControlList.erase(it);
2673 found = true ;
2674 break;
2675 }
2676 }
2677 }
2678}
2679
524c47aa
SC
2680IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
2681
415f4a01 2682wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl, bool isUserPane )
524c47aa
SC
2683{
2684 Init();
2685 m_isRootControl = isRootControl;
415f4a01 2686 m_isUserPane = isUserPane;
524c47aa 2687 m_wxPeer = peer;
809020fc 2688 m_shouldSendEvents = true;
524c47aa
SC
2689}
2690
2691wxWidgetImpl::wxWidgetImpl()
2692{
2693 Init();
2694}
2695
2696wxWidgetImpl::~wxWidgetImpl()
2697{
2698}
2699
2700void wxWidgetImpl::Init()
2701{
2702 m_isRootControl = false;
2703 m_wxPeer = NULL;
2704 m_needsFocusRect = false;
f2f6030e 2705 m_needsFrame = true;
524c47aa
SC
2706}
2707
2708void wxWidgetImpl::SetNeedsFocusRect( bool needs )
2709{
2710 m_needsFocusRect = needs;
2711}
2712
2713bool wxWidgetImpl::NeedsFocusRect() const
2714{
2715 return m_needsFocusRect;
2716}
2717
f2f6030e
SC
2718void wxWidgetImpl::SetNeedsFrame( bool needs )
2719{
2720 m_needsFrame = needs;
2721}
2722
2723bool wxWidgetImpl::NeedsFrame() const
2724{
2725 return m_needsFrame;
2726}