[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / guilib / GUIBaseContainer.h
1 /*!
2 \file GUIListContainer.h
3 \brief
4 */
5
6 #pragma once
7
8 /*
9  *      Copyright (C) 2005-2013 Team XBMC
10  *      http://xbmc.org
11  *
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)
15  *  any later version.
16  *
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.
21  *
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/>.
25  *
26  */
27
28 #include "IGUIContainer.h"
29 #include "GUIListItemLayout.h"
30 #include "utils/Stopwatch.h"
31
32 /*!
33  \ingroup controls
34  \brief
35  */
36
37 class IListProvider;
38
39 class CGUIBaseContainer : public IGUIContainer
40 {
41 public:
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);
44
45   virtual bool OnAction(const CAction &action);
46   virtual void OnDown();
47   virtual void OnUp();
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);
57
58   virtual unsigned int GetRows() const;
59
60   virtual bool HasNextPage() const;
61   virtual bool HasPreviousPage() const;
62
63   void SetPageControl(int id);
64
65   virtual CStdString GetDescription() const;
66   virtual void SaveStates(std::vector<CControlState> &states);
67   virtual int GetSelectedItem() const;
68
69   virtual void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions);
70   virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);
71
72   void LoadLayout(TiXmlElement *layout);
73   void LoadListProvider(TiXmlElement *content, int defaultItem, bool defaultAlways);
74
75   virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
76
77   virtual bool GetCondition(int condition, int data) const;
78   virtual CStdString GetLabel(int info) const;
79
80   /*! \brief Set the list provider for this container (for python).
81    \param provider the list provider to use for this container.
82    */
83   void SetListProvider(IListProvider *provider);
84
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.
89    */
90   void SetRenderOffset(const CPoint &offset);
91
92   void SetAutoScrolling(const TiXmlNode *node);
93   void ResetAutoScrolling();
94   void UpdateAutoScrolling(unsigned int currentTime);
95
96 #ifdef _DEBUG
97   virtual void DumpTextureUse();
98 #endif
99 protected:
100   virtual EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event);
101   bool OnClick(int actionID);
102
103   virtual void ProcessItem(float posX, float posY, CGUIListItemPtr& item, bool focused, unsigned int currentTime, CDirtyRegionList &dirtyregions);
104
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);
126
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;
133
134   CPoint m_renderOffset; ///< \brief render offset of the first item in the list \sa SetRenderOffset
135     
136   float m_analogScrollCount;
137   unsigned int m_lastHoldTime;
138
139   ORIENTATION m_orientation;
140   int m_itemsPerPage;
141
142   std::vector< CGUIListItemPtr > m_items;
143   typedef std::vector<CGUIListItemPtr> ::iterator iItems;
144   CGUIListItemPtr m_lastItem;
145
146   int m_pageControl;
147
148   std::vector<CGUIListItemLayout> m_layouts;
149   std::vector<CGUIListItemLayout> m_focusedLayouts;
150
151   CGUIListItemLayout *m_layout;
152   CGUIListItemLayout *m_focusedLayout;
153
154   void ScrollToOffset(int offset);
155   void SetContainerMoving(int direction);
156   void UpdateScrollOffset(unsigned int currentTime);
157
158   CScroller m_scroller;
159
160   IListProvider *m_listProvider;
161
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
165                     // changing around)
166
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(); };
172   void OnNextLetter();
173   void OnPrevLetter();
174   void OnJumpLetter(char letter, bool skip = false);
175   void OnJumpSMS(int letter);
176   std::vector< std::pair<int, CStdString> > m_letterOffsets;
177
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)
181    */
182   virtual void SetCursor(int cursor);
183   inline int GetCursor() const { return m_cursor; };
184
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)
188    */
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.
192    \sa GetItemOffset
193   */
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.
197    \sa GetOffset
198   */
199   inline int GetItemOffset() const { return CorrectOffset(GetOffset(), 0); }
200
201   // autoscrolling
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
206
207   unsigned int m_lastRenderTime;
208
209 private:
210   int m_cursor;
211   int m_offset;
212   int m_cacheItems;
213   CStopWatch m_scrollTimer;
214   CStopWatch m_lastScrollStartTimer;
215   CStopWatch m_pageChangeTimer;
216
217   // letter match searching
218   CStopWatch m_matchTimer;
219   CStdString m_match;
220   float m_scrollItemsPerFrame;
221
222   static const int letter_match_timeout = 1000;
223 };
224
225