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
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <sfx2/docfilt.hxx>
29 #include <sot/storage.hxx>
30 #include <tools/urlobj.hxx>
31 #ifndef SVTOOLS_FSTATHELPER_HXX
32 #include <svl/fstathelper.hxx>
33 #endif
34 #include <svl/macitem.hxx>
35 #include <unotools/charclass.hxx>
36 #include <frmfmt.hxx>
37 #include <doc.hxx>
38 #include <docary.hxx>
39 #include <pam.hxx>
40 #include <shellio.hxx>
41 #include <swblocks.hxx>
42 #include <ndtxt.hxx>
43 #include <mdiexp.hxx> // Progress
44 #include <SwXMLTextBlocks.hxx>
45 #ifndef _DOCSH_HXX
46 #include <docsh.hxx>
47 #endif
48 #include <swunohelper.hxx>
49
50 #ifndef _STATSTR_HRC
51 #include <statstr.hrc>
52 #endif
53 #include <swerror.h>
54
55 SV_IMPL_OP_PTRARR_SORT( SwBlockNames, SwBlockName* );
56
57 //////////////////////////////////////////////////////////////////////////
58
59 // Hash-Code errechnen (muss nicht eindeutig sein)
60
61
Hash(const String & r)62 sal_uInt16 SwImpBlocks::Hash( const String& r )
63 {
64 sal_uInt16 n = 0;
65 xub_StrLen nLen = r.Len();
66 if( nLen > 8 )
67 nLen = 8;
68 const sal_Unicode* p = r.GetBuffer();
69 while( nLen-- )
70 n = ( n << 1 ) + *p++;
71 return n;
72 }
73
74
SwBlockName(const String & rShort,const String & rLong,long n)75 SwBlockName::SwBlockName( const String& rShort, const String& rLong, long n )
76 : nPos( n ), aShort( rShort ), aLong( rLong ), aPackageName (rShort),
77 bIsOnlyTxtFlagInit( sal_False ), bIsOnlyTxt( sal_False )
78 {
79 nHashS = SwImpBlocks::Hash( rShort );
80 nHashL = SwImpBlocks::Hash( rLong );
81 }
SwBlockName(const String & rShort,const String & rLong,const String & rPackageName)82 SwBlockName::SwBlockName( const String& rShort, const String& rLong, const String& rPackageName)
83 : nPos( 0 ), aShort( rShort ), aLong( rLong ), aPackageName (rPackageName),
84 bIsOnlyTxtFlagInit( sal_False ), bIsOnlyTxt( sal_False )
85 {
86 nHashS = SwImpBlocks::Hash( rShort );
87 nHashL = SwImpBlocks::Hash( rLong );
88 }
89
90
91 // Ist die angegebene Datei ein Storage oder gibt es sie nicht?
92
GetFileType(const String & rFile)93 short SwImpBlocks::GetFileType( const String& rFile )
94 {
95 if( !FStatHelper::IsDocument( rFile ) )
96 return SWBLK_NO_FILE;
97 if( SwXMLTextBlocks::IsFileUCBStorage( rFile ) )
98 return SWBLK_XML;
99 if( SvStorage::IsStorageFile( rFile ) )
100 return SWBLK_SW3;
101 //otherwise return NONE
102 return SWBLK_NONE;
103 }
104
105
SwImpBlocks(const String & rFile,sal_Bool)106 SwImpBlocks::SwImpBlocks( const String& rFile, sal_Bool )
107 : aFile( rFile ), pDoc( 0 ), nCur( (sal_uInt16)-1 ),
108 bReadOnly( sal_True ), bInPutMuchBlocks( sal_False )
109 {
110 FStatHelper::GetModifiedDateTimeOfFile( rFile,
111 &aDateModified, &aTimeModified );
112 INetURLObject aObj(rFile);
113 aObj.setExtension( aEmptyStr );
114 aName = aObj.GetBase();
115 }
116
117
~SwImpBlocks()118 SwImpBlocks::~SwImpBlocks()
119 {
120 aNames.DeleteAndDestroy( 0, aNames.Count() );
121 }
122
123 // Loeschen des Inhaltes des Dokuments
ClearDoc()124 void SwImpBlocks::ClearDoc()
125 {
126 pDoc->ClearDoc();
127 }
128
GetDocForConversion(sal_uInt16 n)129 sal_uLong SwImpBlocks::GetDocForConversion( sal_uInt16 n )
130 {
131 return GetDoc( n );
132 }
133
134 // Erzeugen eines PaMs, der das ganze Dokument umfasst
MakePaM()135 SwPaM* SwImpBlocks::MakePaM()
136 {
137 SwPaM* pPam = new SwPaM( pDoc->GetNodes().GetEndOfContent() );
138 pPam->Move( fnMoveBackward, fnGoDoc );
139 pPam->SetMark();
140 pPam->Move( fnMoveForward, fnGoDoc );
141 pPam->Exchange();
142 return pPam;
143 }
144
145
GetCount() const146 sal_uInt16 SwImpBlocks::GetCount() const
147 {
148 return aNames.Count();
149 }
150
151 // Case Insensitive
GetIndex(const String & rShort) const152 sal_uInt16 SwImpBlocks::GetIndex( const String& rShort ) const
153 {
154 String s( GetAppCharClass().upper( rShort ) );
155 sal_uInt16 nHash = Hash( s );
156 for( sal_uInt16 i = 0; i < aNames.Count(); i++ )
157 {
158 SwBlockName* pName = aNames[ i ];
159 if( pName->nHashS == nHash
160 && pName->aShort == s )
161 return i;
162 }
163 return (sal_uInt16) -1;
164 }
165
166
GetLongIndex(const String & rLong) const167 sal_uInt16 SwImpBlocks::GetLongIndex( const String& rLong ) const
168 {
169 sal_uInt16 nHash = Hash( rLong );
170 for( sal_uInt16 i = 0; i < aNames.Count(); i++ )
171 {
172 SwBlockName* pName = aNames[ i ];
173 if( pName->nHashL == nHash
174 && pName->aLong == rLong )
175 return i;
176 }
177 return (sal_uInt16) -1;
178 }
179
180
GetShortName(sal_uInt16 n) const181 const String& SwImpBlocks::GetShortName( sal_uInt16 n ) const
182 {
183 if( n < aNames.Count() )
184 return aNames[ n ]->aShort;
185 return aEmptyStr;
186 }
187
188
GetLongName(sal_uInt16 n) const189 const String& SwImpBlocks::GetLongName( sal_uInt16 n ) const
190 {
191 if( n < aNames.Count() )
192 return aNames[ n ]->aLong;
193 return aEmptyStr;
194 }
195
GetPackageName(sal_uInt16 n) const196 const String& SwImpBlocks::GetPackageName( sal_uInt16 n ) const
197 {
198 if( n < aNames.Count() )
199 return aNames[ n ]->aPackageName;
200 return aEmptyStr;
201 }
202
AddName(const String & rShort,const String & rLong,sal_Bool bOnlyTxt)203 void SwImpBlocks::AddName( const String& rShort, const String& rLong,
204 sal_Bool bOnlyTxt )
205 {
206 sal_uInt16 nIdx = GetIndex( rShort );
207 if( nIdx != (sal_uInt16) -1 )
208 aNames.DeleteAndDestroy( nIdx );
209 SwBlockName* pNew = new SwBlockName( rShort, rLong, 0L );
210 pNew->bIsOnlyTxtFlagInit = sal_True;
211 pNew->bIsOnlyTxt = bOnlyTxt;
212 aNames.C40_PTR_INSERT( SwBlockName, pNew );
213 }
214
215
216
IsFileChanged() const217 sal_Bool SwImpBlocks::IsFileChanged() const
218 {
219 Date aTempDateModified( aDateModified );
220 Time aTempTimeModified( aTimeModified );
221 return FStatHelper::GetModifiedDateTimeOfFile( aFile,
222 &aTempDateModified, &aTempTimeModified ) &&
223 ( aDateModified != aTempDateModified ||
224 aTimeModified != aTempTimeModified );
225 }
226
227
Touch()228 void SwImpBlocks::Touch()
229 {
230 FStatHelper::GetModifiedDateTimeOfFile( aFile,
231 &aDateModified, &aTimeModified );
232 }
233
IsOnlyTextBlock(const String &) const234 sal_Bool SwImpBlocks::IsOnlyTextBlock( const String& ) const
235 {
236 return sal_False;
237 }
238
GetMacroTable(sal_uInt16,SvxMacroTableDtor &,sal_Bool)239 sal_uLong SwImpBlocks::GetMacroTable( sal_uInt16, SvxMacroTableDtor&, sal_Bool )
240 {
241 return 0;
242 }
243
SetMacroTable(sal_uInt16,const SvxMacroTableDtor &,sal_Bool)244 sal_uLong SwImpBlocks::SetMacroTable( sal_uInt16 ,
245 const SvxMacroTableDtor& , sal_Bool )
246 {
247 return 0;
248 }
249
PutMuchEntries(sal_Bool)250 sal_Bool SwImpBlocks::PutMuchEntries( sal_Bool )
251 {
252 return sal_False;
253 }
254
255 ////////////////////////////////////////////////////////////////////////////
256
257
SwTextBlocks(const String & rFile)258 SwTextBlocks::SwTextBlocks( const String& rFile )
259 : pImp( 0 ), nErr( 0 )
260 {
261 INetURLObject aObj(rFile);
262 String sFileName = aObj.GetMainURL( INetURLObject::NO_DECODE );
263 switch( SwImpBlocks::GetFileType( rFile ) )
264 {
265 //case SWBLK_SW2: pImp = new Sw2TextBlocks( sFileName ); break;
266 //case SWBLK_SW3: pImp = new Sw3TextBlocks( sFileName ); break;
267 case SWBLK_XML: pImp = new SwXMLTextBlocks( sFileName ); break;
268 case SWBLK_NO_FILE: pImp = new SwXMLTextBlocks( sFileName ); break;
269 }
270 if( !pImp )
271 nErr = ERR_SWG_FILE_FORMAT_ERROR;
272 }
273
~SwTextBlocks()274 SwTextBlocks::~SwTextBlocks()
275 {
276 delete pImp;
277 }
278
GetName()279 const String& SwTextBlocks::GetName()
280 {
281 return pImp ? pImp->aName : aEmptyStr;
282 }
283
284
SetName(const String & r)285 void SwTextBlocks::SetName( const String& r )
286 {
287 if( pImp )
288 pImp->SetName( r );
289 }
290
291
IsOld() const292 sal_Bool SwTextBlocks::IsOld() const
293 {
294 if (pImp)
295 {
296 short nType = pImp->GetFileType();
297 if (SWBLK_SW3 == nType || SWBLK_SW2 == nType )
298 return sal_True;
299 }
300 return sal_False;
301 }
302
303
304 /*
305 sal_uLong SwTextBlocks::ConvertToNew()
306 {
307 // Wir nehmen die aktuelle Datei, benennen diese in .BAK um
308 // und kreieren den neuen Storage
309 if( IsOld() )
310 {
311 // Erst mal muessen wir die Datei freigeben
312 short nType = pImp->GetFileType();
313 Sw2TextBlocks *pTwo = NULL;
314 Sw3TextBlocks *pThree = NULL;
315 SwImpBlocks *pOld = NULL;
316
317 pImp->nCur = (sal_uInt16) -1;
318 String aName( pImp->aFile );
319 delete pImp; pImp = NULL;
320 // Jetzt wird umbenannt
321 INetURLObject aOldFull( aName );
322 INetURLObject aNewFull( aName );
323
324 aOldFull.SetExtension( String::CreateFromAscii("bak") );
325 String aOld( aOldFull.GetMainURL( INetURLObject::NO_DECODE ) );
326 String aNew( aNewFull.GetMainURL( INetURLObject::NO_DECODE ) );
327
328 sal_Bool bError = !SWUnoHelper::UCB_CopyFile( aNew, aOld, sal_True );
329 if( bError )
330 {
331 if (nType == SWBLK_SW2)
332 pImp = new Sw2TextBlocks( aOld );
333 else
334 pImp = new Sw3TextBlocks( aOld );
335 return nErr = ERR_SWG_CANNOT_WRITE;
336 }
337
338 // Die Datei ist erfolgreich umbenannt. Jetzt wird der Storage
339 // aufgesetzt
340 if (nType == SWBLK_SW2)
341 pOld = pTwo = new Sw2TextBlocks( aOld );
342 else
343 pOld = pThree = new Sw3TextBlocks( aOld );
344 SwXMLTextBlocks* pNew = new SwXMLTextBlocks( aName );
345 pNew->SetName ( pOld->GetName());
346 // Wir kopieren den Doc-Ptr in das alte System
347 // den alten SvPersist heben wir uns aber auf,
348 // da dieser die ganze Zeit leben bleibt
349 // und lesen die Dateivorlagen erneut ein
350 SvPersist* pPersist2 = pOld->pDoc->GetPersist();
351 if (SWBLK_SW2 == nType )
352 {
353 delete pOld->pDoc;
354 pOld->pDoc = pNew->pDoc;nLinkCt
355 nErr = pTwo->LoadDoc();
356 }
357 else
358 {
359 nErr = pThree->OpenFile ( sal_True );
360 // Within this call, Sw3IoImp::SetDoc calls RemoveLink
361 // on the old document, and deletes it if the
362 // ref count is now zero
363 pThree->SetDoc ( pNew->pDoc );
364 pOld->pDoc->AddLink();
365 }
366 if( !nErr && 0 == ( nErr = pNew->OpenFile( sal_False )) )
367 {
368 nErr = pNew->SetConvertMode( sal_True );
369 // jetzt werden die Bausteine einfach umkopiert!
370 if( !nErr )
371 {
372 if (SWBLK_SW2 == nType)
373 pTwo->StatLineStartPercent();
374 sal_uInt16 nCount = pOld->GetCount();
375 for( sal_uInt16 i = 0; i < nCount; i++ )
376 {
377 pNew->ClearDoc();
378 String aShort( pOld->GetShortName( i ) );
379 String aLong( pOld->GetLongName( i ) );
380 pNew->AddName( aShort, aLong );
381 if ( SWBLK_SW3 == nType && pThree->IsOnlyTextBlock(aShort) )
382 {
383 String sText;
384 pThree->GetText( aShort, sText );
385 pNew->PutText( aShort, aLong, sText );
386 }
387 else
388 {
389 if (SWBLK_SW2 == nType )
390 {
391 // I think this is how it should work (!!!!!!) mtg
392 pNew->pDoc->SetPersist( pPersist2 );
393 }
394 nErr = pOld->GetDocForConversion( i );
395 if( nErr )
396 break;
397 nErr = pNew->BeginPutDoc( aShort, aLong );
398 if( nErr )
399 break;
400 nErr = pNew->PutDoc();
401 if( nErr )
402 break;
403 }
404
405 // convert macros, too
406 SvxMacroTableDtor aMacroTable;
407 pOld->GetMacroTable( i, aMacroTable, sal_True );
408 pNew->SetMacroTable( i, aMacroTable, sal_True );
409
410 if (SWBLK_SW2 == nType )
411 pNew->pDoc->SetPersist( 0 );
412 }
413 if (SWBLK_SW2 == nType )
414 ::EndProgress( pOld->pDoc->GetDocShell() );
415 }
416 if( !nErr )
417 nErr = pNew->SetConvertMode( sal_False );
418 }
419 if ( SWBLK_SW3 == nType )
420 {
421 pThree->CloseFile();
422 }
423 else
424 {
425 // Haben wir es geschafft?
426 pOld->pDoc = NULL;
427 }
428 pNew->ClearDoc();
429 if( !nErr )
430 {
431 delete pOld;
432 pImp = pNew;
433 SWUnoHelper::UCB_DeleteFile( aOld );
434 pNew->MakeBlockList();
435 }
436 else
437 {
438 delete pOld; delete pNew;
439 SWUnoHelper::UCB_DeleteFile( aNew );
440 SWUnoHelper::UCB_CopyFile( aOld, aNew, sal_True );
441 if ( SWBLK_SW2 == nType )
442 pImp = new Sw2TextBlocks( aOld );
443 else
444 pImp = new Sw3TextBlocks( aOld );
445 }
446 pNew->CloseFile();
447 FStatHelper::GetModifiedDateTimeOfFile( aNew,
448 &pImp->aDateModified, &pImp->aTimeModified );
449 }
450 return nErr;
451 } */
452
453
GetCount() const454 sal_uInt16 SwTextBlocks::GetCount() const
455 {
456 return pImp ? pImp->GetCount() : 0;
457 }
458
459
GetIndex(const String & r) const460 sal_uInt16 SwTextBlocks::GetIndex( const String& r ) const
461 {
462 return pImp ? pImp->GetIndex( r ) : (sal_uInt16) -1;
463 }
464
465
GetLongIndex(const String & r) const466 sal_uInt16 SwTextBlocks::GetLongIndex( const String& r ) const
467 {
468 return pImp ? (sal_uInt16)(pImp->GetLongIndex( r )) : (sal_uInt16) -1;
469 }
470
471
GetShortName(sal_uInt16 n) const472 const String& SwTextBlocks::GetShortName( sal_uInt16 n ) const
473 {
474 if( pImp )
475 return pImp->GetShortName( n );
476 return aEmptyStr;
477 }
478
479
GetLongName(sal_uInt16 n) const480 const String& SwTextBlocks::GetLongName( sal_uInt16 n ) const
481 {
482 if( pImp )
483 return pImp->GetLongName( n );
484 return aEmptyStr;
485 }
486
487
Delete(sal_uInt16 n)488 sal_Bool SwTextBlocks::Delete( sal_uInt16 n )
489 {
490 if( pImp && !pImp->bInPutMuchBlocks )
491 {
492 if( pImp->IsFileChanged() )
493 nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
494 else if( 0 == (nErr = pImp->OpenFile( sal_False ) ))
495 {
496 nErr = pImp->Delete( n );
497 if( !nErr )
498 pImp->aNames.DeleteAndDestroy( n );
499 if( n == pImp->nCur )
500 pImp->nCur = (sal_uInt16) -1;
501 if( !nErr )
502 nErr = pImp->MakeBlockList();
503 }
504 pImp->CloseFile();
505 pImp->Touch();
506
507 return sal_Bool( nErr == 0 );
508 }
509 return sal_False;
510 }
511
512
Rename(sal_uInt16 n,const String * s,const String * l)513 sal_uInt16 SwTextBlocks::Rename( sal_uInt16 n, const String* s, const String* l )
514 {
515 sal_uInt16 nIdx = (sal_uInt16)-1;
516 if( pImp && !pImp->bInPutMuchBlocks )
517 {
518 pImp->nCur = nIdx;
519 String aNew, aLong;
520 if( s )
521 aNew = aLong = *s;
522 if( l )
523 aLong = *l;
524 if( !aNew.Len() )
525 {
526 ASSERT( sal_False, "No short name specified in Rename" );
527 nErr = ERR_SWG_INTERNAL_ERROR; return (sal_uInt16) -1;
528 }
529
530 if( pImp->IsFileChanged() )
531 nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
532 else if( 0 == ( nErr = pImp->OpenFile( sal_False )))
533 {
534 // Vorher den neuen Eintrag in die Liste setzen!
535 GetAppCharClass().toUpper( aNew );
536 nErr = pImp->Rename( n, aNew, aLong );
537 if( !nErr )
538 {
539 sal_Bool bOnlyTxt = pImp->aNames[ n ]->bIsOnlyTxt;
540 pImp->aNames.DeleteAndDestroy( n );
541 pImp->AddName( aNew, aLong, bOnlyTxt );
542 nErr = pImp->MakeBlockList();
543 }
544 }
545 pImp->CloseFile();
546 pImp->Touch();
547 if( !nErr )
548 nIdx = pImp->GetIndex( aNew );
549 }
550 return nIdx;
551 }
552
CopyBlock(SwTextBlocks & rSource,String & rSrcShort,const String & rLong)553 sal_uLong SwTextBlocks::CopyBlock( SwTextBlocks& rSource, String& rSrcShort,
554 const String& rLong )
555 {
556 sal_Bool bIsOld = sal_False;
557 if (rSource.pImp)
558 {
559 short nType = rSource.pImp->GetFileType();
560 if (SWBLK_SW2 == nType || SWBLK_SW3 == nType )
561 bIsOld = sal_True;
562 }
563 if( bIsOld ) //rSource.IsOld() )
564 nErr = ERR_SWG_OLD_GLOSSARY;
565 else if( pImp->bInPutMuchBlocks )
566 nErr = ERR_SWG_INTERNAL_ERROR;
567 else
568 nErr = pImp->CopyBlock(*rSource.pImp, rSrcShort, rLong);
569 return nErr;
570 }
571
BeginGetDoc(sal_uInt16 n)572 sal_Bool SwTextBlocks::BeginGetDoc( sal_uInt16 n )
573 {
574 if( pImp && !pImp->bInPutMuchBlocks )
575 {
576 // diese Optimierierung darf es nicht mehr geben. OLE-Objecte muessen auf
577 // ihre SubStorages zugreifem koennen!
578 // if( n == pImp->nCur )
579 // return sal_True;
580
581 if( pImp->IsFileChanged() )
582 nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
583 else if( 0 == ( nErr = pImp->OpenFile( sal_True )))
584 {
585 pImp->ClearDoc();
586 nErr = pImp->GetDoc( n );
587 if( nErr )
588 pImp->nCur = (sal_uInt16)-1;
589 else
590 pImp->nCur = n;
591 }
592 return sal_Bool( nErr == 0 );
593 }
594 return sal_False;
595 }
596
597
EndGetDoc()598 void SwTextBlocks::EndGetDoc()
599 {
600 if( pImp && !pImp->bInPutMuchBlocks )
601 pImp->CloseFile();
602 }
603
604
BeginPutDoc(const String & s,const String & l)605 sal_Bool SwTextBlocks::BeginPutDoc( const String& s, const String& l )
606 {
607 if( pImp )
608 {
609 sal_Bool bOk = pImp->bInPutMuchBlocks;
610 if( !bOk )
611 {
612 if( pImp->IsFileChanged() )
613 nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
614 else
615 nErr = pImp->OpenFile( sal_False );
616 bOk = 0 == nErr;
617 }
618 if( bOk )
619 {
620 String aNew( s );
621 GetAppCharClass().toUpper( aNew );
622 nErr = pImp->BeginPutDoc( aNew, l );
623 }
624 if( nErr )
625 pImp->CloseFile();
626 }
627 return 0 == nErr;
628 }
629
630
PutDoc()631 sal_uInt16 SwTextBlocks::PutDoc()
632 {
633 sal_uInt16 nIdx = (sal_uInt16)-1;
634 if( pImp )
635 {
636 nErr = pImp->PutDoc();
637 if( !nErr )
638 {
639 pImp->nCur = GetIndex( pImp->aShort );
640 if( pImp->nCur != (sal_uInt16) -1 )
641 pImp->aNames[ pImp->nCur ]->aLong = pImp->aLong;
642 else
643 {
644 pImp->AddName( pImp->aShort, pImp->aLong );
645 pImp->nCur = pImp->GetIndex( pImp->aShort );
646 }
647 if( !pImp->bInPutMuchBlocks )
648 nErr = pImp->MakeBlockList();
649 }
650 if( !pImp->bInPutMuchBlocks )
651 {
652 pImp->CloseFile();
653 pImp->Touch();
654 }
655 nIdx = pImp->nCur;
656 }
657 return nIdx;
658 }
659
PutText(const String & rShort,const String & rName,const String & rTxt)660 sal_uInt16 SwTextBlocks::PutText( const String& rShort, const String& rName,
661 const String& rTxt )
662 {
663 sal_uInt16 nIdx = (sal_uInt16) -1;
664 if( pImp )
665 {
666 sal_Bool bOk = pImp->bInPutMuchBlocks;
667 if( !bOk )
668 {
669 if( pImp->IsFileChanged() )
670 nErr = ERR_TXTBLOCK_NEWFILE_ERROR;
671 else
672 nErr = pImp->OpenFile( sal_False );
673 bOk = 0 == nErr;
674 }
675 if( bOk )
676 {
677 String aNew( rShort );
678 GetAppCharClass().toUpper( aNew );
679 nErr = pImp->PutText( aNew, rName, rTxt );
680 pImp->nCur = (sal_uInt16) -1;
681 if( !nErr )
682 {
683 nIdx = GetIndex( pImp->aShort );
684 if( nIdx != (sal_uInt16) -1 )
685 pImp->aNames[ nIdx ]->aLong = rName;
686 else
687 {
688 pImp->AddName( pImp->aShort, rName, sal_True );
689 nIdx = pImp->GetIndex( pImp->aShort );
690 }
691 if( !pImp->bInPutMuchBlocks )
692 nErr = pImp->MakeBlockList();
693 }
694 }
695 if( !pImp->bInPutMuchBlocks )
696 {
697 pImp->CloseFile();
698 pImp->Touch();
699 }
700 }
701 return nIdx;
702 }
703
704
GetDoc()705 SwDoc* SwTextBlocks::GetDoc()
706 {
707 if( pImp )
708 return pImp->pDoc;
709 return 0;
710 }
711
712
ClearDoc()713 void SwTextBlocks::ClearDoc()
714 {
715 if( pImp )
716 pImp->ClearDoc();
717 pImp->nCur = (sal_uInt16) -1;
718 }
719
720
GetFileName() const721 const String& SwTextBlocks::GetFileName() const
722 {
723 return pImp->GetFileName();
724 }
725
726
IsReadOnly() const727 sal_Bool SwTextBlocks::IsReadOnly() const
728 {
729 return pImp->bReadOnly;
730 }
731
IsOnlyTextBlock(sal_uInt16 nIdx) const732 sal_Bool SwTextBlocks::IsOnlyTextBlock( sal_uInt16 nIdx ) const
733 {
734 sal_Bool bRet = sal_False;
735 if( pImp && !pImp->bInPutMuchBlocks )
736 {
737 SwBlockName* pBlkNm = pImp->aNames[ nIdx ];
738 if( !pBlkNm->bIsOnlyTxtFlagInit &&
739 !pImp->IsFileChanged() && !pImp->OpenFile( sal_True ) )
740 {
741 pBlkNm->bIsOnlyTxt = pImp->IsOnlyTextBlock( pBlkNm->aShort );
742 pBlkNm->bIsOnlyTxtFlagInit = sal_True;
743 pImp->CloseFile();
744 }
745 bRet = pBlkNm->bIsOnlyTxt;
746 }
747 return bRet;
748 }
749
IsOnlyTextBlock(const String & rShort) const750 sal_Bool SwTextBlocks::IsOnlyTextBlock( const String& rShort ) const
751 {
752 sal_uInt16 nIdx = pImp->GetIndex( rShort );
753 if( USHRT_MAX != nIdx )
754 {
755 if( pImp->aNames[ nIdx ]->bIsOnlyTxtFlagInit )
756 return pImp->aNames[ nIdx ]->bIsOnlyTxt;
757 return IsOnlyTextBlock( nIdx );
758 }
759
760 ASSERT( sal_False, "invalid name" );
761 return sal_False;
762 }
763
GetMacroTable(sal_uInt16 nIdx,SvxMacroTableDtor & rMacroTbl)764 sal_Bool SwTextBlocks::GetMacroTable( sal_uInt16 nIdx, SvxMacroTableDtor& rMacroTbl )
765 {
766 sal_Bool bRet = sal_True;
767 if ( pImp && !pImp->bInPutMuchBlocks )
768 bRet = ( 0 == pImp->GetMacroTable( nIdx, rMacroTbl ) );
769 return bRet;
770 }
771
SetMacroTable(sal_uInt16 nIdx,const SvxMacroTableDtor & rMacroTbl)772 sal_Bool SwTextBlocks::SetMacroTable( sal_uInt16 nIdx,
773 const SvxMacroTableDtor& rMacroTbl )
774 {
775 sal_Bool bRet = sal_True;
776 if ( pImp && !pImp->bInPutMuchBlocks )
777 bRet = ( 0 == pImp->SetMacroTable( nIdx, rMacroTbl ) );
778 return bRet;
779 }
780
StartPutMuchBlockEntries()781 sal_Bool SwTextBlocks::StartPutMuchBlockEntries()
782 {
783 sal_Bool bRet = sal_False;
784 if( !IsOld() && pImp )
785 bRet = pImp->PutMuchEntries( sal_True );
786 return bRet;
787 }
788
EndPutMuchBlockEntries()789 void SwTextBlocks::EndPutMuchBlockEntries()
790 {
791 if( pImp )
792 pImp->PutMuchEntries( sal_False );
793 }
794
795 /*-- 20.09.2004 10:25:33---------------------------------------------------
796
797 -----------------------------------------------------------------------*/
GetBaseURL() const798 String SwTextBlocks::GetBaseURL() const
799 {
800 String sRet;
801 if(pImp)
802 sRet = pImp->GetBaseURL();
803 return sRet;
804 }
805 /*-- 20.09.2004 10:25:33---------------------------------------------------
806
807 -----------------------------------------------------------------------*/
SetBaseURL(const String & rURL)808 void SwTextBlocks::SetBaseURL( const String& rURL )
809 {
810 if(pImp)
811 pImp->SetBaseURL(rURL);
812 }
813
814
815