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