Katayama Hirofumi MZ <katayama DOT hirofumi DOT mz AT gmail DOT com>
authorMatthias Kupfer <mkupfer@reactos.org>
Sun, 4 Jul 2010 16:40:03 +0000 (16:40 +0000)
committerMatthias Kupfer <mkupfer@reactos.org>
Sun, 4 Jul 2010 16:40:03 +0000 (16:40 +0000)
- Preperation of quick preview für themes.
- See issue #5487 for details.

svn path=/trunk/; revision=47937

reactos/dll/cpl/desk/advappdlg.c
reactos/dll/cpl/desk/appearance.c
reactos/dll/cpl/desk/appearance.h
reactos/dll/cpl/desk/desk.rbuild
reactos/dll/cpl/desk/draw.c [new file with mode: 0644]
reactos/dll/cpl/desk/draw.h [new file with mode: 0644]
reactos/dll/cpl/desk/effappdlg.c
reactos/dll/cpl/desk/preview.c
reactos/dll/cpl/desk/preview.h
reactos/dll/cpl/desk/theme.c [new file with mode: 0644]
reactos/dll/cpl/desk/theme.h [new file with mode: 0644]

index f262c49..725fe82 100644 (file)
@@ -5,15 +5,55 @@
  * FILE:            dll/cpl/desk/advappdlg.c
  * PURPOSE:         Advanced appearance dialog
  *
  * FILE:            dll/cpl/desk/advappdlg.c
  * PURPOSE:         Advanced appearance dialog
  *
- * PROGRAMMER:     Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de)
+ * PROGRAMMER:      Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de)
  *
  */
 
 #include "desk.h"
  *
  */
 
 #include "desk.h"
+#include "theme.h"
 #include "appearance.h"
 #include "preview.h"
 
 #include "appearance.h"
 #include "preview.h"
 
+/******************************************************************************/
 
 
+typedef struct
+{
+       int Size;
+       int Size2;
+       int Color1;
+       int Color2;
+       int Font;
+       int FontColor;
+} ASSIGNMENT;
+
+/* This const assigns the color and metric numbers to the elements from the elements list */
+
+/* Size 1 (width)      Size 2 (height) Color 1                                 Color 2                                                 Font                    Fontcolor */
+const ASSIGNMENT g_Assignment[NUM_ELEMENTS] =
+{ {-1,                         -1,                             COLOR_DESKTOP,                  -1,                                                             -1,                             -1},                            /* -Desktop */
+  {SIZE_CAPTION_Y,     -1,                             COLOR_INACTIVECAPTION,  COLOR_GRADIENTINACTIVECAPTION,  FONT_CAPTION,   -1},                            /* inactive window caption */
+  {SIZE_BORDER_X,      SIZE_BORDER_Y,  COLOR_INACTIVEBORDER,   -1,                                                             -1,                             -1},                            /* inactive window border */
+  {SIZE_CAPTION_Y,     -1,                             COLOR_ACTIVECAPTION,    COLOR_GRADIENTACTIVECAPTION,    FONT_CAPTION,   COLOR_CAPTIONTEXT},     /* -active window caption */
+  {SIZE_BORDER_X,      SIZE_BORDER_Y,  COLOR_ACTIVEBORDER,             -1,                                                             -1,                             -1},                            /* active window border */
+  {SIZE_MENU_SIZE_X,SIZE_MENU_Y,       COLOR_MENU,                             -1,                                                     FONT_MENU,              COLOR_MENUTEXT},        /* menu */
+  {SIZE_MENU_SIZE_X,SIZE_MENU_Y,       COLOR_HIGHLIGHT,                -1,                                                             FONT_HILIGHT,   COLOR_HIGHLIGHTTEXT},/* marked element */
+  {-1,                         -1,                             COLOR_WINDOW,                   -1 /*COLOR_WINDOWFRAME*/,                               -1,                             COLOR_WINDOWTEXT},      /* window */
+  {SIZE_SCROLL_X,      SIZE_SCROLL_Y,  COLOR_SCROLLBAR,                -1,                                                             -1,                             -1},                            /* scroll bar */
+  {-1,                         -1,                             COLOR_3DFACE,                   -1,                                                             -1,                             COLOR_BTNTEXT},         /* 3d objects */
+  {SIZE_SMCAPTION_Y,-1,                                -1,                                             -1,                                                             FONT_SMCAPTION, -1},                            /* palette window caption */
+  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* symbol caption FIXME: Access? */
+  {SIZE_CAPTION_Y,     -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* caption bar */
+  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             COLOR_GRAYTEXT},        /* inactive menu item FIXME: Access? */
+  {-1,                         -1,                             -1,                                             -1,                                                             FONT_DIALOG,    COLOR_WINDOWTEXT},      /* dialog */
+  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* scrollbar controls FIXME: Access? */
+  {-1,                         -1,                             COLOR_APPWORKSPACE,             -1,                                                             -1,                             -1},                            /* application background */
+  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* small caption bar FIXME: Access? */
+  {SIZE_ICON_SPC_X,    -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* symbol distance horiz. */
+  {SIZE_ICON_SPC_Y,    -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* symbol distance vert. */
+  {-1,                         -1,                             COLOR_INFOBK,                   -1,                                                             FONT_INFO,              COLOR_INFOTEXT},        /* quickinfo */
+  {SIZE_ICON_X,                SIZE_ICON_Y,    -1,                                             -1,                                                             FONT_ICON,              -1}};                           /* symbol */
+
+/******************************************************************************/
 
 /* Draw the current color on the color picker buttons */
 static VOID
 
 /* Draw the current color on the color picker buttons */
 static VOID
@@ -71,6 +111,7 @@ InitColorButtons(HWND hwndDlg, GLOBALS* g)
        HPEN hPen;
        HWND hwndColorButton;
        HGDIOBJ hgdiTemp;
        HPEN hPen;
        HWND hwndColorButton;
        HGDIOBJ hgdiTemp;
+    THEME *theme = &g->ThemeAdv;
 
        const POINT Points[3] = {{29,6},{33,6},{31,8}};
 
 
        const POINT Points[3] = {{29,6},{33,6},{31,8}};
 
@@ -92,7 +133,7 @@ InitColorButtons(HWND hwndDlg, GLOBALS* g)
                rect.top = 0;
                rect.right = 36;
                rect.bottom = 15;
                rect.top = 0;
                rect.right = 36;
                rect.bottom = 15;
-               hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
+               hbrush = CreateSolidBrush(theme->crColor[COLOR_BTNFACE]);
                FillRect(hdcCompat, &rect, hbrush);
                DeleteObject(hbrush);
 
                FillRect(hdcCompat, &rect, hbrush);
                DeleteObject(hbrush);
 
@@ -101,12 +142,12 @@ InitColorButtons(HWND hwndDlg, GLOBALS* g)
                rect.top = 1;
                rect.right = 23;
                rect.bottom = 14;
                rect.top = 1;
                rect.right = 23;
                rect.bottom = 14;
-               hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNTEXT));
+               hbrush = CreateSolidBrush(theme->crColor[COLOR_BTNTEXT]);
                FillRect(hdcCompat, &rect, hbrush);
                DeleteObject(hbrush);
 
                /* Draw left side of line */
                FillRect(hdcCompat, &rect, hbrush);
                DeleteObject(hbrush);
 
                /* Draw left side of line */
-               hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
+               hPen = CreatePen(PS_SOLID, 1, theme->crColor[COLOR_BTNSHADOW]);
                SelectObject(hdcCompat, hPen);
                MoveToEx(hdcCompat, 26, 1, NULL);
                LineTo(hdcCompat, 26, 14);
                SelectObject(hdcCompat, hPen);
                MoveToEx(hdcCompat, 26, 1, NULL);
                LineTo(hdcCompat, 26, 14);
@@ -114,7 +155,7 @@ InitColorButtons(HWND hwndDlg, GLOBALS* g)
                DeleteObject(hPen);
 
                /* Draw right side of line */
                DeleteObject(hPen);
 
                /* Draw right side of line */
-               hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
+               hPen = CreatePen(PS_SOLID, 1, theme->crColor[COLOR_BTNHIGHLIGHT]);
                SelectObject(hdcCompat,hPen);
                MoveToEx(hdcCompat, 27, 1, NULL);
                LineTo(hdcCompat, 27, 14);
                SelectObject(hdcCompat,hPen);
                MoveToEx(hdcCompat, 27, 1, NULL);
                LineTo(hdcCompat, 27, 14);
@@ -122,8 +163,8 @@ InitColorButtons(HWND hwndDlg, GLOBALS* g)
                DeleteObject(hPen);
 
                /* Draw triangle */
                DeleteObject(hPen);
 
                /* Draw triangle */
-               hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
-               hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNTEXT));
+               hPen = CreatePen(PS_SOLID, 1, theme->crColor[COLOR_BTNTEXT]);
+               hbrush = CreateSolidBrush(theme->crColor[COLOR_BTNTEXT]);
                SelectObject(hdcCompat, hPen);
                SelectObject(hdcCompat, hbrush);
                SetPolyFillMode(hdcCompat, WINDING);
                SelectObject(hdcCompat, hPen);
                SelectObject(hdcCompat, hbrush);
                SetPolyFillMode(hdcCompat, WINDING);
@@ -293,7 +334,7 @@ GetColor(HWND hwndDlg, GLOBALS* g, INT nButton)
                if (crColor != cc.rgbResult)
                {
                        UpdateButtonColor(hwndDlg, g, ID, nButton, ColorIndex);
                if (crColor != cc.rgbResult)
                {
                        UpdateButtonColor(hwndDlg, g, ID, nButton, ColorIndex);
-                       SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCOLOR, ColorIndex, cc.rgbResult);
+                       SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                        return TRUE;
                }
        }
                        return TRUE;
                }
        }
@@ -317,6 +358,9 @@ AdvAppearanceDlg_Init(HWND hwndDlg, GLOBALS *g)
        /* Copy the current theme values */
        g->ThemeAdv = g->Theme;
 
        /* Copy the current theme values */
        g->ThemeAdv = g->Theme;
 
+       SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
+       
+
        /* Add the elements to the combo */
        for (iElement = 0; iElement < NUM_ELEMENTS; iElement++)
        {
        /* Add the elements to the combo */
        for (iElement = 0; iElement < NUM_ELEMENTS; iElement++)
        {
@@ -338,12 +382,6 @@ AdvAppearanceDlg_Init(HWND hwndDlg, GLOBALS *g)
 
        SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETCURSEL, iDeskIndex, 0);
 
 
        SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETCURSEL, iDeskIndex, 0);
 
-       /* Set colors for the color buttons */
-       g->crCOLOR_BTNFACE = g->Theme.crColor[COLOR_BTNFACE];
-       g->crCOLOR_BTNTEXT = g->Theme.crColor[COLOR_BTNTEXT];
-       g->crCOLOR_BTNSHADOW = g->Theme.crColor[COLOR_BTNSHADOW];
-       g->crCOLOR_BTNHIGHLIGHT = g->Theme.crColor[COLOR_BTNHIGHLIGHT];
-
        /* Create font for bold button */
        lfButtonFont = g->Theme.lfFont[FONT_DIALOG];
        lfButtonFont.lfWeight = FW_BOLD;
        /* Create font for bold button */
        lfButtonFont = g->Theme.lfFont[FONT_DIALOG];
        lfButtonFont.lfWeight = FW_BOLD;
@@ -377,7 +415,7 @@ AdvAppearanceDlg_Init(HWND hwndDlg, GLOBALS *g)
        InitColorButtons(hwndDlg, g);
 
        /* Make the UpDown control count correctly */
        InitColorButtons(hwndDlg, g);
 
        /* Make the UpDown control count correctly */
-       SendMessage (GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), UDM_SETRANGE, 0L, MAKELONG (200, 1));
+       SendMessage(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), UDM_SETRANGE, 0L, MAKELONG (200, 1));
 
        /* Fill font selection combo */
        lfFont.lfCharSet = DEFAULT_CHARSET;
 
        /* Fill font selection combo */
        lfFont.lfCharSet = DEFAULT_CHARSET;
@@ -508,12 +546,12 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                        {
                                case IDOK:
                                        SaveCurrentValues(hwndDlg, g);
                        {
                                case IDOK:
                                        SaveCurrentValues(hwndDlg, g);
-                                       EndDialog(hwndDlg, 0);
+                                       EndDialog(hwndDlg, IDOK);
                                        break;
 
                                case IDCANCEL:
                                        g->ThemeAdv = g->Theme;
                                        break;
 
                                case IDCANCEL:
                                        g->ThemeAdv = g->Theme;
-                                       EndDialog(hwndDlg, 0);
+                                       EndDialog(hwndDlg, IDCANCEL);
                                        break;
 
                                case IDC_APPEARANCE_PREVIEW:
                                        break;
 
                                case IDC_APPEARANCE_PREVIEW:
@@ -571,22 +609,19 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                                                        case IDX_ACTIVE_CAPTION:
                                                                GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C,
                                                                        g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName);
                                                        case IDX_ACTIVE_CAPTION:
                                                                GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C,
                                                                        g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCAPTIONFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_MENU:
                                                                GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C,
                                                                        g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName);
                                                                break;
 
                                                        case IDX_MENU:
                                                                GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C,
                                                                        g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETMENUFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C,
                                                                        g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                GetSelectedComboText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C,
                                                                        g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
                                                }
                                        }
                                                                break;
                                                }
                                        }
@@ -605,24 +640,21 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                                                                i = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
                                                                i = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCAPTIONFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_MENU:
                                                                i = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
                                                                break;
 
                                                        case IDX_MENU:
                                                                i = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETMENUFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = GetSelectedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
                                                }
 
                                                                break;
                                                }
 
@@ -640,24 +672,21 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                                                                i = GetEditedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
                                                                i = GetEditedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCAPTIONFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_MENU:
                                                                i = GetEditedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
                                                                break;
 
                                                        case IDX_MENU:
                                                                i = GetEditedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETMENUFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = GetEditedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = GetEditedComboInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight =
                                                                        -MulDiv(i , GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
                                                }
 
                                                                break;
                                                }
 
@@ -677,9 +706,7 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight =
                                                                        (i == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0);
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight =
                                                                        (i == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
-
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCAPTIONFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_MENU:
                                                                break;
 
                                                        case IDX_MENU:
@@ -687,18 +714,14 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight =
                                                                        (i == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
 
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight =
                                                                        (i == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETMENUFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0);
-
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight =
                                                                        (i == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight =
                                                                        (i == BST_CHECKED) ? FW_BOLD : FW_NORMAL;
-
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
                                                }
                                        }
                                                                break;
                                                }
                                        }
@@ -714,32 +737,23 @@ AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
                                                        case IDX_INACTIVE_CAPTION:
                                                        case IDX_ACTIVE_CAPTION:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
                                                        case IDX_INACTIVE_CAPTION:
                                                        case IDX_ACTIVE_CAPTION:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
-
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic =
                                                                        (i == BST_CHECKED) ? TRUE : FALSE;
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic =
                                                                        (i == BST_CHECKED) ? TRUE : FALSE;
-
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCAPTIONFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_MENU:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
                                                                break;
 
                                                        case IDX_MENU:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
-
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic =
                                                                        (i == BST_CHECKED) ? TRUE : FALSE;
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic =
                                                                        (i == BST_CHECKED) ? TRUE : FALSE;
-
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETMENUFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
                                                                break;
 
                                                        case IDX_DIALOG:
                                                                i = (INT)SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
-
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic =
                                                                        (i == BST_CHECKED) ? TRUE : FALSE;
                                                                g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic =
                                                                        (i == BST_CHECKED) ? TRUE : FALSE;
