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