2 \file GUIListContainer.h
9 * Copyright (C) 2005-2013 Team XBMC
12 * This Program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This Program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with XBMC; see the file COPYING. If not, see
24 * <http://www.gnu.org/licenses/>.
28 #include "IGUIContainer.h"
29 #include "GUIListItemLayout.h"
30 #include "utils/Stopwatch.h"
39 class CGUIBaseContainer : public IGUIContainer
42 CGUIBaseContainer(int parentID, int controlID, float posX, float posY, float width, float height, ORIENTATION orientation, const CScroller& scroller, int preloadItems);
43 virtual ~CGUIBaseContainer(void);
45 virtual bool OnAction(const CAction &action);
46 virtual void OnDown();
48 virtual void OnLeft();
49 virtual void OnRight();
50 virtual bool OnMouseOver(const CPoint &point);
51 virtual bool CanFocus() const;
52 virtual bool OnMessage(CGUIMessage& message);
53 virtual void SetFocus(bool bOnOff);
54 virtual void AllocResources();
55 virtual void FreeResources(bool immediately = false);
56 virtual void UpdateVisibility(const CGUIListItem *item = NULL);
58 virtual unsigned int GetRows() const;
60 virtual bool HasNextPage() const;
61 virtual bool HasPreviousPage() const;
63 void SetPageControl(int id);
65 virtual CStdString GetDescription() const;
66 virtual void SaveStates(std::vector<CControlState> &states);
67 virtual int GetSelectedItem() const;
69 virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions);
70 virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
72 void LoadLayout(TiXmlElement *layout);
73 void LoadListProvider(TiXmlElement *content, int defaultItem, bool defaultAlways);
75 virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
77 virtual bool GetCondition(int condition, int data) const;
78 virtual CStdString GetLabel(int info) const;
80 /*! \brief Set the list provider for this container (for python).
81 \param provider the list provider to use for this container.
83 void SetListProvider(IListProvider *provider);
85 /*! \brief Set the offset of the first item in the container from the container's position
86 Useful for lists/panels where the focused item may be larger than the non-focused items and thus
87 normally cut off from the clipping window defined by the container's position + size.
88 \param offset CPoint holding the offset in skin coordinates.
90 void SetRenderOffset(const CPoint &offset);
92 void SetAutoScrolling(const TiXmlNode *node);
93 void ResetAutoScrolling();
94 void UpdateAutoScrolling(unsigned int currentTime);
97 virtual void DumpTextureUse();
100 virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event);
101 bool OnClick(int actionID);
103 virtual void ProcessItem(float posX, float posY, CGUIListItemPtr& item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions);
105 virtual void Render();
106 virtual void RenderItem(float posX, float posY, CGUIListItem *item, bool focused);
107 virtual void Scroll(int amount);
108 virtual bool MoveDown(bool wrapAround);
109 virtual bool MoveUp(bool wrapAround);
110 virtual bool GetOffsetRange(int &minOffset, int &maxOffset) const;
111 virtual void ValidateOffset();
112 virtual int CorrectOffset(int offset, int cursor) const;
113 virtual void UpdateLayout(bool refreshAllItems = false);
114 virtual void SetPageControlRange();
115 virtual void UpdatePageControl(int offset);
116 virtual void CalculateLayout();
117 virtual void SelectItem(int item) {};
118 virtual bool SelectItemFromPoint(const CPoint &point) { return false; };
119 virtual int GetCursorFromPoint(const CPoint &point, CPoint *itemPoint = NULL) const { return -1; };
120 virtual void Reset();
121 virtual unsigned int GetNumItems() const { return m_items.size(); };
122 virtual int GetCurrentPage() const;
123 bool InsideLayout(const CGUIListItemLayout *layout, const CPoint &point) const;
124 virtual void OnFocus();
125 void UpdateListProvider(bool refreshItems = false);
127 int ScrollCorrectionRange() const;
128 inline float Size() const;
129 void MoveToRow(int row);
130 void FreeMemory(int keepStart, int keepEnd);
131 void GetCurrentLayouts();
132 CGUIListItemLayout *GetFocusedLayout() const;
134 CPoint m_renderOffset; ///< \brief render offset of the first item in the list \sa SetRenderOffset
136 float m_analogScrollCount;
137 unsigned int m_lastHoldTime;
139 ORIENTATION m_orientation;
142 std::vector< CGUIListItemPtr > m_items;
143 typedef std::vector<CGUIListItemPtr> ::iterator iItems;
144 CGUIListItemPtr m_lastItem;
148 std::vector<CGUIListItemLayout> m_layouts;
149 std::vector<CGUIListItemLayout> m_focusedLayouts;
151 CGUIListItemLayout *m_layout;
152 CGUIListItemLayout *m_focusedLayout;
154 void ScrollToOffset(int offset);
155 void SetContainerMoving(int direction);
156 void UpdateScrollOffset(unsigned int currentTime);
158 CScroller m_scroller;
160 IListProvider *m_listProvider;
162 bool m_wasReset; // true if we've received a Reset message until we've rendered once. Allows
163 // us to make sure we don't tell the infomanager that we've been moving when
164 // the "movement" was simply due to the list being repopulated (thus cursor position
167 void UpdateScrollByLetter();
168 void GetCacheOffsets(int &cacheBefore, int &cacheAfter) const;
169 int GetCacheCount() const { return m_cacheItems; };
170 bool ScrollingDown() const { return m_scroller.IsScrollingDown(); };
171 bool ScrollingUp() const { return m_scroller.IsScrollingUp(); };
174 void OnJumpLetter(char letter, bool skip = false);
175 void OnJumpSMS(int letter);
176 std::vector< std::pair<int, CStdString> > m_letterOffsets;
178 /*! \brief Set the cursor position
179 Should be used by all base classes rather than directly setting it, as
180 this also marks the control as dirty (if needed)
182 virtual void SetCursor(int cursor);
183 inline int GetCursor() const { return m_cursor; };
185 /*! \brief Set the container offset
186 Should be used by all base classes rather than directly setting it, as
187 this also marks the control as dirty (if needed)
189 void SetOffset(int offset);
190 /*! \brief Returns the index of the first visible row
191 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.
194 inline int GetOffset() const { return m_offset; };
195 /*! \brief Returns the index of the first visible item
196 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.
199 inline int GetItemOffset() const { return CorrectOffset(GetOffset(), 0); }
202 INFO::InfoPtr m_autoScrollCondition;
203 int m_autoScrollMoveTime; // time between to moves
204 unsigned int m_autoScrollDelayTime; // current offset into the delay
205 bool m_autoScrollIsReversed; // scroll backwards
207 unsigned int m_lastRenderTime;
213 CStopWatch m_scrollTimer;
214 CStopWatch m_lastScrollStartTimer;
215 CStopWatch m_pageChangeTimer;
217 // letter match searching
218 CStopWatch m_matchTimer;
220 float m_scrollItemsPerFrame;
222 static const int letter_match_timeout = 1000;