Kaydet (Commit) 5da75c78 authored tarafından Jürgen Schmidt's avatar Jürgen Schmidt

#121733# enhancement for colored smarttags

Patch By: Kai Labusch
Review by: arielch, jsc
üst c1fb6ce1
...@@ -28,12 +28,37 @@ ...@@ -28,12 +28,37 @@
#include <com/sun/star/container/XStringKeyMap.hpp> #include <com/sun/star/container/XStringKeyMap.hpp>
#endif #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 <vector>
#include <tools/string.hxx> #include <tools/string.hxx>
#include <tools/color.hxx>
#include <viewopt.hxx>
class SwWrongList; 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 // ST2
class SwWrongArea class SwWrongArea
{ {
...@@ -44,21 +69,122 @@ public: ...@@ -44,21 +69,122 @@ public:
xub_StrLen mnLen; xub_StrLen mnLen;
SwWrongList* mpSubList; 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, SwWrongArea( const rtl::OUString& rType,
com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag, com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
xub_StrLen nPos, xub_StrLen nPos,
xub_StrLen nLen, xub_StrLen nLen,
SwWrongList* pSubList ) SwWrongList* pSubList);
: maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(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 class SwWrongList
...@@ -137,7 +263,8 @@ public: ...@@ -137,7 +263,8 @@ public:
i = maList.end(); // robust i = maList.end(); // robust
else else
i += nWhere; 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, void Insert( const rtl::OUString& rType,
......
...@@ -33,6 +33,33 @@ ...@@ -33,6 +33,33 @@
#include "SwGrammarMarkUp.hxx" #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() * SwWrongList::SwWrongList()
...@@ -634,7 +661,7 @@ void SwWrongList::Insert( const rtl::OUString& rType, ...@@ -634,7 +661,7 @@ void SwWrongList::Insert( const rtl::OUString& rType,
++aIter; ++aIter;
} }
maList.insert(aIter, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) ); maList.insert(aIter, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
} }
...@@ -710,115 +710,136 @@ static void lcl_DrawLineForWrongListData( ...@@ -710,115 +710,136 @@ static void lcl_DrawLineForWrongListData(
const CalcLinePosData &rCalcLinePosData, const CalcLinePosData &rCalcLinePosData,
const Size &rPrtFontSize ) const Size &rPrtFontSize )
{ {
if (!pWList) if (!pWList) return;
return;
xub_StrLen nStart = rInf.GetIdx(); xub_StrLen nStart = rInf.GetIdx();
xub_StrLen nWrLen = rInf.GetLen(); xub_StrLen nWrLen = rInf.GetLen();
// check if respective data is available in the current text range // 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... nStart = nStart - rInf.GetIdx();
Color aLineColor;
if (pWList == rInf.GetWrong()) // ... for spell checking const xub_StrLen nEnd = nStart + nWrLen;
aLineColor = SwViewOption::GetSpellColor(); xub_StrLen nNext = nStart;
else if (pWList == rInf.GetGrammarCheck()) // ... for grammar checking while( nNext < nEnd )
// 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(); while( pIter != rForbidden.end() && pIter->second <= nNext )
if (rInf.GetOut().GetConnectMetaFile()) ++pIter;
rInf.GetOut().Push();
const Color aCol( rInf.GetOut().GetLineColor() ); xub_StrLen nNextStart = nNext;
const sal_Bool bColSave = aCol != aLineColor; xub_StrLen nNextEnd = nEnd;
if (bColSave)
rInf.GetOut().SetLineColor( aLineColor );
// iterate over all ranges stored in the respective SwWrongList if( pIter == rForbidden.end() || nNextEnd <= pIter->first )
do
{ {
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; sal_uInt16 wrongPos = pWList->GetWrongPos(nNextStart + rInf.GetIdx());
xub_StrLen nNext = nStart;
while( nNext < nEnd ) const SwWrongArea* wrongArea = pWList->GetElement(wrongPos);
if (wrongArea != 0)
{
if (WRONGAREA_DASHED == wrongArea->mLineType)
{ {
while( pIter != rForbidden.end() && pIter->second <= nNext ) rInf.GetOut().SetLineColor( wrongArea->mColor );
++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 );
// draw line for smart tags? aStart.Y() +=30;
if (pWList == rInf.GetSmartTags()) aEnd.Y() +=30;
{
aStart.Y() +=30;
aEnd.Y() +=30;
LineInfo aLineInfo( LINE_DASH ); LineInfo aLineInfo( LINE_DASH );
aLineInfo.SetDistance( 40 ); aLineInfo.SetDistance( 40 );
aLineInfo.SetDashLen( 1 ); aLineInfo.SetDashLen( 1 );
aLineInfo.SetDashCount(1); aLineInfo.SetDashCount(1);
rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo ); rInf.GetOut().DrawLine( aStart, aEnd, aLineInfo );
} }
else // draw wavy lines for spell or grammar errors else if (WRONGAREA_WAVE == wrongArea->mLineType)
{ {
// get wavy line type to use rInf.GetOut().SetLineColor( wrongArea->mColor );
sal_uInt16 nWave =
WRONG_SHOW_MEDIUM < nHght ? WAVE_NORMAL :
( WRONG_SHOW_SMALL < nHght ? WAVE_SMALL : WAVE_FLAT );
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(); rInf.GetOut().DrawWaveLine( aStart, aEnd, WAVE_NORMAL);
nWrLen = rInf.GetIdx() + rInf.GetLen() - nStart; }
}
while (nWrLen && pWList->Check( nStart, nWrLen ));
if (bColSave) else if (WRONGAREA_WAVE_SMALL == wrongArea->mLineType)
rInf.GetOut().SetLineColor( aCol ); {
rInf.GetOut().SetLineColor( wrongArea->mColor );
if (rInf.GetOut().GetConnectMetaFile()) rInf.GetOut().DrawWaveLine( aStart, aEnd, WAVE_SMALL);
rInf.GetOut().Pop(); }
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();
} }
......
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