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