Line data Source code
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/svdview.hxx>
21 :
22 : #include <editsh.hxx>
23 : #include <fesh.hxx>
24 : #include <doc.hxx>
25 : #include <IDocumentUndoRedo.hxx>
26 : #include <IDocumentContentOperations.hxx>
27 : #include <IDocumentRedlineAccess.hxx>
28 : #include <pam.hxx>
29 : #include <UndoCore.hxx>
30 : #include <swundo.hxx>
31 : #include <dcontact.hxx>
32 : #include <flyfrm.hxx>
33 : #include <frmfmt.hxx>
34 : #include <viewimp.hxx>
35 : #include <docsh.hxx>
36 : #include <pagefrm.hxx>
37 :
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 );
42 :
43 70 : bool SwEditShell::CursorsLocked() const
44 : {
45 70 : return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
46 : }
47 :
48 33 : void SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext)
49 : {
50 : // do nothing if somebody has locked controllers!
51 33 : if (CursorsLocked())
52 : {
53 33 : return;
54 : }
55 :
56 33 : SwFrameFormat * pSelFormat(0);
57 33 : SdrMarkList * pMarkList(0);
58 33 : rContext.GetSelections(pSelFormat, pMarkList);
59 :
60 33 : if (pSelFormat) // select frame
61 : {
62 0 : if (RES_DRAWFRMFMT == pSelFormat->Which())
63 : {
64 0 : SdrObject* pSObj = pSelFormat->FindSdrObject();
65 : static_cast<SwFEShell*>(this)->SelectObj(
66 0 : pSObj->GetCurrentBoundRect().Center() );
67 : }
68 : else
69 : {
70 0 : Point aPt;
71 : SwFlyFrm *const pFly =
72 0 : static_cast<SwFlyFrameFormat*>(pSelFormat)->GetFrm(& aPt, false);
73 0 : if (pFly)
74 : {
75 : // fdo#36681: Invalidate the content and layout to refresh
76 : // the picture anchoring properly
77 0 : SwPageFrm* pPageFrm = pFly->FindPageFrmOfAnchor();
78 0 : pPageFrm->InvalidateFlyLayout();
79 0 : pPageFrm->InvalidateContent();
80 :
81 0 : static_cast<SwFEShell*>(this)->SelectFlyFrm(*pFly, true);
82 : }
83 : }
84 : }
85 33 : else if (pMarkList)
86 : {
87 0 : lcl_SelectSdrMarkList( this, pMarkList );
88 : }
89 33 : else if (GetCrsr()->GetNext() != GetCrsr())
90 : {
91 : // current cursor is the last one:
92 : // go around the ring, to the first cursor
93 0 : GoNextCrsr();
94 : }
95 : }
96 :
97 3 : bool SwEditShell::Undo(sal_uInt16 const nCount)
98 : {
99 3 : SET_CURR_SHELL( this );
100 :
101 : // current undo state was not saved
102 6 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
103 3 : bool bRet = false;
104 :
105 3 : StartAllAction();
106 : {
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 3 : KillPams();
110 3 : SetMark(); // Bound1 and Bound2 in the same Node
111 3 : ClearMark();
112 :
113 : // Keep Cursor - so that we're able to set it at
114 : // the same position for autoformat or autocorrection
115 3 : SwUndoId nLastUndoId(UNDO_EMPTY);
116 3 : GetLastUndoInfo(0, & nLastUndoId);
117 : const bool bRestoreCrsr = nCount == 1
118 3 : && ( UNDO_AUTOFORMAT == nLastUndoId
119 3 : || UNDO_AUTOCORRECT == nLastUndoId
120 6 : || UNDO_SETDEFTATTR == nLastUndoId );
121 3 : Push();
122 :
123 : // Destroy stored TableBoxPtr. A dection is only permitted for the new "Box"!
124 3 : ClearTableBoxContent();
125 :
126 3 : const RedlineMode_t eOld = GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
127 :
128 : try {
129 5 : for (sal_uInt16 i = 0; i < nCount; ++i)
130 : {
131 3 : bRet = GetDoc()->GetIDocumentUndoRedo().Undo()
132 2 : || bRet;
133 : }
134 1 : } catch (const ::com::sun::star::uno::Exception & e) {
135 : SAL_WARN("sw.core",
136 : "SwEditShell::Undo(): exception caught: " << e.Message);
137 : }
138 :
139 3 : if (bRestoreCrsr)
140 : { // fdo#39003 Pop does not touch the rest of the cursor ring
141 0 : KillPams(); // so call this first to get rid of unwanted cursors
142 : }
143 3 : Pop( !bRestoreCrsr );
144 :
145 3 : GetDoc()->getIDocumentRedlineAccess().SetRedlineMode( eOld );
146 3 : GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
147 :
148 : // automatic detection of the new "Box"
149 3 : SaveTableBoxContent();
150 : }
151 3 : EndAllAction();
152 :
153 6 : return bRet;
154 : }
155 :
156 1 : bool SwEditShell::Redo(sal_uInt16 const nCount)
157 : {
158 1 : SET_CURR_SHELL( this );
159 :
160 1 : bool bRet = false;
161 :
162 : // undo state was not saved
163 2 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
164 :
165 1 : StartAllAction();
166 :
167 : {
168 : // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
169 : // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
170 1 : KillPams();
171 1 : SetMark(); // Bound1 and Bound2 in the same Node
172 1 : ClearMark();
173 :
174 1 : SwUndoId nFirstRedoId(UNDO_EMPTY);
175 1 : GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(0, & nFirstRedoId);
176 1 : const bool bRestoreCrsr = nCount == 1 && UNDO_SETDEFTATTR == nFirstRedoId;
177 1 : Push();
178 :
179 : // Destroy stored TableBoxPtr. A dection is only permitted for the new "Box"!
180 1 : ClearTableBoxContent();
181 :
182 1 : RedlineMode_t eOld = GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
183 :
184 : try {
185 1 : for (sal_uInt16 i = 0; i < nCount; ++i)
186 : {
187 1 : bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
188 0 : || bRet;
189 : }
190 1 : } catch (const ::com::sun::star::uno::Exception & e) {
191 : SAL_WARN("sw.core",
192 : "SwEditShell::Redo(): exception caught: " << e.Message);
193 : }
194 :
195 1 : Pop( !bRestoreCrsr );
196 :
197 1 : GetDoc()->getIDocumentRedlineAccess().SetRedlineMode( eOld );
198 1 : GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
199 :
200 : // automatic detection of the new "Box"
201 1 : SaveTableBoxContent();
202 : }
203 :
204 1 : EndAllAction();
205 :
206 2 : return bRet;
207 : }
208 :
209 0 : bool SwEditShell::Repeat(sal_uInt16 const nCount)
210 : {
211 0 : SET_CURR_SHELL( this );
212 :
213 0 : bool bRet = false;
214 0 : StartAllAction();
215 :
216 : try {
217 0 : ::sw::RepeatContext context(*GetDoc(), *GetCrsr());
218 0 : bRet = GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount )
219 0 : || bRet;
220 0 : } catch (const ::com::sun::star::uno::Exception & e) {
221 : SAL_WARN("sw.core",
222 : "SwEditShell::Repeat(): exception caught: " << e.Message);
223 : }
224 :
225 0 : EndAllAction();
226 0 : return bRet;
227 : }
228 :
229 0 : static void lcl_SelectSdrMarkList( SwEditShell* pShell,
230 : const SdrMarkList* pSdrMarkList )
231 : {
232 : OSL_ENSURE( pShell != NULL, "need shell!" );
233 : OSL_ENSURE( pSdrMarkList != NULL, "need mark list" );
234 :
235 0 : if( pShell->ISA( SwFEShell ) )
236 : {
237 0 : SwFEShell* pFEShell = static_cast<SwFEShell*>( pShell );
238 0 : bool bFirst = true;
239 0 : for( size_t i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
240 : {
241 0 : SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
242 0 : if( pObj )
243 : {
244 0 : pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
245 0 : bFirst = false;
246 : }
247 : }
248 :
249 : // the old implementation would always unselect
250 : // objects, even if no new ones were selected. If this
251 : // is a problem, we need to re-work this a little.
252 : OSL_ENSURE( pSdrMarkList->GetMarkCount() != 0, "empty mark list" );
253 : }
254 177 : }
255 :
256 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|