⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appearance.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: appearance.c 25934 2007-03-01 13:19:50Z fireball $
 *
 * COPYRIGHT:       See COPYING in the top level directory
 * PROJECT:         ReactOS Display Control Panel
 * FILE:            lib/cpl/desk/appearance.c
 * PURPOSE:         Appearance property page
 * 
 * PROGRAMMERS:     Trevor McCort (lycan359@gmail.com)
 *                  Timo Kreuzer (timo[dot]kreuzer[at]web[dot]de
 */

#include "desk.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);
}


static VOID
LoadThemeFromReg(GLOBALS* g, INT iPreset)
{
	INT i;
	TCHAR strSizeName[20] = {TEXT("Sizes\\0")};
	TCHAR strValueName[10];
	HKEY hkNewSchemes, hkScheme, hkSize;
	DWORD dwType, dwLength;

	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)
			{
				dwLength = sizeof(BOOL);
				RegQueryValueEx(hkSize, TEXT("FlatMenus"), NULL, &dwType, (LPBYTE)&g->Theme.bFlatMenus, &dwLength);

				for (i = 0; i <= 30; i++)
				{
					wsprintf(strValueName, TEXT("Color #%d"), i);
					dwLength = sizeof(COLORREF);
					RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&g->Theme.crColor[i], &dwLength);
				}
				for (i = 0; i <= 5; i++)
				{
					wsprintf(strValueName, TEXT("Font #%d"), i);
					dwLength = sizeof(LOGFONT);
					g->Theme.lfFont[i].lfFaceName[0] = 'x';
					RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&g->Theme.lfFont[i], &dwLength);
				}
				for (i = 0; i <= 8; i++)
				{
					wsprintf(strValueName, TEXT("Size #%d"), i);
					dwLength = sizeof(DWORD);
					RegQueryValueEx(hkSize, strValueName, NULL, &dwType, (LPBYTE)&g->Theme.Size[i], &dwLength);
				}
				RegCloseKey(hkScheme);
			}
			RegCloseKey(hkScheme);
		}
		RegCloseKey(hkNewSchemes);
	}
}


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;

	g->Theme.bHasChanged = FALSE;

	/* 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]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -