[gspell/wip/entry: 1/5] Add GspellEntryBuffer class



commit 1ae97d61c725e172fc35fc4ea36f942e08ce66c5
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Oct 27 17:18:04 2016 +0200

    Add GspellEntryBuffer class
    
    Exactly the same as GspellTextBuffer, to have a consistent API.
    
    I think most of the time GtkEntry is used alone, app developers don't
    care about GtkEntryBuffer. But it is easy to get the GtkEntryBuffer of a
    GtkEntry, and for those who use GtkEntryBuffer, gspell supports it.
    There will anyway be a basic_setup() function in GspellEntry.

 docs/reference/gspell-1.0-sections.txt |   12 ++
 docs/reference/gspell-docs.xml.in      |    5 +
 gspell/Makefile.am                     |    2 +
 gspell/gspell-entry-buffer.c           |  249 ++++++++++++++++++++++++++++++++
 gspell/gspell-entry-buffer.h           |   50 +++++++
 gspell/gspell.h                        |    1 +
 po/POTFILES.in                         |    1 +
 7 files changed, 320 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index e21091d..bb37768 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -132,3 +132,15 @@ gspell_language_chooser_dialog_new
 <SUBSECTION Standard>
 GSPELL_TYPE_LANGUAGE_CHOOSER_DIALOG
 </SECTION>
+
+<SECTION>
+<FILE>entry-buffer</FILE>
+<TITLE>GspellEntryBuffer</TITLE>
+GspellEntryBuffer
+gspell_entry_buffer_get_from_gtk_entry_buffer
+gspell_entry_buffer_get_buffer
+gspell_entry_buffer_get_spell_checker
+gspell_entry_buffer_set_spell_checker
+<SUBSECTION Standard>
+GSPELL_TYPE_ENTRY_BUFFER
+</SECTION>
diff --git a/docs/reference/gspell-docs.xml.in b/docs/reference/gspell-docs.xml.in
index 3f17a04..783fe59 100644
--- a/docs/reference/gspell-docs.xml.in
+++ b/docs/reference/gspell-docs.xml.in
@@ -42,6 +42,11 @@
       <xi:include href="xml/text-view.xml"/>
       <xi:include href="xml/navigator-text-view.xml"/>
     </chapter>
+
+    <chapter>
+      <title>GtkEntry Support</title>
+      <xi:include href="xml/entry-buffer.xml"/>
+    </chapter>
   </part>
 
   <chapter id="object-tree">
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index 98b3d11..90c89c3 100644
--- a/gspell/Makefile.am
+++ b/gspell/Makefile.am
@@ -17,6 +17,7 @@ gspell_public_headers =                               \
        gspell.h                                \
        gspell-checker.h                        \
        gspell-checker-dialog.h                 \
+       gspell-entry-buffer.h                   \
        gspell-language.h                       \
        gspell-language-chooser.h               \
        gspell-language-chooser-button.h        \
@@ -29,6 +30,7 @@ gspell_public_headers =                               \
 gspell_public_c_files =                                \
        gspell-checker.c                        \
        gspell-checker-dialog.c                 \
+       gspell-entry-buffer.c                   \
        gspell-language.c                       \
        gspell-language-chooser.c               \
        gspell-language-chooser-button.c        \
