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