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