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