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.
This commit is contained in:
Vadim Zeitlin
2021-08-23 01:37:48 +02:00
parent 94173e3fae
commit 45dcb1a8a5
11 changed files with 69 additions and 33 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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)) {}

View File

@@ -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

View File

@@ -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:

View File

@@ -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.

View File

@@ -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__

View File

@@ -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

View File

@@ -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

View File

@@ -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()
{
}