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