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