]> git.saurik.com Git - wxWidgets.git/blame - src/common/wincmn.cpp
Minor code tweeks to stop BCC compiler warnings
[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
7ec1983b
VZ
9// Licence: wxWindows license
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"
38 #include "wx/checkbox.h"
39 #include "wx/radiobut.h"
26bf1ce0 40 #include "wx/textctrl.h"
f03fc89f
VZ
41 #include "wx/settings.h"
42 #include "wx/dialog.h"
a02dc3e3 43 #include "wx/msgdlg.h"
a37a5a73 44 #include "wx/statusbr.h"
f03fc89f
VZ
45#endif //WX_PRECOMP
46
47#if wxUSE_CONSTRAINTS
48 #include "wx/layout.h"
3417c2cd 49 #include "wx/sizer.h"
f03fc89f
VZ
50#endif // wxUSE_CONSTRAINTS
51
52#if wxUSE_DRAG_AND_DROP
53 #include "wx/dnd.h"
54#endif // wxUSE_DRAG_AND_DROP
55
bd83cb56
VZ
56#if wxUSE_HELP
57 #include "wx/cshelp.h"
58#endif // wxUSE_HELP
59
f03fc89f
VZ
60#if wxUSE_TOOLTIPS
61 #include "wx/tooltip.h"
62#endif // wxUSE_TOOLTIPS
63
789295bf
VZ
64#if wxUSE_CARET
65 #include "wx/caret.h"
66#endif // wxUSE_CARET
67
f03fc89f
VZ
68// ----------------------------------------------------------------------------
69// static data
70// ----------------------------------------------------------------------------
71
42e69d6b 72int wxWindowBase::ms_lastControlId = -200;
f03fc89f
VZ
73
74IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
75
76// ----------------------------------------------------------------------------
77// event table
78// ----------------------------------------------------------------------------
79
80BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
81 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
82 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
a02dc3e3 83 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
bd83cb56
VZ
84
85#if wxUSE_HELP
86 EVT_HELP(-1, wxWindowBase::OnHelp)
87#endif // wxUSE_HELP
88
f03fc89f
VZ
89END_EVENT_TABLE()
90
91// ============================================================================
92// implementation of the common functionality of the wxWindow class
93// ============================================================================
94
95// ----------------------------------------------------------------------------
96// initialization
97// ----------------------------------------------------------------------------
98
99// the default initialization
100void wxWindowBase::InitBase()
101{
102 // no window yet, no parent nor children
f03fc89f
VZ
103 m_parent = (wxWindow *)NULL;
104 m_windowId = -1;
105 m_children.DeleteContents( FALSE ); // don't auto delete node data
106
107 // no constraints on the minimal window size
108 m_minWidth =
109 m_minHeight =
110 m_maxWidth =
111 m_maxHeight = -1;
112
113 // window is created enabled but it's not visible yet
114 m_isShown = FALSE;
115 m_isEnabled = TRUE;
116
8d99be5f 117 // no client data (yet)
f03fc89f 118 m_clientData = NULL;
8d99be5f 119 m_clientDataType = ClientData_None;
f03fc89f
VZ
120
121 // the default event handler is just this window
122 m_eventHandler = this;
123
88ac883a 124#if wxUSE_VALIDATORS
f03fc89f
VZ
125 // no validator
126 m_windowValidator = (wxValidator *) NULL;
88ac883a 127#endif // wxUSE_VALIDATORS
f03fc89f
VZ
128
129 // use the system default colours
807a903e 130 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE);
f6e4e9ea
JS
131 m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
132
8290d43d 133 // GRG, changed Mar/2000
807a903e
VZ
134 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
135
f03fc89f 136 // no style bits
d80cd92a 137 m_exStyle =
f03fc89f
VZ
138 m_windowStyle = 0;
139
140 // an optimization for the event processing: checking this flag is much
141 // faster than using IsKindOf(CLASSINFO(wxWindow))
142 m_isWindow = TRUE;
143
144#if wxUSE_CONSTRAINTS
145 // no constraints whatsoever
146 m_constraints = (wxLayoutConstraints *) NULL;
147 m_constraintsInvolvedIn = (wxWindowList *) NULL;
148 m_windowSizer = (wxSizer *) NULL;
f03fc89f
VZ
149 m_autoLayout = FALSE;
150#endif // wxUSE_CONSTRAINTS
151
152#if wxUSE_DRAG_AND_DROP
153 m_dropTarget = (wxDropTarget *)NULL;
154#endif // wxUSE_DRAG_AND_DROP
155
156#if wxUSE_TOOLTIPS
157 m_tooltip = (wxToolTip *)NULL;
158#endif // wxUSE_TOOLTIPS
789295bf
VZ
159
160#if wxUSE_CARET
161 m_caret = (wxCaret *)NULL;
162#endif // wxUSE_CARET
a2d93e73
JS
163
164 // Whether we're using the current theme for this window (wxGTK only for now)
165 m_themeEnabled = FALSE;
f03fc89f
VZ
166}
167
168// common part of window creation process
169bool wxWindowBase::CreateBase(wxWindowBase *parent,
170 wxWindowID id,
74e3313b
VZ
171 const wxPoint& WXUNUSED(pos),
172 const wxSize& WXUNUSED(size),
f03fc89f 173 long style,
8d99be5f 174 const wxValidator& validator,
f03fc89f
VZ
175 const wxString& name)
176{
177 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
178 // member variables - check that it has been called (will catch the case
179 // when a new ctor is added which doesn't call InitWindow)
223d09f6 180 wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") );
f03fc89f
VZ
181
182 // generate a new id if the user doesn't care about it
69418a8e 183 m_windowId = id == -1 ? NewControlId() : id;
f03fc89f
VZ
184
185 SetName(name);
186 SetWindowStyleFlag(style);
187 SetParent(parent);
674ac8b9
VZ
188
189#if wxUSE_VALIDATORS
8d99be5f 190 SetValidator(validator);
674ac8b9 191#endif // wxUSE_VALIDATORS
f03fc89f 192
8ae6ce07
VZ
193 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
194 // have it too - like this it's possible to set it only in the top level
195 // dialog/frame and all children will inherit it by defult
196 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
197 {
198 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
199 }
200
f03fc89f
VZ
201 return TRUE;
202}
203
204// ----------------------------------------------------------------------------
205// destruction
206// ----------------------------------------------------------------------------
207
208// common clean up
209wxWindowBase::~wxWindowBase()
210{
211 // FIXME if these 2 cases result from programming errors in the user code
212 // we should probably assert here instead of silently fixing them
213
214 // Just in case the window has been Closed, but we're then deleting
215 // immediately: don't leave dangling pointers.
216 wxPendingDelete.DeleteObject(this);
217
218 // Just in case we've loaded a top-level window via LoadNativeDialog but
219 // we weren't a dialog class
220 wxTopLevelWindows.DeleteObject(this);
a23fd0e1 221
223d09f6 222 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
f03fc89f 223
319fefa9
VZ
224 // make sure that there are no dangling pointers left pointing to us
225 wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
226 if ( panel )
227 {
228 if ( panel->GetLastFocus() == this )
229 {
230 panel->SetLastFocus((wxWindow *)NULL);
231 }
232 }
233
789295bf
VZ
234#if wxUSE_CARET
235 if ( m_caret )
236 delete m_caret;
237#endif // wxUSE_CARET
238
88ac883a 239#if wxUSE_VALIDATORS
f03fc89f
VZ
240 if ( m_windowValidator )
241 delete m_windowValidator;
88ac883a 242#endif // wxUSE_VALIDATORS
f03fc89f 243
6ccec5fc
VZ
244 // we only delete object data, not untyped
245 if ( m_clientDataType == ClientData_Object )
f03fc89f
VZ
246 delete m_clientObject;
247
248#if wxUSE_CONSTRAINTS
249 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
250 // at deleted windows as they delete themselves.
251 DeleteRelatedConstraints();
252
253 if ( m_constraints )
254 {
255 // This removes any dangling pointers to this window in other windows'
256 // constraintsInvolvedIn lists.
257 UnsetConstraints(m_constraints);
258 delete m_constraints;
259 m_constraints = NULL;
260 }
261
262 if ( m_windowSizer )
263 delete m_windowSizer;
264
f03fc89f
VZ
265#endif // wxUSE_CONSTRAINTS
266
267#if wxUSE_DRAG_AND_DROP
268 if ( m_dropTarget )
269 delete m_dropTarget;
270#endif // wxUSE_DRAG_AND_DROP
271
272#if wxUSE_TOOLTIPS
273 if ( m_tooltip )
274 delete m_tooltip;
275#endif // wxUSE_TOOLTIPS
276}
277
278bool wxWindowBase::Destroy()
279{
280 delete this;
281
282 return TRUE;
283}
284
285bool wxWindowBase::Close(bool force)
286{
287 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
288 event.SetEventObject(this);
289#if WXWIN_COMPATIBILITY
290 event.SetForce(force);
291#endif // WXWIN_COMPATIBILITY
292 event.SetCanVeto(!force);
293
294 // return FALSE if window wasn't closed because the application vetoed the
295 // close event
296 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
297}
298
299bool wxWindowBase::DestroyChildren()
300{
301 wxWindowList::Node *node;
a23fd0e1 302 for ( ;; )
f03fc89f 303 {
a23fd0e1
VZ
304 // we iterate until the list becomes empty
305 node = GetChildren().GetFirst();
306 if ( !node )
307 break;
308
f03fc89f 309 wxWindow *child = node->GetData();
a23fd0e1 310
223d09f6 311 wxASSERT_MSG( child, wxT("children list contains empty nodes") );
a23fd0e1 312
eb082a08 313 delete child;
a23fd0e1
VZ
314
315 wxASSERT_MSG( !GetChildren().Find(child),
223d09f6 316 wxT("child didn't remove itself using RemoveChild()") );
f03fc89f
VZ
317 }
318
319 return TRUE;
320}
321
322// ----------------------------------------------------------------------------
f68586e5 323// size/position related methods
f03fc89f
VZ
324// ----------------------------------------------------------------------------
325
326// centre the window with respect to its parent in either (or both) directions
327void wxWindowBase::Centre(int direction)
328{
f6bcfd97
BP
329 // the position/size of the parent window or of the entire screen
330 wxPoint posParent;
f03fc89f
VZ
331 int widthParent, heightParent;
332
f6bcfd97
BP
333 wxWindow *parent = NULL;
334
335 if ( !(direction & wxCENTRE_ON_SCREEN) )
f03fc89f 336 {
f6bcfd97
BP
337 // find the parent to centre this window on: it should be the
338 // immediate parent for the controls but the top level parent for the
339 // top level windows (like dialogs)
340 parent = GetParent();
341 if ( IsTopLevel() )
342 {
343 while ( parent && !parent->IsTopLevel() )
344 {
345 parent = parent->GetParent();
346 }
347 }
348
349 // did we find the parent?
350 if ( !parent )
351 {
352 // no other choice
353 direction |= wxCENTRE_ON_SCREEN;
354 }
f03fc89f 355 }
10fcf31a
VZ
356
357 if ( direction & wxCENTRE_ON_SCREEN )
f03fc89f
VZ
358 {
359 // centre with respect to the whole screen
360 wxDisplaySize(&widthParent, &heightParent);
361 }
10fcf31a
VZ
362 else
363 {
f6bcfd97
BP
364 if ( IsTopLevel() )
365 {
366 // centre on the parent
367 parent->GetSize(&widthParent, &heightParent);
368
369 // adjust to the parents position
370 posParent = parent->GetPosition();
371 }
372 else
373 {
374 // centre inside the parents client rectangle
375 parent->GetClientSize(&widthParent, &heightParent);
376 }
10fcf31a 377 }
f03fc89f
VZ
378
379 int width, height;
380 GetSize(&width, &height);
381
c39eda94
VZ
382 int xNew = -1,
383 yNew = -1;
f03fc89f
VZ
384
385 if ( direction & wxHORIZONTAL )
c39eda94 386 xNew = (widthParent - width)/2;
f03fc89f
VZ
387
388 if ( direction & wxVERTICAL )
c39eda94 389 yNew = (heightParent - height)/2;
f03fc89f 390
f6bcfd97
BP
391 xNew += posParent.x;
392 yNew += posParent.y;
7631a292 393
0fff366e
VZ
394 // move the window to this position (keeping the old size but using
395 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
db89aa76 396 SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);
7631a292
RD
397}
398
f03fc89f
VZ
399// fits the window around the children
400void wxWindowBase::Fit()
401{
f68586e5
VZ
402 if ( GetChildren().GetCount() > 0 )
403 {
ba81034d
VZ
404 wxSize size = DoGetBestSize();
405
406 // for compatibility with the old versions and because it really looks
407 // slightly more pretty like this, add a pad
408 size.x += 7;
409 size.y += 14;
410
411 SetClientSize(size);
f68586e5
VZ
412 }
413 //else: do nothing if we have no children
414}
f03fc89f 415
f68586e5
VZ
416// return the size best suited for the current window
417wxSize wxWindowBase::DoGetBestSize() const
418{
419 if ( GetChildren().GetCount() > 0 )
f03fc89f 420 {
f68586e5
VZ
421 // our minimal acceptable size is such that all our windows fit inside
422 int maxX = 0,
423 maxY = 0;
424
425 for ( wxWindowList::Node *node = GetChildren().GetFirst();
426 node;
427 node = node->GetNext() )
42e69d6b 428 {
f68586e5 429 wxWindow *win = node->GetData();
e63fdcd6 430 if ( win->IsTopLevel() || wxDynamicCast(win, wxStatusBar) || !win->IsShown())
f68586e5
VZ
431 {
432 // dialogs and frames lie in different top level windows -
7d9fd004
VZ
433 // don't deal with them here; as for the status bars, they
434 // don't lie in the client area at all
f68586e5
VZ
435 continue;
436 }
437
438 int wx, wy, ww, wh;
439 win->GetPosition(&wx, &wy);
3f5513f5
VZ
440
441 // if the window hadn't been positioned yet, assume that it is in
442 // the origin
443 if ( wx == -1 )
444 wx = 0;
445 if ( wy == -1 )
446 wy = 0;
447
f68586e5
VZ
448 win->GetSize(&ww, &wh);
449 if ( wx + ww > maxX )
450 maxX = wx + ww;
451 if ( wy + wh > maxY )
452 maxY = wy + wh;
42e69d6b
VZ
453 }
454
ba81034d 455 return wxSize(maxX, maxY);
f68586e5
VZ
456 }
457 else
458 {
459 // for a generic window there is no natural best size - just use the
460 // current one
461 return GetSize();
f03fc89f 462 }
f03fc89f
VZ
463}
464
465// set the min/max size of the window
f03fc89f
VZ
466void wxWindowBase::SetSizeHints(int minW, int minH,
467 int maxW, int maxH,
468 int WXUNUSED(incW), int WXUNUSED(incH))
469{
470 m_minWidth = minW;
471 m_maxWidth = maxW;
472 m_minHeight = minH;
473 m_maxHeight = maxH;
474}
475
476// ----------------------------------------------------------------------------
477// show/hide/enable/disable the window
478// ----------------------------------------------------------------------------
479
480bool wxWindowBase::Show(bool show)
481{
482 if ( show != m_isShown )
483 {
484 m_isShown = show;
485
486 return TRUE;
487 }
488 else
489 {
490 return FALSE;
491 }
492}
493
494bool wxWindowBase::Enable(bool enable)
495{
496 if ( enable != m_isEnabled )
497 {
498 m_isEnabled = enable;
499
500 return TRUE;
501 }
502 else
503 {
504 return FALSE;
505 }
506}
34636400
VZ
507// ----------------------------------------------------------------------------
508// RTTI
509// ----------------------------------------------------------------------------
510
511bool wxWindowBase::IsTopLevel() const
512{
8487f887 513 return FALSE;
34636400 514}
f03fc89f
VZ
515
516// ----------------------------------------------------------------------------
517// reparenting the window
518// ----------------------------------------------------------------------------
519
520void wxWindowBase::AddChild(wxWindowBase *child)
521{
223d09f6 522 wxCHECK_RET( child, wxT("can't add a NULL child") );
f03fc89f 523
f6bcfd97
BP
524 // this should never happen and it will lead to a crash later if it does
525 // because RemoveChild() will remove only one node from the children list
526 // and the other(s) one(s) will be left with dangling pointers in them
527 wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") );
528
f03fc89f
VZ
529 GetChildren().Append(child);
530 child->SetParent(this);
531}
532
533void wxWindowBase::RemoveChild(wxWindowBase *child)
534{
223d09f6 535 wxCHECK_RET( child, wxT("can't remove a NULL child") );
f03fc89f
VZ
536
537 GetChildren().DeleteObject(child);
538 child->SetParent((wxWindow *)NULL);
539}
439b3bf1 540
f03fc89f
VZ
541bool wxWindowBase::Reparent(wxWindowBase *newParent)
542{
543 wxWindow *oldParent = GetParent();
544 if ( newParent == oldParent )
545 {
546 // nothing done
547 return FALSE;
548 }
549
550 // unlink this window from the existing parent.
551 if ( oldParent )
552 {
553 oldParent->RemoveChild(this);
554 }
555 else
556 {
557 wxTopLevelWindows.DeleteObject(this);
558 }
559
560 // add it to the new one
561 if ( newParent )
562 {
563 newParent->AddChild(this);
564 }
565 else
566 {
567 wxTopLevelWindows.Append(this);
568 }
569
570 return TRUE;
571}
572
573// ----------------------------------------------------------------------------
574// event handler stuff
575// ----------------------------------------------------------------------------
576
577void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
578{
579 handler->SetNextHandler(GetEventHandler());
580 SetEventHandler(handler);
581}
582
583wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
584{
585 wxEvtHandler *handlerA = GetEventHandler();
586 if ( handlerA )
587 {
588 wxEvtHandler *handlerB = handlerA->GetNextHandler();
589 handlerA->SetNextHandler((wxEvtHandler *)NULL);
590 SetEventHandler(handlerB);
591 if ( deleteHandler )
592 {
593 delete handlerA;
594 handlerA = (wxEvtHandler *)NULL;
595 }
596 }
597
598 return handlerA;
599}
600
601// ----------------------------------------------------------------------------
602// cursors, fonts &c
603// ----------------------------------------------------------------------------
604
605bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
606{
607 if ( !colour.Ok() || (colour == m_backgroundColour) )
608 return FALSE;
609
610 m_backgroundColour = colour;
611
612 return TRUE;
613}
614
615bool wxWindowBase::SetForegroundColour( const wxColour &colour )
616{
617 if ( !colour.Ok() || (colour == m_foregroundColour) )
618 return FALSE;
619
620 m_foregroundColour = colour;
621
622 return TRUE;
623}
624
625bool wxWindowBase::SetCursor(const wxCursor& cursor)
626{
8a9c2246
VZ
627 // setting an invalid cursor is ok, it means that we don't have any special
628 // cursor
13588544 629 if ( m_cursor == cursor )
f03fc89f
VZ
630 {
631 // no change
632 return FALSE;
633 }
634
8a9c2246 635 m_cursor = cursor;
f03fc89f
VZ
636
637 return TRUE;
638}
639
640bool wxWindowBase::SetFont(const wxFont& font)
641{
642 // don't try to set invalid font, always fall back to the default
643 const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT;
644
913df6f2 645 if ( (wxFont&)fontOk == m_font )
f03fc89f
VZ
646 {
647 // no change
648 return FALSE;
649 }
650
651 m_font = fontOk;
652
653 return TRUE;
654}
655
789295bf
VZ
656#if wxUSE_CARET
657void wxWindowBase::SetCaret(wxCaret *caret)
658{
659 if ( m_caret )
660 {
661 delete m_caret;
662 }
663
664 m_caret = caret;
665
666 if ( m_caret )
667 {
668 wxASSERT_MSG( m_caret->GetWindow() == this,
223d09f6 669 wxT("caret should be created associated to this window") );
789295bf
VZ
670 }
671}
672#endif // wxUSE_CARET
673
88ac883a 674#if wxUSE_VALIDATORS
f03fc89f
VZ
675// ----------------------------------------------------------------------------
676// validators
677// ----------------------------------------------------------------------------
678
679void wxWindowBase::SetValidator(const wxValidator& validator)
680{
681 if ( m_windowValidator )
682 delete m_windowValidator;
683
684 m_windowValidator = (wxValidator *)validator.Clone();
685
686 if ( m_windowValidator )
687 m_windowValidator->SetWindow(this) ;
688}
88ac883a 689#endif // wxUSE_VALIDATORS
f03fc89f
VZ
690
691// ----------------------------------------------------------------------------
692// update region testing
693// ----------------------------------------------------------------------------
694
695bool wxWindowBase::IsExposed(int x, int y) const
696{
697 return m_updateRegion.Contains(x, y) != wxOutRegion;
698}
699
700bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
701{
702 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
703}
704
705// ----------------------------------------------------------------------------
706// find window by id or name
707// ----------------------------------------------------------------------------
708
709wxWindow *wxWindowBase::FindWindow( long id )
710{
711 if ( id == m_windowId )
712 return (wxWindow *)this;
713
714 wxWindowBase *res = (wxWindow *)NULL;
715 wxWindowList::Node *node;
716 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
717 {
718 wxWindowBase *child = node->GetData();
719 res = child->FindWindow( id );
720 }
721
722 return (wxWindow *)res;
723}
724
725wxWindow *wxWindowBase::FindWindow( const wxString& name )
726{
727 if ( name == m_windowName )
728 return (wxWindow *)this;
729
730 wxWindowBase *res = (wxWindow *)NULL;
731 wxWindowList::Node *node;
732 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
733 {
734 wxWindow *child = node->GetData();
735 res = child->FindWindow(name);
736 }
737
738 return (wxWindow *)res;
739}
740
741// ----------------------------------------------------------------------------
742// dialog oriented functions
743// ----------------------------------------------------------------------------
744
34636400 745void wxWindowBase::MakeModal(bool modal)
f03fc89f 746{
34636400
VZ
747 // Disable all other windows
748 if ( IsTopLevel() )
749 {
750 wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
751 while (node)
752 {
753 wxWindow *win = node->GetData();
754 if (win != this)
755 win->Enable(!modal);
756
757 node = node->GetNext();
758 }
759 }
f03fc89f
VZ
760}
761
762bool wxWindowBase::Validate()
763{
88ac883a 764#if wxUSE_VALIDATORS
d80cd92a
VZ
765 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
766
f03fc89f
VZ
767 wxWindowList::Node *node;
768 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
769 {
770 wxWindowBase *child = node->GetData();
771 wxValidator *validator = child->GetValidator();
dcd6b914 772 if ( validator && !validator->Validate((wxWindow *)this) )
f03fc89f
VZ
773 {
774 return FALSE;
775 }
d80cd92a
VZ
776
777 if ( recurse && !child->Validate() )
778 {
779 return FALSE;
780 }
f03fc89f 781 }
88ac883a 782#endif // wxUSE_VALIDATORS
f03fc89f
VZ
783
784 return TRUE;
785}
786
787bool wxWindowBase::TransferDataToWindow()
788{
88ac883a 789#if wxUSE_VALIDATORS
d80cd92a
VZ
790 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
791
f03fc89f
VZ
792 wxWindowList::Node *node;
793 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
794 {
795 wxWindowBase *child = node->GetData();
796 wxValidator *validator = child->GetValidator();
797 if ( validator && !validator->TransferToWindow() )
798 {
d80cd92a
VZ
799 wxLogWarning(_("Could not transfer data to window"));
800 wxLog::FlushActive();
f03fc89f
VZ
801
802 return FALSE;
803 }
d80cd92a
VZ
804
805 if ( recurse )
806 {
a58a12e9 807 if ( !child->TransferDataToWindow() )
d80cd92a
VZ
808 {
809 // warning already given
810 return FALSE;
811 }
812 }
f03fc89f 813 }
88ac883a 814#endif // wxUSE_VALIDATORS
f03fc89f
VZ
815
816 return TRUE;
817}
818
819bool wxWindowBase::TransferDataFromWindow()
820{
88ac883a 821#if wxUSE_VALIDATORS
d80cd92a
VZ
822 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
823
f03fc89f
VZ
824 wxWindowList::Node *node;
825 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
826 {
827 wxWindow *child = node->GetData();
d80cd92a
VZ
828 wxValidator *validator = child->GetValidator();
829 if ( validator && !validator->TransferFromWindow() )
f03fc89f 830 {
d80cd92a
VZ
831 // nop warning here because the application is supposed to give
832 // one itself - we don't know here what might have gone wrongly
833
f03fc89f
VZ
834 return FALSE;
835 }
d80cd92a
VZ
836
837 if ( recurse )
838 {
a58a12e9 839 if ( !child->TransferDataFromWindow() )
d80cd92a
VZ
840 {
841 // warning already given
842 return FALSE;
843 }
844 }
f03fc89f 845 }
88ac883a 846#endif // wxUSE_VALIDATORS
f03fc89f
VZ
847
848 return TRUE;
849}
850
851void wxWindowBase::InitDialog()
852{
853 wxInitDialogEvent event(GetId());
854 event.SetEventObject( this );
855 GetEventHandler()->ProcessEvent(event);
856}
857
858// ----------------------------------------------------------------------------
bd83cb56
VZ
859// context-sensitive help support
860// ----------------------------------------------------------------------------
861
862#if wxUSE_HELP
863
864// associate this help text with this window
865void wxWindowBase::SetHelpText(const wxString& text)
866{
867 wxHelpProvider *helpProvider = wxHelpProvider::Get();
868 if ( helpProvider )
869 {
870 helpProvider->AddHelp(this, text);
871 }
872}
873
874// associate this help text with all windows with the same id as this
875// one
876void wxWindowBase::SetHelpTextForId(const wxString& text)
877{
878 wxHelpProvider *helpProvider = wxHelpProvider::Get();
879 if ( helpProvider )
880 {
881 helpProvider->AddHelp(GetId(), text);
882 }
883}
884
885// get the help string associated with this window (may be empty)
886wxString wxWindowBase::GetHelpText() const
887{
888 wxString text;
889 wxHelpProvider *helpProvider = wxHelpProvider::Get();
890 if ( helpProvider )
891 {
892 text = helpProvider->GetHelp(this);
893 }
894
895 return text;
896}
897
898// show help for this window
899void wxWindowBase::OnHelp(wxHelpEvent& event)
900{
901 wxHelpProvider *helpProvider = wxHelpProvider::Get();
902 if ( helpProvider )
903 {
904 if ( helpProvider->ShowHelp(this) )
905 {
906 // skip the event.Skip() below
907 return;
908 }
909 }
910
911 event.Skip();
912}
913
914#endif // wxUSE_HELP
915
916// ----------------------------------------------------------------------------
f03fc89f
VZ
917// tooltips
918// ----------------------------------------------------------------------------
919
920#if wxUSE_TOOLTIPS
921
922void wxWindowBase::SetToolTip( const wxString &tip )
923{
924 // don't create the new tooltip if we already have one
925 if ( m_tooltip )
926 {
927 m_tooltip->SetTip( tip );
928 }
929 else
930 {
931 SetToolTip( new wxToolTip( tip ) );
932 }
933
934 // setting empty tooltip text does not remove the tooltip any more - use
935 // SetToolTip((wxToolTip *)NULL) for this
936}
937
938void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
939{
940 if ( m_tooltip )
941 delete m_tooltip;
942
943 m_tooltip = tooltip;
944}
945
946#endif // wxUSE_TOOLTIPS
947
948// ----------------------------------------------------------------------------
949// constraints and sizers
950// ----------------------------------------------------------------------------
951
952#if wxUSE_CONSTRAINTS
953
954void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
955{
956 if ( m_constraints )
957 {
958 UnsetConstraints(m_constraints);
959 delete m_constraints;
960 }
961 m_constraints = constraints;
962 if ( m_constraints )
963 {
964 // Make sure other windows know they're part of a 'meaningful relationship'
965 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
966 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
967 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
968 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
969 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
970 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
971 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
972 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
973 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
974 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
975 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
976 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
977 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
978 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
979 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
980 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
981 }
982}
983
984// This removes any dangling pointers to this window in other windows'
985// constraintsInvolvedIn lists.
986void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
987{
988 if ( c )
989 {
990 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
991 c->left.GetOtherWindow()->RemoveConstraintReference(this);
992 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
993 c->top.GetOtherWindow()->RemoveConstraintReference(this);
994 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
995 c->right.GetOtherWindow()->RemoveConstraintReference(this);
996 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
997 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
998 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
999 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1000 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1001 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1002 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1003 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1004 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1005 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1006 }
1007}
1008
1009// Back-pointer to other windows we're involved with, so if we delete this
1010// window, we must delete any constraints we're involved with.
1011void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1012{
1013 if ( !m_constraintsInvolvedIn )
1014 m_constraintsInvolvedIn = new wxWindowList;
1015 if ( !m_constraintsInvolvedIn->Find(otherWin) )
1016 m_constraintsInvolvedIn->Append(otherWin);
1017}
1018
1019// REMOVE back-pointer to other windows we're involved with.
1020void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1021{
1022 if ( m_constraintsInvolvedIn )
1023 m_constraintsInvolvedIn->DeleteObject(otherWin);
1024}
1025
1026// Reset any constraints that mention this window
1027void wxWindowBase::DeleteRelatedConstraints()
1028{
1029 if ( m_constraintsInvolvedIn )
1030 {
1031 wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst();
1032 while (node)
1033 {
1034 wxWindow *win = node->GetData();
1035 wxLayoutConstraints *constr = win->GetConstraints();
1036
1037 // Reset any constraints involving this window
1038 if ( constr )
1039 {
1040 constr->left.ResetIfWin(this);
1041 constr->top.ResetIfWin(this);
1042 constr->right.ResetIfWin(this);
1043 constr->bottom.ResetIfWin(this);
1044 constr->width.ResetIfWin(this);
1045 constr->height.ResetIfWin(this);
1046 constr->centreX.ResetIfWin(this);
1047 constr->centreY.ResetIfWin(this);
1048 }
1049
1050 wxWindowList::Node *next = node->GetNext();
1051 delete node;
1052 node = next;
1053 }
1054
1055 delete m_constraintsInvolvedIn;
1056 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1057 }
1058}
1059
1060void wxWindowBase::SetSizer(wxSizer *sizer)
1061{
3417c2cd
RR
1062 if (m_windowSizer) delete m_windowSizer;
1063
f03fc89f 1064 m_windowSizer = sizer;
f03fc89f
VZ
1065}
1066
1067bool wxWindowBase::Layout()
1068{
3417c2cd 1069 // If there is a sizer, use it instead of the constraints
f03fc89f
VZ
1070 if ( GetSizer() )
1071 {
f1df0927
VZ
1072 int w, h;
1073 GetClientSize(&w, &h);
1074
3417c2cd 1075 GetSizer()->SetDimension( 0, 0, w, h );
f03fc89f 1076 }
f1df0927 1077 else
f03fc89f 1078 {
4b7f2165
VZ
1079 wxLayoutConstraints *constr = GetConstraints();
1080 bool wasOk = constr && constr->AreSatisfied();
1081
f1df0927 1082 ResetConstraints(); // Mark all constraints as unevaluated
4b7f2165
VZ
1083
1084 // if we're a top level panel (i.e. our parent is frame/dialog), our
1085 // own constraints will never be satisfied any more unless we do it
1086 // here
1087 if ( wasOk )
1088 {
1089 int noChanges = 1;
1090 while ( noChanges > 0 )
1091 {
1092 constr->SatisfyConstraints(this, &noChanges);
1093 }
1094 }
1095
1096 DoPhase(1); // Layout children
1097 DoPhase(2); // Layout grand children
f1df0927 1098 SetConstraintSizes(); // Recursively set the real window sizes
f03fc89f 1099 }
5d4b632b 1100
f03fc89f
VZ
1101 return TRUE;
1102}
1103
1104
1105// Do a phase of evaluating constraints: the default behaviour. wxSizers may
1106// do a similar thing, but also impose their own 'constraints' and order the
1107// evaluation differently.
1108bool wxWindowBase::LayoutPhase1(int *noChanges)
1109{
1110 wxLayoutConstraints *constr = GetConstraints();
1111 if ( constr )
1112 {
1113 return constr->SatisfyConstraints(this, noChanges);
1114 }
1115 else
1116 return TRUE;
1117}
1118
1119bool wxWindowBase::LayoutPhase2(int *noChanges)
1120{
1121 *noChanges = 0;
1122
1123 // Layout children
1124 DoPhase(1);
1125 DoPhase(2);
1126 return TRUE;
1127}
1128
1129// Do a phase of evaluating child constraints
1130bool wxWindowBase::DoPhase(int phase)
1131{
1132 int noIterations = 0;
1133 int maxIterations = 500;
1134 int noChanges = 1;
1135 int noFailures = 0;
1136 wxWindowList succeeded;
1137 while ((noChanges > 0) && (noIterations < maxIterations))
1138 {
1139 noChanges = 0;
1140 noFailures = 0;
1141 wxWindowList::Node *node = GetChildren().GetFirst();
1142 while (node)
1143 {
1144 wxWindow *child = node->GetData();
34636400 1145 if ( !child->IsTopLevel() )
f03fc89f
VZ
1146 {
1147 wxLayoutConstraints *constr = child->GetConstraints();
1148 if ( constr )
1149 {
1150 if ( !succeeded.Find(child) )
1151 {
1152 int tempNoChanges = 0;
1153 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
1154 noChanges += tempNoChanges;
1155 if ( success )
1156 {
1157 succeeded.Append(child);
1158 }
1159 }
1160 }
1161 }
1162 node = node->GetNext();
1163 }
1164
1165 noIterations++;
1166 }
1167
1168 return TRUE;
1169}
1170
1171void wxWindowBase::ResetConstraints()
1172{
1173 wxLayoutConstraints *constr = GetConstraints();
1174 if ( constr )
1175 {
1176 constr->left.SetDone(FALSE);
1177 constr->top.SetDone(FALSE);
1178 constr->right.SetDone(FALSE);
1179 constr->bottom.SetDone(FALSE);
1180 constr->width.SetDone(FALSE);
1181 constr->height.SetDone(FALSE);
1182 constr->centreX.SetDone(FALSE);
1183 constr->centreY.SetDone(FALSE);
1184 }
f1df0927 1185
f03fc89f
VZ
1186 wxWindowList::Node *node = GetChildren().GetFirst();
1187 while (node)
1188 {
1189 wxWindow *win = node->GetData();
34636400 1190 if ( !win->IsTopLevel() )
f03fc89f
VZ
1191 win->ResetConstraints();
1192 node = node->GetNext();
1193 }
1194}
1195
1196// Need to distinguish between setting the 'fake' size for windows and sizers,
1197// and setting the real values.
1198void wxWindowBase::SetConstraintSizes(bool recurse)
1199{
1200 wxLayoutConstraints *constr = GetConstraints();
4b7f2165 1201 if ( constr && constr->AreSatisfied() )
f03fc89f
VZ
1202 {
1203 int x = constr->left.GetValue();
1204 int y = constr->top.GetValue();
1205 int w = constr->width.GetValue();
1206 int h = constr->height.GetValue();
1207
f03fc89f 1208 if ( (constr->width.GetRelationship() != wxAsIs ) ||
3417c2cd 1209 (constr->height.GetRelationship() != wxAsIs) )
f03fc89f 1210 {
3417c2cd 1211 SetSize(x, y, w, h);
f03fc89f
VZ
1212 }
1213 else
1214 {
3417c2cd
RR
1215 // If we don't want to resize this window, just move it...
1216 Move(x, y);
f03fc89f
VZ
1217 }
1218 }
1219 else if ( constr )
1220 {
4b7f2165 1221 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
f1df0927 1222 GetClassInfo()->GetClassName(),
4b7f2165 1223 GetName().c_str());
f03fc89f
VZ
1224 }
1225
1226 if ( recurse )
1227 {
1228 wxWindowList::Node *node = GetChildren().GetFirst();
1229 while (node)
1230 {
1231 wxWindow *win = node->GetData();
34636400 1232 if ( !win->IsTopLevel() )
f03fc89f
VZ
1233 win->SetConstraintSizes();
1234 node = node->GetNext();
1235 }
1236 }
1237}
1238
f03fc89f
VZ
1239// Only set the size/position of the constraint (if any)
1240void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1241{
1242 wxLayoutConstraints *constr = GetConstraints();
1243 if ( constr )
1244 {
1245 if ( x != -1 )
1246 {
1247 constr->left.SetValue(x);
1248 constr->left.SetDone(TRUE);
1249 }
1250 if ( y != -1 )
1251 {
1252 constr->top.SetValue(y);
1253 constr->top.SetDone(TRUE);
1254 }
1255 if ( w != -1 )
1256 {
1257 constr->width.SetValue(w);
1258 constr->width.SetDone(TRUE);
1259 }
1260 if ( h != -1 )
1261 {
1262 constr->height.SetValue(h);
1263 constr->height.SetDone(TRUE);
1264 }
1265 }
1266}
1267
1268void wxWindowBase::MoveConstraint(int x, int y)
1269{
1270 wxLayoutConstraints *constr = GetConstraints();
1271 if ( constr )
1272 {
1273 if ( x != -1 )
1274 {
1275 constr->left.SetValue(x);
1276 constr->left.SetDone(TRUE);
1277 }
1278 if ( y != -1 )
1279 {
1280 constr->top.SetValue(y);
1281 constr->top.SetDone(TRUE);
1282 }
1283 }
1284}
1285
1286void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1287{
1288 wxLayoutConstraints *constr = GetConstraints();
1289 if ( constr )
1290 {
1291 *w = constr->width.GetValue();
1292 *h = constr->height.GetValue();
1293 }
1294 else
1295 GetSize(w, h);
1296}
1297
1298void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1299{
1300 wxLayoutConstraints *constr = GetConstraints();
1301 if ( constr )
1302 {
1303 *w = constr->width.GetValue();
1304 *h = constr->height.GetValue();
1305 }
1306 else
1307 GetClientSize(w, h);
1308}
1309
1310void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1311{
1312 wxLayoutConstraints *constr = GetConstraints();
1313 if ( constr )
1314 {
1315 *x = constr->left.GetValue();
1316 *y = constr->top.GetValue();
1317 }
1318 else
1319 GetPosition(x, y);
1320}
1321
1322#endif // wxUSE_CONSTRAINTS
1323
1324// ----------------------------------------------------------------------------
1325// do Update UI processing for child controls
1326// ----------------------------------------------------------------------------
7ec1983b
VZ
1327
1328// TODO: should this be implemented for the child window rather
1329// than the parent? Then you can override it e.g. for wxCheckBox
1330// to do the Right Thing rather than having to assume a fixed number
1331// of control classes.
f03fc89f 1332void wxWindowBase::UpdateWindowUI()
7ec1983b 1333{
26bf1ce0
VZ
1334 wxUpdateUIEvent event(GetId());
1335 event.m_eventObject = this;
1336
1337 if ( GetEventHandler()->ProcessEvent(event) )
7ec1983b 1338 {
26bf1ce0
VZ
1339 if ( event.GetSetEnabled() )
1340 Enable(event.GetEnabled());
7ec1983b 1341
26bf1ce0 1342 if ( event.GetSetText() )
f03fc89f 1343 {
26bf1ce0
VZ
1344 wxControl *control = wxDynamicCast(this, wxControl);
1345 if ( control )
34636400 1346 {
26bf1ce0
VZ
1347 wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
1348 if ( text )
1349 text->SetValue(event.GetText());
1350 else
34636400
VZ
1351 control->SetLabel(event.GetText());
1352 }
26bf1ce0 1353 }
f03fc89f 1354
88ac883a 1355#if wxUSE_CHECKBOX
26bf1ce0
VZ
1356 wxCheckBox *checkbox = wxDynamicCast(this, wxCheckBox);
1357 if ( checkbox )
1358 {
1359 if ( event.GetSetChecked() )
1360 checkbox->SetValue(event.GetChecked());
1361 }
88ac883a
VZ
1362#endif // wxUSE_CHECKBOX
1363
b3402d0d 1364#if wxUSE_RADIOBTN
26bf1ce0
VZ
1365 wxRadioButton *radiobtn = wxDynamicCast(this, wxRadioButton);
1366 if ( radiobtn )
1367 {
1368 if ( event.GetSetChecked() )
1369 radiobtn->SetValue(event.GetChecked());
f03fc89f 1370 }
b3402d0d 1371#endif // wxUSE_RADIOBTN
7ec1983b 1372 }
7ec1983b 1373}
fd71308f 1374
f03fc89f
VZ
1375// ----------------------------------------------------------------------------
1376// dialog units translations
1377// ----------------------------------------------------------------------------
1378
1379wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
fd71308f
JS
1380{
1381 int charWidth = GetCharWidth();
1382 int charHeight = GetCharHeight();
5d9c2818
RD
1383 wxPoint pt2(-1, -1);
1384 if (pt.x != -1)
1385 pt2.x = (int) ((pt.x * 4) / charWidth) ;
1386 if (pt.y != -1)
1387 pt2.y = (int) ((pt.y * 8) / charHeight) ;
fd71308f
JS
1388
1389 return pt2;
1390}
1391
f03fc89f 1392wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
fd71308f
JS
1393{
1394 int charWidth = GetCharWidth();
1395 int charHeight = GetCharHeight();
5d9c2818
RD
1396 wxPoint pt2(-1, -1);
1397 if (pt.x != -1)
1398 pt2.x = (int) ((pt.x * charWidth) / 4) ;
1399 if (pt.y != -1)
1400 pt2.y = (int) ((pt.y * charHeight) / 8) ;
fd71308f
JS
1401
1402 return pt2;
1403}
1404
8d99be5f
VZ
1405// ----------------------------------------------------------------------------
1406// client data
1407// ----------------------------------------------------------------------------
1408
1409void wxWindowBase::DoSetClientObject( wxClientData *data )
1410{
1411 wxASSERT_MSG( m_clientDataType != ClientData_Void,
223d09f6 1412 wxT("can't have both object and void client data") );
8d99be5f
VZ
1413
1414 if ( m_clientObject )
1415 delete m_clientObject;
1416
1417 m_clientObject = data;
1418 m_clientDataType = ClientData_Object;
1419}
1420
1421wxClientData *wxWindowBase::DoGetClientObject() const
1422{
0d7ea902
VZ
1423 // it's not an error to call GetClientObject() on a window which doesn't
1424 // have client data at all - NULL will be returned
1425 wxASSERT_MSG( m_clientDataType != ClientData_Void,
223d09f6 1426 wxT("this window doesn't have object client data") );
8d99be5f
VZ
1427
1428 return m_clientObject;
1429}
1430
1431void wxWindowBase::DoSetClientData( void *data )
1432{
1433 wxASSERT_MSG( m_clientDataType != ClientData_Object,
223d09f6 1434 wxT("can't have both object and void client data") );
8d99be5f
VZ
1435
1436 m_clientData = data;
1437 m_clientDataType = ClientData_Void;
1438}
1439
1440void *wxWindowBase::DoGetClientData() const
1441{
0d7ea902
VZ
1442 // it's not an error to call GetClientData() on a window which doesn't have
1443 // client data at all - NULL will be returned
1444 wxASSERT_MSG( m_clientDataType != ClientData_Object,
223d09f6 1445 wxT("this window doesn't have void client data") );
8d99be5f
VZ
1446
1447 return m_clientData;
1448}
1449
f03fc89f
VZ
1450// ----------------------------------------------------------------------------
1451// event handlers
1452// ----------------------------------------------------------------------------
1453
1454// propagate the colour change event to the subwindows
1455void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
1456{
1457 wxWindowList::Node *node = GetChildren().GetFirst();
1458 while ( node )
1459 {
1460 // Only propagate to non-top-level windows
1461 wxWindow *win = node->GetData();
1462 if ( !win->IsTopLevel() )
1463 {
1464 wxSysColourChangedEvent event2;
1465 event.m_eventObject = win;
1466 win->GetEventHandler()->ProcessEvent(event2);
1467 }
1468
1469 node = node->GetNext();
1470 }
1471}
1472
1473// the default action is to populate dialog with data when it's created
1474void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1475{
1476 TransferDataToWindow();
1477}
1478
a02dc3e3
VZ
1479// process Ctrl-Alt-mclick
1480void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1481{
1482 if ( event.ControlDown() && event.AltDown() )
1483 {
1484 // don't translate these strings
1485 wxString port;
1486 switch ( wxGetOsVersion() )
1487 {
1488 case wxMOTIF_X: port = _T("Motif"); break;
1489 case wxMACINTOSH: port = _T("Mac"); break;
1490 case wxBEOS: port = _T("BeOS"); break;
1491 case wxGTK:
1492 case wxGTK_WIN32:
1493 case wxGTK_OS2:
1494 case wxGTK_BEOS: port = _T("GTK"); break;
1495 case wxWINDOWS:
1496 case wxPENWINDOWS:
1497 case wxWINDOWS_NT:
1498 case wxWIN32S:
1499 case wxWIN95:
1500 case wxWIN386: port = _T("MS Windows"); break;
1501 case wxMGL_UNIX:
1502 case wxMGL_X:
1503 case wxMGL_WIN32:
1504 case wxMGL_OS2: port = _T("MGL"); break;
1505 case wxWINDOWS_OS2:
1506 case wxOS2_PM: port = _T("OS/2"); break;
1507 default: port = _T("unknown"); break;
1508 }
1509
1510 wxMessageBox(wxString::Format(
1511 _T(
f6bcfd97 1512 " wxWindows Library (%s port)\nVersion %u.%u.%u, compiled at %s %s\n Copyright (c) 1995-2000 wxWindows team"
a02dc3e3
VZ
1513 ),
1514 port.c_str(),
1515 wxMAJOR_VERSION,
1516 wxMINOR_VERSION,
1517 wxRELEASE_NUMBER,
1518 __DATE__,
1519 __TIME__
1520 ),
1521 _T("wxWindows information"),
1522 wxICON_INFORMATION | wxOK,
1523 (wxWindow *)this);
1524 }
1525 else
1526 {
1527 event.Skip();
1528 }
1529}
1530
f03fc89f
VZ
1531// ----------------------------------------------------------------------------
1532// list classes implementation
1533// ----------------------------------------------------------------------------
1534
1535void wxWindowListNode::DeleteData()
1536{
1537 delete (wxWindow *)GetData();
1538}
1539