]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmain.c
Add GtkSpinner::animation-duration style property
[~andy/gtk] / gtk / gtkmain.c
index 241936185e6a7bf934513a4e8e81af59632141b0..645da6f8f24b0e949f80637987b79818e7316429 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <glib.h>
 #include "gdkconfig.h"
 
 #include <locale.h>
 
-#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
-#include <libintl.h>
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 #ifdef G_OS_WIN32
 
-G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
+static HMODULE gtk_dll;
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+        DWORD     fdwReason,
+        LPVOID    lpvReserved)
+{
+  switch (fdwReason)
+    {
+    case DLL_PROCESS_ATTACH:
+      gtk_dll = (HMODULE) hinstDLL;
+      break;
+    }
+
+  return TRUE;
+}
 
-/* This here before inclusion of gtkprivate.h so that it sees the
- * original GTK_LOCALEDIR definition. Yeah, this is a bit sucky.
+/* These here before inclusion of gtkprivate.h so that the original
+ * GTK_LIBDIR and GTK_LOCALEDIR definitions are seen. Yeah, this is a
+ * bit sucky.
  */
+const gchar *
+_gtk_get_libdir (void)
+{
+  static char *gtk_libdir = NULL;
+  if (gtk_libdir == NULL)
+    {
+      gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
+      gchar *slash = strrchr (root, '\\');
+      if (g_ascii_strcasecmp (slash + 1, ".libs") == 0)
+       gtk_libdir = GTK_LIBDIR;
+      else
+       gtk_libdir = g_build_filename (root, "lib", NULL);
+      g_free (root);
+    }
+
+  return gtk_libdir;
+}
+
 const gchar *
 _gtk_get_localedir (void)
 {
@@ -84,7 +114,7 @@ _gtk_get_localedir (void)
   if (gtk_localedir == NULL)
     {
       const gchar *p;
-      gchar *temp;
+      gchar *root, *temp;
       
       /* GTK_LOCALEDIR ends in either /lib/locale or
        * /share/locale. Scan for that slash.
@@ -95,8 +125,9 @@ _gtk_get_localedir (void)
       while (*--p != '/')
        ;
 
-      temp = g_win32_get_package_installation_subdirectory
-        (GETTEXT_PACKAGE, dll_name, p);
+      root = g_win32_get_package_installation_directory_of_module (gtk_dll);
+      temp = g_build_filename (root, p, NULL);
+      g_free (root);
 
       /* gtk_localedir is passed to bindtextdomain() which isn't
        * UTF-8-aware.
@@ -131,14 +162,14 @@ struct _GtkQuitFunction
   GtkCallbackMarshal marshal;
   GtkFunction function;
   gpointer data;
-  GtkDestroyNotify destroy;
+  GDestroyNotify destroy;
 };
 
 struct _GtkClosure
 {
   GtkCallbackMarshal marshal;
   gpointer data;
-  GtkDestroyNotify destroy;
+  GDestroyNotify destroy;
 };
 
 struct _GtkKeySnooperData
@@ -311,30 +342,25 @@ _gtk_get_datadir (void)
 {
   static char *gtk_datadir = NULL;
   if (gtk_datadir == NULL)
-    gtk_datadir = g_win32_get_package_installation_subdirectory
-      (GETTEXT_PACKAGE, dll_name, "share");
+    {
+      gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
+      gtk_datadir = g_build_filename (root, "share", NULL);
+      g_free (root);
+    }
 
   return gtk_datadir;
 }
 
-const gchar *
-_gtk_get_libdir (void)
-{
-  static char *gtk_libdir = NULL;
-  if (gtk_libdir == NULL)
-    gtk_libdir = g_win32_get_package_installation_subdirectory
-      (GETTEXT_PACKAGE, dll_name, "lib");
-
-  return gtk_libdir;
-}
-
 const gchar *
 _gtk_get_sysconfdir (void)
 {
   static char *gtk_sysconfdir = NULL;
   if (gtk_sysconfdir == NULL)
-    gtk_sysconfdir = g_win32_get_package_installation_subdirectory
-      (GETTEXT_PACKAGE, dll_name, "etc");
+    {
+      gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
+      gtk_sysconfdir = g_build_filename (root, "etc", NULL);
+      g_free (root);
+    }
 
   return gtk_sysconfdir;
 }
@@ -344,8 +370,7 @@ _gtk_get_data_prefix (void)
 {
   static char *gtk_data_prefix = NULL;
   if (gtk_data_prefix == NULL)
-    gtk_data_prefix = g_win32_get_package_installation_directory
-      (GETTEXT_PACKAGE, dll_name);
+    gtk_data_prefix = g_win32_get_package_installation_directory_of_module (gtk_dll);
 
   return gtk_data_prefix;
 }
@@ -527,22 +552,13 @@ enum_locale_proc (LPTSTR locale)
 #endif
 
 static void
-do_pre_parse_initialization (int    *argc,
-                            char ***argv)
+setlocale_initialization (void)
 {
-  const gchar *env_string;
-  
-#if    0
-  g_set_error_handler (gtk_error);
-  g_set_warning_handler (gtk_warning);
-  g_set_message_handler (gtk_message);
-  g_set_print_handler (gtk_print);
-#endif
+  static gboolean initialized = FALSE;
 
-  if (pre_initialized)
+  if (initialized)
     return;
-
-  pre_initialized = TRUE;
+  initialized = TRUE;
 
   if (do_setlocale)
     {
@@ -607,6 +623,25 @@ do_pre_parse_initialization (int    *argc,
        g_warning ("Locale not supported by C library.\n\tUsing the fallback 'C' locale.");
 #endif
     }
+}
+
+static void
+do_pre_parse_initialization (int    *argc,
+                            char ***argv)
+{
+  const gchar *env_string;
+  
+#if    0
+  g_set_error_handler (gtk_error);
+  g_set_warning_handler (gtk_warning);
+  g_set_message_handler (gtk_message);
+  g_set_print_handler (gtk_print);
+#endif
+
+  if (pre_initialized)
+    return;
+
+  pre_initialized = TRUE;
 
   gdk_pre_parse_libgtk_only ();
   gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
@@ -630,6 +665,8 @@ do_pre_parse_initialization (int    *argc,
 static void
 gettext_initialization (void)
 {
+  setlocale_initialization ();
+
 #ifdef ENABLE_NLS
   bindtextdomain (GETTEXT_PACKAGE, GTK_LOCALEDIR);
   bindtextdomain (GETTEXT_PACKAGE "-properties", GTK_LOCALEDIR);
@@ -649,6 +686,10 @@ do_post_parse_initialization (int    *argc,
 
   gettext_initialization ();
 
+#ifdef SIGPIPE
+  signal (SIGPIPE, SIG_IGN);
+#endif
+
   if (g_fatal_warnings)
     {
       GLogLevelFlags fatal_mask;
@@ -674,8 +715,11 @@ do_post_parse_initialization (int    *argc,
       g_warning ("Whoever translated default:LTR did so wrongly.\n");
   }
 
-  gtk_type_init (0);
- _gtk_accel_map_init ();  
+  /* do what the call to gtk_type_init() used to do */
+  g_type_init ();
+  gtk_object_get_type ();
+
+  _gtk_accel_map_init ();
   _gtk_rc_init ();
 
   /* Set the 'initialized' flag.
@@ -688,6 +732,10 @@ do_post_parse_initialization (int    *argc,
       _gtk_modules_init (argc, argv, gtk_modules_string->str);
       g_string_free (gtk_modules_string, TRUE);
     }
+  else
+    {
+      _gtk_modules_init (argc, argv, NULL);
+    }
 }
 
 
@@ -726,7 +774,7 @@ post_parse_hook (GOptionContext *context,
          g_set_error (error, 
                       G_OPTION_ERROR, 
                       G_OPTION_ERROR_FAILED,
-                      "cannot open display: %s",
+                      _("Cannot open display: %s"),
                       display_name ? display_name : "" );
          
          return FALSE;
@@ -811,7 +859,7 @@ gtk_init_with_args (int            *argc,
   gboolean retval;
 
   if (gtk_initialized)
-    return TRUE;
+    return gdk_display_open_default_libgtk_only () != NULL;
 
   gettext_initialization ();
 
@@ -941,6 +989,15 @@ gtk_init_check (int         *argc,
  * the GUI for some reason. If you want your program to fall back to a 
  * textual interface you want to call gtk_init_check() instead.
  * </para></note>
+ *
+ * <note><para>
+ * Since 2.18, GTK+ calls <literal>signal (SIGPIPE, SIG_IGN)</literal>
+ * during initialization, to ignore SIGPIPE signals, since these are
+ * almost never wanted in graphical applications. If you do need to
+ * handle SIGPIPE for some reason, reset the handler after gtk_init(),
+ * but notice that other libraries (e.g. libdbus or gvfs) might do
+ * similar things.
+ * </para></note>
  **/
 void
 gtk_init (int *argc, char ***argv)
@@ -1347,6 +1404,7 @@ rewrite_event_for_grabs (GdkEvent *event)
 {
   GdkWindow *grab_window;
   GtkWidget *event_widget, *grab_widget;
+  gpointer grab_widget_ptr;
   gboolean owner_events;
   GdkDisplay *display;
 
@@ -1379,7 +1437,8 @@ rewrite_event_for_grabs (GdkEvent *event)
     }
 
   event_widget = gtk_get_event_widget (event);
-  gdk_window_get_user_data (grab_window, (void**) &grab_widget);
+  gdk_window_get_user_data (grab_window, &grab_widget_ptr);
+  grab_widget = grab_widget_ptr;
 
   if (grab_widget &&
       gtk_main_get_window_group (grab_widget) != gtk_main_get_window_group (event_widget))
@@ -1513,7 +1572,15 @@ gtk_main_do_event (GdkEvent *event)
          gdk_window_end_paint (event->any.window);
        }
       else
-       gtk_widget_send_expose (event_widget, event);
+       {
+         /* The app may paint with a previously allocated cairo_t,
+            which will draw directly to the window. We can't catch cairo
+            drap operatoins to automatically flush the window, thus we
+            need to explicitly flush any outstanding moves or double
+            buffering */
+         gdk_window_flush (event->any.window);
+         gtk_widget_send_expose (event_widget, event);
+       }
       break;
 
     case GDK_PROPERTY_NOTIFY:
@@ -1556,25 +1623,15 @@ gtk_main_do_event (GdkEvent *event)
       break;
       
     case GDK_ENTER_NOTIFY:
+      GTK_PRIVATE_SET_FLAG (event_widget, GTK_HAS_POINTER);
+      _gtk_widget_set_pointer_window (event_widget, event->any.window);
       if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
-       {
-         g_object_ref (event_widget);
-         
-         gtk_widget_event (grab_widget, event);
-         if (event_widget == grab_widget)
-           GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
-         
-         g_object_unref (event_widget);
-       }
+       gtk_widget_event (grab_widget, event);
       break;
       
     case GDK_LEAVE_NOTIFY:
-      if (GTK_WIDGET_LEAVE_PENDING (event_widget))
-       {
-         GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_LEAVE_PENDING);
-         gtk_widget_event (event_widget, event);
-       }
-      else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
+      GTK_PRIVATE_UNSET_FLAG (event_widget, GTK_HAS_POINTER);
+      if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
        gtk_widget_event (grab_widget, event);
       break;
       
