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