diff options
author | Andre Fische <andre.f.fischer Andre Fischerandre.f.fischer@oracle.com> | 2011-03-08 17:22:13 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-11-28 12:48:32 +0000 |
commit | cbb599f657acc1953ef77d4f4fd895f75f9c7dad (patch) | |
tree | ff5455b4c3cb0876182f34ffc4ac71050b9b9717 /sd | |
parent | b3a2432e7df44c7f6387a41a246050d1bfba8984 (diff) |
impress211: #i88880# Fixed dragging of slides from navigator to slide sorter.
Conflicts:
sd/source/ui/app/sdxfer.cxx
sd/source/ui/dlg/sdtreelb.cxx
sd/source/ui/slidesorter/controller/SlsClipboard.cxx
sd/source/ui/slidesorter/controller/makefile.mk
sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx
Diffstat (limited to 'sd')
18 files changed, 481 insertions, 97 deletions
diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index 227a3c05203f..6390e1135f38 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -361,7 +361,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\ sd/source/ui/slidesorter/controller/SlsSelectionManager \ sd/source/ui/slidesorter/controller/SlsSelectionObserver \ sd/source/ui/slidesorter/controller/SlsSlotManager \ - sd/source/ui/slidesorter/controller/SlsTransferable \ + sd/source/ui/slidesorter/controller/SlsTransferableData \ sd/source/ui/slidesorter/controller/SlsVisibleAreaManager \ sd/source/ui/slidesorter/model/SlideSorterModel \ sd/source/ui/slidesorter/model/SlsPageDescriptor \ diff --git a/sd/source/ui/app/sdxfer.cxx b/sd/source/ui/app/sdxfer.cxx index b73058cb6e33..68072350d3eb 100644..100755 --- a/sd/source/ui/app/sdxfer.cxx +++ b/sd/source/ui/app/sdxfer.cxx @@ -117,6 +117,7 @@ SdTransferable::SdTransferable( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, , mbPageTransferable( sal_False ) , mbPageTransferablePersistent( sal_False ) , mbIsUnoObj( false ) +, maUserData() { if( mpSourceDoc ) StartListening( *mpSourceDoc ); @@ -770,6 +771,37 @@ sal_Int64 SAL_CALL SdTransferable::getSomething( const ::com::sun::star::uno::Se return nRet; } + +SdDrawDocument* SdTransferable::GetSourceDoc (void) const +{ + return mpSourceDoc; +} + +void SdTransferable::AddUserData (const ::boost::shared_ptr<UserData>& rpData) +{ + maUserData.push_back(rpData); +} + +void SdTransferable::RemoveUserData (const ::boost::shared_ptr<UserData>& rpData) +{ + maUserData.erase(::std::find(maUserData.begin(), maUserData.end(), rpData)); +} + +sal_Int32 SdTransferable::GetUserDataCount (void) const +{ + return maUserData.size(); +} + +::boost::shared_ptr<SdTransferable::UserData> SdTransferable::GetUserData (const sal_Int32 nIndex) const +{ + if (nIndex>=0 && nIndex<maUserData.size()) + return maUserData[nIndex]; + else + return ::boost::shared_ptr<UserData>(); +} + +// ----------------------------------------------------------------------------- + namespace { class theSdTransferableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdTransferableUnoTunnelId > {}; diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx index a672ed972763..4d80b7f4231e 100644 --- a/sd/source/ui/dlg/sdtreelb.cxx +++ b/sd/source/ui/dlg/sdtreelb.cxx @@ -51,13 +51,18 @@ #include "strings.hrc" #include "res_bmp.hrc" #include "customshowlist.hxx" +#include "ViewShell.hxx" +#include "DrawController.hxx" +#include "ViewShellBase.hxx" #include <com/sun/star/embed/XEmbedPersist.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XFramesSupplier.hpp> #include <svtools/embedtransfer.hxx> #include "svtools/treelistentry.hxx" -#include <tools/diagnose_ex.h> #include <comphelper/servicehelper.hxx> -#include <ViewShell.hxx> +#include <comphelper/processfactory.hxx> +#include <tools/diagnose_ex.h> using namespace com::sun::star; @@ -145,6 +150,7 @@ sal_Bool SdPageObjsTLB::SdPageObjsTransferable::GetData( const ::com::sun::star: void SdPageObjsTLB::SdPageObjsTransferable::DragFinished( sal_Int8 nDropAction ) { mrParent.OnDragFinished( nDropAction ); + SdTransferable::DragFinished(nDropAction); } // ----------------------------------------------------------------------------- @@ -216,6 +222,9 @@ sal_uInt32 SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId (void) return mnListBoxDropFormatId; } + + + /************************************************************************* |* |* Ctor1 SdPageObjsTLB @@ -976,6 +985,11 @@ void SdPageObjsTLB::DoDrag() if( eDragType == NAVIGATOR_DRAGTYPE_LINK ) nDNDActions = DND_ACTION_LINK; // Either COPY *or* LINK, never both! + else if (mpDoc->GetSdPageCount(PK_STANDARD) == 1) + { + // Can not move away the last slide in a document. + nDNDActions = DND_ACTION_COPY; + } SvTreeListBox::ReleaseMouse(); @@ -993,16 +1007,15 @@ void SdPageObjsTLB::DoDrag() // object is destroyed by internal reference mechanism SdTransferable* pTransferable = new SdPageObjsTLB::SdPageObjsTransferable( *this, aBookmark, *pDocShell, eDragType, aTreeListBoxData); - OSL_TRACE("created new SdPageObjsTransferable at %x", pTransferable); // Get the view. - sd::View* pView = NULL; - if (pDocShell != NULL) + ::sd::ViewShell* pViewShell = GetViewShellForDocShell(*pDocShell); + if (pViewShell == NULL) { - ::sd::ViewShell* pViewShell = pDocShell->GetViewShell(); - if (pViewShell != NULL) - pView = pViewShell->GetView(); + OSL_ASSERT(pViewShell!=NULL); + return; } + sd::View* pView = pViewShell->GetView(); if (pView == NULL) { OSL_ASSERT(pView!=NULL); @@ -1013,27 +1026,32 @@ void SdPageObjsTLB::DoDrag() void* pUserData = GetCurEntry()->GetUserData(); if (pUserData != NULL && pUserData != (void*)1) pObject = reinterpret_cast<SdrObject*>(pUserData); - if (pObject == NULL) - return; + if (pObject != NULL) + { + // For shapes without a user supplied name (the automatically + // created name does not count), a different drag and drop technique + // is used. + if (GetObjectName(pObject, false).Len() == 0) + { + AddShapeToTransferable(*pTransferable, *pObject); + pTransferable->SetView(pView); + SD_MOD()->pTransferDrag = pTransferable; + } - // For shapes without a user supplied name (the automatically - // created name does not count), a different drag and drop technique - // is used. - if (GetObjectName(pObject, false).Len() == 0) + // Unnamed shapes have to be selected to be recognized by the + // current drop implementation. In order to have a consistent + // behaviour for all shapes, every shape that is to be dragged is + // selected first. + SdrPageView* pPageView = pView->GetSdrPageView(); + pView->UnmarkAllObj(pPageView); + pView->MarkObj(pObject, pPageView); + } + else { - AddShapeToTransferable(*pTransferable, *pObject); pTransferable->SetView(pView); SD_MOD()->pTransferDrag = pTransferable; } - // Unnamed shapes have to be selected to be recognized by the - // current drop implementation. In order to have a consistent - // behaviour for all shapes, every shape that is to be dragged is - // selected first. - SdrPageView* pPageView = pView->GetSdrPageView(); - pView->UnmarkAllObj(pPageView); - pView->MarkObj(pObject, pPageView); - pTransferable->StartDrag( this, nDNDActions ); } } @@ -1263,8 +1281,6 @@ SvTreeListEntry* SdPageObjsTLB::GetDropTarget (const Point& rLocation) if (pEntry == NULL) return NULL; - OSL_TRACE("entry is %s", - ::rtl::OUStringToOString(GetEntryText(pEntry), RTL_TEXTENCODING_UTF8).getStr()); if (GetParent(pEntry) == NULL) { // Use page entry as insertion position. @@ -1287,8 +1303,6 @@ SvTreeListEntry* SdPageObjsTLB::GetDropTarget (const Point& rLocation) else break; } - OSL_TRACE("returning %s", - ::rtl::OUStringToOString(GetEntryText(pEntry), RTL_TEXTENCODING_UTF8).getStr()); } return pEntry; @@ -1367,6 +1381,66 @@ void SdPageObjsTLB::AddShapeToTransferable ( +::sd::ViewShell* SdPageObjsTLB::GetViewShellForDocShell (::sd::DrawDocShell& rDocShell) +{ + { + ::sd::ViewShell* pViewShell = rDocShell.GetViewShell(); + if (pViewShell != NULL) + return pViewShell; + } + + try + { + // Get a component enumeration from the desktop and search it for documents. + uno::Reference<lang::XMultiServiceFactory> xFactory ( + ::comphelper::getProcessServiceFactory ()); + if ( ! xFactory.is()) + return NULL; + + uno::Reference<frame::XDesktop> xDesktop (xFactory->createInstance ( + ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), uno::UNO_QUERY); + if ( ! xDesktop.is()) + return NULL; + + uno::Reference<frame::XFramesSupplier> xFrameSupplier (xDesktop, uno::UNO_QUERY); + if ( ! xFrameSupplier.is()) + return NULL; + + uno::Reference<container::XIndexAccess> xFrameAccess (xFrameSupplier->getFrames(), uno::UNO_QUERY); + if ( ! xFrameAccess.is()) + return NULL; + + for (sal_Int32 nIndex=0,nCount=xFrameAccess->getCount(); nIndex<nCount; ++nIndex) + { + uno::Reference<frame::XFrame> xFrame; + if ( ! (xFrameAccess->getByIndex(nIndex) >>= xFrame)) + continue; + + ::sd::DrawController* pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get()); + if (pController == NULL) + continue; + ::sd::ViewShellBase* pBase = pController->GetViewShellBase(); + if (pBase == NULL) + continue; + if (pBase->GetDocShell() != &rDocShell) + continue; + + const ::boost::shared_ptr<sd::ViewShell> pViewShell (pBase->GetMainViewShell()); + if (pViewShell) + return pViewShell.get(); + } + } + catch (uno::Exception e) + { + // When there is an exception then simply use the default value of + // bIsEnabled and disable the controls. + } + return NULL; +} + + + + //===== IconProvider ========================================================== SdPageObjsTLB::IconProvider::IconProvider (void) diff --git a/sd/source/ui/inc/sdtreelb.hxx b/sd/source/ui/inc/sdtreelb.hxx index 50ad60e4353d..a19cac2733a0 100644 --- a/sd/source/ui/inc/sdtreelb.hxx +++ b/sd/source/ui/inc/sdtreelb.hxx @@ -39,6 +39,8 @@ #include <svl/urlbmk.hxx> #include <tools/ref.hxx> #include "sdxfer.hxx" +#include <boost/scoped_ptr.hpp> +#include <boost/function.hpp> class SdDrawDocument; class SfxMedium; @@ -50,6 +52,8 @@ class SdPage; class SvTreeListEntry; namespace sd { +class ViewShell; + class DrawDocShell; #ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED #define SV_DECL_DRAW_DOC_SHELL_DEFINED @@ -103,7 +107,6 @@ public: ::sd::DrawDocShell& mrDocShell; NavigatorDragType meDragType; const ::com::sun::star::uno::Any maTreeListBoxData; - SD_DLLPRIVATE virtual ~SdPageObjsTransferable(); SD_DLLPRIVATE virtual void AddSupportedFormats(); @@ -226,6 +229,17 @@ public: using SvTreeListBox::ExecuteDrop; using SvTreeListBox::SelectEntry; + + /** Return the view shell that is linked to the given doc shell. + Call this method when the there is a chance that the doc shell + has been disconnected from the view shell (but not the other + way round.) + @return + May return <NULL/> when the link between view shell and + doc shell has been severed. + */ + static ::sd::ViewShell* GetViewShellForDocShell (::sd::DrawDocShell &rDocShell); + private: /** This flag controls whether all shapes are shown as children of pages and group shapes or only the named shapes. diff --git a/sd/source/ui/inc/sdxfer.hxx b/sd/source/ui/inc/sdxfer.hxx index 82f231f3375c..b68233a99e75 100644..100755 --- a/sd/source/ui/inc/sdxfer.hxx +++ b/sd/source/ui/inc/sdxfer.hxx @@ -90,12 +90,41 @@ public: // SfxListener virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + virtual void DragFinished( sal_Int8 nDropAction ); + SdDrawDocument* GetSourceDoc (void) const; + + /** User data objects can be used to store information temporarily + at the transferable. The slide sorter uses this to store + previews of the slides that are referenced by the + transferable. + */ + class UserData {public:virtual~UserData(){}}; + + /** Add a user data object. When it was added before (and not + removed) then this call is ignored. + */ + void AddUserData (const ::boost::shared_ptr<UserData>& rpData); + + /** Remove a previously added user data object. When the object + was never added or removed before then this call is ignored. + */ + void RemoveUserData (const ::boost::shared_ptr<UserData>& rpData); + + /** Return the number of user data objects. + */ + sal_Int32 GetUserDataCount (void) const; + + /** Return the specified user data object. When the index is not + valid, ie not in the range [0,count) then an empty pointer is + returned. + */ + ::boost::shared_ptr<UserData> GetUserData (const sal_Int32 nIndex) const; + protected: virtual void AddSupportedFormats(); virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor ); virtual sal_Bool WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, const ::com::sun::star::datatransfer::DataFlavor& rFlavor ); - virtual void DragFinished( sal_Int8 nDropAction ); virtual void ObjectReleased(); virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException ); @@ -125,6 +154,7 @@ private: sal_Bool mbPageTransferable : 1; sal_Bool mbPageTransferablePersistent : 1; bool mbIsUnoObj : 1; + ::std::vector<boost::shared_ptr<UserData> > maUserData; // not available SdTransferable(); diff --git a/sd/source/ui/slidesorter/controller/SlideSorterController.cxx b/sd/source/ui/slidesorter/controller/SlideSorterController.cxx index a28b3a838b1d..3fca80732987 100644 --- a/sd/source/ui/slidesorter/controller/SlideSorterController.cxx +++ b/sd/source/ui/slidesorter/controller/SlideSorterController.cxx @@ -42,7 +42,7 @@ #include "controller/SlsScrollBarManager.hxx" #include "controller/SlsSelectionManager.hxx" #include "controller/SlsSlotManager.hxx" -#include "controller/SlsTransferable.hxx" +#include "controller/SlsTransferableData.hxx" #include "controller/SlsVisibleAreaManager.hxx" #include "model/SlideSorterModel.hxx" #include "model/SlsPageEnumerationProvider.hxx" @@ -424,8 +424,7 @@ bool SlideSorterController::Command ( // indicator so that the user knows where a page insertion // would take place. mpInsertionIndicatorHandler->Start(false); - mpInsertionIndicatorHandler->UpdateIndicatorIcon( - dynamic_cast<Transferable*>(SD_MOD()->pTransferClip)); + mpInsertionIndicatorHandler->UpdateIndicatorIcon(SD_MOD()->pTransferClip); mpInsertionIndicatorHandler->UpdatePosition( pWindow->PixelToLogic(rEvent.GetMousePosPixel()), InsertionIndicatorHandler::MoveMode); diff --git a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx index a41d5d0e3f08..f852d1e8c0d3 100644 --- a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx +++ b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx @@ -44,12 +44,13 @@ #include "controller/SlsScrollBarManager.hxx" #include "controller/SlsFocusManager.hxx" #include "controller/SlsSelectionManager.hxx" -#include "controller/SlsTransferable.hxx" +#include "controller/SlsTransferableData.hxx" #include "controller/SlsSelectionObserver.hxx" #include "controller/SlsVisibleAreaManager.hxx" #include "cache/SlsPageCache.hxx" #include "ViewShellBase.hxx" +#include "View.hxx" #include "DrawViewShell.hxx" #include "Window.hxx" #include "fupoor.hxx" @@ -68,6 +69,7 @@ #include "drawdoc.hxx" #include "DrawDocShell.hxx" #include "sdpage.hxx" +#include "sdtreelb.hxx" #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> #include <sfx2/request.hxx> @@ -81,6 +83,8 @@ #include <rtl/ustring.hxx> #include <osl/mutex.hxx> #include <vcl/svapp.hxx> +#include <boost/bind.hpp> + namespace sd { namespace slidesorter { namespace controller { @@ -114,7 +118,6 @@ private: }; } // end of anonymous namespace - class Clipboard::UndoContext { public: @@ -439,7 +442,7 @@ void Clipboard::CreateSlideTransferable ( // previews are included into the transferable so that an insertion // indicator can be rendered. aSelectedPages.Rewind(); - ::std::vector<Transferable::Representative> aRepresentatives; + ::std::vector<TransferableData::Representative> aRepresentatives; aRepresentatives.reserve(3); ::boost::shared_ptr<cache::PageCache> pPreviewCache ( mrSlideSorter.GetView().GetPreviewCache()); @@ -449,7 +452,7 @@ void Clipboard::CreateSlideTransferable ( if ( ! pDescriptor || pDescriptor->GetPage()==NULL) continue; Bitmap aPreview (pPreviewCache->GetPreviewBitmap(pDescriptor->GetPage(), false)); - aRepresentatives.push_back(Transferable::Representative( + aRepresentatives.push_back(TransferableData::Representative( aPreview, pDescriptor->HasState(model::PageDescriptor::ST_Excluded))); if (aRepresentatives.size() >= 3) @@ -460,7 +463,7 @@ void Clipboard::CreateSlideTransferable ( { mrSlideSorter.GetView().BrkAction(); SdDrawDocument* pDocument = mrSlideSorter.GetModel().GetDocument(); - SdTransferable* pTransferable = new Transferable ( + SdTransferable* pTransferable = TransferableData::CreateTransferable ( pDocument, NULL, sal_False, @@ -519,6 +522,95 @@ void Clipboard::CreateSlideTransferable ( +::boost::shared_ptr<SdTransferable::UserData> Clipboard::CreateTransferableUserData (SdTransferable* pTransferable) +{ + do + { + SdPageObjsTLB::SdPageObjsTransferable* pTreeListBoxTransferable + = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable*>(pTransferable); + if (pTreeListBoxTransferable == NULL) + break; + + // Find view shell for the document of the transferable. + ::sd::ViewShell* pViewShell + = SdPageObjsTLB::GetViewShellForDocShell(pTreeListBoxTransferable->GetDocShell()); + if (pViewShell == NULL) + break; + + // Find slide sorter for the document of the transferable. + SlideSorterViewShell* pSlideSorterViewShell + = SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase()); + if (pSlideSorterViewShell == NULL) + break; + SlideSorter& rSlideSorter (pSlideSorterViewShell->GetSlideSorter()); + + // Get bookmark from transferable. + TransferableDataHelper aDataHelper (pTransferable); + INetBookmark aINetBookmark; + if ( ! aDataHelper.GetINetBookmark(SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK, aINetBookmark)) + break; + const rtl::OUString sURL (aINetBookmark.GetURL()); + const sal_Int32 nIndex (sURL.indexOf((sal_Unicode)'#')); + if (nIndex == -1) + break; + String sBookmark (sURL.copy(nIndex+1)); + + // Make sure that the bookmark points to a page. + SdDrawDocument* pTransferableDocument = rSlideSorter.GetModel().GetDocument(); + if (pTransferableDocument == NULL) + break; + BOOL bIsMasterPage; + const USHORT nPageIndex (pTransferableDocument->GetPageByName(sBookmark, bIsMasterPage)); + if (nPageIndex == SDRPAGE_NOTFOUND) + break; + + // Create preview. + ::std::vector<TransferableData::Representative> aRepresentatives; + aRepresentatives.reserve(1); + ::boost::shared_ptr<cache::PageCache> pPreviewCache ( + rSlideSorter.GetView().GetPreviewCache()); + model::SharedPageDescriptor pDescriptor (rSlideSorter.GetModel().GetPageDescriptor((nPageIndex-1)/2)); + if ( ! pDescriptor || pDescriptor->GetPage()==NULL) + break; + Bitmap aPreview (pPreviewCache->GetPreviewBitmap(pDescriptor->GetPage(), false)); + aRepresentatives.push_back(TransferableData::Representative( + aPreview, + pDescriptor->HasState(model::PageDescriptor::ST_Excluded))); + + // Remember the page in maPagesToRemove so that it can be removed + // when drag and drop action is "move". + Clipboard& rOtherClipboard (pSlideSorterViewShell->GetSlideSorter().GetController().GetClipboard()); + rOtherClipboard.maPagesToRemove.clear(); + rOtherClipboard.maPagesToRemove.push_back(pDescriptor->GetPage()); + + // Create the new transferable. + ::boost::shared_ptr<SdTransferable::UserData> pNewTransferable ( + new TransferableData( + pSlideSorterViewShell, + aRepresentatives)); + pTransferable->SetWorkDocument( dynamic_cast<SdDrawDocument*>( + pTreeListBoxTransferable->GetSourceDoc()->AllocModel())); + // pTransferable->SetView(&mrSlideSorter.GetView()); + + // Set page bookmark list. + std::vector<rtl::OUString> aPageBookmarks; + aPageBookmarks.push_back(sBookmark); + pTransferable->SetPageBookmarks(aPageBookmarks, false); + + // Replace the view referenced by the transferable with the + // corresponding slide sorter view. + pTransferable->SetView(&pSlideSorterViewShell->GetSlideSorter().GetView()); + + return pNewTransferable; + } + while (false); + + return ::boost::shared_ptr<SdTransferable::UserData>(); +} + + + + void Clipboard::StartDrag ( const Point& rPosition, ::Window* pWindow) @@ -539,8 +631,6 @@ void Clipboard::StartDrag ( void Clipboard::DragFinished (sal_Int8 nDropAction) { SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; - if (pDragTransferable != NULL) - pDragTransferable->SetView (NULL); if (mnDragFinishedUserEventId == 0) { @@ -602,11 +692,12 @@ sal_Int8 Clipboard::AcceptDrop ( { sal_Int8 nAction (DND_ACTION_NONE); - const Clipboard::DropType eDropType (IsDropAccepted()); + const Clipboard::DropType eDropType (IsDropAccepted(rTargetHelper)); switch (eDropType) { case DT_PAGE: + case DT_PAGE_FROM_NAVIGATOR: { // Accept a drop. nAction = rEvent.mnAction; @@ -614,7 +705,7 @@ sal_Int8 Clipboard::AcceptDrop ( // Use the copy action when the drop action is the default, i.e. not // explicitly set to move or link, and when the source and // target models are not the same. - const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; + SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; if (pDragTransferable != NULL && pDragTransferable->IsPageTransferable() && ((rEvent.maDragEvent.DropAction @@ -624,7 +715,7 @@ sal_Int8 Clipboard::AcceptDrop ( { nAction = DND_ACTION_COPY; } - else if (mrController.GetInsertionIndicatorHandler()->IsInsertionTrivial(nAction)) + else if (IsInsertionTrivial(pDragTransferable, nAction)) { nAction = DND_ACTION_NONE; } @@ -652,6 +743,7 @@ sal_Int8 Clipboard::AcceptDrop ( break; default: + case DT_NONE: nAction = DND_ACTION_NONE; break; } @@ -671,12 +763,14 @@ sal_Int8 Clipboard::ExecuteDrop ( { sal_Int8 nResult = DND_ACTION_NONE; mpUndoContext.reset(); + const Clipboard::DropType eDropType (IsDropAccepted(rTargetHelper)); - switch (IsDropAccepted()) + switch (eDropType) { case DT_PAGE: + case DT_PAGE_FROM_NAVIGATOR: { - const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; + SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; const Point aEventModelPosition ( pTargetWindow->PixelToLogic (rEvent.maPosPixel)); const sal_Int32 nXOffset (labs (pDragTransferable->GetStartPos().X() @@ -695,7 +789,7 @@ sal_Int8 Clipboard::ExecuteDrop ( // Do not process the insertion when it is trivial, // i.e. would insert pages at their original place. - if (pInsertionIndicatorHandler->IsInsertionTrivial(rEvent.mnAction)) + if (IsInsertionTrivial(pDragTransferable, rEvent.mnAction)) bContinue = false; // Tell the insertion indicator handler to hide before the model @@ -723,6 +817,19 @@ sal_Int8 Clipboard::ExecuteDrop ( // well as the ones above. } + // When the pages originated in another slide sorter then + // only that is notified automatically about the drag + // operation being finished. Because the target slide sorter + // has be notified, too, add a callback for that. + ::boost::shared_ptr<TransferableData> pSlideSorterTransferable ( + TransferableData::GetFromTransferable(pDragTransferable)); + BOOST_ASSERT(pSlideSorterTransferable); + if (pSlideSorterTransferable + && pSlideSorterTransferable->GetSourceViewShell() != mrSlideSorter.GetViewShell()) + { + DragFinished(nResult); + } + // Notify the receiving selection function that drag-and-drop is // finished and the substitution handler can be released. ::rtl::Reference<SelectionFunction> pFunction ( @@ -742,7 +849,9 @@ sal_Int8 Clipboard::ExecuteDrop ( nPage, nLayer); break; + default: + case DT_NONE: break; } @@ -752,6 +861,21 @@ sal_Int8 Clipboard::ExecuteDrop ( +bool Clipboard::IsInsertionTrivial ( + SdTransferable* pTransferable, + const sal_Int8 nDndAction) const +{ + ::boost::shared_ptr<TransferableData> pSlideSorterTransferable ( + TransferableData::GetFromTransferable(pTransferable)); + if (pSlideSorterTransferable + && pSlideSorterTransferable->GetSourceViewShell() != mrSlideSorter.GetViewShell()) + return false; + return mrController.GetInsertionIndicatorHandler()->IsInsertionTrivial(nDndAction); +} + + + + void Clipboard::Abort (void) { if (mpSelectionObserverContext) @@ -807,25 +931,26 @@ sal_uInt16 Clipboard::InsertSlides ( -Clipboard::DropType Clipboard::IsDropAccepted (void) const +Clipboard::DropType Clipboard::IsDropAccepted (DropTargetHelper& rTargetHelper) const { - DropType eResult (DT_NONE); - const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; - if (pDragTransferable != NULL) + if (pDragTransferable == NULL) + return DT_NONE; + + if (pDragTransferable->IsPageTransferable()) { - if (pDragTransferable->IsPageTransferable()) - { - if (mrSlideSorter.GetModel().GetEditMode() != EM_MASTERPAGE) - eResult = DT_PAGE; - } + if (mrSlideSorter.GetModel().GetEditMode() != EM_MASTERPAGE) + return DT_PAGE; else - { - eResult = DT_SHAPE; - } + return DT_NONE; } - return eResult; + const SdPageObjsTLB::SdPageObjsTransferable* pPageObjsTransferable + = dynamic_cast<const SdPageObjsTLB::SdPageObjsTransferable*>(pDragTransferable); + if (pPageObjsTransferable != NULL) + return DT_PAGE_FROM_NAVIGATOR; + + return DT_SHAPE; } diff --git a/sd/source/ui/slidesorter/controller/SlsDragAndDropContext.cxx b/sd/source/ui/slidesorter/controller/SlsDragAndDropContext.cxx index c1bf497ee080..56930335b87a 100644 --- a/sd/source/ui/slidesorter/controller/SlsDragAndDropContext.cxx +++ b/sd/source/ui/slidesorter/controller/SlsDragAndDropContext.cxx @@ -39,10 +39,12 @@ #include "controller/SlsProperties.hxx" #include "controller/SlsSelectionFunction.hxx" #include "controller/SlsSelectionManager.hxx" -#include "controller/SlsTransferable.hxx" +#include "controller/SlsClipboard.hxx" +#include "controller/SlsTransferableData.hxx" #include "DrawDocShell.hxx" #include "drawdoc.hxx" #include "app.hrc" +#include "sdtreelb.hxx" #include <sfx2/bindings.hxx> #include <boost/bind.hpp> @@ -58,8 +60,19 @@ DragAndDropContext::DragAndDropContext (SlideSorter& rSlideSorter) if (rSlideSorter.GetModel().GetEditMode() != EM_PAGE) return; - rSlideSorter.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon( - dynamic_cast<Transferable*>(SD_MOD()->pTransferDrag)); + // For poperly handling transferables created by the navigator we + // need additional information. For this a user data object is + // created that contains the necessary information. + SdTransferable* pTransferable = SD_MOD()->pTransferDrag; + SdPageObjsTLB::SdPageObjsTransferable* pTreeListBoxTransferable + = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable*>(pTransferable); + if (pTreeListBoxTransferable!=NULL && !TransferableData::GetFromTransferable(pTransferable)) + { + pTransferable->AddUserData( + rSlideSorter.GetController().GetClipboard().CreateTransferableUserData(pTransferable)); + } + + rSlideSorter.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable); } diff --git a/sd/source/ui/slidesorter/controller/SlsInsertionIndicatorHandler.cxx b/sd/source/ui/slidesorter/controller/SlsInsertionIndicatorHandler.cxx index 165ff8ff49b0..6b079f70370b 100644 --- a/sd/source/ui/slidesorter/controller/SlsInsertionIndicatorHandler.cxx +++ b/sd/source/ui/slidesorter/controller/SlsInsertionIndicatorHandler.cxx @@ -120,7 +120,7 @@ void InsertionIndicatorHandler::ForceEnd (void) -void InsertionIndicatorHandler::UpdateIndicatorIcon (const Transferable* pTransferable) +void InsertionIndicatorHandler::UpdateIndicatorIcon (const SdTransferable* pTransferable) { mpInsertionIndicatorOverlay->Create(pTransferable); maIconSize = mpInsertionIndicatorOverlay->GetSize(); diff --git a/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx b/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx index 516ba9811b15..c6f7a3faf216 100644 --- a/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx +++ b/sd/source/ui/slidesorter/controller/SlsSelectionFunction.cxx @@ -32,7 +32,7 @@ #include "SlideSorter.hxx" #include "SlideSorterViewShell.hxx" #include "SlsDragAndDropContext.hxx" -#include "controller/SlsTransferable.hxx" +#include "controller/SlsTransferableData.hxx" #include "controller/SlideSorterController.hxx" #include "controller/SlsPageSelector.hxx" #include "controller/SlsFocusManager.hxx" diff --git a/sd/source/ui/slidesorter/controller/SlsTransferable.cxx b/sd/source/ui/slidesorter/controller/SlsTransferableData.cxx index faf4a088c8a7..f12e9491f3aa 100644 --- a/sd/source/ui/slidesorter/controller/SlsTransferable.cxx +++ b/sd/source/ui/slidesorter/controller/SlsTransferableData.cxx @@ -27,21 +27,48 @@ ************************************************************************/ -#include "controller/SlsTransferable.hxx" +#include "controller/SlsTransferableData.hxx" #include "SlideSorterViewShell.hxx" #include "View.hxx" namespace sd { namespace slidesorter { namespace controller { -Transferable::Transferable ( +SdTransferable* TransferableData::CreateTransferable ( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, sal_Bool bInitOnGetData, SlideSorterViewShell* pViewShell, const ::std::vector<Representative>& rRepresentatives) - : SdTransferable (pSrcDoc, pWorkView, bInitOnGetData), - mpViewShell(pViewShell), +{ + SdTransferable* pTransferable = new SdTransferable (pSrcDoc, pWorkView, bInitOnGetData); + ::boost::shared_ptr<TransferableData> pData (new TransferableData(pViewShell, rRepresentatives)); + pTransferable->AddUserData(pData); + return pTransferable; +} + + + + +::boost::shared_ptr<TransferableData> TransferableData::GetFromTransferable (const SdTransferable* pTransferable) +{ + ::boost::shared_ptr<TransferableData> pData; + for (sal_Int32 nIndex=0,nCount=pTransferable->GetUserDataCount(); nIndex<nCount; ++nIndex) + { + pData = ::boost::dynamic_pointer_cast<TransferableData>(pTransferable->GetUserData(nIndex)); + if (pData) + return pData; + } + return ::boost::shared_ptr<TransferableData>(); +} + + + + +TransferableData::TransferableData ( + SlideSorterViewShell* pViewShell, + const ::std::vector<Representative>& rRepresentatives) + : mpViewShell(pViewShell), maRepresentatives(rRepresentatives) { if (mpViewShell != NULL) @@ -51,7 +78,7 @@ Transferable::Transferable ( -Transferable::~Transferable (void) +TransferableData::~TransferableData (void) { if (mpViewShell != NULL) EndListening(*mpViewShell); @@ -60,16 +87,28 @@ Transferable::~Transferable (void) -void Transferable::DragFinished (sal_Int8 nDropAction) +void TransferableData::DragFinished (sal_Int8 nDropAction) { if (mpViewShell != NULL) mpViewShell->DragFinished(nDropAction); + /* + for (CallbackContainer::const_iterator + iCallback(maDragFinishCallbacks.begin()), + iEnd(maDragFinishCallbacks.end()); + iCallback!=iEnd; + ++iCallback) + { + if (*iCallback) + (*iCallback)(nDropAction); + } + maDragFinishCallbacks.clear(); + */ } -void Transferable::Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint) +void TransferableData::Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint) { if (rHint.ISA(SfxSimpleHint) && mpViewShell!=NULL) { @@ -84,19 +123,24 @@ void Transferable::Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint) mpViewShell = NULL; } } - - SdTransferable::Notify(rBroadcaster, rHint); } -const ::std::vector<Transferable::Representative>& Transferable::GetRepresentatives (void) const +const ::std::vector<TransferableData::Representative>& TransferableData::GetRepresentatives (void) const { return maRepresentatives; } + + +SlideSorterViewShell* TransferableData::GetSourceViewShell (void) const +{ + return mpViewShell; +} + } } } // end of namespace ::sd::slidesorter::controller /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx b/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx index 26ab20370791..e620c656f94f 100644 --- a/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx +++ b/sd/source/ui/slidesorter/inc/controller/SlsClipboard.hxx @@ -31,6 +31,8 @@ #include "ViewClipboard.hxx" #include "controller/SlsSelectionObserver.hxx" +#include "sdxfer.hxx" + #include <sal/types.h> #include <tools/solar.h> #include <svx/svdpage.hxx> @@ -55,6 +57,12 @@ namespace sd { namespace slidesorter { class SlideSorter; } } +namespace sd { namespace slidesorter { namespace model { +class PageDescriptor; +} } } + +namespace { class NavigatorDropEvent; } + namespace sd { namespace slidesorter { namespace controller { class SlideSorterController; @@ -66,6 +74,12 @@ public: Clipboard (SlideSorter& rSlideSorter); ~Clipboard (void); + /** Create a slide sorter transferable from the given sd + transferable. The returned transferable is set up with all + information necessary so that it can be dropped on a slide sorter. + */ + ::boost::shared_ptr<SdTransferable::UserData> CreateTransferableUserData (SdTransferable* pTransferable); + void HandleSlotCall (SfxRequest& rRequest); void DoCut (::Window* pWindow = 0); @@ -181,8 +195,8 @@ private: transferable is not accepted. The reason is the missing implementation of proper handling master pages copy-and-paste. */ - enum DropType { DT_PAGE, DT_SHAPE, DT_NONE }; - DropType IsDropAccepted (void) const; + enum DropType { DT_PAGE, DT_PAGE_FROM_NAVIGATOR, DT_SHAPE, DT_NONE }; + DropType IsDropAccepted (DropTargetHelper& rTargetHelper) const; /** This method contains the code for AcceptDrop() and ExecuteDrop() shapes. There are only minor differences for the two cases at this level. @@ -213,10 +227,19 @@ private: sal_uInt16 nPage, sal_uInt16 nLayer); + /** Return whether the insertion defined by the transferable is + trivial, ie would not change either source nor target document. + */ + bool IsInsertionTrivial ( + SdTransferable* pTransferable, + const sal_Int8 nDndAction) const; + /** Asynchronous part of DragFinished. The argument is the sal_Int8 nDropAction, disguised as void*. */ DECL_LINK(ProcessDragFinished, void*); + + DECL_LINK(ExecuteNavigatorDrop, NavigatorDropEvent*); }; } } } // end of namespace ::sd::slidesorter::controller diff --git a/sd/source/ui/slidesorter/inc/controller/SlsInsertionIndicatorHandler.hxx b/sd/source/ui/slidesorter/inc/controller/SlsInsertionIndicatorHandler.hxx index 834b1da02e63..0b2a84a0dd20 100644 --- a/sd/source/ui/slidesorter/inc/controller/SlsInsertionIndicatorHandler.hxx +++ b/sd/source/ui/slidesorter/inc/controller/SlsInsertionIndicatorHandler.hxx @@ -32,6 +32,8 @@ #include "view/SlsInsertAnimator.hxx" #include "view/SlsLayouter.hxx" +#include "sdxfer.hxx" + namespace sd { namespace slidesorter { class SlideSorter; } } namespace sd { namespace slidesorter { namespace view { @@ -81,7 +83,7 @@ public: /** Update the indicator icon from the current transferable (from the clipboard or an active drag and drop operation.) */ - void UpdateIndicatorIcon (const Transferable* pTransferable); + void UpdateIndicatorIcon (const SdTransferable* pTransferable); /** Set the position of the insertion marker to the given coordinates. */ diff --git a/sd/source/ui/slidesorter/inc/controller/SlsTransferable.hxx b/sd/source/ui/slidesorter/inc/controller/SlsTransferableData.hxx index a0b81a246408..dcc79f3f2b0e 100644 --- a/sd/source/ui/slidesorter/inc/controller/SlsTransferable.hxx +++ b/sd/source/ui/slidesorter/inc/controller/SlsTransferableData.hxx @@ -26,10 +26,12 @@ * ************************************************************************/ -#ifndef SD_SLIDESORTER_TRANSFERABLE_HXX -#define SD_SLIDESORTER_TRANSFERABLE_HXX +#ifndef SD_SLIDESORTER_TRANSFERABLE_DATA_HXX +#define SD_SLIDESORTER_TRANSFERABLE_DATA_HXX #include "sdxfer.hxx" +#include <boost/function.hpp> +#include <vector> class SdDrawDocument; namespace sd { namespace slidesorter { @@ -38,12 +40,12 @@ class SlideSorterViewShell; namespace sd { namespace slidesorter { namespace controller { - -/** This class exists to have DragFinished call the correct object: the - SlideSorterViewShell instead of the old SlideView. +/** Represent previews and other information so that they can be + attached to an existing transferable. */ -class Transferable - : public SdTransferable +class TransferableData + : public SdTransferable::UserData, + public SfxListener { public: class Representative @@ -62,23 +64,32 @@ public: bool mbIsExcluded; }; - - Transferable ( + static SdTransferable* CreateTransferable ( SdDrawDocument* pSrcDoc, ::sd::View* pWorkView, sal_Bool bInitOnGetData, SlideSorterViewShell* pViewShell, - const ::std::vector<Representative>& rRepresentatives); + const ::std::vector<TransferableData::Representative>& rRepresentatives); - virtual ~Transferable (void); + static ::boost::shared_ptr<TransferableData> GetFromTransferable (const SdTransferable* pTransferable); + + TransferableData ( + SlideSorterViewShell* pViewShell, + const ::std::vector<TransferableData::Representative>& rRepresentatives); + ~TransferableData (void); virtual void DragFinished (sal_Int8 nDropAction); const ::std::vector<Representative>& GetRepresentatives (void) const; + /** Return the view shell for which the transferable was created. + */ + SlideSorterViewShell* GetSourceViewShell (void) const; + private: SlideSorterViewShell* mpViewShell; const ::std::vector<Representative> maRepresentatives; + typedef ::std::vector<boost::function<void(sal_uInt8)> > CallbackContainer; virtual void Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint); }; diff --git a/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx b/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx index f8cf71e25793..77e0c50cb345 100644 --- a/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx +++ b/sd/source/ui/slidesorter/inc/view/SlideSorterView.hxx @@ -242,6 +242,8 @@ public: ToolTip& GetToolTip (void) const; + virtual void DragFinished (sal_Int8 nDropAction); + protected: virtual void Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint); diff --git a/sd/source/ui/slidesorter/inc/view/SlsInsertionIndicatorOverlay.hxx b/sd/source/ui/slidesorter/inc/view/SlsInsertionIndicatorOverlay.hxx index 58e6fff0bd75..c9c945dac231 100644 --- a/sd/source/ui/slidesorter/inc/view/SlsInsertionIndicatorOverlay.hxx +++ b/sd/source/ui/slidesorter/inc/view/SlsInsertionIndicatorOverlay.hxx @@ -31,7 +31,8 @@ #include "model/SlsSharedPageDescriptor.hxx" #include "view/SlsILayerPainter.hxx" -#include "controller/SlsTransferable.hxx" +#include "controller/SlsTransferableData.hxx" +#include "sdxfer.hxx" #include <tools/gen.hxx> #include <vcl/bitmapex.hxx> @@ -66,7 +67,7 @@ public: virtual void SetLayerInvalidator (const SharedILayerInvalidator& rpInvalidator); - void Create (const controller::Transferable* pTransferable); + void Create (const SdTransferable* pTransferable); /** Given a position in model coordinates this method calculates the insertion marker both as an index in the document and as a location @@ -102,7 +103,7 @@ private: OutputDevice& rContent, const Size aPreviewSize, const sal_Int32 nOffset, - const ::std::vector<controller::Transferable::Representative>& rPages) const; + const ::std::vector<controller::TransferableData::Representative>& rPages) const; void PaintPageCount ( OutputDevice& rDevice, const sal_Int32 nSelectionCount, @@ -112,7 +113,7 @@ private: scaled down previews of some of the selected pages. */ void Create ( - const ::std::vector<controller::Transferable::Representative>& rPages, + const ::std::vector<controller::TransferableData::Representative>& rPages, const sal_Int32 nSelectionCount); }; diff --git a/sd/source/ui/slidesorter/view/SlideSorterView.cxx b/sd/source/ui/slidesorter/view/SlideSorterView.cxx index 66c3cdf0d315..d874fe9ce25e 100644 --- a/sd/source/ui/slidesorter/view/SlideSorterView.cxx +++ b/sd/source/ui/slidesorter/view/SlideSorterView.cxx @@ -42,6 +42,7 @@ #include "view/SlsToolTip.hxx" #include "controller/SlideSorterController.hxx" #include "controller/SlsProperties.hxx" +#include "controller/SlsClipboard.hxx" #include "model/SlideSorterModel.hxx" #include "model/SlsPageEnumerationProvider.hxx" #include "model/SlsPageDescriptor.hxx" @@ -173,7 +174,6 @@ SlideSorterView::SlideSorterView (SlideSorter& rSlideSorter) // Hide the page that contains the page objects. SetPageVisible (sal_False); - // Register the background painter on level 1 to avoid the creation of a // background buffer. mpLayeredDevice->RegisterPainter(mpBackgroundPainter, 1); @@ -874,6 +874,16 @@ ToolTip& SlideSorterView::GetToolTip (void) const +void SlideSorterView::DragFinished (sal_Int8 nDropAction) +{ + mrSlideSorter.GetController().GetClipboard().DragFinished(nDropAction); + + View::DragFinished(nDropAction); +} + + + + void SlideSorterView::Notify (SfxBroadcaster& rBroadcaster, const SfxHint& rHint) { ::sd::DrawDocShell* pDocShell = mrModel.GetDocument()->GetDocSh(); diff --git a/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx b/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx index dec938a25d8b..1166ffda8848 100644 --- a/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx +++ b/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx @@ -103,11 +103,15 @@ InsertionIndicatorOverlay::~InsertionIndicatorOverlay (void) -void InsertionIndicatorOverlay::Create (const controller::Transferable* pTransferable) +void InsertionIndicatorOverlay::Create (const SdTransferable* pTransferable) { if (pTransferable == NULL) return; + ::boost::shared_ptr<controller::TransferableData> pData ( + controller::TransferableData::GetFromTransferable(pTransferable)); + if ( ! pData) + return; sal_Int32 nSelectionCount (0); if (pTransferable->HasPageBookmarks()) nSelectionCount = pTransferable->GetPageBookmarks().size(); @@ -121,14 +125,14 @@ void InsertionIndicatorOverlay::Create (const controller::Transferable* pTransfe nSelectionCount = pDataDocument->GetSdPageCount(PK_STANDARD); } } - Create(pTransferable->GetRepresentatives(), nSelectionCount); + Create(pData->GetRepresentatives(), nSelectionCount); } void InsertionIndicatorOverlay::Create ( - const ::std::vector<controller::Transferable::Representative>& rRepresentatives, + const ::std::vector<controller::TransferableData::Representative>& rRepresentatives, const sal_Int32 nSelectionCount) { view::Layouter& rLayouter (mrSlideSorter.GetView().GetLayouter()); @@ -180,7 +184,7 @@ Point InsertionIndicatorOverlay::PaintRepresentatives ( OutputDevice& rContent, const Size aPreviewSize, const sal_Int32 nOffset, - const ::std::vector<controller::Transferable::Representative>& rRepresentatives) const + const ::std::vector<controller::TransferableData::Representative>& rRepresentatives) const { const Point aOffset (0,rRepresentatives.size()==1 ? -nOffset : 0); |