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