]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmain.c
Change FSF Address
[~andy/gtk] / gtk / gtkmain.c
index 9a3b0314fabcf65e6868b7be8b6e0d375626fec0..c0cdabd9c88ae32056d39de5ab9ae6a6dde5d4fd 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
@@ -91,9 +89,6 @@
 
 #include "config.h"
 
-#include "gtkmainprivate.h"
-
-#include <glib.h>
 #include "gdk/gdk.h"
 
 #include <locale.h>
 
 #include "gtkintl.h"
 
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
 #include "gtkbox.h"
 #include "gtkclipboard.h"
+#include "gtkdebug.h"
 #include "gtkdnd.h"
-#include "gtkversion.h"
+#include "gtkmain.h"
+#include "gtkmenu.h"
 #include "gtkmodules.h"
-#include "gtkrc.h"
+#include "gtkmodulesprivate.h"
+#include "gtkprivate.h"
 #include "gtkrecentmanager.h"
-#include "gtkselection.h"
+#include "gtkresources.h"
+#include "gtkselectionprivate.h"
 #include "gtksettingsprivate.h"
+#include "gtktooltip.h"
+#include "gtkversion.h"
 #include "gtkwidgetprivate.h"
 #include "gtkwindowprivate.h"
-#include "gtktooltip.h"
-#include "gtkdebug.h"
-#include "gtkmenu.h"
-
-#ifdef G_OS_WIN32
-
-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;
-}
 
-/* 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)
-{
-  static char *gtk_localedir = NULL;
-  if (gtk_localedir == NULL)
-    {
-      const gchar *p;
-      gchar *root, *temp;
-      
-      /* GTK_LOCALEDIR ends in either /lib/locale or
-       * /share/locale. Scan for that slash.
-       */
-      p = GTK_LOCALEDIR + strlen (GTK_LOCALEDIR);
-      while (*--p != '/')
-        ;
-      while (*--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.
-       */
-      gtk_localedir = g_win32_locale_filename_from_utf8 (temp);
-      g_free (temp);
-    }
-  return gtk_localedir;
-}
-
-#endif
-
-#include "gtkprivate.h"
+#include "a11y/gailutil.h"
 
 /* Private type definitions
  */
@@ -448,48 +372,6 @@ check_setugid (void)
   return TRUE;
 }
 