-
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
-                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->ThemeAdv);
                                                                break;
                                                }
                                        }
                                                                break;
                                                }
                                        }
index c3c21d4..8e31b40 100644 (file)
  */
 
 #include "desk.h"
  */
 
 #include "desk.h"
+#include "theme.h"
+#include "preview.h"
 #include "appearance.h"
 
 /******************************************************************************/
 
 #include "appearance.h"
 
 /******************************************************************************/
 
-/* This const assigns the color and metric numbers to the elements from the elements list */
-
-/* Size 1 (width)      Size 2 (height) Color 1                                 Color 2                                                 Font                    Fontcolor */
-const ASSIGNMENT g_Assignment[NUM_ELEMENTS] =
-{ {-1,                         -1,                             COLOR_DESKTOP,                  -1,                                                             -1,                             -1},                            /* -Desktop */
-  {SIZE_CAPTION_Y,     -1,                             COLOR_INACTIVECAPTION,  COLOR_GRADIENTINACTIVECAPTION,  FONT_CAPTION,   -1},                            /* inactive window caption */
-  {SIZE_BORDER_X,      SIZE_BORDER_Y,  COLOR_INACTIVEBORDER,   -1,                                                             -1,                             -1},                            /* inactive window border */
-  {SIZE_CAPTION_Y,     -1,                             COLOR_ACTIVECAPTION,    COLOR_GRADIENTACTIVECAPTION,    FONT_CAPTION,   COLOR_CAPTIONTEXT},     /* -active window caption */
-  {SIZE_BORDER_X,      SIZE_BORDER_Y,  COLOR_ACTIVEBORDER,             -1,                                                             -1,                             -1},                            /* active window border */
-  {SIZE_MENU_X,                SIZE_MENU_Y,    COLOR_MENU,                             -1,                                                     FONT_MENU,              COLOR_MENUTEXT},        /* menu */
-  {SIZE_MENU_X,                SIZE_MENU_Y,    COLOR_HIGHLIGHT,                -1,                                                             FONT_HILIGHT,   COLOR_HIGHLIGHTTEXT},/* marked element */
-  {-1,                         -1,                             COLOR_WINDOW,                   -1 /*COLOR_WINDOWFRAME*/,                               -1,                             COLOR_WINDOWTEXT},      /* window */
-  {SIZE_SCROLL_X,      SIZE_SCROLL_Y,  COLOR_SCROLLBAR,                -1,                                                             -1,                             -1},                            /* scroll bar */
-  {-1,                         -1,                             COLOR_3DFACE,                   -1,                                                             -1,                             COLOR_BTNTEXT},         /* 3d objects */
-  {SIZE_SMCAPTION_Y,-1,                                -1,                                             -1,                                                             FONT_SMCAPTION, -1},                            /* palette window caption */
-  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* symbol caption FIXME: Access? */
-  {SIZE_CAPTION_Y,     -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* caption bar */
-  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             COLOR_GRAYTEXT},        /* inactive menu item FIXME: Access? */
-  {-1,                         -1,                             -1,                                             -1,                                                             FONT_DIALOG,    COLOR_WINDOWTEXT},      /* dialog */
-  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* scrollbar controls FIXME: Access? */
-  {-1,                         -1,                             COLOR_APPWORKSPACE,             -1,                                                             -1,                             -1},                            /* application background */
-  {-1,                         -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* small caption bar FIXME: Access? */
-  {SIZE_ICON_SPC_X,    -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* symbol distance horiz. */
-  {SIZE_ICON_SPC_Y,    -1,                             -1,                                             -1,                                                             -1,                             -1},                            /* symbol distance vert. */
-  {-1,                         -1,                             COLOR_INFOBK,                   -1,                                                             FONT_INFO,              COLOR_INFOTEXT},        /* quickinfo */
-  {SIZE_ICON_X,                SIZE_ICON_Y,    -1,                                             -1,                                                             FONT_ICON,              -1}};                           /* symbol */
-
-/* This is the list of names for the colors stored in the registry */
-const TCHAR g_RegColorNames[NUM_COLORS][MAX_COLORNAMELENGTH] =
-       {TEXT("Scrollbar"),                             /* 00 = COLOR_SCROLLBAR */
-       TEXT("Background"),                             /* 01 = COLOR_DESKTOP */
-       TEXT("ActiveTitle"),                    /* 02 = COLOR_ACTIVECAPTION  */
-       TEXT("InactiveTitle"),                  /* 03 = COLOR_INACTIVECAPTION */
-       TEXT("Menu"),                                   /* 04 = COLOR_MENU */
-       TEXT("Window"),                                 /* 05 = COLOR_WINDOW */
-       TEXT("WindowFrame"),                    /* 06 = COLOR_WINDOWFRAME */
-       TEXT("MenuText"),                               /* 07 = COLOR_MENUTEXT */
-       TEXT("WindowText"),                     /* 08 = COLOR_WINDOWTEXT */
-       TEXT("TitleText"),                              /* 09 = COLOR_CAPTIONTEXT */
-       TEXT("ActiveBorder"),                   /* 10 = COLOR_ACTIVEBORDER */
-       TEXT("InactiveBorder"),                 /* 11 = COLOR_INACTIVEBORDER */
-       TEXT("AppWorkSpace"),                   /* 12 = COLOR_APPWORKSPACE */
-       TEXT("Hilight"),                                /* 13 = COLOR_HIGHLIGHT */
-       TEXT("HilightText"),                    /* 14 = COLOR_HIGHLIGHTTEXT */
-       TEXT("ButtonFace"),                     /* 15 = COLOR_BTNFACE */
-       TEXT("ButtonShadow"),                   /* 16 = COLOR_BTNSHADOW */
-       TEXT("GrayText"),                               /* 17 = COLOR_GRAYTEXT */
-       TEXT("ButtonText"),                     /* 18 = COLOR_BTNTEXT */
-       TEXT("InactiveTitleText"),              /* 19 = COLOR_INACTIVECAPTIONTEXT */
-       TEXT("ButtonHilight"),                  /* 20 = COLOR_BTNHIGHLIGHT */
-       TEXT("ButtonDkShadow"),                 /* 21 = COLOR_3DDKSHADOW */
-       TEXT("ButtonLight"),                    /* 22 = COLOR_3DLIGHT */
-       TEXT("InfoText"),                               /* 23 = COLOR_INFOTEXT */
-       TEXT("InfoWindow"),                     /* 24 = COLOR_INFOBK */
-       TEXT("ButtonAlternateFace"),    /* 25 = COLOR_ALTERNATEBTNFACE */
-       TEXT("HotTrackingColor"),               /* 26 = COLOR_HOTLIGHT */
-       TEXT("GradientActiveTitle"),    /* 27 = COLOR_GRADIENTACTIVECAPTION */
-       TEXT("GradientInactiveTitle"),  /* 28 = COLOR_GRADIENTINACTIVECAPTION */
-       TEXT("MenuHilight"),                    /* 29 = COLOR_MENUHILIGHT */
-       TEXT("MenuBar"),                                /* 30 = COLOR_MENUBAR */
-};
-
-/* This is the list of used metrics and their numbers */
-const int g_SizeMetric[NUM_SIZES] =
-{
-       SM_CXBORDER,
-       SM_CYBORDER,
-       SM_CYCAPTION,
-       SM_CXICON,
-       SM_CYICON,
-       SM_CXICONSPACING,
-       SM_CYICONSPACING,
-       SM_CXMENUSIZE,
-       SM_CYMENU,
-       SM_CXVSCROLL,
-       SM_CYHSCROLL,
-       SM_CYSMCAPTION
-};
-
-/******************************************************************************/
-
-static VOID
-LoadCurrentTheme(GLOBALS* g)
-{
-       INT i;
-       NONCLIENTMETRICS NonClientMetrics;
-
-       g->Theme.bHasChanged = FALSE;
-       /* FIXME: it may be custom! */
-       g->Theme.bIsCustom = FALSE;
-
-       /* Load colors */
-       for (i = 0; i <= 30; i++)
-       {
-               g->ColorList[i] = i;
-               g->Theme.crColor[i] = (COLORREF)GetSysColor(i);
-       }
-
-       /* Load sizes */
-       for (i = 0; i <= 11; i++)
-       {
-               g->Theme.Size[i] = GetSystemMetrics(g_SizeMetric[i]);
-       }
-
-       /* Load fonts */
-       NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
-       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
-       g->Theme.lfFont[FONT_CAPTION] = NonClientMetrics.lfCaptionFont;
-       g->Theme.lfFont[FONT_SMCAPTION] = NonClientMetrics.lfSmCaptionFont;
-       g->Theme.lfFont[FONT_MENU] = NonClientMetrics.lfMenuFont;
-       g->Theme.lfFont[FONT_INFO] = NonClientMetrics.lfStatusFont;
-       g->Theme.lfFont[FONT_DIALOG] = NonClientMetrics.lfMessageFont;
-       SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &g->Theme.lfFont[FONT_ICON], 0);
-
-    /* Effects */
-   /* "Use the following transition effect for menus and tooltips" */
-    SystemParametersInfo(SPI_GETMENUANIMATION, sizeof(BOOL), &g->Theme.Effects.bMenuAnimation, 0);
-    SystemParametersInfo(SPI_GETMENUFADE, sizeof(BOOL), &g->Theme.Effects.bMenuFade, 0);
-    /* FIXME: XP seems to use grayed checkboxes to reflect differences between menu and tooltips settings
-     * Just keep them in sync for now:
-     */
-    g->Theme.Effects.bTooltipAnimation  = g->Theme.Effects.bMenuAnimation;
-    g->Theme.Effects.bTooltipFade       = g->Theme.Effects.bMenuFade;
-
-    /* show content of windows during dragging */
-    //SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, g->Theme.Effects.bDragFullWindows, NULL, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE);
-    SystemParametersInfoW(SPI_GETDRAGFULLWINDOWS, 0, &g->Theme.Effects.bDragFullWindows, 0);
-
-    /* "Hide underlined letters for keyboard navigation until I press the Alt key" */
-    SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &g->Theme.Effects.bKeyboardCues, 0);
-}
-
-
-static BOOL
-LoadThemeFromReg(GLOBALS* g)
-{
-       INT i;
-       TCHAR strSizeName[20] = {TEXT("Sizes\\0")};
-       TCHAR strValueName[10];
-       HKEY hkNewSchemes, hkScheme, hkSize;
-       DWORD dwType, dwLength;
-       BOOL Ret = FALSE;
-       INT iPreset = g->Theme.Id;
-
-       if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance\\New Schemes"),
-               0, KEY_READ, &hkNewSchemes) == ERROR_SUCCESS)
-       {
-               if(RegOpenKeyEx(hkNewSchemes, g->ThemeTemplates[iPreset].strKeyName, 0, KEY_READ, &hkScheme) == ERROR_SUCCESS)
-               {
-                       lstrcpyn(&strSizeName[6],g->ThemeTemplates[iPreset].strSizeName, 3);
-                       if(RegOpenKeyEx(hkScheme, strSizeName, 0, KEY_READ, &hkSize) == ERROR_SUCCESS)
-                       {
-                               Ret = TRUE;
-
-                               dwLength = sizeof(DWORD);
-                               if (RegQueryValueEx(hkSize, TEXT("FlatMenus"), NULL, &dwType, (LPBYTE)&g->Theme.bFlatMenus, &dwLength) != ERROR_SUCCESS ||
-                                   dwType != REG_DWORD || dwLength != sizeof(DWORD))
-                               {
-                                       /* Failed to read registry value */
-                                       g->Theme.bFlatMenus = FALSE;
-                                       Ret = FALSE;
-                               }
-
-                               for (i = 0; i <= 30; i++)
-                               {
-                                       wsprintf(strValueName, TEXT("Color #%d"), i);
-                                       dwLength = sizeof(COLORREF);
-                                       if (RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&g->Theme.crColor[i], &dwLength) != ERROR_SUCCESS ||
-                                           dwType != REG_DWORD || dwLength != sizeof(COLORREF))
-                                       {
-                                               /* Failed to read registry value, initialize with current setting for now */
-                                               g->Theme.crColor[i] = GetSysColor(i);
-                                               Ret = FALSE;
-                                       }
-                               }
-                               for (i = 0; i <= 5; i++)
-                               {
-                                       wsprintf(strValueName, TEXT("Font #%d"), i);
-                                       dwLength = sizeof(LOGFONT);
-                                       g->Theme.lfFont[i].lfFaceName[0] = 'x';
-                                       if (RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&g->Theme.lfFont[i], &dwLength) != ERROR_SUCCESS ||
-                                           dwType != REG_BINARY || dwLength != sizeof(LOGFONT))
-                                       {
-                                               /* Failed to read registry value */
-                                               Ret = FALSE;
-                                       }
-                               }
-                               for (i = 0; i <= 8; i++)
-                               {
-                                       wsprintf(strValueName, TEXT("Size #%d"), i);
-                                       dwLength = sizeof(UINT64);
-                                       if (RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&g->Theme.Size[i], &dwLength) != ERROR_SUCCESS ||
-                                           dwType != REG_QWORD || dwLength != sizeof(UINT64))
-                                       {
-                                               /* Failed to read registry value, initialize with current setting for now */
-                                               g->Theme.Size[i] = GetSystemMetrics(g_SizeMetric[i]);
-                                               Ret = FALSE;
-                                       }
-                               }
-                               RegCloseKey(hkScheme);
-                       }
-                       RegCloseKey(hkScheme);
-               }
-               RegCloseKey(hkNewSchemes);
-       }
-
-       return Ret;
-}
-
-static VOID
-_UpdateUserPref(UINT SpiGet,UINT SpiSet,BOOL *pbFlag)
-{
-    SystemParametersInfo(SpiSet, 0, (PVOID)pbFlag, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
-}
-#define UPDATE_USERPREF(NAME,pbFlag) _UpdateUserPref(SPI_GET ## NAME, SPI_SET ## NAME, pbFlag)
-
-static VOID
-ApplyTheme(GLOBALS* g)
-{
-       INT i, Result;
-       HKEY hKey;
-       DWORD dwDisposition = 0;
-       TCHAR clText[16] = {0};
-       NONCLIENTMETRICS NonClientMetrics;
-       HFONT hMyFont;
-       LOGFONT lfButtonFont;
-
-       if (!g->Theme.bHasChanged)
-               return;
-
-       /* Update some globals */
-       g->crCOLOR_BTNFACE = g->Theme.crColor[COLOR_BTNFACE];
-       g->crCOLOR_BTNTEXT = g->Theme.crColor[COLOR_BTNTEXT];
-       g->crCOLOR_BTNSHADOW = g->Theme.crColor[COLOR_BTNSHADOW];
-       g->crCOLOR_BTNHIGHLIGHT = g->Theme.crColor[COLOR_BTNHIGHLIGHT];
-       lfButtonFont = g->Theme.lfFont[FONT_DIALOG];
-
-       /* Create new font for bold button */
-       lfButtonFont.lfWeight = FW_BOLD;
-       lfButtonFont.lfItalic = FALSE;
-       hMyFont = CreateFontIndirect(&lfButtonFont);
-       if (hMyFont)
-       {
-               if (g->hBoldFont)
-                       DeleteObject(g->hBoldFont);
-               g->hBoldFont = hMyFont;
-       }
-
-       /* Create new font for italic button */
-       lfButtonFont.lfWeight = FW_REGULAR;
-       lfButtonFont.lfItalic = TRUE;
-       hMyFont = CreateFontIndirect(&lfButtonFont);
-       if (hMyFont)
-       {
-               if (g->hItalicFont)
-                       DeleteObject(g->hItalicFont);
-               g->hItalicFont = hMyFont;
-       }
-
-       /* Apply Colors from global variable */
-       SetSysColors(30, &g->ColorList[0], &g->Theme.crColor[0]);
-
-       /* Save colors to registry */
-       Result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 0, KEY_ALL_ACCESS, &hKey);
-       if (Result != ERROR_SUCCESS)
-       {
-               /* Could not open the key, try to create it */
-               Result = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Colors"), 0, NULL, 0, KEY_ALL_ACCESS, NULL,&hKey, &dwDisposition);
-       }
-
-       if (Result == ERROR_SUCCESS)
-       {
-               for (i = 0; i <= 30; i++)
-               {
-                       DWORD red   = GetRValue(g->Theme.crColor[i]);
-                       DWORD green = GetGValue(g->Theme.crColor[i]);
-                       DWORD blue  = GetBValue(g->Theme.crColor[i]);
-                       wsprintf(clText, TEXT("%d %d %d"), red, green, blue);
-                       RegSetValueEx(hKey, g_RegColorNames[i], 0, REG_SZ, (BYTE *)clText, lstrlen( clText )*sizeof(TCHAR) + sizeof(TCHAR));
-               }
-
-               RegCloseKey(hKey);
-       }
-
-       /* Apply the fonts */
-       NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
-       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
-       NonClientMetrics.lfCaptionFont = g->Theme.lfFont[FONT_CAPTION];
-       NonClientMetrics.lfSmCaptionFont = g->Theme.lfFont[FONT_SMCAPTION];
-       NonClientMetrics.lfMenuFont = g->Theme.lfFont[FONT_MENU];
-       NonClientMetrics.lfStatusFont = g->Theme.lfFont[FONT_INFO];
-       NonClientMetrics.lfMessageFont = g->Theme.lfFont[FONT_DIALOG];
-       SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
-       SystemParametersInfo(SPI_SETICONTITLELOGFONT, sizeof(LOGFONT), &g->Theme.lfFont[FONT_ICON], 0);
-
-       /* FIXME: Apply size metrics */
-
-       /* Save fonts and size metrics to registry */
-       Result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop\\WindowMetrics"), 0, KEY_ALL_ACCESS, &hKey);
-       if (Result != ERROR_SUCCESS)
-       {
-               /* Could not open the key, try to create it */
-               Result = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop\\WindowMetrics"), 0, NULL, 0, KEY_ALL_ACCESS, NULL,&hKey, &dwDisposition);
-       }
-
-       if (Result == ERROR_SUCCESS)
-       {
-               RegSetValueEx(hKey, TEXT("CaptionFont"), 0, REG_BINARY, (BYTE *)&g->Theme.lfFont[FONT_CAPTION], sizeof(LOGFONT));
-               RegSetValueEx(hKey, TEXT("SmCaptionFont"), 0, REG_BINARY, (BYTE *)&g->Theme.lfFont[FONT_SMCAPTION], sizeof(LOGFONT));
-               RegSetValueEx(hKey, TEXT("IconFont"), 0, REG_BINARY, (BYTE *)&g->Theme.lfFont[FONT_ICON], sizeof(LOGFONT));
-               RegSetValueEx(hKey, TEXT("MenuFont"), 0, REG_BINARY, (BYTE *)&g->Theme.lfFont[FONT_MENU], sizeof(LOGFONT));
-               RegSetValueEx(hKey, TEXT("StatusFont"), 0, REG_BINARY, (BYTE *)&g->Theme.lfFont[FONT_INFO], sizeof(LOGFONT));
-               RegSetValueEx(hKey, TEXT("MessageFont"), 0, REG_BINARY, (BYTE *)&g->Theme.lfFont[FONT_DIALOG], sizeof(LOGFONT));
-
-               /* Save size metrics to registry */
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_BORDER_X]);
-               RegSetValueEx(hKey, TEXT("BorderWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_CAPTION_Y]);
-               RegSetValueEx(hKey, TEXT("CaptionWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_CAPTION_Y]);
-               RegSetValueEx(hKey, TEXT("CaptionHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_SMCAPTION_Y]);
-               RegSetValueEx(hKey, TEXT("SmCaptionWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_SMCAPTION_Y]);
-               RegSetValueEx(hKey, TEXT("SmCaptionHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_ICON_SPC_X]);
-               RegSetValueEx(hKey, TEXT("IconSpacing"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_ICON_SPC_Y]);
-               RegSetValueEx(hKey, TEXT("IconVerticalSpacing"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_MENU_X]);
-               RegSetValueEx(hKey, TEXT("MenuWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_MENU_Y]);
-               RegSetValueEx(hKey, TEXT("MenuHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_SCROLL_X]);
-               RegSetValueEx(hKey, TEXT("ScrollWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), -15 * g->Theme.Size[SIZE_SCROLL_Y]);
-               RegSetValueEx(hKey, TEXT("ScrollHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-               wsprintf(clText, TEXT("%d"), g->Theme.Size[SIZE_ICON_X]);
-               RegSetValueEx(hKey, TEXT("Shell Icon Sizet"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
-
-               RegCloseKey(hKey);
-       }
-
-    /* Effects, save only when needed: */
-    /* FIXME: XP seems to use grayed checkboxes to reflect differences between menu and tooltips settings
-     * Just keep them in sync for now.
-     */
-    g->Theme.Effects.bTooltipAnimation  = g->Theme.Effects.bMenuAnimation;
-    g->Theme.Effects.bTooltipFade       = g->Theme.Effects.bMenuFade;
-    SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, g->Theme.Effects.bDragFullWindows, NULL, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
-    //UPDATE_USERPREF(KEYBOARDCUES, &g->Theme.Effects.bKeyboardCues);
-    //UPDATE_USERPREF(ACTIVEWINDOWTRACKING, &g->Theme.Effects.bActiveWindowTracking);
-    //UPDATE_USERPREF(MENUANIMATION, &g->Theme.Effects.bMenuAnimation);
-    //UPDATE_USERPREF(COMBOBOXANIMATION, &g->Theme.Effects.bComboBoxAnimation);
-    //UPDATE_USERPREF(LISTBOXSMOOTHSCROLLING, &g->Theme.Effects.bListBoxSmoothScrolling);
-    //UPDATE_USERPREF(GRADIENTCAPTIONS, &g->Theme.Effects.bGradientCaptions);
-    //UPDATE_USERPREF(ACTIVEWNDTRKZORDER, &g->Theme.Effects.bActiveWndTrkZorder);
-    //UPDATE_USERPREF(HOTTRACKING, &g->Theme.Effects.bHotTracking);
-    UPDATE_USERPREF(MENUFADE, &g->Theme.Effects.bMenuFade);
-    //UPDATE_USERPREF(SELECTIONFADE, &g->Theme.Effects.bSelectionFade);
-    UPDATE_USERPREF(TOOLTIPANIMATION, &g->Theme.Effects.bTooltipAnimation);
-    UPDATE_USERPREF(TOOLTIPFADE, &g->Theme.Effects.bTooltipFade);
-    //UPDATE_USERPREF(CURSORSHADOW, &g->Theme.Effects.bCursorShadow);
-    //UPDATE_USERPREF(UIEFFECTS, &g->Theme.Effects.bUiEffects);
-       /* Save ThemeId */
-       Result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance\\New Schemes"), 0, KEY_ALL_ACCESS, &hKey);
-       if (Result == ERROR_SUCCESS)
-       {
-               lstrcpy(clText, g->ThemeTemplates[g->Theme.Id].strKeyName);
-               RegSetValueEx(hKey, TEXT("SelectedStyle"), 0, REG_SZ, (BYTE *)clText, (lstrlen(clText)+1) * sizeof (TCHAR));
-               RegCloseKey(hKey);
-       }
-}
-
-
 static INT_PTR
 static INT_PTR
-AppearancePage_OnInit(HWND hwndDlg, GLOBALS *g)
+AppearancePage_OnInit(HWND hwndDlg)
 {
 {
-       HKEY hkNewSchemes, hkScheme, hkSizes, hkSize;
-       FILETIME ftLastWriteTime;
        TCHAR strSelectedStyle[4];
        TCHAR strSelectedStyle[4];
-       DWORD dwLength, dwType;
-       DWORD dwDisposition = 0;
-       INT iStyle, iSize, iTemplateIndex, iListIndex = 0;
-       INT Result;
+       INT i, TemplateCount, iListIndex;
+       HWND hwndCombo;
+       GLOBALS *g;
 
 
-       g = (GLOBALS*)malloc(sizeof(GLOBALS));
+       g = (GLOBALS*)LocalAlloc(LPTR, sizeof(GLOBALS));
        if (g == NULL)
        if (g == NULL)
-       {
                return FALSE;
                return FALSE;
-       }
 
        SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
 
 
        SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
 
-       LoadCurrentTheme(g);
+       LoadCurrentTheme(&g->Theme);
+       g->ThemeAdv = g->Theme;
+       g->bHasChanged = FALSE;
+       g->hBoldFont = g->hItalicFont = NULL;
+       g->hbmpColor[0] = g->hbmpColor[1] = g->hbmpColor[2] = NULL;
+       g->bInitializing = FALSE;
 
 
-       /* Fill color schemes combo */
-       Result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance\\New Schemes"),
-               0, KEY_READ, &hkNewSchemes);
-       if (Result != ERROR_SUCCESS)
-       {
-               /* Could not open the key, try to create it */
-               Result = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance\\New Schemes"), 0, NULL, 0, KEY_ALL_ACCESS, NULL,&hkNewSchemes, &dwDisposition);
-               if (Result == ERROR_SUCCESS)
-               {
-                       /* FIXME: We have created it new, so let's put somethig there */
-               }
-       }
-       if (Result == ERROR_SUCCESS)
+       TemplateCount = LoadThemeTemplates(strSelectedStyle);
+
+       hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+       g->ThemeId = -1;
+       g->bInitializing = TRUE;
+       for(i = 0; i < TemplateCount; i++)
        {
        {
-               /* First find out the currently selected template */
-               dwLength = 8;
-               RegQueryValueEx(hkNewSchemes, TEXT("SelectedStyle"), NULL, &dwType, (LPBYTE)&strSelectedStyle, &dwLength);
-               iTemplateIndex = 0;
-               iStyle = 0;
-               dwLength = MAX_TEMPLATENAMELENTGH;
-               while((RegEnumKeyEx(hkNewSchemes, iStyle, g->ThemeTemplates[iTemplateIndex].strKeyName, &dwLength,
-                       NULL, NULL, NULL, &ftLastWriteTime) == ERROR_SUCCESS) && (iTemplateIndex < MAX_TEMPLATES))
+               iListIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)g_ThemeTemplates[i].strLegacyName);
+               SendMessage(hwndCombo, CB_SETITEMDATA, iListIndex, i);
+               if (lstrcmp(g_ThemeTemplates[i].strKeyName, strSelectedStyle) == 0)
                {
                {
-                       /* is it really a template or one of the other entries */
-                       if (dwLength < 5)
-                       {
-                               if (RegOpenKeyEx(hkNewSchemes, g->ThemeTemplates[iTemplateIndex].strKeyName, 0, KEY_READ, &hkScheme) == ERROR_SUCCESS)
-                               {
-                                       if(RegOpenKeyEx(hkScheme, TEXT("Sizes"), 0, KEY_READ, &hkSizes) == ERROR_SUCCESS)
-                                       {
-                                               iSize = 0;
-                                               dwLength = 3;
-                                               while((RegEnumKeyEx(hkSizes, iSize, g->ThemeTemplates[iTemplateIndex].strSizeName, &dwLength,
-                                                       NULL, NULL, NULL, &ftLastWriteTime) == ERROR_SUCCESS) && (iSize <= 4))
-                                               {
-                                                       if(RegOpenKeyEx(hkSizes, g->ThemeTemplates[iTemplateIndex].strSizeName, 0, KEY_READ, &hkSize) == ERROR_SUCCESS)
-                                                       {
-                                                               dwLength = MAX_TEMPLATENAMELENTGH;
-                                                               RegQueryValueEx(hkSize, TEXT("DisplayName"), NULL, &dwType, (LPBYTE)&g->ThemeTemplates[iTemplateIndex].strDisplayName, &dwLength);
-                                                               dwLength = MAX_TEMPLATENAMELENTGH;
-                                                               RegQueryValueEx(hkSize, TEXT("LegacyName"), NULL, &dwType, (LPBYTE)&g->ThemeTemplates[iTemplateIndex].strLegacyName, &dwLength);
-                                                               RegCloseKey(hkSize);
-                                                       }
-                                                       iListIndex = SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_ADDSTRING, 0, (LPARAM)g->ThemeTemplates[iTemplateIndex].strLegacyName);
-                                                       SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETITEMDATA, iListIndex, iTemplateIndex);
-                                                       if (lstrcmp(g->ThemeTemplates[iTemplateIndex].strKeyName, strSelectedStyle) == 0)
-                                                       {
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)iListIndex, 0);
-                                                       }
-                                                       iSize++;
-                                                       iTemplateIndex++;
-                                                       dwLength = 3;
-                                               }
-                                               RegCloseKey(hkSizes);
-                                       }
-                                       RegCloseKey(hkScheme);
-                               }
-                       }
-                       iStyle++;
-                       dwLength = MAX_TEMPLATENAMELENTGH;
+                       g->ThemeId = i;
+                       SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)iListIndex, 0);
                }
                }
-               RegCloseKey(hkNewSchemes);
        }
        }
-       SendMessage(GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME), LB_SETCURSEL, 0, 0);
+       g->bInitializing = FALSE;
 
        return FALSE;
 }
 
 
        return FALSE;
 }
 
-
-static INT_PTR
+static VOID
 AppearancePage_OnDestroy(HWND hwndDlg, GLOBALS *g)
 {
 AppearancePage_OnDestroy(HWND hwndDlg, GLOBALS *g)
 {
-       free(g);
-       return TRUE;
+       LocalFree(g);
 }
 
 }
 
-static void
-UpdateSelectedThemeId(HWND hwndDlg, GLOBALS *g)
+static INT
+GetSelectedThemeId(HWND hwndDlg)
 {
 {
-       int sel;
-       sel = SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_GETCURSEL, 0, 0);
-       g->Theme.Id = SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_GETITEMDATA, (WPARAM)sel, 0);
+       HWND hwndCombo;
+       INT sel;
+
+       hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
+       sel = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
+       if (sel == CB_ERR)
+               return -1;
+       return (INT)SendMessage(hwndCombo, CB_GETITEMDATA, (WPARAM)sel, 0);
 }
 
 INT_PTR CALLBACK
 }
 
 INT_PTR CALLBACK
@@ -504,76 +86,83 @@ AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
        switch (uMsg)
        {
                case WM_INITDIALOG:
        switch (uMsg)
        {
                case WM_INITDIALOG:
-                       return AppearancePage_OnInit(hwndDlg, g);
+                       return AppearancePage_OnInit(hwndDlg);
 
                case WM_DESTROY:
 
                case WM_DESTROY:
-                       return AppearancePage_OnDestroy(hwndDlg, g);
+                       AppearancePage_OnDestroy(hwndDlg, g);
+                       break;
 
                case WM_COMMAND:
                        switch (LOWORD(wParam))
                        {
                                case IDC_APPEARANCE_EFFECTS:
 
                case WM_COMMAND:
                        switch (LOWORD(wParam))
                        {
                                case IDC_APPEARANCE_EFFECTS:
-                                       DialogBoxParam(hApplet, (LPCTSTR)IDD_EFFAPPEARANCE,
-                                               hwndDlg, EffAppearanceDlgProc, (LPARAM)g);
-
-                                       /* Was anything changed in the effects appearance dialog? */
-                                       if (memcmp(&g->Theme, &g->ThemeAdv, sizeof(THEME)) != 0)
+                                       if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_EFFAPPEARANCE),
+                                                                          hwndDlg, EffAppearanceDlgProc, (LPARAM)g) == IDOK)
                                        {
                                                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                                                g->Theme = g->ThemeAdv;
                                        {
                                                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                                                g->Theme = g->ThemeAdv;
-                                               g->Theme.bHasChanged = TRUE;
+                                               g->bHasChanged = TRUE;
+                                               g->ThemeId = -1;        /* Customized */
+                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
+                                               SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
+                                               /* SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme); */
                                        }
                                        break;
 
                                case IDC_APPEARANCE_ADVANCED:
                                        }
                                        break;
 
                                case IDC_APPEARANCE_ADVANCED:
-                                       DialogBoxParam(hApplet, (LPCTSTR)IDD_ADVAPPEARANCE,
-                                               hwndDlg, AdvAppearanceDlgProc, (LPARAM)g);
-
-                                       /* Was anything changed in the advanced appearance dialog? */
-                                       if (memcmp(&g->Theme, &g->ThemeAdv, sizeof(THEME)) != 0)
+                                       if (DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_ADVAPPEARANCE),
+                                                                          hwndDlg, AdvAppearanceDlgProc, (LPARAM)g) == IDOK)
                                        {
                                                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                                                g->Theme = g->ThemeAdv;
                                        {
                                                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                                                g->Theme = g->ThemeAdv;
-                                               g->Theme.bHasChanged = TRUE;
+                                               g->bHasChanged = TRUE;
+                                               g->ThemeId = -1;        /* Customized */
+                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_COLORSCHEME, CB_SETCURSEL, (WPARAM)-1, 0);
+                                               SetDlgItemText(hwndDlg, IDC_APPEARANCE_COLORSCHEME, TEXT(""));
+                                               /* SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme); */
                                        }
                                        break;
 
                                case IDC_APPEARANCE_COLORSCHEME:
                                        }
                                        break;
 
                                case IDC_APPEARANCE_COLORSCHEME:
-                                       if(HIWORD(wParam) == CBN_SELCHANGE)
+                                       if (HIWORD(wParam) == CBN_SELCHANGE && !g->bInitializing)
                                        {
                                        {
+                                               THEME Theme;
+                                               INT ThemeId = GetSelectedThemeId(hwndDlg);
                                                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
                                                PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
-                                               g->Theme.bHasChanged = TRUE;
-                                               UpdateSelectedThemeId(hwndDlg, g);
-                                               LoadThemeFromReg(g);
-                                               //SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, WM_PAINT, 0, 0);
+                                               g->bHasChanged = TRUE;
+                                               if (ThemeId != -1 && LoadThemeFromReg(&Theme, ThemeId))
+                                               {
+                                                       g->Theme = Theme;
+                                                       g->ThemeId = ThemeId;
+                                                       /* SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Theme); */
+                                               }
                                        }
                                        break;
                                        }
                                        break;
-
-                               default:
-                                       return FALSE;
                        }
                        }
-                       return TRUE;
+                       break;
 
                case WM_NOTIFY:
                        lpnm = (LPNMHDR)lParam;
                        switch (lpnm->code)
                        {
                                case PSN_APPLY:
 
                case WM_NOTIFY:
                        lpnm = (LPNMHDR)lParam;
                        switch (lpnm->code)
                        {
                                case PSN_APPLY:
-                                       if (g->Theme.bHasChanged)
+                                       if (g->bHasChanged)
                                        {
                                        {
-                                               UpdateSelectedThemeId(hwndDlg, g);
-                                               ApplyTheme(g);
+                                               INT ThemeId = GetSelectedThemeId(hwndDlg);
+                                               ApplyTheme(&g->Theme, ThemeId);
+                                               g->ThemeId = ThemeId;
+                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
+                                               g->bHasChanged = FALSE;
                                        }
                                        }
+                                       SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)PSNRET_NOERROR);
                                        return TRUE;
 
                                        return TRUE;
 
-                               default:
-                                       return FALSE;
+                               case PSN_KILLACTIVE:
+                                       SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)FALSE);
+                                       return TRUE;
                        }
                        }
