/*
* PROJECT: ReactOS Desktop Control Panel
* LICENSE: GPL - See COPYING in the top level directory
- * FILE: lib/cpl/desk/preview.c
+ * FILE: dll/cpl/desk/preview.c
* PURPOSE: Draws the preview control
* COPYRIGHT: Copyright 2006, 2007 Eric Kohl
*/
#include "desk.h"
-#include "theme.h"
-#include "preview.h"
-#include "draw.h"
static const TCHAR szPreviewWndClass[] = TEXT("PreviewWndClass");
typedef struct _PREVIEW_DATA
{
+ HDC hdcPreview;
+
HWND hwndParent;
- THEME Theme;
+ COLOR_SCHEME Scheme;
HBRUSH hbrScrollbar;
HBRUSH hbrDesktop;
} PREVIEW_DATA, *PPREVIEW_DATA;
-static VOID UpdatePreviewTheme(HWND hwnd, PPREVIEW_DATA pPreviewData, THEME *theme)
+static VOID UpdatePreviewTheme(HWND hwnd, PPREVIEW_DATA pPreviewData, COLOR_SCHEME *scheme)
{
if (pPreviewData->hbrScrollbar != NULL)
DeleteObject(pPreviewData->hbrScrollbar);
- pPreviewData->hbrScrollbar = CreateSolidBrush(theme->crColor[COLOR_SCROLLBAR]);
+ pPreviewData->hbrScrollbar = CreateSolidBrush(scheme->crColor[COLOR_SCROLLBAR]);
if (pPreviewData->hbrDesktop != NULL)
DeleteObject(pPreviewData->hbrDesktop);
- pPreviewData->hbrDesktop = CreateSolidBrush(theme->crColor[COLOR_DESKTOP]);
+ pPreviewData->hbrDesktop = CreateSolidBrush(scheme->crColor[COLOR_DESKTOP]);
if (pPreviewData->hbrWindow != NULL)
DeleteObject(pPreviewData->hbrWindow);
- pPreviewData->hbrWindow = CreateSolidBrush(theme->crColor[COLOR_WINDOW]);
+ pPreviewData->hbrWindow = CreateSolidBrush(scheme->crColor[COLOR_WINDOW]);
- pPreviewData->cxEdge = theme->Size[SIZE_EDGE_X] - 2; /* SM_CXEDGE */
- pPreviewData->cyEdge = theme->Size[SIZE_EDGE_Y] - 2; /* SM_CYEDGE */
+ pPreviewData->cxEdge = 2; /* SM_CXEDGE */
+ pPreviewData->cyEdge = 2; /* SM_CYEDGE */
- pPreviewData->cySizeFrame = theme->Size[SIZE_FRAME_Y] - 1; /* SM_CYSIZEFRAME */
+ pPreviewData->cySizeFrame = scheme->ncMetrics.iBorderWidth; /* SM_CYSIZEFRAME */
- pPreviewData->cyCaption = theme->Size[SIZE_CAPTION_Y]; /* SM_CYCAPTION */
- pPreviewData->cyMenu = theme->Size[SIZE_MENU_Y]; /* SM_CYMENU */
- pPreviewData->cxScrollbar = theme->Size[SIZE_SCROLL_X]; /* SM_CXVSCROLL */
- pPreviewData->cyBorder = theme->Size[SIZE_BORDER_Y]; /* SM_CYBORDER */
+ pPreviewData->cyCaption = scheme->ncMetrics.iCaptionHeight+1; /* SM_CYCAPTION */
+ pPreviewData->cyMenu = scheme->ncMetrics.iMenuHeight -1; /* SM_CYMENU */
+ pPreviewData->cxScrollbar = scheme->ncMetrics.iScrollWidth; /* SM_CXVSCROLL */
+ pPreviewData->cyBorder = scheme->ncMetrics.iBorderWidth; /* SM_CYBORDER */
if (pPreviewData->hCaptionFont != NULL)
DeleteObject(pPreviewData->hCaptionFont);
- pPreviewData->hCaptionFont = CreateFontIndirect(&theme->lfFont[FONT_CAPTION]);
+ pPreviewData->hCaptionFont = CreateFontIndirect(&scheme->ncMetrics.lfCaptionFont);
if (pPreviewData->hMenuFont != NULL)
DeleteObject(pPreviewData->hMenuFont);
- pPreviewData->hMenuFont = CreateFontIndirect(&theme->lfFont[FONT_MENU]);
+ pPreviewData->hMenuFont = CreateFontIndirect(&scheme->ncMetrics.lfMenuFont);
if (pPreviewData->hMessageFont != NULL)
DeleteObject(pPreviewData->hMessageFont);
- pPreviewData->hMessageFont = CreateFontIndirect(&theme->lfFont[FONT_DIALOG]);
+ pPreviewData->hMessageFont = CreateFontIndirect(&scheme->ncMetrics.lfMessageFont);
- pPreviewData->Theme = *theme;
+ pPreviewData->Scheme = *scheme;
InvalidateRect(hwnd, NULL, FALSE);
}
static VOID
OnCreate(HWND hwnd, PPREVIEW_DATA pPreviewData)
{
- THEME *theme;
+ COLOR_SCHEME *scheme;
pPreviewData->hClientFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
AllocAndLoadString(&pPreviewData->lpMessText, hApplet, IDS_MESSTEXT);
AllocAndLoadString(&pPreviewData->lpButText, hApplet, IDS_BUTTEXT);
- theme = &pPreviewData->Theme;
- LoadCurrentTheme(theme);
+ scheme = &pPreviewData->Scheme;
+ LoadCurrentScheme(scheme);
- UpdatePreviewTheme(hwnd, pPreviewData, theme);
+ UpdatePreviewTheme(hwnd, pPreviewData, scheme);
}
HFONT hOldFont;
HDC hdc;
RECT rc;
- THEME *theme;
+ COLOR_SCHEME *scheme;
- theme = &pPreviewData->Theme;
+ scheme = &pPreviewData->Scheme;
hdc = BeginPaint(hwnd, &ps);
+ if(pPreviewData->hdcPreview)
+ {
+ BitBlt(hdc,0,0, pPreviewData->rcDesktop.right, pPreviewData->rcDesktop.bottom, pPreviewData->hdcPreview, 0,0, SRCCOPY);
+ EndPaint(hwnd, &ps);
+ return;
+ }
+
/* Desktop */
FillRect(hdc, &pPreviewData->rcDesktop, pPreviewData->hbrDesktop);
/* Inactive Window */
- MyDrawEdge(hdc, &pPreviewData->rcInactiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, theme);
- SetTextColor(hdc, theme->crColor[COLOR_INACTIVECAPTIONTEXT]);
+ MyDrawEdge(hdc, &pPreviewData->rcInactiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE | MY_BF_INACTIVEBORDER, scheme);
+ SetTextColor(hdc, scheme->crColor[COLOR_INACTIVECAPTIONTEXT]);
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);
+ NULL, pPreviewData->lpInAct, DC_GRADIENT | DC_ICON | DC_TEXT, scheme);
+ MyDrawCaptionButtons(hdc, &pPreviewData->rcInactiveCaption, TRUE, pPreviewData->cyCaption - 2, scheme);
/* Active Window */
- MyDrawEdge(hdc, &pPreviewData->rcActiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, theme);
- SetTextColor(hdc, theme->crColor[COLOR_CAPTIONTEXT]);
+ MyDrawEdge(hdc, &pPreviewData->rcActiveFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE | MY_BF_ACTIVEBORDER, scheme);
+ SetTextColor(hdc, scheme->crColor[COLOR_CAPTIONTEXT]);
MyDrawCaptionTemp(NULL, hdc, &pPreviewData->rcActiveCaption, pPreviewData->hCaptionFont,
- NULL, pPreviewData->lpAct, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT, theme);
- MyDrawCaptionButtons(hdc, &pPreviewData->rcActiveCaption, TRUE, pPreviewData->cyCaption - 2, theme);
+ NULL, pPreviewData->lpAct, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT, scheme);
+ MyDrawCaptionButtons(hdc, &pPreviewData->rcActiveCaption, TRUE, pPreviewData->cyCaption - 2, scheme);
/* Draw the menu bar */
MyDrawMenuBarTemp(hwnd, hdc, &pPreviewData->rcActiveMenuBar,
pPreviewData->hMenu,
- pPreviewData->hMenuFont, theme);
+ pPreviewData->hMenuFont, scheme);
/* Draw the client area */
CopyRect(&rc, &pPreviewData->rcActiveClient);
- MyDrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST, theme);
+ MyDrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_ADJUST, scheme);
FillRect(hdc, &rc, pPreviewData->hbrWindow);
/* Draw the client text */
CopyRect(&rc, &pPreviewData->rcActiveClient);
rc.left += 4;
rc.top += 2;
- SetTextColor(hdc, theme->crColor[COLOR_WINDOWTEXT]);
+ SetTextColor(hdc, scheme->crColor[COLOR_WINDOWTEXT]);
hOldFont = SelectObject(hdc, pPreviewData->hClientFont);
DrawText(hdc, pPreviewData->lpWinTxt, -1, &rc, DT_LEFT);
SelectObject(hdc, hOldFont);
/* Draw the scroll bar */
- MyDrawScrollbar(hdc, &pPreviewData->rcActiveScroll, pPreviewData->hbrScrollbar, theme);
+ MyDrawScrollbar(hdc, &pPreviewData->rcActiveScroll, pPreviewData->hbrScrollbar, scheme);
/* Dialog Window */
- MyDrawEdge(hdc, &pPreviewData->rcDialogFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, theme);
- SetTextColor(hdc, theme->crColor[COLOR_WINDOW]);
+ MyDrawEdge(hdc, &pPreviewData->rcDialogFrame, EDGE_RAISED, BF_RECT | BF_MIDDLE, scheme);
+ SetTextColor(hdc, scheme->crColor[COLOR_WINDOW]);
MyDrawCaptionTemp(NULL, hdc, &pPreviewData->rcDialogCaption, pPreviewData->hCaptionFont,
- NULL, pPreviewData->lpMessBox, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT, theme);
- MyDrawCaptionButtons(hdc, &pPreviewData->rcDialogCaption, FALSE, pPreviewData->cyCaption - 2, theme);
+ NULL, pPreviewData->lpMessBox, DC_ACTIVE | DC_GRADIENT | DC_ICON | DC_TEXT, scheme);
+ MyDrawCaptionButtons(hdc, &pPreviewData->rcDialogCaption, FALSE, pPreviewData->cyCaption - 2, scheme);
/* Draw the dialog text */
CopyRect(&rc, &pPreviewData->rcDialogClient);
rc.left += 4;
rc.top += 2;
- SetTextColor(hdc, theme->crColor[COLOR_BTNTEXT]);
+ SetTextColor(hdc, scheme->crColor[COLOR_WINDOWTEXT]);
hOldFont = SelectObject(hdc, pPreviewData->hMessageFont);
DrawText(hdc, pPreviewData->lpMessText, -1, &rc, DT_LEFT);
SelectObject(hdc, hOldFont);
/* Draw Button */
- MyDrawFrameControl(hdc, &pPreviewData->rcDialogButton, DFC_BUTTON, DFCS_BUTTONPUSH, theme);
+ MyDrawFrameControl(hdc, &pPreviewData->rcDialogButton, DFC_BUTTON, DFCS_BUTTONPUSH, scheme);
CopyRect(&rc, &pPreviewData->rcDialogButton);
- SetTextColor(hdc, theme->crColor[COLOR_BTNTEXT]);
+ SetTextColor(hdc, scheme->crColor[COLOR_BTNTEXT]);
hOldFont = SelectObject(hdc, pPreviewData->hMessageFont);
DrawText(hdc, pPreviewData->lpButText, -1, &rc, DT_VCENTER | DT_CENTER | DT_SINGLELINE);
SelectObject(hdc, hOldFont);
HeapFree(GetProcessHeap(), 0, pPreviewData);
break;
- case PVM_GETCYCAPTION:
- return pPreviewData->cyCaption;
-
- case PVM_SETCYCAPTION:
- if ((INT)lParam > 0)
- {
- pPreviewData->cyCaption = (INT)lParam;
- CalculateItemSize(pPreviewData);
- InvalidateRect(hwnd, NULL, FALSE);
- }
+ case PVM_UPDATETHEME:
+ UpdatePreviewTheme(hwnd, pPreviewData, (COLOR_SCHEME *)lParam);
+ CalculateItemSize(pPreviewData);
+ InvalidateRect(hwnd, NULL, FALSE);
break;
- case PVM_GETCYMENU:
- return pPreviewData->cyMenu;
+ case PVM_SETSIZE:
+ SchemeSetMetric(&pPreviewData->Scheme, wParam, lParam);
+ pPreviewData->cySizeFrame = pPreviewData->Scheme.ncMetrics.iBorderWidth; /* SM_CYSIZEFRAME */
+ pPreviewData->cyCaption = pPreviewData->Scheme.ncMetrics.iCaptionHeight+1; /* SM_CYCAPTION */
+ pPreviewData->cyMenu = pPreviewData->Scheme.ncMetrics.iMenuHeight -1; /* SM_CYMENU */
+ pPreviewData->cxScrollbar = pPreviewData->Scheme.ncMetrics.iScrollWidth; /* SM_CXVSCROLL */
+ pPreviewData->cyBorder = pPreviewData->Scheme.ncMetrics.iBorderWidth; /* SM_CYBORDER */
+ CalculateItemSize(pPreviewData);
+ InvalidateRect(hwnd, NULL, FALSE);
+ break;
+
+ case PVM_SETFONT:
+ {
+ PLOGFONTW plfFont;
+ HFONT* phFont;
- case PVM_SETCYMENU:
- if ((INT)lParam > 0)
+ switch(wParam)
{
- pPreviewData->cyMenu = (INT)lParam;
- CalculateItemSize(pPreviewData);
- InvalidateRect(hwnd, NULL, FALSE);
+ case FONT_CAPTION: phFont = &pPreviewData->hCaptionFont; break;
+ case FONT_MENU: phFont = &pPreviewData->hMenuFont; break;
+ case FONT_MESSAGE: phFont = &pPreviewData->hMessageFont; break;
+ default: return TRUE;
}
- break;
- case PVM_GETCXSCROLLBAR:
- return pPreviewData->cxScrollbar;
+ plfFont = SchemeGetFont(&pPreviewData->Scheme, wParam);
+ memcpy(plfFont, (PVOID)lParam, sizeof(LOGFONTW));
- case PVM_SETCXSCROLLBAR:
- if ((INT)lParam > 0)
- {
- pPreviewData->cxScrollbar = (INT)lParam;
- CalculateItemSize(pPreviewData);
- InvalidateRect(hwnd, NULL, FALSE);
- }
- break;
+ DeleteObject(*phFont);
+ *phFont = CreateFontIndirect(plfFont);
- case PVM_GETCYSIZEFRAME:
- return pPreviewData->cySizeFrame;
+ InvalidateRect(hwnd, NULL, FALSE);
+ break;
+ }
- case PVM_SETCYSIZEFRAME:
- if ((INT)lParam > 0)
+ case PVM_SETCOLOR:
+ pPreviewData->Scheme.crColor[wParam] = lParam;
+ switch(wParam)
{
- pPreviewData->cySizeFrame = (INT)lParam;
- CalculateItemSize(pPreviewData);
- InvalidateRect(hwnd, NULL, FALSE);
+ case COLOR_SCROLLBAR:
+ DeleteObject(pPreviewData->hbrScrollbar);
+ pPreviewData->hbrScrollbar = CreateSolidBrush(pPreviewData->Scheme.crColor[wParam]);
+ break;
+ case COLOR_DESKTOP:
+ DeleteObject(pPreviewData->hbrDesktop);
+ pPreviewData->hbrDesktop = CreateSolidBrush(pPreviewData->Scheme.crColor[wParam]);
+ break;
+ case COLOR_WINDOW:
+ DeleteObject(pPreviewData->hbrWindow);
+ pPreviewData->hbrWindow = CreateSolidBrush(pPreviewData->Scheme.crColor[wParam]);
+ break;
}
+
+ CalculateItemSize(pPreviewData);
+ InvalidateRect(hwnd, NULL, FALSE);
break;
- case PVM_UPDATETHEME:
- UpdatePreviewTheme(hwnd, pPreviewData, (THEME *)lParam);
+ case PVM_GETSIZE:
+ return SchemeGetMetric(&pPreviewData->Scheme, wParam);
+ case PVM_GETFONT:
+ return (LRESULT)SchemeGetFont(&pPreviewData->Scheme, wParam);
+ case PVM_GETCOLOR:
+ return pPreviewData->Scheme.crColor[wParam];
+
+ case PVM_SET_HDC_PREVIEW:
+ pPreviewData->hdcPreview = (HDC)lParam;
+ InvalidateRect(hwnd, NULL, FALSE);
break;
default: