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