-                       return TRUE;
-
-               default:
-                       return FALSE;
+                       break;
        }
 
        }
 
-       return TRUE;
+       return FALSE;
 }
 }
index 9d50975..60c8ff6 100644 (file)
-
-/* Some definitions for appearance page */
-#define SIZE_BORDER_X 0
-#define SIZE_BORDER_Y 1
-#define SIZE_CAPTION_Y 2
-#define SIZE_ICON_X 3
-#define SIZE_ICON_Y 4
-#define SIZE_ICON_SPC_X 5
-#define SIZE_ICON_SPC_Y 6
-#define SIZE_MENU_X 7
-#define SIZE_MENU_Y 8
-#define SIZE_SCROLL_X 9
-#define SIZE_SCROLL_Y 10
-#define SIZE_SMCAPTION_Y 11
-
-#define FONT_CAPTION 0
-#define FONT_SMCAPTION 1
-#define FONT_HILIGHT 2
-#define FONT_MENU 2
-#define FONT_ICON 3
-#define FONT_INFO 4
-#define FONT_DIALOG 5
-
-#define NUM_ELEMENTS 22
-#define NUM_FONTS 6
-#define NUM_SIZES 13
-#define NUM_COLORS 31
-#define MAX_TEMPLATES 50
-#define MAX_COLORNAMELENGTH 30
-#define MAX_TEMPLATENAMELENTGH 80
-
 /* Some typedefs for appearance */
 
 /* Some typedefs for appearance */
 
