Kaydet (Commit) 68d06f69 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

StyleManager & StylePreviewRenderer + common implementation

StyleManager is a new class responsible to handle document styles.
The current implementation has only the responsibility to provide
a implementation of StylePreviewReneder, but the idea is to move
all style related functionallity to this class (and relieve the
SfxObjectShell a bit). CommonStyleMAnager is the common impl.

StylePreviewRenderer is responsible to render a preview of a style.
As styles can be handled differently by each component it is
possible to provide component specific StylePreviewRendered, but
currently only the common one is implemented and used by sw.

Change-Id: Id271485f571a777a3e94f855d3c614a2efc14628
üst a630f4f2
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SFX2_STYLEMANAGER_HXX
#define INCLUDED_SFX2_STYLEMANAGER_HXX
#include <sfx2/dllapi.h>
#include <vcl/outdev.hxx>
#include <sfx2/StylePreviewRenderer.hxx>
#include <rsc/rscsfx.hxx>
#include <sfx2/objsh.hxx>
namespace sfx2
{
class SFX2_DLLPUBLIC StyleManager
{
protected:
SfxObjectShell& mrShell;
public:
StyleManager(SfxObjectShell& rShell)
: mrShell(rShell)
{}
virtual ~StyleManager()
{}
virtual StylePreviewRenderer* CreateStylePreviewRenderer(
OutputDevice& /*rOutputDev*/, OUString /*rName*/,
SfxStyleFamily /*eFamily*/, long /*nMaxHeight*/ = 32) = 0;
};
} // end namespace sfx2
#endif //INCLUDED_SFX2_STYLEMANAGER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SFX2_STYLEPREVIEWRENDERER_HXX
#define INCLUDED_SFX2_STYLEPREVIEWRENDERER_HXX
#include <sfx2/dllapi.h>
#include <vcl/outdev.hxx>
#include <rsc/rscsfx.hxx>
#include <svl/style.hxx>
#include <sfx2/objsh.hxx>
namespace sfx2
{
class SFX2_DLLPUBLIC StylePreviewRenderer
{
protected:
const SfxObjectShell& mrShell;
OutputDevice& mrOutputDev;
SfxStyleSheetBase* mpStyle;
long mnMaxHeight;
public:
StylePreviewRenderer(const SfxObjectShell& rShell,
OutputDevice& rOutputDev,
SfxStyleSheetBase* pStyle,
long nMaxHeight = 32)
: mrShell(rShell)
, mrOutputDev(rOutputDev)
, mpStyle(pStyle)
, mnMaxHeight(nMaxHeight)
{}
virtual ~StylePreviewRenderer()
{}
virtual bool recalculate() = 0;
virtual Size getRenderSize() = 0;
virtual bool render(const Rectangle& aRectangle) = 0;
};
} // end namespace sfx2
#endif // INCLUDED_SVX_STYLEPREVIEWRENDERER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -97,6 +97,7 @@ enum class SfxModelFlags;
namespace sfx2
{
class SvLinkSource;
class StyleManager;
}
namespace com { namespace sun { namespace star { namespace datatransfer { class XTransferable; } } } }
......@@ -494,8 +495,14 @@ public:
// Contents
virtual SfxStyleSheetBasePool* GetStyleSheetPool();
void SetStyleSheetPool(SfxStyleSheetBasePool *pBasePool ) {
pStyleSheetPool = pBasePool; }
void SetStyleSheetPool(SfxStyleSheetBasePool *pBasePool )
{
pStyleSheetPool = pBasePool;
}
virtual void LoadStyles(SfxObjectShell &rSource);
virtual sfx2::StyleManager* GetStyleManager();
// Determine the position of the "Automatic" filter in the stylist
void SetAutoStyleFilterIndex(sal_uInt16 nSet);
......@@ -510,7 +517,6 @@ public:
virtual std::set<Color> GetDocColors();
virtual void LoadStyles( SfxObjectShell &rSource );
void ReadNote( INote * );
void UpdateNote( INote * );
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SVX_COMMONSTYLEMANAGER_HXX
#define INCLUDED_SVX_COMMONSTYLEMANAGER_HXX
#include <sfx2/StyleManager.hxx>
#include <vcl/outdev.hxx>
#include <svx/svxdllapi.h>
#include <rsc/rscsfx.hxx>
namespace svx
{
class SVX_DLLPUBLIC CommonStyleManager : public sfx2::StyleManager
{
public:
CommonStyleManager(SfxObjectShell& rShell)
: StyleManager(rShell)
{}
virtual ~CommonStyleManager()
{}
virtual sfx2::StylePreviewRenderer* CreateStylePreviewRenderer(
OutputDevice& rOutputDev, OUString sName,
SfxStyleFamily eFamily, long nMaxHeight = 32) SAL_OVERRIDE;
};
} // end namespace svx
#endif // INCLUDED_SVX_COMMONSTYLEMANAGER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SVX_COMMONSTYLEPREVIEWRENDERER_HXX
#define INCLUDED_SVX_COMMONSTYLEPREVIEWRENDERER_HXX
#include <vcl/outdev.hxx>
#include <rsc/rscsfx.hxx>
#include <editeng/svxfont.hxx>
#include <svx/svxdllapi.h>
#include <sfx2/StylePreviewRenderer.hxx>
namespace svx
{
class SVX_DLLPUBLIC CommonStylePreviewRenderer : public sfx2::StylePreviewRenderer
{
SvxFont maFont;
Color maFontColor;
Color maBackgroundColor;
Size maPixelSize;
OUString maStyleName;
public:
CommonStylePreviewRenderer(const SfxObjectShell& rShell, OutputDevice& rOutputDev,
SfxStyleSheetBase* pStyle, long nMaxHeight = 32);
virtual ~CommonStylePreviewRenderer();
virtual bool recalculate() SAL_OVERRIDE;
virtual Size getRenderSize() SAL_OVERRIDE;
virtual bool render(const Rectangle& aRectangle) SAL_OVERRIDE;
};
} // end namespace svx
#endif // INCLUDED_SVX_COMMONSTYLEPREVIEWRENDERER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -365,7 +365,10 @@ void SfxObjectShell::LoadStyles
}
}
sfx2::StyleManager* SfxObjectShell::GetStyleManager()
{
return nullptr;
}
void SfxObjectShell::UpdateFromTemplate_Impl( )
......
......@@ -338,6 +338,8 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/svdraw/svdview \
svx/source/svdraw/svdviter \
svx/source/svdraw/svdxcgv \
svx/source/styles/CommonStylePreviewRenderer \
svx/source/styles/CommonStyleManager \
svx/source/table/cell \
svx/source/table/cellcursor \
svx/source/table/cellrange \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <svx/CommonStyleManager.hxx>
#include <svx/CommonStylePreviewRenderer.hxx>
namespace svx
{
sfx2::StylePreviewRenderer* CommonStyleManager::CreateStylePreviewRenderer(
OutputDevice& rOutputDev, OUString sName,
SfxStyleFamily eFamily, long nMaxHeight)
{
SfxStyleSheetBasePool* pPool = mrShell.GetStyleSheetPool();
if (!pPool)
return nullptr;
pPool->SetSearchMask(eFamily, SFXSTYLEBIT_ALL);
SfxStyleSheetBase* pStyle = nullptr;
pStyle = pPool->First();
while (pStyle)
{
if (sName == pStyle->GetName())
return new CommonStylePreviewRenderer(mrShell, rOutputDev, pStyle, nMaxHeight);
pStyle = pPool->Next();
}
return nullptr;
}
} // end svx namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <svx/CommonStylePreviewRenderer.hxx>
#include <sfx2/objsh.hxx>
#include <svl/style.hxx>
#include <svl/itemset.hxx>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <svx/xdef.hxx>
#include <svx/xfillit0.hxx>
#include <svx/xflclit.hxx>
#include <svx/xcolit.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/charreliefitem.hxx>
#include <editeng/contouritem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/crossedoutitem.hxx>
#include <editeng/emphasismarkitem.hxx>
#include <editeng/flstitem.hxx>
#include <editeng/lineitem.hxx>
#include <editeng/postitem.hxx>
#include <editeng/shdditem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/svxfont.hxx>
#include <editeng/cmapitem.hxx>
#include <editeng/editids.hrc>
using namespace css;
namespace svx
{
CommonStylePreviewRenderer::CommonStylePreviewRenderer(
const SfxObjectShell& rShell, OutputDevice& rOutputDev,
SfxStyleSheetBase* pStyle, long nMaxHeight)
: StylePreviewRenderer(rShell, rOutputDev, pStyle, nMaxHeight)
, maFont()
, maFontColor(COL_AUTO)
, maBackgroundColor(COL_AUTO)
, maPixelSize()
, maStyleName(mpStyle->GetName())
{
}
CommonStylePreviewRenderer::~CommonStylePreviewRenderer()
{}
bool CommonStylePreviewRenderer::recalculate()
{
const SfxItemSet& aItemSet = mpStyle->GetItemSet();
maFont = SvxFont();
const SfxPoolItem* pItem;
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_WEIGHT)) != nullptr)
{
maFont.SetWeight(static_cast<const SvxWeightItem*>(pItem)->GetWeight());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_POSTURE)) != nullptr)
{
maFont.SetItalic(static_cast<const SvxPostureItem*>(pItem)->GetPosture());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_CONTOUR)) != nullptr)
{
maFont.SetOutline(static_cast< const SvxContourItem*>(pItem)->GetValue());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_SHADOWED)) != nullptr)
{
maFont.SetShadow(static_cast<const SvxShadowedItem*>(pItem)->GetValue());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_RELIEF)) != nullptr)
{
maFont.SetRelief(static_cast<FontRelief>(static_cast<const SvxCharReliefItem*>(pItem)->GetValue()));
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_UNDERLINE)) != nullptr)
{
maFont.SetUnderline(static_cast< const SvxUnderlineItem*>(pItem)->GetLineStyle());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_OVERLINE)) != nullptr)
{
maFont.SetOverline(static_cast<FontUnderline>(static_cast<const SvxOverlineItem*>(pItem)->GetValue()));
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_STRIKEOUT)) != nullptr)
{
maFont.SetStrikeout(static_cast<const SvxCrossedOutItem*>(pItem)->GetStrikeout());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_CASEMAP)) != nullptr)
{
maFont.SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_EMPHASISMARK)) != nullptr)
{
maFont.SetEmphasisMark(static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark());
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_COLOR)) != nullptr)
{
maFontColor = Color(static_cast<const SvxColorItem*>(pItem)->GetValue());
}
if (mpStyle->GetFamily() == SFX_STYLE_FAMILY_PARA)
{
if ((pItem = aItemSet.GetItem(XATTR_FILLSTYLE)) != nullptr)
{
sal_uInt16 aFillStyle = static_cast<const XFillStyleItem*>(pItem)->GetValue();
if (aFillStyle == drawing::FillStyle_SOLID)
{
if ((pItem = aItemSet.GetItem(XATTR_FILLCOLOR)) != nullptr)
{
maBackgroundColor = Color(static_cast<const XFillColorItem*>(pItem)->GetColorValue());
}
}
}
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_FONT)) != nullptr)
{
const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(pItem);
maFont.SetName(pFontItem->GetFamilyName());
maFont.SetStyleName(pFontItem->GetStyleName());
}
else
{
return false;
}
if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_FONTHEIGHT)) != nullptr)
{
const SvxFontHeightItem* pFontHeightItem = static_cast<const SvxFontHeightItem*>(pItem);
Size aFontSize(0, pFontHeightItem->GetHeight());
maPixelSize = Size(mrOutputDev.LogicToPixel(aFontSize, mrShell.GetMapUnit()));
maFont.SetSize(maPixelSize);
vcl::Font aOldFont(mrOutputDev.GetFont());
mrOutputDev.SetFont(maFont);
Rectangle aTextRect;
mrOutputDev.GetTextBoundRect(aTextRect, mpStyle->GetName());
if (aTextRect.Bottom() > mnMaxHeight)
{
double ratio = double(mnMaxHeight) / aTextRect.Bottom();
maPixelSize.Width() *= ratio;
maPixelSize.Height() *= ratio;
maFont.SetSize(maPixelSize);
}
mrOutputDev.SetFont(aOldFont);
}
else
{
return false;
}
return true;
}
Size CommonStylePreviewRenderer::getRenderSize()
{
maPixelSize = maFont.GetTxtSize(&mrOutputDev, maStyleName);
if (maPixelSize.Height() > mnMaxHeight)
maPixelSize.Height() = mnMaxHeight;
return maPixelSize;
}
bool CommonStylePreviewRenderer::render(const Rectangle& aRectangle)
{
// setup the device & draw
vcl::Font aOldFont(mrOutputDev.GetFont());
Color aOldColor(mrOutputDev.GetTextColor());
Color aOldFillColor(mrOutputDev.GetFillColor());
if (maBackgroundColor != COL_AUTO)
{
mrOutputDev.SetFillColor(maBackgroundColor);
mrOutputDev.DrawRect(aRectangle);
}
mrOutputDev.SetFont(maFont);
if (maFontColor != COL_AUTO)
mrOutputDev.SetTextColor(maFontColor);
Point aFontDrawPosition = aRectangle.TopLeft();
if (aRectangle.GetHeight() > maPixelSize.Height())
aFontDrawPosition.Y() += ( aRectangle.GetHeight() - maPixelSize.Height() ) / 2;
mrOutputDev.DrawText(aFontDrawPosition, maStyleName);
mrOutputDev.SetFillColor(aOldFillColor);
mrOutputDev.SetTextColor(aOldColor);
mrOutputDev.SetFont(aOldFont);
return true;
}
} // end svx namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -32,6 +32,8 @@
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitTypes.h>
#include <sfx2/StyleManager.hxx>
class SwDoc;
class SfxDocumentInfoDialog;
class SfxStyleSheetBasePool;
......@@ -67,6 +69,8 @@ class SW_DLLPUBLIC SwDocShell
FontList* m_pFontList; ///< Current Fontlist.
bool m_IsInUpdateFontList; ///< prevent nested calls of UpdateFontList
std::unique_ptr<sfx2::StyleManager> m_pStyleManager;
/** For "historical reasons" nothing can be done without the WrtShell.
Back-pointer on View (again "for historical reasons").
Back-pointer is valid until in Activate a new one is set
......@@ -212,6 +216,7 @@ public:
/// For Style PI.
virtual SfxStyleSheetBasePool* GetStyleSheetPool() SAL_OVERRIDE;
virtual sfx2::StyleManager* GetStyleManager() SAL_OVERRIDE;
/// Set View for actions via Shell.
void SetView(SwView* pVw);
......
......@@ -1064,6 +1064,11 @@ SfxStyleSheetBasePool* SwDocShell::GetStyleSheetPool()
return m_xBasePool.get();
}
sfx2::StyleManager* SwDocShell::GetStyleManager()
{
return m_pStyleManager.get();
}
void SwDocShell::SetView(SwView* pVw)
{
SetViewShell_Impl(pVw);
......
......@@ -86,6 +86,8 @@
#include <globals.hrc>
#include <unochart.hxx>
#include <svx/CommonStyleManager.hxx>
// text grid
#include <tgrditem.hxx>
#include <boost/scoped_ptr.hpp>
......@@ -326,6 +328,7 @@ SwDocShell::SwDocShell( SfxObjectCreateMode const eMode )
, m_pDoc(nullptr)
, m_pFontList(nullptr)
, m_IsInUpdateFontList(false)
, m_pStyleManager(new svx::CommonStyleManager(*this))
, m_pView(nullptr)
, m_pWrtShell(nullptr)
, m_pOLEChildList(nullptr)
......@@ -342,6 +345,7 @@ SwDocShell::SwDocShell( const SfxModelFlags i_nSfxCreationFlags )
, m_pDoc(nullptr)
, m_pFontList(nullptr)
, m_IsInUpdateFontList(false)
, m_pStyleManager(new svx::CommonStyleManager(*this))
, m_pView(nullptr)
, m_pWrtShell(nullptr)
, m_pOLEChildList(nullptr)
......@@ -358,6 +362,7 @@ SwDocShell::SwDocShell( SwDoc *const pD, SfxObjectCreateMode const eMode )
, m_pDoc(pD)
, m_pFontList(nullptr)
, m_IsInUpdateFontList(false)
, m_pStyleManager(new svx::CommonStyleManager(*this))
, m_pView(nullptr)
, m_pWrtShell(nullptr)
, m_pOLEChildList(nullptr)
......
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