LibreOffice Module sw (master) 1
edundo.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <svx/svdmark.hxx>
22
23#include <editsh.hxx>
24#include <fesh.hxx>
25#include <doc.hxx>
26#include <IDocumentUndoRedo.hxx>
28#include <UndoCore.hxx>
29#include <swundo.hxx>
30#include <flyfrm.hxx>
31#include <frmfmt.hxx>
32#include <docsh.hxx>
33#include <pagefrm.hxx>
34#include <textboxhelper.hxx>
35#include <fmtanchr.hxx>
36
37#include <wrtsh.hxx>
38
41static void lcl_SelectSdrMarkList( SwEditShell* pShell,
42 const SdrMarkList* pSdrMarkList );
43
45{
46 return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
47}
48
50{
51 // do nothing if somebody has locked controllers!
52 if (CursorsLocked())
53 {
54 return;
55 }
56
57 SwFrameFormat * pSelFormat(nullptr);
58 SdrMarkList * pMarkList(nullptr);
59 rContext.GetSelections(pSelFormat, pMarkList);
60
61 if (pSelFormat) // select frame
62 {
63 if (RES_DRAWFRMFMT == pSelFormat->Which())
64 {
65 SdrObject* pSObj = pSelFormat->FindSdrObject();
66
67 // Before layout calc, inline anchored textboxes have to be synced unless crash.
68 if (pSelFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR
69 && pSelFormat->GetOtherTextBoxFormats())
71 pSelFormat, pSObj);
72
73 static_cast<SwFEShell*>(this)->SelectObj(
74 pSObj->GetCurrentBoundRect().Center() );
75 }
76 else
77 {
78 Point aPt;
79 SwFlyFrame *const pFly =
80 static_cast<SwFlyFrameFormat*>(pSelFormat)->GetFrame(& aPt);
81 if (pFly)
82 {
83 // fdo#36681: Invalidate the content and layout to refresh
84 // the picture anchoring properly
85 SwPageFrame* pPageFrame = pFly->FindPageFrameOfAnchor();
86 pPageFrame->InvalidateFlyLayout();
87 pPageFrame->InvalidateContent();
88
89 static_cast<SwFEShell*>(this)->SelectFlyFrame(*pFly);
90 }
91 }
92 }
93 else if (pMarkList)
94 {
95 lcl_SelectSdrMarkList( this, pMarkList );
96 }
97 else if (GetCursor()->GetNext() != GetCursor())
98 {
99 // current cursor is the last one:
100 // go around the ring, to the first cursor
101 GoNextCursor();
102 }
103}
104
105void SwEditShell::Undo(sal_uInt16 const nCount, sal_uInt16 nOffset)
106{
108
109 CurrShell aCurr( this );
110
111 // current undo state was not saved
112 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
113 bool bRet = false;
114
116 {
117 // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
118 // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
119 KillPams();
120 SetMark(); // Bound1 and Bound2 in the same Node
121 ClearMark();
122
123 // Keep Cursor - so that we're able to set it at
124 // the same position for autoformat or autocorrection
125 SwUndoId nLastUndoId(SwUndoId::EMPTY);
126 GetLastUndoInfo(nullptr, & nLastUndoId);
127 const bool bRestoreCursor = nCount == 1
128 && ( SwUndoId::AUTOFORMAT == nLastUndoId
129 || SwUndoId::AUTOCORRECT == nLastUndoId
130 || SwUndoId::SETDEFTATTR == nLastUndoId );
131 Push();
132
133 // Destroy stored TableBoxPtr. A detection is only permitted for the new "Box"!
135
137
138 try {
139 for (sal_uInt16 i = 0; i < nCount; ++i)
140 {
141 bRet = GetDoc()->GetIDocumentUndoRedo().UndoWithOffset(nOffset) || bRet;
142 }
143 } catch (const css::uno::Exception &) {
144 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Undo()");
145 }
146
147 if (bRestoreCursor)
148 { // fdo#39003 Pop does not touch the rest of the cursor ring
149 KillPams(); // so call this first to get rid of unwanted cursors
150 }
152
155
156 // automatic detection of the new "Box"
158 }
159 EndAllAction();
160}
161
162void SwEditShell::Redo(sal_uInt16 const nCount)
163{
165
166 CurrShell aCurr( this );
167
168 bool bRet = false;
169
170 // undo state was not saved
171 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
172
174
175 {
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.
178 KillPams();
179 SetMark(); // Bound1 and Bound2 in the same Node
180 ClearMark();
181
182 SwUndoId nFirstRedoId(SwUndoId::EMPTY);
183 GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(nullptr, & nFirstRedoId);
184 const bool bRestoreCursor = nCount == 1 && SwUndoId::SETDEFTATTR == nFirstRedoId;
185 Push();
186
187 // Destroy stored TableBoxPtr. A detection is only permitted for the new "Box"!
189
191
192 try {
193 for (sal_uInt16 i = 0; i < nCount; ++i)
194 {
195 bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
196 || bRet;
197 }
198 } catch (const css::uno::Exception &) {
199 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Redo()");
200 }
201
203
206
207 // automatic detection of the new "Box"
209 }
210
211 EndAllAction();
212}
213
214void SwEditShell::Repeat(sal_uInt16 const nCount)
215{
216 CurrShell aCurr( this );
217
219
220 try {
221 ::sw::RepeatContext context(*GetDoc(), *GetCursor());
222 GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount );
223 } catch (const css::uno::Exception &) {
224 TOOLS_WARN_EXCEPTION("sw.core", "SwEditShell::Repeat()");
225 }
226
227 EndAllAction();
228}
229
231 const SdrMarkList* pSdrMarkList )
232{
233 OSL_ENSURE( pShell != nullptr, "need shell!" );
234 OSL_ENSURE( pSdrMarkList != nullptr, "need mark list" );
235
236 SwFEShell* pFEShell = dynamic_cast<SwFEShell*>( pShell );
237 if( !pFEShell )
238 return;
239
240 bool bFirst = true;
241 for( size_t i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
242 {
243 SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
244 if( pObj )
245 {
246 pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
247 bFirst = false;
248 }
249 }
250
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" );
255}
256
257/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetRedlineFlags(RedlineFlags eMode)=0
Set a new redline mode.
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
virtual void CompressRedlines(size_t nStartIndex=0)=0
virtual bool UndoWithOffset(size_t nUndoOffset)=0
Zero offset means undoing the top undo action.
virtual bool Redo()=0
Execute Redo.
virtual bool GetFirstRedoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const =0
Get Id and comment of first Redo action.
virtual bool Repeat(::sw::RepeatContext &rContext, sal_uInt16 const nRepeatCnt)=0
Repeat the last Undo action.
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
SdrObject * GetMarkedSdrObj() const
virtual const tools::Rectangle & GetCurrentBoundRect() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
SwPageFrame * FindPageFrameOfAnchor()
method to determine the page frame, on which the 'anchor' of the given anchored object is.
bool Pop(PopMode, ::std::optional< SwCallLink > &roLink)
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2251
void ClearTableBoxContent()
Definition: trvltbl.cxx:906
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
bool GoNextCursor()
go to the next SSelection
Definition: crsrsh.cxx:1357
void ClearMark()
Definition: crsrsh.cxx:939
void SetMark()
Definition: crsrsh.hxx:895
void KillPams()
Definition: crsrsh.cxx:1022
void SaveTableBoxContent(const SwPosition *pPos=nullptr)
Definition: trvltbl.cxx:867
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:150
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:341
SwDocShell * GetDocShell()
Definition: doc.hxx:1359
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void Repeat(sal_uInt16 const nCount)
Definition: edundo.cxx:214
void HandleUndoRedoContext(::sw::UndoRedoContext &rContext)
set selections to those contained in the UndoRedoContext should only be called by sw::UndoManager!
Definition: edundo.cxx:49
bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:237
void Redo(sal_uInt16 const nCount=1)
Definition: edundo.cxx:162
void Undo(sal_uInt16 const nCount=1, sal_uInt16 nOffset=0)
Definition: edundo.cxx:105
void EndAllAction()
Definition: edws.cxx:97
bool CursorsLocked() const
is it forbidden to modify cursors via API calls?
Definition: edundo.cxx:44
bool SelectObj(const Point &rSelPt, sal_uInt8 nFlag=0, SdrObject *pObj=nullptr)
If an object has been given, exactly this object is selected (instead of searching over position).
Definition: feshview.cxx:177
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
RndStdIds GetAnchorId() const
Definition: fmtanchr.hxx:67
sal_uInt16 Which() const
for Querying of Writer-functions.
Definition: format.hxx:82
const SwFormatAnchor & GetAnchor(bool=true) const
Definition: fmtanchr.hxx:83
Style of a layout element.
Definition: frmfmt.hxx:62
const std::shared_ptr< SwTextBoxNode > & GetOtherTextBoxFormats() const
Definition: frmfmt.hxx:106
SdrObject * FindSdrObject()
Definition: frmfmt.hxx:141
A page of the document layout.
Definition: pagefrm.hxx:58
void InvalidateContent() const
Definition: pagefrm.hxx:380
void InvalidateFlyLayout() const
Validate, invalidate and query the Page status Layout/Content and Fly/non-Fly respectively are inspec...
Definition: pagefrm.hxx:364
static bool changeAnchor(SwFrameFormat *pShape, SdrObject *pObj)
Sets the anchor of the associated textframe of the given shape, and returns true on success.
static void synchronizeGroupTextBoxProperty(bool pFunc(SwFrameFormat *, SdrObject *), SwFrameFormat *pFormat, SdrObject *pObj)
Calls the method given by pFunc with every textboxes of the group given by pFormat.
IDocumentUndoRedo const & GetIDocumentUndoRedo() const
Provides access to the document undo/redo interface.
Definition: viewsh.cxx:2821
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
void GetSelections(SwFrameFormat *&o_rpSelFormat, SdrMarkList *&o_rpMarkList)
Definition: UndoCore.hxx:104
constexpr Point Center() const
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
static void lcl_SelectSdrMarkList(SwEditShell *pShell, const SdrMarkList *pSdrMarkList)
helper function to select all objects in an SdrMarkList; implementation: see below
Definition: edundo.cxx:230
#define SW_ADD_SELECT
Definition: fesh.hxx:166
constexpr TypedWhichId< SwDrawFrameFormat > RES_DRAWFRMFMT(159)
uno_Any a
int i
SwUndoId
Definition: swundo.hxx:30