[Libreoffice-commits] .: 2 commits - sfx2/inc sfx2/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Jan 16 05:22:11 PST 2013


 sfx2/inc/sfx2/templatecontaineritem.hxx       |   13 +
 sfx2/inc/sfx2/thumbnailviewitem.hxx           |    2 
 sfx2/source/control/templateabstractview.cxx  |   16 ++
 sfx2/source/control/templatecontaineritem.cxx |  172 ++++++++++++++------------
 sfx2/source/control/templatelocalview.cxx     |   36 ++---
 sfx2/source/control/templateviewitem.cxx      |   27 ----
 sfx2/source/control/thumbnailviewitem.cxx     |   86 ++++++++++---
 7 files changed, 207 insertions(+), 145 deletions(-)

New commits:
commit 7c7520bad93185eb4a5a3b60241b53c989aeb4c8
Author: Cédric Bosdonnat <cedric.bosdonnat at free.fr>
Date:   Wed Jan 16 13:51:45 2013 +0100

    Template Manager: show names on several lines
    
    Change-Id: I6990bb6ac52889de36f3ec2cce33e4dc2f3da2ea

diff --git a/sfx2/inc/sfx2/thumbnailviewitem.hxx b/sfx2/inc/sfx2/thumbnailviewitem.hxx
index 9609667..18b7eae 100644
--- a/sfx2/inc/sfx2/thumbnailviewitem.hxx
+++ b/sfx2/inc/sfx2/thumbnailviewitem.hxx
@@ -22,6 +22,7 @@
 
 #include <basegfx/vector/b2dvector.hxx>
 #include <drawinglayer/attribute/fontattribute.hxx>
+#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
 #include <osl/mutex.hxx>
 #include <vcl/bitmapex.hxx>
 #include "sfx2/dllapi.h"
@@ -106,6 +107,7 @@ public:
 
     virtual void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
                         const ThumbnailItemAttributes *pAttrs);
+    void addTextPrimitives (const rtl::OUString& rText, const ThumbnailItemAttributes *pAttrs, Point aPos, drawinglayer::primitive2d::Primitive2DSequence& rSeq);
 
     static drawinglayer::primitive2d::PolygonHairlinePrimitive2D*
         createBorderLine (const basegfx::B2DPolygon &rPolygon);
diff --git a/sfx2/source/control/templatecontaineritem.cxx b/sfx2/source/control/templatecontaineritem.cxx
index 25fa5fe..febd87f 100644
--- a/sfx2/source/control/templatecontaineritem.cxx
+++ b/sfx2/source/control/templatecontaineritem.cxx
@@ -84,8 +84,6 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
     Size aThumbSize( ( maThumbnailArea.getWidth() - 3 * nThumbPadding ) / 2, ( maThumbnailArea.getHeight() - 3* nThumbPadding ) / 2 );
 
     // Draw thumbnail
-    Point aPos = maPrev1Pos;
-
     for (int i=0; i<4; ++i)
     {
         long nPosX = 0;
@@ -153,21 +151,7 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
         }
     }
 
