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