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