[Libreoffice-commits] .: Branch 'feature/template-dialog' - 11 commits - sfx2/inc sfx2/source

Rafael Dominguez rdominguez at kemper.freedesktop.org
Thu Jun 28 20:46:51 PDT 2012


 sfx2/inc/sfx2/templatefolderview.hxx           |    2 
 sfx2/inc/sfx2/templatefolderviewitem.hxx       |    2 
 sfx2/inc/sfx2/templateview.hxx                 |    5 
 sfx2/inc/sfx2/thumbnailview.hxx                |   20 -
 sfx2/inc/sfx2/thumbnailviewitem.hxx            |    3 
 sfx2/inc/templatedlg.hxx                       |    4 
 sfx2/source/control/templatefolderview.cxx     |   57 +++
 sfx2/source/control/templatefolderviewitem.cxx |    4 
 sfx2/source/control/templateview.cxx           |    7 
 sfx2/source/control/thumbnailview.cxx          |  371 ++++++++-----------------
 sfx2/source/control/thumbnailviewitem.cxx      |    6 
 sfx2/source/doc/templatedlg.cxx                |   88 +++++
 sfx2/source/doc/templatedlg.hrc                |    5 
 sfx2/source/doc/templatedlg.src                |    5 
 14 files changed, 298 insertions(+), 281 deletions(-)

New commits:
commit 8f7d779f94ef277ab4162b4a45d81d1fdd2a1f7c
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 23:14:52 2012 -0430

    Display Move to Folder popup menu when selecting a template.
    
    Change-Id: If4ad6a1809b428b55b26bdb21d64f41cc9b6fbf5

diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx
index 46c3bcf..b406d25 100644
--- a/sfx2/inc/templatedlg.hxx
+++ b/sfx2/inc/templatedlg.hxx
@@ -56,6 +56,7 @@ private:
     DECL_LINK(TVTemplateStateHdl, const ThumbnailViewItem*);
 
     DECL_LINK(MenuSelectHdl, Menu*);
+    DECL_LINK(MoveMenuSelectHdl, Menu*);
 
     DECL_LINK(OpenTemplateHdl, ThumbnailViewItem*);
 
@@ -82,6 +83,7 @@ private:
     TemplateFolderView *maView;
     PopupMenu *mpCreateMenu;
     PopupMenu *mpActionMenu;
+    PopupMenu *mpMoveMenu;
 
     int mnSelectionCount;
     std::set<const ThumbnailViewItem*> maSelTemplates;
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 7668177..4a3eb37 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -91,6 +91,10 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     mpActionMenu->InsertItem(MNI_ACTION_SORT_NAME,SfxResId(STR_ACTION_SORT_NAME).toString());
     mpActionMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,MenuSelectHdl));
 
+    mpMoveMenu = new PopupMenu;
+    mpMoveMenu->InsertItem(MNI_MOVE_NEW,SfxResId(STR_MOVE_NEW).toString());
+    mpMoveMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,MoveMenuSelectHdl));
+
     Size aWinSize = GetOutputSize();
 
     // Calculate thumbnail view minimum size
@@ -123,6 +127,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     // Set toolbox button bits
     mpViewBar->SetItemBits(TBI_TEMPLATE_CREATE, TIB_DROPDOWNONLY);
     mpActionBar->SetItemBits(TBI_TEMPLATE_ACTION, TIB_DROPDOWNONLY);
+    mpTemplateBar->SetItemBits(TBI_TEMPLATE_MOVE,TIB_DROPDOWNONLY);
 
     // Set toolbox handlers
     mpViewBar->SetClickHdl(LINK(this,SfxTemplateManagerDlg,TBXViewHdl));
@@ -130,6 +135,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     mpActionBar->SetClickHdl(LINK(this,SfxTemplateManagerDlg,TBXActionHdl));
     mpActionBar->SetDropdownClickHdl(LINK(this,SfxTemplateManagerDlg,TBXDropdownHdl));
     mpTemplateBar->SetClickHdl(LINK(this,SfxTemplateManagerDlg,TBXTemplateHdl));
+    mpTemplateBar->SetDropdownClickHdl(LINK(this,SfxTemplateManagerDlg,TBXDropdownHdl));
 
     // Set view position below toolbox
     Point aViewPos = maView->GetPosPixel();
@@ -188,6 +194,7 @@ SfxTemplateManagerDlg::~SfxTemplateManagerDlg ()
     delete maView;
     delete mpCreateMenu;
     delete mpActionMenu;
+    delete mpMoveMenu;
 }
 
 IMPL_LINK_NOARG(SfxTemplateManagerDlg,ViewAllHdl)
@@ -309,6 +316,16 @@ IMPL_LINK(SfxTemplateManagerDlg, TBXDropdownHdl, ToolBox*, pBox)
         pBox->EndSelection();
         pBox->Invalidate();
         break;
+    case TBI_TEMPLATE_MOVE:
+        pBox->SetItemDown( nCurItemId, true );
+
+        mpMoveMenu->Execute(pBox,pBox->GetItemRect(TBI_TEMPLATE_MOVE),
+                            POPUPMENU_EXECUTE_DOWN);
+
+        pBox->SetItemDown( nCurItemId, false );
+        pBox->EndSelection();
+        pBox->Invalidate();
+        break;
     default:
         break;
     }
@@ -392,6 +409,20 @@ IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, Menu*, pMenu)
     return 0;
 }
 
+IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu)
+{
+    sal_uInt16 nMenuId = pMenu->GetCurItemId();
+
+    if (nMenuId == MNI_MOVE_NEW)
+    {
+    }
+    else
+    {
+    }
+
+    return 0;
+}
+
 IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem)
 {
     uno::Sequence< PropertyValue > aArgs(1);
diff --git a/sfx2/source/doc/templatedlg.hrc b/sfx2/source/doc/templatedlg.hrc
index 064e85c..5fbbfab 100644
--- a/sfx2/source/doc/templatedlg.hrc
+++ b/sfx2/source/doc/templatedlg.hrc
@@ -43,4 +43,9 @@
 
 #define STR_ACTION_SORT_NAME        264
 
+#define MNI_MOVE_NEW                265
+#define MNI_MOVE_FOLDER_BASE        266
+
+#define STR_MOVE_NEW                267
+
 #define IMG_ONLINE_REPOSITORY       100
diff --git a/sfx2/source/doc/templatedlg.src b/sfx2/source/doc/templatedlg.src
index e98ca37..48bee92 100644
--- a/sfx2/source/doc/templatedlg.src
+++ b/sfx2/source/doc/templatedlg.src
@@ -35,6 +35,11 @@ String STR_ACTION_SORT_NAME
     Text [ en-US ] = "Sort by name";
 };
 
