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