summaryrefslogtreecommitdiff
path: root/gtk/gtkcalendar.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2006-10-07 21:32:53 +0000
committerTor Lillqvist <tml@src.gnome.org>2006-10-07 21:32:53 +0000
commite4581869b4a93ab882439673159a8f77b2396e57 (patch)
tree8c6988b033ea422270fa493719e1e9abcef5dc5a /gtk/gtkcalendar.c
parentc52d217e07ddc2d3e236fd0a9d1749c3ba7c01df (diff)
downloadgtk+-e4581869b4a93ab882439673159a8f77b2396e57.tar.gz
Use the Win32 thread locale's first day of week setting on Win32.
2006-10-07 Tor Lillqvist <tml@novell.com> * gtk/gtkcalendar.c (gtk_calendar_init): Use the Win32 thread locale's first day of week setting on Win32. (#339752, Bogdan Nicula) Don't do this if one of the environment variables that affect gettext is set, though. In that case use the week start day from the corresponding message catalog. Unfortunately the same logic isn't possible in the weekday and month name lookup; there even if you have set one of the aforementioned environment variables, you still get the weekday and month names from the Win32 thread locale. Yes, this is inconsistent. Use only wide-character API in the Win32 code in this file, too.
Diffstat (limited to 'gtk/gtkcalendar.c')
-rw-r--r--gtk/gtkcalendar.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 13762a0604..3effc22b92 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -560,10 +560,10 @@ gtk_calendar_init (GtkCalendar *calendar)
time_t secs;
struct tm *tm;
gint i;
- char buffer[255];
#ifdef G_OS_WIN32
wchar_t wbuffer[100];
#else
+ char buffer[255];
time_t tmp_time;
#endif
GtkCalendarPrivate *priv;
@@ -591,23 +591,11 @@ gtk_calendar_init (GtkCalendar *calendar)
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);
- }
+ if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
+ wbuffer, G_N_ELEMENTS (wbuffer)))
+ default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
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);
- }
+ default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
#endif
}
@@ -619,23 +607,11 @@ gtk_calendar_init (GtkCalendar *calendar)
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);
- }
+ if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
+ wbuffer, G_N_ELEMENTS (wbuffer)))
+ default_monthname[i] = g_strdup_printf ("(%d)", i);
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);
- }
+ default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
#endif
}
@@ -698,6 +674,32 @@ gtk_calendar_init (GtkCalendar *calendar)
else if (strcmp (year_before, "calendar:MY") != 0)
g_warning ("Whoever translated calendar:MY did so wrongly.\n");
+#ifdef G_OS_WIN32
+ /* Check if any of those environment variables that affect the
+ * behaviour of gettext are set. If not, we use the thread's
+ * locale's week start day.
+ */
+ if (getenv ("LANGUAGE") == NULL &&
+ getenv ("LC_ALL") == NULL &&
+ getenv ("LC_MESSAGES") == NULL &&
+ getenv ("LANG") == NULL)
+ {
+ priv->week_start = 0;
+ week_start = NULL;
+
+ if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
+ wbuffer, G_N_ELEMENTS (wbuffer)))
+ week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+
+ if (week_start != NULL)
+ {
+ priv->week_start = (week_start[0] - '0' + 1) % 7;
+ g_free(week_start);
+ }
+ }
+ else
+ {
+#endif
#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
langinfo = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
first_weekday = langinfo[0];
@@ -729,6 +731,9 @@ gtk_calendar_init (GtkCalendar *calendar)
priv->week_start = 0;
}
#endif
+#ifdef G_OS_WIN32
+ }
+#endif
calendar_compute_days (calendar);
}