sd/inc/drawdoc.hxx                                      |    3 -
 sd/source/core/drawdoc2.cxx                             |   36 ++++++++--------
 sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx |    8 +--
 sd/source/ui/unoidl/unomodel.cxx                        |   21 ++++++++-
 sd/source/ui/view/outlview.cxx                          |    2 
 sd/source/ui/view/tabcontr.cxx                          |    4 -
 sd/source/ui/view/viewshe3.cxx                          |    2 
 7 files changed, 49 insertions(+), 27 deletions(-)

New commits:
commit e7e48682cca73b3eb4ddba947e10159b6aeb5335
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Wed Apr 30 15:25:55 2025 +0530
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Apr 30 20:32:58 2025 +0200

    sd: use slide(SdPage/Part) selection for current view only
    
    problem:
    in LOK when multipe users select the different slides some operations may 
fail
    i.e:
    - user A and B opens the document,
    - User B selects slide 4
    - User A selects slide 1
    (without this patch SdPage will only concider slide 1 selected)
    - Then user B tries to drag and drop slide 4 above the slide 1
    - now core will think slide 1 is selected and need to put
    it above slide 1 that means nothing happens
    
    Change-Id: Ia9ebe531ddb1c21ffaa1435d9cc777750b4ca24c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184629
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    (cherry picked from commit aee332547295c78b3bcda38b67ba3f1ec2b0fc06)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184842
    Tested-by: Jenkins

diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index 24f1b077a21e..8abe00c78f55 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -780,7 +780,8 @@ public:
 
     SAL_DLLPRIVATE void                SetSelected(SdPage* pPage, bool 
bSelect);
     SAL_DLLPRIVATE void                UnselectAllPages();
-    SAL_DLLPRIVATE bool                MovePages(sal_uInt16 nTargetPage);
+    SAL_DLLPRIVATE bool                MoveSelectedPages(sal_uInt16 
nTargetPage);
+    SAL_DLLPRIVATE bool MovePages(sal_uInt16 nTargetPage, 
std::vector<SdPage*>& vSelectedPages);
 
     SdPage*GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind);
     sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const;
diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index 5f8ab487f9e4..5c03bb7848e1 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -787,14 +787,29 @@ void SdDrawDocument::UnselectAllPages()
     }
 }
 
+bool SdDrawDocument::MoveSelectedPages(sal_uInt16 nTargetPage)
+{
+    sal_uInt16 nNoOfPages = GetSdPageCount(PageKind::Standard);
+    std::vector<SdPage*> aPageList;
+    for (sal_uInt16 nPage = 0; nPage < nNoOfPages; nPage++)
+    {
+        SdPage* pPage = GetSdPage(nPage, PageKind::Standard);
+
+        if (pPage->IsSelected())
+        {
+            aPageList.push_back(pPage);
+        }
+    }
+    return MovePages(nTargetPage, aPageList);
+}
+
 // + Move selected pages after said page
 //   (nTargetPage = (sal_uInt16)-1  --> move before first page)
 // + Returns sal_True when the page has been moved
-bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
+bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage, std::vector<SdPage*>& 
vSelectedPages)
 {
     SdPage* pPage              = nullptr;
-    sal_uInt16  nPage;
-    sal_uInt16  nNoOfPages         = GetSdPageCount(PageKind::Standard);
+    sal_uInt16 nPage;
     bool    bSomethingHappened = false;
 
     const bool bUndo = IsUndoEnabled();
@@ -802,17 +817,6 @@ bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
     if( bUndo )
         BegUndo(SdResId(STR_UNDO_MOVEPAGES));
 
-    // List of selected pages
-    std::vector<SdPage*> aPageList;
-    for (nPage = 0; nPage < nNoOfPages; nPage++)
-    {
-        pPage = GetSdPage(nPage, PageKind::Standard);
-
-        if (pPage->IsSelected()) {
-            aPageList.push_back(pPage);
-        }
-    }
-
     // If necessary, look backwards, until we find a page that wasn't selected
     nPage = nTargetPage;
 
@@ -835,7 +839,7 @@ bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
     if (nPage == sal_uInt16(-1))
     {
         std::vector<SdPage*>::reverse_iterator iter;
-        for (iter = aPageList.rbegin(); iter != aPageList.rend(); ++iter)
+        for (iter = vSelectedPages.rbegin(); iter != vSelectedPages.rend(); 
++iter)
         {
             nPage = (*iter)->GetPageNum();
             if (nPage != 0)
@@ -857,7 +861,7 @@ bool SdDrawDocument::MovePages(sal_uInt16 nTargetPage)
     {
         nTargetPage = 2 * nPage + 1;    // PageKind::Standard --> absolute
 
-        for (const auto& rpPage : aPageList)
+        for (const auto& rpPage : vSelectedPages)
         {
             nPage = rpPage->GetPageNum();
             if (nPage > nTargetPage)
diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx 
b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
index 3eb048984b70..e4f7a34fd05d 100644
--- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
+++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
@@ -765,7 +765,7 @@ void SlideSorterViewShell::ExecMovePageFirst (SfxRequest& 
/*rReq*/)
     SyncPageSelectionToDocument(xSelection);
 
     // Moves selected pages after page -1
-    GetDoc()->MovePages( sal_uInt16(-1) );
+    GetDoc()->MoveSelectedPages( sal_uInt16(-1) );
 
     PostMoveSlidesActions(xSelection);
 }
@@ -821,7 +821,7 @@ void SlideSorterViewShell::ExecMovePageUp (SfxRequest& 
/*rReq*/)
 
     // Move pages before firstSelectedPageNo - 1 (so after firstSelectedPageNo 
- 2),
     // remembering that -1 means at first, which is good.
-    GetDoc()->MovePages( firstSelectedPageNo - 2 );
+    GetDoc()->MoveSelectedPages( firstSelectedPageNo - 2 );
 
     PostMoveSlidesActions(xSelection);
 }
@@ -850,7 +850,7 @@ void SlideSorterViewShell::ExecMovePageDown (SfxRequest& 
/*rReq*/)
         return;
 
     // Move to position after lastSelectedPageNo
-    GetDoc()->MovePages( lastSelectedPageNo + 1 );
+    GetDoc()->MoveSelectedPages( lastSelectedPageNo + 1 );
 
     PostMoveSlidesActions(xSelection);
 }
@@ -874,7 +874,7 @@ void SlideSorterViewShell::ExecMovePageLast (SfxRequest& 
/*rReq*/)
     sal_uInt16 nNoOfPages = GetDoc()->GetSdPageCount(PageKind::Standard);
 
     // Move to position after last page No (=Number of pages - 1)
-    GetDoc()->MovePages( nNoOfPages - 1 );
+    GetDoc()->MoveSelectedPages( nNoOfPages - 1 );
 
     PostMoveSlidesActions(xSelection);
 }
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 9f8a6d909fde..0de64714ac22 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -180,6 +180,10 @@
 #include <frozen/bits/defines.h>
 #include <frozen/bits/elsa_std.h>
 #include <frozen/unordered_map.h>
