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