2 \file GUIWindowManager.h
6 #ifndef GUILIB_CGUIWindowManager_H
7 #define GUILIB_CGUIWindowManager_H
12 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
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"
41 #define WINDOW_ID_MASK 0xffff
47 class CGUIWindowManager
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);
56 void Add(CGUIWindow* pWindow);
57 void AddUniqueInstance(CGUIWindow *window);
58 void AddCustomWindow(CGUIWindow* pWindow);
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();
66 void CloseDialogs(bool forceClose = false) const;
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;
73 /*! \brief Process active controls allowing them to animate before rendering.
75 void Process(unsigned int currentTime);
77 /*! \brief Mark the screen as dirty, forcing a redraw at the next Render()
81 /*! \brief Mark a region as dirty, forcing a redraw at the next Render()
83 void MarkDirty(const CRect& rect);
85 /*! \brief Get the current dirty region
87 CDirtyRegionList GetDirty() { return m_tracker.GetDirtyRegions(); }
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.
96 /*! \brief Do any post render activities.
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.
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.
111 bool Initialized() const { return m_initialized; };
113 CGUIWindow* GetWindow(int id) const;
114 void ProcessRenderLoop(bool renderOnly = false);
115 void SetCallback(IWindowManagerCallback& callback);
118 void RouteToWindow(CGUIWindow* dialog);
119 void AddModeless(CGUIWindow* dialog);
120 void RemoveDialog(int id);
121 int GetTopMostModalDialogID(bool ignoreClosing = false) const;
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);
143 void DumpTextureUse();
146 void RenderPass() const;
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;
156 friend class CApplicationMessenger;
157 void ActivateWindow_Internal(int windowID, const std::vector<CStdString> ¶ms, bool swappingWindows);
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;
169 std::stack<int> m_windowHistory;
171 IWindowManagerCallback* m_pCallback;
172 std::list < std::pair<CGUIMessage*,int> > m_vecThreadMessages;
173 CCriticalSection m_critSection;
174 std::vector <IMsgTargetCallback*> m_vecMsgTargets;
180 CDirtyRegionTracker m_tracker;
183 class CGUIWindowManagerIdCache
186 CGUIWindowManagerIdCache(void) : m_id(WINDOW_INVALID) {}
187 CGUIWindow *Get(int id)
193 void Set(int id, CGUIWindow *window)
198 void Invalidate(void)
200 m_id = WINDOW_INVALID;
204 CGUIWindow *m_window;
206 mutable CGUIWindowManagerIdCache m_idCache;
213 XBMC_GLOBAL_REF(CGUIWindowManager,g_windowManager);
214 #define g_windowManager XBMC_GLOBAL_USE(CGUIWindowManager)