[Libreoffice-commits] core.git: linguistic/source offapi/com sw/source

Fred Kruse f.kruse at freenet.de
Fri Jun 1 01:57:54 UTC 2018


 linguistic/source/gciterator.cxx                  |   62 +++++++++++++++++++++
 linguistic/source/gciterator.hxx                  |   28 +++++++++
 offapi/com/sun/star/text/TextMarkupDescriptor.idl |   10 +++
 sw/source/core/inc/wrong.hxx                      |   64 +++++++++++++++++++++-
 4 files changed, 161 insertions(+), 3 deletions(-)

New commits:
commit 7e428cac54c0a10aa7885923b836562e8fa82235
Author: Fred Kruse <f.kruse at freenet.de>
Date:   Mon May 28 13:04:48 2018 +0200

    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/54927
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx
index b1dce0de8543..a1bba7cbf739 100644
--- a/linguistic/source/gciterator.cxx
+++ b/linguistic/source/gciterator.cxx
@@ -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() :
     m_bEnd( false ),
     m_aCurCheckedDocId(),
@@ -382,6 +426,24 @@ void GrammarCheckingIterator::ProcessResult(
                     // differently for example. But no special handling right now.
                     if (rDesc.nType == text::TextMarkupType::SPELLCHECK)
                         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
diff --git a/linguistic/source/gciterator.hxx b/linguistic/source/gciterator.hxx
index 568a30f50150..9241b4136dd7 100644
--- a/linguistic/source/gciterator.hxx
+++ b/linguistic/source/gciterator.hxx
@@ -37,6 +37,10 @@
 #include <osl/thread.h>
 #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 <deque>
 
@@ -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
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/offapi/com/sun/star/text/TextMarkupDescriptor.idl b/offapi/com/sun/star/text/TextMarkupDescriptor.idl
index 17eea6e58173..f78cb28c07ce 100644
--- a/offapi/com/sun/star/text/TextMarkupDescriptor.idl
+++ b/offapi/com/sun/star/text/TextMarkupDescriptor.idl
@@ -47,7 +47,15 @@ struct TextMarkupDescriptor
     /// Length of the markup range
     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;
 };
 
diff --git a/sw/source/core/inc/wrong.hxx b/sw/source/core/inc/wrong.hxx
index 3bca9d8d6fa0..0aa575434483 100644
--- a/sw/source/core/inc/wrong.hxx
+++ b/sw/source/core/inc/wrong.hxx
@@ -76,6 +76,66 @@ public:
                  SwWrongList* pSubList);
 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)
     {
         try
@@ -145,7 +205,7 @@ private:
         }
         else if (WRONGLIST_GRAMMAR == listType)
         {
-            return COL_LIGHTBLUE;
+            return getGrammarColor(xPropertyBag);
         }
         else if (WRONGLIST_SMARTTAG == listType)
         {
@@ -164,7 +224,7 @@ private:
         }
         else if (WRONGLIST_GRAMMAR == listType)
         {
-            return WRONGAREA_WAVE;
+            return getGrammarLineType(xPropertyBag);
         }
         else if (WRONGLIST_SMARTTAG == listType)
         {


More information about the Libreoffice-commits mailing list