+#include <SlideSorter.hxx>
+#include <SlideSorterViewShell.hxx>
+#include <controller/SlideSorterController.hxx>
+#include <controller/SlsPageSelector.hxx>
 
 #include <app.hrc>
 
@@ -3976,8 +3980,21 @@ void SdXImpressDocument::selectPart(int nPart, int 
nSelect)
 void SdXImpressDocument::moveSelectedParts(int nPosition, bool bDuplicate)
 {
     // Duplicating is currently unsupported.
-    if (!bDuplicate)
-        mpDoc->MovePages(nPosition);
+    if (bDuplicate)
+        return;
+
+    DrawViewShell* pViewSh = GetViewShell();
+    if (!pViewSh)
+        return;
+
+    auto pSlideSorter
+        = 
sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewSh->GetViewShellBase());
+    sd::slidesorter::SharedPageSelection pSelectedPage
+        = pSlideSorter ? pSlideSorter->GetPageSelection() : nullptr;
+    std::vector<SdPage*> aPageList;
+    if (pSelectedPage)
+        aPageList = *pSelectedPage;
+    mpDoc->MovePages(nPosition, aPageList);
 }
 
 OUString SdXImpressDocument::getPartInfo(int nPart)
diff --git a/sd/source/ui/view/outlview.cxx b/sd/source/ui/view/outlview.cxx
index f2f5ca1ffe1a..40b81ad3c95c 100644
--- a/sd/source/ui/view/outlview.cxx
+++ b/sd/source/ui/view/outlview.cxx
@@ -839,7 +839,7 @@ IMPL_LINK( OutlineView, EndMovingHdl, ::Outliner *, 
pOutliner, void )
         DBG_ASSERT(nPos != 0xffff, "Paragraph not found");
     }
 
-    mrDoc.MovePages(nPos);
+    mrDoc.MoveSelectedPages(nPos);
 
     // deselect the pages again
     sal_uInt16 nPageCount = static_cast<sal_uInt16>(maSelectedParas.size());
diff --git a/sd/source/ui/view/tabcontr.cxx b/sd/source/ui/view/tabcontr.cxx
index 68baa2b8067d..ba2829459170 100644
--- a/sd/source/ui/view/tabcontr.cxx
+++ b/sd/source/ui/view/tabcontr.cxx
@@ -210,7 +210,7 @@ sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& 
rEvt )
         switch (rEvt.mnAction)
         {
             case DND_ACTION_MOVE:
-                if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( 
nPageId ) )
+                if( pDrViewSh->IsSwitchPageAllowed() && 
pDoc->MoveSelectedPages( nPageId ) )
                 {
                     SfxDispatcher* pDispatcher = 
pDrViewSh->GetViewFrame()->GetDispatcher();
                     pDispatcher->Execute(SID_SWITCHPAGE, 
SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
@@ -237,7 +237,7 @@ sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& 
rEvt )
                     sal_uInt16 nPageNum = nPageId;
                     if ((nPageNumOfCopy <= nPageNum) && (nPageNum != 
sal_uInt16(-1)))
                         nPageNum += 1;
-                    if (pDoc->MovePages(nPageNum))
+                    if (pDoc->MoveSelectedPages(nPageNum))
                     {
                         // 3. Switch to the copy that has been moved to its
                         // final destination.  Use an asynchron slot call to
diff --git a/sd/source/ui/view/viewshe3.cxx b/sd/source/ui/view/viewshe3.cxx
index 45b6e99cb091..a722aef10fe3 100644
--- a/sd/source/ui/view/viewshe3.cxx
+++ b/sd/source/ui/view/viewshe3.cxx
@@ -331,7 +331,7 @@ SdPage* ViewShell::CreateOrDuplicatePage (
                             i == nNewPageIndex);
                     }
                     // Move the selected page to the head of the document
-                    pDocument->MovePages (sal_uInt16(-1));
+                    pDocument->MoveSelectedPages (sal_uInt16(-1));
                     nNewPageIndex = 0;
                 }
             else

Reply via email to