[gtksourceview/wip/chergert/gsv-gtk4] wip: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4] wip: port to GTK 4
- Date: Fri, 10 Jan 2020 18:54:35 +0000 (UTC)
commit 248f1c7a2e05f1f2247b6a270a417f73323994b5
Author: Christian Hergert <chergert redhat com>
Date: Thu Jan 9 19:04:53 2020 -0800
wip: port to GTK 4
README.md | 4 +-
docs/reference/gtksourceview-docs.xml.in | 1 -
docs/reference/meson.build | 1 -
.../words/gtksourcecompletionwords.c | 3 +-
gtksourceview/gtksource.h | 2 +-
gtksourceview/gtksourcebuffer.c | 551 +------
gtksourceview/gtksourcebuffer.h | 17 +-
gtksourceview/gtksourcebufferoutputstream.c | 8 +-
gtksourceview/gtksourcecompletion.c | 85 +-
gtksourceview/gtksourcecompletion.ui | 26 +-
gtksourceview/gtksourcecompletioncontainer.c | 222 ---
gtksourceview/gtksourcecompletioninfo.c | 185 +--
gtksourceview/gtksourcecontextengine.c | 11 +-
gtksourceview/gtksourcefile-private.h | 10 +-
gtksourceview/gtksourcefile.c | 17 +-
gtksourceview/gtksourcefileloader.c | 14 +-
gtksourceview/gtksourcefilesaver.c | 23 +-
gtksourceview/gtksourcegutter-private.h | 8 +-
gtksourceview/gtksourcegutter.c | 1582 +++++++------------
gtksourceview/gtksourcegutter.h | 27 +-
gtksourceview/gtksourcegutterrenderer-private.h | 15 +-
gtksourceview/gtksourcegutterrenderer.c | 1444 ++++++------------
gtksourceview/gtksourcegutterrenderer.h | 196 +--
gtksourceview/gtksourcegutterrendererlines.c | 334 ++--
gtksourceview/gtksourcegutterrendererlines.h | 65 +
gtksourceview/gtksourcegutterrendererpixbuf.c | 210 +--
gtksourceview/gtksourcegutterrendererpixbuf.h | 55 +-
gtksourceview/gtksourcegutterrenderertext.c | 276 ++--
gtksourceview/gtksourcegutterrenderertext.h | 61 +-
gtksourceview/gtksourceinit.c | 17 +-
gtksourceview/gtksourceinit.h | 5 +-
gtksourceview/gtksourceiter.c | 50 +-
gtksourceview/gtksourceiter.h | 95 ++
...ontainer-private.h => gtksourcelines-private.h} | 17 +-
gtksourceview/gtksourcelines.c | 641 ++++++++
gtksourceview/gtksourcelines.h | 96 ++
gtksourceview/gtksourcemap.c | 388 ++---
gtksourceview/gtksourcemap.h | 29 +-
gtksourceview/gtksourcemark.c | 47 +-
gtksourceview/gtksourcemark.h | 43 +-
gtksourceview/gtksourcemarkattributes.c | 107 +-
gtksourceview/gtksourcemarkattributes.h | 83 +-
gtksourceview/gtksourcemarkssequence-private.h | 72 +-
gtksourceview/gtksourcemarkssequence.c | 148 +-
gtksourceview/gtksourcemarshalers.list | 7 +-
gtksourceview/gtksourcepixbufhelper-private.h | 40 +-
gtksourceview/gtksourcepixbufhelper.c | 96 +-
gtksourceview/gtksourcespacedrawer-private.h | 8 +-
gtksourceview/gtksourcespacedrawer.c | 390 +++--
gtksourceview/gtksourcespacedrawer.h | 87 +-
gtksourceview/gtksourcestyle-private.h | 18 +-
gtksourceview/gtksourcestyle.c | 42 +-
gtksourceview/gtksourcestyle.h | 18 +-
gtksourceview/gtksourcestylescheme-private.h | 3 +
gtksourceview/gtksourcestylescheme.c | 332 ++--
gtksourceview/gtksourcestylescheme.h | 45 +-
gtksourceview/gtksourcestyleschemechooser.c | 4 +-
gtksourceview/gtksourcestyleschemechooser.h | 28 +-
gtksourceview/gtksourcestyleschemechooserbutton.c | 32 +-
gtksourceview/gtksourcestyleschemechooserbutton.h | 22 +-
gtksourceview/gtksourcestyleschemechooserwidget.c | 49 +-
gtksourceview/gtksourcestyleschemechooserwidget.h | 25 +-
.../gtksourcestyleschememanager-private.h | 1 +
gtksourceview/gtksourcestyleschememanager.c | 128 +-
gtksourceview/gtksourcestyleschememanager.h | 63 +-
gtksourceview/gtksourcetag.c | 22 +-
gtksourceview/gtksourcetag.h | 10 +-
gtksourceview/gtksourcetypes-private.h | 22 +-
gtksourceview/gtksourcetypes.h | 64 +-
gtksourceview/gtksourceundomanager.c | 289 ----
gtksourceview/gtksourceundomanager.h | 88 --
gtksourceview/gtksourceundomanagerdefault.c | 1590 --------------------
gtksourceview/gtksourceundomanagerdefault.h | 59 -
gtksourceview/gtksourceutils-private.h | 24 +-
gtksourceview/gtksourceutils.c | 4 +-
gtksourceview/gtksourceutils.h | 5 +-
gtksourceview/gtksourceversion.c | 4 +-
gtksourceview/gtksourceview.c | 1585 ++++++++-----------
gtksourceview/gtksourceview.h | 200 ++-
gtksourceview/meson.build | 29 +-
gtksourceview/quarkset-inline.h | 185 +++
meson.build | 4 +-
po/POTFILES.in | 1 -
tests/meson.build | 1 -
tests/test-completion.c | 20 +-
tests/test-completion.ui | 313 ++--
tests/test-search-performances.c | 2 +-
tests/test-search.c | 8 +-
tests/test-search.ui | 285 ++--
tests/test-space-drawing.c | 4 +-
tests/test-undo-manager-performances.c | 103 --
tests/test-widget.c | 29 +-
tests/test-widget.ui | 468 ++----
testsuite/meson.build | 1 -
testsuite/test-undo-manager.c | 918 -----------
95 files changed, 5392 insertions(+), 9674 deletions(-)
---
diff --git a/README.md b/README.md
index e28a8c7c..783e752c 100644
--- a/README.md
+++ b/README.md
@@ -18,8 +18,8 @@ The official web site is https://wiki.gnome.org/Projects/GtkSourceView.
Dependencies
------------
-* GLib >= 2.48
-* GTK+ >= 3.22
+* GLib >= 2.62
+* GTK+ >= 3.96
* libxml2 >= 2.6
* freebidi >= 0.19.7
diff --git a/docs/reference/gtksourceview-docs.xml.in b/docs/reference/gtksourceview-docs.xml.in
index c2f3ec7e..8669e238 100644
--- a/docs/reference/gtksourceview-docs.xml.in
+++ b/docs/reference/gtksourceview-docs.xml.in
@@ -90,7 +90,6 @@
<xi:include href="xml/region.xml"/>
<xi:include href="xml/spacedrawer.xml"/>
<xi:include href="xml/tag.xml"/>
- <xi:include href="xml/undomanager.xml"/>
<xi:include href="xml/utils.xml"/>
<xi:include href="xml/version.xml"/>
</chapter>
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index f3a4e8f8..f1fa7427 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -39,7 +39,6 @@ reference_private_h = [
'gtksourcestylescheme-private.h',
'gtksourcestyleschememanager-private.h',
'gtksourcetypes-private.h',
- 'gtksourceundomanagerdefault.h',
'gtksourceutils-private.h',
]
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
index 32b04e46..2cf8dc4d 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
@@ -268,8 +268,7 @@ gtk_source_completion_words_populate (GtkSourceCompletionProvider *provider,
if (add_in_idle (words))
{
gtk_source_completion_words_library_lock (priv->library);
- priv->idle_id = gdk_threads_add_idle ((GSourceFunc)add_in_idle,
- words);
+ priv->idle_id = g_idle_add ((GSourceFunc)add_in_idle, words);
}
}
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index 2f84a3b4..fbbb81c7 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -39,6 +39,7 @@
#include "gtksourceinit.h"
#include "gtksourcelanguage.h"
#include "gtksourcelanguagemanager.h"
+#include "gtksourcelines.h"
#include "gtksourcemap.h"
#include "gtksourcemark.h"
#include "gtksourcemarkattributes.h"
@@ -54,7 +55,6 @@
#include "gtksourcestyleschemechooserwidget.h"
#include "gtksourcestyleschememanager.h"
#include "gtksourcetag.h"
-#include "gtksourceundomanager.h"
#include "gtksourceutils.h"
#include "gtksourceversion.h"
#include "gtksourceview.h"
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index cdec9a0d..6105abe6 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -34,13 +34,13 @@
#include "gtksourcelanguage.h"
#include "gtksourcelanguage-private.h"
#include "gtksource-marshal.h"
-#include "gtksourceundomanager.h"
-#include "gtksourceundomanagerdefault.h"
#include "gtksourcestyle.h"
+#include "gtksourcestylescheme.h"
#include "gtksourcestylescheme-private.h"
#include "gtksourcestyleschememanager.h"
#include "gtksourcemark.h"
#include "gtksourcemarkssequence-private.h"
+#include "gtksourcesearchcontext.h"
#include "gtksourcesearchcontext-private.h"
#include "gtksourcetag.h"
#include "gtksource-enumtypes.h"
@@ -53,8 +53,7 @@
*
* A #GtkSourceBuffer object is the model for #GtkSourceView widgets.
* It extends the #GtkTextBuffer class by adding features useful to display
- * and edit source code such as syntax highlighting and bracket matching. It
- * also implements support for the undo/redo.
+ * and edit source code such as syntax highlighting and bracket matching.
*
* To create a #GtkSourceBuffer use gtk_source_buffer_new() or
* gtk_source_buffer_new_with_language(). The second form is just a convenience
@@ -65,34 +64,6 @@
* The highlighting is enabled by default, but you can disable it with
* gtk_source_buffer_set_highlight_syntax().
*
- * # Undo/Redo
- *
- * A custom #GtkSourceUndoManager can be implemented and set with
- * gtk_source_buffer_set_undo_manager(). However the default implementation
- * should be suitable for most uses, so you can use the API provided by
- * #GtkSourceBuffer instead of using #GtkSourceUndoManager. By default, actions
- * that can be undone or redone are defined as groups of operations between a
- * call to gtk_text_buffer_begin_user_action() and
- * gtk_text_buffer_end_user_action(). In general, this happens whenever the user
- * presses any key which modifies the buffer. But the default undo manager will
- * try to merge similar consecutive actions into one undo/redo level. The
- * merging is done word by word, so after writing a new sentence (character by
- * character), each undo will remove the previous word.
- *
- * The default undo manager remembers the "modified" state of the buffer, and
- * restores it when an action is undone or redone. It can be useful in a text
- * editor to know whether the file is saved. See gtk_text_buffer_get_modified()
- * and gtk_text_buffer_set_modified().
- *
- * The default undo manager also restores the selected text (or cursor
- * position), if the selection was related to the action. For example if the
- * user selects some text and deletes it, an undo will restore the selection. On
- * the other hand, if some text is selected but a deletion occurs elsewhere (the
- * deletion was done programmatically), an undo will not restore the selection,
- * it will only moves the cursor (the cursor is moved so that the user sees the
- * undo's effect). Warning: the selection restoring behavior might change in the
- * future.
- *
* # Context Classes # {#context-classes}
*
* It is possible to retrieve some information from the syntax highlighting
@@ -161,12 +132,13 @@
#define PROFILE(x)
#endif
-#define UPDATE_BRACKET_DELAY 50
-#define BRACKET_MATCHING_CHARS_LIMIT 10000
-#define CONTEXT_CLASSES_PREFIX "gtksourceview:context-classes:"
+#define UPDATE_BRACKET_DELAY 50
+#define BRACKET_MATCHING_CHARS_LIMIT 10000
+#define CONTEXT_CLASSES_PREFIX "gtksourceview:context-classes:"
enum
{
+ CURSOR_MOVED,
HIGHLIGHT_UPDATED,
SOURCE_MARK_UPDATED,
UNDO,
@@ -178,15 +150,11 @@ enum
enum
{
PROP_0,
- PROP_CAN_UNDO,
- PROP_CAN_REDO,
- PROP_HIGHLIGHT_SYNTAX,
PROP_HIGHLIGHT_MATCHING_BRACKETS,
- PROP_MAX_UNDO_LEVELS,
+ PROP_HIGHLIGHT_SYNTAX,
+ PROP_IMPLICIT_TRAILING_NEWLINE,
PROP_LANGUAGE,
PROP_STYLE_SCHEME,
- PROP_UNDO_MANAGER,
- PROP_IMPLICIT_TRAILING_NEWLINE,
N_PROPERTIES
};
@@ -204,9 +172,6 @@ typedef struct
GtkSourceLanguage *language;
GtkSourceEngine *highlight_engine;
- GtkSourceUndoManager *undo_manager;
- gint max_undo_levels;
-
GtkTextMark *tmp_insert_mark;
GtkTextMark *tmp_selection_bound_mark;
@@ -235,17 +200,13 @@ static void gtk_source_buffer_get_property (GObject
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void gtk_source_buffer_can_undo_handler (GtkSourceUndoManager *manager,
- GtkSourceBuffer *buffer);
-static void gtk_source_buffer_can_redo_handler (GtkSourceUndoManager *manager,
- GtkSourceBuffer *buffer);
static void gtk_source_buffer_real_insert_text (GtkTextBuffer *buffer,
GtkTextIter *iter,
const gchar *text,
gint len);
-static void gtk_source_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
+static void gtk_source_buffer_real_insert_texture (GtkTextBuffer *buffer,
GtkTextIter *pos,
- GdkPixbuf *pixbuf);
+ GdkTexture *texture);
static void gtk_source_buffer_real_insert_child_anchor
(GtkTextBuffer *buffer,
GtkTextIter *pos,
@@ -260,9 +221,6 @@ static void gtk_source_buffer_real_mark_set (GtkTextBuffer
*buffer,
static void gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
GtkTextMark *mark);
-static void gtk_source_buffer_real_undo (GtkSourceBuffer *buffer);
-static void gtk_source_buffer_real_redo (GtkSourceBuffer *buffer);
-
static void gtk_source_buffer_real_highlight_updated
(GtkSourceBuffer *buffer,
GtkTextIter *start,
@@ -316,15 +274,8 @@ static void
gtk_source_buffer_constructed (GObject *object)
{
GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
GtkTextTagTable *table;
- if (priv->undo_manager == NULL)
- {
- /* This will install the default undo manager */
- gtk_source_buffer_set_undo_manager (buffer, NULL);
- }
-
G_OBJECT_CLASS (gtk_source_buffer_parent_class)->constructed (object);
table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer));
@@ -354,14 +305,11 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
text_buffer_class->delete_range = gtk_source_buffer_real_delete_range;
text_buffer_class->insert_text = gtk_source_buffer_real_insert_text;
- text_buffer_class->insert_pixbuf = gtk_source_buffer_real_insert_pixbuf;
+ text_buffer_class->insert_texture = gtk_source_buffer_real_insert_texture;
text_buffer_class->insert_child_anchor = gtk_source_buffer_real_insert_child_anchor;
text_buffer_class->mark_set = gtk_source_buffer_real_mark_set;
text_buffer_class->mark_deleted = gtk_source_buffer_real_mark_deleted;
- klass->undo = gtk_source_buffer_real_undo;
- klass->redo = gtk_source_buffer_real_redo;
-
/**
* GtkSourceBuffer:highlight-syntax:
*
@@ -388,22 +336,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
- /**
- * GtkSourceBuffer:max-undo-levels:
- *
- * Number of undo levels for the buffer. -1 means no limit. This property
- * will only affect the default undo manager.
- */
- buffer_properties[PROP_MAX_UNDO_LEVELS] =
- g_param_spec_int ("max-undo-levels",
- "Maximum Undo Levels",
- "Number of undo levels for the buffer",
- -1,
- G_MAXINT,
- -1,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS);
-
buffer_properties[PROP_LANGUAGE] =
g_param_spec_object ("language",
"Language",
@@ -412,22 +344,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
- buffer_properties[PROP_CAN_UNDO] =
- g_param_spec_boolean ("can-undo",
- "Can undo",
- "Whether Undo operation is possible",
- FALSE,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS);
-
- buffer_properties[PROP_CAN_REDO] =
- g_param_spec_boolean ("can-redo",
- "Can redo",
- "Whether Redo operation is possible",
- FALSE,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS);
-
/**
* GtkSourceBuffer:style-scheme:
*
@@ -443,15 +359,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
- buffer_properties[PROP_UNDO_MANAGER] =
- g_param_spec_object ("undo-manager",
- "Undo manager",
- "The buffer undo manager",
- GTK_SOURCE_TYPE_UNDO_MANAGER,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS);
-
/**
* GtkSourceBuffer:implicit-trailing-newline:
*
@@ -471,6 +378,21 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
g_object_class_install_properties (object_class, N_PROPERTIES, buffer_properties);
+ /**
+ * GtkSourceBuffer::cursor-moved:
+ * @buffer: a #GtkSourceBuffer
+ *
+ * The "cursor-moved" signal is emitted when then insertion mark has moved.
+ *
+ * Since: 5.0
+ */
+ buffer_signals[CURSOR_MOVED] =
+ g_signal_new_class_handler ("cursor-moved",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ NULL, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+
/**
* GtkSourceBuffer::highlight-updated:
* @buffer: the buffer that received the signal
@@ -517,43 +439,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
G_TYPE_FROM_CLASS (klass),
g_cclosure_marshal_VOID__OBJECTv);
- /**
- * GtkSourceBuffer::undo:
- * @buffer: the buffer that received the signal
- *
- * The ::undo signal is emitted to undo the last user action which
- * modified the buffer.
- */
- buffer_signals[UNDO] =
- g_signal_new ("undo",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkSourceBufferClass, undo),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- g_signal_set_va_marshaller (buffer_signals[UNDO],
- G_TYPE_FROM_CLASS (klass),
- g_cclosure_marshal_VOID__VOIDv);
-
- /**
- * GtkSourceBuffer::redo:
- * @buffer: the buffer that received the signal
- *
- * The ::redo signal is emitted to redo the last undo operation.
- */
- buffer_signals[REDO] =
- g_signal_new ("redo",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkSourceBufferClass, redo),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- g_signal_set_va_marshaller (buffer_signals[REDO],
- G_TYPE_FROM_CLASS (klass),
- g_cclosure_marshal_VOID__VOIDv);
-
/**
* GtkSourceBuffer::bracket-matched:
* @buffer: a #GtkSourceBuffer.
@@ -586,51 +471,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
_gtk_source_marshal_VOID__BOXED_ENUMv);
}
-static void
-set_undo_manager (GtkSourceBuffer *buffer,
- GtkSourceUndoManager *manager)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- if (manager == priv->undo_manager)
- {
- return;
- }
-
- if (priv->undo_manager != NULL)
- {
- g_signal_handlers_disconnect_by_func (priv->undo_manager,
- G_CALLBACK (gtk_source_buffer_can_undo_handler),
- buffer);
-
- g_signal_handlers_disconnect_by_func (priv->undo_manager,
- G_CALLBACK (gtk_source_buffer_can_redo_handler),
- buffer);
-
- g_object_unref (priv->undo_manager);
- priv->undo_manager = NULL;
- }
-
- if (manager != NULL)
- {
- priv->undo_manager = g_object_ref (manager);
-
- g_signal_connect (priv->undo_manager,
- "can-undo-changed",
- G_CALLBACK (gtk_source_buffer_can_undo_handler),
- buffer);
-
- g_signal_connect (priv->undo_manager,
- "can-redo-changed",
- G_CALLBACK (gtk_source_buffer_can_redo_handler),
- buffer);
-
- /* Notify possible changes in the can-undo/redo state */
- g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_UNDO]);
- g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_REDO]);
- }
-}
-
static void
search_context_weak_notify_cb (GtkSourceBuffer *buffer,
GObject *search_context)
@@ -648,7 +488,6 @@ gtk_source_buffer_init (GtkSourceBuffer *buffer)
priv->highlight_syntax = TRUE;
priv->highlight_brackets = TRUE;
priv->bracket_match_state = GTK_SOURCE_BRACKET_MATCH_NONE;
- priv->max_undo_levels = -1;
priv->source_marks = g_hash_table_new_full (g_str_hash,
g_str_equal,
@@ -678,11 +517,6 @@ gtk_source_buffer_dispose (GObject *object)
priv->bracket_highlighting_timeout_id = 0;
}
- if (priv->undo_manager != NULL)
- {
- set_undo_manager (buffer, NULL);
- }
-
if (priv->highlight_engine != NULL)
{
_gtk_source_engine_attach_buffer (priv->highlight_engine, NULL);
@@ -733,10 +567,6 @@ gtk_source_buffer_set_property (GObject *object,
gtk_source_buffer_set_highlight_matching_brackets (buffer, g_value_get_boolean
(value));
break;
- case PROP_MAX_UNDO_LEVELS:
- gtk_source_buffer_set_max_undo_levels (buffer, g_value_get_int (value));
- break;
-
case PROP_LANGUAGE:
gtk_source_buffer_set_language (buffer, g_value_get_object (value));
break;
@@ -745,10 +575,6 @@ gtk_source_buffer_set_property (GObject *object,
gtk_source_buffer_set_style_scheme (buffer, g_value_get_object (value));
break;
- case PROP_UNDO_MANAGER:
- gtk_source_buffer_set_undo_manager (buffer, g_value_get_object (value));
- break;
-
case PROP_IMPLICIT_TRAILING_NEWLINE:
gtk_source_buffer_set_implicit_trailing_newline (buffer, g_value_get_boolean (value));
break;
@@ -778,10 +604,6 @@ gtk_source_buffer_get_property (GObject *object,
g_value_set_boolean (value, priv->highlight_brackets);
break;
- case PROP_MAX_UNDO_LEVELS:
- g_value_set_int (value, priv->max_undo_levels);
- break;
-
case PROP_LANGUAGE:
g_value_set_object (value, priv->language);
break;
@@ -790,18 +612,6 @@ gtk_source_buffer_get_property (GObject *object,
g_value_set_object (value, priv->style_scheme);
break;
- case PROP_CAN_UNDO:
- g_value_set_boolean (value, gtk_source_buffer_can_undo (buffer));
- break;
-
- case PROP_CAN_REDO:
- g_value_set_boolean (value, gtk_source_buffer_can_redo (buffer));
- break;
-
- case PROP_UNDO_MANAGER:
- g_value_set_object (value, priv->undo_manager);
- break;
-
case PROP_IMPLICIT_TRAILING_NEWLINE:
g_value_set_boolean (value, priv->implicit_trailing_newline);
break;
@@ -823,8 +633,6 @@ gtk_source_buffer_get_property (GObject *object,
GtkSourceBuffer *
gtk_source_buffer_new (GtkTextTagTable *table)
{
- g_return_val_if_fail (table == NULL || GTK_IS_TEXT_TAG_TABLE (table), NULL);
-
return g_object_new (GTK_SOURCE_TYPE_BUFFER,
"tag-table", table,
NULL);
@@ -852,24 +660,6 @@ gtk_source_buffer_new_with_language (GtkSourceLanguage *language)
NULL);
}
-static void
-gtk_source_buffer_can_undo_handler (GtkSourceUndoManager *manager,
- GtkSourceBuffer *buffer)
-{
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_UNDO]);
-}
-
-static void
-gtk_source_buffer_can_redo_handler (GtkSourceUndoManager *manager,
- GtkSourceBuffer *buffer)
-{
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_REDO]);
-}
-
static void
update_bracket_match_style (GtkSourceBuffer *buffer)
{
@@ -1187,11 +977,11 @@ queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
* ::update() or ::after-paint() to synchronize this.
*/
priv->bracket_highlighting_timeout_id =
- gdk_threads_add_timeout_full (G_PRIORITY_LOW,
- UPDATE_BRACKET_DELAY,
- bracket_highlighting_timeout_cb,
- buffer,
- NULL);
+ g_timeout_add_full (G_PRIORITY_LOW,
+ UPDATE_BRACKET_DELAY,
+ bracket_highlighting_timeout_cb,
+ buffer,
+ NULL);
}
/* Although this function is not really useful
@@ -1202,6 +992,8 @@ static void
cursor_moved (GtkSourceBuffer *buffer)
{
queue_bracket_highlighting_update (buffer);
+
+ g_signal_emit (buffer, buffer_signals[CURSOR_MOVED], 0);
}
static void
@@ -1257,14 +1049,14 @@ gtk_source_buffer_real_insert_text (GtkTextBuffer *buffer,
gtk_text_iter_get_offset (iter));
}
-/* insert_pixbuf and insert_child_anchor do nothing except notifying
+/* insert_texture and insert_child_anchor do nothing except notifying
* the highlighting engine about the change, because engine's idea
* of buffer char count must be correct at all times.
*/
static void
-gtk_source_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
- GtkTextIter *iter,
- GdkPixbuf *pixbuf)
+gtk_source_buffer_real_insert_texture (GtkTextBuffer *buffer,
+ GtkTextIter *iter,
+ GdkTexture *texture)
{
gint start_offset;
@@ -1279,7 +1071,7 @@ gtk_source_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
* default signal handler revalidates it to point to the end of the
* inserted text.
*/
- GTK_TEXT_BUFFER_CLASS (gtk_source_buffer_parent_class)->insert_pixbuf (buffer, iter, pixbuf);
+ GTK_TEXT_BUFFER_CLASS (gtk_source_buffer_parent_class)->insert_texture (buffer, iter, texture);
gtk_source_buffer_content_inserted (buffer,
start_offset,
@@ -1532,195 +1324,6 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer *buffer,
return result_right;
}
-/**
- * gtk_source_buffer_can_undo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines whether a source buffer can undo the last action.
- *
- * Returns: %TRUE if it's possible to undo the last action.
- */
-gboolean
-gtk_source_buffer_can_undo (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_undo_manager_can_undo (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_can_redo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines whether a source buffer can redo the last action
- * (i.e. if the last operation was an undo).
- *
- * Returns: %TRUE if a redo is possible.
- */
-gboolean
-gtk_source_buffer_can_redo (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- return gtk_source_undo_manager_can_redo (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_undo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Undoes the last user action which modified the buffer. Use
- * gtk_source_buffer_can_undo() to check whether a call to this
- * function will have any effect.
- *
- * This function emits the #GtkSourceBuffer::undo signal.
- */
-void
-gtk_source_buffer_undo (GtkSourceBuffer *buffer)
-{
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- g_signal_emit (buffer, buffer_signals[UNDO], 0);
-}
-
-/**
- * gtk_source_buffer_redo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Redoes the last undo operation. Use gtk_source_buffer_can_redo()
- * to check whether a call to this function will have any effect.
- *
- * This function emits the #GtkSourceBuffer::redo signal.
- */
-void
-gtk_source_buffer_redo (GtkSourceBuffer *buffer)
-{
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- g_signal_emit (buffer, buffer_signals[REDO], 0);
-}
-
-/**
- * gtk_source_buffer_get_max_undo_levels:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines the number of undo levels the buffer will track for buffer edits.
- *
- * Returns: the maximum number of possible undo levels or -1 if no limit is set.
- */
-gint
-gtk_source_buffer_get_max_undo_levels (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), 0);
-
- return priv->max_undo_levels;
-}
-
-/**
- * gtk_source_buffer_set_max_undo_levels:
- * @buffer: a #GtkSourceBuffer.
- * @max_undo_levels: the desired maximum number of undo levels.
- *
- * Sets the number of undo levels for user actions the buffer will
- * track. If the number of user actions exceeds the limit set by this
- * function, older actions will be discarded.
- *
- * If @max_undo_levels is -1, the undo/redo is unlimited.
- *
- * If @max_undo_levels is 0, the undo/redo is disabled.
- */
-void
-gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer *buffer,
- gint max_undo_levels)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- if (priv->max_undo_levels == max_undo_levels)
- {
- return;
- }
-
- priv->max_undo_levels = max_undo_levels;
-
- if (GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
- {
- gtk_source_undo_manager_default_set_max_undo_levels (GTK_SOURCE_UNDO_MANAGER_DEFAULT
(priv->undo_manager),
- max_undo_levels);
- }
-
- g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_MAX_UNDO_LEVELS]);
-}
-
-gboolean
-_gtk_source_buffer_is_undo_redo_enabled (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
- if (priv->undo_manager == NULL)
- {
- return FALSE;
- }
-
- /* A custom UndoManager is not forced to follow max_undo_levels. */
- if (!GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
- {
- return TRUE;
- }
-
- return priv->max_undo_levels != 0;
-}
-
-/**
- * gtk_source_buffer_begin_not_undoable_action:
- * @buffer: a #GtkSourceBuffer.
- *
- * Marks the beginning of a not undoable action on the buffer,
- * disabling the undo manager. Typically you would call this function
- * before initially setting the contents of the buffer (e.g. when
- * loading a file in a text editor).
- *
- * You may nest gtk_source_buffer_begin_not_undoable_action() /
- * gtk_source_buffer_end_not_undoable_action() blocks.
- */
-void
-gtk_source_buffer_begin_not_undoable_action (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- gtk_source_undo_manager_begin_not_undoable_action (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_end_not_undoable_action:
- * @buffer: a #GtkSourceBuffer.
- *
- * Marks the end of a not undoable action on the buffer. When the
- * last not undoable block is closed through the call to this
- * function, the list of undo actions is cleared and the undo manager
- * is re-enabled.
- */
-void
-gtk_source_buffer_end_not_undoable_action (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
- gtk_source_undo_manager_end_not_undoable_action (priv->undo_manager);
-}
-
/**
* gtk_source_buffer_get_highlight_matching_brackets:
* @buffer: a #GtkSourceBuffer.
@@ -2111,26 +1714,6 @@ gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
}
}
-static void
-gtk_source_buffer_real_undo (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_if_fail (gtk_source_undo_manager_can_undo (priv->undo_manager));
-
- gtk_source_undo_manager_undo (priv->undo_manager);
-}
-
-static void
-gtk_source_buffer_real_redo (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_if_fail (gtk_source_undo_manager_can_redo (priv->undo_manager));
-
- gtk_source_undo_manager_redo (priv->undo_manager);
-}
-
/**
* gtk_source_buffer_create_source_mark:
* @buffer: a #GtkSourceBuffer.
@@ -3192,62 +2775,6 @@ gtk_source_buffer_sort_lines (GtkSourceBuffer *buffer,
g_free (lines);
}
-/**
- * gtk_source_buffer_set_undo_manager:
- * @buffer: a #GtkSourceBuffer.
- * @manager: (nullable): A #GtkSourceUndoManager or %NULL.
- *
- * Set the buffer undo manager. If @manager is %NULL the default undo manager
- * will be set.
- */
-void
-gtk_source_buffer_set_undo_manager (GtkSourceBuffer *buffer,
- GtkSourceUndoManager *manager)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
- g_return_if_fail (manager == NULL || GTK_SOURCE_IS_UNDO_MANAGER (manager));
-
- if (manager == NULL)
- {
- manager = g_object_new (GTK_SOURCE_TYPE_UNDO_MANAGER_DEFAULT,
- "buffer", buffer,
- "max-undo-levels", priv->max_undo_levels,
- NULL);
- }
- else
- {
- g_object_ref (manager);
- }
-
- set_undo_manager (buffer, manager);
- g_object_unref (manager);
-
- g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_UNDO_MANAGER]);
-}
-
-/**
- * gtk_source_buffer_get_undo_manager:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns the #GtkSourceUndoManager associated with the buffer,
- * see gtk_source_buffer_set_undo_manager(). The returned object should not be
- * unreferenced by the user.
- *
- * Returns: (nullable) (transfer none): the #GtkSourceUndoManager associated
- * with the buffer, or %NULL.
- */
-GtkSourceUndoManager *
-gtk_source_buffer_get_undo_manager (GtkSourceBuffer *buffer)
-{
- GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
- return priv->undo_manager;
-}
-
void
_gtk_source_buffer_add_search_context (GtkSourceBuffer *buffer,
GtkSourceSearchContext *search_context)
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 382955f6..872c7f79 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -94,12 +94,9 @@ struct _GtkSourceBufferClass
GtkTextBufferClass parent_class;
/* Signals */
- void (*undo) (GtkSourceBuffer *buffer);
- void (*redo) (GtkSourceBuffer *buffer);
-
void (*bracket_matched) (GtkSourceBuffer *buffer,
- GtkTextIter *iter,
- GtkSourceBracketMatchType state);
+ GtkTextIter *iter,
+ GtkSourceBracketMatchType state);
/*< private >*/
gpointer _reserved[20];
@@ -120,11 +117,6 @@ GTK_SOURCE_AVAILABLE_IN_ALL
void gtk_source_buffer_set_highlight_matching_brackets (GtkSourceBuffer
*buffer,
gboolean
highlight);
GTK_SOURCE_AVAILABLE_IN_ALL
-gint gtk_source_buffer_get_max_undo_levels (GtkSourceBuffer
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer
*buffer,
- gint
max_undo_levels);
-GTK_SOURCE_AVAILABLE_IN_ALL
GtkSourceLanguage *gtk_source_buffer_get_language (GtkSourceBuffer
*buffer);
GTK_SOURCE_AVAILABLE_IN_ALL
void gtk_source_buffer_set_language (GtkSourceBuffer
*buffer,
@@ -206,11 +198,6 @@ void gtk_source_buffer_sort_lines (
GtkTextIter *end,
GtkSourceSortFlags
flags,
gint
column);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceUndoManager *gtk_source_buffer_get_undo_manager (GtkSourceBuffer
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_buffer_set_undo_manager (GtkSourceBuffer
*buffer,
- GtkSourceUndoManager
*manager);
GTK_SOURCE_AVAILABLE_IN_3_14
void gtk_source_buffer_set_implicit_trailing_newline (GtkSourceBuffer
*buffer,
gboolean
implicit_trailing_newline);
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index ab41c2b5..55cac2de 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -192,12 +192,12 @@ gtk_source_buffer_output_stream_constructed (GObject *object)
return;
}
- gtk_source_buffer_begin_not_undoable_action (stream->source_buffer);
+ gtk_text_buffer_begin_irreversible_action (GTK_TEXT_BUFFER (stream->source_buffer));
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->source_buffer), "", 0);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->source_buffer), FALSE);
- gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
+ gtk_text_buffer_end_irreversible_action (GTK_TEXT_BUFFER (stream->source_buffer));
G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->constructed (object);
}
@@ -765,7 +765,7 @@ end_append_text_to_document (GtkSourceBufferOutputStream *stream)
FALSE);
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (stream->source_buffer));
- gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
+ gtk_text_buffer_end_irreversible_action (GTK_TEXT_BUFFER (stream->source_buffer));
}
static gboolean
@@ -947,7 +947,7 @@ gtk_source_buffer_output_stream_write (GOutputStream *stream,
* as only one action, for the features that rely on the user
* action.
*/
- gtk_source_buffer_begin_not_undoable_action (ostream->source_buffer);
+ gtk_text_buffer_begin_irreversible_action (GTK_TEXT_BUFFER (ostream->source_buffer));
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (ostream->source_buffer));
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->source_buffer),
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 3df3c6ea..a13e8602 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -108,7 +108,6 @@
#include "gtksourcecompletioninfo-private.h"
#include "gtksourcecompletionproposal.h"
#include "gtksourcecompletionprovider.h"
-#include "gtksourcecompletioncontainer-private.h"
#include "gtksourcecompletioncontext-private.h"
#include "gtksourcebuffer.h"
#include "gtksource-marshal.h"
@@ -634,8 +633,8 @@ gtk_source_completion_hide_default (GtkSourceCompletion *completion)
static void
gtk_source_completion_proposals_size_allocate (GtkSourceCompletion *completion,
- GtkAllocation *allocation,
- GtkWidget *widget)
+ GtkAllocation *allocation,
+ GtkWidget *widget)
{
GtkTreeViewColumn *column;
gint cell_offset = 0;
@@ -649,10 +648,15 @@ gtk_source_completion_proposals_size_allocate (GtkSourceCompletion *completion,
return;
}
+#if 0
gtk_widget_style_get (GTK_WIDGET (completion->tree_view_proposals),
"focus-padding", &focus_padding,
"horizontal-separator", &horizontal_separator,
NULL);
+#else
+ focus_padding = 0;
+ horizontal_separator = 0;
+#endif
column = gtk_tree_view_get_column (completion->tree_view_proposals, 1);
column_offset = gtk_tree_view_column_get_x_offset (column);
@@ -744,9 +748,10 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
static void
update_info_position (GtkSourceCompletion *completion)
{
+#if 0
GdkDisplay *display;
GdkMonitor *monitor;
- GdkWindow *window;
+ GdkSurface *window;
GdkRectangle geom;
gint x, y;
gint width, height;
@@ -772,6 +777,7 @@ update_info_position (GtkSourceCompletion *completion)
}
gtk_window_move (GTK_WINDOW (completion->info_window), x, y);
+#endif
}
static GtkSourceCompletionProvider *
@@ -1265,6 +1271,7 @@ selection_changed_cb (GtkTreeSelection *selection,
}
}
+#if 0
static gboolean
gtk_source_completion_configure_event (GtkWidget *widget,
GdkEventConfigure *event,
@@ -1273,6 +1280,7 @@ gtk_source_completion_configure_event (GtkWidget *widget,
update_info_position (completion);
return FALSE;
}
+#endif
static gboolean
hide_completion_cb (GtkSourceCompletion *completion)
@@ -1283,14 +1291,19 @@ hide_completion_cb (GtkSourceCompletion *completion)
static gboolean
view_key_press_event_cb (GtkSourceView *view,
- GdkEventKey *event,
- GtkSourceCompletion *completion)
+ guint keyval,
+ guint keycode,
+ GdkModifierType state,
+ GtkSourceCompletion *completion)
{
static gboolean mnemonic_keyval_set = FALSE;
static guint mnemonic_keyval = GDK_KEY_VoidSymbol;
GdkModifierType mod;
GtkBindingSet *binding_set;
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+ g_assert (GTK_SOURCE_IS_COMPLETION (completion));
+
if (!gtk_widget_get_visible (GTK_WIDGET (completion->main_window)))
{
return FALSE;
@@ -1308,11 +1321,11 @@ view_key_press_event_cb (GtkSourceView *view,
g_object_unref (label);
}
- mod = gtk_accelerator_get_default_mod_mask () & event->state;
+ mod = gtk_accelerator_get_default_mod_mask () & state;
/* Handle info button mnemonic */
if ((mod & GDK_MOD1_MASK) != 0 &&
- event->keyval == mnemonic_keyval &&
+ keyval == mnemonic_keyval &&
gtk_widget_get_sensitive (GTK_WIDGET (completion->info_button)))
{
gtk_toggle_button_set_active (completion->info_button,
@@ -1321,9 +1334,10 @@ view_key_press_event_cb (GtkSourceView *view,
}
if ((mod & GDK_MOD1_MASK) != 0 &&
- GDK_KEY_0 <= event->keyval && event->keyval <= GDK_KEY_9)
+ GDK_KEY_0 <= keyval &&
+ keyval <= GDK_KEY_9)
{
- if (activate_by_accelerator (completion, event->keyval - GDK_KEY_0))
+ if (activate_by_accelerator (completion, keyval - GDK_KEY_0))
{
return TRUE;
}
@@ -1331,10 +1345,7 @@ view_key_press_event_cb (GtkSourceView *view,
binding_set = gtk_binding_set_by_class (G_OBJECT_GET_CLASS (completion));
- if (gtk_binding_set_activate (binding_set,
- event->keyval,
- event->state,
- G_OBJECT (completion)))
+ if (gtk_binding_set_activate (binding_set, keyval, state, G_OBJECT (completion)))
{
return TRUE;
}
@@ -1587,7 +1598,6 @@ style_context_changed (GtkStyleContext *style_context,
gtk_style_context_set_state (style_context, GTK_STATE_FLAG_NORMAL);
gtk_style_context_get (style_context,
- gtk_style_context_get_state (style_context),
GTK_STYLE_PROPERTY_FONT, &font_desc,
NULL);
@@ -1804,26 +1814,35 @@ static void
connect_view (GtkSourceCompletion *completion,
GtkSourceView *view)
{
+ GtkEventController *key;
+ GtkGesture *click;
+
g_assert (completion->view == NULL);
completion->view = view;
+ key = gtk_event_controller_key_new ();
+ gtk_widget_add_controller (GTK_WIDGET (view), key);
+
+ click = gtk_gesture_click_new ();
+ gtk_widget_add_controller (GTK_WIDGET (view), GTK_EVENT_CONTROLLER (click));
+
g_object_add_weak_pointer (G_OBJECT (view),
(gpointer *)&completion->view);
- g_signal_connect_object (completion->view,
- "focus-out-event",
+ g_signal_connect_object (key,
+ "focus-out",
G_CALLBACK (hide_completion_cb),
completion,
G_CONNECT_SWAPPED);
- g_signal_connect_object (completion->view,
- "button-press-event",
+ g_signal_connect_object (click,
+ "pressed",
G_CALLBACK (hide_completion_cb),
completion,
G_CONNECT_SWAPPED);
- g_signal_connect_object (completion->view,
- "key-press-event",
+ g_signal_connect_object (key,
+ "key-pressed",
G_CALLBACK (view_key_press_event_cb),
completion,
0);
@@ -2089,13 +2108,10 @@ init_tree_view (GtkSourceCompletion *completion,
gtk_style_context_set_state (style_context, GTK_STATE_FLAG_INSENSITIVE);
gtk_style_context_get (style_context,
- gtk_style_context_get_state (style_context),
"background-color", &background_color,
NULL);
- gtk_style_context_get_color (style_context,
- gtk_style_context_get_state (style_context),
- &foreground_color);
+ gtk_style_context_get_color (style_context, &foreground_color);
gtk_style_context_restore (style_context);
@@ -2171,25 +2187,28 @@ init_main_window (GtkSourceCompletion *completion,
completion->selection_label = GTK_LABEL (gtk_builder_get_object (builder, "selection_label"));
completion->bottom_bar = GTK_WIDGET (gtk_builder_get_object (builder, "bottom_bar"));
- gtk_container_set_border_width (GTK_CONTAINER (completion->main_window), 0);
+ g_object_set (completion->main_window,
+ "margin", 0,
+ NULL);
gtk_window_set_attached_to (GTK_WINDOW (completion->main_window),
GTK_WIDGET (completion->view));
+#if 0
+ /* TODO: fix legacy events */
g_signal_connect (completion->main_window,
"configure-event",
G_CALLBACK (gtk_source_completion_configure_event),
completion);
+#endif
g_signal_connect_swapped (completion->main_window,
"size-allocate",
G_CALLBACK (update_window_position),
completion);
- g_signal_connect (completion->main_window,
- "delete-event",
- G_CALLBACK (gtk_widget_hide_on_delete),
- NULL);
+ gtk_window_set_hide_on_close (GTK_WINDOW (completion->main_window),
+ TRUE);
g_signal_connect (completion->main_window,
"notify::transient-for",
@@ -2251,14 +2270,9 @@ gtk_source_completion_constructed (GObject *object)
GtkSourceCompletion *completion = GTK_SOURCE_COMPLETION (object);
GError *error = NULL;
GtkBuilder *builder = gtk_builder_new ();
- GtkSourceCompletionContainer *container = _gtk_source_completion_container_new ();
- g_object_ref_sink (container);
gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
- /* GtkSourceCompletionContainer is a private type. */
- gtk_builder_expose_object (builder, "completion_container", G_OBJECT (container));
-
gtk_builder_add_from_resource (builder,
"/org/gnome/gtksourceview/ui/gtksourcecompletion.ui",
&error);
@@ -2274,7 +2288,6 @@ gtk_source_completion_constructed (GObject *object)
connect_style_context (completion);
g_object_unref (builder);
- g_object_unref (container);
G_OBJECT_CLASS (gtk_source_completion_parent_class)->constructed (object);
}
diff --git a/gtksourceview/gtksourcecompletion.ui b/gtksourceview/gtksourcecompletion.ui
index 497eabd0..7de346ce 100644
--- a/gtksourceview/gtksourcecompletion.ui
+++ b/gtksourceview/gtksourcecompletion.ui
@@ -27,8 +27,6 @@ along with this library; if not, see <http://www.gnu.org/licenses/>.
<property name="type">popup</property>
<property name="type_hint">combo</property>
<property name="resizable">False</property>
- <property name="skip_taskbar_hint">True</property>
- <property name="skip_pager_hint">True</property>
<property name="accept_focus">False</property>
<property name="focus_on_map">False</property>
<property name="decorated">False</property>
@@ -38,8 +36,12 @@ along with this library; if not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkSourceCompletionContainer" id="completion_container">
+ <object class="GtkScrolledWindow" id="completion_container">
<property name="visible">True</property>
+ <!-- TODO: this will need more work with a gtk4 port -->
+ <property name="propagate-natural-height">True</property>
+ <property name="propagate-natural-width">True</property>
+ <property name="max-content-height">250</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="tree_view_proposals">
@@ -94,24 +96,24 @@ along with this library; if not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="halign">end</property>
<property name="hexpand">True</property>
+ <layout>
+ <property name="left_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="selection_label">
<property name="visible">True</property>
<property name="margin">6</property>
+ <layout>
+ <property name="left_attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">2</property>
- </packing>
</child>
+ <layout>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="top_attach">1</property>
- </packing>
</child>
</object>
</child>
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 93884df5..3ae427b6 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -68,6 +68,7 @@ struct _GtkSourceCompletionInfo
guint idle_resize;
GtkWidget *attached_to;
+ GtkEventController *key;
gulong focus_out_event_handler;
gint xoffset;
@@ -79,135 +80,17 @@ G_DEFINE_TYPE (GtkSourceCompletionInfo, gtk_source_completion_info, GTK_TYPE_WIN
/* Resize the window */
-static gboolean
-idle_resize (GtkSourceCompletionInfo *info)
-{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (info));
- GtkRequisition nat_size;
- guint border_width;
- gint window_width;
- gint window_height;
- gint cur_window_width;
- gint cur_window_height;
-
- info->idle_resize = 0;
-
- if (child == NULL)
- {
- return G_SOURCE_REMOVE;
- }
-
- gtk_widget_get_preferred_size (child, NULL, &nat_size);
-
- border_width = gtk_container_get_border_width (GTK_CONTAINER (info));
-
- window_width = nat_size.width + 2 * border_width;
- window_height = nat_size.height + 2 * border_width;
-
- gtk_window_get_size (GTK_WINDOW (info), &cur_window_width, &cur_window_height);
-
- /* Avoid an infinite loop */
- if (cur_window_width != window_width || cur_window_height != window_height)
- {
- gtk_window_resize (GTK_WINDOW (info),
- MAX (1, window_width),
- MAX (1, window_height));
- }
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-queue_resize (GtkSourceCompletionInfo *info)
-{
- if (info->idle_resize == 0)
- {
- info->idle_resize = g_idle_add ((GSourceFunc)idle_resize, info);
- }
-}
-
-static void
-gtk_source_completion_info_check_resize (GtkContainer *container)
-{
- GtkSourceCompletionInfo *info = GTK_SOURCE_COMPLETION_INFO (container);
- queue_resize (info);
-
- GTK_CONTAINER_CLASS (gtk_source_completion_info_parent_class)->check_resize (container);
-}
-
-/* Geometry management */
-
-static GtkSizeRequestMode
-gtk_source_completion_info_get_request_mode (GtkWidget *widget)
-{
- return GTK_SIZE_REQUEST_CONSTANT_SIZE;
-}
-
-static void
-gtk_source_completion_info_get_preferred_width (GtkWidget *widget,
- gint *min_width,
- gint *nat_width)
-{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
- gint width = 0;
-
- if (child != NULL)
- {
- GtkRequisition nat_size;
- gtk_widget_get_preferred_size (child, NULL, &nat_size);
- width = nat_size.width;
- }
-
- if (min_width != NULL)
- {
- *min_width = width;
- }
-
- if (nat_width != NULL)
- {
- *nat_width = width;
- }
-}
+/* Init, dispose, finalize, ... */
static void
-gtk_source_completion_info_get_preferred_height (GtkWidget *widget,
- gint *min_height,
- gint *nat_height)
+set_attached_to (GtkSourceCompletionInfo *info,
+ GtkWidget *attached_to)
{
- GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
- gint height = 0;
-
- if (child != NULL)
+ if (info->attached_to == attached_to)
{
- GtkRequisition nat_size;
- gtk_widget_get_preferred_size (child, NULL, &nat_size);
- height = nat_size.height;
- }
-
- if (min_height != NULL)
- {
- *min_height = height;
- }
-
- if (nat_height != NULL)
- {
- *nat_height = height;
+ return;
}
-}
-/* Init, dispose, finalize, ... */
-
-static gboolean
-focus_out_event_cb (GtkSourceCompletionInfo *info)
-{
- gtk_widget_hide (GTK_WIDGET (info));
- return FALSE;
-}
-
-static void
-set_attached_to (GtkSourceCompletionInfo *info,
- GtkWidget *attached_to)
-{
if (info->attached_to != NULL)
{
g_object_remove_weak_pointer (G_OBJECT (info->attached_to),
@@ -215,14 +98,16 @@ set_attached_to (GtkSourceCompletionInfo *info,
if (info->focus_out_event_handler != 0)
{
- g_signal_handler_disconnect (info->attached_to,
+ g_signal_handler_disconnect (info->key,
info->focus_out_event_handler);
info->focus_out_event_handler = 0;
+ info->key = NULL;
}
}
info->attached_to = attached_to;
+ info->key = NULL;
if (attached_to == NULL)
{
@@ -232,10 +117,13 @@ set_attached_to (GtkSourceCompletionInfo *info,
g_object_add_weak_pointer (G_OBJECT (attached_to),
(gpointer *) &info->attached_to);
+ info->key = gtk_event_controller_key_new ();
+ gtk_widget_add_controller (GTK_WIDGET (attached_to), info->key);
+
info->focus_out_event_handler =
- g_signal_connect_swapped (attached_to,
- "focus-out-event",
- G_CALLBACK (focus_out_event_cb),
+ g_signal_connect_swapped (info->key,
+ "focus-out",
+ G_CALLBACK (gtk_widget_hide),
info);
info->transient_set = FALSE;
@@ -250,8 +138,6 @@ update_attached_to (GtkSourceCompletionInfo *info)
static void
gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
{
- info = gtk_source_completion_info_get_instance_private (info);
-
g_signal_connect (info,
"notify::attached-to",
G_CALLBACK (update_attached_to),
@@ -264,9 +150,9 @@ gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
gtk_widget_set_name (GTK_WIDGET (info), "gtk-tooltip");
gtk_window_set_type_hint (GTK_WINDOW (info),
- GDK_WINDOW_TYPE_HINT_COMBO);
+ GDK_SURFACE_TYPE_HINT_COMBO);
- gtk_container_set_border_width (GTK_CONTAINER (info), 1);
+ g_object_set (info, "margin", 1, NULL);
}
static void
@@ -292,13 +178,14 @@ gtk_source_completion_info_show (GtkWidget *widget)
if (info->attached_to != NULL && !info->transient_set)
{
- GtkWidget *toplevel;
+ GtkRoot *toplevel;
+
+ toplevel = gtk_widget_get_root (GTK_WIDGET (info->attached_to));
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (info->attached_to));
- if (gtk_widget_is_toplevel (toplevel))
+ if (toplevel != NULL)
{
gtk_window_set_transient_for (GTK_WINDOW (info),
- GTK_WINDOW (toplevel));
+ GTK_WINDOW (toplevel));
info->transient_set = TRUE;
}
}
@@ -306,37 +193,15 @@ gtk_source_completion_info_show (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_source_completion_info_parent_class)->show (widget);
}
-static gboolean
-gtk_source_completion_info_draw (GtkWidget *widget,
- cairo_t *cr)
-{
- GTK_WIDGET_CLASS (gtk_source_completion_info_parent_class)->draw (widget, cr);
-
- gtk_render_frame (gtk_widget_get_style_context (widget),
- cr,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
-
- return FALSE;
-}
-
static void
gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
object_class->dispose = gtk_source_completion_info_dispose;
widget_class->show = gtk_source_completion_info_show;
- widget_class->draw = gtk_source_completion_info_draw;
- widget_class->get_request_mode = gtk_source_completion_info_get_request_mode;
- widget_class->get_preferred_width = gtk_source_completion_info_get_preferred_width;
- widget_class->get_preferred_height = gtk_source_completion_info_get_preferred_height;
-
- container_class->check_resize = gtk_source_completion_info_check_resize;
}
void
@@ -349,6 +214,7 @@ _gtk_source_completion_info_set_xoffset (GtkSourceCompletionInfo *window,
}
/* Move to iter */
+#if 0
static void
get_iter_pos (GtkTextView *text_view,
@@ -529,6 +395,7 @@ move_to_cursor (GtkSourceCompletionInfo *window,
move_to_iter (window, view, &insert);
}
+#endif
/* Public functions */
@@ -542,7 +409,7 @@ gtk_source_completion_info_new (void)
{
return g_object_new (GTK_SOURCE_TYPE_COMPLETION_INFO,
"type", GTK_WINDOW_POPUP,
- "border-width", 3,
+ "margin", 3,
NULL);
}
@@ -565,6 +432,7 @@ gtk_source_completion_info_move_to_iter (GtkSourceCompletionInfo *info,
g_return_if_fail (GTK_SOURCE_IS_COMPLETION_INFO (info));
g_return_if_fail (GTK_IS_TEXT_VIEW (view));
+#if 0
if (iter == NULL)
{
move_to_cursor (info, view);
@@ -573,4 +441,5 @@ gtk_source_completion_info_move_to_iter (GtkSourceCompletionInfo *info,
{
move_to_iter (info, view, iter);
}
+#endif
}
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index dc1bf174..b086e484 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -2391,8 +2391,9 @@ install_idle_worker (GtkSourceContextEngine *ce)
{
if (ce->first_update == 0 && ce->incremental_update == 0)
ce->incremental_update =
- gdk_threads_add_idle_full (INCREMENTAL_UPDATE_PRIORITY,
- (GSourceFunc) idle_worker, ce, NULL);
+ g_idle_add_full (INCREMENTAL_UPDATE_PRIORITY,
+ (GSourceFunc) idle_worker,
+ ce, NULL);
}
/**
@@ -2414,9 +2415,9 @@ install_first_update (GtkSourceContextEngine *ce)
}
ce->first_update =
- gdk_threads_add_idle_full (FIRST_UPDATE_PRIORITY,
- (GSourceFunc) first_update_callback,
- ce, NULL);
+ g_idle_add_full (FIRST_UPDATE_PRIORITY,
+ (GSourceFunc) first_update_callback,
+ ce, NULL);
}
}
diff --git a/gtksourceview/gtksourcefile-private.h b/gtksourceview/gtksourcefile-private.h
index 68a94ef8..a64d42cc 100644
--- a/gtksourceview/gtksourcefile-private.h
+++ b/gtksourceview/gtksourcefile-private.h
@@ -35,14 +35,12 @@ void _gtk_source_file_set_compression_type (GtkSource
GtkSourceCompressionType
compression_type);
G_GNUC_INTERNAL
GMountOperation *_gtk_source_file_create_mount_operation (GtkSourceFile *file);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_GNUC_INTERNAL
-gboolean _gtk_source_file_get_modification_time (GtkSourceFile *file,
- GTimeVal
*modification_time);
+gboolean _gtk_source_file_get_modification_time (GtkSourceFile *file,
+ gint64 *modification_time);
G_GNUC_INTERNAL
-void _gtk_source_file_set_modification_time (GtkSourceFile *file,
- GTimeVal
modification_time);
-G_GNUC_END_IGNORE_DEPRECATIONS
+void _gtk_source_file_set_modification_time (GtkSourceFile *file,
+ gint64 modification_time);
G_GNUC_INTERNAL
void _gtk_source_file_set_externally_modified (GtkSourceFile *file,
gboolean
externally_modified);
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 212d46b2..934d150e 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -69,7 +69,7 @@ typedef struct
/* Last known modification time of 'location'. The value is updated on a
* file loading or file saving.
*/
- GTimeVal modification_time;
+ gint64 modification_time;
guint modification_time_set : 1;
@@ -467,7 +467,7 @@ _gtk_source_file_create_mount_operation (GtkSourceFile *file)
gboolean
_gtk_source_file_get_modification_time (GtkSourceFile *file,
- GTimeVal *modification_time)
+ gint64 *modification_time)
{
GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
@@ -490,7 +490,7 @@ _gtk_source_file_get_modification_time (GtkSourceFile *file,
void
_gtk_source_file_set_modification_time (GtkSourceFile *file,
- GTimeVal modification_time)
+ gint64 modification_time)
{
GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
@@ -571,18 +571,21 @@ gtk_source_file_check_file_on_disk (GtkSourceFile *file)
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) &&
priv->modification_time_set)
{
- GTimeVal timeval;
+ GDateTime *dt;
+ gint64 mtime;
- g_file_info_get_modification_time (info, &timeval);
+ dt = g_file_info_get_modification_date_time (info);
+ mtime = g_date_time_to_unix (dt);
/* Note that the modification time can even go backwards if the
* user is copying over an old file.
*/
- if (timeval.tv_sec != priv->modification_time.tv_sec ||
- timeval.tv_usec != priv->modification_time.tv_usec)
+ if (mtime != priv->modification_time)
{
priv->externally_modified = TRUE;
}
+
+ g_date_time_unref (dt);
}
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index e6970fe2..8724731a 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -1250,10 +1250,18 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader *loader,
if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
- GTimeVal modification_time;
+ GDateTime *dt;
+ gint64 mtime = 0;
- g_file_info_get_modification_time (task_data->info, &modification_time);
- _gtk_source_file_set_modification_time (loader->file, modification_time);
+ dt = g_file_info_get_modification_date_time (task_data->info);
+
+ if (dt != NULL)
+ {
+ mtime = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
+ }
+
+ _gtk_source_file_set_modification_time (loader->file, mtime);
}
if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 18e87913..426bbba3 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -925,8 +925,8 @@ check_externally_modified_cb (GObject *source_object,
GtkSourceFileSaver *saver;
TaskData *task_data;
GFileInfo *info;
- GTimeVal old_mtime;
- GTimeVal cur_mtime;
+ gint64 old_mtime;
+ gint64 cur_mtime;
GError *error = NULL;
DEBUG ({
@@ -965,10 +965,13 @@ check_externally_modified_cb (GObject *source_object,
info != NULL &&
g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
- g_file_info_get_modification_time (info, &cur_mtime);
+ GDateTime *dt;
- if (old_mtime.tv_sec != cur_mtime.tv_sec ||
- old_mtime.tv_usec != cur_mtime.tv_usec)
+ dt = g_file_info_get_modification_date_time (info);
+ cur_mtime = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
+
+ if (old_mtime != cur_mtime)
{
DEBUG ({
g_print ("The file is externally modified\n");
@@ -1505,10 +1508,14 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
{
- GTimeVal modification_time;
+ GDateTime *dt;
+ gint64 mtime;
+
+ dt = g_file_info_get_modification_date_time (task_data->info);
+ mtime = g_date_time_to_unix (dt);
+ g_date_time_unref (dt);
- g_file_info_get_modification_time (task_data->info, &modification_time);
- _gtk_source_file_set_modification_time (saver->file, modification_time);
+ _gtk_source_file_set_modification_time (saver->file, mtime);
}
}
diff --git a/gtksourceview/gtksourcegutter-private.h b/gtksourceview/gtksourcegutter-private.h
index e1ebeb8a..e3e5a118 100644
--- a/gtksourceview/gtksourcegutter-private.h
+++ b/gtksourceview/gtksourcegutter-private.h
@@ -21,16 +21,14 @@
#pragma once
#include <gtk/gtk.h>
+
#include "gtksourcetypes.h"
G_BEGIN_DECLS
G_GNUC_INTERNAL
-GtkSourceGutter *_gtk_source_gutter_new (GtkSourceView *view,
- GtkTextWindowType type);
+GtkSourceGutter *_gtk_source_gutter_new (GtkTextWindowType type);
G_GNUC_INTERNAL
-void _gtk_source_gutter_draw (GtkSourceGutter *gutter,
- GtkSourceView *view,
- cairo_t *cr);
+GtkSourceLines *_gtk_source_gutter_get_lines (GtkSourceGutter *gutter);
G_END_DECLS
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index 9a988e53..eb493c55 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -22,6 +22,8 @@
#include "gtksourcegutter.h"
#include "gtksourcegutter-private.h"
+#include "gtksourcelines.h"
+#include "gtksourcelines-private.h"
#include "gtksourceview.h"
#include "gtksourcegutterrenderer.h"
#include "gtksourcegutterrenderer-private.h"
@@ -62,134 +64,74 @@ typedef struct
gint prelit;
gint position;
-
- gulong queue_draw_handler;
- gulong size_changed_handler;
- gulong notify_xpad_handler;
- gulong notify_ypad_handler;
- gulong notify_visible_handler;
} Renderer;
struct _GtkSourceGutter
{
- GObject parent_instance;
-
- GtkSourceView *view;
- GtkTextWindowType window_type;
- GtkOrientation orientation;
-
- GList *renderers;
-
- guint is_drawing : 1;
-};
+ GtkContainer parent_instance;
-G_DEFINE_TYPE (GtkSourceGutter, gtk_source_gutter, G_TYPE_OBJECT)
-
-static gboolean on_view_motion_notify_event (GtkSourceView *view,
- GdkEventMotion *event,
- GtkSourceGutter *gutter);
-static gboolean on_view_enter_notify_event (GtkSourceView *view,
- GdkEventCrossing *event,
- GtkSourceGutter *gutter);
-static gboolean on_view_leave_notify_event (GtkSourceView *view,
- GdkEventCrossing *event,
- GtkSourceGutter *gutter);
-static gboolean on_view_button_press_event (GtkSourceView *view,
- GdkEventButton *event,
- GtkSourceGutter *gutter);
-static gboolean on_view_query_tooltip (GtkSourceView *view,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- GtkSourceGutter *gutter);
-static void on_view_style_updated (GtkSourceView *view,
- GtkSourceGutter *gutter);
-static void do_redraw (GtkSourceGutter *gutter);
-static void update_gutter_size (GtkSourceGutter *gutter);
-
-static GdkWindow *
-get_window (GtkSourceGutter *gutter)
-{
- return gtk_text_view_get_window (GTK_TEXT_VIEW (gutter->view),
- gutter->window_type);
-}
+ GtkSourceView *view;
+ GList *renderers;
+ GtkSourceLines *lines;
-static void
-on_renderer_size_changed (GtkSourceGutterRenderer *renderer,
- GParamSpec *spec,
- GtkSourceGutter *gutter)
-{
- update_gutter_size (gutter);
-}
+ GtkTextWindowType window_type;
+ GtkOrientation orientation;
-static void
-on_renderer_queue_draw (GtkSourceGutterRenderer *renderer,
- GtkSourceGutter *gutter)
-{
- do_redraw (gutter);
-}
+ gulong adj_changed_handler;
+ gulong realize_handler;
+ gulong style_updated_handler;
-static void
-on_renderer_notify_padding (GtkSourceGutterRenderer *renderer,
- GParamSpec *spec,
- GtkSourceGutter *gutter)
-{
- update_gutter_size (gutter);
-}
+ guint is_drawing : 1;
+};
-static void
-on_renderer_notify_visible (GtkSourceGutterRenderer *renderer,
- GParamSpec *spec,
- GtkSourceGutter *gutter)
-{
- update_gutter_size (gutter);
-}
+G_DEFINE_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_TYPE_CONTAINER)
+
+static void gtk_source_gutter_add (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_source_gutter_remove (GtkContainer *container,
+ GtkWidget *widget);
+static void on_view_style_updated (GtkSourceView *view,
+ GtkSourceGutter *gutter);
+static void on_gutter_motion_enter (GtkSourceGutter *gutter,
+ gdouble x,
+ gdouble y,
+ GdkCrossingMode mode,
+ GdkNotifyType notify_type,
+ GtkEventControllerMotion *motion);
+static void on_gutter_motion (GtkSourceGutter *gutter,
+ gdouble x,
+ gdouble y,
+ GtkEventControllerMotion *motion);
+static void on_gutter_motion_leave (GtkSourceGutter *gutter,
+ GdkCrossingMode mode,
+ GdkNotifyType notify_type,
+ GtkEventControllerMotion *motion);
+static void on_gutter_pressed_cb (GtkSourceGutter *gutter,
+ gint n_presses,
+ gdouble x,
+ gdouble y,
+ GtkGestureClick *click);
+static void do_redraw (GtkSourceGutter *gutter);
+static void gtk_source_gutter_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot);
+static void gtk_source_gutter_size_allocate (GtkWidget *widget,
+ gint width,
+ gint height,
+ gint baseline);
static Renderer *
renderer_new (GtkSourceGutter *gutter,
GtkSourceGutterRenderer *renderer,
gint position)
{
- Renderer *ret = g_slice_new0 (Renderer);
+ Renderer *ret;
+ ret = g_slice_new0 (Renderer);
ret->renderer = g_object_ref_sink (renderer);
ret->position = position;
ret->prelit = -1;
- _gtk_source_gutter_renderer_set_view (renderer,
- GTK_TEXT_VIEW (gutter->view),
- gutter->window_type);
-
- ret->size_changed_handler =
- g_signal_connect (ret->renderer,
- "notify::size",
- G_CALLBACK (on_renderer_size_changed),
- gutter);
-
- ret->queue_draw_handler =
- g_signal_connect (ret->renderer,
- "queue-draw",
- G_CALLBACK (on_renderer_queue_draw),
- gutter);
-
- ret->notify_xpad_handler =
- g_signal_connect (ret->renderer,
- "notify::xpad",
- G_CALLBACK (on_renderer_notify_padding),
- gutter);
-
- ret->notify_ypad_handler =
- g_signal_connect (ret->renderer,
- "notify::ypad",
- G_CALLBACK (on_renderer_notify_padding),
- gutter);
-
- ret->notify_visible_handler =
- g_signal_connect (ret->renderer,
- "notify::visible",
- G_CALLBACK (on_renderer_notify_visible),
- gutter);
+ _gtk_source_gutter_renderer_set_view (renderer, gutter->view);
return ret;
}
@@ -197,40 +139,48 @@ renderer_new (GtkSourceGutter *gutter,
static void
renderer_free (Renderer *renderer)
{
- g_signal_handler_disconnect (renderer->renderer,
- renderer->queue_draw_handler);
-
- g_signal_handler_disconnect (renderer->renderer,
- renderer->size_changed_handler);
-
- g_signal_handler_disconnect (renderer->renderer,
- renderer->notify_xpad_handler);
-
- g_signal_handler_disconnect (renderer->renderer,
- renderer->notify_ypad_handler);
-
- g_signal_handler_disconnect (renderer->renderer,
- renderer->notify_visible_handler);
-
- _gtk_source_gutter_renderer_set_view (renderer->renderer,
- NULL,
- GTK_TEXT_WINDOW_PRIVATE);
+ _gtk_source_gutter_renderer_set_view (renderer->renderer, NULL);
g_object_unref (renderer->renderer);
g_slice_free (Renderer, renderer);
}
static void
-gtk_source_gutter_dispose (GObject *object)
+get_alignment_modes (GtkSourceGutter *gutter,
+ gboolean *needs_wrap_first,
+ gboolean *needs_wrap_last)
{
- GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (object);
+ const GList *list;
+
+ g_assert (GTK_SOURCE_GUTTER (gutter));
+ g_assert (needs_wrap_first != NULL);
+ g_assert (needs_wrap_last != NULL);
+
+ *needs_wrap_first = FALSE;
+ *needs_wrap_last = FALSE;
- g_list_free_full (gutter->renderers, (GDestroyNotify)renderer_free);
- gutter->renderers = NULL;
+ for (list = gutter->renderers; list; list = list->next)
+ {
+ Renderer *renderer = list->data;
+ GtkSourceGutterRendererAlignmentMode mode;
+
+ mode = gtk_source_gutter_renderer_get_alignment_mode (renderer->renderer);
+
+ switch (mode)
+ {
+ case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST:
+ *needs_wrap_first = TRUE;
+ break;
- gutter->view = NULL;
+ case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST:
+ *needs_wrap_last = TRUE;
+ break;
- G_OBJECT_CLASS (gtk_source_gutter_parent_class)->dispose (object);
+ case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL:
+ default:
+ break;
+ }
+ }
}
static void
@@ -239,16 +189,18 @@ gtk_source_gutter_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GtkSourceGutter *self = GTK_SOURCE_GUTTER (object);
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (object);
switch (prop_id)
{
case PROP_VIEW:
- g_value_set_object (value, self->view);
+ g_value_set_object (value, gutter->view);
break;
+
case PROP_WINDOW_TYPE:
- g_value_set_enum (value, self->window_type);
+ g_value_set_enum (value, gutter->window_type);
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -256,143 +208,233 @@ gtk_source_gutter_get_property (GObject *object,
}
static void
-on_view_realize (GtkSourceView *view,
- GtkSourceGutter *gutter)
+on_adjustment_value_changed (GtkAdjustment *adj,
+ GtkSourceGutter *gutter)
+{
+ const GList *list;
+
+ for (list = gutter->renderers; list; list = list->next)
+ {
+ Renderer *renderer = list->data;
+
+ gtk_widget_queue_draw (GTK_WIDGET (renderer->renderer));
+ }
+}
+
+static GtkAdjustment *
+get_adjustment (GtkSourceGutter *gutter,
+ GtkSourceView *view)
+{
+ if (gutter->window_type == GTK_TEXT_WINDOW_LEFT ||
+ gutter->window_type == GTK_TEXT_WINDOW_RIGHT)
+ {
+ return gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view));
+ }
+ else
+ {
+ return gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (view));
+ }
+}
+
+static void
+connect_view (GtkSourceGutter *gutter,
+ GtkSourceView *view)
+{
+ g_assert (GTK_SOURCE_IS_GUTTER (gutter));
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+
+ gutter->adj_changed_handler =
+ g_signal_connect (get_adjustment (gutter, view),
+ "value-changed",
+ G_CALLBACK (on_adjustment_value_changed),
+ gutter);
+
+ gutter->style_updated_handler =
+ g_signal_connect (view,
+ "style-updated",
+ G_CALLBACK (on_view_style_updated),
+ gutter);
+}
+
+static void
+disconnect_view (GtkSourceGutter *gutter,
+ GtkSourceView *view)
{
- update_gutter_size (gutter);
+ g_assert (GTK_SOURCE_IS_GUTTER (gutter));
+ g_assert (GTK_SOURCE_IS_VIEW (view));
+
+ g_clear_signal_handler (&gutter->adj_changed_handler,
+ get_adjustment (gutter, view));
+ g_clear_signal_handler (&gutter->realize_handler, view);
+ g_clear_signal_handler (&gutter->style_updated_handler, view);
}
static void
set_view (GtkSourceGutter *gutter,
GtkSourceView *view)
{
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
+ g_return_if_fail (!view || GTK_SOURCE_IS_VIEW (view));
+
+ if (view == gutter->view)
+ {
+ return;
+ }
+
+ if (gutter->view != NULL)
+ {
+ disconnect_view (gutter, gutter->view);
+ }
+
gutter->view = view;
- g_signal_connect_object (view,
- "motion-notify-event",
- G_CALLBACK (on_view_motion_notify_event),
- gutter,
- 0);
-
- g_signal_connect_object (view,
- "enter-notify-event",
- G_CALLBACK (on_view_enter_notify_event),
- gutter,
- 0);
-
- g_signal_connect_object (view,
- "leave-notify-event",
- G_CALLBACK (on_view_leave_notify_event),
- gutter,
- 0);
-
- g_signal_connect_object (view,
- "button-press-event",
- G_CALLBACK (on_view_button_press_event),
- gutter,
- 0);
-
- g_signal_connect_object (view,
- "query-tooltip",
- G_CALLBACK (on_view_query_tooltip),
- gutter,
- 0);
-
- g_signal_connect_object (view,
- "realize",
- G_CALLBACK (on_view_realize),
- gutter,
- 0);
-
- g_signal_connect_object (view,
- "style-updated",
- G_CALLBACK (on_view_style_updated),
- gutter,
- 0);
+ if (view != NULL)
+ {
+ connect_view (gutter, view);
+ }
}
static void
do_redraw (GtkSourceGutter *gutter)
{
- GdkWindow *window;
-
- window = gtk_text_view_get_window (GTK_TEXT_VIEW (gutter->view),
- gutter->window_type);
-
- if (window && !gutter->is_drawing)
+ if (!gutter->is_drawing)
{
- gdk_window_invalidate_rect (window, NULL, FALSE);
+ gtk_widget_queue_draw (GTK_WIDGET (gutter));
}
}
-static gint
-calculate_gutter_size (GtkSourceGutter *gutter,
- GArray *sizes)
+static void
+gtk_source_gutter_map (GtkWidget *widget)
{
- GList *item;
- gint total_width = 0;
+ gtk_widget_set_cursor_from_name (widget, "arrow");
+ GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->map (widget);
+}
+
+static void
+gtk_source_gutter_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
+{
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (widget);
+ const GList *item;
/* Calculate size */
- for (item = gutter->renderers; item; item = g_list_next (item))
+ for (item = gutter->renderers; item; item = item->next)
{
Renderer *renderer = item->data;
- gint width;
+ int r_minimum;
+ int r_natural;
+ int r_minimum_baseline;
+ int r_natural_baseline;
- if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
+ if (!gtk_widget_get_visible (GTK_WIDGET (renderer->renderer)))
{
- width = 0;
+ continue;
}
- else
- {
- gint xpad;
- gint size;
- size = gtk_source_gutter_renderer_get_size (renderer->renderer);
+ gtk_widget_measure (GTK_WIDGET (renderer->renderer),
+ orientation,
+ for_size,
+ &r_minimum,
+ &r_natural,
+ &r_minimum_baseline,
+ &r_natural_baseline);
- gtk_source_gutter_renderer_get_padding (renderer->renderer,
- &xpad,
- NULL);
+ *minimum += r_minimum;
+ *natural += r_natural;
+ }
- width = size + 2 * xpad;
- }
+ *minimum_baseline = -1;
+ *natural_baseline = -1;
+}
- if (sizes)
- {
- g_array_append_val (sizes, width);
- }
+static void
+apply_style (GtkSourceGutter *gutter,
+ GtkStyleContext *style_context)
+{
+ const gchar *class;
+
+ switch (gutter->window_type)
+ {
+ case GTK_TEXT_WINDOW_TOP:
+ class = GTK_STYLE_CLASS_TOP;
+ break;
+
+ case GTK_TEXT_WINDOW_RIGHT:
+ class = GTK_STYLE_CLASS_RIGHT;
+ break;
+
+ case GTK_TEXT_WINDOW_BOTTOM:
+ class = GTK_STYLE_CLASS_BOTTOM;
+ break;
+
+ case GTK_TEXT_WINDOW_LEFT:
+ class = GTK_STYLE_CLASS_LEFT;
+ break;
- total_width += width;
+ case GTK_TEXT_WINDOW_WIDGET:
+ case GTK_TEXT_WINDOW_TEXT:
+ default:
+ g_return_if_reached ();
}
- return total_width;
+ gtk_style_context_add_class (style_context, class);
+}
+
+static void
+gtk_source_gutter_root (GtkWidget *widget)
+{
+ GtkWidget *view;
+
+ GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->root (widget);
+
+ view = gtk_widget_get_ancestor (widget, GTK_SOURCE_TYPE_VIEW);
+ set_view (GTK_SOURCE_GUTTER (widget), GTK_SOURCE_VIEW (view));
+}
+
+static void
+gtk_source_gutter_unroot (GtkWidget *widget)
+{
+ GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->unroot (widget);
+ set_view (GTK_SOURCE_GUTTER (widget), NULL);
}
static void
-update_gutter_size (GtkSourceGutter *gutter)
+gtk_source_gutter_forall (GtkContainer *container,
+ GtkCallback callback,
+ gpointer callback_data)
{
- gint width = calculate_gutter_size (gutter, NULL);
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (container);
+ const GList *list = gutter->renderers;
- gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (gutter->view),
- gutter->window_type,
- width);
+ while (list != NULL)
+ {
+ Renderer *renderer = list->data;
+
+ list = list->next;
+
+ callback (GTK_WIDGET (renderer->renderer), callback_data);
+ }
}
static void
-gtk_source_gutter_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+gtk_source_gutter_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GtkSourceGutter *self = GTK_SOURCE_GUTTER (object);
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (object);
switch (prop_id)
{
- case PROP_VIEW:
- set_view (self, GTK_SOURCE_VIEW (g_value_get_object (value)));
- break;
case PROP_WINDOW_TYPE:
- self->window_type = g_value_get_enum (value);
+ gutter->window_type = g_value_get_enum (value);
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -402,33 +444,48 @@ gtk_source_gutter_set_property (GObject *object,
static void
gtk_source_gutter_constructed (GObject *object)
{
- GtkSourceGutter *gutter;
-
- gutter = GTK_SOURCE_GUTTER (object);
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (object);
+ GtkStyleContext *context;
if (gutter->window_type == GTK_TEXT_WINDOW_LEFT ||
gutter->window_type == GTK_TEXT_WINDOW_RIGHT)
{
gutter->orientation = GTK_ORIENTATION_HORIZONTAL;
+ gtk_widget_set_vexpand (GTK_WIDGET (gutter), TRUE);
}
else
{
gutter->orientation = GTK_ORIENTATION_VERTICAL;
+ gtk_widget_set_hexpand (GTK_WIDGET (gutter), TRUE);
}
G_OBJECT_CLASS (gtk_source_gutter_parent_class)->constructed (object);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (gutter));
+ apply_style (gutter, context);
}
static void
gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
- object_class->set_property = gtk_source_gutter_set_property;
+ object_class->constructed = gtk_source_gutter_constructed;
object_class->get_property = gtk_source_gutter_get_property;
+ object_class->set_property = gtk_source_gutter_set_property;
- object_class->dispose = gtk_source_gutter_dispose;
- object_class->constructed = gtk_source_gutter_constructed;
+ widget_class->map = gtk_source_gutter_map;
+ widget_class->measure = gtk_source_gutter_measure;
+ widget_class->root = gtk_source_gutter_root;
+ widget_class->size_allocate = gtk_source_gutter_size_allocate;
+ widget_class->snapshot = gtk_source_gutter_snapshot;
+ widget_class->unroot = gtk_source_gutter_unroot;
+
+ container_class->forall = gtk_source_gutter_forall;
+ container_class->add = gtk_source_gutter_add;
+ container_class->remove = gtk_source_gutter_remove;
/**
* GtkSourceGutter:view:
@@ -441,7 +498,7 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
"View",
"",
GTK_SOURCE_TYPE_VIEW,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GtkSourceGutter:window-type:
@@ -454,14 +511,43 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
"Window Type",
"The gutters' text window type",
GTK_TYPE_TEXT_WINDOW_TYPE,
- 0,
+ GTK_TEXT_WINDOW_LEFT,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+ gtk_widget_class_set_css_name (widget_class, "gutter");
}
static void
-gtk_source_gutter_init (GtkSourceGutter *self)
+gtk_source_gutter_init (GtkSourceGutter *gutter)
{
- self = gtk_source_gutter_get_instance_private (self);
+ GtkGesture *click;
+ GtkEventController *motion;
+
+ gutter->window_type = GTK_TEXT_WINDOW_LEFT;
+
+ /* Setup fallback click handling */
+ click = gtk_gesture_click_new ();
+ g_signal_connect_swapped (click,
+ "pressed",
+ G_CALLBACK (on_gutter_pressed_cb),
+ gutter);
+ gtk_widget_add_controller (GTK_WIDGET (gutter), GTK_EVENT_CONTROLLER (click));
+
+ /* Track motion enter/leave for prelit status */
+ motion = gtk_event_controller_motion_new ();
+ g_signal_connect_swapped (motion,
+ "enter",
+ G_CALLBACK (on_gutter_motion_enter),
+ gutter);
+ g_signal_connect_swapped (motion,
+ "leave",
+ G_CALLBACK (on_gutter_motion_leave),
+ gutter);
+ g_signal_connect_swapped (motion,
+ "motion",
+ G_CALLBACK (on_gutter_motion),
+ gutter);
+ gtk_widget_add_controller (GTK_WIDGET (gutter), motion);
}
static gint
@@ -487,32 +573,26 @@ static void
append_renderer (GtkSourceGutter *gutter,
Renderer *renderer)
{
- gutter->renderers =
- g_list_insert_sorted_with_data (gutter->renderers,
- renderer,
- (GCompareDataFunc)sort_by_position,
- NULL);
-
- update_gutter_size (gutter);
+ gutter->renderers = g_list_insert_sorted_with_data (gutter->renderers,
+ renderer,
+ (GCompareDataFunc)sort_by_position,
+ NULL);
}
GtkSourceGutter *
-_gtk_source_gutter_new (GtkSourceView *view,
- GtkTextWindowType type)
+_gtk_source_gutter_new (GtkTextWindowType type)
{
return g_object_new (GTK_SOURCE_TYPE_GUTTER,
- "view", view,
"window_type", type,
NULL);
}
-/* Public API */
-
/**
* gtk_source_gutter_get_view:
* @gutter: a #GtkSourceGutter.
*
* Returns: (transfer none): the associated #GtkSourceView.
+ *
* Since: 3.24
*/
GtkSourceView *
@@ -523,21 +603,6 @@ gtk_source_gutter_get_view (GtkSourceGutter *gutter)
return gutter->view;
}
-/**
- * gtk_source_gutter_get_window_type:
- * @gutter: a #GtkSourceGutter.
- *
- * Returns: the #GtkTextWindowType of @gutter.
- * Since: 3.24
- */
-GtkTextWindowType
-gtk_source_gutter_get_window_type (GtkSourceGutter *gutter)
-{
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), GTK_TEXT_WINDOW_PRIVATE);
-
- return gutter->window_type;
-}
-
/**
* gtk_source_gutter_insert:
* @gutter: a #GtkSourceGutter.
@@ -563,10 +628,11 @@ gtk_source_gutter_insert (GtkSourceGutter *gutter,
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), FALSE);
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
g_return_val_if_fail (gtk_source_gutter_renderer_get_view (renderer) == NULL, FALSE);
- g_return_val_if_fail (gtk_source_gutter_renderer_get_window_type (renderer) ==
GTK_TEXT_WINDOW_PRIVATE, FALSE);
internal_renderer = renderer_new (gutter, renderer, position);
append_renderer (gutter, internal_renderer);
+ gtk_widget_set_parent (GTK_WIDGET (renderer), GTK_WIDGET (gutter));
+ gtk_widget_queue_resize (GTK_WIDGET (gutter));
return TRUE;
}
@@ -579,7 +645,7 @@ renderer_find (GtkSourceGutter *gutter,
{
GList *list;
- for (list = gutter->renderers; list; list = g_list_next (list))
+ for (list = gutter->renderers; list; list = list->next)
{
*ret = list->data;
@@ -597,50 +663,69 @@ renderer_find (GtkSourceGutter *gutter,
return FALSE;
}
-/**
- * gtk_source_gutter_reorder:
- * @gutter: a #GtkSourceGutterRenderer.
- * @renderer: a #GtkCellRenderer.
- * @position: the new renderer position.
- *
- * Reorders @renderer in @gutter to new @position.
- *
- * Since: 2.8
- */
-void
-gtk_source_gutter_reorder (GtkSourceGutter *gutter,
- GtkSourceGutterRenderer *renderer,
- gint position)
+static void
+gtk_source_gutter_add (GtkContainer *container,
+ GtkWidget *widget)
+{
+ if (!GTK_SOURCE_IS_GUTTER_RENDERER (widget))
+ {
+ g_warning ("Cannot add %s to %s as it is not a GtkSourceGutterRenderer",
+ G_OBJECT_TYPE_NAME (widget),
+ G_OBJECT_TYPE_NAME (container));
+ }
+ else
+ {
+ gtk_source_gutter_insert (GTK_SOURCE_GUTTER (container),
+ GTK_SOURCE_GUTTER_RENDERER (widget),
+ 0);
+ }
+}
+
+static void
+gtk_source_gutter_remove (GtkContainer *container,
+ GtkWidget *widget)
{
+ GtkSourceGutterRenderer *renderer;
+ GtkSourceGutter *gutter;
Renderer *ret;
GList *retlist;
- g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER (container));
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (widget));
+
+ gutter = GTK_SOURCE_GUTTER (container);
+ renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
if (renderer_find (gutter, renderer, &ret, &retlist))
{
gutter->renderers =
- g_list_delete_link (gutter->renderers,
- retlist);
-
- ret->position = position;
- append_renderer (gutter, ret);
+ g_list_delete_link (gutter->renderers, retlist);
+ gtk_widget_unparent (GTK_WIDGET (renderer));
+ renderer_free (ret);
+ gtk_widget_queue_resize (GTK_WIDGET (gutter));
+ }
+ else
+ {
+ g_warning ("Failed to locate %s within %s",
+ G_OBJECT_TYPE_NAME (widget),
+ G_OBJECT_TYPE_NAME (gutter));
}
}
/**
- * gtk_source_gutter_remove:
- * @gutter: a #GtkSourceGutter.
- * @renderer: a #GtkSourceGutterRenderer.
+ * gtk_source_gutter_reorder:
+ * @gutter: a #GtkSourceGutterRenderer.
+ * @renderer: a #GtkCellRenderer.
+ * @position: the new renderer position.
*
- * Removes @renderer from @gutter.
+ * Reorders @renderer in @gutter to new @position.
*
* Since: 2.8
*/
void
-gtk_source_gutter_remove (GtkSourceGutter *gutter,
- GtkSourceGutterRenderer *renderer)
+gtk_source_gutter_reorder (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer,
+ gint position)
{
Renderer *ret;
GList *retlist;
@@ -651,549 +736,180 @@ gtk_source_gutter_remove (GtkSourceGutter *gutter,
if (renderer_find (gutter, renderer, &ret, &retlist))
{
gutter->renderers =
- g_list_delete_link (gutter->renderers,
- retlist);
-
- update_gutter_size (gutter);
- renderer_free (ret);
+ g_list_delete_link (gutter->renderers, retlist);
+ ret->position = position;
+ append_renderer (gutter, ret);
+ gtk_widget_queue_allocate (GTK_WIDGET (gutter));
}
}
-/**
- * gtk_source_gutter_queue_draw:
- * @gutter: a #GtkSourceGutter.
- *
- * Invalidates the drawable area of the gutter. You can use this to force a
- * redraw of the gutter if something has changed and needs to be redrawn.
- *
- * Since: 2.8
- */
-void
-gtk_source_gutter_queue_draw (GtkSourceGutter *gutter)
-{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
-
- do_redraw (gutter);
-}
-
-typedef struct
-{
- gint total_height;
- gint lines_count;
- GArray *buffer_coords;
- GArray *line_heights;
- GArray *line_numbers;
- GtkTextIter start;
- GtkTextIter end;
-} LinesInfo;
-
-static LinesInfo *
-lines_info_new (void)
-{
- LinesInfo *info;
-
- info = g_slice_new0 (LinesInfo);
-
- info->buffer_coords = g_array_new (FALSE, FALSE, sizeof (gint));
- info->line_heights = g_array_new (FALSE, FALSE, sizeof (gint));
- info->line_numbers = g_array_new (FALSE, FALSE, sizeof (gint));
-
- return info;
-}
-
static void
-lines_info_free (LinesInfo *info)
-{
- if (info != NULL)
- {
- g_array_free (info->buffer_coords, TRUE);
- g_array_free (info->line_heights, TRUE);
- g_array_free (info->line_numbers, TRUE);
-
- g_slice_free (LinesInfo, info);
- }
-}
-
-/* This function is taken and adapted from gtk+/tests/testtext.c */
-static LinesInfo *
-get_lines_info (GtkTextView *text_view,
- gint first_y_buffer_coord,
- gint last_y_buffer_coord)
+gtk_source_gutter_size_allocate (GtkWidget *widget,
+ gint width,
+ gint height,
+ gint baseline)
{
- LinesInfo *info;
- GtkTextIter iter;
- gint last_line_num = -1;
-
- info = lines_info_new ();
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (widget);
+ const GList *list;
+ gint x = 0;
- /* Get iter at first y */
- gtk_text_view_get_line_at_y (text_view, &iter, first_y_buffer_coord, NULL);
+ GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->size_allocate (widget,
+ width,
+ height,
+ baseline);
- info->start = iter;
-
- /* For each iter, get its location and add it to the arrays.
- * Stop when we pass last_y_buffer_coord.
- */
- while (!gtk_text_iter_is_end (&iter))
+ for (list = gutter->renderers; list; list = list->next)
{
- gint y;
- gint height;
- gint line_num;
+ Renderer *renderer = list->data;
+ GtkRequisition child_req;
+ GtkAllocation alloc;
- gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
+ gtk_widget_get_preferred_size (GTK_WIDGET (renderer->renderer),
+ &child_req, NULL);
- g_array_append_val (info->buffer_coords, y);
- g_array_append_val (info->line_heights, height);
+ alloc.x = x;
+ alloc.y = 0;
+ alloc.width = child_req.width;
+ alloc.height = height;
- info->total_height += height;
+ gtk_widget_size_allocate (GTK_WIDGET (renderer->renderer),
+ &alloc,
+ -1);
- line_num = gtk_text_iter_get_line (&iter);
- g_array_append_val (info->line_numbers, line_num);
-
- last_line_num = line_num;
-
- info->lines_count++;
-
- if (last_y_buffer_coord <= (y + height))
- {
- break;
- }
-
- gtk_text_iter_forward_line (&iter);
- }
-
- if (gtk_text_iter_is_end (&iter))
- {
- gint y;
- gint height;
- gint line_num;
-
- gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
-
- line_num = gtk_text_iter_get_line (&iter);
-
- if (line_num != last_line_num)
- {
- g_array_append_val (info->buffer_coords, y);
- g_array_append_val (info->line_heights, height);
-
- info->total_height += height;
-
- g_array_append_val (info->line_numbers, line_num);
- info->lines_count++;
- }
- }
-
- if (info->lines_count == 0)
- {
- gint y = 0;
- gint n = 0;
- gint height;
-
- info->lines_count = 1;
-
- g_array_append_val (info->buffer_coords, y);
- g_array_append_val (info->line_numbers, n);
-
- gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
- g_array_append_val (info->line_heights, height);
-
- info->total_height += height;
- }
-
- info->end = iter;
-
- return info;
-}
-
-/* Returns %TRUE if @clip is set. @clip contains the area that should be drawn. */
-static gboolean
-get_clip_rectangle (GtkSourceGutter *gutter,
- GtkSourceView *view,
- cairo_t *cr,
- GdkRectangle *clip)
-{
- GdkWindow *window = get_window (gutter);
-
- if (window == NULL || !gtk_cairo_should_draw_window (cr, window))
- {
- return FALSE;
- }
-
- gtk_cairo_transform_to_window (cr, GTK_WIDGET (view), window);
-
- return gdk_cairo_get_clip_rectangle (cr, clip);
-}
-
-static void
-apply_style (GtkSourceGutter *gutter,
- GtkSourceView *view,
- GtkStyleContext *style_context,
- cairo_t *cr)
-{
- const gchar *class;
- GdkRGBA fg_color;
-
- switch (gutter->window_type)
- {
- case GTK_TEXT_WINDOW_TOP:
- class = GTK_STYLE_CLASS_TOP;
- break;
-
- case GTK_TEXT_WINDOW_RIGHT:
- class = GTK_STYLE_CLASS_RIGHT;
- break;
-
- case GTK_TEXT_WINDOW_BOTTOM:
- class = GTK_STYLE_CLASS_BOTTOM;
- break;
-
- case GTK_TEXT_WINDOW_LEFT:
- class = GTK_STYLE_CLASS_LEFT;
- break;
-
- case GTK_TEXT_WINDOW_PRIVATE:
- case GTK_TEXT_WINDOW_WIDGET:
- case GTK_TEXT_WINDOW_TEXT:
- default:
- g_return_if_reached ();
+ x += alloc.width;
}
- /* Apply classes ourselves, since we are in connect_after and so they
- * are not set by gtk.
- */
- gtk_style_context_add_class (style_context, class);
- gtk_style_context_get_color (style_context,
- gtk_style_context_get_state (style_context),
- &fg_color);
-
- gdk_cairo_set_source_rgba (cr, &fg_color);
+ gtk_widget_queue_draw (widget);
}
-/* Call gtk_source_gutter_renderer_begin() on each renderer. */
static void
-begin_draw (GtkSourceGutter *gutter,
- GtkTextView *view,
- GArray *renderer_widths,
- LinesInfo *info,
- cairo_t *cr)
+gtk_source_gutter_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
- GdkRectangle background_area = { 0 };
- GdkRectangle cell_area;
- GList *l;
- gint renderer_num;
-
- background_area.x = 0;
- background_area.height = info->total_height;
-
- gtk_text_view_buffer_to_window_coords (view,
- gutter->window_type,
- 0,
- g_array_index (info->buffer_coords, gint, 0),
- NULL,
- &background_area.y);
+ GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (widget);
+ GtkTextView *text_view = GTK_TEXT_VIEW (gutter->view);
+ GtkStyleContext *view_context;
+ const GList *list;
+ GdkRectangle visible_rect;
+ GtkTextIter begin;
+ GtkTextIter end;
+ gboolean needs_wrap_first = FALSE;
+ gboolean needs_wrap_last = FALSE;
- cell_area = background_area;
+ g_clear_object (&gutter->lines);
- for (l = gutter->renderers, renderer_num = 0;
- l != NULL;
- l = l->next, renderer_num++)
+ if (text_view == NULL || gtk_widget_get_width (widget) == 0)
{
- Renderer *renderer = l->data;
- gint width;
- gint xpad;
-
- width = g_array_index (renderer_widths, gint, renderer_num);
-
- if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
- {
- g_assert_cmpint (width, ==, 0);
- continue;
- }
-
- gtk_source_gutter_renderer_get_padding (renderer->renderer,
- &xpad,
- NULL);
-
- background_area.width = width;
-
- cell_area.width = background_area.width - 2 * xpad;
- cell_area.x = background_area.x + xpad;
-
- cairo_save (cr);
-
- gdk_cairo_rectangle (cr, &background_area);
- cairo_clip (cr);
-
- gtk_source_gutter_renderer_begin (renderer->renderer,
- cr,
- &background_area,
- &cell_area,
- &info->start,
- &info->end);
-
- cairo_restore (cr);
-
- background_area.x += background_area.width;
+ return;
}
-}
-static void
-draw_cells (GtkSourceGutter *gutter,
- GtkTextView *view,
- GArray *renderer_widths,
- LinesInfo *info,
- cairo_t *cr)
-{
- GtkTextBuffer *buffer;
- GtkTextIter insert_iter;
- gint cur_line;
- GtkTextIter selection_start;
- GtkTextIter selection_end;
- gint selection_start_line = 0;
- gint selection_end_line = 0;
- gboolean has_selection;
- GtkTextIter start;
- gint i;
-
- buffer = gtk_text_view_get_buffer (view);
-
- gtk_text_buffer_get_iter_at_mark (buffer,
- &insert_iter,
- gtk_text_buffer_get_insert (buffer));
-
- cur_line = gtk_text_iter_get_line (&insert_iter);
-
- has_selection = gtk_text_buffer_get_selection_bounds (buffer,
- &selection_start,
- &selection_end);
-
- if (has_selection)
- {
- selection_start_line = gtk_text_iter_get_line (&selection_start);
- selection_end_line = gtk_text_iter_get_line (&selection_end);
- }
+ /* We need the style from the view itself for highlight lines */
+ view_context = gtk_widget_get_style_context (GTK_WIDGET (gutter->view));
- start = info->start;
- i = 0;
+ gtk_text_view_get_visible_rect (text_view, &visible_rect);
+ gtk_text_view_get_iter_at_location (text_view, &begin,
+ visible_rect.x, visible_rect.y);
+ gtk_text_view_get_iter_at_location (text_view, &end,
+ visible_rect.x,
+ visible_rect.y + visible_rect.height);
- while (i < info->lines_count)
+ /* The first step is to get line information about all the visible
+ * lines. We do this up front so that we can do it once to reduce many
+ * times the renderers need to walk through the buffer contents as that
+ * can be expensive.
+ */
+ get_alignment_modes (gutter, &needs_wrap_first, &needs_wrap_last);
+ gutter->lines = _gtk_source_lines_new (text_view,
+ &begin,
+ &end,
+ needs_wrap_first,
+ needs_wrap_last);
+
+ /* Draw the current-line highlight if necessary */
+ if (gtk_source_view_get_highlight_current_line (gutter->view))
{
- GtkTextIter end;
- GdkRectangle background_area;
- GtkSourceGutterRendererState state;
- gint pos;
- gint line_to_paint;
- gint renderer_num;
- GList *l;
-
- end = start;
-
- if (!gtk_text_iter_ends_line (&end))
- {
- /*
- * It turns out that gtk_text_iter_forward_to_line_end
- * is slower than jumping to the next line in the
- * btree index and then moving backwards a character.
- * We don't really care that we might be after the
- * newline breaking characters, since those are part
- * of the same line (rather than the next line).
- */
- if (gtk_text_iter_forward_line (&end))
- {
- gtk_text_iter_backward_char (&end);
- }
- }
-
- /* Possible improvement: if buffer and window coords have the
- * same unit, there are probably some possible performance
- * improvements by avoiding some buffer <-> window coords
- * conversions.
- */
- gtk_text_view_buffer_to_window_coords (view,
- gutter->window_type,
- 0,
- g_array_index (info->buffer_coords, gint, i),
- NULL,
- &pos);
-
- line_to_paint = g_array_index (info->line_numbers, gint, i);
-
- background_area.y = pos;
- background_area.height = g_array_index (info->line_heights, gint, i);
- background_area.x = 0;
-
- state = GTK_SOURCE_GUTTER_RENDERER_STATE_NORMAL;
-
- if (line_to_paint == cur_line)
- {
- state |= GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR;
- }
+ guint cursor_line;
- if (has_selection &&
- selection_start_line <= line_to_paint && line_to_paint <= selection_end_line)
- {
- state |= GTK_SOURCE_GUTTER_RENDERER_STATE_SELECTED;
- }
+ cursor_line = _gtk_source_lines_get_cursor_line (gutter->lines);
- for (l = gutter->renderers, renderer_num = 0;
- l != NULL;
- l = l->next, renderer_num++)
+ if (cursor_line >= gtk_source_lines_get_first (gutter->lines) &&
+ cursor_line <= gtk_source_lines_get_last (gutter->lines))
{
- Renderer *renderer;
- GdkRectangle cell_area;
- gint width;
- gint xpad;
- gint ypad;
-
- renderer = l->data;
- width = g_array_index (renderer_widths, gint, renderer_num);
-
- if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
- {
- g_assert_cmpint (width, ==, 0);
- continue;
- }
-
- gtk_source_gutter_renderer_get_padding (renderer->renderer,
- &xpad,
- &ypad);
-
- background_area.width = width;
-
- cell_area.y = background_area.y + ypad;
- cell_area.height = background_area.height - 2 * ypad;
-
- cell_area.x = background_area.x + xpad;
- cell_area.width = background_area.width - 2 * xpad;
-
- if (renderer->prelit >= 0 &&
- cell_area.y <= renderer->prelit && renderer->prelit <= cell_area.y +
cell_area.height)
- {
- state |= GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT;
- }
-
- gtk_source_gutter_renderer_query_data (renderer->renderer,
- &start,
- &end,
- state);
-
- cairo_save (cr);
-
- gdk_cairo_rectangle (cr, &background_area);
-
- cairo_clip (cr);
-
- /* Call render with correct area */
- gtk_source_gutter_renderer_draw (renderer->renderer,
- cr,
- &background_area,
- &cell_area,
- &start,
- &end,
- state);
-
- cairo_restore (cr);
-
- background_area.x += background_area.width;
- state &= ~GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT;
+ gint y;
+ gint height;
+
+ gtk_source_lines_get_line_yrange (gutter->lines,
+ cursor_line,
+ GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
+ &y,
+ &height);
+
+ gtk_style_context_save (view_context);
+ gtk_style_context_add_class (view_context, "current-line-number");
+
+ gtk_snapshot_render_background (snapshot,
+ view_context,
+ 0,
+ y,
+ gtk_widget_get_width (widget),
+ height);
+
+ gtk_style_context_restore (view_context);
}
-
- i++;
- gtk_text_iter_forward_line (&start);
}
-}
-static void
-end_draw (GtkSourceGutter *gutter)
-{
- GList *l;
+ gutter->is_drawing = TRUE;
- for (l = gutter->renderers; l != NULL; l = l->next)
+ /* Now let the renderers populate information about the lines that are
+ * to be rendered. They may need to go through line by line and add
+ * classes (GQuark) to the lines to be used when snapshoting. Since
+ * we've already calculated line information, this is relatively fast.
+ *
+ * We also only emit the ::query-data signal in the case that the
+ * renderer has not override then (*query_data) vfunc which saves quite
+ * a bit of signal overhead.
+ */
+ for (list = gutter->renderers; list; list = list->next)
{
- Renderer *renderer = l->data;
+ Renderer *renderer = list->data;
- if (gtk_source_gutter_renderer_get_visible (renderer->renderer))
- {
- gtk_source_gutter_renderer_end (renderer->renderer);
- }
+ _gtk_source_gutter_renderer_begin (renderer->renderer,
+ gutter->lines);
}
-}
-void
-_gtk_source_gutter_draw (GtkSourceGutter *gutter,
- GtkSourceView *view,
- cairo_t *cr)
-{
- GdkRectangle clip;
- GtkTextView *text_view;
- gint first_y_window_coord;
- gint last_y_window_coord;
- gint first_y_buffer_coord;
- gint last_y_buffer_coord;
- GArray *renderer_widths;
- LinesInfo *info;
- GtkStyleContext *style_context;
-
- if (!get_clip_rectangle (gutter, view, cr, &clip))
+ gtk_snapshot_push_clip (snapshot,
+ &GRAPHENE_RECT_INIT (0,
+ 0,
+ gtk_widget_get_width (widget),
+ gtk_widget_get_height (widget)));
+
+ /* Now let the renderers draw the content for each line. Because
+ * iterating a Linked-List is slower than iterating a series of line
+ * numbers, we make the renderer list the outter loop, and the
+ * snapshotting of lines (within the renderer) the inner loop as part
+ * of snapshot.
+ */
+ for (list = gutter->renderers; list; list = list->next)
{
- return;
- }
-
- gutter->is_drawing = TRUE;
-
- renderer_widths = g_array_new (FALSE, FALSE, sizeof (gint));
- calculate_gutter_size (gutter, renderer_widths);
-
- text_view = GTK_TEXT_VIEW (view);
+ Renderer *renderer = list->data;
- first_y_window_coord = clip.y;
- last_y_window_coord = first_y_window_coord + clip.height;
-
- /* get the extents of the line printing */
- gtk_text_view_window_to_buffer_coords (text_view,
- gutter->window_type,
- 0,
- first_y_window_coord,
- NULL,
- &first_y_buffer_coord);
-
- gtk_text_view_window_to_buffer_coords (text_view,
- gutter->window_type,
- 0,
- last_y_window_coord,
- NULL,
- &last_y_buffer_coord);
-
- info = get_lines_info (text_view,
- first_y_buffer_coord,
- last_y_buffer_coord);
-
- style_context = gtk_widget_get_style_context (GTK_WIDGET (view));
- gtk_style_context_save (style_context);
- apply_style (gutter, view, style_context, cr);
-
- begin_draw (gutter,
- text_view,
- renderer_widths,
- info,
- cr);
+ gtk_widget_snapshot_child (widget,
+ GTK_WIDGET (renderer->renderer),
+ snapshot);
+ }
- draw_cells (gutter,
- text_view,
- renderer_widths,
- info,
- cr);
+ gtk_snapshot_pop (snapshot);
- /* Allow to call queue_redraw() in ::end. */
+ /* Allow to call queue_redraw() in end. */
gutter->is_drawing = FALSE;
- end_draw (gutter);
-
- gtk_style_context_restore (style_context);
+ /* Now notify the renderers of completion */
+ for (list = gutter->renderers; list; list = list->next)
+ {
+ Renderer *renderer = list->data;
- g_array_free (renderer_widths, TRUE);
- lines_info_free (info);
+ _gtk_source_gutter_renderer_end (renderer->renderer);
+ }
}
static Renderer *
@@ -1202,94 +918,29 @@ renderer_at_x (GtkSourceGutter *gutter,
gint *start,
gint *width)
{
- GList *item;
- gint s;
- gint w;
-
- update_gutter_size (gutter);
-
- s = 0;
+ const GList *item;
for (item = gutter->renderers; item; item = g_list_next (item))
{
Renderer *renderer = item->data;
- gint xpad;
-
- if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
- {
- continue;
- }
-
- w = gtk_source_gutter_renderer_get_size (renderer->renderer);
+ GtkAllocation alloc;
- gtk_source_gutter_renderer_get_padding (renderer->renderer,
- &xpad,
- NULL);
+ gtk_widget_get_allocation (GTK_WIDGET (renderer->renderer),
+ &alloc);
- s += xpad;
-
- if (w > 0 && x >= s && x < s + w)
+ if (x >= alloc.x && x <= alloc.x + alloc.width)
{
- if (width)
- {
- *width = w;
- }
-
- if (start)
- {
- *start = s;
- }
-
return renderer;
}
-
- s += w + xpad;
}
return NULL;
}
-static void
-get_renderer_rect (GtkSourceGutter *gutter,
- Renderer *renderer,
- GtkTextIter *iter,
- gint line,
- GdkRectangle *rectangle,
- gint start)
-{
- gint y;
- gint ypad;
-
- rectangle->x = start;
-
- gtk_text_view_get_line_yrange (GTK_TEXT_VIEW (gutter->view),
- iter,
- &y,
- &rectangle->height);
-
- rectangle->width = gtk_source_gutter_renderer_get_size (renderer->renderer);
-
- gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (gutter->view),
- gutter->window_type,
- 0,
- y,
- NULL,
- &rectangle->y);
-
- gtk_source_gutter_renderer_get_padding (renderer->renderer,
- NULL,
- &ypad);
-
- rectangle->y += ypad;
- rectangle->height -= 2 * ypad;
-}
-
static gboolean
renderer_query_activatable (GtkSourceGutter *gutter,
Renderer *renderer,
GdkEvent *event,
- gint x,
- gint y,
GtkTextIter *line_iter,
GdkRectangle *rect,
gint start)
@@ -1297,17 +948,24 @@ renderer_query_activatable (GtkSourceGutter *gutter,
gint y_buf;
gint yline;
GtkTextIter iter;
- GdkRectangle r;
+ GdkRectangle r = {0};
+ gdouble x;
+ gdouble y;
if (!renderer)
{
return FALSE;
}
+ if (!gdk_event_get_coords (event, &x, &y))
+ {
+ return FALSE;
+ }
+
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (gutter->view),
- gutter->window_type,
- x,
- y,
+ GTK_TEXT_WINDOW_WIDGET,
+ (gint)x,
+ (gint)y,
NULL,
&y_buf);
@@ -1321,7 +979,7 @@ renderer_query_activatable (GtkSourceGutter *gutter,
return FALSE;
}
- get_renderer_rect (gutter, renderer, &iter, yline, &r, start);
+ //get_renderer_rect (gutter, renderer, &iter, yline, &r, start);
if (line_iter)
{
@@ -1346,21 +1004,18 @@ renderer_query_activatable (GtkSourceGutter *gutter,
static gboolean
redraw_for_window (GtkSourceGutter *gutter,
- GdkEvent *event,
- gboolean act_on_window,
- gint x,
- gint y)
+ gboolean act_on_window,
+ gint x,
+ gint y)
{
+ gtk_widget_queue_draw (GTK_WIDGET (gutter));
+
+#if 0
Renderer *at_x = NULL;
gint start = 0;
GList *item;
gboolean redraw;
- if (event->any.window != get_window (gutter) && act_on_window)
- {
- return FALSE;
- }
-
if (act_on_window)
{
at_x = renderer_at_x (gutter, x, &start, NULL);
@@ -1385,7 +1040,6 @@ redraw_for_window (GtkSourceGutter *gutter,
}
else if (renderer_query_activatable (gutter,
renderer,
- event,
x,
y,
NULL,
@@ -1407,74 +1061,71 @@ redraw_for_window (GtkSourceGutter *gutter,
{
do_redraw (gutter);
}
+#endif
return FALSE;
}
-static gboolean
-on_view_motion_notify_event (GtkSourceView *view,
- GdkEventMotion *event,
- GtkSourceGutter *gutter)
+static void
+on_gutter_motion_enter (GtkSourceGutter *gutter,
+ gdouble x,
+ gdouble y,
+ GdkCrossingMode mode,
+ GdkNotifyType notify_type,
+ GtkEventControllerMotion *motion)
{
- return redraw_for_window (gutter,
- (GdkEvent *)event,
- TRUE,
- (gint)event->x,
- (gint)event->y);
+ redraw_for_window (gutter, TRUE, x, y);
}
-static gboolean
-on_view_enter_notify_event (GtkSourceView *view,
- GdkEventCrossing *event,
- GtkSourceGutter *gutter)
+static void
+on_gutter_motion (GtkSourceGutter *gutter,
+ gdouble x,
+ gdouble y,
+ GtkEventControllerMotion *motion)
+
{
- return redraw_for_window (gutter,
- (GdkEvent *)event,
- TRUE,
- (gint)event->x,
- (gint)event->y);
+ redraw_for_window (gutter, TRUE, x, y);
}
-static gboolean
-on_view_leave_notify_event (GtkSourceView *view,
- GdkEventCrossing *event,
- GtkSourceGutter *gutter)
+static void
+on_gutter_motion_leave (GtkSourceGutter *gutter,
+ GdkCrossingMode mode,
+ GdkNotifyType notify_type,
+ GtkEventControllerMotion *motion)
{
- return redraw_for_window (gutter,
- (GdkEvent *)event,
- FALSE,
- (gint)event->x,
- (gint)event->y);
+ redraw_for_window (gutter, FALSE, -1, -1);
}
-static gboolean
-on_view_button_press_event (GtkSourceView *view,
- GdkEventButton *event,
- GtkSourceGutter *gutter)
+static void
+on_gutter_pressed_cb (GtkSourceGutter *gutter,
+ gint n_presses,
+ gdouble x,
+ gdouble y,
+ GtkGestureClick *click)
{
+
Renderer *renderer;
GtkTextIter line_iter;
gint start = -1;
GdkRectangle rect;
+ const GdkEvent *event;
- if (event->window != get_window (gutter))
- {
- return FALSE;
- }
+ g_assert (GTK_SOURCE_IS_GUTTER (gutter));
+ g_assert (GTK_IS_GESTURE_CLICK (click));
- if (event->type != GDK_BUTTON_PRESS)
+ event = gtk_gesture_get_last_event (GTK_GESTURE (click), NULL);
+
+ if (event == NULL)
{
- return FALSE;
+ return;
}
/* Check cell renderer */
- renderer = renderer_at_x (gutter, event->x, &start, NULL);
+ renderer = renderer_at_x (gutter, x, &start, NULL);
if (renderer_query_activatable (gutter,
renderer,
(GdkEvent *)event,
- (gint)event->x,
- (gint)event->y,
&line_iter,
&rect,
start))
@@ -1486,111 +1137,22 @@ on_view_button_press_event (GtkSourceView *view,
do_redraw (gutter);
- return TRUE;
+ gtk_gesture_set_state (GTK_GESTURE (click),
+ GTK_EVENT_SEQUENCE_CLAIMED);
}
-
- return FALSE;
-}
-
-static gboolean
-on_view_query_tooltip (GtkSourceView *view,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip,
- GtkSourceGutter *gutter)
-{
- GtkTextView *text_view = GTK_TEXT_VIEW (view);
- Renderer *renderer;
- gint start = 0;
- gint width = 0;
- gint y_buf;
- gint yline;
- GtkTextIter line_iter;
- GdkRectangle rect;
-
- if (keyboard_mode)
- {
- return FALSE;
- }
-
- /* Check cell renderer */
- renderer = renderer_at_x (gutter, x, &start, &width);
-
- if (!renderer)
- {
- return FALSE;
- }
-
- gtk_text_view_window_to_buffer_coords (text_view,
- gutter->window_type,
- x, y,
- NULL, &y_buf);
-
- gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view),
- &line_iter,
- y_buf,
- &yline);
-
- if (yline > y_buf)
- {
- return FALSE;
- }
-
- get_renderer_rect (gutter,
- renderer,
- &line_iter,
- yline,
- &rect,
- start);
-
- return gtk_source_gutter_renderer_query_tooltip (renderer->renderer,
- &line_iter,
- &rect,
- x,
- y,
- tooltip);
}
static void
on_view_style_updated (GtkSourceView *view,
GtkSourceGutter *gutter)
{
- gtk_source_gutter_queue_draw (gutter);
+ do_redraw (gutter);
}
-/**
- * gtk_source_gutter_get_renderer_at_pos:
- * @gutter: A #GtkSourceGutter.
- * @x: The x position to get identified.
- * @y: The y position to get identified.
- *
- * Finds the #GtkSourceGutterRenderer at (x, y).
- *
- * Returns: (nullable) (transfer none): the renderer at (x, y) or %NULL.
- */
-/* TODO: better document this function. The (x,y) position is different from
- * the position passed to gtk_source_gutter_insert() and
- * gtk_source_gutter_reorder(). The (x,y) coordinate can come from a click
- * event, for example? Is the (x,y) a coordinate of the Gutter's GdkWindow?
- * Where is the (0,0)? And so on.
- * Also, this function doesn't seem to be used.
- */
-GtkSourceGutterRenderer *
-gtk_source_gutter_get_renderer_at_pos (GtkSourceGutter *gutter,
- gint x,
- gint y)
+GtkSourceLines *
+_gtk_source_gutter_get_lines (GtkSourceGutter *gutter)
{
- Renderer *renderer;
-
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), NULL);
- renderer = renderer_at_x (gutter, x, NULL, NULL);
-
- if (renderer == NULL)
- {
- return NULL;
- }
-
- return renderer->renderer;
+ return gutter->lines;
}
diff --git a/gtksourceview/gtksourcegutter.h b/gtksourceview/gtksourcegutter.h
index 3fdf5b44..d25a1769 100644
--- a/gtksourceview/gtksourcegutter.h
+++ b/gtksourceview/gtksourcegutter.h
@@ -33,28 +33,17 @@ G_BEGIN_DECLS
#define GTK_SOURCE_TYPE_GUTTER (gtk_source_gutter_get_type())
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_SOURCE, GUTTER, GObject)
+G_DECLARE_FINAL_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_SOURCE, GUTTER, GtkContainer)
GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceView *gtk_source_gutter_get_view (GtkSourceGutter *gutter);
-GTK_SOURCE_AVAILABLE_IN_3_24
-GtkTextWindowType gtk_source_gutter_get_window_type (GtkSourceGutter *gutter);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_gutter_insert (GtkSourceGutter *gutter,
- GtkSourceGutterRenderer *renderer,
- gint position);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_reorder (GtkSourceGutter *gutter,
- GtkSourceGutterRenderer *renderer,
- gint position);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_remove (GtkSourceGutter *gutter,
- GtkSourceGutterRenderer *renderer);
+GtkSourceView *gtk_source_gutter_get_view (GtkSourceGutter *gutter);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_queue_draw (GtkSourceGutter *gutter);
+gboolean gtk_source_gutter_insert (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer,
+ gint position);
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_get_renderer_at_pos (GtkSourceGutter *gutter,
- gint x,
- gint y);
+void gtk_source_gutter_reorder (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer,
+ gint position);
G_END_DECLS
diff --git a/gtksourceview/gtksourcegutterrenderer-private.h b/gtksourceview/gtksourcegutterrenderer-private.h
index 790fa6df..bff23843 100644
--- a/gtksourceview/gtksourcegutterrenderer-private.h
+++ b/gtksourceview/gtksourcegutterrenderer-private.h
@@ -21,13 +21,22 @@
#pragma once
#include <gtk/gtk.h>
+
#include "gtksourcetypes.h"
G_BEGIN_DECLS
G_GNUC_INTERNAL
-void _gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
- GtkTextView *view,
- GtkTextWindowType window_type);
+void _gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
+ GtkSourceView *view);
+G_GNUC_INTERNAL
+void _gtk_source_gutter_renderer_begin (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines);
+G_GNUC_INTERNAL
+void _gtk_source_gutter_renderer_snapshot (GtkSourceGutterRenderer *renderer,
+ GtkSnapshot *snapshot,
+ GtkSourceLines *lines);
+G_GNUC_INTERNAL
+void _gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer);
G_END_DECLS
diff --git a/gtksourceview/gtksourcegutterrenderer.c b/gtksourceview/gtksourcegutterrenderer.c
index bcc6e5dc..751c3948 100644
--- a/gtksourceview/gtksourcegutterrenderer.c
+++ b/gtksourceview/gtksourcegutterrenderer.c
@@ -20,8 +20,12 @@
#include "config.h"
+#include "gtksourcebuffer.h"
+#include "gtksourcegutter.h"
+#include "gtksourcegutter-private.h"
#include "gtksourcegutterrenderer.h"
#include "gtksourcegutterrenderer-private.h"
+#include "gtksourcelines.h"
#include "gtksourcestylescheme.h"
#include "gtksourceview.h"
#include "gtksource-enumtypes.h"
@@ -39,9 +43,11 @@
* this case, #GtkSourceGutterRendererAlignmentMode controls the alignment of
* the cell.
*
- * The gutter renderer must announce its #GtkSourceGutterRenderer:size. The
- * height is determined by the text view height. The width must be determined by
- * the gutter renderer. The width generally takes into account the entire text
+ * The gutter renderer is a #GtkWidget and is measured using the normal widget
+ * measurement facilities. The width of the gutter will be determined by the
+ * measurements of the gutter renderers.
+ *
+ * The width of a gutter renderer generally takes into account the entire text
* buffer. For instance, to display the line numbers, if the buffer contains 100
* lines, the gutter renderer will always set its width such as three digits can
* be printed, even if only the first 20 lines are shown. Another strategy is to
@@ -51,122 +57,83 @@
* into account the text buffer to announce its width. It only depends on the
* icons size displayed in the gutter column.
*
- * An horizontal and vertical padding can be added with
- * gtk_source_gutter_renderer_set_padding(). The total width of a gutter
- * renderer is its size (#GtkSourceGutterRenderer:size) plus two times the
- * horizontal padding (#GtkSourceGutterRenderer:xpad).
- *
* When the available size to render a cell is greater than the required size to
* render the cell contents, the cell contents can be aligned horizontally and
* vertically with gtk_source_gutter_renderer_set_alignment().
*
- * The cells rendering occurs in three phases:
- * - begin: the gtk_source_gutter_renderer_begin() function is called when some
- * cells need to be redrawn. It provides the associated region of the
- * #GtkTextBuffer. The cells need to be redrawn when the #GtkTextView is
- * scrolled, or when the state of the cells change (see
- * #GtkSourceGutterRendererState).
- * - draw: gtk_source_gutter_renderer_draw() is called for each cell that needs
- * to be drawn.
- * - end: finally, gtk_source_gutter_renderer_end() is called.
+ * The cells rendering occurs using gtk_widget_snapshot(). Implementations
+ * should use gtk_source_gutter_renderer_get_lines() to retrieve information
+ * about the lines to be rendered. To help with aligning content which takes
+ * into account the padding and alignment of a cell, implementations may call
+ * gtk_source_gutter_renderer_align_cell() for a given line number with the
+ * width and height measurement of the content they width to render.
*/
-enum
+struct _GtkSourceGutterRendererPrivate
{
- ACTIVATE,
- QUEUE_DRAW,
- QUERY_TOOLTIP,
- QUERY_DATA,
- QUERY_ACTIVATABLE,
- N_SIGNALS
-};
-
-typedef struct
-{
- GtkTextView *view;
- GtkTextBuffer *buffer;
- GtkTextWindowType window_type;
-
- gint xpad;
- gint ypad;
+ GtkSourceGutter *gutter;
+ GtkSourceView *view;
+ GtkSourceBuffer *buffer;
+ GtkSourceLines *lines;
gfloat xalign;
gfloat yalign;
- gint size;
+ gint xpad;
+ gint ypad;
GtkSourceGutterRendererAlignmentMode alignment_mode;
- GdkRGBA background_color;
-
- guint background_set : 1;
guint visible : 1;
-} GtkSourceGutterRendererPrivate;
-
-static guint signals[N_SIGNALS];
+};
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkSourceGutterRenderer, gtk_source_gutter_renderer,
G_TYPE_INITIALLY_UNOWNED)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkSourceGutterRenderer, gtk_source_gutter_renderer, GTK_TYPE_WIDGET)
enum
{
PROP_0,
- PROP_VISIBLE,
- PROP_XPAD,
- PROP_YPAD,
+ PROP_ALIGNMENT_MODE,
+ PROP_LINES,
+ PROP_VIEW,
PROP_XALIGN,
+ PROP_XPAD,
PROP_YALIGN,
- PROP_VIEW,
- PROP_ALIGNMENT_MODE,
- PROP_WINDOW_TYPE,
- PROP_SIZE,
- PROP_BACKGROUND_RGBA,
- PROP_BACKGROUND_SET
+ PROP_YPAD,
+ N_PROPS
};
-static void
-set_buffer (GtkSourceGutterRenderer *renderer,
- GtkTextBuffer *buffer)
+enum
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- if (priv->buffer != NULL)
- {
- g_object_remove_weak_pointer (G_OBJECT (priv->buffer),
- (gpointer) &priv->buffer);
- }
-
- if (buffer != NULL)
- {
- g_object_add_weak_pointer (G_OBJECT (buffer),
- (gpointer) &priv->buffer);
- }
+ ACTIVATE,
+ QUERY_ACTIVATABLE,
+ QUERY_DATA,
+ N_SIGNALS
+};
- priv->buffer = buffer;
-}
+static GParamSpec *properties[N_PROPS];
+static guint signals[N_SIGNALS];
static void
-emit_buffer_changed (GtkTextView *view,
+emit_buffer_changed (GtkSourceView *view,
GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
- GtkTextBuffer* buffer;
+ GtkSourceBuffer *buffer;
+ GtkSourceBuffer *old_buffer;
- buffer = gtk_text_view_get_buffer (view);
+ old_buffer = renderer->priv->buffer;
+ buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
- if (buffer != priv->buffer)
+ if (buffer == old_buffer)
{
- if (GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_buffer)
- {
- GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_buffer (renderer,
- priv->buffer);
- }
-
- set_buffer (renderer, buffer);
+ return;
}
+
+ g_set_weak_pointer (&renderer->priv->buffer, buffer);
+ GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_buffer (renderer, old_buffer);
}
static void
-on_buffer_changed (GtkTextView *view,
+on_buffer_changed (GtkSourceView *view,
GParamSpec *spec,
GtkSourceGutterRenderer *renderer)
{
@@ -174,23 +141,27 @@ on_buffer_changed (GtkTextView *view,
}
static void
-renderer_change_view_impl (GtkSourceGutterRenderer *renderer,
- GtkTextView *old_view)
+gtk_source_gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
+ GtkSourceBuffer *buffer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+}
- if (old_view)
+static void
+gtk_source_gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
+ GtkSourceView *old_view)
+{
+ if (old_view != NULL)
{
g_signal_handlers_disconnect_by_func (old_view,
G_CALLBACK (on_buffer_changed),
renderer);
}
- if (priv->view)
+ if (renderer->priv->view != NULL)
{
- emit_buffer_changed (priv->view, renderer);
+ emit_buffer_changed (renderer->priv->view, renderer);
- g_signal_connect (priv->view,
+ g_signal_connect (renderer->priv->view,
"notify::buffer",
G_CALLBACK (on_buffer_changed),
renderer);
@@ -198,196 +169,96 @@ renderer_change_view_impl (GtkSourceGutterRenderer *renderer,
}
static void
-gtk_source_gutter_renderer_dispose (GObject *object)
+gtk_source_gutter_renderer_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
- GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (object);
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- set_buffer (renderer, NULL);
+ GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
+ GtkSourceGutterRendererClass *klass = GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (widget);
+ GtkSourceGutterRendererAlignmentMode mode = renderer->priv->alignment_mode;
+ GtkSourceLines *lines = renderer->priv->lines;
+ guint first;
+ guint last;
+ guint line;
+ gint y;
+ gint h;
- if (priv->view)
+ if (lines == NULL || klass->snapshot_line == NULL)
{
- _gtk_source_gutter_renderer_set_view (renderer,
- NULL,
- GTK_TEXT_WINDOW_PRIVATE);
+ return;
}
- G_OBJECT_CLASS (gtk_source_gutter_renderer_parent_class)->dispose (object);
-}
-
-static void
-set_visible (GtkSourceGutterRenderer *renderer,
- gboolean visible)
-{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- visible = visible != FALSE;
+ first = gtk_source_lines_get_first (lines);
+ last = gtk_source_lines_get_last (lines);
- if (priv->visible != visible)
+ for (line = first; line <= last; line++)
{
- priv->visible = visible;
- g_object_notify (G_OBJECT (renderer), "visible");
+ gtk_source_lines_get_line_yrange (lines, line, mode, &y, &h);
- gtk_source_gutter_renderer_queue_draw (renderer);
+ klass->query_data (renderer, lines, line);
+ klass->snapshot_line (renderer, snapshot, lines, line);
}
}
-static gboolean
-set_padding (GtkSourceGutterRenderer *renderer,
- gint *field,
- gint padding,
- const gchar *name)
-{
- if (*field == padding || padding < 0)
- {
- return FALSE;
- }
-
- *field = padding;
- g_object_notify (G_OBJECT (renderer), name);
-
- return TRUE;
-}
-
-static gboolean
-set_xpad (GtkSourceGutterRenderer *renderer,
- gint xpad)
+static void
+gtk_source_gutter_renderer_dispose (GObject *object)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+ GtkSourceGutterRenderer *renderer;
- return set_padding (renderer,
- &priv->xpad,
- xpad,
- "xpad");
-}
+ renderer = GTK_SOURCE_GUTTER_RENDERER (object);
-static gboolean
-set_ypad (GtkSourceGutterRenderer *renderer,
- gint ypad)
-{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+ g_clear_weak_pointer (&renderer->priv->buffer);
- return set_padding (renderer,
- &priv->ypad,
- ypad,
- "ypad");
-}
-
-static gboolean
-set_alignment (GtkSourceGutterRenderer *renderer,
- gfloat *field,
- gfloat align,
- const gchar *name,
- gboolean emit)
-{
- if (*field == align || align < 0)
+ if (renderer->priv->view != NULL)
{
- return FALSE;
+ _gtk_source_gutter_renderer_set_view (renderer, NULL);
}
- *field = align;
- g_object_notify (G_OBJECT (renderer), name);
-
- if (emit)
- {
- gtk_source_gutter_renderer_queue_draw (renderer);
- }
-
- return TRUE;
+ G_OBJECT_CLASS (gtk_source_gutter_renderer_parent_class)->dispose (object);
}
-static gboolean
-set_xalign (GtkSourceGutterRenderer *renderer,
- gfloat xalign,
- gboolean emit)
+static void
+gtk_source_gutter_renderer_root (GtkWidget *widget)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+ GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
+ GtkWidget *gutter;
- return set_alignment (renderer,
- &priv->xalign,
- xalign,
- "xalign",
- emit);
-}
+ GTK_WIDGET_CLASS (gtk_source_gutter_renderer_parent_class)->root (widget);
-static gboolean
-set_yalign (GtkSourceGutterRenderer *renderer,
- gfloat yalign,
- gboolean emit)
-{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+ gutter = gtk_widget_get_ancestor (widget, GTK_SOURCE_TYPE_GUTTER);
- return set_alignment (renderer,
- &priv->yalign,
- yalign,
- "yalign",
- emit);
+ if (GTK_SOURCE_IS_GUTTER (gutter))
+ {
+ renderer->priv->gutter = GTK_SOURCE_GUTTER (gutter);
+ }
}
static void
-set_alignment_mode (GtkSourceGutterRenderer *renderer,
- GtkSourceGutterRendererAlignmentMode mode)
+gtk_source_gutter_renderer_unroot (GtkWidget *widget)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+ GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
- if (priv->alignment_mode == mode)
- {
- return;
- }
-
- priv->alignment_mode = mode;
- g_object_notify (G_OBJECT (renderer), "alignment-mode");
+ renderer->priv->gutter = NULL;
- gtk_source_gutter_renderer_queue_draw (renderer);
+ GTK_WIDGET_CLASS (gtk_source_gutter_renderer_parent_class)->unroot (widget);
}
static void
-set_size (GtkSourceGutterRenderer *renderer,
- gint value)
+gtk_source_gutter_renderer_real_begin (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- if (priv->size == value)
- {
- return;
- }
-
- priv->size = value;
- g_object_notify (G_OBJECT (renderer), "size");
}
static void
-set_background_color_set (GtkSourceGutterRenderer *renderer,
- gboolean isset)
+gtk_source_gutter_renderer_real_end (GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- isset = (isset != FALSE);
-
- if (isset != priv->background_set)
- {
- priv->background_set = isset;
- gtk_source_gutter_renderer_queue_draw (renderer);
- }
}
static void
-set_background_color (GtkSourceGutterRenderer *renderer,
- const GdkRGBA *color)
+gtk_source_gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines,
+ guint line)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- if (!color)
- {
- set_background_color_set (renderer, FALSE);
- }
- else
- {
- priv->background_color = *color;
- priv->background_set = TRUE;
-
- gtk_source_gutter_renderer_queue_draw (renderer);
- }
+ g_signal_emit (renderer, signals[QUERY_DATA], 0, lines, line);
}
static void
@@ -397,45 +268,29 @@ gtk_source_gutter_renderer_set_property (GObject *object,
GParamSpec *pspec)
{
GtkSourceGutterRenderer *self = GTK_SOURCE_GUTTER_RENDERER (object);
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (self);
switch (prop_id)
{
- case PROP_VISIBLE:
- set_visible (self, g_value_get_boolean (value));
- break;
case PROP_XPAD:
- set_xpad (self, g_value_get_int (value));
+ gtk_source_gutter_renderer_set_xpad (self, g_value_get_int (value));
break;
+
case PROP_YPAD:
- set_ypad (self, g_value_get_int (value));
+ gtk_source_gutter_renderer_set_ypad (self, g_value_get_int (value));
break;
+
case PROP_XALIGN:
- set_xalign (self, g_value_get_float (value), TRUE);
+ gtk_source_gutter_renderer_set_xalign (self, g_value_get_float (value));
break;
+
case PROP_YALIGN:
- set_yalign (self, g_value_get_float (value), TRUE);
+ gtk_source_gutter_renderer_set_yalign (self, g_value_get_float (value));
break;
+
case PROP_ALIGNMENT_MODE:
- set_alignment_mode (self, g_value_get_enum (value));
- break;
- case PROP_VIEW:
- priv->view = g_value_get_object (value);
- break;
- case PROP_WINDOW_TYPE:
- priv->window_type = g_value_get_enum (value);
- break;
- case PROP_SIZE:
- set_size (self, g_value_get_int (value));
- break;
- case PROP_BACKGROUND_RGBA:
- set_background_color (self,
- g_value_get_boxed (value));
- break;
- case PROP_BACKGROUND_SET:
- set_background_color_set (self,
- g_value_get_boolean (value));
+ gtk_source_gutter_renderer_set_alignment_mode (self, g_value_get_enum (value));
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -449,146 +304,104 @@ gtk_source_gutter_renderer_get_property (GObject *object,
GParamSpec *pspec)
{
GtkSourceGutterRenderer *self = GTK_SOURCE_GUTTER_RENDERER (object);
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (self);
switch (prop_id)
{
- case PROP_VISIBLE:
- g_value_set_boolean (value, priv->visible);
- break;
- case PROP_XPAD:
- g_value_set_int (value, priv->xpad);
- break;
- case PROP_YPAD:
- g_value_set_int (value, priv->ypad);
+ case PROP_LINES:
+ g_value_set_object (value, self->priv->lines);
break;
+
case PROP_XALIGN:
- g_value_set_float (value, priv->xalign);
+ g_value_set_float (value, self->priv->xalign);
break;
+
+ case PROP_XPAD:
+ g_value_set_int (value, self->priv->xpad);
+ break;
+
case PROP_YALIGN:
- g_value_set_float (value, priv->yalign);
+ g_value_set_float (value, self->priv->yalign);
break;
+
+ case PROP_YPAD:
+ g_value_set_int (value, self->priv->ypad);
+ break;
+
case PROP_VIEW:
- g_value_set_object (value, priv->view);
+ g_value_set_object (value, self->priv->view);
break;
+
case PROP_ALIGNMENT_MODE:
- g_value_set_enum (value, priv->alignment_mode);
- break;
- case PROP_WINDOW_TYPE:
- g_value_set_enum (value, priv->window_type);
- break;
- case PROP_SIZE:
- g_value_set_int (value, priv->size);
- break;
- case PROP_BACKGROUND_RGBA:
- g_value_set_boxed (value, &priv->background_color);
- break;
- case PROP_BACKGROUND_SET:
- g_value_set_boolean (value, priv->background_set);
+ g_value_set_enum (value, self->priv->alignment_mode);
break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
-static void
-renderer_draw_impl (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state)
-{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- if (priv->background_set)
- {
- cairo_save (cr);
- gdk_cairo_rectangle (cr, background_area);
- gdk_cairo_set_source_rgba (cr, &priv->background_color);
- cairo_fill (cr);
- cairo_restore (cr);
- }
- else if ((state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) != 0 &&
- GTK_SOURCE_IS_VIEW (priv->view) &&
- gtk_source_view_get_highlight_current_line (GTK_SOURCE_VIEW (priv->view)))
- {
- GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (GTK_WIDGET (priv->view));
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, "current-line-number");
-
- gtk_render_background (context,
- cr,
- background_area->x,
- background_area->y,
- background_area->width,
- background_area->height);
-
- gtk_style_context_restore (context);
- }
-}
-
static void
gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = gtk_source_gutter_renderer_dispose;
-
object_class->get_property = gtk_source_gutter_renderer_get_property;
object_class->set_property = gtk_source_gutter_renderer_set_property;
- klass->draw = renderer_draw_impl;
- klass->change_view = renderer_change_view_impl;
+ widget_class->root = gtk_source_gutter_renderer_root;
+ widget_class->unroot = gtk_source_gutter_renderer_unroot;
+ widget_class->snapshot = gtk_source_gutter_renderer_snapshot;
+
+ klass->begin = gtk_source_gutter_renderer_real_begin;
+ klass->end = gtk_source_gutter_renderer_real_end;
+ klass->change_buffer = gtk_source_gutter_renderer_change_buffer;
+ klass->change_view = gtk_source_gutter_renderer_change_view;
+ klass->query_data = gtk_source_gutter_renderer_query_data;
/**
- * GtkSourceGutterRenderer:visible:
+ * GtkSourceGutterRenderer:lines:
*
- * The visibility of the renderer.
- *
- **/
- g_object_class_install_property (object_class,
- PROP_VISIBLE,
- g_param_spec_boolean ("visible",
- "Visible",
- "Visible",
- TRUE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ * The "lines" property contains information about the lines to be
+ * rendered. It should be used by #GtkSourceGutterRenderer
+ * implementations from gtk_widget_snapshot().
+ */
+ properties[PROP_LINES] =
+ g_param_spec_object ("lines",
+ "Lines",
+ "Information about the lines to render",
+ GTK_SOURCE_TYPE_LINES,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
/**
* GtkSourceGutterRenderer:xpad:
*
* The left and right padding of the renderer.
*/
- g_object_class_install_property (object_class,
- PROP_XPAD,
- g_param_spec_int ("xpad",
- "X Padding",
- "The x-padding",
- -1,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ properties[PROP_XPAD] =
+ g_param_spec_int ("xpad",
+ "X Padding",
+ "The x-padding",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* GtkSourceGutterRenderer:ypad:
*
* The top and bottom padding of the renderer.
*/
- g_object_class_install_property (object_class,
- PROP_YPAD,
- g_param_spec_int ("ypad",
- "Y Padding",
- "The y-padding",
- -1,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ properties[PROP_YPAD] =
+ g_param_spec_int ("ypad",
+ "Y Padding",
+ "The y-padding",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* GtkSourceGutterRenderer:xalign:
@@ -597,15 +410,14 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
* alignment. 1 for a right alignment. And 0.5 for centering the cells.
* A value lower than 0 doesn't modify the alignment.
*/
- g_object_class_install_property (object_class,
- PROP_XALIGN,
- g_param_spec_float ("xalign",
- "X Alignment",
- "The x-alignment",
- -1,
- 1,
- 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ properties[PROP_XALIGN] =
+ g_param_spec_float ("xalign",
+ "X Alignment",
+ "The x-alignment",
+ 0.0,
+ 1.0,
+ 0.0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
* GtkSourceGutterRenderer:yalign:
@@ -614,15 +426,46 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
* alignment. 1 for a bottom alignment. And 0.5 for centering the cells.
* A value lower than 0 doesn't modify the alignment.
*/
- g_object_class_install_property (object_class,
- PROP_YALIGN,
- g_param_spec_float ("yalign",
- "Y Alignment",
- "The y-alignment",
- -1,
- 1,
- 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ properties[PROP_YALIGN] =
+ g_param_spec_float ("yalign",
+ "Y Alignment",
+ "The y-alignment",
+ 0.0,
+ 1.0,
+ 0.0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+
+ /**
+ * GtkSourceGutterRenderer:view:
+ *
+ * The view on which the renderer is placed.
+ **/
+ properties[PROP_VIEW] =
+ g_param_spec_object ("view",
+ "The View",
+ "The view",
+ GTK_TYPE_TEXT_VIEW,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ /**
+ * GtkSourceGutterRenderer:alignment-mode:
+ *
+ * The alignment mode of the renderer. This can be used to indicate
+ * that in the case a cell spans multiple lines (due to text wrapping)
+ * the alignment should work on either the full cell, the first line
+ * or the last line.
+ *
+ **/
+ properties[PROP_ALIGNMENT_MODE] =
+ g_param_spec_enum ("alignment-mode",
+ "Alignment Mode",
+ "The alignment mode",
+ GTK_SOURCE_TYPE_GUTTER_RENDERER_ALIGNMENT_MODE,
+ GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
/**
* GtkSourceGutterRenderer::activate:
@@ -633,105 +476,22 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
*
* The ::activate signal is emitted when the renderer is
* activated.
- *
*/
signals[ACTIVATE] =
g_signal_new ("activate",
- G_TYPE_FROM_CLASS (object_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkSourceGutterRendererClass, activate),
NULL, NULL,
- _gtk_source_marshal_VOID__BOXED_BOXED_BOXED,
+ _gtk_source_marshal_VOID__BOXED_BOXED_OBJECT,
G_TYPE_NONE,
3,
- GTK_TYPE_TEXT_ITER,
- GDK_TYPE_RECTANGLE,
+ GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
+ GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE,
GDK_TYPE_EVENT);
g_signal_set_va_marshaller (signals[ACTIVATE],
G_TYPE_FROM_CLASS (klass),
- _gtk_source_marshal_VOID__BOXED_BOXED_BOXEDv);
-
- /**
- * GtkSourceGutterRenderer::queue-draw:
- * @renderer: the #GtkSourceGutterRenderer who emits the signal
- *
- * The ::queue-draw signal is emitted when the renderer needs
- * to be redrawn. Use gtk_source_gutter_renderer_queue_draw()
- * to emit this signal from an implementation of the
- * #GtkSourceGutterRenderer interface.
- */
- signals[QUEUE_DRAW] =
- g_signal_new ("queue-draw",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkSourceGutterRendererClass, queue_draw),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- g_signal_set_va_marshaller (signals[QUEUE_DRAW],
- G_TYPE_FROM_CLASS (klass),
- g_cclosure_marshal_VOID__VOIDv);
-
- /**
- * GtkSourceGutterRenderer::query-tooltip:
- * @renderer: the #GtkSourceGutterRenderer who emits the signal
- * @iter: a #GtkTextIter
- * @area: a #GdkRectangle
- * @x: the x position (in window coordinates)
- * @y: the y position (in window coordinates)
- * @tooltip: a #GtkTooltip
- *
- * The ::query-tooltip signal is emitted when the renderer can
- * show a tooltip.
- *
- */
- signals[QUERY_TOOLTIP] =
- g_signal_new ("query-tooltip",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkSourceGutterRendererClass, query_tooltip),
- g_signal_accumulator_true_handled,
- NULL,
- _gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT,
- G_TYPE_BOOLEAN,
- 5,
- GTK_TYPE_TEXT_ITER,
- GDK_TYPE_RECTANGLE,
- G_TYPE_INT,
- G_TYPE_INT,
- GTK_TYPE_TOOLTIP);
- g_signal_set_va_marshaller (signals[QUERY_TOOLTIP],
- G_TYPE_FROM_CLASS (klass),
- _gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECTv);
-
- /**
- * GtkSourceGutterRenderer::query-data:
- * @renderer: the #GtkSourceGutterRenderer who emits the signal
- * @start: a #GtkTextIter
- * @end: a #GtkTextIter
- * @state: the renderer state
- *
- * The ::query-data signal is emitted when the renderer needs
- * to be filled with data just before a cell is drawn. This can
- * be used by general renderer implementations to allow render
- * data to be filled in externally.
- *
- */
- signals[QUERY_DATA] =
- g_signal_new ("query-data",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkSourceGutterRendererClass, query_data),
- NULL, NULL,
- _gtk_source_marshal_VOID__BOXED_BOXED_FLAGS,
- G_TYPE_NONE,
- 3,
- GTK_TYPE_TEXT_ITER,
- GTK_TYPE_TEXT_ITER,
- GTK_SOURCE_TYPE_GUTTER_RENDERER_STATE);
- g_signal_set_va_marshaller (signals[QUERY_DATA],
- G_TYPE_FROM_CLASS (klass),
- _gtk_source_marshal_VOID__BOXED_BOXED_FLAGSv);
+ _gtk_source_marshal_VOID__BOXED_BOXED_OBJECTv);
/**
* GtkSourceGutterRenderer::query-activatable:
@@ -742,214 +502,46 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
*
* The ::query-activatable signal is emitted when the renderer
* can possibly be activated.
- *
*/
signals[QUERY_ACTIVATABLE] =
g_signal_new ("query-activatable",
- G_TYPE_FROM_CLASS (object_class),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkSourceGutterRendererClass, query_activatable),
g_signal_accumulator_true_handled,
NULL,
- _gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXED,
+ _gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECT,
G_TYPE_BOOLEAN,
3,
- GTK_TYPE_TEXT_ITER,
- GDK_TYPE_RECTANGLE,
+ GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
+ GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE,
GDK_TYPE_EVENT);
g_signal_set_va_marshaller (signals[QUERY_ACTIVATABLE],
G_TYPE_FROM_CLASS (klass),
- _gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXEDv);
-
- /**
- * GtkSourceGutterRenderer:view:
- *
- * The view on which the renderer is placed.
- *
- **/
- g_object_class_install_property (object_class,
- PROP_VIEW,
- g_param_spec_object ("view",
- "The View",
- "The view",
- GTK_TYPE_TEXT_VIEW,
- G_PARAM_READABLE));
+ _gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECTv);
- /**
- * GtkSourceGutterRenderer:alignment-mode:
- *
- * The alignment mode of the renderer. This can be used to indicate
- * that in the case a cell spans multiple lines (due to text wrapping)
- * the alignment should work on either the full cell, the first line
- * or the last line.
- *
- **/
- g_object_class_install_property (object_class,
- PROP_ALIGNMENT_MODE,
- g_param_spec_enum ("alignment-mode",
- "Alignment Mode",
- "The alignment mode",
- GTK_SOURCE_TYPE_GUTTER_RENDERER_ALIGNMENT_MODE,
- GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ signals[QUERY_DATA] =
+ g_signal_new ("query-data",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ _gtk_source_marshal_VOID__OBJECT_UINT,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_OBJECT,
+ G_TYPE_UINT);
+ g_signal_set_va_marshaller (signals[QUERY_DATA],
+ G_TYPE_FROM_CLASS (klass),
+ _gtk_source_marshal_VOID__OBJECT_UINTv);
- /**
- * GtkSourceGutterRenderer:window-type:
- *
- * The window type of the view on which the renderer is placed (left,
- * or right).
- *
- **/
- g_object_class_install_property (object_class,
- PROP_WINDOW_TYPE,
- g_param_spec_enum ("window-type",
- "Window Type",
- "The window type",
- GTK_TYPE_TEXT_WINDOW_TYPE,
- GTK_TEXT_WINDOW_PRIVATE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_SIZE,
- g_param_spec_int ("size",
- "Size",
- "The size",
- 0,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (object_class,
- PROP_BACKGROUND_RGBA,
- g_param_spec_boxed ("background-rgba",
- "Background Color",
- "The background color",
- GDK_TYPE_RGBA,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_BACKGROUND_SET,
- g_param_spec_boolean ("background-set",
- "Background Set",
- "Whether the background color is set",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ gtk_widget_class_set_css_name (widget_class, "gutterrenderer");
}
static void
gtk_source_gutter_renderer_init (GtkSourceGutterRenderer *self)
{
-}
-
-/**
- * gtk_source_gutter_renderer_begin:
- * @renderer: a #GtkSourceGutterRenderer
- * @cr: a #cairo_t
- * @background_area: a #GdkRectangle
- * @cell_area: a #GdkRectangle
- * @start: a #GtkTextIter
- * @end: a #GtkTextIter
- *
- * Called when drawing a region begins. The region to be drawn is indicated
- * by @start and @end. The purpose is to allow the implementation to precompute
- * some state before the draw method is called for each cell.
- */
-void
-gtk_source_gutter_renderer_begin (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end)
-{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
- g_return_if_fail (cr != NULL);
- g_return_if_fail (background_area != NULL);
- g_return_if_fail (cell_area != NULL);
- g_return_if_fail (start != NULL);
- g_return_if_fail (end != NULL);
-
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->begin)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (
- G_OBJECT_GET_CLASS (renderer))->begin (renderer,
- cr,
- background_area,
- cell_area,
- start,
- end);
- }
-}
-
-/**
- * gtk_source_gutter_renderer_draw:
- * @renderer: a #GtkSourceGutterRenderer
- * @cr: the cairo render context
- * @background_area: a #GdkRectangle indicating the total area to be drawn
- * @cell_area: a #GdkRectangle indicating the area to draw content
- * @start: a #GtkTextIter
- * @end: a #GtkTextIter
- * @state: a #GtkSourceGutterRendererState
- *
- * Main renderering method. Implementations should implement this method to draw
- * onto the cairo context. The @background_area indicates the total area of the
- * cell to be drawn. The @cell_area indicates the area where content can be
- * drawn (text, images, etc).
- *
- * The @background_area is the @cell_area plus the padding on each side (two
- * times the #GtkSourceGutterRenderer:xpad horizontally and two times the
- * #GtkSourceGutterRenderer:ypad vertically, so that the @cell_area is centered
- * inside @background_area).
- *
- * The @state argument indicates the current state of the renderer and should
- * be taken into account to properly draw the different possible states
- * (cursor, prelit, selected) if appropriate.
- */
-void
-gtk_source_gutter_renderer_draw (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state)
-{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
- g_return_if_fail (cr != NULL);
- g_return_if_fail (background_area != NULL);
- g_return_if_fail (cell_area != NULL);
- g_return_if_fail (start != NULL);
- g_return_if_fail (end != NULL);
-
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->draw)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (
- G_OBJECT_GET_CLASS (renderer))->draw (renderer,
- cr,
- background_area,
- cell_area,
- start,
- end,
- state);
- }
-}
-
-/**
- * gtk_source_gutter_renderer_end:
- * @renderer: a #GtkSourceGutterRenderer
- *
- * Called when drawing a region of lines has ended.
- *
- **/
-void
-gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer)
-{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->end)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->end (renderer);
- }
+ self->priv = gtk_source_gutter_renderer_get_instance_private (self);
}
/**
@@ -968,8 +560,8 @@ gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer)
**/
gboolean
gtk_source_gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- GdkRectangle *area,
+ const GtkTextIter *iter,
+ const GdkRectangle *area,
GdkEvent *event)
{
gboolean ret;
@@ -1004,8 +596,8 @@ gtk_source_gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
*/
void
gtk_source_gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- GdkRectangle *area,
+ const GtkTextIter *iter,
+ const GdkRectangle *area,
GdkEvent *event)
{
g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
@@ -1017,443 +609,373 @@ gtk_source_gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
}
/**
- * gtk_source_gutter_renderer_queue_draw:
+ * gtk_source_gutter_renderer_set_alignment_mode:
* @renderer: a #GtkSourceGutterRenderer
+ * @mode: a #GtkSourceGutterRendererAlignmentMode
*
- * Emits the #GtkSourceGutterRenderer::queue-draw signal of the renderer. Call
- * this from an implementation to inform that the renderer has changed such that
- * it needs to redraw.
- */
-void
-gtk_source_gutter_renderer_queue_draw (GtkSourceGutterRenderer *renderer)
-{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
- g_signal_emit (renderer, signals[QUEUE_DRAW], 0);
-}
-
-/**
- * gtk_source_gutter_renderer_query_tooltip:
- * @renderer: a #GtkSourceGutterRenderer.
- * @iter: a #GtkTextIter.
- * @area: a #GdkRectangle.
- * @x: The x position of the tooltip.
- * @y: The y position of the tooltip.
- * @tooltip: a #GtkTooltip.
- *
- * Emits the #GtkSourceGutterRenderer::query-tooltip signal. This function is
- * called from #GtkSourceGutter. Implementations can override the default signal
- * handler or can connect to the signal externally.
- *
- * Returns: %TRUE if the tooltip has been set, %FALSE otherwise
- */
-gboolean
-gtk_source_gutter_renderer_query_tooltip (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- GdkRectangle *area,
- gint x,
- gint y,
- GtkTooltip *tooltip)
-{
- gboolean ret;
-
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (area != NULL, FALSE);
- g_return_val_if_fail (GTK_IS_TOOLTIP (tooltip), FALSE);
-
- ret = FALSE;
-
- g_signal_emit (renderer,
- signals[QUERY_TOOLTIP],
- 0,
- iter,
- area,
- x,
- y,
- tooltip,
- &ret);
-
- return ret;
-}
-
-/**
- * gtk_source_gutter_renderer_query_data:
- * @renderer: a #GtkSourceGutterRenderer.
- * @start: a #GtkTextIter.
- * @end: a #GtkTextIter.
- * @state: a #GtkSourceGutterRendererState.
- *
- * Emit the #GtkSourceGutterRenderer::query-data signal. This function is called
- * to query for data just before rendering a cell. This is called from the
- * #GtkSourceGutter. Implementations can override the default signal handler or
- * can connect a signal handler externally to the
- * #GtkSourceGutterRenderer::query-data signal.
- */
+ * Set the alignment mode. The alignment mode describes the manner in which the
+ * renderer is aligned (see #GtkSourceGutterRenderer:xalign and
+ * #GtkSourceGutterRenderer:yalign).
+ **/
void
-gtk_source_gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state)
+gtk_source_gutter_renderer_set_alignment_mode (GtkSourceGutterRenderer *renderer,
+ GtkSourceGutterRendererAlignmentMode mode)
{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
- g_return_if_fail (start != NULL);
- g_return_if_fail (end != NULL);
+ g_return_if_fail (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ g_return_if_fail (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL ||
+ mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST ||
+ mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST);
-
- /* Signal emission is relatively expensive and this code path is
- * frequent enough to optimize the common case where we only have the
- * override and no connected handlers.
- *
- * This is the same trick used by gtk_widget_draw().
- */
- if (G_UNLIKELY (g_signal_has_handler_pending (renderer, signals[QUERY_DATA], 0, FALSE)))
+ if (renderer->priv->alignment_mode != mode)
{
- g_signal_emit (renderer, signals[QUERY_DATA], 0, start, end, state);
- }
- else if (GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->query_data)
- {
- GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->query_data (renderer, start, end, state);
+ renderer->priv->alignment_mode = mode;
+ g_object_notify_by_pspec (G_OBJECT (renderer),
+ properties[PROP_ALIGNMENT_MODE]);
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
}
}
/**
- * gtk_source_gutter_renderer_set_visible:
+ * gtk_source_gutter_renderer_get_alignment_mode:
* @renderer: a #GtkSourceGutterRenderer
- * @visible: the visibility
*
- * Set whether the gutter renderer is visible.
+ * Get the alignment mode. The alignment mode describes the manner in which the
+ * renderer is aligned (see :xalign and :yalign).
*
+ * Returns: a #GtkSourceGutterRendererAlignmentMode
**/
-void
-gtk_source_gutter_renderer_set_visible (GtkSourceGutterRenderer *renderer,
- gboolean visible)
+GtkSourceGutterRendererAlignmentMode
+gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer *renderer)
{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
- set_visible (renderer, visible);
+ return renderer->priv->alignment_mode;
}
/**
- * gtk_source_gutter_renderer_get_visible:
+ * gtk_source_gutter_renderer_get_view:
* @renderer: a #GtkSourceGutterRenderer
*
- * Get whether the gutter renderer is visible.
- *
- * Returns: %TRUE if the renderer is visible, %FALSE otherwise
+ * Get the view associated to the gutter renderer
*
+ * Returns: (transfer none): a #GtkSourceView
**/
-gboolean
-gtk_source_gutter_renderer_get_visible (GtkSourceGutterRenderer *renderer)
+GtkSourceView *
+gtk_source_gutter_renderer_get_view (GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
+ g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), NULL);
- return priv->visible;
+ return GTK_SOURCE_VIEW (renderer->priv->view);
}
-/**
- * gtk_source_gutter_renderer_set_padding:
- * @renderer: a #GtkSourceGutterRenderer
- * @xpad: the x-padding
- * @ypad: the y-padding
- *
- * Set the padding of the gutter renderer. Both @xpad and @ypad can be
- * -1, which means the values will not be changed (this allows changing only
- * one of the values).
- *
- * @xpad is the left and right padding. @ypad is the top and bottom padding.
- */
void
-gtk_source_gutter_renderer_set_padding (GtkSourceGutterRenderer *renderer,
- gint xpad,
- gint ypad)
+_gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
+ GtkSourceView *view)
{
+ GtkSourceView *old_view;
+
g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_if_fail (view == NULL || GTK_SOURCE_IS_VIEW (view));
+
+ if (view == renderer->priv->view)
+ {
+ return;
+ }
+
+ old_view = g_steal_pointer (&renderer->priv->view);
+ g_set_object (&renderer->priv->view, view);
+
+ GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_view (renderer, old_view);
- set_xpad (renderer, xpad);
- set_ypad (renderer, ypad);
+ g_clear_object (&old_view);
+
+ g_object_notify_by_pspec (G_OBJECT (renderer), properties[PROP_VIEW]);
}
-/**
- * gtk_source_gutter_renderer_get_padding:
- * @renderer: a #GtkSourceGutterRenderer
- * @xpad: (out caller-allocates) (optional): return location for the x-padding,
- * or %NULL to ignore.
- * @ypad: (out caller-allocates) (optional): return location for the y-padding,
- * or %NULL to ignore.
- *
- * Get the x-padding and y-padding of the gutter renderer.
- */
-void
-gtk_source_gutter_renderer_get_padding (GtkSourceGutterRenderer *renderer,
- gint *xpad,
- gint *ypad)
+static void
+get_line_rect (GtkSourceGutterRenderer *renderer,
+ guint line,
+ GdkRectangle *rect)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+ GtkSourceLines *lines = NULL;
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
- if (xpad)
+ if (renderer->priv->gutter != NULL)
{
- *xpad = priv->xpad;
+ lines = _gtk_source_gutter_get_lines (renderer->priv->gutter);
}
- if (ypad)
+ if (lines != NULL)
{
- *ypad = priv->ypad;
+ gint y;
+ gint height;
+
+ gtk_source_lines_get_line_yrange (lines,
+ line,
+ renderer->priv->alignment_mode,
+ &y,
+ &height);
+
+ rect->x = renderer->priv->xpad;
+ rect->y = y + renderer->priv->ypad;
+ rect->width = gtk_widget_get_width (GTK_WIDGET (renderer));
+ rect->height = height;
+
+ rect->width -= 2 * renderer->priv->xpad;
+ rect->height -= 2 * renderer->priv->ypad;
+ }
+ else
+ {
+ rect->x = 0;
+ rect->y = 0;
+ rect->width = 0;
+ rect->height = 0;
}
}
/**
- * gtk_source_gutter_renderer_set_alignment:
- * @renderer: a #GtkSourceGutterRenderer
- * @xalign: the x-alignment
- * @yalign: the y-alignment
+ * gtk_source_gutter_renderer_align_cell:
+ * @renderer: the #GtkSourceGutterRenderer
+ * @line: the line number for content
+ * @width: the width of the content to draw
+ * @height: the height of the content to draw
+ * @x: (out): the X position to render the content
+ * @y: (out): the Y position to render the content
+ *
+ * Locates where to render content that is @width x @height based on
+ * the renderers alignment and padding.
+ *
+ * The location will be placed into @x and @y and is relative to the
+ * renderer's coordinates.
*
- * Set the alignment of the gutter renderer. Both @xalign and @yalign can be
- * -1, which means the values will not be changed (this allows changing only
- * one of the values).
+ * It is encouraged that renderers use this function when snappshotting
+ * to ensure consistent placement of their contents.
*
- * @xalign is the horizontal alignment. Set to 0 for a left alignment. 1 for a
- * right alignment. And 0.5 for centering the cells. @yalign is the vertical
- * alignment. Set to 0 for a top alignment. 1 for a bottom alignment.
+ * Since: 5.0
*/
void
-gtk_source_gutter_renderer_set_alignment (GtkSourceGutterRenderer *renderer,
- gfloat xalign,
- gfloat yalign)
+gtk_source_gutter_renderer_align_cell (GtkSourceGutterRenderer *renderer,
+ guint line,
+ gfloat width,
+ gfloat height,
+ gfloat *x,
+ gfloat *y)
{
- gboolean changed_x;
- gboolean changed_y;
+ GdkRectangle rect;
g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
- changed_x = set_xalign (renderer, xalign, FALSE);
- changed_y = set_yalign (renderer, yalign, FALSE);
+ get_line_rect (renderer, line, &rect);
- if (changed_x || changed_y)
- {
- gtk_source_gutter_renderer_queue_draw (renderer);
- }
+ *x = rect.x + (rect.width - width) * renderer->priv->xalign;
+ *y = rect.y + (rect.height - height) * renderer->priv->yalign;
}
/**
- * gtk_source_gutter_renderer_get_alignment:
+ * gtk_source_gutter_renderer_get_xpad:
* @renderer: a #GtkSourceGutterRenderer
- * @xalign: (out caller-allocates) (optional): return location for the x-alignment,
- * or %NULL to ignore.
- * @yalign: (out caller-allocates) (optional): return location for the y-alignment,
- * or %NULL to ignore.
*
- * Get the x-alignment and y-alignment of the gutter renderer.
+ * Gets the "xpad" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust the cell rectangle that the renderer will use to draw.
+ *
+ * Since: 5.0
*/
-void
-gtk_source_gutter_renderer_get_alignment (GtkSourceGutterRenderer *renderer,
- gfloat *xalign,
- gfloat *yalign)
+gint
+gtk_source_gutter_renderer_get_xpad (GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
- if (xalign)
- {
- *xalign = priv->xalign;
- }
+ g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
- if (yalign)
- {
- *yalign = priv->yalign;
- }
+ return renderer->priv->xpad;
}
/**
- * gtk_source_gutter_renderer_set_alignment_mode:
+ * gtk_source_gutter_renderer_set_xpad:
* @renderer: a #GtkSourceGutterRenderer
- * @mode: a #GtkSourceGutterRendererAlignmentMode
+ * @xpad: the Y padding for the drawing cell
*
- * Set the alignment mode. The alignment mode describes the manner in which the
- * renderer is aligned (see :xalign and :yalign).
+ * Adjusts the "xpad" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust the cell rectangle that the renderer will use to draw.
*
- **/
+ * Since: 5.0
+ */
void
-gtk_source_gutter_renderer_set_alignment_mode (GtkSourceGutterRenderer *renderer,
- GtkSourceGutterRendererAlignmentMode mode)
+gtk_source_gutter_renderer_set_xpad (GtkSourceGutterRenderer *renderer,
+ gint xpad)
{
g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_if_fail (xpad >= 0);
- set_alignment_mode (renderer, mode);
+ if (renderer->priv->xpad != xpad)
+ {
+ renderer->priv->xpad = xpad;
+ g_object_notify_by_pspec (G_OBJECT (renderer),
+ properties[PROP_XPAD]);
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
+ }
}
/**
- * gtk_source_gutter_renderer_get_alignment_mode:
+ * gtk_source_gutter_renderer_get_ypad:
* @renderer: a #GtkSourceGutterRenderer
*
- * Get the alignment mode. The alignment mode describes the manner in which the
- * renderer is aligned (see :xalign and :yalign).
- *
- * Returns: a #GtkSourceGutterRendererAlignmentMode
+ * Gets the "ypad" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust the cell rectangle that the renderer will use to draw.
*
- **/
-GtkSourceGutterRendererAlignmentMode
-gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+gint
+gtk_source_gutter_renderer_get_ypad (GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
- return priv->alignment_mode;
+ return renderer->priv->ypad;
}
/**
- * gtk_source_gutter_renderer_get_window_type:
+ * gtk_source_gutter_renderer_set_ypad:
* @renderer: a #GtkSourceGutterRenderer
+ * @ypad: the Y padding for the drawing cell
*
- * Get the #GtkTextWindowType associated with the gutter renderer.
- *
- * Returns: a #GtkTextWindowType
+ * Adjusts the "ypad" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust the cell rectangle that the renderer will use to draw.
*
- **/
-GtkTextWindowType
-gtk_source_gutter_renderer_get_window_type (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+void
+gtk_source_gutter_renderer_set_ypad (GtkSourceGutterRenderer *renderer,
+ gint ypad)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), GTK_TEXT_WINDOW_PRIVATE);
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_if_fail (ypad >= 0);
- return priv->window_type;
+ if (renderer->priv->ypad != ypad)
+ {
+ renderer->priv->ypad = ypad;
+ g_object_notify_by_pspec (G_OBJECT (renderer),
+ properties[PROP_YPAD]);
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
+ }
}
/**
- * gtk_source_gutter_renderer_get_view:
+ * gtk_source_gutter_renderer_get_xalign:
* @renderer: a #GtkSourceGutterRenderer
*
- * Get the view associated to the gutter renderer
- *
- * Returns: (transfer none): a #GtkTextView
+ * Gets the "xalign" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust where within the cell rectangle the renderer will draw.
*
- **/
-GtkTextView *
-gtk_source_gutter_renderer_get_view (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+gfloat
+gtk_source_gutter_renderer_get_xalign (GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), NULL);
+ g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
- return priv->view;
+ return renderer->priv->xalign;
}
/**
- * gtk_source_gutter_renderer_get_size:
+ * gtk_source_gutter_renderer_set_xalign:
* @renderer: a #GtkSourceGutterRenderer
+ * @xalign: the Y padding for the drawing cell
*
- * Get the size of the renderer.
- *
- * Returns: the size of the renderer.
+ * Adjusts the "xalign" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust where within the cell rectangle the renderer will draw.
*
- **/
-gint
-gtk_source_gutter_renderer_get_size (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+void
+gtk_source_gutter_renderer_set_xalign (GtkSourceGutterRenderer *renderer,
+ gfloat xalign)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_if_fail (xalign >= 0);
- return priv->size;
+ if (renderer->priv->xalign != xalign)
+ {
+ renderer->priv->xalign = xalign;
+ g_object_notify_by_pspec (G_OBJECT (renderer),
+ properties[PROP_XALIGN]);
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
+ }
}
/**
- * gtk_source_gutter_renderer_set_size:
+ * gtk_source_gutter_renderer_get_yalign:
* @renderer: a #GtkSourceGutterRenderer
- * @size: the size
*
- * Sets the size of the renderer. A value of -1 specifies that the size
- * is to be determined dynamically.
+ * Gets the "yalign" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust where within the cell rectangle the renderer will draw.
*
- **/
-void
-gtk_source_gutter_renderer_set_size (GtkSourceGutterRenderer *renderer,
- gint size)
+ * Since: 5.0
+ */
+gfloat
+gtk_source_gutter_renderer_get_yalign (GtkSourceGutterRenderer *renderer)
{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
- set_size (renderer, size);
+ return renderer->priv->yalign;
}
/**
- * gtk_source_gutter_renderer_get_background:
+ * gtk_source_gutter_renderer_set_yalign:
* @renderer: a #GtkSourceGutterRenderer
- * @color: (out caller-allocates) (optional): return value for a #GdkRGBA
+ * @yalign: the Y padding for the drawing cell
*
- * Get the background color of the renderer.
+ * Adjusts the "yalign" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust where within the cell rectangle the renderer will draw.
*
- * Returns: %TRUE if the background color is set, %FALSE otherwise
- *
- **/
-gboolean
-gtk_source_gutter_renderer_get_background (GtkSourceGutterRenderer *renderer,
- GdkRGBA *color)
+ * Since: 5.0
+ */
+void
+gtk_source_gutter_renderer_set_yalign (GtkSourceGutterRenderer *renderer,
+ gfloat yalign)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_if_fail (yalign >= 0);
- if (color)
+ if (renderer->priv->yalign != yalign)
{
- *color = priv->background_color;
+ renderer->priv->yalign = yalign;
+ g_object_notify_by_pspec (G_OBJECT (renderer),
+ properties[PROP_YALIGN]);
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
}
-
- return priv->background_set;
}
/**
- * gtk_source_gutter_renderer_set_background:
+ * gtk_source_gutter_renderer_get_buffer:
* @renderer: a #GtkSourceGutterRenderer
- * @color: (nullable): a #GdkRGBA or %NULL
*
- * Set the background color of the renderer. If @color is set to %NULL, the
- * renderer will not have a background color.
+ * Gets the #GtkSourceBuffer for which the gutter renderer is drawing.
*
+ * Returns: (transfer none) (nullable): a #GtkTextBuffer or %NULL
+ *
+ * Since: 5.0
*/
-void
-gtk_source_gutter_renderer_set_background (GtkSourceGutterRenderer *renderer,
- const GdkRGBA *color)
+GtkSourceBuffer *
+gtk_source_gutter_renderer_get_buffer (GtkSourceGutterRenderer *renderer)
{
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+ g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), NULL);
- set_background_color (renderer, color);
+ return renderer->priv->buffer;
}
void
-_gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
- GtkTextView *view,
- GtkTextWindowType window_type)
+_gtk_source_gutter_renderer_begin (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines)
{
- GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
- GtkTextView *old_view;
-
g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
- g_return_if_fail (view == NULL || GTK_IS_TEXT_VIEW (view));
+ g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
- old_view = priv->view;
-
- priv->window_type = window_type;
- priv->view = view != NULL ? g_object_ref (view) : NULL;
-
- if (GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_view)
- {
- GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_view (renderer,
- old_view);
- }
+ g_set_object (&renderer->priv->lines, lines);
+ GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->begin (renderer, lines);
+}
- if (old_view)
- {
- g_object_unref (old_view);
- }
+void
+_gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer)
+{
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
- g_object_notify (G_OBJECT (renderer), "view");
- g_object_notify (G_OBJECT (renderer), "window_type");
+ GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->end (renderer);
+ g_clear_object (&renderer->priv->lines);
}
diff --git a/gtksourceview/gtksourcegutterrenderer.h b/gtksourceview/gtksourcegutterrenderer.h
index baa413d5..2167a3e5 100644
--- a/gtksourceview/gtksourcegutterrenderer.h
+++ b/gtksourceview/gtksourcegutterrenderer.h
@@ -30,25 +30,16 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER (gtk_source_gutter_renderer_get_type())
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER (gtk_source_gutter_renderer_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRenderer))
+#define GTK_SOURCE_GUTTER_RENDERER_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRenderer const))
+#define GTK_SOURCE_GUTTER_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRendererClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER))
+#define GTK_SOURCE_GUTTER_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRendererClass))
-/**
- * GtkSourceGutterRendererState:
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_NORMAL: normal state
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR: area in the renderer represents the
- * line on which the insert cursor is currently positioned
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT: the mouse pointer is currently
- * over the activatable area of the renderer
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_SELECTED: area in the renderer represents
- * a line in the buffer which contains part of the selection
- **/
-typedef enum _GtkSourceGutterRendererState
-{
- GTK_SOURCE_GUTTER_RENDERER_STATE_NORMAL = 0,
- GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR = 1 << 0,
- GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT = 1 << 1,
- GTK_SOURCE_GUTTER_RENDERER_STATE_SELECTED = 1 << 2
-} GtkSourceGutterRendererState;
+typedef struct _GtkSourceGutterRendererClass GtkSourceGutterRendererClass;
+typedef struct _GtkSourceGutterRendererPrivate GtkSourceGutterRendererPrivate;
/**
* GtkSourceGutterRendererAlignmentMode:
@@ -63,30 +54,32 @@ typedef enum _GtkSourceGutterRendererAlignmentMode
{
GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
- GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST
+ GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST,
} GtkSourceGutterRendererAlignmentMode;
+struct _GtkSourceGutterRenderer
+{
+ GtkWidget parent;
+
+ /*< private >*/
+ GtkSourceGutterRendererPrivate *priv;
+};
+
struct _GtkSourceGutterRendererClass
{
- GInitiallyUnownedClass parent_class;
-
- /*< public >*/
- void (*begin) (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end);
-
- void (*draw) (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state);
-
- void (*end) (GtkSourceGutterRenderer *renderer);
+ GtkWidgetClass parent_class;
+
+ void (*query_data) (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines,
+ guint line);
+
+ void (*begin) (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines);
+ void (*snapshot_line) (GtkSourceGutterRenderer *renderer,
+ GtkSnapshot *snapshot,
+ GtkSourceLines *lines,
+ guint line);
+ void (*end) (GtkSourceGutterRenderer *renderer);
/**
* GtkSourceGutterRendererClass::change_view:
@@ -95,8 +88,8 @@ struct _GtkSourceGutterRendererClass
*
* This is called when the text view changes for @renderer.
*/
- void (*change_view) (GtkSourceGutterRenderer *renderer,
- GtkTextView *old_view);
+ void (*change_view) (GtkSourceGutterRenderer *renderer,
+ GtkSourceView *old_view);
/**
* GtkSourceGutterRendererClass::change_buffer:
@@ -105,122 +98,71 @@ struct _GtkSourceGutterRendererClass
*
* This is called when the text buffer changes for @renderer.
*/
- void (*change_buffer) (GtkSourceGutterRenderer *renderer,
- GtkTextBuffer *old_buffer);
+ void (*change_buffer) (GtkSourceGutterRenderer *renderer,
+ GtkSourceBuffer *old_buffer);
/* Signal handlers */
- gboolean (*query_activatable) (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- GdkRectangle *area,
- GdkEvent *event);
-
- void (*activate) (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- GdkRectangle *area,
- GdkEvent *event);
-
- void (*queue_draw) (GtkSourceGutterRenderer *renderer);
-
- gboolean (*query_tooltip) (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- GdkRectangle *area,
- gint x,
- gint y,
- GtkTooltip *tooltip);
-
- void (*query_data) (GtkSourceGutterRenderer *renderer,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state);
+ gboolean (*query_activatable) (GtkSourceGutterRenderer *renderer,
+ GtkTextIter *iter,
+ GdkRectangle *area,
+ GdkEvent *event);
+ void (*activate) (GtkSourceGutterRenderer *renderer,
+ GtkTextIter *iter,
+ GdkRectangle *area,
+ GdkEvent *event);
+
/*< private >*/
gpointer _reserved[20];
};
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRenderer, gtk_source_gutter_renderer, GTK_SOURCE, GUTTER_RENDERER,
GInitiallyUnowned)
-
+GType gtk_source_gutter_renderer_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_begin (GtkSourceGutterRenderer
*renderer,
- cairo_t
*cr,
- GdkRectangle
*background_area,
- GdkRectangle
*cell_area,
- GtkTextIter
*start,
- GtkTextIter
*end);
+gfloat gtk_source_gutter_renderer_get_xalign (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_draw (GtkSourceGutterRenderer
*renderer,
- cairo_t
*cr,
- GdkRectangle
*background_area,
- GdkRectangle
*cell_area,
- GtkTextIter
*start,
- GtkTextIter
*end,
-
GtkSourceGutterRendererState state);
+void gtk_source_gutter_renderer_set_xalign (GtkSourceGutterRenderer
*renderer,
+ gfloat
xalign);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_end (GtkSourceGutterRenderer
*renderer);
+gfloat gtk_source_gutter_renderer_get_yalign (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
-gint gtk_source_gutter_renderer_get_size (GtkSourceGutterRenderer
*renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_set_size (GtkSourceGutterRenderer
*renderer,
- gint
size);
+void gtk_source_gutter_renderer_set_yalign (GtkSourceGutterRenderer
*renderer,
+ gfloat
yalign);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_set_visible (GtkSourceGutterRenderer
*renderer,
- gboolean
visible);
+gint gtk_source_gutter_renderer_get_xpad (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_gutter_renderer_get_visible (GtkSourceGutterRenderer
*renderer);
+void gtk_source_gutter_renderer_set_xpad (GtkSourceGutterRenderer
*renderer,
+ gint
xpad);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_get_padding (GtkSourceGutterRenderer
*renderer,
- gint
*xpad,
- gint
*ypad);
+gint gtk_source_gutter_renderer_get_ypad (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_set_padding (GtkSourceGutterRenderer
*renderer,
- gint
xpad,
+void gtk_source_gutter_renderer_set_ypad (GtkSourceGutterRenderer
*renderer,
gint
ypad);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_get_alignment (GtkSourceGutterRenderer
*renderer,
- gfloat
*xalign,
- gfloat
*yalign);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_set_alignment (GtkSourceGutterRenderer
*renderer,
- gfloat
xalign,
- gfloat
yalign);
+GtkSourceGutterRendererAlignmentMode gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
void gtk_source_gutter_renderer_set_alignment_mode (GtkSourceGutterRenderer
*renderer,
GtkSourceGutterRendererAlignmentMode mode);
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkTextWindowType gtk_source_gutter_renderer_get_window_type (GtkSourceGutterRenderer
*renderer);
+GtkSourceBuffer *gtk_source_gutter_renderer_get_buffer (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkTextView *gtk_source_gutter_renderer_get_view (GtkSourceGutterRenderer
*renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRendererAlignmentMode gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer
*renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_gutter_renderer_get_background (GtkSourceGutterRenderer
*renderer,
- GdkRGBA
*color);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_set_background (GtkSourceGutterRenderer
*renderer,
- const GdkRGBA
*color);
+GtkSourceView *gtk_source_gutter_renderer_get_view (GtkSourceGutterRenderer
*renderer);
GTK_SOURCE_AVAILABLE_IN_ALL
void gtk_source_gutter_renderer_activate (GtkSourceGutterRenderer
*renderer,
- GtkTextIter
*iter,
- GdkRectangle
*area,
+ const GtkTextIter
*iter,
+ const GdkRectangle
*area,
GdkEvent
*event);
GTK_SOURCE_AVAILABLE_IN_ALL
gboolean gtk_source_gutter_renderer_query_activatable (GtkSourceGutterRenderer
*renderer,
- GtkTextIter
*iter,
- GdkRectangle
*area,
+ const GtkTextIter
*iter,
+ const GdkRectangle
*area,
GdkEvent
*event);
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_queue_draw (GtkSourceGutterRenderer
*renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_gutter_renderer_query_tooltip (GtkSourceGutterRenderer
*renderer,
- GtkTextIter
*iter,
- GdkRectangle
*area,
- gint
x,
- gint
y,
- GtkTooltip
*tooltip);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_query_data (GtkSourceGutterRenderer
*renderer,
- GtkTextIter
*start,
- GtkTextIter
*end,
-
GtkSourceGutterRendererState state);
+void gtk_source_gutter_renderer_align_cell (GtkSourceGutterRenderer
*renderer,
+ guint
line,
+ gfloat
width,
+ gfloat
height,
+ gfloat
*x,
+ gfloat
*y);
G_END_DECLS
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index 6f508ce1..88f14f02 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -20,29 +20,19 @@
#include "config.h"
-#include "gtksourcegutterrendererlines-private.h"
+#include "gtksourcegutterrendererlines.h"
+#include "gtksourcelines.h"
#include "gtksourceutils-private.h"
#include "gtksourceview.h"
-struct _GtkSourceGutterRendererLines
+struct _GtkSourceGutterRendererLinesPrivate
{
- GtkSourceGutterRendererText parent_instance;
gint num_line_digits;
gint prev_line_num;
guint cursor_visible : 1;
};
-G_DEFINE_TYPE (GtkSourceGutterRendererLines, _gtk_source_gutter_renderer_lines,
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
-
-static GtkTextBuffer *
-get_buffer (GtkSourceGutterRendererLines *renderer)
-{
- GtkTextView *view;
-
- view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (renderer));
-
- return view != NULL ? gtk_text_view_get_buffer (view) : NULL;
-}
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererLines, gtk_source_gutter_renderer_lines,
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
static inline gint
count_num_digits (gint num_lines)
@@ -76,33 +66,18 @@ count_num_digits (gint num_lines)
static void
recalculate_size (GtkSourceGutterRendererLines *renderer)
{
+ GtkSourceBuffer *buffer;
gint num_lines;
- gint num_digits = 0;
- GtkTextBuffer *buffer;
-
- buffer = get_buffer (renderer);
-
- num_lines = gtk_text_buffer_get_line_count (buffer);
+ gint num_digits;
+ buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ num_lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer));
num_digits = count_num_digits (num_lines);
- if (num_digits != renderer->num_line_digits)
+ if (num_digits != renderer->priv->num_line_digits)
{
- gchar markup[24];
- gint size;
-
- renderer->num_line_digits = num_digits;
-
- num_lines = MAX (num_lines, 99);
-
- g_snprintf (markup, sizeof markup, "<b>%d</b>", num_lines);
- gtk_source_gutter_renderer_text_measure_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
- markup,
- &size,
- NULL);
-
- gtk_source_gutter_renderer_set_size (GTK_SOURCE_GUTTER_RENDERER (renderer),
- size);
+ renderer->priv->num_line_digits = num_digits;
+ gtk_widget_queue_resize (GTK_WIDGET (renderer));
}
}
@@ -113,21 +88,37 @@ on_buffer_changed (GtkSourceBuffer *buffer,
recalculate_size (renderer);
}
+static void
+on_buffer_cursor_moved (GtkSourceBuffer *buffer,
+ GtkSourceGutterRendererLines *renderer)
+{
+ if (renderer->priv->cursor_visible)
+ {
+ /* Redraw if the current-line needs updating */
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
+ }
+}
+
static void
gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
- GtkTextBuffer *old_buffer)
+ GtkSourceBuffer *old_buffer)
{
GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
- GtkTextBuffer *buffer;
+ GtkSourceBuffer *buffer;
if (old_buffer != NULL)
{
g_signal_handlers_disconnect_by_func (old_buffer,
on_buffer_changed,
lines);
+ g_signal_handlers_disconnect_by_func (old_buffer,
+ on_buffer_cursor_moved,
+ lines);
}
- buffer = get_buffer (lines);
+ buffer = gtk_source_gutter_renderer_get_buffer (renderer);
+
+ lines->priv->prev_line_num = 0;
if (buffer != NULL)
{
@@ -137,15 +128,17 @@ gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
lines,
0);
+ g_signal_connect_object (buffer,
+ "cursor-moved",
+ G_CALLBACK (on_buffer_cursor_moved),
+ lines,
+ 0);
+
recalculate_size (lines);
}
- lines->prev_line_num = 0;
-
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->change_buffer
!= NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS
(_gtk_source_gutter_renderer_lines_parent_class)->change_buffer (renderer, old_buffer);
- }
+ GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_buffer
(renderer,
+
old_buffer);
}
static void
@@ -153,7 +146,7 @@ on_view_style_updated (GtkTextView *view,
GtkSourceGutterRendererLines *renderer)
{
/* Force to recalculate the size. */
- renderer->num_line_digits = -1;
+ renderer->priv->num_line_digits = -1;
recalculate_size (renderer);
}
@@ -162,14 +155,14 @@ on_view_notify_cursor_visible (GtkTextView *view,
GParamSpec *pspec,
GtkSourceGutterRendererLines *renderer)
{
- renderer->cursor_visible = gtk_text_view_get_cursor_visible (view);
+ renderer->priv->cursor_visible = gtk_text_view_get_cursor_visible (view);
}
static void
gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
- GtkTextView *old_view)
+ GtkSourceView *old_view)
{
- GtkTextView *new_view;
+ GtkSourceView *new_view;
if (old_view != NULL)
{
@@ -197,116 +190,11 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
renderer,
0);
- GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->cursor_visible =
gtk_text_view_get_cursor_visible (new_view);
- }
-
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->change_view !=
NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS
(_gtk_source_gutter_renderer_lines_parent_class)->change_view (renderer, old_view);
- }
-}
-
-static void
-gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state)
-{
- GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
- gchar text[24];
- const gchar *textptr = text;
- gint line;
- gint len;
- gboolean current_line;
-
- line = gtk_text_iter_get_line (start) + 1;
-
- current_line = (state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) &&
- lines->cursor_visible;
-
- if G_LIKELY (!current_line)
- {
- len = _gtk_source_utils_int_to_string (line, &textptr);
- }
- else
- {
- len = g_snprintf (text, sizeof text, "<b>%d</b>", line);
- }
-
- gtk_source_gutter_renderer_text_set_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
- textptr,
- len);
-}
-
-static gint
-get_last_visible_line_number (GtkSourceGutterRendererLines *lines)
-{
- GtkTextView *view;
- GdkRectangle visible_rect;
- GtkTextIter iter;
-
- view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (lines));
-
- gtk_text_view_get_visible_rect (view, &visible_rect);
-
- gtk_text_view_get_line_at_y (view,
- &iter,
- visible_rect.y + visible_rect.height,
- NULL);
-
- gtk_text_iter_forward_line (&iter);
-
- return gtk_text_iter_get_line (&iter);
-}
-
-static void
-gutter_renderer_end (GtkSourceGutterRenderer *renderer)
-{
- GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
- GtkTextBuffer *buffer = get_buffer (lines);
-
- if (buffer != NULL)
- {
- gint line_num = get_last_visible_line_number (lines);
-
- /* When the text is modified in a GtkTextBuffer, GtkTextView tries to
- * redraw the smallest required region. But the information displayed in
- * the gutter may become invalid in a bigger region.
- * See https://bugzilla.gnome.org/show_bug.cgi?id=732418 for an example
- * where line numbers are not updated correctly when splitting a wrapped
- * line.
- * The performances should not be a big problem here. Correctness is
- * more important than performances. It just triggers a second
- * draw.
- * The queue_draw() is called in gutter_renderer_end(), because
- * the first draw is anyway needed to avoid flickering (if the
- * first draw is not done, there will be a white region in the
- * gutter during one frame).
- * Another solution that has better performances is to compare
- * the total number of lines in the buffer, instead of the last
- * visible line. But it has the drawback that the gutter is
- * continuously redrawn during file loading.
- *
- * FIXME A better solution would be to add a vfunc in the
- * GutterRenderer so that the Gutter can ask each renderer for
- * the invalidation region, before drawing. So that only one
- * draw is needed, and the solution would be more generic (if
- * other renderers also need a different invalidation region
- * than the GtkTextView). But the GutterRendererClass doesn't
- * have padding for future expansion, so it must wait for
- * GtkSourceView 4.
- */
- if (lines->prev_line_num != line_num)
- {
- lines->prev_line_num = line_num;
- gtk_source_gutter_renderer_queue_draw (renderer);
- }
+ GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->priv->cursor_visible =
gtk_text_view_get_cursor_visible (GTK_TEXT_VIEW (new_view));
}
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->end != NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->end
(renderer);
- }
+ GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_view
(renderer,
+
old_view);
}
static void
@@ -316,11 +204,11 @@ extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
GtkTextIter start;
GtkTextIter end;
GtkTextIter line_end;
- GtkTextBuffer *buffer;
+ GtkSourceBuffer *buffer;
- buffer = get_buffer (renderer);
+ buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
- gtk_text_buffer_get_selection_bounds (buffer,
+ gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer),
&start,
&end);
@@ -333,7 +221,7 @@ extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
if (gtk_text_iter_compare (&start, line_start) < 0)
{
- gtk_text_buffer_select_range (buffer,
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
&start,
&line_end);
}
@@ -341,13 +229,13 @@ extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
{
/* if the selection is in this line, extend
* the selection to the whole line */
- gtk_text_buffer_select_range (buffer,
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
&line_end,
line_start);
}
else
{
- gtk_text_buffer_select_range (buffer,
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
&end,
line_start);
}
@@ -358,9 +246,9 @@ select_line (GtkSourceGutterRendererLines *renderer,
GtkTextIter *line_start)
{
GtkTextIter iter;
- GtkTextBuffer *buffer;
+ GtkSourceBuffer *buffer;
- buffer = get_buffer (renderer);
+ buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
iter = *line_start;
@@ -370,7 +258,7 @@ select_line (GtkSourceGutterRendererLines *renderer,
}
/* Select the line, put the cursor at the end of the line */
- gtk_text_buffer_select_range (buffer, &iter, line_start);
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &iter, line_start);
}
static void
@@ -380,21 +268,35 @@ gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
GdkEvent *event)
{
GtkSourceGutterRendererLines *lines;
+ GdkModifierType state;
+ GdkEventType etype;
+ guint button;
lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
+ etype = gdk_event_get_event_type (event);
- if (event->type == GDK_BUTTON_PRESS && (event->button.button == 1))
+ if (!gdk_event_get_button (event, &button))
{
- GtkTextBuffer *buffer;
+ return;
+ }
- buffer = get_buffer (lines);
+ if (!gdk_event_get_state (event, &state))
+ {
+ state = 0;
+ }
+
+ if (etype == GDK_BUTTON_PRESS && button == 1)
+ {
+ GtkSourceBuffer *buffer;
- if ((event->button.state & GDK_CONTROL_MASK) != 0)
+ buffer = gtk_source_gutter_renderer_get_buffer (renderer);
+
+ if ((state & GDK_CONTROL_MASK) != 0)
{
/* Single click + Ctrl -> select the line */
select_line (lines, iter);
}
- else if ((event->button.state & GDK_SHIFT_MASK) != 0)
+ else if ((state & GDK_SHIFT_MASK) != 0)
{
/* Single click + Shift -> extended current
selection to include the clicked line */
@@ -402,13 +304,18 @@ gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
}
else
{
- gtk_text_buffer_place_cursor (buffer, iter);
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (buffer), iter);
}
}
- else if (event->type == GDK_2BUTTON_PRESS && (event->button.button == 1))
+#if 0
+ /* Requires porting to GtkWidget or drastically changing API,
+ * which is about the same as porting to widget.
+ */
+ else if (etype == GDK_2BUTTON_PRESS && button == 1)
{
select_line (lines, iter);
}
+#endif
}
static gboolean
@@ -417,29 +324,98 @@ gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
GdkRectangle *area,
GdkEvent *event)
{
- return get_buffer (GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)) != NULL;
+ return gtk_source_gutter_renderer_get_buffer (renderer) != NULL;
}
static void
-_gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *klass)
+gtk_source_gutter_renderer_lines_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
+{
+ GtkSourceGutterRendererLines *renderer = GTK_SOURCE_GUTTER_RENDERER_LINES (widget);
+
+ if (orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ *minimum = 0;
+ *natural = 0;
+ }
+ else
+ {
+ GtkSourceBuffer *buffer;
+ gchar markup[32];
+ guint num_lines;
+ gint size;
+ gint xpad;
+
+ buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ num_lines = MAX (99, gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer)));
+
+ g_snprintf (markup, sizeof markup, "<b>%u</b>", num_lines);
+ gtk_source_gutter_renderer_text_measure_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
+ markup,
+ &size,
+ NULL);
+
+ xpad = gtk_source_gutter_renderer_get_xpad (GTK_SOURCE_GUTTER_RENDERER (renderer));
+
+ *natural = *minimum = size + xpad * 2;
+ }
+
+ *minimum_baseline = -1;
+ *natural_baseline = -1;
+}
+
+static void
+gtk_source_gutter_renderer_lines_query_data (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines,
+ guint line)
+{
+ GtkSourceGutterRendererLines *self = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
+ gint len;
+
+ if G_UNLIKELY (self->priv->cursor_visible && gtk_source_lines_is_cursor (lines, line))
+ {
+ gchar text[32];
+
+ len = g_snprintf (text, sizeof text, "<b>%d</b>", line + 1);
+ gtk_source_gutter_renderer_text_set_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer), text,
len);
+ }
+ else
+ {
+ const gchar *text;
+
+ len = _gtk_source_utils_int_to_string (line + 1, &text);
+ gtk_source_gutter_renderer_text_set_text (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer), text,
len);
+ }
+}
+
+static void
+gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *klass)
{
GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ widget_class->measure = gtk_source_gutter_renderer_lines_measure;
- renderer_class->query_data = gutter_renderer_query_data;
- renderer_class->end = gutter_renderer_end;
renderer_class->query_activatable = gutter_renderer_query_activatable;
+ renderer_class->query_data = gtk_source_gutter_renderer_lines_query_data;
renderer_class->activate = gutter_renderer_activate;
renderer_class->change_buffer = gutter_renderer_change_buffer;
renderer_class->change_view = gutter_renderer_change_view;
}
static void
-_gtk_source_gutter_renderer_lines_init (GtkSourceGutterRendererLines *self)
+gtk_source_gutter_renderer_lines_init (GtkSourceGutterRendererLines *self)
{
+ self->priv = gtk_source_gutter_renderer_lines_get_instance_private (self);
}
GtkSourceGutterRenderer *
-_gtk_source_gutter_renderer_lines_new (void)
+gtk_source_gutter_renderer_lines_new (void)
{
return g_object_new (GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, NULL);
}
diff --git a/gtksourceview/gtksourcegutterrendererlines.h b/gtksourceview/gtksourcegutterrendererlines.h
new file mode 100644
index 00000000..5077f68a
--- /dev/null
+++ b/gtksourceview/gtksourcegutterrendererlines.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2010 - Jesse van den Kieboom
+ *
+ * GtkSourceView 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.
+ *
+ * GtkSourceView 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/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+#include "gtksourcegutterrenderertext.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES (gtk_source_gutter_renderer_lines_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER_LINES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLines))
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLines const))
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLinesClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_LINES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_LINES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES))
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLinesClass))
+
+typedef struct _GtkSourceGutterRendererLinesClass GtkSourceGutterRendererLinesClass;
+typedef struct _GtkSourceGutterRendererLinesPrivate GtkSourceGutterRendererLinesPrivate;
+
+struct _GtkSourceGutterRendererLines
+{
+ /*< private >*/
+ GtkSourceGutterRendererText parent;
+
+ GtkSourceGutterRendererLinesPrivate *priv;
+
+ /*< public >*/
+};
+
+struct _GtkSourceGutterRendererLinesClass
+{
+ /*< private >*/
+ GtkSourceGutterRendererTextClass parent_class;
+
+ /*< public >*/
+};
+
+G_GNUC_INTERNAL
+GType gtk_source_gutter_renderer_lines_get_type (void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_lines_new (void);
+
+G_END_DECLS
diff --git a/gtksourceview/gtksourcegutterrendererpixbuf.c b/gtksourceview/gtksourcegutterrendererpixbuf.c
index 46026886..032dd531 100644
--- a/gtksourceview/gtksourcegutterrendererpixbuf.c
+++ b/gtksourceview/gtksourcegutterrendererpixbuf.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcegutterrendererpixbuf.h"
#include "gtksourcepixbufhelper-private.h"
@@ -33,10 +35,10 @@
* #GtkSourceGutter.
*/
-typedef struct
+struct _GtkSourceGutterRendererPixbufPrivate
{
GtkSourcePixbufHelper *helper;
-} GtkSourceGutterRendererPixbufPrivate;
+};
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererPixbuf, gtk_source_gutter_renderer_pixbuf,
GTK_SOURCE_TYPE_GUTTER_RENDERER)
@@ -49,153 +51,50 @@ enum
};
static void
-center_on (GtkSourceGutterRenderer *renderer,
- GdkRectangle *cell_area,
- GtkTextIter *iter,
- gint width,
- gint height,
- gfloat xalign,
- gfloat yalign,
- gint *x,
- gint *y)
-{
- GtkTextView *view;
- GtkTextWindowType window_type;
- GdkRectangle buffer_location;
- gint window_y;
-
- view = gtk_source_gutter_renderer_get_view (renderer);
- window_type = gtk_source_gutter_renderer_get_window_type (renderer);
-
- gtk_text_view_get_iter_location (view, iter, &buffer_location);
-
- gtk_text_view_buffer_to_window_coords (view,
- window_type,
- 0, buffer_location.y,
- NULL, &window_y);
-
- *x = cell_area->x + (cell_area->width - width) * xalign;
- *y = window_y + (buffer_location.height - height) * yalign;
-}
-
-static void
-gutter_renderer_pixbuf_draw (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state)
+gutter_renderer_pixbuf_snapshot_line (GtkSourceGutterRenderer *renderer,
+ GtkSnapshot *snapshot,
+ GtkSourceLines *lines,
+ guint line)
{
GtkSourceGutterRendererPixbuf *pix = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (renderer);
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(pix);
+ GtkWidget *widget = GTK_WIDGET (renderer);
+ GdkPaintable *paintable;
+ GtkSourceView *view;
gint width;
gint height;
- gfloat xalign;
- gfloat yalign;
- GtkSourceGutterRendererAlignmentMode mode;
- GtkTextView *view;
- gint scale;
- gint x = 0;
- gint y = 0;
- GdkPixbuf *pixbuf;
- cairo_surface_t *surface;
-
- /* Chain up to draw background */
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->draw != NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->draw
(renderer,
- cr,
-
background_area,
-
cell_area,
-
start,
- end,
-
state);
- }
+ gfloat x = 0;
+ gfloat y = 0;
+ gint size;
view = gtk_source_gutter_renderer_get_view (renderer);
- pixbuf = gtk_source_pixbuf_helper_render (priv->helper,
- GTK_WIDGET (view),
- cell_area->width);
+ width = gtk_widget_get_width (widget);
+ height = gtk_widget_get_height (widget);
+ size = MIN (width, height);
- if (!pixbuf)
- {
- return;
- }
+ paintable = gtk_source_pixbuf_helper_render (pix->priv->helper,
+ GTK_WIDGET (view),
+ size);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
-
- /*
- * We might have gotten a pixbuf back from the helper that will allow
- * us to render for HiDPI. If we detect this, we pretend that we got a
- * different size back and then gdk_cairo_surface_create_from_pixbuf()
- * will take care of the rest.
- */
- scale = gtk_widget_get_scale_factor (GTK_WIDGET (view));
- if ((scale > 1) &&
- ((width > cell_area->width) || (height > cell_area->height)) &&
- (width <= (cell_area->width * scale)) &&
- (height <= (cell_area->height * scale)))
+ if (paintable == NULL)
{
- width = width / scale;
- height = height / scale;
- }
-
- gtk_source_gutter_renderer_get_alignment (renderer,
- &xalign,
- &yalign);
-
- mode = gtk_source_gutter_renderer_get_alignment_mode (renderer);
-
- switch (mode)
- {
- case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL:
- x = cell_area->x + (cell_area->width - width) * xalign;
- y = cell_area->y + (cell_area->height - height) * yalign;
- break;
- case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST:
- center_on (renderer,
- cell_area,
- start,
- width,
- height,
- xalign,
- yalign,
- &x,
- &y);
- break;
- case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST:
- center_on (renderer,
- cell_area,
- end,
- width,
- height,
- xalign,
- yalign,
- &x,
- &y);
- break;
- default:
- g_assert_not_reached ();
+ return;
}
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
- cairo_set_source_surface (cr, surface, x, y);
-
- cairo_paint (cr);
+ gtk_source_gutter_renderer_align_cell (renderer, line, size, size, &x, &y);
- cairo_surface_destroy (surface);
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
+ gdk_paintable_snapshot (paintable, snapshot, size, size);
+ gtk_snapshot_restore (snapshot);
}
static void
gtk_source_gutter_renderer_pixbuf_finalize (GObject *object)
{
GtkSourceGutterRendererPixbuf *renderer = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (object);
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
- gtk_source_pixbuf_helper_free (priv->helper);
+ gtk_source_pixbuf_helper_free (renderer->priv->helper);
G_OBJECT_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->finalize (object);
}
@@ -204,39 +103,36 @@ static void
set_pixbuf (GtkSourceGutterRendererPixbuf *renderer,
GdkPixbuf *pixbuf)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
-
- gtk_source_pixbuf_helper_set_pixbuf (priv->helper, pixbuf);
+ gtk_source_pixbuf_helper_set_pixbuf (renderer->priv->helper,
+ pixbuf);
g_object_notify (G_OBJECT (renderer), "pixbuf");
- gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
}
static void
set_gicon (GtkSourceGutterRendererPixbuf *renderer,
GIcon *icon)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
-
- gtk_source_pixbuf_helper_set_gicon (priv->helper, icon);
+ gtk_source_pixbuf_helper_set_gicon (renderer->priv->helper,
+ icon);
g_object_notify (G_OBJECT (renderer), "gicon");
- gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
}
static void
set_icon_name (GtkSourceGutterRendererPixbuf *renderer,
const gchar *icon_name)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
-
- gtk_source_pixbuf_helper_set_icon_name (priv->helper, icon_name);
+ gtk_source_pixbuf_helper_set_icon_name (renderer->priv->helper,
+ icon_name);
g_object_notify (G_OBJECT (renderer), "icon-name");
- gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ gtk_widget_queue_draw (GTK_WIDGET (renderer));
}
@@ -273,22 +169,23 @@ gtk_source_gutter_renderer_pixbuf_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GtkSourceGutterRendererPixbuf *renderer = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (object);
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
+ GtkSourceGutterRendererPixbuf *renderer;
+
+ renderer = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (object);
switch (prop_id)
{
case PROP_PIXBUF:
g_value_set_object (value,
- gtk_source_pixbuf_helper_get_pixbuf (priv->helper));
+ gtk_source_pixbuf_helper_get_pixbuf (renderer->priv->helper));
break;
case PROP_ICON_NAME:
g_value_set_string (value,
- gtk_source_pixbuf_helper_get_icon_name (priv->helper));
+ gtk_source_pixbuf_helper_get_icon_name (renderer->priv->helper));
break;
case PROP_GICON:
g_value_set_object (value,
- gtk_source_pixbuf_helper_get_gicon (priv->helper));
+ gtk_source_pixbuf_helper_get_gicon (renderer->priv->helper));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -303,11 +200,10 @@ gtk_source_gutter_renderer_pixbuf_class_init (GtkSourceGutterRendererPixbufClass
GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
object_class->finalize = gtk_source_gutter_renderer_pixbuf_finalize;
-
object_class->get_property = gtk_source_gutter_renderer_pixbuf_get_property;
object_class->set_property = gtk_source_gutter_renderer_pixbuf_set_property;
- renderer_class->draw = gutter_renderer_pixbuf_draw;
+ renderer_class->snapshot_line = gutter_renderer_pixbuf_snapshot_line;
g_object_class_install_property (object_class,
PROP_PIXBUF,
@@ -337,9 +233,9 @@ gtk_source_gutter_renderer_pixbuf_class_init (GtkSourceGutterRendererPixbufClass
static void
gtk_source_gutter_renderer_pixbuf_init (GtkSourceGutterRendererPixbuf *self)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(self);
+ self->priv = gtk_source_gutter_renderer_pixbuf_get_instance_private (self);
- priv->helper = gtk_source_pixbuf_helper_new ();
+ self->priv->helper = gtk_source_pixbuf_helper_new ();
}
/**
@@ -384,11 +280,9 @@ gtk_source_gutter_renderer_pixbuf_set_pixbuf (GtkSourceGutterRendererPixbuf *ren
GdkPixbuf *
gtk_source_gutter_renderer_pixbuf_get_pixbuf (GtkSourceGutterRendererPixbuf *renderer)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
-
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF (renderer), NULL);
- return gtk_source_pixbuf_helper_get_pixbuf (priv->helper);
+ return gtk_source_pixbuf_helper_get_pixbuf (renderer->priv->helper);
}
/**
@@ -418,11 +312,9 @@ gtk_source_gutter_renderer_pixbuf_set_gicon (GtkSourceGutterRendererPixbuf *rend
GIcon *
gtk_source_gutter_renderer_pixbuf_get_gicon (GtkSourceGutterRendererPixbuf *renderer)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
-
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF (renderer), NULL);
- return gtk_source_pixbuf_helper_get_gicon (priv->helper);
+ return gtk_source_pixbuf_helper_get_gicon (renderer->priv->helper);
}
/**
@@ -442,9 +334,7 @@ gtk_source_gutter_renderer_pixbuf_set_icon_name (GtkSourceGutterRendererPixbuf *
const gchar *
gtk_source_gutter_renderer_pixbuf_get_icon_name (GtkSourceGutterRendererPixbuf *renderer)
{
- GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private
(renderer);
-
g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF (renderer), NULL);
- return gtk_source_pixbuf_helper_get_icon_name (priv->helper);
+ return gtk_source_pixbuf_helper_get_icon_name (renderer->priv->helper);
}
diff --git a/gtksourceview/gtksourcegutterrendererpixbuf.h b/gtksourceview/gtksourcegutterrendererpixbuf.h
index ee82b6a4..7b1617d5 100644
--- a/gtksourceview/gtksourcegutterrendererpixbuf.h
+++ b/gtksourceview/gtksourcegutterrendererpixbuf.h
@@ -29,35 +29,60 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF (gtk_source_gutter_renderer_pixbuf_get_type())
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF (gtk_source_gutter_renderer_pixbuf_get_type
())
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbuf))
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbuf const))
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbufClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF))
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbufClass))
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRendererPixbuf, gtk_source_gutter_renderer_pixbuf, GTK_SOURCE,
GUTTER_RENDERER_PIXBUF, GtkSourceGutterRenderer)
+typedef struct _GtkSourceGutterRendererPixbufClass GtkSourceGutterRendererPixbufClass;
+typedef struct _GtkSourceGutterRendererPixbufPrivate GtkSourceGutterRendererPixbufPrivate;
+
+struct _GtkSourceGutterRendererPixbuf
+{
+ /*< private >*/
+ GtkSourceGutterRenderer parent;
+
+ GtkSourceGutterRendererPixbufPrivate *priv;
+
+ /*< public >*/
+};
struct _GtkSourceGutterRendererPixbufClass
{
+ /*< private >*/
GtkSourceGutterRendererClass parent_class;
- /*< private >*/
- gpointer _reserved[10];
+ gpointer padding[10];
};
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_renderer_pixbuf_new (void);
+GType gtk_source_gutter_renderer_pixbuf_get_type (void) G_GNUC_CONST;
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_pixbuf_new (void);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_pixbuf_set_pixbuf (GtkSourceGutterRendererPixbuf
*renderer,
- GdkPixbuf
*pixbuf);
+void gtk_source_gutter_renderer_pixbuf_set_pixbuf (GtkSourceGutterRendererPixbuf *renderer,
+ GdkPixbuf *pixbuf);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GdkPixbuf *gtk_source_gutter_renderer_pixbuf_get_pixbuf (GtkSourceGutterRendererPixbuf
*renderer);
+GdkPixbuf *gtk_source_gutter_renderer_pixbuf_get_pixbuf (GtkSourceGutterRendererPixbuf *renderer);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_pixbuf_set_gicon (GtkSourceGutterRendererPixbuf
*renderer,
- GIcon
*icon);
+void gtk_source_gutter_renderer_pixbuf_set_gicon (GtkSourceGutterRendererPixbuf *renderer,
+ GIcon *icon);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GIcon *gtk_source_gutter_renderer_pixbuf_get_gicon (GtkSourceGutterRendererPixbuf
*renderer);
+GIcon *gtk_source_gutter_renderer_pixbuf_get_gicon (GtkSourceGutterRendererPixbuf *renderer);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_pixbuf_set_icon_name (GtkSourceGutterRendererPixbuf
*renderer,
- const gchar
*icon_name);
+void gtk_source_gutter_renderer_pixbuf_set_icon_name (GtkSourceGutterRendererPixbuf *renderer,
+ const gchar *icon_name);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_gutter_renderer_pixbuf_get_icon_name (GtkSourceGutterRendererPixbuf
*renderer);
+const gchar *gtk_source_gutter_renderer_pixbuf_get_icon_name (GtkSourceGutterRendererPixbuf *renderer);
G_END_DECLS
diff --git a/gtksourceview/gtksourcegutterrenderertext.c b/gtksourceview/gtksourcegutterrenderertext.c
index c8085afe..643a521a 100644
--- a/gtksourceview/gtksourcegutterrenderertext.c
+++ b/gtksourceview/gtksourcegutterrenderertext.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcegutterrenderertext.h"
@@ -32,14 +34,14 @@
* #GtkSourceGutter.
*/
-typedef struct
+struct _GtkSourceGutterRendererTextPrivate
{
- gchar *text;
-
+ gchar *text;
PangoLayout *cached_layout;
-
- guint is_markup : 1;
-} GtkSourceGutterRendererTextPrivate;
+ GdkRGBA cached_color;
+ gsize text_len;
+ guint is_markup : 1;
+};
G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererText, gtk_source_gutter_renderer_text,
GTK_SOURCE_TYPE_GUTTER_RENDERER)
@@ -47,171 +49,86 @@ enum
{
PROP_0,
PROP_MARKUP,
- PROP_TEXT
+ PROP_TEXT,
+ N_PROPS
};
static void
-gutter_renderer_text_begin (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end)
+gtk_source_gutter_renderer_text_begin (GtkSourceGutterRenderer *renderer,
+ GtkSourceLines *lines)
{
- GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(text);
- GtkTextView *view;
- view = gtk_source_gutter_renderer_get_view (renderer);
-
- g_clear_object (&priv->cached_layout);
- priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);
-
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin != NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin
(renderer,
- cr,
-
background_area,
-
cell_area,
- start,
- end);
- }
-}
-
-static void
-center_on (GtkTextView *view,
- GdkRectangle *cell_area,
- GtkTextIter *iter,
- gint width,
- gint height,
- gfloat xalign,
- gfloat yalign,
- gint *x,
- gint *y)
-{
- GdkRectangle location;
+ GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
- gtk_text_view_get_iter_location (view, iter, &location);
+ GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin (renderer,
lines);
- *x = cell_area->x + (cell_area->width - width) * xalign;
- *y = cell_area->y + (location.height - height) * yalign;
+ g_clear_object (&text->priv->cached_layout);
+ text->priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (renderer), NULL);
}
static void
-gutter_renderer_text_draw (GtkSourceGutterRenderer *renderer,
- cairo_t *cr,
- GdkRectangle *background_area,
- GdkRectangle *cell_area,
- GtkTextIter *start,
- GtkTextIter *end,
- GtkSourceGutterRendererState state)
+gtk_source_gutter_renderer_text_snapshot_line (GtkSourceGutterRenderer *renderer,
+ GtkSnapshot *snapshot,
+ GtkSourceLines *lines,
+ guint line)
{
GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(text);
- GtkTextView *view;
+ PangoLayout *layout;
+ gfloat x;
+ gfloat y;
gint width;
gint height;
- gfloat xalign;
- gfloat yalign;
- GtkSourceGutterRendererAlignmentMode mode;
- gint x = 0;
- gint y = 0;
- GtkStyleContext *context;
-
- /* Chain up to draw background */
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw != NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw
(renderer,
- cr,
-
background_area,
-
cell_area,
- start,
- end,
- state);
- }
-
- view = gtk_source_gutter_renderer_get_view (renderer);
- if (priv->is_markup)
- {
- pango_layout_set_markup (priv->cached_layout,
- priv->text,
- -1);
- }
- else
+ if (text->priv->text == NULL || text->priv->text_len == 0)
{
- pango_layout_set_text (priv->cached_layout,
- priv->text,
- -1);
+ return;
}
- pango_layout_get_pixel_size (priv->cached_layout, &width, &height);
+ layout = text->priv->cached_layout;
- gtk_source_gutter_renderer_get_alignment (renderer,
- &xalign,
- &yalign);
-
- /* Avoid calculations if we don't wrap text */
- if (gtk_text_view_get_wrap_mode (view) == GTK_WRAP_NONE)
+ if (text->priv->is_markup)
{
- mode = GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL;
+ pango_layout_set_markup (layout,
+ text->priv->text,
+ text->priv->text_len);
}
else
{
- mode = gtk_source_gutter_renderer_get_alignment_mode (renderer);
+ pango_layout_set_text (layout,
+ text->priv->text,
+ text->priv->text_len);
}
- switch (mode)
- {
- case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL:
- x = cell_area->x + (cell_area->width - width) * xalign;
- y = cell_area->y + (cell_area->height - height) * yalign;
- break;
+ pango_layout_get_pixel_size (layout, &width, &height);
- case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST:
- center_on (view,
- cell_area,
- start,
- width,
- height,
- xalign,
- yalign,
- &x,
- &y);
- break;
+ gtk_source_gutter_renderer_align_cell (renderer,
+ line,
+ width,
+ height,
+ &x,
+ &y);
- case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST:
- center_on (view,
- cell_area,
- end,
- width,
- height,
- xalign,
- yalign,
- &x,
- &y);
- break;
+ gtk_snapshot_render_layout (snapshot,
+ gtk_widget_get_style_context (GTK_WIDGET (text)),
+ x,
+ y,
+ layout);
- default:
- g_assert_not_reached ();
+ if (text->priv->is_markup)
+ {
+ pango_layout_set_attributes (layout, NULL);
}
-
- context = gtk_widget_get_style_context (GTK_WIDGET (view));
- gtk_render_layout (context, cr, x, y, priv->cached_layout);
}
static void
-gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
+gtk_source_gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
{
+
GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(text);
- g_clear_object (&priv->cached_layout);
+ GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end (renderer);
- if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end != NULL)
- {
- GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end
(renderer);
- }
+ g_clear_object (&text->priv->cached_layout);
}
static void
@@ -221,7 +138,7 @@ measure_text (GtkSourceGutterRendererText *renderer,
gint *width,
gint *height)
{
- GtkTextView *view;
+ GtkSourceView *view;
PangoLayout *layout;
view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (renderer));
@@ -290,14 +207,52 @@ gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText *ren
measure_text (renderer, markup, NULL, width, height);
}
+static void
+gtk_source_gutter_renderer_text_real_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
+{
+ GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (widget);
+
+ *minimum = 0;
+ *natural = 0;
+ *minimum_baseline = -1;
+ *natural_baseline = -1;
+
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ gint xpad = gtk_source_gutter_renderer_get_xpad (GTK_SOURCE_GUTTER_RENDERER (renderer));
+ gint width = 0;
+ gint height = 0;
+
+ if (renderer->priv->text != NULL)
+ {
+ if (renderer->priv->is_markup)
+ {
+ measure_text (renderer, renderer->priv->text, NULL, &width, &height);
+ }
+ else
+ {
+ measure_text (renderer, NULL, renderer->priv->text, &width, &height);
+ }
+ }
+
+ *natural = *minimum = width + 2 * xpad;
+ }
+
+}
+
static void
gtk_source_gutter_renderer_text_finalize (GObject *object)
{
GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(renderer);
- g_free (priv->text);
- g_clear_object (&priv->cached_layout);
+ g_clear_pointer (&renderer->priv->text, g_free);
+ g_clear_object (&renderer->priv->cached_layout);
G_OBJECT_CLASS (gtk_source_gutter_renderer_text_parent_class)->finalize (object);
}
@@ -308,12 +263,20 @@ set_text (GtkSourceGutterRendererText *renderer,
gint length,
gboolean is_markup)
{
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(renderer);
-
- g_free (priv->text);
+ g_free (renderer->priv->text);
- priv->text = length >= 0 ? g_strndup (text, length) : g_strdup (text);
- priv->is_markup = is_markup;
+ if (text == NULL)
+ {
+ renderer->priv->text_len = 0;
+ renderer->priv->text = NULL;
+ renderer->priv->is_markup = FALSE;
+ }
+ else
+ {
+ renderer->priv->text_len = length >= 0 ? length : strlen (text);
+ renderer->priv->text = g_strndup (text, renderer->priv->text_len);
+ renderer->priv->is_markup = !!is_markup;
+ }
}
static void
@@ -346,16 +309,17 @@ gtk_source_gutter_renderer_text_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(renderer);
+ GtkSourceGutterRendererText *renderer;
+
+ renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
switch (prop_id)
{
case PROP_MARKUP:
- g_value_set_string (value, priv->is_markup ? priv->text : NULL);
+ g_value_set_string (value, renderer->priv->is_markup ? renderer->priv->text : NULL);
break;
case PROP_TEXT:
- g_value_set_string (value, !priv->is_markup ? priv->text : NULL);
+ g_value_set_string (value, !renderer->priv->is_markup ? renderer->priv->text : NULL);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -367,16 +331,18 @@ static void
gtk_source_gutter_renderer_text_class_init (GtkSourceGutterRendererTextClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
object_class->finalize = gtk_source_gutter_renderer_text_finalize;
-
object_class->get_property = gtk_source_gutter_renderer_text_get_property;
object_class->set_property = gtk_source_gutter_renderer_text_set_property;
- renderer_class->begin = gutter_renderer_text_begin;
- renderer_class->draw = gutter_renderer_text_draw;
- renderer_class->end = gutter_renderer_text_end;
+ widget_class->measure = gtk_source_gutter_renderer_text_real_measure;
+
+ renderer_class->begin = gtk_source_gutter_renderer_text_begin;
+ renderer_class->end = gtk_source_gutter_renderer_text_end;
+ renderer_class->snapshot_line = gtk_source_gutter_renderer_text_snapshot_line;
g_object_class_install_property (object_class,
PROP_MARKUP,
@@ -398,9 +364,9 @@ gtk_source_gutter_renderer_text_class_init (GtkSourceGutterRendererTextClass *kl
static void
gtk_source_gutter_renderer_text_init (GtkSourceGutterRendererText *self)
{
- GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private
(self);
+ self->priv = gtk_source_gutter_renderer_text_get_instance_private (self);
- priv->is_markup = TRUE;
+ self->priv->is_markup = TRUE;
}
/**
diff --git a/gtksourceview/gtksourcegutterrenderertext.h b/gtksourceview/gtksourcegutterrenderertext.h
index c31600c6..1ebc8253 100644
--- a/gtksourceview/gtksourcegutterrenderertext.h
+++ b/gtksourceview/gtksourcegutterrenderertext.h
@@ -29,38 +29,61 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT (gtk_source_gutter_renderer_text_get_type())
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT (gtk_source_gutter_renderer_text_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererText))
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererText const))
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererTextClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT))
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererTextClass))
+
+typedef struct _GtkSourceGutterRendererTextClass GtkSourceGutterRendererTextClass;
+typedef struct _GtkSourceGutterRendererTextPrivate GtkSourceGutterRendererTextPrivate;
+
+struct _GtkSourceGutterRendererText
+{
+ /*< private >*/
+ GtkSourceGutterRenderer parent;
+
+ GtkSourceGutterRendererTextPrivate *priv;
+
+ /*< public >*/
+};
struct _GtkSourceGutterRendererTextClass
{
+ /*< private >*/
GtkSourceGutterRendererClass parent_class;
- /*< private >*/
- gpointer _reserved[10];
+ gpointer padding[10];
};
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRendererText, gtk_source_gutter_renderer_text, GTK_SOURCE,
GUTTER_RENDERER_TEXT, GtkSourceGutterRenderer)
+GType gtk_source_gutter_renderer_text_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_renderer_text_new (void);
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_text_new (void);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_set_markup (GtkSourceGutterRendererText
*renderer,
- const gchar *markup,
- gint
length);
+void gtk_source_gutter_renderer_text_set_markup (GtkSourceGutterRendererText *renderer,
+ const gchar *markup,
+ gint length);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_set_text (GtkSourceGutterRendererText
*renderer,
- const gchar *text,
- gint
length);
+void gtk_source_gutter_renderer_text_set_text (GtkSourceGutterRendererText *renderer,
+ const gchar *text,
+ gint length);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_measure (GtkSourceGutterRendererText
*renderer,
- const gchar *text,
- gint *width,
- gint
*height);
+void gtk_source_gutter_renderer_text_measure (GtkSourceGutterRendererText *renderer,
+ const gchar *text,
+ gint *width,
+ gint *height);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText
*renderer,
- const gchar *markup,
- gint *width,
- gint
*height);
+void gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText *renderer,
+ const gchar *markup,
+ gint *width,
+ gint *height);
G_END_DECLS
diff --git a/gtksourceview/gtksourceinit.c b/gtksourceview/gtksourceinit.c
index d13e5918..44f44f58 100644
--- a/gtksourceview/gtksourceinit.c
+++ b/gtksourceview/gtksourceinit.c
@@ -18,13 +18,21 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <glib/gi18n-lib.h>
#include "gtksourceinit.h"
+#include "gtksourcegutterrendererlines.h"
+#include "gtksourcegutterrenderertext.h"
#include "gtksourcelanguagemanager-private.h"
+#include "gtksourcemap.h"
+#include "gtksourcestyleschemechooserbutton.h"
+#include "gtksourcestyleschemechooserwidget.h"
#include "gtksourcestyleschememanager-private.h"
+#include "gtksourceview.h"
#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN
@@ -156,6 +164,13 @@ gtk_source_init (void)
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ g_type_ensure (GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES);
+ g_type_ensure (GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT);
+ g_type_ensure (GTK_SOURCE_TYPE_MAP);
+ g_type_ensure (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON);
+ g_type_ensure (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET);
+ g_type_ensure (GTK_SOURCE_TYPE_VIEW);
+
done = TRUE;
}
}
diff --git a/gtksourceview/gtksourceinit.h b/gtksourceview/gtksourceinit.h
index 87898b76..bedb8af7 100644
--- a/gtksourceview/gtksourceinit.h
+++ b/gtksourceview/gtksourceinit.h
@@ -30,8 +30,9 @@
G_BEGIN_DECLS
GTK_SOURCE_AVAILABLE_IN_4_0
-void gtk_source_init (void);
+void gtk_source_init (void);
+
GTK_SOURCE_AVAILABLE_IN_4_0
-void gtk_source_finalize (void);
+void gtk_source_finalize (void);
G_END_DECLS
diff --git a/gtksourceview/gtksourceiter.c b/gtksourceview/gtksourceiter.c
index bafc842e..c974fa89 100644
--- a/gtksourceview/gtksourceiter.c
+++ b/gtksourceview/gtksourceiter.c
@@ -18,9 +18,11 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
/* GtkTextIter functions. Contains forward/backward functions for word
* movements, with custom word boundaries that are used for word selection
@@ -66,21 +68,14 @@ _gtk_source_iter_forward_full_word_end (GtkTextIter *iter)
while (g_unichar_isspace (gtk_text_iter_get_char (&pos)))
{
- if (!gtk_text_iter_forward_visible_cursor_position (&pos))
- {
- break;
- }
+ gtk_text_iter_forward_visible_cursor_position (&pos);
}
while (!gtk_text_iter_is_end (&pos) &&
!g_unichar_isspace (gtk_text_iter_get_char (&pos)))
{
non_blank_found = TRUE;
-
- if (!gtk_text_iter_forward_visible_cursor_position (&pos))
- {
- break;
- }
+ gtk_text_iter_forward_visible_cursor_position (&pos);
}
if (non_blank_found)
@@ -102,11 +97,7 @@ _gtk_source_iter_backward_full_word_start (GtkTextIter *iter)
while (!gtk_text_iter_is_start (&pos))
{
prev = pos;
-
- if (!gtk_text_iter_backward_visible_cursor_position (&prev))
- {
- break;
- }
+ gtk_text_iter_backward_visible_cursor_position (&prev);
if (!g_unichar_isspace (gtk_text_iter_get_char (&prev)))
{
@@ -119,11 +110,7 @@ _gtk_source_iter_backward_full_word_start (GtkTextIter *iter)
while (!gtk_text_iter_is_start (&pos))
{
prev = pos;
-
- if (!gtk_text_iter_backward_visible_cursor_position (&prev))
- {
- break;
- }
+ gtk_text_iter_backward_visible_cursor_position (&prev);
if (g_unichar_isspace (gtk_text_iter_get_char (&prev)))
{
@@ -210,17 +197,11 @@ _gtk_source_iter_forward_extra_natural_word_end (GtkTextIter *iter)
{
if (gtk_text_iter_get_char (iter) == '_')
{
- if (!gtk_text_iter_forward_visible_cursor_position (iter))
- {
- break;
- }
+ gtk_text_iter_forward_visible_cursor_position (iter);
}
else if (gtk_text_iter_starts_word (iter))
{
- if (!gtk_text_iter_forward_visible_word_end (iter))
- {
- break;
- }
+ gtk_text_iter_forward_visible_word_end (iter);
}
else
{
@@ -262,11 +243,7 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
while (!gtk_text_iter_is_start (iter))
{
GtkTextIter prev = *iter;
-
- if (!gtk_text_iter_backward_visible_cursor_position (&prev))
- {
- break;
- }
+ gtk_text_iter_backward_visible_cursor_position (&prev);
if (gtk_text_iter_get_char (&prev) == '_')
{
@@ -274,10 +251,7 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
}
else if (gtk_text_iter_ends_word (iter))
{
- if (!gtk_text_iter_backward_visible_word_start (iter))
- {
- break;
- }
+ gtk_text_iter_backward_visible_word_start (iter);
}
else
{
diff --git a/gtksourceview/gtksourceiter.h b/gtksourceview/gtksourceiter.h
new file mode 100644
index 00000000..a8f3660a
--- /dev/null
+++ b/gtksourceview/gtksourceiter.h
@@ -0,0 +1,95 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2014, 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView 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.
+ *
+ * GtkSourceView 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/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes-private.h"
+
+G_BEGIN_DECLS
+
+/* Semi-public functions. */
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_forward_visible_word_end (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_forward_visible_word_ends (GtkTextIter *iter,
+ gint count);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_backward_visible_word_start (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_backward_visible_word_starts (GtkTextIter *iter,
+ gint count);
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_extend_selection_word (const GtkTextIter *location,
+ GtkTextIter *start,
+ GtkTextIter *end);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter,
+ gboolean visible);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_ends_extra_natural_word (const GtkTextIter *iter,
+ gboolean visible);
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_get_leading_spaces_end_boundary (const GtkTextIter *iter,
+ GtkTextIter *leading_end);
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_get_trailing_spaces_start_boundary (const GtkTextIter *iter,
+ GtkTextIter *trailing_start);
+
+/* Internal functions, in the header for unit tests. */
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_forward_full_word_end (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_backward_full_word_start (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_starts_full_word (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_ends_full_word (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_forward_extra_natural_word_end (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+void _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_starts_word (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_ends_word (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_inside_word (const GtkTextIter *iter);
+
+G_END_DECLS
diff --git a/gtksourceview/gtksourcecompletioncontainer-private.h b/gtksourceview/gtksourcelines-private.h
similarity index 59%
rename from gtksourceview/gtksourcecompletioncontainer-private.h
rename to gtksourceview/gtksourcelines-private.h
index dbb5af44..02be73e4 100644
--- a/gtksourceview/gtksourcecompletioncontainer-private.h
+++ b/gtksourceview/gtksourcelines-private.h
@@ -1,8 +1,8 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- /
*
* This file is part of GtkSourceView
*
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2019 - Christian Hergert <chergert redhat com>
*
* GtkSourceView is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,16 +22,17 @@
#include <gtk/gtk.h>
-#include "gtksourcetypes-private.h"
+#include "gtksourcelines.h"
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_COMPLETION_CONTAINER (_gtk_source_completion_container_get_type())
-
G_GNUC_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceCompletionContainer, _gtk_source_completion_container, GTK_SOURCE,
COMPLETION_CONTAINER, GtkScrolledWindow)
-
+GtkSourceLines *_gtk_source_lines_new (GtkTextView *text_view,
+ const GtkTextIter *begin,
+ const GtkTextIter *end,
+ gboolean needs_wrap_first,
+ gboolean needs_wrap_last);
G_GNUC_INTERNAL
-GtkSourceCompletionContainer *_gtk_source_completion_container_new (void);
+guint _gtk_source_lines_get_cursor_line (GtkSourceLines *lines);
G_END_DECLS
diff --git a/gtksourceview/gtksourcelines.c b/gtksourceview/gtksourcelines.c
new file mode 100644
index 00000000..6995fe90
--- /dev/null
+++ b/gtksourceview/gtksourcelines.c
@@ -0,0 +1,641 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- /
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2019 - Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView 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.
+ *
+ * GtkSourceView 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 "gtksourcelines.h"
+#include "gtksourcelines-private.h"
+
+#include "quarkset-inline.h"
+
+struct _GtkSourceLines
+{
+ GObject parent_instance;
+ GtkTextView *view;
+ GArray *lines;
+ GdkRectangle visible_rect;
+ guint first;
+ guint last;
+ guint cursor_line;
+};
+
+typedef struct
+{
+ QuarkSet classes;
+ gint y;
+ gint height;
+ gint first_height;
+ gint last_height;
+} LineInfo;
+
+G_DEFINE_TYPE (GtkSourceLines, gtk_source_lines, G_TYPE_OBJECT)
+
+static GQuark q_cursor_line;
+static GQuark q_prelit;
+static GQuark q_selected;
+
+static void
+gtk_source_lines_finalize (GObject *object)
+{
+ GtkSourceLines *lines = (GtkSourceLines *)object;
+
+ g_clear_pointer (&lines->lines, g_array_unref);
+ g_clear_object (&lines->view);
+
+ G_OBJECT_CLASS (gtk_source_lines_parent_class)->finalize (object);
+}
+
+static void
+gtk_source_lines_class_init (GtkSourceLinesClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtk_source_lines_finalize;
+
+ q_cursor_line = g_quark_from_static_string ("cursor-line");
+ q_prelit = g_quark_from_static_string ("prelit");
+ q_selected = g_quark_from_static_string ("selected");
+}
+
+static void
+gtk_source_lines_init (GtkSourceLines *self)
+{
+ self->cursor_line = -1;
+}
+
+static void
+clear_line_info (gpointer data)
+{
+ LineInfo *info = data;
+
+ info->y = 0;
+ info->height = 0;
+ quark_set_clear (&info->classes);
+}
+
+GtkSourceLines *
+_gtk_source_lines_new (GtkTextView *text_view,
+ const GtkTextIter *begin,
+ const GtkTextIter *end,
+ gboolean needs_wrap_first,
+ gboolean needs_wrap_last)
+{
+ GtkSourceLines *lines;
+ GtkTextBuffer *buffer;
+ GtkTextMark *mark;
+ GtkTextIter iter;
+ gboolean single_line;
+ guint cursor_line;
+ guint i;
+
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
+ g_return_val_if_fail (begin != NULL, NULL);
+ g_return_val_if_fail (end != NULL, NULL);
+ g_return_val_if_fail (begin != end, NULL);
+
+ buffer = gtk_text_view_get_buffer (text_view);
+
+ g_return_val_if_fail (gtk_text_iter_get_buffer (begin) == buffer, NULL);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL);
+
+ if (gtk_text_iter_compare (begin, end) > 0)
+ {
+ const GtkTextIter *tmp = begin;
+ begin = end;
+ end = tmp;
+ }
+
+ g_return_val_if_fail (begin != end, NULL);
+
+ lines = g_object_new (GTK_SOURCE_TYPE_LINES, NULL);
+ lines->view = g_object_ref (text_view);
+ lines->first = gtk_text_iter_get_line (begin);
+ lines->last = gtk_text_iter_get_line (end);
+ lines->lines = g_array_sized_new (FALSE,
+ FALSE,
+ sizeof (LineInfo),
+ lines->last - lines->first + 1);
+ g_array_set_clear_func (lines->lines, clear_line_info);
+ gtk_text_view_get_visible_rect (text_view, &lines->visible_rect);
+
+ /* No need to calculate special wrapping if wrap mode is none */
+ if (gtk_text_view_get_wrap_mode (text_view) == GTK_WRAP_NONE)
+ {
+ needs_wrap_first = FALSE;
+ needs_wrap_last = FALSE;
+ }
+
+ single_line = !needs_wrap_first && !needs_wrap_last;
+
+ /* Get the line number containing the cursor to compare while
+ * building the lines to add the "cursor-line" quark.
+ */
+ mark = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+ cursor_line = gtk_text_iter_get_line (&iter);
+
+ lines->cursor_line = cursor_line;
+
+ iter = *begin;
+
+ if (!gtk_text_iter_starts_line (&iter))
+ {
+ gtk_text_iter_set_line_offset (&iter, 0);
+ }
+
+ for (i = lines->first; i <= lines->last; i++)
+ {
+ LineInfo info = {0};
+
+ if G_LIKELY (single_line)
+ {
+ GdkRectangle rect;
+
+ gtk_text_view_get_iter_location (text_view, &iter, &rect);
+
+ info.y = rect.y;
+ info.height = rect.height;
+ info.first_height = rect.height;
+ info.last_height = rect.height;
+ }
+ else
+ {
+ gtk_text_view_get_line_yrange (text_view,
+ &iter,
+ &info.y,
+ &info.height);
+
+ if (gtk_text_iter_starts_line (&iter) &&
+ gtk_text_iter_ends_line (&iter))
+ {
+ info.first_height = info.height;
+ info.last_height = info.height;
+ }
+ else
+ {
+ GdkRectangle rect;
+
+ if (needs_wrap_first)
+ {
+
+ gtk_text_view_get_iter_location (text_view,
+ &iter,
+ &rect);
+ info.first_height = rect.height;
+ }
+ else
+ {
+ info.first_height = info.height;
+ }
+
+ if (needs_wrap_last)
+ {
+ gtk_text_iter_forward_to_line_end (&iter);
+ gtk_text_view_get_iter_location (text_view,
+ &iter,
+ &rect);
+ info.last_height = rect.height;
+ }
+ else
+ {
+ info.last_height = info.height;
+ }
+ }
+ }
+
+ if G_UNLIKELY (i == cursor_line)
+ {
+ quark_set_add (&info.classes, q_cursor_line);
+ }
+
+ g_array_append_val (lines->lines, info);
+
+ if G_UNLIKELY (!gtk_text_iter_forward_line (&iter) &&
+ !gtk_text_iter_is_end (&iter))
+ {
+ break;
+ }
+ }
+
+ g_return_val_if_fail (lines->lines->len > 0, NULL);
+ g_return_val_if_fail ((lines->last - lines->first) >= (lines->lines->len - 1), NULL);
+
+ return g_steal_pointer (&lines);
+}
+
+/**
+ * gtk_source_lines_add_qclass:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @qname: a class name as a #GQuark
+ *
+ * Adds the class denoted by @qname to @line.
+ *
+ * You may check if a line has @qname by calling
+ * gtk_source_lines_has_qclass().
+ *
+ * You can remove @qname by calling
+ * gtk_source_lines_remove_qclass().
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_add_qclass (GtkSourceLines *lines,
+ guint line,
+ GQuark qname)
+{
+ LineInfo *info;
+
+ g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+ g_return_if_fail (qname != 0);
+ g_return_if_fail (line >= lines->first);
+ g_return_if_fail (line <= lines->last);
+ g_return_if_fail (line - lines->first < lines->lines->len);
+
+ info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+ quark_set_add (&info->classes, qname);
+}
+
+/**
+ * gtk_source_lines_add_class:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @name: a class name
+ *
+ * Adds the class @name to @line.
+ *
+ * @name will be converted to a #GQuark as part of this process. A
+ * faster version of this function is available via
+ * gtk_source_lines_add_qclass() for situations where the #GQuark is
+ * known ahead of time.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_add_class (GtkSourceLines *lines,
+ guint line,
+ const gchar *name)
+{
+ g_return_if_fail (name != NULL);
+
+ gtk_source_lines_add_qclass (lines,
+ line,
+ g_quark_from_string (name));
+}
+
+/**
+ * gtk_source_lines_remove_class:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @name: a class name
+ *
+ * Removes the class matching @name from @line.
+ *
+ * A faster version of this function is available via
+ * gtk_source_lines_remove_qclass() for situations where the
+ * #GQuark is known ahead of time.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_remove_class (GtkSourceLines *lines,
+ guint line,
+ const gchar *name)
+{
+ GQuark qname;
+
+ g_return_if_fail (name != NULL);
+
+ qname = g_quark_try_string (name);
+
+ if (qname != 0)
+ {
+ gtk_source_lines_remove_qclass (lines, line, qname);
+ }
+}
+
+/**
+ * gtk_source_lines_remove_qclass:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @qname: a #GQuark to remove from @line
+ *
+ * Reverses a call to gtk_source_lines_add_qclass() by removing
+ * the #GQuark matching @qname.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_remove_qclass (GtkSourceLines *lines,
+ guint line,
+ GQuark qname)
+{
+ LineInfo *info;
+
+ g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+ g_return_if_fail (qname != 0);
+ g_return_if_fail (line >= lines->first);
+ g_return_if_fail (line <= lines->last);
+ g_return_if_fail (line - lines->first < lines->lines->len);
+
+ info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+ quark_set_remove (&info->classes, qname);
+}
+
+/**
+ * gtk_source_lines_has_class:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @name: a class name that may be convered to a #GQuark
+ *
+ * Checks to see if gtk_source_lines_add_class() was called with
+ * the @name for @line.
+ *
+ * A faster version of this function is provided via
+ * gtk_source_lines_has_qclass() for situations where the quark
+ * is known ahead of time.
+ *
+ * Returns: %TRUE if @line contains @name
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_has_class (GtkSourceLines *lines,
+ guint line,
+ const gchar *name)
+{
+ GQuark qname;
+
+ g_return_val_if_fail (name != NULL, FALSE);
+
+ qname = g_quark_try_string (name);
+
+ if (qname == 0)
+ {
+ return FALSE;
+ }
+
+ return gtk_source_lines_has_qclass (lines, line, qname);
+}
+
+/**
+ * gtk_source_lines_has_qclass:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @qname: a #GQuark containing the class name
+ *
+ * Checks to see if gtk_source_lines_add_qclass() was called with
+ * the quark denoted by @qname for @line.
+ *
+ * Returns: %TRUE if @line contains @qname
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_has_qclass (GtkSourceLines *lines,
+ guint line,
+ GQuark qname)
+{
+ LineInfo *info;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), FALSE);
+ g_return_val_if_fail (qname != 0, FALSE);
+ g_return_val_if_fail (line >= lines->first, FALSE);
+ g_return_val_if_fail (line <= lines->last, FALSE);
+ g_return_val_if_fail (line - lines->first < lines->lines->len, FALSE);
+
+ info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+
+ return quark_set_contains (&info->classes, qname);
+}
+
+/**
+ * gtk_source_lines_is_cursor:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ *
+ * Checks to see if @line contains the insertion cursor.
+ *
+ * Returns: %TRUE if the insertion cursor is on @line
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_is_cursor (GtkSourceLines *lines,
+ guint line)
+{
+ return gtk_source_lines_has_qclass (lines, line, q_cursor_line);
+}
+
+/**
+ * gtk_source_lines_is_prelit:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ *
+ * Checks to see if @line is marked as prelit. Generally, this means
+ * the mouse pointer is over the line within the gutter.
+ *
+ * Returns: %TRUE if the line is prelit
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_is_prelit (GtkSourceLines *lines,
+ guint line)
+{
+ return gtk_source_lines_has_qclass (lines, line, q_prelit);
+}
+
+/**
+ * gtk_source_lines_is_selected:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ *
+ * Checks to see if the view had a selection and if that selection overlaps
+ * @line in some way.
+ *
+ * Returns: %TRUE if the line contains a selection
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_is_selected (GtkSourceLines *lines,
+ guint line)
+{
+ return gtk_source_lines_has_qclass (lines, line, q_selected);
+}
+
+/**
+ * gtk_source_lines_get_first:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the line number (starting from 0) for the first line that is
+ * user visible.
+ *
+ * Returns: a line number starting from 0
+ *
+ * Since: 5.0
+ */
+guint
+gtk_source_lines_get_first (GtkSourceLines *lines)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), 0);
+
+ return lines->first;
+}
+
+/**
+ * gtk_source_lines_get_last:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the line number (starting from 0) for the last line that is
+ * user visible.
+ *
+ * Returns: a line number starting from 0
+ *
+ * Since: 5.0
+ */
+guint
+gtk_source_lines_get_last (GtkSourceLines *lines)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), 0);
+
+ return lines->last;
+}
+
+/**
+ * gtk_source_lines_get_iter_at_line:
+ * @lines: a #GtkSourceLines
+ * @iter: (out): a location for a #GtkTextIter
+ * @line: the line number
+ *
+ * Gets a #GtkTextIter for the current buffer at @line
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_get_iter_at_line (GtkSourceLines *lines,
+ GtkTextIter *iter,
+ guint line)
+{
+ GtkTextBuffer *buffer;
+
+ g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+ g_return_if_fail (iter != NULL);
+
+ buffer = gtk_text_view_get_buffer (lines->view);
+ gtk_text_buffer_get_iter_at_line (buffer, iter, line);
+}
+
+/**
+ * gtk_source_lines_get_view:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the #GtkTextView that the #GtkSourceLines represents.
+ *
+ * Returns: (transfer none) (not nullable): a #GtkTextView
+ *
+ * Since: 5.0
+ */
+GtkTextView *
+gtk_source_lines_get_view (GtkSourceLines *lines)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), NULL);
+
+ return lines->view;
+}
+
+/**
+ * gtk_source_lines_get_buffer:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the #GtkTextBuffer that the #GtkSourceLines represents.
+ *
+ * Returns: (transfer none) (not nullable): a #GtkTextBuffer
+ *
+ * Since: 5.0
+ */
+GtkTextBuffer *
+gtk_source_lines_get_buffer (GtkSourceLines *lines)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), NULL);
+
+ return gtk_text_view_get_buffer (lines->view);
+}
+
+/**
+ * gtk_source_lines_get_line_yrange:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @mode: a #GtkSourceGutterRendererAlignmentMode
+ * @y: (out): a location for the Y position in widget coordinates
+ * @height: (out): the line height based on @mode
+ *
+ * Gets the Y range for a line based on @mode.
+ *
+ * The value for @y is relative to the renderers widget coordinates.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_get_line_yrange (GtkSourceLines *lines,
+ guint line,
+ GtkSourceGutterRendererAlignmentMode mode,
+ gint *y,
+ gint *height)
+{
+ LineInfo *info;
+
+ g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+ g_return_if_fail (line >= lines->first);
+ g_return_if_fail (line <= lines->last);
+
+ info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+
+ if (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL)
+ {
+ *y = info->y;
+ *height = info->height;
+ }
+ else if (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST)
+ {
+ *y = info->y;
+ *height = info->first_height;
+ }
+ else if (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST)
+ {
+ *y = info->y + info->height - info->last_height;
+ *height = info->last_height;
+ }
+ else
+ {
+ g_return_if_reached ();
+ }
+
+ *y -= lines->visible_rect.y;
+}
+
+guint
+_gtk_source_lines_get_cursor_line (GtkSourceLines *lines)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), 0);
+
+ return lines->cursor_line;
+}
diff --git a/gtksourceview/gtksourcelines.h b/gtksourceview/gtksourcelines.h
new file mode 100644
index 00000000..d1b57d4b
--- /dev/null
+++ b/gtksourceview/gtksourcelines.h
@@ -0,0 +1,96 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- /
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2019 - Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView 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.
+ *
+ * GtkSourceView 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/>.
+ */
+
+#pragma once
+
+#if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
+#error "Only <gtksourceview/gtksource.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes.h"
+#include "gtksourcegutterrenderer.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_LINES (gtk_source_lines_get_type())
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkSourceLines, gtk_source_lines, GTK_SOURCE, LINES, GObject)
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+guint gtk_source_lines_get_first (GtkSourceLines *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+guint gtk_source_lines_get_last (GtkSourceLines *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_get_iter_at_line (GtkSourceLines *lines,
+ GtkTextIter *iter,
+ guint line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkTextView *gtk_source_lines_get_view (GtkSourceLines *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkTextBuffer *gtk_source_lines_get_buffer (GtkSourceLines *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_get_yrange (GtkSourceLines *lines,
+ guint line,
+ guint *line_y,
+ guint *line_height);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_add_qclass (GtkSourceLines *lines,
+ guint line,
+ GQuark qname);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_add_class (GtkSourceLines *lines,
+ guint line,
+ const gchar *name);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_remove_class (GtkSourceLines *lines,
+ guint line,
+ const gchar *name);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_remove_qclass (GtkSourceLines *lines,
+ guint line,
+ GQuark qname);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean gtk_source_lines_has_class (GtkSourceLines *lines,
+ guint line,
+ const gchar *name);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean gtk_source_lines_has_qclass (GtkSourceLines *lines,
+ guint line,
+ GQuark qname);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean gtk_source_lines_is_cursor (GtkSourceLines *lines,
+ guint line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean gtk_source_lines_is_prelit (GtkSourceLines *lines,
+ guint line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean gtk_source_lines_is_selected (GtkSourceLines *lines,
+ guint line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_lines_get_line_yrange (GtkSourceLines *lines,
+ guint line,
+ GtkSourceGutterRendererAlignmentMode mode,
+ gint *y,
+ gint *height);
+
+G_END_DECLS
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index 792776e0..af737ae8 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -17,16 +17,21 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
-#include "gtksourcemap.h"
#include <string.h>
+
+#include "gtksourcemap.h"
#include "gtksourcebuffer.h"
#include "gtksourcecompletion.h"
#include "gtksourcestyle-private.h"
#include "gtksourcestylescheme.h"
#include "gtksourceutils-private.h"
+#define SCRUBBER_MIN_HEIGHT 10
+
/**
* SECTION:map
* @Short_description: Widget that displays a map for a specific #GtkSourceView
@@ -189,6 +194,7 @@ update_scrubber_position (GtkSourceMap *map)
GdkRectangle scrubber_area;
GtkAllocation alloc;
GtkAllocation view_alloc;
+ gint ignored;
gint child_height;
gint view_height;
gint y;
@@ -203,8 +209,16 @@ update_scrubber_position (GtkSourceMap *map)
gtk_widget_get_allocation (GTK_WIDGET (priv->view), &view_alloc);
gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);
- gtk_widget_get_preferred_height (GTK_WIDGET (priv->view), NULL, &view_height);
- gtk_widget_get_preferred_height (GTK_WIDGET (map), NULL, &child_height);
+ gtk_widget_measure (GTK_WIDGET (priv->view),
+ GTK_ORIENTATION_VERTICAL,
+ gtk_widget_get_width (GTK_WIDGET (priv->view)),
+ NULL,
+ &view_height,
+ NULL, NULL);
+ GTK_WIDGET_CLASS (gtk_source_map_parent_class)->measure (GTK_WIDGET (map),
+ GTK_ORIENTATION_VERTICAL,
+ gtk_widget_get_width (GTK_WIDGET (map)),
+ &ignored, &child_height, &ignored, &ignored);
gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (priv->view), &visible_area);
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (priv->view), &iter,
@@ -225,28 +239,8 @@ update_scrubber_position (GtkSourceMap *map)
if (memcmp (&scrubber_area, &priv->scrubber_area, sizeof scrubber_area) != 0)
{
- GdkWindow *window;
-
- /*
- * NOTE:
- *
- * Initially we had a gtk_widget_queue_draw() here thinking
- * that we would hit the pixel cache and everything would be
- * fine. However, it actually has a noticible improvement on
- * interactivity to simply invalidate the old and new region
- * in the widgets primary GdkWindow. Since the window is
- * not the GTK_TEXT_WINDOW_TEXT, we don't seem to invalidate
- * the pixel cache. This makes things as interactive as they
- * were when drawing the scrubber from a parent widget.
- */
- window = gtk_text_view_get_window (GTK_TEXT_VIEW (map), GTK_TEXT_WINDOW_WIDGET);
- if (window != NULL)
- {
- gdk_window_invalidate_rect (window, &priv->scrubber_area, FALSE);
- gdk_window_invalidate_rect (window, &scrubber_area, FALSE);
- }
-
priv->scrubber_area = scrubber_area;
+ gtk_widget_queue_draw (GTK_WIDGET (map));
}
}
@@ -334,7 +328,7 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
if (background == NULL)
{
GtkStyleContext *context;
- GdkRGBA color;
+ GdkRGBA *color = NULL;
/*
* We failed to locate a style for both "map-overlay" and for
@@ -348,13 +342,11 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
gtk_style_context_save (context);
gtk_style_context_add_class (context, "view");
gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED);
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- gtk_style_context_get_background_color (context,
- gtk_style_context_get_state (context),
- &color);
- G_GNUC_END_IGNORE_DEPRECATIONS;
+ gtk_style_context_get (context,
+ GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &color,
+ NULL);
gtk_style_context_restore (context);
- background = gdk_rgba_to_string (&color);
+ background = gdk_rgba_to_string (color);
/*
* Make sure we alter the alpha. It is possible this could be
@@ -362,6 +354,8 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
* not contain a background color.
*/
alter_alpha = TRUE;
+
+ gdk_rgba_free (color);
}
if (alter_alpha)
@@ -392,7 +386,7 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
if (gstr->len > 0)
{
- gtk_css_provider_load_from_data (priv->css_provider, gstr->str, gstr->len, NULL);
+ gtk_css_provider_load_from_data (priv->css_provider, gstr->str, gstr->len);
}
g_string_free (gstr, TRUE);
@@ -568,64 +562,60 @@ gtk_source_map_set_font_name (GtkSourceMap *map,
}
static void
-gtk_source_map_get_preferred_width (GtkWidget *widget,
- gint *mininum_width,
- gint *natural_width)
+gtk_source_map_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
{
GtkSourceMap *map = GTK_SOURCE_MAP (widget);
GtkSourceMapPrivate *priv;
- PangoLayout *layout;
- gint height;
- gint width;
priv = gtk_source_map_get_instance_private (map);
- if (priv->font_desc == NULL)
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- *mininum_width = *natural_width = DEFAULT_WIDTH;
- return;
+ if (priv->font_desc == NULL)
+ {
+ *minimum = *natural = DEFAULT_WIDTH;
+ }
+ else
+ {
+ PangoLayout *layout;
+ gint height;
+ gint width;
+
+ /*
+ * FIXME:
+ *
+ * This seems like the type of thing we should calculate when
+ * rebuilding our CSS since it gets used a bunch and changes
+ * very little.
+ */
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (map), "X");
+ pango_layout_get_pixel_size (layout, &width, &height);
+ g_object_unref (layout);
+
+ width *= gtk_source_view_get_right_margin_position (priv->view);
+
+ *minimum = *natural = width;
+ }
}
-
- /*
- * FIXME:
- *
- * This seems like the type of thing we should calculate when
- * rebuilding our CSS since it gets used a bunch and changes
- * very little.
- */
- layout = gtk_widget_create_pango_layout (GTK_WIDGET (map), "X");
- pango_layout_get_pixel_size (layout, &width, &height);
- g_object_unref (layout);
-
- width *= gtk_source_view_get_right_margin_position (priv->view);
-
- *mininum_width = *natural_width = width;
-}
-
-static void
-gtk_source_map_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- GtkSourceMap *map = GTK_SOURCE_MAP (widget);
- GtkSourceMapPrivate *priv;
-
- priv = gtk_source_map_get_instance_private (map);
-
- if (priv->view == NULL)
+ else if (orientation == GTK_ORIENTATION_VERTICAL)
{
- *minimum_height = *natural_height = 0;
- return;
+ GTK_WIDGET_CLASS (gtk_source_map_parent_class)->measure (widget,
+ orientation,
+ for_size,
+ minimum,
+ natural,
+ minimum_baseline,
+ natural_baseline);
+ *minimum = *natural = 0;
}
-
- GTK_WIDGET_CLASS (gtk_source_map_parent_class)->get_preferred_height (widget,
- minimum_height,
- natural_height);
-
- *minimum_height = 0;
}
-
/*
* This scrolls using buffer coordinates.
* Translate your event location to a buffer coordinate before
@@ -655,12 +645,14 @@ scroll_to_child_point (GtkSourceMap *map,
}
static void
-gtk_source_map_size_allocate (GtkWidget *widget,
- GtkAllocation *alloc)
+gtk_source_map_size_allocate (GtkWidget *widget,
+ int width,
+ int height,
+ int baseline)
{
GtkSourceMap *map = GTK_SOURCE_MAP (widget);
- GTK_WIDGET_CLASS (gtk_source_map_parent_class)->size_allocate (widget, alloc);
+ GTK_WIDGET_CLASS (gtk_source_map_parent_class)->size_allocate (widget, width, height, baseline);
update_scrubber_position (map);
}
@@ -722,16 +714,6 @@ connect_view (GtkSourceMap *map,
map,
G_CONNECT_SWAPPED);
- if ((gtk_widget_get_events (GTK_WIDGET (priv->view)) & GDK_ENTER_NOTIFY_MASK) == 0)
- {
- gtk_widget_add_events (GTK_WIDGET (priv->view), GDK_ENTER_NOTIFY_MASK);
- }
-
- if ((gtk_widget_get_events (GTK_WIDGET (priv->view)) & GDK_LEAVE_NOTIFY_MASK) == 0)
- {
- gtk_widget_add_events (GTK_WIDGET (priv->view), GDK_LEAVE_NOTIFY_MASK);
- }
-
/* If we are not visible, we want to block certain signal handlers */
if (!gtk_widget_get_visible (GTK_WIDGET (map)))
{
@@ -818,9 +800,9 @@ gtk_source_map_destroy (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_source_map_parent_class)->destroy (widget);
}
-static gboolean
-gtk_source_map_draw (GtkWidget *widget,
- cairo_t *cr)
+static void
+gtk_source_map_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
GtkSourceMap *map = GTK_SOURCE_MAP (widget);
GtkSourceMapPrivate *priv;
@@ -828,18 +810,27 @@ gtk_source_map_draw (GtkWidget *widget,
priv = gtk_source_map_get_instance_private (map);
- style_context = gtk_widget_get_style_context (widget);
+ GTK_WIDGET_CLASS (gtk_source_map_parent_class)->snapshot (widget, snapshot);
- GTK_WIDGET_CLASS (gtk_source_map_parent_class)->draw (widget, cr);
+ style_context = gtk_widget_get_style_context (widget);
gtk_style_context_save (style_context);
gtk_style_context_add_class (style_context, "scrubber");
- gtk_render_background (style_context, cr,
- priv->scrubber_area.x, priv->scrubber_area.y,
- priv->scrubber_area.width, priv->scrubber_area.height);
+ gtk_snapshot_render_background (snapshot,
+ style_context,
+ priv->scrubber_area.x, priv->scrubber_area.y,
+ priv->scrubber_area.width, priv->scrubber_area.height);
gtk_style_context_restore (style_context);
+}
- return FALSE;
+static void
+gtk_source_map_snapshot_layer (GtkTextView *text_view,
+ GtkTextViewLayer layer,
+ GtkSnapshot *snapshot)
+{
+ /* Avoid drawing layers from GtkSourceView. They details are
+ * too small to see and significantly slow down rendering.
+ */
}
static void
@@ -891,98 +882,66 @@ gtk_source_map_set_property (GObject *object,
}
}
-static gboolean
-gtk_source_map_button_press_event (GtkWidget *widget,
- GdkEventButton *event)
+static void
+gtk_source_map_drag_update (GtkSourceMap *map,
+ gdouble x,
+ gdouble y,
+ GtkGestureDrag *drag)
{
- GtkSourceMap *map = GTK_SOURCE_MAP (widget);
- GtkSourceMapPrivate *priv;
+ GtkTextBuffer *buffer;
+ GtkAllocation alloc;
+ GdkRectangle area;
+ GtkTextIter iter;
GdkPoint point;
+ gdouble yratio;
+ gdouble begin_x;
+ gdouble begin_y;
+ gint ignored;
+ gint real_height;
+ gint height;
- priv = gtk_source_map_get_instance_private (map);
+ gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);
+ gtk_gesture_drag_get_start_point (drag, &begin_x, &begin_y);
+ y = CLAMP (begin_y + y, 0, alloc.height);
- point.x = event->x;
- point.y = event->y;
+ GTK_WIDGET_CLASS (gtk_source_map_parent_class)->measure (GTK_WIDGET (map),
+ GTK_ORIENTATION_VERTICAL,
+ gtk_widget_get_width (GTK_WIDGET (map)),
+ &ignored, &real_height, &ignored, &ignored);
- gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (map),
- GTK_TEXT_WINDOW_WIDGET,
- event->x, event->y,
- &point.x, &point.y);
+ height = MIN (real_height, alloc.height);
- scroll_to_child_point (map, &point);
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (map));
+ gtk_text_buffer_get_end_iter (buffer, &iter);
+ gtk_text_view_get_iter_location (GTK_TEXT_VIEW (map), &iter, &area);
- gtk_grab_add (widget);
+ yratio = CLAMP (y, 0, height) / (gdouble)height;
- priv->in_press = TRUE;
+ point.x = 0;
+ point.y = real_height * yratio;
- return GDK_EVENT_STOP;
+ scroll_to_child_point (map, &point);
}
-static gboolean
-gtk_source_map_button_release_event (GtkWidget *widget,
- GdkEventButton *event)
+static void
+gtk_source_map_drag_begin (GtkSourceMap *map,
+ gdouble start_x,
+ gdouble start_y,
+ GtkGestureDrag *drag)
{
- GtkSourceMap *map = GTK_SOURCE_MAP (widget);
- GtkSourceMapPrivate *priv;
-
- priv = gtk_source_map_get_instance_private (map);
-
- gtk_grab_remove (widget);
-
- priv->in_press = FALSE;
-
- return GDK_EVENT_STOP;
+ gtk_gesture_set_state (GTK_GESTURE (drag), GTK_EVENT_SEQUENCE_CLAIMED);
+ gtk_source_map_drag_update (map, 0, 0, drag);
}
static gboolean
-gtk_source_map_motion_notify_event (GtkWidget *widget,
- GdkEventMotion *event)
-{
- GtkSourceMap *map = GTK_SOURCE_MAP (widget);
- GtkSourceMapPrivate *priv;
-
- priv = gtk_source_map_get_instance_private (map);
-
- if (priv->in_press && (priv->view != NULL))
- {
- GtkTextBuffer *buffer;
- GtkAllocation alloc;
- GdkRectangle area;
- GtkTextIter iter;
- GdkPoint point;
- gdouble yratio;
- gint height;
-
- gtk_widget_get_allocation (widget, &alloc);
- gtk_widget_get_preferred_height (widget, NULL, &height);
- if (height > 0)
- {
- height = MIN (height, alloc.height);
- }
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (map));
- gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_view_get_iter_location (GTK_TEXT_VIEW (map), &iter, &area);
-
- yratio = CLAMP (event->y - alloc.y, 0, height) / (gdouble)height;
-
- point.x = 0;
- point.y = (area.y + area.height) * yratio;
-
- scroll_to_child_point (map, &point);
- }
-
- return GDK_EVENT_STOP;
-}
-
-static gboolean
-gtk_source_map_scroll_event (GtkWidget *widget,
- GdkEventScroll *event)
+gtk_source_map_scroll (GtkWidget *widget,
+ gdouble x,
+ gdouble y)
{
+ static const gint scroll_acceleration = 6;
GtkSourceMap *map = GTK_SOURCE_MAP (widget);
GtkSourceMapPrivate *priv;
- static const gint scroll_acceleration = 4;
priv = gtk_source_map_get_instance_private (map);
@@ -994,36 +953,20 @@ gtk_source_map_scroll_event (GtkWidget *widget,
*/
if (priv->view != NULL)
{
- gdouble x;
- gdouble y;
gint count = 0;
- if (event->direction == GDK_SCROLL_UP)
- {
- count = -scroll_acceleration;
- }
- else if (event->direction == GDK_SCROLL_DOWN)
+ if (y > 0)
{
count = scroll_acceleration;
}
- else
+ else if (y < 0)
{
- gdk_event_get_scroll_deltas ((GdkEvent *)event, &x, &y);
-
- if (y > 0)
- {
- count = scroll_acceleration;
- }
- else if (y < 0)
- {
- count = -scroll_acceleration;
- }
+ count = -scroll_acceleration;
}
if (count != 0)
{
- g_signal_emit_by_name (priv->view, "move-viewport",
- GTK_SCROLL_STEPS, count);
+ g_signal_emit_by_name (priv->view, "move-viewport", GTK_SCROLL_STEPS, count);
return GDK_EVENT_STOP;
}
}
@@ -1031,26 +974,13 @@ gtk_source_map_scroll_event (GtkWidget *widget,
return GDK_EVENT_PROPAGATE;
}
-static void
-set_view_cursor (GtkSourceMap *map)
-{
- GdkWindow *window;
-
- window = gtk_text_view_get_window (GTK_TEXT_VIEW (map),
- GTK_TEXT_WINDOW_TEXT);
- if (window != NULL)
- {
- gdk_window_set_cursor (window, NULL);
- }
-}
-
static void
gtk_source_map_state_flags_changed (GtkWidget *widget,
GtkStateFlags flags)
{
GTK_WIDGET_CLASS (gtk_source_map_parent_class)->state_flags_changed (widget, flags);
- set_view_cursor (GTK_SOURCE_MAP (widget));
+ gtk_widget_set_cursor (widget, NULL);
}
static void
@@ -1058,7 +988,7 @@ gtk_source_map_realize (GtkWidget *widget)
{
GTK_WIDGET_CLASS (gtk_source_map_parent_class)->realize (widget);
- set_view_cursor (GTK_SOURCE_MAP (widget));
+ gtk_widget_set_cursor (widget, NULL);
}
static void
@@ -1108,24 +1038,22 @@ gtk_source_map_class_init (GtkSourceMapClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
object_class->get_property = gtk_source_map_get_property;
object_class->set_property = gtk_source_map_set_property;
widget_class->destroy = gtk_source_map_destroy;
- widget_class->draw = gtk_source_map_draw;
- widget_class->get_preferred_height = gtk_source_map_get_preferred_height;
- widget_class->get_preferred_width = gtk_source_map_get_preferred_width;
+ widget_class->snapshot = gtk_source_map_snapshot;
+ widget_class->measure = gtk_source_map_measure;
widget_class->hide = gtk_source_map_hide;
widget_class->size_allocate = gtk_source_map_size_allocate;
- widget_class->button_press_event = gtk_source_map_button_press_event;
- widget_class->button_release_event = gtk_source_map_button_release_event;
- widget_class->motion_notify_event = gtk_source_map_motion_notify_event;
- widget_class->scroll_event = gtk_source_map_scroll_event;
widget_class->show = gtk_source_map_show;
widget_class->state_flags_changed = gtk_source_map_state_flags_changed;
widget_class->realize = gtk_source_map_realize;
+ text_view_class->snapshot_layer = gtk_source_map_snapshot_layer;
+
properties[PROP_VIEW] =
g_param_spec_object ("view",
"View",
@@ -1148,7 +1076,9 @@ gtk_source_map_init (GtkSourceMap *map)
{
GtkSourceMapPrivate *priv;
GtkSourceCompletion *completion;
+ GtkEventController *scroll;
GtkStyleContext *context;
+ GtkGesture *drag;
priv = gtk_source_map_get_instance_private (map);
@@ -1165,18 +1095,34 @@ gtk_source_map_init (GtkSourceMap *map)
"editable", FALSE,
"expand", FALSE,
"monospace", TRUE,
- "show-line-numbers", FALSE,
- "show-line-marks", FALSE,
"show-right-margin", FALSE,
"visible", TRUE,
NULL);
- gtk_widget_add_events (GTK_WIDGET (map), GDK_SCROLL_MASK);
-
completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (map));
gtk_source_completion_block_interactive (completion);
- gtk_source_map_set_font_name (map, "Monospace 1");
+ gtk_source_map_set_font_name (map, "BuilderBlocks 1");
+
+ drag = gtk_gesture_drag_new ();
+ g_signal_connect_swapped (drag,
+ "drag-begin",
+ G_CALLBACK (gtk_source_map_drag_begin),
+ map);
+ g_signal_connect_swapped (drag,
+ "drag-update",
+ G_CALLBACK (gtk_source_map_drag_update),
+ map);
+ gtk_widget_add_controller (GTK_WIDGET (map),
+ GTK_EVENT_CONTROLLER (g_steal_pointer (&drag)));
+
+ scroll = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
+ gtk_event_controller_set_propagation_phase (scroll, GTK_PHASE_CAPTURE);
+ g_signal_connect_swapped (scroll,
+ "scroll",
+ G_CALLBACK (gtk_source_map_scroll),
+ map);
+ gtk_widget_add_controller (GTK_WIDGET (map), g_steal_pointer (&scroll));
}
/**
diff --git a/gtksourceview/gtksourcemap.h b/gtksourceview/gtksourcemap.h
index 9fd57c33..b5a225cd 100644
--- a/gtksourceview/gtksourcemap.h
+++ b/gtksourceview/gtksourcemap.h
@@ -30,10 +30,20 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_MAP (gtk_source_map_get_type())
+#define GTK_SOURCE_TYPE_MAP (gtk_source_map_get_type())
+#define GTK_SOURCE_MAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MAP,
GtkSourceMap))
+#define GTK_SOURCE_MAP_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MAP, GtkSourceMap
const))
+#define GTK_SOURCE_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_MAP,
GtkSourceMapClass))
+#define GTK_SOURCE_IS_MAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_MAP))
+#define GTK_SOURCE_IS_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_MAP))
+#define GTK_SOURCE_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_MAP,
GtkSourceMapClass))
-GTK_SOURCE_AVAILABLE_IN_3_18
-G_DECLARE_DERIVABLE_TYPE (GtkSourceMap, gtk_source_map, GTK_SOURCE, MAP, GtkSourceView)
+typedef struct _GtkSourceMapClass GtkSourceMapClass;
+
+struct _GtkSourceMap
+{
+ GtkSourceView parent_instance;
+};
struct _GtkSourceMapClass
{
@@ -44,11 +54,16 @@ struct _GtkSourceMapClass
};
GTK_SOURCE_AVAILABLE_IN_3_18
-GtkWidget *gtk_source_map_new (void);
+GType gtk_source_map_get_type (void);
+
+GTK_SOURCE_AVAILABLE_IN_3_18
+GtkWidget *gtk_source_map_new (void);
+
GTK_SOURCE_AVAILABLE_IN_3_18
-void gtk_source_map_set_view (GtkSourceMap *map,
- GtkSourceView *view);
+void gtk_source_map_set_view (GtkSourceMap *map,
+ GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_3_18
-GtkSourceView *gtk_source_map_get_view (GtkSourceMap *map);
+GtkSourceView *gtk_source_map_get_view (GtkSourceMap *map);
G_END_DECLS
diff --git a/gtksourceview/gtksourcemark.c b/gtksourceview/gtksourcemark.c
index 5e32123e..d546401c 100644
--- a/gtksourceview/gtksourcemark.c
+++ b/gtksourceview/gtksourcemark.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcemark.h"
#include "gtksourcebuffer.h"
@@ -49,21 +51,24 @@ enum
PROP_CATEGORY
};
-typedef struct
+struct _GtkSourceMarkPrivate
{
gchar *category;
-} GtkSourceMarkPrivate;
+};
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMark, gtk_source_mark, GTK_TYPE_TEXT_MARK)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMark, gtk_source_mark, GTK_TYPE_TEXT_MARK);
static void
gtk_source_mark_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GtkSourceMark *mark = GTK_SOURCE_MARK (object);
- GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
+ GtkSourceMarkPrivate *priv;
+
+ g_return_if_fail (GTK_SOURCE_IS_MARK (object));
+
+ priv = GTK_SOURCE_MARK (object)->priv;
switch (prop_id)
{
@@ -81,11 +86,15 @@ gtk_source_mark_set_property (GObject *object,
static void
gtk_source_mark_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GtkSourceMark *mark = GTK_SOURCE_MARK (object);
+ GtkSourceMark *mark;
+
+ g_return_if_fail (GTK_SOURCE_IS_MARK (object));
+
+ mark = GTK_SOURCE_MARK (object);
switch (prop_id)
{
@@ -104,9 +113,8 @@ static void
gtk_source_mark_finalize (GObject *object)
{
GtkSourceMark *mark = GTK_SOURCE_MARK (object);
- GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
- g_clear_pointer (&priv->category, g_free);
+ g_free (mark->priv->category);
G_OBJECT_CLASS (gtk_source_mark_parent_class)->finalize (object);
}
@@ -142,6 +150,7 @@ gtk_source_mark_class_init (GtkSourceMarkClass *klass)
static void
gtk_source_mark_init (GtkSourceMark *mark)
{
+ mark->priv = gtk_source_mark_get_instance_private (mark);
}
/**
@@ -188,11 +197,9 @@ gtk_source_mark_new (const gchar *name,
const gchar *
gtk_source_mark_get_category (GtkSourceMark *mark)
{
- GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
-
g_return_val_if_fail (GTK_SOURCE_IS_MARK (mark), NULL);
- return priv->category;
+ return mark->priv->category;
}
/**
@@ -211,7 +218,7 @@ gtk_source_mark_get_category (GtkSourceMark *mark)
*/
GtkSourceMark *
gtk_source_mark_next (GtkSourceMark *mark,
- const gchar *category)
+ const gchar *category)
{
GtkTextBuffer *buffer;
@@ -245,7 +252,7 @@ gtk_source_mark_next (GtkSourceMark *mark,
*/
GtkSourceMark *
gtk_source_mark_prev (GtkSourceMark *mark,
- const gchar *category)
+ const gchar *category)
{
GtkTextBuffer *buffer;
diff --git a/gtksourceview/gtksourcemark.h b/gtksourceview/gtksourcemark.h
index 17bc46e5..c995b342 100644
--- a/gtksourceview/gtksourcemark.h
+++ b/gtksourceview/gtksourcemark.h
@@ -30,29 +30,48 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_MARK (gtk_source_mark_get_type())
+#define GTK_SOURCE_TYPE_MARK (gtk_source_mark_get_type ())
+#define GTK_SOURCE_MARK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MARK,
GtkSourceMark))
+#define GTK_SOURCE_MARK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_MARK,
GtkSourceMarkClass))
+#define GTK_SOURCE_IS_MARK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_MARK))
+#define GTK_SOURCE_IS_MARK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_MARK))
+#define GTK_SOURCE_MARK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_MARK,
GtkSourceMarkClass))
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceMark, gtk_source_mark, GTK_SOURCE, MARK, GtkTextMark)
+typedef struct _GtkSourceMarkClass GtkSourceMarkClass;
+
+typedef struct _GtkSourceMarkPrivate GtkSourceMarkPrivate;
+
+struct _GtkSourceMark
+{
+ GtkTextMark parent_instance;
+
+ GtkSourceMarkPrivate *priv;
+};
struct _GtkSourceMarkClass
{
GtkTextMarkClass parent_class;
- /*< private >*/
- gpointer _reserved[10];
+ /* Padding for future expansion */
+ gpointer padding[10];
};
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark *gtk_source_mark_new (const gchar *name,
- const gchar *category);
+GType gtk_source_mark_get_type (void) G_GNUC_CONST;
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_mark_get_category (GtkSourceMark *mark);
+GtkSourceMark *gtk_source_mark_new (const gchar *name,
+ const gchar *category);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark *gtk_source_mark_next (GtkSourceMark *mark,
- const gchar *category);
+const gchar *gtk_source_mark_get_category (GtkSourceMark *mark);
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkSourceMark *gtk_source_mark_next (GtkSourceMark *mark,
+ const gchar *category);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark *gtk_source_mark_prev (GtkSourceMark *mark,
- const gchar *category);
+GtkSourceMark *gtk_source_mark_prev (GtkSourceMark *mark,
+ const gchar *category);
G_END_DECLS
diff --git a/gtksourceview/gtksourcemarkattributes.c b/gtksourceview/gtksourcemarkattributes.c
index 95f3785f..1bd9dfff 100644
--- a/gtksourceview/gtksourcemarkattributes.c
+++ b/gtksourceview/gtksourcemarkattributes.c
@@ -19,7 +19,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcemarkattributes.h"
#include "gtksourcemark.h"
@@ -75,10 +77,8 @@
* takes precedence.
*/
-struct _GtkSourceMarkAttributes
+struct _GtkSourceMarkAttributesPrivate
{
- GObject parent_instance;
-
GdkRGBA background;
GtkSourcePixbufHelper *helper;
@@ -86,7 +86,7 @@ struct _GtkSourceMarkAttributes
guint background_set : 1;
};
-G_DEFINE_TYPE (GtkSourceMarkAttributes, gtk_source_mark_attributes, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMarkAttributes, gtk_source_mark_attributes, G_TYPE_OBJECT)
enum
{
@@ -111,36 +111,36 @@ gtk_source_mark_attributes_finalize (GObject *object)
{
GtkSourceMarkAttributes *attributes = GTK_SOURCE_MARK_ATTRIBUTES (object);
- gtk_source_pixbuf_helper_free (attributes->helper);
+ gtk_source_pixbuf_helper_free (attributes->priv->helper);
G_OBJECT_CLASS (gtk_source_mark_attributes_parent_class)->finalize (object);
}
static void
set_background (GtkSourceMarkAttributes *attributes,
- const GdkRGBA *color)
+ const GdkRGBA *color)
{
if (color)
{
- attributes->background = *color;
+ attributes->priv->background = *color;
}
- attributes->background_set = color != NULL;
+ attributes->priv->background_set = color != NULL;
g_object_notify (G_OBJECT (attributes), "background");
}
static void
set_icon_name (GtkSourceMarkAttributes *attributes,
- const gchar *icon_name)
+ const gchar *icon_name)
{
- if (g_strcmp0 (gtk_source_pixbuf_helper_get_icon_name (attributes->helper),
+ if (g_strcmp0 (gtk_source_pixbuf_helper_get_icon_name (attributes->priv->helper),
icon_name) == 0)
{
return;
}
- gtk_source_pixbuf_helper_set_icon_name (attributes->helper,
+ gtk_source_pixbuf_helper_set_icon_name (attributes->priv->helper,
icon_name);
g_object_notify (G_OBJECT (attributes), "icon-name");
@@ -148,14 +148,14 @@ set_icon_name (GtkSourceMarkAttributes *attributes,
static void
set_pixbuf (GtkSourceMarkAttributes *attributes,
- const GdkPixbuf *pixbuf)
+ const GdkPixbuf *pixbuf)
{
- if (gtk_source_pixbuf_helper_get_pixbuf (attributes->helper) == pixbuf)
+ if (gtk_source_pixbuf_helper_get_pixbuf (attributes->priv->helper) == pixbuf)
{
return;
}
- gtk_source_pixbuf_helper_set_pixbuf (attributes->helper,
+ gtk_source_pixbuf_helper_set_pixbuf (attributes->priv->helper,
pixbuf);
g_object_notify (G_OBJECT (attributes), "pixbuf");
@@ -163,14 +163,14 @@ set_pixbuf (GtkSourceMarkAttributes *attributes,
static void
set_gicon (GtkSourceMarkAttributes *attributes,
- GIcon *gicon)
+ GIcon *gicon)
{
- if (gtk_source_pixbuf_helper_get_gicon (attributes->helper) == gicon)
+ if (gtk_source_pixbuf_helper_get_gicon (attributes->priv->helper) == gicon)
{
return;
}
- gtk_source_pixbuf_helper_set_gicon (attributes->helper,
+ gtk_source_pixbuf_helper_set_gicon (attributes->priv->helper,
gicon);
g_object_notify (G_OBJECT (attributes), "gicon");
@@ -178,9 +178,9 @@ set_gicon (GtkSourceMarkAttributes *attributes,
static void
gtk_source_mark_attributes_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceMarkAttributes *self = GTK_SOURCE_MARK_ATTRIBUTES (object);
@@ -206,18 +206,18 @@ gtk_source_mark_attributes_set_property (GObject *object,
static void
gtk_source_mark_attributes_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceMarkAttributes *self = GTK_SOURCE_MARK_ATTRIBUTES (object);
switch (prop_id)
{
case PROP_BACKGROUND:
- if (self->background_set)
+ if (self->priv->background_set)
{
- g_value_set_boxed (value, &self->background);
+ g_value_set_boxed (value, &self->priv->background);
}
else
{
@@ -226,15 +226,15 @@ gtk_source_mark_attributes_get_property (GObject *object,
break;
case PROP_PIXBUF:
g_value_set_object (value,
- gtk_source_pixbuf_helper_get_pixbuf (self->helper));
+ gtk_source_pixbuf_helper_get_pixbuf (self->priv->helper));
break;
case PROP_ICON_NAME:
g_value_set_string (value,
- gtk_source_pixbuf_helper_get_icon_name (self->helper));
+ gtk_source_pixbuf_helper_get_icon_name (self->priv->helper));
break;
case PROP_GICON:
g_value_set_object (value,
- gtk_source_pixbuf_helper_get_gicon (self->helper));
+ gtk_source_pixbuf_helper_get_gicon (self->priv->helper));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -362,9 +362,9 @@ gtk_source_mark_attributes_class_init (GtkSourceMarkAttributesClass *klass)
static void
gtk_source_mark_attributes_init (GtkSourceMarkAttributes *self)
{
- self = gtk_source_mark_attributes_get_instance_private (self);
+ self->priv = gtk_source_mark_attributes_get_instance_private (self);
- self->helper = gtk_source_pixbuf_helper_new ();
+ self->priv->helper = gtk_source_pixbuf_helper_new ();
}
/**
@@ -389,7 +389,7 @@ gtk_source_mark_attributes_new (void)
*/
void
gtk_source_mark_attributes_set_background (GtkSourceMarkAttributes *attributes,
- const GdkRGBA *background)
+ const GdkRGBA *background)
{
g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
@@ -407,15 +407,15 @@ gtk_source_mark_attributes_set_background (GtkSourceMarkAttributes *attributes,
*/
gboolean
gtk_source_mark_attributes_get_background (GtkSourceMarkAttributes *attributes,
- GdkRGBA *background)
+ GdkRGBA *background)
{
g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), FALSE);
if (background)
{
- *background = attributes->background;
+ *background = attributes->priv->background;
}
- return attributes->background_set;
+ return attributes->priv->background_set;
}
/**
@@ -427,7 +427,7 @@ gtk_source_mark_attributes_get_background (GtkSourceMarkAttributes *attributes,
*/
void
gtk_source_mark_attributes_set_icon_name (GtkSourceMarkAttributes *attributes,
- const gchar *icon_name)
+ const gchar *icon_name)
{
g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
@@ -449,7 +449,7 @@ gtk_source_mark_attributes_get_icon_name (GtkSourceMarkAttributes *attributes)
{
g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
- return gtk_source_pixbuf_helper_get_icon_name (attributes->helper);
+ return gtk_source_pixbuf_helper_get_icon_name (attributes->priv->helper);
}
/**
@@ -461,7 +461,7 @@ gtk_source_mark_attributes_get_icon_name (GtkSourceMarkAttributes *attributes)
*/
void
gtk_source_mark_attributes_set_gicon (GtkSourceMarkAttributes *attributes,
- GIcon *gicon)
+ GIcon *gicon)
{
g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
@@ -483,7 +483,7 @@ gtk_source_mark_attributes_get_gicon (GtkSourceMarkAttributes *attributes)
{
g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
- return gtk_source_pixbuf_helper_get_gicon (attributes->helper);
+ return gtk_source_pixbuf_helper_get_gicon (attributes->priv->helper);
}
/**
@@ -495,7 +495,7 @@ gtk_source_mark_attributes_get_gicon (GtkSourceMarkAttributes *attributes)
*/
void
gtk_source_mark_attributes_set_pixbuf (GtkSourceMarkAttributes *attributes,
- const GdkPixbuf *pixbuf)
+ const GdkPixbuf *pixbuf)
{
g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
@@ -517,7 +517,7 @@ gtk_source_mark_attributes_get_pixbuf (GtkSourceMarkAttributes *attributes)
{
g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
- return gtk_source_pixbuf_helper_get_pixbuf (attributes->helper);
+ return gtk_source_pixbuf_helper_get_pixbuf (attributes->priv->helper);
}
/**
@@ -531,21 +531,27 @@ gtk_source_mark_attributes_get_pixbuf (GtkSourceMarkAttributes *attributes)
* gtk_source_mark_attributes_set_gicon() or
* gtk_source_mark_attributes_set_icon_name(). @size cannot be lower than 1.
*
- * Returns: (transfer none): A rendered pixbuf. The pixbuf belongs to @attributes
+ * Returns: (transfer none): A #GdkPaintable. The paintable belongs to @attributes
* and should not be unreffed.
*/
-const GdkPixbuf *
+GdkPaintable *
gtk_source_mark_attributes_render_icon (GtkSourceMarkAttributes *attributes,
- GtkWidget *widget,
- gint size)
+ GtkWidget *widget,
+ gint size)
{
+ GdkPaintable *ret;
+
g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (size > 0, NULL);
- return gtk_source_pixbuf_helper_render (attributes->helper,
- widget,
- size);
+ ret = gtk_source_pixbuf_helper_render (attributes->priv->helper,
+ widget,
+ size);
+
+ g_return_val_if_fail (ret == NULL || GDK_IS_PAINTABLE (ret), NULL);
+
+ return ret;
}
/**
@@ -562,7 +568,7 @@ gtk_source_mark_attributes_render_icon (GtkSourceMarkAttributes *attributes,
*/
gchar *
gtk_source_mark_attributes_get_tooltip_text (GtkSourceMarkAttributes *attributes,
- GtkSourceMark *mark)
+ GtkSourceMark *mark)
{
gchar *ret;
@@ -589,7 +595,7 @@ gtk_source_mark_attributes_get_tooltip_text (GtkSourceMarkAttributes *attributes
*/
gchar *
gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attributes,
- GtkSourceMark *mark)
+ GtkSourceMark *mark)
{
gchar *ret;
@@ -601,3 +607,4 @@ gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attribut
return ret;
}
+
diff --git a/gtksourceview/gtksourcemarkattributes.h b/gtksourceview/gtksourcemarkattributes.h
index 29cb0c85..29262ddb 100644
--- a/gtksourceview/gtksourcemarkattributes.h
+++ b/gtksourceview/gtksourcemarkattributes.h
@@ -31,43 +31,80 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_MARK_ATTRIBUTES (gtk_source_mark_attributes_get_type())
+#define GTK_SOURCE_TYPE_MARK_ATTRIBUTES (gtk_source_mark_attributes_get_type ())
+#define GTK_SOURCE_MARK_ATTRIBUTES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_MARK_ATTRIBUTES, GtkSourceMarkAttributes))
+#define GTK_SOURCE_MARK_ATTRIBUTES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_MARK_ATTRIBUTES, GtkSourceMarkAttributesClass))
+#define GTK_SOURCE_IS_MARK_ATTRIBUTES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_MARK_ATTRIBUTES))
+#define GTK_SOURCE_IS_MARK_ATTRIBUTES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_MARK_ATTRIBUTES))
+#define GTK_SOURCE_MARK_ATTRIBUTES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_MARK_ATTRIBUTES, GtkSourceMarkAttributesClass))
+
+typedef struct _GtkSourceMarkAttributesClass GtkSourceMarkAttributesClass;
+typedef struct _GtkSourceMarkAttributesPrivate GtkSourceMarkAttributesPrivate;
+
+struct _GtkSourceMarkAttributes
+{
+ /*< private >*/
+ GObject parent;
+
+ GtkSourceMarkAttributesPrivate *priv;
+
+ /*< public >*/
+};
+
+struct _GtkSourceMarkAttributesClass
+{
+ /*< private >*/
+ GObjectClass parent_class;
+
+ gpointer padding[10];
+};
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceMarkAttributes, gtk_source_mark_attributes, GTK_SOURCE, MARK_ATTRIBUTES,
GObject)
+GType gtk_source_mark_attributes_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMarkAttributes *gtk_source_mark_attributes_new (void);
+GtkSourceMarkAttributes *gtk_source_mark_attributes_new (void);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_mark_attributes_set_background (GtkSourceMarkAttributes *attributes,
- const GdkRGBA *background);
+void gtk_source_mark_attributes_set_background (GtkSourceMarkAttributes *attributes,
+ const GdkRGBA *background);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_mark_attributes_get_background (GtkSourceMarkAttributes *attributes,
- GdkRGBA *background);
+gboolean gtk_source_mark_attributes_get_background (GtkSourceMarkAttributes *attributes,
+ GdkRGBA *background);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_mark_attributes_set_icon_name (GtkSourceMarkAttributes *attributes,
- const gchar *icon_name);
+void gtk_source_mark_attributes_set_icon_name (GtkSourceMarkAttributes *attributes,
+ const gchar *icon_name);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_mark_attributes_get_icon_name (GtkSourceMarkAttributes *attributes);
+const gchar *gtk_source_mark_attributes_get_icon_name (GtkSourceMarkAttributes *attributes);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_mark_attributes_set_gicon (GtkSourceMarkAttributes *attributes,
- GIcon *gicon);
+void gtk_source_mark_attributes_set_gicon (GtkSourceMarkAttributes *attributes,
+ GIcon *gicon);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GIcon *gtk_source_mark_attributes_get_gicon (GtkSourceMarkAttributes *attributes);
+GIcon *gtk_source_mark_attributes_get_gicon (GtkSourceMarkAttributes *attributes);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_mark_attributes_set_pixbuf (GtkSourceMarkAttributes *attributes,
- const GdkPixbuf *pixbuf);
+void gtk_source_mark_attributes_set_pixbuf (GtkSourceMarkAttributes *attributes,
+ const GdkPixbuf *pixbuf);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const GdkPixbuf *gtk_source_mark_attributes_get_pixbuf (GtkSourceMarkAttributes *attributes);
+const GdkPixbuf *gtk_source_mark_attributes_get_pixbuf (GtkSourceMarkAttributes *attributes);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const GdkPixbuf *gtk_source_mark_attributes_render_icon (GtkSourceMarkAttributes *attributes,
- GtkWidget *widget,
- gint size);
+GdkPaintable *gtk_source_mark_attributes_render_icon (GtkSourceMarkAttributes *attributes,
+ GtkWidget *widget,
+ gint size);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gchar *gtk_source_mark_attributes_get_tooltip_text (GtkSourceMarkAttributes *attributes,
- GtkSourceMark *mark);
+gchar *gtk_source_mark_attributes_get_tooltip_text (GtkSourceMarkAttributes *attributes,
+ GtkSourceMark *mark);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gchar *gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attributes,
- GtkSourceMark *mark);
+gchar *gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attributes,
+ GtkSourceMark *mark);
G_END_DECLS
diff --git a/gtksourceview/gtksourcemarkssequence-private.h b/gtksourceview/gtksourcemarkssequence-private.h
index 0da2194b..8f60ede8 100644
--- a/gtksourceview/gtksourcemarkssequence-private.h
+++ b/gtksourceview/gtksourcemarkssequence-private.h
@@ -21,43 +21,73 @@
#pragma once
#include <gtk/gtk.h>
+
#include "gtksourcetypes-private.h"
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_MARKS_SEQUENCE (_gtk_source_marks_sequence_get_type())
+#define GTK_SOURCE_TYPE_MARKS_SEQUENCE (_gtk_source_marks_sequence_get_type ())
+#define GTK_SOURCE_MARKS_SEQUENCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_MARKS_SEQUENCE, GtkSourceMarksSequence))
+#define GTK_SOURCE_MARKS_SEQUENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_MARKS_SEQUENCE, GtkSourceMarksSequenceClass))
+#define GTK_SOURCE_IS_MARKS_SEQUENCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_MARKS_SEQUENCE))
+#define GTK_SOURCE_IS_MARKS_SEQUENCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_MARKS_SEQUENCE))
+#define GTK_SOURCE_MARKS_SEQUENCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_MARKS_SEQUENCE, GtkSourceMarksSequenceClass))
+
+typedef struct _GtkSourceMarksSequenceClass GtkSourceMarksSequenceClass;
+typedef struct _GtkSourceMarksSequencePrivate GtkSourceMarksSequencePrivate;
+
+struct _GtkSourceMarksSequence
+{
+ GObject parent;
+
+ GtkSourceMarksSequencePrivate *priv;
+};
+
+struct _GtkSourceMarksSequenceClass
+{
+ GObjectClass parent_class;
+};
G_GNUC_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceMarksSequence, _gtk_source_marks_sequence, GTK_SOURCE, MARKS_SEQUENCE,
GObject)
+GType _gtk_source_marks_sequence_get_type (void) G_GNUC_CONST;
G_GNUC_INTERNAL
-GtkSourceMarksSequence *_gtk_source_marks_sequence_new (GtkTextBuffer *buffer);
+GtkSourceMarksSequence *_gtk_source_marks_sequence_new (GtkTextBuffer *buffer);
+
G_GNUC_INTERNAL
-gboolean _gtk_source_marks_sequence_is_empty (GtkSourceMarksSequence *seq);
+gboolean _gtk_source_marks_sequence_is_empty (GtkSourceMarksSequence *seq);
+
G_GNUC_INTERNAL
-void _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+void _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
+
G_GNUC_INTERNAL
-void _gtk_source_marks_sequence_remove (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+void _gtk_source_marks_sequence_remove (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
+
G_GNUC_INTERNAL
-GtkTextMark *_gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+GtkTextMark *_gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
+
G_GNUC_INTERNAL
-GtkTextMark *_gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
- GtkTextMark *mark);
+GtkTextMark *_gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
+ GtkTextMark *mark);
+
G_GNUC_INTERNAL
-gboolean _gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
- GtkTextIter *iter);
+gboolean _gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
+ GtkTextIter *iter);
+
G_GNUC_INTERNAL
-gboolean _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
- GtkTextIter *iter);
+gboolean _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
+ GtkTextIter *iter);
+
G_GNUC_INTERNAL
-GSList *_gtk_source_marks_sequence_get_marks_at_iter (GtkSourceMarksSequence *seq,
- const GtkTextIter *iter);
+GSList *_gtk_source_marks_sequence_get_marks_at_iter (GtkSourceMarksSequence *seq,
+ const GtkTextIter *iter);
+
G_GNUC_INTERNAL
-GSList *_gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
- const GtkTextIter *iter1,
- const GtkTextIter *iter2);
+GSList *_gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
+ const GtkTextIter *iter1,
+ const GtkTextIter *iter2);
G_END_DECLS
diff --git a/gtksourceview/gtksourcemarkssequence.c b/gtksourceview/gtksourcemarkssequence.c
index c4b723d7..2ceb69ec 100644
--- a/gtksourceview/gtksourcemarkssequence.c
+++ b/gtksourceview/gtksourcemarkssequence.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcemarkssequence-private.h"
@@ -41,10 +43,8 @@ enum
PROP_BUFFER,
};
-struct _GtkSourceMarksSequence
+struct _GtkSourceMarksSequencePrivate
{
- GObject parent_instance;
-
GtkTextBuffer *buffer;
GSequence *seq;
@@ -54,35 +54,35 @@ struct _GtkSourceMarksSequence
GQuark quark;
};
-G_DEFINE_TYPE (GtkSourceMarksSequence, _gtk_source_marks_sequence, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMarksSequence, _gtk_source_marks_sequence, G_TYPE_OBJECT)
static void
remove_qdata (GtkTextMark *mark,
- GtkSourceMarksSequence *seq)
+ GtkSourceMarksSequence *seq)
{
g_object_set_qdata (G_OBJECT (mark),
- seq->quark,
+ seq->priv->quark,
NULL);
}
static void
free_sequence (GtkSourceMarksSequence *seq)
{
- if (seq->seq != NULL)
+ if (seq->priv->seq != NULL)
{
- g_sequence_foreach (seq->seq,
+ g_sequence_foreach (seq->priv->seq,
(GFunc)remove_qdata,
seq);
- g_sequence_free (seq->seq);
- seq->seq = NULL;
+ g_sequence_free (seq->priv->seq);
+ seq->priv->seq = NULL;
}
}
static gint
compare_marks (GtkTextMark *mark1,
- GtkTextMark *mark2,
- gpointer user_data)
+ GtkTextMark *mark2,
+ gpointer user_data)
{
GtkTextBuffer *buffer;
GtkTextIter iter1;
@@ -103,13 +103,13 @@ compare_marks (GtkTextMark *mark1,
static void
mark_set_cb (GtkTextBuffer *buffer,
- GtkTextIter *location,
- GtkTextMark *mark,
- GtkSourceMarksSequence *seq)
+ GtkTextIter *location,
+ GtkTextMark *mark,
+ GtkSourceMarksSequence *seq)
{
GSequenceIter *seq_iter;
- seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+ seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
if (seq_iter != NULL)
{
@@ -121,22 +121,22 @@ mark_set_cb (GtkTextBuffer *buffer,
static void
mark_deleted_cb (GtkTextBuffer *buffer,
- GtkTextMark *mark,
- GtkSourceMarksSequence *seq)
+ GtkTextMark *mark,
+ GtkSourceMarksSequence *seq)
{
_gtk_source_marks_sequence_remove (seq, mark);
}
static void
set_buffer (GtkSourceMarksSequence *seq,
- GtkTextBuffer *buffer)
+ GtkTextBuffer *buffer)
{
- g_assert (seq->buffer == NULL);
+ g_assert (seq->priv->buffer == NULL);
- seq->buffer = buffer;
+ seq->priv->buffer = buffer;
g_object_add_weak_pointer (G_OBJECT (buffer),
- (gpointer *)&seq->buffer);
+ (gpointer *)&seq->priv->buffer);
g_signal_connect_object (buffer,
"mark-set",
@@ -156,12 +156,12 @@ _gtk_source_marks_sequence_dispose (GObject *object)
{
GtkSourceMarksSequence *seq = GTK_SOURCE_MARKS_SEQUENCE (object);
- if (seq->buffer != NULL)
+ if (seq->priv->buffer != NULL)
{
- g_object_remove_weak_pointer (G_OBJECT (seq->buffer),
- (gpointer *)&seq->buffer);
+ g_object_remove_weak_pointer (G_OBJECT (seq->priv->buffer),
+ (gpointer *)&seq->priv->buffer);
- seq->buffer = NULL;
+ seq->priv->buffer = NULL;
}
free_sequence (seq);
@@ -171,9 +171,9 @@ _gtk_source_marks_sequence_dispose (GObject *object)
static void
_gtk_source_marks_sequence_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceMarksSequence *seq;
@@ -184,7 +184,7 @@ _gtk_source_marks_sequence_get_property (GObject *object,
switch (prop_id)
{
case PROP_BUFFER:
- g_value_set_object (value, seq->buffer);
+ g_value_set_object (value, seq->priv->buffer);
break;
default:
@@ -195,9 +195,9 @@ _gtk_source_marks_sequence_get_property (GObject *object,
static void
_gtk_source_marks_sequence_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceMarksSequence *seq;
@@ -242,10 +242,12 @@ _gtk_source_marks_sequence_init (GtkSourceMarksSequence *seq)
{
gchar *unique_str;
- seq->seq = g_sequence_new ((GDestroyNotify)g_object_unref);
+ seq->priv = _gtk_source_marks_sequence_get_instance_private (seq);
+
+ seq->priv->seq = g_sequence_new ((GDestroyNotify)g_object_unref);
unique_str = g_strdup_printf ("gtk-source-marks-sequence-%p", seq);
- seq->quark = g_quark_from_string (unique_str);
+ seq->priv->quark = g_quark_from_string (unique_str);
g_free (unique_str);
}
@@ -264,20 +266,20 @@ _gtk_source_marks_sequence_is_empty (GtkSourceMarksSequence *seq)
{
g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), TRUE);
- return g_sequence_is_empty (seq->seq);
+ return g_sequence_is_empty (seq->priv->seq);
}
void
_gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
- GtkTextMark *mark)
+ GtkTextMark *mark)
{
GSequenceIter *seq_iter;
g_return_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq));
g_return_if_fail (GTK_IS_TEXT_MARK (mark));
- g_return_if_fail (gtk_text_mark_get_buffer (mark) == seq->buffer);
+ g_return_if_fail (gtk_text_mark_get_buffer (mark) == seq->priv->buffer);
- seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+ seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
if (seq_iter != NULL)
{
@@ -285,46 +287,46 @@ _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
return;
}
- seq_iter = g_sequence_insert_sorted (seq->seq,
+ seq_iter = g_sequence_insert_sorted (seq->priv->seq,
mark,
(GCompareDataFunc)compare_marks,
NULL);
g_object_ref (mark);
g_object_set_qdata (G_OBJECT (mark),
- seq->quark,
+ seq->priv->quark,
seq_iter);
}
void
_gtk_source_marks_sequence_remove (GtkSourceMarksSequence *seq,
- GtkTextMark *mark)
+ GtkTextMark *mark)
{
GSequenceIter *seq_iter;
g_return_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq));
g_return_if_fail (GTK_IS_TEXT_MARK (mark));
- seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+ seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
if (seq_iter != NULL)
{
- g_object_set_qdata (G_OBJECT (mark), seq->quark, NULL);
+ g_object_set_qdata (G_OBJECT (mark), seq->priv->quark, NULL);
g_sequence_remove (seq_iter);
}
}
GtkTextMark *
_gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
- GtkTextMark *mark)
+ GtkTextMark *mark)
{
GSequenceIter *seq_iter;
g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), NULL);
- g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->buffer, NULL);
+ g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->priv->buffer, NULL);
- seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+ seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
g_return_val_if_fail (seq_iter != NULL, NULL);
@@ -335,15 +337,15 @@ _gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
GtkTextMark *
_gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
- GtkTextMark *mark)
+ GtkTextMark *mark)
{
GSequenceIter *seq_iter;
g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), NULL);
- g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->buffer, NULL);
+ g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->priv->buffer, NULL);
- seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+ seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
g_return_val_if_fail (seq_iter != NULL, NULL);
@@ -362,33 +364,33 @@ _gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
*/
gboolean
_gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
- GtkTextIter *iter)
+ GtkTextIter *iter)
{
GtkTextMark *mark;
GSequenceIter *seq_iter;
g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->buffer, FALSE);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, FALSE);
- mark = gtk_text_buffer_create_mark (seq->buffer,
+ mark = gtk_text_buffer_create_mark (seq->priv->buffer,
NULL,
iter,
TRUE);
- seq_iter = g_sequence_search (seq->seq,
+ seq_iter = g_sequence_search (seq->priv->seq,
mark,
(GCompareDataFunc)compare_marks,
NULL);
- gtk_text_buffer_delete_mark (seq->buffer, mark);
+ gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
while (!g_sequence_iter_is_end (seq_iter))
{
GtkTextMark *cur_mark = g_sequence_get (seq_iter);
GtkTextIter cur_iter;
- gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+ gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
if (gtk_text_iter_compare (iter, &cur_iter) < 0)
{
@@ -407,26 +409,26 @@ _gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
*/
gboolean
_gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
- GtkTextIter *iter)
+ GtkTextIter *iter)
{
GtkTextMark *mark;
GSequenceIter *seq_iter;
g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->buffer, FALSE);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, FALSE);
- mark = gtk_text_buffer_create_mark (seq->buffer,
+ mark = gtk_text_buffer_create_mark (seq->priv->buffer,
NULL,
iter,
TRUE);
- seq_iter = g_sequence_search (seq->seq,
+ seq_iter = g_sequence_search (seq->priv->seq,
mark,
(GCompareDataFunc)compare_marks,
NULL);
- gtk_text_buffer_delete_mark (seq->buffer, mark);
+ gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
if (g_sequence_iter_is_end (seq_iter))
{
@@ -446,7 +448,7 @@ _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
cur_mark = g_sequence_get (seq_iter);
- gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+ gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
if (gtk_text_iter_compare (&cur_iter, iter) < 0)
{
@@ -467,8 +469,8 @@ _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
GSList *
_gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
- const GtkTextIter *iter1,
- const GtkTextIter *iter2)
+ const GtkTextIter *iter1,
+ const GtkTextIter *iter2)
{
GtkTextIter start;
GtkTextIter end;
@@ -480,25 +482,25 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
g_return_val_if_fail (iter1 != NULL, NULL);
g_return_val_if_fail (iter2 != NULL, NULL);
- g_return_val_if_fail (gtk_text_iter_get_buffer (iter1) == seq->buffer, NULL);
- g_return_val_if_fail (gtk_text_iter_get_buffer (iter2) == seq->buffer, NULL);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter1) == seq->priv->buffer, NULL);
+ g_return_val_if_fail (gtk_text_iter_get_buffer (iter2) == seq->priv->buffer, NULL);
start = *iter1;
end = *iter2;
gtk_text_iter_order (&start, &end);
- mark_start = gtk_text_buffer_create_mark (seq->buffer,
+ mark_start = gtk_text_buffer_create_mark (seq->priv->buffer,
NULL,
&start,
TRUE);
- seq_iter = g_sequence_search (seq->seq,
+ seq_iter = g_sequence_search (seq->priv->seq,
mark_start,
(GCompareDataFunc)compare_marks,
NULL);
- gtk_text_buffer_delete_mark (seq->buffer, mark_start);
+ gtk_text_buffer_delete_mark (seq->priv->buffer, mark_start);
if (g_sequence_iter_is_end (seq_iter))
{
@@ -519,7 +521,7 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
GtkTextIter cur_iter;
cur_mark = g_sequence_get (seq_iter);
- gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+ gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
if (gtk_text_iter_compare (&cur_iter, &start) < 0)
{
@@ -552,7 +554,7 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
GtkTextIter cur_iter;
cur_mark = g_sequence_get (seq_iter);
- gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+ gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
if (gtk_text_iter_compare (&end, &cur_iter) < 0)
{
@@ -567,7 +569,7 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
GSList *
_gtk_source_marks_sequence_get_marks_at_iter (GtkSourceMarksSequence *seq,
- const GtkTextIter *iter)
+ const GtkTextIter *iter)
{
return _gtk_source_marks_sequence_get_marks_in_range (seq, iter, iter);
}
diff --git a/gtksourceview/gtksourcemarshalers.list b/gtksourceview/gtksourcemarshalers.list
index de20fb82..7d4032c1 100644
--- a/gtksourceview/gtksourcemarshalers.list
+++ b/gtksourceview/gtksourcemarshalers.list
@@ -1,9 +1,12 @@
-BOOLEAN:BOXED,BOXED,INT,INT,OBJECT
BOOLEAN:BOXED,BOXED,BOXED
+BOOLEAN:BOXED,BOXED,INT,INT,OBJECT
+BOOLEAN:BOXED,BOXED,OBJECT
STRING:OBJECT
VOID:BOXED,BOXED
VOID:BOXED,BOXED,BOXED
+VOID:BOXED,BOXED,FLAGS
+VOID:BOXED,BOXED,OBJECT
VOID:BOXED,ENUM
VOID:BOXED,INT
VOID:ENUM,INT
-VOID:BOXED,BOXED,FLAGS
+VOID:OBJECT,UINT
diff --git a/gtksourceview/gtksourcepixbufhelper-private.h b/gtksourceview/gtksourcepixbufhelper-private.h
index 58904256..66a828ed 100644
--- a/gtksourceview/gtksourcepixbufhelper-private.h
+++ b/gtksourceview/gtksourcepixbufhelper-private.h
@@ -24,30 +24,34 @@
#include "gtksourcetypes-private.h"
-G_BEGIN_DECLS
-
-G_GNUC_INTERNAL
-GtkSourcePixbufHelper *gtk_source_pixbuf_helper_new (void);
G_GNUC_INTERNAL
-void gtk_source_pixbuf_helper_free (GtkSourcePixbufHelper *helper);
+GtkSourcePixbufHelper *gtk_source_pixbuf_helper_new (void);
+
G_GNUC_INTERNAL
-void gtk_source_pixbuf_helper_set_pixbuf (GtkSourcePixbufHelper *helper,
- const GdkPixbuf *pixbuf);
+void gtk_source_pixbuf_helper_free (GtkSourcePixbufHelper *helper);
+
G_GNUC_INTERNAL
-GdkPixbuf *gtk_source_pixbuf_helper_get_pixbuf (GtkSourcePixbufHelper *helper);
+void gtk_source_pixbuf_helper_set_pixbuf (GtkSourcePixbufHelper *helper,
+ const GdkPixbuf *pixbuf);
+
G_GNUC_INTERNAL
-void gtk_source_pixbuf_helper_set_icon_name (GtkSourcePixbufHelper *helper,
- const gchar *icon_name);
+GdkPixbuf *gtk_source_pixbuf_helper_get_pixbuf (GtkSourcePixbufHelper *helper);
+
G_GNUC_INTERNAL
-const gchar *gtk_source_pixbuf_helper_get_icon_name (GtkSourcePixbufHelper *helper);
+void gtk_source_pixbuf_helper_set_icon_name (GtkSourcePixbufHelper *helper,
+ const gchar *icon_name);
+
G_GNUC_INTERNAL
-void gtk_source_pixbuf_helper_set_gicon (GtkSourcePixbufHelper *helper,
- GIcon *gicon);
+const gchar *gtk_source_pixbuf_helper_get_icon_name (GtkSourcePixbufHelper *helper);
+
G_GNUC_INTERNAL
-GIcon *gtk_source_pixbuf_helper_get_gicon (GtkSourcePixbufHelper *helper);
+void gtk_source_pixbuf_helper_set_gicon (GtkSourcePixbufHelper *helper,
+ GIcon *gicon);
+
G_GNUC_INTERNAL
-GdkPixbuf *gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
- GtkWidget *widget,
- gint size);
+GIcon *gtk_source_pixbuf_helper_get_gicon (GtkSourcePixbufHelper *helper);
-G_END_DECLS
+G_GNUC_INTERNAL
+GdkPaintable *gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
+ GtkWidget *widget,
+ gint size);
diff --git a/gtksourceview/gtksourcepixbufhelper.c b/gtksourceview/gtksourcepixbufhelper.c
index 6af12974..3ecba51a 100644
--- a/gtksourceview/gtksourcepixbufhelper.c
+++ b/gtksourceview/gtksourcepixbufhelper.c
@@ -31,7 +31,7 @@ typedef enum _IconType
struct _GtkSourcePixbufHelper
{
- GdkPixbuf *cached_pixbuf;
+ GdkPaintable *cached_paintable;
IconType type;
GdkPixbuf *pixbuf;
@@ -48,40 +48,20 @@ gtk_source_pixbuf_helper_new (void)
void
gtk_source_pixbuf_helper_free (GtkSourcePixbufHelper *helper)
{
- if (helper->pixbuf)
- {
- g_object_unref (helper->pixbuf);
- }
-
- if (helper->cached_pixbuf)
- {
- g_object_unref (helper->cached_pixbuf);
- }
-
- if (helper->gicon)
- {
- g_object_unref (helper->gicon);
- }
-
- g_free (helper->icon_name);
+ g_clear_object (&helper->pixbuf);
+ g_clear_object (&helper->cached_paintable);
+ g_clear_object (&helper->gicon);
+ g_clear_pointer (&helper->icon_name, g_free);
g_slice_free (GtkSourcePixbufHelper, helper);
}
static void
set_cache (GtkSourcePixbufHelper *helper,
- GdkPixbuf *pixbuf)
+ GdkPaintable *paintable)
{
- if (helper->cached_pixbuf)
- {
- g_object_unref (helper->cached_pixbuf);
- helper->cached_pixbuf = NULL;
- }
-
- if (pixbuf)
- {
- helper->cached_pixbuf = pixbuf;
- }
+ g_clear_object (&helper->cached_paintable);
+ helper->cached_paintable = paintable;
}
static void
@@ -169,26 +149,10 @@ from_pixbuf (GtkSourcePixbufHelper *helper,
GtkWidget *widget,
gint size)
{
- if (helper->pixbuf == NULL)
+ if (helper->pixbuf != NULL)
{
- return;
- }
-
- if (gdk_pixbuf_get_width (helper->pixbuf) <= size)
- {
- if (!helper->cached_pixbuf)
- {
- set_cache (helper, gdk_pixbuf_copy (helper->pixbuf));
- }
-
- return;
+ set_cache (helper, GDK_PAINTABLE (gdk_texture_new_for_pixbuf (helper->pixbuf)));
}
-
- /* Make smaller */
- set_cache (helper, gdk_pixbuf_scale_simple (helper->pixbuf,
- size,
- size,
- GDK_INTERP_BILINEAR));
}
static void
@@ -196,13 +160,18 @@ from_gicon (GtkSourcePixbufHelper *helper,
GtkWidget *widget,
gint size)
{
- GdkScreen *screen;
+ GdkDisplay *display;
GtkIconTheme *icon_theme;
GtkIconInfo *info;
GtkIconLookupFlags flags;
- screen = gtk_widget_get_screen (widget);
- icon_theme = gtk_icon_theme_get_for_screen (screen);
+ if (helper->gicon == NULL)
+ {
+ return;
+ }
+
+ display = gtk_widget_get_display (widget);
+ icon_theme = gtk_icon_theme_get_for_display (display);
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
@@ -213,6 +182,7 @@ from_gicon (GtkSourcePixbufHelper *helper,
if (info)
{
+
set_cache (helper, gtk_icon_info_load_icon (info, NULL));
}
}
@@ -222,14 +192,19 @@ from_name (GtkSourcePixbufHelper *helper,
GtkWidget *widget,
gint size)
{
- GdkScreen *screen;
+ GdkDisplay *display;
GtkIconTheme *icon_theme;
GtkIconInfo *info;
GtkIconLookupFlags flags;
gint scale;
- screen = gtk_widget_get_screen (widget);
- icon_theme = gtk_icon_theme_get_for_screen (screen);
+ if (helper->icon_name == NULL)
+ {
+ return;
+ }
+
+ display = gtk_widget_get_display (widget);
+ icon_theme = gtk_icon_theme_get_for_display (display);
flags = GTK_ICON_LOOKUP_USE_BUILTIN;
scale = gtk_widget_get_scale_factor (widget);
@@ -242,33 +217,32 @@ from_name (GtkSourcePixbufHelper *helper,
if (info)
{
- GdkPixbuf *pixbuf;
+ GdkPaintable *paintable;
if (gtk_icon_info_is_symbolic (info))
{
GtkStyleContext *context;
context = gtk_widget_get_style_context (widget);
- pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
+ paintable = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
}
else
{
- pixbuf = gtk_icon_info_load_icon (info, NULL);
+ paintable = gtk_icon_info_load_icon (info, NULL);
}
- set_cache (helper, pixbuf);
+ set_cache (helper, paintable);
}
}
-GdkPixbuf *
+GdkPaintable *
gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
GtkWidget *widget,
gint size)
{
- if (helper->cached_pixbuf &&
- gdk_pixbuf_get_width (helper->cached_pixbuf) == size)
+ if (helper->cached_paintable != NULL)
{
- return helper->cached_pixbuf;
+ return helper->cached_paintable;
}
switch (helper->type)
@@ -286,6 +260,6 @@ gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
g_assert_not_reached ();
}
- return helper->cached_pixbuf;
+ return helper->cached_paintable;
}
diff --git a/gtksourceview/gtksourcespacedrawer-private.h b/gtksourceview/gtksourcespacedrawer-private.h
index e7d3a5b4..f44f83fe 100644
--- a/gtksourceview/gtksourcespacedrawer-private.h
+++ b/gtksourceview/gtksourcespacedrawer-private.h
@@ -21,18 +21,18 @@
#pragma once
#include <gtk/gtk.h>
-
#include "gtksourcetypes.h"
#include "gtksourcetypes-private.h"
G_BEGIN_DECLS
-GTK_SOURCE_INTERNAL
+G_GNUC_INTERNAL
void _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
GtkSourceView *view);
-GTK_SOURCE_INTERNAL
+
+G_GNUC_INTERNAL
void _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
GtkSourceView *view,
- cairo_t *cr);
+ GtkSnapshot *snapshot);
G_END_DECLS
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index adc32c8c..b74ffb87 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -23,13 +23,16 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcespacedrawer.h"
#include "gtksourcespacedrawer-private.h"
#include "gtksourcebuffer.h"
#include "gtksourcebuffer-private.h"
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
+#include "gtksourcestylescheme.h"
#include "gtksourcestylescheme-private.h"
#include "gtksourcetag.h"
#include "gtksourceview.h"
@@ -88,17 +91,39 @@
* default with a DVD of Matrix, in case the astronauts are bored.
*/
-/*
-#define ENABLE_PROFILE
-*/
-#undef ENABLE_PROFILE
+#if 0
+# define ENABLE_PROFILE
+#else
+# undef ENABLE_PROFILE
+#endif
-struct _GtkSourceSpaceDrawer
+typedef enum
+{
+ DRAW_TAB,
+ DRAW_NARROW_NBSP,
+ DRAW_NBSP,
+ DRAW_SPACE,
+ DRAW_NEWLINE,
+ N_DRAW
+} Draw;
+
+typedef struct
+{
+ GskRenderNode *node;
+ gint width;
+ gint height;
+} CachedNode;
+
+struct _GtkSourceSpaceDrawerPrivate
{
- GObject parent_instance;
GtkSourceSpaceTypeFlags *matrix;
- GdkRGBA *color;
- guint enable_matrix : 1;
+
+ CachedNode cached[N_DRAW];
+
+ GdkRGBA color;
+
+ guint color_set : 1;
+ guint enable_matrix : 1;
};
enum
@@ -111,7 +136,20 @@ enum
static GParamSpec *properties[N_PROPERTIES];
-G_DEFINE_TYPE (GtkSourceSpaceDrawer, gtk_source_space_drawer, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceSpaceDrawer, gtk_source_space_drawer, G_TYPE_OBJECT)
+
+static void
+gtk_source_space_drawer_purge_cache (GtkSourceSpaceDrawer *drawer)
+{
+ guint i;
+
+ g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
+
+ for (i = 0; i < G_N_ELEMENTS (drawer->priv->cached); i++)
+ {
+ g_clear_pointer (&drawer->priv->cached[i].node, gsk_render_node_unref);
+ }
+}
static gint
get_number_of_locations (void)
@@ -164,7 +202,7 @@ is_zero_matrix (GtkSourceSpaceDrawer *drawer)
for (i = 0; i < num_locations; i++)
{
- if (drawer->matrix[i] != 0)
+ if (drawer->priv->matrix[i] != 0)
{
return FALSE;
}
@@ -184,9 +222,9 @@ set_zero_matrix (GtkSourceSpaceDrawer *drawer)
for (i = 0; i < num_locations; i++)
{
- if (drawer->matrix[i] != 0)
+ if (drawer->priv->matrix[i] != 0)
{
- drawer->matrix[i] = 0;
+ drawer->priv->matrix[i] = 0;
changed = TRUE;
}
}
@@ -200,7 +238,7 @@ set_zero_matrix (GtkSourceSpaceDrawer *drawer)
/* AND */
static GtkSourceSpaceTypeFlags
get_types_at_all_locations (GtkSourceSpaceDrawer *drawer,
- GtkSourceSpaceLocationFlags locations)
+ GtkSourceSpaceLocationFlags locations)
{
GtkSourceSpaceTypeFlags ret = GTK_SOURCE_SPACE_TYPE_ALL;
gint index;
@@ -215,7 +253,7 @@ get_types_at_all_locations (GtkSourceSpaceDrawer *drawer,
{
if ((locations & 1) == 1)
{
- ret &= drawer->matrix[index];
+ ret &= drawer->priv->matrix[index];
found = TRUE;
}
@@ -229,7 +267,7 @@ get_types_at_all_locations (GtkSourceSpaceDrawer *drawer,
/* OR */
static GtkSourceSpaceTypeFlags
get_types_at_any_locations (GtkSourceSpaceDrawer *drawer,
- GtkSourceSpaceLocationFlags locations)
+ GtkSourceSpaceLocationFlags locations)
{
GtkSourceSpaceTypeFlags ret = GTK_SOURCE_SPACE_TYPE_NONE;
gint index;
@@ -242,7 +280,7 @@ get_types_at_any_locations (GtkSourceSpaceDrawer *drawer,
{
if ((locations & 1) == 1)
{
- ret |= drawer->matrix[index];
+ ret |= drawer->priv->matrix[index];
}
locations >>= 1;
@@ -254,9 +292,9 @@ get_types_at_any_locations (GtkSourceSpaceDrawer *drawer,
static void
gtk_source_space_drawer_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceSpaceDrawer *drawer = GTK_SOURCE_SPACE_DRAWER (object);
@@ -278,9 +316,9 @@ gtk_source_space_drawer_get_property (GObject *object,
static void
gtk_source_space_drawer_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceSpaceDrawer *drawer = GTK_SOURCE_SPACE_DRAWER (object);
@@ -305,12 +343,8 @@ gtk_source_space_drawer_finalize (GObject *object)
{
GtkSourceSpaceDrawer *drawer = GTK_SOURCE_SPACE_DRAWER (object);
- g_free (drawer->matrix);
-
- if (drawer->color != NULL)
- {
- gdk_rgba_free (drawer->color);
- }
+ gtk_source_space_drawer_purge_cache (drawer);
+ g_free (drawer->priv->matrix);
G_OBJECT_CLASS (gtk_source_space_drawer_parent_class)->finalize (object);
}
@@ -375,9 +409,9 @@ gtk_source_space_drawer_class_init (GtkSourceSpaceDrawerClass *klass)
static void
gtk_source_space_drawer_init (GtkSourceSpaceDrawer *drawer)
{
- drawer = gtk_source_space_drawer_get_instance_private (drawer);
+ drawer->priv = gtk_source_space_drawer_get_instance_private (drawer);
- drawer->matrix = g_new0 (GtkSourceSpaceTypeFlags, get_number_of_locations ());
+ drawer->priv->matrix = g_new0 (GtkSourceSpaceTypeFlags, get_number_of_locations ());
}
/**
@@ -414,7 +448,7 @@ gtk_source_space_drawer_new (void)
*/
GtkSourceSpaceTypeFlags
gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer *drawer,
- GtkSourceSpaceLocationFlags locations)
+ GtkSourceSpaceLocationFlags locations)
{
g_return_val_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer), GTK_SOURCE_SPACE_TYPE_NONE);
@@ -434,8 +468,8 @@ gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer *dr
*/
void
gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer *drawer,
- GtkSourceSpaceLocationFlags locations,
- GtkSourceSpaceTypeFlags types)
+ GtkSourceSpaceLocationFlags locations,
+ GtkSourceSpaceTypeFlags types)
{
gint index;
gint num_locations;
@@ -449,9 +483,9 @@ gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer *dr
while (locations != 0 && index < num_locations)
{
if ((locations & 1) == 1 &&
- drawer->matrix[index] != types)
+ drawer->priv->matrix[index] != types)
{
- drawer->matrix[index] = types;
+ drawer->priv->matrix[index] = types;
changed = TRUE;
}
@@ -501,7 +535,7 @@ gtk_source_space_drawer_get_matrix (GtkSourceSpaceDrawer *drawer)
{
GVariant *space_types;
- space_types = g_variant_new_uint32 (drawer->matrix[i]);
+ space_types = g_variant_new_uint32 (drawer->priv->matrix[i]);
g_variant_builder_add_value (&builder, space_types);
}
@@ -526,7 +560,7 @@ gtk_source_space_drawer_get_matrix (GtkSourceSpaceDrawer *drawer)
*/
void
gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
- GVariant *matrix)
+ GVariant *matrix)
{
gint num_locations;
gint index;
@@ -560,9 +594,9 @@ gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
space_types = g_variant_get_uint32 (child);
- if (drawer->matrix[index] != space_types)
+ if (drawer->priv->matrix[index] != space_types)
{
- drawer->matrix[index] = space_types;
+ drawer->priv->matrix[index] = space_types;
changed = TRUE;
}
@@ -572,9 +606,9 @@ gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
while (index < num_locations)
{
- if (drawer->matrix[index] != 0)
+ if (drawer->priv->matrix[index] != 0)
{
- drawer->matrix[index] = 0;
+ drawer->priv->matrix[index] = 0;
changed = TRUE;
}
@@ -605,7 +639,7 @@ gtk_source_space_drawer_get_enable_matrix (GtkSourceSpaceDrawer *drawer)
{
g_return_val_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer), FALSE);
- return drawer->enable_matrix;
+ return drawer->priv->enable_matrix;
}
/**
@@ -619,23 +653,23 @@ gtk_source_space_drawer_get_enable_matrix (GtkSourceSpaceDrawer *drawer)
*/
void
gtk_source_space_drawer_set_enable_matrix (GtkSourceSpaceDrawer *drawer,
- gboolean enable_matrix)
+ gboolean enable_matrix)
{
g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
enable_matrix = enable_matrix != FALSE;
- if (drawer->enable_matrix != enable_matrix)
+ if (drawer->priv->enable_matrix != enable_matrix)
{
- drawer->enable_matrix = enable_matrix;
+ drawer->priv->enable_matrix = enable_matrix;
g_object_notify_by_pspec (G_OBJECT (drawer), properties[PROP_ENABLE_MATRIX]);
}
}
static gboolean
matrix_get_mapping (GValue *value,
- GVariant *variant,
- gpointer user_data)
+ GVariant *variant,
+ gpointer user_data)
{
g_value_set_variant (value, variant);
return TRUE;
@@ -643,8 +677,8 @@ matrix_get_mapping (GValue *value,
static GVariant *
matrix_set_mapping (const GValue *value,
- const GVariantType *expected_type,
- gpointer user_data)
+ const GVariantType *expected_type,
+ gpointer user_data)
{
return g_value_dup_variant (value);
}
@@ -670,9 +704,9 @@ matrix_set_mapping (const GValue *value,
*/
void
gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
- GSettings *settings,
- const gchar *key,
- GSettingsBindFlags flags)
+ GSettings *settings,
+ const gchar *key,
+ GSettingsBindFlags flags)
{
GVariant *value;
@@ -700,7 +734,7 @@ gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
void
_gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
- GtkSourceView *view)
+ GtkSourceView *view)
{
GtkSourceBuffer *buffer;
GtkSourceStyleScheme *style_scheme;
@@ -708,11 +742,9 @@ _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
- if (drawer->color != NULL)
- {
- gdk_rgba_free (drawer->color);
- drawer->color = NULL;
- }
+ gtk_source_space_drawer_purge_cache (drawer);
+
+ drawer->priv->color_set = FALSE;
buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
style_scheme = gtk_source_buffer_get_style_scheme (buffer);
@@ -738,14 +770,15 @@ _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
color_str != NULL &&
gdk_rgba_parse (&color, color_str))
{
- drawer->color = gdk_rgba_copy (&color);
+ drawer->priv->color = color;
+ drawer->priv->color_set = TRUE;
}
g_free (color_str);
}
}
- if (drawer->color == NULL)
+ if (!drawer->priv->color_set)
{
GtkStyleContext *context;
GdkRGBA color;
@@ -753,12 +786,11 @@ _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
context = gtk_widget_get_style_context (GTK_WIDGET (view));
gtk_style_context_save (context);
gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
- gtk_style_context_get_color (context,
- gtk_style_context_get_state (context),
- &color);
+ gtk_style_context_get_color (context, &color);
gtk_style_context_restore (context);
- drawer->color = gdk_rgba_copy (&color);
+ drawer->priv->color = color;
+ drawer->priv->color_set = TRUE;
}
}
@@ -808,61 +840,43 @@ is_whitespace (gunichar ch)
}
static void
-draw_space_at_pos (cairo_t *cr,
- GdkRectangle rect)
+draw_space_at_pos (cairo_t *cr,
+ gdouble w,
+ gdouble h)
{
- gint x, y;
- gdouble w;
-
- x = rect.x;
- y = rect.y + rect.height * 2 / 3;
-
- w = rect.width;
+ const gint x = 0;
+ const gint y = h * 2 / 3;
- cairo_save (cr);
cairo_move_to (cr, x + w * 0.5, y);
cairo_arc (cr, x + w * 0.5, y, 0.8, 0, 2 * G_PI);
cairo_stroke (cr);
- cairo_restore (cr);
}
static void
-draw_tab_at_pos (cairo_t *cr,
- GdkRectangle rect)
+draw_tab_at_pos (cairo_t *cr,
+ gdouble w,
+ gdouble h)
{
- gint x, y;
- gdouble w, h;
+ const gint x = 0;
+ const gint y = h * 2 / 3;
- x = rect.x;
- y = rect.y + rect.height * 2 / 3;
-
- w = rect.width;
- h = rect.height;
-
- cairo_save (cr);
cairo_move_to (cr, x + w * 1 / 8, y);
cairo_rel_line_to (cr, w * 6 / 8, 0);
cairo_rel_line_to (cr, -h * 1 / 4, -h * 1 / 4);
cairo_rel_move_to (cr, +h * 1 / 4, +h * 1 / 4);
cairo_rel_line_to (cr, -h * 1 / 4, +h * 1 / 4);
cairo_stroke (cr);
- cairo_restore (cr);
}
static void
-draw_newline_at_pos (cairo_t *cr,
- GdkRectangle rect)
+draw_newline_at_pos (cairo_t *cr,
+ gdouble w,
+ gdouble h)
{
- gint x, y;
- gdouble w, h;
-
- x = rect.x;
- y = rect.y + rect.height / 3;
-
- w = 2 * rect.width;
- h = rect.height;
+ const gint x = 0;
+ const gint y = h / 3;
- cairo_save (cr);
+ w = w * 2;
if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR)
{
@@ -884,48 +898,50 @@ draw_newline_at_pos (cairo_t *cr,
}
cairo_stroke (cr);
- cairo_restore (cr);
}
static void
-draw_nbsp_at_pos (cairo_t *cr,
- GdkRectangle rect,
- gboolean narrowed)
+draw_narrow_nbsp_at_pos (cairo_t *cr,
+ gdouble w,
+ gdouble h)
{
- gint x, y;
- gdouble w, h;
+ const gint x = 0;
+ const gint y = h / 2;
- x = rect.x;
- y = rect.y + rect.height / 2;
-
- w = rect.width;
- h = rect.height;
-
- cairo_save (cr);
cairo_move_to (cr, x + w * 1 / 6, y);
cairo_rel_line_to (cr, w * 4 / 6, 0);
cairo_rel_line_to (cr, -w * 2 / 6, +h * 1 / 4);
cairo_rel_line_to (cr, -w * 2 / 6, -h * 1 / 4);
+ cairo_fill (cr);
+}
- if (narrowed)
- {
- cairo_fill (cr);
- }
- else
- {
- cairo_stroke (cr);
- }
+static void
+draw_nbsp_at_pos (cairo_t *cr,
+ gdouble w,
+ gdouble h)
+{
+ const gint x = 0;
+ const gint y = h / 2;
- cairo_restore (cr);
+ cairo_move_to (cr, x + w * 1 / 6, y);
+ cairo_rel_line_to (cr, w * 4 / 6, 0);
+ cairo_rel_line_to (cr, -w * 2 / 6, +h * 1 / 4);
+ cairo_rel_line_to (cr, -w * 2 / 6, -h * 1 / 4);
+ cairo_stroke (cr);
}
static void
-draw_whitespace_at_iter (GtkTextView *text_view,
- GtkTextIter *iter,
- cairo_t *cr)
+draw_whitespace_at_iter (GtkSourceSpaceDrawer *drawer,
+ GtkTextView *text_view,
+ const GtkTextIter *iter,
+ const GdkRGBA *color,
+ GtkSnapshot *snapshot)
{
- gunichar ch;
+ void (*draw) (cairo_t *cr, gdouble w, gdouble h) = NULL;
+ CachedNode *cache = NULL;
GdkRectangle rect;
+ gunichar ch;
+ gint ratio = 1;
gtk_text_view_get_iter_location (text_view, iter, &rect);
@@ -941,26 +957,73 @@ draw_whitespace_at_iter (GtkTextView *text_view,
if (is_tab (ch))
{
- draw_tab_at_pos (cr, rect);
+ draw = draw_tab_at_pos;
+ cache = &drawer->priv->cached[DRAW_TAB];
}
else if (is_nbsp (ch))
{
- draw_nbsp_at_pos (cr, rect, is_narrowed_nbsp (ch));
+ if (is_narrowed_nbsp (ch))
+ {
+ draw = draw_narrow_nbsp_at_pos;
+ cache = &drawer->priv->cached[DRAW_NARROW_NBSP];
+ }
+ else
+ {
+ draw = draw_nbsp_at_pos;
+ cache = &drawer->priv->cached[DRAW_NBSP];
+ }
}
else if (is_space (ch))
{
- draw_space_at_pos (cr, rect);
+ draw = draw_space_at_pos;
+ cache = &drawer->priv->cached[DRAW_SPACE];
}
else if (is_newline (iter))
{
- draw_newline_at_pos (cr, rect);
+ draw = draw_newline_at_pos;
+ cache = &drawer->priv->cached[DRAW_NEWLINE];
+ ratio = 2;
+ }
+
+ g_assert (draw == NULL || cache != NULL);
+
+ if (draw != NULL)
+ {
+ if (cache->width != rect.width || cache->height != rect.height)
+ {
+ g_clear_pointer (&cache->node, gsk_render_node_unref);
+ }
+
+ if G_UNLIKELY (cache->node == NULL)
+ {
+ GtkSnapshot *to_cache;
+ cairo_t *cr;
+
+ to_cache = gtk_snapshot_new ();
+ cr = gtk_snapshot_append_cairo (to_cache,
+ &GRAPHENE_RECT_INIT (0, 0, rect.width * ratio,
rect.height));
+ gdk_cairo_set_source_rgba (cr, color);
+ cairo_set_line_width (cr, 0.8);
+ cairo_translate (cr, -0.5, -0.5);
+ draw (cr, rect.width, rect.height);
+ cairo_destroy (cr);
+
+ cache->node = gtk_snapshot_free_to_node (g_steal_pointer (&to_cache));
+ cache->width = rect.width;
+ cache->height = rect.height;
+ }
+
+ gtk_snapshot_save (snapshot);
+ gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (rect.x, rect.y));
+ gtk_snapshot_append_node (snapshot, cache->node);
+ gtk_snapshot_restore (snapshot);
}
}
static void
space_needs_drawing_according_to_tag (const GtkTextIter *iter,
- gboolean *has_tag,
- gboolean *needs_drawing)
+ gboolean *has_tag,
+ gboolean *needs_drawing)
{
GSList *tags;
GSList *l;
@@ -999,8 +1062,8 @@ space_needs_drawing_according_to_tag (const GtkTextIter *iter,
static GtkSourceSpaceLocationFlags
get_iter_locations (const GtkTextIter *iter,
- const GtkTextIter *leading_end,
- const GtkTextIter *trailing_start)
+ const GtkTextIter *leading_end,
+ const GtkTextIter *trailing_start)
{
GtkSourceSpaceLocationFlags iter_locations = GTK_SOURCE_SPACE_LOCATION_NONE;
@@ -1052,9 +1115,9 @@ get_iter_space_type (const GtkTextIter *iter)
static gboolean
space_needs_drawing_according_to_matrix (GtkSourceSpaceDrawer *drawer,
- const GtkTextIter *iter,
- const GtkTextIter *leading_end,
- const GtkTextIter *trailing_start)
+ const GtkTextIter *iter,
+ const GtkTextIter *leading_end,
+ const GtkTextIter *trailing_start)
{
GtkSourceSpaceLocationFlags iter_locations;
GtkSourceSpaceTypeFlags iter_space_type;
@@ -1069,9 +1132,9 @@ space_needs_drawing_according_to_matrix (GtkSourceSpaceDrawer *drawer,
static gboolean
space_needs_drawing (GtkSourceSpaceDrawer *drawer,
- const GtkTextIter *iter,
- const GtkTextIter *leading_end,
- const GtkTextIter *trailing_start)
+ const GtkTextIter *iter,
+ const GtkTextIter *leading_end,
+ const GtkTextIter *trailing_start)
{
gboolean has_tag;
gboolean needs_drawing;
@@ -1084,17 +1147,17 @@ space_needs_drawing (GtkSourceSpaceDrawer *drawer,
}
/* Check the matrix */
- return (drawer->enable_matrix &&
+ return (drawer->priv->enable_matrix &&
space_needs_drawing_according_to_matrix (drawer, iter, leading_end, trailing_start));
}
static void
get_line_end (GtkTextView *text_view,
- const GtkTextIter *start_iter,
- GtkTextIter *line_end,
- gint max_x,
- gint max_y,
- gboolean is_wrapping)
+ const GtkTextIter *start_iter,
+ GtkTextIter *line_end,
+ gint max_x,
+ gint max_y,
+ gboolean is_wrapping)
{
gint min;
gint max;
@@ -1145,11 +1208,11 @@ get_line_end (GtkTextView *text_view,
void
_gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
GtkSourceView *view,
- cairo_t *cr)
+ GtkSnapshot *snapshot)
{
GtkTextView *text_view;
GtkTextBuffer *buffer;
- GdkRectangle clip;
+ GdkRectangle visible;
gint min_x;
gint min_y;
gint max_x;
@@ -1174,9 +1237,8 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
- g_return_if_fail (cr != NULL);
- if (drawer->color == NULL)
+ if (!drawer->priv->color_set)
{
g_warning ("GtkSourceSpaceDrawer: color not set.");
return;
@@ -1185,32 +1247,24 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
text_view = GTK_TEXT_VIEW (view);
buffer = gtk_text_view_get_buffer (text_view);
- if ((!drawer->enable_matrix || is_zero_matrix (drawer)) &&
+ if ((!drawer->priv->enable_matrix || is_zero_matrix (drawer)) &&
!_gtk_source_buffer_has_spaces_tag (GTK_SOURCE_BUFFER (buffer)))
{
return;
}
- if (!gdk_cairo_get_clip_rectangle (cr, &clip))
- {
- return;
- }
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible);
is_wrapping = gtk_text_view_get_wrap_mode (text_view) != GTK_WRAP_NONE;
- min_x = clip.x;
- min_y = clip.y;
- max_x = min_x + clip.width;
- max_y = min_y + clip.height;
+ min_x = visible.x;
+ min_y = visible.y;
+ max_x = min_x + visible.width;
+ max_y = min_y + visible.height;
gtk_text_view_get_iter_at_location (text_view, &start, min_x, min_y);
gtk_text_view_get_iter_at_location (text_view, &end, max_x, max_y);
- cairo_save (cr);
- gdk_cairo_set_source_rgba (cr, drawer->color);
- cairo_set_line_width (cr, 0.8);
- cairo_translate (cr, -0.5, -0.5);
-
iter = start;
_gtk_source_iter_get_leading_spaces_end_boundary (&iter, &leading_end);
_gtk_source_iter_get_trailing_spaces_start_boundary (&iter, &trailing_start);
@@ -1225,7 +1279,11 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
if ((is_whitespace (ch) || gtk_text_iter_is_end (&iter)) &&
space_needs_drawing (drawer, &iter, &leading_end, &trailing_start))
{
- draw_whitespace_at_iter (text_view, &iter, cr);
+ draw_whitespace_at_iter (drawer,
+ text_view,
+ &iter,
+ &drawer->priv->color,
+ snapshot);
}
if (gtk_text_iter_is_end (&iter) ||
@@ -1278,8 +1336,6 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
}
};
- cairo_restore (cr);
-
#ifdef ENABLE_PROFILE
g_timer_stop (timer);
diff --git a/gtksourceview/gtksourcespacedrawer.h b/gtksourceview/gtksourcespacedrawer.h
index dff6dacc..33aa2583 100644
--- a/gtksourceview/gtksourcespacedrawer.h
+++ b/gtksourceview/gtksourcespacedrawer.h
@@ -30,7 +30,29 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_SPACE_DRAWER (gtk_source_space_drawer_get_type())
+#define GTK_SOURCE_TYPE_SPACE_DRAWER (gtk_source_space_drawer_get_type ())
+#define GTK_SOURCE_SPACE_DRAWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_SPACE_DRAWER, GtkSourceSpaceDrawer))
+#define GTK_SOURCE_SPACE_DRAWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_SPACE_DRAWER, GtkSourceSpaceDrawerClass))
+#define GTK_SOURCE_IS_SPACE_DRAWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_SPACE_DRAWER))
+#define GTK_SOURCE_IS_SPACE_DRAWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_SPACE_DRAWER))
+#define GTK_SOURCE_SPACE_DRAWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_SPACE_DRAWER, GtkSourceSpaceDrawerClass))
+
+typedef struct _GtkSourceSpaceDrawerClass GtkSourceSpaceDrawerClass;
+typedef struct _GtkSourceSpaceDrawerPrivate GtkSourceSpaceDrawerPrivate;
+
+struct _GtkSourceSpaceDrawer
+{
+ GObject parent;
+
+ GtkSourceSpaceDrawerPrivate *priv;
+};
+
+struct _GtkSourceSpaceDrawerClass
+{
+ GObjectClass parent_class;
+
+ gpointer padding[20];
+};
/**
* GtkSourceSpaceTypeFlags:
@@ -49,12 +71,12 @@ G_BEGIN_DECLS
*/
typedef enum _GtkSourceSpaceTypeFlags
{
- GTK_SOURCE_SPACE_TYPE_NONE = 0,
- GTK_SOURCE_SPACE_TYPE_SPACE = 1 << 0,
- GTK_SOURCE_SPACE_TYPE_TAB = 1 << 1,
- GTK_SOURCE_SPACE_TYPE_NEWLINE = 1 << 2,
- GTK_SOURCE_SPACE_TYPE_NBSP = 1 << 3,
- GTK_SOURCE_SPACE_TYPE_ALL = 0xf
+ GTK_SOURCE_SPACE_TYPE_NONE = 0,
+ GTK_SOURCE_SPACE_TYPE_SPACE = 1 << 0,
+ GTK_SOURCE_SPACE_TYPE_TAB = 1 << 1,
+ GTK_SOURCE_SPACE_TYPE_NEWLINE = 1 << 2,
+ GTK_SOURCE_SPACE_TYPE_NBSP = 1 << 3,
+ GTK_SOURCE_SPACE_TYPE_ALL = 0xf
} GtkSourceSpaceTypeFlags;
/**
@@ -75,39 +97,46 @@ typedef enum _GtkSourceSpaceTypeFlags
*/
typedef enum _GtkSourceSpaceLocationFlags
{
- GTK_SOURCE_SPACE_LOCATION_NONE = 0,
- GTK_SOURCE_SPACE_LOCATION_LEADING = 1 << 0,
- GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT = 1 << 1,
- GTK_SOURCE_SPACE_LOCATION_TRAILING = 1 << 2,
- GTK_SOURCE_SPACE_LOCATION_ALL = 0x7
+ GTK_SOURCE_SPACE_LOCATION_NONE = 0,
+ GTK_SOURCE_SPACE_LOCATION_LEADING = 1 << 0,
+ GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT = 1 << 1,
+ GTK_SOURCE_SPACE_LOCATION_TRAILING = 1 << 2,
+ GTK_SOURCE_SPACE_LOCATION_ALL = 0x7
} GtkSourceSpaceLocationFlags;
GTK_SOURCE_AVAILABLE_IN_3_24
-G_DECLARE_FINAL_TYPE (GtkSourceSpaceDrawer, gtk_source_space_drawer, GTK_SOURCE, SPACE_DRAWER, GObject)
+GType gtk_source_space_drawer_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceSpaceDrawer *gtk_source_space_drawer_new (void);
+GtkSourceSpaceDrawer * gtk_source_space_drawer_new (void);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceSpaceTypeFlags gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer
*drawer,
- GtkSourceSpaceLocationFlags
locations);
+GtkSourceSpaceTypeFlags gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer
*drawer,
+ GtkSourceSpaceLocationFlags
locations);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-void gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer
*drawer,
- GtkSourceSpaceLocationFlags
locations,
- GtkSourceSpaceTypeFlags
types);
+void gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer *drawer,
+ GtkSourceSpaceLocationFlags
locations,
+ GtkSourceSpaceTypeFlags types);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-GVariant *gtk_source_space_drawer_get_matrix (GtkSourceSpaceDrawer
*drawer);
+GVariant * gtk_source_space_drawer_get_matrix (GtkSourceSpaceDrawer *drawer);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-void gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer
*drawer,
- GVariant
*matrix);
+void gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
+ GVariant *matrix);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-gboolean gtk_source_space_drawer_get_enable_matrix (GtkSourceSpaceDrawer
*drawer);
+gboolean gtk_source_space_drawer_get_enable_matrix (GtkSourceSpaceDrawer *drawer);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-void gtk_source_space_drawer_set_enable_matrix (GtkSourceSpaceDrawer
*drawer,
- gboolean
enable_matrix);
+void gtk_source_space_drawer_set_enable_matrix (GtkSourceSpaceDrawer *drawer,
+ gboolean enable_matrix);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-void gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer
*drawer,
- GSettings
*settings,
- const gchar *key,
- GSettingsBindFlags
flags);
+void gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
+ GSettings *settings,
+ const gchar *key,
+ GSettingsBindFlags flags);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestyle-private.h b/gtksourceview/gtksourcestyle-private.h
index 739ac6f6..b0a68e0f 100644
--- a/gtksourceview/gtksourcestyle-private.h
+++ b/gtksourceview/gtksourcestyle-private.h
@@ -33,15 +33,15 @@ G_BEGIN_DECLS
enum
{
- GTK_SOURCE_STYLE_USE_LINE_BACKGROUND = 1 << 0, /*< nick=use_line_background >*/
- GTK_SOURCE_STYLE_USE_BACKGROUND = 1 << 1, /*< nick=use_background >*/
- GTK_SOURCE_STYLE_USE_FOREGROUND = 1 << 2, /*< nick=use_foreground >*/
- GTK_SOURCE_STYLE_USE_ITALIC = 1 << 3, /*< nick=use_italic >*/
- GTK_SOURCE_STYLE_USE_BOLD = 1 << 4, /*< nick=use_bold >*/
- GTK_SOURCE_STYLE_USE_UNDERLINE = 1 << 5, /*< nick=use_underline >*/
- GTK_SOURCE_STYLE_USE_STRIKETHROUGH = 1 << 6, /*< nick=use_strikethrough >*/
- GTK_SOURCE_STYLE_USE_SCALE = 1 << 7, /*< nick=use_scale >*/
- GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR = 1 << 8, /*< nick=use_underline_color >*/
+ GTK_SOURCE_STYLE_USE_LINE_BACKGROUND = 1 << 0, /*< nick=use_line_background >*/
+ GTK_SOURCE_STYLE_USE_BACKGROUND = 1 << 1, /*< nick=use_background >*/
+ GTK_SOURCE_STYLE_USE_FOREGROUND = 1 << 2, /*< nick=use_foreground >*/
+ GTK_SOURCE_STYLE_USE_ITALIC = 1 << 3, /*< nick=use_italic >*/
+ GTK_SOURCE_STYLE_USE_BOLD = 1 << 4, /*< nick=use_bold >*/
+ GTK_SOURCE_STYLE_USE_UNDERLINE = 1 << 5, /*< nick=use_underline >*/
+ GTK_SOURCE_STYLE_USE_STRIKETHROUGH = 1 << 6, /*< nick=use_strikethrough >*/
+ GTK_SOURCE_STYLE_USE_SCALE = 1 << 7, /*< nick=use_scale >*/
+ GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR = 1 << 8 /*< nick=use_underline_color >*/
};
struct _GtkSourceStyle
diff --git a/gtksourceview/gtksourcestyle.c b/gtksourceview/gtksourcestyle.c
index 65048c84..fe1e4962 100644
--- a/gtksourceview/gtksourcestyle.c
+++ b/gtksourceview/gtksourcestyle.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcestyle.h"
#include "gtksourcestyle-private.h"
@@ -33,14 +35,20 @@
* which are set when given style is used.
*/
-static void gtk_source_style_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_source_style_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+static void gtk_source_style_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void gtk_source_style_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+struct _GtkSourceStyleClass
+{
+ GObjectClass parent_class;
+};
G_DEFINE_TYPE (GtkSourceStyle, gtk_source_style, G_TYPE_OBJECT)
@@ -249,9 +257,9 @@ G_STMT_START { \
static void
gtk_source_style_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceStyle *style = GTK_SOURCE_STYLE (object);
const gchar *string;
@@ -391,10 +399,10 @@ gtk_source_style_set_property (GObject *object,
}
static void
-gtk_source_style_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+gtk_source_style_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceStyle *style = GTK_SOURCE_STYLE (object);
@@ -530,7 +538,7 @@ gtk_source_style_copy (const GtkSourceStyle *style)
*/
void
gtk_source_style_apply (const GtkSourceStyle *style,
- GtkTextTag *tag)
+ GtkTextTag *tag)
{
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
diff --git a/gtksourceview/gtksourcestyle.h b/gtksourceview/gtksourcestyle.h
index 3ae95dc8..6e8ece45 100644
--- a/gtksourceview/gtksourcestyle.h
+++ b/gtksourceview/gtksourcestyle.h
@@ -30,15 +30,23 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_STYLE (gtk_source_style_get_type ())
+#define GTK_SOURCE_TYPE_STYLE (gtk_source_style_get_type ())
+#define GTK_SOURCE_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_STYLE,
GtkSourceStyle))
+#define GTK_SOURCE_IS_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_STYLE))
+#define GTK_SOURCE_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_STYLE,
GtkSourceStyleClass))
+#define GTK_SOURCE_IS_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_STYLE))
+#define GTK_SOURCE_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_STYLE,
GtkSourceStyleClass))
+
+typedef struct _GtkSourceStyleClass GtkSourceStyleClass;
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceStyle, gtk_source_style, GTK_SOURCE, STYLE, GObject)
+GType gtk_source_style_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyle *gtk_source_style_copy (const GtkSourceStyle *style);
+GtkSourceStyle *gtk_source_style_copy (const GtkSourceStyle *style);
+
GTK_SOURCE_AVAILABLE_IN_3_22
-void gtk_source_style_apply (const GtkSourceStyle *style,
- GtkTextTag *tag);
+void gtk_source_style_apply (const GtkSourceStyle *style,
+ GtkTextTag *tag);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestylescheme-private.h b/gtksourceview/gtksourcestylescheme-private.h
index c2846eea..753c0e4b 100644
--- a/gtksourceview/gtksourcestylescheme-private.h
+++ b/gtksourceview/gtksourcestylescheme-private.h
@@ -20,6 +20,9 @@
#pragma once
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes.h"
#include "gtksourcestylescheme.h"
G_BEGIN_DECLS
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 668585e6..54ee218a 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -18,11 +18,13 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <glib/gi18n-lib.h>
#include <libxml/parser.h>
#include <string.h>
-#include <glib/gi18n-lib.h>
#include "gtksourcestylescheme.h"
#include "gtksourcestylescheme-private.h"
@@ -78,10 +80,8 @@ enum
PROP_FILENAME
};
-struct _GtkSourceStyleScheme
+struct _GtkSourceStyleSchemePrivate
{
- GObject parent_instance;
-
gchar *id;
gchar *name;
GPtrArray *authors;
@@ -97,34 +97,34 @@ struct _GtkSourceStyleScheme
GtkCssProvider *css_provider_cursors;
};
-G_DEFINE_TYPE (GtkSourceStyleScheme, gtk_source_style_scheme, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceStyleScheme, gtk_source_style_scheme, G_TYPE_OBJECT)
static void
gtk_source_style_scheme_dispose (GObject *object)
{
GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
- if (scheme->named_colors != NULL)
+ if (scheme->priv->named_colors != NULL)
{
- g_hash_table_unref (scheme->named_colors);
- scheme->named_colors = NULL;
+ g_hash_table_unref (scheme->priv->named_colors);
+ scheme->priv->named_colors = NULL;
}
- if (scheme->style_cache != NULL)
+ if (scheme->priv->style_cache != NULL)
{
- g_hash_table_unref (scheme->style_cache);
- scheme->style_cache = NULL;
+ g_hash_table_unref (scheme->priv->style_cache);
+ scheme->priv->style_cache = NULL;
}
- if (scheme->defined_styles != NULL)
+ if (scheme->priv->defined_styles != NULL)
{
- g_hash_table_unref (scheme->defined_styles);
- scheme->defined_styles = NULL;
+ g_hash_table_unref (scheme->priv->defined_styles);
+ scheme->priv->defined_styles = NULL;
}
- g_clear_object (&scheme->parent);
- g_clear_object (&scheme->css_provider);
- g_clear_object (&scheme->css_provider_cursors);
+ g_clear_object (&scheme->priv->parent);
+ g_clear_object (&scheme->priv->css_provider);
+ g_clear_object (&scheme->priv->css_provider_cursors);
G_OBJECT_CLASS (gtk_source_style_scheme_parent_class)->dispose (object);
}
@@ -134,33 +134,33 @@ gtk_source_style_scheme_finalize (GObject *object)
{
GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
- if (scheme->authors != NULL)
+ if (scheme->priv->authors != NULL)
{
- g_ptr_array_free (scheme->authors, TRUE);
+ g_ptr_array_free (scheme->priv->authors, TRUE);
}
- g_free (scheme->filename);
- g_free (scheme->description);
- g_free (scheme->id);
- g_free (scheme->name);
- g_free (scheme->parent_id);
+ g_free (scheme->priv->filename);
+ g_free (scheme->priv->description);
+ g_free (scheme->priv->id);
+ g_free (scheme->priv->name);
+ g_free (scheme->priv->parent_id);
G_OBJECT_CLASS (gtk_source_style_scheme_parent_class)->finalize (object);
}
static void
-gtk_source_style_scheme_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+gtk_source_style_scheme_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
switch (prop_id)
{
case PROP_ID:
- g_free (scheme->id);
- scheme->id = g_value_dup_string (value);
+ g_free (scheme->priv->id);
+ scheme->priv->id = g_value_dup_string (value);
break;
default:
@@ -170,29 +170,29 @@ gtk_source_style_scheme_set_property (GObject *object,
}
static void
-gtk_source_style_scheme_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+gtk_source_style_scheme_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
switch (prop_id)
{
case PROP_ID:
- g_value_set_string (value, scheme->id);
+ g_value_set_string (value, scheme->priv->id);
break;
case PROP_NAME:
- g_value_set_string (value, scheme->name);
+ g_value_set_string (value, scheme->priv->name);
break;
case PROP_DESCRIPTION:
- g_value_set_string (value, scheme->description);
+ g_value_set_string (value, scheme->priv->description);
break;
case PROP_FILENAME:
- g_value_set_string (value, scheme->filename);
+ g_value_set_string (value, scheme->priv->filename);
break;
default:
@@ -277,18 +277,18 @@ unref_if_not_null (gpointer object)
static void
gtk_source_style_scheme_init (GtkSourceStyleScheme *scheme)
{
- scheme = gtk_source_style_scheme_get_instance_private (scheme);
+ scheme->priv = gtk_source_style_scheme_get_instance_private (scheme);
- scheme->defined_styles = g_hash_table_new_full (g_str_hash, g_str_equal,
+ scheme->priv->defined_styles = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
- scheme->style_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ scheme->priv->style_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, unref_if_not_null);
- scheme->named_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
+ scheme->priv->named_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
- scheme->css_provider = gtk_css_provider_new ();
+ scheme->priv->css_provider = gtk_css_provider_new ();
}
/**
@@ -303,9 +303,9 @@ const gchar *
gtk_source_style_scheme_get_id (GtkSourceStyleScheme *scheme)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
- g_return_val_if_fail (scheme->id != NULL, "");
+ g_return_val_if_fail (scheme->priv->id != NULL, "");
- return scheme->id;
+ return scheme->priv->id;
}
/**
@@ -320,9 +320,9 @@ const gchar *
gtk_source_style_scheme_get_name (GtkSourceStyleScheme *scheme)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
- g_return_val_if_fail (scheme->name != NULL, "");
+ g_return_val_if_fail (scheme->priv->name != NULL, "");
- return scheme->name;
+ return scheme->priv->name;
}
/**
@@ -338,7 +338,7 @@ gtk_source_style_scheme_get_description (GtkSourceStyleScheme *scheme)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
- return scheme->description;
+ return scheme->priv->description;
}
/**
@@ -356,12 +356,12 @@ gtk_source_style_scheme_get_authors (GtkSourceStyleScheme *scheme)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
- if (scheme->authors == NULL)
+ if (scheme->priv->authors == NULL)
{
return NULL;
}
- return (const gchar * const *)scheme->authors->pdata;
+ return (const gchar * const *)scheme->priv->authors->pdata;
}
/**
@@ -378,7 +378,7 @@ gtk_source_style_scheme_get_filename (GtkSourceStyleScheme *scheme)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
- return scheme->filename;
+ return scheme->priv->filename;
}
/*
@@ -418,7 +418,7 @@ color_parse (const gchar *color,
*/
static const gchar *
get_color_by_name (GtkSourceStyleScheme *scheme,
- const gchar *name)
+ const gchar *name)
{
const char *color = NULL;
@@ -437,11 +437,11 @@ get_color_by_name (GtkSourceStyleScheme *scheme,
}
else
{
- color = g_hash_table_lookup (scheme->named_colors, name);
+ color = g_hash_table_lookup (scheme->priv->named_colors, name);
- if (color == NULL && scheme->parent != NULL)
+ if (color == NULL && scheme->priv->parent != NULL)
{
- color = get_color_by_name (scheme->parent, name);
+ color = get_color_by_name (scheme->priv->parent, name);
}
if (color == NULL)
@@ -455,7 +455,7 @@ get_color_by_name (GtkSourceStyleScheme *scheme,
static GtkSourceStyle *
fix_style_colors (GtkSourceStyleScheme *scheme,
- GtkSourceStyle *real_style)
+ GtkSourceStyle *real_style)
{
GtkSourceStyle *style;
guint i;
@@ -495,47 +495,6 @@ fix_style_colors (GtkSourceStyleScheme *scheme,
return style;
}
-static GtkSourceStyle *
-gtk_source_style_scheme_get_style_internal (GtkSourceStyleScheme *scheme,
- const gchar *style_id)
-{
- GtkSourceStyle *style = NULL;
- GtkSourceStyle *real_style;
-
- if (g_hash_table_lookup_extended (scheme->style_cache,
- style_id,
- NULL,
- (gpointer)&style))
- {
- return style;
- }
-
- real_style = g_hash_table_lookup (scheme->defined_styles, style_id);
-
- if (real_style == NULL)
- {
- if (scheme->parent != NULL)
- {
- style = gtk_source_style_scheme_get_style (scheme->parent,
- style_id);
- }
- if (style != NULL)
- {
- g_object_ref (style);
- }
- }
- else
- {
- style = fix_style_colors (scheme, real_style);
- }
-
- g_hash_table_insert (scheme->style_cache,
- g_strdup (style_id),
- style);
-
- return style;
-}
-
/**
* gtk_source_style_scheme_get_style:
* @scheme: a #GtkSourceStyleScheme.
@@ -560,37 +519,44 @@ gtk_source_style_scheme_get_style_internal (GtkSourceStyleScheme *scheme,
*/
GtkSourceStyle *
gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
- const gchar *style_id)
+ const gchar *style_id)
{
- GtkSourceStyle *style;
+ GtkSourceStyle *style = NULL;
+ GtkSourceStyle *real_style;
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
g_return_val_if_fail (style_id != NULL, NULL);
+ if (g_hash_table_lookup_extended (scheme->priv->style_cache,
+ style_id,
+ NULL,
+ (gpointer)&style))
+ {
+ return style;
+ }
- style = gtk_source_style_scheme_get_style_internal (scheme, style_id);
+ real_style = g_hash_table_lookup (scheme->priv->defined_styles, style_id);
- if (style == NULL)
+ if (real_style == NULL)
{
- /* Long ago, "underlined" was added as a style. The problem with
- * this is that it defines how something should look rather than
- * classifying what it is.
- *
- * In general, this was used for URLs.
- *
- * However, going forward we want to change this but do our best
- * to not break existing style-schemes. Should "net-address" be
- * requested, but only "underlined" existed, we will fallback to
- * the "underlined" style.
- *
- * If in the future, we need to support more fallbacks, this should
- * be changed to a GHashTable to map from src->dst style id.
- */
- if (g_str_equal (style_id, "def:net-address"))
+ if (scheme->priv->parent != NULL)
{
- style = gtk_source_style_scheme_get_style_internal (scheme, "def:underlined");
+ style = gtk_source_style_scheme_get_style (scheme->priv->parent,
+ style_id);
+ }
+ if (style != NULL)
+ {
+ g_object_ref (style);
}
}
+ else
+ {
+ style = fix_style_colors (scheme, real_style);
+ }
+
+ g_hash_table_insert (scheme->priv->style_cache,
+ g_strdup (style_id),
+ style);
return style;
}
@@ -621,8 +587,8 @@ _gtk_source_style_scheme_get_draw_spaces_style (GtkSourceStyleScheme *scheme)
static gboolean
get_color (GtkSourceStyle *style,
- gboolean foreground,
- GdkRGBA *dest)
+ gboolean foreground,
+ GdkRGBA *dest)
{
const gchar *color;
guint mask;
@@ -661,7 +627,7 @@ get_color (GtkSourceStyle *style,
*/
gboolean
_gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
- GdkRGBA *color)
+ GdkRGBA *color)
{
GtkSourceStyle *style;
@@ -692,7 +658,7 @@ _gtk_source_style_scheme_get_background_pattern_color (GtkSourceStyleScheme *sch
static gchar *
get_cursors_css_style (GtkSourceStyleScheme *scheme,
- GtkWidget *widget)
+ GtkWidget *widget)
{
GtkSourceStyle *primary_style;
GtkSourceStyle *secondary_style;
@@ -740,7 +706,6 @@ get_cursors_css_style (GtkSourceStyleScheme *scheme,
gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
gtk_style_context_get (context,
- gtk_style_context_get_state (context),
"background-color", &background_color,
NULL);
@@ -775,7 +740,7 @@ get_cursors_css_style (GtkSourceStyleScheme *scheme,
*/
static GtkCssProvider *
get_css_provider_cursors (GtkSourceStyleScheme *scheme,
- GtkWidget *widget)
+ GtkWidget *widget)
{
gchar *css;
GtkCssProvider *provider;
@@ -790,7 +755,7 @@ get_css_provider_cursors (GtkSourceStyleScheme *scheme,
provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (provider, css, -1, &error);
+ gtk_css_provider_load_from_data (provider, css, -1);
g_free (css);
if (error != NULL)
@@ -814,7 +779,7 @@ get_css_provider_cursors (GtkSourceStyleScheme *scheme,
*/
void
_gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
- GtkSourceView *view)
+ GtkSourceView *view)
{
GtkStyleContext *context;
@@ -823,32 +788,23 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
context = gtk_widget_get_style_context (GTK_WIDGET (view));
gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (scheme->css_provider),
+ GTK_STYLE_PROVIDER (scheme->priv->css_provider),
GTK_SOURCE_STYLE_PROVIDER_PRIORITY);
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- /* See https://bugzilla.gnome.org/show_bug.cgi?id=708583 */
- gtk_style_context_invalidate (context);
- G_GNUC_END_IGNORE_DEPRECATIONS;
-
/* The CssProvider for the cursors needs that the first provider is
* applied, to get the background color.
*/
- if (scheme->css_provider_cursors == NULL)
+ if (scheme->priv->css_provider_cursors == NULL)
{
- scheme->css_provider_cursors = get_css_provider_cursors (scheme,
+ scheme->priv->css_provider_cursors = get_css_provider_cursors (scheme,
GTK_WIDGET (view));
}
- if (scheme->css_provider_cursors != NULL)
+ if (scheme->priv->css_provider_cursors != NULL)
{
gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (scheme->css_provider_cursors),
+ GTK_STYLE_PROVIDER (scheme->priv->css_provider_cursors),
GTK_SOURCE_STYLE_PROVIDER_PRIORITY);
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- gtk_style_context_invalidate (context);
- G_GNUC_END_IGNORE_DEPRECATIONS;
}
}
@@ -863,7 +819,7 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
*/
void
_gtk_source_style_scheme_unapply (GtkSourceStyleScheme *scheme,
- GtkSourceView *view)
+ GtkSourceView *view)
{
GtkStyleContext *context;
@@ -872,18 +828,13 @@ _gtk_source_style_scheme_unapply (GtkSourceStyleScheme *scheme,
context = gtk_widget_get_style_context (GTK_WIDGET (view));
gtk_style_context_remove_provider (context,
- GTK_STYLE_PROVIDER (scheme->css_provider));
+ GTK_STYLE_PROVIDER (scheme->priv->css_provider));
- if (scheme->css_provider_cursors != NULL)
+ if (scheme->priv->css_provider_cursors != NULL)
{
gtk_style_context_remove_provider (context,
- GTK_STYLE_PROVIDER (scheme->css_provider_cursors));
+ GTK_STYLE_PROVIDER (scheme->priv->css_provider_cursors));
}
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- /* See https://bugzilla.gnome.org/show_bug.cgi?id=708583 */
- gtk_style_context_invalidate (context);
- G_GNUC_END_IGNORE_DEPRECATIONS;
}
/* --- PARSER ---------------------------------------------------------------- */
@@ -1000,10 +951,9 @@ generate_css_style (GtkSourceStyleScheme *scheme)
{
GError *error = NULL;
- gtk_css_provider_load_from_data (scheme->css_provider,
+ gtk_css_provider_load_from_data (scheme->priv->css_provider,
final_style->str,
- final_style->len,
- &error);
+ final_style->len);
if (error != NULL)
{
@@ -1025,10 +975,10 @@ parse_bool (char *value)
static void
get_bool (xmlNode *node,
- const char *propname,
- guint *mask,
- guint mask_value,
- gboolean *value)
+ const char *propname,
+ guint *mask,
+ guint mask_value,
+ gboolean *value)
{
xmlChar *tmp = xmlGetProp (node, BAD_CAST propname);
@@ -1042,11 +992,11 @@ get_bool (xmlNode *node,
}
static gboolean
-parse_style (GtkSourceStyleScheme *scheme,
- xmlNode *node,
- gchar **style_name_p,
- GtkSourceStyle **style_p,
- GError **error)
+parse_style (GtkSourceStyleScheme *scheme,
+ xmlNode *node,
+ gchar **style_name_p,
+ GtkSourceStyle **style_p,
+ GError **error)
{
GtkSourceStyle *use_style = NULL;
GtkSourceStyle *result = NULL;
@@ -1213,9 +1163,9 @@ parse_style (GtkSourceStyleScheme *scheme,
}
static gboolean
-parse_color (GtkSourceStyleScheme *scheme,
- xmlNode *node,
- GError **error)
+parse_color (GtkSourceStyleScheme *scheme,
+ xmlNode *node,
+ GError **error)
{
xmlChar *name, *value;
gboolean result = FALSE;
@@ -1229,13 +1179,13 @@ parse_color (GtkSourceStyleScheme *scheme,
g_set_error (error, ERROR_QUARK, 0, "value attribute missing in 'color' tag");
else if (value[0] != '#' || value[1] == 0)
g_set_error (error, ERROR_QUARK, 0, "value in 'color' tag is not of the form '#RGB' or
'#name'");
- else if (g_hash_table_lookup (scheme->named_colors, name) != NULL)
+ else if (g_hash_table_lookup (scheme->priv->named_colors, name) != NULL)
g_set_error (error, ERROR_QUARK, 0, "duplicated color '%s'", name);
else
result = TRUE;
if (result)
- g_hash_table_insert (scheme->named_colors,
+ g_hash_table_insert (scheme->priv->named_colors,
g_strdup ((char *) name),
g_strdup ((char *) value));
@@ -1246,9 +1196,9 @@ parse_color (GtkSourceStyleScheme *scheme,
}
static gboolean
-parse_style_scheme_child (GtkSourceStyleScheme *scheme,
- xmlNode *node,
- GError **error)
+parse_style_scheme_child (GtkSourceStyleScheme *scheme,
+ xmlNode *node,
+ GError **error)
{
if (strcmp ((char*) node->name, "style") == 0)
{
@@ -1258,7 +1208,7 @@ parse_style_scheme_child (GtkSourceStyleScheme *scheme,
if (!parse_style (scheme, node, &style_name, &style, error))
return FALSE;
- g_hash_table_insert (scheme->defined_styles, style_name, style);
+ g_hash_table_insert (scheme->priv->defined_styles, style_name, style);
}
else if (strcmp ((char*) node->name, "color") == 0)
{
@@ -1268,23 +1218,23 @@ parse_style_scheme_child (GtkSourceStyleScheme *scheme,
else if (strcmp ((char*) node->name, "author") == 0)
{
xmlChar *tmp = xmlNodeGetContent (node);
- if (scheme->authors == NULL)
- scheme->authors = g_ptr_array_new_with_free_func (g_free);
+ if (scheme->priv->authors == NULL)
+ scheme->priv->authors = g_ptr_array_new_with_free_func (g_free);
- g_ptr_array_add (scheme->authors, g_strdup ((char*) tmp));
+ g_ptr_array_add (scheme->priv->authors, g_strdup ((char*) tmp));
xmlFree (tmp);
}
else if (strcmp ((char*) node->name, "description") == 0)
{
xmlChar *tmp = xmlNodeGetContent (node);
- scheme->description = g_strdup ((char*) tmp);
+ scheme->priv->description = g_strdup ((char*) tmp);
xmlFree (tmp);
}
else if (strcmp ((char*) node->name, "_description") == 0)
{
xmlChar *tmp = xmlNodeGetContent (node);
- scheme->description = g_strdup (_((char*) tmp));
+ scheme->priv->description = g_strdup (_((char*) tmp));
xmlFree (tmp);
}
else
@@ -1297,9 +1247,9 @@ parse_style_scheme_child (GtkSourceStyleScheme *scheme,
}
static void
-parse_style_scheme_element (GtkSourceStyleScheme *scheme,
- xmlNode *scheme_node,
- GError **error)
+parse_style_scheme_element (GtkSourceStyleScheme *scheme,
+ xmlNode *scheme_node,
+ GError **error)
{
xmlChar *tmp;
xmlNode *node;
@@ -1332,14 +1282,14 @@ parse_style_scheme_element (GtkSourceStyleScheme *scheme,
g_set_error (error, ERROR_QUARK, 0, "missing 'id' attribute");
return;
}
- scheme->id = g_strdup ((char*) tmp);
+ scheme->priv->id = g_strdup ((char*) tmp);
xmlFree (tmp);
tmp = xmlGetProp (scheme_node, BAD_CAST "_name");
if (tmp != NULL)
- scheme->name = g_strdup (_((char*) tmp));
+ scheme->priv->name = g_strdup (_((char*) tmp));
else if ((tmp = xmlGetProp (scheme_node, BAD_CAST "name")) != NULL)
- scheme->name = g_strdup ((char*) tmp);
+ scheme->priv->name = g_strdup ((char*) tmp);
else
{
g_set_error (error, ERROR_QUARK, 0, "missing 'name' attribute");
@@ -1349,7 +1299,7 @@ parse_style_scheme_element (GtkSourceStyleScheme *scheme,
tmp = xmlGetProp (scheme_node, BAD_CAST "parent-scheme");
if (tmp != NULL)
- scheme->parent_id = g_strdup ((char*) tmp);
+ scheme->priv->parent_id = g_strdup ((char*) tmp);
xmlFree (tmp);
for (node = scheme_node->children; node != NULL; node = node->next)
@@ -1358,8 +1308,8 @@ parse_style_scheme_element (GtkSourceStyleScheme *scheme,
return;
/* NULL-terminate the array of authors */
- if (scheme->authors != NULL)
- g_ptr_array_add (scheme->authors, NULL);
+ if (scheme->priv->authors != NULL)
+ g_ptr_array_add (scheme->priv->authors, NULL);
}
/**
@@ -1417,7 +1367,7 @@ _gtk_source_style_scheme_new_from_file (const gchar *filename)
}
scheme = g_object_new (GTK_SOURCE_TYPE_STYLE_SCHEME, NULL);
- scheme->filename = g_strdup (filename);
+ scheme->priv->filename = g_strdup (filename);
parse_style_scheme_element (scheme, node, &error);
@@ -1455,7 +1405,7 @@ _gtk_source_style_scheme_get_parent_id (GtkSourceStyleScheme *scheme)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
- return scheme->parent_id;
+ return scheme->priv->parent_id;
}
/**
@@ -1471,27 +1421,27 @@ _gtk_source_style_scheme_get_parent_id (GtkSourceStyleScheme *scheme)
*/
void
_gtk_source_style_scheme_set_parent (GtkSourceStyleScheme *scheme,
- GtkSourceStyleScheme *parent_scheme)
+ GtkSourceStyleScheme *parent_scheme)
{
g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme));
g_return_if_fail (parent_scheme == NULL || GTK_SOURCE_IS_STYLE_SCHEME (parent_scheme));
- if (scheme->parent == parent_scheme)
+ if (scheme->priv->parent == parent_scheme)
{
return;
}
- g_clear_object (&scheme->parent);
+ g_clear_object (&scheme->priv->parent);
if (parent_scheme != NULL)
{
g_object_ref (parent_scheme);
}
- scheme->parent = parent_scheme;
+ scheme->priv->parent = parent_scheme;
/* Update CSS based on parent styles */
- g_hash_table_remove_all (scheme->style_cache);
+ g_hash_table_remove_all (scheme->priv->style_cache);
generate_css_style (scheme);
}
diff --git a/gtksourceview/gtksourcestylescheme.h b/gtksourceview/gtksourcestylescheme.h
index 6e598543..57cb9a70 100644
--- a/gtksourceview/gtksourcestylescheme.h
+++ b/gtksourceview/gtksourcestylescheme.h
@@ -30,23 +30,50 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_STYLE_SCHEME (gtk_source_style_scheme_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME (gtk_source_style_scheme_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME, GtkSourceStyleScheme))
+#define GTK_SOURCE_STYLE_SCHEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME, GtkSourceStyleSchemeClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME))
+#define GTK_SOURCE_STYLE_SCHEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME, GtkSourceStyleSchemeClass))
+
+typedef struct _GtkSourceStyleSchemePrivate GtkSourceStyleSchemePrivate;
+typedef struct _GtkSourceStyleSchemeClass GtkSourceStyleSchemeClass;
+
+struct _GtkSourceStyleScheme
+{
+ GObject base;
+ GtkSourceStyleSchemePrivate *priv;
+};
+
+struct _GtkSourceStyleSchemeClass
+{
+ GObjectClass base_class;
+
+ /* Padding for future expansion */
+ gpointer padding[10];
+};
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceStyleScheme, gtk_source_style_scheme, GTK_SOURCE, STYLE_SCHEME, GObject)
+GType gtk_source_style_scheme_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_style_scheme_get_id (GtkSourceStyleScheme *scheme);
+const gchar *gtk_source_style_scheme_get_id (GtkSourceStyleScheme
*scheme);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_style_scheme_get_name (GtkSourceStyleScheme *scheme);
+const gchar *gtk_source_style_scheme_get_name (GtkSourceStyleScheme
*scheme);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_style_scheme_get_description (GtkSourceStyleScheme *scheme);
+const gchar *gtk_source_style_scheme_get_description (GtkSourceStyleScheme
*scheme);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const *gtk_source_style_scheme_get_authors (GtkSourceStyleScheme *scheme);
+const gchar * const * gtk_source_style_scheme_get_authors (GtkSourceStyleScheme
*scheme);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar *gtk_source_style_scheme_get_filename (GtkSourceStyleScheme *scheme);
+const gchar *gtk_source_style_scheme_get_filename (GtkSourceStyleScheme
*scheme);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyle *gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
- const gchar *style_id);
+GtkSourceStyle *gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
+ const gchar
*style_id);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestyleschemechooser.c b/gtksourceview/gtksourcestyleschemechooser.c
index 56de962d..8dea7355 100644
--- a/gtksourceview/gtksourcestyleschemechooser.c
+++ b/gtksourceview/gtksourcestyleschemechooser.c
@@ -18,7 +18,9 @@
* along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcestyleschemechooser.h"
#include "gtksourcestylescheme.h"
diff --git a/gtksourceview/gtksourcestyleschemechooser.h b/gtksourceview/gtksourcestyleschemechooser.h
index c0a67106..4723ed9d 100644
--- a/gtksourceview/gtksourcestyleschemechooser.h
+++ b/gtksourceview/gtksourcestyleschemechooser.h
@@ -30,29 +30,35 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER (gtk_source_style_scheme_chooser_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER (gtk_source_style_scheme_chooser_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER, GtkSourceStyleSchemeChooser))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER, GtkSourceStyleSchemeChooserInterface))
-GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_INTERFACE (GtkSourceStyleSchemeChooser, gtk_source_style_scheme_chooser, GTK_SOURCE,
STYLE_SCHEME_CHOOSER, GObject)
+typedef struct _GtkSourceStyleSchemeChooserInterface GtkSourceStyleSchemeChooserInterface;
struct _GtkSourceStyleSchemeChooserInterface
{
GTypeInterface base_interface;
/* Methods */
- GtkSourceStyleScheme *(*get_style_scheme) (GtkSourceStyleSchemeChooser *chooser);
+ GtkSourceStyleScheme * (* get_style_scheme) (GtkSourceStyleSchemeChooser *chooser);
- void (*set_style_scheme) (GtkSourceStyleSchemeChooser *chooser,
- GtkSourceStyleScheme *scheme);
+ void (* set_style_scheme) (GtkSourceStyleSchemeChooser *chooser,
+ GtkSourceStyleScheme *scheme);
- /*< private >*/
- gpointer _reserved[12];
+ /* Padding */
+ gpointer padding[12];
};
GTK_SOURCE_AVAILABLE_IN_3_16
-GtkSourceStyleScheme *gtk_source_style_scheme_chooser_get_style_scheme (GtkSourceStyleSchemeChooser
*chooser);
+GType gtk_source_style_scheme_chooser_get_type (void) G_GNUC_CONST;
+
+GTK_SOURCE_AVAILABLE_IN_3_16
+GtkSourceStyleScheme *gtk_source_style_scheme_chooser_get_style_scheme
(GtkSourceStyleSchemeChooser *chooser);
+
GTK_SOURCE_AVAILABLE_IN_3_16
-void gtk_source_style_scheme_chooser_set_style_scheme (GtkSourceStyleSchemeChooser *chooser,
- GtkSourceStyleScheme *scheme);
+void gtk_source_style_scheme_chooser_set_style_scheme
(GtkSourceStyleSchemeChooser *chooser,
+ GtkSourceStyleScheme
*scheme);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.c
b/gtksourceview/gtksourcestyleschemechooserbutton.c
index fb69c0cb..73e01491 100644
--- a/gtksourceview/gtksourcestyleschemechooserbutton.c
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.c
@@ -19,7 +19,9 @@
* along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <glib/gi18n-lib.h>
@@ -53,14 +55,16 @@ typedef struct
GtkSourceStyleSchemeChooserWidget *chooser;
} GtkSourceStyleSchemeChooserButtonPrivate;
-static void style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface);
+static void gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init
(GtkSourceStyleSchemeChooserInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserButton,
gtk_source_style_scheme_chooser_button,
GTK_TYPE_BUTTON,
G_ADD_PRIVATE (GtkSourceStyleSchemeChooserButton)
G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
- style_scheme_chooser_interface_init))
+
gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init))
+
+#define GET_PRIV(o) gtk_source_style_scheme_chooser_button_get_instance_private (o)
enum
{
@@ -72,7 +76,7 @@ static void
gtk_source_style_scheme_chooser_button_dispose (GObject *object)
{
GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (object);
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
g_clear_object (&priv->scheme);
@@ -131,7 +135,7 @@ dialog_destroy (GtkWidget *widget,
gpointer data)
{
GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (data);
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
priv->dialog = NULL;
priv->chooser = NULL;
@@ -151,7 +155,7 @@ dialog_response (GtkDialog *dialog,
else if (response == GTK_RESPONSE_OK)
{
GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (data);
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
GtkSourceStyleScheme *scheme;
scheme = gtk_source_style_scheme_chooser_get_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER
(priv->chooser));
@@ -167,7 +171,7 @@ dialog_response (GtkDialog *dialog,
static void
ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
{
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
GtkWidget *parent, *dialog, *scrolled_window;
GtkWidget *content_area;
@@ -176,7 +180,7 @@ ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
return;
}
- parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+ parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (button)));
/* TODO: have a ChooserDialog? */
priv->dialog = dialog = gtk_dialog_new_with_buttons (_("Select a Style"),
@@ -203,7 +207,7 @@ ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (priv->chooser));
- if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+ if (GTK_IS_ROOT (parent) && GTK_IS_WINDOW (parent))
{
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
{
@@ -224,7 +228,7 @@ static void
gtk_source_style_scheme_chooser_button_clicked (GtkButton *button)
{
GtkSourceStyleSchemeChooserButton *cbutton = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (button);
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (cbutton);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (cbutton);
ensure_dialog (cbutton);
@@ -259,7 +263,7 @@ static GtkSourceStyleScheme *
gtk_source_style_scheme_chooser_button_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
{
GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (chooser);
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
return priv->scheme;
}
@@ -267,7 +271,7 @@ gtk_source_style_scheme_chooser_button_get_style_scheme (GtkSourceStyleSchemeCho
static void
gtk_source_style_scheme_chooser_button_update_label (GtkSourceStyleSchemeChooserButton *button)
{
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
const gchar *label;
label = priv->scheme != NULL ? gtk_source_style_scheme_get_name (priv->scheme) : NULL;
@@ -279,7 +283,7 @@ gtk_source_style_scheme_chooser_button_set_style_scheme (GtkSourceStyleSchemeCho
GtkSourceStyleScheme *scheme)
{
GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (chooser);
- GtkSourceStyleSchemeChooserButtonPrivate *priv =
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+ GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
if (g_set_object (&priv->scheme, scheme))
{
@@ -290,7 +294,7 @@ gtk_source_style_scheme_chooser_button_set_style_scheme (GtkSourceStyleSchemeCho
}
static void
-style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface)
+gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init
(GtkSourceStyleSchemeChooserInterface *iface)
{
iface->get_style_scheme = gtk_source_style_scheme_chooser_button_get_style_scheme;
iface->set_style_scheme = gtk_source_style_scheme_chooser_button_set_style_scheme;
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.h
b/gtksourceview/gtksourcestyleschemechooserbutton.h
index 1615c5cb..dd472e05 100644
--- a/gtksourceview/gtksourcestyleschemechooserbutton.h
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.h
@@ -31,20 +31,32 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON (gtk_source_style_scheme_chooser_button_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON
(gtk_source_style_scheme_chooser_button_get_type())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButton))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButton const))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButtonClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButtonClass))
+
+typedef struct _GtkSourceStyleSchemeChooserButtonClass GtkSourceStyleSchemeChooserButtonClass;
+
+struct _GtkSourceStyleSchemeChooserButton
+{
+ GtkButton parent;
+};
struct _GtkSourceStyleSchemeChooserButtonClass
{
GtkButtonClass parent;
- /*< private >*/
- gpointer _reserved[10];
+ gpointer padding[10];
};
GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_DERIVABLE_TYPE (GtkSourceStyleSchemeChooserButton, gtk_source_style_scheme_chooser_button,
GTK_SOURCE, STYLE_SCHEME_CHOOSER_BUTTON, GtkButton)
+GType gtk_source_style_scheme_chooser_button_get_type (void);
GTK_SOURCE_AVAILABLE_IN_3_16
-GtkWidget *gtk_source_style_scheme_chooser_button_new (void);
+GtkWidget *gtk_source_style_scheme_chooser_button_new (void);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.c
b/gtksourceview/gtksourcestyleschemechooserwidget.c
index 68175b51..faca4137 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.c
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.c
@@ -19,7 +19,9 @@
* along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcestyleschemechooserwidget.h"
#include "gtksourcestyleschemechooser.h"
@@ -54,14 +56,16 @@ typedef struct
GtkSourceStyleScheme *scheme;
} GtkSourceStyleSchemeChooserWidgetPrivate;
-static void style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface);
+static void gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init
(GtkSourceStyleSchemeChooserInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserWidget,
gtk_source_style_scheme_chooser_widget,
GTK_TYPE_BIN,
G_ADD_PRIVATE (GtkSourceStyleSchemeChooserWidget)
G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
- style_scheme_chooser_interface_init))
+
gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init))
+
+#define GET_PRIV(o) gtk_source_style_scheme_chooser_widget_get_instance_private (o)
enum
{
@@ -73,7 +77,7 @@ static void
gtk_source_style_scheme_chooser_widget_dispose (GObject *object)
{
GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (object);
- GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
g_clear_object (&priv->scheme);
@@ -134,9 +138,10 @@ make_row (GtkSourceStyleScheme *scheme,
{
GtkWidget *row;
AtkObject *accessible;
- GtkWidget *event;
GtkSourceBuffer *buffer;
GtkWidget *view;
+ GtkWidget *overlay;
+ GtkWidget *label;
gchar *text;
row = gtk_list_box_row_new ();
@@ -147,11 +152,6 @@ make_row (GtkSourceStyleScheme *scheme,
g_object_set_data (G_OBJECT (row), "scheme", scheme);
- event = gtk_event_box_new ();
- gtk_event_box_set_above_child (GTK_EVENT_BOX (event), TRUE);
- gtk_widget_show (event);
- gtk_container_add (GTK_CONTAINER (row), event);
-
buffer = gtk_source_buffer_new_with_language (language);
gtk_source_buffer_set_highlight_matching_brackets (buffer, FALSE);
gtk_source_buffer_set_style_scheme (buffer, scheme);
@@ -161,18 +161,29 @@ make_row (GtkSourceStyleScheme *scheme,
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), text, -1);
g_free (text);
+ overlay = gtk_overlay_new ();
+ gtk_container_add (GTK_CONTAINER (row), overlay);
+ gtk_widget_show (overlay);
+
view = g_object_new (GTK_SOURCE_TYPE_VIEW,
"buffer", buffer,
"can-focus", FALSE,
"cursor-visible", FALSE,
"editable", FALSE,
"visible", TRUE,
- "show-line-numbers", TRUE,
"right-margin-position", 30,
"show-right-margin", TRUE,
"margin", 2,
NULL);
- gtk_container_add (GTK_CONTAINER (event), view);
+ gtk_container_add (GTK_CONTAINER (overlay), view);
+
+ label = g_object_new (GTK_TYPE_LABEL,
+ "can-focus", FALSE,
+ "expand", TRUE,
+ "selectable", FALSE,
+ "visible", TRUE,
+ NULL);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
return row;
}
@@ -182,7 +193,7 @@ on_row_selected (GtkListBox *list_box,
GtkListBoxRow *row,
GtkSourceStyleSchemeChooserWidget *widget)
{
- GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
if (row != NULL)
{
@@ -199,7 +210,7 @@ on_row_selected (GtkListBox *list_box,
static void
destroy_child_cb (GtkWidget *widget,
- gpointer data)
+ gpointer data)
{
gtk_widget_destroy (widget);
}
@@ -207,7 +218,7 @@ destroy_child_cb (GtkWidget *widget,
static void
gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidget *widget)
{
- GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
GtkSourceLanguageManager *lm;
GtkSourceLanguage *lang;
GtkSourceStyleSchemeManager *manager;
@@ -265,7 +276,7 @@ on_scheme_ids_changed (GtkSourceStyleSchemeManager *manager,
static void
gtk_source_style_scheme_chooser_widget_init (GtkSourceStyleSchemeChooserWidget *widget)
{
- GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
GtkSourceStyleSchemeManager *manager;
priv->list_box = GTK_LIST_BOX (gtk_list_box_new ());
@@ -294,7 +305,7 @@ static GtkSourceStyleScheme *
gtk_source_style_scheme_chooser_widget_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
{
GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (chooser);
- GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
return priv->scheme;
}
@@ -304,7 +315,7 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
GtkSourceStyleScheme *scheme)
{
GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (chooser);
- GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+ GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
if (g_set_object (&priv->scheme, scheme))
{
@@ -336,7 +347,7 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
}
static void
-style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface)
+gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init
(GtkSourceStyleSchemeChooserInterface *iface)
{
iface->get_style_scheme = gtk_source_style_scheme_chooser_widget_get_style_scheme;
iface->set_style_scheme = gtk_source_style_scheme_chooser_widget_set_style_scheme;
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.h
b/gtksourceview/gtksourcestyleschemechooserwidget.h
index ceb9320b..1177d74b 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.h
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.h
@@ -26,24 +26,37 @@
#endif
#include <gtk/gtk.h>
-#include <gtksourceview/gtksourcetypes.h>
+
+#include "gtksourcetypes.h"
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET (gtk_source_style_scheme_chooser_widget_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET
(gtk_source_style_scheme_chooser_widget_get_type())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidget))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidget const))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidgetClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidgetClass))
+
+typedef struct _GtkSourceStyleSchemeChooserWidgetClass GtkSourceStyleSchemeChooserWidgetClass;
+
+struct _GtkSourceStyleSchemeChooserWidget
+{
+ GtkBin parent;
+};
struct _GtkSourceStyleSchemeChooserWidgetClass
{
GtkBinClass parent;
- /*< private >*/
- gpointer _reserved[10];
+ gpointer padding[10];
};
GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_DERIVABLE_TYPE (GtkSourceStyleSchemeChooserWidget, gtk_source_style_scheme_chooser_widget,
GTK_SOURCE, STYLE_SCHEME_CHOOSER_WIDGET, GtkBin)
+GType gtk_source_style_scheme_chooser_widget_get_type (void);
GTK_SOURCE_AVAILABLE_IN_3_16
-GtkWidget *gtk_source_style_scheme_chooser_widget_new (void);
+GtkWidget *gtk_source_style_scheme_chooser_widget_new (void);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestyleschememanager-private.h
b/gtksourceview/gtksourcestyleschememanager-private.h
index 7efc716d..38eb0da4 100644
--- a/gtksourceview/gtksourcestyleschememanager-private.h
+++ b/gtksourceview/gtksourcestyleschememanager-private.h
@@ -20,6 +20,7 @@
#pragma once
+#include "gtksourcetypes.h"
#include "gtksourcestyleschememanager.h"
G_BEGIN_DECLS
diff --git a/gtksourceview/gtksourcestyleschememanager.c b/gtksourceview/gtksourcestyleschememanager.c
index d609d3f5..cff0e9ee 100644
--- a/gtksourceview/gtksourcestyleschememanager.c
+++ b/gtksourceview/gtksourcestyleschememanager.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <string.h>
@@ -35,13 +37,11 @@
* Object which provides access to #GtkSourceStyleScheme<!-- -->s.
*/
-#define SCHEME_FILE_SUFFIX ".xml"
-#define STYLES_DIR "styles"
+#define SCHEME_FILE_SUFFIX ".xml"
+#define STYLES_DIR "styles"
-struct _GtkSourceStyleSchemeManager
+struct _GtkSourceStyleSchemeManagerPrivate
{
- GObject parent_instance;
-
GHashTable *schemes_hash;
gchar **search_path;
@@ -58,13 +58,13 @@ enum {
static GtkSourceStyleSchemeManager *default_instance;
-G_DEFINE_TYPE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, G_TYPE_OBJECT)
static void
-gtk_source_style_scheme_manager_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+gtk_source_style_scheme_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceStyleSchemeManager *sm;
@@ -87,9 +87,9 @@ gtk_source_style_scheme_manager_set_property (GObject *object,
static void
gtk_source_style_scheme_manager_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceStyleSchemeManager *sm;
@@ -118,14 +118,14 @@ gtk_source_style_scheme_manager_get_property (GObject *object,
static void
free_schemes (GtkSourceStyleSchemeManager *mgr)
{
- if (mgr->schemes_hash != NULL)
+ if (mgr->priv->schemes_hash != NULL)
{
- g_hash_table_destroy (mgr->schemes_hash);
- mgr->schemes_hash = NULL;
+ g_hash_table_destroy (mgr->priv->schemes_hash);
+ mgr->priv->schemes_hash = NULL;
}
- g_strfreev (mgr->ids);
- mgr->ids = NULL;
+ g_strfreev (mgr->priv->ids);
+ mgr->priv->ids = NULL;
}
static void
@@ -137,7 +137,7 @@ gtk_source_style_scheme_manager_finalize (GObject *object)
free_schemes (mgr);
- g_strfreev (mgr->search_path);
+ g_strfreev (mgr->priv->search_path);
G_OBJECT_CLASS (gtk_source_style_scheme_manager_parent_class)->finalize (object);
}
@@ -171,11 +171,11 @@ gtk_source_style_scheme_manager_class_init (GtkSourceStyleSchemeManagerClass *kl
static void
gtk_source_style_scheme_manager_init (GtkSourceStyleSchemeManager *mgr)
{
- mgr = gtk_source_style_scheme_manager_get_instance_private (mgr);
- mgr->schemes_hash = NULL;
- mgr->ids = NULL;
- mgr->search_path = NULL;
- mgr->need_reload = TRUE;
+ mgr->priv = gtk_source_style_scheme_manager_get_instance_private (mgr);
+ mgr->priv->schemes_hash = NULL;
+ mgr->priv->ids = NULL;
+ mgr->priv->search_path = NULL;
+ mgr->priv->need_reload = TRUE;
}
/**
@@ -220,9 +220,9 @@ _gtk_source_style_scheme_manager_peek_default (void)
}
static gboolean
-build_reference_chain (GtkSourceStyleScheme *scheme,
- GHashTable *hash,
- GSList **ret)
+build_reference_chain (GtkSourceStyleScheme *scheme,
+ GHashTable *hash,
+ GSList **ret)
{
GSList *chain;
gboolean retval = TRUE;
@@ -268,8 +268,7 @@ build_reference_chain (GtkSourceStyleScheme *scheme,
}
static GSList *
-check_parents (GSList *schemes,
- GHashTable *hash)
+check_parents (GSList *schemes, GHashTable *hash)
{
GSList *to_check;
@@ -306,8 +305,7 @@ check_parents (GSList *schemes,
}
static gint
-schemes_compare (GtkSourceStyleScheme *scheme1,
- GtkSourceStyleScheme *scheme2)
+schemes_compare (GtkSourceStyleScheme *scheme1, GtkSourceStyleScheme *scheme2)
{
const gchar *name1;
const gchar *name2;
@@ -346,7 +344,7 @@ reload_if_needed (GtkSourceStyleSchemeManager *mgr)
GSList *l;
GHashTable *schemes_hash;
- if (!mgr->need_reload)
+ if (!mgr->priv->need_reload)
return;
schemes_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
@@ -389,17 +387,17 @@ reload_if_needed (GtkSourceStyleSchemeManager *mgr)
free_schemes (mgr);
- mgr->need_reload = FALSE;
- mgr->schemes_hash = schemes_hash;
+ mgr->priv->need_reload = FALSE;
+ mgr->priv->schemes_hash = schemes_hash;
- mgr->ids = schemes_list_to_ids (schemes);
+ mgr->priv->ids = schemes_list_to_ids (schemes);
g_slist_free (schemes);
}
static void
notify_search_path (GtkSourceStyleSchemeManager *mgr)
{
- mgr->need_reload = TRUE;
+ mgr->priv->need_reload = TRUE;
g_object_notify (G_OBJECT (mgr), "search-path");
g_object_notify (G_OBJECT (mgr), "scheme-ids");
@@ -417,18 +415,18 @@ notify_search_path (GtkSourceStyleSchemeManager *mgr)
*/
void
gtk_source_style_scheme_manager_set_search_path (GtkSourceStyleSchemeManager *manager,
- gchar **path)
+ gchar **path)
{
gchar **tmp;
g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
- tmp = manager->search_path;
+ tmp = manager->priv->search_path;
if (path == NULL)
- manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+ manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
else
- manager->search_path = g_strdupv (path);
+ manager->priv->search_path = g_strdupv (path);
g_strfreev (tmp);
@@ -446,26 +444,26 @@ gtk_source_style_scheme_manager_set_search_path (GtkSourceStyleSchemeManager *m
*/
void
gtk_source_style_scheme_manager_append_search_path (GtkSourceStyleSchemeManager *manager,
- const gchar *path)
+ const gchar *path)
{
guint len = 0;
g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
g_return_if_fail (path != NULL);
- if (manager->search_path == NULL)
- manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+ if (manager->priv->search_path == NULL)
+ manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
- g_return_if_fail (manager->search_path != NULL);
+ g_return_if_fail (manager->priv->search_path != NULL);
- len = g_strv_length (manager->search_path);
+ len = g_strv_length (manager->priv->search_path);
- manager->search_path = g_renew (gchar *,
- manager->search_path,
+ manager->priv->search_path = g_renew (gchar *,
+ manager->priv->search_path,
len + 2); /* old path + new entry + NULL */
- manager->search_path[len] = g_strdup (path);
- manager->search_path[len + 1] = NULL;
+ manager->priv->search_path[len] = g_strdup (path);
+ manager->priv->search_path[len + 1] = NULL;
notify_search_path (manager);
}
@@ -481,7 +479,7 @@ gtk_source_style_scheme_manager_append_search_path (GtkSourceStyleSchemeManager
*/
void
gtk_source_style_scheme_manager_prepend_search_path (GtkSourceStyleSchemeManager *manager,
- const gchar *path)
+ const gchar *path)
{
guint len = 0;
gchar **new_search_path;
@@ -489,19 +487,19 @@ gtk_source_style_scheme_manager_prepend_search_path (GtkSourceStyleSchemeManager
g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
g_return_if_fail (path != NULL);
- if (manager->search_path == NULL)
- manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+ if (manager->priv->search_path == NULL)
+ manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
- g_return_if_fail (manager->search_path != NULL);
+ g_return_if_fail (manager->priv->search_path != NULL);
- len = g_strv_length (manager->search_path);
+ len = g_strv_length (manager->priv->search_path);
new_search_path = g_new (gchar *, len + 2);
new_search_path[0] = g_strdup (path);
- memcpy (new_search_path + 1, manager->search_path, (len + 1) * sizeof (gchar*));
+ memcpy (new_search_path + 1, manager->priv->search_path, (len + 1) * sizeof (gchar*));
- g_free (manager->search_path);
- manager->search_path = new_search_path;
+ g_free (manager->priv->search_path);
+ manager->priv->search_path = new_search_path;
notify_search_path (manager);
}
@@ -522,10 +520,10 @@ gtk_source_style_scheme_manager_get_search_path (GtkSourceStyleSchemeManager *ma
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL);
- if (manager->search_path == NULL)
- manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+ if (manager->priv->search_path == NULL)
+ manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
- return (const gchar * const *)manager->search_path;
+ return (const gchar * const *)manager->priv->search_path;
}
/**
@@ -541,7 +539,7 @@ gtk_source_style_scheme_manager_force_rescan (GtkSourceStyleSchemeManager *manag
{
g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
- manager->need_reload = TRUE;
+ manager->priv->need_reload = TRUE;
g_object_notify (G_OBJECT (manager), "scheme-ids");
}
@@ -565,7 +563,7 @@ gtk_source_style_scheme_manager_get_scheme_ids (GtkSourceStyleSchemeManager *man
reload_if_needed (manager);
- return (const gchar * const *)manager->ids;
+ return (const gchar * const *)manager->priv->ids;
}
/**
@@ -580,12 +578,12 @@ gtk_source_style_scheme_manager_get_scheme_ids (GtkSourceStyleSchemeManager *man
*/
GtkSourceStyleScheme *
gtk_source_style_scheme_manager_get_scheme (GtkSourceStyleSchemeManager *manager,
- const gchar *scheme_id)
+ const gchar *scheme_id)
{
g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL);
g_return_val_if_fail (scheme_id != NULL, NULL);
reload_if_needed (manager);
- return g_hash_table_lookup (manager->schemes_hash, scheme_id);
+ return g_hash_table_lookup (manager->priv->schemes_hash, scheme_id);
}
diff --git a/gtksourceview/gtksourcestyleschememanager.h b/gtksourceview/gtksourcestyleschememanager.h
index 3335cf60..fcaee9d1 100644
--- a/gtksourceview/gtksourcestyleschememanager.h
+++ b/gtksourceview/gtksourcestyleschememanager.h
@@ -30,32 +30,65 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER (gtk_source_style_scheme_manager_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER (gtk_source_style_scheme_manager_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER, GtkSourceStyleSchemeManager))
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER, GtkSourceStyleSchemeManagerClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER))
+#define GTK_SOURCE_IS_STYLE_SCHEME_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER))
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER, GtkSourceStyleSchemeManagerClass))
+
+typedef struct _GtkSourceStyleSchemeManagerClass GtkSourceStyleSchemeManagerClass;
+typedef struct _GtkSourceStyleSchemeManagerPrivate GtkSourceStyleSchemeManagerPrivate;
+
+struct _GtkSourceStyleSchemeManager
+{
+ GObject parent;
+
+ GtkSourceStyleSchemeManagerPrivate *priv;
+};
+
+struct _GtkSourceStyleSchemeManagerClass
+{
+ GObjectClass parent_class;
+
+ /* Padding for future expansion */
+ gpointer padding[10];
+};
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, GTK_SOURCE,
STYLE_SCHEME_MANAGER, GObject)
+GType gtk_source_style_scheme_manager_get_type (void) G_GNUC_CONST;
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleSchemeManager *gtk_source_style_scheme_manager_new (void);
+GtkSourceStyleSchemeManager *
+ gtk_source_style_scheme_manager_new (void);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleSchemeManager *gtk_source_style_scheme_manager_get_default (void);
+GtkSourceStyleSchemeManager *
+ gtk_source_style_scheme_manager_get_default (void);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_style_scheme_manager_set_search_path
(GtkSourceStyleSchemeManager *manager,
- gchar
**path);
+void gtk_source_style_scheme_manager_set_search_path (GtkSourceStyleSchemeManager
*manager,
+ gchar
**path);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_style_scheme_manager_append_search_path
(GtkSourceStyleSchemeManager *manager,
- const gchar
*path);
+void gtk_source_style_scheme_manager_append_search_path (GtkSourceStyleSchemeManager
*manager,
+ const gchar
*path);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_style_scheme_manager_prepend_search_path
(GtkSourceStyleSchemeManager *manager,
- const gchar
*path);
+void gtk_source_style_scheme_manager_prepend_search_path (GtkSourceStyleSchemeManager
*manager,
+ const gchar
*path);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const *gtk_source_style_scheme_manager_get_search_path
(GtkSourceStyleSchemeManager *manager);
+const gchar * const * gtk_source_style_scheme_manager_get_search_path (GtkSourceStyleSchemeManager
*manager);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_style_scheme_manager_force_rescan
(GtkSourceStyleSchemeManager *manager);
+void gtk_source_style_scheme_manager_force_rescan (GtkSourceStyleSchemeManager
*manager);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const *gtk_source_style_scheme_manager_get_scheme_ids
(GtkSourceStyleSchemeManager *manager);
+const gchar * const * gtk_source_style_scheme_manager_get_scheme_ids (GtkSourceStyleSchemeManager
*manager);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleScheme *gtk_source_style_scheme_manager_get_scheme
(GtkSourceStyleSchemeManager *manager,
- const gchar
*scheme_id);
+GtkSourceStyleScheme *gtk_source_style_scheme_manager_get_scheme (GtkSourceStyleSchemeManager
*manager,
+ const gchar
*scheme_id);
G_END_DECLS
diff --git a/gtksourceview/gtksourcetag.c b/gtksourceview/gtksourcetag.c
index ad007e4c..2970e5ae 100644
--- a/gtksourceview/gtksourcetag.c
+++ b/gtksourceview/gtksourcetag.c
@@ -20,7 +20,9 @@
* Author: Sébastien Wilmet
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourcetag.h"
@@ -37,11 +39,13 @@
* a #GtkTextTag, not a #GtkSourceTag.
*/
-typedef struct
+typedef struct _GtkSourceTagPrivate GtkSourceTagPrivate;
+
+struct _GtkSourceTagPrivate
{
guint draw_spaces : 1;
guint draw_spaces_set : 1;
-} GtkSourceTagPrivate;
+};
enum
{
@@ -54,9 +58,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceTag, gtk_source_tag, GTK_TYPE_TEXT_TAG)
static void
gtk_source_tag_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceTagPrivate *priv;
@@ -80,9 +84,9 @@ gtk_source_tag_get_property (GObject *object,
static void
gtk_source_tag_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceTag *tag;
GtkSourceTagPrivate *priv;
diff --git a/gtksourceview/gtksourcetag.h b/gtksourceview/gtksourcetag.h
index 9141b7bf..48108ed1 100644
--- a/gtksourceview/gtksourcetag.h
+++ b/gtksourceview/gtksourcetag.h
@@ -32,20 +32,22 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_TAG (gtk_source_tag_get_type())
+#define GTK_SOURCE_TYPE_TAG (gtk_source_tag_get_type ())
GTK_SOURCE_AVAILABLE_IN_3_20
-G_DECLARE_DERIVABLE_TYPE (GtkSourceTag, gtk_source_tag, GTK_SOURCE, TAG, GtkTextTag)
+G_DECLARE_DERIVABLE_TYPE (GtkSourceTag, gtk_source_tag,
+ GTK_SOURCE, TAG,
+ GtkTextTag)
struct _GtkSourceTagClass
{
GtkTextTagClass parent_class;
- /*< private >*/
+ /*< private >*/
gpointer _reserved[10];
};
GTK_SOURCE_AVAILABLE_IN_3_20
-GtkTextTag *gtk_source_tag_new (const gchar *name);
+GtkTextTag * gtk_source_tag_new (const gchar *name);
G_END_DECLS
diff --git a/gtksourceview/gtksourcetypes-private.h b/gtksourceview/gtksourcetypes-private.h
index 002a144d..44b56b04 100644
--- a/gtksourceview/gtksourcetypes-private.h
+++ b/gtksourceview/gtksourcetypes-private.h
@@ -23,18 +23,16 @@
G_BEGIN_DECLS
-typedef struct _GtkSourceBufferInputStream GtkSourceBufferInputStream;
-typedef struct _GtkSourceBufferOutputStream GtkSourceBufferOutputStream;
-typedef struct _GtkSourceCompletionContainer GtkSourceCompletionContainer;
-typedef struct _GtkSourceCompletionModel GtkSourceCompletionModel;
-typedef struct _GtkSourceContextEngine GtkSourceContextEngine;
-typedef struct _GtkSourceEngine GtkSourceEngine;
-typedef struct _GtkSourceGutterRendererLines GtkSourceGutterRendererLines;
-typedef struct _GtkSourceGutterRendererMarks GtkSourceGutterRendererMarks;
-typedef struct _GtkSourceMarksSequence GtkSourceMarksSequence;
-typedef struct _GtkSourcePixbufHelper GtkSourcePixbufHelper;
-typedef struct _GtkSourceRegex GtkSourceRegex;
-typedef struct _GtkSourceUndoManagerDefault GtkSourceUndoManagerDefault;
+typedef struct _GtkSourceBufferInputStream GtkSourceBufferInputStream;
+typedef struct _GtkSourceBufferOutputStream GtkSourceBufferOutputStream;
+typedef struct _GtkSourceCompletionModel GtkSourceCompletionModel;
+typedef struct _GtkSourceContextEngine GtkSourceContextEngine;
+typedef struct _GtkSourceEngine GtkSourceEngine;
+typedef struct _GtkSourceGutterRendererLines GtkSourceGutterRendererLines;
+typedef struct _GtkSourceGutterRendererMarks GtkSourceGutterRendererMarks;
+typedef struct _GtkSourceMarksSequence GtkSourceMarksSequence;
+typedef struct _GtkSourcePixbufHelper GtkSourcePixbufHelper;
+typedef struct _GtkSourceRegex GtkSourceRegex;
#ifdef _MSC_VER
/* For Visual Studio, we need to export the symbols used by the unit tests */
diff --git a/gtksourceview/gtksourcetypes.h b/gtksourceview/gtksourcetypes.h
index ae358abc..71fb3381 100644
--- a/gtksourceview/gtksourcetypes.h
+++ b/gtksourceview/gtksourcetypes.h
@@ -35,37 +35,37 @@ G_BEGIN_DECLS
* https://bugzilla.gnome.org/show_bug.cgi?id=679424#c20
*/
-typedef struct _GtkSourceBuffer GtkSourceBuffer;
-typedef struct _GtkSourceCompletionContext GtkSourceCompletionContext;
-typedef struct _GtkSourceCompletion GtkSourceCompletion;
-typedef struct _GtkSourceCompletionInfo GtkSourceCompletionInfo;
-typedef struct _GtkSourceCompletionItem GtkSourceCompletionItem;
-typedef struct _GtkSourceCompletionProposal GtkSourceCompletionProposal;
-typedef struct _GtkSourceCompletionProvider GtkSourceCompletionProvider;
-typedef struct _GtkSourceEncoding GtkSourceEncoding;
-typedef struct _GtkSourceFile GtkSourceFile;
-typedef struct _GtkSourceFileLoader GtkSourceFileLoader;
-typedef struct _GtkSourceFileSaver GtkSourceFileSaver;
-typedef struct _GtkSourceGutter GtkSourceGutter;
-typedef struct _GtkSourceGutterRenderer GtkSourceGutterRenderer;
-typedef struct _GtkSourceGutterRendererPixbuf GtkSourceGutterRendererPixbuf;
-typedef struct _GtkSourceGutterRendererText GtkSourceGutterRendererText;
-typedef struct _GtkSourceLanguage GtkSourceLanguage;
-typedef struct _GtkSourceLanguageManager GtkSourceLanguageManager;
-typedef struct _GtkSourceMap GtkSourceMap;
-typedef struct _GtkSourceMarkAttributes GtkSourceMarkAttributes;
-typedef struct _GtkSourceMark GtkSourceMark;
-typedef struct _GtkSourcePrintCompositor GtkSourcePrintCompositor;
-typedef struct _GtkSourceSearchContext GtkSourceSearchContext;
-typedef struct _GtkSourceSearchSettings GtkSourceSearchSettings;
-typedef struct _GtkSourceSpaceDrawer GtkSourceSpaceDrawer;
-typedef struct _GtkSourceStyle GtkSourceStyle;
-typedef struct _GtkSourceStyleSchemeChooserButton GtkSourceStyleSchemeChooserButton;
-typedef struct _GtkSourceStyleSchemeChooser GtkSourceStyleSchemeChooser;
-typedef struct _GtkSourceStyleSchemeChooserWidget GtkSourceStyleSchemeChooserWidget;
-typedef struct _GtkSourceStyleScheme GtkSourceStyleScheme;
-typedef struct _GtkSourceStyleSchemeManager GtkSourceStyleSchemeManager;
-typedef struct _GtkSourceUndoManager GtkSourceUndoManager;
-typedef struct _GtkSourceView GtkSourceView;
+typedef struct _GtkSourceBuffer GtkSourceBuffer;
+typedef struct _GtkSourceCompletionContext GtkSourceCompletionContext;
+typedef struct _GtkSourceCompletion GtkSourceCompletion;
+typedef struct _GtkSourceCompletionInfo GtkSourceCompletionInfo;
+typedef struct _GtkSourceCompletionItem GtkSourceCompletionItem;
+typedef struct _GtkSourceCompletionProposal GtkSourceCompletionProposal;
+typedef struct _GtkSourceCompletionProvider GtkSourceCompletionProvider;
+typedef struct _GtkSourceEncoding GtkSourceEncoding;
+typedef struct _GtkSourceFile GtkSourceFile;
+typedef struct _GtkSourceFileLoader GtkSourceFileLoader;
+typedef struct _GtkSourceFileSaver GtkSourceFileSaver;
+typedef struct _GtkSourceGutter GtkSourceGutter;
+typedef struct _GtkSourceGutterRenderer GtkSourceGutterRenderer;
+typedef struct _GtkSourceGutterRendererPixbuf GtkSourceGutterRendererPixbuf;
+typedef struct _GtkSourceGutterRendererText GtkSourceGutterRendererText;
+typedef struct _GtkSourceLanguage GtkSourceLanguage;
+typedef struct _GtkSourceLanguageManager GtkSourceLanguageManager;
+typedef struct _GtkSourceLines GtkSourceLines;
+typedef struct _GtkSourceMap GtkSourceMap;
+typedef struct _GtkSourceMarkAttributes GtkSourceMarkAttributes;
+typedef struct _GtkSourceMark GtkSourceMark;
+typedef struct _GtkSourcePrintCompositor GtkSourcePrintCompositor;
+typedef struct _GtkSourceSearchContext GtkSourceSearchContext;
+typedef struct _GtkSourceSearchSettings GtkSourceSearchSettings;
+typedef struct _GtkSourceSpaceDrawer GtkSourceSpaceDrawer;
+typedef struct _GtkSourceStyle GtkSourceStyle;
+typedef struct _GtkSourceStyleScheme GtkSourceStyleScheme;
+typedef struct _GtkSourceStyleSchemeChooser GtkSourceStyleSchemeChooser;
+typedef struct _GtkSourceStyleSchemeChooserButton GtkSourceStyleSchemeChooserButton;
+typedef struct _GtkSourceStyleSchemeChooserWidget GtkSourceStyleSchemeChooserWidget;
+typedef struct _GtkSourceStyleSchemeManager GtkSourceStyleSchemeManager;
+typedef struct _GtkSourceView GtkSourceView;
G_END_DECLS
diff --git a/gtksourceview/gtksourceutils-private.h b/gtksourceview/gtksourceutils-private.h
index 25dd7b03..28c08a34 100644
--- a/gtksourceview/gtksourceutils-private.h
+++ b/gtksourceview/gtksourceutils-private.h
@@ -28,22 +28,26 @@
G_BEGIN_DECLS
G_GNUC_INTERNAL
-gchar **_gtk_source_utils_get_default_dirs (const gchar *basename);
+gchar ** _gtk_source_utils_get_default_dirs (const gchar *basename);
+
G_GNUC_INTERNAL
-GSList *_gtk_source_utils_get_file_list (gchar **path,
- const gchar *suffix,
- gboolean only_dirs);
+GSList * _gtk_source_utils_get_file_list (gchar **path,
+ const gchar *suffix,
+ gboolean only_dirs);
+
G_GNUC_INTERNAL
-gint _gtk_source_utils_string_to_int (const gchar *str);
+gint _gtk_source_utils_string_to_int (const gchar *str);
+
G_GNUC_INTERNAL
-gint _gtk_source_utils_int_to_string (guint value,
- const gchar **outstr);
+gint _gtk_source_utils_int_to_string (guint value,
+ const gchar **outstr);
+
G_GNUC_INTERNAL
-gchar *_gtk_source_utils_pango_font_description_to_css (const PangoFontDescription *font_desc);
+gchar * _gtk_source_utils_pango_font_description_to_css (const PangoFontDescription
*font_desc);
/* Note: it returns duplicated string. */
G_GNUC_INTERNAL
-gchar *_gtk_source_utils_dgettext (const gchar *domain,
- const gchar *msgid)
G_GNUC_FORMAT(2);
+gchar * _gtk_source_utils_dgettext (const gchar *domain,
+ const gchar *msgid) G_GNUC_FORMAT(2);
G_END_DECLS
diff --git a/gtksourceview/gtksourceutils.c b/gtksourceview/gtksourceutils.c
index 9024c667..7aa79d2f 100644
--- a/gtksourceview/gtksourceutils.c
+++ b/gtksourceview/gtksourceutils.c
@@ -29,7 +29,9 @@
* Utility functions.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourceutils.h"
#include "gtksourceutils-private.h"
diff --git a/gtksourceview/gtksourceutils.h b/gtksourceview/gtksourceutils.h
index 2f4faf9e..4ea2f89c 100644
--- a/gtksourceview/gtksourceutils.h
+++ b/gtksourceview/gtksourceutils.h
@@ -31,8 +31,9 @@
G_BEGIN_DECLS
GTK_SOURCE_AVAILABLE_IN_3_10
-gchar *gtk_source_utils_unescape_search_text (const gchar *text);
+gchar *gtk_source_utils_unescape_search_text (const gchar *text);
+
GTK_SOURCE_AVAILABLE_IN_3_10
-gchar *gtk_source_utils_escape_search_text (const gchar *text);
+gchar *gtk_source_utils_escape_search_text (const gchar *text);
G_END_DECLS
diff --git a/gtksourceview/gtksourceversion.c b/gtksourceview/gtksourceversion.c
index f6927492..6aea3c8f 100644
--- a/gtksourceview/gtksourceversion.c
+++ b/gtksourceview/gtksourceversion.c
@@ -18,7 +18,9 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourceversion.h"
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index afa014c6..19d3f369 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -21,11 +21,13 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include "gtksourceview.h"
-#include <string.h> /* For strlen */
+#include <string.h>
#include <fribidi.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@@ -35,19 +37,18 @@
#include "gtksourcebuffer.h"
#include "gtksourcebuffer-private.h"
#include "gtksourcebufferinternal-private.h"
+#include "gtksourcecompletion.h"
+#include "gtksourcegutter.h"
+#include "gtksourcegutter-private.h"
+#include "gtksourcegutterrendererlines.h"
#include "gtksource-enumtypes.h"
#include "gtksourcemark.h"
#include "gtksourcemarkattributes.h"
#include "gtksource-marshal.h"
#include "gtksourcestylescheme-private.h"
-#include "gtksourcecompletion.h"
#include "gtksourcecompletion-private.h"
#include "gtksourcecompletionprovider.h"
-#include "gtksourcegutter.h"
-#include "gtksourcegutter-private.h"
-#include "gtksourcegutterrendererlines-private.h"
-#include "gtksourcegutterrenderermarks-private.h"
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
#include "gtksourcesearchcontext-private.h"
#include "gtksourcespacedrawer.h"
#include "gtksourcespacedrawer-private.h"
@@ -137,23 +138,22 @@
#define PROFILE(x)
#endif
-#define GUTTER_PIXMAP 16
-#define DEFAULT_TAB_WIDTH 8
-#define MAX_TAB_WIDTH 32
-#define MAX_INDENT_WIDTH 32
+#define GUTTER_PIXMAP 16
+#define DEFAULT_TAB_WIDTH 8
+#define MAX_TAB_WIDTH 32
+#define MAX_INDENT_WIDTH 32
-#define DEFAULT_RIGHT_MARGIN_POSITION 80
-#define MAX_RIGHT_MARGIN_POSITION 1000
+#define DEFAULT_RIGHT_MARGIN_POSITION 80
+#define MAX_RIGHT_MARGIN_POSITION 1000
-#define RIGHT_MARGIN_LINE_ALPHA 40
-#define RIGHT_MARGIN_OVERLAY_ALPHA 15
+#define RIGHT_MARGIN_LINE_ALPHA 40
+#define RIGHT_MARGIN_OVERLAY_ALPHA 15
enum
{
UNDO,
REDO,
SHOW_COMPLETION,
- LINE_MARK_ACTIVATED,
MOVE_LINES,
MOVE_WORDS,
SMART_HOME_END,
@@ -169,7 +169,6 @@ enum
PROP_0,
PROP_COMPLETION,
PROP_SHOW_LINE_NUMBERS,
- PROP_SHOW_LINE_MARKS,
PROP_TAB_WIDTH,
PROP_INDENT_WIDTH,
PROP_AUTO_INDENT,
@@ -184,7 +183,7 @@ enum
PROP_SPACE_DRAWER
};
-typedef struct
+struct _GtkSourceViewPrivate
{
GtkSourceStyleScheme *style_scheme;
GdkRGBA *right_margin_line_color;
@@ -200,7 +199,6 @@ typedef struct
GtkSourceGutter *right_gutter;
GtkSourceGutterRenderer *line_renderer;
- GtkSourceGutterRenderer *marks_renderer;
GdkRGBA current_line_color;
@@ -216,7 +214,6 @@ typedef struct
guint tabs_set : 1;
guint show_line_numbers : 1;
- guint show_line_marks : 1;
guint auto_indent : 1;
guint insert_spaces : 1;
guint highlight_current_line : 1;
@@ -225,13 +222,15 @@ typedef struct
guint current_line_color_set : 1;
guint background_pattern_color_set : 1;
guint smart_backspace : 1;
-} GtkSourceViewPrivate;
+};
+
+typedef struct _MarkCategory MarkCategory;
-typedef struct
+struct _MarkCategory
{
GtkSourceMarkAttributes *attributes;
gint priority;
-} MarkCategory;
+};
static guint signals[N_SIGNALS];
@@ -247,75 +246,73 @@ typedef enum _GtkSourceViewDropTypes {
TARGET_COLOR = 200
} GtkSourceViewDropTypes;
+#if 0
static const GtkTargetEntry drop_types[] = {
{(gchar *)"application/x-color", 0, TARGET_COLOR}
};
+#endif
-static void gtk_source_view_dispose (GObject *object);
-static void gtk_source_view_finalize (GObject *object);
-static void gtk_source_view_undo (GtkSourceView *view);
-static void gtk_source_view_redo (GtkSourceView *view);
-static void gtk_source_view_show_completion_real (GtkSourceView *view);
-static GtkTextBuffer *gtk_source_view_create_buffer (GtkTextView *view);
-static void remove_source_buffer (GtkSourceView *view);
-static void set_source_buffer (GtkSourceView *view,
- GtkTextBuffer *buffer);
-static void gtk_source_view_populate_popup (GtkTextView *view,
- GtkWidget *popup);
-static void gtk_source_view_move_cursor (GtkTextView *text_view,
- GtkMovementStep step,
- gint count,
- gboolean extend_selection);
-static void gtk_source_view_delete_from_cursor (GtkTextView *text_view,
- GtkDeleteType type,
- gint count);
-static gboolean gtk_source_view_extend_selection (GtkTextView *text_view,
- GtkTextExtendSelection granularity,
- const GtkTextIter *location,
- GtkTextIter *start,
- GtkTextIter *end);
-static void gtk_source_view_get_lines (GtkTextView *text_view,
- gint first_y,
- gint last_y,
- GArray *buffer_coords,
- GArray *line_heights,
- GArray *numbers,
- gint *countp);
-static gboolean gtk_source_view_draw (GtkWidget *widget,
- cairo_t *cr);
-static void gtk_source_view_move_lines (GtkSourceView *view,
- gboolean down);
-static void gtk_source_view_move_words (GtkSourceView *view,
- gint step);
-static gboolean gtk_source_view_key_press_event (GtkWidget *widget,
- GdkEventKey *event);
-static void view_dnd_drop (GtkTextView *view,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *selection_data,
- guint info,
- guint timestamp,
- gpointer data);
-static gint calculate_real_tab_width (GtkSourceView *view,
- guint tab_size,
- gchar c);
-static void gtk_source_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_source_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void gtk_source_view_style_updated (GtkWidget *widget);
-static void gtk_source_view_update_style_scheme (GtkSourceView *view);
-static void gtk_source_view_draw_layer (GtkTextView *view,
- GtkTextViewLayer layer,
- cairo_t *cr);
-static MarkCategory *mark_category_new (GtkSourceMarkAttributes *attributes,
- gint priority);
-static void mark_category_free (MarkCategory *category);
+/* Prototypes. */
+static void gtk_source_view_dispose (GObject *object);
+static void gtk_source_view_finalize (GObject *object);
+static void gtk_source_view_show_completion_real (GtkSourceView *view);
+static GtkTextBuffer * gtk_source_view_create_buffer (GtkTextView *view);
+static void remove_source_buffer (GtkSourceView *view);
+static void set_source_buffer (GtkSourceView *view,
+ GtkTextBuffer *buffer);
+static void gtk_source_view_move_cursor (GtkTextView *text_view,
+ GtkMovementStep step,
+ gint count,
+ gboolean extend_selection);
+static void gtk_source_view_delete_from_cursor (GtkTextView *text_view,
+ GtkDeleteType type,
+ gint count);
+static gboolean gtk_source_view_extend_selection (GtkTextView *text_view,
+ GtkTextExtendSelection granularity,
+ const GtkTextIter *location,
+ GtkTextIter *start,
+ GtkTextIter *end);
+static void gtk_source_view_get_lines (GtkTextView *text_view,
+ gint first_y,
+ gint last_y,
+ GArray *buffer_coords,
+ GArray *line_heights,
+ GArray *numbers,
+ gint *countp);
+static void gtk_source_view_move_lines (GtkSourceView *view,
+ gboolean down);
+static void gtk_source_view_move_words (GtkSourceView *view,
+ gint step);
+static gboolean gtk_source_view_key_pressed (GtkSourceView *view,
+ guint keyval,
+ guint keycode,
+ guint state,
+ GtkEventControllerKey *controller);
+static gint calculate_real_tab_width (GtkSourceView *view,
+ guint tab_size,
+ gchar c);
+static void gtk_source_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_source_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void gtk_source_view_style_updated (GtkWidget *widget);
+static void gtk_source_view_update_style_scheme (GtkSourceView *view);
+
+static MarkCategory *mark_category_new (GtkSourceMarkAttributes *attributes,
+ gint priority);
+static void mark_category_free (MarkCategory *category);
+static void gtk_source_view_ensure_redrawn_rect_is_highlighted (GtkSourceView *view,
+ GdkRectangle *clip);
+static void gtk_source_view_snapshot_layer (GtkTextView *text_view,
+ GtkTextViewLayer layer,
+ GtkSnapshot *snapshot);
+static void gtk_source_view_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot);
+static void gtk_source_view_queue_draw (GtkSourceView *view);
static void
gtk_source_view_constructed (GObject *object)
@@ -329,7 +326,7 @@ gtk_source_view_constructed (GObject *object)
static void
gtk_source_view_move_to_matching_bracket (GtkSourceView *view,
- gboolean extend_selection)
+ gboolean extend_selection)
{
GtkTextView *text_view = GTK_TEXT_VIEW (view);
GtkTextBuffer *buffer;
@@ -364,7 +361,7 @@ gtk_source_view_move_to_matching_bracket (GtkSourceView *view,
static void
gtk_source_view_change_number (GtkSourceView *view,
- gint count)
+ gint count)
{
GtkTextView *text_view = GTK_TEXT_VIEW (view);
GtkTextBuffer *buffer;
@@ -426,7 +423,7 @@ gtk_source_view_change_number (GtkSourceView *view,
static void
gtk_source_view_change_case (GtkSourceView *view,
- GtkSourceChangeCaseType case_type)
+ GtkSourceChangeCaseType case_type)
{
GtkSourceBuffer *buffer;
GtkTextIter start, end;
@@ -444,6 +441,27 @@ gtk_source_view_change_case (GtkSourceView *view,
gtk_source_buffer_change_case (buffer, case_type, &start, &end);
}
+static void
+gtk_source_view_activate_change_case (GtkWidget *widget,
+ const gchar *action_name,
+ GVariant *parameter)
+{
+ GEnumClass *klass;
+ GEnumValue *value;
+ const gchar *nick;
+
+ nick = g_variant_get_string (parameter, NULL);
+ klass = g_type_class_ref (GTK_SOURCE_TYPE_CHANGE_CASE_TYPE);
+ value = g_enum_get_value_by_nick (klass, nick);
+
+ if (value != NULL)
+ {
+ gtk_source_view_change_case (GTK_SOURCE_VIEW (widget), value->value);
+ }
+
+ g_type_class_unref (klass);
+}
+
static void
gtk_source_view_join_lines (GtkSourceView *view)
{
@@ -478,19 +496,15 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
object_class->get_property = gtk_source_view_get_property;
object_class->set_property = gtk_source_view_set_property;
- widget_class->key_press_event = gtk_source_view_key_press_event;
- widget_class->draw = gtk_source_view_draw;
+ widget_class->snapshot = gtk_source_view_snapshot;
widget_class->style_updated = gtk_source_view_style_updated;
- textview_class->populate_popup = gtk_source_view_populate_popup;
textview_class->move_cursor = gtk_source_view_move_cursor;
textview_class->delete_from_cursor = gtk_source_view_delete_from_cursor;
textview_class->extend_selection = gtk_source_view_extend_selection;
textview_class->create_buffer = gtk_source_view_create_buffer;
- textview_class->draw_layer = gtk_source_view_draw_layer;
+ textview_class->snapshot_layer = gtk_source_view_snapshot_layer;
- klass->undo = gtk_source_view_undo;
- klass->redo = gtk_source_view_redo;
klass->show_completion = gtk_source_view_show_completion_real;
klass->move_lines = gtk_source_view_move_lines;
klass->move_words = gtk_source_view_move_words;
@@ -522,19 +536,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
- /**
- * GtkSourceView:show-line-marks:
- *
- * Whether to display line mark pixbufs
- */
- g_object_class_install_property (object_class,
- PROP_SHOW_LINE_MARKS,
- g_param_spec_boolean ("show-line-marks",
- "Show Line Marks",
- "Whether to display line mark pixbufs",
- FALSE,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS));
/**
* GtkSourceView:tab-width:
@@ -702,30 +703,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
- signals[UNDO] =
- g_signal_new ("undo",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GtkSourceViewClass, undo),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- g_signal_set_va_marshaller (signals[UNDO],
- G_TYPE_FROM_CLASS (klass),
- g_cclosure_marshal_VOID__VOIDv);
-
- signals[REDO] =
- g_signal_new ("redo",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GtkSourceViewClass, redo),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- g_signal_set_va_marshaller (signals[REDO],
- G_TYPE_FROM_CLASS (klass),
- g_cclosure_marshal_VOID__VOIDv);
-
/**
* GtkSourceView::show-completion:
* @view: The #GtkSourceView who emits the signal
@@ -753,31 +730,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
G_TYPE_FROM_CLASS (klass),
g_cclosure_marshal_VOID__VOIDv);
- /**
- * GtkSourceView::line-mark-activated:
- * @view: the #GtkSourceView
- * @iter: a #GtkTextIter
- * @event: the #GdkEvent that activated the event
- *
- * Emitted when a line mark has been activated (for instance when there
- * was a button press in the line marks gutter). You can use @iter to
- * determine on which line the activation took place.
- */
- signals[LINE_MARK_ACTIVATED] =
- g_signal_new ("line-mark-activated",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkSourceViewClass, line_mark_activated),
- NULL, NULL,
- _gtk_source_marshal_VOID__BOXED_BOXED,
- G_TYPE_NONE,
- 2,
- GTK_TYPE_TEXT_ITER,
- GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
- g_signal_set_va_marshaller (signals[LINE_MARK_ACTIVATED],
- G_TYPE_FROM_CLASS (klass),
- _gtk_source_marshal_VOID__BOXED_BOXEDv);
-
/**
* GtkSourceView::move-lines:
* @view: the #GtkSourceView which received the signal.
@@ -946,20 +898,11 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
G_TYPE_FROM_CLASS (klass),
g_cclosure_marshal_VOID__VOIDv);
+ gtk_widget_class_install_action (widget_class, "source.change-case", "s",
+ gtk_source_view_activate_change_case);
+
binding_set = gtk_binding_set_by_class (klass);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_z,
- GDK_CONTROL_MASK,
- "undo", 0);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_z,
- GDK_CONTROL_MASK | GDK_SHIFT_MASK,
- "redo", 0);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_F14,
- 0,
- "undo", 0);
gtk_binding_entry_add_signal (binding_set,
GDK_KEY_space,
GDK_CONTROL_MASK,
@@ -1133,9 +1076,9 @@ gtk_source_view_buildable_interface_init (GtkBuildableIface *iface)
static void
gtk_source_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkSourceView *view;
@@ -1149,10 +1092,6 @@ gtk_source_view_set_property (GObject *object,
gtk_source_view_set_show_line_numbers (view, g_value_get_boolean (value));
break;
- case PROP_SHOW_LINE_MARKS:
- gtk_source_view_set_show_line_marks (view, g_value_get_boolean (value));
- break;
-
case PROP_TAB_WIDTH:
gtk_source_view_set_tab_width (view, g_value_get_uint (value));
break;
@@ -1205,9 +1144,9 @@ gtk_source_view_set_property (GObject *object,
static void
gtk_source_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkSourceView *view;
@@ -1225,10 +1164,6 @@ gtk_source_view_get_property (GObject *object,
g_value_set_boolean (value, gtk_source_view_get_show_line_numbers (view));
break;
- case PROP_SHOW_LINE_MARKS:
- g_value_set_boolean (value, gtk_source_view_get_show_line_marks (view));
- break;
-
case PROP_TAB_WIDTH:
g_value_set_uint (value, gtk_source_view_get_tab_width (view));
break;
@@ -1285,10 +1220,10 @@ gtk_source_view_get_property (GObject *object,
static void
space_drawer_notify_cb (GtkSourceSpaceDrawer *space_drawer,
- GParamSpec *pspec,
- GtkSourceView *view)
+ GParamSpec *pspec,
+ GtkSourceView *view)
{
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
}
static void
@@ -1300,48 +1235,66 @@ notify_buffer_cb (GtkSourceView *view)
static void
gtk_source_view_init (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkStyleContext *context;
+ GtkEventController *key;
+#if 0
GtkTargetList *target_list;
+#endif
+
+ view->priv = gtk_source_view_get_instance_private (view);
+ view->priv->tab_width = DEFAULT_TAB_WIDTH;
+ view->priv->tabs_set = FALSE;
+ view->priv->indent_width = -1;
+ view->priv->indent_on_tab = TRUE;
+ view->priv->smart_home_end = GTK_SOURCE_SMART_HOME_END_DISABLED;
+ view->priv->right_margin_pos = DEFAULT_RIGHT_MARGIN_POSITION;
+ view->priv->cached_right_margin_pos = -1;
- priv->tab_width = DEFAULT_TAB_WIDTH;
- priv->tabs_set = FALSE;
- priv->indent_width = -1;
- priv->indent_on_tab = TRUE;
- priv->smart_home_end = GTK_SOURCE_SMART_HOME_END_DISABLED;
- priv->right_margin_pos = DEFAULT_RIGHT_MARGIN_POSITION;
- priv->cached_right_margin_pos = -1;
+ /* Default to monospace */
+ gtk_text_view_set_monospace (GTK_TEXT_VIEW (view), TRUE);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 2);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 2);
- priv->right_margin_line_color = NULL;
- priv->right_margin_overlay_color = NULL;
+ view->priv->right_margin_line_color = NULL;
+ view->priv->right_margin_overlay_color = NULL;
- priv->space_drawer = gtk_source_space_drawer_new ();
- g_signal_connect_object (priv->space_drawer,
+ view->priv->space_drawer = gtk_source_space_drawer_new ();
+ g_signal_connect_object (view->priv->space_drawer,
"notify",
G_CALLBACK (space_drawer_notify_cb),
view,
0);
- priv->mark_categories = g_hash_table_new_full (g_str_hash,
+ view->priv->mark_categories = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) mark_category_free);
+ key = gtk_event_controller_key_new ();
+ gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE);
+ g_signal_connect_swapped (key,
+ "key-pressed",
+ G_CALLBACK (gtk_source_view_key_pressed),
+ view);
+ gtk_widget_add_controller (GTK_WIDGET (view), g_steal_pointer (&key));
+
+#if 0
target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (view));
g_return_if_fail (target_list != NULL);
gtk_target_list_add_table (target_list, drop_types, G_N_ELEMENTS (drop_types));
+#endif
gtk_widget_set_has_tooltip (GTK_WIDGET (view), TRUE);
+#if 0
g_signal_connect (view,
"drag_data_received",
G_CALLBACK (view_dnd_drop),
NULL);
+#endif
g_signal_connect (view,
"notify::buffer",
@@ -1356,13 +1309,10 @@ static void
gtk_source_view_dispose (GObject *object)
{
GtkSourceView *view = GTK_SOURCE_VIEW (object);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
- g_clear_object (&priv->completion);
- g_clear_object (&priv->left_gutter);
- g_clear_object (&priv->right_gutter);
- g_clear_object (&priv->style_scheme);
- g_clear_object (&priv->space_drawer);
+ g_clear_object (&view->priv->completion);
+ g_clear_object (&view->priv->style_scheme);
+ g_clear_object (&view->priv->space_drawer);
remove_source_buffer (view);
@@ -1381,21 +1331,20 @@ static void
gtk_source_view_finalize (GObject *object)
{
GtkSourceView *view = GTK_SOURCE_VIEW (object);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
- if (priv->right_margin_line_color != NULL)
+ if (view->priv->right_margin_line_color != NULL)
{
- gdk_rgba_free (priv->right_margin_line_color);
+ gdk_rgba_free (view->priv->right_margin_line_color);
}
- if (priv->right_margin_overlay_color != NULL)
+ if (view->priv->right_margin_overlay_color != NULL)
{
- gdk_rgba_free (priv->right_margin_overlay_color);
+ gdk_rgba_free (view->priv->right_margin_overlay_color);
}
- if (priv->mark_categories)
+ if (view->priv->mark_categories)
{
- g_hash_table_destroy (priv->mark_categories);
+ g_hash_table_destroy (view->priv->mark_categories);
}
G_OBJECT_CLASS (gtk_source_view_parent_class)->finalize (object);
@@ -1403,8 +1352,8 @@ gtk_source_view_finalize (GObject *object)
static void
get_visible_region (GtkTextView *text_view,
- GtkTextIter *start,
- GtkTextIter *end)
+ GtkTextIter *start,
+ GtkTextIter *end)
{
GdkRectangle visible_rect;
@@ -1424,11 +1373,26 @@ get_visible_region (GtkTextView *text_view,
gtk_text_iter_forward_line (end);
}
+static void
+changed_cb (GtkSourceBuffer *buffer,
+ GtkSourceView *view)
+{
+ if (view->priv->left_gutter != NULL)
+ {
+ gtk_widget_queue_draw (GTK_WIDGET (view->priv->left_gutter));
+ }
+
+ if (view->priv->right_gutter != NULL)
+ {
+ gtk_widget_queue_draw (GTK_WIDGET (view->priv->right_gutter));
+ }
+}
+
static void
highlight_updated_cb (GtkSourceBuffer *buffer,
- GtkTextIter *_start,
- GtkTextIter *_end,
- GtkTextView *text_view)
+ GtkTextIter *_start,
+ GtkTextIter *_end,
+ GtkTextView *text_view)
{
GtkTextIter start;
GtkTextIter end;
@@ -1502,10 +1466,9 @@ highlight_updated_cb (GtkSourceBuffer *buffer,
static void
search_start_cb (GtkSourceBufferInternal *buffer_internal,
- GtkSourceSearchContext *search_context,
- GtkSourceView *view)
+ GtkSourceSearchContext *search_context,
+ GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextIter visible_start;
GtkTextIter visible_end;
GtkSourceBuffer *buffer_search;
@@ -1513,7 +1476,7 @@ search_start_cb (GtkSourceBufferInternal *buffer_internal,
get_visible_region (GTK_TEXT_VIEW (view), &visible_start, &visible_end);
buffer_search = gtk_source_search_context_get_buffer (search_context);
- g_assert (buffer_search == priv->source_buffer);
+ g_assert (buffer_search == view->priv->source_buffer);
_gtk_source_search_context_update_highlight (search_context,
&visible_start,
@@ -1523,74 +1486,89 @@ search_start_cb (GtkSourceBufferInternal *buffer_internal,
static void
source_mark_updated_cb (GtkSourceBuffer *buffer,
- GtkSourceMark *mark,
- GtkTextView *text_view)
+ GtkSourceMark *mark,
+ GtkTextView *text_view)
{
/* TODO do something more intelligent here, namely
* invalidate only the area under the mark if possible */
- gtk_widget_queue_draw (GTK_WIDGET (text_view));
+ gtk_source_view_queue_draw (GTK_SOURCE_VIEW (text_view));
}
static void
buffer_style_scheme_changed_cb (GtkSourceBuffer *buffer,
- GParamSpec *pspec,
- GtkSourceView *view)
+ GParamSpec *pspec,
+ GtkSourceView *view)
{
gtk_source_view_update_style_scheme (view);
}
+static void
+buffer_has_selection_changed_cb (GtkSourceBuffer *buffer,
+ GParamSpec *pspec,
+ GtkSourceView *view)
+{
+ gtk_widget_action_set_enabled (GTK_WIDGET (view),
+ "source.change-case",
+ (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer))));
+}
+
static void
implicit_trailing_newline_changed_cb (GtkSourceBuffer *buffer,
- GParamSpec *pspec,
- GtkSourceView *view)
+ GParamSpec *pspec,
+ GtkSourceView *view)
{
/* For drawing or not a trailing newline. */
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
}
static void
remove_source_buffer (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- if (priv->source_buffer != NULL)
+ if (view->priv->source_buffer != NULL)
{
GtkSourceBufferInternal *buffer_internal;
- g_signal_handlers_disconnect_by_func (priv->source_buffer,
+ g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
+ changed_cb,
+ view);
+
+ g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
highlight_updated_cb,
view);
- g_signal_handlers_disconnect_by_func (priv->source_buffer,
+ g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
source_mark_updated_cb,
view);
- g_signal_handlers_disconnect_by_func (priv->source_buffer,
+ g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
buffer_style_scheme_changed_cb,
view);
- g_signal_handlers_disconnect_by_func (priv->source_buffer,
+ g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
+ buffer_has_selection_changed_cb,
+ view);
+
+ g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
implicit_trailing_newline_changed_cb,
view);
- buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
+ buffer_internal = _gtk_source_buffer_internal_get_from_buffer (view->priv->source_buffer);
g_signal_handlers_disconnect_by_func (buffer_internal,
search_start_cb,
view);
- g_object_unref (priv->source_buffer);
- priv->source_buffer = NULL;
+ g_object_unref (view->priv->source_buffer);
+ view->priv->source_buffer = NULL;
}
}
static void
set_source_buffer (GtkSourceView *view,
- GtkTextBuffer *buffer)
+ GtkTextBuffer *buffer)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- if (buffer == (GtkTextBuffer*) priv->source_buffer)
+ if (buffer == (GtkTextBuffer*) view->priv->source_buffer)
{
return;
}
@@ -1601,7 +1579,12 @@ set_source_buffer (GtkSourceView *view,
{
GtkSourceBufferInternal *buffer_internal;
- priv->source_buffer = g_object_ref (GTK_SOURCE_BUFFER (buffer));
+ view->priv->source_buffer = g_object_ref (GTK_SOURCE_BUFFER (buffer));
+
+ g_signal_connect (buffer,
+ "changed",
+ G_CALLBACK (changed_cb),
+ view);
g_signal_connect (buffer,
"highlight-updated",
@@ -1623,103 +1606,28 @@ set_source_buffer (GtkSourceView *view,
G_CALLBACK (implicit_trailing_newline_changed_cb),
view);
- buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
+ g_signal_connect (buffer,
+ "notify::has-selection",
+ G_CALLBACK (buffer_has_selection_changed_cb),
+ view);
+
+ buffer_internal = _gtk_source_buffer_internal_get_from_buffer (view->priv->source_buffer);
g_signal_connect (buffer_internal,
"search-start",
G_CALLBACK (search_start_cb),
view);
- }
-
- gtk_source_view_update_style_scheme (view);
-}
-
-static void
-scroll_to_insert (GtkSourceView *view,
- GtkTextBuffer *buffer)
-{
- GtkTextMark *insert;
- GtkTextIter iter;
- GdkRectangle visible, location;
-
- insert = gtk_text_buffer_get_insert (buffer);
- gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
-
- gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible);
- gtk_text_view_get_iter_location (GTK_TEXT_VIEW (view), &iter, &location);
- if (location.y < visible.y || visible.y + visible.height < location.y)
- {
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
- insert,
- 0.0,
- TRUE,
- 0.5, 0.5);
+ buffer_has_selection_changed_cb (GTK_SOURCE_BUFFER (buffer), NULL, view);
}
- else if (location.x < visible.x || visible.x + visible.width < location.x)
- {
- gdouble position;
- GtkAdjustment *adjustment;
-
- /* We revert the vertical position of the view because
- * _scroll_to_iter will cause it to move and the
- * insert mark is already visible vertically. */
-
- adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view));
- position = gtk_adjustment_get_value (adjustment);
-
- /* Must use _to_iter as _to_mark scrolls in an
- * idle handler and would prevent use from
- * reverting the vertical position of the view. */
- gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view),
- &iter,
- 0.0,
- TRUE,
- 0.5, 0.0);
-
- gtk_adjustment_set_value (adjustment, position);
- }
-}
-static void
-gtk_source_view_undo (GtkSourceView *view)
-{
- GtkTextBuffer *buffer;
-
- g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- if (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
- GTK_SOURCE_IS_BUFFER (buffer) &&
- gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (buffer)))
- {
- gtk_source_buffer_undo (GTK_SOURCE_BUFFER (buffer));
- scroll_to_insert (view, buffer);
- }
-}
-
-static void
-gtk_source_view_redo (GtkSourceView *view)
-{
- GtkTextBuffer *buffer;
-
- g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
- if (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
- GTK_SOURCE_IS_BUFFER (buffer) &&
- gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (buffer)))
- {
- gtk_source_buffer_redo (GTK_SOURCE_BUFFER (buffer));
- scroll_to_insert (view, buffer);
- }
+ gtk_source_view_update_style_scheme (view);
}
static void
gtk_source_view_show_completion_real (GtkSourceView *view)
{
+#if 0
GtkSourceCompletion *completion;
GtkSourceCompletionContext *context;
@@ -1729,43 +1637,13 @@ gtk_source_view_show_completion_real (GtkSourceView *view)
gtk_source_completion_start (completion,
gtk_source_completion_get_providers (completion),
context);
+#endif
}
-static void
-menu_item_activate_change_case_cb (GtkWidget *menu_item,
- GtkTextView *text_view)
-{
- GtkTextBuffer *buffer;
- GtkTextIter start, end;
-
- buffer = gtk_text_view_get_buffer (text_view);
- if (!GTK_SOURCE_IS_BUFFER (buffer))
- {
- return;
- }
-
- if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
- {
- GtkSourceChangeCaseType case_type;
-
- case_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "change-case"));
- gtk_source_buffer_change_case (GTK_SOURCE_BUFFER (buffer), case_type, &start, &end);
- }
-}
-
-static void
-menu_item_activate_cb (GtkWidget *menu_item,
- GtkTextView *text_view)
-{
- const gchar *gtksignal;
-
- gtksignal = g_object_get_data (G_OBJECT (menu_item), "gtk-signal");
- g_signal_emit_by_name (G_OBJECT (text_view), gtksignal);
-}
-
+#if 0
static void
gtk_source_view_populate_popup (GtkTextView *text_view,
- GtkWidget *popup)
+ GtkWidget *popup)
{
GtkTextBuffer *buffer;
GtkMenuShell *menu;
@@ -1794,24 +1672,14 @@ gtk_source_view_populate_popup (GtkTextView *text_view,
/* create redo menu_item. */
menu_item = gtk_menu_item_new_with_mnemonic (_("_Redo"));
- g_object_set_data (G_OBJECT (menu_item), "gtk-signal", (gpointer)"redo");
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (menu_item_activate_cb), text_view);
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item), "text.redo");
gtk_menu_shell_prepend (menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (buffer))));
gtk_widget_show (menu_item);
/* create undo menu_item. */
menu_item = gtk_menu_item_new_with_mnemonic (_("_Undo"));
- g_object_set_data (G_OBJECT (menu_item), "gtk-signal", (gpointer)"undo");
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (menu_item_activate_cb), text_view);
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item), "text.undo");
gtk_menu_shell_prepend (menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (buffer))));
gtk_widget_show (menu_item);
}
@@ -1824,58 +1692,36 @@ gtk_source_view_populate_popup (GtkTextView *text_view,
case_menu = GTK_MENU_SHELL (gtk_menu_new ());
menu_item = gtk_menu_item_new_with_mnemonic (_("All _Upper Case"));
- g_object_set_data (G_OBJECT (menu_item), "change-case",
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_UPPER));
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+ gtk_actionable_set_detailed_action_name ("source.change-case('upper')");
gtk_menu_shell_append (case_menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_text_buffer_get_has_selection (buffer)));
gtk_widget_show (menu_item);
menu_item = gtk_menu_item_new_with_mnemonic (_("All _Lower Case"));
- g_object_set_data (G_OBJECT (menu_item), "change-case",
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_LOWER));
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+ gtk_actionable_set_detailed_action_name ("source.change-case('lower')");
gtk_menu_shell_append (case_menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_text_buffer_get_has_selection (buffer)));
gtk_widget_show (menu_item);
menu_item = gtk_menu_item_new_with_mnemonic (_("_Invert Case"));
- g_object_set_data (G_OBJECT (menu_item), "change-case",
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_TOGGLE));
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+ gtk_actionable_set_detailed_action_name ("source.change-case('toggle')");
gtk_menu_shell_append (case_menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_text_buffer_get_has_selection (buffer)));
gtk_widget_show (menu_item);
menu_item = gtk_menu_item_new_with_mnemonic (_("_Title Case"));
- g_object_set_data (G_OBJECT (menu_item), "change-case",
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_TITLE));
- g_signal_connect (G_OBJECT (menu_item), "activate",
- G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+ gtk_actionable_set_detailed_action_name ("source.change-case('title')");
gtk_menu_shell_append (case_menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_text_buffer_get_has_selection (buffer)));
gtk_widget_show (menu_item);
menu_item = gtk_menu_item_new_with_mnemonic (_("C_hange Case"));
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), GTK_WIDGET (case_menu));
gtk_menu_shell_append (menu, menu_item);
- gtk_widget_set_sensitive (menu_item,
- (gtk_text_view_get_editable (text_view) &&
- gtk_text_buffer_get_has_selection (buffer)));
gtk_widget_show (menu_item);
}
+#endif
static void
move_cursor (GtkTextView *text_view,
- const GtkTextIter *new_location,
- gboolean extend_selection)
+ const GtkTextIter *new_location,
+ gboolean extend_selection)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
@@ -1894,8 +1740,8 @@ move_cursor (GtkTextView *text_view,
static void
move_to_first_char (GtkTextView *text_view,
- GtkTextIter *iter,
- gboolean display_line)
+ GtkTextIter *iter,
+ gboolean display_line)
{
GtkTextIter last;
@@ -1939,8 +1785,8 @@ move_to_first_char (GtkTextView *text_view,
static void
move_to_last_char (GtkTextView *text_view,
- GtkTextIter *iter,
- gboolean display_line)
+ GtkTextIter *iter,
+ gboolean display_line)
{
GtkTextIter first;
@@ -1983,10 +1829,10 @@ move_to_last_char (GtkTextView *text_view,
static void
do_cursor_move_home_end (GtkTextView *text_view,
- GtkTextIter *cur,
- GtkTextIter *iter,
- gboolean extend_selection,
- gint count)
+ GtkTextIter *cur,
+ GtkTextIter *iter,
+ gboolean extend_selection,
+ gint count)
{
/* if we are clearing selection, we need to move_cursor even
* if we are at proper iter because selection_bound may need
@@ -2001,12 +1847,11 @@ do_cursor_move_home_end (GtkTextView *text_view,
/* Returns %TRUE if handled. */
static gboolean
move_cursor_smart_home_end (GtkTextView *text_view,
- GtkMovementStep step,
- gint count,
- gboolean extend_selection)
+ GtkMovementStep step,
+ gint count,
+ gboolean extend_selection)
{
GtkSourceView *source_view = GTK_SOURCE_VIEW (text_view);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (source_view);
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
gboolean move_display_line;
GtkTextMark *mark;
@@ -2037,7 +1882,7 @@ move_cursor_smart_home_end (GtkTextView *text_view,
at_home = gtk_text_iter_starts_line (&cur);
}
- switch (priv->smart_home_end)
+ switch (source_view->priv->smart_home_end)
{
case GTK_SOURCE_SMART_HOME_END_BEFORE:
if (!gtk_text_iter_equal (&cur, &iter) || at_home)
@@ -2095,7 +1940,7 @@ move_cursor_smart_home_end (GtkTextView *text_view,
at_end = gtk_text_iter_ends_line (&cur);
}
- switch (priv->smart_home_end)
+ switch (source_view->priv->smart_home_end)
{
case GTK_SOURCE_SMART_HOME_END_BEFORE:
if (!gtk_text_iter_equal (&cur, &iter) || at_end)
@@ -2140,8 +1985,8 @@ move_cursor_smart_home_end (GtkTextView *text_view,
static void
move_cursor_words (GtkTextView *text_view,
- gint count,
- gboolean extend_selection)
+ gint count,
+ gboolean extend_selection)
{
GtkTextBuffer *buffer;
GtkTextIter insert;
@@ -2211,9 +2056,9 @@ move_cursor_words (GtkTextView *text_view,
static void
gtk_source_view_move_cursor (GtkTextView *text_view,
- GtkMovementStep step,
- gint count,
- gboolean extend_selection)
+ GtkMovementStep step,
+ gint count,
+ gboolean extend_selection)
{
if (!gtk_text_view_get_cursor_visible (text_view))
{
@@ -2256,8 +2101,8 @@ chain_up:
static void
gtk_source_view_delete_from_cursor (GtkTextView *text_view,
- GtkDeleteType type,
- gint count)
+ GtkDeleteType type,
+ gint count)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
GtkTextIter insert;
@@ -2302,10 +2147,10 @@ gtk_source_view_delete_from_cursor (GtkTextView *text_view,
static gboolean
gtk_source_view_extend_selection (GtkTextView *text_view,
- GtkTextExtendSelection granularity,
- const GtkTextIter *location,
- GtkTextIter *start,
- GtkTextIter *end)
+ GtkTextExtendSelection granularity,
+ const GtkTextIter *location,
+ GtkTextIter *start,
+ GtkTextIter *end)
{
if (granularity == GTK_TEXT_EXTEND_SELECTION_WORD)
{
@@ -2322,45 +2167,37 @@ gtk_source_view_extend_selection (GtkTextView *text_view,
static void
gtk_source_view_ensure_redrawn_rect_is_highlighted (GtkSourceView *view,
- cairo_t *cr)
+ GdkRectangle *clip)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
- GdkRectangle clip;
GtkTextIter iter1, iter2;
- if (priv->source_buffer == NULL ||
- !gdk_cairo_get_clip_rectangle (cr, &clip))
- {
- return;
- }
-
- gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter1, clip.y, NULL);
+ gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter1, clip->y, NULL);
gtk_text_iter_backward_line (&iter1);
- gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter2, clip.y + clip.height, NULL);
+ gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter2, clip->y + clip->height, NULL);
gtk_text_iter_forward_line (&iter2);
DEBUG ({
- g_print (" draw area: %d - %d\n", clip.y, clip.y + clip.height);
+ g_print (" draw area: %d - %d\n", clip->y, clip->y + clip->height);
g_print (" lines to update: %d - %d\n",
gtk_text_iter_get_line (&iter1),
gtk_text_iter_get_line (&iter2));
});
- _gtk_source_buffer_update_syntax_highlight (priv->source_buffer,
+ _gtk_source_buffer_update_syntax_highlight (view->priv->source_buffer,
&iter1, &iter2, FALSE);
- _gtk_source_buffer_update_search_highlight (priv->source_buffer,
+ _gtk_source_buffer_update_search_highlight (view->priv->source_buffer,
&iter1, &iter2, FALSE);
}
/* This function is taken from gtk+/tests/testtext.c */
static void
gtk_source_view_get_lines (GtkTextView *text_view,
- gint first_y,
- gint last_y,
- GArray *buffer_coords,
- GArray *line_heights,
- GArray *numbers,
- gint *countp)
+ gint first_y,
+ gint last_y,
+ GArray *buffer_coords,
+ GArray *line_heights,
+ GArray *numbers,
+ gint *countp)
{
GtkTextIter iter;
gint count;
@@ -2434,31 +2271,37 @@ gtk_source_view_get_lines (GtkTextView *text_view,
*/
static void
gtk_source_view_paint_line_background (GtkTextView *text_view,
- cairo_t *cr,
+ GtkSnapshot *snapshot,
int y, /* in buffer coordinates */
int height,
const GdkRGBA *color)
{
- gdouble x1, y1, x2, y2;
-
- cairo_save (cr);
- cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
+ static const float widths[4] = { 1, 0, 1, 0 };
+ GdkRGBA colors[4] = { *color, *color, *color, *color };
+ GdkRectangle visible_rect;
- gdk_cairo_set_source_rgba (cr, (GdkRGBA *)color);
- cairo_set_line_width (cr, 1);
- cairo_rectangle (cr, x1 + .5, y + .5, x2 - x1 - 1, height - 1);
- cairo_stroke_preserve (cr);
- cairo_fill (cr);
- cairo_restore (cr);
+ gtk_text_view_get_visible_rect (text_view, &visible_rect);
+ gtk_snapshot_append_border (snapshot,
+ &GSK_ROUNDED_RECT_INIT (visible_rect.x,
+ y,
+ visible_rect.width,
+ height),
+ widths,
+ colors);
+ gtk_snapshot_append_color (snapshot,
+ color,
+ &GRAPHENE_RECT_INIT (visible_rect.x,
+ y,
+ visible_rect.width,
+ height));
}
static void
gtk_source_view_paint_marks_background (GtkSourceView *view,
- cairo_t *cr)
+ GtkSnapshot *snapshot)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextView *text_view;
- GdkRectangle clip;
+ GdkRectangle visible_rect;
GArray *numbers;
GArray *pixels;
GArray *heights;
@@ -2466,17 +2309,18 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
gint count;
gint i;
- if (priv->source_buffer == NULL ||
- !_gtk_source_buffer_has_source_marks (priv->source_buffer) ||
- !gdk_cairo_get_clip_rectangle (cr, &clip))
+ if (view->priv->source_buffer == NULL ||
+ !_gtk_source_buffer_has_source_marks (view->priv->source_buffer))
{
return;
}
text_view = GTK_TEXT_VIEW (view);
- y1 = clip.y;
- y2 = y1 + clip.height;
+ gtk_text_view_get_visible_rect (text_view, &visible_rect);
+
+ y1 = visible_rect.y;
+ y2 = y1 + visible_rect.height;
numbers = g_array_new (FALSE, FALSE, sizeof (gint));
pixels = g_array_new (FALSE, FALSE, sizeof (gint));
@@ -2522,7 +2366,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
line_to_paint = g_array_index (numbers, gint, i);
- marks = gtk_source_buffer_get_source_marks_at_line (priv->source_buffer,
+ marks = gtk_source_buffer_get_source_marks_at_line (view->priv->source_buffer,
line_to_paint,
NULL);
@@ -2552,7 +2396,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
if (priority != -1)
{
gtk_source_view_paint_line_background (text_view,
- cr,
+ snapshot,
g_array_index (pixels, gint, i),
g_array_index (heights, gint, i),
&background);
@@ -2566,11 +2410,10 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
static void
gtk_source_view_paint_right_margin (GtkSourceView *view,
- cairo_t *cr)
+ GtkSnapshot *snapshot)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextView *text_view = GTK_TEXT_VIEW (view);
- GdkRectangle clip;
+ GdkRectangle visible_rect;
gdouble x;
#ifdef ENABLE_PROFILE
@@ -2584,48 +2427,40 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
g_timer_start (timer);
#endif
- g_return_if_fail (priv->right_margin_line_color != NULL);
+ g_return_if_fail (view->priv->right_margin_line_color != NULL);
- if (!gdk_cairo_get_clip_rectangle (cr, &clip))
- {
- return;
- }
+ gtk_text_view_get_visible_rect (text_view, &visible_rect);
- if (priv->cached_right_margin_pos < 0)
+ if (view->priv->cached_right_margin_pos < 0)
{
- priv->cached_right_margin_pos =
+ view->priv->cached_right_margin_pos =
calculate_real_tab_width (view,
- priv->right_margin_pos,
+ view->priv->right_margin_pos,
'_');
}
- x = priv->cached_right_margin_pos + gtk_text_view_get_left_margin (text_view);
+ x = view->priv->cached_right_margin_pos + gtk_text_view_get_left_margin (text_view);
- cairo_save (cr);
- cairo_set_line_width (cr, 1.0);
+ gtk_snapshot_save (snapshot);
- if (x + 1 >= clip.x && x <= clip.x + clip.width)
- {
- cairo_move_to (cr, x + 0.5, clip.y);
- cairo_line_to (cr, x + 0.5, clip.y + clip.height);
-
- gdk_cairo_set_source_rgba (cr, priv->right_margin_line_color);
- cairo_stroke (cr);
- }
+ gtk_snapshot_append_color (snapshot,
+ view->priv->right_margin_line_color,
+ &GRAPHENE_RECT_INIT (x,
+ visible_rect.y,
+ 1,
+ visible_rect.height));
- /* Only draw the overlay when the style scheme explicitly sets it. */
- if (priv->right_margin_overlay_color != NULL && clip.x + clip.width > x + 1)
+ if (view->priv->right_margin_overlay_color != NULL)
{
- /* Draw the rectangle next to the line (x+1). */
- cairo_rectangle (cr,
- x + 1, clip.y,
- clip.x + clip.width - (x + 1), clip.height);
-
- gdk_cairo_set_source_rgba (cr, priv->right_margin_overlay_color);
- cairo_fill (cr);
+ gtk_snapshot_append_color (snapshot,
+ view->priv->right_margin_overlay_color,
+ &GRAPHENE_RECT_INIT (x + 1,
+ visible_rect.y,
+ visible_rect.x + visible_rect.width,
+ visible_rect.height));
}
- cairo_restore (cr);
+ gtk_snapshot_restore (snapshot);
PROFILE ({
g_timer_stop (timer);
@@ -2637,7 +2472,7 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
static gint
realign (gint offset,
- guint align)
+ guint align)
{
if (offset > 0 && align > 0)
{
@@ -2652,16 +2487,17 @@ realign (gint offset,
static void
gtk_source_view_paint_background_pattern_grid (GtkSourceView *view,
- cairo_t *cr)
+ GtkSnapshot *snapshot)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
- GdkRectangle clip;
+ GdkRectangle visible_rect;
gint x, y, x2, y2;
PangoContext *context;
PangoLayout *layout;
gint grid_width = 16;
gint grid_height = 16;
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible_rect);
+
context = gtk_widget_get_pango_context (GTK_WIDGET (view));
layout = pango_layout_new (context);
pango_layout_set_text (layout, "X", 1);
@@ -2672,40 +2508,28 @@ gtk_source_view_paint_background_pattern_grid (GtkSourceView *view,
grid_height = MAX (1, grid_height / 2);
grid_width = MAX (1, grid_width);
- cairo_save (cr);
-
- gdk_cairo_get_clip_rectangle (cr, &clip);
-
- cairo_set_line_width (cr, 1.0);
- gdk_cairo_set_source_rgba (cr, &priv->background_pattern_color);
-
/* Align our drawing position with a multiple of the grid size. */
- x = realign (clip.x - grid_width, grid_width);
- y = realign (clip.y - grid_height, grid_height);
- x2 = realign (x + clip.width + grid_width * 2, grid_width);
- y2 = realign (y + clip.height + grid_height * 2, grid_height);
-
- for (; x <= x2; x += grid_width)
- {
- cairo_move_to (cr, x + .5, clip.y - .5);
- cairo_line_to (cr, x + .5, clip.y + clip.height - .5);
- }
-
- for (; y <= y2; y += grid_height)
- {
- cairo_move_to (cr, clip.x + .5, y - .5);
- cairo_line_to (cr, clip.x + clip.width + .5, y - .5);
- }
-
- cairo_stroke (cr);
- cairo_restore (cr);
+ x = realign (visible_rect.x - grid_width, grid_width);
+ y = realign (visible_rect.y - grid_height, grid_height);
+ x2 = realign (x + visible_rect.width + grid_width * 2, grid_width);
+ y2 = realign (y + visible_rect.height + grid_height * 2, grid_height);
+
+ gtk_snapshot_push_repeat (snapshot,
+ &GRAPHENE_RECT_INIT (x, y, x2 - x, y2 - y),
+ &GRAPHENE_RECT_INIT (x, y, grid_width, grid_height));
+ gtk_snapshot_append_color (snapshot,
+ &view->priv->background_pattern_color,
+ &GRAPHENE_RECT_INIT (x, y, 1, grid_height));
+ gtk_snapshot_append_color (snapshot,
+ &view->priv->background_pattern_color,
+ &GRAPHENE_RECT_INIT (x, y, grid_width, 1));
+ gtk_snapshot_pop (snapshot);
}
static void
gtk_source_view_paint_current_line_highlight (GtkSourceView *view,
- cairo_t *cr)
+ GtkSnapshot *snapshot)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buffer;
GtkTextIter cur;
gint y;
@@ -2718,101 +2542,66 @@ gtk_source_view_paint_current_line_highlight (GtkSourceView *view,
gtk_text_view_get_line_yrange (GTK_TEXT_VIEW (view), &cur, &y, &height);
gtk_source_view_paint_line_background (GTK_TEXT_VIEW (view),
- cr,
+ snapshot,
y, height,
- &priv->current_line_color);
+ &view->priv->current_line_color);
}
static void
-gtk_source_view_draw_layer (GtkTextView *text_view,
- GtkTextViewLayer layer,
- cairo_t *cr)
+gtk_source_view_snapshot_layer (GtkTextView *text_view,
+ GtkTextViewLayer layer,
+ GtkSnapshot *snapshot)
{
- GtkSourceView *view = GTK_SOURCE_VIEW (text_view);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+ GtkSourceView *view;
+
+ view = GTK_SOURCE_VIEW (text_view);
- cairo_save (cr);
+ gtk_snapshot_save (snapshot);
if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT)
{
- gtk_source_view_ensure_redrawn_rect_is_highlighted (view, cr);
-
- if (priv->background_pattern == GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID &&
- priv->background_pattern_color_set)
+ if (view->priv->background_pattern == GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID &&
+ view->priv->background_pattern_color_set)
{
- gtk_source_view_paint_background_pattern_grid (view, cr);
+ gtk_source_view_paint_background_pattern_grid (view, snapshot);
}
if (gtk_widget_is_sensitive (GTK_WIDGET (view)) &&
- priv->highlight_current_line &&
- priv->current_line_color_set)
+ view->priv->highlight_current_line &&
+ view->priv->current_line_color_set)
{
- gtk_source_view_paint_current_line_highlight (view, cr);
+ gtk_source_view_paint_current_line_highlight (view, snapshot);
}
- gtk_source_view_paint_marks_background (view, cr);
+ gtk_source_view_paint_marks_background (view, snapshot);
}
else if (layer == GTK_TEXT_VIEW_LAYER_ABOVE_TEXT)
{
/* Draw the right margin vertical line + overlay. */
- if (priv->show_right_margin)
+ if (view->priv->show_right_margin)
{
- gtk_source_view_paint_right_margin (view, cr);
+ gtk_source_view_paint_right_margin (view, snapshot);
}
- if (priv->space_drawer != NULL)
+ if (view->priv->space_drawer != NULL)
{
- _gtk_source_space_drawer_draw (priv->space_drawer, view, cr);
+ _gtk_source_space_drawer_draw (view->priv->space_drawer, view, snapshot);
}
}
- cairo_restore (cr);
+ gtk_snapshot_restore (snapshot);
}
-static gboolean
-gtk_source_view_draw (GtkWidget *widget,
- cairo_t *cr)
+static void
+gtk_source_view_snapshot (GtkWidget *widget,
+ GtkSnapshot *snapshot)
{
- GtkSourceView *view = GTK_SOURCE_VIEW (widget);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
- gboolean event_handled;
-
-#ifdef ENABLE_PROFILE
- static GTimer *timer = NULL;
- if (timer == NULL)
- {
- timer = g_timer_new ();
- }
-
- g_timer_start (timer);
-#endif
-
- DEBUG ({
- g_print ("> gtk_source_view_draw start\n");
- });
-
- event_handled = GTK_WIDGET_CLASS (gtk_source_view_parent_class)->draw (widget, cr);
-
- if (priv->left_gutter != NULL)
- {
- _gtk_source_gutter_draw (priv->left_gutter, view, cr);
- }
-
- if (priv->right_gutter != NULL)
- {
- _gtk_source_gutter_draw (priv->right_gutter, view, cr);
- }
+ GdkRectangle visible_rect;
- PROFILE ({
- g_timer_stop (timer);
- g_print (" gtk_source_view_draw time: %g (sec * 1000)\n",
- g_timer_elapsed (timer, NULL) * 1000);
- });
- DEBUG ({
- g_print ("> gtk_source_view_draw end\n");
- });
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (widget), &visible_rect);
+ gtk_source_view_ensure_redrawn_rect_is_highlighted (GTK_SOURCE_VIEW (widget), &visible_rect);
- return event_handled;
+ GTK_WIDGET_CLASS (gtk_source_view_parent_class)->snapshot (widget, snapshot);
}
/* This is a pretty important function... We call it when the tab_stop is changed,
@@ -2918,11 +2707,9 @@ gtk_source_view_new_with_buffer (GtkSourceBuffer *buffer)
gboolean
gtk_source_view_get_show_line_numbers (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->show_line_numbers;
+ return view->priv->show_line_numbers;
}
/**
@@ -2934,27 +2721,25 @@ gtk_source_view_get_show_line_numbers (GtkSourceView *view)
*/
void
gtk_source_view_set_show_line_numbers (GtkSourceView *view,
- gboolean show)
+ gboolean show)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
show = show != FALSE;
- if (show == priv->show_line_numbers)
+ if (show == view->priv->show_line_numbers)
{
return;
}
- if (priv->line_renderer == NULL)
+ if (view->priv->line_renderer == NULL)
{
GtkSourceGutter *gutter;
gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
- priv->line_renderer = _gtk_source_gutter_renderer_lines_new ();
- g_object_set (priv->line_renderer,
+ view->priv->line_renderer = gtk_source_gutter_renderer_lines_new ();
+ g_object_set (view->priv->line_renderer,
"alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
"yalign", 0.5,
"xalign", 1.0,
@@ -2962,106 +2747,23 @@ gtk_source_view_set_show_line_numbers (GtkSourceView *view,
NULL);
gtk_source_gutter_insert (gutter,
- priv->line_renderer,
+ view->priv->line_renderer,
GTK_SOURCE_VIEW_GUTTER_POSITION_LINES);
}
- gtk_source_gutter_renderer_set_visible (priv->line_renderer, show);
- priv->show_line_numbers = show;
+ gtk_widget_set_visible (GTK_WIDGET (view->priv->line_renderer), show);
+ view->priv->show_line_numbers = show;
g_object_notify (G_OBJECT (view), "show_line_numbers");
}
-/**
- * gtk_source_view_get_show_line_marks:
- * @view: a #GtkSourceView.
- *
- * Returns whether line marks are displayed beside the text.
- *
- * Return value: %TRUE if the line marks are displayed.
- *
- * Since: 2.2
- */
-gboolean
-gtk_source_view_get_show_line_marks (GtkSourceView *view)
-{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
-
- return priv->show_line_marks;
-}
-
-static void
-gutter_renderer_marks_activate (GtkSourceGutterRenderer *renderer,
- GtkTextIter *iter,
- const GdkRectangle *area,
- GdkEvent *event,
- GtkSourceView *view)
-{
- g_signal_emit (view,
- signals[LINE_MARK_ACTIVATED],
- 0,
- iter,
- event);
-}
-
-/**
- * gtk_source_view_set_show_line_marks:
- * @view: a #GtkSourceView.
- * @show: whether line marks should be displayed.
- *
- * If %TRUE line marks will be displayed beside the text.
- *
- * Since: 2.2
- */
-void
-gtk_source_view_set_show_line_marks (GtkSourceView *view,
- gboolean show)
-{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
- show = show != FALSE;
-
- if (show == priv->show_line_marks)
- {
- return;
- }
-
- if (priv->marks_renderer == NULL)
- {
- GtkSourceGutter *gutter;
-
- gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
-
- priv->marks_renderer = gtk_source_gutter_renderer_marks_new ();
-
- gtk_source_gutter_insert (gutter,
- priv->marks_renderer,
- GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS);
-
- g_signal_connect (priv->marks_renderer,
- "activate",
- G_CALLBACK (gutter_renderer_marks_activate),
- view);
- }
-
- gtk_source_gutter_renderer_set_visible (priv->marks_renderer, show);
- priv->show_line_marks = show;
-
- g_object_notify (G_OBJECT (view), "show_line_marks");
-}
-
static gboolean
set_tab_stops_internal (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
PangoTabArray *tab_array;
gint real_tab_width;
- real_tab_width = calculate_real_tab_width (view, priv->tab_width, ' ');
+ real_tab_width = calculate_real_tab_width (view, view->priv->tab_width, ' ');
if (real_tab_width < 0)
{
@@ -3073,7 +2775,7 @@ set_tab_stops_internal (GtkSourceView *view)
gtk_text_view_set_tabs (GTK_TEXT_VIEW (view),
tab_array);
- priv->tabs_set = TRUE;
+ view->priv->tabs_set = TRUE;
pango_tab_array_free (tab_array);
@@ -3091,21 +2793,20 @@ set_tab_stops_internal (GtkSourceView *view)
*/
void
gtk_source_view_set_tab_width (GtkSourceView *view,
- guint width)
+ guint width)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
guint save_width;
g_return_if_fail (GTK_SOURCE_VIEW (view));
g_return_if_fail (0 < width && width <= MAX_TAB_WIDTH);
- if (priv->tab_width == width)
+ if (view->priv->tab_width == width)
{
return;
}
- save_width = priv->tab_width;
- priv->tab_width = width;
+ save_width = view->priv->tab_width;
+ view->priv->tab_width = width;
if (set_tab_stops_internal (view))
{
g_object_notify (G_OBJECT (view), "tab-width");
@@ -3113,7 +2814,7 @@ gtk_source_view_set_tab_width (GtkSourceView *view,
else
{
g_warning ("Impossible to set tab width.");
- priv->tab_width = save_width;
+ view->priv->tab_width = save_width;
}
}
@@ -3128,11 +2829,9 @@ gtk_source_view_set_tab_width (GtkSourceView *view,
guint
gtk_source_view_get_tab_width (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), DEFAULT_TAB_WIDTH);
- return priv->tab_width;
+ return view->priv->tab_width;
}
/**
@@ -3163,16 +2862,14 @@ gtk_source_view_get_tab_width (GtkSourceView *view)
*/
void
gtk_source_view_set_indent_width (GtkSourceView *view,
- gint width)
+ gint width)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_VIEW (view));
g_return_if_fail (width == -1 || (0 < width && width <= MAX_INDENT_WIDTH));
- if (priv->indent_width != width)
+ if (view->priv->indent_width != width)
{
- priv->indent_width = width;
+ view->priv->indent_width = width;
g_object_notify (G_OBJECT (view), "indent-width");
}
}
@@ -3189,16 +2886,14 @@ gtk_source_view_set_indent_width (GtkSourceView *view,
gint
gtk_source_view_get_indent_width (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), 0);
- return priv->indent_width;
+ return view->priv->indent_width;
}
static gchar *
compute_indentation (GtkSourceView *view,
- GtkTextIter *cur)
+ GtkTextIter *cur)
{
GtkTextIter start;
GtkTextIter end;
@@ -3235,16 +2930,14 @@ compute_indentation (GtkSourceView *view,
static guint
get_real_indent_width (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- return priv->indent_width < 0 ?
- priv->tab_width :
- (guint) priv->indent_width;
+ return view->priv->indent_width < 0 ?
+ view->priv->tab_width :
+ (guint) view->priv->indent_width;
}
static gchar *
get_indent_string (guint tabs,
- guint spaces)
+ guint spaces)
{
gchar *str;
@@ -3278,10 +2971,9 @@ get_indent_string (guint tabs,
*/
void
gtk_source_view_indent_lines (GtkSourceView *view,
- GtkTextIter *start,
- GtkTextIter *end)
+ GtkTextIter *start,
+ GtkTextIter *end)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buf;
gboolean bracket_hl;
GtkTextMark *start_mark, *end_mark;
@@ -3291,9 +2983,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
guint spaces = 0;
gint i;
- if (priv->completion != NULL)
+ if (view->priv->completion != NULL)
{
- gtk_source_completion_block_interactive (priv->completion);
+ gtk_source_completion_block_interactive (view->priv->completion);
}
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -3313,20 +3005,20 @@ gtk_source_view_indent_lines (GtkSourceView *view,
end_line--;
}
- if (priv->insert_spaces)
+ if (view->priv->insert_spaces)
{
spaces = get_real_indent_width (view);
tab_buffer = g_strnfill (spaces, ' ');
}
- else if (priv->indent_width > 0 &&
- priv->indent_width != (gint)priv->tab_width)
+ else if (view->priv->indent_width > 0 &&
+ view->priv->indent_width != (gint)view->priv->tab_width)
{
guint indent_width;
indent_width = get_real_indent_width (view);
- spaces = indent_width % priv->tab_width;
- tabs = indent_width / priv->tab_width;
+ spaces = indent_width % view->priv->tab_width;
+ tabs = indent_width / view->priv->tab_width;
tab_buffer = get_indent_string (tabs, spaces);
}
@@ -3369,9 +3061,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
/* if tabs are allowed try to merge the spaces
* with the tab we are going to insert (if any) */
iter2 = iter;
- while (!priv->insert_spaces &&
+ while (!view->priv->insert_spaces &&
(gtk_text_iter_get_char (&iter2) == ' ') &&
- replaced_spaces < priv->tab_width)
+ replaced_spaces < view->priv->tab_width)
{
++replaced_spaces;
@@ -3383,8 +3075,8 @@ gtk_source_view_indent_lines (GtkSourceView *view,
gchar *indent_buf;
guint t, s;
- t = tabs + (spaces + replaced_spaces) / priv->tab_width;
- s = (spaces + replaced_spaces) % priv->tab_width;
+ t = tabs + (spaces + replaced_spaces) / view->priv->tab_width;
+ s = (spaces + replaced_spaces) % view->priv->tab_width;
indent_buf = get_indent_string (t, s);
gtk_text_buffer_delete (buf, &iter, &iter2);
@@ -3404,9 +3096,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buf), bracket_hl);
- if (priv->completion != NULL)
+ if (view->priv->completion != NULL)
{
- gtk_source_completion_unblock_interactive (priv->completion);
+ gtk_source_completion_unblock_interactive (view->priv->completion);
}
gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view),
@@ -3433,10 +3125,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
*/
void
gtk_source_view_unindent_lines (GtkSourceView *view,
- GtkTextIter *start,
- GtkTextIter *end)
+ GtkTextIter *start,
+ GtkTextIter *end)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buf;
gboolean bracket_hl;
GtkTextMark *start_mark, *end_mark;
@@ -3445,9 +3136,9 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
gint indent_width;
gint i;
- if (priv->completion != NULL)
+ if (view->priv->completion != NULL)
{
- gtk_source_completion_block_interactive (priv->completion);
+ gtk_source_completion_block_interactive (view->priv->completion);
}
buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -3467,7 +3158,7 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
end_line--;
}
- tab_width = priv->tab_width;
+ tab_width = view->priv->tab_width;
indent_width = get_real_indent_width (view);
gtk_text_buffer_begin_user_action (buf);
@@ -3517,9 +3208,9 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buf), bracket_hl);
- if (priv->completion != NULL)
+ if (view->priv->completion != NULL)
{
- gtk_source_completion_unblock_interactive (priv->completion);
+ gtk_source_completion_unblock_interactive (view->priv->completion);
}
gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view),
@@ -3535,14 +3226,13 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
static gint
get_line_offset_in_equivalent_spaces (GtkSourceView *view,
- GtkTextIter *iter)
+ GtkTextIter *iter)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextIter i;
gint tab_width;
gint n = 0;
- tab_width = priv->tab_width;
+ tab_width = view->priv->tab_width;
i = *iter;
gtk_text_iter_set_line_offset (&i, 0);
@@ -3569,15 +3259,14 @@ get_line_offset_in_equivalent_spaces (GtkSourceView *view,
static void
insert_tab_or_spaces (GtkSourceView *view,
- GtkTextIter *start,
- GtkTextIter *end)
+ GtkTextIter *start,
+ GtkTextIter *end)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buf;
gchar *tab_buf;
gint cursor_offset = 0;
- if (priv->insert_spaces)
+ if (view->priv->insert_spaces)
{
gint indent_width;
gint pos;
@@ -3591,8 +3280,8 @@ insert_tab_or_spaces (GtkSourceView *view,
tab_buf = g_strnfill (spaces, ' ');
}
- else if (priv->indent_width > 0 &&
- priv->indent_width != (gint)priv->tab_width)
+ else if (view->priv->indent_width > 0 &&
+ view->priv->indent_width != (gint)view->priv->tab_width)
{
GtkTextIter iter;
gint i;
@@ -3606,7 +3295,7 @@ insert_tab_or_spaces (GtkSourceView *view,
gint tabs;
gint spaces;
- tab_width = priv->tab_width;
+ tab_width = view->priv->tab_width;
indent_width = get_real_indent_width (view);
/* CHECK: is this a performance problem? */
@@ -3681,7 +3370,7 @@ insert_tab_or_spaces (GtkSourceView *view,
static void
gtk_source_view_move_words (GtkSourceView *view,
- gint step)
+ gint step)
{
GtkTextBuffer *buf;
GtkTextIter s, e, ns, ne;
@@ -3852,7 +3541,7 @@ remove_trailing_newline (GtkTextBuffer *buffer)
static void
gtk_source_view_move_lines (GtkSourceView *view,
- gboolean down)
+ gboolean down)
{
GtkTextBuffer *buffer;
GtkTextIter start;
@@ -3954,7 +3643,6 @@ gtk_source_view_move_lines (GtkSourceView *view,
static gboolean
do_smart_backspace (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buffer;
gboolean default_editable;
GtkTextIter insert;
@@ -3963,7 +3651,7 @@ do_smart_backspace (GtkSourceView *view)
guint visual_column;
gint indent_width;
- buffer = GTK_TEXT_BUFFER (priv->source_buffer);
+ buffer = GTK_TEXT_BUFFER (view->priv->source_buffer);
default_editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
if (gtk_text_buffer_get_selection_bounds (buffer, &insert, &end))
@@ -3979,10 +3667,10 @@ do_smart_backspace (GtkSourceView *view)
}
visual_column = gtk_source_view_get_visual_column (view, &insert);
- indent_width = priv->indent_width;
+ indent_width = view->priv->indent_width;
if (indent_width <= 0)
{
- indent_width = priv->tab_width;
+ indent_width = view->priv->tab_width;
}
g_return_val_if_fail (indent_width > 0, FALSE);
@@ -4027,14 +3715,13 @@ do_smart_backspace (GtkSourceView *view)
static gboolean
do_ctrl_backspace (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buffer;
GtkTextIter insert;
GtkTextIter end;
GtkTextIter leading_end;
gboolean default_editable;
- buffer = GTK_TEXT_BUFFER (priv->source_buffer);
+ buffer = GTK_TEXT_BUFFER (view->priv->source_buffer);
default_editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
if (gtk_text_buffer_get_selection_bounds (buffer, &insert, &end))
@@ -4069,11 +3756,12 @@ do_ctrl_backspace (GtkSourceView *view)
}
static gboolean
-gtk_source_view_key_press_event (GtkWidget *widget,
- GdkEventKey *event)
+gtk_source_view_key_pressed (GtkSourceView *view,
+ guint keyval,
+ guint keycode,
+ guint state,
+ GtkEventControllerKey *controller)
{
- GtkSourceView *view = GTK_SOURCE_VIEW (widget);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buf;
GtkTextIter cur;
GtkTextMark *mark;
@@ -4081,22 +3769,22 @@ gtk_source_view_key_press_event (GtkWidget *widget,
gint key;
gboolean editable;
- buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
+ buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (widget));
+ editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
/* Be careful when testing for modifier state equality:
* caps lock, num lock,etc need to be taken into account */
modifiers = gtk_accelerator_get_default_mod_mask ();
- key = event->keyval;
+ key = keyval;
mark = gtk_text_buffer_get_insert (buf);
gtk_text_buffer_get_iter_at_mark (buf, &cur, mark);
if ((key == GDK_KEY_Return || key == GDK_KEY_KP_Enter) &&
- !(event->state & GDK_SHIFT_MASK) &&
- priv->auto_indent)
+ !(state & GDK_SHIFT_MASK) &&
+ view->priv->auto_indent)
{
/* Auto-indent means that when you press ENTER at the end of a
* line, the new line is automatically indented at the same
@@ -4110,6 +3798,7 @@ gtk_source_view_key_press_event (GtkWidget *widget,
if (indent != NULL)
{
+#if 0
/* Allow input methods to internally handle a key press event.
* If this function returns TRUE, then no further processing should be done
* for this keystroke. */
@@ -4118,6 +3807,7 @@ gtk_source_view_key_press_event (GtkWidget *widget,
g_free (indent);
return GDK_EVENT_STOP;
}
+#endif
/* Delete any selected text to preserve behavior without auto-indent */
gtk_text_buffer_delete_selection (buf,
@@ -4135,8 +3825,7 @@ gtk_source_view_key_press_event (GtkWidget *widget,
gtk_text_buffer_insert (buf, &cur, indent, strlen (indent));
g_free (indent);
gtk_text_buffer_end_user_action (buf);
- gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (widget),
- mark);
+ gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view), mark);
return GDK_EVENT_STOP;
}
}
@@ -4145,8 +3834,8 @@ gtk_source_view_key_press_event (GtkWidget *widget,
* with shift+tab key is GDK_ISO_Left_Tab (yay! on win32 and mac too!)
*/
if ((key == GDK_KEY_Tab || key == GDK_KEY_KP_Tab || key == GDK_KEY_ISO_Left_Tab) &&
- ((event->state & modifiers) == 0 ||
- (event->state & modifiers) == GDK_SHIFT_MASK) &&
+ ((state & modifiers) == 0 ||
+ (state & modifiers) == GDK_SHIFT_MASK) &&
editable &&
gtk_text_view_get_accepts_tab (GTK_TEXT_VIEW (view)))
{
@@ -4155,10 +3844,10 @@ gtk_source_view_key_press_event (GtkWidget *widget,
has_selection = gtk_text_buffer_get_selection_bounds (buf, &s, &e);
- if (priv->indent_on_tab)
+ if (view->priv->indent_on_tab)
{
/* shift+tab: always unindent */
- if (event->state & GDK_SHIFT_MASK)
+ if (state & GDK_SHIFT_MASK)
{
_gtk_source_buffer_save_and_clear_selection (GTK_SOURCE_BUFFER (buf));
gtk_source_view_unindent_lines (view, &s, &e);
@@ -4187,14 +3876,14 @@ gtk_source_view_key_press_event (GtkWidget *widget,
if (key == GDK_KEY_BackSpace)
{
- if ((event->state & modifiers) == 0)
+ if ((state & modifiers) == 0)
{
- if (priv->smart_backspace && do_smart_backspace (view))
+ if (view->priv->smart_backspace && do_smart_backspace (view))
{
return GDK_EVENT_STOP;
}
}
- else if ((event->state & modifiers) == GDK_CONTROL_MASK)
+ else if ((state & modifiers) == GDK_CONTROL_MASK)
{
if (do_ctrl_backspace (view))
{
@@ -4203,7 +3892,7 @@ gtk_source_view_key_press_event (GtkWidget *widget,
}
}
- return GTK_WIDGET_CLASS (gtk_source_view_parent_class)->key_press_event (widget, event);
+ return GDK_EVENT_PROPAGATE;
}
/**
@@ -4217,11 +3906,9 @@ gtk_source_view_key_press_event (GtkWidget *widget,
gboolean
gtk_source_view_get_auto_indent (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->auto_indent;
+ return view->priv->auto_indent;
}
/**
@@ -4238,17 +3925,15 @@ gtk_source_view_get_auto_indent (GtkSourceView *view)
*/
void
gtk_source_view_set_auto_indent (GtkSourceView *view,
- gboolean enable)
+ gboolean enable)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
enable = enable != FALSE;
- if (priv->auto_indent != enable)
+ if (view->priv->auto_indent != enable)
{
- priv->auto_indent = enable;
+ view->priv->auto_indent = enable;
g_object_notify (G_OBJECT (view), "auto_indent");
}
}
@@ -4265,11 +3950,9 @@ gtk_source_view_set_auto_indent (GtkSourceView *view,
gboolean
gtk_source_view_get_insert_spaces_instead_of_tabs (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->insert_spaces;
+ return view->priv->insert_spaces;
}
/**
@@ -4283,17 +3966,15 @@ gtk_source_view_get_insert_spaces_instead_of_tabs (GtkSourceView *view)
*/
void
gtk_source_view_set_insert_spaces_instead_of_tabs (GtkSourceView *view,
- gboolean enable)
+ gboolean enable)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
enable = enable != FALSE;
- if (priv->insert_spaces != enable)
+ if (view->priv->insert_spaces != enable)
{
- priv->insert_spaces = enable;
+ view->priv->insert_spaces = enable;
g_object_notify (G_OBJECT (view), "insert_spaces_instead_of_tabs");
}
}
@@ -4310,11 +3991,9 @@ gtk_source_view_set_insert_spaces_instead_of_tabs (GtkSourceView *view,
gboolean
gtk_source_view_get_indent_on_tab (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->indent_on_tab;
+ return view->priv->indent_on_tab;
}
/**
@@ -4334,82 +4013,59 @@ gtk_source_view_get_indent_on_tab (GtkSourceView *view)
*/
void
gtk_source_view_set_indent_on_tab (GtkSourceView *view,
- gboolean enable)
+ gboolean enable)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
enable = enable != FALSE;
- if (priv->indent_on_tab != enable)
+ if (view->priv->indent_on_tab != enable)
{
- priv->indent_on_tab = enable;
+ view->priv->indent_on_tab = enable;
g_object_notify (G_OBJECT (view), "indent_on_tab");
}
}
+#if 0
static void
view_dnd_drop (GtkTextView *view,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *selection_data,
- guint info,
- guint timestamp,
- gpointer data)
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint timestamp,
+ gpointer data)
{
GtkTextIter iter;
if (info == TARGET_COLOR)
{
- GdkRGBA rgba;
+ guint16 *vals;
gchar string[] = "#000000";
gint buffer_x;
gint buffer_y;
gint length = gtk_selection_data_get_length (selection_data);
- guint format;
if (length < 0)
{
return;
}
- format = gtk_selection_data_get_format (selection_data);
-
- if (format == 8 && length == 4)
- {
- guint8 *vals;
-
- vals = (gpointer) gtk_selection_data_get_data (selection_data);
-
- rgba.red = vals[0] / 256.0;
- rgba.green = vals[1] / 256.0;
- rgba.blue = vals[2] / 256.0;
- rgba.alpha = 1.0;
- }
- else if (format == 16 && length == 8)
- {
- guint16 *vals;
-
- vals = (gpointer) gtk_selection_data_get_data (selection_data);
-
- rgba.red = vals[0] / 65535.0;
- rgba.green = vals[1] / 65535.0;
- rgba.blue = vals[2] / 65535.0;
- rgba.alpha = 1.0;
- }
- else
+ if (gtk_selection_data_get_format (selection_data) != 16 || length != 8)
{
g_warning ("Received invalid color data\n");
return;
}
- g_snprintf (string, sizeof string, "#%02X%02X%02X",
- (gint)(rgba.red * 256),
- (gint)(rgba.green * 256),
- (gint)(rgba.blue * 256));
+ vals = (gpointer) gtk_selection_data_get_data (selection_data);
+
+ vals[0] /= 256;
+ vals[1] /= 256;
+ vals[2] /= 256;
+
+ g_snprintf (string, sizeof (string), "#%02X%02X%02X", vals[0], vals[1], vals[2]);
gtk_text_view_window_to_buffer_coords (view,
GTK_TEXT_WINDOW_TEXT,
@@ -4438,6 +4094,7 @@ view_dnd_drop (GtkTextView *view,
return;
}
}
+#endif
/**
* gtk_source_view_get_highlight_current_line:
@@ -4450,11 +4107,9 @@ view_dnd_drop (GtkTextView *view,
gboolean
gtk_source_view_get_highlight_current_line (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->highlight_current_line;
+ return view->priv->highlight_current_line;
}
/**
@@ -4466,19 +4121,17 @@ gtk_source_view_get_highlight_current_line (GtkSourceView *view)
*/
void
gtk_source_view_set_highlight_current_line (GtkSourceView *view,
- gboolean highlight)
+ gboolean highlight)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
highlight = highlight != FALSE;
- if (priv->highlight_current_line != highlight)
+ if (view->priv->highlight_current_line != highlight)
{
- priv->highlight_current_line = highlight;
+ view->priv->highlight_current_line = highlight;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
g_object_notify (G_OBJECT (view), "highlight_current_line");
}
@@ -4495,11 +4148,9 @@ gtk_source_view_set_highlight_current_line (GtkSourceView *view,
gboolean
gtk_source_view_get_show_right_margin (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->show_right_margin;
+ return view->priv->show_right_margin;
}
/**
@@ -4511,19 +4162,17 @@ gtk_source_view_get_show_right_margin (GtkSourceView *view)
*/
void
gtk_source_view_set_show_right_margin (GtkSourceView *view,
- gboolean show)
+ gboolean show)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
show = show != FALSE;
- if (priv->show_right_margin != show)
+ if (view->priv->show_right_margin != show)
{
- priv->show_right_margin = show;
+ view->priv->show_right_margin = show;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
g_object_notify (G_OBJECT (view), "show-right-margin");
}
@@ -4540,11 +4189,9 @@ gtk_source_view_set_show_right_margin (GtkSourceView *view,
guint
gtk_source_view_get_right_margin_position (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), DEFAULT_RIGHT_MARGIN_POSITION);
- return priv->right_margin_pos;
+ return view->priv->right_margin_pos;
}
/**
@@ -4556,19 +4203,17 @@ gtk_source_view_get_right_margin_position (GtkSourceView *view)
*/
void
gtk_source_view_set_right_margin_position (GtkSourceView *view,
- guint pos)
+ guint pos)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
g_return_if_fail (1 <= pos && pos <= MAX_RIGHT_MARGIN_POSITION);
- if (priv->right_margin_pos != pos)
+ if (view->priv->right_margin_pos != pos)
{
- priv->right_margin_pos = pos;
- priv->cached_right_margin_pos = -1;
+ view->priv->right_margin_pos = pos;
+ view->priv->cached_right_margin_pos = -1;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
g_object_notify (G_OBJECT (view), "right-margin-position");
}
@@ -4588,15 +4233,13 @@ void
gtk_source_view_set_smart_backspace (GtkSourceView *view,
gboolean smart_backspace)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
smart_backspace = smart_backspace != FALSE;
- if (smart_backspace != priv->smart_backspace)
+ if (smart_backspace != view->priv->smart_backspace)
{
- priv->smart_backspace = smart_backspace;
+ view->priv->smart_backspace = smart_backspace;
g_object_notify (G_OBJECT (view), "smart-backspace");
}
}
@@ -4615,11 +4258,9 @@ gtk_source_view_set_smart_backspace (GtkSourceView *view,
gboolean
gtk_source_view_get_smart_backspace (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->smart_backspace;
+ return view->priv->smart_backspace;
}
/**
@@ -4632,15 +4273,13 @@ gtk_source_view_get_smart_backspace (GtkSourceView *view)
*/
void
gtk_source_view_set_smart_home_end (GtkSourceView *view,
- GtkSourceSmartHomeEndType smart_home_end)
+ GtkSourceSmartHomeEndType smart_home_end)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
- if (priv->smart_home_end != smart_home_end)
+ if (view->priv->smart_home_end != smart_home_end)
{
- priv->smart_home_end = smart_home_end;
+ view->priv->smart_home_end = smart_home_end;
g_object_notify (G_OBJECT (view), "smart_home_end");
}
}
@@ -4657,11 +4296,9 @@ gtk_source_view_set_smart_home_end (GtkSourceView *view,
GtkSourceSmartHomeEndType
gtk_source_view_get_smart_home_end (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
- return priv->smart_home_end;
+ return view->priv->smart_home_end;
}
/**
@@ -4676,9 +4313,8 @@ gtk_source_view_get_smart_home_end (GtkSourceView *view)
*/
guint
gtk_source_view_get_visual_column (GtkSourceView *view,
- const GtkTextIter *iter)
+ const GtkTextIter *iter)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextIter position;
guint column;
guint tab_width;
@@ -4687,7 +4323,7 @@ gtk_source_view_get_visual_column (GtkSourceView *view,
g_return_val_if_fail (iter != NULL, 0);
column = 0;
- tab_width = priv->tab_width;
+ tab_width = view->priv->tab_width;
position = *iter;
gtk_text_iter_set_line_offset (&position, 0);
@@ -4717,58 +4353,53 @@ gtk_source_view_get_visual_column (GtkSourceView *view,
static void
update_background_pattern_color (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- if (priv->style_scheme == NULL)
+ if (view->priv->style_scheme == NULL)
{
- priv->background_pattern_color_set = FALSE;
+ view->priv->background_pattern_color_set = FALSE;
return;
}
- priv->background_pattern_color_set =
- _gtk_source_style_scheme_get_background_pattern_color (priv->style_scheme,
- &priv->background_pattern_color);
+ view->priv->background_pattern_color_set =
+ _gtk_source_style_scheme_get_background_pattern_color (view->priv->style_scheme,
+ &view->priv->background_pattern_color);
}
static void
update_current_line_color (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
- if (priv->style_scheme == NULL)
+ if (view->priv->style_scheme == NULL)
{
- priv->current_line_color_set = FALSE;
+ view->priv->current_line_color_set = FALSE;
return;
}
- priv->current_line_color_set =
- _gtk_source_style_scheme_get_current_line_color (priv->style_scheme,
- &priv->current_line_color);
+ view->priv->current_line_color_set =
+ _gtk_source_style_scheme_get_current_line_color (view->priv->style_scheme,
+ &view->priv->current_line_color);
}
static void
update_right_margin_colors (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkWidget *widget = GTK_WIDGET (view);
- if (priv->right_margin_line_color != NULL)
+ if (view->priv->right_margin_line_color != NULL)
{
- gdk_rgba_free (priv->right_margin_line_color);
- priv->right_margin_line_color = NULL;
+ gdk_rgba_free (view->priv->right_margin_line_color);
+ view->priv->right_margin_line_color = NULL;
}
- if (priv->right_margin_overlay_color != NULL)
+ if (view->priv->right_margin_overlay_color != NULL)
{
- gdk_rgba_free (priv->right_margin_overlay_color);
- priv->right_margin_overlay_color = NULL;
+ gdk_rgba_free (view->priv->right_margin_overlay_color);
+ view->priv->right_margin_overlay_color = NULL;
}
- if (priv->style_scheme != NULL)
+ if (view->priv->style_scheme != NULL)
{
GtkSourceStyle *style;
- style = _gtk_source_style_scheme_get_right_margin_style (priv->style_scheme);
+ style = _gtk_source_style_scheme_get_right_margin_style (view->priv->style_scheme);
if (style != NULL)
{
@@ -4785,8 +4416,8 @@ update_right_margin_colors (GtkSourceView *view)
color_str != NULL &&
gdk_rgba_parse (&color, color_str))
{
- priv->right_margin_line_color = gdk_rgba_copy (&color);
- priv->right_margin_line_color->alpha =
+ view->priv->right_margin_line_color = gdk_rgba_copy (&color);
+ view->priv->right_margin_line_color->alpha =
RIGHT_MARGIN_LINE_ALPHA / 255.;
}
@@ -4802,8 +4433,8 @@ update_right_margin_colors (GtkSourceView *view)
color_str != NULL &&
gdk_rgba_parse (&color, color_str))
{
- priv->right_margin_overlay_color = gdk_rgba_copy (&color);
- priv->right_margin_overlay_color->alpha =
+ view->priv->right_margin_overlay_color = gdk_rgba_copy (&color);
+ view->priv->right_margin_overlay_color->alpha =
RIGHT_MARGIN_OVERLAY_ALPHA / 255.;
}
@@ -4811,7 +4442,7 @@ update_right_margin_colors (GtkSourceView *view)
}
}
- if (priv->right_margin_line_color == NULL)
+ if (view->priv->right_margin_line_color == NULL)
{
GtkStyleContext *context;
GdkRGBA color;
@@ -4819,13 +4450,11 @@ update_right_margin_colors (GtkSourceView *view)
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
- gtk_style_context_get_color (context,
- gtk_style_context_get_state (context),
- &color);
+ gtk_style_context_get_color (context, &color);
gtk_style_context_restore (context);
- priv->right_margin_line_color = gdk_rgba_copy (&color);
- priv->right_margin_line_color->alpha =
+ view->priv->right_margin_line_color = gdk_rgba_copy (&color);
+ view->priv->right_margin_line_color->alpha =
RIGHT_MARGIN_LINE_ALPHA / 255.;
}
}
@@ -4833,24 +4462,21 @@ update_right_margin_colors (GtkSourceView *view)
static void
update_style (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
update_background_pattern_color (view);
update_current_line_color (view);
update_right_margin_colors (view);
- if (priv->space_drawer != NULL)
+ if (view->priv->space_drawer != NULL)
{
- _gtk_source_space_drawer_update_color (priv->space_drawer, view);
+ _gtk_source_space_drawer_update_color (view->priv->space_drawer, view);
}
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
}
static void
gtk_source_view_update_style_scheme (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
GtkTextBuffer *buffer;
GtkSourceStyleScheme *new_scheme = NULL;
@@ -4861,21 +4487,21 @@ gtk_source_view_update_style_scheme (GtkSourceView *view)
new_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer));
}
- if (priv->style_scheme == new_scheme)
+ if (view->priv->style_scheme == new_scheme)
{
return;
}
- if (priv->style_scheme != NULL)
+ if (view->priv->style_scheme != NULL)
{
- _gtk_source_style_scheme_unapply (priv->style_scheme, view);
+ _gtk_source_style_scheme_unapply (view->priv->style_scheme, view);
}
- g_set_object (&priv->style_scheme, new_scheme);
+ g_set_object (&view->priv->style_scheme, new_scheme);
- if (priv->style_scheme != NULL)
+ if (view->priv->style_scheme != NULL)
{
- _gtk_source_style_scheme_apply (priv->style_scheme, view);
+ _gtk_source_style_scheme_apply (view->priv->style_scheme, view);
}
update_style (view);
@@ -4885,7 +4511,6 @@ static void
gtk_source_view_style_updated (GtkWidget *widget)
{
GtkSourceView *view = GTK_SOURCE_VIEW (widget);
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
/* Call default handler first. */
if (GTK_WIDGET_CLASS (gtk_source_view_parent_class)->style_updated != NULL)
@@ -4896,20 +4521,20 @@ gtk_source_view_style_updated (GtkWidget *widget)
/* Re-set tab stops, but only if we already modified them, i.e.
* do nothing with good old 8-space tabs.
*/
- if (priv->tabs_set)
+ if (view->priv->tabs_set)
{
set_tab_stops_internal (view);
}
/* Make sure the margin position is recalculated on next redraw. */
- priv->cached_right_margin_pos = -1;
+ view->priv->cached_right_margin_pos = -1;
update_style (view);
}
static MarkCategory *
mark_category_new (GtkSourceMarkAttributes *attributes,
- gint priority)
+ gint priority)
{
MarkCategory* category = g_slice_new (MarkCategory);
@@ -4942,16 +4567,14 @@ mark_category_free (MarkCategory *category)
GtkSourceCompletion *
gtk_source_view_get_completion (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
- if (priv->completion == NULL)
+ if (view->priv->completion == NULL)
{
- priv->completion = _gtk_source_completion_new (view);
+ view->priv->completion = _gtk_source_completion_new (view);
}
- return priv->completion;
+ return view->priv->completion;
}
/**
@@ -4970,32 +4593,38 @@ gtk_source_view_get_completion (GtkSourceView *view)
*/
GtkSourceGutter *
gtk_source_view_get_gutter (GtkSourceView *view,
- GtkTextWindowType window_type)
+ GtkTextWindowType window_type)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
g_return_val_if_fail (window_type == GTK_TEXT_WINDOW_LEFT ||
window_type == GTK_TEXT_WINDOW_RIGHT, NULL);
if (window_type == GTK_TEXT_WINDOW_LEFT)
{
- if (priv->left_gutter == NULL)
+ if (view->priv->left_gutter == NULL)
{
- priv->left_gutter = _gtk_source_gutter_new (view, window_type);
+ view->priv->left_gutter = _gtk_source_gutter_new (window_type);
+ gtk_text_view_set_gutter (GTK_TEXT_VIEW (view),
+ GTK_TEXT_WINDOW_LEFT,
+ GTK_WIDGET (view->priv->left_gutter));
}
- return priv->left_gutter;
+ return view->priv->left_gutter;
}
- else
+ else if (window_type == GTK_TEXT_WINDOW_RIGHT)
{
- if (priv->right_gutter == NULL)
+ if (view->priv->right_gutter == NULL)
{
- priv->right_gutter = _gtk_source_gutter_new (view, window_type);
+ view->priv->right_gutter = _gtk_source_gutter_new (window_type);
+ gtk_text_view_set_gutter (GTK_TEXT_VIEW (view),
+ GTK_TEXT_WINDOW_RIGHT,
+ GTK_WIDGET (view->priv->right_gutter));
}
- return priv->right_gutter;
+ return view->priv->right_gutter;
}
+
+ g_return_val_if_reached (NULL);
}
/**
@@ -5009,11 +4638,10 @@ gtk_source_view_get_gutter (GtkSourceView *view,
*/
void
gtk_source_view_set_mark_attributes (GtkSourceView *view,
- const gchar *category,
- GtkSourceMarkAttributes *attributes,
- gint priority)
+ const gchar *category,
+ GtkSourceMarkAttributes *attributes,
+ gint priority)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
MarkCategory *mark_category;
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
@@ -5022,7 +4650,7 @@ gtk_source_view_set_mark_attributes (GtkSourceView *view,
g_return_if_fail (priority >= 0);
mark_category = mark_category_new (attributes, priority);
- g_hash_table_replace (priv->mark_categories,
+ g_hash_table_replace (view->priv->mark_categories,
g_strdup (category),
mark_category);
}
@@ -5040,16 +4668,15 @@ gtk_source_view_set_mark_attributes (GtkSourceView *view,
*/
GtkSourceMarkAttributes *
gtk_source_view_get_mark_attributes (GtkSourceView *view,
- const gchar *category,
- gint *priority)
+ const gchar *category,
+ gint *priority)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
MarkCategory *mark_category;
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
g_return_val_if_fail (category != NULL, NULL);
- mark_category = g_hash_table_lookup (priv->mark_categories,
+ mark_category = g_hash_table_lookup (view->priv->mark_categories,
category);
if (mark_category != NULL)
@@ -5076,17 +4703,15 @@ gtk_source_view_get_mark_attributes (GtkSourceView *view,
*/
void
gtk_source_view_set_background_pattern (GtkSourceView *view,
- GtkSourceBackgroundPatternType background_pattern)
+ GtkSourceBackgroundPatternType background_pattern)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
- if (priv->background_pattern != background_pattern)
+ if (view->priv->background_pattern != background_pattern)
{
- priv->background_pattern = background_pattern;
+ view->priv->background_pattern = background_pattern;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ gtk_source_view_queue_draw (view);
g_object_notify (G_OBJECT (view), "background-pattern");
}
@@ -5105,11 +4730,9 @@ gtk_source_view_set_background_pattern (GtkSourceView *view,
GtkSourceBackgroundPatternType
gtk_source_view_get_background_pattern (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), GTK_SOURCE_BACKGROUND_PATTERN_TYPE_NONE);
- return priv->background_pattern;
+ return view->priv->background_pattern;
}
/**
@@ -5126,9 +4749,23 @@ gtk_source_view_get_background_pattern (GtkSourceView *view)
GtkSourceSpaceDrawer *
gtk_source_view_get_space_drawer (GtkSourceView *view)
{
- GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
- return priv->space_drawer;
+ return view->priv->space_drawer;
+}
+
+static void
+gtk_source_view_queue_draw (GtkSourceView *view)
+{
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+
+ if (view->priv->left_gutter != NULL)
+ {
+ gtk_widget_queue_draw (GTK_WIDGET (view->priv->left_gutter));
+ }
+
+ if (view->priv->right_gutter != NULL)
+ {
+ gtk_widget_queue_draw (GTK_WIDGET (view->priv->right_gutter));
+ }
}
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 40ef7e96..2dde3d46 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -32,7 +32,15 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_VIEW (gtk_source_view_get_type())
+#define GTK_SOURCE_TYPE_VIEW (gtk_source_view_get_type ())
+#define GTK_SOURCE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_VIEW,
GtkSourceView))
+#define GTK_SOURCE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_VIEW,
GtkSourceViewClass))
+#define GTK_SOURCE_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_VIEW))
+#define GTK_SOURCE_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_VIEW))
+#define GTK_SOURCE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_VIEW,
GtkSourceViewClass))
+
+typedef struct _GtkSourceViewClass GtkSourceViewClass;
+typedef struct _GtkSourceViewPrivate GtkSourceViewPrivate;
/**
* GtkSourceViewGutterPosition:
@@ -80,123 +88,165 @@ typedef enum _GtkSourceBackgroundPatternType
GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID
} GtkSourceBackgroundPatternType;
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceView, gtk_source_view, GTK_SOURCE, VIEW, GtkTextView)
+struct _GtkSourceView
+{
+ GtkTextView parent;
+
+ GtkSourceViewPrivate *priv;
+};
struct _GtkSourceViewClass
{
GtkTextViewClass parent_class;
- void (*undo) (GtkSourceView *view);
- void (*redo) (GtkSourceView *view);
- void (*line_mark_activated) (GtkSourceView *view,
- GtkTextIter *iter,
- GdkEvent *event);
- void (*show_completion) (GtkSourceView *view);
- void (*move_lines) (GtkSourceView *view,
- gboolean down);
- void (*move_words) (GtkSourceView *view,
- gint step);
+ void (*show_completion) (GtkSourceView *view);
+ void (*move_lines) (GtkSourceView *view,
+ gboolean down);
+
+ void (*move_words) (GtkSourceView *view,
+ gint step);
/*< private >*/
gpointer _reserved[20];
};
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkWidget *gtk_source_view_new (void);
+GType gtk_source_view_get_type (void) G_GNUC_CONST;
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkWidget *gtk_source_view_new_with_buffer (GtkSourceBuffer
*buffer);
+GtkWidget *gtk_source_view_new (void);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_show_line_numbers (GtkSourceView
*view,
- gboolean
show);
+GtkWidget *gtk_source_view_new_with_buffer (GtkSourceBuffer *buffer);
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_view_set_show_line_numbers (GtkSourceView *view,
+ gboolean show);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_show_line_numbers (GtkSourceView
*view);
+gboolean gtk_source_view_get_show_line_numbers (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_tab_width (GtkSourceView
*view,
- guint
width);
+void gtk_source_view_set_tab_width (GtkSourceView *view,
+ guint width);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-guint gtk_source_view_get_tab_width (GtkSourceView
*view);
+guint gtk_source_view_get_tab_width (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_indent_width (GtkSourceView
*view,
- gint
width);
+void gtk_source_view_set_indent_width (GtkSourceView *view,
+ gint width);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gint gtk_source_view_get_indent_width (GtkSourceView
*view);
+gint gtk_source_view_get_indent_width (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_auto_indent (GtkSourceView
*view,
- gboolean
enable);
+void gtk_source_view_set_auto_indent (GtkSourceView *view,
+ gboolean enable);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_auto_indent (GtkSourceView
*view);
+gboolean gtk_source_view_get_auto_indent (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_insert_spaces_instead_of_tabs (GtkSourceView
*view,
- gboolean
enable);
+void gtk_source_view_set_insert_spaces_instead_of_tabs
+ (GtkSourceView *view,
+ gboolean enable);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_insert_spaces_instead_of_tabs (GtkSourceView
*view);
+gboolean gtk_source_view_get_insert_spaces_instead_of_tabs
+ (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_indent_on_tab (GtkSourceView
*view,
- gboolean
enable);
+void gtk_source_view_set_indent_on_tab (GtkSourceView *view,
+ gboolean enable);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_indent_on_tab (GtkSourceView
*view);
+gboolean gtk_source_view_get_indent_on_tab (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_3_16
-void gtk_source_view_indent_lines (GtkSourceView
*view,
- GtkTextIter
*start,
- GtkTextIter
*end);
+void gtk_source_view_indent_lines (GtkSourceView *view,
+ GtkTextIter *start,
+ GtkTextIter *end);
+
GTK_SOURCE_AVAILABLE_IN_3_16
-void gtk_source_view_unindent_lines (GtkSourceView
*view,
- GtkTextIter
*start,
- GtkTextIter
*end);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_highlight_current_line (GtkSourceView
*view,
- gboolean
highlight);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_highlight_current_line (GtkSourceView
*view);
+void gtk_source_view_unindent_lines (GtkSourceView *view,
+ GtkTextIter *start,
+ GtkTextIter *end);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_show_right_margin (GtkSourceView
*view,
- gboolean
show);
+void gtk_source_view_set_highlight_current_line
+ (GtkSourceView *view,
+ gboolean highlight);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_show_right_margin (GtkSourceView
*view);
+gboolean gtk_source_view_get_highlight_current_line
+ (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_right_margin_position (GtkSourceView
*view,
- guint
pos);
+void gtk_source_view_set_show_right_margin (GtkSourceView *view,
+ gboolean show);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-guint gtk_source_view_get_right_margin_position (GtkSourceView
*view);
+gboolean gtk_source_view_get_show_right_margin (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_show_line_marks (GtkSourceView
*view,
- gboolean
show);
+void gtk_source_view_set_right_margin_position
+ (GtkSourceView *view,
+ guint pos);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean gtk_source_view_get_show_line_marks (GtkSourceView
*view);
+guint gtk_source_view_get_right_margin_position
+ (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_mark_attributes (GtkSourceView
*view,
- const gchar
*category,
- GtkSourceMarkAttributes
*attributes,
- gint
priority);
+void gtk_source_view_set_mark_attributes (GtkSourceView *view,
+ const gchar *category,
+ GtkSourceMarkAttributes *attributes,
+ gint priority);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMarkAttributes *gtk_source_view_get_mark_attributes (GtkSourceView
*view,
- const gchar
*category,
- gint
*priority);
+GtkSourceMarkAttributes *
+ gtk_source_view_get_mark_attributes (GtkSourceView *view,
+ const gchar *category,
+ gint *priority);
+
GTK_SOURCE_AVAILABLE_IN_3_18
-void gtk_source_view_set_smart_backspace (GtkSourceView
*view,
- gboolean
smart_backspace);
+void gtk_source_view_set_smart_backspace (GtkSourceView *view,
+ gboolean smart_backspace);
+
GTK_SOURCE_AVAILABLE_IN_3_18
-gboolean gtk_source_view_get_smart_backspace (GtkSourceView
*view);
+gboolean gtk_source_view_get_smart_backspace (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_view_set_smart_home_end (GtkSourceView
*view,
- GtkSourceSmartHomeEndType
smart_home_end);
+void gtk_source_view_set_smart_home_end (GtkSourceView *view,
+ GtkSourceSmartHomeEndType smart_home_end);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceSmartHomeEndType gtk_source_view_get_smart_home_end (GtkSourceView
*view);
+GtkSourceSmartHomeEndType
+ gtk_source_view_get_smart_home_end (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-guint gtk_source_view_get_visual_column (GtkSourceView
*view,
- const GtkTextIter
*iter);
+guint gtk_source_view_get_visual_column (GtkSourceView *view,
+ const GtkTextIter *iter);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceCompletion *gtk_source_view_get_completion (GtkSourceView
*view);
+GtkSourceCompletion *
+ gtk_source_view_get_completion (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutter *gtk_source_view_get_gutter (GtkSourceView
*view,
- GtkTextWindowType
window_type);
+GtkSourceGutter *gtk_source_view_get_gutter (GtkSourceView *view,
+ GtkTextWindowType window_type);
+
GTK_SOURCE_AVAILABLE_IN_3_16
-void gtk_source_view_set_background_pattern (GtkSourceView
*view,
-
GtkSourceBackgroundPatternType background_pattern);
+void gtk_source_view_set_background_pattern (GtkSourceView *view,
+ GtkSourceBackgroundPatternType background_pattern);
+
GTK_SOURCE_AVAILABLE_IN_3_16
-GtkSourceBackgroundPatternType gtk_source_view_get_background_pattern (GtkSourceView
*view);
+GtkSourceBackgroundPatternType
+ gtk_source_view_get_background_pattern (GtkSourceView *view);
+
GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceSpaceDrawer *gtk_source_view_get_space_drawer (GtkSourceView
*view);
+GtkSourceSpaceDrawer *
+ gtk_source_view_get_space_drawer (GtkSourceView *view);
G_END_DECLS
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index 3a1e99d3..f533a0f4 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -25,6 +25,7 @@ core_public_h = files([
'gtksourceinit.h',
'gtksourcelanguage.h',
'gtksourcelanguagemanager.h',
+ 'gtksourcelines.h',
'gtksourcemap.h',
'gtksourcemark.h',
'gtksourcemarkattributes.h',
@@ -41,7 +42,6 @@ core_public_h = files([
'gtksourcestyleschememanager.h',
'gtksourcetag.h',
'gtksourcetypes.h',
- 'gtksourceundomanager.h',
'gtksourceutils.h',
'gtksourceview.h',
])
@@ -65,6 +65,7 @@ core_public_c = files([
'gtksourceinit.c',
'gtksourcelanguage.c',
'gtksourcelanguagemanager.c',
+ 'gtksourcelines.c',
'gtksourcemap.c',
'gtksourcemark.c',
'gtksourcemarkattributes.c',
@@ -80,7 +81,6 @@ core_public_c = files([
'gtksourcestyleschemechooserwidget.c',
'gtksourcestyleschememanager.c',
'gtksourcetag.c',
- 'gtksourceundomanager.c',
'gtksourceutils.c',
'gtksourceversion.c',
'gtksourceview.c',
@@ -90,18 +90,16 @@ core_private_c = files([
'gtksourcebufferinputstream.c',
'gtksourcebufferinternal.c',
'gtksourcebufferoutputstream.c',
- 'gtksourcecompletioncontainer.c',
'gtksourcecompletionmodel.c',
'gtksourcecontextengine.c',
'gtksourceengine.c',
'gtksourcegutterrendererlines.c',
- 'gtksourcegutterrenderermarks.c',
+ # 'gtksourcegutterrenderermarks.c',
'gtksourceiter.c',
'gtksourcelanguage-parser-2.c',
'gtksourcemarkssequence.c',
'gtksourcepixbufhelper.c',
'gtksourceregex.c',
- 'gtksourceundomanagerdefault.c',
])
core_c_args = [
@@ -139,14 +137,14 @@ gtksourceview_include_dirs = [rootdir, gtksourceview_extra_include_dirs]
core_enums_header = '''
#if defined (GTK_SOURCE_COMPILATION) && defined (HAVE_CONFIG_H)
-# include <config.h>
+# include "config.h"
#endif
#if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
# error "Only <gtksourceview/gtksource.h> can be included directly."
#endif
-#include "gtksourceversion.h"
+#include <gtksourceview/gtksourceversion.h>
'''
core_enums = gnome.mkenums_simple('gtksource-enumtypes',
@@ -264,12 +262,12 @@ if generate_gir
identifier_prefix: 'GtkSource',
export_packages: [package_string],
link_with: gtksource_lib,
- includes: [ 'Gdk-3.0', 'Gtk-3.0' ],
+ includes: [ 'Gtk-4.0' ],
install: true,
install_dir_gir: girdir,
install_dir_typelib: typelibdir,
extra_args: [ '--c-include=gtksourceview/gtksource.h',
- '--warn-all' ],
+ '--warn-all' ],
)
gtksource_dep_sources += [
@@ -289,12 +287,11 @@ if generate_gir
install: true,
install_dir: vapidir,
packages: [ 'atk',
- 'gdk-3.0',
- 'gdk-pixbuf-2.0',
- 'gio-2.0',
- 'gtk+-3.0',
- 'pango',
- 'cairo' ],
+ 'gdk-pixbuf-2.0',
+ 'gio-2.0',
+ 'gtk4',
+ 'pango',
+ 'cairo' ],
)
endif
endif
@@ -311,7 +308,7 @@ gtksource_pc_reqs = [
'glib-2.0 @0@'.format(glib_req),
'gobject-2.0 @0@'.format(glib_req),
'gio-2.0 @0@'.format(glib_req),
- 'gtk+-3.0 @0@'.format(gtk_req),
+ 'gtk4 @0@'.format(gtk_req),
]
gtksource_pc_private_reqs = []
diff --git a/gtksourceview/quarkset-inline.h b/gtksourceview/quarkset-inline.h
new file mode 100644
index 00000000..c744c0a2
--- /dev/null
+++ b/gtksourceview/quarkset-inline.h
@@ -0,0 +1,185 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView 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.
+ *
+ * GtkSourceView 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/>.
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _QuarkSet
+{
+ gint32 len;
+ union {
+ GQuark embed[2];
+ GQuark *alloc;
+ } u;
+} QuarkSet;
+
+static inline gboolean
+quark_set_is_embed (QuarkSet *set)
+{
+ return set->len >= 0;
+}
+
+static inline void
+quark_set_clear (QuarkSet *set)
+{
+ if (set->len < 0)
+ {
+ g_free (set->u.alloc);
+ }
+
+ set->len = 0;
+ set->u.alloc = NULL;
+}
+
+static inline gboolean
+quark_set_contains (QuarkSet *set,
+ GQuark quark)
+{
+ GQuark *quarks;
+ guint i;
+ guint len;
+
+ if (set->len == 0)
+ {
+ return FALSE;
+ }
+
+ if (quark_set_is_embed (set))
+ {
+ quarks = set->u.embed;
+ len = set->len;
+ }
+ else
+ {
+ quarks = set->u.alloc;
+ len = ABS (set->len);
+ }
+
+ for (i = 0; i < len; i++)
+ {
+ if (quarks[i] == quark)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static inline void
+quark_set_add (QuarkSet *set,
+ GQuark quark)
+{
+ if (quark_set_contains (set, quark))
+ {
+ return;
+ }
+
+ if G_LIKELY (set->len == 0 || set->len == 1)
+ {
+ G_STATIC_ASSERT (G_N_ELEMENTS (set->u.embed) == 2);
+
+ set->u.embed[set->len++] = quark;
+ }
+ else if (set->len == G_N_ELEMENTS (set->u.embed))
+ {
+ GQuark *alloc = g_new (GQuark, set->len + 1);
+ guint i;
+
+ for (i = 0; i < set->len; i++)
+ {
+ alloc[i] = set->u.embed[i];
+ }
+
+ alloc[set->len] = quark;
+ set->len = -(set->len + 1);
+ set->u.alloc = alloc;
+ }
+ else if (set->len < 0)
+ {
+ guint len = ABS (set->len);
+
+ set->u.alloc = g_realloc_n (set->u.alloc, len + 1, sizeof (GQuark));
+ set->u.alloc[len] = quark;
+ set->len--; /* = -(len + 1) */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+}
+
+static inline void
+quark_set_remove (QuarkSet *set,
+ GQuark quark)
+{
+ if (set->len == 0)
+ {
+ return;
+ }
+ else if (set->len == -1 && set->u.alloc[0] == quark)
+ {
+ quark_set_clear (set);
+ return;
+ }
+ else if (set->len > 0)
+ {
+ G_STATIC_ASSERT (G_N_ELEMENTS (set->u.embed) == 2);
+
+ if (set->u.embed[0] == quark)
+ {
+ set->u.embed[0] = set->u.embed[1];
+ set->len--;
+ }
+ else if (set->u.embed[1] == quark)
+ {
+ set->len--;
+ }
+ }
+ else if (set->len < 0)
+ {
+ guint len = ABS (set->len);
+ guint i;
+
+ for (i = 0; i < len; i++)
+ {
+ if (set->u.alloc[i] == quark)
+ {
+ if (i + 1 < len)
+ {
+ set->u.alloc[i] = set->u.alloc[len - 1];
+ }
+
+ set->len++; /* = -(len - 1) */
+
+ break;
+ }
+ }
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+}
+
+G_END_DECLS
diff --git a/meson.build b/meson.build
index 8574775d..73cf063c 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,5 @@
project('gtksourceview', 'c',
- version: '4.99.0',
+ version: '4.90.0',
license: 'LGPL-2.1-or-later',
meson_version: '>= 0.50.0',
default_options: [ 'c_std=gnu11',
@@ -64,7 +64,7 @@ build_gtk_doc = get_option('gtk_doc')
# Dependencies
cc = meson.get_compiler('c')
-glib_req_version = '2.48'
+glib_req_version = '2.62'
gtk_req_version = '3.96'
libm_dep = cc.find_library('m', required: false)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5fe44fe0..a1f7b9bf 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -39,6 +39,5 @@ gtksourceview/gtksourcestylescheme.c
gtksourceview/gtksourcestyleschemechooserbutton.c
gtksourceview/gtksourcestyleschememanager.c
gtksourceview/gtksourcetag.c
-gtksourceview/gtksourceundomanagerdefault.c
gtksourceview/gtksourceutils.c
gtksourceview/gtksourceview.c
diff --git a/tests/meson.build b/tests/meson.build
index eb078ee8..a33e8228 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -9,7 +9,6 @@ tests_sources = {
'search': ['test-search.c'],
'search-performances': ['test-search-performances.c'],
'space-drawing': ['test-space-drawing.c'],
- 'undo-manager-performances': ['test-undo-manager-performances.c'],
'widget': ['test-widget.c'],
}
diff --git a/tests/test-completion.c b/tests/test-completion.c
index 6830d904..669a6398 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -37,9 +37,9 @@ struct _TestProvider
gint priority;
gchar *name;
- GdkPixbuf *provider_icon;
+ GdkPaintable *provider_icon;
- GdkPixbuf *item_icon;
+ GdkPaintable *item_icon;
GIcon *item_gicon;
/* If it's a random provider, a subset of 'proposals' are choosen on
@@ -115,9 +115,14 @@ test_provider_populate (GtkSourceCompletionProvider *completion_provider,
static GdkPixbuf *
test_provider_get_icon (GtkSourceCompletionProvider *provider)
{
+#if 0
TestProvider *tp = (TestProvider *)provider;
return tp->is_random ? NULL : tp->provider_icon;
+#else
+ /* TODO: Switch to texture API */
+ return NULL;
+#endif
}
static void
@@ -199,7 +204,7 @@ test_provider_set_fixed (TestProvider *provider,
item = gtk_source_completion_item_new ();
gtk_source_completion_item_set_markup (item, "A very <b>long</b> proposal. I <i>repeat</i>, a very
long proposal!");
gtk_source_completion_item_set_text (item, "A very long proposal. I repeat, a very long proposal!");
- gtk_source_completion_item_set_icon (item, provider->item_icon);
+ /* gtk_source_completion_item_set_icon (item, provider->item_icon); */
gtk_source_completion_item_set_info (item, "To test the horizontal scrollbar and the markup.");
proposals = g_list_prepend (proposals, item);
@@ -222,7 +227,7 @@ test_provider_set_fixed (TestProvider *provider,
item = gtk_source_completion_item_new ();
gtk_source_completion_item_set_label (item, name);
gtk_source_completion_item_set_text (item, name);
- gtk_source_completion_item_set_icon (item, provider->item_icon);
+ /* gtk_source_completion_item_set_icon (item, provider->item_icon); */
gtk_source_completion_item_set_info (item, "The extra info of the proposal.\nA second line.");
proposals = g_list_prepend (proposals, item);
@@ -251,7 +256,7 @@ test_provider_set_random (TestProvider *provider,
item = gtk_source_completion_item_new ();
gtk_source_completion_item_set_label (item, name);
gtk_source_completion_item_set_text (item, name);
- gtk_source_completion_item_set_icon (item, provider->item_icon);
+ /* gtk_source_completion_item_set_icon (item, provider->item_icon); */
proposals = g_list_prepend (proposals, item);
g_free (padding);
@@ -454,9 +459,10 @@ create_window (void)
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- gtk_init (&argc, &argv);
+ gtk_init ();
create_window ();
diff --git a/tests/test-completion.ui b/tests/test-completion.ui
index 41375079..a3f3f515 100644
--- a/tests/test-completion.ui
+++ b/tests/test-completion.ui
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.0 -->
- <!-- interface-requires gtksourceview 3.0 -->
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100000</property>
<property name="value">3</property>
@@ -15,329 +13,236 @@
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="window">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="visible">1</property>
<child>
<object class="GtkGrid" id="grid1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">6</property>
+ <property name="margin">6</property>
<property name="column_spacing">10</property>
<child>
<object class="GtkGrid" id="grid2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="row_spacing">5</property>
<child>
<object class="GtkGrid" id="grid3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="margin_start">10</property>
<child>
<object class="GtkCheckButton" id="checkbutton_remember_info_visibility">
<property name="label">Remember info visibility</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_select_on_show">
<property name="label">Select first on show</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_show_headers">
<property name="label">Show headers</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_show_icons">
<property name="label">Show icons</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Providers</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">General options</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="margin_start">10</property>
<child>
<object class="GtkCheckButton" id="checkbutton_word_provider">
<property name="label">Word provider</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <property name="active">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_fixed_provider">
<property name="label">Fixed provider</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <property name="active">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_random_provider">
<property name="label">Random provider</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <property name="active">1</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Fixed provider proposals</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid5">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="margin_start">10</property>
<child>
<object class="GtkGrid" id="grid6">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkLabel" id="label4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="label">Number of proposals:</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton_nb_fixed_proposals">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">1</property>
<property name="text" translatable="yes">3</property>
<property name="adjustment">adjustment1</property>
<property name="value">3</property>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">5</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label5">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Random provider proposals</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">6</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">6</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid7">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="margin_start">10</property>
<property name="column_spacing">5</property>
<child>
<object class="GtkLabel" id="label6">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="label">Max number of proposals:</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton_nb_random_proposals">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">1</property>
<property name="adjustment">adjustment2</property>
<property name="value">10</property>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">7</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">7</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="width_request">600</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">1</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkSourceView" id="source_view">
@@ -354,20 +259,18 @@
<property name="remember_info_visibility">True</property>
<child internal-child="info_window">
<object class="GtkSourceCompletionInfo">
- <property name="border_width">3</property>
+ <property name="margin">3</property>
</object>
</child>
</object>
</child>
</object>
</child>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
</object>
</child>
diff --git a/tests/test-search-performances.c b/tests/test-search-performances.c
index 7c68323a..f2a08b36 100644
--- a/tests/test-search-performances.c
+++ b/tests/test-search-performances.c
@@ -58,7 +58,7 @@ main (int argc, char *argv[])
GtkTextSearchFlags flags;
gchar *regex_pattern;
- gtk_init (&argc, &argv);
+ gtk_init ();
buffer = gtk_source_buffer_new (NULL);
diff --git a/tests/test-search.c b/tests/test-search.c
index 75ae96de..e59eed4a 100644
--- a/tests/test-search.c
+++ b/tests/test-search.c
@@ -154,7 +154,7 @@ static void
search_entry_changed_cb (TestSearch *search,
GtkEntry *entry)
{
- const gchar *text = gtk_entry_get_text (entry);
+ const gchar *text = gtk_editable_get_text (GTK_EDITABLE (entry));
gchar *unescaped_text = gtk_source_utils_unescape_search_text (text);
gtk_source_search_settings_set_search_text (search->priv->search_settings, unescaped_text);
@@ -270,7 +270,7 @@ button_replace_clicked_cb (TestSearch *search,
gtk_source_search_context_replace (search->priv->search_context,
&match_start,
&match_end,
- gtk_entry_get_text (search->priv->replace_entry),
+ gtk_editable_get_text (GTK_EDITABLE (search->priv->replace_entry)),
replace_length,
NULL);
@@ -293,7 +293,7 @@ button_replace_all_clicked_cb (TestSearch *search,
gint replace_length = gtk_entry_buffer_get_bytes (entry_buffer);
gtk_source_search_context_replace_all (search->priv->search_context,
- gtk_entry_get_text (search->priv->replace_entry),
+ gtk_editable_get_text (GTK_EDITABLE
(search->priv->replace_entry)),
replace_length,
NULL);
}
@@ -462,7 +462,7 @@ main (gint argc, gchar *argv[])
GtkWidget *window;
TestSearch *search;
- gtk_init (&argc, &argv);
+ gtk_init ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/tests/test-search.ui b/tests/test-search.ui
index b822e960..fd63ca77 100644
--- a/tests/test-search.ui
+++ b/tests/test-search.ui
@@ -1,40 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.10 -->
- <!-- interface-requires gtksourceview 3.0 -->
<object class="GtkImage" id="image1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">go-up</property>
<property name="icon_size">1</property>
</object>
<object class="GtkImage" id="image2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">go-down</property>
<property name="icon_size">1</property>
</object>
<object class="GtkImage" id="image3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">edit-find-replace</property>
<property name="icon_size">1</property>
</object>
<object class="GtkImage" id="image4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">edit-find-replace</property>
<property name="icon_size">1</property>
</object>
<template class="TestSearch" parent="GtkGrid">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">6</property>
+ <property name="margin">6</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">1</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkSourceView" id="source_view">
@@ -48,298 +35,228 @@
<property name="monospace">True</property>
</object>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Search:</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="width_request">300</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">1</property>
<property name="halign">start</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<signal name="changed" handler="search_entry_changed_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label_occurrences">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">0 occurrences</property>
+ <layout>
+ <property name="left_attach">4</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">4</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="button_previous">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can_focus">1</property>
+ <property name="receives_default">1</property>
<property name="halign">start</property>
<property name="image">image1</property>
<signal name="clicked" handler="button_previous_clicked_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">2</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="button_next">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can_focus">1</property>
+ <property name="receives_default">1</property>
<property name="halign">start</property>
<property name="image">image2</property>
<signal name="clicked" handler="button_next_clicked_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">3</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">3</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label_regex_error">
- <property name="can_focus">False</property>
+ <property name="visible">0</property>
<property name="halign">start</property>
<property name="label">Regex search error</property>
- <property name="wrap">True</property>
- <property name="selectable">True</property>
+ <property name="wrap">1</property>
+ <property name="selectable">1</property>
<property name="max_width_chars">72</property>
<attributes>
- <attribute name="foreground" value="#cccc00000000"/>
+ <attribute name="foreground" value="#cccc00000000"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="column-span">4</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">4</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<placeholder/>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="checkbutton_match_case">
<property name="label">Match case</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
<signal name="toggled" handler="match_case_toggled_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_at_word_boundaries">
<property name="label">At word boundaries</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
<signal name="toggled" handler="at_word_boundaries_toggled_cb" object="TestSearch"
swapped="yes"/>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_wrap_around">
<property name="label">Wrap around</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
<signal name="toggled" handler="wrap_around_toggled_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_highlight">
<property name="label">Highlight search occurrences</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
+ <property name="active">1</property>
<signal name="toggled" handler="highlight_toggled_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_regex">
<property name="label">Regex</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can_focus">1</property>
<signal name="toggled" handler="regex_toggled_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Replace:</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkEntry" id="replace_entry">
<property name="width_request">300</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">1</property>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="button_replace">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can_focus">1</property>
+ <property name="receives_default">1</property>
<property name="image">image3</property>
<signal name="clicked" handler="button_replace_clicked_cb" object="TestSearch" swapped="yes"/>
+ <layout>
+ <property name="left_attach">2</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="button_replace_all">
<property name="label">All</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can_focus">1</property>
+ <property name="receives_default">1</property>
<property name="image">image4</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="button_replace_all_clicked_cb" object="TestSearch"
swapped="yes"/>
+ <layout>
+ <property name="left_attach">3</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">3</property>
- <property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
</child>
</template>
</interface>
diff --git a/tests/test-space-drawing.c b/tests/test-space-drawing.c
index e6940348..d5f734fd 100644
--- a/tests/test-space-drawing.c
+++ b/tests/test-space-drawing.c
@@ -141,14 +141,14 @@ create_window (void)
gtk_container_add (GTK_CONTAINER (window), hgrid);
- gtk_widget_show_all (window);
+ gtk_window_present (GTK_WINDOW (window));
}
gint
main (gint argc,
gchar **argv)
{
- gtk_init (&argc, &argv);
+ gtk_init ();
create_window ();
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 5ca68c8a..be0df572 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -61,6 +61,7 @@ struct _TestWidgetPrivate
GtkLabel *cursor_position_info;
GtkSourceStyleSchemeChooserButton *chooser_button;
GtkComboBoxText *background_pattern;
+ GtkWidget *top;
};
GType test_widget_get_type (void);
@@ -183,7 +184,7 @@ print_language_style_ids (GtkSourceLanguage *language)
{
gchar **styles;
- g_assert_nonnull (language);
+ g_assert (language != NULL);
styles = gtk_source_language_get_style_ids (language);
@@ -295,8 +296,10 @@ static void
show_line_marks_toggled_cb (TestWidget *self,
GtkCheckButton *button)
{
+#if 0
gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
gtk_source_view_set_show_line_marks (self->priv->view, enabled);
+#endif
}
static void
@@ -472,7 +475,7 @@ open_button_clicked_cb (TestWidget *self)
gint response;
static gchar *last_dir;
- main_window = gtk_widget_get_toplevel (GTK_WIDGET (self->priv->view));
+ main_window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (self->priv->view)));
chooser = gtk_file_chooser_dialog_new ("Open file...",
GTK_WINDOW (main_window),
@@ -543,7 +546,7 @@ paginate (GtkPrintOperation *operation,
{
gint n_pages;
- g_assert_cmpint (gtk_source_print_compositor_get_pagination_progress (compositor), ==, 1.0);
+ g_assert (gtk_source_print_compositor_get_pagination_progress (compositor) == 1.0);
g_print ("Pagination progress: %.2f %%\n",
gtk_source_print_compositor_get_pagination_progress (compositor) * 100.0);
n_pages = gtk_source_print_compositor_get_n_pages (compositor);
@@ -779,6 +782,7 @@ mark_set_cb (GtkTextBuffer *buffer,
}
}
+#if 0
static void
line_mark_activated_cb (GtkSourceGutter *gutter,
GtkTextIter *iter,
@@ -812,6 +816,7 @@ line_mark_activated_cb (GtkSourceGutter *gutter,
g_slist_free (mark_list);
}
+#endif
static void
bracket_matched_cb (GtkSourceBuffer *buffer,
@@ -980,15 +985,21 @@ test_widget_class_init (TestWidgetClass *klass)
static void
show_top_border_window_toggled_cb (GtkToggleButton *checkbutton,
- TestWidget *self)
+ TestWidget *self)
{
gint size;
size = gtk_toggle_button_get_active (checkbutton) ? 20 : 0;
- gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (self->priv->view),
- GTK_TEXT_WINDOW_TOP,
- size);
+ if (self->priv->top == NULL)
+ {
+ self->priv->top = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_text_view_set_gutter (GTK_TEXT_VIEW (self->priv->view),
+ GTK_TEXT_WINDOW_TOP,
+ GTK_WIDGET (self->priv->top));
+ }
+
+ gtk_widget_set_size_request (self->priv->top, -1, size);
}
static void
@@ -1037,10 +1048,12 @@ test_widget_init (TestWidget *self)
add_source_mark_attributes (self->priv->view);
+#if 0
g_signal_connect (self->priv->view,
"line-mark-activated",
G_CALLBACK (line_mark_activated_cb),
self);
+#endif
g_object_bind_property (self->priv->chooser_button,
"style-scheme",
@@ -1085,7 +1098,7 @@ main (int argc, char *argv[])
GtkWidget *window;
TestWidget *test_widget;
- gtk_init (&argc, &argv);
+ gtk_init ();
gtk_source_init ();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/tests/test-widget.ui b/tests/test-widget.ui
index 150e5e3a..834e0c1d 100644
--- a/tests/test-widget.ui
+++ b/tests/test-widget.ui
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.19.0 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<requires lib="gtksourceview" version="3.0"/>
@@ -24,239 +23,178 @@
<property name="page_increment">10</property>
</object>
<template class="TestWidget" parent="GtkGrid">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="border_width">6</property>
+ <property name="margin">6</property>
<property name="column_spacing">4</property>
<child>
<object class="GtkGrid" id="grid2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="row_spacing">2</property>
<child>
<object class="GtkButton" id="open_button">
<property name="label">Open File</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">1</property>
+ <property name="receives_default">1</property>
<signal name="clicked" handler="open_button_clicked_cb" object="TestWidget" swapped="yes"/>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="print_button">
<property name="label">Print</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">1</property>
+ <property name="receives_default">1</property>
<signal name="clicked" handler="print_button_clicked_cb" object="TestWidget" swapped="yes"/>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">General options</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="top-attach">3</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="highlight_matching_bracket">
<property name="label">Highlight matching bracket</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <property name="active">1</property>
<signal name="toggled" handler="highlight_matching_bracket_toggled_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="top-attach">1</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="show_line_numbers">
<property name="label">Show line numbers</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="show_line_numbers_toggled_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="top-attach">2</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="show_line_marks">
<property name="label">Show line marks</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="show_line_marks_toggled_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="top-attach">3</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="show_right_margin">
<property name="label">Show right margin</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="show_right_margin_toggled_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="top-attach">5</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">5</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid9">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">4</property>
<child>
<object class="GtkLabel" id="label6">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="label">Right margin position:</property>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkSpinButton" id="right_margin_position">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can-focus">1</property>
<property name="adjustment">adjustment_right_margin</property>
<property name="value">80</property>
<signal name="value-changed" handler="right_margin_position_value_changed_cb"
object="TestWidget" swapped="yes"/>
+ <layout>
+ <property name="left-attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">6</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">6</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="show_map_checkbutton">
<property name="label">Show source map</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <layout>
+ <property name="top-attach">7</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">7</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="highlight_current_line">
<property name="label">Highlight current line</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="highlight_current_line_toggled_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="top-attach">8</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">8</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="wrap_lines">
<property name="label">Wrap lines</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="wrap_lines_toggled_cb" object="TestWidget" swapped="yes"/>
+ <layout>
+ <property name="top-attach">9</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">9</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="draw_spaces_checkbutton">
<property name="label">Draw Spaces</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <layout>
+ <property name="top-attach">10</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">10</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="smart_backspace_checkbutton">
<property name="label">Smart Backspace</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <layout>
+ <property name="top-attach">11</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">11</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid8">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">3</property>
<child>
<object class="GtkLabel" id="label5">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="label">Smart home/end:</property>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkComboBoxText" id="smart_home_end">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="active">0</property>
<items>
<item id="0">Disabled</item>
@@ -265,335 +203,259 @@
<item id="3">Always</item>
</items>
<signal name="changed" handler="smart_home_end_changed_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="left-attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">12</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">12</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid10">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
+ <layout>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </layout>
<child>
<object class="GtkCheckButton" id="highlight_syntax">
<property name="label">Highlight syntax</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <property name="active">1</property>
<signal name="toggled" handler="highlight_syntax_toggled_cb" object="TestWidget"
swapped="yes"/>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkSourceStyleSchemeChooserButton" id="chooser_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkComboBoxText" id="background_pattern">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="active">0</property>
<items>
<item translatable="yes">None</item>
<item translatable="yes">Grid</item>
</items>
+ <layout>
+ <property name="left-attach">2</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">0</property>
- </packing>
</child>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="show_top_border_window_checkbutton">
<property name="label">Show top border window</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="xalign">0</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <property name="halign">start</property>
+ <layout>
+ <property name="top-attach">4</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">4</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">4</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">4</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Indentation</property>
<attributes>
- <attribute name="weight" value="bold"/>
+ <attribute name="weight" value="bold"></attribute>
</attributes>
+ <layout>
+ <property name="top-attach">5</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">5</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="auto_indent">
<property name="label">Auto indent</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="auto_indent_toggled_cb" object="TestWidget" swapped="yes"/>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="indent_spaces">
<property name="label">Insert spaces instead of tabs</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
<signal name="toggled" handler="indent_spaces_toggled_cb" object="TestWidget" swapped="yes"/>
+ <layout>
+ <property name="top-attach">1</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid5">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">4</property>
<child>
<object class="GtkLabel" id="label3">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="label">Tab width:</property>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkSpinButton" id="tab_width">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can-focus">1</property>
<property name="adjustment">adjustment_tab_width</property>
<property name="value">8</property>
<signal name="value-changed" handler="tab_width_value_changed_cb" object="TestWidget"
swapped="yes"/>
+ <layout>
+ <property name="left-attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">2</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid6">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">4</property>
<child>
<object class="GtkSpinButton" id="indent_width_spinbutton">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can-focus">1</property>
<property name="adjustment">adjustment_indent_width</property>
<property name="value">8</property>
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkCheckButton" id="indent_width_checkbutton">
<property name="label">Different indent width:</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="draw_indicator">True</property>
+ <property name="can-focus">1</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">3</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">3</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">6</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">6</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid7">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="column_spacing">3</property>
<child>
<object class="GtkLabel" id="label4">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="label">String toggle:</property>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="backward_string">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">1</property>
+ <property name="receives_default">1</property>
<signal name="clicked" handler="backward_string_clicked_cb" object="TestWidget"
swapped="yes"/>
<child>
<object class="GtkImage" id="image1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">go-previous</property>
</object>
</child>
+ <layout>
+ <property name="left-attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="forward_string">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">1</property>
+ <property name="receives_default">1</property>
<signal name="clicked" handler="forward_string_clicked_cb" object="TestWidget"
swapped="yes"/>
<child>
<object class="GtkImage" id="image2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="icon_name">go-next</property>
</object>
</child>
+ <layout>
+ <property name="left-attach">2</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">2</property>
- <property name="top_attach">0</property>
- </packing>
</child>
+ <layout>
+ <property name="top-attach">2</property>
+ <property name="left-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">2</property>
- </packing>
</child>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkGrid" id="grid1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="row_spacing">3</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="width_request">400</property>
<property name="height_request">400</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can-focus">1</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkSourceView" id="view">
<property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <property name="left_margin">2</property>
- <property name="right_margin">2</property>
<property name="monospace">True</property>
</object>
</child>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkSourceMap" id="map">
<property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can_focus">False</property>
<property name="view">view</property>
+ <layout>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
<child>
<object class="GtkLabel" id="cursor_position_info">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label">Cursor position info</property>
+ <layout>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
</child>
+ <layout>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </layout>
</object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">0</property>
- </packing>
</child>
</template>
</interface>
diff --git a/testsuite/meson.build b/testsuite/meson.build
index f842a07a..8fac92c9 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -32,7 +32,6 @@ testsuite_sources = [
['test-space-drawer'],
['test-stylescheme'],
['test-styleschememanager'],
- ['test-undo-manager'],
['test-utils'],
['test-view'],
]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]