[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 22 18:36:26 UTC 2020


 include/sfx2/templatelocalview.hxx         |   72 -----
 sfx2/source/control/recentdocsviewitem.cxx |    4 
 sfx2/source/control/templatelocalview.cxx  |  393 -----------------------------
 sfx2/source/control/templatesearchview.cxx |    2 
 4 files changed, 5 insertions(+), 466 deletions(-)

New commits:
commit 2a635ba02b51a2523feef71fb28643cad540f942
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sat Oct 17 17:36:07 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Oct 22 20:35:41 2020 +0200

    drop newly unused TemplateLocalView
    
    Change-Id: I8c7fb0fe21df55056eba4a0672cff1689f0f4aea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104535
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/sfx2/templatelocalview.hxx b/include/sfx2/templatelocalview.hxx
index 997a67823a44..5ce620bed4a2 100644
--- a/include/sfx2/templatelocalview.hxx
+++ b/include/sfx2/templatelocalview.hxx
@@ -63,78 +63,6 @@ private:
     FILTER_APPLICATION mApp;
 };
 
-
-class TemplateLocalView : public ThumbnailView
-{
-    typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
-
-public:
-
-    TemplateLocalView ( vcl::Window* pParent );
-
-    virtual ~TemplateLocalView () override;
-    virtual void dispose() override;
-
-    // Fill view with new item list
-    void insertItems (const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected = true, bool bShowCategoryInTooltip = false);
-
-    // Fill view with template folders thumbnails
-    void Populate ();
-
-    virtual void reload ();
-
-    virtual void showAllTemplates ();
-
-    void showRegion (TemplateContainerItem const *pItem);
-
-    DECL_LINK(ContextMenuSelectHdl, Menu*, bool);
-
-    virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle) override;
-
-    virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
-
-    virtual void RequestHelp( const HelpEvent& rHEvt ) override;
-
-    virtual void Command( const CommandEvent& rCEvt ) override;
-
-    virtual void KeyInput( const KeyEvent& rKEvt ) override;
-
-    void setCreateContextMenuHdl(const Link<ThumbnailViewItem*,void> &rLink);
-
-    void setOpenTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
-
-    void setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink);
-
-    static BitmapEx scaleImg (const BitmapEx &rImg, tools::Long width, tools::Long height);
-
-    static BitmapEx getDefaultThumbnail( const OUString& rPath );
-
-    static BitmapEx fetchThumbnail (const OUString &msURL, tools::Long width, tools::Long height);
-
-    static bool IsDefaultTemplate(const OUString& rPath);
-
-protected:
-    virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override;
-
-protected:
-    sal_uInt16 mnCurRegionId;
-
-    TemplateViewItem *maSelectedItem;
-
-    tools::Long mnThumbnailWidth;
-    tools::Long mnThumbnailHeight;
-
-    Point maPosition; //store the point of click event
-
-    Link<ThumbnailViewItem*,void> maCreateContextMenuHdl;
-    Link<ThumbnailViewItem*,void> maOpenTemplateHdl;
-    Link<ThumbnailViewItem*,void> maEditTemplateHdl;
-
-    std::unique_ptr<SfxDocumentTemplates> mpDocTemplates;
-    std::vector<std::unique_ptr<TemplateContainerItem> > maRegions;
-    std::vector<TemplateItemProperties > maAllTemplates;
-};
-
 class SfxTemplateLocalView : public SfxThumbnailView
 {
     typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*);
diff --git a/sfx2/source/control/recentdocsviewitem.cxx b/sfx2/source/control/recentdocsviewitem.cxx
index 8a047b20ee8d..9b73ef2c88ef 100644
--- a/sfx2/source/control/recentdocsviewitem.cxx
+++ b/sfx2/source/control/recentdocsviewitem.cxx
@@ -84,7 +84,7 @@ RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView &rView, const OUStri
 
         if (aExtSize.Width() > aThumbnailSize.Width() || aExtSize.Height() > aThumbnailSize.Height())
         {
-            aExt = TemplateLocalView::scaleImg(aExt, aThumbnailSize.Width(), aThumbnailSize.Height());
+            aExt = SfxTemplateLocalView::scaleImg(aExt, aThumbnailSize.Width(), aThumbnailSize.Height());
             aExtSize = aExt.GetSizePixel();
         }
 
