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