[KSPROXY]
[reactos.git] / reactos / dll / cpl / desk / advappdlg.c
index 2584bb0..f262c49 100644 (file)
-/* $Id: advappdlg.c 24836 2007-02-12 03:12:56Z tkreuzer $\r
- *\r
- * COPYRIGHT:       See COPYING in the top level directory\r
- * PROJECT:         ReactOS Display Control Panel\r
- * FILE:            dll/cpl/desk/advappdlg.c\r
- * PURPOSE:         Advanced appearance dialog\r
- * \r
- * PROGRAMMER:     Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de)\r
- * \r
- */\r
-\r
-#include "desk.h"\r
-#include "appearance.h"\r
-#include "preview.h"\r
-\r
-\r
-\r
-/* Draw the current color on the color picker buttons */\r
-static VOID\r
-UpdateButtonColor(HWND hwndDlg, GLOBALS* g, INT ID, INT nButton, INT nColor)\r
-{\r
-       HDC hdcColorButton, hdcCompat;\r
-       RECT rect;\r
-       HBRUSH hbrush;\r
-       HWND hwndColorButton;\r
-       COLORREF crColor = g->ThemeAdv.crColor[nColor];\r
-       HGDIOBJ hgdiTmp;\r
-\r
-       if (nColor != -1)\r
-       {\r
-               /* Create a DC to draw on */\r
-               hwndColorButton = GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B);\r
-               hdcColorButton = GetDC(hwndColorButton);\r
-               hdcCompat = CreateCompatibleDC(hdcColorButton);\r
-               ReleaseDC(hwndColorButton, hdcColorButton);\r
-\r
-               /* Select the button image to it */\r
-               hgdiTmp = SelectObject(hdcCompat, g->hbmpColor[nButton]);\r
-\r
-               /* Create a brush and draw the rectangle */\r
-               rect.left = 2;\r
-               rect.top = 2;\r
-               rect.right = 22;\r
-               rect.bottom = 13;\r
-               hbrush = CreateSolidBrush(crColor);\r
-               FillRect(hdcCompat, &rect, hbrush);\r
-               DeleteObject(hbrush);\r
-\r
-               /* hdcCompat is not needed anymore */\r
-               SelectObject(hdcCompat,hgdiTmp);\r
-               DeleteDC(hdcCompat);\r
-\r
-               SendDlgItemMessage(hwndDlg, ID, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[nButton]);\r
-               EnableWindow(GetDlgItem(hwndDlg, ID), TRUE);\r
-       }\r
-       else\r
-       {\r
-               SendDlgItemMessage(hwndDlg, ID, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)NULL);\r
-               EnableWindow(GetDlgItem(hwndDlg, ID), FALSE);\r
-       }\r
-}\r
-\r
-\r
-/* Create the basic bitmaps for the color picker buttons */\r
-static VOID\r
-InitColorButtons(HWND hwndDlg, GLOBALS* g)\r
-{\r
-       INT i;\r
-       HDC hdcColorButton, hdcCompat;\r
-       RECT rect;\r
-       HBRUSH hbrush;\r
-       HPEN hPen;\r
-       HWND hwndColorButton;\r
-       HGDIOBJ hgdiTemp;\r
-\r
-       const POINT Points[3] = {{29,6},{33,6},{31,8}};\r
-\r
-       hwndColorButton = GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B);\r
-       hdcColorButton = GetDC(hwndColorButton);\r
-       for (i = 0; i <= 2; i++)\r
-       {\r
-               /* Create a DC to draw on */\r
-               hdcCompat = CreateCompatibleDC(hdcColorButton); \r
-\r
-               /* Create the button image */\r
-               g->hbmpColor[i] = CreateCompatibleBitmap(hdcColorButton, 36, 15);\r
-\r
-               /* Select the button image to the DC */\r
-               hgdiTemp = SelectObject(hdcCompat, g->hbmpColor[i]); \r
-\r
-               /* Draw the buttons background color */\r
-               rect.left = 0;\r
-               rect.top = 0;\r
-               rect.right = 36;\r
-               rect.bottom = 15;\r
-               hbrush = CreateSolidBrush(g->crCOLOR_BTNFACE);\r
-               FillRect(hdcCompat, &rect, hbrush);\r
-               DeleteObject(hbrush);\r
-\r
-               /* Draw the rectangle */\r
-               rect.left = 1;\r
-               rect.top = 1;\r
-               rect.right = 23;\r
-               rect.bottom = 14;\r
-               hbrush = CreateSolidBrush(g->crCOLOR_BTNTEXT);\r
-               FillRect(hdcCompat, &rect, hbrush);\r
-               DeleteObject(hbrush);\r
-\r
-               /* Draw left side of line */\r
-               hPen = CreatePen(PS_SOLID, 1, g->crCOLOR_BTNSHADOW);\r
-               SelectObject(hdcCompat, hPen);\r
-               MoveToEx(hdcCompat, 26, 1, NULL);\r
-               LineTo(hdcCompat, 26, 14);\r
-               SelectObject(hdcCompat, GetStockObject(BLACK_PEN));\r
-               DeleteObject(hPen);\r
-\r
-               /* Draw right side of line */\r
-               hPen = CreatePen(PS_SOLID, 1, g->crCOLOR_BTNHIGHLIGHT);\r
-               SelectObject(hdcCompat,hPen);\r
-               MoveToEx(hdcCompat, 27, 1, NULL);\r
-               LineTo(hdcCompat, 27, 14);\r
-               SelectObject(hdcCompat, GetStockObject(BLACK_PEN));\r
-               DeleteObject(hPen);\r
-\r
-               /* Draw triangle */\r
-               hPen = CreatePen(PS_SOLID, 1, g->crCOLOR_BTNTEXT);\r
-               hbrush = CreateSolidBrush(g->crCOLOR_BTNTEXT);\r
-               SelectObject(hdcCompat, hPen);\r
-               SelectObject(hdcCompat, hbrush);\r
-               SetPolyFillMode(hdcCompat, WINDING);\r
-\r
-               /* FIXME: HACK, see Points definition */\r
-               Polygon(hdcCompat, Points, 3);\r
-\r
-               /* Cleanup */\r
-               SelectObject(hdcCompat,hgdiTemp);\r
-               DeleteDC(hdcCompat);\r
-               DeleteObject(hPen);\r
-               DeleteObject(hbrush);\r
-       }\r
-\r
-       ReleaseDC(hwndColorButton, hdcColorButton);\r
-\r
-       /* Set the images of the buttons */\r
-       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[0]);\r
-       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_COLOR2_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[1]);\r
-       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTCOLOR_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[2]);\r
-}\r
-\r
-\r
-/* This is the callback function to add the installed fonts to the font combo */\r
-static int CALLBACK\r
-EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, DWORD dwFontType, LPARAM lParam)\r
-{\r
-       /* Don't enumerate more than 100 fonts */\r
-       if (SendMessage((HWND)lParam, CB_GETCOUNT, 0, 0) >= 100)\r
-               return 0;\r
-\r
-       /* Only add the string once */\r
-       if (SendMessage((HWND)lParam, CB_FINDSTRINGEXACT, -1, (WPARAM)&(lpelfe->elfLogFont.lfFaceName)) != CB_ERR)\r
-               return 2;\r
-\r
-       SendMessage((HWND)lParam, CB_ADDSTRING, 0, (WPARAM)&(lpelfe->elfLogFont.lfFaceName));\r
-\r
-       return 1;\r
-}\r
-\r
-\r
-/* Update all the controls with the current values for the selected screen element */\r
-static VOID\r
-UpdateControls(HWND hwndDlg, GLOBALS *g)\r
-{\r
-       INT iElement;\r
-       HDC hdcDlg;\r
-\r
-       iElement = g->CurrentElement;\r
-\r
-       /* First enable / disable the controls */\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E), (g_Assignment[iElement].Size != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), (g_Assignment[iElement].Size != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_T), (g_Assignment[iElement].Size != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_T), (g_Assignment[iElement].Color1 != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR2_T), (g_Assignment[iElement].Color2 != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_T), (g_Assignment[iElement].Font != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_C), (g_Assignment[iElement].Font != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_T), (g_Assignment[iElement].Font != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E), (g_Assignment[iElement].Font != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTCOLOR_T), (g_Assignment[iElement].FontColor != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD), (g_Assignment[iElement].Font != -1));\r
-       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC), (g_Assignment[iElement].Font != -1));\r
-\r
-       /* Update the colors of the color buttons */\r
-       UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_COLOR1_B, 0, g_Assignment[iElement].Color1);\r
-       UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_COLOR2_B, 1, g_Assignment[iElement].Color2);\r
-       UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_FONTCOLOR_B, 2, g_Assignment[iElement].FontColor);\r
-\r
-       if (g_Assignment[iElement].Size != -1)\r
-               SetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, g->ThemeAdv.Size[g_Assignment[iElement].Size], FALSE);\r
-       else\r
-               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, TEXT(""));\r
-\r
-       hdcDlg = GetDC(hwndDlg);\r
-       if (g_Assignment[iElement].Font != -1)\r
-       {\r
-               LOGFONT lfFont = g->ThemeAdv.lfFont[g_Assignment[iElement].Font];\r
-\r
-               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, lfFont.lfFaceName);\r
-               SetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, -MulDiv(g->ThemeAdv.lfFont[g_Assignment[iElement].Font].lfHeight, 72, GetDeviceCaps(hdcDlg, LOGPIXELSY)),FALSE);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, CB_FINDSTRINGEXACT, -1, (WPARAM)lfFont.lfFaceName);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_SETCHECK, g->ThemeAdv.lfFont[g_Assignment[iElement].Font].lfWeight == FW_BOLD?1:0, 0);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_SETCHECK, g->ThemeAdv.lfFont[g_Assignment[iElement].Font].lfItalic, 0);\r
-       }\r
-       else\r
-       {\r
-               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, NULL);\r
-               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, NULL);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_SETCHECK, 0, 0);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_SETCHECK, 0, 0);\r
-       }\r
-\r
-       ReleaseDC(hwndDlg, hdcDlg);\r
-}\r
-\r
-\r
-static VOID\r
-SaveCurrentValues(HWND hwndDlg, GLOBALS *g)\r
-{\r
-       BOOL bTranslated;\r
-       HDC hdcDlg = GetDC(hwndDlg);\r
-\r
-       if (g_Assignment[g->CurrentElement].Size != -1)\r
-       {\r
-               g->ThemeAdv.Size[g_Assignment[g->CurrentElement].Size] = GetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, &bTranslated, FALSE);\r
-       }\r
-\r
-       if (g_Assignment[g->CurrentElement].Font != -1)\r
-       {\r
-               g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight = -MulDiv(GetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, &bTranslated, FALSE), GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);\r
-               g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight = (SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0) == 1)?FW_BOLD:FW_NORMAL;\r
-               g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);\r
-               GetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName, LF_FACESIZE * sizeof(TCHAR));\r
-       }\r
-\r
-       ReleaseDC(hwndDlg, hdcDlg);\r
-}\r
-\r
-\r
-/* Select a color using a color picker */\r
-static BOOL\r
-GetColor(HWND hwndDlg, GLOBALS* g, INT nButton)\r
-{\r
-       CHOOSECOLOR cc;\r
-       COLORREF crCustom[16] = { 0 };\r
-       COLORREF crColor;\r
-       INT ID = 0;\r
-       INT ColorIndex = 0;\r
-\r
-       /* Get the color index from the element index and button number */\r
-       switch (nButton)\r
-       {\r
-               case 0:\r
-                       ColorIndex = g_Assignment[g->CurrentElement].Color1;\r
-                       ID = IDC_ADVAPPEARANCE_COLOR1_B;\r
-                       break;\r
-\r
-               case 1:\r
-                       ColorIndex = g_Assignment[g->CurrentElement].Color2;\r
-                       ID = IDC_ADVAPPEARANCE_COLOR2_B;\r
-                       break;\r
-\r
-               case 2:\r
-                       ColorIndex = g_Assignment[g->CurrentElement].FontColor;\r
-                       ID = IDC_ADVAPPEARANCE_FONTCOLOR_B;\r
-                       break;\r
-       }\r
-\r
-       crColor = g->ThemeAdv.crColor[ColorIndex];\r
-\r
-       /* Prepare cc structure */\r
-       cc.lStructSize = sizeof(CHOOSECOLOR);\r
-       cc.hwndOwner = hwndDlg;\r
-       cc.hInstance = NULL;\r
-       cc.rgbResult = crColor;\r
-       cc.lpCustColors = crCustom;\r
-       cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;\r
-       cc.lCustData = 0;\r
-       cc.lpfnHook = NULL;\r
-       cc.lpTemplateName = NULL;\r
-\r
-       /* Create the colorpicker */\r
-       if (ChooseColor(&cc))\r
-       {\r
-               g->ThemeAdv.crColor[ColorIndex] = cc.rgbResult;\r
-               if (crColor != cc.rgbResult)\r
-               {\r
-                       UpdateButtonColor(hwndDlg, g, ID, nButton, ColorIndex);\r
-                       return TRUE;\r
-               }\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-\r
-/* Initialize the advanced appearance dialog */\r
-static VOID\r
-AdvAppearanceDlg_Init(HWND hwndDlg, GLOBALS *g)\r
-{\r
-       INT i, iElement, iListIndex, iDeskIndex = 0;\r
-       TCHAR tstrText[80];\r
-       LOGFONT lfFont;\r
-       LOGFONT lfButtonFont;\r
-       HFONT hMyFont;\r
-       HDC hScreenDC;\r
-       TCHAR Size[4];\r
-\r
-       /* Copy the current theme values */\r
-       g->ThemeAdv = g->Theme;\r
-\r
-       /* Add the elements to the combo */\r
-       for (iElement = 0; iElement < NUM_ELEMENTS; iElement++)\r
-       {\r
-               LoadString(hApplet, IDS_ELEMENT_1 + iElement, (LPTSTR)&tstrText, 79);\r
-               iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_ADDSTRING, 0, (LPARAM)&tstrText);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETITEMDATA, (WPARAM)iListIndex, (LPARAM)iElement);\r
-       }\r
-\r
-       /* Get the list index of the desktop element */\r
-       for (iListIndex = 0; iListIndex < NUM_ELEMENTS; iListIndex++)\r
-       {\r
-               iElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);\r
-               if (iElement == 0)\r
-               {\r
-                       iDeskIndex = iListIndex;\r
-                       break;\r
-               }\r
-       }\r
-\r
-       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETCURSEL, iDeskIndex, 0);\r
-\r
-       /* Set colors for the color buttons */\r
-       g->crCOLOR_BTNFACE = g->Theme.crColor[COLOR_BTNFACE];\r
-       g->crCOLOR_BTNTEXT = g->Theme.crColor[COLOR_BTNTEXT];\r
-       g->crCOLOR_BTNSHADOW = g->Theme.crColor[COLOR_BTNSHADOW];\r
-       g->crCOLOR_BTNHIGHLIGHT = g->Theme.crColor[COLOR_BTNHIGHLIGHT];\r
-\r
-       /* Create font for bold button */\r
-       lfButtonFont = g->Theme.lfFont[FONT_DIALOG];\r
-       lfButtonFont.lfWeight = FW_BOLD;\r
-       lfButtonFont.lfItalic = FALSE;\r
-       hMyFont = CreateFontIndirect(&lfButtonFont);\r
-       if (hMyFont)\r
-       {\r
-               if (g->hBoldFont)\r
-                       DeleteObject(g->hBoldFont);\r
-\r
-               g->hBoldFont = hMyFont;\r
-       }\r
-\r
-       /* Create font for italic button */\r
-       lfButtonFont.lfWeight = FW_REGULAR;\r
-       lfButtonFont.lfItalic = TRUE;\r
-       hMyFont = CreateFontIndirect(&lfButtonFont);\r
-       if (hMyFont)\r
-       {\r
-               if (g->hItalicFont)\r
-                       DeleteObject(g->hItalicFont);\r
-\r
-               g->hItalicFont = hMyFont;\r
-       }\r
-\r
-       /* Set the fonts for the font style buttons */\r
-       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, WM_SETFONT, (WPARAM)g->hBoldFont, (LPARAM)TRUE);\r
-       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, WM_SETFONT, (WPARAM)g->hItalicFont, (LPARAM)TRUE);\r
-\r
-       /* Draw Bitmaps for the colorbuttons */\r
-       InitColorButtons(hwndDlg, g);\r
-\r
-       /* Make the UpDown control count correctly */\r
-       SendMessage (GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), UDM_SETRANGE, 0L, MAKELONG (200, 1));\r
-\r
-       /* Fill font selection combo */\r
-       lfFont.lfCharSet = DEFAULT_CHARSET;\r
-       lfFont.lfFaceName[0] = (TCHAR)0;\r
-       lfFont.lfPitchAndFamily = 0;\r
-       hScreenDC = GetDC(0);\r
-       EnumFontFamiliesEx(hScreenDC, &lfFont, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_C), 0);\r
-       ReleaseDC(0, hScreenDC);\r
-\r
-       /* Fill font size combo */\r
-       for (i = 6; i <= 24; i++)\r
-       {\r
-               SetDlgItemInt(hwndDlg, IDC_CONVERT, i, FALSE);\r
-               GetDlgItemText(hwndDlg, IDC_CONVERT, (LPTSTR)&Size, 3);\r
-               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, CB_ADDSTRING, 0, (LPARAM)&Size);\r
-       }\r
-\r
-       /* Update the controls */\r
-       iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETCURSEL, 0, 0);\r
-       g->CurrentElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);\r
-       UpdateControls(hwndDlg, g);\r
-}\r
-\r
-\r
-static VOID\r
-AdvAppearanceDlg_CleanUp(HWND hwndDlg, GLOBALS* g)\r
-{\r
-       DeleteObject(g->hBoldFont);\r
-       DeleteObject(g->hItalicFont);\r
-}\r
-\r
-\r
-static VOID\r
-SelectComboByElement(HWND hwnd, INT id, LPARAM lParam)\r
-{\r
-    INT nCount;\r
-    INT i;\r
-\r
-    nCount = SendDlgItemMessage(hwnd, id, CB_GETCOUNT, 0, 0);\r
-    if (nCount == CB_ERR)\r
-        return;\r
-\r
-    for (i = 0; i < nCount; i++)\r
-    {\r
-        if (SendDlgItemMessage(hwnd, id, CB_GETITEMDATA, (WPARAM)i, 0) == lParam)\r
-        {\r
-            SendDlgItemMessage(hwnd, id, CB_SETCURSEL, (WPARAM)i, 0);\r
-            break;\r
-        }\r
-    }\r
-}\r
-\r
-\r
-INT_PTR CALLBACK\r
-AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
-{\r
-       INT iListIndex;\r
-       GLOBALS* g;\r
-\r
-       g = (GLOBALS*)GetWindowLongPtr(hwndDlg, DWLP_USER);\r
-\r
-       switch (uMsg)\r
-       {\r
-               case WM_INITDIALOG:\r
-                       g = (GLOBALS*)lParam;\r
-                       SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);\r
-                       AdvAppearanceDlg_Init(hwndDlg, g);\r
-                       break;\r
-\r
-               case WM_DESTROY:\r
-                       AdvAppearanceDlg_CleanUp(hwndDlg, g);\r
-                       break;\r
-\r
-               case WM_COMMAND:\r
-                       switch(LOWORD(wParam))\r
-                       {\r
-                               case IDOK:\r
-                                       SaveCurrentValues(hwndDlg, g);\r
-                                       EndDialog(hwndDlg, 0);\r
-                                       break;\r
-\r
-                               case IDCANCEL:\r
-                                       g->ThemeAdv = g->Theme;\r
-                                       EndDialog(hwndDlg, 0);\r
-                                       break;\r
-\r
-                               case IDC_APPEARANCE_PREVIEW:\r
-                                       SaveCurrentValues(hwndDlg, g);\r
-                                       SelectComboByElement(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, lParam);\r
-                                       g->CurrentElement = (INT)lParam;\r
-                                       UpdateControls(hwndDlg, g);\r
-                                       break;\r
-\r
-                               case IDC_ADVAPPEARANCE_ELEMENT:\r
-                                       if (HIWORD(wParam) == CBN_SELCHANGE)\r
-                                       {\r
-                                               SaveCurrentValues(hwndDlg, g);\r
-                                               iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETCURSEL, 0, 0);\r
-                                               g->CurrentElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);\r
-                                               UpdateControls(hwndDlg, g);\r
-                                       }\r
-                                       break;\r
-\r
-                               case IDC_ADVAPPEARANCE_SIZE_E:\r
-                                       if (g && HIWORD(wParam) == EN_CHANGE)\r
-                                       {\r
-                                               int i = (int)LOWORD(SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD, UDM_GETPOS,0,0L));\r
-\r
-                                               switch (g->CurrentElement)\r
-                                               {\r
-                                                       case IDX_INACTIVE_CAPTION:\r
-                                                       case IDX_ACTIVE_CAPTION:\r
-                                                       case IDX_CAPTION_BUTTON:\r
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCYCAPTION, 0, i);\r
-                                                               break;\r
-\r
-                                                       case IDX_MENU:\r
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCYMENU, 0, i);\r
-                                                               break;\r
-\r
-                                                       case IDX_SCROLLBAR:\r
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCXSCROLLBAR, 0, i);\r
-                                                               break;\r
-\r
-                                                       case IDX_INACTIVE_BORDER:\r
-                                                       case IDX_ACTIVE_BORDER:\r
-                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCYSIZEFRAME, 0, i);\r
-                                                               break;\r
-                                               }\r
-                                       }\r
-                                       break;\r
-\r
-                               case IDC_ADVAPPEARANCE_COLOR1_B:\r
-                                       GetColor(hwndDlg, g, 0);\r
-                                       break;\r
-\r
-                               case IDC_ADVAPPEARANCE_COLOR2_B:\r
-                                       GetColor(hwndDlg, g, 1);\r
-                                       break;\r
-\r
-                               case IDC_ADVAPPEARANCE_FONTCOLOR_B:\r
-                                       GetColor(hwndDlg, g, 2);\r
-                                       break;\r
-\r
-                               default:\r
-                                       return FALSE;\r
-                       }\r
-                       break;\r
-\r
-               default:\r
-                       return FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
+/* $Id: advappdlg.c 24836 2007-02-12 03:12:56Z tkreuzer $
+ *
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS Display Control Panel
+ * FILE:            dll/cpl/desk/advappdlg.c
+ * PURPOSE:         Advanced appearance dialog
+ *
+ * PROGRAMMER:     Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de)
+ *
+ */
+
+#include "desk.h"
+#include "appearance.h"
+#include "preview.h"
+
+
+
+/* Draw the current color on the color picker buttons */
+static VOID
+UpdateButtonColor(HWND hwndDlg, GLOBALS* g, INT ID, INT nButton, INT nColor)
+{
+       HDC hdcColorButton, hdcCompat;
+       RECT rect;
+       HBRUSH hbrush;
+       HWND hwndColorButton;
+       HGDIOBJ hgdiTmp;
+
+       if (nColor != -1)
+       {
+               /* Create a DC to draw on */
+               hwndColorButton = GetDlgItem(hwndDlg, ID);
+               hdcColorButton = GetDC(hwndColorButton);
+               hdcCompat = CreateCompatibleDC(hdcColorButton);
+               ReleaseDC(hwndColorButton, hdcColorButton);
+
+               /* Select the button image to it */
+               hgdiTmp = SelectObject(hdcCompat, g->hbmpColor[nButton]);
+
+               /* Create a brush and draw the rectangle */
+               rect.left = 2;
+               rect.top = 2;
+               rect.right = 22;
+               rect.bottom = 13;
+               hbrush = CreateSolidBrush(g->ThemeAdv.crColor[nColor]);
+               FillRect(hdcCompat, &rect, hbrush);
+               DeleteObject(hbrush);
+
+               /* hdcCompat is not needed anymore */
+               SelectObject(hdcCompat,hgdiTmp);
+               DeleteDC(hdcCompat);
+
+               SendDlgItemMessage(hwndDlg, ID, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[nButton]);
+               EnableWindow(GetDlgItem(hwndDlg, ID), TRUE);
+       }
+       else
+       {
+               SendDlgItemMessage(hwndDlg, ID, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)NULL);
+               EnableWindow(GetDlgItem(hwndDlg, ID), FALSE);
+       }
+}
+
+
+/* Create the basic bitmaps for the color picker buttons */
+static VOID
+InitColorButtons(HWND hwndDlg, GLOBALS* g)
+{
+       INT i;
+       HDC hdcColorButton, hdcCompat;
+       RECT rect;
+       HBRUSH hbrush;
+       HPEN hPen;
+       HWND hwndColorButton;
+       HGDIOBJ hgdiTemp;
+
+       const POINT Points[3] = {{29,6},{33,6},{31,8}};
+
+       hwndColorButton = GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B);
+       hdcColorButton = GetDC(hwndColorButton);
+       for (i = 0; i <= 2; i++)
+       {
+               /* Create a DC to draw on */
+               hdcCompat = CreateCompatibleDC(hdcColorButton);
+
+               /* Create the button image */
+               g->hbmpColor[i] = CreateCompatibleBitmap(hdcColorButton, 36, 15);
+
+               /* Select the button image to the DC */
+               hgdiTemp = SelectObject(hdcCompat, g->hbmpColor[i]);
+
+               /* Draw the buttons background color */
+               rect.left = 0;
+               rect.top = 0;
+               rect.right = 36;
+               rect.bottom = 15;
+               hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
+               FillRect(hdcCompat, &rect, hbrush);
+               DeleteObject(hbrush);
+
+               /* Draw the rectangle */
+               rect.left = 1;
+               rect.top = 1;
+               rect.right = 23;
+               rect.bottom = 14;
+               hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNTEXT));
+               FillRect(hdcCompat, &rect, hbrush);
+               DeleteObject(hbrush);
+
+               /* Draw left side of line */
+               hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
+               SelectObject(hdcCompat, hPen);
+               MoveToEx(hdcCompat, 26, 1, NULL);
+               LineTo(hdcCompat, 26, 14);
+               SelectObject(hdcCompat, GetStockObject(BLACK_PEN));
+               DeleteObject(hPen);
+
+               /* Draw right side of line */
+               hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
+               SelectObject(hdcCompat,hPen);
+               MoveToEx(hdcCompat, 27, 1, NULL);
+               LineTo(hdcCompat, 27, 14);
+               SelectObject(hdcCompat, GetStockObject(BLACK_PEN));
+               DeleteObject(hPen);
+
+               /* Draw triangle */
+               hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
+               hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNTEXT));
+               SelectObject(hdcCompat, hPen);
+               SelectObject(hdcCompat, hbrush);
+               SetPolyFillMode(hdcCompat, WINDING);
+
+               /* FIXME: HACK, see Points definition */
+               Polygon(hdcCompat, Points, 3);
+
+               /* Cleanup */
+               SelectObject(hdcCompat,hgdiTemp);
+               DeleteDC(hdcCompat);
+               DeleteObject(hPen);
+               DeleteObject(hbrush);
+       }
+
+       ReleaseDC(hwndColorButton, hdcColorButton);
+
+       /* Set the images of the buttons */
+       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[0]);
+       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_COLOR2_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[1]);
+       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTCOLOR_B, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)g->hbmpColor[2]);
+}
+
+
+/* This is the callback function to add the installed fonts to the font combo */
+static int CALLBACK
+EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, DWORD dwFontType, LPARAM lParam)
+{
+       /* Don't enumerate more than 100 fonts */
+       if (SendMessage((HWND)lParam, CB_GETCOUNT, 0, 0) >= 100)
+               return 0;
+
+       /* Only add the string once */
+       if (SendMessage((HWND)lParam, CB_FINDSTRINGEXACT, -1, (WPARAM)&(lpelfe->elfLogFont.lfFaceName)) != CB_ERR)
+               return 2;
+
+       SendMessage((HWND)lParam, CB_ADDSTRING, 0, (WPARAM)&(lpelfe->elfLogFont.lfFaceName));
+
+       return 1;
+}
+
+
+/* Update all the controls with the current values for the selected screen element */
+static VOID
+UpdateControls(HWND hwndDlg, GLOBALS *g)
+{
+       INT iElement;
+       HDC hdcDlg;
+
+       iElement = g->CurrentElement;
+
+       /* First enable / disable the controls */
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E), (g_Assignment[iElement].Size != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), (g_Assignment[iElement].Size != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_T), (g_Assignment[iElement].Size != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_T), (g_Assignment[iElement].Color1 != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR2_T), (g_Assignment[iElement].Color2 != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_T), (g_Assignment[iElement].Font != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_C), (g_Assignment[iElement].Font != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_T), (g_Assignment[iElement].Font != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E), (g_Assignment[iElement].Font != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTCOLOR_T), (g_Assignment[iElement].FontColor != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD), (g_Assignment[iElement].Font != -1));
+       EnableWindow(GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC), (g_Assignment[iElement].Font != -1));
+
+       /* Update the colors of the color buttons */
+       UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_COLOR1_B, 0, g_Assignment[iElement].Color1);
+       UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_COLOR2_B, 1, g_Assignment[iElement].Color2);
+       UpdateButtonColor(hwndDlg, g, IDC_ADVAPPEARANCE_FONTCOLOR_B, 2, g_Assignment[iElement].FontColor);
+
+       if (g_Assignment[iElement].Size != -1)
+               SetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, g->ThemeAdv.Size[g_Assignment[iElement].Size], FALSE);
+       else
+               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, TEXT(""));
+
+       hdcDlg = GetDC(hwndDlg);
+       if (g_Assignment[iElement].Font != -1)
+       {
+               LOGFONT lfFont = g->ThemeAdv.lfFont[g_Assignment[iElement].Font];
+
+               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, lfFont.lfFaceName);
+               SetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, -MulDiv(g->ThemeAdv.lfFont[g_Assignment[iElement].Font].lfHeight, 72, GetDeviceCaps(hdcDlg, LOGPIXELSY)),FALSE);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, CB_FINDSTRINGEXACT, -1, (WPARAM)lfFont.lfFaceName);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_SETCHECK, g->ThemeAdv.lfFont[g_Assignment[iElement].Font].lfWeight == FW_BOLD?1:0, 0);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_SETCHECK, g->ThemeAdv.lfFont[g_Assignment[iElement].Font].lfItalic, 0);
+       }
+       else
+       {
+               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, NULL);
+               SetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, NULL);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_SETCHECK, 0, 0);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_SETCHECK, 0, 0);
+       }
+
+       ReleaseDC(hwndDlg, hdcDlg);
+}
+
+
+static VOID
+SaveCurrentValues(HWND hwndDlg, GLOBALS *g)
+{
+       BOOL bTranslated;
+       HDC hdcDlg = GetDC(hwndDlg);
+
+       if (g_Assignment[g->CurrentElement].Size != -1)
+       {
+               g->ThemeAdv.Size[g_Assignment[g->CurrentElement].Size] = GetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_SIZE_E, &bTranslated, FALSE);
+       }
+
+       if (g_Assignment[g->CurrentElement].Font != -1)
+       {
+               g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfHeight = -MulDiv(GetDlgItemInt(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, &bTranslated, FALSE), GetDeviceCaps(hdcDlg, LOGPIXELSY), 72);
+               g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfWeight = (SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, BM_GETCHECK, 0, 0) == 1)?FW_BOLD:FW_NORMAL;
+               g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfItalic = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, BM_GETCHECK, 0, 0);
+               GetDlgItemText(hwndDlg, IDC_ADVAPPEARANCE_FONT_C, g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font].lfFaceName, LF_FACESIZE * sizeof(TCHAR));
+       }
+
+       ReleaseDC(hwndDlg, hdcDlg);
+}
+
+
+/* Select a color using a color picker */
+static BOOL
+GetColor(HWND hwndDlg, GLOBALS* g, INT nButton)
+{
+       CHOOSECOLOR cc;
+       COLORREF crCustom[16] = { 0 };
+       COLORREF crColor;
+       INT ID = 0;
+       INT ColorIndex = 0;
+
+       /* Get the color index from the element index and button number */
+       switch (nButton)
+       {
+               case 0:
+                       ColorIndex = g_Assignment[g->CurrentElement].Color1;
+                       ID = IDC_ADVAPPEARANCE_COLOR1_B;
+                       break;
+
+               case 1:
+                       ColorIndex = g_Assignment[g->CurrentElement].Color2;
+                       ID = IDC_ADVAPPEARANCE_COLOR2_B;
+                       break;
+
+               case 2:
+                       ColorIndex = g_Assignment[g->CurrentElement].FontColor;
+                       ID = IDC_ADVAPPEARANCE_FONTCOLOR_B;
+                       break;
+       }
+
+       crColor = g->ThemeAdv.crColor[ColorIndex];
+
+       /* Prepare cc structure */
+       cc.lStructSize = sizeof(CHOOSECOLOR);
+       cc.hwndOwner = hwndDlg;
+       cc.hInstance = NULL;
+       cc.rgbResult = crColor;
+       cc.lpCustColors = crCustom;
+       cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
+       cc.lCustData = 0;
+       cc.lpfnHook = NULL;
+       cc.lpTemplateName = NULL;
+
+       /* Create the colorpicker */
+       if (ChooseColor(&cc))
+       {
+               g->ThemeAdv.crColor[ColorIndex] = cc.rgbResult;
+               if (crColor != cc.rgbResult)
+               {
+                       UpdateButtonColor(hwndDlg, g, ID, nButton, ColorIndex);
+                       SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCOLOR, ColorIndex, cc.rgbResult);
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+
+/* Initialize the advanced appearance dialog */
+static VOID
+AdvAppearanceDlg_Init(HWND hwndDlg, GLOBALS *g)
+{
+       INT i, iElement, iListIndex, iDeskIndex = 0;
+       TCHAR tstrText[80];
+       LOGFONT lfFont;
+       LOGFONT lfButtonFont;
+       HFONT hMyFont;
+       HDC hScreenDC;
+       TCHAR Size[4];
+
+       /* Copy the current theme values */
+       g->ThemeAdv = g->Theme;
+
+       /* Add the elements to the combo */
+       for (iElement = 0; iElement < NUM_ELEMENTS; iElement++)
+       {
+               LoadString(hApplet, IDS_ELEMENT_1 + iElement, (LPTSTR)&tstrText, 79);
+               iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_ADDSTRING, 0, (LPARAM)&tstrText);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_SETITEMDATA, (WPARAM)iListIndex, (LPARAM)iElement);
+       }
+
+       /* Get the list index of the desktop element */
+       for (iListIndex = 0; iListIndex < NUM_ELEMENTS; iListIndex++)
+       {
+               iElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);
+               if (iElement == 0)
+               {
+                       iDeskIndex = iListIndex;
+                       break;
+               }
+       }
+
+       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;
+       lfButtonFont.lfItalic = FALSE;
+       hMyFont = CreateFontIndirect(&lfButtonFont);
+       if (hMyFont)
+       {
+               if (g->hBoldFont)
+                       DeleteObject(g->hBoldFont);
+
+               g->hBoldFont = hMyFont;
+       }
+
+       /* Create 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;
+       }
+
+       /* Set the fonts for the font style buttons */
+       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTBOLD, WM_SETFONT, (WPARAM)g->hBoldFont, (LPARAM)TRUE);
+       SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTITALIC, WM_SETFONT, (WPARAM)g->hItalicFont, (LPARAM)TRUE);
+
+       /* Draw Bitmaps for the colorbuttons */
+       InitColorButtons(hwndDlg, g);
+
+       /* Make the UpDown control count correctly */
+       SendMessage (GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD), UDM_SETRANGE, 0L, MAKELONG (200, 1));
+
+       /* Fill font selection combo */
+       lfFont.lfCharSet = DEFAULT_CHARSET;
+       lfFont.lfFaceName[0] = (TCHAR)0;
+       lfFont.lfPitchAndFamily = 0;
+       hScreenDC = GetDC(0);
+       EnumFontFamiliesEx(hScreenDC, &lfFont, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_FONT_C), 0);
+       ReleaseDC(0, hScreenDC);
+
+       /* Fill font size combo */
+       for (i = 6; i <= 24; i++)
+       {
+               wsprintf(Size, TEXT("%d"), i);
+               SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_FONTSIZE_E, CB_ADDSTRING, 0, (LPARAM)&Size);
+       }
+
+       /* Update the controls */
+       iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETCURSEL, 0, 0);
+       g->CurrentElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);
+       UpdateControls(hwndDlg, g);
+}
+
+
+static VOID
+AdvAppearanceDlg_CleanUp(HWND hwndDlg, GLOBALS* g)
+{
+       DeleteObject(g->hBoldFont);
+       DeleteObject(g->hItalicFont);
+}
+
+
+static VOID
+SelectComboByElement(HWND hwnd, INT id, LPARAM lParam)
+{
+    INT nCount;
+    INT i;
+
+    nCount = SendDlgItemMessage(hwnd, id, CB_GETCOUNT, 0, 0);
+    if (nCount == CB_ERR)
+        return;
+
+    for (i = 0; i < nCount; i++)
+    {
+        if (SendDlgItemMessage(hwnd, id, CB_GETITEMDATA, (WPARAM)i, 0) == lParam)
+        {
+            SendDlgItemMessage(hwnd, id, CB_SETCURSEL, (WPARAM)i, 0);
+            break;
+        }
+    }
+}
+
+
+static VOID
+GetSelectedComboText(HWND hwnd, INT id, LPWSTR lpStr)
+{
+    INT nCount;
+
+    nCount = SendDlgItemMessage(hwnd, id, CB_GETCURSEL, 0, 0);
+    if (nCount == CB_ERR)
+    {
+        *lpStr = 0;
+        return;
+    }
+
+    nCount = SendDlgItemMessage(hwnd, id, CB_GETLBTEXT, (WPARAM)nCount, (LPARAM)lpStr);
+    if (nCount == CB_ERR)
+    {
+        *lpStr = 0;
+    }
+}
+
+
+static INT
+GetSelectedComboInt(HWND hwnd, INT id)
+{
+    TCHAR szBuffer[80];
+    INT nCount;
+
+    nCount = SendDlgItemMessage(hwnd, id, CB_GETCURSEL, 0, 0);
+    if (nCount == CB_ERR)
+        return 0;
+
+    nCount = SendDlgItemMessage(hwnd, id, CB_GETLBTEXT, (WPARAM)nCount, (LPARAM)szBuffer);
+    if (nCount == CB_ERR)
+        return 0;
+
+    return _ttoi(szBuffer);
+}
+
+
+static INT
+GetEditedComboInt(HWND hwnd, INT id)
+{
+    INT nCount;
+    BOOL bTranslated;
+
+    nCount = GetDlgItemInt(hwnd, id, &bTranslated, FALSE);
+    if (bTranslated == FALSE)
+        return 12;
+
+    return nCount;
+}
+
+
+
+INT_PTR CALLBACK
+AdvAppearanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+       INT iListIndex;
+       GLOBALS* g;
+
+       g = (GLOBALS*)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
+       switch (uMsg)
+       {
+               case WM_INITDIALOG:
+                       g = (GLOBALS*)lParam;
+                       SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)g);
+                       AdvAppearanceDlg_Init(hwndDlg, g);
+                       break;
+
+               case WM_DESTROY:
+                       AdvAppearanceDlg_CleanUp(hwndDlg, g);
+                       break;
+
+               case WM_COMMAND:
+                       switch(LOWORD(wParam))
+                       {
+                               case IDOK:
+                                       SaveCurrentValues(hwndDlg, g);
+                                       EndDialog(hwndDlg, 0);
+                                       break;
+
+                               case IDCANCEL:
+                                       g->ThemeAdv = g->Theme;
+                                       EndDialog(hwndDlg, 0);
+                                       break;
+
+                               case IDC_APPEARANCE_PREVIEW:
+                                       SaveCurrentValues(hwndDlg, g);
+                                       SelectComboByElement(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, lParam);
+                                       g->CurrentElement = (INT)lParam;
+                                       UpdateControls(hwndDlg, g);
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_ELEMENT:
+                                       if (HIWORD(wParam) == CBN_SELCHANGE)
+                                       {
+                                               SaveCurrentValues(hwndDlg, g);
+                                               iListIndex = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETCURSEL, 0, 0);
+                                               g->CurrentElement = SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_ELEMENT, CB_GETITEMDATA, (WPARAM)iListIndex, 0);
+                                               UpdateControls(hwndDlg, g);
+                                       }
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_SIZE_E:
+                                       if (g && HIWORD(wParam) == EN_CHANGE)
+                                       {
+                                               INT i = (INT)LOWORD(SendDlgItemMessage(hwndDlg, IDC_ADVAPPEARANCE_SIZE_UD, UDM_GETPOS,0,0L));
+
+                                               switch (g->CurrentElement)
+                                               {
+                                                       case IDX_INACTIVE_CAPTION:
+                                                       case IDX_ACTIVE_CAPTION:
+                                                       case IDX_CAPTION_BUTTON:
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCYCAPTION, 0, i);
+                                                               break;
+
+                                                       case IDX_MENU:
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCYMENU, 0, i);
+                                                               break;
+
+                                                       case IDX_SCROLLBAR:
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCXSCROLLBAR, 0, i);
+                                                               break;
+
+                                                       case IDX_INACTIVE_BORDER:
+                                                       case IDX_ACTIVE_BORDER:
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCYSIZEFRAME, 0, i);
+                                                               break;
+                                               }
+                                       }
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_FONT_C:
+                                       if (g && HIWORD(wParam) == CBN_SELCHANGE)
+                                       {
+                                               switch (g->CurrentElement)
+                                               {
+                                                       case IDX_INACTIVE_CAPTION:
+                                                       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]);
+                                                               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]);
+                                                               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]);
+                                                               break;
+                                               }
+                                       }
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_FONTSIZE_E:
+                                       if (g && HIWORD(wParam) == CBN_SELCHANGE)
+                                       {
+                                               HDC hdcDlg = GetDC(hwndDlg);
+                                               INT i;
+
+                                               switch (g->CurrentElement)
+                                               {
+                                                       case IDX_INACTIVE_CAPTION:
+                                                       case IDX_ACTIVE_CAPTION:
+                                                               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]);
+                                                               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]);
+                                                               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]);
+                                                               break;
+                                               }
+
+                                               ReleaseDC(hwndDlg, hdcDlg);
+                                       }
+                                       else if (g && HIWORD(wParam) == CBN_EDITCHANGE)
+                                       {
+                                               HDC hdcDlg = GetDC(hwndDlg);
+                                               INT i;
+
+                                               switch (g->CurrentElement)
+                                               {
+                                                       case IDX_INACTIVE_CAPTION:
+                                                       case IDX_ACTIVE_CAPTION:
+                                                               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]);
+                                                               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]);
+                                                               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]);
+                                                               break;
+                                               }
+
+                                               ReleaseDC(hwndDlg, hdcDlg);
+                                       }
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_FONTBOLD:
+                                       if (g && HIWORD(wParam) == BN_CLICKED)
+                                       {
+                                               INT i;
+
+                                               switch (g->CurrentElement)
+                                               {
+                                                       case IDX_INACTIVE_CAPTION:
+                                                       case IDX_ACTIVE_CAPTION:
+                                                               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]);
+                                                               break;
+
+                                                       case IDX_MENU:
+                                                               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_SETMENUFONT, 0,
+                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               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;
+
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
+                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               break;
+                                               }
+                                       }
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_FONTITALIC:
+                                       if (g && HIWORD(wParam) == BN_CLICKED)
+                                       {
+                                               INT i;
+
+                                               switch (g->CurrentElement)
+                                               {
+                                                       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;
+
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETCAPTIONFONT, 0,
+                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               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;
+
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETMENUFONT, 0,
+                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               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;
+
+                                                               SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_SETDIALOGFONT, 0,
+                                                                       (LPARAM)&g->ThemeAdv.lfFont[g_Assignment[g->CurrentElement].Font]);
+                                                               break;
+                                               }
+                                       }
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_COLOR1_B:
+                                       GetColor(hwndDlg, g, 0);
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_COLOR2_B:
+                                       GetColor(hwndDlg, g, 1);
+                                       break;
+
+                               case IDC_ADVAPPEARANCE_FONTCOLOR_B:
+                                       GetColor(hwndDlg, g, 2);
+                                       break;
+
+                               default:
+                                       return FALSE;
+                       }
+                       break;
+
+               default:
+                       return FALSE;
+       }
+
+       return TRUE;
+}