-/* Most (but not all) fields below correspond to HKCU\Control Panel\Desktop\UserPreferencesMask */
-typedef struct
-{
-       BOOL bActiveWindowTracking;
-       BOOL bMenuAnimation;
-       BOOL bComboBoxAnimation;
-       BOOL bListBoxSmoothScrolling;
-       BOOL bGradientCaptions;
-       BOOL bKeyboardCues;
-       BOOL bActiveWndTrkZorder;
-       BOOL bHotTracking;
-       BOOL bMenuFade;
-       BOOL bSelectionFade;
-       BOOL bTooltipAnimation;
-       BOOL bTooltipFade;
-       BOOL bCursorShadow;
-       BOOL bUiEffects;
-       BOOL bFontSmoothing;
-       BOOL bDragFullWindows;
-       UINT uiFontSmoothingType;
-} EFFECTS;
-
-typedef struct
-{
-       COLORREF crColor[NUM_COLORS];
-       LOGFONT lfFont[NUM_FONTS];
-       UINT64 Size[NUM_SIZES];
-       INT Id;
-       BOOL bFlatMenus;
-       BOOL bHasChanged;
-       BOOL bIsCustom;
-       EFFECTS Effects;
-} THEME;
-
-typedef struct
-{
-       TCHAR strKeyName[4];
-       TCHAR strSizeName[4];
-       TCHAR strDisplayName[MAX_TEMPLATENAMELENTGH];
-       TCHAR strLegacyName[MAX_TEMPLATENAMELENTGH];
-       INT NumSizes;
-} THEME_PRESET;
-
-typedef struct
-{
-       int Size;
-       int Size2;
-       int Color1;
-       int Color2;
-       int Font;
-       int FontColor;
-} ASSIGNMENT;
-
 /* 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
 {
 /* 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
 {
-       THEME_PRESET ThemeTemplates[MAX_TEMPLATES];
+       INT ThemeId;    /* Theme is customized if ThemeId == -1 */
        THEME Theme;
        THEME ThemeAdv;
        THEME Theme;
        THEME ThemeAdv;
-       INT ColorList[NUM_COLORS];
+       BOOL bHasChanged;
        HBITMAP hbmpColor[3];
        INT CurrentElement;
        HBITMAP hbmpColor[3];
        INT CurrentElement;
-       COLORREF crCOLOR_BTNFACE;
-       COLORREF crCOLOR_BTNSHADOW;
-       COLORREF crCOLOR_BTNTEXT;
-       COLORREF crCOLOR_BTNHIGHLIGHT;
        HFONT hBoldFont;
        HFONT hItalicFont;
        HFONT hBoldFont;
        HFONT hItalicFont;
+    BOOL bInitializing;
 } GLOBALS;
 
 } GLOBALS;
 
-
-extern const ASSIGNMENT g_Assignment[NUM_ELEMENTS];
-extern const TCHAR g_RegColorNames[NUM_COLORS][MAX_COLORNAMELENGTH];
-extern const INT g_SizeMetric[NUM_SIZES];
-
 /* prototypes for appearance.c */
 INT_PTR CALLBACK AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
 /* prototypes for appearance.c */
 INT_PTR CALLBACK AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
index 4fde972..fddd10e 100644 (file)
@@ -31,4 +31,6 @@
        <file>monslctl.c</file>
        <file>general.c</file>
        <file>desk.rc</file>
        <file>monslctl.c</file>
        <file>general.c</file>
        <file>desk.rc</file>
+       <file>draw.c</file>
+       <file>theme.c</file>
 </module>
 </module>
