[Libreoffice-commits] .: 6 commits - sfx2/inc sfx2/Library_sfx.mk sfx2/Package_inc.mk sfx2/source
Rafael Dominguez
rdominguez at kemper.freedesktop.org
Sun Jul 29 21:03:50 PDT 2012
sfx2/Library_sfx.mk | 4
sfx2/Package_inc.mk | 4
sfx2/inc/sfx2/templateabstractview.hxx | 28 +
sfx2/inc/sfx2/templatefolderview.hxx | 82 --
sfx2/inc/sfx2/templatefolderviewitem.hxx | 42 -
sfx2/inc/sfx2/templatelocalview.hxx | 73 ++
sfx2/inc/sfx2/templatelocalviewitem.hxx | 42 +
sfx2/inc/sfx2/templateonlineview.hxx | 2
sfx2/inc/templatedlg.hxx | 4
sfx2/source/control/templateabstractview.cxx | 29 +
sfx2/source/control/templatefolderview.cxx | 691 -------------------------
sfx2/source/control/templatefolderviewitem.cxx | 115 ----
sfx2/source/control/templatelocalview.cxx | 650 +++++++++++++++++++++++
sfx2/source/control/templatelocalviewitem.cxx | 115 ++++
sfx2/source/control/templateonlineview.cxx | 7
sfx2/source/doc/templatedlg.cxx | 24
16 files changed, 967 insertions(+), 945 deletions(-)
New commits:
commit e09046cede7ae47615f404474fe289d89f91dac5
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 29 23:30:47 2012 -0430
Filter online view templates depending on their type.
- Moved ViewFilter_Application to TemplateAbstractView header.
- Removed unused attribute in ViewFilter_Application.
Change-Id: I569f6a0c7135781256e348b01cb45aad6b7dcee6
diff --git a/sfx2/inc/sfx2/templateabstractview.hxx b/sfx2/inc/sfx2/templateabstractview.hxx
index 74dcd8a..a4b1daf 100644
--- a/sfx2/inc/sfx2/templateabstractview.hxx
+++ b/sfx2/inc/sfx2/templateabstractview.hxx
@@ -13,6 +13,32 @@
#include <sfx2/thumbnailview.hxx>
class TemplateView;
+class SfxDocumentTemplates;
+
+enum FILTER_APPLICATION
+{
+ FILTER_APP_NONE,
+ FILTER_APP_WRITER,
+ FILTER_APP_CALC,
+ FILTER_APP_IMPRESS,
+ FILTER_APP_DRAW
+};
+
+// Display template items depending on the generator application
+class ViewFilter_Application
+{
+public:
+
+ ViewFilter_Application (FILTER_APPLICATION App)
+ : mApp(App)
+ {}
+
+ bool operator () (const ThumbnailViewItem *pItem);
+
+private:
+
+ FILTER_APPLICATION mApp;
+};
class SFX2_DLLPUBLIC TemplateAbstractView : public ThumbnailView
{
@@ -27,6 +53,8 @@ public:
// Fill view with template folders thumbnails
virtual void Populate () = 0;
+ virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp) = 0;
+
virtual void showOverlay (bool bVisible) = 0;
sal_uInt16 getOverlayRegionId () const;
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index f3161e7..67a56ae 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -18,15 +18,6 @@
class SfxDocumentTemplates;
class TemplateLocalViewItem;
-enum FILTER_APPLICATION
-{
- FILTER_APP_NONE,
- FILTER_APP_WRITER,
- FILTER_APP_CALC,
- FILTER_APP_IMPRESS,
- FILTER_APP_DRAW
-};
-
class SFX2_DLLPUBLIC TemplateLocalView : public TemplateAbstractView
{
public:
@@ -42,7 +33,7 @@ public:
virtual void showOverlay (bool bVisible);
- void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
+ virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
std::vector<TemplateItemProperties>
getFilteredItems (const boost::function<bool (const TemplateItemProperties&) > &rFunc) const;
diff --git a/sfx2/inc/sfx2/templateonlineview.hxx b/sfx2/inc/sfx2/templateonlineview.hxx
index e868248..245da5f 100644
--- a/sfx2/inc/sfx2/templateonlineview.hxx
+++ b/sfx2/inc/sfx2/templateonlineview.hxx
@@ -25,6 +25,8 @@ public:
// Load repositories from user settings.
virtual void Populate ();
+ virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
+
virtual void showOverlay (bool bVisible);
void setItemDimensions (long ItemWidth, long ThumbnailHeight, long DisplayHeight, int itemPadding);
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx
index 8f8d78b..fbe2378 100644
--- a/sfx2/source/control/templateabstractview.cxx
+++ b/sfx2/source/control/templateabstractview.cxx
@@ -11,6 +11,7 @@
#include <comphelper/processfactory.hxx>
#include <sfx2/templateview.hxx>
+#include <sfx2/templateviewitem.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/pngread.hxx>
@@ -20,6 +21,34 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
+{
+ const TemplateViewItem *pTempItem = static_cast<const TemplateViewItem*>(pItem);
+
+ if (mApp == FILTER_APP_WRITER)
+ {
+ return pTempItem->getFileType() == "OpenDocument Text" ||
+ pTempItem->getFileType() == "OpenDocument Text Template";
+ }
+ else if (mApp == FILTER_APP_CALC)
+ {
+ return pTempItem->getFileType() == "OpenDocument Spreadsheet" ||
+ pTempItem->getFileType() == "OpenDocument Spreadsheet Template";
+ }
+ else if (mApp == FILTER_APP_IMPRESS)
+ {
+ return pTempItem->getFileType() == "OpenDocument Presentation" ||
+ pTempItem->getFileType() == "OpenDocument Presentation Template";
+ }
+ else if (mApp == FILTER_APP_DRAW)
+ {
+ return pTempItem->getFileType() == "OpenDocument Drawing" ||
+ pTempItem->getFileType() == "OpenDocument Drawing Template";
+ }
+
+ return true;
+}
+
TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
: ThumbnailView(pParent,nWinStyle,bDisableTransientChildren),
mpItemView(new TemplateView(this))
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index fa19d54..e1916da 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -38,49 +38,6 @@
void lcl_updateThumbnails (TemplateLocalViewItem *pItem);
-// Display template items depending on the generator application
-class ViewFilter_Application
-{
-public:
-
- ViewFilter_Application (SfxDocumentTemplates *pDocTemplates, FILTER_APPLICATION App)
- : mApp(App), mpDocTemplates(pDocTemplates)
- {}
-
- bool operator () (const ThumbnailViewItem *pItem)
- {
- const TemplateViewItem *pTempItem = static_cast<const TemplateViewItem*>(pItem);
-
- if (mApp == FILTER_APP_WRITER)
- {
- return pTempItem->getFileType() == "OpenDocument Text" ||
- pTempItem->getFileType() == "OpenDocument Text Template";
- }
- else if (mApp == FILTER_APP_CALC)
- {
- return pTempItem->getFileType() == "OpenDocument Spreadsheet" ||
- pTempItem->getFileType() == "OpenDocument Spreadsheet Template";
- }
- else if (mApp == FILTER_APP_IMPRESS)
- {
- return pTempItem->getFileType() == "OpenDocument Presentation" ||
- pTempItem->getFileType() == "OpenDocument Presentation Template";
- }
- else if (mApp == FILTER_APP_DRAW)
- {
- return pTempItem->getFileType() == "OpenDocument Drawing" ||
- pTempItem->getFileType() == "OpenDocument Drawing Template";
- }
-
- return true;
- }
-
-private:
-
- FILTER_APPLICATION mApp;
- SfxDocumentTemplates *mpDocTemplates;
-};
-
class FolderFilter_Application
{
public:
@@ -266,7 +223,7 @@ void TemplateLocalView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
if (mpItemView->IsVisible())
{
mbFilteredResults = true;
- mpItemView->filterItems(ViewFilter_Application(mpDocTemplates,eApp));
+ mpItemView->filterItems(ViewFilter_Application(eApp));
}
else
{
@@ -642,7 +599,7 @@ void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pRegionItem)
mpItemView->setSelectionMode(true);
if (meFilterOption != FILTER_APP_NONE)
- mpItemView->filterItems(ViewFilter_Application(mpDocTemplates,meFilterOption));
+ mpItemView->filterItems(ViewFilter_Application(meFilterOption));
mbActive = false;
mpItemView->Show();
diff --git a/sfx2/source/control/templateonlineview.cxx b/sfx2/source/control/templateonlineview.cxx
index 2f88ca0..822145c 100644
--- a/sfx2/source/control/templateonlineview.cxx
+++ b/sfx2/source/control/templateonlineview.cxx
@@ -93,6 +93,12 @@ void TemplateOnlineView::Populate()
Invalidate();
}
+void TemplateOnlineView::filterTemplatesByApp(const FILTER_APPLICATION &eApp)
+{
+ if (mpItemView->IsVisible())
+ mpItemView->filterItems(ViewFilter_Application(eApp));
+}
+
void TemplateOnlineView::showOverlay (bool bVisible)
{
mbActive = !bVisible;
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index f37130e..28b7f86 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -264,31 +264,31 @@ SfxTemplateManagerDlg::~SfxTemplateManagerDlg ()
IMPL_LINK_NOARG(SfxTemplateManagerDlg,ViewAllHdl)
{
- maView->filterTemplatesByApp(FILTER_APP_NONE);
+ mpCurView->filterTemplatesByApp(FILTER_APP_NONE);
return 0;
}
IMPL_LINK_NOARG(SfxTemplateManagerDlg,ViewDocsHdl)
{
- maView->filterTemplatesByApp(FILTER_APP_WRITER);
+ mpCurView->filterTemplatesByApp(FILTER_APP_WRITER);
return 0;
}
IMPL_LINK_NOARG(SfxTemplateManagerDlg,ViewPresentsHdl)
{
- maView->filterTemplatesByApp(FILTER_APP_IMPRESS);
+ mpCurView->filterTemplatesByApp(FILTER_APP_IMPRESS);
return 0;
}
IMPL_LINK_NOARG(SfxTemplateManagerDlg,ViewSheetsHdl)
{
- maView->filterTemplatesByApp(FILTER_APP_CALC);
+ mpCurView->filterTemplatesByApp(FILTER_APP_CALC);
return 0;
}
IMPL_LINK_NOARG(SfxTemplateManagerDlg,ViewDrawsHdl)
{
- maView->filterTemplatesByApp(FILTER_APP_DRAW);
+ mpCurView->filterTemplatesByApp(FILTER_APP_DRAW);
return 0;
}
commit ff8c376564b935035140bf296ef86ddbb8222bab
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 29 23:02:03 2012 -0430
Display overlay name for online view.
Change-Id: I52b59074b10abd960b43d5d3326a312e2391b3eb
diff --git a/sfx2/source/control/templateonlineview.cxx b/sfx2/source/control/templateonlineview.cxx
index 2d6c75d..2f88ca0 100644
--- a/sfx2/source/control/templateonlineview.cxx
+++ b/sfx2/source/control/templateonlineview.cxx
@@ -212,6 +212,7 @@ void TemplateOnlineView::OnItemDblClicked(ThumbnailViewItem *pItem)
}
}
+ mpItemView->setName(pItem->maTitle);
mpItemView->InsertItems(aItems);
mpItemView->Show();
}
commit 8c71dff488bd91e8f20018af38ed906762ea58e8
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 29 22:52:44 2012 -0430
Rename TemplateFolderView to TemplateLocalView.
Change-Id: I1cc75b9f4279323ca26943f8a2f3d2d0ac1a7edc
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 06f64d0..95c68e2 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -136,8 +136,8 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/control/templateabstractview \
sfx2/source/control/templateview \
sfx2/source/control/templateviewitem \
- sfx2/source/control/templatefolderview \
- sfx2/source/control/templatefolderviewitem \
+ sfx2/source/control/templatelocalview \
+ sfx2/source/control/templatelocalviewitem \
sfx2/source/control/templateonlineview \
sfx2/source/control/templateonlineviewitem \
sfx2/source/control/templatesearchview \
diff --git a/sfx2/Package_inc.mk b/sfx2/Package_inc.mk
index c3bfff6..1a71255 100644
--- a/sfx2/Package_inc.mk
+++ b/sfx2/Package_inc.mk
@@ -120,8 +120,8 @@ $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templdlg.hxx,sfx2/templdlg.h
$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocnames.hrc,sfx2/templatelocnames.hrc))
$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateabstractview.hxx,sfx2/templateabstractview.hxx))
$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateview.hxx,sfx2/templateview.hxx))
-$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatefolderview.hxx,sfx2/templatefolderview.hxx))
-$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatefolderviewitem.hxx,sfx2/templatefolderviewitem.hxx))
+$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocalview.hxx,sfx2/templatelocalview.hxx))
+$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocalviewitem.hxx,sfx2/templatelocalviewitem.hxx))
$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateonlineview.hxx,sfx2/templateonlineview.hxx))
$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateonlineviewitem.hxx,sfx2/templateonlineviewitem.hxx))
$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/thumbnailview.hxx,sfx2/thumbnailview.hxx))
diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx
deleted file mode 100644
index 44c61e0..0000000
--- a/sfx2/inc/sfx2/templatefolderview.hxx
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright 2012 LibreOffice contributors.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef TEMPLATEFOLDERVIEW_HXX
-#define TEMPLATEFOLDERVIEW_HXX
-
-#include <set>
-
-#include <sfx2/templateabstractview.hxx>
-#include <sfx2/templateproperties.hxx>
-
-class SfxDocumentTemplates;
-class TemplateFolderViewItem;
-
-enum FILTER_APPLICATION
-{
- FILTER_APP_NONE,
- FILTER_APP_WRITER,
- FILTER_APP_CALC,
- FILTER_APP_IMPRESS,
- FILTER_APP_DRAW
-};
-
-class SFX2_DLLPUBLIC TemplateFolderView : public TemplateAbstractView
-{
-public:
-
- TemplateFolderView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
-
- virtual ~TemplateFolderView ();
-
- // Fill view with template folders thumbnails
- virtual void Populate ();
-
- std::vector<rtl::OUString> getFolderNames ();
-
- virtual void showOverlay (bool bVisible);
-
- void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
-
- std::vector<TemplateItemProperties>
- getFilteredItems (const boost::function<bool (const TemplateItemProperties&) > &rFunc) const;
-
- sal_uInt16 createRegion (const rtl::OUString &rName);
-
- bool removeRegion (const sal_uInt16 nItemId);
-
- bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId);
-
- bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem,
- const sal_uInt16 nTargetItem, bool bCopy);
-
- bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem, bool bCopy);
-
- void copyFrom (const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath);
-
- void copyFrom (TemplateFolderViewItem *pItem, const rtl::OUString &rPath);
-
-private:
-
- virtual void Resize ();
-
- virtual void OnItemDblClicked (ThumbnailViewItem *pRegionItem);
-
- DECL_LINK(ChangeNameHdl, TemplateView*);
-
-private:
-
- bool mbFilteredResults; // Flag keep track if overlay has been filtered so folders can get filtered too afterwards
- FILTER_APPLICATION meFilterOption;
- SfxDocumentTemplates *mpDocTemplates;
-};
-
-#endif // TEMPLATEFOLDERVIEW_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/inc/sfx2/templatefolderviewitem.hxx b/sfx2/inc/sfx2/templatefolderviewitem.hxx
deleted file mode 100644
index d4c6c0a..0000000
--- a/sfx2/inc/sfx2/templatefolderviewitem.hxx
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright 2012 LibreOffice contributors.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef TEMPLATEFOLDERVIEWITEM_HXX
-#define TEMPLATEFOLDERVIEWITEM_HXX
-
-#include <sfx2/templateproperties.hxx>
-#include <sfx2/thumbnailviewitem.hxx>
-
-class TemplateViewItem;
-
-class TemplateFolderViewItem : public ThumbnailViewItem
-{
-public:
-
- BitmapEx maPreview2;
- std::vector<TemplateItemProperties> maTemplates;
-
- TemplateFolderViewItem (ThumbnailView &rView, Window *pParent);
-
- virtual ~TemplateFolderViewItem ();
-
- virtual void calculateItemsPosition (sal_uInt32 nMaxTextLenght);
-
- const Point& getPrev2Pos () const { return maPrev2Pos; }
-
- virtual void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
- const ThumbnailItemAttributes *pAttrs);
-private:
-
- Point maPrev2Pos;
-};
-
-#endif // TEMPLATEFOLDERVIEWITEM_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
new file mode 100644
index 0000000..f3161e7
--- /dev/null
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright 2012 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef TEMPLATEFOLDERVIEW_HXX
+#define TEMPLATEFOLDERVIEW_HXX
+
+#include <set>
+
+#include <sfx2/templateabstractview.hxx>
+#include <sfx2/templateproperties.hxx>
+
+class SfxDocumentTemplates;
+class TemplateLocalViewItem;
+
+enum FILTER_APPLICATION
+{
+ FILTER_APP_NONE,
+ FILTER_APP_WRITER,
+ FILTER_APP_CALC,
+ FILTER_APP_IMPRESS,
+ FILTER_APP_DRAW
+};
+
+class SFX2_DLLPUBLIC TemplateLocalView : public TemplateAbstractView
+{
+public:
+
+ TemplateLocalView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
+
+ virtual ~TemplateLocalView ();
+
+ // Fill view with template folders thumbnails
+ virtual void Populate ();
+
+ std::vector<rtl::OUString> getFolderNames ();
+
+ virtual void showOverlay (bool bVisible);
+
+ void filterTemplatesByApp (const FILTER_APPLICATION &eApp);
+
+ std::vector<TemplateItemProperties>
+ getFilteredItems (const boost::function<bool (const TemplateItemProperties&) > &rFunc) const;
+
+ sal_uInt16 createRegion (const rtl::OUString &rName);
+
+ bool removeRegion (const sal_uInt16 nItemId);
+
+ bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId);
+
+ bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem,
+ const sal_uInt16 nTargetItem, bool bCopy);
+
+ bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem, bool bCopy);
+
+ void copyFrom (const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath);
+
+ void copyFrom (TemplateLocalViewItem *pItem, const rtl::OUString &rPath);
+
+private:
+
+ virtual void Resize ();
+
+ virtual void OnItemDblClicked (ThumbnailViewItem *pRegionItem);
+
+ DECL_LINK(ChangeNameHdl, TemplateView*);
+
+private:
+
+ bool mbFilteredResults; // Flag keep track if overlay has been filtered so folders can get filtered too afterwards
+ FILTER_APPLICATION meFilterOption;
+ SfxDocumentTemplates *mpDocTemplates;
+};
+
+#endif // TEMPLATEFOLDERVIEW_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/inc/sfx2/templatelocalviewitem.hxx b/sfx2/inc/sfx2/templatelocalviewitem.hxx
new file mode 100644
index 0000000..2f75159
--- /dev/null
+++ b/sfx2/inc/sfx2/templatelocalviewitem.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright 2012 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef TEMPLATEFOLDERVIEWITEM_HXX
+#define TEMPLATEFOLDERVIEWITEM_HXX
+
+#include <sfx2/templateproperties.hxx>
+#include <sfx2/thumbnailviewitem.hxx>
+
+class TemplateViewItem;
+
+class TemplateLocalViewItem : public ThumbnailViewItem
+{
+public:
+
+ BitmapEx maPreview2;
+ std::vector<TemplateItemProperties> maTemplates;
+
+ TemplateLocalViewItem (ThumbnailView &rView, Window *pParent);
+
+ virtual ~TemplateLocalViewItem ();
+
+ virtual void calculateItemsPosition (sal_uInt32 nMaxTextLenght);
+
+ const Point& getPrev2Pos () const { return maPrev2Pos; }
+
+ virtual void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
+ const ThumbnailItemAttributes *pAttrs);
+private:
+
+ Point maPrev2Pos;
+};
+
+#endif // TEMPLATEFOLDERVIEWITEM_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx
index bffc83b..406fcb5 100644
--- a/sfx2/inc/templatedlg.hxx
+++ b/sfx2/inc/templatedlg.hxx
@@ -18,7 +18,7 @@
class Edit;
class PopupMenu;
class TemplateAbstractView;
-class TemplateFolderView;
+class TemplateLocalView;
class TemplateOnlineView;
class TemplateSearchView;
class ThumbnailView;
@@ -115,7 +115,7 @@ private:
ToolBox *mpTemplateBar;
TemplateSearchView *mpSearchView;
TemplateAbstractView *mpCurView;
- TemplateFolderView *maView;
+ TemplateLocalView *maView;
TemplateOnlineView *mpOnlineView;
PopupMenu *mpCreateMenu;
PopupMenu *mpActionMenu;
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
deleted file mode 100644
index 30cd5ff..0000000
--- a/sfx2/source/control/templatefolderview.cxx
+++ /dev/null
@@ -1,693 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright 2012 LibreOffice contributors.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include <sfx2/templatefolderview.hxx>
-
-#include <comphelper/processfactory.hxx>
-#include <sfx2/doctempl.hxx>
-#include <sfx2/templateview.hxx>
-#include <sfx2/templateviewitem.hxx>
-#include <sfx2/templatefolderviewitem.hxx>
-#include <svl/inettype.hxx>
-#include <svtools/imagemgr.hxx>
-#include <tools/urlobj.hxx>
-#include <unotools/ucbstreamhelper.hxx>
-#include <vcl/pngread.hxx>
-
-#include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/embed/XStorage.hpp>
-#include <com/sun/star/lang/XComponent.hpp>
-#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 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
-
-void lcl_updateThumbnails (TemplateFolderViewItem *pItem);
-
-// Display template items depending on the generator application
-class ViewFilter_Application
-{
-public:
-
- ViewFilter_Application (SfxDocumentTemplates *pDocTemplates, FILTER_APPLICATION App)
- : mApp(App), mpDocTemplates(pDocTemplates)
- {}
-
- bool operator () (const ThumbnailViewItem *pItem)
- {
- const TemplateViewItem *pTempItem = static_cast<const TemplateViewItem*>(pItem);
-
- if (mApp == FILTER_APP_WRITER)
- {
- return pTempItem->getFileType() == "OpenDocument Text" ||
- pTempItem->getFileType() == "OpenDocument Text Template";
- }
- else if (mApp == FILTER_APP_CALC)
- {
- return pTempItem->getFileType() == "OpenDocument Spreadsheet" ||
- pTempItem->getFileType() == "OpenDocument Spreadsheet Template";
- }
- else if (mApp == FILTER_APP_IMPRESS)
- {
- return pTempItem->getFileType() == "OpenDocument Presentation" ||
- pTempItem->getFileType() == "OpenDocument Presentation Template";
- }
- else if (mApp == FILTER_APP_DRAW)
- {
- return pTempItem->getFileType() == "OpenDocument Drawing" ||
- pTempItem->getFileType() == "OpenDocument Drawing Template";
- }
-
- return true;
- }
-
-private:
-
- FILTER_APPLICATION mApp;
- SfxDocumentTemplates *mpDocTemplates;
-};
-
-class FolderFilter_Application
-{
-public:
-
- FolderFilter_Application (FILTER_APPLICATION eApp)
- : meApp(eApp)
- {
- }
-
- bool operator () (const ThumbnailViewItem *pItem)
- {
- TemplateFolderViewItem *pFolderItem = (TemplateFolderViewItem*)pItem;
-
- std::vector<TemplateItemProperties> &rTemplates = pFolderItem->maTemplates;
-
- size_t nVisCount = 0;
-
- // Clear thumbnails
- pFolderItem->maPreview1.Clear();
- pFolderItem->maPreview2.Clear();
-
- for (size_t i = 0, n = rTemplates.size(); i < n; ++i)
- {
- if (isValid(rTemplates[i].aType))
- {
- ++nVisCount;
-
- // Update the thumbnails
- if (nVisCount == 1)
- pFolderItem->maPreview1 = rTemplates[i].aThumbnail;
- else if (nVisCount == 2)
- pFolderItem->maPreview2 = rTemplates[i].aThumbnail;
- }
- }
-
- return nVisCount;
- }
-
- bool isValid (const rtl::OUString &rType) const
- {
- bool bRet = true;
-
- if (meApp == FILTER_APP_WRITER)
- {
- bRet = rType == "OpenDocument Text" || rType == "OpenDocument Text Template";
- }
- else if (meApp == FILTER_APP_CALC)
- {
- bRet = rType == "OpenDocument Spreadsheet" || rType == "OpenDocument Spreadsheet Template";
- }
- else if (meApp == FILTER_APP_IMPRESS)
- {
- bRet = rType == "OpenDocument Presentation" || rType == "OpenDocument Presentation Template";
- }
- else if (meApp == FILTER_APP_DRAW)
- {
- bRet = rType == "OpenDocument Drawing" || rType == "OpenDocument Drawing Template";
- }
-
- return bRet;
- }
-
-private:
-
- FILTER_APPLICATION meApp;
-};
-
-TemplateFolderView::TemplateFolderView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren)
- : TemplateAbstractView(pParent,rResId,bDisableTransientChildren),
- mbFilteredResults(false),
- meFilterOption(FILTER_APP_NONE),
- mpDocTemplates(new SfxDocumentTemplates)
-{
- Size aViewSize = mpItemView->CalcWindowSizePixel(INIT_VIEW_COLS,INIT_VIEW_LINES,
- ITEM_MAX_WIDTH,ITEM_MAX_HEIGHT,ITEM_SPACE);
-
- mpItemView->SetColor(Color(COL_WHITE));
- mpItemView->SetSizePixel(aViewSize);
- mpItemView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
- ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
- ITEM_PADDING);
-
- mpItemView->setChangeNameHdl(LINK(this,TemplateFolderView,ChangeNameHdl));
-}
-
-TemplateFolderView::~TemplateFolderView()
-{
- delete mpDocTemplates;
-}
-
-void TemplateFolderView::Populate ()
-{
- sal_uInt16 nCount = mpDocTemplates->GetRegionCount();
- for (sal_uInt16 i = 0; i < nCount; ++i)
- {
- rtl::OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
-
- if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
- {
- aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
- aRegionName += "...";
- }
-
- TemplateFolderViewItem* pItem = new TemplateFolderViewItem( *this, this );
- pItem->mnId = i+1;
- pItem->maTitle = aRegionName;
- pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
-
- sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
-
- 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 ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
- {
- aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
- aName += "...";
- }
-
- TemplateItemProperties aProperties;;
- aProperties.nId = j+1;
- aProperties.nRegionId = i;
- aProperties.aName = aName;
- aProperties.aPath = aURL;
- aProperties.aType = aType;
- aProperties.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
-
- pItem->maTemplates.push_back(aProperties);
- }
-
- lcl_updateThumbnails(pItem);
-
- mItemList.push_back(pItem);
- }
-
- CalculateItemPositions();
-
- if ( IsReallyVisible() && IsUpdateMode() )
- Invalidate();
-}
-
-std::vector<rtl::OUString> TemplateFolderView::getFolderNames()
-{
- size_t n = mItemList.size();
- std::vector<rtl::OUString> ret(n);
-
- for (size_t i = 0; i < n; ++i)
- ret[i] = mItemList[i]->maTitle;
-
- return ret;
-}
-
-void TemplateFolderView::showOverlay (bool bVisible)
-{
- mbActive = !bVisible;
- mpItemView->Show(bVisible);
-
- // Clear items is the overlay is closed.
- if (!bVisible)
- {
- // Check if the folder view needs to be filtered
- if (mbFilteredResults)
- {
- filterItems(FolderFilter_Application(meFilterOption));
-
- mbFilteredResults = false;
- meFilterOption = FILTER_APP_NONE;
- }
-
- mpItemView->Clear();
-
- setSelectionMode(mbSelectionMode);
- }
-}
-
-void TemplateFolderView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
-{
- meFilterOption = eApp;
-
- if (mpItemView->IsVisible())
- {
- mbFilteredResults = true;
- mpItemView->filterItems(ViewFilter_Application(mpDocTemplates,eApp));
- }
- else
- {
- filterItems(FolderFilter_Application(eApp));
- }
-}
-
-std::vector<TemplateItemProperties>
-TemplateFolderView::getFilteredItems(const boost::function<bool (const TemplateItemProperties&) > &rFunc) const
-{
- std::vector<TemplateItemProperties> aItems;
-
- for (size_t i = 0; i < mItemList.size(); ++i)
- {
- TemplateFolderViewItem *pFolderItem = static_cast<TemplateFolderViewItem*>(mItemList[i]);
-
- for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j)
- {
- if (rFunc(pFolderItem->maTemplates[j]))
- aItems.push_back(pFolderItem->maTemplates[j]);
- }
- }
-
- return aItems;
-}
-
-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 ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
- {
- aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
- aRegionName += "...";
- }
-
- TemplateFolderViewItem* pItem = new TemplateFolderViewItem( *this, this );
- pItem->mnId = nRegionId+1;
- pItem->maTitle = aRegionName;
- pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
-
- mItemList.push_back(pItem);
-
- CalculateItemPositions();
-
- if ( IsReallyVisible() && IsUpdateMode() )
- Invalidate();
-
- return pItem->mnId;
-}
-
-bool TemplateFolderView::removeRegion(const sal_uInt16 nItemId)
-{
- sal_uInt16 nRegionId = nItemId - 1;
-
- if (!mpDocTemplates->Delete(nRegionId,USHRT_MAX))
- return false;
-
- RemoveItem(nItemId);
-
- return true;
-}
-
-bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId)
-{
- sal_uInt16 nRegionId = nSrcItemId - 1;
- sal_uInt16 nTemplateId = nItemId - 1;
-
- if (!mpDocTemplates->Delete(nRegionId,nTemplateId))
- return false;
-
- for (size_t i = 0, n = mItemList.size(); i < n; ++i)
- {
- if (mItemList[i]->mnId == nSrcItemId)
- {
-
- TemplateFolderViewItem *pItem = static_cast<TemplateFolderViewItem*>(mItemList[i]);
- std::vector<TemplateItemProperties>::iterator pIter;
- for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter)
- {
- if (pIter->nId == nItemId)
- {
- pItem->maTemplates.erase(pIter);
-
- mpItemView->RemoveItem(nItemId);
-
- break;
- }
- }
-
- lcl_updateThumbnails(pItem);
-
- CalculateItemPositions();
-
- break;
- }
- }
-
- return true;
-}
-
-bool TemplateFolderView::moveTemplate (const ThumbnailViewItem *pItem, const sal_uInt16 nSrcItem,
- const sal_uInt16 nTargetItem, bool bCopy)
-{
- bool bRet = true;
- bool bRefresh = false;
-
- TemplateFolderViewItem *pTarget = NULL;
- TemplateFolderViewItem *pSrc = NULL;
-
- for (size_t i = 0, n = mItemList.size(); i < n; ++i)
- {
- if (mItemList[i]->mnId == nTargetItem)
- pTarget = static_cast<TemplateFolderViewItem*>(mItemList[i]);
- else if (mItemList[i]->mnId == nSrcItem)
- pSrc = static_cast<TemplateFolderViewItem*>(mItemList[i]);
- }
-
- if (pTarget && pSrc)
- {
- sal_uInt16 nSrcRegionId = nSrcItem-1;
- sal_uInt16 nTargetRegion = pTarget->mnId-1;
- sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx
-
- const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem);
-
- bool bOK;
-
- if (bCopy)
- bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
- else
- bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
-
- if (!bOK)
- return false;
-
- // move template to destination
-
- TemplateItemProperties aTemplateItem;
- aTemplateItem.nId = nTargetIdx + 1;
- aTemplateItem.nRegionId = nTargetRegion;
- aTemplateItem.aName = pViewItem->maTitle;
- aTemplateItem.aPath = pViewItem->getPath();
- aTemplateItem.aType = pViewItem->getFileType();
- aTemplateItem.aThumbnail = pViewItem->maPreview1;
-
- pTarget->maTemplates.push_back(aTemplateItem);
-
- if (!bCopy)
- {
- // remove template from overlay and from cached data
-
- std::vector<TemplateItemProperties>::iterator aIter;
- for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter)
- {
- if (aIter->nId == pViewItem->mnId)
- {
- pSrc->maTemplates.erase(aIter);
-
- mpItemView->RemoveItem(pViewItem->mnId);
- break;
- }
- }
- }
-
- bRefresh = true;
- }
- else
- bRet = false;
-
- if (bRefresh)
- {
- lcl_updateThumbnails(pSrc);
- lcl_updateThumbnails(pTarget);
-
- CalculateItemPositions();
-
- if (IsReallyVisible() && IsUpdateMode())
- {
- Invalidate();
- mpItemView->Invalidate();
- }
- }
-
- return bRet;
-}
-
-bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems,
- const sal_uInt16 nTargetItem, bool bCopy)
-{
- bool ret = true;
- bool refresh = false;
-
- sal_uInt16 nSrcRegionId = mpItemView->getId();
- sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1;
-
- TemplateFolderViewItem *pTarget = NULL;
- TemplateFolderViewItem *pSrc = NULL;
-
- for (size_t i = 0, n = mItemList.size(); i < n; ++i)
- {
- if (mItemList[i]->mnId == nTargetItem)
- pTarget = static_cast<TemplateFolderViewItem*>(mItemList[i]);
- else if (mItemList[i]->mnId == nSrcRegionItemId)
- pSrc = static_cast<TemplateFolderViewItem*>(mItemList[i]);
- }
-
- if (pTarget && pSrc)
- {
- sal_uInt16 nTargetRegion = pTarget->mnId-1;
- sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx
-
- std::set<const ThumbnailViewItem*>::iterator aSelIter;
- for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx )
- {
- const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
-
- bool bOK;
-
- if (bCopy)
- bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
- else
- bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
-
- if (!bOK)
- {
- ret = false;
- continue;
- }
-
- // move template to destination
-
- TemplateItemProperties aTemplateItem;
- aTemplateItem.nId = nTargetIdx + 1;
- aTemplateItem.nRegionId = nTargetRegion;
- aTemplateItem.aName = pViewItem->maTitle;
- aTemplateItem.aPath = pViewItem->getPath();
- aTemplateItem.aType = pViewItem->getFileType();
- aTemplateItem.aThumbnail = pViewItem->maPreview1;
-
- pTarget->maTemplates.push_back(aTemplateItem);
-
- if (!bCopy)
- {
- // remove template from overlay and from cached data
-
- std::vector<TemplateItemProperties>::iterator pIter;
- for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter)
- {
- if (pIter->nId == pViewItem->mnId)
- {
- pSrc->maTemplates.erase(pIter);
-
- mpItemView->RemoveItem(pViewItem->mnId);
- break;
- }
- }
- }
-
- refresh = true;
- }
- }
- else
- ret = false;
-
- if (refresh)
- {
- lcl_updateThumbnails(pSrc);
- lcl_updateThumbnails(pTarget);
-
- CalculateItemPositions();
-
- Invalidate();
- mpItemView->Invalidate();
- }
-
- return ret;
-}
-
-void TemplateFolderView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail,
- const OUString &rPath)
-{
- sal_uInt16 nId = 0;
- sal_uInt16 nRegionId = nRegionItemId - 1;
-
- if (!mItemList.empty())
- nId = (mItemList.back())->mnId;
-
- String aPath(rPath);
-
- if (mpDocTemplates->CopyFrom(nRegionId,nId,aPath))
- {
- TemplateItemProperties aTemplate;
- aTemplate.nId = nId+1;
- aTemplate.nRegionId = nRegionId;
- aTemplate.aName = aPath;
- aTemplate.aThumbnail = rThumbnail;
- aTemplate.aPath = mpDocTemplates->GetPath(nRegionId,nId);
- aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(aPath));
-
- for (size_t i = 0, n = mItemList.size(); i < n; ++i)
- {
- if (mItemList[i]->mnId == nRegionItemId)
- {
- TemplateFolderViewItem *pItem =
- static_cast<TemplateFolderViewItem*>(mItemList[i]);
-
- pItem->maTemplates.push_back(aTemplate);
-
- lcl_updateThumbnails(pItem);
- }
- }
-
- CalculateItemPositions();
- }
-}
-
-void TemplateFolderView::copyFrom (TemplateFolderViewItem *pItem, const rtl::OUString &rPath)
-{
- sal_uInt16 nId = 0;
- sal_uInt16 nRegionId = pItem->mnId - 1;
- String aPath(rPath);
-
- if (!mItemList.empty())
- nId = (mItemList.back())->mnId+1;
-
- if (mpDocTemplates->CopyFrom(nRegionId,nId,aPath))
- {
- TemplateItemProperties aTemplate;
- aTemplate.nId = nId+1;
- aTemplate.nRegionId = nRegionId;
- aTemplate.aName = mpDocTemplates->GetName(nRegionId,nId);
- aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath,
- THUMBNAIL_MAX_WIDTH,
- THUMBNAIL_MAX_HEIGHT);
- aTemplate.aPath = rPath;
- aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(rPath));
-
- pItem->maTemplates.push_back(aTemplate);
-
- lcl_updateThumbnails(pItem);
-
- CalculateItemPositions();
- }
-}
-
-void TemplateFolderView::Resize()
-{
- Size aWinSize = GetOutputSize();
- Size aViewSize = mpItemView->GetSizePixel();
-
- Point aPos;
- aPos.setX((aWinSize.getWidth() - aViewSize.getWidth())/2);
-
- mpItemView->SetPosPixel(aPos);
-}
-
-void TemplateFolderView::OnItemDblClicked (ThumbnailViewItem *pRegionItem)
-{
- // Fill templates
- sal_uInt16 nRegionId = pRegionItem->mnId-1;
-
- mpItemView->setId(nRegionId);
- mpItemView->setName(mpDocTemplates->GetRegionName(nRegionId));
- mpItemView->InsertItems(static_cast<TemplateFolderViewItem*>(pRegionItem)->maTemplates);
-
- if (mbSelectionMode)
- mpItemView->setSelectionMode(true);
-
- if (meFilterOption != FILTER_APP_NONE)
- mpItemView->filterItems(ViewFilter_Application(mpDocTemplates,meFilterOption));
-
- mbActive = false;
- mpItemView->Show();
-}
-
-IMPL_LINK(TemplateFolderView, ChangeNameHdl, TemplateView*, pView)
-{
- sal_uInt16 nRegionId = pView->getId();
- sal_uInt16 nItemId = nRegionId + 1;
-
- if (!mpDocTemplates->SetName(pView->getName(),nRegionId,USHRT_MAX))
- return false;
-
- for (size_t i = 0; i < mItemList.size(); ++i)
- {
- if (mItemList[i]->mnId == nItemId)
- {
- mItemList[i]->maTitle = pView->getName();
- mItemList[i]->calculateItemsPosition(mpItemAttrs->nMaxTextLenght);
- Invalidate();
- break;
- }
- }
-
- return true;
-}
-
-void lcl_updateThumbnails (TemplateFolderViewItem *pItem)
-{
- // Update folder thumbnails
- for (size_t i = 0, n = pItem->maTemplates.size(); i < 2 && i < n; ++i)
- {
- if (i == 0)
- {
- pItem->maPreview1 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
- THUMBNAIL_MAX_WIDTH*0.75,
- THUMBNAIL_MAX_HEIGHT*0.75);
- }
- else
- {
- pItem->maPreview2 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
- THUMBNAIL_MAX_WIDTH*0.75,
- THUMBNAIL_MAX_HEIGHT*0.75);
- }
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatefolderviewitem.cxx b/sfx2/source/control/templatefolderviewitem.cxx
deleted file mode 100644
index d996c98..0000000
--- a/sfx2/source/control/templatefolderviewitem.cxx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Copyright 2012 LibreOffice contributors.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include <sfx2/templatefolderviewitem.hxx>
-
-#include <basegfx/matrix/b2dhommatrixtools.hxx>
-#include <basegfx/polygon/b2dpolygon.hxx>
-#include <drawinglayer/attribute/fillbitmapattribute.hxx>
-#include <drawinglayer/primitive2d/fillbitmapprimitive2d.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>
-
-using namespace basegfx;
-using namespace basegfx::tools;
-using namespace drawinglayer::attribute;
-using namespace drawinglayer::primitive2d;
-
-TemplateFolderViewItem::TemplateFolderViewItem (ThumbnailView &rView, Window *pParent)
- : ThumbnailViewItem(rView,pParent)
-{
-}
-
-TemplateFolderViewItem::~TemplateFolderViewItem ()
-{
-}
-
-void TemplateFolderViewItem::calculateItemsPosition (sal_uInt32 nMaxTextLenght)
-{
- ThumbnailViewItem::calculateItemsPosition(nMaxTextLenght);
-}
-
-void TemplateFolderViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
- const ThumbnailItemAttributes *pAttrs)
-{
- int nCount = 0;
- int nSeqSize = 3;
-
- if (!maPreview2.IsEmpty())
- ++nSeqSize;
-
- BColor aFillColor = pAttrs->aFillColor;
- Primitive2DSequence aSeq(nSeqSize);
-
- // Draw background
- if ( mbSelected || mbHover )
- aFillColor = pAttrs->aHighlightColor;
-
- aSeq[nCount++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
- B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
- aFillColor));
-
- // Draw thumbnail
- Point aPos = maPrev1Pos;
- Size aImageSize = maPreview1.GetSizePixel();
-
- float fScaleX = 1.0f;
- float fScaleY = 1.0f;
-
- if (!maPreview2.IsEmpty())
- {
- fScaleX = 0.8f;
- fScaleY = 0.8f;
-
- aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
- createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
- FillBitmapAttribute(maPreview2,
- B2DPoint(35,20),
- B2DVector(aImageSize.Width(),aImageSize.Height()),
- false)
- ));
- }
-
- aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
- createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
- FillBitmapAttribute(maPreview1,
- B2DPoint(0,0),
- B2DVector(aImageSize.Width(),aImageSize.Height()),
- false)
- ));
-
- // 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() ) );
-
- pProcessor->process(aSeq);
-
- if (mbMode || mbHover || mbSelected)
- mpSelectBox->Paint(maDrawArea);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-
-
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
new file mode 100644
index 0000000..fa19d54
--- /dev/null
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -0,0 +1,693 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright 2012 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sfx2/templatelocalview.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <sfx2/doctempl.hxx>
+#include <sfx2/templateview.hxx>
+#include <sfx2/templateviewitem.hxx>
+#include <sfx2/templatefolderviewitem.hxx>
+#include <svl/inettype.hxx>
+#include <svtools/imagemgr.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <vcl/pngread.hxx>
+
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#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 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
+
+void lcl_updateThumbnails (TemplateLocalViewItem *pItem);
+
+// Display template items depending on the generator application
+class ViewFilter_Application
+{
+public:
+
+ ViewFilter_Application (SfxDocumentTemplates *pDocTemplates, FILTER_APPLICATION App)
+ : mApp(App), mpDocTemplates(pDocTemplates)
+ {}
+
+ bool operator () (const ThumbnailViewItem *pItem)
+ {
+ const TemplateViewItem *pTempItem = static_cast<const TemplateViewItem*>(pItem);
+
+ if (mApp == FILTER_APP_WRITER)
+ {
+ return pTempItem->getFileType() == "OpenDocument Text" ||
+ pTempItem->getFileType() == "OpenDocument Text Template";
+ }
+ else if (mApp == FILTER_APP_CALC)
+ {
+ return pTempItem->getFileType() == "OpenDocument Spreadsheet" ||
+ pTempItem->getFileType() == "OpenDocument Spreadsheet Template";
+ }
+ else if (mApp == FILTER_APP_IMPRESS)
+ {
+ return pTempItem->getFileType() == "OpenDocument Presentation" ||
+ pTempItem->getFileType() == "OpenDocument Presentation Template";
+ }
+ else if (mApp == FILTER_APP_DRAW)
+ {
+ return pTempItem->getFileType() == "OpenDocument Drawing" ||
+ pTempItem->getFileType() == "OpenDocument Drawing Template";
+ }
+
+ return true;
+ }
+
+private:
+
+ FILTER_APPLICATION mApp;
+ SfxDocumentTemplates *mpDocTemplates;
+};
+
+class FolderFilter_Application
+{
+public:
+
+ FolderFilter_Application (FILTER_APPLICATION eApp)
+ : meApp(eApp)
+ {
+ }
+
+ bool operator () (const ThumbnailViewItem *pItem)
+ {
+ TemplateLocalViewItem *pFolderItem = (TemplateLocalViewItem*)pItem;
+
+ std::vector<TemplateItemProperties> &rTemplates = pFolderItem->maTemplates;
+
+ size_t nVisCount = 0;
+
+ // Clear thumbnails
+ pFolderItem->maPreview1.Clear();
+ pFolderItem->maPreview2.Clear();
+
+ for (size_t i = 0, n = rTemplates.size(); i < n; ++i)
+ {
+ if (isValid(rTemplates[i].aType))
+ {
+ ++nVisCount;
+
+ // Update the thumbnails
+ if (nVisCount == 1)
+ pFolderItem->maPreview1 = rTemplates[i].aThumbnail;
+ else if (nVisCount == 2)
+ pFolderItem->maPreview2 = rTemplates[i].aThumbnail;
+ }
+ }
+
+ return nVisCount;
+ }
+
+ bool isValid (const rtl::OUString &rType) const
+ {
+ bool bRet = true;
+
+ if (meApp == FILTER_APP_WRITER)
+ {
+ bRet = rType == "OpenDocument Text" || rType == "OpenDocument Text Template";
+ }
+ else if (meApp == FILTER_APP_CALC)
+ {
+ bRet = rType == "OpenDocument Spreadsheet" || rType == "OpenDocument Spreadsheet Template";
+ }
+ else if (meApp == FILTER_APP_IMPRESS)
+ {
+ bRet = rType == "OpenDocument Presentation" || rType == "OpenDocument Presentation Template";
+ }
+ else if (meApp == FILTER_APP_DRAW)
+ {
+ bRet = rType == "OpenDocument Drawing" || rType == "OpenDocument Drawing Template";
+ }
+
+ return bRet;
+ }
+
+private:
+
+ FILTER_APPLICATION meApp;
+};
+
+TemplateLocalView::TemplateLocalView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren)
+ : TemplateAbstractView(pParent,rResId,bDisableTransientChildren),
+ mbFilteredResults(false),
+ meFilterOption(FILTER_APP_NONE),
+ mpDocTemplates(new SfxDocumentTemplates)
+{
+ Size aViewSize = mpItemView->CalcWindowSizePixel(INIT_VIEW_COLS,INIT_VIEW_LINES,
+ ITEM_MAX_WIDTH,ITEM_MAX_HEIGHT,ITEM_SPACE);
+
+ mpItemView->SetColor(Color(COL_WHITE));
+ mpItemView->SetSizePixel(aViewSize);
+ mpItemView->setItemDimensions(ITEM_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT,
+ ITEM_MAX_HEIGHT-THUMBNAIL_MAX_HEIGHT,
+ ITEM_PADDING);
+
+ mpItemView->setChangeNameHdl(LINK(this,TemplateLocalView,ChangeNameHdl));
+}
+
+TemplateLocalView::~TemplateLocalView()
+{
+ delete mpDocTemplates;
+}
+
+void TemplateLocalView::Populate ()
+{
+ sal_uInt16 nCount = mpDocTemplates->GetRegionCount();
+ for (sal_uInt16 i = 0; i < nCount; ++i)
+ {
+ rtl::OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
+
+ if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
+ {
+ aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+ aRegionName += "...";
+ }
+
+ TemplateLocalViewItem* pItem = new TemplateLocalViewItem( *this, this );
+ pItem->mnId = i+1;
+ pItem->maTitle = aRegionName;
+ pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
+
+ sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
+
+ 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 ((sal_uInt32)aName.getLength() > mpItemAttrs->nMaxTextLenght)
+ {
+ aName = aName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+ aName += "...";
+ }
+
+ TemplateItemProperties aProperties;;
+ aProperties.nId = j+1;
+ aProperties.nRegionId = i;
+ aProperties.aName = aName;
+ aProperties.aPath = aURL;
+ aProperties.aType = aType;
+ aProperties.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
+
+ pItem->maTemplates.push_back(aProperties);
+ }
+
+ lcl_updateThumbnails(pItem);
+
+ mItemList.push_back(pItem);
+ }
+
+ CalculateItemPositions();
+
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+}
+
+std::vector<rtl::OUString> TemplateLocalView::getFolderNames()
+{
+ size_t n = mItemList.size();
+ std::vector<rtl::OUString> ret(n);
+
+ for (size_t i = 0; i < n; ++i)
+ ret[i] = mItemList[i]->maTitle;
+
+ return ret;
+}
+
+void TemplateLocalView::showOverlay (bool bVisible)
+{
+ mbActive = !bVisible;
+ mpItemView->Show(bVisible);
+
+ // Clear items is the overlay is closed.
+ if (!bVisible)
+ {
+ // Check if the folder view needs to be filtered
+ if (mbFilteredResults)
+ {
+ filterItems(FolderFilter_Application(meFilterOption));
+
+ mbFilteredResults = false;
+ meFilterOption = FILTER_APP_NONE;
+ }
+
+ mpItemView->Clear();
+
+ setSelectionMode(mbSelectionMode);
+ }
+}
+
+void TemplateLocalView::filterTemplatesByApp (const FILTER_APPLICATION &eApp)
+{
+ meFilterOption = eApp;
+
+ if (mpItemView->IsVisible())
+ {
+ mbFilteredResults = true;
+ mpItemView->filterItems(ViewFilter_Application(mpDocTemplates,eApp));
+ }
+ else
+ {
+ filterItems(FolderFilter_Application(eApp));
+ }
+}
+
+std::vector<TemplateItemProperties>
+TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateItemProperties&) > &rFunc) const
+{
+ std::vector<TemplateItemProperties> aItems;
+
+ for (size_t i = 0; i < mItemList.size(); ++i)
+ {
+ TemplateLocalViewItem *pFolderItem = static_cast<TemplateLocalViewItem*>(mItemList[i]);
+
+ for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j)
+ {
+ if (rFunc(pFolderItem->maTemplates[j]))
+ aItems.push_back(pFolderItem->maTemplates[j]);
+ }
+ }
+
+ return aItems;
+}
+
+sal_uInt16 TemplateLocalView::createRegion(const rtl::OUString &rName)
+{
+ sal_uInt16 nRegionId = mpDocTemplates->GetRegionCount(); // Next regionId
+
+ if (!mpDocTemplates->InsertDir(rName,nRegionId))
+ return false;
+
+ rtl::OUString aRegionName = rName;
+
+ if ((sal_uInt32)aRegionName.getLength() > mpItemAttrs->nMaxTextLenght)
+ {
+ aRegionName = aRegionName.copy(0,mpItemAttrs->nMaxTextLenght-3);
+ aRegionName += "...";
+ }
+
+ TemplateLocalViewItem* pItem = new TemplateLocalViewItem( *this, this );
+ pItem->mnId = nRegionId+1;
+ pItem->maTitle = aRegionName;
+ pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
+
+ mItemList.push_back(pItem);
+
+ CalculateItemPositions();
+
+ if ( IsReallyVisible() && IsUpdateMode() )
+ Invalidate();
+
+ return pItem->mnId;
+}
+
+bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId)
+{
+ sal_uInt16 nRegionId = nItemId - 1;
+
+ if (!mpDocTemplates->Delete(nRegionId,USHRT_MAX))
+ return false;
+
+ RemoveItem(nItemId);
+
+ return true;
+}
+
+bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId)
+{
+ sal_uInt16 nRegionId = nSrcItemId - 1;
+ sal_uInt16 nTemplateId = nItemId - 1;
+
+ if (!mpDocTemplates->Delete(nRegionId,nTemplateId))
+ return false;
+
+ for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+ {
+ if (mItemList[i]->mnId == nSrcItemId)
+ {
+
+ TemplateLocalViewItem *pItem = static_cast<TemplateLocalViewItem*>(mItemList[i]);
+ std::vector<TemplateItemProperties>::iterator pIter;
+ for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter)
+ {
+ if (pIter->nId == nItemId)
+ {
+ pItem->maTemplates.erase(pIter);
+
+ mpItemView->RemoveItem(nItemId);
+
+ break;
+ }
+ }
+
+ lcl_updateThumbnails(pItem);
+
+ CalculateItemPositions();
+
+ break;
+ }
+ }
+
+ return true;
+}
+
+bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_uInt16 nSrcItem,
+ const sal_uInt16 nTargetItem, bool bCopy)
+{
+ bool bRet = true;
+ bool bRefresh = false;
+
+ TemplateLocalViewItem *pTarget = NULL;
+ TemplateLocalViewItem *pSrc = NULL;
+
+ for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+ {
+ if (mItemList[i]->mnId == nTargetItem)
+ pTarget = static_cast<TemplateLocalViewItem*>(mItemList[i]);
+ else if (mItemList[i]->mnId == nSrcItem)
+ pSrc = static_cast<TemplateLocalViewItem*>(mItemList[i]);
+ }
+
+ if (pTarget && pSrc)
+ {
+ sal_uInt16 nSrcRegionId = nSrcItem-1;
+ sal_uInt16 nTargetRegion = pTarget->mnId-1;
+ sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx
+
+ const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem);
+
+ bool bOK;
+
+ if (bCopy)
+ bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
+ else
+ bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
+
+ if (!bOK)
+ return false;
+
+ // move template to destination
+
+ TemplateItemProperties aTemplateItem;
+ aTemplateItem.nId = nTargetIdx + 1;
+ aTemplateItem.nRegionId = nTargetRegion;
+ aTemplateItem.aName = pViewItem->maTitle;
+ aTemplateItem.aPath = pViewItem->getPath();
+ aTemplateItem.aType = pViewItem->getFileType();
+ aTemplateItem.aThumbnail = pViewItem->maPreview1;
+
+ pTarget->maTemplates.push_back(aTemplateItem);
+
+ if (!bCopy)
+ {
+ // remove template from overlay and from cached data
+
+ std::vector<TemplateItemProperties>::iterator aIter;
+ for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter)
+ {
+ if (aIter->nId == pViewItem->mnId)
+ {
+ pSrc->maTemplates.erase(aIter);
+
+ mpItemView->RemoveItem(pViewItem->mnId);
+ break;
+ }
+ }
+ }
+
+ bRefresh = true;
+ }
+ else
+ bRet = false;
+
+ if (bRefresh)
+ {
+ lcl_updateThumbnails(pSrc);
+ lcl_updateThumbnails(pTarget);
+
+ CalculateItemPositions();
+
+ if (IsReallyVisible() && IsUpdateMode())
+ {
+ Invalidate();
+ mpItemView->Invalidate();
+ }
+ }
+
+ return bRet;
+}
+
+bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems,
+ const sal_uInt16 nTargetItem, bool bCopy)
+{
+ bool ret = true;
+ bool refresh = false;
+
+ sal_uInt16 nSrcRegionId = mpItemView->getId();
+ sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1;
+
+ TemplateLocalViewItem *pTarget = NULL;
+ TemplateLocalViewItem *pSrc = NULL;
+
+ for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+ {
+ if (mItemList[i]->mnId == nTargetItem)
+ pTarget = static_cast<TemplateLocalViewItem*>(mItemList[i]);
+ else if (mItemList[i]->mnId == nSrcRegionItemId)
+ pSrc = static_cast<TemplateLocalViewItem*>(mItemList[i]);
+ }
+
+ if (pTarget && pSrc)
+ {
+ sal_uInt16 nTargetRegion = pTarget->mnId-1;
+ sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx
+
+ std::set<const ThumbnailViewItem*>::iterator aSelIter;
+ for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx )
+ {
+ const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter);
+
+ bool bOK;
+
+ if (bCopy)
+ bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
+ else
+ bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1);
+
+ if (!bOK)
+ {
+ ret = false;
+ continue;
+ }
+
+ // move template to destination
+
+ TemplateItemProperties aTemplateItem;
+ aTemplateItem.nId = nTargetIdx + 1;
+ aTemplateItem.nRegionId = nTargetRegion;
+ aTemplateItem.aName = pViewItem->maTitle;
+ aTemplateItem.aPath = pViewItem->getPath();
+ aTemplateItem.aType = pViewItem->getFileType();
+ aTemplateItem.aThumbnail = pViewItem->maPreview1;
+
+ pTarget->maTemplates.push_back(aTemplateItem);
+
+ if (!bCopy)
+ {
+ // remove template from overlay and from cached data
+
+ std::vector<TemplateItemProperties>::iterator pIter;
+ for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter)
+ {
+ if (pIter->nId == pViewItem->mnId)
+ {
+ pSrc->maTemplates.erase(pIter);
+
+ mpItemView->RemoveItem(pViewItem->mnId);
+ break;
+ }
+ }
+ }
+
+ refresh = true;
+ }
+ }
+ else
+ ret = false;
+
+ if (refresh)
+ {
+ lcl_updateThumbnails(pSrc);
+ lcl_updateThumbnails(pTarget);
+
+ CalculateItemPositions();
+
+ Invalidate();
+ mpItemView->Invalidate();
+ }
+
+ return ret;
+}
+
+void TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail,
+ const OUString &rPath)
+{
+ sal_uInt16 nId = 0;
+ sal_uInt16 nRegionId = nRegionItemId - 1;
+
+ if (!mItemList.empty())
+ nId = (mItemList.back())->mnId;
+
+ String aPath(rPath);
+
+ if (mpDocTemplates->CopyFrom(nRegionId,nId,aPath))
+ {
+ TemplateItemProperties aTemplate;
+ aTemplate.nId = nId+1;
+ aTemplate.nRegionId = nRegionId;
+ aTemplate.aName = aPath;
+ aTemplate.aThumbnail = rThumbnail;
+ aTemplate.aPath = mpDocTemplates->GetPath(nRegionId,nId);
+ aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(aPath));
+
+ for (size_t i = 0, n = mItemList.size(); i < n; ++i)
+ {
+ if (mItemList[i]->mnId == nRegionItemId)
+ {
+ TemplateLocalViewItem *pItem =
+ static_cast<TemplateLocalViewItem*>(mItemList[i]);
+
+ pItem->maTemplates.push_back(aTemplate);
+
+ lcl_updateThumbnails(pItem);
+ }
+ }
+
+ CalculateItemPositions();
+ }
+}
+
+void TemplateLocalView::copyFrom (TemplateLocalViewItem *pItem, const rtl::OUString &rPath)
+{
+ sal_uInt16 nId = 0;
+ sal_uInt16 nRegionId = pItem->mnId - 1;
+ String aPath(rPath);
+
+ if (!mItemList.empty())
+ nId = (mItemList.back())->mnId+1;
+
+ if (mpDocTemplates->CopyFrom(nRegionId,nId,aPath))
+ {
+ TemplateItemProperties aTemplate;
+ aTemplate.nId = nId+1;
+ aTemplate.nRegionId = nRegionId;
+ aTemplate.aName = mpDocTemplates->GetName(nRegionId,nId);
+ aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath,
+ THUMBNAIL_MAX_WIDTH,
+ THUMBNAIL_MAX_HEIGHT);
+ aTemplate.aPath = rPath;
+ aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(rPath));
+
+ pItem->maTemplates.push_back(aTemplate);
+
+ lcl_updateThumbnails(pItem);
+
+ CalculateItemPositions();
+ }
+}
+
+void TemplateLocalView::Resize()
+{
+ Size aWinSize = GetOutputSize();
+ Size aViewSize = mpItemView->GetSizePixel();
+
+ Point aPos;
+ aPos.setX((aWinSize.getWidth() - aViewSize.getWidth())/2);
+
+ mpItemView->SetPosPixel(aPos);
+}
+
+void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pRegionItem)
+{
+ // Fill templates
+ sal_uInt16 nRegionId = pRegionItem->mnId-1;
+
+ mpItemView->setId(nRegionId);
+ mpItemView->setName(mpDocTemplates->GetRegionName(nRegionId));
+ mpItemView->InsertItems(static_cast<TemplateLocalViewItem*>(pRegionItem)->maTemplates);
+
+ if (mbSelectionMode)
+ mpItemView->setSelectionMode(true);
+
+ if (meFilterOption != FILTER_APP_NONE)
+ mpItemView->filterItems(ViewFilter_Application(mpDocTemplates,meFilterOption));
+
+ mbActive = false;
+ mpItemView->Show();
+}
+
+IMPL_LINK(TemplateLocalView, ChangeNameHdl, TemplateView*, pView)
+{
+ sal_uInt16 nRegionId = pView->getId();
+ sal_uInt16 nItemId = nRegionId + 1;
+
+ if (!mpDocTemplates->SetName(pView->getName(),nRegionId,USHRT_MAX))
+ return false;
+
+ for (size_t i = 0; i < mItemList.size(); ++i)
+ {
+ if (mItemList[i]->mnId == nItemId)
+ {
+ mItemList[i]->maTitle = pView->getName();
+ mItemList[i]->calculateItemsPosition(mpItemAttrs->nMaxTextLenght);
+ Invalidate();
+ break;
+ }
+ }
+
+ return true;
+}
+
+void lcl_updateThumbnails (TemplateLocalViewItem *pItem)
+{
+ // Update folder thumbnails
+ for (size_t i = 0, n = pItem->maTemplates.size(); i < 2 && i < n; ++i)
+ {
+ if (i == 0)
+ {
+ pItem->maPreview1 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
+ THUMBNAIL_MAX_WIDTH*0.75,
+ THUMBNAIL_MAX_HEIGHT*0.75);
+ }
+ else
+ {
+ pItem->maPreview2 = TemplateAbstractView::scaleImg(pItem->maTemplates[i].aThumbnail,
+ THUMBNAIL_MAX_WIDTH*0.75,
+ THUMBNAIL_MAX_HEIGHT*0.75);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/templatelocalviewitem.cxx b/sfx2/source/control/templatelocalviewitem.cxx
new file mode 100644
index 0000000..32f1e2e
--- /dev/null
+++ b/sfx2/source/control/templatelocalviewitem.cxx
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright 2012 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sfx2/templatelocalviewitem.hxx>
+
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <basegfx/polygon/b2dpolygon.hxx>
+#include <drawinglayer/attribute/fillbitmapattribute.hxx>
+#include <drawinglayer/primitive2d/fillbitmapprimitive2d.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>
+
+using namespace basegfx;
+using namespace basegfx::tools;
+using namespace drawinglayer::attribute;
+using namespace drawinglayer::primitive2d;
+
+TemplateLocalViewItem::TemplateLocalViewItem (ThumbnailView &rView, Window *pParent)
+ : ThumbnailViewItem(rView,pParent)
+{
+}
+
+TemplateLocalViewItem::~TemplateLocalViewItem ()
+{
+}
+
+void TemplateLocalViewItem::calculateItemsPosition (sal_uInt32 nMaxTextLenght)
+{
+ ThumbnailViewItem::calculateItemsPosition(nMaxTextLenght);
+}
+
+void TemplateLocalViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
+ const ThumbnailItemAttributes *pAttrs)
+{
+ int nCount = 0;
+ int nSeqSize = 3;
+
+ if (!maPreview2.IsEmpty())
+ ++nSeqSize;
+
+ BColor aFillColor = pAttrs->aFillColor;
+ Primitive2DSequence aSeq(nSeqSize);
+
+ // Draw background
+ if ( mbSelected || mbHover )
+ aFillColor = pAttrs->aHighlightColor;
+
+ aSeq[nCount++] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
+ B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
+ aFillColor));
+
+ // Draw thumbnail
+ Point aPos = maPrev1Pos;
+ Size aImageSize = maPreview1.GetSizePixel();
+
+ float fScaleX = 1.0f;
+ float fScaleY = 1.0f;
+
+ if (!maPreview2.IsEmpty())
+ {
+ fScaleX = 0.8f;
+ fScaleY = 0.8f;
+
+ aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
+ createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
+ FillBitmapAttribute(maPreview2,
+ B2DPoint(35,20),
+ B2DVector(aImageSize.Width(),aImageSize.Height()),
+ false)
+ ));
+ }
+
+ aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D(
+ createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()),
+ FillBitmapAttribute(maPreview1,
+ B2DPoint(0,0),
+ B2DVector(aImageSize.Width(),aImageSize.Height()),
+ false)
+ ));
+
+ // 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() ) );
+
+ pProcessor->process(aSeq);
+
+ if (mbMode || mbHover || mbSelected)
+ mpSelectBox->Paint(maDrawArea);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+
+
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 9d0cd28..f37130e 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -16,8 +16,8 @@
#include <comphelper/processfactory.hxx>
#include <sfx2/filedlghelper.hxx>
#include <sfx2/sfxresid.hxx>
-#include <sfx2/templatefolderview.hxx>
-#include <sfx2/templatefolderviewitem.hxx>
+#include <sfx2/templatelocalview.hxx>
+#include <sfx2/templatelocalviewitem.hxx>
#include <sfx2/templateonlineview.hxx>
#include <sfx2/templateviewitem.hxx>
#include <sfx2/thumbnailviewitem.hxx>
@@ -99,7 +99,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent)
mpActionBar( new ToolBox(this, SfxResId(TBX_ACTION_ACTION))),
mpTemplateBar( new ToolBox(this, SfxResId(TBX_ACTION_TEMPLATES))),
mpSearchView(new TemplateSearchView(this)),
- maView(new TemplateFolderView(this,SfxResId(TEMPLATE_VIEW))),
+ maView(new TemplateLocalView(this,SfxResId(TEMPLATE_VIEW))),
mpOnlineView(new TemplateOnlineView(this, WB_VSCROLL,false)),
mnSelectionCount(0),
mxDesktop(comphelper::getProcessServiceFactory()->createInstance( "com.sun.star.frame.Desktop" ),uno::UNO_QUERY )
@@ -690,7 +690,7 @@ void SfxTemplateManagerDlg::OnTemplateImport ()
std::set<const ThumbnailViewItem*>::const_iterator pIter;
for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter)
{
- TemplateFolderViewItem *pFolder = (TemplateFolderViewItem*)(*pIter);
+ TemplateLocalViewItem *pFolder = (TemplateLocalViewItem*)(*pIter);
for (size_t i = 0, n = aFiles.getLength(); i < n; ++i)
maView->copyFrom(pFolder,aFiles[i]);
commit da501ad185ee35ac85724866035b813fe08d8717
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 29 22:35:50 2012 -0430
Show/Hide template delete action depending on the view.
Change-Id: Ia414e9c2ea8d1944b378e373e77607fad531b45f
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 3b327df..9d0cd28 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -868,6 +868,9 @@ void SfxTemplateManagerDlg::switchMainView(bool bDisplayLocal)
mpViewBar->ShowItem(TBI_TEMPLATE_ONLINE);
mpViewBar->HideItem(TBI_TEMPLATE_LOCAL);
+ // Enable deleting items from the filesystem
+ mpTemplateBar->ShowItem(TBI_TEMPLATE_DELETE);
+
mpOnlineView->Hide();
maView->Show();
}
@@ -878,6 +881,9 @@ void SfxTemplateManagerDlg::switchMainView(bool bDisplayLocal)
mpViewBar->ShowItem(TBI_TEMPLATE_LOCAL);
mpViewBar->HideItem(TBI_TEMPLATE_ONLINE);
+ // Disable deleting items from remote repositories
+ mpTemplateBar->HideItem(TBI_TEMPLATE_DELETE);
+
maView->Hide();
mpOnlineView->Show();
}
commit 250b0c95475aeb4c92b6917894fe5b22e8d18f7c
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 29 21:51:06 2012 -0430
Dont use a hardcode thumbnail maximum size use the define one instead.
Change-Id: Ibe8f72463e542563d796bebe6d117097eff6b79a
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 9a27db6..30cd5ff 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -604,7 +604,9 @@ void TemplateFolderView::copyFrom (TemplateFolderViewItem *pItem, const rtl::OUS
aTemplate.nId = nId+1;
aTemplate.nRegionId = nRegionId;
aTemplate.aName = mpDocTemplates->GetName(nRegionId,nId);
- aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath,128,128);
+ aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath,
+ THUMBNAIL_MAX_WIDTH,
+ THUMBNAIL_MAX_HEIGHT);
aTemplate.aPath = rPath;
aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(rPath));
commit 3011ec0b11c3788cc208b0c54ccd1174790ee1fa
Author: Rafael Dominguez <venccsralph at gmail.com>
Date: Sun Jul 29 21:50:02 2012 -0430
Fix setting corret id for an imported template.
Change-Id: I7f87901732d50a0bec9138d3feaf795d76a16e2a
diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx
index 31d7888..9a27db6 100644
--- a/sfx2/source/control/templatefolderview.cxx
+++ b/sfx2/source/control/templatefolderview.cxx
@@ -601,7 +601,7 @@ void TemplateFolderView::copyFrom (TemplateFolderViewItem *pItem, const rtl::OUS
if (mpDocTemplates->CopyFrom(nRegionId,nId,aPath))
{
TemplateItemProperties aTemplate;
- aTemplate.nId = nId;
+ aTemplate.nId = nId+1;
aTemplate.nRegionId = nRegionId;
aTemplate.aName = mpDocTemplates->GetName(nRegionId,nId);
aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath,128,128);
More information about the Libreoffice-commits
mailing list