]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcalendar.c
Apply a cleanup patch by Kjartan Maraas (#341812)
[~andy/gtk] / gtk / gtkcalendar.c
index 90141d575590e162ccce0786bec1e682e6a912d5..eb97c1f8e0586c1b731965bc6e198dfcec5800e3 100644 (file)
 #include <windows.h>
 #endif
 
-#include <glib/gprintf.h>
-
 #undef GTK_DISABLE_DEPRECATED
 #include "gtkcalendar.h"
-#define GTK_DISABLE_DEPRECATED
 
 #include "gtkdnd.h"
 #include "gtkintl.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
-#include "gtkintl.h"
 #include "gdk/gdkkeysyms.h"
 #include "gtkalias.h"
 
@@ -188,6 +184,8 @@ dates_difference(guint year1, guint mm1, guint dd1,
 #define DAY_XSEP                0 /* not really good for small calendar */
 #define DAY_YSEP                0 /* not really good for small calendar */
 
+#define SCROLL_DELAY_FACTOR      5
+
 /* Color usage */
 #define HEADER_FG_COLOR(widget)                 (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
 #define HEADER_BG_COLOR(widget)                 (& (widget)->style->bg[GTK_WIDGET_STATE (widget)])
@@ -561,10 +559,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;
@@ -592,23 +590,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
       }
   
@@ -620,23 +606,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
       }
   
@@ -699,6 +673,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];
@@ -730,6 +730,9 @@ gtk_calendar_init (GtkCalendar *calendar)
       priv->week_start = 0;
     }
 #endif
+#ifdef G_OS_WIN32
+    }
+#endif
 
   calendar_compute_days (calendar);
 }
@@ -2400,9 +2403,10 @@ calendar_timer (gpointer data)
           g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
 
          priv->need_timer = FALSE;
-         priv->timer = g_timeout_add (timeout,
-                                       (GSourceFunc) calendar_timer,
-                                       (gpointer) calendar);
+         priv->timer = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                           timeout * SCROLL_DELAY_FACTOR,
+                                           (GSourceFunc) calendar_timer,
+                                           (gpointer) calendar, NULL);
        }
       else 
        retval = TRUE;
@@ -2430,9 +2434,10 @@ calendar_start_spinning (GtkCalendar *calendar,
       g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
 
       priv->need_timer = TRUE;
-      priv->timer = g_timeout_add (timeout,
-                                  calendar_timer,
-                                  calendar);
+      priv->timer = g_timeout_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                       timeout,
+                                       (GSourceFunc) calendar_timer,
+                                       (gpointer) calendar, NULL);
     }
 }