summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJürgen Schmidt <jsc@apache.org>2013-03-20 14:18:15 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-05-23 11:55:27 +0100
commit79b231f7a032c7e04b74fa019e18a5d7e3b5f4f3 (patch)
tree64ac7648566d3180e7fafaeddbadb7620c982e4c /sw
parentc5b604b9527d0dc32066e17dc3ce7f7370a78fe1 (diff)
Resolves: #i121733# enhancement for colored smarttags
Patch By: Kai Labusch Review by: arielch, jsc (cherry picked from commit 5da75c78a80e43cb2bb4ed777ae5efcc1449cdda) Conflicts: sw/source/core/inc/wrong.hxx sw/source/core/txtnode/fntcache.cxx Change-Id: Ibc609ce4ef3492b537bb1ddec5ff7c460eb2c573
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/inc/wrong.hxx149
-rw-r--r--sw/source/core/text/wrong.cxx29
-rw-r--r--sw/source/core/txtnode/fntcache.cxx195
3 files changed, 274 insertions, 99 deletions
diff --git a/sw/source/core/inc/wrong.hxx b/sw/source/core/inc/wrong.hxx
index a2add8569bcd..215fcd92bc51 100644
--- a/sw/source/core/inc/wrong.hxx
+++ b/sw/source/core/inc/wrong.hxx
@@ -22,12 +22,37 @@
#include <com/sun/star/container/XStringKeyMap.hpp>
+#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
{
@@ -38,21 +63,122 @@ public:
xub_StrLen mnLen;
SwWrongList* mpSubList;
- SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL) {}
+ Color mColor;
+ WrongAreaLineType mLineType;
+
+ SwWrongArea( const OUString& rType,
+ WrongListType listType,
+ com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
+ xub_StrLen nPos,
+ xub_StrLen nLen);
+
SwWrongArea( const 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
@@ -131,7 +257,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 OUString& rType,
diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx
index 4dabc006fb7c..59ce856f3560 100644
--- a/sw/source/core/text/wrong.cxx
+++ b/sw/source/core/text/wrong.cxx
@@ -22,6 +22,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()
@@ -622,7 +649,7 @@ void SwWrongList::Insert( const OUString& rType,
++aIter;
}
- maList.insert(aIter, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) );
+ maList.insert(aIter, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
}
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 83981599c0df..77ae8499ce4e 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -665,115 +665,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 ))
+ {
+ return;
+ }
+
+ 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;
+ }
+
+ SwForbidden::iterator pIter = rForbidden.begin();
+ if (rInf.GetOut().GetConnectMetaFile())
+ rInf.GetOut().Push();
+
+ const Color aCol( rInf.GetOut().GetLineColor() );
+
+ // iterate over all ranges stored in the respective SwWrongList
+ do
{
- // 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)
+ nStart = nStart - rInf.GetIdx();
+
+ const xub_StrLen nEnd = nStart + nWrLen;
+ xub_StrLen nNext = nStart;
+ while( nNext < nEnd )
{
- SwForbidden::iterator pIter = rForbidden.begin();
- if (rInf.GetOut().GetConnectMetaFile())
- rInf.GetOut().Push();
+ while( pIter != rForbidden.end() && pIter->second <= nNext )
+ ++pIter;
- const Color aCol( rInf.GetOut().GetLineColor() );
- const bool bColSave = aCol != aLineColor;
- if (bColSave)
- rInf.GetOut().SetLineColor( aLineColor );
+ xub_StrLen nNextStart = nNext;
+ xub_StrLen nNextEnd = nEnd;
- // iterate over all ranges stored in the respective SwWrongList
- do
+ if( pIter == rForbidden.end() || nNextEnd <= pIter->first )
{
- nStart = nStart - rInf.GetIdx();
+ // 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 );
+
- const xub_StrLen nEnd = nStart + nWrLen;
- xub_StrLen nNext = nStart;
- while( nNext < nEnd )
+ sal_uInt16 wrongPos = pWList->GetWrongPos(nNextStart + rInf.GetIdx());
+
+ const SwWrongArea* wrongArea = pWList->GetElement(wrongPos);
+
+ if (wrongArea != 0)
+ {
+ if (WRONGAREA_DASHED == wrongArea->mLineType)
{
- 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 );
+ rInf.GetOut().SetLineColor( wrongArea->mColor );
- // draw line for smart tags?
- if (pWList == rInf.GetSmartTags())
- {
- aStart.Y() +=30;
- aEnd.Y() +=30;
+ aStart.Y() +=30;
+ aEnd.Y() +=30;
- LineInfo aLineInfo( LINE_DASH );
- aLineInfo.SetDistance( 40 );
- aLineInfo.SetDashLen( 1 );
- aLineInfo.SetDashCount(1);
+ LineInfo aLineInfo( LINE_DASH );
+ aLineInfo.SetDistance( 40 );
+ aLineInfo.SetDashLen( 1 );
+ aLineInfo.SetDashCount(1);
- 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 );
+ rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo );
+ }
+ else if (WRONGAREA_WAVE == wrongArea->mLineType)
+ {
+ rInf.GetOut().SetLineColor( wrongArea->mColor );
- rInf.GetOut().DrawWaveLine( aStart, aEnd, nWave );
- }
+ // 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 );
- nStart = nEnd + rInf.GetIdx();
- nWrLen = rInf.GetIdx() + rInf.GetLen() - nStart;
- }
- while (nWrLen && pWList->Check( nStart, nWrLen ));
+ rInf.GetOut().DrawWaveLine( aStart, aEnd, WAVE_NORMAL);
+ }
- if (bColSave)
- rInf.GetOut().SetLineColor( aCol );
+ else if (WRONGAREA_WAVE_SMALL == wrongArea->mLineType)
+ {
+ rInf.GetOut().SetLineColor( wrongArea->mColor );
- if (rInf.GetOut().GetConnectMetaFile())
- rInf.GetOut().Pop();
+ 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();
}