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 :
21 : #include <svx/svdview.hxx>
22 :
23 : #include <editsh.hxx>
24 : #include <fesh.hxx>
25 : #include <doc.hxx>
26 : #include <IDocumentUndoRedo.hxx>
27 : #include <pam.hxx>
28 : #include <UndoCore.hxx>
29 : #include <swundo.hxx>
30 : #include <dcontact.hxx>
31 : #include <flyfrm.hxx>
32 : #include <frmfmt.hxx>
33 : #include <viewimp.hxx>
34 : #include <docsh.hxx>
35 : #include <pagefrm.hxx>
36 :
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 0 : bool SwEditShell::CursorsLocked() const
44 : {
45 :
46 0 : return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
47 : }
48 :
49 : void
50 0 : SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext)
51 : {
52 : // do nothing if somebody has locked controllers!
53 0 : if (CursorsLocked())
54 : {
55 0 : return;
56 : }
57 :
58 0 : SwFrmFmt * pSelFmt(0);
59 0 : SdrMarkList * pMarkList(0);
60 0 : rContext.GetSelections(pSelFmt, pMarkList);
61 :
62 0 : if (pSelFmt) // select frame
63 : {
64 0 : if (RES_DRAWFRMFMT == pSelFmt->Which())
65 : {
66 0 : SdrObject* pSObj = pSelFmt->FindSdrObject();
67 : static_cast<SwFEShell*>(this)->SelectObj(
68 0 : pSObj->GetCurrentBoundRect().Center() );
69 : }
70 : else
71 : {
72 0 : Point aPt;
73 : SwFlyFrm *const pFly =
74 0 : static_cast<SwFlyFrmFmt*>(pSelFmt)->GetFrm(& aPt, false);
75 0 : if (pFly)
76 : {
77 : // fdo#36681: Invalidate the content and layout to refresh
78 : // the picture anchoring properly
79 0 : SwPageFrm* pPageFrm = pFly->FindPageFrmOfAnchor();
80 0 : pPageFrm->InvalidateFlyLayout();
81 0 : pPageFrm->InvalidateCntnt();
82 :
83 0 : static_cast<SwFEShell*>(this)->SelectFlyFrm(*pFly, true);
84 : }
85 : }
86 : }
87 0 : else if (pMarkList)
88 : {
89 0 : lcl_SelectSdrMarkList( this, pMarkList );
90 : }
91 0 : else if (GetCrsr()->GetNext() != GetCrsr())
92 : {
93 : // current cursor is the last one:
94 : // go around the ring, to the first cursor
95 0 : GoNextCrsr();
96 : }
97 : }
98 :
99 0 : bool SwEditShell::Undo(sal_uInt16 const nCount)
100 : {
101 0 : SET_CURR_SHELL( this );
102 :
103 : // current undo state was not saved
104 0 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
105 0 : bool bRet = false;
106 :
107 0 : StartAllAction();
108 : {
109 : // eigentlich muesste ja nur der aktuelle Cursor berarbeitet
110 : // werden, d.H. falls ein Ring besteht, diesen temporaer aufheben,
111 : // damit nicht bei Einfuge-Operationen innerhalb von Undo
112 : // an allen Bereichen eingefuegt wird.
113 0 : KillPams();
114 0 : SetMark(); // Bound1 und Bound2 in den gleichen Node
115 0 : ClearMark();
116 :
117 : // JP 02.04.98: Cursor merken - beim Auto-Format/-Korrektur
118 : // soll dieser wieder an die Position
119 0 : SwUndoId nLastUndoId(UNDO_EMPTY);
120 0 : GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(0, & nLastUndoId);
121 : bool bRestoreCrsr = 1 == nCount && (UNDO_AUTOFORMAT == nLastUndoId ||
122 0 : UNDO_AUTOCORRECT == nLastUndoId );
123 0 : Push();
124 :
125 : //JP 18.09.97: gesicherten TabellenBoxPtr zerstoeren, eine autom.
126 : // Erkennung darf nur noch fuer die neue "Box" erfolgen!
127 0 : ClearTblBoxCntnt();
128 :
129 0 : RedlineMode_t eOld = GetDoc()->GetRedlineMode();
130 :
131 : try {
132 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
133 : {
134 0 : bRet = GetDoc()->GetIDocumentUndoRedo().Undo()
135 0 : || bRet;
136 : }
137 0 : } catch (const ::com::sun::star::uno::Exception & e) {
138 : OSL_TRACE("SwEditShell::Undo(): exception caught:\n %s",
139 : ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
140 : .getStr());
141 : }
142 :
143 0 : if (bRestoreCrsr)
144 : { // fdo#39003 Pop does not touch the rest of the cursor ring
145 0 : KillPams(); // so call this first to get rid of unwanted cursors
146 : }
147 0 : Pop( !bRestoreCrsr );
148 :
149 0 : GetDoc()->SetRedlineMode( eOld );
150 0 : GetDoc()->CompressRedlines();
151 :
152 : // autom. Erkennung fuer die neue "Box"
153 0 : SaveTblBoxCntnt();
154 : }
155 0 : EndAllAction();
156 :
157 0 : return bRet;
158 : }
159 :
160 0 : bool SwEditShell::Redo(sal_uInt16 const nCount)
161 : {
162 0 : SET_CURR_SHELL( this );
163 :
164 0 : bool bRet = false;
165 :
166 : // undo state was not saved
167 0 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
168 :
169 0 : StartAllAction();
170 :
171 : {
172 : // eigentlich muesste ja nur der aktuelle Cursor berarbeitet
173 : // werden, d.H. falls ein Ring besteht, diesen temporaer aufheben,
174 : // damit nicht bei Einfuge-Operationen innerhalb von Undo
175 : // an allen Bereichen eingefuegt wird.
176 0 : KillPams();
177 0 : SetMark(); // Bound1 und Bound2 in den gleichen Node
178 0 : ClearMark();
179 :
180 : //JP 18.09.97: gesicherten TabellenBoxPtr zerstoeren, eine autom.
181 : // Erkennung darf nur noch fuer die neue "Box" erfolgen!
182 0 : ClearTblBoxCntnt();
183 :
184 0 : RedlineMode_t eOld = GetDoc()->GetRedlineMode();
185 :
186 : try {
187 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
188 : {
189 0 : bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
190 0 : || bRet;
191 : }
192 0 : } catch (const ::com::sun::star::uno::Exception & e) {
193 : OSL_TRACE("SwEditShell::Redo(): exception caught:\n %s",
194 : ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
195 : .getStr());
196 : }
197 :
198 0 : GetDoc()->SetRedlineMode( eOld );
199 0 : GetDoc()->CompressRedlines();
200 :
201 : // autom. Erkennung fuer die neue "Box"
202 0 : SaveTblBoxCntnt();
203 : }
204 :
205 0 : EndAllAction();
206 :
207 0 : return bRet;
208 : }
209 :
210 :
211 0 : bool SwEditShell::Repeat(sal_uInt16 const nCount)
212 : {
213 0 : SET_CURR_SHELL( this );
214 :
215 0 : bool bRet = false;
216 0 : StartAllAction();
217 :
218 : try {
219 0 : ::sw::RepeatContext context(*GetDoc(), *GetCrsr());
220 0 : bRet = GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount )
221 0 : || bRet;
222 0 : } catch (const ::com::sun::star::uno::Exception & e) {
223 : OSL_TRACE("SwEditShell::Repeat(): exception caught:\n %s",
224 : ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
225 : .getStr());
226 : }
227 :
228 0 : EndAllAction();
229 0 : return bRet;
230 : }
231 :
232 :
233 0 : static void lcl_SelectSdrMarkList( SwEditShell* pShell,
234 : const SdrMarkList* pSdrMarkList )
235 : {
236 : OSL_ENSURE( pShell != NULL, "need shell!" );
237 : OSL_ENSURE( pSdrMarkList != NULL, "need mark list" );
238 :
239 0 : if( pShell->ISA( SwFEShell ) )
240 : {
241 0 : SwFEShell* pFEShell = static_cast<SwFEShell*>( pShell );
242 0 : bool bFirst = true;
243 0 : for( sal_uInt16 i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
244 : {
245 0 : SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
246 0 : if( pObj )
247 : {
248 0 : pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
249 0 : bFirst = false;
250 : }
251 : }
252 :
253 : // the old implementation would always unselect
254 : // objects, even if no new ones were selected. If this
255 : // is a problem, we need to re-work this a little.
256 : OSL_ENSURE( pSdrMarkList->GetMarkCount() != 0, "empty mark list" );
257 : }
258 0 : }
259 :
260 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|