@@ -99,7 +99,7 @@ RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView &rView, const OUStri
     }
 
     maTitle = aTitle;
-    maPreview1 = TemplateLocalView::scaleImg(aThumbnail, nThumbnailSize, nThumbnailSize);
+    maPreview1 = SfxTemplateLocalView::scaleImg(aThumbnail, nThumbnailSize, nThumbnailSize);
 }
 
 ::tools::Rectangle RecentDocsViewItem::updateHighlight(bool bVisible, const Point& rPoint)
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 1657a3bae43c..40f0418b9206 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -27,12 +27,6 @@
 #include <sfx2/strings.hrc>
 #include <bitmaps.hlst>
 
-#define MNI_OPEN               1
-#define MNI_EDIT               2
-//#define MNI_DEFAULT_TEMPLATE   3
-#define MNI_DELETE             4
-#define MNI_RENAME             5
-
 using namespace ::com::sun::star;
 
 bool ViewFilter_Application::isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt)
@@ -77,395 +71,12 @@ bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
     return true;
 }
 
-TemplateLocalView::TemplateLocalView ( vcl::Window* pParent)
-    : ThumbnailView(pParent),
-      mnCurRegionId(0),
-      maSelectedItem(nullptr),
-      mnThumbnailWidth(TEMPLATE_THUMBNAIL_MAX_WIDTH),
-      mnThumbnailHeight(TEMPLATE_THUMBNAIL_MAX_HEIGHT),
-      maPosition(0,0),
-      mpDocTemplates(new SfxDocumentTemplates)
-{
-}
-
-TemplateLocalView::~TemplateLocalView()
-{
-    disposeOnce();
-}
-
-void TemplateLocalView::dispose()
-{
-    maRegions.clear();
-
-    maAllTemplates.clear();
-
-    mpDocTemplates.reset();
-    ThumbnailView::dispose();
-}
-
-void TemplateLocalView::Populate ()
-{
-    maRegions.clear();
-    maAllTemplates.clear();
-
-    sal_uInt16 nCount = mpDocTemplates->GetRegionCount();
-    for (sal_uInt16 i = 0; i < nCount; ++i)
-    {
-        OUString aRegionName(mpDocTemplates->GetFullRegionName(i));
-
-        std::unique_ptr<TemplateContainerItem> pItem(new TemplateContainerItem( i+1 ));
-        pItem->mnRegionId = i;
-        pItem->maTitle = aRegionName;
-
-        sal_uInt16 nEntries = mpDocTemplates->GetCount(i);
-
-        for (sal_uInt16 j = 0; j < nEntries; ++j)
-        {
-            OUString aName = mpDocTemplates->GetName(i,j);
-            OUString aURL = mpDocTemplates->GetPath(i,j);
-
-            TemplateItemProperties aProperties;
-            aProperties.nId = j+1;
-            aProperties.nDocId = j;
-            aProperties.nRegionId = i;
-            aProperties.aName = aName;
-            aProperties.aPath = aURL;
-            aProperties.aRegionName = aRegionName;
-            aProperties.aThumbnail = TemplateLocalView::fetchThumbnail(aURL,
-                                                                          mnThumbnailWidth,
-                                                                          mnThumbnailHeight);
-
-            pItem->maTemplates.push_back(aProperties);
-            maAllTemplates.push_back(aProperties);
-        }
-
-        maRegions.push_back(std::move(pItem));
-    }
-}
-
-void TemplateLocalView::reload ()
-{
-    mpDocTemplates->Update();
-
-    Populate();
-
-    // Check if we are currently browsing a region or root folder
-    if (mnCurRegionId)
-    {
-        sal_uInt16 nRegionId = mnCurRegionId - 1;   //Is offset by 1
-
-        for (auto const & pRegion : maRegions)
-        {
-            if (pRegion->mnRegionId == nRegionId)
-            {
-                showRegion(pRegion.get());
-                break;
-            }
-        }
-    }
-    else
-        showAllTemplates();
-
-    //No items should be selected by default
-    deselectItems();
-}
-
-void TemplateLocalView::showAllTemplates()
-{
-    mnCurRegionId = 0;
-
-    insertItems(maAllTemplates, false, true);
-}
-
-void TemplateLocalView::showRegion(TemplateContainerItem const *pItem)
-{
-    mnCurRegionId = pItem->mnRegionId+1;
-
-    insertItems(pItem->maTemplates);
-}
-
-IMPL_LINK(TemplateLocalView, ContextMenuSelectHdl, Menu*, pMenu, bool)
-{
-    sal_uInt16 nMenuId = pMenu->GetCurItemId();
-
-    switch(nMenuId)
-    {
-    case MNI_OPEN:
-        maOpenTemplateHdl.Call(maSelectedItem);
-        break;
-    case MNI_EDIT:
-        maEditTemplateHdl.Call(maSelectedItem);
-        break;
-    case MNI_RENAME:
-    {
-        InputDialog aTitleEditDlg(GetFrameWeld(), SfxResId(STR_RENAME_TEMPLATE));
-        OUString sOldTitle = maSelectedItem->getTitle();
-        aTitleEditDlg.SetEntryText(sOldTitle);
-        aTitleEditDlg.HideHelpBtn();
-
-        if (!aTitleEditDlg.run())
-            break;
-        OUString sNewTitle = comphelper::string::strip(aTitleEditDlg.GetEntryText(), ' ');
-
-        if ( !sNewTitle.isEmpty() && sNewTitle != sOldTitle )
-        {
-            maSelectedItem->setTitle(sNewTitle);
-        }
-    }
-        break;
-    case MNI_DELETE:
-    {
-        std::unique_ptr<weld::MessageDialog> xQueryDlg(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo,
-                                                       SfxResId(STR_QMSG_SEL_TEMPLATE_DELETE)));
-        if (xQueryDlg->run() != RET_YES)
-            break;
-
-        reload();
-    }
-        break;
-    default:
-        break;
-    }
-
-    return false;
-}
-
-bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle)
-{
-    sal_uInt16 nRegionId = 0;
-    sal_uInt16 nDocId = USHRT_MAX;
-    TemplateViewItem* pDocItem = dynamic_cast<TemplateViewItem*>( pItem );
-
-    if ( pDocItem )
-    {
-        nRegionId = pDocItem->mnRegionId;
-        nDocId = pDocItem->mnDocId;
-    }
-
-    return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
-}
-
-void TemplateLocalView::insertItems(const std::vector<TemplateItemProperties> &rTemplates, bool isRegionSelected, bool bShowCategoryInTooltip)
-{
-    std::vector<std::unique_ptr<ThumbnailViewItem>> aItems(rTemplates.size());
-    for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
-    {
-        const TemplateItemProperties *pCur = &rTemplates[i];
-
-        std::unique_ptr<TemplateViewItem> pChild;
-        if(isRegionSelected)
-            pChild.reset(new TemplateViewItem(*this, pCur->nId));
-        else
-            pChild.reset(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);
-            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] = std::move(pChild);
-    }
-
-    updateItems(std::move(aItems));
-}
-
-void SfxTemplateLocalView::updateThumbnailDimensions(tools::Long itemMaxSize)
+void SfxTemplateLocalView::updateThumbnailDimensions(long itemMaxSize)
 {
     mnThumbnailWidth = itemMaxSize;
     mnThumbnailHeight = itemMaxSize;
 }
 