+String STR_MOVE_NEW
+{
+    Text [ en-US ] = "New folder";
+};
+
 ModalDialog DLG_TEMPLATE_MANAGER
 {
     HelpId = CMD_SID_TEMPLATE_MANAGER;
commit 0333ccf342a0e25f0e1836349c469eb2d165bd57
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 22:38:59 2012 -0430

    Dont draw an item thats not visible when it loose focus.
    
    Change-Id: I62eb4f280d288dd00bc8d09b26ff911c4876bb1b

diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 243fe2c..7905e94 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -195,10 +195,13 @@ void ThumbnailView::ImplInitScrollBar()
 
 void ThumbnailView::DrawItem (ThumbnailViewItem *pItem)
 {
-    Rectangle aRect = pItem->getDrawArea();
+    if (pItem->isVisible())
+    {
+        Rectangle aRect = pItem->getDrawArea();
 
-    if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) )
-        pItem->Paint(mpProcessor,mpItemAttrs);
+        if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) )
+            pItem->Paint(mpProcessor,mpItemAttrs);
+    }
 }
 
 void ThumbnailView::OnSelectionMode (bool bMode)
commit f0bbbb4b7acb8174dd1f954906a823552b95eff1
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 22:36:16 2012 -0430

    Display correct items when scrolling.
    
    Change-Id: I7c3fd82c81711ae48dd8a7000cda83a133586e3c

diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx
index 22e58db..f0f0ed9 100644
--- a/sfx2/source/control/templateview.cxx
+++ b/sfx2/source/control/templateview.cxx
@@ -29,7 +29,7 @@ using namespace drawinglayer::attribute;
 using namespace drawinglayer::primitive2d;
 
 TemplateView::TemplateView (Window *pParent, SfxDocumentTemplates *pTemplates)
-    : ThumbnailView(pParent),
+    : ThumbnailView(pParent,WB_VSCROLL),
       maCloseImg(SfxResId(IMG_TEMPLATE_VIEW_CLOSE)),
       mnRegionId(0),
       mpDocTemplates(pTemplates)
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 517fb83..243fe2c 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -296,6 +296,8 @@ void ThumbnailView::CalculateItemPositions ()
     long y = nStartY;
 
     // draw items
+    size_t nFirstItem = mnFirstLine * mnCols;
+    size_t nLastItem = nFirstItem + (mnVisLines * mnCols);
     size_t nTotalItems = mnFirstLine*mnCols + mnVisLines*mnCols;
 
     maItemListRect.Left() = x;
@@ -314,7 +316,7 @@ void ThumbnailView::CalculateItemPositions ()
     {
         ThumbnailViewItem *const pItem = mItemList[i];
 
-        if (maFilterFunc(pItem) && nCurCount < nTotalItems)
+        if ((i >= nFirstItem) && (i < nLastItem) && maFilterFunc(pItem) && nCurCount < nTotalItems)
         {
             if( !pItem->isVisible() && ImplHasAccessibleListeners() )
             {
@@ -498,57 +500,7 @@ IMPL_LINK( ThumbnailView,ImplScrollHdl, ScrollBar*, pScrollBar )
     {
         mnFirstLine = nNewFirstLine;
 
-        // Recalculate item positions
-        Size aWinSize = GetOutputSizePixel();
-        size_t nItemCount = mItemList.size();
-
-        // calculate offsets
-        long nStartX = 0;
-        long nStartY = 0;
-
-        // calculate items
-        long x = nStartX;
-        long y = nStartY;
-
-        // draw items
-        sal_uLong nFirstItem = mnFirstLine * mnCols;
-        sal_uLong nLastItem = nFirstItem + (mnVisLines * mnCols);
-
-        // If want also draw parts of items in the last line,
-        // then we add one more line if parts of these line are
-        // visible
-        if ( y+(mnVisLines*(mnItemHeight+mnSpacing)) < aWinSize.Height() )
-            nLastItem += mnCols;
-
-        for ( size_t i = 0; i < nItemCount; i++ )
-        {
-            ThumbnailViewItem *const pItem = mItemList[i];
-
-            if ( (i >= nFirstItem) && (i < nLastItem) )
-            {
-                if (!mItemList[i]->isVisible())
-                    maItemStateHdl.Call(mItemList[i]);
-
-                pItem->show(true);
-                pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ));
-                pItem->calculateItemsPosition(mpItemAttrs->nMaxTextLenght);
-
-                if ( !((i+1) % mnCols) )
-                {
-                    x = nStartX;
-                    y += mnItemHeight+mnSpacing;
-                }
-                else
-                    x += mnItemWidth+mnSpacing;
-            }
-            else
-            {
-                if (mItemList[i]->isVisible())
-                    maItemStateHdl.Call(mItemList[i]);
-
-                pItem->show(false);
-            }
-        }
+        CalculateItemPositions();
 
         if ( IsReallyVisible() && IsUpdateMode() )
             Invalidate();
commit c6aab78b31d55ce1554b74acd346f1a4bfd4f348
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 22:21:26 2012 -0430

    Open a template when double clicking in its thumbnail.
    
    Change-Id: I08884e5f113353261aebcd92b6ecf02146b377c1

diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx
index 00d88da..87cfb14 100644
--- a/sfx2/inc/sfx2/templatefolderview.hxx
+++ b/sfx2/inc/sfx2/templatefolderview.hxx
@@ -41,6 +41,8 @@ public:
 
     void showOverlay (bool bVisible);
 
+    void setOverlayDblClickHdl (const Link &rLink);
+
     void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
 
     void sortOverlayItems (const boost::function<bool (const ThumbnailViewItem*,
diff --git a/sfx2/inc/sfx2/templateview.hxx b/sfx2/inc/sfx2/templateview.hxx
index b3c6b6a..45f755a 100644
--- a/sfx2/inc/sfx2/templateview.hxx
+++ b/sfx2/inc/sfx2/templateview.hxx
@@ -34,16 +34,21 @@ public:
 
     void InsertItems (const std::vector<TemplateViewItem*> &rTemplates);
 
+    void setDblClickHdl (const Link &rLink) { maDblClickHdl = rLink; }
+
 protected:
 
     virtual void MouseButtonDown (const MouseEvent &rMEvt);
 
+    virtual void OnItemDblClicked (ThumbnailViewItem *pItem);
+
 private:
 
     Image maCloseImg;
     sal_uInt16 mnRegionId;
     rtl::OUString maFolderName;
     SfxDocumentTemplates *mpDocTemplates;
+    Link maDblClickHdl;
 };
 
 #endif // TEMPLATEVIEW_HXX
diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx
index 84b3315..46c3bcf 100644
--- a/sfx2/inc/templatedlg.hxx
+++ b/sfx2/inc/templatedlg.hxx
@@ -57,6 +57,8 @@ private:
 
     DECL_LINK(MenuSelectHdl, Menu*);
 
+    DECL_LINK(OpenTemplateHdl, ThumbnailViewItem*);
+
     void OnTemplateImport ();
     void OnTemplateSearch ();
     void OnTemplateEdit ();
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index f874b72..68f622b 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -361,6 +361,11 @@ void TemplateFolderView::showOverlay (bool bVisible)
     }
 }
 
+void TemplateFolderView::setOverlayDblClickHdl(const Link &rLink)
+{
+    mpItemView->setDblClickHdl(rLink);
+}
+
 void TemplateFolderView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
 {
     meFilterOption = eApp;
diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx
index 961029e..22e58db 100644
--- a/sfx2/source/control/templateview.cxx
+++ b/sfx2/source/control/templateview.cxx
@@ -152,6 +152,11 @@ void TemplateView::MouseButtonDown (const MouseEvent &rMEvt)
     ThumbnailView::MouseButtonDown(rMEvt);
 }
 
+void TemplateView::OnItemDblClicked(ThumbnailViewItem *pItem)
+{
+    maDblClickHdl.Call(pItem);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 
 
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index e39f5ab..7668177 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -158,6 +158,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
 
     maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVFolderStateHdl));
     maView->setTemplateStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));
