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