diff --git a/reactos/dll/cpl/desk/draw.c b/reactos/dll/cpl/desk/draw.c
new file mode 100644 (file)
index 0000000..07ff803
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS Display Control Panel
+ * FILE:            lib/cpl/desk/draw.c
+ * PURPOSE:         Providing drawing functions
+ *
+ * PROGRAMMERS:     Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
+ */
+
+/* #define NTOS_MODE_USER */
+/* #define WIN32_NO_STATUS */
+#include "desk.h"
+#include "theme.h"
+#include "draw.h"
+/* #include <ndk/ntndk.h> */
+/* #include <win32k/ntuser.h> */
+
+/******************************************************************************/
+
+static const signed char LTInnerNormal[] = {
+    -1,        -1,                  -1,                 -1,
+    -1,        COLOR_BTNHIGHLIGHT,  COLOR_BTNHIGHLIGHT, -1,
+    -1,        COLOR_3DDKSHADOW,    COLOR_3DDKSHADOW,   -1,
+    -1,        -1,                  -1,                 -1
+};
+
+static const signed char LTOuterNormal[] = {
+    -1,                 COLOR_3DLIGHT,   COLOR_BTNSHADOW, -1,
+    COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT,   COLOR_BTNSHADOW, -1,
+    COLOR_3DDKSHADOW,   COLOR_3DLIGHT,   COLOR_BTNSHADOW, -1,
+    -1,                 COLOR_3DLIGHT,   COLOR_BTNSHADOW, -1
+};
+
+static const signed char RBInnerNormal[] = {
+    -1,        -1,              -1,                 -1,
+    -1,        COLOR_BTNSHADOW, COLOR_BTNSHADOW,    -1,
+    -1,        COLOR_3DLIGHT,   COLOR_3DLIGHT,      -1,
+    -1,        -1,              -1,                 -1
+};
+
+static const signed char RBOuterNormal[] = {
+    -1,                 COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1,
+    COLOR_BTNSHADOW,    COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1,
+    COLOR_3DLIGHT,      COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1,
+    -1,                 COLOR_3DDKSHADOW,  COLOR_BTNHIGHLIGHT, -1
+};
+
+static BOOL
+MyIntDrawRectEdge(HDC hdc, LPRECT rc, UINT uType, UINT uFlags, THEME *theme)
+{
+       signed char LTInnerI, LTOuterI;
+       signed char RBInnerI, RBOuterI;
+       HPEN LTInnerPen, LTOuterPen;
+       HPEN RBInnerPen, RBOuterPen;
+       RECT InnerRect = *rc;
+       POINT SavePoint;
+       HPEN SavePen;
+       int LBpenplus = 0;
+       int LTpenplus = 0;
+       int RTpenplus = 0;
+       int RBpenplus = 0;
+       /* Init some vars */
+       LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
+       SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
+
+       /* Determine the colors of the edges */
+       LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
+       LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
+       RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
+       RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
+
+       if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT)
+               LBpenplus = 1;
+       if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT)
+               RTpenplus = 1;
+       if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT)
+               RBpenplus = 1;
+       if((uFlags & BF_TOPLEFT) == BF_TOPLEFT)
+               LTpenplus = 1;
+
+       if(LTInnerI != -1)
+               LTInnerPen = GetStockObject(DC_PEN);
+       if(LTOuterI != -1)
+               LTOuterPen = GetStockObject(DC_PEN);
+       if(RBInnerI != -1)
+               RBInnerPen = GetStockObject(DC_PEN);
+       if(RBOuterI != -1)
+               RBOuterPen = GetStockObject(DC_PEN);
+       {
+               HBRUSH hbr;
+               hbr = CreateSolidBrush(theme->crColor[COLOR_BTNFACE]);
+               FillRect(hdc, &InnerRect, hbr);
+               DeleteObject(hbr);
+       }
+       MoveToEx(hdc, 0, 0, &SavePoint);
+
+       /* Draw the outer edge */
+       SelectObject(hdc, LTOuterPen);
+       SetDCPenColor(hdc, theme->crColor[LTOuterI]);
+       if(uFlags & BF_TOP)
+       {
+               MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
+               LineTo(hdc, InnerRect.right, InnerRect.top);
+       }
+       if(uFlags & BF_LEFT)
+       {
+               MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
+               LineTo(hdc, InnerRect.left, InnerRect.bottom);
+       }
+       SelectObject(hdc, RBOuterPen);
+       SetDCPenColor(hdc, theme->crColor[RBOuterI]);
+       if(uFlags & BF_BOTTOM)
+       {
+               MoveToEx(hdc, InnerRect.left, InnerRect.bottom-1, NULL);
+               LineTo(hdc, InnerRect.right, InnerRect.bottom-1);
+       }
+       if(uFlags & BF_RIGHT)
+       {
+               MoveToEx(hdc, InnerRect.right-1, InnerRect.top, NULL);
+               LineTo(hdc, InnerRect.right-1, InnerRect.bottom);
+       }
+
+       /* Draw the inner edge */
+       SelectObject(hdc, LTInnerPen);
+       SetDCPenColor(hdc, theme->crColor[LTInnerI]);
+       if(uFlags & BF_TOP)
+       {
+               MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
+               LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
+       }
+       if(uFlags & BF_LEFT)
+       {
+               MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
+               LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
+       }
+       SelectObject(hdc, RBInnerPen);
+       SetDCPenColor(hdc, theme->crColor[RBInnerI]);
+       if(uFlags & BF_BOTTOM)
+       {
+               MoveToEx(hdc, InnerRect.left+LBpenplus, InnerRect.bottom-2, NULL);
+               LineTo(hdc, InnerRect.right-RBpenplus, InnerRect.bottom-2);
+       }
+       if(uFlags & BF_RIGHT)
+       {
+               MoveToEx(hdc, InnerRect.right-2, InnerRect.top+RTpenplus, NULL);
+               LineTo(hdc, InnerRect.right-2, InnerRect.bottom-RBpenplus);
+       }
+
+       /* Cleanup */
+       SelectObject(hdc, SavePen);
+       MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
+       return TRUE;
+}
+
+static BOOL
+MyDrawFrameButton(HDC hdc, LPRECT rc, UINT uState, THEME *theme)
+{
+       UINT edge;
+       if(uState & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT))
+               edge = EDGE_SUNKEN;
+       else
+               edge = EDGE_RAISED;
+       return MyIntDrawRectEdge(hdc, rc, edge, (uState & DFCS_FLAT) | BF_RECT | BF_SOFT, theme);
+}
+
+static int
+MyMakeSquareRect(LPRECT src, LPRECT dst)
+{
+       int Width  = src->right - src->left;
+       int Height = src->bottom - src->top;
+       int SmallDiam = Width > Height ? Height : Width;
+
+       *dst = *src;
+
+       /* Make it a square box */
+       if (Width < Height)       /* SmallDiam == Width */
+       {
+               dst->top += (Height-Width)/2;
+               dst->bottom = dst->top + SmallDiam;
+       }
+       else if(Width > Height) /* SmallDiam == Height */
+       {
+               dst->left += (Width-Height)/2;
+               dst->right = dst->left + SmallDiam;
+       }
+
+       return SmallDiam;
+}
+
+static BOOL
+MyDrawFrameCaption(HDC dc, LPRECT r, UINT uFlags, THEME *theme)
+{
+       LOGFONT lf;
+       HFONT hFont, hOldFont;
+       COLORREF clrsave;
+       RECT myr;
+       INT bkmode;
+       TCHAR Symbol;
+       switch(uFlags & 0xff)
+       {
+       case DFCS_CAPTIONCLOSE:
+               Symbol = 'r';
+               break;
+       case DFCS_CAPTIONHELP:
+               Symbol = 's';
+               break;
+       case DFCS_CAPTIONMIN:
+               Symbol = '0';
+               break;
+       case DFCS_CAPTIONMAX:
+               Symbol = '1';
+               break;
+       case DFCS_CAPTIONRESTORE:
+               Symbol = '2';
+               break;
+       }
+       MyIntDrawRectEdge(dc, r, (uFlags & DFCS_PUSHED) ? EDGE_SUNKEN : EDGE_RAISED, BF_RECT | BF_MIDDLE | BF_SOFT, theme);
+       ZeroMemory(&lf, sizeof(LOGFONT));
+       MyMakeSquareRect(r, &myr);
+       myr.left += 1;
+       myr.top += 1;
+       myr.right -= 1;
+       myr.bottom -= 1;
+       if(uFlags & DFCS_PUSHED)
+          OffsetRect(&myr,1,1);
+       lf.lfHeight = myr.bottom - myr.top;
+       lf.lfWidth = 0;
+       lf.lfWeight = FW_NORMAL;
+       lf.lfCharSet = DEFAULT_CHARSET;
+       lstrcpy(lf.lfFaceName, TEXT("Marlett"));
+       hFont = CreateFontIndirect(&lf);
+       /* save font and text color */
+       hOldFont = SelectObject(dc, hFont);
+       clrsave = GetTextColor(dc);
+       bkmode = GetBkMode(dc);
+       /* set color and drawing mode */
+       SetBkMode(dc, TRANSPARENT);
+       if(uFlags & DFCS_INACTIVE)
+       {
+               /* draw shadow */
+               SetTextColor(dc, theme->crColor[COLOR_BTNHIGHLIGHT]);
+               TextOut(dc, myr.left + 1, myr.top + 1, &Symbol, 1);
+       }
+       SetTextColor(dc, theme->crColor[(uFlags & DFCS_INACTIVE) ? COLOR_BTNSHADOW : COLOR_BTNTEXT]);
+       /* draw selected symbol */
+       TextOut(dc, myr.left, myr.top, &Symbol, 1);
+       /* restore previous settings */
+       SetTextColor(dc, clrsave);
+       SelectObject(dc, hOldFont);
+       SetBkMode(dc, bkmode);
+       DeleteObject(hFont);
+       return TRUE;
+}
+
+/******************************************************************************/
+
+static BOOL
+MyDrawFrameScroll(HDC dc, LPRECT r, UINT uFlags, THEME *theme)
+{
+       LOGFONT lf;
+       HFONT hFont, hOldFont;
+       COLORREF clrsave;
+       RECT myr;
+       INT bkmode;
+       TCHAR Symbol;
+       switch(uFlags & 0xff)
+       {
+       case DFCS_SCROLLCOMBOBOX:
+       case DFCS_SCROLLDOWN:
+               Symbol = '6';
+               break;
+
+       case DFCS_SCROLLUP:
+               Symbol = '5';
+               break;
+
+       case DFCS_SCROLLLEFT:
+               Symbol = '3';
+               break;
+
+       case DFCS_SCROLLRIGHT:
+               Symbol = '4';
+               break;
+       }
+       MyIntDrawRectEdge(dc, r, (uFlags & DFCS_PUSHED) ? EDGE_SUNKEN : EDGE_RAISED, (uFlags&DFCS_FLAT) | BF_MIDDLE | BF_RECT, theme);
+       ZeroMemory(&lf, sizeof(LOGFONT));
+       MyMakeSquareRect(r, &myr);
+       myr.left += 1;
+       myr.top += 1;
+       myr.right -= 1;
+       myr.bottom -= 1;
+       if(uFlags & DFCS_PUSHED)
+          OffsetRect(&myr,1,1);
+       lf.lfHeight = myr.bottom - myr.top;
+       lf.lfWidth = 0;
+       lf.lfWeight = FW_NORMAL;
+       lf.lfCharSet = DEFAULT_CHARSET;
+       lstrcpy(lf.lfFaceName, TEXT("Marlett"));
+       hFont = CreateFontIndirect(&lf);
+       /* save font and text color */
+       hOldFont = SelectObject(dc, hFont);
+       clrsave = GetTextColor(dc);
+       bkmode = GetBkMode(dc);
+       /* set color and drawing mode */
+       SetBkMode(dc, TRANSPARENT);
+       if(uFlags & DFCS_INACTIVE)
+       {
+               /* draw shadow */
+               SetTextColor(dc, theme->crColor[COLOR_BTNHIGHLIGHT]);
+               TextOut(dc, myr.left + 1, myr.top + 1, &Symbol, 1);
+       }
+       SetTextColor(dc, theme->crColor[(uFlags & DFCS_INACTIVE) ? COLOR_BTNSHADOW : COLOR_BTNTEXT]);
+       /* draw selected symbol */
+       TextOut(dc, myr.left, myr.top, &Symbol, 1);
+       /* restore previous settings */
+       SetTextColor(dc, clrsave);
+       SelectObject(dc, hOldFont);
+       SetBkMode(dc, bkmode);
+       DeleteObject(hFont);
+       return TRUE;
+}
+
+BOOL
+MyDrawFrameControl(HDC hDC, LPRECT rc, UINT uType, UINT uState, THEME *theme)
+{
+       switch(uType)
+       {
+       case DFC_BUTTON:
+               return MyDrawFrameButton(hDC, rc, uState, theme);
+       case DFC_CAPTION:
+               return MyDrawFrameCaption(hDC, rc, uState, theme);
+       case DFC_SCROLL:
+               return MyDrawFrameScroll(hDC, rc, uState, theme);
+       }
+       return FALSE;
+}
+
+BOOL
+MyDrawEdge(HDC hDC, LPRECT rc, UINT edge, UINT flags, THEME *theme)
+{
+       return MyIntDrawRectEdge(hDC, rc, edge, flags, theme);
+}
+
+VOID
+MyDrawCaptionButtons(HDC hdc, LPRECT lpRect, BOOL bMinMax, int x, THEME *theme)
+{
+       RECT rc3;
+       RECT rc4;
+       RECT rc5;
+
+       rc3.left = lpRect->right - 2 - x;
+       rc3.top = lpRect->top + 2;
+       rc3.right = lpRect->right - 2;
+       rc3.bottom = lpRect->bottom - 2;
+
+       MyDrawFrameControl(hdc, &rc3, DFC_CAPTION, DFCS_CAPTIONCLOSE, theme);
+
+       if (bMinMax)
+       {
+               rc4.left = rc3.left - x - 2;
+               rc4.top = rc3.top;
+               rc4.right = rc3.right - x - 2;
+               rc4.bottom = rc3.bottom;
+
+               MyDrawFrameControl(hdc, &rc4, DFC_CAPTION, DFCS_CAPTIONMAX, theme);
+
+               rc5.left = rc4.left - x;
+               rc5.top = rc4.top;
+               rc5.right = rc4.right - x;
+               rc5.bottom = rc4.bottom;
+
+               MyDrawFrameControl(hdc, &rc5, DFC_CAPTION, DFCS_CAPTIONMIN, theme);
+       }
+}
+
+VOID
+MyDrawScrollbar(HDC hdc, LPRECT rc, HBRUSH hbrScrollbar, THEME *theme)
+{
+       RECT rcTop;
+       RECT rcBottom;
+       RECT rcMiddle;
+       int width;
+
+       width = rc->right - rc->left;
+
+       rcTop.left = rc->left;
+       rcTop.right = rc->right;
+       rcTop.top = rc->top;
+       rcTop.bottom = rc->top + width;
+
+       rcMiddle.left = rc->left;
+       rcMiddle.right = rc->right;
+       rcMiddle.top = rc->top + width;
+       rcMiddle.bottom = rc->bottom - width;
+
+       rcBottom.left = rc->left;
+       rcBottom.right = rc->right;
+       rcBottom.top = rc->bottom - width;
+       rcBottom.bottom = rc->bottom;
+
+       MyDrawFrameControl(hdc, &rcTop, DFC_SCROLL, DFCS_SCROLLUP, theme);
+       MyDrawFrameControl(hdc, &rcBottom, DFC_SCROLL, DFCS_SCROLLDOWN, theme);
+
+       FillRect(hdc, &rcMiddle, hbrScrollbar);
+}
+
+/******************************************************************************/
+
+BOOL
+MyDrawCaptionTemp(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCWSTR str, UINT uFlags, THEME *theme)
+{
+       /* FIXME */
+       return DrawCaptionTemp(hwnd, hdc, rect, hFont, hIcon, str, uFlags);
+}
+
+/******************************************************************************/
+
+DWORD
+MyDrawMenuBarTemp(HWND Wnd, HDC DC, LPRECT Rect, HMENU Menu, HFONT Font, THEME *theme)
+{
+       /* FIXME */
+       return DrawMenuBarTemp(Wnd, DC, Rect, Menu, Font);
+}
diff --git a/reactos/dll/cpl/desk/draw.h b/reactos/dll/cpl/desk/draw.h
new file mode 100644 (file)
index 0000000..be45a89
--- /dev/null
@@ -0,0 +1,12 @@
+BOOL
+MyDrawFrameControl(HDC hDC, LPRECT rc, UINT uType, UINT uState, THEME *theme);
+BOOL
+MyDrawEdge(HDC hDC, LPRECT rc, UINT edge, UINT flags, THEME *theme);
+VOID
+MyDrawCaptionButtons(HDC hdc, LPRECT lpRect, BOOL bMinMax, int x, THEME *theme);
+VOID
+MyDrawScrollbar(HDC hdc, LPRECT rc, HBRUSH hbrScrollbar, THEME *theme);
+BOOL
+MyDrawCaptionTemp(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCWSTR str, UINT uFlags, THEME *theme);
+DWORD
+MyDrawMenuBarTemp(HWND Wnd, HDC DC, LPRECT Rect, HMENU Menu, HFONT Font, THEME *theme);
index 3a7c8b4..ba5d7a7 100644 (file)
@@ -4,11 +4,12 @@
  * FILE:            dll/cpl/desk/effappdlg.c
  * PURPOSE:         Effects appearance dialog
  *
  * FILE:            dll/cpl/desk/effappdlg.c
  * PURPOSE:         Effects appearance dialog
  *
- * PROGRAMMER:     Jan Roeloffzen (jroeloffzen[at]hotmail[dot]com)
+ * PROGRAMMER:      Jan Roeloffzen (jroeloffzen[at]hotmail[dot]com)
  *
  */
 
 #include "desk.h"
  *
  */
 
 #include "desk.h"
+#include "theme.h"
 #include "appearance.h"
 
 /* Update all the controls with the current values for the selected screen element */
 #include "appearance.h"
 
 /* Update all the controls with the current values for the selected screen element */
index 1f2cdb2..0cda379 100644 (file)
@@ -7,7 +7,9 @@
  */
 
 #include "desk.h"
  */
 
 #include "desk.h"
+#include "theme.h"
 #include "preview.h"
 #include "preview.h"
+#include "draw.h"
 
 static const TCHAR szPreviewWndClass[] = TEXT("PreviewWndClass");
 
 
 static const TCHAR szPreviewWndClass[] = TEXT("PreviewWndClass");
 
@@ -15,7 +17,7 @@ typedef struct _PREVIEW_DATA
 {
     HWND hwndParent;
 
 {
     HWND hwndParent;
 
-    DWORD clrSysColor[COLOR_MENUBAR];
+    THEME Theme;
 
     HBRUSH hbrScrollbar;
     HBRUSH hbrDesktop;
 
     HBRUSH hbrScrollbar;
     HBRUSH hbrDesktop;
@@ -58,10 +60,6 @@ typedef struct _PREVIEW_DATA
     LPTSTR lpMessText;
     LPTSTR lpButText;
 
     LPTSTR lpMessText;
     LPTSTR lpButText;
 
-    LOGFONT lfCaptionFont;
-    LOGFONT lfMenuFont;
-    LOGFONT lfMessageFont;
-
     HFONT hCaptionFont;
     HFONT hMenuFont;
     HFONT hMessageFont;
     HFONT hCaptionFont;
     HFONT hMenuFont;
     HFONT hMessageFont;
@@ -71,109 +69,48 @@ typedef struct _PREVIEW_DATA
 } PREVIEW_DATA, *PPREVIEW_DATA;
 
 
 } PREVIEW_DATA, *PPREVIEW_DATA;
 
 
-
-static VOID
-DrawCaptionButtons(HDC hdc, LPRECT lpRect, BOOL bMinMax, int x)
-{
-    RECT rc3;
-    RECT rc4;
-    RECT rc5;
-
-    rc3.left = lpRect->right - 2 - x;
-    rc3.top = lpRect->top + 2;
-    rc3.right = lpRect->right - 2;
-    rc3.bottom = lpRect->bottom - 2;
-
-    DrawFrameControl(hdc, &rc3, DFC_CAPTION, DFCS_CAPTIONCLOSE);
-
-    if (bMinMax)
-    {
-        rc4.left = rc3.left - x - 2;
-        rc4.top = rc3.top;
-        rc4.right = rc3.right - x - 2;
-        rc4.bottom = rc3.bottom;
-
-        DrawFrameControl(hdc, &rc4, DFC_CAPTION, DFCS_CAPTIONMAX);
-
-        rc5.left = rc4.left - x;
-        rc5.top = rc4.top;
-        rc5.right = rc4.right - x;
-        rc5.bottom = rc4.bottom;
-
-        DrawFrameControl(hdc, &rc5, DFC_CAPTION, DFCS_CAPTIONMIN);
-    }
-}
-
-
-static VOID
-DrawScrollbar(HDC hdc, LPRECT rc, HBRUSH hbrScrollbar)
+static VOID UpdatePreviewTheme(HWND hwnd, PPREVIEW_DATA pPreviewData, THEME *theme)
 {
 {
-    RECT rcTop;
-    RECT rcBottom;
-    RECT rcMiddle;
-    int width;
-
-    width = rc->right - rc->left;
-
-    rcTop.left = rc->left;
-    rcTop.right = rc->right;
-    rcTop.top = rc->top;
-    rcTop.bottom = rc->top + width;
-
-    rcMiddle.left = rc->left;
-    rcMiddle.right = rc->right;
-    rcMiddle.top = rc->top + width;
-    rcMiddle.bottom = rc->bottom - width;
-
-    rcBottom.left = rc->left;
-    rcBottom.right = rc->right;
-    rcBottom.top = rc->bottom - width;
-    rcBottom.bottom = rc->bottom;
-
-    DrawFrameControl(hdc, &rcTop, DFC_SCROLL, DFCS_SCROLLUP);
-    DrawFrameControl(hdc, &rcBottom, DFC_SCROLL, DFCS_SCROLLDOWN);
-
-    FillRect(hdc, &rcMiddle, hbrScrollbar);
+    if (pPreviewData->hbrScrollbar != NULL)
+        DeleteObject(pPreviewData->hbrScrollbar);
+    pPreviewData->hbrScrollbar = CreateSolidBrush(theme->crColor[COLOR_SCROLLBAR]);
+    if (pPreviewData->hbrDesktop != NULL)
+        DeleteObject(pPreviewData->hbrDesktop);
+    pPreviewData->hbrDesktop = CreateSolidBrush(theme->crColor[COLOR_DESKTOP]);
+    if (pPreviewData->hbrWindow != NULL)
+        DeleteObject(pPreviewData->hbrWindow);
+    pPreviewData->hbrWindow = CreateSolidBrush(theme->crColor[COLOR_WINDOW]);
+
+    pPreviewData->cxEdge = theme->Size[SIZE_EDGE_X] - 2;        /* SM_CXEDGE */
+    pPreviewData->cyEdge = theme->Size[SIZE_EDGE_Y] - 2;        /* SM_CYEDGE */
+
+    pPreviewData->cySizeFrame = theme->Size[SIZE_FRAME_Y] - 1;  /* SM_CYSIZEFRAME */
+
+    pPreviewData->cyCaption = theme->Size[SIZE_CAPTION_Y];      /* SM_CYCAPTION */
+    pPreviewData->cyMenu = theme->Size[SIZE_MENU_Y];            /* SM_CYMENU */
+    pPreviewData->cxScrollbar = theme->Size[SIZE_SCROLL_X];     /* SM_CXVSCROLL */
+    pPreviewData->cyBorder = theme->Size[SIZE_BORDER_Y];        /* SM_CYBORDER */
+
+    if (pPreviewData->hCaptionFont != NULL)
+        DeleteObject(pPreviewData->hCaptionFont);
+    pPreviewData->hCaptionFont = CreateFontIndirect(&theme->lfFont[FONT_CAPTION]);
+
+    if (pPreviewData->hMenuFont != NULL)
+        DeleteObject(pPreviewData->hMenuFont);
+    pPreviewData->hMenuFont = CreateFontIndirect(&theme->lfFont[FONT_MENU]);
+
+    if (pPreviewData->hMessageFont != NULL)
+        DeleteObject(pPreviewData->hMessageFont);
+    pPreviewData->hMessageFont = CreateFontIndirect(&theme->lfFont[FONT_DIALOG]);
+
+    pPreviewData->Theme = *theme;
+    InvalidateRect(hwnd, NULL, FALSE);
 }
 
 }
 