+    maView->setOverlayDblClickHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl));
 
     aButtonAll.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewAllHdl));
     aButtonDocs.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewDocsHdl));
@@ -391,6 +392,25 @@ IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, Menu*, pMenu)
     return 0;
 }
 
+IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem)
+{
+    uno::Sequence< PropertyValue > aArgs(1);
+    aArgs[0].Name = "AsTemplate";
+    aArgs[0].Value <<= sal_True;
+
+    TemplateViewItem *pTemplateItem = static_cast<TemplateViewItem*>(pItem);
+
+    try
+    {
+        mxDesktop->loadComponentFromURL(pTemplateItem->getPath(),rtl::OUString("_blank"), 0, aArgs );
+    }
+    catch( const uno::Exception& )
+    {
+    }
+
+    return 0;
+}
+
 void SfxTemplateManagerDlg::OnTemplateImport ()
 {
     sal_Int16 nDialogType =
commit bfb8b048290fee3b26b08db09271bf2f34316679
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 21:59:48 2012 -0430

    Wrap thumbnail item name text inside its assigned area.
    
    Change-Id: I4b3d57c7d2fa1a8cffb35345ea46390f6eff3cb1

diff --git a/sfx2/inc/sfx2/templatefolderviewitem.hxx b/sfx2/inc/sfx2/templatefolderviewitem.hxx
index b504a9d..16fb646 100644
--- a/sfx2/inc/sfx2/templatefolderviewitem.hxx
+++ b/sfx2/inc/sfx2/templatefolderviewitem.hxx
@@ -23,7 +23,7 @@ struct TemplateFolderViewItem : public ThumbnailViewItem
 
     virtual ~TemplateFolderViewItem ();
 
-    virtual void calculateItemsPosition ();
+    virtual void calculateItemsPosition (sal_uInt32 nMaxTextLenght);
 
     const Point& getPrev2Pos () const { return maPrev2Pos; }
 
diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx
index bbdeeb1..9c40f70 100644
--- a/sfx2/inc/sfx2/thumbnailview.hxx
+++ b/sfx2/inc/sfx2/thumbnailview.hxx
@@ -207,6 +207,8 @@ public:
 
     long GetItemHeight() const { return mnItemHeight; }
 
+    void setItemMaxTextLength (sal_uInt32 nLength);
+
     void setItemDimensions (long ItemWidth, long ThumbnailHeight,
                             long DisplayHeight, int itemPadding);
 
diff --git a/sfx2/inc/sfx2/thumbnailviewitem.hxx b/sfx2/inc/sfx2/thumbnailviewitem.hxx
index 0d9fbd4..e771db3 100644
--- a/sfx2/inc/sfx2/thumbnailviewitem.hxx
+++ b/sfx2/inc/sfx2/thumbnailviewitem.hxx
@@ -51,6 +51,7 @@ namespace drawinglayer {
 
 struct ThumbnailItemAttributes
 {
+    sal_uInt32 nMaxTextLenght;
     basegfx::BColor aFillColor;
     basegfx::BColor aHighlightColor;
     basegfx::B2DVector aFontSize;
@@ -91,7 +92,7 @@ struct ThumbnailViewItem
 
     const Rectangle& getDrawArea () const { return maDrawArea; }
 
-    virtual void calculateItemsPosition ();
+    virtual void calculateItemsPosition (sal_uInt32 nMaxTextLenght);
 
     const Point& getTextPos () const { return maTextPos; }
 
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index fb1e5d6..f874b72 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -277,6 +277,12 @@ void TemplateFolderView::Populate ()
     {
         rtl::OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
 
+        if (aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
+        {
+            aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+            aRegionName += "...";
+        }
+
         sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
 
         if (nEntries)
@@ -298,12 +304,19 @@ void TemplateFolderView::Populate ()
 
             for (sal_uInt16 j = 0; j < nEntries; ++j)
             {
+                rtl::OUString aName = mpDocTemplates->GetName(i,j);
                 rtl::OUString aURL = mpDocTemplates->GetPath(i,j);
                 rtl::OUString aType = SvFileInformationManager::GetDescription(INetURLObject(aURL));
 
+                if (aName.getLength() > mpItemAttrs->nMaxTextLenght)
+                {
+                    aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+                    aName += "...";
+                }
+
                 TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView);
                 pTemplateItem->mnId = j+1;
-                pTemplateItem->maText = mpDocTemplates->GetName(i,j);
+                pTemplateItem->maText = aName;
                 pTemplateItem->setPath(aURL);
                 pTemplateItem->setFileType(aType);
                 pTemplateItem->maPreview1 = lcl_fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
diff --git a/sfx2/source/control/templatefolderviewitem.cxx b/sfx2/source/control/templatefolderviewitem.cxx
index dd0d393..7c5459b 100644
--- a/sfx2/source/control/templatefolderviewitem.cxx
+++ b/sfx2/source/control/templatefolderviewitem.cxx
@@ -36,9 +36,9 @@ TemplateFolderViewItem::~TemplateFolderViewItem ()
         delete maTemplates[i];
 }
 
-void TemplateFolderViewItem::calculateItemsPosition ()
+void TemplateFolderViewItem::calculateItemsPosition (sal_uInt32 nMaxTextLenght)
 {
-    ThumbnailViewItem::calculateItemsPosition();
+    ThumbnailViewItem::calculateItemsPosition(nMaxTextLenght);
 }
 
 void TemplateFolderViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index a2a7626..517fb83 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -172,6 +172,7 @@ void ThumbnailView::ImplInitSettings( bool bFont, bool bForeground, bool bBackgr
     mpItemAttrs->aFillColor = maColor.getBColor();
     mpItemAttrs->aHighlightColor = rStyleSettings.GetHighlightColor().getBColor();
     mpItemAttrs->aFontAttr = getFontAttributeFromVclFont(mpItemAttrs->aFontSize,GetFont(),false,true);
+    mpItemAttrs->nMaxTextLenght = -1;
 }
 
 void ThumbnailView::ImplInitScrollBar()
@@ -328,7 +329,7 @@ void ThumbnailView::CalculateItemPositions ()
 
             pItem->show(true);
             pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ));
-            pItem->calculateItemsPosition();
+            pItem->calculateItemsPosition(mpItemAttrs->nMaxTextLenght);
 
             if ( !((nCurCount+1) % mnCols) )
             {
@@ -530,7 +531,7 @@ IMPL_LINK( ThumbnailView,ImplScrollHdl, ScrollBar*, pScrollBar )
 
                 pItem->show(true);
                 pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ));
-                pItem->calculateItemsPosition();
+                pItem->calculateItemsPosition(mpItemAttrs->nMaxTextLenght);
 
                 if ( !((i+1) % mnCols) )
                 {
@@ -1085,6 +1086,11 @@ void ThumbnailView::SetLineCount( sal_uInt16 nNewLines )
     }
 }
 