diff --git a/gspell/gspell-entry-buffer.c b/gspell/gspell-entry-buffer.c
new file mode 100644
index 0000000..2e5683a
--- /dev/null
+++ b/gspell/gspell-entry-buffer.c
@@ -0,0 +1,249 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2016 - Sébastien Wilmet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gspell-entry-buffer.h"
+
+/**
+ * SECTION:entry-buffer
+ * @Title: GspellEntryBuffer
+ * @Short_description: Spell checking support for GtkEntryBuffer
+ *
+ * #GspellEntryBuffer extends the #GtkEntryBuffer class with spell checking
+ * support.
+ */
+
+struct _GspellEntryBuffer
+{
+       GObject parent;
+
+       GtkEntryBuffer *buffer;
+       GspellChecker *spell_checker;
+};
+
+enum
+{
+       PROP_0,
+       PROP_BUFFER,
+       PROP_SPELL_CHECKER,
+};
+
+#define GSPELL_ENTRY_BUFFER_KEY "gspell-entry-buffer-key"
+
+G_DEFINE_TYPE (GspellEntryBuffer, gspell_entry_buffer, G_TYPE_OBJECT)
+
+static void
+gspell_entry_buffer_get_property (GObject    *object,
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+       GspellEntryBuffer *gspell_buffer = GSPELL_ENTRY_BUFFER (object);
+
+       switch (prop_id)
+       {
+               case PROP_BUFFER:
+                       g_value_set_object (value, gspell_entry_buffer_get_buffer (gspell_buffer));
+                       break;
+
+               case PROP_SPELL_CHECKER:
+                       g_value_set_object (value, gspell_entry_buffer_get_spell_checker (gspell_buffer));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gspell_entry_buffer_set_property (GObject      *object,
+                                 guint         prop_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+       GspellEntryBuffer *gspell_buffer = GSPELL_ENTRY_BUFFER (object);
+
+       switch (prop_id)
+       {
+               case PROP_BUFFER:
+                       g_assert (gspell_buffer->buffer == NULL);
+                       gspell_buffer->buffer = g_value_get_object (value);
+                       break;
+
+               case PROP_SPELL_CHECKER:
+                       gspell_entry_buffer_set_spell_checker (gspell_buffer, g_value_get_object (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gspell_entry_buffer_dispose (GObject *object)
+{
+       GspellEntryBuffer *gspell_buffer = GSPELL_ENTRY_BUFFER (object);
+
+       gspell_buffer->buffer = NULL;
+       g_clear_object (&gspell_buffer->spell_checker);
+
+       G_OBJECT_CLASS (gspell_entry_buffer_parent_class)->dispose (object);
+}
+
+static void
+gspell_entry_buffer_class_init (GspellEntryBufferClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->get_property = gspell_entry_buffer_get_property;
+       object_class->set_property = gspell_entry_buffer_set_property;
+       object_class->dispose = gspell_entry_buffer_dispose;
+
+       /**
+        * GspellEntryBuffer:buffer:
+        *
+        * The #GtkEntryBuffer.
+        *
+        * Since: 1.4
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_BUFFER,
+                                        g_param_spec_object ("buffer",
+                                                             "Buffer",
+                                                             "",
+                                                             GTK_TYPE_ENTRY_BUFFER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY |
+                                                             G_PARAM_STATIC_STRINGS));
+
+       /**
+        * GspellEntryBuffer:spell-checker:
+        *
+        * The #GspellChecker.
+        *
+        * Since: 1.4
+        */
+       g_object_class_install_property (object_class,
+                                        PROP_SPELL_CHECKER,
+                                        g_param_spec_object ("spell-checker",
+                                                             "Spell Checker",
+                                                             "",
+                                                             GSPELL_TYPE_CHECKER,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gspell_entry_buffer_init (GspellEntryBuffer *gspell_buffer)
+{
+}
+
+/**
+ * gspell_entry_buffer_get_from_gtk_entry_buffer:
+ * @gtk_buffer: a #GtkEntryBuffer.
+ *
+ * Returns the #GspellEntryBuffer of @gtk_buffer. The returned object is
+ * guaranteed to be the same for the lifetime of @gtk_buffer.
+ *
+ * Returns: (transfer none): the #GspellEntryBuffer of @gtk_buffer.
+ * Since: 1.4
+ */
+GspellEntryBuffer *
+gspell_entry_buffer_get_from_gtk_entry_buffer (GtkEntryBuffer *gtk_buffer)
+{
+       GspellEntryBuffer *gspell_buffer;
+
+       g_return_val_if_fail (GTK_IS_ENTRY_BUFFER (gtk_buffer), NULL);
+
+       gspell_buffer = g_object_get_data (G_OBJECT (gtk_buffer), GSPELL_ENTRY_BUFFER_KEY);
+
+       if (gspell_buffer == NULL)
+       {
+               gspell_buffer = g_object_new (GSPELL_TYPE_ENTRY_BUFFER,
+                                             "buffer", gtk_buffer,
+                                             NULL);
+
+               g_object_set_data_full (G_OBJECT (gtk_buffer),
+                                       GSPELL_ENTRY_BUFFER_KEY,
+                                       gspell_buffer,
+                                       g_object_unref);
+       }
+
+       g_return_val_if_fail (GSPELL_IS_ENTRY_BUFFER (gspell_buffer), NULL);
+       return gspell_buffer;
+}
+
+/**
+ * gspell_entry_buffer_get_buffer:
+ * @gspell_buffer: a #GspellEntryBuffer.
+ *
+ * Returns: (transfer none): the #GtkEntryBuffer of @gspell_buffer.
+ * Since: 1.4
+ */
+GtkEntryBuffer *
+gspell_entry_buffer_get_buffer (GspellEntryBuffer *gspell_buffer)
+{
+       g_return_val_if_fail (GSPELL_IS_ENTRY_BUFFER (gspell_buffer), NULL);
+
+       return gspell_buffer->buffer;
+}
+
+/**
+ * gspell_entry_buffer_get_spell_checker:
+ * @gspell_buffer: a #GspellEntryBuffer.
+ *
+ * Returns: (nullable) (transfer none): the #GspellChecker if one has been set,
+ *   or %NULL.
+ * Since: 1.4
+ */
+GspellChecker *
+gspell_entry_buffer_get_spell_checker (GspellEntryBuffer *gspell_buffer)
+{
+       g_return_val_if_fail (GSPELL_IS_ENTRY_BUFFER (gspell_buffer), NULL);
+
+       return gspell_buffer->spell_checker;
+}
+
+/**
+ * gspell_entry_buffer_set_spell_checker:
+ * @gspell_buffer: a #GspellEntryBuffer.
+ * @spell_checker: (nullable): a #GspellChecker, or %NULL to unset the spell
+ *   checker.
+ *
+ * Sets a #GspellChecker to a #GspellEntryBuffer. The @gspell_buffer will own a
+ * reference to @spell_checker, so you can release your reference to
+ * @spell_checker if you no longer need it.
+ *
+ * Since: 1.4
+ */
+void
+gspell_entry_buffer_set_spell_checker (GspellEntryBuffer *gspell_buffer,
+                                      GspellChecker     *spell_checker)
+{
+       g_return_if_fail (GSPELL_IS_ENTRY_BUFFER (gspell_buffer));
+       g_return_if_fail (spell_checker == NULL || GSPELL_IS_CHECKER (spell_checker));
+
+       if (g_set_object (&gspell_buffer->spell_checker, spell_checker))
+       {
+               g_object_notify (G_OBJECT (gspell_buffer), "spell-checker");
+       }
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell-entry-buffer.h b/gspell/gspell-entry-buffer.h
new file mode 100644
index 0000000..adb1736
--- /dev/null
+++ b/gspell/gspell-entry-buffer.h
@@ -0,0 +1,50 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2016 - Sébastien Wilmet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GSPELL_ENTRY_BUFFER_H
+#define GSPELL_ENTRY_BUFFER_H
+
+#if !defined (GSPELL_H_INSIDE) && !defined (GSPELL_COMPILATION)
+#error "Only <gspell/gspell.h> can be included directly."
+#endif
+
+#include <gspell/gspell-checker.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GSPELL_TYPE_ENTRY_BUFFER (gspell_entry_buffer_get_type ())
+G_DECLARE_FINAL_TYPE (GspellEntryBuffer, gspell_entry_buffer,
+                     GSPELL, ENTRY_BUFFER,
+                     GObject)
+
+GspellEntryBuffer *    gspell_entry_buffer_get_from_gtk_entry_buffer   (GtkEntryBuffer *gtk_buffer);
+
+GtkEntryBuffer *       gspell_entry_buffer_get_buffer                  (GspellEntryBuffer *gspell_buffer);
+
+GspellChecker *                gspell_entry_buffer_get_spell_checker           (GspellEntryBuffer 
*gspell_buffer);
+
+void                   gspell_entry_buffer_set_spell_checker           (GspellEntryBuffer *gspell_buffer,
+                                                                        GspellChecker     *spell_checker);
+
+G_END_DECLS
+
+#endif /* GSPELL_ENTRY_BUFFER_H */
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell.h b/gspell/gspell.h
index 98702c5..c227b7e 100644
--- a/gspell/gspell.h
+++ b/gspell/gspell.h
@@ -24,6 +24,7 @@
 
 #include <gspell/gspell-checker.h>
 #include <gspell/gspell-checker-dialog.h>
+#include <gspell/gspell-entry-buffer.h>
 #include <gspell/gspell-language.h>
 #include <gspell/gspell-language-chooser.h>
 #include <gspell/gspell-language-chooser-button.h>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8431042..fd1edf3 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
 # List of source files containing translatable strings.
 gspell/gspell-checker.c
 gspell/gspell-checker-dialog.c
+gspell/gspell-entry-buffer.c
 gspell/gspell-inline-checker-text-buffer.c
 gspell/gspell-language.c
 gspell/gspell-language-chooser.c


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]