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