xbmc
GUIWindowManager.h
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 
11 #include "DirtyRegionTracker.h"
12 #include "GUIWindow.h"
13 #include "IMsgTargetCallback.h"
14 #include "IWindowManagerCallback.h"
15 #include "guilib/WindowIDs.h"
16 #include "messaging/IMessageTarget.h"
17 
18 #include <list>
19 #include <unordered_map>
20 #include <utility>
21 #include <vector>
22 
23 class CGUIDialog;
24 class CGUIMediaWindow;
25 
26 #ifdef TARGET_WINDOWS_STORE
27 #pragma pack(push, 8)
28 #endif
29 enum class DialogModalityType;
30 #ifdef TARGET_WINDOWS_STORE
31 #pragma pack(pop)
32 #endif
33 
34 namespace KODI
35 {
36  namespace MESSAGING
37  {
38  class CApplicationMessenger;
39  }
40 }
41 
42 #define WINDOW_ID_MASK 0xffff
43 
49 {
50  friend CGUIDialog;
51  friend CGUIMediaWindow;
52 public:
54  ~CGUIWindowManager() override;
55  bool SendMessage(CGUIMessage& message);
56  bool SendMessage(int message, int senderID, int destID, int param1 = 0, int param2 = 0);
57  bool SendMessage(CGUIMessage& message, int window);
58  void Initialize();
59  void Add(CGUIWindow* pWindow);
60  void AddUniqueInstance(CGUIWindow *window);
61  void AddCustomWindow(CGUIWindow* pWindow);
62  void Remove(int id);
63  void Delete(int id);
64  void ActivateWindow(int iWindowID, const std::string &strPath = "");
65  void ForceActivateWindow(int iWindowID, const std::string &strPath = "");
66  void ChangeActiveWindow(int iNewID, const std::string &strPath = "");
67  void ActivateWindow(int iWindowID, const std::vector<std::string>& params, bool swappingWindows = false, bool force = false);
68  void PreviousWindow();
69 
76  bool SwitchToFullScreen(bool force = false);
77 
78  void CloseDialogs(bool forceClose = false) const;
79  void CloseInternalModalDialogs(bool forceClose = false) const;
80 
81  void OnApplicationMessage(KODI::MESSAGING::ThreadMessage* pMsg) override;
82  int GetMessageMask() override;
83 
84  // OnAction() runs through our active dialogs and windows and sends the message
85  // off to the callbacks (application, python, playlist player) and to the
86  // currently focused window(s). Returns true only if the message is handled.
87  bool OnAction(const CAction &action) const;
88 
91  void Process(unsigned int currentTime);
92 
95  void MarkDirty();
96 
99  void MarkDirty(const CRect& rect);
100 
106  bool Render();
107 
108  void RenderEx() const;
109 
112  void AfterRender();
113 
118  void FrameMove();
119 
125  bool Initialized() const { return m_initialized; }
126 
129  void CreateWindows();
130 
135  bool DestroyWindows();
136 
141  void DestroyWindow(int id);
142 
150  template<typename T,
151  typename std::enable_if<std::is_base_of<CGUIWindow, T>::value>::type* = nullptr>
152  T* GetWindow(int id) const
153  {
154  return dynamic_cast<T*>(GetWindow(id));
155  }
156 
162  CGUIWindow* GetWindow(int id) const;
163 
169  CGUIDialog* GetDialog(int id) const;
170 
171  void SetCallback(IWindowManagerCallback& callback);
172  void DeInitialize();
173 
178  void RegisterDialog(CGUIWindow* dialog);
179  void RemoveDialog(int id);
180 
186  int GetTopmostDialog(bool ignoreClosing = false) const;
187 
193  int GetTopmostModalDialog(bool ignoreClosing = false) const;
194 
195  void SendThreadMessage(CGUIMessage& message, int window = 0);
196  void DispatchThreadMessages();
197  // method to removed queued messages with message id in the requested message id list.
198  // pMessageIDList: point to first integer of a 0 ends integer array.
199  int RemoveThreadMessageByMessageIds(int *pMessageIDList);
200  void AddMsgTarget( IMsgTargetCallback* pMsgTarget );
201  int GetActiveWindow() const;
202  int GetActiveWindowOrDialog() const;
203  bool HasModalDialog(bool ignoreClosing) const;
204  bool HasVisibleModalDialog() const;
205  bool IsDialogTopmost(int id, bool modal = false) const;
206  bool IsDialogTopmost(const std::string &xmlFile, bool modal = false) const;
207  bool IsModalDialogTopmost(int id) const;
208  bool IsModalDialogTopmost(const std::string &xmlFile) const;
209  bool IsWindowActive(int id, bool ignoreClosing = true) const;
210  bool IsWindowVisible(int id) const;
211  bool IsWindowActive(const std::string &xmlFile, bool ignoreClosing = true) const;
212  bool IsWindowVisible(const std::string &xmlFile) const;
217  bool IsAddonWindow(int id) const { return (id >= WINDOW_ADDON_START && id <= WINDOW_ADDON_END); }
222  bool IsPythonWindow(int id) const
223  {
224  return (id >= WINDOW_PYTHON_START && id <= WINDOW_PYTHON_END);
225  }
226 
227  bool HasVisibleControls();
228 
229 #ifdef _DEBUG
230  void DumpTextureUse();
231 #endif
232 private:
233  void RenderPass() const;
234 
235  void LoadNotOnDemandWindows();
236  void UnloadNotOnDemandWindows();
237  void AddToWindowHistory(int newWindowID);
238 
246  void RemoveFromWindowHistory(int windowID);
247  void ClearWindowHistory();
248  void CloseWindowSync(CGUIWindow *window, int nextWindowID = 0);
249  int GetTopmostDialog(bool modal, bool ignoreClosing) const;
250 
252 
260  void ActivateWindow_Internal(int windowID, const std::vector<std::string> &params, bool swappingWindows, bool force = false);
261 
262  bool ProcessRenderLoop(bool renderOnly);
263 
264  bool HandleAction(const CAction &action) const;
265 
266  std::unordered_map<int, CGUIWindow*> m_mapWindows;
267  std::vector<CGUIWindow*> m_vecCustomWindows;
268  std::vector<CGUIWindow*> m_activeDialogs;
269  std::vector<CGUIWindow*> m_deleteWindows;
270 
271  std::deque<int> m_windowHistory;
272 
273  IWindowManagerCallback* m_pCallback;
274  std::list< std::pair<CGUIMessage*,int> > m_vecThreadMessages;
275  CCriticalSection m_critSection;
276  std::vector<IMsgTargetCallback*> m_vecMsgTargets;
277 
278  int m_iNested;
279  bool m_initialized;
280  mutable bool m_touchGestureActive{false};
281  mutable bool m_inhibitTouchGestureEvents{false};
282 
283  CDirtyRegionList m_dirtyregions;
284  CDirtyRegionTracker m_tracker;
285 };
Definition: DirtyRegionTracker.h:19
A class wishing to receive messages should implement this and call.
Definition: IMessageTarget.h:23
Definition: IWindowManagerCallback.h:20
Definition: ThreadMessage.h:25
Definition: IMsgTargetCallback.h:22
Definition: GUIWindowManager.h:48
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Definition: GUIDialog.h:35
Definition: AudioDecoder.h:18
bool Initialized() const
Return whether the window manager is initialized. The window manager is initialized on skin load - if...
Definition: GUIWindowManager.h:125
Definition: GUIMessage.h:365
Definition: GUIWindow.h:58
This implements a simple message dispatcher/router for Kodi.
Definition: ApplicationMessenger.h:230
Definition: GUIMediaWindow.h:28