diff options
author | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2013-02-11 15:30:16 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2013-02-11 15:39:48 +0100 |
commit | d4617cf434844f15c7be29ecc95edf0b4e384e67 (patch) | |
tree | e42462e6b373b65e3f7172d235d381f4d47d12c1 /sfx2 | |
parent | 7b384313399ee8199cd7241527c3dbc1d50694a2 (diff) |
Templates Manager: UI for renaming templates and folders, fdo#60579
After thinking this was a feature regression, I finally discovered that
the old template manager couldn't rename templates. This commit is
bringing back some previously unused code dropped in an ealier commit.
Even though this is a UI change, no new string is added by this commit.
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/doctempl.hxx | 15 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templatelocalview.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templateview.hxx | 3 | ||||
-rw-r--r-- | sfx2/inc/sfx2/templateviewitem.hxx | 4 | ||||
-rw-r--r-- | sfx2/inc/sfx2/thumbnailview.hxx | 2 | ||||
-rw-r--r-- | sfx2/inc/sfx2/thumbnailviewitem.hxx | 9 | ||||
-rw-r--r-- | sfx2/source/control/templatelocalview.cxx | 21 | ||||
-rw-r--r-- | sfx2/source/control/templateview.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/control/templateviewitem.cxx | 4 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailview.cxx | 9 | ||||
-rw-r--r-- | sfx2/source/control/thumbnailviewitem.cxx | 128 | ||||
-rw-r--r-- | sfx2/source/doc/doctempl.cxx | 55 |
12 files changed, 257 insertions, 5 deletions
diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx index 01d398f1aa7c..54e53c6983a8 100644 --- a/sfx2/inc/sfx2/doctempl.hxx +++ b/sfx2/inc/sfx2/doctempl.hxx @@ -92,6 +92,21 @@ public: sal_Bool Delete(sal_uInt16 nRegion, sal_uInt16 nIdx); sal_Bool InsertDir(const String &rText, sal_uInt16 nRegion); + /** Change the name of an entry or a directory + + \param rName + The new name to set + \param nRegion + The id of the region to rename or containing the template to rename + \param nIdx + The id of the template to rename or USHRT_MAX to rename the region. + + \return + sal_True if the action could be performed, sal_False otherwise + + */ + sal_Bool SetName(const rtl::OUString &rName, sal_uInt16 nRegion, sal_uInt16 nIdx); + sal_Bool CopyTo(sal_uInt16 nRegion, sal_uInt16 nIdx, const String &rName) const; sal_Bool CopyFrom(sal_uInt16 nRegion, sal_uInt16 nIdx, String &rName); diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx index 5c54375a4935..c27659f90b63 100644 --- a/sfx2/inc/sfx2/templatelocalview.hxx +++ b/sfx2/inc/sfx2/templatelocalview.hxx @@ -68,6 +68,8 @@ public: const OUString &rName); bool isTemplateNameUnique (const sal_uInt16 nRegionItemId, const OUString &rName) const; + + virtual void renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle); private: diff --git a/sfx2/inc/sfx2/templateview.hxx b/sfx2/inc/sfx2/templateview.hxx index 8ee529d707ec..81582efc904c 100644 --- a/sfx2/inc/sfx2/templateview.hxx +++ b/sfx2/inc/sfx2/templateview.hxx @@ -42,6 +42,8 @@ public: // FIXME Kept only during the refactoring void setOpenHdl (const Link &rLink) { maOpenHdl = rLink; } virtual void OnItemDblClicked(ThumbnailViewItem *pItem) { maOpenHdl.Call(pItem); } + void setMasterView(TemplateAbstractView* pMasterView) { mpMasterView = pMasterView; } + virtual void renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle); protected: @@ -50,6 +52,7 @@ protected: private: Link maOpenHdl; + TemplateAbstractView* mpMasterView; Control maButtons; PushButton maAllButton; diff --git a/sfx2/inc/sfx2/templateviewitem.hxx b/sfx2/inc/sfx2/templateviewitem.hxx index b19a06060421..0a3cb3e10b44 100644 --- a/sfx2/inc/sfx2/templateviewitem.hxx +++ b/sfx2/inc/sfx2/templateviewitem.hxx @@ -42,6 +42,10 @@ public: virtual void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor, const ThumbnailItemAttributes *pAttrs); + + sal_uInt16 mnRegionId; + sal_uInt16 mnDocId; + private: rtl::OUString maPath; diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx index bc5aae95763c..78e1df6bf6ef 100644 --- a/sfx2/inc/sfx2/thumbnailview.hxx +++ b/sfx2/inc/sfx2/thumbnailview.hxx @@ -236,6 +236,8 @@ public: virtual void Resize(); + virtual void renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle); + protected: virtual void MouseButtonDown( const MouseEvent& rMEvt ); diff --git a/sfx2/inc/sfx2/thumbnailviewitem.hxx b/sfx2/inc/sfx2/thumbnailviewitem.hxx index 18b7eae57f90..2acc8de9f9e3 100644 --- a/sfx2/inc/sfx2/thumbnailviewitem.hxx +++ b/sfx2/inc/sfx2/thumbnailviewitem.hxx @@ -25,6 +25,7 @@ #include <drawinglayer/primitive2d/baseprimitive2d.hxx> #include <osl/mutex.hxx> #include <vcl/bitmapex.hxx> +#include <vcl/vclmedit.hxx> #include "sfx2/dllapi.h" #include <com/sun/star/accessibility/XAccessible.hpp> @@ -88,12 +89,17 @@ public: void setHighlight (bool state); + void setEditTitle (bool edit, bool bChangeFocus = true); + void updateTitleEditSize (); + virtual void setTitle (const rtl::OUString& rTitle); + ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > GetAccessible( bool bIsTransientChildrenDisabled ); void setDrawArea (const Rectangle &area); const Rectangle& getDrawArea () const { return maDrawArea; } + Rectangle getTextArea () const; virtual void calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight, const long nPadding, sal_uInt32 nMaxTextLenght, @@ -118,6 +124,9 @@ protected: Point maPrev1Pos; Rectangle maDrawArea; Link maClickHdl; + bool mbEditTitle; + VclMultiLineEdit* mpTitleED; + Rectangle maTextEditMaxArea; }; #endif // THUMBNAILVIEWITEM_HXX diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 2cacc9b3b3d7..e42f9c8a243d 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -37,6 +37,7 @@ TemplateLocalView::TemplateLocalView ( Window* pParent, const ResId& rResId, boo mpDocTemplates(new SfxDocumentTemplates) { mpItemView->SetColor(GetSettings().GetStyleSettings().GetFieldColor()); + mpItemView->setMasterView(this); } TemplateLocalView::~TemplateLocalView() @@ -63,7 +64,7 @@ void TemplateLocalView::Populate () OUString aName = mpDocTemplates->GetName(i,j); OUString aURL = mpDocTemplates->GetPath(i,j); - TemplateItemProperties aProperties;; + TemplateItemProperties aProperties; aProperties.nId = j+1; aProperties.nDocId = j; aProperties.nRegionId = i; @@ -570,6 +571,24 @@ bool TemplateLocalView::isTemplateNameUnique(const sal_uInt16 nRegionItemId, con return true; } +void TemplateLocalView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle) +{ + sal_uInt16 nRegionId = 0; + sal_uInt16 nDocId = USHRT_MAX; + TemplateViewItem* pDocItem = dynamic_cast<TemplateViewItem*>( pItem ); + TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>( pItem ); + if ( pDocItem ) + { + nRegionId = pDocItem->mnRegionId; + nDocId = pDocItem->mnDocId; + } + else if ( pContainerItem ) + { + nRegionId = pContainerItem->mnId - 1; + } + mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId ); +} + static void lcl_updateThumbnails (TemplateContainerItem *pItem) { pItem->maPreview1.Clear(); diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx index 4a44ea0d6004..7073a6f90474 100644 --- a/sfx2/source/control/templateview.cxx +++ b/sfx2/source/control/templateview.cxx @@ -9,6 +9,7 @@ #include "templatedlg.hxx" #include <sfx2/templateview.hxx> +#include <sfx2/templateabstractview.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/point/b2dpoint.hxx> @@ -34,6 +35,7 @@ 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)), @@ -61,6 +63,8 @@ void TemplateView::InsertItems (const std::vector<TemplateItemProperties> &rTemp 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; @@ -96,6 +100,12 @@ void TemplateView::Resize() ThumbnailView::Resize(); } +void TemplateView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle) +{ + if (mpMasterView) + mpMasterView->renameItem(pItem, sNewTitle); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/templateviewitem.cxx b/sfx2/source/control/templateviewitem.cxx index 9f06ebbddcbf..94ce4d30ee2b 100644 --- a/sfx2/source/control/templateviewitem.cxx +++ b/sfx2/source/control/templateviewitem.cxx @@ -28,7 +28,9 @@ using namespace drawinglayer::attribute; using namespace drawinglayer::primitive2d; TemplateViewItem::TemplateViewItem (ThumbnailView &rView) - : ThumbnailViewItem(rView) + : ThumbnailViewItem(rView), + mnRegionId(USHRT_MAX), + mnDocId(USHRT_MAX) { } diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index d2196eb48535..a1c08980161a 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -505,6 +505,9 @@ void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt ) deselectItems( ); pItem->setSelection(true); + bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel()); + pItem->setEditTitle(bClickOnTitle); + if (!pItem->isHighlighted()) DrawItem(pItem); @@ -881,6 +884,7 @@ void ThumbnailView::deselectItems() { if (mItemList[i]->isSelected()) { + mItemList[i]->setEditTitle(false); mItemList[i]->setSelection(false); maItemStateHdl.Call(mItemList[i]); @@ -965,6 +969,11 @@ void ThumbnailView::sortItems (const boost::function<bool (const ThumbnailViewIt Invalidate(); } +void ThumbnailView::renameItem(ThumbnailViewItem*, rtl::OUString) +{ + // Do nothing by default +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx index 2e6eb96a7910..c228babd21c5 100644 --- a/sfx2/source/control/thumbnailviewitem.cxx +++ b/sfx2/source/control/thumbnailviewitem.cxx @@ -19,6 +19,7 @@ #include <sfx2/thumbnailviewitem.hxx> +#include "thumbnailview.hxx" #include "thumbnailviewacc.hxx" #include <basegfx/matrix/b2dhommatrixtools.hxx> @@ -42,6 +43,66 @@ using namespace ::com::sun::star; using namespace drawinglayer::attribute; using namespace drawinglayer::primitive2d; +class ResizableMultiLineEdit : public VclMultiLineEdit +{ + private: + ThumbnailViewItem* mpItem; + bool mbIsInGrabFocus; + + public: + ResizableMultiLineEdit (Window* pParent, ThumbnailViewItem* pItem); + ~ResizableMultiLineEdit (); + + void SetInGrabFocus(bool bInGrabFocus) { mbIsInGrabFocus = bInGrabFocus; } + + virtual long PreNotify(NotifyEvent& rNEvt); + virtual void Modify(); +}; + +ResizableMultiLineEdit::ResizableMultiLineEdit (Window* pParent, ThumbnailViewItem* pItem) : + VclMultiLineEdit (pParent, WB_CENTER | WB_BORDER), + mpItem(pItem), + mbIsInGrabFocus(false) +{ +} + +ResizableMultiLineEdit::~ResizableMultiLineEdit () +{ +} + +long ResizableMultiLineEdit::PreNotify(NotifyEvent& rNEvt) +{ + long nDone = 0; + if( rNEvt.GetType() == EVENT_KEYINPUT ) + { + const KeyEvent& rKEvt = *rNEvt.GetKeyEvent(); + KeyCode aCode = rKEvt.GetKeyCode(); + switch (aCode.GetCode()) + { + case KEY_RETURN: + mpItem->setTitle( GetText() ); + case KEY_ESCAPE: + mpItem->setEditTitle(false); + nDone = 1; + break; + default: + break; + } + } + else if ( rNEvt.GetType() == EVENT_LOSEFOCUS && !mbIsInGrabFocus ) + { + mpItem->setTitle( GetText() ); + mpItem->setEditTitle(false, false); + } + return nDone ? nDone : VclMultiLineEdit::PreNotify(rNEvt); +} + +void ResizableMultiLineEdit::Modify() +{ + VclMultiLineEdit::Modify(); + mpItem->updateTitleEditSize(); +} + ThumbnailViewItem::ThumbnailViewItem(ThumbnailView &rView) : mrParent(rView) , mnId(0) @@ -49,11 +110,16 @@ ThumbnailViewItem::ThumbnailViewItem(ThumbnailView &rView) , mbSelected(false) , mbHover(false) , mpxAcc(NULL) + , mbEditTitle(false) + , mpTitleED(NULL) + , maTextEditMaxArea() { + mpTitleED = new ResizableMultiLineEdit(&rView, this); } ThumbnailViewItem::~ThumbnailViewItem() { + delete mpTitleED; if( mpxAcc ) { static_cast< ThumbnailViewItemAcc* >( mpxAcc->get() )->ParentDestroyed(); @@ -64,6 +130,8 @@ ThumbnailViewItem::~ThumbnailViewItem() void ThumbnailViewItem::show (bool bVisible) { mbVisible = bVisible; + if (!mbVisible) + mpTitleED->Show(false); } void ThumbnailViewItem::setSelection (bool state) @@ -76,6 +144,53 @@ void ThumbnailViewItem::setHighlight (bool state) mbHover = state; } +void ThumbnailViewItem::setEditTitle (bool edit, bool bChangeFocus) +{ + mbEditTitle = edit; + mpTitleED->Show(edit); + if (edit) + { + mpTitleED->SetText(maTitle); + updateTitleEditSize(); + static_cast<ResizableMultiLineEdit*>(mpTitleED)->SetInGrabFocus(true); + mpTitleED->GrabFocus(); + static_cast<ResizableMultiLineEdit*>(mpTitleED)->SetInGrabFocus(false); + } + else if (bChangeFocus) + { + mrParent.GrabFocus(); + } +} + +Rectangle ThumbnailViewItem::getTextArea() const +{ + Rectangle aTextArea(maTextEditMaxArea); + + TextEngine aTextEngine; + aTextEngine.SetMaxTextWidth(maDrawArea.getWidth()); + aTextEngine.SetText(maTitle); + + long nTxtHeight = aTextEngine.GetTextHeight() + 6; + if (nTxtHeight < aTextArea.GetHeight()) + aTextArea.SetSize(Size(aTextArea.GetWidth(), nTxtHeight)); + + return aTextArea; +} + +void ThumbnailViewItem::updateTitleEditSize() +{ + Rectangle aTextArea = getTextArea(); + Point aPos = aTextArea.TopLeft(); + Size aSize = aTextArea.GetSize(); + mpTitleED->SetPosSizePixel(aPos, aSize); +} + +void ThumbnailViewItem::setTitle (const rtl::OUString& rTitle) +{ + mrParent.renameItem(this, rTitle); + maTitle = rTitle; +} + uno::Reference< accessibility::XAccessible > ThumbnailViewItem::GetAccessible( bool bIsTransientChildrenDisabled ) { if( !mpxAcc ) @@ -108,9 +223,15 @@ void ThumbnailViewItem::calculateItemsPosition (const long nThumbnailHeight, con maPrev1Pos = aPos; // Calculate text position - aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding + aTextDev.getTextHeight(); + aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding * 2; aPos.X() = maDrawArea.Left() + (aRectSize.Width() - aTextDev.getTextWidth(maTitle,0,nMaxTextLenght))/2; maTextPos = aPos; + + // Calculate the text edit max area + aPos = Point(maDrawArea.getX() + nPadding, maTextPos.getY()); + Size aEditSize(maDrawArea.GetWidth() - nPadding * 2, + maDrawArea.Bottom() - maTextPos.Y()); + maTextEditMaxArea = Rectangle( aPos, aEditSize ); } void ThumbnailViewItem::setSelectClickHdl (const Link &link) @@ -162,8 +283,7 @@ void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProc // Draw text below thumbnail aPos = maTextPos; - - addTextPrimitives( maTitle, pAttrs, maTextPos, aSeq ); + addTextPrimitives( maTitle, pAttrs, aPos, aSeq ); pProcessor->process(aSeq); } @@ -172,6 +292,8 @@ void ThumbnailViewItem::addTextPrimitives (const rtl::OUString& rText, const Thu { drawinglayer::primitive2d::TextLayouterDevice aTextDev; + aPos.setY(aPos.getY() + aTextDev.getTextHeight()); + rtl::OUString aText (rText); TextEngine aTextEngine; diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx index f1e7e976f02a..9c171ee30d1c 100644 --- a/sfx2/source/doc/doctempl.cxx +++ b/sfx2/source/doc/doctempl.cxx @@ -1039,6 +1039,61 @@ sal_Bool SfxDocumentTemplates::InsertDir return sal_False; } +sal_Bool SfxDocumentTemplates::SetName( const OUString& rName, sal_uInt16 nRegion, sal_uInt16 nIdx ) + +{ + DocTemplLocker_Impl aLocker( *pImp ); + + if ( ! pImp->Construct() ) + return sal_False; + + RegionData_Impl *pRegion = pImp->GetRegion( nRegion ); + DocTempl_EntryData_Impl *pEntry = NULL; + + if ( !pRegion ) + return sal_False; + + uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates(); + OUString aEmpty; + + if ( nIdx == USHRT_MAX ) + { + if ( pRegion->GetTitle() == rName ) + return sal_True; + + // we have to rename a region + if ( xTemplates->renameGroup( pRegion->GetTitle(), rName ) ) + { + pRegion->SetTitle( rName ); + pRegion->SetTargetURL( aEmpty ); + pRegion->SetHierarchyURL( aEmpty ); + return sal_True; + } + } + else + { + pEntry = pRegion->GetEntry( nIdx ); + + if ( !pEntry ) + return sal_False; + + if ( pEntry->GetTitle() == rName ) + return sal_True; + + if ( xTemplates->renameTemplate( pRegion->GetTitle(), + pEntry->GetTitle(), + rName ) ) + { + pEntry->SetTitle( rName ); + pEntry->SetTargetURL( aEmpty ); + pEntry->SetHierarchyURL( aEmpty ); + return sal_True; + } + } + + return sal_False; +} + //------------------------------------------------------------------------ sal_Bool SfxDocumentTemplates::GetFull |