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 String ControlTextBox::getText() throw (UnimplementedException)
146 if (!pGUIControl) return NULL;
149 return ((CGUITextBox*) pGUIControl)->GetDescription();
152 void ControlTextBox::reset() throw(UnimplementedException)
155 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
156 g_windowManager.SendThreadMessage(msg, iParentId);
159 void ControlTextBox::scroll(long position) throw(UnimplementedException)
161 static_cast<CGUITextBox*>(pGUIControl)->Scroll((int)position);
164 CGUIControl* ControlTextBox::Create() throw (WindowException)
168 label.font = g_fontManager.GetFont(strFont);
169 label.textColor = label.focusedColor = textColor;
171 pGUIControl = new CGUITextBox(iParentId, iControlId,
172 (float)dwPosX, (float)dwPosY, (float)dwWidth, (float)dwHeight,
176 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
177 pGUIControl->OnMessage(msg);
182 // ============================================================
184 // ============================================================
185 // ============================================================
186 ControlButton::ControlButton(long x, long y, long width, long height, const String& label,
187 const char* focusTexture, const char* noFocusTexture,
188 long _textOffsetX, long _textOffsetY,
189 long alignment, const char* font, const char* _textColor,
190 const char* _disabledColor, long angle,
191 const char* _shadowColor, const char* _focusedColor) :
192 textOffsetX(_textOffsetX), textOffsetY(_textOffsetY),
193 align(alignment), strFont("font13"), textColor(0xffffffff), disabledColor(0x60ffffff),
194 iAngle(angle), shadowColor(0), focusedColor(0xffffffff)
203 // if texture is supplied use it, else get default ones
204 strTextureFocus = focusTexture ? focusTexture :
205 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturefocus", (char*)"button-focus.png");
206 strTextureNoFocus = noFocusTexture ? noFocusTexture :
207 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturenofocus", (char*)"button-nofocus.jpg");
209 if (font) strFont = font;
210 if (_textColor) sscanf( _textColor, "%x", &textColor );
211 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
212 if (_shadowColor) sscanf( _shadowColor, "%x", &shadowColor );
213 if (_focusedColor) sscanf( _focusedColor, "%x", &focusedColor );
216 void ControlButton::setLabel(const String& label,
218 const char* _textColor,
219 const char* _disabledColor,
220 const char* _shadowColor,
221 const char* _focusedColor,
222 const String& label2) throw (UnimplementedException)
224 if (!label.empty()) strText = label;
225 if (!label2.empty()) strText2 = label2;
226 if (font) strFont = font;
227 if (_textColor) sscanf(_textColor, "%x", &textColor);
228 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
229 if (_shadowColor) sscanf(_shadowColor, "%x", &shadowColor);
230 if (_focusedColor) sscanf(_focusedColor, "%x", &focusedColor);
235 ((CGUIButtonControl*)pGUIControl)->PythonSetLabel(strFont, strText, textColor, shadowColor, focusedColor);
236 ((CGUIButtonControl*)pGUIControl)->SetLabel2(strText2);
237 ((CGUIButtonControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
241 void ControlButton::setDisabledColor(const char* color) throw (UnimplementedException)
243 if (color) sscanf(color, "%x", &disabledColor);
248 ((CGUIButtonControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
252 String ControlButton::getLabel() throw (UnimplementedException)
254 if (!pGUIControl) return NULL;
257 return ((CGUIButtonControl*) pGUIControl)->GetLabel();
260 String ControlButton::getLabel2() throw (UnimplementedException)
262 if (!pGUIControl) return NULL;
265 return ((CGUIButtonControl*) pGUIControl)->GetLabel2();
268 CGUIControl* ControlButton::Create() throw (WindowException)
271 label.font = g_fontManager.GetFont(strFont);
272 label.textColor = textColor;
273 label.disabledColor = disabledColor;
274 label.shadowColor = shadowColor;
275 label.focusedColor = focusedColor;
277 label.offsetX = (float)textOffsetX;
278 label.offsetY = (float)textOffsetY;
279 label.angle = (float)-iAngle;
280 pGUIControl = new CGUIButtonControl(
287 (CStdString)strTextureFocus,
288 (CStdString)strTextureNoFocus,
291 CGUIButtonControl* pGuiButtonControl =
292 (CGUIButtonControl*)pGUIControl;
294 pGuiButtonControl->SetLabel(strText);
295 pGuiButtonControl->SetLabel2(strText2);
300 // ============================================================
302 // ============================================================
303 // ============================================================
304 ControlCheckMark::ControlCheckMark(long x, long y, long width, long height, const String& label,
305 const char* focusTexture, const char* noFocusTexture,
306 long _checkWidth, long _checkHeight,
307 long _alignment, const char* font,
308 const char* _textColor, const char* _disabledColor) :
309 strFont("font13"), checkWidth(_checkWidth), checkHeight(_checkHeight),
310 align(_alignment), textColor(0xffffffff), disabledColor(0x60ffffff)
318 if (font) strFont = font;
319 if (_textColor) sscanf(_textColor, "%x", &textColor);
320 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
322 strTextureFocus = focusTexture ? focusTexture :
323 XBMCAddonUtils::getDefaultImage((char*)"checkmark", (char*)"texturefocus", (char*)"check-box.png");
324 strTextureNoFocus = noFocusTexture ? noFocusTexture :
325 XBMCAddonUtils::getDefaultImage((char*)"checkmark", (char*)"texturenofocus", (char*)"check-boxNF.png");
328 bool ControlCheckMark::getSelected() throw (UnimplementedException)
330 bool isSelected = false;
335 isSelected = ((CGUICheckMarkControl*)pGUIControl)->GetSelected();
341 void ControlCheckMark::setSelected(bool selected) throw (UnimplementedException)
346 ((CGUICheckMarkControl*)pGUIControl)->SetSelected(selected);
350 void ControlCheckMark::setLabel(const String& label,
352 const char* _textColor,
353 const char* _disabledColor,
354 const char* _shadowColor,
355 const char* _focusedColor,
356 const String& label2) throw (UnimplementedException)
359 if (font) strFont = font;
360 if (_textColor) sscanf(_textColor, "%x", &textColor);
361 if (_disabledColor) sscanf(_disabledColor, "%x", &disabledColor);
366 ((CGUICheckMarkControl*)pGUIControl)->PythonSetLabel(strFont,strText,textColor);
367 ((CGUICheckMarkControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
371 void ControlCheckMark::setDisabledColor(const char* color) throw (UnimplementedException)
373 if (color) sscanf(color, "%x", &disabledColor);
378 ((CGUICheckMarkControl*)pGUIControl)->PythonSetDisabledColor( disabledColor );
382 CGUIControl* ControlCheckMark::Create() throw (WindowException)
385 label.disabledColor = disabledColor;
386 label.textColor = label.focusedColor = textColor;
387 label.font = g_fontManager.GetFont(strFont);
389 CTextureInfo imageFocus(strTextureFocus);
390 CTextureInfo imageNoFocus(strTextureNoFocus);
391 pGUIControl = new CGUICheckMarkControl(
398 imageFocus, imageNoFocus,
403 CGUICheckMarkControl* pGuiCheckMarkControl = (CGUICheckMarkControl*)pGUIControl;
404 pGuiCheckMarkControl->SetLabel(strText);
409 // ============================================================
411 // ============================================================
412 // ============================================================
413 ControlImage::ControlImage(long x, long y, long width, long height,
414 const char* filename, long aRatio,
415 const char* _colorDiffuse):
416 aspectRatio(aRatio), colorDiffuse(0)
423 // check if filename exists
424 strFileName = filename;
426 sscanf(_colorDiffuse, "%x", &colorDiffuse);
429 void ControlImage::setImage(const char* imageFilename, const bool useCache) throw (UnimplementedException)
431 strFileName = imageFilename;
435 ((CGUIImage*)pGUIControl)->SetFileName(strFileName, false, useCache);
438 void ControlImage::setColorDiffuse(const char* cColorDiffuse) throw (UnimplementedException)
440 if (cColorDiffuse) sscanf(cColorDiffuse, "%x", &colorDiffuse);
441 else colorDiffuse = 0;
445 ((CGUIImage *)pGUIControl)->SetColorDiffuse(colorDiffuse);
448 CGUIControl* ControlImage::Create() throw (WindowException)
450 pGUIControl = new CGUIImage(iParentId, iControlId,
451 (float)dwPosX, (float)dwPosY, (float)dwWidth, (float)dwHeight,
452 (CStdString)strFileName);
454 if (pGUIControl && aspectRatio <= CAspectRatio::AR_KEEP)
455 ((CGUIImage *)pGUIControl)->SetAspectRatio((CAspectRatio::ASPECT_RATIO)aspectRatio);
457 if (pGUIControl && colorDiffuse)
458 ((CGUIImage *)pGUIControl)->SetColorDiffuse(colorDiffuse);
463 // ============================================================
465 // ============================================================
466 // ============================================================
467 ControlProgress::ControlProgress(long x, long y, long width, long height,
468 const char* texturebg,
469 const char* textureleft,
470 const char* texturemid,
471 const char* textureright,
472 const char* textureoverlay)
479 // if texture is supplied use it, else get default ones
480 strTextureBg = texturebg ? texturebg :
481 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"texturebg", (char*)"progress_back.png");
482 strTextureLeft = textureleft ? textureleft :
483 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"lefttexture", (char*)"progress_left.png");
484 strTextureMid = texturemid ? texturemid :
485 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"midtexture", (char*)"progress_mid.png");
486 strTextureRight = textureright ? textureright :
487 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"righttexture", (char*)"progress_right.png");
488 strTextureOverlay = textureoverlay ? textureoverlay :
489 XBMCAddonUtils::getDefaultImage((char*)"progress", (char*)"overlaytexture", (char*)"progress_over.png");
492 void ControlProgress::setPercent(float pct) throw (UnimplementedException)
495 ((CGUIProgressControl*)pGUIControl)->SetPercentage(pct);
498 float ControlProgress::getPercent() throw (UnimplementedException)
500 return (pGUIControl) ? ((CGUIProgressControl*)pGUIControl)->GetPercentage() : 0.0f;
503 CGUIControl* ControlProgress::Create() throw (WindowException)
505 pGUIControl = new CGUIProgressControl(iParentId, iControlId,
506 (float)dwPosX, (float)dwPosY,
507 (float)dwWidth,(float)dwHeight,
508 (CStdString)strTextureBg,(CStdString)strTextureLeft,
509 (CStdString)strTextureMid,(CStdString)strTextureRight,
510 (CStdString)strTextureOverlay);
512 if (pGUIControl && colorDiffuse)
513 ((CGUIProgressControl *)pGUIControl)->SetColorDiffuse(colorDiffuse);
518 // ============================================================
520 // ============================================================
521 // ============================================================
522 ControlSlider::ControlSlider(long x, long y, long width, long height,
523 const char* textureback,
525 const char* texturefocus)
532 // if texture is supplied use it, else get default ones
533 strTextureBack = textureback ? textureback :
534 XBMCAddonUtils::getDefaultImage((char*)"slider", (char*)"texturesliderbar", (char*)"osd_slider_bg_2.png");
535 strTexture = texture ? texture :
536 XBMCAddonUtils::getDefaultImage((char*)"slider", (char*)"textureslidernib", (char*)"osd_slider_nibNF.png");
537 strTextureFoc = texturefocus ? texturefocus :
538 XBMCAddonUtils::getDefaultImage((char*)"slider", (char*)"textureslidernibfocus", (char*)"osd_slider_nib.png");
541 float ControlSlider::getPercent() throw (UnimplementedException)
543 return (pGUIControl) ? ((CGUISliderControl*)pGUIControl)->GetPercentage() : 0.0f;
546 void ControlSlider::setPercent(float pct) throw (UnimplementedException)
549 ((CGUISliderControl*)pGUIControl)->SetPercentage(pct);
552 CGUIControl* ControlSlider::Create () throw (WindowException)
554 pGUIControl = new CGUISliderControl(iParentId, iControlId,(float)dwPosX, (float)dwPosY,
555 (float)dwWidth,(float)dwHeight,
556 (CStdString)strTextureBack,(CStdString)strTexture,
557 (CStdString)strTextureFoc,0);
562 // ============================================================
564 // ============================================================
565 // ============================================================
566 ControlGroup::ControlGroup(long x, long y, long width, long height)
574 CGUIControl* ControlGroup::Create() throw (WindowException)
576 pGUIControl = new CGUIControlGroup(iParentId,
585 // ============================================================
587 // ============================================================
588 // ============================================================
589 ControlRadioButton::ControlRadioButton(long x, long y, long width, long height, const String& label,
590 const char* focusOnTexture, const char* noFocusOnTexture,
591 const char* focusOffTexture, const char* noFocusOffTexture,
592 const char* focusTexture, const char* noFocusTexture,
593 long _textOffsetX, long _textOffsetY,
594 long alignment, const char* font, const char* _textColor,
595 const char* _disabledColor, long angle,
596 const char* _shadowColor, const char* _focusedColor) :
597 strFont("font13"), textColor(0xffffffff), disabledColor(0x60ffffff),
598 textOffsetX(_textOffsetX), textOffsetY(_textOffsetY), align(alignment), iAngle(angle),
599 shadowColor(0), focusedColor(0xffffffff)
608 // if texture is supplied use it, else get default ones
609 strTextureFocus = focusTexture ? focusTexture :
610 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturefocus", (char*)"button-focus.png");
611 strTextureNoFocus = noFocusTexture ? noFocusTexture :
612 XBMCAddonUtils::getDefaultImage((char*)"button", (char*)"texturenofocus", (char*)"button-nofocus.jpg");
614 if (focusOnTexture && noFocusOnTexture)
616 strTextureRadioOnFocus = focusOnTexture;
617 strTextureRadioOnNoFocus = noFocusOnTexture;
621 strTextureRadioOnFocus = strTextureRadioOnNoFocus = focusTexture ? focusTexture :
622 XBMCAddonUtils::getDefaultImage((char*)"radiobutton", (char*)"textureradiofocus", (char*)"radiobutton-focus.png");
625 if (focusOffTexture && noFocusOffTexture)
627 strTextureRadioOffFocus = focusOffTexture;
628 strTextureRadioOffNoFocus = noFocusOffTexture;
632 strTextureRadioOffFocus = strTextureRadioOffNoFocus = noFocusTexture ? noFocusTexture :
633 XBMCAddonUtils::getDefaultImage((char*)"radiobutton", (char*)"textureradiofocus", (char*)"radiobutton-focus.png");
636 if (font) strFont = font;
637 if (_textColor) sscanf( _textColor, "%x", &textColor );
638 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
639 if (_shadowColor) sscanf( _shadowColor, "%x", &shadowColor );
640 if (_focusedColor) sscanf( _focusedColor, "%x", &focusedColor );
643 void ControlRadioButton::setSelected(bool selected) throw (UnimplementedException)
648 ((CGUIRadioButtonControl*)pGUIControl)->SetSelected(selected);
652 bool ControlRadioButton::isSelected() throw (UnimplementedException)
654 bool isSelected = false;
659 isSelected = ((CGUIRadioButtonControl*)pGUIControl)->IsSelected();
664 void ControlRadioButton::setLabel(const String& label,
666 const char* _textColor,
667 const char* _disabledColor,
668 const char* _shadowColor,
669 const char* _focusedColor,
670 const String& label2) throw (UnimplementedException)
672 if (!label.empty()) strText = label;
673 if (font) strFont = font;
674 if (_textColor) sscanf(_textColor, "%x", &textColor);
675 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
676 if (_shadowColor) sscanf(_shadowColor, "%x", &shadowColor);
677 if (_focusedColor) sscanf(_focusedColor, "%x", &focusedColor);
682 ((CGUIRadioButtonControl*)pGUIControl)->PythonSetLabel(strFont, strText, textColor, shadowColor, focusedColor);
683 ((CGUIRadioButtonControl*)pGUIControl)->PythonSetDisabledColor(disabledColor);
687 void ControlRadioButton::setRadioDimension(long x, long y, long width, long height)
688 throw (UnimplementedException)
697 ((CGUIRadioButtonControl*)pGUIControl)->SetRadioDimensions((float)dwPosX, (float)dwPosY, (float)dwWidth, (float)dwHeight);
701 CGUIControl* ControlRadioButton::Create() throw (WindowException)
704 label.font = g_fontManager.GetFont(strFont);
705 label.textColor = textColor;
706 label.disabledColor = disabledColor;
707 label.shadowColor = shadowColor;
708 label.focusedColor = focusedColor;
710 label.offsetX = (float)textOffsetX;
711 label.offsetY = (float)textOffsetY;
712 label.angle = (float)-iAngle;
713 pGUIControl = new CGUIRadioButtonControl(
720 (CStdString)strTextureFocus,
721 (CStdString)strTextureNoFocus,
723 (CStdString)strTextureRadioOnFocus,
724 (CStdString)strTextureRadioOnNoFocus,
725 (CStdString)strTextureRadioOffFocus,
726 (CStdString)strTextureRadioOffNoFocus);
728 CGUIRadioButtonControl* pGuiButtonControl =
729 (CGUIRadioButtonControl*)pGUIControl;
731 pGuiButtonControl->SetLabel(strText);
736 // ============================================================
738 // ============================================================
739 // ============================================================
740 Control::~Control() { deallocating(); }
742 CGUIControl* Control::Create() throw (WindowException)
744 throw WindowException("Object is a Control, but can't be added to a window");
747 std::vector<int> Control::getPosition()
749 std::vector<int> ret(2);
755 void Control::setEnabled(bool enabled)
757 DelayedCallGuard dcguard(languageHook);
760 pGUIControl->SetEnabled(enabled);
763 void Control::setVisible(bool visible)
765 DelayedCallGuard dcguard(languageHook);
768 pGUIControl->SetVisible(visible);
771 void Control::setVisibleCondition(const char* visible, bool allowHiddenFocus)
773 DelayedCallGuard dcguard(languageHook);
777 pGUIControl->SetVisibleCondition(visible, allowHiddenFocus ? "true" : "false");
780 void Control::setEnableCondition(const char* enable)
782 DelayedCallGuard dcguard(languageHook);
786 pGUIControl->SetEnableCondition(enable);
789 void Control::setAnimations(const std::vector< Tuple<String,String> >& eventAttr) throw (WindowException)
792 TiXmlElement xmlRootElement("control");
793 TiXmlNode *pRoot = xmlDoc.InsertEndChild(xmlRootElement);
795 throw WindowException("TiXmlNode creation error");
797 std::vector<CAnimation> animations;
799 for (unsigned int anim = 0; anim < eventAttr.size(); anim++)
801 const Tuple<String,String>& pTuple = eventAttr[anim];
803 if (pTuple.GetNumValuesSet() != 2)
804 throw WindowException("Error unpacking tuple found in list");
806 const String& cEvent = pTuple.first();
807 const String& cAttr = pTuple.second();
809 TiXmlElement pNode("animation");
810 CStdStringArray attrs;
811 StringUtils::SplitString(cAttr.c_str(), " ", attrs);
812 for (unsigned int i = 0; i < attrs.size(); i++)
814 CStdStringArray attrs2;
815 StringUtils::SplitString(attrs[i], "=", attrs2);
816 if (attrs2.size() == 2)
817 pNode.SetAttribute(attrs2[0], attrs2[1]);
819 TiXmlText value(cEvent.c_str());
820 pNode.InsertEndChild(value);
821 pRoot->InsertEndChild(pNode);
824 const CRect animRect((float)dwPosX, (float)dwPosY, (float)dwPosX + dwWidth, (float)dwPosY + dwHeight);
828 CGUIControlFactory::GetAnimations(pRoot, animRect, iParentId, animations);
829 pGUIControl->SetAnimations(animations);
833 void Control::setPosition(long x, long y)
835 DelayedCallGuard dcguard(languageHook);
840 pGUIControl->SetPosition((float)dwPosX, (float)dwPosY);
843 void Control::setWidth(long width)
845 DelayedCallGuard dcguard(languageHook);
849 pGUIControl->SetWidth((float)dwWidth);
852 void Control::setHeight(long height)
854 DelayedCallGuard dcguard(languageHook);
858 pGUIControl->SetHeight((float)dwHeight);
861 void Control::setNavigation(const Control* up, const Control* down,
862 const Control* left, const Control* right)
863 throw (WindowException)
866 throw WindowException("Control has to be added to a window first");
868 iControlUp = up->iControlId;
869 iControlDown = down->iControlId;
870 iControlLeft = left->iControlId;
871 iControlRight = right->iControlId;
876 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
880 void Control::controlUp(const Control* control) throw (WindowException)
883 throw WindowException("Control has to be added to a window first");
885 iControlUp = control->iControlId;
889 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
893 void Control::controlDown(const Control* control) throw (WindowException)
896 throw WindowException("Control has to be added to a window first");
898 iControlDown = control->iControlId;
902 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
906 void Control::controlLeft(const Control* control) throw (WindowException)
909 throw WindowException("Control has to be added to a window first");
911 iControlLeft = control->iControlId;
915 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
919 void Control::controlRight(const Control* control) throw (WindowException)
922 throw WindowException("Control has to be added to a window first");
924 iControlRight = control->iControlId;
928 pGUIControl->SetNavigation(iControlUp,iControlDown,iControlLeft,iControlRight);
932 // ============================================================
934 // ============================================================
935 ControlSpin::ControlSpin()
937 // default values for spin control
944 // get default images
945 strTextureUp = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"textureup", (char*)"scroll-up.png");
946 strTextureDown = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturedown", (char*)"scroll-down.png");
947 strTextureUpFocus = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"textureupfocus", (char*)"scroll-up-focus.png");
948 strTextureDownFocus = XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturedownfocus", (char*)"scroll-down-focus.png");
951 void ControlSpin::setTextures(const char* up, const char* down,
953 const char* downFocus) throw(UnimplementedException)
956 strTextureDown = down;
957 strTextureUpFocus = upFocus;
958 strTextureDownFocus = downFocus;
961 if (self->pGUIControl)
963 CGUISpinControl* pControl = (CGUISpinControl*)self->pGUIControl;
969 ControlSpin::~ControlSpin() {}
970 // ============================================================
972 // ============================================================
974 // ============================================================
975 ControlLabel::ControlLabel(long x, long y, long width, long height,
977 const char* font, const char* p_textColor,
978 const char* p_disabledColor,
980 bool hasPath, long angle) :
982 textColor(0xffffffff), disabledColor(0x60ffffff),
983 align(p_alignment), bHasPath(hasPath), iAngle(angle)
995 sscanf(p_textColor, "%x", &textColor);
998 sscanf( p_disabledColor, "%x", &disabledColor );
1001 ControlLabel::~ControlLabel() {}
1003 CGUIControl* ControlLabel::Create() throw (WindowException)
1006 label.font = g_fontManager.GetFont(strFont);
1007 label.textColor = label.focusedColor = textColor;
1008 label.disabledColor = disabledColor;
1009 label.align = align;
1010 label.angle = (float)-iAngle;
1011 pGUIControl = new CGUILabelControl(
1021 ((CGUILabelControl *)pGUIControl)->SetLabel(strText);
1025 void ControlLabel::setLabel(const String& label, const char* font,
1026 const char* textColor, const char* disabledColor,
1027 const char* shadowColor, const char* focusedColor,
1028 const String& label2) throw(UnimplementedException)
1031 CGUIMessage msg(GUI_MSG_LABEL_SET, iParentId, iControlId);
1032 msg.SetLabel(strText);
1033 g_windowManager.SendThreadMessage(msg, iParentId);
1036 String ControlLabel::getLabel() throw(UnimplementedException)
1042 // ============================================================
1044 // ============================================================
1046 // ============================================================
1047 ControlEdit::ControlEdit(long x, long y, long width, long height, const String& label,
1048 const char* font, const char* _textColor,
1049 const char* _disabledColor,
1050 long _alignment, const char* focusTexture,
1051 const char* noFocusTexture, bool isPassword) :
1052 strFont("font13"), textColor(0xffffffff), disabledColor(0x60ffffff),
1053 align(_alignment), bIsPassword(isPassword)
1056 strTextureFocus = focusTexture ? focusTexture :
1057 XBMCAddonUtils::getDefaultImage((char*)"edit", (char*)"texturefocus", (char*)"button-focus.png");
1059 strTextureNoFocus = noFocusTexture ? noFocusTexture :
1060 XBMCAddonUtils::getDefaultImage((char*)"edit", (char*)"texturenofocus", (char*)"button-focus.png");
1062 if (font) strFont = font;
1063 if (_textColor) sscanf( _textColor, "%x", &textColor );
1064 if (_disabledColor) sscanf( _disabledColor, "%x", &disabledColor );
1067 CGUIControl* ControlEdit::Create() throw (WindowException)
1070 label.font = g_fontManager.GetFont(strFont);
1071 label.textColor = label.focusedColor = textColor;
1072 label.disabledColor = disabledColor;
1073 label.align = align;
1074 pGUIControl = new CGUIEditControl(
1081 (CStdString)strTextureFocus,
1082 (CStdString)strTextureNoFocus,
1087 ((CGUIEditControl *) pGUIControl)->SetInputType(CGUIEditControl::INPUT_TYPE_PASSWORD, 0);
1091 void ControlEdit::setLabel(const String& label, const char* font,
1092 const char* textColor, const char* disabledColor,
1093 const char* shadowColor, const char* focusedColor,
1094 const String& label2) throw(UnimplementedException)
1097 CGUIMessage msg(GUI_MSG_LABEL_SET, iParentId, iControlId);
1098 msg.SetLabel(strText);
1099 g_windowManager.SendThreadMessage(msg, iParentId);
1102 String ControlEdit::getLabel() throw(UnimplementedException)
1109 void ControlEdit::setText(const String& text) throw(UnimplementedException)
1112 CGUIMessage msg(GUI_MSG_LABEL2_SET, iParentId, iControlId);
1116 g_windowManager.SendThreadMessage(msg, iParentId);
1119 String ControlEdit::getText() throw(UnimplementedException)
1121 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, iParentId, iControlId);
1122 g_windowManager.SendMessage(msg, iParentId);
1124 return msg.GetLabel();
1127 // ============================================================
1129 // ============================================================
1130 ControlList::ControlList(long x, long y, long width, long height, const char* font,
1131 const char* ctextColor, const char* cbuttonTexture,
1132 const char* cbuttonFocusTexture,
1133 const char* cselectedColor,
1134 long _imageWidth, long _imageHeight, long _itemTextXOffset,
1135 long _itemTextYOffset, long _itemHeight, long _space, long _alignmentY) :
1137 textColor(0xe0f0f0f0), selectedColor(0xffffffff),
1138 imageHeight(_imageHeight), imageWidth(_imageWidth),
1139 itemHeight(_itemHeight), space(_space),
1140 itemTextOffsetX(_itemTextXOffset),itemTextOffsetY(_itemTextYOffset),
1141 alignmentY(_alignmentY)
1148 // create a python spin control
1149 pControlSpin = new ControlSpin();
1151 // initialize default values
1156 sscanf( ctextColor, "%x", &textColor );
1159 sscanf( cselectedColor, "%x", &selectedColor );
1161 strTextureButton = cbuttonTexture ? cbuttonTexture :
1162 XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturenofocus", (char*)"list-nofocus.png");
1164 strTextureButtonFocus = cbuttonFocusTexture ? cbuttonFocusTexture :
1165 XBMCAddonUtils::getDefaultImage((char*)"listcontrol", (char*)"texturefocus", (char*)"list-focus.png");
1167 // default values for spin control
1168 pControlSpin->dwPosX = dwWidth - 35;
1169 pControlSpin->dwPosY = dwHeight - 15;
1172 ControlList::~ControlList() { }
1174 CGUIControl* ControlList::Create() throw (WindowException)
1177 label.align = alignmentY;
1178 label.font = g_fontManager.GetFont(strFont);
1179 label.textColor = label.focusedColor = textColor;
1180 //label.shadowColor = shadowColor;
1181 label.selectedColor = selectedColor;
1182 label.offsetX = (float)itemTextOffsetX;
1183 label.offsetY = (float)itemTextOffsetY;
1184 // Second label should have the same font, alignment, and colours as the first, but
1185 // the offsets should be 0.
1186 CLabelInfo label2 = label;
1187 label2.offsetX = label2.offsetY = 0;
1188 label2.align |= XBFONT_RIGHT;
1190 pGUIControl = new CGUIListContainer(
1196 (float)dwHeight - pControlSpin->dwHeight - 5,
1198 (CStdString)strTextureButton,
1199 (CStdString)strTextureButtonFocus,
1201 (float)imageWidth, (float)imageHeight,
1207 void ControlList::addItem(const Alternative<String, const XBMCAddon::xbmcgui::ListItem* > & item, bool sendMessage)
1211 if (item.which() == first)
1212 internAddListItem(ListItem::fromString(item.former()),sendMessage);
1214 internAddListItem(item.later(),sendMessage);
1217 void ControlList::addItems(const std::vector<Alternative<String, const XBMCAddon::xbmcgui::ListItem* > > & items)
1221 for (std::vector<Alternative<String, const XBMCAddon::xbmcgui::ListItem* > >::const_iterator iter = items.begin(); iter != items.end(); ++iter)
1222 addItem(*iter,false);
1223 sendLabelBind(items.size());
1226 void ControlList::internAddListItem(AddonClass::Ref<ListItem> pListItem, bool sendMessage) throw (WindowException)
1228 if (pListItem.isNull())
1229 throw WindowException("NULL ListItem passed to ControlList::addListItem");
1231 // add item to objects vector
1232 vecItems.push_back(pListItem);
1234 // send all of the items ... this is what it did before.
1236 sendLabelBind(vecItems.size());
1239 void ControlList::sendLabelBind(int tail)
1241 // construct a CFileItemList to pass 'em on to the list
1242 CGUIListItemPtr items(new CFileItemList());
1243 for (unsigned int i = vecItems.size() - tail; i < vecItems.size(); i++)
1244 ((CFileItemList*)items.get())->Add(vecItems[i]->item);
1246 CGUIMessage msg(GUI_MSG_LABEL_BIND, iParentId, iControlId, 0, 0, items);
1247 msg.SetPointer(items.get());
1248 g_windowManager.SendThreadMessage(msg, iParentId);
1251 void ControlList::selectItem(long item) throw(UnimplementedException)
1254 CGUIMessage msg(GUI_MSG_ITEM_SELECT, iParentId, iControlId, item);
1257 g_windowManager.SendThreadMessage(msg, iParentId);
1260 void ControlList::removeItem(int index) throw(UnimplementedException,WindowException)
1262 if (index < 0 || index >= (int)vecItems.size())
1263 throw WindowException("Index out of range");
1265 vecItems.erase(vecItems.begin() + index);
1267 sendLabelBind(vecItems.size());
1270 void ControlList::reset() throw(UnimplementedException)
1272 CGUIMessage msg(GUI_MSG_LABEL_RESET, iParentId, iControlId);
1274 g_windowManager.SendThreadMessage(msg, iParentId);
1276 // delete all items from vector
1277 // delete all ListItem from vector
1278 vecItems.clear(); // this should delete all of the objects
1281 Control* ControlList::getSpinControl() throw (UnimplementedException)
1283 return pControlSpin;
1286 long ControlList::getSelectedPosition() throw(UnimplementedException)
1288 DelayedCallGuard dcguard(languageHook);
1292 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, iParentId, iControlId);
1296 if ((vecItems.size() > 0) && pGUIControl)
1298 pGUIControl->OnMessage(msg);
1299 pos = msg.GetParam1();
1305 XBMCAddon::xbmcgui::ListItem* ControlList::getSelectedItem() throw (UnimplementedException)
1307 DelayedCallGuard dcguard(languageHook);
1311 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, iParentId, iControlId);
1312 AddonClass::Ref<ListItem> pListItem = NULL;
1315 if ((vecItems.size() > 0) && pGUIControl)
1317 pGUIControl->OnMessage(msg);
1318 if (msg.GetParam1() >= 0 && (size_t)msg.GetParam1() < vecItems.size())
1319 pListItem = vecItems[msg.GetParam1()];
1322 return pListItem.get();
1325 void ControlList::setImageDimensions(long imageWidth,long imageHeight) throw (UnimplementedException)
1327 CLog::Log(LOGWARNING,"ControlList::setImageDimensions was called but ... it currently isn't defined to do anything.");
1330 if (self->pGUIControl)
1332 CGUIListControl* pListControl = (CGUIListControl*) self->pGUIControl;
1333 pListControl->SetImageDimensions((float)self->dwImageWidth, (float)self->dwImageHeight );
1339 void ControlList::setItemHeight(long height) throw (UnimplementedException)
1341 CLog::Log(LOGWARNING,"ControlList::setItemHeight was called but ... it currently isn't defined to do anything.");
1344 if (self->pGUIControl)
1346 CGUIListControl* pListControl = (CGUIListControl*) self->pGUIControl;
1347 pListControl->SetItemHeight((float)self->dwItemHeight);
1353 void ControlList::setSpace(int space) throw (UnimplementedException)
1355 CLog::Log(LOGWARNING,"ControlList::setSpace was called but ... it currently isn't defined to do anything.");
1358 if (self->pGUIControl)
1360 CGUIListControl* pListControl = (CGUIListControl*) self->pGUIControl;
1361 pListControl->SetSpaceBetweenItems((float)self->dwSpace);
1367 void ControlList::setPageControlVisible(bool visible) throw (UnimplementedException)
1369 CLog::Log(LOGWARNING,"ControlList::setPageControlVisible was called but ... it currently isn't defined to do anything.");
1371 // char isOn = true;
1375 if (self->pGUIControl)
1377 ((CGUIListControl*)self->pGUIControl)->SetPageControlVisible((bool)isOn );
1383 long ControlList::size() throw (UnimplementedException)
1385 return (long)vecItems.size();
1388 long ControlList::getItemHeight() throw(UnimplementedException)
1390 return (long)itemHeight;
1393 long ControlList::getSpace() throw (UnimplementedException)
1398 XBMCAddon::xbmcgui::ListItem* ControlList::getListItem(int index) throw (UnimplementedException,WindowException)
1400 if (index < 0 || index >= (int)vecItems.size())
1401 throw WindowException("Index out of range");
1403 AddonClass::Ref<ListItem> pListItem = vecItems[index];
1404 return pListItem.get();
1407 void ControlList::setStaticContent(const ListItemList* pitems) throw (UnimplementedException)
1409 const ListItemList& vecItems = *pitems;
1411 std::vector<CGUIStaticItemPtr> items;
1413 for (unsigned int item = 0; item < vecItems.size(); item++)
1415 ListItem* pItem = vecItems[item];
1417 // NOTE: This code has likely not worked fully correctly for some time
1418 // In particular, the click behaviour won't be working.
1419 CGUIStaticItemPtr newItem(new CGUIStaticItem(*pItem->item));
1420 items.push_back(newItem);
1424 IListProvider *provider = new CStaticListProvider(items);
1425 ((CGUIBaseContainer *)pGUIControl)->SetListProvider(provider);
1428 // ============================================================