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