nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / edit / edundo.cxx
bloba55f45651fbad40df71c16f3cdffa817d7f9df4f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svdmark.hxx>
21 #include <tools/diagnose_ex.h>
23 #include <com/sun/star/frame/XModel.hpp>
25 #include <editsh.hxx>
26 #include <fesh.hxx>
27 #include <doc.hxx>
28 #include <IDocumentUndoRedo.hxx>
29 #include <IDocumentRedlineAccess.hxx>
30 #include <pam.hxx>
31 #include <UndoCore.hxx>
32 #include <swundo.hxx>
33 #include <flyfrm.hxx>
34 #include <frmfmt.hxx>
35 #include <docsh.hxx>
36 #include <pagefrm.hxx>
38 /** helper function to select all objects in an SdrMarkList;
39 * implementation: see below */
40 static void lcl_SelectSdrMarkList( SwEditShell* pShell,
41 const SdrMarkList* pSdrMarkList );
43 bool SwEditShell::CursorsLocked() const
45 return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
48 void SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext)
50 // do nothing if somebody has locked controllers!
51 if (CursorsLocked())
53 return;
56 SwFrameFormat * pSelFormat(nullptr);
57 SdrMarkList * pMarkList(nullptr);
58 rContext.GetSelections(pSelFormat, pMarkList);
60 if (pSelFormat) // select frame
62 if (RES_DRAWFRMFMT == pSelFormat->Which())
64 SdrObject* pSObj = pSelFormat->FindSdrObject();
65 static_cast<SwFEShell*>(this)->SelectObj(
66 pSObj->GetCurrentBoundRect().Center() );
68 else
70 Point aPt;
71 SwFlyFrame *const pFly =
72 static_cast<SwFlyFrameFormat*>(pSelFormat)->GetFrame(& aPt);
73 if (pFly)
75 // fdo#36681: Invalidate the content and layout to refresh
76 // the picture anchoring properly
77 SwPageFrame* pPageFrame = pFly->FindPageFrameOfAnchor();
78 pPageFrame->InvalidateFlyLayout();
79 pPageFrame->InvalidateContent();
81 static_cast<SwFEShell*>(this)->SelectFlyFrame(*pFly);
85 else if (pMarkList)
87 lcl_SelectSdrMarkList( this, pMarkList );
89 else if (GetCursor()->GetNext() != GetCursor())
91 // current cursor is the last one:
92 // go around the ring, to the first cursor
93 GoNextCursor();
97 void SwEditShell::Undo(sal_uInt16 const nCount)
99 CurrShell aCurr( this );
101 // current undo state was not saved
102 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
103 bool bRet = false;
105 StartAllAction();
107 // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
108 // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
109 KillPams();
110 SetMark(); // Bound1 and Bound2 in the same Node
111 ClearMark();
113 // Keep Cursor - so that we're able to set it at
114 // the same position for autoformat or autocorrection
115 SwUndoId nLastUndoId(SwUndoId::EMPTY);
116 GetLastUndoInfo(nullptr, & nLastUndoId);
117 const bool bRestoreCursor = nCount == 1
118 && ( SwUndoId::AUTOFORMAT == nLastUndoId
119 || SwUndoId::AUTOCORRECT == nLastUndoId
120 || SwUndoId::SETDEFTATTR == nLastUndoId );
121 Push();
123 // Destroy stored TableBoxPtr. A detection is only permitted for the new "Box"!
124 ClearTableBoxContent();
126 const RedlineFlags eOld = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
128 try {
129 for (sal_uInt16 i = 0; i < nCount; ++i)
131 bRet = GetDoc()->GetIDocumentUndoRedo().Undo()
132 || bRet;
134 } catch (const css::uno::Exception &) {
135 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Undo()");
138 if (bRestoreCursor)
139 { // fdo#39003 Pop does not touch the rest of the cursor ring
140 KillPams(); // so call this first to get rid of unwanted cursors
142 Pop(bRestoreCursor ? PopMode::DeleteCurrent : PopMode::DeleteStack);
144 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOld );
145 GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
147 // automatic detection of the new "Box"
148 SaveTableBoxContent();
150 EndAllAction();
153 void SwEditShell::Redo(sal_uInt16 const nCount)
155 CurrShell aCurr( this );
157 bool bRet = false;
159 // undo state was not saved
160 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
162 StartAllAction();
165 // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
166 // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
167 KillPams();
168 SetMark(); // Bound1 and Bound2 in the same Node
169 ClearMark();
171 SwUndoId nFirstRedoId(SwUndoId::EMPTY);
172 GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(nullptr, & nFirstRedoId);
173 const bool bRestoreCursor = nCount == 1 && SwUndoId::SETDEFTATTR == nFirstRedoId;
174 Push();
176 // Destroy stored TableBoxPtr. A detection is only permitted for the new "Box"!
177 ClearTableBoxContent();
179 RedlineFlags eOld = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
181 try {
182 for (sal_uInt16 i = 0; i < nCount; ++i)
184 bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
185 || bRet;
187 } catch (const css::uno::Exception &) {
188 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Redo()");
191 Pop(bRestoreCursor ? PopMode::DeleteCurrent : PopMode::DeleteStack);
193 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOld );
194 GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
196 // automatic detection of the new "Box"
197 SaveTableBoxContent();
200 EndAllAction();
203 void SwEditShell::Repeat(sal_uInt16 const nCount)
205 CurrShell aCurr( this );
207 StartAllAction();
209 try {
210 ::sw::RepeatContext context(*GetDoc(), *GetCursor());
211 GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount );
212 } catch (const css::uno::Exception &) {
213 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Repeat()");
216 EndAllAction();
219 static void lcl_SelectSdrMarkList( SwEditShell* pShell,
220 const SdrMarkList* pSdrMarkList )
222 OSL_ENSURE( pShell != nullptr, "need shell!" );
223 OSL_ENSURE( pSdrMarkList != nullptr, "need mark list" );
225 SwFEShell* pFEShell = dynamic_cast<SwFEShell*>( pShell );
226 if( !pFEShell )
227 return;
229 bool bFirst = true;
230 for( size_t i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
232 SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
233 if( pObj )
235 pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
236 bFirst = false;
240 // the old implementation would always unselect
241 // objects, even if no new ones were selected. If this
242 // is a problem, we need to re-work this a little.
243 OSL_ENSURE( pSdrMarkList->GetMarkCount() != 0, "empty mark list" );
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */