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