+void ThumbnailView::setItemMaxTextLength(sal_uInt32 nLength)
+{
+    mpItemAttrs->nMaxTextLenght = nLength;
+}
+
 void ThumbnailView::setItemDimensions(long itemWidth, long thumbnailHeight, long displayHeight, int itemPadding)
 {
     mnItemWidth = itemWidth + 2*itemPadding;
diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx
index a23fcb2..dbbbcb7 100644
--- a/sfx2/source/control/thumbnailviewitem.cxx
+++ b/sfx2/source/control/thumbnailviewitem.cxx
@@ -116,7 +116,7 @@ void ThumbnailViewItem::setDrawArea (const Rectangle &area)
     maDrawArea = area;
 }
 
-void ThumbnailViewItem::calculateItemsPosition ()
+void ThumbnailViewItem::calculateItemsPosition (sal_uInt32 nMaxTextLenght)
 {
     drawinglayer::primitive2d::TextLayouterDevice aTextDev;
 
@@ -132,7 +132,7 @@ void ThumbnailViewItem::calculateItemsPosition ()
     // Calculate text position
     aPos.Y() += aImageSize.Height();
     aPos.Y() = aPos.Y() + aTextDev.getTextHeight() + (maDrawArea.Bottom() - aPos.Y() - aTextDev.getTextHeight())/2;
-    aPos.X() = maDrawArea.Left() + (aRectSize.Width() - aTextDev.getTextWidth(maText,0,maText.getLength()))/2;
+    aPos.X() = maDrawArea.Left() + (aRectSize.Width() - aTextDev.getTextWidth(maText,0,nMaxTextLenght))/2;
     maTextPos = aPos;
 
     // Calculate checkbox position
@@ -199,7 +199,7 @@ void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProc
 
     aSeq[2] = Primitive2DReference(
                 new TextSimplePortionPrimitive2D(aTextMatrix,
-                                                 maText,0,maText.getLength(),
+                                                 maText,0,pAttrs->nMaxTextLenght,
                                                  std::vector< double >( ),
                                                  pAttrs->aFontAttr,
                                                  com::sun::star::lang::Locale(),
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 89e638c..e39f5ab 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -35,6 +35,7 @@
 #define ITEM_MAX_HEIGHT 192
 #define ITEM_PADDING 5
 #define ITEM_SPACE 20
+#define ITEM_MAX_TEXT_LENGTH 20
 #define THUMBNAIL_MAX_HEIGHT 128
 
 #define INIT_FOLDER_COLS 3
@@ -149,6 +150,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     maView->SetStyle(WB_TABSTOP | WB_VSCROLL);
     maView->SetColor(GetBackground().GetColor());
     maView->SetSizePixel(aThumbSize);
+    maView->setItemMaxTextLength(ITEM_MAX_TEXT_LENGTH);
 
     maView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
                               ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
commit 05156817f7792621603356f7953101bfe5cbed6f
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 20:03:02 2012 -0430

    Set initial folder background color outside of its class.
    
    Change-Id: I6db8700ce9d4c155137645dc967e2124e59d7bb5

diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 9693b07..a2a7626 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -61,8 +61,7 @@ ThumbnailView::ThumbnailView (Window *pParent, WinBits nWinStyle, bool bDisableT
 }
 
 ThumbnailView::ThumbnailView (Window *pParent, const ResId &rResId, bool bDisableTransientChildren)
-    : Control( pParent, rResId ),
-    maColor( pParent->GetBackground().GetColor() )
+    : Control( pParent, rResId )
 {
     ImplInit();
     mbIsTransientChildrenDisabled = bDisableTransientChildren;
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 5f074b1..89e638c 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -147,6 +147,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     mpSearchEdit->SetPosPixel(Point(PADDING_DLG_BORDER,aActionPos.Y()+aActionSize.getHeight()));
 
     maView->SetStyle(WB_TABSTOP | WB_VSCROLL);
+    maView->SetColor(GetBackground().GetColor());
     maView->SetSizePixel(aThumbSize);
 
     maView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
commit 2c73b51bcaf7ff5513eaf8b31c67506925d7d6e2
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 19:58:00 2012 -0430

    Set folder overlay dimensions.
    
    Change-Id: Ic8c1d5508e7517e059649525a508b2f6702b9bb0

diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index c5a2287..fb1e5d6 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -29,9 +29,13 @@
 #define ITEM_MAX_WIDTH 192
 #define ITEM_MAX_HEIGHT 192
 #define ITEM_PADDING 5
+#define ITEM_SPACE 20
 #define THUMBNAIL_MAX_HEIGHT 128 - 2*ITEM_PADDING
 #define THUMBNAIL_MAX_WIDTH ITEM_MAX_WIDTH - 2*ITEM_PADDING
 
+#define INIT_VIEW_COLS 3
+#define INIT_VIEW_LINES 1
+
 BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, long width, long height)
 {
     using namespace ::com::sun::star;
@@ -247,9 +251,12 @@ TemplateFolderView::TemplateFolderView ( Window* pParent, const ResId& rResId, b
       mpDocTemplates(new SfxDocumentTemplates),
       mpItemView(new TemplateView(this,mpDocTemplates))
 {
+    Size aViewSize = mpItemView->CalcWindowSizePixel(INIT_VIEW_COLS,INIT_VIEW_LINES,
+                                                     ITEM_MAX_WIDTH,ITEM_MAX_HEIGHT,ITEM_SPACE);
+
     mpItemView->SetColor(Color(COL_WHITE));
     mpItemView->SetPosPixel(Point(0,0));
-    mpItemView->SetSizePixel(GetOutputSizePixel());
+    mpItemView->SetSizePixel(aViewSize);
     mpItemView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
                                   ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
                                   ITEM_PADDING);
commit 75b139c66913db75ff4b355ddafee1165ff07df8
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 19:00:29 2012 -0430

    Improve folder view initial layout.
    
    Change-Id: I45620b8ffb700e530fcca3b2c92e033c782d1e50

diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index fdd86df..5f074b1 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -34,8 +34,12 @@
 #define ITEM_MAX_WIDTH 192
 #define ITEM_MAX_HEIGHT 192
 #define ITEM_PADDING 5
+#define ITEM_SPACE 20
 #define THUMBNAIL_MAX_HEIGHT 128
 
+#define INIT_FOLDER_COLS 3
+#define INIT_FOLDER_LINES 2
+
 #define PADDING_TOOLBAR_VIEW    15
 #define PADDING_DLG_BORDER      10
 
@@ -86,8 +90,16 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     mpActionMenu->InsertItem(MNI_ACTION_SORT_NAME,SfxResId(STR_ACTION_SORT_NAME).toString());
     mpActionMenu->SetSelectHdl(LINK(this,SfxTemplateManagerDlg,MenuSelectHdl));
 
-    // Calculate toolboxs size and positions
     Size aWinSize = GetOutputSize();
+
+    // Calculate thumbnail view minimum size
+    Size aThumbSize = maView->CalcWindowSizePixel(INIT_FOLDER_COLS,INIT_FOLDER_LINES,
+                                                  ITEM_MAX_WIDTH,ITEM_MAX_HEIGHT,ITEM_SPACE);
+
+    if (aWinSize.getWidth() < aThumbSize.getWidth() + 2*PADDING_DLG_BORDER)
+        aWinSize.setWidth(aThumbSize.getWidth() + 2*PADDING_DLG_BORDER);
+
+    // Calculate toolboxs size and positions
     Size aViewSize = mpViewBar->CalcMinimumWindowSizePixel();
     Size aActionSize = mpActionBar->CalcMinimumWindowSizePixel();
     Size aTemplateSize = mpTemplateBar->CalcMinimumWindowSizePixel();
@@ -121,8 +133,12 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     // Set view position below toolbox
     Point aViewPos = maView->GetPosPixel();
     aViewPos.setY(aActionPos.Y() + aActionSize.getHeight() + PADDING_TOOLBAR_VIEW);
+    aViewPos.setX((aWinSize.getWidth() - aThumbSize.getWidth())/2);     // Center the view
     maView->SetPosPixel(aViewPos);
 
+    if (aWinSize.getHeight() < aViewPos.getY() + aThumbSize.getHeight() + PADDING_DLG_BORDER)
+        aWinSize.setHeight(aViewPos.getY() + aThumbSize.getHeight() + PADDING_DLG_BORDER);
+
     // Set search box position and size
     Size aSearchSize = mpSearchEdit->CalcMinimumSize();
     aSearchSize.setWidth(aWinSize.getWidth() - 2*PADDING_DLG_BORDER);
@@ -131,6 +147,8 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     mpSearchEdit->SetPosPixel(Point(PADDING_DLG_BORDER,aActionPos.Y()+aActionSize.getHeight()));
 
     maView->SetStyle(WB_TABSTOP | WB_VSCROLL);
+    maView->SetSizePixel(aThumbSize);
+
     maView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
                               ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
                               ITEM_PADDING);
@@ -145,6 +163,9 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     aButtonDraws.SetClickHdl(LINK(this,SfxTemplateManagerDlg,ViewDrawsHdl));
     maButtonSelMode.SetClickHdl(LINK(this,SfxTemplateManagerDlg,OnClickSelectionMode));
 
+    // Set dialog to correct dimensions
+    SetSizePixel(aWinSize);
+
     mpViewBar->Show();
     mpActionBar->Show();
 
commit 3c4b2bcca318e25b393fc48e5520fb7b67a96cb9
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 18:43:57 2012 -0430

    Correct calculation of minimum windows size for ThumbnailView.
    
    Change-Id: Ic286603c5558859f833358518d8d2828831bb0cc

diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx
index f2ba241..bbdeeb1 100644
--- a/sfx2/inc/sfx2/thumbnailview.hxx
+++ b/sfx2/inc/sfx2/thumbnailview.hxx
@@ -229,9 +229,9 @@ public:
 
     bool IsColor() const { return maColor.GetTransparency() == 0; }
 
-    Size            CalcWindowSizePixel( const Size& rItemSize,
-                                         sal_uInt16 nCalcCols = 0,
-                                         sal_uInt16 nCalcLines = 0 );
+    Size CalcWindowSizePixel(sal_uInt16 nCalcCols, sal_uInt16 nCalcLines,
+                             sal_uInt16 nItemWidth, sal_uInt16 nItemHeight,
+                             sal_uInt16 nItemSpace);
 
     long            GetScrollWidth() const;
 
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 6156870..9693b07 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -1255,42 +1255,16 @@ bool ThumbnailView::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
     return true;
 }
 
-Size ThumbnailView::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesireCols,
-                                    sal_uInt16 nDesireLines )
+Size ThumbnailView::CalcWindowSizePixel (sal_uInt16 nCols, sal_uInt16 nLines,
+                                         sal_uInt16 nItemWidth, sal_uInt16 nItemHeight,
+                                         sal_uInt16 nItemSpace)
 {
-    size_t nCalcCols = nDesireCols;
-    size_t nCalcLines = nDesireLines;
+    Size aSize(nItemWidth*nCols, nItemHeight*nLines);
 
-    if ( !nCalcCols )
-    {
-        if ( mnUserCols )
-            nCalcCols = mnUserCols;
-        else
-            nCalcCols = 1;
-    }
+    aSize.Width()  += nItemSpace*(nCols+1);
+    aSize.Height() += nItemSpace*(nLines+1);
 
-    if ( !nCalcLines )
-    {
-        nCalcLines = mnVisLines;
-
-        if ( mnUserVisLines )
-            nCalcLines = mnUserVisLines;
-        else
-        {
-            // Floor( (M+N-1)/N )==Ceiling( M/N )
-            nCalcLines = (mItemList.size()+nCalcCols-1) / nCalcCols;
-            if ( !nCalcLines )
-                nCalcLines = 1;
-        }
-    }
-
-    Size        aSize( rItemSize.Width()*nCalcCols, rItemSize.Height()*nCalcLines );
-
-    if ( mnSpacing )
-    {
-        aSize.Width()  += mnSpacing*(nCalcCols-1);
-        aSize.Height() += mnSpacing*(nCalcLines-1);
-    }
+    aSize.Height() += mnHeaderHeight;
 
     // sum possible ScrollBar width
     aSize.Width() += GetScrollWidth();
commit 0c5bc40c1a32cbc2f2b23cfd6c9ff7b1ade9ef53
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 17:53:38 2012 -0430

    Scale image if dont fits the thumbnail preview area.
    
    Change-Id: I8b13d9c65c1e3845ff7ef70ede3debb89e709840

diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 8dc9288..c5a2287 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -29,9 +29,10 @@
 #define ITEM_MAX_WIDTH 192
 #define ITEM_MAX_HEIGHT 192
 #define ITEM_PADDING 5
-#define THUMBNAIL_MAX_HEIGHT 128
+#define THUMBNAIL_MAX_HEIGHT 128 - 2*ITEM_PADDING
+#define THUMBNAIL_MAX_WIDTH ITEM_MAX_WIDTH - 2*ITEM_PADDING
 
-BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height)
+BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, long width, long height)
 {
     using namespace ::com::sun::star;
     using namespace ::com::sun::star::uno;
@@ -137,7 +138,10 @@ BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height)
         aThumbnail = aReader.Read ();
     }
 
