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