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