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