mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
css: Split GtkCssLocation into its own file
And make the struct public, so we can use it in signal handlers.
This commit is contained in:
parent
d4d46e8125
commit
32e256e5ab
@ -5090,6 +5090,7 @@ GTK_CSS_PARSER_ERROR
|
||||
GtkCssParserError
|
||||
GtkCssParserWarning
|
||||
<SUBSECTION>
|
||||
GtkCssLocation
|
||||
GtkCssSection
|
||||
GtkCssSectionType
|
||||
gtk_css_section_get_end_line
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <gtk/css/gtkcssenums.h>
|
||||
#include <gtk/css/gtkcssenumtypes.h>
|
||||
#include <gtk/css/gtkcsserror.h>
|
||||
#include <gtk/css/gtkcsslocation.h>
|
||||
|
||||
#undef __GTK_CSS_H_INSIDE__
|
||||
|
||||
|
74
gtk/css/gtkcsslocation.c
Normal file
74
gtk/css/gtkcsslocation.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* GSK - The GIMP Toolkit
|
||||
* Copyright (C) 2019 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcsslocationprivate.h"
|
||||
|
||||
/**
|
||||
* GtkCssLocation:
|
||||
* @bytes: number of bytes parsed since the beginning
|
||||
* @chars: number of characters parsed since the beginning
|
||||
* @lines: number of full lines that have been parsed
|
||||
* If you want to display this as a line number, you
|
||||
* need to add 1 to this.
|
||||
* @line_bytes: Number of bytes parsed since the last line break
|
||||
* @line_chars: Number of characters parsed since the last line
|
||||
* break
|
||||
*
|
||||
* @GtkCssLocation is used to present a location in a file - or other
|
||||
* source of data parsed by the CSS engine.
|
||||
*
|
||||
* The @bytes and @line_bytes offsets are meant to be used to
|
||||
* programmatically match data. The @lines and @line_chars offsets
|
||||
* can be used for printing the location in a file.
|
||||
*
|
||||
* Note that the @lines parameter starts from 0 and is increased
|
||||
* whenever a CSS line break is encountered. (CSS defines the C character
|
||||
* sequences "\r\n", "\r", "\n" and "\f" as newlines.)
|
||||
* If your document uses different rules for line breaking, you might want
|
||||
* run into problems here.
|
||||
*/
|
||||
|
||||
void
|
||||
gtk_css_location_init (GtkCssLocation *location)
|
||||
{
|
||||
memset (location, 0, sizeof (GtkCssLocation));
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_location_advance (GtkCssLocation *location,
|
||||
gsize bytes,
|
||||
gsize chars)
|
||||
{
|
||||
location->bytes += bytes;
|
||||
location->chars += chars;
|
||||
location->line_bytes += bytes;
|
||||
location->line_chars += chars;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_location_advance_newline (GtkCssLocation *location,
|
||||
gboolean is_windows)
|
||||
{
|
||||
gtk_css_location_advance (location, is_windows ? 2 : 1, is_windows ? 2 : 1);
|
||||
|
||||
location->lines++;
|
||||
location->line_bytes = 0;
|
||||
location->line_chars = 0;
|
||||
}
|
||||
|
43
gtk/css/gtkcsslocation.h
Normal file
43
gtk/css/gtkcsslocation.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* GSK - The GIMP Toolkit
|
||||
* Copyright (C) 2011 Benjamin Otte <otte@gnome.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_CSS_LOCATION_H__
|
||||
#define __GTK_CSS_LOCATION_H__
|
||||
|
||||
#if !defined (__GTK_CSS_H_INSIDE__) && !defined (GTK_CSS_COMPILATION)
|
||||
#error "Only <gtk/css/gtkcss.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GtkCssLocation GtkCssLocation;
|
||||
|
||||
struct _GtkCssLocation
|
||||
{
|
||||
gsize bytes;
|
||||
gsize chars;
|
||||
gsize lines;
|
||||
gsize line_bytes;
|
||||
gsize line_chars;
|
||||
};
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_LOCATION_H__ */
|
39
gtk/css/gtkcsslocationprivate.h
Normal file
39
gtk/css/gtkcsslocationprivate.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright © 2019 Benjamin Otte
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GTK_CSS_LOCATION_PRIVATE_H__
|
||||
#define __GTK_CSS_LOCATION_PRIVATE_H__
|
||||
|
||||
#include "gtkcsslocation.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void gtk_css_location_init (GtkCssLocation *location);
|
||||
|
||||
void gtk_css_location_advance (GtkCssLocation *location,
|
||||
gsize bytes,
|
||||
gsize chars);
|
||||
void gtk_css_location_advance_newline (GtkCssLocation *location,
|
||||
gboolean is_windows);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_CSS_LOCATION_PRIVATE_H__ */
|
||||
|
@ -19,9 +19,9 @@
|
||||
|
||||
#include "gtkcsstokenizerprivate.h"
|
||||
|
||||
/* for error enum */
|
||||
#include "gtkcssenums.h"
|
||||
#include "gtkcsserror.h"
|
||||
#include "gtkcsslocationprivate.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
@ -37,34 +37,6 @@ struct _GtkCssTokenizer
|
||||
GtkCssLocation position;
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_css_location_init (GtkCssLocation *location)
|
||||
{
|
||||
memset (location, 0, sizeof (GtkCssLocation));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_location_advance (GtkCssLocation *location,
|
||||
gsize bytes,
|
||||
gsize chars)
|
||||
{
|
||||
location->bytes += bytes;
|
||||
location->chars += chars;
|
||||
location->line_bytes += bytes;
|
||||
location->line_chars += chars;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_location_advance_newline (GtkCssLocation *location,
|
||||
gboolean is_windows)
|
||||
{
|
||||
gtk_css_location_advance (location, is_windows ? 2 : 1, is_windows ? 2 : 1);
|
||||
|
||||
location->lines++;
|
||||
location->line_bytes = 0;
|
||||
location->line_chars = 0;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_token_clear (GtkCssToken *token)
|
||||
{
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <gtk/css/gtkcsslocation.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
@ -70,7 +72,6 @@ typedef enum {
|
||||
|
||||
typedef union _GtkCssToken GtkCssToken;
|
||||
typedef struct _GtkCssTokenizer GtkCssTokenizer;
|
||||
typedef struct _GtkCssLocation GtkCssLocation;
|
||||
|
||||
typedef struct _GtkCssStringToken GtkCssStringToken;
|
||||
typedef struct _GtkCssDelimToken GtkCssDelimToken;
|
||||
@ -106,15 +107,6 @@ union _GtkCssToken {
|
||||
GtkCssDimensionToken dimension;
|
||||
};
|
||||
|
||||
struct _GtkCssLocation
|
||||
{
|
||||
gsize bytes;
|
||||
gsize chars;
|
||||
gsize lines;
|
||||
gsize line_bytes;
|
||||
gsize line_chars;
|
||||
};
|
||||
|
||||
void gtk_css_token_clear (GtkCssToken *token);
|
||||
|
||||
gboolean gtk_css_token_is_finite (const GtkCssToken *token);
|
||||
|
@ -1,4 +1,5 @@
|
||||
gtk_css_public_sources = files([
|
||||
'gtkcsslocation.c',
|
||||
'gtkcsserror.c',
|
||||
])
|
||||
|
||||
@ -9,6 +10,7 @@ gtk_css_private_sources = files([
|
||||
gtk_css_public_headers = files([
|
||||
'gtkcssenums.h',
|
||||
'gtkcsserror.h',
|
||||
'gtkcsslocation.h',
|
||||
])
|
||||
|
||||
install_headers(gtk_css_public_headers, 'gtkcss.h', subdir: 'gtk-4.0/gtk/css')
|
||||
|
Loading…
Reference in New Issue
Block a user