2 * Copyright (C) 2012-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "Application.h"
22 #include "ApplicationMessenger.h"
24 #include "AddonCallbacksGUI.h"
25 #include "utils/log.h"
28 #include "filesystem/File.h"
29 #include "utils/URIUtils.h"
30 #include "utils/TimeUtils.h"
31 #include "utils/StringUtils.h"
32 #include "guilib/GUIWindowManager.h"
33 #include "guilib/Key.h"
34 #include "guilib/TextureManager.h"
35 #include "guilib/GUISpinControlEx.h"
36 #include "guilib/GUIRadioButtonControl.h"
37 #include "guilib/GUISettingsSliderControl.h"
38 #include "guilib/GUIEditControl.h"
39 #include "guilib/GUIProgressControl.h"
40 #include "guilib/GUIRenderingControl.h"
42 #define CONTROL_BTNVIEWASICONS 2
43 #define CONTROL_BTNSORTBY 3
44 #define CONTROL_BTNSORTASC 4
45 #define CONTROL_LABELFILES 12
52 static int iXBMCGUILockRef = 0;
54 CAddonCallbacksGUI::CAddonCallbacksGUI(CAddon* addon)
57 m_callbacks = new CB_GUILib;
59 /* GUI Helper functions */
60 m_callbacks->Lock = CAddonCallbacksGUI::Lock;
61 m_callbacks->Unlock = CAddonCallbacksGUI::Unlock;
62 m_callbacks->GetScreenHeight = CAddonCallbacksGUI::GetScreenHeight;
63 m_callbacks->GetScreenWidth = CAddonCallbacksGUI::GetScreenWidth;
64 m_callbacks->GetVideoResolution = CAddonCallbacksGUI::GetVideoResolution;
65 m_callbacks->Window_New = CAddonCallbacksGUI::Window_New;
66 m_callbacks->Window_Delete = CAddonCallbacksGUI::Window_Delete;
67 m_callbacks->Window_SetCallbacks = CAddonCallbacksGUI::Window_SetCallbacks;
68 m_callbacks->Window_Show = CAddonCallbacksGUI::Window_Show;
69 m_callbacks->Window_Close = CAddonCallbacksGUI::Window_Close;
70 m_callbacks->Window_DoModal = CAddonCallbacksGUI::Window_DoModal;
71 m_callbacks->Window_SetFocusId = CAddonCallbacksGUI::Window_SetFocusId;
72 m_callbacks->Window_GetFocusId = CAddonCallbacksGUI::Window_GetFocusId;
73 m_callbacks->Window_SetCoordinateResolution = CAddonCallbacksGUI::Window_SetCoordinateResolution;
74 m_callbacks->Window_SetProperty = CAddonCallbacksGUI::Window_SetProperty;
75 m_callbacks->Window_SetPropertyInt = CAddonCallbacksGUI::Window_SetPropertyInt;
76 m_callbacks->Window_SetPropertyBool = CAddonCallbacksGUI::Window_SetPropertyBool;
77 m_callbacks->Window_SetPropertyDouble = CAddonCallbacksGUI::Window_SetPropertyDouble;
78 m_callbacks->Window_GetProperty = CAddonCallbacksGUI::Window_GetProperty;
79 m_callbacks->Window_GetPropertyInt = CAddonCallbacksGUI::Window_GetPropertyInt;
80 m_callbacks->Window_GetPropertyBool = CAddonCallbacksGUI::Window_GetPropertyBool;
81 m_callbacks->Window_GetPropertyDouble = CAddonCallbacksGUI::Window_GetPropertyDouble;
82 m_callbacks->Window_ClearProperties = CAddonCallbacksGUI::Window_ClearProperties;
84 m_callbacks->Window_GetListSize = CAddonCallbacksGUI::Window_GetListSize;
85 m_callbacks->Window_ClearList = CAddonCallbacksGUI::Window_ClearList;
86 m_callbacks->Window_AddItem = CAddonCallbacksGUI::Window_AddItem;
87 m_callbacks->Window_AddStringItem = CAddonCallbacksGUI::Window_AddStringItem;
88 m_callbacks->Window_RemoveItem = CAddonCallbacksGUI::Window_RemoveItem;
89 m_callbacks->Window_GetListItem = CAddonCallbacksGUI::Window_GetListItem;
90 m_callbacks->Window_SetCurrentListPosition = CAddonCallbacksGUI::Window_SetCurrentListPosition;
91 m_callbacks->Window_GetCurrentListPosition = CAddonCallbacksGUI::Window_GetCurrentListPosition;
93 m_callbacks->Window_GetControl_Spin = CAddonCallbacksGUI::Window_GetControl_Spin;
94 m_callbacks->Window_GetControl_Button = CAddonCallbacksGUI::Window_GetControl_Button;
95 m_callbacks->Window_GetControl_RadioButton = CAddonCallbacksGUI::Window_GetControl_RadioButton;
96 m_callbacks->Window_GetControl_Edit = CAddonCallbacksGUI::Window_GetControl_Edit;
97 m_callbacks->Window_GetControl_Progress = CAddonCallbacksGUI::Window_GetControl_Progress;
98 m_callbacks->Window_GetControl_RenderAddon = CAddonCallbacksGUI::Window_GetControl_RenderAddon;
100 m_callbacks->Window_SetControlLabel = CAddonCallbacksGUI::Window_SetControlLabel;
101 m_callbacks->Window_MarkDirtyRegion = CAddonCallbacksGUI::Window_MarkDirtyRegion;
103 m_callbacks->Control_Spin_SetVisible = CAddonCallbacksGUI::Control_Spin_SetVisible;
104 m_callbacks->Control_Spin_SetText = CAddonCallbacksGUI::Control_Spin_SetText;
105 m_callbacks->Control_Spin_Clear = CAddonCallbacksGUI::Control_Spin_Clear;
106 m_callbacks->Control_Spin_AddLabel = CAddonCallbacksGUI::Control_Spin_AddLabel;
107 m_callbacks->Control_Spin_GetValue = CAddonCallbacksGUI::Control_Spin_GetValue;
108 m_callbacks->Control_Spin_SetValue = CAddonCallbacksGUI::Control_Spin_SetValue;
110 m_callbacks->Control_RadioButton_SetVisible = CAddonCallbacksGUI::Control_RadioButton_SetVisible;
111 m_callbacks->Control_RadioButton_SetText = CAddonCallbacksGUI::Control_RadioButton_SetText;
112 m_callbacks->Control_RadioButton_SetSelected= CAddonCallbacksGUI::Control_RadioButton_SetSelected;
113 m_callbacks->Control_RadioButton_IsSelected = CAddonCallbacksGUI::Control_RadioButton_IsSelected;
115 m_callbacks->Control_Progress_SetPercentage = CAddonCallbacksGUI::Control_Progress_SetPercentage;
116 m_callbacks->Control_Progress_GetPercentage = CAddonCallbacksGUI::Control_Progress_GetPercentage;
117 m_callbacks->Control_Progress_SetInfo = CAddonCallbacksGUI::Control_Progress_SetInfo;
118 m_callbacks->Control_Progress_GetInfo = CAddonCallbacksGUI::Control_Progress_GetInfo;
119 m_callbacks->Control_Progress_GetDescription= CAddonCallbacksGUI::Control_Progress_GetDescription;
121 m_callbacks->ListItem_Create = CAddonCallbacksGUI::ListItem_Create;
122 m_callbacks->ListItem_GetLabel = CAddonCallbacksGUI::ListItem_GetLabel;
123 m_callbacks->ListItem_SetLabel = CAddonCallbacksGUI::ListItem_SetLabel;
124 m_callbacks->ListItem_GetLabel2 = CAddonCallbacksGUI::ListItem_GetLabel2;
125 m_callbacks->ListItem_SetLabel2 = CAddonCallbacksGUI::ListItem_SetLabel2;
126 m_callbacks->ListItem_SetIconImage = CAddonCallbacksGUI::ListItem_SetIconImage;
127 m_callbacks->ListItem_SetThumbnailImage = CAddonCallbacksGUI::ListItem_SetThumbnailImage;
128 m_callbacks->ListItem_SetInfo = CAddonCallbacksGUI::ListItem_SetInfo;
129 m_callbacks->ListItem_SetProperty = CAddonCallbacksGUI::ListItem_SetProperty;
130 m_callbacks->ListItem_GetProperty = CAddonCallbacksGUI::ListItem_GetProperty;
131 m_callbacks->ListItem_SetPath = CAddonCallbacksGUI::ListItem_SetPath;
133 m_callbacks->RenderAddon_SetCallbacks = CAddonCallbacksGUI::RenderAddon_SetCallbacks;
134 m_callbacks->RenderAddon_Delete = CAddonCallbacksGUI::RenderAddon_Delete;
137 CAddonCallbacksGUI::~CAddonCallbacksGUI()
142 void CAddonCallbacksGUI::Lock()
144 if (iXBMCGUILockRef == 0) g_graphicsContext.Lock();
148 void CAddonCallbacksGUI::Unlock()
150 if (iXBMCGUILockRef > 0)
153 if (iXBMCGUILockRef == 0) g_graphicsContext.Unlock();
157 int CAddonCallbacksGUI::GetScreenHeight()
159 return g_graphicsContext.GetHeight();
162 int CAddonCallbacksGUI::GetScreenWidth()
164 return g_graphicsContext.GetWidth();
167 int CAddonCallbacksGUI::GetVideoResolution()
169 return (int)g_graphicsContext.GetVideoResolution();
172 GUIHANDLE CAddonCallbacksGUI::Window_New(void *addonData, const char *xmlFilename, const char *defaultSkin, bool forceFallback, bool asDialog)
174 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
178 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
181 CStdString strSkinPath;
184 /* Check to see if the XML file exists in current skin. If not use
185 fallback path to find a skin for the addon */
186 strSkinPath = g_SkinInfo->GetSkinPath(xmlFilename, &res);
188 if (!XFILE::CFile::Exists(strSkinPath))
190 /* Check for the matching folder for the skin in the fallback skins folder */
191 CStdString basePath = URIUtils::AddFileToFolder(guiHelper->m_addon->Path(), "resources");
192 basePath = URIUtils::AddFileToFolder(basePath, "skins");
193 basePath = URIUtils::AddFileToFolder(basePath, URIUtils::GetFileName(g_SkinInfo->Path()));
194 strSkinPath = g_SkinInfo->GetSkinPath(xmlFilename, &res, basePath);
195 if (!XFILE::CFile::Exists(strSkinPath))
197 /* Finally fallback to the DefaultSkin as it didn't exist in either the
198 XBMC Skin folder or the fallback skin folder */
199 forceFallback = true;
206 //FIXME make this static method of current skin?
207 CStdString str("none");
208 AddonProps props(str, ADDON_SKIN, str, str);
209 CStdString basePath = URIUtils::AddFileToFolder(guiHelper->m_addon->Path(), "resources");
210 basePath = URIUtils::AddFileToFolder(basePath, "skins");
211 basePath = URIUtils::AddFileToFolder(basePath, defaultSkin);
212 props.path = basePath;
214 CSkinInfo skinInfo(props);
216 strSkinPath = skinInfo.GetSkinPath(xmlFilename, &res, basePath);
218 if (!XFILE::CFile::Exists(strSkinPath))
220 CLog::Log(LOGERROR, "Window_New: %s/%s - XML File '%s' for Window is missing, contact Developer '%s' of this AddOn", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str(), strSkinPath.c_str(), guiHelper->m_addon->Author().c_str());
224 // window id's 14000 - 14100 are reserved for addons
225 // get first window id that is not in use
226 int id = WINDOW_ADDON_START;
227 // if window 14099 is in use it means addon can't create more windows
229 if (g_windowManager.GetWindow(WINDOW_ADDON_END))
232 CLog::Log(LOGERROR, "Window_New: %s/%s - maximum number of windows reached", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
235 while(id < WINDOW_ADDON_END && g_windowManager.GetWindow(id) != NULL) id++;
240 window = new CGUIAddonWindow(id, strSkinPath, guiHelper->m_addon);
242 window = new CGUIAddonWindowDialog(id, strSkinPath, guiHelper->m_addon);
245 g_windowManager.Add(window);
248 window->SetCoordsRes(res);
253 void CAddonCallbacksGUI::Window_Delete(void *addonData, GUIHANDLE handle)
255 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
259 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
263 CLog::Log(LOGERROR, "Window_Show: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
267 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
268 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
273 // first change to an existing window
274 if (g_windowManager.GetActiveWindow() == pAddonWindow->m_iWindowId && !g_application.m_bStop)
276 if(g_windowManager.GetWindow(pAddonWindow->m_iOldWindowId))
277 g_windowManager.ActivateWindow(pAddonWindow->m_iOldWindowId);
278 else // old window does not exist anymore, switch to home
279 g_windowManager.ActivateWindow(WINDOW_HOME);
281 // Free any window properties
282 pAddonWindow->ClearProperties();
283 // free the window's resources and unload it (free all guicontrols)
284 pAddonWindow->FreeResources(true);
286 g_windowManager.Remove(pAddonWindow->GetID());
291 void CAddonCallbacksGUI::Window_SetCallbacks(void *addonData, GUIHANDLE handle, GUIHANDLE clienthandle, bool (*initCB)(GUIHANDLE), bool (*clickCB)(GUIHANDLE, int), bool (*focusCB)(GUIHANDLE, int), bool (*onActionCB)(GUIHANDLE handle, int))
293 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
294 if (!helper || !handle)
297 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
300 pAddonWindow->m_clientHandle = clienthandle;
301 pAddonWindow->CBOnInit = initCB;
302 pAddonWindow->CBOnClick = clickCB;
303 pAddonWindow->CBOnFocus = focusCB;
304 pAddonWindow->CBOnAction = onActionCB;
308 bool CAddonCallbacksGUI::Window_Show(void *addonData, GUIHANDLE handle)
310 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
314 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
318 CLog::Log(LOGERROR, "Window_Show: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
322 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
323 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
327 if (pAddonWindow->m_iOldWindowId != pAddonWindow->m_iWindowId && pAddonWindow->m_iWindowId != g_windowManager.GetActiveWindow())
328 pAddonWindow->m_iOldWindowId = g_windowManager.GetActiveWindow();
331 if (pAddonWindow->IsDialog())
332 ((CGUIAddonWindowDialog*)pAddonWindow)->Show();
334 g_windowManager.ActivateWindow(pAddonWindow->m_iWindowId);
340 bool CAddonCallbacksGUI::Window_Close(void *addonData, GUIHANDLE handle)
342 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
346 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
350 CLog::Log(LOGERROR, "Window_Close: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
354 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
355 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
359 pAddonWindow->m_bModal = false;
360 if (pAddonWindow->IsDialog())
361 ((CGUIAddonWindowDialog*)pAddonWindow)->PulseActionEvent();
363 ((CGUIAddonWindow*)pAddonWindow)->PulseActionEvent();
366 // if it's a dialog, we have to close it a bit different
367 if (pAddonWindow->IsDialog())
368 ((CGUIAddonWindowDialog*)pAddonWindow)->Show(false);
370 g_windowManager.ActivateWindow(pAddonWindow->m_iOldWindowId);
371 pAddonWindow->m_iOldWindowId = 0;
378 bool CAddonCallbacksGUI::Window_DoModal(void *addonData, GUIHANDLE handle)
380 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
384 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
388 CLog::Log(LOGERROR, "Window_DoModal: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
392 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
393 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
397 pAddonWindow->m_bModal = true;
399 if (pAddonWindow->m_iWindowId != g_windowManager.GetActiveWindow())
400 Window_Show(addonData, handle);
405 bool CAddonCallbacksGUI::Window_SetFocusId(void *addonData, GUIHANDLE handle, int iControlId)
407 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
411 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
415 CLog::Log(LOGERROR, "Window_SetFocusId: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
419 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
420 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
424 if(!pWindow->GetControl(iControlId))
426 CLog::Log(LOGERROR, "Window_SetFocusId: %s/%s - Control does not exist in window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
431 CGUIMessage msg = CGUIMessage(GUI_MSG_SETFOCUS, pAddonWindow->m_iWindowId, iControlId);
432 pWindow->OnMessage(msg);
438 int CAddonCallbacksGUI::Window_GetFocusId(void *addonData, GUIHANDLE handle)
442 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
446 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
450 CLog::Log(LOGERROR, "Window_GetFocusId: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
454 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
455 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
460 iControlId = pWindow->GetFocusedControlID();
463 if (iControlId == -1)
465 CLog::Log(LOGERROR, "Window_GetFocusId: %s/%s - No control in this window has focus", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
472 bool CAddonCallbacksGUI::Window_SetCoordinateResolution(void *addonData, GUIHANDLE handle, int res)
474 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
478 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
482 CLog::Log(LOGERROR, "SetCoordinateResolution: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
486 if (res < RES_HDTV_1080i || res > RES_AUTORES)
488 CLog::Log(LOGERROR, "SetCoordinateResolution: %s/%s - Invalid resolution", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
492 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
493 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
497 pWindow->SetCoordsRes((RESOLUTION)res);
502 void CAddonCallbacksGUI::Window_SetProperty(void *addonData, GUIHANDLE handle, const char *key, const char *value)
504 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
508 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
512 CLog::Log(LOGERROR, "Window_SetProperty: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
516 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
517 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
521 CStdString lowerKey = key;
522 StringUtils::ToLower(lowerKey);
525 pWindow->SetProperty(lowerKey, value);
529 void CAddonCallbacksGUI::Window_SetPropertyInt(void *addonData, GUIHANDLE handle, const char *key, int value)
531 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
535 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
539 CLog::Log(LOGERROR, "Window_SetPropertyInt: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
543 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
544 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
548 CStdString lowerKey = key;
549 StringUtils::ToLower(lowerKey);
552 pWindow->SetProperty(lowerKey, value);
556 void CAddonCallbacksGUI::Window_SetPropertyBool(void *addonData, GUIHANDLE handle, const char *key, bool value)
558 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
562 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
566 CLog::Log(LOGERROR, "Window_SetPropertyBool: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
570 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
571 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
575 CStdString lowerKey = key;
576 StringUtils::ToLower(lowerKey);
579 pWindow->SetProperty(lowerKey, value);
583 void CAddonCallbacksGUI::Window_SetPropertyDouble(void *addonData, GUIHANDLE handle, const char *key, double value)
585 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
589 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
593 CLog::Log(LOGERROR, "Window_SetPropertyDouble: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
597 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
598 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
602 CStdString lowerKey = key;
603 StringUtils::ToLower(lowerKey);
606 pWindow->SetProperty(lowerKey, value);
610 const char* CAddonCallbacksGUI::Window_GetProperty(void *addonData, GUIHANDLE handle, const char *key)
612 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
616 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
620 CLog::Log(LOGERROR, "Window_GetProperty: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
624 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
625 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
629 CStdString lowerKey = key;
630 StringUtils::ToLower(lowerKey);
633 string value = pWindow->GetProperty(lowerKey).asString();
636 return strdup(value.c_str());
639 int CAddonCallbacksGUI::Window_GetPropertyInt(void *addonData, GUIHANDLE handle, const char *key)
641 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
645 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
649 CLog::Log(LOGERROR, "Window_GetPropertyInt: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
653 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
654 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
658 CStdString lowerKey = key;
659 StringUtils::ToLower(lowerKey);
662 int value = (int)pWindow->GetProperty(lowerKey).asInteger();
668 bool CAddonCallbacksGUI::Window_GetPropertyBool(void *addonData, GUIHANDLE handle, const char *key)
670 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
674 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
678 CLog::Log(LOGERROR, "Window_GetPropertyBool: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
682 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
683 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
687 CStdString lowerKey = key;
688 StringUtils::ToLower(lowerKey);
691 bool value = pWindow->GetProperty(lowerKey).asBoolean();
697 double CAddonCallbacksGUI::Window_GetPropertyDouble(void *addonData, GUIHANDLE handle, const char *key)
699 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
703 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
707 CLog::Log(LOGERROR, "Window_GetPropertyDouble: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
711 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
712 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
716 CStdString lowerKey = key;
717 StringUtils::ToLower(lowerKey);
720 double value = pWindow->GetProperty(lowerKey).asDouble();
726 void CAddonCallbacksGUI::Window_ClearProperties(void *addonData, GUIHANDLE handle)
728 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
732 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
736 CLog::Log(LOGERROR, "Window_ClearProperties: %s/%s - No Window", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
740 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
741 CGUIWindow *pWindow = (CGUIWindow*)g_windowManager.GetWindow(pAddonWindow->m_iWindowId);
746 pWindow->ClearProperties();
750 int CAddonCallbacksGUI::Window_GetListSize(void *addonData, GUIHANDLE handle)
752 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
753 if (!helper || !handle)
756 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
759 int listSize = pAddonWindow->GetListSize();
765 void CAddonCallbacksGUI::Window_ClearList(void *addonData, GUIHANDLE handle)
767 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
768 if (!helper || !handle)
771 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
774 pAddonWindow->ClearList();
780 GUIHANDLE CAddonCallbacksGUI::Window_AddItem(void *addonData, GUIHANDLE handle, GUIHANDLE item, int itemPosition)
782 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
783 if (!helper || !handle || !item)
786 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
787 CFileItemPtr pItem((CFileItem*)item);
789 pAddonWindow->AddItem(pItem, itemPosition);
795 GUIHANDLE CAddonCallbacksGUI::Window_AddStringItem(void *addonData, GUIHANDLE handle, const char *itemName, int itemPosition)
797 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
798 if (!helper || !handle || !itemName)
801 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
802 CFileItemPtr item(new CFileItem(itemName));
804 pAddonWindow->AddItem(item, itemPosition);
810 void CAddonCallbacksGUI::Window_RemoveItem(void *addonData, GUIHANDLE handle, int itemPosition)
812 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
813 if (!helper || !handle)
816 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
819 pAddonWindow->RemoveItem(itemPosition);
825 GUIHANDLE CAddonCallbacksGUI::Window_GetListItem(void *addonData, GUIHANDLE handle, int listPos)
827 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
828 if (!helper || !handle)
831 CAddonCallbacksGUI* guiHelper = helper->GetHelperGUI();
832 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
835 CFileItemPtr fi = pAddonWindow->GetListItem(listPos);
839 CLog::Log(LOGERROR, "Window_GetListItem: %s/%s - Index out of range", TranslateType(guiHelper->m_addon->Type()).c_str(), guiHelper->m_addon->Name().c_str());
847 void CAddonCallbacksGUI::Window_SetCurrentListPosition(void *addonData, GUIHANDLE handle, int listPos)
849 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
850 if (!helper || !handle)
853 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
856 pAddonWindow->SetCurrentListPosition(listPos);
862 int CAddonCallbacksGUI::Window_GetCurrentListPosition(void *addonData, GUIHANDLE handle)
864 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
865 if (!helper || !handle)
868 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
871 int listPos = pAddonWindow->GetCurrentListPosition();
877 GUIHANDLE CAddonCallbacksGUI::Window_GetControl_Spin(void *addonData, GUIHANDLE handle, int controlId)
879 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
880 if (!helper || !handle)
883 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
884 CGUIControl* pGUIControl = (CGUIControl*)pAddonWindow->GetControl(controlId);
885 if (pGUIControl && pGUIControl->GetControlType() != CGUIControl::GUICONTROL_SPINEX)
891 GUIHANDLE CAddonCallbacksGUI::Window_GetControl_Button(void *addonData, GUIHANDLE handle, int controlId)
893 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
894 if (!helper || !handle)
897 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
898 CGUIControl* pGUIControl = (CGUIControl*)pAddonWindow->GetControl(controlId);
899 if (pGUIControl && pGUIControl->GetControlType() != CGUIControl::GUICONTROL_BUTTON)
905 GUIHANDLE CAddonCallbacksGUI::Window_GetControl_RadioButton(void *addonData, GUIHANDLE handle, int controlId)
907 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
908 if (!helper || !handle)
911 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
912 CGUIControl* pGUIControl = (CGUIControl*)pAddonWindow->GetControl(controlId);
913 if (pGUIControl && pGUIControl->GetControlType() != CGUIControl::GUICONTROL_RADIO)
919 GUIHANDLE CAddonCallbacksGUI::Window_GetControl_Edit(void *addonData, GUIHANDLE handle, int controlId)
921 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
922 if (!helper || !handle)
925 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
926 CGUIControl* pGUIControl = (CGUIControl*)pAddonWindow->GetControl(controlId);
927 if (pGUIControl && pGUIControl->GetControlType() != CGUIControl::GUICONTROL_EDIT)
933 GUIHANDLE CAddonCallbacksGUI::Window_GetControl_Progress(void *addonData, GUIHANDLE handle, int controlId)
935 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
936 if (!helper || !handle)
939 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
940 CGUIControl* pGUIControl = (CGUIControl*)pAddonWindow->GetControl(controlId);
941 if (pGUIControl && pGUIControl->GetControlType() != CGUIControl::GUICONTROL_PROGRESS)
947 GUIHANDLE CAddonCallbacksGUI::Window_GetControl_RenderAddon(void *addonData, GUIHANDLE handle, int controlId)
949 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
950 if (!helper || !handle)
953 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
954 CGUIControl* pGUIControl = (CGUIControl*)pAddonWindow->GetControl(controlId);
955 if (pGUIControl && pGUIControl->GetControlType() != CGUIControl::GUICONTROL_RENDERADDON)
958 CGUIAddonRenderingControl *pProxyControl;
959 pProxyControl = new CGUIAddonRenderingControl((CGUIRenderingControl*)pGUIControl);
960 return pProxyControl;
963 void CAddonCallbacksGUI::Window_SetControlLabel(void *addonData, GUIHANDLE handle, int controlId, const char *label)
965 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
966 if (!helper || !handle)
969 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
971 CGUIMessage msg(GUI_MSG_LABEL_SET, pAddonWindow->m_iWindowId, controlId);
973 pAddonWindow->OnMessage(msg);
976 void CAddonCallbacksGUI::Window_MarkDirtyRegion(void *addonData, GUIHANDLE handle)
978 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
979 if (!helper || !handle)
982 CGUIAddonWindow *pAddonWindow = (CGUIAddonWindow*)handle;
984 pAddonWindow->MarkDirtyRegion();
987 void CAddonCallbacksGUI::Control_Spin_SetVisible(void *addonData, GUIHANDLE spinhandle, bool yesNo)
989 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
990 if (!helper || !spinhandle)
993 CGUISpinControlEx *pSpin = (CGUISpinControlEx*)spinhandle;
994 pSpin->SetVisible(yesNo);
997 void CAddonCallbacksGUI::Control_Spin_SetText(void *addonData, GUIHANDLE spinhandle, const char *label)
999 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1000 if (!helper || !spinhandle)
1003 CGUISpinControlEx *pSpin = (CGUISpinControlEx*)spinhandle;
1004 pSpin->SetText(label);
1007 void CAddonCallbacksGUI::Control_Spin_Clear(void *addonData, GUIHANDLE spinhandle)
1009 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1010 if (!helper || !spinhandle)
1013 CGUISpinControlEx *pSpin = (CGUISpinControlEx*)spinhandle;
1017 void CAddonCallbacksGUI::Control_Spin_AddLabel(void *addonData, GUIHANDLE spinhandle, const char *label, int iValue)
1019 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1020 if (!helper || !spinhandle)
1023 CGUISpinControlEx *pSpin = (CGUISpinControlEx*)spinhandle;
1024 pSpin->AddLabel(label, iValue);
1027 int CAddonCallbacksGUI::Control_Spin_GetValue(void *addonData, GUIHANDLE spinhandle)
1029 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1030 if (!helper || !spinhandle)
1033 CGUISpinControlEx *pSpin = (CGUISpinControlEx*)spinhandle;
1034 return pSpin->GetValue();
1037 void CAddonCallbacksGUI::Control_Spin_SetValue(void *addonData, GUIHANDLE spinhandle, int iValue)
1039 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1040 if (!helper || !spinhandle)
1043 CGUISpinControlEx *pSpin = (CGUISpinControlEx*)spinhandle;
1044 pSpin->SetValue(iValue);
1047 void CAddonCallbacksGUI::Control_RadioButton_SetVisible(void *addonData, GUIHANDLE handle, bool yesNo)
1049 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1050 if (!helper || !handle)
1053 CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl*)handle;
1054 pRadioButton->SetVisible(yesNo);
1057 void CAddonCallbacksGUI::Control_RadioButton_SetText(void *addonData, GUIHANDLE handle, const char *label)
1059 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1060 if (!helper || !handle)
1063 CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl*)handle;
1064 pRadioButton->SetLabel(label);
1067 void CAddonCallbacksGUI::Control_RadioButton_SetSelected(void *addonData, GUIHANDLE handle, bool yesNo)
1069 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1070 if (!helper || !handle)
1073 CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl*)handle;
1074 pRadioButton->SetSelected(yesNo);
1077 bool CAddonCallbacksGUI::Control_RadioButton_IsSelected(void *addonData, GUIHANDLE handle)
1079 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1080 if (!helper || !handle)
1083 CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl*)handle;
1084 return pRadioButton->IsSelected();
1087 void CAddonCallbacksGUI::Control_Progress_SetPercentage(void *addonData, GUIHANDLE handle, float fPercent)
1089 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1090 if (!helper || !handle)
1093 CGUIProgressControl *pControl = (CGUIProgressControl*)handle;
1094 pControl->SetPercentage(fPercent);
1097 float CAddonCallbacksGUI::Control_Progress_GetPercentage(void *addonData, GUIHANDLE handle)
1099 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1100 if (!helper || !handle)
1103 CGUIProgressControl *pControl = (CGUIProgressControl*)handle;
1104 return pControl->GetPercentage();
1107 void CAddonCallbacksGUI::Control_Progress_SetInfo(void *addonData, GUIHANDLE handle, int iInfo)
1109 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1110 if (!helper || !handle)
1113 CGUIProgressControl *pControl = (CGUIProgressControl*)handle;
1114 pControl->SetInfo(iInfo);
1117 int CAddonCallbacksGUI::Control_Progress_GetInfo(void *addonData, GUIHANDLE handle)
1119 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1120 if (!helper || !handle)
1123 CGUIProgressControl *pControl = (CGUIProgressControl*)handle;
1124 return pControl->GetInfo();
1127 const char* CAddonCallbacksGUI::Control_Progress_GetDescription(void *addonData, GUIHANDLE handle)
1129 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1130 if (!helper || !handle)
1133 CGUIProgressControl *pControl = (CGUIProgressControl*)handle;
1134 CStdString string = pControl->GetDescription();
1136 char *buffer = (char*) malloc (string.length()+1);
1137 strcpy(buffer, string.c_str());
1141 GUIHANDLE CAddonCallbacksGUI::ListItem_Create(void *addonData, const char *label, const char *label2, const char *iconImage, const char *thumbnailImage, const char *path)
1143 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1148 CFileItem *pItem = new CFileItem();
1153 pItem->SetLabel(label);
1155 pItem->SetLabel2(label2);
1157 pItem->SetIconImage(iconImage);
1159 pItem->SetArt("thumb", thumbnailImage);
1161 pItem->SetPath(path);
1166 const char* CAddonCallbacksGUI::ListItem_GetLabel(void *addonData, GUIHANDLE handle)
1168 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1169 if (!helper || !handle)
1172 CStdString string = ((CFileItem*)handle)->GetLabel();
1173 char *buffer = (char*) malloc (string.length()+1);
1174 strcpy(buffer, string.c_str());
1178 void CAddonCallbacksGUI::ListItem_SetLabel(void *addonData, GUIHANDLE handle, const char *label)
1180 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1181 if (!helper || !handle)
1184 ((CFileItem*)handle)->SetLabel(label);
1187 const char* CAddonCallbacksGUI::ListItem_GetLabel2(void *addonData, GUIHANDLE handle)
1189 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1190 if (!helper || !handle)
1193 CStdString string = ((CFileItem*)handle)->GetLabel2();
1195 char *buffer = (char*) malloc (string.length()+1);
1196 strcpy(buffer, string.c_str());
1200 void CAddonCallbacksGUI::ListItem_SetLabel2(void *addonData, GUIHANDLE handle, const char *label)
1202 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1203 if (!helper || !handle)
1206 ((CFileItem*)handle)->SetLabel2(label);
1209 void CAddonCallbacksGUI::ListItem_SetIconImage(void *addonData, GUIHANDLE handle, const char *image)
1211 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1212 if (!helper || !handle)
1215 ((CFileItem*)handle)->SetIconImage(image);
1218 void CAddonCallbacksGUI::ListItem_SetThumbnailImage(void *addonData, GUIHANDLE handle, const char *image)
1220 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1221 if (!helper || !handle)
1224 ((CFileItem*)handle)->SetArt("thumb", image);
1227 void CAddonCallbacksGUI::ListItem_SetInfo(void *addonData, GUIHANDLE handle, const char *info)
1229 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1230 if (!helper || !handle)
1235 void CAddonCallbacksGUI::ListItem_SetProperty(void *addonData, GUIHANDLE handle, const char *key, const char *value)
1237 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1238 if (!helper || !handle)
1241 ((CFileItem*)handle)->SetProperty(key, value);
1244 const char* CAddonCallbacksGUI::ListItem_GetProperty(void *addonData, GUIHANDLE handle, const char *key)
1246 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1247 if (!helper || !handle)
1250 string string = ((CFileItem*)handle)->GetProperty(key).asString();
1251 char *buffer = (char*) malloc (string.length()+1);
1252 strcpy(buffer, string.c_str());
1256 void CAddonCallbacksGUI::ListItem_SetPath(void *addonData, GUIHANDLE handle, const char *path)
1258 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1259 if (!helper || !handle)
1262 ((CFileItem*)handle)->SetPath(path);
1265 void CAddonCallbacksGUI::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))
1267 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1268 if (!helper || !handle)
1271 CGUIAddonRenderingControl *pAddonControl = (CGUIAddonRenderingControl*)handle;
1274 pAddonControl->m_clientHandle = clienthandle;
1275 pAddonControl->CBCreate = createCB;
1276 pAddonControl->CBRender = renderCB;
1277 pAddonControl->CBStop = stopCB;
1278 pAddonControl->CBDirty = dirtyCB;
1281 pAddonControl->m_pControl->InitCallback(pAddonControl);
1284 void CAddonCallbacksGUI::RenderAddon_Delete(void *addonData, GUIHANDLE handle)
1286 CAddonCallbacks* helper = (CAddonCallbacks*) addonData;
1287 if (!helper || !handle)
1290 CGUIAddonRenderingControl *pAddonControl = (CGUIAddonRenderingControl*)handle;
1293 pAddonControl->Delete();
1299 CGUIAddonWindow::CGUIAddonWindow(int id, CStdString strXML, CAddon* addon)
1300 : CGUIMediaWindow(id, strXML)
1304 , m_bIsDialog(false)
1305 , m_actionEvent(true)
1308 m_loadType = LOAD_ON_GUI_INIT;
1315 CGUIAddonWindow::~CGUIAddonWindow(void)
1319 bool CGUIAddonWindow::OnAction(const CAction &action)
1321 // Let addon decide whether it wants to hande action first
1322 if (CBOnAction && CBOnAction(m_clientHandle, action.GetID()))
1325 return CGUIWindow::OnAction(action);
1328 bool CGUIAddonWindow::OnMessage(CGUIMessage& message)
1330 // TODO: We shouldn't be dropping down to CGUIWindow in any of this ideally.
1331 // We have to make up our minds about what python should be doing and
1332 // what this side of things should be doing
1333 switch (message.GetMessage())
1335 case GUI_MSG_WINDOW_DEINIT:
1337 return CGUIMediaWindow::OnMessage(message);
1341 case GUI_MSG_WINDOW_INIT:
1343 CGUIMediaWindow::OnMessage(message);
1345 CBOnInit(m_clientHandle);
1351 case GUI_MSG_SETFOCUS:
1353 if (m_viewControl.HasControl(message.GetControlId()) && m_viewControl.GetCurrentControl() != (int)message.GetControlId())
1355 m_viewControl.SetFocused();
1358 // check if our focused control is one of our category buttons
1359 int iControl = message.GetControlId();
1362 CBOnFocus(m_clientHandle, iControl);
1367 case GUI_MSG_FOCUSED:
1369 if (HasID(message.GetSenderId()) && CBOnFocus)
1371 CBOnFocus(m_clientHandle, message.GetControlId());
1376 case GUI_MSG_CLICKED:
1378 int iControl=message.GetSenderId();
1379 // Handle Sort/View internally. Scripters shouldn't use ID 2, 3 or 4.
1380 if (iControl == CONTROL_BTNSORTASC) // sort asc
1382 CLog::Log(LOGINFO, "WindowXML: Internal asc/dsc button not implemented");
1383 /*if (m_guiState.get())
1384 m_guiState->SetNextSortOrder();
1388 else if (iControl == CONTROL_BTNSORTBY) // sort by
1390 CLog::Log(LOGINFO, "WindowXML: Internal sort button not implemented");
1391 /*if (m_guiState.get())
1392 m_guiState->SetNextSortMethod();
1397 if (CBOnClick && iControl && iControl != (int)this->GetID())
1399 CGUIControl* controlClicked = (CGUIControl*)this->GetControl(iControl);
1401 // The old python way used to check list AND SELECITEM method or if its a button, checkmark.
1402 // Its done this way for now to allow other controls without a python version like togglebutton to still raise a onAction event
1403 if (controlClicked) // Will get problems if we the id is not on the window and we try to do GetControlType on it. So check to make sure it exists
1405 if ((controlClicked->IsContainer() && (message.GetParam1() == ACTION_SELECT_ITEM ||
1406 message.GetParam1() == ACTION_MOUSE_LEFT_CLICK)) ||
1407 !controlClicked->IsContainer())
1409 if (CBOnClick(m_clientHandle, iControl))
1412 else if (controlClicked->IsContainer() && message.GetParam1() == ACTION_MOUSE_RIGHT_CLICK)
1414 // PyXBMCAction* inf = new PyXBMCAction;
1415 // inf->pObject = Action_FromAction(CAction(ACTION_CONTEXT_MENU));
1416 // inf->pCallbackWindow = pCallbackWindow;
1419 // PyXBMC_AddPendingCall(Py_XBMC_Event_OnAction, inf);
1420 // PulseActionEvent();
1428 return CGUIMediaWindow::OnMessage(message);
1431 void CGUIAddonWindow::AllocResources(bool forceLoad /*= FALSE */)
1433 CStdString tmpDir = URIUtils::GetDirectory(GetProperty("xmlfile").asString());
1434 CStdString fallbackMediaPath;
1435 URIUtils::GetParentPath(tmpDir, fallbackMediaPath);
1436 URIUtils::RemoveSlashAtEnd(fallbackMediaPath);
1437 m_mediaDir = fallbackMediaPath;
1439 //CLog::Log(LOGDEBUG, "CGUIPythonWindowXML::AllocResources called: %s", fallbackMediaPath.c_str());
1440 g_TextureManager.AddTexturePath(m_mediaDir);
1441 CGUIMediaWindow::AllocResources(forceLoad);
1442 g_TextureManager.RemoveTexturePath(m_mediaDir);
1445 void CGUIAddonWindow::FreeResources(bool forceUnLoad /*= FALSE */)
1447 CGUIMediaWindow::FreeResources(forceUnLoad);
1450 void CGUIAddonWindow::Render()
1452 g_TextureManager.AddTexturePath(m_mediaDir);
1453 CGUIMediaWindow::Render();
1454 g_TextureManager.RemoveTexturePath(m_mediaDir);
1457 void CGUIAddonWindow::Update()
1461 void CGUIAddonWindow::AddItem(CFileItemPtr fileItem, int itemPosition)
1463 if (itemPosition == -1 || itemPosition > m_vecItems->Size())
1465 m_vecItems->Add(fileItem);
1467 else if (itemPosition < -1 && !(itemPosition-1 < m_vecItems->Size()))
1469 m_vecItems->AddFront(fileItem,0);
1473 m_vecItems->AddFront(fileItem,itemPosition);
1475 m_viewControl.SetItems(*m_vecItems);
1479 void CGUIAddonWindow::RemoveItem(int itemPosition)
1481 m_vecItems->Remove(itemPosition);
1482 m_viewControl.SetItems(*m_vecItems);
1486 int CGUIAddonWindow::GetCurrentListPosition()
1488 return m_viewControl.GetSelectedItem();
1491 void CGUIAddonWindow::SetCurrentListPosition(int item)
1493 m_viewControl.SetSelectedItem(item);
1496 int CGUIAddonWindow::GetListSize()
1498 return m_vecItems->Size();
1501 CFileItemPtr CGUIAddonWindow::GetListItem(int position)
1503 if (position < 0 || position >= m_vecItems->Size()) return CFileItemPtr();
1504 return m_vecItems->Get(position);
1507 void CGUIAddonWindow::ClearList()
1511 m_viewControl.SetItems(*m_vecItems);
1515 void CGUIAddonWindow::GetContextButtons(int itemNumber, CContextButtons &buttons)
1517 // maybe on day we can make an easy way to do this context menu
1518 // with out this method overriding the MediaWindow version, it will display 'Add to Favorites'
1521 void CGUIAddonWindow::WaitForActionEvent(unsigned int timeout)
1523 m_actionEvent.WaitMSec(timeout);
1524 m_actionEvent.Reset();
1527 void CGUIAddonWindow::PulseActionEvent()
1529 m_actionEvent.Set();
1532 bool CGUIAddonWindow::OnClick(int iItem)
1534 // Hook Over calling CGUIMediaWindow::OnClick(iItem) results in it trying to PLAY the file item
1535 // which if its not media is BAD and 99 out of 100 times undesireable.
1541 CGUIMediaWindow::OnWindowLoaded() calls SetupShares() so override it
1542 and just call UpdateButtons();
1544 void CGUIAddonWindow::SetupShares()
1550 CGUIAddonWindowDialog::CGUIAddonWindowDialog(int id, CStdString strXML, CAddon* addon)
1551 : CGUIAddonWindow(id,strXML,addon)
1557 CGUIAddonWindowDialog::~CGUIAddonWindowDialog(void)
1561 bool CGUIAddonWindowDialog::OnMessage(CGUIMessage &message)
1563 if (message.GetMessage() == GUI_MSG_WINDOW_DEINIT)
1565 CGUIWindow *pWindow = g_windowManager.GetWindow(g_windowManager.GetActiveWindow());
1567 g_windowManager.ShowOverlay(pWindow->GetOverlayState());
1568 return CGUIWindow::OnMessage(message);
1570 return CGUIAddonWindow::OnMessage(message);
1573 void CGUIAddonWindowDialog::Show(bool show /* = true */)
1575 unsigned int iCount = g_graphicsContext.exit();
1576 ThreadMessage tMsg = {TMSG_GUI_ADDON_DIALOG, 1, show ? 1u : 0u};
1578 CApplicationMessenger::Get().SendMessage(tMsg, true);
1579 g_graphicsContext.restore(iCount);
1582 void CGUIAddonWindowDialog::Show_Internal(bool show /* = true */)
1588 g_windowManager.RouteToWindow(this);
1590 // active this window...
1591 CGUIMessage msg(GUI_MSG_WINDOW_INIT, 0, 0, WINDOW_INVALID, m_iWindowId);
1594 while (m_bRunning && !g_application.m_bStop)
1596 g_windowManager.ProcessRenderLoop();
1603 CGUIMessage msg(GUI_MSG_WINDOW_DEINIT,0,0);
1606 g_windowManager.RemoveDialog(GetID());
1610 CGUIAddonRenderingControl::CGUIAddonRenderingControl(CGUIRenderingControl *pControl)
1612 m_pControl = pControl;
1616 bool CGUIAddonRenderingControl::Create(int x, int y, int w, int h, void *device)
1620 if (CBCreate(m_clientHandle, x, y, w, h, device))
1629 void CGUIAddonRenderingControl::Render()
1633 g_graphicsContext.BeginPaint();
1634 CBRender(m_clientHandle);
1635 g_graphicsContext.EndPaint();
1639 void CGUIAddonRenderingControl::Stop()
1643 CBStop(m_clientHandle);
1646 if (m_refCount <= 0)
1650 void CGUIAddonRenderingControl::Delete()
1653 if (m_refCount <= 0)
1657 bool CGUIAddonRenderingControl::IsDirty()
1662 ret = CBDirty(m_clientHandle);
1667 }; /* namespace ADDON */