tdf#154088 Merge code snippets for character retrieval and string construction
The DrawChars_Impl method has been unified since the duplicates were identical and only differed in how they retrieved characters from a separate source. Each class now has its own implentation of GetCharFromIndex as a solution. Change-Id: Ic2d10a46a91ea8dee2c94b620e6745bf77ae9eab Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159773 Tested-by: Jenkins Reviewed-by: Hossein <hossein@libreoffice.org>
This commit is contained in:
parent
847001ffbb
commit
94d2d9a594
4 changed files with 20 additions and 150 deletions
|
@ -66,6 +66,7 @@ public:
|
||||||
|
|
||||||
void SelectCharacter( sal_UCS4 cNew );
|
void SelectCharacter( sal_UCS4 cNew );
|
||||||
virtual sal_UCS4 GetSelectCharacter() const;
|
virtual sal_UCS4 GetSelectCharacter() const;
|
||||||
|
virtual sal_UCS4 GetCharFromIndex(int index) const;
|
||||||
void createContextMenu(const Point& rPosition);
|
void createContextMenu(const Point& rPosition);
|
||||||
|
|
||||||
void SetDoubleClickHdl( const Link<SvxShowCharSet*,void>& rLink ) { aDoubleClkHdl = rLink; }
|
void SetDoubleClickHdl( const Link<SvxShowCharSet*,void>& rLink ) { aDoubleClkHdl = rLink; }
|
||||||
|
@ -148,7 +149,7 @@ protected:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool KeyInput(const KeyEvent&) override;
|
virtual bool KeyInput(const KeyEvent&) override;
|
||||||
virtual void DrawChars_Impl(vcl::RenderContext& rRenderContext, int n1, int n2);
|
void DrawChars_Impl(vcl::RenderContext& rRenderContext, int n1, int n2);
|
||||||
void InitSettings(vcl::RenderContext& rRenderContext);
|
void InitSettings(vcl::RenderContext& rRenderContext);
|
||||||
// abstraction layers are: Unicode<->MapIndex<->Pixel
|
// abstraction layers are: Unicode<->MapIndex<->Pixel
|
||||||
Point MapIndexToPixel( int) const;
|
Point MapIndexToPixel( int) const;
|
||||||
|
|
|
@ -44,6 +44,7 @@ public:
|
||||||
|
|
||||||
void SelectCharacter( const Subset* sub);
|
void SelectCharacter( const Subset* sub);
|
||||||
virtual sal_UCS4 GetSelectCharacter() const override;
|
virtual sal_UCS4 GetSelectCharacter() const override;
|
||||||
|
virtual sal_UCS4 GetCharFromIndex(int index) const override;
|
||||||
|
|
||||||
virtual svx::SvxShowCharSetItem* ImplGetItem( int _nPos ) override;
|
virtual svx::SvxShowCharSetItem* ImplGetItem( int _nPos ) override;
|
||||||
virtual int LastInView() const override;
|
virtual int LastInView() const override;
|
||||||
|
@ -59,7 +60,6 @@ private:
|
||||||
//to uniquely identify each appended element
|
//to uniquely identify each appended element
|
||||||
std::unordered_map<sal_Int32, sal_UCS4> m_aItemList;
|
std::unordered_map<sal_Int32, sal_UCS4> m_aItemList;
|
||||||
private:
|
private:
|
||||||
virtual void DrawChars_Impl(vcl::RenderContext& rRenderContext, int n1, int n2) override;
|
|
||||||
virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
|
virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
|
||||||
virtual bool KeyInput(const KeyEvent& rKEvt) override;
|
virtual bool KeyInput(const KeyEvent& rKEvt) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -534,12 +534,17 @@ void SvxShowCharSet::DrawChars_Impl(vcl::RenderContext& rRenderContext, int n1,
|
||||||
tools::Rectangle aBoundRect;
|
tools::Rectangle aBoundRect;
|
||||||
for (i = n1; i <= n2; ++i)
|
for (i = n1; i <= n2; ++i)
|
||||||
{
|
{
|
||||||
|
sal_UCS4 charValue = GetCharFromIndex(i);
|
||||||
|
|
||||||
|
if (charValue == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
OUString aCharStr(&charValue, 1);
|
||||||
|
|
||||||
Point pix = MapIndexToPixel(i);
|
Point pix = MapIndexToPixel(i);
|
||||||
int x = pix.X();
|
int x = pix.X();
|
||||||
int y = pix.Y();
|
int y = pix.Y();
|
||||||
|
|
||||||
sal_UCS4 nChar = mxFontCharMap->GetCharFromIndex(i);
|
|
||||||
OUString aCharStr(&nChar, 1);
|
|
||||||
int nTextWidth = rRenderContext.GetTextWidth(aCharStr);
|
int nTextWidth = rRenderContext.GetTextWidth(aCharStr);
|
||||||
int tx = x + (nX - nTextWidth + 1) / 2;
|
int tx = x + (nX - nTextWidth + 1) / 2;
|
||||||
int ty = y + (nY - nTextHeight + 1) / 2;
|
int ty = y + (nY - nTextHeight + 1) / 2;
|
||||||
|
@ -672,6 +677,10 @@ sal_UCS4 SvxShowCharSet::GetSelectCharacter() const
|
||||||
return getSelectedChar();
|
return getSelectedChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sal_UCS4 SvxShowCharSet::GetCharFromIndex(int index) const
|
||||||
|
{
|
||||||
|
return mxFontCharMap->GetCharFromIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
void SvxShowCharSet::RecalculateFont(vcl::RenderContext& rRenderContext)
|
void SvxShowCharSet::RecalculateFont(vcl::RenderContext& rRenderContext)
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,6 +140,12 @@ void SvxSearchCharSet::SelectCharacter( const Subset* sub )
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sal_UCS4 SvxSearchCharSet::GetCharFromIndex(int index) const
|
||||||
|
{
|
||||||
|
std::unordered_map<sal_Int32, sal_UCS4>::const_iterator got = m_aItemList.find(index);
|
||||||
|
return (got != m_aItemList.end()) ? got->second : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void SvxSearchCharSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
|
void SvxSearchCharSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
|
||||||
{
|
{
|
||||||
InitSettings(rRenderContext);
|
InitSettings(rRenderContext);
|
||||||
|
@ -147,152 +153,6 @@ void SvxSearchCharSet::Paint(vcl::RenderContext& rRenderContext, const tools::Re
|
||||||
DrawChars_Impl(rRenderContext, FirstInView(), LastInView());
|
DrawChars_Impl(rRenderContext, FirstInView(), LastInView());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SvxSearchCharSet::DrawChars_Impl(vcl::RenderContext& rRenderContext, int n1, int n2)
|
|
||||||
{
|
|
||||||
if (n1 > LastInView() || n2 < FirstInView())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Size aOutputSize(GetOutputSizePixel());
|
|
||||||
|
|
||||||
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
|
|
||||||
const Color aWindowTextColor(rStyleSettings.GetFieldTextColor());
|
|
||||||
Color aHighlightColor(rStyleSettings.GetHighlightColor());
|
|
||||||
Color aHighlightTextColor(rStyleSettings.GetHighlightTextColor());
|
|
||||||
Color aFaceColor(rStyleSettings.GetFaceColor());
|
|
||||||
Color aLightColor(rStyleSettings.GetLightColor());
|
|
||||||
Color aShadowColor(rStyleSettings.GetShadowColor());
|
|
||||||
|
|
||||||
int i;
|
|
||||||
rRenderContext.SetLineColor(aShadowColor);
|
|
||||||
for (i = 1; i < COLUMN_COUNT; ++i)
|
|
||||||
{
|
|
||||||
rRenderContext.DrawLine(Point(nX * i + m_nXGap, 0),
|
|
||||||
Point(nX * i + m_nXGap, aOutputSize.Height()));
|
|
||||||
}
|
|
||||||
for (i = 1; i < ROW_COUNT; ++i)
|
|
||||||
{
|
|
||||||
rRenderContext.DrawLine(Point(0, nY * i + m_nYGap),
|
|
||||||
Point(aOutputSize.Width(), nY * i + m_nYGap));
|
|
||||||
}
|
|
||||||
|
|
||||||
int nTextHeight = rRenderContext.GetTextHeight();
|
|
||||||
tools::Rectangle aBoundRect;
|
|
||||||
for (i = n1; i <= n2; ++i)
|
|
||||||
{
|
|
||||||
Point pix = MapIndexToPixel(i);
|
|
||||||
int x = pix.X();
|
|
||||||
int y = pix.Y();
|
|
||||||
|
|
||||||
OUStringBuffer buf;
|
|
||||||
std::unordered_map<sal_Int32, sal_UCS4>::const_iterator got = m_aItemList.find (i);
|
|
||||||
sal_UCS4 sName;
|
|
||||||
|
|
||||||
if(got == m_aItemList.end())
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
sName = got->second;
|
|
||||||
|
|
||||||
buf.appendUtf32(sName);
|
|
||||||
OUString aCharStr(buf.makeStringAndClear());
|
|
||||||
int nTextWidth = rRenderContext.GetTextWidth(aCharStr);
|
|
||||||
int tx = x + (nX - nTextWidth + 1) / 2;
|
|
||||||
int ty = y + (nY - nTextHeight + 1) / 2;
|
|
||||||
Point aPointTxTy(tx, ty);
|
|
||||||
|
|
||||||
// adjust position before it gets out of bounds
|
|
||||||
if (rRenderContext.GetTextBoundRect(aBoundRect, aCharStr) && !aBoundRect.IsEmpty())
|
|
||||||
{
|
|
||||||
// zero advance width => use ink width to center glyph
|
|
||||||
if (!nTextWidth)
|
|
||||||
{
|
|
||||||
aPointTxTy.setX( x - aBoundRect.Left() + (nX - aBoundRect.GetWidth() + 1) / 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
aBoundRect += aPointTxTy;
|
|
||||||
|
|
||||||
// shift back vertically if needed
|
|
||||||
int nYLDelta = aBoundRect.Top() - y;
|
|
||||||
int nYHDelta = (y + nY) - aBoundRect.Bottom();
|
|
||||||
if (nYLDelta <= 0)
|
|
||||||
aPointTxTy.AdjustY( -(nYLDelta - 1) );
|
|
||||||
else if (nYHDelta <= 0)
|
|
||||||
aPointTxTy.AdjustY(nYHDelta - 1 );
|
|
||||||
|
|
||||||
// shift back horizontally if needed
|
|
||||||
int nXLDelta = aBoundRect.Left() - x;
|
|
||||||
int nXHDelta = (x + nX) - aBoundRect.Right();
|
|
||||||
if (nXLDelta <= 0)
|
|
||||||
aPointTxTy.AdjustX( -(nXLDelta - 1) );
|
|
||||||
else if (nXHDelta <= 0)
|
|
||||||
aPointTxTy.AdjustX(nXHDelta - 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// tdf#109214 - highlight the favorite characters
|
|
||||||
if (isFavChar(aCharStr, mxVirDev->GetFont().GetFamilyName()))
|
|
||||||
{
|
|
||||||
const Color aLineCol = rRenderContext.GetLineColor();
|
|
||||||
rRenderContext.SetLineColor(aHighlightColor);
|
|
||||||
rRenderContext.SetFillColor(COL_TRANSPARENT);
|
|
||||||
// Outer border
|
|
||||||
rRenderContext.DrawRect(tools::Rectangle(Point(x - 1, y - 1), Size(nX + 3, nY + 3)), 1, 1);
|
|
||||||
// Inner border
|
|
||||||
rRenderContext.DrawRect(tools::Rectangle(Point(x, y), Size(nX + 1, nY + 1)), 1, 1);
|
|
||||||
rRenderContext.SetLineColor(aLineCol);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color aTextCol = rRenderContext.GetTextColor();
|
|
||||||
if (i != nSelectedIndex)
|
|
||||||
{
|
|
||||||
rRenderContext.SetTextColor(aWindowTextColor);
|
|
||||||
rRenderContext.DrawText(aPointTxTy, aCharStr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Color aLineCol = rRenderContext.GetLineColor();
|
|
||||||
Color aFillCol = rRenderContext.GetFillColor();
|
|
||||||
rRenderContext.SetLineColor();
|
|
||||||
Point aPointUL(x + 1, y + 1);
|
|
||||||
if (HasFocus())
|
|
||||||
{
|
|
||||||
rRenderContext.SetFillColor(aHighlightColor);
|
|
||||||
rRenderContext.DrawRect(getGridRectangle(aPointUL, aOutputSize));
|
|
||||||
|
|
||||||
rRenderContext.SetTextColor(aHighlightTextColor);
|
|
||||||
rRenderContext.DrawText(aPointTxTy, aCharStr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rRenderContext.SetFillColor(aFaceColor);
|
|
||||||
rRenderContext.DrawRect(getGridRectangle(aPointUL, aOutputSize));
|
|
||||||
|
|
||||||
rRenderContext.SetLineColor(aLightColor);
|
|
||||||
rRenderContext.DrawLine(aPointUL, Point(x + nX - 1, y + 1));
|
|
||||||
rRenderContext.DrawLine(aPointUL, Point(x + 1, y + nY - 1));
|
|
||||||
|
|
||||||
rRenderContext.SetLineColor(aShadowColor);
|
|
||||||
rRenderContext.DrawLine(Point(x + 1, y + nY - 1), Point(x + nX - 1, y + nY - 1));
|
|
||||||
rRenderContext.DrawLine(Point(x + nX - 1, y + nY - 1), Point(x + nX - 1, y + 1));
|
|
||||||
|
|
||||||
rRenderContext.DrawText(aPointTxTy, aCharStr);
|
|
||||||
}
|
|
||||||
rRenderContext.SetLineColor(aLineCol);
|
|
||||||
rRenderContext.SetFillColor(aFillCol);
|
|
||||||
}
|
|
||||||
rRenderContext.SetTextColor(aTextCol);
|
|
||||||
}
|
|
||||||
|
|
||||||
// tdf#141319 - mark empty/unused cells
|
|
||||||
if (n2 - n1 < ROW_COUNT * COLUMN_COUNT)
|
|
||||||
{
|
|
||||||
rRenderContext.SetFillColor(rStyleSettings.GetDisableColor());
|
|
||||||
for (i = n2 - n1 + 1; i < ROW_COUNT * COLUMN_COUNT; i++)
|
|
||||||
{
|
|
||||||
rRenderContext.DrawRect(
|
|
||||||
tools::Rectangle(MapIndexToPixel(i + n1), Size(nX + 2, nY + 2)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sal_UCS4 SvxSearchCharSet::GetSelectCharacter() const
|
sal_UCS4 SvxSearchCharSet::GetSelectCharacter() const
|
||||||
{
|
{
|
||||||
if( nSelectedIndex >= 0 )
|
if( nSelectedIndex >= 0 )
|
||||||
|
|
Loading…
Reference in a new issue