-    aThumbnail.Scale(Size(width,height));
+    int sWidth = std::min(aThumbnail.GetSizePixel().getWidth(),width);
+    int sHeight = std::min(aThumbnail.GetSizePixel().getHeight(),height);
+
+    aThumbnail.Scale(Size(sWidth,sHeight),BMP_SCALE_INTERPOLATE);
 
     // Note that the preview is returned without scaling it to the desired
     // width.  This gives the caller the chance to take advantage of a
@@ -276,10 +280,14 @@ void TemplateFolderView::Populate ()
             pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected));
 
             /// Preview first 2 thumbnails for folder
-            pItem->maPreview1 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,0),128,128);
+            pItem->maPreview1 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,0),
+                                                   THUMBNAIL_MAX_WIDTH*0.75,
+                                                   THUMBNAIL_MAX_HEIGHT*0.75);
 
             if ( nEntries > 2 )
-                pItem->maPreview2 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,1),128,128);
+                pItem->maPreview2 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,1),
+                                                       THUMBNAIL_MAX_WIDTH*0.75,
+                                                       THUMBNAIL_MAX_HEIGHT*0.75);
 
             for (sal_uInt16 j = 0; j < nEntries; ++j)
             {
@@ -291,7 +299,7 @@ void TemplateFolderView::Populate ()
                 pTemplateItem->maText = mpDocTemplates->GetName(i,j);
                 pTemplateItem->setPath(aURL);
                 pTemplateItem->setFileType(aType);
-                pTemplateItem->maPreview1 = lcl_fetchThumbnail(aURL,128,128);
+                pTemplateItem->maPreview1 = lcl_fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
 
                 pItem->maTemplates.push_back(pTemplateItem);
             }
