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

Rafael Dominguez rdominguez at kemper.freedesktop.org
Thu Jul 5 17:49:56 PDT 2012


 sfx2/inc/sfx2/templatefolderview.hxx       |    2 
 sfx2/source/control/templatefolderview.cxx |   73 +++++++++++++++++++++--------
 sfx2/source/doc/templatedlg.cxx            |   14 +++++
 3 files changed, 70 insertions(+), 19 deletions(-)

New commits:
commit 551948e6239926c414e2f26c95d0a71f7b88a355
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jul 5 20:14:00 2012 -0430

    Fix moving templates between folders.
    
    Change-Id: I1befe0add1bdff518c4553a8116d4fed235fd1b8

diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 4f39428..022fb47 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -519,17 +519,18 @@ bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rIte
         std::set<const ThumbnailViewItem*>::iterator aSelIter;
         for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter )
         {
+            const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
+
             sal_uInt16 nTargetRegion = pTarget->mnId-1;
-            sal_uInt16 nTargetIdx = pTarget->maTemplates.back()->mnId; // Last Assigned in filesystem is mnId-1
+            sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion);    // Next Idx
 
-            if (!mpDocTemplates->Move(nTargetRegion,nTargetIdx,mpItemView->getRegionId(),(*aSelIter)->mnId-1))
+            if (!mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1))
             {
                 ret = false;
                 continue;
             }
 
             // move template to destination
-            const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
 
             TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView);
             pTemplateItem->mnId = nTargetIdx + 1;
commit 2691b4db8242aa82c7c77a54902ae112fae635d0
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jul 5 19:44:40 2012 -0430

    Display all folders even if theyre empty.
    
    Change-Id: I3b7db9adf513d0c3aa8c70c7f6edc5b690504eff

diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 1035944..4f39428 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -288,15 +288,15 @@ void TemplateFolderView::Populate ()
             aRegionName += "...";
         }
 
+        TemplateFolderViewItem* pItem = new TemplateFolderViewItem( *this, this );
+        pItem->mnId = i+1;
+        pItem->maText = aRegionName;
+        pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected));
+
         sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
 
         if (nEntries)
         {
-            TemplateFolderViewItem* pItem = new TemplateFolderViewItem( *this, this );
-            pItem->mnId = i+1;
-            pItem->maText = aRegionName;
-            pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected));
-
             /// Preview first 2 thumbnails for folder
             pItem->maPreview1 = lcl_fetchThumbnail(mpDocTemplates->GetPath(i,0),
                                                    THUMBNAIL_MAX_WIDTH*0.75,
@@ -328,9 +328,9 @@ void TemplateFolderView::Populate ()
 
                 pItem->maTemplates.push_back(pTemplateItem);
             }
-
-            mItemList.push_back(pItem);
         }
+
+        mItemList.push_back(pItem);
     }
 
     CalculateItemPositions();
commit e1301a4087bcba029665a3a8dd99888470c980dc
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Thu Jul 5 18:55:41 2012 -0430

    Implement move templates to a new region.
    
    Change-Id: I57597a39e3af80e6e25f46eac17e888f99b5482a

diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx
index ae5f6a1..dac804b 100644
--- a/sfx2/inc/sfx2/templatefolderview.hxx
+++ b/sfx2/inc/sfx2/templatefolderview.hxx
@@ -57,7 +57,7 @@ public:
 
     void setTemplateStateHdl (const Link &aLink) { maTemplateStateHdl = aLink; }
 
-    bool createRegion (const rtl::OUString &rName, const std::set<const ThumbnailViewItem*> &rItems);
+    sal_uInt16 createRegion (const rtl::OUString &rName);
 
     bool removeTemplate (const sal_uInt16 nItemId);
 
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index fc9b372..1035944 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -36,6 +36,18 @@
 #define INIT_VIEW_COLS 3
 #define INIT_VIEW_LINES 1
 
