3d0fd4c099725355fbc9dfbac966cde4061a636f
[vuplus_xbmc] / xbmc / addons / AddonCallbacksGUI.h
1 #pragma once
2 /*
3  *      Copyright (C) 2012-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22
23 #include "AddonCallbacks.h"
24 #include "windows/GUIMediaWindow.h"
25 #include "threads/Event.h"
26 #include "guilib/IRenderingCallback.h"
27
28 class CGUISpinControlEx;
29 class CGUIButtonControl;
30 class CGUIRadioButtonControl;
31 class CGUISettingsSliderControl;
32 class CGUIEditControl;
33 class CGUIRenderingControl;
34
35 namespace ADDON
36 {
37
38 class CAddonCallbacksGUI
39 {
40 public:
41   CAddonCallbacksGUI(CAddon* addon);
42   ~CAddonCallbacksGUI();
43
44   /**! \name General Functions */
45   CB_GUILib *GetCallbacks() { return m_callbacks; }
46
47   static void         Lock();
48   static void         Unlock();
49   static int          GetScreenHeight();
50   static int          GetScreenWidth();
51   static int          GetVideoResolution();
52
53   static GUIHANDLE    Window_New(void *addonData, const char *xmlFilename, const char *defaultSkin, bool forceFallback, bool asDialog);
54   static void         Window_Delete(void *addonData, GUIHANDLE handle);
55   static void         Window_SetCallbacks(void *addonData, GUIHANDLE handle, GUIHANDLE clienthandle, bool (*initCB)(GUIHANDLE), bool (*clickCB)(GUIHANDLE, int), bool (*focusCB)(GUIHANDLE, int), bool (*onActionCB)(GUIHANDLE handle, int));
56   static bool         Window_Show(void *addonData, GUIHANDLE handle);
57   static bool         Window_Close(void *addonData, GUIHANDLE handle);
58   static bool         Window_DoModal(void *addonData, GUIHANDLE handle);
59   static bool         Window_SetFocusId(void *addonData, GUIHANDLE handle, int iControlId);
60   static int          Window_GetFocusId(void *addonData, GUIHANDLE handle);
61   static bool         Window_SetCoordinateResolution(void *addonData, GUIHANDLE handle, int res);
62   static void         Window_SetProperty(void *addonData, GUIHANDLE handle, const char *key, const char *value);
63   static void         Window_SetPropertyInt(void *addonData, GUIHANDLE handle, const char *key, int value);
64   static void         Window_SetPropertyBool(void *addonData, GUIHANDLE handle, const char *key, bool value);
65   static void         Window_SetPropertyDouble(void *addonData, GUIHANDLE handle, const char *key, double value);
66   static const char * Window_GetProperty(void *addonData, GUIHANDLE handle, const char *key);
67   static int          Window_GetPropertyInt(void *addonData, GUIHANDLE handle, const char *key);
68   static bool         Window_GetPropertyBool(void *addonData, GUIHANDLE handle, const char *key);
69   static double       Window_GetPropertyDouble(void *addonData, GUIHANDLE handle, const char *key);
70   static void         Window_ClearProperties(void *addonData, GUIHANDLE handle);
71   static int          Window_GetListSize(void *addonData, GUIHANDLE handle);
72   static void         Window_ClearList(void *addonData, GUIHANDLE handle);
73   static GUIHANDLE    Window_AddItem(void *addonData, GUIHANDLE handle, GUIHANDLE item, int itemPosition);
74   static GUIHANDLE    Window_AddStringItem(void *addonData, GUIHANDLE handle, const char *itemName, int itemPosition);
75   static void         Window_RemoveItem(void *addonData, GUIHANDLE handle, int itemPosition);
76   static GUIHANDLE    Window_GetListItem(void *addonData, GUIHANDLE handle, int listPos);
77   static void         Window_SetCurrentListPosition(void *addonData, GUIHANDLE handle, int listPos);
78   static int          Window_GetCurrentListPosition(void *addonData, GUIHANDLE handle);
79   static GUIHANDLE    Window_GetControl_Spin(void *addonData, GUIHANDLE handle, int controlId);
80   static GUIHANDLE    Window_GetControl_Button(void *addonData, GUIHANDLE handle, int controlId);
81   static GUIHANDLE    Window_GetControl_RadioButton(void *addonData, GUIHANDLE handle, int controlId);
82   static GUIHANDLE    Window_GetControl_Edit(void *addonData, GUIHANDLE handle, int controlId);
83   static GUIHANDLE    Window_GetControl_Progress(void *addonData, GUIHANDLE handle, int controlId);
84   static GUIHANDLE    Window_GetControl_RenderAddon(void *addonData, GUIHANDLE handle, int controlId);
85   static void         Window_SetControlLabel(void *addonData, GUIHANDLE handle, int controlId, const char *label);
86   static void         Window_MarkDirtyRegion(void *addonData, GUIHANDLE handle);
87   static void         Control_Spin_SetVisible(void *addonData, GUIHANDLE spinhandle, bool yesNo);
88   static void         Control_Spin_SetText(void *addonData, GUIHANDLE spinhandle, const char *label);
89   static void         Control_Spin_Clear(void *addonData, GUIHANDLE spinhandle);
90   static void         Control_Spin_AddLabel(void *addonData, GUIHANDLE spinhandle, const char *label, int iValue);
91   static int          Control_Spin_GetValue(void *addonData, GUIHANDLE spinhandle);
92   static void         Control_Spin_SetValue(void *addonData, GUIHANDLE spinhandle, int iValue);
93   static void         Control_RadioButton_SetVisible(void *addonData, GUIHANDLE handle, bool yesNo);
94   static void         Control_RadioButton_SetText(void *addonData, GUIHANDLE handle, const char *label);
95   static void         Control_RadioButton_SetSelected(void *addonData, GUIHANDLE handle, bool yesNo);
96   static bool         Control_RadioButton_IsSelected(void *addonData, GUIHANDLE handle);
97   static void         Control_Progress_SetPercentage(void *addonData, GUIHANDLE handle, float fPercent);
98   static float        Control_Progress_GetPercentage(void *addonData, GUIHANDLE handle);
99   static void         Control_Progress_SetInfo(void *addonData, GUIHANDLE handle, int iInfo);
100   static int          Control_Progress_GetInfo(void *addonData, GUIHANDLE handle);
101   static const char * Control_Progress_GetDescription(void *addonData, GUIHANDLE handle);
102   static GUIHANDLE    ListItem_Create(void *addonData, const char *label, const char *label2, const char *iconImage, const char *thumbnailImage, const char *path);
103   static const char * ListItem_GetLabel(void *addonData, GUIHANDLE handle);
104   static void         ListItem_SetLabel(void *addonData, GUIHANDLE handle, const char *label);
105   static const char * ListItem_GetLabel2(void *addonData, GUIHANDLE handle);
106   static void         ListItem_SetLabel2(void *addonData, GUIHANDLE handle, const char *label);
107   static void         ListItem_SetIconImage(void *addonData, GUIHANDLE handle, const char *image);
108   static void         ListItem_SetThumbnailImage(void *addonData, GUIHANDLE handle, const char *image);
109   static void         ListItem_SetInfo(void *addonData, GUIHANDLE handle, const char *info);
110   static void         ListItem_SetProperty(void *addonData, GUIHANDLE handle, const char *key, const char *value);
111   static const char * ListItem_GetProperty(void *addonData, GUIHANDLE handle, const char *key);
112   static void         ListItem_SetPath(void *addonData, GUIHANDLE handle, const char *path);
113   static void         RenderAddon_SetCallbacks(void *addonData, GUIHANDLE handle, GUIHANDLE clienthandle, bool (*createCB)(GUIHANDLE,int,int,int,int,void*), void (*renderCB)(GUIHANDLE), void (*stopCB)(GUIHANDLE), bool (*dirtyCB)(GUIHANDLE));
114   static void         RenderAddon_Delete(void *addonData, GUIHANDLE handle);
115   static void         RenderAddon_MarkDirty(void *addonData, GUIHANDLE handle);
116
117 private:
118   CB_GUILib    *m_callbacks;
119   CAddon       *m_addon;
120 };
121
122 class CGUIAddonWindow : public CGUIMediaWindow
123 {
124 friend class CAddonCallbacksGUI;
125
126 public:
127   CGUIAddonWindow(int id, CStdString strXML, CAddon* addon);
128   virtual ~CGUIAddonWindow(void);
129
130   virtual bool      OnMessage(CGUIMessage& message);
131   virtual bool      OnAction(const CAction &action);
132   virtual void      AllocResources(bool forceLoad = false);
133   virtual void      FreeResources(bool forceUnLoad = false);
134   virtual void      Render();
135   void              WaitForActionEvent(unsigned int timeout);
136   void              PulseActionEvent();
137   void              AddItem(CFileItemPtr fileItem, int itemPosition);
138   void              RemoveItem(int itemPosition);
139   void              ClearList();
140   CFileItemPtr      GetListItem(int position);
141   int               GetListSize();
142   int               GetCurrentListPosition();
143   void              SetCurrentListPosition(int item);
144   virtual bool      OnClick(int iItem);
145
146 protected:
147   virtual void     Update();
148   virtual void     GetContextButtons(int itemNumber, CContextButtons &buttons);
149   void             ClearAddonStrings();
150   void             SetupShares();
151
152   bool (*CBOnInit)(GUIHANDLE cbhdl);
153   bool (*CBOnFocus)(GUIHANDLE cbhdl, int controlId);
154   bool (*CBOnClick)(GUIHANDLE cbhdl, int controlId);
155   bool (*CBOnAction)(GUIHANDLE cbhdl, int);
156
157   GUIHANDLE        m_clientHandle;
158   const int m_iWindowId;
159   int m_iOldWindowId;
160   bool m_bModal;
161   bool m_bIsDialog;
162
163 private:
164   CEvent           m_actionEvent;
165   CAddon          *m_addon;
166   CStdString       m_mediaDir;
167 };
168
169 class CGUIAddonWindowDialog : public CGUIAddonWindow
170 {
171 public:
172   CGUIAddonWindowDialog(int id, CStdString strXML, CAddon* addon);
173   virtual ~CGUIAddonWindowDialog(void);
174
175   void            Show(bool show = true);
176   virtual bool    OnMessage(CGUIMessage &message);
177   virtual bool    IsDialogRunning() const { return m_bRunning; }
178   virtual bool    IsDialog() const { return true;};
179   virtual bool    IsModalDialog() const { return true; };
180   virtual bool    IsMediaWindow() const { return false; };
181
182   void Show_Internal(bool show = true);
183
184 private:
185   bool             m_bRunning;
186 };
187
188 class CGUIAddonRenderingControl : public IRenderingCallback
189 {
190 friend class CAddonCallbacksGUI;
191 public:
192   CGUIAddonRenderingControl(CGUIRenderingControl *pControl);
193   virtual ~CGUIAddonRenderingControl() {}
194   virtual bool Create(int x, int y, int w, int h, void *device);
195   virtual void Render();
196   virtual void Stop();
197   virtual bool IsDirty();
198   virtual void Delete();
199 protected:
200   bool (*CBCreate) (GUIHANDLE cbhdl, int x, int y, int w, int h, void *device);
201   void (*CBRender)(GUIHANDLE cbhdl);
202   void (*CBStop)(GUIHANDLE cbhdl);
203   bool (*CBDirty)(GUIHANDLE cbhdl);
204
205   GUIHANDLE m_clientHandle;
206   CGUIRenderingControl *m_pControl;
207   int m_refCount;
208 };
209
210 }; /* namespace ADDON */