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