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