-    // Draw centered text below thumbnail
-    aPos = maTextPos;
-
-    // Create the text primitive
-    basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix(
-                pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
-                double( aPos.X() ), double( aPos.Y() ) ) );
-
-    aSeq[nCount++] = Primitive2DReference(
-                new TextSimplePortionPrimitive2D(aTextMatrix,
-                                                 maTitle,0,maTitle.getLength(),
-                                                 std::vector< double >( ),
-                                                 pAttrs->aFontAttr,
-                                                 com::sun::star::lang::Locale(),
-                                                 Color(COL_BLACK).getBColor() ) );
+    addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
 
     pProcessor->process(aSeq);
 }
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index a2e9ff1..2cacc9b 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -51,12 +51,6 @@ void TemplateLocalView::Populate ()
     {
         OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
 
-        if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
-        {
-            aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
-            aRegionName += "...";
-        }
-
         TemplateContainerItem* pItem = new TemplateContainerItem( *this );
         pItem->mnId = i+1;
         pItem->maTitle = aRegionName;
@@ -69,12 +63,6 @@ void TemplateLocalView::Populate ()
             OUString aName = mpDocTemplates->GetName(i,j);
             OUString aURL = mpDocTemplates->GetPath(i,j);
 
-            if ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
-            {
-                aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
-                aName += "...";
-            }
-
             TemplateItemProperties aProperties;;
             aProperties.nId = j+1;
             aProperties.nDocId = j;
@@ -162,12 +150,6 @@ sal_uInt16 TemplateLocalView::createRegion(const OUString &rName)
 
     OUString aRegionName = rName;
 
-    if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
-    {
-        aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
-        aRegionName += "...";
-    }
-
     TemplateContainerItem* pItem = new TemplateContainerItem( *this );
     pItem->mnId = nRegionId+1;
     pItem->maTitle = aRegionName;
diff --git a/sfx2/source/control/templateviewitem.cxx b/sfx2/source/control/templateviewitem.cxx
index 51a2862..9f06ebb 100644
--- a/sfx2/source/control/templateviewitem.cxx
+++ b/sfx2/source/control/templateviewitem.cxx
@@ -108,34 +108,11 @@ void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProces
     // draw thumbnail borders
     aSeq[3] = Primitive2DReference(createBorderLine(aBounds));
 
-    // Draw centered text below thumbnail
-
-    // Create the text primitive
-    basegfx::B2DHomMatrix aTitleMatrix( createScaleTranslateB2DHomMatrix(
-                pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
-                double( maTextPos.X() ), double( maTextPos.Y() ) ) );
-
-    aSeq[4] = Primitive2DReference(
-                new TextSimplePortionPrimitive2D(aTitleMatrix,
-                                                 maTitle,0,pAttrs->nMaxTextLenght,
-                                                 std::vector< double >( ),
-                                                 pAttrs->aFontAttr,
-                                                 com::sun::star::lang::Locale(),
-                                                 Color(COL_BLACK).getBColor() ) );
+    addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
 
     if (!maSubTitle.isEmpty())
     {
-        basegfx::B2DHomMatrix aSubTitleMatrix( createScaleTranslateB2DHomMatrix(
-                    pAttrs->aFontSize.getX()*SUBTITLE_SCALE_FACTOR, pAttrs->aFontSize.getY()*SUBTITLE_SCALE_FACTOR,
-                    double( maSubTitlePos.X() ), double( maSubTitlePos.Y() ) ) );
-
-        aSeq[5] = Primitive2DReference(
-                    new TextSimplePortionPrimitive2D(aSubTitleMatrix,
-                                                     maSubTitle,0,pAttrs->nMaxTextLenght,
-                                                     std::vector< double >( ),
-                                                     pAttrs->aFontAttr,
-                                                     com::sun::star::lang::Locale(),
-                                                     Color(COL_BLACK).getBColor() ) );
+        addTextPrimitives(maSubTitle, pAttrs, maSubTitlePos, aSeq);
     }
 
     pProcessor->process(aSeq);
diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx
index e5a07db..2e6eb96 100644
--- a/sfx2/source/control/thumbnailviewitem.cxx
+++ b/sfx2/source/control/thumbnailviewitem.cxx
@@ -34,6 +34,7 @@
 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
 #include <vcl/button.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/texteng.hxx>
 
 using namespace basegfx;
 using namespace basegfx::tools;
@@ -127,7 +128,8 @@ void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProc
     if ( mbSelected || mbHover )
         aFillColor = pAttrs->aHighlightColor;
 
-    aSeq[0] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
+    sal_uInt32 nPrimitive = 0;
+    aSeq[nPrimitive++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
                                                aFillColor));
 
@@ -135,7 +137,7 @@ void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProc
     Point aPos = maPrev1Pos;
     Size aImageSize = maPreview1.GetSizePixel();
 
