[gspell] Add GspellEntry API
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell] Add GspellEntry API
- Date: Mon, 31 Oct 2016 10:37:35 +0000 (UTC)
commit 8ff4a134e355141031adc3b6647f8d9985bd6979
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Oct 27 18:59:25 2016 +0200
Add GspellEntry API
Similar to GspellTextView, but without the enable-language-menu property
(it'll be always TRUE). For GtkEntry, inline spell checking is the only
feature to do, so a context menu is always needed. For GtkTextView,
there can be a checker dialog or a checker bar, so the context menu is
not always wanted there.
A basic_setup() function will be added later.
docs/reference/gspell-1.0-sections.txt | 12 ++
docs/reference/gspell-docs.xml.in | 1 +
gspell/Makefile.am | 2 +
gspell/gspell-entry.c | 261 ++++++++++++++++++++++++++++++++
gspell/gspell-entry.h | 49 ++++++
gspell/gspell.h | 1 +
po/POTFILES.in | 1 +
7 files changed, 327 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index bb37768..44042c3 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -144,3 +144,15 @@ gspell_entry_buffer_set_spell_checker
<SUBSECTION Standard>
GSPELL_TYPE_ENTRY_BUFFER
</SECTION>
+
+<SECTION>
+<FILE>entry</FILE>
+<TITLE>GspellEntry</TITLE>
+GspellEntry
+gspell_entry_get_from_gtk_entry
+gspell_entry_get_entry
+gspell_entry_get_inline_spell_checking
+gspell_entry_set_inline_spell_checking
+<SUBSECTION Standard>
+GSPELL_TYPE_ENTRY
+</SECTION>
diff --git a/docs/reference/gspell-docs.xml.in b/docs/reference/gspell-docs.xml.in
index 783fe59..c921a31 100644
--- a/docs/reference/gspell-docs.xml.in
+++ b/docs/reference/gspell-docs.xml.in
@@ -46,6 +46,7 @@
<chapter>
<title>GtkEntry Support</title>
<xi:include href="xml/entry-buffer.xml"/>
+ <xi:include href="xml/entry.xml"/>
</chapter>
</part>
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index 90c89c3..3cfd0da 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.h \
gspell-entry-buffer.h \
gspell-language.h \
gspell-language-chooser.h \
@@ -30,6 +31,7 @@ gspell_public_headers = \
gspell_public_c_files = \
gspell-checker.c \
gspell-checker-dialog.c \
+ gspell-entry.c \
gspell-entry-buffer.c \
gspell-language.c \
gspell-language-chooser.c \
diff --git a/gspell/gspell-entry.c b/gspell/gspell-entry.c
new file mode 100644
index 0000000..e76db20
--- /dev/null
+++ b/gspell/gspell-entry.c
@@ -0,0 +1,261 @@
+/*
+ * 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.h"
+
+/**
+ * SECTION:entry
+ * @Title: GspellEntry
+ * @Short_description: Spell checking support for GtkEntry
+ *
+ * #GspellEntry extends the #GtkEntry class with inline spell checking.
+ * Misspelled words are highlighted with a %PANGO_UNDERLINE_ERROR, usually a red
+ * wavy underline.
+ *
+ * Note that #GspellEntry extends the #GtkEntry class but without subclassing
+ * it, because #GtkEntry is already subclassed by #GtkSearchEntry for example.
+ */
+
+struct _GspellEntry
+{
+ GObject parent;
+
+ GtkEntry *entry;
+ guint inline_spell_checking : 1;
+};
+
+enum
+{
+ PROP_0,
+ PROP_ENTRY,
+ PROP_INLINE_SPELL_CHECKING,
+};
+
+#define GSPELL_ENTRY_KEY "gspell-entry-key"
+
+G_DEFINE_TYPE (GspellEntry, gspell_entry, G_TYPE_OBJECT)
+
+static void
+set_entry (GspellEntry *gspell_entry,
+ GtkEntry *gtk_entry)
+{
+ g_return_if_fail (GTK_IS_ENTRY (gtk_entry));
+
+ g_assert (gspell_entry->entry == NULL);
+ gspell_entry->entry = gtk_entry;
+
+ g_object_notify (G_OBJECT (gspell_entry), "entry");
+}
+
+static void
+gspell_entry_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GspellEntry *gspell_entry = GSPELL_ENTRY (object);
+
+ switch (prop_id)
+ {
+ case PROP_ENTRY:
+ g_value_set_object (value, gspell_entry_get_entry (gspell_entry));
+ break;
+
+ case PROP_INLINE_SPELL_CHECKING:
+ g_value_set_boolean (value, gspell_entry_get_inline_spell_checking (gspell_entry));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gspell_entry_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GspellEntry *gspell_entry = GSPELL_ENTRY (object);
+
+ switch (prop_id)
+ {
+ case PROP_ENTRY:
+ set_entry (gspell_entry, g_value_get_object (value));
+ break;
+
+ case PROP_INLINE_SPELL_CHECKING:
+ gspell_entry_set_inline_spell_checking (gspell_entry, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gspell_entry_dispose (GObject *object)
+{
+ GspellEntry *gspell_entry = GSPELL_ENTRY (object);
+
+ gspell_entry->entry = NULL;
+
+ G_OBJECT_CLASS (gspell_entry_parent_class)->dispose (object);
+}
+
+static void
+gspell_entry_class_init (GspellEntryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gspell_entry_get_property;
+ object_class->set_property = gspell_entry_set_property;
+ object_class->dispose = gspell_entry_dispose;
+
+ /**
+ * GspellEntry:entry:
+ *
+ * The #GtkEntry.
+ *
+ * Since: 1.4
+ */
+ g_object_class_install_property (object_class,
+ PROP_ENTRY,
+ g_param_spec_object ("entry",
+ "Entry",
+ "",
+ GTK_TYPE_ENTRY,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GspellEntry:inline-spell-checking:
+ *
+ * Whether the inline spell checking is enabled.
+ *
+ * Since: 1.4
+ */
+ g_object_class_install_property (object_class,
+ PROP_INLINE_SPELL_CHECKING,
+ g_param_spec_boolean ("inline-spell-checking",
+ "Inline Spell Checking",
+ "",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+gspell_entry_init (GspellEntry *gspell_entry)
+{
+}
+
+/**
+ * gspell_entry_get_from_gtk_entry:
+ * @gtk_entry: a #GtkEntry.
+ *
+ * Returns the #GspellEntry of @gtk_entry. The returned object is guaranteed
+ * to be the same for the lifetime of @gtk_entry.
+ *
+ * Returns: (transfer none): the #GspellEntry of @gtk_entry.
+ * Since: 1.4
+ */
+GspellEntry *
+gspell_entry_get_from_gtk_entry (GtkEntry *gtk_entry)
+{
+ GspellEntry *gspell_entry;
+
+ g_return_val_if_fail (GTK_IS_ENTRY (gtk_entry), NULL);
+
+ gspell_entry = g_object_get_data (G_OBJECT (gtk_entry), GSPELL_ENTRY_KEY);
+
+ if (gspell_entry == NULL)
+ {
+ gspell_entry = g_object_new (GSPELL_TYPE_ENTRY,
+ "entry", gtk_entry,
+ NULL);
+
+ g_object_set_data_full (G_OBJECT (gtk_entry),
+ GSPELL_ENTRY_KEY,
+ gspell_entry,
+ g_object_unref);
+ }
+
+ g_return_val_if_fail (GSPELL_IS_ENTRY (gspell_entry), NULL);
+ return gspell_entry;
+}
+
+/**
+ * gspell_entry_get_entry:
+ * @gspell_entry: a #GspellEntry.
+ *
+ * Returns: (transfer none): the #GtkEntry of @gspell_entry.
+ * Since: 1.4
+ */
+GtkEntry *
+gspell_entry_get_entry (GspellEntry *gspell_entry)
+{
+ g_return_val_if_fail (GSPELL_IS_ENTRY (gspell_entry), NULL);
+
+ return gspell_entry->entry;
+}
+
+/**
+ * gspell_entry_get_inline_spell_checking:
+ * @gspell_entry: a #GspellEntry.
+ *
+ * Returns: whether the inline spell checking is enabled.
+ * Since: 1.4
+ */
+gboolean
+gspell_entry_get_inline_spell_checking (GspellEntry *gspell_entry)
+{
+ g_return_val_if_fail (GSPELL_IS_ENTRY (gspell_entry), FALSE);
+
+ return gspell_entry->inline_spell_checking;
+}
+
+/**
+ * gspell_entry_set_inline_spell_checking:
+ * @gspell_entry: a #GspellEntry.
+ * @enable: the new state.
+ *
+ * Enables or disables the inline spell checking.
+ *
+ * Since: 1.4
+ */
+void
+gspell_entry_set_inline_spell_checking (GspellEntry *gspell_entry,
+ gboolean enable)
+{
+ g_return_if_fail (GSPELL_IS_ENTRY (gspell_entry));
+
+ enable = enable != FALSE;
+
+ if (gspell_entry->inline_spell_checking != enable)
+ {
+ gspell_entry->inline_spell_checking = enable;
+ g_object_notify (G_OBJECT (gspell_entry), "inline-spell-checking");
+ }
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell-entry.h b/gspell/gspell-entry.h
new file mode 100644
index 0000000..ee2ccb7
--- /dev/null
+++ b/gspell/gspell-entry.h
@@ -0,0 +1,49 @@
+/*
+ * 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_H
+#define GSPELL_ENTRY_H
+
+#if !defined (GSPELL_H_INSIDE) && !defined (GSPELL_COMPILATION)
+#error "Only <gspell/gspell.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GSPELL_TYPE_ENTRY (gspell_entry_get_type ())
+G_DECLARE_FINAL_TYPE (GspellEntry, gspell_entry,
+ GSPELL, ENTRY,
+ GObject)
+
+GspellEntry * gspell_entry_get_from_gtk_entry (GtkEntry *gtk_entry);
+
+GtkEntry * gspell_entry_get_entry (GspellEntry *gspell_entry);
+
+gboolean gspell_entry_get_inline_spell_checking (GspellEntry *gspell_entry);
+
+void gspell_entry_set_inline_spell_checking (GspellEntry *gspell_entry,
+ gboolean enable);
+
+G_END_DECLS
+
+#endif /* GSPELL_ENTRY_H */
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell.h b/gspell/gspell.h
index c227b7e..ee74859 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.h>
#include <gspell/gspell-entry-buffer.h>
#include <gspell/gspell-language.h>
#include <gspell/gspell-language-chooser.h>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fd1edf3..f4bb7a8 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.c
gspell/gspell-entry-buffer.c
gspell/gspell-inline-checker-text-buffer.c
gspell/gspell-language.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]