]> git.saurik.com Git - wxWidgets.git/blob - src/common/wincmn.cpp
added wxWindow::IsVisible() method
[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 bool wxWindowBase::IsVisible() const
749 {
750 return IsShown() && (GetParent() == NULL || GetParent()->IsVisible());
751 }
752
753 // ----------------------------------------------------------------------------
754 // RTTI
755 // ----------------------------------------------------------------------------
756
757 bool wxWindowBase::IsTopLevel() const
758 {
759 return false;
760 }
761
762 // ----------------------------------------------------------------------------
763 // reparenting the window
764 // ----------------------------------------------------------------------------
765
766 void wxWindowBase::AddChild(wxWindowBase *child)
767 {
768 wxCHECK_RET( child, wxT("can't add a NULL child") );
769
770 // this should never happen and it will lead to a crash later if it does
771 // because RemoveChild() will remove only one node from the children list
772 // and the other(s) one(s) will be left with dangling pointers in them
773 wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") );
774
775 GetChildren().Append((wxWindow*)child);
776 child->SetParent(this);
777 }
778
779 void wxWindowBase::RemoveChild(wxWindowBase *child)
780 {
781 wxCHECK_RET( child, wxT("can't remove a NULL child") );
782
783 GetChildren().DeleteObject((wxWindow *)child);
784 child->SetParent(NULL);
785 }
786
787 bool wxWindowBase::Reparent(wxWindowBase *newParent)
788 {
789 wxWindow *oldParent = GetParent();
790 if ( newParent == oldParent )
791 {
792 // nothing done
793 return false;
794 }
795
796 // unlink this window from the existing parent.
797 if ( oldParent )
798 {
799 oldParent->RemoveChild(this);
800 }
801 else
802 {
803 wxTopLevelWindows.DeleteObject((wxWindow *)this);
804 }
805
806 // add it to the new one
807 if ( newParent )
808 {
809 newParent->AddChild(this);
810 }
811 else
812 {
813 wxTopLevelWindows.Append((wxWindow *)this);
814 }
815
816 return true;
817 }
818
819 // ----------------------------------------------------------------------------
820 // event handler stuff
821 // ----------------------------------------------------------------------------
822
823 void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
824 {
825 wxEvtHandler *handlerOld = GetEventHandler();
826
827 handler->SetNextHandler(handlerOld);
828
829 if ( handlerOld )
830 GetEventHandler()->SetPreviousHandler(handler);
831
832 SetEventHandler(handler);
833 }
834
835 wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
836 {
837 wxEvtHandler *handlerA = GetEventHandler();
838 if ( handlerA )
839 {
840 wxEvtHandler *handlerB = handlerA->GetNextHandler();
841 handlerA->SetNextHandler((wxEvtHandler *)NULL);
842
843 if ( handlerB )
844 handlerB->SetPreviousHandler((wxEvtHandler *)NULL);
845 SetEventHandler(handlerB);
846
847 if ( deleteHandler )
848 {
849 delete handlerA;
850 handlerA = (wxEvtHandler *)NULL;
851 }
852 }
853
854 return handlerA;
855 }
856
857 bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
858 {
859 wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") );
860
861 wxEvtHandler *handlerPrev = NULL,
862 *handlerCur = GetEventHandler();
863 while ( handlerCur )
864 {
865 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
866
867 if ( handlerCur == handler )
868 {
869 if ( handlerPrev )
870 {
871 handlerPrev->SetNextHandler(handlerNext);
872 }
873 else
874 {
875 SetEventHandler(handlerNext);
876 }
877
878 if ( handlerNext )
879 {
880 handlerNext->SetPreviousHandler ( handlerPrev );
881 }
882
883 handler->SetNextHandler(NULL);
884 handler->SetPreviousHandler(NULL);
885
886 return true;
887 }
888
889 handlerPrev = handlerCur;
890 handlerCur = handlerNext;
891 }
892
893 wxFAIL_MSG( _T("where has the event handler gone?") );
894
895 return false;
896 }
897
898 // ----------------------------------------------------------------------------
899 // colours, fonts &c
900 // ----------------------------------------------------------------------------
901
902 void wxWindowBase::InheritAttributes()
903 {
904 const wxWindowBase * const parent = GetParent();
905 if ( !parent )
906 return;
907
908 // we only inherit attributes which had been explicitly set for the parent
909 // which ensures that this only happens if the user really wants it and
910 // not by default which wouldn't make any sense in modern GUIs where the
911 // controls don't all use the same fonts (nor colours)
912 if ( parent->m_inheritFont && !m_hasFont )
913 SetFont(parent->GetFont());
914
915 // in addition, there is a possibility to explicitly forbid inheriting
916 // colours at each class level by overriding ShouldInheritColours()
917 if ( ShouldInheritColours() )
918 {
919 if ( parent->m_inheritFgCol && !m_hasFgCol )
920 SetForegroundColour(parent->GetForegroundColour());
921
922 // inheriting (solid) background colour is wrong as it totally breaks
923 // any kind of themed backgrounds
924 //
925 // instead, the controls should use the same background as their parent
926 // (ideally by not drawing it at all)
927 #if 0
928 if ( parent->m_inheritBgCol && !m_hasBgCol )
929 SetBackgroundColour(parent->GetBackgroundColour());
930 #endif // 0
931 }
932 }
933
934 /* static */ wxVisualAttributes
935 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
936 {
937 // it is important to return valid values for all attributes from here,
938 // GetXXX() below rely on this
939 wxVisualAttributes attrs;
940 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
941 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
942
943 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
944 // the usual background colour than wxSYS_COLOUR_BTNFACE.
945 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
946 // colour on other platforms.
947
948 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
949 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
950 #else
951 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
952 #endif
953 return attrs;
954 }
955
956 wxColour wxWindowBase::GetBackgroundColour() const
957 {
958 if ( !m_backgroundColour.Ok() )
959 {
960 wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") );
961
962 // get our default background colour
963 wxColour colBg = GetDefaultAttributes().colBg;
964
965 // we must return some valid colour to avoid redoing this every time
966 // and also to avoid surprizing the applications written for older
967 // wxWidgets versions where GetBackgroundColour() always returned
968 // something -- so give them something even if it doesn't make sense
969 // for this window (e.g. it has a themed background)
970 if ( !colBg.Ok() )
971 colBg = GetClassDefaultAttributes().colBg;
972
973 return colBg;
974 }
975 else
976 return m_backgroundColour;
977 }
978
979 wxColour wxWindowBase::GetForegroundColour() const
980 {
981 // logic is the same as above
982 if ( !m_hasFgCol && !m_foregroundColour.Ok() )
983 {
984 wxASSERT_MSG( !m_hasFgCol, _T("we have invalid explicit fg colour?") );
985
986 wxColour colFg = GetDefaultAttributes().colFg;
987
988 if ( !colFg.Ok() )
989 colFg = GetClassDefaultAttributes().colFg;
990
991 return colFg;
992 }
993 else
994 return m_foregroundColour;
995 }
996
997 bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
998 {
999 if ( colour == m_backgroundColour )
1000 return false;
1001
1002 m_hasBgCol = colour.Ok();
1003 if ( m_backgroundStyle != wxBG_STYLE_CUSTOM )
1004 m_backgroundStyle = m_hasBgCol ? wxBG_STYLE_COLOUR : wxBG_STYLE_SYSTEM;
1005
1006 m_inheritBgCol = m_hasBgCol;
1007 m_backgroundColour = colour;
1008 SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
1009 return true;
1010 }
1011
1012 bool wxWindowBase::SetForegroundColour( const wxColour &colour )
1013 {
1014 if (colour == m_foregroundColour )
1015 return false;
1016
1017 m_hasFgCol = colour.Ok();
1018 m_inheritFgCol = m_hasFgCol;
1019 m_foregroundColour = colour;
1020 SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
1021 return true;
1022 }
1023
1024 bool wxWindowBase::SetCursor(const wxCursor& cursor)
1025 {
1026 // setting an invalid cursor is ok, it means that we don't have any special
1027 // cursor
1028 if ( m_cursor == cursor )
1029 {
1030 // no change
1031 return false;
1032 }
1033
1034 m_cursor = cursor;
1035
1036 return true;
1037 }
1038
1039 wxFont wxWindowBase::GetFont() const
1040 {
1041 // logic is the same as in GetBackgroundColour()
1042 if ( !m_font.Ok() )
1043 {
1044 wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") );
1045
1046 wxFont font = GetDefaultAttributes().font;
1047 if ( !font.Ok() )
1048 font = GetClassDefaultAttributes().font;
1049
1050 return font;
1051 }
1052 else
1053 return m_font;
1054 }
1055
1056 bool wxWindowBase::SetFont(const wxFont& font)
1057 {
1058 if ( font == m_font )
1059 {
1060 // no change
1061 return false;
1062 }
1063
1064 m_font = font;
1065 m_hasFont = font.Ok();
1066 m_inheritFont = m_hasFont;
1067
1068 InvalidateBestSize();
1069
1070 return true;
1071 }
1072
1073 #if wxUSE_PALETTE
1074
1075 void wxWindowBase::SetPalette(const wxPalette& pal)
1076 {
1077 m_hasCustomPalette = true;
1078 m_palette = pal;
1079
1080 // VZ: can anyone explain me what do we do here?
1081 wxWindowDC d((wxWindow *) this);
1082 d.SetPalette(pal);
1083 }
1084
1085 wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
1086 {
1087 wxWindow *win = (wxWindow *)this;
1088 while ( win && !win->HasCustomPalette() )
1089 {
1090 win = win->GetParent();
1091 }
1092
1093 return win;
1094 }
1095
1096 #endif // wxUSE_PALETTE
1097
1098 #if wxUSE_CARET
1099 void wxWindowBase::SetCaret(wxCaret *caret)
1100 {
1101 if ( m_caret )
1102 {
1103 delete m_caret;
1104 }
1105
1106 m_caret = caret;
1107
1108 if ( m_caret )
1109 {
1110 wxASSERT_MSG( m_caret->GetWindow() == this,
1111 wxT("caret should be created associated to this window") );
1112 }
1113 }
1114 #endif // wxUSE_CARET
1115
1116 #if wxUSE_VALIDATORS
1117 // ----------------------------------------------------------------------------
1118 // validators
1119 // ----------------------------------------------------------------------------
1120
1121 void wxWindowBase::SetValidator(const wxValidator& validator)
1122 {
1123 if ( m_windowValidator )
1124 delete m_windowValidator;
1125
1126 m_windowValidator = (wxValidator *)validator.Clone();
1127
1128 if ( m_windowValidator )
1129 m_windowValidator->SetWindow(this);
1130 }
1131 #endif // wxUSE_VALIDATORS
1132
1133 // ----------------------------------------------------------------------------
1134 // update region stuff
1135 // ----------------------------------------------------------------------------
1136
1137 wxRect wxWindowBase::GetUpdateClientRect() const
1138 {
1139 wxRegion rgnUpdate = GetUpdateRegion();
1140 rgnUpdate.Intersect(GetClientRect());
1141 wxRect rectUpdate = rgnUpdate.GetBox();
1142 wxPoint ptOrigin = GetClientAreaOrigin();
1143 rectUpdate.x -= ptOrigin.x;
1144 rectUpdate.y -= ptOrigin.y;
1145
1146 return rectUpdate;
1147 }
1148
1149 bool wxWindowBase::IsExposed(int x, int y) const
1150 {
1151 return m_updateRegion.Contains(x, y) != wxOutRegion;
1152 }
1153
1154 bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
1155 {
1156 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
1157 }
1158
1159 void wxWindowBase::ClearBackground()
1160 {
1161 // wxGTK uses its own version, no need to add never used code
1162 #ifndef __WXGTK__
1163 wxClientDC dc((wxWindow *)this);
1164 wxBrush brush(GetBackgroundColour(), wxSOLID);
1165 dc.SetBackground(brush);
1166 dc.Clear();
1167 #endif // __WXGTK__
1168 }
1169
1170 // ----------------------------------------------------------------------------
1171 // find child window by id or name
1172 // ----------------------------------------------------------------------------
1173
1174 wxWindow *wxWindowBase::FindWindow(long id) const
1175 {
1176 if ( id == m_windowId )
1177 return (wxWindow *)this;
1178
1179 wxWindowBase *res = (wxWindow *)NULL;
1180 wxWindowList::compatibility_iterator node;
1181 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1182 {
1183 wxWindowBase *child = node->GetData();
1184 res = child->FindWindow( id );
1185 }
1186
1187 return (wxWindow *)res;
1188 }
1189
1190 wxWindow *wxWindowBase::FindWindow(const wxString& name) const
1191 {
1192 if ( name == m_windowName )
1193 return (wxWindow *)this;
1194
1195 wxWindowBase *res = (wxWindow *)NULL;
1196 wxWindowList::compatibility_iterator node;
1197 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1198 {
1199 wxWindow *child = node->GetData();
1200 res = child->FindWindow(name);
1201 }
1202
1203 return (wxWindow *)res;
1204 }
1205
1206
1207 // find any window by id or name or label: If parent is non-NULL, look through
1208 // children for a label or title matching the specified string. If NULL, look
1209 // through all top-level windows.
1210 //
1211 // to avoid duplicating code we reuse the same helper function but with
1212 // different comparators
1213
1214 typedef bool (*wxFindWindowCmp)(const wxWindow *win,
1215 const wxString& label, long id);
1216
1217 static
1218 bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
1219 long WXUNUSED(id))
1220 {
1221 return win->GetLabel() == label;
1222 }
1223
1224 static
1225 bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
1226 long WXUNUSED(id))
1227 {
1228 return win->GetName() == label;
1229 }
1230
1231 static
1232 bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
1233 long id)
1234 {
1235 return win->GetId() == id;
1236 }
1237
1238 // recursive helper for the FindWindowByXXX() functions
1239 static
1240 wxWindow *wxFindWindowRecursively(const wxWindow *parent,
1241 const wxString& label,
1242 long id,
1243 wxFindWindowCmp cmp)
1244 {
1245 if ( parent )
1246 {
1247 // see if this is the one we're looking for
1248 if ( (*cmp)(parent, label, id) )
1249 return (wxWindow *)parent;
1250
1251 // It wasn't, so check all its children
1252 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1253 node;
1254 node = node->GetNext() )
1255 {
1256 // recursively check each child
1257 wxWindow *win = (wxWindow *)node->GetData();
1258 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1259 if (retwin)
1260 return retwin;
1261 }
1262 }
1263
1264 // Not found
1265 return NULL;
1266 }
1267
1268 // helper for FindWindowByXXX()
1269 static
1270 wxWindow *wxFindWindowHelper(const wxWindow *parent,
1271 const wxString& label,
1272 long id,
1273 wxFindWindowCmp cmp)
1274 {
1275 if ( parent )
1276 {
1277 // just check parent and all its children
1278 return wxFindWindowRecursively(parent, label, id, cmp);
1279 }
1280
1281 // start at very top of wx's windows
1282 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1283 node;
1284 node = node->GetNext() )
1285 {
1286 // recursively check each window & its children
1287 wxWindow *win = node->GetData();
1288 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1289 if (retwin)
1290 return retwin;
1291 }
1292
1293 return NULL;
1294 }
1295
1296 /* static */
1297 wxWindow *
1298 wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
1299 {
1300 return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
1301 }
1302
1303 /* static */
1304 wxWindow *
1305 wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
1306 {
1307 wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
1308
1309 if ( !win )
1310 {
1311 // fall back to the label
1312 win = FindWindowByLabel(title, parent);
1313 }
1314
1315 return win;
1316 }
1317
1318 /* static */
1319 wxWindow *
1320 wxWindowBase::FindWindowById( long id, const wxWindow* parent )
1321 {
1322 return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds);
1323 }
1324
1325 // ----------------------------------------------------------------------------
1326 // dialog oriented functions
1327 // ----------------------------------------------------------------------------
1328
1329 void wxWindowBase::MakeModal(bool modal)
1330 {
1331 // Disable all other windows
1332 if ( IsTopLevel() )
1333 {
1334 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1335 while (node)
1336 {
1337 wxWindow *win = node->GetData();
1338 if (win != this)
1339 win->Enable(!modal);
1340
1341 node = node->GetNext();
1342 }
1343 }
1344 }
1345
1346 bool wxWindowBase::Validate()
1347 {
1348 #if wxUSE_VALIDATORS
1349 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1350
1351 wxWindowList::compatibility_iterator node;
1352 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1353 {
1354 wxWindowBase *child = node->GetData();
1355 wxValidator *validator = child->GetValidator();
1356 if ( validator && !validator->Validate((wxWindow *)this) )
1357 {
1358 return false;
1359 }
1360
1361 if ( recurse && !child->Validate() )
1362 {
1363 return false;
1364 }
1365 }
1366 #endif // wxUSE_VALIDATORS
1367
1368 return true;
1369 }
1370
1371 bool wxWindowBase::TransferDataToWindow()
1372 {
1373 #if wxUSE_VALIDATORS
1374 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1375
1376 wxWindowList::compatibility_iterator node;
1377 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1378 {
1379 wxWindowBase *child = node->GetData();
1380 wxValidator *validator = child->GetValidator();
1381 if ( validator && !validator->TransferToWindow() )
1382 {
1383 wxLogWarning(_("Could not transfer data to window"));
1384 #if wxUSE_LOG
1385 wxLog::FlushActive();
1386 #endif // wxUSE_LOG
1387
1388 return false;
1389 }
1390
1391 if ( recurse )
1392 {
1393 if ( !child->TransferDataToWindow() )
1394 {
1395 // warning already given
1396 return false;
1397 }
1398 }
1399 }
1400 #endif // wxUSE_VALIDATORS
1401
1402 return true;
1403 }
1404
1405 bool wxWindowBase::TransferDataFromWindow()
1406 {
1407 #if wxUSE_VALIDATORS
1408 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1409
1410 wxWindowList::compatibility_iterator node;
1411 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1412 {
1413 wxWindow *child = node->GetData();
1414 wxValidator *validator = child->GetValidator();
1415 if ( validator && !validator->TransferFromWindow() )
1416 {
1417 // nop warning here because the application is supposed to give
1418 // one itself - we don't know here what might have gone wrongly
1419
1420 return false;
1421 }
1422
1423 if ( recurse )
1424 {
1425 if ( !child->TransferDataFromWindow() )
1426 {
1427 // warning already given
1428 return false;
1429 }
1430 }
1431 }
1432 #endif // wxUSE_VALIDATORS
1433
1434 return true;
1435 }
1436
1437 void wxWindowBase::InitDialog()
1438 {
1439 wxInitDialogEvent event(GetId());
1440 event.SetEventObject( this );
1441 GetEventHandler()->ProcessEvent(event);
1442 }
1443
1444 // ----------------------------------------------------------------------------
1445 // context-sensitive help support
1446 // ----------------------------------------------------------------------------
1447
1448 #if wxUSE_HELP
1449
1450 // associate this help text with this window
1451 void wxWindowBase::SetHelpText(const wxString& text)
1452 {
1453 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1454 if ( helpProvider )
1455 {
1456 helpProvider->AddHelp(this, text);
1457 }
1458 }
1459
1460 // associate this help text with all windows with the same id as this
1461 // one
1462 void wxWindowBase::SetHelpTextForId(const wxString& text)
1463 {
1464 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1465 if ( helpProvider )
1466 {
1467 helpProvider->AddHelp(GetId(), text);
1468 }
1469 }
1470
1471 // get the help string associated with this window (may be empty)
1472 // default implementation forwards calls to the help provider
1473 wxString
1474 wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt),
1475 wxHelpEvent::Origin WXUNUSED(origin)) const
1476 {
1477 wxString text;
1478 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1479 if ( helpProvider )
1480 {
1481 text = helpProvider->GetHelp(this);
1482 }
1483
1484 return text;
1485 }
1486
1487 // show help for this window
1488 void wxWindowBase::OnHelp(wxHelpEvent& event)
1489 {
1490 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1491 if ( helpProvider )
1492 {
1493 if ( helpProvider->ShowHelpAtPoint(this, event.GetPosition(), event.GetOrigin()) )
1494 {
1495 // skip the event.Skip() below
1496 return;
1497 }
1498 }
1499
1500 event.Skip();
1501 }
1502
1503 #endif // wxUSE_HELP
1504
1505 // ----------------------------------------------------------------------------
1506 // tooltipsroot.Replace("\\", "/");
1507 // ----------------------------------------------------------------------------
1508
1509 #if wxUSE_TOOLTIPS
1510
1511 void wxWindowBase::SetToolTip( const wxString &tip )
1512 {
1513 // don't create the new tooltip if we already have one
1514 if ( m_tooltip )
1515 {
1516 m_tooltip->SetTip( tip );
1517 }
1518 else
1519 {
1520 SetToolTip( new wxToolTip( tip ) );
1521 }
1522
1523 // setting empty tooltip text does not remove the tooltip any more - use
1524 // SetToolTip((wxToolTip *)NULL) for this
1525 }
1526
1527 void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1528 {
1529 if ( m_tooltip != tooltip )
1530 {
1531 if ( m_tooltip )
1532 delete m_tooltip;
1533
1534 m_tooltip = tooltip;
1535 }
1536 }
1537
1538 #endif // wxUSE_TOOLTIPS
1539
1540 // ----------------------------------------------------------------------------
1541 // constraints and sizers
1542 // ----------------------------------------------------------------------------
1543
1544 #if wxUSE_CONSTRAINTS
1545
1546 void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1547 {
1548 if ( m_constraints )
1549 {
1550 UnsetConstraints(m_constraints);
1551 delete m_constraints;
1552 }
1553 m_constraints = constraints;
1554 if ( m_constraints )
1555 {
1556 // Make sure other windows know they're part of a 'meaningful relationship'
1557 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1558 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1559 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1560 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1561 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1562 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1563 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1564 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1565 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1566 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1567 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1568 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1569 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1570 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1571 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1572 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
1573 }
1574 }
1575
1576 // This removes any dangling pointers to this window in other windows'
1577 // constraintsInvolvedIn lists.
1578 void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
1579 {
1580 if ( c )
1581 {
1582 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1583 c->left.GetOtherWindow()->RemoveConstraintReference(this);
1584 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1585 c->top.GetOtherWindow()->RemoveConstraintReference(this);
1586 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
1587 c->right.GetOtherWindow()->RemoveConstraintReference(this);
1588 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
1589 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
1590 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1591 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1592 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1593 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1594 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1595 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1596 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1597 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1598 }
1599 }
1600
1601 // Back-pointer to other windows we're involved with, so if we delete this
1602 // window, we must delete any constraints we're involved with.
1603 void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1604 {
1605 if ( !m_constraintsInvolvedIn )
1606 m_constraintsInvolvedIn = new wxWindowList;
1607 if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) )
1608 m_constraintsInvolvedIn->Append((wxWindow *)otherWin);
1609 }
1610
1611 // REMOVE back-pointer to other windows we're involved with.
1612 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1613 {
1614 if ( m_constraintsInvolvedIn )
1615 m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin);
1616 }
1617
1618 // Reset any constraints that mention this window
1619 void wxWindowBase::DeleteRelatedConstraints()
1620 {
1621 if ( m_constraintsInvolvedIn )
1622 {
1623 wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst();
1624 while (node)
1625 {
1626 wxWindow *win = node->GetData();
1627 wxLayoutConstraints *constr = win->GetConstraints();
1628
1629 // Reset any constraints involving this window
1630 if ( constr )
1631 {
1632 constr->left.ResetIfWin(this);
1633 constr->top.ResetIfWin(this);
1634 constr->right.ResetIfWin(this);
1635 constr->bottom.ResetIfWin(this);
1636 constr->width.ResetIfWin(this);
1637 constr->height.ResetIfWin(this);
1638 constr->centreX.ResetIfWin(this);
1639 constr->centreY.ResetIfWin(this);
1640 }
1641
1642 wxWindowList::compatibility_iterator next = node->GetNext();
1643 m_constraintsInvolvedIn->Erase(node);
1644 node = next;
1645 }
1646
1647 delete m_constraintsInvolvedIn;
1648 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1649 }
1650 }
1651
1652 #endif // wxUSE_CONSTRAINTS
1653
1654 void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
1655 {
1656 if ( sizer == m_windowSizer)
1657 return;
1658
1659 if ( m_windowSizer )
1660 {
1661 m_windowSizer->SetContainingWindow(NULL);
1662
1663 if ( deleteOld )
1664 delete m_windowSizer;
1665 }
1666
1667 m_windowSizer = sizer;
1668 if ( m_windowSizer )
1669 {
1670 m_windowSizer->SetContainingWindow((wxWindow *)this);
1671 }
1672
1673 SetAutoLayout(m_windowSizer != NULL);
1674 }
1675
1676 void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
1677 {
1678 SetSizer( sizer, deleteOld );
1679 sizer->SetSizeHints( (wxWindow*) this );
1680 }
1681
1682
1683 void wxWindowBase::SetContainingSizer(wxSizer* sizer)
1684 {
1685 // adding a window to a sizer twice is going to result in fatal and
1686 // hard to debug problems later because when deleting the second
1687 // associated wxSizerItem we're going to dereference a dangling
1688 // pointer; so try to detect this as early as possible
1689 wxASSERT_MSG( !sizer || m_containingSizer != sizer,
1690 _T("Adding a window to the same sizer twice?") );
1691
1692 m_containingSizer = sizer;
1693 }
1694
1695 #if wxUSE_CONSTRAINTS
1696
1697 void wxWindowBase::SatisfyConstraints()
1698 {
1699 wxLayoutConstraints *constr = GetConstraints();
1700 bool wasOk = constr && constr->AreSatisfied();
1701
1702 ResetConstraints(); // Mark all constraints as unevaluated
1703
1704 int noChanges = 1;
1705
1706 // if we're a top level panel (i.e. our parent is frame/dialog), our
1707 // own constraints will never be satisfied any more unless we do it
1708 // here
1709 if ( wasOk )
1710 {
1711 while ( noChanges > 0 )
1712 {
1713 LayoutPhase1(&noChanges);
1714 }
1715 }
1716
1717 LayoutPhase2(&noChanges);
1718 }
1719
1720 #endif // wxUSE_CONSTRAINTS
1721
1722 bool wxWindowBase::Layout()
1723 {
1724 // If there is a sizer, use it instead of the constraints
1725 if ( GetSizer() )
1726 {
1727 int w = 0, h = 0;
1728 GetVirtualSize(&w, &h);
1729 GetSizer()->SetDimension( 0, 0, w, h );
1730 }
1731 #if wxUSE_CONSTRAINTS
1732 else
1733 {
1734 SatisfyConstraints(); // Find the right constraints values
1735 SetConstraintSizes(); // Recursively set the real window sizes
1736 }
1737 #endif
1738
1739 return true;
1740 }
1741
1742 #if wxUSE_CONSTRAINTS
1743
1744 // first phase of the constraints evaluation: set our own constraints
1745 bool wxWindowBase::LayoutPhase1(int *noChanges)
1746 {
1747 wxLayoutConstraints *constr = GetConstraints();
1748
1749 return !constr || constr->SatisfyConstraints(this, noChanges);
1750 }
1751
1752 // second phase: set the constraints for our children
1753 bool wxWindowBase::LayoutPhase2(int *noChanges)
1754 {
1755 *noChanges = 0;
1756
1757 // Layout children
1758 DoPhase(1);
1759
1760 // Layout grand children
1761 DoPhase(2);
1762
1763 return true;
1764 }
1765
1766 // Do a phase of evaluating child constraints
1767 bool wxWindowBase::DoPhase(int phase)
1768 {
1769 // the list containing the children for which the constraints are already
1770 // set correctly
1771 wxWindowList succeeded;
1772
1773 // the max number of iterations we loop before concluding that we can't set
1774 // the constraints
1775 static const int maxIterations = 500;
1776
1777 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
1778 {
1779 int noChanges = 0;
1780
1781 // loop over all children setting their constraints
1782 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1783 node;
1784 node = node->GetNext() )
1785 {
1786 wxWindow *child = node->GetData();
1787 if ( child->IsTopLevel() )
1788 {
1789 // top level children are not inside our client area
1790 continue;
1791 }
1792
1793 if ( !child->GetConstraints() || succeeded.Find(child) )
1794 {
1795 // this one is either already ok or nothing we can do about it
1796 continue;
1797 }
1798
1799 int tempNoChanges = 0;
1800 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
1801 : child->LayoutPhase2(&tempNoChanges);
1802 noChanges += tempNoChanges;
1803
1804 if ( success )
1805 {
1806 succeeded.Append(child);
1807 }
1808 }
1809
1810 if ( !noChanges )
1811 {
1812 // constraints are set
1813 break;
1814 }
1815 }
1816
1817 return true;
1818 }
1819
1820 void wxWindowBase::ResetConstraints()
1821 {
1822 wxLayoutConstraints *constr = GetConstraints();
1823 if ( constr )
1824 {
1825 constr->left.SetDone(false);
1826 constr->top.SetDone(false);
1827 constr->right.SetDone(false);
1828 constr->bottom.SetDone(false);
1829 constr->width.SetDone(false);
1830 constr->height.SetDone(false);
1831 constr->centreX.SetDone(false);
1832 constr->centreY.SetDone(false);
1833 }
1834
1835 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1836 while (node)
1837 {
1838 wxWindow *win = node->GetData();
1839 if ( !win->IsTopLevel() )
1840 win->ResetConstraints();
1841 node = node->GetNext();
1842 }
1843 }
1844
1845 // Need to distinguish between setting the 'fake' size for windows and sizers,
1846 // and setting the real values.
1847 void wxWindowBase::SetConstraintSizes(bool recurse)
1848 {
1849 wxLayoutConstraints *constr = GetConstraints();
1850 if ( constr && constr->AreSatisfied() )
1851 {
1852 int x = constr->left.GetValue();
1853 int y = constr->top.GetValue();
1854 int w = constr->width.GetValue();
1855 int h = constr->height.GetValue();
1856
1857 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1858 (constr->height.GetRelationship() != wxAsIs) )
1859 {
1860 SetSize(x, y, w, h);
1861 }
1862 else
1863 {
1864 // If we don't want to resize this window, just move it...
1865 Move(x, y);
1866 }
1867 }
1868 else if ( constr )
1869 {
1870 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1871 GetClassInfo()->GetClassName(),
1872 GetName().c_str());
1873 }
1874
1875 if ( recurse )
1876 {
1877 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1878 while (node)
1879 {
1880 wxWindow *win = node->GetData();
1881 if ( !win->IsTopLevel() && win->GetConstraints() )
1882 win->SetConstraintSizes();
1883 node = node->GetNext();
1884 }
1885 }
1886 }
1887
1888 // Only set the size/position of the constraint (if any)
1889 void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1890 {
1891 wxLayoutConstraints *constr = GetConstraints();
1892 if ( constr )
1893 {
1894 if ( x != wxDefaultCoord )
1895 {
1896 constr->left.SetValue(x);
1897 constr->left.SetDone(true);
1898 }
1899 if ( y != wxDefaultCoord )
1900 {
1901 constr->top.SetValue(y);
1902 constr->top.SetDone(true);
1903 }
1904 if ( w != wxDefaultCoord )
1905 {
1906 constr->width.SetValue(w);
1907 constr->width.SetDone(true);
1908 }
1909 if ( h != wxDefaultCoord )
1910 {
1911 constr->height.SetValue(h);
1912 constr->height.SetDone(true);
1913 }
1914 }
1915 }
1916
1917 void wxWindowBase::MoveConstraint(int x, int y)
1918 {
1919 wxLayoutConstraints *constr = GetConstraints();
1920 if ( constr )
1921 {
1922 if ( x != wxDefaultCoord )
1923 {
1924 constr->left.SetValue(x);
1925 constr->left.SetDone(true);
1926 }
1927 if ( y != wxDefaultCoord )
1928 {
1929 constr->top.SetValue(y);
1930 constr->top.SetDone(true);
1931 }
1932 }
1933 }
1934
1935 void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1936 {
1937 wxLayoutConstraints *constr = GetConstraints();
1938 if ( constr )
1939 {
1940 *w = constr->width.GetValue();
1941 *h = constr->height.GetValue();
1942 }
1943 else
1944 GetSize(w, h);
1945 }
1946
1947 void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1948 {
1949 wxLayoutConstraints *constr = GetConstraints();
1950 if ( constr )
1951 {
1952 *w = constr->width.GetValue();
1953 *h = constr->height.GetValue();
1954 }
1955 else
1956 GetClientSize(w, h);
1957 }
1958
1959 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1960 {
1961 wxLayoutConstraints *constr = GetConstraints();
1962 if ( constr )
1963 {
1964 *x = constr->left.GetValue();
1965 *y = constr->top.GetValue();
1966 }
1967 else
1968 GetPosition(x, y);
1969 }
1970
1971 #endif // wxUSE_CONSTRAINTS
1972
1973 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
1974 {
1975 // don't do it for the dialogs/frames - they float independently of their
1976 // parent
1977 if ( !IsTopLevel() )
1978 {
1979 wxWindow *parent = GetParent();
1980 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
1981 {
1982 wxPoint pt(parent->GetClientAreaOrigin());
1983 x += pt.x;
1984 y += pt.y;
1985 }
1986 }
1987 }
1988
1989 // ----------------------------------------------------------------------------
1990 // do Update UI processing for child controls
1991 // ----------------------------------------------------------------------------
1992
1993 void wxWindowBase::UpdateWindowUI(long flags)
1994 {
1995 wxUpdateUIEvent event(GetId());
1996 event.SetEventObject(this);
1997
1998 if ( GetEventHandler()->ProcessEvent(event) )
1999 {
2000 DoUpdateWindowUI(event);
2001 }
2002
2003 if (flags & wxUPDATE_UI_RECURSE)
2004 {
2005 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2006 while (node)
2007 {
2008 wxWindow* child = (wxWindow*) node->GetData();
2009 child->UpdateWindowUI(flags);
2010 node = node->GetNext();
2011 }
2012 }
2013 }
2014
2015 // do the window-specific processing after processing the update event
2016 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
2017 {
2018 if ( event.GetSetEnabled() )
2019 Enable(event.GetEnabled());
2020
2021 if ( event.GetSetShown() )
2022 Show(event.GetShown());
2023 }
2024
2025 #if 0
2026 // call internal idle recursively
2027 // may be obsolete (wait until OnIdle scheme stabilises)
2028 void wxWindowBase::ProcessInternalIdle()
2029 {
2030 OnInternalIdle();
2031
2032 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2033 while (node)
2034 {
2035 wxWindow *child = node->GetData();
2036 child->ProcessInternalIdle();
2037 node = node->GetNext();
2038 }
2039 }
2040 #endif
2041
2042 // ----------------------------------------------------------------------------
2043 // dialog units translations
2044 // ----------------------------------------------------------------------------
2045
2046 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
2047 {
2048 int charWidth = GetCharWidth();
2049 int charHeight = GetCharHeight();
2050 wxPoint pt2 = wxDefaultPosition;
2051 if (pt.x != wxDefaultCoord)
2052 pt2.x = (int) ((pt.x * 4) / charWidth);
2053 if (pt.y != wxDefaultCoord)
2054 pt2.y = (int) ((pt.y * 8) / charHeight);
2055
2056 return pt2;
2057 }
2058
2059 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
2060 {
2061 int charWidth = GetCharWidth();
2062 int charHeight = GetCharHeight();
2063 wxPoint pt2 = wxDefaultPosition;
2064 if (pt.x != wxDefaultCoord)
2065 pt2.x = (int) ((pt.x * charWidth) / 4);
2066 if (pt.y != wxDefaultCoord)
2067 pt2.y = (int) ((pt.y * charHeight) / 8);
2068
2069 return pt2;
2070 }
2071
2072 // ----------------------------------------------------------------------------
2073 // event handlers
2074 // ----------------------------------------------------------------------------
2075
2076 // propagate the colour change event to the subwindows
2077 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
2078 {
2079 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2080 while ( node )
2081 {
2082 // Only propagate to non-top-level windows
2083 wxWindow *win = node->GetData();
2084 if ( !win->IsTopLevel() )
2085 {
2086 wxSysColourChangedEvent event2;
2087 event.SetEventObject(win);
2088 win->GetEventHandler()->ProcessEvent(event2);
2089 }
2090
2091 node = node->GetNext();
2092 }
2093
2094 Refresh();
2095 }
2096
2097 // the default action is to populate dialog with data when it's created,
2098 // and nudge the UI into displaying itself correctly in case
2099 // we've turned the wxUpdateUIEvents frequency down low.
2100 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2101 {
2102 TransferDataToWindow();
2103
2104 // Update the UI at this point
2105 UpdateWindowUI(wxUPDATE_UI_RECURSE);
2106 }
2107
2108 // methods for drawing the sizers in a visible way
2109 #ifdef __WXDEBUG__
2110
2111 static void DrawSizers(wxWindowBase *win);
2112
2113 static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false)
2114 {
2115 wxClientDC dc((wxWindow *)win);
2116 dc.SetPen(*wxRED_PEN);
2117 dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH);
2118 dc.DrawRectangle(rect.Deflate(1, 1));
2119 }
2120
2121 static void DrawSizer(wxWindowBase *win, wxSizer *sizer)
2122 {
2123 const wxSizerItemList& items = sizer->GetChildren();
2124 for ( wxSizerItemList::const_iterator i = items.begin(),
2125 end = items.end();
2126 i != end;
2127 ++i )
2128 {
2129 wxSizerItem *item = *i;
2130 if ( item->IsSizer() )
2131 {
2132 DrawBorder(win, item->GetRect().Deflate(2));
2133 DrawSizer(win, item->GetSizer());
2134 }
2135 else if ( item->IsSpacer() )
2136 {
2137 DrawBorder(win, item->GetRect().Deflate(2), true);
2138 }
2139 else if ( item->IsWindow() )
2140 {
2141 DrawSizers(item->GetWindow());
2142 }
2143 }
2144 }
2145
2146 static void DrawSizers(wxWindowBase *win)
2147 {
2148 wxSizer *sizer = win->GetSizer();
2149 if ( sizer )
2150 {
2151 DrawBorder(win, win->GetClientSize());
2152 DrawSizer(win, sizer);
2153 }
2154 else // no sizer, still recurse into the children
2155 {
2156 const wxWindowList& children = win->GetChildren();
2157 for ( wxWindowList::const_iterator i = children.begin(),
2158 end = children.end();
2159 i != end;
2160 ++i )
2161 {
2162 DrawSizers(*i);
2163 }
2164 }
2165 }
2166
2167 #endif // __WXDEBUG__
2168
2169 // process special middle clicks
2170 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2171 {
2172 if ( event.ControlDown() && event.AltDown() )
2173 {
2174 #ifdef __WXDEBUG__
2175 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2176 if ( event.ShiftDown() )
2177 {
2178 DrawSizers(this);
2179 return;
2180 }
2181 #endif // __WXDEBUG__
2182
2183 #if wxUSE_MSGDLG
2184 // don't translate these strings, they're for diagnostics purposes only
2185 wxString msg;
2186 msg.Printf(_T("wxWidgets Library (%s port)\n")
2187 _T("Version %d.%d.%d%s%s, compiled at %s %s%s\n")
2188 _T("Copyright (c) 1995-2006 wxWidgets team"),
2189 wxPlatformInfo().GetPortIdName().c_str(),
2190 wxMAJOR_VERSION,
2191 wxMINOR_VERSION,
2192 wxRELEASE_NUMBER,
2193 #if wxUSE_UNICODE
2194 L" (Unicode)",
2195 #else
2196 wxEmptyString,
2197 #endif
2198 #ifdef __WXDEBUG__
2199 _T(" Debug build"),
2200 #else
2201 wxEmptyString,
2202 #endif
2203 __TDATE__,
2204 __TTIME__,
2205 #ifdef __WXGTK__
2206 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()
2207 #else
2208 wxEmptyString
2209 #endif
2210 );
2211
2212 wxMessageBox(msg, _T("wxWidgets information"),
2213 wxICON_INFORMATION | wxOK,
2214 (wxWindow *)this);
2215 }
2216 else
2217 #endif // wxUSE_MSGDLG
2218 {
2219 event.Skip();
2220 }
2221 }
2222
2223 // ----------------------------------------------------------------------------
2224 // accessibility
2225 // ----------------------------------------------------------------------------
2226
2227 #if wxUSE_ACCESSIBILITY
2228 void wxWindowBase::SetAccessible(wxAccessible* accessible)
2229 {
2230 if (m_accessible && (accessible != m_accessible))
2231 delete m_accessible;
2232 m_accessible = accessible;
2233 if (m_accessible)
2234 m_accessible->SetWindow((wxWindow*) this);
2235 }
2236
2237 // Returns the accessible object, creating if necessary.
2238 wxAccessible* wxWindowBase::GetOrCreateAccessible()
2239 {
2240 if (!m_accessible)
2241 m_accessible = CreateAccessible();
2242 return m_accessible;
2243 }
2244
2245 // Override to create a specific accessible object.
2246 wxAccessible* wxWindowBase::CreateAccessible()
2247 {
2248 return new wxWindowAccessible((wxWindow*) this);
2249 }
2250
2251 #endif
2252
2253 // ----------------------------------------------------------------------------
2254 // list classes implementation
2255 // ----------------------------------------------------------------------------
2256
2257 #if wxUSE_STL
2258
2259 #include "wx/listimpl.cpp"
2260 WX_DEFINE_LIST(wxWindowList)
2261
2262 #else
2263
2264 void wxWindowListNode::DeleteData()
2265 {
2266 delete (wxWindow *)GetData();
2267 }
2268
2269 #endif
2270
2271 // ----------------------------------------------------------------------------
2272 // borders
2273 // ----------------------------------------------------------------------------
2274
2275 wxBorder wxWindowBase::GetBorder(long flags) const
2276 {
2277 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
2278 if ( border == wxBORDER_DEFAULT )
2279 {
2280 border = GetDefaultBorder();
2281 }
2282
2283 return border;
2284 }
2285
2286 wxBorder wxWindowBase::GetDefaultBorder() const
2287 {
2288 return wxBORDER_NONE;
2289 }
2290
2291 // ----------------------------------------------------------------------------
2292 // hit testing
2293 // ----------------------------------------------------------------------------
2294
2295 wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2296 {
2297 // here we just check if the point is inside the window or not
2298
2299 // check the top and left border first
2300 bool outside = x < 0 || y < 0;
2301 if ( !outside )
2302 {
2303 // check the right and bottom borders too
2304 wxSize size = GetSize();
2305 outside = x >= size.x || y >= size.y;
2306 }
2307
2308 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2309 }
2310
2311 // ----------------------------------------------------------------------------
2312 // mouse capture
2313 // ----------------------------------------------------------------------------
2314
2315 struct WXDLLEXPORT wxWindowNext
2316 {
2317 wxWindow *win;
2318 wxWindowNext *next;
2319 } *wxWindowBase::ms_winCaptureNext = NULL;
2320 wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL;
2321 bool wxWindowBase::ms_winCaptureChanging = false;
2322
2323 void wxWindowBase::CaptureMouse()
2324 {
2325 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2326
2327 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive CaptureMouse call?") );
2328
2329 ms_winCaptureChanging = true;
2330
2331 wxWindow *winOld = GetCapture();
2332 if ( winOld )
2333 {
2334 ((wxWindowBase*) winOld)->DoReleaseMouse();
2335
2336 // save it on stack
2337 wxWindowNext *item = new wxWindowNext;
2338 item->win = winOld;
2339 item->next = ms_winCaptureNext;
2340 ms_winCaptureNext = item;
2341 }
2342 //else: no mouse capture to save
2343
2344 DoCaptureMouse();
2345 ms_winCaptureCurrent = (wxWindow*)this;
2346
2347 ms_winCaptureChanging = false;
2348 }
2349
2350 void wxWindowBase::ReleaseMouse()
2351 {
2352 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2353
2354 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive ReleaseMouse call?") );
2355
2356 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2357
2358 ms_winCaptureChanging = true;
2359
2360 DoReleaseMouse();
2361 ms_winCaptureCurrent = NULL;
2362
2363 if ( ms_winCaptureNext )
2364 {
2365 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
2366 ms_winCaptureCurrent = ms_winCaptureNext->win;
2367
2368 wxWindowNext *item = ms_winCaptureNext;
2369 ms_winCaptureNext = item->next;
2370 delete item;
2371 }
2372 //else: stack is empty, no previous capture
2373
2374 ms_winCaptureChanging = false;
2375
2376 wxLogTrace(_T("mousecapture"),
2377 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
2378 wx_static_cast(void*, GetCapture()));
2379 }
2380
2381 static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
2382 {
2383 wxMouseCaptureLostEvent event(win->GetId());
2384 event.SetEventObject(win);
2385 if ( !win->GetEventHandler()->ProcessEvent(event) )
2386 {
2387 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2388 }
2389 }
2390
2391 /* static */
2392 void wxWindowBase::NotifyCaptureLost()
2393 {
2394 // don't do anything if capture lost was expected, i.e. resulted from
2395 // a wx call to ReleaseMouse or CaptureMouse:
2396 if ( ms_winCaptureChanging )
2397 return;
2398
2399 // if the capture was lost unexpectedly, notify every window that has
2400 // capture (on stack or current) about it and clear the stack:
2401
2402 if ( ms_winCaptureCurrent )
2403 {
2404 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent);
2405 ms_winCaptureCurrent = NULL;
2406 }
2407
2408 while ( ms_winCaptureNext )
2409 {
2410 wxWindowNext *item = ms_winCaptureNext;
2411 ms_winCaptureNext = item->next;
2412
2413 DoNotifyWindowAboutCaptureLost(item->win);
2414
2415 delete item;
2416 }
2417 }
2418
2419 #if wxUSE_HOTKEY
2420
2421 bool
2422 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2423 int WXUNUSED(modifiers),
2424 int WXUNUSED(keycode))
2425 {
2426 // not implemented
2427 return false;
2428 }
2429
2430 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
2431 {
2432 // not implemented
2433 return false;
2434 }
2435
2436 #endif // wxUSE_HOTKEY
2437
2438 void wxWindowBase::SendDestroyEvent()
2439 {
2440 wxWindowDestroyEvent event;
2441 event.SetEventObject(this);
2442 event.SetId(GetId());
2443 GetEventHandler()->ProcessEvent(event);
2444 }
2445
2446 // ----------------------------------------------------------------------------
2447 // event processing
2448 // ----------------------------------------------------------------------------
2449
2450 bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
2451 {
2452 #if wxUSE_VALIDATORS
2453 // Can only use the validator of the window which
2454 // is receiving the event
2455 if ( event.GetEventObject() == this )
2456 {
2457 wxValidator *validator = GetValidator();
2458 if ( validator && validator->ProcessEvent(event) )
2459 {
2460 return true;
2461 }
2462 }
2463 #endif // wxUSE_VALIDATORS
2464
2465 return false;
2466 }
2467
2468 bool wxWindowBase::TryParent(wxEvent& event)
2469 {
2470 // carry on up the parent-child hierarchy if the propagation count hasn't
2471 // reached zero yet
2472 if ( event.ShouldPropagate() )
2473 {
2474 // honour the requests to stop propagation at this window: this is
2475 // used by the dialogs, for example, to prevent processing the events
2476 // from the dialog controls in the parent frame which rarely, if ever,
2477 // makes sense
2478 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2479 {
2480 wxWindow *parent = GetParent();
2481 if ( parent && !parent->IsBeingDeleted() )
2482 {
2483 wxPropagateOnce propagateOnce(event);
2484
2485 return parent->GetEventHandler()->ProcessEvent(event);
2486 }
2487 }
2488 }
2489
2490 return wxEvtHandler::TryParent(event);
2491 }
2492
2493 // ----------------------------------------------------------------------------
2494 // keyboard navigation
2495 // ----------------------------------------------------------------------------
2496
2497 // Navigates in the specified direction.
2498 bool wxWindowBase::Navigate(int flags)
2499 {
2500 wxNavigationKeyEvent eventNav;
2501 eventNav.SetFlags(flags);
2502 eventNav.SetEventObject(this);
2503 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
2504 {
2505 return true;
2506 }
2507 return false;
2508 }
2509
2510 void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
2511 {
2512 // check that we're not a top level window
2513 wxCHECK_RET( GetParent(),
2514 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2515
2516 // detect the special case when we have nothing to do anyhow and when the
2517 // code below wouldn't work
2518 if ( win == this )
2519 return;
2520
2521 // find the target window in the siblings list
2522 wxWindowList& siblings = GetParent()->GetChildren();
2523 wxWindowList::compatibility_iterator i = siblings.Find(win);
2524 wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2525
2526 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2527 // can't just move the node around
2528 wxWindow *self = (wxWindow *)this;
2529 siblings.DeleteObject(self);
2530 if ( move == MoveAfter )
2531 {
2532 i = i->GetNext();
2533 }
2534
2535 if ( i )
2536 {
2537 siblings.Insert(i, self);
2538 }
2539 else // MoveAfter and win was the last sibling
2540 {
2541 siblings.Append(self);
2542 }
2543 }
2544
2545 // ----------------------------------------------------------------------------
2546 // focus handling
2547 // ----------------------------------------------------------------------------
2548
2549 /*static*/ wxWindow* wxWindowBase::FindFocus()
2550 {
2551 wxWindowBase *win = DoFindFocus();
2552 return win ? win->GetMainWindowOfCompositeControl() : NULL;
2553 }
2554
2555 // ----------------------------------------------------------------------------
2556 // global functions
2557 // ----------------------------------------------------------------------------
2558
2559 wxWindow* wxGetTopLevelParent(wxWindow *win)
2560 {
2561 while ( win && !win->IsTopLevel() )
2562 win = win->GetParent();
2563
2564 return win;
2565 }
2566
2567 #if wxUSE_ACCESSIBILITY
2568 // ----------------------------------------------------------------------------
2569 // accessible object for windows
2570 // ----------------------------------------------------------------------------
2571
2572 // Can return either a child object, or an integer
2573 // representing the child element, starting from 1.
2574 wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
2575 {
2576 wxASSERT( GetWindow() != NULL );
2577 if (!GetWindow())
2578 return wxACC_FAIL;
2579
2580 return wxACC_NOT_IMPLEMENTED;
2581 }
2582
2583 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2584 wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2585 {
2586 wxASSERT( GetWindow() != NULL );
2587 if (!GetWindow())
2588 return wxACC_FAIL;
2589
2590 wxWindow* win = NULL;
2591 if (elementId == 0)
2592 {
2593 win = GetWindow();
2594 }
2595 else
2596 {
2597 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2598 {
2599 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
2600 }
2601 else
2602 return wxACC_FAIL;
2603 }
2604 if (win)
2605 {
2606 rect = win->GetRect();
2607 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2608 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2609 return wxACC_OK;
2610 }
2611
2612 return wxACC_NOT_IMPLEMENTED;
2613 }
2614
2615 // Navigates from fromId to toId/toObject.
2616 wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
2617 int* WXUNUSED(toId), wxAccessible** toObject)
2618 {
2619 wxASSERT( GetWindow() != NULL );
2620 if (!GetWindow())
2621 return wxACC_FAIL;
2622
2623 switch (navDir)
2624 {
2625 case wxNAVDIR_FIRSTCHILD:
2626 {
2627 if (GetWindow()->GetChildren().GetCount() == 0)
2628 return wxACC_FALSE;
2629 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2630 *toObject = childWindow->GetOrCreateAccessible();
2631
2632 return wxACC_OK;
2633 }
2634 case wxNAVDIR_LASTCHILD:
2635 {
2636 if (GetWindow()->GetChildren().GetCount() == 0)
2637 return wxACC_FALSE;
2638 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2639 *toObject = childWindow->GetOrCreateAccessible();
2640
2641 return wxACC_OK;
2642 }
2643 case wxNAVDIR_RIGHT:
2644 case wxNAVDIR_DOWN:
2645 case wxNAVDIR_NEXT:
2646 {
2647 wxWindowList::compatibility_iterator node =
2648 wxWindowList::compatibility_iterator();
2649 if (fromId == 0)
2650 {
2651 // Can't navigate to sibling of this window
2652 // if we're a top-level window.
2653 if (!GetWindow()->GetParent())
2654 return wxACC_NOT_IMPLEMENTED;
2655
2656 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2657 }
2658 else
2659 {
2660 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2661 node = GetWindow()->GetChildren().Item(fromId-1);
2662 }
2663
2664 if (node && node->GetNext())
2665 {
2666 wxWindow* nextWindow = node->GetNext()->GetData();
2667 *toObject = nextWindow->GetOrCreateAccessible();
2668 return wxACC_OK;
2669 }
2670 else
2671 return wxACC_FALSE;
2672 }
2673 case wxNAVDIR_LEFT:
2674 case wxNAVDIR_UP:
2675 case wxNAVDIR_PREVIOUS:
2676 {
2677 wxWindowList::compatibility_iterator node =
2678 wxWindowList::compatibility_iterator();
2679 if (fromId == 0)
2680 {
2681 // Can't navigate to sibling of this window
2682 // if we're a top-level window.
2683 if (!GetWindow()->GetParent())
2684 return wxACC_NOT_IMPLEMENTED;
2685
2686 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2687 }
2688 else
2689 {
2690 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2691 node = GetWindow()->GetChildren().Item(fromId-1);
2692 }
2693
2694 if (node && node->GetPrevious())
2695 {
2696 wxWindow* previousWindow = node->GetPrevious()->GetData();
2697 *toObject = previousWindow->GetOrCreateAccessible();
2698 return wxACC_OK;
2699 }
2700 else
2701 return wxACC_FALSE;
2702 }
2703 }
2704
2705 return wxACC_NOT_IMPLEMENTED;
2706 }
2707
2708 // Gets the name of the specified object.
2709 wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2710 {
2711 wxASSERT( GetWindow() != NULL );
2712 if (!GetWindow())
2713 return wxACC_FAIL;
2714
2715 wxString title;
2716
2717 // If a child, leave wxWidgets to call the function on the actual
2718 // child object.
2719 if (childId > 0)
2720 return wxACC_NOT_IMPLEMENTED;
2721
2722 // This will eventually be replaced by specialised
2723 // accessible classes, one for each kind of wxWidgets
2724 // control or window.
2725 #if wxUSE_BUTTON
2726 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2727 title = ((wxButton*) GetWindow())->GetLabel();
2728 else
2729 #endif
2730 title = GetWindow()->GetName();
2731
2732 if (!title.empty())
2733 {
2734 *name = title;
2735 return wxACC_OK;
2736 }
2737 else
2738 return wxACC_NOT_IMPLEMENTED;
2739 }
2740
2741 // Gets the number of children.
2742 wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2743 {
2744 wxASSERT( GetWindow() != NULL );
2745 if (!GetWindow())
2746 return wxACC_FAIL;
2747
2748 *childId = (int) GetWindow()->GetChildren().GetCount();
2749 return wxACC_OK;
2750 }
2751
2752 // Gets the specified child (starting from 1).
2753 // If *child is NULL and return value is wxACC_OK,
2754 // this means that the child is a simple element and
2755 // not an accessible object.
2756 wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2757 {
2758 wxASSERT( GetWindow() != NULL );
2759 if (!GetWindow())
2760 return wxACC_FAIL;
2761
2762 if (childId == 0)
2763 {
2764 *child = this;
2765 return wxACC_OK;
2766 }
2767
2768 if (childId > (int) GetWindow()->GetChildren().GetCount())
2769 return wxACC_FAIL;
2770
2771 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
2772 *child = childWindow->GetOrCreateAccessible();
2773 if (*child)
2774 return wxACC_OK;
2775 else
2776 return wxACC_FAIL;
2777 }
2778
2779 // Gets the parent, or NULL.
2780 wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2781 {
2782 wxASSERT( GetWindow() != NULL );
2783 if (!GetWindow())
2784 return wxACC_FAIL;
2785
2786 wxWindow* parentWindow = GetWindow()->GetParent();
2787 if (!parentWindow)
2788 {
2789 *parent = NULL;
2790 return wxACC_OK;
2791 }
2792 else
2793 {
2794 *parent = parentWindow->GetOrCreateAccessible();
2795 if (*parent)
2796 return wxACC_OK;
2797 else
2798 return wxACC_FAIL;
2799 }
2800 }
2801
2802 // Performs the default action. childId is 0 (the action for this object)
2803 // or > 0 (the action for a child).
2804 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2805 // window (e.g. an edit control).
2806 wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
2807 {
2808 wxASSERT( GetWindow() != NULL );
2809 if (!GetWindow())
2810 return wxACC_FAIL;
2811
2812 return wxACC_NOT_IMPLEMENTED;
2813 }
2814
2815 // Gets the default action for this object (0) or > 0 (the action for a child).
2816 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2817 // string if there is no action.
2818 // The retrieved string describes the action that is performed on an object,
2819 // not what the object does as a result. For example, a toolbar button that prints
2820 // a document has a default action of "Press" rather than "Prints the current document."
2821 wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
2822 {
2823 wxASSERT( GetWindow() != NULL );
2824 if (!GetWindow())
2825 return wxACC_FAIL;
2826
2827 return wxACC_NOT_IMPLEMENTED;
2828 }
2829
2830 // Returns the description for this object or a child.
2831 wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
2832 {
2833 wxASSERT( GetWindow() != NULL );
2834 if (!GetWindow())
2835 return wxACC_FAIL;
2836
2837 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
2838 if (!ht.empty())
2839 {
2840 *description = ht;
2841 return wxACC_OK;
2842 }
2843 return wxACC_NOT_IMPLEMENTED;
2844 }
2845
2846 // Returns help text for this object or a child, similar to tooltip text.
2847 wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
2848 {
2849 wxASSERT( GetWindow() != NULL );
2850 if (!GetWindow())
2851 return wxACC_FAIL;
2852
2853 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
2854 if (!ht.empty())
2855 {
2856 *helpText = ht;
2857 return wxACC_OK;
2858 }
2859 return wxACC_NOT_IMPLEMENTED;
2860 }
2861
2862 // Returns the keyboard shortcut for this object or child.
2863 // Return e.g. ALT+K
2864 wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
2865 {
2866 wxASSERT( GetWindow() != NULL );
2867 if (!GetWindow())
2868 return wxACC_FAIL;
2869
2870 return wxACC_NOT_IMPLEMENTED;
2871 }
2872
2873 // Returns a role constant.
2874 wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
2875 {
2876 wxASSERT( GetWindow() != NULL );
2877 if (!GetWindow())
2878 return wxACC_FAIL;
2879
2880 // If a child, leave wxWidgets to call the function on the actual
2881 // child object.
2882 if (childId > 0)
2883 return wxACC_NOT_IMPLEMENTED;
2884
2885 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2886 return wxACC_NOT_IMPLEMENTED;
2887 #if wxUSE_STATUSBAR
2888 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2889 return wxACC_NOT_IMPLEMENTED;
2890 #endif
2891 #if wxUSE_TOOLBAR
2892 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2893 return wxACC_NOT_IMPLEMENTED;
2894 #endif
2895
2896 //*role = wxROLE_SYSTEM_CLIENT;
2897 *role = wxROLE_SYSTEM_CLIENT;
2898 return wxACC_OK;
2899
2900 #if 0
2901 return wxACC_NOT_IMPLEMENTED;
2902 #endif
2903 }
2904
2905 // Returns a state constant.
2906 wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
2907 {
2908 wxASSERT( GetWindow() != NULL );
2909 if (!GetWindow())
2910 return wxACC_FAIL;
2911
2912 // If a child, leave wxWidgets to call the function on the actual
2913 // child object.
2914 if (childId > 0)
2915 return wxACC_NOT_IMPLEMENTED;
2916
2917 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2918 return wxACC_NOT_IMPLEMENTED;
2919
2920 #if wxUSE_STATUSBAR
2921 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2922 return wxACC_NOT_IMPLEMENTED;
2923 #endif
2924 #if wxUSE_TOOLBAR
2925 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2926 return wxACC_NOT_IMPLEMENTED;
2927 #endif
2928
2929 *state = 0;
2930 return wxACC_OK;
2931
2932 #if 0
2933 return wxACC_NOT_IMPLEMENTED;
2934 #endif
2935 }
2936
2937 // Returns a localized string representing the value for the object
2938 // or child.
2939 wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
2940 {
2941 wxASSERT( GetWindow() != NULL );
2942 if (!GetWindow())
2943 return wxACC_FAIL;
2944
2945 return wxACC_NOT_IMPLEMENTED;
2946 }
2947
2948 // Selects the object or child.
2949 wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
2950 {
2951 wxASSERT( GetWindow() != NULL );
2952 if (!GetWindow())
2953 return wxACC_FAIL;
2954
2955 return wxACC_NOT_IMPLEMENTED;
2956 }
2957
2958 // Gets the window with the keyboard focus.
2959 // If childId is 0 and child is NULL, no object in
2960 // this subhierarchy has the focus.
2961 // If this object has the focus, child should be 'this'.
2962 wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
2963 {
2964 wxASSERT( GetWindow() != NULL );
2965 if (!GetWindow())
2966 return wxACC_FAIL;
2967
2968 return wxACC_NOT_IMPLEMENTED;
2969 }
2970
2971 // Gets a variant representing the selected children
2972 // of this object.
2973 // Acceptable values:
2974 // - a null variant (IsNull() returns true)
2975 // - a list variant (GetType() == wxT("list")
2976 // - an integer representing the selected child element,
2977 // or 0 if this object is selected (GetType() == wxT("long")
2978 // - a "void*" pointer to a wxAccessible child object
2979 wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
2980 {
2981 wxASSERT( GetWindow() != NULL );
2982 if (!GetWindow())
2983 return wxACC_FAIL;
2984
2985 return wxACC_NOT_IMPLEMENTED;
2986 }
2987
2988 #endif // wxUSE_ACCESSIBILITY
2989
2990 // ----------------------------------------------------------------------------
2991 // RTL support
2992 // ----------------------------------------------------------------------------
2993
2994 wxCoord
2995 wxWindowBase::AdjustForLayoutDirection(wxCoord x,
2996 wxCoord width,
2997 wxCoord widthTotal) const
2998 {
2999 if ( GetLayoutDirection() == wxLayout_RightToLeft )
3000 {
3001 x = widthTotal - x - width;
3002 }
3003
3004 return x;
3005 }
3006