FX_BOOL Document::icons(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsSetting()) { CJS_Context* pContext = static_cast<CJS_Context*>(cc); sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); return FALSE; } if (!m_pIconTree) { vp.SetNull(); return TRUE; } CJS_Array Icons(m_isolate); IconElement* pIconElement = NULL; int iIconTreeLength = m_pIconTree->GetLength(); CJS_Context* pContext = (CJS_Context *)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); for (int i = 0; i < iIconTreeLength; i++) { pIconElement = (*m_pIconTree)[i]; JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon")); if (pObj.IsEmpty()) return FALSE; CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj); if (!pJS_Icon) return FALSE; Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); if (!pIcon)return FALSE; pIcon->SetStream(pIconElement->IconStream->GetStream()); pIcon->SetIconName(pIconElement->IconName); Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon)); } vp << Icons; return TRUE; }
FX_BOOL Document::getIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { CJS_Context* pContext = (CJS_Context *)cc; if (params.size() != 1) { sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); return FALSE; } if(!m_pIconTree) return FALSE; CFX_WideString swIconName = params[0].ToCFXWideString(); int iIconCounts = m_pIconTree->GetLength(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); for (int i = 0; i < iIconCounts; i++) { if ((*m_pIconTree)[i]->IconName == swIconName) { Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon")); if (pObj.IsEmpty()) return FALSE; CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj); if (!pJS_Icon) return FALSE; Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); if (!pIcon)return FALSE; pIcon->SetIconName(swIconName); pIcon->SetStream(pRetIcon->GetStream()); vRet = pJS_Icon; return TRUE; } } return FALSE; }