summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-04-10 05:18:14 +0200
committerBenjamin Otte <otte@redhat.com>2019-04-12 19:34:28 +0200
commita8f712b09af665577213a3696da64197396e8654 (patch)
treeb7b6973a1d07dec310149c5a3050bc4091b59a44
parent2fb202187cc1185d854ee7229a12e3f1f31ecba4 (diff)
downloadgtk+-a8f712b09af665577213a3696da64197396e8654.tar.gz
cssection: Return locations, not numbers
Now that we have GtkCssLocation, actually use it.
-rw-r--r--demos/gtk-demo/css_basics.c11
-rw-r--r--demos/gtk-demo/css_multiplebgs.c12
-rw-r--r--demos/gtk-demo/css_pixbufs.c12
-rw-r--r--demos/gtk-demo/css_shadows.c11
-rw-r--r--docs/reference/gtk/gtk4-sections.txt6
-rw-r--r--gtk/gtkcsssection.c99
-rw-r--r--gtk/gtkcsssection.h12
-rw-r--r--gtk/inspector/css-editor.c11
-rw-r--r--tests/testboxcss.c11
-rw-r--r--testsuite/css/parser/test-css-parser.c7
10 files changed, 77 insertions, 115 deletions
diff --git a/demos/gtk-demo/css_basics.c b/demos/gtk-demo/css_basics.c
index 258aacb46b..06b36483ed 100644
--- a/demos/gtk-demo/css_basics.c
+++ b/demos/gtk-demo/css_basics.c
@@ -13,17 +13,20 @@ show_parsing_error (GtkCssProvider *provider,
const GError *error,
GtkTextBuffer *buffer)
{
+ const GtkCssLocation *start_location, *end_location;
GtkTextIter start, end;
const char *tag_name;
+ start_location = gtk_css_section_get_start_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&start,
- gtk_css_section_get_start_line (section),
- gtk_css_section_get_start_position (section));
+ start_location->lines,
+ start_location->line_bytes);
+ end_location = gtk_css_section_get_end_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&end,
- gtk_css_section_get_end_line (section),
- gtk_css_section_get_end_position (section));
+ end_location->lines,
+ end_location->line_bytes);
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
diff --git a/demos/gtk-demo/css_multiplebgs.c b/demos/gtk-demo/css_multiplebgs.c
index e865521bba..6475c2c31a 100644
--- a/demos/gtk-demo/css_multiplebgs.c
+++ b/demos/gtk-demo/css_multiplebgs.c
@@ -13,17 +13,21 @@ show_parsing_error (GtkCssProvider *provider,
const GError *error,
GtkTextBuffer *buffer)
{
+ const GtkCssLocation *start_location, *end_location;
GtkTextIter start, end;
const char *tag_name;
+ start_location = gtk_css_section_get_start_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&start,
- gtk_css_section_get_start_line (section),
- gtk_css_section_get_start_position (section));
+ start_location->lines,
+ start_location->line_bytes);
+ end_location = gtk_css_section_get_end_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&end,
- gtk_css_section_get_end_line (section),
- gtk_css_section_get_end_position (section));
+ end_location->lines,
+ end_location->line_bytes);
+
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
diff --git a/demos/gtk-demo/css_pixbufs.c b/demos/gtk-demo/css_pixbufs.c
index 7cd5b975bb..4846102ac3 100644
--- a/demos/gtk-demo/css_pixbufs.c
+++ b/demos/gtk-demo/css_pixbufs.c
@@ -12,17 +12,21 @@ show_parsing_error (GtkCssProvider *provider,
const GError *error,
GtkTextBuffer *buffer)
{
+ const GtkCssLocation *start_location, *end_location;
GtkTextIter start, end;
const char *tag_name;
+ start_location = gtk_css_section_get_start_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&start,
- gtk_css_section_get_start_line (section),
- gtk_css_section_get_start_position (section));
+ start_location->lines,
+ start_location->line_bytes);
+ end_location = gtk_css_section_get_end_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&end,
- gtk_css_section_get_end_line (section),
- gtk_css_section_get_end_position (section));
+ end_location->lines,
+ end_location->line_bytes);
+
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
diff --git a/demos/gtk-demo/css_shadows.c b/demos/gtk-demo/css_shadows.c
index 318f12d632..318141c896 100644
--- a/demos/gtk-demo/css_shadows.c
+++ b/demos/gtk-demo/css_shadows.c
@@ -11,17 +11,20 @@ show_parsing_error (GtkCssProvider *provider,
const GError *error,
GtkTextBuffer *buffer)
{
+ const GtkCssLocation *start_location, *end_location;
GtkTextIter start, end;
const char *tag_name;
+ start_location = gtk_css_section_get_start_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&start,
- gtk_css_section_get_start_line (section),
- gtk_css_section_get_start_position (section));
+ start_location->lines,
+ start_location->line_bytes);
+ end_location = gtk_css_section_get_end_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&end,
- gtk_css_section_get_end_line (section),
- gtk_css_section_get_end_position (section));
+ end_location->lines,
+ end_location->line_bytes);
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 3b26ffe436..bf98069542 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5092,12 +5092,10 @@ GtkCssParserWarning
<SUBSECTION>
GtkCssLocation
GtkCssSection
-gtk_css_section_get_end_line
-gtk_css_section_get_end_position
gtk_css_section_get_file
gtk_css_section_get_parent
-gtk_css_section_get_start_line
-gtk_css_section_get_start_position
+gtk_css_section_get_start_location
+gtk_css_section_get_end_location
gtk_css_section_ref
gtk_css_section_unref
<SUBSECTION Standard>
diff --git a/gtk/gtkcsssection.c b/gtk/gtkcsssection.c
index c514f27651..6fae99d6bf 100644
--- a/gtk/gtkcsssection.c
+++ b/gtk/gtkcsssection.c
@@ -150,97 +150,40 @@ gtk_css_section_get_file (const GtkCssSection *section)
}
/**
- * gtk_css_section_get_start_line:
+ * gtk_css_section_get_start_location:
* @section: the section
*
- * Returns the line in the CSS document where this section starts.
- * The line number is 0-indexed, so the first line of the document
- * will return 0.
+ * Returns the location in the CSS document where this section starts.
*
- * Returns: the line number
+ * Returns: (tranfer none) (not nullable): The start location of
+ * this section
**/
-guint
-gtk_css_section_get_start_line (const GtkCssSection *section)
+const GtkCssLocation *
+gtk_css_section_get_start_location (const GtkCssSection *section)
{
- gtk_internal_return_val_if_fail (section != NULL, 0);
-
- return section->start_location.lines;
-}
-
-/**
- * gtk_css_section_get_start_position:
- * @section: the section
- *
- * Returns the offset in bytes from the start of the current line
- * returned via gtk_css_section_get_start_line().
- *
- * Returns: the offset in bytes from the start of the line.
- **/
-guint
-gtk_css_section_get_start_position (const GtkCssSection *section)
-{
- gtk_internal_return_val_if_fail (section != NULL, 0);
-
- return section->start_location.line_chars;
-}
-
-/**
- * gtk_css_section_get_end_line:
- * @section: the section
- *
- * Returns the line in the CSS document where this section end.
- * The line number is 0-indexed, so the first line of the document
- * will return 0.
- * This value may change in future invocations of this function if
- * @section is not yet parsed completely. This will for example
- * happen in the GtkCssProvider::parsing-error signal.
- * The end position and line may be identical to the start
- * position and line for sections which failed to parse anything
- * successfully.
- *
- * Returns: the line number
- **/
-guint
-gtk_css_section_get_end_line (const GtkCssSection *section)
-{
- GtkCssLocation location;
-
- gtk_internal_return_val_if_fail (section != NULL, 0);
-
- if (!section->parser)
- return section->end_location.lines;
+ gtk_internal_return_val_if_fail (section != NULL, NULL);
- gtk_css_parser_get_location (section->parser, &location);
- return location.lines;
+ return &section->start_location;
}
/**
- * gtk_css_section_get_end_position:
+ * gtk_css_section_get_end_location:
* @section: the section
*
- * Returns the offset in bytes from the start of the current line
- * returned via gtk_css_section_get_end_line().
- * This value may change in future invocations of this function if
- * @section is not yet parsed completely. This will for example
- * happen in the GtkCssProvider::parsing-error signal.
- * The end position and line may be identical to the start
- * position and line for sections which failed to parse anything
- * successfully.
+ * Returns the location in the CSS document where this section ends.
*
- * Returns: the offset in bytes from the start of the line.
+ * Returns: (tranfer none) (not nullable): The end location of
+ * this section
**/
-guint
-gtk_css_section_get_end_position (const GtkCssSection *section)
+const GtkCssLocation *
+gtk_css_section_get_end_location (const GtkCssSection *section)
{
- GtkCssLocation location;
-
- gtk_internal_return_val_if_fail (section != NULL, 0);
+ gtk_internal_return_val_if_fail (section != NULL, NULL);
- if (!section->parser)
- return section->end_location.line_chars;
+ if (section->parser)
+ gtk_css_parser_get_location (section->parser, (GtkCssLocation *) &section->end_location);
- gtk_css_parser_get_location (section->parser, &location);
- return location.line_chars;
+ return &section->end_location;
}
void
@@ -268,9 +211,9 @@ _gtk_css_section_print (const GtkCssSection *section,
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));
+ g_string_append_printf (string, ":%zu:%zu",
+ section->end_location.lines + 1,
+ section->end_location.line_chars + 1);
}
char *
diff --git a/gtk/gtkcsssection.h b/gtk/gtkcsssection.h
index 4927cd1cc0..5763aad204 100644
--- a/gtk/gtkcsssection.h
+++ b/gtk/gtkcsssection.h
@@ -19,7 +19,7 @@
#define __GTK_CSS_SECTION_H__
#include <gio/gio.h>
-#include <gdk/gdk.h>
+#include <gtk/css/gtkcss.h>
G_BEGIN_DECLS
@@ -47,13 +47,11 @@ GtkCssSection * gtk_css_section_get_parent (const GtkCssSection *se
GDK_AVAILABLE_IN_ALL
GFile * gtk_css_section_get_file (const GtkCssSection *section);
GDK_AVAILABLE_IN_ALL
-guint gtk_css_section_get_start_line (const GtkCssSection *section);
+const GtkCssLocation *
+ gtk_css_section_get_start_location (const GtkCssSection *section);
GDK_AVAILABLE_IN_ALL
-guint gtk_css_section_get_start_position (const GtkCssSection *section);
-GDK_AVAILABLE_IN_ALL
-guint gtk_css_section_get_end_line (const GtkCssSection *section);
-GDK_AVAILABLE_IN_ALL
-guint gtk_css_section_get_end_position (const GtkCssSection *section);
+const GtkCssLocation *
+ gtk_css_section_get_end_location (const GtkCssSection *section);
G_END_DECLS
diff --git a/gtk/inspector/css-editor.c b/gtk/inspector/css-editor.c
index 7033bbd047..4f253d91ca 100644
--- a/gtk/inspector/css-editor.c
+++ b/gtk/inspector/css-editor.c
@@ -292,19 +292,22 @@ show_parsing_error (GtkCssProvider *provider,
{
const char *tag_name;
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (ce->priv->text);
+ const GtkCssLocation *start, *end;
CssError *css_error;
css_error = g_new (CssError, 1);
css_error->error = g_error_copy (error);
+ start = gtk_css_section_get_start_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&css_error->start,
- gtk_css_section_get_start_line (section),
- gtk_css_section_get_start_position (section));
+ start->lines,
+ start->line_bytes);
+ end = gtk_css_section_get_end_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&css_error->end,
- gtk_css_section_get_end_line (section),
- gtk_css_section_get_end_position (section));
+ end->lines,
+ end->line_bytes);
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
diff --git a/tests/testboxcss.c b/tests/testboxcss.c
index 7742f75510..2a72309724 100644
--- a/tests/testboxcss.c
+++ b/tests/testboxcss.c
@@ -49,17 +49,20 @@ show_parsing_error (GtkCssProvider *provider,
const GError *error,
GtkTextBuffer *buffer)
{
+ const GtkCssLocation *start_location, *end_location;
GtkTextIter start, end;
const char *tag_name;
+ start_location = gtk_css_section_get_start_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&start,
- gtk_css_section_get_start_line (section),
- gtk_css_section_get_start_position (section));
+ start_location->lines,
+ start_location->line_bytes);
+ end_location = gtk_css_section_get_end_location (section);
gtk_text_buffer_get_iter_at_line_index (buffer,
&end,
- gtk_css_section_get_end_line (section),
- gtk_css_section_get_end_position (section));
+ end_location->lines,
+ end_location->line_bytes);
if (error->domain == GTK_CSS_PARSER_WARNING)
tag_name = "warning";
diff --git a/testsuite/css/parser/test-css-parser.c b/testsuite/css/parser/test-css-parser.c
index 4fa1281014..6e9f3efc31 100644
--- a/testsuite/css/parser/test-css-parser.c
+++ b/testsuite/css/parser/test-css-parser.c
@@ -142,12 +142,15 @@ parsing_error_cb (GtkCssProvider *provider,
const GError *error,
GString *errors)
{
+ const GtkCssLocation *end_location;
char *basename;
+ end_location = gtk_css_section_get_end_location (section);
+
basename = g_file_get_basename (gtk_css_section_get_file (section));
g_string_append_printf (errors,
- "%s:%u: error: ",
- basename, gtk_css_section_get_end_line (section) + 1);
+ "%s:%zu: error: ",
+ basename, end_location->lines + 1);
g_free (basename);
if (error->domain == GTK_CSS_PARSER_ERROR)