-
 static VOID
 OnCreate(HWND hwnd, PPREVIEW_DATA pPreviewData)
 {
 static VOID
 OnCreate(HWND hwnd, PPREVIEW_DATA pPreviewData)
 {
-    NONCLIENTMETRICS NonClientMetrics;
-    INT i;
-
-    for (i = 0; i < COLOR_MENUBAR + 1; i++)
-    {
-        pPreviewData->clrSysColor[i] = GetSysColor(i);
-    }
-
-    pPreviewData->hbrScrollbar = CreateSolidBrush(pPreviewData->clrSysColor[COLOR_SCROLLBAR]);
-    pPreviewData->hbrDesktop = CreateSolidBrush(pPreviewData->clrSysColor[COLOR_DESKTOP]);
-    pPreviewData->hbrWindow = CreateSolidBrush(pPreviewData->clrSysColor[COLOR_WINDOW]);
-
-    pPreviewData->cxEdge = GetSystemMetrics(SM_CXEDGE) - 2;
-    pPreviewData->cyEdge = GetSystemMetrics(SM_CXEDGE) - 2;
-
-    pPreviewData->cySizeFrame = GetSystemMetrics(SM_CYSIZEFRAME) - 1;
-
-    pPreviewData->cyCaption = GetSystemMetrics(SM_CYCAPTION);
-    pPreviewData->cyMenu = GetSystemMetrics(SM_CYMENU);
-    pPreviewData->cxScrollbar = GetSystemMetrics(SM_CXVSCROLL);
-    pPreviewData->cyBorder = GetSystemMetrics(SM_CYBORDER);
-
-    /* load font info */
-    NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
-    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
-
-    pPreviewData->lfCaptionFont = NonClientMetrics.lfCaptionFont;
-    pPreviewData->hCaptionFont = CreateFontIndirect(&pPreviewData->lfCaptionFont);
-
-    pPreviewData->lfMenuFont = NonClientMetrics.lfMenuFont;
-    pPreviewData->hMenuFont = CreateFontIndirect(&pPreviewData->lfMenuFont);
-
-    pPreviewData->lfMessageFont = NonClientMetrics.lfMessageFont;
-    pPreviewData->hMessageFont = CreateFontIndirect(&pPreviewData->lfMessageFont);
+    THEME *theme;
 
     /* Load and modify the menu */
     pPreviewData->hMenu = LoadMenu(hApplet, MAKEINTRESOURCE(IDR_PREVIEW_MENU));
 
     /* Load and modify the menu */
     pPreviewData->hMenu = LoadMenu(hApplet, MAKEINTRESOURCE(IDR_PREVIEW_MENU));
@@ -191,6 +128,11 @@ OnCreate(HWND hwnd, PPREVIEW_DATA pPreviewData)
     AllocAndLoadString(&pPreviewData->lpMessBox, hApplet, IDS_MESSBOX);
     AllocAndLoadString(&pPreviewData->lpMessText, hApplet, IDS_MESSTEXT);
     AllocAndLoadString(&pPreviewData->lpButText, hApplet, IDS_BUTTEXT);
     AllocAndLoadString(&pPreviewData->lpMessBox, hApplet, IDS_MESSBOX);
     AllocAndLoadString(&pPreviewData->lpMessText, hApplet, IDS_MESSTEXT);
     AllocAndLoadString(&pPreviewData->lpButText, hApplet, IDS_BUTTEXT);
+
+    theme = &pPreviewData->Theme;
+    LoadCurrentTheme(theme);
+
+    UpdatePreviewTheme(hwnd, pPreviewData, theme);
 }
 
 
 }
 
 
@@ -302,21 +244,6 @@ OnSize(INT cx, INT cy, PPREVIEW_DATA pPreviewData)
     CalculateItemSize(pPreviewData);
 }
 
     CalculateItemSize(pPreviewData);
 }
 
-#ifdef _MSC_VER
-
-#if _UNICODE
-typedef BOOL (WINAPI * DCT_PROC)(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCWSTR str, UINT uFlags);
-#define DCT_ORD 178
-#else
-typedef BOOL (WINAPI * DCT_PROC)(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon, LPCSTR str, UINT uFlags);
-#define DCT_ORD 177
-#endif
-
-typedef DWORD (WINAPI * DMBT_PROC)(HWND hwnd, HDC hDC, LPRECT lprect, HMENU hMenu, HFONT hFont);
-#define DMBT_ORD 186
-
-#endif
-
 static VOID
 OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
 {
 static VOID
 OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
 {
@@ -324,19 +251,9 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
     HFONT hOldFont;
     HDC hdc;
     RECT rc;
     HFONT hOldFont;
     HDC hdc;
     RECT rc;
+    THEME *theme;
 
 
-#ifdef _MSC_VER
-    DCT_PROC DrawCaptionTemp;
-    DMBT_PROC DrawMenuBarTemp;
-    HMODULE hUser32;
-
-    hUser32 = LoadLibrary(_T("user32.dll"));
-    if(hUser32 == NULL)
-        return;
-
-    DrawCaptionTemp = (DCT_PROC)GetProcAddress(hUser32, (LPCSTR)DCT_ORD);
-    DrawMenuBarTemp = (DMBT_PROC)GetProcAddress(hUser32, (LPCSTR)DMBT_ORD);
-#endif
+    theme = &pPreviewData->Theme;
 
     hdc = BeginPaint(hwnd, &ps);
 
 
     hdc = BeginPaint(hwnd, &ps);
 
@@ -344,47 +261,47 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
     FillRect(hdc, &pPreviewData->rcDesktop, pPreviewData->hbrDesktop);
 
     /* Inactive Window */
     FillRect(hdc, &pPreviewData->rcDesktop, pPreviewData->hbrDesktop);
 
     /* Inactive Window */
-    DrawEdge(hdc, &pPreviewData->rcInactiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE);
-    SetTextColor(hdc, pPreviewData->clrSysColor[COLOR_INACTIVECAPTIONTEXT]);
+    MyDrawEdge(hdc, &pPreviewData->rcInactiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, theme);
+    SetTextColor(hdc, theme->crColor[COLOR_INACTIVECAPTIONTEXT]);
     DrawCaptionTemp(NULL, hdc, &pPreviewData->rcInactiveCaption,  pPreviewData->hCaptionFont,
                     NULL, pPreviewData->lpInAct, DC_GRADIENT | DC_ICON | DC_TEXT);
     DrawCaptionTemp(NULL, hdc, &pPreviewData->rcInactiveCaption,  pPreviewData->hCaptionFont,
                     NULL, pPreviewData->lpInAct, DC_GRADIENT | DC_ICON | DC_TEXT);
-    DrawCaptionButtons(hdc, &pPreviewData->rcInactiveCaption, TRUE, pPreviewData->cyCaption - 2);
+    MyDrawCaptionButtons(hdc, &pPreviewData->rcInactiveCaption, TRUE, pPreviewData->cyCaption - 2, theme);
 
     /* Active Window */
 
     /* Active Window */
-    DrawEdge(hdc, &pPreviewData->rcActiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE);
-    SetTextColor(hdc, pPreviewData->clrSysColor[COLOR_CAPTIONTEXT]);
-    DrawCaptionTemp(NULL, hdc, &pPreviewData->rcActiveCaption, pPreviewData->hCaptionFont,
-                    NULL, pPreviewData->lpAct, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT);
-    DrawCaptionButtons(hdc, &pPreviewData->rcActiveCaption, TRUE, pPreviewData->cyCaption - 2);
+    MyDrawEdge(hdc, &pPreviewData->rcActiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, theme);
+    SetTextColor(hdc, theme->crColor[COLOR_CAPTIONTEXT]);
+    MyDrawCaptionTemp(NULL, hdc, &pPreviewData->rcActiveCaption, pPreviewData->hCaptionFont,
+                      NULL, pPreviewData->lpAct, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT, theme);
+    MyDrawCaptionButtons(hdc, &pPreviewData->rcActiveCaption, TRUE, pPreviewData->cyCaption - 2, theme);
 
     /* Draw the menu bar */
 
     /* Draw the menu bar */
-    DrawMenuBarTemp(hwnd, hdc, &pPreviewData->rcActiveMenuBar,
-                    pPreviewData->hMenu,
-                    pPreviewData->hMenuFont);
+    MyDrawMenuBarTemp(hwnd, hdc, &pPreviewData->rcActiveMenuBar,
+                      pPreviewData->hMenu,
+                      pPreviewData->hMenuFont, theme);
 
     /* Draw the client area */
     CopyRect(&rc, &pPreviewData->rcActiveClient);
 
     /* Draw the client area */
     CopyRect(&rc, &pPreviewData->rcActiveClient);
-    DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
+    MyDrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST, theme);
     FillRect(hdc, &rc, pPreviewData->hbrWindow);
 
     /* Draw the client text */
     CopyRect(&rc, &pPreviewData->rcActiveClient);
     rc.left += 4;
     rc.top += 2;
     FillRect(hdc, &rc, pPreviewData->hbrWindow);
 
     /* Draw the client text */
     CopyRect(&rc, &pPreviewData->rcActiveClient);
     rc.left += 4;
     rc.top += 2;
-    SetTextColor(hdc, pPreviewData->clrSysColor[COLOR_WINDOWTEXT]);
-    hOldFont = SelectObject(hdc, pPreviewData->hCaptionFont);
+    SetTextColor(hdc, theme->crColor[COLOR_WINDOWTEXT]);
+    hOldFont = SelectObject(hdc, pPreviewData->hCaptionFont);   /* FIXME: client text is not caption text */
     DrawText(hdc, pPreviewData->lpWinTxt, lstrlen(pPreviewData->lpWinTxt), &rc, DT_LEFT);
     SelectObject(hdc, hOldFont);
 
     /* Draw the scroll bar */
     DrawText(hdc, pPreviewData->lpWinTxt, lstrlen(pPreviewData->lpWinTxt), &rc, DT_LEFT);
     SelectObject(hdc, hOldFont);
 
     /* Draw the scroll bar */
-    DrawScrollbar(hdc, &pPreviewData->rcActiveScroll, pPreviewData->hbrScrollbar);
+    MyDrawScrollbar(hdc, &pPreviewData->rcActiveScroll, pPreviewData->hbrScrollbar, theme);
 
     /* Dialog Window */
 
     /* Dialog Window */
-    DrawEdge(hdc, &pPreviewData->rcDialogFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE);
-    SetTextColor(hdc, pPreviewData->clrSysColor[COLOR_WINDOW]);
-    DrawCaptionTemp(NULL, hdc, &pPreviewData->rcDialogCaption, pPreviewData->hCaptionFont,
-                    NULL, pPreviewData->lpMessBox, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT);
-    DrawCaptionButtons(hdc, &pPreviewData->rcDialogCaption, FALSE, pPreviewData->cyCaption - 2);
+    MyDrawEdge(hdc, &pPreviewData->rcDialogFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, theme);
+    SetTextColor(hdc, theme->crColor[COLOR_WINDOW]);
+    MyDrawCaptionTemp(NULL, hdc, &pPreviewData->rcDialogCaption, pPreviewData->hCaptionFont,
+                      NULL, pPreviewData->lpMessBox, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT, theme);
+    MyDrawCaptionButtons(hdc, &pPreviewData->rcDialogCaption, FALSE, pPreviewData->cyCaption - 2, theme);
 
     /* Draw the dialog text */
     CopyRect(&rc, &pPreviewData->rcDialogClient);
 
     /* Draw the dialog text */
     CopyRect(&rc, &pPreviewData->rcDialogClient);
@@ -396,9 +313,9 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
     SelectObject(hdc, hOldFont);
 
     /* Draw Button */
     SelectObject(hdc, hOldFont);
 
     /* Draw Button */
-    DrawFrameControl(hdc, &pPreviewData->rcDialogButton, DFC_BUTTON, DFCS_BUTTONPUSH);
+    MyDrawFrameControl(hdc, &pPreviewData->rcDialogButton, DFC_BUTTON, DFCS_BUTTONPUSH, theme);
     CopyRect(&rc, &pPreviewData->rcDialogButton);
     CopyRect(&rc, &pPreviewData->rcDialogButton);
-    SetTextColor(hdc, pPreviewData->clrSysColor[COLOR_BTNTEXT]);
+    SetTextColor(hdc, theme->crColor[COLOR_BTNTEXT]);
     hOldFont = SelectObject(hdc, pPreviewData->hMessageFont);
     DrawText(hdc, pPreviewData->lpButText, lstrlen(pPreviewData->lpButText), &rc, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
     SelectObject(hdc, hOldFont);
     hOldFont = SelectObject(hdc, pPreviewData->hMessageFont);
     DrawText(hdc, pPreviewData->lpButText, lstrlen(pPreviewData->lpButText), &rc, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
     SelectObject(hdc, hOldFont);
@@ -575,60 +492,14 @@ PreviewWndProc(HWND hwnd,
             }
             break;
 
             }
             break;
 
-        case PVM_SETCAPTIONFONT:
-            CopyMemory(&pPreviewData->lfCaptionFont, (LOGFONT*)lParam, sizeof(LOGFONT));
-            DeleteObject(pPreviewData->hCaptionFont);
-            pPreviewData->hCaptionFont = CreateFontIndirect(&pPreviewData->lfCaptionFont);
-            CalculateItemSize(pPreviewData);
-            InvalidateRect(hwnd, NULL, FALSE);
-            break;
-
-        case PVM_SETMENUFONT:
-            CopyMemory(&pPreviewData->lfMenuFont, (LOGFONT*)lParam, sizeof(LOGFONT));
-            DeleteObject(pPreviewData->hMenuFont);
-            pPreviewData->hMenuFont = CreateFontIndirect(&pPreviewData->lfMenuFont);
-            CalculateItemSize(pPreviewData);
-            InvalidateRect(hwnd, NULL, FALSE);
-            break;
-
-        case PVM_SETDIALOGFONT:
-            CopyMemory(&pPreviewData->lfMessageFont, (LOGFONT*)lParam, sizeof(LOGFONT));
-            DeleteObject(pPreviewData->hMessageFont);
-            pPreviewData->hMessageFont = CreateFontIndirect(&pPreviewData->lfMessageFont);
-            CalculateItemSize(pPreviewData);
-            InvalidateRect(hwnd, NULL, FALSE);
-            break;
-
-        case PVM_SETCOLOR:
-            pPreviewData->clrSysColor[(INT)wParam] = (DWORD)lParam;
-            switch((INT)wParam)
-            {
-                case COLOR_SCROLLBAR:
-                    DeleteObject(pPreviewData->hbrScrollbar);
-                    pPreviewData->hbrScrollbar = CreateSolidBrush(pPreviewData->clrSysColor[COLOR_SCROLLBAR]);
-                    break;
-
-                case COLOR_DESKTOP:
-                    DeleteObject(pPreviewData->hbrDesktop);
-                    pPreviewData->hbrDesktop = CreateSolidBrush(pPreviewData->clrSysColor[COLOR_DESKTOP]);
-                    break;
-
-                case COLOR_WINDOW:
-                    DeleteObject(pPreviewData->hbrWindow);
-                    pPreviewData->hbrWindow = CreateSolidBrush(pPreviewData->clrSysColor[COLOR_WINDOW]);
-                    break;
-            }
-            InvalidateRect(hwnd, NULL, FALSE);
+        case PVM_UPDATETHEME:
+            UpdatePreviewTheme(hwnd, pPreviewData, (THEME *)lParam);
             break;
 
         default:
             break;
 
         default:
-            DefWindowProc(hwnd,
-                          uMsg,
-                          wParam,
-                          lParam);
+            return DefWindowProc(hwnd, uMsg, wParam, lParam);
     }
     }
