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