+BitmapEx lcl_ScaleImg (const BitmapEx &rImg, long width, long height)
+{
+    BitmapEx aImg = rImg;
+
+    int sWidth = std::min(aImg.GetSizePixel().getWidth(),width);
+    int sHeight = std::min(aImg.GetSizePixel().getHeight(),height);
+
+    aImg.Scale(Size(sWidth,sHeight),BMP_SCALE_INTERPOLATE);
+
+    return aImg;
+}
+
 BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, long width, long height)
 {
     using namespace ::com::sun::star;
@@ -142,15 +154,7 @@ BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, long width, long height
         aThumbnail = aReader.Read ();
     }
 
-    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
-    // possibly larger resolution then was asked for.
-    return aThumbnail;
+    return lcl_ScaleImg(aThumbnail,width,height);
 }
 
 // Display template items depending on the generator application
@@ -425,8 +429,33 @@ void TemplateFolderView::sortOverlayItems(const boost::function<bool (const Thum
     mpItemView->sortItems(func);
 }
 
-bool TemplateFolderView::createRegion(const rtl::OUString &rName, const std::set<const ThumbnailViewItem*> &rItems)
+sal_uInt16 TemplateFolderView::createRegion(const rtl::OUString &rName)
 {
+    sal_uInt16 nRegionId = mpDocTemplates->GetRegionCount();    // Next regionId
+
+    if (!mpDocTemplates->InsertDir(rName,nRegionId))
+        return false;
+
+    rtl::OUString aRegionName = rName;
+
+    if (aRegionName.getLength() > (sal_Int32)mpItemAttrs->nMaxTextLenght)
+    {
+        aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+        aRegionName += "...";
+    }
+
+    TemplateFolderViewItem* pItem = new TemplateFolderViewItem( *this, this );
+    pItem->mnId = nRegionId+1;
+    pItem->maText = aRegionName;
+    pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected));
+
+    mItemList.push_back(pItem);
+
+    CalculateItemPositions();
+
+    if ( IsReallyVisible() && IsUpdateMode() )
+        Invalidate();
+
     return true;
 }
 
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 5c6747f..819c3ab 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -498,7 +498,9 @@ IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu)
 
             if (!aName.isEmpty())
             {
-                if (!maView->createRegion(aName,maSelTemplates))
+                sal_uInt16 nNewRegionId = maView->createRegion(aName);
+
+                if (nNewRegionId && !maView->moveTemplates(maSelTemplates,nNewRegionId))
                 {
                 }
             }
commit 2168ee056253def18c43a6b13dbdfd0a992de2df
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Wed Jul 4 12:52:28 2012 -0430

    Create new folder after getting input text with selected templates.
    
    Change-Id: I8eb788e9158f5016f60ae344543859ac4e403ebe

diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx
index 1e0c2b5..ae5f6a1 100644
--- a/sfx2/inc/sfx2/templatefolderview.hxx
+++ b/sfx2/inc/sfx2/templatefolderview.hxx
@@ -57,6 +57,8 @@ public:
 
     void setTemplateStateHdl (const Link &aLink) { maTemplateStateHdl = aLink; }
 
+    bool createRegion (const rtl::OUString &rName, const std::set<const ThumbnailViewItem*> &rItems);
+
     bool removeTemplate (const sal_uInt16 nItemId);
 
     bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem);
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index d202293..fc9b372 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -425,6 +425,11 @@ void TemplateFolderView::sortOverlayItems(const boost::function<bool (const Thum
     mpItemView->sortItems(func);
 }
 
+bool TemplateFolderView::createRegion(const rtl::OUString &rName, const std::set<const ThumbnailViewItem*> &rItems)
+{
+    return true;
+}
+
 bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId)
 {
     sal_uInt16 nRegionId = mpItemView->getRegionId();
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 29d664a..5c6747f 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -491,6 +491,18 @@ IMPL_LINK(SfxTemplateManagerDlg, MoveMenuSelectHdl, Menu*, pMenu)
         InputDialog dlg(SfxResId(STR_INPUT_NEW).toString(),this);
 
         int ret = dlg.Execute();
+
+        if (ret)
+        {
+            rtl::OUString aName = dlg.getEntryText();
+
+            if (!aName.isEmpty())
+            {
+                if (!maView->createRegion(aName,maSelTemplates))
+                {
+                }
+            }
+        }
     }
     else if (nMenuId == MNI_MOVE_DELETE)
     {


More information about the Libreoffice-commits mailing list