You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by js...@apache.org on 2013/03/20 16:18:15 UTC

svn commit: r1458879 - in /openoffice/trunk/main/sw/source/core: inc/wrong.hxx text/wrong.cxx txtnode/fntcache.cxx

Author: jsc
Date: Wed Mar 20 15:18:15 2013
New Revision: 1458879

URL: http://svn.apache.org/r1458879
Log:
#121733# enhancement for colored smarttags

Patch By: Kai Labusch
Review by: arielch, jsc

Modified:
    openoffice/trunk/main/sw/source/core/inc/wrong.hxx
    openoffice/trunk/main/sw/source/core/text/wrong.cxx
    openoffice/trunk/main/sw/source/core/txtnode/fntcache.cxx

Modified: openoffice/trunk/main/sw/source/core/inc/wrong.hxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/inc/wrong.hxx?rev=1458879&r1=1458878&r2=1458879&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/inc/wrong.hxx (original)
+++ openoffice/trunk/main/sw/source/core/inc/wrong.hxx Wed Mar 20 15:18:15 2013
@@ -28,12 +28,37 @@
 #include <com/sun/star/container/XStringKeyMap.hpp>
 #endif
 
+#include <com/sun/star/util/Color.hpp>
+#include <com/sun/star/awt/FontUnderline.hpp>
+#include <com/sun/star/uno/Any.hxx>
+
 #include <vector>
 
 #include <tools/string.hxx>
+#include <tools/color.hxx>
+#include <viewopt.hxx>
 
 class SwWrongList;
 
