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.
12 \file GUIListContainer.h
16 #include "GUIAction.h"
17 #include "IGUIContainer.h"
18 #include "utils/Stopwatch.h"
33 class CGUIListItemLayout
;
35 class CGUIBaseContainer
: public IGUIContainer
38 CGUIBaseContainer(int parentID
, int controlID
, float posX
, float posY
, float width
, float height
, ORIENTATION orientation
, const CScroller
& scroller
, int preloadItems
);
39 explicit CGUIBaseContainer(const CGUIBaseContainer
& other
);
40 ~CGUIBaseContainer(void) override
;
42 bool OnAction(const CAction
&action
) override
;
43 void OnDown() override
;
45 void OnLeft() override
;
46 void OnRight() override
;
47 bool OnMouseOver(const CPoint
&point
) override
;
48 bool CanFocus() const override
;
49 bool OnMessage(CGUIMessage
& message
) override
;
50 void SetFocus(bool bOnOff
) override
;
51 void AllocResources() override
;
52 void FreeResources(bool immediately
= false) override
;
53 void UpdateVisibility(const CGUIListItem
*item
= NULL
) override
;
54 void AssignDepth() override
;
56 virtual unsigned int GetRows() const;
58 virtual bool HasNextPage() const;
59 virtual bool HasPreviousPage() const;
61 void SetPageControl(int id
);
63 std::string
GetDescription() const override
;
64 void SaveStates(std::vector
<CControlState
> &states
) override
;
65 virtual int GetSelectedItem() const;
67 void DoProcess(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
) override
;
68 void Process(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
) override
;
70 void LoadLayout(TiXmlElement
*layout
);
71 void LoadListProvider(TiXmlElement
*content
, int defaultItem
, bool defaultAlways
);
73 std::shared_ptr
<CGUIListItem
> GetListItem(int offset
, unsigned int flag
= 0) const override
;
75 bool GetCondition(int condition
, int data
) const override
;
76 std::string
GetLabel(int info
) const override
;
78 /*! \brief Set the list provider for this container (for python).
79 \param provider the list provider to use for this container.
81 void SetListProvider(std::unique_ptr
<IListProvider
> provider
);
83 /*! \brief Set the offset of the first item in the container from the container's position
84 Useful for lists/panels where the focused item may be larger than the non-focused items and thus
85 normally cut off from the clipping window defined by the container's position + size.
86 \param offset CPoint holding the offset in skin coordinates.
88 void SetRenderOffset(const CPoint
&offset
);
90 void SetClickActions(const CGUIAction
& clickActions
) { m_clickActions
= clickActions
; }
91 void SetFocusActions(const CGUIAction
& focusActions
) { m_focusActions
= focusActions
; }
92 void SetUnFocusActions(const CGUIAction
& unfocusActions
) { m_unfocusActions
= unfocusActions
; }
94 void SetAutoScrolling(const TiXmlNode
*node
);
95 void ResetAutoScrolling();
96 void UpdateAutoScrolling(unsigned int currentTime
);
99 void DumpTextureUse() override
;
102 EVENT_RESULT
OnMouseEvent(const CPoint
& point
, const KODI::MOUSE::CMouseEvent
& event
) override
;
103 bool OnClick(int actionID
);
105 virtual void ProcessItem(float posX
,
107 std::shared_ptr
<CGUIListItem
>& item
,
109 unsigned int currentTime
,
110 CDirtyRegionList
& dirtyregions
);
112 void Render() override
;
113 virtual void RenderItem(float posX
, float posY
, CGUIListItem
*item
, bool focused
);
114 virtual void Scroll(int amount
);
115 virtual bool MoveDown(bool wrapAround
);
116 virtual bool MoveUp(bool wrapAround
);
117 virtual bool GetOffsetRange(int &minOffset
, int &maxOffset
) const;
118 virtual void ValidateOffset();
119 virtual int CorrectOffset(int offset
, int cursor
) const;
120 virtual void UpdateLayout(bool refreshAllItems
= false);
121 virtual void SetPageControlRange();
122 virtual void UpdatePageControl(int offset
);
123 virtual void CalculateLayout();
124 virtual void SelectItem(int item
) {}
125 virtual bool SelectItemFromPoint(const CPoint
& point
) { return false; }
126 virtual int GetCursorFromPoint(const CPoint
& point
, CPoint
* itemPoint
= NULL
) const { return -1; }
127 virtual void Reset();
128 virtual size_t GetNumItems() const { return m_items
.size(); }
129 virtual int GetCurrentPage() const;
130 bool InsideLayout(const CGUIListItemLayout
*layout
, const CPoint
&point
) const;
131 void OnFocus() override
;
132 void OnUnFocus() override
;
133 void UpdateListProvider(bool forceRefresh
= false);
135 int ScrollCorrectionRange() const;
136 inline float Size() const;
137 void FreeMemory(int keepStart
, int keepEnd
);
138 void GetCurrentLayouts();
139 CGUIListItemLayout
*GetFocusedLayout() const;
141 CPoint m_renderOffset
; ///< \brief render offset of the first item in the list \sa SetRenderOffset
143 float m_analogScrollCount
;
144 unsigned int m_lastHoldTime
;
146 ORIENTATION m_orientation
;
149 std::vector
<std::shared_ptr
<CGUIListItem
>> m_items
;
150 typedef std::vector
<std::shared_ptr
<CGUIListItem
>>::iterator iItems
;
151 std::shared_ptr
<CGUIListItem
> m_lastItem
;
155 std::list
<CGUIListItemLayout
> m_layouts
;
156 std::list
<CGUIListItemLayout
> m_focusedLayouts
;
158 CGUIListItemLayout
* m_layout
{nullptr};
159 CGUIListItemLayout
* m_focusedLayout
{nullptr};
160 bool m_layoutCondition
= false;
161 bool m_focusedLayoutCondition
= false;
163 virtual void ScrollToOffset(int offset
);
164 void SetContainerMoving(int direction
);
165 void UpdateScrollOffset(unsigned int currentTime
);
167 CScroller m_scroller
;
169 std::unique_ptr
<IListProvider
> m_listProvider
;
171 bool m_wasReset
; // true if we've received a Reset message until we've rendered once. Allows
172 // us to make sure we don't tell the infomanager that we've been moving when
173 // the "movement" was simply due to the list being repopulated (thus cursor position
176 void UpdateScrollByLetter();
177 void GetCacheOffsets(int &cacheBefore
, int &cacheAfter
) const;
178 int GetCacheCount() const { return m_cacheItems
; }
179 bool ScrollingDown() const { return m_scroller
.IsScrollingDown(); }
180 bool ScrollingUp() const { return m_scroller
.IsScrollingUp(); }
183 void OnJumpLetter(const std::string
& letter
, bool skip
= false);
184 void OnJumpSMS(int letter
);
185 std::vector
< std::pair
<int, std::string
> > m_letterOffsets
;
187 /*! \brief Set the cursor position
188 Should be used by all base classes rather than directly setting it, as
189 this also marks the control as dirty (if needed)
191 virtual void SetCursor(int cursor
);
192 inline int GetCursor() const { return m_cursor
; }
194 /*! \brief Set the container offset
195 Should be used by all base classes rather than directly setting it, as
196 this also marks the control as dirty (if needed)
198 void SetOffset(int offset
);
199 /*! \brief Returns the index of the first visible row
200 returns the first row. This may be outside of the range of available items. Use GetItemOffset() to retrieve the first visible item in the list.
203 inline int GetOffset() const { return m_offset
; }
204 /*! \brief Returns the index of the first visible item
205 returns the first visible item. This will always be in the range of available items. Use GetOffset() to retrieve the first visible row in the list.
208 inline int GetItemOffset() const { return CorrectOffset(GetOffset(), 0); }
211 INFO::InfoPtr m_autoScrollCondition
;
212 int m_autoScrollMoveTime
; // time between to moves
213 unsigned int m_autoScrollDelayTime
; // current offset into the delay
214 bool m_autoScrollIsReversed
; // scroll backwards
216 unsigned int m_lastRenderTime
;
222 std::shared_ptr
<CGUIListItem
> item
;
227 bool OnContextMenu();
232 CStopWatch m_scrollTimer
;
233 CStopWatch m_lastScrollStartTimer
;
234 CStopWatch m_pageChangeTimer
;
236 CGUIAction m_clickActions
;
237 CGUIAction m_focusActions
;
238 CGUIAction m_unfocusActions
;
240 // letter match searching
241 CStopWatch m_matchTimer
;
243 float m_scrollItemsPerFrame
;
244 static const int letter_match_timeout
= 1000;
246 bool m_gestureActive
= false;
248 // early inertial scroll cancellation
249 bool m_waitForScrollEnd
= false;
250 float m_lastScrollValue
= 0.0f
;