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