1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/diagnose_ex.hxx>
26 #include <IDocumentUndoRedo.hxx>
27 #include <IDocumentRedlineAccess.hxx>
28 #include <UndoCore.hxx>
33 #include <pagefrm.hxx>
34 #include <textboxhelper.hxx>
35 #include <fmtanchr.hxx>
39 /** helper function to select all objects in an SdrMarkList;
40 * implementation: see below */
41 static void lcl_SelectSdrMarkList( SwEditShell
* pShell
,
42 const SdrMarkList
* pSdrMarkList
);
44 bool SwEditShell::CursorsLocked() const
46 SwDocShell
* pShell
= GetDoc()->GetDocShell();
49 return pShell
->GetModel()->hasControllersLocked();
52 void SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext
& rContext
)
54 // do nothing if somebody has locked controllers!
60 SwFrameFormat
* pSelFormat(nullptr);
61 SdrMarkList
* pMarkList(nullptr);
62 rContext
.GetSelections(pSelFormat
, pMarkList
);
64 if (pSelFormat
) // select frame
66 if (RES_DRAWFRMFMT
== pSelFormat
->Which())
68 SdrObject
* pSObj
= pSelFormat
->FindSdrObject();
70 // Before layout calc, inline anchored textboxes have to be synced unless crash.
71 if (pSelFormat
->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR
72 && pSelFormat
->GetOtherTextBoxFormats())
73 SwTextBoxHelper::synchronizeGroupTextBoxProperty(SwTextBoxHelper::changeAnchor
,
76 static_cast<SwFEShell
*>(this)->SelectObj(
77 pSObj
->GetCurrentBoundRect().Center() );
82 SwFlyFrame
*const pFly
=
83 static_cast<SwFlyFrameFormat
*>(pSelFormat
)->GetFrame(& aPt
);
86 // fdo#36681: Invalidate the content and layout to refresh
87 // the picture anchoring properly
88 SwPageFrame
* pPageFrame
= pFly
->FindPageFrameOfAnchor();
89 pPageFrame
->InvalidateFlyLayout();
90 pPageFrame
->InvalidateContent();
92 static_cast<SwFEShell
*>(this)->SelectFlyFrame(*pFly
);
98 lcl_SelectSdrMarkList( this, pMarkList
);
100 else if (GetCursor()->GetNext() != GetCursor())
102 // current cursor is the last one:
103 // go around the ring, to the first cursor
108 void SwEditShell::Undo(sal_uInt16
const nCount
, sal_uInt16 nOffset
)
110 MakeAllOutlineContentTemporarilyVisible
a(GetDoc(), true);
112 CurrShell
aCurr( this );
114 // current undo state was not saved
115 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
119 // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
120 // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
122 SetMark(); // Bound1 and Bound2 in the same Node
125 // Keep Cursor - so that we're able to set it at
126 // the same position for autoformat or autocorrection
127 SwUndoId
nLastUndoId(SwUndoId::EMPTY
);
128 GetLastUndoInfo(nullptr, & nLastUndoId
);
129 const bool bRestoreCursor
= nCount
== 1
130 && ( SwUndoId::AUTOFORMAT
== nLastUndoId
131 || SwUndoId::AUTOCORRECT
== nLastUndoId
132 || SwUndoId::SETDEFTATTR
== nLastUndoId
);
135 // Destroy stored TableBoxPtr. A detection is only permitted for the new "Box"!
136 ClearTableBoxContent();
138 const RedlineFlags eOld
= GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
141 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
143 GetDoc()->GetIDocumentUndoRedo().UndoWithOffset(nOffset
);
145 } catch (const css::uno::Exception
&) {
146 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Undo()");
150 { // fdo#39003 Pop does not touch the rest of the cursor ring
151 KillPams(); // so call this first to get rid of unwanted cursors
153 Pop(bRestoreCursor
? PopMode::DeleteCurrent
: PopMode::DeleteStack
);
155 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOld
);
156 GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
158 // automatic detection of the new "Box"
159 SaveTableBoxContent();
164 void SwEditShell::Redo(sal_uInt16
const nCount
)
166 MakeAllOutlineContentTemporarilyVisible
a(GetDoc(), true);
168 CurrShell
aCurr( this );
170 // undo state was not saved
171 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
176 // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
177 // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
179 SetMark(); // Bound1 and Bound2 in the same Node
182 SwUndoId
nFirstRedoId(SwUndoId::EMPTY
);
183 GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(nullptr, & nFirstRedoId
);
184 const bool bRestoreCursor
= nCount
== 1 && SwUndoId::SETDEFTATTR
== nFirstRedoId
;
187 // Destroy stored TableBoxPtr. A detection is only permitted for the new "Box"!
188 ClearTableBoxContent();
190 RedlineFlags eOld
= GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags();
193 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
195 GetDoc()->GetIDocumentUndoRedo().Redo();
197 } catch (const css::uno::Exception
&) {
198 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Redo()");
201 Pop(bRestoreCursor
? PopMode::DeleteCurrent
: PopMode::DeleteStack
);
203 GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOld
);
204 GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
206 // automatic detection of the new "Box"
207 SaveTableBoxContent();
213 void SwEditShell::Repeat(sal_uInt16
const nCount
)
215 CurrShell
aCurr( this );
220 ::sw::RepeatContext
context(*GetDoc(), *GetCursor());
221 GetDoc()->GetIDocumentUndoRedo().Repeat( context
, nCount
);
222 } catch (const css::uno::Exception
&) {
223 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Repeat()");
229 static void lcl_SelectSdrMarkList( SwEditShell
* pShell
,
230 const SdrMarkList
* pSdrMarkList
)
232 OSL_ENSURE( pShell
!= nullptr, "need shell!" );
234 SwFEShell
* pFEShell
= dynamic_cast<SwFEShell
*>( pShell
);
238 assert(pSdrMarkList
!= nullptr && "need mark list");
241 for( size_t i
= 0; i
< pSdrMarkList
->GetMarkCount(); ++i
)
243 SdrObject
*pObj
= pSdrMarkList
->GetMark( i
)->GetMarkedSdrObj();
246 pFEShell
->SelectObj( Point(), bFirst
? 0 : SW_ADD_SELECT
, pObj
);
251 // the old implementation would always unselect
252 // objects, even if no new ones were selected. If this
253 // is a problem, we need to re-work this a little.
254 OSL_ENSURE( pSdrMarkList
->GetMarkCount() != 0, "empty mark list" );
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */