]> git.saurik.com Git - wxWidgets.git/blame - src/common/wincmn.cpp
generate #line references to source .xrc files in wxrc --gettext (patch #1803492...
[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
00a77b7c
VZ
2236// ----------------------------------------------------------------------------
2237// menu-related functions
2238// ----------------------------------------------------------------------------
2239
2240#if wxUSE_MENUS
2241
2242// this is used to pass the id of the selected item from the menu event handler
2243// to the main function itself
2244//
2245// it's ok to use a global here as there can be at most one popup menu shown at
2246// any time
2247static int gs_popupMenuSelection = wxID_NONE;
2248
2249void wxWindowBase::InternalOnPopupMenu(wxCommandEvent& event)
2250{
2251 // store the id in a global variable where we'll retrieve it from later
2252 gs_popupMenuSelection = event.GetId();
2253}
2254
2255int
2256wxWindowBase::DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y)
2257{
2258 gs_popupMenuSelection = wxID_NONE;
2259
2260 Connect(wxEVT_COMMAND_MENU_SELECTED,
2261 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu),
2262 NULL,
2263 this);
2264
2265 PopupMenu(&menu, x, y);
2266
2267 Disconnect(wxEVT_COMMAND_MENU_SELECTED,
2268 wxCommandEventHandler(wxWindowBase::InternalOnPopupMenu),
2269 NULL,
2270 this);
2271
2272 return gs_popupMenuSelection;
2273}
2274
2275#endif // wxUSE_MENUS
2276
dddd1f21
VZ
2277// methods for drawing the sizers in a visible way
2278#ifdef __WXDEBUG__
2279
2280static void DrawSizers(wxWindowBase *win);
2281
2282static void DrawBorder(wxWindowBase *win, const wxRect& rect, bool fill = false)
2283{
2284 wxClientDC dc((wxWindow *)win);
2285 dc.SetPen(*wxRED_PEN);
2286 dc.SetBrush(fill ? wxBrush(*wxRED, wxCROSSDIAG_HATCH): *wxTRANSPARENT_BRUSH);
2287 dc.DrawRectangle(rect.Deflate(1, 1));
2288}
2289
2290static void DrawSizer(wxWindowBase *win, wxSizer *sizer)
2291{
2292 const wxSizerItemList& items = sizer->GetChildren();
2293 for ( wxSizerItemList::const_iterator i = items.begin(),
2294 end = items.end();
2295 i != end;
2296 ++i )
2297 {
2298 wxSizerItem *item = *i;
2299 if ( item->IsSizer() )
2300 {
2301 DrawBorder(win, item->GetRect().Deflate(2));
2302 DrawSizer(win, item->GetSizer());
2303 }
2304 else if ( item->IsSpacer() )
2305 {
2306 DrawBorder(win, item->GetRect().Deflate(2), true);
2307 }
2308 else if ( item->IsWindow() )
2309 {
2310 DrawSizers(item->GetWindow());
2311 }
2312 }
2313}
2314
2315static void DrawSizers(wxWindowBase *win)
2316{
2317 wxSizer *sizer = win->GetSizer();
2318 if ( sizer )
2319 {
2320 DrawBorder(win, win->GetClientSize());
2321 DrawSizer(win, sizer);
2322 }
2323 else // no sizer, still recurse into the children
2324 {
2325 const wxWindowList& children = win->GetChildren();
2326 for ( wxWindowList::const_iterator i = children.begin(),
2327 end = children.end();
2328 i != end;
2329 ++i )
2330 {
2331 DrawSizers(*i);
2332 }
2333 }
2334}
2335
2336#endif // __WXDEBUG__
2337
2338// process special middle clicks
a02dc3e3
VZ
2339void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2340{
2341 if ( event.ControlDown() && event.AltDown() )
2342 {
dddd1f21
VZ
2343#ifdef __WXDEBUG__
2344 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2345 if ( event.ShiftDown() )
2346 {
2347 DrawSizers(this);
2348 return;
2349 }
2350#endif // __WXDEBUG__
2351
2352#if wxUSE_MSGDLG
8bb6b2c0
VZ
2353 // don't translate these strings, they're for diagnostics purposes only
2354 wxString msg;
2355 msg.Printf(_T("wxWidgets Library (%s port)\n")
449090b5
VZ
2356 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2357 _T("Runtime version of toolkit used is %d.%d.%s\n")
c05daf1b 2358 _T("Copyright (c) 1995-2007 wxWidgets team"),
449090b5 2359 wxPlatformInfo::Get().GetPortIdName().c_str(),
8bb6b2c0
VZ
2360 wxMAJOR_VERSION,
2361 wxMINOR_VERSION,
2362 wxRELEASE_NUMBER,
3f562374 2363#if wxUSE_UNICODE
8bb6b2c0 2364 L" (Unicode)",
3f562374 2365#else
8bb6b2c0 2366 wxEmptyString,
b1433926 2367#endif
4200d1f4 2368#ifdef __WXDEBUG__
8bb6b2c0 2369 _T(" Debug build"),
b1433926 2370#else
8bb6b2c0 2371 wxEmptyString,
3f562374 2372#endif
8bb6b2c0
VZ
2373 __TDATE__,
2374 __TTIME__,
449090b5
VZ
2375 wxPlatformInfo::Get().GetToolkitMajorVersion(),
2376 wxPlatformInfo::Get().GetToolkitMinorVersion(),
0118b60b 2377#ifdef __WXGTK__
449090b5 2378 wxString::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION).c_str()
0118b60b 2379#else
8bb6b2c0 2380 wxEmptyString
0118b60b 2381#endif
8bb6b2c0
VZ
2382 );
2383
2384 wxMessageBox(msg, _T("wxWidgets information"),
a02dc3e3
VZ
2385 wxICON_INFORMATION | wxOK,
2386 (wxWindow *)this);
fae86641 2387#endif // wxUSE_MSGDLG
a02dc3e3
VZ
2388 }
2389 else
2390 {
2391 event.Skip();
2392 }
2393}
2394
ed5317e5
JS
2395// ----------------------------------------------------------------------------
2396// accessibility
2397// ----------------------------------------------------------------------------
2398
2399#if wxUSE_ACCESSIBILITY
2400void wxWindowBase::SetAccessible(wxAccessible* accessible)
2401{
2aefc528 2402 if (m_accessible && (accessible != m_accessible))
ed5317e5
JS
2403 delete m_accessible;
2404 m_accessible = accessible;
2405 if (m_accessible)
2406 m_accessible->SetWindow((wxWindow*) this);
2407}
2408
2409// Returns the accessible object, creating if necessary.
2410wxAccessible* wxWindowBase::GetOrCreateAccessible()
2411{
2412 if (!m_accessible)
2413 m_accessible = CreateAccessible();
2414 return m_accessible;
2415}
2416
2417// Override to create a specific accessible object.
2418wxAccessible* wxWindowBase::CreateAccessible()
2419{
2420 return new wxWindowAccessible((wxWindow*) this);
2421}
2422
2423#endif
2424
f03fc89f
VZ
2425// ----------------------------------------------------------------------------
2426// list classes implementation
2427// ----------------------------------------------------------------------------
2428
ed1288c1
VZ
2429#if wxUSE_STL
2430
7ec69821 2431#include "wx/listimpl.cpp"
412e0d47 2432WX_DEFINE_LIST(wxWindowList)
ed1288c1 2433
602a2e02 2434#else // !wxUSE_STL
ed1288c1 2435
f03fc89f
VZ
2436void wxWindowListNode::DeleteData()
2437{
2438 delete (wxWindow *)GetData();
2439}
ed1288c1 2440
602a2e02 2441#endif // wxUSE_STL/!wxUSE_STL
f03fc89f 2442
1e6feb95
VZ
2443// ----------------------------------------------------------------------------
2444// borders
2445// ----------------------------------------------------------------------------
2446
aede4ebb 2447wxBorder wxWindowBase::GetBorder(long flags) const
1e6feb95 2448{
aede4ebb 2449 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
1e6feb95
VZ
2450 if ( border == wxBORDER_DEFAULT )
2451 {
2452 border = GetDefaultBorder();
2453 }
78cd9c69
JS
2454 else if ( border == wxBORDER_THEME )
2455 {
2456 border = GetDefaultBorderForControl();
2457 }
1e6feb95
VZ
2458
2459 return border;
2460}
2461
2462wxBorder wxWindowBase::GetDefaultBorder() const
2463{
2464 return wxBORDER_NONE;
2465}
2466
2467// ----------------------------------------------------------------------------
2468// hit testing
2469// ----------------------------------------------------------------------------
2470
2471wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2472{
2473 // here we just check if the point is inside the window or not
2474
2475 // check the top and left border first
2476 bool outside = x < 0 || y < 0;
2477 if ( !outside )
2478 {
2479 // check the right and bottom borders too
2480 wxSize size = GetSize();
2481 outside = x >= size.x || y >= size.y;
2482 }
2483
2484 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2485}
2486
94633ad9
VZ
2487// ----------------------------------------------------------------------------
2488// mouse capture
2489// ----------------------------------------------------------------------------
2490
2491struct WXDLLEXPORT wxWindowNext
2492{
2493 wxWindow *win;
2494 wxWindowNext *next;
786646f3 2495} *wxWindowBase::ms_winCaptureNext = NULL;
63e819f2
VS
2496wxWindow *wxWindowBase::ms_winCaptureCurrent = NULL;
2497bool wxWindowBase::ms_winCaptureChanging = false;
94633ad9 2498
a83e1475 2499void wxWindowBase::CaptureMouse()
94633ad9 2500{
008202b7 2501 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
45e0dc94 2502
63e819f2
VS
2503 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive CaptureMouse call?") );
2504
2505 ms_winCaptureChanging = true;
2506
94633ad9
VZ
2507 wxWindow *winOld = GetCapture();
2508 if ( winOld )
2509 {
df2f507b 2510 ((wxWindowBase*) winOld)->DoReleaseMouse();
edd802c6 2511
94633ad9
VZ
2512 // save it on stack
2513 wxWindowNext *item = new wxWindowNext;
2514 item->win = winOld;
2515 item->next = ms_winCaptureNext;
2516 ms_winCaptureNext = item;
2517 }
2518 //else: no mouse capture to save
2519
2520 DoCaptureMouse();
63e819f2
VS
2521 ms_winCaptureCurrent = (wxWindow*)this;
2522
2523 ms_winCaptureChanging = false;
94633ad9
VZ
2524}
2525
a83e1475 2526void wxWindowBase::ReleaseMouse()
94633ad9 2527{
008202b7 2528 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
349d1942 2529
63e819f2
VS
2530 wxASSERT_MSG( !ms_winCaptureChanging, _T("recursive ReleaseMouse call?") );
2531
63fd5f0b 2532 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
a7b09001 2533
63e819f2
VS
2534 ms_winCaptureChanging = true;
2535
94633ad9 2536 DoReleaseMouse();
63e819f2 2537 ms_winCaptureCurrent = NULL;
94633ad9
VZ
2538
2539 if ( ms_winCaptureNext )
2540 {
44f8caa7 2541 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
63e819f2 2542 ms_winCaptureCurrent = ms_winCaptureNext->win;
edd802c6 2543
94633ad9
VZ
2544 wxWindowNext *item = ms_winCaptureNext;
2545 ms_winCaptureNext = item->next;
2546 delete item;
2547 }
2548 //else: stack is empty, no previous capture
2549
63e819f2
VS
2550 ms_winCaptureChanging = false;
2551
94633ad9 2552 wxLogTrace(_T("mousecapture"),
e11f4636 2553 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
008202b7 2554 wx_static_cast(void*, GetCapture()));
94633ad9
VZ
2555}
2556
63e819f2
VS
2557static void DoNotifyWindowAboutCaptureLost(wxWindow *win)
2558{
2559 wxMouseCaptureLostEvent event(win->GetId());
2560 event.SetEventObject(win);
40bdc5d6
VZ
2561 if ( !win->GetEventHandler()->ProcessEvent(event) )
2562 {
44038f9a
VS
2563 // windows must handle this event, otherwise the app wouldn't behave
2564 // correctly if it loses capture unexpectedly; see the discussion here:
2565 // http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863
2566 // http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/82376
40bdc5d6
VZ
2567 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2568 }
63e819f2
VS
2569}
2570
2571/* static */
72f8c792 2572void wxWindowBase::NotifyCaptureLost()
63e819f2
VS
2573{
2574 // don't do anything if capture lost was expected, i.e. resulted from
2575 // a wx call to ReleaseMouse or CaptureMouse:
2576 if ( ms_winCaptureChanging )
2577 return;
2578
2579 // if the capture was lost unexpectedly, notify every window that has
2580 // capture (on stack or current) about it and clear the stack:
2581
2582 if ( ms_winCaptureCurrent )
2583 {
2584 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent);
2585 ms_winCaptureCurrent = NULL;
2586 }
2587
2588 while ( ms_winCaptureNext )
2589 {
2590 wxWindowNext *item = ms_winCaptureNext;
2591 ms_winCaptureNext = item->next;
2592
2593 DoNotifyWindowAboutCaptureLost(item->win);
2594
2595 delete item;
2596 }
2597}
2598
5048c832 2599#if wxUSE_HOTKEY
540b6b09
VZ
2600
2601bool
2602wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2603 int WXUNUSED(modifiers),
2604 int WXUNUSED(keycode))
5048c832
JS
2605{
2606 // not implemented
2607 return false;
2608}
2609
540b6b09 2610bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
5048c832
JS
2611{
2612 // not implemented
2613 return false;
2614}
540b6b09
VZ
2615
2616#endif // wxUSE_HOTKEY
7de59551 2617
4caf847c
VZ
2618// ----------------------------------------------------------------------------
2619// event processing
2620// ----------------------------------------------------------------------------
2621
ac8d0c11 2622bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
4caf847c 2623{
6eabf58c 2624#if wxUSE_VALIDATORS
4caf847c
VZ
2625 // Can only use the validator of the window which
2626 // is receiving the event
2627 if ( event.GetEventObject() == this )
2628 {
2629 wxValidator *validator = GetValidator();
2630 if ( validator && validator->ProcessEvent(event) )
2631 {
6eabf58c 2632 return true;
4caf847c
VZ
2633 }
2634 }
6eabf58c 2635#endif // wxUSE_VALIDATORS
4caf847c 2636
6eabf58c 2637 return false;
4caf847c
VZ
2638}
2639
4caf847c
VZ
2640bool wxWindowBase::TryParent(wxEvent& event)
2641{
90e572f1 2642 // carry on up the parent-child hierarchy if the propagation count hasn't
040e234d
VZ
2643 // reached zero yet
2644 if ( event.ShouldPropagate() )
4caf847c
VZ
2645 {
2646 // honour the requests to stop propagation at this window: this is
2647 // used by the dialogs, for example, to prevent processing the events
2648 // from the dialog controls in the parent frame which rarely, if ever,
2649 // makes sense
2650 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2651 {
2652 wxWindow *parent = GetParent();
2653 if ( parent && !parent->IsBeingDeleted() )
040e234d
VZ
2654 {
2655 wxPropagateOnce propagateOnce(event);
2656
4caf847c 2657 return parent->GetEventHandler()->ProcessEvent(event);
040e234d 2658 }
4caf847c
VZ
2659 }
2660 }
2661
2662 return wxEvtHandler::TryParent(event);
2663}
2664
5f6cfda7 2665// ----------------------------------------------------------------------------
a24de76b 2666// keyboard navigation
5f6cfda7
JS
2667// ----------------------------------------------------------------------------
2668
5644933f
VZ
2669// Navigates in the specified direction inside this window
2670bool wxWindowBase::DoNavigateIn(int flags)
5f6cfda7 2671{
5644933f
VZ
2672#ifdef wxHAS_NATIVE_TAB_TRAVERSAL
2673 // native code doesn't process our wxNavigationKeyEvents anyhow
2674 return false;
2675#else // !wxHAS_NATIVE_TAB_TRAVERSAL
5f6cfda7 2676 wxNavigationKeyEvent eventNav;
eedc82f4 2677 eventNav.SetFlags(flags);
5644933f
VZ
2678 eventNav.SetEventObject(FindFocus());
2679 return GetEventHandler()->ProcessEvent(eventNav);
2680#endif // wxHAS_NATIVE_TAB_TRAVERSAL/!wxHAS_NATIVE_TAB_TRAVERSAL
5f6cfda7
JS
2681}
2682
a24de76b
VZ
2683void wxWindowBase::DoMoveInTabOrder(wxWindow *win, MoveKind move)
2684{
2685 // check that we're not a top level window
2686 wxCHECK_RET( GetParent(),
2687 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2688
ef6816ef
VZ
2689 // detect the special case when we have nothing to do anyhow and when the
2690 // code below wouldn't work
2691 if ( win == this )
2692 return;
2693
a24de76b
VZ
2694 // find the target window in the siblings list
2695 wxWindowList& siblings = GetParent()->GetChildren();
2696 wxWindowList::compatibility_iterator i = siblings.Find(win);
2697 wxCHECK_RET( i, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2698
2699 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2700 // can't just move the node around
feef1ecf
VZ
2701 wxWindow *self = (wxWindow *)this;
2702 siblings.DeleteObject(self);
9e9300c4
VZ
2703 if ( move == MoveAfter )
2704 {
2705 i = i->GetNext();
2706 }
2707
2708 if ( i )
a24de76b 2709 {
feef1ecf 2710 siblings.Insert(i, self);
a24de76b
VZ
2711 }
2712 else // MoveAfter and win was the last sibling
2713 {
feef1ecf 2714 siblings.Append(self);
a24de76b
VZ
2715 }
2716}
2717
0fe02759
VS
2718// ----------------------------------------------------------------------------
2719// focus handling
2720// ----------------------------------------------------------------------------
2721
2722/*static*/ wxWindow* wxWindowBase::FindFocus()
2723{
9c52a429 2724 wxWindowBase *win = DoFindFocus();
0fe02759
VS
2725 return win ? win->GetMainWindowOfCompositeControl() : NULL;
2726}
2727
33b494d6
VZ
2728// ----------------------------------------------------------------------------
2729// global functions
2730// ----------------------------------------------------------------------------
2731
2732wxWindow* wxGetTopLevelParent(wxWindow *win)
2733{
2734 while ( win && !win->IsTopLevel() )
2735 win = win->GetParent();
2736
2737 return win;
2738}
2739
ed5317e5
JS
2740#if wxUSE_ACCESSIBILITY
2741// ----------------------------------------------------------------------------
2742// accessible object for windows
2743// ----------------------------------------------------------------------------
2744
2745// Can return either a child object, or an integer
2746// representing the child element, starting from 1.
66b9ec3d 2747wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
ed5317e5
JS
2748{
2749 wxASSERT( GetWindow() != NULL );
2750 if (!GetWindow())
2751 return wxACC_FAIL;
2752
2753 return wxACC_NOT_IMPLEMENTED;
2754}
2755
2756// Returns the rectangle for this object (id = 0) or a child element (id > 0).
2757wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2758{
2759 wxASSERT( GetWindow() != NULL );
2760 if (!GetWindow())
2761 return wxACC_FAIL;
2762
c6e2af45
JS
2763 wxWindow* win = NULL;
2764 if (elementId == 0)
2765 {
2766 win = GetWindow();
2767 }
2768 else
2769 {
2770 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2771 {
ee6eb8d8 2772 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
c6e2af45
JS
2773 }
2774 else
2775 return wxACC_FAIL;
2776 }
2777 if (win)
2778 {
2779 rect = win->GetRect();
2780 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2781 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2782 return wxACC_OK;
2783 }
2784
ed5317e5
JS
2785 return wxACC_NOT_IMPLEMENTED;
2786}
2787
2788// Navigates from fromId to toId/toObject.
2789wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
66b9ec3d 2790 int* WXUNUSED(toId), wxAccessible** toObject)
ed5317e5
JS
2791{
2792 wxASSERT( GetWindow() != NULL );
2793 if (!GetWindow())
2794 return wxACC_FAIL;
2795
c6e2af45
JS
2796 switch (navDir)
2797 {
2798 case wxNAVDIR_FIRSTCHILD:
2799 {
2800 if (GetWindow()->GetChildren().GetCount() == 0)
2801 return wxACC_FALSE;
2802 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2803 *toObject = childWindow->GetOrCreateAccessible();
2804
2805 return wxACC_OK;
2806 }
2807 case wxNAVDIR_LASTCHILD:
2808 {
2809 if (GetWindow()->GetChildren().GetCount() == 0)
2810 return wxACC_FALSE;
2811 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2812 *toObject = childWindow->GetOrCreateAccessible();
2813
2814 return wxACC_OK;
2815 }
2816 case wxNAVDIR_RIGHT:
2817 case wxNAVDIR_DOWN:
2818 case wxNAVDIR_NEXT:
2819 {
ee6eb8d8
MB
2820 wxWindowList::compatibility_iterator node =
2821 wxWindowList::compatibility_iterator();
c6e2af45
JS
2822 if (fromId == 0)
2823 {
2824 // Can't navigate to sibling of this window
2825 // if we're a top-level window.
2826 if (!GetWindow()->GetParent())
2827 return wxACC_NOT_IMPLEMENTED;
2828
2829 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2830 }
2831 else
2832 {
2833 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
33b3f7c3 2834 node = GetWindow()->GetChildren().Item(fromId-1);
c6e2af45
JS
2835 }
2836
2837 if (node && node->GetNext())
2838 {
ee6eb8d8 2839 wxWindow* nextWindow = node->GetNext()->GetData();
c6e2af45
JS
2840 *toObject = nextWindow->GetOrCreateAccessible();
2841 return wxACC_OK;
2842 }
2843 else
2844 return wxACC_FALSE;
2845 }
2846 case wxNAVDIR_LEFT:
2847 case wxNAVDIR_UP:
2848 case wxNAVDIR_PREVIOUS:
2849 {
ee6eb8d8
MB
2850 wxWindowList::compatibility_iterator node =
2851 wxWindowList::compatibility_iterator();
c6e2af45
JS
2852 if (fromId == 0)
2853 {
2854 // Can't navigate to sibling of this window
2855 // if we're a top-level window.
2856 if (!GetWindow()->GetParent())
2857 return wxACC_NOT_IMPLEMENTED;
2858
2859 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2860 }
2861 else
2862 {
2863 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
33b3f7c3 2864 node = GetWindow()->GetChildren().Item(fromId-1);
c6e2af45
JS
2865 }
2866
2867 if (node && node->GetPrevious())
2868 {
ee6eb8d8 2869 wxWindow* previousWindow = node->GetPrevious()->GetData();
c6e2af45
JS
2870 *toObject = previousWindow->GetOrCreateAccessible();
2871 return wxACC_OK;
2872 }
2873 else
2874 return wxACC_FALSE;
2875 }
2876 }
2877
ed5317e5
JS
2878 return wxACC_NOT_IMPLEMENTED;
2879}
2880
2881// Gets the name of the specified object.
2882wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2883{
2884 wxASSERT( GetWindow() != NULL );
2885 if (!GetWindow())
2886 return wxACC_FAIL;
2887
2aefc528
JS
2888 wxString title;
2889
77ffb593 2890 // If a child, leave wxWidgets to call the function on the actual
2aefc528
JS
2891 // child object.
2892 if (childId > 0)
2893 return wxACC_NOT_IMPLEMENTED;
2894
2895 // This will eventually be replaced by specialised
77ffb593 2896 // accessible classes, one for each kind of wxWidgets
2aefc528 2897 // control or window.
0b4f47a3 2898#if wxUSE_BUTTON
2aefc528
JS
2899 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2900 title = ((wxButton*) GetWindow())->GetLabel();
2901 else
0b4f47a3 2902#endif
2aefc528 2903 title = GetWindow()->GetName();
e11f4636 2904
ba889513 2905 if (!title.empty())
ed5317e5
JS
2906 {
2907 *name = title;
2908 return wxACC_OK;
2909 }
2910 else
2911 return wxACC_NOT_IMPLEMENTED;
2912}
2913
2914// Gets the number of children.
2915wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2916{
2917 wxASSERT( GetWindow() != NULL );
2918 if (!GetWindow())
2919 return wxACC_FAIL;
2920
2921 *childId = (int) GetWindow()->GetChildren().GetCount();
2922 return wxACC_OK;
2923}
2924
2925// Gets the specified child (starting from 1).
2926// If *child is NULL and return value is wxACC_OK,
2927// this means that the child is a simple element and
2928// not an accessible object.
2929wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2930{
2931 wxASSERT( GetWindow() != NULL );
2932 if (!GetWindow())
2933 return wxACC_FAIL;
2934
2935 if (childId == 0)
2936 {
2937 *child = this;
2938 return wxACC_OK;
2939 }
2940
2941 if (childId > (int) GetWindow()->GetChildren().GetCount())
2942 return wxACC_FAIL;
2943
ee6eb8d8 2944 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
ed5317e5
JS
2945 *child = childWindow->GetOrCreateAccessible();
2946 if (*child)
2947 return wxACC_OK;
2948 else
2949 return wxACC_FAIL;
2950}
2951
2952// Gets the parent, or NULL.
2953wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2954{
2955 wxASSERT( GetWindow() != NULL );
2956 if (!GetWindow())
2957 return wxACC_FAIL;
2958
2959 wxWindow* parentWindow = GetWindow()->GetParent();
c6e2af45 2960 if (!parentWindow)
ed5317e5
JS
2961 {
2962 *parent = NULL;
2963 return wxACC_OK;
2964 }
2965 else
2966 {
2967 *parent = parentWindow->GetOrCreateAccessible();
2968 if (*parent)
2969 return wxACC_OK;
2970 else
2971 return wxACC_FAIL;
2972 }
2973}
2974
2975// Performs the default action. childId is 0 (the action for this object)
2976// or > 0 (the action for a child).
2977// Return wxACC_NOT_SUPPORTED if there is no default action for this
2978// window (e.g. an edit control).
66b9ec3d 2979wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
ed5317e5
JS
2980{
2981 wxASSERT( GetWindow() != NULL );
2982 if (!GetWindow())
2983 return wxACC_FAIL;
2984
2985 return wxACC_NOT_IMPLEMENTED;
2986}
2987
2988// Gets the default action for this object (0) or > 0 (the action for a child).
2989// Return wxACC_OK even if there is no action. actionName is the action, or the empty
2990// string if there is no action.
2991// The retrieved string describes the action that is performed on an object,
2992// not what the object does as a result. For example, a toolbar button that prints
2993// a document has a default action of "Press" rather than "Prints the current document."
66b9ec3d 2994wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
ed5317e5
JS
2995{
2996 wxASSERT( GetWindow() != NULL );
2997 if (!GetWindow())
2998 return wxACC_FAIL;
2999
3000 return wxACC_NOT_IMPLEMENTED;
3001}
3002
3003// Returns the description for this object or a child.
66b9ec3d 3004wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
ed5317e5
JS
3005{
3006 wxASSERT( GetWindow() != NULL );
3007 if (!GetWindow())
3008 return wxACC_FAIL;
3009
dc6588e7 3010 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
ba889513 3011 if (!ht.empty())
2aefc528
JS
3012 {
3013 *description = ht;
3014 return wxACC_OK;
3015 }
ed5317e5
JS
3016 return wxACC_NOT_IMPLEMENTED;
3017}
3018
3019// Returns help text for this object or a child, similar to tooltip text.
66b9ec3d 3020wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
ed5317e5
JS
3021{
3022 wxASSERT( GetWindow() != NULL );
3023 if (!GetWindow())
3024 return wxACC_FAIL;
3025
dc6588e7 3026 wxString ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Keyboard));
ba889513 3027 if (!ht.empty())
ed5317e5
JS
3028 {
3029 *helpText = ht;
3030 return wxACC_OK;
3031 }
3032 return wxACC_NOT_IMPLEMENTED;
3033}
3034
3035// Returns the keyboard shortcut for this object or child.
3036// Return e.g. ALT+K
66b9ec3d 3037wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
ed5317e5
JS
3038{
3039 wxASSERT( GetWindow() != NULL );
3040 if (!GetWindow())
3041 return wxACC_FAIL;
3042
3043 return wxACC_NOT_IMPLEMENTED;
3044}
3045
3046// Returns a role constant.
3047wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
3048{
3049 wxASSERT( GetWindow() != NULL );
3050 if (!GetWindow())
3051 return wxACC_FAIL;
3052
77ffb593 3053 // If a child, leave wxWidgets to call the function on the actual
2aefc528
JS
3054 // child object.
3055 if (childId > 0)
3056 return wxACC_NOT_IMPLEMENTED;
3057
3058 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
3059 return wxACC_NOT_IMPLEMENTED;
3060#if wxUSE_STATUSBAR
3061 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
3062 return wxACC_NOT_IMPLEMENTED;
3063#endif
3064#if wxUSE_TOOLBAR
3065 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
3066 return wxACC_NOT_IMPLEMENTED;
3067#endif
3068
3069 //*role = wxROLE_SYSTEM_CLIENT;
3070 *role = wxROLE_SYSTEM_CLIENT;
3071 return wxACC_OK;
3072
66b9ec3d 3073 #if 0
ed5317e5 3074 return wxACC_NOT_IMPLEMENTED;
66b9ec3d 3075 #endif
ed5317e5
JS
3076}
3077
3078// Returns a state constant.
3079wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
3080{
3081 wxASSERT( GetWindow() != NULL );
3082 if (!GetWindow())
3083 return wxACC_FAIL;
3084
77ffb593 3085 // If a child, leave wxWidgets to call the function on the actual
2aefc528
JS
3086 // child object.
3087 if (childId > 0)
3088 return wxACC_NOT_IMPLEMENTED;
3089
3090 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
3091 return wxACC_NOT_IMPLEMENTED;
3092
3093#if wxUSE_STATUSBAR
3094 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
3095 return wxACC_NOT_IMPLEMENTED;
3096#endif
3097#if wxUSE_TOOLBAR
3098 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
3099 return wxACC_NOT_IMPLEMENTED;
3100#endif
3101
3102 *state = 0;
3103 return wxACC_OK;
3104
66b9ec3d 3105 #if 0
ed5317e5 3106 return wxACC_NOT_IMPLEMENTED;
66b9ec3d 3107 #endif
ed5317e5
JS
3108}
3109
3110// Returns a localized string representing the value for the object
3111// or child.
66b9ec3d 3112wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
ed5317e5
JS
3113{
3114 wxASSERT( GetWindow() != NULL );
3115 if (!GetWindow())
3116 return wxACC_FAIL;
3117
3118 return wxACC_NOT_IMPLEMENTED;
3119}
3120
3121// Selects the object or child.
66b9ec3d 3122wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
ed5317e5
JS
3123{
3124 wxASSERT( GetWindow() != NULL );
3125 if (!GetWindow())
3126 return wxACC_FAIL;
3127
3128 return wxACC_NOT_IMPLEMENTED;
3129}
3130
3131// Gets the window with the keyboard focus.
3132// If childId is 0 and child is NULL, no object in
3133// this subhierarchy has the focus.
3134// If this object has the focus, child should be 'this'.
66b9ec3d 3135wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
ed5317e5
JS
3136{
3137 wxASSERT( GetWindow() != NULL );
3138 if (!GetWindow())
3139 return wxACC_FAIL;
3140
3141 return wxACC_NOT_IMPLEMENTED;
3142}
3143
ca5c6ac3 3144#if wxUSE_VARIANT
ed5317e5
JS
3145// Gets a variant representing the selected children
3146// of this object.
3147// Acceptable values:
cab1a605 3148// - a null variant (IsNull() returns true)
ed5317e5
JS
3149// - a list variant (GetType() == wxT("list")
3150// - an integer representing the selected child element,
3151// or 0 if this object is selected (GetType() == wxT("long")
3152// - a "void*" pointer to a wxAccessible child object
66b9ec3d 3153wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
ed5317e5
JS
3154{
3155 wxASSERT( GetWindow() != NULL );
3156 if (!GetWindow())
3157 return wxACC_FAIL;
3158
3159 return wxACC_NOT_IMPLEMENTED;
3160}
ca5c6ac3 3161#endif // wxUSE_VARIANT
ed5317e5
JS
3162
3163#endif // wxUSE_ACCESSIBILITY
978af864
VZ
3164
3165// ----------------------------------------------------------------------------
3166// RTL support
3167// ----------------------------------------------------------------------------
3168
3169wxCoord
3170wxWindowBase::AdjustForLayoutDirection(wxCoord x,
3171 wxCoord width,
3172 wxCoord widthTotal) const
3173{
3174 if ( GetLayoutDirection() == wxLayout_RightToLeft )
3175 {
3176 x = widthTotal - x - width;
3177 }
3178
3179 return x;
3180}
3181