wxPlatformInfo (patch 1532064)
[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 ( deleteOld )
1654 delete m_windowSizer;
1655
1656 m_windowSizer = sizer;
1657
1658 SetAutoLayout( sizer != NULL );
1659 }
1660
1661 void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
1662 {
1663 SetSizer( sizer, deleteOld );
1664 sizer->SetSizeHints( (wxWindow*) this );
1665 }
1666
1667
1668 void wxWindowBase::SetContainingSizer(wxSizer* sizer)
1669 {
1670 // adding a window to a sizer twice is going to result in fatal and
1671 // hard to debug problems later because when deleting the second
1672 // associated wxSizerItem we're going to dereference a dangling
1673 // pointer; so try to detect this as early as possible
1674 wxASSERT_MSG( !sizer || m_containingSizer != sizer,
1675 _T("Adding a window to the same sizer twice?") );
1676
1677 m_containingSizer = sizer;
1678 }
1679
1680 #if wxUSE_CONSTRAINTS
1681
1682 void wxWindowBase::SatisfyConstraints()
1683 {
1684 wxLayoutConstraints *constr = GetConstraints();
1685 bool wasOk = constr && constr->AreSatisfied();
1686
1687 ResetConstraints(); // Mark all constraints as unevaluated
1688
1689 int noChanges = 1;
1690
1691 // if we're a top level panel (i.e. our parent is frame/dialog), our
1692 // own constraints will never be satisfied any more unless we do it
1693 // here
1694 if ( wasOk )
1695 {
1696 while ( noChanges > 0 )
1697 {
1698 LayoutPhase1(&noChanges);
1699 }
1700 }
1701
1702 LayoutPhase2(&noChanges);
1703 }
1704
1705 #endif // wxUSE_CONSTRAINTS
1706
1707 bool wxWindowBase::Layout()
1708 {
1709 // If there is a sizer, use it instead of the constraints
1710 if ( GetSizer() )
1711 {
1712 int w = 0, h = 0;
1713 GetVirtualSize(&w, &h);
1714 GetSizer()->SetDimension( 0, 0, w, h );
1715 }
1716 #if wxUSE_CONSTRAINTS
1717 else
1718 {
1719 SatisfyConstraints(); // Find the right constraints values
1720 SetConstraintSizes(); // Recursively set the real window sizes
1721 }
1722 #endif
1723
1724 return true;
1725 }
1726
1727 #if wxUSE_CONSTRAINTS
1728
1729 // first phase of the constraints evaluation: set our own constraints
1730 bool wxWindowBase::LayoutPhase1(int *noChanges)
1731 {
1732 wxLayoutConstraints *constr = GetConstraints();
1733
1734 return !constr || constr->SatisfyConstraints(this, noChanges);
1735 }
1736
1737 // second phase: set the constraints for our children
1738 bool wxWindowBase::LayoutPhase2(int *noChanges)
1739 {
1740 *noChanges = 0;
1741
1742 // Layout children
1743 DoPhase(1);
1744
1745 // Layout grand children
1746 DoPhase(2);
1747
1748 return true;
1749 }
1750
1751 // Do a phase of evaluating child constraints
1752 bool wxWindowBase::DoPhase(int phase)
1753 {
1754 // the list containing the children for which the constraints are already
1755 // set correctly
1756 wxWindowList succeeded;
1757
1758 // the max number of iterations we loop before concluding that we can't set
1759 // the constraints
1760 static const int maxIterations = 500;
1761
1762 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
1763 {
1764 int noChanges = 0;
1765
1766 // loop over all children setting their constraints
1767 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1768 node;
1769 node = node->GetNext() )
1770 {
1771 wxWindow *child = node->GetData();
1772 if ( child->IsTopLevel() )
1773 {
1774 // top level children are not inside our client area
1775 continue;
1776 }
1777
1778 if ( !child->GetConstraints() || succeeded.Find(child) )
1779 {
1780 // this one is either already ok or nothing we can do about it
1781 continue;
1782 }
1783
1784 int tempNoChanges = 0;
1785 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
1786 : child->LayoutPhase2(&tempNoChanges);
1787 noChanges += tempNoChanges;
1788
1789 if ( success )
1790 {
1791 succeeded.Append(child);
1792 }
1793 }
1794
1795 if ( !noChanges )
1796 {
1797 // constraints are set
1798 break;
1799 }
1800 }
1801
1802 return true;
1803 }
1804
1805 void wxWindowBase::ResetConstraints()
1806 {
1807 wxLayoutConstraints *constr = GetConstraints();
1808 if ( constr )
1809 {
1810 constr->left.SetDone(false);
1811 constr->top.SetDone(false);
1812 constr->right.SetDone(false);
1813 constr->bottom.SetDone(false);
1814 constr->width.SetDone(false);
1815 constr->height.SetDone(false);
1816 constr->centreX.SetDone(false);
1817 constr->centreY.SetDone(false);
1818 }
1819
1820 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1821 while (node)
1822 {
1823 wxWindow *win = node->GetData();
1824 if ( !win->IsTopLevel() )
1825 win->ResetConstraints();
1826 node = node->GetNext();
1827 }
1828 }
1829
1830 // Need to distinguish between setting the 'fake' size for windows and sizers,
1831 // and setting the real values.
1832 void wxWindowBase::SetConstraintSizes(bool recurse)
1833 {
1834 wxLayoutConstraints *constr = GetConstraints();
1835 if ( constr && constr->AreSatisfied() )
1836 {
1837 int x = constr->left.GetValue();
1838 int y = constr->top.GetValue();
1839 int w = constr->width.GetValue();
1840 int h = constr->height.GetValue();
1841
1842 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1843 (constr->height.GetRelationship() != wxAsIs) )
1844 {
1845 SetSize(x, y, w, h);
1846 }
1847 else
1848 {
1849 // If we don't want to resize this window, just move it...
1850 Move(x, y);
1851 }
1852 }
1853 else if ( constr )
1854 {
1855 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1856 GetClassInfo()->GetClassName(),
1857 GetName().c_str());
1858 }
1859
1860 if ( recurse )
1861 {
1862 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1863 while (node)
1864 {
1865 wxWindow *win = node->GetData();
1866 if ( !win->IsTopLevel() && win->GetConstraints() )
1867 win->SetConstraintSizes();
1868 node = node->GetNext();
1869 }
1870 }
1871 }
1872
1873 // Only set the size/position of the constraint (if any)
1874 void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1875 {
1876 wxLayoutConstraints *constr = GetConstraints();
1877 if ( constr )
1878 {
1879 if ( x != wxDefaultCoord )
1880 {
1881 constr->left.SetValue(x);
1882 constr->left.SetDone(true);
1883 }
1884 if ( y != wxDefaultCoord )
1885 {
1886 constr->top.SetValue(y);
1887 constr->top.SetDone(true);
1888 }
1889 if ( w != wxDefaultCoord )
1890 {
1891 constr->width.SetValue(w);
1892 constr->width.SetDone(true);
1893 }
1894 if ( h != wxDefaultCoord )
1895 {
1896 constr->height.SetValue(h);
1897 constr->height.SetDone(true);
1898 }
1899 }
1900 }
1901
1902 void wxWindowBase::MoveConstraint(int x, int y)
1903 {
1904 wxLayoutConstraints *constr = GetConstraints();
1905 if ( constr )
1906 {
1907 if ( x != wxDefaultCoord )
1908 {
1909 constr->left.SetValue(x);
1910 constr->left.SetDone(true);
1911 }
1912 if ( y != wxDefaultCoord )
1913 {
1914 constr->top.SetValue(y);
1915 constr->top.SetDone(true);
1916 }
1917 }
1918 }
1919
1920 void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1921 {
1922 wxLayoutConstraints *constr = GetConstraints();
1923 if ( constr )
1924 {
1925 *w = constr->width.GetValue();
1926 *h = constr->height.GetValue();
1927 }
1928 else
1929 GetSize(w, h);
1930 }
1931
1932 void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1933 {
1934 wxLayoutConstraints *constr = GetConstraints();
1935 if ( constr )
1936 {
1937 *w = constr->width.GetValue();
1938 *h = constr->height.GetValue();
1939 }
1940 else
1941 GetClientSize(w, h);
1942 }
1943
1944 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1945 {
1946 wxLayoutConstraints *constr = GetConstraints();
1947 if ( constr )
1948 {
1949 *x = constr->left.GetValue();
1950 *y = constr->top.GetValue();
1951 }
1952 else
1953 GetPosition(x, y);
1954 }
1955
1956 #endif // wxUSE_CONSTRAINTS
1957
1958 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
1959 {
1960 // don't do it for the dialogs/frames - they float independently of their
1961 // parent
1962 if ( !IsTopLevel() )
1963 {
1964 wxWindow *parent = GetParent();
1965 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
1966 {
1967 wxPoint pt(parent->GetClientAreaOrigin());
1968 x += pt.x;
1969 y += pt.y;
1970 }
1971 }
1972 }
1973
1974 // ----------------------------------------------------------------------------
1975 // do Update UI processing for child controls
1976 // ----------------------------------------------------------------------------
1977
1978 void wxWindowBase::UpdateWindowUI(long flags)
1979 {
1980 wxUpdateUIEvent event(GetId());
1981 event.SetEventObject(this);
1982
1983 if ( GetEventHandler()->ProcessEvent(event) )
1984 {
1985 DoUpdateWindowUI(event);
1986 }
1987
1988 if (flags & wxUPDATE_UI_RECURSE)
1989 {
1990 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1991 while (node)
1992 {
1993 wxWindow* child = (wxWindow*) node->GetData();
1994 child->UpdateWindowUI(flags);
1995 node = node->GetNext();
1996 }
1997 }
1998 }
1999
2000 // do the window-specific processing after processing the update event
2001 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
2002 {
2003 if ( event.GetSetEnabled() )
2004 Enable(event.GetEnabled());
2005
2006 if ( event.GetSetShown() )
2007 Show(event.GetShown());
2008 }
2009
2010 #if 0
2011 // call internal idle recursively
2012 // may be obsolete (wait until OnIdle scheme stabilises)
2013 void wxWindowBase::ProcessInternalIdle()
2014 {
2015 OnInternalIdle();
2016
2017 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2018 while (node)
2019 {
2020 wxWindow *child = node->GetData();
2021 child->ProcessInternalIdle();
2022 node = node->GetNext();
2023 }
2024 }
2025 #endif
2026
2027 // ----------------------------------------------------------------------------
2028 // dialog units translations
2029 // ----------------------------------------------------------------------------
2030
2031 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
2032 {
2033 int charWidth = GetCharWidth();
2034 int charHeight = GetCharHeight();
2035 wxPoint pt2 = wxDefaultPosition;
2036 if (pt.x != wxDefaultCoord)
2037 pt2.x = (int) ((pt.x * 4) / charWidth);
2038 if (pt.y != wxDefaultCoord)
2039 pt2.y = (int) ((pt.y * 8) / charHeight);
2040
2041 return pt2;
2042 }
2043
2044 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
2045 {
2046 int charWidth = GetCharWidth();
2047 int charHeight = GetCharHeight();
2048 wxPoint pt2 = wxDefaultPosition;
2049 if (pt.x != wxDefaultCoord)
2050 pt2.x = (int) ((pt.x * charWidth) / 4);
2051 if (pt.y != wxDefaultCoord)
2052 pt2.y = (int) ((pt.y * charHeight) / 8);
2053
2054 return pt2;
2055 }
2056
2057 // ----------------------------------------------------------------------------
2058 // event handlers
2059 // ----------------------------------------------------------------------------
2060
2061 // propagate the colour change event to the subwindows
2062 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
2063 {
2064 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2065 while ( node )
2066 {
2067 // Only propagate to non-top-level windows
2068 wxWindow *win = node->GetData();
2069 if ( !win->IsTopLevel() )
2070 {
2071 wxSysColourChangedEvent event2;
2072 event.SetEventObject(win);
2073 win->GetEventHandler()->ProcessEvent(event2);
2074 }
2075
2076 node = node->GetNext();
2077 }
2078
2079 Refresh();
2080 }
2081
2082 // the default action is to populate dialog with data when it's created,
2083 // and nudge the UI into displaying itself correctly in case
2084 // we've turned the wxUpdateUIEvents frequency down low.
2085 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2086 {
2087 TransferDataToWindow();
2088
2089 // Update the UI at this point
2090 UpdateWindowUI(wxUPDATE_UI_RECURSE);
2091 }
2092
2093 // methods for drawing the sizers in a visible way
2094 #ifdef __WXDEBUG__
2095
2096 static void DrawSizers(wxWindowBase *win);
2097
2098 static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false)
2099 {
2100 wxClientDC dc((wxWindow *)win);
2101 dc.SetPen(*wxRED_PEN);
2102 dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH);
2103 dc.DrawRectangle(rect.Deflate(1, 1));
2104 }
2105
2106 static void DrawSizer(wxWindowBase *win, wxSizer *sizer)
2107 {
2108 const wxSizerItemList& items = sizer->GetChildren();
2109 for ( wxSizerItemList::const_iterator i = items.begin(),
2110 end = items.end();
2111 i != end;
2112 ++i )
2113 {
2114 wxSizerItem *item = *i;
2115 if ( item->IsSizer() )
2116 {
2117 DrawBorder(win, item->GetRect().Deflate(2));
2118 DrawSizer(win, item->GetSizer());
2119 }
2120 else if ( item->IsSpacer() )
2121 {
2122 DrawBorder(win, item->GetRect().Deflate(2), true);
2123 }
2124 else if ( item->IsWindow() )
2125 {
2126 DrawSizers(item->GetWindow());
2127 }
2128 }
2129 }
2130
2131 static void DrawSizers(wxWindowBase *win)
2132 {
2133 wxSizer *sizer = win->GetSizer();
2134 if ( sizer )
2135 {
2136 DrawBorder(win, win->GetClientSize());
2137 DrawSizer(win, sizer);
2138 }
2139 else // no sizer, still recurse into the children
2140 {
2141 const wxWindowList& children = win->GetChildren();
2142 for ( wxWindowList::const_iterator i = children.begin(),
2143 end = children.end();
2144 i != end;
2145 ++i )
2146 {
2147 DrawSizers(*i);
2148 }
2149 }
2150 }
2151
2152 #endif // __WXDEBUG__
2153
2154 // process special middle clicks
2155 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2156 {
2157 if ( event.ControlDown() && event.AltDown() )
2158 {
2159 #ifdef __WXDEBUG__
2160 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2161 if ( event.ShiftDown() )
2162 {
2163 DrawSizers(this);
2164 return;
2165 }
2166 #endif // __WXDEBUG__
2167
2168 #if wxUSE_MSGDLG
2169 // don't translate these strings, they're for diagnostics purposes only
2170 wxString msg;
2171 msg.Printf(_T("wxWidgets Library (%s port)\n")
2172 _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n")
2173 _T("Copyright (c) 1995-2006 wxWidgets team"),
2174 wxPlatformInfo().GetPortIdName().c_str(),
2175 wxMAJOR_VERSION,
2176 wxMINOR_VERSION,
2177 wxRELEASE_NUMBER,
2178 #if wxUSE_UNICODE
2179 L" (Unicode)",
2180 #else
2181 wxEmptyString,
2182 #endif
2183 #ifdef __WXDEBUG__
2184 _T(" Debug build"),
2185 #else
2186 wxEmptyString,
2187 #endif
2188 __TDATE__,
2189 __TTIME__,
2190 #ifdef __WXGTK__
2191 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()
2192 #else
2193 wxEmptyString
2194 #endif
2195 );
2196
2197 wxMessageBox(msg, _T("wxWidgets information"),
2198 wxICON_INFORMATION | wxOK,
2199 (wxWindow *)this);
2200 }
2201 else
2202 #endif // wxUSE_MSGDLG
2203 {
2204 event.Skip();
2205 }
2206 }
2207
2208 // ----------------------------------------------------------------------------
2209 // accessibility
2210 // ----------------------------------------------------------------------------
2211
2212 #if wxUSE_ACCESSIBILITY
2213 void wxWindowBase::SetAccessible(wxAccessible* accessible)
2214 {
2215 if (m_accessible && (accessible != m_accessible))
2216 delete m_accessible;
2217 m_accessible = accessible;
2218 if (m_accessible)
2219 m_accessible->SetWindow((wxWindow*) this);
2220 }
2221
2222 // Returns the accessible object, creating if necessary.
2223 wxAccessible* wxWindowBase::GetOrCreateAccessible()
2224 {
2225 if (!m_accessible)
2226 m_accessible = CreateAccessible();
2227 return m_accessible;
2228 }
2229
2230 // Override to create a specific accessible object.
2231 wxAccessible* wxWindowBase::CreateAccessible()
2232 {
2233 return new wxWindowAccessible((wxWindow*) this);
2234 }
2235
2236 #endif
2237
2238 // ----------------------------------------------------------------------------
2239 // list classes implementation
2240 // ----------------------------------------------------------------------------
2241
2242 #if wxUSE_STL
2243
2244 #include "wx/listimpl.cpp"
2245 WX_DEFINE_LIST(wxWindowList)
2246
2247 #else
2248
2249 void wxWindowListNode::DeleteData()
2250 {
2251 delete (wxWindow *)GetData();
2252 }
2253
2254 #endif
2255
2256 // ----------------------------------------------------------------------------
2257 // borders
2258 // ----------------------------------------------------------------------------
2259
2260 wxBorder wxWindowBase::GetBorder(long flags) const
2261 {
2262 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
2263 if ( border == wxBORDER_DEFAULT )
2264 {
2265 border = GetDefaultBorder();
2266 }
2267
2268 return border;
2269 }
2270
2271 wxBorder wxWindowBase::GetDefaultBorder() const
2272 {
2273 return wxBORDER_NONE;
2274 }
2275
2276 // ----------------------------------------------------------------------------
2277 // hit testing
2278 // ----------------------------------------------------------------------------
2279
2280 wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2281 {
2282 // here we just check if the point is inside the window or not
2283
2284 // check the top and left border first
2285 bool outside = x < 0 || y < 0;
2286 if ( !outside )
2287 {
2288 // check the right and bottom borders too
2289 wxSize size = GetSize();
2290 outside = x >= size.x || y >= size.y;
2291 }
2292
2293 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2294 }
2295
2296 // ----------------------------------------------------------------------------
2297 // mouse capture
2298 // ----------------------------------------------------------------------------
2299
2300 struct WXDLLEXPORT wxWindowNext
2301 {
2302 wxWindow *win;
2303 wxWindowNext *next;
2304 } *wxWindowBase::ms_winCaptureNext = NULL;
2305 wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL;
2306 bool wxWindowBase::ms_winCaptureChanging = false;
2307
2308 void wxWindowBase::CaptureMouse()
2309 {
2310 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2311
2312 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive CaptureMouse call?") );
2313
2314 ms_winCaptureChanging = true;
2315
2316 wxWindow *winOld = GetCapture();
2317 if ( winOld )
2318 {
2319 ((wxWindowBase*) winOld)->DoReleaseMouse();
2320
2321 // save it on stack
2322 wxWindowNext *item = new wxWindowNext;
2323 item->win = winOld;
2324 item->next = ms_winCaptureNext;
2325 ms_winCaptureNext = item;
2326 }
2327 //else: no mouse capture to save
2328
2329 DoCaptureMouse();
2330 ms_winCaptureCurrent = (wxWindow*)this;
2331
2332 ms_winCaptureChanging = false;
2333 }
2334
2335 void wxWindowBase::ReleaseMouse()
2336 {
2337 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2338
2339 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive ReleaseMouse call?") );
2340
2341 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2342
2343 ms_winCaptureChanging = true;
2344
2345 DoReleaseMouse();
2346 ms_winCaptureCurrent = NULL;
2347
2348 if ( ms_winCaptureNext )
2349 {
2350 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
2351 ms_winCaptureCurrent = ms_winCaptureNext->win;
2352
2353 wxWindowNext *item = ms_winCaptureNext;
2354 ms_winCaptureNext = item->next;
2355 delete item;
2356 }
2357 //else: stack is empty, no previous capture
2358
2359 ms_winCaptureChanging = false;
2360
2361 wxLogTrace(_T("mousecapture"),
2362 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
2363 wx_static_cast(void*, GetCapture()));
2364 }
2365
2366 static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
2367 {
2368 wxMouseCaptureLostEvent event(win->GetId());
2369 event.SetEventObject(win);
2370 if ( !win->GetEventHandler()->ProcessEvent(event) )
2371 {
2372 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2373 }
2374 }
2375
2376 /* static */
2377 void wxWindowBase::NotifyCaptureLost()
2378 {
2379 // don't do anything if capture lost was expected, i.e. resulted from
2380 // a wx call to ReleaseMouse or CaptureMouse:
2381 if ( ms_winCaptureChanging )
2382 return;
2383
2384 // if the capture was lost unexpectedly, notify every window that has
2385 // capture (on stack or current) about it and clear the stack:
2386
2387 if ( ms_winCaptureCurrent )
2388 {
2389 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent);
2390 ms_winCaptureCurrent = NULL;
2391 }
2392
2393 while ( ms_winCaptureNext )
2394 {
2395 wxWindowNext *item = ms_winCaptureNext;
2396 ms_winCaptureNext = item->next;
2397
2398 DoNotifyWindowAboutCaptureLost(item->win);
2399
2400 delete item;
2401 }
2402 }
2403
2404 #if wxUSE_HOTKEY
2405
2406 bool
2407 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2408 int WXUNUSED(modifiers),
2409 int WXUNUSED(keycode))
2410 {
2411 // not implemented
2412 return false;
2413 }
2414
2415 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
2416 {
2417 // not implemented
2418 return false;
2419 }
2420
2421 #endif // wxUSE_HOTKEY
2422
2423 void wxWindowBase::SendDestroyEvent()
2424 {
2425 wxWindowDestroyEvent event;
2426 event.SetEventObject(this);
2427 event.SetId(GetId());
2428 GetEventHandler()->ProcessEvent(event);
2429 }
2430
2431 // ----------------------------------------------------------------------------
2432 // event processing
2433 // ----------------------------------------------------------------------------
2434
2435 bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
2436 {
2437 #if wxUSE_VALIDATORS
2438 // Can only use the validator of the window which
2439 // is receiving the event
2440 if ( event.GetEventObject() == this )
2441 {
2442 wxValidator *validator = GetValidator();
2443 if ( validator && validator->ProcessEvent(event) )
2444 {
2445 return true;
2446 }
2447 }
2448 #endif // wxUSE_VALIDATORS
2449
2450 return false;
2451 }
2452
2453 bool wxWindowBase::TryParent(wxEvent& event)
2454 {
2455 // carry on up the parent-child hierarchy if the propagation count hasn't
2456 // reached zero yet
2457 if ( event.ShouldPropagate() )
2458 {
2459 // honour the requests to stop propagation at this window: this is
2460 // used by the dialogs, for example, to prevent processing the events
2461 // from the dialog controls in the parent frame which rarely, if ever,
2462 // makes sense
2463 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2464 {
2465 wxWindow *parent = GetParent();
2466 if ( parent && !parent->IsBeingDeleted() )
2467 {
2468 wxPropagateOnce propagateOnce(event);
2469
2470 return parent->GetEventHandler()->ProcessEvent(event);
2471 }
2472 }
2473 }
2474
2475 return wxEvtHandler::TryParent(event);
2476 }
2477
2478 // ----------------------------------------------------------------------------
2479 // keyboard navigation
2480 // ----------------------------------------------------------------------------
2481
2482 // Navigates in the specified direction.
2483 bool wxWindowBase::Navigate(int flags)
2484 {
2485 wxNavigationKeyEvent eventNav;
2486 eventNav.SetFlags(flags);
2487 eventNav.SetEventObject(this);
2488 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
2489 {
2490 return true;
2491 }
2492 return false;
2493 }
2494
2495 void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
2496 {
2497 // check that we're not a top level window
2498 wxCHECK_RET( GetParent(),
2499 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2500
2501 // detect the special case when we have nothing to do anyhow and when the
2502 // code below wouldn't work
2503 if ( win == this )
2504 return;
2505
2506 // find the target window in the siblings list
2507 wxWindowList& siblings = GetParent()->GetChildren();
2508 wxWindowList::compatibility_iterator i = siblings.Find(win);
2509 wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2510
2511 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2512 // can't just move the node around
2513 wxWindow *self = (wxWindow *)this;
2514 siblings.DeleteObject(self);
2515 if ( move == MoveAfter )
2516 {
2517 i = i->GetNext();
2518 }
2519
2520 if ( i )
2521 {
2522 siblings.Insert(i, self);
2523 }
2524 else // MoveAfter and win was the last sibling
2525 {
2526 siblings.Append(self);
2527 }
2528 }
2529
2530 // ----------------------------------------------------------------------------
2531 // focus handling
2532 // ----------------------------------------------------------------------------
2533
2534 /*static*/ wxWindow* wxWindowBase::FindFocus()
2535 {
2536 wxWindowBase *win = DoFindFocus();
2537 return win ? win->GetMainWindowOfCompositeControl() : NULL;
2538 }
2539
2540 // ----------------------------------------------------------------------------
2541 // global functions
2542 // ----------------------------------------------------------------------------
2543
2544 wxWindow* wxGetTopLevelParent(wxWindow *win)
2545 {
2546 while ( win && !win->IsTopLevel() )
2547 win = win->GetParent();
2548
2549 return win;
2550 }
2551
2552 #if wxUSE_ACCESSIBILITY
2553 // ----------------------------------------------------------------------------
2554 // accessible object for windows
2555 // ----------------------------------------------------------------------------
2556
2557 // Can return either a child object, or an integer
2558 // representing the child element, starting from 1.
2559 wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
2560 {
2561 wxASSERT( GetWindow() != NULL );
2562 if (!GetWindow())
2563 return wxACC_FAIL;
2564
2565 return wxACC_NOT_IMPLEMENTED;
2566 }
2567
2568 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2569 wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2570 {
2571 wxASSERT( GetWindow() != NULL );
2572 if (!GetWindow())
2573 return wxACC_FAIL;
2574
2575 wxWindow* win = NULL;
2576 if (elementId == 0)
2577 {
2578 win = GetWindow();
2579 }
2580 else
2581 {
2582 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2583 {
2584 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
2585 }
2586 else
2587 return wxACC_FAIL;
2588 }
2589 if (win)
2590 {
2591 rect = win->GetRect();
2592 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2593 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2594 return wxACC_OK;
2595 }
2596
2597 return wxACC_NOT_IMPLEMENTED;
2598 }
2599
2600 // Navigates from fromId to toId/toObject.
2601 wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
2602 int* WXUNUSED(toId), wxAccessible** toObject)
2603 {
2604 wxASSERT( GetWindow() != NULL );
2605 if (!GetWindow())
2606 return wxACC_FAIL;
2607
2608 switch (navDir)
2609 {
2610 case wxNAVDIR_FIRSTCHILD:
2611 {
2612 if (GetWindow()->GetChildren().GetCount() == 0)
2613 return wxACC_FALSE;
2614 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2615 *toObject = childWindow->GetOrCreateAccessible();
2616
2617 return wxACC_OK;
2618 }
2619 case wxNAVDIR_LASTCHILD:
2620 {
2621 if (GetWindow()->GetChildren().GetCount() == 0)
2622 return wxACC_FALSE;
2623 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2624 *toObject = childWindow->GetOrCreateAccessible();
2625
2626 return wxACC_OK;
2627 }
2628 case wxNAVDIR_RIGHT:
2629 case wxNAVDIR_DOWN:
2630 case wxNAVDIR_NEXT:
2631 {
2632 wxWindowList::compatibility_iterator node =
2633 wxWindowList::compatibility_iterator();
2634 if (fromId == 0)
2635 {
2636 // Can't navigate to sibling of this window
2637 // if we're a top-level window.
2638 if (!GetWindow()->GetParent())
2639 return wxACC_NOT_IMPLEMENTED;
2640
2641 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2642 }
2643 else
2644 {
2645 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2646 node = GetWindow()->GetChildren().Item(fromId-1);
2647 }
2648
2649 if (node && node->GetNext())
2650 {
2651 wxWindow* nextWindow = node->GetNext()->GetData();
2652 *toObject = nextWindow->GetOrCreateAccessible();
2653 return wxACC_OK;
2654 }
2655 else
2656 return wxACC_FALSE;
2657 }
2658 case wxNAVDIR_LEFT:
2659 case wxNAVDIR_UP:
2660 case wxNAVDIR_PREVIOUS:
2661 {
2662 wxWindowList::compatibility_iterator node =
2663 wxWindowList::compatibility_iterator();
2664 if (fromId == 0)
2665 {
2666 // Can't navigate to sibling of this window
2667 // if we're a top-level window.
2668 if (!GetWindow()->GetParent())
2669 return wxACC_NOT_IMPLEMENTED;
2670
2671 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2672 }
2673 else
2674 {
2675 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2676 node = GetWindow()->GetChildren().Item(fromId-1);
2677 }
2678
2679 if (node && node->GetPrevious())
2680 {
2681 wxWindow* previousWindow = node->GetPrevious()->GetData();
2682 *toObject = previousWindow->GetOrCreateAccessible();
2683 return wxACC_OK;
2684 }
2685 else
2686 return wxACC_FALSE;
2687 }
2688 }
2689
2690 return wxACC_NOT_IMPLEMENTED;
2691 }
2692
2693 // Gets the name of the specified object.
2694 wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2695 {
2696 wxASSERT( GetWindow() != NULL );
2697 if (!GetWindow())
2698 return wxACC_FAIL;
2699
2700 wxString title;
2701
2702 // If a child, leave wxWidgets to call the function on the actual
2703 // child object.
2704 if (childId > 0)
2705 return wxACC_NOT_IMPLEMENTED;
2706
2707 // This will eventually be replaced by specialised
2708 // accessible classes, one for each kind of wxWidgets
2709 // control or window.
2710 #if wxUSE_BUTTON
2711 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2712 title = ((wxButton*) GetWindow())->GetLabel();
2713 else
2714 #endif
2715 title = GetWindow()->GetName();
2716
2717 if (!title.empty())
2718 {
2719 *name = title;
2720 return wxACC_OK;
2721 }
2722 else
2723 return wxACC_NOT_IMPLEMENTED;
2724 }
2725
2726 // Gets the number of children.
2727 wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2728 {
2729 wxASSERT( GetWindow() != NULL );
2730 if (!GetWindow())
2731 return wxACC_FAIL;
2732
2733 *childId = (int) GetWindow()->GetChildren().GetCount();
2734 return wxACC_OK;
2735 }
2736
2737 // Gets the specified child (starting from 1).
2738 // If *child is NULL and return value is wxACC_OK,
2739 // this means that the child is a simple element and
2740 // not an accessible object.
2741 wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2742 {
2743 wxASSERT( GetWindow() != NULL );
2744 if (!GetWindow())
2745 return wxACC_FAIL;
2746
2747 if (childId == 0)
2748 {
2749 *child = this;
2750 return wxACC_OK;
2751 }
2752
2753 if (childId > (int) GetWindow()->GetChildren().GetCount())
2754 return wxACC_FAIL;
2755
2756 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
2757 *child = childWindow->GetOrCreateAccessible();
2758 if (*child)
2759 return wxACC_OK;
2760 else
2761 return wxACC_FAIL;
2762 }
2763
2764 // Gets the parent, or NULL.
2765 wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2766 {
2767 wxASSERT( GetWindow() != NULL );
2768 if (!GetWindow())
2769 return wxACC_FAIL;
2770
2771 wxWindow* parentWindow = GetWindow()->GetParent();
2772 if (!parentWindow)
2773 {
2774 *parent = NULL;
2775 return wxACC_OK;
2776 }
2777 else
2778 {
2779 *parent = parentWindow->GetOrCreateAccessible();
2780 if (*parent)
2781 return wxACC_OK;
2782 else
2783 return wxACC_FAIL;
2784 }
2785 }
2786
2787 // Performs the default action. childId is 0 (the action for this object)
2788 // or > 0 (the action for a child).
2789 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2790 // window (e.g. an edit control).
2791 wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
2792 {
2793 wxASSERT( GetWindow() != NULL );
2794 if (!GetWindow())
2795 return wxACC_FAIL;
2796
2797 return wxACC_NOT_IMPLEMENTED;
2798 }
2799
2800 // Gets the default action for this object (0) or > 0 (the action for a child).
2801 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2802 // string if there is no action.
2803 // The retrieved string describes the action that is performed on an object,
2804 // not what the object does as a result. For example, a toolbar button that prints
2805 // a document has a default action of "Press" rather than "Prints the current document."
2806 wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
2807 {
2808 wxASSERT( GetWindow() != NULL );
2809 if (!GetWindow())
2810 return wxACC_FAIL;
2811
2812 return wxACC_NOT_IMPLEMENTED;
2813 }
2814
2815 // Returns the description for this object or a child.
2816 wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
2817 {
2818 wxASSERT( GetWindow() != NULL );
2819 if (!GetWindow())
2820 return wxACC_FAIL;
2821
2822 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
2823 if (!ht.empty())
2824 {
2825 *description = ht;
2826 return wxACC_OK;
2827 }
2828 return wxACC_NOT_IMPLEMENTED;
2829 }
2830
2831 // Returns help text for this object or a child, similar to tooltip text.
2832 wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
2833 {
2834 wxASSERT( GetWindow() != NULL );
2835 if (!GetWindow())
2836 return wxACC_FAIL;
2837
2838 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
2839 if (!ht.empty())
2840 {
2841 *helpText = ht;
2842 return wxACC_OK;
2843 }
2844 return wxACC_NOT_IMPLEMENTED;
2845 }
2846
2847 // Returns the keyboard shortcut for this object or child.
2848 // Return e.g. ALT+K
2849 wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
2850 {
2851 wxASSERT( GetWindow() != NULL );
2852 if (!GetWindow())
2853 return wxACC_FAIL;
2854
2855 return wxACC_NOT_IMPLEMENTED;
2856 }
2857
2858 // Returns a role constant.
2859 wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
2860 {
2861 wxASSERT( GetWindow() != NULL );
2862 if (!GetWindow())
2863 return wxACC_FAIL;
2864
2865 // If a child, leave wxWidgets to call the function on the actual
2866 // child object.
2867 if (childId > 0)
2868 return wxACC_NOT_IMPLEMENTED;
2869
2870 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2871 return wxACC_NOT_IMPLEMENTED;
2872 #if wxUSE_STATUSBAR
2873 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2874 return wxACC_NOT_IMPLEMENTED;
2875 #endif
2876 #if wxUSE_TOOLBAR
2877 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2878 return wxACC_NOT_IMPLEMENTED;
2879 #endif
2880
2881 //*role = wxROLE_SYSTEM_CLIENT;
2882 *role = wxROLE_SYSTEM_CLIENT;
2883 return wxACC_OK;
2884
2885 #if 0
2886 return wxACC_NOT_IMPLEMENTED;
2887 #endif
2888 }
2889
2890 // Returns a state constant.
2891 wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
2892 {
2893 wxASSERT( GetWindow() != NULL );
2894 if (!GetWindow())
2895 return wxACC_FAIL;
2896
2897 // If a child, leave wxWidgets to call the function on the actual
2898 // child object.
2899 if (childId > 0)
2900 return wxACC_NOT_IMPLEMENTED;
2901
2902 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2903 return wxACC_NOT_IMPLEMENTED;
2904
2905 #if wxUSE_STATUSBAR
2906 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2907 return wxACC_NOT_IMPLEMENTED;
2908 #endif
2909 #if wxUSE_TOOLBAR
2910 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2911 return wxACC_NOT_IMPLEMENTED;
2912 #endif
2913
2914 *state = 0;
2915 return wxACC_OK;
2916
2917 #if 0
2918 return wxACC_NOT_IMPLEMENTED;
2919 #endif
2920 }
2921
2922 // Returns a localized string representing the value for the object
2923 // or child.
2924 wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
2925 {
2926 wxASSERT( GetWindow() != NULL );
2927 if (!GetWindow())
2928 return wxACC_FAIL;
2929
2930 return wxACC_NOT_IMPLEMENTED;
2931 }
2932
2933 // Selects the object or child.
2934 wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
2935 {
2936 wxASSERT( GetWindow() != NULL );
2937 if (!GetWindow())
2938 return wxACC_FAIL;
2939
2940 return wxACC_NOT_IMPLEMENTED;
2941 }
2942
2943 // Gets the window with the keyboard focus.
2944 // If childId is 0 and child is NULL, no object in
2945 // this subhierarchy has the focus.
2946 // If this object has the focus, child should be 'this'.
2947 wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
2948 {
2949 wxASSERT( GetWindow() != NULL );
2950 if (!GetWindow())
2951 return wxACC_FAIL;
2952
2953 return wxACC_NOT_IMPLEMENTED;
2954 }
2955
2956 // Gets a variant representing the selected children
2957 // of this object.
2958 // Acceptable values:
2959 // - a null variant (IsNull() returns true)
2960 // - a list variant (GetType() == wxT("list")
2961 // - an integer representing the selected child element,
2962 // or 0 if this object is selected (GetType() == wxT("long")
2963 // - a "void*" pointer to a wxAccessible child object
2964 wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
2965 {
2966 wxASSERT( GetWindow() != NULL );
2967 if (!GetWindow())
2968 return wxACC_FAIL;
2969
2970 return wxACC_NOT_IMPLEMENTED;
2971 }
2972
2973 #endif // wxUSE_ACCESSIBILITY