]> git.saurik.com Git - wxWidgets.git/blob - src/common/wincmn.cpp
Make DoGetBestSize cache the value of GetSize() the first time it is called
[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 licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/statbox.h"
42 #include "wx/textctrl.h"
43 #include "wx/settings.h"
44 #include "wx/dialog.h"
45 #include "wx/msgdlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/dcclient.h"
48 #endif //WX_PRECOMP
49
50 #if wxUSE_CONSTRAINTS
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
53
54 #include "wx/sizer.h"
55
56 #if wxUSE_DRAG_AND_DROP
57 #include "wx/dnd.h"
58 #endif // wxUSE_DRAG_AND_DROP
59
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
62 #endif
63
64 #if wxUSE_HELP
65 #include "wx/cshelp.h"
66 #endif // wxUSE_HELP
67
68 #if wxUSE_TOOLTIPS
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
71
72 #if wxUSE_CARET
73 #include "wx/caret.h"
74 #endif // wxUSE_CARET
75
76 // ----------------------------------------------------------------------------
77 // static data
78 // ----------------------------------------------------------------------------
79
80 #if defined(__WXPM__)
81 int wxWindowBase::ms_lastControlId = 2000;
82 #else
83 int wxWindowBase::ms_lastControlId = -200;
84 #endif
85
86 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase, wxEvtHandler)
87
88 // ----------------------------------------------------------------------------
89 // event table
90 // ----------------------------------------------------------------------------
91
92 BEGIN_EVENT_TABLE(wxWindowBase, wxEvtHandler)
93 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged)
94 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog)
95 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick)
96
97 #if wxUSE_HELP
98 EVT_HELP(wxID_ANY, wxWindowBase::OnHelp)
99 #endif // wxUSE_HELP
100
101 END_EVENT_TABLE()
102
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
106
107 // ----------------------------------------------------------------------------
108 // initialization
109 // ----------------------------------------------------------------------------
110
111 // the default initialization
112 wxWindowBase::wxWindowBase()
113 : m_bestSize(wxDefaultSize)
114 {
115 // no window yet, no parent nor children
116 m_parent = (wxWindow *)NULL;
117 m_windowId = wxID_ANY;
118
119 // no constraints on the minimal window size
120 m_minWidth =
121 m_minHeight =
122 m_maxWidth =
123 m_maxHeight = -1;
124
125 // window are created enabled and visible by default
126 m_isShown =
127 m_isEnabled = true;
128
129 // the default event handler is just this window
130 m_eventHandler = this;
131
132 #if wxUSE_VALIDATORS
133 // no validator
134 m_windowValidator = (wxValidator *) NULL;
135 #endif // wxUSE_VALIDATORS
136
137 // the colours/fonts are default for now, so leave m_font,
138 // m_backgroundColour and m_foregroundColour uninitialized and set those
139 m_hasBgCol =
140 m_hasFgCol =
141 m_hasFont = false;
142
143 // no style bits
144 m_exStyle =
145 m_windowStyle = 0;
146
147 #if wxUSE_CONSTRAINTS
148 // no constraints whatsoever
149 m_constraints = (wxLayoutConstraints *) NULL;
150 m_constraintsInvolvedIn = (wxWindowList *) NULL;
151 #endif // wxUSE_CONSTRAINTS
152
153 m_windowSizer = (wxSizer *) NULL;
154 m_containingSizer = (wxSizer *) NULL;
155 m_autoLayout = false;
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 #if wxUSE_PALETTE
170 m_hasCustomPalette = false;
171 #endif // wxUSE_PALETTE
172
173 #if wxUSE_ACCESSIBILITY
174 m_accessible = NULL;
175 #endif
176
177 m_virtualSize = wxDefaultSize;
178
179 m_minVirtualWidth =
180 m_minVirtualHeight =
181 m_maxVirtualWidth =
182 m_maxVirtualHeight = -1;
183
184 m_windowVariant = wxWINDOW_VARIANT_NORMAL;
185
186 // Whether we're using the current theme for this window (wxGTK only for now)
187 m_themeEnabled = false;
188
189 // VZ: this one shouldn't exist...
190 m_isBeingDeleted = false;
191 }
192
193 // common part of window creation process
194 bool wxWindowBase::CreateBase(wxWindowBase *parent,
195 wxWindowID id,
196 const wxPoint& WXUNUSED(pos),
197 const wxSize& WXUNUSED(size),
198 long style,
199 const wxValidator& wxVALIDATOR_PARAM(validator),
200 const wxString& name)
201 {
202 #if wxUSE_STATBOX
203 // wxGTK doesn't allow to create controls with static box as the parent so
204 // this will result in a crash when the program is ported to wxGTK so warn
205 // the user about it
206
207 // if you get this assert, the correct solution is to create the controls
208 // as siblings of the static box
209 wxASSERT_MSG( !parent || !wxDynamicCast(parent, wxStaticBox),
210 _T("wxStaticBox can't be used as a window parent!") );
211 #endif // wxUSE_STATBOX
212
213 // ids are limited to 16 bits under MSW so if you care about portability,
214 // it's not a good idea to use ids out of this range (and negative ids are
215 // reserved for wxWindows own usage)
216 wxASSERT_MSG( id == wxID_ANY || (id >= 0 && id < 32767),
217 _T("invalid id value") );
218
219 // generate a new id if the user doesn't care about it
220 m_windowId = id == wxID_ANY ? NewControlId() : id;
221
222 SetName(name);
223 SetWindowStyleFlag(style);
224 SetParent(parent);
225
226 #if wxUSE_VALIDATORS
227 SetValidator(validator);
228 #endif // wxUSE_VALIDATORS
229
230 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
231 // have it too - like this it's possible to set it only in the top level
232 // dialog/frame and all children will inherit it by defult
233 if ( parent && (parent->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) )
234 {
235 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
236 }
237
238 return true;
239 }
240
241 // ----------------------------------------------------------------------------
242 // destruction
243 // ----------------------------------------------------------------------------
244
245 // common clean up
246 wxWindowBase::~wxWindowBase()
247 {
248 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
249
250 // FIXME if these 2 cases result from programming errors in the user code
251 // we should probably assert here instead of silently fixing them
252
253 // Just in case the window has been Closed, but we're then deleting
254 // immediately: don't leave dangling pointers.
255 wxPendingDelete.DeleteObject(this);
256
257 // Just in case we've loaded a top-level window via LoadNativeDialog but
258 // we weren't a dialog class
259 wxTopLevelWindows.DeleteObject((wxWindow*)this);
260
261 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
262
263 // reset the dangling pointer our parent window may keep to us
264 if ( m_parent )
265 {
266 if ( m_parent->GetDefaultItem() == this )
267 {
268 m_parent->SetDefaultItem(NULL);
269 }
270
271 m_parent->RemoveChild(this);
272 }
273
274 #if wxUSE_CARET
275 delete m_caret;
276 #endif // wxUSE_CARET
277
278 #if wxUSE_VALIDATORS
279 delete m_windowValidator;
280 #endif // wxUSE_VALIDATORS
281
282 #if wxUSE_CONSTRAINTS
283 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
284 // at deleted windows as they delete themselves.
285 DeleteRelatedConstraints();
286
287 if ( m_constraints )
288 {
289 // This removes any dangling pointers to this window in other windows'
290 // constraintsInvolvedIn lists.
291 UnsetConstraints(m_constraints);
292 delete m_constraints;
293 m_constraints = NULL;
294 }
295 #endif // wxUSE_CONSTRAINTS
296
297 if ( m_containingSizer )
298 m_containingSizer->Detach( (wxWindow*)this );
299
300 delete m_windowSizer;
301
302 #if wxUSE_DRAG_AND_DROP
303 delete m_dropTarget;
304 #endif // wxUSE_DRAG_AND_DROP
305
306 #if wxUSE_TOOLTIPS
307 delete m_tooltip;
308 #endif // wxUSE_TOOLTIPS
309
310 #if wxUSE_ACCESSIBILITY
311 delete m_accessible;
312 #endif
313 }
314
315 bool wxWindowBase::Destroy()
316 {
317 delete this;
318
319 return true;
320 }
321
322 bool wxWindowBase::Close(bool force)
323 {
324 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
325 event.SetEventObject(this);
326 event.SetCanVeto(!force);
327
328 // return false if window wasn't closed because the application vetoed the
329 // close event
330 return GetEventHandler()->ProcessEvent(event) && !event.GetVeto();
331 }
332
333 bool wxWindowBase::DestroyChildren()
334 {
335 wxWindowList::compatibility_iterator node;
336 for ( ;; )
337 {
338 // we iterate until the list becomes empty
339 node = GetChildren().GetFirst();
340 if ( !node )
341 break;
342
343 wxWindow *child = node->GetData();
344
345 // note that we really want to call delete and not ->Destroy() here
346 // because we want to delete the child immediately, before we are
347 // deleted, and delayed deletion would result in problems as our (top
348 // level) child could outlive its parent
349 delete child;
350
351 wxASSERT_MSG( !GetChildren().Find(child),
352 wxT("child didn't remove itself using RemoveChild()") );
353 }
354
355 return true;
356 }
357
358 // ----------------------------------------------------------------------------
359 // size/position related methods
360 // ----------------------------------------------------------------------------
361
362 // centre the window with respect to its parent in either (or both) directions
363 void wxWindowBase::Centre(int direction)
364 {
365 // the position/size of the parent window or of the entire screen
366 wxPoint posParent;
367 int widthParent, heightParent;
368
369 wxWindow *parent = NULL;
370
371 if ( !(direction & wxCENTRE_ON_SCREEN) )
372 {
373 // find the parent to centre this window on: it should be the
374 // immediate parent for the controls but the top level parent for the
375 // top level windows (like dialogs)
376 parent = GetParent();
377 if ( IsTopLevel() )
378 {
379 while ( parent && !parent->IsTopLevel() )
380 {
381 parent = parent->GetParent();
382 }
383 }
384
385 // there is no wxTopLevelWindow under wxMotif yet
386 #ifndef __WXMOTIF__
387 // we shouldn't center the dialog on the iconized window: under
388 // Windows, for example, this places it completely off the screen
389 if ( parent )
390 {
391 wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
392 if ( winTop && winTop->IsIconized() )
393 {
394 parent = NULL;
395 }
396 }
397 #endif // __WXMOTIF__
398
399 // did we find the parent?
400 if ( !parent )
401 {
402 // no other choice
403 direction |= wxCENTRE_ON_SCREEN;
404 }
405 }
406
407 if ( direction & wxCENTRE_ON_SCREEN )
408 {
409 // centre with respect to the whole screen
410 wxDisplaySize(&widthParent, &heightParent);
411 }
412 else
413 {
414 if ( IsTopLevel() )
415 {
416 // centre on the parent
417 parent->GetSize(&widthParent, &heightParent);
418
419 // adjust to the parents position
420 posParent = parent->GetPosition();
421 }
422 else
423 {
424 // centre inside the parents client rectangle
425 parent->GetClientSize(&widthParent, &heightParent);
426 }
427 }
428
429 int width, height;
430 GetSize(&width, &height);
431
432 int xNew = -1,
433 yNew = -1;
434
435 if ( direction & wxHORIZONTAL )
436 xNew = (widthParent - width)/2;
437
438 if ( direction & wxVERTICAL )
439 yNew = (heightParent - height)/2;
440
441 xNew += posParent.x;
442 yNew += posParent.y;
443
444 // Base size of the visible dimensions of the display
445 // to take into account the taskbar
446 wxRect rect = wxGetClientDisplayRect();
447 wxSize size (rect.width,rect.height);
448
449 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
450 // but it may mean that the window is placed on other than the main
451 // display. Therefore we only make sure centered window is on the main display
452 // if the parent is at least partially present here.
453 if (posParent.x + widthParent >= 0) // if parent is (partially) on the main display
454 {
455 if (xNew < 0)
456 xNew = 0;
457 else if (xNew+width > size.x)
458 xNew = size.x-width-1;
459 }
460 if (posParent.y + heightParent >= 0) // if parent is (partially) on the main display
461 {
462 if (yNew+height > size.y)
463 yNew = size.y-height-1;
464
465 // Make certain that the title bar is initially visible
466 // always, even if this would push the bottom of the
467 // dialog of the visible area of the display
468 if (yNew < 0)
469 yNew = 0;
470 }
471
472 // move the window to this position (keeping the old size but using
473 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
474 SetSize(xNew, yNew, width, height, wxSIZE_ALLOW_MINUS_ONE);
475 }
476
477 // fits the window around the children
478 void wxWindowBase::Fit()
479 {
480 if ( GetChildren().GetCount() > 0 )
481 {
482 SetClientSize(DoGetBestSize());
483 }
484 //else: do nothing if we have no children
485 }
486
487 // fits virtual size (ie. scrolled area etc.) around children
488 void wxWindowBase::FitInside()
489 {
490 if ( GetChildren().GetCount() > 0 )
491 {
492 SetVirtualSize( GetBestVirtualSize() );
493 }
494 }
495
496 // return the size best suited for the current window
497 wxSize wxWindowBase::DoGetBestSize() const
498 {
499 if ( m_windowSizer )
500 {
501 return m_windowSizer->GetMinSize();
502 }
503 #if wxUSE_CONSTRAINTS
504 else if ( m_constraints )
505 {
506 wxConstCast(this, wxWindowBase)->SatisfyConstraints();
507
508 // our minimal acceptable size is such that all our windows fit inside
509 int maxX = 0,
510 maxY = 0;
511
512 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
513 node;
514 node = node->GetNext() )
515 {
516 wxLayoutConstraints *c = node->GetData()->GetConstraints();
517 if ( !c )
518 {
519 // it's not normal that we have an unconstrained child, but
520 // what can we do about it?
521 continue;
522 }
523
524 int x = c->right.GetValue(),
525 y = c->bottom.GetValue();
526
527 if ( x > maxX )
528 maxX = x;
529
530 if ( y > maxY )
531 maxY = y;
532
533 // TODO: we must calculate the overlaps somehow, otherwise we
534 // will never return a size bigger than the current one :-(
535 }
536
537 return wxSize(maxX, maxY);
538 }
539 #endif // wxUSE_CONSTRAINTS
540 else if ( GetChildren().GetCount() > 0 )
541 {
542 // our minimal acceptable size is such that all our windows fit inside
543 int maxX = 0,
544 maxY = 0;
545
546 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
547 node;
548 node = node->GetNext() )
549 {
550 wxWindow *win = node->GetData();
551 if ( win->IsTopLevel()
552 #if wxUSE_STATUSBAR
553 || wxDynamicCast(win, wxStatusBar)
554 #endif // wxUSE_STATUSBAR
555 )
556 {
557 // dialogs and frames lie in different top level windows -
558 // don't deal with them here; as for the status bars, they
559 // don't lie in the client area at all
560 continue;
561 }
562
563 int wx, wy, ww, wh;
564 win->GetPosition(&wx, &wy);
565
566 // if the window hadn't been positioned yet, assume that it is in
567 // the origin
568 if ( wx == -1 )
569 wx = 0;
570 if ( wy == -1 )
571 wy = 0;
572
573 win->GetSize(&ww, &wh);
574 if ( wx + ww > maxX )
575 maxX = wx + ww;
576 if ( wy + wh > maxY )
577 maxY = wy + wh;
578 }
579
580 // for compatibility with the old versions and because it really looks
581 // slightly more pretty like this, add a pad
582 maxX += 7;
583 maxY += 14;
584
585 return wxSize(maxX, maxY);
586 }
587 else
588 {
589 // Windows which don't implement DoGetBestSize and aren't parents.
590 // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
591
592 // If you get the following message you should do one of two things
593 // 1. Do what it says (best)
594 // 2. m_bestSize = GetSize() at end of Create() (hack)
595 if(m_bestSize == wxDefaultSize)
596 {
597 wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
598 wxConstCast(this,wxWindowBase)->m_bestSize = GetSize();
599 }
600 return m_bestSize;
601 }
602 }
603
604 // by default the origin is not shifted
605 wxPoint wxWindowBase::GetClientAreaOrigin() const
606 {
607 return wxPoint(0, 0);
608 }
609
610 // set the min/max size of the window
611 void wxWindowBase::SetSizeHints(int minW, int minH,
612 int maxW, int maxH,
613 int WXUNUSED(incW), int WXUNUSED(incH))
614 {
615 // setting min width greater than max width leads to infinite loops under
616 // X11 and generally doesn't make any sense, so don't allow it
617 wxCHECK_RET( (minW == -1 || maxW == -1 || minW <= maxW) &&
618 (minH == -1 || maxH == -1 || minH <= maxH),
619 _T("min width/height must be less than max width/height!") );
620
621 m_minWidth = minW;
622 m_maxWidth = maxW;
623 m_minHeight = minH;
624 m_maxHeight = maxH;
625 }
626
627 void wxWindowBase::SetWindowVariant( wxWindowVariant variant )
628 {
629 if ( m_windowVariant != variant )
630 {
631 m_windowVariant = variant;
632
633 DoSetWindowVariant(variant);
634 }
635 }
636
637 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
638 {
639 // adjust the font height to correspond to our new variant (notice that
640 // we're only called if something really changed)
641 wxFont font = GetFont();
642 int size = font.GetPointSize();
643 switch ( variant )
644 {
645 case wxWINDOW_VARIANT_NORMAL:
646 break;
647
648 case wxWINDOW_VARIANT_SMALL:
649 size *= 3;
650 size /= 4;
651 break;
652
653 case wxWINDOW_VARIANT_MINI:
654 size *= 2;
655 size /= 3;
656 break;
657
658 case wxWINDOW_VARIANT_LARGE:
659 size *= 5;
660 size /= 4;
661 break;
662
663 default:
664 wxFAIL_MSG(_T("unexpected window variant"));
665 break;
666 }
667
668 font.SetPointSize(size);
669 SetFont(font);
670 }
671
672 void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
673 int maxW, int maxH )
674 {
675 m_minVirtualWidth = minW;
676 m_maxVirtualWidth = maxW;
677 m_minVirtualHeight = minH;
678 m_maxVirtualHeight = maxH;
679 }
680
681 void wxWindowBase::DoSetVirtualSize( int x, int y )
682 {
683 if ( m_minVirtualWidth != -1 && m_minVirtualWidth > x )
684 x = m_minVirtualWidth;
685 if ( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x )
686 x = m_maxVirtualWidth;
687 if ( m_minVirtualHeight != -1 && m_minVirtualHeight > y )
688 y = m_minVirtualHeight;
689 if ( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y )
690 y = m_maxVirtualHeight;
691
692 m_virtualSize = wxSize(x, y);
693 }
694
695 wxSize wxWindowBase::DoGetVirtualSize() const
696 {
697 wxSize s( GetClientSize() );
698
699 return wxSize( wxMax( m_virtualSize.GetWidth(), s.GetWidth() ),
700 wxMax( m_virtualSize.GetHeight(), s.GetHeight() ) );
701 }
702
703 // ----------------------------------------------------------------------------
704 // show/hide/enable/disable the window
705 // ----------------------------------------------------------------------------
706
707 bool wxWindowBase::Show(bool show)
708 {
709 if ( show != m_isShown )
710 {
711 m_isShown = show;
712
713 return true;
714 }
715 else
716 {
717 return false;
718 }
719 }
720
721 bool wxWindowBase::Enable(bool enable)
722 {
723 if ( enable != m_isEnabled )
724 {
725 m_isEnabled = enable;
726
727 return true;
728 }
729 else
730 {
731 return false;
732 }
733 }
734 // ----------------------------------------------------------------------------
735 // RTTI
736 // ----------------------------------------------------------------------------
737
738 bool wxWindowBase::IsTopLevel() const
739 {
740 return false;
741 }
742
743 // ----------------------------------------------------------------------------
744 // reparenting the window
745 // ----------------------------------------------------------------------------
746
747 void wxWindowBase::AddChild(wxWindowBase *child)
748 {
749 wxCHECK_RET( child, wxT("can't add a NULL child") );
750
751 // this should never happen and it will lead to a crash later if it does
752 // because RemoveChild() will remove only one node from the children list
753 // and the other(s) one(s) will be left with dangling pointers in them
754 wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") );
755
756 GetChildren().Append((wxWindow*)child);
757 child->SetParent(this);
758 }
759
760 void wxWindowBase::RemoveChild(wxWindowBase *child)
761 {
762 wxCHECK_RET( child, wxT("can't remove a NULL child") );
763
764 GetChildren().DeleteObject((wxWindow *)child);
765 child->SetParent(NULL);
766 }
767
768 bool wxWindowBase::Reparent(wxWindowBase *newParent)
769 {
770 wxWindow *oldParent = GetParent();
771 if ( newParent == oldParent )
772 {
773 // nothing done
774 return false;
775 }
776
777 // unlink this window from the existing parent.
778 if ( oldParent )
779 {
780 oldParent->RemoveChild(this);
781 }
782 else
783 {
784 wxTopLevelWindows.DeleteObject((wxWindow *)this);
785 }
786
787 // add it to the new one
788 if ( newParent )
789 {
790 newParent->AddChild(this);
791 }
792 else
793 {
794 wxTopLevelWindows.Append((wxWindow *)this);
795 }
796
797 return true;
798 }
799
800 // ----------------------------------------------------------------------------
801 // event handler stuff
802 // ----------------------------------------------------------------------------
803
804 void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
805 {
806 wxEvtHandler *handlerOld = GetEventHandler();
807
808 handler->SetNextHandler(handlerOld);
809
810 if ( handlerOld )
811 GetEventHandler()->SetPreviousHandler(handler);
812
813 SetEventHandler(handler);
814 }
815
816 wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
817 {
818 wxEvtHandler *handlerA = GetEventHandler();
819 if ( handlerA )
820 {
821 wxEvtHandler *handlerB = handlerA->GetNextHandler();
822 handlerA->SetNextHandler((wxEvtHandler *)NULL);
823
824 if ( handlerB )
825 handlerB->SetPreviousHandler((wxEvtHandler *)NULL);
826 SetEventHandler(handlerB);
827
828 if ( deleteHandler )
829 {
830 delete handlerA;
831 handlerA = (wxEvtHandler *)NULL;
832 }
833 }
834
835 return handlerA;
836 }
837
838 bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
839 {
840 wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") );
841
842 wxEvtHandler *handlerPrev = NULL,
843 *handlerCur = GetEventHandler();
844 while ( handlerCur )
845 {
846 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
847
848 if ( handlerCur == handler )
849 {
850 if ( handlerPrev )
851 {
852 handlerPrev->SetNextHandler(handlerNext);
853 }
854 else
855 {
856 SetEventHandler(handlerNext);
857 }
858
859 if ( handlerNext )
860 {
861 handlerNext->SetPreviousHandler ( handlerPrev );
862 }
863
864 handler->SetNextHandler(NULL);
865 handler->SetPreviousHandler(NULL);
866
867 return true;
868 }
869
870 handlerPrev = handlerCur;
871 handlerCur = handlerNext;
872 }
873
874 wxFAIL_MSG( _T("where has the event handler gone?") );
875
876 return false;
877 }
878
879 // ----------------------------------------------------------------------------
880 // colours, fonts &c
881 // ----------------------------------------------------------------------------
882
883 /* static */ wxVisualAttributes
884 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
885 {
886 // it is important to return valid values for all attributes from here,
887 // GetXXX() below rely on this
888 wxVisualAttributes attrs;
889 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
890 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
891 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
892
893 return attrs;
894 }
895
896 wxColour wxWindowBase::GetBackgroundColour() const
897 {
898 if ( !m_backgroundColour.Ok() )
899 {
900 wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") );
901
902 // get our default background colour
903 wxColour colBg = GetDefaultAttributes().colBg;
904
905 // we must return some valid colour to avoid redoing this every time
906 // and also to avoid surprizing the applications written for older
907 // wxWindows versions where GetBackgroundColour() always returned
908 // something -- so give them something even if it doesn't make sense
909 // for this window (e.g. it has a themed background)
910 if ( !colBg.Ok() )
911 colBg = GetClassDefaultAttributes().colBg;
912
913 // cache it for the next call
914 wxConstCast(this, wxWindowBase)->m_backgroundColour = colBg;
915 }
916
917 return m_backgroundColour;
918 }
919
920 wxColour wxWindowBase::GetForegroundColour() const
921 {
922 // logic is the same as above
923 if ( !m_hasFgCol && !m_foregroundColour.Ok() )
924 {
925 wxASSERT_MSG( !m_hasFgCol, _T("we have invalid explicit fg colour?") );
926
927 wxColour colFg = GetDefaultAttributes().colFg;
928
929 if ( !colFg.Ok() )
930 colFg = GetClassDefaultAttributes().colFg;
931
932 wxConstCast(this, wxWindowBase)->m_foregroundColour = colFg;
933 }
934
935 return m_foregroundColour;
936 }
937
938 bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
939 {
940 if ( !colour.Ok() || (colour == m_backgroundColour) )
941 return false;
942
943 m_backgroundColour = colour;
944
945 m_hasBgCol = true;
946
947 return true;
948 }
949
950 bool wxWindowBase::SetForegroundColour( const wxColour &colour )
951 {
952 if ( !colour.Ok() || (colour == m_foregroundColour) )
953 return false;
954
955 m_foregroundColour = colour;
956
957 m_hasFgCol = true;
958
959 return true;
960 }
961
962 bool wxWindowBase::SetCursor(const wxCursor& cursor)
963 {
964 // setting an invalid cursor is ok, it means that we don't have any special
965 // cursor
966 if ( m_cursor == cursor )
967 {
968 // no change
969 return false;
970 }
971
972 m_cursor = cursor;
973
974 return true;
975 }
976
977 wxFont& wxWindowBase::DoGetFont() const
978 {
979 // logic is the same as in GetBackgroundColour()
980 if ( !m_font.Ok() )
981 {
982 wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") );
983
984 wxFont font = GetDefaultAttributes().font;
985 if ( !font.Ok() )
986 font = GetClassDefaultAttributes().font;
987
988 wxConstCast(this, wxWindowBase)->m_font = font;
989 }
990
991 // cast is here for non-const GetFont() convenience
992 return wxConstCast(this, wxWindowBase)->m_font;
993 }
994
995 bool wxWindowBase::SetFont(const wxFont& font)
996 {
997 if ( !font.Ok() )
998 return false;
999
1000 if ( font == m_font )
1001 {
1002 // no change
1003 return false;
1004 }
1005
1006 m_font = font;
1007
1008 m_hasFont = true;
1009
1010 return true;
1011 }
1012
1013 #if wxUSE_PALETTE
1014
1015 void wxWindowBase::SetPalette(const wxPalette& pal)
1016 {
1017 m_hasCustomPalette = true;
1018 m_palette = pal;
1019
1020 // VZ: can anyone explain me what do we do here?
1021 wxWindowDC d((wxWindow *) this);
1022 d.SetPalette(pal);
1023 }
1024
1025 wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
1026 {
1027 wxWindow *win = (wxWindow *)this;
1028 while ( win && !win->HasCustomPalette() )
1029 {
1030 win = win->GetParent();
1031 }
1032
1033 return win;
1034 }
1035
1036 #endif // wxUSE_PALETTE
1037
1038 #if wxUSE_CARET
1039 void wxWindowBase::SetCaret(wxCaret *caret)
1040 {
1041 if ( m_caret )
1042 {
1043 delete m_caret;
1044 }
1045
1046 m_caret = caret;
1047
1048 if ( m_caret )
1049 {
1050 wxASSERT_MSG( m_caret->GetWindow() == this,
1051 wxT("caret should be created associated to this window") );
1052 }
1053 }
1054 #endif // wxUSE_CARET
1055
1056 #if wxUSE_VALIDATORS
1057 // ----------------------------------------------------------------------------
1058 // validators
1059 // ----------------------------------------------------------------------------
1060
1061 void wxWindowBase::SetValidator(const wxValidator& validator)
1062 {
1063 if ( m_windowValidator )
1064 delete m_windowValidator;
1065
1066 m_windowValidator = (wxValidator *)validator.Clone();
1067
1068 if ( m_windowValidator )
1069 m_windowValidator->SetWindow(this);
1070 }
1071 #endif // wxUSE_VALIDATORS
1072
1073 // ----------------------------------------------------------------------------
1074 // update region stuff
1075 // ----------------------------------------------------------------------------
1076
1077 wxRect wxWindowBase::GetUpdateClientRect() const
1078 {
1079 wxRegion rgnUpdate = GetUpdateRegion();
1080 rgnUpdate.Intersect(GetClientRect());
1081 wxRect rectUpdate = rgnUpdate.GetBox();
1082 wxPoint ptOrigin = GetClientAreaOrigin();
1083 rectUpdate.x -= ptOrigin.x;
1084 rectUpdate.y -= ptOrigin.y;
1085
1086 return rectUpdate;
1087 }
1088
1089 bool wxWindowBase::IsExposed(int x, int y) const
1090 {
1091 return m_updateRegion.Contains(x, y) != wxOutRegion;
1092 }
1093
1094 bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
1095 {
1096 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
1097 }
1098
1099 void wxWindowBase::ClearBackground()
1100 {
1101 // wxGTK uses its own version, no need to add never used code
1102 #ifndef __WXGTK__
1103 wxClientDC dc((wxWindow *)this);
1104 wxBrush brush(GetBackgroundColour(), wxSOLID);
1105 dc.SetBackground(brush);
1106 dc.Clear();
1107 #endif // __WXGTK__
1108 }
1109
1110 // ----------------------------------------------------------------------------
1111 // find child window by id or name
1112 // ----------------------------------------------------------------------------
1113
1114 wxWindow *wxWindowBase::FindWindow( long id )
1115 {
1116 if ( id == m_windowId )
1117 return (wxWindow *)this;
1118
1119 wxWindowBase *res = (wxWindow *)NULL;
1120 wxWindowList::compatibility_iterator node;
1121 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1122 {
1123 wxWindowBase *child = node->GetData();
1124 res = child->FindWindow( id );
1125 }
1126
1127 return (wxWindow *)res;
1128 }
1129
1130 wxWindow *wxWindowBase::FindWindow( const wxString& name )
1131 {
1132 if ( name == m_windowName )
1133 return (wxWindow *)this;
1134
1135 wxWindowBase *res = (wxWindow *)NULL;
1136 wxWindowList::compatibility_iterator node;
1137 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1138 {
1139 wxWindow *child = node->GetData();
1140 res = child->FindWindow(name);
1141 }
1142
1143 return (wxWindow *)res;
1144 }
1145
1146
1147 // find any window by id or name or label: If parent is non-NULL, look through
1148 // children for a label or title matching the specified string. If NULL, look
1149 // through all top-level windows.
1150 //
1151 // to avoid duplicating code we reuse the same helper function but with
1152 // different comparators
1153
1154 typedef bool (*wxFindWindowCmp)(const wxWindow *win,
1155 const wxString& label, long id);
1156
1157 static
1158 bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
1159 long WXUNUSED(id))
1160 {
1161 return win->GetLabel() == label;
1162 }
1163
1164 static
1165 bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
1166 long WXUNUSED(id))
1167 {
1168 return win->GetName() == label;
1169 }
1170
1171 static
1172 bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
1173 long id)
1174 {
1175 return win->GetId() == id;
1176 }
1177
1178 // recursive helper for the FindWindowByXXX() functions
1179 static
1180 wxWindow *wxFindWindowRecursively(const wxWindow *parent,
1181 const wxString& label,
1182 long id,
1183 wxFindWindowCmp cmp)
1184 {
1185 if ( parent )
1186 {
1187 // see if this is the one we're looking for
1188 if ( (*cmp)(parent, label, id) )
1189 return (wxWindow *)parent;
1190
1191 // It wasn't, so check all its children
1192 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1193 node;
1194 node = node->GetNext() )
1195 {
1196 // recursively check each child
1197 wxWindow *win = (wxWindow *)node->GetData();
1198 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1199 if (retwin)
1200 return retwin;
1201 }
1202 }
1203
1204 // Not found
1205 return NULL;
1206 }
1207
1208 // helper for FindWindowByXXX()
1209 static
1210 wxWindow *wxFindWindowHelper(const wxWindow *parent,
1211 const wxString& label,
1212 long id,
1213 wxFindWindowCmp cmp)
1214 {
1215 if ( parent )
1216 {
1217 // just check parent and all its children
1218 return wxFindWindowRecursively(parent, label, id, cmp);
1219 }
1220
1221 // start at very top of wx's windows
1222 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1223 node;
1224 node = node->GetNext() )
1225 {
1226 // recursively check each window & its children
1227 wxWindow *win = node->GetData();
1228 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1229 if (retwin)
1230 return retwin;
1231 }
1232
1233 return NULL;
1234 }
1235
1236 /* static */
1237 wxWindow *
1238 wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
1239 {
1240 return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
1241 }
1242
1243 /* static */
1244 wxWindow *
1245 wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
1246 {
1247 wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
1248
1249 if ( !win )
1250 {
1251 // fall back to the label
1252 win = FindWindowByLabel(title, parent);
1253 }
1254
1255 return win;
1256 }
1257
1258 /* static */
1259 wxWindow *
1260 wxWindowBase::FindWindowById( long id, const wxWindow* parent )
1261 {
1262 return wxFindWindowHelper(parent, _T(""), id, wxFindWindowCmpIds);
1263 }
1264
1265 // ----------------------------------------------------------------------------
1266 // dialog oriented functions
1267 // ----------------------------------------------------------------------------
1268
1269 void wxWindowBase::MakeModal(bool modal)
1270 {
1271 // Disable all other windows
1272 if ( IsTopLevel() )
1273 {
1274 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1275 while (node)
1276 {
1277 wxWindow *win = node->GetData();
1278 if (win != this)
1279 win->Enable(!modal);
1280
1281 node = node->GetNext();
1282 }
1283 }
1284 }
1285
1286 bool wxWindowBase::Validate()
1287 {
1288 #if wxUSE_VALIDATORS
1289 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1290
1291 wxWindowList::compatibility_iterator node;
1292 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1293 {
1294 wxWindowBase *child = node->GetData();
1295 wxValidator *validator = child->GetValidator();
1296 if ( validator && !validator->Validate((wxWindow *)this) )
1297 {
1298 return false;
1299 }
1300
1301 if ( recurse && !child->Validate() )
1302 {
1303 return false;
1304 }
1305 }
1306 #endif // wxUSE_VALIDATORS
1307
1308 return true;
1309 }
1310
1311 bool wxWindowBase::TransferDataToWindow()
1312 {
1313 #if wxUSE_VALIDATORS
1314 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1315
1316 wxWindowList::compatibility_iterator node;
1317 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1318 {
1319 wxWindowBase *child = node->GetData();
1320 wxValidator *validator = child->GetValidator();
1321 if ( validator && !validator->TransferToWindow() )
1322 {
1323 wxLogWarning(_("Could not transfer data to window"));
1324 #if wxUSE_LOG
1325 wxLog::FlushActive();
1326 #endif // wxUSE_LOG
1327
1328 return false;
1329 }
1330
1331 if ( recurse )
1332 {
1333 if ( !child->TransferDataToWindow() )
1334 {
1335 // warning already given
1336 return false;
1337 }
1338 }
1339 }
1340 #endif // wxUSE_VALIDATORS
1341
1342 return true;
1343 }
1344
1345 bool wxWindowBase::TransferDataFromWindow()
1346 {
1347 #if wxUSE_VALIDATORS
1348 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1349
1350 wxWindowList::compatibility_iterator node;
1351 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1352 {
1353 wxWindow *child = node->GetData();
1354 wxValidator *validator = child->GetValidator();
1355 if ( validator && !validator->TransferFromWindow() )
1356 {
1357 // nop warning here because the application is supposed to give
1358 // one itself - we don't know here what might have gone wrongly
1359
1360 return false;
1361 }
1362
1363 if ( recurse )
1364 {
1365 if ( !child->TransferDataFromWindow() )
1366 {
1367 // warning already given
1368 return false;
1369 }
1370 }
1371 }
1372 #endif // wxUSE_VALIDATORS
1373
1374 return true;
1375 }
1376
1377 void wxWindowBase::InitDialog()
1378 {
1379 wxInitDialogEvent event(GetId());
1380 event.SetEventObject( this );
1381 GetEventHandler()->ProcessEvent(event);
1382 }
1383
1384 // ----------------------------------------------------------------------------
1385 // context-sensitive help support
1386 // ----------------------------------------------------------------------------
1387
1388 #if wxUSE_HELP
1389
1390 // associate this help text with this window
1391 void wxWindowBase::SetHelpText(const wxString& text)
1392 {
1393 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1394 if ( helpProvider )
1395 {
1396 helpProvider->AddHelp(this, text);
1397 }
1398 }
1399
1400 // associate this help text with all windows with the same id as this
1401 // one
1402 void wxWindowBase::SetHelpTextForId(const wxString& text)
1403 {
1404 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1405 if ( helpProvider )
1406 {
1407 helpProvider->AddHelp(GetId(), text);
1408 }
1409 }
1410
1411 // get the help string associated with this window (may be empty)
1412 wxString wxWindowBase::GetHelpText() const
1413 {
1414 wxString text;
1415 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1416 if ( helpProvider )
1417 {
1418 text = helpProvider->GetHelp(this);
1419 }
1420
1421 return text;
1422 }
1423
1424 // show help for this window
1425 void wxWindowBase::OnHelp(wxHelpEvent& event)
1426 {
1427 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1428 if ( helpProvider )
1429 {
1430 if ( helpProvider->ShowHelp(this) )
1431 {
1432 // skip the event.Skip() below
1433 return;
1434 }
1435 }
1436
1437 event.Skip();
1438 }
1439
1440 #endif // wxUSE_HELP
1441
1442 // ----------------------------------------------------------------------------
1443 // tooltipsroot.Replace("\\", "/");
1444 // ----------------------------------------------------------------------------
1445
1446 #if wxUSE_TOOLTIPS
1447
1448 void wxWindowBase::SetToolTip( const wxString &tip )
1449 {
1450 // don't create the new tooltip if we already have one
1451 if ( m_tooltip )
1452 {
1453 m_tooltip->SetTip( tip );
1454 }
1455 else
1456 {
1457 SetToolTip( new wxToolTip( tip ) );
1458 }
1459
1460 // setting empty tooltip text does not remove the tooltip any more - use
1461 // SetToolTip((wxToolTip *)NULL) for this
1462 }
1463
1464 void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1465 {
1466 if ( m_tooltip )
1467 delete m_tooltip;
1468
1469 m_tooltip = tooltip;
1470 }
1471
1472 #endif // wxUSE_TOOLTIPS
1473
1474 // ----------------------------------------------------------------------------
1475 // constraints and sizers
1476 // ----------------------------------------------------------------------------
1477
1478 #if wxUSE_CONSTRAINTS
1479
1480 void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1481 {
1482 if ( m_constraints )
1483 {
1484 UnsetConstraints(m_constraints);
1485 delete m_constraints;
1486 }
1487 m_constraints = constraints;
1488 if ( m_constraints )
1489 {
1490 // Make sure other windows know they're part of a 'meaningful relationship'
1491 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1492 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1493 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1494 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1495 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1496 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1497 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1498 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1499 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1500 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1501 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1502 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1503 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1504 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1505 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1506 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
1507 }
1508 }
1509
1510 // This removes any dangling pointers to this window in other windows'
1511 // constraintsInvolvedIn lists.
1512 void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
1513 {
1514 if ( c )
1515 {
1516 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1517 c->left.GetOtherWindow()->RemoveConstraintReference(this);
1518 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1519 c->top.GetOtherWindow()->RemoveConstraintReference(this);
1520 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
1521 c->right.GetOtherWindow()->RemoveConstraintReference(this);
1522 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
1523 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
1524 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1525 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1526 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1527 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1528 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1529 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1530 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1531 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1532 }
1533 }
1534
1535 // Back-pointer to other windows we're involved with, so if we delete this
1536 // window, we must delete any constraints we're involved with.
1537 void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1538 {
1539 if ( !m_constraintsInvolvedIn )
1540 m_constraintsInvolvedIn = new wxWindowList;
1541 if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) )
1542 m_constraintsInvolvedIn->Append((wxWindow *)otherWin);
1543 }
1544
1545 // REMOVE back-pointer to other windows we're involved with.
1546 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1547 {
1548 if ( m_constraintsInvolvedIn )
1549 m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin);
1550 }
1551
1552 // Reset any constraints that mention this window
1553 void wxWindowBase::DeleteRelatedConstraints()
1554 {
1555 if ( m_constraintsInvolvedIn )
1556 {
1557 wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst();
1558 while (node)
1559 {
1560 wxWindow *win = node->GetData();
1561 wxLayoutConstraints *constr = win->GetConstraints();
1562
1563 // Reset any constraints involving this window
1564 if ( constr )
1565 {
1566 constr->left.ResetIfWin(this);
1567 constr->top.ResetIfWin(this);
1568 constr->right.ResetIfWin(this);
1569 constr->bottom.ResetIfWin(this);
1570 constr->width.ResetIfWin(this);
1571 constr->height.ResetIfWin(this);
1572 constr->centreX.ResetIfWin(this);
1573 constr->centreY.ResetIfWin(this);
1574 }
1575
1576 wxWindowList::compatibility_iterator next = node->GetNext();
1577 m_constraintsInvolvedIn->Erase(node);
1578 node = next;
1579 }
1580
1581 delete m_constraintsInvolvedIn;
1582 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1583 }
1584 }
1585
1586 #endif // wxUSE_CONSTRAINTS
1587
1588 void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
1589 {
1590 if ( sizer == m_windowSizer)
1591 return;
1592
1593 if ( deleteOld )
1594 delete m_windowSizer;
1595
1596 m_windowSizer = sizer;
1597
1598 SetAutoLayout( sizer != NULL );
1599 }
1600
1601 void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
1602 {
1603 SetSizer( sizer, deleteOld );
1604 sizer->SetSizeHints( (wxWindow*) this );
1605 }
1606
1607 #if wxUSE_CONSTRAINTS
1608
1609 void wxWindowBase::SatisfyConstraints()
1610 {
1611 wxLayoutConstraints *constr = GetConstraints();
1612 bool wasOk = constr && constr->AreSatisfied();
1613
1614 ResetConstraints(); // Mark all constraints as unevaluated
1615
1616 int noChanges = 1;
1617
1618 // if we're a top level panel (i.e. our parent is frame/dialog), our
1619 // own constraints will never be satisfied any more unless we do it
1620 // here
1621 if ( wasOk )
1622 {
1623 while ( noChanges > 0 )
1624 {
1625 LayoutPhase1(&noChanges);
1626 }
1627 }
1628
1629 LayoutPhase2(&noChanges);
1630 }
1631
1632 #endif // wxUSE_CONSTRAINTS
1633
1634 bool wxWindowBase::Layout()
1635 {
1636 // If there is a sizer, use it instead of the constraints
1637 if ( GetSizer() )
1638 {
1639 int w, h;
1640 GetVirtualSize(&w, &h);
1641 GetSizer()->SetDimension( 0, 0, w, h );
1642 }
1643 #if wxUSE_CONSTRAINTS
1644 else
1645 {
1646 SatisfyConstraints(); // Find the right constraints values
1647 SetConstraintSizes(); // Recursively set the real window sizes
1648 }
1649 #endif
1650
1651 return true;
1652 }
1653
1654 #if wxUSE_CONSTRAINTS
1655
1656 // first phase of the constraints evaluation: set our own constraints
1657 bool wxWindowBase::LayoutPhase1(int *noChanges)
1658 {
1659 wxLayoutConstraints *constr = GetConstraints();
1660
1661 return !constr || constr->SatisfyConstraints(this, noChanges);
1662 }
1663
1664 // second phase: set the constraints for our children
1665 bool wxWindowBase::LayoutPhase2(int *noChanges)
1666 {
1667 *noChanges = 0;
1668
1669 // Layout children
1670 DoPhase(1);
1671
1672 // Layout grand children
1673 DoPhase(2);
1674
1675 return true;
1676 }
1677
1678 // Do a phase of evaluating child constraints
1679 bool wxWindowBase::DoPhase(int phase)
1680 {
1681 // the list containing the children for which the constraints are already
1682 // set correctly
1683 wxWindowList succeeded;
1684
1685 // the max number of iterations we loop before concluding that we can't set
1686 // the constraints
1687 static const int maxIterations = 500;
1688
1689 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
1690 {
1691 int noChanges = 0;
1692
1693 // loop over all children setting their constraints
1694 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1695 node;
1696 node = node->GetNext() )
1697 {
1698 wxWindow *child = node->GetData();
1699 if ( child->IsTopLevel() )
1700 {
1701 // top level children are not inside our client area
1702 continue;
1703 }
1704
1705 if ( !child->GetConstraints() || succeeded.Find(child) )
1706 {
1707 // this one is either already ok or nothing we can do about it
1708 continue;
1709 }
1710
1711 int tempNoChanges = 0;
1712 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
1713 : child->LayoutPhase2(&tempNoChanges);
1714 noChanges += tempNoChanges;
1715
1716 if ( success )
1717 {
1718 succeeded.Append(child);
1719 }
1720 }
1721
1722 if ( !noChanges )
1723 {
1724 // constraints are set
1725 break;
1726 }
1727 }
1728
1729 return true;
1730 }
1731
1732 void wxWindowBase::ResetConstraints()
1733 {
1734 wxLayoutConstraints *constr = GetConstraints();
1735 if ( constr )
1736 {
1737 constr->left.SetDone(false);
1738 constr->top.SetDone(false);
1739 constr->right.SetDone(false);
1740 constr->bottom.SetDone(false);
1741 constr->width.SetDone(false);
1742 constr->height.SetDone(false);
1743 constr->centreX.SetDone(false);
1744 constr->centreY.SetDone(false);
1745 }
1746
1747 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1748 while (node)
1749 {
1750 wxWindow *win = node->GetData();
1751 if ( !win->IsTopLevel() )
1752 win->ResetConstraints();
1753 node = node->GetNext();
1754 }
1755 }
1756
1757 // Need to distinguish between setting the 'fake' size for windows and sizers,
1758 // and setting the real values.
1759 void wxWindowBase::SetConstraintSizes(bool recurse)
1760 {
1761 wxLayoutConstraints *constr = GetConstraints();
1762 if ( constr && constr->AreSatisfied() )
1763 {
1764 int x = constr->left.GetValue();
1765 int y = constr->top.GetValue();
1766 int w = constr->width.GetValue();
1767 int h = constr->height.GetValue();
1768
1769 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1770 (constr->height.GetRelationship() != wxAsIs) )
1771 {
1772 SetSize(x, y, w, h);
1773 }
1774 else
1775 {
1776 // If we don't want to resize this window, just move it...
1777 Move(x, y);
1778 }
1779 }
1780 else if ( constr )
1781 {
1782 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1783 GetClassInfo()->GetClassName(),
1784 GetName().c_str());
1785 }
1786
1787 if ( recurse )
1788 {
1789 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1790 while (node)
1791 {
1792 wxWindow *win = node->GetData();
1793 if ( !win->IsTopLevel() && win->GetConstraints() )
1794 win->SetConstraintSizes();
1795 node = node->GetNext();
1796 }
1797 }
1798 }
1799
1800 // Only set the size/position of the constraint (if any)
1801 void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1802 {
1803 wxLayoutConstraints *constr = GetConstraints();
1804 if ( constr )
1805 {
1806 if ( x != -1 )
1807 {
1808 constr->left.SetValue(x);
1809 constr->left.SetDone(true);
1810 }
1811 if ( y != -1 )
1812 {
1813 constr->top.SetValue(y);
1814 constr->top.SetDone(true);
1815 }
1816 if ( w != -1 )
1817 {
1818 constr->width.SetValue(w);
1819 constr->width.SetDone(true);
1820 }
1821 if ( h != -1 )
1822 {
1823 constr->height.SetValue(h);
1824 constr->height.SetDone(true);
1825 }
1826 }
1827 }
1828
1829 void wxWindowBase::MoveConstraint(int x, int y)
1830 {
1831 wxLayoutConstraints *constr = GetConstraints();
1832 if ( constr )
1833 {
1834 if ( x != -1 )
1835 {
1836 constr->left.SetValue(x);
1837 constr->left.SetDone(true);
1838 }
1839 if ( y != -1 )
1840 {
1841 constr->top.SetValue(y);
1842 constr->top.SetDone(true);
1843 }
1844 }
1845 }
1846
1847 void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1848 {
1849 wxLayoutConstraints *constr = GetConstraints();
1850 if ( constr )
1851 {
1852 *w = constr->width.GetValue();
1853 *h = constr->height.GetValue();
1854 }
1855 else
1856 GetSize(w, h);
1857 }
1858
1859 void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1860 {
1861 wxLayoutConstraints *constr = GetConstraints();
1862 if ( constr )
1863 {
1864 *w = constr->width.GetValue();
1865 *h = constr->height.GetValue();
1866 }
1867 else
1868 GetClientSize(w, h);
1869 }
1870
1871 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1872 {
1873 wxLayoutConstraints *constr = GetConstraints();
1874 if ( constr )
1875 {
1876 *x = constr->left.GetValue();
1877 *y = constr->top.GetValue();
1878 }
1879 else
1880 GetPosition(x, y);
1881 }
1882
1883 #endif // wxUSE_CONSTRAINTS
1884
1885 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
1886 {
1887 // don't do it for the dialogs/frames - they float independently of their
1888 // parent
1889 if ( !IsTopLevel() )
1890 {
1891 wxWindow *parent = GetParent();
1892 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
1893 {
1894 wxPoint pt(parent->GetClientAreaOrigin());
1895 x += pt.x;
1896 y += pt.y;
1897 }
1898 }
1899 }
1900
1901 // ----------------------------------------------------------------------------
1902 // do Update UI processing for child controls
1903 // ----------------------------------------------------------------------------
1904
1905 void wxWindowBase::UpdateWindowUI(long flags)
1906 {
1907 wxUpdateUIEvent event(GetId());
1908 event.m_eventObject = this;
1909
1910 if ( GetEventHandler()->ProcessEvent(event) )
1911 {
1912 DoUpdateWindowUI(event);
1913 }
1914
1915 if (flags & wxUPDATE_UI_RECURSE)
1916 {
1917 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1918 while (node)
1919 {
1920 wxWindow* child = (wxWindow*) node->GetData();
1921 child->UpdateWindowUI(flags);
1922 node = node->GetNext();
1923 }
1924 }
1925 }
1926
1927 // do the window-specific processing after processing the update event
1928 // TODO: take specific knowledge out of this function and
1929 // put in each control's base class. Unfortunately we don't
1930 // yet have base implementation files for wxCheckBox and wxRadioButton.
1931 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
1932 {
1933 if ( event.GetSetEnabled() )
1934 Enable(event.GetEnabled());
1935
1936 #if wxUSE_CONTROLS
1937 if ( event.GetSetText() )
1938 {
1939 wxControl *control = wxDynamicCastThis(wxControl);
1940 if ( control )
1941 {
1942 if ( event.GetText() != control->GetLabel() )
1943 control->SetLabel(event.GetText());
1944 }
1945 #if wxUSE_CHECKBOX
1946 wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
1947 if ( checkbox )
1948 {
1949 if ( event.GetSetChecked() )
1950 checkbox->SetValue(event.GetChecked());
1951 }
1952 #endif // wxUSE_CHECKBOX
1953
1954 #if wxUSE_RADIOBTN
1955 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
1956 if ( radiobtn )
1957 {
1958 if ( event.GetSetChecked() )
1959 radiobtn->SetValue(event.GetChecked());
1960 }
1961 #endif // wxUSE_RADIOBTN
1962 }
1963 #endif
1964 }
1965
1966 #if 0
1967 // call internal idle recursively
1968 // may be obsolete (wait until OnIdle scheme stabilises)
1969 void wxWindowBase::ProcessInternalIdle()
1970 {
1971 OnInternalIdle();
1972
1973 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1974 while (node)
1975 {
1976 wxWindow *child = node->GetData();
1977 child->ProcessInternalIdle();
1978 node = node->GetNext();
1979 }
1980 }
1981 #endif
1982
1983 // ----------------------------------------------------------------------------
1984 // dialog units translations
1985 // ----------------------------------------------------------------------------
1986
1987 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
1988 {
1989 int charWidth = GetCharWidth();
1990 int charHeight = GetCharHeight();
1991 wxPoint pt2(-1, -1);
1992 if (pt.x != -1)
1993 pt2.x = (int) ((pt.x * 4) / charWidth);
1994 if (pt.y != -1)
1995 pt2.y = (int) ((pt.y * 8) / charHeight);
1996
1997 return pt2;
1998 }
1999
2000 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
2001 {
2002 int charWidth = GetCharWidth();
2003 int charHeight = GetCharHeight();
2004 wxPoint pt2(-1, -1);
2005 if (pt.x != -1)
2006 pt2.x = (int) ((pt.x * charWidth) / 4);
2007 if (pt.y != -1)
2008 pt2.y = (int) ((pt.y * charHeight) / 8);
2009
2010 return pt2;
2011 }
2012
2013 // ----------------------------------------------------------------------------
2014 // event handlers
2015 // ----------------------------------------------------------------------------
2016
2017 // propagate the colour change event to the subwindows
2018 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
2019 {
2020 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2021 while ( node )
2022 {
2023 // Only propagate to non-top-level windows
2024 wxWindow *win = node->GetData();
2025 if ( !win->IsTopLevel() )
2026 {
2027 wxSysColourChangedEvent event2;
2028 event.m_eventObject = win;
2029 win->GetEventHandler()->ProcessEvent(event2);
2030 }
2031
2032 node = node->GetNext();
2033 }
2034 }
2035
2036 // the default action is to populate dialog with data when it's created,
2037 // and nudge the UI into displaying itself correctly in case
2038 // we've turned the wxUpdateUIEvents frequency down low.
2039 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
2040 {
2041 TransferDataToWindow();
2042
2043 // Update the UI at this point
2044 UpdateWindowUI(wxUPDATE_UI_RECURSE);
2045 }
2046
2047 // process Ctrl-Alt-mclick
2048 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
2049 {
2050 #if wxUSE_MSGDLG
2051 if ( event.ControlDown() && event.AltDown() )
2052 {
2053 // don't translate these strings
2054 wxString port;
2055
2056 #ifdef __WXUNIVERSAL__
2057 port = _T("Univ/");
2058 #endif // __WXUNIVERSAL__
2059
2060 switch ( wxGetOsVersion() )
2061 {
2062 case wxMOTIF_X: port += _T("Motif"); break;
2063 case wxMAC:
2064 case wxMAC_DARWIN: port += _T("Mac"); break;
2065 case wxBEOS: port += _T("BeOS"); break;
2066 case wxGTK:
2067 case wxGTK_WIN32:
2068 case wxGTK_OS2:
2069 case wxGTK_BEOS: port += _T("GTK"); break;
2070 case wxWINDOWS:
2071 case wxPENWINDOWS:
2072 case wxWINDOWS_NT:
2073 case wxWIN32S:
2074 case wxWIN95:
2075 case wxWIN386: port += _T("MS Windows"); break;
2076 case wxMGL_UNIX:
2077 case wxMGL_X:
2078 case wxMGL_WIN32:
2079 case wxMGL_OS2: port += _T("MGL"); break;
2080 case wxWINDOWS_OS2:
2081 case wxOS2_PM: port += _T("OS/2"); break;
2082 default: port += _T("unknown"); break;
2083 }
2084
2085 wxMessageBox(wxString::Format(
2086 _T(
2087 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2088 ),
2089 port.c_str(),
2090 wxMAJOR_VERSION,
2091 wxMINOR_VERSION,
2092 wxRELEASE_NUMBER,
2093 #if wxUSE_UNICODE
2094 L" (Unicode)",
2095 #else
2096 "",
2097 #endif
2098 __TDATE__,
2099 __TTIME__
2100 ),
2101 _T("wxWindows information"),
2102 wxICON_INFORMATION | wxOK,
2103 (wxWindow *)this);
2104 }
2105 else
2106 #endif // wxUSE_MSGDLG
2107 {
2108 event.Skip();
2109 }
2110 }
2111
2112 // ----------------------------------------------------------------------------
2113 // accessibility
2114 // ----------------------------------------------------------------------------
2115
2116 #if wxUSE_ACCESSIBILITY
2117 void wxWindowBase::SetAccessible(wxAccessible* accessible)
2118 {
2119 if (m_accessible && (accessible != m_accessible))
2120 delete m_accessible;
2121 m_accessible = accessible;
2122 if (m_accessible)
2123 m_accessible->SetWindow((wxWindow*) this);
2124 }
2125
2126 // Returns the accessible object, creating if necessary.
2127 wxAccessible* wxWindowBase::GetOrCreateAccessible()
2128 {
2129 if (!m_accessible)
2130 m_accessible = CreateAccessible();
2131 return m_accessible;
2132 }
2133
2134 // Override to create a specific accessible object.
2135 wxAccessible* wxWindowBase::CreateAccessible()
2136 {
2137 return new wxWindowAccessible((wxWindow*) this);
2138 }
2139
2140 #endif
2141
2142 #if !wxUSE_STL
2143 // ----------------------------------------------------------------------------
2144 // list classes implementation
2145 // ----------------------------------------------------------------------------
2146
2147 void wxWindowListNode::DeleteData()
2148 {
2149 delete (wxWindow *)GetData();
2150 }
2151 #endif
2152
2153 // ----------------------------------------------------------------------------
2154 // borders
2155 // ----------------------------------------------------------------------------
2156
2157 wxBorder wxWindowBase::GetBorder(long flags) const
2158 {
2159 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
2160 if ( border == wxBORDER_DEFAULT )
2161 {
2162 border = GetDefaultBorder();
2163 }
2164
2165 return border;
2166 }
2167
2168 wxBorder wxWindowBase::GetDefaultBorder() const
2169 {
2170 return wxBORDER_NONE;
2171 }
2172
2173 // ----------------------------------------------------------------------------
2174 // hit testing
2175 // ----------------------------------------------------------------------------
2176
2177 wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2178 {
2179 // here we just check if the point is inside the window or not
2180
2181 // check the top and left border first
2182 bool outside = x < 0 || y < 0;
2183 if ( !outside )
2184 {
2185 // check the right and bottom borders too
2186 wxSize size = GetSize();
2187 outside = x >= size.x || y >= size.y;
2188 }
2189
2190 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2191 }
2192
2193 // ----------------------------------------------------------------------------
2194 // mouse capture
2195 // ----------------------------------------------------------------------------
2196
2197 struct WXDLLEXPORT wxWindowNext
2198 {
2199 wxWindow *win;
2200 wxWindowNext *next;
2201 } *wxWindowBase::ms_winCaptureNext = NULL;
2202
2203 void wxWindowBase::CaptureMouse()
2204 {
2205 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2206
2207 wxWindow *winOld = GetCapture();
2208 if ( winOld )
2209 {
2210 ((wxWindowBase*) winOld)->DoReleaseMouse();
2211
2212 // save it on stack
2213 wxWindowNext *item = new wxWindowNext;
2214 item->win = winOld;
2215 item->next = ms_winCaptureNext;
2216 ms_winCaptureNext = item;
2217 }
2218 //else: no mouse capture to save
2219
2220 DoCaptureMouse();
2221 }
2222
2223 void wxWindowBase::ReleaseMouse()
2224 {
2225 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2226
2227 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2228
2229 DoReleaseMouse();
2230
2231 if ( ms_winCaptureNext )
2232 {
2233 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
2234
2235 wxWindowNext *item = ms_winCaptureNext;
2236 ms_winCaptureNext = item->next;
2237 delete item;
2238 }
2239 //else: stack is empty, no previous capture
2240
2241 wxLogTrace(_T("mousecapture"),
2242 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
2243 GetCapture());
2244 }
2245
2246 #if wxUSE_HOTKEY
2247
2248 bool
2249 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2250 int WXUNUSED(modifiers),
2251 int WXUNUSED(keycode))
2252 {
2253 // not implemented
2254 return false;
2255 }
2256
2257 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
2258 {
2259 // not implemented
2260 return false;
2261 }
2262
2263 #endif // wxUSE_HOTKEY
2264
2265 void wxWindowBase::SendDestroyEvent()
2266 {
2267 wxWindowDestroyEvent event;
2268 event.SetEventObject(this);
2269 event.SetId(GetId());
2270 GetEventHandler()->ProcessEvent(event);
2271 }
2272
2273 // ----------------------------------------------------------------------------
2274 // event processing
2275 // ----------------------------------------------------------------------------
2276
2277 bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
2278 {
2279 #if wxUSE_VALIDATORS
2280 // Can only use the validator of the window which
2281 // is receiving the event
2282 if ( event.GetEventObject() == this )
2283 {
2284 wxValidator *validator = GetValidator();
2285 if ( validator && validator->ProcessEvent(event) )
2286 {
2287 return true;
2288 }
2289 }
2290 #endif // wxUSE_VALIDATORS
2291
2292 return false;
2293 }
2294
2295 bool wxWindowBase::TryParent(wxEvent& event)
2296 {
2297 // carry on up the parent-child hierarchy if the propgation count hasn't
2298 // reached zero yet
2299 if ( event.ShouldPropagate() )
2300 {
2301 // honour the requests to stop propagation at this window: this is
2302 // used by the dialogs, for example, to prevent processing the events
2303 // from the dialog controls in the parent frame which rarely, if ever,
2304 // makes sense
2305 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2306 {
2307 wxWindow *parent = GetParent();
2308 if ( parent && !parent->IsBeingDeleted() )
2309 {
2310 wxPropagateOnce propagateOnce(event);
2311
2312 return parent->GetEventHandler()->ProcessEvent(event);
2313 }
2314 }
2315 }
2316
2317 return wxEvtHandler::TryParent(event);
2318 }
2319
2320 // ----------------------------------------------------------------------------
2321 // global functions
2322 // ----------------------------------------------------------------------------
2323
2324 wxWindow* wxGetTopLevelParent(wxWindow *win)
2325 {
2326 while ( win && !win->IsTopLevel() )
2327 win = win->GetParent();
2328
2329 return win;
2330 }
2331
2332 #if wxUSE_ACCESSIBILITY
2333 // ----------------------------------------------------------------------------
2334 // accessible object for windows
2335 // ----------------------------------------------------------------------------
2336
2337 // Can return either a child object, or an integer
2338 // representing the child element, starting from 1.
2339 wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
2340 {
2341 wxASSERT( GetWindow() != NULL );
2342 if (!GetWindow())
2343 return wxACC_FAIL;
2344
2345 return wxACC_NOT_IMPLEMENTED;
2346 }
2347
2348 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2349 wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2350 {
2351 wxASSERT( GetWindow() != NULL );
2352 if (!GetWindow())
2353 return wxACC_FAIL;
2354
2355 wxWindow* win = NULL;
2356 if (elementId == 0)
2357 {
2358 win = GetWindow();
2359 }
2360 else
2361 {
2362 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2363 {
2364 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
2365 }
2366 else
2367 return wxACC_FAIL;
2368 }
2369 if (win)
2370 {
2371 rect = win->GetRect();
2372 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2373 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2374 return wxACC_OK;
2375 }
2376
2377 return wxACC_NOT_IMPLEMENTED;
2378 }
2379
2380 // Navigates from fromId to toId/toObject.
2381 wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
2382 int* WXUNUSED(toId), wxAccessible** toObject)
2383 {
2384 wxASSERT( GetWindow() != NULL );
2385 if (!GetWindow())
2386 return wxACC_FAIL;
2387
2388 switch (navDir)
2389 {
2390 case wxNAVDIR_FIRSTCHILD:
2391 {
2392 if (GetWindow()->GetChildren().GetCount() == 0)
2393 return wxACC_FALSE;
2394 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2395 *toObject = childWindow->GetOrCreateAccessible();
2396
2397 return wxACC_OK;
2398 }
2399 case wxNAVDIR_LASTCHILD:
2400 {
2401 if (GetWindow()->GetChildren().GetCount() == 0)
2402 return wxACC_FALSE;
2403 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2404 *toObject = childWindow->GetOrCreateAccessible();
2405
2406 return wxACC_OK;
2407 }
2408 case wxNAVDIR_RIGHT:
2409 case wxNAVDIR_DOWN:
2410 case wxNAVDIR_NEXT:
2411 {
2412 wxWindowList::compatibility_iterator node =
2413 wxWindowList::compatibility_iterator();
2414 if (fromId == 0)
2415 {
2416 // Can't navigate to sibling of this window
2417 // if we're a top-level window.
2418 if (!GetWindow()->GetParent())
2419 return wxACC_NOT_IMPLEMENTED;
2420
2421 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2422 }
2423 else
2424 {
2425 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2426 node = GetWindow()->GetChildren().Item(fromId-1);
2427 }
2428
2429 if (node && node->GetNext())
2430 {
2431 wxWindow* nextWindow = node->GetNext()->GetData();
2432 *toObject = nextWindow->GetOrCreateAccessible();
2433 return wxACC_OK;
2434 }
2435 else
2436 return wxACC_FALSE;
2437 }
2438 case wxNAVDIR_LEFT:
2439 case wxNAVDIR_UP:
2440 case wxNAVDIR_PREVIOUS:
2441 {
2442 wxWindowList::compatibility_iterator node =
2443 wxWindowList::compatibility_iterator();
2444 if (fromId == 0)
2445 {
2446 // Can't navigate to sibling of this window
2447 // if we're a top-level window.
2448 if (!GetWindow()->GetParent())
2449 return wxACC_NOT_IMPLEMENTED;
2450
2451 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2452 }
2453 else
2454 {
2455 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2456 node = GetWindow()->GetChildren().Item(fromId-1);
2457 }
2458
2459 if (node && node->GetPrevious())
2460 {
2461 wxWindow* previousWindow = node->GetPrevious()->GetData();
2462 *toObject = previousWindow->GetOrCreateAccessible();
2463 return wxACC_OK;
2464 }
2465 else
2466 return wxACC_FALSE;
2467 }
2468 }
2469
2470 return wxACC_NOT_IMPLEMENTED;
2471 }
2472
2473 // Gets the name of the specified object.
2474 wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2475 {
2476 wxASSERT( GetWindow() != NULL );
2477 if (!GetWindow())
2478 return wxACC_FAIL;
2479
2480 wxString title;
2481
2482 // If a child, leave wxWindows to call the function on the actual
2483 // child object.
2484 if (childId > 0)
2485 return wxACC_NOT_IMPLEMENTED;
2486
2487 // This will eventually be replaced by specialised
2488 // accessible classes, one for each kind of wxWindows
2489 // control or window.
2490 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2491 title = ((wxButton*) GetWindow())->GetLabel();
2492 else
2493 title = GetWindow()->GetName();
2494
2495 if (!title.IsEmpty())
2496 {
2497 *name = title;
2498 return wxACC_OK;
2499 }
2500 else
2501 return wxACC_NOT_IMPLEMENTED;
2502 }
2503
2504 // Gets the number of children.
2505 wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2506 {
2507 wxASSERT( GetWindow() != NULL );
2508 if (!GetWindow())
2509 return wxACC_FAIL;
2510
2511 *childId = (int) GetWindow()->GetChildren().GetCount();
2512 return wxACC_OK;
2513 }
2514
2515 // Gets the specified child (starting from 1).
2516 // If *child is NULL and return value is wxACC_OK,
2517 // this means that the child is a simple element and
2518 // not an accessible object.
2519 wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2520 {
2521 wxASSERT( GetWindow() != NULL );
2522 if (!GetWindow())
2523 return wxACC_FAIL;
2524
2525 if (childId == 0)
2526 {
2527 *child = this;
2528 return wxACC_OK;
2529 }
2530
2531 if (childId > (int) GetWindow()->GetChildren().GetCount())
2532 return wxACC_FAIL;
2533
2534 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
2535 *child = childWindow->GetOrCreateAccessible();
2536 if (*child)
2537 return wxACC_OK;
2538 else
2539 return wxACC_FAIL;
2540 }
2541
2542 // Gets the parent, or NULL.
2543 wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2544 {
2545 wxASSERT( GetWindow() != NULL );
2546 if (!GetWindow())
2547 return wxACC_FAIL;
2548
2549 wxWindow* parentWindow = GetWindow()->GetParent();
2550 if (!parentWindow)
2551 {
2552 *parent = NULL;
2553 return wxACC_OK;
2554 }
2555 else
2556 {
2557 *parent = parentWindow->GetOrCreateAccessible();
2558 if (*parent)
2559 return wxACC_OK;
2560 else
2561 return wxACC_FAIL;
2562 }
2563 }
2564
2565 // Performs the default action. childId is 0 (the action for this object)
2566 // or > 0 (the action for a child).
2567 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2568 // window (e.g. an edit control).
2569 wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
2570 {
2571 wxASSERT( GetWindow() != NULL );
2572 if (!GetWindow())
2573 return wxACC_FAIL;
2574
2575 return wxACC_NOT_IMPLEMENTED;
2576 }
2577
2578 // Gets the default action for this object (0) or > 0 (the action for a child).
2579 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2580 // string if there is no action.
2581 // The retrieved string describes the action that is performed on an object,
2582 // not what the object does as a result. For example, a toolbar button that prints
2583 // a document has a default action of "Press" rather than "Prints the current document."
2584 wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
2585 {
2586 wxASSERT( GetWindow() != NULL );
2587 if (!GetWindow())
2588 return wxACC_FAIL;
2589
2590 return wxACC_NOT_IMPLEMENTED;
2591 }
2592
2593 // Returns the description for this object or a child.
2594 wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
2595 {
2596 wxASSERT( GetWindow() != NULL );
2597 if (!GetWindow())
2598 return wxACC_FAIL;
2599
2600 wxString ht(GetWindow()->GetHelpText());
2601 if (!ht.IsEmpty())
2602 {
2603 *description = ht;
2604 return wxACC_OK;
2605 }
2606 return wxACC_NOT_IMPLEMENTED;
2607 }
2608
2609 // Returns help text for this object or a child, similar to tooltip text.
2610 wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
2611 {
2612 wxASSERT( GetWindow() != NULL );
2613 if (!GetWindow())
2614 return wxACC_FAIL;
2615
2616 wxString ht(GetWindow()->GetHelpText());
2617 if (!ht.IsEmpty())
2618 {
2619 *helpText = ht;
2620 return wxACC_OK;
2621 }
2622 return wxACC_NOT_IMPLEMENTED;
2623 }
2624
2625 // Returns the keyboard shortcut for this object or child.
2626 // Return e.g. ALT+K
2627 wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
2628 {
2629 wxASSERT( GetWindow() != NULL );
2630 if (!GetWindow())
2631 return wxACC_FAIL;
2632
2633 return wxACC_NOT_IMPLEMENTED;
2634 }
2635
2636 // Returns a role constant.
2637 wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
2638 {
2639 wxASSERT( GetWindow() != NULL );
2640 if (!GetWindow())
2641 return wxACC_FAIL;
2642
2643 // If a child, leave wxWindows to call the function on the actual
2644 // child object.
2645 if (childId > 0)
2646 return wxACC_NOT_IMPLEMENTED;
2647
2648 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2649 return wxACC_NOT_IMPLEMENTED;
2650 #if wxUSE_STATUSBAR
2651 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2652 return wxACC_NOT_IMPLEMENTED;
2653 #endif
2654 #if wxUSE_TOOLBAR
2655 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2656 return wxACC_NOT_IMPLEMENTED;
2657 #endif
2658
2659 //*role = wxROLE_SYSTEM_CLIENT;
2660 *role = wxROLE_SYSTEM_CLIENT;
2661 return wxACC_OK;
2662
2663 #if 0
2664 return wxACC_NOT_IMPLEMENTED;
2665 #endif
2666 }
2667
2668 // Returns a state constant.
2669 wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
2670 {
2671 wxASSERT( GetWindow() != NULL );
2672 if (!GetWindow())
2673 return wxACC_FAIL;
2674
2675 // If a child, leave wxWindows to call the function on the actual
2676 // child object.
2677 if (childId > 0)
2678 return wxACC_NOT_IMPLEMENTED;
2679
2680 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2681 return wxACC_NOT_IMPLEMENTED;
2682
2683 #if wxUSE_STATUSBAR
2684 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2685 return wxACC_NOT_IMPLEMENTED;
2686 #endif
2687 #if wxUSE_TOOLBAR
2688 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2689 return wxACC_NOT_IMPLEMENTED;
2690 #endif
2691
2692 *state = 0;
2693 return wxACC_OK;
2694
2695 #if 0
2696 return wxACC_NOT_IMPLEMENTED;
2697 #endif
2698 }
2699
2700 // Returns a localized string representing the value for the object
2701 // or child.
2702 wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
2703 {
2704 wxASSERT( GetWindow() != NULL );
2705 if (!GetWindow())
2706 return wxACC_FAIL;
2707
2708 return wxACC_NOT_IMPLEMENTED;
2709 }
2710
2711 // Selects the object or child.
2712 wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
2713 {
2714 wxASSERT( GetWindow() != NULL );
2715 if (!GetWindow())
2716 return wxACC_FAIL;
2717
2718 return wxACC_NOT_IMPLEMENTED;
2719 }
2720
2721 // Gets the window with the keyboard focus.
2722 // If childId is 0 and child is NULL, no object in
2723 // this subhierarchy has the focus.
2724 // If this object has the focus, child should be 'this'.
2725 wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
2726 {
2727 wxASSERT( GetWindow() != NULL );
2728 if (!GetWindow())
2729 return wxACC_FAIL;
2730
2731 return wxACC_NOT_IMPLEMENTED;
2732 }
2733
2734 // Gets a variant representing the selected children
2735 // of this object.
2736 // Acceptable values:
2737 // - a null variant (IsNull() returns TRUE)
2738 // - a list variant (GetType() == wxT("list")
2739 // - an integer representing the selected child element,
2740 // or 0 if this object is selected (GetType() == wxT("long")
2741 // - a "void*" pointer to a wxAccessible child object
2742 wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
2743 {
2744 wxASSERT( GetWindow() != NULL );
2745 if (!GetWindow())
2746 return wxACC_FAIL;
2747
2748 return wxACC_NOT_IMPLEMENTED;
2749 }
2750
2751 #endif // wxUSE_ACCESSIBILITY