1
0

skinnedstatic.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "./skinnedstatic.h"
  2. #include "../winamp/wa_dlg.h"
  3. #include "./skinning.h"
  4. #include <strsafe.h>
  5. #define MARGIN_TOP 2
  6. #define MARGIN_BOTTOM 2
  7. #define MARGIN_LEFT 2
  8. #define MARGIN_RIGHT 2
  9. SkinnedStatic::SkinnedStatic(void) : SkinnedWnd(FALSE)
  10. {
  11. }
  12. SkinnedStatic::~SkinnedStatic(void)
  13. {
  14. }
  15. BOOL SkinnedStatic::Attach(HWND hwndStatic)
  16. {
  17. if(!SkinnedWnd::Attach(hwndStatic)) return FALSE;
  18. SetType(SKINNEDWND_TYPE_STATIC);
  19. HWND hwndParent = GetParent(hwndStatic);
  20. if (hwndParent) SkinWindow(hwndParent, SWS_NORMAL);
  21. SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
  22. return TRUE;
  23. }
  24. LRESULT SkinnedStatic::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  25. {
  26. if (SWS_USESKINCOLORS & style)
  27. {
  28. switch(uMsg)
  29. {
  30. case REFLECTED_CTLCOLORSTATIC:
  31. {
  32. COLORREF rgbText, rgbTextBk;
  33. rgbText = WADlg_getColor(WADLG_WNDFG);
  34. rgbTextBk = WADlg_getColor(WADLG_WNDBG);
  35. if(!IsWindowEnabled(hwnd))
  36. {
  37. rgbText = RGB((GetRValue(rgbText)+GetRValue(rgbTextBk))/2,
  38. (GetGValue(rgbText)+GetGValue(rgbTextBk))/2,
  39. (GetBValue(rgbText)+GetBValue(rgbTextBk))/2);
  40. }
  41. SetBkColor((HDC)wParam, rgbTextBk);
  42. SetTextColor((HDC)wParam, rgbText);
  43. }
  44. ((REFLECTPARAM*)lParam)->result = (LRESULT)MlStockObjects_Get(WNDBCK_BRUSH);
  45. return TRUE;
  46. }
  47. }
  48. return __super::WindowProc(uMsg, wParam, lParam);
  49. }
  50. LRESULT SkinnedStatic::GetIdealSize(LPCWSTR pszText)
  51. {
  52. INT cchText;
  53. SIZE szButton;
  54. szButton.cx = 0;
  55. szButton.cy = 0;
  56. cchText = (pszText) ? lstrlenW(pszText) : (INT)SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0L);
  57. {
  58. HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE);
  59. if (hdc)
  60. {
  61. wchar_t szText[STATIC_TEXT_MAX] = {0};
  62. if (NULL == pszText)
  63. {
  64. SendMessageW(hwnd, WM_GETTEXT, (WPARAM)STATIC_TEXT_MAX, (LPARAM)szText);
  65. pszText = szText;
  66. }
  67. HFONT hFont = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
  68. if (NULL == hFont) hFont = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
  69. HFONT hfo = (NULL != hFont) ? (HFONT)SelectObject(hdc, hFont) : NULL;
  70. if (0 != cchText)
  71. {
  72. RECT rt;
  73. SetRect(&rt, 0, 0, 0, 0);
  74. if (FALSE == DrawTextW(hdc, pszText, cchText, &rt, DT_CALCRECT | DT_SINGLELINE))
  75. {
  76. szButton.cx = 0;
  77. szButton.cy = 0;
  78. }
  79. else
  80. {
  81. szButton.cx = rt.right - rt.left;
  82. szButton.cy = rt.bottom - rt.top;
  83. }
  84. }
  85. else
  86. {
  87. TEXTMETRIC metrics;
  88. szButton.cx = 0;
  89. if (FALSE == GetTextMetrics(hdc, &metrics))
  90. szButton.cy = 0;
  91. else
  92. szButton.cy = metrics.tmHeight;
  93. }
  94. if (0 != szButton.cy)
  95. szButton.cy += (MARGIN_TOP + MARGIN_BOTTOM);
  96. if (0 != szButton.cx)
  97. szButton.cx += (MARGIN_LEFT + MARGIN_RIGHT) + 2;
  98. if (NULL != hfo)
  99. SelectObject(hdc, hfo);
  100. ReleaseDC(hwnd, hdc);
  101. }
  102. }
  103. return MAKELPARAM(szButton.cx, szButton.cy);
  104. }
  105. BOOL SkinnedStatic::OnMediaLibraryIPC(INT msg, INT_PTR param, LRESULT *pResult)
  106. {
  107. switch(msg)
  108. {
  109. case ML_IPC_SKINNEDSTATIC_GETIDEALSIZE:
  110. *pResult = GetIdealSize((LPCWSTR)param);
  111. return TRUE;
  112. }
  113. return __super::OnMediaLibraryIPC(msg, param, pResult);
  114. }