- Implement theme quick preview. Patch by Katayama Hirofumi.

See issue #5525 for more details.

svn path=/trunk/; revision=48159
This commit is contained in:
Gabriel Ilardi 2010-07-21 12:20:18 +00:00
parent 8d8f884623
commit 11a32bcc42
5 changed files with 209 additions and 25 deletions

View file

@ -36,7 +36,7 @@ AppearancePage_OnInit(HWND hwndDlg)
g->hbmpColor[0] = g->hbmpColor[1] = g->hbmpColor[2] = NULL;
g->bInitializing = FALSE;
TemplateCount = LoadThemeTemplates(strSelectedStyle);
TemplateCount = LoadThemePresetEntries(strSelectedStyle);
hwndCombo = GetDlgItem(hwndDlg, IDC_APPEARANCE_COLORSCHEME);
g->ThemeId = -1;
@ -105,7 +105,7 @@ AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
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); */
SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
}
break;
@ -119,7 +119,7 @@ AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
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); */
SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&g->Theme);
}
break;
@ -134,7 +134,7 @@ AppearancePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
g->Theme = Theme;
g->ThemeId = ThemeId;
/* SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Theme); */
SendDlgItemMessage(hwndDlg, IDC_APPEARANCE_PREVIEW, PVM_UPDATETHEME, 0, (LPARAM)&Theme);
}
}
break;

View file

