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