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