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