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