commit 5f0a0e82d9bffde6cbee6538d6eff435f4676386
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jun 28 16:34:06 2012 -0430

    Improve thumbnail item positioning and dimensions.
    
    Change-Id: I9b76cabcf94e1cc740cd2d23be1236e14e5ca36f

diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx
index f12a1fb..f2ba241 100644
--- a/sfx2/inc/sfx2/thumbnailview.hxx
+++ b/sfx2/inc/sfx2/thumbnailview.hxx
@@ -203,13 +203,12 @@ public:
 
     sal_uInt16 GetLineCount() const { return mnUserVisLines; }
 
-    void SetItemWidth( long nItemWidth = 0 );
+    long GetItemWidth() const { return mnItemWidth; }
 
-    long GetItemWidth() const { return mnUserItemWidth; }
+    long GetItemHeight() const { return mnItemHeight; }
 
-    void SetItemHeight( long nLineHeight = 0 );
-
-    long GetItemHeight() const { return mnUserItemHeight; }
+    void setItemDimensions (long ItemWidth, long ThumbnailHeight,
+                            long DisplayHeight, int itemPadding);
 
     sal_uInt16 GetFirstLine() const { return mnFirstLine; }
 
@@ -292,6 +291,8 @@ protected:
     using Control::ImplInitSettings;
     using Window::ImplInit;
 
+    void calculateColumnsRows ();
+
     void CalculateItemPositions ();
 
     SVT_DLLPRIVATE void         ImplInit();
@@ -325,6 +326,9 @@ protected:
     long mnHeaderHeight;
     long mnItemWidth;
     long mnItemHeight;
+    long mnItemPadding;
+    long mnThumbnailHeight;     // Maximum height of the thumbnail
+    long mnDisplayHeight;       // Height of the data display box (name, etc)
     long mnVisLines;
     long mnLines;
     long mnUserItemWidth;
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index cb8b69c..8dc9288 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -26,6 +26,11 @@
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 
+#define ITEM_MAX_WIDTH 192
+#define ITEM_MAX_HEIGHT 192
+#define ITEM_PADDING 5
+#define THUMBNAIL_MAX_HEIGHT 128
+
 BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height)
 {
     using namespace ::com::sun::star;
@@ -241,8 +246,9 @@ TemplateFolderView::TemplateFolderView ( Window* pParent, const ResId& rResId, b
     mpItemView->SetColor(Color(COL_WHITE));
     mpItemView->SetPosPixel(Point(0,0));
     mpItemView->SetSizePixel(GetOutputSizePixel());
-    mpItemView->SetColCount(3);
-    mpItemView->SetLineCount(2);
+    mpItemView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
+                                  ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
+                                  ITEM_PADDING);
 
     mpItemView->setItemStateHdl(LINK(this,TemplateFolderView,TVTemplateStateHdl));
 }
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index fd0d412..6156870 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -89,6 +89,7 @@ void ThumbnailView::ImplInit()
     mnHeaderHeight      = 0;
     mnItemWidth         = 0;
     mnItemHeight        = 0;
+    mnItemPadding = 0;
     mnVisLines          = 0;
     mnLines             = 0;
     mnUserItemWidth     = 0;
