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