Switch to using GSpell for wxTextCtrl proof checker in wxGTK

Use GSpell rather than GtkSpell because GSpell also allows to check
single line text controls.

Closes https://github.com/wxWidgets/wxWidgets/pull/2516
This commit is contained in:
Iwbnwif Yiw
2021-09-08 21:02:44 +01:00
committed by Vadim Zeitlin
parent 0fd138a4e7
commit 5ba2461fd1
6 changed files with 83 additions and 68 deletions

View File

@@ -50,7 +50,7 @@ case $(uname -s) in
*) *)
case "$wxGTK_VERSION" in case "$wxGTK_VERSION" in
3) libtoolkit_dev=libgtk-3-dev 3) libtoolkit_dev=libgtk-3-dev
extra_deps='libwebkit2gtk-4.0-dev libwebkitgtk-3.0-dev libgtkspell3-3-dev' extra_deps='libwebkit2gtk-4.0-dev libwebkitgtk-3.0-dev libgspell-1-dev'
;; ;;
2) libtoolkit_dev=libgtk2.0-dev 2) libtoolkit_dev=libgtk2.0-dev
extra_deps='libwebkitgtk-dev' extra_deps='libwebkitgtk-dev'

61
configure vendored
View File

@@ -951,8 +951,8 @@ GTKPRINT_CFLAGS
SDL_CONFIG SDL_CONFIG
SDL_LIBS SDL_LIBS
SDL_CFLAGS SDL_CFLAGS
GTKSPELL_LIBS GSPELL_LIBS
GTKSPELL_CFLAGS GSPELL_CFLAGS
LIBSECRET_LIBS LIBSECRET_LIBS
LIBSECRET_CFLAGS LIBSECRET_CFLAGS
GXX_VERSION GXX_VERSION
@@ -1434,8 +1434,8 @@ MesaGL_CFLAGS
MesaGL_LIBS MesaGL_LIBS
LIBSECRET_CFLAGS LIBSECRET_CFLAGS
LIBSECRET_LIBS LIBSECRET_LIBS
GTKSPELL_CFLAGS GSPELL_CFLAGS
GTKSPELL_LIBS GSPELL_LIBS
SDL_CFLAGS SDL_CFLAGS
SDL_LIBS SDL_LIBS
GTKPRINT_CFLAGS GTKPRINT_CFLAGS
@@ -2475,10 +2475,9 @@ Some influential environment variables:
C compiler flags for LIBSECRET, overriding pkg-config C compiler flags for LIBSECRET, overriding pkg-config
LIBSECRET_LIBS LIBSECRET_LIBS
linker flags for LIBSECRET, overriding pkg-config linker flags for LIBSECRET, overriding pkg-config
GTKSPELL_CFLAGS GSPELL_CFLAGS
C compiler flags for GTKSPELL, overriding pkg-config C compiler flags for GSPELL, overriding pkg-config
GTKSPELL_LIBS GSPELL_LIBS linker flags for GSPELL, overriding pkg-config
linker flags for GTKSPELL, overriding pkg-config
SDL_CFLAGS C compiler flags for SDL, overriding pkg-config SDL_CFLAGS C compiler flags for SDL, overriding pkg-config
SDL_LIBS linker flags for SDL, overriding pkg-config SDL_LIBS linker flags for SDL, overriding pkg-config
GTKPRINT_CFLAGS GTKPRINT_CFLAGS
@@ -34014,20 +34013,20 @@ if test "$wxUSE_SPELLCHECK" = "yes"; then
if test "$WXGTK3" = 1; then if test "$WXGTK3" = 1; then
pkg_failed=no pkg_failed=no
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GTKSPELL" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GSPELL" >&5
$as_echo_n "checking for GTKSPELL... " >&6; } $as_echo_n "checking for GSPELL... " >&6; }
if test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG"; then
if test -n "$GTKSPELL_CFLAGS"; then if test -n "$GSPELL_CFLAGS"; then
pkg_cv_GTKSPELL_CFLAGS="$GTKSPELL_CFLAGS" pkg_cv_GSPELL_CFLAGS="$GSPELL_CFLAGS"
else else
if test -n "$PKG_CONFIG" && \ if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gtkspell3-3.0\""; } >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gspell-1\""; } >&5
($PKG_CONFIG --exists --print-errors "gtkspell3-3.0") 2>&5 ($PKG_CONFIG --exists --print-errors "gspell-1") 2>&5
ac_status=$? ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then test $ac_status = 0; }; then
pkg_cv_GTKSPELL_CFLAGS=`$PKG_CONFIG --cflags "gtkspell3-3.0" 2>/dev/null` pkg_cv_GSPELL_CFLAGS=`$PKG_CONFIG --cflags "gspell-1" 2>/dev/null`
else else
pkg_failed=yes pkg_failed=yes
fi fi
@@ -34036,16 +34035,16 @@ else
pkg_failed=untried pkg_failed=untried
fi fi
if test -n "$PKG_CONFIG"; then if test -n "$PKG_CONFIG"; then
if test -n "$GTKSPELL_LIBS"; then if test -n "$GSPELL_LIBS"; then
pkg_cv_GTKSPELL_LIBS="$GTKSPELL_LIBS" pkg_cv_GSPELL_LIBS="$GSPELL_LIBS"
else else
if test -n "$PKG_CONFIG" && \ if test -n "$PKG_CONFIG" && \
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gtkspell3-3.0\""; } >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gspell-1\""; } >&5
($PKG_CONFIG --exists --print-errors "gtkspell3-3.0") 2>&5 ($PKG_CONFIG --exists --print-errors "gspell-1") 2>&5
ac_status=$? ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then test $ac_status = 0; }; then
pkg_cv_GTKSPELL_LIBS=`$PKG_CONFIG --libs "gtkspell3-3.0" 2>/dev/null` pkg_cv_GSPELL_LIBS=`$PKG_CONFIG --libs "gspell-1" 2>/dev/null`
else else
pkg_failed=yes pkg_failed=yes
fi fi
@@ -34064,34 +34063,34 @@ else
_pkg_short_errors_supported=no _pkg_short_errors_supported=no
fi fi
if test $_pkg_short_errors_supported = yes; then if test $_pkg_short_errors_supported = yes; then
GTKSPELL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "gtkspell3-3.0"` GSPELL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "gspell-1"`
else else
GTKSPELL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "gtkspell3-3.0"` GSPELL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "gspell-1"`
fi fi
# Put the nasty error message in config.log where it belongs # Put the nasty error message in config.log where it belongs
echo "$GTKSPELL_PKG_ERRORS" >&5 echo "$GSPELL_PKG_ERRORS" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gspell-1 not found, spell checking in wxTextCtrl won't be available" >&5
$as_echo "$as_me: WARNING: gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available" >&2;} $as_echo "$as_me: WARNING: gspell-1 not found, spell checking in wxTextCtrl won't be available" >&2;}
wxUSE_SPELLCHECK=no wxUSE_SPELLCHECK=no
elif test $pkg_failed = untried; then elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gspell-1 not found, spell checking in wxTextCtrl won't be available" >&5
$as_echo "$as_me: WARNING: gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available" >&2;} $as_echo "$as_me: WARNING: gspell-1 not found, spell checking in wxTextCtrl won't be available" >&2;}
wxUSE_SPELLCHECK=no wxUSE_SPELLCHECK=no
else else
GTKSPELL_CFLAGS=$pkg_cv_GTKSPELL_CFLAGS GSPELL_CFLAGS=$pkg_cv_GSPELL_CFLAGS
GTKSPELL_LIBS=$pkg_cv_GTKSPELL_LIBS GSPELL_LIBS=$pkg_cv_GSPELL_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; } $as_echo "yes" >&6; }
CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" CXXFLAGS="$GSPELL_CFLAGS $CXXFLAGS"
LIBS="$GTKSPELL_LIBS $LIBS" LIBS="$GSPELL_LIBS $LIBS"
fi fi
fi fi

