sfx2/Library_sfx.mk | 1 sfx2/Package_inc.mk | 1 sfx2/inc/sfx2/templatefolderview.hxx | 40 +++ sfx2/inc/sfx2/thumbnailview.hxx | 21 + sfx2/inc/sfx2/thumbnailviewitem.hxx | 23 ++ sfx2/inc/templatedlg.hxx | 4 sfx2/source/control/templatefolderview.cxx | 213 +++++++++++++++++++ sfx2/source/control/thumbnailview.cxx | 310 +---------------------------- sfx2/source/control/thumbnailviewitem.cxx | 97 ++++++++- sfx2/source/doc/templatedlg.cxx | 4 10 files changed, 406 insertions(+), 308 deletions(-)
New commits: commit 0f53d3bfb93537f20d9734fe7c84a88e8a82092b Author: Rafael Dominguez <[email protected]> Date: Mon Jun 18 22:57:35 2012 -0430 Display templates when double clicking a folder. Change-Id: Idf9be4b2f5fbff60b881e72fe52ac13767f32459 diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx index ad56fcc..a6aec17 100644 --- a/sfx2/inc/sfx2/templatefolderview.hxx +++ b/sfx2/inc/sfx2/templatefolderview.hxx @@ -27,7 +27,12 @@ public: private: + virtual void OnItemDblClicked (ThumbnailViewItem *pRegionItem); + +private: + SfxOrganizeMgr *mpMgr; + ThumbnailView *mpItemView; }; #endif // TEMPLATEFOLDERVIEW_HXX diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx index 2f224e2..8106cb3 100644 --- a/sfx2/source/control/templatefolderview.cxx +++ b/sfx2/source/control/templatefolderview.cxx @@ -139,13 +139,20 @@ BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height) TemplateFolderView::TemplateFolderView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren) : ThumbnailView(pParent,rResId,bDisableTransientChildren), - mpMgr(new SfxOrganizeMgr(NULL,NULL)) + mpMgr(new SfxOrganizeMgr(NULL,NULL)), + mpItemView(new ThumbnailView(this,WB_VSCROLL)) { + mpItemView->SetColor(Color(COL_WHITE)); + mpItemView->SetPosPixel(Point(0,0)); + mpItemView->SetSizePixel(GetOutputSizePixel()); + mpItemView->SetColCount(3); + mpItemView->SetLineCount(2); } TemplateFolderView::~TemplateFolderView() { delete mpMgr; + delete mpItemView; } void TemplateFolderView::Populate () @@ -182,6 +189,25 @@ void TemplateFolderView::Populate () Invalidate(); } +void TemplateFolderView::OnItemDblClicked (ThumbnailViewItem *pRegionItem) +{ + // Clear previous items + mpItemView->Clear(); + + // Fill templates + sal_uInt16 nRegionId = pRegionItem->mnId-1; + const SfxDocumentTemplates* pTemplates = mpMgr->GetTemplates(); + + sal_uInt16 nEntries = pTemplates->GetCount(nRegionId); + for (sal_uInt16 i = 0; i < nEntries; ++i) + { + mpItemView->InsertItem(i+1,lcl_fetchThumbnail(pTemplates->GetPath(nRegionId,i),128,128), + pTemplates->GetName(nRegionId,i)); + } + + mpItemView->Show(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 927f4ecd40ea6652709551690be9d2f583a6d1d9 Author: Rafael Dominguez <[email protected]> Date: Mon Jun 18 22:04:59 2012 -0430 Add a double click handler to ThumbnailView. Change-Id: I8c5711c89fe2d2cede55399028f8a3910a7bcbec diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx index f54a549..a1db106 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -266,6 +266,8 @@ protected: virtual void DrawItem (ThumbnailViewItem *pItem); + virtual void OnItemDblClicked (ThumbnailViewItem *pItem); + protected: friend class ThumbnailViewAcc; diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index 9ea0edd..e9d3e27 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -203,6 +203,10 @@ void ThumbnailView::DrawItem (ThumbnailViewItem *pItem) pItem->Paint(mpProcessor,mpItemAttrs); } +void ThumbnailView::OnItemDblClicked (ThumbnailViewItem*) +{ +} + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ThumbnailView::CreateAccessible() { return new ThumbnailViewAcc( this, mbIsTransientChildrenDisabled ); @@ -674,7 +678,7 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt ) } } else if ( rMEvt.GetClicks() == 2 ) - ; + OnItemDblClicked(pItem); } return; commit 0a89ff70b440158e301dff5b5c6eb612f1c2a676 Author: Rafael Dominguez <[email protected]> Date: Mon Jun 18 21:53:07 2012 -0430 Create a thumbnailview for templates folders. Change-Id: I2c5e2899e854df0edb3ee7bade55f39c8984177d diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 9009ede..9fbcee3 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -148,6 +148,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/shell \ sfx2/source/control/sorgitm \ sfx2/source/control/statcach \ + sfx2/source/control/templatefolderview \ sfx2/source/control/thumbnailviewitem \ sfx2/source/control/thumbnailviewacc \ sfx2/source/control/thumbnailview \ diff --git a/sfx2/Package_inc.mk b/sfx2/Package_inc.mk index dee4610..aef6ea4 100644 --- a/sfx2/Package_inc.mk +++ b/sfx2/Package_inc.mk @@ -127,6 +127,7 @@ $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/taskpane.hxx,sfx2/taskpane.h $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/tbxctrl.hxx,sfx2/tbxctrl.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templdlg.hxx,sfx2/templdlg.hxx)) $(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/templatefolderview.hxx,sfx2/templatefolderview.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/thumbnailview.hxx,sfx2/thumbnailview.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/thumbnailviewitem.hxx,sfx2/thumbnailviewitem.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/titledockwin.hxx,sfx2/titledockwin.hxx)) diff --git a/sfx2/inc/sfx2/templatefolderview.hxx b/sfx2/inc/sfx2/templatefolderview.hxx new file mode 100644 index 0000000..ad56fcc --- /dev/null +++ b/sfx2/inc/sfx2/templatefolderview.hxx @@ -0,0 +1,35 @@ +/* -*- 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 <sfx2/thumbnailview.hxx> + +class SfxOrganizeMgr; + +class TemplateFolderView : public ThumbnailView +{ +public: + + TemplateFolderView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false ); + + virtual ~TemplateFolderView (); + + // Fill view with template folders thumbnails + void Populate (); + +private: + + SfxOrganizeMgr *mpMgr; +}; + +#endif // TEMPLATEFOLDERVIEW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx index 0bd2501..f54a549 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -24,7 +24,6 @@ class HelpEvent; class KeyEvent; class DataChangedEvent; class ScrollBar; -class SfxOrganizeMgr; struct ThumbnailViewItem; typedef ::std::vector< ThumbnailViewItem* > ValueItemList; @@ -168,9 +167,6 @@ public: virtual ~ThumbnailView (); - // Fill view with template thumbnails - void Populate (); - void InsertItem( sal_uInt16 nItemId, const BitmapEx &rImage, const rtl::OUString &rStr, size_t nPos = THUMBNAILVIEW_APPEND ); @@ -270,7 +266,7 @@ protected: virtual void DrawItem (ThumbnailViewItem *pItem); -private: +protected: friend class ThumbnailViewAcc; friend class ThumbnailViewItemAcc; @@ -305,7 +301,6 @@ protected: Timer maTimer; ValueItemList mItemList; - SfxOrganizeMgr *mpMgr; ScrollBar* mpScrBar; Rectangle maNoneItemRect; Rectangle maItemListRect; diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx index d475ef8..bb13fe0 100644 --- a/sfx2/inc/templatedlg.hxx +++ b/sfx2/inc/templatedlg.hxx @@ -13,7 +13,7 @@ #include <vcl/dialog.hxx> #include <vcl/button.hxx> -class ThumbnailView; +class TemplateFolderView; class SfxTemplateManagerDlg : public ModalDialog { @@ -42,7 +42,7 @@ private: PushButton aButtonDraws; ImageButton maButtonSelMode; - ThumbnailView *maView; + TemplateFolderView *maView; }; #endif // TEMPLATEDLG_HXX diff --git a/sfx2/source/control/templatefolderview.cxx b/sfx2/source/control/templatefolderview.cxx new file mode 100644 index 0000000..2f224e2 --- /dev/null +++ b/sfx2/source/control/templatefolderview.cxx @@ -0,0 +1,187 @@ +/* -*- 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/thumbnailviewitem.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> + +#include "orgmgr.hxx" + +BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height) +{ + using namespace ::com::sun::star; + using namespace ::com::sun::star::uno; + + // Load the thumbnail from a template document. + uno::Reference<io::XInputStream> xIStream; + + uno::Reference< lang::XMultiServiceFactory > xServiceManager ( + ::comphelper::getProcessServiceFactory()); + if (xServiceManager.is()) + { + try + { + uno::Reference<lang::XSingleServiceFactory> xStorageFactory( + xServiceManager->createInstance( "com.sun.star.embed.StorageFactory"), + uno::UNO_QUERY); + + if (xStorageFactory.is()) + { + uno::Sequence<uno::Any> aArgs (2); + aArgs[0] <<= msURL; + aArgs[1] <<= embed::ElementModes::READ; + uno::Reference<embed::XStorage> xDocStorage ( + xStorageFactory->createInstanceWithArguments(aArgs), + uno::UNO_QUERY); + + try + { + if (xDocStorage.is()) + { + uno::Reference<embed::XStorage> xStorage ( + xDocStorage->openStorageElement( + "Thumbnails", + embed::ElementModes::READ)); + if (xStorage.is()) + { + uno::Reference<io::XStream> xThumbnailCopy ( + xStorage->cloneStreamElement("thumbnail.png")); + if (xThumbnailCopy.is()) + xIStream = xThumbnailCopy->getInputStream(); + } + } + } + catch (const uno::Exception& rException) + { + OSL_TRACE ( + "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s", + ::rtl::OUStringToOString(msURL, + RTL_TEXTENCODING_UTF8).getStr(), + ::rtl::OUStringToOString(rException.Message, + RTL_TEXTENCODING_UTF8).getStr()); + } + + try + { + // An (older) implementation had a bug - The storage + // name was "Thumbnail" instead of "Thumbnails". The + // old name is still used as fallback but this code can + // be removed soon. + if ( ! xIStream.is()) + { + uno::Reference<embed::XStorage> xStorage ( + xDocStorage->openStorageElement( "Thumbnail", + embed::ElementModes::READ)); + if (xStorage.is()) + { + uno::Reference<io::XStream> xThumbnailCopy ( + xStorage->cloneStreamElement("thumbnail.png")); + if (xThumbnailCopy.is()) + xIStream = xThumbnailCopy->getInputStream(); + } + } + } + catch (const uno::Exception& rException) + { + OSL_TRACE ( + "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s", + ::rtl::OUStringToOString(msURL, + RTL_TEXTENCODING_UTF8).getStr(), + ::rtl::OUStringToOString(rException.Message, + RTL_TEXTENCODING_UTF8).getStr()); + } + } + } + catch (const uno::Exception& rException) + { + OSL_TRACE ( + "caught exception while trying to access tuhmbnail of %s: %s", + ::rtl::OUStringToOString(msURL, + RTL_TEXTENCODING_UTF8).getStr(), + ::rtl::OUStringToOString(rException.Message, + RTL_TEXTENCODING_UTF8).getStr()); + } + } + + // Extract the image from the stream. + BitmapEx aThumbnail; + if (xIStream.is()) + { + ::std::auto_ptr<SvStream> pStream ( + ::utl::UcbStreamHelper::CreateStream (xIStream)); + ::vcl::PNGReader aReader (*pStream); + aThumbnail = aReader.Read (); + } + + aThumbnail.Scale(Size(width,height)); + + // Note that the preview is returned without scaling it to the desired + // width. This gives the caller the chance to take advantage of a + // possibly larger resolution then was asked for. + return aThumbnail; +} + +TemplateFolderView::TemplateFolderView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren) + : ThumbnailView(pParent,rResId,bDisableTransientChildren), + mpMgr(new SfxOrganizeMgr(NULL,NULL)) +{ +} + +TemplateFolderView::~TemplateFolderView() +{ + delete mpMgr; +} + +void TemplateFolderView::Populate () +{ + const SfxDocumentTemplates* pTemplates = mpMgr->GetTemplates(); + + sal_uInt16 nCount = pTemplates->GetRegionCount(); + for (sal_uInt16 i = 0; i < nCount; ++i) + { + rtl::OUString aRegionName(pTemplates->GetFullRegionName(i)); + + sal_uInt16 nEntries = pTemplates->GetCount(i); + + if (nEntries) + { + ThumbnailViewItem* pItem = new ThumbnailViewItem( *this, this ); + pItem->mnId = i+1; + pItem->maText = aRegionName; + pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected)); + + /// Preview first 2 thumbnails for folder + pItem->maPreview1 = lcl_fetchThumbnail(pTemplates->GetPath(i,0),128,128); + + if ( nEntries > 2 ) + pItem->maPreview2 = lcl_fetchThumbnail(pTemplates->GetPath(i,1),128,128); + + mItemList.push_back(pItem); + } + } + + CalculateItemPositions(); + + if ( IsReallyVisible() && IsUpdateMode() ) + Invalidate(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + + diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index b4bb470..9ea0edd 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -9,9 +9,7 @@ #include <sfx2/thumbnailview.hxx> #include <sfx2/thumbnailviewitem.hxx> -#include <sfx2/doctempl.hxx> -#include "orgmgr.hxx" #include "thumbnailviewacc.hxx" #include <basegfx/color/bcolortools.hxx> @@ -19,7 +17,6 @@ #include <basegfx/range/b2drectangle.hxx> #include <basegfx/vector/b2dsize.hxx> #include <basegfx/vector/b2dvector.hxx> -#include <comphelper/processfactory.hxx> #include <drawinglayer/attribute/fillbitmapattribute.hxx> #include <drawinglayer/attribute/fontattribute.hxx> #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx> @@ -29,20 +26,13 @@ #include <drawinglayer/processor2d/baseprocessor2d.hxx> #include <drawinglayer/processor2d/processorfromoutputdevice.hxx> #include <rtl/ustring.hxx> -#include <unotools/ucbstreamhelper.hxx> #include <vcl/decoview.hxx> #include <vcl/svapp.hxx> #include <vcl/scrbar.hxx> #include <vcl/help.hxx> -#include <vcl/pngread.hxx> #include <com/sun/star/accessibility/AccessibleEventId.hpp> #include <com/sun/star/accessibility/AccessibleStateType.hpp> -#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> using namespace basegfx; using namespace basegfx::tools; @@ -61,120 +51,6 @@ enum SCROLL_OFFSET = 4 }; -BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height) -{ - using namespace ::com::sun::star; - using namespace ::com::sun::star::uno; - - // Load the thumbnail from a template document. - uno::Reference<io::XInputStream> xIStream; - - uno::Reference< lang::XMultiServiceFactory > xServiceManager ( - ::comphelper::getProcessServiceFactory()); - if (xServiceManager.is()) - { - try - { - uno::Reference<lang::XSingleServiceFactory> xStorageFactory( - xServiceManager->createInstance( "com.sun.star.embed.StorageFactory"), - uno::UNO_QUERY); - - if (xStorageFactory.is()) - { - uno::Sequence<uno::Any> aArgs (2); - aArgs[0] <<= msURL; - aArgs[1] <<= embed::ElementModes::READ; - uno::Reference<embed::XStorage> xDocStorage ( - xStorageFactory->createInstanceWithArguments(aArgs), - uno::UNO_QUERY); - - try - { - if (xDocStorage.is()) - { - uno::Reference<embed::XStorage> xStorage ( - xDocStorage->openStorageElement( - "Thumbnails", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference<io::XStream> xThumbnailCopy ( - xStorage->cloneStreamElement("thumbnail.png")); - if (xThumbnailCopy.is()) - xIStream = xThumbnailCopy->getInputStream(); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s", - ::rtl::OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - ::rtl::OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - - try - { - // An (older) implementation had a bug - The storage - // name was "Thumbnail" instead of "Thumbnails". The - // old name is still used as fallback but this code can - // be removed soon. - if ( ! xIStream.is()) - { - uno::Reference<embed::XStorage> xStorage ( - xDocStorage->openStorageElement( "Thumbnail", - embed::ElementModes::READ)); - if (xStorage.is()) - { - uno::Reference<io::XStream> xThumbnailCopy ( - xStorage->cloneStreamElement("thumbnail.png")); - if (xThumbnailCopy.is()) - xIStream = xThumbnailCopy->getInputStream(); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s", - ::rtl::OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - ::rtl::OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - } - } - catch (const uno::Exception& rException) - { - OSL_TRACE ( - "caught exception while trying to access tuhmbnail of %s: %s", - ::rtl::OUStringToOString(msURL, - RTL_TEXTENCODING_UTF8).getStr(), - ::rtl::OUStringToOString(rException.Message, - RTL_TEXTENCODING_UTF8).getStr()); - } - } - - // Extract the image from the stream. - BitmapEx aThumbnail; - if (xIStream.is()) - { - ::std::auto_ptr<SvStream> pStream ( - ::utl::UcbStreamHelper::CreateStream (xIStream)); - ::vcl::PNGReader aReader (*pStream); - aThumbnail = aReader.Read (); - } - - aThumbnail.Scale(Size(width,height)); - - // Note that the preview is returned without scaling it to the desired - // width. This gives the caller the chance to take advantage of a - // possibly larger resolution then was asked for. - return aThumbnail; -} - ThumbnailView::ThumbnailView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren) : Control( pParent, nWinStyle ), maColor( pParent->GetBackground().GetColor() ) @@ -200,7 +76,6 @@ ThumbnailView::~ThumbnailView() if (xComponent.is()) xComponent->dispose (); - delete mpMgr; delete mpScrBar; delete mpItemAttrs; @@ -209,7 +84,6 @@ ThumbnailView::~ThumbnailView() void ThumbnailView::ImplInit() { - mpMgr = new SfxOrganizeMgr(NULL,NULL); mpScrBar = NULL; mnItemWidth = 0; mnItemHeight = 0; @@ -1159,40 +1033,6 @@ void ThumbnailView::DataChanged( const DataChangedEvent& rDCEvt ) } } -void ThumbnailView::Populate () -{ - const SfxDocumentTemplates* pTemplates = mpMgr->GetTemplates(); - - sal_uInt16 nCount = pTemplates->GetRegionCount(); - for (sal_uInt16 i = 0; i < nCount; ++i) - { - rtl::OUString aRegionName(pTemplates->GetFullRegionName(i)); - - sal_uInt16 nEntries = pTemplates->GetCount(i); - - if (nEntries) - { - ThumbnailViewItem* pItem = new ThumbnailViewItem( *this, this ); - pItem->mnId = i+1; - pItem->maText = aRegionName; - pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnFolderSelected)); - - /// Preview first 2 thumbnails for folder - pItem->maPreview1 = lcl_fetchThumbnail(pTemplates->GetPath(i,0),128,128); - - if ( nEntries > 2 ) - pItem->maPreview2 = lcl_fetchThumbnail(pTemplates->GetPath(i,1),128,128); - - mItemList.push_back(pItem); - } - } - - CalculateItemPositions(); - - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); -} - void ThumbnailView::InsertItem( sal_uInt16 nItemId, const BitmapEx& rImage, const rtl::OUString& rText, size_t nPos ) { diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 48600d5..a7d5c32 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -10,7 +10,7 @@ #include "templatedlg.hxx" #include <sfx2/sfxresid.hxx> -#include <sfx2/thumbnailview.hxx> +#include <sfx2/templatefolderview.hxx> #include "doc.hrc" #include "templatedlg.hrc" @@ -26,7 +26,7 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent) aButtonSheets(this,SfxResId(BTN_SELECT_SHEETS)), aButtonDraws(this,SfxResId(BTN_SELECT_DRAWS)), maButtonSelMode(this,SfxResId(BTN_SELECTION_MODE)), - maView(new ThumbnailView(this,SfxResId(TEMPLATE_VIEW))) + maView(new TemplateFolderView(this,SfxResId(TEMPLATE_VIEW))) { maButtonSelMode.SetStyle(maButtonSelMode.GetStyle() | WB_TOGGLE); commit 4ee41fdfe79cafe35a3cd7ed3ad2142bbc5a3fbf Author: Rafael Dominguez <[email protected]> Date: Mon Jun 18 21:15:39 2012 -0430 Remove SetItemText function. Change-Id: Ie37f706baca178592c22d0f928f1ead43206f2a8 diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx index 60750a1..0bd2501 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -212,8 +212,6 @@ public: bool IsItemSelected( sal_uInt16 nItemId ) const { return nItemId == mnSelItemId; } - void SetItemText( sal_uInt16 nItemId, const rtl::OUString &rStr ); - rtl::OUString GetItemText( sal_uInt16 nItemId ) const; void SetColor( const Color& rColor ); diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index 3eaa08b..b4bb470 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -1453,44 +1453,6 @@ void ThumbnailView::SelectItem( sal_uInt16 nItemId ) } } -void ThumbnailView::SetItemText( sal_uInt16 nItemId, const rtl::OUString& rText ) -{ - size_t nPos = GetItemPos( nItemId ); - - if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND ) - return; - - - ThumbnailViewItem* pItem = mItemList[nPos]; - - // Remember old and new name for accessibility event. - ::com::sun::star::uno::Any aOldName, aNewName; - ::rtl::OUString sString (pItem->maText); - aOldName <<= sString; - sString = rText; - aNewName <<= sString; - - pItem->maText = rText; - - if ( IsReallyVisible() && IsUpdateMode() ) - { - sal_uInt16 nTempId = mnSelItemId; - - if ( mbHighlight ) - nTempId = mnHighItemId; - } - - if (ImplHasAccessibleListeners()) - { - ::com::sun::star::uno::Reference< - ::com::sun::star::accessibility::XAccessible> xAccessible ( - pItem->GetAccessible( mbIsTransientChildrenDisabled ) ); - static_cast<ThumbnailViewAcc*>(xAccessible.get())->FireAccessibleEvent ( - ::com::sun::star::accessibility::AccessibleEventId::NAME_CHANGED, - aOldName, aNewName); - } -} - rtl::OUString ThumbnailView::GetItemText( sal_uInt16 nItemId ) const { size_t nPos = GetItemPos( nItemId ); commit d338cd728efb83fe5983bac5f97afd782460824e Author: Rafael Dominguez <[email protected]> Date: Mon Jun 18 21:05:29 2012 -0430 Handle item paint inside its own method. - Dont recreate drawinglayer processor in each paint call. - Create a structure to set thumbnail item attributes. Change-Id: I95aec60fc05cc60f96f0bca6748b94327febd69f diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx index 1fe45f0..60750a1 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -28,9 +28,16 @@ class SfxOrganizeMgr; struct ThumbnailViewItem; typedef ::std::vector< ThumbnailViewItem* > ValueItemList; +class ThumbnailItemAttributes; class ThumbnailViewAcc; class ThumbnailViewItemAcc; +namespace drawinglayer { + namespace processor2d { + class BaseProcessor2D; + } +} + /************************************************************************* Description @@ -329,6 +336,9 @@ protected: bool mbHasVisibleItems : 1; bool mbSelectionMode; Color maColor; + + ThumbnailItemAttributes *mpItemAttrs; + drawinglayer::processor2d::BaseProcessor2D *mpProcessor; }; #endif // THUMBNAILVIEW_HXX diff --git a/sfx2/inc/sfx2/thumbnailviewitem.hxx b/sfx2/inc/sfx2/thumbnailviewitem.hxx index 7cc6252..81d4bdd 100644 --- a/sfx2/inc/sfx2/thumbnailviewitem.hxx +++ b/sfx2/inc/sfx2/thumbnailviewitem.hxx @@ -29,6 +29,8 @@ #ifndef THUMBNAILVIEWITEM_HXX #define THUMBNAILVIEWITEM_HXX +#include <basegfx/vector/b2dvector.hxx> +#include <drawinglayer/attribute/fontattribute.hxx> #include <osl/mutex.hxx> #include <vcl/bitmapex.hxx> @@ -37,9 +39,24 @@ #define THUMBNAILVIEW_ITEM_NONEITEM 0xFFFE class CheckBox; +class Font; class Window; class ThumbnailView; +namespace drawinglayer { + namespace processor2d { + class BaseProcessor2D; + } +} + +struct ThumbnailItemAttributes +{ + basegfx::BColor aFillColor; + basegfx::BColor aHighlightColor; + basegfx::B2DVector aFontSize; + drawinglayer::attribute::FontAttribute aFontAttr; +}; + struct ThumbnailViewItem { ThumbnailView &mrParent; @@ -89,7 +106,8 @@ struct ThumbnailViewItem bool isInsideTitle (const Point &pt) const; - void Paint (const Rectangle &aRect); + void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor, + const ThumbnailItemAttributes *pAttrs); private: @@ -106,6 +124,9 @@ private: CheckBox *mpSelectBox; }; +// Helper function to convert a rectangle to a polygon. +basegfx::B2DPolygon Rect2Polygon (const Rectangle &aRect); + #endif // THUMBNAILVIEWITEM_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index c8a2959..3eaa08b 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -16,7 +16,6 @@ #include <basegfx/color/bcolortools.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> -#include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/range/b2drectangle.hxx> #include <basegfx/vector/b2dsize.hxx> #include <basegfx/vector/b2dvector.hxx> @@ -62,17 +61,6 @@ enum SCROLL_OFFSET = 4 }; -B2DPolygon lcl_Rect2Polygon (const Rectangle &aRect) -{ - B2DPolygon aPolygon; - aPolygon.append(B2DPoint(aRect.Left(),aRect.Top())); - aPolygon.append(B2DPoint(aRect.Left(),aRect.Bottom())); - aPolygon.append(B2DPoint(aRect.Right(),aRect.Bottom())); - aPolygon.append(B2DPoint(aRect.Right(),aRect.Top())); - - return aPolygon; -} - BitmapEx lcl_fetchThumbnail (const rtl::OUString &msURL, int width, int height) { using namespace ::com::sun::star; @@ -214,6 +202,7 @@ ThumbnailView::~ThumbnailView() delete mpMgr; delete mpScrBar; + delete mpItemAttrs; ImplDeleteItems(); } @@ -246,6 +235,10 @@ void ThumbnailView::ImplInit() mbHasVisibleItems = false; mbSelectionMode = false; + // Create the processor and process the primitives + const drawinglayer::geometry::ViewInformation2D aNewViewInfos; + mpProcessor = drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*this, aNewViewInfos ); + ImplInitSettings( true, true, true ); } @@ -303,6 +296,11 @@ void ThumbnailView::ImplInitSettings( bool bFont, bool bForeground, bool bBackgr aColor = rStyleSettings.GetFaceColor(); SetBackground( aColor ); } + + mpItemAttrs = new ThumbnailItemAttributes; + mpItemAttrs->aFillColor = maColor.getBColor(); + mpItemAttrs->aHighlightColor = rStyleSettings.GetHighlightColor().getBColor(); + mpItemAttrs->aFontAttr = getFontAttributeFromVclFont(mpItemAttrs->aFontSize,GetFont(),false,true); } void ThumbnailView::ImplInitScrollBar() @@ -328,87 +326,7 @@ void ThumbnailView::DrawItem (ThumbnailViewItem *pItem) Rectangle aRect = pItem->getDrawArea(); if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) ) - { - int nCount = 0; - int nSeqSize = 3; - - if (!pItem->maPreview2.IsEmpty()) - ++nSeqSize; - - Primitive2DSequence aSeq(nSeqSize); - - const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); - - // Draw item background - BColor aFillColor = maColor.getBColor(); - - if ( pItem->isSelected() || pItem->isHighlighted() ) - aFillColor = rStyleSettings.GetHighlightColor().getBColor(); - - aSeq[nCount++] = Primitive2DReference( new PolyPolygonColorPrimitive2D( - B2DPolyPolygon(lcl_Rect2Polygon(aRect)), - aFillColor)); - - // Draw thumbnail - Point aPos = pItem->getPrev1Pos(); - Size aImageSize = pItem->maPreview1.GetSizePixel(); - - float fScaleX = 1.0f; - float fScaleY = 1.0f; - - if (!pItem->maPreview2.IsEmpty()) - { - fScaleX = 0.8; - fScaleY = 0.8; - - aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D( - createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()), - FillBitmapAttribute(pItem->maPreview2, - B2DPoint(35,20), - B2DVector(aImageSize.Width(),aImageSize.Height()), - false) - )); - } - - aSeq[nCount++] = Primitive2DReference( new FillBitmapPrimitive2D( - createScaleTranslateB2DHomMatrix(fScaleX,fScaleY,aPos.X(),aPos.Y()), - FillBitmapAttribute(pItem->maPreview1, - B2DPoint(0,0), - B2DVector(aImageSize.Width(),aImageSize.Height()), - false) - )); - - // Draw centered text below thumbnail - aPos = pItem->getTextPos(); - - // Create the text primitive - B2DVector aFontSize; - FontAttribute aFontAttr = getFontAttributeFromVclFont( - aFontSize, GetFont(), false, true ); - - - basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix( - aFontSize.getX(), aFontSize.getY(), - double( aPos.X() ), double( aPos.Y() ) ) ); - - aSeq[nCount++] = Primitive2DReference( - new TextSimplePortionPrimitive2D(aTextMatrix, - pItem->maText,0,pItem->maText.getLength(), - std::vector< double >( ), - aFontAttr, - com::sun::star::lang::Locale(), - Color(COL_BLACK).getBColor() ) ); - - // Create the processor and process the primitives - const drawinglayer::geometry::ViewInformation2D aNewViewInfos; - drawinglayer::processor2d::BaseProcessor2D * pProcessor = - drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice( - *this, aNewViewInfos ); - - pProcessor->process(aSeq); - - pItem->Paint(aRect); - } + pItem->Paint(mpProcessor,mpItemAttrs); } ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ThumbnailView::CreateAccessible() @@ -1585,7 +1503,9 @@ rtl::OUString ThumbnailView::GetItemText( sal_uInt16 nItemId ) const void ThumbnailView::SetColor( const Color& rColor ) { - maColor = rColor; + maColor = rColor; + mpItemAttrs->aFillColor = rColor.getBColor(); + if ( IsReallyVisible() && IsUpdateMode() ) Invalidate(); } diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx index 5e4685d..b9f4ad0 100644 --- a/sfx2/source/control/thumbnailviewitem.cxx +++ b/sfx2/source/control/thumbnailviewitem.cxx @@ -26,14 +26,28 @@ * ************************************************************************/ +#include <sfx2/thumbnailviewitem.hxx> + #include "thumbnailviewacc.hxx" +#include <basegfx/matrix/b2dhommatrixtools.hxx> +#include <basegfx/range/b2drectangle.hxx> +#include <basegfx/vector/b2dsize.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 <sfx2/thumbnailviewitem.hxx> +#include <drawinglayer/primitive2d/textprimitive2d.hxx> +#include <drawinglayer/processor2d/baseprocessor2d.hxx> #include <vcl/button.hxx> #include <vcl/svapp.hxx> +using namespace basegfx; +using namespace basegfx::tools; using namespace ::com::sun::star; +using namespace drawinglayer::attribute; +using namespace drawinglayer::primitive2d; ThumbnailViewItem::ThumbnailViewItem(ThumbnailView &rView, Window *pParent) : mrParent(rView) @@ -149,10 +163,75 @@ bool ThumbnailViewItem::isInsideTitle (const Point &pt) const return aRect.IsInside(pt); } -void ThumbnailViewItem::Paint (const Rectangle &aRect) +void ThumbnailViewItem::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(Rect2Polygon(maDrawArea)), + aFillColor)); + + // Draw thumbnail + Point aPos = maPrev1Pos; + Size aImageSize = maPreview1.GetSizePixel(); + + float fScaleX = 1.0f; + float fScaleY = 1.0f; + + if (!maPreview2.IsEmpty()) + { + fScaleX = 0.8; + fScaleY = 0.8; + + 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, + maText,0,maText.getLength(), + std::vector< double >( ), + pAttrs->aFontAttr, + com::sun::star::lang::Locale(), + Color(COL_BLACK).getBColor() ) ); + + pProcessor->process(aSeq); + if (mbMode || mbHover || mbSelected) - mpSelectBox->Paint(aRect); + mpSelectBox->Paint(maDrawArea); } IMPL_LINK (ThumbnailViewItem, OnClick, CheckBox*, ) @@ -163,6 +242,17 @@ IMPL_LINK (ThumbnailViewItem, OnClick, CheckBox*, ) return 0; } +basegfx::B2DPolygon Rect2Polygon (const Rectangle &aRect) +{ + basegfx::B2DPolygon aPolygon; + aPolygon.append(basegfx::B2DPoint(aRect.Left(),aRect.Top())); + aPolygon.append(basegfx::B2DPoint(aRect.Left(),aRect.Bottom())); + aPolygon.append(basegfx::B2DPoint(aRect.Right(),aRect.Bottom())); + aPolygon.append(basegfx::B2DPoint(aRect.Right(),aRect.Top())); + + return aPolygon; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 406c66af52b416864a1de29f77f58223e75759b0 Author: Rafael Dominguez <[email protected]> Date: Mon Jun 18 18:57:31 2012 -0430 Dont paint selection box if its hidden. Change-Id: If618c913205ffa89b6afaf18244c85fce5c6e804 diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx index f86bfd0..5e4685d 100644 --- a/sfx2/source/control/thumbnailviewitem.cxx +++ b/sfx2/source/control/thumbnailviewitem.cxx @@ -151,7 +151,8 @@ bool ThumbnailViewItem::isInsideTitle (const Point &pt) const void ThumbnailViewItem::Paint (const Rectangle &aRect) { - mpSelectBox->Paint(aRect); + if (mbMode || mbHover || mbSelected) + mpSelectBox->Paint(aRect); } IMPL_LINK (ThumbnailViewItem, OnClick, CheckBox*, ) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
