diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2005-09-23 10:28:29 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2005-09-23 10:28:29 +0000 |
commit | 3437816e0a0ad17534255cafe6b9e733dc0f367f (patch) | |
tree | ca605399f4e198b4367ca32bed8949e14dd58e08 /sd/source/ui/slidesorter/controller/SlsClipboard.cxx | |
parent | e2a74d042adf689321cffe3b27fb6510162f4be0 (diff) |
INTEGRATION: CWS impress57 (1.12.42); FILE MERGED
2005/05/30 15:52:50 af 1.12.42.2: #i40631# Added support for drag-and-drop of shapes into the slide sorter.
2005/05/27 09:44:33 af 1.12.42.1: #i49761# Disbled copy-and-paste and drag-and-drop of master pages.
Diffstat (limited to 'sd/source/ui/slidesorter/controller/SlsClipboard.cxx')
-rw-r--r-- | sd/source/ui/slidesorter/controller/SlsClipboard.cxx | 250 |
1 files changed, 174 insertions, 76 deletions
diff --git a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx index f34de34b50ac..36129a3e2e44 100644 --- a/sd/source/ui/slidesorter/controller/SlsClipboard.cxx +++ b/sd/source/ui/slidesorter/controller/SlsClipboard.cxx @@ -4,9 +4,9 @@ * * $RCSfile: SlsClipboard.cxx,v $ * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * - * last change: $Author: rt $ $Date: 2005-09-09 06:13:27 $ + * last change: $Author: hr $ $Date: 2005-09-23 11:28:29 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -49,6 +49,8 @@ #include "controller/SlsScrollBarManager.hxx" #include "controller/SlsFocusManager.hxx" +#include "ViewShellBase.hxx" +#include "DrawViewShell.hxx" #include "Window.hxx" #include "fupoor.hxx" #include "fuslhide.hxx" @@ -58,6 +60,7 @@ #include "fuexpand.hxx" #include "fusumry.hxx" #include "app.hrc" +#include "glob.hrc" #include "strings.hrc" #include "sdresid.hxx" #include "sdxfer.hxx" @@ -75,6 +78,7 @@ #include <svx/svxids.hrc> #include <vcl/msgbox.hxx> #include <tools/urlobj.hxx> +#include <rtl/ustring.hxx> namespace sd { namespace slidesorter { namespace controller { @@ -478,21 +482,36 @@ sal_Int8 Clipboard::AcceptDrop ( { sal_Int8 nResult = DND_ACTION_NONE; - if (IsDropAccepted()) + switch (IsDropAccepted()) { - const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; - // Accept a drop. - nResult = rEvent.mnAction; - - // Show the insertion marker and the substitution for a drop. - Point aPosition = pTargetWindow->PixelToLogic (rEvent.maPosPixel); - view::ViewOverlay& rOverlay (mrController.GetView().GetOverlay()); - rOverlay.GetInsertionIndicatorOverlay().SetPosition (aPosition); - rOverlay.GetInsertionIndicatorOverlay().Show(); - rOverlay.GetSubstitutionOverlay().SetPosition (aPosition); - - // Scroll the window when the mouse reaches the window border. - mrController.GetScrollBarManager().AutoScroll (rEvent.maPosPixel); + case DT_PAGE: + { + const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; + // Accept a drop. + nResult = rEvent.mnAction; + + // Show the insertion marker and the substitution for a drop. + Point aPosition = pTargetWindow->PixelToLogic (rEvent.maPosPixel); + view::ViewOverlay& rOverlay (mrController.GetView().GetOverlay()); + rOverlay.GetInsertionIndicatorOverlay().SetPosition (aPosition); + rOverlay.GetInsertionIndicatorOverlay().Show(); + rOverlay.GetSubstitutionOverlay().SetPosition (aPosition); + + // Scroll the window when the mouse reaches the window border. + mrController.GetScrollBarManager().AutoScroll (rEvent.maPosPixel); + } + break; + + case DT_SHAPE: + nResult = ExecuteOrAcceptShapeDrop( + DC_ACCEPT, + rEvent.maPosPixel, + &rEvent, + rTargetHelper, + pTargetWindow, + nPage, + nLayer); + break; } return nResult; @@ -510,59 +529,74 @@ sal_Int8 Clipboard::ExecuteDrop ( { sal_Int8 nResult = DND_ACTION_NONE; - if (IsDropAccepted()) + switch (IsDropAccepted()) { - const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; - const Point aEventModelPosition ( - pTargetWindow->PixelToLogic (rEvent.maPosPixel)); - long int nXOffset = labs (pDragTransferable->GetStartPos().X() - - aEventModelPosition.X()); - long int nYOffset = labs (pDragTransferable->GetStartPos().Y() - - aEventModelPosition.Y()); - const bool bContinue = - ( pDragTransferable->GetView() != &mrController.GetView() ) - || ( nXOffset >= 2 && nYOffset >= 2 ); - - // Get insertion position and then turn off the insertion indicator. - view::ViewOverlay& rOverlay (mrController.GetView().GetOverlay()); - rOverlay.GetInsertionIndicatorOverlay().SetPosition( - aEventModelPosition); - USHORT nIndex = DetermineInsertPosition (*pDragTransferable); - OSL_TRACE ("Clipboard::AcceptDrop() called for index %d", - nIndex); - rOverlay.GetInsertionIndicatorOverlay().Hide(); - - if (bContinue) + case DT_PAGE: { - SlideSorterController::ModelChangeLock aModelChangeLock (mrController); - - if (pDragTransferable->GetView() == &mrController.GetView() - && rEvent.mnAction == DND_ACTION_MOVE) + const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; + const Point aEventModelPosition ( + pTargetWindow->PixelToLogic (rEvent.maPosPixel)); + long int nXOffset = labs (pDragTransferable->GetStartPos().X() + - aEventModelPosition.X()); + long int nYOffset = labs (pDragTransferable->GetStartPos().Y() + - aEventModelPosition.Y()); + const bool bContinue = + ( pDragTransferable->GetView() != &mrController.GetView() ) + || ( nXOffset >= 2 && nYOffset >= 2 ); + + // Get insertion position and then turn off the insertion indicator. + view::ViewOverlay& rOverlay (mrController.GetView().GetOverlay()); + rOverlay.GetInsertionIndicatorOverlay().SetPosition( + aEventModelPosition); + USHORT nIndex = DetermineInsertPosition (*pDragTransferable); + OSL_TRACE ("Clipboard::AcceptDrop() called for index %d", + nIndex); + rOverlay.GetInsertionIndicatorOverlay().Hide(); + + if (bContinue) { - // We are asked to move pages inside one view. For this we - // call MoveSelectedPages() which is faster than going the - // generic way. - - // Remember to select the moved pages afterwards. - maPagesToRemove.swap(maPagesToSelect); - maPagesToRemove.clear(); - - USHORT nSdrModelIndex; - if (nIndex != SDRPAGE_NOTFOUND) - nSdrModelIndex = nIndex / 2 - 1; + SlideSorterController::ModelChangeLock aModelChangeLock (mrController); + + if (pDragTransferable->GetView() == &mrController.GetView() + && rEvent.mnAction == DND_ACTION_MOVE) + { + // We are asked to move pages inside one view. For this we + // call MoveSelectedPages() which is faster than going the + // generic way. + + // Remember to select the moved pages afterwards. + maPagesToRemove.swap(maPagesToSelect); + maPagesToRemove.clear(); + + USHORT nSdrModelIndex; + if (nIndex != SDRPAGE_NOTFOUND) + nSdrModelIndex = nIndex / 2 - 1; + else + nSdrModelIndex = SDRPAGE_NOTFOUND; + mrController.MoveSelectedPages(nSdrModelIndex); + mbUpdateSelectionPending = true; + nResult = DND_ACTION_NONE; + } else - nSdrModelIndex = SDRPAGE_NOTFOUND; - mrController.MoveSelectedPages(nSdrModelIndex); - mbUpdateSelectionPending = true; - nResult = DND_ACTION_NONE; - } - else - { - // Handle a general drop operation. - HandlePageDrop (*pDragTransferable); - nResult = rEvent.mnAction; + { + // Handle a general drop operation. + HandlePageDrop (*pDragTransferable); + nResult = rEvent.mnAction; + } } } + break; + + case DT_SHAPE: + nResult = ExecuteOrAcceptShapeDrop( + DC_EXECUTE, + rEvent.maPosPixel, + &rEvent, + rTargetHelper, + pTargetWindow, + nPage, + nLayer); + break; } return nResult; @@ -620,27 +654,91 @@ USHORT Clipboard::InsertSlides ( -bool Clipboard::IsDropAccepted (void) const +Clipboard::DropType Clipboard::IsDropAccepted (void) const { - const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; + DropType eResult (DT_NONE); - bool bIsDropAccepted (false); - do + const SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag; + if (pDragTransferable != NULL) { - if (pDragTransferable == NULL) - break; + if (pDragTransferable->IsPageTransferable()) + { + if (mrController.GetModel().GetEditMode() != EM_MASTERPAGE) + eResult = DT_PAGE; + } + else + { + eResult = DT_SHAPE; + } + } - if ( ! pDragTransferable->IsPageTransferable()) - break; + return eResult; +} - if (mrController.GetModel().GetEditMode() == EM_MASTERPAGE) - break; - bIsDropAccepted = true; + + +sal_Int8 Clipboard::ExecuteOrAcceptShapeDrop ( + DropCommand eCommand, + const Point& rPosition, + const void* pDropEvent, + DropTargetHelper& rTargetHelper, + ::sd::Window* pTargetWindow, + USHORT nPage, + USHORT nLayer) +{ + sal_Int8 nResult = 0; + + // The dropping of a shape is accepted or executed only when there is + // DrawViewShell available to which we can forward this call. This has + // technical reasons: The actual code to accept or execute a shape drop + // is implemented in the ViewShell class and uses the page view of the + // main edit view. This is not possible without a DrawViewShell. + DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>( + mrController.GetViewShell().GetViewShellBase().GetMainViewShell()); + if (pDrawViewShell != NULL + && (pDrawViewShell->GetShellType() == ViewShell::ST_IMPRESS + || pDrawViewShell->GetShellType() == ViewShell::ST_DRAW)) + { + // The drop is only accepted or executed when it takes place over a + // page object. Therefore we replace a missing page number by the + // number of the page under the mouse. + if (nPage == SDRPAGE_NOTFOUND) + { + model::PageDescriptor* pDescriptor + = mrController.GetModel().GetPageDescriptor( + mrController.GetView().GetPageIndexAtPoint(rPosition)); + if (pDescriptor != NULL && pDescriptor->GetPage()!=NULL) + nPage = (pDescriptor->GetPage()->GetPageNum() - 1) / 2; + } + + // Now comes the code that is different for the Execute and Accept: + // We simply forward the call to the AcceptDrop() or ExecuteDrop() + // methods of the DrawViewShell in the center pane. + if (nPage != SDRPAGE_NOTFOUND) + switch (eCommand) + { + case DC_ACCEPT: + nResult = pDrawViewShell->AcceptDrop( + *reinterpret_cast<const AcceptDropEvent*>(pDropEvent), + rTargetHelper, + pTargetWindow, + nPage, + nLayer); + break; + + case DC_EXECUTE: + nResult = pDrawViewShell->ExecuteDrop( + *reinterpret_cast<const ExecuteDropEvent*>(pDropEvent), + rTargetHelper, + pTargetWindow, + nPage, + nLayer); + break; + } } - while (false); - return bIsDropAccepted; + return nResult; } |