-    aSeq[1] = Primitive2DReference( new FillBitmapPrimitive2D(
+    aSeq[nPrimitive++] = Primitive2DReference( new FillBitmapPrimitive2D(
                                         createTranslateB2DHomMatrix(aPos.X(),aPos.Y()),
                                         FillBitmapAttribute(maPreview1,
                                                             B2DPoint(0,0),
@@ -156,27 +158,74 @@ void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProc
     aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
     aBounds.setClosed(true);
 
-    aSeq[2] = Primitive2DReference(createBorderLine(aBounds));
+    aSeq[nPrimitive++] = Primitive2DReference(createBorderLine(aBounds));
 
-    // Draw centered text below thumbnail
+    // Draw text below thumbnail
     aPos = maTextPos;
 
-    // Create the text primitive
-    basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix(
-                pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
-                double( aPos.X() ), double( aPos.Y() ) ) );
-
-    aSeq[3] = Primitive2DReference(
-                new TextSimplePortionPrimitive2D(aTextMatrix,
-                                                 maTitle,0,pAttrs->nMaxTextLenght,
-                                                 std::vector< double >( ),
-                                                 pAttrs->aFontAttr,
-                                                 com::sun::star::lang::Locale(),
-                                                 Color(COL_BLACK).getBColor() ) );
+    addTextPrimitives( maTitle, pAttrs, maTextPos, aSeq );
 
     pProcessor->process(aSeq);
 }
 
+void ThumbnailViewItem::addTextPrimitives (const rtl::OUString& rText, const ThumbnailItemAttributes *pAttrs, Point aPos, Primitive2DSequence& rSeq)
+{
+    drawinglayer::primitive2d::TextLayouterDevice aTextDev;
+
+    rtl::OUString aText (rText);
+
+    TextEngine aTextEngine;
+    aTextEngine.SetMaxTextWidth(maDrawArea.getWidth());
+    aTextEngine.SetText(rText);
+
+    sal_Int32 nPrimitives = rSeq.getLength();
+    rSeq.realloc(nPrimitives + aTextEngine.GetLineCount(0));
+
+    // Create the text primitives
+    sal_uInt16 nLineStart = 0;
+    for (sal_uInt16 i=0; i<aTextEngine.GetLineCount(0); ++i)
+    {
+        sal_uInt16 nLineLength = aTextEngine.GetLineLen(0, i);
+        double nLineWidth = aTextDev.getTextWidth (aText, nLineStart, nLineLength);
+
+        bool bTooLong = (aPos.getY() + aTextEngine.GetCharHeight()) > maDrawArea.Bottom();
+        if (bTooLong && (nLineLength + nLineStart) < rText.getLength())
+        {
+            // Add the '...' to the last line to show, even though it may require to shorten the line
+            double nDotsWidth = aTextDev.getTextWidth(rtl::OUString("..."),0,3);
+
+            sal_uInt16 nLength = nLineLength - 1;
+            while ( nDotsWidth + aTextDev.getTextWidth(aText, nLineStart, nLength) > maDrawArea.getWidth() && nLength > 0)
+            {
+                --nLength;
+            }
+
+            aText = aText.copy(0, nLineStart+nLength);
+            aText += "...";
+            nLineLength = nLength + 3;
+        }
+
+        double nLineX = maDrawArea.Left() + (maDrawArea.getWidth() - nLineWidth) / 2.0;
+
+        basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix(
+                    pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
+                    nLineX, double( aPos.Y() ) ) );
+
+        rSeq[nPrimitives++] = Primitive2DReference(
+                    new TextSimplePortionPrimitive2D(aTextMatrix,
+                                                     aText,nLineStart,nLineLength,
+                                                     std::vector< double >( ),
+                                                     pAttrs->aFontAttr,
+                                                     com::sun::star::lang::Locale(),
+                                                     Color(COL_BLACK).getBColor() ) );
+        nLineStart += nLineLength;
+        aPos.setY(aPos.getY() + aTextEngine.GetCharHeight());
+
+        if (bTooLong)
+            break;
+    }
+}
+
 drawinglayer::primitive2d::PolygonHairlinePrimitive2D*
 ThumbnailViewItem::createBorderLine (const basegfx::B2DPolygon& rPolygon)
 {
commit 34856077702907aed5568ff3d4b98888ced37edf
Author: Cédric Bosdonnat <cedric.bosdonnat at free.fr>
Date:   Mon Jan 14 16:50:03 2013 +0100

    Template Manager: show folders with 4 previews inside a rounded rect
    
    The previous display had the inconvenient to be misleading if there was
    one or no template inside a folder.
    
    Change-Id: I16faa2556ca02380bd4dac0d821ecac45b98b8c3
    Reviewed-on: https://gerrit.libreoffice.org/1678
    Reviewed-by: Noel Power <noel.power at suse.com>
    Tested-by: Noel Power <noel.power at suse.com>

diff --git a/sfx2/inc/sfx2/templatecontaineritem.hxx b/sfx2/inc/sfx2/templatecontaineritem.hxx
index 2c2d18b..4768604 100644
--- a/sfx2/inc/sfx2/templatecontaineritem.hxx
+++ b/sfx2/inc/sfx2/templatecontaineritem.hxx
@@ -18,19 +18,26 @@ class TemplateContainerItem : public ThumbnailViewItem
 public:
 
     BitmapEx maPreview2;
+    BitmapEx maPreview3;
+    BitmapEx maPreview4;
     std::vector<TemplateItemProperties> maTemplates;
 
     TemplateContainerItem (ThumbnailView &rView);
 
     virtual ~TemplateContainerItem ();
 
-    const Point& getPrev2Pos () const { return maPrev2Pos; }
-
     virtual void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
                         const ThumbnailItemAttributes *pAttrs);
+
+    virtual void calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
+                                         const long nPadding, sal_uInt32 nMaxTextLenght,
+                                         const ThumbnailItemAttributes *pAttrs);
+
+    bool HasMissingPreview( );
+
 private:
 
-    Point maPrev2Pos;
+    Rectangle maThumbnailArea;
 };
 
 #endif // TEMPLATEFOLDERVIEWITEM_HXX
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index 27d37a8..0679e63 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -66,8 +66,10 @@ bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
         // Clear thumbnails
         pContainerItem->maPreview1.Clear();
         pContainerItem->maPreview2.Clear();
