Merge pull request #4687 from ruuk/textboxgettext
[vuplus_xbmc] / xbmc / guilib / GUIWindowManager.h
1 /*!
2 \file GUIWindowManager.h
3 \brief
4 */
5
6 #ifndef GUILIB_CGUIWindowManager_H
7 #define GUILIB_CGUIWindowManager_H
8
9 #pragma once
10
11 /*
12  *      Copyright (C) 2005-2013 Team XBMC
13  *      http://xbmc.org
14  *
15  *  This Program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2, or (at your option)
18  *  any later version.
19  *
20  *  This Program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with XBMC; see the file COPYING.  If not, see
27  *  <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #include "GUIWindow.h"
32 #include "IWindowManagerCallback.h"
33 #include "IMsgTargetCallback.h"
34 #include "DirtyRegionTracker.h"
35 #include "utils/GlobalsHandling.h"
36 #include "guilib/WindowIDs.h"
37 #include <list>
38
39 class CGUIDialog;
40
41 #define WINDOW_ID_MASK 0xffff
42
43 /*!
44  \ingroup winman
45  \brief
46  */
47 class CGUIWindowManager
48 {
49 public:
50   CGUIWindowManager(void);
51   virtual ~CGUIWindowManager(void);
52   bool SendMessage(CGUIMessage& message);
53   bool SendMessage(int message, int senderID, int destID, int param1 = 0, int param2 = 0);
54   bool SendMessage(CGUIMessage& message, int window);
55   void Initialize();
56   void Add(CGUIWindow* pWindow);
57   void AddUniqueInstance(CGUIWindow *window);
58   void AddCustomWindow(CGUIWindow* pWindow);
59   void Remove(int id);
60   void Delete(int id);
61   void ActivateWindow(int iWindowID, const CStdString &strPath = "");
62   void ChangeActiveWindow(int iNewID, const CStdString &strPath = "");
63   void ActivateWindow(int iWindowID, const std::vector<CStdString>& params, bool swappingWindows = false);
64   void PreviousWindow();
65
66   void CloseDialogs(bool forceClose = false) const;
67
68   // OnAction() runs through our active dialogs and windows and sends the message
69   // off to the callbacks (application, python, playlist player) and to the
70   // currently focused window(s).  Returns true only if the message is handled.
71   bool OnAction(const CAction &action) const;
72
73   /*! \brief Process active controls allowing them to animate before rendering.
74    */
75   void Process(unsigned int currentTime);
76
77   /*! \brief Mark the screen as dirty, forcing a redraw at the next Render()
78    */
79   void MarkDirty();
80
81   /*! \brief Mark a region as dirty, forcing a redraw at the next Render()
82    */
83   void MarkDirty(const CRect& rect);
84
85   /*! \brief Get the current dirty region
86    */
87   CDirtyRegionList GetDirty() { return m_tracker.GetDirtyRegions(); }
88
89   /*! \brief Rendering of the current window and any dialogs
90    Render is called every frame to draw the current window and any dialogs.
91    It should only be called from the application thread.
92    Returns true only if it has rendered something.
93    */
94   bool Render();
95
96   /*! \brief Do any post render activities.
97    */
98   void AfterRender();
99
100   /*! \brief Per-frame updating of the current window and any dialogs
101    FrameMove is called every frame to update the current window and any dialogs
102    on screen. It should only be called from the application thread.
103    */
104   void FrameMove();
105
106   /*! \brief Return whether the window manager is initialized.
107    The window manager is initialized on skin load - if the skin isn't yet loaded,
108    no windows should be able to be initialized.
109    \return true if the window manager is initialized, false otherwise.
110    */
111   bool Initialized() const { return m_initialized; };
112
113   CGUIWindow* GetWindow(int id) const;
114   void ProcessRenderLoop(bool renderOnly = false);
115   void SetCallback(IWindowManagerCallback& callback);
116   void DeInitialize();
117
118   void RouteToWindow(CGUIWindow* dialog);
119   void AddModeless(CGUIWindow* dialog);
120   void RemoveDialog(int id);
121   int GetTopMostModalDialogID(bool ignoreClosing = false) const;
122
123   void SendThreadMessage(CGUIMessage& message, int window = 0);
124   void DispatchThreadMessages();
125   // method to removed queued messages with message id in the requested message id list.
126   // pMessageIDList: point to first integer of a 0 ends integer array.
127   int RemoveThreadMessageByMessageIds(int *pMessageIDList);
128   void AddMsgTarget( IMsgTargetCallback* pMsgTarget );
129   int GetActiveWindow() const;
130   int GetFocusedWindow() const;
131   bool HasModalDialog() const;
132   bool HasDialogOnScreen() const;
133   bool IsWindowActive(int id, bool ignoreClosing = true) const;
134   bool IsWindowVisible(int id) const;
135   bool IsWindowTopMost(int id) const;
136   bool IsWindowActive(const CStdString &xmlFile, bool ignoreClosing = true) const;
137   bool IsWindowVisible(const CStdString &xmlFile) const;
138   bool IsWindowTopMost(const CStdString &xmlFile) const;
139   bool IsOverlayAllowed() const;
140   void ShowOverlay(CGUIWindow::OVERLAY_STATE state);
141   void GetActiveModelessWindows(std::vector<int> &ids);
142 #ifdef _DEBUG
143   void DumpTextureUse();
144 #endif
145 private:
146   void RenderPass() const;
147
148   void LoadNotOnDemandWindows();
149   void UnloadNotOnDemandWindows();
150   void HideOverlay(CGUIWindow::OVERLAY_STATE state);
151   void AddToWindowHistory(int newWindowID);
152   void ClearWindowHistory();
153   void CloseWindowSync(CGUIWindow *window, int nextWindowID = 0);
154   CGUIWindow *GetTopMostDialog() const;
155
156   friend class CApplicationMessenger;
157   void ActivateWindow_Internal(int windowID, const std::vector<CStdString> &params, bool swappingWindows);
158
159   typedef std::map<int, CGUIWindow *> WindowMap;
160   WindowMap m_mapWindows;
161   std::vector <CGUIWindow*> m_vecCustomWindows;
162   std::vector <CGUIWindow*> m_activeDialogs;
163   std::vector <CGUIWindow*> m_deleteWindows;
164   typedef std::vector<CGUIWindow*>::iterator iDialog;
165   typedef std::vector<CGUIWindow*>::const_iterator ciDialog;
166   typedef std::vector<CGUIWindow*>::reverse_iterator rDialog;
167   typedef std::vector<CGUIWindow*>::const_reverse_iterator crDialog;
168
169   std::stack<int> m_windowHistory;
170
171   IWindowManagerCallback* m_pCallback;
172   std::list < std::pair<CGUIMessage*,int> > m_vecThreadMessages;
173   CCriticalSection m_critSection;
174   std::vector <IMsgTargetCallback*> m_vecMsgTargets;
175
176   bool m_bShowOverlay;
177   int  m_iNested;
178   bool m_initialized;
179
180   CDirtyRegionTracker m_tracker;
181
182 private:
183   class CGUIWindowManagerIdCache
184   {
185   public:
186     CGUIWindowManagerIdCache(void) : m_id(WINDOW_INVALID) {}
187     CGUIWindow *Get(int id)
188     {
189       if (id == m_id)
190         return m_window;
191       return NULL;
192     }
193     void Set(int id, CGUIWindow *window)
194     {
195       m_id = id;
196       m_window = window;
197     }
198     void Invalidate(void)
199     {
200       m_id = WINDOW_INVALID;
201     }
202   private:
203     int m_id;
204     CGUIWindow *m_window;
205   };
206   mutable CGUIWindowManagerIdCache m_idCache;
207 };
208
209 /*!
210  \ingroup winman
211  \brief
212  */
213 XBMC_GLOBAL_REF(CGUIWindowManager,g_windowManager);
214 #define g_windowManager XBMC_GLOBAL_USE(CGUIWindowManager)
215 #endif
216