-#ifdef G_OS_WIN32
-
-const gchar *
-_gtk_get_datadir (void)
-{
-  static char *gtk_datadir = NULL;
-  if (gtk_datadir == NULL)
-    {
-      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_sysconfdir (void)
-{
-  static char *gtk_sysconfdir = NULL;
-  if (gtk_sysconfdir == NULL)
-    {
-      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;
-}
-
-const gchar *
-_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_of_module (gtk_dll);
-
-  return gtk_data_prefix;
-}
-
-#endif /* G_OS_WIN32 */
-
 static gboolean do_setlocale = TRUE;
 
 /**
@@ -738,22 +620,6 @@ 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)
@@ -765,11 +631,12 @@ do_pre_parse_initialization (int    *argc,
 
   pre_initialized = TRUE;
 
-  check_mixed_deps ();
+  if (_gtk_module_has_mixed_deps (NULL))
+    g_error ("GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
 
   gdk_pre_parse_libgtk_only ();
   gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
-  
+
 #ifdef G_ENABLE_DEBUG
   env_string = g_getenv ("GTK_DEBUG");
   if (env_string != NULL)
@@ -792,8 +659,8 @@ gettext_initialization (void)
   setlocale_initialization ();
 
 #ifdef ENABLE_NLS
-  bindtextdomain (GETTEXT_PACKAGE, GTK_LOCALEDIR);
-  bindtextdomain (GETTEXT_PACKAGE "-properties", GTK_LOCALEDIR);
+  bindtextdomain (GETTEXT_PACKAGE, _gtk_get_localedir ());
+  bindtextdomain (GETTEXT_PACKAGE "-properties", _gtk_get_localedir ());
 #    ifdef HAVE_BIND_TEXTDOMAIN_CODESET
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   bind_textdomain_codeset (GETTEXT_PACKAGE "-properties", "UTF-8");
@@ -801,6 +668,9 @@ gettext_initialization (void)
 #endif  
 }
 
+/* XXX: Remove me after getting rid of gail */
+extern void _gtk_accessibility_init (void);
+
 static void
 do_post_parse_initialization (int    *argc,
                               char ***argv)
@@ -839,6 +709,8 @@ do_post_parse_initialization (int    *argc,
       g_warning ("Whoever translated default:LTR did so wrongly.\n");
   }
 
+  _gtk_register_resource ();
+
   /* do what the call to gtk_type_init() used to do */
   g_type_init ();
 
@@ -858,6 +730,8 @@ do_post_parse_initialization (int    *argc,
     {
       _gtk_modules_init (argc, argv, NULL);
     }
+
+  _gtk_accessibility_init ();
 }
 
 
@@ -935,7 +809,7 @@ gtk_set_debug_flags (guint flags)
 }
 
 /**
- * gtk_get_option_group:
+ * gtk_get_option_group: (skip)
  * @open_default_display: whether to open the default display
  *     when parsing the commandline arguments
  *
@@ -974,13 +848,17 @@ gtk_get_option_group (gboolean open_default_display)
 
 /**
  * gtk_init_with_args:
- * @argc: a pointer to the number of command line arguments
- * @argv: a pointer to the array of command line arguments
+ * @argc: (inout): Address of the <parameter>argc</parameter> parameter of
+ *     your main() function (or 0 if @argv is %NULL). This will be changed if 
+ *     any arguments were handled.
+ * @argv: (array length=argc) (inout) (allow-none): Address of the
+ *     <parameter>argv</parameter> parameter of main(), or %NULL. Any options
+ *     understood by GTK+ are stripped before return.
  * @parameter_string: a string which is displayed in
  *    the first line of <option>--help</option> output, after
  *    <literal><replaceable>programname</replaceable> [OPTION...]</literal>
- * @entries: a %NULL-terminated array of #GOptionEntrys
- *    describing the options of your program
+ * @entries: (array zero-terminated=1): a %NULL-terminated array
+ *    of #GOptionEntrys 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
  *    and the @parameter_string with gettext(), or %NULL
@@ -1036,7 +914,8 @@ gtk_init_with_args (gint                 *argc,
 /**
  * gtk_parse_args:
  * @argc: (inout): a pointer to the number of command line arguments
- * @argv: (array) (inout): a pointer to the array of command line arguments
+ * @argv: (array length=argc) (inout): a pointer to the array of
+ *     command line arguments
  *
  * Parses command line arguments, and initializes global
  * attributes of GTK+, but does not actually open a connection
@@ -1089,10 +968,11 @@ gtk_parse_args (int    *argc,
 /**
  * gtk_init_check:
  * @argc: (inout): Address of the <parameter>argc</parameter> parameter of
- *     your main() function. Changed if any arguments were handled
+ *     your main() function (or 0 if @argv is %NULL). This will be changed if 
+ *     any arguments were handled.
  * @argv: (array length=argc) (inout) (allow-none): Address of the
- *     <parameter>argv</parameter> parameter of main()
- *   Any parameters understood by gtk_init() are stripped before return
+ *     <parameter>argv</parameter> parameter of main(), or %NULL. Any options
+ *     understood by GTK+ are stripped before return.
  *
  * This function does the same work as gtk_init() with only a single
  * change: It does not terminate the program if the windowing system
@@ -1122,15 +1002,20 @@ gtk_init_check (int    *argc,
 /**
  * gtk_init:
  * @argc: (inout): Address of the <parameter>argc</parameter> parameter of
- *     your main() function. Changed if any arguments were handled
+ *     your main() function (or 0 if @argv is %NULL). This will be changed if 
+ *     any arguments were handled.
  * @argv: (array length=argc) (inout) (allow-none): Address of the
- *     <parameter>argv</parameter> parameter of main(). Any options
+ *     <parameter>argv</parameter> parameter of main(), or %NULL. Any options
  *     understood by GTK+ are stripped before return.
  *
  * Call this function before using any other GTK+ functions in your GUI
  * applications.  It will initialize everything needed to operate the
  * toolkit and parses some standard command line options.
  *
+ * Although you are expected to pass the @argc, @argv parameters from main() to 
+ * this function, it is possible to pass %NULL if @argv is not available or 
+ * commandline handling is not required.
+ *
  * @argc and @argv are adjusted accordingly so your own code will
  * never see those standard arguments.
  *
@@ -1231,66 +1116,6 @@ gtk_init_check_abi_check (int *argc, char ***argv, int num_checks, size_t sizeof
 
 #endif
 
-/*
- * _gtk_get_lc_ctype:
- *
- * Return the Unix-style locale string for the language currently in
- * effect. On Unix systems, this is the return value from
- * <literal>setlocale(LC_CTYPE, NULL)</literal>, and the user can
- * affect this through the environment variables LC_ALL, LC_CTYPE or
- * LANG (checked in that order). The locale strings typically is in
- * the form lang_COUNTRY, where lang is an ISO-639 language code, and
- * COUNTRY is an ISO-3166 country code. For instance, sv_FI for
- * Swedish as written in Finland or pt_BR for Portuguese as written in
- * Brazil.
- *
- * On Windows, the C library doesn't use any such environment
- * variables, and setting them won't affect the behaviour of functions
- * like ctime(). The user sets the locale through the Regional Options
- * in the Control Panel. The C library (in the setlocale() function)
- * does not use country and language codes, but country and language
- * names spelled out in English.
- * However, this function does check the above environment
- * variables, and does return a Unix-style locale string based on
- * either said environment variables or the thread's current locale.
- *
- * Return value: a dynamically allocated string, free with g_free().
- */
-
-gchar *
-_gtk_get_lc_ctype (void)
-{
-#ifdef G_OS_WIN32
-  /* Somebody might try to set the locale for this process using the
-   * LANG or LC_ environment variables. The Microsoft C library
-   * doesn't know anything about them. You set the locale in the
-   * Control Panel. Setting these env vars won't have any affect on
-   * locale-dependent C library functions like ctime(). But just for
-   * kicks, do obey LC_ALL, LC_CTYPE and LANG in GTK. (This also makes
-   * it easier to test GTK and Pango in various default languages, you
-   * don't have to clickety-click in the Control Panel, you can simply
-   * start the program with LC_ALL=something on the command line.)
-   */
-  gchar *p;
-
-  p = getenv ("LC_ALL");
-  if (p != NULL)
-    return g_strdup (p);
-
-  p = getenv ("LC_CTYPE");
-  if (p != NULL)
-    return g_strdup (p);
-
-  p = getenv ("LANG");
-  if (p != NULL)
-    return g_strdup (p);
-
-  return g_win32_getlocale ();
-#else
-  return g_strdup (setlocale (LC_CTYPE, NULL));
-#endif
-}
-
 /**
  * gtk_get_default_language:
  *
@@ -1813,15 +1638,26 @@ gtk_main_do_event (GdkEvent *event)
 
     case GDK_KEY_PRESS:
     case GDK_KEY_RELEASE:
-      if (key_snoopers)
-        {
-          if (gtk_invoke_key_snoopers (grab_widget, event))
-            break;
-        }
+      if (gtk_invoke_key_snoopers (grab_widget, event))
+        break;
+
+      /* make focus visible in a window that receives a key event */
+      {
+        GtkWidget *window;
+        GtkPolicyType visible_focus;
+
+        window = gtk_widget_get_toplevel (grab_widget);
+        g_object_get (gtk_widget_get_settings (grab_widget), "gtk-visible-focus", &visible_focus, NULL);
+        if (GTK_IS_WINDOW (window) && visible_focus != GTK_POLICY_NEVER)
+          gtk_window_set_focus_visible (GTK_WINDOW (window), TRUE);
+      }
+
       /* Catch alt press to enable auto-mnemonics;
        * menus are handled elsewhere
+       * FIXME: this does not work with mnemonic modifiers other than Alt
        */
       if ((event->key.keyval == GDK_KEY_Alt_L || event->key.keyval == GDK_KEY_Alt_R) &&
+          ((event->key.state & (gtk_accelerator_get_default_mod_mask ()) & ~(GDK_RELEASE_MASK|GDK_MOD1_MASK)) == 0) &&
           !GTK_IS_MENU_SHELL (grab_widget))
         {
           gboolean auto_mnemonics;
@@ -1837,7 +1673,6 @@ gtk_main_do_event (GdkEvent *event)
               mnemonics_visible = (event->type == GDK_KEY_PRESS);
 
               window = gtk_widget_get_toplevel (grab_widget);
-
               if (GTK_IS_WINDOW (window))
                 gtk_window_set_mnemonics_visible (GTK_WINDOW (window), mnemonics_visible);
             }
@@ -1851,17 +1686,21 @@ gtk_main_do_event (GdkEvent *event)
       break;
 
     case GDK_ENTER_NOTIFY:
-      _gtk_widget_set_device_window (event_widget,
-                                     gdk_event_get_device (event),
-                                     event->any.window);
+      if (event->crossing.detail != GDK_NOTIFY_VIRTUAL &&
+          event->crossing.detail != GDK_NOTIFY_NONLINEAR_VIRTUAL)
+        _gtk_widget_set_device_window (event_widget,
+                                       gdk_event_get_device (event),
+                                       event->any.window);
       if (gtk_widget_is_sensitive (grab_widget))
         gtk_widget_event (grab_widget, event);
       break;
 
     case GDK_LEAVE_NOTIFY:
-      _gtk_widget_set_device_window (event_widget,
-                                     gdk_event_get_device (event),
-                                     NULL);
+      if (event->crossing.detail != GDK_NOTIFY_VIRTUAL &&
+          event->crossing.detail != GDK_NOTIFY_NONLINEAR_VIRTUAL)
+        _gtk_widget_set_device_window (event_widget,
+                                       gdk_event_get_device (event),
+                                       NULL);
       if (gtk_widget_is_sensitive (grab_widget))
         gtk_widget_event (grab_widget, event);
       break;
@@ -2149,7 +1988,7 @@ gtk_grab_notify (GtkWindowGroup *group,
 }
 
 /**
- * gtk_grab_add:
+ * gtk_grab_add: (method)
  * @widget: The widget that grabs keyboard and pointer events
  *
  * Makes @widget the current grabbed widget.
@@ -2203,7 +2042,7 @@ gtk_grab_get_current (void)
 }
 
 /**
- * gtk_grab_remove:
+ * gtk_grab_remove: (method)
  * @widget: The widget which gives up the grab
  *
  * Removes the grab from the given widget.
@@ -2297,7 +2136,7 @@ gtk_device_grab_remove (GtkWidget *widget,
 }
 
 /**
- * gtk_key_snooper_install:
+ * gtk_key_snooper_install: (skip)
  * @snooper: a #GtkKeySnoopFunc
  * @func_data: data to pass to @snooper
  *
@@ -2306,6 +2145,9 @@ gtk_device_grab_remove (GtkWidget *widget,
  *
  * Returns: a unique id for this key snooper for use with
  *    gtk_key_snooper_remove().
+ *
+ * Deprecated: 3.4: Key snooping should not be done. Events should
+ *     be handled by widgets.
  */
 guint
 gtk_key_snooper_install (GtkKeySnoopFunc snooper,
@@ -2330,6 +2172,9 @@ gtk_key_snooper_install (GtkKeySnoopFunc snooper,
  * @snooper_handler_id: Identifies the key snooper to remove
  *
  * Removes the key snooper function with the given id.
+ *
+ * Deprecated: 3.4: Key snooping should not be done. Events should
+ *     be handled by widgets.
  */
 void
 gtk_key_snooper_remove (guint snooper_id)
@@ -2361,6 +2206,8 @@ gtk_invoke_key_snoopers (GtkWidget *grab_widget,
   GSList *slist;
   gint return_val = FALSE;
 
+  return_val = _gail_util_key_snooper (grab_widget, (GdkEventKey *) event);
+
   slist = key_snoopers;
   while (slist && !return_val)
     {
@@ -2383,9 +2230,9 @@ gtk_invoke_key_snoopers (GtkWidget *grab_widget,
  * the current event will be the #GdkEventButton that triggered
  * the ::clicked signal.
  *
- * Return value: a copy of the current event, or %NULL if there is
- *     no current event. The returned event must be freed with
- *     gdk_event_free().
+ * Return value: (transfer full): a copy of the current event, or
+ *     %NULL if there is no current event. The returned event must be
+ *     freed with gdk_event_free().
  */
 GdkEvent*
 gtk_get_current_event (void)
@@ -2416,7 +2263,7 @@ gtk_get_current_event_time (void)
 
 /**
  * gtk_get_current_event_state:
- * @state: a location to store the state of the current event
+ * @state: (out): a location to store the state of the current event
  *
  * If there is a current event and it has a state field, place
  * that state field in @state and return %TRUE, otherwise return
@@ -2588,19 +2435,3 @@ gtk_propagate_event (GtkWidget *widget,
   else
     g_object_unref (widget);
 }
-
-gboolean
-_gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
-                                  GValue                *return_accu,
-                                  const GValue          *handler_return,
-                                  gpointer               dummy)
-{
-  gboolean continue_emission;
-  gboolean signal_handled;
-
-  signal_handled = g_value_get_boolean (handler_return);
-  g_value_set_boolean (return_accu, signal_handled);
-  continue_emission = !signal_handled;
-
-  return continue_emission;
-}