+enum WrongAreaLineType
+{
+    WRONGAREA_DASHED,
+    WRONGAREA_WAVE,
+    WRONGAREA_WAVE_NORMAL,
+    WRONGAREA_WAVE_SMALL,
+    WRONGAREA_WAVE_FLAT,
+    WRONGAREA_NONE
+};
+
+enum WrongListType
+{
+    WRONGLIST_SPELL,
+    WRONGLIST_GRAMMAR,
+    WRONGLIST_SMARTTAG,
+    WRONGLIST_CHANGETRACKING
+};
+
+
 // ST2
 class SwWrongArea
 {
@@ -44,21 +69,122 @@ public:
     xub_StrLen mnLen;
     SwWrongList* mpSubList;
 
-    SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL) {}
+    Color mColor;
+    WrongAreaLineType mLineType;
+
+    SwWrongArea( const rtl::OUString& rType,
+                 WrongListType listType,
+                 com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
+                 xub_StrLen nPos,
+                 xub_StrLen nLen);
+
     SwWrongArea( const rtl::OUString& rType,
                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
                  xub_StrLen nPos,
                  xub_StrLen nLen,
-                 SwWrongList* pSubList )
-        : maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(pSubList) {}
-};
+                 SwWrongList* pSubList);
+private:
+
+    SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL), mColor(0,0,0), mLineType(WRONGAREA_WAVE) {}
+
+    Color getSmartColor ( com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag)
+    {
+        try
+        {
+            if (xPropertyBag.is())
+            {
+                const ::rtl::OUString colorKey  = ::rtl::OUString::createFromAscii ("LineColor");
+                com::sun::star::uno::Any aLineColor = xPropertyBag->getValue(colorKey).get< com::sun::star::uno::Any>();
+                com::sun::star::util::Color lineColor = 0;
+
+                if (aLineColor >>= lineColor)
+                {
+                    return Color( lineColor );
+                }
+            }
+        }
+        catch(::com::sun::star::container::NoSuchElementException& ex)
+        {
+        }
+        catch(::com::sun::star::uno::RuntimeException& ex)
+        {
+        }
+
+        return SwViewOption::GetSmarttagColor( );
+    }
+
+    WrongAreaLineType getSmartLineType( com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
+    {
+        try
+        {
+            if (xPropertyBag.is())
+            {
+                const ::rtl::OUString typeKey  = ::rtl::OUString::createFromAscii ("LineType");
+                com::sun::star::uno::Any aLineType = xPropertyBag->getValue(typeKey).get< com::sun::star::uno::Any>();
+                ::sal_Int16 lineType = 0;
+
+                if (!(aLineType >>= lineType))
+                {
+                    return WRONGAREA_DASHED;
+                }
+                if (::com::sun::star::awt::FontUnderline::WAVE == lineType)
+                {
+                    return WRONGAREA_WAVE_NORMAL;
+                } 
+                if (::com::sun::star::awt::FontUnderline::SMALLWAVE == lineType)
+                {
+                    return WRONGAREA_WAVE_SMALL;
+                }
+            }
+        }
+        catch(::com::sun::star::container::NoSuchElementException& ex)
+        {
+        }
+        catch(::com::sun::star::uno::RuntimeException& ex)
+        {
+        }
+
+        return WRONGAREA_DASHED;
+    }
+
+    Color getWrongAreaColor(WrongListType listType,
+                            com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
+    {
+        if (WRONGLIST_SPELL == listType)
+        {
+            return SwViewOption::GetSpellColor();
+        }
+        else if (WRONGLIST_GRAMMAR == listType)
+        {
+            return Color( COL_LIGHTBLUE );
+        }
+        else if (WRONGLIST_SMARTTAG == listType)
+        {
+            return  getSmartColor(xPropertyBag); 
+        }
+
+        return SwViewOption::GetSpellColor();       
+    }
+
+    WrongAreaLineType getWrongAreaLineType(WrongListType listType,
+                                           com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
+    {
+        if (WRONGLIST_SPELL == listType)
+        {
+            return WRONGAREA_WAVE;
+        }
+        else if (WRONGLIST_GRAMMAR == listType)
+        {
+            return WRONGAREA_WAVE;
+        }
+        else if (WRONGLIST_SMARTTAG == listType)
+        {
+            return getSmartLineType(xPropertyBag);
+        }
+
+        return WRONGAREA_WAVE;       
+    }
 
-enum WrongListType
-{
-    WRONGLIST_SPELL,
-    WRONGLIST_GRAMMAR,
-    WRONGLIST_SMARTTAG,
-    WRONGLIST_CHANGETRACKING
 };
 
 class SwWrongList
@@ -137,7 +263,8 @@ public:
             i = maList.end(); // robust
         else
             i += nWhere;
-        maList.insert(i, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) );
+
+        maList.insert(i, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
     }
 
     void Insert( const rtl::OUString& rType,

Modified: openoffice/trunk/main/sw/source/core/text/wrong.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/text/wrong.cxx?rev=1458879&r1=1458878&r2=1458879&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/text/wrong.cxx (original)
+++ openoffice/trunk/main/sw/source/core/text/wrong.cxx Wed Mar 20 15:18:15 2013
@@ -33,6 +33,33 @@
 
 #include "SwGrammarMarkUp.hxx"
 
+/*************************************************************************
+ *SwWrongArea::SwWrongArea
+ *************************************************************************/
+
+SwWrongArea::SwWrongArea( const rtl::OUString& rType, WrongListType listType,
+        com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
+        xub_StrLen nPos,
+        xub_StrLen nLen)
+: maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(0) 
+{
+    mColor =  getWrongAreaColor(listType, xPropertyBag);
+    mLineType = getWrongAreaLineType(listType, xPropertyBag);
+}
+
+SwWrongArea::SwWrongArea( const rtl::OUString& rType,
+        com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
+        xub_StrLen nPos,
+        xub_StrLen nLen,
+        SwWrongList* pSubList)
+: maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(pSubList), mLineType(WRONGAREA_NONE) 
+{
+    if (pSubList != 0)
+    {
+        mColor =  getWrongAreaColor(pSubList->GetWrongListType(), xPropertyBag);
+        mLineType = getWrongAreaLineType(pSubList->GetWrongListType(), xPropertyBag);
+    }
+}
 
 /*************************************************************************
  * SwWrongList::SwWrongList()
@@ -634,7 +661,7 @@ void SwWrongList::Insert( const rtl::OUS
         ++aIter;
     }
 
-    maList.insert(aIter, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) );
+    maList.insert(aIter, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
 }
 
 

Modified: openoffice/trunk/main/sw/source/core/txtnode/fntcache.cxx
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/sw/source/core/txtnode/fntcache.cxx?rev=1458879&r1=1458878&r2=1458879&view=diff
==============================================================================
--- openoffice/trunk/main/sw/source/core/txtnode/fntcache.cxx (original)
+++ openoffice/trunk/main/sw/source/core/txtnode/fntcache.cxx Wed Mar 20 15:18:15 2013
@@ -710,115 +710,136 @@ static void lcl_DrawLineForWrongListData
     const CalcLinePosData   &rCalcLinePosData,
     const Size              &rPrtFontSize )
 {
-    if (!pWList)
-        return;
+    if (!pWList) return;
 
     xub_StrLen nStart = rInf.GetIdx();
     xub_StrLen nWrLen = rInf.GetLen();
 
     // check if respective data is available in the current text range
-    if (pWList->Check( nStart, nWrLen ))
+    if (!pWList->Check( nStart, nWrLen ))
     {
-        // get line color to use...
-        Color aLineColor;
-        if (pWList == rInf.GetWrong())  // ... for spell checking
-            aLineColor = SwViewOption::GetSpellColor();
-        else if (pWList == rInf.GetGrammarCheck())  // ... for grammar checking
-            // currently there is no specific color for grammar check errors available in the configuration
-            aLineColor = Color( COL_LIGHTBLUE );
-        else if (pWList == rInf.GetSmartTags())  // ... for smart tags
-            aLineColor = SwViewOption::GetSmarttagColor();
-
-        long nHght = rInf.GetOut().LogicToPixel( rPrtFontSize ).Height();
-
-        // Draw wavy lines for spell and grammar errors only if font is large enough.
-        // Lines for smart tags will always be drawn.
-        if (pWList == rInf.GetSmartTags() || WRONG_SHOW_MIN < nHght)
-        {
-            SwForbidden::iterator pIter = rForbidden.begin();
-            if (rInf.GetOut().GetConnectMetaFile())
-                rInf.GetOut().Push();
-
-            const Color aCol( rInf.GetOut().GetLineColor() );
-            const sal_Bool bColSave = aCol != aLineColor;
-            if (bColSave)
-                rInf.GetOut().SetLineColor( aLineColor );
-
-            // iterate over all ranges stored in the respective SwWrongList
-            do
-            {
-                nStart = nStart - rInf.GetIdx();
-
-                const xub_StrLen nEnd = nStart + nWrLen;
-                xub_StrLen nNext = nStart;
-                while( nNext < nEnd )
-                {
-                    while( pIter != rForbidden.end() && pIter->second <= nNext )
-                        ++pIter;
-                    xub_StrLen nNextStart = nNext;
-                    xub_StrLen nNextEnd = nEnd;
-                    if( pIter == rForbidden.end() || nNextEnd <= pIter->first )
-                    {
-                        // No overlapping mark up found
-                        std::pair< xub_StrLen, xub_StrLen > aNew;
-                        aNew.first = nNextStart;
-                        aNew.second = nNextEnd;
-                        rForbidden.insert( pIter, aNew );
-                        pIter = rForbidden.begin();
-                        nNext = nEnd;
-                    }
-                    else
-                    {
-                        nNext = pIter->second;
-                        if( nNextStart < pIter->first )
-                        {
-                            nNextEnd = pIter->first;
-                            pIter->first = nNextStart;
-                        }
-                        else
-                            continue;
-                    }
-                    // determine line pos
-                    Point aStart( rInf.GetPos() );
-                    Point aEnd;
-                    lcl_calcLinePos( rCalcLinePosData, aStart, aEnd, nNextStart, nNextEnd - nNextStart );
+        return;
+    }
 
-                    // draw line for smart tags?
-                    if (pWList == rInf.GetSmartTags())
-                    {
-                        aStart.Y() +=30;
-                        aEnd.Y() +=30;
+    long nHght = rInf.GetOut().LogicToPixel( rPrtFontSize ).Height();
+
+    // Draw wavy lines for spell and grammar errors only if font is large enough.
+    // Lines for smart tags will always be drawn.
+    if (pWList != rInf.GetSmartTags() && WRONG_SHOW_MIN >= nHght)
+    {
+        return;
+    }
 
-                        LineInfo aLineInfo( LINE_DASH );
-                        aLineInfo.SetDistance( 40 );
-                        aLineInfo.SetDashLen( 1 );
-                        aLineInfo.SetDashCount(1);
+    SwForbidden::iterator pIter = rForbidden.begin();
+    if (rInf.GetOut().GetConnectMetaFile())
+        rInf.GetOut().Push();
 
-                        rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo );
-                    }
-                    else    // draw wavy lines for spell or grammar errors
-                    {
-                        // get wavy line type to use
-                        sal_uInt16 nWave =
-                            WRONG_SHOW_MEDIUM < nHght ? WAVE_NORMAL :
-                            ( WRONG_SHOW_SMALL < nHght ? WAVE_SMALL : WAVE_FLAT );
+    const Color aCol( rInf.GetOut().GetLineColor() );
 
-                        rInf.GetOut().DrawWaveLine( aStart, aEnd, nWave );
-                    }
-                }
+    // iterate over all ranges stored in the respective SwWrongList
+    do
+    {
+        nStart = nStart - rInf.GetIdx();
 
-                nStart = nEnd + rInf.GetIdx();
-                nWrLen = rInf.GetIdx() + rInf.GetLen() - nStart;
+        const xub_StrLen nEnd = nStart + nWrLen;
+        xub_StrLen nNext = nStart;
+        while( nNext < nEnd )
+        {
+            while( pIter != rForbidden.end() && pIter->second <= nNext )
+                ++pIter;
+
+            xub_StrLen nNextStart = nNext;
+            xub_StrLen nNextEnd = nEnd;
+
+            if( pIter == rForbidden.end() || nNextEnd <= pIter->first )
+            {
+                // No overlapping mark up found
+                std::pair< xub_StrLen, xub_StrLen > aNew;
+                aNew.first = nNextStart;
+                aNew.second = nNextEnd;
+                rForbidden.insert( pIter, aNew );
+                pIter = rForbidden.begin();
+                nNext = nEnd;
             }
-            while (nWrLen && pWList->Check( nStart, nWrLen ));
+            else
+            {
+                nNext = pIter->second;
+                if( nNextStart < pIter->first )
+                {
+                    nNextEnd = pIter->first;
+                    pIter->first = nNextStart;
+                }
+                else
+                    continue;
+            }
+            // determine line pos
+            Point aStart( rInf.GetPos() );
+            Point aEnd;
+            lcl_calcLinePos( rCalcLinePosData, aStart, aEnd, nNextStart, nNextEnd - nNextStart );
+
 
-            if (bColSave)
-                rInf.GetOut().SetLineColor( aCol );
+            sal_uInt16 wrongPos = pWList->GetWrongPos(nNextStart + rInf.GetIdx());
+
+            const SwWrongArea* wrongArea = pWList->GetElement(wrongPos);
+
+            if (wrongArea != 0)
+            {
+                if (WRONGAREA_DASHED == wrongArea->mLineType)
+                {
+                    rInf.GetOut().SetLineColor( wrongArea->mColor );
 
-            if (rInf.GetOut().GetConnectMetaFile())
-                rInf.GetOut().Pop();
+                    aStart.Y() +=30;
+                    aEnd.Y() +=30;
+
+                    LineInfo aLineInfo( LINE_DASH );
+                    aLineInfo.SetDistance( 40 );
+                    aLineInfo.SetDashLen( 1 );
+                    aLineInfo.SetDashCount(1);
+
+                    rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo );
+                }
+                else if (WRONGAREA_WAVE == wrongArea->mLineType)
+                {
+                    rInf.GetOut().SetLineColor( wrongArea->mColor );
+
+                    // get wavy line type to use
+                    sal_uInt16 nWave =
+                        WRONG_SHOW_MEDIUM < nHght ? WAVE_NORMAL :
+                        ( WRONG_SHOW_SMALL < nHght ? WAVE_SMALL : WAVE_FLAT );
+
+                    rInf.GetOut().DrawWaveLine( aStart, aEnd, nWave );
+                }
+                else if (WRONGAREA_WAVE_NORMAL == wrongArea->mLineType)
+                {
+                    rInf.GetOut().SetLineColor( wrongArea->mColor );
+
+                    rInf.GetOut().DrawWaveLine( aStart, aEnd, WAVE_NORMAL);
+                }
+
+                else if (WRONGAREA_WAVE_SMALL == wrongArea->mLineType)
+                {
+                    rInf.GetOut().SetLineColor( wrongArea->mColor );
+
+                    rInf.GetOut().DrawWaveLine( aStart, aEnd, WAVE_SMALL);
+                }
+                else if (WRONGAREA_WAVE_FLAT == wrongArea->mLineType)
+                {
+                    rInf.GetOut().SetLineColor( wrongArea->mColor );
+
+                    rInf.GetOut().DrawWaveLine( aStart, aEnd, WAVE_FLAT);
+                }
+            }
         }
+
+        nStart = nEnd + rInf.GetIdx();
+        nWrLen = rInf.GetIdx() + rInf.GetLen() - nStart;
     }
+    while (nWrLen && pWList->Check( nStart, nWrLen ));
+
+    rInf.GetOut().SetLineColor( aCol );
+
+    if (rInf.GetOut().GetConnectMetaFile())
+        rInf.GetOut().Pop();
 }