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