summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorAkshay Deep <akshaydeepiitr@gmail.com>2016-05-21 23:16:28 +0530
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2016-05-25 09:24:33 +0000
commit72a1fbe16b147911ff90fb5145ea3e2d783193f8 (patch)
tree3b1b4315398277184da2028a6178809828b928e9 /sfx2
parentd37a18ff0576dcbc1e776bef7dc475928c0dd948 (diff)
New Template Manager: Remove inheritance of TemplateContainerItem
Conflicts: include/sfx2/templatelocalview.hxx sfx2/source/control/templatelocalview.cxx Change-Id: I5eb120853be768c3770a71829c40d00c97fcdadb Reviewed-on: https://gerrit.libreoffice.org/25272 Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/templateabstractview.cxx16
-rw-r--r--sfx2/source/control/templatecontaineritem.cxx155
-rw-r--r--sfx2/source/control/templatelocalview.cxx53
-rw-r--r--sfx2/source/control/templateremoteview.cxx2
-rw-r--r--sfx2/source/doc/templatedlg.cxx2
5 files changed, 26 insertions, 202 deletions
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index 117d04bc1924..8f08f58b899a 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -260,20 +260,10 @@ BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width
void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
{
- //Check if the item is a TemplateContainerItem (Folder) or a TemplateViewItem (File)
+ TemplateViewItem* pViewItem = dynamic_cast<TemplateViewItem*>(pItem);
- TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>(pItem);
- if ( pContainerItem )
- {
- // Fill templates
- mnCurRegionId = pContainerItem->mnRegionId+1;
- maCurRegionName = pContainerItem->maTitle;
- showRegion(pItem);
- }
- else
- {
- maOpenTemplateHdl.Call(pItem);
- }
+ if( pViewItem )
+ maOpenTemplateHdl.Call(pViewItem);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatecontaineritem.cxx b/sfx2/source/control/templatecontaineritem.cxx
index afeac9534121..2d5cbb25a6e1 100644
--- a/sfx2/source/control/templatecontaineritem.cxx
+++ b/sfx2/source/control/templatecontaineritem.cxx
@@ -8,28 +8,10 @@
*/
#include <sfx2/templatecontaineritem.hxx>
-#include <sfx2/templateabstractview.hxx>
-
-#include <basegfx/matrix/b2dhommatrixtools.hxx>
-#include <basegfx/polygon/b2dpolygon.hxx>
-#include <drawinglayer/attribute/fillgraphicattribute.hxx>
-#include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
-#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
-#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
-#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
-#include <drawinglayer/primitive2d/textprimitive2d.hxx>
-#include <drawinglayer/processor2d/baseprocessor2d.hxx>
#include <sfx2/templateviewitem.hxx>
-#include <vcl/button.hxx>
-#include <vcl/graph.hxx>
-
-using namespace basegfx;
-using namespace basegfx::tools;
-using namespace drawinglayer::attribute;
-using namespace drawinglayer::primitive2d;
-TemplateContainerItem::TemplateContainerItem (ThumbnailView &rView, sal_uInt16 nId)
- : ThumbnailViewItem(rView, nId)
+TemplateContainerItem::TemplateContainerItem (sal_uInt16 nId)
+ : mnId(nId)
, mnRegionId(0)
{
}
@@ -38,139 +20,6 @@ TemplateContainerItem::~TemplateContainerItem ()
{
}
-void TemplateContainerItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
- const long nPadding, sal_uInt32 nMaxTextLength,
- const ThumbnailItemAttributes *pAttrs)
-{
- ThumbnailViewItem::calculateItemsPosition( nThumbnailHeight, nDisplayHeight, nPadding, nMaxTextLength, pAttrs);
- Point aPos (maDrawArea.getX() + nPadding, maDrawArea.getY() + nPadding);
- maThumbnailArea = Rectangle(aPos, Size(maDrawArea.GetWidth() - 2 * nPadding, nThumbnailHeight));
-}
-
-void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
- const ThumbnailItemAttributes *pAttrs)
-{
- int nCount = 0;
- int nSeqSize = 3;
-
- if (!maPreview1.IsEmpty())
- nSeqSize += 3;
-
- if (!maPreview2.IsEmpty())
- nSeqSize += 3;
-
- if (!maPreview3.IsEmpty())
- nSeqSize += 3;
-
- if (!maPreview4.IsEmpty())
- nSeqSize += 3;
-
- BColor aFillColor = pAttrs->aFillColor;
- drawinglayer::primitive2d::Primitive2DContainer aSeq(nSeqSize);
- double fTransparence = 0.0;
-
- // Draw background
- if ( mbSelected || mbHover )
- aFillColor = pAttrs->aHighlightColor;
-
- if (mbHover)
- fTransparence = pAttrs->fHighlightTransparence;
-
- aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference(
- new PolyPolygonSelectionPrimitive2D( B2DPolyPolygon( ::tools::Polygon(maDrawArea,5,5).getB2DPolygon()),
- aFillColor,
- fTransparence,
- 0.0,
- true));
-
- // Create rounded rectangle border
- aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference(
- new PolygonStrokePrimitive2D( ::tools::Polygon(maThumbnailArea, 5, 5).getB2DPolygon(),
- LineAttribute(BColor(0.5, 0.5, 0.5), 2.0)));
-
- // Paint the thumbnails side by side on a 2x2 grid
- long nThumbPadding = 4;
- Size aThumbSize( ( maThumbnailArea.getWidth() - 3 * nThumbPadding ) / 2, ( maThumbnailArea.getHeight() - 3* nThumbPadding ) / 2 );
-
- // Draw thumbnail
- for (int i=0; i<4; ++i)
- {
- long nPosX = 0;
- long nPosY = 0;
- BitmapEx* pImage = nullptr;
-
- switch (i)
- {
- case 0:
- pImage = &maPreview1;
- break;
- case 1:
- pImage = &maPreview2;
- nPosX = aThumbSize.getWidth() + nThumbPadding;
- break;
- case 2:
- pImage = &maPreview3;
- nPosY = aThumbSize.getHeight() + nThumbPadding;
- break;
- case 3:
- pImage = &maPreview4;
- nPosX = aThumbSize.getWidth() + nThumbPadding;
- nPosY = aThumbSize.getHeight() + nThumbPadding;
- break;
- }
-
- if (!pImage->IsEmpty())
- {
- // Check the size of the picture and resize if needed
- Size aImageSize = pImage->GetSizePixel();
- if (aImageSize.getWidth() > aThumbSize.getWidth() || aImageSize.getHeight() > aThumbSize.getHeight())
- {
- // Resize the picture and store it for next times
- *pImage = TemplateAbstractView::scaleImg( *pImage, aThumbSize.getWidth(), aThumbSize.getHeight() );
- aImageSize = pImage->GetSizePixel();
- }
-
- float nOffX = (aThumbSize.getWidth() - aImageSize.getWidth()) / 2.0;
- float nOffY = (aThumbSize.getHeight() - aImageSize.getHeight()) / 2.0;
-
- float fWidth = aImageSize.Width();
- float fHeight = aImageSize.Height();
- float fPosX = maThumbnailArea.Left() + nThumbPadding + nPosX + nOffX;
- float fPosY = maThumbnailArea.Top() + nThumbPadding + nPosY + nOffY;
-
- B2DPolygon aBounds;
- aBounds.append(B2DPoint(fPosX,fPosY));
- aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
- aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
- aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
- aBounds.setClosed(true);
-
- aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
- B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
- aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
- createScaleTranslateB2DHomMatrix(1.0,1.0,fPosX,fPosY),
- FillGraphicAttribute(Graphic(*pImage),
- B2DRange(
- B2DPoint(0.0,0.0),
- B2DPoint(aImageSize.Width(),aImageSize.Height())),
- false)
- ));
-
- // draw thumbnail borders
- aSeq[nCount++] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds));
- }
- }
-
- addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
-
- pProcessor->process(aSeq);
-}
-
-bool TemplateContainerItem::HasMissingPreview( )
-{
- return maPreview1.IsEmpty() || maPreview2.IsEmpty() || maPreview3.IsEmpty() || maPreview4.IsEmpty();
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index c0c2b3a68df9..2070a4836396 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -81,7 +81,7 @@ void TemplateLocalView::Populate ()
{
OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
- TemplateContainerItem* pItem = new TemplateContainerItem( *this, i+1 );
+ TemplateContainerItem* pItem = new TemplateContainerItem( i+1 );
pItem->mnRegionId = i;
pItem->maTitle = aRegionName;
@@ -147,12 +147,12 @@ void TemplateLocalView::showAllTemplates()
maOpenRegionHdl.Call(nullptr);
}
-void TemplateLocalView::showRegion(ThumbnailViewItem *pItem)
+void TemplateLocalView::showRegion(TemplateContainerItem *pItem)
{
- mnCurRegionId = static_cast<TemplateContainerItem*>(pItem)->mnRegionId+1;
+ mnCurRegionId = pItem->mnRegionId+1;
maCurRegionName = pItem->maTitle;
- insertItems(reinterpret_cast<TemplateContainerItem*>(pItem)->maTemplates);
+ insertItems((pItem)->maTemplates);
maOpenRegionHdl.Call(nullptr);
}
@@ -169,7 +169,7 @@ void TemplateLocalView::showRegion(const OUString &rName)
}
}
-ThumbnailViewItem* TemplateLocalView::getRegion(OUString const & rName)
+TemplateContainerItem* TemplateLocalView::getRegion(OUString const & rName)
{
for (TemplateContainerItem* pRegion : maRegions)
if (pRegion->maTitle == rName)
@@ -333,21 +333,12 @@ sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
return 0;
// Insert to the region cache list and to the thumbnail item list
- TemplateContainerItem* pItem = new TemplateContainerItem( *this, nItemId );
+ TemplateContainerItem* pItem = new TemplateContainerItem( nItemId );
pItem->mnRegionId = nRegionId;
pItem->maTitle = rName;
maRegions.push_back(pItem);
- pItem = new TemplateContainerItem(*this, nItemId);
- pItem->mnRegionId = nRegionId;
- pItem->maTitle = rName;
-
- AppendItem(pItem);
-
- CalculateItemPositions();
- Invalidate();
-
return pItem->mnId;
}
@@ -383,15 +374,13 @@ bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId)
return false;
// Synchronize view regions ids with SfxDocumentTemplates
- std::vector<ThumbnailViewItem*>::iterator pViewIt = mItemList.begin();
- for ( pViewIt = mItemList.begin(); pViewIt != mItemList.end(); ++pViewIt)
+ std::vector<TemplateContainerItem*>::iterator pRegionIter = maRegions.begin();
+ for ( ; pRegionIter != maRegions.end(); ++pRegionIter)
{
- if (static_cast<TemplateContainerItem*>(*pViewIt)->mnRegionId > nRegionId)
- --static_cast<TemplateContainerItem*>(*pViewIt)->mnRegionId;
+ if ((*pRegionIter)->mnRegionId > nRegionId)
+ --(*pRegionIter)->mnRegionId;
}
- RemoveItem(nItemId);
-
return true;
}
@@ -401,7 +390,7 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt
{
if (pRegion->mnId == nSrcItemId)
{
- TemplateContainerItem *pItem = static_cast<TemplateContainerItem*>(pRegion);
+ TemplateContainerItem *pItem = pRegion;
std::vector<TemplateItemProperties>::iterator pIter;
for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter)
{
@@ -443,9 +432,9 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_
for (TemplateContainerItem* pRegion : maRegions)
{
if (pRegion->mnId == nTargetItem)
- pTarget = static_cast<TemplateContainerItem*>(pRegion);
+ pTarget = pRegion;
else if (pRegion->mnId == nSrcItem)
- pSrc = static_cast<TemplateContainerItem*>(pRegion);
+ pSrc = pRegion;
}
if (pTarget && pSrc)
@@ -526,7 +515,7 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
for (TemplateContainerItem* pRegion : maRegions)
{
if (pRegion->mnId == nTargetItem)
- pTarget = static_cast<TemplateContainerItem*>(pRegion);
+ pTarget = pRegion;
}
if (pTarget)
@@ -546,7 +535,7 @@ bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, s
for (TemplateContainerItem* pRegion : maRegions)
{
if (pRegion->mnRegionId == nSrcRegionId)
- pSrc = static_cast<TemplateContainerItem*>(pRegion);
+ pSrc = pRegion;
}
if(pSrc)
@@ -637,7 +626,7 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
sal_uInt16 nDocId = 0;
TemplateContainerItem *pRegionItem =
- static_cast<TemplateContainerItem*>(pRegion);
+ pRegion;
if (!pRegionItem->maTemplates.empty())
{
@@ -659,8 +648,7 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx
aTemplate.aThumbnail = rThumbnail;
aTemplate.aPath = mpDocTemplates->GetPath(nRegionId,nDocId);
- TemplateContainerItem *pItem =
- static_cast<TemplateContainerItem*>(pRegion);
+ TemplateContainerItem *pItem = pRegion;
pItem->maTemplates.push_back(aTemplate);
@@ -776,16 +764,13 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe
sal_uInt16 nRegionId = 0;
sal_uInt16 nDocId = USHRT_MAX;
TemplateViewItem* pDocItem = dynamic_cast<TemplateViewItem*>( pItem );
- TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>( pItem );
+
if ( pDocItem )
{
nRegionId = pDocItem->mnRegionId;
nDocId = pDocItem->mnDocId;
}
- else if ( pContainerItem )
- {
- nRegionId = pContainerItem->mnRegionId;
- }
+
return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
}
diff --git a/sfx2/source/control/templateremoteview.cxx b/sfx2/source/control/templateremoteview.cxx
index 1e9409a7f37d..c04b4d12d75f 100644
--- a/sfx2/source/control/templateremoteview.cxx
+++ b/sfx2/source/control/templateremoteview.cxx
@@ -60,7 +60,7 @@ VCL_BUILDER_DECL_FACTORY(TemplateRemoteView)
rRet = VclPtr<TemplateRemoteView>::Create(pParent, WB_VSCROLL, false);
}
-void TemplateRemoteView::showRegion(ThumbnailViewItem * /*pItem*/)
+void TemplateRemoteView::showRegion(TemplateContainerItem * /*pItem*/)
{
//TODO:
}
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 13476b832c47..fe9c922fcbcc 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -1034,7 +1034,7 @@ void SfxTemplateManagerDlg::OnTemplateImportCategory(const OUString& sCategory)
if (aFiles.hasElements())
{
//Import to the selected regions
- TemplateContainerItem* pContItem = const_cast<TemplateContainerItem*>(static_cast<const TemplateContainerItem*>(mpLocalView->getRegion(sCategory)));
+ TemplateContainerItem* pContItem = mpLocalView->getRegion(sCategory);
if(pContItem)
{
OUString aTemplateList;