1
0

browserUiHook.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #include "main.h"
  2. #include "./browserUiHook.h"
  3. #include "./browserUiCommon.h"
  4. #include "./browserUiInternal.h"
  5. #include "./browserPopup.h"
  6. #include "./browserHost.h"
  7. #include "./ifc_omservice.h"
  8. #include "./ifc_omserviceeventmngr.h"
  9. #include "./ifc_omservicecommand.h"
  10. #include "./ifc_omtoolbarconfig.h"
  11. #include "./ifc_omstatusbarconfig.h"
  12. #include "./ifc_omserviceeditor.h"
  13. #include "./ifc_omconfig.h"
  14. #include "./obj_ombrowser.h"
  15. #include "./toolbar.h"
  16. #include "./statusbar.h"
  17. #include "../winamp/IWasabiDispatchable.h"
  18. #include "../winamp/JSAPI_Info.h"
  19. #include <strsafe.h>
  20. BrowserUiHook::BrowserUiHook(HWND hTarget, BOOL fPopupMode)
  21. : ref(1), popupMode(fPopupMode), hwnd(hTarget), winampCookie(NULL), configCookie(NULL)
  22. {
  23. }
  24. BrowserUiHook::~BrowserUiHook()
  25. {
  26. }
  27. HRESULT BrowserUiHook::CreateInstance(HWND hTarget, BOOL fPopupMode, BrowserUiHook **instance)
  28. {
  29. if (NULL == instance) return E_POINTER;
  30. *instance = NULL;
  31. if (NULL == hTarget || FALSE == IsWindow(hTarget))
  32. return E_INVALIDARG;
  33. *instance = new BrowserUiHook(hTarget, fPopupMode);
  34. if (NULL == *instance) return E_OUTOFMEMORY;
  35. return S_OK;
  36. }
  37. size_t BrowserUiHook::AddRef()
  38. {
  39. return InterlockedIncrement((LONG*)&ref);
  40. }
  41. size_t BrowserUiHook::Release()
  42. {
  43. if (0 == ref)
  44. return ref;
  45. LONG r = InterlockedDecrement((LONG*)&ref);
  46. if (0 == r)
  47. delete(this);
  48. return r;
  49. }
  50. int BrowserUiHook::QueryInterface(GUID interface_guid, void **object)
  51. {
  52. if (NULL == object) return E_POINTER;
  53. if (IsEqualIID(interface_guid, IFC_WinampHook))
  54. *object = static_cast<ifc_winamphook*>(this);
  55. else if (IsEqualIID(interface_guid, IFC_OmServiceEvent))
  56. *object = static_cast<ifc_omserviceevent*>(this);
  57. else if (IsEqualIID(interface_guid, IFC_OmConfigCallback))
  58. *object = static_cast<ifc_omconfigcallback*>(this);
  59. else
  60. {
  61. *object = NULL;
  62. return E_NOINTERFACE;
  63. }
  64. if (NULL == *object)
  65. return E_UNEXPECTED;
  66. AddRef();
  67. return S_OK;
  68. }
  69. HRESULT BrowserUiHook::SkinChanging(void)
  70. {
  71. if (FALSE != popupMode)
  72. {
  73. BrowserPopup_SkinRefreshing(hwnd);
  74. PostMessage(hwnd, NBPM_SKINREFRESHED, 0, 0L);
  75. }
  76. return S_OK;
  77. }
  78. HRESULT BrowserUiHook::SkinChanged(const wchar_t *skinName)
  79. {
  80. PostMessage(hwnd, NBCM_UPDATESKIN, 0, TRUE);
  81. return S_OK;
  82. }
  83. HRESULT BrowserUiHook::SkinColorChange(const wchar_t *colorTheme)
  84. {
  85. PostMessage(hwnd, NBCM_UPDATESKIN, 0, TRUE);
  86. return S_OK;
  87. }
  88. HRESULT BrowserUiHook::ResetFont(void)
  89. {
  90. PostMessage(hwnd, NBCM_UPDATESKIN, 0, TRUE);
  91. return S_OK;
  92. }
  93. void BrowserUiHook::ServiceChange(ifc_omservice *service, UINT nModified)
  94. {
  95. ifc_omservice *windowService;
  96. if (FALSE == (BOOL)SendMessage(hwnd, NBCM_GETSERVICE, 0, (LPARAM)&windowService) || NULL == windowService)
  97. return;
  98. if (windowService != service) return;
  99. if (0 != (ifc_omserviceeditor::modifiedName & nModified))
  100. {
  101. IDispatch *pDispatch;
  102. if (SUCCEEDED(windowService->GetExternal(&pDispatch) && NULL != pDispatch))
  103. {
  104. IWasabiDispatchable *pWasabi;
  105. if (SUCCEEDED(pDispatch->QueryInterface(IID_IWasabiDispatchable, (void**)&pWasabi)))
  106. {
  107. JSAPI::ifc_info *info = NULL;
  108. if (SUCCEEDED(pWasabi->QueryDispatchable(JSAPI::IID_JSAPI_ifc_info, (Dispatchable**)&info)))
  109. {
  110. WCHAR szName[512] = {0};
  111. if (FAILED(service->GetName(szName, ARRAYSIZE(szName))))
  112. StringCchCopy(szName, ARRAYSIZE(szName), L"Unknown");
  113. info->SetName(szName);
  114. info->Release();
  115. }
  116. pWasabi->Release();
  117. }
  118. pDispatch->Release();
  119. }
  120. if (FALSE != popupMode)
  121. PostMessage(hwnd, NBPM_REFRESHTITLE, 0, 0L);
  122. }
  123. if (0 != (ifc_omserviceeditor::modifiedRating & nModified))
  124. {
  125. HWND hToolbar = BrowserControl_GetToolbar(hwnd);
  126. if (NULL != hToolbar)
  127. {
  128. UINT rating;
  129. if(SUCCEEDED(service->GetRating(&rating)))
  130. {
  131. Toolbar_SetItemInt(hToolbar, TOOLITEM_USERRATING, rating);
  132. }
  133. }
  134. }
  135. if (0 != (ifc_omserviceeditor::modifiedGeneration & nModified))
  136. {
  137. HWND hHost = BrowserControl_GetHost(hwnd);
  138. if (NULL != hHost) PostMessage(hHost, NBHM_UPDATEEXTERNAL, 0 , 0L);
  139. }
  140. }
  141. void BrowserUiHook::CommandStateChange(ifc_omservice *service, const GUID *commandGroup, unsigned int commandId)
  142. {
  143. if (NULL != commandGroup)
  144. {
  145. if (IsEqualGUID(CMDGROUP_SERVICE, *commandGroup))
  146. {
  147. switch(commandId)
  148. {
  149. case SVCCOMMAND_BLOCKNAV:
  150. CheckBlockedState(service);
  151. break;
  152. }
  153. }
  154. }
  155. }
  156. HRESULT BrowserUiHook::ValueChanged(const GUID *configUid, UINT valueId, ULONG_PTR value)
  157. {
  158. if (NULL == configUid)
  159. return E_UNEXPECTED;
  160. if (IsEqualIID(IFC_OmToolbarConfig, *configUid))
  161. {
  162. HWND hToolbar = (HWND)SendMessage(hwnd, NBCM_GETTOOLBAR, 0, 0L);
  163. if (NULL == hToolbar) return S_FALSE;
  164. switch(valueId)
  165. {
  166. case CFGID_TOOLBAR_BOTTOMDOCK: Toolbar_EnableBottomDock(hToolbar, (BOOL)value); break;
  167. case CFGID_TOOLBAR_AUTOHIDE: Toolbar_EnableAutoHide(hToolbar, (BOOL)value); break;
  168. case CFGID_TOOLBAR_TABSTOP: Toolbar_EnableTabStop(hToolbar, (BOOL)value); break;
  169. case CFGID_TOOLBAR_FORCEADDRESS: Toolbar_EnableForceAddress(hToolbar, (BOOL)value); break;
  170. case CFGID_TOOLBAR_FANCYADDRESS: Toolbar_EnableFancyAddress(hToolbar, (BOOL)value); break;
  171. }
  172. }
  173. else if (IsEqualIID(IFC_OmStatusbarConfig, *configUid))
  174. {
  175. HWND hStatusbar = (HWND)SendMessage(hwnd, NBCM_GETSTATUSBAR, 0, 0L);
  176. if (NULL == hStatusbar) return S_FALSE;
  177. switch(valueId)
  178. {
  179. case CFGID_STATUSBAR_ENABLED: Statusbar_Enable(hStatusbar, (BOOL)value); break;
  180. }
  181. }
  182. return S_OK;
  183. }
  184. HRESULT BrowserUiHook::Register(obj_ombrowser *browserManager, ifc_omservice *service)
  185. {
  186. Plugin_RegisterWinampHook(this, &winampCookie);
  187. ifc_omconfig *config;
  188. if (NULL != browserManager && SUCCEEDED(browserManager->GetConfig(NULL, (void**)&config)))
  189. {
  190. config->RegisterCallback(this, &configCookie);
  191. config->Release();
  192. }
  193. ifc_omserviceeventmngr *eventManager;
  194. if (NULL != service && SUCCEEDED(service->QueryInterface(IFC_OmServiceEventMngr, (void**)&eventManager)))
  195. {
  196. eventManager->RegisterHandler(this);
  197. eventManager->Release();
  198. }
  199. return S_OK;
  200. }
  201. HRESULT BrowserUiHook::Unregister(obj_ombrowser *browserManager, ifc_omservice *service)
  202. {
  203. if (0 != configCookie)
  204. {
  205. ifc_omconfig *config;
  206. if (NULL != browserManager && SUCCEEDED(browserManager->GetConfig(NULL, (void**)&config)))
  207. {
  208. config->UnregisterCallback(configCookie);
  209. config->Release();
  210. }
  211. configCookie = 0;
  212. }
  213. ifc_omserviceeventmngr *eventManager;
  214. if (NULL != service && SUCCEEDED(service->QueryInterface(IFC_OmServiceEventMngr, (void**)&eventManager)))
  215. {
  216. eventManager->UnregisterHandler(this);
  217. eventManager->Release();
  218. }
  219. if (0 != winampCookie)
  220. {
  221. Plugin_UnregisterWinampHook(winampCookie);
  222. winampCookie = 0;
  223. }
  224. return S_OK;
  225. }
  226. HRESULT BrowserUiHook::CheckBlockedState(ifc_omservice *service)
  227. {
  228. if (NULL == service)
  229. return E_INVALIDARG;
  230. HRESULT hr;
  231. ifc_omservicecommand *serviceCommand;
  232. hr = service->QueryInterface(IFC_OmServiceCommand, (void**)&serviceCommand);
  233. if (SUCCEEDED(hr))
  234. {
  235. HRESULT state = serviceCommand->QueryState(hwnd, &CMDGROUP_SERVICE, SVCCOMMAND_BLOCKNAV);
  236. PostMessage(hwnd, NBCM_BLOCK, 0, (CMDSTATE_ENABLED == state));
  237. serviceCommand->Release();
  238. }
  239. return hr;
  240. }
  241. #define CBCLASS BrowserUiHook
  242. START_MULTIPATCH;
  243. START_PATCH(MPIID_WINAMPHOOK)
  244. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, ADDREF, AddRef);
  245. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, RELEASE, Release);
  246. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, QUERYINTERFACE, QueryInterface);
  247. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, API_SKINCHANGING, SkinChanging);
  248. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, API_SKINCHANGED, SkinChanged);
  249. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, API_SKINCOLORCHANGE, SkinColorChange);
  250. M_CB(MPIID_WINAMPHOOK, ifc_winamphook, API_RESETFONT, ResetFont);
  251. NEXT_PATCH(MPIID_SERVICEEVENT)
  252. M_CB(MPIID_SERVICEEVENT, ifc_omserviceevent, ADDREF, AddRef);
  253. M_CB(MPIID_SERVICEEVENT, ifc_omserviceevent, RELEASE, Release);
  254. M_CB(MPIID_SERVICEEVENT, ifc_omserviceevent, QUERYINTERFACE, QueryInterface);
  255. M_VCB(MPIID_SERVICEEVENT, ifc_omserviceevent, API_SERVICECHANGE, ServiceChange);
  256. M_VCB(MPIID_SERVICEEVENT, ifc_omserviceevent, API_COMMANDSTATECHANGE, CommandStateChange);
  257. NEXT_PATCH(MPIID_CONFIGCALLBACK)
  258. M_CB(MPIID_CONFIGCALLBACK, ifc_omconfigcallback, ADDREF, AddRef);
  259. M_CB(MPIID_CONFIGCALLBACK, ifc_omconfigcallback, RELEASE, Release);
  260. M_CB(MPIID_CONFIGCALLBACK, ifc_omconfigcallback, QUERYINTERFACE, QueryInterface);
  261. M_CB(MPIID_CONFIGCALLBACK, ifc_omconfigcallback, API_VALUECHANGED, ValueChanged);
  262. END_PATCH
  263. END_MULTIPATCH;
  264. #undef CBCLASS