-
-void TemplateLocalView::MouseButtonDown( const MouseEvent& rMEvt )
-{
-    GrabFocus();
-    ThumbnailView::MouseButtonDown(rMEvt);
-}
-
-void TemplateLocalView::RequestHelp( const HelpEvent& rHEvt )
-{
-    if ( rHEvt.GetMode() & HelpEventMode::QUICK )
-    {
-        tools::Rectangle aRect( OutputToScreenPixel( GetPosPixel() ), GetSizePixel() );
-        Help::ShowQuickHelp( this, aRect, GetQuickHelpText(),
-                             QuickHelpFlags::CtrlText | QuickHelpFlags::TipStyleBalloon );
-        return;
-    }
-
-    ThumbnailView::RequestHelp( rHEvt );
-}
-
-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<const TemplateViewItem*>(pItem);
-
-            if(pViewItem)
-            {
-                maSelectedItem = dynamic_cast<TemplateViewItem*>(pItem);
-                maCreateContextMenuHdl.Call(pItem);
-            }
-        }
-        else
-        {
-            for (ThumbnailViewItem* pItem : mFilteredItemList)
-            {
-                //create context menu for the first selected item
-                if (pItem->isSelected())
-                {
-                    deselectItems();
-                    pItem->setSelection(true);
-                    tools::Rectangle aRect = pItem->getDrawArea();
-                    maPosition = aRect.Center();
-                    maSelectedItem = dynamic_cast<TemplateViewItem*>(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);
-            }
-        }
-
-        if (IsReallyVisible() && IsUpdateMode())
-            Invalidate();
-        return;
-    }
-    else if( aKeyCode == KEY_DELETE && !mFilteredItemList.empty())
-    {
-        std::unique_ptr<weld::MessageDialog> xQueryDlg(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo,
-                                                       SfxResId(STR_QMSG_SEL_TEMPLATE_DELETE)));
-        if (xQueryDlg->run() != RET_YES)
-            return;
-
-        reload();
-    }
-
-    ThumbnailView::KeyInput(rKEvt);
-}
-
-
-void TemplateLocalView::setCreateContextMenuHdl(const Link<ThumbnailViewItem*,void> &rLink)
-{
-    maCreateContextMenuHdl = rLink;
-}
-
-void TemplateLocalView::setOpenTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
-{
-    maOpenTemplateHdl = rLink;
-}
-
-void TemplateLocalView::setEditTemplateHdl(const Link<ThumbnailViewItem*,void> &rLink)
-{
-    maEditTemplateHdl = rLink;
-}
-
-BitmapEx TemplateLocalView::scaleImg (const BitmapEx &rImg, tools::Long width, tools::Long height)
-{
-    BitmapEx aImg = rImg;
-
-    if (!rImg.IsEmpty())
-    {
-        Size aSize = rImg.GetSizePixel();
-
-        if (aSize.Width() == 0)
-            aSize.setWidth( 1 );
-
-        if (aSize.Height() == 0)
-            aSize.setHeight( 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<OUString> &aServiceNames = aModOpt.GetAllServiceNames();
-
-    return std::any_of(aServiceNames.begin(), aServiceNames.end(), [&rPath](const OUString& rName) {
-        return SfxObjectFactory::GetStandardTemplate(rName).match(rPath); });
-}
-
-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(SFX_THUMBNAIL_TEXT);
-    else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::CALC, aExt) )
-        aImg = BitmapEx(SFX_THUMBNAIL_SHEET);
-    else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::IMPRESS, aExt) )
-        aImg = BitmapEx(SFX_THUMBNAIL_PRESENTATION);
-    else if ( ViewFilter_Application::isFilteredExtension( FILTER_APPLICATION::DRAW, aExt) )
-        aImg = BitmapEx(SFX_THUMBNAIL_DRAWING);
-
-    return aImg;
-}
-
-BitmapEx TemplateLocalView::fetchThumbnail (const OUString &msURL, tools::Long width, tools::Long height)
-{
-    return TemplateLocalView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height);
-}
-
-void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pItem)
-{
-    TemplateViewItem* pViewItem = dynamic_cast<TemplateViewItem*>(pItem);
-
-    if( pViewItem )
-        maOpenTemplateHdl.Call(pViewItem);
-}
-
 SfxTemplateLocalView::SfxTemplateLocalView(std::unique_ptr<weld::ScrolledWindow> xWindow,
                                            std::unique_ptr<weld::Menu> xMenu)
     : SfxThumbnailView(std::move(xWindow), std::move(xMenu))
@@ -510,7 +121,7 @@ void SfxTemplateLocalView::Populate()
             aProperties.aName = aName;
             aProperties.aPath = aURL;
             aProperties.aRegionName = aRegionName;
-            aProperties.aThumbnail = TemplateLocalView::fetchThumbnail(aURL,
+            aProperties.aThumbnail = SfxTemplateLocalView::fetchThumbnail(aURL,
                                                                           mnThumbnailWidth,
                                                                           mnThumbnailHeight);
 
diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx
index 759c888ce8d7..757dc9984767 100644
--- a/sfx2/source/control/templatesearchview.cxx
+++ b/sfx2/source/control/templatesearchview.cxx
@@ -214,7 +214,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionI
     pItem->setHelpText(rSubtitle);
     pItem->setPath(rPath);
 
-    if(TemplateLocalView::IsDefaultTemplate(rPath))
+    if (SfxTemplateLocalView::IsDefaultTemplate(rPath))
         pItem->showDefaultIcon(true);
 
     SfxThumbnailView::AppendItem(std::move(pItem));


More information about the Libreoffice-commits mailing list