]> git.saurik.com Git - wxWidgets.git/blob - src/common/wincmn.cpp
don't inherit font from the parent by default
[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 are created enabled and visible by default
125 m_isShown =
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_NORMAL ;
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 default:
655 wxFAIL_MSG(_T("unexpected window variant"));
656 break ;
657 }
658 SetFont( font ) ;
659 }
660
661 void wxWindowBase::SetVirtualSizeHints( int minW, int minH,
662 int maxW, int maxH )
663 {
664 m_minVirtualWidth = minW;
665 m_maxVirtualWidth = maxW;
666 m_minVirtualHeight = minH;
667 m_maxVirtualHeight = maxH;
668 }
669
670 void wxWindowBase::DoSetVirtualSize( int x, int y )
671 {
672 if ( m_minVirtualWidth != -1 && m_minVirtualWidth > x )
673 x = m_minVirtualWidth;
674 if ( m_maxVirtualWidth != -1 && m_maxVirtualWidth < x )
675 x = m_maxVirtualWidth;
676 if ( m_minVirtualHeight != -1 && m_minVirtualHeight > y )
677 y = m_minVirtualHeight;
678 if ( m_maxVirtualHeight != -1 && m_maxVirtualHeight < y )
679 y = m_maxVirtualHeight;
680
681 m_virtualSize = wxSize(x, y);
682 }
683
684 wxSize wxWindowBase::DoGetVirtualSize() const
685 {
686 wxSize s( GetClientSize() );
687
688 return wxSize( wxMax( m_virtualSize.GetWidth(), s.GetWidth() ),
689 wxMax( m_virtualSize.GetHeight(), s.GetHeight() ) );
690 }
691
692 // ----------------------------------------------------------------------------
693 // show/hide/enable/disable the window
694 // ----------------------------------------------------------------------------
695
696 bool wxWindowBase::Show(bool show)
697 {
698 if ( show != m_isShown )
699 {
700 m_isShown = show;
701
702 return true;
703 }
704 else
705 {
706 return false;
707 }
708 }
709
710 bool wxWindowBase::Enable(bool enable)
711 {
712 if ( enable != m_isEnabled )
713 {
714 m_isEnabled = enable;
715
716 return true;
717 }
718 else
719 {
720 return false;
721 }
722 }
723 // ----------------------------------------------------------------------------
724 // RTTI
725 // ----------------------------------------------------------------------------
726
727 bool wxWindowBase::IsTopLevel() const
728 {
729 return false;
730 }
731
732 // ----------------------------------------------------------------------------
733 // reparenting the window
734 // ----------------------------------------------------------------------------
735
736 void wxWindowBase::AddChild(wxWindowBase *child)
737 {
738 wxCHECK_RET( child, wxT("can't add a NULL child") );
739
740 // this should never happen and it will lead to a crash later if it does
741 // because RemoveChild() will remove only one node from the children list
742 // and the other(s) one(s) will be left with dangling pointers in them
743 wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), _T("AddChild() called twice") );
744
745 GetChildren().Append((wxWindow*)child);
746 child->SetParent(this);
747 }
748
749 void wxWindowBase::RemoveChild(wxWindowBase *child)
750 {
751 wxCHECK_RET( child, wxT("can't remove a NULL child") );
752
753 GetChildren().DeleteObject((wxWindow *)child);
754 child->SetParent(NULL);
755 }
756
757 bool wxWindowBase::Reparent(wxWindowBase *newParent)
758 {
759 wxWindow *oldParent = GetParent();
760 if ( newParent == oldParent )
761 {
762 // nothing done
763 return false;
764 }
765
766 // unlink this window from the existing parent.
767 if ( oldParent )
768 {
769 oldParent->RemoveChild(this);
770 }
771 else
772 {
773 wxTopLevelWindows.DeleteObject((wxWindow *)this);
774 }
775
776 // add it to the new one
777 if ( newParent )
778 {
779 newParent->AddChild(this);
780 }
781 else
782 {
783 wxTopLevelWindows.Append((wxWindow *)this);
784 }
785
786 return true;
787 }
788
789 // ----------------------------------------------------------------------------
790 // event handler stuff
791 // ----------------------------------------------------------------------------
792
793 void wxWindowBase::PushEventHandler(wxEvtHandler *handler)
794 {
795 wxEvtHandler *handlerOld = GetEventHandler();
796
797 handler->SetNextHandler(handlerOld);
798
799 if ( handlerOld )
800 GetEventHandler()->SetPreviousHandler(handler);
801
802 SetEventHandler(handler);
803 }
804
805 wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
806 {
807 wxEvtHandler *handlerA = GetEventHandler();
808 if ( handlerA )
809 {
810 wxEvtHandler *handlerB = handlerA->GetNextHandler();
811 handlerA->SetNextHandler((wxEvtHandler *)NULL);
812
813 if ( handlerB )
814 handlerB->SetPreviousHandler((wxEvtHandler *)NULL);
815 SetEventHandler(handlerB);
816
817 if ( deleteHandler )
818 {
819 delete handlerA;
820 handlerA = (wxEvtHandler *)NULL;
821 }
822 }
823
824 return handlerA;
825 }
826
827 bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler)
828 {
829 wxCHECK_MSG( handler, false, _T("RemoveEventHandler(NULL) called") );
830
831 wxEvtHandler *handlerPrev = NULL,
832 *handlerCur = GetEventHandler();
833 while ( handlerCur )
834 {
835 wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
836
837 if ( handlerCur == handler )
838 {
839 if ( handlerPrev )
840 {
841 handlerPrev->SetNextHandler(handlerNext);
842 }
843 else
844 {
845 SetEventHandler(handlerNext);
846 }
847
848 if ( handlerNext )
849 {
850 handlerNext->SetPreviousHandler ( handlerPrev );
851 }
852
853 handler->SetNextHandler(NULL);
854 handler->SetPreviousHandler(NULL);
855
856 return true;
857 }
858
859 handlerPrev = handlerCur;
860 handlerCur = handlerNext;
861 }
862
863 wxFAIL_MSG( _T("where has the event handler gone?") );
864
865 return false;
866 }
867
868 // ----------------------------------------------------------------------------
869 // cursors, fonts &c
870 // ----------------------------------------------------------------------------
871
872 bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
873 {
874 if ( !colour.Ok() || (colour == m_backgroundColour) )
875 return false;
876
877 m_backgroundColour = colour;
878
879 m_hasBgCol = true;
880
881 return true;
882 }
883
884 bool wxWindowBase::SetForegroundColour( const wxColour &colour )
885 {
886 if ( !colour.Ok() || (colour == m_foregroundColour) )
887 return false;
888
889 m_foregroundColour = colour;
890
891 m_hasFgCol = true;
892
893 return true;
894 }
895
896 bool wxWindowBase::SetCursor(const wxCursor& cursor)
897 {
898 // setting an invalid cursor is ok, it means that we don't have any special
899 // cursor
900 if ( m_cursor == cursor )
901 {
902 // no change
903 return false;
904 }
905
906 m_cursor = cursor;
907
908 return true;
909 }
910
911 bool wxWindowBase::SetFont(const wxFont& font)
912 {
913 // don't try to set invalid font, always fall back to the default
914 const wxFont& fontOk = font.Ok() ? font : *wxSWISS_FONT;
915
916 if ( fontOk == m_font )
917 {
918 // no change
919 return false;
920 }
921
922 m_font = fontOk;
923
924 m_hasFont = true;
925
926 return true;
927 }
928
929 #if wxUSE_PALETTE
930
931 void wxWindowBase::SetPalette(const wxPalette& pal)
932 {
933 m_hasCustomPalette = true;
934 m_palette = pal;
935
936 // VZ: can anyone explain me what do we do here?
937 wxWindowDC d((wxWindow *) this);
938 d.SetPalette(pal);
939 }
940
941 wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
942 {
943 wxWindow *win = (wxWindow *)this;
944 while ( win && !win->HasCustomPalette() )
945 {
946 win = win->GetParent();
947 }
948
949 return win;
950 }
951
952 #endif // wxUSE_PALETTE
953
954 #if wxUSE_CARET
955 void wxWindowBase::SetCaret(wxCaret *caret)
956 {
957 if ( m_caret )
958 {
959 delete m_caret;
960 }
961
962 m_caret = caret;
963
964 if ( m_caret )
965 {
966 wxASSERT_MSG( m_caret->GetWindow() == this,
967 wxT("caret should be created associated to this window") );
968 }
969 }
970 #endif // wxUSE_CARET
971
972 #if wxUSE_VALIDATORS
973 // ----------------------------------------------------------------------------
974 // validators
975 // ----------------------------------------------------------------------------
976
977 void wxWindowBase::SetValidator(const wxValidator& validator)
978 {
979 if ( m_windowValidator )
980 delete m_windowValidator;
981
982 m_windowValidator = (wxValidator *)validator.Clone();
983
984 if ( m_windowValidator )
985 m_windowValidator->SetWindow(this) ;
986 }
987 #endif // wxUSE_VALIDATORS
988
989 // ----------------------------------------------------------------------------
990 // update region stuff
991 // ----------------------------------------------------------------------------
992
993 wxRect wxWindowBase::GetUpdateClientRect() const
994 {
995 wxRegion rgnUpdate = GetUpdateRegion();
996 rgnUpdate.Intersect(GetClientRect());
997 wxRect rectUpdate = rgnUpdate.GetBox();
998 wxPoint ptOrigin = GetClientAreaOrigin();
999 rectUpdate.x -= ptOrigin.x;
1000 rectUpdate.y -= ptOrigin.y;
1001
1002 return rectUpdate;
1003 }
1004
1005 bool wxWindowBase::IsExposed(int x, int y) const
1006 {
1007 return m_updateRegion.Contains(x, y) != wxOutRegion;
1008 }
1009
1010 bool wxWindowBase::IsExposed(int x, int y, int w, int h) const
1011 {
1012 return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
1013 }
1014
1015 void wxWindowBase::ClearBackground()
1016 {
1017 // wxGTK uses its own version, no need to add never used code
1018 #ifndef __WXGTK__
1019 wxClientDC dc((wxWindow *)this);
1020 wxBrush brush(GetBackgroundColour(), wxSOLID);
1021 dc.SetBackground(brush);
1022 dc.Clear();
1023 #endif // __WXGTK__
1024 }
1025
1026 // ----------------------------------------------------------------------------
1027 // find child window by id or name
1028 // ----------------------------------------------------------------------------
1029
1030 wxWindow *wxWindowBase::FindWindow( long id )
1031 {
1032 if ( id == m_windowId )
1033 return (wxWindow *)this;
1034
1035 wxWindowBase *res = (wxWindow *)NULL;
1036 wxWindowList::compatibility_iterator node;
1037 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1038 {
1039 wxWindowBase *child = node->GetData();
1040 res = child->FindWindow( id );
1041 }
1042
1043 return (wxWindow *)res;
1044 }
1045
1046 wxWindow *wxWindowBase::FindWindow( const wxString& name )
1047 {
1048 if ( name == m_windowName )
1049 return (wxWindow *)this;
1050
1051 wxWindowBase *res = (wxWindow *)NULL;
1052 wxWindowList::compatibility_iterator node;
1053 for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
1054 {
1055 wxWindow *child = node->GetData();
1056 res = child->FindWindow(name);
1057 }
1058
1059 return (wxWindow *)res;
1060 }
1061
1062
1063 // find any window by id or name or label: If parent is non-NULL, look through
1064 // children for a label or title matching the specified string. If NULL, look
1065 // through all top-level windows.
1066 //
1067 // to avoid duplicating code we reuse the same helper function but with
1068 // different comparators
1069
1070 typedef bool (*wxFindWindowCmp)(const wxWindow *win,
1071 const wxString& label, long id);
1072
1073 static
1074 bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
1075 long WXUNUSED(id))
1076 {
1077 return win->GetLabel() == label;
1078 }
1079
1080 static
1081 bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
1082 long WXUNUSED(id))
1083 {
1084 return win->GetName() == label;
1085 }
1086
1087 static
1088 bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
1089 long id)
1090 {
1091 return win->GetId() == id;
1092 }
1093
1094 // recursive helper for the FindWindowByXXX() functions
1095 static
1096 wxWindow *wxFindWindowRecursively(const wxWindow *parent,
1097 const wxString& label,
1098 long id,
1099 wxFindWindowCmp cmp)
1100 {
1101 if ( parent )
1102 {
1103 // see if this is the one we're looking for
1104 if ( (*cmp)(parent, label, id) )
1105 return (wxWindow *)parent;
1106
1107 // It wasn't, so check all its children
1108 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1109 node;
1110 node = node->GetNext() )
1111 {
1112 // recursively check each child
1113 wxWindow *win = (wxWindow *)node->GetData();
1114 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1115 if (retwin)
1116 return retwin;
1117 }
1118 }
1119
1120 // Not found
1121 return NULL;
1122 }
1123
1124 // helper for FindWindowByXXX()
1125 static
1126 wxWindow *wxFindWindowHelper(const wxWindow *parent,
1127 const wxString& label,
1128 long id,
1129 wxFindWindowCmp cmp)
1130 {
1131 if ( parent )
1132 {
1133 // just check parent and all its children
1134 return wxFindWindowRecursively(parent, label, id, cmp);
1135 }
1136
1137 // start at very top of wx's windows
1138 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1139 node;
1140 node = node->GetNext() )
1141 {
1142 // recursively check each window & its children
1143 wxWindow *win = node->GetData();
1144 wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
1145 if (retwin)
1146 return retwin;
1147 }
1148
1149 return NULL;
1150 }
1151
1152 /* static */
1153 wxWindow *
1154 wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
1155 {
1156 return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
1157 }
1158
1159 /* static */
1160 wxWindow *
1161 wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
1162 {
1163 wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
1164
1165 if ( !win )
1166 {
1167 // fall back to the label
1168 win = FindWindowByLabel(title, parent);
1169 }
1170
1171 return win;
1172 }
1173
1174 /* static */
1175 wxWindow *
1176 wxWindowBase::FindWindowById( long id, const wxWindow* parent )
1177 {
1178 return wxFindWindowHelper(parent, _T(""), id, wxFindWindowCmpIds);
1179 }
1180
1181 // ----------------------------------------------------------------------------
1182 // dialog oriented functions
1183 // ----------------------------------------------------------------------------
1184
1185 void wxWindowBase::MakeModal(bool modal)
1186 {
1187 // Disable all other windows
1188 if ( IsTopLevel() )
1189 {
1190 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
1191 while (node)
1192 {
1193 wxWindow *win = node->GetData();
1194 if (win != this)
1195 win->Enable(!modal);
1196
1197 node = node->GetNext();
1198 }
1199 }
1200 }
1201
1202 bool wxWindowBase::Validate()
1203 {
1204 #if wxUSE_VALIDATORS
1205 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1206
1207 wxWindowList::compatibility_iterator node;
1208 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1209 {
1210 wxWindowBase *child = node->GetData();
1211 wxValidator *validator = child->GetValidator();
1212 if ( validator && !validator->Validate((wxWindow *)this) )
1213 {
1214 return false;
1215 }
1216
1217 if ( recurse && !child->Validate() )
1218 {
1219 return false;
1220 }
1221 }
1222 #endif // wxUSE_VALIDATORS
1223
1224 return true;
1225 }
1226
1227 bool wxWindowBase::TransferDataToWindow()
1228 {
1229 #if wxUSE_VALIDATORS
1230 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1231
1232 wxWindowList::compatibility_iterator node;
1233 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1234 {
1235 wxWindowBase *child = node->GetData();
1236 wxValidator *validator = child->GetValidator();
1237 if ( validator && !validator->TransferToWindow() )
1238 {
1239 wxLogWarning(_("Could not transfer data to window"));
1240 #if wxUSE_LOG
1241 wxLog::FlushActive();
1242 #endif // wxUSE_LOG
1243
1244 return false;
1245 }
1246
1247 if ( recurse )
1248 {
1249 if ( !child->TransferDataToWindow() )
1250 {
1251 // warning already given
1252 return false;
1253 }
1254 }
1255 }
1256 #endif // wxUSE_VALIDATORS
1257
1258 return true;
1259 }
1260
1261 bool wxWindowBase::TransferDataFromWindow()
1262 {
1263 #if wxUSE_VALIDATORS
1264 bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
1265
1266 wxWindowList::compatibility_iterator node;
1267 for ( node = m_children.GetFirst(); node; node = node->GetNext() )
1268 {
1269 wxWindow *child = node->GetData();
1270 wxValidator *validator = child->GetValidator();
1271 if ( validator && !validator->TransferFromWindow() )
1272 {
1273 // nop warning here because the application is supposed to give
1274 // one itself - we don't know here what might have gone wrongly
1275
1276 return false;
1277 }
1278
1279 if ( recurse )
1280 {
1281 if ( !child->TransferDataFromWindow() )
1282 {
1283 // warning already given
1284 return false;
1285 }
1286 }
1287 }
1288 #endif // wxUSE_VALIDATORS
1289
1290 return true;
1291 }
1292
1293 void wxWindowBase::InitDialog()
1294 {
1295 wxInitDialogEvent event(GetId());
1296 event.SetEventObject( this );
1297 GetEventHandler()->ProcessEvent(event);
1298 }
1299
1300 // ----------------------------------------------------------------------------
1301 // context-sensitive help support
1302 // ----------------------------------------------------------------------------
1303
1304 #if wxUSE_HELP
1305
1306 // associate this help text with this window
1307 void wxWindowBase::SetHelpText(const wxString& text)
1308 {
1309 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1310 if ( helpProvider )
1311 {
1312 helpProvider->AddHelp(this, text);
1313 }
1314 }
1315
1316 // associate this help text with all windows with the same id as this
1317 // one
1318 void wxWindowBase::SetHelpTextForId(const wxString& text)
1319 {
1320 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1321 if ( helpProvider )
1322 {
1323 helpProvider->AddHelp(GetId(), text);
1324 }
1325 }
1326
1327 // get the help string associated with this window (may be empty)
1328 wxString wxWindowBase::GetHelpText() const
1329 {
1330 wxString text;
1331 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1332 if ( helpProvider )
1333 {
1334 text = helpProvider->GetHelp(this);
1335 }
1336
1337 return text;
1338 }
1339
1340 // show help for this window
1341 void wxWindowBase::OnHelp(wxHelpEvent& event)
1342 {
1343 wxHelpProvider *helpProvider = wxHelpProvider::Get();
1344 if ( helpProvider )
1345 {
1346 if ( helpProvider->ShowHelp(this) )
1347 {
1348 // skip the event.Skip() below
1349 return;
1350 }
1351 }
1352
1353 event.Skip();
1354 }
1355
1356 #endif // wxUSE_HELP
1357
1358 // ----------------------------------------------------------------------------
1359 // tooltipsroot.Replace("\\", "/");
1360 // ----------------------------------------------------------------------------
1361
1362 #if wxUSE_TOOLTIPS
1363
1364 void wxWindowBase::SetToolTip( const wxString &tip )
1365 {
1366 // don't create the new tooltip if we already have one
1367 if ( m_tooltip )
1368 {
1369 m_tooltip->SetTip( tip );
1370 }
1371 else
1372 {
1373 SetToolTip( new wxToolTip( tip ) );
1374 }
1375
1376 // setting empty tooltip text does not remove the tooltip any more - use
1377 // SetToolTip((wxToolTip *)NULL) for this
1378 }
1379
1380 void wxWindowBase::DoSetToolTip(wxToolTip *tooltip)
1381 {
1382 if ( m_tooltip )
1383 delete m_tooltip;
1384
1385 m_tooltip = tooltip;
1386 }
1387
1388 #endif // wxUSE_TOOLTIPS
1389
1390 // ----------------------------------------------------------------------------
1391 // constraints and sizers
1392 // ----------------------------------------------------------------------------
1393
1394 #if wxUSE_CONSTRAINTS
1395
1396 void wxWindowBase::SetConstraints( wxLayoutConstraints *constraints )
1397 {
1398 if ( m_constraints )
1399 {
1400 UnsetConstraints(m_constraints);
1401 delete m_constraints;
1402 }
1403 m_constraints = constraints;
1404 if ( m_constraints )
1405 {
1406 // Make sure other windows know they're part of a 'meaningful relationship'
1407 if ( m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this) )
1408 m_constraints->left.GetOtherWindow()->AddConstraintReference(this);
1409 if ( m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this) )
1410 m_constraints->top.GetOtherWindow()->AddConstraintReference(this);
1411 if ( m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this) )
1412 m_constraints->right.GetOtherWindow()->AddConstraintReference(this);
1413 if ( m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this) )
1414 m_constraints->bottom.GetOtherWindow()->AddConstraintReference(this);
1415 if ( m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this) )
1416 m_constraints->width.GetOtherWindow()->AddConstraintReference(this);
1417 if ( m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this) )
1418 m_constraints->height.GetOtherWindow()->AddConstraintReference(this);
1419 if ( m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this) )
1420 m_constraints->centreX.GetOtherWindow()->AddConstraintReference(this);
1421 if ( m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this) )
1422 m_constraints->centreY.GetOtherWindow()->AddConstraintReference(this);
1423 }
1424 }
1425
1426 // This removes any dangling pointers to this window in other windows'
1427 // constraintsInvolvedIn lists.
1428 void wxWindowBase::UnsetConstraints(wxLayoutConstraints *c)
1429 {
1430 if ( c )
1431 {
1432 if ( c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1433 c->left.GetOtherWindow()->RemoveConstraintReference(this);
1434 if ( c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this) )
1435 c->top.GetOtherWindow()->RemoveConstraintReference(this);
1436 if ( c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this) )
1437 c->right.GetOtherWindow()->RemoveConstraintReference(this);
1438 if ( c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this) )
1439 c->bottom.GetOtherWindow()->RemoveConstraintReference(this);
1440 if ( c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this) )
1441 c->width.GetOtherWindow()->RemoveConstraintReference(this);
1442 if ( c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this) )
1443 c->height.GetOtherWindow()->RemoveConstraintReference(this);
1444 if ( c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this) )
1445 c->centreX.GetOtherWindow()->RemoveConstraintReference(this);
1446 if ( c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this) )
1447 c->centreY.GetOtherWindow()->RemoveConstraintReference(this);
1448 }
1449 }
1450
1451 // Back-pointer to other windows we're involved with, so if we delete this
1452 // window, we must delete any constraints we're involved with.
1453 void wxWindowBase::AddConstraintReference(wxWindowBase *otherWin)
1454 {
1455 if ( !m_constraintsInvolvedIn )
1456 m_constraintsInvolvedIn = new wxWindowList;
1457 if ( !m_constraintsInvolvedIn->Find((wxWindow *)otherWin) )
1458 m_constraintsInvolvedIn->Append((wxWindow *)otherWin);
1459 }
1460
1461 // REMOVE back-pointer to other windows we're involved with.
1462 void wxWindowBase::RemoveConstraintReference(wxWindowBase *otherWin)
1463 {
1464 if ( m_constraintsInvolvedIn )
1465 m_constraintsInvolvedIn->DeleteObject((wxWindow *)otherWin);
1466 }
1467
1468 // Reset any constraints that mention this window
1469 void wxWindowBase::DeleteRelatedConstraints()
1470 {
1471 if ( m_constraintsInvolvedIn )
1472 {
1473 wxWindowList::compatibility_iterator node = m_constraintsInvolvedIn->GetFirst();
1474 while (node)
1475 {
1476 wxWindow *win = node->GetData();
1477 wxLayoutConstraints *constr = win->GetConstraints();
1478
1479 // Reset any constraints involving this window
1480 if ( constr )
1481 {
1482 constr->left.ResetIfWin(this);
1483 constr->top.ResetIfWin(this);
1484 constr->right.ResetIfWin(this);
1485 constr->bottom.ResetIfWin(this);
1486 constr->width.ResetIfWin(this);
1487 constr->height.ResetIfWin(this);
1488 constr->centreX.ResetIfWin(this);
1489 constr->centreY.ResetIfWin(this);
1490 }
1491
1492 wxWindowList::compatibility_iterator next = node->GetNext();
1493 m_constraintsInvolvedIn->Erase(node);
1494 node = next;
1495 }
1496
1497 delete m_constraintsInvolvedIn;
1498 m_constraintsInvolvedIn = (wxWindowList *) NULL;
1499 }
1500 }
1501
1502 #endif // wxUSE_CONSTRAINTS
1503
1504 void wxWindowBase::SetSizer(wxSizer *sizer, bool deleteOld)
1505 {
1506 if ( sizer == m_windowSizer)
1507 return;
1508
1509 if ( deleteOld )
1510 delete m_windowSizer;
1511
1512 m_windowSizer = sizer;
1513
1514 SetAutoLayout( sizer != NULL );
1515 }
1516
1517 void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
1518 {
1519 SetSizer( sizer, deleteOld );
1520 sizer->SetSizeHints( (wxWindow*) this );
1521 }
1522
1523 #if wxUSE_CONSTRAINTS
1524
1525 void wxWindowBase::SatisfyConstraints()
1526 {
1527 wxLayoutConstraints *constr = GetConstraints();
1528 bool wasOk = constr && constr->AreSatisfied();
1529
1530 ResetConstraints(); // Mark all constraints as unevaluated
1531
1532 int noChanges = 1;
1533
1534 // if we're a top level panel (i.e. our parent is frame/dialog), our
1535 // own constraints will never be satisfied any more unless we do it
1536 // here
1537 if ( wasOk )
1538 {
1539 while ( noChanges > 0 )
1540 {
1541 LayoutPhase1(&noChanges);
1542 }
1543 }
1544
1545 LayoutPhase2(&noChanges);
1546 }
1547
1548 #endif // wxUSE_CONSTRAINTS
1549
1550 bool wxWindowBase::Layout()
1551 {
1552 // If there is a sizer, use it instead of the constraints
1553 if ( GetSizer() )
1554 {
1555 int w, h;
1556 GetVirtualSize(&w, &h);
1557 GetSizer()->SetDimension( 0, 0, w, h );
1558 }
1559 #if wxUSE_CONSTRAINTS
1560 else
1561 {
1562 SatisfyConstraints(); // Find the right constraints values
1563 SetConstraintSizes(); // Recursively set the real window sizes
1564 }
1565 #endif
1566
1567 return true;
1568 }
1569
1570 #if wxUSE_CONSTRAINTS
1571
1572 // first phase of the constraints evaluation: set our own constraints
1573 bool wxWindowBase::LayoutPhase1(int *noChanges)
1574 {
1575 wxLayoutConstraints *constr = GetConstraints();
1576
1577 return !constr || constr->SatisfyConstraints(this, noChanges);
1578 }
1579
1580 // second phase: set the constraints for our children
1581 bool wxWindowBase::LayoutPhase2(int *noChanges)
1582 {
1583 *noChanges = 0;
1584
1585 // Layout children
1586 DoPhase(1);
1587
1588 // Layout grand children
1589 DoPhase(2);
1590
1591 return true;
1592 }
1593
1594 // Do a phase of evaluating child constraints
1595 bool wxWindowBase::DoPhase(int phase)
1596 {
1597 // the list containing the children for which the constraints are already
1598 // set correctly
1599 wxWindowList succeeded;
1600
1601 // the max number of iterations we loop before concluding that we can't set
1602 // the constraints
1603 static const int maxIterations = 500;
1604
1605 for ( int noIterations = 0; noIterations < maxIterations; noIterations++ )
1606 {
1607 int noChanges = 0;
1608
1609 // loop over all children setting their constraints
1610 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1611 node;
1612 node = node->GetNext() )
1613 {
1614 wxWindow *child = node->GetData();
1615 if ( child->IsTopLevel() )
1616 {
1617 // top level children are not inside our client area
1618 continue;
1619 }
1620
1621 if ( !child->GetConstraints() || succeeded.Find(child) )
1622 {
1623 // this one is either already ok or nothing we can do about it
1624 continue;
1625 }
1626
1627 int tempNoChanges = 0;
1628 bool success = phase == 1 ? child->LayoutPhase1(&tempNoChanges)
1629 : child->LayoutPhase2(&tempNoChanges);
1630 noChanges += tempNoChanges;
1631
1632 if ( success )
1633 {
1634 succeeded.Append(child);
1635 }
1636 }
1637
1638 if ( !noChanges )
1639 {
1640 // constraints are set
1641 break;
1642 }
1643 }
1644
1645 return true;
1646 }
1647
1648 void wxWindowBase::ResetConstraints()
1649 {
1650 wxLayoutConstraints *constr = GetConstraints();
1651 if ( constr )
1652 {
1653 constr->left.SetDone(false);
1654 constr->top.SetDone(false);
1655 constr->right.SetDone(false);
1656 constr->bottom.SetDone(false);
1657 constr->width.SetDone(false);
1658 constr->height.SetDone(false);
1659 constr->centreX.SetDone(false);
1660 constr->centreY.SetDone(false);
1661 }
1662
1663 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1664 while (node)
1665 {
1666 wxWindow *win = node->GetData();
1667 if ( !win->IsTopLevel() )
1668 win->ResetConstraints();
1669 node = node->GetNext();
1670 }
1671 }
1672
1673 // Need to distinguish between setting the 'fake' size for windows and sizers,
1674 // and setting the real values.
1675 void wxWindowBase::SetConstraintSizes(bool recurse)
1676 {
1677 wxLayoutConstraints *constr = GetConstraints();
1678 if ( constr && constr->AreSatisfied() )
1679 {
1680 int x = constr->left.GetValue();
1681 int y = constr->top.GetValue();
1682 int w = constr->width.GetValue();
1683 int h = constr->height.GetValue();
1684
1685 if ( (constr->width.GetRelationship() != wxAsIs ) ||
1686 (constr->height.GetRelationship() != wxAsIs) )
1687 {
1688 SetSize(x, y, w, h);
1689 }
1690 else
1691 {
1692 // If we don't want to resize this window, just move it...
1693 Move(x, y);
1694 }
1695 }
1696 else if ( constr )
1697 {
1698 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1699 GetClassInfo()->GetClassName(),
1700 GetName().c_str());
1701 }
1702
1703 if ( recurse )
1704 {
1705 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1706 while (node)
1707 {
1708 wxWindow *win = node->GetData();
1709 if ( !win->IsTopLevel() && win->GetConstraints() )
1710 win->SetConstraintSizes();
1711 node = node->GetNext();
1712 }
1713 }
1714 }
1715
1716 // Only set the size/position of the constraint (if any)
1717 void wxWindowBase::SetSizeConstraint(int x, int y, int w, int h)
1718 {
1719 wxLayoutConstraints *constr = GetConstraints();
1720 if ( constr )
1721 {
1722 if ( x != -1 )
1723 {
1724 constr->left.SetValue(x);
1725 constr->left.SetDone(true);
1726 }
1727 if ( y != -1 )
1728 {
1729 constr->top.SetValue(y);
1730 constr->top.SetDone(true);
1731 }
1732 if ( w != -1 )
1733 {
1734 constr->width.SetValue(w);
1735 constr->width.SetDone(true);
1736 }
1737 if ( h != -1 )
1738 {
1739 constr->height.SetValue(h);
1740 constr->height.SetDone(true);
1741 }
1742 }
1743 }
1744
1745 void wxWindowBase::MoveConstraint(int x, int y)
1746 {
1747 wxLayoutConstraints *constr = GetConstraints();
1748 if ( constr )
1749 {
1750 if ( x != -1 )
1751 {
1752 constr->left.SetValue(x);
1753 constr->left.SetDone(true);
1754 }
1755 if ( y != -1 )
1756 {
1757 constr->top.SetValue(y);
1758 constr->top.SetDone(true);
1759 }
1760 }
1761 }
1762
1763 void wxWindowBase::GetSizeConstraint(int *w, int *h) const
1764 {
1765 wxLayoutConstraints *constr = GetConstraints();
1766 if ( constr )
1767 {
1768 *w = constr->width.GetValue();
1769 *h = constr->height.GetValue();
1770 }
1771 else
1772 GetSize(w, h);
1773 }
1774
1775 void wxWindowBase::GetClientSizeConstraint(int *w, int *h) const
1776 {
1777 wxLayoutConstraints *constr = GetConstraints();
1778 if ( constr )
1779 {
1780 *w = constr->width.GetValue();
1781 *h = constr->height.GetValue();
1782 }
1783 else
1784 GetClientSize(w, h);
1785 }
1786
1787 void wxWindowBase::GetPositionConstraint(int *x, int *y) const
1788 {
1789 wxLayoutConstraints *constr = GetConstraints();
1790 if ( constr )
1791 {
1792 *x = constr->left.GetValue();
1793 *y = constr->top.GetValue();
1794 }
1795 else
1796 GetPosition(x, y);
1797 }
1798
1799 #endif // wxUSE_CONSTRAINTS
1800
1801 void wxWindowBase::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const
1802 {
1803 // don't do it for the dialogs/frames - they float independently of their
1804 // parent
1805 if ( !IsTopLevel() )
1806 {
1807 wxWindow *parent = GetParent();
1808 if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
1809 {
1810 wxPoint pt(parent->GetClientAreaOrigin());
1811 x += pt.x;
1812 y += pt.y;
1813 }
1814 }
1815 }
1816
1817 // ----------------------------------------------------------------------------
1818 // do Update UI processing for child controls
1819 // ----------------------------------------------------------------------------
1820
1821 void wxWindowBase::UpdateWindowUI(long flags)
1822 {
1823 wxUpdateUIEvent event(GetId());
1824 event.m_eventObject = this;
1825
1826 if ( GetEventHandler()->ProcessEvent(event) )
1827 {
1828 DoUpdateWindowUI(event);
1829 }
1830
1831 if (flags & wxUPDATE_UI_RECURSE)
1832 {
1833 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1834 while (node)
1835 {
1836 wxWindow* child = (wxWindow*) node->GetData();
1837 child->UpdateWindowUI(flags);
1838 node = node->GetNext();
1839 }
1840 }
1841 }
1842
1843 // do the window-specific processing after processing the update event
1844 // TODO: take specific knowledge out of this function and
1845 // put in each control's base class. Unfortunately we don't
1846 // yet have base implementation files for wxCheckBox and wxRadioButton.
1847 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent& event)
1848 {
1849 if ( event.GetSetEnabled() )
1850 Enable(event.GetEnabled());
1851
1852 #if wxUSE_CONTROLS
1853 if ( event.GetSetText() )
1854 {
1855 wxControl *control = wxDynamicCastThis(wxControl);
1856 if ( control )
1857 {
1858 if ( event.GetText() != control->GetLabel() )
1859 control->SetLabel(event.GetText());
1860 }
1861 #if wxUSE_CHECKBOX
1862 wxCheckBox *checkbox = wxDynamicCastThis(wxCheckBox);
1863 if ( checkbox )
1864 {
1865 if ( event.GetSetChecked() )
1866 checkbox->SetValue(event.GetChecked());
1867 }
1868 #endif // wxUSE_CHECKBOX
1869
1870 #if wxUSE_RADIOBTN
1871 wxRadioButton *radiobtn = wxDynamicCastThis(wxRadioButton);
1872 if ( radiobtn )
1873 {
1874 if ( event.GetSetChecked() )
1875 radiobtn->SetValue(event.GetChecked());
1876 }
1877 #endif // wxUSE_RADIOBTN
1878 }
1879 #endif
1880 }
1881
1882 #if 0
1883 // call internal idle recursively
1884 // may be obsolete (wait until OnIdle scheme stabilises)
1885 void wxWindowBase::ProcessInternalIdle()
1886 {
1887 OnInternalIdle();
1888
1889 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1890 while (node)
1891 {
1892 wxWindow *child = node->GetData();
1893 child->ProcessInternalIdle();
1894 node = node->GetNext();
1895 }
1896 }
1897 #endif
1898
1899 // ----------------------------------------------------------------------------
1900 // dialog units translations
1901 // ----------------------------------------------------------------------------
1902
1903 wxPoint wxWindowBase::ConvertPixelsToDialog(const wxPoint& pt)
1904 {
1905 int charWidth = GetCharWidth();
1906 int charHeight = GetCharHeight();
1907 wxPoint pt2(-1, -1);
1908 if (pt.x != -1)
1909 pt2.x = (int) ((pt.x * 4) / charWidth) ;
1910 if (pt.y != -1)
1911 pt2.y = (int) ((pt.y * 8) / charHeight) ;
1912
1913 return pt2;
1914 }
1915
1916 wxPoint wxWindowBase::ConvertDialogToPixels(const wxPoint& pt)
1917 {
1918 int charWidth = GetCharWidth();
1919 int charHeight = GetCharHeight();
1920 wxPoint pt2(-1, -1);
1921 if (pt.x != -1)
1922 pt2.x = (int) ((pt.x * charWidth) / 4) ;
1923 if (pt.y != -1)
1924 pt2.y = (int) ((pt.y * charHeight) / 8) ;
1925
1926 return pt2;
1927 }
1928
1929 // ----------------------------------------------------------------------------
1930 // event handlers
1931 // ----------------------------------------------------------------------------
1932
1933 // propagate the colour change event to the subwindows
1934 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent& event)
1935 {
1936 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
1937 while ( node )
1938 {
1939 // Only propagate to non-top-level windows
1940 wxWindow *win = node->GetData();
1941 if ( !win->IsTopLevel() )
1942 {
1943 wxSysColourChangedEvent event2;
1944 event.m_eventObject = win;
1945 win->GetEventHandler()->ProcessEvent(event2);
1946 }
1947
1948 node = node->GetNext();
1949 }
1950 }
1951
1952 // the default action is to populate dialog with data when it's created,
1953 // and nudge the UI into displaying itself correctly in case
1954 // we've turned the wxUpdateUIEvents frequency down low.
1955 void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
1956 {
1957 TransferDataToWindow();
1958
1959 // Update the UI at this point
1960 UpdateWindowUI(wxUPDATE_UI_RECURSE);
1961 }
1962
1963 // process Ctrl-Alt-mclick
1964 void wxWindowBase::OnMiddleClick( wxMouseEvent& event )
1965 {
1966 #if wxUSE_MSGDLG
1967 if ( event.ControlDown() && event.AltDown() )
1968 {
1969 // don't translate these strings
1970 wxString port;
1971
1972 #ifdef __WXUNIVERSAL__
1973 port = _T("Univ/");
1974 #endif // __WXUNIVERSAL__
1975
1976 switch ( wxGetOsVersion() )
1977 {
1978 case wxMOTIF_X: port += _T("Motif"); break;
1979 case wxMAC:
1980 case wxMAC_DARWIN: port += _T("Mac"); break;
1981 case wxBEOS: port += _T("BeOS"); break;
1982 case wxGTK:
1983 case wxGTK_WIN32:
1984 case wxGTK_OS2:
1985 case wxGTK_BEOS: port += _T("GTK"); break;
1986 case wxWINDOWS:
1987 case wxPENWINDOWS:
1988 case wxWINDOWS_NT:
1989 case wxWIN32S:
1990 case wxWIN95:
1991 case wxWIN386: port += _T("MS Windows"); break;
1992 case wxMGL_UNIX:
1993 case wxMGL_X:
1994 case wxMGL_WIN32:
1995 case wxMGL_OS2: port += _T("MGL"); break;
1996 case wxWINDOWS_OS2:
1997 case wxOS2_PM: port += _T("OS/2"); break;
1998 default: port += _T("unknown"); break;
1999 }
2000
2001 wxMessageBox(wxString::Format(
2002 _T(
2003 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2004 ),
2005 port.c_str(),
2006 wxMAJOR_VERSION,
2007 wxMINOR_VERSION,
2008 wxRELEASE_NUMBER,
2009 #if wxUSE_UNICODE
2010 L" (Unicode)",
2011 #else
2012 "",
2013 #endif
2014 __TDATE__,
2015 __TTIME__
2016 ),
2017 _T("wxWindows information"),
2018 wxICON_INFORMATION | wxOK,
2019 (wxWindow *)this);
2020 }
2021 else
2022 #endif // wxUSE_MSGDLG
2023 {
2024 event.Skip();
2025 }
2026 }
2027
2028 // ----------------------------------------------------------------------------
2029 // accessibility
2030 // ----------------------------------------------------------------------------
2031
2032 #if wxUSE_ACCESSIBILITY
2033 void wxWindowBase::SetAccessible(wxAccessible* accessible)
2034 {
2035 if (m_accessible && (accessible != m_accessible))
2036 delete m_accessible;
2037 m_accessible = accessible;
2038 if (m_accessible)
2039 m_accessible->SetWindow((wxWindow*) this);
2040 }
2041
2042 // Returns the accessible object, creating if necessary.
2043 wxAccessible* wxWindowBase::GetOrCreateAccessible()
2044 {
2045 if (!m_accessible)
2046 m_accessible = CreateAccessible();
2047 return m_accessible;
2048 }
2049
2050 // Override to create a specific accessible object.
2051 wxAccessible* wxWindowBase::CreateAccessible()
2052 {
2053 return new wxWindowAccessible((wxWindow*) this);
2054 }
2055
2056 #endif
2057
2058 #if !wxUSE_STL
2059 // ----------------------------------------------------------------------------
2060 // list classes implementation
2061 // ----------------------------------------------------------------------------
2062
2063 void wxWindowListNode::DeleteData()
2064 {
2065 delete (wxWindow *)GetData();
2066 }
2067 #endif
2068
2069 // ----------------------------------------------------------------------------
2070 // borders
2071 // ----------------------------------------------------------------------------
2072
2073 wxBorder wxWindowBase::GetBorder(long flags) const
2074 {
2075 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
2076 if ( border == wxBORDER_DEFAULT )
2077 {
2078 border = GetDefaultBorder();
2079 }
2080
2081 return border;
2082 }
2083
2084 wxBorder wxWindowBase::GetDefaultBorder() const
2085 {
2086 return wxBORDER_NONE;
2087 }
2088
2089 // ----------------------------------------------------------------------------
2090 // hit testing
2091 // ----------------------------------------------------------------------------
2092
2093 wxHitTest wxWindowBase::DoHitTest(wxCoord x, wxCoord y) const
2094 {
2095 // here we just check if the point is inside the window or not
2096
2097 // check the top and left border first
2098 bool outside = x < 0 || y < 0;
2099 if ( !outside )
2100 {
2101 // check the right and bottom borders too
2102 wxSize size = GetSize();
2103 outside = x >= size.x || y >= size.y;
2104 }
2105
2106 return outside ? wxHT_WINDOW_OUTSIDE : wxHT_WINDOW_INSIDE;
2107 }
2108
2109 // ----------------------------------------------------------------------------
2110 // mouse capture
2111 // ----------------------------------------------------------------------------
2112
2113 struct WXDLLEXPORT wxWindowNext
2114 {
2115 wxWindow *win;
2116 wxWindowNext *next;
2117 } *wxWindowBase::ms_winCaptureNext = NULL;
2118
2119 void wxWindowBase::CaptureMouse()
2120 {
2121 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2122
2123 wxWindow *winOld = GetCapture();
2124 if ( winOld )
2125 {
2126 ((wxWindowBase*) winOld)->DoReleaseMouse();
2127
2128 // save it on stack
2129 wxWindowNext *item = new wxWindowNext;
2130 item->win = winOld;
2131 item->next = ms_winCaptureNext;
2132 ms_winCaptureNext = item;
2133 }
2134 //else: no mouse capture to save
2135
2136 DoCaptureMouse();
2137 }
2138
2139 void wxWindowBase::ReleaseMouse()
2140 {
2141 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2142
2143 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2144
2145 DoReleaseMouse();
2146
2147 if ( ms_winCaptureNext )
2148 {
2149 ((wxWindowBase*)ms_winCaptureNext->win)->DoCaptureMouse();
2150
2151 wxWindowNext *item = ms_winCaptureNext;
2152 ms_winCaptureNext = item->next;
2153 delete item;
2154 }
2155 //else: stack is empty, no previous capture
2156
2157 wxLogTrace(_T("mousecapture"),
2158 (const wxChar *) _T("After ReleaseMouse() mouse is captured by %p"),
2159 GetCapture());
2160 }
2161
2162 #if wxUSE_HOTKEY
2163
2164 bool
2165 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId),
2166 int WXUNUSED(modifiers),
2167 int WXUNUSED(keycode))
2168 {
2169 // not implemented
2170 return false;
2171 }
2172
2173 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId))
2174 {
2175 // not implemented
2176 return false;
2177 }
2178
2179 #endif // wxUSE_HOTKEY
2180
2181 void wxWindowBase::SendDestroyEvent()
2182 {
2183 wxWindowDestroyEvent event;
2184 event.SetEventObject(this);
2185 event.SetId(GetId());
2186 GetEventHandler()->ProcessEvent(event);
2187 }
2188
2189 // ----------------------------------------------------------------------------
2190 // event processing
2191 // ----------------------------------------------------------------------------
2192
2193 bool wxWindowBase::TryValidator(wxEvent& wxVALIDATOR_PARAM(event))
2194 {
2195 #if wxUSE_VALIDATORS
2196 // Can only use the validator of the window which
2197 // is receiving the event
2198 if ( event.GetEventObject() == this )
2199 {
2200 wxValidator *validator = GetValidator();
2201 if ( validator && validator->ProcessEvent(event) )
2202 {
2203 return true;
2204 }
2205 }
2206 #endif // wxUSE_VALIDATORS
2207
2208 return false;
2209 }
2210
2211 bool wxWindowBase::TryParent(wxEvent& event)
2212 {
2213 // carry on up the parent-child hierarchy if the propgation count hasn't
2214 // reached zero yet
2215 if ( event.ShouldPropagate() )
2216 {
2217 // honour the requests to stop propagation at this window: this is
2218 // used by the dialogs, for example, to prevent processing the events
2219 // from the dialog controls in the parent frame which rarely, if ever,
2220 // makes sense
2221 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
2222 {
2223 wxWindow *parent = GetParent();
2224 if ( parent && !parent->IsBeingDeleted() )
2225 {
2226 wxPropagateOnce propagateOnce(event);
2227
2228 return parent->GetEventHandler()->ProcessEvent(event);
2229 }
2230 }
2231 }
2232
2233 return wxEvtHandler::TryParent(event);
2234 }
2235
2236 // ----------------------------------------------------------------------------
2237 // global functions
2238 // ----------------------------------------------------------------------------
2239
2240 wxWindow* wxGetTopLevelParent(wxWindow *win)
2241 {
2242 while ( win && !win->IsTopLevel() )
2243 win = win->GetParent();
2244
2245 return win;
2246 }
2247
2248 #if wxUSE_ACCESSIBILITY
2249 // ----------------------------------------------------------------------------
2250 // accessible object for windows
2251 // ----------------------------------------------------------------------------
2252
2253 // Can return either a child object, or an integer
2254 // representing the child element, starting from 1.
2255 wxAccStatus wxWindowAccessible::HitTest(const wxPoint& WXUNUSED(pt), int* WXUNUSED(childId), wxAccessible** WXUNUSED(childObject))
2256 {
2257 wxASSERT( GetWindow() != NULL );
2258 if (!GetWindow())
2259 return wxACC_FAIL;
2260
2261 return wxACC_NOT_IMPLEMENTED;
2262 }
2263
2264 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2265 wxAccStatus wxWindowAccessible::GetLocation(wxRect& rect, int elementId)
2266 {
2267 wxASSERT( GetWindow() != NULL );
2268 if (!GetWindow())
2269 return wxACC_FAIL;
2270
2271 wxWindow* win = NULL;
2272 if (elementId == 0)
2273 {
2274 win = GetWindow();
2275 }
2276 else
2277 {
2278 if (elementId <= (int) GetWindow()->GetChildren().GetCount())
2279 {
2280 win = GetWindow()->GetChildren().Item(elementId-1)->GetData();
2281 }
2282 else
2283 return wxACC_FAIL;
2284 }
2285 if (win)
2286 {
2287 rect = win->GetRect();
2288 if (win->GetParent() && !win->IsKindOf(CLASSINFO(wxTopLevelWindow)))
2289 rect.SetPosition(win->GetParent()->ClientToScreen(rect.GetPosition()));
2290 return wxACC_OK;
2291 }
2292
2293 return wxACC_NOT_IMPLEMENTED;
2294 }
2295
2296 // Navigates from fromId to toId/toObject.
2297 wxAccStatus wxWindowAccessible::Navigate(wxNavDir navDir, int fromId,
2298 int* WXUNUSED(toId), wxAccessible** toObject)
2299 {
2300 wxASSERT( GetWindow() != NULL );
2301 if (!GetWindow())
2302 return wxACC_FAIL;
2303
2304 switch (navDir)
2305 {
2306 case wxNAVDIR_FIRSTCHILD:
2307 {
2308 if (GetWindow()->GetChildren().GetCount() == 0)
2309 return wxACC_FALSE;
2310 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetFirst()->GetData();
2311 *toObject = childWindow->GetOrCreateAccessible();
2312
2313 return wxACC_OK;
2314 }
2315 case wxNAVDIR_LASTCHILD:
2316 {
2317 if (GetWindow()->GetChildren().GetCount() == 0)
2318 return wxACC_FALSE;
2319 wxWindow* childWindow = (wxWindow*) GetWindow()->GetChildren().GetLast()->GetData();
2320 *toObject = childWindow->GetOrCreateAccessible();
2321
2322 return wxACC_OK;
2323 }
2324 case wxNAVDIR_RIGHT:
2325 case wxNAVDIR_DOWN:
2326 case wxNAVDIR_NEXT:
2327 {
2328 wxWindowList::compatibility_iterator node =
2329 wxWindowList::compatibility_iterator();
2330 if (fromId == 0)
2331 {
2332 // Can't navigate to sibling of this window
2333 // if we're a top-level window.
2334 if (!GetWindow()->GetParent())
2335 return wxACC_NOT_IMPLEMENTED;
2336
2337 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2338 }
2339 else
2340 {
2341 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2342 node = GetWindow()->GetChildren().Item(fromId-1);
2343 }
2344
2345 if (node && node->GetNext())
2346 {
2347 wxWindow* nextWindow = node->GetNext()->GetData();
2348 *toObject = nextWindow->GetOrCreateAccessible();
2349 return wxACC_OK;
2350 }
2351 else
2352 return wxACC_FALSE;
2353 }
2354 case wxNAVDIR_LEFT:
2355 case wxNAVDIR_UP:
2356 case wxNAVDIR_PREVIOUS:
2357 {
2358 wxWindowList::compatibility_iterator node =
2359 wxWindowList::compatibility_iterator();
2360 if (fromId == 0)
2361 {
2362 // Can't navigate to sibling of this window
2363 // if we're a top-level window.
2364 if (!GetWindow()->GetParent())
2365 return wxACC_NOT_IMPLEMENTED;
2366
2367 node = GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2368 }
2369 else
2370 {
2371 if (fromId <= (int) GetWindow()->GetChildren().GetCount())
2372 node = GetWindow()->GetChildren().Item(fromId-1);
2373 }
2374
2375 if (node && node->GetPrevious())
2376 {
2377 wxWindow* previousWindow = node->GetPrevious()->GetData();
2378 *toObject = previousWindow->GetOrCreateAccessible();
2379 return wxACC_OK;
2380 }
2381 else
2382 return wxACC_FALSE;
2383 }
2384 }
2385
2386 return wxACC_NOT_IMPLEMENTED;
2387 }
2388
2389 // Gets the name of the specified object.
2390 wxAccStatus wxWindowAccessible::GetName(int childId, wxString* name)
2391 {
2392 wxASSERT( GetWindow() != NULL );
2393 if (!GetWindow())
2394 return wxACC_FAIL;
2395
2396 wxString title;
2397
2398 // If a child, leave wxWindows to call the function on the actual
2399 // child object.
2400 if (childId > 0)
2401 return wxACC_NOT_IMPLEMENTED;
2402
2403 // This will eventually be replaced by specialised
2404 // accessible classes, one for each kind of wxWindows
2405 // control or window.
2406 if (GetWindow()->IsKindOf(CLASSINFO(wxButton)))
2407 title = ((wxButton*) GetWindow())->GetLabel();
2408 else
2409 title = GetWindow()->GetName();
2410
2411 if (!title.IsEmpty())
2412 {
2413 *name = title;
2414 return wxACC_OK;
2415 }
2416 else
2417 return wxACC_NOT_IMPLEMENTED;
2418 }
2419
2420 // Gets the number of children.
2421 wxAccStatus wxWindowAccessible::GetChildCount(int* childId)
2422 {
2423 wxASSERT( GetWindow() != NULL );
2424 if (!GetWindow())
2425 return wxACC_FAIL;
2426
2427 *childId = (int) GetWindow()->GetChildren().GetCount();
2428 return wxACC_OK;
2429 }
2430
2431 // Gets the specified child (starting from 1).
2432 // If *child is NULL and return value is wxACC_OK,
2433 // this means that the child is a simple element and
2434 // not an accessible object.
2435 wxAccStatus wxWindowAccessible::GetChild(int childId, wxAccessible** child)
2436 {
2437 wxASSERT( GetWindow() != NULL );
2438 if (!GetWindow())
2439 return wxACC_FAIL;
2440
2441 if (childId == 0)
2442 {
2443 *child = this;
2444 return wxACC_OK;
2445 }
2446
2447 if (childId > (int) GetWindow()->GetChildren().GetCount())
2448 return wxACC_FAIL;
2449
2450 wxWindow* childWindow = GetWindow()->GetChildren().Item(childId-1)->GetData();
2451 *child = childWindow->GetOrCreateAccessible();
2452 if (*child)
2453 return wxACC_OK;
2454 else
2455 return wxACC_FAIL;
2456 }
2457
2458 // Gets the parent, or NULL.
2459 wxAccStatus wxWindowAccessible::GetParent(wxAccessible** parent)
2460 {
2461 wxASSERT( GetWindow() != NULL );
2462 if (!GetWindow())
2463 return wxACC_FAIL;
2464
2465 wxWindow* parentWindow = GetWindow()->GetParent();
2466 if (!parentWindow)
2467 {
2468 *parent = NULL;
2469 return wxACC_OK;
2470 }
2471 else
2472 {
2473 *parent = parentWindow->GetOrCreateAccessible();
2474 if (*parent)
2475 return wxACC_OK;
2476 else
2477 return wxACC_FAIL;
2478 }
2479 }
2480
2481 // Performs the default action. childId is 0 (the action for this object)
2482 // or > 0 (the action for a child).
2483 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2484 // window (e.g. an edit control).
2485 wxAccStatus wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
2486 {
2487 wxASSERT( GetWindow() != NULL );
2488 if (!GetWindow())
2489 return wxACC_FAIL;
2490
2491 return wxACC_NOT_IMPLEMENTED;
2492 }
2493
2494 // Gets the default action for this object (0) or > 0 (the action for a child).
2495 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2496 // string if there is no action.
2497 // The retrieved string describes the action that is performed on an object,
2498 // not what the object does as a result. For example, a toolbar button that prints
2499 // a document has a default action of "Press" rather than "Prints the current document."
2500 wxAccStatus wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId), wxString* WXUNUSED(actionName))
2501 {
2502 wxASSERT( GetWindow() != NULL );
2503 if (!GetWindow())
2504 return wxACC_FAIL;
2505
2506 return wxACC_NOT_IMPLEMENTED;
2507 }
2508
2509 // Returns the description for this object or a child.
2510 wxAccStatus wxWindowAccessible::GetDescription(int WXUNUSED(childId), wxString* description)
2511 {
2512 wxASSERT( GetWindow() != NULL );
2513 if (!GetWindow())
2514 return wxACC_FAIL;
2515
2516 wxString ht(GetWindow()->GetHelpText());
2517 if (!ht.IsEmpty())
2518 {
2519 *description = ht;
2520 return wxACC_OK;
2521 }
2522 return wxACC_NOT_IMPLEMENTED;
2523 }
2524
2525 // Returns help text for this object or a child, similar to tooltip text.
2526 wxAccStatus wxWindowAccessible::GetHelpText(int WXUNUSED(childId), wxString* helpText)
2527 {
2528 wxASSERT( GetWindow() != NULL );
2529 if (!GetWindow())
2530 return wxACC_FAIL;
2531
2532 wxString ht(GetWindow()->GetHelpText());
2533 if (!ht.IsEmpty())
2534 {
2535 *helpText = ht;
2536 return wxACC_OK;
2537 }
2538 return wxACC_NOT_IMPLEMENTED;
2539 }
2540
2541 // Returns the keyboard shortcut for this object or child.
2542 // Return e.g. ALT+K
2543 wxAccStatus wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId), wxString* WXUNUSED(shortcut))
2544 {
2545 wxASSERT( GetWindow() != NULL );
2546 if (!GetWindow())
2547 return wxACC_FAIL;
2548
2549 return wxACC_NOT_IMPLEMENTED;
2550 }
2551
2552 // Returns a role constant.
2553 wxAccStatus wxWindowAccessible::GetRole(int childId, wxAccRole* role)
2554 {
2555 wxASSERT( GetWindow() != NULL );
2556 if (!GetWindow())
2557 return wxACC_FAIL;
2558
2559 // If a child, leave wxWindows to call the function on the actual
2560 // child object.
2561 if (childId > 0)
2562 return wxACC_NOT_IMPLEMENTED;
2563
2564 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2565 return wxACC_NOT_IMPLEMENTED;
2566 #if wxUSE_STATUSBAR
2567 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2568 return wxACC_NOT_IMPLEMENTED;
2569 #endif
2570 #if wxUSE_TOOLBAR
2571 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2572 return wxACC_NOT_IMPLEMENTED;
2573 #endif
2574
2575 //*role = wxROLE_SYSTEM_CLIENT;
2576 *role = wxROLE_SYSTEM_CLIENT;
2577 return wxACC_OK;
2578
2579 #if 0
2580 return wxACC_NOT_IMPLEMENTED;
2581 #endif
2582 }
2583
2584 // Returns a state constant.
2585 wxAccStatus wxWindowAccessible::GetState(int childId, long* state)
2586 {
2587 wxASSERT( GetWindow() != NULL );
2588 if (!GetWindow())
2589 return wxACC_FAIL;
2590
2591 // If a child, leave wxWindows to call the function on the actual
2592 // child object.
2593 if (childId > 0)
2594 return wxACC_NOT_IMPLEMENTED;
2595
2596 if (GetWindow()->IsKindOf(CLASSINFO(wxControl)))
2597 return wxACC_NOT_IMPLEMENTED;
2598
2599 #if wxUSE_STATUSBAR
2600 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar)))
2601 return wxACC_NOT_IMPLEMENTED;
2602 #endif
2603 #if wxUSE_TOOLBAR
2604 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar)))
2605 return wxACC_NOT_IMPLEMENTED;
2606 #endif
2607
2608 *state = 0;
2609 return wxACC_OK;
2610
2611 #if 0
2612 return wxACC_NOT_IMPLEMENTED;
2613 #endif
2614 }
2615
2616 // Returns a localized string representing the value for the object
2617 // or child.
2618 wxAccStatus wxWindowAccessible::GetValue(int WXUNUSED(childId), wxString* WXUNUSED(strValue))
2619 {
2620 wxASSERT( GetWindow() != NULL );
2621 if (!GetWindow())
2622 return wxACC_FAIL;
2623
2624 return wxACC_NOT_IMPLEMENTED;
2625 }
2626
2627 // Selects the object or child.
2628 wxAccStatus wxWindowAccessible::Select(int WXUNUSED(childId), wxAccSelectionFlags WXUNUSED(selectFlags))
2629 {
2630 wxASSERT( GetWindow() != NULL );
2631 if (!GetWindow())
2632 return wxACC_FAIL;
2633
2634 return wxACC_NOT_IMPLEMENTED;
2635 }
2636
2637 // Gets the window with the keyboard focus.
2638 // If childId is 0 and child is NULL, no object in
2639 // this subhierarchy has the focus.
2640 // If this object has the focus, child should be 'this'.
2641 wxAccStatus wxWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
2642 {
2643 wxASSERT( GetWindow() != NULL );
2644 if (!GetWindow())
2645 return wxACC_FAIL;
2646
2647 return wxACC_NOT_IMPLEMENTED;
2648 }
2649
2650 // Gets a variant representing the selected children
2651 // of this object.
2652 // Acceptable values:
2653 // - a null variant (IsNull() returns TRUE)
2654 // - a list variant (GetType() == wxT("list")
2655 // - an integer representing the selected child element,
2656 // or 0 if this object is selected (GetType() == wxT("long")
2657 // - a "void*" pointer to a wxAccessible child object
2658 wxAccStatus wxWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
2659 {
2660 wxASSERT( GetWindow() != NULL );
2661 if (!GetWindow())
2662 return wxACC_FAIL;
2663
2664 return wxACC_NOT_IMPLEMENTED;
2665 }
2666
2667 #endif // wxUSE_ACCESSIBILITY