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