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