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