[WASAPI] fix stream types and frequencies enumeration
[xbmc.git] / xbmc / guilib / GUIListGroup.cpp
blob8883d944e518c1f5e79642791cb58fa8c0623829
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIListGroup.h"
11 #include "GUIListLabel.h"
12 #include "utils/log.h"
14 #include <set>
16 namespace
18 // Supported control types. Keep sorted.
19 const std::set<CGUIControl::GUICONTROLTYPES> supportedTypes = {
20 // clang-format off
21 CGUIControl::GUICONTROL_BORDEREDIMAGE,
22 CGUIControl::GUICONTROL_GAME,
23 CGUIControl::GUICONTROL_GAMECONTROLLER,
24 CGUIControl::GUICONTROL_GAMECONTROLLERLIST,
25 CGUIControl::GUICONTROL_IMAGE,
26 CGUIControl::GUICONTROL_LISTGROUP,
27 CGUIControl::GUICONTROL_LISTLABEL,
28 CGUIControl::GUICONTROL_MULTI_IMAGE,
29 CGUIControl::GUICONTROL_PROGRESS,
30 CGUIControl::GUICONTROL_TEXTBOX,
31 // clang-format on
33 } // namespace
35 CGUIListGroup::CGUIListGroup(int parentID, int controlID, float posX, float posY, float width, float height)
36 : CGUIControlGroup(parentID, controlID, posX, posY, width, height)
38 m_item = NULL;
39 ControlType = GUICONTROL_LISTGROUP;
42 CGUIListGroup::CGUIListGroup(const CGUIListGroup &right)
43 : CGUIControlGroup(right)
45 m_item = NULL;
46 ControlType = GUICONTROL_LISTGROUP;
49 CGUIListGroup::~CGUIListGroup(void)
51 FreeResources();
54 void CGUIListGroup::AddControl(CGUIControl *control, int position /*= -1*/)
56 if (control)
58 if (supportedTypes.find(control->GetControlType()) == supportedTypes.end())
59 CLog::Log(LOGWARNING, "Trying to add unsupported control type {}", control->GetControlType());
61 CGUIControlGroup::AddControl(control, position);
64 void CGUIListGroup::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
66 CServiceBroker::GetWinSystem()->GetGfxContext().SetOrigin(m_posX, m_posY);
68 CRect rect;
69 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
71 CGUIControl *control = *it;
72 control->UpdateVisibility(m_item);
73 unsigned int oldDirty = dirtyregions.size();
74 control->DoProcess(currentTime, dirtyregions);
75 if (control->IsVisible() || (oldDirty != dirtyregions.size())) // visible or dirty (was visible?)
76 rect.Union(control->GetRenderRegion());
79 CServiceBroker::GetWinSystem()->GetGfxContext().RestoreOrigin();
80 CGUIControl::Process(currentTime, dirtyregions);
81 m_renderRegion = rect;
82 m_item = NULL;
85 void CGUIListGroup::ResetAnimation(ANIMATION_TYPE type)
87 CGUIControl::ResetAnimation(type);
88 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
89 (*it)->ResetAnimation(type);
92 void CGUIListGroup::UpdateVisibility(const CGUIListItem *item)
94 CGUIControlGroup::UpdateVisibility(item);
95 m_item = item;
98 void CGUIListGroup::UpdateInfo(const CGUIListItem *item)
100 for (iControls it = m_children.begin(); it != m_children.end(); it++)
102 (*it)->UpdateInfo(item);
103 (*it)->UpdateVisibility(item);
105 // now we have to check our overlapping label pairs
106 for (unsigned int i = 0; i < m_children.size(); i++)
108 if (m_children[i]->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL && m_children[i]->IsVisible())
110 for (unsigned int j = i + 1; j < m_children.size(); j++)
112 if (m_children[j]->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL && m_children[j]->IsVisible())
113 CGUIListLabel::CheckAndCorrectOverlap(*static_cast<CGUIListLabel*>(m_children[i]), *static_cast<CGUIListLabel*>(m_children[j]));
119 void CGUIListGroup::EnlargeWidth(float difference)
121 // Alters the width of the controls that have an ID of 1 to 14
122 for (iControls it = m_children.begin(); it != m_children.end(); it++)
124 CGUIControl *child = *it;
125 if (child->GetID() >= 1 && child->GetID() <= 14)
127 if (child->GetID() == 1)
129 child->SetWidth(child->GetWidth() + difference);
130 child->SetVisible(child->GetWidth() > 10);
132 else
134 child->SetWidth(child->GetWidth() + difference);
138 SetInvalid();
141 void CGUIListGroup::EnlargeHeight(float difference)
143 // Alters the height of the controls that have an ID of 1 to 14
144 for (iControls it = m_children.begin(); it != m_children.end(); it++)
146 CGUIControl *child = *it;
147 if (child->GetID() >= 1 && child->GetID() <= 14)
149 if (child->GetID() == 1)
151 child->SetHeight(child->GetHeight() + difference);
152 child->SetVisible(child->GetHeight() > 10);
154 else
156 child->SetHeight(child->GetHeight() + difference);
160 SetInvalid();
163 void CGUIListGroup::SetInvalid()
165 if (!m_bInvalidated)
166 { // this can be triggered by an item change, so all children need invalidating rather than just the group
167 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
168 (*it)->SetInvalid();
169 CGUIControlGroup::SetInvalid();
173 void CGUIListGroup::SetFocusedItem(unsigned int focus)
175 for (iControls it = m_children.begin(); it != m_children.end(); it++)
177 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP)
178 ((CGUIListGroup *)(*it))->SetFocusedItem(focus);
179 else
180 (*it)->SetFocus(focus > 0);
182 SetFocus(focus > 0);
185 unsigned int CGUIListGroup::GetFocusedItem() const
187 for (ciControls it = m_children.begin(); it != m_children.end(); it++)
189 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP && ((CGUIListGroup *)(*it))->GetFocusedItem())
190 return ((CGUIListGroup *)(*it))->GetFocusedItem();
192 return m_bHasFocus ? 1 : 0;
195 bool CGUIListGroup::MoveLeft()
197 for (iControls it = m_children.begin(); it != m_children.end(); it++)
199 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP && ((CGUIListGroup *)(*it))->MoveLeft())
200 return true;
202 return false;
205 bool CGUIListGroup::MoveRight()
207 for (iControls it = m_children.begin(); it != m_children.end(); it++)
209 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP && ((CGUIListGroup *)(*it))->MoveRight())
210 return true;
212 return false;
215 void CGUIListGroup::SetState(bool selected, bool focused)
217 for (iControls it = m_children.begin(); it != m_children.end(); it++)
219 if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTLABEL)
221 CGUIListLabel *label = (CGUIListLabel *)(*it);
222 label->SetSelected(selected);
224 else if ((*it)->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP)
225 ((CGUIListGroup *)(*it))->SetState(selected, focused);
229 void CGUIListGroup::SelectItemFromPoint(const CPoint &point)
231 CPoint controlCoords(point);
232 m_transform.InverseTransformPosition(controlCoords.x, controlCoords.y);
233 for (iControls it = m_children.begin(); it != m_children.end(); ++it)
235 CGUIControl *child = *it;
236 if (child->GetControlType() == CGUIControl::GUICONTROL_LISTGROUP)
237 static_cast<CGUIListGroup*>(child)->SelectItemFromPoint(point);