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