+        pContainerItem->maPreview3.Clear();
+        pContainerItem->maPreview4.Clear();
 
-        for (size_t i = 0, n = rTemplates.size(); i < n; ++i)
+        for (size_t i = 0, n = rTemplates.size(); i < n && pContainerItem->HasMissingPreview(); ++i)
         {
             if (isValid(rTemplates[i].aPath))
             {
@@ -84,6 +86,18 @@ bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
                                                                        TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
                                                                        TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
                 }
+                else if ( pContainerItem->maPreview3.IsEmpty() )
+                {
+                    pContainerItem->maPreview3 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
+                                                                       TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
+                                                                       TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
+                }
+                else if ( pContainerItem->maPreview4.IsEmpty() )
+                {
+                    pContainerItem->maPreview4 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
+                                                                       TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
+                                                                       TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
+                }
             }
         }
 
diff --git a/sfx2/source/control/templatecontaineritem.cxx b/sfx2/source/control/templatecontaineritem.cxx
index d63ce8a..25fa5fe 100644
--- a/sfx2/source/control/templatecontaineritem.cxx
+++ b/sfx2/source/control/templatecontaineritem.cxx
@@ -8,6 +8,7 @@
  */
 
 #include <sfx2/templatecontaineritem.hxx>
+#include <sfx2/templateabstractview.hxx>
 
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
@@ -35,11 +36,20 @@ TemplateContainerItem::~TemplateContainerItem ()
 {
 }
 
+void TemplateContainerItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
+                                     const long nPadding, sal_uInt32 nMaxTextLenght,
+                                     const ThumbnailItemAttributes *pAttrs)
+{
+    ThumbnailViewItem::calculateItemsPosition( nThumbnailHeight, nDisplayHeight, nPadding, nMaxTextLenght, 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 = 2;
+    int nSeqSize = 3;
 
     if (!maPreview1.IsEmpty())
         nSeqSize += 3;
@@ -47,6 +57,12 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
     if (!maPreview2.IsEmpty())
         nSeqSize += 3;
 
+    if (!maPreview3.IsEmpty())
+        nSeqSize += 3;
+
+    if (!maPreview4.IsEmpty())
+        nSeqSize += 3;
+
     BColor aFillColor = pAttrs->aFillColor;
     Primitive2DSequence aSeq(nSeqSize);
 
@@ -58,70 +74,83 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
                                                aFillColor));
 
-    // Draw thumbnail
-    Point aPos = maPrev1Pos;
-    Size aImageSize = maPreview1.GetSizePixel();
+    // Create rounded rectangle border
+    aSeq[nCount++] = Primitive2DReference( new PolygonStrokePrimitive2D(
+                                              Polygon(maThumbnailArea,5,5).getB2DPolygon(),
+                                              LineAttribute(BColor(0.8, 0.8, 0.8), 2.0)));
 
-    float fScaleX = 1.0f;
-    float fScaleY = 1.0f;
+    // 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 );
 
-    if (!maPreview2.IsEmpty())
-    {
-        fScaleX = 0.8f;
-        fScaleY = 0.8f;
-
-        float fWidth = aImageSize.Width()*fScaleX;
-        float fHeight = aImageSize.Height()*fScaleY;
-        float fPosX = aPos.getX()+35*fScaleX;
-        float fPosY = aPos.getY()+20*fScaleY;
-
-        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++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
-                                            B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
-        aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
-                                            createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
-                                            FillBitmapAttribute(maPreview2,
-                                                                B2DPoint(35,20),
-                                                                B2DVector(aImageSize.Width(),aImageSize.Height()),
-                                                                false)
-                                            ));
-
-        // draw thumbnail borders
-        aSeq[nCount++] = Primitive2DReference(createBorderLine(aBounds));
-    }
+    // Draw thumbnail
+    Point aPos = maPrev1Pos;
 
