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 : #include <vcl/window.hxx>
21 :
22 : #include <editsh.hxx>
23 : #include <doc.hxx>
24 : #include <IDocumentUndoRedo.hxx>
25 : #include <pam.hxx>
26 : #include <docary.hxx>
27 : #include <acorrect.hxx>
28 : #include <swtable.hxx>
29 : #include <ndtxt.hxx>
30 : #include <swundo.hxx>
31 : #include <SwRewriter.hxx>
32 :
33 : // masqueraded copy constructor
34 0 : SwEditShell::SwEditShell( SwEditShell& rEdSH, Window *pWindow )
35 0 : : SwCrsrShell( rEdSH, pWindow )
36 : {
37 0 : }
38 :
39 0 : SwEditShell::SwEditShell( SwDoc& rDoc, Window *pWindow, const SwViewOption *pOptions )
40 0 : : SwCrsrShell( rDoc, pWindow, pOptions )
41 : {
42 0 : GetDoc()->GetIDocumentUndoRedo().DoUndo(true);
43 0 : }
44 :
45 0 : SwEditShell::~SwEditShell() // USED
46 : {
47 0 : }
48 :
49 0 : sal_Bool SwEditShell::IsModified() const
50 : {
51 0 : return GetDoc()->IsModified();
52 : }
53 :
54 0 : void SwEditShell::SetModified()
55 : {
56 0 : GetDoc()->SetModified();
57 0 : }
58 :
59 0 : void SwEditShell::ResetModified()
60 : {
61 0 : GetDoc()->ResetModified();
62 0 : }
63 :
64 0 : void SwEditShell::SetUndoNoResetModified()
65 : {
66 0 : GetDoc()->SetModified();
67 0 : GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
68 0 : }
69 :
70 0 : void SwEditShell::StartAllAction()
71 : {
72 0 : SwViewShell *pSh = this;
73 0 : do {
74 0 : if( pSh->IsA( TYPE( SwEditShell ) ) )
75 0 : ((SwEditShell*)pSh)->StartAction();
76 : else
77 0 : pSh->StartAction();
78 0 : pSh = (SwViewShell *)pSh->GetNext();
79 0 : } while(pSh != this);
80 0 : }
81 :
82 0 : void SwEditShell::EndAllAction()
83 : {
84 0 : SwViewShell *pSh = this;
85 0 : do {
86 0 : if( pSh->IsA( TYPE( SwEditShell ) ) )
87 0 : ((SwEditShell*)pSh)->EndAction();
88 : else
89 0 : pSh->EndAction();
90 0 : pSh = (SwViewShell *)pSh->GetNext();
91 0 : } while(pSh != this);
92 0 : }
93 :
94 0 : void SwEditShell::CalcLayout()
95 : {
96 0 : StartAllAction();
97 0 : SwViewShell::CalcLayout();
98 :
99 0 : SwViewShell *pSh = this;
100 0 : do
101 : {
102 0 : if ( pSh->GetWin() )
103 0 : pSh->GetWin()->Invalidate();
104 0 : pSh = (SwViewShell*)pSh->GetNext();
105 :
106 0 : } while ( pSh != this );
107 :
108 0 : EndAllAction();
109 0 : }
110 :
111 : /** Get the content type of a shell
112 : *
113 : * @todo Is this called for every attribute?
114 : */
115 0 : sal_uInt16 SwEditShell::GetCntType() const
116 : {
117 0 : sal_uInt16 nRet = 0;
118 0 : if( IsTableMode() )
119 0 : nRet = CNT_TXT;
120 : else
121 0 : switch( GetCrsr()->GetNode()->GetNodeType() )
122 : {
123 0 : case ND_TEXTNODE: nRet = CNT_TXT; break;
124 0 : case ND_GRFNODE: nRet = CNT_GRF; break;
125 0 : case ND_OLENODE: nRet = CNT_OLE; break;
126 : }
127 :
128 : OSL_ASSERT( nRet );
129 0 : return nRet;
130 : }
131 :
132 0 : sal_Bool SwEditShell::HasOtherCnt() const
133 :
134 : {
135 0 : if ( !GetDoc()->GetSpzFrmFmts()->empty() )
136 0 : return sal_True;
137 :
138 0 : const SwNodes &rNds = GetDoc()->GetNodes();
139 : const SwNode *pNd;
140 :
141 0 : pNd = &rNds.GetEndOfInserts();
142 0 : if ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
143 0 : return sal_True;
144 :
145 0 : pNd = &rNds.GetEndOfAutotext();
146 0 : if ( 1 != (pNd->GetIndex() - pNd->StartOfSectionIndex()) )
147 0 : return sal_True;
148 :
149 0 : return sal_False;
150 : }
151 :
152 : // access controll functions for file name handling
153 :
154 0 : SwActContext::SwActContext(SwEditShell *pShell)
155 0 : : pSh(pShell)
156 : {
157 0 : pSh->StartAction();
158 0 : }
159 :
160 0 : SwActContext::~SwActContext()
161 : {
162 0 : pSh->EndAction();
163 0 : }
164 :
165 0 : SwMvContext::SwMvContext(SwEditShell *pShell)
166 0 : : pSh(pShell)
167 : {
168 0 : pSh->SttCrsrMove();
169 0 : }
170 :
171 0 : SwMvContext::~SwMvContext()
172 : {
173 0 : pSh->EndCrsrMove();
174 0 : }
175 :
176 0 : SwFrmFmt *SwEditShell::GetTableFmt() // fastest test on a table
177 : {
178 0 : const SwTableNode* pTblNd = IsCrsrInTbl();
179 0 : return pTblNd ? (SwFrmFmt*)pTblNd->GetTable().GetFrmFmt() : 0;
180 : }
181 :
182 : // TODO: Why is this called 3x for a new document?
183 0 : sal_uInt16 SwEditShell::GetTOXTypeCount(TOXTypes eTyp) const
184 : {
185 0 : return mpDoc->GetTOXTypeCount(eTyp);
186 : }
187 :
188 0 : void SwEditShell::InsertTOXType(const SwTOXType& rTyp)
189 : {
190 0 : mpDoc->InsertTOXType(rTyp);
191 0 : }
192 :
193 0 : void SwEditShell::DoUndo( sal_Bool bOn )
194 0 : { GetDoc()->GetIDocumentUndoRedo().DoUndo( bOn ); }
195 :
196 0 : sal_Bool SwEditShell::DoesUndo() const
197 0 : { return GetDoc()->GetIDocumentUndoRedo().DoesUndo(); }
198 :
199 0 : void SwEditShell::DoGroupUndo( sal_Bool bOn )
200 0 : { GetDoc()->GetIDocumentUndoRedo().DoGroupUndo( bOn ); }
201 :
202 0 : sal_Bool SwEditShell::DoesGroupUndo() const
203 0 : { return GetDoc()->GetIDocumentUndoRedo().DoesGroupUndo(); }
204 :
205 0 : void SwEditShell::DelAllUndoObj()
206 : {
207 0 : GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
208 0 : }
209 :
210 : // Combine continuous calls of Insert/Delete/Overwrite on characters. Default: sdbcx::Group-Undo.
211 :
212 : /** open undo container
213 : *
214 : * @return nUndoId ID of the container
215 : */
216 0 : SwUndoId SwEditShell::StartUndo( SwUndoId eUndoId,
217 : const SwRewriter *pRewriter )
218 0 : { return GetDoc()->GetIDocumentUndoRedo().StartUndo( eUndoId, pRewriter ); }
219 :
220 : /** close undo container
221 : *
222 : * not used by UI
223 : *
224 : * @param eUndoId ID of the undo container
225 : * @param pRewriter ?
226 : */
227 0 : SwUndoId SwEditShell::EndUndo(SwUndoId eUndoId, const SwRewriter *pRewriter)
228 0 : { return GetDoc()->GetIDocumentUndoRedo().EndUndo(eUndoId, pRewriter); }
229 :
230 0 : bool SwEditShell::GetLastUndoInfo(OUString *const o_pStr,
231 : SwUndoId *const o_pId) const
232 0 : { return GetDoc()->GetIDocumentUndoRedo().GetLastUndoInfo(o_pStr, o_pId); }
233 :
234 0 : bool SwEditShell::GetFirstRedoInfo(OUString *const o_pStr) const
235 0 : { return GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(o_pStr); }
236 :
237 0 : SwUndoId SwEditShell::GetRepeatInfo(OUString *const o_pStr) const
238 0 : { return GetDoc()->GetIDocumentUndoRedo().GetRepeatInfo(o_pStr); }
239 :
240 : /** Auto correction */
241 0 : void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Bool bInsert,
242 : sal_Unicode cChar )
243 : {
244 0 : SET_CURR_SHELL( this );
245 :
246 0 : StartAllAction();
247 :
248 0 : SwPaM* pCrsr = getShellCrsr( true );
249 0 : SwTxtNode* pTNd = pCrsr->GetNode()->GetTxtNode();
250 :
251 0 : SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, cChar );
252 : // FIXME: this _must_ be called with reference to the actual node text!
253 0 : OUString const& rNodeText(pTNd->GetTxt());
254 : rACorr.DoAutoCorrect( aSwAutoCorrDoc,
255 0 : rNodeText, pCrsr->GetPoint()->nContent.GetIndex(),
256 0 : cChar, bInsert, GetWin() );
257 0 : if( cChar )
258 0 : SaveTblBoxCntnt( pCrsr->GetPoint() );
259 0 : EndAllAction();
260 0 : }
261 :
262 0 : void SwEditShell::SetNewDoc(sal_Bool bNew)
263 : {
264 0 : GetDoc()->SetNewDoc(bNew);
265 0 : }
266 :
267 0 : sal_Bool SwEditShell::GetPrevAutoCorrWord( SvxAutoCorrect& rACorr, OUString& rWord )
268 : {
269 0 : SET_CURR_SHELL( this );
270 :
271 : sal_Bool bRet;
272 0 : SwPaM* pCrsr = getShellCrsr( true );
273 0 : const sal_Int32 nPos = pCrsr->GetPoint()->nContent.GetIndex();
274 0 : SwTxtNode* pTNd = pCrsr->GetNode()->GetTxtNode();
275 0 : if( pTNd && nPos )
276 : {
277 0 : SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCrsr, 0 );
278 : bRet = rACorr.GetPrevAutoCorrWord( aSwAutoCorrDoc,
279 0 : pTNd->GetTxt(), nPos, rWord );
280 : }
281 : else
282 0 : bRet = sal_False;
283 0 : return bRet;
284 : }
285 :
286 0 : SwAutoCompleteWord& SwEditShell::GetAutoCompleteWords()
287 : {
288 0 : return SwDoc::GetAutoCompleteWords();
289 : }
290 :
291 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|