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