-    if (!maPreview1.IsEmpty())
+    for (int i=0; i<4; ++i)
     {
-        // draw thumbnail borders
-        float fWidth = aImageSize.Width()*fScaleX;
-        float fHeight = aImageSize.Height()*fScaleY;
-        float fPosX = aPos.getX();
-        float fPosY = aPos.getY();
-
-        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++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
-                                            B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
-        aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
-                                            createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
-                                            FillBitmapAttribute(maPreview1,
-                                                                B2DPoint(0,0),
-                                                                B2DVector(aImageSize.Width(),aImageSize.Height()),
-                                                                false)
-                                            ));
-
-        aSeq[nCount++] = Primitive2DReference(createBorderLine(aBounds));
+        long nPosX = 0;
+        long nPosY = 0;
+        BitmapEx* pImage = NULL;
+
+        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;
+            float nOffY = (aThumbSize.getHeight() - aImageSize.getHeight()) / 2;
+
+            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++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
+                                                B2DPolyPolygon(aBounds), Color(COL_WHITE).getBColor()));
+            aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
+                                                createScaleTranslateB2DHomMatrix(1.0,1.0,fPosX,fPosY),
+                                                FillBitmapAttribute(*pImage,
+                                                                    B2DPoint(0.0,0.0),
+                                                                    B2DVector(aImageSize.Width(),aImageSize.Height()),
+                                                                    false)
+                                                ));
+
+            // draw thumbnail borders
+            aSeq[nCount++] = Primitive2DReference(createBorderLine(aBounds));
+        }
     }
 
     // Draw centered text below thumbnail
@@ -143,6 +172,11 @@ void TemplateContainerItem::Paint (drawinglayer::processor2d::BaseProcessor2D *p
     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 16b1b44..a2e9ff1 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -592,9 +592,11 @@ static void lcl_updateThumbnails (TemplateContainerItem *pItem)
 {
     pItem->maPreview1.Clear();
     pItem->maPreview2.Clear();
+    pItem->maPreview3.Clear();
+    pItem->maPreview4.Clear();
 
     // Update folder thumbnails
-    for (size_t i = 0, n = pItem->maTemplates.size(); i < n && ( pItem->maPreview1.IsEmpty() || pItem->maPreview2.IsEmpty( ) ); ++i)
+    for (size_t i = 0, n = pItem->maTemplates.size(); i < n && pItem->HasMissingPreview(); ++i)
     {
         if ( pItem->maPreview1.IsEmpty( ) )
         {
@@ -602,12 +604,24 @@ static void lcl_updateThumbnails (TemplateContainerItem *pItem)
                                                                TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
                                                                TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
         }
-        else
+        else if ( pItem->maPreview2.IsEmpty() )
         {
             pItem->maPreview2 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
                                                                TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
                                                                TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
         }
+        else if ( pItem->maPreview3.IsEmpty() )
+        {
+            pItem->maPreview3 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
+                                                               TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
+                                                               TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
+        }
+        else if ( pItem->maPreview4.IsEmpty() )
+        {
+            pItem->maPreview4 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
+                                                               TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
+                                                               TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
+        }
     }
 }
 
diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx
index 3f1077e..e5a07db 100644
--- a/sfx2/source/control/thumbnailviewitem.cxx
+++ b/sfx2/source/control/thumbnailviewitem.cxx
@@ -88,7 +88,7 @@ void ThumbnailViewItem::setDrawArea (const Rectangle &area)
     maDrawArea = area;
 }
 
-void ThumbnailViewItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
+void ThumbnailViewItem::calculateItemsPosition (const long nThumbnailHeight, const long,
                                                 const long nPadding, sal_uInt32 nMaxTextLenght,
                                                 const ThumbnailItemAttributes *pAttrs)
 {
@@ -107,8 +107,7 @@ void ThumbnailViewItem::calculateItemsPosition (const long nThumbnailHeight, con
     maPrev1Pos = aPos;
 
     // Calculate text position
-    aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding;
-    aPos.Y() = aPos.Y() + aTextDev.getTextHeight() + (nDisplayHeight - aTextDev.getTextHeight())/2;
+    aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding + aTextDev.getTextHeight();
     aPos.X() = maDrawArea.Left() + (aRectSize.Width() - aTextDev.getTextWidth(maTitle,0,nMaxTextLenght))/2;
     maTextPos = aPos;
 }


More information about the Libreoffice-commits mailing list