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