diff options
author | Tor Lillqvist <tml@novell.com> | 2005-11-28 01:42:45 +0000 |
---|---|---|
committer | Tor Lillqvist <tml@src.gnome.org> | 2005-11-28 01:42:45 +0000 |
commit | d3020806567e900991d313dd73d4759312b8db26 (patch) | |
tree | 2bd467b5614701026d7f586792743cbb351167b3 | |
parent | baa523023c61ba2031ab298c902d571ef8e51bf6 (diff) | |
download | gdk-pixbuf-d3020806567e900991d313dd73d4759312b8db26.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)
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 9 | ||||
-rw-r--r-- | gtk/gtkcalendar.c | 51 |
3 files changed, 69 insertions, 0 deletions
@@ -1,3 +1,12 @@ +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) + 2005-11-27 Matthias Clasen <mclasen@redhat.com> * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6eed6109b..72812b90d 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +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) + 2005-11-27 Matthias Clasen <mclasen@redhat.com> * gtk/gtkmessagedialog.c (gtk_message_dialog_new_with_markup): diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c index 9cf044eaa..a189ef4cc 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 */ |