Hi,
I am trying to implement a Grammar Checker (C++) and I have implemented
XProofreader in my test module.
I have found out that if I uncheck the "Check grammar as you type" check box
in the "options-writing aids" dialog I have the following two issues:
1. After doProofreading() returns (grammar) errors its gets called always
with the same StartOfSentencePos and SuggestedBehindEndOfSentencePosition
parameters (pointing to the first sentence in the paragraph) even when I
click "Ignore Once" (I would have expect to be called with index of next
sentence).
When doProofreading() does not return a (grammar) error, next call will
provide, correctly, the indexes pointing to the next sentence.
2. I supply correction for 2 (grammar) errors but see in the UI only the
first.
If I do check the "Check grammar as you type" check box things work better
but have an issue that when I run "grammar and spelling" (F7) each time it
starts from some point in the doc rather from the cursor and stops before
the end of the doc (when I re-open the doc and run the "grammar and
spelling" for the first time it work OK) .
Are those bugs?
Am I missing something and this is the expected behavior?
Should I implement XGrammarChecker instead of XProofreader ?
Below is my doProofreading() function.
Thanks and Best Regards
Guy
linguistic2::ProofreadingResult SAL_CALL
GrammarChecker::doProofreading(const OUString & aDocumentIdentifier,
const OUString & aText,
const
lang::Locale & aLocale,
sal_Int32
nStartOfSentencePos,
sal_Int32
nSuggestedBehindEndOfSentencePosition,
const
uno::Sequence<beans::PropertyValue> & aProperties)
throw (uno::RuntimeException, lang::IllegalArgumentException)
{
linguistic2::ProofreadingResult result;
result.aDocumentIdentifier = aDocumentIdentifier;
result.xFlatParagraph = 0;
result.aText = aText;
result.aLocale = aLocale;
result.nStartOfSentencePosition = nStartOfSentencePos;
result.nBehindEndOfSentencePosition =
nSuggestedBehindEndOfSentencePosition;
result.xProofreader = this;
OString text = ::rtl::OUStringToOString(aText,
RTL_TEXTENCODING_UTF8);
sal_Int32 paraLen = text.getLength();
if (paraLen <= 100)
return result;
// DUMMY ERRORS (for the sake of the test)
uno::Sequence<linguistic2::SingleProofreadingError> spErrors(2);
spErrors[0].nErrorStart = result.nStartOfSentencePosition;
spErrors[0].nErrorLength = 3;
spErrors[0].nErrorType = text::TextMarkupType::PROOFREADING;
OUString comment (RTL_CONSTASCII_USTRINGPARAM("A grammer error") );
OUString commentLong (RTL_CONSTASCII_USTRINGPARAM("A grammer error
long long") );
spErrors[0].aShortComment = comment;
spErrors[0].aFullComment = commentLong;
uno::Sequence<OUString> suggSeq(1);
OString ostr = OString("Sugg");
suggSeq[0] = OStringToOUString(ostr, RTL_TEXTENCODING_UTF8);
spErrors[0].aSuggestions = suggSeq;
spErrors[1].nErrorStart = result.nStartOfSentencePosition + 10;
spErrors[1].nErrorLength = 10;
spErrors[1].nErrorType = text::TextMarkupType::PROOFREADING;
OUString comment2 (RTL_CONSTASCII_USTRINGPARAM("Found a grammer
error2 ") );
OUString commentLong2 (RTL_CONSTASCII_USTRINGPARAM("Found a grammer
error long long 2") );
spErrors[1].aShortComment = comment2;
spErrors[1].aFullComment = commentLong2;
uno::Sequence<OUString> suggSeq2(1);
OString ostr2 = OString("Sugg2");
suggSeq2[0] = OStringToOUString(ostr2, RTL_TEXTENCODING_UTF8);
spErrors[1].aSuggestions = suggSeq2;
result.aErrors = spErrors;
result.nStartOfNextSentencePosition =
nSuggestedBehindEndOfSentencePosition;
return result;
}