📄 monthcal.c
字号:
if (pressed)
style |= DFCS_PUSHED;
else
{
DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
if (dwStyle & WS_DISABLED) style |= DFCS_INACTIVE;
}
DrawFrameControl(hdc, r, DFC_SCROLL, style);
}
}
static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
{
static const WCHAR todayW[] = { 'T','o','d','a','y',':',0 };
static const WCHAR fmt1W[] = { '%','s',' ','%','l','d',0 };
static const WCHAR fmt2W[] = { '%','s',' ','%','s',0 };
static const WCHAR fmt3W[] = { '%','d',0 };
RECT *title=&infoPtr->title;
RECT *prev=&infoPtr->titlebtnprev;
RECT *next=&infoPtr->titlebtnnext;
RECT *titlemonth=&infoPtr->titlemonth;
RECT *titleyear=&infoPtr->titleyear;
RECT dayrect;
RECT *days=&dayrect;
RECT rtoday;
int i, j, m, mask, day, firstDay, weeknum, weeknum1,prevMonth;
int textHeight = infoPtr->textHeight, textWidth = infoPtr->textWidth;
SIZE size;
HBRUSH hbr;
HFONT currentFont;
WCHAR buf[20];
WCHAR buf1[20];
WCHAR buf2[32];
COLORREF oldTextColor, oldBkColor;
DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
RECT rcTemp;
RECT rcDay; /* used in MONTHCAL_CalcDayRect() */
SYSTEMTIME localtime;
int startofprescal;
oldTextColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
/* fill background */
hbr = CreateSolidBrush (infoPtr->bk);
FillRect(hdc, &ps->rcPaint, hbr);
DeleteObject(hbr);
/* draw header */
if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
{
hbr = CreateSolidBrush(infoPtr->titlebk);
FillRect(hdc, title, hbr);
DeleteObject(hbr);
}
/* if the previous button is pressed draw it depressed */
if(IntersectRect(&rcTemp, &(ps->rcPaint), prev))
paint_button (infoPtr, hdc, FALSE, infoPtr->status & MC_PREVPRESSED, prev);
/* if next button is depressed draw it depressed */
if(IntersectRect(&rcTemp, &(ps->rcPaint), next))
paint_button (infoPtr, hdc, TRUE, infoPtr->status & MC_NEXTPRESSED, next);
oldBkColor = SetBkColor(hdc, infoPtr->titlebk);
SetTextColor(hdc, infoPtr->titletxt);
currentFont = SelectObject(hdc, infoPtr->hBoldFont);
GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
buf1,countof(buf1));
wsprintfW(buf, fmt1W, buf1, infoPtr->currentYear);
if(IntersectRect(&rcTemp, &(ps->rcPaint), title))
{
DrawTextW(hdc, buf, strlenW(buf), title,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
/* titlemonth left/right contained rect for whole titletxt('June 1999')
* MCM_HitTestInfo wants month & year rects, so prepare these now.
*(no, we can't draw them separately; the whole text is centered)
*/
GetTextExtentPoint32W(hdc, buf, strlenW(buf), &size);
titlemonth->left = title->right / 2 + title->left / 2 - size.cx / 2;
titleyear->right = title->right / 2 + title->left / 2 + size.cx / 2;
GetTextExtentPoint32W(hdc, buf1, strlenW(buf1), &size);
titlemonth->right = titlemonth->left + size.cx;
titleyear->left = titlemonth->right;
/* draw month area */
rcTemp.top=infoPtr->wdays.top;
rcTemp.left=infoPtr->wdays.left;
rcTemp.bottom=infoPtr->todayrect.bottom;
rcTemp.right =infoPtr->todayrect.right;
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcTemp))
{
hbr = CreateSolidBrush(infoPtr->monthbk);
FillRect(hdc, &rcTemp, hbr);
DeleteObject(hbr);
}
/* draw line under day abbreviatons */
MoveToEx(hdc, infoPtr->days.left + 3, title->bottom + textHeight + 1, NULL);
LineTo(hdc, infoPtr->days.right - 3, title->bottom + textHeight + 1);
prevMonth = infoPtr->currentMonth - 1;
if(prevMonth == 0) /* if currentMonth is january(1) prevMonth is */
prevMonth = 12; /* december(12) of the previous year */
infoPtr->wdays.left = infoPtr->days.left = infoPtr->weeknums.right;
/* draw day abbreviations */
SelectObject(hdc, infoPtr->hFont);
SetBkColor(hdc, infoPtr->monthbk);
SetTextColor(hdc, infoPtr->trailingtxt);
/* copy this rect so we can change the values without changing */
/* the original version */
days->left = infoPtr->wdays.left;
days->right = days->left + infoPtr->width_increment;
days->top = infoPtr->wdays.top;
days->bottom = infoPtr->wdays.bottom;
i = infoPtr->firstDay;
for(j=0; j<7; j++) {
GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i+j+6)%7, buf, countof(buf));
DrawTextW(hdc, buf, strlenW(buf), days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
days->left+=infoPtr->width_increment;
days->right+=infoPtr->width_increment;
}
/* draw day numbers; first, the previous month */
firstDay = MONTHCAL_CalculateDayOfWeek(1, infoPtr->currentMonth, infoPtr->currentYear);
day = MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear) +
(infoPtr->firstDay + 7 - firstDay)%7 + 1;
if (day > MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear))
day -=7;
startofprescal = day;
mask = 1<<(day-1);
i = 0;
m = 0;
while(day <= MONTHCAL_MonthLength(prevMonth, infoPtr->currentYear)) {
MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
{
MONTHCAL_DrawDay(infoPtr, hdc, day, prevMonth, i, 0,
infoPtr->monthdayState[m] & mask);
}
mask<<=1;
day++;
i++;
}
/* draw `current' month */
day = 1; /* start at the beginning of the current month */
infoPtr->firstDayplace = i;
SetTextColor(hdc, infoPtr->txt);
m++;
mask = 1;
/* draw the first week of the current month */
while(i<7) {
MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, 0);
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
{
MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->currentMonth, i, 0,
infoPtr->monthdayState[m] & mask);
if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
(day==infoPtr->todaysDate.wDay) &&
(infoPtr->currentYear == infoPtr->todaysDate.wYear)) {
if(!(dwStyle & MCS_NOTODAYCIRCLE))
MONTHCAL_CircleDay(infoPtr, hdc, day, infoPtr->currentMonth);
}
}
mask<<=1;
day++;
i++;
}
j = 1; /* move to the 2nd week of the current month */
i = 0; /* move back to sunday */
while(day <= MONTHCAL_MonthLength(infoPtr->currentMonth, infoPtr->currentYear)) {
MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
{
MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->currentMonth, i, j,
infoPtr->monthdayState[m] & mask);
if((infoPtr->currentMonth==infoPtr->todaysDate.wMonth) &&
(day==infoPtr->todaysDate.wDay) &&
(infoPtr->currentYear == infoPtr->todaysDate.wYear))
if(!(dwStyle & MCS_NOTODAYCIRCLE))
MONTHCAL_CircleDay(infoPtr, hdc, day, infoPtr->currentMonth);
}
mask<<=1;
day++;
i++;
if(i>6) { /* past saturday, goto the next weeks sunday */
i = 0;
j++;
}
}
/* draw `next' month */
day = 1; /* start at the first day of the next month */
m++;
mask = 1;
SetTextColor(hdc, infoPtr->trailingtxt);
while((i<7) &&(j<6)) {
MONTHCAL_CalcDayRect(infoPtr, &rcDay, i, j);
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rcDay))
{
MONTHCAL_DrawDay(infoPtr, hdc, day, infoPtr->currentMonth + 1, i, j,
infoPtr->monthdayState[m] & mask);
}
mask<<=1;
day++;
i++;
if(i==7) { /* past saturday, go to next week's sunday */
i = 0;
j++;
}
}
SetTextColor(hdc, infoPtr->txt);
/* draw `today' date if style allows it, and draw a circle before today's
* date if necessary */
if(!(dwStyle & MCS_NOTODAY)) {
int offset = 0;
if(!(dwStyle & MCS_NOTODAYCIRCLE)) {
/*day is the number of days from nextmonth we put on the calendar */
MONTHCAL_CircleDay(infoPtr, hdc,
day+MONTHCAL_MonthLength(infoPtr->currentMonth,infoPtr->currentYear),
infoPtr->currentMonth);
offset+=textWidth;
}
if (!LoadStringW(COMCTL32_hModule,IDM_TODAY,buf1,countof(buf1)))
{
WARN("Can't load resource\n");
strcpyW(buf1, todayW);
}
MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
MONTHCAL_CopyTime(&infoPtr->todaysDate,&localtime);
GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,countof(buf2));
wsprintfW(buf, fmt2W, buf1, buf2);
SelectObject(hdc, infoPtr->hBoldFont);
DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
{
DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
}
SelectObject(hdc, infoPtr->hFont);
}
/*eventually draw week numbers*/
if(dwStyle & MCS_WEEKNUMBERS) {
/* display weeknumbers*/
int mindays;
/* Rules what week to call the first week of a new year:
LOCALE_IFIRSTWEEKOFYEAR == 0 (e.g US?):
The week containing Jan 1 is the first week of year
LOCALE_IFIRSTWEEKOFYEAR == 2 (e.g. Germany):
First week of year must contain 4 days of the new year
LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
The first week of the year must contain only days of the new year
*/
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
weeknum = atoiW(buf);
switch (weeknum)
{
case 1: mindays = 6;
break;
case 2: mindays = 3;
break;
case 0:
default:
mindays = 0;
}
if (infoPtr->currentMonth < 2)
{
/* calculate all those exceptions for january */
weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
if ((infoPtr->firstDay +7 - weeknum1)%7 > mindays)
weeknum =1;
else
{
weeknum = 0;
for(i=0; i<11; i++)
weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear-1);
weeknum +=startofprescal+ 7;
weeknum /=7;
weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear-1);
if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
weeknum++;
}
}
else
{
weeknum = 0;
for(i=0; i<prevMonth-1; i++)
weeknum+=MONTHCAL_MonthLength(i+1, infoPtr->currentYear);
weeknum +=startofprescal+ 7;
weeknum /=7;
weeknum1=MONTHCAL_CalculateDayOfWeek(1,1,infoPtr->currentYear);
if ((infoPtr->firstDay + 7 - weeknum1)%7 > mindays)
weeknum++;
}
days->left = infoPtr->weeknums.left;
days->right = infoPtr->weeknums.right;
days->top = infoPtr->weeknums.top;
days->bottom = days->top +infoPtr->height_increment;
for(i=0; i<6; i++) {
if((i==0)&&(weeknum>50))
{
wsprintfW(buf, fmt3W, weeknum);
weeknum=0;
}
else if((i==5)&&(weeknum>47))
{
wsprintfW(buf, fmt3W, 1);
}
else
wsprintfW(buf, fmt3W, weeknum + i);
DrawTextW(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
days->top+=infoPtr->height_increment;
days->bottom+=infoPtr->height_increment;
}
MoveToEx(hdc, infoPtr->weeknums.right, infoPtr->weeknums.top + 3 , NULL);
LineTo(hdc, infoPtr->weeknums.right, infoPtr->weeknums.bottom );
}
/* currentFont was font at entering Refresh */
SetBkColor(hdc, oldBkColor);
SelectObject(hdc, currentFont);
SetTextColor(hdc, oldTextColor);
}
static LRESULT
MONTHCAL_GetMinReqRect(MONTHCAL_INFO *infoPtr, LPARAM lParam)
{
LPRECT lpRect = (LPRECT) lParam;
TRACE("rect %p\n", lpRect);
/* validate parameters */
if((infoPtr==NULL) ||(lpRect == NULL) ) return FALSE;
lpRect->left = infoPtr->title.left;
lpRect->top = infoPtr->title.top;
lpRect->right = infoPtr->title.right;
lpRect->bottom = infoPtr->todayrect.bottom;
AdjustWindowRect(lpRect, GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE), FALSE);
TRACE("%s\n", wine_dbgstr_rect(lpRect));
return TRUE;
}
static LRESULT
MONTHCAL_GetColor(MONTHCAL_INFO *infoPtr, WPARAM wParam)
{
TRACE("\n");
switch((int)wParam) {
case MCSC_BACKGROUND:
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
MONTHCAL_SetColor(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
int prev = -1;
TRACE("%d: color %08lx\n", wParam, lParam);
switch((int)wParam) {
case MCSC_BACKGROUND:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -