]> git.saurik.com Git - wxWidgets.git/blob - src/common/wincmn.cpp
fixed the last of the off-by-one errors (some are refixed, again...)
[wxWidgets.git] / src / common / wincmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
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$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "windowbase.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
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/control.h"
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
41 #include "wx/textctrl.h"
42 #include "wx/settings.h"
43 #include "wx/dialog.h"
44 #include "wx/msgdlg.h"
45 #include "wx/statusbr.h"
46 #endif //WX_PRECOMP
47
48 #if wxUSE_CONSTRAINTS
49 #include "wx/layout.h"
50 #include "wx/sizer.h"
51 #endif // wxUSE_CONSTRAINTS
52
53 #if wxUSE_DRAG_AND_DROP
54 #include "wx/dnd.h"
55 #endif // wxUSE_DRAG_AND_DROP
56
57 #if wxUSE_HELP
58 #include "wx/cshelp.h"
59 #endif // wxUSE_HELP
60
61 #if wxUSE_TOOLTIPS
62 #include "wx/tooltip.h"
63 #endif // wxUSE_TOOLTIPS
64
65 #if wxUSE_CARET
66 #include "wx/caret.h"
67 #endif // wxUSE_CARET
68
69 // ----------------------------------------------------------------------------
70 // static data
71 // ----------------------------------------------------------------------------
72
73 int wxWindowBase::ms_lastControlId = -200;
74
75 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
76
77 // ----------------------------------------------------------------------------
78 // event table
79 // ----------------------------------------------------------------------------
80
81 BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
82 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
83 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
84 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
85
86 #if wxUSE_HELP
87 EVT_HELP(-1, wxWindowBase::OnHelp)
88 #endif // wxUSE_HELP
89
90 END_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
101 void wxWindowBase::InitBase()
102 {
103 // no window yet, no parent nor children
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
118 // no client data (yet)
119 m_clientData = NULL;
120 m_clientDataType = wxClientData_None;
121
122 // the default event handler is just this window
123 m_eventHandler = this;
124
125 #if wxUSE_VALIDATORS
126 // no validator
127 m_windowValidator = (wxValidator *) NULL;
128 #endif // wxUSE_VALIDATORS
129
130 // use the system default colours
131 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_BTNFACE);
132 m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
133
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__
138 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
139 #endif // __WXMSW__
140
141 // no style bits
142 m_exStyle =
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;
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
164
165 #if wxUSE_CARET
166 m_caret = (wxCaret *)NULL;
167 #endif // wxUSE_CARET
168
169 // Whether we're using the current theme for this window (wxGTK only for now)
170 m_themeEnabled = FALSE;
171 }
172
173 // common part of window creation process
174 bool wxWindowBase::CreateBase(wxWindowBase *parent,
175 wxWindowID id,
176 const wxPoint& WXUNUSED(pos),
177 const wxSize& WXUNUSED(size),
178 long style,
179 const wxValidator& validator,
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)
185 wxASSERT_MSG( m_isWindow, wxT("Init() must have been called before!") );
186
187 // generate a new id if the user doesn't care about it
188 m_windowId = id == -1 ? NewControlId() : id;
189
190 SetName(name);
191 SetWindowStyleFlag(style);
192 SetParent(parent);
193
194 #if wxUSE_VALIDATORS
195 SetValidator(validator);
196 #endif // wxUSE_VALIDATORS
197
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
206 return TRUE;
207 }
208
209 // ----------------------------------------------------------------------------
210 // destruction
211 // ----------------------------------------------------------------------------
212
213 // common clean up
214 wxWindowBase::~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);
226
227 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
228
229 #if wxUSE_CARET
230 if ( m_caret )
231 delete m_caret;
232 #endif // wxUSE_CARET
233
234 #if wxUSE_VALIDATORS
235 if ( m_windowValidator )
236 delete m_windowValidator;
237 #endif // wxUSE_VALIDATORS
238
239 // we only delete object data, not untyped
240 if ( m_clientDataType == wxClientData_Object )
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
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
273 bool wxWindowBase::Destroy()
274 {
275 delete this;
276
277 return TRUE;
278 }
279
280 bool 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
294 bool wxWindowBase::DestroyChildren()
295 {
296 wxWindowList::Node *node;
297 for ( ;; )
298 {
299 // we iterate until the list becomes empty
300 node = GetChildren().GetFirst();
301 if ( !node )
302 break;
303
304 wxWindow *child = node->GetData();
305
306 wxASSERT_MSG( child, wxT("children list contains empty nodes") );
307
308 child->Show(FALSE);
309 delete child;
310
311 wxASSERT_MSG( !GetChildren().Find(child),
312 wxT("child didn't remove itself using RemoveChild()") );
313 }
314
315 return TRUE;
316 }
317
318 // ----------------------------------------------------------------------------
319 // size/position related methods
320 // ----------------------------------------------------------------------------
321
322 // centre the window with respect to its parent in either (or both) directions
323 void wxWindowBase::Centre(int direction)
324 {
325 // the position/size of the parent window or of the entire screen
326 wxPoint posParent;
327 int widthParent, heightParent;
328
329 wxWindow *parent = NULL;
330
331 if ( !(direction & wxCENTRE_ON_SCREEN) )
332 {
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 }
351 }
352
353 if ( direction & wxCENTRE_ON_SCREEN )
354 {
355 // centre with respect to the whole screen
356 wxDisplaySize(&widthParent, &heightParent);
357 }
358 else
359 {
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 }
373 }
374
375 int width, height;
376 GetSize(&width, &height);
377
378 int xNew = -1,
379 yNew = -1;
380
381 if ( direction & wxHORIZONTAL )
382 xNew = (widthParent - width)/2;
383
384 if ( direction & wxVERTICAL )
385 yNew = (heightParent - height)/2;
386
387 xNew += posParent.x;
388 yNew += posParent.y;
389
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
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)
416 SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);
417 }
418
419 // fits the window around the children
420 void wxWindowBase::Fit()
421 {
422 if ( GetChildren().GetCount() > 0 )
423 {
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);
432 }
433 //else: do nothing if we have no children
434 }
435
436 // return the size best suited for the current window
437 wxSize wxWindowBase::DoGetBestSize() const
438 {
439 if ( GetChildren().GetCount() > 0 )
440 {
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() )
448 {
449 wxWindow *win = node->GetData();
450 if ( win->IsTopLevel()
451 #if wxUSE_STATUSBAR
452 || wxDynamicCast(win, wxStatusBar)
453 #endif // wxUSE_STATUSBAR
454 )
455 {
456 // dialogs and frames lie in different top level windows -
457 // don't deal with them here; as for the status bars, they
458 // don't lie in the client area at all
459 continue;
460 }
461
462 int wx, wy, ww, wh;
463 win->GetPosition(&wx, &wy);
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
472 win->GetSize(&ww, &wh);
473 if ( wx + ww > maxX )
474 maxX = wx + ww;
475 if ( wy + wh > maxY )
476 maxY = wy + wh;
477 }
478
479 return wxSize(maxX, maxY);
480 }
481 else
482 {
483 // for a generic window there is no natural best size - just use the
484 // current one
485 return GetSize();
486 }
487 }
488
489 // by default the origin is not shifted
490 wxPoint wxWindowBase::GetClientAreaOrigin() const
491 {
492 return wxPoint(0, 0);
493 }
494
495 // set the min/max size of the window
496 void 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
510 bool 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
524 bool 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 }
537 // ----------------------------------------------------------------------------
538 // RTTI
539 // ----------------------------------------------------------------------------
540
541 bool wxWindowBase::IsTopLevel() const
542 {
543 return FALSE;
544 }
545
546 // ----------------------------------------------------------------------------
547 // reparenting the window
548 // ----------------------------------------------------------------------------
549
550 void wxWindowBase::AddChild(wxWindowBase *child)
551 {
552 wxCHECK_RET( child, wxT("can't add a NULL child") );
553
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
559 GetChildren().Append(child);
560 child->SetParent(this);
561 }
562
563 void wxWindowBase::RemoveChild(wxWindowBase *child)
564 {
565 wxCHECK_RET( child, wxT("can't remove a NULL child") );
566
567 GetChildren().DeleteObject(child);
568 child->SetParent((wxWindow *)NULL);
569 }
570
571 bool 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
607 void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
608 {
609 handler->SetNextHandler(GetEventHandler());
610 SetEventHandler(handler);
611 }
612
613 wxEvtHandler *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
635 bool 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
645 bool 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
655 bool wxWindowBase::SetCursor(const wxCursor& cursor)
656 {
657 // setting an invalid cursor is ok, it means that we don't have any special
658 // cursor
659 if ( m_cursor == cursor )
660 {
661 // no change
662 return FALSE;
663 }
664
665 m_cursor = cursor;
666
667 return TRUE;
668 }
669
670 bool 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
675 if ( fontOk == m_font )
676 {
677 // no change
678 return FALSE;
679 }
680
681 m_font = fontOk;
682
683 return TRUE;
684 }
685
686 #if wxUSE_CARET
687 void 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,
699 wxT("caret should be created associated to this window") );
700 }
701 }
702 #endif // wxUSE_CARET
703
704 #if wxUSE_VALIDATORS
705 // ----------------------------------------------------------------------------
706 // validators
707 // ----------------------------------------------------------------------------
708
709 void 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 }
719 #endif // wxUSE_VALIDATORS
720
721 // ----------------------------------------------------------------------------
722 // update region stuff
723 // ----------------------------------------------------------------------------
724
725 wxRect 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
737 bool wxWindowBase::IsExposed(int x, int y) const
738 {
739 return m_updateRegion.Contains(x, y) != wxOutRegion;
740 }
741
742 bool 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
751 wxWindow *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
767 wxWindow *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
787 void wxWindowBase::MakeModal(bool modal)
788 {
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 }
802 }
803
804 bool wxWindowBase::Validate()
805 {
806 #if wxUSE_VALIDATORS
807 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
808
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();
814 if ( validator && !validator->Validate((wxWindow *)this) )
815 {
816 return FALSE;
817 }
818
819 if ( recurse && !child->Validate() )
820 {
821 return FALSE;
822 }
823 }
824 #endif // wxUSE_VALIDATORS
825
826 return TRUE;
827 }
828
829 bool wxWindowBase::TransferDataToWindow()
830 {
831 #if wxUSE_VALIDATORS
832 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
833
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 {
841 wxLogWarning(_("Could not transfer data to window"));
842 wxLog::FlushActive();
843
844 return FALSE;
845 }
846
847 if ( recurse )
848 {
849 if ( !child->TransferDataToWindow() )
850 {
851 // warning already given
852 return FALSE;
853 }
854 }
855 }
856 #endif // wxUSE_VALIDATORS
857
858 return TRUE;
859 }
860
861 bool wxWindowBase::TransferDataFromWindow()
862 {
863 #if wxUSE_VALIDATORS
864 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
865
866 wxWindowList::Node *node;
867 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
868 {
869 wxWindow *child = node->GetData();
870 wxValidator *validator = child->GetValidator();
871 if ( validator && !validator->TransferFromWindow() )
872 {
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
876 return FALSE;
877 }
878
879 if ( recurse )
880 {
881 if ( !child->TransferDataFromWindow() )
882 {
883 // warning already given
884 return FALSE;
885 }
886 }
887 }
888 #endif // wxUSE_VALIDATORS
889
890 return TRUE;
891 }
892
893 void wxWindowBase::InitDialog()
894 {
895 wxInitDialogEvent event(GetId());
896 event.SetEventObject( this );
897 GetEventHandler()->ProcessEvent(event);
898 }
899
900 // ----------------------------------------------------------------------------
901 // context-sensitive help support
902 // ----------------------------------------------------------------------------
903
904 #if wxUSE_HELP
905
906 // associate this help text with this window
907 void 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
918 void 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)
928 wxString 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
941 void 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 // ----------------------------------------------------------------------------
959 // tooltips
960 // ----------------------------------------------------------------------------
961
962 #if wxUSE_TOOLTIPS
963
964 void 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
980 void 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
996 void 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.
1028 void 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.
1053 void 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.
1062 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1063 {
1064 if ( m_constraintsInvolvedIn )
1065 m_constraintsInvolvedIn->DeleteObject(otherWin);
1066 }
1067
1068 // Reset any constraints that mention this window
1069 void 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
1102 void wxWindowBase::SetSizer(wxSizer *sizer)
1103 {
1104 if (m_windowSizer) delete m_windowSizer;
1105
1106 m_windowSizer = sizer;
1107 }
1108
1109 bool wxWindowBase::Layout()
1110 {
1111 // If there is a sizer, use it instead of the constraints
1112 if ( GetSizer() )
1113 {
1114 int w, h;
1115 GetClientSize(&w, &h);
1116
1117 GetSizer()->SetDimension( 0, 0, w, h );
1118 }
1119 else
1120 {
1121 wxLayoutConstraints *constr = GetConstraints();
1122 bool wasOk = constr && constr->AreSatisfied();
1123
1124 ResetConstraints(); // Mark all constraints as unevaluated
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
1140 SetConstraintSizes(); // Recursively set the real window sizes
1141 }
1142
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.
1150 bool 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
1161 bool 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
1172 bool 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();
1187 if ( !child->IsTopLevel() )
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
1213 void 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 }
1227
1228 wxWindowList::Node *node = GetChildren().GetFirst();
1229 while (node)
1230 {
1231 wxWindow *win = node->GetData();
1232 if ( !win->IsTopLevel() )
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.
1240 void wxWindowBase::SetConstraintSizes(bool recurse)
1241 {
1242 wxLayoutConstraints *constr = GetConstraints();
1243 if ( constr && constr->AreSatisfied() )
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
1250 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1251 (constr->height.GetRelationship() != wxAsIs) )
1252 {
1253 SetSize(x, y, w, h);
1254 }
1255 else
1256 {
1257 // If we don't want to resize this window, just move it...
1258 Move(x, y);
1259 }
1260 }
1261 else if ( constr )
1262 {
1263 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1264 GetClassInfo()->GetClassName(),
1265 GetName().c_str());
1266 }
1267
1268 if ( recurse )
1269 {
1270 wxWindowList::Node *node = GetChildren().GetFirst();
1271 while (node)
1272 {
1273 wxWindow *win = node->GetData();
1274 if ( !win->IsTopLevel() )
1275 win->SetConstraintSizes();
1276 node = node->GetNext();
1277 }
1278 }
1279 }
1280
1281 // Only set the size/position of the constraint (if any)
1282 void 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
1310 void 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
1328 void 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
1340 void 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
1352 void 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 // ----------------------------------------------------------------------------
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.
1374 void wxWindowBase::UpdateWindowUI()
1375 {
1376 #if wxUSE_CONTROLS
1377 wxUpdateUIEvent event(GetId());
1378 event.m_eventObject = this;
1379
1380 if ( GetEventHandler()->ProcessEvent(event) )
1381 {
1382 if ( event.GetSetEnabled() )
1383 Enable(event.GetEnabled());
1384
1385 if ( event.GetSetText() )
1386 {
1387 wxControl *control = wxDynamicCastThis(wxControl);
1388 if ( control )
1389 {
1390 #if wxUSE_TEXTCTRL
1391 wxTextCtrl *text = wxDynamicCast(control, wxTextCtrl);
1392 if ( text )
1393 text->SetValue(event.GetText());
1394 else
1395 #endif // wxUSE_TEXTCTRL
1396 control->SetLabel(event.GetText());
1397 }
1398 }
1399
1400 #if wxUSE_CHECKBOX
1401 wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
1402 if ( checkbox )
1403 {
1404 if ( event.GetSetChecked() )
1405 checkbox->SetValue(event.GetChecked());
1406 }
1407 #endif // wxUSE_CHECKBOX
1408
1409 #if wxUSE_RADIOBTN
1410 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
1411 if ( radiobtn )
1412 {
1413 if ( event.GetSetChecked() )
1414 radiobtn->SetValue(event.GetChecked());
1415 }
1416 #endif // wxUSE_RADIOBTN
1417 }
1418 #endif // wxUSE_CONTROLS
1419 }
1420
1421 // ----------------------------------------------------------------------------
1422 // dialog units translations
1423 // ----------------------------------------------------------------------------
1424
1425 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
1426 {
1427 int charWidth = GetCharWidth();
1428 int charHeight = GetCharHeight();
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) ;
1434
1435 return pt2;
1436 }
1437
1438 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
1439 {
1440 int charWidth = GetCharWidth();
1441 int charHeight = GetCharHeight();
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) ;
1447
1448 return pt2;
1449 }
1450
1451 // ----------------------------------------------------------------------------
1452 // client data
1453 // ----------------------------------------------------------------------------
1454
1455 void wxWindowBase::DoSetClientObject( wxClientData *data )
1456 {
1457 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1458 wxT("can't have both object and void client data") );
1459
1460 if ( m_clientObject )
1461 delete m_clientObject;
1462
1463 m_clientObject = data;
1464 m_clientDataType = wxClientData_Object;
1465 }
1466
1467 wxClientData *wxWindowBase::DoGetClientObject() const
1468 {
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
1471 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1472 wxT("this window doesn't have object client data") );
1473
1474 return m_clientObject;
1475 }
1476
1477 void wxWindowBase::DoSetClientData( void *data )
1478 {
1479 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1480 wxT("can't have both object and void client data") );
1481
1482 m_clientData = data;
1483 m_clientDataType = wxClientData_Void;
1484 }
1485
1486 void *wxWindowBase::DoGetClientData() const
1487 {
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
1490 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1491 wxT("this window doesn't have void client data") );
1492
1493 return m_clientData;
1494 }
1495
1496 // ----------------------------------------------------------------------------
1497 // event handlers
1498 // ----------------------------------------------------------------------------
1499
1500 // propagate the colour change event to the subwindows
1501 void 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
1520 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1521 {
1522 TransferDataToWindow();
1523 }
1524
1525 // process Ctrl-Alt-mclick
1526 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1527 {
1528 #if wxUSE_MSGDLG
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(
1559 " wxWindows Library (%s port)\nVersion %u.%u.%u, compiled at %s %s\n Copyright (c) 1995-2000 wxWindows team"
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
1573 #endif // wxUSE_MSGDLG
1574 {
1575 event.Skip();
1576 }
1577 }
1578
1579 // ----------------------------------------------------------------------------
1580 // list classes implementation
1581 // ----------------------------------------------------------------------------
1582
1583 void wxWindowListNode::DeleteData()
1584 {
1585 delete (wxWindow *)GetData();
1586 }
1587
1588 // ----------------------------------------------------------------------------
1589 // borders
1590 // ----------------------------------------------------------------------------
1591
1592 wxBorder 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
1603 wxBorder wxWindowBase::GetDefaultBorder() const
1604 {
1605 return wxBORDER_NONE;
1606 }
1607
1608 // ----------------------------------------------------------------------------
1609 // hit testing
1610 // ----------------------------------------------------------------------------
1611
1612 wxHitTest 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