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