@@ -222,11 +223,12 @@ void ThumbnailView::OnItemDblClicked (ThumbnailViewItem*)
 
 void ThumbnailView::CalculateItemPositions ()
 {
+    if (!mnItemHeight || !mnItemWidth)
+        return;
+
     Size        aWinSize = GetOutputSizePixel();
     size_t      nItemCount = mItemList.size();
     WinBits     nStyle = GetStyle();
-    long        nNoneHeight = 0;
-    long        nNoneSpace = 0;
     ScrollBar*  pDelScrBar = NULL;
 
     // consider the scrolling
@@ -247,41 +249,34 @@ void ThumbnailView::CalculateItemPositions ()
     if ( mpScrBar )
         nScrBarWidth = mpScrBar->GetSizePixel().Width()+SCRBAR_OFFSET;
 
-    // calculate number of columns
-    if ( !mnUserCols )
-    {
-        if ( mnUserItemWidth )
-        {
-            mnCols = (sal_uInt16)((aWinSize.Width()-nScrBarWidth+mnSpacing) / (mnUserItemWidth+mnSpacing));
-            if ( !mnCols )
-                mnCols = 1;
-        }
-        else
-            mnCols = 1;
-    }
-    else
+    // calculate maximum number of visible columns
+    mnCols = (sal_uInt16)((aWinSize.Width()-nScrBarWidth) / (mnItemWidth));
+
+    if ( mnUserCols && mnUserCols < mnCols )
         mnCols = mnUserCols;
 
-    // calculate number of rows
-    mbScroll = false;
+    // calculate maximum number of visible rows
+    mnVisLines = (sal_uInt16)((aWinSize.Height()-mnHeaderHeight) / (mnItemHeight));
+
+    if ( mnUserVisLines && mnUserVisLines < mnVisLines )
+        mnVisLines = mnUserVisLines;
+
+    // calculate empty space
+    long nHSpace = aWinSize.Width()-nScrBarWidth - mnCols*mnItemWidth;
+    long nVSpace = aWinSize.Height()-mnHeaderHeight - mnVisLines*mnItemHeight;
+    long nHItemSpace = nHSpace / (mnCols+1);
+    long nVItemSpace = nVSpace / (mnVisLines+1);
+
+    // calculate maximum number of rows
     // Floor( (M+N-1)/N )==Ceiling( M/N )
     mnLines = (static_cast<long>(nItemCount)+mnCols-1) / mnCols;
+
     if ( !mnLines )
         mnLines = 1;
 
-    long nCalcHeight = aWinSize.Height()-nNoneHeight;
-    if ( mnUserVisLines )
-        mnVisLines = mnUserVisLines;
-    else if ( mnUserItemHeight )
-    {
-        mnVisLines = (nCalcHeight-nNoneSpace+mnSpacing) / (mnUserItemHeight+mnSpacing);
-        if ( !mnVisLines )
-            mnVisLines = 1;
-    }
-    else
-        mnVisLines = mnLines;
-    if ( mnLines > mnVisLines )
-        mbScroll = true;
+    // check if scroll is needed
+    mbScroll = mnLines > mnVisLines;
+
     if ( mnLines <= mnVisLines )
         mnFirstLine = 0;
     else
@@ -290,138 +285,93 @@ void ThumbnailView::CalculateItemPositions ()
             mnFirstLine = (sal_uInt16)(mnLines-mnVisLines);
     }
 
-    // calculate item size
-    const long nColSpace  = (mnCols-1)*mnSpacing;
-    const long nLineSpace = ((mnVisLines-1)*mnSpacing)+nNoneSpace;
-    if ( mnUserItemWidth && !mnUserCols )
-    {
-        mnItemWidth = mnUserItemWidth;
-        if ( mnItemWidth > aWinSize.Width()-nScrBarWidth-nColSpace )
-            mnItemWidth = aWinSize.Width()-nScrBarWidth-nColSpace;
-    }
-    else
-        mnItemWidth = (aWinSize.Width()-nScrBarWidth-nColSpace) / mnCols;
-    if ( mnUserItemHeight && !mnUserVisLines )
-    {
-        mnItemHeight = mnUserItemHeight;
-        if ( mnItemHeight > nCalcHeight-nNoneSpace )
-            mnItemHeight = nCalcHeight-nNoneSpace;
-    }
-    else
-    {
-        nCalcHeight -= nLineSpace;
-        mnItemHeight = nCalcHeight / mnVisLines;
-    }
-
-    // nothing is changed in case of too small items
-    if ( (mnItemWidth <= 0) ||
-         (mnItemHeight <= 2) ||
-         !nItemCount )
-    {
-        mbHasVisibleItems = false;
-
-        for ( size_t i = 0; i < nItemCount; i++ )
-        {
-            if (mItemList[i]->isVisible())
-                maItemStateHdl.Call(mItemList[i]);
-
-            mItemList[i]->show(false);
-        }
+    mbHasVisibleItems = true;
 
-        if ( mpScrBar )
-            mpScrBar->Hide();
-    }
-    else
-    {
-        mbHasVisibleItems = true;
+    // calculate offsets
+    long nStartX = nHItemSpace;
+    long nStartY = nVItemSpace + mnHeaderHeight;
 
-        // calculate offsets
-        long nStartX = 0;
-        long nStartY = mnHeaderHeight;
+    // calculate and draw items
+    long x = nStartX;
+    long y = nStartY;
 
-        // calculate and draw items
-        long x = nStartX;
-        long y = nStartY;
+    // draw items
+    size_t nTotalItems = mnFirstLine*mnCols + mnVisLines*mnCols;
 
-        // draw items
-        size_t nTotalItems = mnFirstLine*mnCols + mnVisLines*mnCols;
+    maItemListRect.Left() = x;
+    maItemListRect.Top() = y;
+    maItemListRect.Right() = x + mnCols*(mnItemWidth+nHItemSpace) - nHItemSpace - 1;
+    maItemListRect.Bottom() = y + mnVisLines*(mnItemHeight+nVItemSpace) - nVItemSpace - 1;
 
-        maItemListRect.Left() = x;
-        maItemListRect.Top() = y + mnHeaderHeight;
-        maItemListRect.Right() = x + mnCols*(mnItemWidth+mnSpacing) - mnSpacing - 1;
-        maItemListRect.Bottom() = y + mnVisLines*(mnItemHeight+mnSpacing) - mnSpacing - 1;
+    // If want also draw parts of items in the last line,
+    // then we add one more line if parts of these line are
+    // visible
+    if ( y+(mnVisLines*(mnItemHeight+nVItemSpace)) < aWinSize.Height() )
+        nTotalItems += mnCols;
 
-        // If want also draw parts of items in the last line,
-        // then we add one more line if parts of these line are
-        // visible
-        if ( y+(mnVisLines*(mnItemHeight+mnSpacing)) < aWinSize.Height() )
-            nTotalItems += mnCols;
-        maItemListRect.Bottom() = aWinSize.Height() - y;
+    size_t nCurCount = 0;
+    for ( size_t i = 0; i < nItemCount; i++ )
+    {
+        ThumbnailViewItem *const pItem = mItemList[i];
 
-        size_t nCurCount = 0;
-        for ( size_t i = 0; i < nItemCount; i++ )
+        if (maFilterFunc(pItem) && nCurCount < nTotalItems)
         {
-            ThumbnailViewItem *const pItem = mItemList[i];
-
-            if (maFilterFunc(pItem) && nCurCount < nTotalItems)
+            if( !pItem->isVisible() && ImplHasAccessibleListeners() )
             {
-                if( !pItem->isVisible() && ImplHasAccessibleListeners() )
-                {
-                    ::com::sun::star::uno::Any aOldAny, aNewAny;
-
-                    aNewAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
-                    ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
-                }
+                ::com::sun::star::uno::Any aOldAny, aNewAny;
 
-                if (!mItemList[i]->isVisible())
-                    maItemStateHdl.Call(mItemList[i]);
+                aNewAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
+                ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
+            }
 
-                pItem->show(true);
-                pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ));
-                pItem->calculateItemsPosition();
+            if (!mItemList[i]->isVisible())
+                maItemStateHdl.Call(mItemList[i]);
 
-                if ( !((nCurCount+1) % mnCols) )
-                {
-                    x = nStartX;
-                    y += mnItemHeight+mnSpacing;
-                }
-                else
-                    x += mnItemWidth+mnSpacing;
+            pItem->show(true);
+            pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ));
+            pItem->calculateItemsPosition();
 
