Kaydet (Commit) 7e428cac authored tarafından Fred Kruse's avatar Fred Kruse Kaydeden (comit) Thorsten Behrens

linguistic: add functionality to change spellcheck color

This adds a way for the grammar checker extension to change color
and line type of the 'wiggly lines' LibreOffice uses to highlight
spelling or grammar errors.

Change-Id: Idd669cf362da34f8cfcdcec14f1f80df1ddb1f9e
Reviewed-on: https://gerrit.libreoffice.org/54927Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 85849a28
...@@ -233,6 +233,50 @@ static lang::Locale lcl_GetPrimaryLanguageOfSentence( ...@@ -233,6 +233,50 @@ static lang::Locale lcl_GetPrimaryLanguageOfSentence(
} }
SwXStringKeyMap::SwXStringKeyMap() {}
void SAL_CALL SwXStringKeyMap::insertValue(const OUString& aKey, const css::uno::Any& aValue)
{
std::map<OUString, css::uno::Any>::const_iterator aIter = maMap.find(aKey);
if (aIter != maMap.end())
throw css::container::ElementExistException();
maMap[aKey] = aValue;
}
css::uno::Any SAL_CALL SwXStringKeyMap::getValue(const OUString& aKey)
{
std::map<OUString, css::uno::Any>::const_iterator aIter = maMap.find(aKey);
if (aIter == maMap.end())
throw css::container::NoSuchElementException();
return (*aIter).second;
}
sal_Bool SAL_CALL SwXStringKeyMap::hasValue(const OUString& aKey)
{
return maMap.find(aKey) != maMap.end();
}
::sal_Int32 SAL_CALL SwXStringKeyMap::getCount() { return maMap.size(); }
OUString SAL_CALL SwXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex)
{
if (static_cast<sal_uInt32>(nIndex) >= maMap.size())
throw css::lang::IndexOutOfBoundsException();
return OUString();
}
css::uno::Any SAL_CALL SwXStringKeyMap::getValueByIndex(::sal_Int32 nIndex)
{
if (static_cast<sal_uInt32>(nIndex) >= maMap.size())
throw css::lang::IndexOutOfBoundsException();
return css::uno::Any();
}
GrammarCheckingIterator::GrammarCheckingIterator() : GrammarCheckingIterator::GrammarCheckingIterator() :
m_bEnd( false ), m_bEnd( false ),
m_aCurCheckedDocId(), m_aCurCheckedDocId(),
...@@ -382,6 +426,24 @@ void GrammarCheckingIterator::ProcessResult( ...@@ -382,6 +426,24 @@ void GrammarCheckingIterator::ProcessResult(
// differently for example. But no special handling right now. // differently for example. But no special handling right now.
if (rDesc.nType == text::TextMarkupType::SPELLCHECK) if (rDesc.nType == text::TextMarkupType::SPELLCHECK)
rDesc.nType = text::TextMarkupType::PROOFREADING; rDesc.nType = text::TextMarkupType::PROOFREADING;
uno::Reference< container::XStringKeyMap > xKeyMap(
new SwXStringKeyMap());
for( const beans::PropertyValue& rProperty : rError.aProperties )
{
if ( rProperty.Name == "LineColor" )
{
xKeyMap->insertValue(rProperty.Name,
rProperty.Value);
rDesc.xMarkupInfoContainer = xKeyMap;
}
else if ( rProperty.Name == "LineType" )
{
xKeyMap->insertValue(rProperty.Name,
rProperty.Value);
rDesc.xMarkupInfoContainer = xKeyMap;
}
}
} }
// at pos nErrors -> sentence markup // at pos nErrors -> sentence markup
......
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
#include <osl/thread.h> #include <osl/thread.h>
#include <rtl/instance.hxx> #include <rtl/instance.hxx>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <cppu/unotype.hxx>
#include <map> #include <map>
#include <deque> #include <deque>
...@@ -180,6 +184,30 @@ public: ...@@ -180,6 +184,30 @@ public:
}; };
/** Implementation of the css::container::XStringKeyMap interface
*/
class SwXStringKeyMap : public ::cppu::WeakImplHelper<css::container::XStringKeyMap>
{
public:
SwXStringKeyMap();
virtual css::uno::Any SAL_CALL getValue(const OUString& aKey) override;
virtual sal_Bool SAL_CALL hasValue(const OUString& aKey) override;
virtual void SAL_CALL insertValue(const OUString& aKey, const css::uno::Any& aValue) override;
virtual ::sal_Int32 SAL_CALL getCount() override;
virtual OUString SAL_CALL getKeyByIndex(::sal_Int32 nIndex) override;
virtual css::uno::Any SAL_CALL getValueByIndex(::sal_Int32 nIndex) override;
private:
SwXStringKeyMap(SwXStringKeyMap&) = delete;
void operator=(SwXStringKeyMap&) = delete;
~SwXStringKeyMap() override{};
std::map<OUString, css::uno::Any> maMap;
};
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -47,7 +47,15 @@ struct TextMarkupDescriptor ...@@ -47,7 +47,15 @@ struct TextMarkupDescriptor
/// Length of the markup range /// Length of the markup range
long nLength; long nLength;
/// contains additional information about the markup /** contains additional information about the markup
Supported properties:
nType | aKey
------------------------- | -------------
PROOFREADING or SMARTTAG | "LineColor": changes the markup color from default to RGB aValue (int32)
PROOFREADING or SMARTTAG | "LineType": changes the wiggly line type from default to aValue (short) (WAVE or DASH)
*/
com::sun::star::container::XStringKeyMap xMarkupInfoContainer; com::sun::star::container::XStringKeyMap xMarkupInfoContainer;
}; };
......
...@@ -76,6 +76,66 @@ public: ...@@ -76,6 +76,66 @@ public:
SwWrongList* pSubList); SwWrongList* pSubList);
private: private:
static Color getGrammarColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag)
{
try
{
if (xPropertyBag.is())
{
const OUString colorKey("LineColor");
css::uno::Any aLineColor = xPropertyBag->getValue(colorKey);
css::util::Color lineColor = 0;
if (aLineColor >>= lineColor)
{
return Color( lineColor );
}
}
}
catch(const css::container::NoSuchElementException&)
{
}
catch(const css::uno::RuntimeException&)
{
}
return COL_LIGHTBLUE;
}
static WrongAreaLineType getGrammarLineType( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
{
try
{
if (xPropertyBag.is())
{
const OUString typeKey("LineType");
css::uno::Any aLineType = xPropertyBag->getValue(typeKey);
::sal_Int16 lineType = 0;
if (!(aLineType >>= lineType))
{
return WRONGAREA_WAVE;
}
if (css::awt::FontUnderline::DASH == lineType)
{
return WRONGAREA_DASHED;
}
if (css::awt::FontUnderline::SMALLWAVE == lineType)
{
return WRONGAREA_WAVE; //Code draws wave height based on space that fits.
}
}
}
catch(const css::container::NoSuchElementException&)
{
}
catch(const css::uno::RuntimeException&)
{
}
return WRONGAREA_WAVE;
}
static Color getSmartColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag) static Color getSmartColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag)
{ {
try try
...@@ -145,7 +205,7 @@ private: ...@@ -145,7 +205,7 @@ private:
} }
else if (WRONGLIST_GRAMMAR == listType) else if (WRONGLIST_GRAMMAR == listType)
{ {
return COL_LIGHTBLUE; return getGrammarColor(xPropertyBag);
} }
else if (WRONGLIST_SMARTTAG == listType) else if (WRONGLIST_SMARTTAG == listType)
{ {
...@@ -164,7 +224,7 @@ private: ...@@ -164,7 +224,7 @@ private:
} }
else if (WRONGLIST_GRAMMAR == listType) else if (WRONGLIST_GRAMMAR == listType)
{ {
return WRONGAREA_WAVE; return getGrammarLineType(xPropertyBag);
} }
else if (WRONGLIST_SMARTTAG == listType) else if (WRONGLIST_SMARTTAG == listType)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment