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