aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/General/gen_ml/skinnedstatic.cpp
blob: 864d7963da3975716f60675a0fd2abd63b3d199c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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);
}