-                ++nCurCount;
+            if ( !((nCurCount+1) % mnCols) )
+            {
+                x = nStartX;
+                y += mnItemHeight+nVItemSpace;
             }
             else
+                x += mnItemWidth+nHItemSpace;
+
+            ++nCurCount;
+        }
+        else
+        {
+            if( pItem->isVisible() && ImplHasAccessibleListeners() )
             {
-                if( pItem->isVisible() && ImplHasAccessibleListeners() )
-                {
-                    ::com::sun::star::uno::Any aOldAny, aNewAny;
+                ::com::sun::star::uno::Any aOldAny, aNewAny;
 
-                    aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
-                    ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
-                }
+                aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
+                ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
+            }
 
-                if (mItemList[i]->isVisible())
-                    maItemStateHdl.Call(mItemList[i]);
+            if (mItemList[i]->isVisible())
+                maItemStateHdl.Call(mItemList[i]);
 
-                pItem->show(false);
-            }
+            pItem->show(false);
         }
+    }
 
-        // arrange ScrollBar, set values and show it
-        if ( mpScrBar )
-        {
-            Point   aPos( aWinSize.Width()-nScrBarWidth+SCRBAR_OFFSET, 0 );
-            Size    aSize( nScrBarWidth-SCRBAR_OFFSET, aWinSize.Height() );
-
-            mpScrBar->SetPosSizePixel( aPos, aSize );
-            mpScrBar->SetRangeMax( mnLines );
-            mpScrBar->SetVisibleSize( mnVisLines );
-            mpScrBar->SetThumbPos( (long)mnFirstLine );
-            long nPageSize = mnVisLines;
-            if ( nPageSize < 1 )
-                nPageSize = 1;
-            mpScrBar->SetPageSize( nPageSize );
-        }
+    // arrange ScrollBar, set values and show it
+    if ( mpScrBar )
+    {
+        Point   aPos( aWinSize.Width()-nScrBarWidth+SCRBAR_OFFSET, 0 );
+        Size    aSize( nScrBarWidth-SCRBAR_OFFSET, aWinSize.Height() );
+
+        mpScrBar->SetPosSizePixel( aPos, aSize );
+        mpScrBar->SetRangeMax( mnLines );
+        mpScrBar->SetVisibleSize( mnVisLines );
+        mpScrBar->SetThumbPos( (long)mnFirstLine );
+        long nPageSize = mnVisLines;
+        if ( nPageSize < 1 )
+            nPageSize = 1;
+        mpScrBar->SetPageSize( nPageSize );
     }
 
     // delete ScrollBar
@@ -1136,30 +1086,13 @@ void ThumbnailView::SetLineCount( sal_uInt16 nNewLines )
     }
 }
 
-void ThumbnailView::SetItemWidth( long nNewItemWidth )
+void ThumbnailView::setItemDimensions(long itemWidth, long thumbnailHeight, long displayHeight, int itemPadding)
 {
-    if ( mnUserItemWidth != nNewItemWidth )
-    {
-        mnUserItemWidth = nNewItemWidth;
-
-        CalculateItemPositions();
-
-        if ( IsReallyVisible() && IsUpdateMode() )
-            Invalidate();
-    }
-}
-
-void ThumbnailView::SetItemHeight( long nNewItemHeight )
-{
-    if ( mnUserItemHeight != nNewItemHeight )
-    {
-        mnUserItemHeight = nNewItemHeight;
-
-        CalculateItemPositions();
-
-        if ( IsReallyVisible() && IsUpdateMode() )
-            Invalidate();
-    }
+    mnItemWidth = itemWidth + 2*itemPadding;
+    mnThumbnailHeight = thumbnailHeight;
+    mnDisplayHeight = displayHeight;
+    mnItemPadding = itemPadding;
+    mnItemHeight = mnDisplayHeight + mnThumbnailHeight + 2*itemPadding;
 }
 
 void ThumbnailView::SelectItem( sal_uInt16 nItemId )
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index dcf3fc0..fdd86df 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -31,8 +31,10 @@
 #include "doc.hrc"
 #include "templatedlg.hrc"
 
-#define MAX_COLUMN_COUNT 4
-#define MAX_LINE_COUNT 2
+#define ITEM_MAX_WIDTH 192
+#define ITEM_MAX_HEIGHT 192
+#define ITEM_PADDING 5
+#define THUMBNAIL_MAX_HEIGHT 128
 
 #define PADDING_TOOLBAR_VIEW    15
 #define PADDING_DLG_BORDER      10
@@ -129,8 +131,9 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
     mpSearchEdit->SetPosPixel(Point(PADDING_DLG_BORDER,aActionPos.Y()+aActionSize.getHeight()));
 
     maView->SetStyle(WB_TABSTOP | WB_VSCROLL);
-    maView->SetColCount(MAX_COLUMN_COUNT);
-    maView->SetLineCount(MAX_LINE_COUNT);
+    maView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
+                              ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
+                              ITEM_PADDING);
 
     maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVFolderStateHdl));
     maView->setTemplateStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl));


More information about the Libreoffice-commits mailing list