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