comctl32/monthcal: Store all control colors in a single array.

This commit is contained in:
Nikolay Sivov 2010-08-08 16:54:23 +04:00 committed by Alexandre Julliard
parent 8caeb2f735
commit ae1062c12d
2 changed files with 93 additions and 172 deletions

View File

@ -94,12 +94,9 @@ typedef struct
{ {
HWND hwndSelf; HWND hwndSelf;
DWORD dwStyle; /* cached GWL_STYLE */ DWORD dwStyle; /* cached GWL_STYLE */
COLORREF bk;
COLORREF txt; COLORREF colors[MCSC_TRAILINGTEXT+1];
COLORREF titlebk;
COLORREF titletxt;
COLORREF monthbk;
COLORREF trailingtxt;
HFONT hFont; HFONT hFont;
HFONT hBoldFont; HFONT hBoldFont;
int textHeight; int textHeight;
@ -687,8 +684,8 @@ static void MONTHCAL_DrawDay(const MONTHCAL_INFO *infoPtr, HDC hdc, const SYSTEM
TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay); TRACE("%d %d %d\n", st->wDay, infoPtr->minSel.wDay, infoPtr->maxSel.wDay);
TRACE("%s\n", wine_dbgstr_rect(&r)); TRACE("%s\n", wine_dbgstr_rect(&r));
oldCol = SetTextColor(hdc, infoPtr->monthbk); oldCol = SetTextColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
oldBk = SetBkColor(hdc, infoPtr->trailingtxt); oldBk = SetBkColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
hbr = GetSysColorBrush(COLOR_HIGHLIGHT); hbr = GetSysColorBrush(COLOR_HIGHLIGHT);
FillRect(hdc, &r, hbr); FillRect(hdc, &r, hbr);
@ -762,13 +759,13 @@ static void MONTHCAL_PaintTitle(MONTHCAL_INFO *infoPtr, HDC hdc, const PAINTSTRU
SIZE sz; SIZE sz;
/* fill header box */ /* fill header box */
hbr = CreateSolidBrush(infoPtr->titlebk); hbr = CreateSolidBrush(infoPtr->colors[MCSC_TITLEBK]);
FillRect(hdc, title, hbr); FillRect(hdc, title, hbr);
DeleteObject(hbr); DeleteObject(hbr);
/* month/year string */ /* month/year string */
SetBkColor(hdc, infoPtr->titlebk); SetBkColor(hdc, infoPtr->colors[MCSC_TITLEBK]);
SetTextColor(hdc, infoPtr->titletxt); SetTextColor(hdc, infoPtr->colors[MCSC_TITLETEXT]);
SelectObject(hdc, infoPtr->hBoldFont); SelectObject(hdc, infoPtr->hBoldFont);
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1, GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1 + st->wMonth - 1,
@ -868,7 +865,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->monthbk); hbr = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
FillRect(hdc, &r, hbr); FillRect(hdc, &r, hbr);
DeleteObject(hbr); DeleteObject(hbr);
@ -966,7 +963,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->monthbk); hbr = CreateSolidBrush(infoPtr->colors[MCSC_MONTHBK]);
FillRect(hdc, &fill_bk_rect, hbr); FillRect(hdc, &fill_bk_rect, hbr);
DeleteObject(hbr); DeleteObject(hbr);
@ -984,8 +981,8 @@ static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const
/* 1. draw day abbreviations */ /* 1. draw day abbreviations */
SelectObject(hdc, infoPtr->hFont); SelectObject(hdc, infoPtr->hFont);
SetBkColor(hdc, infoPtr->monthbk); SetBkColor(hdc, infoPtr->colors[MCSC_MONTHBK]);
SetTextColor(hdc, infoPtr->trailingtxt); SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
/* rectangle to draw a single day abbreviation within */ /* rectangle to draw a single day abbreviation within */
r = infoPtr->calendars[calIdx].wdays; r = infoPtr->calendars[calIdx].wdays;
r.right = r.left + infoPtr->width_increment; r.right = r.left + infoPtr->width_increment;
@ -1002,7 +999,7 @@ static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const
{ {
SYSTEMTIME st_max; SYSTEMTIME st_max;
SetTextColor(hdc, infoPtr->trailingtxt); SetTextColor(hdc, infoPtr->colors[MCSC_TRAILINGTEXT]);
/* draw prev month */ /* draw prev month */
if (calIdx == 0) if (calIdx == 0)
@ -1038,7 +1035,7 @@ static void MONTHCAL_PaintCalendar(const MONTHCAL_INFO *infoPtr, HDC hdc, const
} }
/* 3. current month */ /* 3. current month */
SetTextColor(hdc, infoPtr->txt); SetTextColor(hdc, infoPtr->colors[MCSC_TEXT]);
st = *date; st = *date;
st.wDay = 1; st.wDay = 1;
mask = 1; mask = 1;
@ -1116,69 +1113,31 @@ MONTHCAL_GetMinReqRect(const MONTHCAL_INFO *infoPtr, RECT *rect)
return TRUE; return TRUE;
} }
static LRESULT static COLORREF
MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, INT index) MONTHCAL_GetColor(const MONTHCAL_INFO *infoPtr, UINT index)
{ {
TRACE("\n"); TRACE("%p, %d\n", infoPtr, index);
switch(index) { if (index > MCSC_TRAILINGTEXT) return -1;
case MCSC_BACKGROUND: return infoPtr->colors[index];
return infoPtr->bk;
case MCSC_TEXT:
return infoPtr->txt;
case MCSC_TITLEBK:
return infoPtr->titlebk;
case MCSC_TITLETEXT:
return infoPtr->titletxt;
case MCSC_MONTHBK:
return infoPtr->monthbk;
case MCSC_TRAILINGTEXT:
return infoPtr->trailingtxt;
}
return -1;
} }
static LRESULT static LRESULT
MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, INT index, COLORREF color) MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, UINT index, COLORREF color)
{ {
COLORREF prev = -1; COLORREF prev;
TRACE("%d: color %08x\n", index, color); TRACE("%p, %d: color %08x\n", infoPtr, index, color);
switch(index) { if (index > MCSC_TRAILINGTEXT) return -1;
case MCSC_BACKGROUND:
prev = infoPtr->bk; prev = infoPtr->colors[index];
infoPtr->bk = color; infoPtr->colors[index] = color;
break;
case MCSC_TEXT:
prev = infoPtr->txt;
infoPtr->txt = color;
break;
case MCSC_TITLEBK:
prev = infoPtr->titlebk;
infoPtr->titlebk = color;
break;
case MCSC_TITLETEXT:
prev=infoPtr->titletxt;
infoPtr->titletxt = color;
break;
case MCSC_MONTHBK:
prev = infoPtr->monthbk;
infoPtr->monthbk = color;
break;
case MCSC_TRAILINGTEXT:
prev = infoPtr->trailingtxt;
infoPtr->trailingtxt = color;
break;
}
InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE); InvalidateRect(infoPtr->hwndSelf, NULL, index == MCSC_BACKGROUND ? TRUE : FALSE);
return prev; return prev;
} }
static LRESULT static LRESULT
MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr) MONTHCAL_GetMonthDelta(const MONTHCAL_INFO *infoPtr)
{ {
@ -2284,7 +2243,7 @@ MONTHCAL_EraseBkgnd(const MONTHCAL_INFO *infoPtr, HDC hdc)
if (!GetClipBox(hdc, &rc)) return FALSE; if (!GetClipBox(hdc, &rc)) return FALSE;
/* fill background */ /* fill background */
hbr = CreateSolidBrush (infoPtr->bk); hbr = CreateSolidBrush (infoPtr->colors[MCSC_BACKGROUND]);
FillRect(hdc, &rc, hbr); FillRect(hdc, &rc, hbr);
DeleteObject(hbr); DeleteObject(hbr);
@ -2574,12 +2533,12 @@ MONTHCAL_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE)); infoPtr->monthdayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
if (!infoPtr->monthdayState) goto fail; if (!infoPtr->monthdayState) goto fail;
infoPtr->titlebk = comctl32_color.clrActiveCaption; infoPtr->colors[MCSC_BACKGROUND] = comctl32_color.clrWindow;
infoPtr->titletxt = comctl32_color.clrWindow; infoPtr->colors[MCSC_TEXT] = comctl32_color.clrWindowText;
infoPtr->monthbk = comctl32_color.clrWindow; infoPtr->colors[MCSC_TITLEBK] = comctl32_color.clrActiveCaption;
infoPtr->trailingtxt = comctl32_color.clrGrayText; infoPtr->colors[MCSC_TITLETEXT] = comctl32_color.clrWindow;
infoPtr->bk = comctl32_color.clrWindow; infoPtr->colors[MCSC_MONTHBK] = comctl32_color.clrWindow;
infoPtr->txt = comctl32_color.clrWindowText; infoPtr->colors[MCSC_TRAILINGTEXT] = comctl32_color.clrGrayText;
infoPtr->minSel = infoPtr->todaysDate; infoPtr->minSel = infoPtr->todaysDate;
infoPtr->maxSel = infoPtr->todaysDate; infoPtr->maxSel = infoPtr->todaysDate;

