From 98ab98b4bef7b4eb0dc392c4f5f7416b1827b4bf Mon Sep 17 00:00:00 2001 From: Akshay Deep Date: Mon, 4 Jul 2016 14:20:34 +0530 Subject: Template Manager: Merge local view and abstract view Change-Id: I789ca15f04d27c1fe1422ff1a81746004b627977 Reviewed-on: https://gerrit.libreoffice.org/26890 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- include/sfx2/templateabstractview.hxx | 154 ----------- include/sfx2/templatedlg.hxx | 5 +- include/sfx2/templatelocalview.hxx | 120 ++++++++- sfx2/Library_sfx.mk | 1 - sfx2/inc/pch/precompiled_sfx.hxx | 1 - sfx2/source/control/recentdocsview.cxx | 2 +- sfx2/source/control/recentdocsviewitem.cxx | 6 +- sfx2/source/control/templateabstractview.cxx | 368 --------------------------- sfx2/source/control/templatelocalview.cxx | 312 ++++++++++++++++++++++- sfx2/source/control/templatesearchview.cxx | 4 +- sfx2/source/dialog/backingwindow.hxx | 2 +- 11 files changed, 431 insertions(+), 544 deletions(-) delete mode 100644 include/sfx2/templateabstractview.hxx delete mode 100644 sfx2/source/control/templateabstractview.cxx diff --git a/include/sfx2/templateabstractview.hxx b/include/sfx2/templateabstractview.hxx deleted file mode 100644 index 9946bcacec9b..000000000000 --- a/include/sfx2/templateabstractview.hxx +++ /dev/null @@ -1,154 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * 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 INCLUDED_SFX2_TEMPLATEABSTRACTVIEW_HXX -#define INCLUDED_SFX2_TEMPLATEABSTRACTVIEW_HXX - -#include -#include -#include -#include - -//template thumbnail item defines -#define TEMPLATE_ITEM_MAX_WIDTH 160 -#define TEMPLATE_ITEM_MAX_HEIGHT 148 -#define TEMPLATE_ITEM_PADDING 5 -#define TEMPLATE_ITEM_MAX_TEXT_LENGTH 20 -#define TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT 96 - -//template thumbnail height with a subtitle -#define TEMPLATE_ITEM_MAX_HEIGHT_SUB 160 - -//template thumbnail image defines -#define TEMPLATE_THUMBNAIL_MAX_HEIGHT TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT - 2*TEMPLATE_ITEM_PADDING -#define TEMPLATE_THUMBNAIL_MAX_WIDTH TEMPLATE_ITEM_MAX_WIDTH - 2*TEMPLATE_ITEM_PADDING - -class SfxDocumentTemplates; -class TemplateViewItem; -class TemplateContainerItem; - -enum class FILTER_APPLICATION -{ - NONE, - WRITER, - CALC, - IMPRESS, - DRAW -}; - -// Display template items depending on the generator application -class ViewFilter_Application -{ -public: - - ViewFilter_Application (FILTER_APPLICATION App) - : mApp(App) - {} - - virtual ~ViewFilter_Application () {} - - bool operator () (const ThumbnailViewItem *pItem); - - static bool isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt); - bool isValid (const OUString& rPath) const; - -protected: - - FILTER_APPLICATION mApp; -}; - -class SFX2_DLLPUBLIC TemplateAbstractView : public ThumbnailView -{ -public: - - TemplateAbstractView(vcl::Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren); - TemplateAbstractView(vcl::Window* pParent); - - virtual ~TemplateAbstractView(); - virtual void dispose() override; - - // Fill view with new item list - void insertItems (const std::vector &rTemplates, bool isRegionSelected = true, bool bShowCategoryInTooltip = false); - - // Fill view with template folders thumbnails - virtual void Populate () { } - - virtual void reload () { } - - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; - - virtual void Command( const CommandEvent& rCEvt ) override; - - virtual void KeyInput( const KeyEvent& rKEvt ) override; - - virtual void showAllTemplates () = 0; - - virtual void showRegion (TemplateContainerItem *pItem) = 0; - - virtual sal_uInt16 createRegion (const OUString &rName) = 0; - - sal_uInt16 getCurRegionId () const { return mnCurRegionId;} - - const OUString& getCurRegionName () const { return maCurRegionName;} - - void setOpenRegionHdl(const Link &rLink); - - void setCreateContextMenuHdl(const Link &rLink); - - void setOpenTemplateHdl(const Link &rLink); - - void setEditTemplateHdl(const Link &rLink); - - void setDeleteTemplateHdl(const Link &rLink); - - void setDefaultTemplateHdl(const Link &rLink); - - void updateThumbnailDimensions(long itemMaxSize); - - long getThumbnailWidth() const { return mnThumbnailWidth;} - long getThumbnailHeight() const {return mnThumbnailHeight;} - - void RemoveDefaultTemplateIcon( const OUString& rPath); - - static BitmapEx scaleImg (const BitmapEx &rImg, long width, long height); - - static BitmapEx getDefaultThumbnail( const OUString& rPath ); - - static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height); - -protected: - - virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override; - -public: - static bool IsDefaultTemplate(const OUString& rPath); - -protected: - - sal_uInt16 mnCurRegionId; - OUString maCurRegionName; - - TemplateViewItem *maSelectedItem; - - long mnThumbnailWidth; - long mnThumbnailHeight; - - Point maPosition; - - Link maOpenRegionHdl; - Link maCreateContextMenuHdl; - Link maOpenTemplateHdl; - Link maEditTemplateHdl; - Link maDeleteTemplateHdl; - Link maDefaultTemplateHdl; -}; - -#endif // INCLUDED_SFX2_TEMPLATEABSTRACTVIEW_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx index 765c959c153b..6962b5917c05 100644 --- a/include/sfx2/templatedlg.hxx +++ b/include/sfx2/templatedlg.hxx @@ -17,13 +17,14 @@ #include #include +#include #include -#include +#include class Edit; class PopupMenu; -class TemplateAbstractView; +class TemplateLocalView; class TemplateLocalView; class TemplateSearchView; class ThumbnailView; diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx index 735e897f7721..3db83979706a 100644 --- a/include/sfx2/templatelocalview.hxx +++ b/include/sfx2/templatelocalview.hxx @@ -12,11 +12,27 @@ #include #include +#include +#include +#include -#include +//template thumbnail item defines +#define TEMPLATE_ITEM_MAX_WIDTH 160 +#define TEMPLATE_ITEM_MAX_HEIGHT 148 +#define TEMPLATE_ITEM_PADDING 5 +#define TEMPLATE_ITEM_MAX_TEXT_LENGTH 20 +#define TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT 96 + +//template thumbnail height with a subtitle +#define TEMPLATE_ITEM_MAX_HEIGHT_SUB 160 + +//template thumbnail image defines +#define TEMPLATE_THUMBNAIL_MAX_HEIGHT TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT - 2*TEMPLATE_ITEM_PADDING +#define TEMPLATE_THUMBNAIL_MAX_WIDTH TEMPLATE_ITEM_MAX_WIDTH - 2*TEMPLATE_ITEM_PADDING class SfxDocumentTemplates; class TemplateContainerItem; +class TemplateViewItem; class PopupMenu; namespace com { @@ -25,7 +41,38 @@ namespace com { } } } } -class SFX2_DLLPUBLIC TemplateLocalView : public TemplateAbstractView +enum class FILTER_APPLICATION +{ + NONE, + WRITER, + CALC, + IMPRESS, + DRAW +}; + +// Display template items depending on the generator application +class ViewFilter_Application +{ +public: + + ViewFilter_Application (FILTER_APPLICATION App) + : mApp(App) + {} + + virtual ~ViewFilter_Application () {} + + bool operator () (const ThumbnailViewItem *pItem); + + static bool isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt); + bool isValid (const OUString& rPath) const; + +protected: + + FILTER_APPLICATION mApp; +}; + + +class SFX2_DLLPUBLIC TemplateLocalView : public ThumbnailView { typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*); @@ -36,14 +83,17 @@ public: virtual ~TemplateLocalView (); virtual void dispose() override; + // Fill view with new item list + void insertItems (const std::vector &rTemplates, bool isRegionSelected = true, bool bShowCategoryInTooltip = false); + // Fill view with template folders thumbnails - virtual void Populate () override; + virtual void Populate (); - virtual void reload () override; + virtual void reload (); - virtual void showAllTemplates () override; + virtual void showAllTemplates (); - virtual void showRegion (TemplateContainerItem *pItem) override; + virtual void showRegion (TemplateContainerItem *pItem); void showRegion (const OUString &rName); @@ -66,7 +116,7 @@ public: std::vector getFilteredItems (const std::function &rFunc) const; - virtual sal_uInt16 createRegion (const OUString &rName) override; + virtual sal_uInt16 createRegion (const OUString &rName); bool renameRegion(const OUString &rTitle, const OUString &rNewTitle); @@ -87,7 +137,63 @@ public: virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle) override; + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + + virtual void Command( const CommandEvent& rCEvt ) override; + + virtual void KeyInput( const KeyEvent& rKEvt ) override; + + sal_uInt16 getCurRegionId () const { return mnCurRegionId;} + + const OUString& getCurRegionName () const { return maCurRegionName;} + + void setOpenRegionHdl(const Link &rLink); + + void setCreateContextMenuHdl(const Link &rLink); + + void setOpenTemplateHdl(const Link &rLink); + + void setEditTemplateHdl(const Link &rLink); + + void setDeleteTemplateHdl(const Link &rLink); + + void setDefaultTemplateHdl(const Link &rLink); + + void updateThumbnailDimensions(long itemMaxSize); + + long getThumbnailWidth() const { return mnThumbnailWidth;} + long getThumbnailHeight() const {return mnThumbnailHeight;} + + void RemoveDefaultTemplateIcon( const OUString& rPath); + + static BitmapEx scaleImg (const BitmapEx &rImg, long width, long height); + + static BitmapEx getDefaultThumbnail( const OUString& rPath ); + + static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height); + + static bool IsDefaultTemplate(const OUString& rPath); + +protected: + virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override; + protected: + sal_uInt16 mnCurRegionId; + OUString maCurRegionName; + + TemplateViewItem *maSelectedItem; + + long mnThumbnailWidth; + long mnThumbnailHeight; + + Point maPosition; //store the point of click event + + Link maOpenRegionHdl; + Link maCreateContextMenuHdl; + Link maOpenTemplateHdl; + Link maEditTemplateHdl; + Link maDeleteTemplateHdl; + Link maDefaultTemplateHdl; SfxDocumentTemplates *mpDocTemplates; std::vector maRegions; diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index ad58c6f5f94c..0b77f45d62b7 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -150,7 +150,6 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/shell \ sfx2/source/control/sorgitm \ sfx2/source/control/statcach \ - sfx2/source/control/templateabstractview \ sfx2/source/control/templatedefaultview \ sfx2/source/control/templateviewitem \ sfx2/source/control/templatelocalview \ diff --git a/sfx2/inc/pch/precompiled_sfx.hxx b/sfx2/inc/pch/precompiled_sfx.hxx index 694aaa1a3b1c..d80b88a71aea 100644 --- a/sfx2/inc/pch/precompiled_sfx.hxx +++ b/sfx2/inc/pch/precompiled_sfx.hxx @@ -511,7 +511,6 @@ #include #include #include -#include #include #include #include diff --git a/sfx2/source/control/recentdocsview.cxx b/sfx2/source/control/recentdocsview.cxx index d30380156801..8dfa4e545669 100644 --- a/sfx2/source/control/recentdocsview.cxx +++ b/sfx2/source/control/recentdocsview.cxx @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include diff --git a/sfx2/source/control/recentdocsviewitem.cxx b/sfx2/source/control/recentdocsviewitem.cxx index 0d353700bd7c..fa1392d3a67d 100644 --- a/sfx2/source/control/recentdocsviewitem.cxx +++ b/sfx2/source/control/recentdocsviewitem.cxx @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -83,7 +83,7 @@ RecentDocsViewItem::RecentDocsViewItem(ThumbnailView &rView, const OUString &rUR if (aExtSize.Width() > aThumbnailSize.Width() || aExtSize.Height() > aThumbnailSize.Height()) { - aExt = TemplateAbstractView::scaleImg(aExt, aThumbnailSize.Width(), aThumbnailSize.Height()); + aExt = TemplateLocalView::scaleImg(aExt, aThumbnailSize.Width(), aThumbnailSize.Height()); aExtSize = aExt.GetSizePixel(); } @@ -98,7 +98,7 @@ RecentDocsViewItem::RecentDocsViewItem(ThumbnailView &rView, const OUString &rUR } maTitle = aTitle; - maPreview1 = TemplateAbstractView::scaleImg(aThumbnail, nThumbnailSize, nThumbnailSize); + maPreview1 = TemplateLocalView::scaleImg(aThumbnail, nThumbnailSize, nThumbnailSize); } Rectangle RecentDocsViewItem::updateHighlight(bool bVisible, const Point& rPoint) diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx deleted file mode 100644 index 0067c3dc63a3..000000000000 --- a/sfx2/source/control/templateabstractview.cxx +++ /dev/null @@ -1,368 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * 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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "../doc/doc.hrc" -#include "templateview.hrc" - -using namespace basegfx; -using namespace drawinglayer::primitive2d; -using namespace ::com::sun::star::uno; - -bool ViewFilter_Application::isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt) -{ - bool bRet = true; - - if (filter == FILTER_APPLICATION::WRITER) - { - bRet = rExt == "ott" || rExt == "stw" || rExt == "oth" || rExt == "dot" || rExt == "dotx" || rExt == "otm"; - } - else if (filter == FILTER_APPLICATION::CALC) - { - bRet = rExt == "ots" || rExt == "stc" || rExt == "xlt" || rExt == "xltm" || rExt == "xltx"; - } - else if (filter == FILTER_APPLICATION::IMPRESS) - { - bRet = rExt == "otp" || rExt == "sti" || rExt == "pot" || rExt == "potm" || rExt == "potx"; - } - else if (filter == FILTER_APPLICATION::DRAW) - { - bRet = rExt == "otg" || rExt == "std"; - } - - return bRet; -} - -bool ViewFilter_Application::isValid (const OUString &rPath) const -{ - INetURLObject aUrl(rPath); - return isFilteredExtension(mApp, aUrl.getExtension()); -} - -bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem) -{ - const TemplateViewItem *pTempItem = dynamic_cast(pItem); - if (pTempItem) - return isValid(pTempItem->getPath()); - - return true; -} - -TemplateAbstractView::TemplateAbstractView (vcl::Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren) - : ThumbnailView(pParent,nWinStyle,bDisableTransientChildren), - mnCurRegionId(0), - maSelectedItem(nullptr), - mnThumbnailWidth(TEMPLATE_THUMBNAIL_MAX_WIDTH), - mnThumbnailHeight(TEMPLATE_THUMBNAIL_MAX_HEIGHT), - maPosition(0,0) -{ -} - -TemplateAbstractView::TemplateAbstractView(vcl::Window *pParent) - : ThumbnailView(pParent), - mnCurRegionId(0), - maSelectedItem(nullptr), - mnThumbnailWidth(TEMPLATE_THUMBNAIL_MAX_WIDTH), - mnThumbnailHeight(TEMPLATE_THUMBNAIL_MAX_HEIGHT), - maPosition(0,0) -{ -} - -TemplateAbstractView::~TemplateAbstractView() -{ - disposeOnce(); -} - -void TemplateAbstractView::dispose() -{ - ThumbnailView::dispose(); -} - -void TemplateAbstractView::insertItems(const std::vector &rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip) -{ - mItemList.clear(); - - std::vector aItems(rTemplates.size()); - for (size_t i = 0, n = rTemplates.size(); i < n; ++i ) - { - const TemplateItemProperties *pCur = &rTemplates[i]; - - TemplateViewItem *pChild; - if(isRegionSelected) - pChild = new TemplateViewItem(*this, pCur->nId); - else - pChild = new TemplateViewItem(*this, i+1); - - pChild->mnDocId = pCur->nDocId; - pChild->mnRegionId = pCur->nRegionId; - pChild->maTitle = pCur->aName; - pChild->setPath(pCur->aPath); - - if(!bShowCategoryInTooltip) - pChild->setHelpText(pCur->aName); - else - { - OUString sHelpText = SfxResId(STR_TEMPLATE_TOOLTIP).toString(); - sHelpText = (sHelpText.replaceFirst("$1", pCur->aName)).replaceFirst("$2", pCur->aRegionName); - pChild->setHelpText(sHelpText); - } - - pChild->maPreview1 = pCur->aThumbnail; - - if(IsDefaultTemplate(pCur->aPath)) - pChild->showDefaultIcon(true); - - if ( pCur->aThumbnail.IsEmpty() ) - { - // Use the default thumbnail if we have nothing else - pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath); - } - - aItems[i] = pChild; - } - - updateItems(aItems); -} - -void TemplateAbstractView::updateThumbnailDimensions(long itemMaxSize) -{ - mnThumbnailWidth = itemMaxSize; - mnThumbnailHeight = itemMaxSize; -} - - -void TemplateAbstractView::MouseButtonDown( const MouseEvent& rMEvt ) -{ - GrabFocus(); - ThumbnailView::MouseButtonDown(rMEvt); -} - -void TemplateAbstractView::Command( const CommandEvent& rCEvt ) -{ - if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) - { - if(rCEvt.IsMouseEvent()) - { - deselectItems(); - size_t nPos = ImplGetItem(rCEvt.GetMousePosPixel()); - Point aPosition (rCEvt.GetMousePosPixel()); - maPosition = aPosition; - ThumbnailViewItem* pItem = ImplGetItem(nPos); - const TemplateViewItem *pViewItem = dynamic_cast(pItem); - - if(pViewItem) - { - maSelectedItem = dynamic_cast(pItem); - maCreateContextMenuHdl.Call(pItem); - } - } - else - { - for (ThumbnailViewItem* pItem : mFilteredItemList) - { - //create context menu for the first selected item - if (pItem->isSelected()) - { - deselectItems(); - pItem->setSelection(true); - maItemStateHdl.Call(pItem); - Rectangle aRect = pItem->getDrawArea(); - maPosition = aRect.Center(); - maSelectedItem = dynamic_cast(pItem); - maCreateContextMenuHdl.Call(pItem); - break; - } - } - } - } - - ThumbnailView::Command(rCEvt); -} - -void TemplateAbstractView::KeyInput( const KeyEvent& rKEvt ) -{ - vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); - - if(aKeyCode == ( KEY_MOD1 | KEY_A ) ) - { - for (ThumbnailViewItem* pItem : mFilteredItemList) - { - if (!pItem->isSelected()) - { - pItem->setSelection(true); - maItemStateHdl.Call(pItem); - } - } - - if (IsReallyVisible() && IsUpdateMode()) - Invalidate(); - return; - } - else if( aKeyCode == KEY_DELETE && !mFilteredItemList.empty()) - { - ScopedVclPtrInstance< MessageDialog > aQueryDlg(this, SfxResId(STR_QMSG_SEL_TEMPLATE_DELETE), VclMessageType::Question, VCL_BUTTONS_YES_NO); - - if ( aQueryDlg->Execute() != RET_YES ) - return; - - //copy to avoid changing filtered item list during deletion - ThumbnailValueItemList mFilteredItemListCopy = mFilteredItemList; - - for (ThumbnailViewItem* pItem : mFilteredItemListCopy) - { - if (pItem->isSelected()) - { - maDeleteTemplateHdl.Call(pItem); - } - } - reload(); - } - - ThumbnailView::KeyInput(rKEvt); -} - - -void TemplateAbstractView::setOpenRegionHdl(const Link &rLink) -{ - maOpenRegionHdl = rLink; -} - -void TemplateAbstractView::setCreateContextMenuHdl(const Link &rLink) -{ - maCreateContextMenuHdl = rLink; -} - -void TemplateAbstractView::setOpenTemplateHdl(const Link &rLink) -{ - maOpenTemplateHdl = rLink; -} - -void TemplateAbstractView::setEditTemplateHdl(const Link &rLink) -{ - maEditTemplateHdl = rLink; -} - -void TemplateAbstractView::setDeleteTemplateHdl(const Link &rLink) -{ - maDeleteTemplateHdl = rLink; -} - -void TemplateAbstractView::setDefaultTemplateHdl(const Link &rLink) -{ - maDefaultTemplateHdl = rLink; -} - -BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long height) -{ - BitmapEx aImg = rImg; - - if (!rImg.IsEmpty()) - { - Size aSize = rImg.GetSizePixel(); - - if (aSize.Width() == 0) - aSize.Width() = 1; - - if (aSize.Height() == 0) - aSize.Height() = 1; - - // make the picture fit the given width/height constraints - double nRatio = std::min(double(width)/double(aSize.Width()), double(height)/double(aSize.Height())); - - aImg.Scale(Size(aSize.Width() * nRatio, aSize.Height() * nRatio)); - } - - return aImg; -} - -bool TemplateAbstractView::IsDefaultTemplate(const OUString& rPath) -{ - SvtModuleOptions aModOpt; - const css::uno::Sequence &aServiceNames = aModOpt.GetAllServiceNames(); - - for( sal_Int32 i=0, nCount = aServiceNames.getLength(); i < nCount; ++i ) - { - const OUString defaultPath = SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ); - if(defaultPath.match(rPath)) - return true; - } - - return false; -} - -void TemplateAbstractView::RemoveDefaultTemplateIcon(const OUString& rPath) -{ - for (ThumbnailViewItem* pItem : mItemList) - { - TemplateViewItem* pViewItem = dynamic_cast(pItem); - if (pViewItem && pViewItem->getPath().match(rPath)) - { - pViewItem->showDefaultIcon(false); - Invalidate(); - return; - } - } -} - -BitmapEx TemplateAbstractView::getDefaultThumbnail( const OUString& rPath ) -{ - BitmapEx aImg; - INetURLObject aUrl(rPath); - OUString aExt = aUrl.getExtension(); - - if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::WRITER, aExt) ) - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) ); - else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::CALC, aExt) ) - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) ); - else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::IMPRESS, aExt) ) - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) ); - else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::DRAW, aExt) ) - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) ); - - return aImg; -} - -BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width, long height) -{ - return TemplateAbstractView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height); -} - -void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem) -{ - TemplateViewItem* pViewItem = dynamic_cast(pItem); - - if( pViewItem ) - maOpenTemplateHdl.Call(pViewItem); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 0ecd166034d5..3ad5d07f87a7 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -16,9 +16,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -32,6 +34,7 @@ #include #include "../doc/doc.hrc" +#include "templateview.hrc" #define MNI_OPEN 1 #define MNI_EDIT 2 @@ -42,8 +45,52 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::frame; +bool ViewFilter_Application::isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt) +{ + bool bRet = true; + + if (filter == FILTER_APPLICATION::WRITER) + { + bRet = rExt == "ott" || rExt == "stw" || rExt == "oth" || rExt == "dot" || rExt == "dotx" || rExt == "otm"; + } + else if (filter == FILTER_APPLICATION::CALC) + { + bRet = rExt == "ots" || rExt == "stc" || rExt == "xlt" || rExt == "xltm" || rExt == "xltx"; + } + else if (filter == FILTER_APPLICATION::IMPRESS) + { + bRet = rExt == "otp" || rExt == "sti" || rExt == "pot" || rExt == "potm" || rExt == "potx"; + } + else if (filter == FILTER_APPLICATION::DRAW) + { + bRet = rExt == "otg" || rExt == "std"; + } + + return bRet; +} + +bool ViewFilter_Application::isValid (const OUString &rPath) const +{ + INetURLObject aUrl(rPath); + return isFilteredExtension(mApp, aUrl.getExtension()); +} + +bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem) +{ + const TemplateViewItem *pTempItem = dynamic_cast(pItem); + if (pTempItem) + return isValid(pTempItem->getPath()); + + return true; +} + TemplateLocalView::TemplateLocalView ( vcl::Window* pParent) - : TemplateAbstractView(pParent), + : ThumbnailView(pParent), + mnCurRegionId(0), + maSelectedItem(nullptr), + mnThumbnailWidth(TEMPLATE_THUMBNAIL_MAX_WIDTH), + mnThumbnailHeight(TEMPLATE_THUMBNAIL_MAX_HEIGHT), + maPosition(0,0), mpDocTemplates(new SfxDocumentTemplates) { } @@ -65,7 +112,7 @@ void TemplateLocalView::dispose() maAllTemplates.clear(); delete mpDocTemplates; - TemplateAbstractView::dispose(); + ThumbnailView::dispose(); } void TemplateLocalView::Populate () @@ -100,7 +147,7 @@ void TemplateLocalView::Populate () aProperties.aName = aName; aProperties.aPath = aURL; aProperties.aRegionName = aRegionName; - aProperties.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL, + aProperties.aThumbnail = TemplateLocalView::fetchThumbnail(aURL, getThumbnailWidth(), getThumbnailHeight()); @@ -717,7 +764,7 @@ bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString & aTemplate.nDocId = nDocId; aTemplate.nRegionId = nRegionId; aTemplate.aName = aPath; - aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath, + aTemplate.aThumbnail = TemplateLocalView::fetchThumbnail(rPath, TEMPLATE_THUMBNAIL_MAX_WIDTH, TEMPLATE_THUMBNAIL_MAX_HEIGHT); aTemplate.aPath = rPath; @@ -773,4 +820,261 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNe return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId ); } +void TemplateLocalView::insertItems(const std::vector &rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip) +{ + mItemList.clear(); + + std::vector aItems(rTemplates.size()); + for (size_t i = 0, n = rTemplates.size(); i < n; ++i ) + { + const TemplateItemProperties *pCur = &rTemplates[i]; + + TemplateViewItem *pChild; + if(isRegionSelected) + pChild = new TemplateViewItem(*this, pCur->nId); + else + pChild = new TemplateViewItem(*this, i+1); + + pChild->mnDocId = pCur->nDocId; + pChild->mnRegionId = pCur->nRegionId; + pChild->maTitle = pCur->aName; + pChild->setPath(pCur->aPath); + + if(!bShowCategoryInTooltip) + pChild->setHelpText(pCur->aName); + else + { + OUString sHelpText = SfxResId(STR_TEMPLATE_TOOLTIP).toString(); + sHelpText = (sHelpText.replaceFirst("$1", pCur->aName)).replaceFirst("$2", pCur->aRegionName); + pChild->setHelpText(sHelpText); + } + + pChild->maPreview1 = pCur->aThumbnail; + + if(IsDefaultTemplate(pCur->aPath)) + pChild->showDefaultIcon(true); + + if ( pCur->aThumbnail.IsEmpty() ) + { + // Use the default thumbnail if we have nothing else + pChild->maPreview1 = TemplateLocalView::getDefaultThumbnail(pCur->aPath); + } + + aItems[i] = pChild; + } + + updateItems(aItems); +} + +void TemplateLocalView::updateThumbnailDimensions(long itemMaxSize) +{ + mnThumbnailWidth = itemMaxSize; + mnThumbnailHeight = itemMaxSize; +} + + +void TemplateLocalView::MouseButtonDown( const MouseEvent& rMEvt ) +{ + GrabFocus(); + ThumbnailView::MouseButtonDown(rMEvt); +} + +void TemplateLocalView::Command( const CommandEvent& rCEvt ) +{ + if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) + { + if(rCEvt.IsMouseEvent()) + { + deselectItems(); + size_t nPos = ImplGetItem(rCEvt.GetMousePosPixel()); + Point aPosition (rCEvt.GetMousePosPixel()); + maPosition = aPosition; + ThumbnailViewItem* pItem = ImplGetItem(nPos); + const TemplateViewItem *pViewItem = dynamic_cast(pItem); + + if(pViewItem) + { + maSelectedItem = dynamic_cast(pItem); + maCreateContextMenuHdl.Call(pItem); + } + } + else + { + for (ThumbnailViewItem* pItem : mFilteredItemList) + { + //create context menu for the first selected item + if (pItem->isSelected()) + { + deselectItems(); + pItem->setSelection(true); + maItemStateHdl.Call(pItem); + Rectangle aRect = pItem->getDrawArea(); + maPosition = aRect.Center(); + maSelectedItem = dynamic_cast(pItem); + maCreateContextMenuHdl.Call(pItem); + break; + } + } + } + } + + ThumbnailView::Command(rCEvt); +} + +void TemplateLocalView::KeyInput( const KeyEvent& rKEvt ) +{ + vcl::KeyCode aKeyCode = rKEvt.GetKeyCode(); + + if(aKeyCode == ( KEY_MOD1 | KEY_A ) ) + { + for (ThumbnailViewItem* pItem : mFilteredItemList) + { + if (!pItem->isSelected()) + { + pItem->setSelection(true); + maItemStateHdl.Call(pItem); + } + } + + if (IsReallyVisible() && IsUpdateMode()) + Invalidate(); + return; + } + else if( aKeyCode == KEY_DELETE && !mFilteredItemList.empty()) + { + ScopedVclPtrInstance< MessageDialog > aQueryDlg(this, SfxResId(STR_QMSG_SEL_TEMPLATE_DELETE), VclMessageType::Question, VCL_BUTTONS_YES_NO); + + if ( aQueryDlg->Execute() != RET_YES ) + return; + + //copy to avoid changing filtered item list during deletion + ThumbnailValueItemList mFilteredItemListCopy = mFilteredItemList; + + for (ThumbnailViewItem* pItem : mFilteredItemListCopy) + { + if (pItem->isSelected()) + { + maDeleteTemplateHdl.Call(pItem); + } + } + reload(); + } + + ThumbnailView::KeyInput(rKEvt); +} + + +void TemplateLocalView::setOpenRegionHdl(const Link &rLink) +{ + maOpenRegionHdl = rLink; +} + +void TemplateLocalView::setCreateContextMenuHdl(const Link &rLink) +{ + maCreateContextMenuHdl = rLink; +} + +void TemplateLocalView::setOpenTemplateHdl(const Link &rLink) +{ + maOpenTemplateHdl = rLink; +} + +void TemplateLocalView::setEditTemplateHdl(const Link &rLink) +{ + maEditTemplateHdl = rLink; +} + +void TemplateLocalView::setDeleteTemplateHdl(const Link &rLink) +{ + maDeleteTemplateHdl = rLink; +} + +void TemplateLocalView::setDefaultTemplateHdl(const Link &rLink) +{ + maDefaultTemplateHdl = rLink; +} + +BitmapEx TemplateLocalView::scaleImg (const BitmapEx &rImg, long width, long height) +{ + BitmapEx aImg = rImg; + + if (!rImg.IsEmpty()) + { + Size aSize = rImg.GetSizePixel(); + + if (aSize.Width() == 0) + aSize.Width() = 1; + + if (aSize.Height() == 0) + aSize.Height() = 1; + + // make the picture fit the given width/height constraints + double nRatio = std::min(double(width)/double(aSize.Width()), double(height)/double(aSize.Height())); + + aImg.Scale(Size(aSize.Width() * nRatio, aSize.Height() * nRatio)); + } + + return aImg; +} + +bool TemplateLocalView::IsDefaultTemplate(const OUString& rPath) +{ + SvtModuleOptions aModOpt; + const css::uno::Sequence &aServiceNames = aModOpt.GetAllServiceNames(); + + for( sal_Int32 i=0, nCount = aServiceNames.getLength(); i < nCount; ++i ) + { + const OUString defaultPath = SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ); + if(defaultPath.match(rPath)) + return true; + } + + return false; +} + +void TemplateLocalView::RemoveDefaultTemplateIcon(const OUString& rPath) +{ + for (ThumbnailViewItem* pItem : mItemList) + { + TemplateViewItem* pViewItem = dynamic_cast(pItem); + if (pViewItem && pViewItem->getPath().match(rPath)) + { + pViewItem->showDefaultIcon(false); + Invalidate(); + return; + } + } +} + +BitmapEx TemplateLocalView::getDefaultThumbnail( const OUString& rPath ) +{ + BitmapEx aImg; + INetURLObject aUrl(rPath); + OUString aExt = aUrl.getExtension(); + + if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::WRITER, aExt) ) + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) ); + else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::CALC, aExt) ) + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) ); + else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::IMPRESS, aExt) ) + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) ); + else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::DRAW, aExt) ) + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) ); + + return aImg; +} + +BitmapEx TemplateLocalView::fetchThumbnail (const OUString &msURL, long width, long height) +{ + return TemplateLocalView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height); +} + +void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pItem) +{ + TemplateViewItem* pViewItem = dynamic_cast(pItem); + + if( pViewItem ) + maOpenTemplateHdl.Call(pViewItem); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx index 39672043a86c..d86172ccf96d 100644 --- a/sfx2/source/control/templatesearchview.cxx +++ b/sfx2/source/control/templatesearchview.cxx @@ -9,7 +9,7 @@ #include "templatesearchview.hxx" #include "templatesearchviewitem.hxx" -#include +#include #include #include #include @@ -227,7 +227,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI pItem->setHelpText(rSubtitle); pItem->setPath(rPath); - if(TemplateAbstractView::IsDefaultTemplate(rPath)) + if(TemplateLocalView::IsDefaultTemplate(rPath)) pItem->showDefaultIcon(true); ThumbnailView::AppendItem(pItem); diff --git a/sfx2/source/dialog/backingwindow.hxx b/sfx2/source/dialog/backingwindow.hxx index 499d8b3dc367..abb68e9c765b 100644 --- a/sfx2/source/dialog/backingwindow.hxx +++ b/sfx2/source/dialog/backingwindow.hxx @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include -- cgit v1.2.3