Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svx/svdview.hxx>
31 : :
32 : : #include <editsh.hxx>
33 : : #include <fesh.hxx>
34 : : #include <doc.hxx>
35 : : #include <IDocumentUndoRedo.hxx>
36 : : #include <pam.hxx>
37 : : #include <UndoCore.hxx>
38 : : #include <swundo.hxx>
39 : : #include <dcontact.hxx>
40 : : #include <flyfrm.hxx>
41 : : #include <frmfmt.hxx>
42 : : #include <viewimp.hxx>
43 : : #include <docsh.hxx>
44 : :
45 : :
46 : : /** helper function to select all objects in an SdrMarkList;
47 : : * implementation: see below */
48 : : void lcl_SelectSdrMarkList( SwEditShell* pShell,
49 : : const SdrMarkList* pSdrMarkList );
50 : :
51 : 96 : bool SwEditShell::CursorsLocked() const
52 : : {
53 : :
54 [ + - ][ + - ]: 96 : return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
55 : : }
56 : :
57 : : void
58 : 44 : SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext)
59 : : {
60 : : // do nothing if somebody has locked controllers!
61 [ + - ][ + - ]: 44 : if (CursorsLocked())
62 : : {
63 : 44 : return;
64 : : }
65 : :
66 : 44 : SwFrmFmt * pSelFmt(0);
67 : 44 : SdrMarkList * pMarkList(0);
68 : 44 : rContext.GetSelections(pSelFmt, pMarkList);
69 : :
70 [ - + ]: 44 : if (pSelFmt) // select frame
71 : : {
72 [ # # ]: 0 : if (RES_DRAWFRMFMT == pSelFmt->Which())
73 : : {
74 [ # # ]: 0 : SdrObject* pSObj = pSelFmt->FindSdrObject();
75 : : static_cast<SwFEShell*>(this)->SelectObj(
76 [ # # ][ # # ]: 0 : pSObj->GetCurrentBoundRect().Center() );
[ # # ]
77 : : }
78 : : else
79 : : {
80 : 0 : Point aPt;
81 : : SwFlyFrm *const pFly =
82 [ # # ]: 0 : static_cast<SwFlyFrmFmt*>(pSelFmt)->GetFrm(& aPt, false);
83 [ # # ]: 0 : if (pFly)
84 : : {
85 [ # # ]: 0 : static_cast<SwFEShell*>(this)->SelectFlyFrm(*pFly, true);
86 : : }
87 : : }
88 : : }
89 [ - + ]: 44 : else if (pMarkList)
90 : : {
91 [ # # ]: 0 : lcl_SelectSdrMarkList( this, pMarkList );
92 : : }
93 [ + - ][ + - ]: 44 : else if (GetCrsr()->GetNext() != GetCrsr())
[ - + ]
94 : : {
95 : : // current cursor is the last one:
96 : : // go around the ring, to the first cursor
97 [ # # ]: 44 : GoNextCrsr();
98 : : }
99 : : }
100 : :
101 : 6 : bool SwEditShell::Undo(sal_uInt16 const nCount)
102 : : {
103 [ + - ]: 6 : SET_CURR_SHELL( this );
104 : :
105 : : // current undo state was not saved
106 [ + - ][ + - ]: 6 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
107 : 6 : sal_Bool bRet = sal_False;
108 : :
109 [ + - ]: 6 : StartAllAction();
110 : : {
111 : : // eigentlich muesste ja nur der aktuelle Cursor berarbeitet
112 : : // werden, d.H. falls ein Ring besteht, diesen temporaer aufheben,
113 : : // damit nicht bei Einfuge-Operationen innerhalb von Undo
114 : : // an allen Bereichen eingefuegt wird.
115 [ + - ]: 6 : KillPams();
116 [ + - ]: 6 : SetMark(); // Bound1 und Bound2 in den gleichen Node
117 [ + - ]: 6 : ClearMark();
118 : :
119 : : // JP 02.04.98: Cursor merken - beim Auto-Format/-Korrektur
120 : : // soll dieser wieder an die Position
121 : 6 : SwUndoId nLastUndoId(UNDO_EMPTY);
122 [ + - ][ + - ]: 6 : GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(0, & nLastUndoId);
123 : : bool bRestoreCrsr = 1 == nCount && (UNDO_AUTOFORMAT == nLastUndoId ||
124 [ + - ][ + - ]: 6 : UNDO_AUTOCORRECT == nLastUndoId );
[ - + ]
125 [ + - ]: 6 : Push();
126 : :
127 : : //JP 18.09.97: gesicherten TabellenBoxPtr zerstoeren, eine autom.
128 : : // Erkennung darf nur noch fuer die neue "Box" erfolgen!
129 [ + - ]: 6 : ClearTblBoxCntnt();
130 : :
131 [ + - ]: 6 : RedlineMode_t eOld = GetDoc()->GetRedlineMode();
132 : :
133 : : try {
134 [ + + ]: 10 : for (sal_uInt16 i = 0; i < nCount; ++i)
135 : : {
136 [ + - ][ + + ]: 6 : bRet = GetDoc()->GetIDocumentUndoRedo().Undo()
137 [ - + ][ # # ]: 4 : || bRet;
138 : : }
139 [ + - ]: 2 : } catch (const ::com::sun::star::uno::Exception & e) {
140 : : OSL_TRACE("SwEditShell::Undo(): exception caught:\n %s",
141 : : ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
142 : : .getStr());
143 : : }
144 : :
145 [ - + ]: 6 : if (bRestoreCrsr)
146 : : { // fdo#39003 Pop does not touch the rest of the cursor ring
147 [ # # ]: 0 : KillPams(); // so call this first to get rid of unwanted cursors
148 : : }
149 [ + - ]: 6 : Pop( !bRestoreCrsr );
150 : :
151 [ + - ]: 6 : GetDoc()->SetRedlineMode( eOld );
152 [ + - ]: 6 : GetDoc()->CompressRedlines();
153 : :
154 : : // autom. Erkennung fuer die neue "Box"
155 [ + - ]: 6 : SaveTblBoxCntnt();
156 : : }
157 [ + - ]: 6 : EndAllAction();
158 : :
159 [ + - ][ + - ]: 8 : return bRet;
[ - + ]
160 : : }
161 : :
162 : 2 : bool SwEditShell::Redo(sal_uInt16 const nCount)
163 : : {
164 [ + - ]: 2 : SET_CURR_SHELL( this );
165 : :
166 : 2 : sal_Bool bRet = sal_False;
167 : :
168 : : // undo state was not saved
169 [ + - ][ + - ]: 2 : ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
170 : :
171 [ + - ]: 2 : StartAllAction();
172 : :
173 : : {
174 : : // eigentlich muesste ja nur der aktuelle Cursor berarbeitet
175 : : // werden, d.H. falls ein Ring besteht, diesen temporaer aufheben,
176 : : // damit nicht bei Einfuge-Operationen innerhalb von Undo
177 : : // an allen Bereichen eingefuegt wird.
178 [ + - ]: 2 : KillPams();
179 [ + - ]: 2 : SetMark(); // Bound1 und Bound2 in den gleichen Node
180 [ + - ]: 2 : ClearMark();
181 : :
182 : : //JP 18.09.97: gesicherten TabellenBoxPtr zerstoeren, eine autom.
183 : : // Erkennung darf nur noch fuer die neue "Box" erfolgen!
184 [ + - ]: 2 : ClearTblBoxCntnt();
185 : :
186 [ + - ]: 2 : RedlineMode_t eOld = GetDoc()->GetRedlineMode();
187 : :
188 : : try {
189 [ + - ]: 2 : for (sal_uInt16 i = 0; i < nCount; ++i)
190 : : {
191 [ + - ][ - + ]: 2 : bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
192 [ # # ][ # # ]: 0 : || bRet;
193 : : }
194 [ + - ]: 2 : } catch (const ::com::sun::star::uno::Exception & e) {
195 : : OSL_TRACE("SwEditShell::Redo(): exception caught:\n %s",
196 : : ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
197 : : .getStr());
198 : : }
199 : :
200 [ + - ]: 2 : GetDoc()->SetRedlineMode( eOld );
201 [ + - ]: 2 : GetDoc()->CompressRedlines();
202 : :
203 : : // autom. Erkennung fuer die neue "Box"
204 [ + - ]: 2 : SaveTblBoxCntnt();
205 : : }
206 : :
207 [ + - ]: 2 : EndAllAction();
208 : :
209 [ + - ][ + - ]: 4 : return bRet;
[ - + ]
210 : : }
211 : :
212 : :
213 : 0 : bool SwEditShell::Repeat(sal_uInt16 const nCount)
214 : : {
215 [ # # ]: 0 : SET_CURR_SHELL( this );
216 : :
217 : 0 : sal_Bool bRet = sal_False;
218 [ # # ]: 0 : StartAllAction();
219 : :
220 : : try {
221 [ # # ][ # # ]: 0 : ::sw::RepeatContext context(*GetDoc(), *GetCrsr());
222 [ # # ][ # # ]: 0 : bRet = GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount )
223 [ # # ][ # # ]: 0 : || bRet;
[ # # ][ # # ]
224 [ # # ]: 0 : } catch (const ::com::sun::star::uno::Exception & e) {
225 : : OSL_TRACE("SwEditShell::Repeat(): exception caught:\n %s",
226 : : ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
227 : : .getStr());
228 : : }
229 : :
230 [ # # ]: 0 : EndAllAction();
231 [ # # ]: 0 : return bRet;
232 : : }
233 : :
234 : :
235 : 0 : void lcl_SelectSdrMarkList( SwEditShell* pShell,
236 : : const SdrMarkList* pSdrMarkList )
237 : : {
238 : : OSL_ENSURE( pShell != NULL, "need shell!" );
239 : : OSL_ENSURE( pSdrMarkList != NULL, "need mark list" );
240 : :
241 [ # # ]: 0 : if( pShell->ISA( SwFEShell ) )
242 : : {
243 : 0 : SwFEShell* pFEShell = static_cast<SwFEShell*>( pShell );
244 : 0 : bool bFirst = true;
245 [ # # ]: 0 : for( sal_uInt16 i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
246 : : {
247 : 0 : SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
248 [ # # ]: 0 : if( pObj )
249 : : {
250 [ # # ][ # # ]: 0 : pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
251 : 0 : bFirst = false;
252 : : }
253 : : }
254 : :
255 : : // the old implementation would always unselect
256 : : // objects, even if no new ones were selected. If this
257 : : // is a problem, we need to re-work this a little.
258 : : OSL_ENSURE( pSdrMarkList->GetMarkCount() != 0, "empty mark list" );
259 : : }
260 : 0 : }
261 : :
262 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|