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