xbmc
GUIWindow.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
16 #include "GUIAction.h"
17 #include "GUIControlGroup.h"
18 #include <memory>
19 #include "threads/CriticalSection.h"
20 
21 class CFileItem; typedef std::shared_ptr<CFileItem> CFileItemPtr;
22 
23 #include <limits.h>
24 #include <map>
25 #include <vector>
26 
27 enum RenderOrder {
28  RENDER_ORDER_WINDOW = 0,
29  RENDER_ORDER_DIALOG = 1,
30  RENDER_ORDER_WINDOW_SCREENSAVER = INT_MAX,
31  RENDER_ORDER_WINDOW_POINTER = INT_MAX - 1,
32  RENDER_ORDER_WINDOW_DEBUG = INT_MAX - 2,
33  RENDER_ORDER_DIALOG_TELETEXT = INT_MAX - 3
34 };
35 
36 // forward
37 class TiXmlNode;
38 class TiXmlElement;
39 class CXBMCTinyXML;
40 class CVariant;
41 
42 class COrigin
43 {
44 public:
45  COrigin()
46  {
47  x = y = 0;
48  };
49  float x;
50  float y;
51  INFO::InfoPtr condition;
52 };
53 
58 class CGUIWindow : public CGUIControlGroup, protected CCriticalSection
59 {
60 public:
61  enum LOAD_TYPE { LOAD_EVERY_TIME, LOAD_ON_GUI_INIT, KEEP_IN_MEMORY };
62 
63  CGUIWindow(int id, const std::string &xmlFile);
64  ~CGUIWindow(void) override;
65 
66  bool Initialize(); // loads the window
67  bool Load(const std::string& strFileName, bool bContainsPath = false);
68 
69  void CenterWindow();
70 
71  void DoProcess(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;
72 
79  void DoRender() override;
80 
84  void AfterRender();
85 
90  virtual void FrameMove() {}
91 
92  void Close(bool forceClose = false, int nextWindowID = 0, bool enableSound = true, bool bWait = true);
93 
94  // OnAction() is called by our window manager. We should process any messages
95  // that should be handled at the window level in the derived classes, and any
96  // unhandled messages should be dropped through to here where we send the message
97  // on to the currently focused control. Returns true if the action has been handled
98  // and does not need to be passed further down the line (to our global action handlers)
99  bool OnAction(const CAction &action) override;
100 
101  using CGUIControlGroup::OnBack;
102  virtual bool OnBack(int actionID);
103  using CGUIControlGroup::OnInfo;
104  virtual bool OnInfo(int actionID) { return false; }
105 
108  virtual void ClearBackground();
109 
110  bool OnMove(int fromControl, int moveAction);
111  bool OnMessage(CGUIMessage& message) override;
112 
113  bool ControlGroupHasFocus(int groupID, int controlID);
114  void SetID(int id) override;
115  virtual bool HasID(int controlID) const;
116  const std::vector<int>& GetIDRange() const { return m_idRange; }
117  int GetPreviousWindow() { return m_previousWindow; }
118  CRect GetScaledBounds() const;
119  void ClearAll() override;
120  using CGUIControlGroup::AllocResources;
121  virtual void AllocResources(bool forceLoad = false);
122  void FreeResources(bool forceUnLoad = false) override;
123  void DynamicResourceAlloc(bool bOnOff) override;
124  virtual bool IsDialog() const { return false; }
125  virtual bool IsDialogRunning() const { return false; }
126  virtual bool IsModalDialog() const { return false; }
127  virtual bool IsMediaWindow() const { return false; }
128  virtual bool HasListItems() const { return false; }
129  virtual bool IsSoundEnabled() const { return true; }
130  virtual CFileItemPtr GetCurrentListItem(int offset = 0) { return CFileItemPtr(); }
131  virtual int GetViewContainerID() const { return 0; }
132  virtual int GetViewCount() const { return 0; }
133  virtual bool CanBeActivated() const { return true; }
134  virtual bool IsActive() const;
135  void SetCoordsRes(const RESOLUTION_INFO& res) { m_coordsRes = res; }
136  const RESOLUTION_INFO& GetCoordsRes() const { return m_coordsRes; }
137  void SetLoadType(LOAD_TYPE loadType) { m_loadType = loadType; }
138  LOAD_TYPE GetLoadType() { return m_loadType; }
139  int GetRenderOrder() { return m_renderOrder; }
140  void SetInitialVisibility() override;
141  bool IsVisible() const override { return true; }; // windows are always considered visible as they implement their own
142  // versions of UpdateVisibility, and are deemed visible if they're in
143  // the window manager's active list.
144  virtual bool HasVisibleControls() { return true; }; //Assume that window always has visible controls
145 
146  bool IsAnimating(ANIMATION_TYPE animType) override;
147 
152  bool IsCustom() const { return m_custom; }
153 
158  void SetCustom(bool custom) { m_custom = custom; }
159 
160  void DisableAnimations();
161 
162  virtual void ResetControlStates();
163  void UpdateControlStats() override {}; // Do not count window itself
164 
165  void SetRunActionsManually();
166  void RunLoadActions() const;
167  void RunUnloadActions() const;
168 
175  void SetProperty(const std::string &key, const CVariant &value);
176 
181  CVariant GetProperty(const std::string &key) const;
182 
186  void ClearProperties();
187 
188 #ifdef _DEBUG
189  void DumpTextureUse() override;
190 #endif
191  bool HasSaveLastControl() const { return !m_defaultAlways; }
192 
193  virtual void OnDeinitWindow(int nextWindowID);
194 protected:
195  EVENT_RESULT OnMouseEvent(const CPoint &point, const CMouseEvent &event) override;
196 
202  virtual bool LoadXML(const std::string& strPath, const std::string &strLowerPath);
203 
209  virtual bool Load(TiXmlElement *pRootElement);
210 
216  virtual std::unique_ptr<TiXmlElement> Prepare(const std::unique_ptr<TiXmlElement>& rootElement);
217 
221  bool NeedLoad() const;
222 
223  virtual void SetDefaults();
224  virtual void OnWindowUnload() {}
225  virtual void OnWindowLoaded();
226  virtual void OnInitWindow();
227  void Close_Internal(bool forceClose = false, int nextWindowID = 0, bool enableSound = true);
228  EVENT_RESULT OnMouseAction(const CAction &action);
229  bool Animate(unsigned int currentTime) override;
230  bool CheckAnimation(ANIMATION_TYPE animType) override;
231 
232  // control state saving on window close
233  virtual void SaveControlStates();
234  virtual void RestoreControlStates();
235 
236  // methods for updating controls and sending messages
237  void OnEditChanged(int id, std::string &text);
238  bool SendMessage(int message, int id, int param1 = 0, int param2 = 0);
239 
240  void LoadControl(TiXmlElement* pControl, CGUIControlGroup *pGroup, const CRect &rect);
241 
242  std::vector<int> m_idRange;
243  RESOLUTION_INFO m_coordsRes; // resolution that the window coordinates are in.
244  bool m_needsScaling;
245  bool m_windowLoaded; // true if the window's xml file has been loaded
246  LOAD_TYPE m_loadType;
247  bool m_dynamicResourceAlloc;
248  bool m_closing;
249  bool m_active; // true if window is active or dialog is running
250  KODI::GUILIB::GUIINFO::CGUIInfoColor m_clearBackground; // colour to clear the window
251 
252  int m_renderOrder; // for render order of dialogs
253 
259  CPoint GetPosition() const override;
260  std::vector<COrigin> m_origins; // positions of dialogs depending on base window
261 
262  // control states
263  int m_lastControlID;
264  std::vector<CControlState> m_controlStates;
265  int m_previousWindow;
266 
267  bool m_animationsEnabled;
268  struct icompare
269  {
270  bool operator()(const std::string &s1, const std::string &s2) const;
271  };
272 
273  CGUIAction m_loadActions;
274  CGUIAction m_unloadActions;
275 
279  std::unique_ptr<TiXmlElement> m_windowXMLRootElement;
280 
281  bool m_manualRunActions;
282 
284 
285  int m_menuControlID;
286  int m_menuLastFocusedControlID;
287  bool m_custom;
288 
289 private:
290  std::map<std::string, CVariant, icompare> m_mapProperties;
291  std::map<INFO::InfoPtr, bool> m_xmlIncludeConditions;
292 };
293 
void SetCustom(bool custom)
Mark this window as custom window.
Definition: GUIWindow.h:158
std::shared_ptr< CFileItem > CFileItemPtr
A shared pointer to CFileItem.
Definition: FileItem.h:680
int m_exclusiveMouseControl
id of child control that wishes to receive all mouse events
Definition: GUIWindow.h:283
Definition: XBMCTinyXML.h:33
std::unique_ptr< TiXmlElement > m_windowXMLRootElement
window root xml definition after resolving any skin includes. Stored to avoid parsing the XML every t...
Definition: GUIWindow.h:279
virtual void FrameMove()
Main update function, called every frame prior to rendering Any window that requires updating on a fr...
Definition: GUIWindow.h:90
EVENT_RESULT
Results of OnMouseEvent() Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was ...
Definition: GUIControl.h:60
Definition: Variant.h:29
bool IsCustom() const
Return if the window is a custom window.
Definition: GUIWindow.h:152
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Provide info of a resolution.
Definition: Resolution.h:66
Definition: GUIMessage.h:365
Definition: GUIWindow.h:58
Definition: GUIWindow.h:42
group of controls, useful for remembering last control + animating/hiding together ...
Definition: GUIControlGroup.h:24
Definition: GUIInfoColor.h:30
Definition: GUIWindow.h:268
Represents a file on a share.
Definition: FileItem.h:102
Simple class for mouse events.
Definition: Key.h:114
Class containing vector of condition->(action/navigation route) and handling its execution.
Definition: GUIAction.h:21