xref: /reactos/dll/cpl/desk/appearance.c (revision e4d0ea53)
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 	LoadCurrentScheme(&g->Scheme);
33 	g->SchemeAdv = g->Scheme;
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 = LoadSchemePresetEntries(strSelectedStyle);
40 
41 	hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
42 	g->SchemeId = -1;
43 	g->bInitializing = TRUE;
44 	for(i = 0; i < TemplateCount; i++)
45 	{
46 		iListIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)g_ColorSchemes[i].strLegacyName);
47 		SendMessage(hwndCombo, CB_SETITEMDATA, iListIndex, i);
48 		if (lstrcmp(g_ColorSchemes[i].strKeyName, strSelectedStyle) == 0)
49 		{
50 			g->SchemeId = 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->Scheme = g->SchemeAdv;
104 						g->bHasChanged = TRUE;
105 						// Effects dialog doesn't change the color scheme, therefore the following lines are commented out, until fixed finally
106 						//g->SchemeId = -1;	/* Customized */
107 						//SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
108 						//SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
109 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
110 					}
111 					break;
112 
113 				case IDC_APPEARANCE_ADVANCED:
114 					if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_ADVAPPEARANCE),
115 									   hwndDlg, AdvAppearanceDlgProc, (LPARAM)g) == IDOK)
116 					{
117 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
118 						g->bHasChanged = TRUE;
119 						g->Scheme = g->SchemeAdv;
120 						g->SchemeId = -1;	/* Customized */
121 						g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
122 
123 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
124 						SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
125 
126 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
127 					}
128 					break;
129 
130 				case IDC_APPEARANCE_COLORSCHEME:
131 					if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
132 					{
133 						COLOR_SCHEME Scheme;
134 						INT SchemeId = GetSelectedThemeId(hwndDlg);
135 						PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
136 						g->bHasChanged = TRUE;
137 						if (SchemeId != -1 && LoadSchemeFromReg(&Scheme, SchemeId))
138 						{
139 							g->Scheme = Scheme;
140 							g->SchemeId = SchemeId;
141 							g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
142 							SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Scheme);
143 						}
144 					}
145 					break;
146 			}
147 			break;
148 
149 		case WM_NOTIFY:
150 			lpnm = (LPNMHDR)lParam;
151 			switch (lpnm->code)
152 			{
153 				case PSN_APPLY:
154 					if (g->bHasChanged)
155 					{
156 						INT SchemeId = GetSelectedThemeId(hwndDlg);
157 						ApplyScheme(&g->Scheme, SchemeId);
158 						g->SchemeId = SchemeId;
159 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
160 						g->bHasChanged = FALSE;
161 					}
162 					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)PSNRET_NOERROR);
163 					return TRUE;
164 
165 				case PSN_KILLACTIVE:
166 					SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)FALSE);
167 					return TRUE;
168 
169 				case PSN_SETACTIVE:
170 					if (g->Scheme.crColor[COLOR_DESKTOP] != g_GlobalData.desktop_color)
171 					{
172 						g->Scheme.crColor[COLOR_DESKTOP] = g_GlobalData.desktop_color;
173 						SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Scheme);
174 					}
175 					break;
176 			}
177 			break;
178 	}
179 
180 	return FALSE;
181 }
182