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.
This commit is contained in:
@@ -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__
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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.
|
||||
|
@@ -1209,7 +1209,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
||||
m_enter->SetClientData(const_cast<void*>(static_cast<const void*>(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."),
|
||||
|
@@ -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 )
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user