|
Packit |
aa0600 |
/*
|
|
Packit |
aa0600 |
* This file is part of gspell, a spell-checking library.
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* Copyright 2016 - Sébastien Wilmet <swilmet@gnome.org>
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
aa0600 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
aa0600 |
* License as published by the Free Software Foundation; either
|
|
Packit |
aa0600 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
aa0600 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aa0600 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aa0600 |
* Lesser General Public License for more details.
|
|
Packit |
aa0600 |
*
|
|
Packit |
aa0600 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
aa0600 |
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
aa0600 |
*/
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
#include <gspell/gspell.h>
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
#define TEST_TYPE_SPELL (test_spell_get_type ())
|
|
Packit |
aa0600 |
G_DECLARE_FINAL_TYPE (TestSpell, test_spell,
|
|
Packit |
aa0600 |
TEST, SPELL,
|
|
Packit |
aa0600 |
GtkGrid)
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
struct _TestSpell
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkGrid parent;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
GtkEntry *entry;
|
|
Packit |
aa0600 |
};
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
G_DEFINE_TYPE (TestSpell, test_spell, GTK_TYPE_GRID)
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_spell_class_init (TestSpellClass *klass)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static GtkEntry *
|
|
Packit |
aa0600 |
create_entry (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkEntry *gtk_entry;
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_entry = GTK_ENTRY (gtk_entry_new ());
|
|
Packit |
aa0600 |
gtk_widget_set_hexpand (GTK_WIDGET (gtk_entry), TRUE);
|
|
Packit |
aa0600 |
gtk_widget_set_valign (GTK_WIDGET (gtk_entry), GTK_ALIGN_START);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (gtk_entry);
|
|
Packit |
aa0600 |
gspell_entry_basic_setup (gspell_entry);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return gtk_entry;
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
bold_toggled_cb (GtkToggleButton *button,
|
|
Packit |
aa0600 |
TestSpell *spell)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
/* Do not care about other users of the GtkEntry:attributes property. An
|
|
Packit |
aa0600 |
* application or another library might do something similar, but
|
|
Packit |
aa0600 |
* GspellEntry should still work.
|
|
Packit |
aa0600 |
*/
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
if (gtk_toggle_button_get_active (button))
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
PangoAttribute *attr_bold;
|
|
Packit |
aa0600 |
PangoAttrList *attr_list;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
attr_bold = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
attr_list = pango_attr_list_new ();
|
|
Packit |
aa0600 |
pango_attr_list_insert (attr_list, attr_bold);
|
|
Packit |
aa0600 |
gtk_entry_set_attributes (spell->entry, attr_list);
|
|
Packit |
aa0600 |
pango_attr_list_unref (attr_list);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
else
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
gtk_entry_set_attributes (spell->entry, NULL);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static GtkWidget *
|
|
Packit |
aa0600 |
create_sidebar (TestSpell *spell)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GspellEntry *gspell_entry;
|
|
Packit |
aa0600 |
GtkWidget *vgrid;
|
|
Packit |
aa0600 |
GtkWidget *enable_toggle_button;
|
|
Packit |
aa0600 |
GtkWidget *bold_toggle_button;
|
|
Packit |
aa0600 |
GtkWidget *password_toggle_button;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
vgrid = gtk_grid_new ();
|
|
Packit |
aa0600 |
gtk_grid_set_row_spacing (GTK_GRID (vgrid), 6);
|
|
Packit |
aa0600 |
gtk_orientable_set_orientation (GTK_ORIENTABLE (vgrid),
|
|
Packit |
aa0600 |
GTK_ORIENTATION_VERTICAL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
enable_toggle_button = gtk_toggle_button_new_with_label ("Enable spell-checking");
|
|
Packit |
aa0600 |
gtk_container_add (GTK_CONTAINER (vgrid), enable_toggle_button);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gspell_entry = gspell_entry_get_from_gtk_entry (spell->entry);
|
|
Packit |
aa0600 |
g_object_bind_property (gspell_entry, "inline-spell-checking",
|
|
Packit |
aa0600 |
enable_toggle_button, "active",
|
|
Packit |
aa0600 |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
bold_toggle_button = gtk_toggle_button_new_with_label ("Text in bold");
|
|
Packit |
aa0600 |
gtk_container_add (GTK_CONTAINER (vgrid), bold_toggle_button);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_signal_connect (bold_toggle_button,
|
|
Packit |
aa0600 |
"toggled",
|
|
Packit |
aa0600 |
G_CALLBACK (bold_toggled_cb),
|
|
Packit |
aa0600 |
spell);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
password_toggle_button = gtk_toggle_button_new_with_label ("Password mode");
|
|
Packit |
aa0600 |
gtk_container_add (GTK_CONTAINER (vgrid), password_toggle_button);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_object_bind_property (spell->entry, "visibility",
|
|
Packit |
aa0600 |
password_toggle_button, "active",
|
|
Packit |
aa0600 |
G_BINDING_BIDIRECTIONAL |
|
|
Packit |
aa0600 |
G_BINDING_SYNC_CREATE |
|
|
Packit |
aa0600 |
G_BINDING_INVERT_BOOLEAN);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_widget_show_all (vgrid);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return vgrid;
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static void
|
|
Packit |
aa0600 |
test_spell_init (TestSpell *spell)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
g_object_set (spell,
|
|
Packit |
aa0600 |
"margin", 6,
|
|
Packit |
aa0600 |
NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_grid_set_column_spacing (GTK_GRID (spell), 6);
|
|
Packit |
aa0600 |
gtk_orientable_set_orientation (GTK_ORIENTABLE (spell),
|
|
Packit |
aa0600 |
GTK_ORIENTATION_HORIZONTAL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
spell->entry = create_entry ();
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_container_add (GTK_CONTAINER (spell),
|
|
Packit |
aa0600 |
create_sidebar (spell));
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_container_add (GTK_CONTAINER (spell),
|
|
Packit |
aa0600 |
GTK_WIDGET (spell->entry));
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_widget_show_all (GTK_WIDGET (spell));
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
static TestSpell *
|
|
Packit |
aa0600 |
test_spell_new (void)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
return g_object_new (TEST_TYPE_SPELL, NULL);
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gint
|
|
Packit |
aa0600 |
main (gint argc,
|
|
Packit |
aa0600 |
gchar **argv)
|
|
Packit |
aa0600 |
{
|
|
Packit |
aa0600 |
GtkWidget *window;
|
|
Packit |
aa0600 |
TestSpell *spell;
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_init (&argc, &argv);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_window_set_default_size (GTK_WINDOW (window), 400, 200);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
g_signal_connect (window,
|
|
Packit |
aa0600 |
"destroy",
|
|
Packit |
aa0600 |
G_CALLBACK (gtk_main_quit),
|
|
Packit |
aa0600 |
NULL);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
spell = test_spell_new ();
|
|
Packit |
aa0600 |
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (spell));
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_widget_show (window);
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
gtk_main ();
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
return 0;
|
|
Packit |
aa0600 |
}
|
|
Packit |
aa0600 |
|
|
Packit |
aa0600 |
/* ex:set ts=8 noet: */
|