1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include <vcl/window.hxx>
28
29 #include <editsh.hxx>
30 #include <doc.hxx>
31 #include <IDocumentUndoRedo.hxx>
32 #include <pam.hxx>
33 #include <docary.hxx>
34 #include <acorrect.hxx>
35 #include <swtable.hxx>
36 #include <ndtxt.hxx>
37 #include <swundo.hxx>
38 #include <SwRewriter.hxx>
39
40 /********************************************************
41 * Ctor/Dtor
42 ********************************************************/
43 // verkleideter Copy-Constructor
44
45
SwEditShell(SwEditShell & rEdSH,Window * pWindow)46 SwEditShell::SwEditShell( SwEditShell& rEdSH, Window *pWindow )
47 : SwCrsrShell( rEdSH, pWindow )
48 {
49 }
50
51 // ctor/dtor
52
53
SwEditShell(SwDoc & rDoc,Window * pWindow,const SwViewOption * pOptions)54 SwEditShell::SwEditShell( SwDoc& rDoc, Window *pWindow, const SwViewOption *pOptions )
55 : SwCrsrShell( rDoc, pWindow, pOptions )
56 {
57 GetDoc()->GetIDocumentUndoRedo().DoUndo(true);
58 }
59
60
~SwEditShell()61 SwEditShell::~SwEditShell() // USED
62 {
63 }
64
65 /******************************************************************************
66 * sal_Bool SwEditShell::IsModified() const
67 ******************************************************************************/
68
69
IsModified() const70 sal_Bool SwEditShell::IsModified() const
71 {
72 return GetDoc()->IsModified();
73 }
74 /******************************************************************************
75 * void SwEditShell::SetModified()
76 ******************************************************************************/
77
78
SetModified()79 void SwEditShell::SetModified()
80 {
81 GetDoc()->SetModified();
82 }
83 /******************************************************************************
84 * void SwEditShell::ResetModified()
85 ******************************************************************************/
86
87
ResetModified()88 void SwEditShell::ResetModified()
89 {
90 GetDoc()->ResetModified();
91 }
92
SetUndoNoResetModified()93 void SwEditShell::SetUndoNoResetModified()
94 {
95 GetDoc()->SetModified();
96 GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
97 }
98
99 /******************************************************************************
100 * void SwEditShell::StartAllAction()
101 ******************************************************************************/
102
103
StartAllAction()104 void SwEditShell::StartAllAction()
105 {
106 ViewShell *pSh = this;
107 do {
108 if( pSh->IsA( TYPE( SwEditShell ) ) )
109 ((SwEditShell*)pSh)->StartAction();
110 else
111 pSh->StartAction();
112 pSh = (ViewShell *)pSh->GetNext();
113 } while(pSh != this);
114 }
115 /******************************************************************************
116 * void SwEditShell::EndAllAction()
117 ******************************************************************************/
118
119
EndAllAction()120 void SwEditShell::EndAllAction()
121 {
122 ViewShell *pSh = this;
123 do {
124 if( pSh->IsA( TYPE( SwEditShell ) ) )
125 ((SwEditShell*)pSh)->EndAction();
126 else
127 pSh->EndAction();
128 pSh = (ViewShell *)pSh->GetNext();
129 } while(pSh != this);
130 }
131
132 /******************************************************************************
133 * void SwEditShell::CalcLayout()
134 ******************************************************************************/
135
136
CalcLayout()137 void SwEditShell::CalcLayout()
138 {
139 StartAllAction();
140 ViewShell::CalcLayout();
141
142 ViewShell *pSh = this;
143 do
144 {
145 if ( pSh->GetWin() )
146 pSh->GetWin()->Invalidate();
147 pSh = (ViewShell*)pSh->GetNext();
148
149 } while ( pSh != this );
150
151 EndAllAction();
152 }
153
154 /******************************************************************************
155 * Inhaltsform bestimmen, holen
156 ******************************************************************************/
157 // OPT: wird fuer jedes Attribut gerufen?
158
159
GetCntType() const160 sal_uInt16 SwEditShell::GetCntType() const
161 {
162 // nur noch am SPoint ist der Inhalt interessant
163 sal_uInt16 nRet = 0;
164 if( IsTableMode() )
165 nRet = CNT_TXT;
166 else
167 switch( GetCrsr()->GetNode()->GetNodeType() )
168 {
169 case ND_TEXTNODE: nRet = CNT_TXT; break;
170 case ND_GRFNODE: nRet = CNT_GRF; break;
171 case ND_OLENODE: nRet = CNT_OLE; break;
172 }
173
174 ASSERT( nRet, ERR_OUTOFSCOPE );
175 return nRet;
176 }
177
178 //------------------------------------------------------------------------------
179
180
HasOtherCnt() const181 sal_Bool SwEditShell::HasOtherCnt() const
182
183 {
184 if ( GetDoc()->GetSpzFrmFmts()->Count() )
185 return sal_True;
186
187 const SwNodes &rNds = GetDoc()->GetNodes();
188 const SwNode *pNd;
189
190 pNd = &rNds.GetEndOfInserts();
191 if ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
192 return sal_True;
193
194 pNd = &rNds.GetEndOfAutotext();
195 if ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
196 return sal_True;
197
198 return sal_False;
199 }
200
201 /******************************************************************************
202 * Zugriffsfunktionen fuer Filename-Behandlung
203 ******************************************************************************/
204
205
SwActKontext(SwEditShell * pShell)206 SwActKontext::SwActKontext(SwEditShell *pShell)
207 : pSh(pShell)
208 {
209 pSh->StartAction();
210 }
211
212
~SwActKontext()213 SwActKontext::~SwActKontext()
214 {
215 pSh->EndAction();
216 }
217
218 /******************************************************************************
219 * Klasse fuer den automatisierten Aufruf von Start- und
220 * EndCrsrMove();
221 ******************************************************************************/
222
223
SwMvKontext(SwEditShell * pShell)224 SwMvKontext::SwMvKontext(SwEditShell *pShell ) : pSh(pShell)
225 {
226 pSh->SttCrsrMove();
227 }
228
229
~SwMvKontext()230 SwMvKontext::~SwMvKontext()
231 {
232 pSh->EndCrsrMove();
233 }
234
235
GetTableFmt()236 SwFrmFmt *SwEditShell::GetTableFmt() // OPT: schnellster Test auf Tabelle?
237 {
238 const SwTableNode* pTblNd = IsCrsrInTbl();
239 return pTblNd ? (SwFrmFmt*)pTblNd->GetTable().GetFrmFmt() : 0;
240 }
241
242 // OPT: wieso 3x beim neuen Dokument
243
244
GetTOXTypeCount(TOXTypes eTyp) const245 sal_uInt16 SwEditShell::GetTOXTypeCount(TOXTypes eTyp) const
246 {
247 return pDoc->GetTOXTypeCount(eTyp);
248 }
249
250
InsertTOXType(const SwTOXType & rTyp)251 void SwEditShell::InsertTOXType(const SwTOXType& rTyp)
252 {
253 pDoc->InsertTOXType(rTyp);
254 }
255
256
257
DoUndo(sal_Bool bOn)258 void SwEditShell::DoUndo( sal_Bool bOn )
259 { GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
260
261
DoesUndo() const262 sal_Bool SwEditShell::DoesUndo() const
263 { return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
264
265
DoGroupUndo(sal_Bool bOn)266 void SwEditShell::DoGroupUndo( sal_Bool bOn )
267 { GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
268
269
DoesGroupUndo() const270 sal_Bool SwEditShell::DoesGroupUndo() const
271 { return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
272
273
DelAllUndoObj()274 void SwEditShell::DelAllUndoObj()
275 {
276 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
277 }
278
279 // Zusammenfassen von Kontinuierlichen Insert/Delete/Overwrite von
280 // Charaktern. Default ist sdbcx::Group-Undo.
281
282 // setzt Undoklammerung auf, liefert nUndoId der Klammerung
283
284
StartUndo(SwUndoId eUndoId,const SwRewriter * pRewriter)285 SwUndoId SwEditShell::StartUndo( SwUndoId eUndoId,
286 const SwRewriter *pRewriter )
287 { return GetDoc()->GetIDocumentUndoRedo().StartUndo( eUndoId, pRewriter ); }
288
289 // schliesst Klammerung der nUndoId, nicht vom UI benutzt
290
291
EndUndo(SwUndoId eUndoId,const SwRewriter * pRewriter)292 SwUndoId SwEditShell::EndUndo(SwUndoId eUndoId,
293 const SwRewriter *pRewriter)
294 { return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); }
295
296
GetLastUndoInfo(::rtl::OUString * const o_pStr,SwUndoId * const o_pId) const297 bool SwEditShell::GetLastUndoInfo(::rtl::OUString *const o_pStr,
298 SwUndoId *const o_pId) const
299 { return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId); }
300
GetFirstRedoInfo(::rtl::OUString * const o_pStr) const301 bool SwEditShell::GetFirstRedoInfo(::rtl::OUString *const o_pStr) const
302 { return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr); }
303
GetRepeatInfo(::rtl::OUString * const o_pStr) const304 SwUndoId SwEditShell::GetRepeatInfo(::rtl::OUString *const o_pStr) const
305 { return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); }
306
307
308
309 // AutoKorrektur - JP 27.01.94
AutoCorrect(SvxAutoCorrect & rACorr,sal_Bool bInsert,sal_Unicode cChar)310 void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Bool bInsert,
311 sal_Unicode cChar )
312 {
313 SET_CURR_SHELL( this );
314
315 StartAllAction();
316
317 SwPaM* pCrsr = getShellCrsr( true );
318 SwTxtNode* pTNd = pCrsr->GetNode()->GetTxtNode();
319
320 SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, cChar );
321 rACorr.AutoCorrect( aSwAutoCorrDoc,
322 pTNd->GetTxt(), pCrsr->GetPoint()->nContent.GetIndex(),
323 cChar, bInsert );
324 if( cChar )
325 SaveTblBoxCntnt( pCrsr->GetPoint() );
326 EndAllAction();
327 }
328
329
SetNewDoc(sal_Bool bNew)330 void SwEditShell::SetNewDoc(sal_Bool bNew)
331 {
332 GetDoc()->SetNewDoc(bNew);
333 }
334
335
GetPrevAutoCorrWord(SvxAutoCorrect & rACorr,String & rWord)336 sal_Bool SwEditShell::GetPrevAutoCorrWord( SvxAutoCorrect& rACorr, String& rWord )
337 {
338 SET_CURR_SHELL( this );
339
340 sal_Bool bRet;
341 SwPaM* pCrsr = getShellCrsr( true );
342 xub_StrLen nPos = pCrsr->GetPoint()->nContent.GetIndex();
343 SwTxtNode* pTNd = pCrsr->GetNode()->GetTxtNode();
344 if( pTNd && nPos )
345 {
346 SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, 0 );
347 bRet = rACorr.GetPrevAutoCorrWord( aSwAutoCorrDoc,
348 pTNd->GetTxt(), nPos, rWord );
349 }
350 else
351 bRet = sal_False;
352 return bRet;
353 }
354
GetAutoCompleteWords()355 SwAutoCompleteWord& SwEditShell::GetAutoCompleteWords()
356 {
357 return SwDoc::GetAutoCompleteWords();
358 }
359
360
361
362