]> git.saurik.com Git - wxWidgets.git/blame - src/common/wincmn.cpp
fixed bug with Broadcast() not waking up all threads (Pieter van der Meulen)
[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 {
ba81034d
VZ
405 wxSize size = DoGetBestSize();
406
407 // for compatibility with the old versions and because it really looks
408 // slightly more pretty like this, add a pad
409 size.x += 7;
410 size.y += 14;
411
412 SetClientSize(size);
f68586e5
VZ
413 }
414 //else: do nothing if we have no children
415}
f03fc89f 416
f68586e5
VZ
417// return the size best suited for the current window
418wxSize wxWindowBase::DoGetBestSize() const
419{
420 if ( GetChildren().GetCount() > 0 )
f03fc89f 421 {
f68586e5
VZ
422 // our minimal acceptable size is such that all our windows fit inside
423 int maxX = 0,
424 maxY = 0;
425
426 for ( wxWindowList::Node *node = GetChildren().GetFirst();
427 node;
428 node = node->GetNext() )
42e69d6b 429 {
f68586e5 430 wxWindow *win = node->GetData();
e63fdcd6 431 if ( win->IsTopLevel() || wxDynamicCast(win, wxStatusBar) || !win->IsShown())
f68586e5
VZ
432 {
433 // dialogs and frames lie in different top level windows -
7d9fd004
VZ
434 // don't deal with them here; as for the status bars, they
435 // don't lie in the client area at all
f68586e5
VZ
436 continue;
437 }
438
439 int wx, wy, ww, wh;
440 win->GetPosition(&wx, &wy);
3f5513f5
VZ
441
442 // if the window hadn't been positioned yet, assume that it is in
443 // the origin
444 if ( wx == -1 )
445 wx = 0;
446 if ( wy == -1 )
447 wy = 0;
448
f68586e5
VZ
449 win->GetSize(&ww, &wh);
450 if ( wx + ww > maxX )
451 maxX = wx + ww;
452 if ( wy + wh > maxY )
453 maxY = wy + wh;
42e69d6b
VZ
454 }
455
ba81034d 456 return wxSize(maxX, maxY);
f68586e5
VZ
457 }
458 else
459 {
460 // for a generic window there is no natural best size - just use the
461 // current one
462 return GetSize();
f03fc89f 463 }
f03fc89f
VZ
464}
465
466// set the min/max size of the window
f03fc89f
VZ
467void wxWindowBase::SetSizeHints(int minW, int minH,
468 int maxW, int maxH,
469 int WXUNUSED(incW), int WXUNUSED(incH))
470{
471 m_minWidth = minW;
472 m_maxWidth = maxW;
473 m_minHeight = minH;
474 m_maxHeight = maxH;
475}
476
477// ----------------------------------------------------------------------------
478// show/hide/enable/disable the window
479// ----------------------------------------------------------------------------
480
481bool wxWindowBase::Show(bool show)
482{
483 if ( show != m_isShown )
484 {
485 m_isShown = show;
486
487 return TRUE;
488 }
489 else
490 {
491 return FALSE;
492 }
493}
494
495bool wxWindowBase::Enable(bool enable)
496{
497 if ( enable != m_isEnabled )
498 {
499 m_isEnabled = enable;
500
501 return TRUE;
502 }
503 else
504 {
505 return FALSE;
506 }
507}
34636400
VZ
508// ----------------------------------------------------------------------------
509// RTTI
510// ----------------------------------------------------------------------------
511
512bool wxWindowBase::IsTopLevel() const
513{
8487f887 514 return FALSE;
34636400 515}
f03fc89f
VZ
516
517// ----------------------------------------------------------------------------
518// reparenting the window
519// ----------------------------------------------------------------------------
520
521void wxWindowBase::AddChild(wxWindowBase *child)
522{
223d09f6 523 wxCHECK_RET( child, wxT("can't add a NULL child") );
f03fc89f 524
f6bcfd97
BP
525 // this should never happen and it will lead to a crash later if it does
526 // because RemoveChild() will remove only one node from the children list
527 // and the other(s) one(s) will be left with dangling pointers in them
528 wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") );
529
f03fc89f
VZ
530 GetChildren().Append(child);
531 child->SetParent(this);
532}
533
534void wxWindowBase::RemoveChild(wxWindowBase *child)
535{
223d09f6 536 wxCHECK_RET( child, wxT("can't remove a NULL child") );
f03fc89f
VZ
537
538 GetChildren().DeleteObject(child);
539 child->SetParent((wxWindow *)NULL);
540}
439b3bf1 541
f03fc89f
VZ
542bool wxWindowBase::Reparent(wxWindowBase *newParent)
543{
544 wxWindow *oldParent = GetParent();
545 if ( newParent == oldParent )
546 {
547 // nothing done
548 return FALSE;
549 }
550
551 // unlink this window from the existing parent.
552 if ( oldParent )
553 {
554 oldParent->RemoveChild(this);
555 }
556 else
557 {
558 wxTopLevelWindows.DeleteObject(this);
559 }
560
561 // add it to the new one
562 if ( newParent )
563 {
564 newParent->AddChild(this);
565 }
566 else
567 {
568 wxTopLevelWindows.Append(this);
569 }
570
571 return TRUE;
572}
573
574// ----------------------------------------------------------------------------
575// event handler stuff
576// ----------------------------------------------------------------------------
577
578void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
579{
580 handler->SetNextHandler(GetEventHandler());
581 SetEventHandler(handler);
582}
583
584wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
585{
586 wxEvtHandler *handlerA = GetEventHandler();
587 if ( handlerA )
588 {
589 wxEvtHandler *handlerB = handlerA->GetNextHandler();
590 handlerA->SetNextHandler((wxEvtHandler *)NULL);
591 SetEventHandler(handlerB);
592 if ( deleteHandler )
593 {
594 delete handlerA;
595 handlerA = (wxEvtHandler *)NULL;
596 }
597 }
598
599 return handlerA;
600}
601
602// ----------------------------------------------------------------------------
603// cursors, fonts &c
604// ----------------------------------------------------------------------------
605
606bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
607{
608 if ( !colour.Ok() || (colour == m_backgroundColour) )
609 return FALSE;
610
611 m_backgroundColour = colour;
612
613 return TRUE;
614}
615
616bool wxWindowBase::SetForegroundColour( const wxColour &colour )
617{
618 if ( !colour.Ok() || (colour == m_foregroundColour) )
619 return FALSE;
620
621 m_foregroundColour = colour;
622
623 return TRUE;
624}
625
626bool wxWindowBase::SetCursor(const wxCursor& cursor)
627{
8a9c2246
VZ
628 // setting an invalid cursor is ok, it means that we don't have any special
629 // cursor
13588544 630 if ( m_cursor == cursor )
f03fc89f
VZ
631 {
632 // no change
633 return FALSE;
634 }
635
8a9c2246 636 m_cursor = cursor;
f03fc89f
VZ
637
638 return TRUE;
639}
640
641bool wxWindowBase::SetFont(const wxFont& font)
642{
643 // don't try to set invalid font, always fall back to the default
644 const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT;
645
913df6f2 646 if ( (wxFont&)fontOk == m_font )
f03fc89f
VZ
647 {
648 // no change
649 return FALSE;
650 }
651
652 m_font = fontOk;
653
654 return TRUE;
655}
656
789295bf
VZ
657#if wxUSE_CARET
658void wxWindowBase::SetCaret(wxCaret *caret)
659{
660 if ( m_caret )
661 {
662 delete m_caret;
663 }
664
665 m_caret = caret;
666
667 if ( m_caret )
668 {
669 wxASSERT_MSG( m_caret->GetWindow() == this,
223d09f6 670 wxT("caret should be created associated to this window") );
789295bf
VZ
671 }
672}
673#endif // wxUSE_CARET
674
88ac883a 675#if wxUSE_VALIDATORS
f03fc89f
VZ
676// ----------------------------------------------------------------------------
677// validators
678// ----------------------------------------------------------------------------
679
680void wxWindowBase::SetValidator(const wxValidator& validator)
681{
682 if ( m_windowValidator )
683 delete m_windowValidator;
684
685 m_windowValidator = (wxValidator *)validator.Clone();
686
687 if ( m_windowValidator )
688 m_windowValidator->SetWindow(this) ;
689}
88ac883a 690#endif // wxUSE_VALIDATORS
f03fc89f
VZ
691
692// ----------------------------------------------------------------------------
693// update region testing
694// ----------------------------------------------------------------------------
695
696bool wxWindowBase::IsExposed(int x, int y) const
697{
698 return m_updateRegion.Contains(x, y) != wxOutRegion;
699}
700
701bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
702{
703 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
704}
705
706// ----------------------------------------------------------------------------
707// find window by id or name
708// ----------------------------------------------------------------------------
709
710wxWindow *wxWindowBase::FindWindow( long id )
711{
712 if ( id == m_windowId )
713 return (wxWindow *)this;
714
715 wxWindowBase *res = (wxWindow *)NULL;
716 wxWindowList::Node *node;
717 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
718 {
719 wxWindowBase *child = node->GetData();
720 res = child->FindWindow( id );
721 }
722
723 return (wxWindow *)res;
724}
725
726wxWindow *wxWindowBase::FindWindow( const wxString& name )
727{
728 if ( name == m_windowName )
729 return (wxWindow *)this;
730
731 wxWindowBase *res = (wxWindow *)NULL;
732 wxWindowList::Node *node;
733 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
734 {
735 wxWindow *child = node->GetData();
736 res = child->FindWindow(name);
737 }
738
739 return (wxWindow *)res;
740}
741
742// ----------------------------------------------------------------------------
743// dialog oriented functions
744// ----------------------------------------------------------------------------
745
34636400 746void wxWindowBase::MakeModal(bool modal)
f03fc89f 747{
34636400
VZ
748 // Disable all other windows
749 if ( IsTopLevel() )
750 {
751 wxWindowList::Node *node = wxTopLevelWindows.GetFirst();
752 while (node)
753 {
754 wxWindow *win = node->GetData();
755 if (win != this)
756 win->Enable(!modal);
757
758 node = node->GetNext();
759 }
760 }
f03fc89f
VZ
761}
762
763bool wxWindowBase::Validate()
764{
88ac883a 765#if wxUSE_VALIDATORS
d80cd92a
VZ
766 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
767
f03fc89f
VZ
768 wxWindowList::Node *node;
769 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
770 {
771 wxWindowBase *child = node->GetData();
772 wxValidator *validator = child->GetValidator();
dcd6b914 773 if ( validator && !validator->Validate((wxWindow *)this) )
f03fc89f
VZ
774 {
775 return FALSE;
776 }
d80cd92a
VZ
777
778 if ( recurse && !child->Validate() )
779 {
780 return FALSE;
781 }
f03fc89f 782 }
88ac883a 783#endif // wxUSE_VALIDATORS
f03fc89f
VZ
784
785 return TRUE;
786}
787
788bool wxWindowBase::TransferDataToWindow()
789{
88ac883a 790#if wxUSE_VALIDATORS
d80cd92a
VZ
791 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
792
f03fc89f
VZ
793 wxWindowList::Node *node;
794 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
795 {
796 wxWindowBase *child = node->GetData();
797 wxValidator *validator = child->GetValidator();
798 if ( validator && !validator->TransferToWindow() )
799 {
d80cd92a
VZ
800 wxLogWarning(_("Could not transfer data to window"));
801 wxLog::FlushActive();
f03fc89f
VZ
802
803 return FALSE;
804 }
d80cd92a
VZ
805
806 if ( recurse )
807 {
a58a12e9 808 if ( !child->TransferDataToWindow() )
d80cd92a
VZ
809 {
810 // warning already given
811 return FALSE;
812 }
813 }
f03fc89f 814 }
88ac883a 815#endif // wxUSE_VALIDATORS
f03fc89f
VZ
816
817 return TRUE;
818}
819
820bool wxWindowBase::TransferDataFromWindow()
821{
88ac883a 822#if wxUSE_VALIDATORS
d80cd92a
VZ
823 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
824
f03fc89f
VZ
825 wxWindowList::Node *node;
826 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
827 {
828 wxWindow *child = node->GetData();
d80cd92a
VZ
829 wxValidator *validator = child->GetValidator();
830 if ( validator && !validator->TransferFromWindow() )
f03fc89f 831 {
d80cd92a
VZ
832 // nop warning here because the application is supposed to give
833 // one itself - we don't know here what might have gone wrongly
834
f03fc89f
VZ
835 return FALSE;
836 }
d80cd92a
VZ
837
838 if ( recurse )
839 {
a58a12e9 840 if ( !child->TransferDataFromWindow() )
d80cd92a
VZ
841 {
842 // warning already given
843 return FALSE;
844 }
845 }
f03fc89f 846 }
88ac883a 847#endif // wxUSE_VALIDATORS
f03fc89f
VZ
848
849 return TRUE;
850}
851
852void wxWindowBase::InitDialog()
853{
854 wxInitDialogEvent event(GetId());
855 event.SetEventObject( this );
856 GetEventHandler()->ProcessEvent(event);
857}
858
859// ----------------------------------------------------------------------------
bd83cb56
VZ
860// context-sensitive help support
861// ----------------------------------------------------------------------------
862
863#if wxUSE_HELP
864
865// associate this help text with this window
866void wxWindowBase::SetHelpText(const wxString& text)
867{
868 wxHelpProvider *helpProvider = wxHelpProvider::Get();
869 if ( helpProvider )
870 {
871 helpProvider->AddHelp(this, text);
872 }
873}
874
875// associate this help text with all windows with the same id as this
876// one
877void wxWindowBase::SetHelpTextForId(const wxString& text)
878{
879 wxHelpProvider *helpProvider = wxHelpProvider::Get();
880 if ( helpProvider )
881 {
882 helpProvider->AddHelp(GetId(), text);
883 }
884}
885
886// get the help string associated with this window (may be empty)
887wxString wxWindowBase::GetHelpText() const
888{
889 wxString text;
890 wxHelpProvider *helpProvider = wxHelpProvider::Get();
891 if ( helpProvider )
892 {
893 text = helpProvider->GetHelp(this);
894 }
895
896 return text;
897}
898
899// show help for this window
900void wxWindowBase::OnHelp(wxHelpEvent& event)
901{
902 wxHelpProvider *helpProvider = wxHelpProvider::Get();
903 if ( helpProvider )
904 {
905 if ( helpProvider->ShowHelp(this) )
906 {
907 // skip the event.Skip() below
908 return;
909 }
910 }
911
912 event.Skip();
913}
914
915#endif // wxUSE_HELP
916
917// ----------------------------------------------------------------------------
f03fc89f
VZ
918// tooltips
919// ----------------------------------------------------------------------------
920
921#if wxUSE_TOOLTIPS
922
923void wxWindowBase::SetToolTip( const wxString &tip )
924{
925 // don't create the new tooltip if we already have one
926 if ( m_tooltip )
927 {
928 m_tooltip->SetTip( tip );
929 }
930 else
931 {
932 SetToolTip( new wxToolTip( tip ) );
933 }
934
935 // setting empty tooltip text does not remove the tooltip any more - use
936 // SetToolTip((wxToolTip *)NULL) for this
937}
938
939void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
940{
941 if ( m_tooltip )
942 delete m_tooltip;
943
944 m_tooltip = tooltip;
945}
946
947#endif // wxUSE_TOOLTIPS
948
949// ----------------------------------------------------------------------------
950// constraints and sizers
951// ----------------------------------------------------------------------------
952
953#if wxUSE_CONSTRAINTS
954
955void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
956{
957 if ( m_constraints )
958 {
959 UnsetConstraints(m_constraints);
960 delete m_constraints;
961 }
962 m_constraints = constraints;
963 if ( m_constraints )
964 {
965 // Make sure other windows know they're part of a 'meaningful relationship'
966 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
967 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
968 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
969 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
970 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
971 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
972 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
973 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
974 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
975 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
976 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
977 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
978 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
979 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
980 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
981 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
982 }
983}
984
985// This removes any dangling pointers to this window in other windows'
986// constraintsInvolvedIn lists.
987void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
988{
989 if ( c )
990 {
991 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
992 c->left.GetOtherWindow()->RemoveConstraintReference(this);
993 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
994 c->top.GetOtherWindow()->RemoveConstraintReference(this);
995 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
996 c->right.GetOtherWindow()->RemoveConstraintReference(this);
997 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
998 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
999 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1000 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1001 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1002 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1003 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1004 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1005 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1006 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1007 }
1008}
1009
1010// Back-pointer to other windows we're involved with, so if we delete this
1011// window, we must delete any constraints we're involved with.
1012void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1013{
1014 if ( !m_constraintsInvolvedIn )
1015 m_constraintsInvolvedIn = new wxWindowList;
1016 if ( !m_constraintsInvolvedIn->Find(otherWin) )
1017 m_constraintsInvolvedIn->Append(otherWin);
1018}
1019
1020// REMOVE back-pointer to other windows we're involved with.
1021void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1022{
1023 if ( m_constraintsInvolvedIn )
1024 m_constraintsInvolvedIn->DeleteObject(otherWin);
1025}
1026
1027// Reset any constraints that mention this window
1028void wxWindowBase::DeleteRelatedConstraints()
1029{
1030 if ( m_constraintsInvolvedIn )
1031 {
1032 wxWindowList::Node *node = m_constraintsInvolvedIn->GetFirst();
1033 while (node)
1034 {
1035 wxWindow *win = node->GetData();
1036 wxLayoutConstraints *constr = win->GetConstraints();
1037
1038 // Reset any constraints involving this window
1039 if ( constr )
1040 {
1041 constr->left.ResetIfWin(this);
1042 constr->top.ResetIfWin(this);
1043 constr->right.ResetIfWin(this);
1044 constr->bottom.ResetIfWin(this);
1045 constr->width.ResetIfWin(this);
1046 constr->height.ResetIfWin(this);
1047 constr->centreX.ResetIfWin(this);
1048 constr->centreY.ResetIfWin(this);
1049 }
1050
1051 wxWindowList::Node *next = node->GetNext();
1052 delete node;
1053 node = next;
1054 }
1055
1056 delete m_constraintsInvolvedIn;
1057 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1058 }
1059}
1060
1061void wxWindowBase::SetSizer(wxSizer *sizer)
1062{
3417c2cd
RR
1063 if (m_windowSizer) delete m_windowSizer;
1064
f03fc89f 1065 m_windowSizer = sizer;
f03fc89f
VZ
1066}
1067
1068bool wxWindowBase::Layout()
1069{
3417c2cd 1070 // If there is a sizer, use it instead of the constraints
f03fc89f
VZ
1071 if ( GetSizer() )
1072 {
f1df0927
VZ
1073 int w, h;
1074 GetClientSize(&w, &h);
1075
3417c2cd 1076 GetSizer()->SetDimension( 0, 0, w, h );
f03fc89f 1077 }
f1df0927 1078 else
f03fc89f 1079 {
4b7f2165
VZ
1080 wxLayoutConstraints *constr = GetConstraints();
1081 bool wasOk = constr && constr->AreSatisfied();
1082
f1df0927 1083 ResetConstraints(); // Mark all constraints as unevaluated
4b7f2165
VZ
1084
1085 // if we're a top level panel (i.e. our parent is frame/dialog), our
1086 // own constraints will never be satisfied any more unless we do it
1087 // here
1088 if ( wasOk )
1089 {
1090 int noChanges = 1;
1091 while ( noChanges > 0 )
1092 {
1093 constr->SatisfyConstraints(this, &noChanges);
1094 }
1095 }
1096
1097 DoPhase(1); // Layout children
1098 DoPhase(2); // Layout grand children
f1df0927 1099 SetConstraintSizes(); // Recursively set the real window sizes
f03fc89f 1100 }
5d4b632b 1101
f03fc89f
VZ
1102 return TRUE;
1103}
1104
1105
1106// Do a phase of evaluating constraints: the default behaviour. wxSizers may
1107// do a similar thing, but also impose their own 'constraints' and order the
1108// evaluation differently.
1109bool wxWindowBase::LayoutPhase1(int *noChanges)
1110{
1111 wxLayoutConstraints *constr = GetConstraints();
1112 if ( constr )
1113 {
1114 return constr->SatisfyConstraints(this, noChanges);
1115 }
1116 else
1117 return TRUE;
1118}
1119
1120bool wxWindowBase::LayoutPhase2(int *noChanges)
1121{
1122 *noChanges = 0;
1123
1124 // Layout children
1125 DoPhase(1);
1126 DoPhase(2);
1127 return TRUE;
1128}
1129
1130// Do a phase of evaluating child constraints
1131bool wxWindowBase::DoPhase(int phase)
1132{
1133 int noIterations = 0;
1134 int maxIterations = 500;
1135 int noChanges = 1;
1136 int noFailures = 0;
1137 wxWindowList succeeded;
1138 while ((noChanges > 0) && (noIterations < maxIterations))
1139 {
1140 noChanges = 0;
1141 noFailures = 0;
1142 wxWindowList::Node *node = GetChildren().GetFirst();
1143 while (node)
1144 {
1145 wxWindow *child = node->GetData();
34636400 1146 if ( !child->IsTopLevel() )
f03fc89f
VZ
1147 {
1148 wxLayoutConstraints *constr = child->GetConstraints();
1149 if ( constr )
1150 {
1151 if ( !succeeded.Find(child) )
1152 {
1153 int tempNoChanges = 0;
1154 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
1155 noChanges += tempNoChanges;
1156 if ( success )
1157 {
1158 succeeded.Append(child);
1159 }
1160 }
1161 }
1162 }
1163 node = node->GetNext();
1164 }
1165
1166 noIterations++;
1167 }
1168
1169 return TRUE;
1170}
1171
1172void wxWindowBase::ResetConstraints()
1173{
1174 wxLayoutConstraints *constr = GetConstraints();
1175 if ( constr )
1176 {
1177 constr->left.SetDone(FALSE);
1178 constr->top.SetDone(FALSE);
1179 constr->right.SetDone(FALSE);
1180 constr->bottom.SetDone(FALSE);
1181 constr->width.SetDone(FALSE);
1182 constr->height.SetDone(FALSE);
1183 constr->centreX.SetDone(FALSE);
1184 constr->centreY.SetDone(FALSE);
1185 }
f1df0927 1186
f03fc89f
VZ
1187 wxWindowList::Node *node = GetChildren().GetFirst();
1188 while (node)
1189 {
1190 wxWindow *win = node->GetData();
34636400 1191 if ( !win->IsTopLevel() )
f03fc89f
VZ
1192 win->ResetConstraints();
1193 node = node->GetNext();
1194 }
1195}
1196
1197// Need to distinguish between setting the 'fake' size for windows and sizers,
1198// and setting the real values.
1199void wxWindowBase::SetConstraintSizes(bool recurse)
1200{
1201 wxLayoutConstraints *constr = GetConstraints();
4b7f2165 1202 if ( constr && constr->AreSatisfied() )
f03fc89f
VZ
1203 {
1204 int x = constr->left.GetValue();
1205 int y = constr->top.GetValue();
1206 int w = constr->width.GetValue();
1207 int h = constr->height.GetValue();
1208
f03fc89f 1209 if ( (constr->width.GetRelationship() != wxAsIs ) ||
3417c2cd 1210 (constr->height.GetRelationship() != wxAsIs) )
f03fc89f 1211 {
3417c2cd 1212 SetSize(x, y, w, h);
f03fc89f
VZ
1213 }
1214 else
1215 {
3417c2cd
RR
1216 // If we don't want to resize this window, just move it...
1217 Move(x, y);
f03fc89f
VZ
1218 }
1219 }
1220 else if ( constr )
1221 {
4b7f2165 1222 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
f1df0927 1223 GetClassInfo()->GetClassName(),
4b7f2165 1224 GetName().c_str());
f03fc89f
VZ
1225 }
1226
1227 if ( recurse )
1228 {
1229 wxWindowList::Node *node = GetChildren().GetFirst();
1230 while (node)
1231 {
1232 wxWindow *win = node->GetData();
34636400 1233 if ( !win->IsTopLevel() )
f03fc89f
VZ
1234 win->SetConstraintSizes();
1235 node = node->GetNext();
1236 }
1237 }
1238}
1239
f03fc89f
VZ
1240// Only set the size/position of the constraint (if any)
1241void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1242{
1243 wxLayoutConstraints *constr = GetConstraints();
1244 if ( constr )
1245 {
1246 if ( x != -1 )
1247 {
1248 constr->left.SetValue(x);
1249 constr->left.SetDone(TRUE);
1250 }
1251 if ( y != -1 )
1252 {
1253 constr->top.SetValue(y);
1254 constr->top.SetDone(TRUE);
1255 }
1256 if ( w != -1 )
1257 {
1258 constr->width.SetValue(w);
1259 constr->width.SetDone(TRUE);
1260 }
1261 if ( h != -1 )
1262 {
1263 constr->height.SetValue(h);
1264 constr->height.SetDone(TRUE);
1265 }
1266 }
1267}
1268
1269void wxWindowBase::MoveConstraint(int x, int y)
1270{
1271 wxLayoutConstraints *constr = GetConstraints();
1272 if ( constr )
1273 {
1274 if ( x != -1 )
1275 {
1276 constr->left.SetValue(x);
1277 constr->left.SetDone(TRUE);
1278 }
1279 if ( y != -1 )
1280 {
1281 constr->top.SetValue(y);
1282 constr->top.SetDone(TRUE);
1283 }
1284 }
1285}
1286
1287void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1288{
1289 wxLayoutConstraints *constr = GetConstraints();
1290 if ( constr )
1291 {
1292 *w = constr->width.GetValue();
1293 *h = constr->height.GetValue();
1294 }
1295 else
1296 GetSize(w, h);
1297}
1298
1299void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1300{
1301 wxLayoutConstraints *constr = GetConstraints();
1302 if ( constr )
1303 {
1304 *w = constr->width.GetValue();
1305 *h = constr->height.GetValue();
1306 }
1307 else
1308 GetClientSize(w, h);
1309}
1310
1311void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1312{
1313 wxLayoutConstraints *constr = GetConstraints();
1314 if ( constr )
1315 {
1316 *x = constr->left.GetValue();
1317 *y = constr->top.GetValue();
1318 }
1319 else
1320 GetPosition(x, y);
1321}
1322
1323#endif // wxUSE_CONSTRAINTS
1324
1325// ----------------------------------------------------------------------------
1326// do Update UI processing for child controls
1327// ----------------------------------------------------------------------------
7ec1983b
VZ
1328
1329// TODO: should this be implemented for the child window rather
1330// than the parent? Then you can override it e.g. for wxCheckBox
1331// to do the Right Thing rather than having to assume a fixed number
1332// of control classes.
f03fc89f 1333void wxWindowBase::UpdateWindowUI()
7ec1983b 1334{
26bf1ce0
VZ
1335 wxUpdateUIEvent event(GetId());
1336 event.m_eventObject = this;
1337
1338 if ( GetEventHandler()->ProcessEvent(event) )
7ec1983b 1339 {
26bf1ce0
VZ
1340 if ( event.GetSetEnabled() )
1341 Enable(event.GetEnabled());
7ec1983b 1342
26bf1ce0 1343 if ( event.GetSetText() )
f03fc89f 1344 {
26bf1ce0
VZ
1345 wxControl *control = wxDynamicCast(this, wxControl);
1346 if ( control )
34636400 1347 {
26bf1ce0
VZ
1348 wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
1349 if ( text )
1350 text->SetValue(event.GetText());
1351 else
34636400
VZ
1352 control->SetLabel(event.GetText());
1353 }
26bf1ce0 1354 }
f03fc89f 1355
88ac883a 1356#if wxUSE_CHECKBOX
26bf1ce0
VZ
1357 wxCheckBox *checkbox = wxDynamicCast(this, wxCheckBox);
1358 if ( checkbox )
1359 {
1360 if ( event.GetSetChecked() )
1361 checkbox->SetValue(event.GetChecked());
1362 }
88ac883a
VZ
1363#endif // wxUSE_CHECKBOX
1364
b3402d0d 1365#if wxUSE_RADIOBTN
26bf1ce0
VZ
1366 wxRadioButton *radiobtn = wxDynamicCast(this, wxRadioButton);
1367 if ( radiobtn )
1368 {
1369 if ( event.GetSetChecked() )
1370 radiobtn->SetValue(event.GetChecked());
f03fc89f 1371 }
b3402d0d 1372#endif // wxUSE_RADIOBTN
7ec1983b 1373 }
7ec1983b 1374}
fd71308f 1375
f03fc89f
VZ
1376// ----------------------------------------------------------------------------
1377// dialog units translations
1378// ----------------------------------------------------------------------------
1379
1380wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
fd71308f
JS
1381{
1382 int charWidth = GetCharWidth();
1383 int charHeight = GetCharHeight();
5d9c2818
RD
1384 wxPoint pt2(-1, -1);
1385 if (pt.x != -1)
1386 pt2.x = (int) ((pt.x * 4) / charWidth) ;
1387 if (pt.y != -1)
1388 pt2.y = (int) ((pt.y * 8) / charHeight) ;
fd71308f
JS
1389
1390 return pt2;
1391}
1392
f03fc89f 1393wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
fd71308f
JS
1394{
1395 int charWidth = GetCharWidth();
1396 int charHeight = GetCharHeight();
5d9c2818
RD
1397 wxPoint pt2(-1, -1);
1398 if (pt.x != -1)
1399 pt2.x = (int) ((pt.x * charWidth) / 4) ;
1400 if (pt.y != -1)
1401 pt2.y = (int) ((pt.y * charHeight) / 8) ;
fd71308f
JS
1402
1403 return pt2;
1404}
1405
8d99be5f
VZ
1406// ----------------------------------------------------------------------------
1407// client data
1408// ----------------------------------------------------------------------------
1409
1410void wxWindowBase::DoSetClientObject( wxClientData *data )
1411{
1412 wxASSERT_MSG( m_clientDataType != ClientData_Void,
223d09f6 1413 wxT("can't have both object and void client data") );
8d99be5f
VZ
1414
1415 if ( m_clientObject )
1416 delete m_clientObject;
1417
1418 m_clientObject = data;
1419 m_clientDataType = ClientData_Object;
1420}
1421
1422wxClientData *wxWindowBase::DoGetClientObject() const
1423{
0d7ea902
VZ
1424 // it's not an error to call GetClientObject() on a window which doesn't
1425 // have client data at all - NULL will be returned
1426 wxASSERT_MSG( m_clientDataType != ClientData_Void,
223d09f6 1427 wxT("this window doesn't have object client data") );
8d99be5f
VZ
1428
1429 return m_clientObject;
1430}
1431
1432void wxWindowBase::DoSetClientData( void *data )
1433{
1434 wxASSERT_MSG( m_clientDataType != ClientData_Object,
223d09f6 1435 wxT("can't have both object and void client data") );
8d99be5f
VZ
1436
1437 m_clientData = data;
1438 m_clientDataType = ClientData_Void;
1439}
1440
1441void *wxWindowBase::DoGetClientData() const
1442{
0d7ea902
VZ
1443 // it's not an error to call GetClientData() on a window which doesn't have
1444 // client data at all - NULL will be returned
1445 wxASSERT_MSG( m_clientDataType != ClientData_Object,
223d09f6 1446 wxT("this window doesn't have void client data") );
8d99be5f
VZ
1447
1448 return m_clientData;
1449}
1450
f03fc89f
VZ
1451// ----------------------------------------------------------------------------
1452// event handlers
1453// ----------------------------------------------------------------------------
1454
1455// propagate the colour change event to the subwindows
1456void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
1457{
1458 wxWindowList::Node *node = GetChildren().GetFirst();
1459 while ( node )
1460 {
1461 // Only propagate to non-top-level windows
1462 wxWindow *win = node->GetData();
1463 if ( !win->IsTopLevel() )
1464 {
1465 wxSysColourChangedEvent event2;
1466 event.m_eventObject = win;
1467 win->GetEventHandler()->ProcessEvent(event2);
1468 }
1469
1470 node = node->GetNext();
1471 }
1472}
1473
1474// the default action is to populate dialog with data when it's created
1475void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1476{
1477 TransferDataToWindow();
1478}
1479
a02dc3e3
VZ
1480// process Ctrl-Alt-mclick
1481void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1482{
1483 if ( event.ControlDown() && event.AltDown() )
1484 {
1485 // don't translate these strings
1486 wxString port;
1487 switch ( wxGetOsVersion() )
1488 {
1489 case wxMOTIF_X: port = _T("Motif"); break;
1490 case wxMACINTOSH: port = _T("Mac"); break;
1491 case wxBEOS: port = _T("BeOS"); break;
1492 case wxGTK:
1493 case wxGTK_WIN32:
1494 case wxGTK_OS2:
1495 case wxGTK_BEOS: port = _T("GTK"); break;
1496 case wxWINDOWS:
1497 case wxPENWINDOWS:
1498 case wxWINDOWS_NT:
1499 case wxWIN32S:
1500 case wxWIN95:
1501 case wxWIN386: port = _T("MS Windows"); break;
1502 case wxMGL_UNIX:
1503 case wxMGL_X:
1504 case wxMGL_WIN32:
1505 case wxMGL_OS2: port = _T("MGL"); break;
1506 case wxWINDOWS_OS2:
1507 case wxOS2_PM: port = _T("OS/2"); break;
1508 default: port = _T("unknown"); break;
1509 }
1510
1511 wxMessageBox(wxString::Format(
1512 _T(
f6bcfd97 1513 " wxWindows Library (%s port)\nVersion %u.%u.%u, compiled at %s %s\n Copyright (c) 1995-2000 wxWindows team"
a02dc3e3
VZ
1514 ),
1515 port.c_str(),
1516 wxMAJOR_VERSION,
1517 wxMINOR_VERSION,
1518 wxRELEASE_NUMBER,
1519 __DATE__,
1520 __TIME__
1521 ),
1522 _T("wxWindows information"),
1523 wxICON_INFORMATION | wxOK,
1524 (wxWindow *)this);
1525 }
1526 else
1527 {
1528 event.Skip();
1529 }
1530}
1531
f03fc89f
VZ
1532// ----------------------------------------------------------------------------
1533// list classes implementation
1534// ----------------------------------------------------------------------------
1535
1536void wxWindowListNode::DeleteData()
1537{
1538 delete (wxWindow *)GetData();
1539}
1540