-
-    return TRUE;
+    return FALSE;
 }
 
 
 }
 
 
@@ -651,6 +522,5 @@ RegisterPreviewControl(IN HINSTANCE hInstance)
 VOID
 UnregisterPreviewControl(IN HINSTANCE hInstance)
 {
 VOID
 UnregisterPreviewControl(IN HINSTANCE hInstance)
 {
-    UnregisterClass(szPreviewWndClass,
-                    hInstance);
+    UnregisterClass(szPreviewWndClass, hInstance);
 }
 }
index 01afe49..444872b 100644 (file)
 #define PVM_GETCYSIZEFRAME   (WM_USER+7)
 #define PVM_SETCYSIZEFRAME   (WM_USER+8)
 
 #define PVM_GETCYSIZEFRAME   (WM_USER+7)
 #define PVM_SETCYSIZEFRAME   (WM_USER+8)
 
-#define PVM_SETCAPTIONFONT   (WM_USER+9)
-#define PVM_SETMENUFONT      (WM_USER+10)
-#define PVM_SETDIALOGFONT    (WM_USER+11)
-
-#define PVM_SETCOLOR         (WM_USER+12)
+#define PVM_UPDATETHEME      (WM_USER+13)
 
 BOOL RegisterPreviewControl(IN HINSTANCE hInstance);
 VOID UnregisterPreviewControl(IN HINSTANCE hInstance);
 
 BOOL RegisterPreviewControl(IN HINSTANCE hInstance);
 VOID UnregisterPreviewControl(IN HINSTANCE hInstance);
