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