aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_ml/skinnedstatic.cpp
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/General/gen_ml/skinnedstatic.cpp
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Plugins/General/gen_ml/skinnedstatic.cpp')
-rw-r--r--Src/Plugins/General/gen_ml/skinnedstatic.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/Src/Plugins/General/gen_ml/skinnedstatic.cpp b/Src/Plugins/General/gen_ml/skinnedstatic.cpp
new file mode 100644
index 00000000..864d7963
--- /dev/null
+++ b/Src/Plugins/General/gen_ml/skinnedstatic.cpp
@@ -0,0 +1,135 @@
+#include "./skinnedstatic.h"
+#include "../winamp/wa_dlg.h"
+#include "./skinning.h"
+#include <strsafe.h>
+
+#define MARGIN_TOP 2
+#define MARGIN_BOTTOM 2
+#define MARGIN_LEFT 2
+#define MARGIN_RIGHT 2
+
+SkinnedStatic::SkinnedStatic(void) : SkinnedWnd(FALSE)
+{
+}
+
+SkinnedStatic::~SkinnedStatic(void)
+{
+}
+
+BOOL SkinnedStatic::Attach(HWND hwndStatic)
+{
+ if(!SkinnedWnd::Attach(hwndStatic)) return FALSE;
+ SetType(SKINNEDWND_TYPE_STATIC);
+
+ HWND hwndParent = GetParent(hwndStatic);
+ if (hwndParent) SkinWindow(hwndParent, SWS_NORMAL);
+
+ SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
+ return TRUE;
+}
+
+LRESULT SkinnedStatic::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ if (SWS_USESKINCOLORS & style)
+ {
+ switch(uMsg)
+ {
+ case REFLECTED_CTLCOLORSTATIC:
+ {
+ COLORREF rgbText, rgbTextBk;
+ rgbText = WADlg_getColor(WADLG_WNDFG);
+ rgbTextBk = WADlg_getColor(WADLG_WNDBG);
+
+ if(!IsWindowEnabled(hwnd))
+ {
+ rgbText = RGB((GetRValue(rgbText)+GetRValue(rgbTextBk))/2,
+ (GetGValue(rgbText)+GetGValue(rgbTextBk))/2,
+ (GetBValue(rgbText)+GetBValue(rgbTextBk))/2);
+ }
+
+ SetBkColor((HDC)wParam, rgbTextBk);
+ SetTextColor((HDC)wParam, rgbText);
+ }
+ ((REFLECTPARAM*)lParam)->result = (LRESULT)MlStockObjects_Get(WNDBCK_BRUSH);
+ return TRUE;
+ }
+ }
+ return __super::WindowProc(uMsg, wParam, lParam);
+}
+
+LRESULT SkinnedStatic::GetIdealSize(LPCWSTR pszText)
+{
+ INT cchText;
+ SIZE szButton;
+ szButton.cx = 0;
+ szButton.cy = 0;
+
+ cchText = (pszText) ? lstrlenW(pszText) : (INT)SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0L);
+
+ {
+ HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE);
+ if (hdc)
+ {
+ wchar_t szText[STATIC_TEXT_MAX] = {0};
+ if (NULL == pszText)
+ {
+ SendMessageW(hwnd, WM_GETTEXT, (WPARAM)STATIC_TEXT_MAX, (LPARAM)szText);
+ pszText = szText;
+ }
+
+ HFONT hFont = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
+ if (NULL == hFont) hFont = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
+ HFONT hfo = (NULL != hFont) ? (HFONT)SelectObject(hdc, hFont) : NULL;
+
+ if (0 != cchText)
+ {
+ RECT rt;
+ SetRect(&rt, 0, 0, 0, 0);
+ if (FALSE == DrawTextW(hdc, pszText, cchText, &rt, DT_CALCRECT | DT_SINGLELINE))
+ {
+ szButton.cx = 0;
+ szButton.cy = 0;
+ }
+ else
+ {
+ szButton.cx = rt.right - rt.left;
+ szButton.cy = rt.bottom - rt.top;
+ }
+ }
+ else
+ {
+ TEXTMETRIC metrics;
+
+ szButton.cx = 0;
+ if (FALSE == GetTextMetrics(hdc, &metrics))
+ szButton.cy = 0;
+ else
+ szButton.cy = metrics.tmHeight;
+ }
+
+ if (0 != szButton.cy)
+ szButton.cy += (MARGIN_TOP + MARGIN_BOTTOM);
+
+ if (0 != szButton.cx)
+ szButton.cx += (MARGIN_LEFT + MARGIN_RIGHT) + 2;
+
+ if (NULL != hfo)
+ SelectObject(hdc, hfo);
+
+ ReleaseDC(hwnd, hdc);
+ }
+ }
+
+ return MAKELPARAM(szButton.cx, szButton.cy);
+}
+
+BOOL SkinnedStatic::OnMediaLibraryIPC(INT msg, INT_PTR param, LRESULT *pResult)
+{
+ switch(msg)
+ {
+ case ML_IPC_SKINNEDSTATIC_GETIDEALSIZE:
+ *pResult = GetIdealSize((LPCWSTR)param);
+ return TRUE;
+ }
+ return __super::OnMediaLibraryIPC(msg, param, pResult);
+} \ No newline at end of file