ReactOS  0.4.14-dev-554-g2f8d847
appearance.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Display Control Panel
4  * FILE: dll/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
17 {
18  if (g->ActiveTheme.ThemeActive)
19  {
20  RECT rcWindow;
21 
22  GetClientRect(GetDlgItem(hwndDlg, IDC_APPEARANCE_PREVIEW), &rcWindow);
23  if (DrawThemePreview(g->hdcThemePreview, &g->Scheme, &g->ActiveTheme, &rcWindow))
24  {
25  SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SET_HDC_PREVIEW, 0, (LPARAM)g->hdcThemePreview);
26  return;
27  }
28  }
29 
32 }
33 
34 static void
36 {
37  if (g->ActiveTheme.ThemeActive == FALSE )
38  {
39  LoadSchemeFromReg(&g->Scheme, &g->ActiveTheme);
40  }
41  else
42  {
43  LoadSchemeFromTheme(&g->Scheme, &g->ActiveTheme);
44  }
45 
46  g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
47 }
48 
49 static void
51 {
52  int iListIndex;
53  HWND hwndList = GetDlgItem(hwndDlg, nIDDlgItem);
54  PTHEME_STYLE pCurrentStyle;
55 
56  SendMessage(hwndList, CB_RESETCONTENT , 0, 0);
57 
58  for (pCurrentStyle = pStyles;
59  pCurrentStyle;
60  pCurrentStyle = pCurrentStyle->NextStyle)
61  {
62  iListIndex = SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM)pCurrentStyle->DisplayName);
63  SendMessage(hwndList, CB_SETITEMDATA, iListIndex, (LPARAM)pCurrentStyle);
64  if (pCurrentStyle == pActiveStyle)
65  {
66  SendMessage(hwndList, CB_SETCURSEL, (WPARAM)iListIndex, 0);
67  }
68  }
69 }
70 
71 static void
73 {
76  g->ActiveTheme.Theme->ColoursList,
77  g->ActiveTheme.Color);
78 }
79 
80 static void
82 {
83  PTHEME_STYLE pSizes;
84 
85  if (g->ActiveTheme.Theme->SizesList)
86  pSizes = g->ActiveTheme.Theme->SizesList;
87  else
88  pSizes = g->ActiveTheme.Color->ChildStyle;
89 
92  pSizes,
93  g->ActiveTheme.Size);
94 }
95 
96 static INT_PTR
98 {
99  INT iListIndex;
100  HWND hwndTheme;
101  GLOBALS *g;
102  RECT rcPreview;
103  HDC hdcScreen;
104  PTHEME pTheme;
105 
107  if (g == NULL)
108  return FALSE;
109 
110  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
111 
112  g->bInitializing = TRUE;
113 
114  if (!LoadCurrentScheme(&g->Scheme))
115  return FALSE;
116 
117  g->pThemes = LoadThemes();
118  if (g->pThemes)
119  {
120  BOOL bLoadedTheme = FALSE;
121 
122  if (g_GlobalData.pwszAction &&
124  wcscmp(g_GlobalData.pwszAction, L"OpenMSTheme") == 0)
125  {
126  bLoadedTheme = FindOrAppendTheme(g->pThemes,
128  NULL,
129  NULL,
130  &g->ActiveTheme);
131  }
132 
133  if (bLoadedTheme)
134  {
135  g->bThemeChanged = TRUE;
136  g->bSchemeChanged = TRUE;
137 
138  PostMessageW(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
139 
141  }
142  else
143  {
144  if (!GetActiveTheme(g->pThemes, &g->ActiveTheme))
145  {
146  g->ActiveTheme.ThemeActive = FALSE;
147  }
148  }
149 
150  /*
151  * Keep a copy of the selected classic theme in order to select this
152  * when user selects the classic theme (and not a horrible random theme )
153  */
154  if (!GetActiveClassicTheme(g->pThemes, &g->ClassicTheme))
155  {
156  g->ClassicTheme.Theme = g->pThemes;
157  g->ClassicTheme.Color = g->pThemes->ColoursList;
158  g->ClassicTheme.Size = g->ClassicTheme.Color->ChildStyle;
159  }
160 
161  if (g->ActiveTheme.ThemeActive == FALSE)
162  g->ActiveTheme = g->ClassicTheme;
163 
164  GetClientRect(GetDlgItem(hwndDlg, IDC_APPEARANCE_PREVIEW), &rcPreview);
165 
166  hdcScreen = GetDC(NULL);
167  g->hbmpThemePreview = CreateCompatibleBitmap(hdcScreen, rcPreview.right, rcPreview.bottom);
168  g->hdcThemePreview = CreateCompatibleDC(hdcScreen);
169  SelectObject(g->hdcThemePreview, g->hbmpThemePreview);
170  ReleaseDC(NULL, hdcScreen);
171 
172  hwndTheme = GetDlgItem(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
173 
174  for (pTheme = g->pThemes; pTheme; pTheme = pTheme->NextTheme)
175  {
176  iListIndex = SendMessage(hwndTheme, CB_ADDSTRING, 0, (LPARAM)pTheme->DisplayName);
177  SendMessage(hwndTheme, CB_SETITEMDATA, iListIndex, (LPARAM)pTheme);
178  if (pTheme == g->ActiveTheme.Theme)
179  {
180  SendMessage(hwndTheme, CB_SETCURSEL, (WPARAM)iListIndex, 0);
181  }
182  }
183 
184  if (g->ActiveTheme.Theme)
185  {
187  AppearancePage_ShowSizes(hwndDlg, g);
189  }
190  }
191  g->bInitializing = FALSE;
192 
193  return FALSE;
194 }
195 
196 static VOID
198 {
199  HeapFree(GetProcessHeap(), 0, g);
200 }
201 
202 static PVOID
204 {
205  HWND hwndCombo;
206  INT sel;
207 
208  hwndCombo = GetDlgItem(hwndDlg, nIDDlgItem);
209  sel = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
210  if (sel == CB_ERR)
211  return NULL;
212  return (PVOID)SendMessage(hwndCombo, CB_GETITEMDATA, (WPARAM)sel, 0);
213 }
214 
217 {
218  GLOBALS *g;
219  LPNMHDR lpnm;
220 
221  g = (GLOBALS*)GetWindowLongPtr(hwndDlg, DWLP_USER);
222 
223  switch (uMsg)
224  {
225  case WM_INITDIALOG:
226  return AppearancePage_OnInit(hwndDlg);
227 
228  case WM_DESTROY:
229  AppearancePage_OnDestroy(hwndDlg, g);
230  break;
231 
232  case WM_COMMAND:
233  if (g == NULL || g->bInitializing)
234  return FALSE;
235 
236  switch (LOWORD(wParam))
237  {
240  hwndDlg, EffAppearanceDlgProc, (LPARAM)g) == IDOK)
241  {
242  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
243  g->Scheme = g->SchemeAdv;
244  g->bSchemeChanged = TRUE;
245  }
246  break;
247 
250  hwndDlg, AdvAppearanceDlgProc, (LPARAM)g) == IDOK)
251  {
252  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
253  g->bSchemeChanged = TRUE;
254  g->Scheme = g->SchemeAdv;
255  g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
256 
258  }
259  break;
260 
262  if (HIWORD(wParam) == CBN_SELCHANGE)
263  {
264  g->ActiveTheme.Color = (PTHEME_STYLE)GetSelectedData(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
265  if (g->ActiveTheme.Color->ChildStyle != NULL)
266  g->ActiveTheme.Size = g->ActiveTheme.Color->ChildStyle;
267 
268  g->bSchemeChanged = TRUE;
269  if (g->ActiveTheme.ThemeActive)
270  g->bThemeChanged = TRUE;
271 
272  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
273 
275  AppearancePage_ShowSizes(hwndDlg, g);
277  }
278  break;
279 
281  if (HIWORD(wParam) == CBN_SELCHANGE)
282  {
284 
285  if (g->ClassicTheme.Theme == pTheme)
286  g->ActiveTheme = g->ClassicTheme;
287  else
288  {
289  g->ActiveTheme.Theme = pTheme;
290  g->ActiveTheme.Size = pTheme->SizesList;
291  g->ActiveTheme.Color = pTheme->ColoursList;
292  g->ActiveTheme.ThemeActive = TRUE;
293  }
294 
295  g->bThemeChanged = TRUE;
296  g->bSchemeChanged = TRUE;
297 
298  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
299 
301  AppearancePage_ShowSizes(hwndDlg, g);
304  }
305  break;
306 
307  case IDC_APPEARANCE_SIZE:
308  if (HIWORD(wParam) == CBN_SELCHANGE)
309  {
310  g->ActiveTheme.Size = (PTHEME_STYLE)GetSelectedData(hwndDlg, IDC_APPEARANCE_SIZE);
311  g->bSchemeChanged = TRUE;
312  if (g->ActiveTheme.ThemeActive)
313  g->bThemeChanged = TRUE;
314 
315  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
316 
319  }
320  }
321  break;
322 
323  case WM_NOTIFY:
324  lpnm = (LPNMHDR)lParam;
325  switch (lpnm->code)
326  {
327  case PSN_APPLY:
328 
329  if (g->bThemeChanged)
330  {
331  ActivateTheme(&g->ActiveTheme);
332  }
333 
334  if (g->bSchemeChanged)
335  {
336  ApplyScheme(&g->Scheme, &g->ActiveTheme);
337  if (g->ActiveTheme.ThemeActive == FALSE)
338  g->ClassicTheme = g->ActiveTheme;
339  }
340 
342  g->bThemeChanged = FALSE;
343  g->bSchemeChanged = FALSE;
345  return TRUE;
346 
347  case PSN_KILLACTIVE:
349  return TRUE;
350 
351  case PSN_SETACTIVE:
352  if (g->Scheme.crColor[COLOR_DESKTOP] != g_GlobalData.desktop_color)
353  {
354  g->Scheme.crColor[COLOR_DESKTOP] = g_GlobalData.desktop_color;
356  }
357  break;
358  }
359  break;
360  }
361 
362  return FALSE;
363 }
BOOL ActivateTheme(PTHEME_SELECTION pSelectedTheme)
INT_PTR CALLBACK EffAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: effappdlg.c:130
#define CB_SETITEMDATA
Definition: winuser.h:1948
BOOL LoadSchemeFromTheme(PCOLOR_SCHEME scheme, PTHEME_SELECTION pSelectedTheme)
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL LoadSchemeFromReg(PCOLOR_SCHEME scheme, PTHEME_SELECTION pSelectedTheme)
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define IDC_APPEARANCE_ADVANCED
Definition: resource.h:90
HDC WINAPI GetDC(_In_opt_ HWND)
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
static VOID AppearancePage_OnDestroy(HWND hwndDlg, GLOBALS *g)
Definition: appearance.c:197
static void AppearancePage_ShowColorSchemes(HWND hwndDlg, GLOBALS *g)
Definition: appearance.c:72
static PVOID GetSelectedData(HWND hwndDlg, int nIDDlgItem)
Definition: appearance.c:203
#define CB_GETITEMDATA
Definition: winuser.h:1932
COLORREF desktop_color
Definition: desk.h:106
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
#define IDC_APPEARANCE_COLORSCHEME
Definition: resource.h:87
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
_In_ int nIDDlgItem
Definition: winuser.h:4594
struct _THEME_STYLE * NextStyle
Definition: appearance.h:81
LPCWSTR pwszAction
Definition: desk.h:108
HINSTANCE hApplet
Definition: access.c:17
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define COLOR_DESKTOP
Definition: winuser.h:904
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5817
#define PSN_APPLY
Definition: prsht.h:117
THEME_STYLE * SizesList
Definition: appearance.h:93
int32_t INT_PTR
Definition: typedefs.h:62
#define IDC_APPEARANCE_SIZE
Definition: resource.h:92
LONG right
Definition: windef.h:308
PWSTR DisplayName
Definition: appearance.h:91
#define PSN_SETACTIVE
Definition: prsht.h:115
int32_t INT
Definition: typedefs.h:56
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1925
WPARAM wParam
Definition: combotst.c:138
#define DWLP_MSGRESULT
Definition: winuser.h:864
struct tagNMHDR * LPNMHDR
UINT code
Definition: winuser.h:3134
PTHEME LoadThemes(VOID)
Definition: theme.c:749
#define PSN_KILLACTIVE
Definition: prsht.h:116
PWSTR DisplayName
Definition: appearance.h:84
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL DrawThemePreview(HDC hdcMem, PCOLOR_SCHEME scheme, PTHEME_SELECTION pSelectedTheme, PRECT prcWindow)
struct _THEME_STYLE * PTHEME_STYLE
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
INT_PTR CALLBACK AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: advappdlg.c:504
static void AppearancePage_UpdateThemePreview(HWND hwndDlg, GLOBALS *g)
Definition: appearance.c:16
#define CB_ADDSTRING
Definition: winuser.h:1918
#define PVM_SET_HDC_PREVIEW
Definition: preview.h:32
smooth NULL
Definition: ftsmooth.c:416
#define IDC_APPEARANCE_VISUAL_STYLE
Definition: resource.h:91
LONG_PTR LPARAM
Definition: windef.h:208
LPCWSTR pwszFile
Definition: desk.h:107
static void AppearancePage_LoadSelectedScheme(HWND hwndDlg, GLOBALS *g)
Definition: appearance.c:35
#define CB_RESETCONTENT
Definition: winuser.h:1941
#define CB_ERR
Definition: winuser.h:2410
#define WM_DESTROY
Definition: winuser.h:1591
GLboolean GLboolean g
Definition: glext.h:6204
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
#define PVM_UPDATETHEME
Definition: preview.h:33
BOOL GetActiveTheme(PTHEME pThemeList, PTHEME_SELECTION pSelectedTheme)
#define PSNRET_NOERROR
Definition: prsht.h:129
#define DialogBoxParam
Definition: winuser.h:5739
static const WCHAR L[]
Definition: oid.c:1250
#define DWLP_USER
Definition: winuser.h:866
VOID ApplyScheme(PCOLOR_SCHEME scheme, PTHEME_SELECTION pSelectedTheme)
static INT_PTR AppearancePage_OnInit(HWND hwndDlg)
Definition: appearance.c:97
#define CB_SETCURSEL
Definition: winuser.h:1943
#define WM_COMMAND
Definition: winuser.h:1722
THEME_STYLE * ColoursList
Definition: appearance.h:92
struct _THEME_STYLE * ChildStyle
Definition: appearance.h:82
struct _THEME * NextTheme
Definition: appearance.h:89
#define IDC_APPEARANCE_PREVIEW
Definition: resource.h:86
BOOL GetActiveClassicTheme(PTHEME pThemeList, PTHEME_SELECTION pSelectedTheme)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
HWND WINAPI GetParent(_In_ HWND)
#define IDD_ADVAPPEARANCE
Definition: resource.h:14
static void AppearancePage_ShowSizes(HWND hwndDlg, GLOBALS *g)
Definition: appearance.c:81
BOOL FindOrAppendTheme(IN PTHEME pThemeList, IN LPCWSTR pwszThemeFileName, IN LPCWSTR pwszColorBuff, IN LPCWSTR pwszSizeBuff, OUT PTHEME_SELECTION pSelectedTheme)
Definition: theme.c:791
BOOL LoadCurrentScheme(PCOLOR_SCHEME scheme)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
struct _GLOBALS GLOBALS
unsigned int UINT
Definition: ndis.h:50
#define PSM_CHANGED
Definition: prsht.h:164
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define CBN_SELCHANGE
Definition: winuser.h:1961
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define SendMessage
Definition: winuser.h:5818
GLOBAL_DATA g_GlobalData
Definition: background.c:84
static void AppearancePage_ShowStyles(HWND hwndDlg, int nIDDlgItem, PTHEME_STYLE pStyles, PTHEME_STYLE pActiveStyle)
Definition: appearance.c:50
#define HIWORD(l)
Definition: typedefs.h:246
LONG bottom
Definition: windef.h:309
#define IDC_APPEARANCE_EFFECTS
Definition: resource.h:89
#define IDD_EFFAPPEARANCE
Definition: resource.h:15
#define GetWindowLongPtr
Definition: treelist.c:73
INT_PTR CALLBACK AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: appearance.c:216
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:402
struct _THEME * PTHEME
#define WM_NOTIFY
Definition: richedit.h:61