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