/* 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(Window* self, int iControlId) { Control* pControl = NULL; // find in window vector first!!! // this saves us from creating a complete new control vector<Control*>::iterator it = self->vecControls.begin(); while (it != self->vecControls.end()) { Control* control = *it; if (control->iControlId == iControlId) { Py_INCREF(control); return control; } else ++it; } // lock xbmc GUI before accessing data from it GilSafeSingleLock lock(g_graphicsContext); // check if control exists CGUIControl* pGUIControl = (CGUIControl*)self->pWindow->GetControl(iControlId); if (!pGUIControl) { // control does not exist. CStdString error; error.Format("Non-Existent Control %d",iControlId); PyErr_SetString(PyExc_TypeError, error.c_str()); return NULL; } // allocate a new control with a new reference CLabelInfo li; switch(pGUIControl->GetControlType()) { case CGUIControl::GUICONTROL_BUTTON: pControl = (Control*)ControlButton_Type.tp_alloc(&ControlButton_Type, 0); new(&((ControlButton*)pControl)->strFont) string(); new(&((ControlButton*)pControl)->strText) string(); new(&((ControlButton*)pControl)->strText2) string(); new(&((ControlButton*)pControl)->strTextureFocus) string(); new(&((ControlButton*)pControl)->strTextureNoFocus) string(); 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 = (Control*)ControlCheckMark_Type.tp_alloc(&ControlCheckMark_Type, 0); new(&((ControlCheckMark*)pControl)->strFont) string(); new(&((ControlCheckMark*)pControl)->strText) string(); new(&((ControlCheckMark*)pControl)->strTextureFocus) string(); new(&((ControlCheckMark*)pControl)->strTextureNoFocus) string(); 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 = (Control*)ControlLabel_Type.tp_alloc(&ControlLabel_Type, 0); new(&((ControlLabel*)pControl)->strText) string(); new(&((ControlLabel*)pControl)->strFont) string(); break; case CGUIControl::GUICONTROL_SPIN: pControl = (Control*)ControlSpin_Type.tp_alloc(&ControlSpin_Type, 0); new(&((ControlSpin*)pControl)->strTextureUp) string(); new(&((ControlSpin*)pControl)->strTextureDown) string(); new(&((ControlSpin*)pControl)->strTextureUpFocus) string(); new(&((ControlSpin*)pControl)->strTextureDownFocus) string(); break; case CGUIControl::GUICONTROL_FADELABEL: pControl = (Control*)ControlFadeLabel_Type.tp_alloc(&ControlFadeLabel_Type, 0); new(&((ControlFadeLabel*)pControl)->strFont) string(); new(&((ControlFadeLabel*)pControl)->vecLabels) std::vector<string>(); break; case CGUIControl::GUICONTROL_TEXTBOX: pControl = (Control*)ControlTextBox_Type.tp_alloc(&ControlTextBox_Type, 0); new(&((ControlTextBox*)pControl)->strFont) string(); break; case CGUIControl::GUICONTROL_IMAGE: pControl = (Control*)ControlImage_Type.tp_alloc(&ControlImage_Type, 0); new(&((ControlImage*)pControl)->strFileName) string(); break; case CGUIControl::GUICONTROL_PROGRESS: pControl = (Control*)ControlProgress_Type.tp_alloc(&ControlProgress_Type, 0); new(&((ControlProgress*)pControl)->strTextureLeft) string(); new(&((ControlProgress*)pControl)->strTextureMid) string(); new(&((ControlProgress*)pControl)->strTextureRight) string(); new(&((ControlProgress*)pControl)->strTextureBg) string(); new(&((ControlProgress*)pControl)->strTextureOverlay) string(); break; case CGUIControl::GUICONTROL_SLIDER: pControl = (Control*)ControlSlider_Type.tp_alloc(&ControlSlider_Type, 0); new(&((ControlSlider*)pControl)->strTextureBack) string(); new(&((ControlSlider*)pControl)->strTexture) string(); new(&((ControlSlider*)pControl)->strTextureFoc) string(); break; case CGUIControl::GUICONTAINER_LIST: case CGUIControl::GUICONTAINER_WRAPLIST: case CGUIControl::GUICONTAINER_FIXEDLIST: case CGUIControl::GUICONTAINER_PANEL: pControl = (Control*)ControlList_Type.tp_alloc(&ControlList_Type, 0); new(&((ControlList*)pControl)->strFont) string(); new(&((ControlList*)pControl)->strTextureButton) string(); new(&((ControlList*)pControl)->strTextureButtonFocus) string(); new(&((ControlList*)pControl)->vecItems) std::vector<PYXBMC::ListItem*>(); // create a python spin control ((ControlList*)pControl)->pControlSpin = (ControlSpin*)ControlSpin_New(); break; case CGUIControl::GUICONTROL_GROUP: pControl = (Control*)ControlGroup_Type.tp_alloc(&ControlGroup_Type, 0); break; case CGUIControl::GUICONTROL_RADIO: pControl = (Control*)ControlRadioButton_Type.tp_alloc(&ControlRadioButton_Type, 0); new(&((ControlRadioButton*)pControl)->strFont) string(); new(&((ControlRadioButton*)pControl)->strText) string(); new(&((ControlRadioButton*)pControl)->strTextureFocus) string(); new(&((ControlRadioButton*)pControl)->strTextureNoFocus) string(); new(&((ControlRadioButton*)pControl)->strTextureRadioFocus) string(); new(&((ControlRadioButton*)pControl)->strTextureRadioNoFocus) string(); 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 = (Control*)ControlEdit_Type.tp_alloc(&ControlEdit_Type, 0); new(&((ControlEdit*)pControl)->strFont) string(); new(&((ControlEdit*)pControl)->strText) string(); new(&((ControlEdit*)pControl)->strTextureFocus) string(); new(&((ControlEdit*)pControl)->strTextureNoFocus) string(); 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 PyErr_SetString(PyExc_Exception, "Unknown control type for python"); return NULL; } Py_INCREF(pControl); // we have a valid control here, fill in all the 'Control' data pControl->pGUIControl = pGUIControl; pControl->iControlId = pGUIControl->GetID(); pControl->iParentId = self->iWindowId; pControl->dwHeight = (int)pGUIControl->GetHeight(); pControl->dwWidth = (int)pGUIControl->GetWidth(); pControl->dwPosX = (int)pGUIControl->GetXPosition(); pControl->dwPosY = (int)pGUIControl->GetYPosition(); pControl->iControlUp = pGUIControl->GetControlIdUp(); pControl->iControlDown = pGUIControl->GetControlIdDown(); pControl->iControlLeft = pGUIControl->GetControlIdLeft(); pControl->iControlRight = pGUIControl->GetControlIdRight(); // 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 self->vecControls.push_back(pControl); // return the control with increased reference (+1) return pControl; }
PyObject* ControlList_New(PyTypeObject *type, PyObject *args, PyObject *kwds) { static const char *keywords[] = { "x", "y", "width", "height", "font", "textColor", "buttonTexture", "buttonFocusTexture", // maintain order of above items for backward compatibility "selectedColor", "imageWidth", "imageHeight", "itemTextXOffset", "itemTextYOffset", "itemHeight", "space", "alignmentY", NULL };//"shadowColor", NULL }; ControlList *self; char *cFont = NULL; char *cTextColor = NULL; char *cSelectedColor = NULL; char *cTextureButton = NULL; char *cTextureButtonFocus = NULL; //char* cShadowColor = NULL; self = (ControlList*)type->tp_alloc(type, 0); if (!self) return NULL; new(&self->strFont) string(); new(&self->strTextureButton) string(); new(&self->strTextureButtonFocus) string(); new(&self->vecItems) std::vector<PYXBMC::ListItem*>(); // create a python spin control self->pControlSpin = (ControlSpin*)ControlSpin_New(); if (!self->pControlSpin) { Py_DECREF( self ); return NULL; } // initialize default values self->strFont = "font13"; self->dwTextColor = 0xe0f0f0f0; self->dwSelectedColor = 0xffffffff; self->dwImageHeight = 10; self->dwImageWidth = 10; self->dwItemHeight = 27; self->dwSpace = 2; self->dwItemTextXOffset = CONTROL_TEXT_OFFSET_X; self->dwItemTextYOffset = CONTROL_TEXT_OFFSET_Y; self->dwAlignmentY = XBFONT_CENTER_Y; //self->dwShadowColor = NULL; if (!PyArg_ParseTupleAndKeywords( args, kwds, (char*)"llll|ssssslllllll",//s", (char**)keywords, &self->dwPosX, &self->dwPosY, &self->dwWidth, &self->dwHeight, &cFont, &cTextColor, &cTextureButton, &cTextureButtonFocus, &cSelectedColor, &self->dwImageWidth, &self->dwImageHeight, &self->dwItemTextXOffset, &self->dwItemTextYOffset, &self->dwItemHeight, &self->dwSpace, &self->dwAlignmentY//, ))//&cShadowColor)) { Py_DECREF( self ); return NULL; } // set specified values if (cFont) self->strFont = cFont; if (cTextColor) { sscanf( cTextColor, "%x", &self->dwTextColor ); } if (cSelectedColor) { sscanf( cSelectedColor, "%x", &self->dwSelectedColor ); } //if (cShadowColor) sscanf( cShadowColor, "%x", &self->dwShadowColor ); self->strTextureButton = cTextureButton ? cTextureButton : PyGetDefaultImage((char*)"listcontrol", (char*)"texturenofocus", (char*)"list-nofocus.png"); self->strTextureButtonFocus = cTextureButtonFocus ? cTextureButtonFocus : PyGetDefaultImage((char*)"listcontrol", (char*)"texturefocus", (char*)"list-focus.png"); // default values for spin control self->pControlSpin->dwPosX = self->dwWidth - 35; self->pControlSpin->dwPosY = self->dwHeight - 15; return (PyObject*)self; }