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