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