summaryrefslogtreecommitdiff
path: root/gtk/gtkcalendar.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2005-11-28 01:51:08 +0000
committerTor Lillqvist <tml@src.gnome.org>2005-11-28 01:51:08 +0000
commit954deb7bf3df039e24cd01b65b0fa2be287898c7 (patch)
tree9bfe5b07d302d9b9730d5e7669aea0ab8270c3ff /gtk/gtkcalendar.c
parentd3a05fe03c3b5a032ad5b9e010de1376d1ad5d28 (diff)
downloadgtk+-954deb7bf3df039e24cd01b65b0fa2be287898c7.tar.gz
Use GetLocaleInfo() on Windows to get the localized weekday and month
2005-11-28 Tor Lillqvist <tml@novell.com> * gtk/gtkcalendar.c (gtk_calendar_init): Use GetLocaleInfo() on Windows to get the localized weekday and month names. strftime() in the Microsoft C library returns strings in the default codepage for the locale of the process, not the system codepage. Thus g_locale_to_utf8() isn't useable on the return value from strftime(). (#322603)
Diffstat (limited to 'gtk/gtkcalendar.c')
-rw-r--r--gtk/gtkcalendar.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 34d76269e1..18cac6fdd4 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -40,6 +40,13 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
+
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
#include <glib/gprintf.h>
#undef GTK_DISABLE_DEPRECATED
@@ -562,7 +569,11 @@ gtk_calendar_init (GtkCalendar *calendar)
struct tm *tm;
gint i;
char buffer[255];
+#ifdef G_OS_WIN32
+ wchar_t wbuffer[100];
+#else
time_t tmp_time;
+#endif
GtkCalendarPrivate *priv;
gchar *year_before;
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
@@ -583,17 +594,57 @@ gtk_calendar_init (GtkCalendar *calendar)
if (!default_abbreviated_dayname[0])
for (i=0; i<7; i++)
{
+#ifndef G_OS_WIN32
tmp_time= (i+3)*86400;
strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#else
+ if (G_WIN32_HAVE_WIDECHAR_API ())
+ {
+ if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
+ wbuffer, G_N_ELEMENTS (wbuffer)))
+ default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
+ else
+ default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+ }
+ else
+ {
+ if (!GetLocaleInfoA (GetThreadLocale (),
+ (LOCALE_SABBREVDAYNAME1 + (i+6)%7) | LOCALE_USE_CP_ACP,
+ buffer, G_N_ELEMENTS (buffer)))
+ default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
+ else
+ default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+ }
+#endif
}
if (!default_monthname[0])
for (i=0; i<12; i++)
{
+#ifndef G_OS_WIN32
tmp_time=i*2764800;
strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#else
+ if (G_WIN32_HAVE_WIDECHAR_API ())
+ {
+ if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
+ wbuffer, G_N_ELEMENTS (wbuffer)))
+ default_monthname[i] = g_strdup_printf ("(%d)", i);
+ else
+ default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+ }
+ else
+ {
+ if (!GetLocaleInfoA (GetThreadLocale (),
+ (LOCALE_SMONTHNAME1 + i) | LOCALE_USE_CP_ACP,
+ buffer, G_N_ELEMENTS (buffer)))
+ default_monthname[i] = g_strdup_printf ("(%d)", i);
+ else
+ default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+ }
+#endif
}
/* Set defaults */