From 472aec2d7e53c68274c9f11fd608f22895adc3d1 Mon Sep 17 00:00:00 2001 From: iwbnwif Date: Wed, 18 Aug 2021 21:17:04 +0100 Subject: [PATCH 01/14] Add support for using native spell checking in wxTextCtrl Add wxTextCtrl::EnableSpellCheck() and implement it for wxMSW and wxGTK3. Closes #17544. --- build/cmake/setup.h.in | 6 ++ build/tools/before_install.sh | 2 +- configure | 149 ++++++++++++++++++++++++++++++++++ configure.in | 43 ++++++++++ include/wx/android/setup.h | 12 +++ include/wx/gtk/setup.h | 12 +++ include/wx/gtk/textctrl.h | 8 ++ include/wx/motif/setup.h | 12 +++ include/wx/msw/setup.h | 12 +++ include/wx/msw/textctrl.h | 9 ++ include/wx/osx/setup.h | 12 +++ include/wx/setup_inc.h | 12 +++ include/wx/textctrl.h | 48 +++++++++++ include/wx/univ/setup.h | 12 +++ interface/wx/textctrl.h | 97 +++++++++++++++++++++- samples/text/text.cpp | 15 +++- setup.h.in | 6 ++ src/gtk/textctrl.cpp | 57 +++++++++++++ src/msw/textctrl.cpp | 55 ++++++++++++- 19 files changed, 575 insertions(+), 4 deletions(-) diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in index d052b2f03c..29fae22477 100644 --- a/build/cmake/setup.h.in +++ b/build/cmake/setup.h.in @@ -216,6 +216,12 @@ #cmakedefine01 wxUSE_SECRETSTORE +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#cmakedefine01 wxUSE_SPELLCHECK +#else +#cmakedefine01 wxUSE_SPELLCHECK +#endif + #cmakedefine01 wxUSE_STDPATHS #cmakedefine01 wxUSE_TEXTBUFFER diff --git a/build/tools/before_install.sh b/build/tools/before_install.sh index 87b1fb0c94..373020c2e3 100755 --- a/build/tools/before_install.sh +++ b/build/tools/before_install.sh @@ -50,7 +50,7 @@ case $(uname -s) in *) case "$wxGTK_VERSION" in 3) libtoolkit_dev=libgtk-3-dev - extra_deps='libwebkit2gtk-4.0-dev libwebkitgtk-3.0-dev' + extra_deps='libwebkit2gtk-4.0-dev libwebkitgtk-3.0-dev libgtkspell3-3-dev' ;; 2) libtoolkit_dev=libgtk2.0-dev extra_deps='libwebkitgtk-dev' diff --git a/configure b/configure index ef15f342aa..aa6780aed7 100755 --- a/configure +++ b/configure @@ -951,6 +951,8 @@ GTKPRINT_CFLAGS SDL_CONFIG SDL_LIBS SDL_CFLAGS +GTKSPELL_LIBS +GTKSPELL_CFLAGS LIBSECRET_LIBS LIBSECRET_CFLAGS GXX_VERSION @@ -1203,6 +1205,7 @@ enable_printfposparam enable_secretstore enable_snglinst enable_sound +enable_spellcheck enable_stdpaths enable_stopwatch enable_streams @@ -1430,6 +1433,8 @@ MesaGL_CFLAGS MesaGL_LIBS LIBSECRET_CFLAGS LIBSECRET_LIBS +GTKSPELL_CFLAGS +GTKSPELL_LIBS SDL_CFLAGS SDL_LIBS GTKPRINT_CFLAGS @@ -2170,6 +2175,7 @@ Optional Features: --enable-secretstore use wxSecretStore class --enable-snglinst use wxSingleInstanceChecker class --enable-sound use wxSound class + --enable-spellcheck enable spellchecking in wxTextCtrl class (MSW and GTK3 only) --enable-stdpaths use wxStandardPaths class --enable-stopwatch use wxStopWatch class --enable-streams use wxStream etc classes @@ -2467,6 +2473,10 @@ Some influential environment variables: C compiler flags for LIBSECRET, overriding pkg-config LIBSECRET_LIBS linker flags for LIBSECRET, overriding pkg-config + GTKSPELL_CFLAGS + C compiler flags for GTKSPELL, overriding pkg-config + GTKSPELL_LIBS + linker flags for GTKSPELL, overriding pkg-config SDL_CFLAGS C compiler flags for SDL, overriding pkg-config SDL_LIBS linker flags for SDL, overriding pkg-config GTKPRINT_CFLAGS @@ -7863,6 +7873,35 @@ fi eval "$wx_cv_use_sound" + enablestring= + defaultval=$wxUSE_ALL_FEATURES + if test -z "$defaultval"; then + if test x"$enablestring" = xdisable; then + defaultval=yes + else + defaultval=no + fi + fi + + # Check whether --enable-spellcheck was given. +if test "${enable_spellcheck+set}" = set; then : + enableval=$enable_spellcheck; + if test "$enableval" = yes; then + wx_cv_use_spellcheck='wxUSE_SPELLCHECK=yes' + else + wx_cv_use_spellcheck='wxUSE_SPELLCHECK=no' + fi + +else + + wx_cv_use_spellcheck='wxUSE_SPELLCHECK=${'DEFAULT_wxUSE_SPELLCHECK":-$defaultval}" + +fi + + + eval "$wx_cv_use_spellcheck" + + enablestring= defaultval=$wxUSE_ALL_FEATURES if test -z "$defaultval"; then @@ -33935,6 +33974,116 @@ fi fi + +if test "$wxUSE_SPELLCHECK" = "yes"; then + + if test "$wxUSE_MSW" = 1 -o test "$wxUSE_OSX_COCOA" = 1; then + has_spellcheck_support=yes + + elif test "$wxUSE_GTK" = 1; then + if test "$WXGTK3" = 1; then + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GTKSPELL" >&5 +$as_echo_n "checking for GTKSPELL... " >&6; } + +if test -n "$PKG_CONFIG"; then + if test -n "$GTKSPELL_CFLAGS"; then + pkg_cv_GTKSPELL_CFLAGS="$GTKSPELL_CFLAGS" + else + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gtkspell3-3.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gtkspell3-3.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GTKSPELL_CFLAGS=`$PKG_CONFIG --cflags "gtkspell3-3.0" 2>/dev/null` +else + pkg_failed=yes +fi + fi +else + pkg_failed=untried +fi +if test -n "$PKG_CONFIG"; then + if test -n "$GTKSPELL_LIBS"; then + pkg_cv_GTKSPELL_LIBS="$GTKSPELL_LIBS" + else + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gtkspell3-3.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gtkspell3-3.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GTKSPELL_LIBS=`$PKG_CONFIG --libs "gtkspell3-3.0" 2>/dev/null` +else + pkg_failed=yes +fi + fi +else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GTKSPELL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "gtkspell3-3.0"` + else + GTKSPELL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "gtkspell3-3.0"` + fi + # Put the nasty error message in config.log where it belongs + echo "$GTKSPELL_PKG_ERRORS" >&5 + + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&5 +$as_echo "$as_me: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&2;} + has_spellcheck_support=no + + +elif test $pkg_failed = untried; then + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&5 +$as_echo "$as_me: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&2;} + has_spellcheck_support=no + + +else + GTKSPELL_CFLAGS=$pkg_cv_GTKSPELL_CFLAGS + GTKSPELL_LIBS=$pkg_cv_GTKSPELL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" + LIBS="$GTKSPELL_LIBS $LIBS" + has_spellcheck_support=yes + +fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Spellchecking is not supported on GTK < 3" >&5 +$as_echo "$as_me: WARNING: Spellchecking is not supported on GTK < 3" >&2;} + has_spellcheck_support=no + fi + + else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Spellchecking is not supported on this platform" >&5 +$as_echo "$as_me: WARNING: Spellchecking is not supported on this platform" >&2;} + has_spellcheck_support=no + fi + + if test "$has_spellcheck_support" = "yes"; then + $as_echo "#define wxUSE_SPELLCHECK 1" >>confdefs.h + + fi +fi + + if test "$wxUSE_STL" = "yes"; then $as_echo "#define wxUSE_STL 1" >>confdefs.h diff --git a/configure.in b/configure.in index 7024c62e6d..812d27b0c1 100644 --- a/configure.in +++ b/configure.in @@ -766,6 +766,7 @@ WX_ARG_FEATURE(printfposparam,[ --enable-printfposparam use wxVsnprintf() which WX_ARG_FEATURE(secretstore, [ --enable-secretstore use wxSecretStore class], wxUSE_SECRETSTORE) WX_ARG_FEATURE(snglinst, [ --enable-snglinst use wxSingleInstanceChecker class], wxUSE_SNGLINST_CHECKER) WX_ARG_FEATURE(sound, [ --enable-sound use wxSound class], wxUSE_SOUND) +WX_ARG_FEATURE(spellcheck, [ --enable-spellcheck enable spellchecking in wxTextCtrl class (MSW and GTK3 only)], wxUSE_SPELLCHECK) WX_ARG_FEATURE(stdpaths, [ --enable-stdpaths use wxStandardPaths class], wxUSE_STDPATHS) WX_ARG_FEATURE(stopwatch, [ --enable-stopwatch use wxStopWatch class], wxUSE_STOPWATCH) WX_ARG_FEATURE(streams, [ --enable-streams use wxStream etc classes], wxUSE_STREAMS) @@ -5761,6 +5762,48 @@ if test "$wxUSE_SECRETSTORE" = "yes"; then fi fi + +dnl --------------------------------------------------------------------------- +dnl Spellchecking for wxTextCtrl +dnl --------------------------------------------------------------------------- + +if test "$wxUSE_SPELLCHECK" = "yes"; then + dnl The required APIs are always available under MSW and OS X but we must + dnl have GTK3 and GNOME gtkspell under Unix to be able to compile this feature. + + if test "$wxUSE_MSW" = 1 -o test "$wxUSE_OSX_COCOA" = 1; then + dnl Always available under these systems + has_spellcheck_support=yes + + elif test "$wxUSE_GTK" = 1; then + if test "$WXGTK3" = 1; then + PKG_CHECK_MODULES(GTKSPELL, [gtkspell3-3.0], + [ + CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" + LIBS="$GTKSPELL_LIBS $LIBS" + has_spellcheck_support=yes + ], + [ + AC_MSG_WARN([gtkspell3-3.0 not found, spellchecking won't be available]) + has_spellcheck_support=no + ] + ) + else + AC_MSG_WARN([Spellchecking is not supported on GTK < 3]) + has_spellcheck_support=no + fi + + else + dnl Not implemented in the other ports yet. + AC_MSG_WARN([Spellchecking is not supported on this platform]) + has_spellcheck_support=no + fi + + if test "$has_spellcheck_support" = "yes"; then + AC_DEFINE(wxUSE_SPELLCHECK) + fi +fi + dnl --------------------------------------------------------------------------- dnl Register non-GUI class options for makefiles and setup.h dnl --------------------------------------------------------------------------- diff --git a/include/wx/android/setup.h b/include/wx/android/setup.h index 7d2516b3aa..e427c6e0b0 100644 --- a/include/wx/android/setup.h +++ b/include/wx/android/setup.h @@ -447,6 +447,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/include/wx/gtk/setup.h b/include/wx/gtk/setup.h index da9678a222..344eec7bab 100644 --- a/include/wx/gtk/setup.h +++ b/include/wx/gtk/setup.h @@ -448,6 +448,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index ebc2f02e0a..296bf73480 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -96,6 +96,14 @@ public: // Overridden wxWindow methods virtual void SetWindowStyleFlag( long style ) wxOVERRIDE; +#if wxUSE_SPELLCHECK + // Use native spelling and grammar checking functions. + virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, + const wxTextProofOptions& WXUNUSED(options) = + wxTextProofOptions()) wxOVERRIDE; + virtual bool IsProofCheckEnabled() const wxOVERRIDE; +#endif // wxUSE_SPELLCHECK + // Implementation from now on void OnDropFiles( wxDropFilesEvent &event ); void OnChar( wxKeyEvent &event ); diff --git a/include/wx/motif/setup.h b/include/wx/motif/setup.h index 9e1174e2ab..1783056cbd 100644 --- a/include/wx/motif/setup.h +++ b/include/wx/motif/setup.h @@ -448,6 +448,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/include/wx/msw/setup.h b/include/wx/msw/setup.h index f87bcece45..c45bcebd1e 100644 --- a/include/wx/msw/setup.h +++ b/include/wx/msw/setup.h @@ -448,6 +448,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 4b85f69e3c..d7f8d04cc8 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -111,6 +111,15 @@ public: bool ShowNativeCaret(bool show = true); bool HideNativeCaret() { return ShowNativeCaret(false); } +#if wxUSE_RICHEDIT && wxUSE_SPELLCHECK + // Use native spelling and grammar checking functions. + // This is only available in wxTE_RICH2 controls. + virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, + const wxTextProofOptions& WXUNUSED(options) = + wxTextProofOptions()) wxOVERRIDE; + virtual bool IsProofCheckEnabled() const wxOVERRIDE; +#endif // wxUSE_RICHEDIT && wxUSE_SPELLCHECK + // Implementation from now on // -------------------------- diff --git a/include/wx/osx/setup.h b/include/wx/osx/setup.h index e11ce81431..1f62e4b3c2 100644 --- a/include/wx/osx/setup.h +++ b/include/wx/osx/setup.h @@ -454,6 +454,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h index 9a59af9816..28dc701f58 100644 --- a/include/wx/setup_inc.h +++ b/include/wx/setup_inc.h @@ -444,6 +444,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index ac18c183e9..66e3f8135e 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -126,6 +126,45 @@ enum wxTextCtrlHitTestResult }; // ... the character returned +#if wxUSE_SPELLCHECK + +// ---------------------------------------------------------------------------- +// wxTextCtrl proof options object +// Passed to ::EnableProofCheck() to configure the proofing options for +// this control +// ---------------------------------------------------------------------------- +class WXDLLIMPEXP_CORE wxTextProofOptions +{ +public: + wxTextProofOptions(const wxString& lang = wxEmptyString) + : m_lang(lang) + { + m_EnableSpellCheck = true; + m_EnableGrammarCheck = false; + } + + wxTextProofOptions& SpellCheck(bool enable = true) + { + m_EnableSpellCheck = enable; + return *this; + } + + wxTextProofOptions& GrammarCheck(bool enable = true) + { + m_EnableGrammarCheck = enable; + return *this; + } + + const wxString& GetLang() const { return m_lang; } + +private: + wxString m_lang; + bool m_EnableSpellCheck; + bool m_EnableGrammarCheck; +}; + +#endif // wxUSE_SPELLCHECK + // ---------------------------------------------------------------------------- // Types for wxTextAttr // ---------------------------------------------------------------------------- @@ -758,6 +797,15 @@ public: virtual const wxTextEntry* WXGetTextEntry() const wxOVERRIDE { return this; } +#if wxUSE_SPELLCHECK + // Use native spelling and grammar checking functions. + virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, + const wxTextProofOptions& WXUNUSED(options) = + wxTextProofOptions()) + { return false; } + virtual bool IsProofCheckEnabled() const { return false; } +#endif // wxUSE_SPELLCHECK + protected: // Override wxEvtHandler method to check for a common problem of binding // wxEVT_TEXT_ENTER to a control without wxTE_PROCESS_ENTER style, which is diff --git a/include/wx/univ/setup.h b/include/wx/univ/setup.h index 010713e897..fcf5db2d92 100644 --- a/include/wx/univ/setup.h +++ b/include/wx/univ/setup.h @@ -447,6 +447,18 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 +// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline +// only). Currently only wxGTK3 and wxMSW are implemented. +// +// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// +// Recommended setting: 1 on supported platforms. +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 1 +#else +#define wxUSE_SPELLCHECK 0 +#endif + // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system // diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index d296d05c72..f888778f41 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -258,7 +258,6 @@ enum wxTextCtrlHitTestResult wxTE_HT_BEYOND }; - /** @class wxTextAttr @@ -979,6 +978,62 @@ public: void operator=(const wxTextAttr& attr); }; +/** + @class wxTextProofOptions + + This class provides a convenient means of passing multiple parameters to + wxTextCtrl::EnableProofCheck(). Typical (and the default) usage is: + + @code + m_pText->EnableProofCheck(true, wxTextProofOptions(wxEmptyString).SpellCheck(true)); + @endcode + + If this is the exact behaviour desired, then the parameters can be omitted. + The following code will have the same result: + + @code + m_pText->EnableProofCheck(); + @endcode + + Options can also be cascaded if required as follows: + + @code + m_pText->EnableProofCheck(true, wxTextProofOptions("fr_FR").SpellCheck(false).GrammarCheck(true)); + @endcode + + @see wxTextCtrl::EnableProofCheck(), wxTextCtrl::IsProofCheckEnabled(). +*/ +class WXDLLIMPEXP_CORE wxTextProofOptions +{ + /** + Default constructor. The proofing language is set to the current locale language, + spell checking is enabled and grammar checking is disabled. + + @param lang + The ISO 639 / ISO 3166 canonical language name of the dictionary + to be used. See wxLocale::GetCanonicalName() for examples. If an + empty string is passed (default), then the current locale will be + used. This parameter is ignored and only the current locale + language (default option) is supported at this time. + */ + wxTextProofOptions(const wxString& lang = wxEmptyString) + + /** + Enable / disable spell checking for this control. + + This option is currently hard coded to @true and is ignored. + Use the global enable parameter passed to + wxTextCtrl::EnableProofCheck() to enable / disable spell checking. + */ + wxTextProofOptions& SpellCheck(bool enable = true) + + /** + Enable / disable grammar checking for this control. + + This option is not currently supported and is ignored. + */ + wxTextProofOptions& GrammarCheck(bool enable = true) +}; /** @class wxTextCtrl @@ -1336,6 +1391,34 @@ public: */ virtual bool EmulateKeyPress(const wxKeyEvent& event); + /** + Enable or disable native spell checking on this text control if it is + available on the current platform. + + @onlyfor{wxmsw,wxgtk} + Currently wxMSW (>= Windows 7) and wxGTK3 are supported. In addition, + wxMSW use requires that the text control has the wxTE_RICH2 style + set. wxGTK3 requires that the control has the wxTE_MULTILINE style. + + @param enable + Enables native proof checking if true, disables it otherwise. + + @param options + A wxTextProofOptions object specifying the desired behaviour + of the proof checker (e.g. language to use, spell check, grammar + check, etc.). This parameter is currently unused and the control is + initialised with the default setting of current locale language / + spell check only. + + @return + @true if proof checking has been successfully enabled (and true was + passed as the enable parameter), @false otherwise. + + @since 3.1.6 + */ + virtual bool EnableProofCheck(bool enable = true, + const wxTextProofOptions& options = wxTextProofOptions()); + /** Returns the style currently used for the new text. @@ -1477,6 +1560,18 @@ public: */ bool IsSingleLine() const; + /** + Returns @true if proof (spell) checking is currently active on this + control, @false otherwise. + + @onlyfor{wxmsw,wxgtk} + + @see EnableProofCheck() + + @since 3.1.6 + */ + virtual bool IsProofCheckEnabled(); + /** Loads and displays the named file, if it exists. diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 892cd0ad36..120877f2ae 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -1205,9 +1205,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_tab->SetClientData(const_cast(static_cast(wxS("tab")))); m_enter = new MyTextCtrl( this, 100, "Multiline, allow processing.", - wxPoint(180,170), wxSize(200,70), wxTE_MULTILINE | wxTE_PROCESS_ENTER ); + wxPoint(180,170), wxSize(200,70), wxTE_MULTILINE | wxTE_PROCESS_ENTER | wxTE_RICH2 ); m_enter->SetClientData(const_cast(static_cast(wxS("enter")))); +#if wxUSE_SPELLCHECK + if ( !m_enter->EnableProofCheck(true, wxTextProofOptions("en_US").SpellCheck()) ) + { + wxMessageDialog error(this, + wxT("Spell checking is not available on this platform or control style."), + wxT("Spell checker error"), + wxOK | wxCENTER | wxICON_ERROR); + error.ShowModal(); + } + else + (*m_enter) << wxT("\nSpell checking is enabled, try typing a misspelled word..."); +#endif + m_textrich = new MyTextCtrl(this, wxID_ANY, "Allows more than 30Kb of text\n" "(on all Windows versions)\n" "and a very very very very very " diff --git a/setup.h.in b/setup.h.in index 673e540222..159f6c8989 100644 --- a/setup.h.in +++ b/setup.h.in @@ -216,6 +216,12 @@ #define wxUSE_SECRETSTORE 0 +#if (defined(__WXGTK3__) || defined(__WXMSW__)) +#define wxUSE_SPELLCHECK 0 +#else +#define wxUSE_SPELLCHECK 0 +#endif + #define wxUSE_STDPATHS 0 #define wxUSE_TEXTBUFFER 0 diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 86adcd3bd4..4d43c3e824 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -32,6 +32,12 @@ #include "wx/gtk/private.h" #include "wx/gtk/private/gtk3-compat.h" +#if wxUSE_SPELLCHECK +extern "C" { +#include +} +#endif // wxUSE_SPELLCHECK + // ---------------------------------------------------------------------------- // helpers // ---------------------------------------------------------------------------- @@ -1017,6 +1023,57 @@ void wxTextCtrl::GTKSetJustification() } } +#if wxUSE_SPELLCHECK + +bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& options) +{ + wxCHECK_MSG( IsMultiLine(), false, + "Unable to enable spell check on control " + "which does not have wxTE_MULTILINE style" ); + + GtkTextView *textview = GTK_TEXT_VIEW(m_text); + wxCHECK_MSG( textview, false, wxS("wxTextCtrl is not a GtkTextView")); + + GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview); + + if ( enable ) + { + 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; + } + else + { + if ( spell ) + gtk_spell_checker_detach(spell); + } + + return IsProofCheckEnabled(); +} + +bool wxTextCtrl::IsProofCheckEnabled() const +{ + GtkTextView *textview = GTK_TEXT_VIEW(m_text); + + if ( !IsMultiLine() || textview == NULL ) + return false; + + GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview); + + return (spell != NULL); +} + +#endif // wxUSE_SPELLCHECK + void wxTextCtrl::SetWindowStyleFlag(long style) { long styleOld = GetWindowStyleFlag(); diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 2819131b4d..47f4bc553c 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -19,7 +19,6 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" - #if wxUSE_TEXTCTRL #ifndef WX_PRECOMP @@ -77,6 +76,27 @@ #include "wx/msw/ole/oleutils.h" #include "wx/msw/private/comptr.h" + + #if wxUSE_SPELLCHECK + #include "wx/msw/wrapwin.h" + + // Add defines that are missing in MinGW. + #ifndef IMF_SPELLCHECKING + #define IMF_SPELLCHECKING 0x0800 + #endif + #ifndef SES_USECTF + #define SES_USECTF 0x00010000 + #endif + #ifndef SES_CTFALLOWEMBED + #define SES_CTFALLOWEMBED 0x00200000 + #endif + #ifndef SES_CTFALLOWSMARTTAG + #define SES_CTFALLOWSMARTTAG 0x00400000 + #endif + #ifndef SES_CTFALLOWPROOFING + #define SES_CTFALLOWPROOFING 0x00800000 + #endif + #endif // wxUSE_SPELLCHECK #endif // wxUSE_RICHEDIT #if wxUSE_INKEDIT @@ -812,6 +832,39 @@ WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const return msStyle; } +#if wxUSE_RICHEDIT && wxUSE_SPELLCHECK + +bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& WXUNUSED(options)) +{ + wxCHECK_MSG((m_windowStyle & wxTE_RICH2), false, + "Unable to enable proof checking on a control " + "that does not have wxTE_RICH2 style"); + + LPARAM editStyle = SES_USECTF | SES_CTFALLOWEMBED + | SES_CTFALLOWSMARTTAG | SES_CTFALLOWPROOFING; + ::SendMessage(GetHwnd(), EM_SETEDITSTYLE, editStyle, editStyle); + + LRESULT langOptions = ::SendMessage(GetHwnd(), EM_GETLANGOPTIONS, 0, 0); + + if ( enable ) + langOptions |= IMF_SPELLCHECKING; + else + langOptions &= ~IMF_SPELLCHECKING; + + ::SendMessage(GetHwnd(), EM_SETLANGOPTIONS, 0, langOptions); + + return IsProofCheckEnabled(); +} + +bool wxTextCtrl::IsProofCheckEnabled() const +{ + LRESULT langOptions = ::SendMessage(GetHwnd(), EM_GETLANGOPTIONS, 0, 0); + + return (langOptions & IMF_SPELLCHECKING); +} + +#endif // wxUSE_SPELLCHECK + void wxTextCtrl::SetWindowStyleFlag(long style) { // changing the alignment of the control dynamically works under Win2003 From fd9e420b422df54a906019f0a8a1346bbb2dfaac Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:41:16 +0200 Subject: [PATCH 02/14] Verify that wxUSE_SPELLCHECK is always defined Add sanity check for this symbol, as it's done for all the other wxUSE_XXXs. --- include/wx/chkconf.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index 4fa7561b9c..657baf4c81 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -282,6 +282,14 @@ # endif #endif /* !defined(wxUSE_SECRETSTORE) */ +#ifndef wxUSE_SPELLCHECK +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxUSE_SPELLCHECK must be defined, please read comment near the top of this file." +# else +# define wxUSE_SPELLCHECK 1 +# endif +#endif /* !defined(wxUSE_SPELLCHECK) */ + #ifndef wxUSE_STDPATHS # ifdef wxABORT_ON_CONFIG_ERROR # error "wxUSE_STDPATHS must be defined, please read comment near the top of this file." From d9ea30cf84fb0322b219f6359868b4c8a4c41096 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:48:14 +0200 Subject: [PATCH 03/14] Always set wxUSE_SPELLCHECK to 1 by default for simplicity It does no real harm to set it to 1 and this avoids the need for the platform checks in setup.h files, simplifying things (although it does require checking for GTK 3 in the code compiled for both GTK 2 and 3, as gtkspell library can only be used with GTK 3). --- build/cmake/setup.h.in | 4 ---- include/wx/android/setup.h | 12 ++++-------- include/wx/gtk/setup.h | 12 ++++-------- include/wx/gtk/textctrl.h | 4 ++-- include/wx/motif/setup.h | 12 ++++-------- include/wx/msw/setup.h | 12 ++++-------- include/wx/osx/setup.h | 12 ++++-------- include/wx/setup_inc.h | 12 ++++-------- include/wx/univ/setup.h | 12 ++++-------- setup.h.in | 4 ---- src/gtk/textctrl.cpp | 8 ++++---- 11 files changed, 34 insertions(+), 70 deletions(-) diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in index 29fae22477..496fa988ee 100644 --- a/build/cmake/setup.h.in +++ b/build/cmake/setup.h.in @@ -216,11 +216,7 @@ #cmakedefine01 wxUSE_SECRETSTORE -#if (defined(__WXGTK3__) || defined(__WXMSW__)) #cmakedefine01 wxUSE_SPELLCHECK -#else -#cmakedefine01 wxUSE_SPELLCHECK -#endif #cmakedefine01 wxUSE_STDPATHS diff --git a/include/wx/android/setup.h b/include/wx/android/setup.h index e427c6e0b0..03875c1dbf 100644 --- a/include/wx/android/setup.h +++ b/include/wx/android/setup.h @@ -447,17 +447,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/include/wx/gtk/setup.h b/include/wx/gtk/setup.h index 344eec7bab..85ffff1c21 100644 --- a/include/wx/gtk/setup.h +++ b/include/wx/gtk/setup.h @@ -448,17 +448,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 296bf73480..95d1f17811 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -96,13 +96,13 @@ public: // Overridden wxWindow methods virtual void SetWindowStyleFlag( long style ) wxOVERRIDE; -#if wxUSE_SPELLCHECK +#if wxUSE_SPELLCHECK && defined(__WXGTK3__) // Use native spelling and grammar checking functions. virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, const wxTextProofOptions& WXUNUSED(options) = wxTextProofOptions()) wxOVERRIDE; virtual bool IsProofCheckEnabled() const wxOVERRIDE; -#endif // wxUSE_SPELLCHECK +#endif // wxUSE_SPELLCHECK && __WXGTK3__ // Implementation from now on void OnDropFiles( wxDropFilesEvent &event ); diff --git a/include/wx/motif/setup.h b/include/wx/motif/setup.h index 1783056cbd..d6474006fb 100644 --- a/include/wx/motif/setup.h +++ b/include/wx/motif/setup.h @@ -448,17 +448,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/include/wx/msw/setup.h b/include/wx/msw/setup.h index c45bcebd1e..3a9bceef80 100644 --- a/include/wx/msw/setup.h +++ b/include/wx/msw/setup.h @@ -448,17 +448,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/include/wx/osx/setup.h b/include/wx/osx/setup.h index 1f62e4b3c2..5254f4e6b2 100644 --- a/include/wx/osx/setup.h +++ b/include/wx/osx/setup.h @@ -454,17 +454,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/include/wx/setup_inc.h b/include/wx/setup_inc.h index 28dc701f58..52b1ca4d2c 100644 --- a/include/wx/setup_inc.h +++ b/include/wx/setup_inc.h @@ -444,17 +444,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/include/wx/univ/setup.h b/include/wx/univ/setup.h index fcf5db2d92..0b07bfbdfe 100644 --- a/include/wx/univ/setup.h +++ b/include/wx/univ/setup.h @@ -447,17 +447,13 @@ // Recommended setting: 1 (but may be safely disabled if you don't use it) #define wxUSE_SECRETSTORE 1 -// Allow the use of the OS built-in spellchecker on wxTextCtrl (multiline -// only). Currently only wxGTK3 and wxMSW are implemented. +// Allow the use of the OS built-in spell checker in wxTextCtrl. // -// Default is 1 on wxGTK3 and wxMSW platforms and 0 otherwise. +// Default is 1, the corresponding wxTextCtrl functions simply won't do +// anything if the functionality is not supported by the current platform. // -// Recommended setting: 1 on supported platforms. -#if (defined(__WXGTK3__) || defined(__WXMSW__)) +// Recommended setting: 1 unless you want to save a tiny bit of code. #define wxUSE_SPELLCHECK 1 -#else -#define wxUSE_SPELLCHECK 0 -#endif // Use wxStandardPaths class which allows to retrieve some standard locations // in the file system diff --git a/setup.h.in b/setup.h.in index 159f6c8989..3e3f576193 100644 --- a/setup.h.in +++ b/setup.h.in @@ -216,11 +216,7 @@ #define wxUSE_SECRETSTORE 0 -#if (defined(__WXGTK3__) || defined(__WXMSW__)) #define wxUSE_SPELLCHECK 0 -#else -#define wxUSE_SPELLCHECK 0 -#endif #define wxUSE_STDPATHS 0 diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 4d43c3e824..7f7adab532 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -32,11 +32,11 @@ #include "wx/gtk/private.h" #include "wx/gtk/private/gtk3-compat.h" -#if wxUSE_SPELLCHECK +#if wxUSE_SPELLCHECK && defined(__WXGTK3__) extern "C" { #include } -#endif // wxUSE_SPELLCHECK +#endif // wxUSE_SPELLCHECK && __WXGTK3__ // ---------------------------------------------------------------------------- // helpers @@ -1023,7 +1023,7 @@ void wxTextCtrl::GTKSetJustification() } } -#if wxUSE_SPELLCHECK +#if wxUSE_SPELLCHECK && defined(__WXGTK3__) bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& options) { @@ -1072,7 +1072,7 @@ bool wxTextCtrl::IsProofCheckEnabled() const return (spell != NULL); } -#endif // wxUSE_SPELLCHECK +#endif // wxUSE_SPELLCHECK && __WXGTK3__ void wxTextCtrl::SetWindowStyleFlag(long style) { From 01d3a96043ae077311daf73f5bc672d3a91a6816 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:53:30 +0200 Subject: [PATCH 04/14] Reduce configure warnings about missing spell checking support It's not really useful to warn that spell checking is not available for the ports for which it's not implemented anyhow, as there is nothing that the person running configure can do about it anyhow. Still warn about missing gtkspell library when using GTK 3, however, as it may be useful to know that it's not available and could be installed in order to activate spell checking support. --- configure | 35 ++++++++++------------------------- configure.in | 44 +++++++++++++++----------------------------- 2 files changed, 25 insertions(+), 54 deletions(-) diff --git a/configure b/configure index aa6780aed7..6f39a87d9d 100755 --- a/configure +++ b/configure @@ -33977,11 +33977,7 @@ fi if test "$wxUSE_SPELLCHECK" = "yes"; then - if test "$wxUSE_MSW" = 1 -o test "$wxUSE_OSX_COCOA" = 1; then - has_spellcheck_support=yes - - elif test "$wxUSE_GTK" = 1; then - if test "$WXGTK3" = 1; then + if test "$WXGTK3" = 1; then pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GTKSPELL" >&5 @@ -34042,16 +34038,16 @@ fi echo "$GTKSPELL_PKG_ERRORS" >&5 - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&5 -$as_echo "$as_me: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&2;} - has_spellcheck_support=no + { $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: WARNING: gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available" >&2;} + wxUSE_SPELLCHECK=no elif test $pkg_failed = untried; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&5 -$as_echo "$as_me: WARNING: gtkspell3-3.0 not found, spellchecking won't be available" >&2;} - has_spellcheck_support=no + { $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: WARNING: gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available" >&2;} + wxUSE_SPELLCHECK=no else @@ -34060,24 +34056,13 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" - LIBS="$GTKSPELL_LIBS $LIBS" - has_spellcheck_support=yes + CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" + LIBS="$GTKSPELL_LIBS $LIBS" fi - else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Spellchecking is not supported on GTK < 3" >&5 -$as_echo "$as_me: WARNING: Spellchecking is not supported on GTK < 3" >&2;} - has_spellcheck_support=no - fi - - else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Spellchecking is not supported on this platform" >&5 -$as_echo "$as_me: WARNING: Spellchecking is not supported on this platform" >&2;} - has_spellcheck_support=no fi - if test "$has_spellcheck_support" = "yes"; then + if test "$wxUSE_SPELLCHECK" = "yes"; then $as_echo "#define wxUSE_SPELLCHECK 1" >>confdefs.h fi diff --git a/configure.in b/configure.in index 812d27b0c1..b7abeb7c27 100644 --- a/configure.in +++ b/configure.in @@ -5768,38 +5768,24 @@ dnl Spellchecking for wxTextCtrl dnl --------------------------------------------------------------------------- if test "$wxUSE_SPELLCHECK" = "yes"; then - dnl The required APIs are always available under MSW and OS X but we must - dnl have GTK3 and GNOME gtkspell under Unix to be able to compile this feature. + 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 we need to check for gtkspell library. - if test "$wxUSE_MSW" = 1 -o test "$wxUSE_OSX_COCOA" = 1; then - dnl Always available under these systems - has_spellcheck_support=yes - - elif test "$wxUSE_GTK" = 1; then - if test "$WXGTK3" = 1; then - PKG_CHECK_MODULES(GTKSPELL, [gtkspell3-3.0], - [ - CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" - LIBS="$GTKSPELL_LIBS $LIBS" - has_spellcheck_support=yes - ], - [ - AC_MSG_WARN([gtkspell3-3.0 not found, spellchecking won't be available]) - has_spellcheck_support=no - ] - ) - else - AC_MSG_WARN([Spellchecking is not supported on GTK < 3]) - has_spellcheck_support=no - fi - - else - dnl Not implemented in the other ports yet. - AC_MSG_WARN([Spellchecking is not supported on this platform]) - has_spellcheck_support=no + if test "$WXGTK3" = 1; then + PKG_CHECK_MODULES(GTKSPELL, [gtkspell3-3.0], + [ + CXXFLAGS="$GTKSPELL_CFLAGS $CXXFLAGS" + LIBS="$GTKSPELL_LIBS $LIBS" + ], + [ + AC_MSG_WARN([gtkspell3-3.0 not found, spell checking in wxTextCtrl won't be available]) + wxUSE_SPELLCHECK=no + ] + ) fi - if test "$has_spellcheck_support" = "yes"; then + if test "$wxUSE_SPELLCHECK" = "yes"; then AC_DEFINE(wxUSE_SPELLCHECK) fi fi From 05df6e03905de3233ae0b7f297423ae850edcf78 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 21:58:06 +0200 Subject: [PATCH 05/14] Slightly reformat EnableProofCheck() declarations Keep the entire wxTextProofOptions argument on the same line. Remove unnecessary WXUNUSED() in the declarations of the function in wxMSW/wxGTK headers. No real changes. --- include/wx/gtk/textctrl.h | 7 ++++--- include/wx/msw/textctrl.h | 7 ++++--- include/wx/textctrl.h | 11 +++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 95d1f17811..0274a89154 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -98,9 +98,10 @@ public: #if wxUSE_SPELLCHECK && defined(__WXGTK3__) // Use native spelling and grammar checking functions. - virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, - const wxTextProofOptions& WXUNUSED(options) = - wxTextProofOptions()) wxOVERRIDE; + virtual bool EnableProofCheck( + bool enable = true, + const wxTextProofOptions& options = wxTextProofOptions() + ) wxOVERRIDE; virtual bool IsProofCheckEnabled() const wxOVERRIDE; #endif // wxUSE_SPELLCHECK && __WXGTK3__ diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index d7f8d04cc8..adbdfc40c5 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -114,9 +114,10 @@ public: #if wxUSE_RICHEDIT && wxUSE_SPELLCHECK // Use native spelling and grammar checking functions. // This is only available in wxTE_RICH2 controls. - virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, - const wxTextProofOptions& WXUNUSED(options) = - wxTextProofOptions()) wxOVERRIDE; + virtual bool EnableProofCheck( + bool enable = true, + const wxTextProofOptions& options = wxTextProofOptions() + ) wxOVERRIDE; virtual bool IsProofCheckEnabled() const wxOVERRIDE; #endif // wxUSE_RICHEDIT && wxUSE_SPELLCHECK diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 66e3f8135e..b195287c58 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -799,10 +799,13 @@ public: #if wxUSE_SPELLCHECK // Use native spelling and grammar checking functions. - virtual bool EnableProofCheck(bool WXUNUSED(enable) = true, - const wxTextProofOptions& WXUNUSED(options) = - wxTextProofOptions()) - { return false; } + virtual bool EnableProofCheck( + bool WXUNUSED(enable) = true, + const wxTextProofOptions& WXUNUSED(options) = wxTextProofOptions() + ) + { + return false; + } virtual bool IsProofCheckEnabled() const { return false; } #endif // wxUSE_SPELLCHECK From 25f912749983e77a46af1ae515f13636213ffa21 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 22:07:34 +0200 Subject: [PATCH 06/14] Mark wxTextProofOptions as being new in 3.1.6 in the docs too --- interface/wx/textctrl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index f888778f41..dcd99c3dc0 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1002,6 +1002,8 @@ public: @endcode @see wxTextCtrl::EnableProofCheck(), wxTextCtrl::IsProofCheckEnabled(). + + @since 3.1.6 */ class WXDLLIMPEXP_CORE wxTextProofOptions { From af43b7c9652568d95233acb3de412fb994eefb06 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 01:16:21 +0200 Subject: [PATCH 07/14] Correct description of EnableProofCheck() requirements This functionality is available since Windows 8 only, not 7. --- interface/wx/textctrl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index dcd99c3dc0..df08b15921 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1397,10 +1397,10 @@ public: Enable or disable native spell checking on this text control if it is available on the current platform. - @onlyfor{wxmsw,wxgtk} - Currently wxMSW (>= Windows 7) and wxGTK3 are supported. In addition, - wxMSW use requires that the text control has the wxTE_RICH2 style - set. wxGTK3 requires that the control has the wxTE_MULTILINE style. + Currently this is supported in wxMSW (when running under Windows 8 or + later) and wxGTK when using GTK 3. In addition, wxMSW requires that the + text control has the wxTE_RICH2 style set. wxGTK3 requires that the + control has the wxTE_MULTILINE style. @param enable Enables native proof checking if true, disables it otherwise. From 90e79d8ed413ae94628d61d14137365bc350efde Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Aug 2021 22:11:39 +0200 Subject: [PATCH 08/14] Implement minimal support for spell checking in wxOSX too Reuse the existing CheckSpelling() function. Also deprecate wxTextCtrl::MacCheckSpelling() in favour of the new portable EnableProofCheck(). --- include/wx/osx/cocoa/private/textimpl.h | 1 + include/wx/osx/core/private.h | 1 + include/wx/osx/iphone/private/textimpl.h | 2 ++ include/wx/osx/textctrl.h | 15 ++++++++++++++- interface/wx/textctrl.h | 11 +++++------ src/osx/cocoa/textctrl.mm | 5 +++++ src/osx/iphone/textctrl.mm | 5 +++++ src/osx/textctrl_osx.cpp | 21 +++++++++++++++++++++ 8 files changed, 54 insertions(+), 7 deletions(-) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index c96cb52944..9c6b5f884a 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -128,6 +128,7 @@ public: virtual bool HasOwnContextMenu() const wxOVERRIDE { return true; } virtual void CheckSpelling(bool check) wxOVERRIDE; + virtual bool IsSpellingCheckEnabled() const wxOVERRIDE; virtual void EnableAutomaticQuoteSubstitution(bool enable) wxOVERRIDE; virtual void EnableAutomaticDashSubstitution(bool enable) wxOVERRIDE; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index d32434c800..326e6e963f 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -738,6 +738,7 @@ public : virtual int GetLineLength(long lineNo) const ; virtual wxString GetLineText(long lineNo) const ; virtual void CheckSpelling(bool WXUNUSED(check)) { } + virtual bool IsSpellingCheckEnabled() const { return false; } virtual void EnableAutomaticQuoteSubstitution(bool WXUNUSED(enable)) {} virtual void EnableAutomaticDashSubstitution(bool WXUNUSED(enable)) {} diff --git a/include/wx/osx/iphone/private/textimpl.h b/include/wx/osx/iphone/private/textimpl.h index 96b52e6d05..c9beb7818a 100644 --- a/include/wx/osx/iphone/private/textimpl.h +++ b/include/wx/osx/iphone/private/textimpl.h @@ -72,6 +72,8 @@ public: virtual bool HasOwnContextMenu() const { return true; } virtual void CheckSpelling(bool check); + virtual bool IsSpellingCheckEnabled() const; + virtual wxSize GetBestSize() const; protected: diff --git a/include/wx/osx/textctrl.h b/include/wx/osx/textctrl.h index a784e39ac6..6adba7f4bb 100644 --- a/include/wx/osx/textctrl.h +++ b/include/wx/osx/textctrl.h @@ -97,6 +97,15 @@ public: virtual void Cut() wxOVERRIDE; virtual void Paste() wxOVERRIDE; +#if wxUSE_SPELLCHECK + // Use native spelling and grammar checking functions (multiline only). + virtual bool EnableProofCheck( + bool enable = true, + const wxTextProofOptions& options = wxTextProofOptions() + ) wxOVERRIDE; + virtual bool IsProofCheckEnabled() const wxOVERRIDE; +#endif // wxUSE_SPELLCHECK + // Implementation // -------------- virtual void Command(wxCommandEvent& event) wxOVERRIDE; @@ -130,7 +139,11 @@ public: virtual void MacVisibilityChanged() wxOVERRIDE; virtual void MacSuperChangedPosition() wxOVERRIDE; - virtual void MacCheckSpelling(bool check); + + // Use portable EnableProofCheck() instead now. +#if WXWIN_COMPATIBILITY_3_0 + wxDEPRECATED( virtual void MacCheckSpelling(bool check) ); +#endif // WXWIN_COMPATIBILITY_3_0 void OSXEnableAutomaticQuoteSubstitution(bool enable); void OSXEnableAutomaticDashSubstitution(bool enable); diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index df08b15921..5e6378f6c4 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1398,9 +1398,9 @@ public: available on the current platform. Currently this is supported in wxMSW (when running under Windows 8 or - later) and wxGTK when using GTK 3. In addition, wxMSW requires that the - text control has the wxTE_RICH2 style set. wxGTK3 requires that the - control has the wxTE_MULTILINE style. + 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 + require that the control has the wxTE_MULTILINE style. @param enable Enables native proof checking if true, disables it otherwise. @@ -1566,9 +1566,8 @@ public: Returns @true if proof (spell) checking is currently active on this control, @false otherwise. - @onlyfor{wxmsw,wxgtk} - - @see EnableProofCheck() + This function is implemented for the same platforms as + EnableProofCheck() and returns @false for the other ones. @since 3.1.6 */ diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index b8bab36b96..91e62092b2 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -1283,6 +1283,11 @@ void wxNSTextViewControl::CheckSpelling(bool check) [m_textView setContinuousSpellCheckingEnabled: check]; } +bool wxNSTextViewControl::IsSpellingCheckEnabled() const +{ + return m_textView && m_textView.continuousSpellCheckingEnabled; +} + void wxNSTextViewControl::EnableAutomaticQuoteSubstitution(bool enable) { if (m_textView) diff --git a/src/osx/iphone/textctrl.mm b/src/osx/iphone/textctrl.mm index 7a1d785c64..9be4a74c09 100644 --- a/src/osx/iphone/textctrl.mm +++ b/src/osx/iphone/textctrl.mm @@ -504,6 +504,11 @@ void wxUITextViewControl::CheckSpelling(bool check) { } +bool wxUITextViewControl::IsSpellingCheckEnabled() const +{ + return false; +} + wxSize wxUITextViewControl::GetBestSize() const { wxRect r; diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 31a3bcebcb..ba21007e46 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -124,10 +124,12 @@ void wxTextCtrl::MacVisibilityChanged() { } +#if WXWIN_COMPATIBILITY_3_0 void wxTextCtrl::MacCheckSpelling(bool check) { GetTextPeer()->CheckSpelling(check); } +#endif // WXWIN_COMPATIBILITY_3_0 void wxTextCtrl::OSXEnableAutomaticQuoteSubstitution(bool enable) { @@ -340,6 +342,25 @@ void wxTextCtrl::Paste() } } +#if wxUSE_SPELLCHECK + +bool wxTextCtrl::EnableProofCheck( + bool enable, + const wxTextProofOptions& WXUNUSED(options) + ) +{ + GetTextPeer()->CheckSpelling(enable); + + return true; +} + +bool wxTextCtrl::IsProofCheckEnabled() const +{ + return GetTextPeer()->IsSpellingCheckEnabled(); +} + +#endif // wxUSE_SPELLCHECK + void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) { // By default, load the first file into the text window. From 72ef834c704addcc7a627b88580b18e5b3ff1644 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 00:33:10 +0200 Subject: [PATCH 09/14] Don't use DLL export declaration with wxTextProofOptions This class doesn't have any non-inline methods, so applying DLL export declaration to it is at best useless and might even be harmful, so don't do it. --- include/wx/textctrl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index b195287c58..84695ec409 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -133,7 +133,7 @@ enum wxTextCtrlHitTestResult // Passed to ::EnableProofCheck() to configure the proofing options for // this control // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxTextProofOptions +class wxTextProofOptions { public: wxTextProofOptions(const wxString& lang = wxEmptyString) From 2bb3083a938b312799d200c0f91a90bca6b71253 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 00:53:58 +0200 Subject: [PATCH 10/14] Use wxTextProofOptions itself to enable or disable the checks Remove a separate "bool enable" argument of EnableProofCheck() and use wxTextProofOptions::IsSpellCheckingEnabled() to decide whether the checks should be enabled or disabled. Also remove wxTextProofOptions ctor and provide named static factory functions for creating the objects of this class with clearly defined meaning. --- include/wx/gtk/textctrl.h | 6 ++-- include/wx/msw/textctrl.h | 6 ++-- include/wx/osx/textctrl.h | 6 ++-- include/wx/textctrl.h | 46 +++++++++++++++++++------ interface/wx/textctrl.h | 72 +++++++++++++++++++++------------------ samples/text/text.cpp | 6 +++- src/gtk/textctrl.cpp | 4 +-- src/msw/textctrl.cpp | 4 +-- src/osx/textctrl_osx.cpp | 7 ++-- 9 files changed, 91 insertions(+), 66 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 0274a89154..390e27987f 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -98,10 +98,8 @@ public: #if wxUSE_SPELLCHECK && defined(__WXGTK3__) // Use native spelling and grammar checking functions. - virtual bool EnableProofCheck( - bool enable = true, - const wxTextProofOptions& options = wxTextProofOptions() - ) wxOVERRIDE; + virtual bool EnableProofCheck(const wxTextProofOptions& options + = wxTextProofOptions::Default()) wxOVERRIDE; virtual bool IsProofCheckEnabled() const wxOVERRIDE; #endif // wxUSE_SPELLCHECK && __WXGTK3__ diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index adbdfc40c5..1383120402 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -114,10 +114,8 @@ public: #if wxUSE_RICHEDIT && wxUSE_SPELLCHECK // Use native spelling and grammar checking functions. // This is only available in wxTE_RICH2 controls. - virtual bool EnableProofCheck( - bool enable = true, - const wxTextProofOptions& options = wxTextProofOptions() - ) wxOVERRIDE; + virtual bool EnableProofCheck(const wxTextProofOptions& options + = wxTextProofOptions::Default()) wxOVERRIDE; virtual bool IsProofCheckEnabled() const wxOVERRIDE; #endif // wxUSE_RICHEDIT && wxUSE_SPELLCHECK diff --git a/include/wx/osx/textctrl.h b/include/wx/osx/textctrl.h index 6adba7f4bb..0bc924713d 100644 --- a/include/wx/osx/textctrl.h +++ b/include/wx/osx/textctrl.h @@ -99,10 +99,8 @@ public: #if wxUSE_SPELLCHECK // Use native spelling and grammar checking functions (multiline only). - virtual bool EnableProofCheck( - bool enable = true, - const wxTextProofOptions& options = wxTextProofOptions() - ) wxOVERRIDE; + virtual bool EnableProofCheck(const wxTextProofOptions& options + = wxTextProofOptions::Default()) wxOVERRIDE; virtual bool IsProofCheckEnabled() const wxOVERRIDE; #endif // wxUSE_SPELLCHECK diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 84695ec409..12553337c0 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -129,20 +129,29 @@ enum wxTextCtrlHitTestResult #if wxUSE_SPELLCHECK // ---------------------------------------------------------------------------- -// wxTextCtrl proof options object -// Passed to ::EnableProofCheck() to configure the proofing options for -// this control +// This object can be passed to wxTextCtrl::EnableProofCheck() to configure the +// proofing options for this control. // ---------------------------------------------------------------------------- class wxTextProofOptions { public: - wxTextProofOptions(const wxString& lang = wxEmptyString) - : m_lang(lang) + // Return the object corresponding to the default options: current + // language, spell checking enabled, grammar checking disabled. + static wxTextProofOptions Default() { - m_EnableSpellCheck = true; - m_EnableGrammarCheck = false; + wxTextProofOptions opts; + return opts.SpellCheck(true); } + // Return the object with all checks disabled. + static wxTextProofOptions Disable() + { + return wxTextProofOptions(); + } + + // Default copy ctor, assignment operator and dtor are ok + + // Methods that can be used to set the various options. wxTextProofOptions& SpellCheck(bool enable = true) { m_EnableSpellCheck = enable; @@ -155,9 +164,26 @@ public: return *this; } + wxTextProofOptions& Language(const wxString& lang) + { + m_lang = lang; + return *this; + } + + // And the corresponding accessors. + bool IsSpellCheckingEnabled() const { return m_EnableSpellCheck; } + bool IsGrammarCheckingEnabled() const { return m_EnableGrammarCheck; } const wxString& GetLang() const { return m_lang; } private: + // Ctor is private, use static factory methods to create objects of this + // class. + wxTextProofOptions() + { + m_EnableSpellCheck = + m_EnableGrammarCheck = false; + } + wxString m_lang; bool m_EnableSpellCheck; bool m_EnableGrammarCheck; @@ -799,10 +825,8 @@ public: #if wxUSE_SPELLCHECK // Use native spelling and grammar checking functions. - virtual bool EnableProofCheck( - bool WXUNUSED(enable) = true, - const wxTextProofOptions& WXUNUSED(options) = wxTextProofOptions() - ) + virtual bool EnableProofCheck(const wxTextProofOptions& WXUNUSED(options) + = wxTextProofOptions::Default()) { return false; } diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index 5e6378f6c4..73122f5444 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -982,24 +982,27 @@ public: @class wxTextProofOptions This class provides a convenient means of passing multiple parameters to - wxTextCtrl::EnableProofCheck(). Typical (and the default) usage is: + wxTextCtrl::EnableProofCheck(). + + By default, i.e. when calling EnableProofCheck() without any parameters, + Default() proof options are used, which enable spelling (but not grammar) + checks for the current language. + + However it is also possible to customize the options: @code - m_pText->EnableProofCheck(true, wxTextProofOptions(wxEmptyString).SpellCheck(true)); + textctrl->EnableProofCheck(wxTextProofOptions::Default().Language("fr").GrammarCheck()); @endcode - If this is the exact behaviour desired, then the parameters can be omitted. - The following code will have the same result: + or disable the all checks entirely: @code - m_pText->EnableProofCheck(); + textctrl->EnableProofCheck(wxTextProofOptions::Disable()); @endcode - Options can also be cascaded if required as follows: - - @code - m_pText->EnableProofCheck(true, wxTextProofOptions("fr_FR").SpellCheck(false).GrammarCheck(true)); - @endcode + Note that this class has no public constructor, except for the copy + constructor, so its objects can only be created using the static factory + methods Default() or Disable(). @see wxTextCtrl::EnableProofCheck(), wxTextCtrl::IsProofCheckEnabled(). @@ -1008,24 +1011,22 @@ public: class WXDLLIMPEXP_CORE wxTextProofOptions { /** - Default constructor. The proofing language is set to the current locale language, - spell checking is enabled and grammar checking is disabled. + Create an object corresponding to the default checks. - @param lang - The ISO 639 / ISO 3166 canonical language name of the dictionary - to be used. See wxLocale::GetCanonicalName() for examples. If an - empty string is passed (default), then the current locale will be - used. This parameter is ignored and only the current locale - language (default option) is supported at this time. + The returned object enables spelling checks and disables grammar checks. */ - wxTextProofOptions(const wxString& lang = wxEmptyString) + static wxTextProofOptions Default() + + /** + Create an object disabling all checks. + + The returned object can be passed to wxTextCtrl::EnableProofCheck() to + disable all checks in the text control. + */ + static wxTextProofOptions Disable() /** Enable / disable spell checking for this control. - - This option is currently hard coded to @true and is ignored. - Use the global enable parameter passed to - wxTextCtrl::EnableProofCheck() to enable / disable spell checking. */ wxTextProofOptions& SpellCheck(bool enable = true) @@ -1035,6 +1036,12 @@ class WXDLLIMPEXP_CORE wxTextProofOptions This option is not currently supported and is ignored. */ wxTextProofOptions& GrammarCheck(bool enable = true) + + /// Return true if spell checking is enabled. + bool IsSpellCheckingEnabled() const; + + /// Return true if grammar checking is enabled. + bool IsGrammarCheckingEnabled() const; }; /** @@ -1402,24 +1409,23 @@ public: that the text control has the wxTE_RICH2 style set. wxGTK3 and wxOSX require that the control has the wxTE_MULTILINE style. - @param enable - Enables native proof checking if true, disables it otherwise. - @param options A wxTextProofOptions object specifying the desired behaviour of the proof checker (e.g. language to use, spell check, grammar - check, etc.). This parameter is currently unused and the control is - initialised with the default setting of current locale language / - spell check only. + check, etc.) and whether the proof checks should be enabled at all. + By default, spelling checks for the current language are enabled. + Passing wxTextProofOptions::Disable() disables all the checks. @return - @true if proof checking has been successfully enabled (and true was - passed as the enable parameter), @false otherwise. + @true if proof checking has been successfully enabled or disabled, + @false otherwise (usually because the corresponding functionality + is not available under the current platform or for this type of + text control). @since 3.1.6 */ - virtual bool EnableProofCheck(bool enable = true, - const wxTextProofOptions& options = wxTextProofOptions()); + virtual bool EnableProofCheck(const wxTextProofOptions& options + = wxTextProofOptions::Default()); /** Returns the style currently used for the new text. diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 120877f2ae..4a9fd1d33a 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -1209,7 +1209,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_enter->SetClientData(const_cast(static_cast(wxS("enter")))); #if wxUSE_SPELLCHECK - if ( !m_enter->EnableProofCheck(true, wxTextProofOptions("en_US").SpellCheck()) ) + // Enable grammar check just for demonstration purposes (note that it's + // only supported under Mac, but spell checking will be enabled under the + // other platforms too, if supported). If we didn't want to enable it, we + // could omit the EnableProofCheck() argument entirely. + if ( !m_enter->EnableProofCheck(wxTextProofOptions::Default().GrammarCheck()) ) { wxMessageDialog error(this, wxT("Spell checking is not available on this platform or control style."), diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 7f7adab532..3c5f5e8427 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1025,7 +1025,7 @@ void wxTextCtrl::GTKSetJustification() #if wxUSE_SPELLCHECK && defined(__WXGTK3__) -bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& options) +bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) { wxCHECK_MSG( IsMultiLine(), false, "Unable to enable spell check on control " @@ -1036,7 +1036,7 @@ bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& options GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview); - if ( enable ) + if ( options.IsSpellCheckingEnabled() ) { if ( !spell ) { diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 47f4bc553c..d2a9082a9d 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -834,7 +834,7 @@ WXDWORD wxTextCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const #if wxUSE_RICHEDIT && wxUSE_SPELLCHECK -bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& WXUNUSED(options)) +bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) { wxCHECK_MSG((m_windowStyle & wxTE_RICH2), false, "Unable to enable proof checking on a control " @@ -846,7 +846,7 @@ bool wxTextCtrl::EnableProofCheck(bool enable, const wxTextProofOptions& WXUNUSE LRESULT langOptions = ::SendMessage(GetHwnd(), EM_GETLANGOPTIONS, 0, 0); - if ( enable ) + if ( options.IsSpellCheckingEnabled() ) langOptions |= IMF_SPELLCHECKING; else langOptions &= ~IMF_SPELLCHECKING; diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index ba21007e46..1af21da2ca 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -344,12 +344,9 @@ void wxTextCtrl::Paste() #if wxUSE_SPELLCHECK -bool wxTextCtrl::EnableProofCheck( - bool enable, - const wxTextProofOptions& WXUNUSED(options) - ) +bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) { - GetTextPeer()->CheckSpelling(enable); + GetTextPeer()->CheckSpelling(options.IsSpellCheckingEnabled()); return true; } From 79fe43c22daff6c6d742f24aa12035a368dba730 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 00:58:00 +0200 Subject: [PATCH 11/14] Don't show message box in text sample unnecessarily This is going to be just annoying on the platforms where spell checking is not supported, so show the message inside the text control itself rather than popping up a message box. Also put a misspelled word in the control from the very beginning to show that it is highlighted. --- samples/text/text.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/samples/text/text.cpp b/samples/text/text.cpp index 4a9fd1d33a..44a680b125 100644 --- a/samples/text/text.cpp +++ b/samples/text/text.cpp @@ -1209,20 +1209,23 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) m_enter->SetClientData(const_cast(static_cast(wxS("enter")))); #if wxUSE_SPELLCHECK + (*m_enter) << "\n"; + // Enable grammar check just for demonstration purposes (note that it's // only supported under Mac, but spell checking will be enabled under the // other platforms too, if supported). If we didn't want to enable it, we // could omit the EnableProofCheck() argument entirely. if ( !m_enter->EnableProofCheck(wxTextProofOptions::Default().GrammarCheck()) ) { - wxMessageDialog error(this, - wxT("Spell checking is not available on this platform or control style."), - wxT("Spell checker error"), - wxOK | wxCENTER | wxICON_ERROR); - error.ShowModal(); + (*m_enter) << "Spell checking is not available on this platform, sorry."; } else - (*m_enter) << wxT("\nSpell checking is enabled, try typing a misspelled word..."); + { + // Break the string in several parts to avoid misspellings in the sources. + (*m_enter) << "Spell checking is enabled, mis" + "s" + "spelled words should be highlighted."; + } #endif m_textrich = new MyTextCtrl(this, wxID_ANY, "Allows more than 30Kb of text\n" From db303979219d568b7e22808fd43e24ba33e3cc19 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 01:11:29 +0200 Subject: [PATCH 12/14] Implement support for grammar checking in wxOSX Use native support for grammar checking in NSTextView. As we're not passing wxTextProofOptions to the lower level function, this functionality now depends on wxUSE_SPELLCHECK, meaning that even the previously existing MacCheckSpelling() function is not defined any more when wxUSE_SPELLCHECK is set to 0. This is not completely backwards-compatible, but hopefully shouldn't be a problem in practice and shouldn't break any existing applications which can't disable the just added wxUSE_SPELLCHECK. --- include/wx/osx/cocoa/private/textimpl.h | 4 +++- include/wx/osx/core/private.h | 6 +++++- include/wx/osx/iphone/private/textimpl.h | 4 +++- include/wx/osx/textctrl.h | 4 ++-- interface/wx/textctrl.h | 3 ++- src/osx/cocoa/textctrl.mm | 12 +++++++++--- src/osx/iphone/textctrl.mm | 6 +++++- src/osx/textctrl_osx.cpp | 9 +++++---- 8 files changed, 34 insertions(+), 14 deletions(-) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index 9c6b5f884a..2984375992 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -127,8 +127,10 @@ public: virtual bool HasOwnContextMenu() const wxOVERRIDE { return true; } - virtual void CheckSpelling(bool check) wxOVERRIDE; +#if wxUSE_SPELLCHECK + virtual void CheckSpelling(const wxTextProofOptions& options) wxOVERRIDE; virtual bool IsSpellingCheckEnabled() const wxOVERRIDE; +#endif // wxUSE_SPELLCHECK virtual void EnableAutomaticQuoteSubstitution(bool enable) wxOVERRIDE; virtual void EnableAutomaticDashSubstitution(bool enable) wxOVERRIDE; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 326e6e963f..4dd3074b7c 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -77,6 +77,8 @@ WXDLLIMPEXP_BASE CFURLRef wxOSXCreateURLFromFileSystemPath( const wxString& path #include "wx/bitmap.h" #include "wx/window.h" +class wxTextProofOptions; + class WXDLLIMPEXP_CORE wxMacCGContextStateSaver { wxDECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver); @@ -737,8 +739,10 @@ public : virtual void ShowPosition(long pos) ; virtual int GetLineLength(long lineNo) const ; virtual wxString GetLineText(long lineNo) const ; - virtual void CheckSpelling(bool WXUNUSED(check)) { } +#if wxUSE_SPELLCHECK + virtual void CheckSpelling(const wxTextProofOptions& WXUNUSED(options)) { } virtual bool IsSpellingCheckEnabled() const { return false; } +#endif // wxUSE_SPELLCHECK virtual void EnableAutomaticQuoteSubstitution(bool WXUNUSED(enable)) {} virtual void EnableAutomaticDashSubstitution(bool WXUNUSED(enable)) {} diff --git a/include/wx/osx/iphone/private/textimpl.h b/include/wx/osx/iphone/private/textimpl.h index c9beb7818a..1a2876e4fe 100644 --- a/include/wx/osx/iphone/private/textimpl.h +++ b/include/wx/osx/iphone/private/textimpl.h @@ -71,8 +71,10 @@ public: virtual bool HasOwnContextMenu() const { return true; } - virtual void CheckSpelling(bool check); +#if wxUSE_SPELLCHECK + virtual void CheckSpelling(const wxTextProofOptions& options); virtual bool IsSpellingCheckEnabled() const; +#endif // wxUSE_SPELLCHECK virtual wxSize GetBestSize() const; diff --git a/include/wx/osx/textctrl.h b/include/wx/osx/textctrl.h index 0bc924713d..b528ee0887 100644 --- a/include/wx/osx/textctrl.h +++ b/include/wx/osx/textctrl.h @@ -139,9 +139,9 @@ public: virtual void MacSuperChangedPosition() wxOVERRIDE; // Use portable EnableProofCheck() instead now. -#if WXWIN_COMPATIBILITY_3_0 +#if WXWIN_COMPATIBILITY_3_0 && wxUSE_SPELLCHECK wxDEPRECATED( virtual void MacCheckSpelling(bool check) ); -#endif // WXWIN_COMPATIBILITY_3_0 +#endif // WXWIN_COMPATIBILITY_3_0 && wxUSE_SPELLCHECK void OSXEnableAutomaticQuoteSubstitution(bool enable); void OSXEnableAutomaticDashSubstitution(bool enable); diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index 73122f5444..6dd7216e03 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1033,7 +1033,8 @@ class WXDLLIMPEXP_CORE wxTextProofOptions /** Enable / disable grammar checking for this control. - This option is not currently supported and is ignored. + This option is currently only supported under macOS and is ignored under + the other platforms. */ wxTextProofOptions& GrammarCheck(bool enable = true) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 91e62092b2..23f9b95ce0 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -1277,10 +1277,14 @@ void wxNSTextViewControl::SetStyle(long start, } } -void wxNSTextViewControl::CheckSpelling(bool check) +#if wxUSE_SPELLCHECK + +void wxNSTextViewControl::CheckSpelling(const wxTextProofOptions& options) { - if (m_textView) - [m_textView setContinuousSpellCheckingEnabled: check]; + wxCHECK_RET( m_textView, "control must be created first" ); + + m_textView.continuousSpellCheckingEnabled = options.IsSpellCheckingEnabled(); + m_textView.grammarCheckingEnabled = options.IsGrammarCheckingEnabled(); } bool wxNSTextViewControl::IsSpellingCheckEnabled() const @@ -1288,6 +1292,8 @@ bool wxNSTextViewControl::IsSpellingCheckEnabled() const return m_textView && m_textView.continuousSpellCheckingEnabled; } +#endif // wxUSE_SPELLCHECK + void wxNSTextViewControl::EnableAutomaticQuoteSubstitution(bool enable) { if (m_textView) diff --git a/src/osx/iphone/textctrl.mm b/src/osx/iphone/textctrl.mm index 9be4a74c09..889cf3c676 100644 --- a/src/osx/iphone/textctrl.mm +++ b/src/osx/iphone/textctrl.mm @@ -500,7 +500,9 @@ void wxUITextViewControl::SetStyle(long start, } } -void wxUITextViewControl::CheckSpelling(bool check) +#if wxUSE_SPELLCHECK + +void wxUITextViewControl::CheckSpelling(const wxTextProofOptions& WXUNUSED(options)) { } @@ -509,6 +511,8 @@ bool wxUITextViewControl::IsSpellingCheckEnabled() const return false; } +#endif // wxUSE_SPELLCHECK + wxSize wxUITextViewControl::GetBestSize() const { wxRect r; diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 1af21da2ca..969e6a9d48 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -124,12 +124,13 @@ void wxTextCtrl::MacVisibilityChanged() { } -#if WXWIN_COMPATIBILITY_3_0 +#if WXWIN_COMPATIBILITY_3_0 && wxUSE_SPELLCHECK void wxTextCtrl::MacCheckSpelling(bool check) { - GetTextPeer()->CheckSpelling(check); + GetTextPeer()->CheckSpelling(check ? wxTextProofOptions::Default() + : wxTextProofOptions::Disable()); } -#endif // WXWIN_COMPATIBILITY_3_0 +#endif // WXWIN_COMPATIBILITY_3_0 && wxUSE_SPELLCHECK void wxTextCtrl::OSXEnableAutomaticQuoteSubstitution(bool enable) { @@ -346,7 +347,7 @@ void wxTextCtrl::Paste() bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) { - GetTextPeer()->CheckSpelling(options.IsSpellCheckingEnabled()); + GetTextPeer()->CheckSpelling(options); return true; } From 94173e3faeda5bd908eb0e417848d9a83b5ac06b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 01:32:29 +0200 Subject: [PATCH 13/14] Remove stub spell checking functions from wxiOS wxTextCtrl There doesn't seem to be any need to have these functions here as the base class implementation already does exactly the same thing (i.e. nothing at all). --- include/wx/osx/iphone/private/textimpl.h | 5 ----- src/osx/iphone/textctrl.mm | 13 ------------- 2 files changed, 18 deletions(-) diff --git a/include/wx/osx/iphone/private/textimpl.h b/include/wx/osx/iphone/private/textimpl.h index 1a2876e4fe..bdaa6c0c72 100644 --- a/include/wx/osx/iphone/private/textimpl.h +++ b/include/wx/osx/iphone/private/textimpl.h @@ -71,11 +71,6 @@ public: virtual bool HasOwnContextMenu() const { return true; } -#if wxUSE_SPELLCHECK - virtual void CheckSpelling(const wxTextProofOptions& options); - virtual bool IsSpellingCheckEnabled() const; -#endif // wxUSE_SPELLCHECK - virtual wxSize GetBestSize() const; protected: diff --git a/src/osx/iphone/textctrl.mm b/src/osx/iphone/textctrl.mm index 889cf3c676..147f8cb1d3 100644 --- a/src/osx/iphone/textctrl.mm +++ b/src/osx/iphone/textctrl.mm @@ -500,19 +500,6 @@ void wxUITextViewControl::SetStyle(long start, } } -#if wxUSE_SPELLCHECK - -void wxUITextViewControl::CheckSpelling(const wxTextProofOptions& WXUNUSED(options)) -{ -} - -bool wxUITextViewControl::IsSpellingCheckEnabled() const -{ - return false; -} - -#endif // wxUSE_SPELLCHECK - wxSize wxUITextViewControl::GetBestSize() const { wxRect r; From 45dcb1a8a5e757c3ebf41825749b5b138cdd0494 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Aug 2021 01:37:48 +0200 Subject: [PATCH 14/14] Replace IsProofCheckEnabled() with GetProofCheckOptions() This is more consistent with EnableProofCheck() and allows to retrieve the current state of grammar checking under macOS, which can be checked by user and so can be useful to know. --- include/wx/gtk/textctrl.h | 2 +- include/wx/msw/textctrl.h | 2 +- include/wx/osx/cocoa/private/textimpl.h | 2 +- include/wx/osx/core/private.h | 2 +- include/wx/osx/textctrl.h | 2 +- include/wx/textctrl.h | 14 +++++++++++--- interface/wx/textctrl.h | 18 +++++++++++------- src/gtk/textctrl.cpp | 19 +++++++++++-------- src/msw/textctrl.cpp | 13 +++++++++---- src/osx/cocoa/textctrl.mm | 15 +++++++++++---- src/osx/textctrl_osx.cpp | 13 +++++++++++-- 11 files changed, 69 insertions(+), 33 deletions(-) diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 390e27987f..b4d6e6b595 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -100,7 +100,7 @@ public: // Use native spelling and grammar checking functions. virtual bool EnableProofCheck(const wxTextProofOptions& options = wxTextProofOptions::Default()) wxOVERRIDE; - virtual bool IsProofCheckEnabled() const wxOVERRIDE; + virtual wxTextProofOptions GetProofCheckOptions() const wxOVERRIDE; #endif // wxUSE_SPELLCHECK && __WXGTK3__ // Implementation from now on diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 1383120402..08ff22bbf4 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -116,7 +116,7 @@ public: // This is only available in wxTE_RICH2 controls. virtual bool EnableProofCheck(const wxTextProofOptions& options = wxTextProofOptions::Default()) wxOVERRIDE; - virtual bool IsProofCheckEnabled() const wxOVERRIDE; + virtual wxTextProofOptions GetProofCheckOptions() const wxOVERRIDE; #endif // wxUSE_RICHEDIT && wxUSE_SPELLCHECK // Implementation from now on diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index 2984375992..c6b57b5a6a 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -129,7 +129,7 @@ public: #if wxUSE_SPELLCHECK virtual void CheckSpelling(const wxTextProofOptions& options) wxOVERRIDE; - virtual bool IsSpellingCheckEnabled() const wxOVERRIDE; + virtual wxTextProofOptions GetCheckingOptions() const wxOVERRIDE; #endif // wxUSE_SPELLCHECK virtual void EnableAutomaticQuoteSubstitution(bool enable) wxOVERRIDE; virtual void EnableAutomaticDashSubstitution(bool enable) wxOVERRIDE; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 4dd3074b7c..db904c8207 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -741,7 +741,7 @@ public : virtual wxString GetLineText(long lineNo) const ; #if wxUSE_SPELLCHECK virtual void CheckSpelling(const wxTextProofOptions& WXUNUSED(options)) { } - virtual bool IsSpellingCheckEnabled() const { return false; } + virtual wxTextProofOptions GetCheckingOptions() const; #endif // wxUSE_SPELLCHECK virtual void EnableAutomaticQuoteSubstitution(bool WXUNUSED(enable)) {} virtual void EnableAutomaticDashSubstitution(bool WXUNUSED(enable)) {} diff --git a/include/wx/osx/textctrl.h b/include/wx/osx/textctrl.h index b528ee0887..6e6a40817c 100644 --- a/include/wx/osx/textctrl.h +++ b/include/wx/osx/textctrl.h @@ -101,7 +101,7 @@ public: // Use native spelling and grammar checking functions (multiline only). virtual bool EnableProofCheck(const wxTextProofOptions& options = wxTextProofOptions::Default()) wxOVERRIDE; - virtual bool IsProofCheckEnabled() const wxOVERRIDE; + virtual wxTextProofOptions GetProofCheckOptions() const wxOVERRIDE; #endif // wxUSE_SPELLCHECK // Implementation diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h index 12553337c0..b2db92f48e 100644 --- a/include/wx/textctrl.h +++ b/include/wx/textctrl.h @@ -171,10 +171,15 @@ public: } // And the corresponding accessors. - bool IsSpellCheckingEnabled() const { return m_EnableSpellCheck; } - bool IsGrammarCheckingEnabled() const { return m_EnableGrammarCheck; } + bool IsSpellCheckEnabled() const { return m_EnableSpellCheck; } + bool IsGrammarCheckEnabled() const { return m_EnableGrammarCheck; } const wxString& GetLang() const { return m_lang; } + bool AnyChecksEnabled() const + { + return IsSpellCheckEnabled() || IsGrammarCheckEnabled(); + } + private: // Ctor is private, use static factory methods to create objects of this // class. @@ -830,7 +835,10 @@ public: { return false; } - virtual bool IsProofCheckEnabled() const { return false; } + virtual wxTextProofOptions GetProofCheckOptions() const + { + return wxTextProofOptions::Disable(); + } #endif // wxUSE_SPELLCHECK protected: diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index 6dd7216e03..40d26da191 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -1004,7 +1004,7 @@ public: constructor, so its objects can only be created using the static factory methods Default() or Disable(). - @see wxTextCtrl::EnableProofCheck(), wxTextCtrl::IsProofCheckEnabled(). + @see wxTextCtrl::EnableProofCheck(), wxTextCtrl::GetProofCheckOptions(). @since 3.1.6 */ @@ -1039,10 +1039,13 @@ class WXDLLIMPEXP_CORE wxTextProofOptions wxTextProofOptions& GrammarCheck(bool enable = true) /// Return true if spell checking is enabled. - bool IsSpellCheckingEnabled() const; + bool IsSpellCheckEnabled() const; /// Return true if grammar checking is enabled. - bool IsGrammarCheckingEnabled() const; + bool IsGrammarCheckEnabled() const; + + /// Returns true if any checks are enabled. + bool AnyChecksEnabled() const }; /** @@ -1570,15 +1573,16 @@ public: bool IsSingleLine() const; /** - Returns @true if proof (spell) checking is currently active on this - control, @false otherwise. + Returns the current text proofing options. This function is implemented for the same platforms as - EnableProofCheck() and returns @false for the other ones. + EnableProofCheck() and returns wxTextProofOptions with all checks + disabled, i.e. such that wxTextProofOptions::AnyChecksEnabled() returns + @false. @since 3.1.6 */ - virtual bool IsProofCheckEnabled(); + virtual wxTextProofOptions GetProofCheckOptions(); /** Loads and displays the named file, if it exists. diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 3c5f5e8427..b279d1a817 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1036,7 +1036,7 @@ bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview); - if ( options.IsSpellCheckingEnabled() ) + if ( options.IsSpellCheckEnabled() ) { if ( !spell ) { @@ -1057,19 +1057,22 @@ bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) gtk_spell_checker_detach(spell); } - return IsProofCheckEnabled(); + return GetProofCheckOptions().IsSpellCheckEnabled(); } -bool wxTextCtrl::IsProofCheckEnabled() const +wxTextProofOptions wxTextCtrl::GetProofCheckOptions() const { + wxTextProofOptions opts = wxTextProofOptions::Disable(); + GtkTextView *textview = GTK_TEXT_VIEW(m_text); - if ( !IsMultiLine() || textview == NULL ) - return false; + if ( IsMultiLine() && textview ) + { + if ( gtk_spell_checker_get_from_text_view(textview) ) + opts.SpellCheck(); + } - GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview); - - return (spell != NULL); + return opts; } #endif // wxUSE_SPELLCHECK && __WXGTK3__ diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index d2a9082a9d..4e06cff953 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -846,21 +846,26 @@ bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) LRESULT langOptions = ::SendMessage(GetHwnd(), EM_GETLANGOPTIONS, 0, 0); - if ( options.IsSpellCheckingEnabled() ) + if ( options.IsSpellCheckEnabled() ) langOptions |= IMF_SPELLCHECKING; else langOptions &= ~IMF_SPELLCHECKING; ::SendMessage(GetHwnd(), EM_SETLANGOPTIONS, 0, langOptions); - return IsProofCheckEnabled(); + return GetProofCheckOptions().IsSpellCheckEnabled(); } -bool wxTextCtrl::IsProofCheckEnabled() const +wxTextProofOptions wxTextCtrl::GetProofCheckOptions() const { + wxTextProofOptions opts = wxTextProofOptions::Disable(); + LRESULT langOptions = ::SendMessage(GetHwnd(), EM_GETLANGOPTIONS, 0, 0); - return (langOptions & IMF_SPELLCHECKING); + if (langOptions & IMF_SPELLCHECKING) + opts.SpellCheck(); + + return opts; } #endif // wxUSE_SPELLCHECK diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 23f9b95ce0..d756dc09d4 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -1283,13 +1283,20 @@ void wxNSTextViewControl::CheckSpelling(const wxTextProofOptions& options) { wxCHECK_RET( m_textView, "control must be created first" ); - m_textView.continuousSpellCheckingEnabled = options.IsSpellCheckingEnabled(); - m_textView.grammarCheckingEnabled = options.IsGrammarCheckingEnabled(); + m_textView.continuousSpellCheckingEnabled = options.IsSpellCheckEnabled(); + m_textView.grammarCheckingEnabled = options.IsGrammarCheckEnabled(); } -bool wxNSTextViewControl::IsSpellingCheckEnabled() const +wxTextProofOptions wxNSTextViewControl::GetCheckingOptions() const { - return m_textView && m_textView.continuousSpellCheckingEnabled; + wxTextProofOptions opts = wxTextProofOptions::Disable(); + if ( m_textView ) + { + opts.SpellCheck(m_textView.continuousSpellCheckingEnabled); + opts.GrammarCheck(m_textView.grammarCheckingEnabled); + } + + return opts; } #endif // wxUSE_SPELLCHECK diff --git a/src/osx/textctrl_osx.cpp b/src/osx/textctrl_osx.cpp index 969e6a9d48..670e4859e2 100644 --- a/src/osx/textctrl_osx.cpp +++ b/src/osx/textctrl_osx.cpp @@ -352,9 +352,9 @@ bool wxTextCtrl::EnableProofCheck(const wxTextProofOptions& options) return true; } -bool wxTextCtrl::IsProofCheckEnabled() const +wxTextProofOptions wxTextCtrl::GetProofCheckOptions() const { - return GetTextPeer()->IsSpellingCheckEnabled(); + return GetTextPeer()->GetCheckingOptions(); } #endif // wxUSE_SPELLCHECK @@ -827,6 +827,15 @@ int wxTextWidgetImpl::GetLineLength(long lineNo) const return -1 ; } +#if wxUSE_SPELLCHECK + +wxTextProofOptions wxTextWidgetImpl::GetCheckingOptions() const +{ + return wxTextProofOptions::Disable(); +} + +#endif // wxUSE_SPELLCHECK + void wxTextWidgetImpl::SetJustification() { }