Sync with trunk (48237)
[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 #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->bHasChanged = TRUE;
119 g->ThemeId = -1; /* Customized */
120 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
121 SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
122 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
123 }
124 break;
125
126 case IDC_APPEARANCE_COLORSCHEME:
127 if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
128 {
129 THEME Theme;
130 INT ThemeId = GetSelectedThemeId(hwndDlg);
131 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
132 g->bHasChanged = TRUE;
133 if (ThemeId != -1 && LoadThemeFromReg(&Theme, ThemeId))
134 {
135 g->Theme = Theme;
136 g->ThemeId = ThemeId;
137 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Theme);
138 }
139 }
140 break;
141 }
142 break;
143
144 case WM_NOTIFY:
145 lpnm = (LPNMHDR)lParam;
146 switch (lpnm->code)
147 {
148 case PSN_APPLY:
149 if (g->bHasChanged)
150 {
151 INT ThemeId = GetSelectedThemeId(hwndDlg);
152 ApplyTheme(&g->Theme, ThemeId);
153 g->ThemeId = ThemeId;
154 SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
155 g->bHasChanged = FALSE;
156 }
157 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)PSNRET_NOERROR);
158 return TRUE;
159
160 case PSN_KILLACTIVE:
161 SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)FALSE);
162 return TRUE;
163 }
164 break;
165 }
166
167 return FALSE;
168 }