]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcsssection.c
GtkEntry: Sanity check the end_pos value in _get_display_text()
[~andy/gtk] / gtk / gtkcsssection.c
index 1b467570da137ab3258001fd000e3a0193ba3073..9246d2d27c65fcd446e1e00f479bf404df5f8e7a 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/>.
  */
 
 #include "config.h"
@@ -51,13 +49,11 @@ G_DEFINE_BOXED_TYPE (GtkCssSection, gtk_css_section, gtk_css_section_ref, gtk_cs
 GtkCssSection *
 _gtk_css_section_new (GtkCssSection     *parent,
                       GtkCssSectionType  type,
-                      GtkCssParser      *parser,
-                      GFile             *file)
+                      GtkCssParser      *parser)
 {
   GtkCssSection *section;
 
   g_return_val_if_fail (parser != NULL, NULL);
-  g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL);
 
   section = g_slice_new0 (GtkCssSection);
 
@@ -65,8 +61,9 @@ _gtk_css_section_new (GtkCssSection     *parent,
   section->section_type = type;
   if (parent)
     section->parent = gtk_css_section_ref (parent);
-  if (file)
-    section->file = g_object_ref (file);
+  section->file = _gtk_css_parser_get_file (parser);
+  if (section->file)
+    g_object_ref (section->file);
   section->start_line = _gtk_css_parser_get_line (parser);
   section->start_position = _gtk_css_parser_get_position (parser);
   section->parser = parser;
@@ -171,10 +168,10 @@ gtk_css_section_get_section_type (const GtkCssSection *section)
  *
  * Gets the parent section for the given @section. The parent section is
  * the section that contains this @section. A special case are sections of
- * type #GTK_CSS_SECTION_TYPE_DOCUMENT. Their parent will either be %NULL
+ * type #GTK_CSS_SECTION_DOCUMENT. Their parent will either be %NULL
  * if they are the original CSS document that was loaded by
  * gtk_css_provider_load_from_file() or a section of type
- * #GTK_CSS_SECTION_TYPE_IMPORT if it was loaded with an import rule from
+ * #GTK_CSS_SECTION_IMPORT if it was loaded with an import rule from
  * a different file.
  *
  * Returns: the parent section or %NULL if none
@@ -194,11 +191,11 @@ gtk_css_section_get_parent (const GtkCssSection *section)
  * @section: the section
  *
  * Gets the file that @section was parsed from. If no such file exists,
- * for example because the CSS was loaded via 
+ * for example because the CSS was loaded via
  * @gtk_css_provider_load_from_data(), then %NULL is returned.
  *
- * Returns: the #GFile that @section was parsed from or %NULL if
- *   @section was parsed from other data.
+ * Returns: (transfer none): the #GFile that @section was parsed from
+ *     or %NULL if @section was parsed from other data
  *
  * Since: 3.2
  **/
@@ -306,3 +303,45 @@ gtk_css_section_get_end_position (const GtkCssSection *section)
     return section->end_position;
 }
 
+void
+_gtk_css_section_print (const GtkCssSection  *section,
+                        GString              *string)
+{
+  if (section->file)
+    {
+      GFileInfo *info;
+
+      info = g_file_query_info (section->file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
+
+      if (info)
+        {
+          g_string_append (string, g_file_info_get_display_name (info));
+          g_object_unref (info);
+        }
+      else
+        {
+          g_string_append (string, "<broken file>");
+        }
+    }
+  else
+    {
+      g_string_append (string, "<data>");
+    }
+
+  g_string_append_printf (string, ":%u:%u", 
+                          gtk_css_section_get_end_line (section) + 1,
+                          gtk_css_section_get_end_position (section));
+}
+
+char *
+_gtk_css_section_to_string (const GtkCssSection *section)
+{
+  GString *string;
+
+  g_return_val_if_fail (section != NULL, NULL);
+
+  string = g_string_new (NULL);
+  _gtk_css_section_print (section, string);
+
+  return g_string_free (string, FALSE);
+}