Permalink
Browse files

Merge pull request #1179 from pieh/no_longer_focusable

  • Loading branch information...
2 parents 2774f6b + f472ae7 commit 1b0360eba2b93da7ccc28baa99617e7915fef52a @pieh pieh committed Jul 29, 2012
Showing with 28 additions and 7 deletions.
  1. +22 −7 xbmc/guilib/GUIControlGroup.cpp
  2. +6 −0 xbmc/guilib/GUIWindow.cpp
@@ -464,18 +464,33 @@ int CGUIControlGroup::GetFocusedControlID() const
CGUIControl *CGUIControlGroup::GetFocusedControl() const
{
+ // try lookup first
+ if (m_focusedControl)
+ {
+ // we may have multiple controls with same id - we pick first that has focus
+ pair<LookupMap::const_iterator, LookupMap::const_iterator> range = m_lookup.equal_range(m_focusedControl);
+ for (LookupMap::const_iterator i = range.first; i != range.second; ++i)
+ {
+ if (i->second->HasFocus())
+ return i->second;
+ }
+ }
+
+ // if lookup didn't find focused control, iterate m_children to find it
for (ciControls it = m_children.begin(); it != m_children.end(); ++it)
{
const CGUIControl* control = *it;
- if (control->HasFocus())
+ // Avoid calling HasFocus() on control group as it will (possibly) recursively
+ // traverse entire group tree just to check if there is focused control.
+ // We are recursively traversing it here so no point in doing it twice.
+ if (control->IsGroup())
{
- if (control->IsGroup())
- {
- CGUIControlGroup *group = (CGUIControlGroup *)control;
- return group->GetFocusedControl();
- }
- return (CGUIControl *)control;
+ CGUIControl* focusedControl = ((CGUIControlGroup *)control)->GetFocusedControl();
+ if (focusedControl)
+ return (CGUIControl *)focusedControl;
}
+ else if (control->HasFocus())
+ return (CGUIControl *)control;
}
return NULL;
}
@@ -302,6 +302,12 @@ void CGUIWindow::DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregi
CGUIControlGroup::DoProcess(currentTime, dirtyregions);
if (size != g_graphicsContext.RemoveTransform())
CLog::Log(LOGERROR, "Unbalanced UI transforms (was %d)", size);
+
+ // check if currently focused control can have it
+ // and fallback to default control if not
+ CGUIControl* focusedControl = GetFocusedControl();
+ if (focusedControl && !focusedControl->CanFocus())
@arnova

arnova Jul 30, 2012

Member

Wouldn't: (!focusControl || !focusedControl->CanFocus())

be possibly better?

@jmarshallnz

jmarshallnz Jul 30, 2012

Member

It's perfectly OK for nothing to have focus (mouse/touch for example).

@arnova

arnova Jul 30, 2012

Member

Ah yes, didn't think of that as I'm always using keyboard/remote ;-)

+ SET_CONTROL_FOCUS(m_defaultControl, 0);
}
void CGUIWindow::DoRender()

5 comments on commit 1b0360e

Member

arnova replied Jul 30, 2012

Thanks for the fix for this ancient bugger ;-)

Member

arnova replied Jul 31, 2012

I doubt it's related.

Member

pieh replied Jul 31, 2012

could be, mover and resize control aren't reporting themselves as focusable - investigating and testing now

Member

pieh replied Aug 1, 2012

fixed in e4443f2

Please sign in to comment.