setupDetailsGroup.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #include "./setupDetails.h"
  2. #include "../common.h"
  3. #include "../resource.h"
  4. #include "../api__ml_online.h"
  5. #include "../../winamp/commandLink.h"
  6. #include "./setupGroup.h"
  7. #include <commctrl.h>
  8. #include <strsafe.h>
  9. #ifndef IDC_HELPLINK
  10. #define IDC_HELPLINK 10000
  11. #endif
  12. struct GROUPDETAILSCREATEPARAM
  13. {
  14. GROUPDETAILSCREATEPARAM() : group(NULL), name(NULL) {}
  15. SetupGroup *group;
  16. LPCWSTR name;
  17. };
  18. struct GROUPDETAILS
  19. {
  20. GROUPDETAILS() : group(NULL), name(NULL), fontTitle(NULL) {}
  21. SetupGroup *group;
  22. LPWSTR name;
  23. HFONT fontTitle;
  24. };
  25. #define GetDetails(__hwnd) ((GROUPDETAILS*)GetPropW((__hwnd), MAKEINTATOM(DETAILS_PROP)))
  26. static INT_PTR WINAPI GroupDetails_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  27. HWND SetupDetails_CreateGroupView(HWND hParent, LPCWSTR pszName, SetupGroup *group)
  28. {
  29. GROUPDETAILSCREATEPARAM param;
  30. param.group = group;
  31. param.name = pszName;
  32. return WASABI_API_CREATEDIALOGPARAMW(IDD_SETUP_GROUPDETAILS, hParent, GroupDetails_DialogProc, (LPARAM)&param);
  33. }
  34. static void GroupDetails_SetTitle(HWND hwnd, SetupGroup *group)
  35. {
  36. HWND hTitle = GetDlgItem(hwnd, IDC_TITLE);
  37. if (NULL == hTitle) return;
  38. WCHAR szBuffer[128] = {0};
  39. if (NULL == group ||
  40. FAILED(group->GetLongName(szBuffer, ARRAYSIZE(szBuffer))))
  41. {
  42. szBuffer[0] = L'\0';
  43. }
  44. GROUPDETAILS *details = GetDetails(hwnd);
  45. if (NULL != details && NULL == details->fontTitle)
  46. {
  47. HFONT dialogFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0L);
  48. LOGFONT lf;
  49. if (0 != GetObject(dialogFont, sizeof(LOGFONT), &lf))
  50. {
  51. StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"Arial Bold");
  52. lf.lfWidth = 0;
  53. lf.lfWeight = FW_DONTCARE;
  54. lf.lfHeight += (lf.lfHeight < 0) ? -2 : +2;
  55. lf.lfQuality = 5/*ANTIALIASED_QUALITY*/;
  56. details->fontTitle = CreateFontIndirect(&lf);
  57. }
  58. if (NULL != details->fontTitle)
  59. {
  60. SendMessage(hTitle, WM_SETFONT, (WPARAM)details->fontTitle, 0L);
  61. }
  62. }
  63. SetWindowText(hTitle, szBuffer);
  64. InvalidateRect(hTitle, NULL, TRUE);
  65. }
  66. static void GroupDetails_SetDescription(HWND hwnd, SetupGroup *group)
  67. {
  68. HWND hDescription = GetDlgItem(hwnd, IDC_DESCRIPTION);
  69. if (NULL == hDescription) return;
  70. WCHAR szBuffer[4096] = {0};
  71. if (NULL == group ||
  72. FAILED(group->GetDescription(szBuffer, ARRAYSIZE(szBuffer))))
  73. {
  74. szBuffer[0] = L'\0';
  75. }
  76. SetupDetails_SetDescription(hDescription, szBuffer);
  77. }
  78. static BOOL GroupDetails_ShowHelp(HWND hwnd)
  79. {
  80. INT result = (INT)(INT_PTR)ShellExecuteW(hwnd, L"open",
  81. L"https://help.winamp.com/hc/articles/8112753225364-Online-Services-Security",
  82. NULL, NULL, SW_SHOWNORMAL);
  83. return (result > 32);
  84. }
  85. static void GroupDetails_UpdateLayout(HWND hwnd, BOOL fRedraw)
  86. {
  87. RECT clientRect, rect;
  88. if(FALSE == GetClientRect(hwnd, &clientRect))
  89. return;
  90. UINT commonFlags = SWP_NOACTIVATE | SWP_NOZORDER;
  91. if (FALSE != fRedraw) commonFlags |= SWP_NOREDRAW;
  92. LONG bottomLine = clientRect.bottom;
  93. HWND hControl;
  94. SIZE linkSize;
  95. RECT linkMargins;
  96. if (NULL != (hControl = GetDlgItem(hwnd, IDC_HELPLINK)) &&
  97. CommandLink_GetIdealSize(hControl, &linkSize))
  98. {
  99. if (!CommandLink_GetMargins(hControl, &linkMargins))
  100. SetRectEmpty(&linkMargins);
  101. if (linkSize.cy > 0)
  102. bottomLine -= linkSize.cy;
  103. SetWindowPos(hControl, NULL, clientRect.left + 4, bottomLine, linkSize.cx, linkSize.cy, commonFlags);
  104. }
  105. else
  106. {
  107. ZeroMemory(&linkSize, sizeof(linkSize));
  108. SetRectEmpty(&linkMargins);
  109. }
  110. if (NULL != (hControl = GetDlgItem(hwnd, IDC_HELPTEXT)))
  111. {
  112. LONG x = clientRect.left + 4 + linkSize.cx/* - linkMargins.right*/;
  113. LONG y = 0;
  114. HDC hdc = GetDCEx(hControl, NULL, DCX_CACHE | DCX_WINDOW | DCX_NORESETATTRS);
  115. if (NULL != hdc)
  116. {
  117. HFONT font = (HFONT)SendMessage(hControl, WM_GETFONT, 0, 0L);
  118. HFONT originalFont = (HFONT)SelectObject(hdc, font);
  119. TEXTMETRICW tm;
  120. if (GetTextMetricsW(hdc, &tm))
  121. y = tm.tmHeight;
  122. SelectObject(hdc, originalFont);
  123. ReleaseDC(hControl, hdc);
  124. }
  125. SetWindowPos(hControl, NULL, x, clientRect.bottom - linkMargins.bottom - y, clientRect.right - x, y, commonFlags);
  126. }
  127. if (NULL != (hControl = GetDlgItem(hwnd, IDC_DESCRIPTION)) &&
  128. FALSE != GetWindowRect(hControl, &rect))
  129. {
  130. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);
  131. SetWindowPos(hControl, NULL, rect.left, rect.right, rect.right - rect.left, bottomLine - rect.top,
  132. commonFlags | SWP_NOMOVE);
  133. }
  134. }
  135. static INT_PTR GroupDetails_OnInitDialog(HWND hwnd, HWND hFocus, LPARAM lParam)
  136. {
  137. GROUPDETAILSCREATEPARAM *param = (GROUPDETAILSCREATEPARAM*)lParam;
  138. GROUPDETAILS *details = (GROUPDETAILS*)calloc(1, sizeof(GROUPDETAILS));
  139. if (NULL == details) return FALSE;
  140. if (!SetProp(hwnd, MAKEINTATOM(DETAILS_PROP), details))
  141. return FALSE;
  142. if (NULL != param)
  143. {
  144. if (NULL != param->group)
  145. {
  146. details->group = param->group;
  147. details->group->AddRef();
  148. }
  149. details->name = Plugin_CopyString(param->name);
  150. }
  151. HINSTANCE winampInstance = (NULL != WASABI_API_APP) ? WASABI_API_APP->main_gethInstance() : NULL;
  152. if (NULL != winampInstance)
  153. {
  154. WCHAR szBuffer[256] = {0};
  155. WASABI_API_LNGSTRINGW_BUF(IDS_CLICKHERE, szBuffer, ARRAYSIZE(szBuffer));
  156. HWND hLink = CreateWindowExW(WS_EX_NOPARENTNOTIFY | WS_EX_TRANSPARENT, NWC_COMMANDLINKW, szBuffer,
  157. WS_VISIBLE | WS_CHILD | WS_TABSTOP | CLS_ALWAYSUNDERLINE | CLS_DEFAULTCOLORS /* | CLS_HOTTRACK */,
  158. 0, 0, 0, 0, hwnd, (HMENU)IDC_HELPLINK, winampInstance, NULL);
  159. if (NULL != hLink)
  160. {
  161. SendMessageW(hLink, WM_SETFONT, (WPARAM)SendMessageW(hwnd, WM_GETFONT, 0, 0L), 0L);
  162. }
  163. }
  164. GroupDetails_UpdateLayout(hwnd, FALSE);
  165. if (NULL != param)
  166. {
  167. GroupDetails_SetTitle(hwnd, param->group);
  168. GroupDetails_SetDescription(hwnd, param->group);
  169. }
  170. return FALSE;
  171. }
  172. static void GroupDetails_OnDestroy(HWND hwnd)
  173. {
  174. GROUPDETAILS *details = GetDetails(hwnd);
  175. RemoveProp(hwnd, MAKEINTATOM(DETAILS_PROP));
  176. if (NULL != details)
  177. {
  178. if (NULL != details->group)
  179. details->group->Release();
  180. if (NULL != details->fontTitle)
  181. DeleteObject(details->fontTitle);
  182. Plugin_FreeString(details->name);
  183. }
  184. }
  185. static INT_PTR GroupDetails_OnDialogColor(HWND hwnd, HDC hdc, HWND hControl)
  186. {
  187. HWND hParent = GetAncestor(hwnd, GA_PARENT);
  188. if (NULL != hParent && hParent != hwnd)
  189. return (INT_PTR)SendMessage(hParent, WM_CTLCOLORDLG, (WPARAM)hdc, (LPARAM)hControl);
  190. return 0;
  191. }
  192. static INT_PTR GroupDetails_OnStaticColor(HWND hwnd, HDC hdc, HWND hControl)
  193. {
  194. HWND hParent = GetAncestor(hwnd, GA_PARENT);
  195. if (NULL != hParent && hParent != hwnd)
  196. return (INT_PTR)SendMessage(hParent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hControl);
  197. return 0;
  198. }
  199. static LRESULT GroupDetails_OnNotify(HWND hwnd, INT controlId, NMHDR *pnmh)
  200. {
  201. switch(controlId)
  202. {
  203. case IDC_HELPLINK:
  204. if (NM_CLICK == pnmh->code)
  205. GroupDetails_ShowHelp(hwnd);
  206. return TRUE;
  207. }
  208. return 0;
  209. }
  210. static BOOL GroupDetails_OnGetUniqueName(HWND hwnd, LPWSTR pszBuffer, UINT cchBufferMax)
  211. {
  212. if (NULL == pszBuffer)
  213. return FALSE;
  214. GROUPDETAILS *details = GetDetails(hwnd);
  215. return SUCCEEDED(StringCchCopy(pszBuffer, cchBufferMax,
  216. (NULL != details && NULL != details->name) ? details->name : L""));
  217. }
  218. static INT_PTR WINAPI GroupDetails_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  219. {
  220. switch(uMsg)
  221. {
  222. case WM_INITDIALOG: return GroupDetails_OnInitDialog(hwnd, (HWND)wParam, lParam);
  223. case WM_DESTROY: GroupDetails_OnDestroy(hwnd); break;
  224. case WM_CTLCOLORDLG: return GroupDetails_OnDialogColor(hwnd, (HDC)wParam, (HWND)lParam);
  225. case WM_CTLCOLORSTATIC: return GroupDetails_OnStaticColor(hwnd, (HDC)wParam, (HWND)lParam);
  226. case WM_NOTIFY: MSGRESULT(hwnd, GroupDetails_OnNotify(hwnd, (INT)wParam, (NMHDR*)lParam));
  227. case NSDM_GETUNIQUENAME: MSGRESULT(hwnd, GroupDetails_OnGetUniqueName(hwnd, (LPWSTR)lParam, (UINT)wParam));
  228. }
  229. return 0;
  230. }