xref: /reactos/dll/cpl/desk/appearance.c (revision 68488873)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS Display Control Panel
4  * FILE:            lib/cpl/desk/appearance.c
5  * PURPOSE:         Appearance property page
6  *
7  * PROGRAMMERS:     Trevor McCort (lycan359@gmail.com)
8  *                  Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de)
9  */
10 
11 #include "desk.h"
12 
13 /******************************************************************************/
14 
15 static void
16 AppearancePage_ShowColorScemes(GLOBALS *g, HWND hwndColor, INT ThemeId)
17 {
18 	int i, iListIndex;
19 
20 	SendMessage(hwndColor, CB_RESETCONTENT , 0, 0);
21 
22 	if(g->bThemeActive == FALSE)
23 	{
24 		for(i = 0; i < g_TemplateCount; i++)
25 		{
26 			iListIndex = SendMessage(hwndColor, CB_ADDSTRING, 0, (LPARAM)g_ColorSchemes[i].strLegacyName);
27 			SendMessage(hwndColor, CB_SETITEMDATA, iListIndex, i);
28 			if (lstrcmp(g_ColorSchemes[i].strKeyName, g->strSelectedStyle) == 0)
29 			{
30 				g->SchemeId = i;
31 				SendMessage(hwndColor, CB_SETCURSEL, (WPARAM)iListIndex, 0);
32 			}
33 		}
34 	}
35 	else
36 	{
37 		PTHEME pTheme = (PTHEME)DSA_GetItemPtr(g->Themes, ThemeId);
38 		for(i = 0; i < pTheme->ColorsCount; i++)
39 		{
40 			PTHEME_STYLE pStyleName;
41 			pStyleName = (PTHEME_STYLE)DSA_GetItemPtr(pTheme->Colors, i);
42 			iListIndex = SendMessage(hwndColor, CB_ADDSTRING, 0, (LPARAM)pStyleName->DisplayName);
43 			SendMessage(hwndColor, CB_SETITEMDATA, iListIndex, i);
44 			if(i == 0 || (g->pszColorName && wcscmp(pStyleName->StlyeName, g->pszColorName) == 0))
45 			{
46 				g->SchemeId = i;
47 				SendMessage(hwndColor, CB_SETCURSEL, (WPARAM)iListIndex, 0);
48 			}
49 		}
50 	}
51 }
52 
53 static INT_PTR
54 AppearancePage_OnInit(HWND hwndDlg)
55 {
56 	INT i, TemplateCount, iListIndex;
57 	HWND hwndColor, hwndTheme;
58 	GLOBALS *g;
59 
60 	g = (GLOBALS*)LocalAlloc(LPTR, sizeof(GLOBALS));
61 	if (g == NULL)
62 		return FALSE;
63 
64 	SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
65 
66 	LoadCurrentScheme(&g->Scheme);
67 	g->SchemeAdv = g->Scheme;
68 	g->bThemeChanged = FALSE;
69 	g->bSchemeChanged = FALSE;
70 	g->hBoldFont = g->hItalicFont = NULL;
71 	g->hbmpColor[0] = g->hbmpColor[1] = g->hbmpColor[2] = NULL;
72 	g->bInitializing = FALSE;
73 	g->bThemeActive = FALSE;
74 
75 	LoadThemes(g);
76 
77 	TemplateCount = LoadSchemePresetEntries(g->strSelectedStyle);
78 
79 	hwndColor = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
80 	g->SchemeId = -1;
81 	g->bInitializing = TRUE;
82 
83 	hwndTheme = GetDlgItem(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
84 	for(i = 0; i < g->ThemesCount; i++)
85 	{
86 		PTHEME pTheme = (PTHEME)DSA_GetItemPtr(g->Themes, i);
87 		iListIndex = SendMessage(hwndTheme, CB_ADDSTRING, 0, (LPARAM)pTheme->displayName);
88 		SendMessage(hwndTheme, CB_SETITEMDATA, iListIndex, i);
89 		if((!pTheme->themeFileName && !IsThemeActive()) ||
90 		   (pTheme->themeFileName && g->pszThemeFileName && wcscmp(pTheme->themeFileName, g->pszThemeFileName) == 0 ))
91 		{
92 			g->ThemeId = i;
93 			g->bThemeActive = (pTheme->themeFileName != NULL);
94 			SendMessage(hwndTheme, CB_SETCURSEL, (WPARAM)iListIndex, 0);
95 			AppearancePage_ShowColorScemes(g, hwndColor, i);
96 		}
97 
98 	}
99 
100 	g->bInitializing = FALSE;
101 
102 	return FALSE;
103 }
104 
105 static VOID
106 AppearancePage_OnDestroy(HWND hwndDlg, GLOBALS *g)
107 {
108 	LocalFree(g);
109 }
110 
111 static INT
112 GetSelectedId(HWND hwndDlg, int nIDDlgItem)
113 {
114 	HWND hwndCombo;
115 	INT sel;
116 
117 	hwndCombo = GetDlgItem(hwndDlg, nIDDlgItem);
118 	sel = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
119 	if (sel == CB_ERR)
120 		return -1;
121 	return (INT)SendMessage(hwndCombo, CB_GETITEMDATA, (WPARAM)sel, 0);
122 }
123 
124 INT_PTR CALLBACK
125 AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
126 {
127 	GLOBALS *g;
128 	LPNMHDR lpnm;
129 
130 	g = (GLOBALS*)GetWindowLongPtr(hwndDlg, DWLP_USER);
131 
132 	switch (uMsg)
133 	{
134 		case WM_INITDIALOG:
135 			return AppearancePage_OnInit(hwndDlg);
136 
137 		case WM_DESTROY:
138 			AppearancePage_OnDestroy(hwndDlg, g);
139 			break;
140 
141 		case WM_COMMAND:
142 			switch (LOWORD(wParam))
143 			{
144 				case IDC_APPEARANCE_EFFECTS:
145 					if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_EFFAPPEARANCE),
146 									   hwndDlg, EffAppearanceDlgProc, (LPARAM)g) == IDOK)
147 					{
148 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
149 						g->Scheme = g->SchemeAdv;
150 						g->bSchemeChanged = TRUE;
151 						// Effects dialog doesn't change the color scheme, therefore the following lines are commented out, until fixed finally
152 						//g->SchemeId = -1;	/* Customized */
153 						//SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
154 						//SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
155 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
156 					}
157 					break;
158 
159 				case IDC_APPEARANCE_ADVANCED:
160 					if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_ADVAPPEARANCE),
161 									   hwndDlg, AdvAppearanceDlgProc, (LPARAM)g) == IDOK)
162 					{
163 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
164 						g->bSchemeChanged = TRUE;
165 						g->Scheme = g->SchemeAdv;
166 						g->SchemeId = -1;	/* Customized */
167 						g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
168 
169 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
170 						SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
171 
172 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
173 					}
174 					break;
175 
176 				case IDC_APPEARANCE_COLORSCHEME:
177 					if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
178 					{
179 						INT SchemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
180 
181 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
182 
183 						if(g->bThemeActive == FALSE)
184 						{
185 							COLOR_SCHEME Scheme;
186 
187 							g->bSchemeChanged = TRUE;
188 							if (SchemeId != -1 && LoadSchemeFromReg(&Scheme, SchemeId))
189 							{
190 								g->Scheme = Scheme;
191 								g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
192 								SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Scheme);
193 							}
194 						}
195 						else
196 						{
197 							g->bThemeChanged = TRUE;
198 						}
199 					}
200 					break;
201 				case IDC_APPEARANCE_VISUAL_STYLE:
202 					if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
203 					{
204 						INT ThemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
205 						HWND hwndColor = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
206 
207 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
208 
209 						g->bThemeActive = (ThemeId!=0);
210 						g->bThemeChanged = TRUE;
211 						AppearancePage_ShowColorScemes(g, hwndColor, ThemeId);
212 					}
213 					break;
214 			}
215 			break;
216 
217 		case WM_NOTIFY:
218 			lpnm = (LPNMHDR)lParam;
219 			switch (lpnm->code)
220 			{
221 				case PSN_APPLY:
222 
223 					g->ThemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
224 					g->SchemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
225 
226 					if(g->bSchemeChanged)
227 					{
228 						ApplyScheme(&g->Scheme, g->SchemeId);
229 					}
230 
231 					if(g->bThemeChanged)
232 					{
233 						PTHEME pTheme = (PTHEME)DSA_GetItemPtr(g->Themes, g->ThemeId);
234 						ActivateTheme(pTheme, g->SchemeId, 0);
235 					}
236 
237 					SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
238 					g->bThemeChanged = FALSE;
239 					g->bSchemeChanged = FALSE;
240 					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)PSNRET_NOERROR);
241 					return TRUE;
242 
243 				case PSN_KILLACTIVE:
244 					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)FALSE);
245 					return TRUE;
246 
247 				case PSN_SETACTIVE:
248 					if (g->Scheme.crColor[COLOR_DESKTOP] != g_GlobalData.desktop_color)
249 					{
250 						g->Scheme.crColor[COLOR_DESKTOP] = g_GlobalData.desktop_color;
251 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
252 					}
253 					break;
254 			}
255 			break;
256 	}
257 
258 	return FALSE;
259 }
260