View File

@ -85,45 +85,6 @@ static const struct message create_monthcal_multi_sel_style_seq[] = {
{ 0 } { 0 }
}; };
static const struct message monthcal_color_seq[] = {
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(0,0,0)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, RGB(255,255,255)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_BACKGROUND, 0},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(0,0,0)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, RGB(255,255,255)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_MONTHBK, 0},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(0,0,0)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TEXT, RGB(255,255,255)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TEXT, 0},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(0,0,0)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, RGB(255,255,255)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLEBK, 0},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(0,0,0)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, RGB(255,255,255)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TITLETEXT, 0},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(0,0,0)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
{ MCM_SETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, RGB(255,255,255)},
{ MCM_GETCOLOR, sent|wparam|lparam, MCSC_TRAILINGTEXT, 0},
{ 0 }
};
static const struct message monthcal_curr_date_seq[] = { static const struct message monthcal_curr_date_seq[] = {
{ MCM_SETCURSEL, sent|wparam, 0}, { MCM_SETCURSEL, sent|wparam, 0},
{ WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0}, { WM_PAINT, sent|wparam|lparam|defwinproc, 0, 0},
@ -613,75 +574,76 @@ static HWND create_monthcal_control(DWORD style)
static void test_color(void) static void test_color(void)
{ {
int res, temp; COLORREF color, prev;
HWND hwnd; HWND hwnd;
hwnd = create_monthcal_control(0); hwnd = create_monthcal_control(0);
flush_sequences(sequences, NUM_MSG_SEQUENCES); /* invalid color index */
color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT + 1, 0);
expect(-1, color);
prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT + 1, RGB(255,255,255));
expect(-1, prev);
/* Setter and Getters for color*/ color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0));
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(0,0,0)); expect(color, prev);
expect(temp, res); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0); expect(RGB(0,0,0), color);
expect(RGB(0,0,0), temp); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255));
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_BACKGROUND, RGB(255,255,255)); expect(color, prev);
expect(temp, res); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_BACKGROUND, 0); expect(RGB(255,255,255), color);
expect(RGB(255,255,255), temp);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(0,0,0));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
expect(RGB(0,0,0), temp); expect(RGB(0,0,0), color);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_MONTHBK, RGB(255,255,255));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_MONTHBK, 0);
expect(RGB(255,255,255), temp); expect(RGB(255,255,255), color);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(0,0,0));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
expect(RGB(0,0,0), temp); expect(RGB(0,0,0), color);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TEXT, RGB(255,255,255));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TEXT, 0);
expect(RGB(255,255,255), temp); expect(RGB(255,255,255), color);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(0,0,0));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
expect(RGB(0,0,0), temp); expect(RGB(0,0,0), color);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLEBK, RGB(255,255,255));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLEBK, 0);
expect(RGB(255,255,255), temp); expect(RGB(255,255,255), color);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(0,0,0));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
expect(RGB(0,0,0), temp); expect(RGB(0,0,0), color);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TITLETEXT, RGB(255,255,255));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TITLETEXT, 0);
expect(RGB(255,255,255), temp); expect(RGB(255,255,255), color);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(0,0,0));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
expect(RGB(0,0,0), temp); expect(RGB(0,0,0), color);
res = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255)); prev = SendMessage(hwnd, MCM_SETCOLOR, MCSC_TRAILINGTEXT, RGB(255,255,255));
expect(temp, res); expect(color, prev);
temp = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0); color = SendMessage(hwnd, MCM_GETCOLOR, MCSC_TRAILINGTEXT, 0);
expect(RGB(255,255,255), temp); expect(RGB(255,255,255), color);
ok_sequence(sequences, MONTHCAL_SEQ_INDEX, monthcal_color_seq, "monthcal color", FALSE);
DestroyWindow(hwnd); DestroyWindow(hwnd);
} }