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.
16 #include "GUIAction.h"
17 #include "GUIControlGroup.h"
19 #include "threads/CriticalSection.h"
21 class CFileItem
; typedef std::shared_ptr
<CFileItem
> CFileItemPtr
;
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
51 INFO::InfoPtr condition
;
58 class CGUIWindow
: public CGUIControlGroup
, protected CCriticalSection
61 enum LOAD_TYPE
{ LOAD_EVERY_TIME
, LOAD_ON_GUI_INIT
, KEEP_IN_MEMORY
};
63 CGUIWindow(int id
, const std::string
&xmlFile
);
64 ~CGUIWindow(void) override
;
66 bool Initialize(); // loads the window
67 bool Load(const std::string
& strFileName
, bool bContainsPath
= false);
71 void DoProcess(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
) override
;
73 /*! \brief Main render function, called every frame.
74 Window classes should override this only if they need to alter how something is rendered.
75 General updating on a per-frame basis should be handled in FrameMove instead, as DoRender
76 is not necessarily re-entrant.
79 void DoRender() override
;
81 /*! \brief Do any post render activities.
82 Check if window closing animation is finished and finalize window closing.
86 /*! \brief Main update function, called every frame prior to rendering
87 Any window that requires updating on a frame by frame basis (such as to maintain
88 timers and the like) should override this function.
90 virtual void FrameMove() {}
92 void Close(bool forceClose
= false, int nextWindowID
= 0, bool enableSound
= true, bool bWait
= true);
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
;
101 using CGUIControlGroup::OnBack
;
102 virtual bool OnBack(int actionID
);
103 using CGUIControlGroup::OnInfo
;
104 virtual bool OnInfo(int actionID
) { return false; }
106 /*! \brief Clear the background (if necessary) prior to rendering the window
108 virtual void ClearBackground();
110 bool OnMove(int fromControl
, int moveAction
);
111 bool OnMessage(CGUIMessage
& message
) override
;
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
146 bool IsAnimating(ANIMATION_TYPE animType
) override
;
149 \brief Return if the window is a custom window
150 \return true if the window is an custom window otherwise false
152 bool IsCustom() const { return m_custom
; }
155 \brief Mark this window as custom window
156 \param custom true if this window is a custom window, false if not
158 void SetCustom(bool custom
) { m_custom
= custom
; }
160 void DisableAnimations();
162 virtual void ResetControlStates();
163 void UpdateControlStats() override
{}; // Do not count window itself
165 void SetRunActionsManually();
166 void RunLoadActions() const;
167 void RunUnloadActions() const;
169 /*! \brief Set a property
170 Sets the value of a property referenced by a key.
171 \param key name of the property to set
172 \param value value to set, may be a string, integer, boolean or double.
175 void SetProperty(const std::string
&key
, const CVariant
&value
);
177 /*! \brief Retrieve a property
178 \param key name of the property to retrieve
179 \return value of the property, empty if it doesn't exist
181 CVariant
GetProperty(const std::string
&key
) const;
183 /*! \brief Clear a all the window's properties
184 \sa SetProperty, HasProperty, GetProperty
186 void ClearProperties();
189 void DumpTextureUse() override
;
191 bool HasSaveLastControl() const { return !m_defaultAlways
; }
193 virtual void OnDeinitWindow(int nextWindowID
);
195 EVENT_RESULT
OnMouseEvent(const CPoint
& point
, const KODI::MOUSE::CMouseEvent
& event
) override
;
198 \brief Load the window XML from the given path
199 \param strPath the path to the window XML
200 \param strLowerPath a lowered path to the window XML
202 virtual bool LoadXML(const std::string
& strPath
, const std::string
&strLowerPath
);
205 \brief Loads the window from the given XML element
206 \param pRootElement the XML element
207 \return true if the window is loaded from the given XML otherwise false.
209 virtual bool Load(TiXmlElement
*pRootElement
);
212 \brief Prepare the XML for load
213 \param rootElement the original XML element
214 \return the prepared XML (resolved includes, constants and expression)
216 virtual std::unique_ptr
<TiXmlElement
> Prepare(const std::unique_ptr
<TiXmlElement
>& rootElement
);
219 \brief Check if window needs a (re)load. The window need to be (re)loaded when window is not loaded or include conditions values were changed
221 bool NeedLoad() const;
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
;
232 // control state saving on window close
233 virtual void SaveControlStates();
234 virtual void RestoreControlStates();
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);
240 void LoadControl(TiXmlElement
* pControl
, CGUIControlGroup
*pGroup
, const CRect
&rect
);
242 std::vector
<int> m_idRange
;
243 RESOLUTION_INFO m_coordsRes
; // resolution that the window coordinates are in.
245 bool m_windowLoaded
; // true if the window's xml file has been loaded
246 LOAD_TYPE m_loadType
;
247 bool m_dynamicResourceAlloc
;
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
252 int m_renderOrder
; // for render order of dialogs
254 /*! \brief Grabs the window's top,left position in skin coordinates
255 The window origin may change based on `<origin>` tag conditions in the skin.
257 \return the window's origin in skin coordinates
259 CPoint
GetPosition() const override
;
260 std::vector
<COrigin
> m_origins
; // positions of dialogs depending on base window
264 std::vector
<CControlState
> m_controlStates
;
265 int m_previousWindow
;
267 bool m_animationsEnabled
;
270 bool operator()(const std::string
&s1
, const std::string
&s2
) const;
273 CGUIAction m_loadActions
;
274 CGUIAction m_unloadActions
;
276 /*! \brief window root xml definition after resolving any skin includes.
277 Stored to avoid parsing the XML every time the window is loaded.
279 std::unique_ptr
<TiXmlElement
> m_windowXMLRootElement
;
281 bool m_manualRunActions
;
283 int m_exclusiveMouseControl
; ///< \brief id of child control that wishes to receive all mouse events \sa GUI_MSG_EXCLUSIVE_MOUSE
286 int m_menuLastFocusedControlID
;
290 std::map
<std::string
, CVariant
, icompare
> m_mapProperties
;
291 std::map
<INFO::InfoPtr
, bool> m_xmlIncludeConditions
; ///< \brief used to store conditions used to resolve includes for this window