1
0

setupServicePanel.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #include "../common.h"
  2. #include "./setupServicePanel.h"
  3. #include "./setupDetails.h"
  4. #include "./setupPage.h"
  5. #include "../resource.h"
  6. #include "../api__ml_online.h"
  7. #include <ifc_omservice.h>
  8. #include <ifc_omservicedetails.h>
  9. #include <ifc_omcachemanager.h>
  10. #include <ifc_omcachegroup.h>
  11. #include <ifc_omcacherecord.h>
  12. #include <ifc_imageloader.h>
  13. #include <ifc_omgraphics.h>
  14. #include <ifc_omserviceeventmngr.h>
  15. #include <ifc_omserviceeditor.h>
  16. #include <shlwapi.h>
  17. #include <strsafe.h>
  18. #define GetPanel(__hwnd) ((ServicePanel*)GetPropW((__hwnd), MAKEINTATOM(DETAILS_PROP)))
  19. #define GET_IDETAILS(__service, __details)\
  20. (NULL != (service) && SUCCEEDED((service)->QueryInterface(IFC_OmServiceDetails, (void**)&(__details))))
  21. ServicePanel::ServicePanel(LPCWSTR pszName, ifc_omservice *service)
  22. : ref(1), name(NULL), service(NULL), hwnd(NULL), fontTitle(NULL), fontMeta(NULL), thumbnailCache(NULL)
  23. {
  24. name = Plugin_CopyString(pszName);
  25. this->service = service;
  26. if (NULL != service)
  27. service->AddRef();
  28. }
  29. ServicePanel::~ServicePanel()
  30. {
  31. Plugin_FreeString(name);
  32. if (NULL != service)
  33. service->Release();
  34. if (NULL != fontTitle)
  35. DeleteObject(fontTitle);
  36. if (NULL != fontMeta)
  37. DeleteObject(fontMeta);
  38. if (NULL != thumbnailCache)
  39. thumbnailCache->Release();
  40. }
  41. HWND ServicePanel::CreateInstance(HWND hParent, LPCWSTR pszName, ifc_omservice *service, ServicePanel **instance)
  42. {
  43. ServicePanel *panel = new ServicePanel(pszName, service);
  44. if (NULL == panel)
  45. {
  46. if (NULL != instance) *instance = NULL;
  47. return NULL;
  48. }
  49. HWND hwnd = WASABI_API_CREATEDIALOGPARAMW(IDD_SETUP_SERVICEDETAILS, hParent, ServicePanel_DialogProc, (LPARAM)panel);
  50. if (NULL != instance)
  51. {
  52. if (NULL != hwnd)
  53. {
  54. *instance = panel;
  55. panel->AddRef();
  56. }
  57. else
  58. *instance = NULL;
  59. }
  60. panel->Release();
  61. return hwnd;
  62. }
  63. size_t ServicePanel::AddRef()
  64. {
  65. return InterlockedIncrement((LONG*)&ref);
  66. }
  67. size_t ServicePanel::Release()
  68. {
  69. if (0 == ref)
  70. return ref;
  71. LONG r = InterlockedDecrement((LONG*)&ref);
  72. if (0 == r)
  73. delete(this);
  74. return r;
  75. }
  76. int ServicePanel::QueryInterface(GUID interface_guid, void **object)
  77. {
  78. if (NULL == object) return E_POINTER;
  79. if (IsEqualIID(interface_guid, IFC_OmServiceEvent))
  80. *object = static_cast<ifc_omserviceevent*>(this);
  81. else
  82. {
  83. *object = NULL;
  84. return E_NOINTERFACE;
  85. }
  86. if (NULL == *object)
  87. return E_UNEXPECTED;
  88. AddRef();
  89. return S_OK;
  90. }
  91. static void CALLBACK ThreadCallback_ServiceChange(Dispatchable *instance, ULONG_PTR param1, ULONG_PTR param2)
  92. {
  93. ifc_omserviceevent *panel = (ifc_omserviceevent*)instance;
  94. ifc_omservice *service = (ifc_omservice*)param1;
  95. if (NULL != service)
  96. {
  97. if (NULL != panel)
  98. panel->ServiceChange(service, (UINT)param2);
  99. service->Release();
  100. }
  101. }
  102. void ServicePanel::ServiceChange(ifc_omservice *service, unsigned int modifiedFlags)
  103. {
  104. DWORD currentTID = GetCurrentThreadId();
  105. DWORD windowTID = GetWindowThreadProcessId(hwnd, NULL);
  106. if (NULL != windowTID && currentTID != windowTID)
  107. {
  108. if(NULL != OMUTILITY)
  109. {
  110. service->AddRef();
  111. if (FAILED(OMUTILITY->PostMainThreadCallback2(ThreadCallback_ServiceChange, (ifc_omserviceevent*)this, (ULONG_PTR)service, (ULONG_PTR)modifiedFlags)))
  112. service->Release();
  113. }
  114. return;
  115. }
  116. if ( 0 != (ifc_omserviceeditor::modifiedName & modifiedFlags))
  117. {
  118. UpdateName();
  119. HWND hPage = GetParent(hwnd);
  120. if (NULL != hPage)
  121. PostMessage(hPage, SPM_UPDATELIST, (WPARAM)service->GetId(), NULL);
  122. }
  123. if ( 0 != (ifc_omserviceeditor::modifiedDescription & modifiedFlags))
  124. UpdateDescription();
  125. if ( 0 != (ifc_omserviceeditor::modifiedThumbnail& modifiedFlags))
  126. UpdateThumbnail();
  127. if ( 0 != ((ifc_omserviceeditor::modifiedAuthorFirst |
  128. ifc_omserviceeditor::modifiedAuthorLast |
  129. ifc_omserviceeditor::modifiedUpdated |
  130. ifc_omserviceeditor::modifiedPublished) & modifiedFlags))
  131. {
  132. UpdateMeta();
  133. }
  134. }
  135. HRESULT ServicePanel::LoadLocalThumbnail(LPCWSTR pszPath)
  136. {
  137. HWND hThumbnail = GetDlgItem(hwnd, IDC_THUMBNAIL);
  138. if (NULL == hThumbnail) return E_UNEXPECTED;
  139. SendMessage(hThumbnail, WM_SETREDRAW, FALSE, 0L);
  140. HBITMAP hBitmap = NULL;
  141. BITMAPINFOHEADER header;
  142. void *pixelData;
  143. ifc_omimageloader *imageLoader;
  144. if (SUCCEEDED(OMUTILITY->QueryImageLoader(NULL, pszPath, FALSE, &imageLoader)))
  145. {
  146. imageLoader->LoadBitmapEx(&hBitmap, &header, &pixelData);
  147. imageLoader->Release();
  148. }
  149. if (NULL == hBitmap &&
  150. SUCCEEDED(OMUTILITY->QueryImageLoader(WASABI_API_ORIG_HINST, MAKEINTRESOURCE(IDR_SERVICE64X64_IMAGE), FALSE, &imageLoader)))
  151. {
  152. imageLoader->LoadBitmapEx(&hBitmap, &header, &pixelData);
  153. imageLoader->Release();
  154. }
  155. HBITMAP hTest = (HBITMAP)SendMessage(hThumbnail, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
  156. if (NULL != hTest)
  157. DeleteObject(hTest);
  158. if (NULL != hBitmap)
  159. {
  160. hTest = (HBITMAP)SendMessage(hThumbnail, STM_GETIMAGE, IMAGE_BITMAP, 0L);
  161. if (hTest != hBitmap)
  162. { // this is XP and up image copy was created and alpha channel will be handled properly
  163. DeleteObject(hBitmap);
  164. }
  165. else
  166. { // fix alpha channel
  167. if (32 == header.biBitCount)
  168. {
  169. HDC hdcFixed = CreateCompatibleDC(NULL);
  170. if (NULL != hdcFixed)
  171. {
  172. BITMAPINFOHEADER headerFixed;
  173. CopyMemory(&headerFixed, &header, sizeof(BITMAPINFOHEADER));
  174. BYTE *pixelsFixed;
  175. INT cx = header.biWidth;
  176. INT cy = abs(header.biHeight);
  177. HBITMAP bitmapFixed = CreateDIBSection(NULL, (LPBITMAPINFO)&headerFixed, DIB_RGB_COLORS, (void**)&pixelsFixed, NULL, 0);
  178. if (NULL != bitmapFixed)
  179. {
  180. HBITMAP bitmapOrig = (HBITMAP)SelectObject(hdcFixed, bitmapFixed);
  181. HBRUSH hb = (HBRUSH)SendMessage(hwnd, WM_CTLCOLORDLG, (WPARAM)hdcFixed, (LPARAM)hwnd);
  182. if (NULL == hb)
  183. hb = GetSysColorBrush(COLOR_3DFACE);
  184. RECT rect;
  185. SetRect(&rect, 0, 0, cx, cy);
  186. FillRect(hdcFixed, &rect, hb);
  187. ifc_omgraphics *graphics;
  188. if (SUCCEEDED(OMUTILITY->GetGraphics(&graphics)))
  189. {
  190. HDC hdcSrc = CreateCompatibleDC(NULL);
  191. if (NULL != hdcSrc)
  192. {
  193. HBITMAP bitmapSrcOrig = (HBITMAP)SelectObject(hdcSrc, hBitmap);
  194. BLENDFUNCTION bf;
  195. bf.BlendOp = AC_SRC_OVER;
  196. bf.BlendFlags = 0;
  197. bf.SourceConstantAlpha = 0xFF;
  198. bf.AlphaFormat = AC_SRC_ALPHA;
  199. RECT blendRect;
  200. SetRect(&blendRect, 0, 0, cx, cy);
  201. graphics->Premultiply((BYTE*)pixelData, cx, cy);
  202. graphics->AlphaBlend(hdcFixed, &blendRect, hdcSrc, &blendRect, bf);
  203. SelectObject(hdcSrc, bitmapSrcOrig);
  204. DeleteDC(hdcSrc);
  205. }
  206. graphics->Release();
  207. }
  208. SelectObject(hdcFixed, bitmapOrig);
  209. SendMessage(hThumbnail, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bitmapFixed);
  210. DeleteObject(hBitmap);
  211. }
  212. DeleteDC(hdcFixed);
  213. }
  214. }
  215. }
  216. }
  217. RECT clientRect;
  218. if (GetClientRect(hThumbnail, &clientRect))
  219. {
  220. INT cx = clientRect.right - clientRect.left;
  221. INT cy = clientRect.bottom - clientRect.top;
  222. if (64 != cx || 64 != cy)
  223. {
  224. SetWindowPos(hThumbnail, NULL, 0, 0, 64, 64, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
  225. }
  226. }
  227. SendMessage(hThumbnail, WM_SETREDRAW, TRUE, 0L);
  228. if (0 != ShowWindow(hThumbnail, (NULL != hBitmap) ? SW_SHOWNA : SW_HIDE))
  229. InvalidateRect(hThumbnail, NULL, TRUE);
  230. return S_OK;
  231. }
  232. static void CALLBACK ThreadCallback_PathChanged(Dispatchable *instance, ULONG_PTR param1, ULONG_PTR param2)
  233. {
  234. ifc_omcachecallback *panel = (ifc_omcachecallback*)instance;
  235. ifc_omcacherecord *record = (ifc_omcacherecord*)param1;
  236. if (NULL != record)
  237. {
  238. if (NULL != panel)
  239. panel->PathChanged(record);
  240. record->Release();
  241. }
  242. }
  243. void ServicePanel::PathChanged(ifc_omcacherecord *record)
  244. {
  245. if (NULL == hwnd || FALSE == IsWindow(hwnd))
  246. return;
  247. DWORD currentTID = GetCurrentThreadId();
  248. DWORD windowTID = GetWindowThreadProcessId(hwnd, NULL);
  249. if (NULL != windowTID && currentTID != windowTID)
  250. {
  251. if(NULL != OMUTILITY)
  252. {
  253. record->AddRef();
  254. if (FAILED(OMUTILITY->PostMainThreadCallback2(ThreadCallback_PathChanged, (ifc_omcachecallback*)this, (ULONG_PTR)record, 0L)))
  255. record->Release();
  256. }
  257. return;
  258. }
  259. WCHAR szPath[2048] = {0};
  260. if (FAILED(record->GetPath(szPath, ARRAYSIZE(szPath))))
  261. szPath[0] = L'\0';
  262. LoadLocalThumbnail(szPath);
  263. }
  264. void ServicePanel::Attach(HWND hwnd)
  265. {
  266. this->hwnd = hwnd;
  267. if (NULL != hwnd &&
  268. FALSE != SetProp(hwnd, MAKEINTATOM(DETAILS_PROP), this))
  269. {
  270. AddRef();
  271. }
  272. }
  273. void ServicePanel::Detach()
  274. {
  275. RemoveProp(hwnd, MAKEINTATOM(DETAILS_PROP));
  276. if (NULL != thumbnailCache)
  277. {
  278. thumbnailCache->UnregisterCallback(this);
  279. thumbnailCache->Release();
  280. thumbnailCache = NULL;
  281. }
  282. if (NULL != service)
  283. {
  284. ifc_omserviceeventmngr *eventManager;
  285. if (SUCCEEDED(service->QueryInterface(IFC_OmServiceEventMngr, (void**)&eventManager)))
  286. {
  287. eventManager->UnregisterHandler(this);
  288. eventManager->Release();
  289. }
  290. }
  291. Release();
  292. }
  293. HFONT ServicePanel::PickTitleFont(LPCWSTR pszTitle, INT cchTitle, INT maxWidth)
  294. {
  295. HFONT dialogFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0L);
  296. LOGFONT lf;
  297. if (0 == GetObject(dialogFont, sizeof(LOGFONT), &lf))
  298. return NULL;
  299. HFONT titleFont = NULL;
  300. if (cchTitle > 0)
  301. {
  302. LOGFONT lf;
  303. if (0 != GetObject(dialogFont, sizeof(LOGFONT), &lf))
  304. {
  305. StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"Arial Bold");
  306. lf.lfWidth = 0;
  307. lf.lfWeight = FW_DONTCARE;
  308. lf.lfQuality = 5/*ANTIALIASED_QUALITY*/;
  309. HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  310. if (NULL != hdc)
  311. {
  312. HFONT origFont = (HFONT)GetCurrentObject(hdc, OBJ_FONT);
  313. SIZE textSize;
  314. INT heightLimit = (lf.lfHeight < 0) ? 1 : -1;
  315. lf.lfHeight += (lf.lfHeight < 0) ? -2 : +2;
  316. do
  317. {
  318. textSize.cx = 0;
  319. if (NULL != titleFont) DeleteObject(titleFont);
  320. titleFont = CreateFontIndirect(&lf);
  321. if (NULL != titleFont)
  322. {
  323. SelectObject(hdc, titleFont);
  324. GetTextExtentPoint32(hdc, pszTitle, cchTitle, &textSize);
  325. }
  326. lf.lfHeight += (lf.lfHeight < 0) ? 1 : -1;
  327. } while(textSize.cx > maxWidth && lf.lfHeight != heightLimit);
  328. if (0 == textSize.cx)
  329. {
  330. DeleteObject(titleFont);
  331. titleFont = NULL;
  332. }
  333. SelectObject(hdc, origFont);
  334. ReleaseDC(hwnd, hdc);
  335. }
  336. }
  337. }
  338. if (NULL == titleFont &&
  339. 0 != GetObject(dialogFont, sizeof(LOGFONT), &lf))
  340. {
  341. titleFont = CreateFontIndirect(&lf);
  342. }
  343. return titleFont;
  344. }
  345. LPCWSTR ServicePanel::FormatDate(LPCWSTR pszDate, LPWSTR pszBuffer, INT cchBufferMax)
  346. {
  347. SYSTEMTIME st;
  348. ZeroMemory(&st, sizeof(SYSTEMTIME));
  349. LPCWSTR cursor;
  350. cursor = pszDate;
  351. INT index = 0;
  352. for(;;)
  353. {
  354. INT iVal;
  355. if (FALSE == StrToIntEx(cursor, STIF_DEFAULT, &iVal) || iVal < 1)
  356. {
  357. index = 0;
  358. break;
  359. }
  360. if (0 == index)
  361. {
  362. if (iVal < 2000 || iVal > 2100)
  363. break;
  364. st.wYear = iVal;
  365. index++;
  366. }
  367. else if (1 == index)
  368. {
  369. if (iVal < 1 || iVal > 12)
  370. break;
  371. st.wMonth = iVal;
  372. index++;
  373. }
  374. else if (2 == index)
  375. {
  376. if (iVal < 1 || iVal > 31)
  377. break;
  378. st.wDay = iVal;
  379. index++;
  380. }
  381. else
  382. {
  383. index = 0;
  384. break;
  385. }
  386. while(L'\0' != *cursor && L'-' != *cursor) cursor++;
  387. if (L'-' == *cursor) cursor++;
  388. if (L'\0' == *cursor)
  389. break;
  390. }
  391. if (3 == index &&
  392. 0 != GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, pszBuffer, cchBufferMax))
  393. {
  394. return pszBuffer;
  395. }
  396. return pszDate;
  397. }
  398. HRESULT ServicePanel::GetFullName(LPWSTR pszBuffer, UINT cchBufferMax)
  399. {
  400. if (NULL == pszBuffer)
  401. return E_POINTER;
  402. *pszBuffer = L'\0';
  403. if (NULL == service) return E_UNEXPECTED;
  404. ifc_omservicedetails *details;
  405. HRESULT hr = service->QueryInterface(IFC_OmServiceDetails, (void**)&details);
  406. if (SUCCEEDED(hr))
  407. {
  408. hr = details->GetAuthorFirst(pszBuffer, cchBufferMax);
  409. if (SUCCEEDED(hr))
  410. {
  411. UINT cchBuffer = lstrlen(pszBuffer);
  412. LPWSTR cursor = pszBuffer + cchBuffer;
  413. size_t remaining = cchBufferMax - cchBuffer;
  414. if (cursor != pszBuffer)
  415. {
  416. hr = StringCchCopyEx(cursor, remaining, L" ", &cursor, &remaining, 0);
  417. if (SUCCEEDED(hr))
  418. {
  419. hr = details->GetAuthorLast(cursor, (UINT)remaining);
  420. if (FAILED(hr) || L'\0' == *cursor)
  421. {
  422. pszBuffer[cchBuffer] = L'\0';
  423. }
  424. }
  425. }
  426. }
  427. }
  428. return hr;
  429. }
  430. void ServicePanel::UpdateName()
  431. {
  432. HWND hTitle = GetDlgItem(hwnd, IDC_TITLE);
  433. if (NULL == hTitle) return;
  434. WCHAR szBuffer[128] = {0};
  435. if (NULL == service ||
  436. FAILED(service->GetName(szBuffer, ARRAYSIZE(szBuffer))))
  437. {
  438. szBuffer[0] = L'\0';
  439. }
  440. INT cchBuffer = lstrlen(szBuffer);
  441. RECT rc;
  442. GetClientRect(hTitle, &rc);
  443. HFONT font = PickTitleFont(szBuffer, cchBuffer, rc.right - rc.left);
  444. if (NULL != font)
  445. {
  446. if (NULL != fontTitle)
  447. DeleteObject(fontTitle);
  448. fontTitle = font;
  449. SendMessage(hTitle, WM_SETFONT, (WPARAM)fontTitle, 0L);
  450. }
  451. SetWindowText(hTitle, szBuffer);
  452. InvalidateRect(hTitle, NULL, TRUE);
  453. }
  454. void ServicePanel::UpdateDescription()
  455. {
  456. HWND hDescription = GetDlgItem(hwnd, IDC_DESCRIPTION);
  457. if (NULL == hDescription) return;
  458. WCHAR szBuffer[4096] = {0};
  459. ifc_omservicedetails *details = 0;
  460. if (GET_IDETAILS(service, details))
  461. {
  462. details->GetDescription(szBuffer, ARRAYSIZE(szBuffer));
  463. details->Release();
  464. }
  465. SetupDetails_SetDescription(hDescription, szBuffer);
  466. }
  467. void ServicePanel::UpdateMeta()
  468. {
  469. HWND hMeta = GetDlgItem(hwnd, IDC_SERVICEMETA);
  470. if (NULL == hMeta) return;
  471. WCHAR szBuffer[512] = {0};
  472. ifc_omservicedetails *svcdetails = 0;
  473. if (GET_IDETAILS(service, svcdetails))
  474. {
  475. WCHAR szValue[256] = {0}, szPrefix[64] = {0};
  476. HRESULT hr = S_OK;
  477. LPWSTR cursor = szBuffer;
  478. size_t remaining = ARRAYSIZE(szBuffer);
  479. if (SUCCEEDED(GetFullName(szValue, ARRAYSIZE(szValue))) && L'\0' != szValue[0])
  480. {
  481. WASABI_API_LNGSTRINGW_BUF(IDS_SERVICE_BYAUTHOR, szPrefix, ARRAYSIZE(szPrefix));
  482. hr = StringCchPrintfEx(cursor, remaining, &cursor, &remaining, STRSAFE_NULL_ON_FAILURE,
  483. L"%s%s", szPrefix, szValue);
  484. }
  485. if (SUCCEEDED(svcdetails->GetUpdated(szValue, ARRAYSIZE(szValue))) && L'\0' != szValue[0])
  486. {
  487. if (cursor != szBuffer)
  488. hr = StringCchCopyEx(cursor, remaining, L"\r\n", &cursor, &remaining, STRSAFE_NULL_ON_FAILURE);
  489. if (SUCCEEDED(hr))
  490. {
  491. WCHAR szDate[128] = {0};
  492. WASABI_API_LNGSTRINGW_BUF(IDS_SERVICE_LASTUPDATED, szPrefix, ARRAYSIZE(szPrefix));
  493. StringCchPrintfEx(cursor, remaining, &cursor, &remaining, STRSAFE_NULL_ON_FAILURE,
  494. L"%s%s", szPrefix, FormatDate(szValue, szDate, ARRAYSIZE(szDate)));
  495. }
  496. }
  497. svcdetails->Release();
  498. }
  499. if (NULL == fontMeta)
  500. {
  501. HFONT dialogFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0L);
  502. LOGFONT lf;
  503. if (0 != GetObject(dialogFont, sizeof(LOGFONT), &lf))
  504. {
  505. StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"Tahoma");
  506. lf.lfWidth = 0;
  507. lf.lfHeight += (lf.lfHeight < 0) ? 1 : -1;
  508. lf.lfQuality = ANTIALIASED_QUALITY;
  509. fontMeta = CreateFontIndirect(&lf);
  510. }
  511. if (NULL != fontMeta)
  512. {
  513. SendMessage(hMeta, WM_SETFONT, (WPARAM)fontMeta, 0L);
  514. }
  515. }
  516. SetWindowText(hMeta, szBuffer);
  517. if (0 != ShowWindow(hMeta, (L'\0' != szBuffer[0]) ? SW_SHOWNA : SW_HIDE))
  518. InvalidateRect(hMeta, NULL, TRUE);
  519. }
  520. void ServicePanel::UpdateThumbnail()
  521. {
  522. if (NULL != thumbnailCache)
  523. {
  524. thumbnailCache->UnregisterCallback(this);
  525. thumbnailCache->Release();
  526. thumbnailCache = NULL;
  527. }
  528. LoadLocalThumbnail(NULL);
  529. ifc_omservicedetails *details = 0;
  530. if (GET_IDETAILS(service, details))
  531. {
  532. WCHAR szPath[2048] = {0};
  533. if (SUCCEEDED(details->GetThumbnail(szPath, ARRAYSIZE(szPath))) && L'\0' != szPath[0])
  534. {
  535. ifc_omcachemanager *cacheManager;
  536. if (SUCCEEDED(OMUTILITY->GetCacheManager(&cacheManager)))
  537. {
  538. ifc_omcachegroup *cacheGroup;
  539. if (SUCCEEDED(cacheManager->Find(L"thumbnails", TRUE, &cacheGroup, NULL)))
  540. {
  541. if (SUCCEEDED(cacheGroup->Find(szPath, TRUE, &thumbnailCache, FALSE)))
  542. {
  543. thumbnailCache->RegisterCallback(this);
  544. if (SUCCEEDED(thumbnailCache->GetPath(szPath, ARRAYSIZE(szPath))))
  545. LoadLocalThumbnail(szPath);
  546. }
  547. cacheGroup->Release();
  548. }
  549. cacheManager->Release();
  550. }
  551. }
  552. details->Release();
  553. }
  554. }
  555. INT_PTR ServicePanel::OnInitDialog(HWND hFocus, LPARAM lParam)
  556. {
  557. UpdateName();
  558. UpdateDescription();
  559. UpdateThumbnail();
  560. UpdateMeta();
  561. if (NULL != service)
  562. {
  563. ifc_omserviceeventmngr *eventManager;
  564. if (SUCCEEDED(service->QueryInterface(IFC_OmServiceEventMngr, (void**)&eventManager)))
  565. {
  566. eventManager->RegisterHandler(this);
  567. eventManager->Release();
  568. }
  569. }
  570. return FALSE;
  571. }
  572. void ServicePanel::OnDestroy()
  573. {
  574. HWND hThumbnail = GetDlgItem(hwnd, IDC_THUMBNAIL);
  575. if (NULL != hThumbnail)
  576. {
  577. HBITMAP hBitmap = (HBITMAP)SendMessage(hThumbnail, STM_SETIMAGE, IMAGE_BITMAP, 0L);
  578. if (NULL != hBitmap)
  579. DeleteObject(hBitmap);
  580. }
  581. Detach();
  582. }
  583. INT_PTR ServicePanel::OnDialogColor(HDC hdc, HWND hControl)
  584. {
  585. HWND hParent = GetAncestor(hwnd, GA_PARENT);
  586. if (NULL != hParent && hParent != hwnd)
  587. return (INT_PTR)SendMessage(hParent, WM_CTLCOLORDLG, (WPARAM)hdc, (LPARAM)hControl);
  588. return 0;
  589. }
  590. INT_PTR ServicePanel::OnStaticColor(HDC hdc, HWND hControl)
  591. {
  592. INT_PTR result = 0;
  593. HWND hParent = GetAncestor(hwnd, GA_PARENT);
  594. if (NULL != hParent && hParent != hwnd)
  595. result = (INT_PTR)SendMessage(hParent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hControl);
  596. INT controlId = GetDlgCtrlID(hControl);
  597. switch(controlId)
  598. {
  599. case IDC_SERVICEMETA:
  600. {
  601. COLORREF rgbBk = GetBkColor(hdc);
  602. COLORREF rgbFg = GetTextColor(hdc);
  603. ifc_omgraphics *graphics;
  604. if (SUCCEEDED(OMUTILITY->GetGraphics(&graphics)))
  605. {
  606. graphics->BlendColor(rgbFg, rgbBk, 180, &rgbFg);
  607. graphics->Release();
  608. }
  609. SetTextColor(hdc, rgbFg);
  610. }
  611. break;
  612. }
  613. return result;
  614. }
  615. INT_PTR ServicePanel::OnGetUniqueName(LPWSTR pszBuffer, UINT cchBufferMax)
  616. {
  617. if (NULL == pszBuffer) return FALSE;
  618. return SUCCEEDED(StringCchCopy(pszBuffer, cchBufferMax, (NULL != name) ? name : L""));
  619. }
  620. INT_PTR ServicePanel::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  621. {
  622. switch(uMsg)
  623. {
  624. case WM_INITDIALOG: return OnInitDialog((HWND)wParam, lParam);
  625. case WM_DESTROY: OnDestroy(); break;
  626. case WM_CTLCOLORDLG: return OnDialogColor((HDC)wParam, (HWND)lParam);
  627. case WM_CTLCOLORSTATIC: return OnStaticColor((HDC)wParam, (HWND)lParam);
  628. case NSDM_GETUNIQUENAME: MSGRESULT(hwnd, OnGetUniqueName((LPWSTR)lParam, (UINT)wParam));
  629. }
  630. return 0;
  631. }
  632. static INT_PTR WINAPI ServicePanel_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  633. {
  634. ServicePanel *panel = GetPanel(hwnd);
  635. if (NULL == panel)
  636. {
  637. if (WM_INITDIALOG == uMsg)
  638. {
  639. panel = (ServicePanel*)lParam;
  640. if (NULL != panel)
  641. panel->Attach(hwnd);
  642. }
  643. if (NULL == panel) return 0;
  644. }
  645. return panel->DialogProc(uMsg, wParam, lParam);
  646. }
  647. #define CBCLASS ServicePanel
  648. START_MULTIPATCH;
  649. START_PATCH(MPIID_SERVICEEVENT)
  650. M_CB(MPIID_SERVICEEVENT, ifc_omserviceevent, ADDREF, AddRef);
  651. M_CB(MPIID_SERVICEEVENT, ifc_omserviceevent, RELEASE, Release);
  652. M_CB(MPIID_SERVICEEVENT, ifc_omserviceevent, QUERYINTERFACE, QueryInterface);
  653. M_VCB(MPIID_SERVICEEVENT, ifc_omserviceevent, API_SERVICECHANGE, ServiceChange);
  654. NEXT_PATCH(MPIID_CACHECALLBACK)
  655. M_CB(MPIID_CACHECALLBACK, ifc_omcachecallback, ADDREF, AddRef);
  656. M_CB(MPIID_CACHECALLBACK, ifc_omcachecallback, RELEASE, Release);
  657. M_CB(MPIID_CACHECALLBACK, ifc_omcachecallback, QUERYINTERFACE, QueryInterface);
  658. M_VCB(MPIID_CACHECALLBACK, ifc_omcachecallback, API_PATHCHANGED, PathChanged);
  659. END_PATCH
  660. END_MULTIPATCH;
  661. #undef CBCLASS