📄 advappdlg.c
字号:
/* $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;
COLORREF crColor = g->ThemeAdv.crColor[nColor];
HGDIOBJ hgdiTmp;
if (nColor != -1)
{
/* Create a DC to draw on */
hwndColorButton = GetDlgItem(hwndDlg, IDC_ADVAPPEARANCE_COLOR1_B);
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(crColor);
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(g->crCOLOR_BTNFACE);
FillRect(hdcCompat, &rect, hbrush);
DeleteObject(hbrush);
/* Draw the rectangle */
rect.left = 1;
rect.top = 1;
rect.right = 23;
rect.bottom = 14;
hbrush = CreateSolidBrush(g->crCOLOR_BTNTEXT);
FillRect(hdcCompat, &rect, hbrush);
DeleteObject(hbrush);
/* Draw left side of line */
hPen = CreatePen(PS_SOLID, 1, g->crCOLOR_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, g->crCOLOR_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, g->crCOLOR_BTNTEXT);
hbrush = CreateSolidBrush(g->crCOLOR_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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -