]> git.saurik.com Git - wxWidgets.git/blame - src/common/wincmn.cpp
update to docs now minimal sample compiles
[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
58654ed0
VZ
20#ifdef __GNUG__
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;
117 m_children.DeleteContents( FALSE ); // don't auto delete node data
118
119 // no constraints on the minimal window size
120 m_minWidth =
121 m_minHeight =
122 m_maxWidth =
123 m_maxHeight = -1;
124
125 // window is created enabled but it's not visible yet
126 m_isShown = FALSE;
127 m_isEnabled = TRUE;
128
f03fc89f
VZ
129 // the default event handler is just this window
130 m_eventHandler = this;
131
88ac883a 132#if wxUSE_VALIDATORS
f03fc89f
VZ
133 // no validator
134 m_windowValidator = (wxValidator *) NULL;
88ac883a 135#endif // wxUSE_VALIDATORS
f03fc89f
VZ
136
137 // use the system default colours
a756f210
VS
138 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
139 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
f6e4e9ea 140
8bf30fe9
VZ
141 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
142 // so the font is *not* really set - but calls to SetFont() later won't do
143 // anything because m_font appears to be already set!
144#ifndef __WXMSW__
a756f210 145 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
8bf30fe9 146#endif // __WXMSW__
807a903e 147
08df3e44
VZ
148 // the colours/fonts are default for now
149 m_hasBgCol =
150 m_hasFgCol =
151 m_hasFont = FALSE;
152
f03fc89f 153 // no style bits
d80cd92a 154 m_exStyle =
f03fc89f
VZ
155 m_windowStyle = 0;
156
157 // an optimization for the event processing: checking this flag is much
158 // faster than using IsKindOf(CLASSINFO(wxWindow))
159 m_isWindow = TRUE;
160
161#if wxUSE_CONSTRAINTS
162 // no constraints whatsoever
163 m_constraints = (wxLayoutConstraints *) NULL;
164 m_constraintsInvolvedIn = (wxWindowList *) NULL;
461e93f9
JS
165#endif // wxUSE_CONSTRAINTS
166
f03fc89f 167 m_windowSizer = (wxSizer *) NULL;
be90c029 168 m_containingSizer = (wxSizer *) NULL;
f03fc89f 169 m_autoLayout = FALSE;
f03fc89f
VZ
170
171#if wxUSE_DRAG_AND_DROP
172 m_dropTarget = (wxDropTarget *)NULL;
173#endif // wxUSE_DRAG_AND_DROP
174
175#if wxUSE_TOOLTIPS
176 m_tooltip = (wxToolTip *)NULL;
177#endif // wxUSE_TOOLTIPS
789295bf
VZ
178
179#if wxUSE_CARET
180 m_caret = (wxCaret *)NULL;
181#endif // wxUSE_CARET
a2d93e73 182
574c939e 183#if wxUSE_PALETTE
b95edd47 184 m_hasCustomPalette = FALSE;
574c939e
KB
185#endif // wxUSE_PALETTE
186
ed5317e5
JS
187#if wxUSE_ACCESSIBILITY
188 m_accessible = NULL;
189#endif
190
566d84a7 191 m_virtualSize = wxDefaultSize;
1e2a653b
VZ
192
193 m_minVirtualWidth =
194 m_minVirtualHeight =
195 m_maxVirtualWidth =
566d84a7
RL
196 m_maxVirtualHeight = -1;
197
a2d93e73
JS
198 // Whether we're using the current theme for this window (wxGTK only for now)
199 m_themeEnabled = FALSE;
f03fc89f
VZ
200}
201
202// common part of window creation process
203bool wxWindowBase::CreateBase(wxWindowBase *parent,
204 wxWindowID id,
74e3313b
VZ
205 const wxPoint& WXUNUSED(pos),
206 const wxSize& WXUNUSED(size),
f03fc89f 207 long style,
8d99be5f 208 const wxValidator& validator,
f03fc89f
VZ
209 const wxString& name)
210{
211 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
212 // member variables - check that it has been called (will catch the case
213 // when a new ctor is added which doesn't call InitWindow)
223d09f6 214 wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") );
f03fc89f 215
106844da
VZ
216#if wxUSE_STATBOX
217 // wxGTK doesn't allow to create controls with static box as the parent so
218 // this will result in a crash when the program is ported to wxGTK so warn
219 // the user about it
220
221 // if you get this assert, the correct solution is to create the controls
222 // as siblings of the static box
223 wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox),
224 _T("wxStaticBox can't be used as a window parent!") );
225#endif // wxUSE_STATBOX
226
925f154d
VZ
227 // ids are limited to 16 bits under MSW so if you care about portability,
228 // it's not a good idea to use ids out of this range (and negative ids are
229 // reserved for wxWindows own usage)
230 wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767),
231 _T("invalid id value") );
232
f03fc89f 233 // generate a new id if the user doesn't care about it
925f154d 234 m_windowId = id == wxID_ANY ? NewControlId() : id;
f03fc89f
VZ
235
236 SetName(name);
237 SetWindowStyleFlag(style);
238 SetParent(parent);
674ac8b9
VZ
239
240#if wxUSE_VALIDATORS
8d99be5f 241 SetValidator(validator);
674ac8b9 242#endif // wxUSE_VALIDATORS
f03fc89f 243
8ae6ce07
VZ
244 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
245 // have it too - like this it's possible to set it only in the top level
246 // dialog/frame and all children will inherit it by defult
247 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
248 {
9cb98d89 249 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
8ae6ce07
VZ
250 }
251
f03fc89f
VZ
252 return TRUE;
253}
254
255// ----------------------------------------------------------------------------
256// destruction
257// ----------------------------------------------------------------------------
258
259// common clean up
260wxWindowBase::~wxWindowBase()
261{
349d1942
VS
262 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
263
f03fc89f
VZ
264 // FIXME if these 2 cases result from programming errors in the user code
265 // we should probably assert here instead of silently fixing them
266
267 // Just in case the window has been Closed, but we're then deleting
268 // immediately: don't leave dangling pointers.
269 wxPendingDelete.DeleteObject(this);
270
271 // Just in case we've loaded a top-level window via LoadNativeDialog but
272 // we weren't a dialog class
273 wxTopLevelWindows.DeleteObject(this);
a23fd0e1 274
223d09f6 275 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
f03fc89f 276
789295bf
VZ
277#if wxUSE_CARET
278 if ( m_caret )
279 delete m_caret;
280#endif // wxUSE_CARET
281
88ac883a 282#if wxUSE_VALIDATORS
f03fc89f
VZ
283 if ( m_windowValidator )
284 delete m_windowValidator;
88ac883a 285#endif // wxUSE_VALIDATORS
f03fc89f 286
f03fc89f
VZ
287#if wxUSE_CONSTRAINTS
288 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
289 // at deleted windows as they delete themselves.
290 DeleteRelatedConstraints();
291
292 if ( m_constraints )
293 {
294 // This removes any dangling pointers to this window in other windows'
295 // constraintsInvolvedIn lists.
296 UnsetConstraints(m_constraints);
297 delete m_constraints;
298 m_constraints = NULL;
299 }
300
461e93f9
JS
301#endif // wxUSE_CONSTRAINTS
302
be90c029 303 if ( m_containingSizer )
12a3f227 304 m_containingSizer->Detach( (wxWindow*)this );
be90c029 305
f03fc89f
VZ
306 if ( m_windowSizer )
307 delete m_windowSizer;
308
f03fc89f
VZ
309#if wxUSE_DRAG_AND_DROP
310 if ( m_dropTarget )
311 delete m_dropTarget;
312#endif // wxUSE_DRAG_AND_DROP
313
314#if wxUSE_TOOLTIPS
315 if ( m_tooltip )
316 delete m_tooltip;
317#endif // wxUSE_TOOLTIPS
b0ee47ff 318
ed5317e5
JS
319#if wxUSE_ACCESSIBILITY
320 if ( m_accessible )
321 delete m_accessible;
322#endif
323
b0ee47ff
VZ
324 // reset the dangling pointer our parent window may keep to us
325 if ( m_parent && m_parent->GetDefaultItem() == this )
326 {
327 m_parent->SetDefaultItem(NULL);
328 }
f03fc89f
VZ
329}
330
331bool wxWindowBase::Destroy()
332{
333 delete this;
334
335 return TRUE;
336}
337
338bool wxWindowBase::Close(bool force)
339{
340 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
341 event.SetEventObject(this);
342#if WXWIN_COMPATIBILITY
343 event.SetForce(force);
344#endif // WXWIN_COMPATIBILITY
345 event.SetCanVeto(!force);
346
347 // return FALSE if window wasn't closed because the application vetoed the
348 // close event
349 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
350}
351
352bool wxWindowBase::DestroyChildren()
353{
354 wxWindowList::Node *node;
a23fd0e1 355 for ( ;; )
f03fc89f 356 {
a23fd0e1
VZ
357 // we iterate until the list becomes empty
358 node = GetChildren().GetFirst();
359 if ( !node )
360 break;
361
f03fc89f 362 wxWindow *child = node->GetData();
a23fd0e1 363
223d09f6 364 wxASSERT_MSG( child, wxT("children list contains empty nodes") );
a23fd0e1 365
1a77875b 366 child->Show(FALSE);
eb082a08 367 delete child;
a23fd0e1
VZ
368
369 wxASSERT_MSG( !GetChildren().Find(child),
223d09f6 370 wxT("child didn't remove itself using RemoveChild()") );
f03fc89f
VZ
371 }
372
373 return TRUE;
374}
375
376// ----------------------------------------------------------------------------
f68586e5 377// size/position related methods
f03fc89f
VZ
378// ----------------------------------------------------------------------------
379
380// centre the window with respect to its parent in either (or both) directions
381void wxWindowBase::Centre(int direction)
382{
f6bcfd97
BP
383 // the position/size of the parent window or of the entire screen
384 wxPoint posParent;
f03fc89f
VZ
385 int widthParent, heightParent;
386
f6bcfd97
BP
387 wxWindow *parent = NULL;
388
389 if ( !(direction & wxCENTRE_ON_SCREEN) )
f03fc89f 390 {
f6bcfd97
BP
391 // find the parent to centre this window on: it should be the
392 // immediate parent for the controls but the top level parent for the
393 // top level windows (like dialogs)
394 parent = GetParent();
395 if ( IsTopLevel() )
396 {
397 while ( parent && !parent->IsTopLevel() )
398 {
399 parent = parent->GetParent();
400 }
401 }
402
e28b0102
VZ
403 // there is no wxTopLevelWindow under wxMotif yet
404#ifndef __WXMOTIF__
085ad686
VZ
405 // we shouldn't center the dialog on the iconized window: under
406 // Windows, for example, this places it completely off the screen
407 if ( parent )
408 {
409 wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
410 if ( winTop && winTop->IsIconized() )
411 {
412 parent = NULL;
413 }
414 }
e28b0102 415#endif // __WXMOTIF__
085ad686 416
f6bcfd97
BP
417 // did we find the parent?
418 if ( !parent )
419 {
420 // no other choice
421 direction |= wxCENTRE_ON_SCREEN;
422 }
f03fc89f 423 }
10fcf31a
VZ
424
425 if ( direction & wxCENTRE_ON_SCREEN )
f03fc89f
VZ
426 {
427 // centre with respect to the whole screen
428 wxDisplaySize(&widthParent, &heightParent);
429 }
10fcf31a
VZ
430 else
431 {
f6bcfd97
BP
432 if ( IsTopLevel() )
433 {
434 // centre on the parent
435 parent->GetSize(&widthParent, &heightParent);
436
437 // adjust to the parents position
438 posParent = parent->GetPosition();
439 }
440 else
441 {
442 // centre inside the parents client rectangle
443 parent->GetClientSize(&widthParent, &heightParent);
444 }
10fcf31a 445 }
f03fc89f
VZ
446
447 int width, height;
448 GetSize(&width, &height);
449
c39eda94
VZ
450 int xNew = -1,
451 yNew = -1;
f03fc89f
VZ
452
453 if ( direction & wxHORIZONTAL )
c39eda94 454 xNew = (widthParent - width)/2;
f03fc89f
VZ
455
456 if ( direction & wxVERTICAL )
c39eda94 457 yNew = (heightParent - height)/2;
f03fc89f 458
f6bcfd97
BP
459 xNew += posParent.x;
460 yNew += posParent.y;
7631a292 461
ef397583
GT
462 // Base size of the visible dimensions of the display
463 // to take into account the taskbar
464 wxRect rect = wxGetClientDisplayRect();
465 wxSize size (rect.width,rect.height);
466
ede7020a
VS
467 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
468 // but it may mean that the window is placed on other than the main
469 // display. Therefore we only make sure centered window is on the main display
470 // if the parent is at least partially present here.
471 if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display
ef397583
GT
472 {
473 if (xNew < 0)
474 xNew = 0;
475 else if (xNew+width > size.x)
476 xNew = size.x-width-1;
477 }
ede7020a 478 if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display
ef397583
GT
479 {
480 if (yNew+height > size.y)
481 yNew = size.y-height-1;
482
483 // Make certain that the title bar is initially visible
484 // always, even if this would push the bottom of the
485 // dialog of the visible area of the display
486 if (yNew < 0)
487 yNew = 0;
488 }
489
0fff366e
VZ
490 // move the window to this position (keeping the old size but using
491 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
db89aa76 492 SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);
7631a292
RD
493}
494
f03fc89f
VZ
495// fits the window around the children
496void wxWindowBase::Fit()
497{
f68586e5
VZ
498 if ( GetChildren().GetCount() > 0 )
499 {
ec5bb70d 500 SetClientSize(DoGetBestSize());
f68586e5
VZ
501 }
502 //else: do nothing if we have no children
503}
f03fc89f 504
2b5f62a0
VZ
505// fits virtual size (ie. scrolled area etc.) around children
506void wxWindowBase::FitInside()
507{
508 if ( GetChildren().GetCount() > 0 )
509 {
510 SetVirtualSize( GetBestVirtualSize() );
511 }
512}
513
f68586e5
VZ
514// return the size best suited for the current window
515wxSize wxWindowBase::DoGetBestSize() const
516{
ec5bb70d
VZ
517 if ( m_windowSizer )
518 {
519 return m_windowSizer->GetMinSize();
520 }
521#if wxUSE_CONSTRAINTS
522 else if ( m_constraints )
523 {
524 wxConstCast(this, wxWindowBase)->SatisfyConstraints();
525
526 // our minimal acceptable size is such that all our windows fit inside
527 int maxX = 0,
528 maxY = 0;
529
530 for ( wxWindowList::Node *node = GetChildren().GetFirst();
531 node;
532 node = node->GetNext() )
533 {
534 wxLayoutConstraints *c = node->GetData()->GetConstraints();
535 if ( !c )
536 {
537 // it's not normal that we have an unconstrained child, but
538 // what can we do about it?
539 continue;
540 }
541
542 int x = c->right.GetValue(),
543 y = c->bottom.GetValue();
544
545 if ( x > maxX )
546 maxX = x;
547
548 if ( y > maxY )
549 maxY = y;
550
551 // TODO: we must calculate the overlaps somehow, otherwise we
552 // will never return a size bigger than the current one :-(
553 }
554
555 return wxSize(maxX, maxY);
556 }
557#endif // wxUSE_CONSTRAINTS
558 else if ( GetChildren().GetCount() > 0 )
f03fc89f 559 {
f68586e5
VZ
560 // our minimal acceptable size is such that all our windows fit inside
561 int maxX = 0,
562 maxY = 0;
563
564 for ( wxWindowList::Node *node = GetChildren().GetFirst();
565 node;
566 node = node->GetNext() )
42e69d6b 567 {
f68586e5 568 wxWindow *win = node->GetData();
1e6feb95
VZ
569 if ( win->IsTopLevel()
570#if wxUSE_STATUSBAR
571 || wxDynamicCast(win, wxStatusBar)
572#endif // wxUSE_STATUSBAR
573 )
f68586e5
VZ
574 {
575 // dialogs and frames lie in different top level windows -
7d9fd004
VZ
576 // don't deal with them here; as for the status bars, they
577 // don't lie in the client area at all
f68586e5
VZ
578 continue;
579 }
580
581 int wx, wy, ww, wh;
582 win->GetPosition(&wx, &wy);
3f5513f5
VZ
583
584 // if the window hadn't been positioned yet, assume that it is in
585 // the origin
586 if ( wx == -1 )
587 wx = 0;
588 if ( wy == -1 )
589 wy = 0;
590
f68586e5
VZ
591 win->GetSize(&ww, &wh);
592 if ( wx + ww > maxX )
593 maxX = wx + ww;
594 if ( wy + wh > maxY )
595 maxY = wy + wh;
42e69d6b
VZ
596 }
597
ec5bb70d
VZ
598 // for compatibility with the old versions and because it really looks
599 // slightly more pretty like this, add a pad
600 maxX += 7;
601 maxY += 14;
602
ba81034d 603 return wxSize(maxX, maxY);
f68586e5
VZ
604 }
605 else
606 {
607 // for a generic window there is no natural best size - just use the
608 // current one
609 return GetSize();
f03fc89f 610 }
f03fc89f
VZ
611}
612
1e6feb95
VZ
613// by default the origin is not shifted
614wxPoint wxWindowBase::GetClientAreaOrigin() const
615{
616 return wxPoint(0, 0);
617}
618
f03fc89f 619// set the min/max size of the window
f03fc89f
VZ
620void wxWindowBase::SetSizeHints(int minW, int minH,
621 int maxW, int maxH,
622 int WXUNUSED(incW), int WXUNUSED(incH))
623{
e587e144
VZ
624 // setting min width greater than max width leads to infinite loops under
625 // X11 and generally doesn't make any sense, so don't allow it
626 wxCHECK_RET( (minW == -1 || maxW == -1 || minW <= maxW) &&
77b0d411 627 (minH == -1 || maxH == -1 || minH <= maxH),
e587e144
VZ
628 _T("min width/height must be less than max width/height!") );
629
f03fc89f
VZ
630 m_minWidth = minW;
631 m_maxWidth = maxW;
632 m_minHeight = minH;
633 m_maxHeight = maxH;
634}
635
566d84a7
RL
636void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
637 int maxW, int maxH )
638{
639 m_minVirtualWidth = minW;
640 m_maxVirtualWidth = maxW;
641 m_minVirtualHeight = minH;
642 m_maxVirtualHeight = maxH;
566d84a7
RL
643}
644
645void wxWindowBase::DoSetVirtualSize( int x, int y )
646{
1e2a653b
VZ
647 if ( m_minVirtualWidth != -1 && m_minVirtualWidth > x )
648 x = m_minVirtualWidth;
649 if ( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x )
650 x = m_maxVirtualWidth;
651 if ( m_minVirtualHeight != -1 && m_minVirtualHeight > y )
652 y = m_minVirtualHeight;
653 if ( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y )
654 y = m_maxVirtualHeight;
655
656 m_virtualSize = wxSize(x, y);
566d84a7
RL
657}
658
659wxSize wxWindowBase::DoGetVirtualSize() const
660{
661 wxSize s( GetClientSize() );
662
150c8d89
RL
663 return wxSize( wxMax( m_virtualSize.GetWidth(), s.GetWidth() ),
664 wxMax( m_virtualSize.GetHeight(), s.GetHeight() ) );
566d84a7
RL
665}
666
f03fc89f
VZ
667// ----------------------------------------------------------------------------
668// show/hide/enable/disable the window
669// ----------------------------------------------------------------------------
670
671bool wxWindowBase::Show(bool show)
672{
673 if ( show != m_isShown )
674 {
675 m_isShown = show;
676
677 return TRUE;
678 }
679 else
680 {
681 return FALSE;
682 }
683}
684
685bool wxWindowBase::Enable(bool enable)
686{
687 if ( enable != m_isEnabled )
688 {
689 m_isEnabled = enable;
690
691 return TRUE;
692 }
693 else
694 {
695 return FALSE;
696 }
697}
34636400
VZ
698// ----------------------------------------------------------------------------
699// RTTI
700// ----------------------------------------------------------------------------
701
702bool wxWindowBase::IsTopLevel() const
703{
8487f887 704 return FALSE;
34636400 705}
f03fc89f
VZ
706
707// ----------------------------------------------------------------------------
708// reparenting the window
709// ----------------------------------------------------------------------------
710
711void wxWindowBase::AddChild(wxWindowBase *child)
712{
223d09f6 713 wxCHECK_RET( child, wxT("can't add a NULL child") );
f03fc89f 714
f6bcfd97
BP
715 // this should never happen and it will lead to a crash later if it does
716 // because RemoveChild() will remove only one node from the children list
717 // and the other(s) one(s) will be left with dangling pointers in them
718 wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") );
719
f03fc89f
VZ
720 GetChildren().Append(child);
721 child->SetParent(this);
722}
723
724void wxWindowBase::RemoveChild(wxWindowBase *child)
725{
223d09f6 726 wxCHECK_RET( child, wxT("can't remove a NULL child") );
f03fc89f
VZ
727
728 GetChildren().DeleteObject(child);
729 child->SetParent((wxWindow *)NULL);
730}
439b3bf1 731
f03fc89f
VZ
732bool wxWindowBase::Reparent(wxWindowBase *newParent)
733{
734 wxWindow *oldParent = GetParent();
735 if ( newParent == oldParent )
736 {
737 // nothing done
738 return FALSE;
739 }
740
741 // unlink this window from the existing parent.
742 if ( oldParent )
743 {
744 oldParent->RemoveChild(this);
745 }
746 else
747 {
748 wxTopLevelWindows.DeleteObject(this);
749 }
750
751 // add it to the new one
752 if ( newParent )
753 {
754 newParent->AddChild(this);
755 }
756 else
757 {
758 wxTopLevelWindows.Append(this);
759 }
760
761 return TRUE;
762}
763
764// ----------------------------------------------------------------------------
765// event handler stuff
766// ----------------------------------------------------------------------------
767
768void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
769{
3a074ba8
VZ
770 wxEvtHandler *handlerOld = GetEventHandler();
771
772 handler->SetNextHandler(handlerOld);
773
774 if ( handlerOld )
775 GetEventHandler()->SetPreviousHandler(handler);
776
f03fc89f
VZ
777 SetEventHandler(handler);
778}
779
780wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
781{
782 wxEvtHandler *handlerA = GetEventHandler();
783 if ( handlerA )
784 {
785 wxEvtHandler *handlerB = handlerA->GetNextHandler();
786 handlerA->SetNextHandler((wxEvtHandler *)NULL);
3a074ba8
VZ
787
788 if ( handlerB )
789 handlerB->SetPreviousHandler((wxEvtHandler *)NULL);
f03fc89f 790 SetEventHandler(handlerB);
3a074ba8 791
f03fc89f
VZ
792 if ( deleteHandler )
793 {
794 delete handlerA;
795 handlerA = (wxEvtHandler *)NULL;
796 }
797 }
798
799 return handlerA;
800}
801
2e36d5cf
VZ
802bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
803{
804 wxCHECK_MSG( handler, FALSE, _T("RemoveEventHandler(NULL) called") );
805
806 wxEvtHandler *handlerPrev = NULL,
807 *handlerCur = GetEventHandler();
808 while ( handlerCur )
809 {
810 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
811
812 if ( handlerCur == handler )
813 {
814 if ( handlerPrev )
815 {
816 handlerPrev->SetNextHandler(handlerNext);
817 }
818 else
819 {
820 SetEventHandler(handlerNext);
821 }
822
7a9c8d74
JS
823 if ( handlerNext )
824 {
825 handlerNext->SetPreviousHandler ( handlerPrev );
826 }
2e36d5cf
VZ
827 handler->SetNextHandler(NULL);
828
829 return TRUE;
830 }
831
832 handlerPrev = handlerCur;
833 handlerCur = handlerNext;
834 }
835
836 wxFAIL_MSG( _T("where has the event handler gone?") );
837
838 return FALSE;
839}
840
f03fc89f
VZ
841// ----------------------------------------------------------------------------
842// cursors, fonts &c
843// ----------------------------------------------------------------------------
844
845bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
846{
847 if ( !colour.Ok() || (colour == m_backgroundColour) )
848 return FALSE;
849
850 m_backgroundColour = colour;
851
23895080
VZ
852 m_hasBgCol = TRUE;
853
f03fc89f
VZ
854 return TRUE;
855}
856
857bool wxWindowBase::SetForegroundColour( const wxColour &colour )
858{
859 if ( !colour.Ok() || (colour == m_foregroundColour) )
860 return FALSE;
861
862 m_foregroundColour = colour;
863
23895080
VZ
864 m_hasFgCol = TRUE;
865
f03fc89f
VZ
866 return TRUE;
867}
868
869bool wxWindowBase::SetCursor(const wxCursor& cursor)
870{
8a9c2246
VZ
871 // setting an invalid cursor is ok, it means that we don't have any special
872 // cursor
13588544 873 if ( m_cursor == cursor )
f03fc89f
VZ
874 {
875 // no change
876 return FALSE;
877 }
878
8a9c2246 879 m_cursor = cursor;
f03fc89f
VZ
880
881 return TRUE;
882}
883
884bool wxWindowBase::SetFont(const wxFont& font)
885{
886 // don't try to set invalid font, always fall back to the default
887 const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT;
888
8bf30fe9 889 if ( fontOk == m_font )
f03fc89f
VZ
890 {
891 // no change
892 return FALSE;
893 }
894
895 m_font = fontOk;
896
23895080
VZ
897 m_hasFont = TRUE;
898
f03fc89f
VZ
899 return TRUE;
900}
901
b95edd47
VZ
902#if wxUSE_PALETTE
903
904void wxWindowBase::SetPalette(const wxPalette& pal)
905{
906 m_hasCustomPalette = TRUE;
907 m_palette = pal;
908
909 // VZ: can anyone explain me what do we do here?
910 wxWindowDC d((wxWindow *) this);
911 d.SetPalette(pal);
912}
913
914wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
915{
916 wxWindow *win = (wxWindow *)this;
917 while ( win && !win->HasCustomPalette() )
918 {
919 win = win->GetParent();
920 }
921
922 return win;
923}
924
925#endif // wxUSE_PALETTE
926
789295bf
VZ
927#if wxUSE_CARET
928void wxWindowBase::SetCaret(wxCaret *caret)
929{
930 if ( m_caret )
931 {
932 delete m_caret;
933 }
934
935 m_caret = caret;
936
937 if ( m_caret )
938 {
939 wxASSERT_MSG( m_caret->GetWindow() == this,
223d09f6 940 wxT("caret should be created associated to this window") );
789295bf
VZ
941 }
942}
943#endif // wxUSE_CARET
944
88ac883a 945#if wxUSE_VALIDATORS
f03fc89f
VZ
946// ----------------------------------------------------------------------------
947// validators
948// ----------------------------------------------------------------------------
949
950void wxWindowBase::SetValidator(const wxValidator& validator)
951{
952 if ( m_windowValidator )
953 delete m_windowValidator;
954
955 m_windowValidator = (wxValidator *)validator.Clone();
956
957 if ( m_windowValidator )
958 m_windowValidator->SetWindow(this) ;
959}
88ac883a 960#endif // wxUSE_VALIDATORS
f03fc89f
VZ
961
962// ----------------------------------------------------------------------------
1e6feb95 963// update region stuff
f03fc89f
VZ
964// ----------------------------------------------------------------------------
965
1e6feb95
VZ
966wxRect wxWindowBase::GetUpdateClientRect() const
967{
968 wxRegion rgnUpdate = GetUpdateRegion();
969 rgnUpdate.Intersect(GetClientRect());
970 wxRect rectUpdate = rgnUpdate.GetBox();
971 wxPoint ptOrigin = GetClientAreaOrigin();
972 rectUpdate.x -= ptOrigin.x;
973 rectUpdate.y -= ptOrigin.y;
974
975 return rectUpdate;
976}
977
f03fc89f
VZ
978bool wxWindowBase::IsExposed(int x, int y) const
979{
980 return m_updateRegion.Contains(x, y) != wxOutRegion;
981}
982
983bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
984{
985 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
986}
987
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;
998 wxWindowList::Node *node;
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;
1014 wxWindowList::Node *node;
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
1070 for ( wxWindowList::Node * node = parent->GetChildren().GetFirst();
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
1100 for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
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 {
1152 wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
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
f03fc89f
VZ
1169 wxWindowList::Node *node;
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
f03fc89f
VZ
1194 wxWindowList::Node *node;
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
f03fc89f
VZ
1228 wxWindowList::Node *node;
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;
1419 if ( !m_constraintsInvolvedIn->Find(otherWin) )
1420 m_constraintsInvolvedIn->Append(otherWin);
1421}
1422
1423// REMOVE back-pointer to other windows we're involved with.
1424void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1425{
1426 if ( m_constraintsInvolvedIn )
1427 m_constraintsInvolvedIn->DeleteObject(otherWin);
1428}
1429
1430// Reset any constraints that mention this window
1431void wxWindowBase::DeleteRelatedConstraints()
1432{
1433 if ( m_constraintsInvolvedIn )
1434 {
1435 wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst();
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
1454 wxWindowList::Node *next = node->GetNext();
1455 delete node;
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
1569 for ( wxWindowList::Node *node = GetChildren().GetFirst();
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
f03fc89f
VZ
1622 wxWindowList::Node *node = GetChildren().GetFirst();
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 {
1664 wxWindowList::Node *node = GetChildren().GetFirst();
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
VZ
1779
1780// TODO: should this be implemented for the child window rather
1781// than the parent? Then you can override it e.g. for wxCheckBox
1782// to do the Right Thing rather than having to assume a fixed number
1783// of control classes.
f03fc89f 1784void wxWindowBase::UpdateWindowUI()
7ec1983b 1785{
1e6feb95 1786#if wxUSE_CONTROLS
26bf1ce0
VZ
1787 wxUpdateUIEvent event(GetId());
1788 event.m_eventObject = this;
1789
1790 if ( GetEventHandler()->ProcessEvent(event) )
7ec1983b 1791 {
26bf1ce0
VZ
1792 if ( event.GetSetEnabled() )
1793 Enable(event.GetEnabled());
7ec1983b 1794
26bf1ce0 1795 if ( event.GetSetText() )
f03fc89f 1796 {
f7637829 1797 wxControl *control = wxDynamicCastThis(wxControl);
26bf1ce0 1798 if ( control )
34636400 1799 {
1e6feb95 1800#if wxUSE_TEXTCTRL
26bf1ce0
VZ
1801 wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
1802 if ( text )
2b5f62a0
VZ
1803 {
1804 if ( event.GetText() != text->GetValue() )
1805 text->SetValue(event.GetText());
1806 }
26bf1ce0 1807 else
1e6feb95 1808#endif // wxUSE_TEXTCTRL
2b5f62a0
VZ
1809 {
1810 if ( event.GetText() != control->GetLabel() )
1811 control->SetLabel(event.GetText());
1812 }
34636400 1813 }
26bf1ce0 1814 }
f03fc89f 1815
88ac883a 1816#if wxUSE_CHECKBOX
f7637829 1817 wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
26bf1ce0
VZ
1818 if ( checkbox )
1819 {
1820 if ( event.GetSetChecked() )
1821 checkbox->SetValue(event.GetChecked());
1822 }
88ac883a
VZ
1823#endif // wxUSE_CHECKBOX
1824
b3402d0d 1825#if wxUSE_RADIOBTN
f7637829 1826 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
26bf1ce0
VZ
1827 if ( radiobtn )
1828 {
1829 if ( event.GetSetChecked() )
1830 radiobtn->SetValue(event.GetChecked());
f03fc89f 1831 }
b3402d0d 1832#endif // wxUSE_RADIOBTN
7ec1983b 1833 }
1e6feb95 1834#endif // wxUSE_CONTROLS
7ec1983b 1835}
fd71308f 1836
f03fc89f
VZ
1837// ----------------------------------------------------------------------------
1838// dialog units translations
1839// ----------------------------------------------------------------------------
1840
1841wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
fd71308f
JS
1842{
1843 int charWidth = GetCharWidth();
1844 int charHeight = GetCharHeight();
5d9c2818
RD
1845 wxPoint pt2(-1, -1);
1846 if (pt.x != -1)
1847 pt2.x = (int) ((pt.x * 4) / charWidth) ;
1848 if (pt.y != -1)
1849 pt2.y = (int) ((pt.y * 8) / charHeight) ;
fd71308f
JS
1850
1851 return pt2;
1852}
1853
f03fc89f 1854wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
fd71308f
JS
1855{
1856 int charWidth = GetCharWidth();
1857 int charHeight = GetCharHeight();
5d9c2818
RD
1858 wxPoint pt2(-1, -1);
1859 if (pt.x != -1)
1860 pt2.x = (int) ((pt.x * charWidth) / 4) ;
1861 if (pt.y != -1)
1862 pt2.y = (int) ((pt.y * charHeight) / 8) ;
fd71308f
JS
1863
1864 return pt2;
1865}
1866
f03fc89f
VZ
1867// ----------------------------------------------------------------------------
1868// event handlers
1869// ----------------------------------------------------------------------------
1870
1871// propagate the colour change event to the subwindows
1872void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
1873{
1874 wxWindowList::Node *node = GetChildren().GetFirst();
1875 while ( node )
1876 {
1877 // Only propagate to non-top-level windows
1878 wxWindow *win = node->GetData();
1879 if ( !win->IsTopLevel() )
1880 {
1881 wxSysColourChangedEvent event2;
1882 event.m_eventObject = win;
1883 win->GetEventHandler()->ProcessEvent(event2);
1884 }
1885
1886 node = node->GetNext();
1887 }
1888}
1889
1890// the default action is to populate dialog with data when it's created
1891void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1892{
1893 TransferDataToWindow();
1894}
1895
a02dc3e3
VZ
1896// process Ctrl-Alt-mclick
1897void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1898{
1e6feb95 1899#if wxUSE_MSGDLG
a02dc3e3
VZ
1900 if ( event.ControlDown() && event.AltDown() )
1901 {
1902 // don't translate these strings
1903 wxString port;
af3062a8
VZ
1904
1905#ifdef __WXUNIVERSAL__
1906 port = _T("Univ/");
1907#endif // __WXUNIVERSAL__
1908
a02dc3e3
VZ
1909 switch ( wxGetOsVersion() )
1910 {
ea8e90b7 1911 case wxMOTIF_X: port += _T("Motif"); break;
ff8fda36 1912 case wxMAC:
ea8e90b7
VZ
1913 case wxMAC_DARWIN: port += _T("Mac"); break;
1914 case wxBEOS: port += _T("BeOS"); break;
a02dc3e3
VZ
1915 case wxGTK:
1916 case wxGTK_WIN32:
1917 case wxGTK_OS2:
ea8e90b7 1918 case wxGTK_BEOS: port += _T("GTK"); break;
a02dc3e3
VZ
1919 case wxWINDOWS:
1920 case wxPENWINDOWS:
1921 case wxWINDOWS_NT:
1922 case wxWIN32S:
1923 case wxWIN95:
ea8e90b7 1924 case wxWIN386: port += _T("MS Windows"); break;
a02dc3e3
VZ
1925 case wxMGL_UNIX:
1926 case wxMGL_X:
1927 case wxMGL_WIN32:
ea8e90b7 1928 case wxMGL_OS2: port += _T("MGL"); break;
a02dc3e3 1929 case wxWINDOWS_OS2:
ea8e90b7
VZ
1930 case wxOS2_PM: port += _T("OS/2"); break;
1931 default: port += _T("unknown"); break;
a02dc3e3
VZ
1932 }
1933
1934 wxMessageBox(wxString::Format(
1935 _T(
af3062a8 1936 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
a02dc3e3
VZ
1937 ),
1938 port.c_str(),
1939 wxMAJOR_VERSION,
1940 wxMINOR_VERSION,
1941 wxRELEASE_NUMBER,
3f562374
VZ
1942#if wxUSE_UNICODE
1943 L" (Unicode)",
1944#else
1945 "",
1946#endif
1947 __TDATE__,
1948 __TTIME__
a02dc3e3
VZ
1949 ),
1950 _T("wxWindows information"),
1951 wxICON_INFORMATION | wxOK,
1952 (wxWindow *)this);
1953 }
1954 else
1e6feb95 1955#endif // wxUSE_MSGDLG
a02dc3e3
VZ
1956 {
1957 event.Skip();
1958 }
1959}
1960
ed5317e5
JS
1961// ----------------------------------------------------------------------------
1962// accessibility
1963// ----------------------------------------------------------------------------
1964
1965#if wxUSE_ACCESSIBILITY
1966void wxWindowBase::SetAccessible(wxAccessible* accessible)
1967{
2aefc528 1968 if (m_accessible && (accessible != m_accessible))
ed5317e5
JS
1969 delete m_accessible;
1970 m_accessible = accessible;
1971 if (m_accessible)
1972 m_accessible->SetWindow((wxWindow*) this);
1973}
1974
1975// Returns the accessible object, creating if necessary.
1976wxAccessible* wxWindowBase::GetOrCreateAccessible()
1977{
1978 if (!m_accessible)
1979 m_accessible = CreateAccessible();
1980 return m_accessible;
1981}
1982
1983// Override to create a specific accessible object.
1984wxAccessible* wxWindowBase::CreateAccessible()
1985{
1986 return new wxWindowAccessible((wxWindow*) this);
1987}
1988
1989#endif
1990
f03fc89f
VZ
1991// ----------------------------------------------------------------------------
1992// list classes implementation
1993// ----------------------------------------------------------------------------
1994
1995void wxWindowListNode::DeleteData()
1996{
1997 delete (wxWindow *)GetData();
1998}
1999
1e6feb95
VZ
2000// ----------------------------------------------------------------------------
2001// borders
2002// ----------------------------------------------------------------------------
2003
2004wxBorder wxWindowBase::GetBorder() const
2005{
2006 wxBorder border = (wxBorder)(m_windowStyle & wxBORDER_MASK);
2007 if ( border == wxBORDER_DEFAULT )
2008 {
2009 border = GetDefaultBorder();
2010 }
2011
2012 return border;
2013}
2014
2015wxBorder wxWindowBase::GetDefaultBorder() const
2016{
2017 return wxBORDER_NONE;
2018}
2019
2020// ----------------------------------------------------------------------------
2021// hit testing
2022// ----------------------------------------------------------------------------
2023
2024wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2025{
2026 // here we just check if the point is inside the window or not
2027
2028 // check the top and left border first
2029 bool outside = x < 0 || y < 0;
2030 if ( !outside )
2031 {
2032 // check the right and bottom borders too
2033 wxSize size = GetSize();
2034 outside = x >= size.x || y >= size.y;
2035 }
2036
2037 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2038}
2039
94633ad9
VZ
2040// ----------------------------------------------------------------------------
2041// mouse capture
2042// ----------------------------------------------------------------------------
2043
2044struct WXDLLEXPORT wxWindowNext
2045{
2046 wxWindow *win;
2047 wxWindowNext *next;
786646f3 2048} *wxWindowBase::ms_winCaptureNext = NULL;
94633ad9 2049
a83e1475 2050void wxWindowBase::CaptureMouse()
94633ad9 2051{
7e555446 2052 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
45e0dc94 2053
94633ad9
VZ
2054 wxWindow *winOld = GetCapture();
2055 if ( winOld )
2056 {
df2f507b 2057 ((wxWindowBase*) winOld)->DoReleaseMouse();
edd802c6 2058
94633ad9
VZ
2059 // save it on stack
2060 wxWindowNext *item = new wxWindowNext;
2061 item->win = winOld;
2062 item->next = ms_winCaptureNext;
2063 ms_winCaptureNext = item;
2064 }
2065 //else: no mouse capture to save
2066
2067 DoCaptureMouse();
2068}
2069
a83e1475 2070void wxWindowBase::ReleaseMouse()
94633ad9 2071{
7e555446 2072 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
349d1942 2073
63fd5f0b 2074 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
a7b09001 2075
94633ad9
VZ
2076 DoReleaseMouse();
2077
2078 if ( ms_winCaptureNext )
2079 {
44f8caa7 2080 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
edd802c6 2081
94633ad9
VZ
2082 wxWindowNext *item = ms_winCaptureNext;
2083 ms_winCaptureNext = item->next;
2084 delete item;
2085 }
2086 //else: stack is empty, no previous capture
2087
2088 wxLogTrace(_T("mousecapture"),
7e555446 2089 _T("After ReleaseMouse() mouse is captured by %p"),
94633ad9
VZ
2090 GetCapture());
2091}
2092
7de59551
RD
2093
2094void wxWindowBase::SendDestroyEvent()
2095{
2096 wxWindowDestroyEvent event;
2097 event.SetEventObject(this);
2098 event.SetId(GetId());
2099 GetEventHandler()->ProcessEvent(event);
2100}
2101
33b494d6
VZ
2102// ----------------------------------------------------------------------------
2103// global functions
2104// ----------------------------------------------------------------------------
2105
2106wxWindow* wxGetTopLevelParent(wxWindow *win)
2107{
2108 while ( win && !win->IsTopLevel() )
2109 win = win->GetParent();
2110
2111 return win;
2112}
2113
ed5317e5
JS
2114#if wxUSE_ACCESSIBILITY
2115// ----------------------------------------------------------------------------
2116// accessible object for windows
2117// ----------------------------------------------------------------------------
2118
2119// Can return either a child object, or an integer
2120// representing the child element, starting from 1.
2121wxAccStatus wxWindowAccessible::HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject)
2122{
2123 wxASSERT( GetWindow() != NULL );
2124 if (!GetWindow())
2125 return wxACC_FAIL;
2126
2127 return wxACC_NOT_IMPLEMENTED;
2128}
2129
2130// Returns the rectangle for this object (id = 0) or a child element (id > 0).
2131wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2132{
2133 wxASSERT( GetWindow() != NULL );
2134 if (!GetWindow())
2135 return wxACC_FAIL;
2136
c6e2af45
JS
2137 wxWindow* win = NULL;
2138 if (elementId == 0)
2139 {
2140 win = GetWindow();
2141 }
2142 else
2143 {
2144 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2145 {
2146 win = (wxWindow*) GetWindow()->GetChildren().Nth(elementId-1)->GetData();
2147 }
2148 else
2149 return wxACC_FAIL;
2150 }
2151 if (win)
2152 {
2153 rect = win->GetRect();
2154 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2155 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2156 return wxACC_OK;
2157 }
2158
ed5317e5
JS
2159 return wxACC_NOT_IMPLEMENTED;
2160}
2161
2162// Navigates from fromId to toId/toObject.
2163wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
2164 int* toId, wxAccessible** toObject)
2165{
2166 wxASSERT( GetWindow() != NULL );
2167 if (!GetWindow())
2168 return wxACC_FAIL;
2169
c6e2af45
JS
2170 switch (navDir)
2171 {
2172 case wxNAVDIR_FIRSTCHILD:
2173 {
2174 if (GetWindow()->GetChildren().GetCount() == 0)
2175 return wxACC_FALSE;
2176 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2177 *toObject = childWindow->GetOrCreateAccessible();
2178
2179 return wxACC_OK;
2180 }
2181 case wxNAVDIR_LASTCHILD:
2182 {
2183 if (GetWindow()->GetChildren().GetCount() == 0)
2184 return wxACC_FALSE;
2185 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2186 *toObject = childWindow->GetOrCreateAccessible();
2187
2188 return wxACC_OK;
2189 }
2190 case wxNAVDIR_RIGHT:
2191 case wxNAVDIR_DOWN:
2192 case wxNAVDIR_NEXT:
2193 {
2194 wxWindowList::Node *node = NULL;
2195 if (fromId == 0)
2196 {
2197 // Can't navigate to sibling of this window
2198 // if we're a top-level window.
2199 if (!GetWindow()->GetParent())
2200 return wxACC_NOT_IMPLEMENTED;
2201
2202 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2203 }
2204 else
2205 {
2206 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2207 node = (wxWindowList::Node*) GetWindow()->GetChildren().Nth(fromId-1);
2208 }
2209
2210 if (node && node->GetNext())
2211 {
2212 wxWindow* nextWindow = (wxWindow*) node->GetNext()->Data();
2213 *toObject = nextWindow->GetOrCreateAccessible();
2214 return wxACC_OK;
2215 }
2216 else
2217 return wxACC_FALSE;
2218 }
2219 case wxNAVDIR_LEFT:
2220 case wxNAVDIR_UP:
2221 case wxNAVDIR_PREVIOUS:
2222 {
2223 wxWindowList::Node *node = NULL;
2224 if (fromId == 0)
2225 {
2226 // Can't navigate to sibling of this window
2227 // if we're a top-level window.
2228 if (!GetWindow()->GetParent())
2229 return wxACC_NOT_IMPLEMENTED;
2230
2231 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2232 }
2233 else
2234 {
2235 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2236 node = (wxWindowList::Node*) GetWindow()->GetChildren().Nth(fromId-1);
2237 }
2238
2239 if (node && node->GetPrevious())
2240 {
2241 wxWindow* previousWindow = (wxWindow*) node->GetPrevious()->Data();
2242 *toObject = previousWindow->GetOrCreateAccessible();
2243 return wxACC_OK;
2244 }
2245 else
2246 return wxACC_FALSE;
2247 }
2248 }
2249
ed5317e5
JS
2250 return wxACC_NOT_IMPLEMENTED;
2251}
2252
2253// Gets the name of the specified object.
2254wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2255{
2256 wxASSERT( GetWindow() != NULL );
2257 if (!GetWindow())
2258 return wxACC_FAIL;
2259
2aefc528
JS
2260 wxString title;
2261
2262 // If a child, leave wxWindows to call the function on the actual
2263 // child object.
2264 if (childId > 0)
2265 return wxACC_NOT_IMPLEMENTED;
2266
2267 // This will eventually be replaced by specialised
2268 // accessible classes, one for each kind of wxWindows
2269 // control or window.
2270 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2271 title = ((wxButton*) GetWindow())->GetLabel();
2272 else
2273 title = GetWindow()->GetName();
2274
ed5317e5
JS
2275 if (!title.IsEmpty())
2276 {
2277 *name = title;
2278 return wxACC_OK;
2279 }
2280 else
2281 return wxACC_NOT_IMPLEMENTED;
2282}
2283
2284// Gets the number of children.
2285wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2286{
2287 wxASSERT( GetWindow() != NULL );
2288 if (!GetWindow())
2289 return wxACC_FAIL;
2290
2291 *childId = (int) GetWindow()->GetChildren().GetCount();
2292 return wxACC_OK;
2293}
2294
2295// Gets the specified child (starting from 1).
2296// If *child is NULL and return value is wxACC_OK,
2297// this means that the child is a simple element and
2298// not an accessible object.
2299wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2300{
2301 wxASSERT( GetWindow() != NULL );
2302 if (!GetWindow())
2303 return wxACC_FAIL;
2304
2305 if (childId == 0)
2306 {
2307 *child = this;
2308 return wxACC_OK;
2309 }
2310
2311 if (childId > (int) GetWindow()->GetChildren().GetCount())
2312 return wxACC_FAIL;
2313
2314 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().Nth(childId-1)->GetData();
2315 *child = childWindow->GetOrCreateAccessible();
2316 if (*child)
2317 return wxACC_OK;
2318 else
2319 return wxACC_FAIL;
2320}
2321
2322// Gets the parent, or NULL.
2323wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2324{
2325 wxASSERT( GetWindow() != NULL );
2326 if (!GetWindow())
2327 return wxACC_FAIL;
2328
2329 wxWindow* parentWindow = GetWindow()->GetParent();
c6e2af45 2330 if (!parentWindow)
ed5317e5
JS
2331 {
2332 *parent = NULL;
2333 return wxACC_OK;
2334 }
2335 else
2336 {
2337 *parent = parentWindow->GetOrCreateAccessible();
2338 if (*parent)
2339 return wxACC_OK;
2340 else
2341 return wxACC_FAIL;
2342 }
2343}
2344
2345// Performs the default action. childId is 0 (the action for this object)
2346// or > 0 (the action for a child).
2347// Return wxACC_NOT_SUPPORTED if there is no default action for this
2348// window (e.g. an edit control).
2349wxAccStatus wxWindowAccessible::DoDefaultAction(int childId)
2350{
2351 wxASSERT( GetWindow() != NULL );
2352 if (!GetWindow())
2353 return wxACC_FAIL;
2354
2355 return wxACC_NOT_IMPLEMENTED;
2356}
2357
2358// Gets the default action for this object (0) or > 0 (the action for a child).
2359// Return wxACC_OK even if there is no action. actionName is the action, or the empty
2360// string if there is no action.
2361// The retrieved string describes the action that is performed on an object,
2362// not what the object does as a result. For example, a toolbar button that prints
2363// a document has a default action of "Press" rather than "Prints the current document."
2364wxAccStatus wxWindowAccessible::GetDefaultAction(int childId, wxString* actionName)
2365{
2366 wxASSERT( GetWindow() != NULL );
2367 if (!GetWindow())
2368 return wxACC_FAIL;
2369
2370 return wxACC_NOT_IMPLEMENTED;
2371}
2372
2373// Returns the description for this object or a child.
2374wxAccStatus wxWindowAccessible::GetDescription(int childId, wxString* description)
2375{
2376 wxASSERT( GetWindow() != NULL );
2377 if (!GetWindow())
2378 return wxACC_FAIL;
2379
2aefc528
JS
2380 wxString ht(GetWindow()->GetHelpText());
2381 if (!ht.IsEmpty())
2382 {
2383 *description = ht;
2384 return wxACC_OK;
2385 }
ed5317e5
JS
2386 return wxACC_NOT_IMPLEMENTED;
2387}
2388
2389// Returns help text for this object or a child, similar to tooltip text.
2390wxAccStatus wxWindowAccessible::GetHelpText(int childId, wxString* helpText)
2391{
2392 wxASSERT( GetWindow() != NULL );
2393 if (!GetWindow())
2394 return wxACC_FAIL;
2395
2396 wxString ht(GetWindow()->GetHelpText());
2397 if (!ht.IsEmpty())
2398 {
2399 *helpText = ht;
2400 return wxACC_OK;
2401 }
2402 return wxACC_NOT_IMPLEMENTED;
2403}
2404
2405// Returns the keyboard shortcut for this object or child.
2406// Return e.g. ALT+K
2407wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int childId, wxString* shortcut)
2408{
2409 wxASSERT( GetWindow() != NULL );
2410 if (!GetWindow())
2411 return wxACC_FAIL;
2412
2413 return wxACC_NOT_IMPLEMENTED;
2414}
2415
2416// Returns a role constant.
2417wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
2418{
2419 wxASSERT( GetWindow() != NULL );
2420 if (!GetWindow())
2421 return wxACC_FAIL;
2422
2aefc528
JS
2423 // If a child, leave wxWindows to call the function on the actual
2424 // child object.
2425 if (childId > 0)
2426 return wxACC_NOT_IMPLEMENTED;
2427
2428 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2429 return wxACC_NOT_IMPLEMENTED;
2430#if wxUSE_STATUSBAR
2431 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2432 return wxACC_NOT_IMPLEMENTED;
2433#endif
2434#if wxUSE_TOOLBAR
2435 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2436 return wxACC_NOT_IMPLEMENTED;
2437#endif
2438
2439 //*role = wxROLE_SYSTEM_CLIENT;
2440 *role = wxROLE_SYSTEM_CLIENT;
2441 return wxACC_OK;
2442
ed5317e5
JS
2443 return wxACC_NOT_IMPLEMENTED;
2444}
2445
2446// Returns a state constant.
2447wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
2448{
2449 wxASSERT( GetWindow() != NULL );
2450 if (!GetWindow())
2451 return wxACC_FAIL;
2452
2aefc528
JS
2453 // If a child, leave wxWindows to call the function on the actual
2454 // child object.
2455 if (childId > 0)
2456 return wxACC_NOT_IMPLEMENTED;
2457
2458 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2459 return wxACC_NOT_IMPLEMENTED;
2460
2461#if wxUSE_STATUSBAR
2462 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2463 return wxACC_NOT_IMPLEMENTED;
2464#endif
2465#if wxUSE_TOOLBAR
2466 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2467 return wxACC_NOT_IMPLEMENTED;
2468#endif
2469
2470 *state = 0;
2471 return wxACC_OK;
2472
ed5317e5
JS
2473 return wxACC_NOT_IMPLEMENTED;
2474}
2475
2476// Returns a localized string representing the value for the object
2477// or child.
2478wxAccStatus wxWindowAccessible::GetValue(int childId, wxString* strValue)
2479{
2480 wxASSERT( GetWindow() != NULL );
2481 if (!GetWindow())
2482 return wxACC_FAIL;
2483
2484 return wxACC_NOT_IMPLEMENTED;
2485}
2486
2487// Selects the object or child.
2488wxAccStatus wxWindowAccessible::Select(int childId, wxAccSelectionFlags selectFlags)
2489{
2490 wxASSERT( GetWindow() != NULL );
2491 if (!GetWindow())
2492 return wxACC_FAIL;
2493
2494 return wxACC_NOT_IMPLEMENTED;
2495}
2496
2497// Gets the window with the keyboard focus.
2498// If childId is 0 and child is NULL, no object in
2499// this subhierarchy has the focus.
2500// If this object has the focus, child should be 'this'.
2501wxAccStatus wxWindowAccessible::GetFocus(int* childId, wxAccessible** child)
2502{
2503 wxASSERT( GetWindow() != NULL );
2504 if (!GetWindow())
2505 return wxACC_FAIL;
2506
2507 return wxACC_NOT_IMPLEMENTED;
2508}
2509
2510// Gets a variant representing the selected children
2511// of this object.
2512// Acceptable values:
2513// - a null variant (IsNull() returns TRUE)
2514// - a list variant (GetType() == wxT("list")
2515// - an integer representing the selected child element,
2516// or 0 if this object is selected (GetType() == wxT("long")
2517// - a "void*" pointer to a wxAccessible child object
2518wxAccStatus wxWindowAccessible::GetSelections(wxVariant* selections)
2519{
2520 wxASSERT( GetWindow() != NULL );
2521 if (!GetWindow())
2522 return wxACC_FAIL;
2523
2524 return wxACC_NOT_IMPLEMENTED;
2525}
2526
2527#endif // wxUSE_ACCESSIBILITY