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