MonthCal unicodification.

This commit is contained in:
Dimitrie O. Paun 2005-04-11 14:21:00 +00:00 committed by Alexandre Julliard
parent 016206c1e1
commit 30a66a051c
1 changed files with 74 additions and 74 deletions

View File

@ -33,7 +33,6 @@
* TODO:
* -- MCM_[GS]ETUNICODEFORMAT
* -- MONTHCAL_GetMonthRange
* -- Unicodification
* -- handle resources better (doesn't work now);
* -- take care of internationalization.
* -- keyboard handling.
@ -56,6 +55,7 @@
#include "winnls.h"
#include "commctrl.h"
#include "comctl32.h"
#include "wine/unicode.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
@ -70,6 +70,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(monthcal);
#define MC_NEXTMONTHTIMER 1 /* Timer ID's */
#define MC_PREVMONTHTIMER 2
#define countof(arr) (sizeof(arr)/sizeof(arr[0]))
typedef struct
{
HWND hwndSelf;
@ -333,14 +335,15 @@ static void MONTHCAL_CircleDay(MONTHCAL_INFO *infoPtr, HDC hdc, int day, int mon
static void MONTHCAL_DrawDay(MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month,
int x, int y, int bold)
{
char buf[10];
static const WCHAR fmtW[] = { '%','d',0 };
WCHAR buf[10];
RECT r;
static int haveBoldFont, haveSelectedDay = FALSE;
HBRUSH hbr;
COLORREF oldCol = 0;
COLORREF oldBk = 0;
sprintf(buf, "%d", day);
wsprintfW(buf, fmtW, day);
/* No need to check styles: when selection is not valid, it is set to zero.
* 1<day<31, so evertyhing's OK.
@ -390,7 +393,7 @@ static void MONTHCAL_DrawDay(MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month
}
SetBkMode(hdc,TRANSPARENT);
DrawTextA(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
DrawTextW(hdc, buf, -1, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
/* draw a rectangle around the currently selected days text */
if((day==infoPtr->curSelDay) && (month==infoPtr->currentMonth))
@ -400,6 +403,10 @@ static void MONTHCAL_DrawDay(MONTHCAL_INFO *infoPtr, HDC hdc, int day, int month
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;
@ -413,9 +420,9 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
SIZE size;
HBRUSH hbr;
HFONT currentFont;
char buf[20];
char buf1[20];
char buf2[32];
WCHAR buf[20];
WCHAR buf1[20];
WCHAR buf2[32];
COLORREF oldTextColor, oldBkColor;
DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
RECT rcTemp;
@ -470,13 +477,13 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
titlemonth->left = title->left;
titlemonth->right = title->right;
GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
buf1,sizeof(buf1));
sprintf(buf, "%s %ld", buf1, infoPtr->currentYear);
GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+infoPtr->currentMonth -1,
buf1,countof(buf1));
wsprintfW(buf, fmt1W, buf1, infoPtr->currentYear);
if(IntersectRect(&rcTemp, &(ps->rcPaint), titlemonth))
{
DrawTextA(hdc, buf, strlen(buf), titlemonth,
DrawTextW(hdc, buf, strlenW(buf), titlemonth,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
@ -486,10 +493,10 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
* MCM_HitTestInfo wants month & year rects, so prepare these now.
*(no, we can't draw them separately; the whole text is centered)
*/
GetTextExtentPoint32A(hdc, buf, strlen(buf), &size);
GetTextExtentPoint32W(hdc, buf, strlenW(buf), &size);
titlemonth->left = title->right / 2 - size.cx / 2;
titleyear->right = title->right / 2 + size.cx / 2;
GetTextExtentPoint32A(hdc, buf1, strlen(buf1), &size);
GetTextExtentPoint32W(hdc, buf1, strlenW(buf1), &size);
titlemonth->right = titlemonth->left + size.cx;
titleyear->left = titlemonth->right;
@ -530,10 +537,8 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
i = infoPtr->firstDay;
for(j=0; j<7; j++) {
GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i +j)%7,
buf,sizeof(buf));
DrawTextA(hdc, buf, strlen(buf), days,
DT_CENTER | DT_VCENTER | DT_SINGLELINE );
GetLocaleInfoW( LOCALE_USER_DEFAULT,LOCALE_SABBREVDAYNAME1 + (i +j)%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;
}
@ -657,21 +662,21 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
infoPtr->currentMonth);
offset+=textWidth;
}
if (!LoadStringA(COMCTL32_hModule,IDM_TODAY,buf1,sizeof(buf1)))
if (!LoadStringW(COMCTL32_hModule,IDM_TODAY,buf1,countof(buf1)))
{
WARN("Can't load resource\n");
strcpy(buf1,"Today:");
strcpyW(buf1, todayW);
}
MONTHCAL_CalcDayRect(infoPtr, &rtoday, 1, 6);
MONTHCAL_CopyTime(&infoPtr->todaysDate,&localtime);
GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,sizeof(buf2));
sprintf(buf, "%s %s", buf1,buf2);
GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&localtime,NULL,buf2,countof(buf2));
wsprintfW(buf, fmt2W, buf1, buf2);
SelectObject(hdc, infoPtr->hBoldFont);
if(IntersectRect(&rcTemp, &(ps->rcPaint), &rtoday))
{
DrawTextA(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
DrawTextA(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
DrawTextW(hdc, buf, -1, &rtoday, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE);
DrawTextW(hdc, buf, -1, &rtoday, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
}
SelectObject(hdc, infoPtr->hFont);
}
@ -689,9 +694,8 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
LOCALE_IFIRSTWEEKOFYEAR == 1 (what contries?)
The first week of the year must contain only days of the new year
*/
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR,
buf, sizeof(buf));
sscanf(buf, "%d", &weeknum);
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTWEEKOFYEAR, buf, countof(buf));
weeknum = atoiW(buf);
switch (weeknum)
{
case 1: mindays = 6;
@ -738,16 +742,16 @@ static void MONTHCAL_Refresh(MONTHCAL_INFO *infoPtr, HDC hdc, PAINTSTRUCT* ps)
for(i=0; i<6; i++) {
if((i==0)&&(weeknum>50))
{
sprintf(buf, "%d", weeknum);
wsprintfW(buf, fmt3W, weeknum);
weeknum=0;
}
else if((i==5)&&(weeknum>47))
{
sprintf(buf, "%d", 1);
wsprintfW(buf, fmt3W, 1);
}
else
sprintf(buf, "%d", weeknum + i);
DrawTextA(hdc, buf, -1, days, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
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;
}
@ -889,8 +893,7 @@ static LRESULT
MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, LPARAM lParam)
{
int prev = infoPtr->firstDay;
char buf[40];
int day;
WCHAR buf[40];
TRACE("day %ld\n", lParam);
@ -899,13 +902,9 @@ MONTHCAL_SetFirstDayOfWeek(MONTHCAL_INFO *infoPtr, LPARAM lParam)
}
else
{
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK,
buf, sizeof(buf));
TRACE("%s %d\n", buf, strlen(buf));
if(sscanf(buf, "%d", &day) == 1)
infoPtr->firstDay = day;
else
infoPtr->firstDay = 0;
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, buf, countof(buf));
TRACE("%s %d\n", debugstr_w(buf), strlenW(buf));
infoPtr->firstDay = atoiW(buf);
}
return prev;
}
@ -1279,7 +1278,7 @@ static void MONTHCAL_GoToNextMonth(MONTHCAL_INFO *infoPtr)
nmds.cDayState = infoPtr->monthRange;
nmds.prgDayState = Alloc(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
(WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
for(i=0; i<infoPtr->monthRange; i++)
infoPtr->monthdayState[i] = nmds.prgDayState[i];
@ -1310,7 +1309,7 @@ static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO *infoPtr)
nmds.prgDayState = Alloc
(infoPtr->monthRange * sizeof(MONTHDAYSTATE));
SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
(WPARAM)nmds.nmhdr.idFrom, (LPARAM)&nmds);
for(i=0; i<infoPtr->monthRange; i++)
infoPtr->monthdayState[i] = nmds.prgDayState[i];
@ -1320,17 +1319,18 @@ static void MONTHCAL_GoToPrevMonth(MONTHCAL_INFO *infoPtr)
static LRESULT
MONTHCAL_RButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
{
static const WCHAR todayW[] = { 'G','o',' ','t','o',' ','T','o','d','a','y',':',0 };
HMENU hMenu;
POINT menupoint;
char buf[32];
WCHAR buf[32];
hMenu = CreatePopupMenu();
if (!LoadStringA(COMCTL32_hModule,IDM_GOTODAY,buf,sizeof(buf)))
if (!LoadStringW(COMCTL32_hModule,IDM_GOTODAY,buf,countof(buf)))
{
WARN("Can't load resource\n");
strcpy(buf,"Go to Today:");
strcpyW(buf, todayW);
}
AppendMenuA(hMenu, MF_STRING|MF_ENABLED,1, buf);
AppendMenuW(hMenu, MF_STRING|MF_ENABLED,1, buf);
menupoint.x=(INT)LOWORD(lParam);
menupoint.y=(INT)HIWORD(lParam);
ClientToScreen(infoPtr->hwndSelf, &menupoint);
@ -1347,11 +1347,12 @@ MONTHCAL_RButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
static LRESULT
MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
{
static const WCHAR EditW[] = { 'E','D','I','T',0 };
MCHITTESTINFO ht;
DWORD hit;
HMENU hMenu;
RECT rcDay; /* used in determining area to invalidate */
char buf[32];
WCHAR buf[32];
int i;
POINT menupoint;
@ -1359,7 +1360,7 @@ MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
if (infoPtr->hWndYearUpDown)
{
infoPtr->currentYear=SendMessageA( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)0);
infoPtr->currentYear=SendMessageW( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)0);
if(!DestroyWindow(infoPtr->hWndYearUpDown))
{
FIXME("Can't destroy Updown Control\n");
@ -1402,9 +1403,8 @@ MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
for (i=0; i<12;i++)
{
GetLocaleInfoA( LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+i,
buf,sizeof(buf));
AppendMenuA(hMenu, MF_STRING|MF_ENABLED,i+1, buf);
GetLocaleInfoW(LOCALE_USER_DEFAULT,LOCALE_SMONTHNAME1+i, buf,countof(buf));
AppendMenuW(hMenu, MF_STRING|MF_ENABLED,i+1, buf);
}
menupoint.x=infoPtr->titlemonth.right;
menupoint.y=infoPtr->titlemonth.bottom;
@ -1418,8 +1418,8 @@ MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
}
}
if(hit == MCHT_TITLEYEAR) {
infoPtr->hWndYearEdit=CreateWindowExA(0,
"EDIT",
infoPtr->hWndYearEdit=CreateWindowExW(0,
EditW,
0,
WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT,
infoPtr->titleyear.left+3,infoPtr->titlebtnnext.top,
@ -1429,8 +1429,8 @@ MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
NULL,
NULL,
NULL);
infoPtr->hWndYearUpDown=CreateWindowExA(0,
UPDOWN_CLASSA,
infoPtr->hWndYearUpDown=CreateWindowExW(0,
UPDOWN_CLASSW,
0,
WS_VISIBLE | WS_CHILD |UDS_SETBUDDYINT|UDS_NOTHOUSANDS|UDS_ARROWKEYS,
infoPtr->titleyear.right+6,infoPtr->titlebtnnext.top,
@ -1440,9 +1440,9 @@ MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
NULL,
NULL,
NULL);
SendMessageA( infoPtr->hWndYearUpDown, UDM_SETRANGE, (WPARAM) 0, MAKELONG (9999, 1753));
SendMessageA( infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM) infoPtr->hWndYearEdit, (LPARAM)0 );
SendMessageA( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)infoPtr->currentYear );
SendMessageW( infoPtr->hWndYearUpDown, UDM_SETRANGE, (WPARAM) 0, MAKELONG (9999, 1753));
SendMessageW( infoPtr->hWndYearUpDown, UDM_SETBUDDY, (WPARAM) infoPtr->hWndYearEdit, (LPARAM)0 );
SendMessageW( infoPtr->hWndYearUpDown, UDM_SETPOS, (WPARAM) 0,(LPARAM)infoPtr->currentYear );
return TRUE;
}
@ -1467,7 +1467,7 @@ MONTHCAL_LButtonDown(MONTHCAL_INFO *infoPtr, LPARAM lParam)
MONTHCAL_CopyTime(&infoPtr->minSel,&nmsc.stSelStart);
MONTHCAL_CopyTime(&infoPtr->maxSel,&nmsc.stSelEnd);
SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
(WPARAM)nmsc.nmhdr.idFrom,(LPARAM)&nmsc);
@ -1533,8 +1533,7 @@ MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
nmhdr.code = NM_RELEASEDCAPTURE;
TRACE("Sent notification from %p to %p\n", infoPtr->hwndSelf, infoPtr->hwndNotify);
SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
(WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
/* redraw if necessary */
if(redraw)
InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
@ -1546,8 +1545,7 @@ MONTHCAL_LButtonUp(MONTHCAL_INFO *infoPtr, LPARAM lParam)
MONTHCAL_CopyTime(&infoPtr->minSel, &nmsc.stSelStart);
MONTHCAL_CopyTime(&infoPtr->maxSel, &nmsc.stSelEnd);
SendMessageA(infoPtr->hwndNotify, WM_NOTIFY,
(WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, (WPARAM)nmsc.nmhdr.idFrom, (LPARAM)&nmsc);
}
return 0;
@ -1700,6 +1698,8 @@ MONTHCAL_SetFocus(MONTHCAL_INFO *infoPtr)
/* sets the size information */
static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
{
static const WCHAR SunW[] = { 'S','u','n',0 };
static const WCHAR O0W[] = { '0','0',0 };
HDC hdc = GetDC(infoPtr->hwndSelf);
RECT *title=&infoPtr->title;
RECT *prev=&infoPtr->titlebtnprev;
@ -1711,7 +1711,7 @@ static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
RECT *days=&infoPtr->days;
RECT *todayrect=&infoPtr->todayrect;
SIZE size;
TEXTMETRICA tm;
TEXTMETRICW tm;
DWORD dwStyle = GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE);
HFONT currentFont;
int xdiv, left_offset;
@ -1722,13 +1722,13 @@ static void MONTHCAL_UpdateSize(MONTHCAL_INFO *infoPtr)
currentFont = SelectObject(hdc, infoPtr->hFont);
/* get the height and width of each day's text */
GetTextMetricsA(hdc, &tm);
GetTextMetricsW(hdc, &tm);
infoPtr->textHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
GetTextExtentPoint32A(hdc, "Sun", 3, &size);
GetTextExtentPoint32W(hdc, SunW, 3, &size);
infoPtr->textWidth = size.cx + 2;
/* recalculate the height and width increments and offsets */
GetTextExtentPoint32A(hdc, "00", 2, &size);
GetTextExtentPoint32W(hdc, O0W, 2, &size);
xdiv = (dwStyle & MCS_WEEKNUMBERS) ? 8 : 7;
@ -1899,7 +1899,7 @@ MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
infoPtr = MONTHCAL_GetInfoPtr(hwnd);
if (!infoPtr && (uMsg != WM_CREATE))
return DefWindowProcA(hwnd, uMsg, wParam, lParam);
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
switch(uMsg)
{
case MCM_GETCURSEL:
@ -2010,7 +2010,7 @@ MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
default:
if ((uMsg >= WM_USER) && (uMsg < WM_APP))
ERR( "unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
return DefWindowProcA(hwnd, uMsg, wParam, lParam);
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
}
@ -2018,23 +2018,23 @@ MONTHCAL_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
void
MONTHCAL_Register(void)
{
WNDCLASSA wndClass;
WNDCLASSW wndClass;
ZeroMemory(&wndClass, sizeof(WNDCLASSA));
ZeroMemory(&wndClass, sizeof(WNDCLASSW));
wndClass.style = CS_GLOBALCLASS;
wndClass.lpfnWndProc = MONTHCAL_WindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = sizeof(MONTHCAL_INFO *);
wndClass.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndClass.lpszClassName = MONTHCAL_CLASSA;
wndClass.lpszClassName = MONTHCAL_CLASSW;
RegisterClassA(&wndClass);
RegisterClassW(&wndClass);
}
void
MONTHCAL_Unregister(void)
{
UnregisterClassA(MONTHCAL_CLASSA, NULL);
UnregisterClassW(MONTHCAL_CLASSW, NULL);
}