Commit 292e4153 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

kernel32: Simplify EnumDateFormats & EnumDateFormatsEx.

parent f1324529
......@@ -1742,93 +1742,126 @@ error:
* alternate calendars is determined.
*/
/**************************************************************************
* EnumDateFormatsExA (KERNEL32.@)
enum enum_callback_type {
CALLBACK_ENUMPROC,
CALLBACK_ENUMPROCEX,
CALLBACK_ENUMPROCEXEX
};
struct enumdateformats_context {
enum enum_callback_type type; /* callback kind */
union {
DATEFMT_ENUMPROCW callback; /* user callback pointer */
DATEFMT_ENUMPROCEXW callbackex;
} u;
LCID lcid; /* locale of interest */
DWORD flags;
BOOL unicode; /* A vs W callback type, only for regular and Ex callbacks */
};
/******************************************************************************
* NLS_EnumDateFormats <internal>
* Enumerates date formats for a specified locale.
*
* FIXME: MSDN mentions only LOCALE_USE_CP_ACP, should we handle
* LOCALE_NOUSEROVERRIDE here as well?
* PARAMS
* ctxt [I] enumeration context, see 'struct enumdateformats_context'
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Use GetLastError() to determine the cause.
*/
BOOL WINAPI EnumDateFormatsExA(DATEFMT_ENUMPROCEXA proc, LCID lcid, DWORD flags)
static BOOL NLS_EnumDateFormats(const struct enumdateformats_context *ctxt)
{
WCHAR bufW[256];
char bufA[256];
LCTYPE lctype;
CALID cal_id;
char buf[256];
INT ret;
if (!proc)
if (!ctxt->u.callback)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (!GetLocaleInfoW(lcid, LOCALE_ICALENDARTYPE|LOCALE_RETURN_NUMBER, (LPWSTR)&cal_id, sizeof(cal_id)/sizeof(WCHAR)))
if (!GetLocaleInfoW(ctxt->lcid, LOCALE_ICALENDARTYPE|LOCALE_RETURN_NUMBER, (LPWSTR)&cal_id, sizeof(cal_id)/sizeof(WCHAR)))
return FALSE;
switch (flags & ~LOCALE_USE_CP_ACP)
switch (ctxt->flags & ~LOCALE_USE_CP_ACP)
{
case 0:
case DATE_SHORTDATE:
if (GetLocaleInfoA(lcid, LOCALE_SSHORTDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf, cal_id);
lctype = LOCALE_SSHORTDATE;
break;
case DATE_LONGDATE:
if (GetLocaleInfoA(lcid, LOCALE_SLONGDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf, cal_id);
lctype = LOCALE_SLONGDATE;
break;
case DATE_YEARMONTH:
if (GetLocaleInfoA(lcid, LOCALE_SYEARMONTH | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf, cal_id);
lctype = LOCALE_SYEARMONTH;
break;
default:
FIXME("Unknown date format (%d)\n", flags);
FIXME("Unknown date format (0x%08x)\n", ctxt->flags);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
lctype |= ctxt->flags & LOCALE_USE_CP_ACP;
if (ctxt->unicode)
ret = GetLocaleInfoW(ctxt->lcid, lctype, bufW, sizeof(bufW)/sizeof(bufW[0]));
else
ret = GetLocaleInfoA(ctxt->lcid, lctype, bufA, sizeof(bufA)/sizeof(bufA[0]));
if (ret)
{
switch (ctxt->type)
{
case CALLBACK_ENUMPROC:
ctxt->u.callback(ctxt->unicode ? bufW : (WCHAR*)bufA);
break;
case CALLBACK_ENUMPROCEX:
ctxt->u.callbackex(ctxt->unicode ? bufW : (WCHAR*)bufA, cal_id);
break;
default:
;
}
}
return TRUE;
}
/**************************************************************************
* EnumDateFormatsExW (KERNEL32.@)
* EnumDateFormatsExA (KERNEL32.@)
*
* FIXME: MSDN mentions only LOCALE_USE_CP_ACP, should we handle
* LOCALE_NOUSEROVERRIDE here as well?
*/
BOOL WINAPI EnumDateFormatsExW(DATEFMT_ENUMPROCEXW proc, LCID lcid, DWORD flags)
BOOL WINAPI EnumDateFormatsExA(DATEFMT_ENUMPROCEXA proc, LCID lcid, DWORD flags)
{
CALID cal_id;
WCHAR buf[256];
struct enumdateformats_context ctxt;
if (!proc)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
ctxt.type = CALLBACK_ENUMPROCEX;
ctxt.u.callbackex = (DATEFMT_ENUMPROCEXW)proc;
ctxt.lcid = lcid;
ctxt.flags = flags;
ctxt.unicode = FALSE;
if (!GetLocaleInfoW(lcid, LOCALE_ICALENDARTYPE|LOCALE_RETURN_NUMBER, (LPWSTR)&cal_id, sizeof(cal_id)/sizeof(WCHAR)))
return FALSE;
return NLS_EnumDateFormats(&ctxt);
}
switch (flags & ~LOCALE_USE_CP_ACP)
{
case 0:
case DATE_SHORTDATE:
if (GetLocaleInfoW(lcid, LOCALE_SSHORTDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf, cal_id);
break;
/**************************************************************************
* EnumDateFormatsExW (KERNEL32.@)
*/
BOOL WINAPI EnumDateFormatsExW(DATEFMT_ENUMPROCEXW proc, LCID lcid, DWORD flags)
{
struct enumdateformats_context ctxt;
case DATE_LONGDATE:
if (GetLocaleInfoW(lcid, LOCALE_SLONGDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf, cal_id);
break;
ctxt.type = CALLBACK_ENUMPROCEX;
ctxt.u.callbackex = proc;
ctxt.lcid = lcid;
ctxt.flags = flags;
ctxt.unicode = TRUE;
case DATE_YEARMONTH:
if (GetLocaleInfoW(lcid, LOCALE_SYEARMONTH | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf, cal_id);
break;
default:
FIXME("Unknown date format (%d)\n", flags);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return TRUE;
return NLS_EnumDateFormats(&ctxt);
}
/**************************************************************************
......@@ -1839,38 +1872,15 @@ BOOL WINAPI EnumDateFormatsExW(DATEFMT_ENUMPROCEXW proc, LCID lcid, DWORD flags)
*/
BOOL WINAPI EnumDateFormatsA(DATEFMT_ENUMPROCA proc, LCID lcid, DWORD flags)
{
char buf[256];
if (!proc)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
switch (flags & ~LOCALE_USE_CP_ACP)
{
case 0:
case DATE_SHORTDATE:
if (GetLocaleInfoA(lcid, LOCALE_SSHORTDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf);
break;
case DATE_LONGDATE:
if (GetLocaleInfoA(lcid, LOCALE_SLONGDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf);
break;
struct enumdateformats_context ctxt;
case DATE_YEARMONTH:
if (GetLocaleInfoA(lcid, LOCALE_SYEARMONTH | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf);
break;
ctxt.type = CALLBACK_ENUMPROC;
ctxt.u.callback = (DATEFMT_ENUMPROCW)proc;
ctxt.lcid = lcid;
ctxt.flags = flags;
ctxt.unicode = FALSE;
default:
FIXME("Unknown date format (%d)\n", flags);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return TRUE;
return NLS_EnumDateFormats(&ctxt);
}
/**************************************************************************
......@@ -1878,38 +1888,15 @@ BOOL WINAPI EnumDateFormatsA(DATEFMT_ENUMPROCA proc, LCID lcid, DWORD flags)
*/
BOOL WINAPI EnumDateFormatsW(DATEFMT_ENUMPROCW proc, LCID lcid, DWORD flags)
{
WCHAR buf[256];
if (!proc)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
struct enumdateformats_context ctxt;
switch (flags & ~LOCALE_USE_CP_ACP)
{
case 0:
case DATE_SHORTDATE:
if (GetLocaleInfoW(lcid, LOCALE_SSHORTDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf);
break;
ctxt.type = CALLBACK_ENUMPROC;
ctxt.u.callback = proc;
ctxt.lcid = lcid;
ctxt.flags = flags;
ctxt.unicode = TRUE;
case DATE_LONGDATE:
if (GetLocaleInfoW(lcid, LOCALE_SLONGDATE | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf);
break;
case DATE_YEARMONTH:
if (GetLocaleInfoW(lcid, LOCALE_SYEARMONTH | (flags & LOCALE_USE_CP_ACP), buf, 256))
proc(buf);
break;
default:
FIXME("Unknown date format (%d)\n", flags);
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return TRUE;
return NLS_EnumDateFormats(&ctxt);
}
/**************************************************************************
......@@ -1971,14 +1958,8 @@ BOOL WINAPI EnumTimeFormatsW(TIMEFMT_ENUMPROCW proc, LCID lcid, DWORD flags)
return TRUE;
}
enum enumcalendar_callback_type {
CALLBACK_ENUMPROC,
CALLBACK_ENUMPROCEX,
CALLBACK_ENUMPROCEXEX
};
struct enumcalendar_context {
enum enumcalendar_callback_type type; /* callback kind */
enum enum_callback_type type; /* callback kind */
union {
CALINFO_ENUMPROCW callback; /* user callback pointer */
CALINFO_ENUMPROCEXW callbackex;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment