comctl32/monthcal: Cache brush handles.

This commit is contained in:
Nikolay Sivov 2011-03-26 15:58:59 +03:00 committed by Alexandre Julliard
parent eb2dc5c900
commit 6d4b96020e
1 changed files with 20 additions and 16 deletions

View File

@ -95,6 +95,7 @@ typedef struct
DWORD dwStyle; /* cached GWL_STYLE */ DWORD dwStyle; /* cached GWL_STYLE */
COLORREF colors[MCSC_TRAILINGTEXT+1]; COLORREF colors[MCSC_TRAILINGTEXT+1];
HBRUSH brushes[MCSC_MONTHBK+1];
HFONT hFont; HFONT hFont;
HFONT hBoldFont; HFONT hBoldFont;
@ -754,13 +755,10 @@ static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRU
RECT *title = &infoPtr->calendars[calIdx].title; RECT *title = &infoPtr->calendars[calIdx].title;
const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month; const SYSTEMTIME *st = &infoPtr->calendars[calIdx].month;
WCHAR buf_month[80], buf_fmt[80]; WCHAR buf_month[80], buf_fmt[80];
HBRUSH hbr;
SIZE sz; SIZE sz;
/* fill header box */ /* fill header box */
hbr = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]); FillRect(hdc, title, infoPtr->brushes[MCSC_TITLEBK]);
FillRect(hdc, title, hbr);
DeleteObject(hbr);
/* month/year string */ /* month/year string */
SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]); SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
@ -792,7 +790,6 @@ static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, con
INT i, prev_month; INT i, prev_month;
SYSTEMTIME st; SYSTEMTIME st;
WCHAR buf[80]; WCHAR buf[80];
HBRUSH hbr;
RECT r; RECT r;
if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return; if (!(infoPtr->dwStyle & MCS_WEEKNUMBERS)) return;
@ -864,9 +861,7 @@ static void MONTHCAL_PaintWeeknumbers(const MONTHCAL_INFO *infoPtr, HDC hdc, con
r = infoPtr->calendars[calIdx].weeknums; r = infoPtr->calendars[calIdx].weeknums;
/* erase whole week numbers area */ /* erase whole week numbers area */
hbr = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]); FillRect(hdc, &r, infoPtr->brushes[MCSC_MONTHBK]);
FillRect(hdc, &r, hbr);
DeleteObject(hbr);
/* reduce rectangle to one week number */ /* reduce rectangle to one week number */
r.bottom = r.top + infoPtr->height_increment; r.bottom = r.top + infoPtr->height_increment;
@ -994,7 +989,6 @@ static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const
RECT r, fill_bk_rect; RECT r, fill_bk_rect;
SYSTEMTIME st; SYSTEMTIME st;
WCHAR buf[80]; WCHAR buf[80];
HBRUSH hbr;
int mask; int mask;
/* fill whole days area - from week days area to today note rectangle */ /* fill whole days area - from week days area to today note rectangle */
@ -1002,9 +996,7 @@ static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const
fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom + fill_bk_rect.bottom = infoPtr->calendars[calIdx].days.bottom +
(infoPtr->todayrect.bottom - infoPtr->todayrect.top); (infoPtr->todayrect.bottom - infoPtr->todayrect.top);
hbr = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]); FillRect(hdc, &fill_bk_rect, infoPtr->brushes[MCSC_MONTHBK]);
FillRect(hdc, &fill_bk_rect, hbr);
DeleteObject(hbr);
/* draw line under day abbreviations */ /* draw line under day abbreviations */
MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3, MoveToEx(hdc, infoPtr->calendars[calIdx].days.left + 3,
@ -1136,6 +1128,13 @@ MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
prev = infoPtr->colors[index]; prev = infoPtr->colors[index];
infoPtr->colors[index] = color; infoPtr->colors[index] = color;
/* update cached brush */
if (index == MCSC_BACKGROUND || index == MCSC_TITLEBK || index == MCSC_MONTHBK)
{
DeleteObject(infoPtr->brushes[index]);
infoPtr->brushes[index] = CreateSolidBrush(color);
}
InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE); InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
return prev; return prev;
} }
@ -2237,15 +2236,12 @@ MONTHCAL_Paint(MONTHCAL_INFO *infoPtr, HDC hdc_paint)
static LRESULT static LRESULT
MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc) MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
{ {
HBRUSH hbr;
RECT rc; RECT rc;
if (!GetClipBox(hdc, &rc)) return FALSE; if (!GetClipBox(hdc, &rc)) return FALSE;
/* fill background */ /* fill background */
hbr = CreateSolidBrush (infoPtr->colors[MCSC_BACKGROUND]); FillRect(hdc, &rc, infoPtr->brushes[MCSC_BACKGROUND]);
FillRect(hdc, &rc, hbr);
DeleteObject(hbr);
return TRUE; return TRUE;
} }
@ -2538,6 +2534,10 @@ MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow; infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText; infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
infoPtr->brushes[MCSC_BACKGROUND] = CreateSolidBrush(infoPtr->colors[MCSC_BACKGROUND]);
infoPtr->brushes[MCSC_TITLEBK] = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
infoPtr->brushes[MCSC_MONTHBK] = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
infoPtr->minSel = infoPtr->todaysDate; infoPtr->minSel = infoPtr->todaysDate;
infoPtr->maxSel = infoPtr->todaysDate; infoPtr->maxSel = infoPtr->todaysDate;
infoPtr->calendars[0].month = infoPtr->todaysDate; infoPtr->calendars[0].month = infoPtr->todaysDate;
@ -2571,6 +2571,10 @@ MONTHCAL_Destroy(MONTHCAL_INFO *infoPtr)
CloseThemeData (GetWindowTheme (infoPtr->hwndSelf)); CloseThemeData (GetWindowTheme (infoPtr->hwndSelf));
DeleteObject(infoPtr->brushes[MCSC_BACKGROUND]);
DeleteObject(infoPtr->brushes[MCSC_TITLEBK]);
DeleteObject(infoPtr->brushes[MCSC_MONTHBK]);
Free(infoPtr); Free(infoPtr);
return 0; return 0;
} }