1
0

JSAPI2_SkinAPI.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include "JSAPI2_SkinAPI.h"
  2. #include "JSAPI2_Security.h"
  3. #include "main.h"
  4. #include "JSAPI.h"
  5. #include "wa_dlg.h"
  6. #include "api.h"
  7. #include "../nu/AutoWide.h"
  8. #include <tataki/color/skinclr.h>
  9. #include <api/service/waservicefactory.h>
  10. JSAPI2::SkinAPI::SkinAPI(const wchar_t *_key, JSAPI::ifc_info *_info)
  11. {
  12. Tataki::Init(serviceManager); // we might need it, go ahead and init here
  13. info = _info;
  14. key = _key;
  15. refCount = 1;
  16. }
  17. JSAPI2::SkinAPI::~SkinAPI()
  18. {
  19. Tataki::Quit();
  20. }
  21. enum
  22. {
  23. DISPID_SKINAPI_GETCLASSICCOLOR,
  24. DISPID_SKINAPI_GETPLAYLISTCOLOR,
  25. DISPID_SKINAPI_GETSKINCOLOR,
  26. DISPID_SKINAPI_NAME,
  27. DISPID_SKINAPI_FONT,
  28. DISPID_SKINAPI_FONTSIZE,
  29. };
  30. #define DISP_TABLE \
  31. CHECK_ID(GetClassicColor, DISPID_SKINAPI_GETCLASSICCOLOR)\
  32. CHECK_ID(GetPlaylistColor, DISPID_SKINAPI_GETPLAYLISTCOLOR)\
  33. CHECK_ID(GetSkinColor, DISPID_SKINAPI_GETSKINCOLOR)\
  34. CHECK_ID(name, DISPID_SKINAPI_NAME)\
  35. CHECK_ID(font, DISPID_SKINAPI_FONT)\
  36. CHECK_ID(fontsize, DISPID_SKINAPI_FONTSIZE)\
  37. #define CHECK_ID(str, id)\
  38. if (CSTR_EQUAL == CompareStringW(lcid, NORM_IGNORECASE, rgszNames[i], -1, L## #str, -1))\
  39. { rgdispid[i] = id; continue; }
  40. HRESULT JSAPI2::SkinAPI::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  41. {
  42. bool unknowns = false;
  43. for (unsigned int i = 0;i != cNames;i++)
  44. {
  45. DISP_TABLE
  46. rgdispid[i] = DISPID_UNKNOWN;
  47. unknowns = true;
  48. }
  49. if (unknowns)
  50. return DISP_E_UNKNOWNNAME;
  51. else
  52. return S_OK;
  53. }
  54. HRESULT JSAPI2::SkinAPI::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  55. {
  56. return E_NOTIMPL;
  57. }
  58. HRESULT JSAPI2::SkinAPI::GetTypeInfoCount(unsigned int FAR * pctinfo)
  59. {
  60. return E_NOTIMPL;
  61. }
  62. HRESULT JSAPI2::SkinAPI::GetClassicColor(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  63. {
  64. JSAPI_VERIFY_METHOD(wFlags);
  65. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
  66. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
  67. JSAPI_INIT_RESULT(pvarResult, VT_BSTR);
  68. COLORREF color = WADlg_getColor(JSAPI_PARAM(pdispparams, 1).lVal);
  69. color = ((color >> 16) & 0xff | (color & 0xff00) | ((color << 16) & 0xff0000));
  70. wchar_t colorString[8] = {0};
  71. StringCchPrintfW(colorString, 8, L"#%06X", color);
  72. JSAPI_SET_RESULT(pvarResult, bstrVal, SysAllocString(colorString));
  73. return S_OK;
  74. }
  75. HRESULT JSAPI2::SkinAPI::GetPlaylistColor(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  76. {
  77. JSAPI_VERIFY_METHOD(wFlags);
  78. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
  79. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_I4, puArgErr);
  80. JSAPI_INIT_RESULT(pvarResult, VT_BSTR);
  81. COLORREF color = Skin_PLColors[JSAPI_PARAM(pdispparams, 1).lVal];
  82. color = ((color >> 16) & 0xff | (color & 0xff00) | ((color << 16) & 0xff0000));
  83. wchar_t colorString[8] = {0};
  84. StringCchPrintfW(colorString, 8, L"#%06X", color);
  85. JSAPI_SET_RESULT(pvarResult, bstrVal, SysAllocString(colorString));
  86. return S_OK;
  87. }
  88. HRESULT JSAPI2::SkinAPI::GetSkinColor(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  89. {
  90. JSAPI_VERIFY_METHOD(wFlags);
  91. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
  92. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
  93. JSAPI_INIT_RESULT(pvarResult, VT_BSTR);
  94. ARGB32 color;
  95. if (SkinColor::TryGetColor(&color, JSAPI_PARAM(pdispparams, 1).bstrVal))
  96. {
  97. color = ((color >> 16) & 0xff | (color & 0xff00) | ((color << 16) & 0xff0000));
  98. wchar_t colorString[8] = {0};
  99. StringCchPrintfW(colorString, 8, L"#%06X", color);
  100. JSAPI_SET_RESULT(pvarResult, bstrVal, SysAllocString(colorString));
  101. }
  102. else
  103. {
  104. JSAPI_EMPTY_RESULT(pvarResult);
  105. }
  106. return S_OK;
  107. }
  108. HRESULT JSAPI2::SkinAPI::name(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  109. {
  110. if (wFlags & DISPATCH_PROPERTYGET)
  111. {
  112. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 0);
  113. VariantInit(pvarResult);
  114. V_VT(pvarResult) = VT_BSTR;
  115. V_BSTR(pvarResult) = SysAllocString(config_skin);
  116. return S_OK;
  117. }
  118. else
  119. return DISP_E_MEMBERNOTFOUND;
  120. }
  121. HRESULT JSAPI2::SkinAPI::font(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  122. {
  123. if (wFlags & DISPATCH_PROPERTYGET)
  124. {
  125. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 0);
  126. VariantInit(pvarResult);
  127. V_VT(pvarResult) = VT_BSTR;
  128. V_BSTR(pvarResult) = SysAllocString(GetFontNameW());
  129. return S_OK;
  130. }
  131. else
  132. return DISP_E_MEMBERNOTFOUND;
  133. }
  134. HRESULT JSAPI2::SkinAPI::fontsize(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  135. {
  136. if (wFlags & DISPATCH_PROPERTYGET)
  137. {
  138. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 0);
  139. VariantInit(pvarResult);
  140. V_VT(pvarResult) = VT_I4;
  141. V_I4(pvarResult) = GetFontSize();
  142. return S_OK;
  143. }
  144. else
  145. return DISP_E_MEMBERNOTFOUND;
  146. return E_FAIL;
  147. }
  148. #undef CHECK_ID
  149. #define CHECK_ID(str, id) case id: return str(wFlags, pdispparams, pvarResult, puArgErr);
  150. HRESULT JSAPI2::SkinAPI::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  151. {
  152. switch (dispid)
  153. {
  154. DISP_TABLE
  155. }
  156. return DISP_E_MEMBERNOTFOUND;
  157. }
  158. STDMETHODIMP JSAPI2::SkinAPI::QueryInterface(REFIID riid, PVOID *ppvObject)
  159. {
  160. if (!ppvObject)
  161. return E_POINTER;
  162. else if (IsEqualIID(riid, IID_IDispatch))
  163. *ppvObject = (IDispatch *)this;
  164. else if (IsEqualIID(riid, IID_IUnknown))
  165. *ppvObject = this;
  166. else
  167. {
  168. *ppvObject = NULL;
  169. return E_NOINTERFACE;
  170. }
  171. AddRef();
  172. return S_OK;
  173. }
  174. ULONG JSAPI2::SkinAPI::AddRef(void)
  175. {
  176. return InterlockedIncrement(&refCount);
  177. }
  178. ULONG JSAPI2::SkinAPI::Release(void)
  179. {
  180. LONG lRef = InterlockedDecrement(&refCount);
  181. if (lRef == 0) delete this;
  182. return lRef;
  183. }