No real changes, just fix a typo in comments and documentation.
[wxWidgets.git] / src / common / wincmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
5 // Modified by:
6 // Created: 13/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #include "wx/log.h"
30 #include "wx/intl.h"
31 #include "wx/frame.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/msgout.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
45 #include "wx/scrolbar.h"
46 #include "wx/layout.h"
47 #include "wx/sizer.h"
48 #include "wx/menu.h"
49 #endif //WX_PRECOMP
50
51 #if wxUSE_DRAG_AND_DROP
52 #include "wx/dnd.h"
53 #endif // wxUSE_DRAG_AND_DROP
54
55 #if wxUSE_ACCESSIBILITY
56 #include "wx/access.h"
57 #endif
58
59 #if wxUSE_HELP
60 #include "wx/cshelp.h"
61 #endif // wxUSE_HELP
62
63 #if wxUSE_TOOLTIPS
64 #include "wx/tooltip.h"
65 #endif // wxUSE_TOOLTIPS
66
67 #if wxUSE_CARET
68 #include "wx/caret.h"
69 #endif // wxUSE_CARET
70
71 #if wxUSE_SYSTEM_OPTIONS
72 #include "wx/sysopt.h"
73 #endif
74
75 #include "wx/platinfo.h"
76
77 // Windows List
78 WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
79
80 // globals
81 #if wxUSE_MENUS
82 wxMenu *wxCurrentPopupMenu = NULL;
83 #endif // wxUSE_MENUS
84
85 // ----------------------------------------------------------------------------
86 // static data
87 // ----------------------------------------------------------------------------
88
89
90 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
91
92 // ----------------------------------------------------------------------------
93 // event table
94 // ----------------------------------------------------------------------------
95
96 BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
97 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
98 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
99 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
100
101 #if wxUSE_HELP
102 EVT_HELP(wxID_ANY, wxWindowBase::OnHelp)
103 #endif // wxUSE_HELP
104
105 EVT_SIZE(wxWindowBase::InternalOnSize)
106 END_EVENT_TABLE()
107
108 // ============================================================================
109 // implementation of the common functionality of the wxWindow class
110 // ============================================================================
111
112 // ----------------------------------------------------------------------------
113 // initialization
114 // ----------------------------------------------------------------------------
115
116 // the default initialization
117 wxWindowBase::wxWindowBase()
118 {
119 // no window yet, no parent nor children
120 m_parent = NULL;
121 m_windowId = wxID_ANY;
122
123 // no constraints on the minimal window size
124 m_minWidth =
125 m_maxWidth = wxDefaultCoord;
126 m_minHeight =
127 m_maxHeight = wxDefaultCoord;
128
129 // invalidiated cache value
130 m_bestSizeCache = wxDefaultSize;
131
132 // window are created enabled and visible by default
133 m_isShown =
134 m_isEnabled = true;
135
136 // the default event handler is just this window
137 m_eventHandler = this;
138
139 #if wxUSE_VALIDATORS
140 // no validator
141 m_windowValidator = NULL;
142 #endif // wxUSE_VALIDATORS
143
144 // the colours/fonts are default for now, so leave m_font,
145 // m_backgroundColour and m_foregroundColour uninitialized and set those
146 m_hasBgCol =
147 m_hasFgCol =
148 m_hasFont = false;
149 m_inheritBgCol =
150 m_inheritFgCol =
151 m_inheritFont = false;
152
153 // no style bits
154 m_exStyle =
155 m_windowStyle = 0;
156
157 m_backgroundStyle = wxBG_STYLE_ERASE;
158
159 #if wxUSE_CONSTRAINTS
160 // no constraints whatsoever
161 m_constraints = NULL;
162 m_constraintsInvolvedIn = NULL;
163 #endif // wxUSE_CONSTRAINTS
164
165 m_windowSizer = NULL;
166 m_containingSizer = NULL;
167 m_autoLayout = false;
168
169 #if wxUSE_DRAG_AND_DROP
170 m_dropTarget = NULL;
171 #endif // wxUSE_DRAG_AND_DROP
172
173 #if wxUSE_TOOLTIPS
174 m_tooltip = NULL;
175 #endif // wxUSE_TOOLTIPS
176
177 #if wxUSE_CARET
178 m_caret = NULL;
179 #endif // wxUSE_CARET
180
181 #if wxUSE_PALETTE
182 m_hasCustomPalette = false;
183 #endif // wxUSE_PALETTE
184
185 #if wxUSE_ACCESSIBILITY
186 m_accessible = NULL;
187 #endif
188
189 m_virtualSize = wxDefaultSize;
190
191 m_scrollHelper = NULL;
192
193 m_windowVariant = wxWINDOW_VARIANT_NORMAL;
194 #if wxUSE_SYSTEM_OPTIONS
195 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) )
196 {
197 m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ;
198 }
199 #endif
200
201 // Whether we're using the current theme for this window (wxGTK only for now)
202 m_themeEnabled = false;
203
204 // This is set to true by SendDestroyEvent() which should be called by the
205 // most derived class to ensure that the destruction event is sent as soon
206 // as possible to allow its handlers to still see the undestroyed window
207 m_isBeingDeleted = false;
208
209 m_freezeCount = 0;
210 }
211
212 // common part of window creation process
213 bool wxWindowBase::CreateBase(wxWindowBase *parent,
214 wxWindowID id,
215 const wxPoint& WXUNUSED(pos),
216 const wxSize& size,
217 long style,
218 const wxString& name)
219 {
220 // ids are limited to 16 bits under MSW so if you care about portability,
221 // it's not a good idea to use ids out of this range (and negative ids are
222 // reserved for wxWidgets own usage)
223 wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767) ||
224 (id >= wxID_AUTO_LOWEST && id <= wxID_AUTO_HIGHEST),
225 wxT("invalid id value") );
226
227 // generate a new id if the user doesn't care about it
228 if ( id == wxID_ANY )
229 {
230 m_windowId = NewControlId();
231 }
232 else // valid id specified
233 {
234 m_windowId = id;
235 }
236
237 // don't use SetWindowStyleFlag() here, this function should only be called
238 // to change the flag after creation as it tries to reflect the changes in
239 // flags by updating the window dynamically and we don't need this here
240 m_windowStyle = style;
241
242 // assume the user doesn't want this window to shrink beneath its initial
243 // size, this worked like this in wxWidgets 2.8 and before and generally
244 // often makes sense for child windows (for top level ones it definitely
245 // does not as the user should be able to resize the window)
246 //
247 // note that we can't use IsTopLevel() from ctor
248 if ( size != wxDefaultSize && !wxTopLevelWindows.Find((wxWindow *)this) )
249 SetMinSize(size);
250
251 SetName(name);
252 SetParent(parent);
253
254 return true;
255 }
256
257 bool wxWindowBase::CreateBase(wxWindowBase *parent,
258 wxWindowID id,
259 const wxPoint& pos,
260 const wxSize& size,
261 long style,
262 const wxValidator& wxVALIDATOR_PARAM(validator),
263 const wxString& name)
264 {
265 if ( !CreateBase(parent, id, pos, size, style, name) )
266 return false;
267
268 #if wxUSE_VALIDATORS
269 SetValidator(validator);
270 #endif // wxUSE_VALIDATORS
271
272 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
273 // have it too - like this it's possible to set it only in the top level
274 // dialog/frame and all children will inherit it by defult
275 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
276 {
277 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
278 }
279
280 return true;
281 }
282
283 bool wxWindowBase::ToggleWindowStyle(int flag)
284 {
285 wxASSERT_MSG( flag, wxT("flags with 0 value can't be toggled") );
286
287 bool rc;
288 long style = GetWindowStyleFlag();
289 if ( style & flag )
290 {
291 style &= ~flag;
292 rc = false;
293 }
294 else // currently off
295 {
296 style |= flag;
297 rc = true;
298 }
299
300 SetWindowStyleFlag(style);
301
302 return rc;
303 }
304
305 // ----------------------------------------------------------------------------
306 // destruction
307 // ----------------------------------------------------------------------------
308
309 // common clean up
310 wxWindowBase::~wxWindowBase()
311 {
312 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
313
314 // FIXME if these 2 cases result from programming errors in the user code
315 // we should probably assert here instead of silently fixing them
316
317 // Just in case the window has been Closed, but we're then deleting
318 // immediately: don't leave dangling pointers.
319 wxPendingDelete.DeleteObject(this);
320
321 // Just in case we've loaded a top-level window via LoadNativeDialog but
322 // we weren't a dialog class
323 wxTopLevelWindows.DeleteObject((wxWindow*)this);
324
325 // Any additional event handlers should be popped before the window is
326 // deleted as otherwise the last handler will be left with a dangling
327 // pointer to this window result in a difficult to diagnose crash later on.
328 wxASSERT_MSG( GetEventHandler() == this,
329 wxT("any pushed event handlers must have been removed") );
330
331 #if wxUSE_MENUS
332 // The associated popup menu can still be alive, disassociate from it in
333 // this case
334 if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetInvokingWindow() == this )
335 wxCurrentPopupMenu->SetInvokingWindow(NULL);
336 #endif // wxUSE_MENUS
337
338 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
339
340 // notify the parent about this window destruction
341 if ( m_parent )
342 m_parent->RemoveChild(this);
343
344 #if wxUSE_CARET
345 delete m_caret;
346 #endif // wxUSE_CARET
347
348 #if wxUSE_VALIDATORS
349 delete m_windowValidator;
350 #endif // wxUSE_VALIDATORS
351
352 #if wxUSE_CONSTRAINTS
353 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
354 // at deleted windows as they delete themselves.
355 DeleteRelatedConstraints();
356
357 if ( m_constraints )
358 {
359 // This removes any dangling pointers to this window in other windows'
360 // constraintsInvolvedIn lists.
361 UnsetConstraints(m_constraints);
362 delete m_constraints;
363 m_constraints = NULL;
364 }
365 #endif // wxUSE_CONSTRAINTS
366
367 if ( m_containingSizer )
368 m_containingSizer->Detach( (wxWindow*)this );
369
370 delete m_windowSizer;
371
372 #if wxUSE_DRAG_AND_DROP
373 delete m_dropTarget;
374 #endif // wxUSE_DRAG_AND_DROP
375
376 #if wxUSE_TOOLTIPS
377 delete m_tooltip;
378 #endif // wxUSE_TOOLTIPS
379
380 #if wxUSE_ACCESSIBILITY
381 delete m_accessible;
382 #endif
383
384 #if wxUSE_HELP
385 // NB: this has to be called unconditionally, because we don't know
386 // whether this window has associated help text or not
387 wxHelpProvider *helpProvider = wxHelpProvider::Get();
388 if ( helpProvider )
389 helpProvider->RemoveHelp(this);
390 #endif
391 }
392
393 bool wxWindowBase::IsBeingDeleted() const
394 {
395 return m_isBeingDeleted ||
396 (!IsTopLevel() && m_parent && m_parent->IsBeingDeleted());
397 }
398
399 void wxWindowBase::SendDestroyEvent()
400 {
401 if ( m_isBeingDeleted )
402 {
403 // we could have been already called from a more derived class dtor,
404 // e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
405 // should be simply ignored
406 return;
407 }
408
409 m_isBeingDeleted = true;
410
411 wxWindowDestroyEvent event;
412 event.SetEventObject(this);
413 event.SetId(GetId());
414 GetEventHandler()->ProcessEvent(event);
415 }
416
417 bool wxWindowBase::Destroy()
418 {
419 SendDestroyEvent();
420
421 delete this;
422
423 return true;
424 }
425
426 bool wxWindowBase::Close(bool force)
427 {
428 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
429 event.SetEventObject(this);
430 event.SetCanVeto(!force);
431
432 // return false if window wasn't closed because the application vetoed the
433 // close event
434 return HandleWindowEvent(event) && !event.GetVeto();
435 }
436
437 bool wxWindowBase::DestroyChildren()
438 {
439 wxWindowList::compatibility_iterator node;
440 for ( ;; )
441 {
442 // we iterate until the list becomes empty
443 node = GetChildren().GetFirst();
444 if ( !node )
445 break;
446
447 wxWindow *child = node->GetData();
448
449 // note that we really want to delete it immediately so don't call the
450 // possible overridden Destroy() version which might not delete the
451 // child immediately resulting in problems with our (top level) child
452 // outliving its parent
453 child->wxWindowBase::Destroy();
454
455 wxASSERT_MSG( !GetChildren().Find(child),
456 wxT("child didn't remove itself using RemoveChild()") );
457 }
458
459 return true;
460 }
461
462 // ----------------------------------------------------------------------------
463 // size/position related methods
464 // ----------------------------------------------------------------------------
465
466 // centre the window with respect to its parent in either (or both) directions
467 void wxWindowBase::DoCentre(int dir)
468 {
469 wxCHECK_RET( !(dir & wxCENTRE_ON_SCREEN) && GetParent(),
470 wxT("this method only implements centering child windows") );
471
472 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir));
473 }
474
475 // fits the window around the children
476 void wxWindowBase::Fit()
477 {
478 if ( !GetChildren().empty() )
479 {
480 SetSize(GetBestSize());
481 }
482 //else: do nothing if we have no children
483 }
484
485 // fits virtual size (ie. scrolled area etc.) around children
486 void wxWindowBase::FitInside()
487 {
488 if ( GetChildren().GetCount() > 0 )
489 {
490 SetVirtualSize( GetBestVirtualSize() );
491 }
492 }
493
494 // On Mac, scrollbars are explicitly children.
495 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
496 static bool wxHasRealChildren(const wxWindowBase* win)
497 {
498 int realChildCount = 0;
499
500 for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
501 node;
502 node = node->GetNext() )
503 {
504 wxWindow *win = node->GetData();
505 if ( !win->IsTopLevel() && win->IsShown()
506 #if wxUSE_SCROLLBAR
507 && !win->IsKindOf(CLASSINFO(wxScrollBar))
508 #endif
509 )
510 realChildCount ++;
511 }
512 return (realChildCount > 0);
513 }
514 #endif
515
516 void wxWindowBase::InvalidateBestSize()
517 {
518 m_bestSizeCache = wxDefaultSize;
519
520 // parent's best size calculation may depend on its children's
521 // as long as child window we are in is not top level window itself
522 // (because the TLW size is never resized automatically)
523 // so let's invalidate it as well to be safe:
524 if (m_parent && !IsTopLevel())
525 m_parent->InvalidateBestSize();
526 }
527
528 // return the size best suited for the current window
529 wxSize wxWindowBase::DoGetBestSize() const
530 {
531 wxSize best;
532
533 if ( m_windowSizer )
534 {
535 best = m_windowSizer->GetMinSize();
536 }
537 #if wxUSE_CONSTRAINTS
538 else if ( m_constraints )
539 {
540 wxConstCast(this, wxWindowBase)->SatisfyConstraints();
541
542 // our minimal acceptable size is such that all our windows fit inside
543 int maxX = 0,
544 maxY = 0;
545
546 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
547 node;
548 node = node->GetNext() )
549 {
550 wxLayoutConstraints *c = node->GetData()->GetConstraints();
551 if ( !c )
552 {
553 // it's not normal that we have an unconstrained child, but
554 // what can we do about it?
555 continue;
556 }
557
558 int x = c->right.GetValue(),
559 y = c->bottom.GetValue();
560
561 if ( x > maxX )
562 maxX = x;
563
564 if ( y > maxY )
565 maxY = y;
566
567 // TODO: we must calculate the overlaps somehow, otherwise we
568 // will never return a size bigger than the current one :-(
569 }
570
571 best = wxSize(maxX, maxY);
572 }
573 #endif // wxUSE_CONSTRAINTS
574 else if ( !GetChildren().empty()
575 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
576 && wxHasRealChildren(this)
577 #endif
578 )
579 {
580 // our minimal acceptable size is such that all our visible child
581 // windows fit inside
582 int maxX = 0,
583 maxY = 0;
584
585 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
586 node;
587 node = node->GetNext() )
588 {
589 wxWindow *win = node->GetData();
590 if ( win->IsTopLevel()
591 || !win->IsShown()
592 #if wxUSE_STATUSBAR
593 || wxDynamicCast(win, wxStatusBar)
594 #endif // wxUSE_STATUSBAR
595 )
596 {
597 // dialogs and frames lie in different top level windows -
598 // don't deal with them here; as for the status bars, they
599 // don't lie in the client area at all
600 continue;
601 }
602
603 int wx, wy, ww, wh;
604 win->GetPosition(&wx, &wy);
605
606 // if the window hadn't been positioned yet, assume that it is in
607 // the origin
608 if ( wx == wxDefaultCoord )
609 wx = 0;
610 if ( wy == wxDefaultCoord )
611 wy = 0;
612
613 win->GetSize(&ww, &wh);
614 if ( wx + ww > maxX )
615 maxX = wx + ww;
616 if ( wy + wh > maxY )
617 maxY = wy + wh;
618 }
619
620 best = wxSize(maxX, maxY);
621 }
622 else // ! has children
623 {
624 wxSize size = GetMinSize();
625 if ( !size.IsFullySpecified() )
626 {
627 // if the window doesn't define its best size we assume that it can
628 // be arbitrarily small -- usually this is not the case, of course,
629 // but we have no way to know what the limit is, it should really
630 // override DoGetBestClientSize() itself to tell us
631 size.SetDefaults(wxSize(1, 1));
632 }
633
634 // return as-is, unadjusted by the client size difference.
635 return size;
636 }
637
638 // Add any difference between size and client size
639 wxSize diff = GetSize() - GetClientSize();
640 best.x += wxMax(0, diff.x);
641 best.y += wxMax(0, diff.y);
642
643 return best;
644 }
645
646 // helper of GetWindowBorderSize(): as many ports don't implement support for
647 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
648 // fallbacks in this case
649 static int wxGetMetricOrDefault(wxSystemMetric what, const wxWindowBase* win)
650 {
651 int rc = wxSystemSettings::GetMetric(
652 what, static_cast<wxWindow*>(const_cast<wxWindowBase*>(win)));
653 if ( rc == -1 )
654 {
655 switch ( what )
656 {
657 case wxSYS_BORDER_X:
658 case wxSYS_BORDER_Y:
659 // 2D border is by default 1 pixel wide
660 rc = 1;
661 break;
662
663 case wxSYS_EDGE_X:
664 case wxSYS_EDGE_Y:
665 // 3D borders are by default 2 pixels
666 rc = 2;
667 break;
668
669 default:
670 wxFAIL_MSG( wxT("unexpected wxGetMetricOrDefault() argument") );
671 rc = 0;
672 }
673 }
674
675 return rc;
676 }
677
678 wxSize wxWindowBase::GetWindowBorderSize() const
679 {
680 wxSize size;
681
682 switch ( GetBorder() )
683 {
684 case wxBORDER_NONE:
685 // nothing to do, size is already (0, 0)
686 break;
687
688 case wxBORDER_SIMPLE:
689 case wxBORDER_STATIC:
690 size.x = wxGetMetricOrDefault(wxSYS_BORDER_X, this);
691 size.y = wxGetMetricOrDefault(wxSYS_BORDER_Y, this);
692 break;
693
694 case wxBORDER_SUNKEN:
695 case wxBORDER_RAISED:
696 size.x = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X, this),
697 wxGetMetricOrDefault(wxSYS_BORDER_X, this));
698 size.y = wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y, this),
699 wxGetMetricOrDefault(wxSYS_BORDER_Y, this));
700 break;
701
702 case wxBORDER_DOUBLE:
703 size.x = wxGetMetricOrDefault(wxSYS_EDGE_X, this) +
704 wxGetMetricOrDefault(wxSYS_BORDER_X, this);
705 size.y = wxGetMetricOrDefault(wxSYS_EDGE_Y, this) +
706 wxGetMetricOrDefault(wxSYS_BORDER_Y, this);
707 break;
708
709 default:
710 wxFAIL_MSG(wxT("Unknown border style."));
711 break;
712 }
713
714 // we have borders on both sides
715 return size*2;
716 }
717
718 wxSize wxWindowBase::GetEffectiveMinSize() const
719 {
720 // merge the best size with the min size, giving priority to the min size
721 wxSize min = GetMinSize();
722
723 if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
724 {
725 wxSize best = GetBestSize();
726 if (min.x == wxDefaultCoord) min.x = best.x;
727 if (min.y == wxDefaultCoord) min.y = best.y;
728 }
729
730 return min;
731 }
732
733 wxSize wxWindowBase::DoGetBorderSize() const
734 {
735 // there is one case in which we can implement it for all ports easily:
736 // do it as some classes used by both wxUniv and native ports (e.g.
737 // wxGenericStaticText) do override DoGetBestClientSize() and so this
738 // method must work for them and that ensures that it does, at least in
739 // the default case)
740 if ( GetBorder() == wxBORDER_NONE )
741 return wxSize(0, 0);
742
743 wxFAIL_MSG( "must be overridden if called" );
744
745 return wxDefaultSize;
746 }
747
748 wxSize wxWindowBase::GetBestSize() const
749 {
750 if ( !m_windowSizer && m_bestSizeCache.IsFullySpecified() )
751 return m_bestSizeCache;
752
753 // call DoGetBestClientSize() first, if a derived class overrides it wants
754 // it to be used
755 wxSize size = DoGetBestClientSize();
756 if ( size != wxDefaultSize )
757 {
758 size += DoGetBorderSize();
759
760 CacheBestSize(size);
761 return size;
762 }
763
764 return DoGetBestSize();
765 }
766
767 void wxWindowBase::SetMinSize(const wxSize& minSize)
768 {
769 m_minWidth = minSize.x;
770 m_minHeight = minSize.y;
771 }
772
773 void wxWindowBase::SetMaxSize(const wxSize& maxSize)
774 {
775 m_maxWidth = maxSize.x;
776 m_maxHeight = maxSize.y;
777 }
778
779 void wxWindowBase::SetInitialSize(const wxSize& size)
780 {
781 // Set the min size to the size passed in. This will usually either be
782 // wxDefaultSize or the size passed to this window's ctor/Create function.
783 SetMinSize(size);
784
785 // Merge the size with the best size if needed
786 wxSize best = GetEffectiveMinSize();
787
788 // If the current size doesn't match then change it
789 if (GetSize() != best)
790 SetSize(best);
791 }
792
793
794 // by default the origin is not shifted
795 wxPoint wxWindowBase::GetClientAreaOrigin() const
796 {
797 return wxPoint(0,0);
798 }
799
800 wxSize wxWindowBase::ClientToWindowSize(const wxSize& size) const
801 {
802 const wxSize diff(GetSize() - GetClientSize());
803
804 return wxSize(size.x == -1 ? -1 : size.x + diff.x,
805 size.y == -1 ? -1 : size.y + diff.y);
806 }
807
808 wxSize wxWindowBase::WindowToClientSize(const wxSize& size) const
809 {
810 const wxSize diff(GetSize() - GetClientSize());
811
812 return wxSize(size.x == -1 ? -1 : size.x - diff.x,
813 size.y == -1 ? -1 : size.y - diff.y);
814 }
815
816 void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
817 {
818 if ( m_windowVariant != variant )
819 {
820 m_windowVariant = variant;
821
822 DoSetWindowVariant(variant);
823 }
824 }
825
826 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
827 {
828 // adjust the font height to correspond to our new variant (notice that
829 // we're only called if something really changed)
830 wxFont font = GetFont();
831 int size = font.GetPointSize();
832 switch ( variant )
833 {
834 case wxWINDOW_VARIANT_NORMAL:
835 break;
836
837 case wxWINDOW_VARIANT_SMALL:
838 size *= 3;
839 size /= 4;
840 break;
841
842 case wxWINDOW_VARIANT_MINI:
843 size *= 2;
844 size /= 3;
845 break;
846
847 case wxWINDOW_VARIANT_LARGE:
848 size *= 5;
849 size /= 4;
850 break;
851
852 default:
853 wxFAIL_MSG(wxT("unexpected window variant"));
854 break;
855 }
856
857 font.SetPointSize(size);
858 SetFont(font);
859 }
860
861 void wxWindowBase::DoSetSizeHints( int minW, int minH,
862 int maxW, int maxH,
863 int WXUNUSED(incW), int WXUNUSED(incH) )
864 {
865 wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
866 (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
867 wxT("min width/height must be less than max width/height!") );
868
869 m_minWidth = minW;
870 m_maxWidth = maxW;
871 m_minHeight = minH;
872 m_maxHeight = maxH;
873 }
874
875
876 #if WXWIN_COMPATIBILITY_2_8
877 void wxWindowBase::SetVirtualSizeHints(int WXUNUSED(minW), int WXUNUSED(minH),
878 int WXUNUSED(maxW), int WXUNUSED(maxH))
879 {
880 }
881
882 void wxWindowBase::SetVirtualSizeHints(const wxSize& WXUNUSED(minsize),
883 const wxSize& WXUNUSED(maxsize))
884 {
885 }
886 #endif // WXWIN_COMPATIBILITY_2_8
887
888 void wxWindowBase::DoSetVirtualSize( int x, int y )
889 {
890 m_virtualSize = wxSize(x, y);
891 }
892
893 wxSize wxWindowBase::DoGetVirtualSize() const
894 {
895 // we should use the entire client area so if it is greater than our
896 // virtual size, expand it to fit (otherwise if the window is big enough we
897 // wouldn't be using parts of it)
898 wxSize size = GetClientSize();
899 if ( m_virtualSize.x > size.x )
900 size.x = m_virtualSize.x;
901
902 if ( m_virtualSize.y >= size.y )
903 size.y = m_virtualSize.y;
904
905 return size;
906 }
907
908 void wxWindowBase::DoGetScreenPosition(int *x, int *y) const
909 {
910 // screen position is the same as (0, 0) in client coords for non TLWs (and
911 // TLWs override this method)
912 if ( x )
913 *x = 0;
914 if ( y )
915 *y = 0;
916
917 ClientToScreen(x, y);
918 }
919
920 void wxWindowBase::SendSizeEvent(int flags)
921 {
922 wxSizeEvent event(GetSize(), GetId());
923 event.SetEventObject(this);
924 if ( flags & wxSEND_EVENT_POST )
925 wxPostEvent(this, event);
926 else
927 HandleWindowEvent(event);
928 }
929
930 void wxWindowBase::SendSizeEventToParent(int flags)
931 {
932 wxWindow * const parent = GetParent();
933 if ( parent && !parent->IsBeingDeleted() )
934 parent->SendSizeEvent(flags);
935 }
936
937 bool wxWindowBase::HasScrollbar(int orient) const
938 {
939 // if scrolling in the given direction is disabled, we can't have the
940 // corresponding scrollbar no matter what
941 if ( !CanScroll(orient) )
942 return false;
943
944 const wxSize sizeVirt = GetVirtualSize();
945 const wxSize sizeClient = GetClientSize();
946
947 return orient == wxHORIZONTAL ? sizeVirt.x > sizeClient.x
948 : sizeVirt.y > sizeClient.y;
949 }
950
951 // ----------------------------------------------------------------------------
952 // show/hide/enable/disable the window
953 // ----------------------------------------------------------------------------
954
955 bool wxWindowBase::Show(bool show)
956 {
957 if ( show != m_isShown )
958 {
959 m_isShown = show;
960
961 return true;
962 }
963 else
964 {
965 return false;
966 }
967 }
968
969 bool wxWindowBase::IsEnabled() const
970 {
971 return IsThisEnabled() && (IsTopLevel() || !GetParent() || GetParent()->IsEnabled());
972 }
973
974 void wxWindowBase::NotifyWindowOnEnableChange(bool enabled)
975 {
976 #ifndef wxHAS_NATIVE_ENABLED_MANAGEMENT
977 DoEnable(enabled);
978 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
979
980 OnEnabled(enabled);
981
982 // If we are top-level then the logic doesn't apply - otherwise
983 // showing a modal dialog would result in total greying out (and ungreying
984 // out later) of everything which would be really ugly
985 if ( IsTopLevel() )
986 return;
987
988 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
989 node;
990 node = node->GetNext() )
991 {
992 wxWindowBase * const child = node->GetData();
993 if ( !child->IsTopLevel() && child->IsThisEnabled() )
994 child->NotifyWindowOnEnableChange(enabled);
995 }
996 }
997
998 bool wxWindowBase::Enable(bool enable)
999 {
1000 if ( enable == IsThisEnabled() )
1001 return false;
1002
1003 m_isEnabled = enable;
1004
1005 #ifdef wxHAS_NATIVE_ENABLED_MANAGEMENT
1006 DoEnable(enable);
1007 #else // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1008 wxWindowBase * const parent = GetParent();
1009 if( !IsTopLevel() && parent && !parent->IsEnabled() )
1010 {
1011 return true;
1012 }
1013 #endif // !defined(wxHAS_NATIVE_ENABLED_MANAGEMENT)
1014
1015 NotifyWindowOnEnableChange(enable);
1016
1017 return true;
1018 }
1019
1020 bool wxWindowBase::IsShownOnScreen() const
1021 {
1022 // A window is shown on screen if it itself is shown and so are all its
1023 // parents. But if a window is toplevel one, then its always visible on
1024 // screen if IsShown() returns true, even if it has a hidden parent.
1025 return IsShown() &&
1026 (IsTopLevel() || GetParent() == NULL || GetParent()->IsShownOnScreen());
1027 }
1028
1029 // ----------------------------------------------------------------------------
1030 // RTTI
1031 // ----------------------------------------------------------------------------
1032
1033 bool wxWindowBase::IsTopLevel() const
1034 {
1035 return false;
1036 }
1037
1038 // ----------------------------------------------------------------------------
1039 // Freeze/Thaw
1040 // ----------------------------------------------------------------------------
1041
1042 void wxWindowBase::Freeze()
1043 {
1044 if ( !m_freezeCount++ )
1045 {
1046 // physically freeze this window:
1047 DoFreeze();
1048
1049 // and recursively freeze all children:
1050 for ( wxWindowList::iterator i = GetChildren().begin();
1051 i != GetChildren().end(); ++i )
1052 {
1053 wxWindow *child = *i;
1054 if ( child->IsTopLevel() )
1055 continue;
1056
1057 child->Freeze();
1058 }
1059 }
1060 }
1061
1062 void wxWindowBase::Thaw()
1063 {
1064 wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" );
1065
1066 if ( !--m_freezeCount )
1067 {
1068 // recursively thaw all children:
1069 for ( wxWindowList::iterator i = GetChildren().begin();
1070 i != GetChildren().end(); ++i )
1071 {
1072 wxWindow *child = *i;
1073 if ( child->IsTopLevel() )
1074 continue;
1075
1076 child->Thaw();
1077 }
1078
1079 // physically thaw this window:
1080 DoThaw();
1081 }
1082 }
1083
1084 // ----------------------------------------------------------------------------
1085 // reparenting the window
1086 // ----------------------------------------------------------------------------
1087
1088 void wxWindowBase::AddChild(wxWindowBase *child)
1089 {
1090 wxCHECK_RET( child, wxT("can't add a NULL child") );
1091
1092 // this should never happen and it will lead to a crash later if it does
1093 // because RemoveChild() will remove only one node from the children list
1094 // and the other(s) one(s) will be left with dangling pointers in them
1095 wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), wxT("AddChild() called twice") );
1096
1097 GetChildren().Append((wxWindow*)child);
1098 child->SetParent(this);
1099
1100 // adding a child while frozen will assert when thawed, so freeze it as if
1101 // it had been already present when we were frozen
1102 if ( IsFrozen() && !child->IsTopLevel() )
1103 child->Freeze();
1104 }
1105
1106 void wxWindowBase::RemoveChild(wxWindowBase *child)
1107 {
1108 wxCHECK_RET( child, wxT("can't remove a NULL child") );
1109
1110 // removing a child while frozen may result in permanently frozen window
1111 // if used e.g. from Reparent(), so thaw it
1112 //
1113 // NB: IsTopLevel() doesn't return true any more when a TLW child is being
1114 // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
1115 if ( IsFrozen() && !child->IsBeingDeleted() && !child->IsTopLevel() )
1116 child->Thaw();
1117
1118 GetChildren().DeleteObject((wxWindow *)child);
1119 child->SetParent(NULL);
1120 }
1121
1122 bool wxWindowBase::Reparent(wxWindowBase *newParent)
1123 {
1124 wxWindow *oldParent = GetParent();
1125 if ( newParent == oldParent )
1126 {
1127 // nothing done
1128 return false;
1129 }
1130
1131 const bool oldEnabledState = IsEnabled();
1132
1133 // unlink this window from the existing parent.
1134 if ( oldParent )
1135 {
1136 oldParent->RemoveChild(this);
1137 }
1138 else
1139 {
1140 wxTopLevelWindows.DeleteObject((wxWindow *)this);
1141 }
1142
1143 // add it to the new one
1144 if ( newParent )
1145 {
1146 newParent->AddChild(this);
1147 }
1148 else
1149 {
1150 wxTopLevelWindows.Append((wxWindow *)this);
1151 }
1152
1153 // We need to notify window (and its subwindows) if by changing the parent
1154 // we also change our enabled/disabled status.
1155 const bool newEnabledState = IsEnabled();
1156 if ( newEnabledState != oldEnabledState )
1157 {
1158 NotifyWindowOnEnableChange(newEnabledState);
1159 }
1160
1161 return true;
1162 }
1163
1164 // ----------------------------------------------------------------------------
1165 // event handler stuff
1166 // ----------------------------------------------------------------------------
1167
1168 void wxWindowBase::SetEventHandler(wxEvtHandler *handler)
1169 {
1170 wxCHECK_RET(handler != NULL, "SetEventHandler(NULL) called");
1171
1172 m_eventHandler = handler;
1173 }
1174
1175 void wxWindowBase::SetNextHandler(wxEvtHandler *WXUNUSED(handler))
1176 {
1177 // disable wxEvtHandler chain mechanism for wxWindows:
1178 // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
1179
1180 wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1181 }
1182 void wxWindowBase::SetPreviousHandler(wxEvtHandler *WXUNUSED(handler))
1183 {
1184 // we can't simply wxFAIL here as in SetNextHandler: in fact the last
1185 // handler of our stack when is destroyed will be Unlink()ed and thus
1186 // will call this function to update the pointer of this window...
1187
1188 //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
1189 }
1190
1191 void wxWindowBase::PushEventHandler(wxEvtHandler *handlerToPush)
1192 {
1193 wxCHECK_RET( handlerToPush != NULL, "PushEventHandler(NULL) called" );
1194
1195 // the new handler is going to be part of the wxWindow stack of event handlers:
1196 // it can't be part also of an event handler double-linked chain:
1197 wxASSERT_MSG(handlerToPush->IsUnlinked(),
1198 "The handler being pushed in the wxWindow stack shouldn't be part of "
1199 "a wxEvtHandler chain; call Unlink() on it first");
1200
1201 wxEvtHandler *handlerOld = GetEventHandler();
1202 wxCHECK_RET( handlerOld, "an old event handler is NULL?" );
1203
1204 // now use wxEvtHandler double-linked list to implement a stack:
1205 handlerToPush->SetNextHandler(handlerOld);
1206
1207 if (handlerOld != this)
1208 handlerOld->SetPreviousHandler(handlerToPush);
1209
1210 SetEventHandler(handlerToPush);
1211
1212 #if wxDEBUG_LEVEL
1213 // final checks of the operations done above:
1214 wxASSERT_MSG( handlerToPush->GetPreviousHandler() == NULL,
1215 "the first handler of the wxWindow stack should "
1216 "have no previous handlers set" );
1217 wxASSERT_MSG( handlerToPush->GetNextHandler() != NULL,
1218 "the first handler of the wxWindow stack should "
1219 "have non-NULL next handler" );
1220
1221 wxEvtHandler* pLast = handlerToPush;
1222 while ( pLast && pLast != this )
1223 pLast = pLast->GetNextHandler();
1224 wxASSERT_MSG( pLast->GetNextHandler() == NULL,
1225 "the last handler of the wxWindow stack should "
1226 "have this window as next handler" );
1227 #endif // wxDEBUG_LEVEL
1228 }
1229
1230 wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
1231 {
1232 // we need to pop the wxWindow stack, i.e. we need to remove the first handler
1233
1234 wxEvtHandler *firstHandler = GetEventHandler();
1235 wxCHECK_MSG( firstHandler != NULL, NULL, "wxWindow cannot have a NULL event handler" );
1236 wxCHECK_MSG( firstHandler != this, NULL, "cannot pop the wxWindow itself" );
1237 wxCHECK_MSG( firstHandler->GetPreviousHandler() == NULL, NULL,
1238 "the first handler of the wxWindow stack should have no previous handlers set" );
1239
1240 wxEvtHandler *secondHandler = firstHandler->GetNextHandler();
1241 wxCHECK_MSG( secondHandler != NULL, NULL,
1242 "the first handler of the wxWindow stack should have non-NULL next handler" );
1243
1244 firstHandler->SetNextHandler(NULL);
1245 secondHandler->SetPreviousHandler(NULL);
1246
1247 // now firstHandler is completely unlinked; set secondHandler as the new window event handler
1248 SetEventHandler(secondHandler);
1249
1250 if ( deleteHandler )
1251 {
1252 delete firstHandler;
1253 firstHandler = NULL;
1254 }
1255
1256 return firstHandler;
1257 }
1258
1259 bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handlerToRemove)
1260 {
1261 wxCHECK_MSG( handlerToRemove != NULL, false, "RemoveEventHandler(NULL) called" );
1262 wxCHECK_MSG( handlerToRemove != this, false, "Cannot remove the window itself" );
1263
1264 if (handlerToRemove == GetEventHandler())
1265 {
1266 // removing the first event handler is equivalent to "popping" the stack
1267 PopEventHandler(false);
1268 return true;
1269 }
1270
1271 // NOTE: the wxWindow event handler list is always terminated with "this" handler
1272 wxEvtHandler *handlerCur = GetEventHandler()->GetNextHandler();
1273 while ( handlerCur != this )
1274 {
1275 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
1276
1277 if ( handlerCur == handlerToRemove )
1278 {
1279 handlerCur->Unlink();
1280
1281 wxASSERT_MSG( handlerCur != GetEventHandler(),
1282 "the case Remove == Pop should was already handled" );
1283 return true;
1284 }
1285
1286 handlerCur = handlerNext;
1287 }
1288
1289 wxFAIL_MSG( wxT("where has the event handler gone?") );
1290
1291 return false;
1292 }
1293
1294 bool wxWindowBase::HandleWindowEvent(wxEvent& event) const
1295 {
1296 // SafelyProcessEvent() will handle exceptions nicely
1297 return GetEventHandler()->SafelyProcessEvent(event);
1298 }
1299
1300 // ----------------------------------------------------------------------------
1301 // colours, fonts &c
1302 // ----------------------------------------------------------------------------
1303
1304 void wxWindowBase::InheritAttributes()
1305 {
1306 const wxWindowBase * const parent = GetParent();
1307 if ( !parent )
1308 return;
1309
1310 // we only inherit attributes which had been explicitly set for the parent
1311 // which ensures that this only happens if the user really wants it and
1312 // not by default which wouldn't make any sense in modern GUIs where the
1313 // controls don't all use the same fonts (nor colours)
1314 if ( parent->m_inheritFont && !m_hasFont )
1315 SetFont(parent->GetFont());
1316
1317 // in addition, there is a possibility to explicitly forbid inheriting
1318 // colours at each class level by overriding ShouldInheritColours()
1319 if ( ShouldInheritColours() )
1320 {
1321 if ( parent->m_inheritFgCol && !m_hasFgCol )
1322 SetForegroundColour(parent->GetForegroundColour());
1323
1324 // inheriting (solid) background colour is wrong as it totally breaks
1325 // any kind of themed backgrounds
1326 //
1327 // instead, the controls should use the same background as their parent
1328 // (ideally by not drawing it at all)
1329 #if 0
1330 if ( parent->m_inheritBgCol && !m_hasBgCol )
1331 SetBackgroundColour(parent->GetBackgroundColour());
1332 #endif // 0
1333 }
1334 }
1335
1336 /* static */ wxVisualAttributes
1337 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
1338 {
1339 // it is important to return valid values for all attributes from here,
1340 // GetXXX() below rely on this
1341 wxVisualAttributes attrs;
1342 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
1343 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
1344
1345 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1346 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1347 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1348 // colour on other platforms.
1349
1350 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1351 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1352 #else
1353 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1354 #endif
1355 return attrs;
1356 }
1357
1358 wxColour wxWindowBase::GetBackgroundColour() const
1359 {
1360 if ( !m_backgroundColour.IsOk() )
1361 {
1362 wxASSERT_MSG( !m_hasBgCol, wxT("we have invalid explicit bg colour?") );
1363
1364 // get our default background colour
1365 wxColour colBg = GetDefaultAttributes().colBg;
1366
1367 // we must return some valid colour to avoid redoing this every time
1368 // and also to avoid surprising the applications written for older
1369 // wxWidgets versions where GetBackgroundColour() always returned
1370 // something -- so give them something even if it doesn't make sense
1371 // for this window (e.g. it has a themed background)
1372 if ( !colBg.Ok() )
1373 colBg = GetClassDefaultAttributes().colBg;
1374
1375 return colBg;
1376 }
1377 else
1378 return m_backgroundColour;
1379 }
1380
1381 wxColour wxWindowBase::GetForegroundColour() const
1382 {
1383 // logic is the same as above
1384 if ( !m_hasFgCol && !m_foregroundColour.Ok() )
1385 {
1386 wxColour colFg = GetDefaultAttributes().colFg;
1387
1388 if ( !colFg.IsOk() )
1389 colFg = GetClassDefaultAttributes().colFg;
1390
1391 return colFg;
1392 }
1393 else
1394 return m_foregroundColour;
1395 }
1396
1397 bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
1398 {
1399 if ( colour == m_backgroundColour )
1400 return false;
1401
1402 m_hasBgCol = colour.IsOk();
1403
1404 m_inheritBgCol = m_hasBgCol;
1405 m_backgroundColour = colour;
1406 SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
1407 return true;
1408 }
1409
1410 bool wxWindowBase::SetForegroundColour( const wxColour &colour )
1411 {
1412 if (colour == m_foregroundColour )
1413 return false;
1414
1415 m_hasFgCol = colour.IsOk();
1416 m_inheritFgCol = m_hasFgCol;
1417 m_foregroundColour = colour;
1418 SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
1419 return true;
1420 }
1421
1422 bool wxWindowBase::SetCursor(const wxCursor& cursor)
1423 {
1424 // setting an invalid cursor is ok, it means that we don't have any special
1425 // cursor
1426 if ( m_cursor.IsSameAs(cursor) )
1427 {
1428 // no change
1429 return false;
1430 }
1431
1432 m_cursor = cursor;
1433
1434 return true;
1435 }
1436
1437 wxFont wxWindowBase::GetFont() const
1438 {
1439 // logic is the same as in GetBackgroundColour()
1440 if ( !m_font.IsOk() )
1441 {
1442 wxASSERT_MSG( !m_hasFont, wxT("we have invalid explicit font?") );
1443
1444 wxFont font = GetDefaultAttributes().font;
1445 if ( !font.IsOk() )
1446 font = GetClassDefaultAttributes().font;
1447
1448 return font;
1449 }
1450 else
1451 return m_font;
1452 }
1453
1454 bool wxWindowBase::SetFont(const wxFont& font)
1455 {
1456 if ( font == m_font )
1457 {
1458 // no change
1459 return false;
1460 }
1461
1462 m_font = font;
1463 m_hasFont = font.IsOk();
1464 m_inheritFont = m_hasFont;
1465
1466 InvalidateBestSize();
1467
1468 return true;
1469 }
1470
1471 #if wxUSE_PALETTE
1472
1473 void wxWindowBase::SetPalette(const wxPalette& pal)
1474 {
1475 m_hasCustomPalette = true;
1476 m_palette = pal;
1477
1478 // VZ: can anyone explain me what do we do here?
1479 wxWindowDC d((wxWindow *) this);
1480 d.SetPalette(pal);
1481 }
1482
1483 wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
1484 {
1485 wxWindow *win = (wxWindow *)this;
1486 while ( win && !win->HasCustomPalette() )
1487 {
1488 win = win->GetParent();
1489 }
1490
1491 return win;
1492 }
1493
1494 #endif // wxUSE_PALETTE
1495
1496 #if wxUSE_CARET
1497 void wxWindowBase::SetCaret(wxCaret *caret)
1498 {
1499 if ( m_caret )
1500 {
1501 delete m_caret;
1502 }
1503
1504 m_caret = caret;
1505
1506 if ( m_caret )
1507 {
1508 wxASSERT_MSG( m_caret->GetWindow() == this,
1509 wxT("caret should be created associated to this window") );
1510 }
1511 }
1512 #endif // wxUSE_CARET
1513
1514 #if wxUSE_VALIDATORS
1515 // ----------------------------------------------------------------------------
1516 // validators
1517 // ----------------------------------------------------------------------------
1518
1519 void wxWindowBase::SetValidator(const wxValidator& validator)
1520 {
1521 if ( m_windowValidator )
1522 delete m_windowValidator;
1523
1524 m_windowValidator = (wxValidator *)validator.Clone();
1525
1526 if ( m_windowValidator )
1527 m_windowValidator->SetWindow(this);
1528 }
1529 #endif // wxUSE_VALIDATORS
1530
1531 // ----------------------------------------------------------------------------
1532 // update region stuff
1533 // ----------------------------------------------------------------------------
1534
1535 wxRect wxWindowBase::GetUpdateClientRect() const
1536 {
1537 wxRegion rgnUpdate = GetUpdateRegion();
1538 rgnUpdate.Intersect(GetClientRect());
1539 wxRect rectUpdate = rgnUpdate.GetBox();
1540 wxPoint ptOrigin = GetClientAreaOrigin();
1541 rectUpdate.x -= ptOrigin.x;
1542 rectUpdate.y -= ptOrigin.y;
1543
1544 return rectUpdate;
1545 }
1546
1547 bool wxWindowBase::DoIsExposed(int x, int y) const
1548 {
1549 return m_updateRegion.Contains(x, y) != wxOutRegion;
1550 }
1551
1552 bool wxWindowBase::DoIsExposed(int x, int y, int w, int h) const
1553 {
1554 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
1555 }
1556
1557 void wxWindowBase::ClearBackground()
1558 {
1559 // wxGTK uses its own version, no need to add never used code
1560 #ifndef __WXGTK__
1561 wxClientDC dc((wxWindow *)this);
1562 wxBrush brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID);
1563 dc.SetBackground(brush);
1564 dc.Clear();
1565 #endif // __WXGTK__
1566 }
1567
1568 // ----------------------------------------------------------------------------
1569 // find child window by id or name
1570 // ----------------------------------------------------------------------------
1571
1572 wxWindow *wxWindowBase::FindWindow(long id) const
1573 {
1574 if ( id == m_windowId )
1575 return (wxWindow *)this;
1576
1577 wxWindowBase *res = NULL;
1578 wxWindowList::compatibility_iterator node;
1579 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1580 {
1581 wxWindowBase *child = node->GetData();
1582 res = child->FindWindow( id );
1583 }
1584
1585 return (wxWindow *)res;
1586 }
1587
1588 wxWindow *wxWindowBase::FindWindow(const wxString& name) const
1589 {
1590 if ( name == m_windowName )
1591 return (wxWindow *)this;
1592
1593 wxWindowBase *res = NULL;
1594 wxWindowList::compatibility_iterator node;
1595 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1596 {
1597 wxWindow *child = node->GetData();
1598 res = child->FindWindow(name);
1599 }
1600
1601 return (wxWindow *)res;
1602 }
1603
1604
1605 // find any window by id or name or label: If parent is non-NULL, look through
1606 // children for a label or title matching the specified string. If NULL, look
1607 // through all top-level windows.
1608 //
1609 // to avoid duplicating code we reuse the same helper function but with
1610 // different comparators
1611
1612 typedef bool (*wxFindWindowCmp)(const wxWindow *win,
1613 const wxString& label, long id);
1614
1615 static
1616 bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
1617 long WXUNUSED(id))
1618 {
1619 return win->GetLabel() == label;
1620 }
1621
1622 static
1623 bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
1624 long WXUNUSED(id))
1625 {
1626 return win->GetName() == label;
1627 }
1628
1629 static
1630 bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
1631 long id)
1632 {
1633 return win->GetId() == id;
1634 }
1635
1636 // recursive helper for the FindWindowByXXX() functions
1637 static
1638 wxWindow *wxFindWindowRecursively(const wxWindow *parent,
1639 const wxString& label,
1640 long id,
1641 wxFindWindowCmp cmp)
1642 {
1643 if ( parent )
1644 {
1645 // see if this is the one we're looking for
1646 if ( (*cmp)(parent, label, id) )
1647 return (wxWindow *)parent;
1648
1649 // It wasn't, so check all its children
1650 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1651 node;
1652 node = node->GetNext() )
1653 {
1654 // recursively check each child
1655 wxWindow *win = (wxWindow *)node->GetData();
1656 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1657 if (retwin)
1658 return retwin;
1659 }
1660 }
1661
1662 // Not found
1663 return NULL;
1664 }
1665
1666 // helper for FindWindowByXXX()
1667 static
1668 wxWindow *wxFindWindowHelper(const wxWindow *parent,
1669 const wxString& label,
1670 long id,
1671 wxFindWindowCmp cmp)
1672 {
1673 if ( parent )
1674 {
1675 // just check parent and all its children
1676 return wxFindWindowRecursively(parent, label, id, cmp);
1677 }
1678
1679 // start at very top of wx's windows
1680 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1681 node;
1682 node = node->GetNext() )
1683 {
1684 // recursively check each window & its children
1685 wxWindow *win = node->GetData();
1686 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1687 if (retwin)
1688 return retwin;
1689 }
1690
1691 return NULL;
1692 }
1693
1694 /* static */
1695 wxWindow *
1696 wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
1697 {
1698 return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
1699 }
1700
1701 /* static */
1702 wxWindow *
1703 wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
1704 {
1705 wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
1706
1707 if ( !win )
1708 {
1709 // fall back to the label
1710 win = FindWindowByLabel(title, parent);
1711 }
1712
1713 return win;
1714 }
1715
1716 /* static */
1717 wxWindow *
1718 wxWindowBase::FindWindowById( long id, const wxWindow* parent )
1719 {
1720 return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds);
1721 }
1722
1723 // ----------------------------------------------------------------------------
1724 // dialog oriented functions
1725 // ----------------------------------------------------------------------------
1726
1727 void wxWindowBase::MakeModal(bool modal)
1728 {
1729 // Disable all other windows
1730 if ( IsTopLevel() )
1731 {
1732 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1733 while (node)
1734 {
1735 wxWindow *win = node->GetData();
1736 if (win != this)
1737 win->Enable(!modal);
1738
1739 node = node->GetNext();
1740 }
1741 }
1742 }
1743
1744 bool wxWindowBase::Validate()
1745 {
1746 #if wxUSE_VALIDATORS
1747 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1748
1749 wxWindowList::compatibility_iterator node;
1750 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1751 {
1752 wxWindowBase *child = node->GetData();
1753 wxValidator *validator = child->GetValidator();
1754 if ( validator && !validator->Validate((wxWindow *)this) )
1755 {
1756 return false;
1757 }
1758
1759 if ( recurse && !child->Validate() )
1760 {
1761 return false;
1762 }
1763 }
1764 #endif // wxUSE_VALIDATORS
1765
1766 return true;
1767 }
1768
1769 bool wxWindowBase::TransferDataToWindow()
1770 {
1771 #if wxUSE_VALIDATORS
1772 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1773
1774 wxWindowList::compatibility_iterator node;
1775 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1776 {
1777 wxWindowBase *child = node->GetData();
1778 wxValidator *validator = child->GetValidator();
1779 if ( validator && !validator->TransferToWindow() )
1780 {
1781 wxLogWarning(_("Could not transfer data to window"));
1782 #if wxUSE_LOG
1783 wxLog::FlushActive();
1784 #endif // wxUSE_LOG
1785
1786 return false;
1787 }
1788
1789 if ( recurse )
1790 {
1791 if ( !child->TransferDataToWindow() )
1792 {
1793 // warning already given
1794 return false;
1795 }
1796 }
1797 }
1798 #endif // wxUSE_VALIDATORS
1799
1800 return true;
1801 }
1802
1803 bool wxWindowBase::TransferDataFromWindow()
1804 {
1805 #if wxUSE_VALIDATORS
1806 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1807
1808 wxWindowList::compatibility_iterator node;
1809 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1810 {
1811 wxWindow *child = node->GetData();
1812 wxValidator *validator = child->GetValidator();
1813 if ( validator && !validator->TransferFromWindow() )
1814 {
1815 // nop warning here because the application is supposed to give
1816 // one itself - we don't know here what might have gone wrongly
1817
1818 return false;
1819 }
1820
1821 if ( recurse )
1822 {
1823 if ( !child->TransferDataFromWindow() )
1824 {
1825 // warning already given
1826 return false;
1827 }
1828 }
1829 }
1830 #endif // wxUSE_VALIDATORS
1831
1832 return true;
1833 }
1834
1835 void wxWindowBase::InitDialog()
1836 {
1837 wxInitDialogEvent event(GetId());
1838 event.SetEventObject( this );
1839 GetEventHandler()->ProcessEvent(event);
1840 }
1841
1842 // ----------------------------------------------------------------------------
1843 // context-sensitive help support
1844 // ----------------------------------------------------------------------------
1845
1846 #if wxUSE_HELP
1847
1848 // associate this help text with this window
1849 void wxWindowBase::SetHelpText(const wxString& text)
1850 {
1851 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1852 if ( helpProvider )
1853 {
1854 helpProvider->AddHelp(this, text);
1855 }
1856 }
1857
1858 #if WXWIN_COMPATIBILITY_2_8
1859 // associate this help text with all windows with the same id as this
1860 // one
1861 void wxWindowBase::SetHelpTextForId(const wxString& text)
1862 {
1863 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1864 if ( helpProvider )
1865 {
1866 helpProvider->AddHelp(GetId(), text);
1867 }
1868 }
1869 #endif // WXWIN_COMPATIBILITY_2_8
1870
1871 // get the help string associated with this window (may be empty)
1872 // default implementation forwards calls to the help provider
1873 wxString
1874 wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt),
1875 wxHelpEvent::Origin WXUNUSED(origin)) const
1876 {
1877 wxString text;
1878 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1879 if ( helpProvider )
1880 {
1881 text = helpProvider->GetHelp(this);
1882 }
1883
1884 return text;
1885 }
1886
1887 // show help for this window
1888 void wxWindowBase::OnHelp(wxHelpEvent& event)
1889 {
1890 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1891 if ( helpProvider )
1892 {
1893 wxPoint pos = event.GetPosition();
1894 const wxHelpEvent::Origin origin = event.GetOrigin();
1895 if ( origin == wxHelpEvent::Origin_Keyboard )
1896 {
1897 // if the help event was generated from keyboard it shouldn't
1898 // appear at the mouse position (which is still the only position
1899 // associated with help event) if the mouse is far away, although
1900 // we still do use the mouse position if it's over the window
1901 // because we suppose the user looks approximately at the mouse
1902 // already and so it would be more convenient than showing tooltip
1903 // at some arbitrary position which can be quite far from it
1904 const wxRect rectClient = GetClientRect();
1905 if ( !rectClient.Contains(ScreenToClient(pos)) )
1906 {
1907 // position help slightly under and to the right of this window
1908 pos = ClientToScreen(wxPoint(
1909 2*GetCharWidth(),
1910 rectClient.height + GetCharHeight()
1911 ));
1912 }
1913 }
1914
1915 if ( helpProvider->ShowHelpAtPoint(this, pos, origin) )
1916 {
1917 // skip the event.Skip() below
1918 return;
1919 }
1920 }
1921
1922 event.Skip();
1923 }
1924
1925 #endif // wxUSE_HELP
1926
1927 // ----------------------------------------------------------------------------
1928 // tooltips
1929 // ----------------------------------------------------------------------------
1930
1931 #if wxUSE_TOOLTIPS
1932
1933 wxString wxWindowBase::GetToolTipText() const
1934 {
1935 return m_tooltip ? m_tooltip->GetTip() : wxString();
1936 }
1937
1938 void wxWindowBase::SetToolTip( const wxString &tip )
1939 {
1940 // don't create the new tooltip if we already have one
1941 if ( m_tooltip )
1942 {
1943 m_tooltip->SetTip( tip );
1944 }
1945 else
1946 {
1947 SetToolTip( new wxToolTip( tip ) );
1948 }
1949
1950 // setting empty tooltip text does not remove the tooltip any more - use
1951 // SetToolTip(NULL) for this
1952 }
1953
1954 void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1955 {
1956 if ( m_tooltip != tooltip )
1957 {
1958 if ( m_tooltip )
1959 delete m_tooltip;
1960
1961 m_tooltip = tooltip;
1962 }
1963 }
1964
1965 #endif // wxUSE_TOOLTIPS
1966
1967 // ----------------------------------------------------------------------------
1968 // constraints and sizers
1969 // ----------------------------------------------------------------------------
1970
1971 #if wxUSE_CONSTRAINTS
1972
1973 void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1974 {
1975 if ( m_constraints )
1976 {
1977 UnsetConstraints(m_constraints);
1978 delete m_constraints;
1979 }
1980 m_constraints = constraints;
1981 if ( m_constraints )
1982 {
1983 // Make sure other windows know they're part of a 'meaningful relationship'
1984 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1985 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1986 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1987 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1988 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1989 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1990 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1991 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1992 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1993 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1994 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1995 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1996 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1997 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1998 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1999 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
2000 }
2001 }
2002
2003 // This removes any dangling pointers to this window in other windows'
2004 // constraintsInvolvedIn lists.
2005 void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
2006 {
2007 if ( c )
2008 {
2009 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
2010 c->left.GetOtherWindow()->RemoveConstraintReference(this);
2011 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
2012 c->top.GetOtherWindow()->RemoveConstraintReference(this);
2013 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
2014 c->right.GetOtherWindow()->RemoveConstraintReference(this);
2015 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
2016 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
2017 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
2018 c->width.GetOtherWindow()->RemoveConstraintReference(this);
2019 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
2020 c->height.GetOtherWindow()->RemoveConstraintReference(this);
2021 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
2022 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
2023 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
2024 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
2025 }
2026 }
2027
2028 // Back-pointer to other windows we're involved with, so if we delete this
2029 // window, we must delete any constraints we're involved with.
2030 void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
2031 {
2032 if ( !m_constraintsInvolvedIn )
2033 m_constraintsInvolvedIn = new wxWindowList;
2034 if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) )
2035 m_constraintsInvolvedIn->Append((wxWindow *)otherWin);
2036 }
2037
2038 // REMOVE back-pointer to other windows we're involved with.
2039 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
2040 {
2041 if ( m_constraintsInvolvedIn )
2042 m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin);
2043 }
2044
2045 // Reset any constraints that mention this window
2046 void wxWindowBase::DeleteRelatedConstraints()
2047 {
2048 if ( m_constraintsInvolvedIn )
2049 {
2050 wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst();
2051 while (node)
2052 {
2053 wxWindow *win = node->GetData();
2054 wxLayoutConstraints *constr = win->GetConstraints();
2055
2056 // Reset any constraints involving this window
2057 if ( constr )
2058 {
2059 constr->left.ResetIfWin(this);
2060 constr->top.ResetIfWin(this);
2061 constr->right.ResetIfWin(this);
2062 constr->bottom.ResetIfWin(this);
2063 constr->width.ResetIfWin(this);
2064 constr->height.ResetIfWin(this);
2065 constr->centreX.ResetIfWin(this);
2066 constr->centreY.ResetIfWin(this);
2067 }
2068
2069 wxWindowList::compatibility_iterator next = node->GetNext();
2070 m_constraintsInvolvedIn->Erase(node);
2071 node = next;
2072 }
2073
2074 delete m_constraintsInvolvedIn;
2075 m_constraintsInvolvedIn = NULL;
2076 }
2077 }
2078
2079 #endif // wxUSE_CONSTRAINTS
2080
2081 void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
2082 {
2083 if ( sizer == m_windowSizer)
2084 return;
2085
2086 if ( m_windowSizer )
2087 {
2088 m_windowSizer->SetContainingWindow(NULL);
2089
2090 if ( deleteOld )
2091 delete m_windowSizer;
2092 }
2093
2094 m_windowSizer = sizer;
2095 if ( m_windowSizer )
2096 {
2097 m_windowSizer->SetContainingWindow((wxWindow *)this);
2098 }
2099
2100 SetAutoLayout(m_windowSizer != NULL);
2101 }
2102
2103 void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
2104 {
2105 SetSizer( sizer, deleteOld );
2106 sizer->SetSizeHints( (wxWindow*) this );
2107 }
2108
2109
2110 void wxWindowBase::SetContainingSizer(wxSizer* sizer)
2111 {
2112 // adding a window to a sizer twice is going to result in fatal and
2113 // hard to debug problems later because when deleting the second
2114 // associated wxSizerItem we're going to dereference a dangling
2115 // pointer; so try to detect this as early as possible
2116 wxASSERT_MSG( !sizer || m_containingSizer != sizer,
2117 wxT("Adding a window to the same sizer twice?") );
2118
2119 m_containingSizer = sizer;
2120 }
2121
2122 #if wxUSE_CONSTRAINTS
2123
2124 void wxWindowBase::SatisfyConstraints()
2125 {
2126 wxLayoutConstraints *constr = GetConstraints();
2127 bool wasOk = constr && constr->AreSatisfied();
2128
2129 ResetConstraints(); // Mark all constraints as unevaluated
2130
2131 int noChanges = 1;
2132
2133 // if we're a top level panel (i.e. our parent is frame/dialog), our
2134 // own constraints will never be satisfied any more unless we do it
2135 // here
2136 if ( wasOk )
2137 {
2138 while ( noChanges > 0 )
2139 {
2140 LayoutPhase1(&noChanges);
2141 }
2142 }
2143
2144 LayoutPhase2(&noChanges);
2145 }
2146
2147 #endif // wxUSE_CONSTRAINTS
2148
2149 bool wxWindowBase::Layout()
2150 {
2151 // If there is a sizer, use it instead of the constraints
2152 if ( GetSizer() )
2153 {
2154 int w = 0, h = 0;
2155 GetVirtualSize(&w, &h);
2156 GetSizer()->SetDimension( 0, 0, w, h );
2157 }
2158 #if wxUSE_CONSTRAINTS
2159 else
2160 {
2161 SatisfyConstraints(); // Find the right constraints values
2162 SetConstraintSizes(); // Recursively set the real window sizes
2163 }
2164 #endif
2165
2166 return true;
2167 }
2168
2169 void wxWindowBase::InternalOnSize(wxSizeEvent& event)
2170 {
2171 if ( GetAutoLayout() )
2172 Layout();
2173
2174 event.Skip();
2175 }
2176
2177 #if wxUSE_CONSTRAINTS
2178
2179 // first phase of the constraints evaluation: set our own constraints
2180 bool wxWindowBase::LayoutPhase1(int *noChanges)
2181 {
2182 wxLayoutConstraints *constr = GetConstraints();
2183
2184 return !constr || constr->SatisfyConstraints(this, noChanges);
2185 }
2186
2187 // second phase: set the constraints for our children
2188 bool wxWindowBase::LayoutPhase2(int *noChanges)
2189 {
2190 *noChanges = 0;
2191
2192 // Layout children
2193 DoPhase(1);
2194
2195 // Layout grand children
2196 DoPhase(2);
2197
2198 return true;
2199 }
2200
2201 // Do a phase of evaluating child constraints
2202 bool wxWindowBase::DoPhase(int phase)
2203 {
2204 // the list containing the children for which the constraints are already
2205 // set correctly
2206 wxWindowList succeeded;
2207
2208 // the max number of iterations we loop before concluding that we can't set
2209 // the constraints
2210 static const int maxIterations = 500;
2211
2212 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
2213 {
2214 int noChanges = 0;
2215
2216 // loop over all children setting their constraints
2217 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2218 node;
2219 node = node->GetNext() )
2220 {
2221 wxWindow *child = node->GetData();
2222 if ( child->IsTopLevel() )
2223 {
2224 // top level children are not inside our client area
2225 continue;
2226 }
2227
2228 if ( !child->GetConstraints() || succeeded.Find(child) )
2229 {
2230 // this one is either already ok or nothing we can do about it
2231 continue;
2232 }
2233
2234 int tempNoChanges = 0;
2235 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
2236 : child->LayoutPhase2(&tempNoChanges);
2237 noChanges += tempNoChanges;
2238
2239 if ( success )
2240 {
2241 succeeded.Append(child);
2242 }
2243 }
2244
2245 if ( !noChanges )
2246 {
2247 // constraints are set
2248 break;
2249 }
2250 }
2251
2252 return true;
2253 }
2254
2255 void wxWindowBase::ResetConstraints()
2256 {
2257 wxLayoutConstraints *constr = GetConstraints();
2258 if ( constr )
2259 {
2260 constr->left.SetDone(false);
2261 constr->top.SetDone(false);
2262 constr->right.SetDone(false);
2263 constr->bottom.SetDone(false);
2264 constr->width.SetDone(false);
2265 constr->height.SetDone(false);
2266 constr->centreX.SetDone(false);
2267 constr->centreY.SetDone(false);
2268 }
2269
2270 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2271 while (node)
2272 {
2273 wxWindow *win = node->GetData();
2274 if ( !win->IsTopLevel() )
2275 win->ResetConstraints();
2276 node = node->GetNext();
2277 }
2278 }
2279
2280 // Need to distinguish between setting the 'fake' size for windows and sizers,
2281 // and setting the real values.
2282 void wxWindowBase::SetConstraintSizes(bool recurse)
2283 {
2284 wxLayoutConstraints *constr = GetConstraints();
2285 if ( constr && constr->AreSatisfied() )
2286 {
2287 int x = constr->left.GetValue();
2288 int y = constr->top.GetValue();
2289 int w = constr->width.GetValue();
2290 int h = constr->height.GetValue();
2291
2292 if ( (constr->width.GetRelationship() != wxAsIs ) ||
2293 (constr->height.GetRelationship() != wxAsIs) )
2294 {
2295 SetSize(x, y, w, h);
2296 }
2297 else
2298 {
2299 // If we don't want to resize this window, just move it...
2300 Move(x, y);
2301 }
2302 }
2303 else if ( constr )
2304 {
2305 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
2306 GetClassInfo()->GetClassName(),
2307 GetName().c_str());
2308 }
2309
2310 if ( recurse )
2311 {
2312 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2313 while (node)
2314 {
2315 wxWindow *win = node->GetData();
2316 if ( !win->IsTopLevel() && win->GetConstraints() )
2317 win->SetConstraintSizes();
2318 node = node->GetNext();
2319 }
2320 }
2321 }
2322
2323 // Only set the size/position of the constraint (if any)
2324 void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
2325 {
2326 wxLayoutConstraints *constr = GetConstraints();
2327 if ( constr )
2328 {
2329 if ( x != wxDefaultCoord )
2330 {
2331 constr->left.SetValue(x);
2332 constr->left.SetDone(true);
2333 }
2334 if ( y != wxDefaultCoord )
2335 {
2336 constr->top.SetValue(y);
2337 constr->top.SetDone(true);
2338 }
2339 if ( w != wxDefaultCoord )
2340 {
2341 constr->width.SetValue(w);
2342 constr->width.SetDone(true);
2343 }
2344 if ( h != wxDefaultCoord )
2345 {
2346 constr->height.SetValue(h);
2347 constr->height.SetDone(true);
2348 }
2349 }
2350 }
2351
2352 void wxWindowBase::MoveConstraint(int x, int y)
2353 {
2354 wxLayoutConstraints *constr = GetConstraints();
2355 if ( constr )
2356 {
2357 if ( x != wxDefaultCoord )
2358 {
2359 constr->left.SetValue(x);
2360 constr->left.SetDone(true);
2361 }
2362 if ( y != wxDefaultCoord )
2363 {
2364 constr->top.SetValue(y);
2365 constr->top.SetDone(true);
2366 }
2367 }
2368 }
2369
2370 void wxWindowBase::GetSizeConstraint(int *w, int *h) const
2371 {
2372 wxLayoutConstraints *constr = GetConstraints();
2373 if ( constr )
2374 {
2375 *w = constr->width.GetValue();
2376 *h = constr->height.GetValue();
2377 }
2378 else
2379 GetSize(w, h);
2380 }
2381
2382 void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
2383 {
2384 wxLayoutConstraints *constr = GetConstraints();
2385 if ( constr )
2386 {
2387 *w = constr->width.GetValue();
2388 *h = constr->height.GetValue();
2389 }
2390 else
2391 GetClientSize(w, h);
2392 }
2393
2394 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
2395 {
2396 wxLayoutConstraints *constr = GetConstraints();
2397 if ( constr )
2398 {
2399 *x = constr->left.GetValue();
2400 *y = constr->top.GetValue();
2401 }
2402 else
2403 GetPosition(x, y);
2404 }
2405
2406 #endif // wxUSE_CONSTRAINTS
2407
2408 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
2409 {
2410 // don't do it for the dialogs/frames - they float independently of their
2411 // parent
2412 if ( !IsTopLevel() )
2413 {
2414 wxWindow *parent = GetParent();
2415 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
2416 {
2417 wxPoint pt(parent->GetClientAreaOrigin());
2418 x += pt.x;
2419 y += pt.y;
2420 }
2421 }
2422 }
2423
2424 // ----------------------------------------------------------------------------
2425 // Update UI processing
2426 // ----------------------------------------------------------------------------
2427
2428 void wxWindowBase::UpdateWindowUI(long flags)
2429 {
2430 wxUpdateUIEvent event(GetId());
2431 event.SetEventObject(this);
2432
2433 if ( GetEventHandler()->ProcessEvent(event) )
2434 {
2435 DoUpdateWindowUI(event);
2436 }
2437
2438 if (flags & wxUPDATE_UI_RECURSE)
2439 {
2440 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2441 while (node)
2442 {
2443 wxWindow* child = (wxWindow*) node->GetData();
2444 child->UpdateWindowUI(flags);
2445 node = node->GetNext();
2446 }
2447 }
2448 }
2449
2450 // do the window-specific processing after processing the update event
2451 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
2452 {
2453 if ( event.GetSetEnabled() )
2454 Enable(event.GetEnabled());
2455
2456 if ( event.GetSetShown() )
2457 Show(event.GetShown());
2458 }
2459
2460 // ----------------------------------------------------------------------------
2461 // dialog units translations
2462 // ----------------------------------------------------------------------------
2463
2464 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
2465 {
2466 int charWidth = GetCharWidth();
2467 int charHeight = GetCharHeight();
2468 wxPoint pt2 = wxDefaultPosition;
2469 if (pt.x != wxDefaultCoord)
2470 pt2.x = (int) ((pt.x * 4) / charWidth);
2471 if (pt.y != wxDefaultCoord)
2472 pt2.y = (int) ((pt.y * 8) / charHeight);
2473
2474 return pt2;
2475 }
2476
2477 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
2478 {
2479 int charWidth = GetCharWidth();
2480 int charHeight = GetCharHeight();
2481 wxPoint pt2 = wxDefaultPosition;
2482 if (pt.x != wxDefaultCoord)
2483 pt2.x = (int) ((pt.x * charWidth) / 4);
2484 if (pt.y != wxDefaultCoord)
2485 pt2.y = (int) ((pt.y * charHeight) / 8);
2486
2487 return pt2;
2488 }
2489
2490 // ----------------------------------------------------------------------------
2491 // event handlers
2492 // ----------------------------------------------------------------------------
2493
2494 // propagate the colour change event to the subwindows
2495 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
2496 {
2497 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2498 while ( node )
2499 {
2500 // Only propagate to non-top-level windows
2501 wxWindow *win = node->GetData();
2502 if ( !win->IsTopLevel() )
2503 {
2504 wxSysColourChangedEvent event2;
2505 event2.SetEventObject(win);
2506 win->GetEventHandler()->ProcessEvent(event2);
2507 }
2508
2509 node = node->GetNext();
2510 }
2511
2512 Refresh();
2513 }
2514
2515 // the default action is to populate dialog with data when it's created,
2516 // and nudge the UI into displaying itself correctly in case
2517 // we've turned the wxUpdateUIEvents frequency down low.
2518 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2519 {
2520 TransferDataToWindow();
2521
2522 // Update the UI at this point
2523 UpdateWindowUI(wxUPDATE_UI_RECURSE);
2524 }
2525
2526 // ----------------------------------------------------------------------------
2527 // menu-related functions
2528 // ----------------------------------------------------------------------------
2529
2530 #if wxUSE_MENUS
2531
2532 bool wxWindowBase::PopupMenu(wxMenu *menu, int x, int y)
2533 {
2534 wxCHECK_MSG( menu, false, "can't popup NULL menu" );
2535
2536 wxCurrentPopupMenu = menu;
2537 const bool rc = DoPopupMenu(menu, x, y);
2538 wxCurrentPopupMenu = NULL;
2539
2540 return rc;
2541 }
2542
2543 // this is used to pass the id of the selected item from the menu event handler
2544 // to the main function itself
2545 //
2546 // it's ok to use a global here as there can be at most one popup menu shown at
2547 // any time
2548 static int gs_popupMenuSelection = wxID_NONE;
2549
2550 void wxWindowBase::InternalOnPopupMenu(wxCommandEvent& event)
2551 {
2552 // store the id in a global variable where we'll retrieve it from later
2553 gs_popupMenuSelection = event.GetId();
2554 }
2555
2556 void wxWindowBase::InternalOnPopupMenuUpdate(wxUpdateUIEvent& WXUNUSED(event))
2557 {
2558 // nothing to do but do not skip it
2559 }
2560
2561 int
2562 wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y)
2563 {
2564 gs_popupMenuSelection = wxID_NONE;
2565
2566 Connect(wxEVT_COMMAND_MENU_SELECTED,
2567 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu),
2568 NULL,
2569 this);
2570
2571 // it is common to construct the menu passed to this function dynamically
2572 // using some fixed range of ids which could clash with the ids used
2573 // elsewhere in the program, which could result in some menu items being
2574 // unintentionally disabled or otherwise modified by update UI handlers
2575 // elsewhere in the program code and this is difficult to avoid in the
2576 // program itself, so instead we just temporarily suspend UI updating while
2577 // this menu is shown
2578 Connect(wxEVT_UPDATE_UI,
2579 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate),
2580 NULL,
2581 this);
2582
2583 PopupMenu(&menu, x, y);
2584
2585 Disconnect(wxEVT_UPDATE_UI,
2586 wxUpdateUIEventHandler(wxWindowBase::InternalOnPopupMenuUpdate),
2587 NULL,
2588 this);
2589 Disconnect(wxEVT_COMMAND_MENU_SELECTED,
2590 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu),
2591 NULL,
2592 this);
2593
2594 return gs_popupMenuSelection;
2595 }
2596
2597 #endif // wxUSE_MENUS
2598
2599 // methods for drawing the sizers in a visible way: this is currently only
2600 // enabled for "full debug" builds with wxDEBUG_LEVEL==2 as it doesn't work
2601 // that well and also because we don't want to leave it enabled in default
2602 // builds used for production
2603 #if wxDEBUG_LEVEL > 1
2604
2605 static void DrawSizers(wxWindowBase *win);
2606
2607 static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill, const wxPen* pen)
2608 {
2609 wxClientDC dc((wxWindow *)win);
2610 dc.SetPen(*pen);
2611 dc.SetBrush(fill ? wxBrush(pen->GetColour(), wxBRUSHSTYLE_CROSSDIAG_HATCH) :
2612 *wxTRANSPARENT_BRUSH);
2613 dc.DrawRectangle(rect.Deflate(1, 1));
2614 }
2615
2616 static void DrawSizer(wxWindowBase *win, wxSizer *sizer)
2617 {
2618 const wxSizerItemList& items = sizer->GetChildren();
2619 for ( wxSizerItemList::const_iterator i = items.begin(),
2620 end = items.end();
2621 i != end;
2622 ++i )
2623 {
2624 wxSizerItem *item = *i;
2625 if ( item->IsSizer() )
2626 {
2627 DrawBorder(win, item->GetRect().Deflate(2), false, wxRED_PEN);
2628 DrawSizer(win, item->GetSizer());
2629 }
2630 else if ( item->IsSpacer() )
2631 {
2632 DrawBorder(win, item->GetRect().Deflate(2), true, wxBLUE_PEN);
2633 }
2634 else if ( item->IsWindow() )
2635 {
2636 DrawSizers(item->GetWindow());
2637 }
2638 else
2639 wxFAIL_MSG("inconsistent wxSizerItem status!");
2640 }
2641 }
2642
2643 static void DrawSizers(wxWindowBase *win)
2644 {
2645 DrawBorder(win, win->GetClientSize(), false, wxGREEN_PEN);
2646
2647 wxSizer *sizer = win->GetSizer();
2648 if ( sizer )
2649 {
2650 DrawSizer(win, sizer);
2651 }
2652 else // no sizer, still recurse into the children
2653 {
2654 const wxWindowList& children = win->GetChildren();
2655 for ( wxWindowList::const_iterator i = children.begin(),
2656 end = children.end();
2657 i != end;
2658 ++i )
2659 {
2660 DrawSizers(*i);
2661 }
2662
2663 // show all kind of sizes of this window; see the "window sizing" topic
2664 // overview for more info about the various differences:
2665 wxSize fullSz = win->GetSize();
2666 wxSize clientSz = win->GetClientSize();
2667 wxSize bestSz = win->GetBestSize();
2668 wxSize minSz = win->GetMinSize();
2669 wxSize maxSz = win->GetMaxSize();
2670 wxSize virtualSz = win->GetVirtualSize();
2671
2672 wxMessageOutputDebug dbgout;
2673 dbgout.Printf(
2674 "%-10s => fullsz=%4d;%-4d clientsz=%4d;%-4d bestsz=%4d;%-4d minsz=%4d;%-4d maxsz=%4d;%-4d virtualsz=%4d;%-4d\n",
2675 win->GetName(),
2676 fullSz.x, fullSz.y,
2677 clientSz.x, clientSz.y,
2678 bestSz.x, bestSz.y,
2679 minSz.x, minSz.y,
2680 maxSz.x, maxSz.y,
2681 virtualSz.x, virtualSz.y);
2682 }
2683 }
2684
2685 #endif // wxDEBUG_LEVEL
2686
2687 // process special middle clicks
2688 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2689 {
2690 if ( event.ControlDown() && event.AltDown() )
2691 {
2692 #if wxDEBUG_LEVEL > 1
2693 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2694 if ( event.ShiftDown() )
2695 {
2696 DrawSizers(this);
2697 }
2698 else
2699 #endif // __WXDEBUG__
2700 {
2701 // just Ctrl-Alt-middle click shows information about wx version
2702 ::wxInfoMessageBox((wxWindow*)this);
2703 }
2704 }
2705 else
2706 {
2707 event.Skip();
2708 }
2709 }
2710
2711 // ----------------------------------------------------------------------------
2712 // accessibility
2713 // ----------------------------------------------------------------------------
2714
2715 #if wxUSE_ACCESSIBILITY
2716 void wxWindowBase::SetAccessible(wxAccessible* accessible)
2717 {
2718 if (m_accessible && (accessible != m_accessible))
2719 delete m_accessible;
2720 m_accessible = accessible;
2721 if (m_accessible)
2722 m_accessible->SetWindow((wxWindow*) this);
2723 }
2724
2725 // Returns the accessible object, creating if necessary.
2726 wxAccessible* wxWindowBase::GetOrCreateAccessible()
2727 {
2728 if (!m_accessible)
2729 m_accessible = CreateAccessible();
2730 return m_accessible;
2731 }
2732
2733 // Override to create a specific accessible object.
2734 wxAccessible* wxWindowBase::CreateAccessible()
2735 {
2736 return new wxWindowAccessible((wxWindow*) this);
2737 }
2738
2739 #endif
2740
2741 // ----------------------------------------------------------------------------
2742 // list classes implementation
2743 // ----------------------------------------------------------------------------
2744
2745 #if wxUSE_STL
2746
2747 #include "wx/listimpl.cpp"
2748 WX_DEFINE_LIST(wxWindowList)
2749
2750 #else // !wxUSE_STL
2751
2752 void wxWindowListNode::DeleteData()
2753 {
2754 delete (wxWindow *)GetData();
2755 }
2756
2757 #endif // wxUSE_STL/!wxUSE_STL
2758
2759 // ----------------------------------------------------------------------------
2760 // borders
2761 // ----------------------------------------------------------------------------
2762
2763 wxBorder wxWindowBase::GetBorder(long flags) const
2764 {
2765 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
2766 if ( border == wxBORDER_DEFAULT )
2767 {
2768 border = GetDefaultBorder();
2769 }
2770 else if ( border == wxBORDER_THEME )
2771 {
2772 border = GetDefaultBorderForControl();
2773 }
2774
2775 return border;
2776 }
2777
2778 wxBorder wxWindowBase::GetDefaultBorder() const
2779 {
2780 return wxBORDER_NONE;
2781 }
2782
2783 // ----------------------------------------------------------------------------
2784 // hit testing
2785 // ----------------------------------------------------------------------------
2786
2787 wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2788 {
2789 // here we just check if the point is inside the window or not
2790
2791 // check the top and left border first
2792 bool outside = x < 0 || y < 0;
2793 if ( !outside )
2794 {
2795 // check the right and bottom borders too
2796 wxSize size = GetSize();
2797 outside = x >= size.x || y >= size.y;
2798 }
2799
2800 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2801 }
2802
2803 // ----------------------------------------------------------------------------
2804 // mouse capture
2805 // ----------------------------------------------------------------------------
2806
2807 struct WXDLLEXPORT wxWindowNext
2808 {
2809 wxWindow *win;
2810 wxWindowNext *next;
2811 } *wxWindowBase::ms_winCaptureNext = NULL;
2812 wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL;
2813 bool wxWindowBase::ms_winCaptureChanging = false;
2814
2815 void wxWindowBase::CaptureMouse()
2816 {
2817 wxLogTrace(wxT("mousecapture"), wxT("CaptureMouse(%p)"), static_cast<void*>(this));
2818
2819 wxASSERT_MSG( !ms_winCaptureChanging, wxT("recursive CaptureMouse call?") );
2820
2821 ms_winCaptureChanging = true;
2822
2823 wxWindow *winOld = GetCapture();
2824 if ( winOld )
2825 {
2826 ((wxWindowBase*) winOld)->DoReleaseMouse();
2827
2828 // save it on stack
2829 wxWindowNext *item = new wxWindowNext;
2830 item->win = winOld;
2831 item->next = ms_winCaptureNext;
2832 ms_winCaptureNext = item;
2833 }
2834 //else: no mouse capture to save
2835
2836 DoCaptureMouse();
2837 ms_winCaptureCurrent = (wxWindow*)this;
2838
2839 ms_winCaptureChanging = false;
2840 }
2841
2842 void wxWindowBase::ReleaseMouse()
2843 {
2844 wxLogTrace(wxT("mousecapture"), wxT("ReleaseMouse(%p)"), static_cast<void*>(this));
2845
2846 wxASSERT_MSG( !ms_winCaptureChanging, wxT("recursive ReleaseMouse call?") );
2847
2848 wxASSERT_MSG( GetCapture() == this,
2849 "attempt to release mouse, but this window hasn't captured it" );
2850 wxASSERT_MSG( ms_winCaptureCurrent == this,
2851 "attempt to release mouse, but this window hasn't captured it" );
2852
2853 ms_winCaptureChanging = true;
2854
2855 DoReleaseMouse();
2856 ms_winCaptureCurrent = NULL;
2857
2858 if ( ms_winCaptureNext )
2859 {
2860 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
2861 ms_winCaptureCurrent = ms_winCaptureNext->win;
2862
2863 wxWindowNext *item = ms_winCaptureNext;
2864 ms_winCaptureNext = item->next;
2865 delete item;
2866 }
2867 //else: stack is empty, no previous capture
2868
2869 ms_winCaptureChanging = false;
2870
2871 wxLogTrace(wxT("mousecapture"),
2872 (const wxChar *) wxT("After ReleaseMouse() mouse is captured by %p"),
2873 static_cast<void*>(GetCapture()));
2874 }
2875
2876 static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
2877 {
2878 wxMouseCaptureLostEvent event(win->GetId());
2879 event.SetEventObject(win);
2880 if ( !win->GetEventHandler()->ProcessEvent(event) )
2881 {
2882 // windows must handle this event, otherwise the app wouldn't behave
2883 // correctly if it loses capture unexpectedly; see the discussion here:
2884 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2885 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
2886 wxFAIL_MSG( wxT("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2887 }
2888 }
2889
2890 /* static */
2891 void wxWindowBase::NotifyCaptureLost()
2892 {
2893 // don't do anything if capture lost was expected, i.e. resulted from
2894 // a wx call to ReleaseMouse or CaptureMouse:
2895 if ( ms_winCaptureChanging )
2896 return;
2897
2898 // if the capture was lost unexpectedly, notify every window that has
2899 // capture (on stack or current) about it and clear the stack:
2900
2901 if ( ms_winCaptureCurrent )
2902 {
2903 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent);
2904 ms_winCaptureCurrent = NULL;
2905 }
2906
2907 while ( ms_winCaptureNext )
2908 {
2909 wxWindowNext *item = ms_winCaptureNext;
2910 ms_winCaptureNext = item->next;
2911
2912 DoNotifyWindowAboutCaptureLost(item->win);
2913
2914 delete item;
2915 }
2916 }
2917
2918 #if wxUSE_HOTKEY
2919
2920 bool
2921 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2922 int WXUNUSED(modifiers),
2923 int WXUNUSED(keycode))
2924 {
2925 // not implemented
2926 return false;
2927 }
2928
2929 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
2930 {
2931 // not implemented
2932 return false;
2933 }
2934
2935 #endif // wxUSE_HOTKEY
2936
2937 // ----------------------------------------------------------------------------
2938 // event processing
2939 // ----------------------------------------------------------------------------
2940
2941 bool wxWindowBase::TryBefore(wxEvent& event)
2942 {
2943 #if wxUSE_VALIDATORS
2944 // Can only use the validator of the window which
2945 // is receiving the event
2946 if ( event.GetEventObject() == this )
2947 {
2948 wxValidator * const validator = GetValidator();
2949 if ( validator && validator->ProcessEventHere(event) )
2950 {
2951 return true;
2952 }
2953 }
2954 #endif // wxUSE_VALIDATORS
2955
2956 return wxEvtHandler::TryBefore(event);
2957 }
2958
2959 bool wxWindowBase::TryAfter(wxEvent& event)
2960 {
2961 // carry on up the parent-child hierarchy if the propagation count hasn't
2962 // reached zero yet
2963 if ( event.ShouldPropagate() )
2964 {
2965 // honour the requests to stop propagation at this window: this is
2966 // used by the dialogs, for example, to prevent processing the events
2967 // from the dialog controls in the parent frame which rarely, if ever,
2968 // makes sense
2969 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2970 {
2971 wxWindow *parent = GetParent();
2972 if ( parent && !parent->IsBeingDeleted() )
2973 {
2974 wxPropagateOnce propagateOnce(event);
2975
2976 return parent->GetEventHandler()->ProcessEvent(event);
2977 }
2978 }
2979 }
2980
2981 return wxEvtHandler::TryAfter(event);
2982 }
2983
2984 // ----------------------------------------------------------------------------
2985 // window relationships
2986 // ----------------------------------------------------------------------------
2987
2988 wxWindow *wxWindowBase::DoGetSibling(WindowOrder order) const
2989 {
2990 wxCHECK_MSG( GetParent(), NULL,
2991 wxT("GetPrev/NextSibling() don't work for TLWs!") );
2992
2993 wxWindowList& siblings = GetParent()->GetChildren();
2994 wxWindowList::compatibility_iterator i = siblings.Find((wxWindow *)this);
2995 wxCHECK_MSG( i, NULL, wxT("window not a child of its parent?") );
2996
2997 if ( order == OrderBefore )
2998 i = i->GetPrevious();
2999 else // OrderAfter
3000 i = i->GetNext();
3001
3002 return i ? i->GetData() : NULL;
3003 }
3004
3005 // ----------------------------------------------------------------------------
3006 // keyboard navigation
3007 // ----------------------------------------------------------------------------
3008
3009 // Navigates in the specified direction inside this window
3010 bool wxWindowBase::DoNavigateIn(int flags)
3011 {
3012 #ifdef wxHAS_NATIVE_TAB_TRAVERSAL
3013 // native code doesn't process our wxNavigationKeyEvents anyhow
3014 wxUnusedVar(flags);
3015 return false;
3016 #else // !wxHAS_NATIVE_TAB_TRAVERSAL
3017 wxNavigationKeyEvent eventNav;
3018 wxWindow *focused = FindFocus();
3019 eventNav.SetCurrentFocus(focused);
3020 eventNav.SetEventObject(focused);
3021 eventNav.SetFlags(flags);
3022 return GetEventHandler()->ProcessEvent(eventNav);
3023 #endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
3024 }
3025
3026 bool wxWindowBase::HandleAsNavigationKey(const wxKeyEvent& event)
3027 {
3028 if ( event.GetKeyCode() != WXK_TAB )
3029 return false;
3030
3031 int flags = wxNavigationKeyEvent::FromTab;
3032
3033 if ( event.ShiftDown() )
3034 flags |= wxNavigationKeyEvent::IsBackward;
3035 else
3036 flags |= wxNavigationKeyEvent::IsForward;
3037
3038 if ( event.ControlDown() )
3039 flags |= wxNavigationKeyEvent::WinChange;
3040
3041 Navigate(flags);
3042 return true;
3043 }
3044
3045 void wxWindowBase::DoMoveInTabOrder(wxWindow *win, WindowOrder move)
3046 {
3047 // check that we're not a top level window
3048 wxCHECK_RET( GetParent(),
3049 wxT("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
3050
3051 // detect the special case when we have nothing to do anyhow and when the
3052 // code below wouldn't work
3053 if ( win == this )
3054 return;
3055
3056 // find the target window in the siblings list
3057 wxWindowList& siblings = GetParent()->GetChildren();
3058 wxWindowList::compatibility_iterator i = siblings.Find(win);
3059 wxCHECK_RET( i, wxT("MoveBefore/AfterInTabOrder(): win is not a sibling") );
3060
3061 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
3062 // can't just move the node around
3063 wxWindow *self = (wxWindow *)this;
3064 siblings.DeleteObject(self);
3065 if ( move == OrderAfter )
3066 {
3067 i = i->GetNext();
3068 }
3069
3070 if ( i )
3071 {
3072 siblings.Insert(i, self);
3073 }
3074 else // OrderAfter and win was the last sibling
3075 {
3076 siblings.Append(self);
3077 }
3078 }
3079
3080 // ----------------------------------------------------------------------------
3081 // focus handling
3082 // ----------------------------------------------------------------------------
3083
3084 /*static*/ wxWindow* wxWindowBase::FindFocus()
3085 {
3086 wxWindowBase *win = DoFindFocus();
3087 return win ? win->GetMainWindowOfCompositeControl() : NULL;
3088 }
3089
3090 bool wxWindowBase::HasFocus() const
3091 {
3092 wxWindowBase *win = DoFindFocus();
3093 return win == this ||
3094 win == wxConstCast(this, wxWindowBase)->GetMainWindowOfCompositeControl();
3095 }
3096
3097 // ----------------------------------------------------------------------------
3098 // drag and drop
3099 // ----------------------------------------------------------------------------
3100
3101 #if wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3102
3103 namespace
3104 {
3105
3106 class DragAcceptFilesTarget : public wxFileDropTarget
3107 {
3108 public:
3109 DragAcceptFilesTarget(wxWindowBase *win) : m_win(win) {}
3110
3111 virtual bool OnDropFiles(wxCoord x, wxCoord y,
3112 const wxArrayString& filenames)
3113 {
3114 wxDropFilesEvent event(wxEVT_DROP_FILES,
3115 filenames.size(),
3116 wxCArrayString(filenames).Release());
3117 event.SetEventObject(m_win);
3118 event.m_pos.x = x;
3119 event.m_pos.y = y;
3120
3121 return m_win->HandleWindowEvent(event);
3122 }
3123
3124 private:
3125 wxWindowBase * const m_win;
3126
3127 wxDECLARE_NO_COPY_CLASS(DragAcceptFilesTarget);
3128 };
3129
3130
3131 } // anonymous namespace
3132
3133 // Generic version of DragAcceptFiles(). It works by installing a simple
3134 // wxFileDropTarget-to-EVT_DROP_FILES adaptor and therefore cannot be used
3135 // together with explicit SetDropTarget() calls.
3136 void wxWindowBase::DragAcceptFiles(bool accept)
3137 {
3138 if ( accept )
3139 {
3140 wxASSERT_MSG( !GetDropTarget(),
3141 "cannot use DragAcceptFiles() and SetDropTarget() together" );
3142 SetDropTarget(new DragAcceptFilesTarget(this));
3143 }
3144 else
3145 {
3146 SetDropTarget(NULL);
3147 }
3148 }
3149
3150 #endif // wxUSE_DRAG_AND_DROP && !defined(__WXMSW__)
3151
3152 // ----------------------------------------------------------------------------
3153 // global functions
3154 // ----------------------------------------------------------------------------
3155
3156 wxWindow* wxGetTopLevelParent(wxWindow *win)
3157 {
3158 while ( win && !win->IsTopLevel() )
3159 win = win->GetParent();
3160
3161 return win;
3162 }
3163
3164 #if wxUSE_ACCESSIBILITY
3165 // ----------------------------------------------------------------------------
3166 // accessible object for windows
3167 // ----------------------------------------------------------------------------
3168
3169 // Can return either a child object, or an integer
3170 // representing the child element, starting from 1.
3171 wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
3172 {
3173 wxASSERT( GetWindow() != NULL );
3174 if (!GetWindow())
3175 return wxACC_FAIL;
3176
3177 return wxACC_NOT_IMPLEMENTED;
3178 }
3179
3180 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
3181 wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
3182 {
3183 wxASSERT( GetWindow() != NULL );
3184 if (!GetWindow())
3185 return wxACC_FAIL;
3186
3187 wxWindow* win = NULL;
3188 if (elementId == 0)
3189 {
3190 win = GetWindow();
3191 }
3192 else
3193 {
3194 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
3195 {
3196 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
3197 }
3198 else
3199 return wxACC_FAIL;
3200 }
3201 if (win)
3202 {
3203 rect = win->GetRect();
3204 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
3205 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
3206 return wxACC_OK;
3207 }
3208
3209 return wxACC_NOT_IMPLEMENTED;
3210 }
3211
3212 // Navigates from fromId to toId/toObject.
3213 wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
3214 int* WXUNUSED(toId), wxAccessible** toObject)
3215 {
3216 wxASSERT( GetWindow() != NULL );
3217 if (!GetWindow())
3218 return wxACC_FAIL;
3219
3220 switch (navDir)
3221 {
3222 case wxNAVDIR_FIRSTCHILD:
3223 {
3224 if (GetWindow()->GetChildren().GetCount() == 0)
3225 return wxACC_FALSE;
3226 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
3227 *toObject = childWindow->GetOrCreateAccessible();
3228
3229 return wxACC_OK;
3230 }
3231 case wxNAVDIR_LASTCHILD:
3232 {
3233 if (GetWindow()->GetChildren().GetCount() == 0)
3234 return wxACC_FALSE;
3235 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
3236 *toObject = childWindow->GetOrCreateAccessible();
3237
3238 return wxACC_OK;
3239 }
3240 case wxNAVDIR_RIGHT:
3241 case wxNAVDIR_DOWN:
3242 case wxNAVDIR_NEXT:
3243 {
3244 wxWindowList::compatibility_iterator node =
3245 wxWindowList::compatibility_iterator();
3246 if (fromId == 0)
3247 {
3248 // Can't navigate to sibling of this window
3249 // if we're a top-level window.
3250 if (!GetWindow()->GetParent())
3251 return wxACC_NOT_IMPLEMENTED;
3252
3253 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3254 }
3255 else
3256 {
3257 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
3258 node = GetWindow()->GetChildren().Item(fromId-1);
3259 }
3260
3261 if (node && node->GetNext())
3262 {
3263 wxWindow* nextWindow = node->GetNext()->GetData();
3264 *toObject = nextWindow->GetOrCreateAccessible();
3265 return wxACC_OK;
3266 }
3267 else
3268 return wxACC_FALSE;
3269 }
3270 case wxNAVDIR_LEFT:
3271 case wxNAVDIR_UP:
3272 case wxNAVDIR_PREVIOUS:
3273 {
3274 wxWindowList::compatibility_iterator node =
3275 wxWindowList::compatibility_iterator();
3276 if (fromId == 0)
3277 {
3278 // Can't navigate to sibling of this window
3279 // if we're a top-level window.
3280 if (!GetWindow()->GetParent())
3281 return wxACC_NOT_IMPLEMENTED;
3282
3283 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
3284 }
3285 else
3286 {
3287 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
3288 node = GetWindow()->GetChildren().Item(fromId-1);
3289 }
3290
3291 if (node && node->GetPrevious())
3292 {
3293 wxWindow* previousWindow = node->GetPrevious()->GetData();
3294 *toObject = previousWindow->GetOrCreateAccessible();
3295 return wxACC_OK;
3296 }
3297 else
3298 return wxACC_FALSE;
3299 }
3300 }
3301
3302 return wxACC_NOT_IMPLEMENTED;
3303 }
3304
3305 // Gets the name of the specified object.
3306 wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
3307 {
3308 wxASSERT( GetWindow() != NULL );
3309 if (!GetWindow())
3310 return wxACC_FAIL;
3311
3312 wxString title;
3313
3314 // If a child, leave wxWidgets to call the function on the actual
3315 // child object.
3316 if (childId > 0)
3317 return wxACC_NOT_IMPLEMENTED;
3318
3319 // This will eventually be replaced by specialised
3320 // accessible classes, one for each kind of wxWidgets
3321 // control or window.
3322 #if wxUSE_BUTTON
3323 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
3324 title = ((wxButton*) GetWindow())->GetLabel();
3325 else
3326 #endif
3327 title = GetWindow()->GetName();
3328
3329 if (!title.empty())
3330 {
3331 *name = title;
3332 return wxACC_OK;
3333 }
3334 else
3335 return wxACC_NOT_IMPLEMENTED;
3336 }
3337
3338 // Gets the number of children.
3339 wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
3340 {
3341 wxASSERT( GetWindow() != NULL );
3342 if (!GetWindow())
3343 return wxACC_FAIL;
3344
3345 *childId = (int) GetWindow()->GetChildren().GetCount();
3346 return wxACC_OK;
3347 }
3348
3349 // Gets the specified child (starting from 1).
3350 // If *child is NULL and return value is wxACC_OK,
3351 // this means that the child is a simple element and
3352 // not an accessible object.
3353 wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
3354 {
3355 wxASSERT( GetWindow() != NULL );
3356 if (!GetWindow())
3357 return wxACC_FAIL;
3358
3359 if (childId == 0)
3360 {
3361 *child = this;
3362 return wxACC_OK;
3363 }
3364
3365 if (childId > (int) GetWindow()->GetChildren().GetCount())
3366 return wxACC_FAIL;
3367
3368 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
3369 *child = childWindow->GetOrCreateAccessible();
3370 if (*child)
3371 return wxACC_OK;
3372 else
3373 return wxACC_FAIL;
3374 }
3375
3376 // Gets the parent, or NULL.
3377 wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
3378 {
3379 wxASSERT( GetWindow() != NULL );
3380 if (!GetWindow())
3381 return wxACC_FAIL;
3382
3383 wxWindow* parentWindow = GetWindow()->GetParent();
3384 if (!parentWindow)
3385 {
3386 *parent = NULL;
3387 return wxACC_OK;
3388 }
3389 else
3390 {
3391 *parent = parentWindow->GetOrCreateAccessible();
3392 if (*parent)
3393 return wxACC_OK;
3394 else
3395 return wxACC_FAIL;
3396 }
3397 }
3398
3399 // Performs the default action. childId is 0 (the action for this object)
3400 // or > 0 (the action for a child).
3401 // Return wxACC_NOT_SUPPORTED if there is no default action for this
3402 // window (e.g. an edit control).
3403 wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
3404 {
3405 wxASSERT( GetWindow() != NULL );
3406 if (!GetWindow())
3407 return wxACC_FAIL;
3408
3409 return wxACC_NOT_IMPLEMENTED;
3410 }
3411
3412 // Gets the default action for this object (0) or > 0 (the action for a child).
3413 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
3414 // string if there is no action.
3415 // The retrieved string describes the action that is performed on an object,
3416 // not what the object does as a result. For example, a toolbar button that prints
3417 // a document has a default action of "Press" rather than "Prints the current document."
3418 wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
3419 {
3420 wxASSERT( GetWindow() != NULL );
3421 if (!GetWindow())
3422 return wxACC_FAIL;
3423
3424 return wxACC_NOT_IMPLEMENTED;
3425 }
3426
3427 // Returns the description for this object or a child.
3428 wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
3429 {
3430 wxASSERT( GetWindow() != NULL );
3431 if (!GetWindow())
3432 return wxACC_FAIL;
3433
3434 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
3435 if (!ht.empty())
3436 {
3437 *description = ht;
3438 return wxACC_OK;
3439 }
3440 return wxACC_NOT_IMPLEMENTED;
3441 }
3442
3443 // Returns help text for this object or a child, similar to tooltip text.
3444 wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
3445 {
3446 wxASSERT( GetWindow() != NULL );
3447 if (!GetWindow())
3448 return wxACC_FAIL;
3449
3450 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
3451 if (!ht.empty())
3452 {
3453 *helpText = ht;
3454 return wxACC_OK;
3455 }
3456 return wxACC_NOT_IMPLEMENTED;
3457 }
3458
3459 // Returns the keyboard shortcut for this object or child.
3460 // Return e.g. ALT+K
3461 wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
3462 {
3463 wxASSERT( GetWindow() != NULL );
3464 if (!GetWindow())
3465 return wxACC_FAIL;
3466
3467 return wxACC_NOT_IMPLEMENTED;
3468 }
3469
3470 // Returns a role constant.
3471 wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
3472 {
3473 wxASSERT( GetWindow() != NULL );
3474 if (!GetWindow())
3475 return wxACC_FAIL;
3476
3477 // If a child, leave wxWidgets to call the function on the actual
3478 // child object.
3479 if (childId > 0)
3480 return wxACC_NOT_IMPLEMENTED;
3481
3482 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
3483 return wxACC_NOT_IMPLEMENTED;
3484 #if wxUSE_STATUSBAR
3485 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
3486 return wxACC_NOT_IMPLEMENTED;
3487 #endif
3488 #if wxUSE_TOOLBAR
3489 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
3490 return wxACC_NOT_IMPLEMENTED;
3491 #endif
3492
3493 //*role = wxROLE_SYSTEM_CLIENT;
3494 *role = wxROLE_SYSTEM_CLIENT;
3495 return wxACC_OK;
3496
3497 #if 0
3498 return wxACC_NOT_IMPLEMENTED;
3499 #endif
3500 }
3501
3502 // Returns a state constant.
3503 wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
3504 {
3505 wxASSERT( GetWindow() != NULL );
3506 if (!GetWindow())
3507 return wxACC_FAIL;
3508
3509 // If a child, leave wxWidgets to call the function on the actual
3510 // child object.
3511 if (childId > 0)
3512 return wxACC_NOT_IMPLEMENTED;
3513
3514 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
3515 return wxACC_NOT_IMPLEMENTED;
3516
3517 #if wxUSE_STATUSBAR
3518 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
3519 return wxACC_NOT_IMPLEMENTED;
3520 #endif
3521 #if wxUSE_TOOLBAR
3522 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
3523 return wxACC_NOT_IMPLEMENTED;
3524 #endif
3525
3526 *state = 0;
3527 return wxACC_OK;
3528
3529 #if 0
3530 return wxACC_NOT_IMPLEMENTED;
3531 #endif
3532 }
3533
3534 // Returns a localized string representing the value for the object
3535 // or child.
3536 wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
3537 {
3538 wxASSERT( GetWindow() != NULL );
3539 if (!GetWindow())
3540 return wxACC_FAIL;
3541
3542 return wxACC_NOT_IMPLEMENTED;
3543 }
3544
3545 // Selects the object or child.
3546 wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
3547 {
3548 wxASSERT( GetWindow() != NULL );
3549 if (!GetWindow())
3550 return wxACC_FAIL;
3551
3552 return wxACC_NOT_IMPLEMENTED;
3553 }
3554
3555 // Gets the window with the keyboard focus.
3556 // If childId is 0 and child is NULL, no object in
3557 // this subhierarchy has the focus.
3558 // If this object has the focus, child should be 'this'.
3559 wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
3560 {
3561 wxASSERT( GetWindow() != NULL );
3562 if (!GetWindow())
3563 return wxACC_FAIL;
3564
3565 return wxACC_NOT_IMPLEMENTED;
3566 }
3567
3568 #if wxUSE_VARIANT
3569 // Gets a variant representing the selected children
3570 // of this object.
3571 // Acceptable values:
3572 // - a null variant (IsNull() returns true)
3573 // - a list variant (GetType() == wxT("list")
3574 // - an integer representing the selected child element,
3575 // or 0 if this object is selected (GetType() == wxT("long")
3576 // - a "void*" pointer to a wxAccessible child object
3577 wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
3578 {
3579 wxASSERT( GetWindow() != NULL );
3580 if (!GetWindow())
3581 return wxACC_FAIL;
3582
3583 return wxACC_NOT_IMPLEMENTED;
3584 }
3585 #endif // wxUSE_VARIANT
3586
3587 #endif // wxUSE_ACCESSIBILITY
3588
3589 // ----------------------------------------------------------------------------
3590 // RTL support
3591 // ----------------------------------------------------------------------------
3592
3593 wxCoord
3594 wxWindowBase::AdjustForLayoutDirection(wxCoord x,
3595 wxCoord width,
3596 wxCoord widthTotal) const
3597 {
3598 if ( GetLayoutDirection() == wxLayout_RightToLeft )
3599 {
3600 x = widthTotal - x - width;
3601 }
3602
3603 return x;
3604 }
3605
3606