View File

@@ -5774,16 +5774,16 @@ dnl ---------------------------------------------------------------------------
if test "$wxUSE_SPELLCHECK" = "yes"; then if test "$wxUSE_SPELLCHECK" = "yes"; then
dnl The required APIs are always available under MSW and OS X and we don't dnl The required APIs are always available under MSW and OS X and we don't
dnl implement support for spell checking in the other ports, but for GTK 3 dnl implement support for spell checking in the other ports, but for GTK 3
dnl we need to check for gtkspell library. dnl we need to check for the gspell library.
if test "$WXGTK3" = 1; then if test "$WXGTK3" = 1; then
PKG_CHECK_MODULES(GTKSPELL, [gtkspell3-3.0], PKG_CHECK_MODULES(GSPELL, [gspell-1],
[ [
CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" CXXFLAGS="$GSPELL_CFLAGS $CXXFLAGS"
LIBS="$GTKSPELL_LIBS $LIBS" LIBS="$GSPELL_LIBS $LIBS"
], ],
[ [
AC_MSG_WARN([gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available]) AC_MSG_WARN([gspell-1 not found, spell checking in wxTextCtrl won't be available])
wxUSE_SPELLCHECK=no wxUSE_SPELLCHECK=no
] ]
) )

View File

@@ -1410,8 +1410,11 @@ public:
Currently this is supported in wxMSW (when running under Windows 8 or Currently this is supported in wxMSW (when running under Windows 8 or
later), wxGTK when using GTK 3 and wxOSX. In addition, wxMSW requires later), wxGTK when using GTK 3 and wxOSX. In addition, wxMSW requires
that the text control has the wxTE_RICH2 style set. wxGTK3 and wxOSX that the text control has the wxTE_RICH2 style set, while wxOSX
require that the control has the wxTE_MULTILINE style. requires that the control has the wxTE_MULTILINE style.
When using wxGTK, this method only works if gspell library was
available during the library build.
@param options @param options
A wxTextProofOptions object specifying the desired behaviour A wxTextProofOptions object specifying the desired behaviour

View File

@@ -1123,6 +1123,16 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
m_text->SetInsertionPoint(0); m_text->SetInsertionPoint(0);
m_text->WriteText( "Prepended. " ); m_text->WriteText( "Prepended. " );
#if wxUSE_SPELLCHECK
if ( m_text->EnableProofCheck(wxTextProofOptions::Default()) )
{
// Break the string in several parts to avoid misspellings in the sources.
(*m_text) << " Mis"
"s"
"spelled.";
}
#endif
m_password = new MyTextCtrl( this, wxID_ANY, "", m_password = new MyTextCtrl( this, wxID_ANY, "",
wxPoint(10,50), wxSize(140,wxDefaultCoord), wxTE_PASSWORD ); wxPoint(10,50), wxSize(140,wxDefaultCoord), wxTE_PASSWORD );
m_password->SetHint("Don't use 12345 here"); m_password->SetHint("Don't use 12345 here");
@@ -1221,7 +1231,6 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
} }
else else
{ {
// Break the string in several parts to avoid misspellings in the sources.
(*m_enter) << "Spell checking is enabled, mis" (*m_enter) << "Spell checking is enabled, mis"
"s" "s"
"spelled words should be highlighted."; "spelled words should be highlighted.";

View File

@@ -34,7 +34,7 @@
#if wxUSE_SPELLCHECK && defined(__WXGTK3__) #if wxUSE_SPELLCHECK && defined(__WXGTK3__)
extern "C" { extern "C" {
#include <gtkspell-3.0/gtkspell/gtkspell.h> #include <gspell-1/gspell/gspell.h>
} }
#endif // wxUSE_SPELLCHECK && __WXGTK3__ #endif // wxUSE_SPELLCHECK && __WXGTK3__
@@ -1027,34 +1027,30 @@ void wxTextCtrl::GTKSetJustification()
bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options)
{ {
wxCHECK_MSG( IsMultiLine(), false, if ( IsMultiLine() )
"Unable to enable spell check on control " {
"which does not have wxTE_MULTILINE style" );
GtkTextView *textview = GTK_TEXT_VIEW(m_text); GtkTextView *textview = GTK_TEXT_VIEW(m_text);
wxCHECK_MSG( textview, false, wxS("wxTextCtrl is not a GtkTextView")); wxCHECK_MSG( textview, false, wxS("wxTextCtrl is not a GtkTextView") );
GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview); GspellTextView *spell = gspell_text_view_get_from_gtk_text_view (textview);
if ( options.IsSpellCheckEnabled() )
{
if ( !spell ) if ( !spell )
{
spell = gtk_spell_checker_new();
gtk_spell_checker_attach(spell, textview);
}
wxString lang = options.GetLang();
if ( !gtk_spell_checker_set_language(spell,
lang.empty() ? NULL : (const gchar *)lang.utf8_str(),
NULL) )
return false; return false;
gspell_text_view_basic_setup(spell);
gspell_text_view_set_inline_spell_checking(spell, options.IsSpellCheckEnabled());
gspell_text_view_set_enable_language_menu(spell, options.IsSpellCheckEnabled());
} }
else else
{ {
if ( spell ) GtkEntry *entry = GTK_ENTRY(m_text);
gtk_spell_checker_detach(spell); wxCHECK_MSG( entry, false, wxS("wxTextCtrl is not a GtkEntry") );
GspellEntry *spell = gspell_entry_get_from_gtk_entry(entry);
if ( !spell )
return false;
gspell_entry_basic_setup(spell);
gspell_entry_set_inline_spell_checking(spell, options.IsSpellCheckEnabled());
} }
return GetProofCheckOptions().IsSpellCheckEnabled(); return GetProofCheckOptions().IsSpellCheckEnabled();
@@ -1064,11 +1060,19 @@ wxTextProofOptions wxTextCtrl::GetProofCheckOptions() const
{ {
wxTextProofOptions opts = wxTextProofOptions::Disable(); wxTextProofOptions opts = wxTextProofOptions::Disable();
if ( IsMultiLine() )
{
GtkTextView *textview = GTK_TEXT_VIEW(m_text); GtkTextView *textview = GTK_TEXT_VIEW(m_text);
if ( IsMultiLine() && textview ) if ( textview && gspell_text_view_get_from_gtk_text_view(textview) )
opts.SpellCheck();
}
else
{ {
if ( gtk_spell_checker_get_from_text_view(textview) ) GtkEntry *entry = GTK_ENTRY(m_text);
if ( entry && gspell_entry_get_from_gtk_entry(entry) )
opts.SpellCheck(); opts.SpellCheck();
} }