2006-06-23 08:13:50 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Timedate Control Panel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2011-11-29 14:55:58 +00:00
|
|
|
* FILE: dll/cpl/timedate/monthcal.c
|
2006-06-23 08:13:50 +00:00
|
|
|
* PURPOSE: Calander implementation
|
|
|
|
* COPYRIGHT: Copyright 2006 Thomas Weidenmueller <w3seek@reactos.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "timedate.h"
|
2006-06-23 08:13:50 +00:00
|
|
|
|
2014-01-19 10:40:50 +00:00
|
|
|
#include <windowsx.h>
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
static const WCHAR szMonthCalWndClass[] = L"MonthCalWnd";
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
#define MONTHCAL_HEADERBG COLOR_INACTIVECAPTION
|
|
|
|
#define MONTHCAL_HEADERFG COLOR_INACTIVECAPTIONTEXT
|
|
|
|
#define MONTHCAL_CTRLBG COLOR_WINDOW
|
|
|
|
#define MONTHCAL_CTRLFG COLOR_WINDOWTEXT
|
|
|
|
#define MONTHCAL_SELBG COLOR_ACTIVECAPTION
|
|
|
|
#define MONTHCAL_SELFG COLOR_CAPTIONTEXT
|
|
|
|
#define MONTHCAL_DISABLED_HEADERBG COLOR_INACTIVECAPTION
|
|
|
|
#define MONTHCAL_DISABLED_HEADERFG COLOR_INACTIVECAPTIONTEXT
|
|
|
|
#define MONTHCAL_DISABLED_CTRLBG COLOR_WINDOW
|
|
|
|
#define MONTHCAL_DISABLED_CTRLFG COLOR_WINDOWTEXT
|
|
|
|
#define MONTHCAL_DISABLED_SELBG COLOR_INACTIVECAPTION
|
|
|
|
#define MONTHCAL_DISABLED_SELFG COLOR_INACTIVECAPTIONTEXT
|
|
|
|
|
|
|
|
#define ID_DAYTIMER 1
|
|
|
|
|
|
|
|
typedef struct _MONTHCALWND
|
|
|
|
{
|
|
|
|
HWND hSelf;
|
|
|
|
HWND hNotify;
|
|
|
|
WORD Day;
|
|
|
|
WORD Month;
|
|
|
|
WORD Year;
|
|
|
|
WORD FirstDayOfWeek;
|
|
|
|
BYTE Days[6][7];
|
2007-07-31 22:17:07 +00:00
|
|
|
WCHAR Week[7];
|
2006-06-23 08:13:50 +00:00
|
|
|
SIZE CellSize;
|
|
|
|
SIZE ClientSize;
|
|
|
|
|
|
|
|
HFONT hFont;
|
|
|
|
HBRUSH hbHeader;
|
|
|
|
HBRUSH hbSelection;
|
|
|
|
|
|
|
|
DWORD UIState;
|
|
|
|
UINT Changed : 1;
|
|
|
|
UINT DayTimerSet : 1;
|
|
|
|
UINT Enabled : 1;
|
|
|
|
UINT HasFocus : 1;
|
|
|
|
} MONTHCALWND, *PMONTHCALWND;
|
|
|
|
|
|
|
|
static LRESULT
|
|
|
|
MonthCalNotifyControlParent(IN PMONTHCALWND infoPtr,
|
|
|
|
IN UINT code,
|
|
|
|
IN OUT PVOID data)
|
|
|
|
{
|
|
|
|
LRESULT Ret = 0;
|
|
|
|
|
|
|
|
if (infoPtr->hNotify != NULL)
|
|
|
|
{
|
|
|
|
LPNMHDR pnmh = (LPNMHDR)data;
|
|
|
|
|
|
|
|
pnmh->hwndFrom = infoPtr->hSelf;
|
2007-07-31 22:17:07 +00:00
|
|
|
pnmh->idFrom = GetWindowLongPtrW(infoPtr->hSelf,
|
|
|
|
GWLP_ID);
|
2006-06-23 08:13:50 +00:00
|
|
|
pnmh->code = code;
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
Ret = SendMessageW(infoPtr->hNotify,
|
|
|
|
WM_NOTIFY,
|
|
|
|
(WPARAM)pnmh->idFrom,
|
|
|
|
(LPARAM)pnmh);
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2008-08-01 17:43:53 +00:00
|
|
|
/*
|
2011-11-29 14:55:58 +00:00
|
|
|
* For the year range 1..9999
|
2008-08-01 17:43:53 +00:00
|
|
|
* return 1 if is leap year otherwise 0
|
|
|
|
*/
|
|
|
|
static WORD LeapYear(IN WORD Year)
|
|
|
|
{
|
2021-09-13 01:33:14 +00:00
|
|
|
return
|
2008-08-01 17:43:53 +00:00
|
|
|
#ifdef WITH_1752
|
|
|
|
(Year <= 1752) ? !(Year % 4) :
|
2021-09-13 01:33:14 +00:00
|
|
|
#endif
|
2008-08-01 17:43:53 +00:00
|
|
|
!(Year % 4) && ((Year % 100) || !(Year % 400));
|
|
|
|
}
|
|
|
|
|
2006-06-23 08:13:50 +00:00
|
|
|
static WORD
|
|
|
|
MonthCalMonthLength(IN WORD Month,
|
|
|
|
IN WORD Year)
|
|
|
|
{
|
|
|
|
const BYTE MonthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 0};
|
|
|
|
|
|
|
|
if(Month == 2)
|
2008-08-01 17:43:53 +00:00
|
|
|
return MonthDays[Month - 1] + LeapYear(Year);
|
2006-06-23 08:13:50 +00:00
|
|
|
else
|
2008-08-01 17:43:53 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_1752
|
|
|
|
if ((Year == 1752) && (Month == 9))
|
2011-11-29 14:55:58 +00:00
|
|
|
return 19; // Special case: September 1752 has no 3rd-13th
|
2008-08-01 17:43:53 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
return MonthDays[Month - 1];
|
|
|
|
}
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static WORD
|
|
|
|
MonthCalWeekInMonth(IN WORD Day,
|
|
|
|
IN WORD DayOfWeek)
|
|
|
|
{
|
|
|
|
return (Day - DayOfWeek + 5) / 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WORD
|
|
|
|
MonthCalDayOfWeek(IN PMONTHCALWND infoPtr,
|
|
|
|
IN WORD Day,
|
|
|
|
IN WORD Month,
|
|
|
|
IN WORD Year)
|
|
|
|
{
|
|
|
|
const BYTE DayOfWeek[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
|
|
|
|
WORD Ret;
|
|
|
|
|
|
|
|
Year -= (Month < 3);
|
|
|
|
Ret = (Year + (Year / 4) - (Year / 100) + (Year / 400) + DayOfWeek[Month - 1] + Day + 6) % 7;
|
|
|
|
|
|
|
|
return (7 + Ret - infoPtr->FirstDayOfWeek) % 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WORD
|
|
|
|
MonthCalFirstDayOfWeek(VOID)
|
|
|
|
{
|
2007-07-31 22:17:07 +00:00
|
|
|
WCHAR szBuf[2] = {0};
|
2006-06-23 08:13:50 +00:00
|
|
|
WORD Ret = 0;
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
if (GetLocaleInfoW(LOCALE_USER_DEFAULT,
|
|
|
|
LOCALE_IFIRSTDAYOFWEEK,
|
|
|
|
szBuf,
|
|
|
|
sizeof(szBuf) / sizeof(szBuf[0])) != 0)
|
2006-06-23 08:13:50 +00:00
|
|
|
{
|
|
|
|
Ret = (WORD)(szBuf[0] - TEXT('0'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
MonthCalValidDate(IN WORD Day,
|
|
|
|
IN WORD Month,
|
|
|
|
IN WORD Year)
|
|
|
|
{
|
|
|
|
if (Month < 1 || Month > 12 ||
|
|
|
|
Day == 0 || Day > MonthCalMonthLength(Month,
|
|
|
|
Year) ||
|
2008-08-01 17:43:53 +00:00
|
|
|
Year < 1899 || Year > 9999)
|
2006-06-23 08:13:50 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalUpdate(IN PMONTHCALWND infoPtr)
|
|
|
|
{
|
|
|
|
PBYTE pDay, pDayEnd;
|
|
|
|
WORD DayOfWeek, MonthLength, d = 0;
|
|
|
|
SIZE NewCellSize;
|
|
|
|
BOOL RepaintHeader = FALSE;
|
|
|
|
|
|
|
|
NewCellSize.cx = infoPtr->ClientSize.cx / 7;
|
|
|
|
NewCellSize.cy = infoPtr->ClientSize.cy / 7;
|
|
|
|
|
|
|
|
if (infoPtr->CellSize.cx != NewCellSize.cx ||
|
|
|
|
infoPtr->CellSize.cy != NewCellSize.cy)
|
|
|
|
{
|
|
|
|
infoPtr->CellSize = NewCellSize;
|
|
|
|
RepaintHeader = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Update the days layout of the current month */
|
2006-06-23 08:13:50 +00:00
|
|
|
ZeroMemory(infoPtr->Days,
|
|
|
|
sizeof(infoPtr->Days));
|
|
|
|
|
|
|
|
DayOfWeek = MonthCalDayOfWeek(infoPtr,
|
|
|
|
1,
|
|
|
|
infoPtr->Month,
|
|
|
|
infoPtr->Year);
|
|
|
|
|
|
|
|
MonthLength = MonthCalMonthLength(infoPtr->Month,
|
|
|
|
infoPtr->Year);
|
|
|
|
|
|
|
|
pDay = &infoPtr->Days[0][DayOfWeek];
|
|
|
|
pDayEnd = pDay + MonthLength;
|
|
|
|
while (pDay != pDayEnd)
|
|
|
|
{
|
2007-04-30 19:05:04 +00:00
|
|
|
*(pDay++) = (BYTE)++d;
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Repaint the control */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (RepaintHeader)
|
|
|
|
{
|
|
|
|
InvalidateRect(infoPtr->hSelf,
|
|
|
|
NULL,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT rcClient;
|
|
|
|
|
|
|
|
rcClient.left = 0;
|
|
|
|
rcClient.top = infoPtr->CellSize.cy;
|
|
|
|
rcClient.right = infoPtr->ClientSize.cx;
|
2007-07-28 21:59:05 +00:00
|
|
|
rcClient.bottom = infoPtr->ClientSize.cy;
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
InvalidateRect(infoPtr->hSelf,
|
|
|
|
&rcClient,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalSetupDayTimer(IN PMONTHCALWND infoPtr)
|
|
|
|
{
|
|
|
|
SYSTEMTIME LocalTime = {0};
|
|
|
|
UINT uElapse;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Update the current date */
|
2006-06-23 08:13:50 +00:00
|
|
|
GetLocalTime(&LocalTime);
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Calculate the number of remaining milliseconds until midnight */
|
2006-06-23 08:13:50 +00:00
|
|
|
uElapse = 1000 - (UINT)LocalTime.wMilliseconds;
|
|
|
|
uElapse += (59 - (UINT)LocalTime.wSecond) * 1000;
|
|
|
|
uElapse += (59 - (UINT)LocalTime.wMinute) * 60 * 1000;
|
|
|
|
uElapse += (23 - (UINT)LocalTime.wHour) * 60 * 60 * 1000;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Setup the new timer */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (SetTimer(infoPtr->hSelf,
|
|
|
|
ID_DAYTIMER,
|
|
|
|
uElapse,
|
|
|
|
NULL) != 0)
|
|
|
|
{
|
|
|
|
infoPtr->DayTimerSet = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalReload(IN PMONTHCALWND infoPtr)
|
|
|
|
{
|
2007-07-31 22:17:07 +00:00
|
|
|
WCHAR szBuf[64];
|
2006-06-23 08:13:50 +00:00
|
|
|
UINT i;
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
infoPtr->UIState = (DWORD)SendMessageW(GetAncestor(infoPtr->hSelf,
|
|
|
|
GA_PARENT),
|
|
|
|
WM_QUERYUISTATE,
|
|
|
|
0,
|
|
|
|
0);
|
2006-06-23 08:13:50 +00:00
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Cache the configuration */
|
2006-06-23 08:13:50 +00:00
|
|
|
infoPtr->FirstDayOfWeek = MonthCalFirstDayOfWeek();
|
|
|
|
|
|
|
|
infoPtr->hbHeader = GetSysColorBrush(infoPtr->Enabled ? MONTHCAL_HEADERBG : MONTHCAL_DISABLED_HEADERBG);
|
|
|
|
infoPtr->hbSelection = GetSysColorBrush(infoPtr->Enabled ? MONTHCAL_SELBG : MONTHCAL_DISABLED_SELBG);
|
|
|
|
|
2007-06-07 16:18:38 +00:00
|
|
|
for (i = 0; i < 7; i++)
|
2006-06-23 08:13:50 +00:00
|
|
|
{
|
2007-07-31 22:17:07 +00:00
|
|
|
if (GetLocaleInfoW(LOCALE_USER_DEFAULT,
|
|
|
|
LOCALE_SABBREVDAYNAME1 +
|
|
|
|
((i + infoPtr->FirstDayOfWeek) % 7),
|
|
|
|
szBuf,
|
|
|
|
sizeof(szBuf) / sizeof(szBuf[0])) != 0)
|
2006-06-23 08:13:50 +00:00
|
|
|
{
|
|
|
|
infoPtr->Week[i] = szBuf[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Update the control */
|
2006-06-23 08:13:50 +00:00
|
|
|
MonthCalUpdate(infoPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
MonthCalGetDayRect(IN PMONTHCALWND infoPtr,
|
|
|
|
IN WORD Day,
|
|
|
|
OUT RECT *rcCell)
|
|
|
|
{
|
|
|
|
if (Day >= 1 && Day <= MonthCalMonthLength(infoPtr->Month,
|
|
|
|
infoPtr->Year))
|
|
|
|
{
|
|
|
|
WORD DayOfWeek;
|
|
|
|
|
|
|
|
DayOfWeek = MonthCalDayOfWeek(infoPtr,
|
|
|
|
Day,
|
|
|
|
infoPtr->Month,
|
|
|
|
infoPtr->Year);
|
|
|
|
|
|
|
|
rcCell->left = DayOfWeek * infoPtr->CellSize.cx;
|
|
|
|
rcCell->top = (MonthCalWeekInMonth(Day,
|
|
|
|
DayOfWeek) + 1) * infoPtr->CellSize.cy;
|
|
|
|
rcCell->right = rcCell->left + infoPtr->CellSize.cx;
|
|
|
|
rcCell->bottom = rcCell->top + infoPtr->CellSize.cy;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalChange(IN PMONTHCALWND infoPtr)
|
|
|
|
{
|
|
|
|
infoPtr->Changed = TRUE;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Kill the day timer */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (infoPtr->DayTimerSet)
|
|
|
|
{
|
|
|
|
KillTimer(infoPtr->hSelf,
|
|
|
|
ID_DAYTIMER);
|
|
|
|
infoPtr->DayTimerSet = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
MonthCalSetDate(IN PMONTHCALWND infoPtr,
|
|
|
|
IN WORD Day,
|
|
|
|
IN WORD Month,
|
|
|
|
IN WORD Year)
|
|
|
|
{
|
|
|
|
NMMCCSELCHANGE sc;
|
|
|
|
BOOL Ret = FALSE;
|
|
|
|
|
|
|
|
sc.OldDay = infoPtr->Day;
|
|
|
|
sc.OldMonth = infoPtr->Month;
|
|
|
|
sc.OldYear = infoPtr->Year;
|
|
|
|
sc.NewDay = Day;
|
|
|
|
sc.NewMonth = Month;
|
|
|
|
sc.NewYear = Year;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Notify the parent */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (!MonthCalNotifyControlParent(infoPtr,
|
|
|
|
MCCN_SELCHANGE,
|
|
|
|
&sc))
|
|
|
|
{
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Check if we actually need to update */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (infoPtr->Month != sc.NewMonth ||
|
|
|
|
infoPtr->Year != sc.NewYear)
|
|
|
|
{
|
|
|
|
infoPtr->Day = sc.NewDay;
|
|
|
|
infoPtr->Month = sc.NewMonth;
|
|
|
|
infoPtr->Year = sc.NewYear;
|
|
|
|
|
|
|
|
MonthCalChange(infoPtr);
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Repaint the entire control */
|
2006-06-23 08:13:50 +00:00
|
|
|
MonthCalUpdate(infoPtr);
|
|
|
|
|
|
|
|
Ret = TRUE;
|
|
|
|
}
|
|
|
|
else if (infoPtr->Day != sc.NewDay)
|
|
|
|
{
|
|
|
|
RECT rcUpdate;
|
|
|
|
|
|
|
|
infoPtr->Day = sc.NewDay;
|
|
|
|
|
|
|
|
MonthCalChange(infoPtr);
|
|
|
|
|
|
|
|
if (MonthCalGetDayRect(infoPtr,
|
|
|
|
sc.OldDay,
|
|
|
|
&rcUpdate))
|
|
|
|
{
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Repaint the day cells that need to be updated */
|
2006-06-23 08:13:50 +00:00
|
|
|
InvalidateRect(infoPtr->hSelf,
|
|
|
|
&rcUpdate,
|
|
|
|
TRUE);
|
|
|
|
if (MonthCalGetDayRect(infoPtr,
|
|
|
|
sc.NewDay,
|
|
|
|
&rcUpdate))
|
|
|
|
{
|
|
|
|
InvalidateRect(infoPtr->hSelf,
|
|
|
|
&rcUpdate,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ret = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalSetLocalTime(IN PMONTHCALWND infoPtr,
|
|
|
|
OUT SYSTEMTIME *Time)
|
|
|
|
{
|
|
|
|
NMMCCAUTOUPDATE au;
|
|
|
|
SYSTEMTIME LocalTime = {0};
|
|
|
|
|
|
|
|
GetLocalTime(&LocalTime);
|
|
|
|
|
|
|
|
au.SystemTime = LocalTime;
|
|
|
|
if (!MonthCalNotifyControlParent(infoPtr,
|
|
|
|
MCCN_AUTOUPDATE,
|
|
|
|
&au))
|
|
|
|
{
|
|
|
|
if (MonthCalSetDate(infoPtr,
|
|
|
|
LocalTime.wDay,
|
|
|
|
LocalTime.wMonth,
|
|
|
|
LocalTime.wYear))
|
|
|
|
{
|
|
|
|
infoPtr->Changed = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Kill the day timer */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (infoPtr->DayTimerSet)
|
|
|
|
{
|
|
|
|
KillTimer(infoPtr->hSelf,
|
|
|
|
ID_DAYTIMER);
|
|
|
|
infoPtr->DayTimerSet = FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Setup the new day timer */
|
2006-06-23 08:13:50 +00:00
|
|
|
MonthCalSetupDayTimer(infoPtr);
|
|
|
|
|
|
|
|
if (Time != NULL)
|
|
|
|
{
|
|
|
|
*Time = LocalTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalRepaintDay(IN PMONTHCALWND infoPtr,
|
|
|
|
IN WORD Day)
|
|
|
|
{
|
|
|
|
RECT rcCell;
|
|
|
|
|
|
|
|
if (MonthCalGetDayRect(infoPtr,
|
|
|
|
Day,
|
|
|
|
&rcCell))
|
|
|
|
{
|
|
|
|
InvalidateRect(infoPtr->hSelf,
|
|
|
|
&rcCell,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
MonthCalPaint(IN PMONTHCALWND infoPtr,
|
|
|
|
IN HDC hDC,
|
|
|
|
IN LPRECT prcUpdate)
|
|
|
|
{
|
2006-07-08 16:45:13 +00:00
|
|
|
LONG x, y;
|
2006-06-23 08:13:50 +00:00
|
|
|
RECT rcCell;
|
|
|
|
COLORREF crOldText, crOldCtrlText = CLR_INVALID;
|
|
|
|
HFONT hOldFont;
|
|
|
|
INT iOldBkMode;
|
|
|
|
|
|
|
|
#if MONTHCAL_CTRLBG != MONTHCAL_DISABLED_CTRLBG
|
|
|
|
if (!infoPtr->Enabled)
|
|
|
|
{
|
|
|
|
FillRect(hDC,
|
|
|
|
prcUpdate,
|
|
|
|
GetSysColorBrush(MONTHCAL_DISABLED_CTRLBG));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
iOldBkMode = SetBkMode(hDC,
|
|
|
|
TRANSPARENT);
|
|
|
|
hOldFont = (HFONT)SelectObject(hDC,
|
|
|
|
infoPtr->hFont);
|
|
|
|
|
|
|
|
for (y = prcUpdate->top / infoPtr->CellSize.cy;
|
|
|
|
y <= prcUpdate->bottom / infoPtr->CellSize.cy && y < 7;
|
|
|
|
y++)
|
|
|
|
{
|
|
|
|
rcCell.top = y * infoPtr->CellSize.cy;
|
|
|
|
rcCell.bottom = rcCell.top + infoPtr->CellSize.cy;
|
|
|
|
|
|
|
|
if (y == 0)
|
|
|
|
{
|
|
|
|
RECT rcHeader;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Paint the header */
|
2006-06-23 08:13:50 +00:00
|
|
|
rcHeader.left = prcUpdate->left;
|
|
|
|
rcHeader.top = rcCell.top;
|
|
|
|
rcHeader.right = prcUpdate->right;
|
|
|
|
rcHeader.bottom = rcCell.bottom;
|
|
|
|
|
|
|
|
FillRect(hDC,
|
|
|
|
&rcHeader,
|
|
|
|
infoPtr->hbHeader);
|
|
|
|
|
|
|
|
crOldText = SetTextColor(hDC,
|
|
|
|
GetSysColor(infoPtr->Enabled ? MONTHCAL_HEADERFG : MONTHCAL_DISABLED_HEADERFG));
|
|
|
|
|
|
|
|
for (x = prcUpdate->left / infoPtr->CellSize.cx;
|
|
|
|
x <= prcUpdate->right / infoPtr->CellSize.cx && x < 7;
|
|
|
|
x++)
|
|
|
|
{
|
|
|
|
rcCell.left = x * infoPtr->CellSize.cx;
|
|
|
|
rcCell.right = rcCell.left + infoPtr->CellSize.cx;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Write the first letter of each weekday */
|
2007-07-31 22:17:07 +00:00
|
|
|
DrawTextW(hDC,
|
|
|
|
&infoPtr->Week[x],
|
|
|
|
1,
|
|
|
|
&rcCell,
|
|
|
|
DT_SINGLELINE | DT_NOPREFIX | DT_CENTER | DT_VCENTER);
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetTextColor(hDC,
|
|
|
|
crOldText);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (crOldCtrlText == CLR_INVALID)
|
|
|
|
{
|
|
|
|
crOldCtrlText = SetTextColor(hDC,
|
2008-06-12 09:50:12 +00:00
|
|
|
GetSysColor(infoPtr->Enabled ? MONTHCAL_CTRLFG : MONTHCAL_DISABLED_CTRLFG));
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (x = prcUpdate->left / infoPtr->CellSize.cx;
|
|
|
|
x <= prcUpdate->right / infoPtr->CellSize.cx && x < 7;
|
|
|
|
x++)
|
|
|
|
{
|
|
|
|
UINT Day = infoPtr->Days[y - 1][x];
|
|
|
|
|
|
|
|
rcCell.left = x * infoPtr->CellSize.cx;
|
|
|
|
rcCell.right = rcCell.left + infoPtr->CellSize.cx;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Write the day number */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (Day != 0 && Day < 100)
|
|
|
|
{
|
2007-07-31 22:17:07 +00:00
|
|
|
WCHAR szDay[3];
|
2006-06-23 08:13:50 +00:00
|
|
|
INT szDayLen;
|
|
|
|
RECT rcText;
|
|
|
|
SIZE TextSize;
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
szDayLen = swprintf(szDay,
|
|
|
|
L"%lu",
|
2006-06-23 08:13:50 +00:00
|
|
|
Day);
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
if (GetTextExtentPoint32W(hDC,
|
|
|
|
szDay,
|
|
|
|
szDayLen,
|
|
|
|
&TextSize))
|
2006-06-23 08:13:50 +00:00
|
|
|
{
|
2008-12-07 21:52:22 +00:00
|
|
|
RECT rcHighlight = { 0, 0, 0, 0 };
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
rcText.left = rcCell.left + (infoPtr->CellSize.cx / 2) - (TextSize.cx / 2);
|
|
|
|
rcText.top = rcCell.top + (infoPtr->CellSize.cy / 2) - (TextSize.cy / 2);
|
|
|
|
rcText.right = rcText.left + TextSize.cx;
|
|
|
|
rcText.bottom = rcText.top + TextSize.cy;
|
|
|
|
|
|
|
|
if (Day == infoPtr->Day)
|
|
|
|
{
|
2007-11-01 17:41:00 +00:00
|
|
|
SIZE TextSel;
|
|
|
|
|
|
|
|
TextSel.cx = (infoPtr->CellSize.cx * 2) / 3;
|
|
|
|
TextSel.cy = (infoPtr->CellSize.cy * 3) / 4;
|
|
|
|
|
|
|
|
if (TextSel.cx < rcText.right - rcText.left)
|
|
|
|
TextSel.cx = rcText.right - rcText.left;
|
|
|
|
if (TextSel.cy < rcText.bottom - rcText.top)
|
|
|
|
TextSel.cy = rcText.bottom - rcText.top;
|
|
|
|
|
|
|
|
rcHighlight.left = rcCell.left + (infoPtr->CellSize.cx / 2) - (TextSel.cx / 2);
|
|
|
|
rcHighlight.right = rcHighlight.left + TextSel.cx;
|
|
|
|
rcHighlight.top = rcCell.top + (infoPtr->CellSize.cy / 2) - (TextSel.cy / 2);
|
|
|
|
rcHighlight.bottom = rcHighlight.top + TextSel.cy;
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
InflateRect(&rcHighlight,
|
|
|
|
GetSystemMetrics(SM_CXFOCUSBORDER),
|
|
|
|
GetSystemMetrics(SM_CYFOCUSBORDER));
|
|
|
|
|
|
|
|
if (!FillRect(hDC,
|
|
|
|
&rcHighlight,
|
|
|
|
infoPtr->hbSelection))
|
|
|
|
{
|
|
|
|
goto FailNoHighlight;
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Highlight the selected day */
|
2006-06-23 08:13:50 +00:00
|
|
|
crOldText = SetTextColor(hDC,
|
|
|
|
GetSysColor(infoPtr->Enabled ? MONTHCAL_SELFG : MONTHCAL_DISABLED_SELFG));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FailNoHighlight:
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Don't change the text color, we're not highlighting it... */
|
2006-06-23 08:13:50 +00:00
|
|
|
crOldText = CLR_INVALID;
|
|
|
|
}
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
TextOutW(hDC,
|
|
|
|
rcText.left,
|
|
|
|
rcText.top,
|
|
|
|
szDay,
|
|
|
|
szDayLen);
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
if (Day == infoPtr->Day && crOldText != CLR_INVALID)
|
|
|
|
{
|
|
|
|
if (infoPtr->HasFocus && infoPtr->Enabled && !(infoPtr->UIState & UISF_HIDEFOCUS))
|
|
|
|
{
|
|
|
|
COLORREF crOldBk;
|
|
|
|
|
|
|
|
crOldBk = SetBkColor(hDC,
|
|
|
|
GetSysColor(infoPtr->Enabled ? MONTHCAL_SELBG : MONTHCAL_DISABLED_SELBG));
|
|
|
|
|
|
|
|
DrawFocusRect(hDC,
|
|
|
|
&rcHighlight);
|
|
|
|
|
|
|
|
SetBkColor(hDC,
|
|
|
|
crOldBk);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTextColor(hDC,
|
|
|
|
crOldText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crOldCtrlText != CLR_INVALID)
|
|
|
|
{
|
|
|
|
SetTextColor(hDC,
|
|
|
|
crOldCtrlText);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetBkMode(hDC,
|
|
|
|
iOldBkMode);
|
|
|
|
SelectObject(hDC,
|
|
|
|
(HGDIOBJ)hOldFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HFONT
|
|
|
|
MonthCalChangeFont(IN PMONTHCALWND infoPtr,
|
|
|
|
IN HFONT hFont,
|
|
|
|
IN BOOL Redraw)
|
|
|
|
{
|
|
|
|
HFONT hOldFont = infoPtr->hFont;
|
|
|
|
infoPtr->hFont = hFont;
|
|
|
|
|
|
|
|
if (Redraw)
|
|
|
|
{
|
|
|
|
InvalidateRect(infoPtr->hSelf,
|
|
|
|
NULL,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hOldFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WORD
|
|
|
|
MonthCalPtToDay(IN PMONTHCALWND infoPtr,
|
2006-07-09 16:19:39 +00:00
|
|
|
IN INT x,
|
|
|
|
IN INT y)
|
2006-06-23 08:13:50 +00:00
|
|
|
{
|
|
|
|
WORD Ret = 0;
|
|
|
|
|
|
|
|
if (infoPtr->CellSize.cx != 0 && infoPtr->CellSize.cy != 0 &&
|
|
|
|
x >= 0 && y >= 0)
|
|
|
|
{
|
|
|
|
x /= infoPtr->CellSize.cx;
|
|
|
|
y /= infoPtr->CellSize.cy;
|
|
|
|
|
|
|
|
if (x < 7 && y != 0 && y < 7)
|
|
|
|
{
|
|
|
|
Ret = (WORD)infoPtr->Days[y - 1][x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK
|
|
|
|
MonthCalWndProc(IN HWND hwnd,
|
|
|
|
IN UINT uMsg,
|
|
|
|
IN WPARAM wParam,
|
|
|
|
IN LPARAM lParam)
|
|
|
|
{
|
|
|
|
PMONTHCALWND infoPtr;
|
|
|
|
LRESULT Ret = 0;
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
infoPtr = (PMONTHCALWND)GetWindowLongPtrW(hwnd,
|
|
|
|
0);
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
if (infoPtr == NULL && uMsg != WM_CREATE)
|
|
|
|
{
|
|
|
|
goto HandleDefaultMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
#if MONTHCAL_CTRLBG != MONTHCAL_DISABLED_CTRLBG
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
Ret = !infoPtr->Enabled;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
case WM_PRINTCLIENT:
|
|
|
|
{
|
|
|
|
if (infoPtr->CellSize.cx != 0 && infoPtr->CellSize.cy != 0)
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hDC;
|
|
|
|
|
|
|
|
if (wParam != 0)
|
|
|
|
{
|
|
|
|
if (!GetUpdateRect(hwnd,
|
|
|
|
&ps.rcPaint,
|
|
|
|
TRUE))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
hDC = (HDC)wParam;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hDC = BeginPaint(hwnd,
|
|
|
|
&ps);
|
|
|
|
if (hDC == NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MonthCalPaint(infoPtr,
|
|
|
|
hDC,
|
|
|
|
&ps.rcPaint);
|
|
|
|
|
|
|
|
if (wParam == 0)
|
|
|
|
{
|
|
|
|
EndPaint(hwnd,
|
|
|
|
&ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
{
|
|
|
|
WORD SelDay;
|
|
|
|
|
|
|
|
SelDay = MonthCalPtToDay(infoPtr,
|
|
|
|
GET_X_LPARAM(lParam),
|
|
|
|
GET_Y_LPARAM(lParam));
|
|
|
|
if (SelDay != 0 && SelDay != infoPtr->Day)
|
|
|
|
{
|
|
|
|
MonthCalSetDate(infoPtr,
|
|
|
|
SelDay,
|
|
|
|
infoPtr->Month,
|
|
|
|
infoPtr->Year);
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Fall through */
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
{
|
|
|
|
if (!infoPtr->HasFocus)
|
|
|
|
{
|
|
|
|
SetFocus(hwnd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
{
|
|
|
|
WORD NewDay = 0;
|
|
|
|
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_UP:
|
|
|
|
{
|
|
|
|
if (infoPtr->Day > 7)
|
|
|
|
{
|
|
|
|
NewDay = infoPtr->Day - 7;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VK_DOWN:
|
|
|
|
{
|
|
|
|
if (infoPtr->Day + 7 <= MonthCalMonthLength(infoPtr->Month,
|
|
|
|
infoPtr->Year))
|
|
|
|
{
|
|
|
|
NewDay = infoPtr->Day + 7;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VK_LEFT:
|
|
|
|
{
|
|
|
|
if (infoPtr->Day > 1)
|
|
|
|
{
|
|
|
|
NewDay = infoPtr->Day - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case VK_RIGHT:
|
|
|
|
{
|
|
|
|
if (infoPtr->Day < MonthCalMonthLength(infoPtr->Month,
|
|
|
|
infoPtr->Year))
|
|
|
|
{
|
|
|
|
NewDay = infoPtr->Day + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Update the selection */
|
2006-06-23 08:13:50 +00:00
|
|
|
if (NewDay != 0)
|
|
|
|
{
|
|
|
|
MonthCalSetDate(infoPtr,
|
|
|
|
NewDay,
|
|
|
|
infoPtr->Month,
|
|
|
|
infoPtr->Year);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto HandleDefaultMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_GETDLGCODE:
|
|
|
|
{
|
|
|
|
INT virtKey;
|
|
|
|
|
|
|
|
virtKey = (lParam != 0 ? (INT)((LPMSG)lParam)->wParam : 0);
|
|
|
|
switch (virtKey)
|
|
|
|
{
|
|
|
|
case VK_TAB:
|
|
|
|
{
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Change the UI status */
|
2007-07-31 22:17:07 +00:00
|
|
|
SendMessageW(GetAncestor(hwnd,
|
|
|
|
GA_PARENT),
|
|
|
|
WM_CHANGEUISTATE,
|
|
|
|
MAKEWPARAM(UIS_INITIALIZE,
|
|
|
|
0),
|
|
|
|
0);
|
2006-06-23 08:13:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ret |= DLGC_WANTARROWS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
{
|
|
|
|
infoPtr->HasFocus = TRUE;
|
|
|
|
MonthCalRepaintDay(infoPtr,
|
|
|
|
infoPtr->Day);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_KILLFOCUS:
|
|
|
|
{
|
|
|
|
infoPtr->HasFocus = FALSE;
|
|
|
|
MonthCalRepaintDay(infoPtr,
|
|
|
|
infoPtr->Day);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_UPDATEUISTATE:
|
|
|
|
{
|
2007-11-22 05:33:22 +00:00
|
|
|
DWORD OldUIState;
|
|
|
|
|
|
|
|
Ret = DefWindowProcW(hwnd,
|
|
|
|
uMsg,
|
|
|
|
wParam,
|
|
|
|
lParam);
|
|
|
|
|
|
|
|
OldUIState = infoPtr->UIState;
|
2006-06-23 08:13:50 +00:00
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case UIS_SET:
|
|
|
|
infoPtr->UIState |= HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UIS_CLEAR:
|
|
|
|
infoPtr->UIState &= ~HIWORD(wParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (infoPtr->UIState != OldUIState)
|
|
|
|
{
|
|
|
|
MonthCalRepaintDay(infoPtr,
|
|
|
|
infoPtr->Day);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCCM_SETDATE:
|
|
|
|
{
|
|
|
|
WORD Day, Month, Year, DaysCount;
|
|
|
|
|
|
|
|
Day = LOWORD(wParam);
|
|
|
|
Month = HIWORD(wParam);
|
|
|
|
Year = LOWORD(lParam);
|
|
|
|
|
|
|
|
if (Day == (WORD)-1)
|
|
|
|
Day = infoPtr->Day;
|
|
|
|
if (Month == (WORD)-1)
|
|
|
|
Month = infoPtr->Month;
|
|
|
|
if (Year == (WORD)-1)
|
|
|
|
Year = infoPtr->Year;
|
|
|
|
|
|
|
|
DaysCount = MonthCalMonthLength(Month,
|
|
|
|
Year);
|
|
|
|
if (Day > DaysCount)
|
|
|
|
Day = DaysCount;
|
|
|
|
|
|
|
|
if (MonthCalValidDate(Day,
|
|
|
|
Month,
|
|
|
|
Year))
|
|
|
|
{
|
|
|
|
if (Day != infoPtr->Day ||
|
|
|
|
Month != infoPtr->Month ||
|
|
|
|
Year != infoPtr->Year)
|
|
|
|
{
|
|
|
|
Ret = MonthCalSetDate(infoPtr,
|
|
|
|
Day,
|
|
|
|
Month,
|
|
|
|
Year);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCCM_GETDATE:
|
|
|
|
{
|
|
|
|
LPSYSTEMTIME lpSystemTime = (LPSYSTEMTIME)wParam;
|
|
|
|
|
|
|
|
lpSystemTime->wYear = infoPtr->Year;
|
|
|
|
lpSystemTime->wMonth = infoPtr->Month;
|
|
|
|
lpSystemTime->wDay = infoPtr->Day;
|
|
|
|
|
|
|
|
Ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCCM_RESET:
|
|
|
|
{
|
|
|
|
MonthCalSetLocalTime(infoPtr,
|
|
|
|
NULL);
|
|
|
|
Ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MCCM_CHANGED:
|
|
|
|
{
|
|
|
|
Ret = infoPtr->Changed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_TIMER:
|
|
|
|
{
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case ID_DAYTIMER:
|
|
|
|
{
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Kill the timer */
|
2006-06-23 08:13:50 +00:00
|
|
|
KillTimer(hwnd,
|
|
|
|
ID_DAYTIMER);
|
|
|
|
infoPtr->DayTimerSet = FALSE;
|
|
|
|
|
|
|
|
if (!infoPtr->Changed)
|
|
|
|
{
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Update the system time and setup the new day timer */
|
2006-06-23 08:13:50 +00:00
|
|
|
MonthCalSetLocalTime(infoPtr,
|
|
|
|
NULL);
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Update the control */
|
2006-06-23 08:13:50 +00:00
|
|
|
MonthCalUpdate(infoPtr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SETFONT:
|
|
|
|
{
|
|
|
|
Ret = (LRESULT)MonthCalChangeFont(infoPtr,
|
|
|
|
(HFONT)wParam,
|
|
|
|
(BOOL)LOWORD(lParam));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
{
|
|
|
|
infoPtr->ClientSize.cx = LOWORD(lParam);
|
|
|
|
infoPtr->ClientSize.cy = HIWORD(lParam);
|
|
|
|
infoPtr->CellSize.cx = infoPtr->ClientSize.cx / 7;
|
|
|
|
infoPtr->CellSize.cy = infoPtr->ClientSize.cy / 7;
|
|
|
|
|
2011-11-29 14:55:58 +00:00
|
|
|
/* Repaint the control */
|
2006-06-23 08:13:50 +00:00
|
|
|
InvalidateRect(hwnd,
|
|
|
|
NULL,
|
|
|
|
TRUE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_GETFONT:
|
|
|
|
{
|
|
|
|
Ret = (LRESULT)infoPtr->hFont;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_ENABLE:
|
|
|
|
{
|
|
|
|
infoPtr->Enabled = ((BOOL)wParam != FALSE);
|
|
|
|
MonthCalReload(infoPtr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_STYLECHANGED:
|
|
|
|
{
|
|
|
|
if (wParam == GWL_STYLE)
|
|
|
|
{
|
2006-07-08 16:45:13 +00:00
|
|
|
unsigned int OldEnabled = infoPtr->Enabled;
|
2006-06-23 08:13:50 +00:00
|
|
|
infoPtr->Enabled = !(((LPSTYLESTRUCT)lParam)->styleNew & WS_DISABLED);
|
|
|
|
|
|
|
|
if (OldEnabled != infoPtr->Enabled)
|
|
|
|
{
|
|
|
|
MonthCalReload(infoPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CREATE:
|
|
|
|
{
|
2006-12-18 14:22:43 +00:00
|
|
|
infoPtr = (MONTHCALWND*) HeapAlloc(GetProcessHeap(),
|
2006-06-23 08:13:50 +00:00
|
|
|
0,
|
|
|
|
sizeof(MONTHCALWND));
|
|
|
|
if (infoPtr == NULL)
|
|
|
|
{
|
|
|
|
Ret = (LRESULT)-1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
SetWindowLongPtrW(hwnd,
|
|
|
|
0,
|
|
|
|
(LONG_PTR)infoPtr);
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
ZeroMemory(infoPtr,
|
|
|
|
sizeof(MONTHCALWND));
|
|
|
|
|
|
|
|
infoPtr->hSelf = hwnd;
|
|
|
|
infoPtr->hNotify = ((LPCREATESTRUCTW)lParam)->hwndParent;
|
|
|
|
infoPtr->Enabled = !(((LPCREATESTRUCTW)lParam)->style & WS_DISABLED);
|
|
|
|
|
|
|
|
MonthCalSetLocalTime(infoPtr,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
MonthCalReload(infoPtr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(),
|
|
|
|
0,
|
|
|
|
infoPtr);
|
2007-07-31 22:17:07 +00:00
|
|
|
SetWindowLongPtrW(hwnd,
|
|
|
|
0,
|
|
|
|
(DWORD_PTR)NULL);
|
2006-06-23 08:13:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
HandleDefaultMessage:
|
2007-07-31 22:17:07 +00:00
|
|
|
Ret = DefWindowProcW(hwnd,
|
|
|
|
uMsg,
|
|
|
|
wParam,
|
|
|
|
lParam);
|
2006-06-23 08:13:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
RegisterMonthCalControl(IN HINSTANCE hInstance)
|
|
|
|
{
|
2007-07-31 22:17:07 +00:00
|
|
|
WNDCLASSW wc = {0};
|
2006-06-23 08:13:50 +00:00
|
|
|
|
|
|
|
wc.style = CS_DBLCLKS;
|
|
|
|
wc.lpfnWndProc = MonthCalWndProc;
|
|
|
|
wc.cbWndExtra = sizeof(PMONTHCALWND);
|
|
|
|
wc.hInstance = hInstance;
|
2007-07-31 22:17:07 +00:00
|
|
|
wc.hCursor = LoadCursorW(NULL,
|
|
|
|
(LPWSTR)IDC_ARROW);
|
2006-06-23 08:13:50 +00:00
|
|
|
wc.hbrBackground = (HBRUSH)(MONTHCAL_CTRLBG + 1);
|
|
|
|
wc.lpszClassName = szMonthCalWndClass;
|
|
|
|
|
2007-07-31 22:17:07 +00:00
|
|
|
return RegisterClassW(&wc) != 0;
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
UnregisterMonthCalControl(IN HINSTANCE hInstance)
|
|
|
|
{
|
2007-07-31 22:17:07 +00:00
|
|
|
UnregisterClassW(szMonthCalWndClass,
|
|
|
|
hInstance);
|
2006-06-23 08:13:50 +00:00
|
|
|
}
|