diff options
-rw-r--r-- | sfx2/inc/sfx2/templatefolderview.hxx | 5 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templatefolderviewitem.hxx | 3 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templateproperties.hxx | 23 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templateview.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/control/templatefolderview.cxx | 120 | ||||
-rw-r--r-- | sfx2/source/control/templatefolderviewitem.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/control/templateview.cxx | 14 | ||||
-rw-r--r-- | sfx2/source/doc/templatedlg.cxx | 24 |
8 files changed, 107 insertions, 87 deletions
diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx index 04a474db3f13..af1296268378 100644 --- a/sfx2/inc/sfx2/templatefolderview.hxx +++ b/sfx2/inc/sfx2/templatefolderview.hxx @@ -12,6 +12,7 @@ #include <set> +#include <sfx2/templateproperties.hxx> #include <sfx2/thumbnailview.hxx> class SfxDocumentTemplates; @@ -49,8 +50,8 @@ public: void filterTemplatesByApp (const FILTER_APPLICATION &eApp); - std::vector<std::pair<sal_uInt16,std::vector<ThumbnailViewItem*> > > - getFilteredItems (const boost::function<bool (const ThumbnailViewItem*) > &rFunc) const; + std::vector<TemplateItemProperties> + getFilteredItems (const boost::function<bool (const TemplateItemProperties&) > &rFunc) const; void sortOverlayItems (const boost::function<bool (const ThumbnailViewItem*, const ThumbnailViewItem*) > &func); diff --git a/sfx2/inc/sfx2/templatefolderviewitem.hxx b/sfx2/inc/sfx2/templatefolderviewitem.hxx index d7684cdd13b5..d4c6c0ac8e88 100644 --- a/sfx2/inc/sfx2/templatefolderviewitem.hxx +++ b/sfx2/inc/sfx2/templatefolderviewitem.hxx @@ -10,6 +10,7 @@ #ifndef TEMPLATEFOLDERVIEWITEM_HXX #define TEMPLATEFOLDERVIEWITEM_HXX +#include <sfx2/templateproperties.hxx> #include <sfx2/thumbnailviewitem.hxx> class TemplateViewItem; @@ -19,7 +20,7 @@ class TemplateFolderViewItem : public ThumbnailViewItem public: BitmapEx maPreview2; - std::vector<TemplateViewItem*> maTemplates; + std::vector<TemplateItemProperties> maTemplates; TemplateFolderViewItem (ThumbnailView &rView, Window *pParent); diff --git a/sfx2/inc/sfx2/templateproperties.hxx b/sfx2/inc/sfx2/templateproperties.hxx index dc0fc3ff5dcd..8891ee956b27 100644 --- a/sfx2/inc/sfx2/templateproperties.hxx +++ b/sfx2/inc/sfx2/templateproperties.hxx @@ -6,10 +6,23 @@ * 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/. */ -... -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -#ifndef TEMPLATEPROPERTIES_HXX -#define TEMPLATEPROPERTIES_HXX +#ifndef __SFX2_TEMPLATEPROPERTIES_HXX__ +#define __SFX2_TEMPLATEPROPERTIES_HXX__ + +#include <rtl/ustring.hxx> +#include <vcl/bitmapex.hxx> + +struct TemplateItemProperties +{ + sal_uInt16 nId; + sal_uInt16 nRegionId; + rtl::OUString aName; + rtl::OUString aPath; + rtl::OUString aType; + BitmapEx aThumbnail; +}; -#endif // TEMPLATEPROPERTIES_HXX +#endif // __SFX2_TEMPLATEPROPERTIES_HXX__ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/inc/sfx2/templateview.hxx b/sfx2/inc/sfx2/templateview.hxx index 0ed278c77af4..8e8bc10ecb19 100644 --- a/sfx2/inc/sfx2/templateview.hxx +++ b/sfx2/inc/sfx2/templateview.hxx @@ -10,6 +10,7 @@ #ifndef TEMPLATEVIEW_HXX #define TEMPLATEVIEW_HXX +#include <sfx2/templateproperties.hxx> #include <sfx2/thumbnailview.hxx> #include <vcl/image.hxx> @@ -33,7 +34,7 @@ public: virtual void Paint (const Rectangle &rRect); - void InsertItems (const std::vector<TemplateViewItem*> &rTemplates); + void InsertItems (const std::vector<TemplateItemProperties> &rTemplates); void setDblClickHdl (const Link &rLink) { maDblClickHdl = rLink; } diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx index c66148d5bbfe..91f0fbb0a695 100644 --- a/sfx2/source/control/templatefolderview.cxx +++ b/sfx2/source/control/templatefolderview.cxx @@ -206,20 +206,18 @@ class FolderFilter_Application { public: - FolderFilter_Application ( SfxDocumentTemplates *pDocTemplates, FILTER_APPLICATION eApp) + FolderFilter_Application (FILTER_APPLICATION eApp) : meApp(eApp) { - maFilterFunc = ViewFilter_Application(pDocTemplates,eApp); } bool operator () (const ThumbnailViewItem *pItem) { TemplateFolderViewItem *pFolderItem = (TemplateFolderViewItem*)pItem; - std::vector<TemplateViewItem*> &rTemplates = pFolderItem->maTemplates; + std::vector<TemplateItemProperties> &rTemplates = pFolderItem->maTemplates; size_t nVisCount = 0; - ThumbnailViewItem *pTemplateItem; // Clear thumbnails pFolderItem->maPreview1.Clear(); @@ -227,27 +225,48 @@ public: for (size_t i = 0, n = rTemplates.size(); i < n; ++i) { - pTemplateItem = rTemplates[i]; - - if (maFilterFunc(pTemplateItem)) + if (isValid(rTemplates[i].aType)) { ++nVisCount; // Update the thumbnails if (nVisCount == 1) - pFolderItem->maPreview1 = pTemplateItem->maPreview1; + pFolderItem->maPreview1 = rTemplates[i].aThumbnail; else if (nVisCount == 2) - pFolderItem->maPreview2 = pTemplateItem->maPreview1; + pFolderItem->maPreview2 = rTemplates[i].aThumbnail; } } return nVisCount; } + bool isValid (const rtl::OUString &rType) const + { + bool bRet = false; + + 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; - boost::function<bool (const ThumbnailViewItem*)> maFilterFunc; }; TemplateFolderView::TemplateFolderView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren) @@ -309,14 +328,15 @@ void TemplateFolderView::Populate () aName += "..."; } - TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView); - pTemplateItem->mnId = j+1; - pTemplateItem->maText = aName; - pTemplateItem->setPath(aURL); - pTemplateItem->setFileType(aType); - pTemplateItem->maPreview1 = lcl_fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT); + TemplateItemProperties aProperties;; + aProperties.nId = j+1; + aProperties.nRegionId = i; + aProperties.aName = aName; + aProperties.aPath = aURL; + aProperties.aType = aType; + aProperties.aThumbnail = lcl_fetchThumbnail(aURL,THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT); - pItem->maTemplates.push_back(pTemplateItem); + pItem->maTemplates.push_back(aProperties); } lcl_updateThumbnails(pItem); @@ -357,7 +377,7 @@ void TemplateFolderView::showOverlay (bool bVisible) // Check if the folder view needs to be filtered if (mbFilteredResults) { - filterItems(FolderFilter_Application(mpDocTemplates,meFilterOption)); + filterItems(FolderFilter_Application(meFilterOption)); mbFilteredResults = false; meFilterOption = FILTER_APP_NONE; @@ -385,30 +405,24 @@ void TemplateFolderView::filterTemplatesByApp (const FILTER_APPLICATION &eApp) } else { - filterItems(FolderFilter_Application(mpDocTemplates,eApp)); + filterItems(FolderFilter_Application(eApp)); } } -std::vector<std::pair<sal_uInt16,std::vector<ThumbnailViewItem*> > > -TemplateFolderView::getFilteredItems(const boost::function<bool (const ThumbnailViewItem*) > &rFunc) const +std::vector<TemplateItemProperties> +TemplateFolderView::getFilteredItems(const boost::function<bool (const TemplateItemProperties&) > &rFunc) const { - std::vector<ThumbnailViewItem*> aRegionItems; - std::vector<std::pair<sal_uInt16,std::vector<ThumbnailViewItem*> > > aItems; + std::vector<TemplateItemProperties> aItems; for (size_t i = 0; i < mItemList.size(); ++i) { TemplateFolderViewItem *pFolderItem = static_cast<TemplateFolderViewItem*>(mItemList[i]); - sal_uInt16 nRegionId = pFolderItem->mnId-1; - for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j) { if (rFunc(pFolderItem->maTemplates[j])) - aRegionItems.push_back(pFolderItem->maTemplates[j]); + aItems.push_back(pFolderItem->maTemplates[j]); } - - aItems.push_back(std::make_pair(nRegionId,aRegionItems)); - aRegionItems.clear(); } return aItems; @@ -465,13 +479,11 @@ bool TemplateFolderView::removeTemplate (const sal_uInt16 nItemId) { TemplateFolderViewItem *pItem = static_cast<TemplateFolderViewItem*>(mItemList[i]); - std::vector<TemplateViewItem*>::iterator pIter; + std::vector<TemplateItemProperties>::iterator pIter; for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter) { - if ((*pIter)->mnId == nItemId) + if (pIter->nId == nItemId) { - delete *pIter; - pItem->maTemplates.erase(pIter); mpItemView->RemoveItem(nItemId); @@ -536,26 +548,25 @@ bool TemplateFolderView::moveTemplates(std::set<const ThumbnailViewItem *> &rIte // move template to destination - TemplateViewItem *pTemplateItem = new TemplateViewItem(*mpItemView,mpItemView); - pTemplateItem->mnId = nTargetIdx + 1; - pTemplateItem->maText = pViewItem->maText; - pTemplateItem->setPath(pViewItem->getPath()); - pTemplateItem->setFileType(pViewItem->getFileType()); - pTemplateItem->maPreview1 = pViewItem->maPreview1; + TemplateItemProperties aTemplateItem; + aTemplateItem.nId = nTargetIdx + 1; + aTemplateItem.nRegionId = nTargetRegion; + aTemplateItem.aName = pViewItem->maText; + aTemplateItem.aPath = pViewItem->getPath(); + aTemplateItem.aType = pViewItem->getFileType(); + aTemplateItem.aThumbnail = pViewItem->maPreview1; - pTarget->maTemplates.push_back(pTemplateItem); + pTarget->maTemplates.push_back(aTemplateItem); if (!bCopy) { - // remove template for overlay and from cached data + // remove template from overlay and from cached data - std::vector<TemplateViewItem*>::iterator pIter; + std::vector<TemplateItemProperties>::iterator pIter; for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter) { - if ((*pIter)->mnId == pViewItem->mnId) + if (pIter->nId == pViewItem->mnId) { - delete *pIter; - pSrc->maTemplates.erase(pIter); mpItemView->RemoveItem(pViewItem->mnId); @@ -595,14 +606,15 @@ void TemplateFolderView::copyFrom (TemplateFolderViewItem *pItem, const rtl::OUS if (mpDocTemplates->CopyFrom(nRegionId,nId,aPath)) { - TemplateViewItem *pTemplate = new TemplateViewItem(*mpItemView,mpItemView); - pTemplate->mnId = nId; - pTemplate->maText = mpDocTemplates->GetName(nRegionId,nId); - pTemplate->maPreview1 = lcl_fetchThumbnail(rPath,128,128); - pTemplate->setPath(rPath); - pTemplate->setFileType(SvFileInformationManager::GetDescription(INetURLObject(rPath))); + TemplateItemProperties aTemplate; + aTemplate.nId = nId; + aTemplate.nRegionId = nRegionId; + aTemplate.aName = mpDocTemplates->GetName(nRegionId,nId); + aTemplate.aThumbnail = lcl_fetchThumbnail(rPath,128,128); + aTemplate.aPath = rPath; + aTemplate.aType = SvFileInformationManager::GetDescription(INetURLObject(rPath)); - pItem->maTemplates.push_back(pTemplate); + pItem->maTemplates.push_back(aTemplate); lcl_updateThumbnails(pItem); @@ -691,13 +703,13 @@ void lcl_updateThumbnails (TemplateFolderViewItem *pItem) { if (i == 0) { - pItem->maPreview1 = lcl_ScaleImg(pItem->maTemplates[i]->maPreview1, + pItem->maPreview1 = lcl_ScaleImg(pItem->maTemplates[i].aThumbnail, THUMBNAIL_MAX_WIDTH*0.75, THUMBNAIL_MAX_HEIGHT*0.75); } else { - pItem->maPreview2 = lcl_ScaleImg(pItem->maTemplates[i]->maPreview1, + pItem->maPreview2 = lcl_ScaleImg(pItem->maTemplates[i].aThumbnail, THUMBNAIL_MAX_WIDTH*0.75, THUMBNAIL_MAX_HEIGHT*0.75); } diff --git a/sfx2/source/control/templatefolderviewitem.cxx b/sfx2/source/control/templatefolderviewitem.cxx index 7c5459b173e4..36f19097a9ca 100644 --- a/sfx2/source/control/templatefolderviewitem.cxx +++ b/sfx2/source/control/templatefolderviewitem.cxx @@ -32,8 +32,6 @@ TemplateFolderViewItem::TemplateFolderViewItem (ThumbnailView &rView, Window *pP TemplateFolderViewItem::~TemplateFolderViewItem () { - for (size_t i = 0; i < maTemplates.size(); ++i) - delete maTemplates[i]; } void TemplateFolderViewItem::calculateItemsPosition (sal_uInt32 nMaxTextLenght) diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx index 350874167aab..a83a56804ad4 100644 --- a/sfx2/source/control/templateview.cxx +++ b/sfx2/source/control/templateview.cxx @@ -107,18 +107,18 @@ void TemplateView::Paint (const Rectangle &rRect) mpProcessor->process(aSeq); } -void TemplateView::InsertItems (const std::vector<TemplateViewItem*> &rTemplates) +void TemplateView::InsertItems (const std::vector<TemplateItemProperties> &rTemplates) { for (size_t i = 0, n = rTemplates.size(); i < n; ++i ) { TemplateViewItem *pItem = new TemplateViewItem(*this,this); - TemplateViewItem *pCur = rTemplates[i]; + const TemplateItemProperties *pCur = &rTemplates[i]; - pItem->mnId = pCur->mnId; - pItem->maText = pCur->maText; - pItem->setPath(pCur->getPath()); - pItem->setFileType(pCur->getFileType()); - pItem->maPreview1 = pCur->maPreview1; + pItem->mnId = pCur->nId; + pItem->maText = pCur->aName; + pItem->setPath(pCur->aPath); + pItem->setFileType(pCur->aType); + pItem->maPreview1 = pCur->aThumbnail; pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected)); mItemList.push_back(pItem); diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 8bf2c44c4ee1..f2c961fd994f 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -72,9 +72,9 @@ public: : maKeyword(rKeyword) {} - bool operator() (const ThumbnailViewItem *pItem) + bool operator() (const TemplateItemProperties &rItem) { - return pItem->maText.indexOf(maKeyword) != -1; + return rItem.aName.indexOf(maKeyword) != -1; } private: @@ -575,25 +575,19 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl) { mpSearchView->Clear(); - std::vector<std::pair<sal_uInt16,std::vector<ThumbnailViewItem*> > > aItems = + std::vector<TemplateItemProperties> aItems = maView->getFilteredItems(SearchView_Keyword(aKeyword)); size_t nCounter = 0; for (size_t i = 0; i < aItems.size(); ++i) { - sal_uInt16 nRegionId = aItems[i].first; - std::vector<ThumbnailViewItem*> &rRegionItems = aItems[i].second; + TemplateItemProperties *pItem = &aItems[i]; - for (size_t j = 0; j < rRegionItems.size(); ++j) - { - TemplateViewItem *pItem = static_cast<TemplateViewItem*>(rRegionItems[j]); - - mpSearchView->AppendItem(++nCounter,nRegionId, - pItem->mnId-1, - pItem->maText, - pItem->getPath(), - pItem->maPreview1); - } + mpSearchView->AppendItem(++nCounter,pItem->nRegionId, + pItem->nId-1, + pItem->aName, + pItem->aPath, + pItem->aThumbnail); } mpSearchView->Invalidate(); |