/* Searches for a control in Window->vecControls * If we can't find any but the window has the controlId (in case of a not python window) * we create a new control with basic functionality */ Control* Window::GetControlById(int iControlId, CCriticalSection* gc) { XBMC_TRACE; // find in window vector first!!! // this saves us from creating a complete new control std::vector<AddonClass::Ref<Control> >::iterator it = vecControls.begin(); while (it != vecControls.end()) { AddonClass::Ref<Control> control = (*it); if (control->iControlId == iControlId) { return control.get(); } else ++it; } // lock xbmc GUI before accessing data from it MaybeLock lock(gc); // check if control exists CGUIControl* pGUIControl = (CGUIControl*)ref(window)->GetControl(iControlId); if (!pGUIControl) { // control does not exist. throw WindowException("Non-Existent Control %d",iControlId); } // allocate a new control with a new reference CLabelInfo li; Control* pControl = NULL; // TODO: Yuck! Should probably be done with a Factory pattern switch(pGUIControl->GetControlType()) { case CGUIControl::GUICONTROL_BUTTON: pControl = new ControlButton(); li = ((CGUIButtonControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlButton*)pControl)->disabledColor = li.disabledColor; ((ControlButton*)pControl)->focusedColor = li.focusedColor; ((ControlButton*)pControl)->textColor = li.textColor; ((ControlButton*)pControl)->shadowColor = li.shadowColor; if (li.font) ((ControlButton*)pControl)->strFont = li.font->GetFontName(); ((ControlButton*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_CHECKMARK: pControl = new ControlCheckMark(); li = ((CGUICheckMarkControl *)pGUIControl)->GetLabelInfo(); // note: conversion to plain colors from infocolors. ((ControlCheckMark*)pControl)->disabledColor = li.disabledColor; //((ControlCheckMark*)pControl)->shadowColor = li.shadowColor; ((ControlCheckMark*)pControl)->textColor = li.textColor; if (li.font) ((ControlCheckMark*)pControl)->strFont = li.font->GetFontName(); ((ControlCheckMark*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_LABEL: pControl = new ControlLabel(); break; case CGUIControl::GUICONTROL_SPIN: pControl = new ControlSpin(); break; case CGUIControl::GUICONTROL_FADELABEL: pControl = new ControlFadeLabel(); break; case CGUIControl::GUICONTROL_TEXTBOX: pControl = new ControlTextBox(); break; case CGUIControl::GUICONTROL_IMAGE: pControl = new ControlImage(); break; case CGUIControl::GUICONTROL_PROGRESS: pControl = new ControlProgress(); break; case CGUIControl::GUICONTROL_SLIDER: pControl = new ControlSlider(); break; case CGUIControl::GUICONTAINER_LIST: case CGUIControl::GUICONTAINER_WRAPLIST: case CGUIControl::GUICONTAINER_FIXEDLIST: case CGUIControl::GUICONTAINER_PANEL: pControl = new ControlList(); // create a python spin control ((ControlList*)pControl)->pControlSpin = new ControlSpin(); break; case CGUIControl::GUICONTROL_GROUP: pControl = new ControlGroup(); break; case CGUIControl::GUICONTROL_RADIO: pControl = new ControlRadioButton(); li = ((CGUIRadioButtonControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlRadioButton*)pControl)->disabledColor = li.disabledColor; ((ControlRadioButton*)pControl)->focusedColor = li.focusedColor; ((ControlRadioButton*)pControl)->textColor = li.textColor; ((ControlRadioButton*)pControl)->shadowColor = li.shadowColor; if (li.font) ((ControlRadioButton*)pControl)->strFont = li.font->GetFontName(); ((ControlRadioButton*)pControl)->align = li.align; break; case CGUIControl::GUICONTROL_EDIT: pControl = new ControlEdit(); li = ((CGUIEditControl *)pGUIControl)->GetLabelInfo(); // note: conversion from infocolors -> plain colors here ((ControlEdit*)pControl)->disabledColor = li.disabledColor; ((ControlEdit*)pControl)->textColor = li.textColor; if (li.font) ((ControlEdit*)pControl)->strFont = li.font->GetFontName(); ((ControlButton*)pControl)->align = li.align; break; default: break; } if (!pControl) // throw an exeption throw WindowException("Unknown control type for python"); // we have a valid control here, fill in all the 'Control' data pControl->pGUIControl = pGUIControl; pControl->iControlId = pGUIControl->GetID(); pControl->iParentId = iWindowId; pControl->dwHeight = (int)pGUIControl->GetHeight(); pControl->dwWidth = (int)pGUIControl->GetWidth(); pControl->dwPosX = (int)pGUIControl->GetXPosition(); pControl->dwPosY = (int)pGUIControl->GetYPosition(); pControl->iControlUp = pGUIControl->GetNavigateAction(ACTION_MOVE_UP).GetNavigation(); pControl->iControlDown = pGUIControl->GetNavigateAction(ACTION_MOVE_DOWN).GetNavigation(); pControl->iControlLeft = pGUIControl->GetNavigateAction(ACTION_MOVE_LEFT).GetNavigation(); pControl->iControlRight = pGUIControl->GetNavigateAction(ACTION_MOVE_RIGHT).GetNavigation(); // It got this far so means the control isn't actually in the vector of controls // so lets add it to save doing all that next time vecControls.push_back(AddonClass::Ref<Control>(pControl)); // return the control with increased reference (+1) return pControl; }