From a6ea18a9cc83a85f4bf4fce78b7dbef3d1a419c6 Mon Sep 17 00:00:00 2001 From: Akshay Deep Date: Thu, 2 Jun 2016 16:06:12 +0530 Subject: [PATCH] Mark Default Templates in Template Manager Change-Id: I1dff486605efce09e862d2924b24949601ae0f17 Reviewed-on: https://gerrit.libreoffice.org/25816 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- icon-themes/galaxy/res/templatestar.png | Bin 0 -> 876 bytes include/sfx2/templateabstractview.hxx | 4 +++ include/sfx2/templateviewitem.hxx | 6 ++++ sfx2/source/control/templateabstractview.cxx | 35 +++++++++++++++++++ sfx2/source/control/templateview.hrc | 1 + sfx2/source/control/templateview.src | 5 +++ sfx2/source/control/templateviewitem.cxx | 26 +++++++++++++- sfx2/source/doc/templatedlg.cxx | 5 +++ 8 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 icon-themes/galaxy/res/templatestar.png diff --git a/icon-themes/galaxy/res/templatestar.png b/icon-themes/galaxy/res/templatestar.png new file mode 100644 index 0000000000000000000000000000000000000000..96bf3cb2351518b6806c455a29e88a6a40e23db1 GIT binary patch literal 876 zcmV-y1C#uTP)fcEg@fpwruLk=3}O9u2K?w^p=VcH7yIJ$tY8MPqK$$nYJ)c zSPxLb%E$>;h81N(XeAXUl6v*drJY~LL1MAmqMbj_x%b2G{C;1KowWmx1F%3M5(7FCMN_rYHE3tKG+Z_z4It(6LTZfReF4^*r$`5l; ze77f3bh(pA%_fm@COt(z&)K!j=av<`9iK##>M)4ZJ;2K9ZdsmoV$Ust!i|iXCo?~Fw%-PCcM0r zUa4uJB_|%zlG1!Tf(o1yJDY^*U0gL*O-1`DW1_8XwX zj&qc_sDPmMe;#Jk-I;7`<4xCud&6;;`Cm}UG}NcW0J9QwJQaGZ8!azfYIV#QnXXe@ z`pFz>s#K8NI7W$!>j}zOjgp+sW1{OuqpwVuMHe5(;I`*EP@yHatrMr<+AQG?{pfVm zNBsqSOUF#;!V(NZ6%Sy4gSFUILr=LV7Z#K!68BvM{fu&RqyXnCj1en3H)gJ?;* zz2!7SRK0hURU7H>^G^sWH1`d;K8r+o)hI;8p=H?y+>qqFfm&I9h@cj$ zKudRTMFHEtp@3}~%RLU&xcpOs{8IgqUy9f7`#%7n?a*tU@y1>N0000 #include #include +#include #include #include #include +#include #include #include @@ -34,6 +36,7 @@ using namespace basegfx; using namespace drawinglayer::primitive2d; +using namespace ::com::sun::star::uno; bool ViewFilter_Application::isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt) { @@ -126,6 +129,9 @@ void TemplateAbstractView::insertItems(const std::vector pChild->setHelpText(pCur->aRegionName); pChild->maPreview1 = pCur->aThumbnail; + if(IsDefaultTemplate(pCur->aPath)) + pChild->showDefaultIcon(true); + if ( pCur->aThumbnail.IsEmpty() ) { // Use the default thumbnail if we have nothing else @@ -245,6 +251,35 @@ BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long return aImg; } +bool TemplateAbstractView::IsDefaultTemplate(const OUString& rPath) +{ + SvtModuleOptions aModOpt; + std::vector aList; + 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( OUString rPath) +{ + for (ThumbnailViewItem* pItem : mItemList) + { + TemplateViewItem* pViewItem = dynamic_cast(pItem); + if(pViewItem->getPath().match(rPath)) + { + pViewItem->showDefaultIcon(false); + return; + } + } +} + BitmapEx TemplateAbstractView::getDefaultThumbnail( const OUString& rPath ) { BitmapEx aImg; diff --git a/sfx2/source/control/templateview.hrc b/sfx2/source/control/templateview.hrc index d2073bc8a304..ae679b88a141 100644 --- a/sfx2/source/control/templateview.hrc +++ b/sfx2/source/control/templateview.hrc @@ -14,5 +14,6 @@ #define IMG_WELCOME 261 #define IMG_RECENTDOC_REMOVE 262 #define IMG_RECENTDOC_REMOVE_HIGHLIGHTED 263 +#define IMG_DEFAULT 264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templateview.src b/sfx2/source/control/templateview.src index d7693723bda2..a8e984c975cd 100644 --- a/sfx2/source/control/templateview.src +++ b/sfx2/source/control/templateview.src @@ -48,4 +48,9 @@ Bitmap IMG_RECENTDOC_REMOVE_HIGHLIGHTED File = "recentdoc_remove_highlighted.png"; }; +Bitmap IMG_DEFAULT +{ + File = "templatestar.png"; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templateviewitem.cxx b/sfx2/source/control/templateviewitem.cxx index 047fec990342..3158a4cdea28 100644 --- a/sfx2/source/control/templateviewitem.cxx +++ b/sfx2/source/control/templateviewitem.cxx @@ -15,11 +15,15 @@ #include #include #include +#include #include #include #include #include #include +#include + +#include using namespace basegfx; using namespace basegfx::tools; @@ -29,7 +33,9 @@ using namespace drawinglayer::primitive2d; TemplateViewItem::TemplateViewItem (ThumbnailView &rView, sal_uInt16 nId) : ThumbnailViewItem(rView, nId), mnRegionId(USHRT_MAX), - mnDocId(USHRT_MAX) + mnDocId(USHRT_MAX), + maDefaultBitmap(SfxResId(IMG_DEFAULT)), + mbIsDefaultTemplate(false) { } @@ -37,6 +43,16 @@ TemplateViewItem::~TemplateViewItem () { } +Rectangle TemplateViewItem::getDefaultIconArea() const +{ + Rectangle aArea(getDrawArea()); + Size aSize(maDefaultBitmap.GetSizePixel()); + + return Rectangle( + Point(aArea.Left() + THUMBNAILVIEW_ITEM_CORNER, aArea.Top() + THUMBNAILVIEW_ITEM_CORNER), + aSize); +} + void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor, const ThumbnailItemAttributes *pAttrs) { @@ -90,6 +106,14 @@ void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProces // draw thumbnail borders aSeq[3] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds)); + if(mbIsDefaultTemplate) + { + Point aIconPos(getDefaultIconArea().TopLeft()); + + aSeq[4] = drawinglayer::primitive2d::Primitive2DReference(new DiscreteBitmapPrimitive2D( maDefaultBitmap, + B2DPoint(aIconPos.X(), aIconPos.Y()))); + } + addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq); pProcessor->process(aSeq); diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 54b22b329132..14181cfe3f22 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -855,7 +855,12 @@ IMPL_LINK_TYPED(SfxTemplateManagerDlg, DefaultTemplateHdl, ThumbnailViewItem*, p OUString aServiceName; if (lcl_getServiceName(pViewItem->getPath(),aServiceName)) { + OUString sPrevDefault = SfxObjectFactory::GetStandardTemplate( aServiceName ); + if(!sPrevDefault.isEmpty()) + mpLocalView->RemoveDefaultTemplateIcon(sPrevDefault); + SfxObjectFactory::SetStandardTemplate(aServiceName,pViewItem->getPath()); + pViewItem->showDefaultIcon(true); createDefaultTemplateMenu(); }