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