[gtksourceview] Change gtk_source_gutter_insert() function prototype.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Change gtk_source_gutter_insert() function prototype.
- Date: Sat, 11 Dec 2010 18:21:13 +0000 (UTC)
commit 334cd070e48be11cea007a2b43fb7da89c39654e
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Tue Dec 7 21:37:42 2010 +0100
Change gtk_source_gutter_insert() function prototype.
gtksourceview/Makefile.am | 33 ++--
gtksourceview/gtksourcegutter.c | 222 +++--------------------
gtksourceview/gtksourcegutter.h | 21 +--
gtksourceview/gtksourcegutterrenderer-private.h | 43 +++++
gtksourceview/gtksourcegutterrenderer.c | 28 +++-
gtksourceview/gtksourceview.c | 40 +++--
6 files changed, 139 insertions(+), 248 deletions(-)
---
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index d7f080f..b0cc83c 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -44,22 +44,23 @@ libgtksourceview_headers = \
gtksourceview.h
NOINST_H_FILES = \
- gtksourcecompletionmodel.h \
- gtksourcecompletion-private.h \
- gtksourcecompletionui.h \
- gtksourcecompletionutils.h \
- gtksourcecontextengine.h \
- gtksourceengine.h \
- gtksourcegutter-private.h \
- gtksourcelanguage-private.h \
- gtksourcestyle-private.h \
- gtksourceundomanagerdefault.h \
- gtksourceview-i18n.h \
- gtksourceview-utils.h \
- gtktextregion.h \
- gtksourcepixbufhelper.h \
- gtksourcegutterrendererlines.h \
- gtksourcegutterrenderermarks.h
+ gtksourcecompletionmodel.h \
+ gtksourcecompletion-private.h \
+ gtksourcecompletionui.h \
+ gtksourcecompletionutils.h \
+ gtksourcecontextengine.h \
+ gtksourceengine.h \
+ gtksourcegutter-private.h \
+ gtksourcelanguage-private.h \
+ gtksourcestyle-private.h \
+ gtksourceundomanagerdefault.h \
+ gtksourceview-i18n.h \
+ gtksourceview-utils.h \
+ gtktextregion.h \
+ gtksourcepixbufhelper.h \
+ gtksourcegutterrendererlines.h \
+ gtksourcegutterrenderermarks.h \
+ gtksourcegutterrenderer-private.h
libgtksourceview_c_files = \
gtksourcebuffer.c \
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index 26e76c9..86f7754 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -24,6 +24,7 @@
#include "gtksourceview-i18n.h"
#include "gtksourceview-marshal.h"
#include "gtksourcegutterrenderer.h"
+#include "gtksourcegutterrenderer-private.h"
#include <gobject/gvaluecollector.h>
@@ -160,23 +161,19 @@ on_renderer_notify_padding (GtkSourceGutterRenderer *renderer,
static Renderer *
renderer_new (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- guint num_parameters,
- GParameter *parameters)
+ GtkSourceGutterRenderer *renderer,
+ gint position)
{
Renderer *ret = g_slice_new0 (Renderer);
- ret->renderer = g_object_newv (gtype, num_parameters, parameters);
-
- if (G_IS_INITIALLY_UNOWNED (ret->renderer))
- {
- g_object_ref_sink (ret->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->priv->view),
+ gutter->priv->window_type);
+
ret->size_changed_handler =
g_signal_connect (ret->renderer,
"notify::size",
@@ -219,6 +216,7 @@ renderer_free (Renderer *renderer)
g_signal_handler_disconnect (renderer->renderer,
renderer->notify_ypad_handler);
+ _gtk_source_gutter_renderer_unset_view (renderer->renderer);
g_object_unref (renderer->renderer);
g_slice_free (Renderer, renderer);
}
@@ -634,195 +632,35 @@ gtk_source_gutter_get_window (GtkSourceGutter *gutter)
/**
* gtk_source_gutter_insert:
* @gutter: a #GtkSourceGutter.
- * @gtype: the type of the gutter renderer (must inherit from #GtkSourceGutterRenderer).
- * @position: the renderers position.
- *
- * Inserts @renderer into @gutter at @position.
- *
- * Since: 3.0
- *
- * Returns: (transfer none): a #GtkSourceGutterRenderer
- */
-GtkSourceGutterRenderer *
-gtk_source_gutter_insert (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- ...)
-{
- va_list ap;
- GtkSourceGutterRenderer *ret;
-
- g_return_val_if_fail (GTK_IS_SOURCE_GUTTER (gutter), NULL);
- g_return_val_if_fail (g_type_is_a (gtype, GTK_TYPE_SOURCE_GUTTER_RENDERER), NULL);
-
- va_start (ap, position);
- ret = gtk_source_gutter_insert_valist (gutter, gtype, position, ap);
- va_end (ap);
-
- return ret;
-}
-
-/**
- * gtk_source_gutter_insert_valist:
- * @gutter: a #GtkSourceGutter.
- * @gtype: the type of the gutter renderer (must inherit from #GtkSourceGutterRenderer).
+ * @renderer: a gutter renderer (must inherit from #GtkSourceGutterRenderer).
* @position: the renderer position.
- * @ap: the parameters.
- *
- * Create and insert a new gutter renderer in the gutter. This function is
- * mostly useful for bindings. Applications should normally use
- * #gtk_source_gutter_renderer_insert
*
- * Since: 3.0
+ * Insert @renderer into the gutter. If @renderer is yet unowned then gutter
+ * claims its ownership. Otherwise just increases renderer's reference count.
+ * @renderer cannot be already inserted to another gutter.
*
- * Returns: (transfer none): a #GtkSourceGutterRenderer
- *
- **/
-GtkSourceGutterRenderer *
-gtk_source_gutter_insert_valist (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- va_list ap)
-{
- const gchar *name;
- GArray *parameters;
- GObjectClass *klass;
- GParameter *params;
- guint num_parameters;
- GtkSourceGutterRenderer *ret;
- guint i;
-
- g_return_val_if_fail (GTK_IS_SOURCE_GUTTER (gutter), NULL);
- g_return_val_if_fail (g_type_is_a (gtype, GTK_TYPE_SOURCE_GUTTER_RENDERER), NULL);
-
- parameters = g_array_new (FALSE, TRUE, sizeof (GParameter));
- klass = g_type_class_ref (gtype);
-
- num_parameters = 0;
-
- while ((name = va_arg (ap, const gchar *)) != NULL)
- {
- GParameter parameter;
- GParamSpec *spec;
- gchar *error = NULL;
-
- spec = g_object_class_find_property (klass, name);
-
- if (!spec)
- {
- g_warning ("%s: object class `%s' has no property named `%s'",
- G_STRFUNC,
- g_type_name (gtype),
- name);
-
- break;
- }
-
- parameter.name = name;
-
- G_VALUE_COLLECT_INIT (¶meter.value,
- spec->value_type,
- ap,
- 0,
- &error);
-
- if (error)
- {
- g_warning ("%s: %s", G_STRFUNC, error);
- g_free (error);
- g_value_unset (¶meter.value);
-
- break;
- }
-
- g_array_append_val (parameters, parameter);
- ++num_parameters;
- }
-
- params = (GParameter *)g_array_free (parameters, FALSE);
-
- ret = gtk_source_gutter_insertv (gutter,
- gtype,
- position,
- num_parameters,
- params);
-
- for (i = 0; i < num_parameters; ++i)
- {
- g_value_unset (¶ms[i].value);
- }
-
- g_free (params);
-
- return ret;
-}
-
-/**
- * gtk_source_gutter_insertv:
- * @gutter: a #GtkSourceGutter.
- * @gtype: the type of the gutter renderer (must inherit from #GtkSourceGutterRenderer).
- * @position: the renderer position.
- * @num_parameters: the number of parameters.
- * @parameters: the parameters.
- *
- * Create and insert a new gutter renderer in the gutter. This function is
- * mostly useful for bindings. Applications should normally use
- * #gtk_source_gutter_renderer_insert
+ * Returns: %TRUE if operation succeeded. Otherwise %FALSE.
*
* Since: 3.0
*
- * Returns: (transfer none): a #GtkSourceGutterRenderer
- *
**/
-GtkSourceGutterRenderer *
-gtk_source_gutter_insertv (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- guint num_parameters,
- GParameter *parameters)
-{
- GParameter *extended;
- guint i;
- gint len;
- GValue *view;
- GValue *window_type;
- Renderer *renderer;
-
- g_return_val_if_fail (GTK_IS_SOURCE_GUTTER (gutter), NULL);
- g_return_val_if_fail (g_type_is_a (gtype, GTK_TYPE_SOURCE_GUTTER_RENDERER), NULL);
-
- len = sizeof (GParameter) * (num_parameters + 2);
- extended = g_slice_alloc0 (len);
- for (i = 0; i < num_parameters; ++i)
- {
- extended[i] = parameters[i];
- }
-
- extended[num_parameters].name = "view";
- view = &(extended[num_parameters].value);
- g_value_init (view, GTK_TYPE_TEXT_VIEW);
- g_value_set_object (view, gutter->priv->view);
-
- extended[num_parameters + 1].name = "window-type";
- window_type = &(extended[num_parameters + 1].value);
- g_value_init (window_type, GTK_TYPE_TEXT_WINDOW_TYPE);
- g_value_set_enum (window_type, gutter->priv->window_type);
-
- renderer = renderer_new (gutter,
- gtype,
- position,
- num_parameters + 2,
- extended);
-
- append_renderer (gutter, renderer);
+gboolean
+gtk_source_gutter_insert (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer,
+ gint position)
+{
+ Renderer* internal_renderer;
- g_value_unset (view);
- g_value_unset (window_type);
+ g_return_val_if_fail (GTK_IS_SOURCE_GUTTER (gutter), FALSE);
+ g_return_val_if_fail (GTK_IS_SOURCE_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);
- g_slice_free1 (len, extended);
+ internal_renderer = renderer_new (gutter, renderer, position);
+ append_renderer (gutter, internal_renderer);
- return renderer->renderer;
+ return TRUE;
}
static gboolean
@@ -875,7 +713,7 @@ gtk_source_gutter_reorder (GtkSourceGutter *gutter,
if (renderer_find (gutter, renderer, &ret, &retlist))
{
gutter->priv->renderers =
- g_list_remove_link (gutter->priv->renderers,
+ g_list_delete_link (gutter->priv->renderers,
retlist);
ret->position = position;
@@ -905,11 +743,9 @@ gtk_source_gutter_remove (GtkSourceGutter *gutter,
if (renderer_find (gutter, renderer, &ret, &retlist))
{
gutter->priv->renderers =
- g_list_remove_link (gutter->priv->renderers,
+ g_list_delete_link (gutter->priv->renderers,
retlist);
- g_object_set (ret->renderer, "view", NULL, NULL);
-
update_gutter_size (gutter);
renderer_free (ret);
}
diff --git a/gtksourceview/gtksourcegutter.h b/gtksourceview/gtksourcegutter.h
index 0b4beec..0b0a346 100644
--- a/gtksourceview/gtksourcegutter.h
+++ b/gtksourceview/gtksourcegutter.h
@@ -57,24 +57,9 @@ GType gtk_source_gutter_get_type (void) G_GNUC_CONST;
GdkWindow *gtk_source_gutter_get_window (GtkSourceGutter *gutter);
-GtkSourceGutterRenderer *
- gtk_source_gutter_insert (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- ...) G_GNUC_NULL_TERMINATED;
-
-GtkSourceGutterRenderer *
- gtk_source_gutter_insert_valist (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- va_list ap);
-
-GtkSourceGutterRenderer *
- gtk_source_gutter_insertv (GtkSourceGutter *gutter,
- GType gtype,
- gint position,
- guint num_parameters,
- GParameter *parameters);
+gboolean gtk_source_gutter_insert (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer,
+ gint position);
void gtk_source_gutter_reorder (GtkSourceGutter *gutter,
GtkSourceGutterRenderer *renderer,
diff --git a/gtksourceview/gtksourcegutterrenderer-private.h b/gtksourceview/gtksourcegutterrenderer-private.h
new file mode 100644
index 0000000..c0adb22
--- /dev/null
+++ b/gtksourceview/gtksourcegutterrenderer-private.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- *
+ * gtksourcegutterrenderer-private.h
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2010 - Krzesimir Nowak
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#ifndef __GTK_SOURCE_GUTTER_RENDERER_PRIVATE_H__
+#define __GTK_SOURCE_GUTTER_RENDERER_PRIVATE_H__
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include <gdk/gdk.h>
+#include <gtksourceview/gtksourcegutterrenderer.h>
+
+G_BEGIN_DECLS
+
+void _gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
+ GtkTextView *view,
+ GtkTextWindowType window_type);
+
+void _gtk_source_gutter_renderer_unset_view (GtkSourceGutterRenderer *renderer);
+
+G_END_DECLS
+
+#endif /* __GTK_SOURCE_GUTTER_RENDERER_PRIVATE_H__ */
+
+/* vi:ts=8 */
diff --git a/gtksourceview/gtksourcegutterrenderer.c b/gtksourceview/gtksourcegutterrenderer.c
index e6b9ffa..0141125 100644
--- a/gtksourceview/gtksourcegutterrenderer.c
+++ b/gtksourceview/gtksourcegutterrenderer.c
@@ -20,6 +20,7 @@
*/
#include "gtksourcegutterrenderer.h"
+#include "gtksourcegutterrenderer-private.h"
#include "gtksourceview-marshal.h"
#include "gtksourceview-typebuiltins.h"
#include "gtksourceview-i18n.h"
@@ -596,7 +597,7 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
_("The View"),
_("The view"),
GTK_TYPE_TEXT_VIEW,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READABLE));
/**
* GtkSourceGutterRenderer:alignment-mode:
@@ -630,7 +631,7 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
_("The window type"),
GTK_TYPE_TEXT_WINDOW_TYPE,
GTK_TEXT_WINDOW_PRIVATE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_SIZE,
@@ -1214,10 +1215,31 @@ gtk_source_gutter_renderer_get_background (GtkSourceGutterRenderer *renderer,
*/
void
gtk_source_gutter_renderer_set_background (GtkSourceGutterRenderer *renderer,
- const GdkRGBA *color)
+ const GdkRGBA *color)
{
g_return_if_fail (GTK_IS_SOURCE_GUTTER_RENDERER (renderer));
set_background_color (renderer, color);
}
+void
+_gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
+ GtkTextView *view,
+ GtkTextWindowType window_type)
+{
+ g_return_if_fail (renderer->priv->view == NULL);
+
+ renderer->priv->view = g_object_ref (view);
+ renderer->priv->window_type = window_type;
+}
+
+void
+_gtk_source_gutter_renderer_unset_view (GtkSourceGutterRenderer *renderer)
+{
+ g_return_if_fail (renderer->priv->view != NULL);
+
+ g_object_unref (renderer->priv->view);
+ renderer->priv->view = NULL;
+ renderer->priv->window_type = GTK_TEXT_WINDOW_PRIVATE;
+}
+
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 91ec3b9..1f9e986 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -931,24 +931,28 @@ init_left_gutter (GtkSourceView *view)
gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
- view->priv->line_renderer =
- gtk_source_gutter_insert (gutter,
- GTK_TYPE_SOURCE_GUTTER_RENDERER_LINES,
- GTK_SOURCE_VIEW_GUTTER_POSITION_LINES,
- "alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
- "yalign", 0.5,
- "xalign", 1.0,
- "xpad", 3,
- NULL);
-
- view->priv->marks_renderer =
- gtk_source_gutter_insert (gutter,
- GTK_TYPE_SOURCE_GUTTER_RENDERER_MARKS,
- GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS,
- "alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
- "yalign", 0.5,
- "xalign", 0.5,
- NULL);
+ 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,
+ "xpad", 3,
+ NULL);
+
+ gtk_source_gutter_insert (gutter,
+ view->priv->line_renderer,
+ GTK_SOURCE_VIEW_GUTTER_POSITION_LINES);
+
+ view->priv->marks_renderer = gtk_source_gutter_renderer_marks_new ();
+ g_object_set (view->priv->marks_renderer,
+ "alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
+ "yalign", 0.5,
+ "xalign", 0.5,
+ NULL);
+
+ gtk_source_gutter_insert (gutter,
+ view->priv->marks_renderer,
+ GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS);
g_signal_connect (view->priv->marks_renderer,
"activate",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]