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