Author: gadamopoulos
Date: Fri Aug 19 15:01:36 2011
New Revision: 53315
URL:
http://svn.reactos.org/svn/reactos?rev=53315&view=rev
Log:
[desk]
- Implement themes support. Even though it doesn't show a preview and doesn't
support choosing a theme size, it can configure themes fine
Modified:
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.c
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.h
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.h
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.rbuild
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/effappdlg.c
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/lang/en-US.rc
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/resource.h
branches/GSoC_2011/ThemesSupport/dll/cpl/desk/theme.c
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.c [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.c [iso-8859-1] Fri Aug 19
15:01:36 2011
@@ -12,12 +12,49 @@
/******************************************************************************/
+static void
+AppearancePage_ShowColorScemes(GLOBALS *g, HWND hwndColor, INT ThemeId)
+{
+ int i, iListIndex;
+
+ SendMessage(hwndColor, CB_RESETCONTENT , 0, 0);
+
+ if(g->bThemeActive == FALSE)
+ {
+ for(i = 0; i < g_TemplateCount; i++)
+ {
+ iListIndex = SendMessage(hwndColor, CB_ADDSTRING, 0,
(LPARAM)g_ColorSchemes[i].strLegacyName);
+ SendMessage(hwndColor, CB_SETITEMDATA, iListIndex, i);
+ if (lstrcmp(g_ColorSchemes[i].strKeyName, g->strSelectedStyle) == 0)
+ {
+ g->SchemeId = i;
+ SendMessage(hwndColor, CB_SETCURSEL, (WPARAM)iListIndex, 0);
+ }
+ }
+ }
+ else
+ {
+ PTHEME pTheme = (PTHEME)DSA_GetItemPtr(g->Themes, ThemeId);
+ for(i = 0; i < pTheme->ColorsCount; i++)
+ {
+ PTHEME_STYLE pStyleName;
+ pStyleName = (PTHEME_STYLE)DSA_GetItemPtr(pTheme->Colors, i);
+ iListIndex = SendMessage(hwndColor, CB_ADDSTRING, 0,
(LPARAM)pStyleName->DisplayName);
+ SendMessage(hwndColor, CB_SETITEMDATA, iListIndex, i);
+ if(i == 0 || (g->pszColorName && wcscmp(pStyleName->StlyeName,
g->pszColorName) == 0))
+ {
+ g->SchemeId = i;
+ SendMessage(hwndColor, CB_SETCURSEL, (WPARAM)iListIndex, 0);
+ }
+ }
+ }
+}
+
static INT_PTR
AppearancePage_OnInit(HWND hwndDlg)
{
- TCHAR strSelectedStyle[4];
INT i, TemplateCount, iListIndex;
- HWND hwndCombo;
+ HWND hwndColor, hwndTheme;
GLOBALS *g;
g = (GLOBALS*)LocalAlloc(LPTR, sizeof(GLOBALS));
@@ -28,26 +65,38 @@
LoadCurrentScheme(&g->Scheme);
g->SchemeAdv = g->Scheme;
- g->bHasChanged = FALSE;
+ g->bThemeChanged = FALSE;
+ g->bSchemeChanged = FALSE;
g->hBoldFont = g->hItalicFont = NULL;
g->hbmpColor[0] = g->hbmpColor[1] = g->hbmpColor[2] = NULL;
g->bInitializing = FALSE;
-
- TemplateCount = LoadSchemePresetEntries(strSelectedStyle);
-
- hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+ g->bThemeActive = FALSE;
+
+ LoadThemes(g);
+
+ TemplateCount = LoadSchemePresetEntries(g->strSelectedStyle);
+
+ hwndColor = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
g->SchemeId = -1;
g->bInitializing = TRUE;
- for(i = 0; i < TemplateCount; i++)
- {
- iListIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0,
(LPARAM)g_ColorSchemes[i].strLegacyName);
- SendMessage(hwndCombo, CB_SETITEMDATA, iListIndex, i);
- if (lstrcmp(g_ColorSchemes[i].strKeyName, strSelectedStyle) == 0)
+
+ hwndTheme = GetDlgItem(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
+ for(i = 0; i < g->ThemesCount; i++)
+ {
+ PTHEME pTheme = (PTHEME)DSA_GetItemPtr(g->Themes, i);
+ iListIndex = SendMessage(hwndTheme, CB_ADDSTRING, 0, (LPARAM)pTheme->displayName);
+ SendMessage(hwndTheme, CB_SETITEMDATA, iListIndex, i);
+ if((!pTheme->themeFileName && !IsThemeActive()) ||
+ (pTheme->themeFileName && g->pszThemeFileName &&
wcscmp(pTheme->themeFileName, g->pszThemeFileName) == 0 ))
{
- g->SchemeId = i;
- SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)iListIndex, 0);
+ g->ThemeId = i;
+ g->bThemeActive = (pTheme->themeFileName != NULL);
+ SendMessage(hwndTheme, CB_SETCURSEL, (WPARAM)iListIndex, 0);
+ AppearancePage_ShowColorScemes(g, hwndColor, i);
}
- }
+
+ }
+
g->bInitializing = FALSE;
return FALSE;
@@ -60,12 +109,12 @@
}
static INT
-GetSelectedThemeId(HWND hwndDlg)
+GetSelectedId(HWND hwndDlg, int nIDDlgItem)
{
HWND hwndCombo;
INT sel;
- hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+ hwndCombo = GetDlgItem(hwndDlg, nIDDlgItem);
sel = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
if (sel == CB_ERR)
return -1;
@@ -98,7 +147,7 @@
{
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
g->Scheme = g->SchemeAdv;
- g->bHasChanged = TRUE;
+ g->bSchemeChanged = TRUE;
// Effects dialog doesn't change the color scheme, therefore the following
lines are commented out, until fixed finally
//g->SchemeId = -1; /* Customized */
//SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1,
0);
@@ -112,7 +161,7 @@
hwndDlg, AdvAppearanceDlgProc, (LPARAM)g) == IDOK)
{
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
- g->bHasChanged = TRUE;
+ g->bSchemeChanged = TRUE;
g->Scheme = g->SchemeAdv;
g->SchemeId = -1; /* Customized */
g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
@@ -127,17 +176,39 @@
case IDC_APPEARANCE_COLORSCHEME:
if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
{
- COLOR_SCHEME Scheme;
- INT SchemeId = GetSelectedThemeId(hwndDlg);
- PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
- g->bHasChanged = TRUE;
- if (SchemeId != -1 && LoadSchemeFromReg(&Scheme, SchemeId))
+ INT SchemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+
+ if(g->bThemeActive == FALSE)
{
- g->Scheme = Scheme;
- g->SchemeId = SchemeId;
- g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
- SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0,
(LPARAM)&Scheme);
+ COLOR_SCHEME Scheme;
+
+ g->bSchemeChanged = TRUE;
+ if (SchemeId != -1 && LoadSchemeFromReg(&Scheme, SchemeId))
+ {
+ g->Scheme = Scheme;
+ g_GlobalData.desktop_color = g->Scheme.crColor[COLOR_DESKTOP];
+ SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0,
(LPARAM)&Scheme);
+ }
}
+ else
+ {
+ g->bThemeChanged = TRUE;
+ }
+ }
+ break;
+ case IDC_APPEARANCE_VISUAL_STYLE:
+ if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
+ {
+ INT ThemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
+ HWND hwndColor = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+
+ g->bThemeActive = (ThemeId!=0);
+ g->bThemeChanged = TRUE;
+ AppearancePage_ShowColorScemes(g, hwndColor, ThemeId);
}
break;
}
@@ -148,14 +219,24 @@
switch (lpnm->code)
{
case PSN_APPLY:
- if (g->bHasChanged)
- {
- INT SchemeId = GetSelectedThemeId(hwndDlg);
- ApplyScheme(&g->Scheme, SchemeId);
- g->SchemeId = SchemeId;
- SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0,
(LPARAM)&g->Scheme);
- g->bHasChanged = FALSE;
- }
+
+ g->ThemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_VISUAL_STYLE);
+ g->SchemeId = GetSelectedId(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+
+ if(g->bSchemeChanged)
+ {
+ ApplyScheme(&g->Scheme, g->SchemeId);
+ }
+
+ if(g->bThemeChanged)
+ {
+ PTHEME pTheme = (PTHEME)DSA_GetItemPtr(g->Themes, g->ThemeId);
+ ActivateTheme(pTheme, g->SchemeId, 0);
+ }
+
+ SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0,
(LPARAM)&g->Scheme);
+ g->bThemeChanged = FALSE;
+ g->bSchemeChanged = FALSE;
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)PSNRET_NOERROR);
return TRUE;
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.h [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/appearance.h [iso-8859-1] Fri Aug 19
15:01:36 2011
@@ -76,17 +76,46 @@
TCHAR strLegacyName[MAX_TEMPLATENAMELENTGH];
} SCHEME_PRESET;
-/* Some typedefs for appearance */
+/* struct for holding theme colors and sizes */
+typedef struct _THEME_STYLE
+{
+ WCHAR* StlyeName;
+ WCHAR* DisplayName;
+} THEME_STYLE, *PTHEME_STYLE;
+
+typedef struct _THEME
+{
+ WCHAR* themeFileName;
+ WCHAR* displayName;
+ HDSA Colors;
+ int ColorsCount;
+ HDSA Sizes;
+ int SizesCount;
+
+} THEME, *PTHEME;
/* This is the global structure used to store the current values.
A pointer of this get's passed to the functions either directly
or by passing hwnd and getting the pointer by GetWindowLongPtr */
typedef struct tagGLOBALS
{
+ HDSA Themes;
+ int ThemesCount;
+ BOOL bThemeActive;
+
+ INT ThemeId;
INT SchemeId; /* Theme is customized if SchemeId == -1 */
+ INT SizeID;
+ TCHAR strSelectedStyle[4];
+
+ LPWSTR pszThemeFileName;
+ LPWSTR pszColorName;
+ LPWSTR pszSizeName;
+
COLOR_SCHEME Scheme;
COLOR_SCHEME SchemeAdv;
- BOOL bHasChanged;
+ BOOL bThemeChanged;
+ BOOL bSchemeChanged;
HBITMAP hbmpColor[3];
INT CurrentElement;
HFONT hBoldFont;
@@ -95,6 +124,7 @@
} GLOBALS;
extern SCHEME_PRESET g_ColorSchemes[MAX_TEMPLATES];
+extern INT g_TemplateCount;
/* prototypes for theme.c */
VOID LoadCurrentScheme(COLOR_SCHEME* scheme);
@@ -102,6 +132,9 @@
VOID ApplyScheme(COLOR_SCHEME* scheme, INT SchemeId);
BOOL SaveScheme(COLOR_SCHEME* scheme, LPCTSTR strLegacyName);
INT LoadSchemePresetEntries(LPTSTR pszSelectedStyle);
+VOID LoadThemes(GLOBALS *g);
+HRESULT ActivateTheme(PTHEME pTheme, int iColor, int iSize);
+void CleanupThemes(GLOBALS *g);
/* prototypes for appearance.c */
INT_PTR CALLBACK AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM
lParam);
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.h [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.h [iso-8859-1] Fri Aug 19 15:01:36
2011
@@ -11,6 +11,8 @@
#include <cplext.h>
#include <dll/desk/deskcplx.h>
#include <cfgmgr32.h>
+#include <Uxtheme.h>
+#include <uxundoc.h>
#include "appearance.h"
#include "preview.h"
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.rbuild [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/desk.rbuild [iso-8859-1] Fri Aug 19
15:01:36 2011
@@ -14,6 +14,7 @@
<library>shell32</library>
<library>ntdll</library>
<library>uuid</library>
+ <library>uxtheme</library>
<file>advmon.c</file>
<file>appearance.c</file>
<file>background.c</file>
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/effappdlg.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/effappdlg.c [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/effappdlg.c [iso-8859-1] Fri Aug 19
15:01:36 2011
@@ -26,7 +26,7 @@
g->SchemeAdv.Effects.bKeyboardCues = (state == BST_CHECKED) ? TRUE : FALSE;
state = SendDlgItemMessage(hwndDlg, IDC_EFFAPPEARANCE_DRAGFULLWINDOWS, BM_GETCHECK,
0, 0);
g->SchemeAdv.Effects.bDragFullWindows = (state == BST_CHECKED) ? TRUE : FALSE;
- g->bHasChanged = TRUE;
+ g->bSchemeChanged = TRUE;
}
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/lang/en-US.rc
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/lang/en-US.rc [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/lang/en-US.rc [iso-8859-1] Fri Aug 19
15:01:36 2011
@@ -51,8 +51,10 @@
BEGIN
CONTROL "", IDC_APPEARANCE_PREVIEW, "PreviewWndClass",
WS_VISIBLE | WS_BORDER, 7, 7, 232, 120
- LTEXT "Colorscheme", IDC_STATIC, 7, 140, 64, 7
- COMBOBOX IDC_APPEARANCE_COLORSCHEME, 7, 150, 134, 90, CBS_DROPDOWNLIST |
CBS_HASSTRINGS | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ LTEXT "Visual Style", IDC_STATIC, 7, 130, 64, 7
+ COMBOBOX IDC_APPEARANCE_VISUAL_STYLE, 7, 140, 134, 90, CBS_DROPDOWNLIST |
CBS_HASSTRINGS | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ LTEXT "Colorscheme", IDC_STATIC, 7, 160, 64, 7
+ COMBOBOX IDC_APPEARANCE_COLORSCHEME, 7, 170, 134, 90, CBS_DROPDOWNLIST |
CBS_HASSTRINGS | CBS_SORT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Effects...", IDC_APPEARANCE_EFFECTS, 182, 150, 56,
15
PUSHBUTTON "Ad&vanced...", IDC_APPEARANCE_ADVANCED, 182, 170, 56,
15
END
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/resource.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/resource.h [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/resource.h [iso-8859-1] Fri Aug 19
15:01:36 2011
@@ -96,6 +96,7 @@
#define IDC_APPEARANCE_FONTSIZE 1502
#define IDC_APPEARANCE_EFFECTS 1503
#define IDC_APPEARANCE_ADVANCED 1504
+#define IDC_APPEARANCE_VISUAL_STYLE 1505
#define IDS_INACTWIN 1510
#define IDS_ACTWIN 1511
Modified: branches/GSoC_2011/ThemesSupport/dll/cpl/desk/theme.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/dll/cpl…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/dll/cpl/desk/theme.c [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/dll/cpl/desk/theme.c [iso-8859-1] Fri Aug 19 15:01:36
2011
@@ -10,7 +10,7 @@
#include "desk.h"
static BOOL g_PresetLoaded = FALSE;
-static INT g_TemplateCount = 0;
+INT g_TemplateCount = 0;
static INT g_ColorList[NUM_COLORS];
@@ -119,8 +119,8 @@
/* FIXME: XP seems to use grayed checkboxes to reflect differences between menu and
tooltips settings
* Just keep them in sync for now:
*/
- scheme->Effects.bTooltipAnimation = scheme->Effects.bMenuAnimation;
- scheme->Effects.bTooltipFade = scheme->Effects.bMenuFade;
+ scheme->Effects.bTooltipAnimation = scheme->Effects.bMenuAnimation;
+ scheme->Effects.bTooltipFade = scheme->Effects.bMenuFade;
/* show content of windows during dragging */
SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0,
&scheme->Effects.bDragFullWindows, 0);
@@ -200,7 +200,7 @@
else
scheme->Size[i] = (INT)iSize;
}
- RegCloseKey(hkScheme);
+ RegCloseKey(hkSize);
}
RegCloseKey(hkScheme);
}
@@ -379,3 +379,160 @@
}
return iTemplateIndex;
}
+
+typedef HRESULT (WINAPI * ENUMTHEMESTYLE) (LPCWSTR, LPWSTR, DWORD, PTHEMENAMES);
+
+BOOL AddThemeStyles(LPCWSTR pszThemeFileName, HDSA* Styles, int* count, ENUMTHEMESTYLE
enumTheme)
+{
+ DWORD index = 0;
+ THEMENAMES names;
+ THEME_STYLE StyleName;
+
+ *Styles = DSA_Create(sizeof(THEMENAMES),1);
+ *count = 0;
+
+ while (SUCCEEDED (enumTheme (pszThemeFileName, NULL, index++, &names)))
+ {
+ StyleName.StlyeName = _wcsdup(names.szName);
+ StyleName.DisplayName = _wcsdup(names.szDisplayName);
+ (*count)++;
+ DSA_InsertItem(*Styles, *count, &StyleName);
+ }
+
+ return TRUE;
+}
+
+BOOL CALLBACK EnumThemeProc(LPVOID lpReserved,
+ LPCWSTR pszThemeFileName,
+ LPCWSTR pszThemeName,
+ LPCWSTR pszToolTip, LPVOID lpReserved2,
+ LPVOID lpData)
+{
+ THEME theme;
+ GLOBALS *g = (GLOBALS *) lpData;
+
+ theme.themeFileName = _wcsdup(pszThemeFileName);
+ theme.displayName = _wcsdup(pszThemeName);
+ AddThemeStyles( pszThemeFileName, &theme.Sizes, &theme.SizesCount,
(ENUMTHEMESTYLE)EnumThemeSizes);
+ AddThemeStyles( pszThemeFileName, &theme.Colors, &theme.ColorsCount,
(ENUMTHEMESTYLE)EnumThemeColors);
+
+ DSA_InsertItem(g->Themes, DSA_APPEND , &theme);
+ g->ThemesCount++;
+
+ return TRUE;
+}
+
+void LoadThemes(GLOBALS *g)
+{
+ WCHAR themesPath[MAX_PATH];
+ HRESULT hret;
+ THEME ClassicTheme;
+ WCHAR szThemeFileName[MAX_PATH];
+ WCHAR szColorBuff[MAX_PATH];
+ WCHAR szSizeBuff[MAX_PATH];
+
+ /* Initialize themes dsa */
+ g->Themes = DSA_Create(sizeof(THEME),5);
+
+ /* Insert the classic theme */
+ memset(&ClassicTheme, 0, sizeof(THEME));
+ ClassicTheme.displayName = _wcsdup(L"Classic Theme");
+ DSA_InsertItem(g->Themes, 0, &ClassicTheme);
+ g->ThemesCount = 1;
+
+ /* Retrieve the name of the current theme */
+ hret = GetCurrentThemeName(szThemeFileName,
+ MAX_PATH,
+ szColorBuff,
+ MAX_PATH,
+ szSizeBuff,
+ MAX_PATH);
+
+ if (FAILED (hret))
+ {
+ g->pszThemeFileName = NULL;
+ g->pszColorName = NULL;
+ g->pszSizeName = NULL;
+ }
+ else
+ {
+ /* Cache the name of the active theme */
+ g->pszThemeFileName = _wcsdup(szThemeFileName);
+ g->pszColorName = _wcsdup(szColorBuff);
+ g->pszSizeName = _wcsdup(szSizeBuff);
+ }
+ /* Get path to themes folder */
+ hret = SHGetFolderPathW (NULL, CSIDL_RESOURCES, NULL, SHGFP_TYPE_CURRENT,
themesPath);
+ if (FAILED (hret))
+ return;
+ lstrcatW (themesPath, L"\\Themes");
+
+ /* Enumerate themes */
+ hret = EnumThemes(themesPath, EnumThemeProc, g);
+}
+
+HRESULT ActivateTheme(PTHEME pTheme, int iColor, int iSize)
+{
+ PTHEME_STYLE pThemeColor;
+ PTHEME_STYLE pThemeSize;
+ HTHEMEFILE hThemeFile = 0;
+ HRESULT hret;
+
+ if(pTheme->themeFileName)
+ {
+ pThemeColor = (PTHEME_STYLE)DSA_GetItemPtr(pTheme->Colors, iColor);
+ pThemeSize = (PTHEME_STYLE)DSA_GetItemPtr(pTheme->Sizes, iSize);
+
+ hret = OpenThemeFile(pTheme->themeFileName,
+ pThemeColor->StlyeName,
+ pThemeSize->StlyeName,
+ &hThemeFile,
+ 0);
+
+ if(!SUCCEEDED(hret))
+ {
+ return hret;
+ }
+
+ }
+
+ hret = ApplyTheme(hThemeFile, "", 0);
+
+ if(pTheme->themeFileName)
+ {
+ hret = CloseThemeFile(hThemeFile);
+ }
+
+ return hret;
+}
+
+int CALLBACK CleanUpThemeStlyeCallback(void *p, void *pData)
+{
+ PTHEME_STYLE pStyle = (PTHEME_STYLE)p;
+
+ free(pStyle->DisplayName);
+ free(pStyle->StlyeName);
+
+ return TRUE;
+}
+
+int CALLBACK CleanUpThemeCallback(void *p, void *pData)
+{
+ PTHEME pTheme = (PTHEME)p;
+
+ free(pTheme->displayName);
+ free(pTheme->themeFileName);
+ DSA_DestroyCallback(pTheme->Colors, CleanUpThemeStlyeCallback, NULL);
+ DSA_DestroyCallback(pTheme->Sizes, CleanUpThemeStlyeCallback, NULL);
+
+ return TRUE;
+}
+
+void CleanupThemes(GLOBALS *g)
+{
+ free(g->pszThemeFileName);
+ free(g->pszColorName);
+ free(g->pszSizeName);
+
+ DSA_DestroyCallback(g->Themes, CleanUpThemeCallback, NULL);
+}