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