]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmain.c
Merge libgdk and libgtk
[~andy/gtk] / gtk / gtkmain.c
index 017d000de1402df42f1619029fdb3ed17ffce00f..dc272600fe2cc10c9e958f6d43c424b3eb341af1 100644 (file)
 
 #include "config.h"
 
+#include "gtkmain.h"
+
 #include <glib.h>
-#include "gdkconfig.h"
+#include "gdk/gdk.h"
 
 #include <locale.h>
 
 #include "gtkclipboard.h"
 #include "gtkdnd.h"
 #include "gtkversion.h"
-#include "gtkmain.h"
 #include "gtkmodules.h"
 #include "gtkrc.h"
 #include "gtkrecentmanager.h"
 #include "gtkselection.h"
 #include "gtksettings.h"
-#include "gtkwidget.h"
-#include "gtkwindow.h"
+#include "gtkwidgetprivate.h"
+#include "gtkwindowprivate.h"
 #include "gtktooltip.h"
 #include "gtkdebug.h"
-#include "gtkalias.h"
 #include "gtkmenu.h"
-#include "gdk/gdkkeysyms.h"
-
-#include "gdk/gdkprivate.h" /* for GDK_WINDOW_DESTROYED */
 
 #ifdef G_OS_WIN32
 
@@ -146,16 +143,9 @@ _gtk_get_localedir (void)
 
 /* Private type definitions
  */
-typedef struct _GtkInitFunction                 GtkInitFunction;
 typedef struct _GtkQuitFunction                 GtkQuitFunction;
 typedef struct _GtkKeySnooperData       GtkKeySnooperData;
 