diff --git a/reactos/dll/cpl/desk/theme.c b/reactos/dll/cpl/desk/theme.c
new file mode 100644 (file)
index 0000000..0170fab
--- /dev/null
@@ -0,0 +1,413 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS Display Control Panel
+ * FILE:            lib/cpl/desk/theme.c
+ * PURPOSE:         Handling themes
+ *
+ * PROGRAMMERS:     Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
+ */
+
+#include "desk.h"
+#include "theme.h"
+
+static BOOL g_TemplateLoaded = FALSE;
+static INT g_TemplateCount = 0;
+
+static INT g_ColorList[NUM_COLORS];
+
+static const TCHAR g_CPColors[] = TEXT("Control Panel\\Colors");
+static const TCHAR g_CPANewSchemes[] = TEXT("Control Panel\\Appearance\\New Schemes");
+static const TCHAR g_SelectedStyle[] = TEXT("SelectedStyle");
+
+/******************************************************************************/
+
+THEME_PRESET g_ThemeTemplates[MAX_TEMPLATES];
+
+/* This is the list of names for the colors stored in the registry */
+const TCHAR g_RegColorNames[NUM_COLORS][MAX_COLORNAMELENGTH] =
+       {TEXT("Scrollbar"),                             /* 00 = COLOR_SCROLLBAR */
+       TEXT("Background"),                             /* 01 = COLOR_DESKTOP */
+       TEXT("ActiveTitle"),                    /* 02 = COLOR_ACTIVECAPTION  */
+       TEXT("InactiveTitle"),                  /* 03 = COLOR_INACTIVECAPTION */
+       TEXT("Menu"),                                   /* 04 = COLOR_MENU */
+       TEXT("Window"),                                 /* 05 = COLOR_WINDOW */
+       TEXT("WindowFrame"),                    /* 06 = COLOR_WINDOWFRAME */
+       TEXT("MenuText"),                               /* 07 = COLOR_MENUTEXT */
+       TEXT("WindowText"),                     /* 08 = COLOR_WINDOWTEXT */
+       TEXT("TitleText"),                              /* 09 = COLOR_CAPTIONTEXT */
+       TEXT("ActiveBorder"),                   /* 10 = COLOR_ACTIVEBORDER */
+       TEXT("InactiveBorder"),                 /* 11 = COLOR_INACTIVEBORDER */
+       TEXT("AppWorkSpace"),                   /* 12 = COLOR_APPWORKSPACE */
+       TEXT("Hilight"),                                /* 13 = COLOR_HIGHLIGHT */
+       TEXT("HilightText"),                    /* 14 = COLOR_HIGHLIGHTTEXT */
+       TEXT("ButtonFace"),                     /* 15 = COLOR_BTNFACE */
+       TEXT("ButtonShadow"),                   /* 16 = COLOR_BTNSHADOW */
+       TEXT("GrayText"),                               /* 17 = COLOR_GRAYTEXT */
+       TEXT("ButtonText"),                     /* 18 = COLOR_BTNTEXT */
+       TEXT("InactiveTitleText"),              /* 19 = COLOR_INACTIVECAPTIONTEXT */
+       TEXT("ButtonHilight"),                  /* 20 = COLOR_BTNHIGHLIGHT */
+       TEXT("ButtonDkShadow"),                 /* 21 = COLOR_3DDKSHADOW */
+       TEXT("ButtonLight"),                    /* 22 = COLOR_3DLIGHT */
+       TEXT("InfoText"),                               /* 23 = COLOR_INFOTEXT */
+       TEXT("InfoWindow"),                     /* 24 = COLOR_INFOBK */
+       TEXT("ButtonAlternateFace"),    /* 25 = COLOR_ALTERNATEBTNFACE */
+       TEXT("HotTrackingColor"),               /* 26 = COLOR_HOTLIGHT */
+       TEXT("GradientActiveTitle"),    /* 27 = COLOR_GRADIENTACTIVECAPTION */
+       TEXT("GradientInactiveTitle"),  /* 28 = COLOR_GRADIENTINACTIVECAPTION */
+       TEXT("MenuHilight"),                    /* 29 = COLOR_MENUHILIGHT */
+       TEXT("MenuBar"),                                /* 30 = COLOR_MENUBAR */
+};
+
+/* This is the list of used metrics and their numbers */
+const int g_SizeMetric[NUM_SIZES] =
+{
+       SM_CXBORDER,        /* 00: SIZE_BORDER_X */
+       SM_CYBORDER,        /* 01: SIZE_BORDER_Y */
+       SM_CYCAPTION,       /* 02: SIZE_CAPTION_Y */
+       SM_CXICON,          /* 03: SIZE_ICON_X */
+       SM_CYICON,          /* 04: SIZE_ICON_Y */
+       SM_CXICONSPACING,   /* 05: SIZE_ICON_SPC_X */
+       SM_CYICONSPACING,   /* 06: SIZE_ICON_SPC_Y */
+       SM_CXMENUSIZE,      /* 07: SIZE_MENU_SIZE_X */
+       SM_CYMENU,          /* 08: SIZE_MENU_Y */
+       SM_CXVSCROLL,       /* 09: SIZE_SCROLL_X */
+       SM_CYHSCROLL,       /* 10: SIZE_SCROLL_Y */
+       SM_CYSMCAPTION,     /* 11: SIZE_SMCAPTION_Y */
+       SM_CXEDGE,          /* 12: SIZE_EDGE_X */
+       SM_CYEDGE,          /* 13: SIZE_EDGE_Y */
+       SM_CYSIZEFRAME,     /* 14: SIZE_FRAME_Y */
+       SM_CXMENUCHECK,     /* 15: SIZE_MENU_CHECK_X */
+       SM_CYMENUCHECK,     /* 16: SIZE_MENU_CHECK_Y */
+       SM_CYMENUSIZE,      /* 17: SIZE_MENU_SIZE_Y */
+       SM_CXSIZE,          /* 18: SIZE_SIZE_X */
+       SM_CYSIZE           /* 19: SIZE_SIZE_Y */
+};
+
+/******************************************************************************/
+
+VOID LoadCurrentTheme(THEME* theme)
+{
+       INT i;
+       NONCLIENTMETRICS NonClientMetrics;
+
+       /* Load colors */
+       for (i = 0; i < NUM_COLORS; i++)
+       {
+               g_ColorList[i] = i;
+               theme->crColor[i] = (COLORREF)GetSysColor(i);
+       }
+
+       /* Load sizes */
+       for (i = 0; i < NUM_SIZES; i++)
+       {
+               theme->Size[i] = GetSystemMetrics(g_SizeMetric[i]);
+       }
+
+       /* Load fonts */
+       NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
+       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
+       theme->lfFont[FONT_CAPTION] = NonClientMetrics.lfCaptionFont;
+       theme->lfFont[FONT_SMCAPTION] = NonClientMetrics.lfSmCaptionFont;
+       theme->lfFont[FONT_MENU] = NonClientMetrics.lfMenuFont;
+       theme->lfFont[FONT_INFO] = NonClientMetrics.lfStatusFont;
+       theme->lfFont[FONT_DIALOG] = NonClientMetrics.lfMessageFont;
+       SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &theme->lfFont[FONT_ICON], 0);
+
+       /* Effects */
+       /* "Use the following transition effect for menus and tooltips" */
+       SystemParametersInfo(SPI_GETMENUANIMATION, sizeof(BOOL), &theme->Effects.bMenuAnimation, 0);
+       SystemParametersInfo(SPI_GETMENUFADE, sizeof(BOOL), &theme->Effects.bMenuFade, 0);
+       /* FIXME: XP seems to use grayed checkboxes to reflect differences between menu and tooltips settings
+        * Just keep them in sync for now:
+        */
+       theme->Effects.bTooltipAnimation  = theme->Effects.bMenuAnimation;
+       theme->Effects.bTooltipFade        = theme->Effects.bMenuFade;
+
+       /* show content of windows during dragging */
+       //SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, theme->Effects.bDragFullWindows, NULL, SPIF_SENDCHANGE | SPIF_UPDATEINIFILE);
+       SystemParametersInfoW(SPI_GETDRAGFULLWINDOWS, 0, &theme->Effects.bDragFullWindows, 0);
+
+       /* "Hide underlined letters for keyboard navigation until I press the Alt key" */
+       SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &theme->Effects.bKeyboardCues, 0);
+}
+
+BOOL LoadThemeFromReg(THEME* theme, INT ThemeId)
+{
+       INT i;
+       TCHAR strSelectedStyle[4];
+       TCHAR strSizeName[20] = {TEXT("Sizes\\0")};
+       TCHAR strValueName[10];
+       HKEY hkNewSchemes, hkScheme, hkSize;
+       DWORD dwType, dwLength;
+       BOOL Ret = FALSE;
+
+       if (!g_TemplateLoaded)
+               LoadThemeTemplates(strSelectedStyle);
+
+       if (ThemeId == -1)
+               return FALSE;
+
+       if (RegOpenKeyEx(HKEY_CURRENT_USER, g_CPANewSchemes, 0, KEY_READ, &hkNewSchemes) == ERROR_SUCCESS)
+       {
+               if (RegOpenKeyEx(hkNewSchemes, g_ThemeTemplates[ThemeId].strKeyName, 0, KEY_READ, &hkScheme) == ERROR_SUCCESS)
+               {
+                       lstrcpyn(&strSizeName[6], g_ThemeTemplates[ThemeId].strSizeName, 3);
+                       if (RegOpenKeyEx(hkScheme, strSizeName, 0, KEY_READ, &hkSize) == ERROR_SUCCESS)
+                       {
+                               Ret = TRUE;
+
+                               dwLength = sizeof(DWORD);
+                               if (RegQueryValueEx(hkSize, TEXT("FlatMenus"), NULL, &dwType, (LPBYTE)&theme->bFlatMenus, &dwLength) != ERROR_SUCCESS ||
+                                       dwType != REG_DWORD)
+                               {
+                                       /* Failed to read registry value */
+                                       theme->bFlatMenus = FALSE;
+                               }
+
+                               for (i = 0; i < NUM_COLORS; i++)
+                               {
+                                       wsprintf(strValueName, TEXT("Color #%d"), i);
+                                       dwLength = sizeof(COLORREF);
+                                       if (RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&theme->crColor[i], &dwLength) != ERROR_SUCCESS ||
+                                               dwType != REG_DWORD)
+                                       {
+                                               /* Failed to read registry value, initialize with current setting for now */
+                                               theme->crColor[i] = GetSysColor(i);
+                                       }
+                               }
+
+                               for (i = 0; i < NUM_FONTS; i++)
+                               {
+                                       wsprintf(strValueName, TEXT("Font #%d"), i);
+                                       dwLength = sizeof(LOGFONT);
+                                       if (RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&theme->lfFont[i], &dwLength) != ERROR_SUCCESS ||
+                                               dwType != REG_BINARY || dwLength != sizeof(LOGFONT))
+                                       {
+                                               /* Failed to read registry value */
+                                               Ret = FALSE;
+                                       }
+                               }
+
+                               for (i = 0; i < NUM_SIZES; i++)
+                               {
+                                       wsprintf(strValueName, TEXT("Size #%d"), i);
+                                       dwLength = sizeof(UINT64);
+                                       if (RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&theme->Size[i], &dwLength) != ERROR_SUCCESS ||
+                                               dwType != REG_QWORD || dwLength != sizeof(UINT64))
+                                       {
+                                               /* Failed to read registry value, initialize with current setting for now */
+                                               theme->Size[i] = GetSystemMetrics(g_SizeMetric[i]);
+                                       }
+                               }
+                               RegCloseKey(hkScheme);
+                       }
+                       RegCloseKey(hkScheme);
+               }
+               RegCloseKey(hkNewSchemes);
+       }
+
+       return Ret;
+}
+
+static VOID
+_UpdateUserPref(UINT SpiGet, UINT SpiSet, BOOL *pbFlag)
+{
+       SystemParametersInfo(SpiSet, 0, (PVOID)pbFlag, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
+}
+#define UPDATE_USERPREF(NAME,pbFlag) _UpdateUserPref(SPI_GET ## NAME, SPI_SET ## NAME, pbFlag)
+
+VOID ApplyTheme(THEME* theme, INT ThemeId)
+{
+       INT i, Result;
+       HKEY hKey;
+       DWORD dwDisposition;
+       TCHAR clText[16];
+       NONCLIENTMETRICS NonClientMetrics;
+
+       /* Apply Colors from global variable */
+       SetSysColors(NUM_COLORS, g_ColorList, theme->crColor);
+
+       /* Save colors to registry */
+       Result = RegOpenKeyEx(HKEY_CURRENT_USER, g_CPColors, 0, KEY_ALL_ACCESS, &hKey);
+       if (Result != ERROR_SUCCESS)
+       {
+               /* Could not open the key, try to create it */
+               Result = RegCreateKeyEx(HKEY_CURRENT_USER, g_CPColors, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
+       }
+
+       if (Result == ERROR_SUCCESS)
+       {
+               for (i = 0; i < NUM_COLORS; i++)
+               {
+                       DWORD red   = GetRValue(theme->crColor[i]);
+                       DWORD green = GetGValue(theme->crColor[i]);
+                       DWORD blue  = GetBValue(theme->crColor[i]);
+                       wsprintf(clText, TEXT("%d %d %d"), red, green, blue);
+                       RegSetValueEx(hKey, g_RegColorNames[i], 0, REG_SZ, (BYTE *)clText, (lstrlen(clText) + 1) * sizeof(TCHAR));
+               }
+               RegCloseKey(hKey);
+       }
+
+       /* Apply the fonts */
+       NonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
+       SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
+       NonClientMetrics.lfCaptionFont = theme->lfFont[FONT_CAPTION];
+       NonClientMetrics.lfSmCaptionFont = theme->lfFont[FONT_SMCAPTION];
+       NonClientMetrics.lfMenuFont = theme->lfFont[FONT_MENU];
+       NonClientMetrics.lfStatusFont = theme->lfFont[FONT_INFO];
+       NonClientMetrics.lfMessageFont = theme->lfFont[FONT_DIALOG];
+       SystemParametersInfo(SPI_SETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &NonClientMetrics, 0);
+       SystemParametersInfo(SPI_SETICONTITLELOGFONT, sizeof(LOGFONT), &theme->lfFont[FONT_ICON], 0);
+
+       /* FIXME: Apply size metrics */
+
+       /* Save fonts and size metrics to registry */
+       Result = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop\\WindowMetrics"), 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
+       if (Result == ERROR_SUCCESS)
+       {
+               RegSetValueEx(hKey, TEXT("CaptionFont"), 0, REG_BINARY, (BYTE *)&theme->lfFont[FONT_CAPTION], sizeof(LOGFONT));
+               RegSetValueEx(hKey, TEXT("SmCaptionFont"), 0, REG_BINARY, (BYTE *)&theme->lfFont[FONT_SMCAPTION], sizeof(LOGFONT));
+               RegSetValueEx(hKey, TEXT("IconFont"), 0, REG_BINARY, (BYTE *)&theme->lfFont[FONT_ICON], sizeof(LOGFONT));
+               RegSetValueEx(hKey, TEXT("MenuFont"), 0, REG_BINARY, (BYTE *)&theme->lfFont[FONT_MENU], sizeof(LOGFONT));
+               RegSetValueEx(hKey, TEXT("StatusFont"), 0, REG_BINARY, (BYTE *)&theme->lfFont[FONT_INFO], sizeof(LOGFONT));
+               RegSetValueEx(hKey, TEXT("MessageFont"), 0, REG_BINARY, (BYTE *)&theme->lfFont[FONT_DIALOG], sizeof(LOGFONT));
+
+               /* Save size metrics to registry */
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_BORDER_X]);
+               RegSetValueEx(hKey, TEXT("BorderWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_CAPTION_Y]);
+               RegSetValueEx(hKey, TEXT("CaptionWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_CAPTION_Y]);
+               RegSetValueEx(hKey, TEXT("CaptionHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_SMCAPTION_Y]);
+               RegSetValueEx(hKey, TEXT("SmCaptionWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_SMCAPTION_Y]);
+               RegSetValueEx(hKey, TEXT("SmCaptionHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_ICON_SPC_X]);
+               RegSetValueEx(hKey, TEXT("IconSpacing"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_ICON_SPC_Y]);
+               RegSetValueEx(hKey, TEXT("IconVerticalSpacing"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_MENU_SIZE_X]);
+               RegSetValueEx(hKey, TEXT("MenuWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_MENU_Y]);
+               RegSetValueEx(hKey, TEXT("MenuHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_SCROLL_X]);
+               RegSetValueEx(hKey, TEXT("ScrollWidth"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), -15 * theme->Size[SIZE_SCROLL_Y]);
+               RegSetValueEx(hKey, TEXT("ScrollHeight"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+               wsprintf(clText, TEXT("%d"), theme->Size[SIZE_ICON_X]);
+               RegSetValueEx(hKey, TEXT("Shell Icon Size"), 0, REG_SZ, (BYTE *)clText, sizeof(clText));
+
+               RegCloseKey(hKey);
+       }
+
+       /* Effects, save only when needed: */
+       /* FIXME: XP seems to use grayed checkboxes to reflect differences between menu and tooltips settings
+        * Just keep them in sync for now.
+        */
+       theme->Effects.bTooltipAnimation  = theme->Effects.bMenuAnimation;
+       theme->Effects.bTooltipFade        = theme->Effects.bMenuFade;
+       SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, theme->Effects.bDragFullWindows, NULL, SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
+       UPDATE_USERPREF(KEYBOARDCUES, &theme->Effects.bKeyboardCues);
+       //UPDATE_USERPREF(ACTIVEWINDOWTRACKING, &theme->Effects.bActiveWindowTracking);
+       //UPDATE_USERPREF(MENUANIMATION, &theme->Effects.bMenuAnimation);
+       //UPDATE_USERPREF(COMBOBOXANIMATION, &theme->Effects.bComboBoxAnimation);
+       //UPDATE_USERPREF(LISTBOXSMOOTHSCROLLING, &theme->Effects.bListBoxSmoothScrolling);
+       //UPDATE_USERPREF(GRADIENTCAPTIONS, &theme->Effects.bGradientCaptions);
+       //UPDATE_USERPREF(ACTIVEWNDTRKZORDER, &theme->Effects.bActiveWndTrkZorder);
+       //UPDATE_USERPREF(HOTTRACKING, &theme->Effects.bHotTracking);
+       UPDATE_USERPREF(MENUFADE, &theme->Effects.bMenuFade);
+       //UPDATE_USERPREF(SELECTIONFADE, &theme->Effects.bSelectionFade);
+       UPDATE_USERPREF(TOOLTIPANIMATION, &theme->Effects.bTooltipAnimation);
+       UPDATE_USERPREF(TOOLTIPFADE, &theme->Effects.bTooltipFade);
+       //UPDATE_USERPREF(CURSORSHADOW, &theme->Effects.bCursorShadow);
+       //UPDATE_USERPREF(UIEFFECTS, &theme->Effects.bUiEffects);
+
+       /* Save ThemeId */
+       Result = RegOpenKeyEx(HKEY_CURRENT_USER, g_CPANewSchemes, 0, KEY_ALL_ACCESS, &hKey);
+       if (Result == ERROR_SUCCESS)
+       {
+               if (ThemeId == -1)
+                       clText[0] = TEXT('\0');
+               else
+                       lstrcpy(clText, g_ThemeTemplates[ThemeId].strKeyName);
+               RegSetValueEx(hKey, g_SelectedStyle, 0, REG_SZ, (BYTE *)clText, (lstrlen(clText) + 1) * sizeof(TCHAR));
+               RegCloseKey(hKey);
+       }
+}
+
+BOOL SaveTheme(THEME* theme, LPCTSTR strLegacyName)
+{
+       /* FIXME: implement */
+       return FALSE;
+}
+
+INT LoadThemeTemplates(LPTSTR pszSelectedStyle)
+{
+       HKEY hkNewSchemes, hkScheme, hkSizes, hkSize;
+       FILETIME ftLastWriteTime;
+       DWORD dwLength, dwType;
+       DWORD dwDisposition;
+       INT iStyle, iSize, iTemplateIndex;
+       INT Result;
+
+       lstrcpy(pszSelectedStyle, TEXT(""));
+
+       iTemplateIndex = 0;
+       Result = RegCreateKeyEx(HKEY_CURRENT_USER, g_CPANewSchemes, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkNewSchemes, &dwDisposition);
+       if (Result == ERROR_SUCCESS)
+       {
+               /* First find out the currently selected template */
+               dwLength = 4 * sizeof(TCHAR);
+               RegQueryValueEx(hkNewSchemes, g_SelectedStyle, NULL, &dwType, (LPBYTE)pszSelectedStyle, &dwLength);
+
+               /* Check if already loaded */
+               if (g_TemplateLoaded)
+               {
+                       RegCloseKey(hkNewSchemes);
+                       return g_TemplateCount;
+               }
+
+               iStyle = 0;
+               dwLength = MAX_TEMPLATENAMELENTGH;
+               while((RegEnumKeyEx(hkNewSchemes, iStyle, g_ThemeTemplates[iTemplateIndex].strKeyName, &dwLength,
+                                                       NULL, NULL, NULL, &ftLastWriteTime) == ERROR_SUCCESS) && (iTemplateIndex < MAX_TEMPLATES))
+               {
+                       /* is it really a template or one of the other entries */
+                       if (dwLength <= 4)
+                       {
+                               if (RegOpenKeyEx(hkNewSchemes, g_ThemeTemplates[iTemplateIndex].strKeyName, 0, KEY_READ, &hkScheme) == ERROR_SUCCESS)
+                               {
+                                       if (RegOpenKeyEx(hkScheme, TEXT("Sizes"), 0, KEY_READ, &hkSizes) == ERROR_SUCCESS)
+                                       {
+                                               iSize = 0;
+                                               dwLength = 3;
+                                               while((RegEnumKeyEx(hkSizes, iSize, g_ThemeTemplates[iTemplateIndex].strSizeName, &dwLength,
+                                                                                       NULL, NULL, NULL, &ftLastWriteTime) == ERROR_SUCCESS) && (iSize <= 4))
+                                               {
+                                                       if(RegOpenKeyEx(hkSizes, g_ThemeTemplates[iTemplateIndex].strSizeName, 0, KEY_READ, &hkSize) == ERROR_SUCCESS)
+                                                       {
+                                                               dwLength = MAX_TEMPLATENAMELENTGH;
+                                                               RegQueryValueEx(hkSize, TEXT("DisplayName"), NULL, &dwType, (LPBYTE)&g_ThemeTemplates[iTemplateIndex].strDisplayName, &dwLength);
+                                                               dwLength = MAX_TEMPLATENAMELENTGH;
+                                                               RegQueryValueEx(hkSize, TEXT("LegacyName"), NULL, &dwType, (LPBYTE)&g_ThemeTemplates[iTemplateIndex].strLegacyName, &dwLength);
+                                                               RegCloseKey(hkSize);
+                                                       }
+                                                       iSize++;
+                                                       iTemplateIndex++;
+                                                       dwLength = 3;
+                                               }
+                                               RegCloseKey(hkSizes);
+                                       }
+                                       RegCloseKey(hkScheme);
+                               }
+                       }
+                       iStyle++;
+                       dwLength = MAX_TEMPLATENAMELENTGH;
+               }
+               RegCloseKey(hkNewSchemes);
+               g_TemplateLoaded = TRUE;
+               g_TemplateCount = iTemplateIndex;
+       }
+       return iTemplateIndex;
+}
diff --git a/reactos/dll/cpl/desk/theme.h b/reactos/dll/cpl/desk/theme.h
new file mode 100644 (file)
index 0000000..8a5f856
--- /dev/null
@@ -0,0 +1,89 @@
+/* Some definitions for theme */
+#define SIZE_BORDER_X 0
+#define SIZE_BORDER_Y 1
+#define SIZE_CAPTION_Y 2
+#define SIZE_ICON_X 3
+#define SIZE_ICON_Y 4
+#define SIZE_ICON_SPC_X 5
+#define SIZE_ICON_SPC_Y 6
+#define SIZE_MENU_SIZE_X 7
+#define SIZE_MENU_Y 8
+#define SIZE_SCROLL_X 9
+#define SIZE_SCROLL_Y 10
+#define SIZE_SMCAPTION_Y 11
+#define SIZE_EDGE_X 12
+#define SIZE_EDGE_Y 13
+#define SIZE_FRAME_Y 14
+#define SIZE_MENU_CHECK_X 15
+#define SIZE_MENU_CHECK_Y 16
+#define SIZE_MENU_SIZE_Y 17
+#define SIZE_SIZE_X 18
+#define SIZE_SIZE_Y 19
+
+#define FONT_CAPTION 0
+#define FONT_SMCAPTION 1
+#define FONT_HILIGHT 2
+#define FONT_MENU 2
+#define FONT_ICON 3
+#define FONT_INFO 4
+#define FONT_DIALOG 5
+
+#define NUM_ELEMENTS 22
+#define NUM_FONTS 6
+#define NUM_SIZES 20
+#define NUM_COLORS 31
+#define MAX_TEMPLATES 50
+#define MAX_COLORNAMELENGTH 30
+#define MAX_TEMPLATENAMELENTGH 80
+
+/* Some typedefs for theme */
+
+/* Most (but not all) fields below correspond to HKCU\Control Panel\Desktop\UserPreferencesMask */
+typedef struct
+{
+       BOOL bActiveWindowTracking;
+       BOOL bMenuAnimation;
+       BOOL bComboBoxAnimation;
+       BOOL bListBoxSmoothScrolling;
+       BOOL bGradientCaptions;
+       BOOL bKeyboardCues;
+       BOOL bActiveWndTrkZorder;
+       BOOL bHotTracking;
+       BOOL bMenuFade;
+       BOOL bSelectionFade;
+       BOOL bTooltipAnimation;
+       BOOL bTooltipFade;
+       BOOL bCursorShadow;
+       BOOL bUiEffects;
+       BOOL bFontSmoothing;
+       BOOL bDragFullWindows;
+       UINT uiFontSmoothingType;
+} EFFECTS;
+
+typedef struct
+{
+       COLORREF crColor[NUM_COLORS];
+       LOGFONT lfFont[NUM_FONTS];
+       UINT64 Size[NUM_SIZES];
+       BOOL bFlatMenus;
+       EFFECTS Effects;
+} THEME;
+
+typedef struct
+{
+       TCHAR strKeyName[4];
+       TCHAR strSizeName[4];
+       TCHAR strDisplayName[MAX_TEMPLATENAMELENTGH];
+       TCHAR strLegacyName[MAX_TEMPLATENAMELENTGH];
+} THEME_PRESET;
+
+extern const TCHAR g_RegColorNames[NUM_COLORS][MAX_COLORNAMELENGTH];
+extern const INT g_SizeMetric[NUM_SIZES];
+extern THEME_PRESET g_ThemeTemplates[MAX_TEMPLATES];
+
+/* prototypes for theme.c */
+VOID LoadCurrentTheme(THEME* theme);
+BOOL LoadThemeFromReg(THEME* theme, INT ThemeId);
+VOID ApplyTheme(THEME* theme, INT ThemeId);
+BOOL SaveTheme(THEME* theme, LPCTSTR strLegacyName);
+INT LoadThemeTemplates(LPTSTR pszSelectedStyle);