1
0

skinnedtooltip.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "main.h"
  2. #include "./skinnedtooltip.h"
  3. #include "./skinning.h"
  4. #include "../winamp/wa_dlg.h"
  5. #include "./colors.h"
  6. #include <strsafe.h>
  7. SkinnedToolTip::SkinnedToolTip(void)
  8. : SkinnedWnd(FALSE), skinCursor(NULL), buffer(NULL), bufferSizeCch(0)
  9. {
  10. }
  11. SkinnedToolTip::~SkinnedToolTip(void)
  12. {
  13. if (NULL != buffer)
  14. free(buffer);
  15. }
  16. BOOL SkinnedToolTip::Attach(HWND hToolTip)
  17. {
  18. if(!__super::Attach(hToolTip)) return FALSE;
  19. SetType(SKINNEDWND_TYPE_TOOLTIP);
  20. return TRUE;
  21. }
  22. HPEN SkinnedToolTip::GetBorderPen(void)
  23. {
  24. return (HPEN)MlStockObjects_Get(TOOLTIPBORDER_PEN);
  25. }
  26. void SkinnedToolTip::OnSkinChanged(BOOL bNotifyChildren, BOOL bRedraw)
  27. {
  28. if (0 != (SWS_USESKINCOLORS & style))
  29. {
  30. HRESULT hr;
  31. COLORREF rgbText, rgbBk;
  32. hr = MLGetSkinColor(MLSO_TOOLTIP, TTP_BACKGROUND, MBS_NORMAL, &rgbBk);
  33. if (SUCCEEDED(hr))
  34. hr = MLGetSkinColor(MLSO_TOOLTIP, TTP_TEXT, MBS_NORMAL, &rgbText);
  35. if (SUCCEEDED(hr))
  36. {
  37. if (rgbBk != (COLORREF)CallPrevWndProc(TTM_GETTIPBKCOLOR, 0, 0L))
  38. CallPrevWndProc(TTM_SETTIPBKCOLOR, rgbBk, 0L);
  39. if (rgbText != (COLORREF)CallPrevWndProc(TTM_GETTIPTEXTCOLOR, 0, 0L))
  40. CallPrevWndProc(TTM_SETTIPTEXTCOLOR, rgbText, 0L);
  41. }
  42. }
  43. skinCursor = (0 != (SWS_USESKINCURSORS & style)) ?
  44. (HCURSOR)SENDWAIPC(plugin.hwndParent, IPC_GETSKINCURSORS, WACURSOR_NORMAL) : NULL;
  45. HFONT hfOld = (HFONT)CallPrevWndProc(WM_GETFONT, 0, 0L);
  46. __super::OnSkinChanged(bNotifyChildren, bRedraw);
  47. if (hfOld != (HFONT)CallPrevWndProc(WM_GETFONT, 0, 0L))
  48. CallPrevWndProc(TTM_UPDATE, 0, 0L);
  49. }
  50. void SkinnedToolTip::OnPaint()
  51. {
  52. BOOL defaultPaint = TRUE;
  53. DWORD windowStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
  54. if (0 == ((WS_BORDER | WS_DLGFRAME | WS_THICKFRAME) & windowStyle))
  55. {
  56. DWORD windowExStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
  57. if (0 == ((WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME) & windowExStyle))
  58. defaultPaint = FALSE;
  59. }
  60. if (FALSE != defaultPaint)
  61. {
  62. CallPrevWndProc(WM_PAINT, 0, 0L);
  63. return;
  64. }
  65. PAINTSTRUCT ps;
  66. HDC hdc = BeginPaint(hwnd, &ps);
  67. if (NULL == hdc) return;
  68. COLORREF rgbBk;
  69. rgbBk = (COLORREF)CallPrevWndProc(TTM_GETTIPBKCOLOR, 0, 0L);
  70. SetBkColor(hdc, rgbBk);
  71. RECT rc, rcText;
  72. GetClientRect(hwnd, &rc);
  73. if (FALSE != ps.fErase)
  74. {
  75. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &ps.rcPaint, NULL, 0, NULL);
  76. DrawBorder(hdc, &rc, BORDER_FLAT, GetBorderPen());
  77. }
  78. unsigned int textLength = (unsigned int)CallPrevWndProc(WM_GETTEXTLENGTH, 0, 0L);
  79. if (0 != textLength)
  80. {
  81. if (textLength >= bufferSizeCch)
  82. {
  83. if (NULL != buffer)
  84. free(buffer);
  85. bufferSizeCch = textLength + 1;
  86. buffer = (wchar_t*)calloc(bufferSizeCch, sizeof(wchar_t));
  87. if (NULL == buffer)
  88. bufferSizeCch = 0;
  89. }
  90. if (NULL != buffer)
  91. textLength = (long)CallPrevWndProc(WM_GETTEXT, (WPARAM)bufferSizeCch, (LPARAM)buffer);
  92. else
  93. textLength = 0;
  94. COLORREF rgbFg = (COLORREF)CallPrevWndProc(TTM_GETTIPTEXTCOLOR, 0, 0L);
  95. SetRectEmpty(&rcText);
  96. CallPrevWndProc(TTM_GETMARGIN, 0, (LPARAM)&rcText);
  97. if (rcText.left < 2)
  98. rcText.left = 2;
  99. if (rcText.right < 2)
  100. rcText.right = 2;
  101. if (rcText.bottom < 1)
  102. rcText.bottom = 1;
  103. if (rcText.top < 1)
  104. rcText.top = 1;
  105. rcText.left = rc.left + rcText.left;
  106. rcText.top = rc.top + rcText.top;
  107. rcText.right = rc.right - rcText.right;
  108. rcText.bottom = rc.bottom - rcText.bottom;
  109. HFONT textFont = (HFONT)CallPrevWndProc(WM_GETFONT, 0, 0L);
  110. if (NULL == textFont)
  111. textFont = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
  112. HFONT textFontOld = (HFONT)SelectObject(hdc, textFont);
  113. COLORREF rgbFgOld = SetTextColor(hdc, rgbFg);
  114. unsigned int textFormat;
  115. textFormat = DT_TOP | DT_LEFT | DT_WORDBREAK;
  116. if (0 != (TTS_NOPREFIX & windowStyle))
  117. textFormat |= DT_NOPREFIX;
  118. DrawTextW(hdc, buffer, textLength, &rcText, textFormat);
  119. SelectObject(hdc, textFontOld);
  120. if (rgbFg != rgbFgOld)
  121. SetTextColor(hdc, rgbFgOld);
  122. }
  123. EndPaint(hwnd, &ps);
  124. }
  125. LRESULT SkinnedToolTip::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  126. {
  127. switch(uMsg)
  128. {
  129. case WM_ERASEBKGND:
  130. return 0;
  131. case WM_PAINT:
  132. OnPaint();
  133. return 0;
  134. case WM_WINDOWPOSCHANGED:
  135. if (0 != (SWP_SHOWWINDOW & ((WINDOWPOS*)lParam)->flags))
  136. SkinChanged(FALSE, TRUE);
  137. break;
  138. case WM_SHOWWINDOW:
  139. if (0 != wParam)
  140. SkinChanged(FALSE, TRUE);
  141. break;
  142. case WM_SETCURSOR:
  143. if (NULL != skinCursor)
  144. {
  145. if (skinCursor != GetCursor())
  146. SetCursor(skinCursor);
  147. return TRUE;
  148. }
  149. break;
  150. }
  151. return __super::WindowProc(uMsg, wParam, lParam);
  152. }