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