]> git.saurik.com Git - wxWidgets.git/blob - src/common/wincmn.cpp
support for unicode font names
[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/defs.h"
33 #include "wx/window.h"
34 #include "wx/control.h"
35 #include "wx/checkbox.h"
36 #include "wx/radiobut.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/dialog.h"
41 #include "wx/msgdlg.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
45 #endif //WX_PRECOMP
46
47 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
48 #include "wx/scrolbar.h"
49 #endif
50
51 #if wxUSE_CONSTRAINTS
52 #include "wx/layout.h"
53 #endif // wxUSE_CONSTRAINTS
54
55 #include "wx/sizer.h"
56
57 #if wxUSE_DRAG_AND_DROP
58 #include "wx/dnd.h"
59 #endif // wxUSE_DRAG_AND_DROP
60
61 #if wxUSE_ACCESSIBILITY
62 #include "wx/access.h"
63 #endif
64
65 #if wxUSE_HELP
66 #include "wx/cshelp.h"
67 #endif // wxUSE_HELP
68
69 #if wxUSE_TOOLTIPS
70 #include "wx/tooltip.h"
71 #endif // wxUSE_TOOLTIPS
72
73 #if wxUSE_CARET
74 #include "wx/caret.h"
75 #endif // wxUSE_CARET
76
77 #if wxUSE_SYSTEM_OPTIONS
78 #include "wx/sysopt.h"
79 #endif
80
81 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
82 // The gtk includes don't pull any other headers in, at least not on my system - MR
83 #ifdef __WXGTK__
84 #ifdef __WXGTK20__
85 #include <gtk/gtkversion.h>
86 #else
87 #include <gtk/gtkfeatures.h>
88 #endif
89 extern const unsigned int gtk_major_version;
90 extern const unsigned int gtk_minor_version;
91 extern const unsigned int gtk_micro_version;
92 #endif
93
94 // ----------------------------------------------------------------------------
95 // static data
96 // ----------------------------------------------------------------------------
97
98 #if defined(__WXPALMOS__)
99 int wxWindowBase::ms_lastControlId = 32767;
100 #elif defined(__WXPM__)
101 int wxWindowBase::ms_lastControlId = 2000;
102 #else
103 int wxWindowBase::ms_lastControlId = -200;
104 #endif
105
106 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
107
108 // ----------------------------------------------------------------------------
109 // event table
110 // ----------------------------------------------------------------------------
111
112 BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
113 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
114 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
115 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
116
117 #if wxUSE_HELP
118 EVT_HELP(wxID_ANY, wxWindowBase::OnHelp)
119 #endif // wxUSE_HELP
120
121 END_EVENT_TABLE()
122
123 // ============================================================================
124 // implementation of the common functionality of the wxWindow class
125 // ============================================================================
126
127 // ----------------------------------------------------------------------------
128 // initialization
129 // ----------------------------------------------------------------------------
130
131 // the default initialization
132 wxWindowBase::wxWindowBase()
133 {
134 // no window yet, no parent nor children
135 m_parent = (wxWindow *)NULL;
136 m_windowId = wxID_ANY;
137
138 // no constraints on the minimal window size
139 m_minWidth =
140 m_maxWidth = wxDefaultCoord;
141 m_minHeight =
142 m_maxHeight = wxDefaultCoord;
143
144 // invalidiated cache value
145 m_bestSizeCache = wxDefaultSize;
146
147 // window are created enabled and visible by default
148 m_isShown =
149 m_isEnabled = true;
150
151 // the default event handler is just this window
152 m_eventHandler = this;
153
154 #if wxUSE_VALIDATORS
155 // no validator
156 m_windowValidator = (wxValidator *) NULL;
157 #endif // wxUSE_VALIDATORS
158
159 // the colours/fonts are default for now, so leave m_font,
160 // m_backgroundColour and m_foregroundColour uninitialized and set those
161 m_hasBgCol =
162 m_hasFgCol =
163 m_hasFont = false;
164 m_inheritBgCol =
165 m_inheritFgCol =
166 m_inheritFont = false;
167
168 // no style bits
169 m_exStyle =
170 m_windowStyle = 0;
171
172 m_backgroundStyle = wxBG_STYLE_SYSTEM;
173
174 #if wxUSE_CONSTRAINTS
175 // no constraints whatsoever
176 m_constraints = (wxLayoutConstraints *) NULL;
177 m_constraintsInvolvedIn = (wxWindowList *) NULL;
178 #endif // wxUSE_CONSTRAINTS
179
180 m_windowSizer = (wxSizer *) NULL;
181 m_containingSizer = (wxSizer *) NULL;
182 m_autoLayout = false;
183
184 #if wxUSE_DRAG_AND_DROP
185 m_dropTarget = (wxDropTarget *)NULL;
186 #endif // wxUSE_DRAG_AND_DROP
187
188 #if wxUSE_TOOLTIPS
189 m_tooltip = (wxToolTip *)NULL;
190 #endif // wxUSE_TOOLTIPS
191
192 #if wxUSE_CARET
193 m_caret = (wxCaret *)NULL;
194 #endif // wxUSE_CARET
195
196 #if wxUSE_PALETTE
197 m_hasCustomPalette = false;
198 #endif // wxUSE_PALETTE
199
200 #if wxUSE_ACCESSIBILITY
201 m_accessible = NULL;
202 #endif
203
204 m_virtualSize = wxDefaultSize;
205
206 m_minVirtualWidth =
207 m_maxVirtualWidth = wxDefaultCoord;
208 m_minVirtualHeight =
209 m_maxVirtualHeight = wxDefaultCoord;
210
211 m_windowVariant = wxWINDOW_VARIANT_NORMAL;
212 #if wxUSE_SYSTEM_OPTIONS
213 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT) )
214 {
215 m_windowVariant = (wxWindowVariant) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT ) ;
216 }
217 #endif
218
219 // Whether we're using the current theme for this window (wxGTK only for now)
220 m_themeEnabled = false;
221
222 // VZ: this one shouldn't exist...
223 m_isBeingDeleted = false;
224
225 // Reserved for future use
226 m_windowReserved = NULL;
227 }
228
229 // common part of window creation process
230 bool wxWindowBase::CreateBase(wxWindowBase *parent,
231 wxWindowID id,
232 const wxPoint& WXUNUSED(pos),
233 const wxSize& WXUNUSED(size),
234 long style,
235 const wxValidator& wxVALIDATOR_PARAM(validator),
236 const wxString& name)
237 {
238 #if wxUSE_STATBOX
239 // wxGTK doesn't allow to create controls with static box as the parent so
240 // this will result in a crash when the program is ported to wxGTK so warn
241 // the user about it
242
243 // if you get this assert, the correct solution is to create the controls
244 // as siblings of the static box
245 wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox),
246 _T("wxStaticBox can't be used as a window parent!") );
247 #endif // wxUSE_STATBOX
248
249 // ids are limited to 16 bits under MSW so if you care about portability,
250 // it's not a good idea to use ids out of this range (and negative ids are
251 // reserved for wxWidgets own usage)
252 wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767),
253 _T("invalid id value") );
254
255 // generate a new id if the user doesn't care about it
256 m_windowId = id == wxID_ANY ? NewControlId() : id;
257
258 SetName(name);
259 SetWindowStyleFlag(style);
260 SetParent(parent);
261
262 #if wxUSE_VALIDATORS
263 SetValidator(validator);
264 #endif // wxUSE_VALIDATORS
265
266 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
267 // have it too - like this it's possible to set it only in the top level
268 // dialog/frame and all children will inherit it by defult
269 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
270 {
271 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
272 }
273
274 return true;
275 }
276
277 // ----------------------------------------------------------------------------
278 // destruction
279 // ----------------------------------------------------------------------------
280
281 // common clean up
282 wxWindowBase::~wxWindowBase()
283 {
284 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
285
286 // FIXME if these 2 cases result from programming errors in the user code
287 // we should probably assert here instead of silently fixing them
288
289 // Just in case the window has been Closed, but we're then deleting
290 // immediately: don't leave dangling pointers.
291 wxPendingDelete.DeleteObject(this);
292
293 // Just in case we've loaded a top-level window via LoadNativeDialog but
294 // we weren't a dialog class
295 wxTopLevelWindows.DeleteObject((wxWindow*)this);
296
297 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
298
299 // reset the dangling pointer our parent window may keep to us
300 if ( m_parent )
301 {
302 if ( m_parent->GetDefaultItem() == this )
303 {
304 m_parent->SetDefaultItem(NULL);
305 }
306
307 m_parent->RemoveChild(this);
308 }
309
310 #if wxUSE_CARET
311 delete m_caret;
312 #endif // wxUSE_CARET
313
314 #if wxUSE_VALIDATORS
315 delete m_windowValidator;
316 #endif // wxUSE_VALIDATORS
317
318 #if wxUSE_CONSTRAINTS
319 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
320 // at deleted windows as they delete themselves.
321 DeleteRelatedConstraints();
322
323 if ( m_constraints )
324 {
325 // This removes any dangling pointers to this window in other windows'
326 // constraintsInvolvedIn lists.
327 UnsetConstraints(m_constraints);
328 delete m_constraints;
329 m_constraints = NULL;
330 }
331 #endif // wxUSE_CONSTRAINTS
332
333 if ( m_containingSizer )
334 m_containingSizer->Detach( (wxWindow*)this );
335
336 delete m_windowSizer;
337
338 #if wxUSE_DRAG_AND_DROP
339 delete m_dropTarget;
340 #endif // wxUSE_DRAG_AND_DROP
341
342 #if wxUSE_TOOLTIPS
343 delete m_tooltip;
344 #endif // wxUSE_TOOLTIPS
345
346 #if wxUSE_ACCESSIBILITY
347 delete m_accessible;
348 #endif
349 }
350
351 bool wxWindowBase::Destroy()
352 {
353 delete this;
354
355 return true;
356 }
357
358 bool wxWindowBase::Close(bool force)
359 {
360 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
361 event.SetEventObject(this);
362 event.SetCanVeto(!force);
363
364 // return false if window wasn't closed because the application vetoed the
365 // close event
366 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
367 }
368
369 bool wxWindowBase::DestroyChildren()
370 {
371 wxWindowList::compatibility_iterator node;
372 for ( ;; )
373 {
374 // we iterate until the list becomes empty
375 node = GetChildren().GetFirst();
376 if ( !node )
377 break;
378
379 wxWindow *child = node->GetData();
380
381 // note that we really want to call delete and not ->Destroy() here
382 // because we want to delete the child immediately, before we are
383 // deleted, and delayed deletion would result in problems as our (top
384 // level) child could outlive its parent
385 delete child;
386
387 wxASSERT_MSG( !GetChildren().Find(child),
388 wxT("child didn't remove itself using RemoveChild()") );
389 }
390
391 return true;
392 }
393
394 // ----------------------------------------------------------------------------
395 // size/position related methods
396 // ----------------------------------------------------------------------------
397
398 // centre the window with respect to its parent in either (or both) directions
399 void wxWindowBase::DoCentre(int dir)
400 {
401 wxCHECK_RET( !(dir & wxCENTRE_ON_SCREEN) && GetParent(),
402 _T("this method only implements centering child windows") );
403
404 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir));
405 }
406
407 // fits the window around the children
408 void wxWindowBase::Fit()
409 {
410 if ( !GetChildren().empty() )
411 {
412 SetClientSize(GetBestSize());
413 }
414 //else: do nothing if we have no children
415 }
416
417 // fits virtual size (ie. scrolled area etc.) around children
418 void wxWindowBase::FitInside()
419 {
420 if ( GetChildren().GetCount() > 0 )
421 {
422 SetVirtualSize( GetBestVirtualSize() );
423 }
424 }
425
426 // On Mac, scrollbars are explicitly children.
427 #ifdef __WXMAC__
428 static bool wxHasRealChildren(const wxWindowBase* win)
429 {
430 int realChildCount = 0;
431
432 for ( wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
433 node;
434 node = node->GetNext() )
435 {
436 wxWindow *win = node->GetData();
437 if ( !win->IsTopLevel() && win->IsShown() && !win->IsKindOf(CLASSINFO(wxScrollBar)))
438 realChildCount ++;
439 }
440 return (realChildCount > 0);
441 }
442 #endif
443
444 void wxWindowBase::InvalidateBestSize()
445 {
446 m_bestSizeCache = wxDefaultSize;
447
448 // parent's best size calculation may depend on its children's
449 // as long as child window we are in is not top level window itself
450 // (because the TLW size is never resized automatically)
451 // so let's invalidate it as well to be safe:
452 if (m_parent && !IsTopLevel())
453 m_parent->InvalidateBestSize();
454 }
455
456 // return the size best suited for the current window
457 wxSize wxWindowBase::DoGetBestSize() const
458 {
459 wxSize best;
460
461 if ( m_windowSizer )
462 {
463 best = GetWindowSizeForVirtualSize(m_windowSizer->GetMinSize());
464 }
465 #if wxUSE_CONSTRAINTS
466 else if ( m_constraints )
467 {
468 wxConstCast(this, wxWindowBase)->SatisfyConstraints();
469
470 // our minimal acceptable size is such that all our windows fit inside
471 int maxX = 0,
472 maxY = 0;
473
474 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
475 node;
476 node = node->GetNext() )
477 {
478 wxLayoutConstraints *c = node->GetData()->GetConstraints();
479 if ( !c )
480 {
481 // it's not normal that we have an unconstrained child, but
482 // what can we do about it?
483 continue;
484 }
485
486 int x = c->right.GetValue(),
487 y = c->bottom.GetValue();
488
489 if ( x > maxX )
490 maxX = x;
491
492 if ( y > maxY )
493 maxY = y;
494
495 // TODO: we must calculate the overlaps somehow, otherwise we
496 // will never return a size bigger than the current one :-(
497 }
498
499 best = wxSize(maxX, maxY);
500 }
501 #endif // wxUSE_CONSTRAINTS
502 else if ( !GetChildren().empty()
503 #ifdef __WXMAC__
504 && wxHasRealChildren(this)
505 #endif
506 )
507 {
508 // our minimal acceptable size is such that all our visible child windows fit inside
509 int maxX = 0,
510 maxY = 0;
511
512 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
513 node;
514 node = node->GetNext() )
515 {
516 wxWindow *win = node->GetData();
517 if ( win->IsTopLevel() || ( ! win->IsShown() )
518 #if wxUSE_STATUSBAR
519 || wxDynamicCast(win, wxStatusBar)
520 #endif // wxUSE_STATUSBAR
521 )
522 {
523 // dialogs and frames lie in different top level windows -
524 // don't deal with them here; as for the status bars, they
525 // don't lie in the client area at all
526 continue;
527 }
528
529 int wx, wy, ww, wh;
530 win->GetPosition(&wx, &wy);
531
532 // if the window hadn't been positioned yet, assume that it is in
533 // the origin
534 if ( wx == wxDefaultCoord )
535 wx = 0;
536 if ( wy == wxDefaultCoord )
537 wy = 0;
538
539 win->GetSize(&ww, &wh);
540 if ( wx + ww > maxX )
541 maxX = wx + ww;
542 if ( wy + wh > maxY )
543 maxY = wy + wh;
544 }
545
546 // for compatibility with the old versions and because it really looks
547 // slightly more pretty like this, add a pad
548 maxX += 7;
549 maxY += 14;
550
551 best = wxSize(maxX, maxY);
552 }
553 else // ! has children
554 {
555 // for a generic window there is no natural best size so, if the
556 // minimal size is not set, use the current size but take care to
557 // remember it as minimal size for the next time because our best size
558 // should be constant: otherwise we could get into a situation when the
559 // window is initially at some size, then expanded to a larger size and
560 // then, when the containing window is shrunk back (because our initial
561 // best size had been used for computing the parent min size), we can't
562 // be shrunk back any more because our best size is now bigger
563 wxSize size = GetMinSize();
564 if ( !size.IsFullySpecified() )
565 {
566 size.SetDefaults(GetSize());
567 wxConstCast(this, wxWindowBase)->SetMinSize(size);
568 }
569
570 // return as-is, unadjusted by the client size difference.
571 return size;
572 }
573
574 // Add any difference between size and client size
575 wxSize diff = GetSize() - GetClientSize();
576 best.x += wxMax(0, diff.x);
577 best.y += wxMax(0, diff.y);
578
579 return best;
580 }
581
582
583 wxSize wxWindowBase::GetBestFittingSize() const
584 {
585 // merge the best size with the min size, giving priority to the min size
586 wxSize min = GetMinSize();
587 if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
588 {
589 wxSize best = GetBestSize();
590 if (min.x == wxDefaultCoord) min.x = best.x;
591 if (min.y == wxDefaultCoord) min.y = best.y;
592 }
593 return min;
594 }
595
596
597 void wxWindowBase::SetBestFittingSize(const wxSize& size)
598 {
599 // Set the min size to the size passed in. This will usually either be
600 // wxDefaultSize or the size passed to this window's ctor/Create function.
601 SetMinSize(size);
602
603 // Merge the size with the best size if needed
604 wxSize best = GetBestFittingSize();
605
606 // If the current size doesn't match then change it
607 if (GetSize() != best)
608 SetSize(best);
609 }
610
611
612 // by default the origin is not shifted
613 wxPoint wxWindowBase::GetClientAreaOrigin() const
614 {
615 return wxPoint(0,0);
616 }
617
618 // set the min/max size of the window
619 void wxWindowBase::DoSetSizeHints(int minW, int minH,
620 int maxW, int maxH,
621 int WXUNUSED(incW), int WXUNUSED(incH))
622 {
623 // setting min width greater than max width leads to infinite loops under
624 // X11 and generally doesn't make any sense, so don't allow it
625 wxCHECK_RET( (minW == wxDefaultCoord || maxW == wxDefaultCoord || minW <= maxW) &&
626 (minH == wxDefaultCoord || maxH == wxDefaultCoord || minH <= maxH),
627 _T("min width/height must be less than max width/height!") );
628
629 m_minWidth = minW;
630 m_maxWidth = maxW;
631 m_minHeight = minH;
632 m_maxHeight = maxH;
633 }
634
635 void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
636 {
637 if ( m_windowVariant != variant )
638 {
639 m_windowVariant = variant;
640
641 DoSetWindowVariant(variant);
642 }
643 }
644
645 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
646 {
647 // adjust the font height to correspond to our new variant (notice that
648 // we're only called if something really changed)
649 wxFont font = GetFont();
650 int size = font.GetPointSize();
651 switch ( variant )
652 {
653 case wxWINDOW_VARIANT_NORMAL:
654 break;
655
656 case wxWINDOW_VARIANT_SMALL:
657 size *= 3;
658 size /= 4;
659 break;
660
661 case wxWINDOW_VARIANT_MINI:
662 size *= 2;
663 size /= 3;
664 break;
665
666 case wxWINDOW_VARIANT_LARGE:
667 size *= 5;
668 size /= 4;
669 break;
670
671 default:
672 wxFAIL_MSG(_T("unexpected window variant"));
673 break;
674 }
675
676 font.SetPointSize(size);
677 SetFont(font);
678 }
679
680 void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
681 int maxW, int maxH )
682 {
683 m_minVirtualWidth = minW;
684 m_maxVirtualWidth = maxW;
685 m_minVirtualHeight = minH;
686 m_maxVirtualHeight = maxH;
687 }
688
689 void wxWindowBase::DoSetVirtualSize( int x, int y )
690 {
691 if ( m_minVirtualWidth != wxDefaultCoord && m_minVirtualWidth > x )
692 x = m_minVirtualWidth;
693 if ( m_maxVirtualWidth != wxDefaultCoord && m_maxVirtualWidth < x )
694 x = m_maxVirtualWidth;
695 if ( m_minVirtualHeight != wxDefaultCoord && m_minVirtualHeight > y )
696 y = m_minVirtualHeight;
697 if ( m_maxVirtualHeight != wxDefaultCoord && m_maxVirtualHeight < y )
698 y = m_maxVirtualHeight;
699
700 m_virtualSize = wxSize(x, y);
701 }
702
703 wxSize wxWindowBase::DoGetVirtualSize() const
704 {
705 // we should use the entire client area so if it is greater than our
706 // virtual size, expand it to fit (otherwise if the window is big enough we
707 // wouldn't be using parts of it)
708 wxSize size = GetClientSize();
709 if ( m_virtualSize.x > size.x )
710 size.x = m_virtualSize.x;
711
712 if ( m_virtualSize.y >= size.y )
713 size.y = m_virtualSize.y;
714
715 return size;
716 }
717
718 // ----------------------------------------------------------------------------
719 // show/hide/enable/disable the window
720 // ----------------------------------------------------------------------------
721
722 bool wxWindowBase::Show(bool show)
723 {
724 if ( show != m_isShown )
725 {
726 m_isShown = show;
727
728 return true;
729 }
730 else
731 {
732 return false;
733 }
734 }
735
736 bool wxWindowBase::Enable(bool enable)
737 {
738 if ( enable != m_isEnabled )
739 {
740 m_isEnabled = enable;
741
742 return true;
743 }
744 else
745 {
746 return false;
747 }
748 }
749 // ----------------------------------------------------------------------------
750 // RTTI
751 // ----------------------------------------------------------------------------
752
753 bool wxWindowBase::IsTopLevel() const
754 {
755 return false;
756 }
757
758 // ----------------------------------------------------------------------------
759 // reparenting the window
760 // ----------------------------------------------------------------------------
761
762 void wxWindowBase::AddChild(wxWindowBase *child)
763 {
764 wxCHECK_RET( child, wxT("can't add a NULL child") );
765
766 // this should never happen and it will lead to a crash later if it does
767 // because RemoveChild() will remove only one node from the children list
768 // and the other(s) one(s) will be left with dangling pointers in them
769 wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") );
770
771 GetChildren().Append((wxWindow*)child);
772 child->SetParent(this);
773 }
774
775 void wxWindowBase::RemoveChild(wxWindowBase *child)
776 {
777 wxCHECK_RET( child, wxT("can't remove a NULL child") );
778
779 GetChildren().DeleteObject((wxWindow *)child);
780 child->SetParent(NULL);
781 }
782
783 bool wxWindowBase::Reparent(wxWindowBase *newParent)
784 {
785 wxWindow *oldParent = GetParent();
786 if ( newParent == oldParent )
787 {
788 // nothing done
789 return false;
790 }
791
792 // unlink this window from the existing parent.
793 if ( oldParent )
794 {
795 oldParent->RemoveChild(this);
796 }
797 else
798 {
799 wxTopLevelWindows.DeleteObject((wxWindow *)this);
800 }
801
802 // add it to the new one
803 if ( newParent )
804 {
805 newParent->AddChild(this);
806 }
807 else
808 {
809 wxTopLevelWindows.Append((wxWindow *)this);
810 }
811
812 return true;
813 }
814
815 // ----------------------------------------------------------------------------
816 // event handler stuff
817 // ----------------------------------------------------------------------------
818
819 void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
820 {
821 wxEvtHandler *handlerOld = GetEventHandler();
822
823 handler->SetNextHandler(handlerOld);
824
825 if ( handlerOld )
826 GetEventHandler()->SetPreviousHandler(handler);
827
828 SetEventHandler(handler);
829 }
830
831 wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
832 {
833 wxEvtHandler *handlerA = GetEventHandler();
834 if ( handlerA )
835 {
836 wxEvtHandler *handlerB = handlerA->GetNextHandler();
837 handlerA->SetNextHandler((wxEvtHandler *)NULL);
838
839 if ( handlerB )
840 handlerB->SetPreviousHandler((wxEvtHandler *)NULL);
841 SetEventHandler(handlerB);
842
843 if ( deleteHandler )
844 {
845 delete handlerA;
846 handlerA = (wxEvtHandler *)NULL;
847 }
848 }
849
850 return handlerA;
851 }
852
853 bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
854 {
855 wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") );
856
857 wxEvtHandler *handlerPrev = NULL,
858 *handlerCur = GetEventHandler();
859 while ( handlerCur )
860 {
861 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
862
863 if ( handlerCur == handler )
864 {
865 if ( handlerPrev )
866 {
867 handlerPrev->SetNextHandler(handlerNext);
868 }
869 else
870 {
871 SetEventHandler(handlerNext);
872 }
873
874 if ( handlerNext )
875 {
876 handlerNext->SetPreviousHandler ( handlerPrev );
877 }
878
879 handler->SetNextHandler(NULL);
880 handler->SetPreviousHandler(NULL);
881
882 return true;
883 }
884
885 handlerPrev = handlerCur;
886 handlerCur = handlerNext;
887 }
888
889 wxFAIL_MSG( _T("where has the event handler gone?") );
890
891 return false;
892 }
893
894 // ----------------------------------------------------------------------------
895 // colours, fonts &c
896 // ----------------------------------------------------------------------------
897
898 void wxWindowBase::InheritAttributes()
899 {
900 const wxWindowBase * const parent = GetParent();
901 if ( !parent )
902 return;
903
904 // we only inherit attributes which had been explicitly set for the parent
905 // which ensures that this only happens if the user really wants it and
906 // not by default which wouldn't make any sense in modern GUIs where the
907 // controls don't all use the same fonts (nor colours)
908 if ( parent->m_inheritFont && !m_hasFont )
909 SetFont(parent->GetFont());
910
911 // in addition, there is a possibility to explicitly forbid inheriting
912 // colours at each class level by overriding ShouldInheritColours()
913 if ( ShouldInheritColours() )
914 {
915 if ( parent->m_inheritFgCol && !m_hasFgCol )
916 SetForegroundColour(parent->GetForegroundColour());
917
918 // inheriting (solid) background colour is wrong as it totally breaks
919 // any kind of themed backgrounds
920 //
921 // instead, the controls should use the same background as their parent
922 // (ideally by not drawing it at all)
923 #if 0
924 if ( parent->m_inheritBgCol && !m_hasBgCol )
925 SetBackgroundColour(parent->GetBackgroundColour());
926 #endif // 0
927 }
928 }
929
930 /* static */ wxVisualAttributes
931 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
932 {
933 // it is important to return valid values for all attributes from here,
934 // GetXXX() below rely on this
935 wxVisualAttributes attrs;
936 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
937 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
938
939 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
940 // the usual background colour than wxSYS_COLOUR_BTNFACE.
941 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
942 // colour on other platforms.
943
944 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
945 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
946 #else
947 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
948 #endif
949 return attrs;
950 }
951
952 wxColour wxWindowBase::GetBackgroundColour() const
953 {
954 if ( !m_backgroundColour.Ok() )
955 {
956 wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") );
957
958 // get our default background colour
959 wxColour colBg = GetDefaultAttributes().colBg;
960
961 // we must return some valid colour to avoid redoing this every time
962 // and also to avoid surprizing the applications written for older
963 // wxWidgets versions where GetBackgroundColour() always returned
964 // something -- so give them something even if it doesn't make sense
965 // for this window (e.g. it has a themed background)
966 if ( !colBg.Ok() )
967 colBg = GetClassDefaultAttributes().colBg;
968
969 return colBg;
970 }
971 else
972 return m_backgroundColour;
973 }
974
975 wxColour wxWindowBase::GetForegroundColour() const
976 {
977 // logic is the same as above
978 if ( !m_hasFgCol && !m_foregroundColour.Ok() )
979 {
980 wxASSERT_MSG( !m_hasFgCol, _T("we have invalid explicit fg colour?") );
981
982 wxColour colFg = GetDefaultAttributes().colFg;
983
984 if ( !colFg.Ok() )
985 colFg = GetClassDefaultAttributes().colFg;
986
987 return colFg;
988 }
989 else
990 return m_foregroundColour;
991 }
992
993 bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
994 {
995 if ( colour == m_backgroundColour )
996 return false;
997
998 m_hasBgCol = colour.Ok();
999 if ( m_backgroundStyle != wxBG_STYLE_CUSTOM )
1000 m_backgroundStyle = m_hasBgCol ? wxBG_STYLE_COLOUR : wxBG_STYLE_SYSTEM;
1001
1002 m_inheritBgCol = m_hasBgCol;
1003 m_backgroundColour = colour;
1004 SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
1005 return true;
1006 }
1007
1008 bool wxWindowBase::SetForegroundColour( const wxColour &colour )
1009 {
1010 if (colour == m_foregroundColour )
1011 return false;
1012
1013 m_hasFgCol = colour.Ok();
1014 m_inheritFgCol = m_hasFgCol;
1015 m_foregroundColour = colour;
1016 SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
1017 return true;
1018 }
1019
1020 bool wxWindowBase::SetCursor(const wxCursor& cursor)
1021 {
1022 // setting an invalid cursor is ok, it means that we don't have any special
1023 // cursor
1024 if ( m_cursor == cursor )
1025 {
1026 // no change
1027 return false;
1028 }
1029
1030 m_cursor = cursor;
1031
1032 return true;
1033 }
1034
1035 wxFont wxWindowBase::GetFont() const
1036 {
1037 // logic is the same as in GetBackgroundColour()
1038 if ( !m_font.Ok() )
1039 {
1040 wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") );
1041
1042 wxFont font = GetDefaultAttributes().font;
1043 if ( !font.Ok() )
1044 font = GetClassDefaultAttributes().font;
1045
1046 return font;
1047 }
1048 else
1049 return m_font;
1050 }
1051
1052 bool wxWindowBase::SetFont(const wxFont& font)
1053 {
1054 if ( font == m_font )
1055 {
1056 // no change
1057 return false;
1058 }
1059
1060 m_font = font;
1061 m_hasFont = font.Ok();
1062 m_inheritFont = m_hasFont;
1063
1064 InvalidateBestSize();
1065
1066 return true;
1067 }
1068
1069 #if wxUSE_PALETTE
1070
1071 void wxWindowBase::SetPalette(const wxPalette& pal)
1072 {
1073 m_hasCustomPalette = true;
1074 m_palette = pal;
1075
1076 // VZ: can anyone explain me what do we do here?
1077 wxWindowDC d((wxWindow *) this);
1078 d.SetPalette(pal);
1079 }
1080
1081 wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
1082 {
1083 wxWindow *win = (wxWindow *)this;
1084 while ( win && !win->HasCustomPalette() )
1085 {
1086 win = win->GetParent();
1087 }
1088
1089 return win;
1090 }
1091
1092 #endif // wxUSE_PALETTE
1093
1094 #if wxUSE_CARET
1095 void wxWindowBase::SetCaret(wxCaret *caret)
1096 {
1097 if ( m_caret )
1098 {
1099 delete m_caret;
1100 }
1101
1102 m_caret = caret;
1103
1104 if ( m_caret )
1105 {
1106 wxASSERT_MSG( m_caret->GetWindow() == this,
1107 wxT("caret should be created associated to this window") );
1108 }
1109 }
1110 #endif // wxUSE_CARET
1111
1112 #if wxUSE_VALIDATORS
1113 // ----------------------------------------------------------------------------
1114 // validators
1115 // ----------------------------------------------------------------------------
1116
1117 void wxWindowBase::SetValidator(const wxValidator& validator)
1118 {
1119 if ( m_windowValidator )
1120 delete m_windowValidator;
1121
1122 m_windowValidator = (wxValidator *)validator.Clone();
1123
1124 if ( m_windowValidator )
1125 m_windowValidator->SetWindow(this);
1126 }
1127 #endif // wxUSE_VALIDATORS
1128
1129 // ----------------------------------------------------------------------------
1130 // update region stuff
1131 // ----------------------------------------------------------------------------
1132
1133 wxRect wxWindowBase::GetUpdateClientRect() const
1134 {
1135 wxRegion rgnUpdate = GetUpdateRegion();
1136 rgnUpdate.Intersect(GetClientRect());
1137 wxRect rectUpdate = rgnUpdate.GetBox();
1138 wxPoint ptOrigin = GetClientAreaOrigin();
1139 rectUpdate.x -= ptOrigin.x;
1140 rectUpdate.y -= ptOrigin.y;
1141
1142 return rectUpdate;
1143 }
1144
1145 bool wxWindowBase::IsExposed(int x, int y) const
1146 {
1147 return m_updateRegion.Contains(x, y) != wxOutRegion;
1148 }
1149
1150 bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
1151 {
1152 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
1153 }
1154
1155 void wxWindowBase::ClearBackground()
1156 {
1157 // wxGTK uses its own version, no need to add never used code
1158 #ifndef __WXGTK__
1159 wxClientDC dc((wxWindow *)this);
1160 wxBrush brush(GetBackgroundColour(), wxSOLID);
1161 dc.SetBackground(brush);
1162 dc.Clear();
1163 #endif // __WXGTK__
1164 }
1165
1166 // ----------------------------------------------------------------------------
1167 // find child window by id or name
1168 // ----------------------------------------------------------------------------
1169
1170 wxWindow *wxWindowBase::FindWindow(long id) const
1171 {
1172 if ( id == m_windowId )
1173 return (wxWindow *)this;
1174
1175 wxWindowBase *res = (wxWindow *)NULL;
1176 wxWindowList::compatibility_iterator node;
1177 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1178 {
1179 wxWindowBase *child = node->GetData();
1180 res = child->FindWindow( id );
1181 }
1182
1183 return (wxWindow *)res;
1184 }
1185
1186 wxWindow *wxWindowBase::FindWindow(const wxString& name) const
1187 {
1188 if ( name == m_windowName )
1189 return (wxWindow *)this;
1190
1191 wxWindowBase *res = (wxWindow *)NULL;
1192 wxWindowList::compatibility_iterator node;
1193 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1194 {
1195 wxWindow *child = node->GetData();
1196 res = child->FindWindow(name);
1197 }
1198
1199 return (wxWindow *)res;
1200 }
1201
1202
1203 // find any window by id or name or label: If parent is non-NULL, look through
1204 // children for a label or title matching the specified string. If NULL, look
1205 // through all top-level windows.
1206 //
1207 // to avoid duplicating code we reuse the same helper function but with
1208 // different comparators
1209
1210 typedef bool (*wxFindWindowCmp)(const wxWindow *win,
1211 const wxString& label, long id);
1212
1213 static
1214 bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
1215 long WXUNUSED(id))
1216 {
1217 return win->GetLabel() == label;
1218 }
1219
1220 static
1221 bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
1222 long WXUNUSED(id))
1223 {
1224 return win->GetName() == label;
1225 }
1226
1227 static
1228 bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
1229 long id)
1230 {
1231 return win->GetId() == id;
1232 }
1233
1234 // recursive helper for the FindWindowByXXX() functions
1235 static
1236 wxWindow *wxFindWindowRecursively(const wxWindow *parent,
1237 const wxString& label,
1238 long id,
1239 wxFindWindowCmp cmp)
1240 {
1241 if ( parent )
1242 {
1243 // see if this is the one we're looking for
1244 if ( (*cmp)(parent, label, id) )
1245 return (wxWindow *)parent;
1246
1247 // It wasn't, so check all its children
1248 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1249 node;
1250 node = node->GetNext() )
1251 {
1252 // recursively check each child
1253 wxWindow *win = (wxWindow *)node->GetData();
1254 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1255 if (retwin)
1256 return retwin;
1257 }
1258 }
1259
1260 // Not found
1261 return NULL;
1262 }
1263
1264 // helper for FindWindowByXXX()
1265 static
1266 wxWindow *wxFindWindowHelper(const wxWindow *parent,
1267 const wxString& label,
1268 long id,
1269 wxFindWindowCmp cmp)
1270 {
1271 if ( parent )
1272 {
1273 // just check parent and all its children
1274 return wxFindWindowRecursively(parent, label, id, cmp);
1275 }
1276
1277 // start at very top of wx's windows
1278 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1279 node;
1280 node = node->GetNext() )
1281 {
1282 // recursively check each window & its children
1283 wxWindow *win = node->GetData();
1284 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1285 if (retwin)
1286 return retwin;
1287 }
1288
1289 return NULL;
1290 }
1291
1292 /* static */
1293 wxWindow *
1294 wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
1295 {
1296 return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
1297 }
1298
1299 /* static */
1300 wxWindow *
1301 wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
1302 {
1303 wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
1304
1305 if ( !win )
1306 {
1307 // fall back to the label
1308 win = FindWindowByLabel(title, parent);
1309 }
1310
1311 return win;
1312 }
1313
1314 /* static */
1315 wxWindow *
1316 wxWindowBase::FindWindowById( long id, const wxWindow* parent )
1317 {
1318 return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds);
1319 }
1320
1321 // ----------------------------------------------------------------------------
1322 // dialog oriented functions
1323 // ----------------------------------------------------------------------------
1324
1325 void wxWindowBase::MakeModal(bool modal)
1326 {
1327 // Disable all other windows
1328 if ( IsTopLevel() )
1329 {
1330 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1331 while (node)
1332 {
1333 wxWindow *win = node->GetData();
1334 if (win != this)
1335 win->Enable(!modal);
1336
1337 node = node->GetNext();
1338 }
1339 }
1340 }
1341
1342 bool wxWindowBase::Validate()
1343 {
1344 #if wxUSE_VALIDATORS
1345 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1346
1347 wxWindowList::compatibility_iterator node;
1348 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1349 {
1350 wxWindowBase *child = node->GetData();
1351 wxValidator *validator = child->GetValidator();
1352 if ( validator && !validator->Validate((wxWindow *)this) )
1353 {
1354 return false;
1355 }
1356
1357 if ( recurse && !child->Validate() )
1358 {
1359 return false;
1360 }
1361 }
1362 #endif // wxUSE_VALIDATORS
1363
1364 return true;
1365 }
1366
1367 bool wxWindowBase::TransferDataToWindow()
1368 {
1369 #if wxUSE_VALIDATORS
1370 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1371
1372 wxWindowList::compatibility_iterator node;
1373 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1374 {
1375 wxWindowBase *child = node->GetData();
1376 wxValidator *validator = child->GetValidator();
1377 if ( validator && !validator->TransferToWindow() )
1378 {
1379 wxLogWarning(_("Could not transfer data to window"));
1380 #if wxUSE_LOG
1381 wxLog::FlushActive();
1382 #endif // wxUSE_LOG
1383
1384 return false;
1385 }
1386
1387 if ( recurse )
1388 {
1389 if ( !child->TransferDataToWindow() )
1390 {
1391 // warning already given
1392 return false;
1393 }
1394 }
1395 }
1396 #endif // wxUSE_VALIDATORS
1397
1398 return true;
1399 }
1400
1401 bool wxWindowBase::TransferDataFromWindow()
1402 {
1403 #if wxUSE_VALIDATORS
1404 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1405
1406 wxWindowList::compatibility_iterator node;
1407 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1408 {
1409 wxWindow *child = node->GetData();
1410 wxValidator *validator = child->GetValidator();
1411 if ( validator && !validator->TransferFromWindow() )
1412 {
1413 // nop warning here because the application is supposed to give
1414 // one itself - we don't know here what might have gone wrongly
1415
1416 return false;
1417 }
1418
1419 if ( recurse )
1420 {
1421 if ( !child->TransferDataFromWindow() )
1422 {
1423 // warning already given
1424 return false;
1425 }
1426 }
1427 }
1428 #endif // wxUSE_VALIDATORS
1429
1430 return true;
1431 }
1432
1433 void wxWindowBase::InitDialog()
1434 {
1435 wxInitDialogEvent event(GetId());
1436 event.SetEventObject( this );
1437 GetEventHandler()->ProcessEvent(event);
1438 }
1439
1440 // ----------------------------------------------------------------------------
1441 // context-sensitive help support
1442 // ----------------------------------------------------------------------------
1443
1444 #if wxUSE_HELP
1445
1446 // associate this help text with this window
1447 void wxWindowBase::SetHelpText(const wxString& text)
1448 {
1449 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1450 if ( helpProvider )
1451 {
1452 helpProvider->AddHelp(this, text);
1453 }
1454 }
1455
1456 // associate this help text with all windows with the same id as this
1457 // one
1458 void wxWindowBase::SetHelpTextForId(const wxString& text)
1459 {
1460 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1461 if ( helpProvider )
1462 {
1463 helpProvider->AddHelp(GetId(), text);
1464 }
1465 }
1466
1467 // get the help string associated with this window (may be empty)
1468 wxString wxWindowBase::GetHelpText() const
1469 {
1470 wxString text;
1471 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1472 if ( helpProvider )
1473 {
1474 text = helpProvider->GetHelp(this);
1475 }
1476
1477 return text;
1478 }
1479
1480 // show help for this window
1481 void wxWindowBase::OnHelp(wxHelpEvent& event)
1482 {
1483 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1484 if ( helpProvider )
1485 {
1486 if ( helpProvider->ShowHelp(this) )
1487 {
1488 // skip the event.Skip() below
1489 return;
1490 }
1491 }
1492
1493 event.Skip();
1494 }
1495
1496 #endif // wxUSE_HELP
1497
1498 // ----------------------------------------------------------------------------
1499 // tooltipsroot.Replace("\\", "/");
1500 // ----------------------------------------------------------------------------
1501
1502 #if wxUSE_TOOLTIPS
1503
1504 void wxWindowBase::SetToolTip( const wxString &tip )
1505 {
1506 // don't create the new tooltip if we already have one
1507 if ( m_tooltip )
1508 {
1509 m_tooltip->SetTip( tip );
1510 }
1511 else
1512 {
1513 SetToolTip( new wxToolTip( tip ) );
1514 }
1515
1516 // setting empty tooltip text does not remove the tooltip any more - use
1517 // SetToolTip((wxToolTip *)NULL) for this
1518 }
1519
1520 void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1521 {
1522 if ( m_tooltip )
1523 delete m_tooltip;
1524
1525 m_tooltip = tooltip;
1526 }
1527
1528 #endif // wxUSE_TOOLTIPS
1529
1530 // ----------------------------------------------------------------------------
1531 // constraints and sizers
1532 // ----------------------------------------------------------------------------
1533
1534 #if wxUSE_CONSTRAINTS
1535
1536 void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1537 {
1538 if ( m_constraints )
1539 {
1540 UnsetConstraints(m_constraints);
1541 delete m_constraints;
1542 }
1543 m_constraints = constraints;
1544 if ( m_constraints )
1545 {
1546 // Make sure other windows know they're part of a 'meaningful relationship'
1547 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1548 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1549 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1550 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1551 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1552 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1553 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1554 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1555 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1556 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1557 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1558 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1560 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1562 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
1563 }
1564 }
1565
1566 // This removes any dangling pointers to this window in other windows'
1567 // constraintsInvolvedIn lists.
1568 void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
1569 {
1570 if ( c )
1571 {
1572 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1573 c->left.GetOtherWindow()->RemoveConstraintReference(this);
1574 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1575 c->top.GetOtherWindow()->RemoveConstraintReference(this);
1576 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
1577 c->right.GetOtherWindow()->RemoveConstraintReference(this);
1578 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
1579 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
1580 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1581 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1582 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1583 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1585 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1587 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1588 }
1589 }
1590
1591 // Back-pointer to other windows we're involved with, so if we delete this
1592 // window, we must delete any constraints we're involved with.
1593 void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1594 {
1595 if ( !m_constraintsInvolvedIn )
1596 m_constraintsInvolvedIn = new wxWindowList;
1597 if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) )
1598 m_constraintsInvolvedIn->Append((wxWindow *)otherWin);
1599 }
1600
1601 // REMOVE back-pointer to other windows we're involved with.
1602 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1603 {
1604 if ( m_constraintsInvolvedIn )
1605 m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin);
1606 }
1607
1608 // Reset any constraints that mention this window
1609 void wxWindowBase::DeleteRelatedConstraints()
1610 {
1611 if ( m_constraintsInvolvedIn )
1612 {
1613 wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst();
1614 while (node)
1615 {
1616 wxWindow *win = node->GetData();
1617 wxLayoutConstraints *constr = win->GetConstraints();
1618
1619 // Reset any constraints involving this window
1620 if ( constr )
1621 {
1622 constr->left.ResetIfWin(this);
1623 constr->top.ResetIfWin(this);
1624 constr->right.ResetIfWin(this);
1625 constr->bottom.ResetIfWin(this);
1626 constr->width.ResetIfWin(this);
1627 constr->height.ResetIfWin(this);
1628 constr->centreX.ResetIfWin(this);
1629 constr->centreY.ResetIfWin(this);
1630 }
1631
1632 wxWindowList::compatibility_iterator next = node->GetNext();
1633 m_constraintsInvolvedIn->Erase(node);
1634 node = next;
1635 }
1636
1637 delete m_constraintsInvolvedIn;
1638 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1639 }
1640 }
1641
1642 #endif // wxUSE_CONSTRAINTS
1643
1644 void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
1645 {
1646 if ( sizer == m_windowSizer)
1647 return;
1648
1649 if ( deleteOld )
1650 delete m_windowSizer;
1651
1652 m_windowSizer = sizer;
1653
1654 SetAutoLayout( sizer != NULL );
1655 }
1656
1657 void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
1658 {
1659 SetSizer( sizer, deleteOld );
1660 sizer->SetSizeHints( (wxWindow*) this );
1661 }
1662
1663
1664 void wxWindowBase::SetContainingSizer(wxSizer* sizer)
1665 {
1666 // adding a window to a sizer twice is going to result in fatal and
1667 // hard to debug problems later because when deleting the second
1668 // associated wxSizerItem we're going to dereference a dangling
1669 // pointer; so try to detect this as early as possible
1670 wxASSERT_MSG( !sizer || m_containingSizer != sizer,
1671 _T("Adding a window to the same sizer twice?") );
1672
1673 m_containingSizer = sizer;
1674 }
1675
1676 #if wxUSE_CONSTRAINTS
1677
1678 void wxWindowBase::SatisfyConstraints()
1679 {
1680 wxLayoutConstraints *constr = GetConstraints();
1681 bool wasOk = constr && constr->AreSatisfied();
1682
1683 ResetConstraints(); // Mark all constraints as unevaluated
1684
1685 int noChanges = 1;
1686
1687 // if we're a top level panel (i.e. our parent is frame/dialog), our
1688 // own constraints will never be satisfied any more unless we do it
1689 // here
1690 if ( wasOk )
1691 {
1692 while ( noChanges > 0 )
1693 {
1694 LayoutPhase1(&noChanges);
1695 }
1696 }
1697
1698 LayoutPhase2(&noChanges);
1699 }
1700
1701 #endif // wxUSE_CONSTRAINTS
1702
1703 bool wxWindowBase::Layout()
1704 {
1705 // If there is a sizer, use it instead of the constraints
1706 if ( GetSizer() )
1707 {
1708 int w = 0, h = 0;
1709 GetVirtualSize(&w, &h);
1710 GetSizer()->SetDimension( 0, 0, w, h );
1711 }
1712 #if wxUSE_CONSTRAINTS
1713 else
1714 {
1715 SatisfyConstraints(); // Find the right constraints values
1716 SetConstraintSizes(); // Recursively set the real window sizes
1717 }
1718 #endif
1719
1720 return true;
1721 }
1722
1723 #if wxUSE_CONSTRAINTS
1724
1725 // first phase of the constraints evaluation: set our own constraints
1726 bool wxWindowBase::LayoutPhase1(int *noChanges)
1727 {
1728 wxLayoutConstraints *constr = GetConstraints();
1729
1730 return !constr || constr->SatisfyConstraints(this, noChanges);
1731 }
1732
1733 // second phase: set the constraints for our children
1734 bool wxWindowBase::LayoutPhase2(int *noChanges)
1735 {
1736 *noChanges = 0;
1737
1738 // Layout children
1739 DoPhase(1);
1740
1741 // Layout grand children
1742 DoPhase(2);
1743
1744 return true;
1745 }
1746
1747 // Do a phase of evaluating child constraints
1748 bool wxWindowBase::DoPhase(int phase)
1749 {
1750 // the list containing the children for which the constraints are already
1751 // set correctly
1752 wxWindowList succeeded;
1753
1754 // the max number of iterations we loop before concluding that we can't set
1755 // the constraints
1756 static const int maxIterations = 500;
1757
1758 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
1759 {
1760 int noChanges = 0;
1761
1762 // loop over all children setting their constraints
1763 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1764 node;
1765 node = node->GetNext() )
1766 {
1767 wxWindow *child = node->GetData();
1768 if ( child->IsTopLevel() )
1769 {
1770 // top level children are not inside our client area
1771 continue;
1772 }
1773
1774 if ( !child->GetConstraints() || succeeded.Find(child) )
1775 {
1776 // this one is either already ok or nothing we can do about it
1777 continue;
1778 }
1779
1780 int tempNoChanges = 0;
1781 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
1782 : child->LayoutPhase2(&tempNoChanges);
1783 noChanges += tempNoChanges;
1784
1785 if ( success )
1786 {
1787 succeeded.Append(child);
1788 }
1789 }
1790
1791 if ( !noChanges )
1792 {
1793 // constraints are set
1794 break;
1795 }
1796 }
1797
1798 return true;
1799 }
1800
1801 void wxWindowBase::ResetConstraints()
1802 {
1803 wxLayoutConstraints *constr = GetConstraints();
1804 if ( constr )
1805 {
1806 constr->left.SetDone(false);
1807 constr->top.SetDone(false);
1808 constr->right.SetDone(false);
1809 constr->bottom.SetDone(false);
1810 constr->width.SetDone(false);
1811 constr->height.SetDone(false);
1812 constr->centreX.SetDone(false);
1813 constr->centreY.SetDone(false);
1814 }
1815
1816 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1817 while (node)
1818 {
1819 wxWindow *win = node->GetData();
1820 if ( !win->IsTopLevel() )
1821 win->ResetConstraints();
1822 node = node->GetNext();
1823 }
1824 }
1825
1826 // Need to distinguish between setting the 'fake' size for windows and sizers,
1827 // and setting the real values.
1828 void wxWindowBase::SetConstraintSizes(bool recurse)
1829 {
1830 wxLayoutConstraints *constr = GetConstraints();
1831 if ( constr && constr->AreSatisfied() )
1832 {
1833 int x = constr->left.GetValue();
1834 int y = constr->top.GetValue();
1835 int w = constr->width.GetValue();
1836 int h = constr->height.GetValue();
1837
1838 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1839 (constr->height.GetRelationship() != wxAsIs) )
1840 {
1841 SetSize(x, y, w, h);
1842 }
1843 else
1844 {
1845 // If we don't want to resize this window, just move it...
1846 Move(x, y);
1847 }
1848 }
1849 else if ( constr )
1850 {
1851 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1852 GetClassInfo()->GetClassName(),
1853 GetName().c_str());
1854 }
1855
1856 if ( recurse )
1857 {
1858 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1859 while (node)
1860 {
1861 wxWindow *win = node->GetData();
1862 if ( !win->IsTopLevel() && win->GetConstraints() )
1863 win->SetConstraintSizes();
1864 node = node->GetNext();
1865 }
1866 }
1867 }
1868
1869 // Only set the size/position of the constraint (if any)
1870 void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1871 {
1872 wxLayoutConstraints *constr = GetConstraints();
1873 if ( constr )
1874 {
1875 if ( x != wxDefaultCoord )
1876 {
1877 constr->left.SetValue(x);
1878 constr->left.SetDone(true);
1879 }
1880 if ( y != wxDefaultCoord )
1881 {
1882 constr->top.SetValue(y);
1883 constr->top.SetDone(true);
1884 }
1885 if ( w != wxDefaultCoord )
1886 {
1887 constr->width.SetValue(w);
1888 constr->width.SetDone(true);
1889 }
1890 if ( h != wxDefaultCoord )
1891 {
1892 constr->height.SetValue(h);
1893 constr->height.SetDone(true);
1894 }
1895 }
1896 }
1897
1898 void wxWindowBase::MoveConstraint(int x, int y)
1899 {
1900 wxLayoutConstraints *constr = GetConstraints();
1901 if ( constr )
1902 {
1903 if ( x != wxDefaultCoord )
1904 {
1905 constr->left.SetValue(x);
1906 constr->left.SetDone(true);
1907 }
1908 if ( y != wxDefaultCoord )
1909 {
1910 constr->top.SetValue(y);
1911 constr->top.SetDone(true);
1912 }
1913 }
1914 }
1915
1916 void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1917 {
1918 wxLayoutConstraints *constr = GetConstraints();
1919 if ( constr )
1920 {
1921 *w = constr->width.GetValue();
1922 *h = constr->height.GetValue();
1923 }
1924 else
1925 GetSize(w, h);
1926 }
1927
1928 void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1929 {
1930 wxLayoutConstraints *constr = GetConstraints();
1931 if ( constr )
1932 {
1933 *w = constr->width.GetValue();
1934 *h = constr->height.GetValue();
1935 }
1936 else
1937 GetClientSize(w, h);
1938 }
1939
1940 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1941 {
1942 wxLayoutConstraints *constr = GetConstraints();
1943 if ( constr )
1944 {
1945 *x = constr->left.GetValue();
1946 *y = constr->top.GetValue();
1947 }
1948 else
1949 GetPosition(x, y);
1950 }
1951
1952 #endif // wxUSE_CONSTRAINTS
1953
1954 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
1955 {
1956 // don't do it for the dialogs/frames - they float independently of their
1957 // parent
1958 if ( !IsTopLevel() )
1959 {
1960 wxWindow *parent = GetParent();
1961 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
1962 {
1963 wxPoint pt(parent->GetClientAreaOrigin());
1964 x += pt.x;
1965 y += pt.y;
1966 }
1967 }
1968 }
1969
1970 // ----------------------------------------------------------------------------
1971 // do Update UI processing for child controls
1972 // ----------------------------------------------------------------------------
1973
1974 void wxWindowBase::UpdateWindowUI(long flags)
1975 {
1976 wxUpdateUIEvent event(GetId());
1977 event.SetEventObject(this);
1978
1979 if ( GetEventHandler()->ProcessEvent(event) )
1980 {
1981 DoUpdateWindowUI(event);
1982 }
1983
1984 if (flags & wxUPDATE_UI_RECURSE)
1985 {
1986 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1987 while (node)
1988 {
1989 wxWindow* child = (wxWindow*) node->GetData();
1990 child->UpdateWindowUI(flags);
1991 node = node->GetNext();
1992 }
1993 }
1994 }
1995
1996 // do the window-specific processing after processing the update event
1997 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
1998 {
1999 if ( event.GetSetEnabled() )
2000 Enable(event.GetEnabled());
2001
2002 if ( event.GetSetShown() )
2003 Show(event.GetShown());
2004 }
2005
2006 #if 0
2007 // call internal idle recursively
2008 // may be obsolete (wait until OnIdle scheme stabilises)
2009 void wxWindowBase::ProcessInternalIdle()
2010 {
2011 OnInternalIdle();
2012
2013 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2014 while (node)
2015 {
2016 wxWindow *child = node->GetData();
2017 child->ProcessInternalIdle();
2018 node = node->GetNext();
2019 }
2020 }
2021 #endif
2022
2023 // ----------------------------------------------------------------------------
2024 // dialog units translations
2025 // ----------------------------------------------------------------------------
2026
2027 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
2028 {
2029 int charWidth = GetCharWidth();
2030 int charHeight = GetCharHeight();
2031 wxPoint pt2 = wxDefaultPosition;
2032 if (pt.x != wxDefaultCoord)
2033 pt2.x = (int) ((pt.x * 4) / charWidth);
2034 if (pt.y != wxDefaultCoord)
2035 pt2.y = (int) ((pt.y * 8) / charHeight);
2036
2037 return pt2;
2038 }
2039
2040 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
2041 {
2042 int charWidth = GetCharWidth();
2043 int charHeight = GetCharHeight();
2044 wxPoint pt2 = wxDefaultPosition;
2045 if (pt.x != wxDefaultCoord)
2046 pt2.x = (int) ((pt.x * charWidth) / 4);
2047 if (pt.y != wxDefaultCoord)
2048 pt2.y = (int) ((pt.y * charHeight) / 8);
2049
2050 return pt2;
2051 }
2052
2053 // ----------------------------------------------------------------------------
2054 // event handlers
2055 // ----------------------------------------------------------------------------
2056
2057 // propagate the colour change event to the subwindows
2058 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
2059 {
2060 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2061 while ( node )
2062 {
2063 // Only propagate to non-top-level windows
2064 wxWindow *win = node->GetData();
2065 if ( !win->IsTopLevel() )
2066 {
2067 wxSysColourChangedEvent event2;
2068 event.SetEventObject(win);
2069 win->GetEventHandler()->ProcessEvent(event2);
2070 }
2071
2072 node = node->GetNext();
2073 }
2074
2075 Refresh();
2076 }
2077
2078 // the default action is to populate dialog with data when it's created,
2079 // and nudge the UI into displaying itself correctly in case
2080 // we've turned the wxUpdateUIEvents frequency down low.
2081 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2082 {
2083 TransferDataToWindow();
2084
2085 // Update the UI at this point
2086 UpdateWindowUI(wxUPDATE_UI_RECURSE);
2087 }
2088
2089 // methods for drawing the sizers in a visible way
2090 #ifdef __WXDEBUG__
2091
2092 static void DrawSizers(wxWindowBase *win);
2093
2094 static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false)
2095 {
2096 wxClientDC dc((wxWindow *)win);
2097 dc.SetPen(*wxRED_PEN);
2098 dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH);
2099 dc.DrawRectangle(rect.Deflate(1, 1));
2100 }
2101
2102 static void DrawSizer(wxWindowBase *win, wxSizer *sizer)
2103 {
2104 const wxSizerItemList& items = sizer->GetChildren();
2105 for ( wxSizerItemList::const_iterator i = items.begin(),
2106 end = items.end();
2107 i != end;
2108 ++i )
2109 {
2110 wxSizerItem *item = *i;
2111 if ( item->IsSizer() )
2112 {
2113 DrawBorder(win, item->GetRect().Deflate(2));
2114 DrawSizer(win, item->GetSizer());
2115 }
2116 else if ( item->IsSpacer() )
2117 {
2118 DrawBorder(win, item->GetRect().Deflate(2), true);
2119 }
2120 else if ( item->IsWindow() )
2121 {
2122 DrawSizers(item->GetWindow());
2123 }
2124 }
2125 }
2126
2127 static void DrawSizers(wxWindowBase *win)
2128 {
2129 wxSizer *sizer = win->GetSizer();
2130 if ( sizer )
2131 {
2132 DrawBorder(win, win->GetClientSize());
2133 DrawSizer(win, sizer);
2134 }
2135 else // no sizer, still recurse into the children
2136 {
2137 const wxWindowList& children = win->GetChildren();
2138 for ( wxWindowList::const_iterator i = children.begin(),
2139 end = children.end();
2140 i != end;
2141 ++i )
2142 {
2143 DrawSizers(*i);
2144 }
2145 }
2146 }
2147
2148 #endif // __WXDEBUG__
2149
2150 // process special middle clicks
2151 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2152 {
2153 if ( event.ControlDown() && event.AltDown() )
2154 {
2155 #ifdef __WXDEBUG__
2156 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2157 if ( event.ShiftDown() )
2158 {
2159 DrawSizers(this);
2160 return;
2161 }
2162 #endif // __WXDEBUG__
2163
2164 #if wxUSE_MSGDLG
2165 // don't translate these strings
2166 wxString port;
2167
2168 #ifdef __WXUNIVERSAL__
2169 port = _T("Univ/");
2170 #endif // __WXUNIVERSAL__
2171
2172 switch ( wxGetOsVersion() )
2173 {
2174 case wxMOTIF_X: port += _T("Motif"); break;
2175 case wxMAC:
2176 case wxMAC_DARWIN: port += _T("Mac"); break;
2177 case wxBEOS: port += _T("BeOS"); break;
2178 case wxGTK:
2179 case wxGTK_WIN32:
2180 case wxGTK_OS2:
2181 case wxGTK_BEOS: port += _T("GTK"); break;
2182 case wxWINDOWS:
2183 case wxPENWINDOWS:
2184 case wxWINDOWS_NT:
2185 case wxWIN32S:
2186 case wxWIN95:
2187 case wxWIN386: port += _T("MS Windows"); break;
2188 case wxMGL_UNIX:
2189 case wxMGL_X:
2190 case wxMGL_WIN32:
2191 case wxMGL_OS2: port += _T("MGL"); break;
2192 case wxWINDOWS_OS2:
2193 case wxOS2_PM: port += _T("OS/2"); break;
2194 case wxPALMOS: port += _T("Palm OS"); break;
2195 case wxWINDOWS_CE: port += _T("Windows CE (generic)"); break;
2196 case wxWINDOWS_POCKETPC: port += _T("Windows CE PocketPC"); break;
2197 case wxWINDOWS_SMARTPHONE: port += _T("Windows CE Smartphone"); break;
2198 default: port += _T("unknown"); break;
2199 }
2200
2201 wxMessageBox(wxString::Format(
2202 _T(
2203 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2006 wxWidgets team"
2204 ),
2205 port.c_str(),
2206 wxMAJOR_VERSION,
2207 wxMINOR_VERSION,
2208 wxRELEASE_NUMBER,
2209 #if wxUSE_UNICODE
2210 L" (Unicode)",
2211 #else
2212 "",
2213 #endif
2214 #ifdef __WXDEBUG__
2215 _T(" Debug build"),
2216 #else
2217 wxEmptyString,
2218 #endif
2219 __TDATE__,
2220 __TTIME__,
2221 #ifdef __WXGTK__
2222 wxString::Format(_T("\nagainst GTK+ %d.%d.%d. Runtime GTK+ version: %d.%d.%d"), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION, gtk_major_version, gtk_minor_version, gtk_micro_version).c_str()
2223 #else
2224 ""
2225 #endif
2226 ),
2227 _T("wxWidgets information"),
2228 wxICON_INFORMATION | wxOK,
2229 (wxWindow *)this);
2230 }
2231 else
2232 #endif // wxUSE_MSGDLG
2233 {
2234 event.Skip();
2235 }
2236 }
2237
2238 // ----------------------------------------------------------------------------
2239 // accessibility
2240 // ----------------------------------------------------------------------------
2241
2242 #if wxUSE_ACCESSIBILITY
2243 void wxWindowBase::SetAccessible(wxAccessible* accessible)
2244 {
2245 if (m_accessible && (accessible != m_accessible))
2246 delete m_accessible;
2247 m_accessible = accessible;
2248 if (m_accessible)
2249 m_accessible->SetWindow((wxWindow*) this);
2250 }
2251
2252 // Returns the accessible object, creating if necessary.
2253 wxAccessible* wxWindowBase::GetOrCreateAccessible()
2254 {
2255 if (!m_accessible)
2256 m_accessible = CreateAccessible();
2257 return m_accessible;
2258 }
2259
2260 // Override to create a specific accessible object.
2261 wxAccessible* wxWindowBase::CreateAccessible()
2262 {
2263 return new wxWindowAccessible((wxWindow*) this);
2264 }
2265
2266 #endif
2267
2268 // ----------------------------------------------------------------------------
2269 // list classes implementation
2270 // ----------------------------------------------------------------------------
2271
2272 #if wxUSE_STL
2273
2274 #include "wx/listimpl.cpp"
2275 WX_DEFINE_LIST(wxWindowList)
2276
2277 #else
2278
2279 void wxWindowListNode::DeleteData()
2280 {
2281 delete (wxWindow *)GetData();
2282 }
2283
2284 #endif
2285
2286 // ----------------------------------------------------------------------------
2287 // borders
2288 // ----------------------------------------------------------------------------
2289
2290 wxBorder wxWindowBase::GetBorder(long flags) const
2291 {
2292 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
2293 if ( border == wxBORDER_DEFAULT )
2294 {
2295 border = GetDefaultBorder();
2296 }
2297
2298 return border;
2299 }
2300
2301 wxBorder wxWindowBase::GetDefaultBorder() const
2302 {
2303 return wxBORDER_NONE;
2304 }
2305
2306 // ----------------------------------------------------------------------------
2307 // hit testing
2308 // ----------------------------------------------------------------------------
2309
2310 wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2311 {
2312 // here we just check if the point is inside the window or not
2313
2314 // check the top and left border first
2315 bool outside = x < 0 || y < 0;
2316 if ( !outside )
2317 {
2318 // check the right and bottom borders too
2319 wxSize size = GetSize();
2320 outside = x >= size.x || y >= size.y;
2321 }
2322
2323 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2324 }
2325
2326 // ----------------------------------------------------------------------------
2327 // mouse capture
2328 // ----------------------------------------------------------------------------
2329
2330 struct WXDLLEXPORT wxWindowNext
2331 {
2332 wxWindow *win;
2333 wxWindowNext *next;
2334 } *wxWindowBase::ms_winCaptureNext = NULL;
2335
2336 void wxWindowBase::CaptureMouse()
2337 {
2338 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2339
2340 wxWindow *winOld = GetCapture();
2341 if ( winOld )
2342 {
2343 ((wxWindowBase*) winOld)->DoReleaseMouse();
2344
2345 // save it on stack
2346 wxWindowNext *item = new wxWindowNext;
2347 item->win = winOld;
2348 item->next = ms_winCaptureNext;
2349 ms_winCaptureNext = item;
2350 }
2351 //else: no mouse capture to save
2352
2353 DoCaptureMouse();
2354 }
2355
2356 void wxWindowBase::ReleaseMouse()
2357 {
2358 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2359
2360 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2361
2362 DoReleaseMouse();
2363
2364 if ( ms_winCaptureNext )
2365 {
2366 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
2367
2368 wxWindowNext *item = ms_winCaptureNext;
2369 ms_winCaptureNext = item->next;
2370 delete item;
2371 }
2372 //else: stack is empty, no previous capture
2373
2374 wxLogTrace(_T("mousecapture"),
2375 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
2376 GetCapture());
2377 }
2378
2379 #if wxUSE_HOTKEY
2380
2381 bool
2382 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2383 int WXUNUSED(modifiers),
2384 int WXUNUSED(keycode))
2385 {
2386 // not implemented
2387 return false;
2388 }
2389
2390 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
2391 {
2392 // not implemented
2393 return false;
2394 }
2395
2396 #endif // wxUSE_HOTKEY
2397
2398 void wxWindowBase::SendDestroyEvent()
2399 {
2400 wxWindowDestroyEvent event;
2401 event.SetEventObject(this);
2402 event.SetId(GetId());
2403 GetEventHandler()->ProcessEvent(event);
2404 }
2405
2406 // ----------------------------------------------------------------------------
2407 // event processing
2408 // ----------------------------------------------------------------------------
2409
2410 bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
2411 {
2412 #if wxUSE_VALIDATORS
2413 // Can only use the validator of the window which
2414 // is receiving the event
2415 if ( event.GetEventObject() == this )
2416 {
2417 wxValidator *validator = GetValidator();
2418 if ( validator && validator->ProcessEvent(event) )
2419 {
2420 return true;
2421 }
2422 }
2423 #endif // wxUSE_VALIDATORS
2424
2425 return false;
2426 }
2427
2428 bool wxWindowBase::TryParent(wxEvent& event)
2429 {
2430 // carry on up the parent-child hierarchy if the propagation count hasn't
2431 // reached zero yet
2432 if ( event.ShouldPropagate() )
2433 {
2434 // honour the requests to stop propagation at this window: this is
2435 // used by the dialogs, for example, to prevent processing the events
2436 // from the dialog controls in the parent frame which rarely, if ever,
2437 // makes sense
2438 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2439 {
2440 wxWindow *parent = GetParent();
2441 if ( parent && !parent->IsBeingDeleted() )
2442 {
2443 wxPropagateOnce propagateOnce(event);
2444
2445 return parent->GetEventHandler()->ProcessEvent(event);
2446 }
2447 }
2448 }
2449
2450 return wxEvtHandler::TryParent(event);
2451 }
2452
2453 // ----------------------------------------------------------------------------
2454 // keyboard navigation
2455 // ----------------------------------------------------------------------------
2456
2457 // Navigates in the specified direction.
2458 bool wxWindowBase::Navigate(int flags)
2459 {
2460 wxNavigationKeyEvent eventNav;
2461 eventNav.SetFlags(flags);
2462 eventNav.SetEventObject(this);
2463 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
2464 {
2465 return true;
2466 }
2467 return false;
2468 }
2469
2470 void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
2471 {
2472 // check that we're not a top level window
2473 wxCHECK_RET( GetParent(),
2474 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2475
2476 // detect the special case when we have nothing to do anyhow and when the
2477 // code below wouldn't work
2478 if ( win == this )
2479 return;
2480
2481 // find the target window in the siblings list
2482 wxWindowList& siblings = GetParent()->GetChildren();
2483 wxWindowList::compatibility_iterator i = siblings.Find(win);
2484 wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2485
2486 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2487 // can't just move the node around
2488 wxWindow *self = (wxWindow *)this;
2489 siblings.DeleteObject(self);
2490 if ( move == MoveAfter )
2491 {
2492 i = i->GetNext();
2493 }
2494
2495 if ( i )
2496 {
2497 siblings.Insert(i, self);
2498 }
2499 else // MoveAfter and win was the last sibling
2500 {
2501 siblings.Append(self);
2502 }
2503 }
2504
2505 // ----------------------------------------------------------------------------
2506 // focus handling
2507 // ----------------------------------------------------------------------------
2508
2509 /*static*/ wxWindow* wxWindowBase::FindFocus()
2510 {
2511 wxWindowBase *win = DoFindFocus();
2512 return win ? win->GetMainWindowOfCompositeControl() : NULL;
2513 }
2514
2515 // ----------------------------------------------------------------------------
2516 // global functions
2517 // ----------------------------------------------------------------------------
2518
2519 wxWindow* wxGetTopLevelParent(wxWindow *win)
2520 {
2521 while ( win && !win->IsTopLevel() )
2522 win = win->GetParent();
2523
2524 return win;
2525 }
2526
2527 #if wxUSE_ACCESSIBILITY
2528 // ----------------------------------------------------------------------------
2529 // accessible object for windows
2530 // ----------------------------------------------------------------------------
2531
2532 // Can return either a child object, or an integer
2533 // representing the child element, starting from 1.
2534 wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
2535 {
2536 wxASSERT( GetWindow() != NULL );
2537 if (!GetWindow())
2538 return wxACC_FAIL;
2539
2540 return wxACC_NOT_IMPLEMENTED;
2541 }
2542
2543 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2544 wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2545 {
2546 wxASSERT( GetWindow() != NULL );
2547 if (!GetWindow())
2548 return wxACC_FAIL;
2549
2550 wxWindow* win = NULL;
2551 if (elementId == 0)
2552 {
2553 win = GetWindow();
2554 }
2555 else
2556 {
2557 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2558 {
2559 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
2560 }
2561 else
2562 return wxACC_FAIL;
2563 }
2564 if (win)
2565 {
2566 rect = win->GetRect();
2567 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2568 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2569 return wxACC_OK;
2570 }
2571
2572 return wxACC_NOT_IMPLEMENTED;
2573 }
2574
2575 // Navigates from fromId to toId/toObject.
2576 wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
2577 int* WXUNUSED(toId), wxAccessible** toObject)
2578 {
2579 wxASSERT( GetWindow() != NULL );
2580 if (!GetWindow())
2581 return wxACC_FAIL;
2582
2583 switch (navDir)
2584 {
2585 case wxNAVDIR_FIRSTCHILD:
2586 {
2587 if (GetWindow()->GetChildren().GetCount() == 0)
2588 return wxACC_FALSE;
2589 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2590 *toObject = childWindow->GetOrCreateAccessible();
2591
2592 return wxACC_OK;
2593 }
2594 case wxNAVDIR_LASTCHILD:
2595 {
2596 if (GetWindow()->GetChildren().GetCount() == 0)
2597 return wxACC_FALSE;
2598 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2599 *toObject = childWindow->GetOrCreateAccessible();
2600
2601 return wxACC_OK;
2602 }
2603 case wxNAVDIR_RIGHT:
2604 case wxNAVDIR_DOWN:
2605 case wxNAVDIR_NEXT:
2606 {
2607 wxWindowList::compatibility_iterator node =
2608 wxWindowList::compatibility_iterator();
2609 if (fromId == 0)
2610 {
2611 // Can't navigate to sibling of this window
2612 // if we're a top-level window.
2613 if (!GetWindow()->GetParent())
2614 return wxACC_NOT_IMPLEMENTED;
2615
2616 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2617 }
2618 else
2619 {
2620 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2621 node = GetWindow()->GetChildren().Item(fromId-1);
2622 }
2623
2624 if (node && node->GetNext())
2625 {
2626 wxWindow* nextWindow = node->GetNext()->GetData();
2627 *toObject = nextWindow->GetOrCreateAccessible();
2628 return wxACC_OK;
2629 }
2630 else
2631 return wxACC_FALSE;
2632 }
2633 case wxNAVDIR_LEFT:
2634 case wxNAVDIR_UP:
2635 case wxNAVDIR_PREVIOUS:
2636 {
2637 wxWindowList::compatibility_iterator node =
2638 wxWindowList::compatibility_iterator();
2639 if (fromId == 0)
2640 {
2641 // Can't navigate to sibling of this window
2642 // if we're a top-level window.
2643 if (!GetWindow()->GetParent())
2644 return wxACC_NOT_IMPLEMENTED;
2645
2646 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2647 }
2648 else
2649 {
2650 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2651 node = GetWindow()->GetChildren().Item(fromId-1);
2652 }
2653
2654 if (node && node->GetPrevious())
2655 {
2656 wxWindow* previousWindow = node->GetPrevious()->GetData();
2657 *toObject = previousWindow->GetOrCreateAccessible();
2658 return wxACC_OK;
2659 }
2660 else
2661 return wxACC_FALSE;
2662 }
2663 }
2664
2665 return wxACC_NOT_IMPLEMENTED;
2666 }
2667
2668 // Gets the name of the specified object.
2669 wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2670 {
2671 wxASSERT( GetWindow() != NULL );
2672 if (!GetWindow())
2673 return wxACC_FAIL;
2674
2675 wxString title;
2676
2677 // If a child, leave wxWidgets to call the function on the actual
2678 // child object.
2679 if (childId > 0)
2680 return wxACC_NOT_IMPLEMENTED;
2681
2682 // This will eventually be replaced by specialised
2683 // accessible classes, one for each kind of wxWidgets
2684 // control or window.
2685 #if wxUSE_BUTTON
2686 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2687 title = ((wxButton*) GetWindow())->GetLabel();
2688 else
2689 #endif
2690 title = GetWindow()->GetName();
2691
2692 if (!title.empty())
2693 {
2694 *name = title;
2695 return wxACC_OK;
2696 }
2697 else
2698 return wxACC_NOT_IMPLEMENTED;
2699 }
2700
2701 // Gets the number of children.
2702 wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2703 {
2704 wxASSERT( GetWindow() != NULL );
2705 if (!GetWindow())
2706 return wxACC_FAIL;
2707
2708 *childId = (int) GetWindow()->GetChildren().GetCount();
2709 return wxACC_OK;
2710 }
2711
2712 // Gets the specified child (starting from 1).
2713 // If *child is NULL and return value is wxACC_OK,
2714 // this means that the child is a simple element and
2715 // not an accessible object.
2716 wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2717 {
2718 wxASSERT( GetWindow() != NULL );
2719 if (!GetWindow())
2720 return wxACC_FAIL;
2721
2722 if (childId == 0)
2723 {
2724 *child = this;
2725 return wxACC_OK;
2726 }
2727
2728 if (childId > (int) GetWindow()->GetChildren().GetCount())
2729 return wxACC_FAIL;
2730
2731 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
2732 *child = childWindow->GetOrCreateAccessible();
2733 if (*child)
2734 return wxACC_OK;
2735 else
2736 return wxACC_FAIL;
2737 }
2738
2739 // Gets the parent, or NULL.
2740 wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2741 {
2742 wxASSERT( GetWindow() != NULL );
2743 if (!GetWindow())
2744 return wxACC_FAIL;
2745
2746 wxWindow* parentWindow = GetWindow()->GetParent();
2747 if (!parentWindow)
2748 {
2749 *parent = NULL;
2750 return wxACC_OK;
2751 }
2752 else
2753 {
2754 *parent = parentWindow->GetOrCreateAccessible();
2755 if (*parent)
2756 return wxACC_OK;
2757 else
2758 return wxACC_FAIL;
2759 }
2760 }
2761
2762 // Performs the default action. childId is 0 (the action for this object)
2763 // or > 0 (the action for a child).
2764 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2765 // window (e.g. an edit control).
2766 wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
2767 {
2768 wxASSERT( GetWindow() != NULL );
2769 if (!GetWindow())
2770 return wxACC_FAIL;
2771
2772 return wxACC_NOT_IMPLEMENTED;
2773 }
2774
2775 // Gets the default action for this object (0) or > 0 (the action for a child).
2776 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2777 // string if there is no action.
2778 // The retrieved string describes the action that is performed on an object,
2779 // not what the object does as a result. For example, a toolbar button that prints
2780 // a document has a default action of "Press" rather than "Prints the current document."
2781 wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
2782 {
2783 wxASSERT( GetWindow() != NULL );
2784 if (!GetWindow())
2785 return wxACC_FAIL;
2786
2787 return wxACC_NOT_IMPLEMENTED;
2788 }
2789
2790 // Returns the description for this object or a child.
2791 wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
2792 {
2793 wxASSERT( GetWindow() != NULL );
2794 if (!GetWindow())
2795 return wxACC_FAIL;
2796
2797 wxString ht(GetWindow()->GetHelpText());
2798 if (!ht.empty())
2799 {
2800 *description = ht;
2801 return wxACC_OK;
2802 }
2803 return wxACC_NOT_IMPLEMENTED;
2804 }
2805
2806 // Returns help text for this object or a child, similar to tooltip text.
2807 wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
2808 {
2809 wxASSERT( GetWindow() != NULL );
2810 if (!GetWindow())
2811 return wxACC_FAIL;
2812
2813 wxString ht(GetWindow()->GetHelpText());
2814 if (!ht.empty())
2815 {
2816 *helpText = ht;
2817 return wxACC_OK;
2818 }
2819 return wxACC_NOT_IMPLEMENTED;
2820 }
2821
2822 // Returns the keyboard shortcut for this object or child.
2823 // Return e.g. ALT+K
2824 wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
2825 {
2826 wxASSERT( GetWindow() != NULL );
2827 if (!GetWindow())
2828 return wxACC_FAIL;
2829
2830 return wxACC_NOT_IMPLEMENTED;
2831 }
2832
2833 // Returns a role constant.
2834 wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
2835 {
2836 wxASSERT( GetWindow() != NULL );
2837 if (!GetWindow())
2838 return wxACC_FAIL;
2839
2840 // If a child, leave wxWidgets to call the function on the actual
2841 // child object.
2842 if (childId > 0)
2843 return wxACC_NOT_IMPLEMENTED;
2844
2845 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2846 return wxACC_NOT_IMPLEMENTED;
2847 #if wxUSE_STATUSBAR
2848 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2849 return wxACC_NOT_IMPLEMENTED;
2850 #endif
2851 #if wxUSE_TOOLBAR
2852 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2853 return wxACC_NOT_IMPLEMENTED;
2854 #endif
2855
2856 //*role = wxROLE_SYSTEM_CLIENT;
2857 *role = wxROLE_SYSTEM_CLIENT;
2858 return wxACC_OK;
2859
2860 #if 0
2861 return wxACC_NOT_IMPLEMENTED;
2862 #endif
2863 }
2864
2865 // Returns a state constant.
2866 wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
2867 {
2868 wxASSERT( GetWindow() != NULL );
2869 if (!GetWindow())
2870 return wxACC_FAIL;
2871
2872 // If a child, leave wxWidgets to call the function on the actual
2873 // child object.
2874 if (childId > 0)
2875 return wxACC_NOT_IMPLEMENTED;
2876
2877 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2878 return wxACC_NOT_IMPLEMENTED;
2879
2880 #if wxUSE_STATUSBAR
2881 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2882 return wxACC_NOT_IMPLEMENTED;
2883 #endif
2884 #if wxUSE_TOOLBAR
2885 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2886 return wxACC_NOT_IMPLEMENTED;
2887 #endif
2888
2889 *state = 0;
2890 return wxACC_OK;
2891
2892 #if 0
2893 return wxACC_NOT_IMPLEMENTED;
2894 #endif
2895 }
2896
2897 // Returns a localized string representing the value for the object
2898 // or child.
2899 wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
2900 {
2901 wxASSERT( GetWindow() != NULL );
2902 if (!GetWindow())
2903 return wxACC_FAIL;
2904
2905 return wxACC_NOT_IMPLEMENTED;
2906 }
2907
2908 // Selects the object or child.
2909 wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
2910 {
2911 wxASSERT( GetWindow() != NULL );
2912 if (!GetWindow())
2913 return wxACC_FAIL;
2914
2915 return wxACC_NOT_IMPLEMENTED;
2916 }
2917
2918 // Gets the window with the keyboard focus.
2919 // If childId is 0 and child is NULL, no object in
2920 // this subhierarchy has the focus.
2921 // If this object has the focus, child should be 'this'.
2922 wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
2923 {
2924 wxASSERT( GetWindow() != NULL );
2925 if (!GetWindow())
2926 return wxACC_FAIL;
2927
2928 return wxACC_NOT_IMPLEMENTED;
2929 }
2930
2931 // Gets a variant representing the selected children
2932 // of this object.
2933 // Acceptable values:
2934 // - a null variant (IsNull() returns true)
2935 // - a list variant (GetType() == wxT("list")
2936 // - an integer representing the selected child element,
2937 // or 0 if this object is selected (GetType() == wxT("long")
2938 // - a "void*" pointer to a wxAccessible child object
2939 wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
2940 {
2941 wxASSERT( GetWindow() != NULL );
2942 if (!GetWindow())
2943 return wxACC_FAIL;
2944
2945 return wxACC_NOT_IMPLEMENTED;
2946 }
2947
2948 #endif // wxUSE_ACCESSIBILITY