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