commandLink.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #include "main.h"
  2. #include "./commandLink.h"
  3. #include "./api.h"
  4. //#include "./guiObjects.h"
  5. #include <windows.h>
  6. #include <shlwapi.h>
  7. #include <commctrl.h>
  8. #include <strsafe.h>
  9. #ifndef LONGX86
  10. #ifdef _WIN64
  11. #define LONGX86 LONG_PTR
  12. #else /*_WIN64*/
  13. #define LONGX86 LONG
  14. #endif /*_WIN64*/
  15. #endif // LONGX86
  16. #define MARGIN_LEFT 2
  17. #define MARGIN_TOP 0
  18. #define MARGIN_RIGHT 2
  19. #define MARGIN_BOTTOM 1
  20. typedef struct __COMMANDLINK
  21. {
  22. COLORREF rgbBk;
  23. COLORREF rgbText;
  24. COLORREF rgbTextVisited;
  25. COLORREF rgbTextHighlight;
  26. HCURSOR cursorHot;
  27. HFONT textFont;
  28. UINT state;
  29. RECT margins;
  30. } COMMANDLINK;
  31. #define GetCommandLink(__hwnd) ((COMMANDLINK*)(LONG_PTR)(LONGX86)GetWindowLongPtrW((__hwnd), 0))
  32. static LRESULT CALLBACK CommandLink_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  33. EXTERN_C BOOL CommandLink_RegisterClass(HINSTANCE hInstance)
  34. {
  35. WNDCLASSEXW wc;
  36. ATOM klassAtom;
  37. if (GetClassInfoExW(hInstance, NWC_COMMANDLINKW, &wc))
  38. return TRUE;
  39. ZeroMemory(&wc, sizeof(WNDCLASSEXW));
  40. wc.cbSize = sizeof(WNDCLASSEXW);
  41. wc.hInstance = hInstance;
  42. wc.lpszClassName = NWC_COMMANDLINKW;
  43. wc.lpfnWndProc = CommandLink_WindowProc;
  44. wc.style = CS_GLOBALCLASS;
  45. wc.hIcon = NULL;
  46. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  47. wc.hbrBackground = NULL;
  48. wc.cbWndExtra = sizeof(COMMANDLINK*);
  49. klassAtom = RegisterClassExW(&wc);
  50. if (0 == klassAtom)
  51. return FALSE;
  52. if (NULL != WASABI_API_APP)
  53. WASABI_API_APP->DirectMouseWheel_RegisterSkipClass(klassAtom);
  54. return TRUE;
  55. }
  56. static COLORREF CommandLink_BlendColors(COLORREF rgbTop, COLORREF rgbBottom, INT alpha)
  57. {
  58. if (alpha > 254) return rgbTop;
  59. if (alpha < 0) return rgbBottom;
  60. INT k = (((255 - alpha)*255 + 127)/255);
  61. return RGB( (GetRValue(rgbTop)*alpha + k*GetRValue(rgbBottom) + 127)/255,
  62. (GetGValue(rgbTop)*alpha + k*GetGValue(rgbBottom) + 127)/255,
  63. (GetBValue(rgbTop)*alpha + k*GetBValue(rgbBottom) + 127)/255);
  64. }
  65. static HBRUSH CommandLink_GetPaintColors(HWND hwnd, HDC hdc, COLORREF *rgbBkOut, COLORREF *rgbFgOut)
  66. {
  67. COMMANDLINK *link = GetCommandLink(hwnd);
  68. if (NULL == link) return NULL;
  69. COLORREF rgbBk, rgbFg;
  70. UINT windowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
  71. BOOL defaultColors = (0 != (CLS_DEFAULTCOLORS & windowStyle));
  72. rgbBk = (defaultColors) ? GetSysColor(COLOR_3DFACE) : link->rgbBk;
  73. if (NULL != rgbBkOut) *rgbBkOut = rgbBk;
  74. if (0 != (WS_DISABLED & windowStyle))
  75. rgbFg = GetSysColor(COLOR_GRAYTEXT);
  76. else
  77. {
  78. if (0 != (CLIS_VISITED & link->state))
  79. rgbFg = (defaultColors) ? RGB(85, 26, 139) : link->rgbTextVisited;
  80. else
  81. rgbFg = (defaultColors) ? GetSysColor(COLOR_HOTLIGHT) : link->rgbText;
  82. if (0 != ((CLIS_HOT | CLIS_PRESSED) & link->state))
  83. {
  84. if (0 == (CLS_HIGHLIGHTCOLOR & windowStyle))
  85. rgbFg = CommandLink_BlendColors(rgbFg, rgbBk, 160);
  86. else
  87. rgbFg = link->rgbTextHighlight;
  88. }
  89. }
  90. if (NULL != rgbFgOut)
  91. *rgbFgOut = rgbFg;
  92. HBRUSH backBrush = NULL;
  93. if (FALSE != defaultColors)
  94. {
  95. HWND hParent = GetParent(hwnd);
  96. if (NULL != hParent)
  97. {
  98. COLORREF backBk = SetBkColor(hdc, rgbBk);
  99. COLORREF backFg = SetBkColor(hdc, rgbFg);
  100. backBrush = (HBRUSH)SendMessageW(hParent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd);
  101. rgbBk = SetBkColor(hdc, backBk);
  102. SetBkColor(hdc, backFg);
  103. }
  104. }
  105. return backBrush;
  106. }
  107. static BOOL CommandLink_GetTextRect(HDC hdc, LPCWSTR pszText, INT cchText, const RECT *prcClient, RECT *prcTextOut, const RECT *margins)
  108. {
  109. if (NULL == prcClient || NULL == prcTextOut)
  110. return FALSE;
  111. SIZE textSize;
  112. if (0 == cchText || !GetTextExtentPoint32W(hdc, pszText, cchText, &textSize))
  113. return SetRectEmpty(prcTextOut);
  114. prcTextOut->left = ((prcClient->right - prcClient->left) - textSize.cx) / 2;
  115. if (prcTextOut->left < (prcClient->left + margins->left))
  116. prcTextOut->left = prcClient->left + margins->left;
  117. prcTextOut->top = ((prcClient->bottom - prcClient->top) - textSize.cy) / 2;
  118. if (prcTextOut->top < (prcClient->top + margins->top))
  119. prcTextOut->top = prcClient->top + margins->top;
  120. prcTextOut->right = prcTextOut->left + textSize.cx;
  121. if (prcTextOut->right > (prcClient->right - margins->right))
  122. prcTextOut->right = prcClient->right - margins->right;
  123. prcTextOut->bottom = prcTextOut->top + textSize.cy;
  124. if (prcTextOut->bottom > (prcClient->bottom - margins->bottom))
  125. prcTextOut->bottom = prcClient->bottom - margins->bottom;
  126. return TRUE;
  127. }
  128. static BOOL CommandLink_GetIdealSizeReal(HWND hwnd, SIZE *sizeOut)
  129. {
  130. if (NULL == sizeOut)
  131. return FALSE;
  132. ZeroMemory(sizeOut, sizeof(SIZE));
  133. COMMANDLINK *link = GetCommandLink(hwnd);
  134. if (NULL == link) return FALSE;
  135. WCHAR szText[256] = {0};
  136. INT cchText = GetWindowTextW(hwnd, szText, ARRAYSIZE(szText));
  137. HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_WINDOW | DCX_NORESETATTRS);
  138. if (NULL == hdc) return FALSE;
  139. HFONT originalFont = (HFONT)SelectObject(hdc, link->textFont);
  140. BOOL resultOk;
  141. if (0 == cchText)
  142. {
  143. TEXTMETRICW tm;
  144. resultOk = GetTextMetricsW(hdc, &tm);
  145. if (resultOk) sizeOut->cy = tm.tmHeight;
  146. }
  147. else
  148. resultOk = GetTextExtentPoint32W(hdc, szText, cchText, sizeOut);
  149. if (originalFont != link->textFont) SelectObject(hdc, originalFont);
  150. ReleaseDC(hwnd, hdc);
  151. if (resultOk)
  152. {
  153. sizeOut->cx += (link->margins.left + link->margins.right);
  154. sizeOut->cy += (link->margins.top + link->margins.bottom);
  155. }
  156. return resultOk;
  157. }
  158. static BOOL CommandLink_SetStateEx(HWND hwnd, UINT newState, UINT stateMask, BOOL fRedraw)
  159. {
  160. COMMANDLINK *link = GetCommandLink(hwnd);
  161. if (NULL == link) return FALSE;
  162. UINT oldState = link->state;
  163. link->state = (link->state & ~stateMask) | (newState & stateMask);
  164. if (oldState != link->state && fRedraw)
  165. InvalidateRect(hwnd, NULL, TRUE);
  166. return TRUE;
  167. }
  168. static void CommandLink_Paint(HWND hwnd, HDC hdc, const RECT *prcPaint, BOOL fErase)
  169. {
  170. COMMANDLINK *link = GetCommandLink(hwnd);
  171. if (NULL == link) return;
  172. RECT clientRect, partRect;
  173. if (!GetClientRect(hwnd, &clientRect)) return;
  174. DWORD windowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
  175. COLORREF rgbBk, rgbFg;
  176. HBRUSH backBrush = CommandLink_GetPaintColors(hwnd, hdc, &rgbBk, &rgbFg);
  177. COLORREF originalBk = SetBkColor(hdc, rgbBk);
  178. COLORREF originalFg = SetTextColor(hdc, rgbFg);
  179. HFONT originalFont = (HFONT)SelectObject(hdc, link->textFont);
  180. WCHAR szText[256] = {0};
  181. INT cchText = GetWindowTextW(hwnd, szText, ARRAYSIZE(szText));
  182. RECT textRect;
  183. CommandLink_GetTextRect(hdc, szText, cchText, &clientRect, &textRect, &link->margins);
  184. if (fErase)
  185. {
  186. if(NULL != backBrush)
  187. {
  188. FillRect(hdc, prcPaint, backBrush);
  189. }
  190. else
  191. {
  192. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, prcPaint, NULL, 0, NULL);
  193. }
  194. }
  195. if (0 != ((CLIS_HOT | CLIS_PRESSED) & link->state) ||
  196. 0 != (CLS_ALWAYSUNDERLINE & windowStyle))
  197. {
  198. TEXTMETRIC tm;
  199. if (GetTextMetrics(hdc, &tm))
  200. {
  201. CopyRect(&partRect, &textRect);
  202. partRect.top = partRect.top + tm.tmAscent + 1;
  203. partRect.bottom = partRect.top + 1;
  204. COLORREF originalColor = SetBkColor(hdc, rgbFg);
  205. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &partRect, NULL, 0, NULL);
  206. if (originalColor != rgbFg) SetBkColor(hdc, originalColor);
  207. }
  208. }
  209. if (0 != cchText)
  210. {
  211. INT originalMode = SetBkMode(hdc, TRANSPARENT);
  212. UINT originalAlign = SetTextAlign(hdc, TA_LEFT | TA_TOP);
  213. ExtTextOutW(hdc, textRect.left, textRect.top, ETO_CLIPPED, &textRect, szText, cchText, NULL);
  214. if (TRANSPARENT != originalMode) SetBkMode(hdc, originalMode);
  215. if ((TA_LEFT | TA_TOP) != originalAlign) SetTextAlign(hdc, originalAlign);
  216. }
  217. if (CLIS_FOCUSED == ((CLIS_FOCUSED | CLIS_HIDEFOCUS) & link->state))
  218. {
  219. SetBkColor(hdc, 0x00FFFFFF);
  220. SetTextColor(hdc, 0x000000000);
  221. DrawFocusRect(hdc, &clientRect);
  222. }
  223. SelectObject(hdc, originalFont);
  224. if (originalBk != rgbBk) SetBkColor(hdc, originalBk);
  225. if (originalFg != rgbFg) SetTextColor(hdc, originalFg);
  226. }
  227. static void CommandLink_NotifyParent(HWND hwnd, UINT notificationId)
  228. {
  229. NMHDR nmhdr;
  230. nmhdr.code = notificationId;
  231. nmhdr.hwndFrom = hwnd;
  232. nmhdr.idFrom = GetDlgCtrlID(hwnd);
  233. HWND hParent = GetParent(hwnd);
  234. if (NULL != hParent)
  235. {
  236. SendMessageW(hParent, WM_NOTIFY, (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
  237. }
  238. }
  239. static void CommandLink_Click(HWND hwnd)
  240. {
  241. CommandLink_NotifyParent(hwnd, NM_CLICK);
  242. DWORD windowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
  243. if (0 != (CLS_TRACKVISITED & windowStyle))
  244. CommandLink_SetStateEx(hwnd, CLIS_VISITED, CLIS_VISITED, TRUE);
  245. }
  246. static void CommandLink_QueryUiState(HWND hwnd)
  247. {
  248. UINT uiState = (UINT)DefWindowProcW(hwnd, WM_QUERYUISTATE, 0, 0L);
  249. CommandLink_SetStateEx(hwnd, (0 != (UISF_HIDEFOCUS & uiState)) ? CLIS_HIDEFOCUS : 0, CLIS_HIDEFOCUS, TRUE);
  250. }
  251. static LRESULT CommandLink_OnCreateWindow(HWND hwnd, CREATESTRUCT *pcs)
  252. {
  253. UNREFERENCED_PARAMETER(pcs);
  254. COMMANDLINK *link;
  255. link = (COMMANDLINK*)calloc(1, sizeof(COMMANDLINK));
  256. if (NULL == link)
  257. {
  258. DestroyWindow(hwnd);
  259. return -1;
  260. }
  261. SetLastError(ERROR_SUCCESS);
  262. if (!SetWindowLongPtrW(hwnd, 0, (LONGX86)(LONG_PTR)link) && ERROR_SUCCESS != GetLastError())
  263. {
  264. free(link);
  265. DestroyWindow(hwnd);
  266. return -1;
  267. }
  268. link->rgbBk = GetSysColor(COLOR_3DFACE);
  269. link->rgbText = GetSysColor(COLOR_HOTLIGHT);
  270. link->rgbTextVisited = (0x00FFFFFF & (~link->rgbText));
  271. link->rgbTextHighlight = GetSysColor(COLOR_HOTLIGHT);
  272. link->cursorHot = LoadCursor(NULL, IDC_HAND);
  273. SetRect(&link->margins, MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT, MARGIN_BOTTOM);
  274. CommandLink_QueryUiState(hwnd);
  275. return FALSE;
  276. }
  277. static void CommandLink_OnDestroy(HWND hwnd)
  278. {
  279. COMMANDLINK *link = GetCommandLink(hwnd);
  280. SetWindowLongPtrW(hwnd, 0, 0L);
  281. if (!link) return;
  282. free(link);
  283. }
  284. static void CommandLink_OnPaint(HWND hwnd)
  285. {
  286. PAINTSTRUCT ps;
  287. if (BeginPaint(hwnd, &ps))
  288. {
  289. if (ps.rcPaint.left != ps.rcPaint.right)
  290. CommandLink_Paint(hwnd, ps.hdc, &ps.rcPaint, ps.fErase);
  291. EndPaint(hwnd, &ps);
  292. }
  293. }
  294. static void CommandLink_OnPrintClient(HWND hwnd, HDC hdc, UINT options)
  295. {
  296. RECT clientRect;
  297. if (GetClientRect(hwnd, &clientRect))
  298. CommandLink_Paint(hwnd, hdc, &clientRect, 0 != (PRF_ERASEBKGND & options));
  299. }
  300. static void CommandLink_OnSetFocus(HWND hwnd, HWND lostFocus)
  301. {
  302. UNREFERENCED_PARAMETER(lostFocus);
  303. CommandLink_SetStateEx(hwnd, CLIS_FOCUSED, CLIS_FOCUSED, TRUE);
  304. CommandLink_NotifyParent(hwnd, NM_SETFOCUS);
  305. }
  306. static void CommandLink_OnKillFocus(HWND hwnd, HWND receiveFocus)
  307. {
  308. UNREFERENCED_PARAMETER(receiveFocus);
  309. CommandLink_SetStateEx(hwnd, 0, CLIS_FOCUSED, TRUE);
  310. CommandLink_NotifyParent(hwnd, NM_KILLFOCUS);
  311. }
  312. static void CommandLink_OnMouseMove(HWND hwnd, UINT mouseFlags, POINTS pts)
  313. {
  314. UNREFERENCED_PARAMETER(mouseFlags);
  315. UNREFERENCED_PARAMETER(pts);
  316. UINT windowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
  317. COMMANDLINK *link = GetCommandLink(hwnd);
  318. if (NULL != link)
  319. {
  320. if (0 == (CLIS_HOT & link->state) && 0 != (CLS_HOTTRACK & windowStyle))
  321. {
  322. link->state |= CLIS_HOT;
  323. InvalidateRect(hwnd, NULL, FALSE);
  324. TRACKMOUSEEVENT tm;
  325. tm.cbSize = sizeof(TRACKMOUSEEVENT);
  326. tm.dwFlags = TME_LEAVE;
  327. tm.hwndTrack = hwnd;
  328. TrackMouseEvent(&tm);
  329. }
  330. }
  331. }
  332. static void CommandLink_OnMouseLeave(HWND hwnd)
  333. {
  334. CommandLink_SetStateEx(hwnd, 0, CLIS_HOT, TRUE);
  335. }
  336. static void CommandLink_OnLButtonDown(HWND hwnd, UINT mouseFlags, POINTS pts)
  337. {
  338. UNREFERENCED_PARAMETER(mouseFlags);
  339. UNREFERENCED_PARAMETER(pts);
  340. if (IsWindowEnabled(hwnd) && hwnd != GetFocus())
  341. SetFocus(hwnd);
  342. CommandLink_SetStateEx(hwnd, CLIS_PRESSED, CLIS_PRESSED, TRUE);
  343. if (hwnd != GetCapture())
  344. SetCapture(hwnd);
  345. }
  346. static void CommandLink_OnLButtonUp(HWND hwnd, UINT mouseFlags, POINTS pts)
  347. {
  348. UNREFERENCED_PARAMETER(mouseFlags);
  349. RECT clientRect;
  350. POINT pt;
  351. POINTSTOPOINT(pt, pts);
  352. COMMANDLINK *link = GetCommandLink(hwnd);
  353. if (NULL != link && 0 != (CLIS_PRESSED & link->state))
  354. {
  355. if (GetClientRect(hwnd, &clientRect) && PtInRect(&clientRect, pt))
  356. CommandLink_Click(hwnd);
  357. CommandLink_SetStateEx(hwnd, 0, CLIS_PRESSED, TRUE);
  358. }
  359. if (hwnd == GetCapture())
  360. SetCapture(NULL);
  361. }
  362. static void CommandLink_OnKeyDown(HWND hwnd, UINT virtualKey, UINT keyFlags)
  363. {
  364. UNREFERENCED_PARAMETER(hwnd);
  365. UNREFERENCED_PARAMETER(virtualKey);
  366. UNREFERENCED_PARAMETER(keyFlags);
  367. }
  368. static void CommandLink_OnKeyUp(HWND hwnd, UINT virtualKey, UINT keyFlags)
  369. {
  370. UNREFERENCED_PARAMETER(keyFlags);
  371. switch(virtualKey)
  372. {
  373. case VK_SPACE:
  374. CommandLink_Click(hwnd);
  375. break;
  376. }
  377. }
  378. static void CommandLink_OnEnable(HWND hwnd, BOOL fEnabled)
  379. {
  380. UNREFERENCED_PARAMETER(fEnabled);
  381. InvalidateRect(hwnd, NULL, TRUE);
  382. }
  383. static void CommandLink_OnUpdateUiState(HWND hwnd, UINT actionId, UINT stateId)
  384. {
  385. DefWindowProcW(hwnd, WM_UPDATEUISTATE, MAKEWPARAM(actionId, stateId), 0L);
  386. CommandLink_QueryUiState(hwnd);
  387. }
  388. static void CommandLink_OnSetFont(HWND hwnd, HFONT newFont, BOOL fRedraw)
  389. {
  390. COMMANDLINK *link = GetCommandLink(hwnd);
  391. if (NULL != link) link->textFont = newFont;
  392. if (FALSE != fRedraw)
  393. InvalidateRect(hwnd, NULL, TRUE);
  394. }
  395. static LRESULT CommandLink_OnGetFont(HWND hwnd)
  396. {
  397. COMMANDLINK *link = GetCommandLink(hwnd);
  398. return (LRESULT)((NULL != link) ? link->textFont : NULL);
  399. }
  400. static LRESULT CommandLink_OnSetCursor(HWND hwnd, HWND cursorWindow, UINT hitTest, UINT uMsg)
  401. {
  402. UNREFERENCED_PARAMETER(cursorWindow);
  403. UNREFERENCED_PARAMETER(hitTest);
  404. UNREFERENCED_PARAMETER(uMsg);
  405. if (IsWindowEnabled(hwnd))
  406. {
  407. COMMANDLINK *link = GetCommandLink(hwnd);
  408. if (NULL != link && NULL != link->cursorHot)
  409. {
  410. SetCursor(link->cursorHot);
  411. return TRUE;
  412. }
  413. }
  414. return FALSE;
  415. }
  416. static LRESULT CommandLink_OnGetIdealHeight(HWND hwnd)
  417. {
  418. SIZE windowSize;
  419. return (CommandLink_GetIdealSizeReal(hwnd, &windowSize)) ? windowSize.cy : 0;
  420. }
  421. static LRESULT CommandLink_OnGetIdealSize(HWND hwnd, SIZE *sizeOut)
  422. {
  423. return CommandLink_GetIdealSizeReal(hwnd, sizeOut);
  424. }
  425. static void CommandLink_OnResetVisited(HWND hwnd)
  426. {
  427. CommandLink_SetStateEx(hwnd, 0, CLIS_VISITED, TRUE);
  428. }
  429. static BOOL CommandLink_OnGetMargins(HWND hwnd, RECT *prc)
  430. {
  431. COMMANDLINK *link = GetCommandLink(hwnd);
  432. if (NULL == prc || NULL == link) return FALSE;
  433. return CopyRect(prc, &link->margins);
  434. }
  435. static BOOL CommandLink_OnSetMargins(HWND hwnd, const RECT *prc)
  436. {
  437. COMMANDLINK *link = GetCommandLink(hwnd);
  438. if (NULL == prc || NULL == link) return FALSE;
  439. return CopyRect(&link->margins, prc);
  440. }
  441. static BOOL CommandLink_OnSetBackColor(HWND hwnd, COLORREF rgb)
  442. {
  443. COMMANDLINK *link = GetCommandLink(hwnd);
  444. if (NULL == link) return FALSE;
  445. link->rgbBk = rgb;
  446. return TRUE;
  447. }
  448. static BOOL CommandLink_OnGetBackColor(HWND hwnd)
  449. {
  450. COMMANDLINK *link = GetCommandLink(hwnd);
  451. return (NULL != link) ? link->rgbBk : RGB(255, 0, 255);
  452. }
  453. static BOOL CommandLink_OnSetTextColor(HWND hwnd, COLORREF rgb)
  454. {
  455. COMMANDLINK *link = GetCommandLink(hwnd);
  456. if (NULL == link) return FALSE;
  457. link->rgbText = rgb;
  458. return TRUE;
  459. }
  460. static BOOL CommandLink_OnGetTextColor(HWND hwnd)
  461. {
  462. COMMANDLINK *link = GetCommandLink(hwnd);
  463. return (NULL != link) ? link->rgbText : RGB(255, 0, 255);
  464. }
  465. static BOOL CommandLink_OnSetVisitedColor(HWND hwnd, COLORREF rgb)
  466. {
  467. COMMANDLINK *link = GetCommandLink(hwnd);
  468. if (NULL == link) return FALSE;
  469. link->rgbTextVisited = rgb;
  470. return TRUE;
  471. }
  472. static BOOL CommandLink_OnGetVisitedColor(HWND hwnd)
  473. {
  474. COMMANDLINK *link = GetCommandLink(hwnd);
  475. return (NULL != link) ? link->rgbTextVisited : RGB(255, 0, 255);
  476. }
  477. static BOOL CommandLink_OnSetHighlightColor(HWND hwnd, COLORREF rgb)
  478. {
  479. COMMANDLINK *link = GetCommandLink(hwnd);
  480. if (NULL == link) return FALSE;
  481. link->rgbTextHighlight = rgb;
  482. return TRUE;
  483. }
  484. static BOOL CommandLink_OnGetHighlightColor(HWND hwnd)
  485. {
  486. COMMANDLINK *link = GetCommandLink(hwnd);
  487. return (NULL != link) ? link->rgbTextHighlight : RGB(255, 0, 255);
  488. }
  489. static LRESULT CALLBACK CommandLink_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  490. {
  491. switch ( uMsg )
  492. {
  493. case WM_CREATE:
  494. return CommandLink_OnCreateWindow( hwnd, (CREATESTRUCT *) lParam );
  495. case WM_DESTROY:
  496. CommandLink_OnDestroy( hwnd );
  497. return 0;
  498. case WM_PAINT:
  499. CommandLink_OnPaint( hwnd );
  500. return 0;
  501. case WM_PRINTCLIENT:
  502. CommandLink_OnPrintClient( hwnd, (HDC) wParam, (UINT) lParam );
  503. return 0;
  504. case WM_ERASEBKGND:
  505. return 0;
  506. case WM_SETFONT:
  507. CommandLink_OnSetFont( hwnd, (HFONT) wParam, (BOOL) LOWORD( lParam ) );
  508. return 0;
  509. case WM_GETFONT:
  510. return CommandLink_OnGetFont( hwnd );
  511. case WM_SETFOCUS:
  512. CommandLink_OnSetFocus( hwnd, (HWND) wParam );
  513. return 0;
  514. case WM_KILLFOCUS:
  515. CommandLink_OnKillFocus( hwnd, (HWND) wParam );
  516. return 0;
  517. case WM_MOUSEMOVE:
  518. CommandLink_OnMouseMove( hwnd, (UINT) wParam, MAKEPOINTS( lParam ) );
  519. return 0;
  520. case WM_MOUSELEAVE:
  521. CommandLink_OnMouseLeave( hwnd );
  522. return 0;
  523. case WM_LBUTTONDOWN:
  524. CommandLink_OnLButtonDown( hwnd, (UINT) wParam, MAKEPOINTS( lParam ) );
  525. return 0;
  526. case WM_LBUTTONUP:
  527. CommandLink_OnLButtonUp( hwnd, (UINT) wParam, MAKEPOINTS( lParam ) );
  528. return 0;
  529. case WM_KEYDOWN:
  530. CommandLink_OnKeyDown( hwnd, (UINT) wParam, (UINT) lParam );
  531. return 0;
  532. case WM_KEYUP:
  533. CommandLink_OnKeyUp( hwnd, (UINT) wParam, (UINT) lParam );
  534. return 0;
  535. case WM_ENABLE:
  536. CommandLink_OnEnable( hwnd, (BOOL) wParam );
  537. return 0;
  538. case WM_UPDATEUISTATE:
  539. CommandLink_OnUpdateUiState( hwnd, LOWORD( wParam ), HIWORD( wParam ) );
  540. return 0;
  541. case WM_SETCURSOR:
  542. return CommandLink_OnSetCursor( hwnd, (HWND) wParam, LOWORD( lParam ), HIWORD( lParam ) );
  543. case CLM_GETIDEALHEIGHT:
  544. return CommandLink_OnGetIdealHeight( hwnd );
  545. case CLM_GETIDEALSIZE:
  546. return CommandLink_OnGetIdealSize( hwnd, (SIZE *) lParam );
  547. case CLM_RESETVISITED:
  548. CommandLink_OnResetVisited( hwnd );
  549. return 0;
  550. case CLM_GETMARGINS:
  551. return CommandLink_OnGetMargins( hwnd, (RECT *) lParam );
  552. case CLM_SETMARGINS:
  553. return CommandLink_OnSetMargins( hwnd, (const RECT *) lParam );
  554. case CLM_SETBACKCOLOR:
  555. return CommandLink_OnSetBackColor( hwnd, (COLORREF) lParam );
  556. case CLM_GETBACKCOLOR:
  557. return CommandLink_OnGetBackColor( hwnd );
  558. case CLM_SETTEXTCOLOR:
  559. return CommandLink_OnSetTextColor( hwnd, (COLORREF) lParam );
  560. case CLM_GETTEXTCOLOR:
  561. return CommandLink_OnGetTextColor( hwnd );
  562. case CLM_SETVISITEDCOLOR:
  563. return CommandLink_OnSetVisitedColor( hwnd, (COLORREF) lParam );
  564. case CLM_GETVISITEDCOLOR:
  565. return CommandLink_OnGetVisitedColor( hwnd );
  566. case CLM_SETHIGHLIGHTCOLOR:
  567. return CommandLink_OnSetHighlightColor( hwnd, (COLORREF) lParam );
  568. case CLM_GETHIGHLIGHTCOLOR:
  569. return CommandLink_OnGetHighlightColor( hwnd );
  570. }
  571. return DefWindowProcW( hwnd, uMsg, wParam, lParam );
  572. }