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