2 * Copyright (C) 2005-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/>.
22 #include "LanguageHook.h"
23 #include "AddonUtils.h"
25 #include "guilib/GUILabel.h"
26 #include "guilib/GUIFontManager.h"
27 #include "guilib/GUILabelControl.h"
28 #include "guilib/GUIFadeLabelControl.h"
29 #include "guilib/GUITextBox.h"
30 #include "guilib/GUIButtonControl.h"
31 #include "guilib/GUICheckMarkControl.h"
32 #include "guilib/GUIImage.h"
33 #include "guilib/GUIListContainer.h"
34 #include "guilib/GUIProgressControl.h"
35 #include "guilib/GUISliderControl.h"
36 #include "guilib/GUIRadioButtonControl.h"
37 #include "GUIInfoManager.h"
38 #include "guilib/GUIWindowManager.h"
39 #include "guilib/GUIEditControl.h"
40 #include "guilib/GUIControlFactory.h"
41 #include "listproviders/StaticProvider.h"
43 #include "utils/XBMCTinyXML.h"
44 #include "utils/StringUtils.h"
51 // ============================================================
53 // ============================================================
54 // ============================================================
55 ControlFadeLabel::ControlFadeLabel(long x, long y, long width, long height,
56 const char* font, const char* _textColor,
58 strFont("font13"), textColor(0xffffffff), align(_alignment)
69 sscanf(_textColor, "%x", &textColor);
74 void ControlFadeLabel::addLabel(const String& label) throw (UnimplementedException)
76 CGUIMessage msg(GUI_MSG_LABEL_ADD, iParentId, iControlId);
79 g_windowManager.SendThreadMessage(msg, iParentId);
82 void ControlFadeLabel::reset() throw (UnimplementedException)
84 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
87 g_windowManager.SendThreadMessage(msg, iParentId);
90 CGUIControl* ControlFadeLabel::Create() throw (WindowException)
93 label.font = g_fontManager.GetFont(strFont);
94 label.textColor = label.focusedColor = textColor;
96 pGUIControl = new CGUIFadeLabelControl(
108 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
109 pGUIControl->OnMessage(msg);
114 // ============================================================
116 // ============================================================
117 // ============================================================
118 ControlTextBox::ControlTextBox(long x, long y, long width, long height,
119 const char* font, const char* _textColor) :
120 strFont("font13"), textColor(0xffffffff)
131 sscanf(_textColor, "%x", &textColor);
134 void ControlTextBox::setText(const String& text) throw(UnimplementedException)
137 CGUIMessage msg(GUI_MSG_LABEL_SET, iParentId, iControlId);
141 g_windowManager.SendThreadMessage(msg, iParentId);
144 void ControlTextBox::reset() throw(UnimplementedException)
147 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
148 g_windowManager.SendThreadMessage(msg, iParentId);
151 void ControlTextBox::scroll(long position) throw(UnimplementedException)
153 static_cast<CGUITextBox*>(pGUIControl)->Scroll((int)position);
156 CGUIControl* ControlTextBox::Create() throw (WindowException)
160 label.font = g_fontManager.GetFont(strFont);
161 label.textColor = label.focusedColor = textColor;
163 pGUIControl = new CGUITextBox(iParentId, iControlId,
164 (float)dwPosX, (float)dwPosY, (float)dwWidth, (float)dwHeight,
168 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
169 pGUIControl->OnMessage(msg);
174 // ============================================================
176 // ============================================================
177 // ============================================================
178 ControlButton::ControlButton(long x, long y, long width, long height, const String& label,
179 const char* focusTexture, const char* noFocusTexture,
180 long _textOffsetX, long _textOffsetY,
181 long alignment, const char* font, const char* _textColor,
182 const char* _disabledColor, long angle,
183 const char* _shadowColor, const char* _focusedColor) :
184 textOffsetX(_textOffsetX), textOffsetY(_textOffsetY),
185 align(alignment), strFont("font13"), textColor(0xffffffff), disabledColor(0x60ffffff),
186 iAngle(angle), shadowColor(0), focusedColor(0xffffffff)
195 // if texture is supplied use it, else get default ones
196 strTextureFocus = focusTexture ? focusTexture :
197 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturefocus", (char*)"button-focus.png");
198 strTextureNoFocus = noFocusTexture ? noFocusTexture :
199 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturenofocus", (char*)"button-nofocus.jpg");
201 if (font) strFont = font;
202 if (_textColor) sscanf( _textColor, "%x", &textColor );
203 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
204 if (_shadowColor) sscanf( _shadowColor, "%x", &shadowColor );
205 if (_focusedColor) sscanf( _focusedColor, "%x", &focusedColor );
208 void ControlButton::setLabel(const String& label,
210 const char* _textColor,
211 const char* _disabledColor,
212 const char* _shadowColor,
213 const char* _focusedColor,
214 const String& label2) throw (UnimplementedException)
216 if (!label.empty()) strText = label;
217 if (!label2.empty()) strText2 = label2;
218 if (font) strFont = font;
219 if (_textColor) sscanf(_textColor, "%x", &textColor);
220 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
221 if (_shadowColor) sscanf(_shadowColor, "%x", &shadowColor);
222 if (_focusedColor) sscanf(_focusedColor, "%x", &focusedColor);
227 ((CGUIButtonControl*)pGUIControl)->PythonSetLabel(strFont, strText, textColor, shadowColor, focusedColor);
228 ((CGUIButtonControl*)pGUIControl)->SetLabel2(strText2);
229 ((CGUIButtonControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
233 void ControlButton::setDisabledColor(const char* color) throw (UnimplementedException)
235 if (color) sscanf(color, "%x", &disabledColor);
240 ((CGUIButtonControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
244 String ControlButton::getLabel() throw (UnimplementedException)
246 if (!pGUIControl) return NULL;
249 return ((CGUIButtonControl*) pGUIControl)->GetLabel();
252 String ControlButton::getLabel2() throw (UnimplementedException)
254 if (!pGUIControl) return NULL;
257 return ((CGUIButtonControl*) pGUIControl)->GetLabel2();
260 CGUIControl* ControlButton::Create() throw (WindowException)
263 label.font = g_fontManager.GetFont(strFont);
264 label.textColor = textColor;
265 label.disabledColor = disabledColor;
266 label.shadowColor = shadowColor;
267 label.focusedColor = focusedColor;
269 label.offsetX = (float)textOffsetX;
270 label.offsetY = (float)textOffsetY;
271 label.angle = (float)-iAngle;
272 pGUIControl = new CGUIButtonControl(
279 (CStdString)strTextureFocus,
280 (CStdString)strTextureNoFocus,
283 CGUIButtonControl* pGuiButtonControl =
284 (CGUIButtonControl*)pGUIControl;
286 pGuiButtonControl->SetLabel(strText);
287 pGuiButtonControl->SetLabel2(strText2);
292 // ============================================================
294 // ============================================================
295 // ============================================================
296 ControlCheckMark::ControlCheckMark(long x, long y, long width, long height, const String& label,
297 const char* focusTexture, const char* noFocusTexture,
298 long _checkWidth, long _checkHeight,
299 long _alignment, const char* font,
300 const char* _textColor, const char* _disabledColor) :
301 strFont("font13"), checkWidth(_checkWidth), checkHeight(_checkHeight),
302 align(_alignment), textColor(0xffffffff), disabledColor(0x60ffffff)
310 if (font) strFont = font;
311 if (_textColor) sscanf(_textColor, "%x", &textColor);
312 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
314 strTextureFocus = focusTexture ? focusTexture :
315 XBMCAddonUtils::getDefaultImage((char*)"checkmark", (char*)"texturefocus", (char*)"check-box.png");
316 strTextureNoFocus = noFocusTexture ? noFocusTexture :
317 XBMCAddonUtils::getDefaultImage((char*)"checkmark", (char*)"texturenofocus", (char*)"check-boxNF.png");
320 bool ControlCheckMark::getSelected() throw (UnimplementedException)
322 bool isSelected = false;
327 isSelected = ((CGUICheckMarkControl*)pGUIControl)->GetSelected();
333 void ControlCheckMark::setSelected(bool selected) throw (UnimplementedException)
338 ((CGUICheckMarkControl*)pGUIControl)->SetSelected(selected);
342 void ControlCheckMark::setLabel(const String& label,
344 const char* _textColor,
345 const char* _disabledColor,
346 const char* _shadowColor,
347 const char* _focusedColor,
348 const String& label2) throw (UnimplementedException)
351 if (font) strFont = font;
352 if (_textColor) sscanf(_textColor, "%x", &textColor);
353 if (_disabledColor) sscanf(_disabledColor, "%x", &disabledColor);
358 ((CGUICheckMarkControl*)pGUIControl)->PythonSetLabel(strFont,strText,textColor);
359 ((CGUICheckMarkControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
363 void ControlCheckMark::setDisabledColor(const char* color) throw (UnimplementedException)
365 if (color) sscanf(color, "%x", &disabledColor);
370 ((CGUICheckMarkControl*)pGUIControl)->PythonSetDisabledColor( disabledColor );
374 CGUIControl* ControlCheckMark::Create() throw (WindowException)
377 label.disabledColor = disabledColor;
378 label.textColor = label.focusedColor = textColor;
379 label.font = g_fontManager.GetFont(strFont);
381 CTextureInfo imageFocus(strTextureFocus);
382 CTextureInfo imageNoFocus(strTextureNoFocus);
383 pGUIControl = new CGUICheckMarkControl(
390 imageFocus, imageNoFocus,
395 CGUICheckMarkControl* pGuiCheckMarkControl = (CGUICheckMarkControl*)pGUIControl;
396 pGuiCheckMarkControl->SetLabel(strText);
401 // ============================================================
403 // ============================================================
404 // ============================================================
405 ControlImage::ControlImage(long x, long y, long width, long height,
406 const char* filename, long aspectRatio,
407 const char* _colorDiffuse):
415 // check if filename exists
416 strFileName = filename;
418 sscanf(_colorDiffuse, "%x", &colorDiffuse);
421 void ControlImage::setImage(const char* imageFilename, const bool useCache) throw (UnimplementedException)
423 strFileName = imageFilename;
427 ((CGUIImage*)pGUIControl)->SetFileName(strFileName, false, useCache);
430 void ControlImage::setColorDiffuse(const char* cColorDiffuse) throw (UnimplementedException)
432 if (cColorDiffuse) sscanf(cColorDiffuse, "%x", &colorDiffuse);
433 else colorDiffuse = 0;
437 ((CGUIImage *)pGUIControl)->SetColorDiffuse(colorDiffuse);
440 CGUIControl* ControlImage::Create() throw (WindowException)
442 pGUIControl = new CGUIImage(iParentId, iControlId,
443 (float)dwPosX, (float)dwPosY, (float)dwWidth, (float)dwHeight,
444 (CStdString)strFileName);
446 if (pGUIControl && aspectRatio <= CAspectRatio::AR_KEEP)
447 ((CGUIImage *)pGUIControl)->SetAspectRatio((CAspectRatio::ASPECT_RATIO)aspectRatio);
449 if (pGUIControl && colorDiffuse)
450 ((CGUIImage *)pGUIControl)->SetColorDiffuse(colorDiffuse);
455 // ============================================================
457 // ============================================================
458 // ============================================================
459 ControlProgress::ControlProgress(long x, long y, long width, long height,
460 const char* texturebg,
461 const char* textureleft,
462 const char* texturemid,
463 const char* textureright,
464 const char* textureoverlay)
471 // if texture is supplied use it, else get default ones
472 strTextureBg = texturebg ? texturebg :
473 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"texturebg", (char*)"progress_back.png");
474 strTextureLeft = textureleft ? textureleft :
475 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"lefttexture", (char*)"progress_left.png");
476 strTextureMid = texturemid ? texturemid :
477 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"midtexture", (char*)"progress_mid.png");
478 strTextureRight = textureright ? textureright :
479 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"righttexture", (char*)"progress_right.png");
480 strTextureOverlay = textureoverlay ? textureoverlay :
481 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"overlaytexture", (char*)"progress_over.png");
484 void ControlProgress::setPercent(float pct) throw (UnimplementedException)
487 ((CGUIProgressControl*)pGUIControl)->SetPercentage(pct);
490 float ControlProgress::getPercent() throw (UnimplementedException)
492 return (pGUIControl) ? ((CGUIProgressControl*)pGUIControl)->GetPercentage() : 0.0f;
495 CGUIControl* ControlProgress::Create() throw (WindowException)
497 pGUIControl = new CGUIProgressControl(iParentId, iControlId,
498 (float)dwPosX, (float)dwPosY,
499 (float)dwWidth,(float)dwHeight,
500 (CStdString)strTextureBg,(CStdString)strTextureLeft,
501 (CStdString)strTextureMid,(CStdString)strTextureRight,
502 (CStdString)strTextureOverlay);
504 if (pGUIControl && colorDiffuse)
505 ((CGUIProgressControl *)pGUIControl)->SetColorDiffuse(colorDiffuse);
510 // ============================================================
512 // ============================================================
513 // ============================================================
514 ControlSlider::ControlSlider(long x, long y, long width, long height,
515 const char* textureback,
517 const char* texturefocus)
524 // if texture is supplied use it, else get default ones
525 strTextureBack = textureback ? textureback :
526 XBMCAddonUtils::getDefaultImage((char*)"slider", (char*)"texturesliderbar", (char*)"osd_slider_bg_2.png");
527 strTexture = texture ? texture :
528 XBMCAddonUtils::getDefaultImage((char*)"slider", (char*)"textureslidernib", (char*)"osd_slider_nibNF.png");
529 strTextureFoc = texturefocus ? texturefocus :
530 XBMCAddonUtils::getDefaultImage((char*)"slider", (char*)"textureslidernibfocus", (char*)"osd_slider_nib.png");
533 float ControlSlider::getPercent() throw (UnimplementedException)
535 return (pGUIControl) ? ((CGUISliderControl*)pGUIControl)->GetPercentage() : 0.0f;
538 void ControlSlider::setPercent(float pct) throw (UnimplementedException)
541 ((CGUISliderControl*)pGUIControl)->SetPercentage(pct);
544 CGUIControl* ControlSlider::Create () throw (WindowException)
546 pGUIControl = new CGUISliderControl(iParentId, iControlId,(float)dwPosX, (float)dwPosY,
547 (float)dwWidth,(float)dwHeight,
548 (CStdString)strTextureBack,(CStdString)strTexture,
549 (CStdString)strTextureFoc,0);
554 // ============================================================
556 // ============================================================
557 // ============================================================
558 ControlGroup::ControlGroup(long x, long y, long width, long height)
566 CGUIControl* ControlGroup::Create() throw (WindowException)
568 pGUIControl = new CGUIControlGroup(iParentId,
577 // ============================================================
579 // ============================================================
580 // ============================================================
581 ControlRadioButton::ControlRadioButton(long x, long y, long width, long height, const String& label,
582 const char* focusOnTexture, const char* noFocusOnTexture,
583 const char* focusOffTexture, const char* noFocusOffTexture,
584 const char* focusTexture, const char* noFocusTexture,
585 long _textOffsetX, long _textOffsetY,
586 long alignment, const char* font, const char* _textColor,
587 const char* _disabledColor, long angle,
588 const char* _shadowColor, const char* _focusedColor,
589 const char* TextureRadioFocus, const char* TextureRadioNoFocus) :
590 strFont("font13"), textColor(0xffffffff), disabledColor(0x60ffffff),
591 textOffsetX(_textOffsetX), textOffsetY(_textOffsetY), align(alignment), iAngle(angle),
592 shadowColor(0), focusedColor(0xffffffff)
601 // if texture is supplied use it, else get default ones
602 strTextureFocus = focusTexture ? focusTexture :
603 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturefocus", (char*)"button-focus.png");
604 strTextureNoFocus = noFocusTexture ? noFocusTexture :
605 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturenofocus", (char*)"button-nofocus.jpg");
607 if (focusOnTexture && noFocusOnTexture)
609 strTextureRadioOnFocus = focusOnTexture;
610 strTextureRadioOnNoFocus = noFocusOnTexture;
614 strTextureRadioOnFocus = strTextureRadioOnNoFocus = focusTexture ? focusTexture :
615 XBMCAddonUtils::getDefaultImage((char*)"radiobutton", (char*)"textureradiofocus", (char*)"radiobutton-focus.png");
618 if (focusOffTexture && noFocusOffTexture)
620 strTextureRadioOffFocus = focusOffTexture;
621 strTextureRadioOffNoFocus = noFocusOffTexture;
625 strTextureRadioOffFocus = strTextureRadioOffNoFocus = noFocusTexture ? noFocusTexture :
626 XBMCAddonUtils::getDefaultImage((char*)"radiobutton", (char*)"textureradiofocus", (char*)"radiobutton-focus.png");
629 if (font) strFont = font;
630 if (_textColor) sscanf( _textColor, "%x", &textColor );
631 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
632 if (_shadowColor) sscanf( _shadowColor, "%x", &shadowColor );
633 if (_focusedColor) sscanf( _focusedColor, "%x", &focusedColor );
636 void ControlRadioButton::setSelected(bool selected) throw (UnimplementedException)
641 ((CGUIRadioButtonControl*)pGUIControl)->SetSelected(selected);
645 bool ControlRadioButton::isSelected() throw (UnimplementedException)
647 bool isSelected = false;
652 isSelected = ((CGUIRadioButtonControl*)pGUIControl)->IsSelected();
657 void ControlRadioButton::setLabel(const String& label,
659 const char* _textColor,
660 const char* _disabledColor,
661 const char* _shadowColor,
662 const char* _focusedColor,
663 const String& label2) throw (UnimplementedException)
665 if (!label.empty()) strText = label;
666 if (font) strFont = font;
667 if (_textColor) sscanf(_textColor, "%x", &textColor);
668 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
669 if (_shadowColor) sscanf(_shadowColor, "%x", &shadowColor);
670 if (_focusedColor) sscanf(_focusedColor, "%x", &focusedColor);
675 ((CGUIRadioButtonControl*)pGUIControl)->PythonSetLabel(strFont, strText, textColor, shadowColor, focusedColor);
676 ((CGUIRadioButtonControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
680 void ControlRadioButton::setRadioDimension(long x, long y, long width, long height)
681 throw (UnimplementedException)
690 ((CGUIRadioButtonControl*)pGUIControl)->SetRadioDimensions((float)dwPosX, (float)dwPosY, (float)dwWidth, (float)dwHeight);
694 CGUIControl* ControlRadioButton::Create() throw (WindowException)
697 label.font = g_fontManager.GetFont(strFont);
698 label.textColor = textColor;
699 label.disabledColor = disabledColor;
700 label.shadowColor = shadowColor;
701 label.focusedColor = focusedColor;
703 label.offsetX = (float)textOffsetX;
704 label.offsetY = (float)textOffsetY;
705 label.angle = (float)-iAngle;
706 pGUIControl = new CGUIRadioButtonControl(
713 (CStdString)strTextureFocus,
714 (CStdString)strTextureNoFocus,
716 (CStdString)strTextureRadioOnFocus,
717 (CStdString)strTextureRadioOnNoFocus,
718 (CStdString)strTextureRadioOffFocus,
719 (CStdString)strTextureRadioOffNoFocus);
721 CGUIRadioButtonControl* pGuiButtonControl =
722 (CGUIRadioButtonControl*)pGUIControl;
724 pGuiButtonControl->SetLabel(strText);
729 // ============================================================
731 // ============================================================
732 // ============================================================
733 Control::~Control() { deallocating(); }
735 CGUIControl* Control::Create() throw (WindowException)
737 throw WindowException("Object is a Control, but can't be added to a window");
740 std::vector<int> Control::getPosition()
742 std::vector<int> ret(2);
748 void Control::setEnabled(bool enabled)
750 DelayedCallGuard dcguard(languageHook);
753 pGUIControl->SetEnabled(enabled);
756 void Control::setVisible(bool visible)
758 DelayedCallGuard dcguard(languageHook);
761 pGUIControl->SetVisible(visible);
764 void Control::setVisibleCondition(const char* visible, bool allowHiddenFocus)
766 DelayedCallGuard dcguard(languageHook);
770 pGUIControl->SetVisibleCondition(visible, allowHiddenFocus ? "true" : "false");
773 void Control::setEnableCondition(const char* enable)
775 DelayedCallGuard dcguard(languageHook);
779 pGUIControl->SetEnableCondition(enable);
782 void Control::setAnimations(const std::vector< Tuple<String,String> >& eventAttr) throw (WindowException)
785 TiXmlElement xmlRootElement("control");
786 TiXmlNode *pRoot = xmlDoc.InsertEndChild(xmlRootElement);
788 throw WindowException("TiXmlNode creation error");
790 std::vector<CAnimation> animations;
792 for (unsigned int anim = 0; anim < eventAttr.size(); anim++)
794 const Tuple<String,String>& pTuple = eventAttr[anim];
796 if (pTuple.GetNumValuesSet() != 2)
797 throw WindowException("Error unpacking tuple found in list");
799 const String& cEvent = pTuple.first();
800 const String& cAttr = pTuple.second();
802 TiXmlElement pNode("animation");
803 CStdStringArray attrs;
804 StringUtils::SplitString(cAttr.c_str(), " ", attrs);
805 for (unsigned int i = 0; i < attrs.size(); i++)
807 CStdStringArray attrs2;
808 StringUtils::SplitString(attrs[i], "=", attrs2);
809 if (attrs2.size() == 2)
810 pNode.SetAttribute(attrs2[0], attrs2[1]);
812 TiXmlText value(cEvent.c_str());
813 pNode.InsertEndChild(value);
814 pRoot->InsertEndChild(pNode);
817 const CRect animRect((float)dwPosX, (float)dwPosY, (float)dwPosX + dwWidth, (float)dwPosY + dwHeight);
821 CGUIControlFactory::GetAnimations(pRoot, animRect, iParentId, animations);
822 pGUIControl->SetAnimations(animations);
826 void Control::setPosition(long x, long y)
828 DelayedCallGuard dcguard(languageHook);
833 pGUIControl->SetPosition((float)dwPosX, (float)dwPosY);
836 void Control::setWidth(long width)
838 DelayedCallGuard dcguard(languageHook);
842 pGUIControl->SetWidth((float)dwWidth);
845 void Control::setHeight(long height)
847 DelayedCallGuard dcguard(languageHook);
851 pGUIControl->SetHeight((float)dwHeight);
854 void Control::setNavigation(const Control* up, const Control* down,
855 const Control* left, const Control* right)
856 throw (WindowException)
859 throw WindowException("Control has to be added to a window first");
861 iControlUp = up->iControlId;
862 iControlDown = down->iControlId;
863 iControlLeft = left->iControlId;
864 iControlRight = right->iControlId;
869 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
873 void Control::controlUp(const Control* control) throw (WindowException)
876 throw WindowException("Control has to be added to a window first");
878 iControlUp = control->iControlId;
882 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
886 void Control::controlDown(const Control* control) throw (WindowException)
889 throw WindowException("Control has to be added to a window first");
891 iControlDown = control->iControlId;
895 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
899 void Control::controlLeft(const Control* control) throw (WindowException)
902 throw WindowException("Control has to be added to a window first");
904 iControlLeft = control->iControlId;
908 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
912 void Control::controlRight(const Control* control) throw (WindowException)
915 throw WindowException("Control has to be added to a window first");
917 iControlRight = control->iControlId;
921 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
925 // ============================================================
927 // ============================================================
928 ControlSpin::ControlSpin()
930 // default values for spin control
937 // get default images
938 strTextureUp = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"textureup", (char*)"scroll-up.png");
939 strTextureDown = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturedown", (char*)"scroll-down.png");
940 strTextureUpFocus = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"textureupfocus", (char*)"scroll-up-focus.png");
941 strTextureDownFocus = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturedownfocus", (char*)"scroll-down-focus.png");
944 void ControlSpin::setTextures(const char* up, const char* down,
946 const char* downFocus) throw(UnimplementedException)
949 strTextureDown = down;
950 strTextureUpFocus = upFocus;
951 strTextureDownFocus = downFocus;
954 if (self->pGUIControl)
956 CGUISpinControl* pControl = (CGUISpinControl*)self->pGUIControl;
962 ControlSpin::~ControlSpin() {}
963 // ============================================================
965 // ============================================================
967 // ============================================================
968 ControlLabel::ControlLabel(long x, long y, long width, long height,
970 const char* font, const char* p_textColor,
971 const char* p_disabledColor,
973 bool hasPath, long angle) :
975 textColor(0xffffffff), disabledColor(0x60ffffff),
976 align(p_alignment), bHasPath(hasPath), iAngle(angle)
988 sscanf(p_textColor, "%x", &textColor);
991 sscanf( p_disabledColor, "%x", &disabledColor );
994 ControlLabel::~ControlLabel() {}
996 CGUIControl* ControlLabel::Create() throw (WindowException)
999 label.font = g_fontManager.GetFont(strFont);
1000 label.textColor = label.focusedColor = textColor;
1001 label.disabledColor = disabledColor;
1002 label.align = align;
1003 label.angle = (float)-iAngle;
1004 pGUIControl = new CGUILabelControl(
1014 ((CGUILabelControl *)pGUIControl)->SetLabel(strText);
1018 void ControlLabel::setLabel(const String& label, const char* font,
1019 const char* textColor, const char* disabledColor,
1020 const char* shadowColor, const char* focusedColor,
1021 const String& label2) throw(UnimplementedException)
1024 CGUIMessage msg(GUI_MSG_LABEL_SET, iParentId, iControlId);
1025 msg.SetLabel(strText);
1026 g_windowManager.SendThreadMessage(msg, iParentId);
1029 String ControlLabel::getLabel() throw(UnimplementedException)
1035 // ============================================================
1037 // ============================================================
1039 // ============================================================
1040 ControlEdit::ControlEdit(long x, long y, long width, long height, const String& label,
1041 const char* font, const char* _textColor,
1042 const char* _disabledColor,
1043 long _alignment, const char* focusTexture,
1044 const char* noFocusTexture, bool isPassword) :
1045 strFont("font13"), textColor(0xffffffff), disabledColor(0x60ffffff),
1046 align(_alignment), bIsPassword(isPassword)
1049 strTextureFocus = focusTexture ? focusTexture :
1050 XBMCAddonUtils::getDefaultImage((char*)"edit", (char*)"texturefocus", (char*)"button-focus.png");
1052 strTextureNoFocus = noFocusTexture ? noFocusTexture :
1053 XBMCAddonUtils::getDefaultImage((char*)"edit", (char*)"texturenofocus", (char*)"button-focus.png");
1055 if (font) strFont = font;
1056 if (_textColor) sscanf( _textColor, "%x", &textColor );
1057 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
1060 CGUIControl* ControlEdit::Create() throw (WindowException)
1063 label.font = g_fontManager.GetFont(strFont);
1064 label.textColor = label.focusedColor = textColor;
1065 label.disabledColor = disabledColor;
1066 label.align = align;
1067 pGUIControl = new CGUIEditControl(
1074 (CStdString)strTextureFocus,
1075 (CStdString)strTextureNoFocus,
1080 ((CGUIEditControl *) pGUIControl)->SetInputType(CGUIEditControl::INPUT_TYPE_PASSWORD, 0);
1084 void ControlEdit::setLabel(const String& label, const char* font,
1085 const char* textColor, const char* disabledColor,
1086 const char* shadowColor, const char* focusedColor,
1087 const String& label2) throw(UnimplementedException)
1090 CGUIMessage msg(GUI_MSG_LABEL_SET, iParentId, iControlId);
1091 msg.SetLabel(strText);
1092 g_windowManager.SendThreadMessage(msg, iParentId);
1095 String ControlEdit::getLabel() throw(UnimplementedException)
1102 void ControlEdit::setText(const String& text) throw(UnimplementedException)
1105 CGUIMessage msg(GUI_MSG_LABEL2_SET, iParentId, iControlId);
1109 g_windowManager.SendThreadMessage(msg, iParentId);
1112 String ControlEdit::getText() throw(UnimplementedException)
1114 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, iParentId, iControlId);
1115 g_windowManager.SendMessage(msg, iParentId);
1117 return msg.GetLabel();
1120 // ============================================================
1122 // ============================================================
1123 ControlList::ControlList(long x, long y, long width, long height, const char* font,
1124 const char* ctextColor, const char* cbuttonTexture,
1125 const char* cbuttonFocusTexture,
1126 const char* cselectedColor,
1127 long _imageWidth, long _imageHeight, long _itemTextXOffset,
1128 long _itemTextYOffset, long _itemHeight, long _space, long _alignmentY) :
1130 textColor(0xe0f0f0f0), selectedColor(0xffffffff),
1131 imageHeight(_imageHeight), imageWidth(_imageWidth),
1132 itemHeight(_itemHeight), space(_space),
1133 itemTextOffsetX(_itemTextXOffset),itemTextOffsetY(_itemTextYOffset),
1134 alignmentY(_alignmentY)
1141 // create a python spin control
1142 pControlSpin = new ControlSpin();
1144 // initialize default values
1149 sscanf( ctextColor, "%x", &textColor );
1152 sscanf( cselectedColor, "%x", &selectedColor );
1154 strTextureButton = cbuttonTexture ? cbuttonTexture :
1155 XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturenofocus", (char*)"list-nofocus.png");
1157 strTextureButtonFocus = cbuttonFocusTexture ? cbuttonFocusTexture :
1158 XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturefocus", (char*)"list-focus.png");
1160 // default values for spin control
1161 pControlSpin->dwPosX = dwWidth - 35;
1162 pControlSpin->dwPosY = dwHeight - 15;
1165 ControlList::~ControlList() { }
1167 CGUIControl* ControlList::Create() throw (WindowException)
1170 label.align = alignmentY;
1171 label.font = g_fontManager.GetFont(strFont);
1172 label.textColor = label.focusedColor = textColor;
1173 //label.shadowColor = shadowColor;
1174 label.selectedColor = selectedColor;
1175 label.offsetX = (float)itemTextOffsetX;
1176 label.offsetY = (float)itemTextOffsetY;
1177 // Second label should have the same font, alignment, and colours as the first, but
1178 // the offsets should be 0.
1179 CLabelInfo label2 = label;
1180 label2.offsetX = label2.offsetY = 0;
1181 label2.align |= XBFONT_RIGHT;
1183 pGUIControl = new CGUIListContainer(
1189 (float)dwHeight - pControlSpin->dwHeight - 5,
1191 (CStdString)strTextureButton,
1192 (CStdString)strTextureButtonFocus,
1194 (float)imageWidth, (float)imageHeight,
1200 void ControlList::addItem(const Alternative<String, const XBMCAddon::xbmcgui::ListItem* > & item, bool sendMessage)
1204 if (item.which() == first)
1205 internAddListItem(ListItem::fromString(item.former()),sendMessage);
1207 internAddListItem(item.later(),sendMessage);
1210 void ControlList::addItems(const std::vector<Alternative<String, const XBMCAddon::xbmcgui::ListItem* > > & items)
1214 for (std::vector<Alternative<String, const XBMCAddon::xbmcgui::ListItem* > >::const_iterator iter = items.begin(); iter != items.end(); ++iter)
1215 addItem(*iter,false);
1216 sendLabelBind(items.size());
1219 void ControlList::internAddListItem(AddonClass::Ref<ListItem> pListItem, bool sendMessage) throw (WindowException)
1221 if (pListItem.isNull())
1222 throw WindowException("NULL ListItem passed to ControlList::addListItem");
1224 // add item to objects vector
1225 vecItems.push_back(pListItem);
1227 // send all of the items ... this is what it did before.
1229 sendLabelBind(vecItems.size());
1232 void ControlList::sendLabelBind(int tail)
1234 // construct a CFileItemList to pass 'em on to the list
1235 CGUIListItemPtr items(new CFileItemList());
1236 for (unsigned int i = vecItems.size() - tail; i < vecItems.size(); i++)
1237 ((CFileItemList*)items.get())->Add(vecItems[i]->item);
1239 CGUIMessage msg(GUI_MSG_LABEL_BIND, iParentId, iControlId, 0, 0, items);
1240 msg.SetPointer(items.get());
1241 g_windowManager.SendThreadMessage(msg, iParentId);
1244 void ControlList::selectItem(long item) throw(UnimplementedException)
1247 CGUIMessage msg(GUI_MSG_ITEM_SELECT, iParentId, iControlId, item);
1250 g_windowManager.SendThreadMessage(msg, iParentId);
1253 void ControlList::removeItem(int index) throw(UnimplementedException,WindowException)
1255 if (index < 0 || index >= (int)vecItems.size())
1256 throw WindowException("Index out of range");
1258 vecItems.erase(vecItems.begin() + index);
1260 sendLabelBind(vecItems.size());
1263 void ControlList::reset() throw(UnimplementedException)
1265 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
1267 g_windowManager.SendThreadMessage(msg, iParentId);
1269 // delete all items from vector
1270 // delete all ListItem from vector
1271 vecItems.clear(); // this should delete all of the objects
1274 Control* ControlList::getSpinControl() throw (UnimplementedException)
1276 return pControlSpin;
1279 long ControlList::getSelectedPosition() throw(UnimplementedException)
1281 DelayedCallGuard dcguard(languageHook);
1285 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, iParentId, iControlId);
1289 if ((vecItems.size() > 0) && pGUIControl)
1291 pGUIControl->OnMessage(msg);
1292 pos = msg.GetParam1();
1298 XBMCAddon::xbmcgui::ListItem* ControlList::getSelectedItem() throw (UnimplementedException)
1300 DelayedCallGuard dcguard(languageHook);
1304 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, iParentId, iControlId);
1305 AddonClass::Ref<ListItem> pListItem = NULL;
1308 if ((vecItems.size() > 0) && pGUIControl)
1310 pGUIControl->OnMessage(msg);
1311 if (msg.GetParam1() >= 0 && (size_t)msg.GetParam1() < vecItems.size())
1312 pListItem = vecItems[msg.GetParam1()];
1315 return pListItem.get();
1318 void ControlList::setImageDimensions(long imageWidth,long imageHeight) throw (UnimplementedException)
1320 CLog::Log(LOGWARNING,"ControlList::setImageDimensions was called but ... it currently isn't defined to do anything.");
1323 if (self->pGUIControl)
1325 CGUIListControl* pListControl = (CGUIListControl*) self->pGUIControl;
1326 pListControl->SetImageDimensions((float)self->dwImageWidth, (float)self->dwImageHeight );
1332 void ControlList::setItemHeight(long height) throw (UnimplementedException)
1334 CLog::Log(LOGWARNING,"ControlList::setItemHeight was called but ... it currently isn't defined to do anything.");
1337 if (self->pGUIControl)
1339 CGUIListControl* pListControl = (CGUIListControl*) self->pGUIControl;
1340 pListControl->SetItemHeight((float)self->dwItemHeight);
1346 void ControlList::setSpace(int space) throw (UnimplementedException)
1348 CLog::Log(LOGWARNING,"ControlList::setSpace was called but ... it currently isn't defined to do anything.");
1351 if (self->pGUIControl)
1353 CGUIListControl* pListControl = (CGUIListControl*) self->pGUIControl;
1354 pListControl->SetSpaceBetweenItems((float)self->dwSpace);
1360 void ControlList::setPageControlVisible(bool visible) throw (UnimplementedException)
1362 CLog::Log(LOGWARNING,"ControlList::setPageControlVisible was called but ... it currently isn't defined to do anything.");
1364 // char isOn = true;
1368 if (self->pGUIControl)
1370 ((CGUIListControl*)self->pGUIControl)->SetPageControlVisible((bool)isOn );
1376 long ControlList::size() throw (UnimplementedException)
1378 return (long)vecItems.size();
1381 long ControlList::getItemHeight() throw(UnimplementedException)
1383 return (long)itemHeight;
1386 long ControlList::getSpace() throw (UnimplementedException)
1391 XBMCAddon::xbmcgui::ListItem* ControlList::getListItem(int index) throw (UnimplementedException,WindowException)
1393 if (index < 0 || index >= (int)vecItems.size())
1394 throw WindowException("Index out of range");
1396 AddonClass::Ref<ListItem> pListItem = vecItems[index];
1397 return pListItem.get();
1400 void ControlList::setStaticContent(const ListItemList* pitems) throw (UnimplementedException)
1402 const ListItemList& vecItems = *pitems;
1404 std::vector<CGUIStaticItemPtr> items;
1406 for (unsigned int item = 0; item < vecItems.size(); item++)
1408 ListItem* pItem = vecItems[item];
1410 // NOTE: This code has likely not worked fully correctly for some time
1411 // In particular, the click behaviour won't be working.
1412 CGUIStaticItemPtr newItem(new CGUIStaticItem(*pItem->item));
1413 items.push_back(newItem);
1417 IListProvider *provider = new CStaticListProvider(items);
1418 ((CGUIBaseContainer *)pGUIControl)->SetListProvider(provider);
1421 // ============================================================