diff options
author | Petr Mladek <pmladek@suse.cz> | 2013-05-01 13:05:06 +0200 |
---|---|---|
committer | Petr Mladek <pmladek@suse.cz> | 2013-05-01 13:05:06 +0200 |
commit | 93e11e4fb697aaea63c99308f980e4c932bd1efa (patch) | |
tree | 1892e49932d8d7b7656ae504113a40e4e39f876f /sfx2 | |
parent | a5b6a379a2d628040db98060c2adfe8f2fac5607 (diff) | |
parent | c6786add5a58268e11aa027c47054344040db1bc (diff) |
Merge tag 'libreoffice-4.0.3.2' into suse-4.0
Tag libreoffice-4.0.3.2
Conflicts:
basic/qa/cppunit/test_vba.cxx
basic/source/runtime/step2.cxx
dictionaries
helpcontent2
instsetoo_native/util/openoffice.lst
libvisio/UnpackedTarball_visio.mk
sc/source/ui/vba/vbaapplication.cxx
sc/source/ui/vba/vbavalidation.cxx
solenv/inc/minor.mk
sw/qa/extras/ooxmlimport/ooxmlimport.cxx
translations
Change-Id: Ic1f06489175f3db92d6bbcebb9732fadc1c61fed
Diffstat (limited to 'sfx2')
28 files changed, 1672 insertions, 1074 deletions
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index bab643a6be30..28e8ab660457 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -71,7 +71,7 @@ $(eval $(call gb_Library_use_libraries,sfx,\ ucbhelper \ utl \ vcl \ - $(gb_UWINAPI) \ + $(gb_UWINAPI) \ )) $(eval $(call gb_Library_use_external,sfx,libxml2)) @@ -138,7 +138,6 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/sorgitm \ sfx2/source/control/statcach \ sfx2/source/control/templateabstractview \ - sfx2/source/control/templateview \ sfx2/source/control/templateviewitem \ sfx2/source/control/templatelocalview \ sfx2/source/control/templatecontaineritem \ @@ -150,7 +149,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/unoctitm \ sfx2/source/dialog/alienwarn \ sfx2/source/dialog/basedlgs \ - sfx2/source/dialog/checkin \ + sfx2/source/dialog/checkin \ sfx2/source/dialog/dinfdlg \ sfx2/source/dialog/dinfedt \ sfx2/source/dialog/dockwin \ @@ -295,11 +294,11 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ )) $(eval $(call gb_Library_use_system_win32_libs,sfx,\ - advapi32 \ - gdi32 \ - ole32 \ - shell32 \ - uuid \ + advapi32 \ + gdi32 \ + ole32 \ + shell32 \ + uuid \ )) endif diff --git a/sfx2/Package_inc.mk b/sfx2/Package_inc.mk index aa368b7e4f00..228cc625b313 100644 --- a/sfx2/Package_inc.mk +++ b/sfx2/Package_inc.mk @@ -120,7 +120,6 @@ $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templdlg.hxx,sfx2/templdlg.h $(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/templateabstractview.hxx,sfx2/templateabstractview.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateinfodlg.hxx,sfx2/templateinfodlg.hxx)) -$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateview.hxx,sfx2/templateview.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocalview.hxx,sfx2/templatelocalview.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatecontaineritem.hxx,sfx2/templatecontaineritem.hxx)) $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateremoteview.hxx,sfx2/templateremoteview.hxx)) diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx index b9ca56d70137..add39df0d603 100644 --- a/sfx2/inc/sfx2/doctempl.hxx +++ b/sfx2/inc/sfx2/doctempl.hxx @@ -96,6 +96,8 @@ public: sal_Bool InsertDir(const String &rText, sal_uInt16 nRegion); sal_Bool SetName(const String &rName, sal_uInt16 nRegion, sal_uInt16 nIdx); + sal_Bool InsertTemplate (sal_uInt16 nSourceRegion, sal_uInt16 nIdx, const OUString &rName, const OUString &rPath); + /** Change the name of an entry or a directory \param rName diff --git a/sfx2/inc/sfx2/templateabstractview.hxx b/sfx2/inc/sfx2/templateabstractview.hxx index ca5118109a0d..f14efada5fbc 100644 --- a/sfx2/inc/sfx2/templateabstractview.hxx +++ b/sfx2/inc/sfx2/templateabstractview.hxx @@ -10,20 +10,25 @@ #ifndef __SFX2_TEMPLATEABSTRACTVIEW_HXX__ #define __SFX2_TEMPLATEABSTRACTVIEW_HXX__ +#include <sfx2/templateproperties.hxx> #include <sfx2/thumbnailview.hxx> +#include <vcl/button.hxx> +#include <vcl/fixed.hxx> //template thumbnail item defines #define TEMPLATE_ITEM_MAX_WIDTH 160 -#define TEMPLATE_ITEM_MAX_HEIGHT 160 +#define TEMPLATE_ITEM_MAX_HEIGHT 140 #define TEMPLATE_ITEM_PADDING 5 #define TEMPLATE_ITEM_MAX_TEXT_LENGTH 20 #define TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT 88 +//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 TemplateView; class SfxDocumentTemplates; enum FILTER_APPLICATION @@ -80,60 +85,59 @@ public: virtual ~TemplateAbstractView (); - // Fill view with template folders thumbnails - virtual void Populate () { }; - - virtual void reload () { }; + void insertItem (const TemplateItemProperties &rTemplate); - virtual void filterTemplatesByApp (const FILTER_APPLICATION &eApp); + // Fill view with new item list + void insertItems (const std::vector<TemplateItemProperties> &rTemplates); - virtual void showOverlay (bool bVisible) = 0; - - void setItemDimensions (long ItemWidth, long ThumbnailHeight, long DisplayHeight, int itemPadding); + // Fill view with template folders thumbnails + virtual void Populate () { } - sal_uInt16 getOverlayRegionId () const; + virtual void reload () { } - const OUString& getOverlayName () const; + virtual void showRootRegion () = 0; - // Check if the overlay is visible or not. - bool isOverlayVisible () const; + virtual void showRegion (ThumbnailViewItem *pItem) = 0; - void deselectOverlayItems (); + // Return if we can have regions inside the current region + virtual bool isNestedRegionAllowed () const = 0; - void deselectOverlayItem (const sal_uInt16 nItemId); + // Return if we can import templates to the current region + virtual bool isImportAllowed () const = 0; - void sortOverlayItems (const boost::function<bool (const ThumbnailViewItem*, - const ThumbnailViewItem*) > &func); + sal_uInt16 getCurRegionId () const; - virtual void filterTemplatesByKeyword (const OUString &rKeyword); + const OUString& getCurRegionName () const; - void setOverlayItemStateHdl (const Link &aLink) { maOverlayItemStateHdl = aLink; } + // Check if the root region is visible or not. + bool isNonRootRegionVisible () const; - void setOverlayDblClickHdl (const Link &rLink); + void setOpenRegionHdl(const Link &rLink); - void setOverlayCloseHdl (const Link &rLink); + void setOpenTemplateHdl (const Link &rLink); static BitmapEx scaleImg (const BitmapEx &rImg, long width, long height); - static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height); + static BitmapEx getDefaultThumbnail( const rtl::OUString& rPath ); - virtual void Resize(); + static BitmapEx fetchThumbnail (const OUString &msURL, long width, long height); protected: - virtual void Paint( const Rectangle& rRect ); + DECL_LINK(ShowRootRegionHdl, void*); - virtual void DrawItem (ThumbnailViewItem *pItem); - - DECL_LINK(OverlayItemStateHdl, const ThumbnailViewItem*); + virtual void OnItemDblClicked(ThumbnailViewItem *pItem); protected: - TemplateView *mpItemView; - Link maOverlayItemStateHdl; + sal_uInt16 mnCurRegionId; + OUString maCurRegionName; + + PushButton maAllButton; + FixedText maFTName; - bool mbFilteredResults; // Flag keep track if overlay has been filtered so folders can get filtered too afterwards - FILTER_APPLICATION meFilterOption; + Link maOpenRegionHdl; + Link maOpenTemplateHdl; }; #endif // __SFX2_TEMPLATEABSTRACTVIEW_HXX__ diff --git a/sfx2/inc/sfx2/templatecontaineritem.hxx b/sfx2/inc/sfx2/templatecontaineritem.hxx index 476860433c47..527571c80cac 100644 --- a/sfx2/inc/sfx2/templatecontaineritem.hxx +++ b/sfx2/inc/sfx2/templatecontaineritem.hxx @@ -17,6 +17,7 @@ class TemplateContainerItem : public ThumbnailViewItem { public: + sal_uInt16 mnRegionId; BitmapEx maPreview2; BitmapEx maPreview3; BitmapEx maPreview4; diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx index 78cf5479bc91..09b69ce762ce 100644 --- a/sfx2/inc/sfx2/templatelocalview.hxx +++ b/sfx2/inc/sfx2/templatelocalview.hxx @@ -13,7 +13,6 @@ #include <set> #include <sfx2/templateabstractview.hxx> -#include <sfx2/templateproperties.hxx> class SfxDocumentTemplates; class TemplateContainerItem; @@ -26,6 +25,8 @@ namespace com { class SFX2_DLLPUBLIC TemplateLocalView : public TemplateAbstractView { + typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*); + public: TemplateLocalView ( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false ); @@ -37,26 +38,45 @@ public: virtual void reload (); - std::vector<OUString> getFolderNames (); + virtual void showRootRegion (); + + virtual void showRegion (ThumbnailViewItem *pItem); + + void showRegion (const OUString &rName); - virtual void showOverlay (bool bVisible); + sal_uInt16 getCurRegionItemId () const; + + sal_uInt16 getRegionId (size_t pos) const; + + OUString getRegionName(const sal_uInt16 nRegionId) const; + + OUString getRegionItemName(const sal_uInt16 nItemId) const; + + std::vector<OUString> getFolderNames (); std::vector<TemplateItemProperties> getFilteredItems (const boost::function<bool (const TemplateItemProperties&) > &rFunc) const; sal_uInt16 createRegion (const OUString &rName); + virtual bool isNestedRegionAllowed () const; + + virtual bool isImportAllowed () const; + bool removeRegion (const sal_uInt16 nItemId); bool removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId); bool moveTemplate (const ThumbnailViewItem* pItem, const sal_uInt16 nSrcItem, - const sal_uInt16 nTargetItem, bool bCopy); + const sal_uInt16 nTargetItem); - bool moveTemplates (std::set<const ThumbnailViewItem*> &rItems, const sal_uInt16 nTargetItem, bool bCopy); + bool moveTemplates (const std::set<const ThumbnailViewItem*,selection_cmp_fn> &rItems, const sal_uInt16 nTargetItem); bool copyFrom (const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath); + // Import a template to the current region + bool copyFrom (const OUString &rPath); + bool copyFrom(TemplateContainerItem *pItem, const OUString &rPath); bool exportTo (const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, const OUString &rName); @@ -65,7 +85,7 @@ public: com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel, const OUString &rName); - bool saveTemplateAs (const TemplateContainerItem *pDstItem, + bool saveTemplateAs (TemplateContainerItem *pDstItem, com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel, const OUString &rName); @@ -75,11 +95,8 @@ public: private: - virtual void OnItemDblClicked (ThumbnailViewItem *pRegionItem); - -private: - SfxDocumentTemplates *mpDocTemplates; + std::vector<TemplateContainerItem* > maRegions; }; #endif // TEMPLATEFOLDERVIEW_HXX diff --git a/sfx2/inc/sfx2/templateproperties.hxx b/sfx2/inc/sfx2/templateproperties.hxx index 0760f604242d..1f109c525105 100644 --- a/sfx2/inc/sfx2/templateproperties.hxx +++ b/sfx2/inc/sfx2/templateproperties.hxx @@ -15,6 +15,7 @@ struct TemplateItemProperties { + bool aIsFolder; sal_uInt16 nId; ///< Index for ThumbnailView sal_uInt16 nDocId; ///< Index based on SfxTemplateDocument sal_uInt16 nRegionId; diff --git a/sfx2/inc/sfx2/templateremoteview.hxx b/sfx2/inc/sfx2/templateremoteview.hxx index bd1bf5cad34a..01a582fe0698 100644 --- a/sfx2/inc/sfx2/templateremoteview.hxx +++ b/sfx2/inc/sfx2/templateremoteview.hxx @@ -25,10 +25,16 @@ public: virtual ~TemplateRemoteView (); - virtual void showOverlay (bool bVisible); + virtual void showRootRegion (); + + virtual void showRegion (ThumbnailViewItem *pItem); bool loadRepository (TemplateRepository* pRepository, bool bRefresh); + virtual bool isNestedRegionAllowed () const; + + virtual bool isImportAllowed () const; + private: com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCmdEnv; diff --git a/sfx2/inc/sfx2/templateview.hxx b/sfx2/inc/sfx2/templateview.hxx deleted file mode 100644 index 3e2a7c846a2d..000000000000 --- a/sfx2/inc/sfx2/templateview.hxx +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- 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 TEMPLATEVIEW_HXX -#define TEMPLATEVIEW_HXX - -#include <sfx2/templateproperties.hxx> -#include <sfx2/thumbnailview.hxx> -#include <vcl/button.hxx> -#include <vcl/fixed.hxx> - -class Edit; -class TemplateViewItem; - -class TemplateView : public ThumbnailView -{ -public: - - TemplateView (Window *pParent); - - virtual ~TemplateView (); - - void setId (const sal_uInt16 nId) { mnId = nId; } - - sal_uInt16 getId () const { return mnId; } - - void setName (const OUString &rName); - - const OUString& getName () const { return maName; } - - void InsertItems (const std::vector<TemplateItemProperties> &rTemplates); - - void setDblClickHdl (const Link &rLink) { maDblClickHdl = rLink; } - - void setCloseHdl (const Link &rLink) { maAllButton.SetClickHdl(rLink); } - void setMasterView(TemplateAbstractView* pMasterView) { mpMasterView = pMasterView; } - virtual bool renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle); - -protected: - - virtual void Resize (); - - virtual void OnItemDblClicked (ThumbnailViewItem *pItem); - -private: - TemplateAbstractView* mpMasterView; - - Control maButtons; - PushButton maAllButton; - FixedText maFTName; - sal_uInt16 mnId; - OUString maName; - Link maDblClickHdl; -}; - -#endif // TEMPLATEVIEW_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ - diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx index 8eb94267fde3..1286385d680b 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -179,16 +179,23 @@ public: virtual ~ThumbnailView (); + void AppendItem (ThumbnailViewItem *pItem); + void RemoveItem( sal_uInt16 nItemId ); void Clear(); + // Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item) + void updateItems(const std::vector<ThumbnailViewItem *> &items); + size_t GetItemPos( sal_uInt16 nItemId ) const; sal_uInt16 GetItemId( size_t nPos ) const; sal_uInt16 GetItemId( const Point& rPos ) const; + sal_uInt16 getNextItemId () const; + long GetItemWidth() const { return mnItemWidth; } long GetItemHeight() const { return mnItemHeight; } @@ -202,10 +209,9 @@ public: void SelectItem( sal_uInt16 nItemId ); - sal_uInt16 GetSelectItemId() const { return mnSelItemId; } + void DeselectItem( sal_uInt16 nItemId ); - bool IsItemSelected( sal_uInt16 nItemId ) const - { return nItemId == mnSelItemId; } + bool IsItemSelected( sal_uInt16 nItemId ) const; void deselectItem (const sal_uInt16 nItemId); @@ -242,6 +248,8 @@ public: protected: + virtual void KeyInput( const KeyEvent& rKEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); virtual void MouseButtonUp( const MouseEvent& rMEvt ); @@ -258,8 +266,6 @@ protected: virtual void DataChanged( const DataChangedEvent& rDCEvt ); - virtual bool StartDrag( const CommandEvent& rCEvt, Region& rRegion ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible(); protected: @@ -277,9 +283,8 @@ protected: using Control::ImplInitSettings; using Window::ImplInit; - void calculateColumnsRows (); - void CalculateItemPositions (); + void MakeItemVisible( sal_uInt16 nId ); SFX2_DLLPRIVATE void ImplInit(); SFX2_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground ); @@ -299,6 +304,8 @@ protected: protected: ValueItemList mItemList; + ValueItemList mFilteredItemList; ///< Cache to store the filtered items + ValueItemList::iterator mpStartSelRange; ScrollBar* mpScrBar; Rectangle maItemListRect; long mnHeaderHeight; @@ -310,7 +317,6 @@ protected: long mnVisLines; long mnLines; sal_uInt16 mnScrBarOffset; - sal_uInt16 mnSelItemId; sal_uInt16 mnHighItemId; sal_uInt16 mnCols; sal_uInt16 mnFirstLine; diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx index 47c1989adb06..343a9ef56ad4 100644 --- a/sfx2/inc/templatedlg.hxx +++ b/sfx2/inc/templatedlg.hxx @@ -15,6 +15,7 @@ #include <vcl/dialog.hxx> #include <vcl/button.hxx> #include <vcl/tabctrl.hxx> +#include <vcl/tabpage.hxx> class Edit; class PopupMenu; @@ -37,6 +38,8 @@ namespace com { class SfxTemplateManagerDlg : public ModelessDialog { + typedef bool (*selection_cmp_fn)(const ThumbnailViewItem*,const ThumbnailViewItem*); + public: SfxTemplateManagerDlg (Window *parent = DIALOG_NO_PARENT); @@ -49,29 +52,27 @@ public: DECL_LINK(ActivatePageHdl, void*); - static BitmapEx getDefaultThumbnail( const rtl::OUString& rPath ); - private: - virtual void MouseButtonDown( const MouseEvent& rMEvt ); + void readSettings (); - virtual void Resize (); + void writeSettings (); - DECL_LINK(CloseOverlayHdl, void*); + virtual void Resize (); DECL_LINK(TBXViewHdl, void*); DECL_LINK(TBXActionHdl, void*); DECL_LINK(TBXTemplateHdl, void*); DECL_LINK(TBXDropdownHdl, ToolBox*); - DECL_LINK(TVFolderStateHdl, const ThumbnailViewItem*); - DECL_LINK(TVTemplateStateHdl, const ThumbnailViewItem*); + DECL_LINK(TVItemStateHdl, const ThumbnailViewItem*); DECL_LINK(MenuSelectHdl, Menu*); DECL_LINK(MoveMenuSelectHdl, Menu*); DECL_LINK(RepositoryMenuSelectHdl, Menu*); DECL_LINK(DefaultTemplateMenuSelectHdl, Menu*); + DECL_LINK(OpenRegionHdl, void*); DECL_LINK(OpenTemplateHdl, ThumbnailViewItem*); DECL_LINK(SearchUpdateHdl, void*); @@ -83,7 +84,13 @@ private: void OnTemplateDelete (); void OnTemplateAsDefault (); void OnTemplateExport (); + + void OnTemplateState (const ThumbnailViewItem *pItem); + void OnFolderDelete (); + + void OnRegionState (const ThumbnailViewItem *pItem); + void OnRepositoryDelete (); void OnTemplateSaveAs (); @@ -126,7 +133,7 @@ private: private: TabControl maTabControl; - Control *mpToolbars; + TabPage maTabPage; Edit *mpSearchEdit; ToolBox *mpViewBar; @@ -140,8 +147,8 @@ private: PopupMenu *mpRepositoryMenu; PopupMenu *mpTemplateDefaultMenu; - std::set<const ThumbnailViewItem*> maSelTemplates; - std::set<const ThumbnailViewItem*> maSelFolders; + std::set<const ThumbnailViewItem*,selection_cmp_fn> maSelTemplates; + std::set<const ThumbnailViewItem*,selection_cmp_fn> maSelFolders; bool mbIsSaveMode; ///< Flag that indicates if we are in save mode or not. com::sun::star::uno::Reference< com::sun::star::frame::XModel > m_xModel; diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx index de2091f22ecd..e28d2e83dbf3 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -8,10 +8,10 @@ */ #include <sfx2/templateabstractview.hxx> -#include <sfx2/templatecontaineritem.hxx> #include <comphelper/processfactory.hxx> -#include <sfx2/templateview.hxx> +#include <sfx2/sfxresid.hxx> +#include <sfx2/templatecontaineritem.hxx> #include <sfx2/templateviewitem.hxx> #include <tools/urlobj.hxx> #include <unotools/ucbstreamhelper.hxx> @@ -23,6 +23,9 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include "../doc/doc.hrc" +#include "templateview.hrc" + bool ViewFilter_Application::isValid (const OUString &rPath) const { bool bRet = true; @@ -99,8 +102,6 @@ bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem) } } } - - return mApp != FILTER_APP_NONE ? nVisCount : true ; } return true; } @@ -114,111 +115,111 @@ bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem) TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren) : ThumbnailView(pParent,nWinStyle,bDisableTransientChildren), - mpItemView(new TemplateView(this)), - mbFilteredResults(false), - meFilterOption(FILTER_APP_WRITER) + mnCurRegionId(0), + maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)), + maFTName(this, SfxResId(FT_NAME)) { - mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl)); + maAllButton.Hide(); + maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON); + maAllButton.SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl)); + maFTName.Hide(); } TemplateAbstractView::TemplateAbstractView(Window *pParent, const ResId &rResId, bool bDisableTransientChildren) : ThumbnailView(pParent,rResId,bDisableTransientChildren), - mpItemView(new TemplateView(this)), - mbFilteredResults(false), - meFilterOption(FILTER_APP_WRITER) + mnCurRegionId(0), + maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)), + maFTName(this, SfxResId(FT_NAME)) { - mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl)); + maAllButton.Hide(); + maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON); + maAllButton.SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl)); + maFTName.Hide(); } TemplateAbstractView::~TemplateAbstractView () { - delete mpItemView; } -void TemplateAbstractView::setItemDimensions(long ItemWidth, long ThumbnailHeight, long DisplayHeight, int itemPadding) +void TemplateAbstractView::insertItem(const TemplateItemProperties &rTemplate) { - ThumbnailView::setItemDimensions(ItemWidth,ThumbnailHeight,DisplayHeight,itemPadding); + const TemplateItemProperties *pCur = &rTemplate; - mpItemView->setItemDimensions(ItemWidth,ThumbnailHeight,DisplayHeight,itemPadding); -} - -sal_uInt16 TemplateAbstractView::getOverlayRegionId() const -{ - return mpItemView->getId(); -} + TemplateViewItem *pChild = new TemplateViewItem(*this); + pChild->mnId = pCur->nId; + pChild->mnDocId = pCur->nDocId; + pChild->mnRegionId = pCur->nRegionId; + pChild->maTitle = pCur->aName; + pChild->setPath(pCur->aPath); + pChild->maPreview1 = pCur->aThumbnail; -const OUString &TemplateAbstractView::getOverlayName() const -{ - return mpItemView->getName(); -} + if ( pCur->aThumbnail.IsEmpty() ) + { + // Use the default thumbnail if we have nothing else + pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath); + } -bool TemplateAbstractView::isOverlayVisible () const -{ - return mpItemView->IsVisible(); -} + pChild->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); -void TemplateAbstractView::deselectOverlayItems() -{ - mpItemView->deselectItems(); -} + AppendItem(pChild); -void TemplateAbstractView::deselectOverlayItem(const sal_uInt16 nItemId) -{ - mpItemView->deselectItem(nItemId); + CalculateItemPositions(); + Invalidate(); } -void TemplateAbstractView::sortOverlayItems(const boost::function<bool (const ThumbnailViewItem*, - const ThumbnailViewItem*) > &func) +void TemplateAbstractView::insertItems(const std::vector<TemplateItemProperties> &rTemplates) { - mpItemView->sortItems(func); -} + std::vector<ThumbnailViewItem*> aItems(rTemplates.size()); + for (size_t i = 0, n = rTemplates.size(); i < n; ++i ) + { + //TODO: CHECK IF THE ITEM IS A FOLDER OR NOT + TemplateViewItem *pChild = new TemplateViewItem(*this); + const TemplateItemProperties *pCur = &rTemplates[i]; + + pChild->mnId = pCur->nId; + pChild->mnDocId = pCur->nDocId; + pChild->mnRegionId = pCur->nRegionId; + pChild->maTitle = pCur->aName; + pChild->setPath(pCur->aPath); + pChild->maPreview1 = pCur->aThumbnail; + + if ( pCur->aThumbnail.IsEmpty() ) + { + // Use the default thumbnail if we have nothing else + pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath); + } -void TemplateAbstractView::filterTemplatesByApp (const FILTER_APPLICATION &eApp) -{ - meFilterOption = eApp; + pChild->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); - if (mpItemView->IsVisible()) - { - mbFilteredResults = true; - mpItemView->filterItems(ViewFilter_Application(eApp)); - } - else - { - filterItems(ViewFilter_Application(eApp)); + aItems[i] = pChild; } + + updateItems(aItems); } -void TemplateAbstractView::showOverlay (bool bVisible) +sal_uInt16 TemplateAbstractView::getCurRegionId() const { - mpItemView->Show(bVisible); - - // Clear items is the overlay is closed. - if (!bVisible) - { - // Check if the folder view needs to be filtered - if (mbFilteredResults) - { - filterItems(ViewFilter_Application(meFilterOption)); - } + return mnCurRegionId; +} - mpItemView->Clear(); - } +const OUString &TemplateAbstractView::getCurRegionName() const +{ + return maCurRegionName; } -void TemplateAbstractView::filterTemplatesByKeyword(const OUString &rKeyword) +bool TemplateAbstractView::isNonRootRegionVisible () const { - if (mpItemView->IsVisible()) - mpItemView->filterItems(ViewFilter_Keyword(rKeyword)); + return mnCurRegionId; } -void TemplateAbstractView::setOverlayDblClickHdl(const Link &rLink) +void TemplateAbstractView::setOpenRegionHdl(const Link &rLink) { - mpItemView->setDblClickHdl(rLink); + maOpenRegionHdl = rLink; } -void TemplateAbstractView::setOverlayCloseHdl(const Link &rLink) +void TemplateAbstractView::setOpenTemplateHdl(const Link &rLink) { - mpItemView->setCloseHdl(rLink); + maOpenTemplateHdl = rLink; } BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long height) @@ -256,6 +257,31 @@ BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long return aImg; } +BitmapEx TemplateAbstractView::getDefaultThumbnail( const OUString& rPath ) +{ + INetURLObject aUrl(rPath); + OUString aExt = aUrl.getExtension(); + + BitmapEx aImg; + if ( aExt == "ott" || aExt == "stw" || aExt == "oth" || aExt == "dot" || aExt == "dotx" ) + { + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) ); + } + else if ( aExt == "ots" || aExt == "stc" || aExt == "xlt" || aExt == "xltm" || aExt == "xltx" ) + { + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) ); + } + else if ( aExt == "otp" || aExt == "sti" || aExt == "pot" || aExt == "potm" || aExt == "potx" ) + { + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) ); + } + else if ( aExt == "otg" || aExt == "std" ) + { + aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) ); + } + return aImg; +} + BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width, long height) { using namespace ::com::sun::star; @@ -365,28 +391,30 @@ BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width return TemplateAbstractView::scaleImg(aThumbnail,width,height); } -void TemplateAbstractView::Resize() +IMPL_LINK_NOARG(TemplateAbstractView, ShowRootRegionHdl) { - mpItemView->SetSizePixel(GetSizePixel()); - ThumbnailView::Resize(); + showRootRegion(); + return 0; } -void TemplateAbstractView::Paint(const Rectangle &rRect) +void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem) { - if (!mpItemView->IsVisible()) - ThumbnailView::Paint(rRect); -} + //Check if the item is a TemplateContainerItem (Folder) or a TemplateViewItem (File) -void TemplateAbstractView::DrawItem(ThumbnailViewItem *pItem) -{ - if (!mpItemView->IsVisible()) - ThumbnailView::DrawItem(pItem); -} + TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>(pItem); + if ( pContainerItem ) + { + // Fill templates -IMPL_LINK(TemplateAbstractView, OverlayItemStateHdl, const ThumbnailViewItem*, pItem) -{ - maOverlayItemStateHdl.Call((void*)pItem); - return 0; + mnCurRegionId = pContainerItem->mnRegionId+1; + maCurRegionName = pContainerItem->maTitle; + maFTName.SetText(maCurRegionName); + showRegion(pItem); + } + else + { + maOpenTemplateHdl.Call(pItem); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index ca8856ece221..f1a34217f0fb 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -12,7 +12,6 @@ #include <comphelper/processfactory.hxx> #include <sfx2/doctempl.hxx> #include <sfx2/templatecontaineritem.hxx> -#include <sfx2/templateview.hxx> #include <sfx2/templateviewitem.hxx> #include <svl/inettype.hxx> #include <tools/urlobj.hxx> @@ -36,17 +35,25 @@ TemplateLocalView::TemplateLocalView ( Window* pParent, const ResId& rResId, boo : TemplateAbstractView(pParent,rResId,bDisableTransientChildren), mpDocTemplates(new SfxDocumentTemplates) { - mpItemView->SetColor(GetSettings().GetStyleSettings().GetFieldColor()); - mpItemView->setMasterView(this); } TemplateLocalView::~TemplateLocalView() { + for (size_t i = 0; i < maRegions.size(); ++i) + delete maRegions[i]; + + maRegions.clear(); + delete mpDocTemplates; } void TemplateLocalView::Populate () { + for (size_t i = 0; i < maRegions.size(); ++i) + delete maRegions[i]; + + maRegions.clear(); + sal_uInt16 nCount = mpDocTemplates->GetRegionCount(); for (sal_uInt16 i = 0; i < nCount; ++i) { @@ -54,6 +61,7 @@ void TemplateLocalView::Populate () TemplateContainerItem* pItem = new TemplateContainerItem( *this ); pItem->mnId = i+1; + pItem->mnRegionId = i; pItem->maTitle = aRegionName; pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); @@ -65,6 +73,7 @@ void TemplateLocalView::Populate () OUString aURL = mpDocTemplates->GetPath(i,j); TemplateItemProperties aProperties; + aProperties.aIsFolder = false; // Flat hierarchy for the local filesystem (no nested folders) aProperties.nId = j+1; aProperties.nDocId = j; aProperties.nRegionId = i; @@ -79,68 +88,132 @@ void TemplateLocalView::Populate () lcl_updateThumbnails(pItem); - mItemList.push_back(pItem); + maRegions.push_back(pItem); } - - CalculateItemPositions(); - - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); } void TemplateLocalView::reload () { mpDocTemplates->Update(); - Clear(); - Populate(); - if (mpItemView->IsVisible()) + // Check if we are currently browsing a region or root folder + if (mnCurRegionId) { - sal_uInt16 nItemId = mpItemView->getId() + 1; + sal_uInt16 nRegionId = mnCurRegionId - 1; //Is offset by 1 - for (size_t i = 0; i < mItemList.size(); ++i) + for (size_t i = 0; i < maRegions.size(); ++i) { - if (mItemList[i]->mnId == nItemId) + if (maRegions[i]->mnRegionId == nRegionId) { - mpItemView->Clear(); - mpItemView->InsertItems(static_cast<TemplateContainerItem*>(mItemList[i])->maTemplates); + showRegion(maRegions[i]); break; } } } + else + showRootRegion(); } -std::vector<OUString> TemplateLocalView::getFolderNames() +void TemplateLocalView::showRootRegion() { - size_t n = mItemList.size(); - std::vector<OUString> ret(n); + mnHeaderHeight = 0; + mnCurRegionId = 0; + maCurRegionName = OUString(); - for (size_t i = 0; i < n; ++i) - ret[i] = mItemList[i]->maTitle; + // Clone root region items so they dont get invalidated when we open another region + std::vector<ThumbnailViewItem*> items(maRegions.size()); + for (int i = 0, n = maRegions.size(); i < n; ++i) + { + TemplateContainerItem *pCur = maRegions[i]; + TemplateContainerItem *pItem = new TemplateContainerItem(*this); + pItem->mnId = pCur->mnId; + pItem->mnRegionId = pCur->mnRegionId; + pItem->maTitle = pCur->maTitle; + pItem->maTemplates = pCur->maTemplates; + pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); - return ret; + items[i] = pItem; + } + + maAllButton.Show(false); + maFTName.Show(false); + + updateItems(items); + + maOpenRegionHdl.Call(NULL); } -void TemplateLocalView::showOverlay (bool bVisible) +void TemplateLocalView::showRegion(ThumbnailViewItem *pItem) { - mpItemView->Show(bVisible); + mnHeaderHeight = maAllButton.GetSizePixel().getHeight() + maAllButton.GetPosPixel().Y() * 2; + + mnCurRegionId = static_cast<TemplateContainerItem*>(pItem)->mnRegionId+1; + maCurRegionName = pItem->maTitle; + maAllButton.Show(true); + maFTName.Show(true); + + insertItems(reinterpret_cast<TemplateContainerItem*>(pItem)->maTemplates); - // Clear items is the overlay is closed. - if (!bVisible) + maOpenRegionHdl.Call(NULL); +} + +void TemplateLocalView::showRegion(const OUString &rName) +{ + for (int i = 0, n = maRegions.size(); i < n; ++i) { - // Check if the folder view needs to be filtered - if (mbFilteredResults) + if (maRegions[i]->maTitle == rName) { - filterItems(ViewFilter_Application(meFilterOption)); - - mbFilteredResults = false; - meFilterOption = FILTER_APP_NONE; + showRegion(maRegions[i]); + break; } + } +} + +sal_uInt16 TemplateLocalView::getCurRegionItemId() const +{ + for (size_t i = 0; i < maRegions.size(); ++i) + { + if (maRegions[i]->mnRegionId == mnCurRegionId-1) + return maRegions[i]->mnId; + } - mpItemView->Clear(); + return 0; +} + +sal_uInt16 TemplateLocalView::getRegionId(size_t pos) const +{ + assert(pos < maRegions.size()); + + return maRegions[pos]->mnId; +} + +OUString TemplateLocalView::getRegionName(const sal_uInt16 nRegionId) const +{ + return mpDocTemplates->GetRegionName(nRegionId); +} + +OUString TemplateLocalView::getRegionItemName(const sal_uInt16 nItemId) const +{ + for (size_t i = 0; i < maRegions.size(); ++i) + { + if (maRegions[i]->mnId == nItemId) + return maRegions[i]->maTitle; } + + return OUString(); +} + +std::vector<OUString> TemplateLocalView::getFolderNames() +{ + size_t n = maRegions.size(); + std::vector<OUString> ret(n); + + for (size_t i = 0; i < n; ++i) + ret[i] = maRegions[i]->maTitle; + + return ret; } std::vector<TemplateItemProperties> @@ -148,9 +221,9 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt { std::vector<TemplateItemProperties> aItems; - for (size_t i = 0; i < mItemList.size(); ++i) + if (mnCurRegionId) { - TemplateContainerItem *pFolderItem = static_cast<TemplateContainerItem*>(mItemList[i]); + TemplateContainerItem *pFolderItem = maRegions[mnCurRegionId-1]; for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j) { @@ -158,6 +231,19 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt aItems.push_back(pFolderItem->maTemplates[j]); } } + else + { + for (size_t i = 0; i < maRegions.size(); ++i) + { + TemplateContainerItem *pFolderItem = maRegions[i]; + + for (size_t j = 0; j < pFolderItem->maTemplates.size(); ++j) + { + if (rFunc(pFolderItem->maTemplates[j])) + aItems.push_back(pFolderItem->maTemplates[j]); + } + } + } return aItems; } @@ -165,34 +251,85 @@ TemplateLocalView::getFilteredItems(const boost::function<bool (const TemplateIt sal_uInt16 TemplateLocalView::createRegion(const OUString &rName) { sal_uInt16 nRegionId = mpDocTemplates->GetRegionCount(); // Next regionId + sal_uInt16 nItemId = getNextItemId(); if (!mpDocTemplates->InsertDir(rName,nRegionId)) return false; OUString aRegionName = rName; + // Insert to the region cache list and to the thumbnail item list TemplateContainerItem* pItem = new TemplateContainerItem( *this ); - pItem->mnId = nRegionId+1; + pItem->mnId = nItemId; + pItem->mnRegionId = nRegionId; pItem->maTitle = aRegionName; pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); - mItemList.push_back(pItem); + maRegions.push_back(pItem); - CalculateItemPositions(); + pItem = new TemplateContainerItem(*this); + pItem->mnId = nItemId; + pItem->mnRegionId = nRegionId; + pItem->maTitle = aRegionName; + pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); - if ( IsReallyVisible() && IsUpdateMode() ) - Invalidate(); + AppendItem(pItem); + + CalculateItemPositions(); + Invalidate(); return pItem->mnId; } +bool TemplateLocalView::isNestedRegionAllowed() const +{ + return !mnCurRegionId; +} + +bool TemplateLocalView::isImportAllowed() const +{ + return mnCurRegionId; +} + bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId) { - sal_uInt16 nRegionId = nItemId - 1; + sal_uInt16 nRegionId = USHRT_MAX; + + // Remove from the region cache list + std::vector<TemplateContainerItem*>::iterator pRegionIt; + for ( pRegionIt = maRegions.begin(); pRegionIt != maRegions.end();) + { + if ( (*pRegionIt)->mnId == nItemId ) + { + if (!mpDocTemplates->Delete((*pRegionIt)->mnRegionId,USHRT_MAX)) + return false; - if (!mpDocTemplates->Delete(nRegionId,USHRT_MAX)) + nRegionId = (*pRegionIt)->mnRegionId; + + delete *pRegionIt; + pRegionIt = maRegions.erase(pRegionIt); + } + else + { + // Syncronize regions cache ids with SfxDocumentTemplates + if (nRegionId != USHRT_MAX && (*pRegionIt)->mnRegionId > nRegionId) + --(*pRegionIt)->mnRegionId; + + ++pRegionIt; + } + } + + if (nRegionId == USHRT_MAX) return false; + // Syncronize view regions ids with SfxDocumentTemplates + std::vector<ThumbnailViewItem*>::iterator pViewIt = mItemList.begin(); + for ( pViewIt = mItemList.begin(); pViewIt != mItemList.end(); ++pViewIt) + { + if (static_cast<TemplateContainerItem*>(*pViewIt)->mnRegionId > nRegionId) + --static_cast<TemplateContainerItem*>(*pViewIt)->mnRegionId; + } + RemoveItem(nItemId); return true; @@ -200,24 +337,26 @@ bool TemplateLocalView::removeRegion(const sal_uInt16 nItemId) bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt16 nSrcItemId) { - sal_uInt16 nRegionId = nSrcItemId - 1; - - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nSrcItemId) + if (maRegions[i]->mnId == nSrcItemId) { - TemplateContainerItem *pItem = static_cast<TemplateContainerItem*>(mItemList[i]); + TemplateContainerItem *pItem = static_cast<TemplateContainerItem*>(maRegions[i]); std::vector<TemplateItemProperties>::iterator pIter; for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter) { if (pIter->nId == nItemId) { - if (!mpDocTemplates->Delete(nRegionId,pIter->nDocId)) + if (!mpDocTemplates->Delete(pItem->mnRegionId,pIter->nDocId)) return false; pIter = pItem->maTemplates.erase(pIter); - mpItemView->RemoveItem(nItemId); + if (maRegions[i]->mnRegionId == mnCurRegionId-1) + { + RemoveItem(nItemId); + Invalidate(); + } // Update Doc Idx for all templates that follow for (; pIter != pItem->maTemplates.end(); ++pIter) @@ -239,40 +378,34 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt } bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_uInt16 nSrcItem, - const sal_uInt16 nTargetItem, bool bCopy) + const sal_uInt16 nTargetItem) { - bool bRet = true; - bool bRefresh = false; - TemplateContainerItem *pTarget = NULL; TemplateContainerItem *pSrc = NULL; - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nTargetItem) - pTarget = static_cast<TemplateContainerItem*>(mItemList[i]); - else if (mItemList[i]->mnId == nSrcItem) - pSrc = static_cast<TemplateContainerItem*>(mItemList[i]); + if (maRegions[i]->mnId == nTargetItem) + pTarget = static_cast<TemplateContainerItem*>(maRegions[i]); + else if (maRegions[i]->mnId == nSrcItem) + pSrc = static_cast<TemplateContainerItem*>(maRegions[i]); } if (pTarget && pSrc) { - sal_uInt16 nSrcRegionId = nSrcItem-1; - sal_uInt16 nTargetRegion = pTarget->mnId-1; + sal_uInt16 nSrcRegionId = pSrc->mnRegionId; + sal_uInt16 nTargetRegion = pTarget->mnRegionId; sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(pItem); - bool bOK; + bool bCopy = !mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId); if (bCopy) - bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); - else - bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); - - if (!bOK) - return false; - + { + if (!mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId)) + return false; + } // move template to destination TemplateItemProperties aTemplateItem; @@ -280,91 +413,94 @@ bool TemplateLocalView::moveTemplate (const ThumbnailViewItem *pItem, const sal_ aTemplateItem.nDocId = nTargetIdx; aTemplateItem.nRegionId = nTargetRegion; aTemplateItem.aName = pViewItem->maTitle; - aTemplateItem.aPath = pViewItem->getPath(); + aTemplateItem.aPath = mpDocTemplates->GetPath(nTargetRegion,nTargetIdx); aTemplateItem.aThumbnail = pViewItem->maPreview1; pTarget->maTemplates.push_back(aTemplateItem); if (!bCopy) { - // remove template from overlay and from cached data + // remove template from region cached data std::vector<TemplateItemProperties>::iterator aIter; - for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end(); ++aIter) + for (aIter = pSrc->maTemplates.begin(); aIter != pSrc->maTemplates.end();) { - if (aIter->nId == pViewItem->mnId) + if (aIter->nDocId == pViewItem->mnDocId) + { + aIter = pSrc->maTemplates.erase(aIter); + } + else { - pSrc->maTemplates.erase(aIter); + // Keep region document id syncronized with SfxDocumentTemplates + if (aIter->nDocId > pViewItem->mnDocId) + --aIter->nDocId; - mpItemView->RemoveItem(pViewItem->mnId); - break; + ++aIter; } } - } - bRefresh = true; - } - else - bRet = false; + // Keep view document id syncronized with SfxDocumentTemplates + std::vector<ThumbnailViewItem*>::iterator pItemIter = mItemList.begin(); + for (; pItemIter != mItemList.end(); ++pItemIter) + { + if (static_cast<TemplateViewItem*>(*pItemIter)->mnDocId > pViewItem->mnDocId) + --static_cast<TemplateViewItem*>(*pItemIter)->mnDocId; + } + } - if (bRefresh) - { lcl_updateThumbnails(pSrc); lcl_updateThumbnails(pTarget); CalculateItemPositions(); + Invalidate(); - if (IsReallyVisible() && IsUpdateMode()) - { - Invalidate(); - mpItemView->Invalidate(); - } + return true; } - return bRet; + return false; } -bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItems, - const sal_uInt16 nTargetItem, bool bCopy) +bool TemplateLocalView::moveTemplates(const std::set<const ThumbnailViewItem*, selection_cmp_fn> &rItems, + const sal_uInt16 nTargetItem) { + assert(mnCurRegionId); // Only allowed in non root regions + bool ret = true; bool refresh = false; - sal_uInt16 nSrcRegionId = mpItemView->getId(); - sal_uInt16 nSrcRegionItemId = nSrcRegionId + 1; + sal_uInt16 nSrcRegionId = mnCurRegionId-1; TemplateContainerItem *pTarget = NULL; TemplateContainerItem *pSrc = NULL; - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nTargetItem) - pTarget = static_cast<TemplateContainerItem*>(mItemList[i]); - else if (mItemList[i]->mnId == nSrcRegionItemId) - pSrc = static_cast<TemplateContainerItem*>(mItemList[i]); + if (maRegions[i]->mnId == nTargetItem) + pTarget = static_cast<TemplateContainerItem*>(maRegions[i]); + else if (maRegions[i]->mnRegionId == nSrcRegionId) + pSrc = static_cast<TemplateContainerItem*>(maRegions[i]); } if (pTarget && pSrc) { - sal_uInt16 nTargetRegion = pTarget->mnId-1; + sal_uInt16 nTargetRegion = pTarget->mnRegionId; sal_uInt16 nTargetIdx = mpDocTemplates->GetCount(nTargetRegion); // Next Idx + std::vector<sal_uInt16> aItemIds; // List of moved items ids (also prevents the invalidation of rItems iterators when we remove them as we go) - std::set<const ThumbnailViewItem*>::iterator aSelIter; + std::set<const ThumbnailViewItem*,selection_cmp_fn>::iterator aSelIter; for ( aSelIter = rItems.begin(); aSelIter != rItems.end(); ++aSelIter, ++nTargetIdx ) { const TemplateViewItem *pViewItem = static_cast<const TemplateViewItem*>(*aSelIter); - bool bOK; + bool bCopy = !mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId); if (bCopy) - bOK = mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); - else - bOK = mpDocTemplates->Move(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnId-1); - - if (!bOK) { - ret = false; - continue; + if (!mpDocTemplates->Copy(nTargetRegion,nTargetIdx,nSrcRegionId,pViewItem->mnDocId)) + { + ret = false; + continue; + } } // move template to destination @@ -374,44 +510,60 @@ bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItem aTemplateItem.nDocId = nTargetIdx; aTemplateItem.nRegionId = nTargetRegion; aTemplateItem.aName = pViewItem->maTitle; - aTemplateItem.aPath = pViewItem->getPath(); + aTemplateItem.aPath = mpDocTemplates->GetPath(nTargetRegion,nTargetIdx); aTemplateItem.aThumbnail = pViewItem->maPreview1; pTarget->maTemplates.push_back(aTemplateItem); if (!bCopy) { - // remove template from overlay and from cached data + // remove template from region cached data - std::vector<TemplateItemProperties>::iterator pIter; - for (pIter = pSrc->maTemplates.begin(); pIter != pSrc->maTemplates.end(); ++pIter) + std::vector<TemplateItemProperties>::iterator pPropIter; + for (pPropIter = pSrc->maTemplates.begin(); pPropIter != pSrc->maTemplates.end();) { - if (pIter->nId == pViewItem->mnId) + if (pPropIter->nDocId == pViewItem->mnDocId) + { + pPropIter = pSrc->maTemplates.erase(pPropIter); + aItemIds.push_back(pViewItem->mnId); + } + else { - pSrc->maTemplates.erase(pIter); + // Keep region document id syncronized with SfxDocumentTemplates + if (pPropIter->nDocId > pViewItem->mnDocId) + --pPropIter->nDocId; - mpItemView->RemoveItem(pViewItem->mnId); - break; + ++pPropIter; } } + + // Keep view document id syncronized with SfxDocumentTemplates + std::vector<ThumbnailViewItem*>::iterator pItemIter = mItemList.begin(); + for (; pItemIter != mItemList.end(); ++pItemIter) + { + if (static_cast<TemplateViewItem*>(*pItemIter)->mnDocId > pViewItem->mnDocId) + --static_cast<TemplateViewItem*>(*pItemIter)->mnDocId; + } } refresh = true; } - } - else - ret = false; - if (refresh) - { - lcl_updateThumbnails(pSrc); - lcl_updateThumbnails(pTarget); + // Remove items from the current view + for (std::vector<sal_uInt16>::iterator it = aItemIds.begin(); it != aItemIds.end(); ++it) + RemoveItem(*it); - CalculateItemPositions(); + if (refresh) + { + lcl_updateThumbnails(pSrc); + lcl_updateThumbnails(pTarget); - Invalidate(); - mpItemView->Invalidate(); + CalculateItemPositions(); + Invalidate(); + } } + else + ret = false; return ret; } @@ -419,17 +571,15 @@ bool TemplateLocalView::moveTemplates(std::set<const ThumbnailViewItem *> &rItem bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx &rThumbnail, const OUString &rPath) { - sal_uInt16 nRegionId = nRegionItemId - 1; - - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nRegionItemId) + if (maRegions[i]->mnId == nRegionItemId) { sal_uInt16 nId = 0; sal_uInt16 nDocId = 0; TemplateContainerItem *pRegionItem = - static_cast<TemplateContainerItem*>(mItemList[i]); + static_cast<TemplateContainerItem*>(maRegions[i]); if (!pRegionItem->maTemplates.empty()) { @@ -438,6 +588,7 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx } String aPath(rPath); + sal_uInt16 nRegionId = maRegions[i]->mnRegionId; if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath)) { @@ -450,7 +601,7 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx aTemplate.aPath = mpDocTemplates->GetPath(nRegionId,nDocId); TemplateContainerItem *pItem = - static_cast<TemplateContainerItem*>(mItemList[i]); + static_cast<TemplateContainerItem*>(maRegions[i]); pItem->maTemplates.push_back(aTemplate); @@ -466,11 +617,47 @@ bool TemplateLocalView::copyFrom(const sal_uInt16 nRegionItemId, const BitmapEx return false; } +bool TemplateLocalView::copyFrom(const OUString &rPath) +{ + assert(mnCurRegionId); + + TemplateContainerItem *pRegItem = maRegions[mnCurRegionId-1]; + + sal_uInt16 nId = getNextItemId(); + sal_uInt16 nDocId = 0; + sal_uInt16 nRegionId = pRegItem->mnRegionId; + + String aPath(rPath); + + if (!pRegItem->maTemplates.empty()) + nDocId = (pRegItem->maTemplates.back()).nDocId+1; + + if (!mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath)) + return false; + + TemplateItemProperties aTemplate; + aTemplate.aIsFolder = false; + aTemplate.nId = nId; + aTemplate.nDocId = nDocId; + aTemplate.nRegionId = nRegionId; + aTemplate.aName = aPath; + aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(rPath, + TEMPLATE_THUMBNAIL_MAX_WIDTH, + TEMPLATE_THUMBNAIL_MAX_HEIGHT); + aTemplate.aPath = rPath; + + pRegItem->maTemplates.push_back(aTemplate); + + insertItem(aTemplate); + + return true; +} + bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString &rPath) { - sal_uInt16 nId = 0; + sal_uInt16 nId = 1; sal_uInt16 nDocId = 0; - sal_uInt16 nRegionId = pItem->mnId - 1; + sal_uInt16 nRegionId = pItem->mnRegionId; String aPath(rPath); if (!pItem->maTemplates.empty()) @@ -482,6 +669,7 @@ bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString & if (mpDocTemplates->CopyFrom(nRegionId,nDocId,aPath)) { TemplateItemProperties aTemplate; + aTemplate.aIsFolder = false; aTemplate.nId = nId; aTemplate.nDocId = nDocId; aTemplate.nRegionId = nRegionId; @@ -505,21 +693,18 @@ bool TemplateLocalView::copyFrom (TemplateContainerItem *pItem, const OUString & bool TemplateLocalView::exportTo(const sal_uInt16 nItemId, const sal_uInt16 nRegionItemId, const OUString &rName) { - sal_uInt16 nRegionId = nRegionItemId - 1; - - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nRegionItemId) + if (maRegions[i]->mnId == nRegionItemId) { - TemplateContainerItem *pRegItem = - static_cast<TemplateContainerItem*>(mItemList[i]); + TemplateContainerItem *pRegItem = maRegions[i]; std::vector<TemplateItemProperties>::iterator aIter; for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter) { if (aIter->nId == nItemId) { - if (!mpDocTemplates->CopyTo(nRegionId,aIter->nDocId,rName)) + if (!mpDocTemplates->CopyTo(pRegItem->mnRegionId,aIter->nDocId,rName)) return false; return true; @@ -537,21 +722,50 @@ bool TemplateLocalView::saveTemplateAs (sal_uInt16 nItemId, com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel, const OUString &rName) { - bool bRet = false; - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nItemId) + if (maRegions[i]->mnId == nItemId) { - bRet = saveTemplateAs((const TemplateContainerItem*)mItemList[i],rModel,rName); - break; + uno::Reference< frame::XStorable > xStorable(rModel, uno::UNO_QUERY_THROW ); + + uno::Reference< frame::XDocumentTemplates > xTemplates( + frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) ); + + if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(maRegions[i]->mnRegionId),rName, xStorable )) + return false; + + sal_uInt16 nDocId = maRegions[i]->maTemplates.size(); + + OUString aURL = mpDocTemplates->GetTemplateTargetURLFromComponent(mpDocTemplates->GetRegionName(maRegions[i]->mnRegionId),rName); + + if(!mpDocTemplates->InsertTemplate(maRegions[i]->mnRegionId,nDocId,rName,aURL)) + return false; + + + TemplateItemProperties aTemplate; + aTemplate.aIsFolder = false; + aTemplate.nId = getNextItemId(); + aTemplate.nDocId = nDocId; + aTemplate.nRegionId = maRegions[i]->mnRegionId; + aTemplate.aName = rName; + aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL, + TEMPLATE_THUMBNAIL_MAX_WIDTH, + TEMPLATE_THUMBNAIL_MAX_HEIGHT); + aTemplate.aPath = aURL; + + maRegions[i]->maTemplates.push_back(aTemplate); + + insertItem(aTemplate); + + return true; } } - return bRet; + return false; } -bool TemplateLocalView::saveTemplateAs(const TemplateContainerItem *pDstItem, +bool TemplateLocalView::saveTemplateAs(TemplateContainerItem *pDstItem, com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel, const OUString &rName) { @@ -560,22 +774,38 @@ bool TemplateLocalView::saveTemplateAs(const TemplateContainerItem *pDstItem, uno::Reference< frame::XDocumentTemplates > xTemplates( frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) ); - sal_uInt16 nRegionId = pDstItem->mnId-1; + if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName, xStorable )) + return false; + + sal_uInt16 nDocId = pDstItem->maTemplates.size(); + OUString aURL = mpDocTemplates->GetTemplateTargetURLFromComponent(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName); - if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(nRegionId),rName, xStorable )) + if(!mpDocTemplates->InsertTemplate(pDstItem->mnRegionId,nDocId,rName,aURL)) return false; + TemplateItemProperties aTemplate; + aTemplate.aIsFolder = false; + aTemplate.nId = pDstItem->maTemplates.empty() ? 1 : pDstItem->maTemplates.back().nId+1; + aTemplate.nDocId = nDocId; + aTemplate.nRegionId = pDstItem->mnRegionId; + aTemplate.aName = rName; + aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL, + TEMPLATE_THUMBNAIL_MAX_WIDTH, + TEMPLATE_THUMBNAIL_MAX_HEIGHT); + aTemplate.aPath = aURL; + + pDstItem->maTemplates.push_back(aTemplate); + return true; } bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, const OUString &rName) const { - for (size_t i = 0, n = mItemList.size(); i < n; ++i) + for (size_t i = 0, n = maRegions.size(); i < n; ++i) { - if (mItemList[i]->mnId == nRegionItemId) + if (maRegions[i]->mnId == nRegionItemId) { - TemplateContainerItem *pRegItem = - static_cast<TemplateContainerItem*>(mItemList[i]); + TemplateContainerItem *pRegItem = maRegions[i]; std::vector<TemplateItemProperties>::iterator aIter; for (aIter = pRegItem->maTemplates.begin(); aIter != pRegItem->maTemplates.end(); ++aIter) @@ -591,19 +821,6 @@ bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, con return true; } -void TemplateLocalView::OnItemDblClicked (ThumbnailViewItem *pRegionItem) -{ - // Fill templates - sal_uInt16 nRegionId = pRegionItem->mnId-1; - - mpItemView->setId(nRegionId); - mpItemView->setName(mpDocTemplates->GetRegionName(nRegionId)); - mpItemView->InsertItems(static_cast<TemplateContainerItem*>(pRegionItem)->maTemplates); - - mpItemView->filterItems(ViewFilter_Application(meFilterOption)); - - showOverlay(true); -} bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle) { @@ -618,7 +835,7 @@ bool TemplateLocalView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewT } else if ( pContainerItem ) { - nRegionId = pContainerItem->mnId - 1; + nRegionId = pContainerItem->mnRegionId; } return mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId ); } diff --git a/sfx2/source/control/templateremoteview.cxx b/sfx2/source/control/templateremoteview.cxx index 9f840533d855..3fc85a75885a 100644 --- a/sfx2/source/control/templateremoteview.cxx +++ b/sfx2/source/control/templateremoteview.cxx @@ -11,7 +11,6 @@ #include <comphelper/processfactory.hxx> #include <sfx2/templaterepository.hxx> -#include <sfx2/templateview.hxx> #include <sfx2/templateviewitem.hxx> #include <svtools/imagemgr.hxx> #include <tools/urlobj.hxx> @@ -47,8 +46,6 @@ enum TemplateRemoteView::TemplateRemoteView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren) : TemplateAbstractView(pParent,nWinStyle,bDisableTransientChildren) { - mpItemView->SetColor(Color(COL_WHITE)); - Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); Reference< XInteractionHandler > xGlobalInteractionHandler( InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW ); @@ -60,15 +57,14 @@ TemplateRemoteView::~TemplateRemoteView () { } -void TemplateRemoteView::showOverlay (bool bVisible) +void TemplateRemoteView::showRootRegion() { - mpItemView->Show(bVisible); + //TODO: +} - // Clear items is the overlay is closed. - if (!bVisible) - { - mpItemView->Clear(); - } +void TemplateRemoteView::showRegion(ThumbnailViewItem */*pItem*/) +{ + //TODO: } bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefresh) @@ -78,13 +74,13 @@ bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefres if (!pItem->getTemplates().empty() && !bRefresh) { - mpItemView->InsertItems(pItem->getTemplates()); + insertItems(pItem->getTemplates()); return true; } - mpItemView->Clear(); - mpItemView->setId(pItem->mnId); - mpItemView->setName(pItem->maTitle); + mnCurRegionId = pItem->mnId; + maCurRegionName = pItem->maTitle; + maFTName.SetText(maCurRegionName); OUString aURL = pItem->getURL(); @@ -178,7 +174,7 @@ bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefres } } - mpItemView->InsertItems(aItems); + insertItems(aItems); } } catch( ucb::CommandAbortedException& ) @@ -194,4 +190,14 @@ bool TemplateRemoteView::loadRepository (TemplateRepository* pItem, bool bRefres return true; } +bool TemplateRemoteView::isNestedRegionAllowed() const +{ + return true; +} + +bool TemplateRemoteView::isImportAllowed() const +{ + return true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templatesearchview.cxx b/sfx2/source/control/templatesearchview.cxx index 775abbc09d4b..c24c567b6946 100644 --- a/sfx2/source/control/templatesearchview.cxx +++ b/sfx2/source/control/templatesearchview.cxx @@ -20,14 +20,15 @@ TemplateSearchView::~TemplateSearchView () { } -void TemplateSearchView::AppendItem(sal_uInt16 nItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx, +void TemplateSearchView::AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx, const OUString &rTitle, const OUString &rSubtitle, const OUString &rPath, const BitmapEx &rImage) { TemplateSearchViewItem *pItem = new TemplateSearchViewItem(*this); - pItem->mnId = nItemId; - pItem->mnIdx = nIdx; + pItem->mnId = getNextItemId(); + pItem->mnAssocId = nAssocItemId; + pItem->mnDocId = nIdx; pItem->mnRegionId = nRegionId; pItem->maPreview1 = rImage; pItem->maTitle = rTitle; @@ -35,7 +36,7 @@ void TemplateSearchView::AppendItem(sal_uInt16 nItemId, sal_uInt16 nRegionId, sa pItem->setPath(rPath); pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); - mItemList.push_back(pItem); + ThumbnailView::AppendItem(pItem); CalculateItemPositions(); } diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx deleted file mode 100644 index 615465df3862..000000000000 --- a/sfx2/source/control/templateview.cxx +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- 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 "templatedlg.hxx" -#include <sfx2/templateview.hxx> -#include <sfx2/templateabstractview.hxx> - -#include <basegfx/matrix/b2dhommatrixtools.hxx> -#include <basegfx/point/b2dpoint.hxx> -#include <basegfx/range/b2drange.hxx> -#include <basegfx/vector/b2dvector.hxx> -#include <drawinglayer/attribute/fillbitmapattribute.hxx> -#include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx> -#include <drawinglayer/primitive2d/textlayoutdevice.hxx> -#include <drawinglayer/primitive2d/textprimitive2d.hxx> -#include <drawinglayer/processor2d/baseprocessor2d.hxx> -#include <sfx2/sfxresid.hxx> -#include <sfx2/templateviewitem.hxx> -#include <vcl/edit.hxx> - -#include "templateview.hrc" - -#define EDIT_HEIGHT 30 - -using namespace basegfx; -using namespace basegfx::tools; -using namespace drawinglayer::attribute; -using namespace drawinglayer::primitive2d; - -TemplateView::TemplateView (Window *pParent) - : ThumbnailView(pParent,WB_VSCROLL), - mpMasterView(NULL), - maButtons(this, SfxResId(CONTROL_BUTTONS)), - maAllButton(&maButtons, SfxResId(BTN_ALL_TEMPLATES)), - maFTName(&maButtons, SfxResId(FT_NAME)), - mnId(0) -{ - mnHeaderHeight = maButtons.GetSizePixel().getHeight(); - maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON); -} - -TemplateView::~TemplateView () -{ -} - -void TemplateView::setName (const OUString &rName) -{ - maName = rName; - maFTName.SetText(maName); -} - -void TemplateView::InsertItems (const std::vector<TemplateItemProperties> &rTemplates) -{ - for (size_t i = 0, n = rTemplates.size(); i < n; ++i ) - { - TemplateViewItem *pItem = new TemplateViewItem(*this); - const TemplateItemProperties *pCur = &rTemplates[i]; - - pItem->mnId = pCur->nId; - pItem->mnDocId = pCur->nDocId; - pItem->mnRegionId = pCur->nRegionId; - pItem->maTitle = pCur->aName; - pItem->setPath(pCur->aPath); - pItem->maPreview1 = pCur->aThumbnail; - if ( pCur->aThumbnail.IsEmpty() ) - { - // Use the default thumbnail if we have nothing else - pItem->maPreview1 = SfxTemplateManagerDlg::getDefaultThumbnail( pItem->getPath() ); - } - pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected)); - - mItemList.push_back(pItem); - } - - CalculateItemPositions(); - - Invalidate(); -} - -void TemplateView::Resize() -{ - Size aWinSize = GetOutputSize(); - - // Set the buttons panel and buttons size - Size aPanelSize = maButtons.GetSizePixel(); - int nDeltaW = aWinSize.getWidth() - aPanelSize.getWidth(); - aPanelSize.setWidth(aWinSize.getWidth()); - maButtons.SetSizePixel(aPanelSize); - - Size aNameSize = maFTName.GetSizePixel(); - aNameSize.setWidth(aNameSize.getWidth() + nDeltaW); - maFTName.SetSizePixel(aNameSize); - - ThumbnailView::Resize(); -} - -void TemplateView::OnItemDblClicked(ThumbnailViewItem *pItem) -{ - maDblClickHdl.Call(pItem); -} - -bool TemplateView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle) -{ - if (mpMasterView) - return mpMasterView->renameItem(pItem, sNewTitle); - return false; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ - - diff --git a/sfx2/source/control/templateview.src b/sfx2/source/control/templateview.src index d2711a7c984b..8549c96485e4 100644 --- a/sfx2/source/control/templateview.src +++ b/sfx2/source/control/templateview.src @@ -8,18 +8,12 @@ #include "templateview.hrc" -Control CONTROL_BUTTONS -{ - Size = MAP_APPFONT( 290, 17 ); - Border = True; - TabStop = False; -}; - PushButton BTN_ALL_TEMPLATES { Pos = MAP_APPFONT( 1, 1 ); Size = MAP_APPFONT( 50, 14 ); Text [ en-US ] = "All Templates"; + TabStop = True; }; FixedText FT_NAME diff --git a/sfx2/source/control/templateviewitem.cxx b/sfx2/source/control/templateviewitem.cxx index 94ce4d30ee2b..d68268b0f276 100644 --- a/sfx2/source/control/templateviewitem.cxx +++ b/sfx2/source/control/templateviewitem.cxx @@ -55,9 +55,6 @@ void TemplateViewItem::calculateItemsPosition(const long nThumbnailHeight, const long nSpace = (nDisplayHeight + nPadding - 2*aTextDev.getTextHeight()) / 3; - // Set title position - maTextPos.setY(maDrawArea.getY() + nThumbnailHeight + nPadding + nSpace + aTextDev.getTextHeight()); - // Set subtitle position maSubTitlePos.setY(maTextPos.getY() + nSpace + aTextDev.getTextHeight()); maSubTitlePos.setX(maDrawArea.Left() + diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index c996f0fad30a..d08173cba7de 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -10,6 +10,8 @@ #include <sfx2/thumbnailview.hxx> #include <sfx2/thumbnailviewitem.hxx> +#include <utility> + #include "thumbnailviewacc.hxx" #include <basegfx/color/bcolortools.hxx> @@ -81,6 +83,27 @@ ThumbnailView::~ThumbnailView() ImplDeleteItems(); } +void ThumbnailView::AppendItem(ThumbnailViewItem *pItem) +{ + if (maFilterFunc(pItem)) + { + // Save current start,end range, iterator might get invalidated + size_t nSelStartPos = 0; + ThumbnailViewItem *pSelStartItem = NULL; + + if (mpStartSelRange != mFilteredItemList.end()) + { + pSelStartItem = *mpStartSelRange; + nSelStartPos = mpStartSelRange - mFilteredItemList.begin(); + } + + mFilteredItemList.push_back(pItem); + mpStartSelRange = pSelStartItem != NULL ? mFilteredItemList.begin() + nSelStartPos : mFilteredItemList.end(); + } + + mItemList.push_back(pItem); +} + void ThumbnailView::ImplInit() { mpScrBar = NULL; @@ -92,7 +115,6 @@ void ThumbnailView::ImplInit() mnLines = 0; mnFirstLine = 0; mnScrBarOffset = 1; - mnSelItemId = 0; mnHighItemId = 0; mnCols = 0; mnSpacing = 0; @@ -100,6 +122,7 @@ void ThumbnailView::ImplInit() mbHasVisibleItems = false; maFilterFunc = ViewFilterAll(); maColor = GetSettings().GetStyleSettings().GetFieldColor(); + mpStartSelRange = mFilteredItemList.end(); // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; @@ -115,6 +138,16 @@ void ThumbnailView::ImplDeleteItems() for ( size_t i = 0; i < n; ++i ) { ThumbnailViewItem *const pItem = mItemList[i]; + + // deselect all current selected items and fire events + if (pItem->isSelected()) + { + pItem->setSelection(false); + maItemStateHdl.Call(pItem); + + // fire accessible event??? + } + if ( pItem->isVisible() && ImplHasAccessibleListeners() ) { ::com::sun::star::uno::Any aOldAny, aNewAny; @@ -127,6 +160,9 @@ void ThumbnailView::ImplDeleteItems() } mItemList.clear(); + mFilteredItemList.clear(); + + mpStartSelRange = mFilteredItemList.end(); } void ThumbnailView::ImplInitSettings( bool bFont, bool bForeground, bool bBackground ) @@ -211,7 +247,7 @@ void ThumbnailView::CalculateItemPositions () return; Size aWinSize = GetOutputSizePixel(); - size_t nItemCount = mItemList.size(); + size_t nItemCount = mFilteredItemList.size(); WinBits nStyle = GetStyle(); ScrollBar* pDelScrBar = NULL; @@ -255,9 +291,6 @@ void ThumbnailView::CalculateItemPositions () if ( !mnLines ) mnLines = 1; - // check if scroll is needed - mbScroll = mnLines > mnVisLines; - if ( mnLines <= mnVisLines ) mnFirstLine = 0; else @@ -295,58 +328,35 @@ void ThumbnailView::CalculateItemPositions () size_t nCurCount = 0; for ( size_t i = 0; i < nItemCount; i++ ) { - ThumbnailViewItem *const pItem = mItemList[i]; + ThumbnailViewItem *const pItem = mFilteredItemList[i]; - if (maFilterFunc(pItem)) + if ((nCurCount >= nFirstItem) && (nCurCount < nLastItem)) { - if ((nCurCount >= nFirstItem) && (nCurCount < nLastItem)) + if( !pItem->isVisible()) { - if( !pItem->isVisible()) + if ( ImplHasAccessibleListeners() ) { - if ( ImplHasAccessibleListeners() ) - { - ::com::sun::star::uno::Any aOldAny, aNewAny; - - aNewAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled ); - ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); - } - - pItem->show(true); + ::com::sun::star::uno::Any aOldAny, aNewAny; - maItemStateHdl.Call(pItem); + aNewAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled ); + ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); } - pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) )); - pItem->calculateItemsPosition(mnThumbnailHeight,mnDisplayHeight,mnItemPadding,mpItemAttrs->nMaxTextLenght,mpItemAttrs); + pItem->show(true); - if ( !((nCurCount+1) % mnCols) ) - { - x = nStartX; - y += mnItemHeight+nVItemSpace; - } - else - x += mnItemWidth+nHItemSpace; + maItemStateHdl.Call(pItem); } - else - { - if( pItem->isVisible()) - { - if ( ImplHasAccessibleListeners() ) - { - ::com::sun::star::uno::Any aOldAny, aNewAny; - - aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled ); - ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); - } - pItem->show(false); - - maItemStateHdl.Call(pItem); - } + pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) )); + pItem->calculateItemsPosition(mnThumbnailHeight,mnDisplayHeight,mnItemPadding,mpItemAttrs->nMaxTextLenght,mpItemAttrs); + if ( !((nCurCount+1) % mnCols) ) + { + x = nStartX; + y += mnItemHeight+nVItemSpace; } - - ++nCurCount; + else + x += mnItemWidth+nHItemSpace; } else { @@ -364,13 +374,20 @@ void ThumbnailView::CalculateItemPositions () maItemStateHdl.Call(pItem); } + } + + ++nCurCount; } // arrange ScrollBar, set values and show it if ( mpScrBar ) { - long nLines = (nCurCount+mnCols-1)/mnCols; + mnLines = (nCurCount+mnCols-1)/mnCols; + + // check if scroll is needed + mbScroll = mnLines > mnVisLines; + Point aPos( aWinSize.Width() - nScrBarWidth - mnScrBarOffset, mnHeaderHeight ); Size aSize( nScrBarWidth - mnScrBarOffset, aWinSize.Height() - mnHeaderHeight ); @@ -383,7 +400,7 @@ void ThumbnailView::CalculateItemPositions () if ( nPageSize < 1 ) nPageSize = 1; mpScrBar->SetPageSize( nPageSize ); - mpScrBar->Show( nLines > mnVisLines ); + mpScrBar->Show( mbScroll ); } // delete ScrollBar @@ -399,9 +416,9 @@ size_t ThumbnailView::ImplGetItem( const Point& rPos, bool bMove ) const if ( maItemListRect.IsInside( rPos ) ) { - for (size_t i = 0; i < mItemList.size(); ++i) + for (size_t i = 0; i < mFilteredItemList.size(); ++i) { - if (mItemList[i]->isVisible() && mItemList[i]->getDrawArea().IsInside(rPos)) + if (mFilteredItemList[i]->isVisible() && mFilteredItemList[i]->getDrawArea().IsInside(rPos)) return i; } @@ -418,7 +435,7 @@ size_t ThumbnailView::ImplGetItem( const Point& rPos, bool bMove ) const ThumbnailViewItem* ThumbnailView::ImplGetItem( size_t nPos ) { - return ( nPos < mItemList.size() ) ? mItemList[nPos] : NULL; + return ( nPos < mFilteredItemList.size() ) ? mFilteredItemList[nPos] : NULL; } sal_uInt16 ThumbnailView::ImplGetVisibleItemCount() const @@ -491,34 +508,287 @@ IMPL_LINK (ThumbnailView, OnItemSelected, ThumbnailViewItem*, pItem) return 0; } +void ThumbnailView::KeyInput( const KeyEvent& rKEvt ) +{ + // Get the last selected item in the list + size_t nLastPos = 0; + bool bFoundLast = false; + for ( long i = mFilteredItemList.size() - 1; !bFoundLast && i >= 0; --i ) + { + ThumbnailViewItem* pItem = mFilteredItemList[i]; + if ( pItem->isSelected() ) + { + nLastPos = i; + bFoundLast = true; + } + } + + bool bValidRange = false; + bool bHasSelRange = mpStartSelRange != mFilteredItemList.end(); + size_t nNextPos = nLastPos; + KeyCode aKeyCode = rKEvt.GetKeyCode(); + ThumbnailViewItem* pNext = NULL; + + if (aKeyCode.IsShift() && bHasSelRange) + { + //If the last elemented selected is the start range position + //search for the first selected item + size_t nSelPos = mpStartSelRange - mFilteredItemList.begin(); + + if (nLastPos == nSelPos) + { + while (nLastPos && mFilteredItemList[nLastPos-1]->isSelected()) + --nLastPos; + } + } + + switch ( aKeyCode.GetCode() ) + { + case KEY_RIGHT: + { + if ( bFoundLast && nLastPos < mFilteredItemList.size( ) - 1 ) + { + bValidRange = true; + nNextPos = nLastPos + 1; + } + + pNext = mFilteredItemList[nNextPos]; + } + break; + case KEY_LEFT: + { + if ( nLastPos > 0 ) + { + bValidRange = true; + nNextPos = nLastPos - 1; + } + + pNext = mFilteredItemList[nNextPos]; + } + break; + case KEY_DOWN: + { + if ( bFoundLast && nLastPos < mFilteredItemList.size( ) - mnCols ) + { + bValidRange = true; + nNextPos = nLastPos + mnCols; + } + + pNext = mFilteredItemList[nNextPos]; + } + break; + case KEY_UP: + { + if ( nLastPos >= mnCols ) + { + bValidRange = true; + nNextPos = nLastPos - mnCols; + } + + pNext = mFilteredItemList[nNextPos]; + } + break; + case KEY_RETURN: + { + if ( bFoundLast ) + OnItemDblClicked( mFilteredItemList[nLastPos] ); + } + default: + Control::KeyInput( rKEvt ); + } + + if ( pNext ) + { + if (aKeyCode.IsShift() && bValidRange) + { + std::pair<size_t,size_t> aRange; + size_t nSelPos = mpStartSelRange - mFilteredItemList.begin(); + + if (nLastPos < nSelPos) + { + if (nNextPos > nLastPos) + { + if ( nNextPos > nSelPos) + aRange = std::make_pair(nLastPos,nNextPos); + else + aRange = std::make_pair(nLastPos,nNextPos-1); + } + else + aRange = std::make_pair(nNextPos,nLastPos-1); + } + else if (nLastPos == nSelPos) + { + if (nNextPos > nLastPos) + aRange = std::make_pair(nLastPos+1,nNextPos); + else + aRange = std::make_pair(nNextPos,nLastPos-1); + } + else + { + if (nNextPos > nLastPos) + aRange = std::make_pair(nLastPos+1,nNextPos); + else + { + if ( nNextPos < nSelPos) + aRange = std::make_pair(nNextPos,nLastPos); + else + aRange = std::make_pair(nNextPos+1,nLastPos); + } + } + + for (size_t i = aRange.first; i <= aRange.second; ++i) + { + if (i != nSelPos) + { + ThumbnailViewItem *pCurItem = mFilteredItemList[i]; + + pCurItem->setSelection(!pCurItem->isSelected()); + + if (pCurItem->isVisible()) + DrawItem(pCurItem); + + maItemStateHdl.Call(pCurItem); + } + } + } + else if (!aKeyCode.IsShift()) + { + deselectItems(); + SelectItem(pNext->mnId); + + //Mark it as the selection range start position + mpStartSelRange = mFilteredItemList.begin() + nNextPos; + } + + MakeItemVisible(pNext->mnId); + } +} + +void ThumbnailView::MakeItemVisible( sal_uInt16 nItemId ) +{ + // Get the item row + size_t nPos = 0; + bool bFound = false; + for ( size_t i = 0; !bFound && i < mFilteredItemList.size(); ++i ) + { + ThumbnailViewItem* pItem = mFilteredItemList[i]; + if ( pItem->mnId == nItemId ) + { + nPos = i; + bFound = true; + } + } + sal_uInt16 nRow = nPos / mnCols; + + // Move the visible rows as little as possible to include that one + if ( nRow < mnFirstLine ) + mnFirstLine = nRow; + else if ( nRow > mnFirstLine + mnVisLines ) + mnFirstLine = nRow - mnVisLines; + + CalculateItemPositions(); + Invalidate(); +} + void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt ) { if ( rMEvt.IsLeft() ) { - ThumbnailViewItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) ); + size_t nPos = ImplGetItem(rMEvt.GetPosPixel()); + ThumbnailViewItem* pItem = ImplGetItem(nPos); if (pItem && pItem->isVisible()) { if ( rMEvt.GetClicks() == 1 ) { - if (!pItem->isSelected() && !rMEvt.IsMod1()) - deselectItems( ); - pItem->setSelection(true); + if (rMEvt.IsMod1()) + { + //Keep selected item group state and just invert current desired one state + pItem->setSelection(!pItem->isSelected()); + + //This one becomes the selection range start position if it changes its state to selected otherwise resets it + mpStartSelRange = pItem->isSelected() ? mFilteredItemList.begin() + nPos : mFilteredItemList.end(); + } + else if (rMEvt.IsShift() && mpStartSelRange != mFilteredItemList.end()) + { + std::pair<size_t,size_t> aNewRange; + aNewRange.first = mpStartSelRange - mFilteredItemList.begin(); + aNewRange.second = nPos; + + if (aNewRange.first > aNewRange.second) + std::swap(aNewRange.first,aNewRange.second); + + //Deselect the ones outside of it + for (size_t i = 0, n = mFilteredItemList.size(); i < n; ++i) + { + ThumbnailViewItem *pCurItem = mFilteredItemList[i]; - bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel()); - pItem->setEditTitle(bClickOnTitle); + if (pCurItem->isSelected() && (i < aNewRange.first || i > aNewRange.second)) + { + pCurItem->setSelection(false); + + if (pCurItem->isVisible()) + DrawItem(pCurItem); + + maItemStateHdl.Call(pCurItem); + } + } + + size_t nSelPos = mpStartSelRange - mFilteredItemList.begin(); + + //Select the items between start range and the selected item + if (nSelPos != nPos) + { + int dir = nSelPos < nPos ? 1 : -1; + size_t nCurPos = nSelPos + dir; + + while (nCurPos != nPos) + { + ThumbnailViewItem *pCurItem = mFilteredItemList[nCurPos]; + + if (!pCurItem->isSelected()) + { + pCurItem->setSelection(true); + + if (pCurItem->isVisible()) + DrawItem(pCurItem); + + maItemStateHdl.Call(pCurItem); + } + + nCurPos += dir; + } + } + + pItem->setSelection(true); + } + else + { + //If we got a group of selected items deselect the rest and only keep the desired one + //mark items as not selected to not fire unnecessary change state events. + pItem->setSelection(false); + deselectItems(); + pItem->setSelection(true); + + //Mark as initial selection range position and reset end one + mpStartSelRange = mFilteredItemList.begin() + nPos; + } + + if (pItem->isSelected()) + { + bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel()); + pItem->setEditTitle(bClickOnTitle); + } if (!pItem->isHighlighted()) DrawItem(pItem); maItemStateHdl.Call(pItem); + + //fire accessible event?? } else if ( rMEvt.GetClicks() == 2 ) { - // The mouse button down event 1 click right before is pointless - pItem->setSelection(false); - maItemStateHdl.Call(pItem); - Rectangle aRect(pItem->getDrawArea()); if (aRect.IsInside(rMEvt.GetPosPixel())) @@ -579,12 +849,28 @@ void ThumbnailView::Paint( const Rectangle &aRect) void ThumbnailView::GetFocus() { - Control::GetFocus(); + if(GETFOCUS_TAB & GetGetFocusFlags()) + { + // Select the first item if nothing selected + int nSelected = -1; + for (size_t i = 0, n = mItemList.size(); i < n && nSelected == -1; ++i) + { + if (mItemList[i]->isSelected()) + nSelected = i; + } + + if ( nSelected == -1 && mItemList.size( ) > 0 ) + { + SelectItem( 1 ); + } + } // Tell the accessible object that we got the focus. ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) ); if( pAcc ) pAcc->GetFocus(); + + Control::GetFocus(); } void ThumbnailView::LoseFocus() @@ -616,11 +902,11 @@ void ThumbnailView::LoseFocus() void ThumbnailView::Resize() { + Control::Resize(); CalculateItemPositions(); if ( IsReallyVisible() && IsUpdateMode() ) Invalidate(); - Control::Resize(); } void ThumbnailView::StateChanged( StateChangedType nType ) @@ -685,18 +971,37 @@ void ThumbnailView::RemoveItem( sal_uInt16 nItemId ) if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND ) return; - if ( nPos < mItemList.size() ) { - ValueItemList::iterator it = mItemList.begin(); + if ( nPos < mFilteredItemList.size() ) { + + // delete item from the thumbnail list + for (size_t i = 0, n = mItemList.size(); i < n; ++i) + { + if (mItemList[i]->mnId == nItemId) + { + mItemList.erase(mItemList.begin()+i); + break; + } + } + + // delete item from the filter item list + ValueItemList::iterator it = mFilteredItemList.begin(); ::std::advance( it, nPos ); + + if ((*it)->isSelected()) + { + (*it)->setSelection(false); + maItemStateHdl.Call(*it); + } + delete *it; - mItemList.erase( it ); + mFilteredItemList.erase( it ); + mpStartSelRange = mFilteredItemList.end(); } // reset variables - if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) ) + if ( (mnHighItemId == nItemId) ) { mnHighItemId = 0; - mnSelItemId = 0; } CalculateItemPositions(); @@ -712,7 +1017,6 @@ void ThumbnailView::Clear() // reset variables mnFirstLine = 0; mnHighItemId = 0; - mnSelItemId = 0; CalculateItemPositions(); @@ -720,10 +1024,23 @@ void ThumbnailView::Clear() Invalidate(); } +void ThumbnailView::updateItems (const std::vector<ThumbnailViewItem*> &items) +{ + ImplDeleteItems(); + + // reset variables + mnFirstLine = 0; + mnHighItemId = 0; + + mItemList = items; + + filterItems(maFilterFunc); +} + size_t ThumbnailView::GetItemPos( sal_uInt16 nItemId ) const { - for ( size_t i = 0, n = mItemList.size(); i < n; ++i ) { - if ( mItemList[i]->mnId == nItemId ) { + for ( size_t i = 0, n = mFilteredItemList.size(); i < n; ++i ) { + if ( mFilteredItemList[i]->mnId == nItemId ) { return i; } } @@ -732,7 +1049,7 @@ size_t ThumbnailView::GetItemPos( sal_uInt16 nItemId ) const sal_uInt16 ThumbnailView::GetItemId( size_t nPos ) const { - return ( nPos < mItemList.size() ) ? mItemList[nPos]->mnId : 0 ; + return ( nPos < mFilteredItemList.size() ) ? mFilteredItemList[nPos]->mnId : 0 ; } sal_uInt16 ThumbnailView::GetItemId( const Point& rPos ) const @@ -744,6 +1061,11 @@ sal_uInt16 ThumbnailView::GetItemId( const Point& rPos ) const return 0; } +sal_uInt16 ThumbnailView::getNextItemId() const +{ + return mItemList.empty() ? 1 : mItemList.back()->mnId + 1; +} + void ThumbnailView::setItemMaxTextLength(sal_uInt32 nLength) { mpItemAttrs->nMaxTextLenght = nLength; @@ -760,19 +1082,18 @@ void ThumbnailView::setItemDimensions(long itemWidth, long thumbnailHeight, long void ThumbnailView::SelectItem( sal_uInt16 nItemId ) { - size_t nItemPos = 0; + size_t nItemPos = GetItemPos( nItemId ); + if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND ) + return; - if ( nItemId ) + ThumbnailViewItem* pItem = mFilteredItemList[nItemPos]; + if (!pItem->isSelected()) { - nItemPos = GetItemPos( nItemId ); - if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND ) - return; - } + pItem->setSelection(true); + maItemStateHdl.Call(pItem); - if ( mnSelItemId != nItemId) - { - sal_uInt16 nOldItem = mnSelItemId ? mnSelItemId : 1; - mnSelItemId = nItemId; + if (IsReallyVisible() && IsUpdateMode()) + Invalidate(); bool bNewOut = IsReallyVisible() && IsUpdateMode(); @@ -798,44 +1119,8 @@ void ThumbnailView::SelectItem( sal_uInt16 nItemId ) if( ImplHasAccessibleListeners() ) { - // focus event (deselect) - if( nOldItem ) - { - const size_t nPos = GetItemPos( nItemId ); - - if( nPos != THUMBNAILVIEW_ITEM_NOTFOUND ) - { - ThumbnailViewAcc* pItemAcc = ThumbnailViewAcc::getImplementation( - mItemList[nPos]->GetAccessible( mbIsTransientChildrenDisabled ) ); - - if( pItemAcc ) - { - ::com::sun::star::uno::Any aOldAny, aNewAny; - if( !mbIsTransientChildrenDisabled ) - { - aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >( - static_cast< ::cppu::OWeakObject* >( pItemAcc )); - ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny ); - } - else - { - aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED; - pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny ); - } - } - } - } - // focus event (select) - const size_t nPos = GetItemPos( mnSelItemId ); - - ThumbnailViewItem* pItem = NULL; - if( nPos != THUMBNAILVIEW_ITEM_NOTFOUND ) - pItem = mItemList[nPos]; - - ThumbnailViewAcc* pItemAcc = NULL; - if (pItem != NULL) - pItemAcc = ThumbnailViewAcc::getImplementation( pItem->GetAccessible( mbIsTransientChildrenDisabled ) ); + ThumbnailViewAcc* pItemAcc = ThumbnailViewAcc::getImplementation( pItem->GetAccessible( mbIsTransientChildrenDisabled ) ); if( pItemAcc ) { @@ -878,6 +1163,35 @@ void ThumbnailView::deselectItem(const sal_uInt16 nItemId) } } +void ThumbnailView::DeselectItem( sal_uInt16 nItemId ) +{ + size_t nItemPos = GetItemPos( nItemId ); + if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND ) + return; + + ThumbnailViewItem* pItem = mFilteredItemList[nItemPos]; + if (pItem->isSelected()) + { + pItem->setSelection(false); + maItemStateHdl.Call(pItem); + + if (IsReallyVisible() && IsUpdateMode()) + Invalidate(); + + // TODO Trigger event in accessible object? + } +} + +bool ThumbnailView::IsItemSelected( sal_uInt16 nItemId ) const +{ + size_t nItemPos = GetItemPos( nItemId ); + if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND ) + return false; + + ThumbnailViewItem* pItem = mFilteredItemList[nItemPos]; + return pItem->isSelected(); +} + void ThumbnailView::deselectItems() { for (size_t i = 0, n = mItemList.size(); i < n; ++i) @@ -900,7 +1214,7 @@ OUString ThumbnailView::GetItemText( sal_uInt16 nItemId ) const size_t nPos = GetItemPos( nItemId ); if ( nPos != THUMBNAILVIEW_ITEM_NOTFOUND ) - return mItemList[nPos]->maTitle; + return mFilteredItemList[nPos]->maTitle; return OUString(); } @@ -914,58 +1228,52 @@ void ThumbnailView::SetColor( const Color& rColor ) Invalidate(); } -bool ThumbnailView::StartDrag( const CommandEvent& rCEvt, Region& rRegion ) +void ThumbnailView::filterItems (const boost::function<bool (const ThumbnailViewItem*) > &func) { - if ( rCEvt.GetCommand() != COMMAND_STARTDRAG ) - return false; - - // if necessary abort an existing action + mnFirstLine = 0; // start at the top of the list instead of the current position + maFilterFunc = func; - // Check out if the the clicked on page is selected. If this is not the - // case set it as the current item. We only check mouse actions since - // drag-and-drop can also be triggered by the keyboard - sal_uInt16 nSelId; - if ( rCEvt.IsMouseEvent() ) - nSelId = GetItemId( rCEvt.GetMousePosPixel() ); - else - nSelId = mnSelItemId; + size_t nSelPos = 0; + bool bHasSelRange = false; + ThumbnailViewItem *curSel = mpStartSelRange != mFilteredItemList.end() ? *mpStartSelRange : NULL; - // don't activate dragging if no item was clicked on - if ( !nSelId ) - return false; + mFilteredItemList.clear(); - // Check out if the page was selected. If not set as current page and - // call select. - if ( nSelId != mnSelItemId ) + for (size_t i = 0, n = mItemList.size(); i < n; ++i) { - SelectItem( nSelId ); - Update(); - } + ThumbnailViewItem *const pItem = mItemList[i]; - Region aRegion; + if (maFilterFunc(pItem)) + { + if (curSel == pItem) + { + nSelPos = i; + bHasSelRange = true; + } - // assign region - rRegion = aRegion; + mFilteredItemList.push_back(pItem); + } + else + { + if( pItem->isVisible()) + { + if ( ImplHasAccessibleListeners() ) + { + ::com::sun::star::uno::Any aOldAny, aNewAny; - return true; -} + aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled ); + ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny ); + } -long ThumbnailView::GetScrollWidth() const -{ - if ( GetStyle() & WB_VSCROLL ) - { - ((ThumbnailView*)this)->ImplInitScrollBar(); - return mpScrBar->GetSizePixel().Width()+mnScrBarOffset; - } - else - return 0; -} + pItem->show(false); + pItem->setSelection(false); -void ThumbnailView::filterItems (const boost::function<bool (const ThumbnailViewItem*) > &func) -{ - mnFirstLine = 0; // start at the top of the list instead of the current position - maFilterFunc = func; + maItemStateHdl.Call(pItem); + } + } + } + mpStartSelRange = bHasSelRange ? mFilteredItemList.begin() + nSelPos : mFilteredItemList.end(); CalculateItemPositions(); Invalidate(); diff --git a/sfx2/source/control/thumbnailviewacc.cxx b/sfx2/source/control/thumbnailviewacc.cxx index 8a7da2b37f71..c89f1b0788fc 100644 --- a/sfx2/source/control/thumbnailviewacc.cxx +++ b/sfx2/source/control/thumbnailviewacc.cxx @@ -350,7 +350,7 @@ uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAcces if( THUMBNAILVIEW_ITEM_NONEITEM != nItemPos ) { - ThumbnailViewItem *const pItem = mpParent->mItemList[nItemPos]; + ThumbnailViewItem *const pItem = mpParent->mFilteredItemList[nItemPos]; xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled ); } } @@ -788,7 +788,7 @@ uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewItemA // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE ); // SELECTED - if( mpParent->mrParent.GetSelectItemId() == mpParent->mnId ) + if( mpParent->isSelected() ) { pStateSet->AddState( accessibility::AccessibleStateType::SELECTED ); // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED ); diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx index a81c27dd5350..c551bac9d027 100644 --- a/sfx2/source/dialog/templdlg.cxx +++ b/sfx2/source/dialog/templdlg.cxx @@ -753,6 +753,7 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, Sfx bUpdateByExampleDisabled( sal_False ), bTreeDrag ( sal_True ), bHierarchical ( sal_False ), + m_bWantHierarchical ( sal_False ), bBindingUpdate ( sal_True ) { aFmtLb.SetAccessibleName(SfxResId(STR_STYLE_ELEMTLIST).toString()); @@ -1278,8 +1279,10 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags) } // if the tree view again, select family hierarchy - if(pTreeBox) + if (pTreeBox || m_bWantHierarchical) + { aFilterLb.SelectEntry(SfxResId(STR_STYLE_FILTER_HIERARCHICAL).toString()); + } // show maximum 14 entries aFilterLb.SetDropDownLineCount( MAX_FILTER_ENTRIES ); @@ -1287,12 +1290,21 @@ void SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(sal_uInt16 nFlags) } else { - if( nActFilter < aFilterLb.GetEntryCount() - 1) - aFilterLb.SelectEntryPos(nActFilter + 1); - else + if (m_bWantHierarchical) { nActFilter = 0; - aFilterLb.SelectEntryPos(1); + aFilterLb.SelectEntry(SfxResId( + STR_STYLE_FILTER_HIERARCHICAL).toString()); + } + else + { + if (nActFilter < aFilterLb.GetEntryCount() - 1) + aFilterLb.SelectEntryPos(nActFilter + 1); + else + { + nActFilter = 0; + aFilterLb.SelectEntryPos(1); + } } } @@ -1635,7 +1647,6 @@ void SfxCommonTemplateDialog_Impl::Notify(SfxBroadcaster& /*rBC*/, const SfxHint //------------------------------------------------------------------------- - // Other filters; can be switched by the users or as a result of new or // editing, if the current document has been assigned a different filter. void SfxCommonTemplateDialog_Impl::FilterSelect( @@ -1646,14 +1657,7 @@ void SfxCommonTemplateDialog_Impl::FilterSelect( if( nEntry != nActFilter || bForce ) { nActFilter = nEntry; - SfxViewFrame *pViewFrame = pBindings->GetDispatcher_Impl()->GetFrame(); - SfxObjectShell *pDocShell = pViewFrame->GetObjectShell(); - if (pDocShell) - { - pDocShell->SetAutoStyleFilterIndex(nActFilter); - SaveFactoryStyleFilter( pDocShell, nActFilter ); - } - + SfxObjectShell *const pDocShell = SaveSelection(); SfxStyleSheetBasePool *pOldStyleSheetPool = pStyleSheetPool; pStyleSheetPool = pDocShell? pDocShell->GetStyleSheetPool(): 0; if ( pOldStyleSheetPool != pStyleSheetPool ) @@ -1744,6 +1748,8 @@ IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox ) { // Turn on treeView bHierarchical=sal_True; + m_bWantHierarchical = sal_True; + SaveSelection(); // fdo#61429 store "hierarchical" const String aSelectEntry( GetSelectedEntry()); aFmtLb.Hide(); @@ -1776,6 +1782,7 @@ IMPL_LINK( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox *, pBox ) aFmtLb.Show(); // If bHierarchical, then the family can have changed // minus one since hierarchical is inserted at the start + m_bWantHierarchical = sal_False; // before FilterSelect FilterSelect(pBox->GetSelectEntryPos() - 1, bHierarchical ); bHierarchical=sal_False; } @@ -1918,6 +1925,10 @@ sal_Int32 SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter( SfxObjectShell* sal_Int32 nDefault = -1; nFilter = aFactoryProps.getUnpackedValueOrDefault( DEFINE_CONST_UNICODE("ooSetupFactoryStyleFilter"), nDefault ); + m_bWantHierarchical = + (nFilter & SFXSTYLEBIT_HIERARCHY) ? sal_True : sal_False; + nFilter &= ~SFXSTYLEBIT_HIERARCHY; // clear it + return nFilter; } @@ -1928,10 +1939,23 @@ void SfxCommonTemplateDialog_Impl::SaveFactoryStyleFilter( SfxObjectShell* i_pOb OSL_ENSURE( i_pObjSh, "SfxCommonTemplateDialog_Impl::LoadFactoryStyleFilter(): no ObjectShell" ); Sequence< PropertyValue > lProps(1); lProps[0].Name = DEFINE_CONST_UNICODE("ooSetupFactoryStyleFilter"); - lProps[0].Value = makeAny( i_nFilter );; + lProps[0].Value = makeAny( + i_nFilter | (m_bWantHierarchical ? SFXSTYLEBIT_HIERARCHY : 0)); xModuleManager->replaceByName( getModuleIdentifier( xModuleManager, i_pObjSh ), makeAny( lProps ) ); } +SfxObjectShell* SfxCommonTemplateDialog_Impl::SaveSelection() +{ + SfxViewFrame *const pViewFrame(pBindings->GetDispatcher_Impl()->GetFrame()); + SfxObjectShell *const pDocShell(pViewFrame->GetObjectShell()); + if (pDocShell) + { + pDocShell->SetAutoStyleFilterIndex(nActFilter); + SaveFactoryStyleFilter( pDocShell, nActFilter ); + } + return pDocShell; +} + //------------------------------------------------------------------------- IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox ) @@ -2650,7 +2674,7 @@ void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl() if ( pOldStyleSheetPool ) EndListening(*pOldStyleSheetPool); if ( pStyleSheetPool ) - StartListening(*pOldStyleSheetPool); + StartListening(*pStyleSheetPool); } bWaterDisabled = sal_False; diff --git a/sfx2/source/doc/doc.hrc b/sfx2/source/doc/doc.hrc index f3edfa7390d2..b56a47358228 100644 --- a/sfx2/source/doc/doc.hrc +++ b/sfx2/source/doc/doc.hrc @@ -39,6 +39,7 @@ #define DLG_DOC_TEMPLATE (RID_SFX_DOC_START+2) #define DLG_ORGANIZE (RID_SFX_DOC_START+3) #define DLG_TEMPLATE_MANAGER (RID_SFX_DOC_START+4) +#define TAB_TEMPLATE_MANAGER (RID_SFX_DOC_START+5) #define BMP_STYLES_CLOSED (RID_SFX_DOC_START+ 0) #define BMP_STYLES_OPENED (RID_SFX_DOC_START+ 1) diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx index 6678600c5cb4..dd09be0d640e 100644 --- a/sfx2/source/doc/doctempl.cxx +++ b/sfx2/source/doc/doctempl.cxx @@ -1098,6 +1098,24 @@ sal_Bool SfxDocumentTemplates::InsertDir return sal_False; } +sal_Bool SfxDocumentTemplates::InsertTemplate(sal_uInt16 nSourceRegion, sal_uInt16 nIdx, const OUString &rName, const OUString &rPath) +{ + DocTemplLocker_Impl aLocker( *pImp ); + + if ( ! pImp->Construct() ) + return sal_False; + + RegionData_Impl *pRegion = pImp->GetRegion( nSourceRegion ); + + if ( !pRegion ) + return sal_False; + + size_t pos = nIdx; + pRegion->AddEntry( rName, rPath, &pos ); + + return sal_True; +} + sal_Bool SfxDocumentTemplates::SetName( const OUString& rName, sal_uInt16 nRegion, sal_uInt16 nIdx ) { diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx index 7041966afb96..82289ba2618a 100644 --- a/sfx2/source/doc/templatedlg.cxx +++ b/sfx2/source/doc/templatedlg.cxx @@ -35,6 +35,7 @@ #include <tools/urlobj.hxx> #include <unotools/moduleoptions.hxx> #include <unotools/pathoptions.hxx> +#include <unotools/viewoptions.hxx> #include <vcl/edit.hxx> #include <vcl/msgbox.hxx> #include <vcl/toolbox.hxx> @@ -57,6 +58,10 @@ #define PADDING_DLG_BORDER 10 +#define TM_SETTING_MANAGER "TemplateManager" +#define TM_SETTING_LASTFOLDER "LastFolder" +#define TM_SETTING_FILTER "SelectedFilter" + using namespace ::com::sun::star; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::embed; @@ -85,36 +90,88 @@ class SearchView_Keyword { public: - SearchView_Keyword (const OUString &rKeyword) - : maKeyword(rKeyword) + SearchView_Keyword (const OUString &rKeyword, FILTER_APPLICATION App) + : maKeyword(rKeyword), meApp(App) {} bool operator() (const TemplateItemProperties &rItem) { - return rItem.aName.matchIgnoreAsciiCase(maKeyword); + bool bRet = true; + + INetURLObject aUrl(rItem.aPath); + OUString aExt = aUrl.getExtension(); + + if (meApp == FILTER_APP_WRITER) + { + bRet = aExt == "ott" || aExt == "stw" || aExt == "oth" || aExt == "dot" || aExt == "dotx"; + } + else if (meApp == FILTER_APP_CALC) + { + bRet = aExt == "ots" || aExt == "stc" || aExt == "xlt" || aExt == "xltm" || aExt == "xltx"; + } + else if (meApp == FILTER_APP_IMPRESS) + { + bRet = aExt == "otp" || aExt == "sti" || aExt == "pot" || aExt == "potm" || aExt == "potx"; + } + else if (meApp == FILTER_APP_DRAW) + { + bRet = aExt == "otg" || aExt == "std"; + } + + return bRet && rItem.aName.matchIgnoreAsciiCase(maKeyword); } private: OUString maKeyword; + FILTER_APPLICATION meApp; +}; + +/*** + * + * Order items in ascending order (useful for the selection sets and move/copy operations since the associated ids + * change when processed by the SfxDocumentTemplates class so we want to process to ones with higher id first) + * + ***/ + +static bool cmpSelectionItems (const ThumbnailViewItem *pItem1, const ThumbnailViewItem *pItem2) +{ + return pItem1->mnId > pItem2->mnId; +} + +class TemplateManagerPage : public TabPage +{ + private: + FixedText maFixedText; + + public: + TemplateManagerPage( Window* pParent ); + ~TemplateManagerPage( ) { }; }; SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent) : ModelessDialog(parent, SfxResId(DLG_TEMPLATE_MANAGER)), maTabControl(this,SfxResId(TAB_CONTROL)), - mpToolbars( new Control(&maTabControl,SfxResId(TOOLBARS))), - mpSearchEdit(new Edit(this,WB_HIDE | WB_BORDER)), - mpViewBar( new ToolBox(mpToolbars, SfxResId(TBX_ACTION_VIEW))), - mpActionBar( new ToolBox(mpToolbars, SfxResId(TBX_ACTION_ACTION))), - mpTemplateBar( new ToolBox(mpToolbars, SfxResId(TBX_ACTION_TEMPLATES))), - mpSearchView(new TemplateSearchView(this)), - maView(new TemplateLocalView(this,SfxResId(TEMPLATE_VIEW))), - mpOnlineView(new TemplateRemoteView(this, WB_VSCROLL,false)), + maTabPage(&maTabControl, SfxResId(TAB_TEMPLATE_MANAGER)), + mpSearchEdit(new Edit(&maTabPage,WB_HIDE | WB_BORDER)), + mpViewBar( new ToolBox(&maTabPage, SfxResId(TBX_ACTION_VIEW))), + mpActionBar( new ToolBox(&maTabPage, SfxResId(TBX_ACTION_ACTION))), + mpTemplateBar( new ToolBox(&maTabPage, SfxResId(TBX_ACTION_TEMPLATES))), + mpSearchView(new TemplateSearchView(&maTabPage)), + maView(new TemplateLocalView(&maTabPage,SfxResId(TEMPLATE_VIEW))), + mpOnlineView(new TemplateRemoteView(&maTabPage, WB_VSCROLL,false)), + maSelTemplates(cmpSelectionItems), + maSelFolders(cmpSelectionItems), mbIsSaveMode(false), mxDesktop(comphelper::getProcessServiceFactory()->createInstance( "com.sun.star.frame.Desktop" ),uno::UNO_QUERY ), mbIsSynced(false), maRepositories() { + maTabControl.SetTabPage( FILTER_DOCS, &maTabPage ); + maTabControl.SetTabPage( FILTER_SHEETS, &maTabPage ); + maTabControl.SetTabPage( FILTER_PRESENTATIONS, &maTabPage ); + maTabControl.SetTabPage( FILTER_DRAWS, &maTabPage ); + // Create popup menus mpActionMenu = new PopupMenu; mpActionMenu->InsertItem(MNI_ACTION_SORT_NAME,SfxResId(STR_ACTION_SORT_NAME).toString(),SfxResId(IMG_ACTION_SORT)); @@ -148,17 +205,16 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent) mpSearchEdit->SetUpdateDataHdl(LINK(this,SfxTemplateManagerDlg,SearchUpdateHdl)); mpSearchEdit->EnableUpdateData(); - maView->SetStyle(WB_VSCROLL); + maView->SetStyle(maView->GetStyle() | WB_VSCROLL); maView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH); maView->setItemDimensions(TEMPLATE_ITEM_MAX_WIDTH,TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT, TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT, TEMPLATE_ITEM_PADDING); - maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVFolderStateHdl)); - maView->setOverlayItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl)); - maView->setOverlayDblClickHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl)); - maView->setOverlayCloseHdl(LINK(this,SfxTemplateManagerDlg,CloseOverlayHdl)); + maView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl)); + maView->setOpenRegionHdl(LINK(this,SfxTemplateManagerDlg,OpenRegionHdl)); + maView->setOpenTemplateHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl)); // Set online view position and dimensions mpOnlineView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH); @@ -167,17 +223,17 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent) TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT, TEMPLATE_ITEM_PADDING); - mpOnlineView->setOverlayItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl)); - mpOnlineView->setOverlayDblClickHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl)); - mpOnlineView->setOverlayCloseHdl(LINK(this,SfxTemplateManagerDlg,CloseOverlayHdl)); + mpOnlineView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl)); + mpOnlineView->setOpenRegionHdl(LINK(this,SfxTemplateManagerDlg,OpenRegionHdl)); + mpOnlineView->setOpenTemplateHdl(LINK(this,SfxTemplateManagerDlg,OpenTemplateHdl)); mpSearchView->setItemMaxTextLength(TEMPLATE_ITEM_MAX_TEXT_LENGTH); mpSearchView->setItemDimensions(TEMPLATE_ITEM_MAX_WIDTH,TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT, - TEMPLATE_ITEM_MAX_HEIGHT-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT, + TEMPLATE_ITEM_MAX_HEIGHT_SUB-TEMPLATE_ITEM_THUMBNAIL_MAX_HEIGHT, TEMPLATE_ITEM_PADDING); - mpSearchView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVTemplateStateHdl)); + mpSearchView->setItemStateHdl(LINK(this,SfxTemplateManagerDlg,TVItemStateHdl)); maTabControl.SetActivatePageHdl(LINK(this,SfxTemplateManagerDlg,ActivatePageHdl)); @@ -188,6 +244,8 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent) mpViewBar->RemoveItem(nPos); } + SetMinOutputSizePixel(GetOutputSizePixel()); + mpViewBar->Show(); mpActionBar->Show(); @@ -199,20 +257,35 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg (Window *parent) createDefaultTemplateMenu(); maView->Populate(); - maView->Show(); + mpCurView->filterItems(ViewFilter_Application(FILTER_APP_WRITER)); + + readSettings(); - mpCurView->filterTemplatesByApp(FILTER_APP_WRITER); + maView->Show(); FreeResource(); } SfxTemplateManagerDlg::~SfxTemplateManagerDlg () { + writeSettings(); + // Synchronize the config before deleting it syncRepositories(); for (size_t i = 0, n = maRepositories.size(); i < n; ++i) delete maRepositories[i]; + // Ignore view events since we are cleaning the object + maView->setItemStateHdl(Link()); + maView->setOpenRegionHdl(Link()); + maView->setOpenTemplateHdl(Link()); + + mpOnlineView->setItemStateHdl(Link()); + mpOnlineView->setOpenRegionHdl(Link()); + mpOnlineView->setOpenTemplateHdl(Link()); + + mpSearchView->setItemStateHdl(Link()); + delete mpSearchEdit; delete mpViewBar; delete mpActionBar; @@ -223,20 +296,27 @@ SfxTemplateManagerDlg::~SfxTemplateManagerDlg () delete mpTemplateDefaultMenu; delete mpActionMenu; delete mpRepositoryMenu; - delete mpToolbars; } void SfxTemplateManagerDlg::setSaveMode(bool bMode) { mbIsSaveMode = bMode; maTabControl.Clear(); - mpCurView->filterTemplatesByApp(FILTER_APP_NONE); + mpCurView->filterItems(ViewFilter_Application(FILTER_APP_NONE)); if (bMode) { mpViewBar->ShowItem(TBI_TEMPLATE_SAVE); mpViewBar->HideItem(TBI_TEMPLATE_IMPORT); mpViewBar->HideItem(TBI_TEMPLATE_REPOSITORY); + + mpTemplateBar->ShowItem(TBI_TEMPLATE_SAVE); + mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES); + mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT); + mpTemplateBar->HideItem(TBI_TEMPLATE_EDIT); + mpTemplateBar->HideItem(TBI_TEMPLATE_MOVE); + mpTemplateBar->HideItem(TBI_TEMPLATE_EXPORT); + mpTemplateBar->HideItem(TBI_TEMPLATE_DELETE); } else { @@ -269,46 +349,103 @@ IMPL_LINK_NOARG(SfxTemplateManagerDlg,ActivatePageHdl) eFilter = FILTER_APP_DRAW; break; } - mpCurView->filterTemplatesByApp(eFilter); + mpCurView->filterItems(ViewFilter_Application(eFilter)); + + if (mpSearchView->IsVisible()) + SearchUpdateHdl(NULL); + return 0; } -void SfxTemplateManagerDlg::MouseButtonDown( const MouseEvent& rMEvt ) +void SfxTemplateManagerDlg::readSettings () { - if (!maView->GetActiveClipRegion().IsInside(rMEvt.GetPosPixel()) && maView->isOverlayVisible()) + OUString aLastFolder; + sal_uInt16 nPageId = FILTER_DOCS; + SvtViewOptions aViewSettings( E_DIALOG, TM_SETTING_MANAGER ); + + if ( aViewSettings.Exists() ) { - maSelTemplates.clear(); - mpTemplateBar->Hide(); - mpViewBar->Show(); + sal_uInt16 nFilter = 0; + aViewSettings.GetUserItem(TM_SETTING_LASTFOLDER) >>= aLastFolder; + aViewSettings.GetUserItem(TM_SETTING_FILTER) >>= nFilter; - maView->showOverlay(false); + switch (nFilter) + { + case FILTER_APP_WRITER: + nPageId = FILTER_DOCS; + break; + case FILTER_APP_IMPRESS: + nPageId = FILTER_PRESENTATIONS; + break; + case FILTER_APP_CALC: + nPageId = FILTER_SHEETS; + break; + case FILTER_APP_DRAW: + nPageId = FILTER_DRAWS; + break; + } } + + if (!aLastFolder.getLength()) + maView->showRootRegion(); + else + maView->showRegion(aLastFolder); + + maTabControl.SelectTabPage(nPageId); } -void SfxTemplateManagerDlg::Resize() +void SfxTemplateManagerDlg::writeSettings () { - Size aWinSize = GetSizePixel(); + Sequence< NamedValue > aSettings(2); + + OUString aLastFolder; + + if (mpCurView == maView && maView->getCurRegionId()) + aLastFolder = maView->getRegionName(maView->getCurRegionId()-1); + + // last folder + aSettings[0].Name = TM_SETTING_LASTFOLDER; + aSettings[0].Value <<= aLastFolder; + + sal_uInt16 nFilter = FILTER_APP_WRITER; + switch (maTabControl.GetCurPageId()) + { + case FILTER_DOCS: + nFilter = FILTER_APP_WRITER; + break; + case FILTER_PRESENTATIONS: + nFilter = FILTER_APP_IMPRESS; + break; + case FILTER_SHEETS: + nFilter = FILTER_APP_CALC; + break; + case FILTER_DRAWS: + nFilter = FILTER_APP_DRAW; + break; + } + + aSettings[1].Name = TM_SETTING_FILTER; + aSettings[1].Value <<= nFilter; + + // write + SvtViewOptions aViewSettings( E_DIALOG, TM_SETTING_MANAGER ); + aViewSettings.SetUserData( aSettings ); +} +void SfxTemplateManagerDlg::Resize() +{ // Fit the tab page control and the toolbars - Size aTabSize = maTabControl.GetSizePixel(); - aTabSize.setWidth(aWinSize.getWidth()); - maTabControl.SetSizePixel(aTabSize); - Size aTabPageSize = maTabControl.GetTabPageSizePixel(); - Point aToolbarsPos(0, aTabSize.getHeight() - aTabPageSize.getHeight()); - mpToolbars->SetPosPixel(aToolbarsPos); - aTabPageSize.setHeight(mpToolbars->GetSizePixel().getHeight() + 3); - maTabControl.SetTabPageSizePixel(aTabPageSize); - - Size aToolbarsSize = mpToolbars->GetSizePixel(); - aToolbarsSize.setWidth(aWinSize.getWidth()); - mpToolbars->SetSizePixel(aToolbarsSize); + maTabControl.SetSizePixel(GetSizePixel()); + const Size aWinSize = maTabControl.GetTabPageSizePixel(); // Calculate toolboxes size and positions Size aViewSize = mpViewBar->CalcMinimumWindowSizePixel(); Size aActionSize = mpActionBar->CalcMinimumWindowSizePixel(); Size aTemplateSize = mpTemplateBar->CalcMinimumWindowSizePixel(); - aActionSize.setWidth(3*aActionSize.getWidth()); + long nToolbarsHeight = std::max(std::max(aViewSize.getHeight(), aActionSize.getHeight()), aTemplateSize.getHeight()); + + aActionSize.setWidth(2.5*aActionSize.getWidth()); aViewSize.setWidth(aWinSize.getWidth()-aActionSize.getWidth()-mpViewBar->GetPosPixel().X()); aTemplateSize.setWidth(aWinSize.getWidth()); @@ -319,15 +456,9 @@ void SfxTemplateManagerDlg::Resize() mpActionBar->SetPosSizePixel(aActionPos,aActionSize); mpTemplateBar->SetSizePixel(aTemplateSize); - // Set view position below toolbox Point aViewPos = maView->GetPosPixel(); - aViewPos.setY(maTabControl.GetPosPixel().Y() + maTabControl.GetSizePixel().getHeight()); + aViewPos.setY(nToolbarsHeight); aViewPos.setX(0); - Size aThumbSize(aWinSize.getWidth(), aWinSize.getHeight() - aViewPos.getY()); - maView->SetPosSizePixel(aViewPos, aThumbSize); - - if (aWinSize.getHeight() < aViewPos.getY() + aThumbSize.getHeight() + PADDING_DLG_BORDER) - aWinSize.setHeight(aViewPos.getY() + aThumbSize.getHeight() + PADDING_DLG_BORDER); // Set search box position and size Size aSearchSize = mpSearchEdit->CalcMinimumSize(); @@ -336,28 +467,17 @@ void SfxTemplateManagerDlg::Resize() mpSearchEdit->SetSizePixel(aSearchSize); mpSearchEdit->SetPosPixel(Point(PADDING_DLG_BORDER,aViewPos.Y())); - maView->SetSizePixel(aThumbSize); - mpOnlineView->SetPosSizePixel(aViewPos,aThumbSize); - mpSearchView->SetSizePixel(aThumbSize); - - mpCurView->Resize(); - - ModelessDialog::Resize(); -} + if (mpSearchEdit->IsVisible()) + aViewPos.setY(aViewPos.getY() + mpSearchEdit->GetSizePixel().getHeight() ); -IMPL_LINK_NOARG(SfxTemplateManagerDlg, CloseOverlayHdl) -{ - maSelTemplates.clear(); - mpTemplateBar->Hide(); - mpViewBar->Show(); - mpActionBar->Show(); + // Set view position below toolbox and search box + Size aThumbSize(aWinSize.getWidth(), aWinSize.getHeight() - aViewPos.getY()); - if (mpCurView == maView) - mpCurView->showOverlay(false); - else - switchMainView(true); + maView->SetPosSizePixel(aViewPos,aThumbSize); + mpOnlineView->SetPosSizePixel(aViewPos,aThumbSize); + mpSearchView->SetPosSizePixel(aViewPos,aThumbSize); - return 0; + ModelessDialog::Resize(); } IMPL_LINK_NOARG(SfxTemplateManagerDlg,TBXViewHdl) @@ -485,79 +605,14 @@ IMPL_LINK(SfxTemplateManagerDlg, TBXDropdownHdl, ToolBox*, pBox) return 0; } -IMPL_LINK(SfxTemplateManagerDlg, TVFolderStateHdl, const ThumbnailViewItem*, pItem) +IMPL_LINK(SfxTemplateManagerDlg, TVItemStateHdl, const ThumbnailViewItem*, pItem) { - if (pItem->isSelected()) - { - if (maSelFolders.empty() && !mbIsSaveMode) - { - mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT); - mpViewBar->ShowItem(TBI_TEMPLATE_FOLDER_DEL); - } + const TemplateContainerItem *pCntItem = dynamic_cast<const TemplateContainerItem*>(pItem); - maSelFolders.insert(pItem); - } + if (pCntItem) + OnRegionState(pItem); else - { - maSelFolders.erase(pItem); - - if (maSelFolders.empty() && !mbIsSaveMode) - { - mpViewBar->HideItem(TBI_TEMPLATE_IMPORT); - mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL); - } - } - - return 0; -} - -IMPL_LINK(SfxTemplateManagerDlg, TVTemplateStateHdl, const ThumbnailViewItem*, pItem) -{ - bool bInSelection = maSelTemplates.find(pItem) != maSelTemplates.end(); - if (pItem->isSelected()) - { - if (!mbIsSaveMode) - { - if (maSelTemplates.empty()) - { - mpViewBar->Show(false); - mpActionBar->Show(false); - mpTemplateBar->Show(); - } - else if (maSelTemplates.size() != 1 || !bInSelection) - { - mpTemplateBar->HideItem(TBI_TEMPLATE_EDIT); - mpTemplateBar->HideItem(TBI_TEMPLATE_PROPERTIES); - mpTemplateBar->HideItem(TBI_TEMPLATE_DEFAULT); - } - } - - if (!bInSelection) - maSelTemplates.insert(pItem); - } - else - { - if (bInSelection) - { - maSelTemplates.erase(pItem); - - if (!mbIsSaveMode) - { - if (maSelTemplates.empty()) - { - mpTemplateBar->Show(false); - mpViewBar->Show(); - mpActionBar->Show(); - } - else if (maSelTemplates.size() == 1) - { - mpTemplateBar->ShowItem(TBI_TEMPLATE_EDIT); - mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES); - mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT); - } - } - } - } + OnTemplateState(pItem); return 0; } @@ -569,10 +624,7 @@ IMPL_LINK(SfxTemplateManagerDlg, MenuSelectHdl, Menu*, pMenu) switch(nMenuId) { case MNI_ACTION_SORT_NAME: - if (maView->isOverlayVisible()) - maView->sortOverlayItems(SortView_Name()); - else - maView->sortItems(SortView_Name()); + maView->sortItems(SortView_Name()); break; case MNI_ACTION_REFRESH: mpCurView->reload(); @@ -651,10 +703,7 @@ IMPL_LINK(SfxTemplateManagerDlg, RepositoryMenuSelectHdl, Menu*, pMenu) } if (mpOnlineView->loadRepository(pRepository,false)) - { switchMainView(false); - mpOnlineView->showOverlay(true); - } } return 0; @@ -672,6 +721,21 @@ IMPL_LINK(SfxTemplateManagerDlg, DefaultTemplateMenuSelectHdl, Menu*, pMenu) return 0; } +IMPL_LINK_NOARG(SfxTemplateManagerDlg, OpenRegionHdl) +{ + maSelFolders.clear(); + maSelTemplates.clear(); + + if (!mbIsSaveMode) + mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT,mpCurView->isImportAllowed()); + + mpTemplateBar->Hide(); + mpViewBar->Show(); + mpActionBar->Show(); + + return 0; +} + IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem) { if (!mbIsSaveMode) @@ -702,59 +766,152 @@ IMPL_LINK(SfxTemplateManagerDlg, OpenTemplateHdl, ThumbnailViewItem*, pItem) IMPL_LINK_NOARG(SfxTemplateManagerDlg, SearchUpdateHdl) { - // if the search view is hidden, hide the folder view and display search one - if (!mpCurView->isOverlayVisible() && !mpSearchView->IsVisible()) - { - mpSearchView->Clear(); - mpSearchView->Show(); - mpCurView->Hide(); - } - OUString aKeyword = mpSearchEdit->GetText(); if (!aKeyword.isEmpty()) { - if (mpCurView->isOverlayVisible()) + mpSearchView->Clear(); + + // if the search view is hidden, hide the folder view and display search one + if (!mpSearchView->IsVisible()) { - mpCurView->filterTemplatesByKeyword(aKeyword); + mpCurView->deselectItems(); + mpSearchView->Show(); + mpCurView->Hide(); } - else + + bool bDisplayFolder = !mpCurView->isNonRootRegionVisible(); + + FILTER_APPLICATION eFilter = FILTER_APP_NONE; + switch (maTabControl.GetCurPageId()) { - mpSearchView->Clear(); + case FILTER_DOCS: + eFilter = FILTER_APP_WRITER; + break; + case FILTER_PRESENTATIONS: + eFilter = FILTER_APP_IMPRESS; + break; + case FILTER_SHEETS: + eFilter = FILTER_APP_CALC; + break; + case FILTER_DRAWS: + eFilter = FILTER_APP_DRAW; + break; + } - std::vector<TemplateItemProperties> aItems = - maView->getFilteredItems(SearchView_Keyword(aKeyword)); + std::vector<TemplateItemProperties> aItems = + maView->getFilteredItems(SearchView_Keyword(aKeyword,eFilter)); - size_t nCounter = 0; - for (size_t i = 0; i < aItems.size(); ++i) - { - TemplateItemProperties *pItem = &aItems[i]; - - mpSearchView->AppendItem(++nCounter,pItem->nRegionId, - pItem->nId-1, - pItem->aName, - maView->GetItemText(pItem->nRegionId+1), - pItem->aPath, - pItem->aThumbnail); - } + for (size_t i = 0; i < aItems.size(); ++i) + { + TemplateItemProperties *pItem = &aItems[i]; - mpSearchView->Invalidate(); + OUString aFolderName; + + if (bDisplayFolder) + aFolderName = maView->getRegionName(pItem->nRegionId); + + mpSearchView->AppendItem(pItem->nId,maView->getRegionId(pItem->nRegionId), + pItem->nDocId, + pItem->aName, + aFolderName, + pItem->aPath, + pItem->aThumbnail); } + + mpSearchView->Invalidate(); } else { - if (mpCurView->isOverlayVisible()) + mpSearchView->Hide(); + mpCurView->Show(); + } + + return 0; +} + +void SfxTemplateManagerDlg::OnRegionState (const ThumbnailViewItem *pItem) +{ + if (pItem->isSelected()) + { + if (maSelFolders.empty() && !mbIsSaveMode) { - mpCurView->filterTemplatesByApp(FILTER_APP_NONE); + mpViewBar->ShowItem(TBI_TEMPLATE_IMPORT); + mpViewBar->ShowItem(TBI_TEMPLATE_FOLDER_DEL); } - else + + maSelFolders.insert(pItem); + } + else + { + maSelFolders.erase(pItem); + + if (maSelFolders.empty() && !mbIsSaveMode) { - mpSearchView->Hide(); - mpCurView->Show(); + mpViewBar->HideItem(TBI_TEMPLATE_IMPORT); + mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL); } } +} - return 0; +void SfxTemplateManagerDlg::OnTemplateState (const ThumbnailViewItem *pItem) +{ + bool bInSelection = maSelTemplates.find(pItem) != maSelTemplates.end(); + + if (pItem->isSelected()) + { + if (maSelTemplates.empty()) + { + mpViewBar->Show(false); + mpTemplateBar->Show(); + } + else if (maSelTemplates.size() != 1 || !bInSelection) + { + if (!mbIsSaveMode) + { + mpTemplateBar->HideItem(TBI_TEMPLATE_EDIT); + mpTemplateBar->HideItem(TBI_TEMPLATE_PROPERTIES); + mpTemplateBar->HideItem(TBI_TEMPLATE_DEFAULT); + } + else + { + mpTemplateBar->HideItem(TBI_TEMPLATE_SAVE); + mpTemplateBar->HideItem(TBI_TEMPLATE_PROPERTIES); + mpTemplateBar->HideItem(TBI_TEMPLATE_DEFAULT); + } + } + + if (!bInSelection) + maSelTemplates.insert(pItem); + } + else + { + if (bInSelection) + { + maSelTemplates.erase(pItem); + + if (maSelTemplates.empty()) + { + mpTemplateBar->Show(false); + mpViewBar->Show(); + } + else if (maSelTemplates.size() == 1) + { + if (!mbIsSaveMode) + { + mpTemplateBar->ShowItem(TBI_TEMPLATE_EDIT); + mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES); + mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT); + } + else + { + mpTemplateBar->ShowItem(TBI_TEMPLATE_SAVE); + mpTemplateBar->ShowItem(TBI_TEMPLATE_PROPERTIES); + mpTemplateBar->ShowItem(TBI_TEMPLATE_DEFAULT); + } + } + } + } } void SfxTemplateManagerDlg::OnTemplateImport () @@ -821,15 +978,41 @@ void SfxTemplateManagerDlg::OnTemplateImport () if (aFiles.hasElements()) { - std::set<const ThumbnailViewItem*>::const_iterator pIter; - for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter) + if (!maSelFolders.empty()) { - OUString aTemplateList; - TemplateContainerItem *pFolder = (TemplateContainerItem*)(*pIter); + //Import to the selected regions + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; + for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter) + { + OUString aTemplateList; + TemplateContainerItem *pFolder = (TemplateContainerItem*)(*pIter); + for (size_t i = 0, n = aFiles.getLength(); i < n; ++i) + { + if(!maView->copyFrom(pFolder,aFiles[i])) + { + if (aTemplateList.isEmpty()) + aTemplateList = aFiles[i]; + else + aTemplateList = aTemplateList + "\n" + aFiles[i]; + } + } + + if (!aTemplateList.isEmpty()) + { + OUString aMsg(SfxResId(STR_MSG_ERROR_IMPORT).toString()); + aMsg = aMsg.replaceFirst("$1",pFolder->maTitle); + ErrorBox(this,WB_OK,aMsg.replaceFirst("$2",aTemplateList)); + } + } + } + else + { + //Import to current region + OUString aTemplateList; for (size_t i = 0, n = aFiles.getLength(); i < n; ++i) { - if(!maView->copyFrom(pFolder,aFiles[i])) + if(!maView->copyFrom(aFiles[i])) { if (aTemplateList.isEmpty()) aTemplateList = aFiles[i]; @@ -841,7 +1024,7 @@ void SfxTemplateManagerDlg::OnTemplateImport () if (!aTemplateList.isEmpty()) { OUString aMsg(SfxResId(STR_MSG_ERROR_IMPORT).toString()); - aMsg = aMsg.replaceFirst("$1",pFolder->maTitle); + aMsg = aMsg.replaceFirst("$1",maView->getCurRegionName()); ErrorBox(this,WB_OK,aMsg.replaceFirst("$2",aTemplateList)); } } @@ -870,7 +1053,7 @@ void SfxTemplateManagerDlg::OnTemplateExport() { sal_uInt16 i = 1; - std::set<const ThumbnailViewItem*>::const_iterator pIter = maSelTemplates.begin(); + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter = maSelTemplates.begin(); for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter, ++i) { const TemplateSearchViewItem *pItem = static_cast<const TemplateSearchViewItem*>(*pIter); @@ -884,7 +1067,7 @@ void SfxTemplateManagerDlg::OnTemplateExport() OUString aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE ); - if (!maView->exportTo(pItem->mnIdx+1,pItem->mnRegionId+1,aPath)) + if (!maView->exportTo(pItem->mnAssocId,pItem->mnRegionId,aPath)) { if (aTemplateList.isEmpty()) aTemplateList = pItem->maTitle; @@ -897,12 +1080,12 @@ void SfxTemplateManagerDlg::OnTemplateExport() } else { - // export templates from the current open overlay + // export templates from the current view sal_uInt16 i = 1; - sal_uInt16 nRegionItemId = maView->getOverlayRegionId() + 1; + sal_uInt16 nRegionItemId = maView->getCurRegionItemId(); - std::set<const ThumbnailViewItem*>::const_iterator pIter = maSelTemplates.begin(); + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter = maSelTemplates.begin(); for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter, ++i) { const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*pIter); @@ -925,7 +1108,7 @@ void SfxTemplateManagerDlg::OnTemplateExport() } } - maView->deselectOverlayItems(); + maView->deselectItems(); } if (!aTemplateList.isEmpty()) @@ -964,6 +1147,7 @@ void SfxTemplateManagerDlg::OnTemplateSearch () // Hide search view if (bVisible) { + mpSearchView->deselectItems(); mpSearchView->Hide(); mpCurView->Show(); } @@ -974,8 +1158,8 @@ void SfxTemplateManagerDlg::OnTemplateSearch () mpSearchEdit->GrabFocus(); // display all templates if we hide the search bar - if (bVisible && mpCurView->isOverlayVisible()) - mpCurView->filterTemplatesByApp(FILTER_APP_NONE); + if (bVisible && mpCurView->isNonRootRegionVisible()) + mpCurView->filterItems(ViewFilter_Application(FILTER_APP_NONE)); } void SfxTemplateManagerDlg::OnTemplateEdit () @@ -989,7 +1173,7 @@ void SfxTemplateManagerDlg::OnTemplateEdit () aArgs[2].Value <<= UpdateDocMode::ACCORDING_TO_CONFIG; uno::Reference< XStorable > xStorable; - std::set<const ThumbnailViewItem*>::const_iterator pIter; + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter) { const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*pIter); @@ -1023,63 +1207,41 @@ void SfxTemplateManagerDlg::OnTemplateDelete () if (mpSearchView->IsVisible()) { - std::set<const ThumbnailViewItem*>::const_iterator pIter; - for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();) + std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; //Avoids invalid iterators + + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; + for (pIter = aSelTemplates.begin(); pIter != aSelTemplates.end(); ++pIter) { const TemplateSearchViewItem *pItem = static_cast<const TemplateSearchViewItem*>(*pIter); - sal_uInt16 nItemId = pItem->mnIdx + 1; - sal_uInt16 nItemRegionId = pItem->mnRegionId + 1; - - if (maView->removeTemplate(nItemId,nItemRegionId)) - maSelTemplates.erase(pIter++); - else + if (!maView->removeTemplate(pItem->mnAssocId,pItem->mnRegionId)) { if (aTemplateList.isEmpty()) aTemplateList = pItem->maTitle; else aTemplateList = aTemplateList + "\n" + pItem->maTitle; - - ++pIter; } + else + mpSearchView->RemoveItem(pItem->mnId); } - - // Update search results - if (maSelTemplates.empty()) - { - mpTemplateBar->Show(false); - mpViewBar->Show(); - mpActionBar->Show(); - } - - SearchUpdateHdl(mpSearchEdit); } else { - std::set<const ThumbnailViewItem*>::const_iterator pIter; - for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end();) + sal_uInt16 nRegionItemId = maView->getCurRegionItemId(); + std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; //Avoid invalid iterators + + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; + for (pIter = aSelTemplates.begin(); pIter != aSelTemplates.end(); ++pIter) { - if (maView->removeTemplate((*pIter)->mnId,maView->getOverlayRegionId()+1)) - maSelTemplates.erase(pIter++); - else + if (!maView->removeTemplate((*pIter)->mnId,nRegionItemId)) { if (aTemplateList.isEmpty()) aTemplateList = (*pIter)->maTitle; else aTemplateList = aTemplateList + "\n" + (*pIter)->maTitle; - - ++pIter; } } - - if (maSelTemplates.empty()) - { - mpTemplateBar->SetItemDown(TBI_TEMPLATE_DELETE,false); - mpTemplateBar->Show(false); - mpViewBar->Show(); - mpActionBar->Show(); - } } if (!aTemplateList.isEmpty()) @@ -1114,12 +1276,12 @@ void SfxTemplateManagerDlg::OnFolderDelete() OUString aFolderList; - std::set<const ThumbnailViewItem*>::const_iterator pIter; - for (pIter = maSelFolders.begin(); pIter != maSelFolders.end();) + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; + std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelFolders = maSelFolders; //Copy to avoid invalidating an iterator + + for (pIter = aSelFolders.begin(); pIter != aSelFolders.end(); ++pIter) { - if (maView->removeRegion((*pIter)->mnId)) - maSelFolders.erase(pIter++); - else + if (!maView->removeRegion((*pIter)->mnId)) { if (aFolderList.isEmpty()) aFolderList = (*pIter)->maTitle; @@ -1130,12 +1292,6 @@ void SfxTemplateManagerDlg::OnFolderDelete() } } - if (maSelFolders.empty()) - { - mpViewBar->HideItem(TBI_TEMPLATE_IMPORT); - mpViewBar->HideItem(TBI_TEMPLATE_FOLDER_DEL); - } - if (!aFolderList.isEmpty()) { OUString aMsg( SfxResId(STR_MSG_ERROR_DELETE_FOLDER).toString() ); @@ -1145,9 +1301,9 @@ void SfxTemplateManagerDlg::OnFolderDelete() void SfxTemplateManagerDlg::OnRepositoryDelete() { - if(deleteRepository(mpOnlineView->getOverlayRegionId())) + if(deleteRepository(mpOnlineView->getCurRegionId())) { - // close overlay and switch to local view + // switch to local view switchMainView(true); createRepositoryMenu(); @@ -1158,7 +1314,7 @@ void SfxTemplateManagerDlg::OnTemplateSaveAs() { assert(m_xModel.is()); - if (!maView->isOverlayVisible() && maSelFolders.empty()) + if (!maView->isNonRootRegionVisible() && maSelFolders.empty()) { ErrorBox(this, WB_OK,SfxResId(STR_MSG_ERROR_SELECT_FOLDER).toString()).Execute(); return; @@ -1176,25 +1332,25 @@ void SfxTemplateManagerDlg::OnTemplateSaveAs() OUString aQMsg(SfxResId(STR_QMSG_TEMPLATE_OVERWRITE).toString()); QueryBox aQueryDlg(this,WB_YES_NO | WB_DEF_YES, OUString()); - if (maView->isOverlayVisible()) + if (maView->isNonRootRegionVisible()) { - sal_uInt16 nRegionItemId = maView->getOverlayRegionId()+1; + sal_uInt16 nRegionItemId = maView->getRegionId(maView->getCurRegionId()-1); if (!maView->isTemplateNameUnique(nRegionItemId,aName)) { aQMsg = aQMsg.replaceFirst("$1",aName); - aQueryDlg.SetMessText(aQMsg.replaceFirst("$2",maView->getOverlayName())); + aQueryDlg.SetMessText(aQMsg.replaceFirst("$2",maView->getCurRegionName())); if (aQueryDlg.Execute() == RET_NO) return; } if (!maView->saveTemplateAs(nRegionItemId,m_xModel,aName)) - aFolderList = maView->getOverlayName(); + aFolderList = maView->getCurRegionName(); } else { - std::set<const ThumbnailViewItem*>::const_iterator pIter; + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter) { TemplateContainerItem *pItem = (TemplateContainerItem*)(*pIter); @@ -1218,8 +1374,6 @@ void SfxTemplateManagerDlg::OnTemplateSaveAs() } } - maView->reload(); - if (!aFolderList.isEmpty()) { } @@ -1315,20 +1469,19 @@ void SfxTemplateManagerDlg::localMoveTo(sal_uInt16 nMenuId) } else { - nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE); + nItemId = maView->getRegionId(nMenuId-MNI_MOVE_FOLDER_BASE); } if (nItemId) { // Move templates to desired folder if for some reason move fails // try copying them. - if (!maView->moveTemplates(maSelTemplates,nItemId,false) && - !maView->moveTemplates(maSelTemplates,nItemId,true)) + if (!maView->moveTemplates(maSelTemplates,nItemId)) { OUString aTemplateList; - std::set<const ThumbnailViewItem*>::const_iterator pIter; - for (pIter = maSelFolders.begin(); pIter != maSelFolders.end(); ++pIter) + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator pIter; + for (pIter = maSelTemplates.begin(); pIter != maSelTemplates.end(); ++pIter) { if (aTemplateList.isEmpty()) aTemplateList = (*pIter)->maTitle; @@ -1336,7 +1489,7 @@ void SfxTemplateManagerDlg::localMoveTo(sal_uInt16 nMenuId) aTemplateList = aTemplateList + "\n" + (*pIter)->maTitle; } - OUString aDst = maView->GetItemText(nItemId); + OUString aDst = maView->getRegionItemName(nItemId); OUString aMsg(SfxResId(STR_MSG_ERROR_LOCAL_MOVE).toString()); aMsg = aMsg.replaceFirst("$1",aDst); ErrorBox(this, WB_OK,aMsg.replaceFirst( "$2",aTemplateList)).Execute(); @@ -1364,14 +1517,14 @@ void SfxTemplateManagerDlg::remoteMoveTo(const sal_uInt16 nMenuId) } else { - nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE); + nItemId = maView->getRegionId(nMenuId-MNI_MOVE_FOLDER_BASE); } if (nItemId) { OUString aTemplateList; - std::set<const ThumbnailViewItem*>::const_iterator aIter; + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator aIter; for (aIter = maSelTemplates.begin(); aIter != maSelTemplates.end(); ++aIter) { const TemplateSearchViewItem *pItem = @@ -1391,8 +1544,8 @@ void SfxTemplateManagerDlg::remoteMoveTo(const sal_uInt16 nMenuId) if (!aTemplateList.isEmpty()) { OUString aMsg(SfxResId(STR_MSG_ERROR_REMOTE_MOVE).toString()); - aMsg = aMsg.replaceFirst("$1",mpOnlineView->getOverlayName()); - aMsg = aMsg.replaceFirst("$2",maView->GetItemText(nItemId)); + aMsg = aMsg.replaceFirst("$1",mpOnlineView->getCurRegionName()); + aMsg = aMsg.replaceFirst("$2",maView->getRegionItemName(nItemId)); ErrorBox(this,WB_OK,aMsg.replaceFirst("$1",aTemplateList)).Execute(); } } @@ -1418,7 +1571,7 @@ void SfxTemplateManagerDlg::localSearchMoveTo(sal_uInt16 nMenuId) } else { - nItemId = maView->GetItemId(nMenuId-MNI_MOVE_FOLDER_BASE); + nItemId = maView->getRegionId(nMenuId-MNI_MOVE_FOLDER_BASE); } if (nItemId) @@ -1427,14 +1580,15 @@ void SfxTemplateManagerDlg::localSearchMoveTo(sal_uInt16 nMenuId) // Move templates to desired folder if for some reason move fails // try copying them. - std::set<const ThumbnailViewItem*>::const_iterator aIter; - for (aIter = maSelTemplates.begin(); aIter != maSelTemplates.end(); ++aIter) + std::set<const ThumbnailViewItem*,selection_cmp_fn>::const_iterator aIter; + std::set<const ThumbnailViewItem*,selection_cmp_fn> aSelTemplates = maSelTemplates; //Copy to avoid invalidating an iterator + + for (aIter = aSelTemplates.begin(); aIter != aSelTemplates.end(); ++aIter) { const TemplateSearchViewItem *pItem = static_cast<const TemplateSearchViewItem*>(*aIter); - if(!maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId,false) - && !maView->moveTemplate(pItem,pItem->mnRegionId+1,nItemId,true)) + if(!maView->moveTemplate(pItem,pItem->mnRegionId,nItemId)) { if (aTemplateList.isEmpty()) aTemplateList = (*aIter)->maTitle; @@ -1445,7 +1599,7 @@ void SfxTemplateManagerDlg::localSearchMoveTo(sal_uInt16 nMenuId) if (!aTemplateList.isEmpty()) { - OUString aDst = maView->GetItemText(nItemId); + OUString aDst = maView->getRegionItemName(nItemId); OUString aMsg(SfxResId(STR_MSG_ERROR_LOCAL_MOVE).toString()); aMsg = aMsg.replaceFirst("$1",aDst); ErrorBox(this, WB_OK,aMsg.replaceFirst( "$2",aTemplateList)).Execute(); @@ -1544,31 +1698,6 @@ void SfxTemplateManagerDlg::syncRepositories() const } } -BitmapEx SfxTemplateManagerDlg::getDefaultThumbnail( const OUString& rPath ) -{ - INetURLObject aUrl(rPath); - OUString aExt = aUrl.getExtension(); - - BitmapEx aImg; - if ( aExt == "ott" || aExt == "stw" || aExt == "oth" || aExt == "dot" || aExt == "dotx" ) - { - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) ); - } - else if ( aExt == "ots" || aExt == "stc" || aExt == "xlt" || aExt == "xltm" || aExt == "xltx" ) - { - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) ); - } - else if ( aExt == "otp" || aExt == "sti" || aExt == "pot" || aExt == "potm" || aExt == "potx" ) - { - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) ); - } - else if ( aExt == "otg" || aExt == "std" ) - { - aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) ); - } - return aImg; -} - static bool lcl_getServiceName ( const OUString &rFileURL, OUString &rName ) { bool bRet = false; diff --git a/sfx2/source/doc/templatedlg.src b/sfx2/source/doc/templatedlg.src index a3514316e76f..9beb3dac9e86 100644 --- a/sfx2/source/doc/templatedlg.src +++ b/sfx2/source/doc/templatedlg.src @@ -101,75 +101,18 @@ String STR_QMSG_TEMPLATE_OVERWRITE Text [ en-US ] = "A template named $1 already exist in $2. Do you want to overwrite it?"; }; -ModelessDialog DLG_TEMPLATE_MANAGER +TabPage TAB_TEMPLATE_MANAGER { - OutputSize = TRUE; - SVLook = TRUE; - Moveable = TRUE; - Closeable = TRUE; - Sizeable = TRUE; + Size = MAP_APPFONT( 290, 220 ); Hide = TRUE; - Size = MAP_APPFONT ( 290 , 250 ); - Text [en-US] = "Template Manager"; - - TabControl TAB_CONTROL - { - OutputSize = TRUE; - Size = MAP_APPFONT( 290, 22 ); - Pos = MAP_APPFONT( 0, 0 ); - PageList = - { - PageItem - { - Identifier = FILTER_DOCS; - Text [ en-US ] = "Documents"; - }; - PageItem - { - Identifier = FILTER_SHEETS; - Text [ en-US ] = "Spreadsheets"; - }; - PageItem - { - Identifier = FILTER_PRESENTATIONS; - Text [ en-US ] = "Presentations"; - }; - PageItem - { - Identifier = FILTER_DRAWS; - Text [ en-US ] = "Drawings"; - }; - }; - }; Control TEMPLATE_VIEW { - Size = MAP_APPFONT(280,220); + Pos = MAP_APPFONT( 0, 20 ); + Size = MAP_APPFONT( 290, 200 ); TabStop = TRUE; }; - Image IMG_ACTION_SORT - { - ImageBitmap = Bitmap - { - File = "sortascending.png"; - }; - }; - - Image IMG_ACTION_REFRESH - { - ImageBitmap = Bitmap - { - File = "reload.png"; - }; - }; - - Control TOOLBARS - { - Size = MAP_APPFONT( 290 , 16 ); - TabStop = False; - }; - ToolBox TBX_ACTION_VIEW { SVLook = TRUE ; @@ -269,6 +212,18 @@ ModelessDialog DLG_TEMPLATE_MANAGER { ToolBoxItem { + Identifier = TBI_TEMPLATE_SAVE; + Hide = TRUE; + Text [ en-US ] = "Save"; + + ItemImage = Image + { + ImageBitmap = Bitmap { File = "actionview028.png" ; }; + }; + }; + + ToolBoxItem + { Identifier = TBI_TEMPLATE_EDIT; Text [ en-US ] = "Edit"; @@ -334,4 +289,63 @@ ModelessDialog DLG_TEMPLATE_MANAGER }; }; }; + + Image IMG_ACTION_SORT + { + ImageBitmap = Bitmap + { + File = "sortascending.png"; + }; + }; + + Image IMG_ACTION_REFRESH + { + ImageBitmap = Bitmap + { + File = "reload.png"; + }; + }; +}; + +ModelessDialog DLG_TEMPLATE_MANAGER +{ + OutputSize = TRUE; + SVLook = TRUE; + Moveable = TRUE; + Closeable = TRUE; + Sizeable = TRUE; + Hide = TRUE; + Size = MAP_APPFONT ( 290 , 250 ); + Text [en-US] = "Template Manager"; + + TabControl TAB_CONTROL + { + OutputSize = TRUE; + Size = MAP_APPFONT( 290, 250 ); + Pos = MAP_APPFONT( 0, 0 ); + PageList = + { + PageItem + { + Identifier = FILTER_DOCS; + Text [ en-US ] = "Documents"; + }; + PageItem + { + Identifier = FILTER_SHEETS; + Text [ en-US ] = "Spreadsheets"; + }; + PageItem + { + Identifier = FILTER_PRESENTATIONS; + Text [ en-US ] = "Presentations"; + }; + PageItem + { + Identifier = FILTER_DRAWS; + Text [ en-US ] = "Drawings"; + }; + }; + }; + }; diff --git a/sfx2/source/inc/templatesearchview.hxx b/sfx2/source/inc/templatesearchview.hxx index de5514d620cb..b9ca781114ea 100644 --- a/sfx2/source/inc/templatesearchview.hxx +++ b/sfx2/source/inc/templatesearchview.hxx @@ -20,7 +20,7 @@ public: virtual ~TemplateSearchView(); - void AppendItem(sal_uInt16 nItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx, + void AppendItem(sal_uInt16 nAssocItemId, sal_uInt16 nRegionId, sal_uInt16 nIdx, const OUString &rTitle, const OUString &rSubtitle, const OUString &rPath, const BitmapEx &rImage ); }; diff --git a/sfx2/source/inc/templatesearchviewitem.hxx b/sfx2/source/inc/templatesearchviewitem.hxx index 27e393d24571..9d26ac7aeb72 100644 --- a/sfx2/source/inc/templatesearchviewitem.hxx +++ b/sfx2/source/inc/templatesearchviewitem.hxx @@ -21,8 +21,7 @@ struct TemplateSearchViewItem : public TemplateViewItem virtual ~TemplateSearchViewItem () {} - sal_uInt16 mnIdx; // Template associated Index - sal_uInt16 mnRegionId; // Template associated Region id + sal_uInt16 mnAssocId; //Associated item id to the TemplateViews }; #endif // __SFX2_TEMPLATESEARCHVIEWITEM_HXX__ diff --git a/sfx2/source/inc/templdgi.hxx b/sfx2/source/inc/templdgi.hxx index 2d92b719ae67..c78ad47be16e 100644 --- a/sfx2/source/inc/templdgi.hxx +++ b/sfx2/source/inc/templdgi.hxx @@ -165,6 +165,7 @@ protected: bUpdateByExampleDisabled:1, bTreeDrag :1, bHierarchical :1, + m_bWantHierarchical :1, bBindingUpdate :1; DECL_LINK( FilterSelectHdl, ListBox * ); @@ -225,6 +226,7 @@ protected: sal_Int32 LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh ); void SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter ); + SfxObjectShell * SaveSelection(); public: TYPEINFO(); |