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

preview of styles in "Style And Formatting" dialog

Change-Id: Ic10025f8b27c87ae40f62cb04653cc8e6abc7fc1
üst 28127854
...@@ -62,13 +62,110 @@ ...@@ -62,13 +62,110 @@
#include "appdata.hxx" #include "appdata.hxx"
#include <sfx2/viewfrm.hxx> #include <sfx2/viewfrm.hxx>
#include <svtools/svlbitm.hxx>
#include <svtools/treelistentry.hxx>
#include <comphelper/string.hxx> #include <comphelper/string.hxx>
#include <sfx2/StyleManager.hxx>
#include <sfx2/StylePreviewRenderer.hxx>
using namespace css; using namespace css;
using namespace css::beans; using namespace css::beans;
using namespace css::frame; using namespace css::frame;
using namespace css::uno; using namespace css::uno;
namespace
{
class StyleLBoxString : public SvLBoxString
{
SfxStyleFamily meStyleFamily;
std::unique_ptr<sfx2::StylePreviewRenderer> mpStylePreviewRenderer;
public:
StyleLBoxString(SvTreeListEntry* pEntry,
sal_uInt16 nFlags,
const OUString& sText,
const SfxStyleFamily& eStyleFamily);
virtual ~StyleLBoxString();
virtual void Paint(const Point& aPos,
SvTreeListBox& rDevice,
const SvViewDataEntry* pView,
const SvTreeListEntry* pEntry) SAL_OVERRIDE;
virtual void InitViewData(SvTreeListBox* pView,
SvTreeListEntry* pEntry,
SvViewDataItem* pViewData) SAL_OVERRIDE;
};
StyleLBoxString::StyleLBoxString(SvTreeListEntry* pEntry, sal_uInt16 nFlags, const OUString& sText, const SfxStyleFamily& eStyleFamily)
: SvLBoxString(pEntry, nFlags, sText)
, meStyleFamily(eStyleFamily)
{}
StyleLBoxString::~StyleLBoxString()
{}
void StyleLBoxString::InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData)
{
if (!pViewData)
{
pViewData = pView->GetViewDataItem(pEntry, this);
}
SfxObjectShell* pShell = SfxObjectShell::Current();
if (!pShell)
return;
sfx2::StyleManager* pStyleManager = pShell->GetStyleManager();
if (!pStyleManager)
{
return;
}
mpStylePreviewRenderer.reset(pStyleManager->CreateStylePreviewRenderer(*pView, GetText(), meStyleFamily));
if (!mpStylePreviewRenderer)
{
return;
}
if (mpStylePreviewRenderer->recalculate())
{
pViewData->maSize = mpStylePreviewRenderer->getRenderSize();
}
else
{
SvLBoxString::InitViewData(pView, pEntry, pViewData);
}
}
void StyleLBoxString::Paint(
const Point& aPos, SvTreeListBox& rDevice,
const SvViewDataEntry* pView, const SvTreeListEntry* pEntry)
{
if (!pEntry)
return;
bool bResult = false;
if (mpStylePreviewRenderer)
{
Rectangle aPaintRectangle = pView->GetPaintRectangle();
bResult = mpStylePreviewRenderer->render(aPaintRectangle);
}
if (!bResult)
{
rDevice.DrawText(aPos, GetText());
}
}
} // end anonymous namespace
// Window is now created dynamically. So here margins, etc. // Window is now created dynamically. So here margins, etc.
#define SFX_TEMPLDLG_HFRAME 3 #define SFX_TEMPLDLG_HFRAME 3
...@@ -228,6 +325,12 @@ SfxActionListBox::SfxActionListBox(SfxCommonTemplateDialog_Impl* pParent, WinBit ...@@ -228,6 +325,12 @@ SfxActionListBox::SfxActionListBox(SfxCommonTemplateDialog_Impl* pParent, WinBit
EnableContextMenuHandling(); EnableContextMenuHandling();
} }
void SfxActionListBox::Recalc()
{
SetEntryHeight(32);
RecalcViewData();
}
PopupMenu* SfxActionListBox::CreateContextMenu() PopupMenu* SfxActionListBox::CreateContextMenu()
{ {
...@@ -412,6 +515,12 @@ StyleTreeListBox_Impl::StyleTreeListBox_Impl(SfxCommonTemplateDialog_Impl* pPare ...@@ -412,6 +515,12 @@ StyleTreeListBox_Impl::StyleTreeListBox_Impl(SfxCommonTemplateDialog_Impl* pPare
EnableContextMenuHandling(); EnableContextMenuHandling();
} }
void StyleTreeListBox_Impl::Recalc()
{
SetEntryHeight(32);
RecalcViewData();
}
/** Internal structure for the establishment of the hierarchical view */ /** Internal structure for the establishment of the hierarchical view */
class StyleTree_Impl; class StyleTree_Impl;
typedef std::vector<StyleTree_Impl*> StyleTreeArr_Impl; typedef std::vector<StyleTree_Impl*> StyleTreeArr_Impl;
...@@ -512,15 +621,25 @@ inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries, ...@@ -512,15 +621,25 @@ inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries,
return false; return false;
} }
SvTreeListEntry* FillBox_Impl(SvTreeListBox *pBox, SvTreeListEntry* FillBox_Impl(SvTreeListBox* pBox,
StyleTree_Impl* pEntry, StyleTree_Impl* pEntry,
const ExpandedEntries_t& rEntries, const ExpandedEntries_t& rEntries,
SvTreeListEntry* pParent = 0) SfxStyleFamily eStyleFamily,
SvTreeListEntry* pParent = nullptr)
{ {
SvTreeListEntry* pNewEntry = pBox->InsertEntry(pEntry->getName(), pParent); SvTreeListEntry* pTreeListEntry = pBox->InsertEntry(pEntry->getName(), pParent);
StyleLBoxString* pStyleLBoxString = new StyleLBoxString(pTreeListEntry, 0, pEntry->getName(), eStyleFamily);
pTreeListEntry->ReplaceItem(pStyleLBoxString, 1);
pBox->GetModel()->InvalidateEntry(pTreeListEntry);
for(sal_uInt16 i = 0; i < pEntry->Count(); ++i) for(sal_uInt16 i = 0; i < pEntry->Count(); ++i)
FillBox_Impl(pBox, (*pEntry)[i], rEntries, pNewEntry); {
return pNewEntry; FillBox_Impl(pBox, (*pEntry)[i], rEntries, eStyleFamily, pTreeListEntry);
}
return pTreeListEntry;
} }
// Constructor // Constructor
...@@ -950,8 +1069,12 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox() ...@@ -950,8 +1069,12 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox()
pTreeBox->SetUpdateMode( false ); pTreeBox->SetUpdateMode( false );
pTreeBox->Clear(); pTreeBox->Clear();
const sal_uInt16 nCount = aArr.size(); const sal_uInt16 nCount = aArr.size();
for(sal_uInt16 i = 0; i < nCount; ++i)
FillBox_Impl(pTreeBox, aArr[i], aEntries); for (sal_uInt16 i = 0; i < nCount; ++i)
{
FillBox_Impl(pTreeBox, aArr[i], aEntries, pItem->GetFamily());
}
pTreeBox->Recalc();
EnableItem(SID_STYLE_WATERCAN,false); EnableItem(SID_STYLE_WATERCAN,false);
...@@ -1103,8 +1226,13 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags) ...@@ -1103,8 +1226,13 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags)
aFmtLb.Clear(); aFmtLb.Clear();
for(nPos = 0; nPos < nCount; ++nPos) for(nPos = 0; nPos < nCount; ++nPos)
aFmtLb.InsertEntry(aStrings[nPos], 0, false, nPos); {
SvTreeListEntry* pTreeListEntry = aFmtLb.InsertEntry(aStrings[nPos], 0, false, nPos);
StyleLBoxString* pStyleLBoxString = new StyleLBoxString(pTreeListEntry, 0, aStrings[nPos], eFam);
pTreeListEntry->ReplaceItem(pStyleLBoxString, 1);
aFmtLb.GetModel()->InvalidateEntry(pTreeListEntry);
}
aFmtLb.Recalc();
aFmtLb.SetUpdateMode(true); aFmtLb.SetUpdateMode(true);
} }
// Selects the current style if any // Selects the current style if any
......
...@@ -114,6 +114,8 @@ protected: ...@@ -114,6 +114,8 @@ protected:
public: public:
StyleTreeListBox_Impl( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle = 0); StyleTreeListBox_Impl( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinStyle = 0);
void Recalc();
void SetDoubleClickHdl(const Link &rLink) void SetDoubleClickHdl(const Link &rLink)
{ {
aDoubleClickLink = rLink; aDoubleClickLink = rLink;
...@@ -145,6 +147,7 @@ public: ...@@ -145,6 +147,7 @@ public:
SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits ); SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits );
virtual PopupMenu* CreateContextMenu() SAL_OVERRIDE; virtual PopupMenu* CreateContextMenu() SAL_OVERRIDE;
void Recalc();
}; };
class SfxCommonTemplateDialog_Impl : public SfxListener class SfxCommonTemplateDialog_Impl : public SfxListener
......
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