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