-struct _GtkInitFunction
-{
-  GtkFunction function;
-  gpointer data;
-};
-
 struct _GtkQuitFunction
 {
   guint id;
@@ -180,12 +170,6 @@ static gint  gtk_invoke_key_snoopers        (GtkWidget          *grab_widget,
 
 static GtkWindowGroup *gtk_main_get_window_group (GtkWidget   *widget);
 
-const guint gtk_major_version = GTK_MAJOR_VERSION;
-const guint gtk_minor_version = GTK_MINOR_VERSION;
-const guint gtk_micro_version = GTK_MICRO_VERSION;
-const guint gtk_binary_age = GTK_BINARY_AGE;
-const guint gtk_interface_age = GTK_INTERFACE_AGE;
-
 static guint gtk_main_loop_level = 0;
 static gint pre_initialized = FALSE;
 static gint gtk_initialized = FALSE;
@@ -193,13 +177,11 @@ static GList *current_events = NULL;
 
 static GSList *main_loops = NULL;      /* stack of currently executing main loops */
 
-static GList *init_functions = NULL;      /* A list of init functions.
-                                           */
 static GList *quit_functions = NULL;      /* A list of quit functions.
                                            */
 static GSList *key_snoopers = NULL;
 
-guint gtk_debug_flags = 0;                /* Global GTK debug flag */
+static guint debug_flags = 0;             /* Global GTK debug flag */
 
 #ifdef G_ENABLE_DEBUG
 static const GDebugKey gtk_debug_keys[] = {
@@ -215,10 +197,111 @@ static const GDebugKey gtk_debug_keys[] = {
   {"icontheme", GTK_DEBUG_ICONTHEME},
   {"printing", GTK_DEBUG_PRINTING},
   {"builder", GTK_DEBUG_BUILDER},
-  {"extended-layout", GTK_DEBUG_EXTENDED_LAYOUT},
+  {"size-request", GTK_DEBUG_SIZE_REQUEST},
 };
 #endif /* G_ENABLE_DEBUG */
 
+/**
+ * gtk_get_major_version:
+ *
+ * Returns the major version number of the GTK+ library.  (e.g. in GTK+ version
+ * 3.1.5 this is 3.) 
+ *
+ * This function is in the library, so it represents the GTK+ library
+ * your code is running against. Contrast with the #GTK_MAJOR_VERSION
+ * macro, which represents the major version of the GTK+ headers you
+ * have included when compiling your code.
+ *
+ * Returns: the major version number of the GTK+ library.
+ *
+ * Since: 3.0
+ */
+guint
+gtk_get_major_version (void)
+{
+  return GTK_MAJOR_VERSION;
+}
+
+/**
+ * gtk_get_minor_version:
+ *
+ * Returns the minor version number of the GTK+ library.  (e.g. in GTK+ version
+ * 3.1.5 this is 1.) 
+ *
+ * This function is in the library, so it represents the GTK+ library
+ * your code is are running against. Contrast with the
+ * #GTK_MINOR_VERSION macro, which represents the minor version of the
+ * GTK+ headers you have included when compiling your code.
+ *
+ * Returns: the minor version number of the GTK+ library.
+ *
+ * Since: 3.0
+ */
+guint
+gtk_get_minor_version (void)
+{
+  return GTK_MINOR_VERSION;
+}
+
+/**
+ * gtk_get_micro_version:
+ *
+ * Returns the micro version number of the GTK+ library.  (e.g. in GTK+ version
+ * 3.1.5 this is 5.) 
+ *
+ * This function is in the library, so it represents the GTK+ library
+ * your code is are running against. Contrast with the
+ * #GTK_MICRO_VERSION macro, which represents the micro version of the
+ * GTK+ headers you have included when compiling your code.
+ *
+ * Returns: the micro version number of the GTK+ library.
+ *
+ * Since: 3.0
+ */
+guint
+gtk_get_micro_version (void)
+{
+  return GTK_MICRO_VERSION;
+}
+
+/**
+ * gtk_get_binary_age:
+ *
+ * Returns the binary age as passed to
+ * <application>libtool</application> when building the GTK+ library
+ * the process is running against. If
+ * <application>libtool</application> means nothing to you, don't
+ * worry about it.
+ *
+ * Returns: the binary age of the GTK+ library.
+ *
+ * Since: 3.0
+ */
+guint
+gtk_get_binary_age (void)
+{
+  return GTK_BINARY_AGE;
+}
+
+/**
+ * gtk_get_interface_age:
+ *
+ * Returns the interface age as passed to
+ * <application>libtool</application> when building the GTK+ library
+ * the process is running against. If
+ * <application>libtool</application> means nothing to you, don't
+ * worry about it.
+ *
+ * Returns: the interface age of the GTK+ library.
+ *
+ * Since: 3.0
+ */
+guint
+gtk_get_interface_age (void)
+{
+  return GTK_INTERFACE_AGE;
+}
+
 /**
  * gtk_check_version:
  * @required_major: the required major version.
@@ -243,7 +326,7 @@ static const GDebugKey gtk_debug_keys[] = {
  * This function is primarily for GTK+ modules; the module
  * can call this function to check that it wasn't loaded
  * into an incompatible version of GTK+. However, such a
- * check isn't completely reliable, since the module may be
+ * check isn't completely reliable, since the module may be
  * linked against an old version of GTK+ and calling the
  * old version of gtk_check_version(), but still get loaded
  * into an application using a newer version of GTK+.
@@ -393,9 +476,9 @@ static gboolean g_fatal_warnings = FALSE;
 static gboolean
 gtk_arg_debug_cb (const char *key, const char *value, gpointer user_data)
 {
-  gtk_debug_flags |= g_parse_debug_string (value,
-                                          gtk_debug_keys,
-                                          G_N_ELEMENTS (gtk_debug_keys));
+  debug_flags |= g_parse_debug_string (value,
+                                      gtk_debug_keys,
+                                      G_N_ELEMENTS (gtk_debug_keys));
 
   return TRUE;
 }
@@ -403,9 +486,9 @@ gtk_arg_debug_cb (const char *key, const char *value, gpointer user_data)
 static gboolean
 gtk_arg_no_debug_cb (const char *key, const char *value, gpointer user_data)
 {
-  gtk_debug_flags &= ~g_parse_debug_string (value,
-                                           gtk_debug_keys,
-                                           G_N_ELEMENTS (gtk_debug_keys));
+  debug_flags &= ~g_parse_debug_string (value,
+                                       gtk_debug_keys,
+                                       G_N_ELEMENTS (gtk_debug_keys));
 
   return TRUE;
 }
@@ -607,6 +690,22 @@ setlocale_initialization (void)
     }
 }
 
+static void
+check_mixed_deps (void)
+{
+  GModule *module;
+  gpointer func;
+
+  module = g_module_open (NULL, 0);
+
+  if (g_module_symbol (module, "gtk_progress_get_type", &func))
+    {
+      g_error ("GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
+    }
+
+  g_module_close (module);
+}
+
 static void
 do_pre_parse_initialization (int    *argc,
                             char ***argv)
@@ -618,6 +717,8 @@ do_pre_parse_initialization (int    *argc,
 
   pre_initialized = TRUE;
 
+  check_mixed_deps ();
+
   gdk_pre_parse_libgtk_only ();
   gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
   
@@ -625,9 +726,9 @@ do_pre_parse_initialization (int    *argc,
   env_string = g_getenv ("GTK_DEBUG");
   if (env_string != NULL)
     {
-      gtk_debug_flags = g_parse_debug_string (env_string,
-                                             gtk_debug_keys,
-                                             G_N_ELEMENTS (gtk_debug_keys));
+      debug_flags = g_parse_debug_string (env_string,
+                                         gtk_debug_keys,
+                                         G_N_ELEMENTS (gtk_debug_keys));
       env_string = NULL;
     }
 #endif /* G_ENABLE_DEBUG */
@@ -674,7 +775,7 @@ do_post_parse_initialization (int    *argc,
       g_log_set_always_fatal (fatal_mask);
     }
 
-  if (gtk_debug_flags & GTK_DEBUG_UPDATES)
+  if (debug_flags & GTK_DEBUG_UPDATES)
     gdk_window_set_debug_updates (TRUE);
 
   {
@@ -694,7 +795,6 @@ do_post_parse_initialization (int    *argc,
   g_type_init ();
 
   _gtk_accel_map_init ();
-  _gtk_rc_init ();
 
   /* Set the 'initialized' flag.
    */
@@ -759,6 +859,33 @@ post_parse_hook (GOptionContext *context,
 }
 
 
+/**
+ * gtk_get_debug_flags:
+ *
+ * Returns the GTK+ debug flags.
+ *
+ * This function is intended for GTK+ modules that want
+ * to adjust their debug output based on GTK+ debug flags.
+ *
+ * Returns: the GTK+ debug flags.
+ */
+guint
+gtk_get_debug_flags (void)
+{
+  return debug_flags;
+}
+
+/**
+ * gtk_set_debug_flags:
+ *
+ * Sets the GTK+ debug flags.
+ */
+void
+gtk_set_debug_flags (guint flags)
+{
+  debug_flags = flags;
+}
+
 /**
  * gtk_get_option_group:
  * @open_default_display: whether to open the default display 
@@ -800,24 +927,24 @@ gtk_get_option_group (gboolean open_default_display)
  * @argc: a pointer to the number of command line arguments.
  * @argv: a pointer to the array of command line arguments.
  * @parameter_string: a string which is displayed in
- *    the first line of <option>--help</option> output, after 
+ *    the first line of <option>--help</option> output, after
  *    <literal><replaceable>programname</replaceable> [OPTION...]</literal>
  * @entries: a %NULL-terminated array of #GOptionEntry<!-- -->s
  *    describing the options of your program
  * @translation_domain: a translation domain to use for translating
  *    the <option>--help</option> output for the options in @entries
- *    with gettext(), or %NULL
- * @error: a return location for errors 
+ *    and the @parameter_string with gettext(), or %NULL
+ * @error: a return location for errors
  *
- * This function does the same work as gtk_init_check(). 
- * Additionally, it allows you to add your own commandline options, 
- * and it automatically generates nicely formatted 
+ * This function does the same work as gtk_init_check().
+ * Additionally, it allows you to add your own commandline options,
+ * and it automatically generates nicely formatted
  * <option>--help</option> output. Note that your program will
  * be terminated after writing out the help output.
  *
- * Returns: %TRUE if the GUI has been successfully initialized, 
+ * Returns: %TRUE if the GUI has been successfully initialized,
  *               %FALSE otherwise.
- * 
+ *
  * Since: 2.6
  */
 gboolean
@@ -841,14 +968,15 @@ gtk_init_with_args (gint                 *argc,
     return FALSE;
 
   gtk_group = gtk_get_option_group (TRUE);
-  
+
   context = g_option_context_new (parameter_string);
   g_option_context_add_group (context, gtk_group);
-  
+  g_option_context_set_translation_domain (context, translation_domain);
+
   if (entries)
     g_option_context_add_main_entries (context, entries, translation_domain);
   retval = g_option_context_parse (context, argc, argv, error);
-  
+
   g_option_context_free (context);
 
   return retval;
@@ -1157,8 +1285,6 @@ void
 gtk_main (void)
 {
   GList *tmp_list;
-  GList *functions;
-  GtkInitFunction *init;
   GMainLoop *loop;
 
   gtk_main_loop_level++;
@@ -1166,19 +1292,6 @@ gtk_main (void)
   loop = g_main_loop_new (NULL, TRUE);
   main_loops = g_slist_prepend (main_loops, loop);
 
-  tmp_list = functions = init_functions;
-  init_functions = NULL;
-  
-  while (tmp_list)
-    {
-      init = tmp_list->data;
-      tmp_list = tmp_list->next;
-      
-      (* init->function) (init->data);
-      g_free (init);
-    }
-  g_list_free (functions);
-
   if (g_main_loop_is_running (main_loops->data))
     {
       GDK_THREADS_LEAVE ();
@@ -1386,7 +1499,7 @@ rewrite_event_for_grabs (GdkEvent *event)
     case GDK_PROXIMITY_OUT:
     case GDK_KEY_PRESS:
     case GDK_KEY_RELEASE:
-      display = gdk_drawable_get_display (event->any.window);
+      display = gdk_window_get_display (event->any.window);
       device = gdk_event_get_device (event);
 
       if (!gdk_device_grab_info_libgtk_only (display, device, &grab_window, &owner_events) ||
@@ -1471,8 +1584,8 @@ gtk_main_do_event (GdkEvent *event)
   if (device)
     grab_widget = gtk_window_group_get_current_device_grab (window_group, device);
 
-  if (!grab_widget && window_group->grabs)
-    grab_widget = window_group->grabs->data;
+  if (!grab_widget)
+    grab_widget = gtk_window_group_get_current_grab (window_group);
 
   /* If the grab widget is an ancestor of the event widget
    *  then we send the event to the original event widget.
@@ -1515,7 +1628,7 @@ gtk_main_do_event (GdkEvent *event)
       
     case GDK_DELETE:
       g_object_ref (event_widget);
-      if ((!window_group->grabs || gtk_widget_get_toplevel (window_group->grabs->data) == event_widget) &&
+      if ((!gtk_window_group_get_current_grab (window_group) || gtk_widget_get_toplevel (gtk_window_group_get_current_grab (window_group)) == event_widget) &&
          !gtk_widget_event (event_widget, event))
        gtk_widget_destroy (event_widget);
       g_object_unref (event_widget);
@@ -1525,7 +1638,7 @@ gtk_main_do_event (GdkEvent *event)
       /* Unexpected GDK_DESTROY from the outside, ignore for
        * child windows, handle like a GDK_DELETE for toplevels
        */
-      if (!event_widget->parent)
+      if (!gtk_widget_get_parent (event_widget))
        {
          g_object_ref (event_widget);
          if (!gtk_widget_event (event_widget, event) &&
@@ -1546,7 +1659,7 @@ gtk_main_do_event (GdkEvent *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
+            draw operations to automatically flush the window, thus we
             need to explicitly flush any outstanding moves or double
             buffering */
          gdk_window_flush (event->any.window);
@@ -1555,7 +1668,6 @@ gtk_main_do_event (GdkEvent *event)
       break;
 
     case GDK_PROPERTY_NOTIFY:
-    case GDK_NO_EXPOSE:
     case GDK_FOCUS_CHANGE:
     case GDK_CONFIGURE:
     case GDK_MAP:
@@ -1588,7 +1700,7 @@ gtk_main_do_event (GdkEvent *event)
       /* Catch alt press to enable auto-mnemonics;
        * menus are handled elsewhere
        */
-      if ((event->key.keyval == GDK_Alt_L || event->key.keyval == GDK_Alt_R) &&
+      if ((event->key.keyval == GDK_KEY_Alt_L || event->key.keyval == GDK_KEY_Alt_R) &&
           !GTK_IS_MENU_SHELL (grab_widget))
         {
           gboolean auto_mnemonics;
@@ -1796,7 +1908,7 @@ gtk_grab_notify_foreach (GtkWidget *child,
 
   if (is_shadowed)
     {
-      GTK_PRIVATE_SET_FLAG (child, GTK_SHADOWED);
+      _gtk_widget_set_shadowed (child, TRUE);
       if (!was_shadowed && devices &&
          gtk_widget_is_sensitive (child))
         synth_crossing_for_grab_notify (child, info->new_grab_widget,
@@ -1805,7 +1917,7 @@ gtk_grab_notify_foreach (GtkWidget *child,
     }
   else
     {
-      GTK_PRIVATE_UNSET_FLAG (child, GTK_SHADOWED);
+      _gtk_widget_set_shadowed (child, FALSE);
       if (was_shadowed && devices &&
           gtk_widget_is_sensitive (child))
         synth_crossing_for_grab_notify (info->old_grab_widget, child,
@@ -1875,21 +1987,26 @@ gtk_grab_add (GtkWidget *widget)
   if (!gtk_widget_has_grab (widget) && gtk_widget_is_sensitive (widget))
     {
       _gtk_widget_set_has_grab (widget, TRUE);
-      
+
       group = gtk_main_get_window_group (widget);
 
-      if (group->grabs)
-       old_grab_widget = (GtkWidget *)group->grabs->data;
-      else
-       old_grab_widget = NULL;
+      old_grab_widget = gtk_window_group_get_current_grab (group);
 
       g_object_ref (widget);
-      group->grabs = g_slist_prepend (group->grabs, widget);
+      _gtk_window_group_add_grab (group, widget);
 
       gtk_grab_notify (group, NULL, old_grab_widget, widget, TRUE);
     }
 }
 
+/**
+ * gtk_grab_get_current:
+ *
+ * Queries the current grab of the default window group.
+ *
+ * Return value: (transfer none): The widget which currently
+ *     has the grab or %NULL if no grab is active
+ */
 GtkWidget*
 gtk_grab_get_current (void)
 {
@@ -1897,9 +2014,7 @@ gtk_grab_get_current (void)
 
   group = gtk_main_get_window_group (NULL);
 
-  if (group->grabs)
-    return GTK_WIDGET (group->grabs->data);
-  return NULL;
+  return gtk_window_group_get_current_grab (group);
 }
 
 void
@@ -1915,15 +2030,11 @@ gtk_grab_remove (GtkWidget *widget)
       _gtk_widget_set_has_grab (widget, FALSE);
 
       group = gtk_main_get_window_group (widget);
-      group->grabs = g_slist_remove (group->grabs, widget);
-      
-      if (group->grabs)
-       new_grab_widget = (GtkWidget *)group->grabs->data;
-      else
-       new_grab_widget = NULL;
+      _gtk_window_group_remove_grab (group, widget);
+      new_grab_widget = gtk_window_group_get_current_grab (group);
 
       gtk_grab_notify (group, NULL, widget, new_grab_widget, FALSE);
-      
+
       g_object_unref (widget);
     }
 }
@@ -1988,19 +2099,6 @@ gtk_device_grab_remove (GtkWidget *widget,
   gtk_grab_notify (group, device, widget, new_grab_widget, FALSE);
 }
 
-void
-gtk_init_add (GtkFunction function,
-             gpointer    data)
-{
-  GtkInitFunction *init;
-  
-  init = g_new (GtkInitFunction, 1);
-  init->function = function;
-  init->data = data;
-  
-  init_functions = g_list_prepend (init_functions, init);
-}
-
 guint
 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
                         gpointer        func_data)
@@ -2097,25 +2195,25 @@ gtk_quit_destroy (GtkQuitFunction *quitf)
 }
 
 static gint
-gtk_quit_destructor (GtkObject **object_p)
+gtk_quit_destructor (GtkWidget **object_p)
 {
   if (*object_p)
-    gtk_object_destroy (*object_p);
+    gtk_widget_destroy (*object_p);
   g_free (object_p);
 
   return FALSE;
 }
 
 void
-gtk_quit_add_destroy (guint              main_level,
-                     GtkObject         *object)
+gtk_quit_add_destroy (guint      main_level,
+                     GtkWidget *object)
 {
-  GtkObject **object_p;
+  GtkWidget **object_p;
 
   g_return_if_fail (main_level > 0);
-  g_return_if_fail (GTK_IS_OBJECT (object));
+  g_return_if_fail (GTK_IS_WIDGET (object));
 
-  object_p = g_new (GtkObject*, 1);
+  object_p = g_new (GtkWidget*, 1);
   *object_p = object;
   g_signal_connect (object,
                    "destroy",
@@ -2247,7 +2345,7 @@ gtk_get_current_event_state (GdkModifierType *state)
  * If there is a current event and it has a device, return that
  * device, otherwise return %NULL.
  *
- * Returns: a #GdkDevice, or %NULL
+ * Returns: (transfer none): a #GdkDevice, or %NULL
  **/
 GdkDevice *
 gtk_get_current_event_device (void)
@@ -2266,7 +2364,8 @@ gtk_get_current_event_device (void)
  * returns %NULL, otherwise returns the widget that received the event
  * originally.
  * 
- * Return value: the widget that originally received @event, or %NULL
+ * Return value: (transfer none): the widget that originally
+ *     received @event, or %NULL
  **/
 GtkWidget*
 gtk_get_event_widget (GdkEvent *event)
@@ -2276,7 +2375,7 @@ gtk_get_event_widget (GdkEvent *event)
 
   widget = NULL;
   if (event && event->any.window && 
-      (event->type == GDK_DESTROY || !GDK_WINDOW_DESTROYED (event->any.window)))
+      (event->type == GDK_DESTROY || !gdk_window_is_destroyed (event->any.window)))
     {
       gdk_window_get_user_data (event->any.window, &widget_ptr);
       widget = widget_ptr;
@@ -2393,8 +2492,8 @@ gtk_propagate_event (GtkWidget *widget,
            handled_event = event->type != GDK_SCROLL;
          else
            handled_event = gtk_widget_event (widget, event);
-             
-         tmp = widget->parent;
+
+          tmp = gtk_widget_get_parent (widget);
          g_object_unref (widget);
 
          widget = tmp;
@@ -2424,6 +2523,3 @@ _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
   
   return continue_emission;
 }
-
-#define __GTK_MAIN_C__
-#include "gtkaliasdef.c"