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