@ -7,13 +7,11 @@
* 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> */
#define MENU_BAR_ITEMS_SPACE (12)
/******************************************************************************/
@ -45,6 +43,20 @@ static const signed char RBOuterNormal[] = {
-1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1
};
static const signed char LTRBOuterMono[] = {
-1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME,
};
static const signed char LTRBInnerMono[] = {
-1, -1, -1, -1,
-1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
-1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
-1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW,
};
static BOOL
MyIntDrawRectEdge(HDC hdc, LPRECT rc, UINT uType, UINT uFlags, THEME *theme)
{
@ -146,6 +158,24 @@ MyIntDrawRectEdge(HDC hdc, LPRECT rc, UINT uType, UINT uFlags, THEME *theme)
LineTo(hdc, InnerRect.right-2, InnerRect.bottom-RBpenplus);
}
if (uFlags & BF_ADJUST)
{
int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
+ (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
if(uFlags & BF_LEFT)
InnerRect.left += add;
if(uFlags & BF_RIGHT)
InnerRect.right -= add;
if(uFlags & BF_TOP)
InnerRect.top += add;
if(uFlags & BF_BOTTOM)
InnerRect.bottom -= add;
if(uFlags & BF_ADJUST)
*rc = InnerRect;
}
/* Cleanup */
SelectObject(hdc, SavePen);
MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
@ -409,8 +439,69 @@ 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)
{
/* FIXME */
return DrawCaptionTemp(hwnd, hdc, rect, hFont, hIcon, str, uFlags);
ULONG Height;
UINT VCenter, Padding;
LONG ButtonWidth;
HBRUSH hbr;
HGDIOBJ hFontOld;
RECT rc;
Height = theme->Size[SIZE_CAPTION_Y] - 1;
VCenter = (rect->bottom - rect->top) / 2;
Padding = VCenter - (Height / 2);
ButtonWidth = theme->Size[SIZE_SIZE_X] - 2;
if (uFlags & DC_GRADIENT)
{
GRADIENT_RECT gcap = {0, 1};
TRIVERTEX vert[2];
COLORREF Colors[2];
Colors[0] = theme->crColor[((uFlags & DC_ACTIVE) ?
COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION)];
Colors[1] = theme->crColor[((uFlags & DC_ACTIVE) ?
COLOR_GRADIENTACTIVECAPTION : COLOR_GRADIENTINACTIVECAPTION)];
vert[0].x = rect->left;
vert[0].y = rect->top;
vert[0].Red = (WORD)Colors[0]<<8;
vert[0].Green = (WORD)Colors[0] & 0xFF00;
vert[0].Blue = (WORD)(Colors[0]>>8) & 0xFF00;
vert[0].Alpha = 0;
vert[1].x = rect->right;
vert[1].y = rect->bottom;
vert[1].Red = (WORD)Colors[1]<<8;
vert[1].Green = (WORD)Colors[1] & 0xFF00;
vert[1].Blue = (WORD)(Colors[1]>>8) & 0xFF00;
vert[1].Alpha = 0;
GradientFill(hdc, vert, 2, &gcap, 1, GRADIENT_FILL_RECT_H);
}
else
{
if (uFlags & DC_ACTIVE)
hbr = CreateSolidBrush(theme->crColor[COLOR_ACTIVECAPTION]);
else
hbr = CreateSolidBrush(theme->crColor[COLOR_INACTIVECAPTION]);
FillRect(hdc, rect, hbr);
DeleteObject(hbr);
}
hFontOld = SelectObject(hdc, hFont);
SetBkMode(hdc, TRANSPARENT);
if (uFlags & DC_ACTIVE)
SetTextColor(hdc, theme->crColor[COLOR_CAPTIONTEXT]);
else
SetTextColor(hdc, theme->crColor[COLOR_INACTIVECAPTIONTEXT]);
rc.left = rect->left + 2;
rc.top = rect->top;
rc.right = rect->right;
rc.bottom = rect->bottom;
DrawTextW(hdc, str, -1, &rc, DT_SINGLELINE | DT_VCENTER);
SelectObject(hdc, hFontOld);
return TRUE;
}
/******************************************************************************/
@ -418,6 +509,99 @@ MyDrawCaptionTemp(HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, HICON hIcon
DWORD
MyDrawMenuBarTemp(HWND Wnd, HDC DC, LPRECT Rect, HMENU Menu, HFONT Font, THEME *theme)
{
/* FIXME */
return DrawMenuBarTemp(Wnd, DC, Rect, Menu, Font);
HBRUSH hbr;
HPEN hPen;
HGDIOBJ hPenOld, hFontOld;
BOOL flat_menu;
INT i, bkgnd, x;
RECT rect;
WCHAR Text[128];
UINT uFormat = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
flat_menu = theme->bFlatMenus;
if (flat_menu)
hbr = CreateSolidBrush(theme->crColor[COLOR_MENUBAR]);
else
hbr = CreateSolidBrush(theme->crColor[COLOR_MENU]);
FillRect(DC, Rect, hbr);
DeleteObject(hbr);
hPen = CreatePen(PS_SOLID, 0, theme->crColor[COLOR_3DFACE]);
hPenOld = SelectObject(DC, hPen);
MoveToEx(DC, Rect->left, Rect->bottom - 1, NULL);
LineTo(DC, Rect->right, Rect->bottom - 1);
SelectObject(DC, hPenOld);
DeleteObject(hPen);
bkgnd = (flat_menu ? COLOR_MENUBAR : COLOR_MENU);
x = Rect->left;
hFontOld = SelectObject(DC, Font);
for(i = 0; i < 3; i++)
{
GetMenuStringW(Menu, i, Text, 128, MF_BYPOSITION);
rect.left = x;
rect.top = Rect->top;
DrawTextW(DC, Text, -1, &rect, DT_SINGLELINE | DT_CALCRECT);
rect.bottom = Rect->bottom;
rect.right += MENU_BAR_ITEMS_SPACE;
x += rect.right - rect.left;
if (i == 2)
{
if (flat_menu)
{
SetTextColor(DC, theme->crColor[COLOR_HIGHLIGHTTEXT]);
SetBkColor(DC, theme->crColor[COLOR_HIGHLIGHT]);
InflateRect (&rect, -1, -1);
hbr = CreateSolidBrush(theme->crColor[COLOR_MENUHILIGHT]);
FillRect(DC, &rect, hbr);
DeleteObject(hbr);
InflateRect (&rect, 1, 1);
hbr = CreateSolidBrush(theme->crColor[COLOR_HIGHLIGHT]);
FrameRect(DC, &rect, hbr);
DeleteObject(hbr);
}
else
{
SetTextColor(DC, theme->crColor[COLOR_MENUTEXT]);
SetBkColor(DC, theme->crColor[COLOR_MENU]);
DrawEdge(DC, &rect, BDR_SUNKENOUTER, BF_RECT);
}
}
else
{
if (i == 1)
SetTextColor(DC, theme->crColor[COLOR_GRAYTEXT]);
else
SetTextColor(DC, theme->crColor[COLOR_MENUTEXT]);
SetBkColor(DC, theme->crColor[bkgnd]);
hbr = CreateSolidBrush(theme->crColor[bkgnd]);
FillRect(DC, &rect, hbr);
DeleteObject(hbr);
}
SetBkMode(DC, TRANSPARENT);
rect.left += MENU_BAR_ITEMS_SPACE / 2;
rect.right -= MENU_BAR_ITEMS_SPACE / 2;
if (i == 1)
{
++rect.left; ++rect.top; ++rect.right; ++rect.bottom;
SetTextColor(DC, RGB(0xff, 0xff, 0xff));
DrawTextW(DC, Text, -1, &rect, uFormat);
--rect.left; --rect.top; --rect.right; --rect.bottom;
SetTextColor(DC, RGB(0x80, 0x80, 0x80));
}
DrawTextW(DC, Text, -1, &rect, uFormat);
}
SelectObject(DC, hFontOld);
return TRUE;
}

View file

@ -263,8 +263,8 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
/* Inactive Window */
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);
MyDrawCaptionTemp(NULL, hdc, &pPreviewData->rcInactiveCaption, pPreviewData->hCaptionFont,
NULL, pPreviewData->lpInAct, DC_GRADIENT | DC_ICON | DC_TEXT, theme);
MyDrawCaptionButtons(hdc, &pPreviewData->rcInactiveCaption, TRUE, pPreviewData->cyCaption - 2, theme);
/* Active Window */
@ -290,7 +290,7 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
rc.top += 2;
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);
DrawText(hdc, pPreviewData->lpWinTxt, -1, &rc, DT_LEFT);
SelectObject(hdc, hOldFont);
/* Draw the scroll bar */
@ -307,9 +307,9 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
CopyRect(&rc, &pPreviewData->rcDialogClient);
rc.left += 4;
rc.top += 2;
SetTextColor(hdc, RGB(0,0,0));
SetTextColor(hdc, theme->crColor[COLOR_BTNTEXT]);
hOldFont = SelectObject(hdc, pPreviewData->hMessageFont);
DrawText(hdc, pPreviewData->lpMessText, lstrlen(pPreviewData->lpMessText), &rc, DT_LEFT);
DrawText(hdc, pPreviewData->lpMessText, -1, &rc, DT_LEFT);
SelectObject(hdc, hOldFont);
/* Draw Button */
@ -317,7 +317,7 @@ OnPaint(HWND hwnd, PPREVIEW_DATA pPreviewData)
CopyRect(&rc, &pPreviewData->rcDialogButton);
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);
DrawText(hdc, pPreviewData->lpButText, -1, &rc, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
SelectObject(hdc, hOldFont);
EndPaint(hwnd, &ps);

View file

@ -10,7 +10,7 @@
#include "desk.h"
#include "theme.h"
static BOOL g_TemplateLoaded = FALSE;
static BOOL g_PresetLoaded = FALSE;
static INT g_TemplateCount = 0;
static INT g_ColorList[NUM_COLORS];
@ -141,8 +141,8 @@ BOOL LoadThemeFromReg(THEME* theme, INT ThemeId)
DWORD dwType, dwLength;
BOOL Ret = FALSE;
if (!g_TemplateLoaded)
LoadThemeTemplates(strSelectedStyle);
if (!g_PresetLoaded)
LoadThemePresetEntries(strSelectedStyle);
if (ThemeId == -1)
return FALSE;
@ -342,7 +342,7 @@ BOOL SaveTheme(THEME* theme, LPCTSTR strLegacyName)
return FALSE;
}
INT LoadThemeTemplates(LPTSTR pszSelectedStyle)
INT LoadThemePresetEntries(LPTSTR pszSelectedStyle)
{
HKEY hkNewSchemes, hkScheme, hkSizes, hkSize;
FILETIME ftLastWriteTime;
@ -362,7 +362,7 @@ INT LoadThemeTemplates(LPTSTR pszSelectedStyle)
RegQueryValueEx(hkNewSchemes, g_SelectedStyle, NULL, &dwType, (LPBYTE)pszSelectedStyle, &dwLength);
/* Check if already loaded */
if (g_TemplateLoaded)
if (g_PresetLoaded)
{
RegCloseKey(hkNewSchemes);
return g_TemplateCount;
@ -406,7 +406,7 @@ INT LoadThemeTemplates(LPTSTR pszSelectedStyle)
dwLength = MAX_TEMPLATENAMELENTGH;
}
RegCloseKey(hkNewSchemes);
g_TemplateLoaded = TRUE;
g_PresetLoaded = TRUE;
g_TemplateCount = iTemplateIndex;
}
return iTemplateIndex;

View file

@ -86,4 +86,4 @@ 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);
INT LoadThemePresetEntries(LPTSTR pszSelectedStyle);