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