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