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