@@ -1647,6 +1704,7 @@ typedef struct
   GtkWidget *new_grab_widget;
   gboolean   was_grabbed;
   gboolean   is_grabbed;
+  gboolean   from_grab;
 } GrabNotifyInfo;
 
 static void
@@ -1668,13 +1726,31 @@ gtk_grab_notify_foreach (GtkWidget *child,
   is_shadowed = info->new_grab_widget && !info->is_grabbed;
 
   g_object_ref (child);
+
+  if ((was_shadowed || is_shadowed) && GTK_IS_CONTAINER (child))
+    gtk_container_forall (GTK_CONTAINER (child), gtk_grab_notify_foreach, info);
   
+  if (is_shadowed)
+    {
+      GTK_PRIVATE_SET_FLAG (child, GTK_SHADOWED);
+      if (!was_shadowed && GTK_WIDGET_HAS_POINTER (child)
+         && GTK_WIDGET_IS_SENSITIVE (child))
+       _gtk_widget_synthesize_crossing (child, info->new_grab_widget,
+                                        GDK_CROSSING_GTK_GRAB);
+    }
+  else
+    {
+      GTK_PRIVATE_UNSET_FLAG (child, GTK_SHADOWED);
+      if (was_shadowed && GTK_WIDGET_HAS_POINTER (child)
+         && GTK_WIDGET_IS_SENSITIVE (child))
+       _gtk_widget_synthesize_crossing (info->old_grab_widget, child,
+                                        info->from_grab ? GDK_CROSSING_GTK_GRAB
+                                        : GDK_CROSSING_GTK_UNGRAB);
+    }
+
   if (was_shadowed != is_shadowed)
     _gtk_widget_grab_notify (child, was_shadowed);
   
-  if ((was_shadowed || is_shadowed) && GTK_IS_CONTAINER (child))
-    gtk_container_forall (GTK_CONTAINER (child), gtk_grab_notify_foreach, info);
-      
   g_object_unref (child);
   
   info->was_grabbed = was_grabbed;
@@ -1684,7 +1760,8 @@ gtk_grab_notify_foreach (GtkWidget *child,
 static void
 gtk_grab_notify (GtkWindowGroup *group,
                 GtkWidget      *old_grab_widget,
-                GtkWidget      *new_grab_widget)
+                GtkWidget      *new_grab_widget,
+                gboolean        from_grab)
 {
   GList *toplevels;
   GrabNotifyInfo info;
@@ -1694,6 +1771,7 @@ gtk_grab_notify (GtkWindowGroup *group,
 
   info.old_grab_widget = old_grab_widget;
   info.new_grab_widget = new_grab_widget;
+  info.from_grab = from_grab;
 
   g_object_ref (group);
 
@@ -1738,7 +1816,7 @@ gtk_grab_add (GtkWidget *widget)
       g_object_ref (widget);
       group->grabs = g_slist_prepend (group->grabs, widget);
 
-      gtk_grab_notify (group, old_grab_widget, widget);
+      gtk_grab_notify (group, old_grab_widget, widget, TRUE);
     }
 }
 
@@ -1774,7 +1852,7 @@ gtk_grab_remove (GtkWidget *widget)
       else
        new_grab_widget = NULL;
 
-      gtk_grab_notify (group, widget, new_grab_widget);
+      gtk_grab_notify (group, widget, new_grab_widget, FALSE);
       
       g_object_unref (widget);
     }
