[cosmetics] update date in GPL header
[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://www.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
37 class CGUIDialog;
38
39 #define WINDOW_ID_MASK 0xffff
40
41 /*!
42  \ingroup winman
43  \brief
44  */
45 class CGUIWindowManager
46 {
47 public:
48   CGUIWindowManager(void);
49   virtual ~CGUIWindowManager(void);
50   bool SendMessage(CGUIMessage& message);
51   bool SendMessage(int message, int senderID, int destID, int param1 = 0, int param2 = 0);
52   bool SendMessage(CGUIMessage& message, int window);
53   void Initialize();
54   void Add(CGUIWindow* pWindow);
55   void AddUniqueInstance(CGUIWindow *window);
56   void AddCustomWindow(CGUIWindow* pWindow);
57   void Remove(int id);
58   void Delete(int id);
59   void ActivateWindow(int iWindowID, const CStdString &strPath = "");
60   void ChangeActiveWindow(int iNewID, const CStdString &strPath = "");
61   void ActivateWindow(int iWindowID, const std::vector<CStdString>& params, bool swappingWindows = false);
62   void PreviousWindow();
63
64   void CloseDialogs(bool forceClose = false);
65
66   // OnAction() runs through our active dialogs and windows and sends the message
67   // off to the callbacks (application, python, playlist player) and to the
68   // currently focused window(s).  Returns true only if the message is handled.
69   bool OnAction(const CAction &action);
70
71   /*! \brief Process active controls allowing them to animate before rendering.
72    */
73   void Process(unsigned int currentTime);
74
75   /*! \brief Mark the screen as dirty, forcing a redraw at the next Render()
76    */
77   void MarkDirty();
78
79   /*! \brief Mark a region as dirty, forcing a redraw at the next Render()
80    */
81   void MarkDirty(const CRect& rect);
82
83   /*! \brief Get the current dirty region
84    */
85   CDirtyRegionList GetDirty() { return m_tracker.GetDirtyRegions(); }
86
87   /*! \brief Rendering of the current window and any dialogs
88    Render is called every frame to draw the current window and any dialogs.
89    It should only be called from the application thread.
90    Returns true only if it has rendered something.
91    */
92   bool Render();
93
94   /*! \brief Do any post render activities.
95    */
96   void AfterRender();
97
98   /*! \brief Per-frame updating of the current window and any dialogs
99    FrameMove is called every frame to update the current window and any dialogs
100    on screen. It should only be called from the application thread.
101    */
102   void FrameMove();
103
104   /*! \brief Return whether the window manager is initialized.
105    The window manager is initialized on skin load - if the skin isn't yet loaded,
106    no windows should be able to be initialized.
107    \return true if the window manager is initialized, false otherwise.
108    */
109   bool Initialized() const { return m_initialized; };
110
111   CGUIWindow* GetWindow(int id) const;
112   void ProcessRenderLoop(bool renderOnly = false);
113   void SetCallback(IWindowManagerCallback& callback);
114   void DeInitialize();
115
116   void RouteToWindow(CGUIWindow* dialog);
117   void AddModeless(CGUIWindow* dialog);
118   void RemoveDialog(int id);
119   int GetTopMostModalDialogID(bool ignoreClosing = false) const;
120
121   void SendThreadMessage(CGUIMessage& message);
122   void SendThreadMessage(CGUIMessage& message, int window);
123   void DispatchThreadMessages();
124   void AddMsgTarget( IMsgTargetCallback* pMsgTarget );
125   int GetActiveWindow() const;
126   int GetFocusedWindow() const;
127   bool HasModalDialog() const;
128   bool HasDialogOnScreen() const;
129   bool IsWindowActive(int id, bool ignoreClosing = true) const;
130   bool IsWindowVisible(int id) const;
131   bool IsWindowTopMost(int id) const;
132   bool IsWindowActive(const CStdString &xmlFile, bool ignoreClosing = true) const;
133   bool IsWindowVisible(const CStdString &xmlFile) const;
134   bool IsWindowTopMost(const CStdString &xmlFile) const;
135   bool IsOverlayAllowed() const;
136   void ShowOverlay(CGUIWindow::OVERLAY_STATE state);
137   void GetActiveModelessWindows(std::vector<int> &ids);
138 #ifdef _DEBUG
139   void DumpTextureUse();
140 #endif
141 private:
142   void RenderPass();
143
144   void LoadNotOnDemandWindows();
145   void UnloadNotOnDemandWindows();
146   void HideOverlay(CGUIWindow::OVERLAY_STATE state);
147   void AddToWindowHistory(int newWindowID);
148   void ClearWindowHistory();
149   void CloseWindowSync(CGUIWindow *window, int nextWindowID = 0);
150   CGUIWindow *GetTopMostDialog() const;
151
152   friend class CApplicationMessenger;
153   void ActivateWindow_Internal(int windowID, const std::vector<CStdString> &params, bool swappingWindows);
154
155   typedef std::map<int, CGUIWindow *> WindowMap;
156   WindowMap m_mapWindows;
157   std::vector <CGUIWindow*> m_vecCustomWindows;
158   std::vector <CGUIWindow*> m_activeDialogs;
159   std::vector <CGUIWindow*> m_deleteWindows;
160   typedef std::vector<CGUIWindow*>::iterator iDialog;
161   typedef std::vector<CGUIWindow*>::const_iterator ciDialog;
162   typedef std::vector<CGUIWindow*>::reverse_iterator rDialog;
163   typedef std::vector<CGUIWindow*>::const_reverse_iterator crDialog;
164
165   std::stack<int> m_windowHistory;
166
167   IWindowManagerCallback* m_pCallback;
168   std::vector < std::pair<CGUIMessage*,int> > m_vecThreadMessages;
169   CCriticalSection m_critSection;
170   std::vector <IMsgTargetCallback*> m_vecMsgTargets;
171
172   bool m_bShowOverlay;
173   int  m_iNested;
174   bool m_initialized;
175
176   CDirtyRegionTracker m_tracker;
177 };
178
179 /*!
180  \ingroup winman
181  \brief
182  */
183 XBMC_GLOBAL_REF(CGUIWindowManager,g_windowManager);
184 #define g_windowManager XBMC_GLOBAL_USE(CGUIWindowManager)
185 #endif
186