]> git.saurik.com Git - wxWidgets.git/blame - src/common/containr.cpp
Implement incremental search in wxGenericListCtrl.
[wxWidgets.git] / src / common / containr.cpp
CommitLineData
456bc6d9
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/containr.cpp
3// Purpose: implementation of wxControlContainer
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 06.08.01
7// RCS-ID: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
526954c5 9// Licence: wxWindows licence
456bc6d9
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
456bc6d9
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
de160b06
VZ
27#ifndef WX_PRECOMP
28 #include "wx/containr.h"
29#endif
30
456bc6d9 31#ifndef WX_PRECOMP
6285be72
VZ
32 #include "wx/log.h"
33 #include "wx/event.h"
34 #include "wx/window.h"
851dee09 35 #include "wx/scrolbar.h"
b0b5881a 36 #include "wx/radiobut.h"
456bc6d9
VZ
37#endif //WX_PRECOMP
38
9f542367 39// trace mask for focus messages
9a83f860 40#define TRACE_FOCUS wxT("focus")
9f542367 41
456bc6d9
VZ
42// ============================================================================
43// implementation
44// ============================================================================
45
80332672
VZ
46// ----------------------------------------------------------------------------
47// wxControlContainerBase
48// ----------------------------------------------------------------------------
49
50void wxControlContainerBase::SetCanFocus(bool acceptsFocus)
456bc6d9 51{
80332672
VZ
52 if ( acceptsFocus == m_acceptsFocus )
53 return;
54
55 m_acceptsFocus = acceptsFocus;
56
57 m_winParent->SetCanFocus(m_acceptsFocus);
456bc6d9
VZ
58}
59
edc09871 60bool wxControlContainerBase::HasAnyFocusableChildren() const
3251b834 61{
edc09871
VZ
62 const wxWindowList& children = m_winParent->GetChildren();
63 for ( wxWindowList::const_iterator i = children.begin(),
64 end = children.end();
65 i != end;
66 ++i )
de160b06 67 {
edc09871 68 const wxWindow * const child = *i;
3251b834 69
049908c5 70 if ( !m_winParent->IsClientAreaChild(child) )
de160b06 71 continue;
80332672 72
de160b06 73 if ( child->CanAcceptFocus() )
edc09871 74 return true;
de160b06 75 }
c9d59ee7 76
edc09871 77 return false;
80332672
VZ
78}
79
c7bfb76a
JS
80bool wxControlContainerBase::DoSetFocus()
81{
9a83f860 82 wxLogTrace(TRACE_FOCUS, wxT("SetFocus on wxPanel 0x%p."),
c7bfb76a
JS
83 m_winParent->GetHandle());
84
85 if (m_inSetFocus)
86 return true;
87
88 // when the panel gets the focus we move the focus to either the last
89 // window that had the focus or the first one that can get it unless the
90 // focus had been already set to some other child
91
92 wxWindow *win = wxWindow::FindFocus();
93 while ( win )
94 {
95 if ( win == m_winParent )
96 {
97 // our child already has focus, don't take it away from it
98 return true;
99 }
100
101 if ( win->IsTopLevel() )
102 {
103 // don't look beyond the first top level parent - useless and
104 // unnecessary
105 break;
106 }
107
108 win = win->GetParent();
109 }
110
111 // protect against infinite recursion:
112 m_inSetFocus = true;
113
114 bool ret = SetFocusToChild();
115
116 m_inSetFocus = false;
117
118 return ret;
119}
120
121bool wxControlContainerBase::SetFocusToChild()
122{
123 return wxSetFocusToChild(m_winParent, &m_winLastFocused);
124}
125
80332672 126#ifndef wxHAS_NATIVE_TAB_TRAVERSAL
3251b834 127
80332672
VZ
128// ----------------------------------------------------------------------------
129// generic wxControlContainer
130// ----------------------------------------------------------------------------
131
132wxControlContainer::wxControlContainer()
133{
134 m_winLastFocused = NULL;
3251b834
VZ
135}
136
456bc6d9
VZ
137void wxControlContainer::SetLastFocus(wxWindow *win)
138{
6aeb6f2a
VZ
139 // the panel itself should never get the focus at all but if it does happen
140 // temporarily (as it seems to do under wxGTK), at the very least don't
141 // forget our previous m_winLastFocused
c25b5d1f 142 if ( win != m_winParent )
456bc6d9 143 {
c25b5d1f
VZ
144 // if we're setting the focus
145 if ( win )
83c865f5 146 {
c25b5d1f
VZ
147 // find the last _immediate_ child which got focus
148 wxWindow *winParent = win;
149 while ( winParent != m_winParent )
150 {
151 win = winParent;
152 winParent = win->GetParent();
83c865f5 153
c25b5d1f
VZ
154 // Yes, this can happen, though in a totally pathological case.
155 // like when detaching a menubar from a frame with a child
156 // which has pushed itself as an event handler for the menubar.
157 // (under wxGTK)
6f8239de 158
c25b5d1f 159 wxASSERT_MSG( winParent,
9a83f860 160 wxT("Setting last focus for a window that is not our child?") );
c25b5d1f 161 }
6f8239de 162 }
456bc6d9 163
c25b5d1f 164 m_winLastFocused = win;
6aeb6f2a 165
c25b5d1f
VZ
166 if ( win )
167 {
9a83f860 168 wxLogTrace(TRACE_FOCUS, wxT("Set last focus to %s(%s)"),
c25b5d1f
VZ
169 win->GetClassInfo()->GetClassName(),
170 win->GetLabel().c_str());
171 }
172 else
173 {
9a83f860 174 wxLogTrace(TRACE_FOCUS, wxT("No more last focus"));
c25b5d1f 175 }
6aeb6f2a 176 }
456bc6d9
VZ
177}
178
7ff1b620 179// --------------------------------------------------------------------
b49f58fe 180// The following four functions are used to find other radio buttons
7ff1b620
VZ
181// within the same group. Used by wxSetFocusToChild on wxMSW
182// --------------------------------------------------------------------
183
a8ff046b 184#if defined(__WXMSW__) && wxUSE_RADIOBTN
7ff1b620
VZ
185
186wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn)
187{
188 if ( btn->HasFlag(wxRB_GROUP) || btn->HasFlag(wxRB_SINGLE) )
189 return NULL;
190
191 const wxWindowList& siblings = btn->GetParent()->GetChildren();
192 wxWindowList::compatibility_iterator nodeThis = siblings.Find(btn);
9a83f860 193 wxCHECK_MSG( nodeThis, NULL, wxT("radio button not a child of its parent?") );
7ff1b620
VZ
194
195 // Iterate over all previous siblings until we find the next radio button
196 wxWindowList::compatibility_iterator nodeBefore = nodeThis->GetPrevious();
197 wxRadioButton *prevBtn = 0;
198 while (nodeBefore)
199 {
200 prevBtn = wxDynamicCast(nodeBefore->GetData(), wxRadioButton);
201 if (prevBtn)
202 break;
203
204 nodeBefore = nodeBefore->GetPrevious();
205 }
b49f58fe 206
7ff1b620
VZ
207 if (!prevBtn || prevBtn->HasFlag(wxRB_SINGLE))
208 {
209 // no more buttons in group
210 return NULL;
211 }
3d3afaec
JS
212
213 return prevBtn;
7ff1b620
VZ
214}
215
216wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn)
217{
218 if (btn->HasFlag(wxRB_SINGLE))
219 return NULL;
220
221 const wxWindowList& siblings = btn->GetParent()->GetChildren();
222 wxWindowList::compatibility_iterator nodeThis = siblings.Find(btn);
9a83f860 223 wxCHECK_MSG( nodeThis, NULL, wxT("radio button not a child of its parent?") );
7ff1b620
VZ
224
225 // Iterate over all previous siblings until we find the next radio button
226 wxWindowList::compatibility_iterator nodeNext = nodeThis->GetNext();
227 wxRadioButton *nextBtn = 0;
228 while (nodeNext)
229 {
230 nextBtn = wxDynamicCast(nodeNext->GetData(), wxRadioButton);
231 if (nextBtn)
232 break;
233
234 nodeNext = nodeNext->GetNext();
235 }
236
237 if ( !nextBtn || nextBtn->HasFlag(wxRB_GROUP) || nextBtn->HasFlag(wxRB_SINGLE) )
238 {
239 // no more buttons or the first button of the next group
240 return NULL;
241 }
3d3afaec
JS
242
243 return nextBtn;
7ff1b620
VZ
244}
245
246wxRadioButton* wxGetFirstButtonInGroup(wxRadioButton *btn)
247{
248 while (true)
249 {
250 wxRadioButton* prevBtn = wxGetPreviousButtonInGroup(btn);
251 if (!prevBtn)
252 return btn;
b49f58fe 253
7ff1b620
VZ
254 btn = prevBtn;
255 }
256}
257
3d3afaec
JS
258wxRadioButton* wxGetLastButtonInGroup(wxRadioButton *btn)
259{
260 while (true)
261 {
262 wxRadioButton* nextBtn = wxGetNextButtonInGroup(btn);
263 if (!nextBtn)
264 return btn;
265
266 btn = nextBtn;
267 }
268}
269
7ff1b620
VZ
270wxRadioButton* wxGetSelectedButtonInGroup(wxRadioButton *btn)
271{
272 // Find currently selected button
273 if (btn->GetValue())
274 return btn;
275
276 if (btn->HasFlag(wxRB_SINGLE))
277 return NULL;
278
279 wxRadioButton *selBtn;
280
281 // First check all previous buttons
282 for (selBtn = wxGetPreviousButtonInGroup(btn); selBtn; selBtn = wxGetPreviousButtonInGroup(selBtn))
283 if (selBtn->GetValue())
284 return selBtn;
285
286 // Now all following buttons
287 for (selBtn = wxGetNextButtonInGroup(btn); selBtn; selBtn = wxGetNextButtonInGroup(selBtn))
288 if (selBtn->GetValue())
289 return selBtn;
290
291 return NULL;
292}
293
b49f58fe 294#endif // __WXMSW__
7ff1b620 295
456bc6d9
VZ
296// ----------------------------------------------------------------------------
297// Keyboard handling - this is the place where the TAB traversal logic is
298// implemented. As this code is common to all ports, this ensures consistent
299// behaviour even if we don't specify how exactly the wxNavigationKeyEvent are
300// generated and this is done in platform specific code which also ensures that
301// we can follow the given platform standards.
302// ----------------------------------------------------------------------------
303
304void wxControlContainer::HandleOnNavigationKey( wxNavigationKeyEvent& event )
305{
391b1695
VZ
306 // for a TLW we shouldn't involve the parent window, it has nothing to do
307 // with keyboard navigation inside this TLW
308 wxWindow *parent = m_winParent->IsTopLevel() ? NULL
309 : m_winParent->GetParent();
456bc6d9
VZ
310
311 // the event is propagated downwards if the event emitter was our parent
312 bool goingDown = event.GetEventObject() == parent;
313
314 const wxWindowList& children = m_winParent->GetChildren();
315
f2426531
VZ
316 // if we have exactly one notebook-like child window (actually it could be
317 // any window that returns true from its HasMultiplePages()), then
318 // [Shift-]Ctrl-Tab and Ctrl-PageUp/Down keys should iterate over its pages
319 // even if the focus is outside of the control because this is how the
320 // standard MSW properties dialogs behave and we do it under other platforms
321 // as well because it seems like a good idea -- but we can always put this
322 // block inside "#ifdef __WXMSW__" if it's not suitable there
323 if ( event.IsWindowChange() && !goingDown )
324 {
325 // check if we have a unique notebook-like child
326 wxWindow *bookctrl = NULL;
327 for ( wxWindowList::const_iterator i = children.begin(),
328 end = children.end();
329 i != end;
330 ++i )
331 {
332 wxWindow * const window = *i;
333 if ( window->HasMultiplePages() )
334 {
335 if ( bookctrl )
336 {
337 // this is the second book-like control already so don't do
338 // anything as we don't know which one should have its page
339 // changed
340 bookctrl = NULL;
341 break;
342 }
343
344 bookctrl = window;
345 }
346 }
347
5f28de16
VZ
348 if ( bookctrl )
349 {
350 // make sure that we don't bubble up the event again from the book
351 // control resulting in infinite recursion
352 wxNavigationKeyEvent eventCopy(event);
353 eventCopy.SetEventObject(m_winParent);
354 if ( bookctrl->GetEventHandler()->ProcessEvent(eventCopy) )
355 return;
356 }
f2426531
VZ
357 }
358
456bc6d9
VZ
359 // there is not much to do if we don't have children and we're not
360 // interested in "notebook page change" events here
361 if ( !children.GetCount() || event.IsWindowChange() )
362 {
363 // let the parent process it unless it already comes from our parent
364 // of we don't have any
365 if ( goingDown ||
366 !parent || !parent->GetEventHandler()->ProcessEvent(event) )
367 {
368 event.Skip();
369 }
370
371 return;
372 }
373
374 // where are we going?
edc0a395 375 const bool forward = event.GetDirection();
456bc6d9
VZ
376
377 // the node of the children list from which we should start looking for the
378 // next acceptable child
222ed1d6 379 wxWindowList::compatibility_iterator node, start_node;
456bc6d9
VZ
380
381 // we should start from the first/last control and not from the one which
382 // had focus the last time if we're propagating the event downwards because
383 // for our parent we look like a single control
384 if ( goingDown )
385 {
386 // just to be sure it's not used (normally this is not necessary, but
387 // doesn't hurt neither)
d3b9f782 388 m_winLastFocused = NULL;
456bc6d9
VZ
389
390 // start from first or last depending on where we're going
391 node = forward ? children.GetFirst() : children.GetLast();
456bc6d9 392 }
edc0a395 393 else // going up
456bc6d9
VZ
394 {
395 // try to find the child which has the focus currently
396
397 // the event emitter might have done this for us
398 wxWindow *winFocus = event.GetCurrentFocus();
399
400 // but if not, we might know where the focus was ourselves
401 if (!winFocus)
402 winFocus = m_winLastFocused;
403
404 // if still no luck, do it the hard way
405 if (!winFocus)
406 winFocus = wxWindow::FindFocus();
407
408 if ( winFocus )
409 {
a8ff046b 410#if defined(__WXMSW__) && wxUSE_RADIOBTN
b49f58fe 411 // If we are in a radio button group, start from the first item in the
7ff1b620
VZ
412 // group
413 if ( event.IsFromTab() && wxIsKindOf(winFocus, wxRadioButton ) )
414 winFocus = wxGetFirstButtonInGroup((wxRadioButton*)winFocus);
a8ff046b 415#endif // __WXMSW__
456bc6d9
VZ
416 // ok, we found the focus - now is it our child?
417 start_node = children.Find( winFocus );
418 }
456bc6d9
VZ
419
420 if ( !start_node && m_winLastFocused )
421 {
422 // window which has focus isn't our child, fall back to the one
423 // which had the focus the last time
424 start_node = children.Find( m_winLastFocused );
425 }
426
427 // if we still didn't find anything, we should start with the first one
428 if ( !start_node )
429 {
430 start_node = children.GetFirst();
431 }
432
433 // and the first child which we can try setting focus to is the next or
434 // the previous one
435 node = forward ? start_node->GetNext() : start_node->GetPrevious();
436 }
437
438 // we want to cycle over all elements passing by NULL
edc0a395 439 for ( ;; )
456bc6d9 440 {
edc0a395 441 // don't go into infinite loop
aa78d22e 442 if ( start_node && node && node == start_node )
edc0a395
VZ
443 break;
444
456bc6d9
VZ
445 // Have we come to the last or first item on the panel?
446 if ( !node )
447 {
e547f7a7
VZ
448 if ( !start_node )
449 {
450 // exit now as otherwise we'd loop forever
451 break;
452 }
453
456bc6d9
VZ
454 if ( !goingDown )
455 {
edc0a395 456 // Check if our (maybe grand) parent is another panel: if this
456bc6d9
VZ
457 // is the case, they will know what to do with this navigation
458 // key and so give them the chance to process it instead of
459 // looping inside this panel (normally, the focus will go to
460 // the next/previous item after this panel in the parent
461 // panel).
2a0777a8 462 wxWindow *focusedParent = m_winParent;
456bc6d9
VZ
463 while ( parent )
464 {
6e92c299
VZ
465 // We don't want to tab into a different dialog or frame or
466 // even an MDI child frame, so test for this explicitly
467 // (and in particular don't just use IsTopLevel() which
468 // would return false in the latter case).
469 if ( focusedParent->IsTopNavigationDomain() )
456bc6d9
VZ
470 break;
471
2a0777a8 472 event.SetCurrentFocus( focusedParent );
456bc6d9
VZ
473 if ( parent->GetEventHandler()->ProcessEvent( event ) )
474 return;
475
2a0777a8 476 focusedParent = parent;
456bc6d9
VZ
477
478 parent = parent->GetParent();
479 }
480 }
481 //else: as the focus came from our parent, we definitely don't want
482 // to send it back to it!
483
484 // no, we are not inside another panel so process this ourself
485 node = forward ? children.GetFirst() : children.GetLast();
486
487 continue;
488 }
489
490 wxWindow *child = node->GetData();
491
e49d331c
VZ
492 // don't TAB to another TLW
493 if ( child->IsTopLevel() )
494 {
495 node = forward ? node->GetNext() : node->GetPrevious();
496
497 continue;
498 }
499
a8ff046b 500#if defined(__WXMSW__) && wxUSE_RADIOBTN
3d3afaec 501 if ( event.IsFromTab() )
7ff1b620 502 {
3d3afaec 503 if ( wxIsKindOf(child, wxRadioButton) )
7ff1b620 504 {
3d3afaec
JS
505 // only radio buttons with either wxRB_GROUP or wxRB_SINGLE
506 // can be tabbed to
507 if ( child->HasFlag(wxRB_GROUP) )
7ff1b620 508 {
3d3afaec
JS
509 // need to tab into the active button within a group
510 wxRadioButton *rb = wxGetSelectedButtonInGroup((wxRadioButton*)child);
511 if ( rb )
512 child = rb;
513 }
514 else if ( !child->HasFlag(wxRB_SINGLE) )
515 {
516 node = forward ? node->GetNext() : node->GetPrevious();
517 continue;
7ff1b620
VZ
518 }
519 }
520 }
3d3afaec
JS
521 else if ( m_winLastFocused &&
522 wxIsKindOf(m_winLastFocused, wxRadioButton) &&
523 !m_winLastFocused->HasFlag(wxRB_SINGLE) )
7ff1b620 524 {
506f9e92 525 wxRadioButton * const
5c33522f 526 lastBtn = static_cast<wxRadioButton *>(m_winLastFocused);
506f9e92 527
3d3afaec
JS
528 // cursor keys don't navigate out of a radio button group so
529 // find the correct radio button to focus
530 if ( forward )
7ff1b620 531 {
506f9e92 532 child = wxGetNextButtonInGroup(lastBtn);
3d3afaec
JS
533 if ( !child )
534 {
535 // no next button in group, set it to the first button
506f9e92 536 child = wxGetFirstButtonInGroup(lastBtn);
3d3afaec
JS
537 }
538 }
539 else
540 {
506f9e92 541 child = wxGetPreviousButtonInGroup(lastBtn);
3d3afaec
JS
542 if ( !child )
543 {
544 // no previous button in group, set it to the last button
506f9e92 545 child = wxGetLastButtonInGroup(lastBtn);
3d3afaec
JS
546 }
547 }
548
549 if ( child == m_winLastFocused )
550 {
551 // must be a group consisting of only one button therefore
552 // no need to send a navigation event
553 event.Skip(false);
554 return;
7ff1b620
VZ
555 }
556 }
3d3afaec 557#endif // __WXMSW__
c932709d 558
21bf81db 559 if ( child->CanAcceptFocusFromKeyboard() )
456bc6d9
VZ
560 {
561 // if we're setting the focus to a child panel we should prevent it
562 // from giving it to the child which had the focus the last time
563 // and instead give it to the first/last child depending from which
564 // direction we're coming
565 event.SetEventObject(m_winParent);
944e8709 566
aef35d0e
VZ
567 // disable propagation for this call as otherwise the event might
568 // bounce back to us.
569 wxPropagationDisabler disableProp(event);
456bc6d9
VZ
570 if ( !child->GetEventHandler()->ProcessEvent(event) )
571 {
2b5f62a0
VZ
572 // set it first in case SetFocusFromKbd() results in focus
573 // change too
574 m_winLastFocused = child;
575
456bc6d9 576 // everything is simple: just give focus to it
5463c0a4 577 child->SetFocusFromKbd();
456bc6d9
VZ
578 }
579 //else: the child manages its focus itself
580
c9d59ee7 581 event.Skip( false );
456bc6d9
VZ
582
583 return;
584 }
585
586 node = forward ? node->GetNext() : node->GetPrevious();
587 }
588
589 // we cycled through all of our children and none of them wanted to accept
590 // focus
591 event.Skip();
592}
593
594void wxControlContainer::HandleOnWindowDestroy(wxWindowBase *child)
595{
596 if ( child == m_winLastFocused )
597 m_winLastFocused = NULL;
456bc6d9
VZ
598}
599
600// ----------------------------------------------------------------------------
601// focus handling
602// ----------------------------------------------------------------------------
603
456bc6d9
VZ
604void wxControlContainer::HandleOnFocus(wxFocusEvent& event)
605{
9a83f860 606 wxLogTrace(TRACE_FOCUS, wxT("OnFocus on wxPanel 0x%p, name: %s"),
9f542367 607 m_winParent->GetHandle(),
456bc6d9
VZ
608 m_winParent->GetName().c_str() );
609
2b5f62a0 610 DoSetFocus();
456bc6d9
VZ
611
612 event.Skip();
613}
614
c7bfb76a
JS
615
616#else
617 // wxHAS_NATIVE_TAB_TRAVERSAL
618
456bc6d9
VZ
619bool wxControlContainer::SetFocusToChild()
620{
c7bfb76a 621 return wxSetFocusToChild(m_winParent, NULL);
456bc6d9
VZ
622}
623
c7bfb76a
JS
624
625#endif // !wxHAS_NATIVE_TAB_TRAVERSAL
626
456bc6d9
VZ
627// ----------------------------------------------------------------------------
628// SetFocusToChild(): this function is used by wxPanel but also by wxFrame in
629// wxMSW, this is why it is outside of wxControlContainer class
630// ----------------------------------------------------------------------------
631
632bool wxSetFocusToChild(wxWindow *win, wxWindow **childLastFocused)
633{
9a83f860 634 wxCHECK_MSG( win, false, wxT("wxSetFocusToChild(): invalid window") );
c7bfb76a 635 // wxCHECK_MSG( childLastFocused, false,
9a83f860 636 // wxT("wxSetFocusToChild(): NULL child poonter") );
456bc6d9 637
c7bfb76a 638 if ( childLastFocused && *childLastFocused )
456bc6d9 639 {
c25b5d1f
VZ
640 // It might happen that the window got reparented
641 if ( (*childLastFocused)->GetParent() == win )
456bc6d9 642 {
6ca243fc
VZ
643 // And it also could have become hidden in the meanwhile
644 // We want to focus on the deepest widget visible
645 wxWindow *deepestVisibleWindow = NULL;
646
647 while ( *childLastFocused )
26647ae4 648 {
6ca243fc
VZ
649 if ( (*childLastFocused)->IsShown() )
650 {
651 if ( !deepestVisibleWindow )
652 deepestVisibleWindow = *childLastFocused;
653 }
654 else
655 deepestVisibleWindow = NULL;
656
26647ae4 657 *childLastFocused = (*childLastFocused)->GetParent();
26647ae4 658 }
456bc6d9 659
6ca243fc 660 if ( deepestVisibleWindow )
26647ae4 661 {
6ca243fc
VZ
662 *childLastFocused = deepestVisibleWindow;
663
26647ae4
VZ
664 wxLogTrace(TRACE_FOCUS,
665 wxT("SetFocusToChild() => last child (0x%p)."),
666 (*childLastFocused)->GetHandle());
667
668 // not SetFocusFromKbd(): we're restoring focus back to the old
669 // window and not setting it as the result of a kbd action
670 (*childLastFocused)->SetFocus();
671 return true;
672 }
456bc6d9
VZ
673 }
674 else
675 {
676 // it doesn't count as such any more
d3b9f782 677 *childLastFocused = NULL;
456bc6d9
VZ
678 }
679 }
680
681 // set the focus to the first child who wants it
222ed1d6 682 wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
456bc6d9
VZ
683 while ( node )
684 {
685 wxWindow *child = node->GetData();
afd7bf26 686 node = node->GetNext();
456bc6d9 687
049908c5
VS
688 // skip special windows:
689 if ( !win->IsClientAreaChild(child) )
afd7bf26 690 continue;
049908c5 691
de160b06 692 if ( child->CanAcceptFocusFromKeyboard() && !child->IsTopLevel() )
456bc6d9 693 {
a8ff046b 694#if defined(__WXMSW__) && wxUSE_RADIOBTN
b49f58fe 695 // If a radiobutton is the first focusable child, search for the
7ff1b620
VZ
696 // selected radiobutton in the same group
697 wxRadioButton* btn = wxDynamicCast(child, wxRadioButton);
698 if (btn)
699 {
700 wxRadioButton* selected = wxGetSelectedButtonInGroup(btn);
701 if (selected)
702 child = selected;
703 }
a8ff046b 704#endif // __WXMSW__
7ff1b620 705
9f542367 706 wxLogTrace(TRACE_FOCUS,
9a83f860 707 wxT("SetFocusToChild() => first child (0x%p)."),
9f542367 708 child->GetHandle());
456bc6d9 709
c7bfb76a
JS
710 if (childLastFocused)
711 *childLastFocused = child;
5463c0a4 712 child->SetFocusFromKbd();
c9d59ee7 713 return true;
456bc6d9 714 }
456bc6d9
VZ
715 }
716
c9d59ee7 717 return false;
456bc6d9 718}
de160b06 719