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