xref: /AOO41X/main/sw/source/core/edit/edws.cxx (revision 0aabba3ab117bd1ebf1560f23f52dfa1a54fd4c7)
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 
46 SwEditShell::SwEditShell( SwEditShell& rEdSH, Window *pWindow )
47     : SwCrsrShell( rEdSH, pWindow )
48 {
49 }
50 
51 // ctor/dtor
52 
53 
54 SwEditShell::SwEditShell( SwDoc& rDoc, Window *pWindow, const SwViewOption *pOptions )
55     : SwCrsrShell( rDoc, pWindow, pOptions )
56 {
57     GetDoc()->GetIDocumentUndoRedo().DoUndo(true);
58 }
59 
60 
61 SwEditShell::~SwEditShell() // USED
62 {
63 }
64 
65 /******************************************************************************
66  *					sal_Bool SwEditShell::IsModified() const
67  ******************************************************************************/
68 
69 
70 sal_Bool SwEditShell::IsModified() const
71 {
72 	return GetDoc()->IsModified();
73 }
74 /******************************************************************************
75  *					  void SwEditShell::SetModified()
76  ******************************************************************************/
77 
78 
79 void SwEditShell::SetModified()
80 {
81 	GetDoc()->SetModified();
82 }
83 /******************************************************************************
84  *					 void SwEditShell::ResetModified()
85  ******************************************************************************/
86 
87 
88 void SwEditShell::ResetModified()
89 {
90 	GetDoc()->ResetModified();
91 }
92 
93 void SwEditShell::SetUndoNoResetModified()
94 {
95 	GetDoc()->SetModified();
96     GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
97 }
98 
99 /******************************************************************************
100  *				   void SwEditShell::StartAllAction()
101  ******************************************************************************/
102 
103 
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 
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 
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 
160 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 
181 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 
206 SwActKontext::SwActKontext(SwEditShell *pShell)
207 	: pSh(pShell)
208 {
209 	pSh->StartAction();
210 }
211 
212 
213 SwActKontext::~SwActKontext()
214 {
215 	pSh->EndAction();
216 }
217 
218 /******************************************************************************
219  * 			Klasse fuer den automatisierten Aufruf von Start- und
220  * 								EndCrsrMove();
221  ******************************************************************************/
222 
223 
224 SwMvKontext::SwMvKontext(SwEditShell *pShell ) : pSh(pShell)
225 {
226 	pSh->SttCrsrMove();
227 }
228 
229 
230 SwMvKontext::~SwMvKontext()
231 {
232 	pSh->EndCrsrMove();
233 }
234 
235 
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 
245 sal_uInt16 SwEditShell::GetTOXTypeCount(TOXTypes eTyp) const
246 {
247 	return pDoc->GetTOXTypeCount(eTyp);
248 }
249 
250 
251 void SwEditShell::InsertTOXType(const SwTOXType& rTyp)
252 {
253 	pDoc->InsertTOXType(rTyp);
254 }
255 
256 
257 
258 void SwEditShell::DoUndo( sal_Bool bOn )
259 { GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
260 
261 
262 sal_Bool SwEditShell::DoesUndo() const
263 { return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
264 
265 
266 void SwEditShell::DoGroupUndo( sal_Bool bOn )
267 { GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
268 
269 
270 sal_Bool SwEditShell::DoesGroupUndo() const
271 { return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
272 
273 
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 
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 
292 SwUndoId SwEditShell::EndUndo(SwUndoId eUndoId,
293                                 const SwRewriter *pRewriter)
294 { return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); }
295 
296 
297 bool     SwEditShell::GetLastUndoInfo(::rtl::OUString *const o_pStr,
298                                       SwUndoId *const o_pId) const
299 { return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId); }
300 
301 bool     SwEditShell::GetFirstRedoInfo(::rtl::OUString *const o_pStr) const
302 { return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr); }
303 
304 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
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 
330 void SwEditShell::SetNewDoc(sal_Bool bNew)
331 {
332 	GetDoc()->SetNewDoc(bNew);
333 }
334 
335 
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 
355 SwAutoCompleteWord& SwEditShell::GetAutoCompleteWords()
356 {
357 	return SwDoc::GetAutoCompleteWords();
358 }
359 
360 
361 
362