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