xref: /reactos/dll/cpl/desk/appearance.c (revision 5eb25b5c)
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 #include "theme.h"
13 #include "preview.h"
14 #include "appearance.h"
15 
16 /******************************************************************************/
17 
18 static INT_PTR
19 AppearancePage_OnInit(HWND hwndDlg)
20 {
21 	TCHAR strSelectedStyle[4];
22 	INT i, TemplateCount, iListIndex;
23 	HWND hwndCombo;
24 	GLOBALS *g;
25 
26 	g = (GLOBALS*)LocalAlloc(LPTR, sizeof(GLOBALS));
27 	if (g == NULL)
28 		return FALSE;
29 
30 	SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
31 
32 	LoadCurrentTheme(&g->Theme);
33 	g->ThemeAdv = g->Theme;
34 	g->bHasChanged = FALSE;
35 	g->hBoldFont = g->hItalicFont = NULL;
36 	g->hbmpColor[0] = g->hbmpColor[1] = g->hbmpColor[2] = NULL;
37 	g->bInitializing = FALSE;
38 
39 	TemplateCount = LoadThemePresetEntries(strSelectedStyle);
40 
41 	hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
42 	g->ThemeId = -1;
43 	g->bInitializing = TRUE;
44 	for(i = 0; i < TemplateCount; i++)
45 	{
46 		iListIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)g_ThemeTemplates[i].strLegacyName);
47 		SendMessage(hwndCombo, CB_SETITEMDATA, iListIndex, i);
48 		if (lstrcmp(g_ThemeTemplates[i].strKeyName, strSelectedStyle) == 0)
49 		{
50 			g->ThemeId = i;
51 			SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)iListIndex, 0);
52 		}
53 	}
54 	g->bInitializing = FALSE;
55 
56 	return FALSE;
57 }
58 
59 static VOID
60 AppearancePage_OnDestroy(HWND hwndDlg, GLOBALS *g)
61 {
62 	LocalFree(g);
63 }
64 
65 static INT
66 GetSelectedThemeId(HWND hwndDlg)
67 {
68 	HWND hwndCombo;
69 	INT sel;
70 
71 	hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
72 	sel = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
73 	if (sel == CB_ERR)
74 		return -1;
75 	return (INT)SendMessage(hwndCombo, CB_GETITEMDATA, (WPARAM)sel, 0);
76 }
77 
78 INT_PTR CALLBACK
79 AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
80 {
81 	GLOBALS *g;
82 	LPNMHDR lpnm;
83 
84 	g = (GLOBALS*)GetWindowLongPtr(hwndDlg, DWLP_USER);
85 
86 	switch (uMsg)
87 	{
88 		case WM_INITDIALOG:
89 			return AppearancePage_OnInit(hwndDlg);
90 
91 		case WM_DESTROY:
92 			AppearancePage_OnDestroy(hwndDlg, g);
93 			break;
94 
95 		case WM_COMMAND:
96 			switch (LOWORD(wParam))
97 			{
98 				case IDC_APPEARANCE_EFFECTS:
99 					if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_EFFAPPEARANCE),
100 									   hwndDlg, EffAppearanceDlgProc, (LPARAM)g) == IDOK)
101 					{
102 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
103 						g->Theme = g->ThemeAdv;
104 						g->bHasChanged = TRUE;
105 						g->ThemeId = -1;	/* Customized */
106 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
107 						SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
108 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
109 					}
110 					break;
111 
112 				case IDC_APPEARANCE_ADVANCED:
113 					if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_ADVAPPEARANCE),
114 									   hwndDlg, AdvAppearanceDlgProc, (LPARAM)g) == IDOK)
115 					{
116 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
117 						g->Theme = g->ThemeAdv;
118 					    g_GlobalData.desktop_color = g->Theme.crColor[COLOR_DESKTOP];
119 						g->bHasChanged = TRUE;
120 						g->ThemeId = -1;	/* Customized */
121 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
122 						SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
123 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
124 					}
125 					break;
126 
127 				case IDC_APPEARANCE_COLORSCHEME:
128 					if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
129 					{
130 						THEME Theme;
131 						INT ThemeId = GetSelectedThemeId(hwndDlg);
132 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
133 						g->bHasChanged = TRUE;
134 						if (ThemeId != -1 && LoadThemeFromReg(&Theme, ThemeId))
135 						{
136 							g->Theme = Theme;
137 							g->ThemeId = ThemeId;
138 							SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Theme);
139 						}
140 					}
141 					break;
142 			}
143 			break;
144 
145 		case WM_NOTIFY:
146 			lpnm = (LPNMHDR)lParam;
147 			switch (lpnm->code)
148 			{
149 				case PSN_APPLY:
150 					if (g->bHasChanged)
151 					{
152 						INT ThemeId = GetSelectedThemeId(hwndDlg);
153 						ApplyTheme(&g->Theme, ThemeId);
154 						g->ThemeId = ThemeId;
155 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
156 						g->bHasChanged = FALSE;
157 					}
158 					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)PSNRET_NOERROR);
159 					return TRUE;
160 
161 				case PSN_KILLACTIVE:
162 					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)FALSE);
163 					return TRUE;
164 
165 				case PSN_SETACTIVE:
166 					if (g->Theme.crColor[COLOR_DESKTOP] != g_GlobalData.desktop_color)
167 					{
168 						g->Theme.crColor[COLOR_DESKTOP] = g_GlobalData.desktop_color;
169 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
170 					}
171 					break;
172 			}
173 			break;
174 	}
175 
176 	return FALSE;
177 }
178