]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrc.c
Updated galician translations
[~andy/gtk] / gtk / gtkrc.c
index 70540a3130216ec571d1da699a9f7acd15976dd9..84efc27a06c3559413f143bb46909ecb0ae9a400 100644 (file)
@@ -56,8 +56,6 @@
 #include "gtksettings.h"
 #include "gtkwindow.h"
 
-#include "gtkalias.h"
-
 #ifdef G_OS_WIN32
 #include <io.h>
 #endif
@@ -117,9 +115,10 @@ struct _GtkRcContext
   /* The files we have parsed, to reread later if necessary */
   GSList *rc_files;
 
-  gchar *theme_name;
-  gchar *key_theme_name;
-  gchar *font_name;
+  gchar    *theme_name;
+  gboolean  prefer_dark_theme;
+  gchar    *key_theme_name;
+  gchar    *font_name;
   
   gchar **pixmap_path;
 
@@ -160,9 +159,10 @@ static GtkStyle *  gtk_rc_style_to_style             (GtkRcContext    *context,
 static GtkStyle*   gtk_rc_init_style                 (GtkRcContext    *context,
                                                      GSList          *rc_styles);
 static void        gtk_rc_parse_default_files        (GtkRcContext    *context);
-static void        gtk_rc_parse_named                (GtkRcContext    *context,
+static gboolean    gtk_rc_parse_named                (GtkRcContext    *context,
                                                      const gchar     *name,
-                                                     const gchar     *type);
+                                                     const gchar     *type,
+                                                     const gchar     *variant);
 static void        gtk_rc_context_parse_file         (GtkRcContext    *context,
                                                      const gchar     *filename,
                                                      gint             priority,
@@ -399,9 +399,9 @@ gtk_rc_make_default_dir (const gchar *type)
   var = g_getenv ("GTK_EXE_PREFIX");
 
   if (var)
-    path = g_build_filename (var, "lib", "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
+    path = g_build_filename (var, "lib", "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
   else
-    path = g_build_filename (GTK_LIBDIR, "gtk-2.0", GTK_BINARY_VERSION, type, NULL);
+    path = g_build_filename (GTK_LIBDIR, "gtk-3.0", GTK_BINARY_VERSION, type, NULL);
 
   return path;
 }
@@ -448,9 +448,9 @@ gtk_rc_get_im_module_file (void)
   if (!result)
     {
       if (im_module_file)
-       result = g_strdup (im_module_file);
+        result = g_strdup (im_module_file);
       else
-       result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtk.immodules", NULL);
+        result = gtk_rc_make_default_dir ("immodules.cache");
     }
 
   return result;
@@ -522,7 +522,7 @@ gtk_rc_add_initial_default_files (void)
   else
     {
       const gchar *home;
-      str = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gtkrc", NULL);
+      str = g_build_filename (GTK_SYSCONFDIR, "gtk-3.0", "gtkrc", NULL);
 
       gtk_rc_add_default_file (str);
       g_free (str);
@@ -530,7 +530,7 @@ gtk_rc_add_initial_default_files (void)
       home = g_get_home_dir ();
       if (home)
        {
-         str = g_build_filename (home, ".gtkrc-2.0", NULL);
+         str = g_build_filename (home, ".gtkrc-3.0", NULL);
          gtk_rc_add_default_file (str);
          g_free (str);
        }
@@ -601,13 +601,13 @@ gtk_rc_set_default_files (gchar **filenames)
 
 /**
  * gtk_rc_get_default_files:
- * 
+ *
  * Retrieves the current list of RC files that will be parsed
  * at the end of gtk_init().
- * 
- * Return value: A %NULL-terminated array of filenames. This memory
- * is owned by GTK+ and must not be freed by the application.
- * If you want to store this information, you should make a copy.
+ *
+ * Return value: (transfer none): A %NULL-terminated array of filenames.
+ *     This memory is owned by GTK+ and must not be freed by the application.
+ *     If you want to store this information, you should make a copy.
  **/
 gchar **
 gtk_rc_get_default_files (void)
@@ -624,6 +624,7 @@ gtk_rc_settings_changed (GtkSettings  *settings,
 {
   gchar *new_theme_name;
   gchar *new_key_theme_name;
+  gboolean new_prefer_dark_theme;
 
   if (context->reloading)
     return;
@@ -631,12 +632,14 @@ gtk_rc_settings_changed (GtkSettings  *settings,
   g_object_get (settings,
                "gtk-theme-name", &new_theme_name,
                "gtk-key-theme-name", &new_key_theme_name,
+               "gtk-application-prefer-dark-theme", &new_prefer_dark_theme,
                NULL);
 
   if ((new_theme_name != context->theme_name && 
        !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
       (new_key_theme_name != context->key_theme_name &&
-       !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
+       !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)) ||
+      new_prefer_dark_theme != context->prefer_dark_theme)
     {
       gtk_rc_reparse_all_for_settings (settings, TRUE);
     }
@@ -692,6 +695,7 @@ gtk_rc_context_get (GtkSettings *settings)
                    "gtk-key-theme-name", &context->key_theme_name,
                    "gtk-font-name", &context->font_name,
                    "color-hash", &context->color_hash,
+                   "gtk-application-prefer-dark-theme", &context->prefer_dark_theme,
                    NULL);
 
       g_signal_connect (settings,
@@ -710,6 +714,10 @@ gtk_rc_context_get (GtkSettings *settings)
                        "notify::color-hash",
                        G_CALLBACK (gtk_rc_color_hash_changed),
                        context);
+      g_signal_connect (settings,
+                       "notify::gtk-application-prefer-dark-theme",
+                       G_CALLBACK (gtk_rc_settings_changed),
+                       context);
 
       context->pixmap_path = NULL;
 
@@ -785,22 +793,27 @@ _gtk_rc_context_destroy (GtkSettings *settings)
   settings->rc_context = NULL;
 }
 
-static void
+static gboolean
 gtk_rc_parse_named (GtkRcContext *context,
                    const gchar  *name,
-                   const gchar  *type)
+                   const gchar  *type,
+                   const gchar  *variant)
 {
   gchar *path = NULL;
   const gchar *home_dir;
   gchar *subpath;
+  gboolean retval;
+
+  retval = FALSE;
 
   if (type)
-    subpath = g_strconcat ("gtk-2.0-", type,
+    subpath = g_strconcat ("gtk-3.0-", type,
                           G_DIR_SEPARATOR_S "gtkrc",
                           NULL);
   else
-    subpath = g_strdup ("gtk-2.0" G_DIR_SEPARATOR_S "gtkrc");
-  
+    subpath = g_strconcat ("gtk-3.0" G_DIR_SEPARATOR_S "gtkrc",
+                          variant, NULL);
+
   /* First look in the users home directory
    */
   home_dir = g_get_home_dir ();
@@ -831,9 +844,12 @@ gtk_rc_parse_named (GtkRcContext *context,
     {
       gtk_rc_context_parse_file (context, path, GTK_PATH_PRIO_THEME, FALSE);
       g_free (path);
+      retval = TRUE;
     }
 
   g_free (subpath);
+
+  return retval;
 }
 
 static void
@@ -887,17 +903,11 @@ _gtk_rc_init (void)
                       "  text[PRELIGHT] = \"#ffffff\"\n"
                       "}\n"
                       "\n"
-                       /* Work around clipping of accelerator underlines */
-                       "style \"gtk-default-label-style\" {\n"
-                       "  GtkWidget::draw-border = {0,0,0,1}\n"
-                       "}\n"
-                       "\n"    
                       "class \"GtkProgressBar\" style : gtk \"gtk-default-progress-bar-style\"\n"
                       "class \"GtkEntry\" style : gtk \"gtk-default-entry-style\"\n"
                       "widget \"gtk-tooltip*\" style : gtk \"gtk-default-tooltips-style\"\n"
                       "widget_class \"*<GtkMenuItem>*\" style : gtk \"gtk-default-menu-item-style\"\n"
                       "widget_class \"*<GtkMenuBar>*<GtkMenuItem>\" style : gtk \"gtk-default-menu-bar-item-style\"\n"
-                       "class \"GtkLabel\" style : gtk \"gtk-default-label-style\"\n"
       );
 }
   
@@ -1250,12 +1260,12 @@ gtk_rc_style_new (void)
 /**
  * gtk_rc_style_copy:
  * @orig: the style to copy
- * 
+ *
  * Makes a copy of the specified #GtkRcStyle. This function
  * will correctly copy an RC style that is a member of a class
  * derived from #GtkRcStyle.
- * 
- * Return value: the resulting #GtkRcStyle
+ *
+ * Return value: (transfer full): the resulting #GtkRcStyle
  **/
 GtkRcStyle *
 gtk_rc_style_copy (GtkRcStyle *orig)
@@ -1304,22 +1314,6 @@ _gtk_rc_style_unset_rc_property (GtkRcStyle *rc_style,
     }
 }
 
-void      
-gtk_rc_style_ref (GtkRcStyle *rc_style)
-{
-  g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
-
-  g_object_ref (rc_style);
-}
-
-void      
-gtk_rc_style_unref (GtkRcStyle *rc_style)
-{
-  g_return_if_fail (GTK_IS_RC_STYLE (rc_style));
-
-  g_object_unref (rc_style);
-}
-
 static GtkRcStyle *
 gtk_rc_style_real_create_rc_style (GtkRcStyle *style)
 {
@@ -1334,6 +1328,34 @@ _gtk_rc_style_get_color_hashes (GtkRcStyle *rc_style)
   return priv->color_hashes;
 }
 
+static void gtk_rc_style_prepend_empty_color_hash (GtkRcStyle *rc_style);
+
+void
+_gtk_rc_style_set_symbolic_color (GtkRcStyle     *rc_style,
+                                  const gchar    *name,
+                                  const GdkColor *color)
+{
+  GtkRcStylePrivate *priv = GTK_RC_STYLE_GET_PRIVATE (rc_style);
+  GHashTable *our_hash = NULL;
+
+  if (priv->color_hashes)
+    our_hash = priv->color_hashes->data;
+
+  if (our_hash == NULL)
+    {
+      if (color == NULL)
+        return;
+
+      gtk_rc_style_prepend_empty_color_hash (rc_style);
+      our_hash = priv->color_hashes->data;
+    }
+
+  if (color)
+    g_hash_table_insert (our_hash, g_strdup (name), gdk_color_copy (color));
+  else
+    g_hash_table_remove (our_hash, name);
+}
+
 static gint
 gtk_rc_properties_cmp (gconstpointer bsearch_node1,
                       gconstpointer bsearch_node2)
@@ -1812,12 +1834,23 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings,
       g_object_get (context->settings,
                    "gtk-theme-name", &context->theme_name,
                    "gtk-key-theme-name", &context->key_theme_name,
+                   "gtk-application-prefer-dark-theme", &context->prefer_dark_theme,
                    NULL);
 
       if (context->theme_name && context->theme_name[0])
-       gtk_rc_parse_named (context, context->theme_name, NULL);
+        {
+          if (context->prefer_dark_theme)
+            {
+              if (!gtk_rc_parse_named (context, context->theme_name, NULL, "-dark"))
+                gtk_rc_parse_named (context, context->theme_name, NULL, NULL);
+           }
+         else
+           {
+             gtk_rc_parse_named (context, context->theme_name, NULL, NULL);
+           }
+       }
       if (context->key_theme_name && context->key_theme_name[0])
-       gtk_rc_parse_named (context, context->key_theme_name, "key");
+       gtk_rc_parse_named (context, context->key_theme_name, "key", NULL);
 
       context->reloading = FALSE;
 
@@ -2028,13 +2061,13 @@ gtk_rc_get_style (GtkWidget *widget)
 /**
  * gtk_rc_get_style_by_paths:
  * @settings: a #GtkSettings object
- * @widget_path: the widget path to use when looking up the style, or %NULL
- *               if no matching against the widget path should be done
- * @class_path: the class path to use when looking up the style, or %NULL
- *               if no matching against the class path should be done.
+ * @widget_path: (allow-none): the widget path to use when looking up the
+ *     style, or %NULL if no matching against the widget path should be done
+ * @class_path: (allow-none): the class path to use when looking up the style,
+ *     or %NULL if no matching against the class path should be done.
  * @type: a type that will be used along with parent types of this type
- *        when matching against class styles, or #G_TYPE_NONE
- * 
+ *     when matching against class styles, or #G_TYPE_NONE
+ *
  * Creates up a #GtkStyle from styles defined in a RC file by providing
  * the raw components used in matching. This function may be useful
  * when creating pseudo-widgets that should be themed like widgets but
@@ -2050,11 +2083,11 @@ gtk_rc_get_style (GtkWidget *widget)
  *                             G_OBJECT_TYPE (widget));
  * ]|
  * 
- * Return value: A style created by matching with the supplied paths,
- *   or %NULL if nothing matching was specified and the default style should
- *   be used. The returned value is owned by GTK+ as part of an internal cache,
- *   so you must call g_object_ref() on the returned value if you want to
- *   keep a reference to it.
+ * Return value: (transfer none): A style created by matching with the
+ *     supplied paths, or %NULL if nothing matching was specified and the
+ *     default style should be used. The returned value is owned by GTK+
+ *     as part of an internal cache, so you must call g_object_ref() on
+ *     the returned value if you want to keep a reference to it.
  **/
 GtkStyle *
 gtk_rc_get_style_by_paths (GtkSettings *settings,
@@ -2134,86 +2167,6 @@ gtk_rc_get_style_by_paths (GtkSettings *settings,
   return NULL;
 }
 
-static GSList *
-gtk_rc_add_rc_sets (GSList      *slist,
-                   GtkRcStyle  *rc_style,
-                   const gchar *pattern,
-                   GtkPathType  path_type)
-{
-  GtkRcStyle *new_style;
-  GtkRcSet *rc_set;
-  guint i;
-  
-  new_style = gtk_rc_style_new ();
-  *new_style = *rc_style;
-  new_style->name = g_strdup (rc_style->name);
-  if (rc_style->font_desc)
-    new_style->font_desc = pango_font_description_copy (rc_style->font_desc);
-  
-  for (i = 0; i < 5; i++)
-    new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]);
-  
-  rc_set = g_new (GtkRcSet, 1);
-  rc_set->type = path_type;
-  
-  if (path_type == GTK_PATH_WIDGET_CLASS)
-    {
-      rc_set->pspec = NULL;
-      rc_set->path = _gtk_rc_parse_widget_class_path (pattern);
-    }
-  else
-    {
-      rc_set->pspec = g_pattern_spec_new (pattern);
-      rc_set->path = NULL;
-    }
-  
-  rc_set->rc_style = rc_style;
-  
-  return g_slist_prepend (slist, rc_set);
-}
-
-void
-gtk_rc_add_widget_name_style (GtkRcStyle  *rc_style,
-                             const gchar *pattern)
-{
-  GtkRcContext *context;
-  
-  g_return_if_fail (rc_style != NULL);
-  g_return_if_fail (pattern != NULL);
-
-  context = gtk_rc_context_get (gtk_settings_get_default ());
-  
-  context->rc_sets_widget = gtk_rc_add_rc_sets (context->rc_sets_widget, rc_style, pattern, GTK_PATH_WIDGET);
-}
-
-void
-gtk_rc_add_widget_class_style (GtkRcStyle  *rc_style,
-                              const gchar *pattern)
-{
-  GtkRcContext *context;
-  
-  g_return_if_fail (rc_style != NULL);
-  g_return_if_fail (pattern != NULL);
-
-  context = gtk_rc_context_get (gtk_settings_get_default ());
-  
-  context->rc_sets_widget_class = gtk_rc_add_rc_sets (context->rc_sets_widget_class, rc_style, pattern, GTK_PATH_WIDGET_CLASS);
-}
-
-void
-gtk_rc_add_class_style (GtkRcStyle  *rc_style,
-                       const gchar *pattern)
-{
-  GtkRcContext *context;
-  
-  g_return_if_fail (rc_style != NULL);
-  g_return_if_fail (pattern != NULL);
-
-  context = gtk_rc_context_get (gtk_settings_get_default ());
-  
-  context->rc_sets_class = gtk_rc_add_rc_sets (context->rc_sets_class, rc_style, pattern, GTK_PATH_CLASS);
-}
-
 GScanner*
 gtk_rc_scanner_new (void)
 {
@@ -2266,13 +2219,15 @@ gtk_rc_parse_any (GtkRcContext *context,
 
              if (scanner->scope_id == 0)
                {
+                  guint token;
+
                  /* if we are in scope 0, we know the symbol names
                   * that are associated with certain token values.
                   * so we look them up to make the error messages
                   * more readable.
                   */
-                 if (expected_token > GTK_RC_TOKEN_INVALID &&
-                     expected_token < GTK_RC_TOKEN_LAST)
+                  if (expected_token > GTK_RC_TOKEN_INVALID &&
+                      expected_token < GTK_RC_TOKEN_LAST)
                    {
                       const gchar *sym = NULL;
 
@@ -2284,8 +2239,9 @@ gtk_rc_parse_any (GtkRcContext *context,
                        msg = g_strconcat ("e.g. `", sym, "'", NULL);
                    }
 
-                 if (scanner->token > GTK_RC_TOKEN_INVALID &&
-                     scanner->token < GTK_RC_TOKEN_LAST)
+                  token = scanner->token;
+                  if (token > GTK_RC_TOKEN_INVALID &&
+                      token < GTK_RC_TOKEN_LAST)
                    {
                      symbol_name = "???";
                      for (i = 0; i < G_N_ELEMENTS (symbols); i++)
@@ -3371,7 +3327,10 @@ static guint
 gtk_rc_parse_xthickness (GScanner   *scanner,
                         GtkRcStyle *style)
 {
-  if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_XTHICKNESS)
+  guint token;
+
+  token = g_scanner_get_next_token (scanner);
+  if (token != GTK_RC_TOKEN_XTHICKNESS)
     return GTK_RC_TOKEN_XTHICKNESS;
 
   if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
@@ -3389,7 +3348,10 @@ static guint
 gtk_rc_parse_ythickness (GScanner   *scanner,
                         GtkRcStyle *style)
 {
-  if (g_scanner_get_next_token (scanner) != GTK_RC_TOKEN_YTHICKNESS)
+  guint token;
+
+  token =  g_scanner_get_next_token (scanner);
+  if (token != GTK_RC_TOKEN_YTHICKNESS)
     return GTK_RC_TOKEN_YTHICKNESS;
 
   if (g_scanner_get_next_token (scanner) != G_TOKEN_EQUAL_SIGN)
@@ -3868,7 +3830,7 @@ gtk_rc_parse_color (GScanner *scanner,
 /**
  * gtk_rc_parse_color_full:
  * @scanner: a #GScanner
- * @style: a #GtkRcStyle, or %NULL
+ * @style: (allow-none): a #GtkRcStyle, or %NULL
  * @color: a pointer to a #GdkColor structure in which to store the result
  *
  * Parses a color in the <link linkend="color=format">format</link> expected
@@ -4866,59 +4828,3 @@ _gtk_rc_match_widget_class (GSList  *list,
 {
   return match_widget_class_recursive (list, length, path, path_reversed);
 }
-
-#if defined (G_OS_WIN32) && !defined (_WIN64)
-
-/* DLL ABI stability backward compatibility versions */
-
-#undef gtk_rc_add_default_file
-
-void
-gtk_rc_add_default_file (const gchar *filename)
-{
-  gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
-
-  gtk_rc_add_default_file_utf8 (utf8_filename);
-
-  g_free (utf8_filename);
-}
-
-#undef gtk_rc_set_default_files
-
-void
-gtk_rc_set_default_files (gchar **filenames)
-{
-  gchar **utf8_filenames;
-  int n = 0, i;
-
-  while (filenames[n++] != NULL)
-    ;
-
-  utf8_filenames = g_new (gchar *, n + 1);
-
-  for (i = 0; i < n; i++)
-    utf8_filenames[i] = g_locale_to_utf8 (filenames[i], -1, NULL, NULL, NULL);
-
-  utf8_filenames[n] = NULL;
-
-  gtk_rc_set_default_files_utf8 (utf8_filenames);
-
-  g_strfreev (utf8_filenames);
-}
-
-#undef gtk_rc_parse
-
-void
-gtk_rc_parse (const gchar *filename)
-{
-  gchar *utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, NULL);
-
-  gtk_rc_parse_utf8 (utf8_filename);
-
-  g_free (utf8_filename);
-}
-
-#endif
-
-#define __GTK_RC_C__
-#include "gtkaliasdef.c"