@@ -1859,7 +1937,7 @@ gtk_quit_add_full (guint          main_level,
                   GtkFunction          function,
                   GtkCallbackMarshal   marshal,
                   gpointer             data,
-                  GtkDestroyNotify     destroy)
+                  GDestroyNotify       destroy)
 {
   static guint quit_id = 1;
   GtkQuitFunction *quitf;
@@ -1977,7 +2055,7 @@ gtk_timeout_add_full (guint32              interval,
                      GtkFunction        function,
                      GtkCallbackMarshal marshal,
                      gpointer           data,
-                     GtkDestroyNotify   destroy)
+                     GDestroyNotify     destroy)
 {
   if (marshal)
     {
@@ -2016,7 +2094,7 @@ gtk_idle_add_full (gint                   priority,
                   GtkFunction          function,
                   GtkCallbackMarshal   marshal,
                   gpointer             data,
-                  GtkDestroyNotify     destroy)
+                  GDestroyNotify       destroy)
 {
   if (marshal)
     {
@@ -2070,7 +2148,7 @@ gtk_input_add_full (gint          source,
                    GdkInputFunction    function,
                    GtkCallbackMarshal  marshal,
                    gpointer            data,
-                   GtkDestroyNotify    destroy)
+                   GDestroyNotify      destroy)
 {
   if (marshal)
     {
@@ -2085,7 +2163,7 @@ gtk_input_add_full (gint          source,
                                 condition,
                                 (GdkInputFunction) gtk_invoke_input,
                                 closure,
-                                (GdkDestroyNotify) gtk_destroy_closure);
+                                (GDestroyNotify) gtk_destroy_closure);
     }
   else
     return gdk_input_add_full (source, condition, function, data, destroy);
@@ -2216,11 +2294,15 @@ GtkWidget*
 gtk_get_event_widget (GdkEvent *event)
 {
   GtkWidget *widget;
+  gpointer widget_ptr;
 
   widget = NULL;
   if (event && event->any.window && 
       (event->type == GDK_DESTROY || !GDK_WINDOW_DESTROYED (event->any.window)))
-    gdk_window_get_user_data (event->any.window, (void**) &widget);
+    {
+      gdk_window_get_user_data (event->any.window, &widget_ptr);
+      widget = widget_ptr;
+    }
   
   return widget;
 }
@@ -2394,7 +2476,7 @@ gtk_print (gchar *str)
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       
       gtk_signal_connect (GTK_OBJECT (window), "destroy",
-                         (GtkSignalFunc) gtk_widget_destroyed,
+                         G_CALLBACK (gtk_widget_destroyed),
                          &window);
       
       gtk_window_set_title (GTK_WINDOW (window), "Messages");
@@ -2445,7 +2527,7 @@ gtk_print (gchar *str)
       
       button = gtk_button_new_with_label ("close");
       gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
-                                (GtkSignalFunc) gtk_widget_hide,
+                                G_CALLBACK (gtk_widget_hide),
                                 GTK_OBJECT (window));
       gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);